@joeywallet/wallet-sdk 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.
Files changed (48) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +705 -0
  3. package/dist/client.d.ts +55 -0
  4. package/dist/client.d.ts.map +1 -0
  5. package/dist/client.js +224 -0
  6. package/dist/client.js.map +1 -0
  7. package/dist/detect.d.ts +45 -0
  8. package/dist/detect.d.ts.map +1 -0
  9. package/dist/detect.js +238 -0
  10. package/dist/detect.js.map +1 -0
  11. package/dist/errors.d.ts +75 -0
  12. package/dist/errors.d.ts.map +1 -0
  13. package/dist/errors.js +120 -0
  14. package/dist/errors.js.map +1 -0
  15. package/dist/index.d.ts +13 -0
  16. package/dist/index.d.ts.map +1 -0
  17. package/dist/index.js +13 -0
  18. package/dist/index.js.map +1 -0
  19. package/dist/mutation.d.ts +46 -0
  20. package/dist/mutation.d.ts.map +1 -0
  21. package/dist/mutation.js +67 -0
  22. package/dist/mutation.js.map +1 -0
  23. package/dist/provider.d.ts +159 -0
  24. package/dist/provider.d.ts.map +1 -0
  25. package/dist/provider.js +142 -0
  26. package/dist/provider.js.map +1 -0
  27. package/dist/react.d.ts +76 -0
  28. package/dist/react.d.ts.map +1 -0
  29. package/dist/react.js +225 -0
  30. package/dist/react.js.map +1 -0
  31. package/dist/types.d.ts +391 -0
  32. package/dist/types.d.ts.map +1 -0
  33. package/dist/types.js +38 -0
  34. package/dist/types.js.map +1 -0
  35. package/dist/vanilla.d.ts +58 -0
  36. package/dist/vanilla.d.ts.map +1 -0
  37. package/dist/vanilla.js +161 -0
  38. package/dist/vanilla.js.map +1 -0
  39. package/package.json +70 -0
  40. package/src/client.ts +342 -0
  41. package/src/detect.ts +278 -0
  42. package/src/errors.ts +133 -0
  43. package/src/index.ts +97 -0
  44. package/src/mutation.ts +109 -0
  45. package/src/provider.ts +229 -0
  46. package/src/react.ts +375 -0
  47. package/src/types.ts +440 -0
  48. package/src/vanilla.ts +239 -0
@@ -0,0 +1,142 @@
1
+ /**
2
+ * Wire method names.
3
+ *
4
+ * Short, unprefixed names: the injected provider is already a Joey-specific
5
+ * object, and the same table is what the content-script bridge and the
6
+ * background validate against. The three that also exist over WalletConnect
7
+ * (`signTransaction`, `signTransactionFor`, `signTransactionBulk`) carry the
8
+ * same parameter shapes as Joey mobile, minus the `xrpl_` namespace prefix that
9
+ * only WalletConnect needs.
10
+ */
11
+ export const JOEY_RPC_METHODS = {
12
+ connect: 'connect',
13
+ disconnect: 'disconnect',
14
+ getAccounts: 'getAccounts',
15
+ getNetwork: 'getNetwork',
16
+ signTransaction: 'signTransaction',
17
+ signAndSubmitTransaction: 'signAndSubmitTransaction',
18
+ signTransactionFor: 'signTransactionFor',
19
+ signTransactionBulk: 'signTransactionBulk',
20
+ signIn: 'signIn',
21
+ };
22
+ /** The name Joey registers under with the Wallet Standard. */
23
+ export const JOEY_WALLET_NAME = 'Joey';
24
+ export const JOEY_RDNS = 'xyz.joeywallet';
25
+ /**
26
+ * Events that mean "the provider just finished installing itself".
27
+ *
28
+ * Both are dispatched synchronously by the provider's install step, so a page
29
+ * whose bundle ran before `document_start` injection completed can wait on them
30
+ * instead of polling. There is no Joey-specific ready event on purpose: an
31
+ * extra global signal is one more thing a page can probe to fingerprint the
32
+ * extension, and these two already exist for discovery.
33
+ */
34
+ export const CAIP294_ANNOUNCE_EVENT = 'wallet_announce';
35
+ export const WALLET_STANDARD_REGISTER_EVENT = 'wallet-standard:register-wallet';
36
+ /**
37
+ * Events an *app* dispatches to make wallets announce themselves again.
38
+ *
39
+ * The counterparts to the two above, and the half that matters for a late
40
+ * bundle: a wallet that installed before your code ran has already dispatched
41
+ * its announcement into a page with nobody listening. Waiting for a second one
42
+ * that will never come is how a detection helper times out against a wallet
43
+ * that is sitting right there. {@link waitForJoey} dispatches both.
44
+ */
45
+ export const CAIP294_PROMPT_EVENT = 'wallet_prompt';
46
+ export const WALLET_STANDARD_APP_READY_EVENT = 'wallet-standard:app-ready';
47
+ /* ------------------------------------------------------------------ limits */
48
+ /**
49
+ * How long the wallet's own plumbing will wait before answering for it.
50
+ *
51
+ * Published because a dapp cannot otherwise size its own spinner or its own
52
+ * retry, and the two numbers are three orders of magnitude apart on purpose. A
53
+ * method that never touches the approval queue — `getAccounts`, `getNetwork`,
54
+ * `disconnect` — answers in milliseconds or the extension's worker is wedged,
55
+ * so it gets {@link REQUEST_TIMEOUT_MS}. A method that does touch the queue is
56
+ * waiting on a person reading a transaction, and its ceiling is
57
+ * {@link APPROVAL_TIMEOUT_MS}, which matches the approval's own expiry: a
58
+ * shorter one would fail a dapp for a signature the user did in fact give.
59
+ *
60
+ * So `signTransaction` can legitimately be pending for five minutes, and with
61
+ * the page's own backstop on top of it, a little over five. Do not put a
62
+ * thirty-second timeout around it.
63
+ */
64
+ export const REQUEST_TIMEOUT_MS = 30_000;
65
+ export const APPROVAL_TIMEOUT_MS = 300_000;
66
+ /**
67
+ * The most transactions `signTransactionBulk` will accept in one call.
68
+ *
69
+ * Exported so a dapp can split its own work rather than discover the rule by
70
+ * rejection. The wallet enforces it; this is the same constant, imported by the
71
+ * wallet from here.
72
+ */
73
+ export const MAX_BULK_TRANSACTIONS = 32;
74
+ /**
75
+ * Transaction types Joey refuses to sign for a website, whatever the user
76
+ * clicks and whichever method carries them.
77
+ *
78
+ * Published so a dapp can check before it builds a flow around one, and so the
79
+ * refusal is a documented rule rather than a surprise `4100`. Every entry hands
80
+ * over or destroys the account itself:
81
+ *
82
+ * - `SetRegularKey`, `SignerListSet` and `DelegateSet` (XLS-75) each grant
83
+ * permanent authority to act as the account, by three separate mechanisms.
84
+ * - `AccountDelete` is irreversible.
85
+ * - `SetHook` installs code that runs on every future transaction.
86
+ * - `Batch` (XLS-56) carries other transactions inside `RawTransactions`, and
87
+ * Joey's approval screen renders the outer transaction. A user cannot consent
88
+ * to something they were never shown, so it is refused until the review
89
+ * screen can render inner transactions individually.
90
+ *
91
+ * Two rules are not expressible as a type name and are enforced anyway:
92
+ * `AccountSet` is refused when it sets or clears a flag that changes who
93
+ * controls the account (`asfDisableMaster`, `asfRequireAuth`, `asfNoFreeze` and
94
+ * the rest of that family) and permitted otherwise; and the ledger's
95
+ * pseudo-transactions — `EnableAmendment`, `SetFee`, `UNLModify` — are refused
96
+ * because no account signs one.
97
+ *
98
+ * The wallet checks at every nesting level, not just the top.
99
+ */
100
+ export const JOEY_DAPP_FORBIDDEN_TRANSACTION_TYPES = Object.freeze([
101
+ 'SetRegularKey',
102
+ 'SignerListSet',
103
+ 'DelegateSet',
104
+ 'AccountDelete',
105
+ 'SetHook',
106
+ 'Batch',
107
+ ]);
108
+ export function isJoeyInjectedProvider(value) {
109
+ if (typeof value !== 'object' || value === null)
110
+ return false;
111
+ const candidate = value;
112
+ return typeof candidate.request === 'function' && typeof candidate.on === 'function';
113
+ }
114
+ /**
115
+ * Call a provider method by name, preferring the typed method over `request()`.
116
+ *
117
+ * The typed methods are not just sugar: `connect`, `disconnect` and
118
+ * `getAccounts` update the provider's own `accounts` and `chain` state, which a
119
+ * dapp reads synchronously through `joey.accounts` / `joey.isConnected()`.
120
+ * Routing those through `request()` would leave that state stale. `request()`
121
+ * remains the fallback for a provider older or newer than this SDK.
122
+ */
123
+ export async function invoke(provider, method, params) {
124
+ const implementation = provider[method];
125
+ if (typeof implementation === 'function') {
126
+ return (await implementation.call(provider, params));
127
+ }
128
+ return await provider.request(params === undefined ? { method } : { method, params });
129
+ }
130
+ /** Subscribe, tolerating a provider that reports removal three different ways. */
131
+ export function subscribe(provider, event, listener) {
132
+ const returned = provider.on(event, listener);
133
+ if (typeof returned === 'function')
134
+ return returned;
135
+ return () => {
136
+ if (typeof provider.removeListener === 'function')
137
+ provider.removeListener(event, listener);
138
+ else if (typeof provider.off === 'function')
139
+ provider.off(event, listener);
140
+ };
141
+ }
142
+ //# sourceMappingURL=provider.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"provider.js","sourceRoot":"","sources":["../src/provider.ts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— because that is the shape web3 developers
6
+ * already have muscle memory for. They do not depend on react-query: a wallet
7
+ * SDK that drags a cache library into every dapp is a tax on integration, and
8
+ * none of react-query's real features (caching, invalidation, retries) apply to
9
+ * a call whose side effect is a human clicking Approve.
10
+ *
11
+ * `react` is an optional peer dependency. Nothing in the core entry point
12
+ * imports this file.
13
+ */
14
+ import { type ReactNode } from 'react';
15
+ import type { Joey } from './client.js';
16
+ import { JoeyRpcError } from './errors.js';
17
+ import { type MutationState } from './mutation.js';
18
+ import type { AnyTransaction, ConnectParams, ConnectResult, JoeyNetwork, SignAndSubmitTransactionResult, SignInParams, SignInResult, SignTransactionBulkParams, SignTransactionForParams, SignTransactionParams, SignTransactionResult, TransactionLike } from './types.js';
19
+ export interface JoeyContextValue {
20
+ /** `null` until the provider is found, and forever if it never appears. */
21
+ joey: Joey | null;
22
+ isAvailable: boolean;
23
+ /** True once detection has finished, whether or not it found anything. */
24
+ isReady: boolean;
25
+ /** Every address granted to this origin. */
26
+ accounts: string[];
27
+ /** The first granted address, which is what most dapps mean by "the account". */
28
+ account: string | null;
29
+ network: JoeyNetwork | null;
30
+ isConnected: boolean;
31
+ connect(params?: ConnectParams): Promise<ConnectResult>;
32
+ disconnect(): Promise<void>;
33
+ /** Re-read the accounts and network from the wallet. */
34
+ refresh(): Promise<void>;
35
+ }
36
+ export interface JoeyProviderProps {
37
+ children?: ReactNode;
38
+ /**
39
+ * Attempt a silent reconnect on mount. Only returns accounts the user already
40
+ * granted this origin, so it never opens an approval window.
41
+ */
42
+ autoConnect?: boolean;
43
+ /** How long to wait for a late-injected provider. Default 3000ms. */
44
+ detectTimeoutMs?: number;
45
+ }
46
+ export declare function JoeyProvider(props: JoeyProviderProps): ReactNode;
47
+ export declare function useJoey(): JoeyContextValue;
48
+ export interface UseJoeyMutationOptions<TData, TVariables> {
49
+ onSuccess?(data: TData, variables: TVariables): void;
50
+ onError?(error: JoeyRpcError, variables: TVariables): void;
51
+ onSettled?(data: TData | undefined, error: JoeyRpcError | undefined, variables: TVariables): void;
52
+ }
53
+ export interface UseJoeyMutationResult<TData, TVariables> extends MutationState<TData, TVariables> {
54
+ /** Fire and forget. Never rejects — read `error` instead. */
55
+ mutate(variables: TVariables): void;
56
+ /** Resolves the result, or rejects with `JoeyRpcError`. */
57
+ mutateAsync(variables: TVariables): Promise<TData>;
58
+ reset(): void;
59
+ }
60
+ /**
61
+ * Build a mutation hook over a Joey method.
62
+ *
63
+ * Exported so a dapp can wrap a method this SDK version does not model, using
64
+ * `joey.request()`, and still get the same `{ mutate, isPending, error }` shape
65
+ * as the built-in hooks.
66
+ */
67
+ export declare function useJoeyMutation<TData, TVariables>(run: (joey: Joey, variables: TVariables) => Promise<TData>, options?: UseJoeyMutationOptions<TData, TVariables>): UseJoeyMutationResult<TData, TVariables>;
68
+ export declare function useConnect(options?: UseJoeyMutationOptions<ConnectResult, ConnectParams | undefined>): UseJoeyMutationResult<ConnectResult, ConnectParams | undefined>;
69
+ export declare function useDisconnect(options?: UseJoeyMutationOptions<void, void>): UseJoeyMutationResult<void, void>;
70
+ export declare function useSignTransaction<TTx extends TransactionLike = AnyTransaction>(options?: UseJoeyMutationOptions<SignTransactionResult, SignTransactionParams<TTx>>): UseJoeyMutationResult<SignTransactionResult, SignTransactionParams<TTx>>;
71
+ export declare function useSignAndSubmit<TTx extends TransactionLike = AnyTransaction>(options?: UseJoeyMutationOptions<SignAndSubmitTransactionResult, SignTransactionParams<TTx>>): UseJoeyMutationResult<SignAndSubmitTransactionResult, SignTransactionParams<TTx>>;
72
+ export declare function useSignTransactionFor<TTx extends TransactionLike = AnyTransaction>(options?: UseJoeyMutationOptions<SignTransactionResult, SignTransactionForParams<TTx>>): UseJoeyMutationResult<SignTransactionResult, SignTransactionForParams<TTx>>;
73
+ export declare function useSignTransactionBulk<TTx extends TransactionLike = AnyTransaction>(options?: UseJoeyMutationOptions<SignAndSubmitTransactionResult[], SignTransactionBulkParams<TTx>>): UseJoeyMutationResult<SignAndSubmitTransactionResult[], SignTransactionBulkParams<TTx>>;
74
+ export declare function useSignIn(options?: UseJoeyMutationOptions<SignInResult, SignInParams | undefined>): UseJoeyMutationResult<SignInResult, SignInParams | undefined>;
75
+ export type { MutationState, MutationStatus } from './mutation.js';
76
+ //# sourceMappingURL=react.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"react.d.ts","sourceRoot":"","sources":["../src/react.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AACH,OAAO,EAUL,KAAK,SAAS,EACf,MAAM,OAAO,CAAA;AAEd,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,aAAa,CAAA;AAEvC,OAAO,EAAoB,YAAY,EAAE,MAAM,aAAa,CAAA;AAC5D,OAAO,EAIL,KAAK,aAAa,EACnB,MAAM,eAAe,CAAA;AACtB,OAAO,KAAK,EACV,cAAc,EACd,aAAa,EACb,aAAa,EACb,WAAW,EACX,8BAA8B,EAC9B,YAAY,EACZ,YAAY,EACZ,yBAAyB,EACzB,wBAAwB,EACxB,qBAAqB,EACrB,qBAAqB,EACrB,eAAe,EAChB,MAAM,YAAY,CAAA;AAWnB,MAAM,WAAW,gBAAgB;IAC/B,2EAA2E;IAC3E,IAAI,EAAE,IAAI,GAAG,IAAI,CAAA;IACjB,WAAW,EAAE,OAAO,CAAA;IACpB,0EAA0E;IAC1E,OAAO,EAAE,OAAO,CAAA;IAChB,4CAA4C;IAC5C,QAAQ,EAAE,MAAM,EAAE,CAAA;IAClB,iFAAiF;IACjF,OAAO,EAAE,MAAM,GAAG,IAAI,CAAA;IACtB,OAAO,EAAE,WAAW,GAAG,IAAI,CAAA;IAC3B,WAAW,EAAE,OAAO,CAAA;IACpB,OAAO,CAAC,MAAM,CAAC,EAAE,aAAa,GAAG,OAAO,CAAC,aAAa,CAAC,CAAA;IACvD,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC,CAAA;IAC3B,wDAAwD;IACxD,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC,CAAA;CACzB;A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C,GACvE,qBAAqB,CAAC,YAAY,EAAE,YAAY,GAAG,SAAS,CAAC,CAK/D;AAED,YAAY,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,eAAe,CAAA"}
package/dist/react.js ADDED
@@ -0,0 +1,225 @@
1
+ /**
2
+ * `@joeywallet/wallet-sdk/react`.
3
+ *
4
+ * The hooks are shaped like react-query mutations — `{ mutate, mutateAsync,
5
+ * isPending, error, data, reset }` — because that is the shape web3 developers
6
+ * already have muscle memory for. They do not depend on react-query: a wallet
7
+ * SDK that drags a cache library into every dapp is a tax on integration, and
8
+ * none of react-query's real features (caching, invalidation, retries) apply to
9
+ * a call whose side effect is a human clicking Approve.
10
+ *
11
+ * `react` is an optional peer dependency. Nothing in the core entry point
12
+ * imports this file.
13
+ */
14
+ import { createContext, createElement, useCallback, useContext, useEffect, useMemo, useReducer, useRef, useState, } from 'react';
15
+ import { getJoey, waitForJoey } from './detect.js';
16
+ import { JOEY_ERROR_CODES, JoeyRpcError } from './errors.js';
17
+ import { initialMutationState, mutationReducer, toPublicState, } from './mutation.js';
18
+ function notInstalled() {
19
+ return new JoeyRpcError(JOEY_ERROR_CODES.DISCONNECTED, 'Joey Wallet is not installed, or its provider has not been injected into this page.');
20
+ }
21
+ const JoeyContext = createContext(null);
22
+ export function JoeyProvider(props) {
23
+ const { children, autoConnect = false, detectTimeoutMs = 3000 } = props;
24
+ // Seeded synchronously: when the provider is already on the page the first
25
+ // render is already correct, and no dapp has to render a "detecting" state.
26
+ const [joey, setJoey] = useState(() => getJoey());
27
+ const [isReady, setIsReady] = useState(() => getJoey() !== null);
28
+ const [accounts, setAccounts] = useState([]);
29
+ const [network, setNetwork] = useState(null);
30
+ useEffect(() => {
31
+ if (joey !== null)
32
+ return;
33
+ let cancelled = false;
34
+ const controller = new AbortController();
35
+ waitForJoey({ timeoutMs: detectTimeoutMs, signal: controller.signal })
36
+ .then((found) => {
37
+ if (!cancelled)
38
+ setJoey(found);
39
+ })
40
+ .catch(() => {
41
+ /* absence is a state, not an error the dapp needs to handle here */
42
+ })
43
+ .finally(() => {
44
+ if (!cancelled)
45
+ setIsReady(true);
46
+ });
47
+ return () => {
48
+ cancelled = true;
49
+ controller.abort();
50
+ };
51
+ }, [joey, detectTimeoutMs]);
52
+ const refresh = useCallback(async () => {
53
+ if (joey === null)
54
+ return;
55
+ const [nextAccounts, nextNetwork] = await Promise.all([
56
+ joey.getAccounts().catch(() => []),
57
+ joey.getNetwork().catch(() => null),
58
+ ]);
59
+ setAccounts(nextAccounts);
60
+ setNetwork(nextNetwork);
61
+ }, [joey]);
62
+ useEffect(() => {
63
+ if (joey === null)
64
+ return;
65
+ const offs = [
66
+ joey.on('accountsChanged', (next) => setAccounts(next.map((a) => a.address))),
67
+ joey.on('networkChanged', (next) => setNetwork(next)),
68
+ joey.on('connect', (result) => setAccounts(result.accounts.map((a) => a.address))),
69
+ joey.on('disconnect', () => setAccounts([])),
70
+ ];
71
+ return () => {
72
+ for (const off of offs)
73
+ off();
74
+ };
75
+ }, [joey]);
76
+ useEffect(() => {
77
+ if (joey === null)
78
+ return;
79
+ let cancelled = false;
80
+ const run = async () => {
81
+ if (autoConnect) {
82
+ try {
83
+ const result = await joey.connect({ silent: true });
84
+ if (cancelled)
85
+ return;
86
+ if (result.accounts.length > 0) {
87
+ setAccounts(result.accounts.map((account) => account.address));
88
+ const next = await joey.getNetwork().catch(() => null);
89
+ if (!cancelled)
90
+ setNetwork(next);
91
+ return;
92
+ }
93
+ }
94
+ catch {
95
+ // A silent connect is best-effort. Fall through to the plain refresh.
96
+ }
97
+ }
98
+ if (!cancelled)
99
+ await refresh();
100
+ };
101
+ void run();
102
+ return () => {
103
+ cancelled = true;
104
+ };
105
+ }, [joey, autoConnect, refresh]);
106
+ const connect = useCallback(async (params) => {
107
+ if (joey === null)
108
+ throw notInstalled();
109
+ const result = await joey.connect(params);
110
+ setAccounts(result.accounts.map((account) => account.address));
111
+ if (result.chain !== null) {
112
+ setNetwork(await joey.getNetwork().catch(() => null));
113
+ }
114
+ return result;
115
+ }, [joey]);
116
+ const disconnect = useCallback(async () => {
117
+ if (joey === null)
118
+ return;
119
+ await joey.disconnect();
120
+ setAccounts([]);
121
+ }, [joey]);
122
+ const value = useMemo(() => ({
123
+ joey,
124
+ isAvailable: joey !== null,
125
+ isReady,
126
+ accounts,
127
+ account: accounts[0] ?? null,
128
+ network,
129
+ isConnected: accounts.length > 0,
130
+ connect,
131
+ disconnect,
132
+ refresh,
133
+ }), [joey, isReady, accounts, network, connect, disconnect, refresh]);
134
+ return createElement(JoeyContext.Provider, { value }, children);
135
+ }
136
+ export function useJoey() {
137
+ const value = useContext(JoeyContext);
138
+ if (value === null) {
139
+ throw new Error('useJoey must be used inside a <JoeyProvider>.');
140
+ }
141
+ return value;
142
+ }
143
+ /**
144
+ * Build a mutation hook over a Joey method.
145
+ *
146
+ * Exported so a dapp can wrap a method this SDK version does not model, using
147
+ * `joey.request()`, and still get the same `{ mutate, isPending, error }` shape
148
+ * as the built-in hooks.
149
+ */
150
+ export function useJoeyMutation(run, options = {}) {
151
+ const { joey } = useJoey();
152
+ const [state, dispatch] = useReducer((mutationReducer), undefined, (initialMutationState));
153
+ const runIdRef = useRef(0);
154
+ const mountedRef = useRef(true);
155
+ useEffect(() => {
156
+ mountedRef.current = true;
157
+ return () => {
158
+ mountedRef.current = false;
159
+ };
160
+ }, []);
161
+ // Held in refs so a callback identity that changes between renders does not
162
+ // change the identity of `mutate`, which dapps put in dependency arrays.
163
+ const runRef = useRef(run);
164
+ runRef.current = run;
165
+ const optionsRef = useRef(options);
166
+ optionsRef.current = options;
167
+ const mutateAsync = useCallback(async (variables) => {
168
+ const runId = ++runIdRef.current;
169
+ dispatch({ type: 'start', variables, runId });
170
+ try {
171
+ if (joey === null)
172
+ throw notInstalled();
173
+ const data = await runRef.current(joey, variables);
174
+ if (mountedRef.current)
175
+ dispatch({ type: 'success', data, runId });
176
+ optionsRef.current.onSuccess?.(data, variables);
177
+ optionsRef.current.onSettled?.(data, undefined, variables);
178
+ return data;
179
+ }
180
+ catch (cause) {
181
+ const error = JoeyRpcError.from(cause);
182
+ if (mountedRef.current)
183
+ dispatch({ type: 'error', error, runId });
184
+ optionsRef.current.onError?.(error, variables);
185
+ optionsRef.current.onSettled?.(undefined, error, variables);
186
+ throw error;
187
+ }
188
+ }, [joey]);
189
+ const mutate = useCallback((variables) => {
190
+ void mutateAsync(variables).catch(() => {
191
+ /* surfaced through `error`; swallowing keeps `mutate` unrejectable */
192
+ });
193
+ }, [mutateAsync]);
194
+ const reset = useCallback(() => {
195
+ dispatch({ type: 'reset' });
196
+ }, []);
197
+ return { ...toPublicState(state), mutate, mutateAsync, reset };
198
+ }
199
+ export function useConnect(options) {
200
+ const { connect } = useJoey();
201
+ return useJoeyMutation(
202
+ // Routed through the context so the provider's account/network state is
203
+ // updated by the same call that resolves the mutation.
204
+ (_joey, params) => connect(params), options);
205
+ }
206
+ export function useDisconnect(options) {
207
+ const { disconnect } = useJoey();
208
+ return useJoeyMutation(() => disconnect(), options);
209
+ }
210
+ export function useSignTransaction(options) {
211
+ return useJoeyMutation((joey, params) => joey.signTransaction(params), options);
212
+ }
213
+ export function useSignAndSubmit(options) {
214
+ return useJoeyMutation((joey, params) => joey.signAndSubmitTransaction(params), options);
215
+ }
216
+ export function useSignTransactionFor(options) {
217
+ return useJoeyMutation((joey, params) => joey.signTransactionFor(params), options);
218
+ }
219
+ export function useSignTransactionBulk(options) {
220
+ return useJoeyMutation((joey, params) => joey.signTransactionBulk(params), options);
221
+ }
222
+ export function useSignIn(options) {
223
+ return useJoeyMutation((joey, params) => joey.signIn(params), options);
224
+ }
225
+ //# sourceMappingURL=react.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"react.js","sourceRoot":"","sources":["../src/react.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AACH,OAAO,EACL,aAAa,EACb,aAAa,EACb,WAAW,EACX,UAAU,EACV,SAAS,EACT,OAAO,EACP,UAAU,EACV,MAA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