@kheopskit/react 6.0.0-rc.2 → 6.0.0-rc.4

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.js CHANGED
@@ -1,8 +1,8 @@
1
1
  "use client";
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
3
  let _kheopskit_core = require("@kheopskit/core");
4
+ let _kheopskit_core_internal = require("@kheopskit/core/internal");
4
5
  let react = require("react");
5
- let rxjs = require("rxjs");
6
6
  let react_jsx_runtime = require("react/jsx-runtime");
7
7
  //#region src/context.ts
8
8
  const KheopskitContext = (0, react.createContext)(null);
@@ -13,17 +13,15 @@ const useKheopskitExternalStore = (hookName) => {
13
13
  };
14
14
  //#endregion
15
15
  //#region src/createExternalStore.ts
16
- const afterThisCommitsLayoutEffects$1 = () => Promise.resolve();
17
- const createExternalStore = (resolveClientSource, serverValue) => {
18
- let source;
16
+ const createExternalStore = (source$, getInitialValue, serverValue) => {
17
+ let initialValue;
19
18
  let latestValue;
20
19
  let subscription;
21
20
  const listeners = /* @__PURE__ */ new Set();
22
- const getSource = () => {
23
- source ?? (source = resolveClientSource());
24
- return source;
21
+ const getSnapshot = () => {
22
+ initialValue ?? (initialValue = getInitialValue());
23
+ return latestValue ?? initialValue;
25
24
  };
26
- const getSnapshot = () => latestValue ?? getSource().initialValue;
27
25
  const getServerSnapshot = () => serverValue;
28
26
  const releaseWhenUnobserved = () => {
29
27
  if (listeners.size) return;
@@ -31,7 +29,7 @@ const createExternalStore = (resolveClientSource, serverValue) => {
31
29
  subscription = void 0;
32
30
  };
33
31
  const subscribe = (listener) => {
34
- if (!subscription || subscription.closed) subscription = getSource().pipeline.observable$.subscribe((value) => {
32
+ if (!subscription || subscription.closed) subscription = source$.subscribe((value) => {
35
33
  latestValue = value;
36
34
  for (const notify of listeners) notify(value);
37
35
  });
@@ -42,65 +40,10 @@ const createExternalStore = (resolveClientSource, serverValue) => {
42
40
  queueMicrotask(releaseWhenUnobserved);
43
41
  };
44
42
  };
45
- /** The shared pipeline's liveness once this commit's layout effects ran. */
46
- const whenLive = async (signal) => {
47
- await afterThisCommitsLayoutEffects$1();
48
- return getSource().pipeline.whenLive(signal);
49
- };
50
43
  return {
51
44
  getSnapshot,
52
45
  getServerSnapshot,
53
- subscribe,
54
- whenLive
55
- };
56
- };
57
- //#endregion
58
- //#region src/liveActions.ts
59
- const didNotRun = {
60
- aborted: "was aborted",
61
- unheld: "was called while nothing holds the pipeline (no KheopskitProvider of this instance is mounted and visible, and nothing subscribes its kheopskit$)",
62
- errored: "did not run because the pipeline stopped with an error",
63
- completed: "did not run because the pipeline completed"
64
- };
65
- const abortedError = (walletId, operation, end) => new _kheopskit_core.KheopskitError("ABORTED", `${operation} of wallet ${walletId} ${didNotRun[end]}`, { walletId });
66
- /**
67
- * `connect` and `disconnect` for one wallet id that act on the instance's
68
- * pipeline at call time: they wait for the restarted pipeline's first emission
69
- * after an `<Activity>` reveal and reject `ABORTED` while nothing holds it.
70
- */
71
- const walletActions = (store, walletId) => {
72
- const liveWallet = async (operation, signal) => {
73
- const liveness = await store.whenLive(signal);
74
- if (liveness.end) throw abortedError(walletId, operation, liveness.end);
75
- const wallet = liveness.state.wallets.find((candidate) => candidate.id === walletId);
76
- if (!wallet) throw new Error(`[kheopskit] no wallet ${walletId}`);
77
- return wallet;
78
- };
79
- return {
80
- connect: async (options) => (await liveWallet("connect", options?.signal)).connect(options),
81
- disconnect: async () => (await liveWallet("disconnect")).disconnect()
82
- };
83
- };
84
- const withLiveActions = (store) => {
85
- const presented = /* @__PURE__ */ new WeakMap();
86
- const present = (state) => {
87
- let live = presented.get(state);
88
- if (!live) {
89
- live = {
90
- ...state,
91
- wallets: state.wallets.map((wallet) => ({
92
- ...wallet,
93
- ...walletActions(store, wallet.id)
94
- }))
95
- };
96
- presented.set(state, live);
97
- }
98
- return live;
99
- };
100
- return {
101
- ...store,
102
- getSnapshot: () => present(store.getSnapshot()),
103
- getServerSnapshot: () => present(store.getServerSnapshot())
46
+ subscribe
104
47
  };
105
48
  };
106
49
  //#endregion
@@ -120,18 +63,18 @@ const serverSnapshot = (config, ssrCookies) => hydrating(config, ssrCookies ===
120
63
  ssrCookies,
121
64
  storageKey: config.storageKey
122
65
  }), config, { icons: false }));
123
- const KheopskitSourceProvider = ({ children, config, ssrCookies, resolveClientSource }) => {
66
+ const KheopskitSourceProvider = ({ children, kit, config, ssrCookies }) => {
124
67
  const resolvedConfig = (0, react.useMemo)(() => (0, _kheopskit_core.resolveConfig)(config), [config]);
125
- const externalStore = (0, react.useMemo)(() => withLiveActions(createExternalStore(() => {
126
- const { store, pipeline } = resolveClientSource(resolvedConfig);
68
+ const externalStore = (0, react.useMemo)(() => {
69
+ const { present, walletActions } = (0, _kheopskit_core_internal.kheopskitInternals)(kit);
127
70
  return {
128
- pipeline,
129
- initialValue: hydrating(resolvedConfig, (0, _kheopskit_core.getHydratedSnapshot)(store, resolvedConfig, { icons: true }))
71
+ ...createExternalStore(kit.kheopskit$, () => present(hydrating(resolvedConfig, (0, _kheopskit_core.getHydratedSnapshot)(kit.store, resolvedConfig, { icons: true }))), present(serverSnapshot(resolvedConfig, ssrCookies))),
72
+ walletActions
130
73
  };
131
- }, serverSnapshot(resolvedConfig, ssrCookies))), [
74
+ }, [
75
+ kit,
132
76
  resolvedConfig,
133
- ssrCookies,
134
- resolveClientSource
77
+ ssrCookies
135
78
  ]);
136
79
  useIsomorphicLayoutEffect$1(() => externalStore.subscribe(keepPipelineRunning), [externalStore]);
137
80
  return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(KheopskitContext.Provider, {
@@ -140,66 +83,6 @@ const KheopskitSourceProvider = ({ children, config, ssrCookies, resolveClientSo
140
83
  });
141
84
  };
142
85
  //#endregion
143
- //#region src/livePipeline.ts
144
- const createLivePipeline = (source$) => {
145
- let holders = 0;
146
- let run = 0;
147
- let emittedRun = 0;
148
- let latestValue;
149
- let ended;
150
- const firstEmissionWaiters = /* @__PURE__ */ new Set();
151
- const settleFirstEmission = (liveness) => {
152
- for (const waiter of firstEmissionWaiters) waiter(liveness);
153
- };
154
- const observable$ = new rxjs.Observable((subscriber) => {
155
- if (holders++ === 0) {
156
- run++;
157
- ended = void 0;
158
- }
159
- const thisRun = run;
160
- const subscription = source$.subscribe({
161
- next: (value) => {
162
- latestValue = value;
163
- emittedRun = thisRun;
164
- settleFirstEmission({ state: value });
165
- subscriber.next(value);
166
- },
167
- error: (error) => {
168
- ended = "errored";
169
- subscriber.error(error);
170
- },
171
- complete: () => {
172
- ended = "completed";
173
- subscriber.complete();
174
- }
175
- });
176
- return () => {
177
- subscription.unsubscribe();
178
- if (--holders === 0) settleFirstEmission({ end: ended ?? "unheld" });
179
- };
180
- });
181
- const whenLive = async (signal) => {
182
- if (signal?.aborted) return { end: "aborted" };
183
- if (ended) return { end: ended };
184
- if (holders === 0) return { end: "unheld" };
185
- if (emittedRun === run) return { state: latestValue };
186
- return new Promise((resolve) => {
187
- const settle = (liveness) => {
188
- firstEmissionWaiters.delete(settle);
189
- signal?.removeEventListener("abort", onAbort);
190
- resolve(liveness);
191
- };
192
- const onAbort = () => settle({ end: "aborted" });
193
- signal?.addEventListener("abort", onAbort, { once: true });
194
- firstEmissionWaiters.add(settle);
195
- });
196
- };
197
- return {
198
- observable$,
199
- whenLive
200
- };
201
- };
202
- //#endregion
203
86
  //#region src/useStateItem.ts
204
87
  const isSameItemIgnoringClosures = (a, b) => {
205
88
  const previous = a;
@@ -273,24 +156,19 @@ const useWallets = () => {
273
156
  };
274
157
  //#endregion
275
158
  //#region src/createKheopskit.tsx
276
- const deferredStore = (claim) => ({
277
- observable: (0, rxjs.defer)(() => claim().observable),
278
- rememberWallet: (walletId) => claim().rememberWallet(walletId),
279
- forgetWallet: (walletId) => claim().forgetWallet(walletId),
280
- getCachedState: () => claim().getCachedState(),
281
- setCachedState: (wallets, accounts) => claim().setCachedState(wallets, accounts),
282
- destroy: () => claim().destroy()
283
- });
284
159
  /**
285
160
  * Binds a platform tuple once and returns one kheopskit instance: a
286
161
  * `KheopskitProvider`, hooks already typed to those platforms, and the
287
- * `kheopskit$` stream and `store` the provider uses, for code outside React.
288
- * Subscribing `kheopskit$` while the provider is mounted runs no second
289
- * pipeline, and holds the one pipeline for every hook action of the instance.
162
+ * `kheopskit$` stream and `store` the provider uses, and `waitForAccount`, for
163
+ * code outside React.
164
+ * It is `@kheopskit/core`'s `createKheopskit` instance: subscribing
165
+ * `kheopskit$` while the provider is mounted runs no second pipeline, and
166
+ * holds the one pipeline for every hook action of the instance.
290
167
  *
291
- * Without `options.store`, the store is created on first use in the browser:
292
- * backed by cookies when the provider renders first with `ssrCookies`, by
293
- * localStorage otherwise. The caller owns `store.destroy()`.
168
+ * Without `options.store`, the store is created on first use, backed by
169
+ * cookies with `{ ssr: true }` and by localStorage otherwise. Only an
170
+ * instance created with `{ ssr: true }` accepts the provider's `ssrCookies`.
171
+ * The caller owns `store.destroy()`.
294
172
  *
295
173
  * @example
296
174
  * ```tsx
@@ -302,41 +180,23 @@ const deferredStore = (claim) => ({
302
180
  * const { accounts } = useWallets(); // accounts are platform-precise, no generic
303
181
  * ```
304
182
  */
305
- const createKheopskit = (config, options = {}) => {
306
- let claimed;
307
- const claimStore = (ssrCookies) => {
308
- claimed ?? (claimed = options.store ?? (0, _kheopskit_core.createKheopskitStore)({
309
- ssrCookies,
310
- storageKey: (0, _kheopskit_core.resolveConfig)(config).storageKey
311
- }));
312
- return claimed;
313
- };
314
- const shared$ = (0, rxjs.defer)(() => (0, _kheopskit_core.getKheopskit$)(config, { store: claimStore() })).pipe((0, rxjs.shareReplay)({
315
- refCount: true,
316
- bufferSize: 1
317
- }));
318
- const pipeline = createLivePipeline(shared$);
319
- const kheopskit$ = pipeline.observable$;
320
- const Provider = ({ children, ssrCookies }) => {
321
- if (typeof window !== "undefined") claimStore(ssrCookies);
322
- const resolveClientSource = (0, react.useCallback)(() => ({
323
- store: claimStore(ssrCookies),
324
- pipeline
325
- }), [ssrCookies]);
326
- return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(KheopskitSourceProvider, {
327
- config,
328
- ssrCookies,
329
- resolveClientSource,
330
- children
331
- });
332
- };
183
+ const createKheopskit = (config, options) => {
184
+ const kit = (0, _kheopskit_core.createKheopskit)(config, options);
185
+ const Provider = ({ children, ssrCookies }) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(KheopskitSourceProvider, {
186
+ kit,
187
+ config,
188
+ ssrCookies,
189
+ children
190
+ });
333
191
  Provider.displayName = "KheopskitProvider";
334
192
  return {
335
193
  KheopskitProvider: Provider,
336
194
  /** The state stream the provider subscribes to, shared with code outside React. */
337
- kheopskit$,
195
+ kheopskit$: kit.kheopskit$,
338
196
  /** The store `kheopskit$` reads the cache from and persists into. */
339
- store: options.store ?? deferredStore(claimStore),
197
+ store: kit.store,
198
+ /** Resolves with the live account once the running instance lists it. */
199
+ waitForAccount: kit.waitForAccount,
340
200
  /** Current state, typed to the bound platform tuple. */
341
201
  useWallets: () => useWallets(),
342
202
  /** Current accounts, typed to the bound platform tuple. */
@@ -357,23 +217,19 @@ const KheopskitProvider = ({ children, config, ssrCookies, store }) => {
357
217
  hasMountedRef.current = true;
358
218
  lastConfigRef.current = config;
359
219
  }, [config]);
360
- const resolveClientSource = (0, react.useCallback)((resolvedConfig) => {
361
- const sourceStore = store ?? (0, _kheopskit_core.createKheopskitStore)({
362
- ssrCookies,
363
- storageKey: resolvedConfig.storageKey
364
- });
365
- return {
366
- store: sourceStore,
367
- pipeline: createLivePipeline((0, _kheopskit_core.getKheopskit$)(resolvedConfig, {
368
- ssrCookies,
369
- store: sourceStore
370
- }))
371
- };
372
- }, [ssrCookies, store]);
220
+ const ssr = ssrCookies !== void 0;
221
+ const kit = (0, react.useMemo)(() => (0, _kheopskit_core.createKheopskit)({
222
+ ...config,
223
+ platforms: config?.platforms ?? []
224
+ }, store ? { store } : { ssr }), [
225
+ config,
226
+ store,
227
+ ssr
228
+ ]);
373
229
  return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(KheopskitSourceProvider, {
230
+ kit,
374
231
  config,
375
232
  ssrCookies,
376
- resolveClientSource,
377
233
  children
378
234
  });
379
235
  };
@@ -392,7 +248,7 @@ const useIsomorphicLayoutEffect = typeof window === "undefined" ? react.useEffec
392
248
  const afterThisCommitsLayoutEffects = () => Promise.resolve();
393
249
  const createWalletActions = (store, walletId) => {
394
250
  let scope = new AbortController();
395
- const wallet = walletActions(store, walletId);
251
+ const wallet = store.walletActions(walletId);
396
252
  return {
397
253
  connect: async () => {
398
254
  if (scope.signal.aborted) await afterThisCommitsLayoutEffects();
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":["createContext","useContext","afterThisCommitsLayoutEffects","KheopskitError","useIsomorphicLayoutEffect","useEffect","useLayoutEffect","getHydratedSnapshot","createKheopskitStore","useMemo","resolveConfig","Observable","useMemo","useSyncExternalStore","useSyncExternalStore","defer","createKheopskitStore","resolveConfig","getKheopskit$","shareReplay","useCallback","useRef","useCallback","createKheopskitStore","getKheopskit$","useEffect","useLayoutEffect","KheopskitError","useMemo"],"sources":["../src/context.ts","../src/createExternalStore.ts","../src/liveActions.ts","../src/KheopskitSourceProvider.tsx","../src/livePipeline.ts","../src/useStateItem.ts","../src/useAccount.ts","../src/useWallet.ts","../src/useWallets.ts","../src/createKheopskit.tsx","../src/KheopskitProvider.tsx","../src/useAccounts.ts","../src/useConnect.ts"],"sourcesContent":["import type { KheopskitState } from \"@kheopskit/core\";\nimport { createContext, useContext } from \"react\";\nimport type { Liveness } from \"./livePipeline\";\n\nexport type KheopskitExternalStore = {\n\tsubscribe: (onChange: () => void) => () => void;\n\tgetSnapshot: () => KheopskitState;\n\tgetServerSnapshot: () => KheopskitState;\n\twhenLive: (signal?: AbortSignal) => Promise<Liveness<KheopskitState>>;\n};\n\nexport const KheopskitContext = createContext<KheopskitExternalStore | null>(\n\tnull,\n);\n\nexport const useKheopskitExternalStore = (hookName: string) => {\n\tconst store = useContext(KheopskitContext);\n\tif (!store)\n\t\tthrow new Error(`${hookName} can't be used without a KheopskitProvider`);\n\treturn store;\n};\n","import type { Subscription } from \"rxjs\";\nimport type { Liveness, LivePipeline } from \"./livePipeline\";\n\nexport type ExternalStoreSource<T> = {\n\tpipeline: LivePipeline<T>;\n\tinitialValue: T;\n};\n\n// React runs every layout setup of a commit synchronously, so once this\n// microtask runs a mounted provider has taken its hold on the pipeline, and a\n// release queued by a hide in this task has landed.\nconst afterThisCommitsLayoutEffects = () => Promise.resolve();\n\nexport const createExternalStore = <T>(\n\tresolveClientSource: () => ExternalStoreSource<T>,\n\tserverValue: T,\n) => {\n\tlet source: ExternalStoreSource<T> | undefined;\n\tlet latestValue: T | undefined;\n\tlet subscription: Subscription | undefined;\n\tconst listeners = new Set<(value: T) => void>();\n\n\tconst getSource = () => {\n\t\tsource ??= resolveClientSource();\n\t\treturn source;\n\t};\n\n\tconst getSnapshot = () => latestValue ?? getSource().initialValue;\n\n\tconst getServerSnapshot = () => serverValue;\n\n\tconst releaseWhenUnobserved = () => {\n\t\tif (listeners.size) return;\n\t\tsubscription?.unsubscribe();\n\t\tsubscription = undefined;\n\t};\n\n\tconst subscribe = (listener: (value: T) => void) => {\n\t\tif (!subscription || subscription.closed) {\n\t\t\tsubscription = getSource().pipeline.observable$.subscribe((value) => {\n\t\t\t\tlatestValue = value;\n\t\t\t\tfor (const notify of listeners) notify(value);\n\t\t\t});\n\t\t}\n\t\tlisteners.add(listener);\n\t\tlistener(getSnapshot());\n\n\t\treturn () => {\n\t\t\tlisteners.delete(listener);\n\t\t\t// StrictMode and a changed `subscribe` unsubscribe and resubscribe in\n\t\t\t// the same task; releasing at once would restart the pipeline between.\n\t\t\tqueueMicrotask(releaseWhenUnobserved);\n\t\t};\n\t};\n\n\t/** The shared pipeline's liveness once this commit's layout effects ran. */\n\tconst whenLive = async (signal?: AbortSignal): Promise<Liveness<T>> => {\n\t\tawait afterThisCommitsLayoutEffects();\n\t\treturn getSource().pipeline.whenLive(signal);\n\t};\n\n\treturn { getSnapshot, getServerSnapshot, subscribe, whenLive };\n};\n","import {\n\ttype ConnectOptions,\n\tKheopskitError,\n\ttype KheopskitState,\n\ttype WalletId,\n} from \"@kheopskit/core\";\nimport type { KheopskitExternalStore } from \"./context\";\nimport type { PipelineEnd } from \"./livePipeline\";\n\ntype Wallet = KheopskitState[\"wallets\"][number];\n\nconst didNotRun: Record<PipelineEnd, string> = {\n\taborted: \"was aborted\",\n\tunheld:\n\t\t\"was called while nothing holds the pipeline (no KheopskitProvider of this instance is mounted and visible, and nothing subscribes its kheopskit$)\",\n\terrored: \"did not run because the pipeline stopped with an error\",\n\tcompleted: \"did not run because the pipeline completed\",\n};\n\nconst abortedError = (\n\twalletId: WalletId,\n\toperation: \"connect\" | \"disconnect\",\n\tend: PipelineEnd,\n) =>\n\tnew KheopskitError(\n\t\t\"ABORTED\",\n\t\t`${operation} of wallet ${walletId} ${didNotRun[end]}`,\n\t\t{ walletId },\n\t);\n\n/**\n * `connect` and `disconnect` for one wallet id that act on the instance's\n * pipeline at call time: they wait for the restarted pipeline's first emission\n * after an `<Activity>` reveal and reject `ABORTED` while nothing holds it.\n */\nexport const walletActions = (\n\tstore: Pick<KheopskitExternalStore, \"whenLive\">,\n\twalletId: WalletId,\n) => {\n\tconst liveWallet = async (\n\t\toperation: \"connect\" | \"disconnect\",\n\t\tsignal?: AbortSignal,\n\t) => {\n\t\tconst liveness = await store.whenLive(signal);\n\t\tif (liveness.end) throw abortedError(walletId, operation, liveness.end);\n\t\tconst wallet = liveness.state.wallets.find(\n\t\t\t(candidate) => candidate.id === walletId,\n\t\t);\n\t\tif (!wallet) throw new Error(`[kheopskit] no wallet ${walletId}`);\n\t\treturn wallet;\n\t};\n\treturn {\n\t\tconnect: async (options?: ConnectOptions) =>\n\t\t\t(await liveWallet(\"connect\", options?.signal)).connect(options),\n\t\tdisconnect: async () => (await liveWallet(\"disconnect\")).disconnect(),\n\t};\n};\n\nexport const withLiveActions = (\n\tstore: KheopskitExternalStore,\n): KheopskitExternalStore => {\n\tconst presented = new WeakMap<KheopskitState, KheopskitState>();\n\tconst present = (state: KheopskitState) => {\n\t\tlet live = presented.get(state);\n\t\tif (!live) {\n\t\t\tlive = {\n\t\t\t\t...state,\n\t\t\t\twallets: state.wallets.map(\n\t\t\t\t\t(wallet): Wallet => ({\n\t\t\t\t\t\t...wallet,\n\t\t\t\t\t\t...walletActions(store, wallet.id),\n\t\t\t\t\t}),\n\t\t\t\t),\n\t\t\t};\n\t\t\tpresented.set(state, live);\n\t\t}\n\t\treturn live;\n\t};\n\treturn {\n\t\t...store,\n\t\tgetSnapshot: () => present(store.getSnapshot()),\n\t\tgetServerSnapshot: () => present(store.getServerSnapshot()),\n\t};\n};\n","import {\n\tcreateKheopskitStore,\n\tgetHydratedSnapshot,\n\ttype HydratedSnapshot,\n\ttype KheopskitConfig,\n\ttype KheopskitState,\n\ttype KheopskitStore,\n\tresolveConfig,\n} from \"@kheopskit/core\";\nimport {\n\ttype FC,\n\ttype PropsWithChildren,\n\tuseEffect,\n\tuseLayoutEffect,\n\tuseMemo,\n} from \"react\";\nimport { KheopskitContext } from \"./context\";\nimport { createExternalStore } from \"./createExternalStore\";\nimport { withLiveActions } from \"./liveActions\";\nimport type { LivePipeline } from \"./livePipeline\";\n\ntype KheopskitSource = {\n\tstore: KheopskitStore;\n\tpipeline: LivePipeline<KheopskitState>;\n};\n\ntype KheopskitSourceProviderProps = PropsWithChildren<{\n\tconfig: Partial<KheopskitConfig> | undefined;\n\tssrCookies: string | undefined;\n\tresolveClientSource: (config: KheopskitConfig) => KheopskitSource;\n}>;\n\nconst keepPipelineRunning = () => {};\n\n// A layout effect, so that a child's layout effect calling an action on reveal\n// finds the pipeline held again one microtask later (see createExternalStore).\nconst useIsomorphicLayoutEffect =\n\ttypeof window === \"undefined\" ? useEffect : useLayoutEffect;\n\nconst hydrating = (\n\tconfig: KheopskitConfig,\n\tsnapshot: HydratedSnapshot,\n): KheopskitState => ({\n\t...snapshot,\n\tconfig,\n\tisHydrating: true,\n\tisDiscovering: true,\n});\n\nconst serverSnapshot = (\n\tconfig: KheopskitConfig,\n\tssrCookies: string | undefined,\n): KheopskitState =>\n\thydrating(\n\t\tconfig,\n\t\tssrCookies === undefined\n\t\t\t? { wallets: [], accounts: [] }\n\t\t\t: getHydratedSnapshot(\n\t\t\t\t\tcreateKheopskitStore({ ssrCookies, storageKey: config.storageKey }),\n\t\t\t\t\tconfig,\n\t\t\t\t\t{ icons: false },\n\t\t\t\t),\n\t);\n\nexport const KheopskitSourceProvider: FC<KheopskitSourceProviderProps> = ({\n\tchildren,\n\tconfig,\n\tssrCookies,\n\tresolveClientSource,\n}) => {\n\tconst resolvedConfig = useMemo(() => resolveConfig(config), [config]);\n\n\tconst externalStore = useMemo(\n\t\t() =>\n\t\t\twithLiveActions(\n\t\t\t\tcreateExternalStore(\n\t\t\t\t\t() => {\n\t\t\t\t\t\tconst { store, pipeline } = resolveClientSource(resolvedConfig);\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\tpipeline,\n\t\t\t\t\t\t\tinitialValue: hydrating(\n\t\t\t\t\t\t\t\tresolvedConfig,\n\t\t\t\t\t\t\t\tgetHydratedSnapshot(store, resolvedConfig, { icons: true }),\n\t\t\t\t\t\t\t),\n\t\t\t\t\t\t};\n\t\t\t\t\t},\n\t\t\t\t\tserverSnapshot(resolvedConfig, ssrCookies),\n\t\t\t\t),\n\t\t\t),\n\t\t[resolvedConfig, ssrCookies, resolveClientSource],\n\t);\n\n\tuseIsomorphicLayoutEffect(\n\t\t() => externalStore.subscribe(keepPipelineRunning),\n\t\t[externalStore],\n\t);\n\n\treturn (\n\t\t<KheopskitContext.Provider value={externalStore}>\n\t\t\t{children}\n\t\t</KheopskitContext.Provider>\n\t);\n};\n","import { Observable } from \"rxjs\";\n\nexport type PipelineEnd = \"aborted\" | \"unheld\" | \"errored\" | \"completed\";\n\n/** The running pipeline's state, or why it cannot serve an action. */\nexport type Liveness<T> = { state: T; end?: undefined } | { end: PipelineEnd };\n\nexport type LivePipeline<T> = {\n\t/** Subscribing holds the pipeline; it runs while at least one holder stays. */\n\tobservable$: Observable<T>;\n\t/**\n\t * The current run's state: its latest value, or its first emission once it\n\t * arrives. Ends `unheld` while nothing holds the pipeline, without starting\n\t * it, `errored` or `completed` once the run ended that way, and `aborted`\n\t * when `signal` fires first.\n\t */\n\twhenLive: (signal?: AbortSignal) => Promise<Liveness<T>>;\n};\n\nexport const createLivePipeline = <T>(\n\tsource$: Observable<T>,\n): LivePipeline<T> => {\n\tlet holders = 0;\n\tlet run = 0;\n\tlet emittedRun = 0;\n\tlet latestValue: T | undefined;\n\tlet ended: PipelineEnd | undefined;\n\tconst firstEmissionWaiters = new Set<(liveness: Liveness<T>) => void>();\n\n\tconst settleFirstEmission = (liveness: Liveness<T>) => {\n\t\tfor (const waiter of firstEmissionWaiters) waiter(liveness);\n\t};\n\n\tconst observable$ = new Observable<T>((subscriber) => {\n\t\tif (holders++ === 0) {\n\t\t\trun++;\n\t\t\tended = undefined;\n\t\t}\n\t\tconst thisRun = run;\n\t\tconst subscription = source$.subscribe({\n\t\t\tnext: (value) => {\n\t\t\t\tlatestValue = value;\n\t\t\t\temittedRun = thisRun;\n\t\t\t\tsettleFirstEmission({ state: value });\n\t\t\t\tsubscriber.next(value);\n\t\t\t},\n\t\t\terror: (error) => {\n\t\t\t\tended = \"errored\";\n\t\t\t\tsubscriber.error(error);\n\t\t\t},\n\t\t\tcomplete: () => {\n\t\t\t\tended = \"completed\";\n\t\t\t\tsubscriber.complete();\n\t\t\t},\n\t\t});\n\t\treturn () => {\n\t\t\tsubscription.unsubscribe();\n\t\t\tif (--holders === 0) settleFirstEmission({ end: ended ?? \"unheld\" });\n\t\t};\n\t});\n\n\tconst whenLive = async (signal?: AbortSignal): Promise<Liveness<T>> => {\n\t\tif (signal?.aborted) return { end: \"aborted\" };\n\t\tif (ended) return { end: ended };\n\t\tif (holders === 0) return { end: \"unheld\" };\n\t\tif (emittedRun === run) return { state: latestValue as T };\n\t\treturn new Promise((resolve) => {\n\t\t\tconst settle = (liveness: Liveness<T>) => {\n\t\t\t\tfirstEmissionWaiters.delete(settle);\n\t\t\t\tsignal?.removeEventListener(\"abort\", onAbort);\n\t\t\t\tresolve(liveness);\n\t\t\t};\n\t\t\tconst onAbort = () => settle({ end: \"aborted\" });\n\t\t\tsignal?.addEventListener(\"abort\", onAbort, { once: true });\n\t\t\tfirstEmissionWaiters.add(settle);\n\t\t});\n\t};\n\n\treturn { observable$, whenLive };\n};\n","import type { KheopskitState } from \"@kheopskit/core\";\nimport { useMemo, useSyncExternalStore } from \"react\";\nimport { useKheopskitExternalStore } from \"./context\";\n\nconst isSameItemIgnoringClosures = (a: object, b: object) => {\n\tconst previous = a as Record<string, unknown>;\n\tconst next = b as Record<string, unknown>;\n\tconst keys = Object.keys(previous);\n\treturn (\n\t\tkeys.length === Object.keys(next).length &&\n\t\tkeys.every(\n\t\t\t(key) =>\n\t\t\t\tObject.hasOwn(next, key) &&\n\t\t\t\t(Object.is(previous[key], next[key]) ||\n\t\t\t\t\t(typeof previous[key] === \"function\" &&\n\t\t\t\t\t\ttypeof next[key] === \"function\")),\n\t\t)\n\t);\n};\n\nexport const useStateItem = <K, T extends object>(\n\thookName: string,\n\tkey: K,\n\tselect: (state: KheopskitState, key: K) => T | undefined,\n): T | undefined => {\n\tconst store = useKheopskitExternalStore(hookName);\n\tconst snapshots = useMemo(() => {\n\t\tlet cached: T | undefined;\n\t\treturn {\n\t\t\tgetSnapshot: () => {\n\t\t\t\tconst item = select(store.getSnapshot(), key);\n\t\t\t\tconst reusable =\n\t\t\t\t\tcached !== undefined &&\n\t\t\t\t\titem !== undefined &&\n\t\t\t\t\tisSameItemIgnoringClosures(cached, item);\n\t\t\t\tif (!reusable) cached = item;\n\t\t\t\treturn cached;\n\t\t\t},\n\t\t\tgetServerSnapshot: () => select(store.getServerSnapshot(), key),\n\t\t};\n\t}, [store, key, select]);\n\treturn useSyncExternalStore(\n\t\tstore.subscribe,\n\t\tsnapshots.getSnapshot,\n\t\tsnapshots.getServerSnapshot,\n\t);\n};\n","import type {\n\tKheopskitPlatform,\n\tKheopskitState,\n\tWalletAccountId,\n} from \"@kheopskit/core\";\nimport { useStateItem } from \"./useStateItem\";\n\nconst selectAccount = (state: KheopskitState, accountId: WalletAccountId) =>\n\tstate.accounts.find((account) => account.id === accountId);\n\n/**\n * Returns the account with this id, or `undefined` while the state lists none.\n * Re-renders only when that account changes: its name, its placeholder flag,\n * a platform field such as an Ethereum `chainId`, or an SDK handle.\n *\n * Pass the platform tuple as a type argument for the SDK-precise account type,\n * or use the pre-typed hook from {@link createKheopskit}.\n */\nexport const useAccount = <\n\tP extends readonly KheopskitPlatform[] = readonly KheopskitPlatform[],\n>(\n\taccountId: WalletAccountId,\n) =>\n\tuseStateItem(\"useAccount\", accountId, selectAccount) as\n\t\t| KheopskitState<P>[\"accounts\"][number]\n\t\t| undefined;\n","import type {\n\tKheopskitPlatform,\n\tKheopskitState,\n\tWalletId,\n} from \"@kheopskit/core\";\nimport { useStateItem } from \"./useStateItem\";\n\nconst selectWallet = (state: KheopskitState, walletId: WalletId) =>\n\tstate.wallets.find((wallet) => wallet.id === walletId);\n\n/**\n * Returns the wallet with this id, or `undefined` while the state lists none.\n * Re-renders only when that wallet changes: its status, connection, error,\n * name or any other field. Its `connect` and `disconnect` act on the instance's\n * pipeline when they are called, also right after an `<Activity>` reveal\n * restarts it and while another provider or a `kheopskit$` subscriber holds\n * it, and reject `ABORTED` while nothing holds it.\n *\n * Pass the platform tuple as a type argument for the SDK-precise wallet type,\n * or use the pre-typed hook from {@link createKheopskit}.\n */\nexport const useWallet = <\n\tP extends readonly KheopskitPlatform[] = readonly KheopskitPlatform[],\n>(\n\twalletId: WalletId,\n) =>\n\tuseStateItem(\"useWallet\", walletId, selectWallet) as\n\t\t| KheopskitState<P>[\"wallets\"][number]\n\t\t| undefined;\n","import type { KheopskitPlatform, KheopskitState } from \"@kheopskit/core\";\nimport { useSyncExternalStore } from \"react\";\nimport { useKheopskitExternalStore } from \"./context\";\n\n/**\n * Returns the current kheopskit state (wallets, accounts, config, isHydrating)\n * and re-renders on every change. To follow one wallet or account, prefer\n * {@link useWallet} or {@link useAccount}. Each wallet's `connect` and\n * `disconnect` act on the instance's pipeline when they are called, while\n * anything holds it.\n *\n * Pass the platform tuple as a type argument to recover SDK-precise account and\n * wallet types — `useWallets<typeof platforms>()`. React contexts can't be\n * generic, so without the argument the state is typed with the base\n * (SDK-free) wallet/account shapes.\n */\nexport const useWallets = <\n\tP extends readonly KheopskitPlatform[] = readonly KheopskitPlatform[],\n>(): KheopskitState<P> => {\n\tconst store = useKheopskitExternalStore(\"useWallets\");\n\treturn useSyncExternalStore(\n\t\tstore.subscribe,\n\t\tstore.getSnapshot,\n\t\tstore.getServerSnapshot,\n\t) as unknown as KheopskitState<P>;\n};\n","import {\n\tcreateKheopskitStore,\n\tgetKheopskit$,\n\ttype KheopskitConfig,\n\ttype KheopskitPlatform,\n\ttype KheopskitState,\n\ttype KheopskitStore,\n\tresolveConfig,\n\ttype WalletAccountId,\n\ttype WalletId,\n} from \"@kheopskit/core\";\nimport { type FC, type PropsWithChildren, useCallback } from \"react\";\nimport { defer, type Observable, shareReplay } from \"rxjs\";\nimport { KheopskitSourceProvider } from \"./KheopskitSourceProvider\";\nimport { createLivePipeline, type LivePipeline } from \"./livePipeline\";\nimport { useAccount } from \"./useAccount\";\nimport { useWallet } from \"./useWallet\";\nimport { useWallets } from \"./useWallets\";\n\nexport type CreateKheopskitConfig<P extends readonly KheopskitPlatform[]> =\n\tOmit<Partial<KheopskitConfig<P>>, \"platforms\"> & {\n\t\t/** Platform plugins, e.g. `[polkadot(), solana()]`. Required. */\n\t\tplatforms: P;\n\t};\n\nexport type CreateKheopskitOptions = {\n\t/**\n\t * Store the shared instance reads the cache from and persists into. Pass one\n\t * when code outside React reads `store` or subscribes `kheopskit$` before\n\t * the provider renders in an SSR app, and in tests.\n\t */\n\tstore?: KheopskitStore;\n};\n\nconst deferredStore = (claim: () => KheopskitStore): KheopskitStore => ({\n\tobservable: defer(() => claim().observable),\n\trememberWallet: (walletId) => claim().rememberWallet(walletId),\n\tforgetWallet: (walletId) => claim().forgetWallet(walletId),\n\tgetCachedState: () => claim().getCachedState(),\n\tsetCachedState: (wallets, accounts) =>\n\t\tclaim().setCachedState(wallets, accounts),\n\tdestroy: () => claim().destroy(),\n});\n\n/**\n * Binds a platform tuple once and returns one kheopskit instance: a\n * `KheopskitProvider`, hooks already typed to those platforms, and the\n * `kheopskit$` stream and `store` the provider uses, for code outside React.\n * Subscribing `kheopskit$` while the provider is mounted runs no second\n * pipeline, and holds the one pipeline for every hook action of the instance.\n *\n * Without `options.store`, the store is created on first use in the browser:\n * backed by cookies when the provider renders first with `ssrCookies`, by\n * localStorage otherwise. The caller owns `store.destroy()`.\n *\n * @example\n * ```tsx\n * // kheopskit.ts\n * export const { KheopskitProvider, useWallets, useWallet, kheopskit$ } =\n * createKheopskit({ platforms: [polkadot(), ethereum(), solana()] });\n *\n * // anywhere\n * const { accounts } = useWallets(); // accounts are platform-precise, no generic\n * ```\n */\nexport const createKheopskit = <\n\tconst P extends readonly [KheopskitPlatform, ...KheopskitPlatform[]],\n>(\n\tconfig: CreateKheopskitConfig<P>,\n\toptions: CreateKheopskitOptions = {},\n) => {\n\tlet claimed: KheopskitStore | undefined;\n\tconst claimStore = (ssrCookies?: string) => {\n\t\tclaimed ??=\n\t\t\toptions.store ??\n\t\t\tcreateKheopskitStore({\n\t\t\t\tssrCookies,\n\t\t\t\tstorageKey: resolveConfig(config).storageKey,\n\t\t\t});\n\t\treturn claimed;\n\t};\n\n\tconst shared$: Observable<KheopskitState<P>> = defer(() =>\n\t\tgetKheopskit$(config, { store: claimStore() }),\n\t).pipe(shareReplay({ refCount: true, bufferSize: 1 }));\n\tconst pipeline = createLivePipeline(shared$);\n\tconst kheopskit$ = pipeline.observable$;\n\n\tconst Provider: FC<PropsWithChildren<{ ssrCookies?: string }>> = ({\n\t\tchildren,\n\t\tssrCookies,\n\t}) => {\n\t\tif (typeof window !== \"undefined\") claimStore(ssrCookies);\n\t\tconst resolveClientSource = useCallback(\n\t\t\t() => ({\n\t\t\t\tstore: claimStore(ssrCookies),\n\t\t\t\tpipeline: pipeline as unknown as LivePipeline<KheopskitState>,\n\t\t\t}),\n\t\t\t[ssrCookies],\n\t\t);\n\t\treturn (\n\t\t\t<KheopskitSourceProvider\n\t\t\t\tconfig={config}\n\t\t\t\tssrCookies={ssrCookies}\n\t\t\t\tresolveClientSource={resolveClientSource}\n\t\t\t>\n\t\t\t\t{children}\n\t\t\t</KheopskitSourceProvider>\n\t\t);\n\t};\n\tProvider.displayName = \"KheopskitProvider\";\n\n\treturn {\n\t\tKheopskitProvider: Provider,\n\t\t/** The state stream the provider subscribes to, shared with code outside React. */\n\t\tkheopskit$,\n\t\t/** The store `kheopskit$` reads the cache from and persists into. */\n\t\tstore: options.store ?? deferredStore(claimStore),\n\t\t/** Current state, typed to the bound platform tuple. */\n\t\tuseWallets: () => useWallets<P>(),\n\t\t/** Current accounts, typed to the bound platform tuple. */\n\t\tuseAccounts: () => useWallets<P>().accounts,\n\t\t/** The wallet with this id, typed to the bound platform tuple. */\n\t\tuseWallet: (walletId: WalletId) => useWallet<P>(walletId),\n\t\t/** The account with this id, typed to the bound platform tuple. */\n\t\tuseAccount: (accountId: WalletAccountId) => useAccount<P>(accountId),\n\t};\n};\n","import {\n\tcreateKheopskitStore,\n\tgetKheopskit$,\n\ttype KheopskitConfig,\n\ttype KheopskitStore,\n} from \"@kheopskit/core\";\nimport {\n\ttype FC,\n\ttype PropsWithChildren,\n\tuseCallback,\n\tuseEffect,\n\tuseRef,\n} from \"react\";\nimport { KheopskitSourceProvider } from \"./KheopskitSourceProvider\";\nimport { createLivePipeline } from \"./livePipeline\";\n\nexport type KheopskitProviderProps = PropsWithChildren & {\n\t/**\n\t * Kheopskit configuration.\n\t *\n\t * @remarks\n\t * Must be a **referentially stable** value — define it once (module scope, a\n\t * `useMemo`, or via {@link createKheopskit}) and pass the same reference. A\n\t * new object literal on every render (`config={{ platforms: [...] }}` inline)\n\t * recreates the underlying store and re-subscribes each render.\n\t */\n\tconfig?: Partial<KheopskitConfig>;\n\t/**\n\t * Cookie string for SSR hydration.\n\t * Pass the request cookie header (e.g., from Next.js headers or TanStack Start)\n\t * to hydrate wallet state on the server.\n\t *\n\t * @remarks\n\t * This value should be stable per render to avoid unnecessary store recreation.\n\t * Compute it once in your server component or layout and pass it down.\n\t *\n\t * @example\n\t * ```tsx\n\t * // Next.js App Router\n\t * const cookieStore = await cookies();\n\t * const ssrCookies = cookieStore.getAll().map(c => `${c.name}=${c.value}`).join('; ');\n\t * return <Providers ssrCookies={ssrCookies}>{children}</Providers>\n\t * ```\n\t */\n\tssrCookies?: string;\n\t/**\n\t * Store the provider reads the cache from and persists into, on the client.\n\t * Defaults to a store per mount, backed by cookies when `ssrCookies` is set\n\t * and by localStorage otherwise. The server snapshot always comes from\n\t * `ssrCookies`.\n\t *\n\t * @example\n\t * ```tsx\n\t * // tests\n\t * const store = createKheopskitStore({ storage: createMemoryStorage() });\n\t * render(<KheopskitProvider config={config} store={store}>…</KheopskitProvider>);\n\t * ```\n\t */\n\tstore?: KheopskitStore;\n};\n\nexport const KheopskitProvider: FC<KheopskitProviderProps> = ({\n\tchildren,\n\tconfig,\n\tssrCookies,\n\tstore,\n}) => {\n\t// Dev-only: warn if the `config` prop reference changes between renders. A new\n\t// object each render recreates the store and re-subscribes the whole pipeline\n\t// (re-hydrating, dropping live connection state) on every render. `config` must\n\t// be referentially stable — define it at module scope, memoize it, or use\n\t// createKheopskit() (which passes a stable reference for you).\n\tconst lastConfigRef = useRef(config);\n\tconst hasMountedRef = useRef(false);\n\tuseEffect(() => {\n\t\tif (\n\t\t\thasMountedRef.current &&\n\t\t\tlastConfigRef.current !== config &&\n\t\t\t(typeof process === \"undefined\" || process.env?.NODE_ENV !== \"production\")\n\t\t) {\n\t\t\tconsole.warn(\n\t\t\t\t\"[kheopskit] KheopskitProvider received a new `config` reference; this \" +\n\t\t\t\t\t\"recreates the store and re-subscribes on every render. Pass a \" +\n\t\t\t\t\t\"referentially stable config (module scope, useMemo, or createKheopskit()).\",\n\t\t\t);\n\t\t}\n\t\thasMountedRef.current = true;\n\t\tlastConfigRef.current = config;\n\t}, [config]);\n\n\tconst resolveClientSource = useCallback(\n\t\t(resolvedConfig: KheopskitConfig) => {\n\t\t\tconst sourceStore =\n\t\t\t\tstore ??\n\t\t\t\tcreateKheopskitStore({\n\t\t\t\t\tssrCookies,\n\t\t\t\t\tstorageKey: resolvedConfig.storageKey,\n\t\t\t\t});\n\t\t\treturn {\n\t\t\t\tstore: sourceStore,\n\t\t\t\tpipeline: createLivePipeline(\n\t\t\t\t\tgetKheopskit$(resolvedConfig, { ssrCookies, store: sourceStore }),\n\t\t\t\t),\n\t\t\t};\n\t\t},\n\t\t[ssrCookies, store],\n\t);\n\n\treturn (\n\t\t<KheopskitSourceProvider\n\t\t\tconfig={config}\n\t\t\tssrCookies={ssrCookies}\n\t\t\tresolveClientSource={resolveClientSource}\n\t\t>\n\t\t\t{children}\n\t\t</KheopskitSourceProvider>\n\t);\n};\n","import type { KheopskitPlatform } from \"@kheopskit/core\";\nimport { useWallets } from \"./useWallets\";\n\n/**\n * Convenience hook returning just the accounts from kheopskit state. Pass the\n * platform tuple as a type argument to recover SDK-precise account types —\n * `useAccounts<typeof platforms>()` — or use the pre-typed hook from\n * {@link createKheopskit}.\n */\nexport const useAccounts = <\n\tP extends readonly KheopskitPlatform[] = readonly KheopskitPlatform[],\n>() => useWallets<P>().accounts;\n","import {\n\tKheopskitError,\n\ttype WalletId,\n\ttype WalletStatus,\n} from \"@kheopskit/core\";\nimport { useEffect, useLayoutEffect, useMemo } from \"react\";\nimport {\n\ttype KheopskitExternalStore,\n\tuseKheopskitExternalStore,\n} from \"./context\";\nimport { walletActions } from \"./liveActions\";\nimport { useWallet } from \"./useWallet\";\n\nexport type UseConnectResult = {\n\t/**\n\t * Connects the wallet through the pipeline that runs when it is called, and\n\t * waits for that pipeline's first emission when an `<Activity>` reveal has\n\t * just restarted it. Resolves once the state shows the wallet connected.\n\t * Unmounting the component or changing `walletId` aborts a pending connect,\n\t * which then resolves without connecting. A connect that starts after\n\t * unmount, or through a `connect` captured before `walletId` changed,\n\t * rejects `ABORTED` without asking the wallet. Rejects with the wallet's\n\t * `KheopskitError` otherwise, such as `USER_REJECTED`, and with an `Error`\n\t * when the state lists no wallet with this id.\n\t */\n\tconnect: () => Promise<void>;\n\t/**\n\t * Disconnects the wallet through the instance's pipeline, like a `useWallet`\n\t * wallet's `disconnect`, also after this component unmounted. Resolves once\n\t * the state shows it disconnected.\n\t */\n\tdisconnect: () => Promise<void>;\n\t/** `undefined` while the state lists no wallet with this id. */\n\tstatus: WalletStatus | undefined;\n\t/** The last connect the platform refused or failed. */\n\terror: KheopskitError | undefined;\n};\n\nconst useIsomorphicLayoutEffect =\n\ttypeof window === \"undefined\" ? useEffect : useLayoutEffect;\n\n// React runs every layout setup of a commit synchronously, so once this\n// microtask runs a mounted owner has renewed its scope.\nconst afterThisCommitsLayoutEffects = () => Promise.resolve();\n\nconst createWalletActions = (\n\tstore: KheopskitExternalStore,\n\twalletId: WalletId,\n) => {\n\tlet scope = new AbortController();\n\tconst wallet = walletActions(store, walletId);\n\n\treturn {\n\t\tconnect: async () => {\n\t\t\tif (scope.signal.aborted) await afterThisCommitsLayoutEffects();\n\t\t\tconst { signal } = scope;\n\t\t\tif (signal.aborted)\n\t\t\t\tthrow new KheopskitError(\n\t\t\t\t\t\"ABORTED\",\n\t\t\t\t\t`connect of wallet ${walletId} started after useConnect unmounted or switched wallet`,\n\t\t\t\t\t{ walletId },\n\t\t\t\t);\n\t\t\ttry {\n\t\t\t\tawait wallet.connect({ signal });\n\t\t\t} catch (error) {\n\t\t\t\tconst abortedByCleanup =\n\t\t\t\t\tsignal.aborted &&\n\t\t\t\t\terror instanceof KheopskitError &&\n\t\t\t\t\terror.code === \"ABORTED\";\n\t\t\t\tif (!abortedByCleanup) throw error;\n\t\t\t}\n\t\t},\n\t\tdisconnect: wallet.disconnect,\n\t\trenew: () => {\n\t\t\tif (scope.signal.aborted) scope = new AbortController();\n\t\t},\n\t\tabort: () => scope.abort(),\n\t};\n};\n\n/**\n * Connect and disconnect actions for one wallet, with its status and error.\n * `connect` and `disconnect` keep their identity while `walletId` is the same,\n * so `useEffect(() => { connect() }, [connect])` connects on mount and after\n * every `<Activity>` reveal.\n *\n * @example\n * ```tsx\n * const ConnectButton = ({ walletId }: { walletId: WalletId }) => {\n * const { connect, disconnect, status } = useConnect(walletId);\n * if (status === \"connected\") return <button onClick={disconnect}>Disconnect</button>;\n * return <button disabled={status === \"connecting\"} onClick={connect}>Connect</button>;\n * };\n * ```\n */\nexport const useConnect = (walletId: WalletId): UseConnectResult => {\n\tconst store = useKheopskitExternalStore(\"useConnect\");\n\tconst wallet = useWallet(walletId);\n\tconst actions = useMemo(\n\t\t() => createWalletActions(store, walletId),\n\t\t[store, walletId],\n\t);\n\n\tuseIsomorphicLayoutEffect(() => actions.renew(), [actions]);\n\tuseEffect(() => () => actions.abort(), [actions]);\n\n\treturn {\n\t\tconnect: actions.connect,\n\t\tdisconnect: actions.disconnect,\n\t\tstatus: wallet?.status,\n\t\terror: wallet?.error,\n\t};\n};\n"],"mappings":";;;;;;;AAWA,MAAa,oBAAA,GAAmBA,MAAAA,cAAAA,CAC/B,IACD;AAEA,MAAa,6BAA6B,aAAqB;CAC9D,MAAM,SAAA,GAAQC,MAAAA,WAAAA,CAAW,gBAAgB;CACzC,IAAI,CAAC,OACJ,MAAM,IAAI,MAAM,GAAG,SAAS,2CAA2C;CACxE,OAAO;AACR;;;ACTA,MAAMC,wCAAsC,QAAQ,QAAQ;AAE5D,MAAa,uBACZ,qBACA,gBACI;CACJ,IAAI;CACJ,IAAI;CACJ,IAAI;CACJ,MAAM,4BAAY,IAAI,IAAwB;CAE9C,MAAM,k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ydratedSnapshot","createKheopskitStore","useMemo","resolveConfig","kheopskitInternals","useMemo","useSyncExternalStore","useSyncExternalStore","createCoreKheopskit","useRef","useMemo","createKheopskit","useEffect","useLayoutEffect","KheopskitError","useMemo"],"sources":["../src/context.ts","../src/createExternalStore.ts","../src/KheopskitSourceProvider.tsx","../src/useStateItem.ts","../src/useAccount.ts","../src/useWallet.ts","../src/useWallets.ts","../src/createKheopskit.tsx","../src/KheopskitProvider.tsx","../src/useAccounts.ts","../src/useConnect.ts"],"sourcesContent":["import type { KheopskitState, WalletId } from \"@kheopskit/core\";\nimport type { WalletActions } from \"@kheopskit/core/internal\";\nimport { createContext, useContext } from \"react\";\n\nexport type KheopskitExternalStore = {\n\tsubscribe: (onChange: () => void) => () => void;\n\tgetSnapshot: () => KheopskitState;\n\tgetServerSnapshot: () => KheopskitState;\n\twalletActions: (walletId: WalletId) => WalletActions;\n};\n\nexport const KheopskitContext = createContext<KheopskitExternalStore | null>(\n\tnull,\n);\n\nexport const useKheopskitExternalStore = (hookName: string) => {\n\tconst store = useContext(KheopskitContext);\n\tif (!store)\n\t\tthrow new Error(`${hookName} can't be used without a KheopskitProvider`);\n\treturn store;\n};\n","import type { Observable, Subscription } from \"rxjs\";\n\nexport const createExternalStore = <T>(\n\tsource$: Observable<T>,\n\tgetInitialValue: () => T,\n\tserverValue: T,\n) => {\n\tlet initialValue: T | undefined;\n\tlet latestValue: T | undefined;\n\tlet subscription: Subscription | undefined;\n\tconst listeners = new Set<(value: T) => void>();\n\n\tconst getSnapshot = () => {\n\t\tinitialValue ??= getInitialValue();\n\t\treturn latestValue ?? initialValue;\n\t};\n\n\tconst getServerSnapshot = () => serverValue;\n\n\tconst releaseWhenUnobserved = () => {\n\t\tif (listeners.size) return;\n\t\tsubscription?.unsubscribe();\n\t\tsubscription = undefined;\n\t};\n\n\tconst subscribe = (listener: (value: T) => void) => {\n\t\tif (!subscription || subscription.closed) {\n\t\t\tsubscription = source$.subscribe((value) => {\n\t\t\t\tlatestValue = value;\n\t\t\t\tfor (const notify of listeners) notify(value);\n\t\t\t});\n\t\t}\n\t\tlisteners.add(listener);\n\t\tlistener(getSnapshot());\n\n\t\treturn () => {\n\t\t\tlisteners.delete(listener);\n\t\t\t// StrictMode and a changed `subscribe` unsubscribe and resubscribe in\n\t\t\t// the same task; releasing at once would restart the pipeline between.\n\t\t\tqueueMicrotask(releaseWhenUnobserved);\n\t\t};\n\t};\n\n\treturn { getSnapshot, getServerSnapshot, subscribe };\n};\n","import {\n\tcreateKheopskitStore,\n\tgetHydratedSnapshot,\n\ttype HydratedSnapshot,\n\ttype Kheopskit,\n\ttype KheopskitConfig,\n\ttype KheopskitPlatform,\n\ttype KheopskitState,\n\tresolveConfig,\n} from \"@kheopskit/core\";\nimport { kheopskitInternals } from \"@kheopskit/core/internal\";\nimport {\n\ttype FC,\n\ttype PropsWithChildren,\n\tuseEffect,\n\tuseLayoutEffect,\n\tuseMemo,\n} from \"react\";\nimport { KheopskitContext, type KheopskitExternalStore } from \"./context\";\nimport { createExternalStore } from \"./createExternalStore\";\n\ntype KheopskitSourceProviderProps = PropsWithChildren<{\n\tkit: Kheopskit<readonly KheopskitPlatform[]>;\n\tconfig: Partial<KheopskitConfig> | undefined;\n\tssrCookies: string | undefined;\n}>;\n\nconst keepPipelineRunning = () => {};\n\n// A layout effect, so that a child's layout effect calling an action on reveal\n// finds the pipeline held again one microtask later (see createExternalStore).\nconst useIsomorphicLayoutEffect =\n\ttypeof window === \"undefined\" ? useEffect : useLayoutEffect;\n\nconst hydrating = (\n\tconfig: KheopskitConfig,\n\tsnapshot: HydratedSnapshot,\n): KheopskitState => ({\n\t...snapshot,\n\tconfig,\n\tisHydrating: true,\n\tisDiscovering: true,\n});\n\nconst serverSnapshot = (\n\tconfig: KheopskitConfig,\n\tssrCookies: string | undefined,\n): KheopskitState =>\n\thydrating(\n\t\tconfig,\n\t\tssrCookies === undefined\n\t\t\t? { wallets: [], accounts: [] }\n\t\t\t: getHydratedSnapshot(\n\t\t\t\t\tcreateKheopskitStore({ ssrCookies, storageKey: config.storageKey }),\n\t\t\t\t\tconfig,\n\t\t\t\t\t{ icons: false },\n\t\t\t\t),\n\t);\n\nexport const KheopskitSourceProvider: FC<KheopskitSourceProviderProps> = ({\n\tchildren,\n\tkit,\n\tconfig,\n\tssrCookies,\n}) => {\n\tconst resolvedConfig = useMemo(() => resolveConfig(config), [config]);\n\n\tconst externalStore = useMemo((): KheopskitExternalStore => {\n\t\tconst { present, walletActions } = kheopskitInternals(kit);\n\t\treturn {\n\t\t\t...createExternalStore(\n\t\t\t\tkit.kheopskit$,\n\t\t\t\t() =>\n\t\t\t\t\tpresent(\n\t\t\t\t\t\thydrating(\n\t\t\t\t\t\t\tresolvedConfig,\n\t\t\t\t\t\t\tgetHydratedSnapshot(kit.store, resolvedConfig, { icons: true }),\n\t\t\t\t\t\t),\n\t\t\t\t\t),\n\t\t\t\tpresent(serverSnapshot(resolvedConfig, ssrCookies)),\n\t\t\t),\n\t\t\twalletActions,\n\t\t};\n\t}, [kit, resolvedConfig, ssrCookies]);\n\n\tuseIsomorphicLayoutEffect(\n\t\t() => externalStore.subscribe(keepPipelineRunning),\n\t\t[externalStore],\n\t);\n\n\treturn (\n\t\t<KheopskitContext.Provider value={externalStore}>\n\t\t\t{children}\n\t\t</KheopskitContext.Provider>\n\t);\n};\n","import type { KheopskitState } from \"@kheopskit/core\";\nimport { useMemo, useSyncExternalStore } from \"react\";\nimport { useKheopskitExternalStore } from \"./context\";\n\nconst isSameItemIgnoringClosures = (a: object, b: object) => {\n\tconst previous = a as Record<string, unknown>;\n\tconst next = b as Record<string, unknown>;\n\tconst keys = Object.keys(previous);\n\treturn (\n\t\tkeys.length === Object.keys(next).length &&\n\t\tkeys.every(\n\t\t\t(key) =>\n\t\t\t\tObject.hasOwn(next, key) &&\n\t\t\t\t(Object.is(previous[key], next[key]) ||\n\t\t\t\t\t(typeof previous[key] === \"function\" &&\n\t\t\t\t\t\ttypeof next[key] === \"function\")),\n\t\t)\n\t);\n};\n\nexport const useStateItem = <K, T extends object>(\n\thookName: string,\n\tkey: K,\n\tselect: (state: KheopskitState, key: K) => T | undefined,\n): T | undefined => {\n\tconst store = useKheopskitExternalStore(hookName);\n\tconst snapshots = useMemo(() => {\n\t\tlet cached: T | undefined;\n\t\treturn {\n\t\t\tgetSnapshot: () => {\n\t\t\t\tconst item = select(store.getSnapshot(), key);\n\t\t\t\tconst reusable =\n\t\t\t\t\tcached !== undefined &&\n\t\t\t\t\titem !== undefined &&\n\t\t\t\t\tisSameItemIgnoringClosures(cached, item);\n\t\t\t\tif (!reusable) cached = item;\n\t\t\t\treturn cached;\n\t\t\t},\n\t\t\tgetServerSnapshot: () => select(store.getServerSnapshot(), key),\n\t\t};\n\t}, [store, key, select]);\n\treturn useSyncExternalStore(\n\t\tstore.subscribe,\n\t\tsnapshots.getSnapshot,\n\t\tsnapshots.getServerSnapshot,\n\t);\n};\n","import type {\n\tKheopskitPlatform,\n\tKheopskitState,\n\tWalletAccountId,\n} from \"@kheopskit/core\";\nimport { useStateItem } from \"./useStateItem\";\n\nconst selectAccount = (state: KheopskitState, accountId: WalletAccountId) =>\n\tstate.accounts.find((account) => account.id === accountId);\n\n/**\n * Returns the account with this id, or `undefined` while the state lists none.\n * Re-renders only when that account changes: its name, its placeholder flag,\n * a platform field such as an Ethereum `chainId`, or an SDK handle.\n *\n * Pass the platform tuple as a type argument for the SDK-precise account type,\n * or use the pre-typed hook from {@link createKheopskit}.\n */\nexport const useAccount = <\n\tP extends readonly KheopskitPlatform[] = readonly KheopskitPlatform[],\n>(\n\taccountId: WalletAccountId,\n) =>\n\tuseStateItem(\"useAccount\", accountId, selectAccount) as\n\t\t| KheopskitState<P>[\"accounts\"][number]\n\t\t| undefined;\n","import type {\n\tKheopskitPlatform,\n\tKheopskitState,\n\tWalletId,\n} from \"@kheopskit/core\";\nimport { useStateItem } from \"./useStateItem\";\n\nconst selectWallet = (state: KheopskitState, walletId: WalletId) =>\n\tstate.wallets.find((wallet) => wallet.id === walletId);\n\n/**\n * Returns the wallet with this id, or `undefined` while the state lists none.\n * Re-renders only when that wallet changes: its status, connection, error,\n * name or any other field. Its `connect` and `disconnect` act on the instance's\n * pipeline when they are called, also right after an `<Activity>` reveal\n * restarts it and while another provider or a `kheopskit$` subscriber holds\n * it, and reject `ABORTED` while nothing holds it.\n *\n * Pass the platform tuple as a type argument for the SDK-precise wallet type,\n * or use the pre-typed hook from {@link createKheopskit}.\n */\nexport const useWallet = <\n\tP extends readonly KheopskitPlatform[] = readonly KheopskitPlatform[],\n>(\n\twalletId: WalletId,\n) =>\n\tuseStateItem(\"useWallet\", walletId, selectWallet) as\n\t\t| KheopskitState<P>[\"wallets\"][number]\n\t\t| undefined;\n","import type { KheopskitPlatform, KheopskitState } from \"@kheopskit/core\";\nimport { useSyncExternalStore } from \"react\";\nimport { useKheopskitExternalStore } from \"./context\";\n\n/**\n * Returns the current kheopskit state (wallets, accounts, config, isHydrating)\n * and re-renders on every change. To follow one wallet or account, prefer\n * {@link useWallet} or {@link useAccount}. Each wallet's `connect` and\n * `disconnect` act on the instance's pipeline when they are called, while\n * anything holds it.\n *\n * Pass the platform tuple as a type argument to recover SDK-precise account and\n * wallet types — `useWallets<typeof platforms>()`. React contexts can't be\n * generic, so without the argument the state is typed with the base\n * (SDK-free) wallet/account shapes.\n */\nexport const useWallets = <\n\tP extends readonly KheopskitPlatform[] = readonly KheopskitPlatform[],\n>(): KheopskitState<P> => {\n\tconst store = useKheopskitExternalStore(\"useWallets\");\n\treturn useSyncExternalStore(\n\t\tstore.subscribe,\n\t\tstore.getSnapshot,\n\t\tstore.getServerSnapshot,\n\t) as unknown as KheopskitState<P>;\n};\n","import {\n\ttype CreateKheopskitConfig,\n\ttype CreateKheopskitOptions,\n\tcreateKheopskit as createCoreKheopskit,\n\ttype KheopskitPlatform,\n\ttype WalletAccountId,\n\ttype WalletId,\n} from \"@kheopskit/core\";\nimport type { FC, PropsWithChildren } from \"react\";\nimport { KheopskitSourceProvider } from \"./KheopskitSourceProvider\";\nimport { useAccount } from \"./useAccount\";\nimport { useWallet } from \"./useWallet\";\nimport { useWallets } from \"./useWallets\";\n\nexport type {\n\tCreateKheopskitConfig,\n\tCreateKheopskitOptions,\n} from \"@kheopskit/core\";\n\ntype ProviderProps<O> = O extends { ssr: true }\n\t? { ssrCookies?: string }\n\t: { ssrCookies?: never };\n\n/**\n * Binds a platform tuple once and returns one kheopskit instance: a\n * `KheopskitProvider`, hooks already typed to those platforms, and the\n * `kheopskit$` stream and `store` the provider uses, and `waitForAccount`, for\n * code outside React.\n * It is `@kheopskit/core`'s `createKheopskit` instance: subscribing\n * `kheopskit$` while the provider is mounted runs no second pipeline, and\n * holds the one pipeline for every hook action of the instance.\n *\n * Without `options.store`, the store is created on first use, backed by\n * cookies with `{ ssr: true }` and by localStorage otherwise. Only an\n * instance created with `{ ssr: true }` accepts the provider's `ssrCookies`.\n * The caller owns `store.destroy()`.\n *\n * @example\n * ```tsx\n * // kheopskit.ts\n * export const { KheopskitProvider, useWallets, useWallet, kheopskit$ } =\n * createKheopskit({ platforms: [polkadot(), ethereum(), solana()] });\n *\n * // anywhere\n * const { accounts } = useWallets(); // accounts are platform-precise, no generic\n * ```\n */\nexport const createKheopskit = <\n\tconst P extends readonly [KheopskitPlatform, ...KheopskitPlatform[]],\n\tconst O extends CreateKheopskitOptions = CreateKheopskitOptions,\n>(\n\tconfig: CreateKheopskitConfig<P>,\n\toptions?: O,\n) => {\n\tconst kit = createCoreKheopskit(config, options);\n\n\tconst Provider: FC<PropsWithChildren<{ ssrCookies?: string }>> = ({\n\t\tchildren,\n\t\tssrCookies,\n\t}) => (\n\t\t<KheopskitSourceProvider kit={kit} config={config} ssrCookies={ssrCookies}>\n\t\t\t{children}\n\t\t</KheopskitSourceProvider>\n\t);\n\tProvider.displayName = \"KheopskitProvider\";\n\n\treturn {\n\t\tKheopskitProvider: Provider as FC<PropsWithChildren<ProviderProps<O>>>,\n\t\t/** The state stream the provider subscribes to, shared with code outside React. */\n\t\tkheopskit$: kit.kheopskit$,\n\t\t/** The store `kheopskit$` reads the cache from and persists into. */\n\t\tstore: kit.store,\n\t\t/** Resolves with the live account once the running instance lists it. */\n\t\twaitForAccount: kit.waitForAccount,\n\t\t/** Current state, typed to the bound platform tuple. */\n\t\tuseWallets: () => useWallets<P>(),\n\t\t/** Current accounts, typed to the bound platform tuple. */\n\t\tuseAccounts: () => useWallets<P>().accounts,\n\t\t/** The wallet with this id, typed to the bound platform tuple. */\n\t\tuseWallet: (walletId: WalletId) => useWallet<P>(walletId),\n\t\t/** The account with this id, typed to the bound platform tuple. */\n\t\tuseAccount: (accountId: WalletAccountId) => useAccount<P>(accountId),\n\t};\n};\n","import {\n\tcreateKheopskit,\n\ttype KheopskitConfig,\n\ttype KheopskitPlatform,\n\ttype KheopskitStore,\n} from \"@kheopskit/core\";\nimport {\n\ttype FC,\n\ttype PropsWithChildren,\n\tuseEffect,\n\tuseMemo,\n\tuseRef,\n} from \"react\";\nimport { KheopskitSourceProvider } from \"./KheopskitSourceProvider\";\n\nexport type KheopskitProviderProps = PropsWithChildren & {\n\t/**\n\t * Kheopskit configuration.\n\t *\n\t * @remarks\n\t * Must be a **referentially stable** value — define it once (module scope, a\n\t * `useMemo`, or via {@link createKheopskit}) and pass the same reference. A\n\t * new object literal on every render (`config={{ platforms: [...] }}` inline)\n\t * recreates the underlying store and re-subscribes each render.\n\t */\n\tconfig?: Partial<KheopskitConfig>;\n\t/**\n\t * The kheopskit cookie, for SSR hydration. Pass only the cookie named after\n\t * `storageKey` (default `kheopskit`), or `\"\"` when it is absent. Never pass\n\t * the whole cookie header: props of a client component are serialized into\n\t * the HTML, httpOnly session cookies included.\n\t *\n\t * @remarks\n\t * This value should be stable per render to avoid unnecessary store recreation.\n\t * Compute it once in your server component or layout and pass it down.\n\t *\n\t * @example\n\t * ```tsx\n\t * // Next.js App Router\n\t * const kheopskitCookie = (await cookies()).get(\"kheopskit\");\n\t * const ssrCookies = kheopskitCookie\n\t * ? `kheopskit=${encodeURIComponent(kheopskitCookie.value)}`\n\t * : \"\";\n\t * return <Providers ssrCookies={ssrCookies}>{children}</Providers>\n\t * ```\n\t */\n\tssrCookies?: string;\n\t/**\n\t * Store the provider reads the cache from and persists into, on the client.\n\t * Defaults to a store per mount, backed by cookies when `ssrCookies` is set\n\t * and by localStorage otherwise. The server snapshot always comes from\n\t * `ssrCookies`.\n\t *\n\t * @example\n\t * ```tsx\n\t * // tests\n\t * const store = createKheopskitStore({ storage: createMemoryStorage() });\n\t * render(<KheopskitProvider config={config} store={store}>…</KheopskitProvider>);\n\t * ```\n\t */\n\tstore?: KheopskitStore;\n};\n\nexport const KheopskitProvider: FC<KheopskitProviderProps> = ({\n\tchildren,\n\tconfig,\n\tssrCookies,\n\tstore,\n}) => {\n\t// Dev-only: warn if the `config` prop reference changes between renders. A new\n\t// object each render recreates the store and re-subscribes the whole pipeline\n\t// (re-hydrating, dropping live connection state) on every render. `config` must\n\t// be referentially stable — define it at module scope, memoize it, or use\n\t// createKheopskit() (which passes a stable reference for you).\n\tconst lastConfigRef = useRef(config);\n\tconst hasMountedRef = useRef(false);\n\tuseEffect(() => {\n\t\tif (\n\t\t\thasMountedRef.current &&\n\t\t\tlastConfigRef.current !== config &&\n\t\t\t(typeof process === \"undefined\" || process.env?.NODE_ENV !== \"production\")\n\t\t) {\n\t\t\tconsole.warn(\n\t\t\t\t\"[kheopskit] KheopskitProvider received a new `config` reference; this \" +\n\t\t\t\t\t\"recreates the store and re-subscribes on every render. Pass a \" +\n\t\t\t\t\t\"referentially stable config (module scope, useMemo, or createKheopskit()).\",\n\t\t\t);\n\t\t}\n\t\thasMountedRef.current = true;\n\t\tlastConfigRef.current = config;\n\t}, [config]);\n\n\tconst ssr = ssrCookies !== undefined;\n\tconst kit = useMemo(\n\t\t() =>\n\t\t\tcreateKheopskit(\n\t\t\t\t{\n\t\t\t\t\t...config,\n\t\t\t\t\tplatforms: (config?.platforms ?? []) as readonly [KheopskitPlatform],\n\t\t\t\t},\n\t\t\t\tstore ? { store } : { ssr },\n\t\t\t),\n\t\t[config, store, ssr],\n\t);\n\n\treturn (\n\t\t<KheopskitSourceProvider kit={kit} config={config} ssrCookies={ssrCookies}>\n\t\t\t{children}\n\t\t</KheopskitSourceProvider>\n\t);\n};\n","import type { KheopskitPlatform } from \"@kheopskit/core\";\nimport { useWallets } from \"./useWallets\";\n\n/**\n * Convenience hook returning just the accounts from kheopskit state. Pass the\n * platform tuple as a type argument to recover SDK-precise account types —\n * `useAccounts<typeof platforms>()` — or use the pre-typed hook from\n * {@link createKheopskit}.\n */\nexport const useAccounts = <\n\tP extends readonly KheopskitPlatform[] = readonly KheopskitPlatform[],\n>() => useWallets<P>().accounts;\n","import {\n\tKheopskitError,\n\ttype WalletId,\n\ttype WalletStatus,\n} from \"@kheopskit/core\";\nimport { useEffect, useLayoutEffect, useMemo } from \"react\";\nimport {\n\ttype KheopskitExternalStore,\n\tuseKheopskitExternalStore,\n} from \"./context\";\nimport { useWallet } from \"./useWallet\";\n\nexport type UseConnectResult = {\n\t/**\n\t * Connects the wallet through the pipeline that runs when it is called, and\n\t * waits for that pipeline's first emission when an `<Activity>` reveal has\n\t * just restarted it. Resolves once the state shows the wallet connected.\n\t * Unmounting the component or changing `walletId` aborts a pending connect,\n\t * which then resolves without connecting. A connect that starts after\n\t * unmount, or through a `connect` captured before `walletId` changed,\n\t * rejects `ABORTED` without asking the wallet. Rejects with the wallet's\n\t * `KheopskitError` otherwise, such as `USER_REJECTED`, and with an `Error`\n\t * when the state lists no wallet with this id.\n\t */\n\tconnect: () => Promise<void>;\n\t/**\n\t * Disconnects the wallet through the instance's pipeline, like a `useWallet`\n\t * wallet's `disconnect`, also after this component unmounted. Resolves once\n\t * the state shows it disconnected.\n\t */\n\tdisconnect: () => Promise<void>;\n\t/** `undefined` while the state lists no wallet with this id. */\n\tstatus: WalletStatus | undefined;\n\t/** The last connect the platform refused or failed. */\n\terror: KheopskitError | undefined;\n};\n\nconst useIsomorphicLayoutEffect =\n\ttypeof window === \"undefined\" ? useEffect : useLayoutEffect;\n\n// React runs every layout setup of a commit synchronously, so once this\n// microtask runs a mounted owner has renewed its scope.\nconst afterThisCommitsLayoutEffects = () => Promise.resolve();\n\nconst createWalletActions = (\n\tstore: KheopskitExternalStore,\n\twalletId: WalletId,\n) => {\n\tlet scope = new AbortController();\n\tconst wallet = store.walletActions(walletId);\n\n\treturn {\n\t\tconnect: async () => {\n\t\t\tif (scope.signal.aborted) await afterThisCommitsLayoutEffects();\n\t\t\tconst { signal } = scope;\n\t\t\tif (signal.aborted)\n\t\t\t\tthrow new KheopskitError(\n\t\t\t\t\t\"ABORTED\",\n\t\t\t\t\t`connect of wallet ${walletId} started after useConnect unmounted or switched wallet`,\n\t\t\t\t\t{ walletId },\n\t\t\t\t);\n\t\t\ttry {\n\t\t\t\tawait wallet.connect({ signal });\n\t\t\t} catch (error) {\n\t\t\t\tconst abortedByCleanup =\n\t\t\t\t\tsignal.aborted &&\n\t\t\t\t\terror instanceof KheopskitError &&\n\t\t\t\t\terror.code === \"ABORTED\";\n\t\t\t\tif (!abortedByCleanup) throw error;\n\t\t\t}\n\t\t},\n\t\tdisconnect: wallet.disconnect,\n\t\trenew: () => {\n\t\t\tif (scope.signal.aborted) scope = new AbortController();\n\t\t},\n\t\tabort: () => scope.abort(),\n\t};\n};\n\n/**\n * Connect and disconnect actions for one wallet, with its status and error.\n * `connect` and `disconnect` keep their identity while `walletId` is the same,\n * so `useEffect(() => { connect() }, [connect])` connects on mount and after\n * every `<Activity>` reveal.\n *\n * @example\n * ```tsx\n * const ConnectButton = ({ walletId }: { walletId: WalletId }) => {\n * const { connect, disconnect, status } = useConnect(walletId);\n * if (status === \"connected\") return <button onClick={disconnect}>Disconnect</button>;\n * return <button disabled={status === \"connecting\"} onClick={connect}>Connect</button>;\n * };\n * ```\n */\nexport const useConnect = (walletId: WalletId): UseConnectResult => {\n\tconst store = useKheopskitExternalStore(\"useConnect\");\n\tconst wallet = useWallet(walletId);\n\tconst actions = useMemo(\n\t\t() => createWalletActions(store, walletId),\n\t\t[store, walletId],\n\t);\n\n\tuseIsomorphicLayoutEffect(() => actions.renew(), [actions]);\n\tuseEffect(() => () => actions.abort(), [actions]);\n\n\treturn {\n\t\tconnect: actions.connect,\n\t\tdisconnect: actions.disconnect,\n\t\tstatus: wallet?.status,\n\t\terror: wallet?.error,\n\t};\n};\n"],"mappings":";;;;;;;AAWA,MAAa,oBAAA,GAAmBA,MAAAA,cAAAA,CAC/B,IACD;AAEA,MAAa,6BAA6B,aAAqB;CAC9D,MAAM,SAAA,GAAQC,MAAAA,WAAAA,CAAW,gBAAgB;CACzC,IAAI,CAAC,OACJ,MAAM,IAAI,MAAM,GAAG,SAAS,2CAA2C;CACxE,OAAO;AACR;;;AClBA,MAAa,uBACZ,SACA,iBACA,gBACI;CACJ,IAAI;CACJ,IAAI;CACJ,IAAI;CACJ,MAAM,4BAAY,IAAI,IAAwB;CAE9C,MAAM,oBAAoB;EACzB,iBAAA,eAAiB,gBAAgB;EACjC,OAAO,eAAe;CACvB;CAEA,MAAM,0BAA0B;CAEhC,MAAM,8BAA8B;EACnC,IAAI,UAAU,MAAM;EACpB,cAAc,YAAY;EAC1B,eAAe,KAAA;CAChB;CAEA,MAAM,aAAa,aAAiC;EACnD,IAAI,CAAC,gBAAgB,aAAa,QACjC,eAAe,QAAQ,WAAW,UAAU;GAC3C,cAAc;GACd,KAAK,MAAM,UAAU,WAAW,OAAO,KAAK;EAC7C,CAAC;EAEF,UAAU,IAAI,QAAQ;EACtB,SAAS,YAAY,CAAC;EAEtB,aAAa;GACZ,UAAU,OAAO,QAAQ;GAGzB,eAAe,qBAAqB;EACrC;CACD;CAEA,OAAO;EAAE;EAAa;EAAmB;CAAU;AACpD;;;ACjBA,MAAM,4BAA4B,CAAC;AAInC,MAAMC,8BACL,OAAO,WAAW,cAAcC,MAAAA,YAAYC,MAAAA;AAE7C,MAAM,aACL,QACA,cACqB;CACrB,GAAG;CACH;C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