@solana/react-hooks 0.0.0 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (92) hide show
  1. package/README.md +114 -25
  2. package/dist/index.browser.cjs +1144 -0
  3. package/dist/index.browser.cjs.map +1 -0
  4. package/dist/index.browser.mjs +1109 -0
  5. package/dist/index.browser.mjs.map +1 -0
  6. package/dist/index.native.mjs +1109 -0
  7. package/dist/index.native.mjs.map +1 -0
  8. package/dist/index.node.cjs +1144 -0
  9. package/dist/index.node.cjs.map +1 -0
  10. package/dist/index.node.mjs +1109 -0
  11. package/dist/index.node.mjs.map +1 -0
  12. package/dist/types/client/src/client/actions.d.ts +18 -0
  13. package/dist/types/client/src/client/actions.d.ts.map +1 -0
  14. package/dist/types/client/src/client/createClient.d.ts +9 -0
  15. package/dist/types/client/src/client/createClient.d.ts.map +1 -0
  16. package/dist/types/client/src/client/createClientHelpers.d.ts +3 -0
  17. package/dist/types/client/src/client/createClientHelpers.d.ts.map +1 -0
  18. package/dist/types/client/src/client/createClientStore.d.ts +29 -0
  19. package/dist/types/client/src/client/createClientStore.d.ts.map +1 -0
  20. package/dist/types/client/src/client/watchers.d.ts +16 -0
  21. package/dist/types/client/src/client/watchers.d.ts.map +1 -0
  22. package/dist/types/client/src/controllers/solTransferController.d.ts +21 -0
  23. package/dist/types/client/src/controllers/solTransferController.d.ts.map +1 -0
  24. package/dist/types/client/src/controllers/splTransferController.d.ts +24 -0
  25. package/dist/types/client/src/controllers/splTransferController.d.ts.map +1 -0
  26. package/dist/types/client/src/features/sol.d.ts +41 -0
  27. package/dist/types/client/src/features/sol.d.ts.map +1 -0
  28. package/dist/types/client/src/features/spl.d.ts +59 -0
  29. package/dist/types/client/src/features/spl.d.ts.map +1 -0
  30. package/dist/types/client/src/features/transactions.d.ts +79 -0
  31. package/dist/types/client/src/features/transactions.d.ts.map +1 -0
  32. package/dist/types/client/src/index.d.ts +25 -0
  33. package/dist/types/client/src/index.d.ts.map +1 -0
  34. package/dist/types/client/src/logging/logger.d.ts +24 -0
  35. package/dist/types/client/src/logging/logger.d.ts.map +1 -0
  36. package/dist/types/client/src/numeric/amounts.d.ts +30 -0
  37. package/dist/types/client/src/numeric/amounts.d.ts.map +1 -0
  38. package/dist/types/client/src/numeric/lamports.d.ts +46 -0
  39. package/dist/types/client/src/numeric/lamports.d.ts.map +1 -0
  40. package/dist/types/client/src/numeric/math.d.ts +74 -0
  41. package/dist/types/client/src/numeric/math.d.ts.map +1 -0
  42. package/dist/types/client/src/numeric/rational.d.ts +27 -0
  43. package/dist/types/client/src/numeric/rational.d.ts.map +1 -0
  44. package/dist/types/client/src/rpc/createSolanaRpcClient.d.ts +42 -0
  45. package/dist/types/client/src/rpc/createSolanaRpcClient.d.ts.map +1 -0
  46. package/dist/types/client/src/serialization/json.d.ts +31 -0
  47. package/dist/types/client/src/serialization/json.d.ts.map +1 -0
  48. package/dist/types/client/src/signatures/status.d.ts +12 -0
  49. package/dist/types/client/src/signatures/status.d.ts.map +1 -0
  50. package/dist/types/client/src/signers/walletTransactionSigner.d.ts +33 -0
  51. package/dist/types/client/src/signers/walletTransactionSigner.d.ts.map +1 -0
  52. package/dist/types/client/src/state/asyncState.d.ts +12 -0
  53. package/dist/types/client/src/state/asyncState.d.ts.map +1 -0
  54. package/dist/types/client/src/transactions/base64.d.ts +12 -0
  55. package/dist/types/client/src/transactions/base64.d.ts.map +1 -0
  56. package/dist/types/client/src/transactions/prepareTransaction.d.ts +16 -0
  57. package/dist/types/client/src/transactions/prepareTransaction.d.ts.map +1 -0
  58. package/dist/types/client/src/transactions/referenceKeys.d.ts +10 -0
  59. package/dist/types/client/src/transactions/referenceKeys.d.ts.map +1 -0
  60. package/dist/types/client/src/transactions/transactionPoolController.d.ts +53 -0
  61. package/dist/types/client/src/transactions/transactionPoolController.d.ts.map +1 -0
  62. package/dist/types/client/src/types.d.ts +205 -0
  63. package/dist/types/client/src/types.d.ts.map +1 -0
  64. package/dist/types/client/src/utils/addressLike.d.ts +5 -0
  65. package/dist/types/client/src/utils/addressLike.d.ts.map +1 -0
  66. package/dist/types/client/src/utils/stableStringify.d.ts +2 -0
  67. package/dist/types/client/src/utils/stableStringify.d.ts.map +1 -0
  68. package/dist/types/client/src/utils.d.ts +21 -0
  69. package/dist/types/client/src/utils.d.ts.map +1 -0
  70. package/dist/types/client/src/wallet/registry.d.ts +9 -0
  71. package/dist/types/client/src/wallet/registry.d.ts.map +1 -0
  72. package/dist/types/client/src/wallet/standard.d.ts +36 -0
  73. package/dist/types/client/src/wallet/standard.d.ts.map +1 -0
  74. package/dist/types/react-hooks/src/QueryProvider.d.ts +11 -0
  75. package/dist/types/react-hooks/src/QueryProvider.d.ts.map +1 -0
  76. package/dist/types/react-hooks/src/context.d.ts +22 -0
  77. package/dist/types/react-hooks/src/context.d.ts.map +1 -0
  78. package/dist/types/react-hooks/src/hooks.d.ts +208 -0
  79. package/dist/types/react-hooks/src/hooks.d.ts.map +1 -0
  80. package/dist/types/react-hooks/src/index.d.ts +8 -0
  81. package/dist/types/react-hooks/src/index.d.ts.map +1 -0
  82. package/dist/types/react-hooks/src/query.d.ts +20 -0
  83. package/dist/types/react-hooks/src/query.d.ts.map +1 -0
  84. package/dist/types/react-hooks/src/queryHooks.d.ts +43 -0
  85. package/dist/types/react-hooks/src/queryHooks.d.ts.map +1 -0
  86. package/dist/types/react-hooks/src/querySuspenseContext.d.ts +4 -0
  87. package/dist/types/react-hooks/src/querySuspenseContext.d.ts.map +1 -0
  88. package/dist/types/react-hooks/src/useClientStore.d.ts +6 -0
  89. package/dist/types/react-hooks/src/useClientStore.d.ts.map +1 -0
  90. package/dist/types/react-hooks/src/walletStandardHooks.d.ts +78 -0
  91. package/dist/types/react-hooks/src/walletStandardHooks.d.ts.map +1 -0
  92. package/package.json +88 -84
@@ -0,0 +1,1144 @@
1
+ 'use strict';
2
+
3
+ var client = require('@solana/client');
4
+ var react = require('react');
5
+ var jsxRuntime = require('react/jsx-runtime');
6
+ var useSWR = require('swr');
7
+ var zustand = require('zustand');
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
+
19
+ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
20
+
21
+ var useSWR__default = /*#__PURE__*/_interopDefault(useSWR);
22
+
23
+ var __defProp = Object.defineProperty;
24
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
25
+ var SolanaClientContext = react.createContext(null);
26
+ function SolanaClientProvider({ children, client: providedClient, config }) {
27
+ const client$1 = react.useMemo(() => {
28
+ if (providedClient) {
29
+ return providedClient;
30
+ }
31
+ if (!config) {
32
+ throw new Error("SolanaClientProvider requires either a `client` or `config` prop.");
33
+ }
34
+ return client.createClient(config);
35
+ }, [config, providedClient]);
36
+ react.useEffect(() => {
37
+ if (providedClient) {
38
+ return;
39
+ }
40
+ return () => {
41
+ client$1.destroy();
42
+ };
43
+ }, [client$1, providedClient]);
44
+ return /* @__PURE__ */ jsxRuntime.jsx(SolanaClientContext.Provider, { value: client$1, children });
45
+ }
46
+ __name(SolanaClientProvider, "SolanaClientProvider");
47
+ function useSolanaClient() {
48
+ const client = react.useContext(SolanaClientContext);
49
+ if (!client) {
50
+ throw new Error("useSolanaClient must be used within a SolanaClientProvider.");
51
+ }
52
+ return client;
53
+ }
54
+ __name(useSolanaClient, "useSolanaClient");
55
+ var QuerySuspenseContext = react.createContext(void 0);
56
+ function useQuerySuspensePreference() {
57
+ return react.useContext(QuerySuspenseContext);
58
+ }
59
+ __name(useQuerySuspensePreference, "useQuerySuspensePreference");
60
+ var identitySelector = /* @__PURE__ */ __name((state) => state, "identitySelector");
61
+ function useClientStore(selector) {
62
+ const client = useSolanaClient();
63
+ const appliedSelector = selector ?? identitySelector;
64
+ const slice = zustand.useStore(client.store, appliedSelector);
65
+ return selector ? slice : slice;
66
+ }
67
+ __name(useClientStore, "useClientStore");
68
+
69
+ // src/query.ts
70
+ var QUERY_NAMESPACE = "@solana/react-hooks";
71
+ function useSolanaRpcQuery(scope, args, fetcher, options = {}) {
72
+ const client = useSolanaClient();
73
+ const cluster = useClientStore((state) => state.cluster);
74
+ const { disabled = false, ...restOptions } = options;
75
+ const providerSuspensePreference = useQuerySuspensePreference();
76
+ const suspenseEnabled = !disabled && Boolean(providerSuspensePreference);
77
+ const swrOptions = {
78
+ ...restOptions,
79
+ suspense: suspenseEnabled
80
+ };
81
+ const key = react.useMemo(() => {
82
+ if (disabled) {
83
+ return null;
84
+ }
85
+ return [QUERY_NAMESPACE, scope, cluster.endpoint, cluster.commitment, ...args];
86
+ }, [cluster.commitment, cluster.endpoint, args, scope, disabled]);
87
+ const swr = useSWR__default.default(key, () => fetcher(client), swrOptions);
88
+ const [dataUpdatedAt, setDataUpdatedAt] = react.useState(
89
+ () => swr.data !== void 0 ? Date.now() : void 0
90
+ );
91
+ react.useEffect(() => {
92
+ if (swr.data !== void 0) {
93
+ setDataUpdatedAt(Date.now());
94
+ }
95
+ }, [swr.data]);
96
+ const status = swr.error ? "error" : swr.isLoading ? "loading" : swr.data !== void 0 ? "success" : "idle";
97
+ const refresh = react.useCallback(() => swr.mutate(void 0, { revalidate: true }), [swr.mutate]);
98
+ return {
99
+ data: swr.data,
100
+ dataUpdatedAt,
101
+ error: swr.error ?? null,
102
+ isError: status === "error",
103
+ isLoading: swr.isLoading,
104
+ isSuccess: status === "success",
105
+ isValidating: swr.isValidating,
106
+ mutate: swr.mutate,
107
+ refresh,
108
+ status
109
+ };
110
+ }
111
+ __name(useSolanaRpcQuery, "useSolanaRpcQuery");
112
+ var DEFAULT_BLOCKHASH_REFRESH_INTERVAL = 3e4;
113
+ function useLatestBlockhash(options) {
114
+ const { commitment, minContextSlot, refreshInterval = DEFAULT_BLOCKHASH_REFRESH_INTERVAL, ...rest } = options ?? {};
115
+ const normalizedMinContextSlot = react.useMemo(() => {
116
+ if (minContextSlot === void 0) {
117
+ return void 0;
118
+ }
119
+ return typeof minContextSlot === "bigint" ? minContextSlot : BigInt(Math.floor(minContextSlot));
120
+ }, [minContextSlot]);
121
+ const keyArgs = react.useMemo(
122
+ () => [commitment ?? null, normalizedMinContextSlot ?? null],
123
+ [commitment, normalizedMinContextSlot]
124
+ );
125
+ const fetcher = react.useCallback(
126
+ async (client) => {
127
+ const fallbackCommitment = commitment ?? client.store.getState().cluster.commitment;
128
+ const plan = client.runtime.rpc.getLatestBlockhash({
129
+ commitment: fallbackCommitment,
130
+ minContextSlot: normalizedMinContextSlot
131
+ });
132
+ return plan.send({ abortSignal: AbortSignal.timeout(15e3) });
133
+ },
134
+ [commitment, normalizedMinContextSlot]
135
+ );
136
+ const query = useSolanaRpcQuery("latestBlockhash", keyArgs, fetcher, {
137
+ refreshInterval,
138
+ ...rest
139
+ });
140
+ return {
141
+ ...query,
142
+ blockhash: query.data?.value.blockhash ?? null,
143
+ contextSlot: query.data?.context.slot,
144
+ lastValidBlockHeight: query.data?.value.lastValidBlockHeight ?? null
145
+ };
146
+ }
147
+ __name(useLatestBlockhash, "useLatestBlockhash");
148
+ function useProgramAccounts(programAddress, options) {
149
+ const { commitment, config, ...queryOptions } = options ?? {};
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]);
154
+ const fetcher = react.useCallback(
155
+ async (client) => {
156
+ if (!address2) {
157
+ throw new Error("Provide a program address before querying program accounts.");
158
+ }
159
+ const fallbackCommitment = commitment ?? config?.commitment ?? client.store.getState().cluster.commitment;
160
+ const mergedConfig = {
161
+ ...config ?? {},
162
+ commitment: fallbackCommitment
163
+ };
164
+ const plan = client.runtime.rpc.getProgramAccounts(address2, mergedConfig);
165
+ return plan.send({ abortSignal: AbortSignal.timeout(2e4) });
166
+ },
167
+ [address2, commitment, config]
168
+ );
169
+ const disabled = disabledOption ?? !address2;
170
+ const query = useSolanaRpcQuery("programAccounts", [addressKey, configKey], fetcher, {
171
+ ...restQueryOptions,
172
+ disabled
173
+ });
174
+ return {
175
+ ...query,
176
+ accounts: query.data ?? []
177
+ };
178
+ }
179
+ __name(useProgramAccounts, "useProgramAccounts");
180
+ function useSimulateTransaction(transaction, options) {
181
+ const { commitment, config, refreshInterval, ...rest } = options ?? {};
182
+ const { disabled: disabledOption, revalidateIfStale, revalidateOnFocus, ...queryOptions } = rest;
183
+ const wire = react.useMemo(() => {
184
+ if (!transaction) {
185
+ return null;
186
+ }
187
+ if (typeof transaction === "string") {
188
+ return transaction;
189
+ }
190
+ return kit.getBase64EncodedWireTransaction(transaction);
191
+ }, [transaction]);
192
+ const configKey = react.useMemo(() => client.stableStringify(config ?? null), [config]);
193
+ const fetcher = react.useCallback(
194
+ async (client) => {
195
+ if (!wire) {
196
+ throw new Error("Provide a transaction payload before simulating.");
197
+ }
198
+ const resolvedConfig = {
199
+ ...config ?? {},
200
+ commitment: commitment ?? config?.commitment ?? client.store.getState().cluster.commitment
201
+ };
202
+ const plan = client.runtime.rpc.simulateTransaction(wire, resolvedConfig);
203
+ return plan.send({ abortSignal: AbortSignal.timeout(2e4) });
204
+ },
205
+ [commitment, config, wire]
206
+ );
207
+ const disabled = disabledOption ?? !wire;
208
+ const query = useSolanaRpcQuery("simulateTransaction", [wire, configKey], fetcher, {
209
+ ...queryOptions,
210
+ refreshInterval,
211
+ disabled,
212
+ revalidateIfStale: revalidateIfStale ?? false,
213
+ revalidateOnFocus: revalidateOnFocus ?? false
214
+ });
215
+ return {
216
+ ...query,
217
+ logs: query.data?.value.logs ?? []
218
+ };
219
+ }
220
+ __name(useSimulateTransaction, "useSimulateTransaction");
221
+
222
+ // src/hooks.ts
223
+ function createClusterSelector() {
224
+ return (state) => state.cluster;
225
+ }
226
+ __name(createClusterSelector, "createClusterSelector");
227
+ function createClusterStatusSelector() {
228
+ return (state) => state.cluster.status;
229
+ }
230
+ __name(createClusterStatusSelector, "createClusterStatusSelector");
231
+ function createWalletSelector() {
232
+ return (state) => state.wallet;
233
+ }
234
+ __name(createWalletSelector, "createWalletSelector");
235
+ function createAccountSelector(key) {
236
+ return (state) => key ? state.accounts[key] : void 0;
237
+ }
238
+ __name(createAccountSelector, "createAccountSelector");
239
+ function useClusterState() {
240
+ const selector = react.useMemo(createClusterSelector, []);
241
+ return useClientStore(selector);
242
+ }
243
+ __name(useClusterState, "useClusterState");
244
+ function useClusterStatus() {
245
+ const selector = react.useMemo(createClusterStatusSelector, []);
246
+ return useClientStore(selector);
247
+ }
248
+ __name(useClusterStatus, "useClusterStatus");
249
+ function useWallet() {
250
+ const selector = react.useMemo(createWalletSelector, []);
251
+ return useClientStore(selector);
252
+ }
253
+ __name(useWallet, "useWallet");
254
+ function useWalletSession() {
255
+ const wallet = useWallet();
256
+ if (wallet.status === "connected") {
257
+ return wallet.session;
258
+ }
259
+ return void 0;
260
+ }
261
+ __name(useWalletSession, "useWalletSession");
262
+ function useWalletActions() {
263
+ const client = useSolanaClient();
264
+ return client.actions;
265
+ }
266
+ __name(useWalletActions, "useWalletActions");
267
+ function useConnectWallet() {
268
+ const client = useSolanaClient();
269
+ return react.useCallback(
270
+ (connectorId, options) => client.actions.connectWallet(connectorId, options),
271
+ [client]
272
+ );
273
+ }
274
+ __name(useConnectWallet, "useConnectWallet");
275
+ function useDisconnectWallet() {
276
+ const client = useSolanaClient();
277
+ return react.useCallback(() => client.actions.disconnectWallet(), [client]);
278
+ }
279
+ __name(useDisconnectWallet, "useDisconnectWallet");
280
+ function useSolTransfer() {
281
+ const client$1 = useSolanaClient();
282
+ const session = useWalletSession();
283
+ const helper = client$1.solTransfer;
284
+ const sessionRef = react.useRef(session);
285
+ react.useEffect(() => {
286
+ sessionRef.current = session;
287
+ }, [session]);
288
+ const controller = react.useMemo(
289
+ () => client.createSolTransferController({
290
+ authorityProvider: /* @__PURE__ */ __name(() => sessionRef.current, "authorityProvider"),
291
+ helper
292
+ }),
293
+ [helper]
294
+ );
295
+ const state = react.useSyncExternalStore(
296
+ controller.subscribe,
297
+ controller.getState,
298
+ controller.getState
299
+ );
300
+ const send = react.useCallback(
301
+ (config, options) => controller.send(config, options),
302
+ [controller]
303
+ );
304
+ return {
305
+ error: state.error ?? null,
306
+ helper,
307
+ isSending: state.status === "loading",
308
+ reset: controller.reset,
309
+ send,
310
+ signature: state.data ?? null,
311
+ status: state.status
312
+ };
313
+ }
314
+ __name(useSolTransfer, "useSolTransfer");
315
+ function useSplToken(mint, options = {}) {
316
+ const client$1 = useSolanaClient();
317
+ const session = useWalletSession();
318
+ const normalizedMint = react.useMemo(() => String(mint), [mint]);
319
+ const helperConfig = react.useMemo(
320
+ () => ({
321
+ commitment: options.commitment,
322
+ mint: normalizedMint,
323
+ ...options.config ?? {}
324
+ }),
325
+ [normalizedMint, options.commitment, options.config]
326
+ );
327
+ const helper = react.useMemo(() => client$1.splToken(helperConfig), [client$1, helperConfig]);
328
+ const ownerRaw = options.owner ?? session?.account.address;
329
+ const owner = react.useMemo(() => ownerRaw ? String(ownerRaw) : null, [ownerRaw]);
330
+ const balanceKey = owner ? ["spl-balance", normalizedMint, owner, options.commitment ?? null] : null;
331
+ const fetchBalance = react.useCallback(() => {
332
+ if (!owner) {
333
+ throw new Error("Unable to fetch SPL balance without an owner.");
334
+ }
335
+ return helper.fetchBalance(owner, options.commitment);
336
+ }, [helper, owner, options.commitment]);
337
+ const { data, error, isLoading, isValidating, mutate } = useSWR__default.default(balanceKey, fetchBalance, {
338
+ revalidateOnFocus: options.revalidateOnFocus ?? false
339
+ });
340
+ const sessionRef = react.useRef(session);
341
+ react.useEffect(() => {
342
+ sessionRef.current = session;
343
+ }, [session]);
344
+ const ownerRef = react.useRef(owner);
345
+ react.useEffect(() => {
346
+ ownerRef.current = owner;
347
+ }, [owner]);
348
+ const controller = react.useMemo(
349
+ () => client.createSplTransferController({
350
+ authorityProvider: /* @__PURE__ */ __name(() => sessionRef.current ?? void 0, "authorityProvider"),
351
+ helper,
352
+ sourceOwnerProvider: /* @__PURE__ */ __name(() => ownerRef.current ?? void 0, "sourceOwnerProvider")
353
+ }),
354
+ [helper]
355
+ );
356
+ const sendState = react.useSyncExternalStore(
357
+ controller.subscribe,
358
+ controller.getState,
359
+ controller.getState
360
+ );
361
+ const refresh = react.useCallback(() => {
362
+ if (!owner) {
363
+ return Promise.resolve(void 0);
364
+ }
365
+ return mutate(() => helper.fetchBalance(owner, options.commitment), { revalidate: false });
366
+ }, [helper, mutate, owner, options.commitment]);
367
+ const send = react.useCallback(
368
+ async (config, sendOptions) => {
369
+ const signature = await controller.send(config, sendOptions);
370
+ if (owner) {
371
+ await mutate(() => helper.fetchBalance(owner, options.commitment), { revalidate: false });
372
+ }
373
+ return signature;
374
+ },
375
+ [controller, helper, mutate, options.commitment, owner]
376
+ );
377
+ const resetSend = react.useCallback(() => {
378
+ controller.reset();
379
+ }, [controller]);
380
+ const status = owner === null ? "disconnected" : error ? "error" : isLoading && !data ? "loading" : "ready";
381
+ return {
382
+ balance: data ?? null,
383
+ error: error ?? null,
384
+ helper,
385
+ isFetching: Boolean(owner) && (isLoading || isValidating),
386
+ isSending: sendState.status === "loading",
387
+ owner,
388
+ refresh,
389
+ refreshing: Boolean(owner) && isValidating,
390
+ resetSend,
391
+ send,
392
+ sendError: sendState.error ?? null,
393
+ sendSignature: sendState.data ?? null,
394
+ sendStatus: sendState.status,
395
+ status
396
+ };
397
+ }
398
+ __name(useSplToken, "useSplToken");
399
+ function useAccount(addressLike, options = {}) {
400
+ const client$1 = useSolanaClient();
401
+ const shouldSkip = options.skip ?? !addressLike;
402
+ const address2 = react.useMemo(() => {
403
+ if (shouldSkip || !addressLike) {
404
+ return void 0;
405
+ }
406
+ return client.toAddress(addressLike);
407
+ }, [addressLike, shouldSkip]);
408
+ const accountKey = react.useMemo(() => address2?.toString(), [address2]);
409
+ const selector = react.useMemo(() => createAccountSelector(accountKey), [accountKey]);
410
+ const account = useClientStore(selector);
411
+ react.useEffect(() => {
412
+ if (!address2) {
413
+ return;
414
+ }
415
+ const commitment = options.commitment;
416
+ if (options.fetch !== false) {
417
+ void client$1.actions.fetchAccount(address2, commitment).catch(() => void 0);
418
+ }
419
+ if (options.watch) {
420
+ const subscription = client$1.watchers.watchAccount({ address: address2, commitment }, () => void 0);
421
+ return () => {
422
+ subscription.abort();
423
+ };
424
+ }
425
+ return void 0;
426
+ }, [address2, client$1, options.commitment, options.fetch, options.watch]);
427
+ return account;
428
+ }
429
+ __name(useAccount, "useAccount");
430
+ function useBalance(addressLike, options = {}) {
431
+ const mergedOptions = react.useMemo(
432
+ () => ({
433
+ commitment: options.commitment,
434
+ fetch: options.fetch ?? true,
435
+ skip: options.skip,
436
+ watch: options.watch ?? true
437
+ }),
438
+ [options.commitment, options.fetch, options.skip, options.watch]
439
+ );
440
+ const client$1 = useSolanaClient();
441
+ const shouldSkip = mergedOptions.skip ?? !addressLike;
442
+ const address2 = react.useMemo(() => {
443
+ if (shouldSkip || !addressLike) {
444
+ return void 0;
445
+ }
446
+ return client.toAddress(addressLike);
447
+ }, [addressLike, shouldSkip]);
448
+ const accountKey = react.useMemo(() => address2?.toString(), [address2]);
449
+ const selector = react.useMemo(() => createAccountSelector(accountKey), [accountKey]);
450
+ const account = useClientStore(selector);
451
+ react.useEffect(() => {
452
+ if (!address2) {
453
+ return;
454
+ }
455
+ const commitment = mergedOptions.commitment;
456
+ if (mergedOptions.fetch !== false) {
457
+ void client$1.actions.fetchBalance(address2, commitment).catch(() => void 0);
458
+ }
459
+ if (mergedOptions.watch) {
460
+ const watcher = client$1.watchers.watchBalance({ address: address2, commitment }, () => void 0);
461
+ return () => {
462
+ watcher.abort();
463
+ };
464
+ }
465
+ return void 0;
466
+ }, [address2, client$1, mergedOptions.commitment, mergedOptions.fetch, mergedOptions.watch]);
467
+ const lamports = account?.lamports ?? null;
468
+ const fetching = account?.fetching ?? false;
469
+ const slot = account?.slot;
470
+ const error = account?.error;
471
+ return react.useMemo(
472
+ () => ({
473
+ account,
474
+ error,
475
+ fetching,
476
+ lamports,
477
+ slot
478
+ }),
479
+ [account, error, fetching, lamports, slot]
480
+ );
481
+ }
482
+ __name(useBalance, "useBalance");
483
+ function useWalletStandardConnectors(options) {
484
+ const overrides = options?.overrides;
485
+ const memoisedOptions = react.useMemo(() => overrides ? { overrides } : void 0, [overrides]);
486
+ const [connectors, setConnectors] = react.useState(
487
+ () => client.getWalletStandardConnectors(memoisedOptions ?? {})
488
+ );
489
+ react.useEffect(() => {
490
+ setConnectors(client.getWalletStandardConnectors(memoisedOptions ?? {}));
491
+ const unwatch = client.watchWalletStandardConnectors(setConnectors, memoisedOptions ?? {});
492
+ return () => {
493
+ unwatch();
494
+ };
495
+ }, [memoisedOptions]);
496
+ return connectors;
497
+ }
498
+ __name(useWalletStandardConnectors, "useWalletStandardConnectors");
499
+ function useTransactionPool(config = {}) {
500
+ const initialInstructions = react.useMemo(
501
+ () => config.instructions ?? [],
502
+ [config.instructions]
503
+ );
504
+ const client$1 = useSolanaClient();
505
+ const helper = client$1.helpers.transaction;
506
+ const blockhashMaxAgeMs = config.latestBlockhash?.refreshInterval ?? 3e4;
507
+ const controller = react.useMemo(
508
+ () => client.createTransactionPoolController({
509
+ blockhashMaxAgeMs,
510
+ helper,
511
+ initialInstructions
512
+ }),
513
+ [blockhashMaxAgeMs, helper, initialInstructions]
514
+ );
515
+ const latestBlockhash = useLatestBlockhash(config.latestBlockhash);
516
+ react.useEffect(() => {
517
+ const value = latestBlockhash.data?.value;
518
+ if (!value) {
519
+ controller.setLatestBlockhashCache(void 0);
520
+ return;
521
+ }
522
+ const cache = {
523
+ updatedAt: latestBlockhash.dataUpdatedAt ?? Date.now(),
524
+ value
525
+ };
526
+ controller.setLatestBlockhashCache(cache);
527
+ }, [controller, latestBlockhash.data, latestBlockhash.dataUpdatedAt]);
528
+ const instructions = react.useSyncExternalStore(
529
+ controller.subscribeInstructions,
530
+ controller.getInstructions,
531
+ controller.getInstructions
532
+ );
533
+ const prepared = react.useSyncExternalStore(
534
+ controller.subscribePrepared,
535
+ controller.getPrepared,
536
+ controller.getPrepared
537
+ );
538
+ const prepareState = react.useSyncExternalStore(
539
+ controller.subscribePrepareState,
540
+ controller.getPrepareState,
541
+ controller.getPrepareState
542
+ );
543
+ const sendState = react.useSyncExternalStore(
544
+ controller.subscribeSendState,
545
+ controller.getSendState,
546
+ controller.getSendState
547
+ );
548
+ return {
549
+ addInstruction: controller.addInstruction,
550
+ addInstructions: controller.addInstructions,
551
+ clearInstructions: controller.clearInstructions,
552
+ instructions,
553
+ isPreparing: prepareState.status === "loading",
554
+ isSending: sendState.status === "loading",
555
+ prepared,
556
+ prepare: controller.prepare,
557
+ prepareError: prepareState.error ?? null,
558
+ prepareStatus: prepareState.status,
559
+ removeInstruction: controller.removeInstruction,
560
+ replaceInstructions: controller.replaceInstructions,
561
+ reset: controller.reset,
562
+ send: controller.send,
563
+ sendError: sendState.error ?? null,
564
+ sendSignature: sendState.data ?? null,
565
+ sendStatus: sendState.status,
566
+ prepareAndSend: controller.prepareAndSend,
567
+ sign: controller.sign,
568
+ toWire: controller.toWire,
569
+ latestBlockhash
570
+ };
571
+ }
572
+ __name(useTransactionPool, "useTransactionPool");
573
+ function useSendTransaction() {
574
+ const client$1 = useSolanaClient();
575
+ const helper = client$1.transaction;
576
+ const session = useWalletSession();
577
+ const [state, setState] = react.useState(
578
+ () => client.createInitialAsyncState()
579
+ );
580
+ const execute = react.useCallback(
581
+ async (operation) => {
582
+ setState(client.createAsyncState("loading"));
583
+ try {
584
+ const signature = await operation();
585
+ setState(client.createAsyncState("success", { data: signature }));
586
+ return signature;
587
+ } catch (error) {
588
+ setState(client.createAsyncState("error", { error }));
589
+ throw error;
590
+ }
591
+ },
592
+ []
593
+ );
594
+ const ensureAuthority = react.useCallback(
595
+ (request) => {
596
+ if (request.authority) {
597
+ return request;
598
+ }
599
+ if (!session) {
600
+ throw new Error("Connect a wallet or supply an `authority` before sending transactions.");
601
+ }
602
+ return { ...request, authority: session };
603
+ },
604
+ [session]
605
+ );
606
+ const send = react.useCallback(
607
+ async (request, options) => {
608
+ const normalizedRequest = ensureAuthority(request);
609
+ return execute(() => helper.prepareAndSend(normalizedRequest, options));
610
+ },
611
+ [ensureAuthority, execute, helper]
612
+ );
613
+ const sendPrepared = react.useCallback(
614
+ async (prepared, options) => execute(() => helper.send(prepared, options)),
615
+ [execute, helper]
616
+ );
617
+ const reset = react.useCallback(() => {
618
+ setState(client.createInitialAsyncState());
619
+ }, []);
620
+ return {
621
+ error: state.error ?? null,
622
+ isSending: state.status === "loading",
623
+ reset,
624
+ send,
625
+ sendPrepared,
626
+ signature: state.data ?? null,
627
+ status: state.status
628
+ };
629
+ }
630
+ __name(useSendTransaction, "useSendTransaction");
631
+ function useSignatureStatus(signatureInput, options = {}) {
632
+ const { config, ...queryOptions } = options;
633
+ const signature = react.useMemo(() => client.normalizeSignature(signatureInput), [signatureInput]);
634
+ const signatureKey = signature?.toString() ?? null;
635
+ const configKey = react.useMemo(() => JSON.stringify(config ?? null), [config]);
636
+ const fetcher = react.useCallback(
637
+ async (client$1) => {
638
+ if (!signatureKey) {
639
+ throw new Error("Provide a signature before querying its status.");
640
+ }
641
+ if (!signature) {
642
+ throw new Error("Provide a signature before querying its status.");
643
+ }
644
+ const plan = client$1.runtime.rpc.getSignatureStatuses([signature], config);
645
+ const response = await plan.send({ abortSignal: AbortSignal.timeout(client.SIGNATURE_STATUS_TIMEOUT_MS) });
646
+ return response.value[0] ?? null;
647
+ },
648
+ [config, signature, signatureKey]
649
+ );
650
+ const disabled = queryOptions.disabled ?? !signatureKey;
651
+ const query = useSolanaRpcQuery(
652
+ "signatureStatus",
653
+ [signatureKey, configKey],
654
+ fetcher,
655
+ {
656
+ ...queryOptions,
657
+ disabled
658
+ }
659
+ );
660
+ const confirmationStatus = client.deriveConfirmationStatus(query.data ?? null);
661
+ return {
662
+ ...query,
663
+ confirmationStatus,
664
+ signatureStatus: query.data ?? null
665
+ };
666
+ }
667
+ __name(useSignatureStatus, "useSignatureStatus");
668
+ function useWaitForSignature(signatureInput, options = {}) {
669
+ const {
670
+ commitment = "confirmed",
671
+ disabled: disabledOption,
672
+ subscribe = true,
673
+ watchCommitment,
674
+ ...signatureStatusOptions
675
+ } = options;
676
+ const { refreshInterval, ...restStatusOptions } = signatureStatusOptions;
677
+ const subscribeCommitment = watchCommitment ?? commitment;
678
+ const client$1 = useSolanaClient();
679
+ const normalizedSignature = react.useMemo(() => client.normalizeSignature(signatureInput), [signatureInput]);
680
+ const disabled = disabledOption ?? !normalizedSignature;
681
+ const statusQuery = useSignatureStatus(signatureInput, {
682
+ ...restStatusOptions,
683
+ refreshInterval: refreshInterval ?? 2e3,
684
+ disabled
685
+ });
686
+ const [subscriptionSettled, setSubscriptionSettled] = react.useState(false);
687
+ react.useEffect(() => {
688
+ if (normalizedSignature === void 0) {
689
+ setSubscriptionSettled(false);
690
+ return;
691
+ }
692
+ setSubscriptionSettled(false);
693
+ }, [normalizedSignature]);
694
+ react.useEffect(() => {
695
+ if (!normalizedSignature || disabled || !subscribe) {
696
+ return;
697
+ }
698
+ const subscription = client$1.watchers.watchSignature(
699
+ {
700
+ commitment: subscribeCommitment,
701
+ enableReceivedNotification: true,
702
+ signature: normalizedSignature
703
+ },
704
+ () => {
705
+ setSubscriptionSettled(true);
706
+ }
707
+ );
708
+ return () => {
709
+ subscription.abort();
710
+ };
711
+ }, [client$1, disabled, normalizedSignature, subscribe, subscribeCommitment]);
712
+ const hasSignature = Boolean(normalizedSignature) && !disabled;
713
+ const signatureError = statusQuery.signatureStatus?.err ?? null;
714
+ const waitError = statusQuery.error ?? signatureError ?? null;
715
+ const meetsCommitment = client.confirmationMeetsCommitment(statusQuery.confirmationStatus, commitment);
716
+ const settled = subscriptionSettled || meetsCommitment;
717
+ let waitStatus = "idle";
718
+ if (!hasSignature) {
719
+ waitStatus = "idle";
720
+ } else if (waitError) {
721
+ waitStatus = "error";
722
+ } else if (settled) {
723
+ waitStatus = "success";
724
+ } else {
725
+ waitStatus = "waiting";
726
+ }
727
+ return {
728
+ ...statusQuery,
729
+ isError: waitStatus === "error",
730
+ isSuccess: waitStatus === "success",
731
+ isWaiting: waitStatus === "waiting",
732
+ waitError,
733
+ waitStatus
734
+ };
735
+ }
736
+ __name(useWaitForSignature, "useWaitForSignature");
737
+ var createCache = /* @__PURE__ */ __name(() => /* @__PURE__ */ new Map(), "createCache");
738
+ var DEFAULT_QUERY_CONFIG = Object.freeze({
739
+ dedupingInterval: 1e3,
740
+ focusThrottleInterval: 1e3,
741
+ provider: /* @__PURE__ */ __name(() => createCache(), "provider"),
742
+ revalidateOnFocus: false,
743
+ revalidateOnReconnect: true
744
+ });
745
+ function SolanaQueryProvider({
746
+ children,
747
+ config,
748
+ resetOnClusterChange = true,
749
+ suspense
750
+ }) {
751
+ const cluster = useClientStore((state) => state.cluster);
752
+ const cacheRegistryRef = react.useRef(/* @__PURE__ */ new Map());
753
+ const cacheKey = resetOnClusterChange ? `${cluster.endpoint}|${cluster.commitment}` : "global";
754
+ const cache = react.useMemo(() => {
755
+ const registry = cacheRegistryRef.current;
756
+ if (!resetOnClusterChange) {
757
+ const existing = registry.get("global");
758
+ if (existing) {
759
+ return existing;
760
+ }
761
+ const next2 = createCache();
762
+ registry.set("global", next2);
763
+ return next2;
764
+ }
765
+ const next = createCache();
766
+ registry.set(cacheKey, next);
767
+ return next;
768
+ }, [cacheKey, resetOnClusterChange]);
769
+ const value = react.useMemo(() => {
770
+ const base = {
771
+ ...DEFAULT_QUERY_CONFIG,
772
+ ...config
773
+ };
774
+ if (!config?.provider) {
775
+ base.provider = () => cache;
776
+ }
777
+ if (base.suspense === void 0 && suspense !== void 0) {
778
+ base.suspense = suspense;
779
+ }
780
+ return base;
781
+ }, [cache, config, suspense]);
782
+ return /* @__PURE__ */ jsxRuntime.jsx(QuerySuspenseContext.Provider, { value: suspense, children: /* @__PURE__ */ jsxRuntime.jsx(useSWR.SWRConfig, { value, children }) });
783
+ }
784
+ __name(SolanaQueryProvider, "SolanaQueryProvider");
785
+ function useSignAndSendTransaction(uiWalletAccount, chain) {
786
+ const signAndSendTransactions = useSignAndSendTransactions(uiWalletAccount, chain);
787
+ return react.useCallback(
788
+ async (input) => {
789
+ const [result] = await signAndSendTransactions(input);
790
+ return result;
791
+ },
792
+ [signAndSendTransactions]
793
+ );
794
+ }
795
+ __name(useSignAndSendTransaction, "useSignAndSendTransaction");
796
+ function useSignAndSendTransactions(uiWalletAccount, chain) {
797
+ if (!uiWalletAccount.chains.includes(chain)) {
798
+ throw new errors.WalletStandardError(errors.WALLET_STANDARD_ERROR__FEATURES__WALLET_ACCOUNT_CHAIN_UNSUPPORTED, {
799
+ address: uiWalletAccount.address,
800
+ chain,
801
+ featureName: walletStandardFeatures.SolanaSignAndSendTransaction,
802
+ supportedChains: [...uiWalletAccount.chains],
803
+ supportedFeatures: [...uiWalletAccount.features]
804
+ });
805
+ }
806
+ const signAndSendTransactionFeature = ui.getWalletAccountFeature(
807
+ uiWalletAccount,
808
+ walletStandardFeatures.SolanaSignAndSendTransaction
809
+ );
810
+ const account = uiRegistry.getWalletAccountForUiWalletAccount_DO_NOT_USE_OR_YOU_WILL_BE_FIRED(uiWalletAccount);
811
+ return react.useCallback(
812
+ async (...inputs) => {
813
+ const inputsWithChainAndAccount = inputs.map(({ options, ...rest }) => {
814
+ const minContextSlot = options?.minContextSlot;
815
+ return {
816
+ ...rest,
817
+ account,
818
+ chain,
819
+ ...minContextSlot != null ? {
820
+ options: {
821
+ minContextSlot: Number(minContextSlot)
822
+ }
823
+ } : null
824
+ };
825
+ });
826
+ const results = await signAndSendTransactionFeature.signAndSendTransaction(...inputsWithChainAndAccount);
827
+ return results;
828
+ },
829
+ [account, chain, signAndSendTransactionFeature]
830
+ );
831
+ }
832
+ __name(useSignAndSendTransactions, "useSignAndSendTransactions");
833
+ function useSignIn(uiWalletHandle) {
834
+ const signIns = useSignIns(uiWalletHandle);
835
+ return react.useCallback(
836
+ async (input) => {
837
+ const [result] = await signIns(input);
838
+ return result;
839
+ },
840
+ [signIns]
841
+ );
842
+ }
843
+ __name(useSignIn, "useSignIn");
844
+ function useSignIns(uiWalletHandle) {
845
+ let signMessageFeature;
846
+ if ("address" in uiWalletHandle && typeof uiWalletHandle.address === "string") {
847
+ uiRegistry.getWalletAccountForUiWalletAccount_DO_NOT_USE_OR_YOU_WILL_BE_FIRED(uiWalletHandle);
848
+ signMessageFeature = ui.getWalletAccountFeature(
849
+ uiWalletHandle,
850
+ walletStandardFeatures.SolanaSignIn
851
+ );
852
+ } else {
853
+ signMessageFeature = ui.getWalletFeature(uiWalletHandle, walletStandardFeatures.SolanaSignIn);
854
+ }
855
+ const wallet = uiRegistry.getWalletForHandle_DO_NOT_USE_OR_YOU_WILL_BE_FIRED(uiWalletHandle);
856
+ return react.useCallback(
857
+ async (...inputs) => {
858
+ const inputsWithAddressAndChainId = inputs.map((input) => ({
859
+ ...input,
860
+ // Prioritize the `UiWalletAccount` address if it exists.
861
+ ..."address" in uiWalletHandle ? { address: uiWalletHandle.address } : null
862
+ }));
863
+ const results = await signMessageFeature.signIn(...inputsWithAddressAndChainId);
864
+ const resultsWithoutSignatureType = results.map(
865
+ ({
866
+ account,
867
+ signatureType: _signatureType,
868
+ // Solana signatures are always of type `ed25519` so drop this property.
869
+ ...rest
870
+ }) => ({
871
+ ...rest,
872
+ account: uiRegistry.getOrCreateUiWalletAccountForStandardWalletAccount_DO_NOT_USE_OR_YOU_WILL_BE_FIRED(
873
+ wallet,
874
+ account
875
+ )
876
+ })
877
+ );
878
+ return resultsWithoutSignatureType;
879
+ },
880
+ [signMessageFeature, uiWalletHandle, wallet]
881
+ );
882
+ }
883
+ __name(useSignIns, "useSignIns");
884
+ function useSignMessage(...config) {
885
+ const signMessages = useSignMessages(...config);
886
+ return react.useCallback(
887
+ async (input) => {
888
+ const [result] = await signMessages(input);
889
+ return result;
890
+ },
891
+ [signMessages]
892
+ );
893
+ }
894
+ __name(useSignMessage, "useSignMessage");
895
+ function useSignMessages(uiWalletAccount) {
896
+ const signMessageFeature = ui.getWalletAccountFeature(
897
+ uiWalletAccount,
898
+ walletStandardFeatures.SolanaSignMessage
899
+ );
900
+ const account = uiRegistry.getWalletAccountForUiWalletAccount_DO_NOT_USE_OR_YOU_WILL_BE_FIRED(uiWalletAccount);
901
+ return react.useCallback(
902
+ async (...inputs) => {
903
+ const inputsWithAccount = inputs.map((input) => ({ ...input, account }));
904
+ const results = await signMessageFeature.signMessage(...inputsWithAccount);
905
+ const resultsWithoutSignatureType = results.map(
906
+ ({
907
+ signatureType: _signatureType,
908
+ // Solana signatures are always of type `ed25519` so drop this property.
909
+ ...rest
910
+ }) => rest
911
+ );
912
+ return resultsWithoutSignatureType;
913
+ },
914
+ [signMessageFeature, account]
915
+ );
916
+ }
917
+ __name(useSignMessages, "useSignMessages");
918
+ function useSignTransaction(uiWalletAccount, chain) {
919
+ const signTransactions = useSignTransactions(uiWalletAccount, chain);
920
+ return react.useCallback(
921
+ async (input) => {
922
+ const [result] = await signTransactions(input);
923
+ return result;
924
+ },
925
+ [signTransactions]
926
+ );
927
+ }
928
+ __name(useSignTransaction, "useSignTransaction");
929
+ function useSignTransactions(uiWalletAccount, chain) {
930
+ if (!uiWalletAccount.chains.includes(chain)) {
931
+ throw new errors.WalletStandardError(errors.WALLET_STANDARD_ERROR__FEATURES__WALLET_ACCOUNT_CHAIN_UNSUPPORTED, {
932
+ address: uiWalletAccount.address,
933
+ chain,
934
+ featureName: walletStandardFeatures.SolanaSignAndSendTransaction,
935
+ supportedChains: [...uiWalletAccount.chains],
936
+ supportedFeatures: [...uiWalletAccount.features]
937
+ });
938
+ }
939
+ const signTransactionFeature = ui.getWalletAccountFeature(
940
+ uiWalletAccount,
941
+ walletStandardFeatures.SolanaSignTransaction
942
+ );
943
+ const account = uiRegistry.getWalletAccountForUiWalletAccount_DO_NOT_USE_OR_YOU_WILL_BE_FIRED(uiWalletAccount);
944
+ return react.useCallback(
945
+ async (...inputs) => {
946
+ const inputsWithAccountAndChain = inputs.map(({ options, ...rest }) => {
947
+ const minContextSlot = options?.minContextSlot;
948
+ return {
949
+ ...rest,
950
+ account,
951
+ chain,
952
+ ...minContextSlot != null ? {
953
+ options: {
954
+ minContextSlot: Number(minContextSlot)
955
+ }
956
+ } : null
957
+ };
958
+ });
959
+ const results = await signTransactionFeature.signTransaction(...inputsWithAccountAndChain);
960
+ return results;
961
+ },
962
+ [signTransactionFeature, account, chain]
963
+ );
964
+ }
965
+ __name(useSignTransactions, "useSignTransactions");
966
+ function useWalletAccountMessageSigner(uiWalletAccount) {
967
+ const signMessage = useSignMessage(uiWalletAccount);
968
+ return react.useMemo(
969
+ () => ({
970
+ address: addresses.address(uiWalletAccount.address),
971
+ async modifyAndSignMessages(messages, config) {
972
+ config?.abortSignal?.throwIfAborted();
973
+ if (messages.length > 1) {
974
+ throw new errors$1.SolanaError(errors$1.SOLANA_ERROR__SIGNER__WALLET_MULTISIGN_UNIMPLEMENTED);
975
+ }
976
+ if (messages.length === 0) {
977
+ return messages;
978
+ }
979
+ const { content: originalMessage, signatures: originalSignatureMap } = messages[0];
980
+ const input = {
981
+ message: originalMessage
982
+ };
983
+ const { signedMessage, signature } = await promises.getAbortablePromise(signMessage(input), config?.abortSignal);
984
+ const messageWasModified = originalMessage.length !== signedMessage.length || originalMessage.some((originalByte, ii) => originalByte !== signedMessage[ii]);
985
+ const originalSignature = originalSignatureMap[uiWalletAccount.address];
986
+ const signatureIsNew = !originalSignature?.every((originalByte, ii) => originalByte === signature[ii]);
987
+ if (!signatureIsNew && !messageWasModified) {
988
+ return messages;
989
+ }
990
+ const nextSignatureMap = messageWasModified ? { [uiWalletAccount.address]: signature } : { ...originalSignatureMap, [uiWalletAccount.address]: signature };
991
+ const outputMessages = Object.freeze([
992
+ Object.freeze({
993
+ content: signedMessage,
994
+ signatures: Object.freeze(nextSignatureMap)
995
+ })
996
+ ]);
997
+ return outputMessages;
998
+ }
999
+ }),
1000
+ [uiWalletAccount, signMessage]
1001
+ );
1002
+ }
1003
+ __name(useWalletAccountMessageSigner, "useWalletAccountMessageSigner");
1004
+ function useWalletAccountTransactionSigner(uiWalletAccount, chain) {
1005
+ const encoderRef = react.useRef(null);
1006
+ const signTransaction = useSignTransaction(uiWalletAccount, chain);
1007
+ return react.useMemo(
1008
+ () => ({
1009
+ address: addresses.address(uiWalletAccount.address),
1010
+ async modifyAndSignTransactions(transactions$1, config = {}) {
1011
+ const { abortSignal, ...options } = config;
1012
+ abortSignal?.throwIfAborted();
1013
+ let transactionCodec = encoderRef.current;
1014
+ if (!transactionCodec) {
1015
+ transactionCodec = transactions.getTransactionCodec();
1016
+ encoderRef.current = transactionCodec;
1017
+ }
1018
+ if (transactions$1.length > 1) {
1019
+ throw new errors$1.SolanaError(errors$1.SOLANA_ERROR__SIGNER__WALLET_MULTISIGN_UNIMPLEMENTED);
1020
+ }
1021
+ if (transactions$1.length === 0) {
1022
+ return transactions$1;
1023
+ }
1024
+ const [transaction] = transactions$1;
1025
+ const wireTransactionBytes = transactionCodec.encode(transaction);
1026
+ const inputWithOptions = {
1027
+ ...options,
1028
+ transaction: wireTransactionBytes
1029
+ };
1030
+ const { signedTransaction } = await promises.getAbortablePromise(signTransaction(inputWithOptions), abortSignal);
1031
+ const decodedSignedTransaction = transactionCodec.decode(
1032
+ signedTransaction
1033
+ );
1034
+ transactions.assertIsTransactionWithinSizeLimit(decodedSignedTransaction);
1035
+ const existingLifetime = "lifetimeConstraint" in transaction ? transaction.lifetimeConstraint : void 0;
1036
+ if (existingLifetime) {
1037
+ if (uint8ArraysEqual(decodedSignedTransaction.messageBytes, transaction.messageBytes)) {
1038
+ return Object.freeze([
1039
+ {
1040
+ ...decodedSignedTransaction,
1041
+ lifetimeConstraint: existingLifetime
1042
+ }
1043
+ ]);
1044
+ }
1045
+ const compiledTransactionMessage2 = transactionMessages.getCompiledTransactionMessageDecoder().decode(
1046
+ decodedSignedTransaction.messageBytes
1047
+ );
1048
+ const currentToken = "blockhash" in existingLifetime ? existingLifetime.blockhash : existingLifetime.nonce;
1049
+ if (compiledTransactionMessage2.lifetimeToken === currentToken) {
1050
+ return Object.freeze([
1051
+ {
1052
+ ...decodedSignedTransaction,
1053
+ lifetimeConstraint: existingLifetime
1054
+ }
1055
+ ]);
1056
+ }
1057
+ }
1058
+ const compiledTransactionMessage = transactionMessages.getCompiledTransactionMessageDecoder().decode(
1059
+ decodedSignedTransaction.messageBytes
1060
+ );
1061
+ const lifetimeConstraint = await transactions.getTransactionLifetimeConstraintFromCompiledTransactionMessage(compiledTransactionMessage);
1062
+ return Object.freeze([
1063
+ {
1064
+ ...decodedSignedTransaction,
1065
+ lifetimeConstraint
1066
+ }
1067
+ ]);
1068
+ }
1069
+ }),
1070
+ [uiWalletAccount.address, signTransaction]
1071
+ );
1072
+ }
1073
+ __name(useWalletAccountTransactionSigner, "useWalletAccountTransactionSigner");
1074
+ function uint8ArraysEqual(arr1, arr2) {
1075
+ return arr1.length === arr2.length && arr1.every((value, index) => value === arr2[index]);
1076
+ }
1077
+ __name(uint8ArraysEqual, "uint8ArraysEqual");
1078
+ function useWalletAccountTransactionSendingSigner(uiWalletAccount, chain) {
1079
+ const encoderRef = react.useRef(null);
1080
+ const signAndSendTransaction = useSignAndSendTransaction(uiWalletAccount, chain);
1081
+ return react.useMemo(
1082
+ () => ({
1083
+ address: addresses.address(uiWalletAccount.address),
1084
+ async signAndSendTransactions(transactions$1, config = {}) {
1085
+ const { abortSignal, ...options } = config;
1086
+ abortSignal?.throwIfAborted();
1087
+ let transactionEncoder = encoderRef.current;
1088
+ if (!transactionEncoder) {
1089
+ transactionEncoder = transactions.getTransactionEncoder();
1090
+ encoderRef.current = transactionEncoder;
1091
+ }
1092
+ if (transactions$1.length > 1) {
1093
+ throw new errors$1.SolanaError(errors$1.SOLANA_ERROR__SIGNER__WALLET_MULTISIGN_UNIMPLEMENTED);
1094
+ }
1095
+ if (transactions$1.length === 0) {
1096
+ return [];
1097
+ }
1098
+ const [transaction] = transactions$1;
1099
+ const wireTransactionBytes = transactionEncoder.encode(transaction);
1100
+ const inputWithOptions = {
1101
+ ...options,
1102
+ transaction: wireTransactionBytes
1103
+ };
1104
+ const { signature } = await promises.getAbortablePromise(signAndSendTransaction(inputWithOptions), abortSignal);
1105
+ return Object.freeze([signature]);
1106
+ }
1107
+ }),
1108
+ [signAndSendTransaction, uiWalletAccount.address]
1109
+ );
1110
+ }
1111
+ __name(useWalletAccountTransactionSendingSigner, "useWalletAccountTransactionSendingSigner");
1112
+
1113
+ exports.SolanaClientProvider = SolanaClientProvider;
1114
+ exports.SolanaQueryProvider = SolanaQueryProvider;
1115
+ exports.useAccount = useAccount;
1116
+ exports.useBalance = useBalance;
1117
+ exports.useClientStore = useClientStore;
1118
+ exports.useClusterState = useClusterState;
1119
+ exports.useClusterStatus = useClusterStatus;
1120
+ exports.useConnectWallet = useConnectWallet;
1121
+ exports.useDisconnectWallet = useDisconnectWallet;
1122
+ exports.useLatestBlockhash = useLatestBlockhash;
1123
+ exports.useProgramAccounts = useProgramAccounts;
1124
+ exports.useSendTransaction = useSendTransaction;
1125
+ exports.useSignAndSendTransaction = useSignAndSendTransaction;
1126
+ exports.useSignIn = useSignIn;
1127
+ exports.useSignMessage = useSignMessage;
1128
+ exports.useSignTransaction = useSignTransaction;
1129
+ exports.useSignatureStatus = useSignatureStatus;
1130
+ exports.useSimulateTransaction = useSimulateTransaction;
1131
+ exports.useSolTransfer = useSolTransfer;
1132
+ exports.useSolanaClient = useSolanaClient;
1133
+ exports.useSplToken = useSplToken;
1134
+ exports.useTransactionPool = useTransactionPool;
1135
+ exports.useWaitForSignature = useWaitForSignature;
1136
+ exports.useWallet = useWallet;
1137
+ exports.useWalletAccountMessageSigner = useWalletAccountMessageSigner;
1138
+ exports.useWalletAccountTransactionSendingSigner = useWalletAccountTransactionSendingSigner;
1139
+ exports.useWalletAccountTransactionSigner = useWalletAccountTransactionSigner;
1140
+ exports.useWalletActions = useWalletActions;
1141
+ exports.useWalletSession = useWalletSession;
1142
+ exports.useWalletStandardConnectors = useWalletStandardConnectors;
1143
+ //# sourceMappingURL=index.browser.cjs.map
1144
+ //# sourceMappingURL=index.browser.cjs.map