@iota/dapp-kit 0.5.3 → 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +52 -0
- package/dist/cjs/components/AccountDropdownMenu.d.ts +4 -2
- package/dist/cjs/components/AccountDropdownMenu.js +81 -15
- package/dist/cjs/components/AccountDropdownMenu.js.map +4 -4
- package/dist/cjs/components/ConnectButton.d.ts +6 -1
- package/dist/cjs/components/ConnectButton.js +177 -91
- package/dist/cjs/components/ConnectButton.js.map +4 -4
- package/dist/cjs/components/WalletProvider.d.ts +3 -1
- package/dist/cjs/components/WalletProvider.js +9 -3
- package/dist/cjs/components/WalletProvider.js.map +2 -2
- package/dist/cjs/components/connect-modal/ConnectModal.d.ts +5 -1
- package/dist/cjs/components/connect-modal/ConnectModal.js +12 -2
- package/dist/cjs/components/connect-modal/ConnectModal.js.map +2 -2
- package/dist/cjs/hooks/useGetDefaultIotaName.d.ts +1 -0
- package/dist/cjs/hooks/useGetDefaultIotaName.js +80 -0
- package/dist/cjs/hooks/useGetDefaultIotaName.js.map +7 -0
- package/dist/cjs/hooks/wallet/useAutoConnectWallet.js +2 -0
- package/dist/cjs/hooks/wallet/useAutoConnectWallet.js.map +2 -2
- package/dist/cjs/hooks/wallet/useConnectWallet.d.ts +6 -2
- package/dist/cjs/hooks/wallet/useConnectWallet.js +2 -0
- package/dist/cjs/hooks/wallet/useConnectWallet.js.map +2 -2
- package/dist/cjs/hooks/wallet/useCurrentChain.d.ts +5 -0
- package/dist/cjs/hooks/wallet/useCurrentChain.js +50 -0
- package/dist/cjs/hooks/wallet/useCurrentChain.js.map +7 -0
- package/dist/cjs/hooks/wallet/useSignAndExecuteTransaction.js +8 -2
- package/dist/cjs/hooks/wallet/useSignAndExecuteTransaction.js.map +3 -3
- package/dist/cjs/index.js +193 -120
- package/dist/cjs/index.js.map +4 -4
- package/dist/cjs/walletStore.d.ts +4 -1
- package/dist/cjs/walletStore.js +3 -1
- package/dist/cjs/walletStore.js.map +2 -2
- package/dist/esm/components/AccountDropdownMenu.d.ts +4 -2
- package/dist/esm/components/AccountDropdownMenu.js +79 -13
- package/dist/esm/components/AccountDropdownMenu.js.map +4 -4
- package/dist/esm/components/ConnectButton.d.ts +6 -1
- package/dist/esm/components/ConnectButton.js +159 -73
- package/dist/esm/components/ConnectButton.js.map +4 -4
- package/dist/esm/components/WalletProvider.d.ts +3 -1
- package/dist/esm/components/WalletProvider.js +9 -3
- package/dist/esm/components/WalletProvider.js.map +2 -2
- package/dist/esm/components/connect-modal/ConnectModal.d.ts +5 -1
- package/dist/esm/components/connect-modal/ConnectModal.js +12 -2
- package/dist/esm/components/connect-modal/ConnectModal.js.map +2 -2
- package/dist/esm/hooks/useGetDefaultIotaName.d.ts +1 -0
- package/dist/esm/hooks/useGetDefaultIotaName.js +59 -0
- package/dist/esm/hooks/useGetDefaultIotaName.js.map +7 -0
- package/dist/esm/hooks/wallet/useAutoConnectWallet.js +2 -0
- package/dist/esm/hooks/wallet/useAutoConnectWallet.js.map +2 -2
- package/dist/esm/hooks/wallet/useConnectWallet.d.ts +6 -2
- package/dist/esm/hooks/wallet/useConnectWallet.js +2 -0
- package/dist/esm/hooks/wallet/useConnectWallet.js.map +2 -2
- package/dist/esm/hooks/wallet/useCurrentChain.d.ts +5 -0
- package/dist/esm/hooks/wallet/useCurrentChain.js +27 -0
- package/dist/esm/hooks/wallet/useCurrentChain.js.map +7 -0
- package/dist/esm/hooks/wallet/useSignAndExecuteTransaction.js +8 -2
- package/dist/esm/hooks/wallet/useSignAndExecuteTransaction.js.map +3 -3
- package/dist/esm/index.js +164 -91
- package/dist/esm/index.js.map +4 -4
- package/dist/esm/walletStore.d.ts +4 -1
- package/dist/esm/walletStore.js +3 -1
- package/dist/esm/walletStore.js.map +2 -2
- package/dist/tsconfig.esm.tsbuildinfo +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +5 -3
- package/src/components/AccountDropdownMenu.tsx +17 -3
- package/src/components/ConnectButton.tsx +11 -1
- package/src/components/WalletProvider.tsx +5 -0
- package/src/components/connect-modal/ConnectModal.tsx +12 -2
- package/src/hooks/useGetDefaultIotaName.ts +43 -0
- package/src/hooks/wallet/useConnectWallet.ts +6 -1
- package/src/hooks/wallet/useCurrentChain.ts +12 -0
- package/src/hooks/wallet/useSignAndExecuteTransaction.ts +5 -2
- package/src/walletStore.ts +5 -0
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
// src/hooks/wallet/useWalletStore.ts
|
|
2
|
+
import { useContext } from "react";
|
|
3
|
+
import { useStore } from "zustand";
|
|
4
|
+
|
|
5
|
+
// src/contexts/walletContext.ts
|
|
6
|
+
import { createContext } from "react";
|
|
7
|
+
var WalletContext = createContext(null);
|
|
8
|
+
|
|
9
|
+
// src/hooks/wallet/useWalletStore.ts
|
|
10
|
+
function useWalletStore(selector) {
|
|
11
|
+
const store = useContext(WalletContext);
|
|
12
|
+
if (!store) {
|
|
13
|
+
throw new Error(
|
|
14
|
+
"Could not find WalletContext. Ensure that you have set up the WalletProvider."
|
|
15
|
+
);
|
|
16
|
+
}
|
|
17
|
+
return useStore(store, selector);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
// src/hooks/wallet/useCurrentChain.ts
|
|
21
|
+
function useCurrentChain() {
|
|
22
|
+
return useWalletStore((state) => state.chain);
|
|
23
|
+
}
|
|
24
|
+
export {
|
|
25
|
+
useCurrentChain
|
|
26
|
+
};
|
|
27
|
+
//# sourceMappingURL=useCurrentChain.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../src/hooks/wallet/useWalletStore.ts", "../../../../src/contexts/walletContext.ts", "../../../../src/hooks/wallet/useCurrentChain.ts"],
|
|
4
|
+
"sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// Modifications Copyright (c) 2024 IOTA Stiftung\n// SPDX-License-Identifier: Apache-2.0\n\nimport { useContext } from 'react';\nimport { useStore } from 'zustand';\n\nimport { WalletContext } from '../../contexts/walletContext.js';\nimport type { StoreState } from '../../walletStore.js';\n\nexport function useWalletStore<T>(selector: (state: StoreState) => T): T {\n const store = useContext(WalletContext);\n if (!store) {\n throw new Error(\n 'Could not find WalletContext. Ensure that you have set up the WalletProvider.',\n );\n }\n return useStore(store, selector);\n}\n", "// Copyright (c) Mysten Labs, Inc.\n// Modifications Copyright (c) 2024 IOTA Stiftung\n// SPDX-License-Identifier: Apache-2.0\n\nimport { createContext } from 'react';\n\nimport type { WalletStore } from '../walletStore.js';\n\nexport const WalletContext = createContext<WalletStore | null>(null);\n", "// Copyright (c) 2025 IOTA Stiftung\n// SPDX-License-Identifier: Apache-2.0\n\nimport type { ChainType } from '@iota/iota-sdk/client';\nimport { useWalletStore } from './useWalletStore.js';\n\n/**\n * Retrieves the chain the dapp is configured with, if any.\n */\nexport function useCurrentChain(): ChainType | undefined {\n return useWalletStore((state) => state.chain);\n}\n"],
|
|
5
|
+
"mappings": ";AAIA,SAAS,kBAAkB;AAC3B,SAAS,gBAAgB;;;ACDzB,SAAS,qBAAqB;AAIvB,IAAM,gBAAgB,cAAkC,IAAI;;;ADE5D,SAAS,eAAkB,UAAuC;AACrE,QAAM,QAAQ,WAAW,aAAa;AACtC,MAAI,CAAC,OAAO;AACR,UAAM,IAAI;AAAA,MACN;AAAA,IACJ;AAAA,EACJ;AACA,SAAO,SAAS,OAAO,QAAQ;AACnC;;;AETO,SAAS,kBAAyC;AACrD,SAAO,eAAe,CAAC,UAAU,MAAM,KAAK;AAChD;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -153,12 +153,18 @@ function useReportTransactionEffects({
|
|
|
153
153
|
});
|
|
154
154
|
}
|
|
155
155
|
|
|
156
|
+
// src/hooks/wallet/useCurrentChain.ts
|
|
157
|
+
function useCurrentChain() {
|
|
158
|
+
return useWalletStore((state) => state.chain);
|
|
159
|
+
}
|
|
160
|
+
|
|
156
161
|
// src/hooks/wallet/useSignAndExecuteTransaction.ts
|
|
157
162
|
function useSignAndExecuteTransaction({
|
|
158
163
|
mutationKey,
|
|
159
164
|
execute,
|
|
160
165
|
...mutationOptions
|
|
161
166
|
} = {}) {
|
|
167
|
+
const currentChain = useCurrentChain();
|
|
162
168
|
const { currentWallet, supportedIntents } = useCurrentWallet();
|
|
163
169
|
const currentAccount = useCurrentAccount();
|
|
164
170
|
const client = useIotaClient();
|
|
@@ -191,12 +197,12 @@ function useSignAndExecuteTransaction({
|
|
|
191
197
|
"No wallet account is selected to sign the transaction with."
|
|
192
198
|
);
|
|
193
199
|
}
|
|
194
|
-
const chain = signTransactionArgs.chain ?? signerAccount?.chains[0];
|
|
195
200
|
if (!currentWallet.features["iota:signTransaction"]) {
|
|
196
201
|
throw new WalletFeatureNotSupportedError(
|
|
197
202
|
"This wallet doesn't support the `signTransaction` feature."
|
|
198
203
|
);
|
|
199
204
|
}
|
|
205
|
+
const chain = signTransactionArgs.chain ?? currentChain ?? signerAccount?.chains[0];
|
|
200
206
|
const { signature, bytes } = await signTransaction(currentWallet, {
|
|
201
207
|
...signTransactionArgs,
|
|
202
208
|
transaction: {
|
|
@@ -208,7 +214,7 @@ function useSignAndExecuteTransaction({
|
|
|
208
214
|
}
|
|
209
215
|
},
|
|
210
216
|
account: signerAccount,
|
|
211
|
-
chain
|
|
217
|
+
chain
|
|
212
218
|
});
|
|
213
219
|
const result = await executeTransaction({ bytes, signature });
|
|
214
220
|
let effects;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["../../../../src/hooks/wallet/useSignAndExecuteTransaction.ts", "../../../../src/constants/walletMutationKeys.ts", "../../../../src/errors/walletErrors.ts", "../../../../src/hooks/useIotaClient.ts", "../../../../src/components/IotaClientProvider.tsx", "../../../../src/hooks/wallet/useWalletStore.ts", "../../../../src/contexts/walletContext.ts", "../../../../src/hooks/wallet/useCurrentAccount.ts", "../../../../src/hooks/wallet/useCurrentWallet.ts", "../../../../src/hooks/wallet/useReportTransactionEffects.ts"],
|
|
4
|
-
"sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// Modifications Copyright (c) 2024 IOTA Stiftung\n// SPDX-License-Identifier: Apache-2.0\n\nimport type { Transaction } from '@iota/iota-sdk/transactions';\nimport { toBase64 } from '@iota/iota-sdk/utils';\nimport type {\n IotaSignAndExecuteTransactionInput,\n IotaSignAndExecuteTransactionOutput,\n} from '@iota/wallet-standard';\nimport { signTransaction } from '@iota/wallet-standard';\nimport type { UseMutationOptions, UseMutationResult } from '@tanstack/react-query';\nimport { useMutation } from '@tanstack/react-query';\n\nimport { walletMutationKeys } from '../../constants/walletMutationKeys.js';\nimport {\n WalletFeatureNotSupportedError,\n WalletNoAccountSelectedError,\n WalletNotConnectedError,\n} from '../../errors/walletErrors.js';\nimport type { PartialBy } from '../../types/utilityTypes.js';\nimport { useIotaClient } from '../useIotaClient.js';\nimport { useCurrentAccount } from './useCurrentAccount.js';\nimport { useCurrentWallet } from './useCurrentWallet.js';\nimport { useReportTransactionEffects } from './useReportTransactionEffects.js';\n\ntype UseSignAndExecuteTransactionArgs = PartialBy<\n Omit<IotaSignAndExecuteTransactionInput, 'transaction'>,\n 'account' | 'chain'\n> & {\n transaction: Transaction | string;\n waitForTransaction?: boolean;\n};\n\ntype UseSignAndExecuteTransactionResult = IotaSignAndExecuteTransactionOutput;\n\ntype UseSignAndExecuteTransactionError =\n | WalletFeatureNotSupportedError\n | WalletNoAccountSelectedError\n | WalletNotConnectedError\n | Error;\n\ntype ExecuteTransactionResult =\n | {\n digest: string;\n rawEffects?: number[];\n }\n | {\n effects?: {\n bcs?: string;\n };\n };\n\ntype UseSignAndExecuteTransactionMutationOptions<Result extends ExecuteTransactionResult> = Omit<\n UseMutationOptions<\n Result,\n UseSignAndExecuteTransactionError,\n UseSignAndExecuteTransactionArgs,\n unknown\n >,\n 'mutationFn'\n> & {\n execute?: ({ bytes, signature }: { bytes: string; signature: string }) => Promise<Result>;\n};\n\n/**\n * Mutation hook for prompting the user to sign and execute a transaction.\n */\nexport function useSignAndExecuteTransaction<\n Result extends ExecuteTransactionResult = UseSignAndExecuteTransactionResult,\n>({\n mutationKey,\n execute,\n ...mutationOptions\n}: UseSignAndExecuteTransactionMutationOptions<Result> = {}): UseMutationResult<\n Result,\n UseSignAndExecuteTransactionError,\n UseSignAndExecuteTransactionArgs\n> {\n const { currentWallet, supportedIntents } = useCurrentWallet();\n const currentAccount = useCurrentAccount();\n const client = useIotaClient();\n const { mutate: reportTransactionEffects } = useReportTransactionEffects();\n\n const executeTransaction: ({\n bytes,\n signature,\n }: {\n bytes: string;\n signature: string;\n }) => Promise<ExecuteTransactionResult> =\n execute ??\n (async ({ bytes, signature }) => {\n const { digest, rawEffects } = await client.executeTransactionBlock({\n transactionBlock: bytes,\n signature,\n options: {\n showRawEffects: true,\n },\n });\n\n return {\n digest,\n rawEffects,\n effects: toBase64(new Uint8Array(rawEffects!)),\n bytes,\n signature,\n };\n });\n\n return useMutation({\n mutationKey: walletMutationKeys.signAndExecuteTransaction(mutationKey),\n mutationFn: async ({ transaction, ...signTransactionArgs }): Promise<Result> => {\n if (!currentWallet) {\n throw new WalletNotConnectedError('No wallet is connected.');\n }\n\n const signerAccount = signTransactionArgs.account ?? currentAccount;\n if (!signerAccount) {\n throw new WalletNoAccountSelectedError(\n 'No wallet account is selected to sign the transaction with.',\n );\n }\n const chain = signTransactionArgs.chain ?? signerAccount?.chains[0];\n\n if (!currentWallet.features['iota:signTransaction']) {\n throw new WalletFeatureNotSupportedError(\n \"This wallet doesn't support the `signTransaction` feature.\",\n );\n }\n\n const { signature, bytes } = await signTransaction(currentWallet, {\n ...signTransactionArgs,\n transaction: {\n async toJSON() {\n return typeof transaction === 'string'\n ? transaction\n : await transaction.toJSON({\n supportedIntents,\n client,\n });\n },\n },\n account: signerAccount,\n chain: signTransactionArgs.chain ?? signerAccount.chains[0],\n });\n\n const result = await executeTransaction({ bytes, signature });\n\n let effects: string;\n\n if ('effects' in result && result.effects?.bcs) {\n effects = result.effects.bcs;\n } else if ('rawEffects' in result) {\n effects = toBase64(new Uint8Array(result.rawEffects!));\n } else {\n throw new Error('Could not parse effects from transaction result.');\n }\n\n reportTransactionEffects({ effects, account: signerAccount, chain });\n\n if (signTransactionArgs.waitForTransaction && 'digest' in result) {\n await client.waitForTransaction({\n digest: result.digest,\n });\n }\n\n return result as Result;\n },\n ...mutationOptions,\n });\n}\n", "// Copyright (c) Mysten Labs, Inc.\n// Modifications Copyright (c) 2024 IOTA Stiftung\n// SPDX-License-Identifier: Apache-2.0\n\nimport type { MutationKey } from '@tanstack/react-query';\n\nexport const walletMutationKeys = {\n all: { baseScope: 'wallet' },\n connectWallet: formMutationKeyFn('connect-wallet'),\n autoconnectWallet: formMutationKeyFn('autoconnect-wallet'),\n disconnectWallet: formMutationKeyFn('disconnect-wallet'),\n signPersonalMessage: formMutationKeyFn('sign-personal-message'),\n signTransaction: formMutationKeyFn('sign-transaction'),\n signAndExecuteTransaction: formMutationKeyFn('sign-and-execute-transaction'),\n switchAccount: formMutationKeyFn('switch-account'),\n reportTransactionEffects: formMutationKeyFn('report-transaction-effects'),\n};\n\nfunction formMutationKeyFn(baseEntity: string) {\n return function mutationKeyFn(additionalKeys: MutationKey = []) {\n return [{ ...walletMutationKeys.all, baseEntity }, ...additionalKeys];\n };\n}\n", "// Copyright (c) Mysten Labs, Inc.\n// Modifications Copyright (c) 2024 IOTA Stiftung\n// SPDX-License-Identifier: Apache-2.0\n\n/**\n * An error that is instantiated when someone attempts to perform an action that requires an active wallet connection.\n */\nexport class WalletNotConnectedError extends Error {}\n\n/**\n * An error that is instantiated when someone attempts to perform an action that requires a selected wallet account.\n * This is more of an edge case stemming from the fact that wallets don't technically require you to authorize any\n * accounts when connecting a wallet.\n */\nexport class WalletNoAccountSelectedError extends Error {}\n\n/**\n * An error that is instantiated when someone attempts to perform an action that isn't supported by a wallet.\n */\nexport class WalletFeatureNotSupportedError extends Error {}\n\n/**\n * An error that is instantiated when a wallet account can't be found for a specific wallet.\n */\nexport class WalletAccountNotFoundError extends Error {}\n", "// Copyright (c) Mysten Labs, Inc.\n// Modifications Copyright (c) 2024 IOTA Stiftung\n// SPDX-License-Identifier: Apache-2.0\n\nimport type { IotaClient } from '@iota/iota-sdk/client';\nimport { useContext } from 'react';\n\nimport { IotaClientContext } from '../components/IotaClientProvider.js';\n\nexport function useIotaClientContext() {\n const iotaClient = useContext(IotaClientContext);\n\n if (!iotaClient) {\n throw new Error(\n 'Could not find IotaClientContext. Ensure that you have set up the IotaClientProvider',\n );\n }\n\n return iotaClient;\n}\n\nexport function useIotaClient(): IotaClient {\n return useIotaClientContext().client;\n}\n", "// Copyright (c) Mysten Labs, Inc.\n// Modifications Copyright (c) 2024 IOTA Stiftung\n// SPDX-License-Identifier: Apache-2.0\n\nimport { getNetwork, isIotaClient, Network, IotaClient } from '@iota/iota-sdk/client';\nimport type { IotaClientOptions } from '@iota/iota-sdk/client';\nimport { createContext, useMemo, useState } from 'react';\n\nimport type { NetworkConfig } from '../hooks/networkConfig.js';\n\ntype NetworkConfigs<T extends NetworkConfig | IotaClient = NetworkConfig | IotaClient> = Record<\n string,\n T\n>;\n\nexport interface IotaClientProviderContext {\n client: IotaClient;\n networks: NetworkConfigs;\n network: string;\n config: NetworkConfig | null;\n selectNetwork: (network: string) => void;\n}\n\nexport const IotaClientContext = createContext<IotaClientProviderContext | null>(null);\n\nexport type IotaClientProviderProps<T extends NetworkConfigs> = {\n createClient?: (name: keyof T, config: T[keyof T]) => IotaClient;\n children: React.ReactNode;\n networks?: T;\n onNetworkChange?: (network: keyof T & string) => void;\n} & (\n | {\n defaultNetwork?: keyof T & string;\n network?: never;\n }\n | {\n defaultNetwork?: never;\n network?: keyof T & string;\n }\n);\n\nconst DEFAULT_NETWORKS = {\n localnet: { url: getNetwork(Network.Localnet)?.url },\n};\n\nconst DEFAULT_CREATE_CLIENT = function createClient(\n _name: string,\n config: NetworkConfig | IotaClient,\n) {\n if (isIotaClient(config)) {\n return config;\n }\n\n return new IotaClient(config);\n};\n\nexport function IotaClientProvider<T extends NetworkConfigs>(props: IotaClientProviderProps<T>) {\n const { onNetworkChange, network, children } = props;\n const networks = (props.networks ?? DEFAULT_NETWORKS) as T;\n const createClient =\n (props.createClient as typeof DEFAULT_CREATE_CLIENT) ?? DEFAULT_CREATE_CLIENT;\n\n const [selectedNetwork, setSelectedNetwork] = useState<keyof T & string>(\n props.network ?? props.defaultNetwork ?? (Object.keys(networks)[0] as keyof T & string),\n );\n\n const currentNetwork = props.network ?? selectedNetwork;\n\n const client = useMemo(() => {\n return createClient(currentNetwork, networks[currentNetwork]);\n }, [createClient, currentNetwork, networks]);\n\n const ctx = useMemo((): IotaClientProviderContext => {\n return {\n client,\n networks,\n network: currentNetwork,\n config:\n networks[currentNetwork] instanceof IotaClient\n ? null\n : (networks[currentNetwork] as IotaClientOptions),\n selectNetwork: (newNetwork) => {\n if (currentNetwork === newNetwork) {\n return;\n }\n\n if (!network && newNetwork !== selectedNetwork) {\n setSelectedNetwork(newNetwork);\n }\n\n onNetworkChange?.(newNetwork);\n },\n };\n }, [client, networks, selectedNetwork, currentNetwork, network, onNetworkChange]);\n\n return <IotaClientContext.Provider value={ctx}>{children}</IotaClientContext.Provider>;\n}\n", "// Copyright (c) Mysten Labs, Inc.\n// Modifications Copyright (c) 2024 IOTA Stiftung\n// SPDX-License-Identifier: Apache-2.0\n\nimport { useContext } from 'react';\nimport { useStore } from 'zustand';\n\nimport { WalletContext } from '../../contexts/walletContext.js';\nimport type { StoreState } from '../../walletStore.js';\n\nexport function useWalletStore<T>(selector: (state: StoreState) => T): T {\n const store = useContext(WalletContext);\n if (!store) {\n throw new Error(\n 'Could not find WalletContext. Ensure that you have set up the WalletProvider.',\n );\n }\n return useStore(store, selector);\n}\n", "// Copyright (c) Mysten Labs, Inc.\n// Modifications Copyright (c) 2024 IOTA Stiftung\n// SPDX-License-Identifier: Apache-2.0\n\nimport { createContext } from 'react';\n\nimport type { WalletStore } from '../walletStore.js';\n\nexport const WalletContext = createContext<WalletStore | null>(null);\n", "// Copyright (c) Mysten Labs, Inc.\n// Modifications Copyright (c) 2024 IOTA Stiftung\n// SPDX-License-Identifier: Apache-2.0\n\nimport type { WalletAccount } from '@iota/wallet-standard';\n\nimport { useWalletStore } from './useWalletStore.js';\n\n/**\n * Retrieves the wallet account that is currently selected, if one exists.\n */\nexport function useCurrentAccount(): WalletAccount | null {\n return useWalletStore((state) => state.currentAccount);\n}\n", "// Copyright (c) Mysten Labs, Inc.\n// Modifications Copyright (c) 2024 IOTA Stiftung\n// SPDX-License-Identifier: Apache-2.0\n\nimport { useWalletStore } from './useWalletStore.js';\n\n/**\n * Retrieves the wallet that is currently connected to the dApp, if one exists.\n */\nexport function useCurrentWallet() {\n const currentWallet = useWalletStore((state) => state.currentWallet);\n const connectionStatus = useWalletStore((state) => state.connectionStatus);\n const supportedIntents = useWalletStore((state) => state.supportedIntents);\n\n switch (connectionStatus) {\n case 'connecting':\n return {\n connectionStatus,\n currentWallet: null,\n isDisconnected: false,\n isConnecting: true,\n isConnected: false,\n supportedIntents: [],\n } as const;\n case 'disconnected':\n return {\n connectionStatus,\n currentWallet: null,\n isDisconnected: true,\n isConnecting: false,\n isConnected: false,\n supportedIntents: [],\n } as const;\n case 'connected': {\n return {\n connectionStatus,\n currentWallet: currentWallet!,\n isDisconnected: false,\n isConnecting: false,\n isConnected: true,\n supportedIntents,\n } as const;\n }\n }\n}\n", "// Copyright (c) Mysten Labs, Inc.\n// Modifications Copyright (c) 2024 IOTA Stiftung\n// SPDX-License-Identifier: Apache-2.0\n\nimport { toBase64 } from '@iota/iota-sdk/utils';\nimport type { IotaReportTransactionEffectsInput } from '@iota/wallet-standard';\nimport type { UseMutationOptions, UseMutationResult } from '@tanstack/react-query';\nimport { useMutation } from '@tanstack/react-query';\n\nimport { walletMutationKeys } from '../../constants/walletMutationKeys.js';\nimport type { WalletFeatureNotSupportedError } from '../../errors/walletErrors.js';\nimport {\n WalletNoAccountSelectedError,\n WalletNotConnectedError,\n} from '../../errors/walletErrors.js';\nimport type { PartialBy } from '../../types/utilityTypes.js';\nimport { useCurrentAccount } from './useCurrentAccount.js';\nimport { useCurrentWallet } from './useCurrentWallet.js';\n\ntype UseReportTransactionEffectsArgs = Omit<\n PartialBy<IotaReportTransactionEffectsInput, 'account' | 'chain'>,\n 'effects'\n> & {\n effects: string | number[];\n};\n\ntype UseReportTransactionEffectsError =\n | WalletFeatureNotSupportedError\n | WalletNoAccountSelectedError\n | WalletNotConnectedError\n | Error;\n\ntype UseReportTransactionEffectsMutationOptions = Omit<\n UseMutationOptions<\n void,\n UseReportTransactionEffectsError,\n UseReportTransactionEffectsArgs,\n unknown\n >,\n 'mutationFn'\n>;\n\n/**\n * Mutation hook for prompting the user to sign a message.\n */\nexport function useReportTransactionEffects({\n mutationKey,\n ...mutationOptions\n}: UseReportTransactionEffectsMutationOptions = {}): UseMutationResult<\n void,\n UseReportTransactionEffectsError,\n UseReportTransactionEffectsArgs\n> {\n const { currentWallet } = useCurrentWallet();\n const currentAccount = useCurrentAccount();\n\n return useMutation({\n mutationKey: walletMutationKeys.reportTransactionEffects(mutationKey),\n mutationFn: async ({\n effects,\n chain = currentWallet?.chains[0],\n account = currentAccount,\n }) => {\n if (!currentWallet) {\n throw new WalletNotConnectedError('No wallet is connected.');\n }\n\n if (!account) {\n throw new WalletNoAccountSelectedError(\n 'No wallet account is selected to report transaction effects for',\n );\n }\n\n const reportTransactionEffectsFeature =\n currentWallet.features['iota:reportTransactionEffects'];\n\n if (reportTransactionEffectsFeature) {\n return await reportTransactionEffectsFeature.reportTransactionEffects({\n effects: Array.isArray(effects) ? toBase64(new Uint8Array(effects)) : effects,\n account,\n chain: chain ?? currentWallet?.chains[0],\n });\n }\n },\n ...mutationOptions,\n });\n}\n"],
|
|
5
|
-
"mappings": ";AAKA,SAAS,YAAAA,iBAAgB;AAKzB,SAAS,uBAAuB;AAEhC,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AC/B,UAAU;AAAA,IACd,MAAM;AACF,UAAI,CAAC,eAAe;AAChB,cAAM,IAAI,wBAAwB,yBAAyB;AAAA,MAC/D;AAEA,UAAI,CAAC,SAAS;AACV,cAAM,IAAI;AAAA,UACN;AAAA,QACJ;AAAA,MACJ;AAEA,YAAM,kCACF,cAAc,SAAS,+BAA+B;AAE1D,UAAI,iCAAiC;AACjC,eAAO,MAAM,gCAAgC,yBAAyB;AAAA,UAClE,SAAS,MAAM,QAAQ,OAAO,IAAI,SAAS,IAAI,WAAW,OAAO,CAAC,IAAI;AAAA,UACtE;AAAA,UACA,OAAO,SAAS,eAAe,OAAO,CAAC;AAAA,QAC3C,CAAC;AAAA,MACL;AAAA,IACJ;AAAA,IACA,GAAG;AAAA,EACP,CAAC;AACL;;;
|
|
3
|
+
"sources": ["../../../../src/hooks/wallet/useSignAndExecuteTransaction.ts", "../../../../src/constants/walletMutationKeys.ts", "../../../../src/errors/walletErrors.ts", "../../../../src/hooks/useIotaClient.ts", "../../../../src/components/IotaClientProvider.tsx", "../../../../src/hooks/wallet/useWalletStore.ts", "../../../../src/contexts/walletContext.ts", "../../../../src/hooks/wallet/useCurrentAccount.ts", "../../../../src/hooks/wallet/useCurrentWallet.ts", "../../../../src/hooks/wallet/useReportTransactionEffects.ts", "../../../../src/hooks/wallet/useCurrentChain.ts"],
|
|
4
|
+
"sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// Modifications Copyright (c) 2024 IOTA Stiftung\n// SPDX-License-Identifier: Apache-2.0\n\nimport type { Transaction } from '@iota/iota-sdk/transactions';\nimport { toBase64 } from '@iota/iota-sdk/utils';\nimport type {\n IotaSignAndExecuteTransactionInput,\n IotaSignAndExecuteTransactionOutput,\n} from '@iota/wallet-standard';\nimport { signTransaction } from '@iota/wallet-standard';\nimport type { UseMutationOptions, UseMutationResult } from '@tanstack/react-query';\nimport { useMutation } from '@tanstack/react-query';\n\nimport { walletMutationKeys } from '../../constants/walletMutationKeys.js';\nimport {\n WalletFeatureNotSupportedError,\n WalletNoAccountSelectedError,\n WalletNotConnectedError,\n} from '../../errors/walletErrors.js';\nimport type { PartialBy } from '../../types/utilityTypes.js';\nimport { useIotaClient } from '../useIotaClient.js';\nimport { useCurrentAccount } from './useCurrentAccount.js';\nimport { useCurrentWallet } from './useCurrentWallet.js';\nimport { useReportTransactionEffects } from './useReportTransactionEffects.js';\nimport { useCurrentChain } from './useCurrentChain.js';\n\ntype UseSignAndExecuteTransactionArgs = PartialBy<\n Omit<IotaSignAndExecuteTransactionInput, 'transaction'>,\n 'account' | 'chain'\n> & {\n transaction: Transaction | string;\n waitForTransaction?: boolean;\n};\n\ntype UseSignAndExecuteTransactionResult = IotaSignAndExecuteTransactionOutput;\n\ntype UseSignAndExecuteTransactionError =\n | WalletFeatureNotSupportedError\n | WalletNoAccountSelectedError\n | WalletNotConnectedError\n | Error;\n\ntype ExecuteTransactionResult =\n | {\n digest: string;\n rawEffects?: number[];\n }\n | {\n effects?: {\n bcs?: string;\n };\n };\n\ntype UseSignAndExecuteTransactionMutationOptions<Result extends ExecuteTransactionResult> = Omit<\n UseMutationOptions<\n Result,\n UseSignAndExecuteTransactionError,\n UseSignAndExecuteTransactionArgs,\n unknown\n >,\n 'mutationFn'\n> & {\n execute?: ({ bytes, signature }: { bytes: string; signature: string }) => Promise<Result>;\n};\n\n/**\n * Mutation hook for prompting the user to sign and execute a transaction.\n */\nexport function useSignAndExecuteTransaction<\n Result extends ExecuteTransactionResult = UseSignAndExecuteTransactionResult,\n>({\n mutationKey,\n execute,\n ...mutationOptions\n}: UseSignAndExecuteTransactionMutationOptions<Result> = {}): UseMutationResult<\n Result,\n UseSignAndExecuteTransactionError,\n UseSignAndExecuteTransactionArgs\n> {\n const currentChain = useCurrentChain();\n const { currentWallet, supportedIntents } = useCurrentWallet();\n const currentAccount = useCurrentAccount();\n const client = useIotaClient();\n const { mutate: reportTransactionEffects } = useReportTransactionEffects();\n\n const executeTransaction: ({\n bytes,\n signature,\n }: {\n bytes: string;\n signature: string;\n }) => Promise<ExecuteTransactionResult> =\n execute ??\n (async ({ bytes, signature }) => {\n const { digest, rawEffects } = await client.executeTransactionBlock({\n transactionBlock: bytes,\n signature,\n options: {\n showRawEffects: true,\n },\n });\n\n return {\n digest,\n rawEffects,\n effects: toBase64(new Uint8Array(rawEffects!)),\n bytes,\n signature,\n };\n });\n\n return useMutation({\n mutationKey: walletMutationKeys.signAndExecuteTransaction(mutationKey),\n mutationFn: async ({ transaction, ...signTransactionArgs }): Promise<Result> => {\n if (!currentWallet) {\n throw new WalletNotConnectedError('No wallet is connected.');\n }\n\n const signerAccount = signTransactionArgs.account ?? currentAccount;\n if (!signerAccount) {\n throw new WalletNoAccountSelectedError(\n 'No wallet account is selected to sign the transaction with.',\n );\n }\n\n if (!currentWallet.features['iota:signTransaction']) {\n throw new WalletFeatureNotSupportedError(\n \"This wallet doesn't support the `signTransaction` feature.\",\n );\n }\n\n const chain = signTransactionArgs.chain ?? currentChain ?? signerAccount?.chains[0];\n\n const { signature, bytes } = await signTransaction(currentWallet, {\n ...signTransactionArgs,\n transaction: {\n async toJSON() {\n return typeof transaction === 'string'\n ? transaction\n : await transaction.toJSON({\n supportedIntents,\n client,\n });\n },\n },\n account: signerAccount,\n chain,\n });\n\n const result = await executeTransaction({ bytes, signature });\n\n let effects: string;\n\n if ('effects' in result && result.effects?.bcs) {\n effects = result.effects.bcs;\n } else if ('rawEffects' in result) {\n effects = toBase64(new Uint8Array(result.rawEffects!));\n } else {\n throw new Error('Could not parse effects from transaction result.');\n }\n\n reportTransactionEffects({ effects, account: signerAccount, chain });\n\n if (signTransactionArgs.waitForTransaction && 'digest' in result) {\n await client.waitForTransaction({\n digest: result.digest,\n });\n }\n\n return result as Result;\n },\n ...mutationOptions,\n });\n}\n", "// Copyright (c) Mysten Labs, Inc.\n// Modifications Copyright (c) 2024 IOTA Stiftung\n// SPDX-License-Identifier: Apache-2.0\n\nimport type { MutationKey } from '@tanstack/react-query';\n\nexport const walletMutationKeys = {\n all: { baseScope: 'wallet' },\n connectWallet: formMutationKeyFn('connect-wallet'),\n autoconnectWallet: formMutationKeyFn('autoconnect-wallet'),\n disconnectWallet: formMutationKeyFn('disconnect-wallet'),\n signPersonalMessage: formMutationKeyFn('sign-personal-message'),\n signTransaction: formMutationKeyFn('sign-transaction'),\n signAndExecuteTransaction: formMutationKeyFn('sign-and-execute-transaction'),\n switchAccount: formMutationKeyFn('switch-account'),\n reportTransactionEffects: formMutationKeyFn('report-transaction-effects'),\n};\n\nfunction formMutationKeyFn(baseEntity: string) {\n return function mutationKeyFn(additionalKeys: MutationKey = []) {\n return [{ ...walletMutationKeys.all, baseEntity }, ...additionalKeys];\n };\n}\n", "// Copyright (c) Mysten Labs, Inc.\n// Modifications Copyright (c) 2024 IOTA Stiftung\n// SPDX-License-Identifier: Apache-2.0\n\n/**\n * An error that is instantiated when someone attempts to perform an action that requires an active wallet connection.\n */\nexport class WalletNotConnectedError extends Error {}\n\n/**\n * An error that is instantiated when someone attempts to perform an action that requires a selected wallet account.\n * This is more of an edge case stemming from the fact that wallets don't technically require you to authorize any\n * accounts when connecting a wallet.\n */\nexport class WalletNoAccountSelectedError extends Error {}\n\n/**\n * An error that is instantiated when someone attempts to perform an action that isn't supported by a wallet.\n */\nexport class WalletFeatureNotSupportedError extends Error {}\n\n/**\n * An error that is instantiated when a wallet account can't be found for a specific wallet.\n */\nexport class WalletAccountNotFoundError extends Error {}\n", "// Copyright (c) Mysten Labs, Inc.\n// Modifications Copyright (c) 2024 IOTA Stiftung\n// SPDX-License-Identifier: Apache-2.0\n\nimport type { IotaClient } from '@iota/iota-sdk/client';\nimport { useContext } from 'react';\n\nimport { IotaClientContext } from '../components/IotaClientProvider.js';\n\nexport function useIotaClientContext() {\n const iotaClient = useContext(IotaClientContext);\n\n if (!iotaClient) {\n throw new Error(\n 'Could not find IotaClientContext. Ensure that you have set up the IotaClientProvider',\n );\n }\n\n return iotaClient;\n}\n\nexport function useIotaClient(): IotaClient {\n return useIotaClientContext().client;\n}\n", "// Copyright (c) Mysten Labs, Inc.\n// Modifications Copyright (c) 2024 IOTA Stiftung\n// SPDX-License-Identifier: Apache-2.0\n\nimport { getNetwork, isIotaClient, Network, IotaClient } from '@iota/iota-sdk/client';\nimport type { IotaClientOptions } from '@iota/iota-sdk/client';\nimport { createContext, useMemo, useState } from 'react';\n\nimport type { NetworkConfig } from '../hooks/networkConfig.js';\n\ntype NetworkConfigs<T extends NetworkConfig | IotaClient = NetworkConfig | IotaClient> = Record<\n string,\n T\n>;\n\nexport interface IotaClientProviderContext {\n client: IotaClient;\n networks: NetworkConfigs;\n network: string;\n config: NetworkConfig | null;\n selectNetwork: (network: string) => void;\n}\n\nexport const IotaClientContext = createContext<IotaClientProviderContext | null>(null);\n\nexport type IotaClientProviderProps<T extends NetworkConfigs> = {\n createClient?: (name: keyof T, config: T[keyof T]) => IotaClient;\n children: React.ReactNode;\n networks?: T;\n onNetworkChange?: (network: keyof T & string) => void;\n} & (\n | {\n defaultNetwork?: keyof T & string;\n network?: never;\n }\n | {\n defaultNetwork?: never;\n network?: keyof T & string;\n }\n);\n\nconst DEFAULT_NETWORKS = {\n localnet: { url: getNetwork(Network.Localnet)?.url },\n};\n\nconst DEFAULT_CREATE_CLIENT = function createClient(\n _name: string,\n config: NetworkConfig | IotaClient,\n) {\n if (isIotaClient(config)) {\n return config;\n }\n\n return new IotaClient(config);\n};\n\nexport function IotaClientProvider<T extends NetworkConfigs>(props: IotaClientProviderProps<T>) {\n const { onNetworkChange, network, children } = props;\n const networks = (props.networks ?? DEFAULT_NETWORKS) as T;\n const createClient =\n (props.createClient as typeof DEFAULT_CREATE_CLIENT) ?? DEFAULT_CREATE_CLIENT;\n\n const [selectedNetwork, setSelectedNetwork] = useState<keyof T & string>(\n props.network ?? props.defaultNetwork ?? (Object.keys(networks)[0] as keyof T & string),\n );\n\n const currentNetwork = props.network ?? selectedNetwork;\n\n const client = useMemo(() => {\n return createClient(currentNetwork, networks[currentNetwork]);\n }, [createClient, currentNetwork, networks]);\n\n const ctx = useMemo((): IotaClientProviderContext => {\n return {\n client,\n networks,\n network: currentNetwork,\n config:\n networks[currentNetwork] instanceof IotaClient\n ? null\n : (networks[currentNetwork] as IotaClientOptions),\n selectNetwork: (newNetwork) => {\n if (currentNetwork === newNetwork) {\n return;\n }\n\n if (!network && newNetwork !== selectedNetwork) {\n setSelectedNetwork(newNetwork);\n }\n\n onNetworkChange?.(newNetwork);\n },\n };\n }, [client, networks, selectedNetwork, currentNetwork, network, onNetworkChange]);\n\n return <IotaClientContext.Provider value={ctx}>{children}</IotaClientContext.Provider>;\n}\n", "// Copyright (c) Mysten Labs, Inc.\n// Modifications Copyright (c) 2024 IOTA Stiftung\n// SPDX-License-Identifier: Apache-2.0\n\nimport { useContext } from 'react';\nimport { useStore } from 'zustand';\n\nimport { WalletContext } from '../../contexts/walletContext.js';\nimport type { StoreState } from '../../walletStore.js';\n\nexport function useWalletStore<T>(selector: (state: StoreState) => T): T {\n const store = useContext(WalletContext);\n if (!store) {\n throw new Error(\n 'Could not find WalletContext. Ensure that you have set up the WalletProvider.',\n );\n }\n return useStore(store, selector);\n}\n", "// Copyright (c) Mysten Labs, Inc.\n// Modifications Copyright (c) 2024 IOTA Stiftung\n// SPDX-License-Identifier: Apache-2.0\n\nimport { createContext } from 'react';\n\nimport type { WalletStore } from '../walletStore.js';\n\nexport const WalletContext = createContext<WalletStore | null>(null);\n", "// Copyright (c) Mysten Labs, Inc.\n// Modifications Copyright (c) 2024 IOTA Stiftung\n// SPDX-License-Identifier: Apache-2.0\n\nimport type { WalletAccount } from '@iota/wallet-standard';\n\nimport { useWalletStore } from './useWalletStore.js';\n\n/**\n * Retrieves the wallet account that is currently selected, if one exists.\n */\nexport function useCurrentAccount(): WalletAccount | null {\n return useWalletStore((state) => state.currentAccount);\n}\n", "// Copyright (c) Mysten Labs, Inc.\n// Modifications Copyright (c) 2024 IOTA Stiftung\n// SPDX-License-Identifier: Apache-2.0\n\nimport { useWalletStore } from './useWalletStore.js';\n\n/**\n * Retrieves the wallet that is currently connected to the dApp, if one exists.\n */\nexport function useCurrentWallet() {\n const currentWallet = useWalletStore((state) => state.currentWallet);\n const connectionStatus = useWalletStore((state) => state.connectionStatus);\n const supportedIntents = useWalletStore((state) => state.supportedIntents);\n\n switch (connectionStatus) {\n case 'connecting':\n return {\n connectionStatus,\n currentWallet: null,\n isDisconnected: false,\n isConnecting: true,\n isConnected: false,\n supportedIntents: [],\n } as const;\n case 'disconnected':\n return {\n connectionStatus,\n currentWallet: null,\n isDisconnected: true,\n isConnecting: false,\n isConnected: false,\n supportedIntents: [],\n } as const;\n case 'connected': {\n return {\n connectionStatus,\n currentWallet: currentWallet!,\n isDisconnected: false,\n isConnecting: false,\n isConnected: true,\n supportedIntents,\n } as const;\n }\n }\n}\n", "// Copyright (c) Mysten Labs, Inc.\n// Modifications Copyright (c) 2024 IOTA Stiftung\n// SPDX-License-Identifier: Apache-2.0\n\nimport { toBase64 } from '@iota/iota-sdk/utils';\nimport type { IotaReportTransactionEffectsInput } from '@iota/wallet-standard';\nimport type { UseMutationOptions, UseMutationResult } from '@tanstack/react-query';\nimport { useMutation } from '@tanstack/react-query';\n\nimport { walletMutationKeys } from '../../constants/walletMutationKeys.js';\nimport type { WalletFeatureNotSupportedError } from '../../errors/walletErrors.js';\nimport {\n WalletNoAccountSelectedError,\n WalletNotConnectedError,\n} from '../../errors/walletErrors.js';\nimport type { PartialBy } from '../../types/utilityTypes.js';\nimport { useCurrentAccount } from './useCurrentAccount.js';\nimport { useCurrentWallet } from './useCurrentWallet.js';\n\ntype UseReportTransactionEffectsArgs = Omit<\n PartialBy<IotaReportTransactionEffectsInput, 'account' | 'chain'>,\n 'effects'\n> & {\n effects: string | number[];\n};\n\ntype UseReportTransactionEffectsError =\n | WalletFeatureNotSupportedError\n | WalletNoAccountSelectedError\n | WalletNotConnectedError\n | Error;\n\ntype UseReportTransactionEffectsMutationOptions = Omit<\n UseMutationOptions<\n void,\n UseReportTransactionEffectsError,\n UseReportTransactionEffectsArgs,\n unknown\n >,\n 'mutationFn'\n>;\n\n/**\n * Mutation hook for prompting the user to sign a message.\n */\nexport function useReportTransactionEffects({\n mutationKey,\n ...mutationOptions\n}: UseReportTransactionEffectsMutationOptions = {}): UseMutationResult<\n void,\n UseReportTransactionEffectsError,\n UseReportTransactionEffectsArgs\n> {\n const { currentWallet } = useCurrentWallet();\n const currentAccount = useCurrentAccount();\n\n return useMutation({\n mutationKey: walletMutationKeys.reportTransactionEffects(mutationKey),\n mutationFn: async ({\n effects,\n chain = currentWallet?.chains[0],\n account = currentAccount,\n }) => {\n if (!currentWallet) {\n throw new WalletNotConnectedError('No wallet is connected.');\n }\n\n if (!account) {\n throw new WalletNoAccountSelectedError(\n 'No wallet account is selected to report transaction effects for',\n );\n }\n\n const reportTransactionEffectsFeature =\n currentWallet.features['iota:reportTransactionEffects'];\n\n if (reportTransactionEffectsFeature) {\n return await reportTransactionEffectsFeature.reportTransactionEffects({\n effects: Array.isArray(effects) ? toBase64(new Uint8Array(effects)) : effects,\n account,\n chain: chain ?? currentWallet?.chains[0],\n });\n }\n },\n ...mutationOptions,\n });\n}\n", "// Copyright (c) 2025 IOTA Stiftung\n// SPDX-License-Identifier: Apache-2.0\n\nimport type { ChainType } from '@iota/iota-sdk/client';\nimport { useWalletStore } from './useWalletStore.js';\n\n/**\n * Retrieves the chain the dapp is configured with, if any.\n */\nexport function useCurrentChain(): ChainType | undefined {\n return useWalletStore((state) => state.chain);\n}\n"],
|
|
5
|
+
"mappings": ";AAKA,SAAS,YAAAA,iBAAgB;AAKzB,SAAS,uBAAuB;AAEhC,SAAS,eAAAC,oBAAmB;;;ACNrB,IAAM,qBAAqB;AAAA,EAC9B,KAAK,EAAE,WAAW,SAAS;AAAA,EAC3B,eAAe,kBAAkB,gBAAgB;AAAA,EACjD,mBAAmB,kBAAkB,oBAAoB;AAAA,EACzD,kBAAkB,kBAAkB,mBAAmB;AAAA,EACvD,qBAAqB,kBAAkB,uBA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J;AAEA,UAAI,CAAC,cAAc,SAAS,sBAAsB,GAAG;AACjD,cAAM,IAAI;AAAA,UACN;AAAA,QACJ;AAAA,MACJ;AAEA,YAAM,QAAQ,oBAAoB,SAAS,gBAAgB,eAAe,OAAO,CAAC;AAElF,YAAM,EAAE,WAAW,MAAM,IAAI,MAAM,gBAAgB,eAAe;AAAA,QAC9D,GAAG;AAAA,QACH,aAAa;AAAA,UACT,MAAM,SAAS;AACX,mBAAO,OAAO,gBAAgB,WACxB,cACA,MAAM,YAAY,OAAO;AAAA,cACrB;AAAA,cACA;AAAA,YACJ,CAAC;AAAA,UACX;AAAA,QACJ;AAAA,QACA,SAAS;AAAA,QACT;AAAA,MACJ,CAAC;AAED,YAAM,SAAS,MAAM,mBAAmB,EAAE,OAAO,UAAU,CAAC;AAE5D,UAAI;AAEJ,UAAI,aAAa,UAAU,OAAO,SAAS,KAAK;AAC5C,kBAAU,OAAO,QAAQ;AAAA,MAC7B,WAAW,gBAAgB,QAAQ;AAC/B,kBAAUD,UAAS,IAAI,WAAW,OAAO,UAAW,CAAC;AAAA,MACzD,OAAO;AACH,cAAM,IAAI,MAAM,kDAAkD;AAAA,MACtE;AAEA,+BAAyB,EAAE,SAAS,SAAS,eAAe,MAAM,CAAC;AAEnE,UAAI,oBAAoB,sBAAsB,YAAY,QAAQ;AAC9D,cAAM,OAAO,mBAAmB;AAAA,UAC5B,QAAQ,OAAO;AAAA,QACnB,CAAC;AAAA,MACL;AAEA,aAAO;AAAA,IACX;AAAA,IACA,GAAG;AAAA,EACP,CAAC;AACL;",
|
|
6
6
|
"names": ["toBase64", "useMutation", "useContext", "createContext", "useContext", "toBase64", "useMutation"]
|
|
7
7
|
}
|
package/dist/esm/index.js
CHANGED
|
@@ -95,6 +95,7 @@ function useWalletStore(selector) {
|
|
|
95
95
|
|
|
96
96
|
// src/hooks/wallet/useConnectWallet.ts
|
|
97
97
|
function useConnectWallet({
|
|
98
|
+
onConnected,
|
|
98
99
|
mutationKey,
|
|
99
100
|
...mutationOptions
|
|
100
101
|
} = {}) {
|
|
@@ -116,6 +117,7 @@ function useConnectWallet({
|
|
|
116
117
|
selectedAccount,
|
|
117
118
|
connectResult.supportedIntents
|
|
118
119
|
);
|
|
120
|
+
onConnected?.({ wallet });
|
|
119
121
|
return { accounts: connectedIotaAccounts };
|
|
120
122
|
} catch (error) {
|
|
121
123
|
setConnectionStatus("disconnected");
|
|
@@ -503,11 +505,19 @@ function WalletList({ selectedWalletName, onPlaceholderClick, onSelect }) {
|
|
|
503
505
|
|
|
504
506
|
// src/components/connect-modal/ConnectModal.tsx
|
|
505
507
|
import { jsx as jsx15, jsxs as jsxs6 } from "react/jsx-runtime";
|
|
506
|
-
function ConnectModal({
|
|
508
|
+
function ConnectModal({
|
|
509
|
+
trigger,
|
|
510
|
+
open,
|
|
511
|
+
defaultOpen,
|
|
512
|
+
onOpenChange,
|
|
513
|
+
onConnected
|
|
514
|
+
}) {
|
|
507
515
|
const [isModalOpen, setModalOpen] = useState(open ?? defaultOpen);
|
|
508
516
|
const [currentView, setCurrentView] = useState();
|
|
509
517
|
const [selectedWallet, setSelectedWallet] = useState();
|
|
510
|
-
const { mutate, isError } = useConnectWallet(
|
|
518
|
+
const { mutate, isError } = useConnectWallet({
|
|
519
|
+
onConnected
|
|
520
|
+
});
|
|
511
521
|
const resetSelection = () => {
|
|
512
522
|
setSelectedWallet(void 0);
|
|
513
523
|
setCurrentView(void 0);
|
|
@@ -770,27 +780,129 @@ function ChevronIcon(props) {
|
|
|
770
780
|
) });
|
|
771
781
|
}
|
|
772
782
|
|
|
783
|
+
// src/hooks/useGetDefaultIotaName.ts
|
|
784
|
+
import { getNetwork as getNetwork2 } from "@iota/iota-sdk/client";
|
|
785
|
+
import { useQuery } from "@tanstack/react-query";
|
|
786
|
+
import { IotaNamesClient, normalizeIotaName } from "@iota/iota-names-sdk";
|
|
787
|
+
|
|
788
|
+
// src/hooks/useIotaClient.ts
|
|
789
|
+
import { useContext as useContext2 } from "react";
|
|
790
|
+
|
|
791
|
+
// src/components/IotaClientProvider.tsx
|
|
792
|
+
import { getNetwork, isIotaClient, Network, IotaClient } from "@iota/iota-sdk/client";
|
|
793
|
+
import { createContext as createContext2, useMemo, useState as useState2 } from "react";
|
|
794
|
+
import { jsx as jsx18 } from "react/jsx-runtime";
|
|
795
|
+
var IotaClientContext = createContext2(null);
|
|
796
|
+
var DEFAULT_NETWORKS = {
|
|
797
|
+
localnet: { url: getNetwork(Network.Localnet)?.url }
|
|
798
|
+
};
|
|
799
|
+
var DEFAULT_CREATE_CLIENT = function createClient(_name, config) {
|
|
800
|
+
if (isIotaClient(config)) {
|
|
801
|
+
return config;
|
|
802
|
+
}
|
|
803
|
+
return new IotaClient(config);
|
|
804
|
+
};
|
|
805
|
+
function IotaClientProvider(props) {
|
|
806
|
+
const { onNetworkChange, network, children } = props;
|
|
807
|
+
const networks = props.networks ?? DEFAULT_NETWORKS;
|
|
808
|
+
const createClient2 = props.createClient ?? DEFAULT_CREATE_CLIENT;
|
|
809
|
+
const [selectedNetwork, setSelectedNetwork] = useState2(
|
|
810
|
+
props.network ?? props.defaultNetwork ?? Object.keys(networks)[0]
|
|
811
|
+
);
|
|
812
|
+
const currentNetwork = props.network ?? selectedNetwork;
|
|
813
|
+
const client = useMemo(() => {
|
|
814
|
+
return createClient2(currentNetwork, networks[currentNetwork]);
|
|
815
|
+
}, [createClient2, currentNetwork, networks]);
|
|
816
|
+
const ctx = useMemo(() => {
|
|
817
|
+
return {
|
|
818
|
+
client,
|
|
819
|
+
networks,
|
|
820
|
+
network: currentNetwork,
|
|
821
|
+
config: networks[currentNetwork] instanceof IotaClient ? null : networks[currentNetwork],
|
|
822
|
+
selectNetwork: (newNetwork) => {
|
|
823
|
+
if (currentNetwork === newNetwork) {
|
|
824
|
+
return;
|
|
825
|
+
}
|
|
826
|
+
if (!network && newNetwork !== selectedNetwork) {
|
|
827
|
+
setSelectedNetwork(newNetwork);
|
|
828
|
+
}
|
|
829
|
+
onNetworkChange?.(newNetwork);
|
|
830
|
+
}
|
|
831
|
+
};
|
|
832
|
+
}, [client, networks, selectedNetwork, currentNetwork, network, onNetworkChange]);
|
|
833
|
+
return /* @__PURE__ */ jsx18(IotaClientContext.Provider, { value: ctx, children });
|
|
834
|
+
}
|
|
835
|
+
|
|
836
|
+
// src/hooks/useIotaClient.ts
|
|
837
|
+
function useIotaClientContext() {
|
|
838
|
+
const iotaClient = useContext2(IotaClientContext);
|
|
839
|
+
if (!iotaClient) {
|
|
840
|
+
throw new Error(
|
|
841
|
+
"Could not find IotaClientContext. Ensure that you have set up the IotaClientProvider"
|
|
842
|
+
);
|
|
843
|
+
}
|
|
844
|
+
return iotaClient;
|
|
845
|
+
}
|
|
846
|
+
function useIotaClient() {
|
|
847
|
+
return useIotaClientContext().client;
|
|
848
|
+
}
|
|
849
|
+
|
|
850
|
+
// src/hooks/useGetDefaultIotaName.ts
|
|
851
|
+
import { useMemo as useMemo2 } from "react";
|
|
852
|
+
import { IotaGraphQLClient } from "@iota/iota-sdk/graphql";
|
|
853
|
+
function useGetDefaultIotaName(address, iotaNamesEnabled) {
|
|
854
|
+
const iotaContext = useIotaClientContext();
|
|
855
|
+
const network = getNetwork2(iotaContext.network);
|
|
856
|
+
const iotaNamesClient = useMemo2(() => {
|
|
857
|
+
const iotaGraphQLClient = new IotaGraphQLClient({
|
|
858
|
+
url: network.graphql
|
|
859
|
+
});
|
|
860
|
+
return new IotaNamesClient({
|
|
861
|
+
graphQlClient: iotaGraphQLClient,
|
|
862
|
+
network: network.id
|
|
863
|
+
});
|
|
864
|
+
}, [network.id]);
|
|
865
|
+
const iotaNamesSupported = !!iotaNamesClient.config;
|
|
866
|
+
return useQuery({
|
|
867
|
+
queryKey: ["iota-name", "default-name", address],
|
|
868
|
+
queryFn: async () => {
|
|
869
|
+
if (!address) return null;
|
|
870
|
+
const name = await iotaNamesClient?.getDefaultName(address);
|
|
871
|
+
return name ? normalizeIotaName(name) : name;
|
|
872
|
+
},
|
|
873
|
+
enabled: !!iotaNamesClient && !!address && iotaNamesEnabled && iotaNamesSupported,
|
|
874
|
+
staleTime: 1e3 * 60 * 10
|
|
875
|
+
});
|
|
876
|
+
}
|
|
877
|
+
|
|
773
878
|
// src/components/AccountDropdownMenu.tsx
|
|
774
|
-
import { jsx as
|
|
775
|
-
function AccountDropdownMenu({
|
|
879
|
+
import { jsx as jsx19, jsxs as jsxs7 } from "react/jsx-runtime";
|
|
880
|
+
function AccountDropdownMenu({
|
|
881
|
+
currentAccount,
|
|
882
|
+
size = "lg",
|
|
883
|
+
iotaNamesEnabled
|
|
884
|
+
}) {
|
|
776
885
|
const { mutate: disconnectWallet } = useDisconnectWallet();
|
|
777
886
|
const accounts = useAccounts();
|
|
887
|
+
const { data: iotaName } = useGetDefaultIotaName(currentAccount.address, iotaNamesEnabled);
|
|
888
|
+
const displayAccount = iotaName ?? currentAccount.label ?? formatAddress(currentAccount.address);
|
|
778
889
|
return /* @__PURE__ */ jsxs7(DropdownMenu.Root, { modal: false, children: [
|
|
779
|
-
/* @__PURE__ */
|
|
780
|
-
/* @__PURE__ */
|
|
781
|
-
/* @__PURE__ */
|
|
890
|
+
/* @__PURE__ */ jsx19(StyleMarker, { children: /* @__PURE__ */ jsx19(DropdownMenu.Trigger, { asChild: true, children: /* @__PURE__ */ jsxs7(Button, { size, className: connectedAccount, children: [
|
|
891
|
+
/* @__PURE__ */ jsx19(Text, { mono: true, weight: "bold", children: displayAccount }),
|
|
892
|
+
/* @__PURE__ */ jsx19(ChevronIcon, {})
|
|
782
893
|
] }) }) }),
|
|
783
|
-
/* @__PURE__ */
|
|
784
|
-
/* @__PURE__ */
|
|
894
|
+
/* @__PURE__ */ jsx19(DropdownMenu.Portal, { children: /* @__PURE__ */ jsx19(StyleMarker, { className: menuContainer, children: /* @__PURE__ */ jsxs7(DropdownMenu.Content, { className: menuContent, children: [
|
|
895
|
+
/* @__PURE__ */ jsx19("div", { className: scrollableContent, children: accounts.map((account) => /* @__PURE__ */ jsx19(
|
|
785
896
|
AccountDropdownMenuItem,
|
|
786
897
|
{
|
|
787
898
|
account,
|
|
788
|
-
active: currentAccount.address === account.address
|
|
899
|
+
active: currentAccount.address === account.address,
|
|
900
|
+
iotaNamesEnabled
|
|
789
901
|
},
|
|
790
902
|
account.address
|
|
791
903
|
)) }),
|
|
792
|
-
/* @__PURE__ */
|
|
793
|
-
/* @__PURE__ */
|
|
904
|
+
/* @__PURE__ */ jsx19(DropdownMenu.Separator, { className: separator }),
|
|
905
|
+
/* @__PURE__ */ jsx19(
|
|
794
906
|
DropdownMenu.Item,
|
|
795
907
|
{
|
|
796
908
|
className: clsx7(menuItem),
|
|
@@ -803,83 +915,51 @@ function AccountDropdownMenu({ currentAccount, size = "lg" }) {
|
|
|
803
915
|
}
|
|
804
916
|
function AccountDropdownMenuItem({
|
|
805
917
|
account,
|
|
806
|
-
active
|
|
918
|
+
active,
|
|
919
|
+
iotaNamesEnabled
|
|
807
920
|
}) {
|
|
808
921
|
const { mutate: switchAccount } = useSwitchAccount();
|
|
922
|
+
const { data: iotaName } = useGetDefaultIotaName(account.address, iotaNamesEnabled);
|
|
923
|
+
const displayAccount = iotaName ?? account.label ?? formatAddress(account.address);
|
|
809
924
|
return /* @__PURE__ */ jsxs7(
|
|
810
925
|
DropdownMenu.Item,
|
|
811
926
|
{
|
|
812
927
|
className: clsx7(menuItem, switchAccountMenuItem),
|
|
813
928
|
onSelect: () => switchAccount({ account }),
|
|
814
929
|
children: [
|
|
815
|
-
/* @__PURE__ */
|
|
816
|
-
active ? /* @__PURE__ */
|
|
930
|
+
/* @__PURE__ */ jsx19(Text, { mono: true, children: displayAccount }),
|
|
931
|
+
active ? /* @__PURE__ */ jsx19(CheckIcon, {}) : null
|
|
817
932
|
]
|
|
818
933
|
}
|
|
819
934
|
);
|
|
820
935
|
}
|
|
821
936
|
|
|
822
937
|
// src/components/ConnectButton.tsx
|
|
823
|
-
import { jsx as
|
|
938
|
+
import { jsx as jsx20 } from "react/jsx-runtime";
|
|
824
939
|
function ConnectButton({
|
|
825
940
|
connectText = "Connect Wallet",
|
|
826
941
|
size,
|
|
942
|
+
iotaNamesEnabled = true,
|
|
943
|
+
onConnected,
|
|
827
944
|
...buttonProps
|
|
828
945
|
}) {
|
|
829
946
|
const currentAccount = useCurrentAccount();
|
|
830
|
-
return currentAccount ? /* @__PURE__ */
|
|
947
|
+
return currentAccount ? /* @__PURE__ */ jsx20(
|
|
948
|
+
AccountDropdownMenu,
|
|
949
|
+
{
|
|
950
|
+
currentAccount,
|
|
951
|
+
size,
|
|
952
|
+
iotaNamesEnabled
|
|
953
|
+
}
|
|
954
|
+
) : /* @__PURE__ */ jsx20(
|
|
831
955
|
ConnectModal,
|
|
832
956
|
{
|
|
833
|
-
|
|
957
|
+
onConnected,
|
|
958
|
+
trigger: /* @__PURE__ */ jsx20(StyleMarker, { children: /* @__PURE__ */ jsx20(Button, { ...buttonProps, size, children: connectText }) })
|
|
834
959
|
}
|
|
835
960
|
);
|
|
836
961
|
}
|
|
837
962
|
|
|
838
|
-
// src/components/IotaClientProvider.tsx
|
|
839
|
-
import { getNetwork, isIotaClient, Network, IotaClient } from "@iota/iota-sdk/client";
|
|
840
|
-
import { createContext as createContext2, useMemo, useState as useState2 } from "react";
|
|
841
|
-
import { jsx as jsx20 } from "react/jsx-runtime";
|
|
842
|
-
var IotaClientContext = createContext2(null);
|
|
843
|
-
var DEFAULT_NETWORKS = {
|
|
844
|
-
localnet: { url: getNetwork(Network.Localnet)?.url }
|
|
845
|
-
};
|
|
846
|
-
var DEFAULT_CREATE_CLIENT = function createClient(_name, config) {
|
|
847
|
-
if (isIotaClient(config)) {
|
|
848
|
-
return config;
|
|
849
|
-
}
|
|
850
|
-
return new IotaClient(config);
|
|
851
|
-
};
|
|
852
|
-
function IotaClientProvider(props) {
|
|
853
|
-
const { onNetworkChange, network, children } = props;
|
|
854
|
-
const networks = props.networks ?? DEFAULT_NETWORKS;
|
|
855
|
-
const createClient2 = props.createClient ?? DEFAULT_CREATE_CLIENT;
|
|
856
|
-
const [selectedNetwork, setSelectedNetwork] = useState2(
|
|
857
|
-
props.network ?? props.defaultNetwork ?? Object.keys(networks)[0]
|
|
858
|
-
);
|
|
859
|
-
const currentNetwork = props.network ?? selectedNetwork;
|
|
860
|
-
const client = useMemo(() => {
|
|
861
|
-
return createClient2(currentNetwork, networks[currentNetwork]);
|
|
862
|
-
}, [createClient2, currentNetwork, networks]);
|
|
863
|
-
const ctx = useMemo(() => {
|
|
864
|
-
return {
|
|
865
|
-
client,
|
|
866
|
-
networks,
|
|
867
|
-
network: currentNetwork,
|
|
868
|
-
config: networks[currentNetwork] instanceof IotaClient ? null : networks[currentNetwork],
|
|
869
|
-
selectNetwork: (newNetwork) => {
|
|
870
|
-
if (currentNetwork === newNetwork) {
|
|
871
|
-
return;
|
|
872
|
-
}
|
|
873
|
-
if (!network && newNetwork !== selectedNetwork) {
|
|
874
|
-
setSelectedNetwork(newNetwork);
|
|
875
|
-
}
|
|
876
|
-
onNetworkChange?.(newNetwork);
|
|
877
|
-
}
|
|
878
|
-
};
|
|
879
|
-
}, [client, networks, selectedNetwork, currentNetwork, network, onNetworkChange]);
|
|
880
|
-
return /* @__PURE__ */ jsx20(IotaClientContext.Provider, { value: ctx, children });
|
|
881
|
-
}
|
|
882
|
-
|
|
883
963
|
// src/components/WalletProvider.tsx
|
|
884
964
|
import { useRef } from "react";
|
|
885
965
|
|
|
@@ -910,7 +990,7 @@ var WALLET_CHROME_EXTENSION_ID = "iidjkmdceolghepehaaddojmnjnkkija";
|
|
|
910
990
|
var WALLET_DOWNLOAD_URL = "https://chromewebstore.google.com/detail/" + WALLET_CHROME_EXTENSION_ID;
|
|
911
991
|
|
|
912
992
|
// src/hooks/wallet/useAutoConnectWallet.ts
|
|
913
|
-
import { useQuery } from "@tanstack/react-query";
|
|
993
|
+
import { useQuery as useQuery2 } from "@tanstack/react-query";
|
|
914
994
|
import { useLayoutEffect, useState as useState3 } from "react";
|
|
915
995
|
function useAutoConnectWallet() {
|
|
916
996
|
const { mutateAsync: connectWallet } = useConnectWallet();
|
|
@@ -925,7 +1005,7 @@ function useAutoConnectWallet() {
|
|
|
925
1005
|
useLayoutEffect(() => {
|
|
926
1006
|
setClientOnly(true);
|
|
927
1007
|
}, []);
|
|
928
|
-
const { data, isError } =
|
|
1008
|
+
const { data, isError } = useQuery2({
|
|
929
1009
|
queryKey: [
|
|
930
1010
|
"@iota/dapp-kit",
|
|
931
1011
|
"autoconnect",
|
|
@@ -990,23 +1070,6 @@ import { Transaction } from "@iota/iota-sdk/transactions";
|
|
|
990
1070
|
import { toBase64 } from "@iota/iota-sdk/utils";
|
|
991
1071
|
import { getWallets as getWallets2, ReadonlyWalletAccount, SUPPORTED_CHAINS } from "@iota/wallet-standard";
|
|
992
1072
|
import { useEffect } from "react";
|
|
993
|
-
|
|
994
|
-
// src/hooks/useIotaClient.ts
|
|
995
|
-
import { useContext as useContext2 } from "react";
|
|
996
|
-
function useIotaClientContext() {
|
|
997
|
-
const iotaClient = useContext2(IotaClientContext);
|
|
998
|
-
if (!iotaClient) {
|
|
999
|
-
throw new Error(
|
|
1000
|
-
"Could not find IotaClientContext. Ensure that you have set up the IotaClientProvider"
|
|
1001
|
-
);
|
|
1002
|
-
}
|
|
1003
|
-
return iotaClient;
|
|
1004
|
-
}
|
|
1005
|
-
function useIotaClient() {
|
|
1006
|
-
return useIotaClientContext().client;
|
|
1007
|
-
}
|
|
1008
|
-
|
|
1009
|
-
// src/hooks/wallet/useUnsafeBurnerWallet.ts
|
|
1010
1073
|
var WALLET_NAME = "Unsafe Burner Wallet";
|
|
1011
1074
|
function useUnsafeBurnerWallet(enabled) {
|
|
1012
1075
|
const iotaClient = useIotaClient();
|
|
@@ -1250,7 +1313,8 @@ function createWalletStore({
|
|
|
1250
1313
|
wallets,
|
|
1251
1314
|
storage,
|
|
1252
1315
|
storageKey,
|
|
1253
|
-
autoConnectEnabled
|
|
1316
|
+
autoConnectEnabled,
|
|
1317
|
+
chain
|
|
1254
1318
|
}) {
|
|
1255
1319
|
return createStore()(
|
|
1256
1320
|
persist(
|
|
@@ -1264,6 +1328,7 @@ function createWalletStore({
|
|
|
1264
1328
|
lastConnectedWalletName: null,
|
|
1265
1329
|
connectionStatus: "disconnected",
|
|
1266
1330
|
supportedIntents: [],
|
|
1331
|
+
chain,
|
|
1267
1332
|
setConnectionStatus(connectionStatus2) {
|
|
1268
1333
|
set(() => ({
|
|
1269
1334
|
connectionStatus: connectionStatus2
|
|
@@ -1449,14 +1514,16 @@ function WalletProvider({
|
|
|
1449
1514
|
enableUnsafeBurner = false,
|
|
1450
1515
|
autoConnect = false,
|
|
1451
1516
|
theme = lightTheme,
|
|
1452
|
-
children
|
|
1517
|
+
children,
|
|
1518
|
+
chain
|
|
1453
1519
|
}) {
|
|
1454
1520
|
const storeRef = useRef(
|
|
1455
1521
|
createWalletStore({
|
|
1456
1522
|
autoConnectEnabled: autoConnect,
|
|
1457
1523
|
wallets: getRegisteredWallets(preferredWallets, walletFilter),
|
|
1458
1524
|
storage: storage || createInMemoryStore(),
|
|
1459
|
-
storageKey
|
|
1525
|
+
storageKey,
|
|
1526
|
+
chain
|
|
1460
1527
|
})
|
|
1461
1528
|
);
|
|
1462
1529
|
return /* @__PURE__ */ jsx22(WalletContext.Provider, { value: storeRef.current, children: /* @__PURE__ */ jsxs8(
|
|
@@ -1544,8 +1611,8 @@ function useIotaClientMutation(method, options = {}) {
|
|
|
1544
1611
|
}
|
|
1545
1612
|
|
|
1546
1613
|
// src/hooks/useIotaClientQuery.ts
|
|
1547
|
-
import { queryOptions, useQuery as
|
|
1548
|
-
import { useMemo as
|
|
1614
|
+
import { queryOptions, useQuery as useQuery3, useSuspenseQuery } from "@tanstack/react-query";
|
|
1615
|
+
import { useMemo as useMemo3 } from "react";
|
|
1549
1616
|
function getIotaClientQuery({
|
|
1550
1617
|
client,
|
|
1551
1618
|
network,
|
|
@@ -1564,7 +1631,7 @@ function getIotaClientQuery({
|
|
|
1564
1631
|
function useIotaClientQuery(...args) {
|
|
1565
1632
|
const [method, params, { queryKey = [], ...options } = {}] = args;
|
|
1566
1633
|
const iotaContext = useIotaClientContext();
|
|
1567
|
-
return
|
|
1634
|
+
return useQuery3({
|
|
1568
1635
|
...options,
|
|
1569
1636
|
queryKey: [iotaContext.network, method, params, ...queryKey],
|
|
1570
1637
|
queryFn: async () => {
|
|
@@ -1577,7 +1644,7 @@ function useIotaClientQuery(...args) {
|
|
|
1577
1644
|
function useIotaClientSuspenseQuery(...args) {
|
|
1578
1645
|
const [method, params, options = {}] = args;
|
|
1579
1646
|
const iotaContext = useIotaClientContext();
|
|
1580
|
-
const query =
|
|
1647
|
+
const query = useMemo3(() => {
|
|
1581
1648
|
return getIotaClientQuery({
|
|
1582
1649
|
client: iotaContext.client,
|
|
1583
1650
|
network: iotaContext.network,
|
|
@@ -1653,12 +1720,18 @@ function useReportTransactionEffects({
|
|
|
1653
1720
|
});
|
|
1654
1721
|
}
|
|
1655
1722
|
|
|
1723
|
+
// src/hooks/wallet/useCurrentChain.ts
|
|
1724
|
+
function useCurrentChain() {
|
|
1725
|
+
return useWalletStore((state) => state.chain);
|
|
1726
|
+
}
|
|
1727
|
+
|
|
1656
1728
|
// src/hooks/wallet/useSignAndExecuteTransaction.ts
|
|
1657
1729
|
function useSignAndExecuteTransaction({
|
|
1658
1730
|
mutationKey,
|
|
1659
1731
|
execute,
|
|
1660
1732
|
...mutationOptions
|
|
1661
1733
|
} = {}) {
|
|
1734
|
+
const currentChain = useCurrentChain();
|
|
1662
1735
|
const { currentWallet, supportedIntents } = useCurrentWallet();
|
|
1663
1736
|
const currentAccount = useCurrentAccount();
|
|
1664
1737
|
const client = useIotaClient();
|
|
@@ -1691,12 +1764,12 @@ function useSignAndExecuteTransaction({
|
|
|
1691
1764
|
"No wallet account is selected to sign the transaction with."
|
|
1692
1765
|
);
|
|
1693
1766
|
}
|
|
1694
|
-
const chain = signTransactionArgs.chain ?? signerAccount?.chains[0];
|
|
1695
1767
|
if (!currentWallet.features["iota:signTransaction"]) {
|
|
1696
1768
|
throw new WalletFeatureNotSupportedError(
|
|
1697
1769
|
"This wallet doesn't support the `signTransaction` feature."
|
|
1698
1770
|
);
|
|
1699
1771
|
}
|
|
1772
|
+
const chain = signTransactionArgs.chain ?? currentChain ?? signerAccount?.chains[0];
|
|
1700
1773
|
const { signature, bytes } = await signTransaction(currentWallet, {
|
|
1701
1774
|
...signTransactionArgs,
|
|
1702
1775
|
transaction: {
|
|
@@ -1708,7 +1781,7 @@ function useSignAndExecuteTransaction({
|
|
|
1708
1781
|
}
|
|
1709
1782
|
},
|
|
1710
1783
|
account: signerAccount,
|
|
1711
|
-
chain
|
|
1784
|
+
chain
|
|
1712
1785
|
});
|
|
1713
1786
|
const result = await executeTransaction({ bytes, signature });
|
|
1714
1787
|
let effects;
|