@usearete/react 0.46.0 → 0.48.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.
@@ -0,0 +1,73 @@
1
+ import { WalletStandardWallet, WalletStandardAccount, AdapterTransportSelection, KitWalletAdapter, WalletStandardSignerError } from '@usearete/adapter-kit';
2
+ export { KitWalletAdapter, WalletStandardAccount, WalletStandardSignerError, WalletStandardSignerErrorCode, WalletStandardWallet, isWalletStandardSignerError } from '@usearete/adapter-kit';
3
+ import { UiWalletAccount } from '@wallet-standard/ui-core';
4
+
5
+ /**
6
+ * `@usearete/react/wallet-standard`: the connected Wallet Standard account as
7
+ * the wallet Arete signs with.
8
+ *
9
+ * Kept out of the main entry so apps that do not use Wallet Standard do not
10
+ * need its packages: this entry needs `@usearete/adapter-kit` (and its
11
+ * `@solana/kit` peer) and `@wallet-standard/ui-registry`, which every
12
+ * `@wallet-standard/react` app already has.
13
+ */
14
+
15
+ /** A Wallet Standard wallet and one of its accounts, outside React's UI handles. */
16
+ interface WalletStandardSelection {
17
+ readonly wallet: WalletStandardWallet;
18
+ readonly account: WalletStandardAccount;
19
+ }
20
+ interface UseWalletStandardWalletOptions {
21
+ /** CAIP-2 chain the wallet signs for, e.g. `solana:mainnet`. */
22
+ readonly chain?: string;
23
+ /**
24
+ * Where the signed transaction is submitted. Defaults to `'auto'`: the
25
+ * Arete client's or session's transaction transport.
26
+ */
27
+ readonly transport?: AdapterTransportSelection;
28
+ }
29
+ interface UseWalletStandardWalletResult {
30
+ /**
31
+ * The sign-only wallet for `AreteProvider wallet={...}`, `createSession`
32
+ * or `execute(prepared, { wallet })`. `undefined` while nothing is
33
+ * connected or when the account cannot be used (see `error`).
34
+ */
35
+ readonly wallet: KitWalletAdapter | undefined;
36
+ /** The connected account's address. */
37
+ readonly address: string | null;
38
+ /** The wallet's approval prompt is open: show "check your wallet". */
39
+ readonly isPromptOpen: boolean;
40
+ /**
41
+ * Why the account cannot sign for Arete; switch on `error.code`:
42
+ *
43
+ * - `sign_transaction_unsupported`: the wallet lacks
44
+ * `solana:signTransaction` (it only signs and sends in one step).
45
+ * - `chain_unsupported`: the account does not sign for `options.chain`.
46
+ * - `account_unavailable`: the account could not be read, or its wallet is
47
+ * no longer registered.
48
+ *
49
+ * A declined prompt is not reported here: it fails the run
50
+ * (`useOperationMutation`'s `wallet-rejected`), and the wallet stays usable.
51
+ */
52
+ readonly error: WalletStandardSignerError | null;
53
+ }
54
+ /**
55
+ * The connected Wallet Standard account as the wallet the Arete provider and
56
+ * sessions sign with. Sign only: the wallet signs (`solana:signTransaction`)
57
+ * and Arete submits the signed bytes through the transport it already uses.
58
+ *
59
+ * ```tsx
60
+ * const { wallets } = useWallets(); // @wallet-standard/react
61
+ * const account = selectedWallet?.accounts[0] ?? null;
62
+ * const { wallet, isPromptOpen, error } = useWalletStandardWallet(account, { chain: 'solana:mainnet' });
63
+ * return <AreteProvider wallet={wallet}>…{isPromptOpen && 'Check your wallet'}</AreteProvider>;
64
+ * ```
65
+ *
66
+ * Accepts a `UiWalletAccount` from `@wallet-standard/react`, or a raw
67
+ * `{ wallet, account }` pair. The returned adapter is stable while the
68
+ * account, chain and transport stay the same.
69
+ */
70
+ declare function useWalletStandardWallet(source: UiWalletAccount | WalletStandardSelection | null | undefined, options?: UseWalletStandardWalletOptions): UseWalletStandardWalletResult;
71
+
72
+ export { useWalletStandardWallet };
73
+ export type { UseWalletStandardWalletOptions, UseWalletStandardWalletResult, WalletStandardSelection };
@@ -0,0 +1,120 @@
1
+ import { useState, useRef, useEffect, useMemo } from 'react';
2
+ import { WalletStandardSignerError, createWalletStandardWalletAdapter, isWalletStandardSignerError } from '@usearete/adapter-kit';
3
+ export { WalletStandardSignerError, isWalletStandardSignerError } from '@usearete/adapter-kit';
4
+ import { getWalletForHandle, getWalletAccountForUiWalletAccount } from '@wallet-standard/ui-registry';
5
+
6
+ /**
7
+ * `@usearete/react/wallet-standard`: the connected Wallet Standard account as
8
+ * the wallet Arete signs with.
9
+ *
10
+ * Kept out of the main entry so apps that do not use Wallet Standard do not
11
+ * need its packages: this entry needs `@usearete/adapter-kit` (and its
12
+ * `@solana/kit` peer) and `@wallet-standard/ui-registry`, which every
13
+ * `@wallet-standard/react` app already has.
14
+ */
15
+ function isSelection(source) {
16
+ return 'wallet' in source && 'account' in source;
17
+ }
18
+ function resolveSelection(source) {
19
+ if (isSelection(source))
20
+ return source;
21
+ // The registry hands back the wallet's own objects: the wallet may compare
22
+ // the account it is asked to sign for by identity.
23
+ return {
24
+ wallet: getWalletForHandle(source),
25
+ account: getWalletAccountForUiWalletAccount(source),
26
+ };
27
+ }
28
+ /**
29
+ * The connected Wallet Standard account as the wallet the Arete provider and
30
+ * sessions sign with. Sign only: the wallet signs (`solana:signTransaction`)
31
+ * and Arete submits the signed bytes through the transport it already uses.
32
+ *
33
+ * ```tsx
34
+ * const { wallets } = useWallets(); // @wallet-standard/react
35
+ * const account = selectedWallet?.accounts[0] ?? null;
36
+ * const { wallet, isPromptOpen, error } = useWalletStandardWallet(account, { chain: 'solana:mainnet' });
37
+ * return <AreteProvider wallet={wallet}>…{isPromptOpen && 'Check your wallet'}</AreteProvider>;
38
+ * ```
39
+ *
40
+ * Accepts a `UiWalletAccount` from `@wallet-standard/react`, or a raw
41
+ * `{ wallet, account }` pair. The returned adapter is stable while the
42
+ * account, chain and transport stay the same.
43
+ */
44
+ function useWalletStandardWallet(source, options = {}) {
45
+ // Open prompts, counted per adapter. Each adapter only moves its own
46
+ // count, so a prompt the previous account's adapter closes late cannot
47
+ // hide one the current adapter has open.
48
+ const [prompts, setPrompts] = useState(() => new Map());
49
+ const mountedRef = useRef(true);
50
+ useEffect(() => {
51
+ mountedRef.current = true;
52
+ return () => {
53
+ mountedRef.current = false;
54
+ };
55
+ }, []);
56
+ let selection = null;
57
+ let resolveError = null;
58
+ if (source) {
59
+ try {
60
+ selection = resolveSelection(source);
61
+ }
62
+ catch (cause) {
63
+ resolveError = new WalletStandardSignerError('account_unavailable', cause instanceof Error && cause.message
64
+ ? cause.message
65
+ : 'The wallet account is not available', { cause });
66
+ }
67
+ }
68
+ const wallet = selection?.wallet;
69
+ const account = selection?.account;
70
+ const { chain, transport } = options;
71
+ const created = useMemo(() => {
72
+ if (!wallet || !account)
73
+ return { error: null };
74
+ let adapter = null;
75
+ const adjust = (delta) => {
76
+ if (!mountedRef.current || !adapter)
77
+ return;
78
+ const owner = adapter;
79
+ setPrompts((current) => {
80
+ const open = Math.max(0, (current.get(owner) ?? 0) + delta);
81
+ if (open === (current.get(owner) ?? 0))
82
+ return current;
83
+ const next = new Map(current);
84
+ if (open === 0)
85
+ next.delete(owner);
86
+ else
87
+ next.set(owner, open);
88
+ return next;
89
+ });
90
+ };
91
+ try {
92
+ adapter = createWalletStandardWalletAdapter({
93
+ wallet,
94
+ account,
95
+ chain,
96
+ transport,
97
+ onPromptOpen: () => adjust(1),
98
+ onPromptClose: () => adjust(-1),
99
+ });
100
+ return { adapter, error: null };
101
+ }
102
+ catch (error) {
103
+ return {
104
+ error: isWalletStandardSignerError(error)
105
+ ? error
106
+ : new WalletStandardSignerError('account_unavailable', error instanceof Error ? error.message : String(error), { cause: error }),
107
+ };
108
+ }
109
+ }, [wallet, account, chain, transport]);
110
+ return {
111
+ wallet: created.adapter,
112
+ address: account?.address ?? null,
113
+ isPromptOpen: created.adapter !== undefined
114
+ && (prompts.get(created.adapter) ?? 0) > 0,
115
+ error: resolveError ?? created.error,
116
+ };
117
+ }
118
+
119
+ export { useWalletStandardWallet };
120
+ //# sourceMappingURL=wallet-standard.esm.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"wallet-standard.esm.js","sources":["../src/wallet-standard.ts"],"sourcesContent":[null],"names":[],"mappings":";;;;;AAAA;;;;;;;;AAQG;AA4DH,SAAS,WAAW,CAClB,MAAiD,EAAA;AAEjD,IAAA,OAAO,QAAQ,IAAI,MAAM,IAAI,SAAS,IAAI,MAAM,CAAC;AACnD,CAAC;AAED,SAAS,gBAA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E,CAAC;SACjC;QAAC,OAAO,KAAK,EAAE;YACd,OAAO;AACL,gBAAA,KAAK,EAAE,2BAA2B,CAAC,KAAK,CAAC;AACvC,sBAAE,KAAK;AACP,sBAAE,IAAI,yBAAyB,CAC7B,qBAAqB,EACrB,KAAK,YAAY,KAAK,GAAG,KAAK,CAAC,OAAO,GAAG,MAAM,CAAC,KAAK,CAAC,EACtD,EAAE,KAAK,EAAE,KAAK,EAAE,CACjB;aACJ,CAAC;SACH;KACF,EAAE,CAAC,MAAM,EAAE,OAAO,EAAE,KAAK,EAAE,SAAS,CAAC,CAAC,CAAC;IAExC,OAAO;QACL,MAAM,EAAE,OAAO,CAAC,OAAO;AACvB,QAAA,OAAO,EAAE,OAAO,EAAE,OAAO,IAAI,IAAI;AACjC,QAAA,YAAY,EAAE,OAAO,CAAC,OAAO,KAAK,SAAS;AACtC,eAAA,CAAC,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC;AAC5C,QAAA,KAAK,EAAE,YAAY,IAAI,OAAO,CAAC,KAAK;KACrC,CAAC;AACJ;;;;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@usearete/react",
3
- "version": "0.46.0",
3
+ "version": "0.48.0",
4
4
  "type": "module",
5
5
  "description": "React SDK for the Arete Solana developer platform",
6
6
  "main": "dist/index.cjs",
@@ -17,6 +17,11 @@
17
17
  "import": "./dist/testing.esm.js",
18
18
  "require": "./dist/testing.cjs"
19
19
  },
20
+ "./wallet-standard": {
21
+ "types": "./dist/wallet-standard.d.ts",
22
+ "import": "./dist/wallet-standard.esm.js",
23
+ "require": "./dist/wallet-standard.cjs"
24
+ },
20
25
  "./eslint-plugin.cjs": "./eslint-plugin.cjs",
21
26
  "./eslint-rules/*": "./eslint-rules/*",
22
27
  "./package.json": "./package.json"
@@ -25,6 +30,9 @@
25
30
  "*": {
26
31
  "testing": [
27
32
  "./dist/testing.d.ts"
33
+ ],
34
+ "wallet-standard": [
35
+ "./dist/wallet-standard.d.ts"
28
36
  ]
29
37
  }
30
38
  },
@@ -61,9 +69,23 @@
61
69
  "node": ">=16.0.0"
62
70
  },
63
71
  "peerDependencies": {
64
- "@usearete/sdk": "^0.46.0",
72
+ "@usearete/adapter-kit": "^0.48.0",
73
+ "@usearete/sdk": "^0.48.0",
74
+ "@wallet-standard/ui-core": "^1.0.1",
75
+ "@wallet-standard/ui-registry": "^1.1.0",
65
76
  "react": "^18.0.0 || ^19.0.0"
66
77
  },
78
+ "peerDependenciesMeta": {
79
+ "@usearete/adapter-kit": {
80
+ "optional": true
81
+ },
82
+ "@wallet-standard/ui-core": {
83
+ "optional": true
84
+ },
85
+ "@wallet-standard/ui-registry": {
86
+ "optional": true
87
+ }
88
+ },
67
89
  "dependencies": {
68
90
  "zustand": "^4.0.0 || ^5.0.0"
69
91
  },
@@ -71,12 +93,17 @@
71
93
  "@rollup/plugin-commonjs": "^28.0.9",
72
94
  "@rollup/plugin-node-resolve": "^16.0.3",
73
95
  "@rollup/plugin-typescript": "^11.0.0",
96
+ "@solana/kit": "^8.3.0",
74
97
  "@types/jest": "^29.0.0",
75
98
  "@types/react": "^19.0.0",
76
99
  "@types/react-test-renderer": "^19.1.0",
77
100
  "@typescript-eslint/eslint-plugin": "^6.21.0",
78
101
  "@typescript-eslint/parser": "^6.21.0",
79
- "@usearete/sdk": "^0.46.0",
102
+ "@usearete/adapter-kit": "^0.48.0",
103
+ "@usearete/sdk": "^0.48.0",
104
+ "@wallet-standard/base": "^1.1.1",
105
+ "@wallet-standard/ui-core": "^1.0.1",
106
+ "@wallet-standard/ui-registry": "^1.1.1",
80
107
  "eslint": "^8.0.0",
81
108
  "eslint-plugin-react-hooks": "^5.2.0",
82
109
  "jest": "^29.0.0",