@solana/kit-plugin-wallet 0.12.0 → 0.13.1
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 +102 -4
- package/dist/index.browser.cjs +120 -36
- package/dist/index.browser.cjs.map +1 -1
- package/dist/index.browser.mjs +120 -37
- package/dist/index.browser.mjs.map +1 -1
- package/dist/index.node.cjs +9 -2
- package/dist/index.node.cjs.map +1 -1
- package/dist/index.node.mjs +9 -3
- package/dist/index.node.mjs.map +1 -1
- package/dist/index.react-native.mjs +9 -3
- package/dist/index.react-native.mjs.map +1 -1
- package/dist/react/index.browser.cjs +77 -0
- package/dist/react/index.browser.cjs.map +1 -0
- package/dist/react/index.browser.mjs +66 -0
- package/dist/react/index.browser.mjs.map +1 -0
- package/dist/react/index.node.cjs +77 -0
- package/dist/react/index.node.cjs.map +1 -0
- package/dist/react/index.node.mjs +66 -0
- package/dist/react/index.node.mjs.map +1 -0
- package/dist/react/index.react-native.mjs +66 -0
- package/dist/react/index.react-native.mjs.map +1 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/react/index.d.ts +235 -0
- package/dist/types/react/index.d.ts.map +1 -0
- package/dist/types/status.d.ts +31 -0
- package/dist/types/status.d.ts.map +1 -0
- package/dist/types/store.d.ts.map +1 -1
- package/dist/types/types.d.ts +57 -9
- package/dist/types/types.d.ts.map +1 -1
- package/dist/types/wallet.d.ts +3 -3
- package/dist/types/wallet.d.ts.map +1 -1
- package/package.json +45 -14
- package/src/__typetests__/wallet-typetest.ts +15 -0
- package/src/index.ts +1 -0
- package/src/react/__typetests__/index.ts +108 -0
- package/src/react/index.ts +301 -0
- package/src/status.ts +33 -0
- package/src/store.ts +208 -81
- package/src/types.ts +58 -9
- package/src/wallet.ts +3 -1
package/dist/types/types.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { MessageSigner, SignatureBytes, TransactionSigner } from '@solana/kit';
|
|
1
|
+
import type { MessageSigner, ReadonlyUint8Array, SignatureBytes, TransactionSigner } from '@solana/kit';
|
|
2
2
|
import type { SolanaChain } from '@solana/wallet-standard-chains';
|
|
3
3
|
import type { SolanaSignInInput, SolanaSignInOutput } from '@solana/wallet-standard-features';
|
|
4
4
|
import type { IdentifierString } from '@wallet-standard/base';
|
|
@@ -228,13 +228,19 @@ export type WalletNamespace = {
|
|
|
228
228
|
*/
|
|
229
229
|
connect: (wallet: UiWallet, options?: WalletActionOptions) => Promise<readonly UiWalletAccount[]>;
|
|
230
230
|
/**
|
|
231
|
-
* Disconnect
|
|
231
|
+
* Disconnect a wallet. Calls `standard:disconnect` if supported.
|
|
232
|
+
*
|
|
233
|
+
* `wallet` defaults to the active wallet. Passing a non-active, currently
|
|
234
|
+
* authorized wallet deauthorizes it (calling `standard:disconnect` if
|
|
235
|
+
* supported) while leaving the active connection untouched. A `wallet`
|
|
236
|
+
* that doesn't support `standard:disconnect`, or one that is already
|
|
237
|
+
* unauthorized/unregistered, is a forgiving no-op.
|
|
232
238
|
*
|
|
233
239
|
* @throws `options.abortSignal.reason` if the signal is already aborted
|
|
234
240
|
* when the action is called. Aborts after the wallet call has been
|
|
235
241
|
* dispatched do not take effect.
|
|
236
242
|
*/
|
|
237
|
-
disconnect: (options?: WalletActionOptions) => Promise<void>;
|
|
243
|
+
disconnect: (wallet?: UiWallet, options?: WalletActionOptions) => Promise<void>;
|
|
238
244
|
/**
|
|
239
245
|
* Get the current wallet state. Referentially stable — a new object is
|
|
240
246
|
* only created when a field actually changes, so React's
|
|
@@ -244,13 +250,19 @@ export type WalletNamespace = {
|
|
|
244
250
|
*/
|
|
245
251
|
getState: () => WalletState;
|
|
246
252
|
/**
|
|
247
|
-
*
|
|
248
|
-
*
|
|
253
|
+
* Select an account, creating and caching a new signer for it.
|
|
254
|
+
*
|
|
255
|
+
* The account may belong to any currently authorized wallet, not only the
|
|
256
|
+
* active one. When it belongs to a different authorized wallet, the active
|
|
257
|
+
* connection switches to that wallet synchronously (no prompt), leaving the
|
|
258
|
+
* previously active wallet authorized. If the store is currently 'disconnected',
|
|
259
|
+
* this allows transitioning to 'connected' synchronously.
|
|
249
260
|
*
|
|
250
|
-
* @throws `SolanaError(SOLANA_ERROR__WALLET__NOT_CONNECTED)` if no wallet is
|
|
251
|
-
* connected, or the connected wallet is currently disconnecting.
|
|
252
261
|
* @throws `SolanaError(SOLANA_ERROR__WALLET__ACCOUNT_NOT_AVAILABLE)` if the
|
|
253
|
-
*
|
|
262
|
+
* account's handle cannot be resolved to a currently authorized wallet, or
|
|
263
|
+
* the account is not among that wallet's accounts.
|
|
264
|
+
* @throws `SolanaError(SOLANA_ERROR__WALLET__NOT_CONNECTED)` if the account's
|
|
265
|
+
* wallet is currently disconnecting.
|
|
254
266
|
*/
|
|
255
267
|
selectAccount: (account: UiWalletAccount) => void;
|
|
256
268
|
/**
|
|
@@ -300,7 +312,7 @@ export type WalletNamespace = {
|
|
|
300
312
|
* when the action is called. Aborts after the wallet call has been
|
|
301
313
|
* dispatched do not take effect.
|
|
302
314
|
*/
|
|
303
|
-
signMessage: (message:
|
|
315
|
+
signMessage: (message: ReadonlyUint8Array, options?: WalletActionOptions) => Promise<SignatureBytes>;
|
|
304
316
|
/**
|
|
305
317
|
* Subscribe to any wallet state change. Compatible with React's
|
|
306
318
|
* `useSyncExternalStore` and similar framework primitives.
|
|
@@ -313,6 +325,42 @@ export type WalletNamespace = {
|
|
|
313
325
|
* ```
|
|
314
326
|
*/
|
|
315
327
|
subscribe: (listener: () => void) => () => void;
|
|
328
|
+
/**
|
|
329
|
+
* **Advanced.** Resolves once the initial connection attempt has settled —
|
|
330
|
+
* i.e. {@link getState}'s `status` is no longer `'pending'` or
|
|
331
|
+
* `'reconnecting'`.
|
|
332
|
+
*
|
|
333
|
+
* You only need this if your app **rebuilds the client at runtime** (for
|
|
334
|
+
* example, to change chain). Each freshly built client runs a silent
|
|
335
|
+
* auto-reconnect that briefly passes through `'pending'`/`'reconnecting'`;
|
|
336
|
+
* awaiting this lets you hold the previous UI until the new client is ready
|
|
337
|
+
* instead of flashing a "reconnecting" state on every swap. Most apps never
|
|
338
|
+
* call it — subscribe to `status` with {@link subscribe} instead.
|
|
339
|
+
*
|
|
340
|
+
* Does **not** wait for user-initiated `connect`/`disconnect`/`signIn`
|
|
341
|
+
* (those pass through `'connecting'`/`'disconnecting'`, which count as
|
|
342
|
+
* ready), so a normal connect never makes this block. While transient it
|
|
343
|
+
* returns the **same** promise reference on every call, so successive
|
|
344
|
+
* awaits during one warm-up share a single settlement.
|
|
345
|
+
*
|
|
346
|
+
* Disposing the client mid-warm-up settles the status to `'disconnected'`,
|
|
347
|
+
* so a pending `whenReady()` resolves rather than hanging. Check
|
|
348
|
+
* {@link getState} after awaiting if you need to distinguish a ready
|
|
349
|
+
* connection from a disposed (or never-connected) client.
|
|
350
|
+
*
|
|
351
|
+
* @returns A promise that resolves with no value once the wallet is past its
|
|
352
|
+
* initial `'pending'`/`'reconnecting'` warm-up. Already resolved when the
|
|
353
|
+
* status is not transient.
|
|
354
|
+
*
|
|
355
|
+
* @example
|
|
356
|
+
* ```ts
|
|
357
|
+
* // On a chain switch, hold the old UI until the rebuilt client is ready:
|
|
358
|
+
* const next = createClient().use(walletSigner({ chain }));
|
|
359
|
+
* await next.wallet.whenReady();
|
|
360
|
+
* setClient(next);
|
|
361
|
+
* ```
|
|
362
|
+
*/
|
|
363
|
+
whenReady: () => Promise<void>;
|
|
316
364
|
};
|
|
317
365
|
/**
|
|
318
366
|
* Properties added to the client by the wallet plugins.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,cAAc,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAAA,OAAO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;;;;;;;;;;;;;;;;;;;;;;;;;;;OA+BG;IACH,MAAM,EAAE,CAAC,MAAM,EAAE,QAAQ,EAAE,KAAK,EAAE,iBAAiB,EAAE,OAAO,CAAC,EAAE,mBAAmB,KAAK,OAAO,CAAC,kBAAkB,CAAC,CAAC;IAEnH;;;;;;;;;;;;;OAaG;IACH,WAAW,EAAE,CAAC,OAAO,EAAE,kBAAkB,EAAE,OAAO,CAAC,EAAE,mBAAmB,KAAK,OAAO,CAAC,cAAc,CAAC,CAAC;IAErG;;;;;;;;;;OAUG;IACH,SAAS,EAAE,CAAC,QAAQ,EAAE,MAAM,IAAI,KAAK,MAAM,IAAI,CAAC;IAEhD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAkCG;IACH,SAAS,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;CAClC,CAAC;AAEF;;;;;;;;;;;;;;GAcG;AACH,MAAM,MAAM,gBAAgB,GAAG;IAC3B,wEAAwE;IACxE,QAAQ,CAAC,MAAM,EAAE,eAAe,CAAC;CACpC,CAAC"}
|
package/dist/types/wallet.d.ts
CHANGED
|
@@ -32,7 +32,7 @@ import type { ClientWithWallet, WalletPluginConfig } from './types';
|
|
|
32
32
|
*/
|
|
33
33
|
export declare function walletSigner(config: WalletPluginConfig): <T extends object & {
|
|
34
34
|
wallet?: never;
|
|
35
|
-
}>(client: T) => Disposable & Omit<T, "
|
|
35
|
+
}>(client: T) => Disposable & Omit<T, "identity" | "payer" | "subscribeToIdentity" | "subscribeToPayer" | "wallet"> & ClientWithIdentity & ClientWithPayer & ClientWithSubscribeToIdentity & ClientWithSubscribeToPayer & ClientWithWallet;
|
|
36
36
|
/**
|
|
37
37
|
* A framework-agnostic Kit plugin that manages wallet discovery, connection
|
|
38
38
|
* lifecycle, and signer creation using wallet-standard — and syncs the
|
|
@@ -64,7 +64,7 @@ export declare function walletSigner(config: WalletPluginConfig): <T extends obj
|
|
|
64
64
|
*/
|
|
65
65
|
export declare function walletIdentity(config: WalletPluginConfig): <T extends object & {
|
|
66
66
|
wallet?: never;
|
|
67
|
-
}>(client: T) => Disposable & Omit<T, "
|
|
67
|
+
}>(client: T) => Disposable & Omit<T, "identity" | "subscribeToIdentity" | "wallet"> & ClientWithIdentity & ClientWithSubscribeToIdentity & ClientWithWallet;
|
|
68
68
|
/**
|
|
69
69
|
* A framework-agnostic Kit plugin that manages wallet discovery, connection
|
|
70
70
|
* lifecycle, and signer creation using wallet-standard — and syncs the
|
|
@@ -96,7 +96,7 @@ export declare function walletIdentity(config: WalletPluginConfig): <T extends o
|
|
|
96
96
|
*/
|
|
97
97
|
export declare function walletPayer(config: WalletPluginConfig): <T extends object & {
|
|
98
98
|
wallet?: never;
|
|
99
|
-
}>(client: T) => Disposable & Omit<T, "
|
|
99
|
+
}>(client: T) => Disposable & Omit<T, "payer" | "subscribeToPayer" | "wallet"> & ClientWithPayer & ClientWithSubscribeToPayer & ClientWithWallet;
|
|
100
100
|
/**
|
|
101
101
|
* A framework-agnostic Kit plugin that manages wallet discovery, connection
|
|
102
102
|
* lifecycle, and signer creation using wallet-standard.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"wallet.d.ts","sourceRoot":"","sources":["../../src/wallet.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,KAAK,kBAAkB,EACvB,KAAK,eAAe,EACpB,KAAK,6BAA6B,EAClC,KAAK,0BAA0B,EAMlC,MAAM,aAAa,CAAC;AAGrB,OAAO,KAAK,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"wallet.d.ts","sourceRoot":"","sources":["../../src/wallet.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,KAAK,kBAAkB,EACvB,KAAK,eAAe,EACpB,KAAK,6BAA6B,EAClC,KAAK,0BAA0B,EAMlC,MAAM,aAAa,CAAC;AAGrB,OAAO,KAAK,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC;AAkEpE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,wBAAgB,YAAY,CAAC,MAAM,EAAE,kBAAkB,IAtD3C,CAAC,SAAS,MAAM,GAAG;IAAE,MAAM,CAAC,EAAE,KAAK,CAAA;CAAE,0OA8DhD;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,wBAAgB,cAAc,CAAC,MAAM,EAAE,kBAAkB,IA7F7C,CAAC,SAAS,MAAM,GAAG;IAAE,MAAM,CAAC,EAAE,KAAK,CAAA;CAAE,4JA+FhD;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,wBAAgB,WAAW,CAAC,MAAM,EAAE,kBAAkB,IA9H1C,CAAC,SAAS,MAAM,GAAG;IAAE,MAAM,CAAC,EAAE,KAAK,CAAA;CAAE,gJAgIhD;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,kBAAkB,IAhKlD,CAAC,SAAS,MAAM,GAAG;IAAE,MAAM,CAAC,EAAE,KAAK,CAAA;CAAE,kEAkKhD"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@solana/kit-plugin-wallet",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.13.1",
|
|
4
4
|
"description": "Wallet connection plugin for Kit clients",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"kit",
|
|
@@ -22,6 +22,7 @@
|
|
|
22
22
|
"files": [
|
|
23
23
|
"./dist/types",
|
|
24
24
|
"./dist/index.*",
|
|
25
|
+
"./dist/react/index.*",
|
|
25
26
|
"./src/"
|
|
26
27
|
],
|
|
27
28
|
"type": "commonjs",
|
|
@@ -35,19 +36,33 @@
|
|
|
35
36
|
"types": "./dist/types/index.d.ts",
|
|
36
37
|
"react-native": "./dist/index.react-native.mjs",
|
|
37
38
|
"exports": {
|
|
38
|
-
"
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
"
|
|
42
|
-
|
|
39
|
+
".": {
|
|
40
|
+
"types": "./dist/types/index.d.ts",
|
|
41
|
+
"react-native": "./dist/index.react-native.mjs",
|
|
42
|
+
"browser": {
|
|
43
|
+
"import": "./dist/index.browser.mjs",
|
|
44
|
+
"require": "./dist/index.browser.cjs"
|
|
45
|
+
},
|
|
46
|
+
"node": {
|
|
47
|
+
"import": "./dist/index.node.mjs",
|
|
48
|
+
"require": "./dist/index.node.cjs"
|
|
49
|
+
}
|
|
43
50
|
},
|
|
44
|
-
"
|
|
45
|
-
"
|
|
46
|
-
"
|
|
51
|
+
"./react": {
|
|
52
|
+
"types": "./dist/types/react/index.d.ts",
|
|
53
|
+
"react-native": "./dist/react/index.react-native.mjs",
|
|
54
|
+
"browser": {
|
|
55
|
+
"import": "./dist/react/index.browser.mjs",
|
|
56
|
+
"require": "./dist/react/index.browser.cjs"
|
|
57
|
+
},
|
|
58
|
+
"node": {
|
|
59
|
+
"import": "./dist/react/index.node.mjs",
|
|
60
|
+
"require": "./dist/react/index.node.cjs"
|
|
61
|
+
}
|
|
47
62
|
}
|
|
48
63
|
},
|
|
49
64
|
"dependencies": {
|
|
50
|
-
"@solana/wallet-account-signer": "^
|
|
65
|
+
"@solana/wallet-account-signer": "^7.0.0",
|
|
51
66
|
"@solana/wallet-standard-chains": "^1.1.2",
|
|
52
67
|
"@solana/wallet-standard-features": "^1.4.0",
|
|
53
68
|
"@wallet-standard/app": "^1.1.1",
|
|
@@ -58,10 +73,25 @@
|
|
|
58
73
|
"@wallet-standard/ui-registry": "^1.1.1"
|
|
59
74
|
},
|
|
60
75
|
"devDependencies": {
|
|
61
|
-
"@
|
|
76
|
+
"@solana/react": "^7.0.0",
|
|
77
|
+
"@testing-library/react": "^16.0.0",
|
|
78
|
+
"@types/react": "^18.0.0 || ^19.0.0",
|
|
79
|
+
"@wallet-standard/errors": "^0.1.2",
|
|
80
|
+
"react": "^18.0.0 || ^19.0.0",
|
|
81
|
+
"react-dom": "^18.0.0 || ^19.0.0"
|
|
62
82
|
},
|
|
63
83
|
"peerDependencies": {
|
|
64
|
-
"@solana/kit": "^
|
|
84
|
+
"@solana/kit": "^7.0.0",
|
|
85
|
+
"@solana/react": "^7.0.0",
|
|
86
|
+
"react": "^18.0.0 || ^19.0.0"
|
|
87
|
+
},
|
|
88
|
+
"peerDependenciesMeta": {
|
|
89
|
+
"@solana/react": {
|
|
90
|
+
"optional": true
|
|
91
|
+
},
|
|
92
|
+
"react": {
|
|
93
|
+
"optional": true
|
|
94
|
+
}
|
|
65
95
|
},
|
|
66
96
|
"browserslist": [
|
|
67
97
|
"supports bigint and not dead",
|
|
@@ -70,8 +100,9 @@
|
|
|
70
100
|
"scripts": {
|
|
71
101
|
"build": "rimraf dist && tsup && tsc -p ./tsconfig.declarations.json",
|
|
72
102
|
"dev": "vitest --project node",
|
|
73
|
-
"test": "pnpm test:types && pnpm test:treeshakability && pnpm test:unit",
|
|
74
|
-
"test:
|
|
103
|
+
"test": "pnpm test:types && pnpm test:treeshakability && pnpm test:packaging && pnpm test:unit",
|
|
104
|
+
"test:packaging": "node ../../scripts/assert-publishable-dist.mjs",
|
|
105
|
+
"test:treeshakability": "for file in dist/index.*.mjs dist/react/index.*.mjs; do agadoo $file; done",
|
|
75
106
|
"test:types": "tsc --noEmit",
|
|
76
107
|
"test:unit": "vitest run"
|
|
77
108
|
}
|
|
@@ -7,6 +7,7 @@ import {
|
|
|
7
7
|
TransactionSigner,
|
|
8
8
|
} from '@solana/kit';
|
|
9
9
|
|
|
10
|
+
import { isWalletWarmingUp, type WalletStatus } from '../index';
|
|
10
11
|
import { ClientWithWallet } from '../types';
|
|
11
12
|
import { walletIdentity, walletPayer, walletSigner, walletWithoutSigner } from '../wallet';
|
|
12
13
|
|
|
@@ -97,6 +98,20 @@ const signer = null as unknown as TransactionSigner;
|
|
|
97
98
|
}
|
|
98
99
|
}
|
|
99
100
|
|
|
101
|
+
// [DESCRIBE] isWalletWarmingUp
|
|
102
|
+
{
|
|
103
|
+
// It is exported from the root entry and narrows a status to a boolean.
|
|
104
|
+
{
|
|
105
|
+
const status = null as unknown as WalletStatus;
|
|
106
|
+
isWalletWarmingUp(status) satisfies boolean;
|
|
107
|
+
}
|
|
108
|
+
// It requires a WalletStatus argument.
|
|
109
|
+
{
|
|
110
|
+
// @ts-expect-error isWalletWarmingUp requires a status argument.
|
|
111
|
+
isWalletWarmingUp();
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
100
115
|
// [DESCRIBE] Only one wallet plugin allowed
|
|
101
116
|
{
|
|
102
117
|
// It fails to typecheck when a wallet plugin is used on a client that already has wallet.
|
package/src/index.ts
CHANGED
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import type { ReadonlyUint8Array, SignatureBytes } from '@solana/kit';
|
|
2
|
+
import type { SolanaSignInInput, SolanaSignInOutput } from '@solana/wallet-standard-features';
|
|
3
|
+
import type { UiWallet, UiWalletAccount } from '@wallet-standard/ui';
|
|
4
|
+
import type { ReactNode } from 'react';
|
|
5
|
+
|
|
6
|
+
import type { WalletState, WalletStatus } from '../../types';
|
|
7
|
+
import {
|
|
8
|
+
useConnect,
|
|
9
|
+
useConnectedWallet,
|
|
10
|
+
useDisconnect,
|
|
11
|
+
useIsWalletReady,
|
|
12
|
+
useSelectAccount,
|
|
13
|
+
useSignIn,
|
|
14
|
+
useSignMessage,
|
|
15
|
+
useWallets,
|
|
16
|
+
WalletReadyGate,
|
|
17
|
+
type WalletReadyGateProps,
|
|
18
|
+
useWalletStatus,
|
|
19
|
+
} from '../index';
|
|
20
|
+
|
|
21
|
+
// NB: hooks are only type-checked here, never executed.
|
|
22
|
+
|
|
23
|
+
// [DESCRIBE] useWalletStatus
|
|
24
|
+
{
|
|
25
|
+
const status = useWalletStatus();
|
|
26
|
+
status satisfies WalletStatus;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// [DESCRIBE] useIsWalletReady
|
|
30
|
+
{
|
|
31
|
+
const isReady = useIsWalletReady();
|
|
32
|
+
isReady satisfies boolean;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// [DESCRIBE] WalletReadyGate
|
|
36
|
+
{
|
|
37
|
+
// Both `children` and `fallback` are required `ReactNode` props.
|
|
38
|
+
({ children: 'ready', fallback: 'loading' }) satisfies WalletReadyGateProps;
|
|
39
|
+
// The gate is callable and its return type is assignable to `ReactNode`.
|
|
40
|
+
const rendered: ReactNode = WalletReadyGate({ children: null, fallback: null });
|
|
41
|
+
void rendered;
|
|
42
|
+
}
|
|
43
|
+
{
|
|
44
|
+
// @ts-expect-error `fallback` is required.
|
|
45
|
+
({ children: null }) satisfies WalletReadyGateProps;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// [DESCRIBE] useConnectedWallet
|
|
49
|
+
{
|
|
50
|
+
const connected = useConnectedWallet();
|
|
51
|
+
connected satisfies WalletState['connected'];
|
|
52
|
+
// The connection is nullable when disconnected.
|
|
53
|
+
connected satisfies { account: UiWalletAccount } | null;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// [DESCRIBE] useWallets
|
|
57
|
+
{
|
|
58
|
+
const wallets = useWallets();
|
|
59
|
+
wallets satisfies readonly UiWallet[];
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// [DESCRIBE] useConnect
|
|
63
|
+
{
|
|
64
|
+
const action = useConnect();
|
|
65
|
+
action.dispatch(null as unknown as UiWallet);
|
|
66
|
+
action.data satisfies readonly UiWalletAccount[] | undefined;
|
|
67
|
+
// @ts-expect-error dispatch requires the wallet argument.
|
|
68
|
+
action.dispatch();
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
// [DESCRIBE] useDisconnect
|
|
72
|
+
{
|
|
73
|
+
const action = useDisconnect();
|
|
74
|
+
// The wallet argument is optional — omit it to disconnect the active wallet.
|
|
75
|
+
action.dispatch();
|
|
76
|
+
// Or pass a specific wallet to deauthorize.
|
|
77
|
+
action.dispatch(null as unknown as UiWallet);
|
|
78
|
+
action.data satisfies void | undefined;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
// [DESCRIBE] useSignIn
|
|
82
|
+
{
|
|
83
|
+
const action = useSignIn();
|
|
84
|
+
action.dispatch(null as unknown as UiWallet, null as unknown as SolanaSignInInput);
|
|
85
|
+
action.data satisfies SolanaSignInOutput | undefined;
|
|
86
|
+
// @ts-expect-error dispatch requires both the wallet and the sign-in input.
|
|
87
|
+
action.dispatch(null as unknown as UiWallet);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
// [DESCRIBE] useSignMessage
|
|
91
|
+
{
|
|
92
|
+
const action = useSignMessage();
|
|
93
|
+
action.dispatch(new Uint8Array());
|
|
94
|
+
action.data satisfies SignatureBytes | undefined;
|
|
95
|
+
}
|
|
96
|
+
{
|
|
97
|
+
// dispatch accepts a ReadonlyUint8Array (e.g. codec output) without a cast.
|
|
98
|
+
const action = useSignMessage();
|
|
99
|
+
action.dispatch(null as unknown as ReadonlyUint8Array);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
// [DESCRIBE] useSelectAccount
|
|
103
|
+
{
|
|
104
|
+
const selectAccount = useSelectAccount();
|
|
105
|
+
selectAccount(null as unknown as UiWalletAccount) satisfies void;
|
|
106
|
+
// @ts-expect-error selectAccount requires the account argument.
|
|
107
|
+
selectAccount();
|
|
108
|
+
}
|