@tuwaio/satellite-core 1.0.0-fix-optimization-alpha.1.d6a8b2d → 1.0.0-fix-optimization-alpha.2.80df34b

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- 'use strict';var orbitCore=require('@tuwaio/orbit-core'),immer=require('immer'),vanilla=require('zustand/vanilla');function b({adapter:l,callbackAfterConnected:h}){return immer.setAutoFreeze(false),vanilla.createStore()((r,c)=>({getAdapter:n=>orbitCore.selectAdapterByKey({adapter:l,adapterKey:n}),getConnectors:()=>{let n;return Array.isArray(l)?n=l.map(o=>o.getConnectors()):n=[l.getConnectors()],n.reduce((o,e)=>{let i=e.adapter,t=e.connectors;return {...o,[i]:t}},{})},initializeAutoConnect:async n=>{await orbitCore.delay(null,300),await c().disconnectAll();let o=Date.now()-10080*60*1e3;if(orbitCore.recentlyConnectedConnectorsListHelpers.removeConnectorsOlderThan(o),n){let e=orbitCore.lastConnectedConnectorHelpers.getLastConnectedConnector();e&&!["impersonatedwallet","walletconnect","coinbasewallet","bitgetwallet"].includes(e.connectorType.split(":")[1])&&(await orbitCore.delay(null,100),await c().connect({connectorType:e.connectorType,chainId:e.chainId}));}else if(orbitCore.isSafeApp){await orbitCore.delay(null,100);let e=c().getAdapter(orbitCore.OrbitAdapter.EVM);if(e&&e.getSafeConnectorChainId){let i=await e.getSafeConnectorChainId();i&&await c().connect({connectorType:`${orbitCore.OrbitAdapter.EVM}:safewallet`,chainId:i});}}},connecting:false,disconnecting:false,connectionError:void 0,switchNetworkError:void 0,activeConnection:void 0,connections:{},setConnectionError:n=>r({connectionError:n}),connect:async({connectorType:n,chainId:o})=>{r({connecting:true,connectionError:void 0});let e=c().getAdapter(orbitCore.getAdapterFromConnectorType(n));if(!e){r({connecting:false,connectionError:`No adapter found for connector type: ${n}`});return}try{if(c().connections[n])return;let t=await e.connect({connectorType:n,chainId:o});if(r(s=>({activeConnection:t,connections:{...s.connections,[t.connectorType]:t}})),e.checkIsContractAddress){let s=await e.checkIsContractAddress({address:t.address,chainId:o});c().updateActiveConnection({...t,isContractAddress:s});}if(h){let s=c().activeConnection;s&&s.connectorType===n&&await h(s);}r({connecting:!1}),orbitCore.lastConnectedConnectorHelpers.setLastConnectedConnector({connectorType:n,chainId:o,address:c().activeConnection?.address});let a=c().activeConnection;a&&a.address&&orbitCore.recentlyConnectedConnectorsListHelpers.addConnector(a.connectorType,{address:a.address,disconnectedTimestamp:Date.now(),icon:a.icon});}catch(i){r({connecting:false,connectionError:"Connector connection failed: "+(i instanceof Error?i.message:String(i))});}},disconnect:async n=>{if(!c().disconnecting){r({disconnecting:true});try{if(n){let e=c(),i=e.connections[n];if(!i){console.warn(`No connection found for connector type: ${n}`);return}let t=c().getAdapter(orbitCore.getAdapterFromConnectorType(i.connectorType));if(t)try{await t.disconnect(i);}catch(d){console.error(`Failed to disconnect connector ${n}:`,d);}let a=e.activeConnection?.connectorType===n,s=Object.values(e.connections).filter(d=>d.connectorType!==n),w;if(a&&s.length>0){let d=s[0];try{let C=c().getAdapter(orbitCore.getAdapterFromConnectorType(d.connectorType));C?.switchConnection&&await C.switchConnection(d.connectorType),w=d;}catch(C){console.error("Failed to switch to remaining connector:",C),w=void 0;}}else a||(w=e.activeConnection);r(d=>immer.produce(d,C=>{delete C.connections[n],C.activeConnection=w,C.connectionError=void 0,C.switchNetworkError=void 0;}));}else await c().disconnectAll();let o=c();Object.keys(o.connections).length===0?(orbitCore.lastConnectedConnectorHelpers.removeLastConnectedConnector(),orbitCore.impersonatedHelpers.removeImpersonated()):o.activeConnection&&orbitCore.lastConnectedConnectorHelpers.setLastConnectedConnector({connectorType:o.activeConnection.connectorType,chainId:o.activeConnection.chainId,address:o.activeConnection.address});}catch(o){console.error("Disconnect operation failed:",o),r(e=>immer.produce(e,i=>{i.connectionError=`Disconnect failed: ${o instanceof Error?o.message:String(o)}`;}));}finally{r({disconnecting:false});}}},disconnectAll:async()=>{if(Array.isArray(l))await Promise.allSettled(l.map(async n=>{try{await n.disconnect();}catch{}}));else try{await l.disconnect();}catch{}r({activeConnection:void 0,connections:{},connectionError:void 0,switchNetworkError:void 0}),orbitCore.impersonatedHelpers.removeImpersonated();},resetConnectionError:()=>{r({connectionError:void 0});},updateActiveConnection:n=>{let o=c().activeConnection,e=n.connectorType??o?.connectorType;e?(n.chainId&&e===o?.connectorType&&orbitCore.lastConnectedConnectorHelpers.setLastConnectedConnector({connectorType:e,chainId:n.chainId,address:n.address??o?.address}),r(i=>immer.produce(i,t=>{t.connections[e]&&(t.connections[e]={...t.connections[e],...n},t.activeConnection?.connectorType===e&&(t.activeConnection=t.connections[e]));}))):n.connectorType!==void 0&&n.chainId!==void 0&&n.address!==void 0?(orbitCore.lastConnectedConnectorHelpers.setLastConnectedConnector({connectorType:n.connectorType,chainId:n.chainId,address:n.address}),r(t=>{let a=n;return {activeConnection:a,connections:{...t.connections,[a.connectorType]:a}}})):console.warn("Attempted to set activeConnection with incomplete data while activeConnection was undefined.");},switchConnection:async n=>{let o=c().connections[n];if(!o){console.warn(`No connection found for connector type: ${n}`);return}if(c().activeConnection?.connectorType!==n)try{let e=c().getAdapter(orbitCore.getAdapterFromConnectorType(n));e?.switchConnection&&await e.switchConnection(n),r(i=>immer.produce(i,t=>{t.activeConnection=o;})),orbitCore.lastConnectedConnectorHelpers.setLastConnectedConnector({connectorType:o.connectorType,chainId:o.chainId,address:o.address});}catch(e){console.error("Failed to switch connection:",e);}},switchNetwork:async(n,o)=>{r({switchNetworkError:void 0});let e=o?c().connections[o]:c().activeConnection;if(e){let i=c().getAdapter(orbitCore.getAdapterFromConnectorType(e.connectorType));if(!i){r({switchNetworkError:`No adapter found for active connector type: ${e.connectorType}`});return}try{await i.checkAndSwitchNetwork(n,e.chainId,c().updateActiveConnection);}catch(t){r({switchNetworkError:"Switch network failed: "+(t instanceof Error?t.message:String(t))});}}},resetSwitchNetworkError:()=>r({switchNetworkError:void 0})}))}exports.createSatelliteConnectStore=b;
1
+ 'use strict';var orbitCore=require('@tuwaio/orbit-core'),immer=require('immer'),vanilla=require('zustand/vanilla');function D({adapter:f,callbackAfterConnected:h}){return immer.setAutoFreeze(false),vanilla.createStore()((r,t)=>({getAdapter:n=>orbitCore.selectAdapterByKey({adapter:f,adapterKey:n}),getConnectors:()=>{let n;return Array.isArray(f)?n=f.map(o=>o.getConnectors()):n=[f.getConnectors()],n.reduce((o,e)=>{let c=e.adapter,i=e.connectors;return {...o,[c]:i}},{})},initializeAutoConnect:async n=>{await orbitCore.delay(null,300),await t().disconnectAll();let o=Date.now()-10080*60*1e3;if(orbitCore.recentlyConnectedConnectorsListHelpers.removeConnectorsOlderThan(o),n){let e=orbitCore.lastConnectedConnectorHelpers.getLastConnectedConnector();e&&!["impersonatedwallet","walletconnect","coinbasewallet","bitgetwallet"].includes(e.connectorType.split(":")[1])&&(await orbitCore.delay(null,100),await t().connect({connectorType:e.connectorType,chainId:e.chainId}));}else if(orbitCore.isSafeApp){await orbitCore.delay(null,100);let e=t().getAdapter(orbitCore.OrbitAdapter.EVM);if(e&&e.getSafeConnectorChainId){let c=await e.getSafeConnectorChainId();c&&await t().connect({connectorType:`${orbitCore.OrbitAdapter.EVM}:safewallet`,chainId:c});}}},connecting:false,disconnecting:false,connectionError:void 0,switchNetworkError:void 0,activeConnection:void 0,connections:{},setConnectionError:n=>r({connectionError:n}),connect:async({connectorType:n,chainId:o})=>{r({connecting:true,connectionError:void 0});let e=t().getAdapter(orbitCore.getAdapterFromConnectorType(n));if(!e){r({connecting:false,connectionError:`No adapter found for connector type: ${n}`});return}try{if(t().connections[n])return;let i=await e.connect({connectorType:n,chainId:o});if(r(s=>({activeConnection:i,connections:{...s.connections,[i.connectorType]:i}})),e.checkIsContractAddress){let s=await e.checkIsContractAddress({address:i.address,chainId:o});t().updateActiveConnection({...i,isContractAddress:s});}if(h){let s=t().activeConnection;s&&s.connectorType===n&&await h(s);}r({connecting:!1}),orbitCore.lastConnectedConnectorHelpers.setLastConnectedConnector({connectorType:n,chainId:o,address:t().activeConnection?.address});let a=t().activeConnection;a&&a.address&&orbitCore.recentlyConnectedConnectorsListHelpers.addConnector(a.connectorType,{address:a.address,disconnectedTimestamp:Date.now(),icon:a.icon});}catch(c){r({connecting:false,connectionError:"Connector connection failed: "+(c instanceof Error?c.message:String(c))});}},disconnect:async n=>{if(!t().disconnecting){r({disconnecting:true});try{if(n){let e=t(),c=e.connections[n];if(!c){console.warn(`No connection found for connector type: ${n}`);return}let i=t().getAdapter(orbitCore.getAdapterFromConnectorType(c.connectorType));if(i)try{await i.disconnect(c);}catch(d){console.error(`Failed to disconnect connector ${n}:`,d);}let a=e.activeConnection?.connectorType===n,s=Object.values(e.connections).filter(d=>d.connectorType!==n),l;if(a&&s.length>0){let d=s[0];try{let C=t().getAdapter(orbitCore.getAdapterFromConnectorType(d.connectorType));C?.switchConnection&&await C.switchConnection(d.connectorType),l=d;}catch(C){console.error("Failed to switch to remaining connector:",C),l=void 0;}}else a||(l=e.activeConnection);r(d=>immer.produce(d,C=>{delete C.connections[n],C.activeConnection=l,C.connectionError=void 0,C.switchNetworkError=void 0;}));}else await t().disconnectAll();let o=t();Object.keys(o.connections).length===0?(orbitCore.lastConnectedConnectorHelpers.removeLastConnectedConnector(),orbitCore.impersonatedHelpers.removeImpersonated()):o.activeConnection&&orbitCore.lastConnectedConnectorHelpers.setLastConnectedConnector({connectorType:o.activeConnection.connectorType,chainId:o.activeConnection.chainId,address:o.activeConnection.address});}catch(o){console.error("Disconnect operation failed:",o),r(e=>immer.produce(e,c=>{c.connectionError=`Disconnect failed: ${o instanceof Error?o.message:String(o)}`;}));}finally{r({disconnecting:false});}}},disconnectAll:async()=>{if(Array.isArray(f))await Promise.allSettled(f.map(async n=>{try{await n.disconnect();}catch{}}));else try{await f.disconnect();}catch{}r({activeConnection:void 0,connections:{},connectionError:void 0,switchNetworkError:void 0}),orbitCore.impersonatedHelpers.removeImpersonated();},resetConnectionError:()=>{r({connectionError:void 0});},updateActiveConnection:n=>{let o=t().activeConnection,e=n.connectorType??o?.connectorType;e?(n.chainId&&e===o?.connectorType&&orbitCore.lastConnectedConnectorHelpers.setLastConnectedConnector({connectorType:e,chainId:n.chainId,address:n.address??o?.address}),r(c=>immer.produce(c,i=>{let a=i.connections[e];if(a){let l={...a,...n};i.connections[e]=l,i.activeConnection?.connectorType===e&&(i.activeConnection=l);}}))):n.connectorType!==void 0&&n.chainId!==void 0&&n.address!==void 0?(orbitCore.lastConnectedConnectorHelpers.setLastConnectedConnector({connectorType:n.connectorType,chainId:n.chainId,address:n.address}),r(i=>{let a=n;return {activeConnection:a,connections:{...i.connections,[a.connectorType]:a}}})):console.warn("Attempted to set activeConnection with incomplete data while activeConnection was undefined.");},switchConnection:async n=>{let o=t().connections[n];if(!o){console.warn(`No connection found for connector type: ${n}`);return}if(t().activeConnection?.connectorType!==n)try{let e=t().getAdapter(orbitCore.getAdapterFromConnectorType(n));e?.switchConnection&&await e.switchConnection(n),r(c=>immer.produce(c,i=>{i.activeConnection=o;})),orbitCore.lastConnectedConnectorHelpers.setLastConnectedConnector({connectorType:o.connectorType,chainId:o.chainId,address:o.address});}catch(e){console.error("Failed to switch connection:",e);}},switchNetwork:async(n,o)=>{r({switchNetworkError:void 0});let e=o?t().connections[o]:t().activeConnection;if(e){let c=t().getAdapter(orbitCore.getAdapterFromConnectorType(e.connectorType));if(!c){r({switchNetworkError:`No adapter found for active connector type: ${e.connectorType}`});return}try{await c.checkAndSwitchNetwork(n,e.chainId,t().updateActiveConnection);}catch(i){r({switchNetworkError:"Switch network failed: "+(i instanceof Error?i.message:String(i))});}}},resetSwitchNetworkError:()=>r({switchNetworkError:void 0})}))}exports.createSatelliteConnectStore=D;
package/dist/index.mjs CHANGED
@@ -1 +1 @@
1
- import {selectAdapterByKey,getAdapterFromConnectorType,lastConnectedConnectorHelpers,impersonatedHelpers,recentlyConnectedConnectorsListHelpers,delay,isSafeApp,OrbitAdapter}from'@tuwaio/orbit-core';import {setAutoFreeze,produce}from'immer';import {createStore}from'zustand/vanilla';function b({adapter:l,callbackAfterConnected:h}){return setAutoFreeze(false),createStore()((r,c)=>({getAdapter:n=>selectAdapterByKey({adapter:l,adapterKey:n}),getConnectors:()=>{let n;return Array.isArray(l)?n=l.map(o=>o.getConnectors()):n=[l.getConnectors()],n.reduce((o,e)=>{let i=e.adapter,t=e.connectors;return {...o,[i]:t}},{})},initializeAutoConnect:async n=>{await delay(null,300),await c().disconnectAll();let o=Date.now()-10080*60*1e3;if(recentlyConnectedConnectorsListHelpers.removeConnectorsOlderThan(o),n){let e=lastConnectedConnectorHelpers.getLastConnectedConnector();e&&!["impersonatedwallet","walletconnect","coinbasewallet","bitgetwallet"].includes(e.connectorType.split(":")[1])&&(await delay(null,100),await c().connect({connectorType:e.connectorType,chainId:e.chainId}));}else if(isSafeApp){await delay(null,100);let e=c().getAdapter(OrbitAdapter.EVM);if(e&&e.getSafeConnectorChainId){let i=await e.getSafeConnectorChainId();i&&await c().connect({connectorType:`${OrbitAdapter.EVM}:safewallet`,chainId:i});}}},connecting:false,disconnecting:false,connectionError:void 0,switchNetworkError:void 0,activeConnection:void 0,connections:{},setConnectionError:n=>r({connectionError:n}),connect:async({connectorType:n,chainId:o})=>{r({connecting:true,connectionError:void 0});let e=c().getAdapter(getAdapterFromConnectorType(n));if(!e){r({connecting:false,connectionError:`No adapter found for connector type: ${n}`});return}try{if(c().connections[n])return;let t=await e.connect({connectorType:n,chainId:o});if(r(s=>({activeConnection:t,connections:{...s.connections,[t.connectorType]:t}})),e.checkIsContractAddress){let s=await e.checkIsContractAddress({address:t.address,chainId:o});c().updateActiveConnection({...t,isContractAddress:s});}if(h){let s=c().activeConnection;s&&s.connectorType===n&&await h(s);}r({connecting:!1}),lastConnectedConnectorHelpers.setLastConnectedConnector({connectorType:n,chainId:o,address:c().activeConnection?.address});let a=c().activeConnection;a&&a.address&&recentlyConnectedConnectorsListHelpers.addConnector(a.connectorType,{address:a.address,disconnectedTimestamp:Date.now(),icon:a.icon});}catch(i){r({connecting:false,connectionError:"Connector connection failed: "+(i instanceof Error?i.message:String(i))});}},disconnect:async n=>{if(!c().disconnecting){r({disconnecting:true});try{if(n){let e=c(),i=e.connections[n];if(!i){console.warn(`No connection found for connector type: ${n}`);return}let t=c().getAdapter(getAdapterFromConnectorType(i.connectorType));if(t)try{await t.disconnect(i);}catch(d){console.error(`Failed to disconnect connector ${n}:`,d);}let a=e.activeConnection?.connectorType===n,s=Object.values(e.connections).filter(d=>d.connectorType!==n),w;if(a&&s.length>0){let d=s[0];try{let C=c().getAdapter(getAdapterFromConnectorType(d.connectorType));C?.switchConnection&&await C.switchConnection(d.connectorType),w=d;}catch(C){console.error("Failed to switch to remaining connector:",C),w=void 0;}}else a||(w=e.activeConnection);r(d=>produce(d,C=>{delete C.connections[n],C.activeConnection=w,C.connectionError=void 0,C.switchNetworkError=void 0;}));}else await c().disconnectAll();let o=c();Object.keys(o.connections).length===0?(lastConnectedConnectorHelpers.removeLastConnectedConnector(),impersonatedHelpers.removeImpersonated()):o.activeConnection&&lastConnectedConnectorHelpers.setLastConnectedConnector({connectorType:o.activeConnection.connectorType,chainId:o.activeConnection.chainId,address:o.activeConnection.address});}catch(o){console.error("Disconnect operation failed:",o),r(e=>produce(e,i=>{i.connectionError=`Disconnect failed: ${o instanceof Error?o.message:String(o)}`;}));}finally{r({disconnecting:false});}}},disconnectAll:async()=>{if(Array.isArray(l))await Promise.allSettled(l.map(async n=>{try{await n.disconnect();}catch{}}));else try{await l.disconnect();}catch{}r({activeConnection:void 0,connections:{},connectionError:void 0,switchNetworkError:void 0}),impersonatedHelpers.removeImpersonated();},resetConnectionError:()=>{r({connectionError:void 0});},updateActiveConnection:n=>{let o=c().activeConnection,e=n.connectorType??o?.connectorType;e?(n.chainId&&e===o?.connectorType&&lastConnectedConnectorHelpers.setLastConnectedConnector({connectorType:e,chainId:n.chainId,address:n.address??o?.address}),r(i=>produce(i,t=>{t.connections[e]&&(t.connections[e]={...t.connections[e],...n},t.activeConnection?.connectorType===e&&(t.activeConnection=t.connections[e]));}))):n.connectorType!==void 0&&n.chainId!==void 0&&n.address!==void 0?(lastConnectedConnectorHelpers.setLastConnectedConnector({connectorType:n.connectorType,chainId:n.chainId,address:n.address}),r(t=>{let a=n;return {activeConnection:a,connections:{...t.connections,[a.connectorType]:a}}})):console.warn("Attempted to set activeConnection with incomplete data while activeConnection was undefined.");},switchConnection:async n=>{let o=c().connections[n];if(!o){console.warn(`No connection found for connector type: ${n}`);return}if(c().activeConnection?.connectorType!==n)try{let e=c().getAdapter(getAdapterFromConnectorType(n));e?.switchConnection&&await e.switchConnection(n),r(i=>produce(i,t=>{t.activeConnection=o;})),lastConnectedConnectorHelpers.setLastConnectedConnector({connectorType:o.connectorType,chainId:o.chainId,address:o.address});}catch(e){console.error("Failed to switch connection:",e);}},switchNetwork:async(n,o)=>{r({switchNetworkError:void 0});let e=o?c().connections[o]:c().activeConnection;if(e){let i=c().getAdapter(getAdapterFromConnectorType(e.connectorType));if(!i){r({switchNetworkError:`No adapter found for active connector type: ${e.connectorType}`});return}try{await i.checkAndSwitchNetwork(n,e.chainId,c().updateActiveConnection);}catch(t){r({switchNetworkError:"Switch network failed: "+(t instanceof Error?t.message:String(t))});}}},resetSwitchNetworkError:()=>r({switchNetworkError:void 0})}))}export{b as createSatelliteConnectStore};
1
+ import {selectAdapterByKey,getAdapterFromConnectorType,lastConnectedConnectorHelpers,impersonatedHelpers,recentlyConnectedConnectorsListHelpers,delay,isSafeApp,OrbitAdapter}from'@tuwaio/orbit-core';import {setAutoFreeze,produce}from'immer';import {createStore}from'zustand/vanilla';function D({adapter:f,callbackAfterConnected:h}){return setAutoFreeze(false),createStore()((r,t)=>({getAdapter:n=>selectAdapterByKey({adapter:f,adapterKey:n}),getConnectors:()=>{let n;return Array.isArray(f)?n=f.map(o=>o.getConnectors()):n=[f.getConnectors()],n.reduce((o,e)=>{let c=e.adapter,i=e.connectors;return {...o,[c]:i}},{})},initializeAutoConnect:async n=>{await delay(null,300),await t().disconnectAll();let o=Date.now()-10080*60*1e3;if(recentlyConnectedConnectorsListHelpers.removeConnectorsOlderThan(o),n){let e=lastConnectedConnectorHelpers.getLastConnectedConnector();e&&!["impersonatedwallet","walletconnect","coinbasewallet","bitgetwallet"].includes(e.connectorType.split(":")[1])&&(await delay(null,100),await t().connect({connectorType:e.connectorType,chainId:e.chainId}));}else if(isSafeApp){await delay(null,100);let e=t().getAdapter(OrbitAdapter.EVM);if(e&&e.getSafeConnectorChainId){let c=await e.getSafeConnectorChainId();c&&await t().connect({connectorType:`${OrbitAdapter.EVM}:safewallet`,chainId:c});}}},connecting:false,disconnecting:false,connectionError:void 0,switchNetworkError:void 0,activeConnection:void 0,connections:{},setConnectionError:n=>r({connectionError:n}),connect:async({connectorType:n,chainId:o})=>{r({connecting:true,connectionError:void 0});let e=t().getAdapter(getAdapterFromConnectorType(n));if(!e){r({connecting:false,connectionError:`No adapter found for connector type: ${n}`});return}try{if(t().connections[n])return;let i=await e.connect({connectorType:n,chainId:o});if(r(s=>({activeConnection:i,connections:{...s.connections,[i.connectorType]:i}})),e.checkIsContractAddress){let s=await e.checkIsContractAddress({address:i.address,chainId:o});t().updateActiveConnection({...i,isContractAddress:s});}if(h){let s=t().activeConnection;s&&s.connectorType===n&&await h(s);}r({connecting:!1}),lastConnectedConnectorHelpers.setLastConnectedConnector({connectorType:n,chainId:o,address:t().activeConnection?.address});let a=t().activeConnection;a&&a.address&&recentlyConnectedConnectorsListHelpers.addConnector(a.connectorType,{address:a.address,disconnectedTimestamp:Date.now(),icon:a.icon});}catch(c){r({connecting:false,connectionError:"Connector connection failed: "+(c instanceof Error?c.message:String(c))});}},disconnect:async n=>{if(!t().disconnecting){r({disconnecting:true});try{if(n){let e=t(),c=e.connections[n];if(!c){console.warn(`No connection found for connector type: ${n}`);return}let i=t().getAdapter(getAdapterFromConnectorType(c.connectorType));if(i)try{await i.disconnect(c);}catch(d){console.error(`Failed to disconnect connector ${n}:`,d);}let a=e.activeConnection?.connectorType===n,s=Object.values(e.connections).filter(d=>d.connectorType!==n),l;if(a&&s.length>0){let d=s[0];try{let C=t().getAdapter(getAdapterFromConnectorType(d.connectorType));C?.switchConnection&&await C.switchConnection(d.connectorType),l=d;}catch(C){console.error("Failed to switch to remaining connector:",C),l=void 0;}}else a||(l=e.activeConnection);r(d=>produce(d,C=>{delete C.connections[n],C.activeConnection=l,C.connectionError=void 0,C.switchNetworkError=void 0;}));}else await t().disconnectAll();let o=t();Object.keys(o.connections).length===0?(lastConnectedConnectorHelpers.removeLastConnectedConnector(),impersonatedHelpers.removeImpersonated()):o.activeConnection&&lastConnectedConnectorHelpers.setLastConnectedConnector({connectorType:o.activeConnection.connectorType,chainId:o.activeConnection.chainId,address:o.activeConnection.address});}catch(o){console.error("Disconnect operation failed:",o),r(e=>produce(e,c=>{c.connectionError=`Disconnect failed: ${o instanceof Error?o.message:String(o)}`;}));}finally{r({disconnecting:false});}}},disconnectAll:async()=>{if(Array.isArray(f))await Promise.allSettled(f.map(async n=>{try{await n.disconnect();}catch{}}));else try{await f.disconnect();}catch{}r({activeConnection:void 0,connections:{},connectionError:void 0,switchNetworkError:void 0}),impersonatedHelpers.removeImpersonated();},resetConnectionError:()=>{r({connectionError:void 0});},updateActiveConnection:n=>{let o=t().activeConnection,e=n.connectorType??o?.connectorType;e?(n.chainId&&e===o?.connectorType&&lastConnectedConnectorHelpers.setLastConnectedConnector({connectorType:e,chainId:n.chainId,address:n.address??o?.address}),r(c=>produce(c,i=>{let a=i.connections[e];if(a){let l={...a,...n};i.connections[e]=l,i.activeConnection?.connectorType===e&&(i.activeConnection=l);}}))):n.connectorType!==void 0&&n.chainId!==void 0&&n.address!==void 0?(lastConnectedConnectorHelpers.setLastConnectedConnector({connectorType:n.connectorType,chainId:n.chainId,address:n.address}),r(i=>{let a=n;return {activeConnection:a,connections:{...i.connections,[a.connectorType]:a}}})):console.warn("Attempted to set activeConnection with incomplete data while activeConnection was undefined.");},switchConnection:async n=>{let o=t().connections[n];if(!o){console.warn(`No connection found for connector type: ${n}`);return}if(t().activeConnection?.connectorType!==n)try{let e=t().getAdapter(getAdapterFromConnectorType(n));e?.switchConnection&&await e.switchConnection(n),r(c=>produce(c,i=>{i.activeConnection=o;})),lastConnectedConnectorHelpers.setLastConnectedConnector({connectorType:o.connectorType,chainId:o.chainId,address:o.address});}catch(e){console.error("Failed to switch connection:",e);}},switchNetwork:async(n,o)=>{r({switchNetworkError:void 0});let e=o?t().connections[o]:t().activeConnection;if(e){let c=t().getAdapter(getAdapterFromConnectorType(e.connectorType));if(!c){r({switchNetworkError:`No adapter found for active connector type: ${e.connectorType}`});return}try{await c.checkAndSwitchNetwork(n,e.chainId,t().updateActiveConnection);}catch(i){r({switchNetworkError:"Switch network failed: "+(i instanceof Error?i.message:String(i))});}}},resetSwitchNetworkError:()=>r({switchNetworkError:void 0})}))}export{D as createSatelliteConnectStore};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tuwaio/satellite-core",
3
- "version": "1.0.0-fix-optimization-alpha.1.d6a8b2d",
3
+ "version": "1.0.0-fix-optimization-alpha.2.80df34b",
4
4
  "private": false,
5
5
  "author": "Oleksandr Tkach",
6
6
  "license": "Apache-2.0",
@@ -45,8 +45,8 @@
45
45
  "zustand": "5.x.x"
46
46
  },
47
47
  "devDependencies": {
48
- "@tuwaio/orbit-core": "^0.2.1",
49
- "immer": "^11.1.0",
48
+ "@tuwaio/orbit-core": "^0.2.2",
49
+ "immer": "^11.1.3",
50
50
  "tsup": "^8.5.1",
51
51
  "typescript": "^5.9.3",
52
52
  "zustand": "^5.0.9"