@solana/react-hooks 1.0.0-rc.3 → 1.1.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 +36 -0
- package/dist/index.browser.cjs +117 -1
- package/dist/index.browser.cjs.map +1 -1
- package/dist/index.browser.mjs +116 -3
- package/dist/index.browser.mjs.map +1 -1
- package/dist/index.native.mjs +116 -3
- package/dist/index.native.mjs.map +1 -1
- package/dist/index.node.cjs +117 -1
- package/dist/index.node.cjs.map +1 -1
- package/dist/index.node.mjs +116 -3
- package/dist/index.node.mjs.map +1 -1
- package/dist/types/hooks.d.ts +71 -1
- package/dist/types/hooks.d.ts.map +1 -1
- package/dist/types/index.d.ts +3 -2
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/ui.d.ts +1 -0
- package/dist/types/ui.d.ts.map +1 -1
- package/package.json +2 -2
package/dist/index.node.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { createClient, toAddress, toAddressString, stableStringify, createSolTransferController, createSplTransferController, createTransactionPoolController, createInitialAsyncState, createAsyncState, normalizeSignature, SIGNATURE_STATUS_TIMEOUT_MS, deriveConfirmationStatus, confirmationMeetsCommitment, resolveClientConfig, deserializeSolanaState, subscribeSolanaState, serializeSolanaState } from '@solana/client';
|
|
1
|
+
import { createClient, toAddress, toAddressString, stableStringify, createSolTransferController, createStakeController, createSplTransferController, createTransactionPoolController, createInitialAsyncState, createAsyncState, normalizeSignature, SIGNATURE_STATUS_TIMEOUT_MS, deriveConfirmationStatus, confirmationMeetsCommitment, resolveClientConfig, 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';
|
|
@@ -389,6 +389,87 @@ function useSolTransfer() {
|
|
|
389
389
|
};
|
|
390
390
|
}
|
|
391
391
|
__name(useSolTransfer, "useSolTransfer");
|
|
392
|
+
function useStake(validatorId) {
|
|
393
|
+
const client = useSolanaClient();
|
|
394
|
+
const session = useWalletSession();
|
|
395
|
+
const helper = client.stake;
|
|
396
|
+
const sessionRef = useRef(session);
|
|
397
|
+
const normalizedValidatorId = useMemo(() => String(validatorId), [validatorId]);
|
|
398
|
+
useEffect(() => {
|
|
399
|
+
sessionRef.current = session;
|
|
400
|
+
}, [session]);
|
|
401
|
+
const controller = useMemo(
|
|
402
|
+
() => createStakeController({
|
|
403
|
+
authorityProvider: /* @__PURE__ */ __name(() => sessionRef.current, "authorityProvider"),
|
|
404
|
+
helper
|
|
405
|
+
}),
|
|
406
|
+
[helper]
|
|
407
|
+
);
|
|
408
|
+
const state = useSyncExternalStore(
|
|
409
|
+
controller.subscribe,
|
|
410
|
+
controller.getState,
|
|
411
|
+
controller.getState
|
|
412
|
+
);
|
|
413
|
+
const unstakeState = useSyncExternalStore(
|
|
414
|
+
controller.subscribeUnstake,
|
|
415
|
+
controller.getUnstakeState,
|
|
416
|
+
controller.getUnstakeState
|
|
417
|
+
);
|
|
418
|
+
const withdrawState = useSyncExternalStore(
|
|
419
|
+
controller.subscribeWithdraw,
|
|
420
|
+
controller.getWithdrawState,
|
|
421
|
+
controller.getWithdrawState
|
|
422
|
+
);
|
|
423
|
+
const stake = useCallback(
|
|
424
|
+
(config, options) => controller.stake({ ...config, validatorId: normalizedValidatorId }, options),
|
|
425
|
+
[controller, normalizedValidatorId]
|
|
426
|
+
);
|
|
427
|
+
const unstake = useCallback(
|
|
428
|
+
(config, options) => controller.unstake({ ...config }, options),
|
|
429
|
+
[controller]
|
|
430
|
+
);
|
|
431
|
+
const withdraw = useCallback(
|
|
432
|
+
(config, options) => controller.withdraw({ ...config }, options),
|
|
433
|
+
[controller]
|
|
434
|
+
);
|
|
435
|
+
const getStakeAccounts = useCallback(
|
|
436
|
+
async (wallet, validatorIdFilter) => {
|
|
437
|
+
if (!helper.getStakeAccounts) {
|
|
438
|
+
throw new Error(
|
|
439
|
+
"getStakeAccounts is not available. Make sure you have the latest version of @solana/client package."
|
|
440
|
+
);
|
|
441
|
+
}
|
|
442
|
+
const walletAddr = typeof wallet === "string" ? wallet : String(wallet);
|
|
443
|
+
const filterAddr = validatorIdFilter ? typeof validatorIdFilter === "string" ? validatorIdFilter : String(validatorIdFilter) : void 0;
|
|
444
|
+
return helper.getStakeAccounts(walletAddr, filterAddr);
|
|
445
|
+
},
|
|
446
|
+
[helper]
|
|
447
|
+
);
|
|
448
|
+
return {
|
|
449
|
+
error: state.error ?? null,
|
|
450
|
+
getStakeAccounts,
|
|
451
|
+
helper,
|
|
452
|
+
isStaking: state.status === "loading",
|
|
453
|
+
isUnstaking: unstakeState.status === "loading",
|
|
454
|
+
isWithdrawing: withdrawState.status === "loading",
|
|
455
|
+
reset: controller.reset,
|
|
456
|
+
resetUnstake: controller.resetUnstake,
|
|
457
|
+
resetWithdraw: controller.resetWithdraw,
|
|
458
|
+
stake,
|
|
459
|
+
unstake,
|
|
460
|
+
withdraw,
|
|
461
|
+
signature: state.data ?? null,
|
|
462
|
+
unstakeSignature: unstakeState.data ?? null,
|
|
463
|
+
withdrawSignature: withdrawState.data ?? null,
|
|
464
|
+
status: state.status,
|
|
465
|
+
unstakeStatus: unstakeState.status,
|
|
466
|
+
withdrawStatus: withdrawState.status,
|
|
467
|
+
unstakeError: unstakeState.error ?? null,
|
|
468
|
+
withdrawError: withdrawState.error ?? null,
|
|
469
|
+
validatorId: normalizedValidatorId
|
|
470
|
+
};
|
|
471
|
+
}
|
|
472
|
+
__name(useStake, "useStake");
|
|
392
473
|
function useSplToken(mint, options = {}) {
|
|
393
474
|
const client = useSolanaClient();
|
|
394
475
|
const session = useWalletSession();
|
|
@@ -832,6 +913,38 @@ function useWaitForSignature(signatureInput, options = {}) {
|
|
|
832
913
|
};
|
|
833
914
|
}
|
|
834
915
|
__name(useWaitForSignature, "useWaitForSignature");
|
|
916
|
+
function useLookupTable(addressLike, options = {}) {
|
|
917
|
+
const addr = useMemo(() => addressLike ? toAddress(addressLike) : void 0, [addressLike]);
|
|
918
|
+
const key = addr?.toString() ?? null;
|
|
919
|
+
const fetcher = useCallback(
|
|
920
|
+
async (c) => {
|
|
921
|
+
if (!addr) throw new Error("Address required");
|
|
922
|
+
return c.actions.fetchLookupTable(addr, options.commitment);
|
|
923
|
+
},
|
|
924
|
+
[addr, options.commitment]
|
|
925
|
+
);
|
|
926
|
+
return useSolanaRpcQuery("lookupTable", [key, options.commitment], fetcher, {
|
|
927
|
+
disabled: !addr,
|
|
928
|
+
swr: options.swr
|
|
929
|
+
});
|
|
930
|
+
}
|
|
931
|
+
__name(useLookupTable, "useLookupTable");
|
|
932
|
+
function useNonceAccount(addressLike, options = {}) {
|
|
933
|
+
const addr = useMemo(() => addressLike ? toAddress(addressLike) : void 0, [addressLike]);
|
|
934
|
+
const key = addr?.toString() ?? null;
|
|
935
|
+
const fetcher = useCallback(
|
|
936
|
+
async (c) => {
|
|
937
|
+
if (!addr) throw new Error("Address required");
|
|
938
|
+
return c.actions.fetchNonceAccount(addr, options.commitment);
|
|
939
|
+
},
|
|
940
|
+
[addr, options.commitment]
|
|
941
|
+
);
|
|
942
|
+
return useSolanaRpcQuery("nonceAccount", [key, options.commitment], fetcher, {
|
|
943
|
+
disabled: !addr,
|
|
944
|
+
swr: options.swr
|
|
945
|
+
});
|
|
946
|
+
}
|
|
947
|
+
__name(useNonceAccount, "useNonceAccount");
|
|
835
948
|
var createCache = /* @__PURE__ */ __name(() => /* @__PURE__ */ new Map(), "createCache");
|
|
836
949
|
var DEFAULT_QUERY_CONFIG = Object.freeze({
|
|
837
950
|
dedupingInterval: 2e3,
|
|
@@ -988,7 +1101,7 @@ function WalletPersistence({
|
|
|
988
1101
|
if (!connector) return;
|
|
989
1102
|
void (async () => {
|
|
990
1103
|
try {
|
|
991
|
-
await connectWallet(connectorId, { autoConnect: true });
|
|
1104
|
+
await connectWallet(connectorId, { autoConnect: true, allowInteractiveFallback: false });
|
|
992
1105
|
} catch {
|
|
993
1106
|
} finally {
|
|
994
1107
|
setHasAttemptedAutoConnect(true);
|
|
@@ -1097,6 +1210,6 @@ function useWalletModalState(options = {}) {
|
|
|
1097
1210
|
}
|
|
1098
1211
|
__name(useWalletModalState, "useWalletModalState");
|
|
1099
1212
|
|
|
1100
|
-
export { SolanaClientProvider, SolanaProvider, SolanaQueryProvider, WalletConnectionManager, getLatestBlockhashKey, getProgramAccountsKey, getSignatureStatusKey, getSimulateTransactionKey, useAccount, useBalance, useClientStore, useClusterState, useClusterStatus, useConnectWallet, useDisconnectWallet, useLatestBlockhash, useProgramAccounts, useSendTransaction, useSignatureStatus, useSimulateTransaction, useSolTransfer, useSolanaClient, useSplToken, useTransactionPool, useWaitForSignature, useWallet, useWalletActions, useWalletConnection, useWalletModalState, useWalletSession };
|
|
1213
|
+
export { SolanaClientProvider, SolanaProvider, SolanaQueryProvider, WalletConnectionManager, getLatestBlockhashKey, getProgramAccountsKey, getSignatureStatusKey, getSimulateTransactionKey, useAccount, useBalance, useClientStore, useClusterState, useClusterStatus, useConnectWallet, useDisconnectWallet, useLatestBlockhash, useLookupTable, useNonceAccount, useProgramAccounts, useSendTransaction, useSignatureStatus, useSimulateTransaction, useSolTransfer, useSolanaClient, useSplToken, useStake, useTransactionPool, useWaitForSignature, useWallet, useWalletActions, useWalletConnection, useWalletModalState, useWalletSession };
|
|
1101
1214
|
//# sourceMappingURL=index.node.mjs.map
|
|
1102
1215
|
//# sourceMappingURL=index.node.mjs.map
|