@tuwaio/satellite-core 1.0.0-fix-test-alpha.2.f8f5982 → 1.0.0-fix-test-alpha.4.d5f27c9
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 +1 -0
- package/dist/index.d.ts +1 -0
- 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.d.mts
CHANGED
|
@@ -239,6 +239,7 @@ declare const impersonatedHelpers: {
|
|
|
239
239
|
* @returns The impersonated address or undefined if not set or in SSR context
|
|
240
240
|
*/
|
|
241
241
|
getImpersonated: () => string | null | undefined;
|
|
242
|
+
removeImpersonated: () => void;
|
|
242
243
|
};
|
|
243
244
|
|
|
244
245
|
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
|
@@ -239,6 +239,7 @@ declare const impersonatedHelpers: {
|
|
|
239
239
|
* @returns The impersonated address or undefined if not set or in SSR context
|
|
240
240
|
*/
|
|
241
241
|
getImpersonated: () => string | null | undefined;
|
|
242
|
+
removeImpersonated: () => void;
|
|
242
243
|
};
|
|
243
244
|
|
|
244
245
|
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
|
|
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}var p={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,removeImpersonated:()=>typeof window<"u"?window.localStorage.removeItem("satellite-connect:impersonatedAddress"):void 0};function E({adapter:r,callbackAfterConnected:f}){return vanilla.createStore()((a,i)=>({getAdapter:()=>r,availableConnectors:{},initializeAppConnectors:async({autoConnect:e})=>{if(Array.isArray(r))(await Promise.all(r.map(o=>o.getConnectors()))).forEach(o=>{a(t=>immer.produce(t,m=>{m.availableConnectors[o.adapter]=o.connectors;}));});else {let n=await r.getConnectors();a(o=>immer.produce(o,t=>{t.availableConnectors[n.adapter]=n.connectors;}));}if(e){let n=i().lastConnectedWallet;n&&await i().connect({walletType:n.walletType,chainId:n.chainId});}},connect:async({walletType:e,chainId:n})=>{a({walletConnecting:true,walletConnectionError:void 0});let o=orbitCore.selectAdapterByKey({adapter:r,adapterKey:l(e)});try{let t=await o?.connect({walletType:e,chainId:n,connectors:i().availableConnectors[l(e)]??[]});a({activeWallet:t}),orbitCore.connectedWalletChainHelpers.setConnectedWalletChain(n),o?.checkIsContractWallet&&t&&(i().updateActiveWallet({isContractAddress:await o.checkIsContractWallet({address:t.address,chainId:n})}),f&&await f(t)),a({walletConnecting:!1,lastConnectedWallet:{walletType:e,chainId:n}});}catch(t){a({walletConnecting:false,walletConnectionError:"Wallet connection failed: "+(t instanceof Error?t.message:String(t))});}},disconnect:async()=>{let e=i().activeWallet;e&&(await orbitCore.selectAdapterByKey({adapter:r,adapterKey:l(e.walletType)})?.disconnect(),a({activeWallet:void 0,lastConnectedWallet:void 0}),orbitCore.connectedWalletChainHelpers.removeConnectedWalletChain(),p.removeImpersonated());},walletConnecting:false,resetWalletConnectionError:()=>{a({walletConnectionError:void 0});},updateActiveWallet:e=>{i().activeWallet?(e.chainId&&orbitCore.connectedWalletChainHelpers.setConnectedWalletChain(e.chainId),a(o=>immer.produce(o,t=>{t.activeWallet&&(t.activeWallet={...t.activeWallet,...e});}))):e.walletType!==void 0&&e.chainId!==void 0&&e.address!==void 0&&(orbitCore.connectedWalletChainHelpers.setConnectedWalletChain(e.chainId),a({activeWallet:e}));},switchNetwork:async e=>{a({switchNetworkError:void 0});let n=i().activeWallet;if(n){let o=orbitCore.selectAdapterByKey({adapter:r,adapterKey:l(n.walletType)});try{await o?.checkAndSwitchNetwork(e,n.chainId,i().updateActiveWallet);}catch(t){a({switchNetworkError:"Switch network failed: "+(t instanceof Error?t.message:String(t))});}}},resetSwitchNetworkError:()=>a({switchNetworkError:void 0})}))}exports.createSatelliteConnectStore=E;exports.getAdapterFromWalletType=l;exports.impersonatedHelpers=p;//# 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/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,CAA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AO,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"]}
|
|
1
|
+
{"version":3,"sources":["../src/utils/getAdapterFromWalletType.ts","../src/utils/impersonatedHelpers.ts","../src/store/satelliteConnectStore.ts"],"names":["getAdapterFromWalletType","walletType","OrbitAdapter","impersonatedHelpers","address","createSatelliteConnectStore","adapter","callbackAfterConnected","createStore","set","get","autoConnect","a","connectors","state","produce","draft","lastConnectedWallet","chainId","foundAdapter","selectAdapterByKey","wallet","connectedWalletChainHelpers","e","activeWallet"],"mappings":"mHA0BO,SAASA,CAAAA,CAAyBC,CAAAA,CAAsC,CAC7E,OAAQA,CAAAA,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"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","import { connectedWalletChainHelpers, 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';\nimport { impersonatedHelpers } from '../utils/impersonatedHelpers';\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 connectedWalletChainHelpers.setConnectedWalletChain(chainId);\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 connectedWalletChainHelpers.removeConnectedWalletChain();\n impersonatedHelpers.removeImpersonated();\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 if (wallet.chainId) {\n connectedWalletChainHelpers.setConnectedWalletChain(wallet.chainId);\n }\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 connectedWalletChainHelpers.setConnectedWalletChain(wallet.chainId);\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"]}
|
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
|
|
1
|
+
import {OrbitAdapter,selectAdapterByKey,connectedWalletChainHelpers}from'@tuwaio/orbit-core';import {produce}from'immer';import {createStore}from'zustand/vanilla';function l(r){return r.split(":")[0]??OrbitAdapter.EVM}var p={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,removeImpersonated:()=>typeof window<"u"?window.localStorage.removeItem("satellite-connect:impersonatedAddress"):void 0};function E({adapter:r,callbackAfterConnected:f}){return createStore()((a,i)=>({getAdapter:()=>r,availableConnectors:{},initializeAppConnectors:async({autoConnect:e})=>{if(Array.isArray(r))(await Promise.all(r.map(o=>o.getConnectors()))).forEach(o=>{a(t=>produce(t,m=>{m.availableConnectors[o.adapter]=o.connectors;}));});else {let n=await r.getConnectors();a(o=>produce(o,t=>{t.availableConnectors[n.adapter]=n.connectors;}));}if(e){let n=i().lastConnectedWallet;n&&await i().connect({walletType:n.walletType,chainId:n.chainId});}},connect:async({walletType:e,chainId:n})=>{a({walletConnecting:true,walletConnectionError:void 0});let o=selectAdapterByKey({adapter:r,adapterKey:l(e)});try{let t=await o?.connect({walletType:e,chainId:n,connectors:i().availableConnectors[l(e)]??[]});a({activeWallet:t}),connectedWalletChainHelpers.setConnectedWalletChain(n),o?.checkIsContractWallet&&t&&(i().updateActiveWallet({isContractAddress:await o.checkIsContractWallet({address:t.address,chainId:n})}),f&&await f(t)),a({walletConnecting:!1,lastConnectedWallet:{walletType:e,chainId:n}});}catch(t){a({walletConnecting:false,walletConnectionError:"Wallet connection failed: "+(t instanceof Error?t.message:String(t))});}},disconnect:async()=>{let e=i().activeWallet;e&&(await selectAdapterByKey({adapter:r,adapterKey:l(e.walletType)})?.disconnect(),a({activeWallet:void 0,lastConnectedWallet:void 0}),connectedWalletChainHelpers.removeConnectedWalletChain(),p.removeImpersonated());},walletConnecting:false,resetWalletConnectionError:()=>{a({walletConnectionError:void 0});},updateActiveWallet:e=>{i().activeWallet?(e.chainId&&connectedWalletChainHelpers.setConnectedWalletChain(e.chainId),a(o=>produce(o,t=>{t.activeWallet&&(t.activeWallet={...t.activeWallet,...e});}))):e.walletType!==void 0&&e.chainId!==void 0&&e.address!==void 0&&(connectedWalletChainHelpers.setConnectedWalletChain(e.chainId),a({activeWallet:e}));},switchNetwork:async e=>{a({switchNetworkError:void 0});let n=i().activeWallet;if(n){let o=selectAdapterByKey({adapter:r,adapterKey:l(n.walletType)});try{await o?.checkAndSwitchNetwork(e,n.chainId,i().updateActiveWallet);}catch(t){a({switchNetworkError:"Switch network failed: "+(t instanceof Error?t.message:String(t))});}}},resetSwitchNetworkError:()=>a({switchNetworkError:void 0})}))}export{E as createSatelliteConnectStore,l as getAdapterFromWalletType,p as impersonatedHelpers};//# 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/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,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,OAAAA,CAAQD,CAAAA,CAAQE,CAAAA,EAAU,CACxBA,CAAAA,CAAM,oBAAoBH,CAAAA,CAAW,OA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A,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"]}
|
|
1
|
+
{"version":3,"sources":["../src/utils/getAdapterFromWalletType.ts","../src/utils/impersonatedHelpers.ts","../src/store/satelliteConnectStore.ts"],"names":["getAdapterFromWalletType","walletType","OrbitAdapter","impersonatedHelpers","address","createSatelliteConnectStore","adapter","callbackAfterConnected","createStore","set","get","autoConnect","a","connectors","state","produce","draft","lastConnectedWallet","chainId","foundAdapter","selectAdapterByKey","wallet","connectedWalletChainHelpers","e","activeWallet"],"mappings":"mKA0BO,SAASA,CAAAA,CAAyBC,CAAAA,CAAsC,CAC7E,OAAQA,CAAAA,CAAW,KAAA,CAAM,GAAG,CAAA,CAAE,CAAC,CAAA,EAAKC,aAAa,GACnD,CCnBO,IAAMC,CAAAA,CAAsB,CAKjC,mBAAA,CACE,OAAO,MAAA,CAAW,GAAA,CAAe,MAAA,CAAO,YAAA,CAAa,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,MAAA,CAEzG,kBAAA,CAAoB,IAClB,OAAO,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AAe,MAAOH,CAAAA,EAA6B,CACjDT,CAAAA,CAAI,CAAE,kBAAA,CAAoB,MAAU,CAAC,CAAA,CACrC,IAAMe,EAAed,CAAAA,EAAI,CAAE,YAAA,CAC3B,GAAIc,CAAAA,CAAc,CAChB,IAAML,CAAAA,CAAeC,kBAAAA,CAAmB,CACtC,OAAA,CAAAd,CAAAA,CACA,UAAA,CAAYN,CAAAA,CAAyBwB,CAAAA,CAAa,UAAU,CAC9D,CAAC,CAAA,CACD,GAAI,CACF,MAAML,CAAAA,EAAc,qBAAA,CAAsBD,CAAAA,CAASM,CAAAA,CAAa,OAAA,CAASd,CAAAA,EAAI,CAAE,kBAAkB,EACnG,CAAA,MAASa,CAAAA,CAAG,CACVd,CAAAA,CAAI,CAAE,kBAAA,CAAoB,yBAAA,EAA6Bc,CAAAA,YAAa,KAAA,CAAQA,CAAAA,CAAE,OAAA,CAAU,MAAA,CAAOA,CAAC,CAAA,CAAG,CAAC,EACtG,CACF,CACF,CAAA,CAKA,uBAAA,CAAyB,IAAMd,CAAAA,CAAI,CAAE,kBAAA,CAAoB,MAAU,CAAC,CACtE,CAAA,CAAE,CACJ","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","import { connectedWalletChainHelpers, 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';\nimport { impersonatedHelpers } from '../utils/impersonatedHelpers';\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 connectedWalletChainHelpers.setConnectedWalletChain(chainId);\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 connectedWalletChainHelpers.removeConnectedWalletChain();\n impersonatedHelpers.removeImpersonated();\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 if (wallet.chainId) {\n connectedWalletChainHelpers.setConnectedWalletChain(wallet.chainId);\n }\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 connectedWalletChainHelpers.setConnectedWalletChain(wallet.chainId);\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"]}
|
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.4.d5f27c9",
|
|
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.
|
|
56
|
+
"@tuwaio/orbit-core": "^1.0.0-fix-test-alpha.4.d5f27c9"
|
|
57
57
|
},
|
|
58
58
|
"scripts": {
|
|
59
59
|
"start": "tsup src/index.ts --watch",
|