@tuwaio/satellite-core 1.0.0-fix-watcher-alpha.3.b979b45 → 1.0.0-fix-error-handling-alpha.1.904199
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 +2 -8
- package/dist/index.d.mts +4 -4
- package/dist/index.d.ts +4 -4
- package/dist/index.js +1 -1
- package/dist/index.mjs +1 -1
- package/package.json +3 -3
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,
|
|
2
|
+
import { ConnectorType, OrbitAdapter, BaseAdapter, TuwaErrorState, OrbitGenericAdapter } from '@tuwaio/orbit-core';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Configuration properties for initializing connectors
|
|
@@ -109,9 +109,9 @@ type ISatelliteConnectStore<C, W extends BaseConnector = BaseConnector> = {
|
|
|
109
109
|
/** Indicates ongoing disconnection attempt */
|
|
110
110
|
disconnecting: boolean;
|
|
111
111
|
/** Contains error message if connection failed */
|
|
112
|
-
connectionError?:
|
|
112
|
+
connectionError?: TuwaErrorState;
|
|
113
113
|
/** Sets error message if connection failed or form validation failed */
|
|
114
|
-
setConnectionError: (error:
|
|
114
|
+
setConnectionError: (error: TuwaErrorState) => void;
|
|
115
115
|
/** Currently connected connector */
|
|
116
116
|
activeConnection?: Connector<W>;
|
|
117
117
|
/** List of all connected connectors */
|
|
@@ -125,7 +125,7 @@ type ISatelliteConnectStore<C, W extends BaseConnector = BaseConnector> = {
|
|
|
125
125
|
/** Switches network for connected connector */
|
|
126
126
|
switchNetwork: (chainId: string | number, connectorType?: ConnectorType) => Promise<void>;
|
|
127
127
|
/** Contains error message if network switch failed */
|
|
128
|
-
switchNetworkError?:
|
|
128
|
+
switchNetworkError?: TuwaErrorState;
|
|
129
129
|
/** Clears network switch error state */
|
|
130
130
|
resetSwitchNetworkError: () => void;
|
|
131
131
|
};
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as zustand_vanilla from 'zustand/vanilla';
|
|
2
|
-
import { ConnectorType,
|
|
2
|
+
import { ConnectorType, OrbitAdapter, BaseAdapter, TuwaErrorState, OrbitGenericAdapter } from '@tuwaio/orbit-core';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Configuration properties for initializing connectors
|
|
@@ -109,9 +109,9 @@ type ISatelliteConnectStore<C, W extends BaseConnector = BaseConnector> = {
|
|
|
109
109
|
/** Indicates ongoing disconnection attempt */
|
|
110
110
|
disconnecting: boolean;
|
|
111
111
|
/** Contains error message if connection failed */
|
|
112
|
-
connectionError?:
|
|
112
|
+
connectionError?: TuwaErrorState;
|
|
113
113
|
/** Sets error message if connection failed or form validation failed */
|
|
114
|
-
setConnectionError: (error:
|
|
114
|
+
setConnectionError: (error: TuwaErrorState) => void;
|
|
115
115
|
/** Currently connected connector */
|
|
116
116
|
activeConnection?: Connector<W>;
|
|
117
117
|
/** List of all connected connectors */
|
|
@@ -125,7 +125,7 @@ type ISatelliteConnectStore<C, W extends BaseConnector = BaseConnector> = {
|
|
|
125
125
|
/** Switches network for connected connector */
|
|
126
126
|
switchNetwork: (chainId: string | number, connectorType?: ConnectorType) => Promise<void>;
|
|
127
127
|
/** Contains error message if network switch failed */
|
|
128
|
-
switchNetworkError?:
|
|
128
|
+
switchNetworkError?: TuwaErrorState;
|
|
129
129
|
/** Clears network switch error state */
|
|
130
130
|
resetSwitchNetworkError: () => void;
|
|
131
131
|
};
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
'use strict';var orbitCore=require('@tuwaio/orbit-core'),immer=require('immer'),vanilla=require('zustand/vanilla');function
|
|
1
|
+
'use strict';var orbitCore=require('@tuwaio/orbit-core'),immer=require('immer'),vanilla=require('zustand/vanilla');function b({adapter:f,callbackAfterConnected:v}){return immer.setAutoFreeze(false),vanilla.createStore()((i,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,r=e.connectors;return {...o,[c]:r}},{})},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=>i({connectionError:n}),connect:async({connectorType:n,chainId:o})=>{i({connecting:true,connectionError:void 0});let e=t().getAdapter(orbitCore.getAdapterFromConnectorType(n));if(!e){i({connecting:false,connectionError:orbitCore.normalizeError(new Error(`No adapter found for connector type: ${n}`))});return}try{if(t().connections[n])return;let r=await e.connect({connectorType:n,chainId:o});if(i(s=>({activeConnection:r,connections:{...s.connections,[r.connectorType]:r}})),e.checkIsContractAddress){let s=await e.checkIsContractAddress({address:r.address,chainId:o});t().updateActiveConnection({...r,isContractAddress:s});}if(v){let s=t().activeConnection;s&&s.connectorType===n&&await v(s);}i({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){i({connecting:false,connectionError:orbitCore.normalizeError(c)});}},disconnect:async n=>{if(!t().disconnecting){i({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 r=t().getAdapter(orbitCore.getAdapterFromConnectorType(c.connectorType));if(r)try{await r.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);i(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),i(e=>immer.produce(e,c=>{c.connectionError=orbitCore.normalizeError(o);}));}finally{i({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{}i({activeConnection:void 0,connections:{},connectionError:void 0,switchNetworkError:void 0}),orbitCore.impersonatedHelpers.removeImpersonated();},resetConnectionError:()=>{i({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}),i(c=>immer.produce(c,r=>{let a=r.connections[e];if(a){let l={...a,...n};r.connections[e]=l,r.activeConnection?.connectorType===e&&(r.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}),i(r=>{let a=n;return {activeConnection:a,connections:{...r.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),i(c=>immer.produce(c,r=>{r.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)=>{i({switchNetworkError:void 0});let e=o?t().connections[o]:t().activeConnection;if(e){let c=t().getAdapter(orbitCore.getAdapterFromConnectorType(e.connectorType));if(!c){i({switchNetworkError:orbitCore.normalizeError(new Error(`No adapter found for active connector type: ${e.connectorType}`))});return}try{await c.checkAndSwitchNetwork(n,e.chainId,t().updateActiveConnection);}catch(r){i({switchNetworkError:orbitCore.normalizeError(r)});}}},resetSwitchNetworkError:()=>i({switchNetworkError:void 0})}))}exports.createSatelliteConnectStore=b;
|
package/dist/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {getAdapterFromConnectorType,normalizeError,lastConnectedConnectorHelpers,impersonatedHelpers,recentlyConnectedConnectorsListHelpers,delay,isSafeApp,OrbitAdapter,selectAdapterByKey}from'@tuwaio/orbit-core';import {setAutoFreeze,produce}from'immer';import {createStore}from'zustand/vanilla';function b({adapter:f,callbackAfterConnected:v}){return setAutoFreeze(false),createStore()((i,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,r=e.connectors;return {...o,[c]:r}},{})},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=>i({connectionError:n}),connect:async({connectorType:n,chainId:o})=>{i({connecting:true,connectionError:void 0});let e=t().getAdapter(getAdapterFromConnectorType(n));if(!e){i({connecting:false,connectionError:normalizeError(new Error(`No adapter found for connector type: ${n}`))});return}try{if(t().connections[n])return;let r=await e.connect({connectorType:n,chainId:o});if(i(s=>({activeConnection:r,connections:{...s.connections,[r.connectorType]:r}})),e.checkIsContractAddress){let s=await e.checkIsContractAddress({address:r.address,chainId:o});t().updateActiveConnection({...r,isContractAddress:s});}if(v){let s=t().activeConnection;s&&s.connectorType===n&&await v(s);}i({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){i({connecting:false,connectionError:normalizeError(c)});}},disconnect:async n=>{if(!t().disconnecting){i({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 r=t().getAdapter(getAdapterFromConnectorType(c.connectorType));if(r)try{await r.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);i(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),i(e=>produce(e,c=>{c.connectionError=normalizeError(o);}));}finally{i({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{}i({activeConnection:void 0,connections:{},connectionError:void 0,switchNetworkError:void 0}),impersonatedHelpers.removeImpersonated();},resetConnectionError:()=>{i({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}),i(c=>produce(c,r=>{let a=r.connections[e];if(a){let l={...a,...n};r.connections[e]=l,r.activeConnection?.connectorType===e&&(r.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}),i(r=>{let a=n;return {activeConnection:a,connections:{...r.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),i(c=>produce(c,r=>{r.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)=>{i({switchNetworkError:void 0});let e=o?t().connections[o]:t().activeConnection;if(e){let c=t().getAdapter(getAdapterFromConnectorType(e.connectorType));if(!c){i({switchNetworkError:normalizeError(new Error(`No adapter found for active connector type: ${e.connectorType}`))});return}try{await c.checkAndSwitchNetwork(n,e.chainId,t().updateActiveConnection);}catch(r){i({switchNetworkError:normalizeError(r)});}}},resetSwitchNetworkError:()=>i({switchNetworkError:void 0})}))}export{b as createSatelliteConnectStore};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tuwaio/satellite-core",
|
|
3
|
-
"version": "1.0.0-fix-
|
|
3
|
+
"version": "1.0.0-fix-error-handling-alpha.1.0904199",
|
|
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": "
|
|
48
|
+
"@tuwaio/orbit-core": "1.0.0-fix-errors-handling-alpha.1.d157b2c",
|
|
49
49
|
"immer": "^11.1.3",
|
|
50
50
|
"tsup": "^8.5.1",
|
|
51
51
|
"typescript": "^5.9.3",
|
|
52
|
-
"zustand": "^5.0.
|
|
52
|
+
"zustand": "^5.0.10"
|
|
53
53
|
},
|
|
54
54
|
"scripts": {
|
|
55
55
|
"start": "tsup src/index.ts --watch",
|