@tuwaio/satellite-react 1.0.0-fix-watchers-alpha.1.39245f5 → 1.0.0-fix-evm-connectors-alpha.1.dbb88c1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -50,54 +50,63 @@ yarn add @tuwaio/satellite-react @tuwaio/satellite-core @tuwaio/orbit-core @wagm
50
50
  ### Basic Setup
51
51
  ```tsx
52
52
  import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
53
- import { satelliteEVMAdapter } from '@tuwaio/satellite-evm';
54
- import { EVMWalletsWatcher, SatelliteConnectProvider, SolanaWalletsWatcher } from '@tuwaio/satellite-react';
55
- import { initializeSolanaMobileConnectors, satelliteSolanaAdapter } from '@tuwaio/satellite-solana';
56
- import { ReactNode } from 'react';
53
+ import { satelliteEVMAdapter, createDefaultTransports, initAllConnectors } from '@tuwaio/satellite-evm';
54
+ import { SatelliteConnectProvider } from '@tuwaio/satellite-react';
55
+ import { EVMWalletsWatcher } from '@tuwaio/satellite-react/evm';
56
+ import { SolanaWalletsWatcher } from '@tuwaio/satellite-react/solana';
57
+ import { satelliteSolanaAdapter } from '@tuwaio/satellite-solana';
57
58
  import { WagmiProvider } from 'wagmi';
58
- import { createWagmiConfig } from '@tuwaio/satellite-evm';
59
- import { Chain, mainnet, sepolia } from 'viem/chains';
59
+ import { ReactNode } from 'react';
60
+ import { createConfig, http } from '@wagmi/core';
61
+ import { mainnet, sepolia } from 'viem/chains';
62
+ import type { Chain } from 'viem/chains';
60
63
 
61
64
  export const appConfig = {
62
- appName: 'Satellite EVM Test App',
65
+ appName: 'Satellite EVM Test App',
66
+ // Ensure you have WalletConnect Project ID in your environment variables
67
+ projectId: process.env.NEXT_PUBLIC_WALLET_PROJECT_ID ?? 'YOUR_OWN_PROJECT_ID',
63
68
  };
64
69
 
70
+ export const appEVMChains = [
71
+ mainnet,
72
+ sepolia,
73
+ ] as readonly [Chain, ...Chain[]];
74
+
75
+ export const wagmiConfig = createConfig({
76
+ connectors: initAllConnectors({
77
+ ...appConfig,
78
+ // Optional: Add app details for WalletConnect modal
79
+ description: 'My awesome dApp',
80
+ appUrl: '[https://my-dapp.com](https://my-dapp.com)',
81
+ appIcons: ['[https://my-dapp.com/icon.png](https://my-dapp.com/icon.png)'],
82
+ }),
83
+ transports: createDefaultTransports(appEVMChains), // Automatically creates http transports
84
+ chains: appEVMChains,
85
+ ssr: true, // Enable SSR support if needed (e.g., in Next.js)
86
+ });
87
+
65
88
  export const solanaRPCUrls = {
66
- devnet: 'https://api.devnet.solana.com',
89
+ devnet: 'https://api.devnet.solana.com',
67
90
  };
68
91
 
69
- export const appEVMChains = [mainnet, sepolia] as readonly [Chain, ...Chain[]];
70
-
71
- export const wagmiConfig = createWagmiConfig({
72
- ...appConfig,
73
- chains: appEVMChains,
74
- ssr: true,
75
- syncConnectedChain: true,
76
- });
77
-
78
92
 
79
93
  const queryClient = new QueryClient();
80
94
 
81
- initializeSolanaMobileConnectors({
82
- rpcUrls: solanaRPCUrls,
83
- ...appConfig,
84
- });
85
-
86
95
  export function Providers({ children }: { children: ReactNode }) {
87
- return (
88
- <WagmiProvider config={wagmiConfig}>
89
- <QueryClientProvider client={queryClient}>
90
- <SatelliteConnectProvider
91
- adapter={[satelliteEVMAdapter(wagmiConfig), satelliteSolanaAdapter({ rpcUrls: solanaRPCUrls })]}
92
- autoConnect={true}
93
- >
94
- <EVMWalletsWatcher wagmiConfig={wagmiConfig} />
95
- <SolanaWalletsWatcher />
96
- {children}
97
- </SatelliteConnectProvider>
98
- </QueryClientProvider>
99
- </WagmiProvider>
100
- );
96
+ return (
97
+ <WagmiProvider config={wagmiConfig}>
98
+ <QueryClientProvider client={queryClient}>
99
+ <SatelliteConnectProvider
100
+ adapter={[satelliteEVMAdapter(wagmiConfig), satelliteSolanaAdapter({ rpcUrls: solanaRPCUrls })]}
101
+ autoConnect={true}
102
+ >
103
+ <EVMWalletsWatcher wagmiConfig={wagmiConfig} />
104
+ <SolanaWalletsWatcher />
105
+ {children}
106
+ </SatelliteConnectProvider>
107
+ </QueryClientProvider>
108
+ </WagmiProvider>
109
+ );
101
110
  }
102
111
  ```
103
112
 
@@ -136,7 +145,3 @@ If you find this library useful, please consider supporting its development. Eve
136
145
  ## 📄 License
137
146
 
138
147
  This project is licensed under the **Apache-2.0 License** - see the [LICENSE](./LICENSE) file for details.
139
-
140
- ## 👥 Contributors
141
-
142
- - **Oleksandr Tkach** - [GitHub](https://github.com/Argeare5)
@@ -1,2 +1,2 @@
1
- 'use strict';var chunkYC7F3NGW_cjs=require('../chunk-YC7F3NGW.cjs'),orbitCore=require('@tuwaio/orbit-core'),core=require('@wagmi/core'),react=require('react');function V({wagmiConfig:c,siwe:n}){let a=chunkYC7F3NGW_cjs.b(t=>t.activeWallet),o=chunkYC7F3NGW_cjs.b(t=>t.disconnect),l=chunkYC7F3NGW_cjs.b(t=>t.walletConnectionError),s=chunkYC7F3NGW_cjs.b(t=>t.updateActiveWallet);return react.useEffect(()=>{n?.enabled&&!n?.isSignedIn&&n?.isRejected&&o();},[n,o]),react.useEffect(()=>core.watchAccount(c,{onChange:e=>{if(e?.status==="disconnected"&&o(),a&&orbitCore.getAdapterFromWalletType(a.walletType)!==orbitCore.OrbitAdapter.EVM||!e.address||l)return;if(n?.enabled?n.isSignedIn:true){let d=a?.walletType,p=d?{walletType:d,address:e.address,chainId:e.chainId,rpcURL:e.chain?.rpcUrls.default.http[0],isConnected:e.isConnected}:{address:e.address,chainId:e.chainId,rpcURL:e.chain?.rpcUrls.default.http[0],isConnected:e.isConnected};s(p);}}}),[a?.walletType,n,l]),null}exports.EVMWalletsWatcher=V;//# sourceMappingURL=index.cjs.map
1
+ 'use strict';var chunkYC7F3NGW_cjs=require('../chunk-YC7F3NGW.cjs'),orbitCore=require('@tuwaio/orbit-core'),core=require('@wagmi/core'),react=require('react');function V({wagmiConfig:i,siwe:n}){let a=chunkYC7F3NGW_cjs.b(t=>t.activeWallet),l=chunkYC7F3NGW_cjs.b(t=>t.disconnect),o=chunkYC7F3NGW_cjs.b(t=>t.walletConnectionError),s=chunkYC7F3NGW_cjs.b(t=>t.updateActiveWallet);return react.useEffect(()=>{n?.enabled&&!n?.isSignedIn&&n?.isRejected&&l();},[n,l]),react.useEffect(()=>core.watchAccount(i,{onChange:e=>{if(e?.status==="disconnected"&&l(),a&&orbitCore.getAdapterFromWalletType(a.walletType)!==orbitCore.OrbitAdapter.EVM||!e.address||o)return;if(n?.enabled?n.isSignedIn:true){let c=a?.walletType,p=c?{walletType:c,address:e.address,chainId:e.chainId,rpcURL:e.chain?.rpcUrls.default.http[0],isConnected:e.isConnected}:{address:e.address,chainId:e.chainId,rpcURL:e.chain?.rpcUrls.default.http[0],isConnected:e.isConnected};s(p);}}}),[a?.walletType,n,o]),null}exports.EVMWalletsWatcher=V;//# sourceMappingURL=index.cjs.map
2
2
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/evm/EVMWalletsWatcher.tsx"],"names":["EVMWalletsWatcher","wagmiConfig","siwe","activeWallet","useSatelliteConnectStore","store","disconnect","walletConnectionError","updateActiveWallet","useEffect","watchAccount","account","getAdapterFromWalletType","OrbitAdapter","walletType","walletUpdate"],"mappings":"+JAMO,SAASA,CAAAA,CAAkB,CAChC,WAAA,CAAAC,CAAAA,CACA,IAAA,CAAAC,CACF,EAQG,CACD,IAAMC,CAAAA,CAAeC,mBAAAA,CAA0BC,GAAUA,CAAAA,CAAM,YAAY,CAAA,CACrEC,CAAAA,CAAaF,oBAA0BC,CAAAA,EAAUA,CAAAA,CAAM,UAAU,CAAA,CACjEE,EAAwBH,mBAAAA,CAA0BC,CAAAA,EAAUA,CAAAA,CAAM,qBAAqB,EACvFG,CAAAA,CAAqBJ,mBAAAA,CAA0BC,CAAAA,EAAUA,CAAAA,CAAM,kBAAkB,CAAA,CAEvF,OAAAI,eAAAA,CAAU,IAAM,CACVP,CAAAA,EAAM,OAAA,EAAW,CAACA,CAAAA,EAAM,YAAcA,CAAAA,EAAM,UAAA,EAC9CI,CAAAA,GAEJ,EAAG,CAACJ,CAAAA,CAAMI,CAAU,CAAC,EAErBG,eAAAA,CAAU,IAqCQC,iBAAAA,CAAaT,CAAAA,CAAa,CAAE,QAAA,CApCqBU,CAAAA,EAAY,CAK3E,GAJIA,CAAAA,EAAS,SAAW,cAAA,EACtBL,CAAAA,EAAW,CAIVH,CAAAA,EAAgBS,mCAAyBT,CAAAA,CAAa,UAAU,CAAA,GAAMU,sBAAAA,CAAa,KACpF,CAACF,CAAAA,CAAQ,OAAA,EACTJ,CAAAA,CAEA,OAKF,GAFqBL,CAAAA,EAAM,OAAA,CAAUA,CAAAA,CAAK,WAAa,IAAA,CAErC,CAChB,IAAMY,CAAAA,CAAaX,GAAc,UAAA,CAC3BY,CAAAA,CAAeD,CAAAA,CACjB,CACE,WAAAA,CAAAA,CACA,OAAA,CAASH,CAAAA,CAAQ,OAAA,CACjB,QAASA,CAAAA,CAAQ,OAAA,CACjB,OAAQA,CAAAA,CAAQ,KAAA,EAAO,QAAQ,OAAA,CAAQ,IAAA,CAAK,CAAC,CAAA,CAC7C,YAAaA,CAAAA,CAAQ,WACvB,CAAA,CACA,CACE,QAASA,CAAAA,CAAQ,OAAA,CACjB,OAAA,CAASA,CAAAA,CAAQ,QACjB,MAAA,CAAQA,CAAAA,CAAQ,KAAA,EAAO,OAAA,CAAQ,QAAQ,IAAA,CAAK,CAAC,CAAA,CAC7C,WAAA,CAAaA,EAAQ,WACvB,CAAA,CAEJH,CAAAA,CAAmBO,CAAY,EACjC,CACF,CAE0E,CAAC,CAAA,CAI1E,CAACZ,CAAAA,EAAc,UAAA,CAAYD,EAAMK,CAAqB,CAAC,EAEnD,IACT","file":"index.cjs","sourcesContent":["import { getAdapterFromWalletType, OrbitAdapter } from '@tuwaio/orbit-core';\nimport { Config, watchAccount, WatchAccountParameters } from '@wagmi/core';\nimport { useEffect } from 'react';\n\nimport { useSatelliteConnectStore } from '../index';\n\nexport function EVMWalletsWatcher({\n wagmiConfig,\n siwe,\n}: {\n wagmiConfig: Config;\n\n siwe?: {\n isRejected: boolean;\n isSignedIn: boolean;\n enabled?: boolean;\n };\n}) {\n const activeWallet = useSatelliteConnectStore((store) => store.activeWallet);\n const disconnect = useSatelliteConnectStore((store) => store.disconnect);\n const walletConnectionError = useSatelliteConnectStore((store) => store.walletConnectionError);\n const updateActiveWallet = useSatelliteConnectStore((store) => store.updateActiveWallet);\n\n useEffect(() => {\n if (siwe?.enabled && !siwe?.isSignedIn && siwe?.isRejected) {\n disconnect();\n }\n }, [siwe, disconnect]);\n\n useEffect(() => {\n const handleAccountChange: WatchAccountParameters['onChange'] = (account) => {\n if (account?.status === 'disconnected') {\n disconnect();\n }\n\n if (\n (activeWallet && getAdapterFromWalletType(activeWallet.walletType) !== OrbitAdapter.EVM) ||\n !account.address ||\n walletConnectionError\n ) {\n return;\n }\n\n const shouldUpdate = siwe?.enabled ? siwe.isSignedIn : true;\n\n if (shouldUpdate) {\n const walletType = activeWallet?.walletType;\n const walletUpdate = walletType\n ? {\n walletType,\n address: account.address,\n chainId: account.chainId,\n rpcURL: account.chain?.rpcUrls.default.http[0],\n isConnected: account.isConnected,\n }\n : {\n address: account.address,\n chainId: account.chainId,\n rpcURL: account.chain?.rpcUrls.default.http[0],\n isConnected: account.isConnected,\n };\n\n updateActiveWallet(walletUpdate);\n }\n };\n\n const unwatch = watchAccount(wagmiConfig, { onChange: handleAccountChange });\n\n return unwatch;\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [activeWallet?.walletType, siwe, walletConnectionError]);\n\n return null;\n}\n"]}
1
+ {"version":3,"sources":["../../src/evm/EVMWalletsWatcher.tsx"],"names":["EVMWalletsWatcher","wagmiConfig","siwe","activeWallet","useSatelliteConnectStore","store","disconnect","walletConnectionError","updateActiveWallet","useEffect","watchAccount","account","getAdapterFromWalletType","OrbitAdapter","walletType","walletUpdate"],"mappings":"+JAiDO,SAASA,CAAAA,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ACjB,OAAA,CAASA,CAAAA,CAAQ,QACjB,MAAA,CAAQA,CAAAA,CAAQ,KAAA,EAAO,OAAA,CAAQ,QAAQ,IAAA,CAAK,CAAC,CAAA,CAC7C,WAAA,CAAaA,EAAQ,WACvB,CAAA,CAGJH,CAAAA,CAAmBO,CAAY,EACjC,CACF,CAG0E,CAAC,CAAA,CAO1E,CAACZ,CAAAA,EAAc,UAAA,CAAYD,EAAMK,CAAqB,CAAC,EAGnD,IACT","file":"index.cjs","sourcesContent":["import { getAdapterFromWalletType, OrbitAdapter } from '@tuwaio/orbit-core';\nimport { Config, watchAccount, WatchAccountParameters } from '@wagmi/core';\nimport { useEffect } from 'react';\n\nimport { useSatelliteConnectStore } from '../index';\n\n/**\n * Props for the {@link EVMWalletsWatcher} component.\n */\ninterface EVMWalletsWatcherProps {\n /**\n * The configuration object from `@wagmi/core`.\n * This is required to initialize the account watcher.\n */\n wagmiConfig: Config;\n\n /**\n * Optional object representing the Sign-In With Ethereum (SIWE) state.\n * If provided, the watcher will use this state to manage updates\n * and disconnections based on SIWE status.\n */\n siwe?: {\n /**\n * Flag indicating if the SIWE authentication request was rejected by the user.\n */\n isRejected: boolean;\n /**\n * Flag indicating if the user is successfully signed in via SIWE.\n */\n isSignedIn: boolean;\n /**\n * Flag indicating if the SIWE flow is enabled.\n */\n enabled?: boolean;\n };\n}\n\n/**\n * A headless React component (renders `null`) that synchronizes the EVM wallet\n * state from `@wagmi/core` with the global `useSatelliteConnectStore`.\n *\n * It is responsible for:\n * 1. Automatically disconnecting if a SIWE (Sign-In With Ethereum) request is rejected.\n * 2. Listening for account changes (e.g., account switch, chain switch, disconnect)\n * from `wagmi` and updating the global store accordingly.\n *\n * @param props - The component's props. See {@link EVMWalletsWatcherProps}.\n * @returns {null} This component does not render any UI.\n */\nexport function EVMWalletsWatcher({ wagmiConfig, siwe }: EVMWalletsWatcherProps) {\n // --- Global Store State ---\n // Subscribes to parts of the global Zustand store.\n\n /**\n * The currently active wallet object from the global store.\n */\n const activeWallet = useSatelliteConnectStore((store) => store.activeWallet);\n /**\n * The global function to trigger a wallet disconnection.\n */\n const disconnect = useSatelliteConnectStore((store) => store.disconnect);\n /**\n * The current connection error state, if any.\n */\n const walletConnectionError = useSatelliteConnectStore((store) => store.walletConnectionError);\n /**\n * The global function to update the active wallet's details.\n */\n const updateActiveWallet = useSatelliteConnectStore((store) => store.updateActiveWallet);\n\n // --- Effects ---\n\n /**\n * Effect: Handles SIWE rejection.\n *\n * If the SIWE flow is enabled (`siwe.enabled`), the user is not yet\n * signed in (`!siwe.isSignedIn`), and they have explicitly rejected\n * the SIWE signature request (`siwe.isRejected`), this effect\n * will call the global `disconnect` function.\n */\n useEffect(() => {\n if (siwe?.enabled && !siwe?.isSignedIn && siwe?.isRejected) {\n disconnect();\n }\n }, [siwe, disconnect]);\n\n /**\n * Effect: Subscribes to wagmi account changes.\n *\n * This effect initializes `watchAccount` from `@wagmi/core` to listen for\n * any changes in the connected wallet's state (like switching accounts,\n * changing networks, or disconnecting).\n */\n useEffect(() => {\n /**\n * Callback function triggered by `watchAccount` whenever the\n * wagmi account state changes.\n *\n * @param account - The new account state provided by wagmi.\n */\n const handleAccountChange: WatchAccountParameters['onChange'] = (account) => {\n // Case 1: The wallet was disconnected from the provider (e.g., MetaMask).\n if (account?.status === 'disconnected') {\n disconnect();\n }\n\n // --- Guard Clauses ---\n // Stop processing if any of these conditions are true:\n // 1. The currently active wallet in our store is NOT an EVM wallet\n // (we don't want this watcher to override a non-EVM wallet).\n // 2. The new account state from wagmi has no address.\n // 3. There is already a connection error in our global store.\n if (\n (activeWallet && getAdapterFromWalletType(activeWallet.walletType) !== OrbitAdapter.EVM) ||\n !account.address ||\n walletConnectionError\n ) {\n return;\n }\n\n /**\n * Determines if the global store *should* be updated.\n * - If SIWE is enabled, we only update the store if the user is signed in.\n * - If SIWE is not enabled, we always update the store.\n */\n const shouldUpdate = siwe?.enabled ? siwe.isSignedIn : true;\n\n if (shouldUpdate) {\n // Preserve the `walletType` if it already exists in the active wallet.\n const walletType = activeWallet?.walletType;\n\n /**\n * The payload to send to the global store update function.\n */\n const walletUpdate = walletType\n ? {\n // Preserve the walletType (e.g., 'metamask', 'walletconnect')\n walletType,\n address: account.address,\n chainId: account.chainId,\n rpcURL: account.chain?.rpcUrls.default.http[0],\n isConnected: account.isConnected,\n }\n : {\n // Fallback if activeWallet was null or had no type\n address: account.address,\n chainId: account.chainId,\n rpcURL: account.chain?.rpcUrls.default.http[0],\n isConnected: account.isConnected,\n };\n\n // Update the global store with the new wallet state.\n updateActiveWallet(walletUpdate);\n }\n };\n\n // Activate the watcher\n const unwatch = watchAccount(wagmiConfig, { onChange: handleAccountChange });\n\n // Return the cleanup function.\n // This `unwatch` function will be called when the component unmounts\n // or when the dependencies in the array change, preventing memory leaks.\n return unwatch;\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [activeWallet?.walletType, siwe, walletConnectionError]);\n\n // This component is \"headless\" - it performs logic but renders nothing.\n return null;\n}\n"]}
@@ -2,14 +2,48 @@ import { OrbitAdapter } from '@tuwaio/orbit-core';
2
2
  import { EVMWallet, ConnectorEVM } from '@tuwaio/satellite-evm';
3
3
  import { Config } from '@wagmi/core';
4
4
 
5
- declare function EVMWalletsWatcher({ wagmiConfig, siwe, }: {
5
+ /**
6
+ * Props for the {@link EVMWalletsWatcher} component.
7
+ */
8
+ interface EVMWalletsWatcherProps {
9
+ /**
10
+ * The configuration object from `@wagmi/core`.
11
+ * This is required to initialize the account watcher.
12
+ */
6
13
  wagmiConfig: Config;
14
+ /**
15
+ * Optional object representing the Sign-In With Ethereum (SIWE) state.
16
+ * If provided, the watcher will use this state to manage updates
17
+ * and disconnections based on SIWE status.
18
+ */
7
19
  siwe?: {
20
+ /**
21
+ * Flag indicating if the SIWE authentication request was rejected by the user.
22
+ */
8
23
  isRejected: boolean;
24
+ /**
25
+ * Flag indicating if the user is successfully signed in via SIWE.
26
+ */
9
27
  isSignedIn: boolean;
28
+ /**
29
+ * Flag indicating if the SIWE flow is enabled.
30
+ */
10
31
  enabled?: boolean;
11
32
  };
12
- }): null;
33
+ }
34
+ /**
35
+ * A headless React component (renders `null`) that synchronizes the EVM wallet
36
+ * state from `@wagmi/core` with the global `useSatelliteConnectStore`.
37
+ *
38
+ * It is responsible for:
39
+ * 1. Automatically disconnecting if a SIWE (Sign-In With Ethereum) request is rejected.
40
+ * 2. Listening for account changes (e.g., account switch, chain switch, disconnect)
41
+ * from `wagmi` and updating the global store accordingly.
42
+ *
43
+ * @param props - The component's props. See {@link EVMWalletsWatcherProps}.
44
+ * @returns {null} This component does not render any UI.
45
+ */
46
+ declare function EVMWalletsWatcher({ wagmiConfig, siwe }: EVMWalletsWatcherProps): null;
13
47
 
14
48
  declare module '@tuwaio/satellite-react' {
15
49
  interface AllWallets {
@@ -2,14 +2,48 @@ import { OrbitAdapter } from '@tuwaio/orbit-core';
2
2
  import { EVMWallet, ConnectorEVM } from '@tuwaio/satellite-evm';
3
3
  import { Config } from '@wagmi/core';
4
4
 
5
- declare function EVMWalletsWatcher({ wagmiConfig, siwe, }: {
5
+ /**
6
+ * Props for the {@link EVMWalletsWatcher} component.
7
+ */
8
+ interface EVMWalletsWatcherProps {
9
+ /**
10
+ * The configuration object from `@wagmi/core`.
11
+ * This is required to initialize the account watcher.
12
+ */
6
13
  wagmiConfig: Config;
14
+ /**
15
+ * Optional object representing the Sign-In With Ethereum (SIWE) state.
16
+ * If provided, the watcher will use this state to manage updates
17
+ * and disconnections based on SIWE status.
18
+ */
7
19
  siwe?: {
20
+ /**
21
+ * Flag indicating if the SIWE authentication request was rejected by the user.
22
+ */
8
23
  isRejected: boolean;
24
+ /**
25
+ * Flag indicating if the user is successfully signed in via SIWE.
26
+ */
9
27
  isSignedIn: boolean;
28
+ /**
29
+ * Flag indicating if the SIWE flow is enabled.
30
+ */
10
31
  enabled?: boolean;
11
32
  };
12
- }): null;
33
+ }
34
+ /**
35
+ * A headless React component (renders `null`) that synchronizes the EVM wallet
36
+ * state from `@wagmi/core` with the global `useSatelliteConnectStore`.
37
+ *
38
+ * It is responsible for:
39
+ * 1. Automatically disconnecting if a SIWE (Sign-In With Ethereum) request is rejected.
40
+ * 2. Listening for account changes (e.g., account switch, chain switch, disconnect)
41
+ * from `wagmi` and updating the global store accordingly.
42
+ *
43
+ * @param props - The component's props. See {@link EVMWalletsWatcherProps}.
44
+ * @returns {null} This component does not render any UI.
45
+ */
46
+ declare function EVMWalletsWatcher({ wagmiConfig, siwe }: EVMWalletsWatcherProps): null;
13
47
 
14
48
  declare module '@tuwaio/satellite-react' {
15
49
  interface AllWallets {
package/dist/evm/index.js CHANGED
@@ -1,2 +1,2 @@
1
- import {b}from'../chunk-3WMGCMYX.js';import {getAdapterFromWalletType,OrbitAdapter}from'@tuwaio/orbit-core';import {watchAccount}from'@wagmi/core';import {useEffect}from'react';function V({wagmiConfig:c,siwe:n}){let a=b(t=>t.activeWallet),o=b(t=>t.disconnect),l=b(t=>t.walletConnectionError),s=b(t=>t.updateActiveWallet);return useEffect(()=>{n?.enabled&&!n?.isSignedIn&&n?.isRejected&&o();},[n,o]),useEffect(()=>watchAccount(c,{onChange:e=>{if(e?.status==="disconnected"&&o(),a&&getAdapterFromWalletType(a.walletType)!==OrbitAdapter.EVM||!e.address||l)return;if(n?.enabled?n.isSignedIn:true){let d=a?.walletType,p=d?{walletType:d,address:e.address,chainId:e.chainId,rpcURL:e.chain?.rpcUrls.default.http[0],isConnected:e.isConnected}:{address:e.address,chainId:e.chainId,rpcURL:e.chain?.rpcUrls.default.http[0],isConnected:e.isConnected};s(p);}}}),[a?.walletType,n,l]),null}export{V as EVMWalletsWatcher};//# sourceMappingURL=index.js.map
1
+ import {b}from'../chunk-3WMGCMYX.js';import {getAdapterFromWalletType,OrbitAdapter}from'@tuwaio/orbit-core';import {watchAccount}from'@wagmi/core';import {useEffect}from'react';function V({wagmiConfig:i,siwe:n}){let a=b(t=>t.activeWallet),l=b(t=>t.disconnect),o=b(t=>t.walletConnectionError),s=b(t=>t.updateActiveWallet);return useEffect(()=>{n?.enabled&&!n?.isSignedIn&&n?.isRejected&&l();},[n,l]),useEffect(()=>watchAccount(i,{onChange:e=>{if(e?.status==="disconnected"&&l(),a&&getAdapterFromWalletType(a.walletType)!==OrbitAdapter.EVM||!e.address||o)return;if(n?.enabled?n.isSignedIn:true){let c=a?.walletType,p=c?{walletType:c,address:e.address,chainId:e.chainId,rpcURL:e.chain?.rpcUrls.default.http[0],isConnected:e.isConnected}:{address:e.address,chainId:e.chainId,rpcURL:e.chain?.rpcUrls.default.http[0],isConnected:e.isConnected};s(p);}}}),[a?.walletType,n,o]),null}export{V as EVMWalletsWatcher};//# sourceMappingURL=index.js.map
2
2
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/evm/EVMWalletsWatcher.tsx"],"names":["EVMWalletsWatcher","wagmiConfig","siwe","activeWallet","useSatelliteConnectStore","store","disconnect","walletConnectionError","updateActiveWallet","useEffect","watchAccount","account","getAdapterFromWalletType","OrbitAdapter","walletType","walletUpdate"],"mappings":"iLAMO,SAASA,CAAAA,CAAkB,CAChC,WAAA,CAAAC,CAAAA,CACA,IAAA,CAAAC,CACF,EAQG,CACD,IAAMC,CAAAA,CAAeC,CAAAA,CAA0BC,GAAUA,CAAAA,CAAM,YAAY,CAAA,CACrEC,CAAAA,CAAaF,EAA0BC,CAAAA,EAAUA,CAAAA,CAAM,UAAU,CAAA,CACjEE,EAAwBH,CAAAA,CAA0BC,CAAAA,EAAUA,CAAAA,CAAM,qBAAqB,EACvFG,CAAAA,CAAqBJ,CAAAA,CAA0BC,CAAAA,EAAUA,CAAAA,CAAM,kBAAkB,CAAA,CAEvF,OAAAI,SAAAA,CAAU,IAAM,CACVP,CAAAA,EAAM,OAAA,EAAW,CAACA,CAAAA,EAAM,YAAcA,CAAAA,EAAM,UAAA,EAC9CI,CAAAA,GAEJ,EAAG,CAACJ,CAAAA,CAAMI,CAAU,CAAC,EAErBG,SAAAA,CAAU,IAqCQC,YAAAA,CAAaT,CAAAA,CAAa,CAAE,QAAA,CApCqBU,CAAAA,EAAY,CAK3E,GAJIA,CAAAA,EAAS,SAAW,cAAA,EACtBL,CAAAA,EAAW,CAIVH,CAAAA,EAAgBS,yBAAyBT,CAAAA,CAAa,UAAU,CAAA,GAAMU,YAAAA,CAAa,KACpF,CAACF,CAAAA,CAAQ,OAAA,EACTJ,CAAAA,CAEA,OAKF,GAFqBL,CAAAA,EAAM,OAAA,CAAUA,CAAAA,CAAK,WAAa,IAAA,CAErC,CAChB,IAAMY,CAAAA,CAAaX,GAAc,UAAA,CAC3BY,CAAAA,CAAeD,CAAAA,CACjB,CACE,WAAAA,CAAAA,CACA,OAAA,CAASH,CAAAA,CAAQ,OAAA,CACjB,QAASA,CAAAA,CAAQ,OAAA,CACjB,OAAQA,CAAAA,CAAQ,KAAA,EAAO,QAAQ,OAAA,CAAQ,IAAA,CAAK,CAAC,CAAA,CAC7C,YAAaA,CAAAA,CAAQ,WACvB,CAAA,CACA,CACE,QAASA,CAAAA,CAAQ,OAAA,CACjB,OAAA,CAASA,CAAAA,CAAQ,QACjB,MAAA,CAAQA,CAAAA,CAAQ,KAAA,EAAO,OAAA,CAAQ,QAAQ,IAAA,CAAK,CAAC,CAAA,CAC7C,WAAA,CAAaA,EAAQ,WACvB,CAAA,CAEJH,CAAAA,CAAmBO,CAAY,EACjC,CACF,CAE0E,CAAC,CAAA,CAI1E,CAACZ,CAAAA,EAAc,UAAA,CAAYD,EAAMK,CAAqB,CAAC,EAEnD,IACT","file":"index.js","sourcesContent":["import { getAdapterFromWalletType, OrbitAdapter } from '@tuwaio/orbit-core';\nimport { Config, watchAccount, WatchAccountParameters } from '@wagmi/core';\nimport { useEffect } from 'react';\n\nimport { useSatelliteConnectStore } from '../index';\n\nexport function EVMWalletsWatcher({\n wagmiConfig,\n siwe,\n}: {\n wagmiConfig: Config;\n\n siwe?: {\n isRejected: boolean;\n isSignedIn: boolean;\n enabled?: boolean;\n };\n}) {\n const activeWallet = useSatelliteConnectStore((store) => store.activeWallet);\n const disconnect = useSatelliteConnectStore((store) => store.disconnect);\n const walletConnectionError = useSatelliteConnectStore((store) => store.walletConnectionError);\n const updateActiveWallet = useSatelliteConnectStore((store) => store.updateActiveWallet);\n\n useEffect(() => {\n if (siwe?.enabled && !siwe?.isSignedIn && siwe?.isRejected) {\n disconnect();\n }\n }, [siwe, disconnect]);\n\n useEffect(() => {\n const handleAccountChange: WatchAccountParameters['onChange'] = (account) => {\n if (account?.status === 'disconnected') {\n disconnect();\n }\n\n if (\n (activeWallet && getAdapterFromWalletType(activeWallet.walletType) !== OrbitAdapter.EVM) ||\n !account.address ||\n walletConnectionError\n ) {\n return;\n }\n\n const shouldUpdate = siwe?.enabled ? siwe.isSignedIn : true;\n\n if (shouldUpdate) {\n const walletType = activeWallet?.walletType;\n const walletUpdate = walletType\n ? {\n walletType,\n address: account.address,\n chainId: account.chainId,\n rpcURL: account.chain?.rpcUrls.default.http[0],\n isConnected: account.isConnected,\n }\n : {\n address: account.address,\n chainId: account.chainId,\n rpcURL: account.chain?.rpcUrls.default.http[0],\n isConnected: account.isConnected,\n };\n\n updateActiveWallet(walletUpdate);\n }\n };\n\n const unwatch = watchAccount(wagmiConfig, { onChange: handleAccountChange });\n\n return unwatch;\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [activeWallet?.walletType, siwe, walletConnectionError]);\n\n return null;\n}\n"]}
1
+ {"version":3,"sources":["../../src/evm/EVMWalletsWatcher.tsx"],"names":["EVMWalletsWatcher","wagmiConfig","siwe","activeWallet","useSatelliteConnectStore","store","disconnect","walletConnectionError","updateActiveWallet","useEffect","watchAccount","account","getAdapterFromWalletType","OrbitAdapter","walletType","walletUpdate"],"mappings":"iLAiDO,SAASA,CAAAA,CAAkB,CAAE,WAAA,CAAAC,CAAAA,CAAa,IAAA,CAAAC,CAAK,EAA2B,CAO/E,IAAMC,CAAAA,CAAeC,CAAAA,CAA0BC,GAAUA,CAAAA,CAAM,YA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,EAAQ,WACvB,CAAA,CAGJH,CAAAA,CAAmBO,CAAY,EACjC,CACF,CAG0E,CAAC,CAAA,CAO1E,CAACZ,CAAAA,EAAc,UAAA,CAAYD,EAAMK,CAAqB,CAAC,EAGnD,IACT","file":"index.js","sourcesContent":["import { getAdapterFromWalletType, OrbitAdapter } from '@tuwaio/orbit-core';\nimport { Config, watchAccount, WatchAccountParameters } from '@wagmi/core';\nimport { useEffect } from 'react';\n\nimport { useSatelliteConnectStore } from '../index';\n\n/**\n * Props for the {@link EVMWalletsWatcher} component.\n */\ninterface EVMWalletsWatcherProps {\n /**\n * The configuration object from `@wagmi/core`.\n * This is required to initialize the account watcher.\n */\n wagmiConfig: Config;\n\n /**\n * Optional object representing the Sign-In With Ethereum (SIWE) state.\n * If provided, the watcher will use this state to manage updates\n * and disconnections based on SIWE status.\n */\n siwe?: {\n /**\n * Flag indicating if the SIWE authentication request was rejected by the user.\n */\n isRejected: boolean;\n /**\n * Flag indicating if the user is successfully signed in via SIWE.\n */\n isSignedIn: boolean;\n /**\n * Flag indicating if the SIWE flow is enabled.\n */\n enabled?: boolean;\n };\n}\n\n/**\n * A headless React component (renders `null`) that synchronizes the EVM wallet\n * state from `@wagmi/core` with the global `useSatelliteConnectStore`.\n *\n * It is responsible for:\n * 1. Automatically disconnecting if a SIWE (Sign-In With Ethereum) request is rejected.\n * 2. Listening for account changes (e.g., account switch, chain switch, disconnect)\n * from `wagmi` and updating the global store accordingly.\n *\n * @param props - The component's props. See {@link EVMWalletsWatcherProps}.\n * @returns {null} This component does not render any UI.\n */\nexport function EVMWalletsWatcher({ wagmiConfig, siwe }: EVMWalletsWatcherProps) {\n // --- Global Store State ---\n // Subscribes to parts of the global Zustand store.\n\n /**\n * The currently active wallet object from the global store.\n */\n const activeWallet = useSatelliteConnectStore((store) => store.activeWallet);\n /**\n * The global function to trigger a wallet disconnection.\n */\n const disconnect = useSatelliteConnectStore((store) => store.disconnect);\n /**\n * The current connection error state, if any.\n */\n const walletConnectionError = useSatelliteConnectStore((store) => store.walletConnectionError);\n /**\n * The global function to update the active wallet's details.\n */\n const updateActiveWallet = useSatelliteConnectStore((store) => store.updateActiveWallet);\n\n // --- Effects ---\n\n /**\n * Effect: Handles SIWE rejection.\n *\n * If the SIWE flow is enabled (`siwe.enabled`), the user is not yet\n * signed in (`!siwe.isSignedIn`), and they have explicitly rejected\n * the SIWE signature request (`siwe.isRejected`), this effect\n * will call the global `disconnect` function.\n */\n useEffect(() => {\n if (siwe?.enabled && !siwe?.isSignedIn && siwe?.isRejected) {\n disconnect();\n }\n }, [siwe, disconnect]);\n\n /**\n * Effect: Subscribes to wagmi account changes.\n *\n * This effect initializes `watchAccount` from `@wagmi/core` to listen for\n * any changes in the connected wallet's state (like switching accounts,\n * changing networks, or disconnecting).\n */\n useEffect(() => {\n /**\n * Callback function triggered by `watchAccount` whenever the\n * wagmi account state changes.\n *\n * @param account - The new account state provided by wagmi.\n */\n const handleAccountChange: WatchAccountParameters['onChange'] = (account) => {\n // Case 1: The wallet was disconnected from the provider (e.g., MetaMask).\n if (account?.status === 'disconnected') {\n disconnect();\n }\n\n // --- Guard Clauses ---\n // Stop processing if any of these conditions are true:\n // 1. The currently active wallet in our store is NOT an EVM wallet\n // (we don't want this watcher to override a non-EVM wallet).\n // 2. The new account state from wagmi has no address.\n // 3. There is already a connection error in our global store.\n if (\n (activeWallet && getAdapterFromWalletType(activeWallet.walletType) !== OrbitAdapter.EVM) ||\n !account.address ||\n walletConnectionError\n ) {\n return;\n }\n\n /**\n * Determines if the global store *should* be updated.\n * - If SIWE is enabled, we only update the store if the user is signed in.\n * - If SIWE is not enabled, we always update the store.\n */\n const shouldUpdate = siwe?.enabled ? siwe.isSignedIn : true;\n\n if (shouldUpdate) {\n // Preserve the `walletType` if it already exists in the active wallet.\n const walletType = activeWallet?.walletType;\n\n /**\n * The payload to send to the global store update function.\n */\n const walletUpdate = walletType\n ? {\n // Preserve the walletType (e.g., 'metamask', 'walletconnect')\n walletType,\n address: account.address,\n chainId: account.chainId,\n rpcURL: account.chain?.rpcUrls.default.http[0],\n isConnected: account.isConnected,\n }\n : {\n // Fallback if activeWallet was null or had no type\n address: account.address,\n chainId: account.chainId,\n rpcURL: account.chain?.rpcUrls.default.http[0],\n isConnected: account.isConnected,\n };\n\n // Update the global store with the new wallet state.\n updateActiveWallet(walletUpdate);\n }\n };\n\n // Activate the watcher\n const unwatch = watchAccount(wagmiConfig, { onChange: handleAccountChange });\n\n // Return the cleanup function.\n // This `unwatch` function will be called when the component unmounts\n // or when the dependencies in the array change, preventing memory leaks.\n return unwatch;\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [activeWallet?.walletType, siwe, walletConnectionError]);\n\n // This component is \"headless\" - it performs logic but renders nothing.\n return null;\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tuwaio/satellite-react",
3
- "version": "1.0.0-fix-watchers-alpha.1.39245f5",
3
+ "version": "1.0.0-fix-evm-connectors-alpha.1.dbb88c1",
4
4
  "private": false,
5
5
  "author": "Oleksandr Tkach",
6
6
  "license": "Apache-2.0",
@@ -136,9 +136,9 @@
136
136
  "viem": "^2.38.3",
137
137
  "typescript": "^5.9.3",
138
138
  "zustand": "^5.0.8",
139
- "@tuwaio/satellite-core": "^1.0.0-fix-watchers-alpha.1.39245f5",
140
- "@tuwaio/satellite-evm": "^1.0.0-fix-watchers-alpha.1.39245f5",
141
- "@tuwaio/satellite-solana": "^1.0.0-fix-watchers-alpha.1.39245f5"
139
+ "@tuwaio/satellite-core": "^1.0.0-fix-evm-connectors-alpha.1.dbb88c1",
140
+ "@tuwaio/satellite-solana": "^1.0.0-fix-evm-connectors-alpha.1.dbb88c1",
141
+ "@tuwaio/satellite-evm": "^1.0.0-fix-evm-connectors-alpha.1.dbb88c1"
142
142
  },
143
143
  "scripts": {
144
144
  "start": "tsup src/index.ts --watch",