@iota/dapp-kit 0.1.2 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +28 -0
- package/README.md +14 -12
- package/dist/cjs/components/AccountDropdownMenu.css +4 -5
- package/dist/cjs/components/AccountDropdownMenu.css.css.map +1 -1
- package/dist/cjs/components/AccountDropdownMenu.css.map +3 -3
- package/dist/cjs/components/AccountDropdownMenu.d.ts +3 -1
- package/dist/cjs/components/AccountDropdownMenu.js +50 -106
- package/dist/cjs/components/AccountDropdownMenu.js.map +4 -4
- package/dist/cjs/components/ConnectButton.css +5 -10
- package/dist/cjs/components/ConnectButton.css.map +3 -3
- package/dist/cjs/components/ConnectButton.d.ts +5 -3
- package/dist/cjs/components/ConnectButton.js +129 -179
- package/dist/cjs/components/ConnectButton.js.map +4 -4
- package/dist/cjs/components/IotaClientProvider.d.ts +0 -1
- package/dist/cjs/components/WalletProvider.d.ts +3 -3
- package/dist/cjs/components/WalletProvider.js +115 -75
- package/dist/cjs/components/WalletProvider.js.map +2 -2
- package/dist/cjs/components/connect-modal/ConnectModal.css +5 -10
- package/dist/cjs/components/connect-modal/ConnectModal.css.css.map +1 -1
- package/dist/cjs/components/connect-modal/ConnectModal.css.map +3 -3
- package/dist/cjs/components/connect-modal/ConnectModal.js +15 -9
- package/dist/cjs/components/connect-modal/ConnectModal.js.map +3 -3
- package/dist/cjs/components/connect-modal/InfoSection.css.css.map +1 -1
- package/dist/cjs/components/connect-modal/InfoSection.css.map +1 -1
- package/dist/cjs/components/connect-modal/views/ConnectionStatus.css +4 -5
- package/dist/cjs/components/connect-modal/views/ConnectionStatus.css.css.map +1 -1
- package/dist/cjs/components/connect-modal/views/ConnectionStatus.css.map +3 -3
- package/dist/cjs/components/connect-modal/views/ConnectionStatus.js.map +2 -2
- package/dist/cjs/components/connect-modal/views/GetTheWallet.css +78 -0
- package/dist/cjs/components/connect-modal/views/GetTheWallet.css.css +35 -0
- package/dist/cjs/components/connect-modal/views/GetTheWallet.css.css.map +7 -0
- package/dist/cjs/components/connect-modal/views/GetTheWallet.css.d.ts +5 -0
- package/dist/cjs/components/connect-modal/views/GetTheWallet.css.js +35 -0
- package/dist/cjs/components/connect-modal/views/GetTheWallet.css.js.map +7 -0
- package/dist/cjs/components/connect-modal/views/GetTheWallet.css.map +7 -0
- package/dist/cjs/components/connect-modal/views/GetTheWallet.d.ts +1 -0
- package/dist/cjs/components/connect-modal/views/GetTheWallet.js +145 -0
- package/dist/cjs/components/connect-modal/views/GetTheWallet.js.map +7 -0
- package/dist/cjs/components/connect-modal/views/GettingStarted.css +4 -5
- package/dist/cjs/components/connect-modal/views/GettingStarted.css.css.map +1 -1
- package/dist/cjs/components/connect-modal/views/GettingStarted.css.map +3 -3
- package/dist/cjs/components/connect-modal/views/GettingStarted.js +2 -2
- package/dist/cjs/components/connect-modal/views/GettingStarted.js.map +1 -1
- package/dist/cjs/components/connect-modal/views/WhatIsAWallet.css.css.map +1 -1
- package/dist/cjs/components/connect-modal/views/WhatIsAWallet.css.map +1 -1
- package/dist/cjs/components/connect-modal/views/index.css +205 -0
- package/dist/cjs/components/connect-modal/views/index.css.map +7 -0
- package/dist/cjs/components/connect-modal/views/index.d.ts +3 -0
- package/dist/cjs/components/connect-modal/views/index.js +286 -0
- package/dist/cjs/components/connect-modal/views/index.js.map +7 -0
- package/dist/cjs/components/connect-modal/wallet-list/WalletList.css.css.map +1 -1
- package/dist/cjs/components/connect-modal/wallet-list/WalletList.css.map +1 -1
- package/dist/cjs/components/connect-modal/wallet-list/WalletList.js +1 -1
- package/dist/cjs/components/connect-modal/wallet-list/WalletList.js.map +2 -2
- package/dist/cjs/components/connect-modal/wallet-list/WalletListItem.css.css.map +1 -1
- package/dist/cjs/components/connect-modal/wallet-list/WalletListItem.css.map +1 -1
- package/dist/cjs/components/connect-modal/wallet-list/WalletListItem.js.map +1 -1
- package/dist/cjs/components/icons/ArrowRightIcon.d.ts +2 -0
- package/dist/cjs/components/icons/ArrowRightIcon.js +47 -0
- package/dist/cjs/components/icons/ArrowRightIcon.js.map +7 -0
- package/dist/cjs/components/icons/ArrowTopRightIcon.d.ts +2 -0
- package/dist/cjs/components/icons/ArrowTopRightIcon.js +47 -0
- package/dist/cjs/components/icons/ArrowTopRightIcon.js.map +7 -0
- package/dist/cjs/components/styling/InjectedThemeStyles.js +15 -8
- package/dist/cjs/components/styling/InjectedThemeStyles.js.map +2 -2
- package/dist/cjs/components/styling/StyleMarker.css.css.map +1 -1
- package/dist/cjs/components/styling/StyleMarker.css.map +1 -1
- package/dist/cjs/components/styling/StyleMarker.d.ts +0 -1
- package/dist/cjs/components/styling/StyleMarker.js +2 -2
- package/dist/cjs/components/styling/StyleMarker.js.map +3 -3
- package/dist/cjs/components/ui/Button.css +4 -5
- package/dist/cjs/components/ui/Button.css.css +4 -5
- package/dist/cjs/components/ui/Button.css.css.map +3 -3
- package/dist/cjs/components/ui/Button.css.d.ts +0 -1
- package/dist/cjs/components/ui/Button.css.js.map +1 -1
- package/dist/cjs/components/ui/Button.css.map +3 -3
- package/dist/cjs/components/ui/Button.d.ts +1 -1
- package/dist/cjs/components/ui/Button.js.map +1 -1
- package/dist/cjs/components/ui/Heading.css.css.map +1 -1
- package/dist/cjs/components/ui/Heading.css.map +1 -1
- package/dist/cjs/components/ui/Heading.d.ts +0 -1
- package/dist/cjs/components/ui/IconButton.css +1 -5
- package/dist/cjs/components/ui/IconButton.css.css +1 -5
- package/dist/cjs/components/ui/IconButton.css.css.map +3 -3
- package/dist/cjs/components/ui/IconButton.css.js.map +1 -1
- package/dist/cjs/components/ui/IconButton.css.map +3 -3
- package/dist/cjs/components/ui/IconButton.d.ts +1 -1
- package/dist/cjs/components/ui/IconButton.js.map +1 -1
- package/dist/cjs/components/ui/Text.css.css.map +1 -1
- package/dist/cjs/components/ui/Text.css.map +1 -1
- package/dist/cjs/components/ui/Text.d.ts +0 -1
- package/dist/cjs/constants/styleDataAttribute.js.map +1 -1
- package/dist/cjs/constants/walletDefaults.d.ts +3 -2
- package/dist/cjs/constants/walletDefaults.js +8 -6
- package/dist/cjs/constants/walletDefaults.js.map +2 -2
- package/dist/cjs/constants/walletMutationKeys.d.ts +3 -2
- package/dist/cjs/constants/walletMutationKeys.js +4 -3
- package/dist/cjs/constants/walletMutationKeys.js.map +2 -2
- package/dist/cjs/contexts/walletContext.d.ts +1 -2
- package/dist/cjs/hooks/useIotaClientInfiniteQuery.js.map +2 -2
- package/dist/cjs/hooks/useIotaClientQuery.js +3 -1
- package/dist/cjs/hooks/useIotaClientQuery.js.map +2 -2
- package/dist/cjs/hooks/wallet/useAutoConnectWallet.js +17 -7
- package/dist/cjs/hooks/wallet/useAutoConnectWallet.js.map +2 -2
- package/dist/cjs/hooks/wallet/useConnectWallet.js +10 -4
- package/dist/cjs/hooks/wallet/useConnectWallet.js.map +2 -2
- package/dist/cjs/hooks/wallet/useCurrentWallet.d.ts +3 -0
- package/dist/cjs/hooks/wallet/useCurrentWallet.js +7 -3
- package/dist/cjs/hooks/wallet/useCurrentWallet.js.map +2 -2
- package/dist/cjs/hooks/wallet/useDisconnectWallet.js +11 -6
- package/dist/cjs/hooks/wallet/useDisconnectWallet.js.map +2 -2
- package/dist/cjs/hooks/wallet/useReportTransactionEffects.d.ts +15 -0
- package/dist/cjs/hooks/wallet/{useSignTransactionBlock.js → useReportTransactionEffects.js} +41 -37
- package/dist/cjs/hooks/wallet/useReportTransactionEffects.js.map +7 -0
- package/dist/cjs/hooks/wallet/useSignAndExecuteTransaction.d.ts +29 -0
- package/dist/cjs/hooks/wallet/useSignAndExecuteTransaction.js +252 -0
- package/dist/cjs/hooks/wallet/useSignAndExecuteTransaction.js.map +7 -0
- package/dist/cjs/hooks/wallet/useSignPersonalMessage.js +21 -27
- package/dist/cjs/hooks/wallet/useSignPersonalMessage.js.map +2 -2
- package/dist/cjs/hooks/wallet/useSignTransaction.d.ts +18 -0
- package/dist/cjs/hooks/wallet/{useSignAndExecuteTransactionBlock.js → useSignTransaction.js} +86 -46
- package/dist/cjs/hooks/wallet/useSignTransaction.js.map +7 -0
- package/dist/cjs/hooks/wallet/useSwitchAccount.js +11 -6
- package/dist/cjs/hooks/wallet/useSwitchAccount.js.map +2 -2
- package/dist/cjs/hooks/wallet/useUnsafeBurnerWallet.js +45 -33
- package/dist/cjs/hooks/wallet/useUnsafeBurnerWallet.js.map +2 -2
- package/dist/cjs/hooks/wallet/useWalletPropertiesChanged.js +7 -3
- package/dist/cjs/hooks/wallet/useWalletPropertiesChanged.js.map +2 -2
- package/dist/cjs/hooks/wallet/useWalletsChanged.d.ts +1 -1
- package/dist/cjs/hooks/wallet/useWalletsChanged.js +7 -6
- package/dist/cjs/hooks/wallet/useWalletsChanged.js.map +2 -2
- package/dist/cjs/index.css +5 -10
- package/dist/cjs/index.css.map +3 -3
- package/dist/cjs/index.d.ts +4 -3
- package/dist/cjs/index.js +437 -287
- package/dist/cjs/index.js.map +4 -4
- package/dist/cjs/themes/darkTheme.d.ts +2 -0
- package/dist/cjs/themes/darkTheme.js +88 -0
- package/dist/cjs/themes/darkTheme.js.map +7 -0
- package/dist/cjs/themes/lightTheme.js +13 -8
- package/dist/cjs/themes/lightTheme.js.map +2 -2
- package/dist/cjs/themes/themeContract.d.ts +22 -12
- package/dist/cjs/themes/themeContract.js +13 -8
- package/dist/cjs/themes/themeContract.js.map +2 -2
- package/dist/cjs/types.d.ts +1 -1
- package/dist/cjs/types.js.map +1 -1
- package/dist/cjs/utils/assertUnreachable.js.map +1 -1
- package/dist/cjs/utils/walletUtils.d.ts +2 -2
- package/dist/cjs/utils/walletUtils.js +2 -2
- package/dist/cjs/utils/walletUtils.js.map +2 -2
- package/dist/cjs/walletStore.d.ts +3 -2
- package/dist/cjs/walletStore.js +8 -4
- package/dist/cjs/walletStore.js.map +2 -2
- package/dist/esm/components/AccountDropdownMenu.css +4 -5
- package/dist/esm/components/AccountDropdownMenu.css.css.map +1 -1
- package/dist/esm/components/AccountDropdownMenu.css.map +3 -3
- package/dist/esm/components/AccountDropdownMenu.d.ts +3 -1
- package/dist/esm/components/AccountDropdownMenu.js +39 -95
- package/dist/esm/components/AccountDropdownMenu.js.map +4 -4
- package/dist/esm/components/ConnectButton.css +5 -10
- package/dist/esm/components/ConnectButton.css.map +3 -3
- package/dist/esm/components/ConnectButton.d.ts +5 -3
- package/dist/esm/components/ConnectButton.js +101 -151
- package/dist/esm/components/ConnectButton.js.map +4 -4
- package/dist/esm/components/IotaClientProvider.d.ts +0 -1
- package/dist/esm/components/WalletProvider.d.ts +3 -3
- package/dist/esm/components/WalletProvider.js +114 -74
- package/dist/esm/components/WalletProvider.js.map +2 -2
- package/dist/esm/components/connect-modal/ConnectModal.css +5 -10
- package/dist/esm/components/connect-modal/ConnectModal.css.css.map +1 -1
- package/dist/esm/components/connect-modal/ConnectModal.css.map +3 -3
- package/dist/esm/components/connect-modal/ConnectModal.js +15 -9
- package/dist/esm/components/connect-modal/ConnectModal.js.map +3 -3
- package/dist/esm/components/connect-modal/InfoSection.css.css.map +1 -1
- package/dist/esm/components/connect-modal/InfoSection.css.map +1 -1
- package/dist/esm/components/connect-modal/views/ConnectionStatus.css +4 -5
- package/dist/esm/components/connect-modal/views/ConnectionStatus.css.css.map +1 -1
- package/dist/esm/components/connect-modal/views/ConnectionStatus.css.map +3 -3
- package/dist/esm/components/connect-modal/views/ConnectionStatus.js.map +2 -2
- package/dist/esm/components/connect-modal/views/GetTheWallet.css +78 -0
- package/dist/esm/components/connect-modal/views/GetTheWallet.css.css +35 -0
- package/dist/esm/components/connect-modal/views/GetTheWallet.css.css.map +7 -0
- package/dist/esm/components/connect-modal/views/GetTheWallet.css.d.ts +5 -0
- package/dist/esm/components/connect-modal/views/GetTheWallet.css.js +14 -0
- package/dist/esm/components/connect-modal/views/GetTheWallet.css.js.map +7 -0
- package/dist/esm/components/connect-modal/views/GetTheWallet.css.map +7 -0
- package/dist/esm/components/connect-modal/views/GetTheWallet.d.ts +1 -0
- package/dist/esm/components/connect-modal/views/GetTheWallet.js +112 -0
- package/dist/esm/components/connect-modal/views/GetTheWallet.js.map +7 -0
- package/dist/esm/components/connect-modal/views/GettingStarted.css +4 -5
- package/dist/esm/components/connect-modal/views/GettingStarted.css.css.map +1 -1
- package/dist/esm/components/connect-modal/views/GettingStarted.css.map +3 -3
- package/dist/esm/components/connect-modal/views/GettingStarted.js +2 -2
- package/dist/esm/components/connect-modal/views/GettingStarted.js.map +1 -1
- package/dist/esm/components/connect-modal/views/WhatIsAWallet.css.css.map +1 -1
- package/dist/esm/components/connect-modal/views/WhatIsAWallet.css.map +1 -1
- package/dist/esm/components/connect-modal/views/index.css +205 -0
- package/dist/esm/components/connect-modal/views/index.css.map +7 -0
- package/dist/esm/components/connect-modal/views/index.d.ts +3 -0
- package/dist/esm/components/connect-modal/views/index.js +253 -0
- package/dist/esm/components/connect-modal/views/index.js.map +7 -0
- package/dist/esm/components/connect-modal/wallet-list/WalletList.css.css.map +1 -1
- package/dist/esm/components/connect-modal/wallet-list/WalletList.css.map +1 -1
- package/dist/esm/components/connect-modal/wallet-list/WalletList.js +1 -1
- package/dist/esm/components/connect-modal/wallet-list/WalletList.js.map +2 -2
- package/dist/esm/components/connect-modal/wallet-list/WalletListItem.css.css.map +1 -1
- package/dist/esm/components/connect-modal/wallet-list/WalletListItem.css.map +1 -1
- package/dist/esm/components/connect-modal/wallet-list/WalletListItem.js.map +1 -1
- package/dist/esm/components/icons/ArrowRightIcon.d.ts +2 -0
- package/dist/esm/components/icons/ArrowRightIcon.js +26 -0
- package/dist/esm/components/icons/ArrowRightIcon.js.map +7 -0
- package/dist/esm/components/icons/ArrowTopRightIcon.d.ts +2 -0
- package/dist/esm/components/icons/ArrowTopRightIcon.js +26 -0
- package/dist/esm/components/icons/ArrowTopRightIcon.js.map +7 -0
- package/dist/esm/components/styling/InjectedThemeStyles.js +15 -8
- package/dist/esm/components/styling/InjectedThemeStyles.js.map +2 -2
- package/dist/esm/components/styling/StyleMarker.css.css.map +1 -1
- package/dist/esm/components/styling/StyleMarker.css.js +2 -2
- package/dist/esm/components/styling/StyleMarker.css.js.map +3 -3
- package/dist/esm/components/styling/StyleMarker.css.map +1 -1
- package/dist/esm/components/styling/StyleMarker.d.ts +0 -1
- package/dist/esm/components/styling/StyleMarker.js +2 -2
- package/dist/esm/components/styling/StyleMarker.js.map +3 -3
- package/dist/esm/components/ui/Button.css +4 -5
- package/dist/esm/components/ui/Button.css.css +4 -5
- package/dist/esm/components/ui/Button.css.css.map +3 -3
- package/dist/esm/components/ui/Button.css.d.ts +0 -1
- package/dist/esm/components/ui/Button.css.js.map +1 -1
- package/dist/esm/components/ui/Button.css.map +3 -3
- package/dist/esm/components/ui/Button.d.ts +1 -1
- package/dist/esm/components/ui/Button.js.map +1 -1
- package/dist/esm/components/ui/Heading.css.css.map +1 -1
- package/dist/esm/components/ui/Heading.css.map +1 -1
- package/dist/esm/components/ui/Heading.d.ts +0 -1
- package/dist/esm/components/ui/IconButton.css +1 -5
- package/dist/esm/components/ui/IconButton.css.css +1 -5
- package/dist/esm/components/ui/IconButton.css.css.map +3 -3
- package/dist/esm/components/ui/IconButton.css.js.map +1 -1
- package/dist/esm/components/ui/IconButton.css.map +3 -3
- package/dist/esm/components/ui/IconButton.d.ts +1 -1
- package/dist/esm/components/ui/IconButton.js.map +1 -1
- package/dist/esm/components/ui/Text.css.css.map +1 -1
- package/dist/esm/components/ui/Text.css.map +1 -1
- package/dist/esm/components/ui/Text.d.ts +0 -1
- package/dist/esm/constants/styleDataAttribute.js.map +1 -1
- package/dist/esm/constants/walletDefaults.d.ts +3 -2
- package/dist/esm/constants/walletDefaults.js +8 -6
- package/dist/esm/constants/walletDefaults.js.map +2 -2
- package/dist/esm/constants/walletMutationKeys.d.ts +3 -2
- package/dist/esm/constants/walletMutationKeys.js +4 -3
- package/dist/esm/constants/walletMutationKeys.js.map +2 -2
- package/dist/esm/contexts/walletContext.d.ts +1 -2
- package/dist/esm/hooks/useIotaClientInfiniteQuery.js.map +2 -2
- package/dist/esm/hooks/useIotaClientQuery.js +3 -1
- package/dist/esm/hooks/useIotaClientQuery.js.map +2 -2
- package/dist/esm/hooks/wallet/useAutoConnectWallet.js +17 -7
- package/dist/esm/hooks/wallet/useAutoConnectWallet.js.map +2 -2
- package/dist/esm/hooks/wallet/useConnectWallet.js +10 -4
- package/dist/esm/hooks/wallet/useConnectWallet.js.map +2 -2
- package/dist/esm/hooks/wallet/useCurrentWallet.d.ts +3 -0
- package/dist/esm/hooks/wallet/useCurrentWallet.js +7 -3
- package/dist/esm/hooks/wallet/useCurrentWallet.js.map +2 -2
- package/dist/esm/hooks/wallet/useDisconnectWallet.js +11 -6
- package/dist/esm/hooks/wallet/useDisconnectWallet.js.map +2 -2
- package/dist/esm/hooks/wallet/useReportTransactionEffects.d.ts +15 -0
- package/dist/esm/hooks/wallet/{useSignTransactionBlock.js → useReportTransactionEffects.js} +38 -34
- package/dist/esm/hooks/wallet/useReportTransactionEffects.js.map +7 -0
- package/dist/esm/hooks/wallet/useSignAndExecuteTransaction.d.ts +29 -0
- package/dist/esm/hooks/wallet/useSignAndExecuteTransaction.js +231 -0
- package/dist/esm/hooks/wallet/useSignAndExecuteTransaction.js.map +7 -0
- package/dist/esm/hooks/wallet/useSignPersonalMessage.js +21 -27
- package/dist/esm/hooks/wallet/useSignPersonalMessage.js.map +2 -2
- package/dist/esm/hooks/wallet/useSignTransaction.d.ts +18 -0
- package/dist/esm/hooks/wallet/{useSignAndExecuteTransactionBlock.js → useSignTransaction.js} +83 -43
- package/dist/esm/hooks/wallet/useSignTransaction.js.map +7 -0
- package/dist/esm/hooks/wallet/useSwitchAccount.js +11 -6
- package/dist/esm/hooks/wallet/useSwitchAccount.js.map +2 -2
- package/dist/esm/hooks/wallet/useUnsafeBurnerWallet.js +44 -32
- package/dist/esm/hooks/wallet/useUnsafeBurnerWallet.js.map +2 -2
- package/dist/esm/hooks/wallet/useWalletPropertiesChanged.js +7 -3
- package/dist/esm/hooks/wallet/useWalletPropertiesChanged.js.map +2 -2
- package/dist/esm/hooks/wallet/useWalletsChanged.d.ts +1 -1
- package/dist/esm/hooks/wallet/useWalletsChanged.js +7 -6
- package/dist/esm/hooks/wallet/useWalletsChanged.js.map +2 -2
- package/dist/esm/index.css +5 -10
- package/dist/esm/index.css.map +3 -3
- package/dist/esm/index.d.ts +4 -3
- package/dist/esm/index.js +424 -274
- package/dist/esm/index.js.map +4 -4
- package/dist/esm/themes/darkTheme.d.ts +2 -0
- package/dist/esm/themes/darkTheme.js +67 -0
- package/dist/esm/themes/darkTheme.js.map +7 -0
- package/dist/esm/themes/lightTheme.js +13 -8
- package/dist/esm/themes/lightTheme.js.map +2 -2
- package/dist/esm/themes/themeContract.d.ts +22 -12
- package/dist/esm/themes/themeContract.js +13 -8
- package/dist/esm/themes/themeContract.js.map +2 -2
- package/dist/esm/types.d.ts +1 -1
- package/dist/esm/utils/assertUnreachable.js.map +1 -1
- package/dist/esm/utils/walletUtils.d.ts +2 -2
- package/dist/esm/utils/walletUtils.js +2 -2
- package/dist/esm/utils/walletUtils.js.map +2 -2
- package/dist/esm/walletStore.d.ts +3 -2
- package/dist/esm/walletStore.js +8 -4
- package/dist/esm/walletStore.js.map +2 -2
- package/dist/index.css/package.json +5 -0
- package/dist/tsconfig.esm.tsbuildinfo +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +27 -28
- package/src/components/AccountDropdownMenu.tsx +5 -12
- package/src/components/ConnectButton.tsx +8 -4
- package/src/components/WalletProvider.tsx +9 -9
- package/src/components/connect-modal/views/GetTheWallet.css.ts +38 -0
- package/src/components/connect-modal/views/GetTheWallet.tsx +25 -0
- package/src/components/connect-modal/views/GettingStarted.tsx +3 -3
- package/src/components/connect-modal/views/index.ts +6 -0
- package/src/components/connect-modal/wallet-list/WalletList.tsx +1 -1
- package/src/components/icons/ArrowRightIcon.tsx +23 -0
- package/src/components/icons/ArrowTopRightIcon.tsx +23 -0
- package/src/components/styling/InjectedThemeStyles.tsx +4 -0
- package/src/components/ui/Button.css.ts +3 -5
- package/src/components/ui/IconButton.css.ts +0 -3
- package/src/constants/walletDefaults.ts +11 -5
- package/src/constants/walletMutationKeys.ts +3 -2
- package/src/hooks/useIotaClientInfiniteQuery.ts +2 -1
- package/src/hooks/useIotaClientQuery.ts +3 -1
- package/src/hooks/wallet/useAutoConnectWallet.ts +1 -1
- package/src/hooks/wallet/useConnectWallet.ts +6 -1
- package/src/hooks/wallet/useCurrentWallet.ts +4 -0
- package/src/hooks/wallet/useReportTransactionEffects.ts +87 -0
- package/src/hooks/wallet/useSignAndExecuteTransaction.ts +165 -0
- package/src/hooks/wallet/useSignPersonalMessage.ts +11 -25
- package/src/hooks/wallet/useSignTransaction.ts +117 -0
- package/src/hooks/wallet/useUnsafeBurnerWallet.ts +41 -18
- package/src/hooks/wallet/useWalletsChanged.ts +5 -4
- package/src/index.ts +4 -3
- package/src/themes/darkTheme.ts +69 -0
- package/src/themes/lightTheme.ts +11 -6
- package/src/themes/themeContract.ts +11 -6
- package/src/types.ts +1 -1
- package/src/utils/walletUtils.ts +8 -3
- package/src/walletStore.ts +12 -1
- package/dist/cjs/hooks/useResolveIotaNSNames.d.ts +0 -3
- package/dist/cjs/hooks/useResolveIotaNSNames.js +0 -83
- package/dist/cjs/hooks/useResolveIotaNSNames.js.map +0 -7
- package/dist/cjs/hooks/wallet/useSignAndExecuteTransactionBlock.d.ts +0 -15
- package/dist/cjs/hooks/wallet/useSignAndExecuteTransactionBlock.js.map +0 -7
- package/dist/cjs/hooks/wallet/useSignTransactionBlock.d.ts +0 -13
- package/dist/cjs/hooks/wallet/useSignTransactionBlock.js.map +0 -7
- package/dist/esm/hooks/useResolveIotaNSNames.d.ts +0 -3
- package/dist/esm/hooks/useResolveIotaNSNames.js +0 -60
- package/dist/esm/hooks/useResolveIotaNSNames.js.map +0 -7
- package/dist/esm/hooks/wallet/useSignAndExecuteTransactionBlock.d.ts +0 -15
- package/dist/esm/hooks/wallet/useSignAndExecuteTransactionBlock.js.map +0 -7
- package/dist/esm/hooks/wallet/useSignTransactionBlock.d.ts +0 -13
- package/dist/esm/hooks/wallet/useSignTransactionBlock.js.map +0 -7
- package/src/hooks/useResolveIotaNSNames.ts +0 -31
- package/src/hooks/wallet/useSignAndExecuteTransactionBlock.ts +0 -117
- package/src/hooks/wallet/useSignTransactionBlock.ts +0 -85
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
|
|
20
|
-
// src/hooks/useResolveIotaNSNames.ts
|
|
21
|
-
var useResolveIotaNSNames_exports = {};
|
|
22
|
-
__export(useResolveIotaNSNames_exports, {
|
|
23
|
-
useResolveIotaNSName: () => useResolveIotaNSName
|
|
24
|
-
});
|
|
25
|
-
module.exports = __toCommonJS(useResolveIotaNSNames_exports);
|
|
26
|
-
|
|
27
|
-
// src/hooks/useIotaClientQuery.ts
|
|
28
|
-
var import_react_query = require("@tanstack/react-query");
|
|
29
|
-
|
|
30
|
-
// src/hooks/useIotaClient.ts
|
|
31
|
-
var import_react2 = require("react");
|
|
32
|
-
|
|
33
|
-
// src/components/IotaClientProvider.tsx
|
|
34
|
-
var import_client = require("@iota/iota-sdk/client");
|
|
35
|
-
var import_react = require("react");
|
|
36
|
-
var import_jsx_runtime = require("react/jsx-runtime");
|
|
37
|
-
var IotaClientContext = (0, import_react.createContext)(null);
|
|
38
|
-
var DEFAULT_NETWORKS = {
|
|
39
|
-
localnet: { url: (0, import_client.getNetwork)(import_client.Network.Local).url }
|
|
40
|
-
};
|
|
41
|
-
|
|
42
|
-
// src/hooks/useIotaClient.ts
|
|
43
|
-
function useIotaClientContext() {
|
|
44
|
-
const iotaClient = (0, import_react2.useContext)(IotaClientContext);
|
|
45
|
-
if (!iotaClient) {
|
|
46
|
-
throw new Error(
|
|
47
|
-
"Could not find IotaClientContext. Ensure that you have set up the IotaClientProvider"
|
|
48
|
-
);
|
|
49
|
-
}
|
|
50
|
-
return iotaClient;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
// src/hooks/useIotaClientQuery.ts
|
|
54
|
-
function useIotaClientQuery(...args) {
|
|
55
|
-
const [method, params, { queryKey = [], ...options } = {}] = args;
|
|
56
|
-
const iotaContext = useIotaClientContext();
|
|
57
|
-
return (0, import_react_query.useQuery)({
|
|
58
|
-
...options,
|
|
59
|
-
queryKey: [iotaContext.network, method, params, ...queryKey],
|
|
60
|
-
queryFn: async () => {
|
|
61
|
-
return await iotaContext.client[method](params);
|
|
62
|
-
}
|
|
63
|
-
});
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
// src/hooks/useResolveIotaNSNames.ts
|
|
67
|
-
function useResolveIotaNSName(address, options) {
|
|
68
|
-
return useIotaClientQuery(
|
|
69
|
-
"resolveNameServiceNames",
|
|
70
|
-
{
|
|
71
|
-
address,
|
|
72
|
-
limit: 1
|
|
73
|
-
},
|
|
74
|
-
{
|
|
75
|
-
...options,
|
|
76
|
-
refetchOnWindowFocus: false,
|
|
77
|
-
retry: false,
|
|
78
|
-
select: (data) => data.data.length > 0 ? data.data[0] : null,
|
|
79
|
-
enabled: !!address && options?.enabled !== false
|
|
80
|
-
}
|
|
81
|
-
);
|
|
82
|
-
}
|
|
83
|
-
//# sourceMappingURL=useResolveIotaNSNames.js.map
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../../src/hooks/useResolveIotaNSNames.ts", "../../../src/hooks/useIotaClientQuery.ts", "../../../src/hooks/useIotaClient.ts", "../../../src/components/IotaClientProvider.tsx"],
|
|
4
|
-
"sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// Modifications Copyright (c) 2024 IOTA Stiftung\n// SPDX-License-Identifier: Apache-2.0\n\nimport type { ResolvedNameServiceNames } from '@iota/iota-sdk/client';\nimport type { UseQueryOptions, UseQueryResult } from '@tanstack/react-query';\n\nimport { useIotaClientQuery } from './useIotaClientQuery.js';\n\nexport function useResolveIotaNSName(\n address?: string | null,\n options?: Omit<\n UseQueryOptions<ResolvedNameServiceNames, Error, string | null, unknown[]>,\n 'queryFn' | 'queryKey' | 'select'\n >,\n): UseQueryResult<string | null, Error> {\n return useIotaClientQuery(\n 'resolveNameServiceNames',\n {\n address: address!,\n limit: 1,\n },\n {\n ...options,\n refetchOnWindowFocus: false,\n retry: false,\n select: (data) => (data.data.length > 0 ? data.data[0] : null),\n enabled: !!address && options?.enabled !== false,\n },\n );\n}\n", "// Copyright (c) Mysten Labs, Inc.\n// Modifications Copyright (c) 2024 IOTA Stiftung\n// SPDX-License-Identifier: Apache-2.0\n\nimport type { IotaClient } from '@iota/iota-sdk/client';\nimport type { UseQueryOptions, UseQueryResult } from '@tanstack/react-query';\nimport { useQuery } from '@tanstack/react-query';\n\nimport type { PartialBy } from '../types/utilityTypes.js';\nimport { useIotaClientContext } from './useIotaClient.js';\n\nexport type IotaRpcMethodName = {\n [K in keyof IotaClient]: IotaClient[K] extends\n | ((input: any) => Promise<any>)\n | (() => Promise<any>)\n ? K\n : never;\n}[keyof IotaClient];\n\nexport type IotaRpcMethods = {\n [K in IotaRpcMethodName]: IotaClient[K] extends (input: infer P) => Promise<infer R>\n ? {\n name: K;\n result: R;\n params: P;\n }\n : IotaClient[K] extends () => Promise<infer R>\n ? {\n name: K;\n result: R;\n params: undefined | object;\n }\n : never;\n};\n\nexport type UseIotaClientQueryOptions<T extends keyof IotaRpcMethods, TData> = PartialBy<\n Omit<UseQueryOptions<IotaRpcMethods[T]['result'], Error, TData, unknown[]>, 'queryFn'>,\n 'queryKey'\n>;\n\nexport function useIotaClientQuery<\n T extends keyof IotaRpcMethods,\n TData = IotaRpcMethods[T]['result'],\n>(\n ...args: undefined extends IotaRpcMethods[T]['params']\n ? [\n method: T,\n params?: IotaRpcMethods[T]['params'],\n options?: UseIotaClientQueryOptions<T, TData>,\n ]\n : [\n method: T,\n params: IotaRpcMethods[T]['params'],\n options?: UseIotaClientQueryOptions<T, TData>,\n ]\n): UseQueryResult<TData, Error> {\n const [method, params, { queryKey = [], ...options } = {}] = args as [\n method: T,\n params?: IotaRpcMethods[T]['params'],\n options?: UseIotaClientQueryOptions<T, TData>,\n ];\n\n const iotaContext = useIotaClientContext();\n\n return useQuery({\n ...options,\n queryKey: [iotaContext.network, method, params, ...queryKey],\n queryFn: async () => {\n return await iotaContext.client[method](params as never);\n },\n });\n}\n", "// Copyright (c) Mysten Labs, Inc.\n// Modifications Copyright (c) 2024 IOTA Stiftung\n// SPDX-License-Identifier: Apache-2.0\n\nimport type { IotaClient } from '@iota/iota-sdk/client';\nimport { useContext } from 'react';\n\nimport { IotaClientContext } from '../components/IotaClientProvider.js';\n\nexport function useIotaClientContext() {\n const iotaClient = useContext(IotaClientContext);\n\n if (!iotaClient) {\n throw new Error(\n 'Could not find IotaClientContext. Ensure that you have set up the IotaClientProvider',\n );\n }\n\n return iotaClient;\n}\n\nexport function useIotaClient(): IotaClient {\n return useIotaClientContext().client;\n}\n", "// Copyright (c) Mysten Labs, Inc.\n// Modifications Copyright (c) 2024 IOTA Stiftung\n// SPDX-License-Identifier: Apache-2.0\n\nimport { getNetwork, isIotaClient, Network, IotaClient } from '@iota/iota-sdk/client';\nimport type { IotaClientOptions } from '@iota/iota-sdk/client';\nimport { createContext, useMemo, useState } from 'react';\n\nimport type { NetworkConfig } from '../hooks/networkConfig.js';\n\ntype NetworkConfigs<T extends NetworkConfig | IotaClient = NetworkConfig | IotaClient> = Record<\n string,\n T\n>;\n\nexport interface IotaClientProviderContext {\n client: IotaClient;\n networks: NetworkConfigs;\n network: string;\n config: NetworkConfig | null;\n selectNetwork: (network: string) => void;\n}\n\nexport const IotaClientContext = createContext<IotaClientProviderContext | null>(null);\n\nexport type IotaClientProviderProps<T extends NetworkConfigs> = {\n createClient?: (name: keyof T, config: T[keyof T]) => IotaClient;\n children: React.ReactNode;\n networks?: T;\n onNetworkChange?: (network: keyof T & string) => void;\n} & (\n | {\n defaultNetwork?: keyof T & string;\n network?: never;\n }\n | {\n defaultNetwork?: never;\n network?: keyof T & string;\n }\n);\n\nconst DEFAULT_NETWORKS = {\n localnet: { url: getNetwork(Network.Local).url },\n};\n\nconst DEFAULT_CREATE_CLIENT = function createClient(\n _name: string,\n config: NetworkConfig | IotaClient,\n) {\n if (isIotaClient(config)) {\n return config;\n }\n\n return new IotaClient(config);\n};\n\nexport function IotaClientProvider<T extends NetworkConfigs>(props: IotaClientProviderProps<T>) {\n const { onNetworkChange, network, children } = props;\n const networks = (props.networks ?? DEFAULT_NETWORKS) as T;\n const createClient =\n (props.createClient as typeof DEFAULT_CREATE_CLIENT) ?? DEFAULT_CREATE_CLIENT;\n\n const [selectedNetwork, setSelectedNetwork] = useState<keyof T & string>(\n props.network ?? props.defaultNetwork ?? (Object.keys(networks)[0] as keyof T & string),\n );\n\n const currentNetwork = props.network ?? selectedNetwork;\n\n const client = useMemo(() => {\n return createClient(currentNetwork, networks[currentNetwork]);\n }, [createClient, currentNetwork, networks]);\n\n const ctx = useMemo((): IotaClientProviderContext => {\n return {\n client,\n networks,\n network: currentNetwork,\n config:\n networks[currentNetwork] instanceof IotaClient\n ? null\n : (networks[currentNetwork] as IotaClientOptions),\n selectNetwork: (newNetwork) => {\n if (currentNetwork === newNetwork) {\n return;\n }\n\n if (!network && newNetwork !== selectedNetwork) {\n setSelectedNetwork(newNetwork);\n }\n\n onNetworkChange?.(newNetwork);\n },\n };\n }, [client, networks, selectedNetwork, currentNetwork, network, onNetworkChange]);\n\n return <IotaClientContext.Provider value={ctx}>{children}</IotaClientContext.Provider>;\n}\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACMA,yBAAyB;;;ACDzB,IAAAA,gBAA2B;;;ACD3B,oBAA8D;AAE9D,mBAAiD;AAyFtC;AAxEJ,IAAM,wBAAoB,4BAAgD,IAAI;AAkBrF,IAAM,mBAAmB;AAAA,EACrB,UAAU,EAAE,SAAK,0BAAW,sBAAQ,KAAK,EAAE,IAAI;AACnD;;;ADlCO,SAAS,uBAAuB;AACnC,QAAM,iBAAa,0BAAW,iBAAiB;AAE/C,MAAI,CAAC,YAAY;AACb,UAAM,IAAI;AAAA,MACN;AAAA,IACJ;AAAA,EACJ;AAEA,SAAO;AACX;;;ADqBO,SAAS,sBAIT,MAWyB;AAC5B,QAAM,CAAC,QAAQ,QAAQ,EAAE,WAAW,CAAC,GAAG,GAAG,QAAQ,IAAI,CAAC,CAAC,IAAI;AAM7D,QAAM,cAAc,qBAAqB;AAEzC,aAAO,6BAAS;AAAA,IACZ,GAAG;AAAA,IACH,UAAU,CAAC,YAAY,SAAS,QAAQ,QAAQ,GAAG,QAAQ;AAAA,IAC3D,SAAS,YAAY;AACjB,aAAO,MAAM,YAAY,OAAO,MAAM,EAAE,MAAe;AAAA,IAC3D;AAAA,EACJ,CAAC;AACL;;;AD9DO,SAAS,qBACZ,SACA,SAIoC;AACpC,SAAO;AAAA,IACH;AAAA,IACA;AAAA,MACI;AAAA,MACA,OAAO;AAAA,IACX;AAAA,IACA;AAAA,MACI,GAAG;AAAA,MACH,sBAAsB;AAAA,MACtB,OAAO;AAAA,MACP,QAAQ,CAAC,SAAU,KAAK,KAAK,SAAS,IAAI,KAAK,KAAK,CAAC,IAAI;AAAA,MACzD,SAAS,CAAC,CAAC,WAAW,SAAS,YAAY;AAAA,IAC/C;AAAA,EACJ;AACJ;",
|
|
6
|
-
"names": ["import_react"]
|
|
7
|
-
}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import type { IotaSignAndExecuteTransactionBlockInput, IotaSignAndExecuteTransactionBlockOutput } from '@iota/wallet-standard';
|
|
2
|
-
import type { UseMutationOptions, UseMutationResult } from '@tanstack/react-query';
|
|
3
|
-
import { WalletFeatureNotSupportedError, WalletNoAccountSelectedError, WalletNotConnectedError } from '../../errors/walletErrors.js';
|
|
4
|
-
import type { PartialBy } from '../../types/utilityTypes.js';
|
|
5
|
-
type UseSignAndExecuteTransactionBlockArgs = PartialBy<IotaSignAndExecuteTransactionBlockInput, 'account' | 'chain'>;
|
|
6
|
-
type UseSignAndExecuteTransactionBlockResult = IotaSignAndExecuteTransactionBlockOutput;
|
|
7
|
-
type UseSignAndExecuteTransactionBlockError = WalletFeatureNotSupportedError | WalletNoAccountSelectedError | WalletNotConnectedError | Error;
|
|
8
|
-
type UseSignAndExecuteTransactionBlockMutationOptions = Omit<UseMutationOptions<UseSignAndExecuteTransactionBlockResult, UseSignAndExecuteTransactionBlockError, UseSignAndExecuteTransactionBlockArgs, unknown>, 'mutationFn'> & {
|
|
9
|
-
executeFromWallet?: boolean;
|
|
10
|
-
};
|
|
11
|
-
/**
|
|
12
|
-
* Mutation hook for prompting the user to sign and execute a transaction block.
|
|
13
|
-
*/
|
|
14
|
-
export declare function useSignAndExecuteTransactionBlock({ mutationKey, executeFromWallet, ...mutationOptions }?: UseSignAndExecuteTransactionBlockMutationOptions): UseMutationResult<UseSignAndExecuteTransactionBlockResult, UseSignAndExecuteTransactionBlockError, UseSignAndExecuteTransactionBlockArgs>;
|
|
15
|
-
export {};
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../../../src/hooks/wallet/useSignAndExecuteTransactionBlock.ts", "../../../../src/constants/walletMutationKeys.ts", "../../../../src/errors/walletErrors.ts", "../../../../src/hooks/useIotaClient.ts", "../../../../src/components/IotaClientProvider.tsx", "../../../../src/hooks/wallet/useWalletStore.ts", "../../../../src/contexts/walletContext.ts", "../../../../src/hooks/wallet/useCurrentAccount.ts", "../../../../src/hooks/wallet/useCurrentWallet.ts"],
|
|
4
|
-
"sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// Modifications Copyright (c) 2024 IOTA Stiftung\n// SPDX-License-Identifier: Apache-2.0\n\nimport type {\n IotaSignAndExecuteTransactionBlockInput,\n IotaSignAndExecuteTransactionBlockOutput,\n} from '@iota/wallet-standard';\nimport type { UseMutationOptions, UseMutationResult } from '@tanstack/react-query';\nimport { useMutation } from '@tanstack/react-query';\n\nimport { walletMutationKeys } from '../../constants/walletMutationKeys.js';\nimport {\n WalletFeatureNotSupportedError,\n WalletNoAccountSelectedError,\n WalletNotConnectedError,\n} from '../../errors/walletErrors.js';\nimport type { PartialBy } from '../../types/utilityTypes.js';\nimport { useIotaClient } from '../useIotaClient.js';\nimport { useCurrentAccount } from './useCurrentAccount.js';\nimport { useCurrentWallet } from './useCurrentWallet.js';\n\ntype UseSignAndExecuteTransactionBlockArgs = PartialBy<\n IotaSignAndExecuteTransactionBlockInput,\n 'account' | 'chain'\n>;\n\ntype UseSignAndExecuteTransactionBlockResult = IotaSignAndExecuteTransactionBlockOutput;\n\ntype UseSignAndExecuteTransactionBlockError =\n | WalletFeatureNotSupportedError\n | WalletNoAccountSelectedError\n | WalletNotConnectedError\n | Error;\n\ntype UseSignAndExecuteTransactionBlockMutationOptions = Omit<\n UseMutationOptions<\n UseSignAndExecuteTransactionBlockResult,\n UseSignAndExecuteTransactionBlockError,\n UseSignAndExecuteTransactionBlockArgs,\n unknown\n >,\n 'mutationFn'\n> & {\n executeFromWallet?: boolean;\n};\n\n/**\n * Mutation hook for prompting the user to sign and execute a transaction block.\n */\nexport function useSignAndExecuteTransactionBlock({\n mutationKey,\n executeFromWallet,\n ...mutationOptions\n}: UseSignAndExecuteTransactionBlockMutationOptions = {}): UseMutationResult<\n UseSignAndExecuteTransactionBlockResult,\n UseSignAndExecuteTransactionBlockError,\n UseSignAndExecuteTransactionBlockArgs\n> {\n const { currentWallet } = useCurrentWallet();\n const currentAccount = useCurrentAccount();\n const client = useIotaClient();\n\n return useMutation({\n mutationKey: walletMutationKeys.signAndExecuteTransactionBlock(mutationKey),\n mutationFn: async ({ requestType, options, ...signTransactionBlockArgs }) => {\n if (!currentWallet) {\n throw new WalletNotConnectedError('No wallet is connected.');\n }\n\n const signerAccount = signTransactionBlockArgs.account ?? currentAccount;\n if (!signerAccount) {\n throw new WalletNoAccountSelectedError(\n 'No wallet account is selected to sign and execute the transaction block with.',\n );\n }\n\n if (executeFromWallet) {\n const walletFeature = currentWallet.features['iota:signAndExecuteTransactionBlock'];\n if (!walletFeature) {\n throw new WalletFeatureNotSupportedError(\n \"This wallet doesn't support the `signAndExecuteTransactionBlock` feature.\",\n );\n }\n\n return walletFeature.signAndExecuteTransactionBlock({\n ...signTransactionBlockArgs,\n account: signerAccount,\n chain: signTransactionBlockArgs.chain ?? signerAccount.chains[0],\n requestType,\n options,\n });\n }\n\n const walletFeature = currentWallet.features['iota:signTransactionBlock'];\n if (!walletFeature) {\n throw new WalletFeatureNotSupportedError(\n \"This wallet doesn't support the `signTransactionBlock` feature.\",\n );\n }\n\n const { signature, transactionBlockBytes } = await walletFeature.signTransactionBlock({\n ...signTransactionBlockArgs,\n account: signerAccount,\n chain: signTransactionBlockArgs.chain ?? signerAccount.chains[0],\n });\n\n return client.executeTransactionBlock({\n transactionBlock: transactionBlockBytes,\n signature,\n requestType,\n options,\n });\n },\n ...mutationOptions,\n });\n}\n", "// Copyright (c) Mysten Labs, Inc.\n// Modifications Copyright (c) 2024 IOTA Stiftung\n// SPDX-License-Identifier: Apache-2.0\n\nimport type { MutationKey } from '@tanstack/react-query';\n\nexport const walletMutationKeys = {\n all: { baseScope: 'wallet' },\n connectWallet: formMutationKeyFn('connect-wallet'),\n autoconnectWallet: formMutationKeyFn('autoconnect-wallet'),\n disconnectWallet: formMutationKeyFn('disconnect-wallet'),\n signPersonalMessage: formMutationKeyFn('sign-personal-message'),\n signTransactionBlock: formMutationKeyFn('sign-transaction-block'),\n signAndExecuteTransactionBlock: formMutationKeyFn('sign-and-execute-transaction-block'),\n switchAccount: formMutationKeyFn('switch-account'),\n};\n\nfunction formMutationKeyFn(baseEntity: string) {\n return function mutationKeyFn(additionalKeys: MutationKey = []) {\n return [{ ...walletMutationKeys.all, baseEntity }, ...additionalKeys];\n };\n}\n", "// Copyright (c) Mysten Labs, Inc.\n// Modifications Copyright (c) 2024 IOTA Stiftung\n// SPDX-License-Identifier: Apache-2.0\n\n/**\n * An error that is instantiated when someone attempts to perform an action that requires an active wallet connection.\n */\nexport class WalletNotConnectedError extends Error {}\n\n/**\n * An error that is instantiated when someone attempts to perform an action that requires a selected wallet account.\n * This is more of an edge case stemming from the fact that wallets don't technically require you to authorize any\n * accounts when connecting a wallet.\n */\nexport class WalletNoAccountSelectedError extends Error {}\n\n/**\n * An error that is instantiated when someone attempts to perform an action that isn't supported by a wallet.\n */\nexport class WalletFeatureNotSupportedError extends Error {}\n\n/**\n * An error that is instantiated when a wallet account can't be found for a specific wallet.\n */\nexport class WalletAccountNotFoundError extends Error {}\n", "// Copyright (c) Mysten Labs, Inc.\n// Modifications Copyright (c) 2024 IOTA Stiftung\n// SPDX-License-Identifier: Apache-2.0\n\nimport type { IotaClient } from '@iota/iota-sdk/client';\nimport { useContext } from 'react';\n\nimport { IotaClientContext } from '../components/IotaClientProvider.js';\n\nexport function useIotaClientContext() {\n const iotaClient = useContext(IotaClientContext);\n\n if (!iotaClient) {\n throw new Error(\n 'Could not find IotaClientContext. Ensure that you have set up the IotaClientProvider',\n );\n }\n\n return iotaClient;\n}\n\nexport function useIotaClient(): IotaClient {\n return useIotaClientContext().client;\n}\n", "// Copyright (c) Mysten Labs, Inc.\n// Modifications Copyright (c) 2024 IOTA Stiftung\n// SPDX-License-Identifier: Apache-2.0\n\nimport { getNetwork, isIotaClient, Network, IotaClient } from '@iota/iota-sdk/client';\nimport type { IotaClientOptions } from '@iota/iota-sdk/client';\nimport { createContext, useMemo, useState } from 'react';\n\nimport type { NetworkConfig } from '../hooks/networkConfig.js';\n\ntype NetworkConfigs<T extends NetworkConfig | IotaClient = NetworkConfig | IotaClient> = Record<\n string,\n T\n>;\n\nexport interface IotaClientProviderContext {\n client: IotaClient;\n networks: NetworkConfigs;\n network: string;\n config: NetworkConfig | null;\n selectNetwork: (network: string) => void;\n}\n\nexport const IotaClientContext = createContext<IotaClientProviderContext | null>(null);\n\nexport type IotaClientProviderProps<T extends NetworkConfigs> = {\n createClient?: (name: keyof T, config: T[keyof T]) => IotaClient;\n children: React.ReactNode;\n networks?: T;\n onNetworkChange?: (network: keyof T & string) => void;\n} & (\n | {\n defaultNetwork?: keyof T & string;\n network?: never;\n }\n | {\n defaultNetwork?: never;\n network?: keyof T & string;\n }\n);\n\nconst DEFAULT_NETWORKS = {\n localnet: { url: getNetwork(Network.Local).url },\n};\n\nconst DEFAULT_CREATE_CLIENT = function createClient(\n _name: string,\n config: NetworkConfig | IotaClient,\n) {\n if (isIotaClient(config)) {\n return config;\n }\n\n return new IotaClient(config);\n};\n\nexport function IotaClientProvider<T extends NetworkConfigs>(props: IotaClientProviderProps<T>) {\n const { onNetworkChange, network, children } = props;\n const networks = (props.networks ?? DEFAULT_NETWORKS) as T;\n const createClient =\n (props.createClient as typeof DEFAULT_CREATE_CLIENT) ?? DEFAULT_CREATE_CLIENT;\n\n const [selectedNetwork, setSelectedNetwork] = useState<keyof T & string>(\n props.network ?? props.defaultNetwork ?? (Object.keys(networks)[0] as keyof T & string),\n );\n\n const currentNetwork = props.network ?? selectedNetwork;\n\n const client = useMemo(() => {\n return createClient(currentNetwork, networks[currentNetwork]);\n }, [createClient, currentNetwork, networks]);\n\n const ctx = useMemo((): IotaClientProviderContext => {\n return {\n client,\n networks,\n network: currentNetwork,\n config:\n networks[currentNetwork] instanceof IotaClient\n ? null\n : (networks[currentNetwork] as IotaClientOptions),\n selectNetwork: (newNetwork) => {\n if (currentNetwork === newNetwork) {\n return;\n }\n\n if (!network && newNetwork !== selectedNetwork) {\n setSelectedNetwork(newNetwork);\n }\n\n onNetworkChange?.(newNetwork);\n },\n };\n }, [client, networks, selectedNetwork, currentNetwork, network, onNetworkChange]);\n\n return <IotaClientContext.Provider value={ctx}>{children}</IotaClientContext.Provider>;\n}\n", "// Copyright (c) Mysten Labs, Inc.\n// Modifications Copyright (c) 2024 IOTA Stiftung\n// SPDX-License-Identifier: Apache-2.0\n\nimport { useContext } from 'react';\nimport { useStore } from 'zustand';\n\nimport { WalletContext } from '../../contexts/walletContext.js';\nimport type { StoreState } from '../../walletStore.js';\n\nexport function useWalletStore<T>(selector: (state: StoreState) => T): T {\n const store = useContext(WalletContext);\n if (!store) {\n throw new Error(\n 'Could not find WalletContext. Ensure that you have set up the WalletProvider.',\n );\n }\n return useStore(store, selector);\n}\n", "// Copyright (c) Mysten Labs, Inc.\n// Modifications Copyright (c) 2024 IOTA Stiftung\n// SPDX-License-Identifier: Apache-2.0\n\nimport { createContext } from 'react';\n\nimport type { WalletStore } from '../walletStore.js';\n\nexport const WalletContext = createContext<WalletStore | null>(null);\n", "// Copyright (c) Mysten Labs, Inc.\n// Modifications Copyright (c) 2024 IOTA Stiftung\n// SPDX-License-Identifier: Apache-2.0\n\nimport type { WalletAccount } from '@iota/wallet-standard';\n\nimport { useWalletStore } from './useWalletStore.js';\n\n/**\n * Retrieves the wallet account that is currently selected, if one exists.\n */\nexport function useCurrentAccount(): WalletAccount | null {\n return useWalletStore((state) => state.currentAccount);\n}\n", "// Copyright (c) Mysten Labs, Inc.\n// Modifications Copyright (c) 2024 IOTA Stiftung\n// SPDX-License-Identifier: Apache-2.0\n\nimport { useWalletStore } from './useWalletStore.js';\n\n/**\n * Retrieves the wallet that is currently connected to the dApp, if one exists.\n */\nexport function useCurrentWallet() {\n const currentWallet = useWalletStore((state) => state.currentWallet);\n const connectionStatus = useWalletStore((state) => state.connectionStatus);\n\n switch (connectionStatus) {\n case 'connecting':\n return {\n connectionStatus,\n currentWallet: null,\n isDisconnected: false,\n isConnecting: true,\n isConnected: false,\n } as const;\n case 'disconnected':\n return {\n connectionStatus,\n currentWallet: null,\n isDisconnected: true,\n isConnecting: false,\n isConnected: false,\n } as const;\n case 'connected': {\n return {\n connectionStatus,\n currentWallet: currentWallet!,\n isDisconnected: false,\n isConnecting: false,\n isConnected: true,\n } as const;\n }\n }\n}\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AASA,yBAA4B;;;ACHrB,IAAM,qBAAqB;AAAA,EAC9B,KAAK,EAAE,WAAW,SAAS;AAAA,EAC3B,eAAe,kBAAkB,gBAAgB;AAAA,EACjD,mBAAmB,kBAAkB,oBAAoB;AAAA,EACzD,kBAAkB,kBAAkB,mBAAmB;AAAA,EACvD,qBAAqB,kBAAkB,uBAAuB;AAAA,EAC9D,sBAAsB,kBAAkB,wBAAwB;AAAA,EAChE,gCAAgC,kBAAkB,oCAAoC;AAAA,EACtF,eAAe,kBAAkB,gBAAgB;AACrD;AAEA,SAAS,kBAAkB,YAAoB;AAC3C,SAAO,SAAS,cAAc,iBAA8B,CAAC,GAAG;AAC5D,WAAO,CAAC,EAAE,GAAG,mBAAmB,KAAK,WAAW,GAAG,GAAG,cAAc;AAAA,EACxE;AACJ;;;ACdO,IAAM,0BAAN,cAAsC,MAAM;AAAC;AAO7C,IAAM,+BAAN,cAA2C,MAAM;AAAC;AAKlD,IAAM,iCAAN,cAA6C,MAAM;AAAC;;;ACd3D,IAAA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,IACL;AAAA,IACA,GAAG;AAAA,EACP,CAAC;AACL;",
|
|
6
|
-
"names": ["import_react", "import_react", "import_react", "walletFeature"]
|
|
7
|
-
}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import type { IotaSignTransactionBlockInput, IotaSignTransactionBlockOutput } from '@iota/wallet-standard';
|
|
2
|
-
import type { UseMutationOptions, UseMutationResult } from '@tanstack/react-query';
|
|
3
|
-
import { WalletFeatureNotSupportedError, WalletNoAccountSelectedError, WalletNotConnectedError } from '../..//errors/walletErrors.js';
|
|
4
|
-
import type { PartialBy } from '../../types/utilityTypes.js';
|
|
5
|
-
type UseSignTransactionBlockArgs = PartialBy<IotaSignTransactionBlockInput, 'account' | 'chain'>;
|
|
6
|
-
type UseSignTransactionBlockResult = IotaSignTransactionBlockOutput;
|
|
7
|
-
type UseSignTransactionBlockError = WalletFeatureNotSupportedError | WalletNoAccountSelectedError | WalletNotConnectedError | Error;
|
|
8
|
-
type UseSignTransactionBlockMutationOptions = Omit<UseMutationOptions<UseSignTransactionBlockResult, UseSignTransactionBlockError, UseSignTransactionBlockArgs, unknown>, 'mutationFn'>;
|
|
9
|
-
/**
|
|
10
|
-
* Mutation hook for prompting the user to sign a transaction block.
|
|
11
|
-
*/
|
|
12
|
-
export declare function useSignTransactionBlock({ mutationKey, ...mutationOptions }?: UseSignTransactionBlockMutationOptions): UseMutationResult<UseSignTransactionBlockResult, UseSignTransactionBlockError, UseSignTransactionBlockArgs>;
|
|
13
|
-
export {};
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../../../src/hooks/wallet/useSignTransactionBlock.ts", "../../../../src/errors/walletErrors.ts", "../../../../src/constants/walletMutationKeys.ts", "../../../../src/hooks/wallet/useWalletStore.ts", "../../../../src/contexts/walletContext.ts", "../../../../src/hooks/wallet/useCurrentAccount.ts", "../../../../src/hooks/wallet/useCurrentWallet.ts"],
|
|
4
|
-
"sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// Modifications Copyright (c) 2024 IOTA Stiftung\n// SPDX-License-Identifier: Apache-2.0\n\nimport type {\n IotaSignTransactionBlockInput,\n IotaSignTransactionBlockOutput,\n} from '@iota/wallet-standard';\nimport type { UseMutationOptions, UseMutationResult } from '@tanstack/react-query';\nimport { useMutation } from '@tanstack/react-query';\n\nimport {\n WalletFeatureNotSupportedError,\n WalletNoAccountSelectedError,\n WalletNotConnectedError,\n} from '../..//errors/walletErrors.js';\nimport { walletMutationKeys } from '../../constants/walletMutationKeys.js';\nimport type { PartialBy } from '../../types/utilityTypes.js';\nimport { useCurrentAccount } from './useCurrentAccount.js';\nimport { useCurrentWallet } from './useCurrentWallet.js';\n\ntype UseSignTransactionBlockArgs = PartialBy<IotaSignTransactionBlockInput, 'account' | 'chain'>;\n\ntype UseSignTransactionBlockResult = IotaSignTransactionBlockOutput;\n\ntype UseSignTransactionBlockError =\n | WalletFeatureNotSupportedError\n | WalletNoAccountSelectedError\n | WalletNotConnectedError\n | Error;\n\ntype UseSignTransactionBlockMutationOptions = Omit<\n UseMutationOptions<\n UseSignTransactionBlockResult,\n UseSignTransactionBlockError,\n UseSignTransactionBlockArgs,\n unknown\n >,\n 'mutationFn'\n>;\n\n/**\n * Mutation hook for prompting the user to sign a transaction block.\n */\nexport function useSignTransactionBlock({\n mutationKey,\n ...mutationOptions\n}: UseSignTransactionBlockMutationOptions = {}): UseMutationResult<\n UseSignTransactionBlockResult,\n UseSignTransactionBlockError,\n UseSignTransactionBlockArgs\n> {\n const { currentWallet } = useCurrentWallet();\n const currentAccount = useCurrentAccount();\n\n return useMutation({\n mutationKey: walletMutationKeys.signTransactionBlock(mutationKey),\n mutationFn: async (signTransactionBlockArgs) => {\n if (!currentWallet) {\n throw new WalletNotConnectedError('No wallet is connected.');\n }\n\n const signerAccount = signTransactionBlockArgs.account ?? currentAccount;\n if (!signerAccount) {\n throw new WalletNoAccountSelectedError(\n 'No wallet account is selected to sign the transaction block with.',\n );\n }\n\n const walletFeature = currentWallet.features['iota:signTransactionBlock'];\n if (!walletFeature) {\n throw new WalletFeatureNotSupportedError(\n \"This wallet doesn't support the `SignTransactionBlock` feature.\",\n );\n }\n\n return await walletFeature.signTransactionBlock({\n ...signTransactionBlockArgs,\n account: signerAccount,\n chain: signTransactionBlockArgs.chain ?? signerAccount.chains[0],\n });\n },\n ...mutationOptions,\n });\n}\n", "// Copyright (c) Mysten Labs, Inc.\n// Modifications Copyright (c) 2024 IOTA Stiftung\n// SPDX-License-Identifier: Apache-2.0\n\n/**\n * An error that is instantiated when someone attempts to perform an action that requires an active wallet connection.\n */\nexport class WalletNotConnectedError extends Error {}\n\n/**\n * An error that is instantiated when someone attempts to perform an action that requires a selected wallet account.\n * This is more of an edge case stemming from the fact that wallets don't technically require you to authorize any\n * accounts when connecting a wallet.\n */\nexport class WalletNoAccountSelectedError extends Error {}\n\n/**\n * An error that is instantiated when someone attempts to perform an action that isn't supported by a wallet.\n */\nexport class WalletFeatureNotSupportedError extends Error {}\n\n/**\n * An error that is instantiated when a wallet account can't be found for a specific wallet.\n */\nexport class WalletAccountNotFoundError extends Error {}\n", "// Copyright (c) Mysten Labs, Inc.\n// Modifications Copyright (c) 2024 IOTA Stiftung\n// SPDX-License-Identifier: Apache-2.0\n\nimport type { MutationKey } from '@tanstack/react-query';\n\nexport const walletMutationKeys = {\n all: { baseScope: 'wallet' },\n connectWallet: formMutationKeyFn('connect-wallet'),\n autoconnectWallet: formMutationKeyFn('autoconnect-wallet'),\n disconnectWallet: formMutationKeyFn('disconnect-wallet'),\n signPersonalMessage: formMutationKeyFn('sign-personal-message'),\n signTransactionBlock: formMutationKeyFn('sign-transaction-block'),\n signAndExecuteTransactionBlock: formMutationKeyFn('sign-and-execute-transaction-block'),\n switchAccount: formMutationKeyFn('switch-account'),\n};\n\nfunction formMutationKeyFn(baseEntity: string) {\n return function mutationKeyFn(additionalKeys: MutationKey = []) {\n return [{ ...walletMutationKeys.all, baseEntity }, ...additionalKeys];\n };\n}\n", "// Copyright (c) Mysten Labs, Inc.\n// Modifications Copyright (c) 2024 IOTA Stiftung\n// SPDX-License-Identifier: Apache-2.0\n\nimport { useContext } from 'react';\nimport { useStore } from 'zustand';\n\nimport { WalletContext } from '../../contexts/walletContext.js';\nimport type { StoreState } from '../../walletStore.js';\n\nexport function useWalletStore<T>(selector: (state: StoreState) => T): T {\n const store = useContext(WalletContext);\n if (!store) {\n throw new Error(\n 'Could not find WalletContext. Ensure that you have set up the WalletProvider.',\n );\n }\n return useStore(store, selector);\n}\n", "// Copyright (c) Mysten Labs, Inc.\n// Modifications Copyright (c) 2024 IOTA Stiftung\n// SPDX-License-Identifier: Apache-2.0\n\nimport { createContext } from 'react';\n\nimport type { WalletStore } from '../walletStore.js';\n\nexport const WalletContext = createContext<WalletStore | null>(null);\n", "// Copyright (c) Mysten Labs, Inc.\n// Modifications Copyright (c) 2024 IOTA Stiftung\n// SPDX-License-Identifier: Apache-2.0\n\nimport type { WalletAccount } from '@iota/wallet-standard';\n\nimport { useWalletStore } from './useWalletStore.js';\n\n/**\n * Retrieves the wallet account that is currently selected, if one exists.\n */\nexport function useCurrentAccount(): WalletAccount | null {\n return useWalletStore((state) => state.currentAccount);\n}\n", "// Copyright (c) Mysten Labs, Inc.\n// Modifications Copyright (c) 2024 IOTA Stiftung\n// SPDX-License-Identifier: Apache-2.0\n\nimport { useWalletStore } from './useWalletStore.js';\n\n/**\n * Retrieves the wallet that is currently connected to the dApp, if one exists.\n */\nexport function useCurrentWallet() {\n const currentWallet = useWalletStore((state) => state.currentWallet);\n const connectionStatus = useWalletStore((state) => state.connectionStatus);\n\n switch (connectionStatus) {\n case 'connecting':\n return {\n connectionStatus,\n currentWallet: null,\n isDisconnected: false,\n isConnecting: true,\n isConnected: false,\n } as const;\n case 'disconnected':\n return {\n connectionStatus,\n currentWallet: null,\n isDisconnected: true,\n isConnecting: false,\n isConnected: false,\n } as const;\n case 'connected': {\n return {\n connectionStatus,\n currentWallet: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{ ResolvedNameServiceNames } from '@iota/iota-sdk/client';
|
|
2
|
-
import type { UseQueryOptions, UseQueryResult } from '@tanstack/react-query';
|
|
3
|
-
export declare function useResolveIotaNSName(address?: string | null, options?: Omit<UseQueryOptions<ResolvedNameServiceNames, Error, string | null, unknown[]>, 'queryFn' | 'queryKey' | 'select'>): UseQueryResult<string | null, Error>;
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
// src/hooks/useIotaClientQuery.ts
|
|
2
|
-
import { useQuery } from "@tanstack/react-query";
|
|
3
|
-
|
|
4
|
-
// src/hooks/useIotaClient.ts
|
|
5
|
-
import { useContext } from "react";
|
|
6
|
-
|
|
7
|
-
// src/components/IotaClientProvider.tsx
|
|
8
|
-
import { getNetwork, isIotaClient, Network, IotaClient } from "@iota/iota-sdk/client";
|
|
9
|
-
import { createContext, useMemo, useState } from "react";
|
|
10
|
-
import { jsx } from "react/jsx-runtime";
|
|
11
|
-
var IotaClientContext = createContext(null);
|
|
12
|
-
var DEFAULT_NETWORKS = {
|
|
13
|
-
localnet: { url: getNetwork(Network.Local).url }
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
// src/hooks/useIotaClient.ts
|
|
17
|
-
function useIotaClientContext() {
|
|
18
|
-
const iotaClient = useContext(IotaClientContext);
|
|
19
|
-
if (!iotaClient) {
|
|
20
|
-
throw new Error(
|
|
21
|
-
"Could not find IotaClientContext. Ensure that you have set up the IotaClientProvider"
|
|
22
|
-
);
|
|
23
|
-
}
|
|
24
|
-
return iotaClient;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
// src/hooks/useIotaClientQuery.ts
|
|
28
|
-
function useIotaClientQuery(...args) {
|
|
29
|
-
const [method, params, { queryKey = [], ...options } = {}] = args;
|
|
30
|
-
const iotaContext = useIotaClientContext();
|
|
31
|
-
return useQuery({
|
|
32
|
-
...options,
|
|
33
|
-
queryKey: [iotaContext.network, method, params, ...queryKey],
|
|
34
|
-
queryFn: async () => {
|
|
35
|
-
return await iotaContext.client[method](params);
|
|
36
|
-
}
|
|
37
|
-
});
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
// src/hooks/useResolveIotaNSNames.ts
|
|
41
|
-
function useResolveIotaNSName(address, options) {
|
|
42
|
-
return useIotaClientQuery(
|
|
43
|
-
"resolveNameServiceNames",
|
|
44
|
-
{
|
|
45
|
-
address,
|
|
46
|
-
limit: 1
|
|
47
|
-
},
|
|
48
|
-
{
|
|
49
|
-
...options,
|
|
50
|
-
refetchOnWindowFocus: false,
|
|
51
|
-
retry: false,
|
|
52
|
-
select: (data) => data.data.length > 0 ? data.data[0] : null,
|
|
53
|
-
enabled: !!address && options?.enabled !== false
|
|
54
|
-
}
|
|
55
|
-
);
|
|
56
|
-
}
|
|
57
|
-
export {
|
|
58
|
-
useResolveIotaNSName
|
|
59
|
-
};
|
|
60
|
-
//# sourceMappingURL=useResolveIotaNSNames.js.map
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../../src/hooks/useIotaClientQuery.ts", "../../../src/hooks/useIotaClient.ts", "../../../src/components/IotaClientProvider.tsx", "../../../src/hooks/useResolveIotaNSNames.ts"],
|
|
4
|
-
"sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// Modifications Copyright (c) 2024 IOTA Stiftung\n// SPDX-License-Identifier: Apache-2.0\n\nimport type { IotaClient } from '@iota/iota-sdk/client';\nimport type { UseQueryOptions, UseQueryResult } from '@tanstack/react-query';\nimport { useQuery } from '@tanstack/react-query';\n\nimport type { PartialBy } from '../types/utilityTypes.js';\nimport { useIotaClientContext } from './useIotaClient.js';\n\nexport type IotaRpcMethodName = {\n [K in keyof IotaClient]: IotaClient[K] extends\n | ((input: any) => Promise<any>)\n | (() => Promise<any>)\n ? K\n : never;\n}[keyof IotaClient];\n\nexport type IotaRpcMethods = {\n [K in IotaRpcMethodName]: IotaClient[K] extends (input: infer P) => Promise<infer R>\n ? {\n name: K;\n result: R;\n params: P;\n }\n : IotaClient[K] extends () => Promise<infer R>\n ? {\n name: K;\n result: R;\n params: undefined | object;\n }\n : never;\n};\n\nexport type UseIotaClientQueryOptions<T extends keyof IotaRpcMethods, TData> = PartialBy<\n Omit<UseQueryOptions<IotaRpcMethods[T]['result'], Error, TData, unknown[]>, 'queryFn'>,\n 'queryKey'\n>;\n\nexport function useIotaClientQuery<\n T extends keyof IotaRpcMethods,\n TData = IotaRpcMethods[T]['result'],\n>(\n ...args: undefined extends IotaRpcMethods[T]['params']\n ? [\n method: T,\n params?: IotaRpcMethods[T]['params'],\n options?: UseIotaClientQueryOptions<T, TData>,\n ]\n : [\n method: T,\n params: IotaRpcMethods[T]['params'],\n options?: UseIotaClientQueryOptions<T, TData>,\n ]\n): UseQueryResult<TData, Error> {\n const [method, params, { queryKey = [], ...options } = {}] = args as [\n method: T,\n params?: IotaRpcMethods[T]['params'],\n options?: UseIotaClientQueryOptions<T, TData>,\n ];\n\n const iotaContext = useIotaClientContext();\n\n return useQuery({\n ...options,\n queryKey: [iotaContext.network, method, params, ...queryKey],\n queryFn: async () => {\n return await iotaContext.client[method](params as never);\n },\n });\n}\n", "// Copyright (c) Mysten Labs, Inc.\n// Modifications Copyright (c) 2024 IOTA Stiftung\n// SPDX-License-Identifier: Apache-2.0\n\nimport type { IotaClient } from '@iota/iota-sdk/client';\nimport { useContext } from 'react';\n\nimport { IotaClientContext } from '../components/IotaClientProvider.js';\n\nexport function useIotaClientContext() {\n const iotaClient = useContext(IotaClientContext);\n\n if (!iotaClient) {\n throw new Error(\n 'Could not find IotaClientContext. Ensure that you have set up the IotaClientProvider',\n );\n }\n\n return iotaClient;\n}\n\nexport function useIotaClient(): IotaClient {\n return useIotaClientContext().client;\n}\n", "// Copyright (c) Mysten Labs, Inc.\n// Modifications Copyright (c) 2024 IOTA Stiftung\n// SPDX-License-Identifier: Apache-2.0\n\nimport { getNetwork, isIotaClient, Network, IotaClient } from '@iota/iota-sdk/client';\nimport type { IotaClientOptions } from '@iota/iota-sdk/client';\nimport { createContext, useMemo, useState } from 'react';\n\nimport type { NetworkConfig } from '../hooks/networkConfig.js';\n\ntype NetworkConfigs<T extends NetworkConfig | IotaClient = NetworkConfig | IotaClient> = Record<\n string,\n T\n>;\n\nexport interface IotaClientProviderContext {\n client: IotaClient;\n networks: NetworkConfigs;\n network: string;\n config: NetworkConfig | null;\n selectNetwork: (network: string) => void;\n}\n\nexport const IotaClientContext = createContext<IotaClientProviderContext | null>(null);\n\nexport type IotaClientProviderProps<T extends NetworkConfigs> = {\n createClient?: (name: keyof T, config: T[keyof T]) => IotaClient;\n children: React.ReactNode;\n networks?: T;\n onNetworkChange?: (network: keyof T & string) => void;\n} & (\n | {\n defaultNetwork?: keyof T & string;\n network?: never;\n }\n | {\n defaultNetwork?: never;\n network?: keyof T & string;\n }\n);\n\nconst DEFAULT_NETWORKS = {\n localnet: { url: getNetwork(Network.Local).url },\n};\n\nconst DEFAULT_CREATE_CLIENT = function createClient(\n _name: string,\n config: NetworkConfig | IotaClient,\n) {\n if (isIotaClient(config)) {\n return config;\n }\n\n return new IotaClient(config);\n};\n\nexport function IotaClientProvider<T extends NetworkConfigs>(props: IotaClientProviderProps<T>) {\n const { onNetworkChange, network, children } = props;\n const networks = (props.networks ?? DEFAULT_NETWORKS) as T;\n const createClient =\n (props.createClient as typeof DEFAULT_CREATE_CLIENT) ?? DEFAULT_CREATE_CLIENT;\n\n const [selectedNetwork, setSelectedNetwork] = useState<keyof T & string>(\n props.network ?? props.defaultNetwork ?? (Object.keys(networks)[0] as keyof T & string),\n );\n\n const currentNetwork = props.network ?? selectedNetwork;\n\n const client = useMemo(() => {\n return createClient(currentNetwork, networks[currentNetwork]);\n }, [createClient, currentNetwork, networks]);\n\n const ctx = useMemo((): IotaClientProviderContext => {\n return {\n client,\n networks,\n network: currentNetwork,\n config:\n networks[currentNetwork] instanceof IotaClient\n ? null\n : (networks[currentNetwork] as IotaClientOptions),\n selectNetwork: (newNetwork) => {\n if (currentNetwork === newNetwork) {\n return;\n }\n\n if (!network && newNetwork !== selectedNetwork) {\n setSelectedNetwork(newNetwork);\n }\n\n onNetworkChange?.(newNetwork);\n },\n };\n }, [client, networks, selectedNetwork, currentNetwork, network, onNetworkChange]);\n\n return <IotaClientContext.Provider value={ctx}>{children}</IotaClientContext.Provider>;\n}\n", "// Copyright (c) Mysten Labs, Inc.\n// Modifications Copyright (c) 2024 IOTA Stiftung\n// SPDX-License-Identifier: Apache-2.0\n\nimport type { ResolvedNameServiceNames } from '@iota/iota-sdk/client';\nimport type { UseQueryOptions, UseQueryResult } from '@tanstack/react-query';\n\nimport { useIotaClientQuery } from './useIotaClientQuery.js';\n\nexport function useResolveIotaNSName(\n address?: string | null,\n options?: Omit<\n UseQueryOptions<ResolvedNameServiceNames, Error, string | null, unknown[]>,\n 'queryFn' | 'queryKey' | 'select'\n >,\n): UseQueryResult<string | null, Error> {\n return useIotaClientQuery(\n 'resolveNameServiceNames',\n {\n address: address!,\n limit: 1,\n },\n {\n ...options,\n refetchOnWindowFocus: false,\n retry: false,\n select: (data) => (data.data.length > 0 ? data.data[0] : null),\n enabled: !!address && options?.enabled !== false,\n },\n );\n}\n"],
|
|
5
|
-
"mappings": ";AAMA,SAAS,gBAAgB;;;ACDzB,SAAS,kBAAkB;;;ACD3B,SAAS,YAAY,cAAc,SAAS,kBAAkB;AAE9D,SAAS,eAAe,SAAS,gBAAgB;AAyFtC;AAxEJ,IAAM,oBAAoB,cAAgD,IAAI;AAkBrF,IAAM,mBAAmB;AAAA,EACrB,UAAU,EAAE,KAAK,WAAW,QAAQ,KAAK,EAAE,IAAI;AACnD;;;ADlCO,SAAS,uBAAuB;AACnC,QAAM,aAAa,WAAW,iBAAiB;AAE/C,MAAI,CAAC,YAAY;AACb,UAAM,IAAI;AAAA,MACN;AAAA,IACJ;AAAA,EACJ;AAEA,SAAO;AACX;;;ADqBO,SAAS,sBAIT,MAWyB;AAC5B,QAAM,CAAC,QAAQ,QAAQ,EAAE,WAAW,CAAC,GAAG,GAAG,QAAQ,IAAI,CAAC,CAAC,IAAI;AAM7D,QAAM,cAAc,qBAAqB;AAEzC,SAAO,SAAS;AAAA,IACZ,GAAG;AAAA,IACH,UAAU,CAAC,YAAY,SAAS,QAAQ,QAAQ,GAAG,QAAQ;AAAA,IAC3D,SAAS,YAAY;AACjB,aAAO,MAAM,YAAY,OAAO,MAAM,EAAE,MAAe;AAAA,IAC3D;AAAA,EACJ,CAAC;AACL;;;AG9DO,SAAS,qBACZ,SACA,SAIoC;AACpC,SAAO;AAAA,IACH;AAAA,IACA;AAAA,MACI;AAAA,MACA,OAAO;AAAA,IACX;AAAA,IACA;AAAA,MACI,GAAG;AAAA,MACH,sBAAsB;AAAA,MACtB,OAAO;AAAA,MACP,QAAQ,CAAC,SAAU,KAAK,KAAK,SAAS,IAAI,KAAK,KAAK,CAAC,IAAI;AAAA,MACzD,SAAS,CAAC,CAAC,WAAW,SAAS,YAAY;AAAA,IAC/C;AAAA,EACJ;AACJ;",
|
|
6
|
-
"names": []
|
|
7
|
-
}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import type { IotaSignAndExecuteTransactionBlockInput, IotaSignAndExecuteTransactionBlockOutput } from '@iota/wallet-standard';
|
|
2
|
-
import type { UseMutationOptions, UseMutationResult } from '@tanstack/react-query';
|
|
3
|
-
import { WalletFeatureNotSupportedError, WalletNoAccountSelectedError, WalletNotConnectedError } from '../../errors/walletErrors.js';
|
|
4
|
-
import type { PartialBy } from '../../types/utilityTypes.js';
|
|
5
|
-
type UseSignAndExecuteTransactionBlockArgs = PartialBy<IotaSignAndExecuteTransactionBlockInput, 'account' | 'chain'>;
|
|
6
|
-
type UseSignAndExecuteTransactionBlockResult = IotaSignAndExecuteTransactionBlockOutput;
|
|
7
|
-
type UseSignAndExecuteTransactionBlockError = WalletFeatureNotSupportedError | WalletNoAccountSelectedError | WalletNotConnectedError | Error;
|
|
8
|
-
type UseSignAndExecuteTransactionBlockMutationOptions = Omit<UseMutationOptions<UseSignAndExecuteTransactionBlockResult, UseSignAndExecuteTransactionBlockError, UseSignAndExecuteTransactionBlockArgs, unknown>, 'mutationFn'> & {
|
|
9
|
-
executeFromWallet?: boolean;
|
|
10
|
-
};
|
|
11
|
-
/**
|
|
12
|
-
* Mutation hook for prompting the user to sign and execute a transaction block.
|
|
13
|
-
*/
|
|
14
|
-
export declare function useSignAndExecuteTransactionBlock({ mutationKey, executeFromWallet, ...mutationOptions }?: UseSignAndExecuteTransactionBlockMutationOptions): UseMutationResult<UseSignAndExecuteTransactionBlockResult, UseSignAndExecuteTransactionBlockError, UseSignAndExecuteTransactionBlockArgs>;
|
|
15
|
-
export {};
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../../../src/hooks/wallet/useSignAndExecuteTransactionBlock.ts", "../../../../src/constants/walletMutationKeys.ts", "../../../../src/errors/walletErrors.ts", "../../../../src/hooks/useIotaClient.ts", "../../../../src/components/IotaClientProvider.tsx", "../../../../src/hooks/wallet/useWalletStore.ts", "../../../../src/contexts/walletContext.ts", "../../../../src/hooks/wallet/useCurrentAccount.ts", "../../../../src/hooks/wallet/useCurrentWallet.ts"],
|
|
4
|
-
"sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// Modifications Copyright (c) 2024 IOTA Stiftung\n// SPDX-License-Identifier: Apache-2.0\n\nimport type {\n IotaSignAndExecuteTransactionBlockInput,\n IotaSignAndExecuteTransactionBlockOutput,\n} from '@iota/wallet-standard';\nimport type { UseMutationOptions, UseMutationResult } from '@tanstack/react-query';\nimport { useMutation } from '@tanstack/react-query';\n\nimport { walletMutationKeys } from '../../constants/walletMutationKeys.js';\nimport {\n WalletFeatureNotSupportedError,\n WalletNoAccountSelectedError,\n WalletNotConnectedError,\n} from '../../errors/walletErrors.js';\nimport type { PartialBy } from '../../types/utilityTypes.js';\nimport { useIotaClient } from '../useIotaClient.js';\nimport { useCurrentAccount } from './useCurrentAccount.js';\nimport { useCurrentWallet } from './useCurrentWallet.js';\n\ntype UseSignAndExecuteTransactionBlockArgs = PartialBy<\n IotaSignAndExecuteTransactionBlockInput,\n 'account' | 'chain'\n>;\n\ntype UseSignAndExecuteTransactionBlockResult = IotaSignAndExecuteTransactionBlockOutput;\n\ntype UseSignAndExecuteTransactionBlockError =\n | WalletFeatureNotSupportedError\n | WalletNoAccountSelectedError\n | WalletNotConnectedError\n | Error;\n\ntype UseSignAndExecuteTransactionBlockMutationOptions = Omit<\n UseMutationOptions<\n UseSignAndExecuteTransactionBlockResult,\n UseSignAndExecuteTransactionBlockError,\n UseSignAndExecuteTransactionBlockArgs,\n unknown\n >,\n 'mutationFn'\n> & {\n executeFromWallet?: boolean;\n};\n\n/**\n * Mutation hook for prompting the user to sign and execute a transaction block.\n */\nexport function useSignAndExecuteTransactionBlock({\n mutationKey,\n executeFromWallet,\n ...mutationOptions\n}: UseSignAndExecuteTransactionBlockMutationOptions = {}): UseMutationResult<\n UseSignAndExecuteTransactionBlockResult,\n UseSignAndExecuteTransactionBlockError,\n UseSignAndExecuteTransactionBlockArgs\n> {\n const { currentWallet } = useCurrentWallet();\n const currentAccount = useCurrentAccount();\n const client = useIotaClient();\n\n return useMutation({\n mutationKey: walletMutationKeys.signAndExecuteTransactionBlock(mutationKey),\n mutationFn: async ({ requestType, options, ...signTransactionBlockArgs }) => {\n if (!currentWallet) {\n throw new WalletNotConnectedError('No wallet is connected.');\n }\n\n const signerAccount = signTransactionBlockArgs.account ?? currentAccount;\n if (!signerAccount) {\n throw new WalletNoAccountSelectedError(\n 'No wallet account is selected to sign and execute the transaction block with.',\n );\n }\n\n if (executeFromWallet) {\n const walletFeature = currentWallet.features['iota:signAndExecuteTransactionBlock'];\n if (!walletFeature) {\n throw new WalletFeatureNotSupportedError(\n \"This wallet doesn't support the `signAndExecuteTransactionBlock` feature.\",\n );\n }\n\n return walletFeature.signAndExecuteTransactionBlock({\n ...signTransactionBlockArgs,\n account: signerAccount,\n chain: signTransactionBlockArgs.chain ?? signerAccount.chains[0],\n requestType,\n options,\n });\n }\n\n const walletFeature = currentWallet.features['iota:signTransactionBlock'];\n if (!walletFeature) {\n throw new WalletFeatureNotSupportedError(\n \"This wallet doesn't support the `signTransactionBlock` feature.\",\n );\n }\n\n const { signature, transactionBlockBytes } = await walletFeature.signTransactionBlock({\n ...signTransactionBlockArgs,\n account: signerAccount,\n chain: signTransactionBlockArgs.chain ?? signerAccount.chains[0],\n });\n\n return client.executeTransactionBlock({\n transactionBlock: transactionBlockBytes,\n signature,\n requestType,\n options,\n });\n },\n ...mutationOptions,\n });\n}\n", "// Copyright (c) Mysten Labs, Inc.\n// Modifications Copyright (c) 2024 IOTA Stiftung\n// SPDX-License-Identifier: Apache-2.0\n\nimport type { MutationKey } from '@tanstack/react-query';\n\nexport const walletMutationKeys = {\n all: { baseScope: 'wallet' },\n connectWallet: formMutationKeyFn('connect-wallet'),\n autoconnectWallet: formMutationKeyFn('autoconnect-wallet'),\n disconnectWallet: formMutationKeyFn('disconnect-wallet'),\n signPersonalMessage: formMutationKeyFn('sign-personal-message'),\n signTransactionBlock: formMutationKeyFn('sign-transaction-block'),\n signAndExecuteTransactionBlock: formMutationKeyFn('sign-and-execute-transaction-block'),\n switchAccount: formMutationKeyFn('switch-account'),\n};\n\nfunction formMutationKeyFn(baseEntity: string) {\n return function mutationKeyFn(additionalKeys: MutationKey = []) {\n return [{ ...walletMutationKeys.all, baseEntity }, ...additionalKeys];\n };\n}\n", "// Copyright (c) Mysten Labs, Inc.\n// Modifications Copyright (c) 2024 IOTA Stiftung\n// SPDX-License-Identifier: Apache-2.0\n\n/**\n * An error that is instantiated when someone attempts to perform an action that requires an active wallet connection.\n */\nexport class WalletNotConnectedError extends Error {}\n\n/**\n * An error that is instantiated when someone attempts to perform an action that requires a selected wallet account.\n * This is more of an edge case stemming from the fact that wallets don't technically require you to authorize any\n * accounts when connecting a wallet.\n */\nexport class WalletNoAccountSelectedError extends Error {}\n\n/**\n * An error that is instantiated when someone attempts to perform an action that isn't supported by a wallet.\n */\nexport class WalletFeatureNotSupportedError extends Error {}\n\n/**\n * An error that is instantiated when a wallet account can't be found for a specific wallet.\n */\nexport class WalletAccountNotFoundError extends Error {}\n", "// Copyright (c) Mysten Labs, Inc.\n// Modifications Copyright (c) 2024 IOTA Stiftung\n// SPDX-License-Identifier: Apache-2.0\n\nimport type { IotaClient } from '@iota/iota-sdk/client';\nimport { useContext } from 'react';\n\nimport { IotaClientContext } from '../components/IotaClientProvider.js';\n\nexport function useIotaClientContext() {\n const iotaClient = useContext(IotaClientContext);\n\n if (!iotaClient) {\n throw new Error(\n 'Could not find IotaClientContext. Ensure that you have set up the IotaClientProvider',\n );\n }\n\n return iotaClient;\n}\n\nexport function useIotaClient(): IotaClient {\n return useIotaClientContext().client;\n}\n", "// Copyright (c) Mysten Labs, Inc.\n// Modifications Copyright (c) 2024 IOTA Stiftung\n// SPDX-License-Identifier: Apache-2.0\n\nimport { getNetwork, isIotaClient, Network, IotaClient } from '@iota/iota-sdk/client';\nimport type { IotaClientOptions } from '@iota/iota-sdk/client';\nimport { createContext, useMemo, useState } from 'react';\n\nimport type { NetworkConfig } from '../hooks/networkConfig.js';\n\ntype NetworkConfigs<T extends NetworkConfig | IotaClient = NetworkConfig | IotaClient> = Record<\n string,\n T\n>;\n\nexport interface IotaClientProviderContext {\n client: IotaClient;\n networks: NetworkConfigs;\n network: string;\n config: NetworkConfig | null;\n selectNetwork: (network: string) => void;\n}\n\nexport const IotaClientContext = createContext<IotaClientProviderContext | null>(null);\n\nexport type IotaClientProviderProps<T extends NetworkConfigs> = {\n createClient?: (name: keyof T, config: T[keyof T]) => IotaClient;\n children: React.ReactNode;\n networks?: T;\n onNetworkChange?: (network: keyof T & string) => void;\n} & (\n | {\n defaultNetwork?: keyof T & string;\n network?: never;\n }\n | {\n defaultNetwork?: never;\n network?: keyof T & string;\n }\n);\n\nconst DEFAULT_NETWORKS = {\n localnet: { url: getNetwork(Network.Local).url },\n};\n\nconst DEFAULT_CREATE_CLIENT = function createClient(\n _name: string,\n config: NetworkConfig | IotaClient,\n) {\n if (isIotaClient(config)) {\n return config;\n }\n\n return new IotaClient(config);\n};\n\nexport function IotaClientProvider<T extends NetworkConfigs>(props: IotaClientProviderProps<T>) {\n const { onNetworkChange, network, children } = props;\n const networks = (props.networks ?? DEFAULT_NETWORKS) as T;\n const createClient =\n (props.createClient as typeof DEFAULT_CREATE_CLIENT) ?? DEFAULT_CREATE_CLIENT;\n\n const [selectedNetwork, setSelectedNetwork] = useState<keyof T & string>(\n props.network ?? props.defaultNetwork ?? (Object.keys(networks)[0] as keyof T & string),\n );\n\n const currentNetwork = props.network ?? selectedNetwork;\n\n const client = useMemo(() => {\n return createClient(currentNetwork, networks[currentNetwork]);\n }, [createClient, currentNetwork, networks]);\n\n const ctx = useMemo((): IotaClientProviderContext => {\n return {\n client,\n networks,\n network: currentNetwork,\n config:\n networks[currentNetwork] instanceof IotaClient\n ? null\n : (networks[currentNetwork] as IotaClientOptions),\n selectNetwork: (newNetwork) => {\n if (currentNetwork === newNetwork) {\n return;\n }\n\n if (!network && newNetwork !== selectedNetwork) {\n setSelectedNetwork(newNetwork);\n }\n\n onNetworkChange?.(newNetwork);\n },\n };\n }, [client, networks, selectedNetwork, currentNetwork, network, onNetworkChange]);\n\n return <IotaClientContext.Provider value={ctx}>{children}</IotaClientContext.Provider>;\n}\n", "// Copyright (c) Mysten Labs, Inc.\n// Modifications Copyright (c) 2024 IOTA Stiftung\n// SPDX-License-Identifier: Apache-2.0\n\nimport { useContext } from 'react';\nimport { useStore } from 'zustand';\n\nimport { WalletContext } from '../../contexts/walletContext.js';\nimport type { StoreState } from '../../walletStore.js';\n\nexport function useWalletStore<T>(selector: (state: StoreState) => T): T {\n const store = useContext(WalletContext);\n if (!store) {\n throw new Error(\n 'Could not find WalletContext. Ensure that you have set up the WalletProvider.',\n );\n }\n return useStore(store, selector);\n}\n", "// Copyright (c) Mysten Labs, Inc.\n// Modifications Copyright (c) 2024 IOTA Stiftung\n// SPDX-License-Identifier: Apache-2.0\n\nimport { createContext } from 'react';\n\nimport type { WalletStore } from '../walletStore.js';\n\nexport const WalletContext = createContext<WalletStore | null>(null);\n", "// Copyright (c) Mysten Labs, Inc.\n// Modifications Copyright (c) 2024 IOTA Stiftung\n// SPDX-License-Identifier: Apache-2.0\n\nimport type { WalletAccount } from '@iota/wallet-standard';\n\nimport { useWalletStore } from './useWalletStore.js';\n\n/**\n * Retrieves the wallet account that is currently selected, if one exists.\n */\nexport function useCurrentAccount(): WalletAccount | null {\n return useWalletStore((state) => state.currentAccount);\n}\n", "// Copyright (c) Mysten Labs, Inc.\n// Modifications Copyright (c) 2024 IOTA Stiftung\n// SPDX-License-Identifier: Apache-2.0\n\nimport { useWalletStore } from './useWalletStore.js';\n\n/**\n * Retrieves the wallet that is currently connected to the dApp, if one exists.\n */\nexport function useCurrentWallet() {\n const currentWallet = useWalletStore((state) => state.currentWallet);\n const connectionStatus = useWalletStore((state) => state.connectionStatus);\n\n switch (connectionStatus) {\n case 'connecting':\n return {\n connectionStatus,\n currentWallet: null,\n isDisconnected: false,\n isConnecting: true,\n isConnected: false,\n } as const;\n case 'disconnected':\n return {\n connectionStatus,\n currentWallet: null,\n isDisconnected: true,\n isConnecting: false,\n isConnected: false,\n } as const;\n case 'connected': {\n return {\n connectionStatus,\n currentWallet: currentWallet!,\n isDisconnected: false,\n isConnecting: false,\n isConnected: true,\n } as const;\n }\n }\n}\n"],
|
|
5
|
-
"mappings": ";AASA,SAAS,mBAAmB;;;ACHrB,IAAM,qBAAqB;AAAA,EAC9B,KAAK,EAAE,WAAW,SAAS;AAAA,EAC3B,eAAe,kBAAkB,gBAAgB;AAAA,EACjD,mBAAmB,kBAAkB,oBAAoB;AAAA,EACzD,kBAAkB,kBAAkB,mBAAmB;AAAA,EACvD,qBAAqB,kBAAkB,uBAAuB;AAAA,EAC9D,sBAAsB,kBAAkB,wBAAwB;AAAA,EAChE,gCAAgC,kBAAkB,o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C;AAAA,MACL;AAEA,YAAM,gBAAgB,cAAc,SAAS,2BAA2B;AACxE,UAAI,CAAC,eAAe;AAChB,cAAM,IAAI;AAAA,UACN;AAAA,QACJ;AAAA,MACJ;AAEA,YAAM,EAAE,WAAW,sBAAsB,IAAI,MAAM,cAAc,qBAAqB;AAAA,QAClF,GAAG;AAAA,QACH,SAAS;AAAA,QACT,OAAO,yBAAyB,SAAS,cAAc,OAAO,CAAC;AAAA,MACnE,CAAC;AAED,aAAO,OAAO,wBAAwB;AAAA,QAClC,kBAAkB;AAAA,QAClB;AAAA,QACA;AAAA,QACA;AAAA,MACJ,CAAC;AAAA,IACL;AAAA,IACA,GAAG;AAAA,EACP,CAAC;AACL;",
|
|
6
|
-
"names": ["useContext", "createContext", "useContext", "walletFeature"]
|
|
7
|
-
}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import type { IotaSignTransactionBlockInput, IotaSignTransactionBlockOutput } from '@iota/wallet-standard';
|
|
2
|
-
import type { UseMutationOptions, UseMutationResult } from '@tanstack/react-query';
|
|
3
|
-
import { WalletFeatureNotSupportedError, WalletNoAccountSelectedError, WalletNotConnectedError } from '../..//errors/walletErrors.js';
|
|
4
|
-
import type { PartialBy } from '../../types/utilityTypes.js';
|
|
5
|
-
type UseSignTransactionBlockArgs = PartialBy<IotaSignTransactionBlockInput, 'account' | 'chain'>;
|
|
6
|
-
type UseSignTransactionBlockResult = IotaSignTransactionBlockOutput;
|
|
7
|
-
type UseSignTransactionBlockError = WalletFeatureNotSupportedError | WalletNoAccountSelectedError | WalletNotConnectedError | Error;
|
|
8
|
-
type UseSignTransactionBlockMutationOptions = Omit<UseMutationOptions<UseSignTransactionBlockResult, UseSignTransactionBlockError, UseSignTransactionBlockArgs, unknown>, 'mutationFn'>;
|
|
9
|
-
/**
|
|
10
|
-
* Mutation hook for prompting the user to sign a transaction block.
|
|
11
|
-
*/
|
|
12
|
-
export declare function useSignTransactionBlock({ mutationKey, ...mutationOptions }?: UseSignTransactionBlockMutationOptions): UseMutationResult<UseSignTransactionBlockResult, UseSignTransactionBlockError, UseSignTransactionBlockArgs>;
|
|
13
|
-
export {};
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../../../src/hooks/wallet/useSignTransactionBlock.ts", "../../../../src/errors/walletErrors.ts", "../../../../src/constants/walletMutationKeys.ts", "../../../../src/hooks/wallet/useWalletStore.ts", "../../../../src/contexts/walletContext.ts", "../../../../src/hooks/wallet/useCurrentAccount.ts", "../../../../src/hooks/wallet/useCurrentWallet.ts"],
|
|
4
|
-
"sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// Modifications Copyright (c) 2024 IOTA Stiftung\n// SPDX-License-Identifier: Apache-2.0\n\nimport type {\n IotaSignTransactionBlockInput,\n IotaSignTransactionBlockOutput,\n} from '@iota/wallet-standard';\nimport type { UseMutationOptions, UseMutationResult } from '@tanstack/react-query';\nimport { useMutation } from '@tanstack/react-query';\n\nimport {\n WalletFeatureNotSupportedError,\n WalletNoAccountSelectedError,\n WalletNotConnectedError,\n} from '../..//errors/walletErrors.js';\nimport { walletMutationKeys } from '../../constants/walletMutationKeys.js';\nimport type { PartialBy } from '../../types/utilityTypes.js';\nimport { useCurrentAccount } from './useCurrentAccount.js';\nimport { useCurrentWallet } from './useCurrentWallet.js';\n\ntype UseSignTransactionBlockArgs = PartialBy<IotaSignTransactionBlockInput, 'account' | 'chain'>;\n\ntype UseSignTransactionBlockResult = IotaSignTransactionBlockOutput;\n\ntype UseSignTransactionBlockError =\n | WalletFeatureNotSupportedError\n | WalletNoAccountSelectedError\n | WalletNotConnectedError\n | Error;\n\ntype UseSignTransactionBlockMutationOptions = Omit<\n UseMutationOptions<\n UseSignTransactionBlockResult,\n UseSignTransactionBlockError,\n UseSignTransactionBlockArgs,\n unknown\n >,\n 'mutationFn'\n>;\n\n/**\n * Mutation hook for prompting the user to sign a transaction block.\n */\nexport function useSignTransactionBlock({\n mutationKey,\n ...mutationOptions\n}: UseSignTransactionBlockMutationOptions = {}): UseMutationResult<\n UseSignTransactionBlockResult,\n UseSignTransactionBlockError,\n UseSignTransactionBlockArgs\n> {\n const { currentWallet } = useCurrentWallet();\n const currentAccount = useCurrentAccount();\n\n return useMutation({\n mutationKey: walletMutationKeys.signTransactionBlock(mutationKey),\n mutationFn: async (signTransactionBlockArgs) => {\n if (!currentWallet) {\n throw new WalletNotConnectedError('No wallet is connected.');\n }\n\n const signerAccount = signTransactionBlockArgs.account ?? currentAccount;\n if (!signerAccount) {\n throw new WalletNoAccountSelectedError(\n 'No wallet account is selected to sign the transaction block with.',\n );\n }\n\n const walletFeature = currentWallet.features['iota:signTransactionBlock'];\n if (!walletFeature) {\n throw new WalletFeatureNotSupportedError(\n \"This wallet doesn't support the `SignTransactionBlock` feature.\",\n );\n }\n\n return await walletFeature.signTransactionBlock({\n ...signTransactionBlockArgs,\n account: signerAccount,\n chain: signTransactionBlockArgs.chain ?? signerAccount.chains[0],\n });\n },\n ...mutationOptions,\n });\n}\n", "// Copyright (c) Mysten Labs, Inc.\n// Modifications Copyright (c) 2024 IOTA Stiftung\n// SPDX-License-Identifier: Apache-2.0\n\n/**\n * An error that is instantiated when someone attempts to perform an action that requires an active wallet connection.\n */\nexport class WalletNotConnectedError extends Error {}\n\n/**\n * An error that is instantiated when someone attempts to perform an action that requires a selected wallet account.\n * This is more of an edge case stemming from the fact that wallets don't technically require you to authorize any\n * accounts when connecting a wallet.\n */\nexport class WalletNoAccountSelectedError extends Error {}\n\n/**\n * An error that is instantiated when someone attempts to perform an action that isn't supported by a wallet.\n */\nexport class WalletFeatureNotSupportedError extends Error {}\n\n/**\n * An error that is instantiated when a wallet account can't be found for a specific wallet.\n */\nexport class WalletAccountNotFoundError extends Error {}\n", "// Copyright (c) Mysten Labs, Inc.\n// Modifications Copyright (c) 2024 IOTA Stiftung\n// SPDX-License-Identifier: Apache-2.0\n\nimport type { MutationKey } from '@tanstack/react-query';\n\nexport const walletMutationKeys = {\n all: { baseScope: 'wallet' },\n connectWallet: formMutationKeyFn('connect-wallet'),\n autoconnectWallet: formMutationKeyFn('autoconnect-wallet'),\n disconnectWallet: formMutationKeyFn('disconnect-wallet'),\n signPersonalMessage: formMutationKeyFn('sign-personal-message'),\n signTransactionBlock: formMutationKeyFn('sign-transaction-block'),\n signAndExecuteTransactionBlock: formMutationKeyFn('sign-and-execute-transaction-block'),\n switchAccount: formMutationKeyFn('switch-account'),\n};\n\nfunction formMutationKeyFn(baseEntity: string) {\n return function mutationKeyFn(additionalKeys: MutationKey = []) {\n return [{ ...walletMutationKeys.all, baseEntity }, ...additionalKeys];\n };\n}\n", "// Copyright (c) Mysten Labs, Inc.\n// Modifications Copyright (c) 2024 IOTA Stiftung\n// SPDX-License-Identifier: Apache-2.0\n\nimport { useContext } from 'react';\nimport { useStore } from 'zustand';\n\nimport { WalletContext } from '../../contexts/walletContext.js';\nimport type { StoreState } from '../../walletStore.js';\n\nexport function useWalletStore<T>(selector: (state: StoreState) => T): T {\n const store = useContext(WalletContext);\n if (!store) {\n throw new Error(\n 'Could not find WalletContext. Ensure that you have set up the WalletProvider.',\n );\n }\n return useStore(store, selector);\n}\n", "// Copyright (c) Mysten Labs, Inc.\n// Modifications Copyright (c) 2024 IOTA Stiftung\n// SPDX-License-Identifier: Apache-2.0\n\nimport { createContext } from 'react';\n\nimport type { WalletStore } from '../walletStore.js';\n\nexport const WalletContext = createContext<WalletStore | null>(null);\n", "// Copyright (c) Mysten Labs, Inc.\n// Modifications Copyright (c) 2024 IOTA Stiftung\n// SPDX-License-Identifier: Apache-2.0\n\nimport type { WalletAccount } from '@iota/wallet-standard';\n\nimport { useWalletStore } from './useWalletStore.js';\n\n/**\n * Retrieves the wallet account that is currently selected, if one exists.\n */\nexport function useCurrentAccount(): WalletAccount | null {\n return useWalletStore((state) => state.currentAccount);\n}\n", "// Copyright (c) Mysten Labs, Inc.\n// Modifications Copyright (c) 2024 IOTA Stiftung\n// SPDX-License-Identifier: Apache-2.0\n\nimport { useWalletStore } from './useWalletStore.js';\n\n/**\n * Retrieves the wallet that is currently connected to the dApp, if one exists.\n */\nexport function useCurrentWallet() {\n const currentWallet = useWalletStore((state) => state.currentWallet);\n const connectionStatus = useWalletStore((state) => state.connectionStatus);\n\n switch (connectionStatus) {\n case 'connecting':\n return {\n connectionStatus,\n currentWallet: null,\n isDisconnected: false,\n isConnecting: true,\n isConnected: false,\n } as const;\n case 'disconnected':\n return {\n connectionStatus,\n currentWallet: null,\n isDisconnected: true,\n isConnecting: false,\n isConnected: false,\n } as const;\n case 'connected': {\n return {\n connectionStatus,\n currentWallet: currentWallet!,\n isDisconnected: false,\n isConnecting: false,\n isConnected: true,\n } as const;\n }\n }\n}\n"],
|
|
5
|
-
"mappings": ";AASA,SAAS,mBAAmB;;;ACFrB,IAAM,0BAAN,cAAsC,MAAM;AAAC;AAO7C,IAAM,+BAAN,cAA2C,MAAM;AAAC;AAKlD,IAAM,iCAAN,cAA6C,MAAM;AAAC;;;ACbpD,IAAM,qBAAqB;AAAA,EAC9B,KAAK,EAAE,WAAW,SAAS;AAAA,EAC3B,eAAe,kBAAkB,gBAAgB;AAAA,EACjD,mBAAmB,kBAAkB,oBAAoB;AAAA,EACzD,kBAAkB,kBAAkB,mBAAmB;AAAA,EACvD,qBAAqB,kBAAkB,uBAAuB;AAAA,EAC9D,sBAAsB,kBAAkB,wBAAwB;AAAA,EAChE,gCAAgC,kBAAkB,oCAAoC;AAAA,EACtF,eAAe,kBAAkB,gBAAgB;AACrD;AAEA,SAAS,kBAAkB,YAAoB;AAC3C,SAAO,SAAS,cAAc,iBAA8B,CAAC,GAAG;AAC5D,WAAO,CAAC,EAAE,GAAG,mBAAmB,KAAK,WAAW,GAAG,GAAG,cAAc;AAAA,EACxE;AACJ;;;ACjBA,SAAS,kBAAkB;AAC3B,SAAS,gBAAgB;;;ACDzB,SAAS,qBAAqB;AAIvB,IAAM,gBAAgB,cAAkC,IAAI;;;ADE5D,SAAS,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2BAA2B;AACxE,UAAI,CAAC,eAAe;AAChB,cAAM,IAAI;AAAA,UACN;AAAA,QACJ;AAAA,MACJ;AAEA,aAAO,MAAM,cAAc,qBAAqB;AAAA,QAC5C,GAAG;AAAA,QACH,SAAS;AAAA,QACT,OAAO,yBAAyB,SAAS,cAAc,OAAO,CAAC;AAAA,MACnE,CAAC;AAAA,IACL;AAAA,IACA,GAAG;AAAA,EACP,CAAC;AACL;",
|
|
6
|
-
"names": []
|
|
7
|
-
}
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
// Copyright (c) Mysten Labs, Inc.
|
|
2
|
-
// Modifications Copyright (c) 2024 IOTA Stiftung
|
|
3
|
-
// SPDX-License-Identifier: Apache-2.0
|
|
4
|
-
|
|
5
|
-
import type { ResolvedNameServiceNames } from '@iota/iota-sdk/client';
|
|
6
|
-
import type { UseQueryOptions, UseQueryResult } from '@tanstack/react-query';
|
|
7
|
-
|
|
8
|
-
import { useIotaClientQuery } from './useIotaClientQuery.js';
|
|
9
|
-
|
|
10
|
-
export function useResolveIotaNSName(
|
|
11
|
-
address?: string | null,
|
|
12
|
-
options?: Omit<
|
|
13
|
-
UseQueryOptions<ResolvedNameServiceNames, Error, string | null, unknown[]>,
|
|
14
|
-
'queryFn' | 'queryKey' | 'select'
|
|
15
|
-
>,
|
|
16
|
-
): UseQueryResult<string | null, Error> {
|
|
17
|
-
return useIotaClientQuery(
|
|
18
|
-
'resolveNameServiceNames',
|
|
19
|
-
{
|
|
20
|
-
address: address!,
|
|
21
|
-
limit: 1,
|
|
22
|
-
},
|
|
23
|
-
{
|
|
24
|
-
...options,
|
|
25
|
-
refetchOnWindowFocus: false,
|
|
26
|
-
retry: false,
|
|
27
|
-
select: (data) => (data.data.length > 0 ? data.data[0] : null),
|
|
28
|
-
enabled: !!address && options?.enabled !== false,
|
|
29
|
-
},
|
|
30
|
-
);
|
|
31
|
-
}
|
|
@@ -1,117 +0,0 @@
|
|
|
1
|
-
// Copyright (c) Mysten Labs, Inc.
|
|
2
|
-
// Modifications Copyright (c) 2024 IOTA Stiftung
|
|
3
|
-
// SPDX-License-Identifier: Apache-2.0
|
|
4
|
-
|
|
5
|
-
import type {
|
|
6
|
-
IotaSignAndExecuteTransactionBlockInput,
|
|
7
|
-
IotaSignAndExecuteTransactionBlockOutput,
|
|
8
|
-
} from '@iota/wallet-standard';
|
|
9
|
-
import type { UseMutationOptions, UseMutationResult } from '@tanstack/react-query';
|
|
10
|
-
import { useMutation } from '@tanstack/react-query';
|
|
11
|
-
|
|
12
|
-
import { walletMutationKeys } from '../../constants/walletMutationKeys.js';
|
|
13
|
-
import {
|
|
14
|
-
WalletFeatureNotSupportedError,
|
|
15
|
-
WalletNoAccountSelectedError,
|
|
16
|
-
WalletNotConnectedError,
|
|
17
|
-
} from '../../errors/walletErrors.js';
|
|
18
|
-
import type { PartialBy } from '../../types/utilityTypes.js';
|
|
19
|
-
import { useIotaClient } from '../useIotaClient.js';
|
|
20
|
-
import { useCurrentAccount } from './useCurrentAccount.js';
|
|
21
|
-
import { useCurrentWallet } from './useCurrentWallet.js';
|
|
22
|
-
|
|
23
|
-
type UseSignAndExecuteTransactionBlockArgs = PartialBy<
|
|
24
|
-
IotaSignAndExecuteTransactionBlockInput,
|
|
25
|
-
'account' | 'chain'
|
|
26
|
-
>;
|
|
27
|
-
|
|
28
|
-
type UseSignAndExecuteTransactionBlockResult = IotaSignAndExecuteTransactionBlockOutput;
|
|
29
|
-
|
|
30
|
-
type UseSignAndExecuteTransactionBlockError =
|
|
31
|
-
| WalletFeatureNotSupportedError
|
|
32
|
-
| WalletNoAccountSelectedError
|
|
33
|
-
| WalletNotConnectedError
|
|
34
|
-
| Error;
|
|
35
|
-
|
|
36
|
-
type UseSignAndExecuteTransactionBlockMutationOptions = Omit<
|
|
37
|
-
UseMutationOptions<
|
|
38
|
-
UseSignAndExecuteTransactionBlockResult,
|
|
39
|
-
UseSignAndExecuteTransactionBlockError,
|
|
40
|
-
UseSignAndExecuteTransactionBlockArgs,
|
|
41
|
-
unknown
|
|
42
|
-
>,
|
|
43
|
-
'mutationFn'
|
|
44
|
-
> & {
|
|
45
|
-
executeFromWallet?: boolean;
|
|
46
|
-
};
|
|
47
|
-
|
|
48
|
-
/**
|
|
49
|
-
* Mutation hook for prompting the user to sign and execute a transaction block.
|
|
50
|
-
*/
|
|
51
|
-
export function useSignAndExecuteTransactionBlock({
|
|
52
|
-
mutationKey,
|
|
53
|
-
executeFromWallet,
|
|
54
|
-
...mutationOptions
|
|
55
|
-
}: UseSignAndExecuteTransactionBlockMutationOptions = {}): UseMutationResult<
|
|
56
|
-
UseSignAndExecuteTransactionBlockResult,
|
|
57
|
-
UseSignAndExecuteTransactionBlockError,
|
|
58
|
-
UseSignAndExecuteTransactionBlockArgs
|
|
59
|
-
> {
|
|
60
|
-
const { currentWallet } = useCurrentWallet();
|
|
61
|
-
const currentAccount = useCurrentAccount();
|
|
62
|
-
const client = useIotaClient();
|
|
63
|
-
|
|
64
|
-
return useMutation({
|
|
65
|
-
mutationKey: walletMutationKeys.signAndExecuteTransactionBlock(mutationKey),
|
|
66
|
-
mutationFn: async ({ requestType, options, ...signTransactionBlockArgs }) => {
|
|
67
|
-
if (!currentWallet) {
|
|
68
|
-
throw new WalletNotConnectedError('No wallet is connected.');
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
const signerAccount = signTransactionBlockArgs.account ?? currentAccount;
|
|
72
|
-
if (!signerAccount) {
|
|
73
|
-
throw new WalletNoAccountSelectedError(
|
|
74
|
-
'No wallet account is selected to sign and execute the transaction block with.',
|
|
75
|
-
);
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
if (executeFromWallet) {
|
|
79
|
-
const walletFeature = currentWallet.features['iota:signAndExecuteTransactionBlock'];
|
|
80
|
-
if (!walletFeature) {
|
|
81
|
-
throw new WalletFeatureNotSupportedError(
|
|
82
|
-
"This wallet doesn't support the `signAndExecuteTransactionBlock` feature.",
|
|
83
|
-
);
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
return walletFeature.signAndExecuteTransactionBlock({
|
|
87
|
-
...signTransactionBlockArgs,
|
|
88
|
-
account: signerAccount,
|
|
89
|
-
chain: signTransactionBlockArgs.chain ?? signerAccount.chains[0],
|
|
90
|
-
requestType,
|
|
91
|
-
options,
|
|
92
|
-
});
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
const walletFeature = currentWallet.features['iota:signTransactionBlock'];
|
|
96
|
-
if (!walletFeature) {
|
|
97
|
-
throw new WalletFeatureNotSupportedError(
|
|
98
|
-
"This wallet doesn't support the `signTransactionBlock` feature.",
|
|
99
|
-
);
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
const { signature, transactionBlockBytes } = await walletFeature.signTransactionBlock({
|
|
103
|
-
...signTransactionBlockArgs,
|
|
104
|
-
account: signerAccount,
|
|
105
|
-
chain: signTransactionBlockArgs.chain ?? signerAccount.chains[0],
|
|
106
|
-
});
|
|
107
|
-
|
|
108
|
-
return client.executeTransactionBlock({
|
|
109
|
-
transactionBlock: transactionBlockBytes,
|
|
110
|
-
signature,
|
|
111
|
-
requestType,
|
|
112
|
-
options,
|
|
113
|
-
});
|
|
114
|
-
},
|
|
115
|
-
...mutationOptions,
|
|
116
|
-
});
|
|
117
|
-
}
|