@tuwaio/orbit-core 1.0.0-fix-test-alpha.18.0fe490a → 1.0.0-fix-test-alpha.20.ee459fd
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 +32 -1
- package/dist/index.d.ts +32 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -193,6 +193,37 @@ declare const createBoundedUseStore: <S extends StoreApi<unknown>>(store: S) =>
|
|
|
193
193
|
<T>(selector: (state: ExtractState<S>) => T): T;
|
|
194
194
|
};
|
|
195
195
|
|
|
196
|
+
/**
|
|
197
|
+
* @name delay
|
|
198
|
+
*
|
|
199
|
+
* Ensures the global 'window' object is available (if running in a browser-like environment),
|
|
200
|
+
* then pauses execution for a specified duration, and finally resolves the Promise with the given value.
|
|
201
|
+
*
|
|
202
|
+
* This utility function is designed to be safe for use in Server-Side Rendering (SSR) environments.
|
|
203
|
+
* It asynchronously waits for the 'window' object to be defined before starting the actual timer,
|
|
204
|
+
* helping to prevent errors during the initial server render while still providing a time delay on the client.
|
|
205
|
+
*
|
|
206
|
+
* @template T - The type of the value being resolved.
|
|
207
|
+
*
|
|
208
|
+
* @param {T} value - The value to resolve the Promise with after the delay.
|
|
209
|
+
* @param {number} ms - The number of milliseconds (delay) to wait before resolving the Promise after 'window' is available.
|
|
210
|
+
*
|
|
211
|
+
* @returns {Promise<T>} A Promise that resolves with the provided `value` after both the 'window' check and the delay (`ms`) are complete.
|
|
212
|
+
*
|
|
213
|
+
* @example
|
|
214
|
+
* ```typescript
|
|
215
|
+
* // Use this in an environment where 'window' might not be immediately available (e.g., Next.js component).
|
|
216
|
+
* async function waitForWindowAndDelay() {
|
|
217
|
+
* console.log("Start wait...");
|
|
218
|
+
* // This will wait for window, and then wait 100ms.
|
|
219
|
+
* const data = await delay("Ready to connect", 100);
|
|
220
|
+
* console.log(data);
|
|
221
|
+
* }
|
|
222
|
+
* waitForWindowAndDelay();
|
|
223
|
+
* ```
|
|
224
|
+
*/
|
|
225
|
+
declare const delay: <T>(value: T, ms: number) => Promise<T>;
|
|
226
|
+
|
|
196
227
|
declare function formatWalletChainId(chainId: string | number, connectedAdapter: OrbitAdapter): string | number;
|
|
197
228
|
|
|
198
229
|
/**
|
|
@@ -288,4 +319,4 @@ declare function isSolanaChain(chainId: number | string): boolean;
|
|
|
288
319
|
*/
|
|
289
320
|
declare function setChainId(chainId: number | string): string | number;
|
|
290
321
|
|
|
291
|
-
export { type BaseAdapter, OrbitAdapter, type OrbitGenericAdapter, type StoreSlice, connectedWalletChainHelpers, createBoundedUseStore, formatWalletChainId, getWalletTypeFromConnectorName, isSolanaChain, selectAdapterByKey, setChainId };
|
|
322
|
+
export { type BaseAdapter, OrbitAdapter, type OrbitGenericAdapter, type StoreSlice, connectedWalletChainHelpers, createBoundedUseStore, delay, formatWalletChainId, getWalletTypeFromConnectorName, isSolanaChain, selectAdapterByKey, setChainId };
|
package/dist/index.d.ts
CHANGED
|
@@ -193,6 +193,37 @@ declare const createBoundedUseStore: <S extends StoreApi<unknown>>(store: S) =>
|
|
|
193
193
|
<T>(selector: (state: ExtractState<S>) => T): T;
|
|
194
194
|
};
|
|
195
195
|
|
|
196
|
+
/**
|
|
197
|
+
* @name delay
|
|
198
|
+
*
|
|
199
|
+
* Ensures the global 'window' object is available (if running in a browser-like environment),
|
|
200
|
+
* then pauses execution for a specified duration, and finally resolves the Promise with the given value.
|
|
201
|
+
*
|
|
202
|
+
* This utility function is designed to be safe for use in Server-Side Rendering (SSR) environments.
|
|
203
|
+
* It asynchronously waits for the 'window' object to be defined before starting the actual timer,
|
|
204
|
+
* helping to prevent errors during the initial server render while still providing a time delay on the client.
|
|
205
|
+
*
|
|
206
|
+
* @template T - The type of the value being resolved.
|
|
207
|
+
*
|
|
208
|
+
* @param {T} value - The value to resolve the Promise with after the delay.
|
|
209
|
+
* @param {number} ms - The number of milliseconds (delay) to wait before resolving the Promise after 'window' is available.
|
|
210
|
+
*
|
|
211
|
+
* @returns {Promise<T>} A Promise that resolves with the provided `value` after both the 'window' check and the delay (`ms`) are complete.
|
|
212
|
+
*
|
|
213
|
+
* @example
|
|
214
|
+
* ```typescript
|
|
215
|
+
* // Use this in an environment where 'window' might not be immediately available (e.g., Next.js component).
|
|
216
|
+
* async function waitForWindowAndDelay() {
|
|
217
|
+
* console.log("Start wait...");
|
|
218
|
+
* // This will wait for window, and then wait 100ms.
|
|
219
|
+
* const data = await delay("Ready to connect", 100);
|
|
220
|
+
* console.log(data);
|
|
221
|
+
* }
|
|
222
|
+
* waitForWindowAndDelay();
|
|
223
|
+
* ```
|
|
224
|
+
*/
|
|
225
|
+
declare const delay: <T>(value: T, ms: number) => Promise<T>;
|
|
226
|
+
|
|
196
227
|
declare function formatWalletChainId(chainId: string | number, connectedAdapter: OrbitAdapter): string | number;
|
|
197
228
|
|
|
198
229
|
/**
|
|
@@ -288,4 +319,4 @@ declare function isSolanaChain(chainId: number | string): boolean;
|
|
|
288
319
|
*/
|
|
289
320
|
declare function setChainId(chainId: number | string): string | number;
|
|
290
321
|
|
|
291
|
-
export { type BaseAdapter, OrbitAdapter, type OrbitGenericAdapter, type StoreSlice, connectedWalletChainHelpers, createBoundedUseStore, formatWalletChainId, getWalletTypeFromConnectorName, isSolanaChain, selectAdapterByKey, setChainId };
|
|
322
|
+
export { type BaseAdapter, OrbitAdapter, type OrbitGenericAdapter, type StoreSlice, connectedWalletChainHelpers, createBoundedUseStore, delay, formatWalletChainId, getWalletTypeFromConnectorName, isSolanaChain, selectAdapterByKey, setChainId };
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
'use strict';var zustand=require('zustand');var o=(r=>(r.EVM="evm",r.SOLANA="solana",r.Starknet="starknet",r))(o||{});var
|
|
1
|
+
'use strict';var zustand=require('zustand');var o=(r=>(r.EVM="evm",r.SOLANA="solana",r.Starknet="starknet",r))(o||{});var d={connectedWalletChain:typeof window<"u"?window.localStorage.getItem("orbit-core:connectedWalletChain")??"":"",setConnectedWalletChain:e=>typeof window<"u"?window.localStorage.setItem("orbit-core:connectedWalletChain",String(e)):void 0,getConnectedWalletChain:()=>typeof window<"u"?window.localStorage.getItem("orbit-core:connectedWalletChain"):void 0,removeConnectedWalletChain:()=>typeof window<"u"?window.localStorage.removeItem("orbit-core:connectedWalletChain"):void 0};var c=(e=>t=>zustand.useStore(e,t));var u=(e,t)=>new Promise(n=>{let r=()=>{setTimeout(()=>n(e),t);};typeof window<"u"?r():setTimeout(r,0);});function g(e,t){return typeof e=="string"?`${t}:${e}`:e}function A(e,t){return `${e}:${t.replace(/\s+/g,"").toLowerCase()}`}var y=({adapterKey:e,adapter:t})=>{if(Array.isArray(t)){if(t.length===0){console.error("Adapter selection failed: The provided adapters array is empty.");return}let n=t.find(r=>r.key===e);return n||(console.warn(`No adapter found for key: "${e}". Falling back to the first available adapter: "${t[0].key}".`),t[0])}return t};function a(e){return typeof e=="string"?["devnet","testnet","mainnet-beta","mainnet"].includes(e):false}function T(e){return a(e)?`solana:${e}`:e}exports.OrbitAdapter=o;exports.connectedWalletChainHelpers=d;exports.createBoundedUseStore=c;exports.delay=u;exports.formatWalletChainId=g;exports.getWalletTypeFromConnectorName=A;exports.isSolanaChain=a;exports.selectAdapterByKey=y;exports.setChainId=T;//# sourceMappingURL=index.js.map
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/types.ts","../src/utils/connectedWalletChainHelpers.ts","../src/utils/createBoundedUseStore.ts","../src/utils/formatWalletChainId.ts","../src/utils/getWalletTypeFromConnectorName.ts","../src/utils/selectAdapterByKey.ts","../src/utils/%D1%81hainHelpers.ts"],"names":["OrbitAdapter","connectedWalletChainHelpers","chain","createBoundedUseStore","store","selector","useStore","formatWalletChainId","chainId","connectedAdapter","getWalletTypeFromConnectorName","adapter","name","selectAdapterByKey","adapterKey","foundAdapter","a","isSolanaChain","setChainId"],"mappings":"4CA4CO,IAAKA,CAAAA,CAAAA,CAAAA,CAAAA,GAUVA,EAAA,GAAA,CAAM,KAAA,CASNA,EAAA,MAAA,CAAS,QAAA,CASTA,EAAA,QAAA,CAAW,UAAA,CA5BDA,OAAA,EAAA,ECnCL,IAAMC,EAA8B,CAKzC,oBAAA,CACE,OAAO,MAAA,CAAW,GAAA,CAAe,OAAO,YAAA,CAAa,OAAA,CAAQ,iCAAiC,CAAA,EAAK,EAAA,CAAM,GAc3G,uBAAA,CAA0BC,CAAAA,EACxB,OAAO,MAAA,CAAW,GAAA,CACd,OAAO,YAAA,CAAa,OAAA,CAAQ,kCAAmC,MAAA,CAAOA,CAAK,CAAC,CAAA,CAC5E,MAAA,CAeN,wBAAyB,IACvB,OAAO,MAAA,CAAW,GAAA,CAAc,MAAA,CAAO,YAAA,CAAa,QAAQ,iCAAiC,CAAA,CAAI,OAEnG,0BAAA,CAA4B,IAC1B,OAAO,MAAA,CAAW,GAAA,CAAc,OAAO,YAAA,CAAa,UAAA,CAAW,iCAAiC,CAAA,CAAI,MACxG,ECnBO,IAAMC,CAAAA,EAA0BC,CAAAA,EAAWC,CAAAA,EAAaC,gBAAAA,CAASF,EAAOC,CAAQ,CAAA,EC/BhF,SAASE,CAAAA,CAAoBC,CAAAA,CAA0BC,EAAgC,CAC5F,OAAI,OAAOD,CAAAA,EAAY,QAAA,CACd,GAAGC,CAAgB,CAAA,CAAA,EAAID,CAAO,CAAA,CAAA,CAE9BA,CAEX,CCoBO,SAASE,CAAAA,CAA+BC,CAAAA,CAAuBC,CAAAA,CAAsB,CAC1F,OAAO,GAAGD,CAAO,CAAA,CAAA,EAAIC,EAAK,OAAA,CAAQ,MAAA,CAAQ,EAAE,CAAA,CAAE,WAAA,EAAa,CAAA,CAC7D,KCeaC,CAAAA,CAAqB,CAAkC,CAClE,UAAA,CAAAC,CAAAA,CACA,QAAAH,CACF,CAAA,GAA4E,CAC1E,GAAI,KAAA,CAAM,OAAA,CAAQA,CAAO,CAAA,CAAG,CAC1B,GAAIA,CAAAA,CAAQ,MAAA,GAAW,EAAG,CACxB,OAAA,CAAQ,MAAM,iEAAiE,CAAA,CAC/E,MACF,CAEA,IAAMI,EAAeJ,CAAAA,CAAQ,IAAA,CAAMK,GAAMA,CAAAA,CAAE,GAAA,GAAQF,CAAU,CAAA,CAE7D,OAAIC,CAAAA,GAGF,QAAQ,IAAA,CACN,CAAA,2BAAA,EAA8BD,CAAU,CAAA,iDAAA,EAAoDH,CAAAA,CAAQ,CAAC,CAAA,CAAE,GAAG,IAC5G,CAAA,CACOA,CAAAA,CAAQ,CAAC,CAAA,CAEpB,CACA,OAAOA,CACT,EC5DO,SAASM,CAAAA,CAAcT,CAAAA,CAAmC,CAC/D,OAAI,OAAOA,CAAAA,EAAY,SACd,CAAC,QAAA,CAAU,UAAW,cAAA,CAAgB,SAAS,EAAE,QAAA,CAASA,CAAO,EAEnE,KACT,CAQO,SAASU,CAAAA,CAAWV,CAAAA,CAA2C,CACpE,OAAIS,CAAAA,CAAcT,CAAO,CAAA,CAChB,CAAA,OAAA,EAAUA,CAAO,CAAA,CAAA,CAEjBA,CAEX","file":"index.js","sourcesContent":["/**\n * @file\n * Core type definitions for the Orbit blockchain adapter system.\n * This file contains fundamental enums and types that define the supported blockchain architectures\n * and their adapter interfaces.\n */\n\nimport { StoreApi } from 'zustand';\n\n/**\n * A utility type for creating modular Zustand store slices, enabling composable state management.\n * @template T The state slice being defined.\n * @template S The full store state that includes the slice `T`.\n */\nexport type StoreSlice<T extends object, S extends object = T> = (\n set: StoreApi<S extends T ? S : S & T>['setState'],\n get: StoreApi<S extends T ? S : S & T>['getState'],\n) => T;\n\n// =================================================================================================\n// 1. ENUMS AND CORE TRANSACTION TYPES\n// =================================================================================================\n\n/**\n * Defines the supported blockchain adapters in the Orbit system.\n * Each adapter corresponds to a specific blockchain architecture and implements\n * the necessary interfaces for that chain's functionality.\n *\n * @enum {string}\n *\n * @example\n * ```typescript\n * // Using adapter types in configuration\n * const config = {\n * chainType: OrbitAdapter.EVM,\n * // other configuration...\n * };\n *\n * // Checking adapter compatibility\n * if (chainType === OrbitAdapter.SOLANA) {\n * // Solana-specific logic\n * }\n * ```\n */\nexport enum OrbitAdapter {\n /**\n * For Ethereum Virtual Machine (EVM) compatible chains.\n * Supports networks like:\n * - Ethereum Mainnet\n * - Polygon\n * - Binance Smart Chain\n * - Avalanche\n * - Other EVM-compatible L1/L2 chains\n */\n EVM = 'evm',\n\n /**\n * For the Solana blockchain.\n * Supports:\n * - Solana Mainnet\n * - Devnet\n * - Testnet\n */\n SOLANA = 'solana',\n\n /**\n * For the Starknet L2 network.\n * Supports:\n * - Starknet Mainnet\n * - Testnet (Goerli)\n * - Other Starknet deployments\n */\n Starknet = 'starknet',\n}\n\n/**\n * Generic type for creating blockchain adapters with type safety.\n * This type ensures that all adapters implement the required interface\n * and are properly keyed by their blockchain type.\n *\n * @typeParam A - Type that extends the base adapter interface with a key property\n *\n * @property {A | A[]} adapter - Single adapter instance or array of adapters\n *\n * @example\n * ```typescript\n * // Single adapter implementation\n * interface EVMAdapter extends BaseAdapter {\n * key: OrbitAdapter.EVM;\n * // EVM-specific methods...\n * }\n * const evmConfig: OrbitGenericAdapter<EVMAdapter> = {\n * adapter: {\n * key: OrbitAdapter.EVM,\n * // implementation...\n * }\n * };\n *\n * // Multiple adapters\n * const multiChainConfig: OrbitGenericAdapter<EVMAdapter> = {\n * adapter: [\n * { key: OrbitAdapter.EVM, ... },\n * { key: OrbitAdapter.SOLANA, ... }\n * ]\n * };\n * ```\n */\nexport type OrbitGenericAdapter<A extends { key: OrbitAdapter }> = {\n adapter: A | A[];\n};\n\nexport type BaseAdapter = {\n /**\n * Generates blockchain explorer URL\n * @returns Explorer URL or undefined if not available\n */\n getExplorerUrl: (url?: string, chainId?: string | number) => string | undefined;\n\n /** Optional method to resolve ENS-like names */\n getName?: (address: string) => Promise<string | null>;\n\n /** Optional method to get avatar for resolved names */\n getAvatar?: (name: string) => Promise<string | null>;\n};\n","/**\n * Helper utilities for managing impersonated wallet addresses\n *\n * @remarks\n * These utilities are primarily used for development and testing purposes.\n * They provide a way to simulate different wallet addresses without actually connecting a wallet.\n * All data is stored in localStorage with the 'satellite-connect:impersonatedAddress' key.\n * Functions are safe to use in both browser and SSR environments.\n */\nexport const connectedWalletChainHelpers = {\n /**\n * Currently impersonated address from localStorage\n * Returns empty string if not set or in SSR context\n */\n connectedWalletChain:\n typeof window !== 'undefined' ? (window.localStorage.getItem('orbit-core:connectedWalletChain') ?? '') : '',\n\n /**\n * Stores an impersonated address in localStorage\n *\n * @example\n * ```typescript\n * // Set impersonated address\n * impersonatedHelpers.setImpersonated('0x1234...5678');\n * ```\n *\n * @param address - Ethereum or Solana address to impersonate\n * @returns undefined in SSR context, void in browser\n */\n setConnectedWalletChain: (chain: string | number) =>\n typeof window !== 'undefined'\n ? window.localStorage.setItem('orbit-core:connectedWalletChain', String(chain))\n : undefined,\n\n /**\n * Retrieves the current impersonated address from localStorage\n *\n * @example\n * ```typescript\n * // Get current impersonated address\n * const address = impersonatedHelpers.getImpersonated();\n * if (address) {\n * console.log('Currently impersonating:', address);\n * }\n * ```\n * @returns The impersonated address or undefined if not set or in SSR context\n */\n getConnectedWalletChain: () =>\n typeof window !== 'undefined' ? window.localStorage.getItem('orbit-core:connectedWalletChain') : undefined,\n\n removeConnectedWalletChain: () =>\n typeof window !== 'undefined' ? window.localStorage.removeItem('orbit-core:connectedWalletChain') : undefined,\n};\n","/**\n * @file This file provides a utility for creating a type-safe, bounded Zustand hook from a vanilla store.\n * This pattern is recommended by the official Zustand documentation to ensure full type\n * safety when integrating vanilla stores with React.\n *\n * @see https://docs.pmnd.rs/zustand/guides/typescript#bounded-usestore-hook-for-vanilla-stores\n */\n\nimport { StoreApi, useStore } from 'zustand';\n\n/**\n * A utility type that infers the state shape from a Zustand `StoreApi`.\n * It extracts the return type of the `getState` method.\n * @template S - The type of the Zustand store (`StoreApi`).\n */\ntype ExtractState<S> = S extends { getState: () => infer T } ? T : never;\n\n/**\n * Creates a bounded `useStore` hook from a vanilla Zustand store.\n *\n * This function takes a vanilla Zustand store instance and returns a React hook\n * that is pre-bound to that store. This approach provides a cleaner API and\n * enhances type inference, eliminating the need to pass the store instance\n * on every use.\n *\n * The returned hook supports two signatures:\n * 1. `useBoundedStore()`: Selects the entire state.\n * 2. `useBoundedStore(selector)`: Selects a slice of the state, returning only what the selector function specifies.\n *\n * @template S - The type of the Zustand store (`StoreApi`).\n * @param {S} store - The vanilla Zustand store instance to bind the hook to.\n * @returns {function} A fully typed React hook for accessing the store's state.\n */\nexport const createBoundedUseStore = ((store) => (selector) => useStore(store, selector)) as <\n S extends StoreApi<unknown>,\n>(\n store: S,\n) => {\n // This implementation uses a Immediately Invoked Function Expression (IIFE)\n // trick combined with casting to achieve the desired overloaded function signature in a concise way.\n (): ExtractState<S>;\n <T>(selector: (state: ExtractState<S>) => T): T;\n};\n","import { OrbitAdapter } from '../types';\n\nexport function formatWalletChainId(chainId: string | number, connectedAdapter: OrbitAdapter) {\n if (typeof chainId === 'string') {\n return `${connectedAdapter}:${chainId}`;\n } else {\n return chainId;\n }\n}\n","import { OrbitAdapter } from '../types';\n\n/**\n * Generates a standardized wallet type identifier from adapter type and connector name\n *\n * @example\n * ```typescript\n * // Returns \"evm:metamask\"\n * getWalletTypeFromConnectorName(OrbitAdapter.EVM, \"MetaMask\");\n *\n * // Returns \"solana:phantom\"\n * getWalletTypeFromConnectorName(OrbitAdapter.SOLANA, \"Phantom\");\n *\n * // Returns \"evm:coinbasewallet\" (removes spaces)\n * getWalletTypeFromConnectorName(OrbitAdapter.EVM, \"Coinbase Wallet\");\n * ```\n *\n * @param adapter - The blockchain adapter type (e.g. EVM, SOLANA)\n * @param name - The wallet connector name (e.g. \"MetaMask\", \"Phantom\")\n * @returns A formatted wallet type string in format \"chain:wallet\"\n *\n * @remarks\n * The function:\n * 1. Combines adapter type with connector name using \":\" as separator\n * 2. Removes all whitespace from connector name\n * 3. Converts connector name to lowercase\n * This ensures consistent wallet type identifiers across the application\n */\nexport function getWalletTypeFromConnectorName(adapter: OrbitAdapter, name: string): string {\n return `${adapter}:${name.replace(/\\s+/g, '').toLowerCase()}`;\n}\n","/**\n * @file\n * This module provides adapter selection functionality for the Orbit system.\n * Part of the core infrastructure for managing blockchain adapters.\n */\n\nimport { OrbitAdapter, OrbitGenericAdapter } from '../types';\n\n/**\n * Selects an appropriate adapter based on the provided key from either a single adapter\n * or an array of adapters.\n *\n * @typeParam A - Type extending basic adapter interface with a key property\n *\n * @param options - Selection configuration object\n * @param options.adapterKey - Target adapter key to search for\n * @param options.adapter - Single adapter or array of adapters to search within\n *\n * @returns Selected adapter or undefined if no suitable adapter found\n *\n * @remarks\n * If an array is provided but no matching adapter is found, falls back to the first adapter\n * in the array with a warning message.\n *\n * @example\n * ```typescript\n * // Single adapter usage\n * const singleResult = selectAdapterByKey({\n * adapterKey: OrbitAdapter.SOLANA,\n * adapter: { key: OrbitAdapter.SOLANA, connect: async () => {...} }\n * });\n *\n * // Multiple adapters usage\n * const multiResult = selectAdapterByKey({\n * adapterKey: OrbitAdapter.EVM,\n * adapter: [\n * { key: OrbitAdapter.SOLANA, connect: async () => {...} },\n * { key: OrbitAdapter.EVM, connect: async () => {...} }\n * ]\n * });\n * ```\n *\n * @throws {Error} Logs error if adapter array is empty\n * @throws {Warning} Logs warning if requested adapter key not found in array\n */\nexport const selectAdapterByKey = <A extends { key: OrbitAdapter }>({\n adapterKey,\n adapter,\n}: { adapterKey: OrbitAdapter } & OrbitGenericAdapter<A>): A | undefined => {\n if (Array.isArray(adapter)) {\n if (adapter.length === 0) {\n console.error('Adapter selection failed: The provided adapters array is empty.');\n return undefined;\n }\n\n const foundAdapter = adapter.find((a) => a.key === adapterKey);\n\n if (foundAdapter) {\n return foundAdapter;\n } else {\n console.warn(\n `No adapter found for key: \"${adapterKey}\". Falling back to the first available adapter: \"${adapter[0].key}\".`,\n );\n return adapter[0];\n }\n }\n return adapter;\n};\n","/**\n * Checks whether the given chain ID belongs to a Solana network.\n * Supports common Solana network names: 'devnet', 'testnet', 'mainnet-beta', 'mainnet'.\n *\n * @param {number | string} chainId - The chain ID or chain name.\n * @returns {boolean} - True if the chain ID corresponds to a Solana network, false otherwise.\n */\nexport function isSolanaChain(chainId: number | string): boolean {\n if (typeof chainId === 'string') {\n return ['devnet', 'testnet', 'mainnet-beta', 'mainnet'].includes(chainId);\n }\n return false;\n}\n\n/**\n * Sets the chain ID to a Solana-specific format if the chain is a Solana network.\n *\n * @param {number | string} chainId - The original chain ID or name.\n * @returns {string | number} - The formatted chain ID prefixed with 'solana:' if Solana, otherwise the original.\n */\nexport function setChainId(chainId: number | string): string | number {\n if (isSolanaChain(chainId)) {\n return `solana:${chainId}`;\n } else {\n return chainId;\n }\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/types.ts","../src/utils/connectedWalletChainHelpers.ts","../src/utils/createBoundedUseStore.ts","../src/utils/delay.ts","../src/utils/formatWalletChainId.ts","../src/utils/getWalletTypeFromConnectorName.ts","../src/utils/selectAdapterByKey.ts","../src/utils/%D1%81hainHelpers.ts"],"names":["OrbitAdapter","connectedWalletChainHelpers","chain","createBoundedUseStore","store","selector","useStore","delay","value","ms","resolve","runTimeout","formatWalletChainId","chainId","connectedAdapter","getWalletTypeFromConnectorName","adapter","name","selectAdapterByKey","adapterKey","foundAdapter","a","isSolanaChain","setChainId"],"mappings":"4CA4CO,IAAKA,CAAAA,CAAAA,CAAAA,CAAAA,GAUVA,CAAAA,CAAA,GAAA,CAAM,KAAA,CASNA,CAAAA,CAAA,OAAS,QAAA,CASTA,CAAAA,CAAA,QAAA,CAAW,UAAA,CA5BDA,CAAAA,CAAAA,EAAAA,CAAAA,EAAA,EAAA,MCnCCC,CAAAA,CAA8B,CAKzC,oBAAA,CACE,OAAO,MAAA,CAAW,GAAA,CAAe,OAAO,YAAA,CAAa,OAAA,CAAQ,iCAAiC,CAAA,EAAK,EAAA,CAAM,EAAA,CAc3G,wBAA0BC,CAAAA,EACxB,OAAO,MAAA,CAAW,GAAA,CACd,MAAA,CAAO,YAAA,CAAa,QAAQ,iCAAA,CAAmC,MAAA,CAAOA,CAAK,CAAC,CAAA,CAC5E,MAAA,CAeN,wBAAyB,IACvB,OAAO,MAAA,CAAW,GAAA,CAAc,MAAA,CAAO,YAAA,CAAa,OAAA,CAAQ,iCAAiC,CAAA,CAAI,MAAA,CAEnG,0BAAA,CAA4B,IAC1B,OAAO,MAAA,CAAW,IAAc,MAAA,CAAO,YAAA,CAAa,UAAA,CAAW,iCAAiC,CAAA,CAAI,MACxG,ECnBO,IAAMC,CAAAA,EAA0BC,GAAWC,CAAAA,EAAaC,gBAAAA,CAASF,CAAAA,CAAOC,CAAQ,CAAA,ECJhF,IAAME,CAAAA,CAAQ,CAAIC,CAAAA,CAAUC,CAAAA,GAC1B,IAAI,OAAA,CAASC,CAAAA,EAAY,CAC9B,IAAMC,CAAAA,CAAa,IAAM,CACvB,UAAA,CAAW,IAAMD,CAAAA,CAAQF,CAAK,CAAA,CAAGC,CAAE,EACrC,CAAA,CAEI,OAAO,MAAA,CAAW,IACpBE,CAAAA,EAAW,CAEX,UAAA,CAAWA,CAAAA,CAAY,CAAC,EAE5B,CAAC,ECtCI,SAASC,CAAAA,CAAoBC,CAAAA,CAA0BC,CAAAA,CAAgC,CAC5F,OAAI,OAAOD,CAAAA,EAAY,QAAA,CACd,CAAA,EAAGC,CAAgB,CAAA,CAAA,EAAID,CAAO,GAE9BA,CAEX,CCoBO,SAASE,CAAAA,CAA+BC,CAAAA,CAAuBC,CAAAA,CAAsB,CAC1F,OAAO,CAAA,EAAGD,CAAO,CAAA,CAAA,EAAIC,CAAAA,CAAK,OAAA,CAAQ,MAAA,CAAQ,EAAE,CAAA,CAAE,WAAA,EAAa,CAAA,CAC7D,CCeO,IAAMC,EAAqB,CAAkC,CAClE,UAAA,CAAAC,CAAAA,CACA,OAAA,CAAAH,CACF,IAA4E,CAC1E,GAAI,KAAA,CAAM,OAAA,CAAQA,CAAO,CAAA,CAAG,CAC1B,GAAIA,CAAAA,CAAQ,MAAA,GAAW,CAAA,CAAG,CACxB,OAAA,CAAQ,KAAA,CAAM,iEAAiE,CAAA,CAC/E,MACF,CAEA,IAAMI,CAAAA,CAAeJ,CAAAA,CAAQ,KAAMK,CAAAA,EAAMA,CAAAA,CAAE,GAAA,GAAQF,CAAU,CAAA,CAE7D,OAAIC,IAGF,OAAA,CAAQ,IAAA,CACN,CAAA,2BAAA,EAA8BD,CAAU,CAAA,iDAAA,EAAoDH,CAAAA,CAAQ,CAAC,CAAA,CAAE,GAAG,CAAA,EAAA,CAC5G,CAAA,CACOA,CAAAA,CAAQ,CAAC,CAAA,CAEpB,CACA,OAAOA,CACT,EC5DO,SAASM,CAAAA,CAAcT,CAAAA,CAAmC,CAC/D,OAAI,OAAOA,CAAAA,EAAY,QAAA,CACd,CAAC,QAAA,CAAU,UAAW,cAAA,CAAgB,SAAS,CAAA,CAAE,QAAA,CAASA,CAAO,CAAA,CAEnE,KACT,CAQO,SAASU,CAAAA,CAAWV,CAAAA,CAA2C,CACpE,OAAIS,CAAAA,CAAcT,CAAO,CAAA,CAChB,CAAA,OAAA,EAAUA,CAAO,CAAA,CAAA,CAEjBA,CAEX","file":"index.js","sourcesContent":["/**\n * @file\n * Core type definitions for the Orbit blockchain adapter system.\n * This file contains fundamental enums and types that define the supported blockchain architectures\n * and their adapter interfaces.\n */\n\nimport { StoreApi } from 'zustand';\n\n/**\n * A utility type for creating modular Zustand store slices, enabling composable state management.\n * @template T The state slice being defined.\n * @template S The full store state that includes the slice `T`.\n */\nexport type StoreSlice<T extends object, S extends object = T> = (\n set: StoreApi<S extends T ? S : S & T>['setState'],\n get: StoreApi<S extends T ? S : S & T>['getState'],\n) => T;\n\n// =================================================================================================\n// 1. ENUMS AND CORE TRANSACTION TYPES\n// =================================================================================================\n\n/**\n * Defines the supported blockchain adapters in the Orbit system.\n * Each adapter corresponds to a specific blockchain architecture and implements\n * the necessary interfaces for that chain's functionality.\n *\n * @enum {string}\n *\n * @example\n * ```typescript\n * // Using adapter types in configuration\n * const config = {\n * chainType: OrbitAdapter.EVM,\n * // other configuration...\n * };\n *\n * // Checking adapter compatibility\n * if (chainType === OrbitAdapter.SOLANA) {\n * // Solana-specific logic\n * }\n * ```\n */\nexport enum OrbitAdapter {\n /**\n * For Ethereum Virtual Machine (EVM) compatible chains.\n * Supports networks like:\n * - Ethereum Mainnet\n * - Polygon\n * - Binance Smart Chain\n * - Avalanche\n * - Other EVM-compatible L1/L2 chains\n */\n EVM = 'evm',\n\n /**\n * For the Solana blockchain.\n * Supports:\n * - Solana Mainnet\n * - Devnet\n * - Testnet\n */\n SOLANA = 'solana',\n\n /**\n * For the Starknet L2 network.\n * Supports:\n * - Starknet Mainnet\n * - Testnet (Goerli)\n * - Other Starknet deployments\n */\n Starknet = 'starknet',\n}\n\n/**\n * Generic type for creating blockchain adapters with type safety.\n * This type ensures that all adapters implement the required interface\n * and are properly keyed by their blockchain type.\n *\n * @typeParam A - Type that extends the base adapter interface with a key property\n *\n * @property {A | A[]} adapter - Single adapter instance or array of adapters\n *\n * @example\n * ```typescript\n * // Single adapter implementation\n * interface EVMAdapter extends BaseAdapter {\n * key: OrbitAdapter.EVM;\n * // EVM-specific methods...\n * }\n * const evmConfig: OrbitGenericAdapter<EVMAdapter> = {\n * adapter: {\n * key: OrbitAdapter.EVM,\n * // implementation...\n * }\n * };\n *\n * // Multiple adapters\n * const multiChainConfig: OrbitGenericAdapter<EVMAdapter> = {\n * adapter: [\n * { key: OrbitAdapter.EVM, ... },\n * { key: OrbitAdapter.SOLANA, ... }\n * ]\n * };\n * ```\n */\nexport type OrbitGenericAdapter<A extends { key: OrbitAdapter }> = {\n adapter: A | A[];\n};\n\nexport type BaseAdapter = {\n /**\n * Generates blockchain explorer URL\n * @returns Explorer URL or undefined if not available\n */\n getExplorerUrl: (url?: string, chainId?: string | number) => string | undefined;\n\n /** Optional method to resolve ENS-like names */\n getName?: (address: string) => Promise<string | null>;\n\n /** Optional method to get avatar for resolved names */\n getAvatar?: (name: string) => Promise<string | null>;\n};\n","/**\n * Helper utilities for managing impersonated wallet addresses\n *\n * @remarks\n * These utilities are primarily used for development and testing purposes.\n * They provide a way to simulate different wallet addresses without actually connecting a wallet.\n * All data is stored in localStorage with the 'satellite-connect:impersonatedAddress' key.\n * Functions are safe to use in both browser and SSR environments.\n */\nexport const connectedWalletChainHelpers = {\n /**\n * Currently impersonated address from localStorage\n * Returns empty string if not set or in SSR context\n */\n connectedWalletChain:\n typeof window !== 'undefined' ? (window.localStorage.getItem('orbit-core:connectedWalletChain') ?? '') : '',\n\n /**\n * Stores an impersonated address in localStorage\n *\n * @example\n * ```typescript\n * // Set impersonated address\n * impersonatedHelpers.setImpersonated('0x1234...5678');\n * ```\n *\n * @param address - Ethereum or Solana address to impersonate\n * @returns undefined in SSR context, void in browser\n */\n setConnectedWalletChain: (chain: string | number) =>\n typeof window !== 'undefined'\n ? window.localStorage.setItem('orbit-core:connectedWalletChain', String(chain))\n : undefined,\n\n /**\n * Retrieves the current impersonated address from localStorage\n *\n * @example\n * ```typescript\n * // Get current impersonated address\n * const address = impersonatedHelpers.getImpersonated();\n * if (address) {\n * console.log('Currently impersonating:', address);\n * }\n * ```\n * @returns The impersonated address or undefined if not set or in SSR context\n */\n getConnectedWalletChain: () =>\n typeof window !== 'undefined' ? window.localStorage.getItem('orbit-core:connectedWalletChain') : undefined,\n\n removeConnectedWalletChain: () =>\n typeof window !== 'undefined' ? window.localStorage.removeItem('orbit-core:connectedWalletChain') : undefined,\n};\n","/**\n * @file This file provides a utility for creating a type-safe, bounded Zustand hook from a vanilla store.\n * This pattern is recommended by the official Zustand documentation to ensure full type\n * safety when integrating vanilla stores with React.\n *\n * @see https://docs.pmnd.rs/zustand/guides/typescript#bounded-usestore-hook-for-vanilla-stores\n */\n\nimport { StoreApi, useStore } from 'zustand';\n\n/**\n * A utility type that infers the state shape from a Zustand `StoreApi`.\n * It extracts the return type of the `getState` method.\n * @template S - The type of the Zustand store (`StoreApi`).\n */\ntype ExtractState<S> = S extends { getState: () => infer T } ? T : never;\n\n/**\n * Creates a bounded `useStore` hook from a vanilla Zustand store.\n *\n * This function takes a vanilla Zustand store instance and returns a React hook\n * that is pre-bound to that store. This approach provides a cleaner API and\n * enhances type inference, eliminating the need to pass the store instance\n * on every use.\n *\n * The returned hook supports two signatures:\n * 1. `useBoundedStore()`: Selects the entire state.\n * 2. `useBoundedStore(selector)`: Selects a slice of the state, returning only what the selector function specifies.\n *\n * @template S - The type of the Zustand store (`StoreApi`).\n * @param {S} store - The vanilla Zustand store instance to bind the hook to.\n * @returns {function} A fully typed React hook for accessing the store's state.\n */\nexport const createBoundedUseStore = ((store) => (selector) => useStore(store, selector)) as <\n S extends StoreApi<unknown>,\n>(\n store: S,\n) => {\n // This implementation uses a Immediately Invoked Function Expression (IIFE)\n // trick combined with casting to achieve the desired overloaded function signature in a concise way.\n (): ExtractState<S>;\n <T>(selector: (state: ExtractState<S>) => T): T;\n};\n","/**\n * @name delay\n *\n * Ensures the global 'window' object is available (if running in a browser-like environment),\n * then pauses execution for a specified duration, and finally resolves the Promise with the given value.\n *\n * This utility function is designed to be safe for use in Server-Side Rendering (SSR) environments.\n * It asynchronously waits for the 'window' object to be defined before starting the actual timer,\n * helping to prevent errors during the initial server render while still providing a time delay on the client.\n *\n * @template T - The type of the value being resolved.\n *\n * @param {T} value - The value to resolve the Promise with after the delay.\n * @param {number} ms - The number of milliseconds (delay) to wait before resolving the Promise after 'window' is available.\n *\n * @returns {Promise<T>} A Promise that resolves with the provided `value` after both the 'window' check and the delay (`ms`) are complete.\n *\n * @example\n * ```typescript\n * // Use this in an environment where 'window' might not be immediately available (e.g., Next.js component).\n * async function waitForWindowAndDelay() {\n * console.log(\"Start wait...\");\n * // This will wait for window, and then wait 100ms.\n * const data = await delay(\"Ready to connect\", 100);\n * console.log(data);\n * }\n * waitForWindowAndDelay();\n * ```\n */\nexport const delay = <T>(value: T, ms: number): Promise<T> => {\n return new Promise((resolve) => {\n const runTimeout = () => {\n setTimeout(() => resolve(value), ms);\n };\n\n if (typeof window !== 'undefined') {\n runTimeout();\n } else {\n setTimeout(runTimeout, 0);\n }\n });\n};\n","import { OrbitAdapter } from '../types';\n\nexport function formatWalletChainId(chainId: string | number, connectedAdapter: OrbitAdapter) {\n if (typeof chainId === 'string') {\n return `${connectedAdapter}:${chainId}`;\n } else {\n return chainId;\n }\n}\n","import { OrbitAdapter } from '../types';\n\n/**\n * Generates a standardized wallet type identifier from adapter type and connector name\n *\n * @example\n * ```typescript\n * // Returns \"evm:metamask\"\n * getWalletTypeFromConnectorName(OrbitAdapter.EVM, \"MetaMask\");\n *\n * // Returns \"solana:phantom\"\n * getWalletTypeFromConnectorName(OrbitAdapter.SOLANA, \"Phantom\");\n *\n * // Returns \"evm:coinbasewallet\" (removes spaces)\n * getWalletTypeFromConnectorName(OrbitAdapter.EVM, \"Coinbase Wallet\");\n * ```\n *\n * @param adapter - The blockchain adapter type (e.g. EVM, SOLANA)\n * @param name - The wallet connector name (e.g. \"MetaMask\", \"Phantom\")\n * @returns A formatted wallet type string in format \"chain:wallet\"\n *\n * @remarks\n * The function:\n * 1. Combines adapter type with connector name using \":\" as separator\n * 2. Removes all whitespace from connector name\n * 3. Converts connector name to lowercase\n * This ensures consistent wallet type identifiers across the application\n */\nexport function getWalletTypeFromConnectorName(adapter: OrbitAdapter, name: string): string {\n return `${adapter}:${name.replace(/\\s+/g, '').toLowerCase()}`;\n}\n","/**\n * @file\n * This module provides adapter selection functionality for the Orbit system.\n * Part of the core infrastructure for managing blockchain adapters.\n */\n\nimport { OrbitAdapter, OrbitGenericAdapter } from '../types';\n\n/**\n * Selects an appropriate adapter based on the provided key from either a single adapter\n * or an array of adapters.\n *\n * @typeParam A - Type extending basic adapter interface with a key property\n *\n * @param options - Selection configuration object\n * @param options.adapterKey - Target adapter key to search for\n * @param options.adapter - Single adapter or array of adapters to search within\n *\n * @returns Selected adapter or undefined if no suitable adapter found\n *\n * @remarks\n * If an array is provided but no matching adapter is found, falls back to the first adapter\n * in the array with a warning message.\n *\n * @example\n * ```typescript\n * // Single adapter usage\n * const singleResult = selectAdapterByKey({\n * adapterKey: OrbitAdapter.SOLANA,\n * adapter: { key: OrbitAdapter.SOLANA, connect: async () => {...} }\n * });\n *\n * // Multiple adapters usage\n * const multiResult = selectAdapterByKey({\n * adapterKey: OrbitAdapter.EVM,\n * adapter: [\n * { key: OrbitAdapter.SOLANA, connect: async () => {...} },\n * { key: OrbitAdapter.EVM, connect: async () => {...} }\n * ]\n * });\n * ```\n *\n * @throws {Error} Logs error if adapter array is empty\n * @throws {Warning} Logs warning if requested adapter key not found in array\n */\nexport const selectAdapterByKey = <A extends { key: OrbitAdapter }>({\n adapterKey,\n adapter,\n}: { adapterKey: OrbitAdapter } & OrbitGenericAdapter<A>): A | undefined => {\n if (Array.isArray(adapter)) {\n if (adapter.length === 0) {\n console.error('Adapter selection failed: The provided adapters array is empty.');\n return undefined;\n }\n\n const foundAdapter = adapter.find((a) => a.key === adapterKey);\n\n if (foundAdapter) {\n return foundAdapter;\n } else {\n console.warn(\n `No adapter found for key: \"${adapterKey}\". Falling back to the first available adapter: \"${adapter[0].key}\".`,\n );\n return adapter[0];\n }\n }\n return adapter;\n};\n","/**\n * Checks whether the given chain ID belongs to a Solana network.\n * Supports common Solana network names: 'devnet', 'testnet', 'mainnet-beta', 'mainnet'.\n *\n * @param {number | string} chainId - The chain ID or chain name.\n * @returns {boolean} - True if the chain ID corresponds to a Solana network, false otherwise.\n */\nexport function isSolanaChain(chainId: number | string): boolean {\n if (typeof chainId === 'string') {\n return ['devnet', 'testnet', 'mainnet-beta', 'mainnet'].includes(chainId);\n }\n return false;\n}\n\n/**\n * Sets the chain ID to a Solana-specific format if the chain is a Solana network.\n *\n * @param {number | string} chainId - The original chain ID or name.\n * @returns {string | number} - The formatted chain ID prefixed with 'solana:' if Solana, otherwise the original.\n */\nexport function setChainId(chainId: number | string): string | number {\n if (isSolanaChain(chainId)) {\n return `solana:${chainId}`;\n } else {\n return chainId;\n }\n}\n"]}
|
package/dist/index.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {useStore}from'zustand';var o=(r=>(r.EVM="evm",r.SOLANA="solana",r.Starknet="starknet",r))(o||{});var
|
|
1
|
+
import {useStore}from'zustand';var o=(r=>(r.EVM="evm",r.SOLANA="solana",r.Starknet="starknet",r))(o||{});var d={connectedWalletChain:typeof window<"u"?window.localStorage.getItem("orbit-core:connectedWalletChain")??"":"",setConnectedWalletChain:e=>typeof window<"u"?window.localStorage.setItem("orbit-core:connectedWalletChain",String(e)):void 0,getConnectedWalletChain:()=>typeof window<"u"?window.localStorage.getItem("orbit-core:connectedWalletChain"):void 0,removeConnectedWalletChain:()=>typeof window<"u"?window.localStorage.removeItem("orbit-core:connectedWalletChain"):void 0};var c=(e=>t=>useStore(e,t));var u=(e,t)=>new Promise(n=>{let r=()=>{setTimeout(()=>n(e),t);};typeof window<"u"?r():setTimeout(r,0);});function g(e,t){return typeof e=="string"?`${t}:${e}`:e}function A(e,t){return `${e}:${t.replace(/\s+/g,"").toLowerCase()}`}var y=({adapterKey:e,adapter:t})=>{if(Array.isArray(t)){if(t.length===0){console.error("Adapter selection failed: The provided adapters array is empty.");return}let n=t.find(r=>r.key===e);return n||(console.warn(`No adapter found for key: "${e}". Falling back to the first available adapter: "${t[0].key}".`),t[0])}return t};function a(e){return typeof e=="string"?["devnet","testnet","mainnet-beta","mainnet"].includes(e):false}function T(e){return a(e)?`solana:${e}`:e}export{o as OrbitAdapter,d as connectedWalletChainHelpers,c as createBoundedUseStore,u as delay,g as formatWalletChainId,A as getWalletTypeFromConnectorName,a as isSolanaChain,y as selectAdapterByKey,T as setChainId};//# sourceMappingURL=index.mjs.map
|
|
2
2
|
//# sourceMappingURL=index.mjs.map
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/types.ts","../src/utils/connectedWalletChainHelpers.ts","../src/utils/createBoundedUseStore.ts","../src/utils/formatWalletChainId.ts","../src/utils/getWalletTypeFromConnectorName.ts","../src/utils/selectAdapterByKey.ts","../src/utils/%D1%81hainHelpers.ts"],"names":["OrbitAdapter","connectedWalletChainHelpers","chain","createBoundedUseStore","store","selector","useStore","formatWalletChainId","chainId","connectedAdapter","getWalletTypeFromConnectorName","adapter","name","selectAdapterByKey","adapterKey","foundAdapter","a","isSolanaChain","setChainId"],"mappings":"+BA4CO,IAAKA,CAAAA,CAAAA,CAAAA,CAAAA,GAUVA,EAAA,GAAA,CAAM,KAAA,CASNA,EAAA,MAAA,CAAS,QAAA,CASTA,EAAA,QAAA,CAAW,UAAA,CA5BDA,OAAA,EAAA,ECnCL,IAAMC,EAA8B,CAKzC,oBAAA,CACE,OAAO,MAAA,CAAW,GAAA,CAAe,OAAO,YAAA,CAAa,OAAA,CAAQ,iCAAiC,CAAA,EAAK,EAAA,CAAM,GAc3G,uBAAA,CAA0BC,CAAAA,EACxB,OAAO,MAAA,CAAW,GAAA,CACd,OAAO,YAAA,CAAa,OAAA,CAAQ,kCAAmC,MAAA,CAAOA,CAAK,CAAC,CAAA,CAC5E,MAAA,CAeN,wBAAyB,IACvB,OAAO,MAAA,CAAW,GAAA,CAAc,MAAA,CAAO,YAAA,CAAa,QAAQ,iCAAiC,CAAA,CAAI,OAEnG,0BAAA,CAA4B,IAC1B,OAAO,MAAA,CAAW,GAAA,CAAc,OAAO,YAAA,CAAa,UAAA,CAAW,iCAAiC,CAAA,CAAI,MACxG,ECnBO,IAAMC,CAAAA,EAA0BC,CAAAA,EAAWC,CAAAA,EAAaC,QAAAA,CAASF,EAAOC,CAAQ,CAAA,EC/BhF,SAASE,CAAAA,CAAoBC,CAAAA,CAA0BC,EAAgC,CAC5F,OAAI,OAAOD,CAAAA,EAAY,QAAA,CACd,GAAGC,CAAgB,CAAA,CAAA,EAAID,CAAO,CAAA,CAAA,CAE9BA,CAEX,CCoBO,SAASE,CAAAA,CAA+BC,CAAAA,CAAuBC,CAAAA,CAAsB,CAC1F,OAAO,GAAGD,CAAO,CAAA,CAAA,EAAIC,EAAK,OAAA,CAAQ,MAAA,CAAQ,EAAE,CAAA,CAAE,WAAA,EAAa,CAAA,CAC7D,KCeaC,CAAAA,CAAqB,CAAkC,CAClE,UAAA,CAAAC,CAAAA,CACA,QAAAH,CACF,CAAA,GAA4E,CAC1E,GAAI,KAAA,CAAM,OAAA,CAAQA,CAAO,CAAA,CAAG,CAC1B,GAAIA,CAAAA,CAAQ,MAAA,GAAW,EAAG,CACxB,OAAA,CAAQ,MAAM,iEAAiE,CAAA,CAC/E,MACF,CAEA,IAAMI,EAAeJ,CAAAA,CAAQ,IAAA,CAAMK,GAAMA,CAAAA,CAAE,GAAA,GAAQF,CAAU,CAAA,CAE7D,OAAIC,CAAAA,GAGF,QAAQ,IAAA,CACN,CAAA,2BAAA,EAA8BD,CAAU,CAAA,iDAAA,EAAoDH,CAAAA,CAAQ,CAAC,CAAA,CAAE,GAAG,IAC5G,CAAA,CACOA,CAAAA,CAAQ,CAAC,CAAA,CAEpB,CACA,OAAOA,CACT,EC5DO,SAASM,CAAAA,CAAcT,CAAAA,CAAmC,CAC/D,OAAI,OAAOA,CAAAA,EAAY,SACd,CAAC,QAAA,CAAU,UAAW,cAAA,CAAgB,SAAS,EAAE,QAAA,CAASA,CAAO,EAEnE,KACT,CAQO,SAASU,CAAAA,CAAWV,CAAAA,CAA2C,CACpE,OAAIS,CAAAA,CAAcT,CAAO,CAAA,CAChB,CAAA,OAAA,EAAUA,CAAO,CAAA,CAAA,CAEjBA,CAEX","file":"index.mjs","sourcesContent":["/**\n * @file\n * Core type definitions for the Orbit blockchain adapter system.\n * This file contains fundamental enums and types that define the supported blockchain architectures\n * and their adapter interfaces.\n */\n\nimport { StoreApi } from 'zustand';\n\n/**\n * A utility type for creating modular Zustand store slices, enabling composable state management.\n * @template T The state slice being defined.\n * @template S The full store state that includes the slice `T`.\n */\nexport type StoreSlice<T extends object, S extends object = T> = (\n set: StoreApi<S extends T ? S : S & T>['setState'],\n get: StoreApi<S extends T ? S : S & T>['getState'],\n) => T;\n\n// =================================================================================================\n// 1. ENUMS AND CORE TRANSACTION TYPES\n// =================================================================================================\n\n/**\n * Defines the supported blockchain adapters in the Orbit system.\n * Each adapter corresponds to a specific blockchain architecture and implements\n * the necessary interfaces for that chain's functionality.\n *\n * @enum {string}\n *\n * @example\n * ```typescript\n * // Using adapter types in configuration\n * const config = {\n * chainType: OrbitAdapter.EVM,\n * // other configuration...\n * };\n *\n * // Checking adapter compatibility\n * if (chainType === OrbitAdapter.SOLANA) {\n * // Solana-specific logic\n * }\n * ```\n */\nexport enum OrbitAdapter {\n /**\n * For Ethereum Virtual Machine (EVM) compatible chains.\n * Supports networks like:\n * - Ethereum Mainnet\n * - Polygon\n * - Binance Smart Chain\n * - Avalanche\n * - Other EVM-compatible L1/L2 chains\n */\n EVM = 'evm',\n\n /**\n * For the Solana blockchain.\n * Supports:\n * - Solana Mainnet\n * - Devnet\n * - Testnet\n */\n SOLANA = 'solana',\n\n /**\n * For the Starknet L2 network.\n * Supports:\n * - Starknet Mainnet\n * - Testnet (Goerli)\n * - Other Starknet deployments\n */\n Starknet = 'starknet',\n}\n\n/**\n * Generic type for creating blockchain adapters with type safety.\n * This type ensures that all adapters implement the required interface\n * and are properly keyed by their blockchain type.\n *\n * @typeParam A - Type that extends the base adapter interface with a key property\n *\n * @property {A | A[]} adapter - Single adapter instance or array of adapters\n *\n * @example\n * ```typescript\n * // Single adapter implementation\n * interface EVMAdapter extends BaseAdapter {\n * key: OrbitAdapter.EVM;\n * // EVM-specific methods...\n * }\n * const evmConfig: OrbitGenericAdapter<EVMAdapter> = {\n * adapter: {\n * key: OrbitAdapter.EVM,\n * // implementation...\n * }\n * };\n *\n * // Multiple adapters\n * const multiChainConfig: OrbitGenericAdapter<EVMAdapter> = {\n * adapter: [\n * { key: OrbitAdapter.EVM, ... },\n * { key: OrbitAdapter.SOLANA, ... }\n * ]\n * };\n * ```\n */\nexport type OrbitGenericAdapter<A extends { key: OrbitAdapter }> = {\n adapter: A | A[];\n};\n\nexport type BaseAdapter = {\n /**\n * Generates blockchain explorer URL\n * @returns Explorer URL or undefined if not available\n */\n getExplorerUrl: (url?: string, chainId?: string | number) => string | undefined;\n\n /** Optional method to resolve ENS-like names */\n getName?: (address: string) => Promise<string | null>;\n\n /** Optional method to get avatar for resolved names */\n getAvatar?: (name: string) => Promise<string | null>;\n};\n","/**\n * Helper utilities for managing impersonated wallet addresses\n *\n * @remarks\n * These utilities are primarily used for development and testing purposes.\n * They provide a way to simulate different wallet addresses without actually connecting a wallet.\n * All data is stored in localStorage with the 'satellite-connect:impersonatedAddress' key.\n * Functions are safe to use in both browser and SSR environments.\n */\nexport const connectedWalletChainHelpers = {\n /**\n * Currently impersonated address from localStorage\n * Returns empty string if not set or in SSR context\n */\n connectedWalletChain:\n typeof window !== 'undefined' ? (window.localStorage.getItem('orbit-core:connectedWalletChain') ?? '') : '',\n\n /**\n * Stores an impersonated address in localStorage\n *\n * @example\n * ```typescript\n * // Set impersonated address\n * impersonatedHelpers.setImpersonated('0x1234...5678');\n * ```\n *\n * @param address - Ethereum or Solana address to impersonate\n * @returns undefined in SSR context, void in browser\n */\n setConnectedWalletChain: (chain: string | number) =>\n typeof window !== 'undefined'\n ? window.localStorage.setItem('orbit-core:connectedWalletChain', String(chain))\n : undefined,\n\n /**\n * Retrieves the current impersonated address from localStorage\n *\n * @example\n * ```typescript\n * // Get current impersonated address\n * const address = impersonatedHelpers.getImpersonated();\n * if (address) {\n * console.log('Currently impersonating:', address);\n * }\n * ```\n * @returns The impersonated address or undefined if not set or in SSR context\n */\n getConnectedWalletChain: () =>\n typeof window !== 'undefined' ? window.localStorage.getItem('orbit-core:connectedWalletChain') : undefined,\n\n removeConnectedWalletChain: () =>\n typeof window !== 'undefined' ? window.localStorage.removeItem('orbit-core:connectedWalletChain') : undefined,\n};\n","/**\n * @file This file provides a utility for creating a type-safe, bounded Zustand hook from a vanilla store.\n * This pattern is recommended by the official Zustand documentation to ensure full type\n * safety when integrating vanilla stores with React.\n *\n * @see https://docs.pmnd.rs/zustand/guides/typescript#bounded-usestore-hook-for-vanilla-stores\n */\n\nimport { StoreApi, useStore } from 'zustand';\n\n/**\n * A utility type that infers the state shape from a Zustand `StoreApi`.\n * It extracts the return type of the `getState` method.\n * @template S - The type of the Zustand store (`StoreApi`).\n */\ntype ExtractState<S> = S extends { getState: () => infer T } ? T : never;\n\n/**\n * Creates a bounded `useStore` hook from a vanilla Zustand store.\n *\n * This function takes a vanilla Zustand store instance and returns a React hook\n * that is pre-bound to that store. This approach provides a cleaner API and\n * enhances type inference, eliminating the need to pass the store instance\n * on every use.\n *\n * The returned hook supports two signatures:\n * 1. `useBoundedStore()`: Selects the entire state.\n * 2. `useBoundedStore(selector)`: Selects a slice of the state, returning only what the selector function specifies.\n *\n * @template S - The type of the Zustand store (`StoreApi`).\n * @param {S} store - The vanilla Zustand store instance to bind the hook to.\n * @returns {function} A fully typed React hook for accessing the store's state.\n */\nexport const createBoundedUseStore = ((store) => (selector) => useStore(store, selector)) as <\n S extends StoreApi<unknown>,\n>(\n store: S,\n) => {\n // This implementation uses a Immediately Invoked Function Expression (IIFE)\n // trick combined with casting to achieve the desired overloaded function signature in a concise way.\n (): ExtractState<S>;\n <T>(selector: (state: ExtractState<S>) => T): T;\n};\n","import { OrbitAdapter } from '../types';\n\nexport function formatWalletChainId(chainId: string | number, connectedAdapter: OrbitAdapter) {\n if (typeof chainId === 'string') {\n return `${connectedAdapter}:${chainId}`;\n } else {\n return chainId;\n }\n}\n","import { OrbitAdapter } from '../types';\n\n/**\n * Generates a standardized wallet type identifier from adapter type and connector name\n *\n * @example\n * ```typescript\n * // Returns \"evm:metamask\"\n * getWalletTypeFromConnectorName(OrbitAdapter.EVM, \"MetaMask\");\n *\n * // Returns \"solana:phantom\"\n * getWalletTypeFromConnectorName(OrbitAdapter.SOLANA, \"Phantom\");\n *\n * // Returns \"evm:coinbasewallet\" (removes spaces)\n * getWalletTypeFromConnectorName(OrbitAdapter.EVM, \"Coinbase Wallet\");\n * ```\n *\n * @param adapter - The blockchain adapter type (e.g. EVM, SOLANA)\n * @param name - The wallet connector name (e.g. \"MetaMask\", \"Phantom\")\n * @returns A formatted wallet type string in format \"chain:wallet\"\n *\n * @remarks\n * The function:\n * 1. Combines adapter type with connector name using \":\" as separator\n * 2. Removes all whitespace from connector name\n * 3. Converts connector name to lowercase\n * This ensures consistent wallet type identifiers across the application\n */\nexport function getWalletTypeFromConnectorName(adapter: OrbitAdapter, name: string): string {\n return `${adapter}:${name.replace(/\\s+/g, '').toLowerCase()}`;\n}\n","/**\n * @file\n * This module provides adapter selection functionality for the Orbit system.\n * Part of the core infrastructure for managing blockchain adapters.\n */\n\nimport { OrbitAdapter, OrbitGenericAdapter } from '../types';\n\n/**\n * Selects an appropriate adapter based on the provided key from either a single adapter\n * or an array of adapters.\n *\n * @typeParam A - Type extending basic adapter interface with a key property\n *\n * @param options - Selection configuration object\n * @param options.adapterKey - Target adapter key to search for\n * @param options.adapter - Single adapter or array of adapters to search within\n *\n * @returns Selected adapter or undefined if no suitable adapter found\n *\n * @remarks\n * If an array is provided but no matching adapter is found, falls back to the first adapter\n * in the array with a warning message.\n *\n * @example\n * ```typescript\n * // Single adapter usage\n * const singleResult = selectAdapterByKey({\n * adapterKey: OrbitAdapter.SOLANA,\n * adapter: { key: OrbitAdapter.SOLANA, connect: async () => {...} }\n * });\n *\n * // Multiple adapters usage\n * const multiResult = selectAdapterByKey({\n * adapterKey: OrbitAdapter.EVM,\n * adapter: [\n * { key: OrbitAdapter.SOLANA, connect: async () => {...} },\n * { key: OrbitAdapter.EVM, connect: async () => {...} }\n * ]\n * });\n * ```\n *\n * @throws {Error} Logs error if adapter array is empty\n * @throws {Warning} Logs warning if requested adapter key not found in array\n */\nexport const selectAdapterByKey = <A extends { key: OrbitAdapter }>({\n adapterKey,\n adapter,\n}: { adapterKey: OrbitAdapter } & OrbitGenericAdapter<A>): A | undefined => {\n if (Array.isArray(adapter)) {\n if (adapter.length === 0) {\n console.error('Adapter selection failed: The provided adapters array is empty.');\n return undefined;\n }\n\n const foundAdapter = adapter.find((a) => a.key === adapterKey);\n\n if (foundAdapter) {\n return foundAdapter;\n } else {\n console.warn(\n `No adapter found for key: \"${adapterKey}\". Falling back to the first available adapter: \"${adapter[0].key}\".`,\n );\n return adapter[0];\n }\n }\n return adapter;\n};\n","/**\n * Checks whether the given chain ID belongs to a Solana network.\n * Supports common Solana network names: 'devnet', 'testnet', 'mainnet-beta', 'mainnet'.\n *\n * @param {number | string} chainId - The chain ID or chain name.\n * @returns {boolean} - True if the chain ID corresponds to a Solana network, false otherwise.\n */\nexport function isSolanaChain(chainId: number | string): boolean {\n if (typeof chainId === 'string') {\n return ['devnet', 'testnet', 'mainnet-beta', 'mainnet'].includes(chainId);\n }\n return false;\n}\n\n/**\n * Sets the chain ID to a Solana-specific format if the chain is a Solana network.\n *\n * @param {number | string} chainId - The original chain ID or name.\n * @returns {string | number} - The formatted chain ID prefixed with 'solana:' if Solana, otherwise the original.\n */\nexport function setChainId(chainId: number | string): string | number {\n if (isSolanaChain(chainId)) {\n return `solana:${chainId}`;\n } else {\n return chainId;\n }\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/types.ts","../src/utils/connectedWalletChainHelpers.ts","../src/utils/createBoundedUseStore.ts","../src/utils/delay.ts","../src/utils/formatWalletChainId.ts","../src/utils/getWalletTypeFromConnectorName.ts","../src/utils/selectAdapterByKey.ts","../src/utils/%D1%81hainHelpers.ts"],"names":["OrbitAdapter","connectedWalletChainHelpers","chain","createBoundedUseStore","store","selector","useStore","delay","value","ms","resolve","runTimeout","formatWalletChainId","chainId","connectedAdapter","getWalletTypeFromConnectorName","adapter","name","selectAdapterByKey","adapterKey","foundAdapter","a","isSolanaChain","setChainId"],"mappings":"+BA4CO,IAAKA,CAAAA,CAAAA,CAAAA,CAAAA,GAUVA,CAAAA,CAAA,GAAA,CAAM,KAAA,CASNA,CAAAA,CAAA,OAAS,QAAA,CASTA,CAAAA,CAAA,QAAA,CAAW,UAAA,CA5BDA,CAAAA,CAAAA,EAAAA,CAAAA,EAAA,EAAA,MCnCCC,CAAAA,CAA8B,CAKzC,oBAAA,CACE,OAAO,MAAA,CAAW,GAAA,CAAe,OAAO,YAAA,CAAa,OAAA,CAAQ,iCAAiC,CAAA,EAAK,EAAA,CAAM,EAAA,CAc3G,wBAA0BC,CAAAA,EACxB,OAAO,MAAA,CAAW,GAAA,CACd,MAAA,CAAO,YAAA,CAAa,QAAQ,iCAAA,CAAmC,MAAA,CAAOA,CAAK,CAAC,CAAA,CAC5E,MAAA,CAeN,wBAAyB,IACvB,OAAO,MAAA,CAAW,GAAA,CAAc,MAAA,CAAO,YAAA,CAAa,OAAA,CAAQ,iCAAiC,CAAA,CAAI,MAAA,CAEnG,0BAAA,CAA4B,IAC1B,OAAO,MAAA,CAAW,IAAc,MAAA,CAAO,YAAA,CAAa,UAAA,CAAW,iCAAiC,CAAA,CAAI,MACxG,ECnBO,IAAMC,CAAAA,EAA0BC,GAAWC,CAAAA,EAAaC,QAAAA,CAASF,CAAAA,CAAOC,CAAQ,CAAA,ECJhF,IAAME,CAAAA,CAAQ,CAAIC,CAAAA,CAAUC,CAAAA,GAC1B,IAAI,OAAA,CAASC,CAAAA,EAAY,CAC9B,IAAMC,CAAAA,CAAa,IAAM,CACvB,UAAA,CAAW,IAAMD,CAAAA,CAAQF,CAAK,CAAA,CAAGC,CAAE,EACrC,CAAA,CAEI,OAAO,MAAA,CAAW,IACpBE,CAAAA,EAAW,CAEX,UAAA,CAAWA,CAAAA,CAAY,CAAC,EAE5B,CAAC,ECtCI,SAASC,CAAAA,CAAoBC,CAAAA,CAA0BC,CAAAA,CAAgC,CAC5F,OAAI,OAAOD,CAAAA,EAAY,QAAA,CACd,CAAA,EAAGC,CAAgB,CAAA,CAAA,EAAID,CAAO,GAE9BA,CAEX,CCoBO,SAASE,CAAAA,CAA+BC,CAAAA,CAAuBC,CAAAA,CAAsB,CAC1F,OAAO,CAAA,EAAGD,CAAO,CAAA,CAAA,EAAIC,CAAAA,CAAK,OAAA,CAAQ,MAAA,CAAQ,EAAE,CAAA,CAAE,WAAA,EAAa,CAAA,CAC7D,CCeO,IAAMC,EAAqB,CAAkC,CAClE,UAAA,CAAAC,CAAAA,CACA,OAAA,CAAAH,CACF,IAA4E,CAC1E,GAAI,KAAA,CAAM,OAAA,CAAQA,CAAO,CAAA,CAAG,CAC1B,GAAIA,CAAAA,CAAQ,MAAA,GAAW,CAAA,CAAG,CACxB,OAAA,CAAQ,KAAA,CAAM,iEAAiE,CAAA,CAC/E,MACF,CAEA,IAAMI,CAAAA,CAAeJ,CAAAA,CAAQ,KAAMK,CAAAA,EAAMA,CAAAA,CAAE,GAAA,GAAQF,CAAU,CAAA,CAE7D,OAAIC,IAGF,OAAA,CAAQ,IAAA,CACN,CAAA,2BAAA,EAA8BD,CAAU,CAAA,iDAAA,EAAoDH,CAAAA,CAAQ,CAAC,CAAA,CAAE,GAAG,CAAA,EAAA,CAC5G,CAAA,CACOA,CAAAA,CAAQ,CAAC,CAAA,CAEpB,CACA,OAAOA,CACT,EC5DO,SAASM,CAAAA,CAAcT,CAAAA,CAAmC,CAC/D,OAAI,OAAOA,CAAAA,EAAY,QAAA,CACd,CAAC,QAAA,CAAU,UAAW,cAAA,CAAgB,SAAS,CAAA,CAAE,QAAA,CAASA,CAAO,CAAA,CAEnE,KACT,CAQO,SAASU,CAAAA,CAAWV,CAAAA,CAA2C,CACpE,OAAIS,CAAAA,CAAcT,CAAO,CAAA,CAChB,CAAA,OAAA,EAAUA,CAAO,CAAA,CAAA,CAEjBA,CAEX","file":"index.mjs","sourcesContent":["/**\n * @file\n * Core type definitions for the Orbit blockchain adapter system.\n * This file contains fundamental enums and types that define the supported blockchain architectures\n * and their adapter interfaces.\n */\n\nimport { StoreApi } from 'zustand';\n\n/**\n * A utility type for creating modular Zustand store slices, enabling composable state management.\n * @template T The state slice being defined.\n * @template S The full store state that includes the slice `T`.\n */\nexport type StoreSlice<T extends object, S extends object = T> = (\n set: StoreApi<S extends T ? S : S & T>['setState'],\n get: StoreApi<S extends T ? S : S & T>['getState'],\n) => T;\n\n// =================================================================================================\n// 1. ENUMS AND CORE TRANSACTION TYPES\n// =================================================================================================\n\n/**\n * Defines the supported blockchain adapters in the Orbit system.\n * Each adapter corresponds to a specific blockchain architecture and implements\n * the necessary interfaces for that chain's functionality.\n *\n * @enum {string}\n *\n * @example\n * ```typescript\n * // Using adapter types in configuration\n * const config = {\n * chainType: OrbitAdapter.EVM,\n * // other configuration...\n * };\n *\n * // Checking adapter compatibility\n * if (chainType === OrbitAdapter.SOLANA) {\n * // Solana-specific logic\n * }\n * ```\n */\nexport enum OrbitAdapter {\n /**\n * For Ethereum Virtual Machine (EVM) compatible chains.\n * Supports networks like:\n * - Ethereum Mainnet\n * - Polygon\n * - Binance Smart Chain\n * - Avalanche\n * - Other EVM-compatible L1/L2 chains\n */\n EVM = 'evm',\n\n /**\n * For the Solana blockchain.\n * Supports:\n * - Solana Mainnet\n * - Devnet\n * - Testnet\n */\n SOLANA = 'solana',\n\n /**\n * For the Starknet L2 network.\n * Supports:\n * - Starknet Mainnet\n * - Testnet (Goerli)\n * - Other Starknet deployments\n */\n Starknet = 'starknet',\n}\n\n/**\n * Generic type for creating blockchain adapters with type safety.\n * This type ensures that all adapters implement the required interface\n * and are properly keyed by their blockchain type.\n *\n * @typeParam A - Type that extends the base adapter interface with a key property\n *\n * @property {A | A[]} adapter - Single adapter instance or array of adapters\n *\n * @example\n * ```typescript\n * // Single adapter implementation\n * interface EVMAdapter extends BaseAdapter {\n * key: OrbitAdapter.EVM;\n * // EVM-specific methods...\n * }\n * const evmConfig: OrbitGenericAdapter<EVMAdapter> = {\n * adapter: {\n * key: OrbitAdapter.EVM,\n * // implementation...\n * }\n * };\n *\n * // Multiple adapters\n * const multiChainConfig: OrbitGenericAdapter<EVMAdapter> = {\n * adapter: [\n * { key: OrbitAdapter.EVM, ... },\n * { key: OrbitAdapter.SOLANA, ... }\n * ]\n * };\n * ```\n */\nexport type OrbitGenericAdapter<A extends { key: OrbitAdapter }> = {\n adapter: A | A[];\n};\n\nexport type BaseAdapter = {\n /**\n * Generates blockchain explorer URL\n * @returns Explorer URL or undefined if not available\n */\n getExplorerUrl: (url?: string, chainId?: string | number) => string | undefined;\n\n /** Optional method to resolve ENS-like names */\n getName?: (address: string) => Promise<string | null>;\n\n /** Optional method to get avatar for resolved names */\n getAvatar?: (name: string) => Promise<string | null>;\n};\n","/**\n * Helper utilities for managing impersonated wallet addresses\n *\n * @remarks\n * These utilities are primarily used for development and testing purposes.\n * They provide a way to simulate different wallet addresses without actually connecting a wallet.\n * All data is stored in localStorage with the 'satellite-connect:impersonatedAddress' key.\n * Functions are safe to use in both browser and SSR environments.\n */\nexport const connectedWalletChainHelpers = {\n /**\n * Currently impersonated address from localStorage\n * Returns empty string if not set or in SSR context\n */\n connectedWalletChain:\n typeof window !== 'undefined' ? (window.localStorage.getItem('orbit-core:connectedWalletChain') ?? '') : '',\n\n /**\n * Stores an impersonated address in localStorage\n *\n * @example\n * ```typescript\n * // Set impersonated address\n * impersonatedHelpers.setImpersonated('0x1234...5678');\n * ```\n *\n * @param address - Ethereum or Solana address to impersonate\n * @returns undefined in SSR context, void in browser\n */\n setConnectedWalletChain: (chain: string | number) =>\n typeof window !== 'undefined'\n ? window.localStorage.setItem('orbit-core:connectedWalletChain', String(chain))\n : undefined,\n\n /**\n * Retrieves the current impersonated address from localStorage\n *\n * @example\n * ```typescript\n * // Get current impersonated address\n * const address = impersonatedHelpers.getImpersonated();\n * if (address) {\n * console.log('Currently impersonating:', address);\n * }\n * ```\n * @returns The impersonated address or undefined if not set or in SSR context\n */\n getConnectedWalletChain: () =>\n typeof window !== 'undefined' ? window.localStorage.getItem('orbit-core:connectedWalletChain') : undefined,\n\n removeConnectedWalletChain: () =>\n typeof window !== 'undefined' ? window.localStorage.removeItem('orbit-core:connectedWalletChain') : undefined,\n};\n","/**\n * @file This file provides a utility for creating a type-safe, bounded Zustand hook from a vanilla store.\n * This pattern is recommended by the official Zustand documentation to ensure full type\n * safety when integrating vanilla stores with React.\n *\n * @see https://docs.pmnd.rs/zustand/guides/typescript#bounded-usestore-hook-for-vanilla-stores\n */\n\nimport { StoreApi, useStore } from 'zustand';\n\n/**\n * A utility type that infers the state shape from a Zustand `StoreApi`.\n * It extracts the return type of the `getState` method.\n * @template S - The type of the Zustand store (`StoreApi`).\n */\ntype ExtractState<S> = S extends { getState: () => infer T } ? T : never;\n\n/**\n * Creates a bounded `useStore` hook from a vanilla Zustand store.\n *\n * This function takes a vanilla Zustand store instance and returns a React hook\n * that is pre-bound to that store. This approach provides a cleaner API and\n * enhances type inference, eliminating the need to pass the store instance\n * on every use.\n *\n * The returned hook supports two signatures:\n * 1. `useBoundedStore()`: Selects the entire state.\n * 2. `useBoundedStore(selector)`: Selects a slice of the state, returning only what the selector function specifies.\n *\n * @template S - The type of the Zustand store (`StoreApi`).\n * @param {S} store - The vanilla Zustand store instance to bind the hook to.\n * @returns {function} A fully typed React hook for accessing the store's state.\n */\nexport const createBoundedUseStore = ((store) => (selector) => useStore(store, selector)) as <\n S extends StoreApi<unknown>,\n>(\n store: S,\n) => {\n // This implementation uses a Immediately Invoked Function Expression (IIFE)\n // trick combined with casting to achieve the desired overloaded function signature in a concise way.\n (): ExtractState<S>;\n <T>(selector: (state: ExtractState<S>) => T): T;\n};\n","/**\n * @name delay\n *\n * Ensures the global 'window' object is available (if running in a browser-like environment),\n * then pauses execution for a specified duration, and finally resolves the Promise with the given value.\n *\n * This utility function is designed to be safe for use in Server-Side Rendering (SSR) environments.\n * It asynchronously waits for the 'window' object to be defined before starting the actual timer,\n * helping to prevent errors during the initial server render while still providing a time delay on the client.\n *\n * @template T - The type of the value being resolved.\n *\n * @param {T} value - The value to resolve the Promise with after the delay.\n * @param {number} ms - The number of milliseconds (delay) to wait before resolving the Promise after 'window' is available.\n *\n * @returns {Promise<T>} A Promise that resolves with the provided `value` after both the 'window' check and the delay (`ms`) are complete.\n *\n * @example\n * ```typescript\n * // Use this in an environment where 'window' might not be immediately available (e.g., Next.js component).\n * async function waitForWindowAndDelay() {\n * console.log(\"Start wait...\");\n * // This will wait for window, and then wait 100ms.\n * const data = await delay(\"Ready to connect\", 100);\n * console.log(data);\n * }\n * waitForWindowAndDelay();\n * ```\n */\nexport const delay = <T>(value: T, ms: number): Promise<T> => {\n return new Promise((resolve) => {\n const runTimeout = () => {\n setTimeout(() => resolve(value), ms);\n };\n\n if (typeof window !== 'undefined') {\n runTimeout();\n } else {\n setTimeout(runTimeout, 0);\n }\n });\n};\n","import { OrbitAdapter } from '../types';\n\nexport function formatWalletChainId(chainId: string | number, connectedAdapter: OrbitAdapter) {\n if (typeof chainId === 'string') {\n return `${connectedAdapter}:${chainId}`;\n } else {\n return chainId;\n }\n}\n","import { OrbitAdapter } from '../types';\n\n/**\n * Generates a standardized wallet type identifier from adapter type and connector name\n *\n * @example\n * ```typescript\n * // Returns \"evm:metamask\"\n * getWalletTypeFromConnectorName(OrbitAdapter.EVM, \"MetaMask\");\n *\n * // Returns \"solana:phantom\"\n * getWalletTypeFromConnectorName(OrbitAdapter.SOLANA, \"Phantom\");\n *\n * // Returns \"evm:coinbasewallet\" (removes spaces)\n * getWalletTypeFromConnectorName(OrbitAdapter.EVM, \"Coinbase Wallet\");\n * ```\n *\n * @param adapter - The blockchain adapter type (e.g. EVM, SOLANA)\n * @param name - The wallet connector name (e.g. \"MetaMask\", \"Phantom\")\n * @returns A formatted wallet type string in format \"chain:wallet\"\n *\n * @remarks\n * The function:\n * 1. Combines adapter type with connector name using \":\" as separator\n * 2. Removes all whitespace from connector name\n * 3. Converts connector name to lowercase\n * This ensures consistent wallet type identifiers across the application\n */\nexport function getWalletTypeFromConnectorName(adapter: OrbitAdapter, name: string): string {\n return `${adapter}:${name.replace(/\\s+/g, '').toLowerCase()}`;\n}\n","/**\n * @file\n * This module provides adapter selection functionality for the Orbit system.\n * Part of the core infrastructure for managing blockchain adapters.\n */\n\nimport { OrbitAdapter, OrbitGenericAdapter } from '../types';\n\n/**\n * Selects an appropriate adapter based on the provided key from either a single adapter\n * or an array of adapters.\n *\n * @typeParam A - Type extending basic adapter interface with a key property\n *\n * @param options - Selection configuration object\n * @param options.adapterKey - Target adapter key to search for\n * @param options.adapter - Single adapter or array of adapters to search within\n *\n * @returns Selected adapter or undefined if no suitable adapter found\n *\n * @remarks\n * If an array is provided but no matching adapter is found, falls back to the first adapter\n * in the array with a warning message.\n *\n * @example\n * ```typescript\n * // Single adapter usage\n * const singleResult = selectAdapterByKey({\n * adapterKey: OrbitAdapter.SOLANA,\n * adapter: { key: OrbitAdapter.SOLANA, connect: async () => {...} }\n * });\n *\n * // Multiple adapters usage\n * const multiResult = selectAdapterByKey({\n * adapterKey: OrbitAdapter.EVM,\n * adapter: [\n * { key: OrbitAdapter.SOLANA, connect: async () => {...} },\n * { key: OrbitAdapter.EVM, connect: async () => {...} }\n * ]\n * });\n * ```\n *\n * @throws {Error} Logs error if adapter array is empty\n * @throws {Warning} Logs warning if requested adapter key not found in array\n */\nexport const selectAdapterByKey = <A extends { key: OrbitAdapter }>({\n adapterKey,\n adapter,\n}: { adapterKey: OrbitAdapter } & OrbitGenericAdapter<A>): A | undefined => {\n if (Array.isArray(adapter)) {\n if (adapter.length === 0) {\n console.error('Adapter selection failed: The provided adapters array is empty.');\n return undefined;\n }\n\n const foundAdapter = adapter.find((a) => a.key === adapterKey);\n\n if (foundAdapter) {\n return foundAdapter;\n } else {\n console.warn(\n `No adapter found for key: \"${adapterKey}\". Falling back to the first available adapter: \"${adapter[0].key}\".`,\n );\n return adapter[0];\n }\n }\n return adapter;\n};\n","/**\n * Checks whether the given chain ID belongs to a Solana network.\n * Supports common Solana network names: 'devnet', 'testnet', 'mainnet-beta', 'mainnet'.\n *\n * @param {number | string} chainId - The chain ID or chain name.\n * @returns {boolean} - True if the chain ID corresponds to a Solana network, false otherwise.\n */\nexport function isSolanaChain(chainId: number | string): boolean {\n if (typeof chainId === 'string') {\n return ['devnet', 'testnet', 'mainnet-beta', 'mainnet'].includes(chainId);\n }\n return false;\n}\n\n/**\n * Sets the chain ID to a Solana-specific format if the chain is a Solana network.\n *\n * @param {number | string} chainId - The original chain ID or name.\n * @returns {string | number} - The formatted chain ID prefixed with 'solana:' if Solana, otherwise the original.\n */\nexport function setChainId(chainId: number | string): string | number {\n if (isSolanaChain(chainId)) {\n return `solana:${chainId}`;\n } else {\n return chainId;\n }\n}\n"]}
|