@tuwaio/satellite-react 0.6.1 → 0.6.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/README.md CHANGED
@@ -12,6 +12,7 @@
12
12
  - **Provider:** `SatelliteConnectProvider` creates the store once, passes later `adapter` and `callbackAfterConnected` changes to it, and runs `initializeAutoConnect` after mount, so the last connected wallet is restored in the browser.
13
13
  - **Hook:** `useSatelliteConnectStore(selector)` reads a value from the store and re-renders when it changes. `SatelliteStoreContext` gives access to the store itself (`getState`, `subscribe`); it is shared on `globalThis`, so packages that bundle their own copy of `@tuwaio/satellite-react` see the same store.
14
14
  - **Chain watchers:** `EVMConnectorsWatcher` (`/evm`) and `SolanaConnectorsWatcher` (`/solana`) render nothing. They load the watcher of their chain package after mount and copy account and chain changes made in the wallet into the store. With the `siwx` prop, for example the result of `useSiwxSession()` from [`@tuwaio/siwx-react`](https://siwx.docs.tuwa.io/packages/siwx-react), they disconnect the wallet when the sign-in is rejected or fails, or when the wallet moves to another account (or EVM chain) than the session. They restart only when a field of `siwx` changes, not when a new but equal object is passed.
15
+ - **No `WagmiProvider`:** `EVMConnectorsWatcher` hydrates a wagmi config created with `ssr: true` after mount, as `WagmiProvider` from `wagmi` does, so the installed wallets found through EIP-6963 (MetaMask, Rabby…) appear in its connectors. wagmi does not reconnect them: the provider restores the last connection. Add `WagmiProvider` only for the hooks of `wagmi`; the watcher then leaves the hydration to it.
15
16
  - **Typed connections:** importing `/evm` or `/solana` adds the connection types of that chain to `AllConnections` and `AllConnectors`, so `activeConnection` is typed as `EVMConnection | SolanaConnection` in an app that imports both.
16
17
 
17
18
  ---
@@ -84,7 +85,7 @@ export function ActiveAddress() {
84
85
  }
85
86
  ```
86
87
 
87
- Connect a wallet with `useSatelliteConnectStore((state) => state.connect)`. Ready-made connect modals are in Nova Connect ([storybook](https://stories.tuwa.io/)), and a full-stack app with Nova Connect, SIWX and Pulsar is in the **[TUWA SDK documentation](https://sdk.docs.tuwa.io/full-stack)**.
88
+ Connect a wallet with `useSatelliteConnectStore((state) => state.connect)`. Ready-made connect modals are in Nova Connect ([storybook](https://stories.tuwa.io/)), and a full-stack app with Nova Connect, SIWX and Pulsar is in the **[Full-Stack React guide](https://docs.tuwa.io/guides/full-stack-react)**.
88
89
 
89
90
  ---
90
91
 
@@ -92,6 +93,8 @@ Connect a wallet with `useSatelliteConnectStore((state) => state.connect)`. Read
92
93
 
93
94
  The provider's store saves the last connection and the recently connected wallets to `localStorage`, and removes the impersonated address, through `@tuwaio/orbit-core`. The keys, their content and when they change are listed on the [`@tuwaio/satellite-core`](https://satellite.docs.tuwa.io/packages/satellite-core) page. The store state itself is not persisted: server rendering and the first client render start with no connection, and `initializeAutoConnect` restores it after mount (it waits 300 ms and disconnects the wallets of every adapter first). Read `isAutoConnectFinished` from the store before treating a missing connection as a disconnect.
94
95
 
96
+ `EVMConnectorsWatcher` hydrates a wagmi config created with `ssr: true` (unless `WagmiProvider` does): wagmi reads its saved state from the `storage` of the config (`localStorage` by default) and the watcher clears the saved wagmi connections.
97
+
95
98
  ---
96
99
 
97
100
  ## 📚 API Reference
@@ -1 +1 @@
1
- 'use strict';var chunkLSWAATDN_cjs=require('../chunk-LSWAATDN.cjs'),chunkHEG6FP5Z_cjs=require('../chunk-HEG6FP5Z.cjs'),react=require('react'),jsxRuntime=require('react/jsx-runtime');function x({createWatcher:c,wagmiConfig:o,siwx:i,siwe:e}){let n=chunkHEG6FP5Z_cjs.b(t=>t.activeConnection),a=chunkHEG6FP5Z_cjs.b(t=>t.disconnect),s=chunkHEG6FP5Z_cjs.b(t=>t.connectionError),l=chunkHEG6FP5Z_cjs.b(t=>t.updateActiveConnection),C=react.useContext(chunkHEG6FP5Z_cjs.a),p=chunkLSWAATDN_cjs.a(i),d=e!==void 0,f=e?.enabled,u=e?.isSignedIn,S=e?.isRejected,m=react.useMemo(()=>d?{enabled:f,isSignedIn:u,isRejected:S}:void 0,[d,f,u,S]);return react.useEffect(()=>c({wagmiConfig:o,siwx:p,siwe:m},{disconnect:a,updateActiveConnection:l,getState:()=>C?.getState()??{activeConnection:n,connectionError:s}}),[c,C,o,p,m,n?.connectorType,s,a,l]),null}function I(c){let[o,i]=react.useState(null);return react.useEffect(()=>{let e=true;return import('@tuwaio/satellite-evm').then(n=>{e&&i(()=>n.createEVMConnectionsWatcher);}).catch(n=>console.warn("Failed to load EVM watcher:",n)),()=>{e=false;}},[]),o?jsxRuntime.jsx(x,{createWatcher:o,...c}):null}exports.EVMConnectorsWatcher=I;
1
+ 'use strict';var chunkLSWAATDN_cjs=require('../chunk-LSWAATDN.cjs'),chunkHEG6FP5Z_cjs=require('../chunk-HEG6FP5Z.cjs'),core=require('@wagmi/core'),react=require('react'),jsxRuntime=require('react/jsx-runtime');var d=new WeakSet;function g(e){react.useEffect(()=>{let{ssr:o,store:c}=e._internal,{persist:t}=c;if(!o||!t||t.hasHydrated()||d.has(e))return;let n=false,i=t.onHydrate(()=>{n=true;}),s=setTimeout(()=>{i(),!(n||t.hasHydrated()||d.has(e))&&(d.add(e),core.hydrate(e,{reconnectOnMount:false}).onMount().catch(l=>console.warn("Failed to hydrate the wagmi config:",l)));},0);return ()=>{clearTimeout(s),i();}},[e]);}function A({createWatcher:e,wagmiConfig:o,siwx:c,siwe:t}){let n=chunkHEG6FP5Z_cjs.b(r=>r.activeConnection),i=chunkHEG6FP5Z_cjs.b(r=>r.disconnect),s=chunkHEG6FP5Z_cjs.b(r=>r.connectionError),l=chunkHEG6FP5Z_cjs.b(r=>r.updateActiveConnection),p=react.useContext(chunkHEG6FP5Z_cjs.a),C=chunkLSWAATDN_cjs.a(c),f=t!==void 0,h=t?.enabled,S=t?.isSignedIn,m=t?.isRejected,E=react.useMemo(()=>f?{enabled:h,isSignedIn:S,isRejected:m}:void 0,[f,h,S,m]);return react.useEffect(()=>e({wagmiConfig:o,siwx:C,siwe:E},{disconnect:i,updateActiveConnection:l,getState:()=>p?.getState()??{activeConnection:n,connectionError:s}}),[e,p,o,C,E,n?.connectorType,s,i,l]),null}function R(e){let[o,c]=react.useState(null);return g(e.wagmiConfig),react.useEffect(()=>{let t=true;return import('@tuwaio/satellite-evm').then(n=>{t&&c(()=>n.createEVMConnectionsWatcher);}).catch(n=>console.warn("Failed to load EVM watcher:",n)),()=>{t=false;}},[]),o?jsxRuntime.jsx(A,{createWatcher:o,...e}):null}exports.EVMConnectorsWatcher=R;
@@ -10,7 +10,7 @@ import { Config } from '@wagmi/core';
10
10
  interface EVMConnectorsWatcherProps {
11
11
  /**
12
12
  * The wagmi `Config` from `@wagmi/core` that the EVM adapter uses. Its connections are watched with
13
- * `watchConnections`.
13
+ * `watchConnections`. A config created with `ssr: true` is hydrated by the watcher (see {@link EVMConnectorsWatcher}).
14
14
  */
15
15
  wagmiConfig: Config;
16
16
  /**
@@ -42,6 +42,14 @@ interface EVMConnectorsWatcherProps {
42
42
  * matches the signed-in session. The watcher restarts when `wagmiConfig`, a field of `siwx`, the active connector or
43
43
  * the connection error changes, and stops on unmount. If the import fails, a warning is logged and nothing is watched.
44
44
  *
45
+ * A `wagmiConfig` created with `ssr: true` is hydrated by the watcher, so no `WagmiProvider` from `wagmi` is needed:
46
+ * until such a config is hydrated, wagmi does not add the installed wallets found through EIP-6963 (MetaMask, Rabby…)
47
+ * to its connectors. One task after mount, unless the config is already hydrating (for example in a `WagmiProvider`
48
+ * around the app), the watcher calls `hydrate(wagmiConfig, { reconnectOnMount: false }).onMount()` from `@wagmi/core`
49
+ * once per config. It reads the saved wagmi state from the `storage` of the config (`localStorage` by default), adds
50
+ * the EIP-6963 wallets and clears the saved wagmi connections; the last wallet is reconnected by
51
+ * `SatelliteConnectProvider`, not by wagmi. If the hydration fails, a warning is logged.
52
+ *
45
53
  * @param props - The component props. See {@link EVMConnectorsWatcherProps}.
46
54
  * @returns `null`; the component renders nothing.
47
55
  *
@@ -10,7 +10,7 @@ import { Config } from '@wagmi/core';
10
10
  interface EVMConnectorsWatcherProps {
11
11
  /**
12
12
  * The wagmi `Config` from `@wagmi/core` that the EVM adapter uses. Its connections are watched with
13
- * `watchConnections`.
13
+ * `watchConnections`. A config created with `ssr: true` is hydrated by the watcher (see {@link EVMConnectorsWatcher}).
14
14
  */
15
15
  wagmiConfig: Config;
16
16
  /**
@@ -42,6 +42,14 @@ interface EVMConnectorsWatcherProps {
42
42
  * matches the signed-in session. The watcher restarts when `wagmiConfig`, a field of `siwx`, the active connector or
43
43
  * the connection error changes, and stops on unmount. If the import fails, a warning is logged and nothing is watched.
44
44
  *
45
+ * A `wagmiConfig` created with `ssr: true` is hydrated by the watcher, so no `WagmiProvider` from `wagmi` is needed:
46
+ * until such a config is hydrated, wagmi does not add the installed wallets found through EIP-6963 (MetaMask, Rabby…)
47
+ * to its connectors. One task after mount, unless the config is already hydrating (for example in a `WagmiProvider`
48
+ * around the app), the watcher calls `hydrate(wagmiConfig, { reconnectOnMount: false }).onMount()` from `@wagmi/core`
49
+ * once per config. It reads the saved wagmi state from the `storage` of the config (`localStorage` by default), adds
50
+ * the EIP-6963 wallets and clears the saved wagmi connections; the last wallet is reconnected by
51
+ * `SatelliteConnectProvider`, not by wagmi. If the hydration fails, a warning is logged.
52
+ *
45
53
  * @param props - The component props. See {@link EVMConnectorsWatcherProps}.
46
54
  * @returns `null`; the component renders nothing.
47
55
  *
package/dist/evm/index.js CHANGED
@@ -1 +1 @@
1
- import {a as a$1}from'../chunk-FBHCKH6M.js';import {b,a}from'../chunk-4A4PSLAK.js';import {useState,useEffect,useContext,useMemo}from'react';import {jsx}from'react/jsx-runtime';function g({createWatcher:c,wagmiConfig:o,siwx:i,siwe:e}){let n=b(t=>t.activeConnection),a$2=b(t=>t.disconnect),s=b(t=>t.connectionError),l=b(t=>t.updateActiveConnection),C=useContext(a),p=a$1(i),d=e!==void 0,f=e?.enabled,u=e?.isSignedIn,S=e?.isRejected,m=useMemo(()=>d?{enabled:f,isSignedIn:u,isRejected:S}:void 0,[d,f,u,S]);return useEffect(()=>c({wagmiConfig:o,siwx:p,siwe:m},{disconnect:a$2,updateActiveConnection:l,getState:()=>C?.getState()??{activeConnection:n,connectionError:s}}),[c,C,o,p,m,n?.connectorType,s,a$2,l]),null}function R(c){let[o,i]=useState(null);return useEffect(()=>{let e=true;return import('@tuwaio/satellite-evm').then(n=>{e&&i(()=>n.createEVMConnectionsWatcher);}).catch(n=>console.warn("Failed to load EVM watcher:",n)),()=>{e=false;}},[]),o?jsx(g,{createWatcher:o,...c}):null}export{R as EVMConnectorsWatcher};
1
+ import {a as a$1}from'../chunk-FBHCKH6M.js';import {b,a}from'../chunk-4A4PSLAK.js';import {hydrate}from'@wagmi/core';import {useState,useEffect,useContext,useMemo}from'react';import {jsx}from'react/jsx-runtime';var d=new WeakSet;function A(e){useEffect(()=>{let{ssr:o,store:c}=e._internal,{persist:t}=c;if(!o||!t||t.hasHydrated()||d.has(e))return;let n=false,i=t.onHydrate(()=>{n=true;}),s=setTimeout(()=>{i(),!(n||t.hasHydrated()||d.has(e))&&(d.add(e),hydrate(e,{reconnectOnMount:false}).onMount().catch(l=>console.warn("Failed to hydrate the wagmi config:",l)));},0);return ()=>{clearTimeout(s),i();}},[e]);}function v({createWatcher:e,wagmiConfig:o,siwx:c,siwe:t}){let n=b(r=>r.activeConnection),i=b(r=>r.disconnect),s=b(r=>r.connectionError),l=b(r=>r.updateActiveConnection),p=useContext(a),C=a$1(c),f=t!==void 0,h=t?.enabled,S=t?.isSignedIn,m=t?.isRejected,E=useMemo(()=>f?{enabled:h,isSignedIn:S,isRejected:m}:void 0,[f,h,S,m]);return useEffect(()=>e({wagmiConfig:o,siwx:C,siwe:E},{disconnect:i,updateActiveConnection:l,getState:()=>p?.getState()??{activeConnection:n,connectionError:s}}),[e,p,o,C,E,n?.connectorType,s,i,l]),null}function j(e){let[o,c]=useState(null);return A(e.wagmiConfig),useEffect(()=>{let t=true;return import('@tuwaio/satellite-evm').then(n=>{t&&c(()=>n.createEVMConnectionsWatcher);}).catch(n=>console.warn("Failed to load EVM watcher:",n)),()=>{t=false;}},[]),o?jsx(v,{createWatcher:o,...e}):null}export{j as EVMConnectorsWatcher};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tuwaio/satellite-react",
3
- "version": "0.6.1",
3
+ "version": "0.6.3",
4
4
  "private": false,
5
5
  "author": "Oleksandr Tkach",
6
6
  "license": "Apache-2.0",
@@ -93,14 +93,14 @@
93
93
  "devDependencies": {
94
94
  "@types/react": "^19.3.0",
95
95
  "@tuwaio/orbit-core": "^0.3.1",
96
- "@tuwaio/satellite-core": "^0.6.1",
97
- "@tuwaio/satellite-evm": "^0.6.0",
98
- "@tuwaio/satellite-solana": "^0.6.0",
96
+ "@tuwaio/satellite-core": "^0.6.2",
97
+ "@tuwaio/satellite-evm": "^0.6.2",
98
+ "@tuwaio/satellite-solana": "^0.6.1",
99
99
  "@wagmi/core": "^3.6.5",
100
100
  "@wallet-standard/react": "^1.0.3",
101
101
  "react": "^19.3.0",
102
102
  "tsup": "^8.5.1",
103
- "viem": "^2.56.9",
103
+ "viem": "^2.57.1",
104
104
  "typescript": "6.0.3",
105
105
  "zustand": "^5.0.15"
106
106
  },