@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/CHANGELOG.md CHANGED
@@ -1,5 +1,29 @@
1
1
  # @kheopskit/react
2
2
 
3
+ ## 6.0.0-rc.4
4
+
5
+ ### Minor Changes
6
+
7
+ - [#166](https://github.com/kheopskit/kheopskit/pull/166) [`3c2bad1`](https://github.com/kheopskit/kheopskit/commit/3c2bad12e121cede1e95d93d7967d7bb96192180) Thanks [@0xKheops](https://github.com/0xKheops)! - Breaking: `getKheopskit$` and its `GetKheopskitOptions` type are removed from `@kheopskit/core`; create one instance with `createKheopskit(config, options)` and subscribe its `kheopskit$` once at app start. A `@kheopskit/react` provider that receives `ssrCookies` needs an instance created with `createKheopskit(config, { ssr: true })`; without it, `ssrCookies` is a type error. On the server, a store that `createKheopskit` creates ignores `rememberWallet`, `forgetWallet` and `setCachedState`, so module code shared by every request cannot change it.
8
+
9
+ Added: `createKheopskit` in `@kheopskit/core` returns `kheopskit$` and `store`. Every subscriber of `kheopskit$` shares one pipeline, which runs while something subscribes, and a wallet's `connect()` and `disconnect()` act on the pipeline running when they are called. `@kheopskit/react`'s `createKheopskit` is built on it. `@kheopskit/core/internal` gains the instance plumbing that `@kheopskit/react` uses; it is not public API.
10
+
11
+ - [#167](https://github.com/kheopskit/kheopskit/pull/167) [`4817131`](https://github.com/kheopskit/kheopskit/commit/4817131306f04ec74d81f95e8727a24c37f1acdb) Thanks [@0xKheops](https://github.com/0xKheops)! - Added: `createKheopskit` returns `waitForAccount(accountId, { signal })`, which resolves with the live account once the running instance lists it, rejects `ACCOUNT_UNAVAILABLE` when the account's wallet settled listing other accounts but not this one or is not connected (a connected wallet that lists no accounts keeps the wait open until `signal` fires), and rejects `ABORTED` like a wallet's `connect()`. `@kheopskit/react`'s `createKheopskit` returns it too.
12
+
13
+ - [#162](https://github.com/kheopskit/kheopskit/pull/162) [`da040e1`](https://github.com/kheopskit/kheopskit/commit/da040e1f1e8e84a21e7abd4481111ff077c0efdb) Thanks [@0xKheops](https://github.com/0xKheops)! - Added: `walletConnect({ appKitOptions })` forwards any other Reown `createAppKit` option to AppKit, such as `featuredWalletIds`, `features` or `allWallets`. The keys kheopskit sets (`projectId`, `metadata`, `networks`, `themeMode`, `themeVariables`, `universalProviderConfigOverride`) are rejected by the type and keep their kheopskit values.
14
+
15
+ ### Patch Changes
16
+
17
+ - [#164](https://github.com/kheopskit/kheopskit/pull/164) [`0e03c4b`](https://github.com/kheopskit/kheopskit/commit/0e03c4bdc7aafa1d2c5649b3673e41da44d3052e) Thanks [@0xKheops](https://github.com/0xKheops)! - Docs: SSR examples and snippets forward only the `kheopskit` cookie as `ssrCookies`, never the whole cookie header. The core README adds a "Knowing when wallets have settled" recipe and states what the cookie and `localStorage` hold.
18
+
19
+ - [#163](https://github.com/kheopskit/kheopskit/pull/163) [`1cc653d`](https://github.com/kheopskit/kheopskit/commit/1cc653d954f02b670f05639fd83b34da29ded5d6) Thanks [@0xKheops](https://github.com/0xKheops)! - Fixed: wallets and accounts cached for a platform missing from `platforms` no longer show on the first frame, in the SSR markup or as hydration placeholders. The cached WalletConnect row and its accounts likewise need `walletConnect` in the config, and a WalletConnect account needs its platform in `platforms`. Remembered wallets of a removed platform are not reconnected and stay remembered, so adding the platform back restores their reconnect.
20
+
21
+ ## 6.0.0-rc.3
22
+
23
+ ### Patch Changes
24
+
25
+ - [#160](https://github.com/kheopskit/kheopskit/pull/160) [`4e55488`](https://github.com/kheopskit/kheopskit/commit/4e5548833b782669f00e33452f5ed4dff9ddcac0) Thanks [@0xKheops](https://github.com/0xKheops)! - Fixed: a remembered wallet forgotten before it injects is no longer reconnected when it does. A placeholder's `disconnect()` now forgets the wallet, or calls the live wallet's `disconnect()` once that one is discovered. `store.forgetWallet(walletId)` during the session cancels the automatic reconnect for good, even if the wallet is remembered again. `disconnect()` now forgets the wallet whatever its status, including while its automatic reconnect waits for the extension or after that reconnect failed, so the next load does not reconnect it. A wallet the user disconnects during hydration no longer holds `isHydrating` until `hydrationTimeout`.
26
+
3
27
  ## 6.0.0-rc.2
4
28
 
5
29
  ### Minor Changes
package/README.md CHANGED
@@ -194,10 +194,13 @@ same for every platform.
194
194
 
195
195
  ## One instance for React and RxJS code
196
196
 
197
- `createKheopskit` also returns `kheopskit$`, the state stream its provider
198
- subscribes to, and `store`, the store that stream persists into. Code outside
199
- React, such as an RxJS pipeline or a sign-in flow, subscribes to the same
200
- `kheopskit$`. While the provider is mounted, both share one pipeline: one wallet
197
+ `createKheopskit` is
198
+ [`@kheopskit/core`'s `createKheopskit`](../core/README.md#usage) plus the
199
+ provider and the typed hooks. It also returns `kheopskit$`, the state stream
200
+ its provider subscribes to, and `store`, the store that stream persists into.
201
+ It returns core's [`waitForAccount`](../core/README.md#usage) too.
202
+ Code outside React, such as an RxJS pipeline or a sign-in flow, subscribes to
203
+ the same `kheopskit$`. While the provider is mounted, both share one pipeline: one wallet
201
204
  discovery, one reconnect attempt and one extension prompt.
202
205
 
203
206
  ```ts
@@ -226,42 +229,52 @@ on the server. It renders each server request from that request's
226
229
  it there. It emits one state without wallets, persists nothing, leaves no timer
227
230
  behind and does not change what the provider renders for a request.
228
231
 
229
- Without `options.store`, `createKheopskit` creates the store on first use in
230
- the browser. The provider claims it when it first renders there. The store is
231
- backed by cookies when the provider renders with `ssrCookies`, and by
232
- localStorage otherwise. Effects of components inside the provider run after
233
- that render, so they use the provider's store. In an SSR app, code that reads
234
- `store` or subscribes to `kheopskit$` before the provider renders, such as
235
- module-scope code or a parent's effect that runs before the provider mounts,
236
- would get the localStorage store. Pass the store in that case:
237
-
238
- ```ts
239
- import { createKheopskitStore } from "@kheopskit/core";
240
-
241
- export const { KheopskitProvider, kheopskit$, store } = createKheopskit(config, {
242
- store: createKheopskitStore({ ssrCookies: "" }),
243
- });
244
- ```
232
+ Without `options.store`, `createKheopskit` creates the store on first use.
233
+ It is backed by cookies with `{ ssr: true }` (see [SSR](#ssr)) and by
234
+ localStorage otherwise, whoever touches it first, the provider or code outside
235
+ React. On the server, that store ignores `rememberWallet`, `forgetWallet` and
236
+ `setCachedState`, so module code shared by every request cannot change it.
245
237
 
246
238
  `createKheopskit` never calls `store.destroy()`, so the store survives a
247
239
  provider remount. Call it yourself when the app no longer needs kheopskit.
248
240
 
249
241
  ## SSR
250
242
 
251
- Pass the request cookie header as `ssrCookies` to hydrate wallet state on the
252
- server without a UI flash:
243
+ Create the instance with `{ ssr: true }`, so it persists in a cookie the server
244
+ can read:
245
+
246
+ ```ts
247
+ // kheopskit.ts
248
+ export const { KheopskitProvider, useWallets } = createKheopskit(
249
+ { platforms: [polkadot()] },
250
+ { ssr: true },
251
+ );
252
+ ```
253
+
254
+ Then pass the `kheopskit` cookie as `ssrCookies` to hydrate wallet state on the
255
+ server without a UI flash. Never forward the whole cookie header to a client
256
+ component: the framework serializes its props into the HTML, httpOnly session
257
+ cookies included.
253
258
 
254
259
  ```tsx
255
260
  // Next.js App Router
256
- const cookieStore = await cookies();
257
- const ssrCookies = cookieStore
258
- .getAll()
259
- .map((c) => `${c.name}=${c.value}`)
260
- .join("; ");
261
+ const kheopskitCookie = (await cookies()).get("kheopskit");
262
+ const ssrCookies = kheopskitCookie
263
+ ? `kheopskit=${encodeURIComponent(kheopskitCookie.value)}`
264
+ : "";
261
265
 
262
266
  <KheopskitProvider ssrCookies={ssrCookies}>{children}</KheopskitProvider>;
263
267
  ```
264
268
 
269
+ Kheopskit reads one cookie, named after the `storageKey` config option
270
+ (default `kheopskit`). Pass `""` when it is absent. The
271
+ [TanStack Start example](https://github.com/kheopskit/kheopskit/blob/main/examples/tanstack-start/src/routes/__root.tsx)
272
+ reads it with `getCookie("kheopskit")` in a server function.
273
+
274
+ `ssrCookies` on the provider of an instance created without `{ ssr: true }` is
275
+ a type error. The standalone `KheopskitProvider` persists to the cookie only
276
+ when it receives `ssrCookies`, so pass `""` rather than leaving the prop out.
277
+
265
278
  > While `state.isHydrating` is `true`, wallets and accounts restored from the
266
279
  > cache are placeholders with `isPlaceholder: true` and no SDK handle
267
280
  > (`txCreator`, `signer`, `client`, `provider`, `extension`). Narrow on
package/dist/index.d.mts CHANGED
@@ -1,29 +1,26 @@
1
- import { KheopskitConfig, KheopskitError, KheopskitPlatform, KheopskitState, KheopskitStore, WalletAccountId, WalletId, WalletStatus } from "@kheopskit/core";
1
+ import { CreateKheopskitConfig, CreateKheopskitConfig as CreateKheopskitConfig$1, CreateKheopskitOptions, CreateKheopskitOptions as CreateKheopskitOptions$1, KheopskitConfig, KheopskitError, KheopskitPlatform, KheopskitState, KheopskitStore, WalletAccountId, WalletId, WalletStatus } from "@kheopskit/core";
2
2
  import { FC, PropsWithChildren } from "react";
3
- import { Observable } from "rxjs";
4
3
  //#region src/createKheopskit.d.ts
5
- export type CreateKheopskitConfig<P extends readonly KheopskitPlatform[]> = Omit<Partial<KheopskitConfig<P>>, "platforms"> & {
6
- /** Platform plugins, e.g. `[polkadot(), solana()]`. Required. */
7
- platforms: P;
8
- };
9
- export type CreateKheopskitOptions = {
10
- /**
11
- * Store the shared instance reads the cache from and persists into. Pass one
12
- * when code outside React reads `store` or subscribes `kheopskit$` before
13
- * the provider renders in an SSR app, and in tests.
14
- */
15
- store?: KheopskitStore;
4
+ type ProviderProps<O> = O extends {
5
+ ssr: true;
6
+ } ? {
7
+ ssrCookies?: string;
8
+ } : {
9
+ ssrCookies?: never;
16
10
  };
17
11
  /**
18
12
  * Binds a platform tuple once and returns one kheopskit instance: a
19
13
  * `KheopskitProvider`, hooks already typed to those platforms, and the
20
- * `kheopskit$` stream and `store` the provider uses, for code outside React.
21
- * Subscribing `kheopskit$` while the provider is mounted runs no second
22
- * pipeline, and holds the one pipeline for every hook action of the instance.
14
+ * `kheopskit$` stream and `store` the provider uses, and `waitForAccount`, for
15
+ * code outside React.
16
+ * It is `@kheopskit/core`'s `createKheopskit` instance: subscribing
17
+ * `kheopskit$` while the provider is mounted runs no second pipeline, and
18
+ * holds the one pipeline for every hook action of the instance.
23
19
  *
24
- * Without `options.store`, the store is created on first use in the browser:
25
- * backed by cookies when the provider renders first with `ssrCookies`, by
26
- * localStorage otherwise. The caller owns `store.destroy()`.
20
+ * Without `options.store`, the store is created on first use, backed by
21
+ * cookies with `{ ssr: true }` and by localStorage otherwise. Only an
22
+ * instance created with `{ ssr: true }` accepts the provider's `ssrCookies`.
23
+ * The caller owns `store.destroy()`.
27
24
  *
28
25
  * @example
29
26
  * ```tsx
@@ -35,16 +32,20 @@ export type CreateKheopskitOptions = {
35
32
  * const { accounts } = useWallets(); // accounts are platform-precise, no generic
36
33
  * ```
37
34
  */
38
- export declare const createKheopskit: <const P extends readonly [KheopskitPlatform, ...KheopskitPlatform[]]>(config: CreateKheopskitConfig<P>, options?: CreateKheopskitOptions) => {
39
- KheopskitProvider: FC<PropsWithChildren<{
40
- ssrCookies?: string;
41
- }>>;
35
+ export declare const createKheopskit: <const P extends readonly [KheopskitPlatform, ...KheopskitPlatform[]], const O extends CreateKheopskitOptions$1 = CreateKheopskitOptions$1>(config: CreateKheopskitConfig$1<P>, options?: O) => {
36
+ KheopskitProvider: FC<PropsWithChildren<ProviderProps<O>>>;
42
37
  /** The state stream the provider subscribes to, shared with code outside React. */
43
- kheopskit$: Observable<KheopskitState<P>>;
38
+ kheopskit$: import("rxjs").Observable<import("@kheopskit/core").KheopskitState<P>>;
44
39
  /** The store `kheopskit$` reads the cache from and persists into. */
45
- store: KheopskitStore;
40
+ store: import("@kheopskit/core").KheopskitStore;
41
+ /** Resolves with the live account once the running instance lists it. */
42
+ waitForAccount: (accountId: WalletAccountId, options?: {
43
+ signal?: AbortSignal;
44
+ }) => Promise<Exclude<import("@kheopskit/core").AccountOf<P[number]>, {
45
+ isPlaceholder: true;
46
+ }>>;
46
47
  /** Current state, typed to the bound platform tuple. */
47
- useWallets: () => KheopskitState<P>;
48
+ useWallets: () => import("@kheopskit/core").KheopskitState<P>;
48
49
  /** Current accounts, typed to the bound platform tuple. */
49
50
  useAccounts: () => import("@kheopskit/core").AccountOf<P[number]>[];
50
51
  /** The wallet with this id, typed to the bound platform tuple. */
@@ -66,9 +67,10 @@ export type KheopskitProviderProps = PropsWithChildren & {
66
67
  */
67
68
  config?: Partial<KheopskitConfig>;
68
69
  /**
69
- * Cookie string for SSR hydration.
70
- * Pass the request cookie header (e.g., from Next.js headers or TanStack Start)
71
- * to hydrate wallet state on the server.
70
+ * The kheopskit cookie, for SSR hydration. Pass only the cookie named after
71
+ * `storageKey` (default `kheopskit`), or `""` when it is absent. Never pass
72
+ * the whole cookie header: props of a client component are serialized into
73
+ * the HTML, httpOnly session cookies included.
72
74
  *
73
75
  * @remarks
74
76
  * This value should be stable per render to avoid unnecessary store recreation.
@@ -77,8 +79,10 @@ export type KheopskitProviderProps = PropsWithChildren & {
77
79
  * @example
78
80
  * ```tsx
79
81
  * // Next.js App Router
80
- * const cookieStore = await cookies();
81
- * const ssrCookies = cookieStore.getAll().map(c => `${c.name}=${c.value}`).join('; ');
82
+ * const kheopskitCookie = (await cookies()).get("kheopskit");
83
+ * const ssrCookies = kheopskitCookie
84
+ * ? `kheopskit=${encodeURIComponent(kheopskitCookie.value)}`
85
+ * : "";
82
86
  * return <Providers ssrCookies={ssrCookies}>{children}</Providers>
83
87
  * ```
84
88
  */
@@ -191,4 +195,5 @@ export declare const useWallet: <P extends readonly KheopskitPlatform[] = readon
191
195
  */
192
196
  export declare const useWallets: <P extends readonly KheopskitPlatform[] = readonly KheopskitPlatform[]>() => KheopskitState<P>;
193
197
  //#endregion
198
+ export type { CreateKheopskitConfig, CreateKheopskitOptions };
194
199
  //# sourceMappingURL=index.d.mts.map
package/dist/index.d.ts CHANGED
@@ -1,29 +1,26 @@
1
- import { KheopskitConfig, KheopskitError, KheopskitPlatform, KheopskitState, KheopskitStore, WalletAccountId, WalletId, WalletStatus } from "@kheopskit/core";
1
+ import { CreateKheopskitConfig, CreateKheopskitConfig as CreateKheopskitConfig$1, CreateKheopskitOptions, CreateKheopskitOptions as CreateKheopskitOptions$1, KheopskitConfig, KheopskitError, KheopskitPlatform, KheopskitState, KheopskitStore, WalletAccountId, WalletId, WalletStatus } from "@kheopskit/core";
2
2
  import { FC, PropsWithChildren } from "react";
3
- import { Observable } from "rxjs";
4
3
  //#region src/createKheopskit.d.ts
5
- export type CreateKheopskitConfig<P extends readonly KheopskitPlatform[]> = Omit<Partial<KheopskitConfig<P>>, "platforms"> & {
6
- /** Platform plugins, e.g. `[polkadot(), solana()]`. Required. */
7
- platforms: P;
8
- };
9
- export type CreateKheopskitOptions = {
10
- /**
11
- * Store the shared instance reads the cache from and persists into. Pass one
12
- * when code outside React reads `store` or subscribes `kheopskit$` before
13
- * the provider renders in an SSR app, and in tests.
14
- */
15
- store?: KheopskitStore;
4
+ type ProviderProps<O> = O extends {
5
+ ssr: true;
6
+ } ? {
7
+ ssrCookies?: string;
8
+ } : {
9
+ ssrCookies?: never;
16
10
  };
17
11
  /**
18
12
  * Binds a platform tuple once and returns one kheopskit instance: a
19
13
  * `KheopskitProvider`, hooks already typed to those platforms, and the
20
- * `kheopskit$` stream and `store` the provider uses, for code outside React.
21
- * Subscribing `kheopskit$` while the provider is mounted runs no second
22
- * pipeline, and holds the one pipeline for every hook action of the instance.
14
+ * `kheopskit$` stream and `store` the provider uses, and `waitForAccount`, for
15
+ * code outside React.
16
+ * It is `@kheopskit/core`'s `createKheopskit` instance: subscribing
17
+ * `kheopskit$` while the provider is mounted runs no second pipeline, and
18
+ * holds the one pipeline for every hook action of the instance.
23
19
  *
24
- * Without `options.store`, the store is created on first use in the browser:
25
- * backed by cookies when the provider renders first with `ssrCookies`, by
26
- * localStorage otherwise. The caller owns `store.destroy()`.
20
+ * Without `options.store`, the store is created on first use, backed by
21
+ * cookies with `{ ssr: true }` and by localStorage otherwise. Only an
22
+ * instance created with `{ ssr: true }` accepts the provider's `ssrCookies`.
23
+ * The caller owns `store.destroy()`.
27
24
  *
28
25
  * @example
29
26
  * ```tsx
@@ -35,16 +32,20 @@ export type CreateKheopskitOptions = {
35
32
  * const { accounts } = useWallets(); // accounts are platform-precise, no generic
36
33
  * ```
37
34
  */
38
- export declare const createKheopskit: <const P extends readonly [KheopskitPlatform, ...KheopskitPlatform[]]>(config: CreateKheopskitConfig<P>, options?: CreateKheopskitOptions) => {
39
- KheopskitProvider: FC<PropsWithChildren<{
40
- ssrCookies?: string;
41
- }>>;
35
+ export declare const createKheopskit: <const P extends readonly [KheopskitPlatform, ...KheopskitPlatform[]], const O extends CreateKheopskitOptions$1 = CreateKheopskitOptions$1>(config: CreateKheopskitConfig$1<P>, options?: O) => {
36
+ KheopskitProvider: FC<PropsWithChildren<ProviderProps<O>>>;
42
37
  /** The state stream the provider subscribes to, shared with code outside React. */
43
- kheopskit$: Observable<KheopskitState<P>>;
38
+ kheopskit$: import("rxjs").Observable<import("@kheopskit/core").KheopskitState<P>>;
44
39
  /** The store `kheopskit$` reads the cache from and persists into. */
45
- store: KheopskitStore;
40
+ store: import("@kheopskit/core").KheopskitStore;
41
+ /** Resolves with the live account once the running instance lists it. */
42
+ waitForAccount: (accountId: WalletAccountId, options?: {
43
+ signal?: AbortSignal;
44
+ }) => Promise<Exclude<import("@kheopskit/core").AccountOf<P[number]>, {
45
+ isPlaceholder: true;
46
+ }>>;
46
47
  /** Current state, typed to the bound platform tuple. */
47
- useWallets: () => KheopskitState<P>;
48
+ useWallets: () => import("@kheopskit/core").KheopskitState<P>;
48
49
  /** Current accounts, typed to the bound platform tuple. */
49
50
  useAccounts: () => import("@kheopskit/core").AccountOf<P[number]>[];
50
51
  /** The wallet with this id, typed to the bound platform tuple. */
@@ -66,9 +67,10 @@ export type KheopskitProviderProps = PropsWithChildren & {
66
67
  */
67
68
  config?: Partial<KheopskitConfig>;
68
69
  /**
69
- * Cookie string for SSR hydration.
70
- * Pass the request cookie header (e.g., from Next.js headers or TanStack Start)
71
- * to hydrate wallet state on the server.
70
+ * The kheopskit cookie, for SSR hydration. Pass only the cookie named after
71
+ * `storageKey` (default `kheopskit`), or `""` when it is absent. Never pass
72
+ * the whole cookie header: props of a client component are serialized into
73
+ * the HTML, httpOnly session cookies included.
72
74
  *
73
75
  * @remarks
74
76
  * This value should be stable per render to avoid unnecessary store recreation.
@@ -77,8 +79,10 @@ export type KheopskitProviderProps = PropsWithChildren & {
77
79
  * @example
78
80
  * ```tsx
79
81
  * // Next.js App Router
80
- * const cookieStore = await cookies();
81
- * const ssrCookies = cookieStore.getAll().map(c => `${c.name}=${c.value}`).join('; ');
82
+ * const kheopskitCookie = (await cookies()).get("kheopskit");
83
+ * const ssrCookies = kheopskitCookie
84
+ * ? `kheopskit=${encodeURIComponent(kheopskitCookie.value)}`
85
+ * : "";
82
86
  * return <Providers ssrCookies={ssrCookies}>{children}</Providers>
83
87
  * ```
84
88
  */
@@ -191,4 +195,5 @@ export declare const useWallet: <P extends readonly KheopskitPlatform[] = readon
191
195
  */
192
196
  export declare const useWallets: <P extends readonly KheopskitPlatform[] = readonly KheopskitPlatform[]>() => KheopskitState<P>;
193
197
  //#endregion
198
+ export type { CreateKheopskitConfig, CreateKheopskitOptions };
194
199
  //# sourceMappingURL=index.d.ts.map