@solana/react-hooks 0.0.2 → 0.2.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/dist/index.browser.cjs +189 -0
- package/dist/index.browser.cjs.map +1 -1
- package/dist/index.browser.mjs +187 -2
- package/dist/index.browser.mjs.map +1 -1
- package/dist/index.native.mjs +187 -2
- package/dist/index.native.mjs.map +1 -1
- package/dist/index.node.cjs +189 -0
- package/dist/index.node.cjs.map +1 -1
- package/dist/index.node.mjs +187 -2
- package/dist/index.node.mjs.map +1 -1
- package/dist/types/QueryProvider.d.ts.map +1 -0
- package/dist/types/SolanaProvider.d.ts +35 -0
- package/dist/types/SolanaProvider.d.ts.map +1 -0
- package/dist/types/context.d.ts.map +1 -0
- package/dist/types/{react-hooks/src/hooks.d.ts → hooks.d.ts} +1 -1
- package/dist/types/hooks.d.ts.map +1 -0
- package/dist/types/{react-hooks/src/index.d.ts → index.d.ts} +2 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/query.d.ts.map +1 -0
- package/dist/types/queryHooks.d.ts.map +1 -0
- package/dist/types/querySuspenseContext.d.ts.map +1 -0
- package/dist/types/ui.d.ts +52 -0
- package/dist/types/ui.d.ts.map +1 -0
- package/dist/types/useClientStore.d.ts.map +1 -0
- package/dist/types/walletStandardHooks.d.ts.map +1 -0
- package/package.json +2 -2
- package/dist/types/client/src/client/actions.d.ts +0 -18
- package/dist/types/client/src/client/actions.d.ts.map +0 -1
- package/dist/types/client/src/client/createClient.d.ts +0 -9
- package/dist/types/client/src/client/createClient.d.ts.map +0 -1
- package/dist/types/client/src/client/createClientHelpers.d.ts +0 -3
- package/dist/types/client/src/client/createClientHelpers.d.ts.map +0 -1
- package/dist/types/client/src/client/createClientStore.d.ts +0 -29
- package/dist/types/client/src/client/createClientStore.d.ts.map +0 -1
- package/dist/types/client/src/client/watchers.d.ts +0 -16
- package/dist/types/client/src/client/watchers.d.ts.map +0 -1
- package/dist/types/client/src/controllers/solTransferController.d.ts +0 -21
- package/dist/types/client/src/controllers/solTransferController.d.ts.map +0 -1
- package/dist/types/client/src/controllers/splTransferController.d.ts +0 -24
- package/dist/types/client/src/controllers/splTransferController.d.ts.map +0 -1
- package/dist/types/client/src/features/sol.d.ts +0 -41
- package/dist/types/client/src/features/sol.d.ts.map +0 -1
- package/dist/types/client/src/features/spl.d.ts +0 -59
- package/dist/types/client/src/features/spl.d.ts.map +0 -1
- package/dist/types/client/src/features/transactions.d.ts +0 -79
- package/dist/types/client/src/features/transactions.d.ts.map +0 -1
- package/dist/types/client/src/index.d.ts +0 -25
- package/dist/types/client/src/index.d.ts.map +0 -1
- package/dist/types/client/src/logging/logger.d.ts +0 -24
- package/dist/types/client/src/logging/logger.d.ts.map +0 -1
- package/dist/types/client/src/numeric/amounts.d.ts +0 -30
- package/dist/types/client/src/numeric/amounts.d.ts.map +0 -1
- package/dist/types/client/src/numeric/lamports.d.ts +0 -46
- package/dist/types/client/src/numeric/lamports.d.ts.map +0 -1
- package/dist/types/client/src/numeric/math.d.ts +0 -74
- package/dist/types/client/src/numeric/math.d.ts.map +0 -1
- package/dist/types/client/src/numeric/rational.d.ts +0 -27
- package/dist/types/client/src/numeric/rational.d.ts.map +0 -1
- package/dist/types/client/src/rpc/createSolanaRpcClient.d.ts +0 -42
- package/dist/types/client/src/rpc/createSolanaRpcClient.d.ts.map +0 -1
- package/dist/types/client/src/serialization/json.d.ts +0 -31
- package/dist/types/client/src/serialization/json.d.ts.map +0 -1
- package/dist/types/client/src/signatures/status.d.ts +0 -12
- package/dist/types/client/src/signatures/status.d.ts.map +0 -1
- package/dist/types/client/src/signers/walletTransactionSigner.d.ts +0 -33
- package/dist/types/client/src/signers/walletTransactionSigner.d.ts.map +0 -1
- package/dist/types/client/src/state/asyncState.d.ts +0 -12
- package/dist/types/client/src/state/asyncState.d.ts.map +0 -1
- package/dist/types/client/src/transactions/base64.d.ts +0 -12
- package/dist/types/client/src/transactions/base64.d.ts.map +0 -1
- package/dist/types/client/src/transactions/prepareTransaction.d.ts +0 -16
- package/dist/types/client/src/transactions/prepareTransaction.d.ts.map +0 -1
- package/dist/types/client/src/transactions/referenceKeys.d.ts +0 -10
- package/dist/types/client/src/transactions/referenceKeys.d.ts.map +0 -1
- package/dist/types/client/src/transactions/transactionPoolController.d.ts +0 -53
- package/dist/types/client/src/transactions/transactionPoolController.d.ts.map +0 -1
- package/dist/types/client/src/types.d.ts +0 -205
- package/dist/types/client/src/types.d.ts.map +0 -1
- package/dist/types/client/src/utils/addressLike.d.ts +0 -5
- package/dist/types/client/src/utils/addressLike.d.ts.map +0 -1
- package/dist/types/client/src/utils/stableStringify.d.ts +0 -2
- package/dist/types/client/src/utils/stableStringify.d.ts.map +0 -1
- package/dist/types/client/src/utils.d.ts +0 -21
- package/dist/types/client/src/utils.d.ts.map +0 -1
- package/dist/types/client/src/wallet/registry.d.ts +0 -9
- package/dist/types/client/src/wallet/registry.d.ts.map +0 -1
- package/dist/types/client/src/wallet/standard.d.ts +0 -36
- package/dist/types/client/src/wallet/standard.d.ts.map +0 -1
- package/dist/types/react-hooks/src/QueryProvider.d.ts.map +0 -1
- package/dist/types/react-hooks/src/context.d.ts.map +0 -1
- package/dist/types/react-hooks/src/hooks.d.ts.map +0 -1
- package/dist/types/react-hooks/src/index.d.ts.map +0 -1
- package/dist/types/react-hooks/src/query.d.ts.map +0 -1
- package/dist/types/react-hooks/src/queryHooks.d.ts.map +0 -1
- package/dist/types/react-hooks/src/querySuspenseContext.d.ts.map +0 -1
- package/dist/types/react-hooks/src/useClientStore.d.ts.map +0 -1
- package/dist/types/react-hooks/src/walletStandardHooks.d.ts.map +0 -1
- /package/dist/types/{react-hooks/src/QueryProvider.d.ts → QueryProvider.d.ts} +0 -0
- /package/dist/types/{react-hooks/src/context.d.ts → context.d.ts} +0 -0
- /package/dist/types/{react-hooks/src/query.d.ts → query.d.ts} +0 -0
- /package/dist/types/{react-hooks/src/queryHooks.d.ts → queryHooks.d.ts} +0 -0
- /package/dist/types/{react-hooks/src/querySuspenseContext.d.ts → querySuspenseContext.d.ts} +0 -0
- /package/dist/types/{react-hooks/src/useClientStore.d.ts → useClientStore.d.ts} +0 -0
- /package/dist/types/{react-hooks/src/walletStandardHooks.d.ts → walletStandardHooks.d.ts} +0 -0
package/dist/index.browser.cjs
CHANGED
|
@@ -782,6 +782,191 @@ function SolanaQueryProvider({
|
|
|
782
782
|
return /* @__PURE__ */ jsxRuntime.jsx(QuerySuspenseContext.Provider, { value: suspense, children: /* @__PURE__ */ jsxRuntime.jsx(useSWR.SWRConfig, { value, children }) });
|
|
783
783
|
}
|
|
784
784
|
__name(SolanaQueryProvider, "SolanaQueryProvider");
|
|
785
|
+
function SolanaProvider({ children, client, config, query, walletPersistence }) {
|
|
786
|
+
const shouldIncludeQueryLayer = query !== false && query?.disabled !== true;
|
|
787
|
+
const queryProps = shouldIncludeQueryLayer && query ? query : {};
|
|
788
|
+
const persistenceConfig = walletPersistence === false ? void 0 : walletPersistence ?? {};
|
|
789
|
+
const content = shouldIncludeQueryLayer ? /* @__PURE__ */ jsxRuntime.jsx(
|
|
790
|
+
SolanaQueryProvider,
|
|
791
|
+
{
|
|
792
|
+
config: queryProps.config,
|
|
793
|
+
resetOnClusterChange: queryProps.resetOnClusterChange,
|
|
794
|
+
suspense: queryProps.suspense,
|
|
795
|
+
children
|
|
796
|
+
}
|
|
797
|
+
) : children;
|
|
798
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(SolanaClientProvider, { client, config, children: [
|
|
799
|
+
persistenceConfig ? /* @__PURE__ */ jsxRuntime.jsx(WalletPersistence, { ...persistenceConfig }) : null,
|
|
800
|
+
content
|
|
801
|
+
] });
|
|
802
|
+
}
|
|
803
|
+
__name(SolanaProvider, "SolanaProvider");
|
|
804
|
+
var DEFAULT_STORAGE_KEY = "solana:last-connector";
|
|
805
|
+
function WalletPersistence({ autoConnect = true, storage, storageKey = DEFAULT_STORAGE_KEY }) {
|
|
806
|
+
const wallet = useWallet();
|
|
807
|
+
const connectWallet = useConnectWallet();
|
|
808
|
+
const client = useSolanaClient();
|
|
809
|
+
const storageRef = react.useRef(storage ?? getDefaultStorage());
|
|
810
|
+
const [hasAttemptedAutoConnect, setHasAttemptedAutoConnect] = react.useState(false);
|
|
811
|
+
const hasPersistedConnectorRef = react.useRef(false);
|
|
812
|
+
const clientRef = react.useRef(null);
|
|
813
|
+
react.useEffect(() => {
|
|
814
|
+
storageRef.current = storage ?? getDefaultStorage();
|
|
815
|
+
}, [storage]);
|
|
816
|
+
react.useEffect(() => {
|
|
817
|
+
if (clientRef.current !== client) {
|
|
818
|
+
clientRef.current = client;
|
|
819
|
+
setHasAttemptedAutoConnect(false);
|
|
820
|
+
}
|
|
821
|
+
}, [client]);
|
|
822
|
+
react.useEffect(() => {
|
|
823
|
+
const activeStorage = storageRef.current;
|
|
824
|
+
if (!activeStorage) return;
|
|
825
|
+
if ("connectorId" in wallet && wallet.connectorId) {
|
|
826
|
+
const connectorId = wallet.connectorId;
|
|
827
|
+
if (connectorId) {
|
|
828
|
+
safelyWrite(() => activeStorage.setItem(storageKey, connectorId));
|
|
829
|
+
hasPersistedConnectorRef.current = true;
|
|
830
|
+
return;
|
|
831
|
+
}
|
|
832
|
+
}
|
|
833
|
+
if (wallet.status === "disconnected" && hasPersistedConnectorRef.current) {
|
|
834
|
+
safelyWrite(() => activeStorage.removeItem(storageKey));
|
|
835
|
+
hasPersistedConnectorRef.current = false;
|
|
836
|
+
}
|
|
837
|
+
}, [storageKey, wallet]);
|
|
838
|
+
react.useEffect(() => {
|
|
839
|
+
if (!autoConnect || hasAttemptedAutoConnect) {
|
|
840
|
+
return;
|
|
841
|
+
}
|
|
842
|
+
if (wallet.status === "connected" || wallet.status === "connecting") {
|
|
843
|
+
setHasAttemptedAutoConnect(true);
|
|
844
|
+
return;
|
|
845
|
+
}
|
|
846
|
+
const activeStorage = storageRef.current;
|
|
847
|
+
if (!activeStorage) {
|
|
848
|
+
setHasAttemptedAutoConnect(true);
|
|
849
|
+
return;
|
|
850
|
+
}
|
|
851
|
+
let cancelled = false;
|
|
852
|
+
const connectorId = safelyRead(() => activeStorage.getItem(storageKey));
|
|
853
|
+
if (!connectorId) {
|
|
854
|
+
setHasAttemptedAutoConnect(true);
|
|
855
|
+
return;
|
|
856
|
+
}
|
|
857
|
+
const connector = client.connectors.get(connectorId);
|
|
858
|
+
if (!connector) {
|
|
859
|
+
return;
|
|
860
|
+
}
|
|
861
|
+
void (async () => {
|
|
862
|
+
try {
|
|
863
|
+
await connectWallet(connectorId, { autoConnect: true });
|
|
864
|
+
} catch {
|
|
865
|
+
} finally {
|
|
866
|
+
if (!cancelled) {
|
|
867
|
+
setHasAttemptedAutoConnect(true);
|
|
868
|
+
}
|
|
869
|
+
}
|
|
870
|
+
})();
|
|
871
|
+
return () => {
|
|
872
|
+
cancelled = true;
|
|
873
|
+
};
|
|
874
|
+
}, [autoConnect, client, connectWallet, hasAttemptedAutoConnect, storageKey, wallet.status]);
|
|
875
|
+
return null;
|
|
876
|
+
}
|
|
877
|
+
__name(WalletPersistence, "WalletPersistence");
|
|
878
|
+
function safelyRead(reader) {
|
|
879
|
+
try {
|
|
880
|
+
return reader();
|
|
881
|
+
} catch {
|
|
882
|
+
return null;
|
|
883
|
+
}
|
|
884
|
+
}
|
|
885
|
+
__name(safelyRead, "safelyRead");
|
|
886
|
+
function safelyWrite(writer) {
|
|
887
|
+
try {
|
|
888
|
+
writer();
|
|
889
|
+
} catch {
|
|
890
|
+
}
|
|
891
|
+
}
|
|
892
|
+
__name(safelyWrite, "safelyWrite");
|
|
893
|
+
function getDefaultStorage() {
|
|
894
|
+
if (typeof globalThis !== "object" || globalThis === null) {
|
|
895
|
+
return null;
|
|
896
|
+
}
|
|
897
|
+
const candidate = globalThis.localStorage;
|
|
898
|
+
if (!candidate) {
|
|
899
|
+
return null;
|
|
900
|
+
}
|
|
901
|
+
return candidate;
|
|
902
|
+
}
|
|
903
|
+
__name(getDefaultStorage, "getDefaultStorage");
|
|
904
|
+
function useWalletConnection(options = {}) {
|
|
905
|
+
const wallet = useWallet();
|
|
906
|
+
const connectWallet = useConnectWallet();
|
|
907
|
+
const disconnectWallet = useDisconnectWallet();
|
|
908
|
+
const discovered = useWalletStandardConnectors(options.discoveryOptions);
|
|
909
|
+
const connectors = options.connectors ?? discovered;
|
|
910
|
+
const connect = react.useCallback(
|
|
911
|
+
(connectorId, connectOptions) => connectWallet(connectorId, connectOptions),
|
|
912
|
+
[connectWallet]
|
|
913
|
+
);
|
|
914
|
+
const disconnect = react.useCallback(() => disconnectWallet(), [disconnectWallet]);
|
|
915
|
+
const state = react.useMemo(() => {
|
|
916
|
+
const connectorId = "connectorId" in wallet ? wallet.connectorId : void 0;
|
|
917
|
+
const session = wallet.status === "connected" ? wallet.session : void 0;
|
|
918
|
+
const error = wallet.status === "error" ? wallet.error ?? null : null;
|
|
919
|
+
return {
|
|
920
|
+
connect,
|
|
921
|
+
connected: wallet.status === "connected",
|
|
922
|
+
connecting: wallet.status === "connecting",
|
|
923
|
+
connectors,
|
|
924
|
+
connectorId,
|
|
925
|
+
disconnect,
|
|
926
|
+
error,
|
|
927
|
+
status: wallet.status,
|
|
928
|
+
wallet: session
|
|
929
|
+
};
|
|
930
|
+
}, [connect, connectors, disconnect, wallet]);
|
|
931
|
+
return state;
|
|
932
|
+
}
|
|
933
|
+
__name(useWalletConnection, "useWalletConnection");
|
|
934
|
+
function WalletConnectionManager({ children, connectors, discoveryOptions }) {
|
|
935
|
+
const state = useWalletConnection({ connectors, discoveryOptions });
|
|
936
|
+
return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: children(state) });
|
|
937
|
+
}
|
|
938
|
+
__name(WalletConnectionManager, "WalletConnectionManager");
|
|
939
|
+
function useWalletModalState(options = {}) {
|
|
940
|
+
const connection = useWalletConnection(options);
|
|
941
|
+
const [isOpen, setIsOpen] = react.useState(options.initialOpen ?? false);
|
|
942
|
+
const [selectedConnector, setSelectedConnector] = react.useState(null);
|
|
943
|
+
const closeOnConnect = options.closeOnConnect ?? true;
|
|
944
|
+
const open = react.useCallback(() => setIsOpen(true), []);
|
|
945
|
+
const close = react.useCallback(() => setIsOpen(false), []);
|
|
946
|
+
const toggle = react.useCallback(() => setIsOpen((value) => !value), []);
|
|
947
|
+
const select = react.useCallback((connectorId) => setSelectedConnector(connectorId), []);
|
|
948
|
+
const connect = react.useCallback(
|
|
949
|
+
async (connectorId, connectOptions) => {
|
|
950
|
+
await connection.connect(connectorId, connectOptions);
|
|
951
|
+
setSelectedConnector(connectorId);
|
|
952
|
+
if (closeOnConnect) {
|
|
953
|
+
setIsOpen(false);
|
|
954
|
+
}
|
|
955
|
+
},
|
|
956
|
+
[closeOnConnect, connection]
|
|
957
|
+
);
|
|
958
|
+
return {
|
|
959
|
+
...connection,
|
|
960
|
+
close,
|
|
961
|
+
connect,
|
|
962
|
+
isOpen,
|
|
963
|
+
open,
|
|
964
|
+
selectedConnector,
|
|
965
|
+
select,
|
|
966
|
+
toggle
|
|
967
|
+
};
|
|
968
|
+
}
|
|
969
|
+
__name(useWalletModalState, "useWalletModalState");
|
|
785
970
|
function useSignAndSendTransaction(uiWalletAccount, chain) {
|
|
786
971
|
const signAndSendTransactions = useSignAndSendTransactions(uiWalletAccount, chain);
|
|
787
972
|
return react.useCallback(
|
|
@@ -1111,7 +1296,9 @@ function useWalletAccountTransactionSendingSigner(uiWalletAccount, chain) {
|
|
|
1111
1296
|
__name(useWalletAccountTransactionSendingSigner, "useWalletAccountTransactionSendingSigner");
|
|
1112
1297
|
|
|
1113
1298
|
exports.SolanaClientProvider = SolanaClientProvider;
|
|
1299
|
+
exports.SolanaProvider = SolanaProvider;
|
|
1114
1300
|
exports.SolanaQueryProvider = SolanaQueryProvider;
|
|
1301
|
+
exports.WalletConnectionManager = WalletConnectionManager;
|
|
1115
1302
|
exports.useAccount = useAccount;
|
|
1116
1303
|
exports.useBalance = useBalance;
|
|
1117
1304
|
exports.useClientStore = useClientStore;
|
|
@@ -1138,6 +1325,8 @@ exports.useWalletAccountMessageSigner = useWalletAccountMessageSigner;
|
|
|
1138
1325
|
exports.useWalletAccountTransactionSendingSigner = useWalletAccountTransactionSendingSigner;
|
|
1139
1326
|
exports.useWalletAccountTransactionSigner = useWalletAccountTransactionSigner;
|
|
1140
1327
|
exports.useWalletActions = useWalletActions;
|
|
1328
|
+
exports.useWalletConnection = useWalletConnection;
|
|
1329
|
+
exports.useWalletModalState = useWalletModalState;
|
|
1141
1330
|
exports.useWalletSession = useWalletSession;
|
|
1142
1331
|
exports.useWalletStandardConnectors = useWalletStandardConnectors;
|
|
1143
1332
|
//# sourceMappingURL=index.browser.cjs.map
|