@tuwaio/satellite-react 0.4.10 → 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/dist/index.d.cts CHANGED
@@ -3,136 +3,166 @@ import { ISatelliteConnectStore, SatelliteConnectStoreInitialParameters } from '
3
3
  import { StoreApi } from 'zustand';
4
4
 
5
5
  /**
6
- * @description
7
- * This interface is intentionally left empty.
8
- * Other packages (@tuwaio/satellite-*) will use module
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
- * @description
15
- * This interface is intentionally left empty.
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 type for all supported connection types.
22
- * It's created from the values of the AllConnections interface.
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 type for all supported connector types.
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
- * Custom hook for accessing the Satellite Connect store state
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
- * @typeParam T - The type of the selected state slice
41
- * @param selector - Function that selects a slice of the store state
42
- * @returns Selected state slice
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
- * @throws Error if used outside of SatelliteConnectProvider
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
- * // Get the active connection
49
- * const activeConnection = useSatelliteConnectStore((state) => state.activeConnection);
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
- * Props for the useInitializeAutoConnect hook.
64
+ * Parameters of {@link useInitializeAutoConnect}.
56
65
  */
57
66
  interface InitializeAutoConnectProps {
58
- /** Function to initialize auto connect logic */
67
+ /**
68
+ * Restores the connection, for example `() => store.getState().initializeAutoConnect(true)`.
69
+ *
70
+ * @returns Resolves when done.
71
+ */
59
72
  initializeAutoConnect: () => Promise<void>;
60
- /** Optional error handler callback */
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
- * Custom hook for initializing connector auto-connection with error handling.
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
- * @remarks
67
- * This hook handles the initial connection logic (e.g., checking for a previously
68
- * connected connector) when a component mounts.
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 - Hook configuration
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
- * // Basic usage with default error handling
79
- * useInitializeAutoConnect({
80
- * initializeAutoConnect: store.initializeAutoConnect
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
- * // With custom error handling
84
- * useInitializeAutoConnect({
85
- * initializeAutoConnect: store.initializeAutoConnect,
86
- * onError: (error) => {
87
- * toast.error(`Failed to auto-connect: ${error.message}`);
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 for SatelliteConnectProvider component
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
- /** React child components */
119
+ /** Components that can read the store. */
99
120
  children: React.ReactNode;
100
- /** Whether to automatically connect to last used connector */
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
- * Provider component that manages connector connections and state
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
- * @remarks
107
- * This component creates and provides the Satellite Connect store context to its children.
108
- * It handles connector connections, state management, and automatic reconnection functionality.
109
- * The store is memoized to ensure stable reference across renders.
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 - Component properties including store parameters and children
112
- * @param props.children - Child components that will have access to the store
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
- * // Basic usage with single adapter
120
- * <SatelliteConnectProvider adapter={solanaAdapter}>
121
- * <App />
122
- * </SatelliteConnectProvider>
145
+ * 'use client';
123
146
  *
124
- * // With auto-connect and multiple adapters
125
- * <SatelliteConnectProvider
126
- * adapter={[solanaAdapter, evmAdapter]}
127
- * autoConnect={true}
128
- * callbackAfterConnected={(wallet) => {
129
- * console.log('Wallet connected:', wallet.address);
130
- * }}
131
- * >
132
- * <App />
133
- * </SatelliteConnectProvider>
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, ...parameters }: SatelliteConnectProviderProps): react.JSX.Element;
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
- * @description
7
- * This interface is intentionally left empty.
8
- * Other packages (@tuwaio/satellite-*) will use module
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
- * @description
15
- * This interface is intentionally left empty.
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 type for all supported connection types.
22
- * It's created from the values of the AllConnections interface.
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 type for all supported connector types.
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
- * Custom hook for accessing the Satellite Connect store state
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
- * @typeParam T - The type of the selected state slice
41
- * @param selector - Function that selects a slice of the store state
42
- * @returns Selected state slice
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
- * @throws Error if used outside of SatelliteConnectProvider
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
- * // Get the active connection
49
- * const activeConnection = useSatelliteConnectStore((state) => state.activeConnection);
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
- * Props for the useInitializeAutoConnect hook.
64
+ * Parameters of {@link useInitializeAutoConnect}.
56
65
  */
57
66
  interface InitializeAutoConnectProps {
58
- /** Function to initialize auto connect logic */
67
+ /**
68
+ * Restores the connection, for example `() => store.getState().initializeAutoConnect(true)`.
69
+ *
70
+ * @returns Resolves when done.
71
+ */
59
72
  initializeAutoConnect: () => Promise<void>;
60
- /** Optional error handler callback */
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
- * Custom hook for initializing connector auto-connection with error handling.
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
- * @remarks
67
- * This hook handles the initial connection logic (e.g., checking for a previously
68
- * connected connector) when a component mounts.
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 - Hook configuration
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
- * // Basic usage with default error handling
79
- * useInitializeAutoConnect({
80
- * initializeAutoConnect: store.initializeAutoConnect
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
- * // With custom error handling
84
- * useInitializeAutoConnect({
85
- * initializeAutoConnect: store.initializeAutoConnect,
86
- * onError: (error) => {
87
- * toast.error(`Failed to auto-connect: ${error.message}`);
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 for SatelliteConnectProvider component
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
- /** React child components */
119
+ /** Components that can read the store. */
99
120
  children: React.ReactNode;
100
- /** Whether to automatically connect to last used connector */
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
- * Provider component that manages connector connections and state
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
- * @remarks
107
- * This component creates and provides the Satellite Connect store context to its children.
108
- * It handles connector connections, state management, and automatic reconnection functionality.
109
- * The store is memoized to ensure stable reference across renders.
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 - Component properties including store parameters and children
112
- * @param props.children - Child components that will have access to the store
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
- * // Basic usage with single adapter
120
- * <SatelliteConnectProvider adapter={solanaAdapter}>
121
- * <App />
122
- * </SatelliteConnectProvider>
145
+ * 'use client';
123
146
  *
124
- * // With auto-connect and multiple adapters
125
- * <SatelliteConnectProvider
126
- * adapter={[solanaAdapter, evmAdapter]}
127
- * autoConnect={true}
128
- * callbackAfterConnected={(wallet) => {
129
- * console.log('Wallet connected:', wallet.address);
130
- * }}
131
- * >
132
- * <App />
133
- * </SatelliteConnectProvider>
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, ...parameters }: SatelliteConnectProviderProps): react.JSX.Element;
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
- export{b as SatelliteConnectProvider,a as useInitializeAutoConnect}from'./chunk-UDS7MUYZ.js';export{a as SatelliteStoreContext,b as useSatelliteConnectStore}from'./chunk-EYVLQZ24.js';
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};
@@ -1 +1 @@
1
- 'use strict';var chunkG2YC6JBO_cjs=require('../chunk-G2YC6JBO.cjs'),react=require('react'),jsxRuntime=require('react/jsx-runtime');function x(o={}){let[c,m]=react.useState(null);return react.useEffect(()=>{(async()=>{try{let e=!1,l=null,i=null;try{let[r,a]=await Promise.all([import('@tuwaio/satellite-solana'),import('@wallet-standard/react')]);l=r.createSolanaConnectionsWatcher,i=a.useWallets,e=!0;}catch{e=!1;}if(e){let r=()=>{let a=i(),s=chunkG2YC6JBO_cjs.b(t=>t.activeConnection),p=chunkG2YC6JBO_cjs.b(t=>t.updateActiveConnection),u=chunkG2YC6JBO_cjs.b(t=>t.connectionError),S=chunkG2YC6JBO_cjs.b(t=>t.disconnect);return react.useEffect(()=>l({wallets:a,siwx:o.siwx},{activeConnection:s,disconnect:S,connectionError:u,updateActiveConnection:p}),[s?.connectorType,a,o.siwx,u,p,S]),null};m(()=>r);}}catch(e){console.warn("Failed to load Solana watcher:",e);}})();},[o.siwx]),c?jsxRuntime.jsx(c,{...o}):null}exports.SolanaConnectorsWatcher=x;
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;
@@ -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
- * If provided, the watcher will manage updates and disconnections based on SIWX status.
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
- * A dynamic version of the SolanaConnectorsWatcher component that avoids static imports.
19
- * This component dynamically imports the dependencies only when they are available.
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
- * @param props - Component props containing optional SIWX session state.
22
- * @returns null - This is a headless component
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
  }