@tuwaio/satellite-core 1.0.0-fix-test-alpha.20.ee459fd → 1.0.0-fix-test-alpha.21.76f200b
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.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 +2 -2
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 p(t){return t.split(":")[0]??orbitCore.OrbitAdapter.EVM}var w={impersonatedAddress:typeof window<"u"?window.localStorage.getItem("satellite-connect:impersonatedAddress")??"":"",setImpersonated:t=>typeof window<"u"?window.localStorage.setItem("satellite-connect:impersonatedAddress",t):void 0,getImpersonated:()=>typeof window<"u"?window.localStorage.getItem("satellite-connect:impersonatedAddress"):void 0,removeImpersonated:()=>typeof window<"u"?window.localStorage.removeItem("satellite-connect:impersonatedAddress"):void 0};function m(t){if(typeof window>"u")return;let s=window.localStorage.getItem(t);if(s)try{return JSON.parse(s)}catch(o){console.error(`Error parsing ${t} from localStorage:`,o);return}}var d={STORAGE_KEY:"satellite-connect:lastConnectedWallet",lastConnectedWallet:m("satellite-connect:lastConnectedWallet"),setLastConnectedWallet:({walletType:t,chainId:s})=>typeof window<"u"?window.localStorage.setItem(d.STORAGE_KEY,JSON.stringify({walletType:t,chainId:s})):void 0,getLastConnectedWallet:()=>m(d.STORAGE_KEY),removeLastConnectedWallet:()=>typeof window<"u"?window.localStorage.removeItem(d.STORAGE_KEY):void 0};var f={STORAGE_KEY:"satellite-connect:recentConnectedWallet",recentConnectedWallet:m("satellite-connect:recentConnectedWallet"),setRecentConnectedWallet:({wallets:t})=>typeof window<"u"?window.localStorage.setItem(f.STORAGE_KEY,JSON.stringify({wallets:t})):void 0,getRecentConnectedWallet:()=>m(f.STORAGE_KEY),removeRecentConnectedWallet:()=>typeof window<"u"?window.localStorage.removeItem(f.STORAGE_KEY):void 0};function B({adapter:t,callbackAfterConnected:s}){return vanilla.createStore()((o,c)=>({getAdapter:()=>t,getConnectors:()=>{let e;return Array.isArray(t)?e=t.map(n=>n.getConnectors()):e=[t.getConnectors()],e.reduce((n,l)=>{let a=l.adapter,r=l.connectors;return {...n,[a]:r}},{})},initializeAutoConnect:async e=>{if(e){let n=d.getLastConnectedWallet();n&&(await orbitCore.delay(null,
|
|
1
|
+
'use strict';var orbitCore=require('@tuwaio/orbit-core'),immer=require('immer'),vanilla=require('zustand/vanilla');function p(t){return t.split(":")[0]??orbitCore.OrbitAdapter.EVM}var w={impersonatedAddress:typeof window<"u"?window.localStorage.getItem("satellite-connect:impersonatedAddress")??"":"",setImpersonated:t=>typeof window<"u"?window.localStorage.setItem("satellite-connect:impersonatedAddress",t):void 0,getImpersonated:()=>typeof window<"u"?window.localStorage.getItem("satellite-connect:impersonatedAddress"):void 0,removeImpersonated:()=>typeof window<"u"?window.localStorage.removeItem("satellite-connect:impersonatedAddress"):void 0};function m(t){if(typeof window>"u")return;let s=window.localStorage.getItem(t);if(s)try{return JSON.parse(s)}catch(o){console.error(`Error parsing ${t} from localStorage:`,o);return}}var d={STORAGE_KEY:"satellite-connect:lastConnectedWallet",lastConnectedWallet:m("satellite-connect:lastConnectedWallet"),setLastConnectedWallet:({walletType:t,chainId:s})=>typeof window<"u"?window.localStorage.setItem(d.STORAGE_KEY,JSON.stringify({walletType:t,chainId:s})):void 0,getLastConnectedWallet:()=>m(d.STORAGE_KEY),removeLastConnectedWallet:()=>typeof window<"u"?window.localStorage.removeItem(d.STORAGE_KEY):void 0};var f={STORAGE_KEY:"satellite-connect:recentConnectedWallet",recentConnectedWallet:m("satellite-connect:recentConnectedWallet"),setRecentConnectedWallet:({wallets:t})=>typeof window<"u"?window.localStorage.setItem(f.STORAGE_KEY,JSON.stringify({wallets:t})):void 0,getRecentConnectedWallet:()=>m(f.STORAGE_KEY),removeRecentConnectedWallet:()=>typeof window<"u"?window.localStorage.removeItem(f.STORAGE_KEY):void 0};function B({adapter:t,callbackAfterConnected:s}){return vanilla.createStore()((o,c)=>({getAdapter:()=>t,getConnectors:()=>{let e;return Array.isArray(t)?e=t.map(n=>n.getConnectors()):e=[t.getConnectors()],e.reduce((n,l)=>{let a=l.adapter,r=l.connectors;return {...n,[a]:r}},{})},initializeAutoConnect:async e=>{if(e){let n=d.getLastConnectedWallet();n&&(await orbitCore.delay(null,200),await c().connect({walletType:n.walletType,chainId:n.chainId}));}},walletConnecting:false,walletConnectionError:void 0,switchNetworkError:void 0,activeWallet:void 0,connect:async({walletType:e,chainId:n})=>{o({walletConnecting:true,walletConnectionError:void 0});let l=p(e),a=orbitCore.selectAdapterByKey({adapter:t,adapterKey:l});if(!a){o({walletConnecting:false,walletConnectionError:`No adapter found for wallet type: ${e}`});return}try{let r=await a.connect({walletType:e,chainId:n});if(o({activeWallet:r}),orbitCore.connectedWalletChainHelpers.setConnectedWalletChain(n),a.checkIsContractWallet){let i=await a.checkIsContractWallet({address:r.address,chainId:n});c().updateActiveWallet({isContractAddress:i});}if(s){let i=c().activeWallet;i&&await s(i);}o({walletConnecting:!1}),d.setLastConnectedWallet({walletType:e,chainId:n});let u=f.getRecentConnectedWallet();if(u){let i={wallets:{...u.wallets,[p(e)]:e}};f.setRecentConnectedWallet(i);}else {let i={wallets:{[p(e)]:e}};f.setRecentConnectedWallet(i);}}catch(r){await c().disconnect(),o({walletConnecting:false,walletConnectionError:"Wallet connection failed: "+(r instanceof Error?r.message:String(r))});}},disconnect:async()=>{let e=c().activeWallet;e&&(await orbitCore.selectAdapterByKey({adapter:t,adapterKey:p(e.walletType)})?.disconnect(),o({activeWallet:void 0,walletConnectionError:void 0,switchNetworkError:void 0}),d.removeLastConnectedWallet(),orbitCore.connectedWalletChainHelpers.removeConnectedWalletChain(),w.removeImpersonated());},disconnectAll:async()=>{if(await orbitCore.delay(null,150),Array.isArray(t))await Promise.allSettled(t.map(async e=>{try{await e.disconnect();}catch{}}));else try{await t.disconnect();}catch{}o({activeWallet:void 0,walletConnectionError:void 0,switchNetworkError:void 0}),orbitCore.connectedWalletChainHelpers.removeConnectedWalletChain(),w.removeImpersonated();},resetWalletConnectionError:()=>{o({walletConnectionError:void 0});},updateActiveWallet:e=>{let n=c().activeWallet;n?(e.chainId&&(orbitCore.connectedWalletChainHelpers.setConnectedWalletChain(e.chainId),d.setLastConnectedWallet({walletType:n.walletType,chainId:e.chainId})),o(l=>immer.produce(l,a=>{a.activeWallet&&(a.activeWallet={...a.activeWallet,...e});}))):e.walletType!==void 0&&e.chainId!==void 0&&e.address!==void 0?(orbitCore.connectedWalletChainHelpers.setConnectedWalletChain(e.chainId),o({activeWallet:e})):console.warn("Attempted to set activeWallet with incomplete data while activeWallet was undefined.");},switchNetwork:async e=>{o({switchNetworkError:void 0});let n=c().activeWallet;if(n){let l=p(n.walletType),a=orbitCore.selectAdapterByKey({adapter:t,adapterKey:l});if(!a){o({switchNetworkError:`No adapter found for active wallet type: ${n.walletType}`});return}try{await a.checkAndSwitchNetwork(e,n.chainId,c().updateActiveWallet);}catch(r){o({switchNetworkError:"Switch network failed: "+(r instanceof Error?r.message:String(r))});}}},resetSwitchNetworkError:()=>o({switchNetworkError:void 0})}))}var $=t=>{switch(t){case "Safe":return "safewallet";default:return t.replace(/\s+/g,"").toLowerCase()}};exports.createSatelliteConnectStore=B;exports.formatWalletName=$;exports.getAdapterFromWalletType=p;exports.getParsedStorageItem=m;exports.impersonatedHelpers=w;exports.lastConnectedWalletHelpers=d;exports.recentConnectedWalletHelpers=f;//# 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/utils/impersonatedHelpers.ts","../src/utils/getParsedStorageItem.ts","../src/utils/lastConnectedWalletHelpers.ts","../src/utils/recentConnectedWalletHelpers.ts","../src/store/satelliteConnectStore.ts","../src/utils/formatWalletName.ts"],"names":["getAdapterFromWalletType","walletType","OrbitAdapter","impersonatedHelpers","address","getParsedStorageItem","key","item","error","lastConnectedWalletHelpers","chainId","recentConnectedWalletHelpers","wallets","createSatelliteConnectStore","adapter","callbackAfterConnected","createStore","set","get","results","a","accumulator","currentResult","value","autoConnect","lastConnectedWallet","delay","adapterKey","foundAdapter","selectAdapterByKey","wallet","connectedWalletChainHelpers","isContractAddress","updatedWallet","recentlyConnectedWallet","updatedRecentlyConnectedWallet","e","activeWallet","state","produce","draft","formatWalletName","walletName"],"mappings":"mHA0BO,SAASA,CAAAA,CAAyBC,CAAAA,CAAsC,CAC7E,OAAQA,CAAAA,CAAW,MAAM,GAAG,CAAA,CAAE,CAAC,CAAA,EAAKC,sBAAAA,CAAa,GACnD,CCnBO,IAAMC,CAAAA,CAAsB,CAKjC,mBAAA,CACE,OAAO,OAAW,GAAA,CAAe,MAAA,CAAO,aAAa,OAAA,CAAQ,uCAAuC,CAAA,EAAK,EAAA,CAAM,EAAA,CAcjH,eAAA,CAAkBC,GAChB,OAAO,MAAA,CAAW,IACd,MAAA,CAAO,YAAA,CAAa,QAAQ,uCAAA,CAAyCA,CAAO,CAAA,CAC5E,MAAA,CAeN,eAAA,CAAiB,IACf,OAAO,MAAA,CAAW,GAAA,CAAc,OAAO,YAAA,CAAa,OAAA,CAAQ,uCAAuC,CAAA,CAAI,MAAA,CAEzG,kBAAA,CAAoB,IAClB,OAAO,MAAA,CAAW,IAAc,MAAA,CAAO,YAAA,CAAa,WAAW,uCAAuC,CAAA,CAAI,MAC9G,EC9CO,SAASC,CAAAA,CAAiCC,CAAAA,CAAqC,CACpF,GAAI,OAAO,MAAA,CAAW,GAAA,CACpB,OAGF,IAAMC,CAAAA,CAAO,OAAO,YAAA,CAAa,OAAA,CAAQD,CAAG,CAAA,CAG5C,GAAKC,CAAAA,CAIL,GAAI,CAEF,OAAO,KAAK,KAAA,CAAMA,CA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,CAAAA,CAAeC,4BAAAA,CAAmB,CAAE,OAAA,CAAAf,CAAAA,CAAS,UAAA,CAAAa,CAAW,CAAC,CAAA,CAE/D,GAAI,CAACC,CAAAA,CAAc,CACjBX,CAAAA,CAAI,CAAE,mBAAoB,CAAA,yCAAA,EAA4CoB,CAAAA,CAAa,UAAU,CAAA,CAAG,CAAC,CAAA,CACjG,MACF,CAEA,GAAI,CAEF,MAAMT,CAAAA,CAAa,sBAAsBlB,CAAAA,CAAS2B,CAAAA,CAAa,OAAA,CAASnB,CAAAA,EAAI,CAAE,kBAAkB,EAClG,CAAA,MAASkB,CAAAA,CAAG,CACVnB,CAAAA,CAAI,CAAE,mBAAoB,yBAAA,EAA6BmB,CAAAA,YAAa,KAAA,CAAQA,CAAAA,CAAE,OAAA,CAAU,MAAA,CAAOA,CAAC,CAAA,CAAG,CAAC,EACtG,CACF,CACF,EAUA,uBAAA,CAAyB,IAAMnB,CAAAA,CAAI,CAAE,kBAAA,CAAoB,MAAU,CAAC,CACtE,CAAA,CAAE,CACJ,CChSO,IAAMwB,EAAoBC,CAAAA,EAAuB,CACtD,OAAQA,CAAAA,EACN,KAAK,OACH,OAAO,YAAA,CACT,QACE,OAAOA,CAAAA,CAAW,OAAA,CAAQ,OAAQ,EAAE,CAAA,CAAE,WAAA,EAC1C,CACF","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","/**\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 removeImpersonated: () =>\n typeof window !== 'undefined' ? window.localStorage.removeItem('satellite-connect:impersonatedAddress') : undefined,\n};\n","/**\n * Internal function for safely retrieving and parsing data from localStorage.\n *\n * @param key - The key for localStorage\n * @returns The parsed LastConnectedWallet object or undefined if data is not found/invalid\n */\nexport function getParsedStorageItem<ReturnType>(key: string): ReturnType | undefined {\n if (typeof window === 'undefined') {\n return undefined;\n }\n\n const item = window.localStorage.getItem(key);\n\n // If the item is null (not set) or an empty string, return undefined\n if (!item) {\n return undefined;\n }\n\n try {\n // Safe JSON parsing\n return JSON.parse(item) as ReturnType;\n } catch (error) {\n // In case of a parsing error (e.g., invalid JSON), log the error and return undefined\n console.error(`Error parsing ${key} from localStorage:`, error);\n return undefined;\n }\n}\n","import { WalletType } from '../types';\nimport { getParsedStorageItem } from './getParsedStorageItem';\n\ntype LastConnectedWallet = { walletType: WalletType; chainId: number | string };\n\n/**\n * Helper utilities for managing the last connected wallet state\n *\n * @remarks\n * All data is stored in localStorage with the 'satellite-connect:lastConnectedWallet' key.\n * Functions are safe to use in both browser and SSR environments.\n */\nexport const lastConnectedWalletHelpers = {\n // Key used for localStorage\n STORAGE_KEY: 'satellite-connect:lastConnectedWallet',\n\n /**\n * The value of the last connected wallet, initialized when the module loads.\n * Returns undefined if not set, invalid, or in an SSR context.\n */\n lastConnectedWallet: getParsedStorageItem<LastConnectedWallet>('satellite-connect:lastConnectedWallet'),\n\n /**\n * Stores the last connected wallet data in localStorage.\n *\n * @param data - Object containing the wallet type and chain ID.\n * @returns undefined in SSR context, void in browser\n */\n setLastConnectedWallet: ({ walletType, chainId }: LastConnectedWallet) =>\n typeof window !== 'undefined'\n ? window.localStorage.setItem(lastConnectedWalletHelpers.STORAGE_KEY, JSON.stringify({ walletType, chainId }))\n : undefined,\n\n /**\n * Retrieves the current last connected wallet data from localStorage.\n *\n * @returns The LastConnectedWallet object or undefined if not set or in SSR context\n */\n getLastConnectedWallet: () => getParsedStorageItem<LastConnectedWallet>(lastConnectedWalletHelpers.STORAGE_KEY),\n\n /**\n * Removes the last connected wallet data from localStorage.\n *\n * @returns undefined in SSR context, void in browser\n */\n removeLastConnectedWallet: () =>\n typeof window !== 'undefined' ? window.localStorage.removeItem(lastConnectedWalletHelpers.STORAGE_KEY) : undefined,\n};\n","import { OrbitAdapter } from '@tuwaio/orbit-core';\n\nimport { WalletType } from '../types';\nimport { getParsedStorageItem } from './getParsedStorageItem';\n\nexport type RecentConnectedWallet = { wallets: Record<OrbitAdapter, WalletType> };\n\n/**\n * Helper utilities for managing the last connected wallet state\n *\n * @remarks\n * All data is stored in localStorage with the 'satellite-connect:lastConnectedWallet' key.\n * Functions are safe to use in both browser and SSR environments.\n */\nexport const recentConnectedWalletHelpers = {\n // Key used for localStorage\n STORAGE_KEY: 'satellite-connect:recentConnectedWallet',\n\n /**\n * The value of the last connected wallet, initialized when the module loads.\n * Returns undefined if not set, invalid, or in an SSR context.\n */\n recentConnectedWallet: getParsedStorageItem<RecentConnectedWallet>('satellite-connect:recentConnectedWallet'),\n\n /**\n * Stores the last connected wallet data in localStorage.\n *\n * @param data - Object containing the wallet type and chain ID.\n * @returns undefined in SSR context, void in browser\n */\n setRecentConnectedWallet: ({ wallets }: RecentConnectedWallet) =>\n typeof window !== 'undefined'\n ? window.localStorage.setItem(recentConnectedWalletHelpers.STORAGE_KEY, JSON.stringify({ wallets }))\n : undefined,\n\n /**\n * Retrieves the current last connected wallet data from localStorage.\n *\n * @returns The LastConnectedWallet object or undefined if not set or in SSR context\n */\n getRecentConnectedWallet: () => getParsedStorageItem<RecentConnectedWallet>(recentConnectedWalletHelpers.STORAGE_KEY),\n\n /**\n * Removes the last connected wallet data from localStorage.\n *\n * @returns undefined in SSR context, void in browser\n */\n removeRecentConnectedWallet: () =>\n typeof window !== 'undefined'\n ? window.localStorage.removeItem(recentConnectedWalletHelpers.STORAGE_KEY)\n : undefined,\n};\n","import { connectedWalletChainHelpers, OrbitAdapter, selectAdapterByKey } from '@tuwaio/orbit-core';\nimport { delay } from '@tuwaio/orbit-core';\nimport { produce } from 'immer';\nimport { createStore } from 'zustand/vanilla';\n\nimport { BaseWallet, ISatelliteConnectStore, SatelliteConnectStoreInitialParameters, Wallet } from '../types';\nimport { getAdapterFromWalletType } from '../utils/getAdapterFromWalletType';\nimport { impersonatedHelpers } from '../utils/impersonatedHelpers';\nimport { lastConnectedWalletHelpers } from '../utils/lastConnectedWalletHelpers';\nimport { RecentConnectedWallet, recentConnectedWalletHelpers } from '../utils/recentConnectedWalletHelpers';\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<C, W extends BaseWallet = BaseWallet>({\n adapter,\n callbackAfterConnected,\n}: SatelliteConnectStoreInitialParameters<C, W>) {\n return createStore<ISatelliteConnectStore<C, W>>()((set, get) => ({\n /**\n * Returns configured adapter(s)\n */\n getAdapter: () => adapter,\n\n /**\n * Get wallet connectors for all configured adapters\n */\n getConnectors: () => {\n let results: { adapter: OrbitAdapter; connectors: C[] }[];\n\n if (Array.isArray(adapter)) {\n results = adapter.map((a) => a.getConnectors());\n } else {\n // Ensure the single adapter result is wrapped in an array for consistent processing\n results = [adapter.getConnectors()];\n }\n\n return results.reduce(\n (accumulator, currentResult) => {\n const key = currentResult.adapter;\n const value = currentResult.connectors;\n return {\n ...accumulator,\n [key]: value,\n };\n },\n {} as Partial<Record<OrbitAdapter, C[]>>,\n );\n },\n\n initializeAutoConnect: async (autoConnect) => {\n if (autoConnect) {\n const lastConnectedWallet = lastConnectedWalletHelpers.getLastConnectedWallet();\n if (lastConnectedWallet) {\n await delay(null, 5);\n await get().connect({ walletType: lastConnectedWallet.walletType, chainId: lastConnectedWallet.chainId });\n }\n }\n },\n\n walletConnecting: false,\n walletConnectionError: undefined,\n switchNetworkError: undefined,\n activeWallet: undefined,\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 adapterKey = getAdapterFromWalletType(walletType);\n const foundAdapter = selectAdapterByKey({ adapter, adapterKey });\n\n if (!foundAdapter) {\n set({\n walletConnecting: false,\n walletConnectionError: `No adapter found for wallet type: ${walletType}`,\n });\n return;\n }\n\n try {\n const wallet = await foundAdapter.connect({\n walletType,\n chainId,\n });\n\n // 1. Set initial wallet state\n set({ activeWallet: wallet });\n\n // 2. Set connected chain storage\n connectedWalletChainHelpers.setConnectedWalletChain(chainId);\n\n // 3. Check for contract address if the adapter supports it\n if (foundAdapter.checkIsContractWallet) {\n const isContractAddress = await foundAdapter.checkIsContractWallet({\n address: wallet.address,\n chainId,\n });\n\n // Update only the isContractAddress property\n get().updateActiveWallet({ isContractAddress });\n }\n\n // 4. Run callback if provided\n if (callbackAfterConnected) {\n // Use the latest wallet state after potential updates (like isContractAddress)\n const updatedWallet = get().activeWallet;\n if (updatedWallet) {\n await callbackAfterConnected(updatedWallet);\n }\n }\n\n // 5. Final state updates\n set({ walletConnecting: false });\n lastConnectedWalletHelpers.setLastConnectedWallet({ walletType, chainId });\n const recentlyConnectedWallet = recentConnectedWalletHelpers.getRecentConnectedWallet();\n if (recentlyConnectedWallet) {\n const updatedRecentlyConnectedWallet = {\n wallets: {\n ...recentlyConnectedWallet.wallets,\n [getAdapterFromWalletType(walletType)]: walletType,\n },\n };\n recentConnectedWalletHelpers.setRecentConnectedWallet(updatedRecentlyConnectedWallet);\n } else {\n const updatedRecentlyConnectedWallet = {\n wallets: {\n [getAdapterFromWalletType(walletType)]: walletType,\n },\n } as RecentConnectedWallet;\n recentConnectedWalletHelpers.setRecentConnectedWallet(updatedRecentlyConnectedWallet);\n }\n } catch (e) {\n await get().disconnect();\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\n // Call disconnect only if adapter is found\n await foundAdapter?.disconnect();\n\n // Clear all states and storages\n set({ activeWallet: undefined, walletConnectionError: undefined, switchNetworkError: undefined });\n lastConnectedWalletHelpers.removeLastConnectedWallet();\n connectedWalletChainHelpers.removeConnectedWalletChain();\n impersonatedHelpers.removeImpersonated();\n }\n },\n\n disconnectAll: async () => {\n await delay(null, 1);\n if (Array.isArray(adapter)) {\n await Promise.allSettled(\n adapter.map(async (a) => {\n try {\n await a.disconnect();\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n } catch (e) {\n /* empty */\n }\n }),\n );\n } else {\n try {\n await adapter.disconnect();\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n } catch (e) {\n /* empty */\n }\n }\n set({ activeWallet: undefined, walletConnectionError: undefined, switchNetworkError: undefined });\n connectedWalletChainHelpers.removeConnectedWalletChain();\n impersonatedHelpers.removeImpersonated();\n },\n\n /**\n * Contains error message if connection failed\n */\n // walletConnectionError is declared above with an initial value\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<W>>) => {\n const activeWallet = get().activeWallet;\n if (activeWallet) {\n // If chainId is updated, update storage\n if (wallet.chainId) {\n connectedWalletChainHelpers.setConnectedWalletChain(wallet.chainId);\n\n // Update lastConnectedWallet storage if chainId changes\n lastConnectedWalletHelpers.setLastConnectedWallet({\n walletType: activeWallet.walletType,\n chainId: wallet.chainId,\n });\n }\n\n // Use produce for immutable state update\n set((state) =>\n produce(state, (draft) => {\n if (draft.activeWallet) {\n // Ensure we merge partial properties into the existing activeWallet object\n draft.activeWallet = {\n ...draft.activeWallet,\n ...wallet,\n } as W; // Cast ensures type compatibility after merging\n }\n }),\n );\n } else {\n const isWalletCanChange =\n wallet.walletType !== undefined && wallet.chainId !== undefined && wallet.address !== undefined;\n\n if (isWalletCanChange) {\n connectedWalletChainHelpers.setConnectedWalletChain(wallet.chainId!);\n set({ activeWallet: wallet as W });\n } else {\n console.warn('Attempted to set activeWallet with incomplete data while activeWallet was undefined.');\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 adapterKey = getAdapterFromWalletType(activeWallet.walletType);\n const foundAdapter = selectAdapterByKey({ adapter, adapterKey });\n\n if (!foundAdapter) {\n set({ switchNetworkError: `No adapter found for active wallet type: ${activeWallet.walletType}` });\n return;\n }\n\n try {\n // Pass the local updateActiveWallet method from 'get()' to the adapter\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 * Contains error message if network switch failed\n */\n // switchNetworkError is declared above with an initial value\n\n /**\n * Resets any network switching errors\n */\n resetSwitchNetworkError: () => set({ switchNetworkError: undefined }),\n }));\n}\n","export const formatWalletName = (walletName: string) => {\n switch (walletName) {\n case 'Safe':\n return 'safewallet';\n default:\n return walletName.replace(/\\s+/g, '').toLowerCase();\n }\n};\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/utils/getAdapterFromWalletType.ts","../src/utils/impersonatedHelpers.ts","../src/utils/getParsedStorageItem.ts","../src/utils/lastConnectedWalletHelpers.ts","../src/utils/recentConnectedWalletHelpers.ts","../src/store/satelliteConnectStore.ts","../src/utils/formatWalletName.ts"],"names":["getAdapterFromWalletType","walletType","OrbitAdapter","impersonatedHelpers","address","getParsedStorageItem","key","item","error","lastConnectedWalletHelpers","chainId","recentConnectedWalletHelpers","wallets","createSatelliteConnectStore","adapter","callbackAfterConnected","createStore","set","get","results","a","accumulator","currentResult","value","autoConnect","lastConnectedWallet","delay","adapterKey","foundAdapter","selectAdapterByKey","wallet","connectedWalletChainHelpers","isContractAddress","updatedWallet","recentlyConnectedWallet","updatedRecentlyConnectedWallet","e","activeWallet","state","produce","draft","format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AA,MAASkB,CAAAA,CAAG,CACVnB,CAAAA,CAAI,CAAE,mBAAoB,yBAAA,EAA6BmB,CAAAA,YAAa,KAAA,CAAQA,CAAAA,CAAE,OAAA,CAAU,MAAA,CAAOA,CAAC,CAAA,CAAG,CAAC,EACtG,CACF,CACF,EAUA,uBAAA,CAAyB,IAAMnB,CAAAA,CAAI,CAAE,kBAAA,CAAoB,MAAU,CAAC,CACtE,CAAA,CAAE,CACJ,CChSO,IAAMwB,EAAoBC,CAAAA,EAAuB,CACtD,OAAQA,CAAAA,EACN,KAAK,OACH,OAAO,YAAA,CACT,QACE,OAAOA,CAAAA,CAAW,OAAA,CAAQ,OAAQ,EAAE,CAAA,CAAE,WAAA,EAC1C,CACF","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","/**\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 removeImpersonated: () =>\n typeof window !== 'undefined' ? window.localStorage.removeItem('satellite-connect:impersonatedAddress') : undefined,\n};\n","/**\n * Internal function for safely retrieving and parsing data from localStorage.\n *\n * @param key - The key for localStorage\n * @returns The parsed LastConnectedWallet object or undefined if data is not found/invalid\n */\nexport function getParsedStorageItem<ReturnType>(key: string): ReturnType | undefined {\n if (typeof window === 'undefined') {\n return undefined;\n }\n\n const item = window.localStorage.getItem(key);\n\n // If the item is null (not set) or an empty string, return undefined\n if (!item) {\n return undefined;\n }\n\n try {\n // Safe JSON parsing\n return JSON.parse(item) as ReturnType;\n } catch (error) {\n // In case of a parsing error (e.g., invalid JSON), log the error and return undefined\n console.error(`Error parsing ${key} from localStorage:`, error);\n return undefined;\n }\n}\n","import { WalletType } from '../types';\nimport { getParsedStorageItem } from './getParsedStorageItem';\n\ntype LastConnectedWallet = { walletType: WalletType; chainId: number | string };\n\n/**\n * Helper utilities for managing the last connected wallet state\n *\n * @remarks\n * All data is stored in localStorage with the 'satellite-connect:lastConnectedWallet' key.\n * Functions are safe to use in both browser and SSR environments.\n */\nexport const lastConnectedWalletHelpers = {\n // Key used for localStorage\n STORAGE_KEY: 'satellite-connect:lastConnectedWallet',\n\n /**\n * The value of the last connected wallet, initialized when the module loads.\n * Returns undefined if not set, invalid, or in an SSR context.\n */\n lastConnectedWallet: getParsedStorageItem<LastConnectedWallet>('satellite-connect:lastConnectedWallet'),\n\n /**\n * Stores the last connected wallet data in localStorage.\n *\n * @param data - Object containing the wallet type and chain ID.\n * @returns undefined in SSR context, void in browser\n */\n setLastConnectedWallet: ({ walletType, chainId }: LastConnectedWallet) =>\n typeof window !== 'undefined'\n ? window.localStorage.setItem(lastConnectedWalletHelpers.STORAGE_KEY, JSON.stringify({ walletType, chainId }))\n : undefined,\n\n /**\n * Retrieves the current last connected wallet data from localStorage.\n *\n * @returns The LastConnectedWallet object or undefined if not set or in SSR context\n */\n getLastConnectedWallet: () => getParsedStorageItem<LastConnectedWallet>(lastConnectedWalletHelpers.STORAGE_KEY),\n\n /**\n * Removes the last connected wallet data from localStorage.\n *\n * @returns undefined in SSR context, void in browser\n */\n removeLastConnectedWallet: () =>\n typeof window !== 'undefined' ? window.localStorage.removeItem(lastConnectedWalletHelpers.STORAGE_KEY) : undefined,\n};\n","import { OrbitAdapter } from '@tuwaio/orbit-core';\n\nimport { WalletType } from '../types';\nimport { getParsedStorageItem } from './getParsedStorageItem';\n\nexport type RecentConnectedWallet = { wallets: Record<OrbitAdapter, WalletType> };\n\n/**\n * Helper utilities for managing the last connected wallet state\n *\n * @remarks\n * All data is stored in localStorage with the 'satellite-connect:lastConnectedWallet' key.\n * Functions are safe to use in both browser and SSR environments.\n */\nexport const recentConnectedWalletHelpers = {\n // Key used for localStorage\n STORAGE_KEY: 'satellite-connect:recentConnectedWallet',\n\n /**\n * The value of the last connected wallet, initialized when the module loads.\n * Returns undefined if not set, invalid, or in an SSR context.\n */\n recentConnectedWallet: getParsedStorageItem<RecentConnectedWallet>('satellite-connect:recentConnectedWallet'),\n\n /**\n * Stores the last connected wallet data in localStorage.\n *\n * @param data - Object containing the wallet type and chain ID.\n * @returns undefined in SSR context, void in browser\n */\n setRecentConnectedWallet: ({ wallets }: RecentConnectedWallet) =>\n typeof window !== 'undefined'\n ? window.localStorage.setItem(recentConnectedWalletHelpers.STORAGE_KEY, JSON.stringify({ wallets }))\n : undefined,\n\n /**\n * Retrieves the current last connected wallet data from localStorage.\n *\n * @returns The LastConnectedWallet object or undefined if not set or in SSR context\n */\n getRecentConnectedWallet: () => getParsedStorageItem<RecentConnectedWallet>(recentConnectedWalletHelpers.STORAGE_KEY),\n\n /**\n * Removes the last connected wallet data from localStorage.\n *\n * @returns undefined in SSR context, void in browser\n */\n removeRecentConnectedWallet: () =>\n typeof window !== 'undefined'\n ? window.localStorage.removeItem(recentConnectedWalletHelpers.STORAGE_KEY)\n : undefined,\n};\n","import { connectedWalletChainHelpers, OrbitAdapter, selectAdapterByKey } from '@tuwaio/orbit-core';\nimport { delay } from '@tuwaio/orbit-core';\nimport { produce } from 'immer';\nimport { createStore } from 'zustand/vanilla';\n\nimport { BaseWallet, ISatelliteConnectStore, SatelliteConnectStoreInitialParameters, Wallet } from '../types';\nimport { getAdapterFromWalletType } from '../utils/getAdapterFromWalletType';\nimport { impersonatedHelpers } from '../utils/impersonatedHelpers';\nimport { lastConnectedWalletHelpers } from '../utils/lastConnectedWalletHelpers';\nimport { RecentConnectedWallet, recentConnectedWalletHelpers } from '../utils/recentConnectedWalletHelpers';\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<C, W extends BaseWallet = BaseWallet>({\n adapter,\n callbackAfterConnected,\n}: SatelliteConnectStoreInitialParameters<C, W>) {\n return createStore<ISatelliteConnectStore<C, W>>()((set, get) => ({\n /**\n * Returns configured adapter(s)\n */\n getAdapter: () => adapter,\n\n /**\n * Get wallet connectors for all configured adapters\n */\n getConnectors: () => {\n let results: { adapter: OrbitAdapter; connectors: C[] }[];\n\n if (Array.isArray(adapter)) {\n results = adapter.map((a) => a.getConnectors());\n } else {\n // Ensure the single adapter result is wrapped in an array for consistent processing\n results = [adapter.getConnectors()];\n }\n\n return results.reduce(\n (accumulator, currentResult) => {\n const key = currentResult.adapter;\n const value = currentResult.connectors;\n return {\n ...accumulator,\n [key]: value,\n };\n },\n {} as Partial<Record<OrbitAdapter, C[]>>,\n );\n },\n\n initializeAutoConnect: async (autoConnect) => {\n if (autoConnect) {\n const lastConnectedWallet = lastConnectedWalletHelpers.getLastConnectedWallet();\n if (lastConnectedWallet) {\n await delay(null, 200);\n await get().connect({ walletType: lastConnectedWallet.walletType, chainId: lastConnectedWallet.chainId });\n }\n }\n },\n\n walletConnecting: false,\n walletConnectionError: undefined,\n switchNetworkError: undefined,\n activeWallet: undefined,\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 adapterKey = getAdapterFromWalletType(walletType);\n const foundAdapter = selectAdapterByKey({ adapter, adapterKey });\n\n if (!foundAdapter) {\n set({\n walletConnecting: false,\n walletConnectionError: `No adapter found for wallet type: ${walletType}`,\n });\n return;\n }\n\n try {\n const wallet = await foundAdapter.connect({\n walletType,\n chainId,\n });\n\n // 1. Set initial wallet state\n set({ activeWallet: wallet });\n\n // 2. Set connected chain storage\n connectedWalletChainHelpers.setConnectedWalletChain(chainId);\n\n // 3. Check for contract address if the adapter supports it\n if (foundAdapter.checkIsContractWallet) {\n const isContractAddress = await foundAdapter.checkIsContractWallet({\n address: wallet.address,\n chainId,\n });\n\n // Update only the isContractAddress property\n get().updateActiveWallet({ isContractAddress });\n }\n\n // 4. Run callback if provided\n if (callbackAfterConnected) {\n // Use the latest wallet state after potential updates (like isContractAddress)\n const updatedWallet = get().activeWallet;\n if (updatedWallet) {\n await callbackAfterConnected(updatedWallet);\n }\n }\n\n // 5. Final state updates\n set({ walletConnecting: false });\n lastConnectedWalletHelpers.setLastConnectedWallet({ walletType, chainId });\n const recentlyConnectedWallet = recentConnectedWalletHelpers.getRecentConnectedWallet();\n if (recentlyConnectedWallet) {\n const updatedRecentlyConnectedWallet = {\n wallets: {\n ...recentlyConnectedWallet.wallets,\n [getAdapterFromWalletType(walletType)]: walletType,\n },\n };\n recentConnectedWalletHelpers.setRecentConnectedWallet(updatedRecentlyConnectedWallet);\n } else {\n const updatedRecentlyConnectedWallet = {\n wallets: {\n [getAdapterFromWalletType(walletType)]: walletType,\n },\n } as RecentConnectedWallet;\n recentConnectedWalletHelpers.setRecentConnectedWallet(updatedRecentlyConnectedWallet);\n }\n } catch (e) {\n await get().disconnect();\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\n // Call disconnect only if adapter is found\n await foundAdapter?.disconnect();\n\n // Clear all states and storages\n set({ activeWallet: undefined, walletConnectionError: undefined, switchNetworkError: undefined });\n lastConnectedWalletHelpers.removeLastConnectedWallet();\n connectedWalletChainHelpers.removeConnectedWalletChain();\n impersonatedHelpers.removeImpersonated();\n }\n },\n\n disconnectAll: async () => {\n await delay(null, 150);\n if (Array.isArray(adapter)) {\n await Promise.allSettled(\n adapter.map(async (a) => {\n try {\n await a.disconnect();\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n } catch (e) {\n /* empty */\n }\n }),\n );\n } else {\n try {\n await adapter.disconnect();\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n } catch (e) {\n /* empty */\n }\n }\n set({ activeWallet: undefined, walletConnectionError: undefined, switchNetworkError: undefined });\n connectedWalletChainHelpers.removeConnectedWalletChain();\n impersonatedHelpers.removeImpersonated();\n },\n\n /**\n * Contains error message if connection failed\n */\n // walletConnectionError is declared above with an initial value\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<W>>) => {\n const activeWallet = get().activeWallet;\n if (activeWallet) {\n // If chainId is updated, update storage\n if (wallet.chainId) {\n connectedWalletChainHelpers.setConnectedWalletChain(wallet.chainId);\n\n // Update lastConnectedWallet storage if chainId changes\n lastConnectedWalletHelpers.setLastConnectedWallet({\n walletType: activeWallet.walletType,\n chainId: wallet.chainId,\n });\n }\n\n // Use produce for immutable state update\n set((state) =>\n produce(state, (draft) => {\n if (draft.activeWallet) {\n // Ensure we merge partial properties into the existing activeWallet object\n draft.activeWallet = {\n ...draft.activeWallet,\n ...wallet,\n } as W; // Cast ensures type compatibility after merging\n }\n }),\n );\n } else {\n const isWalletCanChange =\n wallet.walletType !== undefined && wallet.chainId !== undefined && wallet.address !== undefined;\n\n if (isWalletCanChange) {\n connectedWalletChainHelpers.setConnectedWalletChain(wallet.chainId!);\n set({ activeWallet: wallet as W });\n } else {\n console.warn('Attempted to set activeWallet with incomplete data while activeWallet was undefined.');\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 adapterKey = getAdapterFromWalletType(activeWallet.walletType);\n const foundAdapter = selectAdapterByKey({ adapter, adapterKey });\n\n if (!foundAdapter) {\n set({ switchNetworkError: `No adapter found for active wallet type: ${activeWallet.walletType}` });\n return;\n }\n\n try {\n // Pass the local updateActiveWallet method from 'get()' to the adapter\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 * Contains error message if network switch failed\n */\n // switchNetworkError is declared above with an initial value\n\n /**\n * Resets any network switching errors\n */\n resetSwitchNetworkError: () => set({ switchNetworkError: undefined }),\n }));\n}\n","export const formatWalletName = (walletName: string) => {\n switch (walletName) {\n case 'Safe':\n return 'safewallet';\n default:\n return walletName.replace(/\\s+/g, '').toLowerCase();\n }\n};\n"]}
|
package/dist/index.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {OrbitAdapter,selectAdapterByKey,connectedWalletChainHelpers,delay}from'@tuwaio/orbit-core';import {produce}from'immer';import {createStore}from'zustand/vanilla';function p(t){return t.split(":")[0]??OrbitAdapter.EVM}var w={impersonatedAddress:typeof window<"u"?window.localStorage.getItem("satellite-connect:impersonatedAddress")??"":"",setImpersonated:t=>typeof window<"u"?window.localStorage.setItem("satellite-connect:impersonatedAddress",t):void 0,getImpersonated:()=>typeof window<"u"?window.localStorage.getItem("satellite-connect:impersonatedAddress"):void 0,removeImpersonated:()=>typeof window<"u"?window.localStorage.removeItem("satellite-connect:impersonatedAddress"):void 0};function m(t){if(typeof window>"u")return;let s=window.localStorage.getItem(t);if(s)try{return JSON.parse(s)}catch(o){console.error(`Error parsing ${t} from localStorage:`,o);return}}var d={STORAGE_KEY:"satellite-connect:lastConnectedWallet",lastConnectedWallet:m("satellite-connect:lastConnectedWallet"),setLastConnectedWallet:({walletType:t,chainId:s})=>typeof window<"u"?window.localStorage.setItem(d.STORAGE_KEY,JSON.stringify({walletType:t,chainId:s})):void 0,getLastConnectedWallet:()=>m(d.STORAGE_KEY),removeLastConnectedWallet:()=>typeof window<"u"?window.localStorage.removeItem(d.STORAGE_KEY):void 0};var f={STORAGE_KEY:"satellite-connect:recentConnectedWallet",recentConnectedWallet:m("satellite-connect:recentConnectedWallet"),setRecentConnectedWallet:({wallets:t})=>typeof window<"u"?window.localStorage.setItem(f.STORAGE_KEY,JSON.stringify({wallets:t})):void 0,getRecentConnectedWallet:()=>m(f.STORAGE_KEY),removeRecentConnectedWallet:()=>typeof window<"u"?window.localStorage.removeItem(f.STORAGE_KEY):void 0};function B({adapter:t,callbackAfterConnected:s}){return createStore()((o,c)=>({getAdapter:()=>t,getConnectors:()=>{let e;return Array.isArray(t)?e=t.map(n=>n.getConnectors()):e=[t.getConnectors()],e.reduce((n,l)=>{let a=l.adapter,r=l.connectors;return {...n,[a]:r}},{})},initializeAutoConnect:async e=>{if(e){let n=d.getLastConnectedWallet();n&&(await delay(null,
|
|
1
|
+
import {OrbitAdapter,selectAdapterByKey,connectedWalletChainHelpers,delay}from'@tuwaio/orbit-core';import {produce}from'immer';import {createStore}from'zustand/vanilla';function p(t){return t.split(":")[0]??OrbitAdapter.EVM}var w={impersonatedAddress:typeof window<"u"?window.localStorage.getItem("satellite-connect:impersonatedAddress")??"":"",setImpersonated:t=>typeof window<"u"?window.localStorage.setItem("satellite-connect:impersonatedAddress",t):void 0,getImpersonated:()=>typeof window<"u"?window.localStorage.getItem("satellite-connect:impersonatedAddress"):void 0,removeImpersonated:()=>typeof window<"u"?window.localStorage.removeItem("satellite-connect:impersonatedAddress"):void 0};function m(t){if(typeof window>"u")return;let s=window.localStorage.getItem(t);if(s)try{return JSON.parse(s)}catch(o){console.error(`Error parsing ${t} from localStorage:`,o);return}}var d={STORAGE_KEY:"satellite-connect:lastConnectedWallet",lastConnectedWallet:m("satellite-connect:lastConnectedWallet"),setLastConnectedWallet:({walletType:t,chainId:s})=>typeof window<"u"?window.localStorage.setItem(d.STORAGE_KEY,JSON.stringify({walletType:t,chainId:s})):void 0,getLastConnectedWallet:()=>m(d.STORAGE_KEY),removeLastConnectedWallet:()=>typeof window<"u"?window.localStorage.removeItem(d.STORAGE_KEY):void 0};var f={STORAGE_KEY:"satellite-connect:recentConnectedWallet",recentConnectedWallet:m("satellite-connect:recentConnectedWallet"),setRecentConnectedWallet:({wallets:t})=>typeof window<"u"?window.localStorage.setItem(f.STORAGE_KEY,JSON.stringify({wallets:t})):void 0,getRecentConnectedWallet:()=>m(f.STORAGE_KEY),removeRecentConnectedWallet:()=>typeof window<"u"?window.localStorage.removeItem(f.STORAGE_KEY):void 0};function B({adapter:t,callbackAfterConnected:s}){return createStore()((o,c)=>({getAdapter:()=>t,getConnectors:()=>{let e;return Array.isArray(t)?e=t.map(n=>n.getConnectors()):e=[t.getConnectors()],e.reduce((n,l)=>{let a=l.adapter,r=l.connectors;return {...n,[a]:r}},{})},initializeAutoConnect:async e=>{if(e){let n=d.getLastConnectedWallet();n&&(await delay(null,200),await c().connect({walletType:n.walletType,chainId:n.chainId}));}},walletConnecting:false,walletConnectionError:void 0,switchNetworkError:void 0,activeWallet:void 0,connect:async({walletType:e,chainId:n})=>{o({walletConnecting:true,walletConnectionError:void 0});let l=p(e),a=selectAdapterByKey({adapter:t,adapterKey:l});if(!a){o({walletConnecting:false,walletConnectionError:`No adapter found for wallet type: ${e}`});return}try{let r=await a.connect({walletType:e,chainId:n});if(o({activeWallet:r}),connectedWalletChainHelpers.setConnectedWalletChain(n),a.checkIsContractWallet){let i=await a.checkIsContractWallet({address:r.address,chainId:n});c().updateActiveWallet({isContractAddress:i});}if(s){let i=c().activeWallet;i&&await s(i);}o({walletConnecting:!1}),d.setLastConnectedWallet({walletType:e,chainId:n});let u=f.getRecentConnectedWallet();if(u){let i={wallets:{...u.wallets,[p(e)]:e}};f.setRecentConnectedWallet(i);}else {let i={wallets:{[p(e)]:e}};f.setRecentConnectedWallet(i);}}catch(r){await c().disconnect(),o({walletConnecting:false,walletConnectionError:"Wallet connection failed: "+(r instanceof Error?r.message:String(r))});}},disconnect:async()=>{let e=c().activeWallet;e&&(await selectAdapterByKey({adapter:t,adapterKey:p(e.walletType)})?.disconnect(),o({activeWallet:void 0,walletConnectionError:void 0,switchNetworkError:void 0}),d.removeLastConnectedWallet(),connectedWalletChainHelpers.removeConnectedWalletChain(),w.removeImpersonated());},disconnectAll:async()=>{if(await delay(null,150),Array.isArray(t))await Promise.allSettled(t.map(async e=>{try{await e.disconnect();}catch{}}));else try{await t.disconnect();}catch{}o({activeWallet:void 0,walletConnectionError:void 0,switchNetworkError:void 0}),connectedWalletChainHelpers.removeConnectedWalletChain(),w.removeImpersonated();},resetWalletConnectionError:()=>{o({walletConnectionError:void 0});},updateActiveWallet:e=>{let n=c().activeWallet;n?(e.chainId&&(connectedWalletChainHelpers.setConnectedWalletChain(e.chainId),d.setLastConnectedWallet({walletType:n.walletType,chainId:e.chainId})),o(l=>produce(l,a=>{a.activeWallet&&(a.activeWallet={...a.activeWallet,...e});}))):e.walletType!==void 0&&e.chainId!==void 0&&e.address!==void 0?(connectedWalletChainHelpers.setConnectedWalletChain(e.chainId),o({activeWallet:e})):console.warn("Attempted to set activeWallet with incomplete data while activeWallet was undefined.");},switchNetwork:async e=>{o({switchNetworkError:void 0});let n=c().activeWallet;if(n){let l=p(n.walletType),a=selectAdapterByKey({adapter:t,adapterKey:l});if(!a){o({switchNetworkError:`No adapter found for active wallet type: ${n.walletType}`});return}try{await a.checkAndSwitchNetwork(e,n.chainId,c().updateActiveWallet);}catch(r){o({switchNetworkError:"Switch network failed: "+(r instanceof Error?r.message:String(r))});}}},resetSwitchNetworkError:()=>o({switchNetworkError:void 0})}))}var $=t=>{switch(t){case "Safe":return "safewallet";default:return t.replace(/\s+/g,"").toLowerCase()}};export{B as createSatelliteConnectStore,$ as formatWalletName,p as getAdapterFromWalletType,m as getParsedStorageItem,w as impersonatedHelpers,d as lastConnectedWalletHelpers,f as recentConnectedWalletHelpers};//# sourceMappingURL=index.mjs.map
|
|
2
2
|
//# sourceMappingURL=index.mjs.map
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/utils/getAdapterFromWalletType.ts","../src/utils/impersonatedHelpers.ts","../src/utils/getParsedStorageItem.ts","../src/utils/lastConnectedWalletHelpers.ts","../src/utils/recentConnectedWalletHelpers.ts","../src/store/satelliteConnectStore.ts","../src/utils/formatWalletName.ts"],"names":["getAdapterFromWalletType","walletType","OrbitAdapter","impersonatedHelpers","address","getParsedStorageItem","key","item","error","lastConnectedWalletHelpers","chainId","recentConnectedWalletHelpers","wallets","createSatelliteConnectStore","adapter","callbackAfterConnected","createStore","set","get","results","a","accumulator","currentResult","value","autoConnect","lastConnectedWallet","delay","adapterKey","foundAdapter","selectAdapterByKey","wallet","connectedWalletChainHelpers","isContractAddress","updatedWallet","recentlyConnectedWallet","updatedRecentlyConnectedWallet","e","activeWallet","state","produce","draft","formatWalletName","walletName"],"mappings":"yKA0BO,SAASA,CAAAA,CAAyBC,CAAAA,CAAsC,CAC7E,OAAQA,CAAAA,CAAW,MAAM,GAAG,CAAA,CAAE,CAAC,CAAA,EAAKC,YAAAA,CAAa,GACnD,CCnBO,IAAMC,CAAAA,CAAsB,CAKjC,mBAAA,CACE,OAAO,OAAW,GAAA,CAAe,MAAA,CAAO,aAAa,OAAA,CAAQ,uCAAuC,CAAA,EAAK,EAAA,CAAM,EAAA,CAcjH,eAAA,CAAkBC,GAChB,OAAO,MAAA,CAAW,IACd,MAAA,CAAO,YAAA,CAAa,QAAQ,uCAAA,CAAyCA,CAAO,CAAA,CAC5E,MAAA,CAeN,eAAA,CAAiB,IACf,OAAO,MAAA,CAAW,GAAA,CAAc,OAAO,YAAA,CAAa,OAAA,CAAQ,uCAAuC,CAAA,CAAI,MAAA,CAEzG,kBAAA,CAAoB,IAClB,OAAO,MAAA,CAAW,IAAc,MAAA,CAAO,YAAA,CAAa,WAAW,uCAAuC,CAAA,CAAI,MAC9G,EC9CO,SAASC,CAAAA,CAAiCC,CAAAA,CAAqC,CACpF,GAAI,OAAO,MAAA,CAAW,GAAA,CACpB,OAGF,IAAMC,CAAAA,CAAO,OAAO,YAAA,CAAa,OAAA,CAAQD,CAAG,CAAA,CAG5C,GAAKC,CAAA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A,CAAa3B,EAAyBqC,CAAAA,CAAa,UAAU,EAC7DT,CAAAA,CAAeC,kBAAAA,CAAmB,CAAE,OAAA,CAAAf,CAAAA,CAAS,UAAA,CAAAa,CAAW,CAAC,CAAA,CAE/D,GAAI,CAACC,CAAAA,CAAc,CACjBX,CAAAA,CAAI,CAAE,mBAAoB,CAAA,yCAAA,EAA4CoB,CAAAA,CAAa,UAAU,CAAA,CAAG,CAAC,CAAA,CACjG,MACF,CAEA,GAAI,CAEF,MAAMT,CAAAA,CAAa,sBAAsBlB,CAAAA,CAAS2B,CAAAA,CAAa,OAAA,CAASnB,CAAAA,EAAI,CAAE,kBAAkB,EAClG,CAAA,MAASkB,CAAAA,CAAG,CACVnB,CAAAA,CAAI,CAAE,mBAAoB,yBAAA,EAA6BmB,CAAAA,YAAa,KAAA,CAAQA,CAAAA,CAAE,OAAA,CAAU,MAAA,CAAOA,CAAC,CAAA,CAAG,CAAC,EACtG,CACF,CACF,EAUA,uBAAA,CAAyB,IAAMnB,CAAAA,CAAI,CAAE,kBAAA,CAAoB,MAAU,CAAC,CACtE,CAAA,CAAE,CACJ,CChSO,IAAMwB,EAAoBC,CAAAA,EAAuB,CACtD,OAAQA,CAAAA,EACN,KAAK,OACH,OAAO,YAAA,CACT,QACE,OAAOA,CAAAA,CAAW,OAAA,CAAQ,OAAQ,EAAE,CAAA,CAAE,WAAA,EAC1C,CACF","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","/**\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 removeImpersonated: () =>\n typeof window !== 'undefined' ? window.localStorage.removeItem('satellite-connect:impersonatedAddress') : undefined,\n};\n","/**\n * Internal function for safely retrieving and parsing data from localStorage.\n *\n * @param key - The key for localStorage\n * @returns The parsed LastConnectedWallet object or undefined if data is not found/invalid\n */\nexport function getParsedStorageItem<ReturnType>(key: string): ReturnType | undefined {\n if (typeof window === 'undefined') {\n return undefined;\n }\n\n const item = window.localStorage.getItem(key);\n\n // If the item is null (not set) or an empty string, return undefined\n if (!item) {\n return undefined;\n }\n\n try {\n // Safe JSON parsing\n return JSON.parse(item) as ReturnType;\n } catch (error) {\n // In case of a parsing error (e.g., invalid JSON), log the error and return undefined\n console.error(`Error parsing ${key} from localStorage:`, error);\n return undefined;\n }\n}\n","import { WalletType } from '../types';\nimport { getParsedStorageItem } from './getParsedStorageItem';\n\ntype LastConnectedWallet = { walletType: WalletType; chainId: number | string };\n\n/**\n * Helper utilities for managing the last connected wallet state\n *\n * @remarks\n * All data is stored in localStorage with the 'satellite-connect:lastConnectedWallet' key.\n * Functions are safe to use in both browser and SSR environments.\n */\nexport const lastConnectedWalletHelpers = {\n // Key used for localStorage\n STORAGE_KEY: 'satellite-connect:lastConnectedWallet',\n\n /**\n * The value of the last connected wallet, initialized when the module loads.\n * Returns undefined if not set, invalid, or in an SSR context.\n */\n lastConnectedWallet: getParsedStorageItem<LastConnectedWallet>('satellite-connect:lastConnectedWallet'),\n\n /**\n * Stores the last connected wallet data in localStorage.\n *\n * @param data - Object containing the wallet type and chain ID.\n * @returns undefined in SSR context, void in browser\n */\n setLastConnectedWallet: ({ walletType, chainId }: LastConnectedWallet) =>\n typeof window !== 'undefined'\n ? window.localStorage.setItem(lastConnectedWalletHelpers.STORAGE_KEY, JSON.stringify({ walletType, chainId }))\n : undefined,\n\n /**\n * Retrieves the current last connected wallet data from localStorage.\n *\n * @returns The LastConnectedWallet object or undefined if not set or in SSR context\n */\n getLastConnectedWallet: () => getParsedStorageItem<LastConnectedWallet>(lastConnectedWalletHelpers.STORAGE_KEY),\n\n /**\n * Removes the last connected wallet data from localStorage.\n *\n * @returns undefined in SSR context, void in browser\n */\n removeLastConnectedWallet: () =>\n typeof window !== 'undefined' ? window.localStorage.removeItem(lastConnectedWalletHelpers.STORAGE_KEY) : undefined,\n};\n","import { OrbitAdapter } from '@tuwaio/orbit-core';\n\nimport { WalletType } from '../types';\nimport { getParsedStorageItem } from './getParsedStorageItem';\n\nexport type RecentConnectedWallet = { wallets: Record<OrbitAdapter, WalletType> };\n\n/**\n * Helper utilities for managing the last connected wallet state\n *\n * @remarks\n * All data is stored in localStorage with the 'satellite-connect:lastConnectedWallet' key.\n * Functions are safe to use in both browser and SSR environments.\n */\nexport const recentConnectedWalletHelpers = {\n // Key used for localStorage\n STORAGE_KEY: 'satellite-connect:recentConnectedWallet',\n\n /**\n * The value of the last connected wallet, initialized when the module loads.\n * Returns undefined if not set, invalid, or in an SSR context.\n */\n recentConnectedWallet: getParsedStorageItem<RecentConnectedWallet>('satellite-connect:recentConnectedWallet'),\n\n /**\n * Stores the last connected wallet data in localStorage.\n *\n * @param data - Object containing the wallet type and chain ID.\n * @returns undefined in SSR context, void in browser\n */\n setRecentConnectedWallet: ({ wallets }: RecentConnectedWallet) =>\n typeof window !== 'undefined'\n ? window.localStorage.setItem(recentConnectedWalletHelpers.STORAGE_KEY, JSON.stringify({ wallets }))\n : undefined,\n\n /**\n * Retrieves the current last connected wallet data from localStorage.\n *\n * @returns The LastConnectedWallet object or undefined if not set or in SSR context\n */\n getRecentConnectedWallet: () => getParsedStorageItem<RecentConnectedWallet>(recentConnectedWalletHelpers.STORAGE_KEY),\n\n /**\n * Removes the last connected wallet data from localStorage.\n *\n * @returns undefined in SSR context, void in browser\n */\n removeRecentConnectedWallet: () =>\n typeof window !== 'undefined'\n ? window.localStorage.removeItem(recentConnectedWalletHelpers.STORAGE_KEY)\n : undefined,\n};\n","import { connectedWalletChainHelpers, OrbitAdapter, selectAdapterByKey } from '@tuwaio/orbit-core';\nimport { delay } from '@tuwaio/orbit-core';\nimport { produce } from 'immer';\nimport { createStore } from 'zustand/vanilla';\n\nimport { BaseWallet, ISatelliteConnectStore, SatelliteConnectStoreInitialParameters, Wallet } from '../types';\nimport { getAdapterFromWalletType } from '../utils/getAdapterFromWalletType';\nimport { impersonatedHelpers } from '../utils/impersonatedHelpers';\nimport { lastConnectedWalletHelpers } from '../utils/lastConnectedWalletHelpers';\nimport { RecentConnectedWallet, recentConnectedWalletHelpers } from '../utils/recentConnectedWalletHelpers';\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<C, W extends BaseWallet = BaseWallet>({\n adapter,\n callbackAfterConnected,\n}: SatelliteConnectStoreInitialParameters<C, W>) {\n return createStore<ISatelliteConnectStore<C, W>>()((set, get) => ({\n /**\n * Returns configured adapter(s)\n */\n getAdapter: () => adapter,\n\n /**\n * Get wallet connectors for all configured adapters\n */\n getConnectors: () => {\n let results: { adapter: OrbitAdapter; connectors: C[] }[];\n\n if (Array.isArray(adapter)) {\n results = adapter.map((a) => a.getConnectors());\n } else {\n // Ensure the single adapter result is wrapped in an array for consistent processing\n results = [adapter.getConnectors()];\n }\n\n return results.reduce(\n (accumulator, currentResult) => {\n const key = currentResult.adapter;\n const value = currentResult.connectors;\n return {\n ...accumulator,\n [key]: value,\n };\n },\n {} as Partial<Record<OrbitAdapter, C[]>>,\n );\n },\n\n initializeAutoConnect: async (autoConnect) => {\n if (autoConnect) {\n const lastConnectedWallet = lastConnectedWalletHelpers.getLastConnectedWallet();\n if (lastConnectedWallet) {\n await delay(null, 5);\n await get().connect({ walletType: lastConnectedWallet.walletType, chainId: lastConnectedWallet.chainId });\n }\n }\n },\n\n walletConnecting: false,\n walletConnectionError: undefined,\n switchNetworkError: undefined,\n activeWallet: undefined,\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 adapterKey = getAdapterFromWalletType(walletType);\n const foundAdapter = selectAdapterByKey({ adapter, adapterKey });\n\n if (!foundAdapter) {\n set({\n walletConnecting: false,\n walletConnectionError: `No adapter found for wallet type: ${walletType}`,\n });\n return;\n }\n\n try {\n const wallet = await foundAdapter.connect({\n walletType,\n chainId,\n });\n\n // 1. Set initial wallet state\n set({ activeWallet: wallet });\n\n // 2. Set connected chain storage\n connectedWalletChainHelpers.setConnectedWalletChain(chainId);\n\n // 3. Check for contract address if the adapter supports it\n if (foundAdapter.checkIsContractWallet) {\n const isContractAddress = await foundAdapter.checkIsContractWallet({\n address: wallet.address,\n chainId,\n });\n\n // Update only the isContractAddress property\n get().updateActiveWallet({ isContractAddress });\n }\n\n // 4. Run callback if provided\n if (callbackAfterConnected) {\n // Use the latest wallet state after potential updates (like isContractAddress)\n const updatedWallet = get().activeWallet;\n if (updatedWallet) {\n await callbackAfterConnected(updatedWallet);\n }\n }\n\n // 5. Final state updates\n set({ walletConnecting: false });\n lastConnectedWalletHelpers.setLastConnectedWallet({ walletType, chainId });\n const recentlyConnectedWallet = recentConnectedWalletHelpers.getRecentConnectedWallet();\n if (recentlyConnectedWallet) {\n const updatedRecentlyConnectedWallet = {\n wallets: {\n ...recentlyConnectedWallet.wallets,\n [getAdapterFromWalletType(walletType)]: walletType,\n },\n };\n recentConnectedWalletHelpers.setRecentConnectedWallet(updatedRecentlyConnectedWallet);\n } else {\n const updatedRecentlyConnectedWallet = {\n wallets: {\n [getAdapterFromWalletType(walletType)]: walletType,\n },\n } as RecentConnectedWallet;\n recentConnectedWalletHelpers.setRecentConnectedWallet(updatedRecentlyConnectedWallet);\n }\n } catch (e) {\n await get().disconnect();\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\n // Call disconnect only if adapter is found\n await foundAdapter?.disconnect();\n\n // Clear all states and storages\n set({ activeWallet: undefined, walletConnectionError: undefined, switchNetworkError: undefined });\n lastConnectedWalletHelpers.removeLastConnectedWallet();\n connectedWalletChainHelpers.removeConnectedWalletChain();\n impersonatedHelpers.removeImpersonated();\n }\n },\n\n disconnectAll: async () => {\n await delay(null, 1);\n if (Array.isArray(adapter)) {\n await Promise.allSettled(\n adapter.map(async (a) => {\n try {\n await a.disconnect();\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n } catch (e) {\n /* empty */\n }\n }),\n );\n } else {\n try {\n await adapter.disconnect();\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n } catch (e) {\n /* empty */\n }\n }\n set({ activeWallet: undefined, walletConnectionError: undefined, switchNetworkError: undefined });\n connectedWalletChainHelpers.removeConnectedWalletChain();\n impersonatedHelpers.removeImpersonated();\n },\n\n /**\n * Contains error message if connection failed\n */\n // walletConnectionError is declared above with an initial value\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<W>>) => {\n const activeWallet = get().activeWallet;\n if (activeWallet) {\n // If chainId is updated, update storage\n if (wallet.chainId) {\n connectedWalletChainHelpers.setConnectedWalletChain(wallet.chainId);\n\n // Update lastConnectedWallet storage if chainId changes\n lastConnectedWalletHelpers.setLastConnectedWallet({\n walletType: activeWallet.walletType,\n chainId: wallet.chainId,\n });\n }\n\n // Use produce for immutable state update\n set((state) =>\n produce(state, (draft) => {\n if (draft.activeWallet) {\n // Ensure we merge partial properties into the existing activeWallet object\n draft.activeWallet = {\n ...draft.activeWallet,\n ...wallet,\n } as W; // Cast ensures type compatibility after merging\n }\n }),\n );\n } else {\n const isWalletCanChange =\n wallet.walletType !== undefined && wallet.chainId !== undefined && wallet.address !== undefined;\n\n if (isWalletCanChange) {\n connectedWalletChainHelpers.setConnectedWalletChain(wallet.chainId!);\n set({ activeWallet: wallet as W });\n } else {\n console.warn('Attempted to set activeWallet with incomplete data while activeWallet was undefined.');\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 adapterKey = getAdapterFromWalletType(activeWallet.walletType);\n const foundAdapter = selectAdapterByKey({ adapter, adapterKey });\n\n if (!foundAdapter) {\n set({ switchNetworkError: `No adapter found for active wallet type: ${activeWallet.walletType}` });\n return;\n }\n\n try {\n // Pass the local updateActiveWallet method from 'get()' to the adapter\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 * Contains error message if network switch failed\n */\n // switchNetworkError is declared above with an initial value\n\n /**\n * Resets any network switching errors\n */\n resetSwitchNetworkError: () => set({ switchNetworkError: undefined }),\n }));\n}\n","export const formatWalletName = (walletName: string) => {\n switch (walletName) {\n case 'Safe':\n return 'safewallet';\n default:\n return walletName.replace(/\\s+/g, '').toLowerCase();\n }\n};\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/utils/getAdapterFromWalletType.ts","../src/utils/impersonatedHelpers.ts","../src/utils/getParsedStorageItem.ts","../src/utils/lastConnectedWalletHelpers.ts","../src/utils/recentConnectedWalletHelpers.ts","../src/store/satelliteConnectStore.ts","../src/utils/formatWalletName.ts"],"names":["getAdapterFromWalletType","walletType","OrbitAdapter","impersonatedHelpers","address","getParsedStorageItem","key","item","error","lastConnectedWalletHelpers","chainId","recentConnectedWalletHelpers","wallets","createSatelliteConnectStore","adapter","callbackAfterConnected","createStore","set","get","results","a","accumulator","currentResult","value","autoConnect","lastConnectedWallet","delay","adapterKey","foundAdapter","selectAdapterByKey","wallet","connectedWalletChainHelpers","isContractAddress","updatedWallet","recentlyCon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AA,CAASnB,CAAAA,EAAI,CAAE,kBAAkB,EAClG,CAAA,MAASkB,CAAAA,CAAG,CACVnB,CAAAA,CAAI,CAAE,mBAAoB,yBAAA,EAA6BmB,CAAAA,YAAa,KAAA,CAAQA,CAAAA,CAAE,OAAA,CAAU,MAAA,CAAOA,CAAC,CAAA,CAAG,CAAC,EACtG,CACF,CACF,EAUA,uBAAA,CAAyB,IAAMnB,CAAAA,CAAI,CAAE,kBAAA,CAAoB,MAAU,CAAC,CACtE,CAAA,CAAE,CACJ,CChSO,IAAMwB,EAAoBC,CAAAA,EAAuB,CACtD,OAAQA,CAAAA,EACN,KAAK,OACH,OAAO,YAAA,CACT,QACE,OAAOA,CAAAA,CAAW,OAAA,CAAQ,OAAQ,EAAE,CAAA,CAAE,WAAA,EAC1C,CACF","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","/**\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 removeImpersonated: () =>\n typeof window !== 'undefined' ? window.localStorage.removeItem('satellite-connect:impersonatedAddress') : undefined,\n};\n","/**\n * Internal function for safely retrieving and parsing data from localStorage.\n *\n * @param key - The key for localStorage\n * @returns The parsed LastConnectedWallet object or undefined if data is not found/invalid\n */\nexport function getParsedStorageItem<ReturnType>(key: string): ReturnType | undefined {\n if (typeof window === 'undefined') {\n return undefined;\n }\n\n const item = window.localStorage.getItem(key);\n\n // If the item is null (not set) or an empty string, return undefined\n if (!item) {\n return undefined;\n }\n\n try {\n // Safe JSON parsing\n return JSON.parse(item) as ReturnType;\n } catch (error) {\n // In case of a parsing error (e.g., invalid JSON), log the error and return undefined\n console.error(`Error parsing ${key} from localStorage:`, error);\n return undefined;\n }\n}\n","import { WalletType } from '../types';\nimport { getParsedStorageItem } from './getParsedStorageItem';\n\ntype LastConnectedWallet = { walletType: WalletType; chainId: number | string };\n\n/**\n * Helper utilities for managing the last connected wallet state\n *\n * @remarks\n * All data is stored in localStorage with the 'satellite-connect:lastConnectedWallet' key.\n * Functions are safe to use in both browser and SSR environments.\n */\nexport const lastConnectedWalletHelpers = {\n // Key used for localStorage\n STORAGE_KEY: 'satellite-connect:lastConnectedWallet',\n\n /**\n * The value of the last connected wallet, initialized when the module loads.\n * Returns undefined if not set, invalid, or in an SSR context.\n */\n lastConnectedWallet: getParsedStorageItem<LastConnectedWallet>('satellite-connect:lastConnectedWallet'),\n\n /**\n * Stores the last connected wallet data in localStorage.\n *\n * @param data - Object containing the wallet type and chain ID.\n * @returns undefined in SSR context, void in browser\n */\n setLastConnectedWallet: ({ walletType, chainId }: LastConnectedWallet) =>\n typeof window !== 'undefined'\n ? window.localStorage.setItem(lastConnectedWalletHelpers.STORAGE_KEY, JSON.stringify({ walletType, chainId }))\n : undefined,\n\n /**\n * Retrieves the current last connected wallet data from localStorage.\n *\n * @returns The LastConnectedWallet object or undefined if not set or in SSR context\n */\n getLastConnectedWallet: () => getParsedStorageItem<LastConnectedWallet>(lastConnectedWalletHelpers.STORAGE_KEY),\n\n /**\n * Removes the last connected wallet data from localStorage.\n *\n * @returns undefined in SSR context, void in browser\n */\n removeLastConnectedWallet: () =>\n typeof window !== 'undefined' ? window.localStorage.removeItem(lastConnectedWalletHelpers.STORAGE_KEY) : undefined,\n};\n","import { OrbitAdapter } from '@tuwaio/orbit-core';\n\nimport { WalletType } from '../types';\nimport { getParsedStorageItem } from './getParsedStorageItem';\n\nexport type RecentConnectedWallet = { wallets: Record<OrbitAdapter, WalletType> };\n\n/**\n * Helper utilities for managing the last connected wallet state\n *\n * @remarks\n * All data is stored in localStorage with the 'satellite-connect:lastConnectedWallet' key.\n * Functions are safe to use in both browser and SSR environments.\n */\nexport const recentConnectedWalletHelpers = {\n // Key used for localStorage\n STORAGE_KEY: 'satellite-connect:recentConnectedWallet',\n\n /**\n * The value of the last connected wallet, initialized when the module loads.\n * Returns undefined if not set, invalid, or in an SSR context.\n */\n recentConnectedWallet: getParsedStorageItem<RecentConnectedWallet>('satellite-connect:recentConnectedWallet'),\n\n /**\n * Stores the last connected wallet data in localStorage.\n *\n * @param data - Object containing the wallet type and chain ID.\n * @returns undefined in SSR context, void in browser\n */\n setRecentConnectedWallet: ({ wallets }: RecentConnectedWallet) =>\n typeof window !== 'undefined'\n ? window.localStorage.setItem(recentConnectedWalletHelpers.STORAGE_KEY, JSON.stringify({ wallets }))\n : undefined,\n\n /**\n * Retrieves the current last connected wallet data from localStorage.\n *\n * @returns The LastConnectedWallet object or undefined if not set or in SSR context\n */\n getRecentConnectedWallet: () => getParsedStorageItem<RecentConnectedWallet>(recentConnectedWalletHelpers.STORAGE_KEY),\n\n /**\n * Removes the last connected wallet data from localStorage.\n *\n * @returns undefined in SSR context, void in browser\n */\n removeRecentConnectedWallet: () =>\n typeof window !== 'undefined'\n ? window.localStorage.removeItem(recentConnectedWalletHelpers.STORAGE_KEY)\n : undefined,\n};\n","import { connectedWalletChainHelpers, OrbitAdapter, selectAdapterByKey } from '@tuwaio/orbit-core';\nimport { delay } from '@tuwaio/orbit-core';\nimport { produce } from 'immer';\nimport { createStore } from 'zustand/vanilla';\n\nimport { BaseWallet, ISatelliteConnectStore, SatelliteConnectStoreInitialParameters, Wallet } from '../types';\nimport { getAdapterFromWalletType } from '../utils/getAdapterFromWalletType';\nimport { impersonatedHelpers } from '../utils/impersonatedHelpers';\nimport { lastConnectedWalletHelpers } from '../utils/lastConnectedWalletHelpers';\nimport { RecentConnectedWallet, recentConnectedWalletHelpers } from '../utils/recentConnectedWalletHelpers';\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<C, W extends BaseWallet = BaseWallet>({\n adapter,\n callbackAfterConnected,\n}: SatelliteConnectStoreInitialParameters<C, W>) {\n return createStore<ISatelliteConnectStore<C, W>>()((set, get) => ({\n /**\n * Returns configured adapter(s)\n */\n getAdapter: () => adapter,\n\n /**\n * Get wallet connectors for all configured adapters\n */\n getConnectors: () => {\n let results: { adapter: OrbitAdapter; connectors: C[] }[];\n\n if (Array.isArray(adapter)) {\n results = adapter.map((a) => a.getConnectors());\n } else {\n // Ensure the single adapter result is wrapped in an array for consistent processing\n results = [adapter.getConnectors()];\n }\n\n return results.reduce(\n (accumulator, currentResult) => {\n const key = currentResult.adapter;\n const value = currentResult.connectors;\n return {\n ...accumulator,\n [key]: value,\n };\n },\n {} as Partial<Record<OrbitAdapter, C[]>>,\n );\n },\n\n initializeAutoConnect: async (autoConnect) => {\n if (autoConnect) {\n const lastConnectedWallet = lastConnectedWalletHelpers.getLastConnectedWallet();\n if (lastConnectedWallet) {\n await delay(null, 200);\n await get().connect({ walletType: lastConnectedWallet.walletType, chainId: lastConnectedWallet.chainId });\n }\n }\n },\n\n walletConnecting: false,\n walletConnectionError: undefined,\n switchNetworkError: undefined,\n activeWallet: undefined,\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 adapterKey = getAdapterFromWalletType(walletType);\n const foundAdapter = selectAdapterByKey({ adapter, adapterKey });\n\n if (!foundAdapter) {\n set({\n walletConnecting: false,\n walletConnectionError: `No adapter found for wallet type: ${walletType}`,\n });\n return;\n }\n\n try {\n const wallet = await foundAdapter.connect({\n walletType,\n chainId,\n });\n\n // 1. Set initial wallet state\n set({ activeWallet: wallet });\n\n // 2. Set connected chain storage\n connectedWalletChainHelpers.setConnectedWalletChain(chainId);\n\n // 3. Check for contract address if the adapter supports it\n if (foundAdapter.checkIsContractWallet) {\n const isContractAddress = await foundAdapter.checkIsContractWallet({\n address: wallet.address,\n chainId,\n });\n\n // Update only the isContractAddress property\n get().updateActiveWallet({ isContractAddress });\n }\n\n // 4. Run callback if provided\n if (callbackAfterConnected) {\n // Use the latest wallet state after potential updates (like isContractAddress)\n const updatedWallet = get().activeWallet;\n if (updatedWallet) {\n await callbackAfterConnected(updatedWallet);\n }\n }\n\n // 5. Final state updates\n set({ walletConnecting: false });\n lastConnectedWalletHelpers.setLastConnectedWallet({ walletType, chainId });\n const recentlyConnectedWallet = recentConnectedWalletHelpers.getRecentConnectedWallet();\n if (recentlyConnectedWallet) {\n const updatedRecentlyConnectedWallet = {\n wallets: {\n ...recentlyConnectedWallet.wallets,\n [getAdapterFromWalletType(walletType)]: walletType,\n },\n };\n recentConnectedWalletHelpers.setRecentConnectedWallet(updatedRecentlyConnectedWallet);\n } else {\n const updatedRecentlyConnectedWallet = {\n wallets: {\n [getAdapterFromWalletType(walletType)]: walletType,\n },\n } as RecentConnectedWallet;\n recentConnectedWalletHelpers.setRecentConnectedWallet(updatedRecentlyConnectedWallet);\n }\n } catch (e) {\n await get().disconnect();\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\n // Call disconnect only if adapter is found\n await foundAdapter?.disconnect();\n\n // Clear all states and storages\n set({ activeWallet: undefined, walletConnectionError: undefined, switchNetworkError: undefined });\n lastConnectedWalletHelpers.removeLastConnectedWallet();\n connectedWalletChainHelpers.removeConnectedWalletChain();\n impersonatedHelpers.removeImpersonated();\n }\n },\n\n disconnectAll: async () => {\n await delay(null, 150);\n if (Array.isArray(adapter)) {\n await Promise.allSettled(\n adapter.map(async (a) => {\n try {\n await a.disconnect();\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n } catch (e) {\n /* empty */\n }\n }),\n );\n } else {\n try {\n await adapter.disconnect();\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n } catch (e) {\n /* empty */\n }\n }\n set({ activeWallet: undefined, walletConnectionError: undefined, switchNetworkError: undefined });\n connectedWalletChainHelpers.removeConnectedWalletChain();\n impersonatedHelpers.removeImpersonated();\n },\n\n /**\n * Contains error message if connection failed\n */\n // walletConnectionError is declared above with an initial value\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<W>>) => {\n const activeWallet = get().activeWallet;\n if (activeWallet) {\n // If chainId is updated, update storage\n if (wallet.chainId) {\n connectedWalletChainHelpers.setConnectedWalletChain(wallet.chainId);\n\n // Update lastConnectedWallet storage if chainId changes\n lastConnectedWalletHelpers.setLastConnectedWallet({\n walletType: activeWallet.walletType,\n chainId: wallet.chainId,\n });\n }\n\n // Use produce for immutable state update\n set((state) =>\n produce(state, (draft) => {\n if (draft.activeWallet) {\n // Ensure we merge partial properties into the existing activeWallet object\n draft.activeWallet = {\n ...draft.activeWallet,\n ...wallet,\n } as W; // Cast ensures type compatibility after merging\n }\n }),\n );\n } else {\n const isWalletCanChange =\n wallet.walletType !== undefined && wallet.chainId !== undefined && wallet.address !== undefined;\n\n if (isWalletCanChange) {\n connectedWalletChainHelpers.setConnectedWalletChain(wallet.chainId!);\n set({ activeWallet: wallet as W });\n } else {\n console.warn('Attempted to set activeWallet with incomplete data while activeWallet was undefined.');\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 adapterKey = getAdapterFromWalletType(activeWallet.walletType);\n const foundAdapter = selectAdapterByKey({ adapter, adapterKey });\n\n if (!foundAdapter) {\n set({ switchNetworkError: `No adapter found for active wallet type: ${activeWallet.walletType}` });\n return;\n }\n\n try {\n // Pass the local updateActiveWallet method from 'get()' to the adapter\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 * Contains error message if network switch failed\n */\n // switchNetworkError is declared above with an initial value\n\n /**\n * Resets any network switching errors\n */\n resetSwitchNetworkError: () => set({ switchNetworkError: undefined }),\n }));\n}\n","export const formatWalletName = (walletName: string) => {\n switch (walletName) {\n case 'Safe':\n return 'safewallet';\n default:\n return walletName.replace(/\\s+/g, '').toLowerCase();\n }\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.
|
|
3
|
+
"version": "1.0.0-fix-test-alpha.21.76f200b",
|
|
4
4
|
"private": false,
|
|
5
5
|
"author": "Oleksandr Tkach",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -49,7 +49,7 @@
|
|
|
49
49
|
"tsup": "^8.5.0",
|
|
50
50
|
"typescript": "^5.9.2",
|
|
51
51
|
"zustand": "^5.0.8",
|
|
52
|
-
"@tuwaio/orbit-core": "^1.0.0-fix-test-alpha.
|
|
52
|
+
"@tuwaio/orbit-core": "^1.0.0-fix-test-alpha.21.76f200b"
|
|
53
53
|
},
|
|
54
54
|
"scripts": {
|
|
55
55
|
"start": "tsup src/index.ts --watch",
|