@solana/react-hooks 0.2.4 → 0.3.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 +7 -2
- package/dist/index.browser.cjs +99 -414
- package/dist/index.browser.cjs.map +1 -1
- package/dist/index.browser.mjs +96 -404
- package/dist/index.browser.mjs.map +1 -1
- package/dist/index.native.mjs +96 -404
- package/dist/index.native.mjs.map +1 -1
- package/dist/index.node.cjs +99 -414
- package/dist/index.node.cjs.map +1 -1
- package/dist/index.node.mjs +96 -404
- package/dist/index.node.mjs.map +1 -1
- package/dist/types/SolanaProvider.d.ts.map +1 -1
- package/dist/types/hooks.d.ts +11 -18
- package/dist/types/hooks.d.ts.map +1 -1
- package/dist/types/index.d.ts +0 -2
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/ui.d.ts +4 -1
- package/dist/types/ui.d.ts.map +1 -1
- package/package.json +2 -2
- package/dist/types/walletStandardHooks.d.ts +0 -78
- package/dist/types/walletStandardHooks.d.ts.map +0 -1
package/dist/index.browser.mjs
CHANGED
|
@@ -1,18 +1,9 @@
|
|
|
1
|
-
import { createClient, toAddress, toAddressString, stableStringify, createSolTransferController, createSplTransferController, getWalletStandardConnectors, watchWalletStandardConnectors, createTransactionPoolController, createInitialAsyncState, createAsyncState, normalizeSignature, SIGNATURE_STATUS_TIMEOUT_MS, deriveConfirmationStatus, confirmationMeetsCommitment } from '@solana/client';
|
|
1
|
+
import { createClient, toAddress, toAddressString, stableStringify, createSolTransferController, createSplTransferController, getWalletStandardConnectors, watchWalletStandardConnectors, createTransactionPoolController, createInitialAsyncState, createAsyncState, normalizeSignature, SIGNATURE_STATUS_TIMEOUT_MS, deriveConfirmationStatus, confirmationMeetsCommitment, deserializeSolanaState, subscribeSolanaState, serializeSolanaState } from '@solana/client';
|
|
2
2
|
import { createContext, useMemo, useEffect, useContext, useCallback, useRef, useSyncExternalStore, useState } from 'react';
|
|
3
3
|
import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
|
|
4
4
|
import useSWR, { SWRConfig } from 'swr';
|
|
5
5
|
import { useStore } from 'zustand';
|
|
6
6
|
import { getBase64EncodedWireTransaction } from '@solana/kit';
|
|
7
|
-
import { address } from '@solana/addresses';
|
|
8
|
-
import { SolanaError, SOLANA_ERROR__SIGNER__WALLET_MULTISIGN_UNIMPLEMENTED } from '@solana/errors';
|
|
9
|
-
import { getAbortablePromise } from '@solana/promises';
|
|
10
|
-
import { getCompiledTransactionMessageDecoder } from '@solana/transaction-messages';
|
|
11
|
-
import { getTransactionCodec, assertIsTransactionWithinSizeLimit, getTransactionLifetimeConstraintFromCompiledTransactionMessage, getTransactionEncoder } from '@solana/transactions';
|
|
12
|
-
import { SolanaSignAndSendTransaction, SolanaSignIn, SolanaSignMessage, SolanaSignTransaction } from '@solana/wallet-standard-features';
|
|
13
|
-
import { WalletStandardError, WALLET_STANDARD_ERROR__FEATURES__WALLET_ACCOUNT_CHAIN_UNSUPPORTED } from '@wallet-standard/errors';
|
|
14
|
-
import { getWalletAccountFeature, getWalletFeature } from '@wallet-standard/ui';
|
|
15
|
-
import { getWalletAccountForUiWalletAccount_DO_NOT_USE_OR_YOU_WILL_BE_FIRED, getWalletForHandle_DO_NOT_USE_OR_YOU_WILL_BE_FIRED, getOrCreateUiWalletAccountForStandardWalletAccount_DO_NOT_USE_OR_YOU_WILL_BE_FIRED } from '@wallet-standard/ui-registry';
|
|
16
7
|
|
|
17
8
|
var __defProp = Object.defineProperty;
|
|
18
9
|
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
@@ -142,12 +133,12 @@ __name(useLatestBlockhash, "useLatestBlockhash");
|
|
|
142
133
|
function useProgramAccounts(programAddress, options) {
|
|
143
134
|
const { commitment, config, ...queryOptions } = options ?? {};
|
|
144
135
|
const { disabled: disabledOption, ...restQueryOptions } = queryOptions;
|
|
145
|
-
const
|
|
146
|
-
const addressKey = useMemo(() =>
|
|
136
|
+
const address = useMemo(() => programAddress ? toAddress(programAddress) : void 0, [programAddress]);
|
|
137
|
+
const addressKey = useMemo(() => address ? toAddressString(address) : null, [address]);
|
|
147
138
|
const configKey = useMemo(() => stableStringify(config ?? null), [config]);
|
|
148
139
|
const fetcher = useCallback(
|
|
149
140
|
async (client) => {
|
|
150
|
-
if (!
|
|
141
|
+
if (!address) {
|
|
151
142
|
throw new Error("Provide a program address before querying program accounts.");
|
|
152
143
|
}
|
|
153
144
|
const fallbackCommitment = commitment ?? config?.commitment ?? client.store.getState().cluster.commitment;
|
|
@@ -155,12 +146,12 @@ function useProgramAccounts(programAddress, options) {
|
|
|
155
146
|
...config ?? {},
|
|
156
147
|
commitment: fallbackCommitment
|
|
157
148
|
};
|
|
158
|
-
const plan = client.runtime.rpc.getProgramAccounts(
|
|
149
|
+
const plan = client.runtime.rpc.getProgramAccounts(address, mergedConfig);
|
|
159
150
|
return plan.send({ abortSignal: AbortSignal.timeout(2e4) });
|
|
160
151
|
},
|
|
161
|
-
[
|
|
152
|
+
[address, commitment, config]
|
|
162
153
|
);
|
|
163
|
-
const disabled = disabledOption ?? !
|
|
154
|
+
const disabled = disabledOption ?? !address;
|
|
164
155
|
const query = useSolanaRpcQuery("programAccounts", [addressKey, configKey], fetcher, {
|
|
165
156
|
...restQueryOptions,
|
|
166
157
|
disabled
|
|
@@ -427,42 +418,42 @@ __name(useSplToken, "useSplToken");
|
|
|
427
418
|
function useAccount(addressLike, options = {}) {
|
|
428
419
|
const client = useSolanaClient();
|
|
429
420
|
const shouldSkip = options.skip ?? !addressLike;
|
|
430
|
-
const
|
|
421
|
+
const address = useMemo(() => {
|
|
431
422
|
if (shouldSkip || !addressLike) {
|
|
432
423
|
return void 0;
|
|
433
424
|
}
|
|
434
425
|
return toAddress(addressLike);
|
|
435
426
|
}, [addressLike, shouldSkip]);
|
|
436
|
-
const accountKey = useMemo(() =>
|
|
427
|
+
const accountKey = useMemo(() => address?.toString(), [address]);
|
|
437
428
|
const selector = useMemo(() => createAccountSelector(accountKey), [accountKey]);
|
|
438
429
|
const account = useClientStore(selector);
|
|
439
430
|
useSuspenseFetcher({
|
|
440
|
-
enabled: options.fetch !== false && !shouldSkip && Boolean(
|
|
431
|
+
enabled: options.fetch !== false && !shouldSkip && Boolean(address),
|
|
441
432
|
fetcher: /* @__PURE__ */ __name(() => {
|
|
442
|
-
if (!
|
|
433
|
+
if (!address) {
|
|
443
434
|
throw new Error("Provide an address before fetching account data.");
|
|
444
435
|
}
|
|
445
|
-
return client.actions.fetchAccount(
|
|
436
|
+
return client.actions.fetchAccount(address, options.commitment);
|
|
446
437
|
}, "fetcher"),
|
|
447
438
|
key: accountKey ?? null,
|
|
448
439
|
ready: account !== void 0
|
|
449
440
|
});
|
|
450
441
|
useEffect(() => {
|
|
451
|
-
if (!
|
|
442
|
+
if (!address) {
|
|
452
443
|
return;
|
|
453
444
|
}
|
|
454
445
|
const commitment = options.commitment;
|
|
455
446
|
if (options.fetch !== false && account === void 0) {
|
|
456
|
-
void client.actions.fetchAccount(
|
|
447
|
+
void client.actions.fetchAccount(address, commitment).catch(() => void 0);
|
|
457
448
|
}
|
|
458
449
|
if (options.watch) {
|
|
459
|
-
const subscription = client.watchers.watchAccount({ address
|
|
450
|
+
const subscription = client.watchers.watchAccount({ address, commitment }, () => void 0);
|
|
460
451
|
return () => {
|
|
461
452
|
subscription.abort();
|
|
462
453
|
};
|
|
463
454
|
}
|
|
464
455
|
return void 0;
|
|
465
|
-
}, [account,
|
|
456
|
+
}, [account, address, client, options.commitment, options.fetch, options.watch]);
|
|
466
457
|
return account;
|
|
467
458
|
}
|
|
468
459
|
__name(useAccount, "useAccount");
|
|
@@ -478,42 +469,42 @@ function useBalance(addressLike, options = {}) {
|
|
|
478
469
|
);
|
|
479
470
|
const client = useSolanaClient();
|
|
480
471
|
const shouldSkip = mergedOptions.skip ?? !addressLike;
|
|
481
|
-
const
|
|
472
|
+
const address = useMemo(() => {
|
|
482
473
|
if (shouldSkip || !addressLike) {
|
|
483
474
|
return void 0;
|
|
484
475
|
}
|
|
485
476
|
return toAddress(addressLike);
|
|
486
477
|
}, [addressLike, shouldSkip]);
|
|
487
|
-
const accountKey = useMemo(() =>
|
|
478
|
+
const accountKey = useMemo(() => address?.toString(), [address]);
|
|
488
479
|
const selector = useMemo(() => createAccountSelector(accountKey), [accountKey]);
|
|
489
480
|
const account = useClientStore(selector);
|
|
490
481
|
useSuspenseFetcher({
|
|
491
|
-
enabled: mergedOptions.fetch !== false && !shouldSkip && Boolean(
|
|
482
|
+
enabled: mergedOptions.fetch !== false && !shouldSkip && Boolean(address),
|
|
492
483
|
fetcher: /* @__PURE__ */ __name(() => {
|
|
493
|
-
if (!
|
|
484
|
+
if (!address) {
|
|
494
485
|
throw new Error("Provide an address before fetching balance.");
|
|
495
486
|
}
|
|
496
|
-
return client.actions.fetchBalance(
|
|
487
|
+
return client.actions.fetchBalance(address, mergedOptions.commitment);
|
|
497
488
|
}, "fetcher"),
|
|
498
489
|
key: accountKey ?? null,
|
|
499
490
|
ready: account !== void 0
|
|
500
491
|
});
|
|
501
492
|
useEffect(() => {
|
|
502
|
-
if (!
|
|
493
|
+
if (!address) {
|
|
503
494
|
return;
|
|
504
495
|
}
|
|
505
496
|
const commitment = mergedOptions.commitment;
|
|
506
497
|
if (mergedOptions.fetch !== false && account === void 0) {
|
|
507
|
-
void client.actions.fetchBalance(
|
|
498
|
+
void client.actions.fetchBalance(address, commitment).catch(() => void 0);
|
|
508
499
|
}
|
|
509
500
|
if (mergedOptions.watch) {
|
|
510
|
-
const watcher = client.watchers.watchBalance({ address
|
|
501
|
+
const watcher = client.watchers.watchBalance({ address, commitment }, () => void 0);
|
|
511
502
|
return () => {
|
|
512
503
|
watcher.abort();
|
|
513
504
|
};
|
|
514
505
|
}
|
|
515
506
|
return void 0;
|
|
516
|
-
}, [account,
|
|
507
|
+
}, [account, address, client, mergedOptions.commitment, mergedOptions.fetch, mergedOptions.watch]);
|
|
517
508
|
const lamports = account?.lamports ?? null;
|
|
518
509
|
const fetching = account?.fetching ?? false;
|
|
519
510
|
const slot = account?.slot;
|
|
@@ -532,17 +523,19 @@ function useBalance(addressLike, options = {}) {
|
|
|
532
523
|
__name(useBalance, "useBalance");
|
|
533
524
|
function useWalletStandardConnectors(options) {
|
|
534
525
|
const overrides = options?.overrides;
|
|
526
|
+
const disabled = options?.disabled ?? false;
|
|
535
527
|
const memoisedOptions = useMemo(() => overrides ? { overrides } : void 0, [overrides]);
|
|
536
528
|
const [connectors, setConnectors] = useState(
|
|
537
|
-
() => getWalletStandardConnectors(memoisedOptions ?? {})
|
|
529
|
+
() => disabled ? [] : getWalletStandardConnectors(memoisedOptions ?? {})
|
|
538
530
|
);
|
|
539
531
|
useEffect(() => {
|
|
532
|
+
if (disabled) return;
|
|
540
533
|
setConnectors(getWalletStandardConnectors(memoisedOptions ?? {}));
|
|
541
534
|
const unwatch = watchWalletStandardConnectors(setConnectors, memoisedOptions ?? {});
|
|
542
535
|
return () => {
|
|
543
536
|
unwatch();
|
|
544
537
|
};
|
|
545
|
-
}, [memoisedOptions]);
|
|
538
|
+
}, [disabled, memoisedOptions]);
|
|
546
539
|
return connectors;
|
|
547
540
|
}
|
|
548
541
|
__name(useWalletStandardConnectors, "useWalletStandardConnectors");
|
|
@@ -836,6 +829,10 @@ function SolanaProvider({ children, client, config, query, walletPersistence })
|
|
|
836
829
|
const shouldIncludeQueryLayer = query !== false && query?.disabled !== true;
|
|
837
830
|
const queryProps = shouldIncludeQueryLayer && query ? query : {};
|
|
838
831
|
const persistenceConfig = walletPersistence === false ? void 0 : walletPersistence ?? {};
|
|
832
|
+
const storage = persistenceConfig ? persistenceConfig.storage ?? getDefaultStorage() : null;
|
|
833
|
+
const storageKey = persistenceConfig?.storageKey ?? DEFAULT_STORAGE_KEY;
|
|
834
|
+
const persistedState = persistenceConfig ? readPersistedState(storage, storageKey) : { legacyConnectorId: null, state: null };
|
|
835
|
+
const clientConfig = config && persistenceConfig ? { ...config, initialState: config.initialState ?? persistedState.state ?? void 0 } : config;
|
|
839
836
|
const content = shouldIncludeQueryLayer ? /* @__PURE__ */ jsx(
|
|
840
837
|
SolanaQueryProvider,
|
|
841
838
|
{
|
|
@@ -845,21 +842,52 @@ function SolanaProvider({ children, client, config, query, walletPersistence })
|
|
|
845
842
|
children
|
|
846
843
|
}
|
|
847
844
|
) : children;
|
|
848
|
-
return /* @__PURE__ */ jsxs(SolanaClientProvider, { client, config, children: [
|
|
849
|
-
persistenceConfig ? /* @__PURE__ */ jsx(
|
|
845
|
+
return /* @__PURE__ */ jsxs(SolanaClientProvider, { client, config: clientConfig, children: [
|
|
846
|
+
persistenceConfig ? /* @__PURE__ */ jsx(
|
|
847
|
+
WalletPersistence,
|
|
848
|
+
{
|
|
849
|
+
autoConnect: persistenceConfig.autoConnect,
|
|
850
|
+
initialState: clientConfig?.initialState ?? persistedState.state,
|
|
851
|
+
legacyConnectorId: persistedState.legacyConnectorId,
|
|
852
|
+
storage,
|
|
853
|
+
storageKey
|
|
854
|
+
}
|
|
855
|
+
) : null,
|
|
850
856
|
content
|
|
851
857
|
] });
|
|
852
858
|
}
|
|
853
859
|
__name(SolanaProvider, "SolanaProvider");
|
|
854
860
|
var DEFAULT_STORAGE_KEY = "solana:last-connector";
|
|
855
|
-
function
|
|
861
|
+
function readPersistedState(storage, storageKey) {
|
|
862
|
+
if (!storage) {
|
|
863
|
+
return { legacyConnectorId: null, state: null };
|
|
864
|
+
}
|
|
865
|
+
const raw = safelyRead(() => storage.getItem(storageKey));
|
|
866
|
+
if (!raw) {
|
|
867
|
+
return { legacyConnectorId: null, state: null };
|
|
868
|
+
}
|
|
869
|
+
const parsed = deserializeSolanaState(raw);
|
|
870
|
+
if (parsed) {
|
|
871
|
+
return { legacyConnectorId: null, state: parsed };
|
|
872
|
+
}
|
|
873
|
+
return { legacyConnectorId: raw, state: null };
|
|
874
|
+
}
|
|
875
|
+
__name(readPersistedState, "readPersistedState");
|
|
876
|
+
function WalletPersistence({
|
|
877
|
+
autoConnect = true,
|
|
878
|
+
initialState = null,
|
|
879
|
+
legacyConnectorId = null,
|
|
880
|
+
storage,
|
|
881
|
+
storageKey = DEFAULT_STORAGE_KEY
|
|
882
|
+
}) {
|
|
856
883
|
const wallet = useWallet();
|
|
857
884
|
const connectWallet = useConnectWallet();
|
|
858
885
|
const client = useSolanaClient();
|
|
859
886
|
const storageRef = useRef(storage ?? getDefaultStorage());
|
|
860
887
|
const [hasAttemptedAutoConnect, setHasAttemptedAutoConnect] = useState(false);
|
|
861
|
-
const hasPersistedConnectorRef = useRef(false);
|
|
862
888
|
const clientRef = useRef(null);
|
|
889
|
+
const persistedStateRef = useRef(initialState);
|
|
890
|
+
const legacyConnectorIdRef = useRef(legacyConnectorId);
|
|
863
891
|
useEffect(() => {
|
|
864
892
|
storageRef.current = storage ?? getDefaultStorage();
|
|
865
893
|
}, [storage]);
|
|
@@ -872,19 +900,19 @@ function WalletPersistence({ autoConnect = true, storage, storageKey = DEFAULT_S
|
|
|
872
900
|
useEffect(() => {
|
|
873
901
|
const activeStorage = storageRef.current;
|
|
874
902
|
if (!activeStorage) return;
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
}
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
}, [
|
|
903
|
+
const unsubscribe = subscribeSolanaState(client, (state) => {
|
|
904
|
+
persistedStateRef.current = state;
|
|
905
|
+
legacyConnectorIdRef.current = null;
|
|
906
|
+
safelyWrite(() => activeStorage.setItem(storageKey, serializeSolanaState(state)));
|
|
907
|
+
});
|
|
908
|
+
return () => {
|
|
909
|
+
unsubscribe();
|
|
910
|
+
};
|
|
911
|
+
}, [client, storageKey]);
|
|
912
|
+
useEffect(() => {
|
|
913
|
+
persistedStateRef.current = initialState ?? persistedStateRef.current;
|
|
914
|
+
legacyConnectorIdRef.current = legacyConnectorId;
|
|
915
|
+
}, [initialState, legacyConnectorId]);
|
|
888
916
|
useEffect(() => {
|
|
889
917
|
if (!autoConnect || hasAttemptedAutoConnect) {
|
|
890
918
|
return;
|
|
@@ -893,35 +921,21 @@ function WalletPersistence({ autoConnect = true, storage, storageKey = DEFAULT_S
|
|
|
893
921
|
setHasAttemptedAutoConnect(true);
|
|
894
922
|
return;
|
|
895
923
|
}
|
|
896
|
-
const
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
}
|
|
901
|
-
let cancelled = false;
|
|
902
|
-
const connectorId = safelyRead(() => activeStorage.getItem(storageKey));
|
|
903
|
-
if (!connectorId) {
|
|
904
|
-
setHasAttemptedAutoConnect(true);
|
|
905
|
-
return;
|
|
906
|
-
}
|
|
924
|
+
const state = persistedStateRef.current ?? initialState;
|
|
925
|
+
const connectorId = state?.lastConnectorId ?? legacyConnectorIdRef.current;
|
|
926
|
+
const shouldAutoConnect = (state?.autoconnect ?? autoConnect) && connectorId;
|
|
927
|
+
if (!shouldAutoConnect || !connectorId) return;
|
|
907
928
|
const connector = client.connectors.get(connectorId);
|
|
908
|
-
if (!connector)
|
|
909
|
-
return;
|
|
910
|
-
}
|
|
929
|
+
if (!connector) return;
|
|
911
930
|
void (async () => {
|
|
912
931
|
try {
|
|
913
932
|
await connectWallet(connectorId, { autoConnect: true });
|
|
914
933
|
} catch {
|
|
915
934
|
} finally {
|
|
916
|
-
|
|
917
|
-
setHasAttemptedAutoConnect(true);
|
|
918
|
-
}
|
|
935
|
+
setHasAttemptedAutoConnect(true);
|
|
919
936
|
}
|
|
920
937
|
})();
|
|
921
|
-
|
|
922
|
-
cancelled = true;
|
|
923
|
-
};
|
|
924
|
-
}, [autoConnect, client, connectWallet, hasAttemptedAutoConnect, storageKey, wallet.status]);
|
|
938
|
+
}, [autoConnect, client, connectWallet, hasAttemptedAutoConnect, initialState, wallet.status]);
|
|
925
939
|
return null;
|
|
926
940
|
}
|
|
927
941
|
__name(WalletPersistence, "WalletPersistence");
|
|
@@ -955,8 +969,13 @@ function useWalletConnection(options = {}) {
|
|
|
955
969
|
const wallet = useWallet();
|
|
956
970
|
const connectWallet = useConnectWallet();
|
|
957
971
|
const disconnectWallet = useDisconnectWallet();
|
|
958
|
-
const
|
|
959
|
-
const
|
|
972
|
+
const client = useSolanaClient();
|
|
973
|
+
const shouldDiscover = !options.connectors && client.connectors.all.length === 0;
|
|
974
|
+
const discovered = useWalletStandardConnectors({
|
|
975
|
+
...options.discoveryOptions,
|
|
976
|
+
disabled: !shouldDiscover
|
|
977
|
+
});
|
|
978
|
+
const connectors = options.connectors ?? (client.connectors.all.length > 0 ? client.connectors.all : discovered);
|
|
960
979
|
const connect = useCallback(
|
|
961
980
|
(connectorId, connectOptions) => connectWallet(connectorId, connectOptions),
|
|
962
981
|
[connectWallet]
|
|
@@ -1017,334 +1036,7 @@ function useWalletModalState(options = {}) {
|
|
|
1017
1036
|
};
|
|
1018
1037
|
}
|
|
1019
1038
|
__name(useWalletModalState, "useWalletModalState");
|
|
1020
|
-
function useSignAndSendTransaction(uiWalletAccount, chain) {
|
|
1021
|
-
const signAndSendTransactions = useSignAndSendTransactions(uiWalletAccount, chain);
|
|
1022
|
-
return useCallback(
|
|
1023
|
-
async (input) => {
|
|
1024
|
-
const [result] = await signAndSendTransactions(input);
|
|
1025
|
-
return result;
|
|
1026
|
-
},
|
|
1027
|
-
[signAndSendTransactions]
|
|
1028
|
-
);
|
|
1029
|
-
}
|
|
1030
|
-
__name(useSignAndSendTransaction, "useSignAndSendTransaction");
|
|
1031
|
-
function useSignAndSendTransactions(uiWalletAccount, chain) {
|
|
1032
|
-
if (!uiWalletAccount.chains.includes(chain)) {
|
|
1033
|
-
throw new WalletStandardError(WALLET_STANDARD_ERROR__FEATURES__WALLET_ACCOUNT_CHAIN_UNSUPPORTED, {
|
|
1034
|
-
address: uiWalletAccount.address,
|
|
1035
|
-
chain,
|
|
1036
|
-
featureName: SolanaSignAndSendTransaction,
|
|
1037
|
-
supportedChains: [...uiWalletAccount.chains],
|
|
1038
|
-
supportedFeatures: [...uiWalletAccount.features]
|
|
1039
|
-
});
|
|
1040
|
-
}
|
|
1041
|
-
const signAndSendTransactionFeature = getWalletAccountFeature(
|
|
1042
|
-
uiWalletAccount,
|
|
1043
|
-
SolanaSignAndSendTransaction
|
|
1044
|
-
);
|
|
1045
|
-
const account = getWalletAccountForUiWalletAccount_DO_NOT_USE_OR_YOU_WILL_BE_FIRED(uiWalletAccount);
|
|
1046
|
-
return useCallback(
|
|
1047
|
-
async (...inputs) => {
|
|
1048
|
-
const inputsWithChainAndAccount = inputs.map(({ options, ...rest }) => {
|
|
1049
|
-
const minContextSlot = options?.minContextSlot;
|
|
1050
|
-
return {
|
|
1051
|
-
...rest,
|
|
1052
|
-
account,
|
|
1053
|
-
chain,
|
|
1054
|
-
...minContextSlot != null ? {
|
|
1055
|
-
options: {
|
|
1056
|
-
minContextSlot: Number(minContextSlot)
|
|
1057
|
-
}
|
|
1058
|
-
} : null
|
|
1059
|
-
};
|
|
1060
|
-
});
|
|
1061
|
-
const results = await signAndSendTransactionFeature.signAndSendTransaction(...inputsWithChainAndAccount);
|
|
1062
|
-
return results;
|
|
1063
|
-
},
|
|
1064
|
-
[account, chain, signAndSendTransactionFeature]
|
|
1065
|
-
);
|
|
1066
|
-
}
|
|
1067
|
-
__name(useSignAndSendTransactions, "useSignAndSendTransactions");
|
|
1068
|
-
function useSignIn(uiWalletHandle) {
|
|
1069
|
-
const signIns = useSignIns(uiWalletHandle);
|
|
1070
|
-
return useCallback(
|
|
1071
|
-
async (input) => {
|
|
1072
|
-
const [result] = await signIns(input);
|
|
1073
|
-
return result;
|
|
1074
|
-
},
|
|
1075
|
-
[signIns]
|
|
1076
|
-
);
|
|
1077
|
-
}
|
|
1078
|
-
__name(useSignIn, "useSignIn");
|
|
1079
|
-
function useSignIns(uiWalletHandle) {
|
|
1080
|
-
let signMessageFeature;
|
|
1081
|
-
if ("address" in uiWalletHandle && typeof uiWalletHandle.address === "string") {
|
|
1082
|
-
getWalletAccountForUiWalletAccount_DO_NOT_USE_OR_YOU_WILL_BE_FIRED(uiWalletHandle);
|
|
1083
|
-
signMessageFeature = getWalletAccountFeature(
|
|
1084
|
-
uiWalletHandle,
|
|
1085
|
-
SolanaSignIn
|
|
1086
|
-
);
|
|
1087
|
-
} else {
|
|
1088
|
-
signMessageFeature = getWalletFeature(uiWalletHandle, SolanaSignIn);
|
|
1089
|
-
}
|
|
1090
|
-
const wallet = getWalletForHandle_DO_NOT_USE_OR_YOU_WILL_BE_FIRED(uiWalletHandle);
|
|
1091
|
-
return useCallback(
|
|
1092
|
-
async (...inputs) => {
|
|
1093
|
-
const inputsWithAddressAndChainId = inputs.map((input) => ({
|
|
1094
|
-
...input,
|
|
1095
|
-
// Prioritize the `UiWalletAccount` address if it exists.
|
|
1096
|
-
..."address" in uiWalletHandle ? { address: uiWalletHandle.address } : null
|
|
1097
|
-
}));
|
|
1098
|
-
const results = await signMessageFeature.signIn(...inputsWithAddressAndChainId);
|
|
1099
|
-
const resultsWithoutSignatureType = results.map(
|
|
1100
|
-
({
|
|
1101
|
-
account,
|
|
1102
|
-
signatureType: _signatureType,
|
|
1103
|
-
// Solana signatures are always of type `ed25519` so drop this property.
|
|
1104
|
-
...rest
|
|
1105
|
-
}) => ({
|
|
1106
|
-
...rest,
|
|
1107
|
-
account: getOrCreateUiWalletAccountForStandardWalletAccount_DO_NOT_USE_OR_YOU_WILL_BE_FIRED(
|
|
1108
|
-
wallet,
|
|
1109
|
-
account
|
|
1110
|
-
)
|
|
1111
|
-
})
|
|
1112
|
-
);
|
|
1113
|
-
return resultsWithoutSignatureType;
|
|
1114
|
-
},
|
|
1115
|
-
[signMessageFeature, uiWalletHandle, wallet]
|
|
1116
|
-
);
|
|
1117
|
-
}
|
|
1118
|
-
__name(useSignIns, "useSignIns");
|
|
1119
|
-
function useSignMessage(...config) {
|
|
1120
|
-
const signMessages = useSignMessages(...config);
|
|
1121
|
-
return useCallback(
|
|
1122
|
-
async (input) => {
|
|
1123
|
-
const [result] = await signMessages(input);
|
|
1124
|
-
return result;
|
|
1125
|
-
},
|
|
1126
|
-
[signMessages]
|
|
1127
|
-
);
|
|
1128
|
-
}
|
|
1129
|
-
__name(useSignMessage, "useSignMessage");
|
|
1130
|
-
function useSignMessages(uiWalletAccount) {
|
|
1131
|
-
const signMessageFeature = getWalletAccountFeature(
|
|
1132
|
-
uiWalletAccount,
|
|
1133
|
-
SolanaSignMessage
|
|
1134
|
-
);
|
|
1135
|
-
const account = getWalletAccountForUiWalletAccount_DO_NOT_USE_OR_YOU_WILL_BE_FIRED(uiWalletAccount);
|
|
1136
|
-
return useCallback(
|
|
1137
|
-
async (...inputs) => {
|
|
1138
|
-
const inputsWithAccount = inputs.map((input) => ({ ...input, account }));
|
|
1139
|
-
const results = await signMessageFeature.signMessage(...inputsWithAccount);
|
|
1140
|
-
const resultsWithoutSignatureType = results.map(
|
|
1141
|
-
({
|
|
1142
|
-
signatureType: _signatureType,
|
|
1143
|
-
// Solana signatures are always of type `ed25519` so drop this property.
|
|
1144
|
-
...rest
|
|
1145
|
-
}) => rest
|
|
1146
|
-
);
|
|
1147
|
-
return resultsWithoutSignatureType;
|
|
1148
|
-
},
|
|
1149
|
-
[signMessageFeature, account]
|
|
1150
|
-
);
|
|
1151
|
-
}
|
|
1152
|
-
__name(useSignMessages, "useSignMessages");
|
|
1153
|
-
function useSignTransaction(uiWalletAccount, chain) {
|
|
1154
|
-
const signTransactions = useSignTransactions(uiWalletAccount, chain);
|
|
1155
|
-
return useCallback(
|
|
1156
|
-
async (input) => {
|
|
1157
|
-
const [result] = await signTransactions(input);
|
|
1158
|
-
return result;
|
|
1159
|
-
},
|
|
1160
|
-
[signTransactions]
|
|
1161
|
-
);
|
|
1162
|
-
}
|
|
1163
|
-
__name(useSignTransaction, "useSignTransaction");
|
|
1164
|
-
function useSignTransactions(uiWalletAccount, chain) {
|
|
1165
|
-
if (!uiWalletAccount.chains.includes(chain)) {
|
|
1166
|
-
throw new WalletStandardError(WALLET_STANDARD_ERROR__FEATURES__WALLET_ACCOUNT_CHAIN_UNSUPPORTED, {
|
|
1167
|
-
address: uiWalletAccount.address,
|
|
1168
|
-
chain,
|
|
1169
|
-
featureName: SolanaSignAndSendTransaction,
|
|
1170
|
-
supportedChains: [...uiWalletAccount.chains],
|
|
1171
|
-
supportedFeatures: [...uiWalletAccount.features]
|
|
1172
|
-
});
|
|
1173
|
-
}
|
|
1174
|
-
const signTransactionFeature = getWalletAccountFeature(
|
|
1175
|
-
uiWalletAccount,
|
|
1176
|
-
SolanaSignTransaction
|
|
1177
|
-
);
|
|
1178
|
-
const account = getWalletAccountForUiWalletAccount_DO_NOT_USE_OR_YOU_WILL_BE_FIRED(uiWalletAccount);
|
|
1179
|
-
return useCallback(
|
|
1180
|
-
async (...inputs) => {
|
|
1181
|
-
const inputsWithAccountAndChain = inputs.map(({ options, ...rest }) => {
|
|
1182
|
-
const minContextSlot = options?.minContextSlot;
|
|
1183
|
-
return {
|
|
1184
|
-
...rest,
|
|
1185
|
-
account,
|
|
1186
|
-
chain,
|
|
1187
|
-
...minContextSlot != null ? {
|
|
1188
|
-
options: {
|
|
1189
|
-
minContextSlot: Number(minContextSlot)
|
|
1190
|
-
}
|
|
1191
|
-
} : null
|
|
1192
|
-
};
|
|
1193
|
-
});
|
|
1194
|
-
const results = await signTransactionFeature.signTransaction(...inputsWithAccountAndChain);
|
|
1195
|
-
return results;
|
|
1196
|
-
},
|
|
1197
|
-
[signTransactionFeature, account, chain]
|
|
1198
|
-
);
|
|
1199
|
-
}
|
|
1200
|
-
__name(useSignTransactions, "useSignTransactions");
|
|
1201
|
-
function useWalletAccountMessageSigner(uiWalletAccount) {
|
|
1202
|
-
const signMessage = useSignMessage(uiWalletAccount);
|
|
1203
|
-
return useMemo(
|
|
1204
|
-
() => ({
|
|
1205
|
-
address: address(uiWalletAccount.address),
|
|
1206
|
-
async modifyAndSignMessages(messages, config) {
|
|
1207
|
-
config?.abortSignal?.throwIfAborted();
|
|
1208
|
-
if (messages.length > 1) {
|
|
1209
|
-
throw new SolanaError(SOLANA_ERROR__SIGNER__WALLET_MULTISIGN_UNIMPLEMENTED);
|
|
1210
|
-
}
|
|
1211
|
-
if (messages.length === 0) {
|
|
1212
|
-
return messages;
|
|
1213
|
-
}
|
|
1214
|
-
const { content: originalMessage, signatures: originalSignatureMap } = messages[0];
|
|
1215
|
-
const input = {
|
|
1216
|
-
message: originalMessage
|
|
1217
|
-
};
|
|
1218
|
-
const { signedMessage, signature } = await getAbortablePromise(signMessage(input), config?.abortSignal);
|
|
1219
|
-
const messageWasModified = originalMessage.length !== signedMessage.length || originalMessage.some((originalByte, ii) => originalByte !== signedMessage[ii]);
|
|
1220
|
-
const originalSignature = originalSignatureMap[uiWalletAccount.address];
|
|
1221
|
-
const signatureIsNew = !originalSignature?.every((originalByte, ii) => originalByte === signature[ii]);
|
|
1222
|
-
if (!signatureIsNew && !messageWasModified) {
|
|
1223
|
-
return messages;
|
|
1224
|
-
}
|
|
1225
|
-
const nextSignatureMap = messageWasModified ? { [uiWalletAccount.address]: signature } : { ...originalSignatureMap, [uiWalletAccount.address]: signature };
|
|
1226
|
-
const outputMessages = Object.freeze([
|
|
1227
|
-
Object.freeze({
|
|
1228
|
-
content: signedMessage,
|
|
1229
|
-
signatures: Object.freeze(nextSignatureMap)
|
|
1230
|
-
})
|
|
1231
|
-
]);
|
|
1232
|
-
return outputMessages;
|
|
1233
|
-
}
|
|
1234
|
-
}),
|
|
1235
|
-
[uiWalletAccount, signMessage]
|
|
1236
|
-
);
|
|
1237
|
-
}
|
|
1238
|
-
__name(useWalletAccountMessageSigner, "useWalletAccountMessageSigner");
|
|
1239
|
-
function useWalletAccountTransactionSigner(uiWalletAccount, chain) {
|
|
1240
|
-
const encoderRef = useRef(null);
|
|
1241
|
-
const signTransaction = useSignTransaction(uiWalletAccount, chain);
|
|
1242
|
-
return useMemo(
|
|
1243
|
-
() => ({
|
|
1244
|
-
address: address(uiWalletAccount.address),
|
|
1245
|
-
async modifyAndSignTransactions(transactions, config = {}) {
|
|
1246
|
-
const { abortSignal, ...options } = config;
|
|
1247
|
-
abortSignal?.throwIfAborted();
|
|
1248
|
-
let transactionCodec = encoderRef.current;
|
|
1249
|
-
if (!transactionCodec) {
|
|
1250
|
-
transactionCodec = getTransactionCodec();
|
|
1251
|
-
encoderRef.current = transactionCodec;
|
|
1252
|
-
}
|
|
1253
|
-
if (transactions.length > 1) {
|
|
1254
|
-
throw new SolanaError(SOLANA_ERROR__SIGNER__WALLET_MULTISIGN_UNIMPLEMENTED);
|
|
1255
|
-
}
|
|
1256
|
-
if (transactions.length === 0) {
|
|
1257
|
-
return transactions;
|
|
1258
|
-
}
|
|
1259
|
-
const [transaction] = transactions;
|
|
1260
|
-
const wireTransactionBytes = transactionCodec.encode(transaction);
|
|
1261
|
-
const inputWithOptions = {
|
|
1262
|
-
...options,
|
|
1263
|
-
transaction: wireTransactionBytes
|
|
1264
|
-
};
|
|
1265
|
-
const { signedTransaction } = await getAbortablePromise(signTransaction(inputWithOptions), abortSignal);
|
|
1266
|
-
const decodedSignedTransaction = transactionCodec.decode(
|
|
1267
|
-
signedTransaction
|
|
1268
|
-
);
|
|
1269
|
-
assertIsTransactionWithinSizeLimit(decodedSignedTransaction);
|
|
1270
|
-
const existingLifetime = "lifetimeConstraint" in transaction ? transaction.lifetimeConstraint : void 0;
|
|
1271
|
-
if (existingLifetime) {
|
|
1272
|
-
if (uint8ArraysEqual(decodedSignedTransaction.messageBytes, transaction.messageBytes)) {
|
|
1273
|
-
return Object.freeze([
|
|
1274
|
-
{
|
|
1275
|
-
...decodedSignedTransaction,
|
|
1276
|
-
lifetimeConstraint: existingLifetime
|
|
1277
|
-
}
|
|
1278
|
-
]);
|
|
1279
|
-
}
|
|
1280
|
-
const compiledTransactionMessage2 = getCompiledTransactionMessageDecoder().decode(
|
|
1281
|
-
decodedSignedTransaction.messageBytes
|
|
1282
|
-
);
|
|
1283
|
-
const currentToken = "blockhash" in existingLifetime ? existingLifetime.blockhash : existingLifetime.nonce;
|
|
1284
|
-
if (compiledTransactionMessage2.lifetimeToken === currentToken) {
|
|
1285
|
-
return Object.freeze([
|
|
1286
|
-
{
|
|
1287
|
-
...decodedSignedTransaction,
|
|
1288
|
-
lifetimeConstraint: existingLifetime
|
|
1289
|
-
}
|
|
1290
|
-
]);
|
|
1291
|
-
}
|
|
1292
|
-
}
|
|
1293
|
-
const compiledTransactionMessage = getCompiledTransactionMessageDecoder().decode(
|
|
1294
|
-
decodedSignedTransaction.messageBytes
|
|
1295
|
-
);
|
|
1296
|
-
const lifetimeConstraint = await getTransactionLifetimeConstraintFromCompiledTransactionMessage(compiledTransactionMessage);
|
|
1297
|
-
return Object.freeze([
|
|
1298
|
-
{
|
|
1299
|
-
...decodedSignedTransaction,
|
|
1300
|
-
lifetimeConstraint
|
|
1301
|
-
}
|
|
1302
|
-
]);
|
|
1303
|
-
}
|
|
1304
|
-
}),
|
|
1305
|
-
[uiWalletAccount.address, signTransaction]
|
|
1306
|
-
);
|
|
1307
|
-
}
|
|
1308
|
-
__name(useWalletAccountTransactionSigner, "useWalletAccountTransactionSigner");
|
|
1309
|
-
function uint8ArraysEqual(arr1, arr2) {
|
|
1310
|
-
return arr1.length === arr2.length && arr1.every((value, index) => value === arr2[index]);
|
|
1311
|
-
}
|
|
1312
|
-
__name(uint8ArraysEqual, "uint8ArraysEqual");
|
|
1313
|
-
function useWalletAccountTransactionSendingSigner(uiWalletAccount, chain) {
|
|
1314
|
-
const encoderRef = useRef(null);
|
|
1315
|
-
const signAndSendTransaction = useSignAndSendTransaction(uiWalletAccount, chain);
|
|
1316
|
-
return useMemo(
|
|
1317
|
-
() => ({
|
|
1318
|
-
address: address(uiWalletAccount.address),
|
|
1319
|
-
async signAndSendTransactions(transactions, config = {}) {
|
|
1320
|
-
const { abortSignal, ...options } = config;
|
|
1321
|
-
abortSignal?.throwIfAborted();
|
|
1322
|
-
let transactionEncoder = encoderRef.current;
|
|
1323
|
-
if (!transactionEncoder) {
|
|
1324
|
-
transactionEncoder = getTransactionEncoder();
|
|
1325
|
-
encoderRef.current = transactionEncoder;
|
|
1326
|
-
}
|
|
1327
|
-
if (transactions.length > 1) {
|
|
1328
|
-
throw new SolanaError(SOLANA_ERROR__SIGNER__WALLET_MULTISIGN_UNIMPLEMENTED);
|
|
1329
|
-
}
|
|
1330
|
-
if (transactions.length === 0) {
|
|
1331
|
-
return [];
|
|
1332
|
-
}
|
|
1333
|
-
const [transaction] = transactions;
|
|
1334
|
-
const wireTransactionBytes = transactionEncoder.encode(transaction);
|
|
1335
|
-
const inputWithOptions = {
|
|
1336
|
-
...options,
|
|
1337
|
-
transaction: wireTransactionBytes
|
|
1338
|
-
};
|
|
1339
|
-
const { signature } = await getAbortablePromise(signAndSendTransaction(inputWithOptions), abortSignal);
|
|
1340
|
-
return Object.freeze([signature]);
|
|
1341
|
-
}
|
|
1342
|
-
}),
|
|
1343
|
-
[signAndSendTransaction, uiWalletAccount.address]
|
|
1344
|
-
);
|
|
1345
|
-
}
|
|
1346
|
-
__name(useWalletAccountTransactionSendingSigner, "useWalletAccountTransactionSendingSigner");
|
|
1347
1039
|
|
|
1348
|
-
export { SolanaClientProvider, SolanaProvider, SolanaQueryProvider, WalletConnectionManager, useAccount, useBalance, useClientStore, useClusterState, useClusterStatus, useConnectWallet, useDisconnectWallet, useLatestBlockhash, useProgramAccounts, useSendTransaction,
|
|
1040
|
+
export { SolanaClientProvider, SolanaProvider, SolanaQueryProvider, WalletConnectionManager, useAccount, useBalance, useClientStore, useClusterState, useClusterStatus, useConnectWallet, useDisconnectWallet, useLatestBlockhash, useProgramAccounts, useSendTransaction, useSignatureStatus, useSimulateTransaction, useSolTransfer, useSolanaClient, useSplToken, useTransactionPool, useWaitForSignature, useWallet, useWalletActions, useWalletConnection, useWalletModalState, useWalletSession, useWalletStandardConnectors };
|
|
1349
1041
|
//# sourceMappingURL=index.browser.mjs.map
|
|
1350
1042
|
//# sourceMappingURL=index.browser.mjs.map
|