@tuwaio/satellite-react 0.5.0 → 0.6.0
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 +53 -107
- package/dist/{chunk-EYVLQZ24.js → chunk-4A4PSLAK.js} +1 -1
- package/dist/chunk-FBHCKH6M.js +1 -0
- package/dist/{chunk-G2YC6JBO.cjs → chunk-HEG6FP5Z.cjs} +1 -1
- package/dist/chunk-LSWAATDN.cjs +1 -0
- package/dist/evm/index.cjs +1 -1
- package/dist/evm/index.d.cts +34 -17
- package/dist/evm/index.d.ts +34 -17
- package/dist/evm/index.js +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +103 -73
- package/dist/index.d.ts +103 -73
- package/dist/index.js +1 -1
- package/dist/solana/index.cjs +1 -1
- package/dist/solana/index.d.cts +24 -13
- package/dist/solana/index.d.ts +24 -13
- package/dist/solana/index.js +1 -1
- package/package.json +19 -64
- package/dist/chunk-UDS7MUYZ.js +0 -1
- package/dist/chunk-YTP4ADBV.cjs +0 -1
package/README.md
CHANGED
|
@@ -1,157 +1,103 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @tuwaio/satellite-react
|
|
2
2
|
|
|
3
3
|
[](https://www.npmjs.com/package/@tuwaio/satellite-react)
|
|
4
|
-
[](
|
|
5
|
-
[](https://github.com/TuwaIO/satellite-connect/actions)
|
|
4
|
+
[](https://github.com/TuwaIO/satellite-connect/blob/main/packages/satellite-react/LICENSE)
|
|
6
5
|
|
|
7
|
-
React
|
|
6
|
+
`@tuwaio/satellite-react` is the React Layer 4 (L4) package of **Satellite Connect**, the wallet connection project of TUWA Stage 2 ("State & Connection", next to Pulsar). Built on **`react`**, **`zustand`** and [`@tuwaio/satellite-core`](https://satellite.docs.tuwa.io/packages/satellite-core), it provides a provider that creates the connection store, a hook to read it in components, and one headless watcher component per chain that keeps the store in sync with the wallets. It has no UI components: wallet modals and buttons live in Nova Connect.
|
|
8
7
|
|
|
9
8
|
---
|
|
10
9
|
|
|
11
|
-
## 🏛️
|
|
10
|
+
## 🏛️ Core Capabilities
|
|
12
11
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
Built on top of `@tuwaio/satellite-core`, this package offers a seamless developer experience for React applications requiring Web3 wallet integration.
|
|
18
|
-
|
|
19
|
-
---
|
|
20
|
-
|
|
21
|
-
## ✨ Key Features
|
|
22
|
-
|
|
23
|
-
- **Type Safety:** Full TypeScript support with proper type definitions
|
|
24
|
-
- **Chain Agnostic:** Unified support for both EVM and Solana wallets
|
|
25
|
-
- **Modern React:** Built with React 19+ features and best practices
|
|
26
|
-
- **Multi-Chain Support:** Seamless integration with multiple blockchain networks
|
|
27
|
-
- **State Management:** Zustand-based store for efficient state handling
|
|
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
|
+
- **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
|
+
- **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
|
+
- **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.
|
|
28
16
|
|
|
29
17
|
---
|
|
30
18
|
|
|
31
19
|
## 💾 Installation
|
|
32
20
|
|
|
33
|
-
|
|
21
|
+
The package has three entry points. Install the peer dependencies of the ones you import:
|
|
34
22
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
-
|
|
23
|
+
| Import path | Provides | Peer dependencies to install |
|
|
24
|
+
| -------------------------------- | ---------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------- |
|
|
25
|
+
| `@tuwaio/satellite-react` | `SatelliteConnectProvider`, `useSatelliteConnectStore`, context, types | `@tuwaio/satellite-core` (>=0.5), `react` (>=19.2.3), `zustand` (5.x) |
|
|
26
|
+
| `@tuwaio/satellite-react/evm` | `EVMConnectorsWatcher` | Also `@tuwaio/satellite-evm` (>=0.5), `@wagmi/core` (3.x) and `@tuwaio/orbit-core` (>=0.3) |
|
|
27
|
+
| `@tuwaio/satellite-react/solana` | `SolanaConnectorsWatcher` | Also `@tuwaio/satellite-solana` (>=0.5), `@wallet-standard/react` (1.x) and `@tuwaio/orbit-core` (>=0.3) |
|
|
28
|
+
|
|
29
|
+
The `/evm` and `/solana` peer dependencies are optional, so an EVM-only app does not install Solana packages. The chain packages bring their own peer dependencies, and `@tuwaio/satellite-core` needs `@tuwaio/orbit-core` and `immer`:
|
|
38
30
|
|
|
39
31
|
```bash
|
|
40
|
-
#
|
|
32
|
+
# @tuwaio/satellite-react
|
|
41
33
|
pnpm add @tuwaio/satellite-react @tuwaio/satellite-core @tuwaio/orbit-core react zustand immer
|
|
42
34
|
|
|
43
|
-
#
|
|
35
|
+
# @tuwaio/satellite-react/evm
|
|
44
36
|
pnpm add @tuwaio/satellite-evm @tuwaio/orbit-evm @wagmi/core viem
|
|
45
37
|
|
|
46
|
-
#
|
|
47
|
-
pnpm add @tuwaio/satellite-solana @tuwaio/orbit-solana @solana/kit @wallet-standard/react
|
|
48
|
-
|
|
49
|
-
# 4. SIWX Authentication Integration (Optional)
|
|
50
|
-
pnpm add @tuwaio/siwx-core @tuwaio/siwx-react
|
|
38
|
+
# @tuwaio/satellite-react/solana
|
|
39
|
+
pnpm add @tuwaio/satellite-solana @tuwaio/orbit-solana @solana/kit @wallet-standard/react @wallet-standard/base @wallet-standard/features @wallet-standard/ui @wallet-standard/ui-registry @wallet-standard/app @wallet-standard/ui-core react-dom
|
|
51
40
|
```
|
|
52
41
|
|
|
53
42
|
---
|
|
54
43
|
|
|
55
|
-
## 🚀
|
|
44
|
+
## 🚀 Usage
|
|
56
45
|
|
|
57
|
-
|
|
46
|
+
Render the provider and the watchers once, around your app:
|
|
58
47
|
|
|
59
48
|
```tsx
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
import {
|
|
49
|
+
'use client';
|
|
50
|
+
|
|
51
|
+
import { satelliteEVMAdapter } from '@tuwaio/satellite-evm';
|
|
52
|
+
import { SatelliteConnectProvider, useSatelliteConnectStore } from '@tuwaio/satellite-react';
|
|
63
53
|
import { EVMConnectorsWatcher } from '@tuwaio/satellite-react/evm';
|
|
64
54
|
import { SolanaConnectorsWatcher } from '@tuwaio/satellite-react/solana';
|
|
65
55
|
import { satelliteSolanaAdapter } from '@tuwaio/satellite-solana';
|
|
66
|
-
import { WagmiProvider } from 'wagmi';
|
|
67
|
-
import { ReactNode } from 'react';
|
|
68
|
-
import { createConfig } from '@wagmi/core';
|
|
69
|
-
import { injected } from '@wagmi/connectors';
|
|
70
|
-
import { mainnet, sepolia } from 'viem/chains';
|
|
71
|
-
import type { Chain } from 'viem/chains';
|
|
72
|
-
|
|
73
|
-
export const appEVMChains = [mainnet, sepolia] as readonly [Chain, ...Chain[]];
|
|
74
|
-
|
|
75
|
-
export const wagmiConfig = createConfig({
|
|
76
|
-
connectors: [injected()],
|
|
77
|
-
transports: createDefaultTransports(appEVMChains), // Automatically creates http transports
|
|
78
|
-
chains: appEVMChains,
|
|
79
|
-
ssr: true, // Enable SSR support if needed (e.g., in Next.js)
|
|
80
|
-
});
|
|
81
|
-
|
|
82
|
-
export const solanaRPCUrls = {
|
|
83
|
-
devnet: 'https://api.devnet.solana.com',
|
|
84
|
-
};
|
|
85
|
-
|
|
86
|
-
const queryClient = new QueryClient();
|
|
87
|
-
|
|
88
|
-
export function Providers({ children }: { children: ReactNode }) {
|
|
89
|
-
return (
|
|
90
|
-
<WagmiProvider config={wagmiConfig}>
|
|
91
|
-
<QueryClientProvider client={queryClient}>
|
|
92
|
-
<SatelliteConnectProvider
|
|
93
|
-
adapter={[satelliteEVMAdapter(wagmiConfig, appEVMChains), satelliteSolanaAdapter({ rpcUrls: solanaRPCUrls })]}
|
|
94
|
-
autoConnect={true}
|
|
95
|
-
>
|
|
96
|
-
<EVMConnectorsWatcher wagmiConfig={wagmiConfig} />
|
|
97
|
-
<SolanaConnectorsWatcher />
|
|
98
|
-
{children}
|
|
99
|
-
</SatelliteConnectProvider>
|
|
100
|
-
</QueryClientProvider>
|
|
101
|
-
</WagmiProvider>
|
|
102
|
-
);
|
|
103
|
-
}
|
|
104
|
-
```
|
|
105
|
-
|
|
106
|
-
### Using Hooks
|
|
107
|
-
|
|
108
|
-
```tsx
|
|
109
|
-
import { useSatelliteConnectStore } from '@tuwaio/satellite-react';
|
|
110
|
-
|
|
111
|
-
function ExampleGettingActiveWalletFromStore() {
|
|
112
|
-
const activeConnection = useSatelliteConnectStore((state) => state.activeConnection);
|
|
113
|
-
return <div>{activeConnection?.address}</div>;
|
|
114
|
-
}
|
|
115
|
-
```
|
|
116
|
-
|
|
117
|
-
---
|
|
118
|
-
|
|
119
|
-
## 🔐 Sign-In With X (SIWX) Integration
|
|
120
|
-
|
|
121
|
-
The `EVMConnectorsWatcher` and `SolanaConnectorsWatcher` components accept the `siwx` session state from `@tuwaio/siwx-react`. The watchers automatically monitor connection parity and disconnect the wallet if account switching occurs without a matching session, or if the user rejects signing:
|
|
122
|
-
|
|
123
|
-
```tsx
|
|
124
56
|
import { useSiwxSession } from '@tuwaio/siwx-react';
|
|
125
|
-
import {
|
|
126
|
-
import {
|
|
127
|
-
import {
|
|
57
|
+
import { createConfig, http, injected } from '@wagmi/core';
|
|
58
|
+
import type { ReactNode } from 'react';
|
|
59
|
+
import { mainnet } from 'viem/chains';
|
|
60
|
+
|
|
61
|
+
const appChains = [mainnet] as const;
|
|
62
|
+
const wagmiConfig = createConfig({ chains: appChains, connectors: [injected()], transports: { [mainnet.id]: http() } });
|
|
63
|
+
const adapters = [
|
|
64
|
+
satelliteEVMAdapter(wagmiConfig, appChains),
|
|
65
|
+
satelliteSolanaAdapter({ rpcUrls: { devnet: 'https://api.devnet.solana.com' } }),
|
|
66
|
+
];
|
|
128
67
|
|
|
129
68
|
export function Providers({ children }: { children: ReactNode }) {
|
|
130
|
-
const siwxSession = useSiwxSession();
|
|
69
|
+
const siwxSession = useSiwxSession(); // optional: pass the SIWX session to the watchers
|
|
131
70
|
|
|
132
71
|
return (
|
|
133
|
-
<SatelliteConnectProvider
|
|
134
|
-
adapter={[satelliteEVMAdapter(wagmiConfig, appEVMChains), satelliteSolanaAdapter({ rpcUrls: solanaRPCUrls })]}
|
|
135
|
-
autoConnect={true}
|
|
136
|
-
>
|
|
72
|
+
<SatelliteConnectProvider adapter={adapters} autoConnect>
|
|
137
73
|
<EVMConnectorsWatcher wagmiConfig={wagmiConfig} siwx={siwxSession} />
|
|
138
74
|
<SolanaConnectorsWatcher siwx={siwxSession} />
|
|
139
75
|
{children}
|
|
140
76
|
</SatelliteConnectProvider>
|
|
141
77
|
);
|
|
142
78
|
}
|
|
79
|
+
|
|
80
|
+
export function ActiveAddress() {
|
|
81
|
+
const activeConnection = useSatelliteConnectStore((state) => state.activeConnection);
|
|
82
|
+
const connecting = useSatelliteConnectStore((state) => state.connecting);
|
|
83
|
+
return <span>{connecting ? 'Connecting…' : (activeConnection?.address ?? 'Not connected')}</span>;
|
|
84
|
+
}
|
|
143
85
|
```
|
|
144
86
|
|
|
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
|
+
|
|
145
89
|
---
|
|
146
90
|
|
|
147
|
-
##
|
|
91
|
+
## 🗄️ Browser Storage
|
|
148
92
|
|
|
149
|
-
|
|
93
|
+
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).
|
|
94
|
+
|
|
95
|
+
---
|
|
150
96
|
|
|
151
|
-
|
|
97
|
+
## 📚 API Reference
|
|
152
98
|
|
|
153
|
-
|
|
99
|
+
Every export, with signatures and types generated from the source, is documented at **[satellite.docs.tuwa.io/packages/satellite-react](https://satellite.docs.tuwa.io/packages/satellite-react)**.
|
|
154
100
|
|
|
155
101
|
## 📄 License
|
|
156
102
|
|
|
157
|
-
|
|
103
|
+
Licensed under the **Apache-2.0 License**. See the [LICENSE](https://github.com/TuwaIO/satellite-connect/blob/main/packages/satellite-react/LICENSE) file for details.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import {createContext,useContext}from'react';import {useStore}from'zustand';var e=Symbol.for("tuwaio.satellite.context"),o=globalThis,a=o[e]||(o[e]=createContext(null)),
|
|
1
|
+
import {createContext,useContext}from'react';import {useStore}from'zustand';var e=Symbol.for("tuwaio.satellite.context"),o=globalThis,a=o[e]||(o[e]=createContext(null)),u=n=>{let t=useContext(a);if(!t)throw new Error("useSatelliteConnectStore must be used within a SatelliteConnectProvider");return useStore(t,n)};export{a,u as b};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import {useMemo}from'react';function m(e){let t=e!=null,s=e?.enabled,n=e?.isSignedIn,d=e?.isAuthenticated,i=e?.isRejected,a=e?.status,o=e?.address,c=e?.chainId,S=!!e?.session,l=e?.session?.address,u=e?.session?.chainId;return useMemo(()=>t?{enabled:s,isSignedIn:n,isAuthenticated:d,isRejected:i,status:a,address:o,chainId:c,session:S?{address:l,chainId:u}:null}:void 0,[t,s,n,d,i,a,o,c,S,l,u])}export{m as a};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
'use strict';var react=require('react'),zustand=require('zustand');var e=Symbol.for("tuwaio.satellite.context"),o=globalThis,a=o[e]||(o[e]=react.createContext(null)),
|
|
1
|
+
'use strict';var react=require('react'),zustand=require('zustand');var e=Symbol.for("tuwaio.satellite.context"),o=globalThis,a=o[e]||(o[e]=react.createContext(null)),p=n=>{let t=react.useContext(a);if(!t)throw new Error("useSatelliteConnectStore must be used within a SatelliteConnectProvider");return zustand.useStore(t,n)};exports.a=a;exports.b=p;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
'use strict';var react=require('react');function I(e){let t=e!=null,s=e?.enabled,n=e?.isSignedIn,d=e?.isAuthenticated,i=e?.isRejected,a=e?.status,o=e?.address,c=e?.chainId,S=!!e?.session,l=e?.session?.address,u=e?.session?.chainId;return react.useMemo(()=>t?{enabled:s,isSignedIn:n,isAuthenticated:d,isRejected:i,status:a,address:o,chainId:c,session:S?{address:l,chainId:u}:null}:void 0,[t,s,n,d,i,a,o,c,S,l,u])}exports.a=I;
|
package/dist/evm/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
'use strict';require('../chunk-
|
|
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;
|
package/dist/evm/index.d.cts
CHANGED
|
@@ -2,60 +2,77 @@ import { OrbitAdapter } from '@tuwaio/orbit-core';
|
|
|
2
2
|
import { EVMConnection, ConnectorEVM } from '@tuwaio/satellite-evm';
|
|
3
3
|
import * as react from 'react';
|
|
4
4
|
import { SatelliteSiwxState } from '@tuwaio/satellite-core';
|
|
5
|
+
import { Config } from '@wagmi/core';
|
|
5
6
|
|
|
6
7
|
/**
|
|
7
8
|
* Props for the {@link EVMConnectorsWatcher} component.
|
|
8
9
|
*/
|
|
9
10
|
interface EVMConnectorsWatcherProps {
|
|
10
11
|
/**
|
|
11
|
-
* The
|
|
12
|
-
*
|
|
12
|
+
* The wagmi `Config` from `@wagmi/core` that the EVM adapter uses. Its connections are watched with
|
|
13
|
+
* `watchConnections`.
|
|
13
14
|
*/
|
|
14
|
-
wagmiConfig:
|
|
15
|
+
wagmiConfig: Config;
|
|
15
16
|
/**
|
|
16
|
-
* Optional Sign-In With X (SIWX) session state
|
|
17
|
-
*
|
|
18
|
-
* Directly compatible with `useSiwxSession()` from `@tuwaio/siwx-react`.
|
|
17
|
+
* Optional Sign-In With X (SIWX) session state, for example the result of `useSiwxSession()` from
|
|
18
|
+
* `@tuwaio/siwx-react`. The watcher is restarted when one of its fields changes.
|
|
19
19
|
*/
|
|
20
20
|
siwx?: SatelliteSiwxState;
|
|
21
21
|
/**
|
|
22
|
-
*
|
|
22
|
+
* Legacy SIWE state, used only when `siwx` is not passed.
|
|
23
|
+
*
|
|
24
|
+
* @deprecated Pass `siwx` instead.
|
|
23
25
|
*/
|
|
24
26
|
siwe?: {
|
|
27
|
+
/** Whether the user rejected the sign-in or it failed. */
|
|
25
28
|
isRejected?: boolean;
|
|
29
|
+
/** Whether the user is signed in. */
|
|
26
30
|
isSignedIn?: boolean;
|
|
31
|
+
/** Whether sign-in is enabled. `false` turns off the disconnect on rejection. */
|
|
27
32
|
enabled?: boolean;
|
|
28
33
|
};
|
|
29
34
|
}
|
|
30
35
|
/**
|
|
31
|
-
*
|
|
32
|
-
*
|
|
36
|
+
* Headless component that keeps the Satellite Connect store in sync with wagmi. Render it once inside
|
|
37
|
+
* `SatelliteConnectProvider`, next to an EVM adapter created with the same `wagmiConfig`.
|
|
33
38
|
*
|
|
34
|
-
*
|
|
35
|
-
*
|
|
39
|
+
* After mount it loads `@tuwaio/satellite-evm` with a dynamic import and runs its `createEVMConnectionsWatcher`: account
|
|
40
|
+
* and network changes made in the wallet update the active connection, a wallet disconnect removes it, and with `siwx`
|
|
41
|
+
* the connection is disconnected when the SIWX sign-in is rejected or fails, or when the account or chain no longer
|
|
42
|
+
* matches the signed-in session. The watcher restarts when `wagmiConfig`, a field of `siwx`, the active connector or
|
|
43
|
+
* the connection error changes, and stops on unmount. If the import fails, a warning is logged and nothing is watched.
|
|
44
|
+
*
|
|
45
|
+
* @param props - The component props. See {@link EVMConnectorsWatcherProps}.
|
|
46
|
+
* @returns `null`; the component renders nothing.
|
|
36
47
|
*
|
|
37
48
|
* @example
|
|
38
49
|
* ```tsx
|
|
39
|
-
* import { useSiwxSession } from '@tuwaio/siwx-react';
|
|
40
50
|
* import { EVMConnectorsWatcher } from '@tuwaio/satellite-react/evm';
|
|
51
|
+
* import { useSiwxSession } from '@tuwaio/siwx-react';
|
|
52
|
+
* import type { Config } from '@wagmi/core';
|
|
41
53
|
*
|
|
42
|
-
* function WatcherContainer() {
|
|
54
|
+
* export function WatcherContainer({ wagmiConfig }: { wagmiConfig: Config }) {
|
|
43
55
|
* const siwxSession = useSiwxSession();
|
|
44
56
|
* return <EVMConnectorsWatcher wagmiConfig={wagmiConfig} siwx={siwxSession} />;
|
|
45
57
|
* }
|
|
46
58
|
* ```
|
|
47
|
-
*
|
|
48
|
-
* @remarks
|
|
49
|
-
* Monitors Wagmi account and network changes. Automatically disconnects wallet state if SIWX
|
|
50
|
-
* session validation fails or is rejected.
|
|
51
59
|
*/
|
|
52
60
|
declare function EVMConnectorsWatcher(props: EVMConnectorsWatcherProps): react.JSX.Element | null;
|
|
53
61
|
|
|
62
|
+
/**
|
|
63
|
+
* The EVM watcher component, imported from `@tuwaio/satellite-react/evm`. Importing this entry point also adds
|
|
64
|
+
* `EVMConnection` and `ConnectorEVM` from `@tuwaio/satellite-evm` to `AllConnections` and `AllConnectors`.
|
|
65
|
+
*
|
|
66
|
+
* @module evm
|
|
67
|
+
*/
|
|
68
|
+
|
|
54
69
|
declare module '@tuwaio/satellite-react' {
|
|
55
70
|
interface AllConnections {
|
|
71
|
+
/** EVM connections (`EVMConnection` from `@tuwaio/satellite-evm`), added by `@tuwaio/satellite-react/evm`. */
|
|
56
72
|
[OrbitAdapter.EVM]: EVMConnection;
|
|
57
73
|
}
|
|
58
74
|
interface AllConnectors {
|
|
75
|
+
/** wagmi connectors (`ConnectorEVM` from `@tuwaio/satellite-evm`), added by `@tuwaio/satellite-react/evm`. */
|
|
59
76
|
[OrbitAdapter.EVM]: ConnectorEVM;
|
|
60
77
|
}
|
|
61
78
|
}
|
package/dist/evm/index.d.ts
CHANGED
|
@@ -2,60 +2,77 @@ import { OrbitAdapter } from '@tuwaio/orbit-core';
|
|
|
2
2
|
import { EVMConnection, ConnectorEVM } from '@tuwaio/satellite-evm';
|
|
3
3
|
import * as react from 'react';
|
|
4
4
|
import { SatelliteSiwxState } from '@tuwaio/satellite-core';
|
|
5
|
+
import { Config } from '@wagmi/core';
|
|
5
6
|
|
|
6
7
|
/**
|
|
7
8
|
* Props for the {@link EVMConnectorsWatcher} component.
|
|
8
9
|
*/
|
|
9
10
|
interface EVMConnectorsWatcherProps {
|
|
10
11
|
/**
|
|
11
|
-
* The
|
|
12
|
-
*
|
|
12
|
+
* The wagmi `Config` from `@wagmi/core` that the EVM adapter uses. Its connections are watched with
|
|
13
|
+
* `watchConnections`.
|
|
13
14
|
*/
|
|
14
|
-
wagmiConfig:
|
|
15
|
+
wagmiConfig: Config;
|
|
15
16
|
/**
|
|
16
|
-
* Optional Sign-In With X (SIWX) session state
|
|
17
|
-
*
|
|
18
|
-
* Directly compatible with `useSiwxSession()` from `@tuwaio/siwx-react`.
|
|
17
|
+
* Optional Sign-In With X (SIWX) session state, for example the result of `useSiwxSession()` from
|
|
18
|
+
* `@tuwaio/siwx-react`. The watcher is restarted when one of its fields changes.
|
|
19
19
|
*/
|
|
20
20
|
siwx?: SatelliteSiwxState;
|
|
21
21
|
/**
|
|
22
|
-
*
|
|
22
|
+
* Legacy SIWE state, used only when `siwx` is not passed.
|
|
23
|
+
*
|
|
24
|
+
* @deprecated Pass `siwx` instead.
|
|
23
25
|
*/
|
|
24
26
|
siwe?: {
|
|
27
|
+
/** Whether the user rejected the sign-in or it failed. */
|
|
25
28
|
isRejected?: boolean;
|
|
29
|
+
/** Whether the user is signed in. */
|
|
26
30
|
isSignedIn?: boolean;
|
|
31
|
+
/** Whether sign-in is enabled. `false` turns off the disconnect on rejection. */
|
|
27
32
|
enabled?: boolean;
|
|
28
33
|
};
|
|
29
34
|
}
|
|
30
35
|
/**
|
|
31
|
-
*
|
|
32
|
-
*
|
|
36
|
+
* Headless component that keeps the Satellite Connect store in sync with wagmi. Render it once inside
|
|
37
|
+
* `SatelliteConnectProvider`, next to an EVM adapter created with the same `wagmiConfig`.
|
|
33
38
|
*
|
|
34
|
-
*
|
|
35
|
-
*
|
|
39
|
+
* After mount it loads `@tuwaio/satellite-evm` with a dynamic import and runs its `createEVMConnectionsWatcher`: account
|
|
40
|
+
* and network changes made in the wallet update the active connection, a wallet disconnect removes it, and with `siwx`
|
|
41
|
+
* the connection is disconnected when the SIWX sign-in is rejected or fails, or when the account or chain no longer
|
|
42
|
+
* matches the signed-in session. The watcher restarts when `wagmiConfig`, a field of `siwx`, the active connector or
|
|
43
|
+
* the connection error changes, and stops on unmount. If the import fails, a warning is logged and nothing is watched.
|
|
44
|
+
*
|
|
45
|
+
* @param props - The component props. See {@link EVMConnectorsWatcherProps}.
|
|
46
|
+
* @returns `null`; the component renders nothing.
|
|
36
47
|
*
|
|
37
48
|
* @example
|
|
38
49
|
* ```tsx
|
|
39
|
-
* import { useSiwxSession } from '@tuwaio/siwx-react';
|
|
40
50
|
* import { EVMConnectorsWatcher } from '@tuwaio/satellite-react/evm';
|
|
51
|
+
* import { useSiwxSession } from '@tuwaio/siwx-react';
|
|
52
|
+
* import type { Config } from '@wagmi/core';
|
|
41
53
|
*
|
|
42
|
-
* function WatcherContainer() {
|
|
54
|
+
* export function WatcherContainer({ wagmiConfig }: { wagmiConfig: Config }) {
|
|
43
55
|
* const siwxSession = useSiwxSession();
|
|
44
56
|
* return <EVMConnectorsWatcher wagmiConfig={wagmiConfig} siwx={siwxSession} />;
|
|
45
57
|
* }
|
|
46
58
|
* ```
|
|
47
|
-
*
|
|
48
|
-
* @remarks
|
|
49
|
-
* Monitors Wagmi account and network changes. Automatically disconnects wallet state if SIWX
|
|
50
|
-
* session validation fails or is rejected.
|
|
51
59
|
*/
|
|
52
60
|
declare function EVMConnectorsWatcher(props: EVMConnectorsWatcherProps): react.JSX.Element | null;
|
|
53
61
|
|
|
62
|
+
/**
|
|
63
|
+
* The EVM watcher component, imported from `@tuwaio/satellite-react/evm`. Importing this entry point also adds
|
|
64
|
+
* `EVMConnection` and `ConnectorEVM` from `@tuwaio/satellite-evm` to `AllConnections` and `AllConnectors`.
|
|
65
|
+
*
|
|
66
|
+
* @module evm
|
|
67
|
+
*/
|
|
68
|
+
|
|
54
69
|
declare module '@tuwaio/satellite-react' {
|
|
55
70
|
interface AllConnections {
|
|
71
|
+
/** EVM connections (`EVMConnection` from `@tuwaio/satellite-evm`), added by `@tuwaio/satellite-react/evm`. */
|
|
56
72
|
[OrbitAdapter.EVM]: EVMConnection;
|
|
57
73
|
}
|
|
58
74
|
interface AllConnectors {
|
|
75
|
+
/** wagmi connectors (`ConnectorEVM` from `@tuwaio/satellite-evm`), added by `@tuwaio/satellite-react/evm`. */
|
|
59
76
|
[OrbitAdapter.EVM]: ConnectorEVM;
|
|
60
77
|
}
|
|
61
78
|
}
|
package/dist/evm/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import'../chunk-
|
|
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};
|
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
'use strict';var
|
|
1
|
+
'use strict';var chunkHEG6FP5Z_cjs=require('./chunk-HEG6FP5Z.cjs'),react=require('react'),satelliteCore=require('@tuwaio/satellite-core'),jsxRuntime=require('react/jsx-runtime');var a=({initializeAutoConnect:n,onError:r})=>{let e=react.useEffectEvent(async()=>n()),t=react.useEffectEvent(o=>{(r??(s=>console.error("Failed to initialize auto connect:",s)))(o);});react.useEffect(()=>{e().catch(o=>t(o));},[]);};function g({children:n,autoConnect:r,adapter:e,callbackAfterConnected:t}){let o=react.useMemo(()=>satelliteCore.createSatelliteConnectStore({adapter:e,callbackAfterConnected:t}),[]);return react.useEffect(()=>{o.getState().updateParameters({adapter:e,callbackAfterConnected:t});},[o,e,t]),a({initializeAutoConnect:()=>o.getState().initializeAutoConnect(r??false)}),jsxRuntime.jsx(chunkHEG6FP5Z_cjs.a.Provider,{value:o,children:n})}Object.defineProperty(exports,"SatelliteStoreContext",{enumerable:true,get:function(){return chunkHEG6FP5Z_cjs.a}});Object.defineProperty(exports,"useSatelliteConnectStore",{enumerable:true,get:function(){return chunkHEG6FP5Z_cjs.b}});exports.SatelliteConnectProvider=g;exports.useInitializeAutoConnect=a;
|