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