@kheopskit/core 4.0.0 → 5.0.1
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/{chunk-SIUWQBT4.js → chunk-4ENHC7G4.js} +11 -2
- package/dist/chunk-4ENHC7G4.js.map +1 -0
- package/dist/{chunk-KWFQDD7E.mjs → chunk-6XAZANB5.mjs} +58 -186
- package/dist/chunk-6XAZANB5.mjs.map +1 -0
- package/dist/{chunk-PNPPI5CH.mjs → chunk-7QSGAJ4A.mjs} +11 -2
- package/dist/chunk-7QSGAJ4A.mjs.map +1 -0
- package/dist/{chunk-TMAPQWW2.js → chunk-B4L6GAYD.js} +24 -9
- package/dist/chunk-B4L6GAYD.js.map +1 -0
- package/dist/chunk-XQWJM3KC.js +450 -0
- package/dist/chunk-XQWJM3KC.js.map +1 -0
- package/dist/{chunk-4RBYRNY3.mjs → chunk-YDLCHYHH.mjs} +22 -7
- package/dist/chunk-YDLCHYHH.mjs.map +1 -0
- package/dist/ethereum.d.mts +4 -3
- package/dist/ethereum.d.ts +4 -3
- package/dist/ethereum.js +61 -42
- package/dist/ethereum.js.map +1 -1
- package/dist/ethereum.mjs +53 -34
- package/dist/ethereum.mjs.map +1 -1
- package/dist/index.d.mts +20 -6
- package/dist/index.d.ts +20 -6
- package/dist/index.js +253 -47
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +271 -65
- package/dist/index.mjs.map +1 -1
- package/dist/internal.d.mts +4 -4
- package/dist/internal.d.ts +4 -4
- package/dist/internal.js +3 -3
- package/dist/internal.mjs +2 -2
- package/dist/polkadot.d.mts +4 -3
- package/dist/polkadot.d.ts +4 -3
- package/dist/polkadot.js +26 -37
- package/dist/polkadot.js.map +1 -1
- package/dist/polkadot.mjs +13 -24
- package/dist/polkadot.mjs.map +1 -1
- package/dist/solana.d.mts +5 -4
- package/dist/solana.d.ts +5 -4
- package/dist/solana.js +37 -42
- package/dist/solana.js.map +1 -1
- package/dist/solana.mjs +26 -31
- package/dist/solana.mjs.map +1 -1
- package/dist/{types-BNzRUNw-.d.mts → types-C7V7DGlg.d.mts} +47 -17
- package/dist/{types-BNzRUNw-.d.ts → types-C7V7DGlg.d.ts} +47 -17
- package/package.json +42 -16
- package/dist/chunk-4RBYRNY3.mjs.map +0 -1
- package/dist/chunk-FIAL4HTE.js +0 -1
- package/dist/chunk-FIAL4HTE.js.map +0 -1
- package/dist/chunk-KWFQDD7E.mjs.map +0 -1
- package/dist/chunk-NU46D4MZ.js +0 -578
- package/dist/chunk-NU46D4MZ.js.map +0 -1
- package/dist/chunk-PNPPI5CH.mjs.map +0 -1
- package/dist/chunk-SIUWQBT4.js.map +0 -1
- package/dist/chunk-TMAPQWW2.js.map +0 -1
- package/dist/chunk-YFD3IKK5.mjs +0 -1
- package/dist/chunk-YFD3IKK5.mjs.map +0 -1
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/api/kheopskit.ts","../src/utils/createHydrationBuffer.ts","../src/utils/logObservable.ts","../src/api/accounts.ts","../src/api/wallets.ts"],"sourcesContent":["import {\n\tcombineLatest,\n\tdebounceTime,\n\tdistinctUntilChanged,\n\tfilter,\n\tmap,\n\tObservable,\n\tshareReplay,\n\tthrottleTime,\n} from \"rxjs\";\nimport {\n\tcreateAccountHydrationBuffer,\n\tcreateHydrationBuffer,\n} from \"../utils/createHydrationBuffer\";\nimport {\n\thydrateAccount,\n\thydrateWallet,\n\tserializeAccount,\n\tserializeWallet,\n} from \"../utils/hydrateState\";\nimport { getCachedIcon, setCachedIcons } from \"../utils/iconCache\";\nimport { logObservable } from \"../utils/logObservable\";\nimport { sortAccounts } from \"../utils/sortAccounts\";\nimport { sortWallets } from \"../utils/sortWallets\";\nimport { getAccounts$ } from \"./accounts\";\nimport { resolveConfig } from \"./config\";\nimport { acceptsCachedAccount } from \"./platform\";\nimport { createKheopskitStore } from \"./store\";\nimport type {\n\tKheopskitConfig,\n\tKheopskitPlatform,\n\tKheopskitState,\n} from \"./types\";\nimport { getWallets$ } from \"./wallets\";\n\nexport type { KheopskitConfig, KheopskitState } from \"./types\";\n\nexport const getKheopskit$ = <\n\tconst P extends readonly KheopskitPlatform[] = readonly KheopskitPlatform[],\n>(\n\tconfig?: Partial<KheopskitConfig<P>>,\n\tssrCookies?: string,\n\texistingStore?: ReturnType<typeof createKheopskitStore>,\n): Observable<KheopskitState<P>> => {\n\tconst kc = resolveConfig(config);\n\tconst store =\n\t\texistingStore ??\n\t\tcreateKheopskitStore({ ssrCookies, storageKey: kc.storageKey });\n\n\tif (kc.debug) console.debug(\"[kheopskit] config\", kc);\n\n\t// Warn about SSR environment without cookies\n\tif (kc.debug && typeof window === \"undefined\" && ssrCookies === undefined) {\n\t\tconsole.warn(\n\t\t\t\"[kheopskit] Running on server without `ssrCookies`. \" +\n\t\t\t\t\"Wallet state will not be hydrated. Pass cookies for SSR support.\",\n\t\t);\n\t}\n\n\t// Get cached state for hydration\n\tconst cachedState = store.getCachedState();\n\t// Hydrate wallets and enrich with icons from localStorage cache\n\tconst cachedWallets = cachedState.wallets.map((w) => {\n\t\tconst wallet = hydrateWallet(w);\n\t\t// If wallet doesn't have icon (e.g., Ethereum), try localStorage cache\n\t\tif (!wallet.icon) {\n\t\t\tconst cachedIcon = getCachedIcon(wallet.id);\n\t\t\tif (cachedIcon) {\n\t\t\t\treturn { ...wallet, icon: cachedIcon };\n\t\t\t}\n\t\t}\n\t\treturn wallet;\n\t});\n\tconst cachedAccounts = cachedState.accounts\n\t\t.filter((cached) => acceptsCachedAccount(cached, kc.platforms))\n\t\t.map(hydrateAccount);\n\n\tif (kc.debug && cachedWallets.length > 0) {\n\t\tconsole.debug(\"[kheopskit] hydrating from cache:\", {\n\t\t\twallets: cachedWallets.length,\n\t\t\taccounts: cachedAccounts.length,\n\t\t});\n\t}\n\n\treturn new Observable<KheopskitState>((subscriber) => {\n\t\t// Get live wallets and accounts\n\t\tconst liveWallets$ = getWallets$(kc, store);\n\t\tconst liveAccounts$ = getAccounts$(kc, liveWallets$);\n\n\t\t// Apply hydration buffer to wallets\n\t\tconst bufferedWallets$ = createHydrationBuffer(\n\t\t\tcachedWallets,\n\t\t\tliveWallets$,\n\t\t\tkc.hydrationGracePeriod,\n\t\t\t(w) => w.id,\n\t\t\t// Hydration converges when all cached-connected wallets are connected in live\n\t\t\t(liveWallets, cached) => {\n\t\t\t\tconst cachedConnectedIds = new Set(\n\t\t\t\t\tcached.filter((w) => w.isConnected).map((w) => w.id),\n\t\t\t\t);\n\t\t\t\tif (cachedConnectedIds.size === 0) return true;\n\t\t\t\treturn [...cachedConnectedIds].every((id) =>\n\t\t\t\t\tliveWallets.some((w) => w.id === id && w.isConnected),\n\t\t\t\t);\n\t\t\t},\n\t\t\t// Merge: prefer cached isConnected state but get icon from cache or live\n\t\t\t(live, cached) => ({\n\t\t\t\t...cached,\n\t\t\t\t// Priority: cached icon > localStorage cache > live icon\n\t\t\t\ticon: cached.icon || getCachedIcon(cached.id) || live.icon,\n\t\t\t\t// Use live wallet's connect/disconnect functions\n\t\t\t\tconnect: live.connect,\n\t\t\t\tdisconnect: live.disconnect,\n\t\t\t}),\n\t\t\t// Transform cached-only items: add icon from localStorage cache\n\t\t\t(cached) => ({\n\t\t\t\t...cached,\n\t\t\t\ticon: cached.icon || getCachedIcon(cached.id) || \"\",\n\t\t\t}),\n\t\t);\n\n\t\t// Apply hydration buffer to accounts\n\t\tconst bufferedAccounts$ = createAccountHydrationBuffer(\n\t\t\tcachedAccounts,\n\t\t\tliveAccounts$,\n\t\t\tkc.hydrationGracePeriod,\n\t\t\t(a) => a.walletId,\n\t\t\t// Hydration converges when all wallets with cached accounts have provided live accounts\n\t\t\t(liveAccounts, cached) => {\n\t\t\t\tconst cachedWalletIds = new Set(cached.map((a) => a.walletId));\n\t\t\t\tif (cachedWalletIds.size === 0) return true;\n\t\t\t\tconst liveWalletIds = new Set(liveAccounts.map((a) => a.walletId));\n\t\t\t\treturn [...cachedWalletIds].every((id) => liveWalletIds.has(id));\n\t\t\t},\n\t\t);\n\n\t\t// Share the buffered streams so the main and persistence subscriptions\n\t\t// below reuse a single hydration pipeline (timers, isHydrating state)\n\t\t// instead of running the buffering twice.\n\t\tconst sharedWallets$ = bufferedWallets$.pipe(\n\t\t\tshareReplay({ bufferSize: 1, refCount: true }),\n\t\t);\n\t\tconst sharedAccounts$ = bufferedAccounts$.pipe(\n\t\t\tshareReplay({ bufferSize: 1, refCount: true }),\n\t\t);\n\n\t\t// Combine buffered wallets and accounts\n\t\tconst subscription = combineLatest({\n\t\t\twallets: sharedWallets$,\n\t\t\taccounts: sharedAccounts$,\n\t\t})\n\t\t\t.pipe(\n\t\t\t\tmap(({ wallets, accounts }) => {\n\t\t\t\t\tif (kc.debug) {\n\t\t\t\t\t\tconsole.debug(\"[kheopskit] hydration state\", {\n\t\t\t\t\t\t\twalletsHydrating: wallets.isHydrating,\n\t\t\t\t\t\t\taccountsHydrating: accounts.isHydrating,\n\t\t\t\t\t\t\twalletsConnected: wallets.items.filter((w) => w.isConnected)\n\t\t\t\t\t\t\t\t.length,\n\t\t\t\t\t\t\twalletsTotal: wallets.items.length,\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\t\t\t\t\t// Sort on every emission with the same comparators used for the\n\t\t\t\t\t// cached initial snapshot. The hydration buffers append cached-only\n\t\t\t\t\t// items after live ones (and reconnects land out of order), so\n\t\t\t\t\t// without this the list visibly reorders as wallets come back.\n\t\t\t\t\treturn {\n\t\t\t\t\t\tconfig: kc,\n\t\t\t\t\t\twallets: [...wallets.items].sort(sortWallets),\n\t\t\t\t\t\taccounts: [...accounts.items].sort(sortAccounts),\n\t\t\t\t\t\tisHydrating: wallets.isHydrating || accounts.isHydrating,\n\t\t\t\t\t};\n\t\t\t\t}),\n\t\t\t)\n\t\t\t.subscribe(subscriber);\n\n\t\t// Persist state snapshot when hydration completes and state stabilizes\n\t\tconst persistSub = combineLatest({\n\t\t\twallets: sharedWallets$,\n\t\t\taccounts: sharedAccounts$,\n\t\t})\n\t\t\t.pipe(\n\t\t\t\t// Wait for hydration to complete\n\t\t\t\tfilter(\n\t\t\t\t\t({ wallets, accounts }) =>\n\t\t\t\t\t\t!wallets.isHydrating && !accounts.isHydrating,\n\t\t\t\t),\n\t\t\t\t// Debounce to avoid excessive writes\n\t\t\t\tdebounceTime(1000),\n\t\t\t\t// Only persist if state actually changed\n\t\t\t\tdistinctUntilChanged((prev, curr) => {\n\t\t\t\t\tconst prevWalletIds = prev.wallets.items.map((w) => w.id);\n\t\t\t\t\tconst currWalletIds = curr.wallets.items.map((w) => w.id);\n\t\t\t\t\tconst prevAccountIds = prev.accounts.items.map((a) => a.id);\n\t\t\t\t\tconst currAccountIds = curr.accounts.items.map((a) => a.id);\n\t\t\t\t\treturn (\n\t\t\t\t\t\tarraysEqual(prevWalletIds, currWalletIds) &&\n\t\t\t\t\t\tarraysEqual(prevAccountIds, currAccountIds)\n\t\t\t\t\t);\n\t\t\t\t}),\n\t\t\t)\n\t\t\t.subscribe(({ wallets, accounts }) => {\n\t\t\t\t// Cache ALL wallets to avoid wallet list flash on reload\n\t\t\t\t// Only accounts from connected wallets are cached\n\t\t\t\tconst connectedWalletIds = new Set(\n\t\t\t\t\twallets.items.filter((w) => w.isConnected).map((w) => w.id),\n\t\t\t\t);\n\t\t\t\tconst relevantAccounts = accounts.items.filter((a) =>\n\t\t\t\t\tconnectedWalletIds.has(a.walletId),\n\t\t\t\t);\n\n\t\t\t\tif (kc.debug) {\n\t\t\t\t\tconsole.debug(\"[kheopskit] persisting state snapshot:\", {\n\t\t\t\t\t\twallets: wallets.items.length,\n\t\t\t\t\t\taccounts: relevantAccounts.length,\n\t\t\t\t\t});\n\t\t\t\t}\n\n\t\t\t\tstore.setCachedState(\n\t\t\t\t\twallets.items.map(serializeWallet),\n\t\t\t\t\trelevantAccounts.map(serializeAccount),\n\t\t\t\t);\n\n\t\t\t\t// Cache wallet icons in localStorage (separate from cookies for size)\n\t\t\t\tconst icons: Record<string, string> = {};\n\t\t\t\tfor (const wallet of wallets.items) {\n\t\t\t\t\tif (wallet.icon) {\n\t\t\t\t\t\ticons[wallet.id] = wallet.icon;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tsetCachedIcons(icons);\n\t\t\t});\n\n\t\treturn () => {\n\t\t\tsubscription.unsubscribe();\n\t\t\tpersistSub.unsubscribe();\n\t\t};\n\t}).pipe(\n\t\tdistinctUntilChanged(statesEqual),\n\t\tthrottleTime(16, undefined, { leading: true, trailing: true }), // ~1 frame at 60fps\n\t\tlogObservable(\"kheopskit$\", { enabled: kc.debug, printValue: true }),\n\t\tshareReplay({ bufferSize: 1, refCount: true }),\n\t\t// The runtime objects are the concrete per-plugin wallet/account types;\n\t\t// recover the precise KheopskitState<P> the caller's plugins imply.\n\t) as unknown as Observable<KheopskitState<P>>;\n};\n\nconst arraysEqual = (a: string[], b: string[]) =>\n\ta.length === b.length && a.every((v, i) => v === b[i]);\n\n/**\n * Deep equality check for KheopskitState to prevent unnecessary emissions.\n */\nconst statesEqual = (a: KheopskitState, b: KheopskitState): boolean =>\n\ta.isHydrating === b.isHydrating &&\n\ta.wallets.length === b.wallets.length &&\n\ta.accounts.length === b.accounts.length &&\n\ta.wallets.every(\n\t\t(w, i) =>\n\t\t\tw.id === b.wallets[i]?.id && w.isConnected === b.wallets[i]?.isConnected,\n\t) &&\n\ta.accounts.every((acc, i) => {\n\t\tconst other = b.accounts[i];\n\t\tif (acc.id !== other?.id) return false;\n\t\t// Compare platform-specific fields that can change without the account id\n\t\t// changing, so the UI re-renders on e.g. an Ethereum chain switch.\n\t\tswitch (acc.platform) {\n\t\t\tcase \"ethereum\":\n\t\t\t\treturn (\n\t\t\t\t\t(acc as { chainId?: number }).chainId ===\n\t\t\t\t\t(other as { chainId?: number }).chainId\n\t\t\t\t);\n\t\t\tcase \"polkadot\":\n\t\t\t\treturn (\n\t\t\t\t\t(acc as { type?: string }).type === (other as { type?: string }).type\n\t\t\t\t);\n\t\t\tcase \"solana\":\n\t\t\t\treturn arraysEqual(\n\t\t\t\t\t(acc as { chains?: string[] }).chains ?? [],\n\t\t\t\t\t(other as { chains?: string[] }).chains ?? [],\n\t\t\t\t);\n\t\t\tdefault:\n\t\t\t\treturn true;\n\t\t}\n\t});\n","import {\n\tBehaviorSubject,\n\tcombineLatest,\n\tfilter,\n\tmap,\n\tObservable,\n\tSubscription,\n\tshareReplay,\n\tstartWith,\n\ttake,\n\ttimer,\n} from \"rxjs\";\n\ntype HydrationBufferResult<T> = {\n\titems: T[];\n\tisHydrating: boolean;\n};\n\n/**\n * Core hydration buffer logic shared between wallets and accounts.\n *\n * During the grace period:\n * - Emits cached items immediately (before any live emissions)\n * - As live items arrive, merges them using the provided merge function\n *\n * After the grace period (and convergence, if provided):\n * - Only live items are returned\n * - isHydrating becomes false\n *\n * If an `isConverged` function is provided, hydration ends only when BOTH\n * the grace period has elapsed AND the live items have converged with cached\n * items (e.g., all previously-connected wallets have reconnected).\n * A max timeout (6x grace period) prevents infinite hydration.\n *\n * @param cachedItems - Initial cached items from storage\n * @param liveItems$ - Observable of live items as they become available\n * @param gracePeriodMs - Time in ms to wait before syncing to live state\n * @param mergeFn - Function to merge live and cached items during hydration\n * @param isConverged - Optional function to check if live items have caught up to cached items\n */\nconst createBufferCore = <T>(\n\tcachedItems: T[],\n\tliveItems$: Observable<T[]>,\n\tgracePeriodMs: number,\n\tmergeFn: (liveItems: T[], cachedItems: T[]) => T[],\n\tisConverged?: (liveItems: T[], cachedItems: T[]) => boolean,\n): Observable<HydrationBufferResult<T>> => {\n\t// If no grace period or no cached items, just pass through live items\n\tif (gracePeriodMs <= 0 || cachedItems.length === 0) {\n\t\treturn liveItems$.pipe(map((items) => ({ items, isHydrating: false })));\n\t}\n\n\t// Wrap in an Observable to properly manage all subscriptions\n\treturn new Observable<HydrationBufferResult<T>>((subscriber) => {\n\t\tconst subscriptions = new Subscription();\n\n\t\t// Track whether we're still in the hydration grace period\n\t\t// Using BehaviorSubject to keep a stateful value that doesn't complete\n\t\tconst isHydrating$ = new BehaviorSubject(true);\n\n\t\t// Use startWith to emit cached items immediately before any live emissions\n\t\tconst liveWithInitial$ = liveItems$.pipe(startWith([] as T[]));\n\n\t\tif (isConverged) {\n\t\t\t// With convergence check: hydration ends when timer fires AND live state has caught up\n\t\t\tconst timerFired$ = timer(gracePeriodMs).pipe(\n\t\t\t\tmap(() => true),\n\t\t\t\tstartWith(false),\n\t\t\t\tshareReplay({ bufferSize: 1, refCount: true }),\n\t\t\t);\n\n\t\t\t// End hydration when timer has fired AND convergence is met\n\t\t\tsubscriptions.add(\n\t\t\t\tcombineLatest([liveWithInitial$, timerFired$])\n\t\t\t\t\t.pipe(\n\t\t\t\t\t\tfilter(([, timerFired]) => timerFired),\n\t\t\t\t\t\tfilter(([liveItems]) => isConverged(liveItems, cachedItems)),\n\t\t\t\t\t\ttake(1),\n\t\t\t\t\t)\n\t\t\t\t\t.subscribe(() => {\n\t\t\t\t\t\tisHydrating$.next(false);\n\t\t\t\t\t}),\n\t\t\t);\n\n\t\t\t// Max timeout (6x grace period) to prevent infinite hydration\n\t\t\t// e.g., if auto-reconnect fails, we still end hydration\n\t\t\tsubscriptions.add(\n\t\t\t\ttimer(gracePeriodMs * 6).subscribe(() => {\n\t\t\t\t\tif (isHydrating$.value) {\n\t\t\t\t\t\tisHydrating$.next(false);\n\t\t\t\t\t}\n\t\t\t\t}),\n\t\t\t);\n\t\t} else {\n\t\t\t// Without convergence check: end hydration on timer only\n\t\t\tsubscriptions.add(\n\t\t\t\ttimer(gracePeriodMs).subscribe(() => {\n\t\t\t\t\tisHydrating$.next(false);\n\t\t\t\t}),\n\t\t\t);\n\t\t}\n\n\t\tsubscriptions.add(\n\t\t\tcombineLatest([liveWithInitial$, isHydrating$])\n\t\t\t\t.pipe(\n\t\t\t\t\tmap(([liveItems, isHydrating]) => {\n\t\t\t\t\t\tif (!isHydrating) {\n\t\t\t\t\t\t\t// Hydration complete - return only live items\n\t\t\t\t\t\t\treturn { items: liveItems, isHydrating: false };\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\titems: mergeFn(liveItems, cachedItems),\n\t\t\t\t\t\t\tisHydrating: true,\n\t\t\t\t\t\t};\n\t\t\t\t\t}),\n\t\t\t\t)\n\t\t\t\t.subscribe(subscriber),\n\t\t);\n\n\t\treturn () => {\n\t\t\tsubscriptions.unsubscribe();\n\t\t\tisHydrating$.complete();\n\t\t};\n\t});\n};\n\n/**\n * Creates a hydration buffer that merges cached items with live items.\n *\n * During hydration, cached items take precedence over live items with the same key.\n * This preserves the cached connected state (e.g., isConnected: true) while\n * auto-reconnect is still in progress. New live items not in the cache are added.\n *\n * @param cachedItems - Initial cached items from storage\n * @param liveItems$ - Observable of live items as they become available\n * @param gracePeriodMs - Time in ms to wait before syncing to live state\n * @param getKey - Function to extract a unique key from an item\n * @param isConverged - Optional function to check if live items have caught up to cached items\n * @param mergeItem - Optional function to merge a live item with its cached counterpart\n * @param transformCachedOnly - Optional function to transform cached items not yet in the live stream\n */\nexport const createHydrationBuffer = <T>(\n\tcachedItems: T[],\n\tliveItems$: Observable<T[]>,\n\tgracePeriodMs: number,\n\tgetKey: (item: T) => string,\n\tisConverged?: (liveItems: T[], cachedItems: T[]) => boolean,\n\tmergeItem?: (liveItem: T, cachedItem: T) => T,\n\ttransformCachedOnly?: (cachedItem: T) => T,\n): Observable<HydrationBufferResult<T>> => {\n\treturn createBufferCore(\n\t\tcachedItems,\n\t\tliveItems$,\n\t\tgracePeriodMs,\n\t\t(liveItems, cached) => {\n\t\t\tconst cachedByKey = new Map(cached.map((item) => [getKey(item), item]));\n\t\t\tconst liveKeys = new Set(liveItems.map(getKey));\n\n\t\t\t// For items in both live and cached, prefer cached (preserves connected state)\n\t\t\t// but allow mergeItem to customize how they're combined\n\t\t\t// For items only in live (newly discovered), use the live version\n\t\t\tconst mergedItems: T[] = liveItems.map((liveItem) => {\n\t\t\t\tconst key = getKey(liveItem);\n\t\t\t\tconst cachedItem = cachedByKey.get(key);\n\t\t\t\tif (!cachedItem) return liveItem;\n\t\t\t\treturn mergeItem ? mergeItem(liveItem, cachedItem) : cachedItem;\n\t\t\t});\n\n\t\t\t// Add cached items not yet in the live stream (e.g., extensions not yet detected)\n\t\t\tfor (const cachedItem of cached) {\n\t\t\t\tif (!liveKeys.has(getKey(cachedItem))) {\n\t\t\t\t\tconst transformed = transformCachedOnly\n\t\t\t\t\t\t? transformCachedOnly(cachedItem)\n\t\t\t\t\t\t: cachedItem;\n\t\t\t\t\tmergedItems.push(transformed);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\treturn mergedItems;\n\t\t},\n\t\tisConverged,\n\t);\n};\n\n/**\n * Creates a hydration buffer specifically for accounts, which need special handling.\n *\n * Accounts are grouped by wallet - when a wallet provides its account list,\n * we replace all cached accounts for that wallet with the live ones.\n * Cached accounts for wallets that haven't provided accounts yet are preserved.\n *\n * @param cachedAccounts - Initial cached accounts from storage\n * @param liveAccounts$ - Observable of live accounts as they become available\n * @param gracePeriodMs - Time in ms to wait before syncing to live state\n * @param getWalletId - Function to extract the wallet ID from an account\n * @param isConverged - Optional function to check if live accounts have caught up to cached accounts\n */\nexport const createAccountHydrationBuffer = <T>(\n\tcachedAccounts: T[],\n\tliveAccounts$: Observable<T[]>,\n\tgracePeriodMs: number,\n\tgetWalletId: (account: T) => string,\n\tisConverged?: (liveAccounts: T[], cachedAccounts: T[]) => boolean,\n): Observable<HydrationBufferResult<T>> => {\n\treturn createBufferCore(\n\t\tcachedAccounts,\n\t\tliveAccounts$,\n\t\tgracePeriodMs,\n\t\t(liveAccounts, cached) => {\n\t\t\tconst walletsWithLiveAccounts = new Set(liveAccounts.map(getWalletId));\n\t\t\tconst mergedAccounts: T[] = [...liveAccounts];\n\n\t\t\tfor (const cachedAccount of cached) {\n\t\t\t\tif (!walletsWithLiveAccounts.has(getWalletId(cachedAccount))) {\n\t\t\t\t\tmergedAccounts.push(cachedAccount);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\treturn mergedAccounts;\n\t\t},\n\t\tisConverged,\n\t);\n};\n","import { type MonoTypeOperatorFunction, tap } from \"rxjs\";\n\ntype Opts = {\n\tprintValue?: boolean;\n\tenabled?: boolean;\n};\n\nexport const logObservable = <T>(\n\tlabel: string,\n\topts?: Opts,\n): MonoTypeOperatorFunction<T> =>\n\ttap((value) => {\n\t\tconst { printValue = false, enabled = true } = opts || {};\n\n\t\tif (!label || !enabled) return;\n\n\t\tconst text = `[kheopskit] observable ${label} emit`;\n\n\t\tif (printValue) console.debug(text, value);\n\t\telse console.debug(text);\n\t});\n","import { combineLatest, map, Observable, of, shareReplay } from \"rxjs\";\nimport { sortAccounts } from \"../utils/sortAccounts\";\nimport type { BaseWallet, BaseWalletAccount, KheopskitConfig } from \"./types\";\n\nexport const getAccounts$ = (\n\tconfig: KheopskitConfig,\n\twallets: Observable<BaseWallet[]>,\n) => {\n\treturn new Observable<BaseWalletAccount[]>((subscriber) => {\n\t\tconst sources = config.platforms.map((plugin) =>\n\t\t\tplugin.getAccounts$(\n\t\t\t\twallets.pipe(\n\t\t\t\t\tmap((ws) => ws.filter((w) => w.platform === plugin.platform)),\n\t\t\t\t),\n\t\t\t),\n\t\t);\n\n\t\tconst accounts$ = sources.length\n\t\t\t? combineLatest(sources).pipe(\n\t\t\t\t\tmap((accounts) => accounts.flat().sort(sortAccounts)),\n\t\t\t\t)\n\t\t\t: of<BaseWalletAccount[]>([]);\n\n\t\tconst sub = accounts$.subscribe(subscriber);\n\n\t\treturn () => {\n\t\t\tsub.unsubscribe();\n\t\t};\n\t}).pipe(shareReplay({ refCount: true, bufferSize: 1 }));\n};\n","import {\n\tcombineLatest,\n\tfilter,\n\tmap,\n\tmergeMap,\n\tObservable,\n\tof,\n\tshareReplay,\n\ttake,\n} from \"rxjs\";\nimport { sortWallets } from \"../utils/sortWallets\";\nimport { store as defaultStore, type KheopskitStore } from \"./store\";\nimport type { BaseWallet, KheopskitConfig, PlatformContext } from \"./types\";\n\nexport const getWallets$ = (\n\tconfig: KheopskitConfig,\n\tstore: KheopskitStore = defaultStore,\n) => {\n\t// lock the list of wallets to auto reconnect on first call\n\tconst autoReconnectWalletIds$ = store.observable.pipe(\n\t\tmap((s) => s.autoReconnect ?? []),\n\t\ttake(1),\n\t\tshareReplay({ bufferSize: 1, refCount: true }),\n\t);\n\n\treturn new Observable<BaseWallet[]>((subscriber) => {\n\t\tconst ctx: PlatformContext = { config, store };\n\t\tconst observables = config.platforms.map((plugin) =>\n\t\t\tplugin.getWallets$(ctx),\n\t\t);\n\n\t\tconst wallets$ = observables.length\n\t\t\t? combineLatest(observables).pipe(\n\t\t\t\t\tmap((wallets) => wallets.flat().sort(sortWallets)),\n\t\t\t\t\t// Note: No startWith([]) here - the hydration buffer handles initial state\n\t\t\t\t)\n\t\t\t: of<BaseWallet[]>([]);\n\n\t\t// Track wallets currently reconnecting (avoid duplicate concurrent attempts)\n\t\t// and those already reconnected (so we don't fight a later manual disconnect).\n\t\t// A failed attempt is left out of `reconnected`, so it can retry when the\n\t\t// wallet next re-emits (e.g. a late-injecting extension).\n\t\tconst reconnectingWallets = new Set<string>();\n\t\tconst reconnectedWallets = new Set<string>();\n\n\t\tconst subAutoReconnect = combineLatest([wallets$, autoReconnectWalletIds$])\n\t\t\t.pipe(\n\t\t\t\tfilter(([, walletIds]) => config.autoReconnect && !!walletIds?.length),\n\t\t\t\tmergeMap(([wallets, walletIds]) =>\n\t\t\t\t\twallets.filter((wallet) => walletIds?.includes(wallet.id)),\n\t\t\t\t),\n\t\t\t)\n\t\t\t.subscribe(async (wallet) => {\n\t\t\t\tif (\n\t\t\t\t\twallet.isConnected ||\n\t\t\t\t\treconnectingWallets.has(wallet.id) ||\n\t\t\t\t\treconnectedWallets.has(wallet.id)\n\t\t\t\t) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\treconnectingWallets.add(wallet.id);\n\t\t\t\ttry {\n\t\t\t\t\tawait wallet.connect();\n\t\t\t\t\treconnectedWallets.add(wallet.id);\n\t\t\t\t} catch (err) {\n\t\t\t\t\tconsole.error(\"Failed to reconnect wallet %s\", wallet.id, { err });\n\t\t\t\t} finally {\n\t\t\t\t\treconnectingWallets.delete(wallet.id);\n\t\t\t\t}\n\t\t\t});\n\n\t\tconst subWallets = wallets$.subscribe(subscriber);\n\n\t\treturn () => {\n\t\t\tsubAutoReconnect.unsubscribe();\n\t\t\tsubWallets.unsubscribe();\n\t\t};\n\t}).pipe(shareReplay({ refCount: true, bufferSize: 1 }));\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA,EACC,iBAAAA;AAAA,EACA;AAAA,EACA;AAAA,EACA,UAAAC;AAAA,EACA,OAAAC;AAAA,EACA,cAAAC;AAAA,EACA,eAAAC;AAAA,EACA;AAAA,OACM;;;ACTP;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACM;AA6BP,IAAM,mBAAmB,CACxB,aACA,YACA,eACA,SACA,gBAC0C;AAE1C,MAAI,iBAAiB,KAAK,YAAY,WAAW,GAAG;AACnD,WAAO,WAAW,KAAK,IAAI,CAAC,WAAW,EAAE,OAAO,aAAa,MAAM,EAAE,CAAC;AAAA,EACvE;AAGA,SAAO,IAAI,WAAqC,CAAC,eAAe;AAC/D,UAAM,gBAAgB,IAAI,aAAa;AAIvC,UAAM,eAAe,IAAI,gBAAgB,IAAI;AAG7C,UAAM,mBAAmB,WAAW,KAAK,UAAU,CAAC,CAAQ,CAAC;AAE7D,QAAI,aAAa;AAEhB,YAAM,cAAc,MAAM,aAAa,EAAE;AAAA,QACxC,IAAI,MAAM,IAAI;AAAA,QACd,UAAU,KAAK;AAAA,QACf,YAAY,EAAE,YAAY,GAAG,UAAU,KAAK,CAAC;AAAA,MAC9C;AAGA,oBAAc;AAAA,QACb,cAAc,CAAC,kBAAkB,WAAW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KAAK;AACJ,aACE,IAA6B,YAC7B,MAA+B;AAAA,IAElC,KAAK;AACJ,aACE,IAA0B,SAAU,MAA4B;AAAA,IAEnE,KAAK;AACJ,aAAO;AAAA,QACL,IAA8B,UAAU,CAAC;AAAA,QACzC,MAAgC,UAAU,CAAC;AAAA,MAC7C;AAAA,IACD;AACC,aAAO;AAAA,EACT;AACD,CAAC;","names":["combineLatest","filter","map","Observable","shareReplay","getWalletId","combineLatest","map","Observable","shareReplay","Observable","map","combineLatest","shareReplay","combineLatest","filter","map","Observable","of","shareReplay","take","store","map","take","shareReplay","Observable","combineLatest","of","filter","store","Observable","shareReplay","combineLatest","map","filter"]}
|
|
1
|
+
{"version":3,"sources":["../src/api/appKit.ts","../src/api/kheopskit.ts","../src/utils/createHydrationBuffer.ts","../src/utils/logObservable.ts","../src/api/accounts.ts","../src/api/wallets.ts"],"sourcesContent":["import {\n\tBehaviorSubject,\n\tdistinctUntilChanged,\n\tfrom,\n\tmap,\n\tObservable,\n\tof,\n\tshareReplay,\n\tswitchMap,\n\ttap,\n} from \"rxjs\";\nimport { clearCachedObservablesByPrefix } from \"../utils/getCachedObservable\";\nimport { WALLET_CONNECT_WALLET_ID } from \"../utils/WalletId\";\nimport type {\n\tAppKitInstance,\n\tKheopskitConfig,\n\tWalletConnectWallet,\n\tWalletPlatform,\n} from \"./types\";\n\n/**\n * Dynamically import @reown/appkit/core to avoid loading browser-only code\n * during SSR or in edge runtimes like Cloudflare Workers.\n * The AppKit library uses Lit for web components which requires document.\n */\nconst loadAppKit = async () => {\n\ttry {\n\t\tconst { createAppKit } = await import(\"@reown/appkit/core\");\n\t\treturn createAppKit;\n\t} catch (cause) {\n\t\tconsole.error(\n\t\t\t\"[kheopskit] WalletConnect is configured but @reown/appkit could not be loaded. \" +\n\t\t\t\t\"Install it with `pnpm add @reown/appkit` (or remove config.walletConnect). \" +\n\t\t\t\t\"WalletConnect wallets are disabled; injected wallets still work.\",\n\t\t\tcause,\n\t\t);\n\t\treturn null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jLTIuMTM5IDIuMDg3LTUuNjA4IDIuMDg3LTcuNzQ4IDBsLTcwLjcwMTUtNjguOTQ1Yy0yLjEzOTYtMi4wODYtMi4xMzk2LTUuNDY5IDAtNy41NTVsMTUuNjc5NS0xNS4yOWMyLjEzOTYtMi4wODYgNS42MDg1LTIuMDg2IDcuNzQ4MSAwbDUwLjE3ODkgNDguOTMyYy41MzUuNTIyIDEuNDAyLjUyMiAxLjkzNyAwbDUwLjE3Ny00OC45MzJjMi4xMzktMi4wODcgNS42MDgtMi4wODcgNy43NDggMGw1MC4xNzkgNDguOTMyYy41MzUuNTIyIDEuNDAyLjUyMiAxLjkzNyAwbDUwLjE3OS00OC45MzFjMi4xMzktMi4wODcgNS42MDgtMi4wODcgNy43NDggMHoiIGZpbGw9IiNmZmYiLz48L2c+PC9zdmc+\";\n\n// Once it exists, the appKit object should never be recreated. Anchored on\n// globalThis so it stays a single instance even if this module is duplicated\n// across bundle chunks (e.g. CJS subpath entries).\nconst APPKIT_SYMBOL = Symbol.for(\"kheopskit.cachedAppKit\");\n// The projectId AppKit was first initialised with. AppKit is a process-wide\n// singleton, so a later call with a different WalletConnect config is silently\n// ignored — we keep this to warn loudly instead of letting it pass unnoticed.\nconst APPKIT_PROJECT_ID_SYMBOL = Symbol.for(\"kheopskit.cachedAppKitProjectId\");\ntype AppKitGlobal = Record<\n\tsymbol,\n\tObservable<WalletConnectWallet | null> | string | undefined\n>;\nconst getCachedAppKit = ():\n\t| Observable<WalletConnectWallet | null>\n\t| undefined =>\n\t(globalThis as unknown as AppKitGlobal)[APPKIT_SYMBOL] as\n\t\t| Observable<WalletConnectWallet | null>\n\t\t| undefined;\nconst getCachedAppKitProjectId = (): string | undefined =>\n\t(globalThis as unknown as AppKitGlobal)[APPKIT_PROJECT_ID_SYMBOL] as\n\t\t| string\n\t\t| undefined;\nconst setCachedAppKit = (\n\tvalue: Observable<WalletConnectWallet | null> | undefined,\n\tprojectId?: string,\n): void => {\n\t(globalThis as unknown as AppKitGlobal)[APPKIT_SYMBOL] = value;\n\t(globalThis as unknown as AppKitGlobal)[APPKIT_PROJECT_ID_SYMBOL] = projectId;\n};\n\n/**\n * Clears the cached AppKit observable.\n * Use when configuration changes or for testing purposes.\n * Note: This does NOT destroy the appKit instance created by Reown.\n */\nexport const resetAppKitCache = (): void => {\n\tsetCachedAppKit(undefined);\n};\n\n/**\n * Drops a WalletConnect namespace's cached account observables. Called when a\n * namespace transitions to disconnected — including external disconnects (from\n * the wallet app), which flip status via `subscribeProviders` without ever\n * calling `disconnect()` — so a later reconnect rebuilds the account observables\n * against the fresh session instead of a stale closure.\n *\n * Keys are `accounts:<walletId>:...`; the trailing colon scopes the prefix to\n * this wallet and avoids matching a sibling whose id is a string prefix.\n */\nconst dropAccountsCache = (platform: WalletPlatform): void => {\n\tclearCachedObservablesByPrefix(\n\t\t`accounts:${WALLET_CONNECT_WALLET_ID}:${platform}:`,\n\t);\n};\n\n/**\n * The single, platform-less WalletConnect connector for the given config — or\n * `null` when WalletConnect isn't configured, on the server, or when\n * `@reown/appkit` isn't installed.\n *\n * @remarks\n * The AppKit instance is a process-wide singleton (Reown AppKit itself cannot\n * be instantiated twice). The **first** call with a `walletConnect` config wins;\n * later calls with a *different* `walletConnect` config reuse that first\n * instance. Call {@link resetAppKitCache} before re-initialising if the\n * WalletConnect config must change.\n *\n * One WalletConnect session is shared across every namespace, and a namespace\n * can only be established during the initial pairing — it can't be added to a\n * live session afterwards. So this exposes ONE connector (not one per platform):\n * `connect()` opens the modal; the wallet approves whichever namespaces it\n * supports in that single pairing, and `platforms` reflects what the live\n * session carries. Per-namespace accounts are derived by each platform plugin.\n */\nexport const getWalletConnectWallet$ = (\n\tconfig: KheopskitConfig,\n): Observable<WalletConnectWallet | null> => {\n\tif (!config.walletConnect) return of(null);\n\n\t// SSR guard - don't try to load AppKit on the server\n\tif (typeof window === \"undefined\") return of(null);\n\n\tconst walletConnect = config.walletConnect;\n\n\tconst cachedProjectId = getCachedAppKitProjectId();\n\tif (\n\t\tcachedProjectId !== undefined &&\n\t\tcachedProjectId !== walletConnect.projectId\n\t) {\n\t\tconsole.warn(\n\t\t\t\"[kheopskit] WalletConnect is already initialised with projectId %s; \" +\n\t\t\t\t\"AppKit is a process-wide singleton, so the first configuration wins and \" +\n\t\t\t\t\"projectId %s is ignored. Call resetAppKitCache() before re-initialising \" +\n\t\t\t\t\"if the WalletConnect config must change.\",\n\t\t\tcachedProjectId,\n\t\t\twalletConnect.projectId,\n\t\t);\n\t}\n\n\tlet cachedAppKit = getCachedAppKit();\n\tif (!cachedAppKit) {\n\t\t// Dynamic import avoids loading @reown/appkit at module-eval time (SSR /\n\t\t// edge runtimes like Cloudflare Workers).\n\t\tcachedAppKit = from(loadAppKit()).pipe(\n\t\t\tswitchMap((createAppKit) => {\n\t\t\t\t// @reown/appkit missing (optional peer dep) — degrade gracefully.\n\t\t\t\tif (!createAppKit) return of<WalletConnectWallet | null>(null);\n\t\t\t\treturn new Observable<WalletConnectWallet | null>((subscriber) => {\n\t\t\t\t\tconst appKit = createAppKit({\n\t\t\t\t\t\tprojectId: walletConnect.projectId,\n\t\t\t\t\t\tmetadata: walletConnect.metadata,\n\t\t\t\t\t\t// Loosely typed in WalletConnectConfig to keep @reown/appkit's\n\t\t\t\t\t\t// types out of core; forwarded to AppKit verbatim.\n\t\t\t\t\t\tnetworks: walletConnect.networks as never,\n\t\t\t\t\t\tthemeMode: walletConnect.themeMode,\n\t\t\t\t\t\tthemeVariables: walletConnect.themeVariables as never,\n\t\t\t\t\t\tuniversalProviderConfigOverride: {\n\t\t\t\t\t\t\tmethods: {\n\t\t\t\t\t\t\t\tpolkadot: [\"polkadot_signTransaction\", \"polkadot_signMessage\"],\n\t\t\t\t\t\t\t\tsolana: [\n\t\t\t\t\t\t\t\t\t\"solana_signTransaction\",\n\t\t\t\t\t\t\t\t\t\"solana_signMessage\",\n\t\t\t\t\t\t\t\t\t\"solana_signAndSendTransaction\",\n\t\t\t\t\t\t\t\t],\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t},\n\t\t\t\t\t\tallWallets: \"HIDE\",\n\t\t\t\t\t\tdebug: config.debug,\n\t\t\t\t\t\tallowUnsupportedChain: true,\n\t\t\t\t\t});\n\n\t\t\t\t\t// Exposed on the wallet as the (decoupled) AppKitInstance escape hatch.\n\t\t\t\t\tconst appKitInstance = appKit as unknown as AppKitInstance;\n\n\t\t\t\t\tconst status$ = new BehaviorSubject({\n\t\t\t\t\t\tisPolkadotConnected: false,\n\t\t\t\t\t\tisEthereumConnected: false,\n\t\t\t\t\t\tisSolanaConnected: false,\n\t\t\t\t\t});\n\n\t\t\t\t\tconst unsubProviders = appKit.subscribeProviders((providers) => {\n\t\t\t\t\t\tstatus$.next({\n\t\t\t\t\t\t\tisPolkadotConnected: !!providers.polkadot,\n\t\t\t\t\t\t\tisEthereumConnected: !!providers.eip155,\n\t\t\t\t\t\t\tisSolanaConnected: !!providers.solana,\n\t\t\t\t\t\t});\n\t\t\t\t\t});\n\n\t\t\t\t\tconst namespaceOf: Record<WalletPlatform, string> = {\n\t\t\t\t\t\tpolkadot: \"polkadot\",\n\t\t\t\t\t\tethereum: \"eip155\",\n\t\t\t\t\t\tsolana: \"solana\",\n\t\t\t\t\t};\n\t\t\t\t\tconst allPlatforms: WalletPlatform[] = [\n\t\t\t\t\t\t\"polkadot\",\n\t\t\t\t\t\t\"ethereum\",\n\t\t\t\t\t\t\"solana\",\n\t\t\t\t\t];\n\t\t\t\t\tconst enabledPlatforms = allPlatforms.filter((p) =>\n\t\t\t\t\t\t(appKit.chainNamespaces as string[]).includes(namespaceOf[p]),\n\t\t\t\t\t);\n\n\t\t\t\t\tlet prevConnected = {\n\t\t\t\t\t\tpolkadot: false,\n\t\t\t\t\t\tethereum: false,\n\t\t\t\t\t\tsolana: false,\n\t\t\t\t\t};\n\n\t\t\t\t\tconst sub = status$\n\t\t\t\t\t\t.pipe(\n\t\t\t\t\t\t\tmap((s) => ({\n\t\t\t\t\t\t\t\tpolkadot: s.isPolkadotConnected,\n\t\t\t\t\t\t\t\tethereum: s.isEthereumConnected,\n\t\t\t\t\t\t\t\tsolana: s.isSolanaConnected,\n\t\t\t\t\t\t\t})),\n\t\t\t\t\t\t\tdistinctUntilChanged(\n\t\t\t\t\t\t\t\t(a, b) =>\n\t\t\t\t\t\t\t\t\ta.polkadot === b.polkadot &&\n\t\t\t\t\t\t\t\t\ta.ethereum === b.ethereum &&\n\t\t\t\t\t\t\t\t\ta.solana === b.solana,\n\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\ttap((connected) => {\n\t\t\t\t\t\t\t\t// Drop caches for namespaces that just went disconnected.\n\t\t\t\t\t\t\t\tfor (const platform of allPlatforms)\n\t\t\t\t\t\t\t\t\tif (prevConnected[platform] && !connected[platform])\n\t\t\t\t\t\t\t\t\t\tdropAccountsCache(platform);\n\t\t\t\t\t\t\t\tprevConnected = connected;\n\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t\tmap((connected): WalletConnectWallet => {\n\t\t\t\t\t\t\t\tconst platforms = enabledPlatforms.filter((p) => connected[p]);\n\t\t\t\t\t\t\t\tconst isConnected = platforms.length > 0;\n\t\t\t\t\t\t\t\tconst walletInfo = appKit.getWalletInfo();\n\t\t\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t\t\tid: WALLET_CONNECT_WALLET_ID,\n\t\t\t\t\t\t\t\t\ttype: \"walletconnect\",\n\t\t\t\t\t\t\t\t\tplatforms,\n\t\t\t\t\t\t\t\t\tappKit: appKitInstance,\n\t\t\t\t\t\t\t\t\tname: walletInfo?.name ?? \"WalletConnect\",\n\t\t\t\t\t\t\t\t\ticon: walletInfo?.icon ?? WALLET_CONNECT_ICON,\n\t\t\t\t\t\t\t\t\t// One shared session: connecting opens the modal; the wallet\n\t\t\t\t\t\t\t\t\t// approves namespaces in that single pairing. Disconnect is\n\t\t\t\t\t\t\t\t\t// session-wide; re-pair to change the approved set.\n\t\t\t\t\t\t\t\t\tconnect: async () => {\n\t\t\t\t\t\t\t\t\t\tif (!isConnected) await appKit.open();\n\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\tdisconnect: async () => {\n\t\t\t\t\t\t\t\t\t\tif (isConnected) await appKit.disconnect();\n\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\tisConnected,\n\t\t\t\t\t\t\t\t};\n\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t)\n\t\t\t\t\t\t.subscribe(subscriber);\n\n\t\t\t\t\treturn () => {\n\t\t\t\t\t\tsub.unsubscribe();\n\t\t\t\t\t\tunsubProviders();\n\t\t\t\t\t};\n\t\t\t\t});\n\t\t\t}),\n\t\t\t// refCount:false keeps the AppKit instance alive for the process lifetime\n\t\t\t// once created: createAppKit runs at most once (Reown AppKit cannot be\n\t\t\t// instantiated twice). With refCount:true the producer would re-run\n\t\t\t// createAppKit whenever every subscriber drained and a new one\n\t\t\t// re-subscribed — e.g. a React unmount/remount or StrictMode's\n\t\t\t// mount→unmount→remount — throwing on the duplicate Lit web components and\n\t\t\t// WalletConnect modal singleton. The replayed connector value also keeps\n\t\t\t// the wallet list stable across such teardown/rebuild cycles.\n\t\t\tshareReplay({ refCount: false, bufferSize: 1 }),\n\t\t);\n\t\tsetCachedAppKit(cachedAppKit, walletConnect.projectId);\n\t}\n\n\treturn cachedAppKit;\n};\n","import {\n\tcombineLatest,\n\tdebounceTime,\n\tdistinctUntilChanged,\n\tfilter,\n\tmap,\n\tObservable,\n\tshareReplay,\n\tthrottleTime,\n} from \"rxjs\";\nimport {\n\tcreateAccountHydrationBuffer,\n\tcreateHydrationBuffer,\n} from \"../utils/createHydrationBuffer\";\nimport {\n\thydrateAccount,\n\thydrateWallet,\n\tserializeAccount,\n\tserializeWallet,\n} from \"../utils/hydrateState\";\nimport { getCachedIcon, setCachedIcons } from \"../utils/iconCache\";\nimport { logObservable } from \"../utils/logObservable\";\nimport { sortAccounts } from \"../utils/sortAccounts\";\nimport { sortWallets } from \"../utils/sortWallets\";\nimport { getAccounts$ } from \"./accounts\";\nimport { resolveConfig } from \"./config\";\nimport { acceptsCachedAccount } from \"./platform\";\nimport { createKheopskitStore } from \"./store\";\nimport type {\n\tBaseWallet,\n\tBaseWalletAccount,\n\tKheopskitConfig,\n\tKheopskitPlatform,\n\tKheopskitState,\n\tWalletConnectWallet,\n} from \"./types\";\nimport { isWalletConnectWallet } from \"./types\";\nimport { getWallets$ } from \"./wallets\";\n\nexport type { KheopskitConfig, KheopskitState } from \"./types\";\n\n/** Options for {@link getKheopskit$}. */\nexport type GetKheopskitOptions = {\n\t/**\n\t * Cookie string for SSR hydration. When provided, state is read from cookies\n\t * instead of localStorage so the server can hydrate without a flash. Pass the\n\t * request's `cookie` header.\n\t */\n\tssrCookies?: string;\n\t/**\n\t * An existing store to reuse instead of creating one. Advanced escape hatch —\n\t * most callers omit it. (`@kheopskit/react` passes its provider-scoped store.)\n\t */\n\tstore?: ReturnType<typeof createKheopskitStore>;\n};\n\nexport const getKheopskit$ = <\n\tconst P extends readonly KheopskitPlatform[] = readonly KheopskitPlatform[],\n>(\n\tconfig?: Partial<KheopskitConfig<P>>,\n\toptions: GetKheopskitOptions = {},\n): Observable<KheopskitState<P>> => {\n\tconst { ssrCookies, store: existingStore } = options;\n\tconst kc = resolveConfig(config);\n\tconst store =\n\t\texistingStore ??\n\t\tcreateKheopskitStore({ ssrCookies, storageKey: kc.storageKey });\n\n\tif (kc.debug) console.debug(\"[kheopskit] config\", kc);\n\n\t// Warn about SSR environment without cookies\n\tif (kc.debug && typeof window === \"undefined\" && ssrCookies === undefined) {\n\t\tconsole.warn(\n\t\t\t\"[kheopskit] Running on server without `ssrCookies`. \" +\n\t\t\t\t\"Wallet state will not be hydrated. Pass cookies for SSR support.\",\n\t\t);\n\t}\n\n\t// Get cached state for hydration\n\tconst cachedState = store.getCachedState();\n\t// Hydrate wallets and enrich with icons from localStorage cache\n\tconst cachedWallets = cachedState.wallets.map((w) => {\n\t\tconst wallet = hydrateWallet(w);\n\t\t// If wallet doesn't have icon (e.g., Ethereum), try localStorage cache\n\t\tif (!wallet.icon) {\n\t\t\tconst cachedIcon = getCachedIcon(wallet.id);\n\t\t\tif (cachedIcon) {\n\t\t\t\treturn { ...wallet, icon: cachedIcon };\n\t\t\t}\n\t\t}\n\t\treturn wallet;\n\t});\n\tconst cachedAccounts = cachedState.accounts\n\t\t.filter((cached) => acceptsCachedAccount(cached, kc.platforms))\n\t\t.map(hydrateAccount);\n\n\tif (kc.debug && cachedWallets.length > 0) {\n\t\tconsole.debug(\"[kheopskit] hydrating from cache:\", {\n\t\t\twallets: cachedWallets.length,\n\t\t\taccounts: cachedAccounts.length,\n\t\t});\n\t}\n\n\treturn new Observable<KheopskitState>((subscriber) => {\n\t\t// Get live wallets and accounts\n\t\tconst liveWallets$ = getWallets$(kc, store);\n\t\tconst liveAccounts$ = getAccounts$(kc, liveWallets$);\n\n\t\t// Apply hydration buffer to wallets\n\t\tconst bufferedWallets$ = createHydrationBuffer(\n\t\t\tcachedWallets,\n\t\t\tliveWallets$,\n\t\t\tkc.hydrationGracePeriod,\n\t\t\t(w) => w.id,\n\t\t\t// Hydration converges when all cached-connected wallets are connected in live\n\t\t\t(liveWallets, cached) => {\n\t\t\t\tconst cachedConnectedIds = new Set(\n\t\t\t\t\tcached.filter((w) => w.isConnected).map((w) => w.id),\n\t\t\t\t);\n\t\t\t\tif (cachedConnectedIds.size === 0) return true;\n\t\t\t\treturn [...cachedConnectedIds].every((id) =>\n\t\t\t\t\tliveWallets.some((w) => w.id === id && w.isConnected),\n\t\t\t\t);\n\t\t\t},\n\t\t\t// Merge: prefer cached isConnected state but get icon from cache or live\n\t\t\t(live, cached) => ({\n\t\t\t\t...cached,\n\t\t\t\t// Priority: cached icon > localStorage cache > live icon\n\t\t\t\ticon: cached.icon || getCachedIcon(cached.id) || live.icon,\n\t\t\t\t// Use live wallet's connect/disconnect functions\n\t\t\t\tconnect: live.connect,\n\t\t\t\tdisconnect: live.disconnect,\n\t\t\t}),\n\t\t\t// Transform cached-only items: add icon from localStorage cache\n\t\t\t(cached) => ({\n\t\t\t\t...cached,\n\t\t\t\ticon: cached.icon || getCachedIcon(cached.id) || \"\",\n\t\t\t}),\n\t\t);\n\n\t\t// Apply hydration buffer to accounts\n\t\tconst bufferedAccounts$ = createAccountHydrationBuffer(\n\t\t\tcachedAccounts,\n\t\t\tliveAccounts$,\n\t\t\tkc.hydrationGracePeriod,\n\t\t\t(a) => a.walletId,\n\t\t\t// Hydration converges when all wallets with cached accounts have provided live accounts\n\t\t\t(liveAccounts, cached) => {\n\t\t\t\tconst cachedWalletIds = new Set(cached.map((a) => a.walletId));\n\t\t\t\tif (cachedWalletIds.size === 0) return true;\n\t\t\t\tconst liveWalletIds = new Set(liveAccounts.map((a) => a.walletId));\n\t\t\t\treturn [...cachedWalletIds].every((id) => liveWalletIds.has(id));\n\t\t\t},\n\t\t);\n\n\t\t// Share the buffered streams so the main and persistence subscriptions\n\t\t// below reuse a single hydration pipeline (timers, isHydrating state)\n\t\t// instead of running the buffering twice.\n\t\tconst sharedWallets$ = bufferedWallets$.pipe(\n\t\t\tshareReplay({ bufferSize: 1, refCount: true }),\n\t\t);\n\t\tconst sharedAccounts$ = bufferedAccounts$.pipe(\n\t\t\tshareReplay({ bufferSize: 1, refCount: true }),\n\t\t);\n\n\t\t// Combine buffered wallets and accounts\n\t\tconst subscription = combineLatest({\n\t\t\twallets: sharedWallets$,\n\t\t\taccounts: sharedAccounts$,\n\t\t})\n\t\t\t.pipe(\n\t\t\t\tmap(({ wallets, accounts }) => {\n\t\t\t\t\tif (kc.debug) {\n\t\t\t\t\t\tconsole.debug(\"[kheopskit] hydration state\", {\n\t\t\t\t\t\t\twalletsHydrating: wallets.isHydrating,\n\t\t\t\t\t\t\taccountsHydrating: accounts.isHydrating,\n\t\t\t\t\t\t\twalletsConnected: wallets.items.filter((w) => w.isConnected)\n\t\t\t\t\t\t\t\t.length,\n\t\t\t\t\t\t\twalletsTotal: wallets.items.length,\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\t\t\t\t\t// Sort on every emission with the same comparators used for the\n\t\t\t\t\t// cached initial snapshot. The hydration buffers append cached-only\n\t\t\t\t\t// items after live ones (and reconnects land out of order), so\n\t\t\t\t\t// without this the list visibly reorders as wallets come back.\n\t\t\t\t\treturn {\n\t\t\t\t\t\tconfig: kc,\n\t\t\t\t\t\twallets: [...wallets.items].sort(sortWallets),\n\t\t\t\t\t\taccounts: [...accounts.items].sort(sortAccounts),\n\t\t\t\t\t\tisHydrating: wallets.isHydrating || accounts.isHydrating,\n\t\t\t\t\t};\n\t\t\t\t}),\n\t\t\t)\n\t\t\t.subscribe(subscriber);\n\n\t\t// Persist state snapshot when hydration completes and state stabilizes\n\t\tconst persistSub = combineLatest({\n\t\t\twallets: sharedWallets$,\n\t\t\taccounts: sharedAccounts$,\n\t\t})\n\t\t\t.pipe(\n\t\t\t\t// Wait for hydration to complete\n\t\t\t\tfilter(\n\t\t\t\t\t({ wallets, accounts }) =>\n\t\t\t\t\t\t!wallets.isHydrating && !accounts.isHydrating,\n\t\t\t\t),\n\t\t\t\t// Debounce to avoid excessive writes\n\t\t\t\tdebounceTime(1000),\n\t\t\t\t// Only persist if the serialized snapshot would actually change.\n\t\t\t\t// Compare the persisted fields (not just ids): an Ethereum chain switch\n\t\t\t\t// keeps the same account id but changes the cached chainId, so an\n\t\t\t\t// id-only comparator would skip persisting it.\n\t\t\t\tdistinctUntilChanged((prev, curr) => {\n\t\t\t\t\tconst prevWalletKeys = prev.wallets.items.map(walletPersistKey);\n\t\t\t\t\tconst currWalletKeys = curr.wallets.items.map(walletPersistKey);\n\t\t\t\t\tconst prevAccountKeys = prev.accounts.items.map(accountChangeKey);\n\t\t\t\t\tconst currAccountKeys = curr.accounts.items.map(accountChangeKey);\n\t\t\t\t\treturn (\n\t\t\t\t\t\tarraysEqual(prevWalletKeys, currWalletKeys) &&\n\t\t\t\t\t\tarraysEqual(prevAccountKeys, currAccountKeys)\n\t\t\t\t\t);\n\t\t\t\t}),\n\t\t\t)\n\t\t\t.subscribe(({ wallets, accounts }) => {\n\t\t\t\t// Cache ALL wallets to avoid wallet list flash on reload\n\t\t\t\t// Only accounts from connected wallets are cached\n\t\t\t\tconst connectedWalletIds = new Set(\n\t\t\t\t\twallets.items.filter((w) => w.isConnected).map((w) => w.id),\n\t\t\t\t);\n\t\t\t\tconst relevantAccounts = accounts.items.filter((a) =>\n\t\t\t\t\tconnectedWalletIds.has(a.walletId),\n\t\t\t\t);\n\n\t\t\t\tif (kc.debug) {\n\t\t\t\t\tconsole.debug(\"[kheopskit] persisting state snapshot:\", {\n\t\t\t\t\t\twallets: wallets.items.length,\n\t\t\t\t\t\taccounts: relevantAccounts.length,\n\t\t\t\t\t});\n\t\t\t\t}\n\n\t\t\t\tstore.setCachedState(\n\t\t\t\t\twallets.items.map(serializeWallet),\n\t\t\t\t\trelevantAccounts.map(serializeAccount),\n\t\t\t\t);\n\n\t\t\t\t// Cache wallet icons in localStorage (separate from cookies for size)\n\t\t\t\tconst icons: Record<string, string> = {};\n\t\t\t\tfor (const wallet of wallets.items) {\n\t\t\t\t\tif (wallet.icon) {\n\t\t\t\t\t\ticons[wallet.id] = wallet.icon;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tsetCachedIcons(icons);\n\t\t\t});\n\n\t\treturn () => {\n\t\t\tsubscription.unsubscribe();\n\t\t\tpersistSub.unsubscribe();\n\t\t};\n\t}).pipe(\n\t\tdistinctUntilChanged(statesEqual),\n\t\tthrottleTime(16, undefined, { leading: true, trailing: true }), // ~1 frame at 60fps\n\t\tlogObservable(\"kheopskit$\", { enabled: kc.debug, printValue: true }),\n\t\tshareReplay({ bufferSize: 1, refCount: true }),\n\t\t// The runtime objects are the concrete per-plugin wallet/account types;\n\t\t// recover the precise KheopskitState<P> the caller's plugins imply.\n\t) as unknown as Observable<KheopskitState<P>>;\n};\n\nconst arraysEqual = (a: string[], b: string[]) =>\n\ta.length === b.length && a.every((v, i) => v === b[i]);\n\n// Mutable per-platform account fields that can change without the account id\n// changing. Declared locally (not imported from the platform packages) so this\n// core entry stays free of platform SDK types — see check:isolation.\ntype EthereumAccountFields = { chainId?: number };\ntype PolkadotAccountFields = { type?: string };\ntype SolanaAccountFields = { chains?: string[] };\n\n/**\n * A signature of an account covering its id plus the platform-specific fields\n * that can change without the id changing (Ethereum chainId, Polkadot key type,\n * Solana clusters). Used to detect both UI-relevant changes and changes worth\n * re-persisting, so the two comparators can't drift apart.\n */\nconst accountChangeKey = (account: BaseWalletAccount): string => {\n\tswitch (account.platform) {\n\t\tcase \"ethereum\":\n\t\t\treturn `${account.id}|${(account as EthereumAccountFields).chainId ?? \"\"}`;\n\t\tcase \"polkadot\":\n\t\t\treturn `${account.id}|${(account as PolkadotAccountFields).type ?? \"\"}`;\n\t\tcase \"solana\":\n\t\t\treturn `${account.id}|${((account as SolanaAccountFields).chains ?? []).join(\",\")}`;\n\t\tdefault:\n\t\t\treturn account.id;\n\t}\n};\n\n/** Platforms a wallet's live session carries (only the WalletConnect connector). */\nconst walletPlatforms = (wallet: BaseWallet | WalletConnectWallet): string =>\n\tisWalletConnectWallet(wallet) ? wallet.platforms.join(\",\") : \"\";\n\n/** Fields persisted to the cache for a wallet (icon is stored separately). */\nconst walletPersistKey = (wallet: BaseWallet | WalletConnectWallet): string =>\n\t`${wallet.id}|${wallet.isConnected ? 1 : 0}|${wallet.name}`;\n\n/**\n * UI-significant signature of a wallet: the persisted fields plus icon and the\n * WalletConnect connector's `platforms` array, which drive what the UI shows but\n * aren't part of the id (icon and platforms can arrive asynchronously after\n * connect without isConnected flipping).\n */\nconst walletUiKey = (wallet: BaseWallet | WalletConnectWallet): string =>\n\t`${walletPersistKey(wallet)}|${wallet.icon}|${walletPlatforms(wallet)}`;\n\n/**\n * Equality check for KheopskitState to prevent unnecessary emissions. Compares\n * the UI-significant signature of every wallet and account, in order.\n */\nconst statesEqual = (a: KheopskitState, b: KheopskitState): boolean =>\n\ta.isHydrating === b.isHydrating &&\n\ta.wallets.length === b.wallets.length &&\n\ta.accounts.length === b.accounts.length &&\n\ta.wallets.every((w, i) => {\n\t\tconst other = b.wallets[i];\n\t\treturn !!other && walletUiKey(w) === walletUiKey(other);\n\t}) &&\n\ta.accounts.every((acc, i) => {\n\t\tconst other = b.accounts[i];\n\t\treturn !!other && accountChangeKey(acc) === accountChangeKey(other);\n\t});\n","import {\n\tBehaviorSubject,\n\tcombineLatest,\n\tfilter,\n\tmap,\n\tObservable,\n\tSubscription,\n\tshareReplay,\n\tstartWith,\n\ttake,\n\ttimer,\n} from \"rxjs\";\n\ntype HydrationBufferResult<T> = {\n\titems: T[];\n\tisHydrating: boolean;\n};\n\n/**\n * Core hydration buffer logic shared between wallets and accounts.\n *\n * During the grace period:\n * - Emits cached items immediately (before any live emissions)\n * - As live items arrive, merges them using the provided merge function\n *\n * After the grace period (and convergence, if provided):\n * - Only live items are returned\n * - isHydrating becomes false\n *\n * If an `isConverged` function is provided, hydration ends only when BOTH\n * the grace period has elapsed AND the live items have converged with cached\n * items (e.g., all previously-connected wallets have reconnected).\n * A max timeout (6x grace period) prevents infinite hydration.\n *\n * @param cachedItems - Initial cached items from storage\n * @param liveItems$ - Observable of live items as they become available\n * @param gracePeriodMs - Time in ms to wait before syncing to live state\n * @param mergeFn - Function to merge live and cached items during hydration\n * @param isConverged - Optional function to check if live items have caught up to cached items\n */\nconst createBufferCore = <T>(\n\tcachedItems: T[],\n\tliveItems$: Observable<T[]>,\n\tgracePeriodMs: number,\n\tmergeFn: (liveItems: T[], cachedItems: T[]) => T[],\n\tisConverged?: (liveItems: T[], cachedItems: T[]) => boolean,\n): Observable<HydrationBufferResult<T>> => {\n\t// If no grace period or no cached items, just pass through live items\n\tif (gracePeriodMs <= 0 || cachedItems.length === 0) {\n\t\treturn liveItems$.pipe(map((items) => ({ items, isHydrating: false })));\n\t}\n\n\t// Wrap in an Observable to properly manage all subscriptions\n\treturn new Observable<HydrationBufferResult<T>>((subscriber) => {\n\t\tconst subscriptions = new Subscription();\n\n\t\t// Track whether we're still in the hydration grace period\n\t\t// Using BehaviorSubject to keep a stateful value that doesn't complete\n\t\tconst isHydrating$ = new BehaviorSubject(true);\n\n\t\t// Use startWith to emit cached items immediately before any live emissions\n\t\tconst liveWithInitial$ = liveItems$.pipe(startWith([] as T[]));\n\n\t\tif (isConverged) {\n\t\t\t// With convergence check: hydration ends when timer fires AND live state has caught up\n\t\t\tconst timerFired$ = timer(gracePeriodMs).pipe(\n\t\t\t\tmap(() => true),\n\t\t\t\tstartWith(false),\n\t\t\t\tshareReplay({ bufferSize: 1, refCount: true }),\n\t\t\t);\n\n\t\t\t// End hydration when timer has fired AND convergence is met\n\t\t\tsubscriptions.add(\n\t\t\t\tcombineLatest([liveWithInitial$, timerFired$])\n\t\t\t\t\t.pipe(\n\t\t\t\t\t\tfilter(([, timerFired]) => timerFired),\n\t\t\t\t\t\tfilter(([liveItems]) => isConverged(liveItems, cachedItems)),\n\t\t\t\t\t\ttake(1),\n\t\t\t\t\t)\n\t\t\t\t\t.subscribe(() => {\n\t\t\t\t\t\tisHydrating$.next(false);\n\t\t\t\t\t}),\n\t\t\t);\n\n\t\t\t// Max timeout (6x grace period) to prevent infinite hydration\n\t\t\t// e.g., if auto-reconnect fails, we still end hydration\n\t\t\tsubscriptions.add(\n\t\t\t\ttimer(gracePeriodMs * 6).subscribe(() => {\n\t\t\t\t\tif (isHydrating$.value) {\n\t\t\t\t\t\tisHydrating$.next(false);\n\t\t\t\t\t}\n\t\t\t\t}),\n\t\t\t);\n\t\t} else {\n\t\t\t// Without convergence check: end hydration on timer only\n\t\t\tsubscriptions.add(\n\t\t\t\ttimer(gracePeriodMs).subscribe(() => {\n\t\t\t\t\tisHydrating$.next(false);\n\t\t\t\t}),\n\t\t\t);\n\t\t}\n\n\t\tsubscriptions.add(\n\t\t\tcombineLatest([liveWithInitial$, isHydrating$])\n\t\t\t\t.pipe(\n\t\t\t\t\tmap(([liveItems, isHydrating]) => {\n\t\t\t\t\t\tif (!isHydrating) {\n\t\t\t\t\t\t\t// Hydration complete - return only live items\n\t\t\t\t\t\t\treturn { items: liveItems, isHydrating: false };\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\titems: mergeFn(liveItems, cachedItems),\n\t\t\t\t\t\t\tisHydrating: true,\n\t\t\t\t\t\t};\n\t\t\t\t\t}),\n\t\t\t\t)\n\t\t\t\t.subscribe(subscriber),\n\t\t);\n\n\t\treturn () => {\n\t\t\tsubscriptions.unsubscribe();\n\t\t\tisHydrating$.complete();\n\t\t};\n\t});\n};\n\n/**\n * Creates a hydration buffer that merges cached items with live items.\n *\n * During hydration, cached items take precedence over live items with the same key.\n * This preserves the cached connected state (e.g., isConnected: true) while\n * auto-reconnect is still in progress. New live items not in the cache are added.\n *\n * @param cachedItems - Initial cached items from storage\n * @param liveItems$ - Observable of live items as they become available\n * @param gracePeriodMs - Time in ms to wait before syncing to live state\n * @param getKey - Function to extract a unique key from an item\n * @param isConverged - Optional function to check if live items have caught up to cached items\n * @param mergeItem - Optional function to merge a live item with its cached counterpart\n * @param transformCachedOnly - Optional function to transform cached items not yet in the live stream\n */\nexport const createHydrationBuffer = <T>(\n\tcachedItems: T[],\n\tliveItems$: Observable<T[]>,\n\tgracePeriodMs: number,\n\tgetKey: (item: T) => string,\n\tisConverged?: (liveItems: T[], cachedItems: T[]) => boolean,\n\tmergeItem?: (liveItem: T, cachedItem: T) => T,\n\ttransformCachedOnly?: (cachedItem: T) => T,\n): Observable<HydrationBufferResult<T>> => {\n\treturn createBufferCore(\n\t\tcachedItems,\n\t\tliveItems$,\n\t\tgracePeriodMs,\n\t\t(liveItems, cached) => {\n\t\t\tconst cachedByKey = new Map(cached.map((item) => [getKey(item), item]));\n\t\t\tconst liveKeys = new Set(liveItems.map(getKey));\n\n\t\t\t// For items in both live and cached, prefer cached (preserves connected state)\n\t\t\t// but allow mergeItem to customize how they're combined\n\t\t\t// For items only in live (newly discovered), use the live version\n\t\t\tconst mergedItems: T[] = liveItems.map((liveItem) => {\n\t\t\t\tconst key = getKey(liveItem);\n\t\t\t\tconst cachedItem = cachedByKey.get(key);\n\t\t\t\tif (!cachedItem) return liveItem;\n\t\t\t\treturn mergeItem ? mergeItem(liveItem, cachedItem) : cachedItem;\n\t\t\t});\n\n\t\t\t// Add cached items not yet in the live stream (e.g., extensions not yet detected)\n\t\t\tfor (const cachedItem of cached) {\n\t\t\t\tif (!liveKeys.has(getKey(cachedItem))) {\n\t\t\t\t\tconst transformed = transformCachedOnly\n\t\t\t\t\t\t? transformCachedOnly(cachedItem)\n\t\t\t\t\t\t: cachedItem;\n\t\t\t\t\tmergedItems.push(transformed);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\treturn mergedItems;\n\t\t},\n\t\tisConverged,\n\t);\n};\n\n/**\n * Creates a hydration buffer specifically for accounts, which need special handling.\n *\n * Accounts are grouped by wallet - when a wallet provides its account list,\n * we replace all cached accounts for that wallet with the live ones.\n * Cached accounts for wallets that haven't provided accounts yet are preserved.\n *\n * @param cachedAccounts - Initial cached accounts from storage\n * @param liveAccounts$ - Observable of live accounts as they become available\n * @param gracePeriodMs - Time in ms to wait before syncing to live state\n * @param getWalletId - Function to extract the wallet ID from an account\n * @param isConverged - Optional function to check if live accounts have caught up to cached accounts\n */\nexport const createAccountHydrationBuffer = <T>(\n\tcachedAccounts: T[],\n\tliveAccounts$: Observable<T[]>,\n\tgracePeriodMs: number,\n\tgetWalletId: (account: T) => string,\n\tisConverged?: (liveAccounts: T[], cachedAccounts: T[]) => boolean,\n): Observable<HydrationBufferResult<T>> => {\n\treturn createBufferCore(\n\t\tcachedAccounts,\n\t\tliveAccounts$,\n\t\tgracePeriodMs,\n\t\t(liveAccounts, cached) => {\n\t\t\tconst walletsWithLiveAccounts = new Set(liveAccounts.map(getWalletId));\n\t\t\tconst mergedAccounts: T[] = [...liveAccounts];\n\n\t\t\tfor (const cachedAccount of cached) {\n\t\t\t\tif (!walletsWithLiveAccounts.has(getWalletId(cachedAccount))) {\n\t\t\t\t\tmergedAccounts.push(cachedAccount);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\treturn mergedAccounts;\n\t\t},\n\t\tisConverged,\n\t);\n};\n","import { type MonoTypeOperatorFunction, tap } from \"rxjs\";\n\ntype Opts = {\n\tprintValue?: boolean;\n\tenabled?: boolean;\n};\n\nexport const logObservable = <T>(\n\tlabel: string,\n\topts?: Opts,\n): MonoTypeOperatorFunction<T> =>\n\ttap((value) => {\n\t\tconst { printValue = false, enabled = true } = opts || {};\n\n\t\tif (!label || !enabled) return;\n\n\t\tconst text = `[kheopskit] observable ${label} emit`;\n\n\t\tif (printValue) console.debug(text, value);\n\t\telse console.debug(text);\n\t});\n","import { combineLatest, map, Observable, of, shareReplay } from \"rxjs\";\nimport { sortAccounts } from \"../utils/sortAccounts\";\nimport type {\n\tBaseWallet,\n\tBaseWalletAccount,\n\tKheopskitConfig,\n\tWalletConnectWallet,\n} from \"./types\";\nimport { isWalletConnectWallet } from \"./types\";\n\nexport const getAccounts$ = (\n\tconfig: KheopskitConfig,\n\twallets: Observable<(BaseWallet | WalletConnectWallet)[]>,\n) => {\n\treturn new Observable<BaseWalletAccount[]>((subscriber) => {\n\t\t// Each plugin gets its own platform's (injected) wallets plus the shared\n\t\t// WalletConnect connector; it derives WC accounts only for the namespaces\n\t\t// the session carries.\n\t\tconst sources = config.platforms.map((plugin) =>\n\t\t\tplugin.getAccounts$(\n\t\t\t\twallets.pipe(\n\t\t\t\t\tmap((ws) =>\n\t\t\t\t\t\tws.filter(\n\t\t\t\t\t\t\t(w) => isWalletConnectWallet(w) || w.platform === plugin.platform,\n\t\t\t\t\t\t),\n\t\t\t\t\t),\n\t\t\t\t),\n\t\t\t),\n\t\t);\n\n\t\tconst accounts$ = sources.length\n\t\t\t? combineLatest(sources).pipe(\n\t\t\t\t\tmap((accounts) => accounts.flat().sort(sortAccounts)),\n\t\t\t\t)\n\t\t\t: of<BaseWalletAccount[]>([]);\n\n\t\tconst sub = accounts$.subscribe(subscriber);\n\n\t\treturn () => {\n\t\t\tsub.unsubscribe();\n\t\t};\n\t}).pipe(shareReplay({ refCount: true, bufferSize: 1 }));\n};\n","import {\n\tcombineLatest,\n\tfilter,\n\tmap,\n\tmergeMap,\n\tObservable,\n\tof,\n\tshareReplay,\n\ttake,\n} from \"rxjs\";\nimport { sortWallets } from \"../utils/sortWallets\";\nimport { getWalletConnectWallet$ } from \"./appKit\";\nimport { store as defaultStore, type KheopskitStore } from \"./store\";\nimport type {\n\tBaseWallet,\n\tKheopskitConfig,\n\tPlatformContext,\n\tWalletConnectWallet,\n} from \"./types\";\n\nexport const getWallets$ = (\n\tconfig: KheopskitConfig,\n\tstore: KheopskitStore = defaultStore,\n) => {\n\t// lock the list of wallets to auto reconnect on first call\n\tconst autoReconnectWalletIds$ = store.observable.pipe(\n\t\tmap((s) => s.autoReconnect ?? []),\n\t\ttake(1),\n\t\tshareReplay({ bufferSize: 1, refCount: true }),\n\t);\n\n\treturn new Observable<(BaseWallet | WalletConnectWallet)[]>((subscriber) => {\n\t\tconst ctx: PlatformContext = { config, store };\n\t\tconst observables = config.platforms.map((plugin) =>\n\t\t\tplugin.getWallets$(ctx),\n\t\t);\n\n\t\tconst platformWallets$ = observables.length\n\t\t\t? combineLatest(observables).pipe(map((wallets) => wallets.flat()))\n\t\t\t: of<BaseWallet[]>([]);\n\n\t\t// The single, platform-less WalletConnect connector is appended here (not\n\t\t// emitted per platform). It sorts last (see sortWallets).\n\t\tconst wallets$ = combineLatest([\n\t\t\tplatformWallets$,\n\t\t\tgetWalletConnectWallet$(config),\n\t\t]).pipe(\n\t\t\tmap(([platformWallets, walletConnect]) => {\n\t\t\t\tconst all: (BaseWallet | WalletConnectWallet)[] = walletConnect\n\t\t\t\t\t? [...platformWallets, walletConnect]\n\t\t\t\t\t: platformWallets;\n\t\t\t\treturn all.sort(sortWallets);\n\t\t\t}),\n\t\t\t// Note: No startWith([]) here - the hydration buffer handles initial state\n\t\t);\n\n\t\t// Track wallets currently reconnecting (avoid duplicate concurrent attempts)\n\t\t// and those already reconnected (so we don't fight a later manual disconnect).\n\t\t// A failed attempt is left out of `reconnected`, so it can retry when the\n\t\t// wallet next re-emits (e.g. a late-injecting extension).\n\t\tconst reconnectingWallets = new Set<string>();\n\t\tconst reconnectedWallets = new Set<string>();\n\t\t// Bounded retry: a wallet whose connect() keeps rejecting (e.g. a permission\n\t\t// permanently denied, or a buggy provider) must not be re-attempted on every\n\t\t// wallets$ emission — the stream re-emits frequently (polkadot polling,\n\t\t// mipd/wallet-standard register events). Allow a few attempts so a\n\t\t// late-injecting extension that isn't ready on first sight still reconnects,\n\t\t// then give up for this session.\n\t\tconst MAX_RECONNECT_ATTEMPTS = 3;\n\t\tconst failedAttempts = new Map<string, number>();\n\n\t\tconst subAutoReconnect = combineLatest([wallets$, autoReconnectWalletIds$])\n\t\t\t.pipe(\n\t\t\t\tfilter(([, walletIds]) => config.autoReconnect && !!walletIds?.length),\n\t\t\t\tmergeMap(([wallets, walletIds]) =>\n\t\t\t\t\twallets.filter((wallet) => walletIds?.includes(wallet.id)),\n\t\t\t\t),\n\t\t\t)\n\t\t\t.subscribe(async (wallet) => {\n\t\t\t\tif (\n\t\t\t\t\twallet.isConnected ||\n\t\t\t\t\treconnectingWallets.has(wallet.id) ||\n\t\t\t\t\treconnectedWallets.has(wallet.id) ||\n\t\t\t\t\t(failedAttempts.get(wallet.id) ?? 0) >= MAX_RECONNECT_ATTEMPTS\n\t\t\t\t) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\treconnectingWallets.add(wallet.id);\n\t\t\t\ttry {\n\t\t\t\t\tawait wallet.connect();\n\t\t\t\t\treconnectedWallets.add(wallet.id);\n\t\t\t\t\tfailedAttempts.delete(wallet.id);\n\t\t\t\t} catch (err) {\n\t\t\t\t\tfailedAttempts.set(\n\t\t\t\t\t\twallet.id,\n\t\t\t\t\t\t(failedAttempts.get(wallet.id) ?? 0) + 1,\n\t\t\t\t\t);\n\t\t\t\t\tconsole.error(\"Failed to reconnect wallet %s\", wallet.id, { err });\n\t\t\t\t} finally {\n\t\t\t\t\treconnectingWallets.delete(wallet.id);\n\t\t\t\t}\n\t\t\t});\n\n\t\tconst subWallets = wallets$.subscribe(subscriber);\n\n\t\treturn () => {\n\t\t\tsubAutoReconnect.unsubscribe();\n\t\t\tsubWallets.unsubscribe();\n\t\t};\n\t}).pipe(shareReplay({ refCount: true, bufferSize: 1 }));\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACM;AAeP,IAAM,aAAa,YAAY;AAC9B,MAAI;AACH,UAAM,EAAE,aAAa,IAAI,MAAM,OAAO,oBAAoB;AAC1D,WAAO;AAAA,EACR,SAAS,OAAO;AACf,YAAQ;AAAA,MACP;AAAA,MAGA;AAAA,IACD;AACA,WAAO;AAAA,EACR;AACD;AAEA,IAAM,sBACL;AAKD,IAAM,gBAAgB,uBAAO,IAAI,wBAAwB;AAIzD,IAAM,2BAA2B,uBAAO,IAAI,iCAAiC;AAK7E,IAAM,kBAAkB,MAGtB,WAAuC,aAAa;AAGtD,IAAM,2BAA2B,MAC/B,WAAuC,wBAAwB;AAGjE,IAAM,kBAAkB,CACvB,OACA,cACU;AACV,EAAC,WAAuC,aAAa,IAAI;AACzD,EAAC,WAAuC,wBAAwB,IAAI;AACrE;AAOO,IAAM,mBAAmB,MAAY;AAC3C,kBAAgB,MAAS;AAC1B;AAYA,IAAM,oBAAoB,CAAC,aAAmC;AAC7D;AAAA,IACC,YAAY,wBAAwB,IAAI,QAAQ;AAAA,EACjD;AACD;AAqBO,IAAM,0BAA0B,CACtC,WAC4C;AAC5C,MAAI,CAAC,OAAO,cAAe,QAAO,GAAG,IAAI;AAGzC,MAAI,OAAO,WAAW,YAAa,QAAO,GAAG,IAAI;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,CAAC,CAAC;AAetD,IAAM,mBAAmB,CAAC,YAAuC;AAChE,UAAQ,QAAQ,UAAU;AAAA,IACzB,KAAK;AACJ,aAAO,GAAG,QAAQ,EAAE,IAAK,QAAkC,WAAW,EAAE;AAAA,IACzE,KAAK;AACJ,aAAO,GAAG,QAAQ,EAAE,IAAK,QAAkC,QAAQ,EAAE;AAAA,IACtE,KAAK;AACJ,aAAO,GAAG,QAAQ,EAAE,KAAM,QAAgC,UAAU,CAAC,GAAG,KAAK,GAAG,CAAC;AAAA,IAClF;AACC,aAAO,QAAQ;AAAA,EACjB;AACD;AAGA,IAAM,kBAAkB,CAAC,WACxB,sBAAsB,MAAM,IAAI,OAAO,UAAU,KAAK,GAAG,IAAI;AAG9D,IAAM,mBAAmB,CAAC,WACzB,GAAG,OAAO,EAAE,IAAI,OAAO,cAAc,IAAI,CAAC,IAAI,OAAO,IAAI;AAQ1D,IAAM,cAAc,CAAC,WACpB,GAAG,iBAAiB,MAAM,CAAC,IAAI,OAAO,IAAI,IAAI,gBAAgB,MAAM,CAAC;AAMtE,IAAM,cAAc,CAAC,GAAmB,MACvC,EAAE,gBAAgB,EAAE,eACpB,EAAE,QAAQ,WAAW,EAAE,QAAQ,UAC/B,EAAE,SAAS,WAAW,EAAE,SAAS,UACjC,EAAE,QAAQ,MAAM,CAAC,GAAG,MAAM;AACzB,QAAM,QAAQ,EAAE,QAAQ,CAAC;AACzB,SAAO,CAAC,CAAC,SAAS,YAAY,CAAC,MAAM,YAAY,KAAK;AACvD,CAAC,KACD,EAAE,SAAS,MAAM,CAAC,KAAK,MAAM;AAC5B,QAAM,QAAQ,EAAE,SAAS,CAAC;AAC1B,SAAO,CAAC,CAAC,SAAS,iBAAiB,GAAG,MAAM,iBAAiB,KAAK;AACnE,CAAC;","names":["combineLatest","distinctUntilChanged","filter","map","Observable","shareReplay","BehaviorSubject","map","Observable","shareReplay","getWalletId","tap","combineLatest","map","Observable","of","shareReplay","Observable","map","combineLatest","of","shareReplay","combineLatest","filter","map","Observable","of","shareReplay","take","store","map","take","shareReplay","Observable","combineLatest","of","filter","store","Observable","shareReplay","combineLatest","map","filter","distinctUntilChanged"]}
|
package/dist/internal.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { C as CachedAccount, K as KheopskitPlatform,
|
|
1
|
+
import { C as CachedAccount, K as KheopskitPlatform, h as BaseWalletAccount, j as CachedWallet, B as BaseWallet, b as WalletConnectWallet } from './types-C7V7DGlg.mjs';
|
|
2
2
|
export { a as clearCachedObservable, b as clearCachedObservablesByPrefix } from './getCachedObservable-C4E8dfMp.mjs';
|
|
3
3
|
import 'rxjs';
|
|
4
4
|
|
|
@@ -41,7 +41,7 @@ declare const acceptsCachedAccount: (cached: CachedAccount, platforms: readonly
|
|
|
41
41
|
* wallet (with its injected provider/extension/standard-wallet handle) replaces
|
|
42
42
|
* it once it loads. connect/disconnect throw until then.
|
|
43
43
|
*/
|
|
44
|
-
declare const hydrateWallet: (cached: CachedWallet) => BaseWallet;
|
|
44
|
+
declare const hydrateWallet: (cached: CachedWallet) => BaseWallet | WalletConnectWallet;
|
|
45
45
|
/**
|
|
46
46
|
* Converts a CachedAccount to a placeholder account for SSR hydration display.
|
|
47
47
|
*
|
|
@@ -57,7 +57,7 @@ declare const hydrateAccount: (cached: CachedAccount) => BaseWalletAccount;
|
|
|
57
57
|
* Converts a wallet to a CachedWallet for storage.
|
|
58
58
|
* Only extracts the serializable properties needed for hydration.
|
|
59
59
|
*/
|
|
60
|
-
declare const serializeWallet: (wallet: BaseWallet) => CachedWallet;
|
|
60
|
+
declare const serializeWallet: (wallet: BaseWallet | WalletConnectWallet) => CachedWallet;
|
|
61
61
|
/**
|
|
62
62
|
* Converts an account to a CachedAccount for storage.
|
|
63
63
|
* Only extracts the serializable properties needed for hydration. Platform-only
|
|
@@ -81,6 +81,6 @@ declare const setCachedIcons: (icons: Record<string, string>) => void;
|
|
|
81
81
|
|
|
82
82
|
declare const sortAccounts: (a1: BaseWalletAccount, a2: BaseWalletAccount) => number;
|
|
83
83
|
|
|
84
|
-
declare const sortWallets: (w1: BaseWallet, w2: BaseWallet) => number;
|
|
84
|
+
declare const sortWallets: (w1: BaseWallet | WalletConnectWallet, w2: BaseWallet | WalletConnectWallet) => number;
|
|
85
85
|
|
|
86
86
|
export { acceptsCachedAccount, getCachedIcon, getSafeLocalStorage, hydrateAccount, hydrateWallet, serializeAccount, serializeWallet, setCachedIcons, sortAccounts, sortWallets };
|
package/dist/internal.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { C as CachedAccount, K as KheopskitPlatform,
|
|
1
|
+
import { C as CachedAccount, K as KheopskitPlatform, h as BaseWalletAccount, j as CachedWallet, B as BaseWallet, b as WalletConnectWallet } from './types-C7V7DGlg.js';
|
|
2
2
|
export { a as clearCachedObservable, b as clearCachedObservablesByPrefix } from './getCachedObservable-C4E8dfMp.js';
|
|
3
3
|
import 'rxjs';
|
|
4
4
|
|
|
@@ -41,7 +41,7 @@ declare const acceptsCachedAccount: (cached: CachedAccount, platforms: readonly
|
|
|
41
41
|
* wallet (with its injected provider/extension/standard-wallet handle) replaces
|
|
42
42
|
* it once it loads. connect/disconnect throw until then.
|
|
43
43
|
*/
|
|
44
|
-
declare const hydrateWallet: (cached: CachedWallet) => BaseWallet;
|
|
44
|
+
declare const hydrateWallet: (cached: CachedWallet) => BaseWallet | WalletConnectWallet;
|
|
45
45
|
/**
|
|
46
46
|
* Converts a CachedAccount to a placeholder account for SSR hydration display.
|
|
47
47
|
*
|
|
@@ -57,7 +57,7 @@ declare const hydrateAccount: (cached: CachedAccount) => BaseWalletAccount;
|
|
|
57
57
|
* Converts a wallet to a CachedWallet for storage.
|
|
58
58
|
* Only extracts the serializable properties needed for hydration.
|
|
59
59
|
*/
|
|
60
|
-
declare const serializeWallet: (wallet: BaseWallet) => CachedWallet;
|
|
60
|
+
declare const serializeWallet: (wallet: BaseWallet | WalletConnectWallet) => CachedWallet;
|
|
61
61
|
/**
|
|
62
62
|
* Converts an account to a CachedAccount for storage.
|
|
63
63
|
* Only extracts the serializable properties needed for hydration. Platform-only
|
|
@@ -81,6 +81,6 @@ declare const setCachedIcons: (icons: Record<string, string>) => void;
|
|
|
81
81
|
|
|
82
82
|
declare const sortAccounts: (a1: BaseWalletAccount, a2: BaseWalletAccount) => number;
|
|
83
83
|
|
|
84
|
-
declare const sortWallets: (w1: BaseWallet, w2: BaseWallet) => number;
|
|
84
|
+
declare const sortWallets: (w1: BaseWallet | WalletConnectWallet, w2: BaseWallet | WalletConnectWallet) => number;
|
|
85
85
|
|
|
86
86
|
export { acceptsCachedAccount, getCachedIcon, getSafeLocalStorage, hydrateAccount, hydrateWallet, serializeAccount, serializeWallet, setCachedIcons, sortAccounts, sortWallets };
|
package/dist/internal.js
CHANGED
|
@@ -8,13 +8,13 @@
|
|
|
8
8
|
|
|
9
9
|
|
|
10
10
|
|
|
11
|
-
var
|
|
11
|
+
var _chunkB4L6GAYDjs = require('./chunk-B4L6GAYD.js');
|
|
12
12
|
require('./chunk-D3EQMFZ2.js');
|
|
13
13
|
|
|
14
14
|
|
|
15
15
|
|
|
16
16
|
|
|
17
|
-
var
|
|
17
|
+
var _chunk4ENHC7G4js = require('./chunk-4ENHC7G4.js');
|
|
18
18
|
|
|
19
19
|
|
|
20
20
|
|
|
@@ -28,5 +28,5 @@ var _chunkSIUWQBT4js = require('./chunk-SIUWQBT4.js');
|
|
|
28
28
|
|
|
29
29
|
|
|
30
30
|
|
|
31
|
-
exports.acceptsCachedAccount =
|
|
31
|
+
exports.acceptsCachedAccount = _chunkB4L6GAYDjs.acceptsCachedAccount; exports.clearCachedObservable = _chunk4ENHC7G4js.clearCachedObservable; exports.clearCachedObservablesByPrefix = _chunk4ENHC7G4js.clearCachedObservablesByPrefix; exports.getCachedIcon = _chunkB4L6GAYDjs.getCachedIcon; exports.getSafeLocalStorage = _chunk4ENHC7G4js.getSafeLocalStorage; exports.hydrateAccount = _chunkB4L6GAYDjs.hydrateAccount; exports.hydrateWallet = _chunkB4L6GAYDjs.hydrateWallet; exports.serializeAccount = _chunkB4L6GAYDjs.serializeAccount; exports.serializeWallet = _chunkB4L6GAYDjs.serializeWallet; exports.setCachedIcons = _chunkB4L6GAYDjs.setCachedIcons; exports.sortAccounts = _chunkB4L6GAYDjs.sortAccounts; exports.sortWallets = _chunkB4L6GAYDjs.sortWallets;
|
|
32
32
|
//# sourceMappingURL=internal.js.map
|
package/dist/internal.mjs
CHANGED
|
@@ -8,13 +8,13 @@ import {
|
|
|
8
8
|
setCachedIcons,
|
|
9
9
|
sortAccounts,
|
|
10
10
|
sortWallets
|
|
11
|
-
} from "./chunk-
|
|
11
|
+
} from "./chunk-YDLCHYHH.mjs";
|
|
12
12
|
import "./chunk-BWUUHUDK.mjs";
|
|
13
13
|
import {
|
|
14
14
|
clearCachedObservable,
|
|
15
15
|
clearCachedObservablesByPrefix,
|
|
16
16
|
getSafeLocalStorage
|
|
17
|
-
} from "./chunk-
|
|
17
|
+
} from "./chunk-7QSGAJ4A.mjs";
|
|
18
18
|
export {
|
|
19
19
|
acceptsCachedAccount,
|
|
20
20
|
clearCachedObservable,
|
package/dist/polkadot.d.mts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { k as PolkadotAccountType, W as WalletAccountId, a as WalletId, K as KheopskitPlatform } from './types-C7V7DGlg.mjs';
|
|
2
|
+
export { b as WalletConnectWallet, i as isInjectedWallet, c as isWalletConnectWallet } from './types-C7V7DGlg.mjs';
|
|
2
3
|
import { InjectedPolkadotAccount, InjectedExtension } from 'polkadot-api/pjs-signer';
|
|
3
4
|
import 'rxjs';
|
|
4
5
|
|
|
@@ -28,7 +29,7 @@ type PolkadotInjectedWallet = {
|
|
|
28
29
|
connect: () => Promise<void>;
|
|
29
30
|
disconnect: () => Promise<void>;
|
|
30
31
|
};
|
|
31
|
-
type PolkadotWallet = PolkadotInjectedWallet
|
|
32
|
+
type PolkadotWallet = PolkadotInjectedWallet;
|
|
32
33
|
/**
|
|
33
34
|
* A Polkadot account. Inherits the fields of polkadot-api's
|
|
34
35
|
* `InjectedPolkadotAccount` — notably the signing surface **`polkadotSigner`**
|
|
@@ -66,4 +67,4 @@ type PolkadotPluginOptions = {
|
|
|
66
67
|
*/
|
|
67
68
|
declare const polkadot: (options?: PolkadotPluginOptions) => KheopskitPlatform<"polkadot", PolkadotWallet, PolkadotAccount>;
|
|
68
69
|
|
|
69
|
-
export { type PolkadotAccount, PolkadotAccountType,
|
|
70
|
+
export { type PolkadotAccount, PolkadotAccountType, type PolkadotInjectedWallet, type PolkadotPluginOptions, type PolkadotWallet, isSs58Address, polkadot };
|
package/dist/polkadot.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { k as PolkadotAccountType, W as WalletAccountId, a as WalletId, K as KheopskitPlatform } from './types-C7V7DGlg.js';
|
|
2
|
+
export { b as WalletConnectWallet, i as isInjectedWallet, c as isWalletConnectWallet } from './types-C7V7DGlg.js';
|
|
2
3
|
import { InjectedPolkadotAccount, InjectedExtension } from 'polkadot-api/pjs-signer';
|
|
3
4
|
import 'rxjs';
|
|
4
5
|
|
|
@@ -28,7 +29,7 @@ type PolkadotInjectedWallet = {
|
|
|
28
29
|
connect: () => Promise<void>;
|
|
29
30
|
disconnect: () => Promise<void>;
|
|
30
31
|
};
|
|
31
|
-
type PolkadotWallet = PolkadotInjectedWallet
|
|
32
|
+
type PolkadotWallet = PolkadotInjectedWallet;
|
|
32
33
|
/**
|
|
33
34
|
* A Polkadot account. Inherits the fields of polkadot-api's
|
|
34
35
|
* `InjectedPolkadotAccount` — notably the signing surface **`polkadotSigner`**
|
|
@@ -66,4 +67,4 @@ type PolkadotPluginOptions = {
|
|
|
66
67
|
*/
|
|
67
68
|
declare const polkadot: (options?: PolkadotPluginOptions) => KheopskitPlatform<"polkadot", PolkadotWallet, PolkadotAccount>;
|
|
68
69
|
|
|
69
|
-
export { type PolkadotAccount, PolkadotAccountType,
|
|
70
|
+
export { type PolkadotAccount, PolkadotAccountType, type PolkadotInjectedWallet, type PolkadotPluginOptions, type PolkadotWallet, isSs58Address, polkadot };
|
package/dist/polkadot.js
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
|
|
2
2
|
|
|
3
3
|
var _chunkD3EQMFZ2js = require('./chunk-D3EQMFZ2.js');
|
|
4
|
-
require('./chunk-FIAL4HTE.js');
|
|
5
4
|
|
|
6
5
|
|
|
7
6
|
|
|
8
7
|
|
|
9
8
|
|
|
9
|
+
var _chunkXQWJM3KCjs = require('./chunk-XQWJM3KC.js');
|
|
10
10
|
|
|
11
|
-
var _chunkNU46D4MZjs = require('./chunk-NU46D4MZ.js');
|
|
12
11
|
|
|
13
12
|
|
|
14
13
|
|
|
15
14
|
|
|
16
|
-
|
|
15
|
+
|
|
16
|
+
var _chunk4ENHC7G4js = require('./chunk-4ENHC7G4.js');
|
|
17
17
|
|
|
18
18
|
// src/api/polkadot/accounts.ts
|
|
19
19
|
|
|
@@ -32,7 +32,7 @@ var getInjectedWalletAccounts$ = (wallet) => {
|
|
|
32
32
|
if (!wallet.isConnected) return _rxjs.of.call(void 0, []);
|
|
33
33
|
return new (0, _rxjs.Observable)((subscriber) => {
|
|
34
34
|
const getAccount = (account) => ({
|
|
35
|
-
id:
|
|
35
|
+
id: _chunkXQWJM3KCjs.getWalletAccountId.call(void 0, wallet.id, account.address),
|
|
36
36
|
...account,
|
|
37
37
|
type: _nullishCoalesce(account.type, () => ( "sr25519")),
|
|
38
38
|
platform: "polkadot",
|
|
@@ -51,14 +51,14 @@ var getInjectedWalletAccounts$ = (wallet) => {
|
|
|
51
51
|
};
|
|
52
52
|
var getAppKitPolkadotSigner = (appKit, address) => {
|
|
53
53
|
const provider = appKit.getProvider("polkadot");
|
|
54
|
-
if (!provider) throw new (0,
|
|
54
|
+
if (!provider) throw new (0, _chunkXQWJM3KCjs.KheopskitError)("NO_PROVIDER", "No provider found");
|
|
55
55
|
if (!provider.session)
|
|
56
|
-
throw new (0,
|
|
56
|
+
throw new (0, _chunkXQWJM3KCjs.KheopskitError)("NO_SESSION", "No session found");
|
|
57
57
|
return _pjssigner.getPolkadotSignerFromPjs.call(void 0,
|
|
58
58
|
address,
|
|
59
59
|
(transactionPayload) => {
|
|
60
60
|
if (!provider.session)
|
|
61
|
-
throw new (0,
|
|
61
|
+
throw new (0, _chunkXQWJM3KCjs.KheopskitError)("NO_SESSION", "No session found");
|
|
62
62
|
return provider.client.request({
|
|
63
63
|
topic: provider.session.topic,
|
|
64
64
|
chainId: `polkadot:${transactionPayload.genesisHash.substring(2, 34)}`,
|
|
@@ -73,11 +73,11 @@ var getAppKitPolkadotSigner = (appKit, address) => {
|
|
|
73
73
|
},
|
|
74
74
|
async ({ address: address2, data }) => {
|
|
75
75
|
if (!provider.session)
|
|
76
|
-
throw new (0,
|
|
76
|
+
throw new (0, _chunkXQWJM3KCjs.KheopskitError)("NO_SESSION", "No session found");
|
|
77
77
|
const networks = appKit.getCaipNetworks("polkadot");
|
|
78
78
|
const chainId = _optionalChain([networks, 'access', _ => _[0], 'optionalAccess', _2 => _2.caipNetworkId]);
|
|
79
79
|
if (!chainId)
|
|
80
|
-
throw new (0,
|
|
80
|
+
throw new (0, _chunkXQWJM3KCjs.KheopskitError)(
|
|
81
81
|
"NO_SESSION",
|
|
82
82
|
"No CAIP network available for polkadot"
|
|
83
83
|
);
|
|
@@ -95,11 +95,12 @@ var getAppKitPolkadotSigner = (appKit, address) => {
|
|
|
95
95
|
}
|
|
96
96
|
);
|
|
97
97
|
};
|
|
98
|
-
var
|
|
98
|
+
var getWalletConnectAccounts$ = (wallet) => {
|
|
99
99
|
const provider = wallet.appKit.getProvider("polkadot");
|
|
100
|
-
if (!wallet.
|
|
101
|
-
|
|
102
|
-
|
|
100
|
+
if (!wallet.platforms.includes("polkadot") || !_optionalChain([provider, 'optionalAccess', _3 => _3.session]))
|
|
101
|
+
return _rxjs.of.call(void 0, []);
|
|
102
|
+
return _chunk4ENHC7G4js.getCachedObservable$.call(void 0,
|
|
103
|
+
`accounts:${wallet.id}:polkadot:`,
|
|
103
104
|
() => new (0, _rxjs.Observable)((subscriber) => {
|
|
104
105
|
const buildAccounts = () => {
|
|
105
106
|
const session = provider.session;
|
|
@@ -111,7 +112,7 @@ var getAppKitAccounts$ = (wallet) => {
|
|
|
111
112
|
];
|
|
112
113
|
return addresses.map(
|
|
113
114
|
(address) => ({
|
|
114
|
-
id:
|
|
115
|
+
id: _chunkXQWJM3KCjs.getWalletAccountId.call(void 0, wallet.id, address),
|
|
115
116
|
platform: "polkadot",
|
|
116
117
|
walletName: wallet.name,
|
|
117
118
|
walletId: wallet.id,
|
|
@@ -147,7 +148,7 @@ var getPolkadotAccounts$ = (polkadotWallets$, polkadotAccountTypes) => new (0, _
|
|
|
147
148
|
_rxjs.switchMap.call(void 0,
|
|
148
149
|
(wallets) => wallets.length ? _rxjs.combineLatest.call(void 0, [
|
|
149
150
|
...wallets.filter((w) => w.type === "injected").map(getInjectedWalletAccounts$),
|
|
150
|
-
...wallets.filter(
|
|
151
|
+
...wallets.filter(_chunk4ENHC7G4js.isWalletConnectWallet).map(getWalletConnectAccounts$)
|
|
151
152
|
]) : _rxjs.of.call(void 0, [])
|
|
152
153
|
),
|
|
153
154
|
_rxjs.map.call(void 0,
|
|
@@ -178,7 +179,7 @@ var _lodashes = require('lodash-es');
|
|
|
178
179
|
|
|
179
180
|
|
|
180
181
|
|
|
181
|
-
var getInjectedWalletsIds = () => typeof window === "undefined" ? [] : _pjssigner.getInjectedExtensions.call(void 0, ).map((name) =>
|
|
182
|
+
var getInjectedWalletsIds = () => typeof window === "undefined" ? [] : _pjssigner.getInjectedExtensions.call(void 0, ).map((name) => _chunk4ENHC7G4js.getWalletId.call(void 0, "polkadot", name));
|
|
182
183
|
var createWalletIdsPoller$ = () => {
|
|
183
184
|
return new (0, _rxjs.Observable)((subscriber) => {
|
|
184
185
|
subscriber.next(getInjectedWalletsIds());
|
|
@@ -207,12 +208,12 @@ var createPolkadotInjectedWallets$ = (store2) => new (0, _rxjs.Observable)((subs
|
|
|
207
208
|
const enabledExtensions$ = new (0, _rxjs.BehaviorSubject)(/* @__PURE__ */ new Map());
|
|
208
209
|
const connect = async (walletId) => {
|
|
209
210
|
if (enabledExtensions$.value.has(walletId))
|
|
210
|
-
throw new (0,
|
|
211
|
+
throw new (0, _chunkXQWJM3KCjs.KheopskitError)(
|
|
211
212
|
"WALLET_ALREADY_CONNECTED",
|
|
212
213
|
`wallet ${walletId} is already connected`,
|
|
213
214
|
{ walletId }
|
|
214
215
|
);
|
|
215
|
-
const { identifier } =
|
|
216
|
+
const { identifier } = _chunk4ENHC7G4js.parseWalletId.call(void 0, walletId);
|
|
216
217
|
const extension = await _pjssigner.connectInjectedExtension.call(void 0, identifier);
|
|
217
218
|
const newMap = new Map(enabledExtensions$.value);
|
|
218
219
|
newMap.set(walletId, extension);
|
|
@@ -221,7 +222,7 @@ var createPolkadotInjectedWallets$ = (store2) => new (0, _rxjs.Observable)((subs
|
|
|
221
222
|
};
|
|
222
223
|
const disconnect = async (walletId) => {
|
|
223
224
|
if (!enabledExtensions$.value.has(walletId))
|
|
224
|
-
throw new (0,
|
|
225
|
+
throw new (0, _chunkXQWJM3KCjs.KheopskitError)(
|
|
225
226
|
"WALLET_NOT_CONNECTED",
|
|
226
227
|
`wallet ${walletId} is not connected`,
|
|
227
228
|
{ walletId }
|
|
@@ -235,7 +236,7 @@ var createPolkadotInjectedWallets$ = (store2) => new (0, _rxjs.Observable)((subs
|
|
|
235
236
|
const subscription = _rxjs.combineLatest.call(void 0, [walletIds$, enabledExtensions$]).pipe(
|
|
236
237
|
_rxjs.map.call(void 0, ([walletIds, enabledExtensions]) => {
|
|
237
238
|
return walletIds.map((id) => {
|
|
238
|
-
const { identifier } =
|
|
239
|
+
const { identifier } = _chunk4ENHC7G4js.parseWalletId.call(void 0, id);
|
|
239
240
|
const extension = enabledExtensions.get(id);
|
|
240
241
|
const extInfo = _chunkD3EQMFZ2js.POLKADOT_EXTENSIONS[identifier];
|
|
241
242
|
return {
|
|
@@ -258,21 +259,7 @@ var createPolkadotInjectedWallets$ = (store2) => new (0, _rxjs.Observable)((subs
|
|
|
258
259
|
subscription.unsubscribe();
|
|
259
260
|
};
|
|
260
261
|
}).pipe(_rxjs.shareReplay.call(void 0, { refCount: true, bufferSize: 1 }));
|
|
261
|
-
var getPolkadotWallets$ = (
|
|
262
|
-
return new (0, _rxjs.Observable)((subscriber) => {
|
|
263
|
-
const subscription = _rxjs.combineLatest.call(void 0, [
|
|
264
|
-
createPolkadotInjectedWallets$(store2),
|
|
265
|
-
_chunkNU46D4MZjs.getAppKitWallets$.call(void 0, config).pipe(_rxjs.map.call(void 0, (w) => w.polkadot))
|
|
266
|
-
]).pipe(
|
|
267
|
-
_rxjs.map.call(void 0,
|
|
268
|
-
([injectedWallets, appKitWallet]) => appKitWallet ? [...injectedWallets, appKitWallet] : injectedWallets
|
|
269
|
-
)
|
|
270
|
-
).subscribe(subscriber);
|
|
271
|
-
return () => {
|
|
272
|
-
subscription.unsubscribe();
|
|
273
|
-
};
|
|
274
|
-
}).pipe(_rxjs.shareReplay.call(void 0, { refCount: true, bufferSize: 1 }));
|
|
275
|
-
};
|
|
262
|
+
var getPolkadotWallets$ = (store2 = _chunkXQWJM3KCjs.store) => createPolkadotInjectedWallets$(store2);
|
|
276
263
|
var walletsEqual = (a, b) => {
|
|
277
264
|
if (a.length !== b.length) return false;
|
|
278
265
|
return a.every(
|
|
@@ -302,7 +289,7 @@ var polkadot = (options = {}) => {
|
|
|
302
289
|
}
|
|
303
290
|
return {
|
|
304
291
|
platform: "polkadot",
|
|
305
|
-
getWallets$: (ctx) => getPolkadotWallets$(ctx.
|
|
292
|
+
getWallets$: (ctx) => getPolkadotWallets$(ctx.store),
|
|
306
293
|
getAccounts$: (wallets$) => getPolkadotAccounts$(wallets$, accountTypes),
|
|
307
294
|
acceptsCachedAccount: (cached) => accountTypes.includes(_nullishCoalesce(cached.polkadotAccountType, () => ( "sr25519")))
|
|
308
295
|
};
|
|
@@ -310,5 +297,7 @@ var polkadot = (options = {}) => {
|
|
|
310
297
|
|
|
311
298
|
|
|
312
299
|
|
|
313
|
-
|
|
300
|
+
|
|
301
|
+
|
|
302
|
+
exports.isInjectedWallet = _chunk4ENHC7G4js.isInjectedWallet; exports.isSs58Address = _chunkXQWJM3KCjs.isSs58Address; exports.isWalletConnectWallet = _chunk4ENHC7G4js.isWalletConnectWallet; exports.polkadot = polkadot;
|
|
314
303
|
//# sourceMappingURL=polkadot.js.map
|