@tuwaio/satellite-core 1.0.0-fix-test-alpha.1.3665b1d → 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 CHANGED
@@ -197,34 +197,6 @@ declare function createSatelliteConnectStore({ adapter, callbackAfterConnected,
197
197
  */
198
198
  declare function getAdapterFromWalletType(walletType: WalletType): OrbitAdapter;
199
199
 
200
- /**
201
- * Generates a standardized wallet type identifier from adapter type and connector name
202
- *
203
- * @example
204
- * ```typescript
205
- * // Returns "evm:metamask"
206
- * getWalletTypeFromConnectorName(OrbitAdapter.EVM, "MetaMask");
207
- *
208
- * // Returns "solana:phantom"
209
- * getWalletTypeFromConnectorName(OrbitAdapter.SOLANA, "Phantom");
210
- *
211
- * // Returns "evm:coinbasewallet" (removes spaces)
212
- * getWalletTypeFromConnectorName(OrbitAdapter.EVM, "Coinbase Wallet");
213
- * ```
214
- *
215
- * @param adapter - The blockchain adapter type (e.g. EVM, SOLANA)
216
- * @param name - The wallet connector name (e.g. "MetaMask", "Phantom")
217
- * @returns A formatted wallet type string in format "chain:wallet"
218
- *
219
- * @remarks
220
- * The function:
221
- * 1. Combines adapter type with connector name using ":" as separator
222
- * 2. Removes all whitespace from connector name
223
- * 3. Converts connector name to lowercase
224
- * This ensures consistent wallet type identifiers across the application
225
- */
226
- declare function getWalletTypeFromConnectorName(adapter: OrbitAdapter, name: string): string;
227
-
228
200
  /**
229
201
  * Helper utilities for managing impersonated wallet addresses
230
202
  *
@@ -269,4 +241,4 @@ declare const impersonatedHelpers: {
269
241
  getImpersonated: () => string | null | undefined;
270
242
  };
271
243
 
272
- export { type BaseWallet, type Connector, type ConnectorEVM, type ConnectorSolana, type ConnectorsInitProps, type ISatelliteConnectStore, type SatelliteAdapter, type SatelliteConnectStoreInitialParameters, type SolanaWallet, type Wallet, type WalletConnectedCallback, type WalletType, createSatelliteConnectStore, getAdapterFromWalletType, getWalletTypeFromConnectorName, impersonatedHelpers };
244
+ export { type BaseWallet, type Connector, type ConnectorEVM, type ConnectorSolana, type ConnectorsInitProps, type ISatelliteConnectStore, type SatelliteAdapter, type SatelliteConnectStoreInitialParameters, type SolanaWallet, type Wallet, type WalletConnectedCallback, type WalletType, createSatelliteConnectStore, getAdapterFromWalletType, impersonatedHelpers };
package/dist/index.d.ts CHANGED
@@ -197,34 +197,6 @@ declare function createSatelliteConnectStore({ adapter, callbackAfterConnected,
197
197
  */
198
198
  declare function getAdapterFromWalletType(walletType: WalletType): OrbitAdapter;
199
199
 
200
- /**
201
- * Generates a standardized wallet type identifier from adapter type and connector name
202
- *
203
- * @example
204
- * ```typescript
205
- * // Returns "evm:metamask"
206
- * getWalletTypeFromConnectorName(OrbitAdapter.EVM, "MetaMask");
207
- *
208
- * // Returns "solana:phantom"
209
- * getWalletTypeFromConnectorName(OrbitAdapter.SOLANA, "Phantom");
210
- *
211
- * // Returns "evm:coinbasewallet" (removes spaces)
212
- * getWalletTypeFromConnectorName(OrbitAdapter.EVM, "Coinbase Wallet");
213
- * ```
214
- *
215
- * @param adapter - The blockchain adapter type (e.g. EVM, SOLANA)
216
- * @param name - The wallet connector name (e.g. "MetaMask", "Phantom")
217
- * @returns A formatted wallet type string in format "chain:wallet"
218
- *
219
- * @remarks
220
- * The function:
221
- * 1. Combines adapter type with connector name using ":" as separator
222
- * 2. Removes all whitespace from connector name
223
- * 3. Converts connector name to lowercase
224
- * This ensures consistent wallet type identifiers across the application
225
- */
226
- declare function getWalletTypeFromConnectorName(adapter: OrbitAdapter, name: string): string;
227
-
228
200
  /**
229
201
  * Helper utilities for managing impersonated wallet addresses
230
202
  *
@@ -269,4 +241,4 @@ declare const impersonatedHelpers: {
269
241
  getImpersonated: () => string | null | undefined;
270
242
  };
271
243
 
272
- export { type BaseWallet, type Connector, type ConnectorEVM, type ConnectorSolana, type ConnectorsInitProps, type ISatelliteConnectStore, type SatelliteAdapter, type SatelliteConnectStoreInitialParameters, type SolanaWallet, type Wallet, type WalletConnectedCallback, type WalletType, createSatelliteConnectStore, getAdapterFromWalletType, getWalletTypeFromConnectorName, impersonatedHelpers };
244
+ export { type BaseWallet, type Connector, type ConnectorEVM, type ConnectorSolana, type ConnectorsInitProps, type ISatelliteConnectStore, type SatelliteAdapter, type SatelliteConnectStoreInitialParameters, type SolanaWallet, type Wallet, type WalletConnectedCallback, type WalletType, createSatelliteConnectStore, getAdapterFromWalletType, impersonatedHelpers };
package/dist/index.js CHANGED
@@ -1,2 +1,2 @@
1
- 'use strict';var orbitCore=require('@tuwaio/orbit-core'),immer=require('immer'),vanilla=require('zustand/vanilla');function l(r){return r.split(":")[0]??orbitCore.OrbitAdapter.EVM}function S({adapter:r,callbackAfterConnected:c}){return vanilla.createStore()((a,i)=>({getAdapter:()=>r,availableConnectors:{},initializeAppConnectors:async({autoConnect:t})=>{if(Array.isArray(r))(await Promise.all(r.map(o=>o.getConnectors()))).forEach(o=>{a(e=>immer.produce(e,p=>{p.availableConnectors[o.adapter]=o.connectors;}));});else {let n=await r.getConnectors();a(o=>immer.produce(o,e=>{e.availableConnectors[n.adapter]=n.connectors;}));}if(t){let n=i().lastConnectedWallet;n&&await i().connect({walletType:n.walletType,chainId:n.chainId});}},connect:async({walletType:t,chainId:n})=>{a({walletConnecting:true,walletConnectionError:void 0});let o=orbitCore.selectAdapterByKey({adapter:r,adapterKey:l(t)});try{let e=await o?.connect({walletType:t,chainId:n,connectors:i().availableConnectors[l(t)]??[]});a({activeWallet:e}),o?.checkIsContractWallet&&e&&(i().updateActiveWallet({isContractAddress:await o.checkIsContractWallet({address:e.address,chainId:n})}),c&&await c(e)),a({walletConnecting:!1,lastConnectedWallet:{walletType:t,chainId:n}});}catch(e){a({walletConnecting:false,walletConnectionError:"Wallet connection failed: "+(e instanceof Error?e.message:String(e))});}},disconnect:async()=>{let t=i().activeWallet;t&&(await orbitCore.selectAdapterByKey({adapter:r,adapterKey:l(t.walletType)})?.disconnect(),a({activeWallet:void 0,lastConnectedWallet:void 0}));},walletConnecting:false,resetWalletConnectionError:()=>{a({walletConnectionError:void 0});},updateActiveWallet:t=>{i().activeWallet?a(o=>immer.produce(o,e=>{e.activeWallet&&(e.activeWallet={...e.activeWallet,...t});})):t.walletType!==void 0&&t.chainId!==void 0&&t.address!==void 0&&a({activeWallet:t});},switchNetwork:async t=>{a({switchNetworkError:void 0});let n=i().activeWallet;if(n){let o=orbitCore.selectAdapterByKey({adapter:r,adapterKey:l(n.walletType)});try{await o?.checkAndSwitchNetwork(t,n.chainId,i().updateActiveWallet);}catch(e){a({switchNetworkError:"Switch network failed: "+(e instanceof Error?e.message:String(e))});}}},resetSwitchNetworkError:()=>a({switchNetworkError:void 0})}))}function h(r,c){return `${r}:${c.replace(/\s+/g,"").toLowerCase()}`}var E={impersonatedAddress:typeof window<"u"?window.localStorage.getItem("satellite-connect:impersonatedAddress")??"":"",setImpersonated:r=>typeof window<"u"?window.localStorage.setItem("satellite-connect:impersonatedAddress",r):void 0,getImpersonated:()=>typeof window<"u"?window.localStorage.getItem("satellite-connect:impersonatedAddress"):void 0};exports.createSatelliteConnectStore=S;exports.getAdapterFromWalletType=l;exports.getWalletTypeFromConnectorName=h;exports.impersonatedHelpers=E;//# sourceMappingURL=index.js.map
1
+ 'use strict';var orbitCore=require('@tuwaio/orbit-core'),immer=require('immer'),vanilla=require('zustand/vanilla');function l(r){return r.split(":")[0]??orbitCore.OrbitAdapter.EVM}function S({adapter:r,callbackAfterConnected:s}){return vanilla.createStore()((o,i)=>({getAdapter:()=>r,availableConnectors:{},initializeAppConnectors:async({autoConnect:t})=>{if(Array.isArray(r))(await Promise.all(r.map(a=>a.getConnectors()))).forEach(a=>{o(e=>immer.produce(e,f=>{f.availableConnectors[a.adapter]=a.connectors;}));});else {let n=await r.getConnectors();o(a=>immer.produce(a,e=>{e.availableConnectors[n.adapter]=n.connectors;}));}if(t){let n=i().lastConnectedWallet;n&&await i().connect({walletType:n.walletType,chainId:n.chainId});}},connect:async({walletType:t,chainId:n})=>{o({walletConnecting:true,walletConnectionError:void 0});let a=orbitCore.selectAdapterByKey({adapter:r,adapterKey:l(t)});try{let e=await a?.connect({walletType:t,chainId:n,connectors:i().availableConnectors[l(t)]??[]});o({activeWallet:e}),a?.checkIsContractWallet&&e&&(i().updateActiveWallet({isContractAddress:await a.checkIsContractWallet({address:e.address,chainId:n})}),s&&await s(e)),o({walletConnecting:!1,lastConnectedWallet:{walletType:t,chainId:n}});}catch(e){o({walletConnecting:false,walletConnectionError:"Wallet connection failed: "+(e instanceof Error?e.message:String(e))});}},disconnect:async()=>{let t=i().activeWallet;t&&(await orbitCore.selectAdapterByKey({adapter:r,adapterKey:l(t.walletType)})?.disconnect(),o({activeWallet:void 0,lastConnectedWallet:void 0}));},walletConnecting:false,resetWalletConnectionError:()=>{o({walletConnectionError:void 0});},updateActiveWallet:t=>{i().activeWallet?o(a=>immer.produce(a,e=>{e.activeWallet&&(e.activeWallet={...e.activeWallet,...t});})):t.walletType!==void 0&&t.chainId!==void 0&&t.address!==void 0&&o({activeWallet:t});},switchNetwork:async t=>{o({switchNetworkError:void 0});let n=i().activeWallet;if(n){let a=orbitCore.selectAdapterByKey({adapter:r,adapterKey:l(n.walletType)});try{await a?.checkAndSwitchNetwork(t,n.chainId,i().updateActiveWallet);}catch(e){o({switchNetworkError:"Switch network failed: "+(e instanceof Error?e.message:String(e))});}}},resetSwitchNetworkError:()=>o({switchNetworkError:void 0})}))}var g={impersonatedAddress:typeof window<"u"?window.localStorage.getItem("satellite-connect:impersonatedAddress")??"":"",setImpersonated:r=>typeof window<"u"?window.localStorage.setItem("satellite-connect:impersonatedAddress",r):void 0,getImpersonated:()=>typeof window<"u"?window.localStorage.getItem("satellite-connect:impersonatedAddress"):void 0};exports.createSatelliteConnectStore=S;exports.getAdapterFromWalletType=l;exports.impersonatedHelpers=g;//# sourceMappingURL=index.js.map
2
2
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/utils/getAdapterFromWalletType.ts","../src/store/satelliteConnectStore.ts","../src/utils/getWalletTypeFromConnectorName.ts","../src/utils/impersonatedHelpers.ts"],"names":["getAdapterFromWalletType","walletType","OrbitAdapter","createSatelliteConnectStore","adapter","callbackAfterConnected","createStore","set","get","autoConnect","a","connectors","state","produce","draft","lastConnectedWallet","chainId","foundAdapter","selectAdapterByKey","wallet","activeWallet","getWalletTypeFromConnectorName","name","impersonatedHelpers","address"],"mappings":"mHA0BO,SAASA,CAAAA,CAAyBC,CAAAA,CAAsC,CAC7E,OAAQA,CAAAA,CAAW,KAAA,CAAM,GAAG,CAAA,CAAE,CAAC,CAAA,EAAKC,sBAAAA,CAAa,GACnD,CCZO,SAASC,CAAAA,CAA4B,CAC1C,OAAA,CAAAC,CAAAA,CACA,sBAAA,CAAAC,CACF,CAAA,CAA2C,CACzC,OAAOC,mBAAAA,EAAoC,CAAE,CAACC,EAAKC,CAAAA,IAAS,CAI1D,UAAA,CAAY,IAAMJ,CAAAA,CAKlB,mBAAA,CAAqB,EAAC,CAMtB,uBAAA,CAAyB,MAAO,CAAE,WAAA,CAAAK,CAAY,CAAA,GAAM,CAClD,GAAI,KAAA,CAAM,OAAA,CAAQL,CAAO,CAAA,CAAA,CACJ,MAAM,OAAA,CAAQ,GAAA,CAAIA,CAAAA,CAAQ,GAAA,CAAKM,CAAAA,EAAMA,CAAAA,CAAE,aAAA,EAAe,CAAC,CAAA,EAC/D,OAAA,CAASC,CAAAA,EAAe,CACjCJ,CAAAA,CAAKK,CAAAA,EACHC,aAAAA,CAAQD,CAAAA,CAAQE,CAAAA,EAAU,CACxBA,CAAAA,CAAM,mBAAA,CAAoBH,CAAAA,CAAW,OAAO,EAAIA,CAAAA,CAAW,WAC7D,CAAC,CACH,EACF,CAAC,CAAA,CAAA,KACI,CACL,IAAMA,CAAAA,CAAa,MAAMP,CAAAA,CAAQ,aAAA,EAAc,CAC/CG,EAAKK,CAAAA,EACHC,aAAAA,CAAQ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AA,CAAW,GAAA,CAAc,MAAA,CAAO,YAAA,CAAa,OAAA,CAAQ,uCAAuC,CAAA,CAAI,MAC3G","file":"index.js","sourcesContent":["import { OrbitAdapter } from '@tuwaio/orbit-core';\n\nimport { WalletType } from '../types';\n\n/**\n * Extracts the adapter type from a wallet type string\n *\n * @example\n * ```typescript\n * // Returns OrbitAdapter.EVM\n * getAdapterFromWalletType('evm:metamask');\n *\n * // Returns OrbitAdapter.SOLANA\n * getAdapterFromWalletType('solana:phantom');\n *\n * // Returns OrbitAdapter.EVM (default)\n * getAdapterFromWalletType('unknown');\n * ```\n *\n * @param walletType - Wallet type in format \"chain:wallet\" (e.g. \"evm:metamask\", \"solana:phantom\")\n * @returns The corresponding {@link OrbitAdapter} type or EVM as default\n *\n * @remarks\n * The function splits the wallet type string by \":\" and takes the first part as the adapter type.\n * If the split fails or the first part is empty, it defaults to EVM adapter.\n */\nexport function getAdapterFromWalletType(walletType: WalletType): OrbitAdapter {\n return (walletType.split(':')[0] ?? OrbitAdapter.EVM) as OrbitAdapter;\n}\n","import { selectAdapterByKey } from '@tuwaio/orbit-core';\nimport { Draft, produce } from 'immer';\nimport { createStore } from 'zustand/vanilla';\n\nimport { Connector, ISatelliteConnectStore, SatelliteConnectStoreInitialParameters, Wallet } from '../types';\nimport { getAdapterFromWalletType } from '../utils/getAdapterFromWalletType';\n\n/**\n * Creates a Satellite Connect store instance for managing wallet connections and state\n *\n * @param params - Configuration parameters for the store\n * @param params.adapter - Single adapter or array of adapters for different chains\n * @param params.callbackAfterConnected - Optional callback function called after successful wallet connection\n *\n * @returns A Zustand store instance with wallet connection state and methods\n */\nexport function createSatelliteConnectStore({\n adapter,\n callbackAfterConnected,\n}: SatelliteConnectStoreInitialParameters) {\n return createStore<ISatelliteConnectStore>()((set, get) => ({\n /**\n * Returns configured adapter(s)\n */\n getAdapter: () => adapter,\n\n /**\n * Available wallet connectors for each chain\n */\n availableConnectors: {},\n\n /**\n * Initializes wallet connectors for all configured adapters\n * @param autoConnect - Whether to automatically reconnect to last used wallet\n */\n initializeAppConnectors: async ({ autoConnect }) => {\n if (Array.isArray(adapter)) {\n const connectors = await Promise.all(adapter.map((a) => a.getConnectors()));\n connectors.forEach((connectors) => {\n set((state) =>\n produce(state, (draft) => {\n draft.availableConnectors[connectors.adapter] = connectors.connectors as Draft<Connector[]>;\n }),\n );\n });\n } else {\n const connectors = await adapter.getConnectors();\n set((state) =>\n produce(state, (draft) => {\n draft.availableConnectors[connectors.adapter] = connectors.connectors as Draft<Connector[]>;\n }),\n );\n }\n if (autoConnect) {\n const lastConnectedWallet = get().lastConnectedWallet;\n if (lastConnectedWallet) {\n await get().connect({ walletType: lastConnectedWallet.walletType, chainId: lastConnectedWallet.chainId });\n }\n }\n },\n\n /**\n * Connects to a wallet\n * @param walletType - Type of wallet to connect to\n * @param chainId - Chain ID to connect on\n */\n connect: async ({ walletType, chainId }) => {\n set({ walletConnecting: true, walletConnectionError: undefined });\n const foundAdapter = selectAdapterByKey({ adapter, adapterKey: getAdapterFromWalletType(walletType) });\n try {\n const wallet = await foundAdapter?.connect({\n walletType,\n chainId,\n connectors: get().availableConnectors[getAdapterFromWalletType(walletType)] ?? [],\n });\n set({ activeWallet: wallet });\n if (foundAdapter?.checkIsContractWallet && wallet) {\n get().updateActiveWallet({\n isContractAddress: await foundAdapter.checkIsContractWallet({\n address: wallet.address,\n chainId,\n }),\n });\n if (callbackAfterConnected) {\n await callbackAfterConnected(wallet);\n }\n }\n set({ walletConnecting: false, lastConnectedWallet: { walletType, chainId } });\n } catch (e) {\n set({\n walletConnecting: false,\n walletConnectionError: 'Wallet connection failed: ' + (e instanceof Error ? e.message : String(e)),\n });\n }\n },\n\n /**\n * Disconnects the currently active wallet\n */\n disconnect: async () => {\n const activeWallet = get().activeWallet;\n if (activeWallet) {\n const foundAdapter = selectAdapterByKey({\n adapter,\n adapterKey: getAdapterFromWalletType(activeWallet.walletType),\n });\n await foundAdapter?.disconnect();\n set({ activeWallet: undefined, lastConnectedWallet: undefined });\n }\n },\n\n walletConnecting: false,\n\n /**\n * Resets any wallet connection errors\n */\n resetWalletConnectionError: () => {\n set({ walletConnectionError: undefined });\n },\n\n /**\n * Updates the active wallet's properties\n * @param wallet - Partial wallet object with properties to update\n */\n updateActiveWallet: (wallet: Partial<Wallet>) => {\n const activeWallet = get().activeWallet;\n if (activeWallet) {\n set((state) =>\n produce(state, (draft) => {\n if (draft.activeWallet) {\n draft.activeWallet = {\n ...draft.activeWallet,\n ...wallet,\n };\n }\n }),\n );\n } else {\n if (wallet.walletType !== undefined && wallet.chainId !== undefined && wallet.address !== undefined) {\n set({ activeWallet: wallet as Wallet });\n }\n }\n },\n\n /**\n * Switches the connected wallet to a different network\n * @param chainId - Target chain ID to switch to\n */\n switchNetwork: async (chainId: string | number) => {\n set({ switchNetworkError: undefined });\n const activeWallet = get().activeWallet;\n if (activeWallet) {\n const foundAdapter = selectAdapterByKey({\n adapter,\n adapterKey: getAdapterFromWalletType(activeWallet.walletType),\n });\n try {\n await foundAdapter?.checkAndSwitchNetwork(chainId, activeWallet.chainId, get().updateActiveWallet);\n } catch (e) {\n set({ switchNetworkError: 'Switch network failed: ' + (e instanceof Error ? e.message : String(e)) });\n }\n }\n },\n\n /**\n * Resets any network switching errors\n */\n resetSwitchNetworkError: () => set({ switchNetworkError: undefined }),\n }));\n}\n","import { OrbitAdapter } from '@tuwaio/orbit-core';\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 * 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 impersonatedHelpers = {\n /**\n * Currently impersonated address from localStorage\n * Returns empty string if not set or in SSR context\n */\n impersonatedAddress:\n typeof window !== 'undefined' ? (window.localStorage.getItem('satellite-connect:impersonatedAddress') ?? '') : '',\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 setImpersonated: (address: string) =>\n typeof window !== 'undefined'\n ? window.localStorage.setItem('satellite-connect:impersonatedAddress', address)\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 getImpersonated: () =>\n typeof window !== 'undefined' ? window.localStorage.getItem('satellite-connect:impersonatedAddress') : undefined,\n};\n"]}
1
+ {"version":3,"sources":["../src/utils/getAdapterFromWalletType.ts","../src/store/satelliteConnectStore.ts","../src/utils/impersonatedHelpers.ts"],"names":["getAdapterFromWalletType","walletType","OrbitAdapter","createSatelliteConnectStore","adapter","callbackAfterConnected","createStore","set","get","autoConnect","connectors","state","produce","draft","lastConnectedWallet","chainId","foundAdapter","selectAdapterByKey","wallet","activeWallet","impersonatedHelpers","address"],"mappings":"mHA0BO,SAASA,CAAAA,CAAyBC,CAAAA,CAAsC,CAC7E,OAAQA,CAAAA,CAAW,KAAA,CAAM,GAAG,CAAA,CAAE,CAAC,CAAA,EAAKC,uBAAa,GACnD,CCZO,SAASC,CAAAA,CAA4B,CAC1C,OAAA,CAAAC,EACA,sBAAA,CAAAC,CACF,CAAA,CAA2C,CACzC,OAAOC,mBAAAA,GAAsC,CAACC,CAAAA,CAAKC,CAAAA,IAAS,CAI1D,UAAA,CAAY,IAAMJ,CAAAA,CAKlB,mBAAA,CAAqB,EAAC,CAMtB,uBAAA,CAAyB,MAAO,CAAE,WAAA,CAAAK,CAAY,CAAA,GAAM,CAClD,GAAI,KAAA,CAAM,OAAA,CAAQL,CAAO,GACJ,MAAM,OAAA,CAAQ,GAAA,CAAIA,CAAAA,CAAQ,GAAA,CAAK,CAAA,EAAM,EAAE,aAAA,EAAe,CAAC,CAAA,EAC/D,OAAA,CAASM,CAAAA,EAAe,CACjCH,CAAAA,CAAKI,CAAAA,EACHC,aAAAA,CAAQD,CAAAA,CAAQE,CAAAA,EAAU,CACxBA,CAAAA,CAAM,oBAAoBH,CAAAA,CAAW,OAAO,CAAA,CAAIA,CAAAA,CAAW,WAC7D,CAAC,CACH,EACF,CAAC,CAAA,CAAA,KACI,CACL,IAAMA,CAAAA,CAAa,MAAMN,CAAAA,CAAQ,aAAA,EAAc,CAC/CG,CAAAA,CAAKI,CAAAA,EACHC,aAAAA,CAAQD,CAAAA,CAAQE,CAAAA,EAAU,CACxBA,CAAAA,CAAM,mBAAA,CAAoBH,CAAAA,CAAW,OAAO,CAAA,CAAIA,EAAW,WAC7D,CAAC,CACH,EACF,CACA,GAAID,EAAa,CACf,IAAMK,CAAAA,CAAsBN,CAAAA,EAAI,CAAE,mBAAA,CAC9BM,GACF,MAAMN,CAAAA,EAAI,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AA,CAAyBmB,CAAAA,CAAa,UAAU,CAC9D,CAAC,CAAA,CACD,GAAI,CACF,MAAMH,CAAAA,EAAc,qBAAA,CAAsBD,CAAAA,CAASI,CAAAA,CAAa,QAASX,CAAAA,EAAI,CAAE,kBAAkB,EACnG,CAAA,MAAS,CAAA,CAAG,CACVD,CAAAA,CAAI,CAAE,kBAAA,CAAoB,yBAAA,EAA6B,CAAA,YAAa,KAAA,CAAQ,CAAA,CAAE,QAAU,MAAA,CAAO,CAAC,CAAA,CAAG,CAAC,EACtG,CACF,CACF,CAAA,CAKA,uBAAA,CAAyB,IAAMA,CAAAA,CAAI,CAAE,kBAAA,CAAoB,MAAU,CAAC,CACtE,CAAA,CAAE,CACJ,CChKO,IAAMa,CAAAA,CAAsB,CAKjC,mBAAA,CACE,OAAO,MAAA,CAAW,GAAA,CAAe,MAAA,CAAO,YAAA,CAAa,QAAQ,uCAAuC,CAAA,EAAK,EAAA,CAAM,EAAA,CAcjH,eAAA,CAAkBC,CAAAA,EAChB,OAAO,MAAA,CAAW,GAAA,CACd,MAAA,CAAO,YAAA,CAAa,OAAA,CAAQ,uCAAA,CAAyCA,CAAO,CAAA,CAC5E,MAAA,CAeN,eAAA,CAAiB,IACf,OAAO,MAAA,CAAW,GAAA,CAAc,MAAA,CAAO,YAAA,CAAa,OAAA,CAAQ,uCAAuC,CAAA,CAAI,MAC3G","file":"index.js","sourcesContent":["import { OrbitAdapter } from '@tuwaio/orbit-core';\n\nimport { WalletType } from '../types';\n\n/**\n * Extracts the adapter type from a wallet type string\n *\n * @example\n * ```typescript\n * // Returns OrbitAdapter.EVM\n * getAdapterFromWalletType('evm:metamask');\n *\n * // Returns OrbitAdapter.SOLANA\n * getAdapterFromWalletType('solana:phantom');\n *\n * // Returns OrbitAdapter.EVM (default)\n * getAdapterFromWalletType('unknown');\n * ```\n *\n * @param walletType - Wallet type in format \"chain:wallet\" (e.g. \"evm:metamask\", \"solana:phantom\")\n * @returns The corresponding {@link OrbitAdapter} type or EVM as default\n *\n * @remarks\n * The function splits the wallet type string by \":\" and takes the first part as the adapter type.\n * If the split fails or the first part is empty, it defaults to EVM adapter.\n */\nexport function getAdapterFromWalletType(walletType: WalletType): OrbitAdapter {\n return (walletType.split(':')[0] ?? OrbitAdapter.EVM) as OrbitAdapter;\n}\n","import { selectAdapterByKey } from '@tuwaio/orbit-core';\nimport { Draft, produce } from 'immer';\nimport { createStore } from 'zustand/vanilla';\n\nimport { Connector, ISatelliteConnectStore, SatelliteConnectStoreInitialParameters, Wallet } from '../types';\nimport { getAdapterFromWalletType } from '../utils/getAdapterFromWalletType';\n\n/**\n * Creates a Satellite Connect store instance for managing wallet connections and state\n *\n * @param params - Configuration parameters for the store\n * @param params.adapter - Single adapter or array of adapters for different chains\n * @param params.callbackAfterConnected - Optional callback function called after successful wallet connection\n *\n * @returns A Zustand store instance with wallet connection state and methods\n */\nexport function createSatelliteConnectStore({\n adapter,\n callbackAfterConnected,\n}: SatelliteConnectStoreInitialParameters) {\n return createStore<ISatelliteConnectStore>()((set, get) => ({\n /**\n * Returns configured adapter(s)\n */\n getAdapter: () => adapter,\n\n /**\n * Available wallet connectors for each chain\n */\n availableConnectors: {},\n\n /**\n * Initializes wallet connectors for all configured adapters\n * @param autoConnect - Whether to automatically reconnect to last used wallet\n */\n initializeAppConnectors: async ({ autoConnect }) => {\n if (Array.isArray(adapter)) {\n const connectors = await Promise.all(adapter.map((a) => a.getConnectors()));\n connectors.forEach((connectors) => {\n set((state) =>\n produce(state, (draft) => {\n draft.availableConnectors[connectors.adapter] = connectors.connectors as Draft<Connector[]>;\n }),\n );\n });\n } else {\n const connectors = await adapter.getConnectors();\n set((state) =>\n produce(state, (draft) => {\n draft.availableConnectors[connectors.adapter] = connectors.connectors as Draft<Connector[]>;\n }),\n );\n }\n if (autoConnect) {\n const lastConnectedWallet = get().lastConnectedWallet;\n if (lastConnectedWallet) {\n await get().connect({ walletType: lastConnectedWallet.walletType, chainId: lastConnectedWallet.chainId });\n }\n }\n },\n\n /**\n * Connects to a wallet\n * @param walletType - Type of wallet to connect to\n * @param chainId - Chain ID to connect on\n */\n connect: async ({ walletType, chainId }) => {\n set({ walletConnecting: true, walletConnectionError: undefined });\n const foundAdapter = selectAdapterByKey({ adapter, adapterKey: getAdapterFromWalletType(walletType) });\n try {\n const wallet = await foundAdapter?.connect({\n walletType,\n chainId,\n connectors: get().availableConnectors[getAdapterFromWalletType(walletType)] ?? [],\n });\n set({ activeWallet: wallet });\n if (foundAdapter?.checkIsContractWallet && wallet) {\n get().updateActiveWallet({\n isContractAddress: await foundAdapter.checkIsContractWallet({\n address: wallet.address,\n chainId,\n }),\n });\n if (callbackAfterConnected) {\n await callbackAfterConnected(wallet);\n }\n }\n set({ walletConnecting: false, lastConnectedWallet: { walletType, chainId } });\n } catch (e) {\n set({\n walletConnecting: false,\n walletConnectionError: 'Wallet connection failed: ' + (e instanceof Error ? e.message : String(e)),\n });\n }\n },\n\n /**\n * Disconnects the currently active wallet\n */\n disconnect: async () => {\n const activeWallet = get().activeWallet;\n if (activeWallet) {\n const foundAdapter = selectAdapterByKey({\n adapter,\n adapterKey: getAdapterFromWalletType(activeWallet.walletType),\n });\n await foundAdapter?.disconnect();\n set({ activeWallet: undefined, lastConnectedWallet: undefined });\n }\n },\n\n walletConnecting: false,\n\n /**\n * Resets any wallet connection errors\n */\n resetWalletConnectionError: () => {\n set({ walletConnectionError: undefined });\n },\n\n /**\n * Updates the active wallet's properties\n * @param wallet - Partial wallet object with properties to update\n */\n updateActiveWallet: (wallet: Partial<Wallet>) => {\n const activeWallet = get().activeWallet;\n if (activeWallet) {\n set((state) =>\n produce(state, (draft) => {\n if (draft.activeWallet) {\n draft.activeWallet = {\n ...draft.activeWallet,\n ...wallet,\n };\n }\n }),\n );\n } else {\n if (wallet.walletType !== undefined && wallet.chainId !== undefined && wallet.address !== undefined) {\n set({ activeWallet: wallet as Wallet });\n }\n }\n },\n\n /**\n * Switches the connected wallet to a different network\n * @param chainId - Target chain ID to switch to\n */\n switchNetwork: async (chainId: string | number) => {\n set({ switchNetworkError: undefined });\n const activeWallet = get().activeWallet;\n if (activeWallet) {\n const foundAdapter = selectAdapterByKey({\n adapter,\n adapterKey: getAdapterFromWalletType(activeWallet.walletType),\n });\n try {\n await foundAdapter?.checkAndSwitchNetwork(chainId, activeWallet.chainId, get().updateActiveWallet);\n } catch (e) {\n set({ switchNetworkError: 'Switch network failed: ' + (e instanceof Error ? e.message : String(e)) });\n }\n }\n },\n\n /**\n * Resets any network switching errors\n */\n resetSwitchNetworkError: () => set({ switchNetworkError: undefined }),\n }));\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 impersonatedHelpers = {\n /**\n * Currently impersonated address from localStorage\n * Returns empty string if not set or in SSR context\n */\n impersonatedAddress:\n typeof window !== 'undefined' ? (window.localStorage.getItem('satellite-connect:impersonatedAddress') ?? '') : '',\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 setImpersonated: (address: string) =>\n typeof window !== 'undefined'\n ? window.localStorage.setItem('satellite-connect:impersonatedAddress', address)\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 getImpersonated: () =>\n typeof window !== 'undefined' ? window.localStorage.getItem('satellite-connect:impersonatedAddress') : undefined,\n};\n"]}
package/dist/index.mjs CHANGED
@@ -1,2 +1,2 @@
1
- import {OrbitAdapter,selectAdapterByKey}from'@tuwaio/orbit-core';import {produce}from'immer';import {createStore}from'zustand/vanilla';function l(r){return r.split(":")[0]??OrbitAdapter.EVM}function S({adapter:r,callbackAfterConnected:c}){return createStore()((a,i)=>({getAdapter:()=>r,availableConnectors:{},initializeAppConnectors:async({autoConnect:t})=>{if(Array.isArray(r))(await Promise.all(r.map(o=>o.getConnectors()))).forEach(o=>{a(e=>produce(e,p=>{p.availableConnectors[o.adapter]=o.connectors;}));});else {let n=await r.getConnectors();a(o=>produce(o,e=>{e.availableConnectors[n.adapter]=n.connectors;}));}if(t){let n=i().lastConnectedWallet;n&&await i().connect({walletType:n.walletType,chainId:n.chainId});}},connect:async({walletType:t,chainId:n})=>{a({walletConnecting:true,walletConnectionError:void 0});let o=selectAdapterByKey({adapter:r,adapterKey:l(t)});try{let e=await o?.connect({walletType:t,chainId:n,connectors:i().availableConnectors[l(t)]??[]});a({activeWallet:e}),o?.checkIsContractWallet&&e&&(i().updateActiveWallet({isContractAddress:await o.checkIsContractWallet({address:e.address,chainId:n})}),c&&await c(e)),a({walletConnecting:!1,lastConnectedWallet:{walletType:t,chainId:n}});}catch(e){a({walletConnecting:false,walletConnectionError:"Wallet connection failed: "+(e instanceof Error?e.message:String(e))});}},disconnect:async()=>{let t=i().activeWallet;t&&(await selectAdapterByKey({adapter:r,adapterKey:l(t.walletType)})?.disconnect(),a({activeWallet:void 0,lastConnectedWallet:void 0}));},walletConnecting:false,resetWalletConnectionError:()=>{a({walletConnectionError:void 0});},updateActiveWallet:t=>{i().activeWallet?a(o=>produce(o,e=>{e.activeWallet&&(e.activeWallet={...e.activeWallet,...t});})):t.walletType!==void 0&&t.chainId!==void 0&&t.address!==void 0&&a({activeWallet:t});},switchNetwork:async t=>{a({switchNetworkError:void 0});let n=i().activeWallet;if(n){let o=selectAdapterByKey({adapter:r,adapterKey:l(n.walletType)});try{await o?.checkAndSwitchNetwork(t,n.chainId,i().updateActiveWallet);}catch(e){a({switchNetworkError:"Switch network failed: "+(e instanceof Error?e.message:String(e))});}}},resetSwitchNetworkError:()=>a({switchNetworkError:void 0})}))}function h(r,c){return `${r}:${c.replace(/\s+/g,"").toLowerCase()}`}var E={impersonatedAddress:typeof window<"u"?window.localStorage.getItem("satellite-connect:impersonatedAddress")??"":"",setImpersonated:r=>typeof window<"u"?window.localStorage.setItem("satellite-connect:impersonatedAddress",r):void 0,getImpersonated:()=>typeof window<"u"?window.localStorage.getItem("satellite-connect:impersonatedAddress"):void 0};export{S as createSatelliteConnectStore,l as getAdapterFromWalletType,h as getWalletTypeFromConnectorName,E as impersonatedHelpers};//# sourceMappingURL=index.mjs.map
1
+ import {OrbitAdapter,selectAdapterByKey}from'@tuwaio/orbit-core';import {produce}from'immer';import {createStore}from'zustand/vanilla';function l(r){return r.split(":")[0]??OrbitAdapter.EVM}function S({adapter:r,callbackAfterConnected:s}){return createStore()((o,i)=>({getAdapter:()=>r,availableConnectors:{},initializeAppConnectors:async({autoConnect:t})=>{if(Array.isArray(r))(await Promise.all(r.map(a=>a.getConnectors()))).forEach(a=>{o(e=>produce(e,f=>{f.availableConnectors[a.adapter]=a.connectors;}));});else {let n=await r.getConnectors();o(a=>produce(a,e=>{e.availableConnectors[n.adapter]=n.connectors;}));}if(t){let n=i().lastConnectedWallet;n&&await i().connect({walletType:n.walletType,chainId:n.chainId});}},connect:async({walletType:t,chainId:n})=>{o({walletConnecting:true,walletConnectionError:void 0});let a=selectAdapterByKey({adapter:r,adapterKey:l(t)});try{let e=await a?.connect({walletType:t,chainId:n,connectors:i().availableConnectors[l(t)]??[]});o({activeWallet:e}),a?.checkIsContractWallet&&e&&(i().updateActiveWallet({isContractAddress:await a.checkIsContractWallet({address:e.address,chainId:n})}),s&&await s(e)),o({walletConnecting:!1,lastConnectedWallet:{walletType:t,chainId:n}});}catch(e){o({walletConnecting:false,walletConnectionError:"Wallet connection failed: "+(e instanceof Error?e.message:String(e))});}},disconnect:async()=>{let t=i().activeWallet;t&&(await selectAdapterByKey({adapter:r,adapterKey:l(t.walletType)})?.disconnect(),o({activeWallet:void 0,lastConnectedWallet:void 0}));},walletConnecting:false,resetWalletConnectionError:()=>{o({walletConnectionError:void 0});},updateActiveWallet:t=>{i().activeWallet?o(a=>produce(a,e=>{e.activeWallet&&(e.activeWallet={...e.activeWallet,...t});})):t.walletType!==void 0&&t.chainId!==void 0&&t.address!==void 0&&o({activeWallet:t});},switchNetwork:async t=>{o({switchNetworkError:void 0});let n=i().activeWallet;if(n){let a=selectAdapterByKey({adapter:r,adapterKey:l(n.walletType)});try{await a?.checkAndSwitchNetwork(t,n.chainId,i().updateActiveWallet);}catch(e){o({switchNetworkError:"Switch network failed: "+(e instanceof Error?e.message:String(e))});}}},resetSwitchNetworkError:()=>o({switchNetworkError:void 0})}))}var g={impersonatedAddress:typeof window<"u"?window.localStorage.getItem("satellite-connect:impersonatedAddress")??"":"",setImpersonated:r=>typeof window<"u"?window.localStorage.setItem("satellite-connect:impersonatedAddress",r):void 0,getImpersonated:()=>typeof window<"u"?window.localStorage.getItem("satellite-connect:impersonatedAddress"):void 0};export{S as createSatelliteConnectStore,l as getAdapterFromWalletType,g as impersonatedHelpers};//# sourceMappingURL=index.mjs.map
2
2
  //# sourceMappingURL=index.mjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/utils/getAdapterFromWalletType.ts","../src/store/satelliteConnectStore.ts","../src/utils/getWalletTypeFromConnectorName.ts","../src/utils/impersonatedHelpers.ts"],"names":["getAdapterFromWalletType","walletType","OrbitAdapter","createSatelliteConnectStore","adapter","callbackAfterConnected","createStore","set","get","autoConnect","a","connectors","state","produce","draft","lastConnectedWallet","chainId","foundAdapter","selectAdapterByKey","wallet","activeWallet","getWalletTypeFromConnectorName","name","impersonatedHelpers","address"],"mappings":"uIA0BO,SAASA,CAAAA,CAAyBC,CAAAA,CAAsC,CAC7E,OAAQA,CAAAA,CAAW,KAAA,CAAM,GAAG,CAAA,CAAE,CAAC,CAAA,EAAKC,YAAAA,CAAa,GACnD,CCZO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CAAA,CAAG,CACVD,CAAAA,CAAI,CAAE,kBAAA,CAAoB,yBAAA,EAA6B,CAAA,YAAa,KAAA,CAAQ,CAAA,CAAE,OAAA,CAAU,OAAO,CAAC,CAAA,CAAG,CAAC,EACtG,CACF,CACF,CAAA,CAKA,uBAAA,CAAyB,IAAMA,CAAAA,CAAI,CAAE,kBAAA,CAAoB,MAAU,CAAC,CACtE,CAAA,CAAE,CACJ,CC7IO,SAASc,CAAAA,CAA+BjB,CAAAA,CAAuBkB,CAAAA,CAAsB,CAC1F,OAAO,CAAA,EAAGlB,CAAO,CAAA,CAAA,EAAIkB,CAAAA,CAAK,OAAA,CAAQ,OAAQ,EAAE,CAAA,CAAE,WAAA,EAAa,CAAA,CAC7D,CCrBO,IAAMC,CAAAA,CAAsB,CAKjC,mBAAA,CACE,OAAO,MAAA,CAAW,GAAA,CAAe,MAAA,CAAO,aAAa,OAAA,CAAQ,uCAAuC,CAAA,EAAK,EAAA,CAAM,EAAA,CAcjH,eAAA,CAAkBC,CAAAA,EAChB,OAAO,MAAA,CAAW,GAAA,CACd,MAAA,CAAO,YAAA,CAAa,OAAA,CAAQ,uCAAA,CAAyCA,CAAO,CAAA,CAC5E,MAAA,CAeN,eAAA,CAAiB,IACf,OAAO,MAAA,CAAW,GAAA,CAAc,MAAA,CAAO,YAAA,CAAa,OAAA,CAAQ,uCAAuC,CAAA,CAAI,MAC3G","file":"index.mjs","sourcesContent":["import { OrbitAdapter } from '@tuwaio/orbit-core';\n\nimport { WalletType } from '../types';\n\n/**\n * Extracts the adapter type from a wallet type string\n *\n * @example\n * ```typescript\n * // Returns OrbitAdapter.EVM\n * getAdapterFromWalletType('evm:metamask');\n *\n * // Returns OrbitAdapter.SOLANA\n * getAdapterFromWalletType('solana:phantom');\n *\n * // Returns OrbitAdapter.EVM (default)\n * getAdapterFromWalletType('unknown');\n * ```\n *\n * @param walletType - Wallet type in format \"chain:wallet\" (e.g. \"evm:metamask\", \"solana:phantom\")\n * @returns The corresponding {@link OrbitAdapter} type or EVM as default\n *\n * @remarks\n * The function splits the wallet type string by \":\" and takes the first part as the adapter type.\n * If the split fails or the first part is empty, it defaults to EVM adapter.\n */\nexport function getAdapterFromWalletType(walletType: WalletType): OrbitAdapter {\n return (walletType.split(':')[0] ?? OrbitAdapter.EVM) as OrbitAdapter;\n}\n","import { selectAdapterByKey } from '@tuwaio/orbit-core';\nimport { Draft, produce } from 'immer';\nimport { createStore } from 'zustand/vanilla';\n\nimport { Connector, ISatelliteConnectStore, SatelliteConnectStoreInitialParameters, Wallet } from '../types';\nimport { getAdapterFromWalletType } from '../utils/getAdapterFromWalletType';\n\n/**\n * Creates a Satellite Connect store instance for managing wallet connections and state\n *\n * @param params - Configuration parameters for the store\n * @param params.adapter - Single adapter or array of adapters for different chains\n * @param params.callbackAfterConnected - Optional callback function called after successful wallet connection\n *\n * @returns A Zustand store instance with wallet connection state and methods\n */\nexport function createSatelliteConnectStore({\n adapter,\n callbackAfterConnected,\n}: SatelliteConnectStoreInitialParameters) {\n return createStore<ISatelliteConnectStore>()((set, get) => ({\n /**\n * Returns configured adapter(s)\n */\n getAdapter: () => adapter,\n\n /**\n * Available wallet connectors for each chain\n */\n availableConnectors: {},\n\n /**\n * Initializes wallet connectors for all configured adapters\n * @param autoConnect - Whether to automatically reconnect to last used wallet\n */\n initializeAppConnectors: async ({ autoConnect }) => {\n if (Array.isArray(adapter)) {\n const connectors = await Promise.all(adapter.map((a) => a.getConnectors()));\n connectors.forEach((connectors) => {\n set((state) =>\n produce(state, (draft) => {\n draft.availableConnectors[connectors.adapter] = connectors.connectors as Draft<Connector[]>;\n }),\n );\n });\n } else {\n const connectors = await adapter.getConnectors();\n set((state) =>\n produce(state, (draft) => {\n draft.availableConnectors[connectors.adapter] = connectors.connectors as Draft<Connector[]>;\n }),\n );\n }\n if (autoConnect) {\n const lastConnectedWallet = get().lastConnectedWallet;\n if (lastConnectedWallet) {\n await get().connect({ walletType: lastConnectedWallet.walletType, chainId: lastConnectedWallet.chainId });\n }\n }\n },\n\n /**\n * Connects to a wallet\n * @param walletType - Type of wallet to connect to\n * @param chainId - Chain ID to connect on\n */\n connect: async ({ walletType, chainId }) => {\n set({ walletConnecting: true, walletConnectionError: undefined });\n const foundAdapter = selectAdapterByKey({ adapter, adapterKey: getAdapterFromWalletType(walletType) });\n try {\n const wallet = await foundAdapter?.connect({\n walletType,\n chainId,\n connectors: get().availableConnectors[getAdapterFromWalletType(walletType)] ?? [],\n });\n set({ activeWallet: wallet });\n if (foundAdapter?.checkIsContractWallet && wallet) {\n get().updateActiveWallet({\n isContractAddress: await foundAdapter.checkIsContractWallet({\n address: wallet.address,\n chainId,\n }),\n });\n if (callbackAfterConnected) {\n await callbackAfterConnected(wallet);\n }\n }\n set({ walletConnecting: false, lastConnectedWallet: { walletType, chainId } });\n } catch (e) {\n set({\n walletConnecting: false,\n walletConnectionError: 'Wallet connection failed: ' + (e instanceof Error ? e.message : String(e)),\n });\n }\n },\n\n /**\n * Disconnects the currently active wallet\n */\n disconnect: async () => {\n const activeWallet = get().activeWallet;\n if (activeWallet) {\n const foundAdapter = selectAdapterByKey({\n adapter,\n adapterKey: getAdapterFromWalletType(activeWallet.walletType),\n });\n await foundAdapter?.disconnect();\n set({ activeWallet: undefined, lastConnectedWallet: undefined });\n }\n },\n\n walletConnecting: false,\n\n /**\n * Resets any wallet connection errors\n */\n resetWalletConnectionError: () => {\n set({ walletConnectionError: undefined });\n },\n\n /**\n * Updates the active wallet's properties\n * @param wallet - Partial wallet object with properties to update\n */\n updateActiveWallet: (wallet: Partial<Wallet>) => {\n const activeWallet = get().activeWallet;\n if (activeWallet) {\n set((state) =>\n produce(state, (draft) => {\n if (draft.activeWallet) {\n draft.activeWallet = {\n ...draft.activeWallet,\n ...wallet,\n };\n }\n }),\n );\n } else {\n if (wallet.walletType !== undefined && wallet.chainId !== undefined && wallet.address !== undefined) {\n set({ activeWallet: wallet as Wallet });\n }\n }\n },\n\n /**\n * Switches the connected wallet to a different network\n * @param chainId - Target chain ID to switch to\n */\n switchNetwork: async (chainId: string | number) => {\n set({ switchNetworkError: undefined });\n const activeWallet = get().activeWallet;\n if (activeWallet) {\n const foundAdapter = selectAdapterByKey({\n adapter,\n adapterKey: getAdapterFromWalletType(activeWallet.walletType),\n });\n try {\n await foundAdapter?.checkAndSwitchNetwork(chainId, activeWallet.chainId, get().updateActiveWallet);\n } catch (e) {\n set({ switchNetworkError: 'Switch network failed: ' + (e instanceof Error ? e.message : String(e)) });\n }\n }\n },\n\n /**\n * Resets any network switching errors\n */\n resetSwitchNetworkError: () => set({ switchNetworkError: undefined }),\n }));\n}\n","import { OrbitAdapter } from '@tuwaio/orbit-core';\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 * 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 impersonatedHelpers = {\n /**\n * Currently impersonated address from localStorage\n * Returns empty string if not set or in SSR context\n */\n impersonatedAddress:\n typeof window !== 'undefined' ? (window.localStorage.getItem('satellite-connect:impersonatedAddress') ?? '') : '',\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 setImpersonated: (address: string) =>\n typeof window !== 'undefined'\n ? window.localStorage.setItem('satellite-connect:impersonatedAddress', address)\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 getImpersonated: () =>\n typeof window !== 'undefined' ? window.localStorage.getItem('satellite-connect:impersonatedAddress') : undefined,\n};\n"]}
1
+ {"version":3,"sources":["../src/utils/getAdapterFromWalletType.ts","../src/store/satelliteConnectStore.ts","../src/utils/impersonatedHelpers.ts"],"names":["getAdapterFromWalletType","walletType","OrbitAdapter","createSatelliteConnectStore","adapter","callbackAfterConnected","createStore","set","get","autoConnect","connectors","state","produce","draft","lastConnectedWallet","chainId","foundAdapter","selectAdapterByKey","wallet","activeWallet","impersonatedHelpers","address"],"mappings":"uIA0BO,SAASA,CAAAA,CAAyBC,CAAAA,CAAsC,CAC7E,OAAQA,CAAAA,CAAW,KAAA,CAAM,GAAG,CAAA,CAAE,CAAC,CAAA,EAAKC,aAAa,GACnD,CCZO,SAASC,CAAAA,CAA4B,CAC1C,OAAA,CAAAC,EACA,sBAAA,CAAAC,CACF,CAAA,CAA2C,CACzC,OAAOC,WAAAA,GAAsC,CAACC,CAAAA,CAAKC,CAAAA,IAAS,CAI1D,UAAA,CAAY,IAAMJ,CAAAA,CAKlB,mBAAA,CAAqB,EAAC,CAMtB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IAAMa,CAAAA,CAAsB,CAKjC,mBAAA,CACE,OAAO,MAAA,CAAW,GAAA,CAAe,MAAA,CAAO,YAAA,CAAa,QAAQ,uCAAuC,CAAA,EAAK,EAAA,CAAM,EAAA,CAcjH,eAAA,CAAkBC,CAAAA,EAChB,OAAO,MAAA,CAAW,GAAA,CACd,MAAA,CAAO,YAAA,CAAa,OAAA,CAAQ,uCAAA,CAAyCA,CAAO,CAAA,CAC5E,MAAA,CAeN,eAAA,CAAiB,IACf,OAAO,MAAA,CAAW,GAAA,CAAc,MAAA,CAAO,YAAA,CAAa,OAAA,CAAQ,uCAAuC,CAAA,CAAI,MAC3G","file":"index.mjs","sourcesContent":["import { OrbitAdapter } from '@tuwaio/orbit-core';\n\nimport { WalletType } from '../types';\n\n/**\n * Extracts the adapter type from a wallet type string\n *\n * @example\n * ```typescript\n * // Returns OrbitAdapter.EVM\n * getAdapterFromWalletType('evm:metamask');\n *\n * // Returns OrbitAdapter.SOLANA\n * getAdapterFromWalletType('solana:phantom');\n *\n * // Returns OrbitAdapter.EVM (default)\n * getAdapterFromWalletType('unknown');\n * ```\n *\n * @param walletType - Wallet type in format \"chain:wallet\" (e.g. \"evm:metamask\", \"solana:phantom\")\n * @returns The corresponding {@link OrbitAdapter} type or EVM as default\n *\n * @remarks\n * The function splits the wallet type string by \":\" and takes the first part as the adapter type.\n * If the split fails or the first part is empty, it defaults to EVM adapter.\n */\nexport function getAdapterFromWalletType(walletType: WalletType): OrbitAdapter {\n return (walletType.split(':')[0] ?? OrbitAdapter.EVM) as OrbitAdapter;\n}\n","import { selectAdapterByKey } from '@tuwaio/orbit-core';\nimport { Draft, produce } from 'immer';\nimport { createStore } from 'zustand/vanilla';\n\nimport { Connector, ISatelliteConnectStore, SatelliteConnectStoreInitialParameters, Wallet } from '../types';\nimport { getAdapterFromWalletType } from '../utils/getAdapterFromWalletType';\n\n/**\n * Creates a Satellite Connect store instance for managing wallet connections and state\n *\n * @param params - Configuration parameters for the store\n * @param params.adapter - Single adapter or array of adapters for different chains\n * @param params.callbackAfterConnected - Optional callback function called after successful wallet connection\n *\n * @returns A Zustand store instance with wallet connection state and methods\n */\nexport function createSatelliteConnectStore({\n adapter,\n callbackAfterConnected,\n}: SatelliteConnectStoreInitialParameters) {\n return createStore<ISatelliteConnectStore>()((set, get) => ({\n /**\n * Returns configured adapter(s)\n */\n getAdapter: () => adapter,\n\n /**\n * Available wallet connectors for each chain\n */\n availableConnectors: {},\n\n /**\n * Initializes wallet connectors for all configured adapters\n * @param autoConnect - Whether to automatically reconnect to last used wallet\n */\n initializeAppConnectors: async ({ autoConnect }) => {\n if (Array.isArray(adapter)) {\n const connectors = await Promise.all(adapter.map((a) => a.getConnectors()));\n connectors.forEach((connectors) => {\n set((state) =>\n produce(state, (draft) => {\n draft.availableConnectors[connectors.adapter] = connectors.connectors as Draft<Connector[]>;\n }),\n );\n });\n } else {\n const connectors = await adapter.getConnectors();\n set((state) =>\n produce(state, (draft) => {\n draft.availableConnectors[connectors.adapter] = connectors.connectors as Draft<Connector[]>;\n }),\n );\n }\n if (autoConnect) {\n const lastConnectedWallet = get().lastConnectedWallet;\n if (lastConnectedWallet) {\n await get().connect({ walletType: lastConnectedWallet.walletType, chainId: lastConnectedWallet.chainId });\n }\n }\n },\n\n /**\n * Connects to a wallet\n * @param walletType - Type of wallet to connect to\n * @param chainId - Chain ID to connect on\n */\n connect: async ({ walletType, chainId }) => {\n set({ walletConnecting: true, walletConnectionError: undefined });\n const foundAdapter = selectAdapterByKey({ adapter, adapterKey: getAdapterFromWalletType(walletType) });\n try {\n const wallet = await foundAdapter?.connect({\n walletType,\n chainId,\n connectors: get().availableConnectors[getAdapterFromWalletType(walletType)] ?? [],\n });\n set({ activeWallet: wallet });\n if (foundAdapter?.checkIsContractWallet && wallet) {\n get().updateActiveWallet({\n isContractAddress: await foundAdapter.checkIsContractWallet({\n address: wallet.address,\n chainId,\n }),\n });\n if (callbackAfterConnected) {\n await callbackAfterConnected(wallet);\n }\n }\n set({ walletConnecting: false, lastConnectedWallet: { walletType, chainId } });\n } catch (e) {\n set({\n walletConnecting: false,\n walletConnectionError: 'Wallet connection failed: ' + (e instanceof Error ? e.message : String(e)),\n });\n }\n },\n\n /**\n * Disconnects the currently active wallet\n */\n disconnect: async () => {\n const activeWallet = get().activeWallet;\n if (activeWallet) {\n const foundAdapter = selectAdapterByKey({\n adapter,\n adapterKey: getAdapterFromWalletType(activeWallet.walletType),\n });\n await foundAdapter?.disconnect();\n set({ activeWallet: undefined, lastConnectedWallet: undefined });\n }\n },\n\n walletConnecting: false,\n\n /**\n * Resets any wallet connection errors\n */\n resetWalletConnectionError: () => {\n set({ walletConnectionError: undefined });\n },\n\n /**\n * Updates the active wallet's properties\n * @param wallet - Partial wallet object with properties to update\n */\n updateActiveWallet: (wallet: Partial<Wallet>) => {\n const activeWallet = get().activeWallet;\n if (activeWallet) {\n set((state) =>\n produce(state, (draft) => {\n if (draft.activeWallet) {\n draft.activeWallet = {\n ...draft.activeWallet,\n ...wallet,\n };\n }\n }),\n );\n } else {\n if (wallet.walletType !== undefined && wallet.chainId !== undefined && wallet.address !== undefined) {\n set({ activeWallet: wallet as Wallet });\n }\n }\n },\n\n /**\n * Switches the connected wallet to a different network\n * @param chainId - Target chain ID to switch to\n */\n switchNetwork: async (chainId: string | number) => {\n set({ switchNetworkError: undefined });\n const activeWallet = get().activeWallet;\n if (activeWallet) {\n const foundAdapter = selectAdapterByKey({\n adapter,\n adapterKey: getAdapterFromWalletType(activeWallet.walletType),\n });\n try {\n await foundAdapter?.checkAndSwitchNetwork(chainId, activeWallet.chainId, get().updateActiveWallet);\n } catch (e) {\n set({ switchNetworkError: 'Switch network failed: ' + (e instanceof Error ? e.message : String(e)) });\n }\n }\n },\n\n /**\n * Resets any network switching errors\n */\n resetSwitchNetworkError: () => set({ switchNetworkError: undefined }),\n }));\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 impersonatedHelpers = {\n /**\n * Currently impersonated address from localStorage\n * Returns empty string if not set or in SSR context\n */\n impersonatedAddress:\n typeof window !== 'undefined' ? (window.localStorage.getItem('satellite-connect:impersonatedAddress') ?? '') : '',\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 setImpersonated: (address: string) =>\n typeof window !== 'undefined'\n ? window.localStorage.setItem('satellite-connect:impersonatedAddress', address)\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 getImpersonated: () =>\n typeof window !== 'undefined' ? window.localStorage.getItem('satellite-connect:impersonatedAddress') : undefined,\n};\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tuwaio/satellite-core",
3
- "version": "1.0.0-fix-test-alpha.1.3665b1d",
3
+ "version": "1.0.0-fix-test-alpha.2.f8f5982",
4
4
  "private": false,
5
5
  "author": "Oleksandr Tkach",
6
6
  "license": "Apache-2.0",
@@ -53,7 +53,7 @@
53
53
  "tsup": "^8.5.0",
54
54
  "typescript": "^5.9.2",
55
55
  "zustand": "^5.0.8",
56
- "@tuwaio/orbit-core": "^1.0.0-fix-test-alpha.1.3665b1d"
56
+ "@tuwaio/orbit-core": "^1.0.0-fix-test-alpha.2.f8f5982"
57
57
  },
58
58
  "scripts": {
59
59
  "start": "tsup src/index.ts --watch",