@solana/react-hooks 0.2.5 → 0.5.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/README.md +14 -2
- package/dist/index.browser.cjs +233 -496
- package/dist/index.browser.cjs.map +1 -1
- package/dist/index.browser.mjs +224 -483
- package/dist/index.browser.mjs.map +1 -1
- package/dist/index.native.mjs +224 -483
- package/dist/index.native.mjs.map +1 -1
- package/dist/index.node.cjs +233 -496
- package/dist/index.node.cjs.map +1 -1
- package/dist/index.node.mjs +224 -483
- package/dist/index.node.mjs.map +1 -1
- package/dist/types/QueryProvider.d.ts.map +1 -1
- package/dist/types/SolanaProvider.d.ts.map +1 -1
- package/dist/types/context.d.ts +3 -0
- package/dist/types/context.d.ts.map +1 -1
- package/dist/types/hooks.d.ts +59 -14
- package/dist/types/hooks.d.ts.map +1 -1
- package/dist/types/index.d.ts +9 -3
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/query.d.ts +2 -1
- package/dist/types/query.d.ts.map +1 -1
- package/dist/types/queryHooks.d.ts +18 -10
- package/dist/types/queryHooks.d.ts.map +1 -1
- package/dist/types/queryKeys.d.ts +8 -0
- package/dist/types/queryKeys.d.ts.map +1 -0
- package/dist/types/ui.d.ts +10 -8
- package/dist/types/ui.d.ts.map +1 -1
- package/dist/types/useClientStore.d.ts +4 -3
- package/dist/types/useClientStore.d.ts.map +1 -1
- package/package.json +2 -7
- package/dist/types/walletStandardHooks.d.ts +0 -78
- package/dist/types/walletStandardHooks.d.ts.map +0 -1
package/dist/index.node.mjs
CHANGED
|
@@ -1,18 +1,9 @@
|
|
|
1
|
-
import { createClient, toAddress, toAddressString, stableStringify, createSolTransferController, createSplTransferController,
|
|
1
|
+
import { createClient, toAddress, toAddressString, stableStringify, createSolTransferController, createSplTransferController, createTransactionPoolController, createInitialAsyncState, createAsyncState, normalizeSignature, SIGNATURE_STATUS_TIMEOUT_MS, deriveConfirmationStatus, confirmationMeetsCommitment, deserializeSolanaState, subscribeSolanaState, serializeSolanaState } from '@solana/client';
|
|
2
2
|
import { createContext, useMemo, useEffect, useContext, useCallback, useRef, useSyncExternalStore, useState } from 'react';
|
|
3
3
|
import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
|
|
4
4
|
import useSWR, { SWRConfig } from 'swr';
|
|
5
5
|
import { useStore } from 'zustand';
|
|
6
6
|
import { getBase64EncodedWireTransaction } from '@solana/kit';
|
|
7
|
-
import { address } from '@solana/addresses';
|
|
8
|
-
import { SolanaError, SOLANA_ERROR__SIGNER__WALLET_MULTISIGN_UNIMPLEMENTED } from '@solana/errors';
|
|
9
|
-
import { getAbortablePromise } from '@solana/promises';
|
|
10
|
-
import { getCompiledTransactionMessageDecoder } from '@solana/transaction-messages';
|
|
11
|
-
import { getTransactionCodec, assertIsTransactionWithinSizeLimit, getTransactionLifetimeConstraintFromCompiledTransactionMessage, getTransactionEncoder } from '@solana/transactions';
|
|
12
|
-
import { SolanaSignAndSendTransaction, SolanaSignIn, SolanaSignMessage, SolanaSignTransaction } from '@solana/wallet-standard-features';
|
|
13
|
-
import { WalletStandardError, WALLET_STANDARD_ERROR__FEATURES__WALLET_ACCOUNT_CHAIN_UNSUPPORTED } from '@wallet-standard/errors';
|
|
14
|
-
import { getWalletAccountFeature, getWalletFeature } from '@wallet-standard/ui';
|
|
15
|
-
import { getWalletAccountForUiWalletAccount_DO_NOT_USE_OR_YOU_WILL_BE_FIRED, getWalletForHandle_DO_NOT_USE_OR_YOU_WILL_BE_FIRED, getOrCreateUiWalletAccountForStandardWalletAccount_DO_NOT_USE_OR_YOU_WILL_BE_FIRED } from '@wallet-standard/ui-registry';
|
|
16
7
|
|
|
17
8
|
var __defProp = Object.defineProperty;
|
|
18
9
|
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
@@ -65,11 +56,11 @@ var QUERY_NAMESPACE = "@solana/react-hooks";
|
|
|
65
56
|
function useSolanaRpcQuery(scope, args, fetcher, options = {}) {
|
|
66
57
|
const client = useSolanaClient();
|
|
67
58
|
const cluster = useClientStore((state) => state.cluster);
|
|
68
|
-
const { disabled = false,
|
|
59
|
+
const { disabled = false, swr } = options;
|
|
69
60
|
const providerSuspensePreference = useQuerySuspensePreference();
|
|
70
61
|
const suspenseEnabled = !disabled && Boolean(providerSuspensePreference);
|
|
71
62
|
const swrOptions = {
|
|
72
|
-
...
|
|
63
|
+
...swr ?? {},
|
|
73
64
|
suspense: suspenseEnabled
|
|
74
65
|
};
|
|
75
66
|
const key = useMemo(() => {
|
|
@@ -78,59 +69,105 @@ function useSolanaRpcQuery(scope, args, fetcher, options = {}) {
|
|
|
78
69
|
}
|
|
79
70
|
return [QUERY_NAMESPACE, scope, cluster.endpoint, cluster.commitment, ...args];
|
|
80
71
|
}, [cluster.commitment, cluster.endpoint, args, scope, disabled]);
|
|
81
|
-
const
|
|
72
|
+
const swrResponse = useSWR(key, () => fetcher(client), swrOptions);
|
|
82
73
|
const [dataUpdatedAt, setDataUpdatedAt] = useState(
|
|
83
|
-
() =>
|
|
74
|
+
() => swrResponse.data !== void 0 ? Date.now() : void 0
|
|
84
75
|
);
|
|
85
76
|
useEffect(() => {
|
|
86
|
-
if (
|
|
77
|
+
if (swrResponse.data !== void 0) {
|
|
87
78
|
setDataUpdatedAt(Date.now());
|
|
88
79
|
}
|
|
89
|
-
}, [
|
|
90
|
-
const status =
|
|
91
|
-
const refresh = useCallback(() =>
|
|
80
|
+
}, [swrResponse.data]);
|
|
81
|
+
const status = swrResponse.error ? "error" : swrResponse.isLoading ? "loading" : swrResponse.data !== void 0 ? "success" : "idle";
|
|
82
|
+
const refresh = useCallback(() => swrResponse.mutate(void 0, { revalidate: true }), [swrResponse.mutate]);
|
|
92
83
|
return {
|
|
93
|
-
data:
|
|
84
|
+
data: swrResponse.data,
|
|
94
85
|
dataUpdatedAt,
|
|
95
|
-
error:
|
|
86
|
+
error: swrResponse.error ?? null,
|
|
96
87
|
isError: status === "error",
|
|
97
|
-
isLoading:
|
|
88
|
+
isLoading: swrResponse.isLoading,
|
|
98
89
|
isSuccess: status === "success",
|
|
99
|
-
isValidating:
|
|
100
|
-
mutate:
|
|
90
|
+
isValidating: swrResponse.isValidating,
|
|
91
|
+
mutate: swrResponse.mutate,
|
|
101
92
|
refresh,
|
|
102
93
|
status
|
|
103
94
|
};
|
|
104
95
|
}
|
|
105
96
|
__name(useSolanaRpcQuery, "useSolanaRpcQuery");
|
|
97
|
+
function getLatestBlockhashKey(params = {}) {
|
|
98
|
+
const { commitment = null, minContextSlot = null } = params;
|
|
99
|
+
return ["latestBlockhash", commitment, normalizeBigint(minContextSlot)];
|
|
100
|
+
}
|
|
101
|
+
__name(getLatestBlockhashKey, "getLatestBlockhashKey");
|
|
102
|
+
function getProgramAccountsKey(params = {}) {
|
|
103
|
+
const { programAddress, config } = params;
|
|
104
|
+
const address = programAddress ? toAddress(programAddress) : void 0;
|
|
105
|
+
const addressKey = address ? toAddressString(address) : null;
|
|
106
|
+
const configKey = stableStringify(config ?? null);
|
|
107
|
+
return ["programAccounts", addressKey, configKey];
|
|
108
|
+
}
|
|
109
|
+
__name(getProgramAccountsKey, "getProgramAccountsKey");
|
|
110
|
+
function getSimulateTransactionKey(params = {}) {
|
|
111
|
+
const { transaction, config } = params;
|
|
112
|
+
const wire = transaction ? normalizeWire(transaction) : null;
|
|
113
|
+
const configKey = stableStringify(config ?? null);
|
|
114
|
+
return ["simulateTransaction", wire, configKey];
|
|
115
|
+
}
|
|
116
|
+
__name(getSimulateTransactionKey, "getSimulateTransactionKey");
|
|
117
|
+
function getSignatureStatusKey(params = {}) {
|
|
118
|
+
const { config, signature } = params;
|
|
119
|
+
const signatureKey = signature?.toString() ?? null;
|
|
120
|
+
const configKey = JSON.stringify(config ?? null);
|
|
121
|
+
return ["signatureStatus", signatureKey, configKey];
|
|
122
|
+
}
|
|
123
|
+
__name(getSignatureStatusKey, "getSignatureStatusKey");
|
|
124
|
+
function normalizeBigint(value) {
|
|
125
|
+
if (value === void 0 || value === null) return null;
|
|
126
|
+
return typeof value === "bigint" ? value : BigInt(Math.floor(value));
|
|
127
|
+
}
|
|
128
|
+
__name(normalizeBigint, "normalizeBigint");
|
|
129
|
+
function normalizeWire(input) {
|
|
130
|
+
if (!input) return null;
|
|
131
|
+
if (typeof input === "string") {
|
|
132
|
+
return input;
|
|
133
|
+
}
|
|
134
|
+
return getBase64EncodedWireTransaction(input);
|
|
135
|
+
}
|
|
136
|
+
__name(normalizeWire, "normalizeWire");
|
|
137
|
+
|
|
138
|
+
// src/queryHooks.ts
|
|
106
139
|
var DEFAULT_BLOCKHASH_REFRESH_INTERVAL = 3e4;
|
|
107
|
-
function useLatestBlockhash(options) {
|
|
108
|
-
const {
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
}
|
|
115
|
-
const keyArgs = useMemo(
|
|
116
|
-
() => [commitment ?? null, normalizedMinContextSlot ?? null],
|
|
117
|
-
[commitment, normalizedMinContextSlot]
|
|
118
|
-
);
|
|
140
|
+
function useLatestBlockhash(options = {}) {
|
|
141
|
+
const {
|
|
142
|
+
commitment,
|
|
143
|
+
minContextSlot,
|
|
144
|
+
refreshInterval = DEFAULT_BLOCKHASH_REFRESH_INTERVAL,
|
|
145
|
+
disabled = false,
|
|
146
|
+
swr
|
|
147
|
+
} = options;
|
|
119
148
|
const fetcher = useCallback(
|
|
120
149
|
async (client) => {
|
|
121
150
|
const fallbackCommitment = commitment ?? client.store.getState().cluster.commitment;
|
|
122
151
|
const plan = client.runtime.rpc.getLatestBlockhash({
|
|
123
152
|
commitment: fallbackCommitment,
|
|
124
|
-
minContextSlot:
|
|
153
|
+
minContextSlot: normalizeMinContextSlot(minContextSlot)
|
|
125
154
|
});
|
|
126
155
|
return plan.send({ abortSignal: AbortSignal.timeout(15e3) });
|
|
127
156
|
},
|
|
128
|
-
[commitment,
|
|
157
|
+
[commitment, minContextSlot]
|
|
158
|
+
);
|
|
159
|
+
const query = useSolanaRpcQuery(
|
|
160
|
+
"latestBlockhash",
|
|
161
|
+
getLatestBlockhashKey(options),
|
|
162
|
+
fetcher,
|
|
163
|
+
{
|
|
164
|
+
disabled,
|
|
165
|
+
swr: {
|
|
166
|
+
refreshInterval,
|
|
167
|
+
...swr
|
|
168
|
+
}
|
|
169
|
+
}
|
|
129
170
|
);
|
|
130
|
-
const query = useSolanaRpcQuery("latestBlockhash", keyArgs, fetcher, {
|
|
131
|
-
refreshInterval,
|
|
132
|
-
...rest
|
|
133
|
-
});
|
|
134
171
|
return {
|
|
135
172
|
...query,
|
|
136
173
|
blockhash: query.data?.value.blockhash ?? null,
|
|
@@ -140,14 +177,11 @@ function useLatestBlockhash(options) {
|
|
|
140
177
|
}
|
|
141
178
|
__name(useLatestBlockhash, "useLatestBlockhash");
|
|
142
179
|
function useProgramAccounts(programAddress, options) {
|
|
143
|
-
const { commitment, config,
|
|
144
|
-
const { disabled: disabledOption, ...restQueryOptions } = queryOptions;
|
|
145
|
-
const address2 = useMemo(() => programAddress ? toAddress(programAddress) : void 0, [programAddress]);
|
|
146
|
-
const addressKey = useMemo(() => address2 ? toAddressString(address2) : null, [address2]);
|
|
147
|
-
const configKey = useMemo(() => stableStringify(config ?? null), [config]);
|
|
180
|
+
const { commitment, config, swr, disabled: disabledOption } = options ?? {};
|
|
148
181
|
const fetcher = useCallback(
|
|
149
182
|
async (client) => {
|
|
150
|
-
|
|
183
|
+
const address = programAddress ? toAddress(programAddress) : void 0;
|
|
184
|
+
if (!address) {
|
|
151
185
|
throw new Error("Provide a program address before querying program accounts.");
|
|
152
186
|
}
|
|
153
187
|
const fallbackCommitment = commitment ?? config?.commitment ?? client.store.getState().cluster.commitment;
|
|
@@ -155,16 +189,21 @@ function useProgramAccounts(programAddress, options) {
|
|
|
155
189
|
...config ?? {},
|
|
156
190
|
commitment: fallbackCommitment
|
|
157
191
|
};
|
|
158
|
-
const plan = client.runtime.rpc.getProgramAccounts(
|
|
192
|
+
const plan = client.runtime.rpc.getProgramAccounts(address, mergedConfig);
|
|
159
193
|
return plan.send({ abortSignal: AbortSignal.timeout(2e4) });
|
|
160
194
|
},
|
|
161
|
-
[
|
|
195
|
+
[commitment, config, programAddress]
|
|
196
|
+
);
|
|
197
|
+
const disabled = disabledOption ?? !programAddress;
|
|
198
|
+
const query = useSolanaRpcQuery(
|
|
199
|
+
"programAccounts",
|
|
200
|
+
getProgramAccountsKey({ programAddress, config }),
|
|
201
|
+
fetcher,
|
|
202
|
+
{
|
|
203
|
+
disabled,
|
|
204
|
+
swr
|
|
205
|
+
}
|
|
162
206
|
);
|
|
163
|
-
const disabled = disabledOption ?? !address2;
|
|
164
|
-
const query = useSolanaRpcQuery("programAccounts", [addressKey, configKey], fetcher, {
|
|
165
|
-
...restQueryOptions,
|
|
166
|
-
disabled
|
|
167
|
-
});
|
|
168
207
|
return {
|
|
169
208
|
...query,
|
|
170
209
|
accounts: query.data ?? []
|
|
@@ -172,8 +211,7 @@ function useProgramAccounts(programAddress, options) {
|
|
|
172
211
|
}
|
|
173
212
|
__name(useProgramAccounts, "useProgramAccounts");
|
|
174
213
|
function useSimulateTransaction(transaction, options) {
|
|
175
|
-
const { commitment, config, refreshInterval,
|
|
176
|
-
const { disabled: disabledOption, revalidateIfStale, revalidateOnFocus, ...queryOptions } = rest;
|
|
214
|
+
const { commitment, config, refreshInterval, disabled: disabledOption, swr } = options ?? {};
|
|
177
215
|
const wire = useMemo(() => {
|
|
178
216
|
if (!transaction) {
|
|
179
217
|
return null;
|
|
@@ -183,7 +221,6 @@ function useSimulateTransaction(transaction, options) {
|
|
|
183
221
|
}
|
|
184
222
|
return getBase64EncodedWireTransaction(transaction);
|
|
185
223
|
}, [transaction]);
|
|
186
|
-
const configKey = useMemo(() => stableStringify(config ?? null), [config]);
|
|
187
224
|
const fetcher = useCallback(
|
|
188
225
|
async (client) => {
|
|
189
226
|
if (!wire) {
|
|
@@ -199,19 +236,31 @@ function useSimulateTransaction(transaction, options) {
|
|
|
199
236
|
[commitment, config, wire]
|
|
200
237
|
);
|
|
201
238
|
const disabled = disabledOption ?? !wire;
|
|
202
|
-
const query = useSolanaRpcQuery(
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
239
|
+
const query = useSolanaRpcQuery(
|
|
240
|
+
"simulateTransaction",
|
|
241
|
+
getSimulateTransactionKey({ transaction, config }),
|
|
242
|
+
fetcher,
|
|
243
|
+
{
|
|
244
|
+
disabled,
|
|
245
|
+
swr: {
|
|
246
|
+
refreshInterval,
|
|
247
|
+
revalidateIfStale: false,
|
|
248
|
+
revalidateOnFocus: false,
|
|
249
|
+
...swr
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
);
|
|
209
253
|
return {
|
|
210
254
|
...query,
|
|
211
255
|
logs: query.data?.value.logs ?? []
|
|
212
256
|
};
|
|
213
257
|
}
|
|
214
258
|
__name(useSimulateTransaction, "useSimulateTransaction");
|
|
259
|
+
function normalizeMinContextSlot(minContextSlot) {
|
|
260
|
+
if (minContextSlot === void 0) return void 0;
|
|
261
|
+
return typeof minContextSlot === "bigint" ? minContextSlot : BigInt(Math.floor(minContextSlot));
|
|
262
|
+
}
|
|
263
|
+
__name(normalizeMinContextSlot, "normalizeMinContextSlot");
|
|
215
264
|
|
|
216
265
|
// src/hooks.ts
|
|
217
266
|
function createClusterSelector() {
|
|
@@ -361,10 +410,19 @@ function useSplToken(mint, options = {}) {
|
|
|
361
410
|
}
|
|
362
411
|
return helper.fetchBalance(owner, options.commitment);
|
|
363
412
|
}, [helper, owner, options.commitment]);
|
|
364
|
-
const
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
413
|
+
const swrOptions = useMemo(
|
|
414
|
+
() => ({
|
|
415
|
+
revalidateOnFocus: options.revalidateOnFocus ?? false,
|
|
416
|
+
suspense,
|
|
417
|
+
...options.swr ?? {}
|
|
418
|
+
}),
|
|
419
|
+
[options.revalidateOnFocus, options.swr, suspense]
|
|
420
|
+
);
|
|
421
|
+
const { data, error, isLoading, isValidating, mutate } = useSWR(
|
|
422
|
+
balanceKey,
|
|
423
|
+
fetchBalance,
|
|
424
|
+
swrOptions
|
|
425
|
+
);
|
|
368
426
|
const sessionRef = useRef(session);
|
|
369
427
|
useEffect(() => {
|
|
370
428
|
sessionRef.current = session;
|
|
@@ -427,42 +485,42 @@ __name(useSplToken, "useSplToken");
|
|
|
427
485
|
function useAccount(addressLike, options = {}) {
|
|
428
486
|
const client = useSolanaClient();
|
|
429
487
|
const shouldSkip = options.skip ?? !addressLike;
|
|
430
|
-
const
|
|
488
|
+
const address = useMemo(() => {
|
|
431
489
|
if (shouldSkip || !addressLike) {
|
|
432
490
|
return void 0;
|
|
433
491
|
}
|
|
434
492
|
return toAddress(addressLike);
|
|
435
493
|
}, [addressLike, shouldSkip]);
|
|
436
|
-
const accountKey = useMemo(() =>
|
|
494
|
+
const accountKey = useMemo(() => address?.toString(), [address]);
|
|
437
495
|
const selector = useMemo(() => createAccountSelector(accountKey), [accountKey]);
|
|
438
496
|
const account = useClientStore(selector);
|
|
439
497
|
useSuspenseFetcher({
|
|
440
|
-
enabled: options.fetch !== false && !shouldSkip && Boolean(
|
|
498
|
+
enabled: options.fetch !== false && !shouldSkip && Boolean(address),
|
|
441
499
|
fetcher: /* @__PURE__ */ __name(() => {
|
|
442
|
-
if (!
|
|
500
|
+
if (!address) {
|
|
443
501
|
throw new Error("Provide an address before fetching account data.");
|
|
444
502
|
}
|
|
445
|
-
return client.actions.fetchAccount(
|
|
503
|
+
return client.actions.fetchAccount(address, options.commitment);
|
|
446
504
|
}, "fetcher"),
|
|
447
505
|
key: accountKey ?? null,
|
|
448
506
|
ready: account !== void 0
|
|
449
507
|
});
|
|
450
508
|
useEffect(() => {
|
|
451
|
-
if (!
|
|
509
|
+
if (!address) {
|
|
452
510
|
return;
|
|
453
511
|
}
|
|
454
512
|
const commitment = options.commitment;
|
|
455
513
|
if (options.fetch !== false && account === void 0) {
|
|
456
|
-
void client.actions.fetchAccount(
|
|
514
|
+
void client.actions.fetchAccount(address, commitment).catch(() => void 0);
|
|
457
515
|
}
|
|
458
516
|
if (options.watch) {
|
|
459
|
-
const subscription = client.watchers.watchAccount({ address
|
|
517
|
+
const subscription = client.watchers.watchAccount({ address, commitment }, () => void 0);
|
|
460
518
|
return () => {
|
|
461
519
|
subscription.abort();
|
|
462
520
|
};
|
|
463
521
|
}
|
|
464
522
|
return void 0;
|
|
465
|
-
}, [account,
|
|
523
|
+
}, [account, address, client, options.commitment, options.fetch, options.watch]);
|
|
466
524
|
return account;
|
|
467
525
|
}
|
|
468
526
|
__name(useAccount, "useAccount");
|
|
@@ -478,42 +536,42 @@ function useBalance(addressLike, options = {}) {
|
|
|
478
536
|
);
|
|
479
537
|
const client = useSolanaClient();
|
|
480
538
|
const shouldSkip = mergedOptions.skip ?? !addressLike;
|
|
481
|
-
const
|
|
539
|
+
const address = useMemo(() => {
|
|
482
540
|
if (shouldSkip || !addressLike) {
|
|
483
541
|
return void 0;
|
|
484
542
|
}
|
|
485
543
|
return toAddress(addressLike);
|
|
486
544
|
}, [addressLike, shouldSkip]);
|
|
487
|
-
const accountKey = useMemo(() =>
|
|
545
|
+
const accountKey = useMemo(() => address?.toString(), [address]);
|
|
488
546
|
const selector = useMemo(() => createAccountSelector(accountKey), [accountKey]);
|
|
489
547
|
const account = useClientStore(selector);
|
|
490
548
|
useSuspenseFetcher({
|
|
491
|
-
enabled: mergedOptions.fetch !== false && !shouldSkip && Boolean(
|
|
549
|
+
enabled: mergedOptions.fetch !== false && !shouldSkip && Boolean(address),
|
|
492
550
|
fetcher: /* @__PURE__ */ __name(() => {
|
|
493
|
-
if (!
|
|
551
|
+
if (!address) {
|
|
494
552
|
throw new Error("Provide an address before fetching balance.");
|
|
495
553
|
}
|
|
496
|
-
return client.actions.fetchBalance(
|
|
554
|
+
return client.actions.fetchBalance(address, mergedOptions.commitment);
|
|
497
555
|
}, "fetcher"),
|
|
498
556
|
key: accountKey ?? null,
|
|
499
557
|
ready: account !== void 0
|
|
500
558
|
});
|
|
501
559
|
useEffect(() => {
|
|
502
|
-
if (!
|
|
560
|
+
if (!address) {
|
|
503
561
|
return;
|
|
504
562
|
}
|
|
505
563
|
const commitment = mergedOptions.commitment;
|
|
506
564
|
if (mergedOptions.fetch !== false && account === void 0) {
|
|
507
|
-
void client.actions.fetchBalance(
|
|
565
|
+
void client.actions.fetchBalance(address, commitment).catch(() => void 0);
|
|
508
566
|
}
|
|
509
567
|
if (mergedOptions.watch) {
|
|
510
|
-
const watcher = client.watchers.watchBalance({ address
|
|
568
|
+
const watcher = client.watchers.watchBalance({ address, commitment }, () => void 0);
|
|
511
569
|
return () => {
|
|
512
570
|
watcher.abort();
|
|
513
571
|
};
|
|
514
572
|
}
|
|
515
573
|
return void 0;
|
|
516
|
-
}, [account,
|
|
574
|
+
}, [account, address, client, mergedOptions.commitment, mergedOptions.fetch, mergedOptions.watch]);
|
|
517
575
|
const lamports = account?.lamports ?? null;
|
|
518
576
|
const fetching = account?.fetching ?? false;
|
|
519
577
|
const slot = account?.slot;
|
|
@@ -530,22 +588,6 @@ function useBalance(addressLike, options = {}) {
|
|
|
530
588
|
);
|
|
531
589
|
}
|
|
532
590
|
__name(useBalance, "useBalance");
|
|
533
|
-
function useWalletStandardConnectors(options) {
|
|
534
|
-
const overrides = options?.overrides;
|
|
535
|
-
const memoisedOptions = useMemo(() => overrides ? { overrides } : void 0, [overrides]);
|
|
536
|
-
const [connectors, setConnectors] = useState(
|
|
537
|
-
() => getWalletStandardConnectors(memoisedOptions ?? {})
|
|
538
|
-
);
|
|
539
|
-
useEffect(() => {
|
|
540
|
-
setConnectors(getWalletStandardConnectors(memoisedOptions ?? {}));
|
|
541
|
-
const unwatch = watchWalletStandardConnectors(setConnectors, memoisedOptions ?? {});
|
|
542
|
-
return () => {
|
|
543
|
-
unwatch();
|
|
544
|
-
};
|
|
545
|
-
}, [memoisedOptions]);
|
|
546
|
-
return connectors;
|
|
547
|
-
}
|
|
548
|
-
__name(useWalletStandardConnectors, "useWalletStandardConnectors");
|
|
549
591
|
function useTransactionPool(config = {}) {
|
|
550
592
|
const initialInstructions = useMemo(
|
|
551
593
|
() => config.instructions ?? [],
|
|
@@ -679,10 +721,9 @@ function useSendTransaction() {
|
|
|
679
721
|
}
|
|
680
722
|
__name(useSendTransaction, "useSendTransaction");
|
|
681
723
|
function useSignatureStatus(signatureInput, options = {}) {
|
|
682
|
-
const { config,
|
|
724
|
+
const { config, disabled: disabledOption, swr } = options;
|
|
683
725
|
const signature = useMemo(() => normalizeSignature(signatureInput), [signatureInput]);
|
|
684
726
|
const signatureKey = signature?.toString() ?? null;
|
|
685
|
-
const configKey = useMemo(() => JSON.stringify(config ?? null), [config]);
|
|
686
727
|
const fetcher = useCallback(
|
|
687
728
|
async (client) => {
|
|
688
729
|
if (!signatureKey) {
|
|
@@ -697,14 +738,14 @@ function useSignatureStatus(signatureInput, options = {}) {
|
|
|
697
738
|
},
|
|
698
739
|
[config, signature, signatureKey]
|
|
699
740
|
);
|
|
700
|
-
const disabled =
|
|
741
|
+
const disabled = disabledOption ?? !signatureKey;
|
|
701
742
|
const query = useSolanaRpcQuery(
|
|
702
743
|
"signatureStatus",
|
|
703
|
-
|
|
744
|
+
getSignatureStatusKey({ signature: signatureInput, config }),
|
|
704
745
|
fetcher,
|
|
705
746
|
{
|
|
706
|
-
|
|
707
|
-
|
|
747
|
+
disabled,
|
|
748
|
+
swr
|
|
708
749
|
}
|
|
709
750
|
);
|
|
710
751
|
const confirmationStatus = deriveConfirmationStatus(query.data ?? null);
|
|
@@ -723,14 +764,17 @@ function useWaitForSignature(signatureInput, options = {}) {
|
|
|
723
764
|
watchCommitment,
|
|
724
765
|
...signatureStatusOptions
|
|
725
766
|
} = options;
|
|
726
|
-
const {
|
|
767
|
+
const { swr, ...restStatusOptions } = signatureStatusOptions;
|
|
727
768
|
const subscribeCommitment = watchCommitment ?? commitment;
|
|
728
769
|
const client = useSolanaClient();
|
|
729
770
|
const normalizedSignature = useMemo(() => normalizeSignature(signatureInput), [signatureInput]);
|
|
730
771
|
const disabled = disabledOption ?? !normalizedSignature;
|
|
731
772
|
const statusQuery = useSignatureStatus(signatureInput, {
|
|
732
773
|
...restStatusOptions,
|
|
733
|
-
|
|
774
|
+
swr: {
|
|
775
|
+
refreshInterval: 2e3,
|
|
776
|
+
...swr
|
|
777
|
+
},
|
|
734
778
|
disabled
|
|
735
779
|
});
|
|
736
780
|
const [subscriptionSettled, setSubscriptionSettled] = useState(false);
|
|
@@ -786,10 +830,11 @@ function useWaitForSignature(signatureInput, options = {}) {
|
|
|
786
830
|
__name(useWaitForSignature, "useWaitForSignature");
|
|
787
831
|
var createCache = /* @__PURE__ */ __name(() => /* @__PURE__ */ new Map(), "createCache");
|
|
788
832
|
var DEFAULT_QUERY_CONFIG = Object.freeze({
|
|
789
|
-
dedupingInterval:
|
|
790
|
-
focusThrottleInterval:
|
|
833
|
+
dedupingInterval: 2e3,
|
|
834
|
+
focusThrottleInterval: 5e3,
|
|
791
835
|
provider: /* @__PURE__ */ __name(() => createCache(), "provider"),
|
|
792
|
-
|
|
836
|
+
revalidateIfStale: true,
|
|
837
|
+
revalidateOnFocus: true,
|
|
793
838
|
revalidateOnReconnect: true
|
|
794
839
|
});
|
|
795
840
|
function SolanaQueryProvider({
|
|
@@ -836,6 +881,10 @@ function SolanaProvider({ children, client, config, query, walletPersistence })
|
|
|
836
881
|
const shouldIncludeQueryLayer = query !== false && query?.disabled !== true;
|
|
837
882
|
const queryProps = shouldIncludeQueryLayer && query ? query : {};
|
|
838
883
|
const persistenceConfig = walletPersistence === false ? void 0 : walletPersistence ?? {};
|
|
884
|
+
const storage = persistenceConfig ? persistenceConfig.storage ?? getDefaultStorage() : null;
|
|
885
|
+
const storageKey = persistenceConfig?.storageKey ?? DEFAULT_STORAGE_KEY;
|
|
886
|
+
const persistedState = persistenceConfig ? readPersistedState(storage, storageKey) : { legacyConnectorId: null, state: null };
|
|
887
|
+
const clientConfig = config && persistenceConfig ? { ...config, initialState: config.initialState ?? persistedState.state ?? void 0 } : config;
|
|
839
888
|
const content = shouldIncludeQueryLayer ? /* @__PURE__ */ jsx(
|
|
840
889
|
SolanaQueryProvider,
|
|
841
890
|
{
|
|
@@ -845,21 +894,52 @@ function SolanaProvider({ children, client, config, query, walletPersistence })
|
|
|
845
894
|
children
|
|
846
895
|
}
|
|
847
896
|
) : children;
|
|
848
|
-
return /* @__PURE__ */ jsxs(SolanaClientProvider, { client, config, children: [
|
|
849
|
-
persistenceConfig ? /* @__PURE__ */ jsx(
|
|
897
|
+
return /* @__PURE__ */ jsxs(SolanaClientProvider, { client, config: clientConfig, children: [
|
|
898
|
+
persistenceConfig ? /* @__PURE__ */ jsx(
|
|
899
|
+
WalletPersistence,
|
|
900
|
+
{
|
|
901
|
+
autoConnect: persistenceConfig.autoConnect,
|
|
902
|
+
initialState: clientConfig?.initialState ?? persistedState.state,
|
|
903
|
+
legacyConnectorId: persistedState.legacyConnectorId,
|
|
904
|
+
storage,
|
|
905
|
+
storageKey
|
|
906
|
+
}
|
|
907
|
+
) : null,
|
|
850
908
|
content
|
|
851
909
|
] });
|
|
852
910
|
}
|
|
853
911
|
__name(SolanaProvider, "SolanaProvider");
|
|
854
912
|
var DEFAULT_STORAGE_KEY = "solana:last-connector";
|
|
855
|
-
function
|
|
913
|
+
function readPersistedState(storage, storageKey) {
|
|
914
|
+
if (!storage) {
|
|
915
|
+
return { legacyConnectorId: null, state: null };
|
|
916
|
+
}
|
|
917
|
+
const raw = safelyRead(() => storage.getItem(storageKey));
|
|
918
|
+
if (!raw) {
|
|
919
|
+
return { legacyConnectorId: null, state: null };
|
|
920
|
+
}
|
|
921
|
+
const parsed = deserializeSolanaState(raw);
|
|
922
|
+
if (parsed) {
|
|
923
|
+
return { legacyConnectorId: null, state: parsed };
|
|
924
|
+
}
|
|
925
|
+
return { legacyConnectorId: raw, state: null };
|
|
926
|
+
}
|
|
927
|
+
__name(readPersistedState, "readPersistedState");
|
|
928
|
+
function WalletPersistence({
|
|
929
|
+
autoConnect = true,
|
|
930
|
+
initialState = null,
|
|
931
|
+
legacyConnectorId = null,
|
|
932
|
+
storage,
|
|
933
|
+
storageKey = DEFAULT_STORAGE_KEY
|
|
934
|
+
}) {
|
|
856
935
|
const wallet = useWallet();
|
|
857
936
|
const connectWallet = useConnectWallet();
|
|
858
937
|
const client = useSolanaClient();
|
|
859
938
|
const storageRef = useRef(storage ?? getDefaultStorage());
|
|
860
939
|
const [hasAttemptedAutoConnect, setHasAttemptedAutoConnect] = useState(false);
|
|
861
|
-
const hasPersistedConnectorRef = useRef(false);
|
|
862
940
|
const clientRef = useRef(null);
|
|
941
|
+
const persistedStateRef = useRef(initialState);
|
|
942
|
+
const legacyConnectorIdRef = useRef(legacyConnectorId);
|
|
863
943
|
useEffect(() => {
|
|
864
944
|
storageRef.current = storage ?? getDefaultStorage();
|
|
865
945
|
}, [storage]);
|
|
@@ -872,19 +952,19 @@ function WalletPersistence({ autoConnect = true, storage, storageKey = DEFAULT_S
|
|
|
872
952
|
useEffect(() => {
|
|
873
953
|
const activeStorage = storageRef.current;
|
|
874
954
|
if (!activeStorage) return;
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
}
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
}, [
|
|
955
|
+
const unsubscribe = subscribeSolanaState(client, (state) => {
|
|
956
|
+
persistedStateRef.current = state;
|
|
957
|
+
legacyConnectorIdRef.current = null;
|
|
958
|
+
safelyWrite(() => activeStorage.setItem(storageKey, serializeSolanaState(state)));
|
|
959
|
+
});
|
|
960
|
+
return () => {
|
|
961
|
+
unsubscribe();
|
|
962
|
+
};
|
|
963
|
+
}, [client, storageKey]);
|
|
964
|
+
useEffect(() => {
|
|
965
|
+
persistedStateRef.current = initialState ?? persistedStateRef.current;
|
|
966
|
+
legacyConnectorIdRef.current = legacyConnectorId;
|
|
967
|
+
}, [initialState, legacyConnectorId]);
|
|
888
968
|
useEffect(() => {
|
|
889
969
|
if (!autoConnect || hasAttemptedAutoConnect) {
|
|
890
970
|
return;
|
|
@@ -893,35 +973,21 @@ function WalletPersistence({ autoConnect = true, storage, storageKey = DEFAULT_S
|
|
|
893
973
|
setHasAttemptedAutoConnect(true);
|
|
894
974
|
return;
|
|
895
975
|
}
|
|
896
|
-
const
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
}
|
|
901
|
-
let cancelled = false;
|
|
902
|
-
const connectorId = safelyRead(() => activeStorage.getItem(storageKey));
|
|
903
|
-
if (!connectorId) {
|
|
904
|
-
setHasAttemptedAutoConnect(true);
|
|
905
|
-
return;
|
|
906
|
-
}
|
|
976
|
+
const state = persistedStateRef.current ?? initialState;
|
|
977
|
+
const connectorId = state?.lastConnectorId ?? legacyConnectorIdRef.current;
|
|
978
|
+
const shouldAutoConnect = (state?.autoconnect ?? autoConnect) && connectorId;
|
|
979
|
+
if (!shouldAutoConnect || !connectorId) return;
|
|
907
980
|
const connector = client.connectors.get(connectorId);
|
|
908
|
-
if (!connector)
|
|
909
|
-
return;
|
|
910
|
-
}
|
|
981
|
+
if (!connector) return;
|
|
911
982
|
void (async () => {
|
|
912
983
|
try {
|
|
913
984
|
await connectWallet(connectorId, { autoConnect: true });
|
|
914
985
|
} catch {
|
|
915
986
|
} finally {
|
|
916
|
-
|
|
917
|
-
setHasAttemptedAutoConnect(true);
|
|
918
|
-
}
|
|
987
|
+
setHasAttemptedAutoConnect(true);
|
|
919
988
|
}
|
|
920
989
|
})();
|
|
921
|
-
|
|
922
|
-
cancelled = true;
|
|
923
|
-
};
|
|
924
|
-
}, [autoConnect, client, connectWallet, hasAttemptedAutoConnect, storageKey, wallet.status]);
|
|
990
|
+
}, [autoConnect, client, connectWallet, hasAttemptedAutoConnect, initialState, wallet.status]);
|
|
925
991
|
return null;
|
|
926
992
|
}
|
|
927
993
|
__name(WalletPersistence, "WalletPersistence");
|
|
@@ -955,8 +1021,8 @@ function useWalletConnection(options = {}) {
|
|
|
955
1021
|
const wallet = useWallet();
|
|
956
1022
|
const connectWallet = useConnectWallet();
|
|
957
1023
|
const disconnectWallet = useDisconnectWallet();
|
|
958
|
-
const
|
|
959
|
-
const connectors = options.connectors ??
|
|
1024
|
+
const client = useSolanaClient();
|
|
1025
|
+
const connectors = options.connectors ?? client.connectors.all;
|
|
960
1026
|
const connect = useCallback(
|
|
961
1027
|
(connectorId, connectOptions) => connectWallet(connectorId, connectOptions),
|
|
962
1028
|
[connectWallet]
|
|
@@ -964,6 +1030,7 @@ function useWalletConnection(options = {}) {
|
|
|
964
1030
|
const disconnect = useCallback(() => disconnectWallet(), [disconnectWallet]);
|
|
965
1031
|
const state = useMemo(() => {
|
|
966
1032
|
const connectorId = "connectorId" in wallet ? wallet.connectorId : void 0;
|
|
1033
|
+
const currentConnector = connectorId ? connectors.find((connector) => connector.id === connectorId) : void 0;
|
|
967
1034
|
const session = wallet.status === "connected" ? wallet.session : void 0;
|
|
968
1035
|
const error = wallet.status === "error" ? wallet.error ?? null : null;
|
|
969
1036
|
return {
|
|
@@ -972,6 +1039,7 @@ function useWalletConnection(options = {}) {
|
|
|
972
1039
|
connecting: wallet.status === "connecting",
|
|
973
1040
|
connectors,
|
|
974
1041
|
connectorId,
|
|
1042
|
+
currentConnector,
|
|
975
1043
|
disconnect,
|
|
976
1044
|
error,
|
|
977
1045
|
status: wallet.status,
|
|
@@ -981,8 +1049,8 @@ function useWalletConnection(options = {}) {
|
|
|
981
1049
|
return state;
|
|
982
1050
|
}
|
|
983
1051
|
__name(useWalletConnection, "useWalletConnection");
|
|
984
|
-
function WalletConnectionManager({ children, connectors
|
|
985
|
-
const state = useWalletConnection({ connectors
|
|
1052
|
+
function WalletConnectionManager({ children, connectors }) {
|
|
1053
|
+
const state = useWalletConnection({ connectors });
|
|
986
1054
|
return /* @__PURE__ */ jsx(Fragment, { children: children(state) });
|
|
987
1055
|
}
|
|
988
1056
|
__name(WalletConnectionManager, "WalletConnectionManager");
|
|
@@ -1017,334 +1085,7 @@ function useWalletModalState(options = {}) {
|
|
|
1017
1085
|
};
|
|
1018
1086
|
}
|
|
1019
1087
|
__name(useWalletModalState, "useWalletModalState");
|
|
1020
|
-
function useSignAndSendTransaction(uiWalletAccount, chain) {
|
|
1021
|
-
const signAndSendTransactions = useSignAndSendTransactions(uiWalletAccount, chain);
|
|
1022
|
-
return useCallback(
|
|
1023
|
-
async (input) => {
|
|
1024
|
-
const [result] = await signAndSendTransactions(input);
|
|
1025
|
-
return result;
|
|
1026
|
-
},
|
|
1027
|
-
[signAndSendTransactions]
|
|
1028
|
-
);
|
|
1029
|
-
}
|
|
1030
|
-
__name(useSignAndSendTransaction, "useSignAndSendTransaction");
|
|
1031
|
-
function useSignAndSendTransactions(uiWalletAccount, chain) {
|
|
1032
|
-
if (!uiWalletAccount.chains.includes(chain)) {
|
|
1033
|
-
throw new WalletStandardError(WALLET_STANDARD_ERROR__FEATURES__WALLET_ACCOUNT_CHAIN_UNSUPPORTED, {
|
|
1034
|
-
address: uiWalletAccount.address,
|
|
1035
|
-
chain,
|
|
1036
|
-
featureName: SolanaSignAndSendTransaction,
|
|
1037
|
-
supportedChains: [...uiWalletAccount.chains],
|
|
1038
|
-
supportedFeatures: [...uiWalletAccount.features]
|
|
1039
|
-
});
|
|
1040
|
-
}
|
|
1041
|
-
const signAndSendTransactionFeature = getWalletAccountFeature(
|
|
1042
|
-
uiWalletAccount,
|
|
1043
|
-
SolanaSignAndSendTransaction
|
|
1044
|
-
);
|
|
1045
|
-
const account = getWalletAccountForUiWalletAccount_DO_NOT_USE_OR_YOU_WILL_BE_FIRED(uiWalletAccount);
|
|
1046
|
-
return useCallback(
|
|
1047
|
-
async (...inputs) => {
|
|
1048
|
-
const inputsWithChainAndAccount = inputs.map(({ options, ...rest }) => {
|
|
1049
|
-
const minContextSlot = options?.minContextSlot;
|
|
1050
|
-
return {
|
|
1051
|
-
...rest,
|
|
1052
|
-
account,
|
|
1053
|
-
chain,
|
|
1054
|
-
...minContextSlot != null ? {
|
|
1055
|
-
options: {
|
|
1056
|
-
minContextSlot: Number(minContextSlot)
|
|
1057
|
-
}
|
|
1058
|
-
} : null
|
|
1059
|
-
};
|
|
1060
|
-
});
|
|
1061
|
-
const results = await signAndSendTransactionFeature.signAndSendTransaction(...inputsWithChainAndAccount);
|
|
1062
|
-
return results;
|
|
1063
|
-
},
|
|
1064
|
-
[account, chain, signAndSendTransactionFeature]
|
|
1065
|
-
);
|
|
1066
|
-
}
|
|
1067
|
-
__name(useSignAndSendTransactions, "useSignAndSendTransactions");
|
|
1068
|
-
function useSignIn(uiWalletHandle) {
|
|
1069
|
-
const signIns = useSignIns(uiWalletHandle);
|
|
1070
|
-
return useCallback(
|
|
1071
|
-
async (input) => {
|
|
1072
|
-
const [result] = await signIns(input);
|
|
1073
|
-
return result;
|
|
1074
|
-
},
|
|
1075
|
-
[signIns]
|
|
1076
|
-
);
|
|
1077
|
-
}
|
|
1078
|
-
__name(useSignIn, "useSignIn");
|
|
1079
|
-
function useSignIns(uiWalletHandle) {
|
|
1080
|
-
let signMessageFeature;
|
|
1081
|
-
if ("address" in uiWalletHandle && typeof uiWalletHandle.address === "string") {
|
|
1082
|
-
getWalletAccountForUiWalletAccount_DO_NOT_USE_OR_YOU_WILL_BE_FIRED(uiWalletHandle);
|
|
1083
|
-
signMessageFeature = getWalletAccountFeature(
|
|
1084
|
-
uiWalletHandle,
|
|
1085
|
-
SolanaSignIn
|
|
1086
|
-
);
|
|
1087
|
-
} else {
|
|
1088
|
-
signMessageFeature = getWalletFeature(uiWalletHandle, SolanaSignIn);
|
|
1089
|
-
}
|
|
1090
|
-
const wallet = getWalletForHandle_DO_NOT_USE_OR_YOU_WILL_BE_FIRED(uiWalletHandle);
|
|
1091
|
-
return useCallback(
|
|
1092
|
-
async (...inputs) => {
|
|
1093
|
-
const inputsWithAddressAndChainId = inputs.map((input) => ({
|
|
1094
|
-
...input,
|
|
1095
|
-
// Prioritize the `UiWalletAccount` address if it exists.
|
|
1096
|
-
..."address" in uiWalletHandle ? { address: uiWalletHandle.address } : null
|
|
1097
|
-
}));
|
|
1098
|
-
const results = await signMessageFeature.signIn(...inputsWithAddressAndChainId);
|
|
1099
|
-
const resultsWithoutSignatureType = results.map(
|
|
1100
|
-
({
|
|
1101
|
-
account,
|
|
1102
|
-
signatureType: _signatureType,
|
|
1103
|
-
// Solana signatures are always of type `ed25519` so drop this property.
|
|
1104
|
-
...rest
|
|
1105
|
-
}) => ({
|
|
1106
|
-
...rest,
|
|
1107
|
-
account: getOrCreateUiWalletAccountForStandardWalletAccount_DO_NOT_USE_OR_YOU_WILL_BE_FIRED(
|
|
1108
|
-
wallet,
|
|
1109
|
-
account
|
|
1110
|
-
)
|
|
1111
|
-
})
|
|
1112
|
-
);
|
|
1113
|
-
return resultsWithoutSignatureType;
|
|
1114
|
-
},
|
|
1115
|
-
[signMessageFeature, uiWalletHandle, wallet]
|
|
1116
|
-
);
|
|
1117
|
-
}
|
|
1118
|
-
__name(useSignIns, "useSignIns");
|
|
1119
|
-
function useSignMessage(...config) {
|
|
1120
|
-
const signMessages = useSignMessages(...config);
|
|
1121
|
-
return useCallback(
|
|
1122
|
-
async (input) => {
|
|
1123
|
-
const [result] = await signMessages(input);
|
|
1124
|
-
return result;
|
|
1125
|
-
},
|
|
1126
|
-
[signMessages]
|
|
1127
|
-
);
|
|
1128
|
-
}
|
|
1129
|
-
__name(useSignMessage, "useSignMessage");
|
|
1130
|
-
function useSignMessages(uiWalletAccount) {
|
|
1131
|
-
const signMessageFeature = getWalletAccountFeature(
|
|
1132
|
-
uiWalletAccount,
|
|
1133
|
-
SolanaSignMessage
|
|
1134
|
-
);
|
|
1135
|
-
const account = getWalletAccountForUiWalletAccount_DO_NOT_USE_OR_YOU_WILL_BE_FIRED(uiWalletAccount);
|
|
1136
|
-
return useCallback(
|
|
1137
|
-
async (...inputs) => {
|
|
1138
|
-
const inputsWithAccount = inputs.map((input) => ({ ...input, account }));
|
|
1139
|
-
const results = await signMessageFeature.signMessage(...inputsWithAccount);
|
|
1140
|
-
const resultsWithoutSignatureType = results.map(
|
|
1141
|
-
({
|
|
1142
|
-
signatureType: _signatureType,
|
|
1143
|
-
// Solana signatures are always of type `ed25519` so drop this property.
|
|
1144
|
-
...rest
|
|
1145
|
-
}) => rest
|
|
1146
|
-
);
|
|
1147
|
-
return resultsWithoutSignatureType;
|
|
1148
|
-
},
|
|
1149
|
-
[signMessageFeature, account]
|
|
1150
|
-
);
|
|
1151
|
-
}
|
|
1152
|
-
__name(useSignMessages, "useSignMessages");
|
|
1153
|
-
function useSignTransaction(uiWalletAccount, chain) {
|
|
1154
|
-
const signTransactions = useSignTransactions(uiWalletAccount, chain);
|
|
1155
|
-
return useCallback(
|
|
1156
|
-
async (input) => {
|
|
1157
|
-
const [result] = await signTransactions(input);
|
|
1158
|
-
return result;
|
|
1159
|
-
},
|
|
1160
|
-
[signTransactions]
|
|
1161
|
-
);
|
|
1162
|
-
}
|
|
1163
|
-
__name(useSignTransaction, "useSignTransaction");
|
|
1164
|
-
function useSignTransactions(uiWalletAccount, chain) {
|
|
1165
|
-
if (!uiWalletAccount.chains.includes(chain)) {
|
|
1166
|
-
throw new WalletStandardError(WALLET_STANDARD_ERROR__FEATURES__WALLET_ACCOUNT_CHAIN_UNSUPPORTED, {
|
|
1167
|
-
address: uiWalletAccount.address,
|
|
1168
|
-
chain,
|
|
1169
|
-
featureName: SolanaSignAndSendTransaction,
|
|
1170
|
-
supportedChains: [...uiWalletAccount.chains],
|
|
1171
|
-
supportedFeatures: [...uiWalletAccount.features]
|
|
1172
|
-
});
|
|
1173
|
-
}
|
|
1174
|
-
const signTransactionFeature = getWalletAccountFeature(
|
|
1175
|
-
uiWalletAccount,
|
|
1176
|
-
SolanaSignTransaction
|
|
1177
|
-
);
|
|
1178
|
-
const account = getWalletAccountForUiWalletAccount_DO_NOT_USE_OR_YOU_WILL_BE_FIRED(uiWalletAccount);
|
|
1179
|
-
return useCallback(
|
|
1180
|
-
async (...inputs) => {
|
|
1181
|
-
const inputsWithAccountAndChain = inputs.map(({ options, ...rest }) => {
|
|
1182
|
-
const minContextSlot = options?.minContextSlot;
|
|
1183
|
-
return {
|
|
1184
|
-
...rest,
|
|
1185
|
-
account,
|
|
1186
|
-
chain,
|
|
1187
|
-
...minContextSlot != null ? {
|
|
1188
|
-
options: {
|
|
1189
|
-
minContextSlot: Number(minContextSlot)
|
|
1190
|
-
}
|
|
1191
|
-
} : null
|
|
1192
|
-
};
|
|
1193
|
-
});
|
|
1194
|
-
const results = await signTransactionFeature.signTransaction(...inputsWithAccountAndChain);
|
|
1195
|
-
return results;
|
|
1196
|
-
},
|
|
1197
|
-
[signTransactionFeature, account, chain]
|
|
1198
|
-
);
|
|
1199
|
-
}
|
|
1200
|
-
__name(useSignTransactions, "useSignTransactions");
|
|
1201
|
-
function useWalletAccountMessageSigner(uiWalletAccount) {
|
|
1202
|
-
const signMessage = useSignMessage(uiWalletAccount);
|
|
1203
|
-
return useMemo(
|
|
1204
|
-
() => ({
|
|
1205
|
-
address: address(uiWalletAccount.address),
|
|
1206
|
-
async modifyAndSignMessages(messages, config) {
|
|
1207
|
-
config?.abortSignal?.throwIfAborted();
|
|
1208
|
-
if (messages.length > 1) {
|
|
1209
|
-
throw new SolanaError(SOLANA_ERROR__SIGNER__WALLET_MULTISIGN_UNIMPLEMENTED);
|
|
1210
|
-
}
|
|
1211
|
-
if (messages.length === 0) {
|
|
1212
|
-
return messages;
|
|
1213
|
-
}
|
|
1214
|
-
const { content: originalMessage, signatures: originalSignatureMap } = messages[0];
|
|
1215
|
-
const input = {
|
|
1216
|
-
message: originalMessage
|
|
1217
|
-
};
|
|
1218
|
-
const { signedMessage, signature } = await getAbortablePromise(signMessage(input), config?.abortSignal);
|
|
1219
|
-
const messageWasModified = originalMessage.length !== signedMessage.length || originalMessage.some((originalByte, ii) => originalByte !== signedMessage[ii]);
|
|
1220
|
-
const originalSignature = originalSignatureMap[uiWalletAccount.address];
|
|
1221
|
-
const signatureIsNew = !originalSignature?.every((originalByte, ii) => originalByte === signature[ii]);
|
|
1222
|
-
if (!signatureIsNew && !messageWasModified) {
|
|
1223
|
-
return messages;
|
|
1224
|
-
}
|
|
1225
|
-
const nextSignatureMap = messageWasModified ? { [uiWalletAccount.address]: signature } : { ...originalSignatureMap, [uiWalletAccount.address]: signature };
|
|
1226
|
-
const outputMessages = Object.freeze([
|
|
1227
|
-
Object.freeze({
|
|
1228
|
-
content: signedMessage,
|
|
1229
|
-
signatures: Object.freeze(nextSignatureMap)
|
|
1230
|
-
})
|
|
1231
|
-
]);
|
|
1232
|
-
return outputMessages;
|
|
1233
|
-
}
|
|
1234
|
-
}),
|
|
1235
|
-
[uiWalletAccount, signMessage]
|
|
1236
|
-
);
|
|
1237
|
-
}
|
|
1238
|
-
__name(useWalletAccountMessageSigner, "useWalletAccountMessageSigner");
|
|
1239
|
-
function useWalletAccountTransactionSigner(uiWalletAccount, chain) {
|
|
1240
|
-
const encoderRef = useRef(null);
|
|
1241
|
-
const signTransaction = useSignTransaction(uiWalletAccount, chain);
|
|
1242
|
-
return useMemo(
|
|
1243
|
-
() => ({
|
|
1244
|
-
address: address(uiWalletAccount.address),
|
|
1245
|
-
async modifyAndSignTransactions(transactions, config = {}) {
|
|
1246
|
-
const { abortSignal, ...options } = config;
|
|
1247
|
-
abortSignal?.throwIfAborted();
|
|
1248
|
-
let transactionCodec = encoderRef.current;
|
|
1249
|
-
if (!transactionCodec) {
|
|
1250
|
-
transactionCodec = getTransactionCodec();
|
|
1251
|
-
encoderRef.current = transactionCodec;
|
|
1252
|
-
}
|
|
1253
|
-
if (transactions.length > 1) {
|
|
1254
|
-
throw new SolanaError(SOLANA_ERROR__SIGNER__WALLET_MULTISIGN_UNIMPLEMENTED);
|
|
1255
|
-
}
|
|
1256
|
-
if (transactions.length === 0) {
|
|
1257
|
-
return transactions;
|
|
1258
|
-
}
|
|
1259
|
-
const [transaction] = transactions;
|
|
1260
|
-
const wireTransactionBytes = transactionCodec.encode(transaction);
|
|
1261
|
-
const inputWithOptions = {
|
|
1262
|
-
...options,
|
|
1263
|
-
transaction: wireTransactionBytes
|
|
1264
|
-
};
|
|
1265
|
-
const { signedTransaction } = await getAbortablePromise(signTransaction(inputWithOptions), abortSignal);
|
|
1266
|
-
const decodedSignedTransaction = transactionCodec.decode(
|
|
1267
|
-
signedTransaction
|
|
1268
|
-
);
|
|
1269
|
-
assertIsTransactionWithinSizeLimit(decodedSignedTransaction);
|
|
1270
|
-
const existingLifetime = "lifetimeConstraint" in transaction ? transaction.lifetimeConstraint : void 0;
|
|
1271
|
-
if (existingLifetime) {
|
|
1272
|
-
if (uint8ArraysEqual(decodedSignedTransaction.messageBytes, transaction.messageBytes)) {
|
|
1273
|
-
return Object.freeze([
|
|
1274
|
-
{
|
|
1275
|
-
...decodedSignedTransaction,
|
|
1276
|
-
lifetimeConstraint: existingLifetime
|
|
1277
|
-
}
|
|
1278
|
-
]);
|
|
1279
|
-
}
|
|
1280
|
-
const compiledTransactionMessage2 = getCompiledTransactionMessageDecoder().decode(
|
|
1281
|
-
decodedSignedTransaction.messageBytes
|
|
1282
|
-
);
|
|
1283
|
-
const currentToken = "blockhash" in existingLifetime ? existingLifetime.blockhash : existingLifetime.nonce;
|
|
1284
|
-
if (compiledTransactionMessage2.lifetimeToken === currentToken) {
|
|
1285
|
-
return Object.freeze([
|
|
1286
|
-
{
|
|
1287
|
-
...decodedSignedTransaction,
|
|
1288
|
-
lifetimeConstraint: existingLifetime
|
|
1289
|
-
}
|
|
1290
|
-
]);
|
|
1291
|
-
}
|
|
1292
|
-
}
|
|
1293
|
-
const compiledTransactionMessage = getCompiledTransactionMessageDecoder().decode(
|
|
1294
|
-
decodedSignedTransaction.messageBytes
|
|
1295
|
-
);
|
|
1296
|
-
const lifetimeConstraint = await getTransactionLifetimeConstraintFromCompiledTransactionMessage(compiledTransactionMessage);
|
|
1297
|
-
return Object.freeze([
|
|
1298
|
-
{
|
|
1299
|
-
...decodedSignedTransaction,
|
|
1300
|
-
lifetimeConstraint
|
|
1301
|
-
}
|
|
1302
|
-
]);
|
|
1303
|
-
}
|
|
1304
|
-
}),
|
|
1305
|
-
[uiWalletAccount.address, signTransaction]
|
|
1306
|
-
);
|
|
1307
|
-
}
|
|
1308
|
-
__name(useWalletAccountTransactionSigner, "useWalletAccountTransactionSigner");
|
|
1309
|
-
function uint8ArraysEqual(arr1, arr2) {
|
|
1310
|
-
return arr1.length === arr2.length && arr1.every((value, index) => value === arr2[index]);
|
|
1311
|
-
}
|
|
1312
|
-
__name(uint8ArraysEqual, "uint8ArraysEqual");
|
|
1313
|
-
function useWalletAccountTransactionSendingSigner(uiWalletAccount, chain) {
|
|
1314
|
-
const encoderRef = useRef(null);
|
|
1315
|
-
const signAndSendTransaction = useSignAndSendTransaction(uiWalletAccount, chain);
|
|
1316
|
-
return useMemo(
|
|
1317
|
-
() => ({
|
|
1318
|
-
address: address(uiWalletAccount.address),
|
|
1319
|
-
async signAndSendTransactions(transactions, config = {}) {
|
|
1320
|
-
const { abortSignal, ...options } = config;
|
|
1321
|
-
abortSignal?.throwIfAborted();
|
|
1322
|
-
let transactionEncoder = encoderRef.current;
|
|
1323
|
-
if (!transactionEncoder) {
|
|
1324
|
-
transactionEncoder = getTransactionEncoder();
|
|
1325
|
-
encoderRef.current = transactionEncoder;
|
|
1326
|
-
}
|
|
1327
|
-
if (transactions.length > 1) {
|
|
1328
|
-
throw new SolanaError(SOLANA_ERROR__SIGNER__WALLET_MULTISIGN_UNIMPLEMENTED);
|
|
1329
|
-
}
|
|
1330
|
-
if (transactions.length === 0) {
|
|
1331
|
-
return [];
|
|
1332
|
-
}
|
|
1333
|
-
const [transaction] = transactions;
|
|
1334
|
-
const wireTransactionBytes = transactionEncoder.encode(transaction);
|
|
1335
|
-
const inputWithOptions = {
|
|
1336
|
-
...options,
|
|
1337
|
-
transaction: wireTransactionBytes
|
|
1338
|
-
};
|
|
1339
|
-
const { signature } = await getAbortablePromise(signAndSendTransaction(inputWithOptions), abortSignal);
|
|
1340
|
-
return Object.freeze([signature]);
|
|
1341
|
-
}
|
|
1342
|
-
}),
|
|
1343
|
-
[signAndSendTransaction, uiWalletAccount.address]
|
|
1344
|
-
);
|
|
1345
|
-
}
|
|
1346
|
-
__name(useWalletAccountTransactionSendingSigner, "useWalletAccountTransactionSendingSigner");
|
|
1347
1088
|
|
|
1348
|
-
export { SolanaClientProvider, SolanaProvider, SolanaQueryProvider, WalletConnectionManager, useAccount, useBalance, useClientStore, useClusterState, useClusterStatus, useConnectWallet, useDisconnectWallet, useLatestBlockhash, useProgramAccounts, useSendTransaction,
|
|
1089
|
+
export { SolanaClientProvider, SolanaProvider, SolanaQueryProvider, WalletConnectionManager, getLatestBlockhashKey, getProgramAccountsKey, getSignatureStatusKey, getSimulateTransactionKey, useAccount, useBalance, useClientStore, useClusterState, useClusterStatus, useConnectWallet, useDisconnectWallet, useLatestBlockhash, useProgramAccounts, useSendTransaction, useSignatureStatus, useSimulateTransaction, useSolTransfer, useSolanaClient, useSplToken, useTransactionPool, useWaitForSignature, useWallet, useWalletActions, useWalletConnection, useWalletModalState, useWalletSession };
|
|
1349
1090
|
//# sourceMappingURL=index.node.mjs.map
|
|
1350
1091
|
//# sourceMappingURL=index.node.mjs.map
|