@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/dist/index.d.cts
CHANGED
|
@@ -3,136 +3,166 @@ import { ISatelliteConnectStore, SatelliteConnectStoreInitialParameters } from '
|
|
|
3
3
|
import { StoreApi } from 'zustand';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
* augmentation to add their specific connection types here.
|
|
6
|
+
* Connection types by chain family, filled by module augmentation. Importing `@tuwaio/satellite-react/evm` adds
|
|
7
|
+
* `EVMConnection` from `@tuwaio/satellite-evm`, and importing `@tuwaio/satellite-react/solana` adds `SolanaConnection`
|
|
8
|
+
* from `@tuwaio/satellite-solana`. It is empty until one of them is imported.
|
|
10
9
|
*/
|
|
11
10
|
interface AllConnections {
|
|
12
11
|
}
|
|
13
12
|
/**
|
|
14
|
-
* @
|
|
15
|
-
*
|
|
16
|
-
* It will be augmented by satellite packages.
|
|
13
|
+
* Wallet connector types by chain family, filled by module augmentation like {@link AllConnections}: the wagmi
|
|
14
|
+
* `Connector` for EVM and the Wallet Standard `UiWallet` for Solana.
|
|
17
15
|
*/
|
|
18
16
|
interface AllConnectors {
|
|
19
17
|
}
|
|
20
18
|
/**
|
|
21
|
-
* Union
|
|
22
|
-
*
|
|
23
|
-
* e.g., { evm: EVMConnection, solana: SolanaConnection } -> EVMConnection | SolanaConnection
|
|
19
|
+
* Union of the connection types in {@link AllConnections}, for example `EVMConnection | SolanaConnection`. The store of
|
|
20
|
+
* `SatelliteConnectProvider` uses it for `activeConnection` and `connections`.
|
|
24
21
|
*/
|
|
25
22
|
type Connection = AllConnections[keyof AllConnections];
|
|
26
23
|
/**
|
|
27
|
-
* Union
|
|
24
|
+
* Union of the wallet connector types in {@link AllConnectors}, returned by the store's `getConnectors`.
|
|
28
25
|
*/
|
|
29
26
|
type Connector = AllConnectors[keyof AllConnectors];
|
|
30
27
|
|
|
28
|
+
/**
|
|
29
|
+
* Value of {@link SatelliteStoreContext}: the store created by {@link SatelliteConnectProvider}, or `null` outside the
|
|
30
|
+
* provider.
|
|
31
|
+
*/
|
|
31
32
|
type SatelliteContextType = StoreApi<ISatelliteConnectStore<Connector, Connection>> | null;
|
|
32
|
-
declare const SatelliteStoreContext: react.Context<SatelliteContextType>;
|
|
33
33
|
/**
|
|
34
|
-
*
|
|
35
|
-
*
|
|
36
|
-
* @remarks
|
|
37
|
-
* This hook provides type-safe access to the Satellite store state and must be used
|
|
38
|
-
* within a component that is wrapped by SatelliteConnectProvider.
|
|
34
|
+
* React context that holds the store of {@link SatelliteConnectProvider}. Use {@link useSatelliteConnectStore} to read
|
|
35
|
+
* it in components; read the context directly to call `getState()` or `subscribe` without re-rendering.
|
|
39
36
|
*
|
|
40
|
-
*
|
|
41
|
-
*
|
|
42
|
-
|
|
37
|
+
* The context object is created once and saved on `globalThis` (`Symbol.for('tuwaio.satellite.context')`), so
|
|
38
|
+
* packages that bundle their own copy of `@tuwaio/satellite-react` share the same context.
|
|
39
|
+
*/
|
|
40
|
+
declare const SatelliteStoreContext: react.Context<SatelliteContextType>;
|
|
41
|
+
/**
|
|
42
|
+
* Reads a value from the store of {@link SatelliteConnectProvider} and re-renders the component when it changes
|
|
43
|
+
* (compared with `Object.is`, through `useStore` from `zustand`). Return stable values from the selector: a new
|
|
44
|
+
* object or array on every call causes endless re-renders (use `useShallow` from `zustand/react/shallow`).
|
|
43
45
|
*
|
|
44
|
-
* @
|
|
46
|
+
* @typeParam T - Type of the selected value.
|
|
47
|
+
* @param selector - Selects a value from the store state (`ISatelliteConnectStore` from `@tuwaio/satellite-core`).
|
|
48
|
+
* @returns The selected value.
|
|
49
|
+
* @throws {Error} `useSatelliteConnectStore must be used within a SatelliteConnectProvider` outside the provider.
|
|
45
50
|
*
|
|
46
51
|
* @example
|
|
47
52
|
* ```tsx
|
|
48
|
-
*
|
|
49
|
-
*
|
|
53
|
+
* import { useSatelliteConnectStore } from '@tuwaio/satellite-react';
|
|
54
|
+
*
|
|
55
|
+
* export function ActiveAddress() {
|
|
56
|
+
* const activeConnection = useSatelliteConnectStore((state) => state.activeConnection);
|
|
57
|
+
* return <span>{activeConnection?.address ?? 'Not connected'}</span>;
|
|
58
|
+
* }
|
|
50
59
|
* ```
|
|
51
60
|
*/
|
|
52
61
|
declare const useSatelliteConnectStore: <T>(selector: (state: ISatelliteConnectStore<Connector, Connection>) => T) => T;
|
|
53
62
|
|
|
54
63
|
/**
|
|
55
|
-
*
|
|
64
|
+
* Parameters of {@link useInitializeAutoConnect}.
|
|
56
65
|
*/
|
|
57
66
|
interface InitializeAutoConnectProps {
|
|
58
|
-
/**
|
|
67
|
+
/**
|
|
68
|
+
* Restores the connection, for example `() => store.getState().initializeAutoConnect(true)`.
|
|
69
|
+
*
|
|
70
|
+
* @returns Resolves when done.
|
|
71
|
+
*/
|
|
59
72
|
initializeAutoConnect: () => Promise<void>;
|
|
60
|
-
/**
|
|
73
|
+
/**
|
|
74
|
+
* Called when `initializeAutoConnect` rejects; the function of the latest render is used. Defaults to
|
|
75
|
+
* `console.error`.
|
|
76
|
+
*
|
|
77
|
+
* @param error - The rejection reason.
|
|
78
|
+
*/
|
|
61
79
|
onError?: (error: Error) => void;
|
|
62
80
|
}
|
|
63
81
|
/**
|
|
64
|
-
*
|
|
82
|
+
* Calls `initializeAutoConnect` once, in an effect after the component mounts (so only in the browser).
|
|
83
|
+
* {@link SatelliteConnectProvider} already uses it; call it yourself only with a store you create with
|
|
84
|
+
* `createSatelliteConnectStore` from `@tuwaio/satellite-core`.
|
|
65
85
|
*
|
|
66
|
-
*
|
|
67
|
-
*
|
|
68
|
-
*
|
|
69
|
-
* It provides default error handling with console.error if no custom handler is provided.
|
|
70
|
-
* The initialization runs only once when the component mounts.
|
|
86
|
+
* It runs once: later renders do not call `initializeAutoConnect` again. If it rejects, the error goes to the `onError`
|
|
87
|
+
* of the latest render, so an inline `onError` needs no memoization. In development, React Strict Mode runs the
|
|
88
|
+
* effect twice.
|
|
71
89
|
*
|
|
72
|
-
* @param props -
|
|
73
|
-
* @param props.initializeAutoConnect - Async function that executes the auto-connect logic
|
|
74
|
-
* @param props.onError - Optional custom error handler
|
|
90
|
+
* @param props - The initializer and the optional error handler. See {@link InitializeAutoConnectProps}.
|
|
75
91
|
*
|
|
76
92
|
* @example
|
|
77
93
|
* ```tsx
|
|
78
|
-
*
|
|
79
|
-
* useInitializeAutoConnect
|
|
80
|
-
*
|
|
94
|
+
* import { createSatelliteConnectStore } from '@tuwaio/satellite-core';
|
|
95
|
+
* import { useInitializeAutoConnect } from '@tuwaio/satellite-react';
|
|
96
|
+
* import { satelliteSolanaAdapter } from '@tuwaio/satellite-solana';
|
|
97
|
+
*
|
|
98
|
+
* const store = createSatelliteConnectStore({
|
|
99
|
+
* adapter: satelliteSolanaAdapter({ rpcUrls: { devnet: 'https://api.devnet.solana.com' } }),
|
|
81
100
|
* });
|
|
82
101
|
*
|
|
83
|
-
*
|
|
84
|
-
*
|
|
85
|
-
*
|
|
86
|
-
*
|
|
87
|
-
*
|
|
102
|
+
* export function AutoConnect() {
|
|
103
|
+
* useInitializeAutoConnect({
|
|
104
|
+
* initializeAutoConnect: () => store.getState().initializeAutoConnect(true),
|
|
105
|
+
* onError: (error) => console.warn('Auto-connect failed:', error.message),
|
|
106
|
+
* });
|
|
107
|
+
* return null;
|
|
88
108
|
* }
|
|
89
|
-
* });
|
|
90
109
|
* ```
|
|
91
110
|
*/
|
|
92
111
|
declare const useInitializeAutoConnect: ({ initializeAutoConnect, onError }: InitializeAutoConnectProps) => void;
|
|
93
112
|
|
|
94
113
|
/**
|
|
95
|
-
* Props
|
|
114
|
+
* Props of {@link SatelliteConnectProvider}: the store parameters (`adapter`, one adapter or an array, and the optional
|
|
115
|
+
* `callbackAfterConnected`, see `SatelliteConnectStoreInitialParameters` from `@tuwaio/satellite-core`) plus the
|
|
116
|
+
* fields below.
|
|
96
117
|
*/
|
|
97
118
|
interface SatelliteConnectProviderProps extends SatelliteConnectStoreInitialParameters<Connector, Connection> {
|
|
98
|
-
/**
|
|
119
|
+
/** Components that can read the store. */
|
|
99
120
|
children: React.ReactNode;
|
|
100
|
-
/**
|
|
121
|
+
/**
|
|
122
|
+
* Whether to reconnect the last connected wallet after a page load (read on the first render only). Defaults to
|
|
123
|
+
* `false`. See `initializeAutoConnect` of the store.
|
|
124
|
+
*/
|
|
101
125
|
autoConnect?: boolean;
|
|
102
126
|
}
|
|
103
127
|
/**
|
|
104
|
-
*
|
|
128
|
+
* Creates the Satellite Connect store (`createSatelliteConnectStore` from `@tuwaio/satellite-core`) and provides it to
|
|
129
|
+
* its children through {@link SatelliteStoreContext}. Read it with {@link useSatelliteConnectStore}.
|
|
105
130
|
*
|
|
106
|
-
*
|
|
107
|
-
*
|
|
108
|
-
*
|
|
109
|
-
*
|
|
131
|
+
* The store is created once, on the first render. When `adapter` or `callbackAfterConnected` changes, the new value
|
|
132
|
+
* is passed to the store's `updateParameters`; the state is kept. Define adapters outside the component (or memoize
|
|
133
|
+
* them), so a render does not create new adapter objects. After mount the provider
|
|
134
|
+
* calls the store's `initializeAutoConnect(autoConnect ?? false)` once, which disconnects the wallets of every adapter,
|
|
135
|
+
* cleans the recently connected list in `localStorage` and, with `autoConnect`, reconnects the last connected wallet.
|
|
136
|
+
* Inside Safe{Wallet} it connects the Safe connector instead, with or without `autoConnect`.
|
|
137
|
+
* Render the chain watchers (`EVMConnectorsWatcher` from `@tuwaio/satellite-react/evm`, `SolanaConnectorsWatcher`
|
|
138
|
+
* from `@tuwaio/satellite-react/solana`) inside it to follow wallet changes.
|
|
110
139
|
*
|
|
111
|
-
* @param props -
|
|
112
|
-
* @
|
|
113
|
-
* @param props.autoConnect - Optional flag to enable automatic connector reconnection
|
|
114
|
-
* @param props.adapter - Blockchain adapter(s) for connector interactions
|
|
115
|
-
* @param props.callbackAfterConnected - Optional callback for successful connections
|
|
140
|
+
* @param props - The store parameters, `autoConnect` and `children`. See {@link SatelliteConnectProviderProps}.
|
|
141
|
+
* @returns The context provider.
|
|
116
142
|
*
|
|
117
143
|
* @example
|
|
118
144
|
* ```tsx
|
|
119
|
-
*
|
|
120
|
-
* <SatelliteConnectProvider adapter={solanaAdapter}>
|
|
121
|
-
* <App />
|
|
122
|
-
* </SatelliteConnectProvider>
|
|
145
|
+
* 'use client';
|
|
123
146
|
*
|
|
124
|
-
*
|
|
125
|
-
*
|
|
126
|
-
*
|
|
127
|
-
*
|
|
128
|
-
*
|
|
129
|
-
*
|
|
130
|
-
*
|
|
131
|
-
*
|
|
132
|
-
*
|
|
133
|
-
*
|
|
147
|
+
* import { SatelliteConnectProvider } from '@tuwaio/satellite-react';
|
|
148
|
+
* import { satelliteSolanaAdapter } from '@tuwaio/satellite-solana';
|
|
149
|
+
* import type { ReactNode } from 'react';
|
|
150
|
+
*
|
|
151
|
+
* const solanaAdapter = satelliteSolanaAdapter({ rpcUrls: { devnet: 'https://api.devnet.solana.com' } });
|
|
152
|
+
*
|
|
153
|
+
* export function Providers({ children }: { children: ReactNode }) {
|
|
154
|
+
* return (
|
|
155
|
+
* <SatelliteConnectProvider
|
|
156
|
+
* adapter={solanaAdapter}
|
|
157
|
+
* autoConnect
|
|
158
|
+
* callbackAfterConnected={(connection) => console.log('Connected:', connection.address)}
|
|
159
|
+
* >
|
|
160
|
+
* {children}
|
|
161
|
+
* </SatelliteConnectProvider>
|
|
162
|
+
* );
|
|
163
|
+
* }
|
|
134
164
|
* ```
|
|
135
165
|
*/
|
|
136
|
-
declare function SatelliteConnectProvider({ children, autoConnect,
|
|
166
|
+
declare function SatelliteConnectProvider({ children, autoConnect, adapter, callbackAfterConnected, }: SatelliteConnectProviderProps): react.JSX.Element;
|
|
137
167
|
|
|
138
|
-
export { type AllConnections, type AllConnectors, type Connection, type Connector, SatelliteConnectProvider, type SatelliteConnectProviderProps, SatelliteStoreContext, useInitializeAutoConnect, useSatelliteConnectStore };
|
|
168
|
+
export { type AllConnections, type AllConnectors, type Connection, type Connector, type InitializeAutoConnectProps, SatelliteConnectProvider, type SatelliteConnectProviderProps, type SatelliteContextType, SatelliteStoreContext, useInitializeAutoConnect, useSatelliteConnectStore };
|
package/dist/index.d.ts
CHANGED
|
@@ -3,136 +3,166 @@ import { ISatelliteConnectStore, SatelliteConnectStoreInitialParameters } from '
|
|
|
3
3
|
import { StoreApi } from 'zustand';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
* augmentation to add their specific connection types here.
|
|
6
|
+
* Connection types by chain family, filled by module augmentation. Importing `@tuwaio/satellite-react/evm` adds
|
|
7
|
+
* `EVMConnection` from `@tuwaio/satellite-evm`, and importing `@tuwaio/satellite-react/solana` adds `SolanaConnection`
|
|
8
|
+
* from `@tuwaio/satellite-solana`. It is empty until one of them is imported.
|
|
10
9
|
*/
|
|
11
10
|
interface AllConnections {
|
|
12
11
|
}
|
|
13
12
|
/**
|
|
14
|
-
* @
|
|
15
|
-
*
|
|
16
|
-
* It will be augmented by satellite packages.
|
|
13
|
+
* Wallet connector types by chain family, filled by module augmentation like {@link AllConnections}: the wagmi
|
|
14
|
+
* `Connector` for EVM and the Wallet Standard `UiWallet` for Solana.
|
|
17
15
|
*/
|
|
18
16
|
interface AllConnectors {
|
|
19
17
|
}
|
|
20
18
|
/**
|
|
21
|
-
* Union
|
|
22
|
-
*
|
|
23
|
-
* e.g., { evm: EVMConnection, solana: SolanaConnection } -> EVMConnection | SolanaConnection
|
|
19
|
+
* Union of the connection types in {@link AllConnections}, for example `EVMConnection | SolanaConnection`. The store of
|
|
20
|
+
* `SatelliteConnectProvider` uses it for `activeConnection` and `connections`.
|
|
24
21
|
*/
|
|
25
22
|
type Connection = AllConnections[keyof AllConnections];
|
|
26
23
|
/**
|
|
27
|
-
* Union
|
|
24
|
+
* Union of the wallet connector types in {@link AllConnectors}, returned by the store's `getConnectors`.
|
|
28
25
|
*/
|
|
29
26
|
type Connector = AllConnectors[keyof AllConnectors];
|
|
30
27
|
|
|
28
|
+
/**
|
|
29
|
+
* Value of {@link SatelliteStoreContext}: the store created by {@link SatelliteConnectProvider}, or `null` outside the
|
|
30
|
+
* provider.
|
|
31
|
+
*/
|
|
31
32
|
type SatelliteContextType = StoreApi<ISatelliteConnectStore<Connector, Connection>> | null;
|
|
32
|
-
declare const SatelliteStoreContext: react.Context<SatelliteContextType>;
|
|
33
33
|
/**
|
|
34
|
-
*
|
|
35
|
-
*
|
|
36
|
-
* @remarks
|
|
37
|
-
* This hook provides type-safe access to the Satellite store state and must be used
|
|
38
|
-
* within a component that is wrapped by SatelliteConnectProvider.
|
|
34
|
+
* React context that holds the store of {@link SatelliteConnectProvider}. Use {@link useSatelliteConnectStore} to read
|
|
35
|
+
* it in components; read the context directly to call `getState()` or `subscribe` without re-rendering.
|
|
39
36
|
*
|
|
40
|
-
*
|
|
41
|
-
*
|
|
42
|
-
|
|
37
|
+
* The context object is created once and saved on `globalThis` (`Symbol.for('tuwaio.satellite.context')`), so
|
|
38
|
+
* packages that bundle their own copy of `@tuwaio/satellite-react` share the same context.
|
|
39
|
+
*/
|
|
40
|
+
declare const SatelliteStoreContext: react.Context<SatelliteContextType>;
|
|
41
|
+
/**
|
|
42
|
+
* Reads a value from the store of {@link SatelliteConnectProvider} and re-renders the component when it changes
|
|
43
|
+
* (compared with `Object.is`, through `useStore` from `zustand`). Return stable values from the selector: a new
|
|
44
|
+
* object or array on every call causes endless re-renders (use `useShallow` from `zustand/react/shallow`).
|
|
43
45
|
*
|
|
44
|
-
* @
|
|
46
|
+
* @typeParam T - Type of the selected value.
|
|
47
|
+
* @param selector - Selects a value from the store state (`ISatelliteConnectStore` from `@tuwaio/satellite-core`).
|
|
48
|
+
* @returns The selected value.
|
|
49
|
+
* @throws {Error} `useSatelliteConnectStore must be used within a SatelliteConnectProvider` outside the provider.
|
|
45
50
|
*
|
|
46
51
|
* @example
|
|
47
52
|
* ```tsx
|
|
48
|
-
*
|
|
49
|
-
*
|
|
53
|
+
* import { useSatelliteConnectStore } from '@tuwaio/satellite-react';
|
|
54
|
+
*
|
|
55
|
+
* export function ActiveAddress() {
|
|
56
|
+
* const activeConnection = useSatelliteConnectStore((state) => state.activeConnection);
|
|
57
|
+
* return <span>{activeConnection?.address ?? 'Not connected'}</span>;
|
|
58
|
+
* }
|
|
50
59
|
* ```
|
|
51
60
|
*/
|
|
52
61
|
declare const useSatelliteConnectStore: <T>(selector: (state: ISatelliteConnectStore<Connector, Connection>) => T) => T;
|
|
53
62
|
|
|
54
63
|
/**
|
|
55
|
-
*
|
|
64
|
+
* Parameters of {@link useInitializeAutoConnect}.
|
|
56
65
|
*/
|
|
57
66
|
interface InitializeAutoConnectProps {
|
|
58
|
-
/**
|
|
67
|
+
/**
|
|
68
|
+
* Restores the connection, for example `() => store.getState().initializeAutoConnect(true)`.
|
|
69
|
+
*
|
|
70
|
+
* @returns Resolves when done.
|
|
71
|
+
*/
|
|
59
72
|
initializeAutoConnect: () => Promise<void>;
|
|
60
|
-
/**
|
|
73
|
+
/**
|
|
74
|
+
* Called when `initializeAutoConnect` rejects; the function of the latest render is used. Defaults to
|
|
75
|
+
* `console.error`.
|
|
76
|
+
*
|
|
77
|
+
* @param error - The rejection reason.
|
|
78
|
+
*/
|
|
61
79
|
onError?: (error: Error) => void;
|
|
62
80
|
}
|
|
63
81
|
/**
|
|
64
|
-
*
|
|
82
|
+
* Calls `initializeAutoConnect` once, in an effect after the component mounts (so only in the browser).
|
|
83
|
+
* {@link SatelliteConnectProvider} already uses it; call it yourself only with a store you create with
|
|
84
|
+
* `createSatelliteConnectStore` from `@tuwaio/satellite-core`.
|
|
65
85
|
*
|
|
66
|
-
*
|
|
67
|
-
*
|
|
68
|
-
*
|
|
69
|
-
* It provides default error handling with console.error if no custom handler is provided.
|
|
70
|
-
* The initialization runs only once when the component mounts.
|
|
86
|
+
* It runs once: later renders do not call `initializeAutoConnect` again. If it rejects, the error goes to the `onError`
|
|
87
|
+
* of the latest render, so an inline `onError` needs no memoization. In development, React Strict Mode runs the
|
|
88
|
+
* effect twice.
|
|
71
89
|
*
|
|
72
|
-
* @param props -
|
|
73
|
-
* @param props.initializeAutoConnect - Async function that executes the auto-connect logic
|
|
74
|
-
* @param props.onError - Optional custom error handler
|
|
90
|
+
* @param props - The initializer and the optional error handler. See {@link InitializeAutoConnectProps}.
|
|
75
91
|
*
|
|
76
92
|
* @example
|
|
77
93
|
* ```tsx
|
|
78
|
-
*
|
|
79
|
-
* useInitializeAutoConnect
|
|
80
|
-
*
|
|
94
|
+
* import { createSatelliteConnectStore } from '@tuwaio/satellite-core';
|
|
95
|
+
* import { useInitializeAutoConnect } from '@tuwaio/satellite-react';
|
|
96
|
+
* import { satelliteSolanaAdapter } from '@tuwaio/satellite-solana';
|
|
97
|
+
*
|
|
98
|
+
* const store = createSatelliteConnectStore({
|
|
99
|
+
* adapter: satelliteSolanaAdapter({ rpcUrls: { devnet: 'https://api.devnet.solana.com' } }),
|
|
81
100
|
* });
|
|
82
101
|
*
|
|
83
|
-
*
|
|
84
|
-
*
|
|
85
|
-
*
|
|
86
|
-
*
|
|
87
|
-
*
|
|
102
|
+
* export function AutoConnect() {
|
|
103
|
+
* useInitializeAutoConnect({
|
|
104
|
+
* initializeAutoConnect: () => store.getState().initializeAutoConnect(true),
|
|
105
|
+
* onError: (error) => console.warn('Auto-connect failed:', error.message),
|
|
106
|
+
* });
|
|
107
|
+
* return null;
|
|
88
108
|
* }
|
|
89
|
-
* });
|
|
90
109
|
* ```
|
|
91
110
|
*/
|
|
92
111
|
declare const useInitializeAutoConnect: ({ initializeAutoConnect, onError }: InitializeAutoConnectProps) => void;
|
|
93
112
|
|
|
94
113
|
/**
|
|
95
|
-
* Props
|
|
114
|
+
* Props of {@link SatelliteConnectProvider}: the store parameters (`adapter`, one adapter or an array, and the optional
|
|
115
|
+
* `callbackAfterConnected`, see `SatelliteConnectStoreInitialParameters` from `@tuwaio/satellite-core`) plus the
|
|
116
|
+
* fields below.
|
|
96
117
|
*/
|
|
97
118
|
interface SatelliteConnectProviderProps extends SatelliteConnectStoreInitialParameters<Connector, Connection> {
|
|
98
|
-
/**
|
|
119
|
+
/** Components that can read the store. */
|
|
99
120
|
children: React.ReactNode;
|
|
100
|
-
/**
|
|
121
|
+
/**
|
|
122
|
+
* Whether to reconnect the last connected wallet after a page load (read on the first render only). Defaults to
|
|
123
|
+
* `false`. See `initializeAutoConnect` of the store.
|
|
124
|
+
*/
|
|
101
125
|
autoConnect?: boolean;
|
|
102
126
|
}
|
|
103
127
|
/**
|
|
104
|
-
*
|
|
128
|
+
* Creates the Satellite Connect store (`createSatelliteConnectStore` from `@tuwaio/satellite-core`) and provides it to
|
|
129
|
+
* its children through {@link SatelliteStoreContext}. Read it with {@link useSatelliteConnectStore}.
|
|
105
130
|
*
|
|
106
|
-
*
|
|
107
|
-
*
|
|
108
|
-
*
|
|
109
|
-
*
|
|
131
|
+
* The store is created once, on the first render. When `adapter` or `callbackAfterConnected` changes, the new value
|
|
132
|
+
* is passed to the store's `updateParameters`; the state is kept. Define adapters outside the component (or memoize
|
|
133
|
+
* them), so a render does not create new adapter objects. After mount the provider
|
|
134
|
+
* calls the store's `initializeAutoConnect(autoConnect ?? false)` once, which disconnects the wallets of every adapter,
|
|
135
|
+
* cleans the recently connected list in `localStorage` and, with `autoConnect`, reconnects the last connected wallet.
|
|
136
|
+
* Inside Safe{Wallet} it connects the Safe connector instead, with or without `autoConnect`.
|
|
137
|
+
* Render the chain watchers (`EVMConnectorsWatcher` from `@tuwaio/satellite-react/evm`, `SolanaConnectorsWatcher`
|
|
138
|
+
* from `@tuwaio/satellite-react/solana`) inside it to follow wallet changes.
|
|
110
139
|
*
|
|
111
|
-
* @param props -
|
|
112
|
-
* @
|
|
113
|
-
* @param props.autoConnect - Optional flag to enable automatic connector reconnection
|
|
114
|
-
* @param props.adapter - Blockchain adapter(s) for connector interactions
|
|
115
|
-
* @param props.callbackAfterConnected - Optional callback for successful connections
|
|
140
|
+
* @param props - The store parameters, `autoConnect` and `children`. See {@link SatelliteConnectProviderProps}.
|
|
141
|
+
* @returns The context provider.
|
|
116
142
|
*
|
|
117
143
|
* @example
|
|
118
144
|
* ```tsx
|
|
119
|
-
*
|
|
120
|
-
* <SatelliteConnectProvider adapter={solanaAdapter}>
|
|
121
|
-
* <App />
|
|
122
|
-
* </SatelliteConnectProvider>
|
|
145
|
+
* 'use client';
|
|
123
146
|
*
|
|
124
|
-
*
|
|
125
|
-
*
|
|
126
|
-
*
|
|
127
|
-
*
|
|
128
|
-
*
|
|
129
|
-
*
|
|
130
|
-
*
|
|
131
|
-
*
|
|
132
|
-
*
|
|
133
|
-
*
|
|
147
|
+
* import { SatelliteConnectProvider } from '@tuwaio/satellite-react';
|
|
148
|
+
* import { satelliteSolanaAdapter } from '@tuwaio/satellite-solana';
|
|
149
|
+
* import type { ReactNode } from 'react';
|
|
150
|
+
*
|
|
151
|
+
* const solanaAdapter = satelliteSolanaAdapter({ rpcUrls: { devnet: 'https://api.devnet.solana.com' } });
|
|
152
|
+
*
|
|
153
|
+
* export function Providers({ children }: { children: ReactNode }) {
|
|
154
|
+
* return (
|
|
155
|
+
* <SatelliteConnectProvider
|
|
156
|
+
* adapter={solanaAdapter}
|
|
157
|
+
* autoConnect
|
|
158
|
+
* callbackAfterConnected={(connection) => console.log('Connected:', connection.address)}
|
|
159
|
+
* >
|
|
160
|
+
* {children}
|
|
161
|
+
* </SatelliteConnectProvider>
|
|
162
|
+
* );
|
|
163
|
+
* }
|
|
134
164
|
* ```
|
|
135
165
|
*/
|
|
136
|
-
declare function SatelliteConnectProvider({ children, autoConnect,
|
|
166
|
+
declare function SatelliteConnectProvider({ children, autoConnect, adapter, callbackAfterConnected, }: SatelliteConnectProviderProps): react.JSX.Element;
|
|
137
167
|
|
|
138
|
-
export { type AllConnections, type AllConnectors, type Connection, type Connector, SatelliteConnectProvider, type SatelliteConnectProviderProps, SatelliteStoreContext, useInitializeAutoConnect, useSatelliteConnectStore };
|
|
168
|
+
export { type AllConnections, type AllConnectors, type Connection, type Connector, type InitializeAutoConnectProps, SatelliteConnectProvider, type SatelliteConnectProviderProps, type SatelliteContextType, SatelliteStoreContext, useInitializeAutoConnect, useSatelliteConnectStore };
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
import {a}from'./chunk-4A4PSLAK.js';export{a as SatelliteStoreContext,b as useSatelliteConnectStore}from'./chunk-4A4PSLAK.js';import {useEffectEvent,useEffect,useMemo}from'react';import {createSatelliteConnectStore}from'@tuwaio/satellite-core';import {jsx}from'react/jsx-runtime';var s=({initializeAutoConnect:n,onError:r})=>{let e=useEffectEvent(async()=>n()),t=useEffectEvent(o=>{(r??(C=>console.error("Failed to initialize auto connect:",C)))(o);});useEffect(()=>{e().catch(o=>t(o));},[]);};function h({children:n,autoConnect:r,adapter:e,callbackAfterConnected:t}){let o=useMemo(()=>createSatelliteConnectStore({adapter:e,callbackAfterConnected:t}),[]);return useEffect(()=>{o.getState().updateParameters({adapter:e,callbackAfterConnected:t});},[o,e,t]),s({initializeAutoConnect:()=>o.getState().initializeAutoConnect(r??false)}),jsx(a.Provider,{value:o,children:n})}export{h as SatelliteConnectProvider,s as useInitializeAutoConnect};
|
package/dist/solana/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
'use strict';var
|
|
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 h({modules:a,siwx:r}){let l=a.useWallets(),o=chunkHEG6FP5Z_cjs.b(t=>t.activeConnection),e=chunkHEG6FP5Z_cjs.b(t=>t.updateActiveConnection),c=chunkHEG6FP5Z_cjs.b(t=>t.connectionError),s=chunkHEG6FP5Z_cjs.b(t=>t.disconnect),i=react.useContext(chunkHEG6FP5Z_cjs.a),S=chunkLSWAATDN_cjs.a(r),{createWatcher:p}=a;return react.useEffect(()=>p({wallets:l,siwx:S},{disconnect:s,updateActiveConnection:e,getState:()=>i?.getState()??{activeConnection:o,connectionError:c}}),[p,i,l,S,o?.connectorType,c,e,s]),null}function b(a={}){let[r,l]=react.useState(null);return react.useEffect(()=>{let o=true;return Promise.all([import('@tuwaio/satellite-solana'),import('@wallet-standard/react')]).then(([e,c])=>{o&&l({createWatcher:e.createSolanaConnectionsWatcher,useWallets:c.useWallets});}).catch(e=>console.warn("Failed to load Solana watcher:",e)),()=>{o=false;}},[]),r?jsxRuntime.jsx(h,{modules:r,...a}):null}exports.SolanaConnectorsWatcher=b;
|
package/dist/solana/index.d.cts
CHANGED
|
@@ -8,41 +8,52 @@ import { SatelliteSiwxState } from '@tuwaio/satellite-core';
|
|
|
8
8
|
*/
|
|
9
9
|
interface SolanaConnectorsWatcherProps {
|
|
10
10
|
/**
|
|
11
|
-
* Optional Sign-In With X (SIWX) session state
|
|
12
|
-
*
|
|
13
|
-
* Directly compatible with `useSiwxSession()` from `@tuwaio/siwx-react`.
|
|
11
|
+
* Optional Sign-In With X (SIWX) session state, for example the result of `useSiwxSession()` from
|
|
12
|
+
* `@tuwaio/siwx-react`. The watcher runs again when one of its fields changes.
|
|
14
13
|
*/
|
|
15
14
|
siwx?: SatelliteSiwxState;
|
|
16
15
|
}
|
|
17
16
|
/**
|
|
18
|
-
*
|
|
19
|
-
*
|
|
17
|
+
* Headless component that keeps the Satellite Connect store in sync with the Solana wallets of the Wallet Standard.
|
|
18
|
+
* Render it once inside `SatelliteConnectProvider`, next to a Solana adapter.
|
|
20
19
|
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
20
|
+
* After mount it loads `@tuwaio/satellite-solana` and `@wallet-standard/react` with dynamic imports. Whenever the list
|
|
21
|
+
* of registered wallets (from `useWallets`) changes, it runs `createSolanaConnectionsWatcher`: an account change in
|
|
22
|
+
* the connected wallet updates the active connection and a wallet without accounts is disconnected. With `siwx`, the
|
|
23
|
+
* connection is disconnected when the SIWX sign-in is rejected or fails, or when the account no longer matches the
|
|
24
|
+
* signed-in session. It also runs when a field of `siwx`, the active connector or the connection error changes. If an
|
|
25
|
+
* import fails, a warning is logged and nothing is watched.
|
|
26
|
+
*
|
|
27
|
+
* @param props - The component props. See {@link SolanaConnectorsWatcherProps}.
|
|
28
|
+
* @returns `null`; the component renders nothing.
|
|
23
29
|
*
|
|
24
30
|
* @example
|
|
25
31
|
* ```tsx
|
|
26
|
-
* import { useSiwxSession } from '@tuwaio/siwx-react';
|
|
27
32
|
* import { SolanaConnectorsWatcher } from '@tuwaio/satellite-react/solana';
|
|
33
|
+
* import { useSiwxSession } from '@tuwaio/siwx-react';
|
|
28
34
|
*
|
|
29
|
-
* function WatcherContainer() {
|
|
35
|
+
* export function WatcherContainer() {
|
|
30
36
|
* const siwxSession = useSiwxSession();
|
|
31
37
|
* return <SolanaConnectorsWatcher siwx={siwxSession} />;
|
|
32
38
|
* }
|
|
33
39
|
* ```
|
|
34
|
-
*
|
|
35
|
-
* @remarks
|
|
36
|
-
* Monitors Wallet Standard account changes. Automatically disconnects wallet state if SIWX
|
|
37
|
-
* session validation fails or is rejected.
|
|
38
40
|
*/
|
|
39
41
|
declare function SolanaConnectorsWatcher(props?: SolanaConnectorsWatcherProps): react.JSX.Element | null;
|
|
40
42
|
|
|
43
|
+
/**
|
|
44
|
+
* The Solana watcher component, imported from `@tuwaio/satellite-react/solana`. Importing this entry point also adds
|
|
45
|
+
* `SolanaConnection` and `ConnectorSolana` from `@tuwaio/satellite-solana` to `AllConnections` and `AllConnectors`.
|
|
46
|
+
*
|
|
47
|
+
* @module solana
|
|
48
|
+
*/
|
|
49
|
+
|
|
41
50
|
declare module '@tuwaio/satellite-react' {
|
|
42
51
|
interface AllConnections {
|
|
52
|
+
/** Solana connections (`SolanaConnection` from `@tuwaio/satellite-solana`), added by `@tuwaio/satellite-react/solana`. */
|
|
43
53
|
[OrbitAdapter.SOLANA]: SolanaConnection;
|
|
44
54
|
}
|
|
45
55
|
interface AllConnectors {
|
|
56
|
+
/** Wallet Standard wallets (`ConnectorSolana` from `@tuwaio/satellite-solana`), added by `@tuwaio/satellite-react/solana`. */
|
|
46
57
|
[OrbitAdapter.SOLANA]: ConnectorSolana;
|
|
47
58
|
}
|
|
48
59
|
}
|