@kheopskit/core 0.1.0 → 0.1.2

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.d.mts CHANGED
@@ -17,6 +17,30 @@ declare const clearCachedObservable: (key: string) => void;
17
17
  */
18
18
  declare const clearAllCachedObservables: () => void;
19
19
 
20
+ type Storage = {
21
+ getItem: (key: string) => string | null;
22
+ setItem: (key: string, value: string) => void;
23
+ removeItem: (key: string) => void;
24
+ };
25
+ /**
26
+ * Extended storage interface with cross-tab sync support.
27
+ */
28
+ type SyncableStorage = Storage & {
29
+ /**
30
+ * Subscribe to storage changes from other tabs.
31
+ * Returns an unsubscribe function.
32
+ */
33
+ subscribe?: (key: string, callback: (value: string | null) => void) => () => void;
34
+ };
35
+ /**
36
+ * A safe localStorage wrapper that falls back to noopStorage
37
+ * when localStorage is not available (e.g., during SSR).
38
+ * Includes cross-tab sync via the native 'storage' event.
39
+ *
40
+ * Lazily initialized on first access to be SSR-safe.
41
+ */
42
+ declare const getSafeLocalStorage: () => SyncableStorage;
43
+
20
44
  type WalletAccountId = string;
21
45
 
22
46
  type WalletId = string;
@@ -124,6 +148,8 @@ type EthereumAccount = {
124
148
  platform: "ethereum";
125
149
  client: WalletClient<CustomTransport, undefined, Account, undefined>;
126
150
  address: `0x${string}`;
151
+ /** Current chain ID the wallet is connected to. `undefined` while loading or after provider disconnect. */
152
+ chainId: number | undefined;
127
153
  walletName: string;
128
154
  walletId: string;
129
155
  isWalletDefault: boolean;
@@ -150,6 +176,8 @@ type CachedAccount = {
150
176
  platform: WalletPlatform;
151
177
  address: string;
152
178
  name?: string;
179
+ /** Cached chain ID for Ethereum accounts. */
180
+ chainId?: number;
153
181
  walletId: WalletId;
154
182
  walletName: string;
155
183
  };
@@ -228,6 +256,13 @@ declare const createKheopskitStore: (options?: CreateKheopskitStoreOptions) => {
228
256
  };
229
257
  setCachedState: (wallets: CachedWallet[], accounts: CachedAccount[]) => void;
230
258
  };
259
+ type KheopskitStore = ReturnType<typeof createKheopskitStore>;
260
+ /**
261
+ * Gets the default store, creating it on first access.
262
+ * Uses localStorage on client, noop on server.
263
+ * Lazily initialized to avoid SSR issues with module-level code.
264
+ */
265
+ declare const getDefaultStore: () => KheopskitStore;
231
266
 
232
267
  type KheopskitState = {
233
268
  wallets: Wallet[];
@@ -244,4 +279,4 @@ type KheopskitState = {
244
279
  };
245
280
  declare const getKheopskit$: (config?: Partial<KheopskitConfig>, ssrCookies?: string, existingStore?: ReturnType<typeof createKheopskitStore>) => Observable<KheopskitState>;
246
281
 
247
- export { type CachedAccount, type CachedWallet, DEFAULT_STORAGE_KEY, type EthereumAccount, type EthereumAppKitWallet, type EthereumInjectedWallet, type EthereumWallet, type KheopskitConfig, type KheopskitState, type PolkadotAccount, type PolkadotAppKitWallet, type PolkadotInjectedWallet, type PolkadotWallet, type Wallet, type WalletAccount, type WalletPlatform, clearAllCachedObservables, clearCachedObservable, createKheopskitStore, getCachedIcon, getKheopskit$, hydrateAccount, hydrateWallet, resetAppKitCache, resolveConfig };
282
+ export { type CachedAccount, type CachedWallet, DEFAULT_STORAGE_KEY, type EthereumAccount, type EthereumAppKitWallet, type EthereumInjectedWallet, type EthereumWallet, type KheopskitConfig, type KheopskitState, type PolkadotAccount, type PolkadotAppKitWallet, type PolkadotInjectedWallet, type PolkadotWallet, type Wallet, type WalletAccount, type WalletPlatform, clearAllCachedObservables, clearCachedObservable, createKheopskitStore, getCachedIcon, getDefaultStore, getKheopskit$, getSafeLocalStorage, hydrateAccount, hydrateWallet, resetAppKitCache, resolveConfig };
package/dist/index.d.ts CHANGED
@@ -17,6 +17,30 @@ declare const clearCachedObservable: (key: string) => void;
17
17
  */
18
18
  declare const clearAllCachedObservables: () => void;
19
19
 
20
+ type Storage = {
21
+ getItem: (key: string) => string | null;
22
+ setItem: (key: string, value: string) => void;
23
+ removeItem: (key: string) => void;
24
+ };
25
+ /**
26
+ * Extended storage interface with cross-tab sync support.
27
+ */
28
+ type SyncableStorage = Storage & {
29
+ /**
30
+ * Subscribe to storage changes from other tabs.
31
+ * Returns an unsubscribe function.
32
+ */
33
+ subscribe?: (key: string, callback: (value: string | null) => void) => () => void;
34
+ };
35
+ /**
36
+ * A safe localStorage wrapper that falls back to noopStorage
37
+ * when localStorage is not available (e.g., during SSR).
38
+ * Includes cross-tab sync via the native 'storage' event.
39
+ *
40
+ * Lazily initialized on first access to be SSR-safe.
41
+ */
42
+ declare const getSafeLocalStorage: () => SyncableStorage;
43
+
20
44
  type WalletAccountId = string;
21
45
 
22
46
  type WalletId = string;
@@ -124,6 +148,8 @@ type EthereumAccount = {
124
148
  platform: "ethereum";
125
149
  client: WalletClient<CustomTransport, undefined, Account, undefined>;
126
150
  address: `0x${string}`;
151
+ /** Current chain ID the wallet is connected to. `undefined` while loading or after provider disconnect. */
152
+ chainId: number | undefined;
127
153
  walletName: string;
128
154
  walletId: string;
129
155
  isWalletDefault: boolean;
@@ -150,6 +176,8 @@ type CachedAccount = {
150
176
  platform: WalletPlatform;
151
177
  address: string;
152
178
  name?: string;
179
+ /** Cached chain ID for Ethereum accounts. */
180
+ chainId?: number;
153
181
  walletId: WalletId;
154
182
  walletName: string;
155
183
  };
@@ -228,6 +256,13 @@ declare const createKheopskitStore: (options?: CreateKheopskitStoreOptions) => {
228
256
  };
229
257
  setCachedState: (wallets: CachedWallet[], accounts: CachedAccount[]) => void;
230
258
  };
259
+ type KheopskitStore = ReturnType<typeof createKheopskitStore>;
260
+ /**
261
+ * Gets the default store, creating it on first access.
262
+ * Uses localStorage on client, noop on server.
263
+ * Lazily initialized to avoid SSR issues with module-level code.
264
+ */
265
+ declare const getDefaultStore: () => KheopskitStore;
231
266
 
232
267
  type KheopskitState = {
233
268
  wallets: Wallet[];
@@ -244,4 +279,4 @@ type KheopskitState = {
244
279
  };
245
280
  declare const getKheopskit$: (config?: Partial<KheopskitConfig>, ssrCookies?: string, existingStore?: ReturnType<typeof createKheopskitStore>) => Observable<KheopskitState>;
246
281
 
247
- export { type CachedAccount, type CachedWallet, DEFAULT_STORAGE_KEY, type EthereumAccount, type EthereumAppKitWallet, type EthereumInjectedWallet, type EthereumWallet, type KheopskitConfig, type KheopskitState, type PolkadotAccount, type PolkadotAppKitWallet, type PolkadotInjectedWallet, type PolkadotWallet, type Wallet, type WalletAccount, type WalletPlatform, clearAllCachedObservables, clearCachedObservable, createKheopskitStore, getCachedIcon, getKheopskit$, hydrateAccount, hydrateWallet, resetAppKitCache, resolveConfig };
282
+ export { type CachedAccount, type CachedWallet, DEFAULT_STORAGE_KEY, type EthereumAccount, type EthereumAppKitWallet, type EthereumInjectedWallet, type EthereumWallet, type KheopskitConfig, type KheopskitState, type PolkadotAccount, type PolkadotAppKitWallet, type PolkadotInjectedWallet, type PolkadotWallet, type Wallet, type WalletAccount, type WalletPlatform, clearAllCachedObservables, clearCachedObservable, createKheopskitStore, getCachedIcon, getDefaultStore, getKheopskit$, getSafeLocalStorage, hydrateAccount, hydrateWallet, resetAppKitCache, resolveConfig };
package/dist/index.js CHANGED
@@ -1,20 +1,30 @@
1
1
  "use strict";
2
+ var __create = Object.create;
2
3
  var __defProp = Object.defineProperty;
3
4
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
5
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
5
7
  var __hasOwnProp = Object.prototype.hasOwnProperty;
6
8
  var __export = (target, all) => {
7
9
  for (var name in all)
8
10
  __defProp(target, name, { get: all[name], enumerable: true });
9
11
  };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
12
+ var __copyProps = (to, from2, except, desc) => {
13
+ if (from2 && typeof from2 === "object" || typeof from2 === "function") {
14
+ for (let key of __getOwnPropNames(from2))
13
15
  if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ __defProp(to, key, { get: () => from2[key], enumerable: !(desc = __getOwnPropDesc(from2, key)) || desc.enumerable });
15
17
  }
16
18
  return to;
17
19
  };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
18
28
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
29
 
20
30
  // src/index.ts
@@ -25,7 +35,9 @@ __export(index_exports, {
25
35
  clearCachedObservable: () => clearCachedObservable,
26
36
  createKheopskitStore: () => createKheopskitStore,
27
37
  getCachedIcon: () => getCachedIcon,
38
+ getDefaultStore: () => getDefaultStore,
28
39
  getKheopskit$: () => getKheopskit$,
40
+ getSafeLocalStorage: () => getSafeLocalStorage,
29
41
  hydrateAccount: () => hydrateAccount,
30
42
  hydrateWallet: () => hydrateWallet,
31
43
  resetAppKitCache: () => resetAppKitCache,
@@ -154,6 +166,7 @@ var hydrateAccount = (cached) => {
154
166
  id: cached.id,
155
167
  platform: "ethereum",
156
168
  address: cached.address,
169
+ chainId: cached.chainId,
157
170
  walletId: cached.walletId,
158
171
  walletName: cached.walletName,
159
172
  isWalletDefault: false,
@@ -176,6 +189,7 @@ var serializeAccount = (account) => ({
176
189
  platform: account.platform,
177
190
  address: account.address,
178
191
  name: "name" in account ? account.name : void 0,
192
+ chainId: account.platform === "ethereum" ? account.chainId : void 0,
179
193
  walletId: account.walletId,
180
194
  walletName: account.walletName
181
195
  });
@@ -188,7 +202,8 @@ var noopStorage = {
188
202
  removeItem: () => {
189
203
  }
190
204
  };
191
- var safeLocalStorage = (() => {
205
+ var _safeLocalStorage = null;
206
+ var createSafeLocalStorage = () => {
192
207
  if (typeof window === "undefined") return noopStorage;
193
208
  try {
194
209
  const testKey = "__kheopskit_test__";
@@ -211,7 +226,23 @@ var safeLocalStorage = (() => {
211
226
  } catch {
212
227
  return noopStorage;
213
228
  }
214
- })();
229
+ };
230
+ var getSafeLocalStorage = () => {
231
+ if (_safeLocalStorage === null) {
232
+ _safeLocalStorage = createSafeLocalStorage();
233
+ }
234
+ return _safeLocalStorage;
235
+ };
236
+ var safeLocalStorage = {
237
+ getItem: (key) => getSafeLocalStorage().getItem(key),
238
+ setItem: (key, value) => getSafeLocalStorage().setItem(key, value),
239
+ removeItem: (key) => getSafeLocalStorage().removeItem(key),
240
+ subscribe: (key, callback) => {
241
+ const storage = getSafeLocalStorage();
242
+ return storage.subscribe?.(key, callback) ?? (() => {
243
+ });
244
+ }
245
+ };
215
246
  var parseCookie = (cookieString, key) => {
216
247
  if (!cookieString) return null;
217
248
  for (const cookie of cookieString.split(";")) {
@@ -333,8 +364,11 @@ var setCachedIcons = (icons) => {
333
364
  };
334
365
 
335
366
  // src/api/appKit.ts
336
- var import_core = require("@reown/appkit/core");
337
367
  var import_rxjs = require("rxjs");
368
+ var loadAppKit = async () => {
369
+ const { createAppKit } = await import("@reown/appkit/core");
370
+ return createAppKit;
371
+ };
338
372
  var WALLET_CONNECT_ICON = "data:image/svg+xml;base64,PHN2ZyBmaWxsPSJub25lIiBoZWlnaHQ9IjQwMCIgdmlld0JveD0iMCAwIDQwMCA0MDAiIHdpZHRoPSI0MDAiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgeG1sbnM6eGxpbms9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkveGxpbmsiPjxjbGlwUGF0aCBpZD0iYSI+PHBhdGggZD0ibTAgMGg0MDB2NDAwaC00MDB6Ii8+PC9jbGlwUGF0aD48ZyBjbGlwLXBhdGg9InVybCgjYSkiPjxjaXJjbGUgY3g9IjIwMCIgY3k9IjIwMCIgZmlsbD0iIzMzOTZmZiIgcj0iMTk5LjUiIHN0cm9rZT0iIzY2YjFmZiIvPjxwYXRoIGQ9Im0xMjIuNTE5IDE0OC45NjVjNDIuNzkxLTQxLjcyOSAxMTIuMTcxLTQxLjcyOSAxNTQuOTYyIDBsNS4xNSA1LjAyMmMyLjE0IDIuMDg2IDIuMTQgNS40NjkgMCA3LjU1NWwtMTcuNjE3IDE3LjE4Yy0xLjA3IDEuMDQzLTIuODA0IDEuMDQzLTMuODc0IDBsLTcuMDg3LTYuOTExYy0yOS44NTMtMjkuMTExLTc4LjI1My0yOS4xMTEtMTA4LjEwNiAwbC03LjU5IDcuNDAxYy0xLjA3IDEuMDQzLTIuODA0IDEuMDQzLTMuODc0IDBsLTE3LjYxNy0xNy4xOGMtMi4xNC0yLjA4Ni0yLjE0LTUuNDY5IDAtNy41NTV6bTE5MS4zOTcgMzUuNTI5IDE1LjY3OSAxNS4yOWMyLjE0IDIuMDg2IDIuMTQgNS40NjkgMCA3LjU1NWwtNzAuNyA2OC45NDRjLTIuMTM5IDIuMDg3LTUuNjA4IDIuMDg3LTcuNzQ4IDBsLTUwLjE3OC00OC45MzFjLS41MzUtLjUyMi0xLjQwMi0uNTIyLTEuOTM3IDBsLTUwLjE3OCA0OC45MzFjLTIuMTM5IDIuMDg3LTUuNjA4IDIuMDg3LTcuNzQ4IDBsLTcwLjcwMTUtNjguOTQ1Yy0yLjEzOTYtMi4wODYtMi4xMzk2LTUuNDY5IDAtNy41NTVsMTUuNjc5NS0xNS4yOWMyLjEzOTYtMi4wODYgNS42MDg1LTIuMDg2IDcuNzQ4MSAwbDUwLjE3ODkgNDguOTMyYy41MzUuNTIyIDEuNDAyLjUyMiAxLjkzNyAwbDUwLjE3Ny00OC45MzJjMi4xMzktMi4wODcgNS42MDgtMi4wODcgNy43NDggMGw1MC4xNzkgNDguOTMyYy41MzUuNTIyIDEuNDAyLjUyMiAxLjkzNyAwbDUwLjE3OS00OC45MzFjMi4xMzktMi4wODcgNS42MDgtMi4wODcgNy43NDggMHoiIGZpbGw9IiNmZmYiLz48L2c+PC9zdmc+";
339
373
  var cachedAppKit = null;
340
374
  var resetAppKitCache = () => {
@@ -342,84 +376,90 @@ var resetAppKitCache = () => {
342
376
  };
343
377
  var getAppKitWallets$ = (config) => {
344
378
  if (!config.walletConnect) return (0, import_rxjs.of)({});
379
+ if (typeof window === "undefined") return (0, import_rxjs.of)({});
345
380
  const walletConnect = config.walletConnect;
346
381
  if (!cachedAppKit) {
347
- cachedAppKit = new import_rxjs.Observable((subscriber) => {
348
- const appKit = (0, import_core.createAppKit)({
349
- projectId: walletConnect.projectId,
350
- metadata: walletConnect.metadata,
351
- networks: walletConnect.networks,
352
- themeMode: walletConnect.themeMode,
353
- themeVariables: walletConnect.themeVariables,
354
- universalProviderConfigOverride: {
355
- methods: {
356
- polkadot: ["polkadot_signTransaction", "polkadot_signMessage"]
357
- }
358
- },
359
- allWallets: "HIDE",
360
- debug: config.debug,
361
- allowUnsupportedChain: true
362
- });
363
- const status$ = new import_rxjs.BehaviorSubject({
364
- isPolkadotConnected: false,
365
- isEthereumConnected: false
366
- });
367
- const unsubProviders = appKit.subscribeProviders((providers) => {
368
- status$.next({
369
- isPolkadotConnected: !!providers.polkadot,
370
- isEthereumConnected: !!providers.eip155
371
- });
372
- });
373
- const polkadotWallet$ = appKit.chainNamespaces.includes("polkadot") ? status$.pipe(
374
- (0, import_rxjs.map)((s) => s.isPolkadotConnected),
375
- (0, import_rxjs.distinctUntilChanged)(),
376
- (0, import_rxjs.map)((isConnected) => {
377
- const walletInfo = appKit.getWalletInfo();
378
- return {
379
- id: getWalletId("polkadot", "walletconnect"),
380
- platform: "polkadot",
381
- type: "appKit",
382
- appKit,
383
- // todo maybe we dont want to expose the appKit instance
384
- name: walletInfo?.name ?? "WalletConnect",
385
- icon: walletInfo?.icon ?? WALLET_CONNECT_ICON,
386
- connect: async () => {
387
- if (!isConnected) await appKit.open();
382
+ cachedAppKit = (0, import_rxjs.from)(loadAppKit()).pipe(
383
+ (0, import_rxjs.switchMap)((createAppKit) => {
384
+ return new import_rxjs.Observable((subscriber) => {
385
+ const appKit = createAppKit({
386
+ projectId: walletConnect.projectId,
387
+ metadata: walletConnect.metadata,
388
+ networks: walletConnect.networks,
389
+ themeMode: walletConnect.themeMode,
390
+ themeVariables: walletConnect.themeVariables,
391
+ universalProviderConfigOverride: {
392
+ methods: {
393
+ polkadot: ["polkadot_signTransaction", "polkadot_signMessage"]
394
+ }
388
395
  },
389
- disconnect: () => {
390
- if (isConnected) appKit.disconnect();
391
- },
392
- isConnected
393
- };
394
- })
395
- ) : (0, import_rxjs.of)(void 0);
396
- const ethereumWallet$ = appKit.chainNamespaces.includes("eip155") ? status$.pipe(
397
- (0, import_rxjs.map)((s) => s.isEthereumConnected),
398
- (0, import_rxjs.distinctUntilChanged)(),
399
- (0, import_rxjs.map)((isConnected) => {
400
- const walletInfo = appKit.getWalletInfo();
401
- return {
402
- id: getWalletId("ethereum", "walletconnect"),
403
- platform: "ethereum",
404
- type: "appKit",
405
- appKit,
406
- name: walletInfo?.name ?? "WalletConnect",
407
- icon: walletInfo?.icon ?? WALLET_CONNECT_ICON,
408
- connect: () => appKit.open(),
409
- disconnect: () => appKit.disconnect(),
410
- isConnected
396
+ allWallets: "HIDE",
397
+ debug: config.debug,
398
+ allowUnsupportedChain: true
399
+ });
400
+ const status$ = new import_rxjs.BehaviorSubject({
401
+ isPolkadotConnected: false,
402
+ isEthereumConnected: false
403
+ });
404
+ const unsubProviders = appKit.subscribeProviders((providers) => {
405
+ status$.next({
406
+ isPolkadotConnected: !!providers.polkadot,
407
+ isEthereumConnected: !!providers.eip155
408
+ });
409
+ });
410
+ const polkadotWallet$ = appKit.chainNamespaces.includes("polkadot") ? status$.pipe(
411
+ (0, import_rxjs.map)((s) => s.isPolkadotConnected),
412
+ (0, import_rxjs.distinctUntilChanged)(),
413
+ (0, import_rxjs.map)((isConnected) => {
414
+ const walletInfo = appKit.getWalletInfo();
415
+ return {
416
+ id: getWalletId("polkadot", "walletconnect"),
417
+ platform: "polkadot",
418
+ type: "appKit",
419
+ appKit,
420
+ // todo maybe we dont want to expose the appKit instance
421
+ name: walletInfo?.name ?? "WalletConnect",
422
+ icon: walletInfo?.icon ?? WALLET_CONNECT_ICON,
423
+ connect: async () => {
424
+ if (!isConnected) await appKit.open();
425
+ },
426
+ disconnect: () => {
427
+ if (isConnected) appKit.disconnect();
428
+ },
429
+ isConnected
430
+ };
431
+ })
432
+ ) : (0, import_rxjs.of)(void 0);
433
+ const ethereumWallet$ = appKit.chainNamespaces.includes("eip155") ? status$.pipe(
434
+ (0, import_rxjs.map)((s) => s.isEthereumConnected),
435
+ (0, import_rxjs.distinctUntilChanged)(),
436
+ (0, import_rxjs.map)((isConnected) => {
437
+ const walletInfo = appKit.getWalletInfo();
438
+ return {
439
+ id: getWalletId("ethereum", "walletconnect"),
440
+ platform: "ethereum",
441
+ type: "appKit",
442
+ appKit,
443
+ name: walletInfo?.name ?? "WalletConnect",
444
+ icon: walletInfo?.icon ?? WALLET_CONNECT_ICON,
445
+ connect: () => appKit.open(),
446
+ disconnect: () => appKit.disconnect(),
447
+ isConnected
448
+ };
449
+ })
450
+ ) : (0, import_rxjs.of)(void 0);
451
+ const sub = (0, import_rxjs.combineLatest)({
452
+ polkadot: polkadotWallet$,
453
+ ethereum: ethereumWallet$
454
+ }).subscribe(subscriber);
455
+ return () => {
456
+ sub.unsubscribe();
457
+ unsubProviders();
411
458
  };
412
- })
413
- ) : (0, import_rxjs.of)(void 0);
414
- const sub = (0, import_rxjs.combineLatest)({
415
- polkadot: polkadotWallet$,
416
- ethereum: ethereumWallet$
417
- }).subscribe(subscriber);
418
- return () => {
419
- sub.unsubscribe();
420
- unsubProviders();
421
- };
422
- }).pipe((0, import_rxjs.shareReplay)({ refCount: true, bufferSize: 1 }));
459
+ });
460
+ }),
461
+ (0, import_rxjs.shareReplay)({ refCount: true, bufferSize: 1 })
462
+ );
423
463
  }
424
464
  return cachedAppKit;
425
465
  };
@@ -659,12 +699,37 @@ var getWalletAccountId = (walletId, address) => {
659
699
  };
660
700
 
661
701
  // src/api/ethereum/accounts.ts
702
+ var normalizeEvmChainId = (value) => {
703
+ let raw = value;
704
+ if (typeof raw === "string" && raw.startsWith("eip155:")) {
705
+ raw = raw.slice("eip155:".length);
706
+ }
707
+ if (typeof raw === "bigint") {
708
+ return raw >= 0n ? Number(raw) : void 0;
709
+ }
710
+ if (typeof raw === "number") {
711
+ return Number.isInteger(raw) && raw >= 0 ? raw : void 0;
712
+ }
713
+ if (typeof raw === "string") {
714
+ const normalized = raw.trim().toLowerCase();
715
+ if (!normalized) return void 0;
716
+ const parsed = normalized.startsWith("0x") ? Number.parseInt(normalized, 16) : Number.parseInt(normalized, 10);
717
+ return Number.isNaN(parsed) ? void 0 : parsed;
718
+ }
719
+ return void 0;
720
+ };
721
+ var toCaipNetworkId = (value) => {
722
+ const chainId = normalizeEvmChainId(value);
723
+ return chainId === void 0 ? void 0 : `eip155:${chainId}`;
724
+ };
662
725
  var getInjectedWalletAccounts$ = (wallet) => {
663
726
  if (!wallet.isConnected) return (0, import_rxjs5.of)([]);
664
727
  return getCachedObservable$(
665
728
  `accounts:${wallet.id}`,
666
729
  () => new import_rxjs5.Observable((subscriber) => {
667
- const getAccount = (address, i) => {
730
+ const addresses$ = new import_rxjs5.ReplaySubject(1);
731
+ const chainId$ = new import_rxjs5.ReplaySubject(1);
732
+ const getAccount = (address, i, chainId) => {
668
733
  const client = (0, import_viem2.createWalletClient)({
669
734
  account: address,
670
735
  transport: (0, import_viem2.custom)(wallet.provider)
@@ -674,26 +739,42 @@ var getInjectedWalletAccounts$ = (wallet) => {
674
739
  platform: "ethereum",
675
740
  client,
676
741
  address: (0, import_viem2.getAddress)(address),
742
+ chainId,
677
743
  walletName: wallet.name,
678
744
  walletId: wallet.id,
679
745
  isWalletDefault: i === 0
680
746
  };
681
747
  };
682
- const handleAccountsChanged = (addresses) => {
683
- subscriber.next(addresses.map(getAccount));
748
+ const handleAccountsChanged = (addrs) => {
749
+ addresses$.next(addrs);
750
+ };
751
+ const handleChainChanged = (chainIdHex) => {
752
+ chainId$.next(normalizeEvmChainId(chainIdHex));
753
+ };
754
+ const handleDisconnect = () => {
755
+ chainId$.next(void 0);
684
756
  };
685
757
  wallet.provider.on("accountsChanged", handleAccountsChanged);
686
- wallet.provider.request({ method: "eth_accounts" }).then((addresses) => {
687
- subscriber.next(addresses.map(getAccount));
688
- }).catch((err) => {
758
+ wallet.provider.on("chainChanged", handleChainChanged);
759
+ wallet.provider.on("disconnect", handleDisconnect);
760
+ wallet.provider.request({ method: "eth_accounts" }).then((addrs) => addresses$.next(addrs)).catch((err) => {
689
761
  console.error("Failed to get accounts", err);
690
- subscriber.next([]);
762
+ addresses$.next([]);
691
763
  });
764
+ wallet.provider.request({ method: "eth_chainId" }).then(handleChainChanged).catch(() => chainId$.next(void 0));
765
+ const sub = (0, import_rxjs5.combineLatest)([addresses$, chainId$]).pipe(
766
+ (0, import_rxjs5.map)(
767
+ ([addresses, chainId]) => addresses.map((addr, i) => getAccount(addr, i, chainId))
768
+ )
769
+ ).subscribe(subscriber);
692
770
  return () => {
693
771
  wallet.provider.removeListener(
694
772
  "accountsChanged",
695
773
  handleAccountsChanged
696
774
  );
775
+ wallet.provider.removeListener("chainChanged", handleChainChanged);
776
+ wallet.provider.removeListener("disconnect", handleDisconnect);
777
+ sub.unsubscribe();
697
778
  };
698
779
  }).pipe((0, import_rxjs5.shareReplay)({ refCount: true, bufferSize: 1 }))
699
780
  );
@@ -722,24 +803,29 @@ var getAppKitAccounts$ = (wallet) => {
722
803
  () => new import_rxjs5.Observable((subscriber) => {
723
804
  const caipNetworkId$ = new import_rxjs5.ReplaySubject(1);
724
805
  const handleChainChanged = (chainId) => {
725
- caipNetworkId$.next(`eip155:${chainId}`);
806
+ const caipNetworkId = toCaipNetworkId(chainId);
807
+ if (caipNetworkId) {
808
+ caipNetworkId$.next(caipNetworkId);
809
+ }
726
810
  };
727
811
  provider.on("chainChanged", handleChainChanged);
728
812
  provider.request({ method: "eth_chainId" }).then(handleChainChanged);
729
813
  const sub = caipNetworkId$.pipe(
730
814
  (0, import_rxjs5.distinctUntilChanged)(),
731
- (0, import_rxjs5.map)(
732
- (caipNetworkId) => (0, import_viem2.custom)(
815
+ (0, import_rxjs5.map)((caipNetworkId) => {
816
+ const chainId = normalizeEvmChainId(caipNetworkId);
817
+ const transport = (0, import_viem2.custom)(
733
818
  wrapWalletConnectProvider(
734
819
  provider,
735
820
  // biome-ignore lint/style/noNonNullAssertion: legacy
736
821
  provider.session.topic,
737
822
  caipNetworkId
738
823
  )
739
- )
740
- ),
824
+ );
825
+ return { transport, chainId };
826
+ }),
741
827
  (0, import_rxjs5.map)(
742
- (transport) => account.allAccounts.map((acc, i) => {
828
+ ({ transport, chainId }) => account.allAccounts.map((acc, i) => {
743
829
  const client = (0, import_viem2.createWalletClient)({
744
830
  account: acc.address,
745
831
  transport
@@ -751,6 +837,7 @@ var getAppKitAccounts$ = (wallet) => {
751
837
  walletId: wallet.id,
752
838
  address: acc.address,
753
839
  client,
840
+ chainId,
754
841
  isWalletDefault: i === 0
755
842
  };
756
843
  })
@@ -785,7 +872,9 @@ var getEthereumAccounts$ = (ethereumWallets) => new import_rxjs5.Observable((sub
785
872
  );
786
873
  var isSameAccountsList = (a, b) => {
787
874
  if (a.length !== b.length) return false;
788
- return a.every((account, i) => account.id === b[i]?.id);
875
+ return a.every(
876
+ (account, i) => account.id === b[i]?.id && account.chainId === b[i]?.chainId
877
+ );
789
878
  };
790
879
 
791
880
  // src/api/polkadot/accounts.ts
@@ -967,7 +1056,22 @@ var createKheopskitStore = (options = {}) => {
967
1056
  setCachedState
968
1057
  };
969
1058
  };
970
- var store = createKheopskitStore();
1059
+ var _defaultStore = null;
1060
+ var getDefaultStore = () => {
1061
+ if (_defaultStore === null) {
1062
+ _defaultStore = createKheopskitStore();
1063
+ }
1064
+ return _defaultStore;
1065
+ };
1066
+ var store = {
1067
+ get observable() {
1068
+ return getDefaultStore().observable;
1069
+ },
1070
+ addEnabledWalletId: (walletId) => getDefaultStore().addEnabledWalletId(walletId),
1071
+ removeEnabledWalletId: (walletId) => getDefaultStore().removeEnabledWalletId(walletId),
1072
+ getCachedState: () => getDefaultStore().getCachedState(),
1073
+ setCachedState: (wallets, accounts) => getDefaultStore().setCachedState(wallets, accounts)
1074
+ };
971
1075
  var isCompactStore = (value) => {
972
1076
  if (!value || typeof value !== "object" || Array.isArray(value)) return false;
973
1077
  if ("cachedWallets" in value || "cachedAccounts" in value) return false;
@@ -986,7 +1090,8 @@ var toCompactStore = (data) => {
986
1090
  (account) => [
987
1091
  account.walletId,
988
1092
  account.address,
989
- account.name ?? null
1093
+ account.name ?? null,
1094
+ account.chainId ?? null
990
1095
  ]
991
1096
  );
992
1097
  return {
@@ -1011,13 +1116,14 @@ var fromCompactStore = (data) => {
1011
1116
  };
1012
1117
  });
1013
1118
  const accounts = (data.a ?? []).map((item) => {
1014
- const [walletId, address, name] = item;
1119
+ const [walletId, address, name, chainId] = item;
1015
1120
  const { platform } = parseWalletId(walletId);
1016
1121
  return {
1017
1122
  id: getWalletAccountId(walletId, address),
1018
1123
  platform,
1019
1124
  address,
1020
1125
  name: name ?? void 0,
1126
+ chainId: chainId ?? void 0,
1021
1127
  walletId,
1022
1128
  walletName: walletNameMap.get(walletId) ?? walletId
1023
1129
  };
@@ -1479,7 +1585,9 @@ var getKheopskit$ = (config, ssrCookies, existingStore) => {
1479
1585
  var arraysEqual = (a, b) => a.length === b.length && a.every((v, i) => v === b[i]);
1480
1586
  var statesEqual = (a, b) => a.isHydrating === b.isHydrating && a.wallets.length === b.wallets.length && a.accounts.length === b.accounts.length && a.wallets.every(
1481
1587
  (w, i) => w.id === b.wallets[i]?.id && w.isConnected === b.wallets[i]?.isConnected
1482
- ) && a.accounts.every((acc, i) => acc.id === b.accounts[i]?.id);
1588
+ ) && a.accounts.every(
1589
+ (acc, i) => acc.id === b.accounts[i]?.id && (acc.platform !== "ethereum" || acc.chainId === b.accounts[i]?.chainId)
1590
+ );
1483
1591
  // Annotate the CommonJS export names for ESM import in node:
1484
1592
  0 && (module.exports = {
1485
1593
  DEFAULT_STORAGE_KEY,
@@ -1487,7 +1595,9 @@ var statesEqual = (a, b) => a.isHydrating === b.isHydrating && a.wallets.length
1487
1595
  clearCachedObservable,
1488
1596
  createKheopskitStore,
1489
1597
  getCachedIcon,
1598
+ getDefaultStore,
1490
1599
  getKheopskit$,
1600
+ getSafeLocalStorage,
1491
1601
  hydrateAccount,
1492
1602
  hydrateWallet,
1493
1603
  resetAppKitCache,