@solana/react-hooks 0.2.5 → 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.
@@ -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
 
@@ -148,12 +139,12 @@ __name(useLatestBlockhash, "useLatestBlockhash");
148
139
  function useProgramAccounts(programAddress, options) {
149
140
  const { commitment, config, ...queryOptions } = options ?? {};
150
141
  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]);
142
+ const address = react.useMemo(() => programAddress ? client.toAddress(programAddress) : void 0, [programAddress]);
143
+ const addressKey = react.useMemo(() => address ? client.toAddressString(address) : null, [address]);
153
144
  const configKey = react.useMemo(() => client.stableStringify(config ?? null), [config]);
154
145
  const fetcher = react.useCallback(
155
146
  async (client) => {
156
- if (!address2) {
147
+ if (!address) {
157
148
  throw new Error("Provide a program address before querying program accounts.");
158
149
  }
159
150
  const fallbackCommitment = commitment ?? config?.commitment ?? client.store.getState().cluster.commitment;
@@ -161,12 +152,12 @@ function useProgramAccounts(programAddress, options) {
161
152
  ...config ?? {},
162
153
  commitment: fallbackCommitment
163
154
  };
164
- const plan = client.runtime.rpc.getProgramAccounts(address2, mergedConfig);
155
+ const plan = client.runtime.rpc.getProgramAccounts(address, mergedConfig);
165
156
  return plan.send({ abortSignal: AbortSignal.timeout(2e4) });
166
157
  },
167
- [address2, commitment, config]
158
+ [address, commitment, config]
168
159
  );
169
- const disabled = disabledOption ?? !address2;
160
+ const disabled = disabledOption ?? !address;
170
161
  const query = useSolanaRpcQuery("programAccounts", [addressKey, configKey], fetcher, {
171
162
  ...restQueryOptions,
172
163
  disabled
@@ -433,42 +424,42 @@ __name(useSplToken, "useSplToken");
433
424
  function useAccount(addressLike, options = {}) {
434
425
  const client$1 = useSolanaClient();
435
426
  const shouldSkip = options.skip ?? !addressLike;
436
- const address2 = react.useMemo(() => {
427
+ const address = react.useMemo(() => {
437
428
  if (shouldSkip || !addressLike) {
438
429
  return void 0;
439
430
  }
440
431
  return client.toAddress(addressLike);
441
432
  }, [addressLike, shouldSkip]);
442
- const accountKey = react.useMemo(() => address2?.toString(), [address2]);
433
+ const accountKey = react.useMemo(() => address?.toString(), [address]);
443
434
  const selector = react.useMemo(() => createAccountSelector(accountKey), [accountKey]);
444
435
  const account = useClientStore(selector);
445
436
  useSuspenseFetcher({
446
- enabled: options.fetch !== false && !shouldSkip && Boolean(address2),
437
+ enabled: options.fetch !== false && !shouldSkip && Boolean(address),
447
438
  fetcher: /* @__PURE__ */ __name(() => {
448
- if (!address2) {
439
+ if (!address) {
449
440
  throw new Error("Provide an address before fetching account data.");
450
441
  }
451
- return client$1.actions.fetchAccount(address2, options.commitment);
442
+ return client$1.actions.fetchAccount(address, options.commitment);
452
443
  }, "fetcher"),
453
444
  key: accountKey ?? null,
454
445
  ready: account !== void 0
455
446
  });
456
447
  react.useEffect(() => {
457
- if (!address2) {
448
+ if (!address) {
458
449
  return;
459
450
  }
460
451
  const commitment = options.commitment;
461
452
  if (options.fetch !== false && account === void 0) {
462
- void client$1.actions.fetchAccount(address2, commitment).catch(() => void 0);
453
+ void client$1.actions.fetchAccount(address, commitment).catch(() => void 0);
463
454
  }
464
455
  if (options.watch) {
465
- const subscription = client$1.watchers.watchAccount({ address: address2, commitment }, () => void 0);
456
+ const subscription = client$1.watchers.watchAccount({ address, commitment }, () => void 0);
466
457
  return () => {
467
458
  subscription.abort();
468
459
  };
469
460
  }
470
461
  return void 0;
471
- }, [account, address2, client$1, options.commitment, options.fetch, options.watch]);
462
+ }, [account, address, client$1, options.commitment, options.fetch, options.watch]);
472
463
  return account;
473
464
  }
474
465
  __name(useAccount, "useAccount");
@@ -484,42 +475,42 @@ function useBalance(addressLike, options = {}) {
484
475
  );
485
476
  const client$1 = useSolanaClient();
486
477
  const shouldSkip = mergedOptions.skip ?? !addressLike;
487
- const address2 = react.useMemo(() => {
478
+ const address = react.useMemo(() => {
488
479
  if (shouldSkip || !addressLike) {
489
480
  return void 0;
490
481
  }
491
482
  return client.toAddress(addressLike);
492
483
  }, [addressLike, shouldSkip]);
493
- const accountKey = react.useMemo(() => address2?.toString(), [address2]);
484
+ const accountKey = react.useMemo(() => address?.toString(), [address]);
494
485
  const selector = react.useMemo(() => createAccountSelector(accountKey), [accountKey]);
495
486
  const account = useClientStore(selector);
496
487
  useSuspenseFetcher({
497
- enabled: mergedOptions.fetch !== false && !shouldSkip && Boolean(address2),
488
+ enabled: mergedOptions.fetch !== false && !shouldSkip && Boolean(address),
498
489
  fetcher: /* @__PURE__ */ __name(() => {
499
- if (!address2) {
490
+ if (!address) {
500
491
  throw new Error("Provide an address before fetching balance.");
501
492
  }
502
- return client$1.actions.fetchBalance(address2, mergedOptions.commitment);
493
+ return client$1.actions.fetchBalance(address, mergedOptions.commitment);
503
494
  }, "fetcher"),
504
495
  key: accountKey ?? null,
505
496
  ready: account !== void 0
506
497
  });
507
498
  react.useEffect(() => {
508
- if (!address2) {
499
+ if (!address) {
509
500
  return;
510
501
  }
511
502
  const commitment = mergedOptions.commitment;
512
503
  if (mergedOptions.fetch !== false && account === void 0) {
513
- void client$1.actions.fetchBalance(address2, commitment).catch(() => void 0);
504
+ void client$1.actions.fetchBalance(address, commitment).catch(() => void 0);
514
505
  }
515
506
  if (mergedOptions.watch) {
516
- const watcher = client$1.watchers.watchBalance({ address: address2, commitment }, () => void 0);
507
+ const watcher = client$1.watchers.watchBalance({ address, commitment }, () => void 0);
517
508
  return () => {
518
509
  watcher.abort();
519
510
  };
520
511
  }
521
512
  return void 0;
522
- }, [account, address2, client$1, mergedOptions.commitment, mergedOptions.fetch, mergedOptions.watch]);
513
+ }, [account, address, client$1, mergedOptions.commitment, mergedOptions.fetch, mergedOptions.watch]);
523
514
  const lamports = account?.lamports ?? null;
524
515
  const fetching = account?.fetching ?? false;
525
516
  const slot = account?.slot;
@@ -538,17 +529,19 @@ function useBalance(addressLike, options = {}) {
538
529
  __name(useBalance, "useBalance");
539
530
  function useWalletStandardConnectors(options) {
540
531
  const overrides = options?.overrides;
532
+ const disabled = options?.disabled ?? false;
541
533
  const memoisedOptions = react.useMemo(() => overrides ? { overrides } : void 0, [overrides]);
542
534
  const [connectors, setConnectors] = react.useState(
543
- () => client.getWalletStandardConnectors(memoisedOptions ?? {})
535
+ () => disabled ? [] : client.getWalletStandardConnectors(memoisedOptions ?? {})
544
536
  );
545
537
  react.useEffect(() => {
538
+ if (disabled) return;
546
539
  setConnectors(client.getWalletStandardConnectors(memoisedOptions ?? {}));
547
540
  const unwatch = client.watchWalletStandardConnectors(setConnectors, memoisedOptions ?? {});
548
541
  return () => {
549
542
  unwatch();
550
543
  };
551
- }, [memoisedOptions]);
544
+ }, [disabled, memoisedOptions]);
552
545
  return connectors;
553
546
  }
554
547
  __name(useWalletStandardConnectors, "useWalletStandardConnectors");
@@ -842,6 +835,10 @@ function SolanaProvider({ children, client, config, query, walletPersistence })
842
835
  const shouldIncludeQueryLayer = query !== false && query?.disabled !== true;
843
836
  const queryProps = shouldIncludeQueryLayer && query ? query : {};
844
837
  const persistenceConfig = walletPersistence === false ? void 0 : walletPersistence ?? {};
838
+ const storage = persistenceConfig ? persistenceConfig.storage ?? getDefaultStorage() : null;
839
+ const storageKey = persistenceConfig?.storageKey ?? DEFAULT_STORAGE_KEY;
840
+ const persistedState = persistenceConfig ? readPersistedState(storage, storageKey) : { legacyConnectorId: null, state: null };
841
+ const clientConfig = config && persistenceConfig ? { ...config, initialState: config.initialState ?? persistedState.state ?? void 0 } : config;
845
842
  const content = shouldIncludeQueryLayer ? /* @__PURE__ */ jsxRuntime.jsx(
846
843
  SolanaQueryProvider,
847
844
  {
@@ -851,46 +848,77 @@ function SolanaProvider({ children, client, config, query, walletPersistence })
851
848
  children
852
849
  }
853
850
  ) : children;
854
- return /* @__PURE__ */ jsxRuntime.jsxs(SolanaClientProvider, { client, config, children: [
855
- persistenceConfig ? /* @__PURE__ */ jsxRuntime.jsx(WalletPersistence, { ...persistenceConfig }) : null,
851
+ return /* @__PURE__ */ jsxRuntime.jsxs(SolanaClientProvider, { client, config: clientConfig, children: [
852
+ persistenceConfig ? /* @__PURE__ */ jsxRuntime.jsx(
853
+ WalletPersistence,
854
+ {
855
+ autoConnect: persistenceConfig.autoConnect,
856
+ initialState: clientConfig?.initialState ?? persistedState.state,
857
+ legacyConnectorId: persistedState.legacyConnectorId,
858
+ storage,
859
+ storageKey
860
+ }
861
+ ) : null,
856
862
  content
857
863
  ] });
858
864
  }
859
865
  __name(SolanaProvider, "SolanaProvider");
860
866
  var DEFAULT_STORAGE_KEY = "solana:last-connector";
861
- function WalletPersistence({ autoConnect = true, storage, storageKey = DEFAULT_STORAGE_KEY }) {
867
+ function readPersistedState(storage, storageKey) {
868
+ if (!storage) {
869
+ return { legacyConnectorId: null, state: null };
870
+ }
871
+ const raw = safelyRead(() => storage.getItem(storageKey));
872
+ if (!raw) {
873
+ return { legacyConnectorId: null, state: null };
874
+ }
875
+ const parsed = client.deserializeSolanaState(raw);
876
+ if (parsed) {
877
+ return { legacyConnectorId: null, state: parsed };
878
+ }
879
+ return { legacyConnectorId: raw, state: null };
880
+ }
881
+ __name(readPersistedState, "readPersistedState");
882
+ function WalletPersistence({
883
+ autoConnect = true,
884
+ initialState = null,
885
+ legacyConnectorId = null,
886
+ storage,
887
+ storageKey = DEFAULT_STORAGE_KEY
888
+ }) {
862
889
  const wallet = useWallet();
863
890
  const connectWallet = useConnectWallet();
864
- const client = useSolanaClient();
891
+ const client$1 = useSolanaClient();
865
892
  const storageRef = react.useRef(storage ?? getDefaultStorage());
866
893
  const [hasAttemptedAutoConnect, setHasAttemptedAutoConnect] = react.useState(false);
867
- const hasPersistedConnectorRef = react.useRef(false);
868
894
  const clientRef = react.useRef(null);
895
+ const persistedStateRef = react.useRef(initialState);
896
+ const legacyConnectorIdRef = react.useRef(legacyConnectorId);
869
897
  react.useEffect(() => {
870
898
  storageRef.current = storage ?? getDefaultStorage();
871
899
  }, [storage]);
872
900
  react.useEffect(() => {
873
- if (clientRef.current !== client) {
874
- clientRef.current = client;
901
+ if (clientRef.current !== client$1) {
902
+ clientRef.current = client$1;
875
903
  setHasAttemptedAutoConnect(false);
876
904
  }
877
- }, [client]);
905
+ }, [client$1]);
878
906
  react.useEffect(() => {
879
907
  const activeStorage = storageRef.current;
880
908
  if (!activeStorage) return;
881
- if ("connectorId" in wallet && wallet.connectorId) {
882
- const connectorId = wallet.connectorId;
883
- if (connectorId) {
884
- safelyWrite(() => activeStorage.setItem(storageKey, connectorId));
885
- hasPersistedConnectorRef.current = true;
886
- return;
887
- }
888
- }
889
- if (wallet.status === "disconnected" && hasPersistedConnectorRef.current) {
890
- safelyWrite(() => activeStorage.removeItem(storageKey));
891
- hasPersistedConnectorRef.current = false;
892
- }
893
- }, [storageKey, wallet]);
909
+ const unsubscribe = client.subscribeSolanaState(client$1, (state) => {
910
+ persistedStateRef.current = state;
911
+ legacyConnectorIdRef.current = null;
912
+ safelyWrite(() => activeStorage.setItem(storageKey, client.serializeSolanaState(state)));
913
+ });
914
+ return () => {
915
+ unsubscribe();
916
+ };
917
+ }, [client$1, storageKey]);
918
+ react.useEffect(() => {
919
+ persistedStateRef.current = initialState ?? persistedStateRef.current;
920
+ legacyConnectorIdRef.current = legacyConnectorId;
921
+ }, [initialState, legacyConnectorId]);
894
922
  react.useEffect(() => {
895
923
  if (!autoConnect || hasAttemptedAutoConnect) {
896
924
  return;
@@ -899,35 +927,21 @@ function WalletPersistence({ autoConnect = true, storage, storageKey = DEFAULT_S
899
927
  setHasAttemptedAutoConnect(true);
900
928
  return;
901
929
  }
902
- const activeStorage = storageRef.current;
903
- if (!activeStorage) {
904
- setHasAttemptedAutoConnect(true);
905
- return;
906
- }
907
- let cancelled = false;
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
- }
930
+ const state = persistedStateRef.current ?? initialState;
931
+ const connectorId = state?.lastConnectorId ?? legacyConnectorIdRef.current;
932
+ const shouldAutoConnect = (state?.autoconnect ?? autoConnect) && connectorId;
933
+ if (!shouldAutoConnect || !connectorId) return;
934
+ const connector = client$1.connectors.get(connectorId);
935
+ if (!connector) return;
917
936
  void (async () => {
918
937
  try {
919
938
  await connectWallet(connectorId, { autoConnect: true });
920
939
  } catch {
921
940
  } finally {
922
- if (!cancelled) {
923
- setHasAttemptedAutoConnect(true);
924
- }
941
+ setHasAttemptedAutoConnect(true);
925
942
  }
926
943
  })();
927
- return () => {
928
- cancelled = true;
929
- };
930
- }, [autoConnect, client, connectWallet, hasAttemptedAutoConnect, storageKey, wallet.status]);
944
+ }, [autoConnect, client$1, connectWallet, hasAttemptedAutoConnect, initialState, wallet.status]);
931
945
  return null;
932
946
  }
933
947
  __name(WalletPersistence, "WalletPersistence");
@@ -961,8 +975,13 @@ function useWalletConnection(options = {}) {
961
975
  const wallet = useWallet();
962
976
  const connectWallet = useConnectWallet();
963
977
  const disconnectWallet = useDisconnectWallet();
964
- const discovered = useWalletStandardConnectors(options.discoveryOptions);
965
- const connectors = options.connectors ?? discovered;
978
+ const client = useSolanaClient();
979
+ const shouldDiscover = !options.connectors && client.connectors.all.length === 0;
980
+ const discovered = useWalletStandardConnectors({
981
+ ...options.discoveryOptions,
982
+ disabled: !shouldDiscover
983
+ });
984
+ const connectors = options.connectors ?? (client.connectors.all.length > 0 ? client.connectors.all : discovered);
966
985
  const connect = react.useCallback(
967
986
  (connectorId, connectOptions) => connectWallet(connectorId, connectOptions),
968
987
  [connectWallet]
@@ -1023,333 +1042,6 @@ function useWalletModalState(options = {}) {
1023
1042
  };
1024
1043
  }
1025
1044
  __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
1045
 
1354
1046
  exports.SolanaClientProvider = SolanaClientProvider;
1355
1047
  exports.SolanaProvider = SolanaProvider;
@@ -1365,10 +1057,6 @@ exports.useDisconnectWallet = useDisconnectWallet;
1365
1057
  exports.useLatestBlockhash = useLatestBlockhash;
1366
1058
  exports.useProgramAccounts = useProgramAccounts;
1367
1059
  exports.useSendTransaction = useSendTransaction;
1368
- exports.useSignAndSendTransaction = useSignAndSendTransaction;
1369
- exports.useSignIn = useSignIn;
1370
- exports.useSignMessage = useSignMessage;
1371
- exports.useSignTransaction = useSignTransaction;
1372
1060
  exports.useSignatureStatus = useSignatureStatus;
1373
1061
  exports.useSimulateTransaction = useSimulateTransaction;
1374
1062
  exports.useSolTransfer = useSolTransfer;
@@ -1377,9 +1065,6 @@ exports.useSplToken = useSplToken;
1377
1065
  exports.useTransactionPool = useTransactionPool;
1378
1066
  exports.useWaitForSignature = useWaitForSignature;
1379
1067
  exports.useWallet = useWallet;
1380
- exports.useWalletAccountMessageSigner = useWalletAccountMessageSigner;
1381
- exports.useWalletAccountTransactionSendingSigner = useWalletAccountTransactionSendingSigner;
1382
- exports.useWalletAccountTransactionSigner = useWalletAccountTransactionSigner;
1383
1068
  exports.useWalletActions = useWalletActions;
1384
1069
  exports.useWalletConnection = useWalletConnection;
1385
1070
  exports.useWalletModalState = useWalletModalState;