@mysten/dapp-kit 0.9.0 → 0.9.1

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.
Files changed (81) hide show
  1. package/CHANGELOG.md +11 -0
  2. package/README.md +19 -4
  3. package/dist/cjs/components/AccountDropdownMenu.js +1 -0
  4. package/dist/cjs/components/AccountDropdownMenu.js.map +2 -2
  5. package/dist/cjs/components/ConnectButton.js +1 -0
  6. package/dist/cjs/components/ConnectButton.js.map +2 -2
  7. package/dist/cjs/components/WalletProvider.js +67 -51
  8. package/dist/cjs/components/WalletProvider.js.map +3 -3
  9. package/dist/cjs/components/connect-modal/ConnectModal.js +1 -0
  10. package/dist/cjs/components/connect-modal/ConnectModal.js.map +2 -2
  11. package/dist/cjs/constants/walletMutationKeys.d.ts +1 -0
  12. package/dist/cjs/constants/walletMutationKeys.js +1 -0
  13. package/dist/cjs/constants/walletMutationKeys.js.map +2 -2
  14. package/dist/cjs/hooks/wallet/useAutoConnectWallet.d.ts +1 -1
  15. package/dist/cjs/hooks/wallet/useAutoConnectWallet.js +50 -27
  16. package/dist/cjs/hooks/wallet/useAutoConnectWallet.js.map +3 -3
  17. package/dist/cjs/hooks/wallet/useConnectWallet.js +1 -0
  18. package/dist/cjs/hooks/wallet/useConnectWallet.js.map +2 -2
  19. package/dist/cjs/hooks/wallet/useDisconnectWallet.js +1 -0
  20. package/dist/cjs/hooks/wallet/useDisconnectWallet.js.map +2 -2
  21. package/dist/cjs/hooks/wallet/useSignAndExecuteTransactionBlock.js +1 -0
  22. package/dist/cjs/hooks/wallet/useSignAndExecuteTransactionBlock.js.map +2 -2
  23. package/dist/cjs/hooks/wallet/useSignPersonalMessage.js +1 -0
  24. package/dist/cjs/hooks/wallet/useSignPersonalMessage.js.map +2 -2
  25. package/dist/cjs/hooks/wallet/useSignTransactionBlock.js +1 -0
  26. package/dist/cjs/hooks/wallet/useSignTransactionBlock.js.map +2 -2
  27. package/dist/cjs/hooks/wallet/useSwitchAccount.js +1 -0
  28. package/dist/cjs/hooks/wallet/useSwitchAccount.js.map +2 -2
  29. package/dist/cjs/index.d.ts +1 -2
  30. package/dist/cjs/index.js +74 -63
  31. package/dist/cjs/index.js.map +4 -4
  32. package/dist/cjs/walletStore.d.ts +3 -5
  33. package/dist/cjs/walletStore.js +2 -7
  34. package/dist/cjs/walletStore.js.map +2 -2
  35. package/dist/esm/components/AccountDropdownMenu.js +1 -0
  36. package/dist/esm/components/AccountDropdownMenu.js.map +2 -2
  37. package/dist/esm/components/ConnectButton.js +1 -0
  38. package/dist/esm/components/ConnectButton.js.map +2 -2
  39. package/dist/esm/components/WalletProvider.js +61 -45
  40. package/dist/esm/components/WalletProvider.js.map +3 -3
  41. package/dist/esm/components/connect-modal/ConnectModal.js +1 -0
  42. package/dist/esm/components/connect-modal/ConnectModal.js.map +2 -2
  43. package/dist/esm/constants/walletMutationKeys.d.ts +1 -0
  44. package/dist/esm/constants/walletMutationKeys.js +1 -0
  45. package/dist/esm/constants/walletMutationKeys.js.map +2 -2
  46. package/dist/esm/hooks/wallet/useAutoConnectWallet.d.ts +1 -1
  47. package/dist/esm/hooks/wallet/useAutoConnectWallet.js +50 -27
  48. package/dist/esm/hooks/wallet/useAutoConnectWallet.js.map +2 -2
  49. package/dist/esm/hooks/wallet/useConnectWallet.js +1 -0
  50. package/dist/esm/hooks/wallet/useConnectWallet.js.map +2 -2
  51. package/dist/esm/hooks/wallet/useDisconnectWallet.js +1 -0
  52. package/dist/esm/hooks/wallet/useDisconnectWallet.js.map +2 -2
  53. package/dist/esm/hooks/wallet/useSignAndExecuteTransactionBlock.js +1 -0
  54. package/dist/esm/hooks/wallet/useSignAndExecuteTransactionBlock.js.map +2 -2
  55. package/dist/esm/hooks/wallet/useSignPersonalMessage.js +1 -0
  56. package/dist/esm/hooks/wallet/useSignPersonalMessage.js.map +2 -2
  57. package/dist/esm/hooks/wallet/useSignTransactionBlock.js +1 -0
  58. package/dist/esm/hooks/wallet/useSignTransactionBlock.js.map +2 -2
  59. package/dist/esm/hooks/wallet/useSwitchAccount.js +1 -0
  60. package/dist/esm/hooks/wallet/useSwitchAccount.js.map +2 -2
  61. package/dist/esm/index.d.ts +1 -2
  62. package/dist/esm/index.js +62 -51
  63. package/dist/esm/index.js.map +4 -4
  64. package/dist/esm/walletStore.d.ts +3 -5
  65. package/dist/esm/walletStore.js +2 -7
  66. package/dist/esm/walletStore.js.map +2 -2
  67. package/dist/tsconfig.esm.tsbuildinfo +1 -1
  68. package/dist/tsconfig.tsbuildinfo +1 -1
  69. package/package.json +4 -6
  70. package/src/components/WalletProvider.tsx +3 -5
  71. package/src/constants/walletMutationKeys.ts +1 -0
  72. package/src/hooks/wallet/useAutoConnectWallet.ts +55 -33
  73. package/src/index.ts +1 -2
  74. package/src/walletStore.ts +4 -12
  75. package/dist/cjs/hooks/wallet/useAutoConnectionStatus.d.ts +0 -4
  76. package/dist/cjs/hooks/wallet/useAutoConnectionStatus.js +0 -50
  77. package/dist/cjs/hooks/wallet/useAutoConnectionStatus.js.map +0 -7
  78. package/dist/esm/hooks/wallet/useAutoConnectionStatus.d.ts +0 -4
  79. package/dist/esm/hooks/wallet/useAutoConnectionStatus.js +0 -27
  80. package/dist/esm/hooks/wallet/useAutoConnectionStatus.js.map +0 -7
  81. package/src/hooks/wallet/useAutoConnectionStatus.ts +0 -12
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../src/hooks/wallet/useSignAndExecuteTransactionBlock.ts", "../../../../src/constants/walletMutationKeys.ts", "../../../../src/errors/walletErrors.ts", "../../../../src/hooks/useSuiClient.ts", "../../../../src/components/SuiClientProvider.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// SPDX-License-Identifier: Apache-2.0\n\nimport type {\n\tSuiSignAndExecuteTransactionBlockInput,\n\tSuiSignAndExecuteTransactionBlockOutput,\n} from '@mysten/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\tWalletFeatureNotSupportedError,\n\tWalletNoAccountSelectedError,\n\tWalletNotConnectedError,\n} from '../../errors/walletErrors.js';\nimport type { PartialBy } from '../../types/utilityTypes.js';\nimport { useSuiClient } from '../useSuiClient.js';\nimport { useCurrentAccount } from './useCurrentAccount.js';\nimport { useCurrentWallet } from './useCurrentWallet.js';\n\ntype UseSignAndExecuteTransactionBlockArgs = PartialBy<\n\tSuiSignAndExecuteTransactionBlockInput,\n\t'account' | 'chain'\n>;\n\ntype UseSignAndExecuteTransactionBlockResult = SuiSignAndExecuteTransactionBlockOutput;\n\ntype UseSignAndExecuteTransactionBlockError =\n\t| WalletFeatureNotSupportedError\n\t| WalletNoAccountSelectedError\n\t| WalletNotConnectedError\n\t| Error;\n\ntype UseSignAndExecuteTransactionBlockMutationOptions = Omit<\n\tUseMutationOptions<\n\t\tUseSignAndExecuteTransactionBlockResult,\n\t\tUseSignAndExecuteTransactionBlockError,\n\t\tUseSignAndExecuteTransactionBlockArgs,\n\t\tunknown\n\t>,\n\t'mutationFn'\n> & {\n\texecuteFromWallet?: boolean;\n};\n\n/**\n * Mutation hook for prompting the user to sign and execute a transaction block.\n */\nexport function useSignAndExecuteTransactionBlock({\n\tmutationKey,\n\texecuteFromWallet,\n\t...mutationOptions\n}: UseSignAndExecuteTransactionBlockMutationOptions = {}): UseMutationResult<\n\tUseSignAndExecuteTransactionBlockResult,\n\tUseSignAndExecuteTransactionBlockError,\n\tUseSignAndExecuteTransactionBlockArgs\n> {\n\tconst { currentWallet } = useCurrentWallet();\n\tconst currentAccount = useCurrentAccount();\n\tconst client = useSuiClient();\n\n\treturn useMutation({\n\t\tmutationKey: walletMutationKeys.signAndExecuteTransactionBlock(mutationKey),\n\t\tmutationFn: async ({ requestType, options, ...signTransactionBlockArgs }) => {\n\t\t\tif (!currentWallet) {\n\t\t\t\tthrow new WalletNotConnectedError('No wallet is connected.');\n\t\t\t}\n\n\t\t\tconst signerAccount = signTransactionBlockArgs.account ?? currentAccount;\n\t\t\tif (!signerAccount) {\n\t\t\t\tthrow new WalletNoAccountSelectedError(\n\t\t\t\t\t'No wallet account is selected to sign and execute the transaction block with.',\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tif (executeFromWallet) {\n\t\t\t\tconst walletFeature = currentWallet.features['sui:signAndExecuteTransactionBlock'];\n\t\t\t\tif (!walletFeature) {\n\t\t\t\t\tthrow new WalletFeatureNotSupportedError(\n\t\t\t\t\t\t\"This wallet doesn't support the `signAndExecuteTransactionBlock` feature.\",\n\t\t\t\t\t);\n\t\t\t\t}\n\n\t\t\t\treturn walletFeature.signAndExecuteTransactionBlock({\n\t\t\t\t\t...signTransactionBlockArgs,\n\t\t\t\t\taccount: signerAccount,\n\t\t\t\t\tchain: signTransactionBlockArgs.chain ?? signerAccount.chains[0],\n\t\t\t\t\trequestType,\n\t\t\t\t\toptions,\n\t\t\t\t});\n\t\t\t}\n\n\t\t\tconst walletFeature = currentWallet.features['sui:signTransactionBlock'];\n\t\t\tif (!walletFeature) {\n\t\t\t\tthrow new WalletFeatureNotSupportedError(\n\t\t\t\t\t\"This wallet doesn't support the `signTransactionBlock` feature.\",\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tconst { signature, transactionBlockBytes } = await walletFeature.signTransactionBlock({\n\t\t\t\t...signTransactionBlockArgs,\n\t\t\t\taccount: signerAccount,\n\t\t\t\tchain: signTransactionBlockArgs.chain ?? signerAccount.chains[0],\n\t\t\t});\n\n\t\t\treturn client.executeTransactionBlock({\n\t\t\t\ttransactionBlock: transactionBlockBytes,\n\t\t\t\tsignature,\n\t\t\t\trequestType,\n\t\t\t\toptions,\n\t\t\t});\n\t\t},\n\t\t...mutationOptions,\n\t});\n}\n", "// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport type { MutationKey } from '@tanstack/react-query';\n\nexport const walletMutationKeys = {\n\tall: { baseScope: 'wallet' },\n\tconnectWallet: formMutationKeyFn('connect-wallet'),\n\tdisconnectWallet: formMutationKeyFn('disconnect-wallet'),\n\tsignPersonalMessage: formMutationKeyFn('sign-personal-message'),\n\tsignTransactionBlock: formMutationKeyFn('sign-transaction-block'),\n\tsignAndExecuteTransactionBlock: formMutationKeyFn('sign-and-execute-transaction-block'),\n\tswitchAccount: formMutationKeyFn('switch-account'),\n};\n\nfunction formMutationKeyFn(baseEntity: string) {\n\treturn function mutationKeyFn(additionalKeys: MutationKey = []) {\n\t\treturn [{ ...walletMutationKeys.all, baseEntity }, ...additionalKeys];\n\t};\n}\n", "// Copyright (c) Mysten Labs, Inc.\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// SPDX-License-Identifier: Apache-2.0\n\nimport type { SuiClient } from '@mysten/sui.js/client';\nimport { useContext } from 'react';\n\nimport { SuiClientContext } from '../components/SuiClientProvider.js';\n\nexport function useSuiClientContext() {\n\tconst suiClient = useContext(SuiClientContext);\n\n\tif (!suiClient) {\n\t\tthrow new Error(\n\t\t\t'Could not find SuiClientContext. Ensure that you have set up the SuiClientProvider',\n\t\t);\n\t}\n\n\treturn suiClient;\n}\n\nexport function useSuiClient(): SuiClient {\n\treturn useSuiClientContext().client;\n}\n", "// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport { getFullnodeUrl, isSuiClient, SuiClient } from '@mysten/sui.js/client';\nimport type { SuiClientOptions } from '@mysten/sui.js/client';\nimport { createContext, useMemo, useState } from 'react';\n\nimport type { NetworkConfig } from '../hooks/networkConfig.js';\n\ntype NetworkConfigs<T extends NetworkConfig | SuiClient = NetworkConfig | SuiClient> = Record<\n\tstring,\n\tT\n>;\n\nexport interface SuiClientProviderContext {\n\tclient: SuiClient;\n\tnetworks: NetworkConfigs;\n\tnetwork: string;\n\tconfig: NetworkConfig | null;\n\tselectNetwork: (network: string) => void;\n}\n\nexport const SuiClientContext = createContext<SuiClientProviderContext | null>(null);\n\nexport type SuiClientProviderProps<T extends NetworkConfigs> = {\n\tcreateClient?: (name: keyof T, config: T[keyof T]) => SuiClient;\n\tchildren: React.ReactNode;\n\tnetworks?: T;\n\tonNetworkChange?: (network: keyof T & string) => void;\n} & (\n\t| {\n\t\t\tdefaultNetwork?: keyof T & string;\n\t\t\tnetwork?: never;\n\t }\n\t| {\n\t\t\tdefaultNetwork?: never;\n\t\t\tnetwork?: keyof T & string;\n\t }\n);\n\nconst DEFAULT_NETWORKS = {\n\tlocalnet: { url: getFullnodeUrl('localnet') },\n};\n\nconst DEFAULT_CREATE_CLIENT = function createClient(\n\t_name: string,\n\tconfig: NetworkConfig | SuiClient,\n) {\n\tif (isSuiClient(config)) {\n\t\treturn config;\n\t}\n\n\treturn new SuiClient(config);\n};\n\nexport function SuiClientProvider<T extends NetworkConfigs>(props: SuiClientProviderProps<T>) {\n\tconst { onNetworkChange, network, children } = props;\n\tconst networks = (props.networks ?? DEFAULT_NETWORKS) as T;\n\tconst createClient =\n\t\t(props.createClient as typeof DEFAULT_CREATE_CLIENT) ?? DEFAULT_CREATE_CLIENT;\n\n\tconst [selectedNetwork, setSelectedNetwork] = useState<keyof T & string>(\n\t\tprops.network ?? props.defaultNetwork ?? (Object.keys(networks)[0] as keyof T & string),\n\t);\n\n\tconst currentNetwork = props.network ?? selectedNetwork;\n\n\tconst client = useMemo(() => {\n\t\treturn createClient(currentNetwork, networks[currentNetwork]);\n\t}, [createClient, currentNetwork, networks]);\n\n\tconst ctx = useMemo((): SuiClientProviderContext => {\n\t\treturn {\n\t\t\tclient,\n\t\t\tnetworks,\n\t\t\tnetwork: currentNetwork,\n\t\t\tconfig:\n\t\t\t\tnetworks[currentNetwork] instanceof SuiClient\n\t\t\t\t\t? null\n\t\t\t\t\t: (networks[currentNetwork] as SuiClientOptions),\n\t\t\tselectNetwork: (newNetwork) => {\n\t\t\t\tif (currentNetwork === newNetwork) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tif (!network && newNetwork !== selectedNetwork) {\n\t\t\t\t\tsetSelectedNetwork(newNetwork);\n\t\t\t\t}\n\n\t\t\t\tonNetworkChange?.(newNetwork);\n\t\t\t},\n\t\t};\n\t}, [client, networks, selectedNetwork, currentNetwork, network, onNetworkChange]);\n\n\treturn <SuiClientContext.Provider value={ctx}>{children}</SuiClientContext.Provider>;\n}\n", "// Copyright (c) Mysten Labs, Inc.\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\tconst store = useContext(WalletContext);\n\tif (!store) {\n\t\tthrow new Error(\n\t\t\t'Could not find WalletContext. Ensure that you have set up the WalletProvider.',\n\t\t);\n\t}\n\treturn useStore(store, selector);\n}\n", "// Copyright (c) Mysten Labs, Inc.\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// SPDX-License-Identifier: Apache-2.0\n\nimport type { WalletAccount } from '@mysten/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\treturn useWalletStore((state) => state.currentAccount);\n}\n", "// Copyright (c) Mysten Labs, Inc.\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\tconst currentWallet = useWalletStore((state) => state.currentWallet);\n\tconst connectionStatus = useWalletStore((state) => state.connectionStatus);\n\n\tswitch (connectionStatus) {\n\t\tcase 'connecting':\n\t\t\treturn {\n\t\t\t\tconnectionStatus,\n\t\t\t\tcurrentWallet: null,\n\t\t\t\tisDisconnected: false,\n\t\t\t\tisConnecting: true,\n\t\t\t\tisConnected: false,\n\t\t\t} as const;\n\t\tcase 'disconnected':\n\t\t\treturn {\n\t\t\t\tconnectionStatus,\n\t\t\t\tcurrentWallet: null,\n\t\t\t\tisDisconnected: true,\n\t\t\t\tisConnecting: false,\n\t\t\t\tisConnected: false,\n\t\t\t} as const;\n\t\tcase 'connected': {\n\t\t\treturn {\n\t\t\t\tconnectionStatus,\n\t\t\t\tcurrentWallet: currentWallet!,\n\t\t\t\tisDisconnected: false,\n\t\t\t\tisConnecting: false,\n\t\t\t\tisConnected: true,\n\t\t\t} as const;\n\t\t}\n\t}\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAQA,yBAA4B;;;ACHrB,IAAM,qBAAqB;AAAA,EACjC,KAAK,EAAE,WAAW,SAAS;AAAA,EAC3B,eAAe,kBAAkB,gBAAgB;AAAA,EACjD,kBAAkB,kBAAkB,mBAAmB;AAAA,EACvD,qBAAqB,kBAAkB,uBAAuB;AAAA,EAC9D,sBAAsB,kBAAkB,wBAAwB;AAAA,EAChE,g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CAAC,eAAe;AACnB,cAAM,IAAI;AAAA,UACT;AAAA,QACD;AAAA,MACD;AAEA,YAAM,EAAE,WAAW,sBAAsB,IAAI,MAAM,cAAc,qBAAqB;AAAA,QACrF,GAAG;AAAA,QACH,SAAS;AAAA,QACT,OAAO,yBAAyB,SAAS,cAAc,OAAO,CAAC;AAAA,MAChE,CAAC;AAED,aAAO,OAAO,wBAAwB;AAAA,QACrC,kBAAkB;AAAA,QAClB;AAAA,QACA;AAAA,QACA;AAAA,MACD,CAAC;AAAA,IACF;AAAA,IACA,GAAG;AAAA,EACJ,CAAC;AACF;",
4
+ "sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport type {\n\tSuiSignAndExecuteTransactionBlockInput,\n\tSuiSignAndExecuteTransactionBlockOutput,\n} from '@mysten/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\tWalletFeatureNotSupportedError,\n\tWalletNoAccountSelectedError,\n\tWalletNotConnectedError,\n} from '../../errors/walletErrors.js';\nimport type { PartialBy } from '../../types/utilityTypes.js';\nimport { useSuiClient } from '../useSuiClient.js';\nimport { useCurrentAccount } from './useCurrentAccount.js';\nimport { useCurrentWallet } from './useCurrentWallet.js';\n\ntype UseSignAndExecuteTransactionBlockArgs = PartialBy<\n\tSuiSignAndExecuteTransactionBlockInput,\n\t'account' | 'chain'\n>;\n\ntype UseSignAndExecuteTransactionBlockResult = SuiSignAndExecuteTransactionBlockOutput;\n\ntype UseSignAndExecuteTransactionBlockError =\n\t| WalletFeatureNotSupportedError\n\t| WalletNoAccountSelectedError\n\t| WalletNotConnectedError\n\t| Error;\n\ntype UseSignAndExecuteTransactionBlockMutationOptions = Omit<\n\tUseMutationOptions<\n\t\tUseSignAndExecuteTransactionBlockResult,\n\t\tUseSignAndExecuteTransactionBlockError,\n\t\tUseSignAndExecuteTransactionBlockArgs,\n\t\tunknown\n\t>,\n\t'mutationFn'\n> & {\n\texecuteFromWallet?: boolean;\n};\n\n/**\n * Mutation hook for prompting the user to sign and execute a transaction block.\n */\nexport function useSignAndExecuteTransactionBlock({\n\tmutationKey,\n\texecuteFromWallet,\n\t...mutationOptions\n}: UseSignAndExecuteTransactionBlockMutationOptions = {}): UseMutationResult<\n\tUseSignAndExecuteTransactionBlockResult,\n\tUseSignAndExecuteTransactionBlockError,\n\tUseSignAndExecuteTransactionBlockArgs\n> {\n\tconst { currentWallet } = useCurrentWallet();\n\tconst currentAccount = useCurrentAccount();\n\tconst client = useSuiClient();\n\n\treturn useMutation({\n\t\tmutationKey: walletMutationKeys.signAndExecuteTransactionBlock(mutationKey),\n\t\tmutationFn: async ({ requestType, options, ...signTransactionBlockArgs }) => {\n\t\t\tif (!currentWallet) {\n\t\t\t\tthrow new WalletNotConnectedError('No wallet is connected.');\n\t\t\t}\n\n\t\t\tconst signerAccount = signTransactionBlockArgs.account ?? currentAccount;\n\t\t\tif (!signerAccount) {\n\t\t\t\tthrow new WalletNoAccountSelectedError(\n\t\t\t\t\t'No wallet account is selected to sign and execute the transaction block with.',\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tif (executeFromWallet) {\n\t\t\t\tconst walletFeature = currentWallet.features['sui:signAndExecuteTransactionBlock'];\n\t\t\t\tif (!walletFeature) {\n\t\t\t\t\tthrow new WalletFeatureNotSupportedError(\n\t\t\t\t\t\t\"This wallet doesn't support the `signAndExecuteTransactionBlock` feature.\",\n\t\t\t\t\t);\n\t\t\t\t}\n\n\t\t\t\treturn walletFeature.signAndExecuteTransactionBlock({\n\t\t\t\t\t...signTransactionBlockArgs,\n\t\t\t\t\taccount: signerAccount,\n\t\t\t\t\tchain: signTransactionBlockArgs.chain ?? signerAccount.chains[0],\n\t\t\t\t\trequestType,\n\t\t\t\t\toptions,\n\t\t\t\t});\n\t\t\t}\n\n\t\t\tconst walletFeature = currentWallet.features['sui:signTransactionBlock'];\n\t\t\tif (!walletFeature) {\n\t\t\t\tthrow new WalletFeatureNotSupportedError(\n\t\t\t\t\t\"This wallet doesn't support the `signTransactionBlock` feature.\",\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tconst { signature, transactionBlockBytes } = await walletFeature.signTransactionBlock({\n\t\t\t\t...signTransactionBlockArgs,\n\t\t\t\taccount: signerAccount,\n\t\t\t\tchain: signTransactionBlockArgs.chain ?? signerAccount.chains[0],\n\t\t\t});\n\n\t\t\treturn client.executeTransactionBlock({\n\t\t\t\ttransactionBlock: transactionBlockBytes,\n\t\t\t\tsignature,\n\t\t\t\trequestType,\n\t\t\t\toptions,\n\t\t\t});\n\t\t},\n\t\t...mutationOptions,\n\t});\n}\n", "// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport type { MutationKey } from '@tanstack/react-query';\n\nexport const walletMutationKeys = {\n\tall: { baseScope: 'wallet' },\n\tconnectWallet: formMutationKeyFn('connect-wallet'),\n\tautoconnectWallet: formMutationKeyFn('autoconnect-wallet'),\n\tdisconnectWallet: formMutationKeyFn('disconnect-wallet'),\n\tsignPersonalMessage: formMutationKeyFn('sign-personal-message'),\n\tsignTransactionBlock: formMutationKeyFn('sign-transaction-block'),\n\tsignAndExecuteTransactionBlock: formMutationKeyFn('sign-and-execute-transaction-block'),\n\tswitchAccount: formMutationKeyFn('switch-account'),\n};\n\nfunction formMutationKeyFn(baseEntity: string) {\n\treturn function mutationKeyFn(additionalKeys: MutationKey = []) {\n\t\treturn [{ ...walletMutationKeys.all, baseEntity }, ...additionalKeys];\n\t};\n}\n", "// Copyright (c) Mysten Labs, Inc.\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// SPDX-License-Identifier: Apache-2.0\n\nimport type { SuiClient } from '@mysten/sui.js/client';\nimport { useContext } from 'react';\n\nimport { SuiClientContext } from '../components/SuiClientProvider.js';\n\nexport function useSuiClientContext() {\n\tconst suiClient = useContext(SuiClientContext);\n\n\tif (!suiClient) {\n\t\tthrow new Error(\n\t\t\t'Could not find SuiClientContext. Ensure that you have set up the SuiClientProvider',\n\t\t);\n\t}\n\n\treturn suiClient;\n}\n\nexport function useSuiClient(): SuiClient {\n\treturn useSuiClientContext().client;\n}\n", "// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport { getFullnodeUrl, isSuiClient, SuiClient } from '@mysten/sui.js/client';\nimport type { SuiClientOptions } from '@mysten/sui.js/client';\nimport { createContext, useMemo, useState } from 'react';\n\nimport type { NetworkConfig } from '../hooks/networkConfig.js';\n\ntype NetworkConfigs<T extends NetworkConfig | SuiClient = NetworkConfig | SuiClient> = Record<\n\tstring,\n\tT\n>;\n\nexport interface SuiClientProviderContext {\n\tclient: SuiClient;\n\tnetworks: NetworkConfigs;\n\tnetwork: string;\n\tconfig: NetworkConfig | null;\n\tselectNetwork: (network: string) => void;\n}\n\nexport const SuiClientContext = createContext<SuiClientProviderContext | null>(null);\n\nexport type SuiClientProviderProps<T extends NetworkConfigs> = {\n\tcreateClient?: (name: keyof T, config: T[keyof T]) => SuiClient;\n\tchildren: React.ReactNode;\n\tnetworks?: T;\n\tonNetworkChange?: (network: keyof T & string) => void;\n} & (\n\t| {\n\t\t\tdefaultNetwork?: keyof T & string;\n\t\t\tnetwork?: never;\n\t }\n\t| {\n\t\t\tdefaultNetwork?: never;\n\t\t\tnetwork?: keyof T & string;\n\t }\n);\n\nconst DEFAULT_NETWORKS = {\n\tlocalnet: { url: getFullnodeUrl('localnet') },\n};\n\nconst DEFAULT_CREATE_CLIENT = function createClient(\n\t_name: string,\n\tconfig: NetworkConfig | SuiClient,\n) {\n\tif (isSuiClient(config)) {\n\t\treturn config;\n\t}\n\n\treturn new SuiClient(config);\n};\n\nexport function SuiClientProvider<T extends NetworkConfigs>(props: SuiClientProviderProps<T>) {\n\tconst { onNetworkChange, network, children } = props;\n\tconst networks = (props.networks ?? DEFAULT_NETWORKS) as T;\n\tconst createClient =\n\t\t(props.createClient as typeof DEFAULT_CREATE_CLIENT) ?? DEFAULT_CREATE_CLIENT;\n\n\tconst [selectedNetwork, setSelectedNetwork] = useState<keyof T & string>(\n\t\tprops.network ?? props.defaultNetwork ?? (Object.keys(networks)[0] as keyof T & string),\n\t);\n\n\tconst currentNetwork = props.network ?? selectedNetwork;\n\n\tconst client = useMemo(() => {\n\t\treturn createClient(currentNetwork, networks[currentNetwork]);\n\t}, [createClient, currentNetwork, networks]);\n\n\tconst ctx = useMemo((): SuiClientProviderContext => {\n\t\treturn {\n\t\t\tclient,\n\t\t\tnetworks,\n\t\t\tnetwork: currentNetwork,\n\t\t\tconfig:\n\t\t\t\tnetworks[currentNetwork] instanceof SuiClient\n\t\t\t\t\t? null\n\t\t\t\t\t: (networks[currentNetwork] as SuiClientOptions),\n\t\t\tselectNetwork: (newNetwork) => {\n\t\t\t\tif (currentNetwork === newNetwork) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tif (!network && newNetwork !== selectedNetwork) {\n\t\t\t\t\tsetSelectedNetwork(newNetwork);\n\t\t\t\t}\n\n\t\t\t\tonNetworkChange?.(newNetwork);\n\t\t\t},\n\t\t};\n\t}, [client, networks, selectedNetwork, currentNetwork, network, onNetworkChange]);\n\n\treturn <SuiClientContext.Provider value={ctx}>{children}</SuiClientContext.Provider>;\n}\n", "// Copyright (c) Mysten Labs, Inc.\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\tconst store = useContext(WalletContext);\n\tif (!store) {\n\t\tthrow new Error(\n\t\t\t'Could not find WalletContext. Ensure that you have set up the WalletProvider.',\n\t\t);\n\t}\n\treturn useStore(store, selector);\n}\n", "// Copyright (c) Mysten Labs, Inc.\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// SPDX-License-Identifier: Apache-2.0\n\nimport type { WalletAccount } from '@mysten/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\treturn useWalletStore((state) => state.currentAccount);\n}\n", "// Copyright (c) Mysten Labs, Inc.\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\tconst currentWallet = useWalletStore((state) => state.currentWallet);\n\tconst connectionStatus = useWalletStore((state) => state.connectionStatus);\n\n\tswitch (connectionStatus) {\n\t\tcase 'connecting':\n\t\t\treturn {\n\t\t\t\tconnectionStatus,\n\t\t\t\tcurrentWallet: null,\n\t\t\t\tisDisconnected: false,\n\t\t\t\tisConnecting: true,\n\t\t\t\tisConnected: false,\n\t\t\t} as const;\n\t\tcase 'disconnected':\n\t\t\treturn {\n\t\t\t\tconnectionStatus,\n\t\t\t\tcurrentWallet: null,\n\t\t\t\tisDisconnected: true,\n\t\t\t\tisConnecting: false,\n\t\t\t\tisConnected: false,\n\t\t\t} as const;\n\t\tcase 'connected': {\n\t\t\treturn {\n\t\t\t\tconnectionStatus,\n\t\t\t\tcurrentWallet: currentWallet!,\n\t\t\t\tisDisconnected: false,\n\t\t\t\tisConnecting: false,\n\t\t\t\tisConnected: true,\n\t\t\t} as const;\n\t\t}\n\t}\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAQA,yBAA4B;;;ACHrB,IAAM,qBAAqB;AAAA,EACjC,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;AAClD;AAEA,SAAS,kBAAkB,YAAoB;AAC9C,SAAO,SAAS,cAAc,iBAA8B,CAAC,GAAG;AAC/D,WAAO,CAAC,EAAE,GAAG,mBAAmB,KAAK,WAAW,GAAG,GAAG,cAAc;AAAA,EACrE;AACD;;;ACdO,IAAM,0BAAN,cAAsC,MAAM;AAAC;AAO7C,IAAM,+BAAN,cAA2C,MAAM;AAAC;AAKlD,IAAM,iCAAN,cAA6C,MAAM;AAAC;;;ACd3D,IAAAA,gBAA2B;;;ACD3B,oBAAuD;AAEvD,mBAAiD;AAyFzC;AAxED,IAAM,uBAAmB,4BAA+C,IAAI;AAkBnF,IAAM,mBAAmB;AAAA,EACxB,UAAU,EAAE,SAAK,8BAAe,UAAU,EAAE;AAC7C;;;ADlCO,SAAS,sBAAsB;AACrC,QAAM,gBAAY,0BAAW,gBAAgB;AAE7C,MAAI,CAAC,WAAW;AACf,UAAM,IAAI;AAAA,MACT;AAAA,IACD;AAAA,EACD;AAEA,SAAO;AACR;AAEO,SAAS,eAA0B;AACzC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AI,CAAC,eAAe;AACnB,cAAM,IAAI,wBAAwB,yBAAyB;AAAA,MAC5D;AAEA,YAAM,gBAAgB,yBAAyB,WAAW;AAC1D,UAAI,CAAC,eAAe;AACnB,cAAM,IAAI;AAAA,UACT;AAAA,QACD;AAAA,MACD;AAEA,UAAI,mBAAmB;AACtB,cAAMC,iBAAgB,cAAc,SAAS,oCAAoC;AACjF,YAAI,CAACA,gBAAe;AACnB,gBAAM,IAAI;AAAA,YACT;AAAA,UACD;AAAA,QACD;AAEA,eAAOA,eAAc,+BAA+B;AAAA,UACnD,GAAG;AAAA,UACH,SAAS;AAAA,UACT,OAAO,yBAAyB,SAAS,cAAc,OAAO,CAAC;AAAA,UAC/D;AAAA,UACA;AAAA,QACD,CAAC;AAAA,MACF;AAEA,YAAM,gBAAgB,cAAc,SAAS,0BAA0B;AACvE,UAAI,CAAC,eAAe;AACnB,cAAM,IAAI;AAAA,UACT;AAAA,QACD;AAAA,MACD;AAEA,YAAM,EAAE,WAAW,sBAAsB,IAAI,MAAM,cAAc,qBAAqB;AAAA,QACrF,GAAG;AAAA,QACH,SAAS;AAAA,QACT,OAAO,yBAAyB,SAAS,cAAc,OAAO,CAAC;AAAA,MAChE,CAAC;AAED,aAAO,OAAO,wBAAwB;AAAA,QACrC,kBAAkB;AAAA,QAClB;AAAA,QACA;AAAA,QACA;AAAA,MACD,CAAC;AAAA,IACF;AAAA,IACA,GAAG;AAAA,EACJ,CAAC;AACF;",
6
6
  "names": ["import_react", "import_react", "import_react", "walletFeature"]
7
7
  }
@@ -37,6 +37,7 @@ var WalletFeatureNotSupportedError = class extends Error {
37
37
  var walletMutationKeys = {
38
38
  all: { baseScope: "wallet" },
39
39
  connectWallet: formMutationKeyFn("connect-wallet"),
40
+ autoconnectWallet: formMutationKeyFn("autoconnect-wallet"),
40
41
  disconnectWallet: formMutationKeyFn("disconnect-wallet"),
41
42
  signPersonalMessage: formMutationKeyFn("sign-personal-message"),
42
43
  signTransactionBlock: formMutationKeyFn("sign-transaction-block"),
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../src/hooks/wallet/useSignPersonalMessage.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// SPDX-License-Identifier: Apache-2.0\n\nimport type {\n\tSuiSignPersonalMessageInput,\n\tSuiSignPersonalMessageOutput,\n} from '@mysten/wallet-standard';\nimport type { UseMutationOptions, UseMutationResult } from '@tanstack/react-query';\nimport { useMutation } from '@tanstack/react-query';\n\nimport {\n\tWalletFeatureNotSupportedError,\n\tWalletNoAccountSelectedError,\n\tWalletNotConnectedError,\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 UseSignPersonalMessageArgs = PartialBy<SuiSignPersonalMessageInput, 'account'>;\n\ntype UseSignPersonalMessageResult = SuiSignPersonalMessageOutput;\n\ntype UseSignPersonalMessageError =\n\t| WalletFeatureNotSupportedError\n\t| WalletNoAccountSelectedError\n\t| WalletNotConnectedError\n\t| Error;\n\ntype UseSignPersonalMessageMutationOptions = Omit<\n\tUseMutationOptions<\n\t\tUseSignPersonalMessageResult,\n\t\tUseSignPersonalMessageError,\n\t\tUseSignPersonalMessageArgs,\n\t\tunknown\n\t>,\n\t'mutationFn'\n>;\n\n/**\n * Mutation hook for prompting the user to sign a message.\n */\nexport function useSignPersonalMessage({\n\tmutationKey,\n\t...mutationOptions\n}: UseSignPersonalMessageMutationOptions = {}): UseMutationResult<\n\tUseSignPersonalMessageResult,\n\tUseSignPersonalMessageError,\n\tUseSignPersonalMessageArgs\n> {\n\tconst { currentWallet } = useCurrentWallet();\n\tconst currentAccount = useCurrentAccount();\n\n\treturn useMutation({\n\t\tmutationKey: walletMutationKeys.signPersonalMessage(mutationKey),\n\t\tmutationFn: async (signPersonalMessageArgs) => {\n\t\t\tif (!currentWallet) {\n\t\t\t\tthrow new WalletNotConnectedError('No wallet is connected.');\n\t\t\t}\n\n\t\t\tconst signerAccount = signPersonalMessageArgs.account ?? currentAccount;\n\t\t\tif (!signerAccount) {\n\t\t\t\tthrow new WalletNoAccountSelectedError(\n\t\t\t\t\t'No wallet account is selected to sign the personal message with.',\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tconst signPersonalMessageFeature = currentWallet.features['sui:signPersonalMessage'];\n\t\t\tif (signPersonalMessageFeature) {\n\t\t\t\treturn await signPersonalMessageFeature.signPersonalMessage({\n\t\t\t\t\t...signPersonalMessageArgs,\n\t\t\t\t\taccount: signerAccount,\n\t\t\t\t});\n\t\t\t}\n\n\t\t\t// TODO: Remove this once we officially discontinue sui:signMessage in the wallet standard\n\t\t\tconst signMessageFeature = currentWallet.features['sui:signMessage'];\n\t\t\tif (signMessageFeature) {\n\t\t\t\tconsole.warn(\n\t\t\t\t\t\"This wallet doesn't support the `signPersonalMessage` feature... falling back to `signMessage`.\",\n\t\t\t\t);\n\n\t\t\t\tconst { messageBytes, signature } = await signMessageFeature.signMessage({\n\t\t\t\t\t...signPersonalMessageArgs,\n\t\t\t\t\taccount: signerAccount,\n\t\t\t\t});\n\t\t\t\treturn { bytes: messageBytes, signature };\n\t\t\t}\n\n\t\t\tthrow new WalletFeatureNotSupportedError(\n\t\t\t\t\"This wallet doesn't support the `signPersonalMessage` feature.\",\n\t\t\t);\n\t\t},\n\t\t...mutationOptions,\n\t});\n}\n", "// Copyright (c) Mysten Labs, Inc.\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// SPDX-License-Identifier: Apache-2.0\n\nimport type { MutationKey } from '@tanstack/react-query';\n\nexport const walletMutationKeys = {\n\tall: { baseScope: 'wallet' },\n\tconnectWallet: formMutationKeyFn('connect-wallet'),\n\tdisconnectWallet: formMutationKeyFn('disconnect-wallet'),\n\tsignPersonalMessage: formMutationKeyFn('sign-personal-message'),\n\tsignTransactionBlock: formMutationKeyFn('sign-transaction-block'),\n\tsignAndExecuteTransactionBlock: formMutationKeyFn('sign-and-execute-transaction-block'),\n\tswitchAccount: formMutationKeyFn('switch-account'),\n};\n\nfunction formMutationKeyFn(baseEntity: string) {\n\treturn function mutationKeyFn(additionalKeys: MutationKey = []) {\n\t\treturn [{ ...walletMutationKeys.all, baseEntity }, ...additionalKeys];\n\t};\n}\n", "// Copyright (c) Mysten Labs, Inc.\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\tconst store = useContext(WalletContext);\n\tif (!store) {\n\t\tthrow new Error(\n\t\t\t'Could not find WalletContext. Ensure that you have set up the WalletProvider.',\n\t\t);\n\t}\n\treturn useStore(store, selector);\n}\n", "// Copyright (c) Mysten Labs, Inc.\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// SPDX-License-Identifier: Apache-2.0\n\nimport type { WalletAccount } from '@mysten/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\treturn useWalletStore((state) => state.currentAccount);\n}\n", "// Copyright (c) Mysten Labs, Inc.\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\tconst currentWallet = useWalletStore((state) => state.currentWallet);\n\tconst connectionStatus = useWalletStore((state) => state.connectionStatus);\n\n\tswitch (connectionStatus) {\n\t\tcase 'connecting':\n\t\t\treturn {\n\t\t\t\tconnectionStatus,\n\t\t\t\tcurrentWallet: null,\n\t\t\t\tisDisconnected: false,\n\t\t\t\tisConnecting: true,\n\t\t\t\tisConnected: false,\n\t\t\t} as const;\n\t\tcase 'disconnected':\n\t\t\treturn {\n\t\t\t\tconnectionStatus,\n\t\t\t\tcurrentWallet: null,\n\t\t\t\tisDisconnected: true,\n\t\t\t\tisConnecting: false,\n\t\t\t\tisConnected: false,\n\t\t\t} as const;\n\t\tcase 'connected': {\n\t\t\treturn {\n\t\t\t\tconnectionStatus,\n\t\t\t\tcurrentWallet: currentWallet!,\n\t\t\t\tisDisconnected: false,\n\t\t\t\tisConnecting: false,\n\t\t\t\tisConnected: true,\n\t\t\t} as const;\n\t\t}\n\t}\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAQA,yBAA4B;;;ACFrB,IAAM,0BAAN,cAAsC,MAAM;AAAC;AAO7C,IAAM,+BAAN,cAA2C,MAAM;AAAC;AAKlD,IAAM,iCAAN,cAA6C,MAAM;AAAC;;;ACbpD,IAAM,qBAAqB;AAAA,EACjC,KAAK,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AAA,QACd,aAAa;AAAA,MACd;AAAA,IACD;AAAA,EACD;AACD;;;ANIO,SAAS,uBAAuB;AAAA,EACtC;AAAA,EACA,GAAG;AACJ,IAA2C,CAAC,GAI1C;AACD,QAAM,EAAE,cAAc,IAAI,iBAAiB;AAC3C,QAAM,iBAAiB,kBAAkB;AAEzC,aAAO,gCAAY;AAAA,IAClB,aAAa,mBAAmB,oBAAoB,WAAW;AAAA,IAC/D,YAAY,OAAO,4BAA4B;AAC9C,UAAI,CAAC,eAAe;AACnB,cAAM,IAAI,wBAAwB,yBAAyB;AAAA,MAC5D;AAEA,YAAM,gBAAgB,wBAAwB,WAAW;AACzD,UAAI,CAAC,eAAe;AACnB,cAAM,IAAI;AAAA,UACT;AAAA,QACD;AAAA,MACD;AAEA,YAAM,6BAA6B,cAAc,SAAS,yBAAyB;AACnF,UAAI,4BAA4B;AAC/B,eAAO,MAAM,2BAA2B,oBAAoB;AAAA,UAC3D,GAAG;AAAA,UACH,SAAS;AAAA,QACV,CAAC;AAAA,MACF;AAGA,YAAM,qBAAqB,cAAc,SAAS,iBAAiB;AACnE,UAAI,oBAAoB;AACvB,gBAAQ;AAAA,UACP;AAAA,QACD;AAEA,cAAM,EAAE,cAAc,UAAU,IAAI,MAAM,mBAAmB,YAAY;AAAA,UACxE,GAAG;AAAA,UACH,SAAS;AAAA,QACV,CAAC;AACD,eAAO,EAAE,OAAO,cAAc,UAAU;AAAA,MACzC;AAEA,YAAM,IAAI;AAAA,QACT;AAAA,MACD;AAAA,IACD;AAAA,IACA,GAAG;AAAA,EACJ,CAAC;AACF;",
4
+ "sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport type {\n\tSuiSignPersonalMessageInput,\n\tSuiSignPersonalMessageOutput,\n} from '@mysten/wallet-standard';\nimport type { UseMutationOptions, UseMutationResult } from '@tanstack/react-query';\nimport { useMutation } from '@tanstack/react-query';\n\nimport {\n\tWalletFeatureNotSupportedError,\n\tWalletNoAccountSelectedError,\n\tWalletNotConnectedError,\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 UseSignPersonalMessageArgs = PartialBy<SuiSignPersonalMessageInput, 'account'>;\n\ntype UseSignPersonalMessageResult = SuiSignPersonalMessageOutput;\n\ntype UseSignPersonalMessageError =\n\t| WalletFeatureNotSupportedError\n\t| WalletNoAccountSelectedError\n\t| WalletNotConnectedError\n\t| Error;\n\ntype UseSignPersonalMessageMutationOptions = Omit<\n\tUseMutationOptions<\n\t\tUseSignPersonalMessageResult,\n\t\tUseSignPersonalMessageError,\n\t\tUseSignPersonalMessageArgs,\n\t\tunknown\n\t>,\n\t'mutationFn'\n>;\n\n/**\n * Mutation hook for prompting the user to sign a message.\n */\nexport function useSignPersonalMessage({\n\tmutationKey,\n\t...mutationOptions\n}: UseSignPersonalMessageMutationOptions = {}): UseMutationResult<\n\tUseSignPersonalMessageResult,\n\tUseSignPersonalMessageError,\n\tUseSignPersonalMessageArgs\n> {\n\tconst { currentWallet } = useCurrentWallet();\n\tconst currentAccount = useCurrentAccount();\n\n\treturn useMutation({\n\t\tmutationKey: walletMutationKeys.signPersonalMessage(mutationKey),\n\t\tmutationFn: async (signPersonalMessageArgs) => {\n\t\t\tif (!currentWallet) {\n\t\t\t\tthrow new WalletNotConnectedError('No wallet is connected.');\n\t\t\t}\n\n\t\t\tconst signerAccount = signPersonalMessageArgs.account ?? currentAccount;\n\t\t\tif (!signerAccount) {\n\t\t\t\tthrow new WalletNoAccountSelectedError(\n\t\t\t\t\t'No wallet account is selected to sign the personal message with.',\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tconst signPersonalMessageFeature = currentWallet.features['sui:signPersonalMessage'];\n\t\t\tif (signPersonalMessageFeature) {\n\t\t\t\treturn await signPersonalMessageFeature.signPersonalMessage({\n\t\t\t\t\t...signPersonalMessageArgs,\n\t\t\t\t\taccount: signerAccount,\n\t\t\t\t});\n\t\t\t}\n\n\t\t\t// TODO: Remove this once we officially discontinue sui:signMessage in the wallet standard\n\t\t\tconst signMessageFeature = currentWallet.features['sui:signMessage'];\n\t\t\tif (signMessageFeature) {\n\t\t\t\tconsole.warn(\n\t\t\t\t\t\"This wallet doesn't support the `signPersonalMessage` feature... falling back to `signMessage`.\",\n\t\t\t\t);\n\n\t\t\t\tconst { messageBytes, signature } = await signMessageFeature.signMessage({\n\t\t\t\t\t...signPersonalMessageArgs,\n\t\t\t\t\taccount: signerAccount,\n\t\t\t\t});\n\t\t\t\treturn { bytes: messageBytes, signature };\n\t\t\t}\n\n\t\t\tthrow new WalletFeatureNotSupportedError(\n\t\t\t\t\"This wallet doesn't support the `signPersonalMessage` feature.\",\n\t\t\t);\n\t\t},\n\t\t...mutationOptions,\n\t});\n}\n", "// Copyright (c) Mysten Labs, Inc.\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// SPDX-License-Identifier: Apache-2.0\n\nimport type { MutationKey } from '@tanstack/react-query';\n\nexport const walletMutationKeys = {\n\tall: { baseScope: 'wallet' },\n\tconnectWallet: formMutationKeyFn('connect-wallet'),\n\tautoconnectWallet: formMutationKeyFn('autoconnect-wallet'),\n\tdisconnectWallet: formMutationKeyFn('disconnect-wallet'),\n\tsignPersonalMessage: formMutationKeyFn('sign-personal-message'),\n\tsignTransactionBlock: formMutationKeyFn('sign-transaction-block'),\n\tsignAndExecuteTransactionBlock: formMutationKeyFn('sign-and-execute-transaction-block'),\n\tswitchAccount: formMutationKeyFn('switch-account'),\n};\n\nfunction formMutationKeyFn(baseEntity: string) {\n\treturn function mutationKeyFn(additionalKeys: MutationKey = []) {\n\t\treturn [{ ...walletMutationKeys.all, baseEntity }, ...additionalKeys];\n\t};\n}\n", "// Copyright (c) Mysten Labs, Inc.\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\tconst store = useContext(WalletContext);\n\tif (!store) {\n\t\tthrow new Error(\n\t\t\t'Could not find WalletContext. Ensure that you have set up the WalletProvider.',\n\t\t);\n\t}\n\treturn useStore(store, selector);\n}\n", "// Copyright (c) Mysten Labs, Inc.\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// SPDX-License-Identifier: Apache-2.0\n\nimport type { WalletAccount } from '@mysten/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\treturn useWalletStore((state) => state.currentAccount);\n}\n", "// Copyright (c) Mysten Labs, Inc.\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\tconst currentWallet = useWalletStore((state) => state.currentWallet);\n\tconst connectionStatus = useWalletStore((state) => state.connectionStatus);\n\n\tswitch (connectionStatus) {\n\t\tcase 'connecting':\n\t\t\treturn {\n\t\t\t\tconnectionStatus,\n\t\t\t\tcurrentWallet: null,\n\t\t\t\tisDisconnected: false,\n\t\t\t\tisConnecting: true,\n\t\t\t\tisConnected: false,\n\t\t\t} as const;\n\t\tcase 'disconnected':\n\t\t\treturn {\n\t\t\t\tconnectionStatus,\n\t\t\t\tcurrentWallet: null,\n\t\t\t\tisDisconnected: true,\n\t\t\t\tisConnecting: false,\n\t\t\t\tisConnected: false,\n\t\t\t} as const;\n\t\tcase 'connected': {\n\t\t\treturn {\n\t\t\t\tconnectionStatus,\n\t\t\t\tcurrentWallet: currentWallet!,\n\t\t\t\tisDisconnected: false,\n\t\t\t\tisConnecting: false,\n\t\t\t\tisConnected: true,\n\t\t\t} as const;\n\t\t}\n\t}\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAQA,yBAA4B;;;ACFrB,IAAM,0BAAN,cAAsC,MAAM;AAAC;AAO7C,IAAM,+BAAN,cAA2C,MAAM;AAAC;AAKlD,IAAM,iCAAN,cAA6C,MAAM;AAAC;;;ACbpD,IAAM,qBAAqB;AAAA,EACjC,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;AAClD;AAEA,SAAS,kBAAkB,YAAoB;AAC9C,SAAO,SAAS,cAAc,iBAA8B,CAAC,GAAG;AAC/D,WAAO,CAAC,EAAE,GAAG,mBAAmB,KAAK,WAAW,GAAG,GAAG,cAAc;AAAA,EACrE;AACD;;;ACjBA,IAAAA,gBAA2B;AAC3B,qB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AAI;AAAA,UACT;AAAA,QACD;AAAA,MACD;AAEA,YAAM,6BAA6B,cAAc,SAAS,yBAAyB;AACnF,UAAI,4BAA4B;AAC/B,eAAO,MAAM,2BAA2B,oBAAoB;AAAA,UAC3D,GAAG;AAAA,UACH,SAAS;AAAA,QACV,CAAC;AAAA,MACF;AAGA,YAAM,qBAAqB,cAAc,SAAS,iBAAiB;AACnE,UAAI,oBAAoB;AACvB,gBAAQ;AAAA,UACP;AAAA,QACD;AAEA,cAAM,EAAE,cAAc,UAAU,IAAI,MAAM,mBAAmB,YAAY;AAAA,UACxE,GAAG;AAAA,UACH,SAAS;AAAA,QACV,CAAC;AACD,eAAO,EAAE,OAAO,cAAc,UAAU;AAAA,MACzC;AAEA,YAAM,IAAI;AAAA,QACT;AAAA,MACD;AAAA,IACD;AAAA,IACA,GAAG;AAAA,EACJ,CAAC;AACF;",
6
6
  "names": ["import_react"]
7
7
  }
@@ -37,6 +37,7 @@ var WalletFeatureNotSupportedError = class extends Error {
37
37
  var walletMutationKeys = {
38
38
  all: { baseScope: "wallet" },
39
39
  connectWallet: formMutationKeyFn("connect-wallet"),
40
+ autoconnectWallet: formMutationKeyFn("autoconnect-wallet"),
40
41
  disconnectWallet: formMutationKeyFn("disconnect-wallet"),
41
42
  signPersonalMessage: formMutationKeyFn("sign-personal-message"),
42
43
  signTransactionBlock: formMutationKeyFn("sign-transaction-block"),
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
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// SPDX-License-Identifier: Apache-2.0\n\nimport type {\n\tSuiSignTransactionBlockInput,\n\tSuiSignTransactionBlockOutput,\n} from '@mysten/wallet-standard';\nimport type { UseMutationOptions, UseMutationResult } from '@tanstack/react-query';\nimport { useMutation } from '@tanstack/react-query';\n\nimport {\n\tWalletFeatureNotSupportedError,\n\tWalletNoAccountSelectedError,\n\tWalletNotConnectedError,\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<SuiSignTransactionBlockInput, 'account' | 'chain'>;\n\ntype UseSignTransactionBlockResult = SuiSignTransactionBlockOutput;\n\ntype UseSignTransactionBlockError =\n\t| WalletFeatureNotSupportedError\n\t| WalletNoAccountSelectedError\n\t| WalletNotConnectedError\n\t| Error;\n\ntype UseSignTransactionBlockMutationOptions = Omit<\n\tUseMutationOptions<\n\t\tUseSignTransactionBlockResult,\n\t\tUseSignTransactionBlockError,\n\t\tUseSignTransactionBlockArgs,\n\t\tunknown\n\t>,\n\t'mutationFn'\n>;\n\n/**\n * Mutation hook for prompting the user to sign a transaction block.\n */\nexport function useSignTransactionBlock({\n\tmutationKey,\n\t...mutationOptions\n}: UseSignTransactionBlockMutationOptions = {}): UseMutationResult<\n\tUseSignTransactionBlockResult,\n\tUseSignTransactionBlockError,\n\tUseSignTransactionBlockArgs\n> {\n\tconst { currentWallet } = useCurrentWallet();\n\tconst currentAccount = useCurrentAccount();\n\n\treturn useMutation({\n\t\tmutationKey: walletMutationKeys.signTransactionBlock(mutationKey),\n\t\tmutationFn: async (signTransactionBlockArgs) => {\n\t\t\tif (!currentWallet) {\n\t\t\t\tthrow new WalletNotConnectedError('No wallet is connected.');\n\t\t\t}\n\n\t\t\tconst signerAccount = signTransactionBlockArgs.account ?? currentAccount;\n\t\t\tif (!signerAccount) {\n\t\t\t\tthrow new WalletNoAccountSelectedError(\n\t\t\t\t\t'No wallet account is selected to sign the transaction block with.',\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tconst walletFeature = currentWallet.features['sui:signTransactionBlock'];\n\t\t\tif (!walletFeature) {\n\t\t\t\tthrow new WalletFeatureNotSupportedError(\n\t\t\t\t\t\"This wallet doesn't support the `SignTransactionBlock` feature.\",\n\t\t\t\t);\n\t\t\t}\n\n\t\t\treturn await walletFeature.signTransactionBlock({\n\t\t\t\t...signTransactionBlockArgs,\n\t\t\t\taccount: signerAccount,\n\t\t\t\tchain: signTransactionBlockArgs.chain ?? signerAccount.chains[0],\n\t\t\t});\n\t\t},\n\t\t...mutationOptions,\n\t});\n}\n", "// Copyright (c) Mysten Labs, Inc.\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// SPDX-License-Identifier: Apache-2.0\n\nimport type { MutationKey } from '@tanstack/react-query';\n\nexport const walletMutationKeys = {\n\tall: { baseScope: 'wallet' },\n\tconnectWallet: formMutationKeyFn('connect-wallet'),\n\tdisconnectWallet: formMutationKeyFn('disconnect-wallet'),\n\tsignPersonalMessage: formMutationKeyFn('sign-personal-message'),\n\tsignTransactionBlock: formMutationKeyFn('sign-transaction-block'),\n\tsignAndExecuteTransactionBlock: formMutationKeyFn('sign-and-execute-transaction-block'),\n\tswitchAccount: formMutationKeyFn('switch-account'),\n};\n\nfunction formMutationKeyFn(baseEntity: string) {\n\treturn function mutationKeyFn(additionalKeys: MutationKey = []) {\n\t\treturn [{ ...walletMutationKeys.all, baseEntity }, ...additionalKeys];\n\t};\n}\n", "// Copyright (c) Mysten Labs, Inc.\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\tconst store = useContext(WalletContext);\n\tif (!store) {\n\t\tthrow new Error(\n\t\t\t'Could not find WalletContext. Ensure that you have set up the WalletProvider.',\n\t\t);\n\t}\n\treturn useStore(store, selector);\n}\n", "// Copyright (c) Mysten Labs, Inc.\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// SPDX-License-Identifier: Apache-2.0\n\nimport type { WalletAccount } from '@mysten/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\treturn useWalletStore((state) => state.currentAccount);\n}\n", "// Copyright (c) Mysten Labs, Inc.\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\tconst currentWallet = useWalletStore((state) => state.currentWallet);\n\tconst connectionStatus = useWalletStore((state) => state.connectionStatus);\n\n\tswitch (connectionStatus) {\n\t\tcase 'connecting':\n\t\t\treturn {\n\t\t\t\tconnectionStatus,\n\t\t\t\tcurrentWallet: null,\n\t\t\t\tisDisconnected: false,\n\t\t\t\tisConnecting: true,\n\t\t\t\tisConnected: false,\n\t\t\t} as const;\n\t\tcase 'disconnected':\n\t\t\treturn {\n\t\t\t\tconnectionStatus,\n\t\t\t\tcurrentWallet: null,\n\t\t\t\tisDisconnected: true,\n\t\t\t\tisConnecting: false,\n\t\t\t\tisConnected: false,\n\t\t\t} as const;\n\t\tcase 'connected': {\n\t\t\treturn {\n\t\t\t\tconnectionStatus,\n\t\t\t\tcurrentWallet: currentWallet!,\n\t\t\t\tisDisconnected: false,\n\t\t\t\tisConnecting: false,\n\t\t\t\tisConnected: true,\n\t\t\t} as const;\n\t\t}\n\t}\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAQA,yBAA4B;;;ACFrB,IAAM,0BAAN,cAAsC,MAAM;AAAC;AAO7C,IAAM,+BAAN,cAA2C,MAAM;AAAC;AAKlD,IAAM,iCAAN,cAA6C,MAAM;AAAC;;;ACbpD,IAAM,qBAAqB;AAAA,EACjC,KAAK,EAAE,WAAW,SAAS;AAAA,EAC3B,eAAe,kBAAkB,gBAAgB;AAAA,EACjD,kBAAkB,kBAAkB,mBAAmB;AAAA,EACvD,qBAAqB,kBAAkB,uBAAuB;AAAA,EAC9D,sBAAsB,kBAAkB,wBAAwB;AAAA,EAChE,gCAAgC,kBAAkB,oCAAoC;AAAA,EACtF,eAAe,kBAAkB,gBAAgB;AAClD;AAEA,SAAS,kBAAkB,YAAoB;AAC9C,SAAO,SAAS,cAAc,iBAA8B,CAAC,GAAG;AAC/D,WAAO,CAAC,EAAE,GAAG,mBAAmB,KAAK,WAAW,GAAG,GAAG,cAAc;AAAA,EACrE;AACD;;;AChBA,IAAAA,gBAA2B;AAC3B,qBAAyB;;;ACDzB,mBAA8B;AAIvB,IAAM,oBAAgB,4BAAkC,IAAI;;;ADE5D,SAAS,eAAkB,UAAuC;AACxE,QAAM,YAAQ,0BAAW,aAAa;AACtC,MAAI,CAAC,OAAO;AACX,UAAM,IAAI;AAAA,MACT;AAAA,IACD;AAAA,EACD;AACA,aAAO,yBAAS,OAAO,QAAQ;AAChC;;;AEPO,SAAS,oBAA0C;AACzD,SAAO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AC;AAAA,MAChE,CAAC;AAAA,IACF;AAAA,IACA,GAAG;AAAA,EACJ,CAAC;AACF;",
4
+ "sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport type {\n\tSuiSignTransactionBlockInput,\n\tSuiSignTransactionBlockOutput,\n} from '@mysten/wallet-standard';\nimport type { UseMutationOptions, UseMutationResult } from '@tanstack/react-query';\nimport { useMutation } from '@tanstack/react-query';\n\nimport {\n\tWalletFeatureNotSupportedError,\n\tWalletNoAccountSelectedError,\n\tWalletNotConnectedError,\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<SuiSignTransactionBlockInput, 'account' | 'chain'>;\n\ntype UseSignTransactionBlockResult = SuiSignTransactionBlockOutput;\n\ntype UseSignTransactionBlockError =\n\t| WalletFeatureNotSupportedError\n\t| WalletNoAccountSelectedError\n\t| WalletNotConnectedError\n\t| Error;\n\ntype UseSignTransactionBlockMutationOptions = Omit<\n\tUseMutationOptions<\n\t\tUseSignTransactionBlockResult,\n\t\tUseSignTransactionBlockError,\n\t\tUseSignTransactionBlockArgs,\n\t\tunknown\n\t>,\n\t'mutationFn'\n>;\n\n/**\n * Mutation hook for prompting the user to sign a transaction block.\n */\nexport function useSignTransactionBlock({\n\tmutationKey,\n\t...mutationOptions\n}: UseSignTransactionBlockMutationOptions = {}): UseMutationResult<\n\tUseSignTransactionBlockResult,\n\tUseSignTransactionBlockError,\n\tUseSignTransactionBlockArgs\n> {\n\tconst { currentWallet } = useCurrentWallet();\n\tconst currentAccount = useCurrentAccount();\n\n\treturn useMutation({\n\t\tmutationKey: walletMutationKeys.signTransactionBlock(mutationKey),\n\t\tmutationFn: async (signTransactionBlockArgs) => {\n\t\t\tif (!currentWallet) {\n\t\t\t\tthrow new WalletNotConnectedError('No wallet is connected.');\n\t\t\t}\n\n\t\t\tconst signerAccount = signTransactionBlockArgs.account ?? currentAccount;\n\t\t\tif (!signerAccount) {\n\t\t\t\tthrow new WalletNoAccountSelectedError(\n\t\t\t\t\t'No wallet account is selected to sign the transaction block with.',\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tconst walletFeature = currentWallet.features['sui:signTransactionBlock'];\n\t\t\tif (!walletFeature) {\n\t\t\t\tthrow new WalletFeatureNotSupportedError(\n\t\t\t\t\t\"This wallet doesn't support the `SignTransactionBlock` feature.\",\n\t\t\t\t);\n\t\t\t}\n\n\t\t\treturn await walletFeature.signTransactionBlock({\n\t\t\t\t...signTransactionBlockArgs,\n\t\t\t\taccount: signerAccount,\n\t\t\t\tchain: signTransactionBlockArgs.chain ?? signerAccount.chains[0],\n\t\t\t});\n\t\t},\n\t\t...mutationOptions,\n\t});\n}\n", "// Copyright (c) Mysten Labs, Inc.\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// SPDX-License-Identifier: Apache-2.0\n\nimport type { MutationKey } from '@tanstack/react-query';\n\nexport const walletMutationKeys = {\n\tall: { baseScope: 'wallet' },\n\tconnectWallet: formMutationKeyFn('connect-wallet'),\n\tautoconnectWallet: formMutationKeyFn('autoconnect-wallet'),\n\tdisconnectWallet: formMutationKeyFn('disconnect-wallet'),\n\tsignPersonalMessage: formMutationKeyFn('sign-personal-message'),\n\tsignTransactionBlock: formMutationKeyFn('sign-transaction-block'),\n\tsignAndExecuteTransactionBlock: formMutationKeyFn('sign-and-execute-transaction-block'),\n\tswitchAccount: formMutationKeyFn('switch-account'),\n};\n\nfunction formMutationKeyFn(baseEntity: string) {\n\treturn function mutationKeyFn(additionalKeys: MutationKey = []) {\n\t\treturn [{ ...walletMutationKeys.all, baseEntity }, ...additionalKeys];\n\t};\n}\n", "// Copyright (c) Mysten Labs, Inc.\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\tconst store = useContext(WalletContext);\n\tif (!store) {\n\t\tthrow new Error(\n\t\t\t'Could not find WalletContext. Ensure that you have set up the WalletProvider.',\n\t\t);\n\t}\n\treturn useStore(store, selector);\n}\n", "// Copyright (c) Mysten Labs, Inc.\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// SPDX-License-Identifier: Apache-2.0\n\nimport type { WalletAccount } from '@mysten/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\treturn useWalletStore((state) => state.currentAccount);\n}\n", "// Copyright (c) Mysten Labs, Inc.\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\tconst currentWallet = useWalletStore((state) => state.currentWallet);\n\tconst connectionStatus = useWalletStore((state) => state.connectionStatus);\n\n\tswitch (connectionStatus) {\n\t\tcase 'connecting':\n\t\t\treturn {\n\t\t\t\tconnectionStatus,\n\t\t\t\tcurrentWallet: null,\n\t\t\t\tisDisconnected: false,\n\t\t\t\tisConnecting: true,\n\t\t\t\tisConnected: false,\n\t\t\t} as const;\n\t\tcase 'disconnected':\n\t\t\treturn {\n\t\t\t\tconnectionStatus,\n\t\t\t\tcurrentWallet: null,\n\t\t\t\tisDisconnected: true,\n\t\t\t\tisConnecting: false,\n\t\t\t\tisConnected: false,\n\t\t\t} as const;\n\t\tcase 'connected': {\n\t\t\treturn {\n\t\t\t\tconnectionStatus,\n\t\t\t\tcurrentWallet: currentWallet!,\n\t\t\t\tisDisconnected: false,\n\t\t\t\tisConnecting: false,\n\t\t\t\tisConnected: true,\n\t\t\t} as const;\n\t\t}\n\t}\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAQA,yBAA4B;;;ACFrB,IAAM,0BAAN,cAAsC,MAAM;AAAC;AAO7C,IAAM,+BAAN,cAA2C,MAAM;AAAC;AAKlD,IAAM,iCAAN,cAA6C,MAAM;AAAC;;;ACbpD,IAAM,qBAAqB;AAAA,EACjC,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;AAClD;AAEA,SAAS,kBAAkB,YAAoB;AAC9C,SAAO,SAAS,cAAc,iBAA8B,CAAC,GAAG;AAC/D,WAAO,CAAC,EAAE,GAAG,mBAAmB,KAAK,WAAW,GAAG,GAAG,cAAc;AAAA,EACrE;AACD;;;ACjBA,IAAAA,gBAA2B;AAC3B,qBAA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I;AAAA,UACT;AAAA,QACD;AAAA,MACD;AAEA,YAAM,gBAAgB,cAAc,SAAS,0BAA0B;AACvE,UAAI,CAAC,eAAe;AACnB,cAAM,IAAI;AAAA,UACT;AAAA,QACD;AAAA,MACD;AAEA,aAAO,MAAM,cAAc,qBAAqB;AAAA,QAC/C,GAAG;AAAA,QACH,SAAS;AAAA,QACT,OAAO,yBAAyB,SAAS,cAAc,OAAO,CAAC;AAAA,MAChE,CAAC;AAAA,IACF;AAAA,IACA,GAAG;AAAA,EACJ,CAAC;AACF;",
6
6
  "names": ["import_react"]
7
7
  }
@@ -29,6 +29,7 @@ var import_react_query = require("@tanstack/react-query");
29
29
  var walletMutationKeys = {
30
30
  all: { baseScope: "wallet" },
31
31
  connectWallet: formMutationKeyFn("connect-wallet"),
32
+ autoconnectWallet: formMutationKeyFn("autoconnect-wallet"),
32
33
  disconnectWallet: formMutationKeyFn("disconnect-wallet"),
33
34
  signPersonalMessage: formMutationKeyFn("sign-personal-message"),
34
35
  signTransactionBlock: formMutationKeyFn("sign-transaction-block"),
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../src/hooks/wallet/useSwitchAccount.ts", "../../../../src/constants/walletMutationKeys.ts", "../../../../src/errors/walletErrors.ts", "../../../../src/hooks/wallet/useWalletStore.ts", "../../../../src/contexts/walletContext.ts", "../../../../src/hooks/wallet/useCurrentWallet.ts"],
4
- "sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport type { WalletAccount } from '@mysten/wallet-standard';\nimport type { UseMutationOptions, UseMutationResult } from '@tanstack/react-query';\nimport { useMutation } from '@tanstack/react-query';\n\nimport { walletMutationKeys } from '../../constants/walletMutationKeys.js';\nimport { WalletAccountNotFoundError, WalletNotConnectedError } from '../../errors/walletErrors.js';\nimport { useCurrentWallet } from './useCurrentWallet.js';\nimport { useWalletStore } from './useWalletStore.js';\n\ntype SwitchAccountArgs = {\n\taccount: WalletAccount;\n};\n\ntype SwitchAccountResult = void;\n\ntype UseSwitchAccountError = WalletNotConnectedError | WalletAccountNotFoundError | Error;\n\ntype UseSwitchAccountMutationOptions = Omit<\n\tUseMutationOptions<SwitchAccountResult, UseSwitchAccountError, SwitchAccountArgs, unknown>,\n\t'mutationFn'\n>;\n\n/**\n * Mutation hook for switching to a specific wallet account.\n */\nexport function useSwitchAccount({\n\tmutationKey,\n\t...mutationOptions\n}: UseSwitchAccountMutationOptions = {}): UseMutationResult<\n\tSwitchAccountResult,\n\tUseSwitchAccountError,\n\tSwitchAccountArgs\n> {\n\tconst { currentWallet } = useCurrentWallet();\n\tconst setAccountSwitched = useWalletStore((state) => state.setAccountSwitched);\n\n\treturn useMutation({\n\t\tmutationKey: walletMutationKeys.switchAccount(mutationKey),\n\t\tmutationFn: async ({ account }) => {\n\t\t\tif (!currentWallet) {\n\t\t\t\tthrow new WalletNotConnectedError('No wallet is connected.');\n\t\t\t}\n\n\t\t\tconst accountToSelect = currentWallet.accounts.find(\n\t\t\t\t(walletAccount) => walletAccount.address === account.address,\n\t\t\t);\n\t\t\tif (!accountToSelect) {\n\t\t\t\tthrow new WalletAccountNotFoundError(\n\t\t\t\t\t`No account with address ${account.address} is connected to ${currentWallet.name}.`,\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tsetAccountSwitched(accountToSelect);\n\t\t},\n\t\t...mutationOptions,\n\t});\n}\n", "// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport type { MutationKey } from '@tanstack/react-query';\n\nexport const walletMutationKeys = {\n\tall: { baseScope: 'wallet' },\n\tconnectWallet: formMutationKeyFn('connect-wallet'),\n\tdisconnectWallet: formMutationKeyFn('disconnect-wallet'),\n\tsignPersonalMessage: formMutationKeyFn('sign-personal-message'),\n\tsignTransactionBlock: formMutationKeyFn('sign-transaction-block'),\n\tsignAndExecuteTransactionBlock: formMutationKeyFn('sign-and-execute-transaction-block'),\n\tswitchAccount: formMutationKeyFn('switch-account'),\n};\n\nfunction formMutationKeyFn(baseEntity: string) {\n\treturn function mutationKeyFn(additionalKeys: MutationKey = []) {\n\t\treturn [{ ...walletMutationKeys.all, baseEntity }, ...additionalKeys];\n\t};\n}\n", "// Copyright (c) Mysten Labs, Inc.\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// 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\tconst store = useContext(WalletContext);\n\tif (!store) {\n\t\tthrow new Error(\n\t\t\t'Could not find WalletContext. Ensure that you have set up the WalletProvider.',\n\t\t);\n\t}\n\treturn useStore(store, selector);\n}\n", "// Copyright (c) Mysten Labs, Inc.\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// 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\tconst currentWallet = useWalletStore((state) => state.currentWallet);\n\tconst connectionStatus = useWalletStore((state) => state.connectionStatus);\n\n\tswitch (connectionStatus) {\n\t\tcase 'connecting':\n\t\t\treturn {\n\t\t\t\tconnectionStatus,\n\t\t\t\tcurrentWallet: null,\n\t\t\t\tisDisconnected: false,\n\t\t\t\tisConnecting: true,\n\t\t\t\tisConnected: false,\n\t\t\t} as const;\n\t\tcase 'disconnected':\n\t\t\treturn {\n\t\t\t\tconnectionStatus,\n\t\t\t\tcurrentWallet: null,\n\t\t\t\tisDisconnected: true,\n\t\t\t\tisConnecting: false,\n\t\t\t\tisConnected: false,\n\t\t\t} as const;\n\t\tcase 'connected': {\n\t\t\treturn {\n\t\t\t\tconnectionStatus,\n\t\t\t\tcurrentWallet: currentWallet!,\n\t\t\t\tisDisconnected: false,\n\t\t\t\tisConnecting: false,\n\t\t\t\tisConnected: true,\n\t\t\t} as const;\n\t\t}\n\t}\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAKA,yBAA4B;;;ACArB,IAAM,qBAAqB;AAAA,EACjC,KAAK,EAAE,WAAW,SAAS;AAAA,EAC3B,eAAe,kBAAkB,gBAAgB;AAAA,EACjD,kBAAkB,kBAAkB,mBAAmB;AAAA,EACvD,qBAAqB,kBAAkB,uBAAuB;AAAA,EAC9D,sBAAsB,kBAAkB,wBAAwB;AAAA,EAChE,gCAAgC,kBAAkB,oCAAoC;AAAA,EACtF,eAAe,kBAAkB,gBAAgB;AAClD;AAEA,SAAS,kBAAkB,YAAoB;AAC9C,SAAO,SAAS,cAAc,iBAA8B,CAAC,GAAG;AAC/D,WAAO,CAAC,EAAE,GAAG,mBAAmB,KAAK,WAAW,GAAG,GAAG,cAAc;AAAA,EACrE;AACD;;;ACbO,IAAM,0BAAN,cAAsC,MAAM;AAAC;AAiB7C,IAAM,6BAAN,cAAyC,MAAM;AAAC;;;ACpBvD,IAAAA,gBAA2B;AAC3B,qBAAyB;;;ACDzB,mBAA8B;AAIvB,IAAM,oBAAgB,4B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BAA2B,cAAc;AAAA,QAC7E;AAAA,MACD;AAEA,yBAAmB,eAAe;AAAA,IACnC;AAAA,IACA,GAAG;AAAA,EACJ,CAAC;AACF;",
4
+ "sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport type { WalletAccount } from '@mysten/wallet-standard';\nimport type { UseMutationOptions, UseMutationResult } from '@tanstack/react-query';\nimport { useMutation } from '@tanstack/react-query';\n\nimport { walletMutationKeys } from '../../constants/walletMutationKeys.js';\nimport { WalletAccountNotFoundError, WalletNotConnectedError } from '../../errors/walletErrors.js';\nimport { useCurrentWallet } from './useCurrentWallet.js';\nimport { useWalletStore } from './useWalletStore.js';\n\ntype SwitchAccountArgs = {\n\taccount: WalletAccount;\n};\n\ntype SwitchAccountResult = void;\n\ntype UseSwitchAccountError = WalletNotConnectedError | WalletAccountNotFoundError | Error;\n\ntype UseSwitchAccountMutationOptions = Omit<\n\tUseMutationOptions<SwitchAccountResult, UseSwitchAccountError, SwitchAccountArgs, unknown>,\n\t'mutationFn'\n>;\n\n/**\n * Mutation hook for switching to a specific wallet account.\n */\nexport function useSwitchAccount({\n\tmutationKey,\n\t...mutationOptions\n}: UseSwitchAccountMutationOptions = {}): UseMutationResult<\n\tSwitchAccountResult,\n\tUseSwitchAccountError,\n\tSwitchAccountArgs\n> {\n\tconst { currentWallet } = useCurrentWallet();\n\tconst setAccountSwitched = useWalletStore((state) => state.setAccountSwitched);\n\n\treturn useMutation({\n\t\tmutationKey: walletMutationKeys.switchAccount(mutationKey),\n\t\tmutationFn: async ({ account }) => {\n\t\t\tif (!currentWallet) {\n\t\t\t\tthrow new WalletNotConnectedError('No wallet is connected.');\n\t\t\t}\n\n\t\t\tconst accountToSelect = currentWallet.accounts.find(\n\t\t\t\t(walletAccount) => walletAccount.address === account.address,\n\t\t\t);\n\t\t\tif (!accountToSelect) {\n\t\t\t\tthrow new WalletAccountNotFoundError(\n\t\t\t\t\t`No account with address ${account.address} is connected to ${currentWallet.name}.`,\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tsetAccountSwitched(accountToSelect);\n\t\t},\n\t\t...mutationOptions,\n\t});\n}\n", "// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport type { MutationKey } from '@tanstack/react-query';\n\nexport const walletMutationKeys = {\n\tall: { baseScope: 'wallet' },\n\tconnectWallet: formMutationKeyFn('connect-wallet'),\n\tautoconnectWallet: formMutationKeyFn('autoconnect-wallet'),\n\tdisconnectWallet: formMutationKeyFn('disconnect-wallet'),\n\tsignPersonalMessage: formMutationKeyFn('sign-personal-message'),\n\tsignTransactionBlock: formMutationKeyFn('sign-transaction-block'),\n\tsignAndExecuteTransactionBlock: formMutationKeyFn('sign-and-execute-transaction-block'),\n\tswitchAccount: formMutationKeyFn('switch-account'),\n};\n\nfunction formMutationKeyFn(baseEntity: string) {\n\treturn function mutationKeyFn(additionalKeys: MutationKey = []) {\n\t\treturn [{ ...walletMutationKeys.all, baseEntity }, ...additionalKeys];\n\t};\n}\n", "// Copyright (c) Mysten Labs, Inc.\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// 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\tconst store = useContext(WalletContext);\n\tif (!store) {\n\t\tthrow new Error(\n\t\t\t'Could not find WalletContext. Ensure that you have set up the WalletProvider.',\n\t\t);\n\t}\n\treturn useStore(store, selector);\n}\n", "// Copyright (c) Mysten Labs, Inc.\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// 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\tconst currentWallet = useWalletStore((state) => state.currentWallet);\n\tconst connectionStatus = useWalletStore((state) => state.connectionStatus);\n\n\tswitch (connectionStatus) {\n\t\tcase 'connecting':\n\t\t\treturn {\n\t\t\t\tconnectionStatus,\n\t\t\t\tcurrentWallet: null,\n\t\t\t\tisDisconnected: false,\n\t\t\t\tisConnecting: true,\n\t\t\t\tisConnected: false,\n\t\t\t} as const;\n\t\tcase 'disconnected':\n\t\t\treturn {\n\t\t\t\tconnectionStatus,\n\t\t\t\tcurrentWallet: null,\n\t\t\t\tisDisconnected: true,\n\t\t\t\tisConnecting: false,\n\t\t\t\tisConnected: false,\n\t\t\t} as const;\n\t\tcase 'connected': {\n\t\t\treturn {\n\t\t\t\tconnectionStatus,\n\t\t\t\tcurrentWallet: currentWallet!,\n\t\t\t\tisDisconnected: false,\n\t\t\t\tisConnecting: false,\n\t\t\t\tisConnected: true,\n\t\t\t} as const;\n\t\t}\n\t}\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAKA,yBAA4B;;;ACArB,IAAM,qBAAqB;AAAA,EACjC,KAAK,EAAE,WAAW,SAAS;AAAA,EAC3B,eAAe,kBAAkB,gBAAgB;AAAA,EACjD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AAAA,MACd;AAAA,IACD;AAAA,EACD;AACD;;;ALXO,SAAS,iBAAiB;AAAA,EAChC;AAAA,EACA,GAAG;AACJ,IAAqC,CAAC,GAIpC;AACD,QAAM,EAAE,cAAc,IAAI,iBAAiB;AAC3C,QAAM,qBAAqB,eAAe,CAAC,UAAU,MAAM,kBAAkB;AAE7E,aAAO,gCAAY;AAAA,IAClB,aAAa,mBAAmB,cAAc,WAAW;AAAA,IACzD,YAAY,OAAO,EAAE,QAAQ,MAAM;AAClC,UAAI,CAAC,eAAe;AACnB,cAAM,IAAI,wBAAwB,yBAAyB;AAAA,MAC5D;AAEA,YAAM,kBAAkB,cAAc,SAAS;AAAA,QAC9C,CAAC,kBAAkB,cAAc,YAAY,QAAQ;AAAA,MACtD;AACA,UAAI,CAAC,iBAAiB;AACrB,cAAM,IAAI;AAAA,UACT,2BAA2B,QAAQ,2BAA2B,cAAc;AAAA,QAC7E;AAAA,MACD;AAEA,yBAAmB,eAAe;AAAA,IACnC;AAAA,IACA,GAAG;AAAA,EACJ,CAAC;AACF;",
6
6
  "names": ["import_react"]
7
7
  }
@@ -6,11 +6,10 @@ export * from './hooks/networkConfig.js';
6
6
  export * from './hooks/useResolveSuiNSNames.js';
7
7
  export * from './hooks/useSuiClient.js';
8
8
  export * from './hooks/useSuiClientInfiniteQuery.js';
9
- export * from './hooks/useSuiClientInfiniteQuery.js';
10
9
  export * from './hooks/useSuiClientMutation.js';
11
10
  export * from './hooks/useSuiClientQuery.js';
12
11
  export * from './hooks/wallet/useAccounts.js';
13
- export * from './hooks/wallet/useAutoConnectionStatus.js';
12
+ export * from './hooks/wallet/useAutoConnectWallet.js';
14
13
  export * from './hooks/wallet/useConnectWallet.js';
15
14
  export * from './hooks/wallet/useCurrentAccount.js';
16
15
  export * from './hooks/wallet/useCurrentWallet.js';
package/dist/cjs/index.js CHANGED
@@ -71,7 +71,7 @@ __export(src_exports, {
71
71
  createNetworkConfig: () => createNetworkConfig,
72
72
  lightTheme: () => lightTheme,
73
73
  useAccounts: () => useAccounts,
74
- useAutoConnectionStatus: () => useAutoConnectionStatus,
74
+ useAutoConnectWallet: () => useAutoConnectWallet,
75
75
  useConnectWallet: () => useConnectWallet,
76
76
  useCurrentAccount: () => useCurrentAccount,
77
77
  useCurrentWallet: () => useCurrentWallet,
@@ -102,6 +102,7 @@ var import_react_query = require("@tanstack/react-query");
102
102
  var walletMutationKeys = {
103
103
  all: { baseScope: "wallet" },
104
104
  connectWallet: formMutationKeyFn("connect-wallet"),
105
+ autoconnectWallet: formMutationKeyFn("autoconnect-wallet"),
105
106
  disconnectWallet: formMutationKeyFn("disconnect-wallet"),
106
107
  signPersonalMessage: formMutationKeyFn("sign-personal-message"),
107
108
  signTransactionBlock: formMutationKeyFn("sign-transaction-block"),
@@ -915,53 +916,75 @@ function ConnectButton({
915
916
  }
916
917
 
917
918
  // src/components/WalletProvider.tsx
918
- var import_react15 = require("react");
919
+ var import_react14 = require("react");
919
920
 
920
921
  // src/hooks/wallet/useAutoConnectWallet.ts
921
- var import_react11 = require("react");
922
- function useAutoConnectWallet(autoConnectEnabled) {
923
- const { mutate: connectWallet } = useConnectWallet();
924
- const setAutoConnectionStatus = useWalletStore((state) => state.setAutoConnectionStatus);
922
+ var import_react_query5 = require("@tanstack/react-query");
923
+ function useAutoConnectWallet() {
924
+ const { mutateAsync: connectWallet } = useConnectWallet();
925
+ const autoConnectEnabled = useWalletStore((state) => state.autoConnectEnabled);
925
926
  const lastConnectedWalletName = useWalletStore((state) => state.lastConnectedWalletName);
926
927
  const lastConnectedAccountAddress = useWalletStore((state) => state.lastConnectedAccountAddress);
927
928
  const wallets = useWallets();
928
929
  const { isDisconnected } = useCurrentWallet();
929
- (0, import_react11.useEffect)(() => {
930
- if (!autoConnectEnabled || !lastConnectedWalletName || !lastConnectedAccountAddress || !isDisconnected) {
931
- return;
932
- }
933
- const wallet = wallets.find((wallet2) => wallet2.name === lastConnectedWalletName);
934
- if (wallet) {
935
- connectWallet(
936
- {
930
+ const { data, isError } = (0, import_react_query5.useQuery)({
931
+ queryKey: [
932
+ "@mysten/dapp-kit",
933
+ "autoconnect",
934
+ {
935
+ isDisconnected,
936
+ autoConnectEnabled,
937
+ lastConnectedWalletName,
938
+ lastConnectedAccountAddress,
939
+ walletCount: wallets.length
940
+ }
941
+ ],
942
+ queryFn: async () => {
943
+ if (!autoConnectEnabled) {
944
+ return "disabled";
945
+ }
946
+ if (!lastConnectedWalletName || !lastConnectedAccountAddress || !isDisconnected) {
947
+ return "attempted";
948
+ }
949
+ const wallet = wallets.find((wallet2) => wallet2.name === lastConnectedWalletName);
950
+ if (wallet) {
951
+ await connectWallet({
937
952
  wallet,
938
953
  accountAddress: lastConnectedAccountAddress,
939
954
  silent: true
940
- },
941
- {
942
- onSettled: () => setAutoConnectionStatus("settled")
943
- }
944
- );
945
- }
946
- }, [
947
- autoConnectEnabled,
948
- connectWallet,
949
- isDisconnected,
950
- lastConnectedAccountAddress,
951
- lastConnectedWalletName,
952
- setAutoConnectionStatus,
953
- wallets
954
- ]);
955
+ });
956
+ }
957
+ return "attempted";
958
+ },
959
+ enabled: autoConnectEnabled,
960
+ persister: void 0,
961
+ gcTime: 0,
962
+ staleTime: 0,
963
+ retry: false,
964
+ retryOnMount: false,
965
+ refetchInterval: false,
966
+ refetchIntervalInBackground: false,
967
+ refetchOnMount: false,
968
+ refetchOnReconnect: false,
969
+ refetchOnWindowFocus: false
970
+ });
971
+ if (!autoConnectEnabled) {
972
+ return "disabled";
973
+ }
974
+ if (!lastConnectedWalletName) {
975
+ return "attempted";
976
+ }
977
+ return isError ? "attempted" : data ?? "idle";
955
978
  }
956
979
 
957
980
  // src/hooks/wallet/useUnsafeBurnerWallet.ts
958
981
  var import_ed25519 = require("@mysten/sui.js/keypairs/ed25519");
959
982
  var import_wallet_standard = require("@mysten/wallet-standard");
960
- var import_react12 = require("react");
983
+ var import_react11 = require("react");
961
984
  var WALLET_NAME = "Unsafe Burner Wallet";
962
985
  function useUnsafeBurnerWallet(enabled) {
963
986
  const suiClient = useSuiClient();
964
- (0, import_react12.useEffect)(() => {
987
+ (0, import_react11.useEffect)(() => {
965
988
  if (!enabled) {
966
989
  return;
967
990
  }
@@ -1071,11 +1094,11 @@ function registerUnsafeBurnerWallet(suiClient) {
1071
1094
  }
1072
1095
 
1073
1096
  // src/hooks/wallet/useWalletPropertiesChanged.ts
1074
- var import_react13 = require("react");
1097
+ var import_react12 = require("react");
1075
1098
  function useWalletPropertiesChanged() {
1076
1099
  const { currentWallet } = useCurrentWallet();
1077
1100
  const updateWalletAccounts = useWalletStore((state) => state.updateWalletAccounts);
1078
- (0, import_react13.useEffect)(() => {
1101
+ (0, import_react12.useEffect)(() => {
1079
1102
  const unsubscribeFromEvents = currentWallet?.features["standard:events"].on(
1080
1103
  "change",
1081
1104
  ({ accounts }) => {
@@ -1090,7 +1113,7 @@ function useWalletPropertiesChanged() {
1090
1113
 
1091
1114
  // src/hooks/wallet/useWalletsChanged.ts
1092
1115
  var import_wallet_standard3 = require("@mysten/wallet-standard");
1093
- var import_react14 = require("react");
1116
+ var import_react13 = require("react");
1094
1117
 
1095
1118
  // src/utils/walletUtils.ts
1096
1119
  var import_wallet_standard2 = require("@mysten/wallet-standard");
@@ -1112,7 +1135,7 @@ function getRegisteredWallets(preferredWallets, requiredFeatures) {
1112
1135
  function useWalletsChanged(preferredWallets, requiredFeatures) {
1113
1136
  const setWalletRegistered = useWalletStore((state) => state.setWalletRegistered);
1114
1137
  const setWalletUnregistered = useWalletStore((state) => state.setWalletUnregistered);
1115
- (0, import_react14.useEffect)(() => {
1138
+ (0, import_react13.useEffect)(() => {
1116
1139
  const walletsApi = (0, import_wallet_standard3.getWallets)();
1117
1140
  const unsubscribeFromRegister = walletsApi.on("register", () => {
1118
1141
  setWalletRegistered(getRegisteredWallets(preferredWallets, requiredFeatures));
@@ -1196,11 +1219,12 @@ function createWalletStore({
1196
1219
  wallets,
1197
1220
  storage,
1198
1221
  storageKey,
1199
- autoConnect
1222
+ autoConnectEnabled
1200
1223
  }) {
1201
1224
  return (0, import_zustand2.createStore)()(
1202
1225
  (0, import_middleware.persist)(
1203
1226
  (set, get) => ({
1227
+ autoConnectEnabled,
1204
1228
  wallets,
1205
1229
  accounts: [],
1206
1230
  currentWallet: null,
@@ -1208,17 +1232,11 @@ function createWalletStore({
1208
1232
  lastConnectedAccountAddress: null,
1209
1233
  lastConnectedWalletName: null,
1210
1234
  connectionStatus: "disconnected",
1211
- autoConnectionStatus: autoConnect ? "idle" : "disabled",
1212
1235
  setConnectionStatus(connectionStatus2) {
1213
1236
  set(() => ({
1214
1237
  connectionStatus: connectionStatus2
1215
1238
  }));
1216
1239
  },
1217
- setAutoConnectionStatus(autoConnectionStatus) {
1218
- set(() => ({
1219
- autoConnectionStatus
1220
- }));
1221
- },
1222
1240
  setWalletConnected(wallet, connectedAccounts, selectedAccount) {
1223
1241
  set(() => ({
1224
1242
  accounts: connectedAccounts,
@@ -1394,12 +1412,12 @@ function WalletProvider({
1394
1412
  theme = lightTheme,
1395
1413
  children
1396
1414
  }) {
1397
- const storeRef = (0, import_react15.useRef)(
1415
+ const storeRef = (0, import_react14.useRef)(
1398
1416
  createWalletStore({
1417
+ autoConnectEnabled: autoConnect,
1399
1418
  wallets: getRegisteredWallets(preferredWallets, requiredFeatures),
1400
1419
  storageKey,
1401
- storage,
1402
- autoConnect
1420
+ storage
1403
1421
  })
1404
1422
  );
1405
1423
  return /* @__PURE__ */ (0, import_jsx_runtime22.jsx)(WalletContext.Provider, { value: storeRef.current, children: /* @__PURE__ */ (0, import_jsx_runtime22.jsxs)(
@@ -1408,7 +1426,6 @@ function WalletProvider({
1408
1426
  preferredWallets,
1409
1427
  requiredFeatures,
1410
1428
  enableUnsafeBurner,
1411
- autoConnect,
1412
1429
  children: [
1413
1430
  theme ? /* @__PURE__ */ (0, import_jsx_runtime22.jsx)(InjectedThemeStyles, { theme }) : null,
1414
1431
  children
@@ -1420,13 +1437,12 @@ function WalletConnectionManager({
1420
1437
  preferredWallets,
1421
1438
  requiredFeatures,
1422
1439
  enableUnsafeBurner,
1423
- autoConnect,
1424
1440
  children
1425
1441
  }) {
1426
1442
  useWalletsChanged(preferredWallets, requiredFeatures);
1427
1443
  useWalletPropertiesChanged();
1428
1444
  useUnsafeBurnerWallet(enableUnsafeBurner);
1429
- useAutoConnectWallet(autoConnect);
1445
+ useAutoConnectWallet();
1430
1446
  return children;
1431
1447
  }
1432
1448
 
@@ -1456,14 +1472,14 @@ function createNetworkConfig(networkConfig) {
1456
1472
  }
1457
1473
 
1458
1474
  // src/hooks/useSuiClientInfiniteQuery.ts
1459
- var import_react_query5 = require("@tanstack/react-query");
1475
+ var import_react_query6 = require("@tanstack/react-query");
1460
1476
  function useSuiClientInfiniteQuery(method, params, {
1461
1477
  queryKey = [],
1462
1478
  enabled = !!params,
1463
1479
  ...options
1464
1480
  } = {}) {
1465
1481
  const suiContext = useSuiClientContext();
1466
- return (0, import_react_query5.useInfiniteQuery)({
1482
+ return (0, import_react_query6.useInfiniteQuery)({
1467
1483
  ...options,
1468
1484
  initialPageParam: null,
1469
1485
  queryKey: [suiContext.network, method, params, ...queryKey],
@@ -1477,10 +1493,10 @@ function useSuiClientInfiniteQuery(method, params, {
1477
1493
  }
1478
1494
 
1479
1495
  // src/hooks/useSuiClientMutation.ts
1480
- var import_react_query6 = require("@tanstack/react-query");
1496
+ var import_react_query7 = require("@tanstack/react-query");
1481
1497
  function useSuiClientMutation(method, options = {}) {
1482
1498
  const suiContext = useSuiClientContext();
1483
- return (0, import_react_query6.useMutation)({
1499
+ return (0, import_react_query7.useMutation)({
1484
1500
  ...options,
1485
1501
  mutationFn: async (params) => {
1486
1502
  return await suiContext.client[method](params);
@@ -1488,13 +1504,8 @@ function useSuiClientMutation(method, options = {}) {
1488
1504
  });
1489
1505
  }
1490
1506
 
1491
- // src/hooks/wallet/useAutoConnectionStatus.ts
1492
- function useAutoConnectionStatus() {
1493
- return useWalletStore((state) => state.autoConnectionStatus);
1494
- }
1495
-
1496
1507
  // src/hooks/wallet/useSignAndExecuteTransactionBlock.ts
1497
- var import_react_query7 = require("@tanstack/react-query");
1508
+ var import_react_query8 = require("@tanstack/react-query");
1498
1509
  function useSignAndExecuteTransactionBlock({
1499
1510
  mutationKey,
1500
1511
  executeFromWallet,
@@ -1503,7 +1514,7 @@ function useSignAndExecuteTransactionBlock({
1503
1514
  const { currentWallet } = useCurrentWallet();
1504
1515
  const currentAccount = useCurrentAccount();
1505
1516
  const client = useSuiClient();
1506
- return (0, import_react_query7.useMutation)({
1517
+ return (0, import_react_query8.useMutation)({
1507
1518
  mutationKey: walletMutationKeys.signAndExecuteTransactionBlock(mutationKey),
1508
1519
  mutationFn: async ({ requestType, options, ...signTransactionBlockArgs }) => {
1509
1520
  if (!currentWallet) {
@@ -1553,14 +1564,14 @@ function useSignAndExecuteTransactionBlock({
1553
1564
  }
1554
1565
 
1555
1566
  // src/hooks/wallet/useSignPersonalMessage.ts
1556
- var import_react_query8 = require("@tanstack/react-query");
1567
+ var import_react_query9 = require("@tanstack/react-query");
1557
1568
  function useSignPersonalMessage({
1558
1569
  mutationKey,
1559
1570
  ...mutationOptions
1560
1571
  } = {}) {
1561
1572
  const { currentWallet } = useCurrentWallet();
1562
1573
  const currentAccount = useCurrentAccount();
1563
- return (0, import_react_query8.useMutation)({
1574
+ return (0, import_react_query9.useMutation)({
1564
1575
  mutationKey: walletMutationKeys.signPersonalMessage(mutationKey),
1565
1576
  mutationFn: async (signPersonalMessageArgs) => {
1566
1577
  if (!currentWallet) {
@@ -1599,14 +1610,14 @@ function useSignPersonalMessage({
1599
1610
  }
1600
1611
 
1601
1612
  // src/hooks/wallet/useSignTransactionBlock.ts
1602
- var import_react_query9 = require("@tanstack/react-query");
1613
+ var import_react_query10 = require("@tanstack/react-query");
1603
1614
  function useSignTransactionBlock({
1604
1615
  mutationKey,
1605
1616
  ...mutationOptions
1606
1617
  } = {}) {
1607
1618
  const { currentWallet } = useCurrentWallet();
1608
1619
  const currentAccount = useCurrentAccount();
1609
- return (0, import_react_query9.useMutation)({
1620
+ return (0, import_react_query10.useMutation)({
1610
1621
  mutationKey: walletMutationKeys.signTransactionBlock(mutationKey),
1611
1622
  mutationFn: async (signTransactionBlockArgs) => {
1612
1623
  if (!currentWallet) {