@tuwaio/satellite-core 0.3.1 → 0.3.3
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 +3 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.js +1 -1
- package/dist/index.mjs +1 -1
- package/package.json +6 -6
package/dist/index.d.mts
CHANGED
|
@@ -128,6 +128,8 @@ type ISatelliteConnectStore<C, W extends BaseConnector = BaseConnector> = {
|
|
|
128
128
|
switchNetworkError?: TuwaErrorState;
|
|
129
129
|
/** Clears network switch error state */
|
|
130
130
|
resetSwitchNetworkError: () => void;
|
|
131
|
+
/** Updates store initialization parameters dynamically */
|
|
132
|
+
updateParameters: (parameters: SatelliteConnectStoreInitialParameters<C, W>) => void;
|
|
131
133
|
};
|
|
132
134
|
/**
|
|
133
135
|
* Callback type for successful connections
|
|
@@ -150,6 +152,6 @@ type SatelliteConnectStoreInitialParameters<C, W extends BaseConnector = BaseCon
|
|
|
150
152
|
*
|
|
151
153
|
* @returns A Zustand store instance with connection state and methods
|
|
152
154
|
*/
|
|
153
|
-
declare function createSatelliteConnectStore<C, W extends BaseConnector = BaseConnector>(
|
|
155
|
+
declare function createSatelliteConnectStore<C, W extends BaseConnector = BaseConnector>(params: SatelliteConnectStoreInitialParameters<C, W>): zustand_vanilla.StoreApi<ISatelliteConnectStore<C, W>>;
|
|
154
156
|
|
|
155
157
|
export { type BaseConnector, type ConnectedCallback, type Connector, type ConnectorsInitProps, type ISatelliteConnectStore, type SatelliteAdapter, type SatelliteConnectStoreInitialParameters, createSatelliteConnectStore };
|
package/dist/index.d.ts
CHANGED
|
@@ -128,6 +128,8 @@ type ISatelliteConnectStore<C, W extends BaseConnector = BaseConnector> = {
|
|
|
128
128
|
switchNetworkError?: TuwaErrorState;
|
|
129
129
|
/** Clears network switch error state */
|
|
130
130
|
resetSwitchNetworkError: () => void;
|
|
131
|
+
/** Updates store initialization parameters dynamically */
|
|
132
|
+
updateParameters: (parameters: SatelliteConnectStoreInitialParameters<C, W>) => void;
|
|
131
133
|
};
|
|
132
134
|
/**
|
|
133
135
|
* Callback type for successful connections
|
|
@@ -150,6 +152,6 @@ type SatelliteConnectStoreInitialParameters<C, W extends BaseConnector = BaseCon
|
|
|
150
152
|
*
|
|
151
153
|
* @returns A Zustand store instance with connection state and methods
|
|
152
154
|
*/
|
|
153
|
-
declare function createSatelliteConnectStore<C, W extends BaseConnector = BaseConnector>(
|
|
155
|
+
declare function createSatelliteConnectStore<C, W extends BaseConnector = BaseConnector>(params: SatelliteConnectStoreInitialParameters<C, W>): zustand_vanilla.StoreApi<ISatelliteConnectStore<C, W>>;
|
|
154
156
|
|
|
155
157
|
export { type BaseConnector, type ConnectedCallback, type Connector, type ConnectorsInitProps, type ISatelliteConnectStore, type SatelliteAdapter, type SatelliteConnectStoreInitialParameters, createSatelliteConnectStore };
|
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 L(T){return immer.setAutoFreeze(false),vanilla.createStore()((i,o)=>{let d=T;return {updateParameters:n=>{d=n;},getAdapter:n=>orbitCore.selectAdapterByKey({adapter:d.adapter,adapterKey:n}),getConnectors:()=>{let n;return Array.isArray(d.adapter)?n=d.adapter.map(t=>t.getConnectors()):n=[d.adapter.getConnectors()],n.reduce((t,e)=>{let c=e.adapter,r=e.connectors;return {...t,[c]:r}},{})},initializeAutoConnect:async n=>{await orbitCore.delay(null,300),await o().disconnectAll();let t=Date.now()-10080*60*1e3;if(orbitCore.recentlyConnectedConnectorsListHelpers.removeConnectorsOlderThan(t),n){let e=orbitCore.lastConnectedConnectorHelpers.getLastConnectedConnector();e&&!["impersonatedwallet","walletconnect","coinbasewallet","bitgetwallet"].includes(e.connectorType.split(":")[1])&&(await orbitCore.delay(null,100),await o().connect({connectorType:e.connectorType,chainId:e.chainId}));}else if(orbitCore.isSafeApp){await orbitCore.delay(null,100);let e=o().getAdapter(orbitCore.OrbitAdapter.EVM);if(e&&e.getSafeConnectorChainId){let c=await e.getSafeConnectorChainId();c&&await o().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:t})=>{i({connecting:true,connectionError:void 0});let e=o().getAdapter(orbitCore.getAdapterFromConnectorType(n));if(!e){i({connecting:false,connectionError:orbitCore.normalizeError(new Error(`No adapter found for connector type: ${n}`))});return}try{if(o().connections[n])return;let r=await e.connect({connectorType:n,chainId:t});if(i(s=>({activeConnection:r,connections:{...s.connections,[r.connectorType]:r}})),e.checkIsContractAddress){let s=await e.checkIsContractAddress({address:r.address,chainId:t});o().updateActiveConnection({...r,isContractAddress:s});}if(d.callbackAfterConnected){let s=o().activeConnection;s&&s.connectorType===n&&await d.callbackAfterConnected(s);}i({connecting:!1}),orbitCore.lastConnectedConnectorHelpers.setLastConnectedConnector({connectorType:n,chainId:t,address:o().activeConnection?.address});let a=o().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(!o().disconnecting){i({disconnecting:true});try{if(n){let e=o(),c=e.connections[n];if(!c){console.warn(`No connection found for connector type: ${n}`);return}let r=o().getAdapter(orbitCore.getAdapterFromConnectorType(c.connectorType));if(r)try{await r.disconnect(c);}catch(C){console.error(`Failed to disconnect connector ${n}:`,C);}let a=e.activeConnection?.connectorType===n,s=Object.values(e.connections).filter(C=>C.connectorType!==n),f;if(a&&s.length>0){let C=s[0];try{let l=o().getAdapter(orbitCore.getAdapterFromConnectorType(C.connectorType));l?.switchConnection&&await l.switchConnection(C.connectorType),f=C;}catch(l){console.error("Failed to switch to remaining connector:",l),f=void 0;}}else a||(f=e.activeConnection);i(C=>immer.produce(C,l=>{delete l.connections[n],l.activeConnection=f,l.connectionError=void 0,l.switchNetworkError=void 0;}));}else await o().disconnectAll();let t=o();Object.keys(t.connections).length===0?(orbitCore.lastConnectedConnectorHelpers.removeLastConnectedConnector(),orbitCore.impersonatedHelpers.removeImpersonated()):t.activeConnection&&orbitCore.lastConnectedConnectorHelpers.setLastConnectedConnector({connectorType:t.activeConnection.connectorType,chainId:t.activeConnection.chainId,address:t.activeConnection.address});}catch(t){console.error("Disconnect operation failed:",t),i(e=>immer.produce(e,c=>{c.connectionError=orbitCore.normalizeError(t);}));}finally{i({disconnecting:false});}}},disconnectAll:async()=>{if(Array.isArray(d.adapter))await Promise.allSettled(d.adapter.map(async n=>{try{await n.disconnect();}catch{}}));else try{await d.adapter.disconnect();}catch{}i({activeConnection:void 0,connections:{},connectionError:void 0,switchNetworkError:void 0}),orbitCore.impersonatedHelpers.removeImpersonated();},resetConnectionError:()=>{i({connectionError:void 0});},updateActiveConnection:n=>{let t=o().activeConnection,e=n.connectorType??t?.connectorType;e?(n.chainId&&e===t?.connectorType&&orbitCore.lastConnectedConnectorHelpers.setLastConnectedConnector({connectorType:e,chainId:n.chainId,address:n.address??t?.address}),i(c=>immer.produce(c,r=>{let a=r.connections[e];if(a){let f={...a,...n};r.connections[e]=f,r.activeConnection?.connectorType===e&&(r.activeConnection=f);}}))):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 t=o().connections[n];if(!t){console.warn(`No connection found for connector type: ${n}`);return}if(o().activeConnection?.connectorType!==n)try{let e=o().getAdapter(orbitCore.getAdapterFromConnectorType(n));e?.switchConnection&&await e.switchConnection(n),i(c=>immer.produce(c,r=>{r.activeConnection=t;})),orbitCore.lastConnectedConnectorHelpers.setLastConnectedConnector({connectorType:t.connectorType,chainId:t.chainId,address:t.address});}catch(e){console.error("Failed to switch connection:",e);}},switchNetwork:async(n,t)=>{i({switchNetworkError:void 0});let e=t?o().connections[t]:o().activeConnection;if(e){let c=o().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,o().updateActiveConnection);}catch(r){i({switchNetworkError:orbitCore.normalizeError(r)});}}},resetSwitchNetworkError:()=>i({switchNetworkError:void 0})}})}exports.createSatelliteConnectStore=L;
|
package/dist/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
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
|
|
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 L(T){return setAutoFreeze(false),createStore()((i,o)=>{let d=T;return {updateParameters:n=>{d=n;},getAdapter:n=>selectAdapterByKey({adapter:d.adapter,adapterKey:n}),getConnectors:()=>{let n;return Array.isArray(d.adapter)?n=d.adapter.map(t=>t.getConnectors()):n=[d.adapter.getConnectors()],n.reduce((t,e)=>{let c=e.adapter,r=e.connectors;return {...t,[c]:r}},{})},initializeAutoConnect:async n=>{await delay(null,300),await o().disconnectAll();let t=Date.now()-10080*60*1e3;if(recentlyConnectedConnectorsListHelpers.removeConnectorsOlderThan(t),n){let e=lastConnectedConnectorHelpers.getLastConnectedConnector();e&&!["impersonatedwallet","walletconnect","coinbasewallet","bitgetwallet"].includes(e.connectorType.split(":")[1])&&(await delay(null,100),await o().connect({connectorType:e.connectorType,chainId:e.chainId}));}else if(isSafeApp){await delay(null,100);let e=o().getAdapter(OrbitAdapter.EVM);if(e&&e.getSafeConnectorChainId){let c=await e.getSafeConnectorChainId();c&&await o().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:t})=>{i({connecting:true,connectionError:void 0});let e=o().getAdapter(getAdapterFromConnectorType(n));if(!e){i({connecting:false,connectionError:normalizeError(new Error(`No adapter found for connector type: ${n}`))});return}try{if(o().connections[n])return;let r=await e.connect({connectorType:n,chainId:t});if(i(s=>({activeConnection:r,connections:{...s.connections,[r.connectorType]:r}})),e.checkIsContractAddress){let s=await e.checkIsContractAddress({address:r.address,chainId:t});o().updateActiveConnection({...r,isContractAddress:s});}if(d.callbackAfterConnected){let s=o().activeConnection;s&&s.connectorType===n&&await d.callbackAfterConnected(s);}i({connecting:!1}),lastConnectedConnectorHelpers.setLastConnectedConnector({connectorType:n,chainId:t,address:o().activeConnection?.address});let a=o().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(!o().disconnecting){i({disconnecting:true});try{if(n){let e=o(),c=e.connections[n];if(!c){console.warn(`No connection found for connector type: ${n}`);return}let r=o().getAdapter(getAdapterFromConnectorType(c.connectorType));if(r)try{await r.disconnect(c);}catch(C){console.error(`Failed to disconnect connector ${n}:`,C);}let a=e.activeConnection?.connectorType===n,s=Object.values(e.connections).filter(C=>C.connectorType!==n),f;if(a&&s.length>0){let C=s[0];try{let l=o().getAdapter(getAdapterFromConnectorType(C.connectorType));l?.switchConnection&&await l.switchConnection(C.connectorType),f=C;}catch(l){console.error("Failed to switch to remaining connector:",l),f=void 0;}}else a||(f=e.activeConnection);i(C=>produce(C,l=>{delete l.connections[n],l.activeConnection=f,l.connectionError=void 0,l.switchNetworkError=void 0;}));}else await o().disconnectAll();let t=o();Object.keys(t.connections).length===0?(lastConnectedConnectorHelpers.removeLastConnectedConnector(),impersonatedHelpers.removeImpersonated()):t.activeConnection&&lastConnectedConnectorHelpers.setLastConnectedConnector({connectorType:t.activeConnection.connectorType,chainId:t.activeConnection.chainId,address:t.activeConnection.address});}catch(t){console.error("Disconnect operation failed:",t),i(e=>produce(e,c=>{c.connectionError=normalizeError(t);}));}finally{i({disconnecting:false});}}},disconnectAll:async()=>{if(Array.isArray(d.adapter))await Promise.allSettled(d.adapter.map(async n=>{try{await n.disconnect();}catch{}}));else try{await d.adapter.disconnect();}catch{}i({activeConnection:void 0,connections:{},connectionError:void 0,switchNetworkError:void 0}),impersonatedHelpers.removeImpersonated();},resetConnectionError:()=>{i({connectionError:void 0});},updateActiveConnection:n=>{let t=o().activeConnection,e=n.connectorType??t?.connectorType;e?(n.chainId&&e===t?.connectorType&&lastConnectedConnectorHelpers.setLastConnectedConnector({connectorType:e,chainId:n.chainId,address:n.address??t?.address}),i(c=>produce(c,r=>{let a=r.connections[e];if(a){let f={...a,...n};r.connections[e]=f,r.activeConnection?.connectorType===e&&(r.activeConnection=f);}}))):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 t=o().connections[n];if(!t){console.warn(`No connection found for connector type: ${n}`);return}if(o().activeConnection?.connectorType!==n)try{let e=o().getAdapter(getAdapterFromConnectorType(n));e?.switchConnection&&await e.switchConnection(n),i(c=>produce(c,r=>{r.activeConnection=t;})),lastConnectedConnectorHelpers.setLastConnectedConnector({connectorType:t.connectorType,chainId:t.chainId,address:t.address});}catch(e){console.error("Failed to switch connection:",e);}},switchNetwork:async(n,t)=>{i({switchNetworkError:void 0});let e=t?o().connections[t]:o().activeConnection;if(e){let c=o().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,o().updateActiveConnection);}catch(r){i({switchNetworkError:normalizeError(r)});}}},resetSwitchNetworkError:()=>i({switchNetworkError:void 0})}})}export{L as createSatelliteConnectStore};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tuwaio/satellite-core",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.3",
|
|
4
4
|
"private": false,
|
|
5
5
|
"author": "Oleksandr Tkach",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -40,16 +40,16 @@
|
|
|
40
40
|
}
|
|
41
41
|
],
|
|
42
42
|
"peerDependencies": {
|
|
43
|
-
"@tuwaio/orbit-core": ">=0.2.
|
|
43
|
+
"@tuwaio/orbit-core": ">=0.2.8",
|
|
44
44
|
"immer": "11.x.x",
|
|
45
45
|
"zustand": "5.x.x"
|
|
46
46
|
},
|
|
47
47
|
"devDependencies": {
|
|
48
|
-
"@tuwaio/orbit-core": "^0.2.
|
|
49
|
-
"immer": "^11.1.
|
|
48
|
+
"@tuwaio/orbit-core": "^0.2.8",
|
|
49
|
+
"immer": "^11.1.8",
|
|
50
50
|
"tsup": "^8.5.1",
|
|
51
|
-
"typescript": "^
|
|
52
|
-
"zustand": "^5.0.
|
|
51
|
+
"typescript": "^6.0.3",
|
|
52
|
+
"zustand": "^5.0.13"
|
|
53
53
|
},
|
|
54
54
|
"scripts": {
|
|
55
55
|
"start": "tsup src/index.ts --watch",
|