@tuwaio/orbit-core 0.0.4 → 1.0.0-fix-test-alpha.2.f8f5982
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 +29 -1
- package/dist/index.d.ts +29 -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
|
@@ -130,6 +130,34 @@ declare const createBoundedUseStore: <S extends StoreApi<unknown>>(store: S) =>
|
|
|
130
130
|
<T>(selector: (state: ExtractState<S>) => T): T;
|
|
131
131
|
};
|
|
132
132
|
|
|
133
|
+
/**
|
|
134
|
+
* Generates a standardized wallet type identifier from adapter type and connector name
|
|
135
|
+
*
|
|
136
|
+
* @example
|
|
137
|
+
* ```typescript
|
|
138
|
+
* // Returns "evm:metamask"
|
|
139
|
+
* getWalletTypeFromConnectorName(OrbitAdapter.EVM, "MetaMask");
|
|
140
|
+
*
|
|
141
|
+
* // Returns "solana:phantom"
|
|
142
|
+
* getWalletTypeFromConnectorName(OrbitAdapter.SOLANA, "Phantom");
|
|
143
|
+
*
|
|
144
|
+
* // Returns "evm:coinbasewallet" (removes spaces)
|
|
145
|
+
* getWalletTypeFromConnectorName(OrbitAdapter.EVM, "Coinbase Wallet");
|
|
146
|
+
* ```
|
|
147
|
+
*
|
|
148
|
+
* @param adapter - The blockchain adapter type (e.g. EVM, SOLANA)
|
|
149
|
+
* @param name - The wallet connector name (e.g. "MetaMask", "Phantom")
|
|
150
|
+
* @returns A formatted wallet type string in format "chain:wallet"
|
|
151
|
+
*
|
|
152
|
+
* @remarks
|
|
153
|
+
* The function:
|
|
154
|
+
* 1. Combines adapter type with connector name using ":" as separator
|
|
155
|
+
* 2. Removes all whitespace from connector name
|
|
156
|
+
* 3. Converts connector name to lowercase
|
|
157
|
+
* This ensures consistent wallet type identifiers across the application
|
|
158
|
+
*/
|
|
159
|
+
declare function getWalletTypeFromConnectorName(adapter: OrbitAdapter, name: string): string;
|
|
160
|
+
|
|
133
161
|
/**
|
|
134
162
|
* @file
|
|
135
163
|
* This module provides adapter selection functionality for the Orbit system.
|
|
@@ -195,4 +223,4 @@ declare function isSolanaChain(chainId: number | string): boolean;
|
|
|
195
223
|
*/
|
|
196
224
|
declare function setChainId(chainId: number | string): string | number;
|
|
197
225
|
|
|
198
|
-
export { OrbitAdapter, type OrbitGenericAdapter, createBoundedUseStore, isSolanaChain, selectAdapterByKey, setChainId };
|
|
226
|
+
export { OrbitAdapter, type OrbitGenericAdapter, createBoundedUseStore, getWalletTypeFromConnectorName, isSolanaChain, selectAdapterByKey, setChainId };
|
package/dist/index.d.ts
CHANGED
|
@@ -130,6 +130,34 @@ declare const createBoundedUseStore: <S extends StoreApi<unknown>>(store: S) =>
|
|
|
130
130
|
<T>(selector: (state: ExtractState<S>) => T): T;
|
|
131
131
|
};
|
|
132
132
|
|
|
133
|
+
/**
|
|
134
|
+
* Generates a standardized wallet type identifier from adapter type and connector name
|
|
135
|
+
*
|
|
136
|
+
* @example
|
|
137
|
+
* ```typescript
|
|
138
|
+
* // Returns "evm:metamask"
|
|
139
|
+
* getWalletTypeFromConnectorName(OrbitAdapter.EVM, "MetaMask");
|
|
140
|
+
*
|
|
141
|
+
* // Returns "solana:phantom"
|
|
142
|
+
* getWalletTypeFromConnectorName(OrbitAdapter.SOLANA, "Phantom");
|
|
143
|
+
*
|
|
144
|
+
* // Returns "evm:coinbasewallet" (removes spaces)
|
|
145
|
+
* getWalletTypeFromConnectorName(OrbitAdapter.EVM, "Coinbase Wallet");
|
|
146
|
+
* ```
|
|
147
|
+
*
|
|
148
|
+
* @param adapter - The blockchain adapter type (e.g. EVM, SOLANA)
|
|
149
|
+
* @param name - The wallet connector name (e.g. "MetaMask", "Phantom")
|
|
150
|
+
* @returns A formatted wallet type string in format "chain:wallet"
|
|
151
|
+
*
|
|
152
|
+
* @remarks
|
|
153
|
+
* The function:
|
|
154
|
+
* 1. Combines adapter type with connector name using ":" as separator
|
|
155
|
+
* 2. Removes all whitespace from connector name
|
|
156
|
+
* 3. Converts connector name to lowercase
|
|
157
|
+
* This ensures consistent wallet type identifiers across the application
|
|
158
|
+
*/
|
|
159
|
+
declare function getWalletTypeFromConnectorName(adapter: OrbitAdapter, name: string): string;
|
|
160
|
+
|
|
133
161
|
/**
|
|
134
162
|
* @file
|
|
135
163
|
* This module provides adapter selection functionality for the Orbit system.
|
|
@@ -195,4 +223,4 @@ declare function isSolanaChain(chainId: number | string): boolean;
|
|
|
195
223
|
*/
|
|
196
224
|
declare function setChainId(chainId: number | string): string | number;
|
|
197
225
|
|
|
198
|
-
export { OrbitAdapter, type OrbitGenericAdapter, createBoundedUseStore, isSolanaChain, selectAdapterByKey, setChainId };
|
|
226
|
+
export { OrbitAdapter, type OrbitGenericAdapter, createBoundedUseStore, 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 d=(e=>t=>zustand.useStore(e,t));var
|
|
1
|
+
'use strict';var zustand=require('zustand');var o=(r=>(r.EVM="evm",r.SOLANA="solana",r.Starknet="starknet",r))(o||{});var d=(e=>t=>zustand.useStore(e,t));function l(e,t){return `${e}:${t.replace(/\s+/g,"").toLowerCase()}`}var A=({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 i(e){return typeof e=="string"?["devnet","testnet","mainnet-beta","mainnet"].includes(e):false}function x(e){return i(e)?`solana:${e}`:e}exports.OrbitAdapter=o;exports.createBoundedUseStore=d;exports.getWalletTypeFromConnectorName=l;exports.isSolanaChain=i;exports.selectAdapterByKey=A;exports.setChainId=x;//# 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/createBoundedUseStore.ts","../src/utils/selectAdapterByKey.ts","../src/utils/%D1%81hainHelpers.ts"],"names":["OrbitAdapter","createBoundedUseStore","store","selector","useStore","selectAdapterByKey","adapterKey","adapter","foundAdapter","a","isSolanaChain","chainId","setChainId"],"mappings":"4CAgCO,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,ECCL,IAAMC,CAAAA,EAA0BC,CAAAA,EAAWC,GAAaC,gBAAAA,CAASF,CAAAA,CAAOC,CAAQ,CAAA,ECYhF,IAAME,CAAAA,CAAqB,CAAkC,CAClE,UAAA,CAAAC,CAAAA,CACA,OAAA,CAAAC,CACF,CAAA,GAA4E,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,IAAMC,CAAAA,CAAeD,CAAAA,CAAQ,IAAA,CAAME,GAAMA,CAAAA,CAAE,GAAA,GAAQH,CAAU,CAAA,CAE7D,OAAIE,CAAAA,GAGF,QAAQ,IAAA,CACN,CAAA,2BAAA,EAA8BF,CAAU,CAAA,iDAAA,EAAoDC,CAAAA,CAAQ,CAAC,EAAE,GAAG,CAAA,EAAA,CAC5G,CAAA,CACOA,CAAAA,CAAQ,CAAC,CAAA,CAEpB,CACA,OAAOA,CACT,EC5DO,SAASG,CAAAA,CAAcC,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,SAASC,CAAAA,CAAWD,CAAAA,CAA2C,CACpE,OAAID,CAAAA,CAAcC,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\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<BaseAdapter> = {\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","/**\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 * @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/createBoundedUseStore.ts","../src/utils/getWalletTypeFromConnectorName.ts","../src/utils/selectAdapterByKey.ts","../src/utils/%D1%81hainHelpers.ts"],"names":["OrbitAdapter","createBoundedUseStore","store","selector","useStore","getWalletTypeFromConnectorName","adapter","name","selectAdapterByKey","adapterKey","foundAdapter","a","isSolanaChain","chainId","setChainId"],"mappings":"4CAgCO,IAAKA,CAAAA,CAAAA,CAAAA,CAAAA,GAUVA,CAAAA,CAAA,GAAA,CAAM,KAAA,CASNA,CAAAA,CAAA,MAAA,CAAS,QAAA,CASTA,CAAAA,CAAA,QAAA,CAAW,UAAA,CA5BDA,CAAAA,CAAAA,EAAAA,CAAAA,EAAA,EAAA,ECCL,IAAMC,CAAAA,EAA0BC,CAAAA,EAAWC,CAAAA,EAAaC,gBAAAA,CAASF,CAAAA,CAAOC,CAAQ,CAAA,ECLhF,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,CAAAA,CAAqB,CAAkC,CAClE,UAAA,CAAAC,CAAAA,CACA,OAAA,CAAAH,CACF,CAAA,GAA4E,CAC1E,GAAI,KAAA,CAAM,OAAA,CAAQA,CAAO,CAAA,CAAG,CAC1B,GAAIA,CAAAA,CAAQ,MAAA,GAAW,EAAG,CACxB,OAAA,CAAQ,KAAA,CAAM,iEAAiE,CAAA,CAC/E,MACF,CAEA,IAAMI,CAAAA,CAAeJ,CAAAA,CAAQ,IAAA,CAAMK,CAAAA,EAAMA,CAAAA,CAAE,GAAA,GAAQF,CAAU,CAAA,CAE7D,OAAIC,CAAAA,GAGF,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,CAAcC,CAAAA,CAAmC,CAC/D,OAAI,OAAOA,CAAAA,EAAY,QAAA,CACd,CAAC,QAAA,CAAU,SAAA,CAAW,cAAA,CAAgB,SAAS,CAAA,CAAE,QAAA,CAASA,CAAO,CAAA,CAEnE,KACT,CAQO,SAASC,CAAAA,CAAWD,CAAAA,CAA2C,CACpE,OAAID,CAAAA,CAAcC,CAAO,CAAA,CAChB,CAAA,OAAA,EAAUA,CAAO,GAEjBA,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\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<BaseAdapter> = {\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","/**\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\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 d=(e=>t=>useStore(e,t));var
|
|
1
|
+
import {useStore}from'zustand';var o=(r=>(r.EVM="evm",r.SOLANA="solana",r.Starknet="starknet",r))(o||{});var d=(e=>t=>useStore(e,t));function l(e,t){return `${e}:${t.replace(/\s+/g,"").toLowerCase()}`}var A=({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 i(e){return typeof e=="string"?["devnet","testnet","mainnet-beta","mainnet"].includes(e):false}function x(e){return i(e)?`solana:${e}`:e}export{o as OrbitAdapter,d as createBoundedUseStore,l as getWalletTypeFromConnectorName,i as isSolanaChain,A as selectAdapterByKey,x 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/createBoundedUseStore.ts","../src/utils/selectAdapterByKey.ts","../src/utils/%D1%81hainHelpers.ts"],"names":["OrbitAdapter","createBoundedUseStore","store","selector","useStore","selectAdapterByKey","adapterKey","adapter","foundAdapter","a","isSolanaChain","chainId","setChainId"],"mappings":"+BAgCO,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,ECCL,IAAMC,CAAAA,EAA0BC,CAAAA,EAAWC,GAAaC,QAAAA,CAASF,CAAAA,CAAOC,CAAQ,CAAA,ECYhF,IAAME,CAAAA,CAAqB,CAAkC,CAClE,UAAA,CAAAC,CAAAA,CACA,OAAA,CAAAC,CACF,CAAA,GAA4E,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,IAAMC,CAAAA,CAAeD,CAAAA,CAAQ,IAAA,CAAME,GAAMA,CAAAA,CAAE,GAAA,GAAQH,CAAU,CAAA,CAE7D,OAAIE,CAAAA,GAGF,QAAQ,IAAA,CACN,CAAA,2BAAA,EAA8BF,CAAU,CAAA,iDAAA,EAAoDC,CAAAA,CAAQ,CAAC,EAAE,GAAG,CAAA,EAAA,CAC5G,CAAA,CACOA,CAAAA,CAAQ,CAAC,CAAA,CAEpB,CACA,OAAOA,CACT,EC5DO,SAASG,CAAAA,CAAcC,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,SAASC,CAAAA,CAAWD,CAAAA,CAA2C,CACpE,OAAID,CAAAA,CAAcC,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\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<BaseAdapter> = {\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","/**\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 * @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/createBoundedUseStore.ts","../src/utils/getWalletTypeFromConnectorName.ts","../src/utils/selectAdapterByKey.ts","../src/utils/%D1%81hainHelpers.ts"],"names":["OrbitAdapter","createBoundedUseStore","store","selector","useStore","getWalletTypeFromConnectorName","adapter","name","selectAdapterByKey","adapterKey","foundAdapter","a","isSolanaChain","chainId","setChainId"],"mappings":"+BAgCO,IAAKA,CAAAA,CAAAA,CAAAA,CAAAA,GAUVA,CAAAA,CAAA,GAAA,CAAM,KAAA,CASNA,CAAAA,CAAA,MAAA,CAAS,QAAA,CASTA,CAAAA,CAAA,QAAA,CAAW,UAAA,CA5BDA,CAAAA,CAAAA,EAAAA,CAAAA,EAAA,EAAA,ECCL,IAAMC,CAAAA,EAA0BC,CAAAA,EAAWC,CAAAA,EAAaC,QAAAA,CAASF,CAAAA,CAAOC,CAAQ,CAAA,ECLhF,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,CAAAA,CAAqB,CAAkC,CAClE,UAAA,CAAAC,CAAAA,CACA,OAAA,CAAAH,CACF,CAAA,GAA4E,CAC1E,GAAI,KAAA,CAAM,OAAA,CAAQA,CAAO,CAAA,CAAG,CAC1B,GAAIA,CAAAA,CAAQ,MAAA,GAAW,EAAG,CACxB,OAAA,CAAQ,KAAA,CAAM,iEAAiE,CAAA,CAC/E,MACF,CAEA,IAAMI,CAAAA,CAAeJ,CAAAA,CAAQ,IAAA,CAAMK,CAAAA,EAAMA,CAAAA,CAAE,GAAA,GAAQF,CAAU,CAAA,CAE7D,OAAIC,CAAAA,GAGF,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,CAAcC,CAAAA,CAAmC,CAC/D,OAAI,OAAOA,CAAAA,EAAY,QAAA,CACd,CAAC,QAAA,CAAU,SAAA,CAAW,cAAA,CAAgB,SAAS,CAAA,CAAE,QAAA,CAASA,CAAO,CAAA,CAEnE,KACT,CAQO,SAASC,CAAAA,CAAWD,CAAAA,CAA2C,CACpE,OAAID,CAAAA,CAAcC,CAAO,CAAA,CAChB,CAAA,OAAA,EAAUA,CAAO,GAEjBA,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\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<BaseAdapter> = {\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","/**\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\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"]}
|