@mysten/dapp-kit-core 1.4.0 → 1.6.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 +47 -0
- package/dist/index.d.mts +2 -2
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +117 -55
- package/dist/index.mjs.map +1 -1
- package/dist/{types-Bk3Btq_s.d.mts → types-Ceigv1q9.d.mts} +39 -11
- package/dist/types-Ceigv1q9.d.mts.map +1 -0
- package/dist/web/index.d.mts +1 -1
- package/docs/actions/sign-and-execute-transaction.md +9 -0
- package/docs/actions/sign-personal-message.md +9 -0
- package/docs/actions/sign-transaction.md +9 -0
- package/package.json +3 -3
- package/src/core/actions/connect-wallet.ts +2 -2
- package/src/core/actions/sign-and-execute-transaction.ts +25 -13
- package/src/core/actions/sign-personal-message.ts +24 -13
- package/src/core/actions/sign-transaction.ts +27 -12
- package/src/core/index.ts +22 -11
- package/src/core/initializers/autoconnect-wallet.ts +82 -15
- package/src/core/initializers/registered-wallets.ts +1 -1
- package/src/core/store.ts +21 -9
- package/src/core/types.ts +8 -0
- package/src/utils/wallets.ts +33 -4
- package/dist/types-Bk3Btq_s.d.mts.map +0 -1
|
@@ -11,40 +11,52 @@ import type {
|
|
|
11
11
|
SuiSignAndExecuteTransactionFeature,
|
|
12
12
|
SuiSignAndExecuteTransactionInput,
|
|
13
13
|
} from '@mysten/wallet-standard';
|
|
14
|
-
import {
|
|
15
|
-
import {
|
|
14
|
+
import { getWalletAccountForUiWalletAccount } from '@wallet-standard/ui-registry';
|
|
15
|
+
import type { UiWalletAccount } from '@wallet-standard/ui';
|
|
16
|
+
import { FeatureNotSupportedError } from '../../utils/errors.js';
|
|
16
17
|
import { getChain } from '../../utils/networks.js';
|
|
18
|
+
import type { Networks } from '../../utils/networks.js';
|
|
17
19
|
import { Transaction } from '@mysten/sui/transactions';
|
|
18
|
-
import { tryGetAccountFeature } from '../../utils/wallets.js';
|
|
20
|
+
import { resolveSigningAccount, tryGetAccountFeature } from '../../utils/wallets.js';
|
|
19
21
|
import { bcs } from '@mysten/sui/bcs';
|
|
20
22
|
import { fromBase64 } from '@mysten/utils';
|
|
21
23
|
import {
|
|
22
24
|
buildTransactionResult,
|
|
23
25
|
type TransactionResultWithEffects,
|
|
24
26
|
} from '../../utils/transaction-result.js';
|
|
27
|
+
import type { DAppKitCompatibleClient } from '../types.js';
|
|
25
28
|
|
|
26
|
-
export type SignAndExecuteTransactionArgs = {
|
|
29
|
+
export type SignAndExecuteTransactionArgs<TNetworks extends Networks = Networks> = {
|
|
27
30
|
transaction: Transaction | string;
|
|
31
|
+
/** The account to sign with. Defaults to the currently connected account. */
|
|
32
|
+
account?: UiWalletAccount;
|
|
33
|
+
/** The network to sign and execute against. Defaults to the dApp kit's current network. */
|
|
34
|
+
network?: TNetworks[number];
|
|
28
35
|
} & Omit<SuiSignAndExecuteTransactionInput, 'account' | 'chain' | 'transaction'>;
|
|
29
36
|
|
|
30
37
|
export type SignAndExecuteTransactionResult = TransactionResultWithEffects;
|
|
31
38
|
|
|
32
|
-
export function signAndExecuteTransactionCreator
|
|
39
|
+
export function signAndExecuteTransactionCreator<TNetworks extends Networks>(
|
|
40
|
+
{ $connection, $currentNetwork }: DAppKitStores<TNetworks>,
|
|
41
|
+
getClient: (network: TNetworks[number]) => DAppKitCompatibleClient,
|
|
42
|
+
) {
|
|
33
43
|
/**
|
|
34
44
|
* Prompts the specified wallet account to sign and execute a transaction.
|
|
35
45
|
*/
|
|
36
46
|
return async function signAndExecuteTransaction({
|
|
37
47
|
transaction,
|
|
48
|
+
account: accountOverride,
|
|
49
|
+
network,
|
|
38
50
|
...standardArgs
|
|
39
|
-
}: SignAndExecuteTransactionArgs): Promise<SignAndExecuteTransactionResult> {
|
|
40
|
-
const
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
}
|
|
51
|
+
}: SignAndExecuteTransactionArgs<TNetworks>): Promise<SignAndExecuteTransactionResult> {
|
|
52
|
+
const connection = $connection.get();
|
|
53
|
+
const account = resolveSigningAccount(connection, accountOverride);
|
|
54
|
+
const supportedIntents = [...connection.supportedIntents];
|
|
44
55
|
|
|
45
56
|
const underlyingAccount = getWalletAccountForUiWalletAccount(account);
|
|
46
|
-
const
|
|
47
|
-
const
|
|
57
|
+
const resolvedNetwork = network ?? $currentNetwork.get();
|
|
58
|
+
const suiClient = getClient(resolvedNetwork);
|
|
59
|
+
const chain = getChain(resolvedNetwork);
|
|
48
60
|
|
|
49
61
|
const transactionWrapper = {
|
|
50
62
|
toJSON: async () => {
|
|
@@ -91,7 +103,7 @@ export function signAndExecuteTransactionCreator({ $connection, $currentClient }
|
|
|
91
103
|
const transactionBlock = Transaction.from(await transactionWrapper.toJSON());
|
|
92
104
|
const { digest, rawEffects, rawTransaction } =
|
|
93
105
|
await signAndExecuteTransactionBlockFeature.signAndExecuteTransactionBlock({
|
|
94
|
-
account,
|
|
106
|
+
account: underlyingAccount,
|
|
95
107
|
chain,
|
|
96
108
|
transactionBlock,
|
|
97
109
|
options: {
|
|
@@ -7,28 +7,39 @@ import type {
|
|
|
7
7
|
SuiSignPersonalMessageFeature,
|
|
8
8
|
SuiSignPersonalMessageInput,
|
|
9
9
|
} from '@mysten/wallet-standard';
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
10
|
+
import { getWalletAccountForUiWalletAccount } from '@wallet-standard/ui-registry';
|
|
11
|
+
import type { UiWalletAccount } from '@wallet-standard/ui';
|
|
12
12
|
import { getChain } from '../../utils/networks.js';
|
|
13
|
-
import {
|
|
13
|
+
import type { Networks } from '../../utils/networks.js';
|
|
14
|
+
import { getAccountFeature, resolveSigningAccount } from '../../utils/wallets.js';
|
|
14
15
|
|
|
15
|
-
export type SignPersonalMessageArgs =
|
|
16
|
+
export type SignPersonalMessageArgs<TNetworks extends Networks = Networks> = {
|
|
17
|
+
/** The account to sign with. Defaults to the currently connected account. */
|
|
18
|
+
account?: UiWalletAccount;
|
|
19
|
+
/** The network to sign against. Defaults to the dApp kit's current network. */
|
|
20
|
+
network?: TNetworks[number];
|
|
21
|
+
} & Omit<SuiSignPersonalMessageInput, 'account' | 'chain'>;
|
|
16
22
|
|
|
17
|
-
export function signPersonalMessageCreator
|
|
23
|
+
export function signPersonalMessageCreator<TNetworks extends Networks>({
|
|
24
|
+
$connection,
|
|
25
|
+
$currentNetwork,
|
|
26
|
+
}: DAppKitStores<TNetworks>) {
|
|
18
27
|
/**
|
|
19
28
|
* Prompts the specified wallet account to sign a personal message.
|
|
20
29
|
*/
|
|
21
|
-
return async function signPersonalMessage({
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
30
|
+
return async function signPersonalMessage({
|
|
31
|
+
account: accountOverride,
|
|
32
|
+
network,
|
|
33
|
+
...standardArgs
|
|
34
|
+
}: SignPersonalMessageArgs<TNetworks>) {
|
|
35
|
+
const connection = $connection.get();
|
|
36
|
+
const account = resolveSigningAccount(connection, accountOverride);
|
|
26
37
|
|
|
27
|
-
const
|
|
28
|
-
const chain = getChain(
|
|
38
|
+
const resolvedNetwork = network ?? $currentNetwork.get();
|
|
39
|
+
const chain = getChain(resolvedNetwork);
|
|
29
40
|
|
|
30
41
|
const signPersonalMessageFeature = getAccountFeature({
|
|
31
|
-
account
|
|
42
|
+
account,
|
|
32
43
|
chain,
|
|
33
44
|
featureName: SuiSignPersonalMessage,
|
|
34
45
|
}) as SuiSignPersonalMessageFeature[typeof SuiSignPersonalMessage];
|
|
@@ -8,29 +8,44 @@ import type {
|
|
|
8
8
|
SuiSignTransactionFeature,
|
|
9
9
|
SuiSignTransactionInput,
|
|
10
10
|
} from '@mysten/wallet-standard';
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
11
|
+
import { getWalletAccountForUiWalletAccount } from '@wallet-standard/ui-registry';
|
|
12
|
+
import type { UiWalletAccount } from '@wallet-standard/ui';
|
|
13
|
+
import { FeatureNotSupportedError } from '../../utils/errors.js';
|
|
13
14
|
import { getChain } from '../../utils/networks.js';
|
|
15
|
+
import type { Networks } from '../../utils/networks.js';
|
|
14
16
|
import { Transaction } from '@mysten/sui/transactions';
|
|
15
|
-
import { tryGetAccountFeature } from '../../utils/wallets.js';
|
|
17
|
+
import { resolveSigningAccount, tryGetAccountFeature } from '../../utils/wallets.js';
|
|
18
|
+
import type { DAppKitCompatibleClient } from '../types.js';
|
|
16
19
|
|
|
17
|
-
export type SignTransactionArgs = {
|
|
20
|
+
export type SignTransactionArgs<TNetworks extends Networks = Networks> = {
|
|
18
21
|
transaction: Transaction | string;
|
|
22
|
+
/** The account to sign with. Defaults to the currently connected account. */
|
|
23
|
+
account?: UiWalletAccount;
|
|
24
|
+
/** The network to sign against. Defaults to the dApp kit's current network. */
|
|
25
|
+
network?: TNetworks[number];
|
|
19
26
|
} & Omit<SuiSignTransactionInput, 'account' | 'chain' | 'transaction'>;
|
|
20
27
|
|
|
21
|
-
export function signTransactionCreator
|
|
28
|
+
export function signTransactionCreator<TNetworks extends Networks>(
|
|
29
|
+
{ $connection, $currentNetwork }: DAppKitStores<TNetworks>,
|
|
30
|
+
getClient: (network: TNetworks[number]) => DAppKitCompatibleClient,
|
|
31
|
+
) {
|
|
22
32
|
/**
|
|
23
33
|
* Prompts the specified wallet account to sign a transaction.
|
|
24
34
|
*/
|
|
25
|
-
return async function signTransaction({
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
35
|
+
return async function signTransaction({
|
|
36
|
+
transaction,
|
|
37
|
+
account: accountOverride,
|
|
38
|
+
network,
|
|
39
|
+
...standardArgs
|
|
40
|
+
}: SignTransactionArgs<TNetworks>) {
|
|
41
|
+
const connection = $connection.get();
|
|
42
|
+
const account = resolveSigningAccount(connection, accountOverride);
|
|
43
|
+
const supportedIntents = [...connection.supportedIntents];
|
|
30
44
|
|
|
31
45
|
const underlyingAccount = getWalletAccountForUiWalletAccount(account);
|
|
32
|
-
const
|
|
33
|
-
const
|
|
46
|
+
const resolvedNetwork = network ?? $currentNetwork.get();
|
|
47
|
+
const suiClient = getClient(resolvedNetwork);
|
|
48
|
+
const chain = getChain(resolvedNetwork);
|
|
34
49
|
|
|
35
50
|
const transactionWrapper = {
|
|
36
51
|
toJSON: async () => {
|
package/src/core/index.ts
CHANGED
|
@@ -39,11 +39,11 @@ export type DAppKit<
|
|
|
39
39
|
> = {
|
|
40
40
|
networks: TNetworks;
|
|
41
41
|
getClient: (network?: TNetworks[number]) => Client;
|
|
42
|
-
signTransaction: (args: SignTransactionArgs) => Promise<SignedTransaction>;
|
|
42
|
+
signTransaction: (args: SignTransactionArgs<TNetworks>) => Promise<SignedTransaction>;
|
|
43
43
|
signAndExecuteTransaction: (
|
|
44
|
-
args: SignAndExecuteTransactionArgs
|
|
44
|
+
args: SignAndExecuteTransactionArgs<TNetworks>,
|
|
45
45
|
) => Promise<SignAndExecuteTransactionResult>;
|
|
46
|
-
signPersonalMessage: (args: SignPersonalMessageArgs) => Promise<SignedPersonalMessage>;
|
|
46
|
+
signPersonalMessage: (args: SignPersonalMessageArgs<TNetworks>) => Promise<SignedPersonalMessage>;
|
|
47
47
|
connectWallet: (args: ConnectWalletArgs) => Promise<{
|
|
48
48
|
accounts: UiWalletAccount[];
|
|
49
49
|
}>;
|
|
@@ -71,9 +71,13 @@ export function createDAppKit<
|
|
|
71
71
|
storage = getDefaultStorage(),
|
|
72
72
|
storageKey = DEFAULT_STORAGE_KEY,
|
|
73
73
|
walletInitializers = [],
|
|
74
|
+
autoConnectTimeout = 5000,
|
|
74
75
|
}: CreateDAppKitOptions<TNetworks, Client>): DAppKit<TNetworks, Client> {
|
|
75
76
|
const networkConfig = createNetworkConfig(networks, createClient);
|
|
76
|
-
const stores = createStores({
|
|
77
|
+
const stores = createStores<TNetworks, Client>({
|
|
78
|
+
defaultNetwork,
|
|
79
|
+
getClient: networkConfig.getClient,
|
|
80
|
+
});
|
|
77
81
|
|
|
78
82
|
function getClient<T extends TNetworks[number]>(network?: TNetworks[number] | T): Client {
|
|
79
83
|
return network ? networkConfig.getClient(network) : stores.$currentClient.get();
|
|
@@ -84,11 +88,7 @@ export function createDAppKit<
|
|
|
84
88
|
syncRegisteredWallets(stores);
|
|
85
89
|
manageWalletConnection(stores);
|
|
86
90
|
|
|
87
|
-
|
|
88
|
-
autoConnectWallet({ networks, stores, storageKey, storage });
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
registerAdditionalWallets(
|
|
91
|
+
const walletsRegistered = registerAdditionalWallets(
|
|
92
92
|
[
|
|
93
93
|
...walletInitializers,
|
|
94
94
|
...(enableBurnerWallet ? [unsafeBurnerWalletInitializer()] : []),
|
|
@@ -97,11 +97,22 @@ export function createDAppKit<
|
|
|
97
97
|
{ networks, getClient },
|
|
98
98
|
);
|
|
99
99
|
|
|
100
|
+
if (autoConnect) {
|
|
101
|
+
autoConnectWallet({
|
|
102
|
+
networks,
|
|
103
|
+
stores,
|
|
104
|
+
storageKey,
|
|
105
|
+
storage,
|
|
106
|
+
walletsRegistered,
|
|
107
|
+
timeout: autoConnectTimeout,
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
|
|
100
111
|
return {
|
|
101
112
|
networks,
|
|
102
113
|
getClient,
|
|
103
|
-
signTransaction: signTransactionCreator(stores),
|
|
104
|
-
signAndExecuteTransaction: signAndExecuteTransactionCreator(stores),
|
|
114
|
+
signTransaction: signTransactionCreator(stores, networkConfig.getClient),
|
|
115
|
+
signAndExecuteTransaction: signAndExecuteTransactionCreator(stores, networkConfig.getClient),
|
|
105
116
|
signPersonalMessage: signPersonalMessageCreator(stores),
|
|
106
117
|
connectWallet: connectWalletCreator(stores, networks, { storage, storageKey }),
|
|
107
118
|
disconnectWallet: disconnectWalletCreator(stores, { storage, storageKey }),
|
|
@@ -15,47 +15,114 @@ import type { Networks } from '../../utils/networks.js';
|
|
|
15
15
|
|
|
16
16
|
/**
|
|
17
17
|
* Attempts to connect to a previously authorized wallet account on mount and when new wallets are registered.
|
|
18
|
+
*
|
|
19
|
+
* Enters `reconnecting` on mount when a persisted session exists, so consumers can tell a
|
|
20
|
+
* restore apart from a logged-out state while the saved wallet is still resolving. Settles
|
|
21
|
+
* to `disconnected` once every initializer has registered and `timeout` has elapsed without
|
|
22
|
+
* a restore, but never interrupts an in-flight restore and keeps listening afterwards.
|
|
18
23
|
*/
|
|
19
24
|
export function autoConnectWallet({
|
|
20
25
|
networks,
|
|
21
26
|
stores: { $baseConnection, $compatibleWallets },
|
|
22
27
|
storage,
|
|
23
28
|
storageKey,
|
|
29
|
+
walletsRegistered,
|
|
30
|
+
timeout,
|
|
24
31
|
}: {
|
|
25
32
|
networks: Networks;
|
|
26
33
|
stores: DAppKitStores;
|
|
27
34
|
storage: StateStorage;
|
|
28
35
|
storageKey: string;
|
|
36
|
+
/** Resolves once all configured wallet initializers have finished registering. */
|
|
37
|
+
walletsRegistered: Promise<unknown>;
|
|
38
|
+
/** Grace period (ms) to keep waiting for a saved wallet to register before giving up. */
|
|
39
|
+
timeout: number;
|
|
29
40
|
}) {
|
|
30
41
|
onMount($compatibleWallets, () => {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
42
|
+
let done = false;
|
|
43
|
+
let unsubscribe: (() => void) | undefined;
|
|
44
|
+
|
|
45
|
+
const stop = () => {
|
|
46
|
+
done = true;
|
|
47
|
+
unsubscribe?.();
|
|
48
|
+
};
|
|
37
49
|
|
|
38
|
-
|
|
39
|
-
|
|
50
|
+
const tryRestore = (wallets: readonly UiWallet[]) =>
|
|
51
|
+
task(async () => {
|
|
52
|
+
if (done) return;
|
|
40
53
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
54
|
+
// A manual connect takes precedence over auto-connect.
|
|
55
|
+
const { status } = $baseConnection.get();
|
|
56
|
+
if (status !== 'disconnected' && status !== 'reconnecting') {
|
|
57
|
+
stop();
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
const savedWalletAccount = await getSavedWalletAccount({
|
|
62
|
+
networks,
|
|
63
|
+
storage,
|
|
64
|
+
storageKey,
|
|
65
|
+
wallets,
|
|
48
66
|
});
|
|
49
67
|
|
|
68
|
+
if (done) return;
|
|
69
|
+
|
|
50
70
|
if (savedWalletAccount) {
|
|
51
71
|
$baseConnection.set({
|
|
52
72
|
status: 'connected',
|
|
53
73
|
currentAccount: savedWalletAccount.account,
|
|
54
74
|
supportedIntents: savedWalletAccount.supportedIntents,
|
|
55
75
|
});
|
|
76
|
+
stop();
|
|
56
77
|
}
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
unsubscribe = $compatibleWallets.subscribe(
|
|
81
|
+
(wallets, oldWallets: readonly UiWallet[] | undefined) => {
|
|
82
|
+
// subscribe on a computed store may fire with undefined due to nanostores
|
|
83
|
+
// reading the underlying atom's uninitialized value instead of computing it.
|
|
84
|
+
if (!wallets) return;
|
|
85
|
+
if (oldWallets && oldWallets.length > wallets.length) return;
|
|
86
|
+
void tryRestore(wallets);
|
|
57
87
|
},
|
|
58
88
|
);
|
|
89
|
+
|
|
90
|
+
void task(async () => {
|
|
91
|
+
const hasSavedSession = Boolean(await storage.getItem(storageKey));
|
|
92
|
+
if (done) return;
|
|
93
|
+
|
|
94
|
+
if (!hasSavedSession) {
|
|
95
|
+
stop();
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
if ($baseConnection.get().status === 'disconnected') {
|
|
100
|
+
$baseConnection.set({
|
|
101
|
+
status: 'reconnecting',
|
|
102
|
+
currentAccount: null,
|
|
103
|
+
supportedIntents: [],
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
// Give every initializer, plus a grace period for late-registering wallets,
|
|
108
|
+
// a chance to register before making a final attempt and giving up.
|
|
109
|
+
const gracePeriod = new Promise((resolve) => setTimeout(resolve, timeout));
|
|
110
|
+
await Promise.all([walletsRegistered.catch(() => {}), gracePeriod]);
|
|
111
|
+
if (done) return;
|
|
112
|
+
|
|
113
|
+
await tryRestore($compatibleWallets.get() ?? []);
|
|
114
|
+
if (done) return;
|
|
115
|
+
|
|
116
|
+
// Settle the signal so consumers aren't stuck, but keep listening so a
|
|
117
|
+
// very-late registration can still restore the session.
|
|
118
|
+
if ($baseConnection.get().status === 'reconnecting') {
|
|
119
|
+
$baseConnection.set({ status: 'disconnected', currentAccount: null });
|
|
120
|
+
}
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
// `stop()` (not just `unsubscribe()`) so an in-flight eager task or restore can't
|
|
124
|
+
// mutate the shared store after teardown (e.g. a React StrictMode double-mount).
|
|
125
|
+
return stop;
|
|
59
126
|
});
|
|
60
127
|
}
|
|
61
128
|
|
|
@@ -5,7 +5,7 @@ import { getWallets, StandardEvents } from '@mysten/wallet-standard';
|
|
|
5
5
|
import { onMount } from 'nanostores';
|
|
6
6
|
import type { DAppKitStores } from '../store.js';
|
|
7
7
|
|
|
8
|
-
import {
|
|
8
|
+
import { getOrCreateUiWalletForStandardWallet } from '@wallet-standard/ui-registry';
|
|
9
9
|
import type { StandardEventsFeature, Wallet, WalletWithFeatures } from '@mysten/wallet-standard';
|
|
10
10
|
|
|
11
11
|
/**
|
package/src/core/store.ts
CHANGED
|
@@ -16,7 +16,13 @@ type InternalWalletConnection =
|
|
|
16
16
|
currentAccount: null;
|
|
17
17
|
}
|
|
18
18
|
| {
|
|
19
|
-
|
|
19
|
+
// `null` account: an initial restore enters this state before the saved wallet registers.
|
|
20
|
+
status: 'reconnecting';
|
|
21
|
+
currentAccount: UiWalletAccount | null;
|
|
22
|
+
supportedIntents: string[];
|
|
23
|
+
}
|
|
24
|
+
| {
|
|
25
|
+
status: 'connected';
|
|
20
26
|
currentAccount: UiWalletAccount;
|
|
21
27
|
supportedIntents: string[];
|
|
22
28
|
};
|
|
@@ -114,24 +120,30 @@ export function createStores<
|
|
|
114
120
|
isDisconnected: false,
|
|
115
121
|
} as const;
|
|
116
122
|
case 'reconnecting': {
|
|
117
|
-
const
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
123
|
+
const { currentAccount } = connection;
|
|
124
|
+
const wallet = currentAccount
|
|
125
|
+
? (wallets.find((w) => uiWalletAccountBelongsToUiWallet(currentAccount, w)) ?? null)
|
|
126
|
+
: null;
|
|
127
|
+
|
|
128
|
+
// Unlike `connected`, keep reporting `isReconnecting` even before the
|
|
129
|
+
// target wallet/account resolves, so an initial restore is distinguishable
|
|
130
|
+
// from a logged-out state.
|
|
131
|
+
if (!currentAccount || !wallet) {
|
|
121
132
|
return {
|
|
122
133
|
wallet: null,
|
|
123
134
|
account: null,
|
|
124
|
-
status:
|
|
135
|
+
status: connection.status,
|
|
125
136
|
supportedIntents: [],
|
|
126
137
|
isConnected: false,
|
|
127
138
|
isConnecting: false,
|
|
128
|
-
isReconnecting:
|
|
129
|
-
isDisconnected:
|
|
139
|
+
isReconnecting: true,
|
|
140
|
+
isDisconnected: false,
|
|
130
141
|
} as const;
|
|
131
142
|
}
|
|
143
|
+
|
|
132
144
|
return {
|
|
133
145
|
wallet,
|
|
134
|
-
account:
|
|
146
|
+
account: currentAccount,
|
|
135
147
|
status: connection.status,
|
|
136
148
|
supportedIntents: connection.supportedIntents,
|
|
137
149
|
isConnected: false,
|
package/src/core/types.ts
CHANGED
|
@@ -38,6 +38,14 @@ export type CreateDAppKitOptions<
|
|
|
38
38
|
*/
|
|
39
39
|
autoConnect?: boolean;
|
|
40
40
|
|
|
41
|
+
/**
|
|
42
|
+
* The grace period, in milliseconds, to wait for a previously connected wallet to
|
|
43
|
+
* register during auto-connect before treating the saved session as unavailable. An
|
|
44
|
+
* in-progress restore is never interrupted by this.
|
|
45
|
+
* @default `5000`
|
|
46
|
+
*/
|
|
47
|
+
autoConnectTimeout?: number;
|
|
48
|
+
|
|
41
49
|
/**
|
|
42
50
|
* A list of networks supported by the application.
|
|
43
51
|
*/
|
package/src/utils/wallets.ts
CHANGED
|
@@ -9,10 +9,15 @@ import {
|
|
|
9
9
|
WALLET_STANDARD_ERROR__FEATURES__WALLET_ACCOUNT_CHAIN_UNSUPPORTED,
|
|
10
10
|
WalletStandardError,
|
|
11
11
|
} from '@mysten/wallet-standard';
|
|
12
|
-
import type { UiWalletAccount, UiWalletHandle } from '@wallet-standard/ui';
|
|
13
|
-
import { getWalletAccountFeature } from '@wallet-standard/ui';
|
|
14
|
-
import {
|
|
15
|
-
import {
|
|
12
|
+
import type { UiWallet, UiWalletAccount, UiWalletHandle } from '@wallet-standard/ui';
|
|
13
|
+
import { getWalletAccountFeature, uiWalletAccountBelongsToUiWallet } from '@wallet-standard/ui';
|
|
14
|
+
import { getWalletForHandle } from '@wallet-standard/ui-registry';
|
|
15
|
+
import {
|
|
16
|
+
ChainNotSupportedError,
|
|
17
|
+
FeatureNotSupportedError,
|
|
18
|
+
WalletAccountNotFoundError,
|
|
19
|
+
WalletNotConnectedError,
|
|
20
|
+
} from './errors.js';
|
|
16
21
|
|
|
17
22
|
export const requiredWalletFeatures = [StandardConnect, StandardEvents] as const;
|
|
18
23
|
|
|
@@ -23,6 +28,30 @@ export function getWalletUniqueIdentifier(walletHandle: UiWalletHandle) {
|
|
|
23
28
|
return underlyingWallet.id ?? underlyingWallet.name;
|
|
24
29
|
}
|
|
25
30
|
|
|
31
|
+
/**
|
|
32
|
+
* Resolves the account a signing action should use, defaulting to the currently connected account.
|
|
33
|
+
*
|
|
34
|
+
* Enforces that the wallet, account, and (downstream) network all stay compatible: a wallet must be
|
|
35
|
+
* connected, and any explicitly provided account must belong to that connected wallet. The
|
|
36
|
+
* account-supports-network check happens later in {@link getAccountFeature} via `account.chains`.
|
|
37
|
+
*/
|
|
38
|
+
export function resolveSigningAccount(
|
|
39
|
+
connection: { wallet: UiWallet | null; account: UiWalletAccount | null },
|
|
40
|
+
account?: UiWalletAccount,
|
|
41
|
+
): UiWalletAccount {
|
|
42
|
+
if (!connection.wallet || !connection.account) {
|
|
43
|
+
throw new WalletNotConnectedError('No wallet is connected.');
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
if (account && !uiWalletAccountBelongsToUiWallet(account, connection.wallet)) {
|
|
47
|
+
throw new WalletAccountNotFoundError(
|
|
48
|
+
`No account with address ${account.address} is connected to ${connection.wallet.name}.`,
|
|
49
|
+
);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
return account ?? connection.account;
|
|
53
|
+
}
|
|
54
|
+
|
|
26
55
|
export function getAccountFeature<TAccount extends UiWalletAccount>({
|
|
27
56
|
account,
|
|
28
57
|
featureName,
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"types-Bk3Btq_s.d.mts","names":[],"sources":["../src/utils/storage.ts","../src/wallets/index.ts","../src/core/types.ts","../src/utils/networks.ts","../src/core/store.ts","../src/core/actions/connect-wallet.ts","../src/core/actions/switch-account.ts","../src/core/actions/sign-personal-message.ts","../src/utils/transaction-result.ts","../src/core/actions/sign-and-execute-transaction.ts","../src/core/actions/sign-transaction.ts","../src/core/index.ts","../src/types.ts"],"mappings":";;;;;;;;KAMY,YAAA;EACX,OAAA,GAAU,IAAA,6BAAiC,OAAA;EAC3C,OAAA,GAAU,IAAA,UAAc,KAAA,uBAA4B,OAAA;EACpD,UAAA,GAAa,IAAA,uBAA2B,OAAA;AAAA;;;KCD7B,cAAA;EACX,QAAA,EAAU,QAAA;EACV,SAAA,GAAY,OAAA,GAAU,QAAA,aAAqB,uBAAA;AAAA;AAAA,KAGhC,gBAAA;EACX,UAAA;AAAA;AAAA,KAGW,iBAAA;EACX,EAAA;EACA,UAAA,CAAW,KAAA,EAAO,cAAA,GAAiB,gBAAA,GAAmB,OAAA,CAAQ,gBAAA;AAAA;;;KCXnD,uBAAA,GAA0B,iBAAA;AAAA,KAE1B,iBAAA;;;AFJZ;;EESC,OAAA;EFR2C;;;;EEc3C,MAAA;EFdA;;;;EEoBA,cAAA;AAAA;AAAA,KAGW,oBAAA,mBACO,QAAA,iBACH,uBAAA;EF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