@tuwaio/satellite-core 1.0.0-fix-test-alpha.9.ca7229f → 1.0.0-fix-test-alpha.11.c127bb8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.mts CHANGED
@@ -1,7 +1,7 @@
1
1
  import * as zustand from 'zustand';
2
2
  import { OrbitGenericAdapter, BaseAdapter, OrbitAdapter } from '@tuwaio/orbit-core';
3
3
  import { Connector as Connector$1, CreateConnectorFn } from '@wagmi/core';
4
- import { UiWallet, UiWalletAccount } from '@wallet-standard/ui';
4
+ import { UiWalletAccount, UiWallet } from '@wallet-standard/ui';
5
5
 
6
6
  /**
7
7
  * Type representing a wallet identifier in format "chain:wallet"
@@ -75,18 +75,17 @@ type SatelliteAdapter = BaseAdapter & {
75
75
  * Initiates wallet connection
76
76
  * @returns Promise resolving to connected wallet instance
77
77
  */
78
- connect: ({ walletType, chainId, connectors, }: {
78
+ connect: ({ walletType, chainId }: {
79
79
  walletType: WalletType;
80
80
  chainId: number | string;
81
- connectors: Connector[];
82
81
  }) => Promise<Wallet>;
83
82
  /** Disconnects current wallet session */
84
83
  disconnect: () => Promise<void>;
85
84
  /** Retrieves available wallet connectors for this adapter */
86
- getConnectors: () => Promise<{
85
+ getConnectors: () => {
87
86
  adapter: OrbitAdapter;
88
87
  connectors: Connector[];
89
- }>;
88
+ };
90
89
  /**
91
90
  * Handles network switching for connected wallet
92
91
  * @param chainId - Target chain ID
@@ -106,17 +105,9 @@ type SatelliteAdapter = BaseAdapter & {
106
105
  type ISatelliteConnectStore = {
107
106
  /** Returns configured adapter(s) */
108
107
  getAdapter: () => SatelliteAdapter | SatelliteAdapter[];
109
- /** Information about last connected wallet */
110
- lastConnectedWallet?: {
111
- walletType: WalletType;
112
- chainId: number | string;
113
- };
114
- /** Available connectors mapped by adapter type */
115
- availableConnectors: Partial<Record<OrbitAdapter, Connector[]>>;
116
- /** Initializes wallet connectors */
117
- initializeAppConnectors: ({ autoConnect }: {
118
- autoConnect?: boolean;
119
- }) => Promise<void>;
108
+ /** Get wallet connectors */
109
+ getConnectors: () => Partial<Record<OrbitAdapter, Connector[]>>;
110
+ initializeAutoConnect: (autoConnect: boolean) => Promise<void>;
120
111
  /** Connects to specified wallet */
121
112
  connect: ({ walletType, chainId }: {
122
113
  walletType: WalletType;
@@ -233,4 +224,43 @@ declare const impersonatedHelpers: {
233
224
  removeImpersonated: () => void;
234
225
  };
235
226
 
236
- 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 };
227
+ type LastConnectedWallet = {
228
+ walletType: WalletType;
229
+ chainId: number | string;
230
+ };
231
+ /**
232
+ * Helper utilities for managing the last connected wallet state
233
+ *
234
+ * @remarks
235
+ * All data is stored in localStorage with the 'satellite-connect:lastConnectedWallet' key.
236
+ * Functions are safe to use in both browser and SSR environments.
237
+ */
238
+ declare const lastConnectedWalletHelpers: {
239
+ STORAGE_KEY: string;
240
+ /**
241
+ * The value of the last connected wallet, initialized when the module loads.
242
+ * Returns undefined if not set, invalid, or in an SSR context.
243
+ */
244
+ lastConnectedWallet: LastConnectedWallet | undefined;
245
+ /**
246
+ * Stores the last connected wallet data in localStorage.
247
+ *
248
+ * @param data - Object containing the wallet type and chain ID.
249
+ * @returns undefined in SSR context, void in browser
250
+ */
251
+ setLastConnectedWallet: ({ walletType, chainId }: LastConnectedWallet) => void;
252
+ /**
253
+ * Retrieves the current last connected wallet data from localStorage.
254
+ *
255
+ * @returns The LastConnectedWallet object or undefined if not set or in SSR context
256
+ */
257
+ getLastConnectedWallet: () => LastConnectedWallet | undefined;
258
+ /**
259
+ * Removes the last connected wallet data from localStorage.
260
+ *
261
+ * @returns undefined in SSR context, void in browser
262
+ */
263
+ removeLastConnectedWallet: () => void;
264
+ };
265
+
266
+ 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, lastConnectedWalletHelpers };
package/dist/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import * as zustand from 'zustand';
2
2
  import { OrbitGenericAdapter, BaseAdapter, OrbitAdapter } from '@tuwaio/orbit-core';
3
3
  import { Connector as Connector$1, CreateConnectorFn } from '@wagmi/core';
4
- import { UiWallet, UiWalletAccount } from '@wallet-standard/ui';
4
+ import { UiWalletAccount, UiWallet } from '@wallet-standard/ui';
5
5
 
6
6
  /**
7
7
  * Type representing a wallet identifier in format "chain:wallet"
@@ -75,18 +75,17 @@ type SatelliteAdapter = BaseAdapter & {
75
75
  * Initiates wallet connection
76
76
  * @returns Promise resolving to connected wallet instance
77
77
  */
78
- connect: ({ walletType, chainId, connectors, }: {
78
+ connect: ({ walletType, chainId }: {
79
79
  walletType: WalletType;
80
80
  chainId: number | string;
81
- connectors: Connector[];
82
81
  }) => Promise<Wallet>;
83
82
  /** Disconnects current wallet session */
84
83
  disconnect: () => Promise<void>;
85
84
  /** Retrieves available wallet connectors for this adapter */
86
- getConnectors: () => Promise<{
85
+ getConnectors: () => {
87
86
  adapter: OrbitAdapter;
88
87
  connectors: Connector[];
89
- }>;
88
+ };
90
89
  /**
91
90
  * Handles network switching for connected wallet
92
91
  * @param chainId - Target chain ID
@@ -106,17 +105,9 @@ type SatelliteAdapter = BaseAdapter & {
106
105
  type ISatelliteConnectStore = {
107
106
  /** Returns configured adapter(s) */
108
107
  getAdapter: () => SatelliteAdapter | SatelliteAdapter[];
109
- /** Information about last connected wallet */
110
- lastConnectedWallet?: {
111
- walletType: WalletType;
112
- chainId: number | string;
113
- };
114
- /** Available connectors mapped by adapter type */
115
- availableConnectors: Partial<Record<OrbitAdapter, Connector[]>>;
116
- /** Initializes wallet connectors */
117
- initializeAppConnectors: ({ autoConnect }: {
118
- autoConnect?: boolean;
119
- }) => Promise<void>;
108
+ /** Get wallet connectors */
109
+ getConnectors: () => Partial<Record<OrbitAdapter, Connector[]>>;
110
+ initializeAutoConnect: (autoConnect: boolean) => Promise<void>;
120
111
  /** Connects to specified wallet */
121
112
  connect: ({ walletType, chainId }: {
122
113
  walletType: WalletType;
@@ -233,4 +224,43 @@ declare const impersonatedHelpers: {
233
224
  removeImpersonated: () => void;
234
225
  };
235
226
 
236
- 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 };
227
+ type LastConnectedWallet = {
228
+ walletType: WalletType;
229
+ chainId: number | string;
230
+ };
231
+ /**
232
+ * Helper utilities for managing the last connected wallet state
233
+ *
234
+ * @remarks
235
+ * All data is stored in localStorage with the 'satellite-connect:lastConnectedWallet' key.
236
+ * Functions are safe to use in both browser and SSR environments.
237
+ */
238
+ declare const lastConnectedWalletHelpers: {
239
+ STORAGE_KEY: string;
240
+ /**
241
+ * The value of the last connected wallet, initialized when the module loads.
242
+ * Returns undefined if not set, invalid, or in an SSR context.
243
+ */
244
+ lastConnectedWallet: LastConnectedWallet | undefined;
245
+ /**
246
+ * Stores the last connected wallet data in localStorage.
247
+ *
248
+ * @param data - Object containing the wallet type and chain ID.
249
+ * @returns undefined in SSR context, void in browser
250
+ */
251
+ setLastConnectedWallet: ({ walletType, chainId }: LastConnectedWallet) => void;
252
+ /**
253
+ * Retrieves the current last connected wallet data from localStorage.
254
+ *
255
+ * @returns The LastConnectedWallet object or undefined if not set or in SSR context
256
+ */
257
+ getLastConnectedWallet: () => LastConnectedWallet | undefined;
258
+ /**
259
+ * Removes the last connected wallet data from localStorage.
260
+ *
261
+ * @returns undefined in SSR context, void in browser
262
+ */
263
+ removeLastConnectedWallet: () => void;
264
+ };
265
+
266
+ 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, lastConnectedWalletHelpers };
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}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
1
+ 'use strict';var orbitCore=require('@tuwaio/orbit-core'),immer=require('immer'),vanilla=require('zustand/vanilla');function f(n){return n.split(":")[0]??orbitCore.OrbitAdapter.EVM}var m={impersonatedAddress:typeof window<"u"?window.localStorage.getItem("satellite-connect:impersonatedAddress")??"":"",setImpersonated:n=>typeof window<"u"?window.localStorage.setItem("satellite-connect:impersonatedAddress",n):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};var W=n=>{if(typeof window>"u")return;let c=window.localStorage.getItem(n);if(c)try{return JSON.parse(c)}catch(o){console.error("Error parsing lastConnectedWallet from localStorage:",o);return}},i={STORAGE_KEY:"satellite-connect:lastConnectedWallet",lastConnectedWallet:W("satellite-connect:lastConnectedWallet"),setLastConnectedWallet:({walletType:n,chainId:c})=>typeof window<"u"?window.localStorage.setItem(i.STORAGE_KEY,JSON.stringify({walletType:n,chainId:c})):void 0,getLastConnectedWallet:()=>W(i.STORAGE_KEY),removeLastConnectedWallet:()=>typeof window<"u"?window.localStorage.removeItem(i.STORAGE_KEY):void 0};function L({adapter:n,callbackAfterConnected:c}){return vanilla.createStore()((o,d)=>({getAdapter:()=>n,getConnectors:()=>{let e;return Array.isArray(n)?e=n.map(t=>t.getConnectors()):e=[n.getConnectors()],e.reduce((t,l)=>{let a=l.adapter,r=l.connectors;return {...t,[a]:r}},{})},initializeAutoConnect:async e=>{if(e){let t=i.getLastConnectedWallet();t&&await d().connect({walletType:t.walletType,chainId:t.chainId});}},walletConnecting:false,walletConnectionError:void 0,switchNetworkError:void 0,activeWallet:void 0,connect:async({walletType:e,chainId:t})=>{o({walletConnecting:true,walletConnectionError:void 0});let l=f(e),a=orbitCore.selectAdapterByKey({adapter:n,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:t});if(o({activeWallet:r}),orbitCore.connectedWalletChainHelpers.setConnectedWalletChain(t),a.checkIsContractWallet){let s=await a.checkIsContractWallet({address:r.address,chainId:t});d().updateActiveWallet({isContractAddress:s});}if(c){let s=d().activeWallet;s&&await c(s);}o({walletConnecting:!1}),i.setLastConnectedWallet({walletType:e,chainId:t});}catch(r){o({walletConnecting:false,walletConnectionError:"Wallet connection failed: "+(r instanceof Error?r.message:String(r))});}},disconnect:async()=>{let e=d().activeWallet;e&&(await orbitCore.selectAdapterByKey({adapter:n,adapterKey:f(e.walletType)})?.disconnect(),o({activeWallet:void 0,walletConnectionError:void 0,switchNetworkError:void 0}),i.removeLastConnectedWallet(),orbitCore.connectedWalletChainHelpers.removeConnectedWalletChain(),m.removeImpersonated());},resetWalletConnectionError:()=>{o({walletConnectionError:void 0});},updateActiveWallet:e=>{let t=d().activeWallet;t?(e.chainId&&(orbitCore.connectedWalletChainHelpers.setConnectedWalletChain(e.chainId),i.setLastConnectedWallet({walletType:t.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 t=d().activeWallet;if(t){let l=f(t.walletType),a=orbitCore.selectAdapterByKey({adapter:n,adapterKey:l});if(!a){o({switchNetworkError:`No adapter found for active wallet type: ${t.walletType}`});return}try{await a.checkAndSwitchNetwork(e,t.chainId,d().updateActiveWallet);}catch(r){o({switchNetworkError:"Switch network failed: "+(r instanceof Error?r.message:String(r))});}}},resetSwitchNetworkError:()=>o({switchNetworkError:void 0})}))}exports.createSatelliteConnectStore=L;exports.getAdapterFromWalletType=f;exports.impersonatedHelpers=m;exports.lastConnectedWalletHelpers=i;//# 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/store/satelliteConnectStore.ts"],"names":["getAdapterFromWalletType","walletType","OrbitAdapter","impersonatedHelpers","address","createSatelliteConnectStore","adapter","callbackAfterConnected","createStore","set","get","autoConnect","a","connectors","state","produce","draft","lastConnect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A,CAAG,CAAC,EACtG,CACF,CACF,CAAA,CAKA,uBAAA,CAAyB,IAAMd,CAAAA,CAAI,CAAE,kBAAA,CAAoB,MAAU,CAAC,CACtE,CAAA,CAAE,CACJ","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","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"]}
1
+ {"version":3,"sources":["../src/utils/getAdapterFromWalletType.ts","../src/utils/impersonatedHelpers.ts","../src/utils/lastConnectedWalletHelpers.ts","../src/store/satelliteConnectStore.ts"],"names":["getAdapterFromWalletType","walletType","OrbitAdapter","impersonatedHelpers","address","getParsedStorageItem","key","item","error","lastConnectedWalletHelpers","chainId","createSatelliteConnectStore","adapter","callbackAfterConnected","createStore","set","get","results","a","accumulator","currentResult","value","autoConnect","lastConnectedWallet","adapterKey","foundAdapter","selectAdapterByKey","wallet","connectedWalletChainHelpers","isContractAddress","updatedWallet","e","activeWallet","state","produce","draft"],"mappings":"mHA0BO,SAASA,CAAAA,CAAyBC,EAAsC,CAC7E,OAAQA,CAAAA,CAAW,KAAA,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O,OAAA,GAAY,MAAA,EAAaA,CAAAA,CAAO,UAAY,MAAA,EAGtFC,qCAAAA,CAA4B,uBAAA,CAAwBD,CAAAA,CAAO,OAAQ,CAAA,CACnEZ,CAAAA,CAAI,CAAE,YAAA,CAAcY,CAAiB,CAAC,CAAA,EAEtC,OAAA,CAAQ,IAAA,CAAK,sFAAsF,EAGzG,CAAA,CAMA,aAAA,CAAe,MAAOjB,GAA6B,CACjDK,CAAAA,CAAI,CAAE,kBAAA,CAAoB,MAAU,CAAC,CAAA,CACrC,IAAMiB,CAAAA,CAAehB,GAAI,CAAE,YAAA,CAC3B,GAAIgB,CAAAA,CAAc,CAChB,IAAMR,CAAAA,CAAaxB,CAAAA,CAAyBgC,CAAAA,CAAa,UAAU,CAAA,CAC7DP,CAAAA,CAAeC,4BAAAA,CAAmB,CAAE,QAAAd,CAAAA,CAAS,UAAA,CAAAY,CAAW,CAAC,EAE/D,GAAI,CAACC,CAAAA,CAAc,CACjBV,EAAI,CAAE,kBAAA,CAAoB,CAAA,yCAAA,EAA4CiB,CAAAA,CAAa,UAAU,CAAA,CAAG,CAAC,CAAA,CACjG,MACF,CAEA,GAAI,CAEF,MAAMP,CAAAA,CAAa,sBAAsBf,CAAAA,CAASsB,CAAAA,CAAa,OAAA,CAAShB,CAAAA,GAAM,kBAAkB,EAClG,CAAA,MAASe,CAAAA,CAAG,CACVhB,CAAAA,CAAI,CAAE,kBAAA,CAAoB,yBAAA,EAA6BgB,aAAa,KAAA,CAAQA,CAAAA,CAAE,OAAA,CAAU,MAAA,CAAOA,CAAC,CAAA,CAAG,CAAC,EACtG,CACF,CACF,CAAA,CAUA,uBAAA,CAAyB,IAAMhB,CAAAA,CAAI,CAAE,kBAAA,CAAoB,MAAU,CAAC,CACtE,EAAE,CACJ","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","import { WalletType } from '../types';\n\ntype LastConnectedWallet = { walletType: WalletType; chainId: number | string };\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 */\nconst getParsedStorageItem = (key: string): LastConnectedWallet | 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 LastConnectedWallet;\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 lastConnectedWallet from localStorage:', error);\n return undefined;\n }\n};\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('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(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 { connectedWalletChainHelpers, OrbitAdapter, selectAdapterByKey } from '@tuwaio/orbit-core';\nimport { 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';\nimport { lastConnectedWalletHelpers } from '../utils/lastConnectedWalletHelpers';\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 * Get wallet connectors for all configured adapters\n */\n getConnectors: () => {\n let results: { adapter: OrbitAdapter; connectors: Connector[] }[];\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, Connector[]>>,\n );\n },\n\n initializeAutoConnect: async (autoConnect) => {\n if (autoConnect) {\n const lastConnectedWallet = lastConnectedWalletHelpers.getLastConnectedWallet();\n if (lastConnectedWallet) {\n // Explicitly await the connect call\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 } 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\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 /**\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>) => {\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 Wallet; // 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 Wallet });\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"]}
package/dist/index.mjs CHANGED
@@ -1,2 +1,2 @@
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
1
+ import {OrbitAdapter,selectAdapterByKey,connectedWalletChainHelpers}from'@tuwaio/orbit-core';import {produce}from'immer';import {createStore}from'zustand/vanilla';function f(n){return n.split(":")[0]??OrbitAdapter.EVM}var m={impersonatedAddress:typeof window<"u"?window.localStorage.getItem("satellite-connect:impersonatedAddress")??"":"",setImpersonated:n=>typeof window<"u"?window.localStorage.setItem("satellite-connect:impersonatedAddress",n):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};var W=n=>{if(typeof window>"u")return;let c=window.localStorage.getItem(n);if(c)try{return JSON.parse(c)}catch(o){console.error("Error parsing lastConnectedWallet from localStorage:",o);return}},i={STORAGE_KEY:"satellite-connect:lastConnectedWallet",lastConnectedWallet:W("satellite-connect:lastConnectedWallet"),setLastConnectedWallet:({walletType:n,chainId:c})=>typeof window<"u"?window.localStorage.setItem(i.STORAGE_KEY,JSON.stringify({walletType:n,chainId:c})):void 0,getLastConnectedWallet:()=>W(i.STORAGE_KEY),removeLastConnectedWallet:()=>typeof window<"u"?window.localStorage.removeItem(i.STORAGE_KEY):void 0};function L({adapter:n,callbackAfterConnected:c}){return createStore()((o,d)=>({getAdapter:()=>n,getConnectors:()=>{let e;return Array.isArray(n)?e=n.map(t=>t.getConnectors()):e=[n.getConnectors()],e.reduce((t,l)=>{let a=l.adapter,r=l.connectors;return {...t,[a]:r}},{})},initializeAutoConnect:async e=>{if(e){let t=i.getLastConnectedWallet();t&&await d().connect({walletType:t.walletType,chainId:t.chainId});}},walletConnecting:false,walletConnectionError:void 0,switchNetworkError:void 0,activeWallet:void 0,connect:async({walletType:e,chainId:t})=>{o({walletConnecting:true,walletConnectionError:void 0});let l=f(e),a=selectAdapterByKey({adapter:n,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:t});if(o({activeWallet:r}),connectedWalletChainHelpers.setConnectedWalletChain(t),a.checkIsContractWallet){let s=await a.checkIsContractWallet({address:r.address,chainId:t});d().updateActiveWallet({isContractAddress:s});}if(c){let s=d().activeWallet;s&&await c(s);}o({walletConnecting:!1}),i.setLastConnectedWallet({walletType:e,chainId:t});}catch(r){o({walletConnecting:false,walletConnectionError:"Wallet connection failed: "+(r instanceof Error?r.message:String(r))});}},disconnect:async()=>{let e=d().activeWallet;e&&(await selectAdapterByKey({adapter:n,adapterKey:f(e.walletType)})?.disconnect(),o({activeWallet:void 0,walletConnectionError:void 0,switchNetworkError:void 0}),i.removeLastConnectedWallet(),connectedWalletChainHelpers.removeConnectedWalletChain(),m.removeImpersonated());},resetWalletConnectionError:()=>{o({walletConnectionError:void 0});},updateActiveWallet:e=>{let t=d().activeWallet;t?(e.chainId&&(connectedWalletChainHelpers.setConnectedWalletChain(e.chainId),i.setLastConnectedWallet({walletType:t.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 t=d().activeWallet;if(t){let l=f(t.walletType),a=selectAdapterByKey({adapter:n,adapterKey:l});if(!a){o({switchNetworkError:`No adapter found for active wallet type: ${t.walletType}`});return}try{await a.checkAndSwitchNetwork(e,t.chainId,d().updateActiveWallet);}catch(r){o({switchNetworkError:"Switch network failed: "+(r instanceof Error?r.message:String(r))});}}},resetSwitchNetworkError:()=>o({switchNetworkError:void 0})}))}export{L as createSatelliteConnectStore,f as getAdapterFromWalletType,m as impersonatedHelpers,i as lastConnectedWalletHelpers};//# sourceMappingURL=index.mjs.map
2
2
  //# sourceMappingURL=index.mjs.map
@@ -1 +1 @@
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,EA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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"]}
1
+ {"version":3,"sources":["../src/utils/getAdapterFromWalletType.ts","../src/utils/impersonatedHelpers.ts","../src/utils/lastConnectedWalletHelpers.ts","../src/store/satelliteConnectStore.ts"],"names":["getAdapterFromWalletType","walletType","OrbitAdapter","impersonatedHelpers","address","getParsedStorageItem","key","item","error","lastConnectedWalletHelpers","chainId","createSatelliteConnectStore","adapter","callbackAfterConnected","createStore","set","get","results","a","accumulator","currentResult","value","autoConnect","lastConnectedWallet","adapterKey","foundAdapter","selectAdapterByKey","wallet","connectedWalletChainHelpers","isContractAddress","updatedWallet","e","activeWallet","state","produce","draft"],"mappings":"mKA0BO,SAASA,CAAAA,CAAyBC,EAAsC,CAC7E,OAAQA,CAAAA,CAAW,KAAA,CAAM,GAAG,CAAA,CAAE,CAAC,CAAA,EAAKC,YAAAA,CAAa,GACnD,CCnBO,IAAMC,CAAAA,CAAsB,CAKjC,oBACE,OAAO,MAAA,CAAW,GAAA,CAAe,MAAA,CAAO,aAAa,OAAA,CAAQ,uCAAuC,CAAA,EAAK,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AA,CAAQ,IAAA,CAAK,sFAAsF,EAGzG,CAAA,CAMA,aAAA,CAAe,MAAOjB,GAA6B,CACjDK,CAAAA,CAAI,CAAE,kBAAA,CAAoB,MAAU,CAAC,CAAA,CACrC,IAAMiB,CAAAA,CAAehB,GAAI,CAAE,YAAA,CAC3B,GAAIgB,CAAAA,CAAc,CAChB,IAAMR,CAAAA,CAAaxB,CAAAA,CAAyBgC,CAAAA,CAAa,UAAU,CAAA,CAC7DP,CAAAA,CAAeC,kBAAAA,CAAmB,CAAE,QAAAd,CAAAA,CAAS,UAAA,CAAAY,CAAW,CAAC,EAE/D,GAAI,CAACC,CAAAA,CAAc,CACjBV,EAAI,CAAE,kBAAA,CAAoB,CAAA,yCAAA,EAA4CiB,CAAAA,CAAa,UAAU,CAAA,CAAG,CAAC,CAAA,CACjG,MACF,CAEA,GAAI,CAEF,MAAMP,CAAAA,CAAa,sBAAsBf,CAAAA,CAASsB,CAAAA,CAAa,OAAA,CAAShB,CAAAA,GAAM,kBAAkB,EAClG,CAAA,MAASe,CAAAA,CAAG,CACVhB,CAAAA,CAAI,CAAE,kBAAA,CAAoB,yBAAA,EAA6BgB,aAAa,KAAA,CAAQA,CAAAA,CAAE,OAAA,CAAU,MAAA,CAAOA,CAAC,CAAA,CAAG,CAAC,EACtG,CACF,CACF,CAAA,CAUA,uBAAA,CAAyB,IAAMhB,CAAAA,CAAI,CAAE,kBAAA,CAAoB,MAAU,CAAC,CACtE,EAAE,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 { WalletType } from '../types';\n\ntype LastConnectedWallet = { walletType: WalletType; chainId: number | string };\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 */\nconst getParsedStorageItem = (key: string): LastConnectedWallet | 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 LastConnectedWallet;\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 lastConnectedWallet from localStorage:', error);\n return undefined;\n }\n};\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('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(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 { connectedWalletChainHelpers, OrbitAdapter, selectAdapterByKey } from '@tuwaio/orbit-core';\nimport { 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';\nimport { lastConnectedWalletHelpers } from '../utils/lastConnectedWalletHelpers';\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 * Get wallet connectors for all configured adapters\n */\n getConnectors: () => {\n let results: { adapter: OrbitAdapter; connectors: Connector[] }[];\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, Connector[]>>,\n );\n },\n\n initializeAutoConnect: async (autoConnect) => {\n if (autoConnect) {\n const lastConnectedWallet = lastConnectedWalletHelpers.getLastConnectedWallet();\n if (lastConnectedWallet) {\n // Explicitly await the connect call\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 } 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\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 /**\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>) => {\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 Wallet; // 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 Wallet });\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"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tuwaio/satellite-core",
3
- "version": "1.0.0-fix-test-alpha.9.ca7229f",
3
+ "version": "1.0.0-fix-test-alpha.11.c127bb8",
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.9.ca7229f"
56
+ "@tuwaio/orbit-core": "^1.0.0-fix-test-alpha.11.c127bb8"
57
57
  },
58
58
  "scripts": {
59
59
  "start": "tsup src/index.ts --watch",