@tuwaio/satellite-react 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright 2025 FOP Tkach Oleksandr
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,142 @@
1
+ # Satellite Connect React
2
+
3
+ [![NPM Version](https://img.shields.io/npm/v/@tuwaio/satellite-react.svg)](https://www.npmjs.com/package/@tuwaio/satellite-react)
4
+ [![License](https://img.shields.io/npm/l/@tuwaio/satellite-react.svg)](./LICENSE)
5
+ [![Build Status](https://img.shields.io/github/actions/workflow/status/TuwaIO/satellite-react/release.yml?branch=main)](https://github.com/TuwaIO/satellite-react/actions)
6
+
7
+ React components and hooks for the Satellite Connect ecosystem, providing an easy-to-use interface for integrating Web3 wallet functionality into React applications.
8
+
9
+ ---
10
+
11
+ ## 🏛️ What is `@tuwaio/satellite-react`?
12
+
13
+ `@tuwaio/satellite-react` is the React integration layer for the Satellite Connect ecosystem. It provides a collection of React hooks and components that make it easy to integrate Web3 wallet functionality into your React applications.
14
+
15
+ Built on top of `@tuwaio/satellite-core`, this package offers a seamless developer experience for React applications requiring Web3 wallet integration.
16
+
17
+ ---
18
+
19
+ ## ✨ Key Features
20
+
21
+ - **Type Safety:** Full TypeScript support with proper type definitions
22
+ - **Chain Agnostic:** Unified support for both EVM and Solana wallets
23
+ - **Modern React:** Built with React 19+ features and best practices
24
+ - **Multi-Chain Support:** Seamless integration with multiple blockchain networks
25
+ - **State Management:** Zustand-based store for efficient state handling
26
+
27
+ ---
28
+
29
+ ## 💾 Installation
30
+
31
+ ### Requirements
32
+ - React 19+
33
+ - Node.js 20+
34
+ - TypeScript 5.9+
35
+
36
+ ```bash
37
+ # Using pnpm (recommended)
38
+ pnpm add @tuwaio/satellite-react @tuwaio/satellite-core @tuwaio/orbit-core @wagmi/core @wallet-standard/react gill react immer zustand
39
+
40
+ # Using npm
41
+ npm install @tuwaio/satellite-react @tuwaio/satellite-core @tuwaio/orbit-core @wagmi/core @wallet-standard/react gill react immer zustand
42
+
43
+ # Using yarn
44
+ yarn add @tuwaio/satellite-react @tuwaio/satellite-core @tuwaio/orbit-core @wagmi/core @wallet-standard/react gill react immer zustand
45
+ ```
46
+ ---
47
+
48
+ ## 🚀 Quick Start
49
+
50
+ ### Basic Setup
51
+ ```tsx
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';
57
+ import { WagmiProvider } from 'wagmi';
58
+ import { createWagmiConfig } from '@tuwaio/satellite-evm';
59
+ import { Chain, mainnet, sepolia } from 'viem/chains';
60
+
61
+ export const appConfig = {
62
+ appName: 'Satellite EVM Test App',
63
+ };
64
+
65
+ export const solanaRPCUrls = {
66
+ devnet: 'https://api.devnet.solana.com',
67
+ };
68
+
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
+
79
+ const queryClient = new QueryClient();
80
+
81
+ initializeSolanaMobileConnectors({
82
+ rpcUrls: solanaRPCUrls,
83
+ ...appConfig,
84
+ });
85
+
86
+ 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
+ );
101
+ }
102
+ ```
103
+
104
+ ### Using Hooks
105
+ ```tsx
106
+ import { useSatelliteConnectStore } from '@tuwaio/satellite-react';
107
+
108
+ function ExampleGettingActiveWalletFromStore() {
109
+ const activeWallet = useSatelliteConnectStore((state) => state.activeWallet);
110
+ return <div>{activeWallet?.address}</div>
111
+ }
112
+ ```
113
+ ---
114
+
115
+ ### Core Components
116
+
117
+ 1. **Store Access**
118
+ - `useSatelliteConnectStore`: Access to satellite connect store with full type safety
119
+ - Provides access to wallet state, connection methods, and chain management
120
+
121
+ 2. **Provider Components**
122
+ - `SatelliteConnectProvider`: Global context provider with all necessary configurations
123
+ - `EVMWalletsWatcher`: EVM wallet connection state management
124
+ - `SolanaWalletsWatcher`: Solana wallet connection state management
125
+
126
+ ---
127
+
128
+ ## 🤝 Contributing & Support
129
+
130
+ Contributions are welcome! Please read our main **[Contribution Guidelines](https://github.com/TuwaIO/workflows/blob/main/CONTRIBUTING.md)**.
131
+
132
+ If you find this library useful, please consider supporting its development. Every contribution helps!
133
+
134
+ [**➡️ View Support Options**](https://github.com/TuwaIO/workflows/blob/main/Donation.md)
135
+
136
+ ## 📄 License
137
+
138
+ 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)
package/dist/index.cjs ADDED
@@ -0,0 +1,2 @@
1
+ 'use strict';var orbitCore=require('@tuwaio/orbit-core'),core=require('@wagmi/core'),react=require('react'),zustand=require('zustand'),react$1=require('@wallet-standard/react'),satelliteCore=require('@tuwaio/satellite-core'),jsxRuntime=require('react/jsx-runtime');var i=react.createContext(null),r=t=>{let o=react.useContext(i);if(!o)throw new Error("useSatelliteConnectStore must be used within a SatelliteConnectProvider");return zustand.useStore(o,t)};function b({wagmiConfig:t}){let o=r(e=>e.updateActiveWallet);return core.watchAccount(t,{onChange:async e=>{o({walletType:`${orbitCore.OrbitAdapter.EVM}:${e?.connector?.type}`,address:e.address,chainId:e.chainId,rpcURL:e.chain?.rpcUrls.default.http[0],isConnected:e.isConnected});}}),null}function V(){let t=react$1.useWallets(),o=r(e=>e.updateActiveWallet);return react.useEffect(()=>{let e=t.filter(n=>n.accounts.length>0)[0];e&&o({address:e.accounts[0].address,isConnected:true,connectedAccount:e.accounts[0],connectedWallet:e});},[t]),null}var l=({initializeAppConnectors:t,onError:o})=>{react.useEffect(()=>{(async()=>{try{await t();}catch(n){(o??(c=>console.error("Failed to initialize connectors:",c)))(n);}})();},[]);};function a({autoConnect:t}){let o=r(e=>e.initializeAppConnectors);return l({initializeAppConnectors:()=>o({autoConnect:t})}),null}function K({children:t,autoConnect:o,...e}){let n=react.useMemo(()=>satelliteCore.createSatelliteConnectStore({...e}),[]);return jsxRuntime.jsxs(i.Provider,{value:n,children:[jsxRuntime.jsx(a,{autoConnect:o}),t]})}exports.EVMWalletsWatcher=b;exports.InitializeConnectorsProvider=a;exports.SatelliteConnectProvider=K;exports.SatelliteStoreContext=i;exports.SolanaWalletsWatcher=V;exports.useInitializeAppConnectors=l;exports.useSatelliteConnectStore=r;//# sourceMappingURL=index.cjs.map
2
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/hooks/satteliteHook.ts","../src/components/EVMWalletsWatcher.tsx","../src/components/SolanaWalletsWatcher.tsx","../src/hooks/useInitializeConnectors.tsx","../src/providers/InitializeConnectorsProvider.tsx","../src/providers/SatelliteConnectProvider.tsx"],"names":["SatelliteStoreContext","createContext","useSatelliteConnectStore","selector","store","useContext","useStore","EVMWalletsWatcher","wagmiConfig","updateActiveWallet","state","watchAccount","account","OrbitAdapter","SolanaWalletsWatcher","wallets","useWallets","useEffect","activeWallet","wallet","useInitializeAppConnectors","initializeAppConnectors","onError","error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AA,CAAA,CAAA6B,cAAAA,CAACR,EAAA,CAA6B,WAAA,CAAaC,CAAAA,CAAa,CAAA,CACvDE,GACH,CAEJ","file":"index.cjs","sourcesContent":["import { ISatelliteConnectStore } from '@tuwaio/satellite-core';\nimport { createContext, useContext } from 'react';\nimport { StoreApi, useStore } from 'zustand';\n\n/**\n * React Context for providing Satellite Connect store throughout the application\n * @internal\n */\nexport const SatelliteStoreContext = createContext<StoreApi<ISatelliteConnectStore> | null>(null);\n\n/**\n * Custom hook for accessing the Satellite Connect store state\n *\n * @remarks\n * This hook provides type-safe access to the Satellite store state and must be used\n * within a component that is wrapped by SatelliteConnectProvider.\n *\n * @typeParam T - The type of the selected state slice\n * @param selector - Function that selects a slice of the store state\n * @returns Selected state slice\n *\n * @throws Error if used outside of SatelliteConnectProvider\n *\n * @example\n * ```tsx\n * // Get the active wallet\n * const activeWallet = useSatelliteConnectStore((state) => state.activeWallet);\n * ```\n */\nexport const useSatelliteConnectStore = <T>(selector: (state: ISatelliteConnectStore) => T): T => {\n // Get store instance from context\n const store = useContext(SatelliteStoreContext);\n\n // Ensure hook is used within provider\n if (!store) {\n throw new Error('useSatelliteConnectStore must be used within a SatelliteConnectProvider');\n }\n\n // Return selected state using Zustand's useStore\n return useStore(store, selector);\n};\n","import { OrbitAdapter } from '@tuwaio/orbit-core';\nimport { WalletType } from '@tuwaio/satellite-core';\nimport { Config, watchAccount } from '@wagmi/core';\n\nimport { useSatelliteConnectStore } from '../hooks/satteliteHook';\n\n/**\n * React component that watches for EVM wallet account changes and updates the Satellite store\n *\n * @remarks\n * This component acts as a bridge between Wagmi account state and Satellite store.\n * It doesn't render anything visible but maintains wallet state synchronization.\n *\n * @param props - Component properties\n * @param props.wagmiConfig - Wagmi configuration instance\n *\n * @returns null - This is a headless component\n **/\nexport function EVMWalletsWatcher({ wagmiConfig }: { wagmiConfig: Config }) {\n // Get the updateActiveWallet function from the Satellite store\n const updateActiveWallet = useSatelliteConnectStore((state) => state.updateActiveWallet);\n\n // Set up account change watcher\n watchAccount(wagmiConfig, {\n onChange: async (account) => {\n // Update the Satellite store with the new account information\n updateActiveWallet({\n // Combine EVM adapter key with connector type for wallet identification\n walletType: `${OrbitAdapter.EVM}:${account?.connector?.type}` as WalletType,\n // Update wallet address\n address: account.address,\n // Update chain ID\n chainId: account.chainId,\n // Update RPC URL using the first available HTTP URL\n rpcURL: account.chain?.rpcUrls.default.http[0],\n // Update connection status\n isConnected: account.isConnected,\n });\n },\n });\n\n // This is a headless component, so return null\n return null;\n}\n","import { useWallets } from '@wallet-standard/react';\nimport { useEffect } from 'react';\n\nimport { useSatelliteConnectStore } from '../hooks/satteliteHook';\n\n/**\n * React component that monitors Solana wallet connections and updates the Satellite store\n *\n * @remarks\n * This component watches for changes in connected Solana wallets using the Wallet Standard.\n * Currently handles the first active wallet only, with multi-wallet support planned for future.\n * It's a headless component that manages state synchronization between Wallet Standard and Satellite store.\n *\n * @returns null - This is a headless component\n *\n */\nexport function SolanaWalletsWatcher() {\n // Get all connected Solana wallets\n const wallets = useWallets();\n\n // Get the updateActiveWallet function from the Satellite store\n const updateActiveWallet = useSatelliteConnectStore((state) => state.updateActiveWallet);\n\n // Watch for changes in connected wallets\n useEffect(() => {\n // Currently only handling the first wallet with active accounts\n const activeWallet = wallets.filter((wallet) => wallet.accounts.length > 0)[0];\n\n if (activeWallet) {\n // Update the Satellite store with the active wallet information\n updateActiveWallet({\n // Use the first account's address\n // TODO: Implement support for multiple connected wallets\n address: activeWallet.accounts[0].address,\n // Set connection status\n isConnected: true,\n // Store Wallet Standard specific information\n connectedAccount: activeWallet.accounts[0],\n connectedWallet: activeWallet,\n });\n }\n }, [wallets]); // Re-run effect when wallets array changes\n\n // This is a headless component, so return null\n return null;\n}\n","import { useEffect } from 'react';\n\n/**\n * Props for useInitializeAppConnectors hook\n */\ninterface InitializeConnectorsProps {\n /** Function to initialize wallet connectors */\n initializeAppConnectors: () => Promise<void>;\n /** Optional error handler callback */\n onError?: (error: Error) => void;\n}\n\n/**\n * Custom hook for initializing wallet connectors with error handling\n *\n * @remarks\n * This hook handles the initialization of blockchain wallet connectors when a component mounts.\n * It provides default error handling with console.error if no custom handler is provided.\n * The initialization runs only once when the component mounts.\n *\n * @param props - Hook configuration\n * @param props.initializeAppConnectors - Async function that initializes the connectors\n * @param props.onError - Optional custom error handler\n *\n * @example\n * ```tsx\n * // Basic usage with default error handling\n * useInitializeAppConnectors({\n * initializeAppConnectors: store.initializeAppConnectors\n * });\n * // With custom error handling\n * useInitializeAppConnectors({\n * initializeAppConnectors: store.initializeAppConnectors,\n * onError: (error) => {\n * toast.error(`Failed to initialize wallets: ${error.message}`);\n * }\n * });\n * ```\n */\nexport const useInitializeAppConnectors = ({ initializeAppConnectors, onError }: InitializeConnectorsProps): void => {\n useEffect(() => {\n const initializeConnectors = async () => {\n try {\n await initializeAppConnectors();\n } catch (error) {\n // Use provided error handler or fallback to default console.error\n const errorHandler = onError ?? ((e: Error) => console.error('Failed to initialize connectors:', e));\n errorHandler(error as Error);\n }\n };\n\n // Initialize connectors when component mounts\n initializeConnectors();\n }, []); // Empty dependency array ensures single execution\n};\n","import { useSatelliteConnectStore } from '../hooks/satteliteHook';\nimport { useInitializeAppConnectors } from '../hooks/useInitializeConnectors';\n\n/**\n * Props for InitializeConnectorsProvider component\n */\ninterface InitializeConnectorsProviderProps {\n /** Whether to automatically connect to the last used wallet */\n autoConnect?: boolean;\n}\n\n/**\n * Provider component that handles wallet connectors initialization\n *\n * @remarks\n * This is a headless component that initializes wallet connectors when mounted.\n * It integrates with the Satellite Connect store and supports automatic reconnection\n * to the last used wallet via the autoConnect prop.\n *\n * @param props - Component properties\n * @param props.autoConnect - Optional flag to enable automatic wallet reconnection\n *\n * @returns null - This is a headless component\n *\n **/\nexport function InitializeConnectorsProvider({ autoConnect }: InitializeConnectorsProviderProps) {\n // Get the initialization function from the store\n const initializeAppConnectors = useSatelliteConnectStore((state) => state.initializeAppConnectors);\n\n // Initialize connectors with autoConnect configuration\n useInitializeAppConnectors({\n initializeAppConnectors: () => initializeAppConnectors({ autoConnect }),\n });\n\n // This is a headless component\n return null;\n}\n","import { createSatelliteConnectStore, SatelliteConnectStoreInitialParameters } from '@tuwaio/satellite-core';\nimport { useMemo } from 'react';\n\nimport { SatelliteStoreContext } from '../hooks/satteliteHook';\nimport { InitializeConnectorsProvider } from './InitializeConnectorsProvider';\n\n/**\n * Props for SatelliteConnectProvider component\n */\ninterface SatelliteConnectProviderProps extends SatelliteConnectStoreInitialParameters {\n /** React child components */\n children: React.ReactNode;\n /** Whether to automatically connect to last used wallet */\n autoConnect?: boolean;\n}\n\n/**\n * Provider component that manages wallet connections and state\n *\n * @remarks\n * This component creates and provides the Satellite Connect store context to its children.\n * It handles wallet connections, state management, and automatic reconnection functionality.\n * The store is memoized to ensure stable reference across renders.\n *\n * @param props - Component properties including store parameters and children\n * @param props.children - Child components that will have access to the store\n * @param props.autoConnect - Optional flag to enable automatic wallet reconnection\n * @param props.adapter - Blockchain adapter(s) for wallet interactions\n * @param props.callbackAfterConnected - Optional callback for successful connections\n *\n * @example\n * ```tsx\n * // Basic usage with single adapter\n * <SatelliteConnectProvider adapter={solanaAdapter}>\n * <App />\n * </SatelliteConnectProvider>\n *\n * // With auto-connect and multiple adapters\n * <SatelliteConnectProvider\n * adapter={[solanaAdapter, evmAdapter]}\n * autoConnect={true}\n * callbackAfterConnected={(wallet) => {\n * console.log('Wallet connected:', wallet.address);\n * }}\n * >\n * <App />\n * </SatelliteConnectProvider>\n * ```\n */\nexport function SatelliteConnectProvider({ children, autoConnect, ...parameters }: SatelliteConnectProviderProps) {\n // Create and memoize the store instance\n const store = useMemo(() => {\n return createSatelliteConnectStore({\n ...parameters,\n });\n }, []); // Empty dependency array as store should be created only once\n\n return (\n <SatelliteStoreContext.Provider value={store}>\n <InitializeConnectorsProvider autoConnect={autoConnect} />\n {children}\n </SatelliteStoreContext.Provider>\n );\n}\n"]}
@@ -0,0 +1,167 @@
1
+ import { Config } from '@wagmi/core';
2
+ import * as react from 'react';
3
+ import { ISatelliteConnectStore, SatelliteConnectStoreInitialParameters } from '@tuwaio/satellite-core';
4
+ import { StoreApi } from 'zustand';
5
+ import * as react_jsx_runtime from 'react/jsx-runtime';
6
+
7
+ /**
8
+ * React component that watches for EVM wallet account changes and updates the Satellite store
9
+ *
10
+ * @remarks
11
+ * This component acts as a bridge between Wagmi account state and Satellite store.
12
+ * It doesn't render anything visible but maintains wallet state synchronization.
13
+ *
14
+ * @param props - Component properties
15
+ * @param props.wagmiConfig - Wagmi configuration instance
16
+ *
17
+ * @returns null - This is a headless component
18
+ **/
19
+ declare function EVMWalletsWatcher({ wagmiConfig }: {
20
+ wagmiConfig: Config;
21
+ }): null;
22
+
23
+ /**
24
+ * React component that monitors Solana wallet connections and updates the Satellite store
25
+ *
26
+ * @remarks
27
+ * This component watches for changes in connected Solana wallets using the Wallet Standard.
28
+ * Currently handles the first active wallet only, with multi-wallet support planned for future.
29
+ * It's a headless component that manages state synchronization between Wallet Standard and Satellite store.
30
+ *
31
+ * @returns null - This is a headless component
32
+ *
33
+ */
34
+ declare function SolanaWalletsWatcher(): null;
35
+
36
+ /**
37
+ * React Context for providing Satellite Connect store throughout the application
38
+ * @internal
39
+ */
40
+ declare const SatelliteStoreContext: react.Context<StoreApi<ISatelliteConnectStore> | null>;
41
+ /**
42
+ * Custom hook for accessing the Satellite Connect store state
43
+ *
44
+ * @remarks
45
+ * This hook provides type-safe access to the Satellite store state and must be used
46
+ * within a component that is wrapped by SatelliteConnectProvider.
47
+ *
48
+ * @typeParam T - The type of the selected state slice
49
+ * @param selector - Function that selects a slice of the store state
50
+ * @returns Selected state slice
51
+ *
52
+ * @throws Error if used outside of SatelliteConnectProvider
53
+ *
54
+ * @example
55
+ * ```tsx
56
+ * // Get the active wallet
57
+ * const activeWallet = useSatelliteConnectStore((state) => state.activeWallet);
58
+ * ```
59
+ */
60
+ declare const useSatelliteConnectStore: <T>(selector: (state: ISatelliteConnectStore) => T) => T;
61
+
62
+ /**
63
+ * Props for useInitializeAppConnectors hook
64
+ */
65
+ interface InitializeConnectorsProps {
66
+ /** Function to initialize wallet connectors */
67
+ initializeAppConnectors: () => Promise<void>;
68
+ /** Optional error handler callback */
69
+ onError?: (error: Error) => void;
70
+ }
71
+ /**
72
+ * Custom hook for initializing wallet connectors with error handling
73
+ *
74
+ * @remarks
75
+ * This hook handles the initialization of blockchain wallet connectors when a component mounts.
76
+ * It provides default error handling with console.error if no custom handler is provided.
77
+ * The initialization runs only once when the component mounts.
78
+ *
79
+ * @param props - Hook configuration
80
+ * @param props.initializeAppConnectors - Async function that initializes the connectors
81
+ * @param props.onError - Optional custom error handler
82
+ *
83
+ * @example
84
+ * ```tsx
85
+ * // Basic usage with default error handling
86
+ * useInitializeAppConnectors({
87
+ * initializeAppConnectors: store.initializeAppConnectors
88
+ * });
89
+ * // With custom error handling
90
+ * useInitializeAppConnectors({
91
+ * initializeAppConnectors: store.initializeAppConnectors,
92
+ * onError: (error) => {
93
+ * toast.error(`Failed to initialize wallets: ${error.message}`);
94
+ * }
95
+ * });
96
+ * ```
97
+ */
98
+ declare const useInitializeAppConnectors: ({ initializeAppConnectors, onError }: InitializeConnectorsProps) => void;
99
+
100
+ /**
101
+ * Props for InitializeConnectorsProvider component
102
+ */
103
+ interface InitializeConnectorsProviderProps {
104
+ /** Whether to automatically connect to the last used wallet */
105
+ autoConnect?: boolean;
106
+ }
107
+ /**
108
+ * Provider component that handles wallet connectors initialization
109
+ *
110
+ * @remarks
111
+ * This is a headless component that initializes wallet connectors when mounted.
112
+ * It integrates with the Satellite Connect store and supports automatic reconnection
113
+ * to the last used wallet via the autoConnect prop.
114
+ *
115
+ * @param props - Component properties
116
+ * @param props.autoConnect - Optional flag to enable automatic wallet reconnection
117
+ *
118
+ * @returns null - This is a headless component
119
+ *
120
+ **/
121
+ declare function InitializeConnectorsProvider({ autoConnect }: InitializeConnectorsProviderProps): null;
122
+
123
+ /**
124
+ * Props for SatelliteConnectProvider component
125
+ */
126
+ interface SatelliteConnectProviderProps extends SatelliteConnectStoreInitialParameters {
127
+ /** React child components */
128
+ children: React.ReactNode;
129
+ /** Whether to automatically connect to last used wallet */
130
+ autoConnect?: boolean;
131
+ }
132
+ /**
133
+ * Provider component that manages wallet connections and state
134
+ *
135
+ * @remarks
136
+ * This component creates and provides the Satellite Connect store context to its children.
137
+ * It handles wallet connections, state management, and automatic reconnection functionality.
138
+ * The store is memoized to ensure stable reference across renders.
139
+ *
140
+ * @param props - Component properties including store parameters and children
141
+ * @param props.children - Child components that will have access to the store
142
+ * @param props.autoConnect - Optional flag to enable automatic wallet reconnection
143
+ * @param props.adapter - Blockchain adapter(s) for wallet interactions
144
+ * @param props.callbackAfterConnected - Optional callback for successful connections
145
+ *
146
+ * @example
147
+ * ```tsx
148
+ * // Basic usage with single adapter
149
+ * <SatelliteConnectProvider adapter={solanaAdapter}>
150
+ * <App />
151
+ * </SatelliteConnectProvider>
152
+ *
153
+ * // With auto-connect and multiple adapters
154
+ * <SatelliteConnectProvider
155
+ * adapter={[solanaAdapter, evmAdapter]}
156
+ * autoConnect={true}
157
+ * callbackAfterConnected={(wallet) => {
158
+ * console.log('Wallet connected:', wallet.address);
159
+ * }}
160
+ * >
161
+ * <App />
162
+ * </SatelliteConnectProvider>
163
+ * ```
164
+ */
165
+ declare function SatelliteConnectProvider({ children, autoConnect, ...parameters }: SatelliteConnectProviderProps): react_jsx_runtime.JSX.Element;
166
+
167
+ export { EVMWalletsWatcher, InitializeConnectorsProvider, SatelliteConnectProvider, SatelliteStoreContext, SolanaWalletsWatcher, useInitializeAppConnectors, useSatelliteConnectStore };
@@ -0,0 +1,167 @@
1
+ import { Config } from '@wagmi/core';
2
+ import * as react from 'react';
3
+ import { ISatelliteConnectStore, SatelliteConnectStoreInitialParameters } from '@tuwaio/satellite-core';
4
+ import { StoreApi } from 'zustand';
5
+ import * as react_jsx_runtime from 'react/jsx-runtime';
6
+
7
+ /**
8
+ * React component that watches for EVM wallet account changes and updates the Satellite store
9
+ *
10
+ * @remarks
11
+ * This component acts as a bridge between Wagmi account state and Satellite store.
12
+ * It doesn't render anything visible but maintains wallet state synchronization.
13
+ *
14
+ * @param props - Component properties
15
+ * @param props.wagmiConfig - Wagmi configuration instance
16
+ *
17
+ * @returns null - This is a headless component
18
+ **/
19
+ declare function EVMWalletsWatcher({ wagmiConfig }: {
20
+ wagmiConfig: Config;
21
+ }): null;
22
+
23
+ /**
24
+ * React component that monitors Solana wallet connections and updates the Satellite store
25
+ *
26
+ * @remarks
27
+ * This component watches for changes in connected Solana wallets using the Wallet Standard.
28
+ * Currently handles the first active wallet only, with multi-wallet support planned for future.
29
+ * It's a headless component that manages state synchronization between Wallet Standard and Satellite store.
30
+ *
31
+ * @returns null - This is a headless component
32
+ *
33
+ */
34
+ declare function SolanaWalletsWatcher(): null;
35
+
36
+ /**
37
+ * React Context for providing Satellite Connect store throughout the application
38
+ * @internal
39
+ */
40
+ declare const SatelliteStoreContext: react.Context<StoreApi<ISatelliteConnectStore> | null>;
41
+ /**
42
+ * Custom hook for accessing the Satellite Connect store state
43
+ *
44
+ * @remarks
45
+ * This hook provides type-safe access to the Satellite store state and must be used
46
+ * within a component that is wrapped by SatelliteConnectProvider.
47
+ *
48
+ * @typeParam T - The type of the selected state slice
49
+ * @param selector - Function that selects a slice of the store state
50
+ * @returns Selected state slice
51
+ *
52
+ * @throws Error if used outside of SatelliteConnectProvider
53
+ *
54
+ * @example
55
+ * ```tsx
56
+ * // Get the active wallet
57
+ * const activeWallet = useSatelliteConnectStore((state) => state.activeWallet);
58
+ * ```
59
+ */
60
+ declare const useSatelliteConnectStore: <T>(selector: (state: ISatelliteConnectStore) => T) => T;
61
+
62
+ /**
63
+ * Props for useInitializeAppConnectors hook
64
+ */
65
+ interface InitializeConnectorsProps {
66
+ /** Function to initialize wallet connectors */
67
+ initializeAppConnectors: () => Promise<void>;
68
+ /** Optional error handler callback */
69
+ onError?: (error: Error) => void;
70
+ }
71
+ /**
72
+ * Custom hook for initializing wallet connectors with error handling
73
+ *
74
+ * @remarks
75
+ * This hook handles the initialization of blockchain wallet connectors when a component mounts.
76
+ * It provides default error handling with console.error if no custom handler is provided.
77
+ * The initialization runs only once when the component mounts.
78
+ *
79
+ * @param props - Hook configuration
80
+ * @param props.initializeAppConnectors - Async function that initializes the connectors
81
+ * @param props.onError - Optional custom error handler
82
+ *
83
+ * @example
84
+ * ```tsx
85
+ * // Basic usage with default error handling
86
+ * useInitializeAppConnectors({
87
+ * initializeAppConnectors: store.initializeAppConnectors
88
+ * });
89
+ * // With custom error handling
90
+ * useInitializeAppConnectors({
91
+ * initializeAppConnectors: store.initializeAppConnectors,
92
+ * onError: (error) => {
93
+ * toast.error(`Failed to initialize wallets: ${error.message}`);
94
+ * }
95
+ * });
96
+ * ```
97
+ */
98
+ declare const useInitializeAppConnectors: ({ initializeAppConnectors, onError }: InitializeConnectorsProps) => void;
99
+
100
+ /**
101
+ * Props for InitializeConnectorsProvider component
102
+ */
103
+ interface InitializeConnectorsProviderProps {
104
+ /** Whether to automatically connect to the last used wallet */
105
+ autoConnect?: boolean;
106
+ }
107
+ /**
108
+ * Provider component that handles wallet connectors initialization
109
+ *
110
+ * @remarks
111
+ * This is a headless component that initializes wallet connectors when mounted.
112
+ * It integrates with the Satellite Connect store and supports automatic reconnection
113
+ * to the last used wallet via the autoConnect prop.
114
+ *
115
+ * @param props - Component properties
116
+ * @param props.autoConnect - Optional flag to enable automatic wallet reconnection
117
+ *
118
+ * @returns null - This is a headless component
119
+ *
120
+ **/
121
+ declare function InitializeConnectorsProvider({ autoConnect }: InitializeConnectorsProviderProps): null;
122
+
123
+ /**
124
+ * Props for SatelliteConnectProvider component
125
+ */
126
+ interface SatelliteConnectProviderProps extends SatelliteConnectStoreInitialParameters {
127
+ /** React child components */
128
+ children: React.ReactNode;
129
+ /** Whether to automatically connect to last used wallet */
130
+ autoConnect?: boolean;
131
+ }
132
+ /**
133
+ * Provider component that manages wallet connections and state
134
+ *
135
+ * @remarks
136
+ * This component creates and provides the Satellite Connect store context to its children.
137
+ * It handles wallet connections, state management, and automatic reconnection functionality.
138
+ * The store is memoized to ensure stable reference across renders.
139
+ *
140
+ * @param props - Component properties including store parameters and children
141
+ * @param props.children - Child components that will have access to the store
142
+ * @param props.autoConnect - Optional flag to enable automatic wallet reconnection
143
+ * @param props.adapter - Blockchain adapter(s) for wallet interactions
144
+ * @param props.callbackAfterConnected - Optional callback for successful connections
145
+ *
146
+ * @example
147
+ * ```tsx
148
+ * // Basic usage with single adapter
149
+ * <SatelliteConnectProvider adapter={solanaAdapter}>
150
+ * <App />
151
+ * </SatelliteConnectProvider>
152
+ *
153
+ * // With auto-connect and multiple adapters
154
+ * <SatelliteConnectProvider
155
+ * adapter={[solanaAdapter, evmAdapter]}
156
+ * autoConnect={true}
157
+ * callbackAfterConnected={(wallet) => {
158
+ * console.log('Wallet connected:', wallet.address);
159
+ * }}
160
+ * >
161
+ * <App />
162
+ * </SatelliteConnectProvider>
163
+ * ```
164
+ */
165
+ declare function SatelliteConnectProvider({ children, autoConnect, ...parameters }: SatelliteConnectProviderProps): react_jsx_runtime.JSX.Element;
166
+
167
+ export { EVMWalletsWatcher, InitializeConnectorsProvider, SatelliteConnectProvider, SatelliteStoreContext, SolanaWalletsWatcher, useInitializeAppConnectors, useSatelliteConnectStore };
package/dist/index.js ADDED
@@ -0,0 +1,2 @@
1
+ import {OrbitAdapter}from'@tuwaio/orbit-core';import {watchAccount}from'@wagmi/core';import {createContext,useContext,useEffect,useMemo}from'react';import {useStore}from'zustand';import {useWallets}from'@wallet-standard/react';import {createSatelliteConnectStore}from'@tuwaio/satellite-core';import {jsxs,jsx}from'react/jsx-runtime';var i=createContext(null),r=t=>{let o=useContext(i);if(!o)throw new Error("useSatelliteConnectStore must be used within a SatelliteConnectProvider");return useStore(o,t)};function b({wagmiConfig:t}){let o=r(e=>e.updateActiveWallet);return watchAccount(t,{onChange:async e=>{o({walletType:`${OrbitAdapter.EVM}:${e?.connector?.type}`,address:e.address,chainId:e.chainId,rpcURL:e.chain?.rpcUrls.default.http[0],isConnected:e.isConnected});}}),null}function V(){let t=useWallets(),o=r(e=>e.updateActiveWallet);return useEffect(()=>{let e=t.filter(n=>n.accounts.length>0)[0];e&&o({address:e.accounts[0].address,isConnected:true,connectedAccount:e.accounts[0],connectedWallet:e});},[t]),null}var l=({initializeAppConnectors:t,onError:o})=>{useEffect(()=>{(async()=>{try{await t();}catch(n){(o??(c=>console.error("Failed to initialize connectors:",c)))(n);}})();},[]);};function a({autoConnect:t}){let o=r(e=>e.initializeAppConnectors);return l({initializeAppConnectors:()=>o({autoConnect:t})}),null}function K({children:t,autoConnect:o,...e}){let n=useMemo(()=>createSatelliteConnectStore({...e}),[]);return jsxs(i.Provider,{value:n,children:[jsx(a,{autoConnect:o}),t]})}export{b as EVMWalletsWatcher,a as InitializeConnectorsProvider,K as SatelliteConnectProvider,i as SatelliteStoreContext,V as SolanaWalletsWatcher,l as useInitializeAppConnectors,r as useSatelliteConnectStore};//# sourceMappingURL=index.js.map
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/hooks/satteliteHook.ts","../src/components/EVMWalletsWatcher.tsx","../src/components/SolanaWalletsWatcher.tsx","../src/hooks/useInitializeConnectors.tsx","../src/providers/InitializeConnectorsProvider.tsx","../src/providers/SatelliteConnectProvider.tsx"],"names":["SatelliteStoreContext","createContext","useSatelliteConnectStore","selector","store","useContext","useStore","EVMWalletsWatcher","wagmiConfig","updateActiveWallet","state","watchAccount","account","OrbitAdapter","SolanaWalletsWatcher","wallets","useWallets","useEffect","activeWallet","wallet","useInitializeAppConnectors","initializeAppConnectors","onError","error","e","InitializeConnectorsProvider","autoConnect","SatelliteConnectProvider","children","parameters","useMemo","createSatelliteConnectStore","jsxs","jsx"],"mappings":"6UAQO,IAAMA,CAAAA,CAAwBC,aAAAA,CAAuD,IAAI,CAAA,CAqBnFC,EAA+BC,CAAAA,EAAsD,CAEhG,IAAMC,CAAAA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C,eAAA,CAAiBA,CACnB,CAAC,EAEL,CAAA,CAAG,CAACH,CAAO,CAAC,CAAA,CAGL,IACT,KCNaK,CAAAA,CAA6B,CAAC,CAAE,uBAAA,CAAAC,EAAyB,OAAA,CAAAC,CAAQ,CAAA,GAAuC,CACnHL,UAAU,IAAM,CAAA,CACe,SAAY,CACvC,GAAI,CACF,MAAMI,CAAAA,GACR,CAAA,MAASE,CAAAA,CAAO,CAAA,CAEOD,CAAAA,GAAaE,CAAAA,EAAa,OAAA,CAAQ,KAAA,CAAM,kCAAA,CAAoCA,CAAC,CAAA,CAAA,EACrFD,CAAc,EAC7B,CACF,CAAA,IAIF,CAAA,CAAG,EAAE,EACP,EC7BO,SAASE,CAAAA,CAA6B,CAAE,WAAA,CAAAC,CAAY,CAAA,CAAsC,CAE/F,IAAML,CAAAA,CAA0BnB,CAAAA,CAA0BQ,CAAAA,EAAUA,CAAAA,CAAM,uBAAuB,CAAA,CAGjG,OAAAU,CAAAA,CAA2B,CACzB,uBAAA,CAAyB,IAAMC,CAAAA,CAAwB,CAAE,WAAA,CAAAK,CAAY,CAAC,CACxE,CAAC,CAAA,CAGM,IACT,CCaO,SAASC,EAAyB,CAAE,QAAA,CAAAC,CAAAA,CAAU,WAAA,CAAAF,CAAAA,CAAa,GAAGG,CAAW,CAAA,CAAkC,CAEhH,IAAMzB,CAAAA,CAAQ0B,OAAAA,CAAQ,IACbC,2BAAAA,CAA4B,CACjC,GAAGF,CACL,CAAC,CAAA,CACA,EAAE,CAAA,CAEL,OACEG,IAAAA,CAAChC,CAAAA,CAAsB,QAAA,CAAtB,CAA+B,KAAA,CAAOI,CAAAA,CACrC,QAAA,CAAA,CAAA6B,GAAAA,CAACR,EAAA,CAA6B,WAAA,CAAaC,CAAAA,CAAa,CAAA,CACvDE,GACH,CAEJ","file":"index.js","sourcesContent":["import { ISatelliteConnectStore } from '@tuwaio/satellite-core';\nimport { createContext, useContext } from 'react';\nimport { StoreApi, useStore } from 'zustand';\n\n/**\n * React Context for providing Satellite Connect store throughout the application\n * @internal\n */\nexport const SatelliteStoreContext = createContext<StoreApi<ISatelliteConnectStore> | null>(null);\n\n/**\n * Custom hook for accessing the Satellite Connect store state\n *\n * @remarks\n * This hook provides type-safe access to the Satellite store state and must be used\n * within a component that is wrapped by SatelliteConnectProvider.\n *\n * @typeParam T - The type of the selected state slice\n * @param selector - Function that selects a slice of the store state\n * @returns Selected state slice\n *\n * @throws Error if used outside of SatelliteConnectProvider\n *\n * @example\n * ```tsx\n * // Get the active wallet\n * const activeWallet = useSatelliteConnectStore((state) => state.activeWallet);\n * ```\n */\nexport const useSatelliteConnectStore = <T>(selector: (state: ISatelliteConnectStore) => T): T => {\n // Get store instance from context\n const store = useContext(SatelliteStoreContext);\n\n // Ensure hook is used within provider\n if (!store) {\n throw new Error('useSatelliteConnectStore must be used within a SatelliteConnectProvider');\n }\n\n // Return selected state using Zustand's useStore\n return useStore(store, selector);\n};\n","import { OrbitAdapter } from '@tuwaio/orbit-core';\nimport { WalletType } from '@tuwaio/satellite-core';\nimport { Config, watchAccount } from '@wagmi/core';\n\nimport { useSatelliteConnectStore } from '../hooks/satteliteHook';\n\n/**\n * React component that watches for EVM wallet account changes and updates the Satellite store\n *\n * @remarks\n * This component acts as a bridge between Wagmi account state and Satellite store.\n * It doesn't render anything visible but maintains wallet state synchronization.\n *\n * @param props - Component properties\n * @param props.wagmiConfig - Wagmi configuration instance\n *\n * @returns null - This is a headless component\n **/\nexport function EVMWalletsWatcher({ wagmiConfig }: { wagmiConfig: Config }) {\n // Get the updateActiveWallet function from the Satellite store\n const updateActiveWallet = useSatelliteConnectStore((state) => state.updateActiveWallet);\n\n // Set up account change watcher\n watchAccount(wagmiConfig, {\n onChange: async (account) => {\n // Update the Satellite store with the new account information\n updateActiveWallet({\n // Combine EVM adapter key with connector type for wallet identification\n walletType: `${OrbitAdapter.EVM}:${account?.connector?.type}` as WalletType,\n // Update wallet address\n address: account.address,\n // Update chain ID\n chainId: account.chainId,\n // Update RPC URL using the first available HTTP URL\n rpcURL: account.chain?.rpcUrls.default.http[0],\n // Update connection status\n isConnected: account.isConnected,\n });\n },\n });\n\n // This is a headless component, so return null\n return null;\n}\n","import { useWallets } from '@wallet-standard/react';\nimport { useEffect } from 'react';\n\nimport { useSatelliteConnectStore } from '../hooks/satteliteHook';\n\n/**\n * React component that monitors Solana wallet connections and updates the Satellite store\n *\n * @remarks\n * This component watches for changes in connected Solana wallets using the Wallet Standard.\n * Currently handles the first active wallet only, with multi-wallet support planned for future.\n * It's a headless component that manages state synchronization between Wallet Standard and Satellite store.\n *\n * @returns null - This is a headless component\n *\n */\nexport function SolanaWalletsWatcher() {\n // Get all connected Solana wallets\n const wallets = useWallets();\n\n // Get the updateActiveWallet function from the Satellite store\n const updateActiveWallet = useSatelliteConnectStore((state) => state.updateActiveWallet);\n\n // Watch for changes in connected wallets\n useEffect(() => {\n // Currently only handling the first wallet with active accounts\n const activeWallet = wallets.filter((wallet) => wallet.accounts.length > 0)[0];\n\n if (activeWallet) {\n // Update the Satellite store with the active wallet information\n updateActiveWallet({\n // Use the first account's address\n // TODO: Implement support for multiple connected wallets\n address: activeWallet.accounts[0].address,\n // Set connection status\n isConnected: true,\n // Store Wallet Standard specific information\n connectedAccount: activeWallet.accounts[0],\n connectedWallet: activeWallet,\n });\n }\n }, [wallets]); // Re-run effect when wallets array changes\n\n // This is a headless component, so return null\n return null;\n}\n","import { useEffect } from 'react';\n\n/**\n * Props for useInitializeAppConnectors hook\n */\ninterface InitializeConnectorsProps {\n /** Function to initialize wallet connectors */\n initializeAppConnectors: () => Promise<void>;\n /** Optional error handler callback */\n onError?: (error: Error) => void;\n}\n\n/**\n * Custom hook for initializing wallet connectors with error handling\n *\n * @remarks\n * This hook handles the initialization of blockchain wallet connectors when a component mounts.\n * It provides default error handling with console.error if no custom handler is provided.\n * The initialization runs only once when the component mounts.\n *\n * @param props - Hook configuration\n * @param props.initializeAppConnectors - Async function that initializes the connectors\n * @param props.onError - Optional custom error handler\n *\n * @example\n * ```tsx\n * // Basic usage with default error handling\n * useInitializeAppConnectors({\n * initializeAppConnectors: store.initializeAppConnectors\n * });\n * // With custom error handling\n * useInitializeAppConnectors({\n * initializeAppConnectors: store.initializeAppConnectors,\n * onError: (error) => {\n * toast.error(`Failed to initialize wallets: ${error.message}`);\n * }\n * });\n * ```\n */\nexport const useInitializeAppConnectors = ({ initializeAppConnectors, onError }: InitializeConnectorsProps): void => {\n useEffect(() => {\n const initializeConnectors = async () => {\n try {\n await initializeAppConnectors();\n } catch (error) {\n // Use provided error handler or fallback to default console.error\n const errorHandler = onError ?? ((e: Error) => console.error('Failed to initialize connectors:', e));\n errorHandler(error as Error);\n }\n };\n\n // Initialize connectors when component mounts\n initializeConnectors();\n }, []); // Empty dependency array ensures single execution\n};\n","import { useSatelliteConnectStore } from '../hooks/satteliteHook';\nimport { useInitializeAppConnectors } from '../hooks/useInitializeConnectors';\n\n/**\n * Props for InitializeConnectorsProvider component\n */\ninterface InitializeConnectorsProviderProps {\n /** Whether to automatically connect to the last used wallet */\n autoConnect?: boolean;\n}\n\n/**\n * Provider component that handles wallet connectors initialization\n *\n * @remarks\n * This is a headless component that initializes wallet connectors when mounted.\n * It integrates with the Satellite Connect store and supports automatic reconnection\n * to the last used wallet via the autoConnect prop.\n *\n * @param props - Component properties\n * @param props.autoConnect - Optional flag to enable automatic wallet reconnection\n *\n * @returns null - This is a headless component\n *\n **/\nexport function InitializeConnectorsProvider({ autoConnect }: InitializeConnectorsProviderProps) {\n // Get the initialization function from the store\n const initializeAppConnectors = useSatelliteConnectStore((state) => state.initializeAppConnectors);\n\n // Initialize connectors with autoConnect configuration\n useInitializeAppConnectors({\n initializeAppConnectors: () => initializeAppConnectors({ autoConnect }),\n });\n\n // This is a headless component\n return null;\n}\n","import { createSatelliteConnectStore, SatelliteConnectStoreInitialParameters } from '@tuwaio/satellite-core';\nimport { useMemo } from 'react';\n\nimport { SatelliteStoreContext } from '../hooks/satteliteHook';\nimport { InitializeConnectorsProvider } from './InitializeConnectorsProvider';\n\n/**\n * Props for SatelliteConnectProvider component\n */\ninterface SatelliteConnectProviderProps extends SatelliteConnectStoreInitialParameters {\n /** React child components */\n children: React.ReactNode;\n /** Whether to automatically connect to last used wallet */\n autoConnect?: boolean;\n}\n\n/**\n * Provider component that manages wallet connections and state\n *\n * @remarks\n * This component creates and provides the Satellite Connect store context to its children.\n * It handles wallet connections, state management, and automatic reconnection functionality.\n * The store is memoized to ensure stable reference across renders.\n *\n * @param props - Component properties including store parameters and children\n * @param props.children - Child components that will have access to the store\n * @param props.autoConnect - Optional flag to enable automatic wallet reconnection\n * @param props.adapter - Blockchain adapter(s) for wallet interactions\n * @param props.callbackAfterConnected - Optional callback for successful connections\n *\n * @example\n * ```tsx\n * // Basic usage with single adapter\n * <SatelliteConnectProvider adapter={solanaAdapter}>\n * <App />\n * </SatelliteConnectProvider>\n *\n * // With auto-connect and multiple adapters\n * <SatelliteConnectProvider\n * adapter={[solanaAdapter, evmAdapter]}\n * autoConnect={true}\n * callbackAfterConnected={(wallet) => {\n * console.log('Wallet connected:', wallet.address);\n * }}\n * >\n * <App />\n * </SatelliteConnectProvider>\n * ```\n */\nexport function SatelliteConnectProvider({ children, autoConnect, ...parameters }: SatelliteConnectProviderProps) {\n // Create and memoize the store instance\n const store = useMemo(() => {\n return createSatelliteConnectStore({\n ...parameters,\n });\n }, []); // Empty dependency array as store should be created only once\n\n return (\n <SatelliteStoreContext.Provider value={store}>\n <InitializeConnectorsProvider autoConnect={autoConnect} />\n {children}\n </SatelliteStoreContext.Provider>\n );\n}\n"]}
package/package.json ADDED
@@ -0,0 +1,70 @@
1
+ {
2
+ "name": "@tuwaio/satellite-react",
3
+ "version": "0.0.3",
4
+ "private": false,
5
+ "author": "Oleksandr Tkach",
6
+ "license": "Apache-2.0",
7
+ "description": "An provider and hook with for React for satellite based wallets.",
8
+ "type": "module",
9
+ "main": "./dist/index.js",
10
+ "module": "./dist/index.mjs",
11
+ "types": "./dist/index.d.ts",
12
+ "publishConfig": {
13
+ "access": "public"
14
+ },
15
+ "files": [
16
+ "dist"
17
+ ],
18
+ "keywords": [
19
+ "web3",
20
+ "connect",
21
+ "wallet",
22
+ "wagmi",
23
+ "viem",
24
+ "zustand"
25
+ ],
26
+ "repository": {
27
+ "type": "git",
28
+ "url": "git+https://github.com/TuwaIO/satellite-connect.git",
29
+ "directory": "packages/satellite-react"
30
+ },
31
+ "homepage": "https://github.com/TuwaIO/satellite-connect",
32
+ "bugs": {
33
+ "url": "https://github.com/TuwaIO/satellite-connect/issues"
34
+ },
35
+ "contributors": [
36
+ {
37
+ "name": "Oleksandr Tkach",
38
+ "url": "https://github.com/Argeare5"
39
+ }
40
+ ],
41
+ "peerDependencies": {
42
+ "@tuwaio/orbit-core": ">=0",
43
+ "@tuwaio/satellite-core": ">=0",
44
+ "@wagmi/core": ">=2",
45
+ "@wallet-standard/react": ">=1",
46
+ "gill": ">=0.11",
47
+ "react": ">=19",
48
+ "immer": ">=10",
49
+ "zustand": ">=5"
50
+ },
51
+ "devDependencies": {
52
+ "@types/react": "^19.1.12",
53
+ "@wagmi/core": "^2.21.1",
54
+ "@wallet-standard/react": "^1.0.1",
55
+ "gill": "^0.11.0",
56
+ "immer": "^10.1.3",
57
+ "react": "^19.1.1",
58
+ "tsup": "^8.5.0",
59
+ "typescript": "^5.9.2",
60
+ "zustand": "^5.0.8",
61
+ "@tuwaio/orbit-core": "^0.0.3",
62
+ "@tuwaio/satellite-core": "^0.0.3",
63
+ "@tuwaio/orbit-solana": "^0.0.3"
64
+ },
65
+ "scripts": {
66
+ "start": "tsup src/index.ts --watch",
67
+ "build": "tsup",
68
+ "test": "vitest"
69
+ }
70
+ }