@tuwaio/satellite-core 0.2.2 → 0.2.4

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/README.md CHANGED
@@ -31,18 +31,12 @@ Built with TypeScript, it leverages modern tools for state management and type-s
31
31
 
32
32
  ### Requirements
33
33
 
34
- - Node.js 20+
34
+ - Node.js 20-24
35
35
  - TypeScript 5.9+
36
36
 
37
37
  ```bash
38
- # Using pnpm (recommended)
38
+ # Using pnpm (recommended), but you can use npm, yarn or bun as well
39
39
  pnpm add @tuwaio/satellite-core @tuwaio/orbit-core immer zustand
40
-
41
- # Using npm
42
- npm install @tuwaio/satellite-core @tuwaio/orbit-core immer zustand
43
-
44
- # Using yarn
45
- yarn add @tuwaio/satellite-core @tuwaio/orbit-core immer zustand
46
40
  ```
47
41
 
48
42
  ---
package/dist/index.d.mts CHANGED
@@ -1,5 +1,5 @@
1
1
  import * as zustand_vanilla from 'zustand/vanilla';
2
- import { ConnectorType, OrbitGenericAdapter, BaseAdapter, OrbitAdapter } from '@tuwaio/orbit-core';
2
+ import { ConnectorType, OrbitAdapter, BaseAdapter, OrbitGenericAdapter } from '@tuwaio/orbit-core';
3
3
 
4
4
  /**
5
5
  * Configuration properties for initializing connectors
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import * as zustand_vanilla from 'zustand/vanilla';
2
- import { ConnectorType, OrbitGenericAdapter, BaseAdapter, OrbitAdapter } from '@tuwaio/orbit-core';
2
+ import { ConnectorType, OrbitAdapter, BaseAdapter, OrbitGenericAdapter } from '@tuwaio/orbit-core';
3
3
 
4
4
  /**
5
5
  * Configuration properties for initializing connectors
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 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};
1
+ import {getAdapterFromConnectorType,lastConnectedConnectorHelpers,impersonatedHelpers,recentlyConnectedConnectorsListHelpers,delay,isSafeApp,OrbitAdapter,selectAdapterByKey}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": "0.2.2",
3
+ "version": "0.2.4",
4
4
  "private": false,
5
5
  "author": "Oleksandr Tkach",
6
6
  "license": "Apache-2.0",
@@ -45,11 +45,11 @@
45
45
  "zustand": "5.x.x"
46
46
  },
47
47
  "devDependencies": {
48
- "@tuwaio/orbit-core": "^0.2.2",
48
+ "@tuwaio/orbit-core": "^0.2.4",
49
49
  "immer": "^11.1.3",
50
50
  "tsup": "^8.5.1",
51
51
  "typescript": "^5.9.3",
52
- "zustand": "^5.0.9"
52
+ "zustand": "^5.0.10"
53
53
  },
54
54
  "scripts": {
55
55
  "start": "tsup src/index.ts --watch",