@tuwaio/satellite-react 1.0.0-fix-test-alpha.12.37394ce → 1.0.0-fix-test-alpha.13.79d73b8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/package.json +4 -4
package/dist/index.cjs
CHANGED
|
@@ -1,2 +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),n=e=>{let o=react.useContext(i);if(!o)throw new Error("useSatelliteConnectStore must be used within a SatelliteConnectProvider");return zustand.useStore(o,e)};function y({wagmiConfig:e}){let o=n(t=>t.updateActiveWallet);return core.watchAccount(e,{onChange:async t=>{o({walletType:`${orbitCore.OrbitAdapter.EVM}:${t?.connector?.type}`,address:t.address,chainId:t.chainId,rpcURL:t.chain?.rpcUrls.default.http[0],isConnected:t.isConnected});}}),null}function R(){let e=react$1.useWallets(),o=n(t=>t.updateActiveWallet);return react.useEffect(()=>{let t=e.filter(r=>r.accounts.length>0)[0];t&&o({address:t.accounts[0].address,isConnected:true,connectedAccount:t.accounts[0],connectedWallet:t});},[e]),null}var l=({initializeAutoConnect:e,onError:o})=>{react.useEffect(()=>{(async()=>{try{await e();}catch(r){(o??(a=>console.error("Failed to initialize auto connect:",a)))(r);}})();},[]);};function q({children:e,autoConnect:o,...t}){let r=react.useMemo(()=>satelliteCore.createSatelliteConnectStore({...t}),[]);return l({initializeAutoConnect:()=>r.getState().initializeAutoConnect(o??!1)}),jsxRuntime.jsx(i.Provider,{value:r,children:e})}exports.EVMWalletsWatcher=y;exports.SatelliteConnectProvider=q;exports.SatelliteStoreContext=i;exports.SolanaWalletsWatcher=R;exports.useInitializeAutoConnect=l;exports.useSatelliteConnectStore=n;//# sourceMappingURL=index.cjs.map
|
|
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),n=e=>{let o=react.useContext(i);if(!o)throw new Error("useSatelliteConnectStore must be used within a SatelliteConnectProvider");return zustand.useStore(o,e)};function y({wagmiConfig:e}){let o=n(t=>t.updateActiveWallet);return core.watchAccount(e,{onChange:async t=>{t.isConnected&&o({walletType:`${orbitCore.OrbitAdapter.EVM}:${t?.connector?.type}`,address:t.address,chainId:t.chainId,rpcURL:t.chain?.rpcUrls.default.http[0],isConnected:t.isConnected});}}),null}function R(){let e=react$1.useWallets(),o=n(t=>t.updateActiveWallet);return react.useEffect(()=>{let t=e.filter(r=>r.accounts.length>0)[0];t&&o({address:t.accounts[0].address,isConnected:true,connectedAccount:t.accounts[0],connectedWallet:t});},[e]),null}var l=({initializeAutoConnect:e,onError:o})=>{react.useEffect(()=>{(async()=>{try{await e();}catch(r){(o??(a=>console.error("Failed to initialize auto connect:",a)))(r);}})();},[]);};function q({children:e,autoConnect:o,...t}){let r=react.useMemo(()=>satelliteCore.createSatelliteConnectStore({...t}),[]);return l({initializeAutoConnect:()=>r.getState().initializeAutoConnect(o??!1)}),jsxRuntime.jsx(i.Provider,{value:r,children:e})}exports.EVMWalletsWatcher=y;exports.SatelliteConnectProvider=q;exports.SatelliteStoreContext=i;exports.SolanaWalletsWatcher=R;exports.useInitializeAutoConnect=l;exports.useSatelliteConnectStore=n;//# sourceMappingURL=index.cjs.map
|
|
2
2
|
//# sourceMappingURL=index.cjs.map
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/hooks/satteliteHook.ts","../src/components/EVMWalletsWatcher.tsx","../src/components/SolanaWalletsWatcher.tsx","../src/hooks/useInitializeAutoConnect.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","useInitializeAutoConnect","initializeAutoConnect","onError","error","e","SatelliteConnectProvider","children","autoConnect","parameters","useMemo","createSatelliteConnectStore","jsx"],"mappings":"yQAQO,IAAMA,CAAAA,CAAwBC,mBAAAA,CAAuD,IAAI,CAAA,CAqBnFC,CAAAA,CAA+BC,CAAAA,EAAsD,CAEhG,IAAMC,CAAAA,CAAQC,gBAAAA,CAAWL,CAAqB,CAAA,CAG9C,GAAI,CAACI,CAAAA,CACH,MAAM,IAAI,KAAA,CAAM,yEAAyE,CAAA,CAI3F,OAAOE,gBAAAA,CAASF,CAAAA,CAAOD,CAAQ,CACjC,ECtBO,SAASI,EAAkB,CAAE,WAAA,CAAAC,CAAY,CAAA,CAA4B,CAE1E,IAAMC,CAAAA,CAAqBP,CAAAA,CAA0BQ,CAAAA,EAAUA,CAAAA,CAAM,kBAAkB,CAAA,CAGvF,OAAAC,iBAAAA,CAAaH,CAAAA,CAAa,CACxB,SAAU,MAAOI,CAAAA,EAAY,CAE3BH,CAAAA,CAAmB,CAEjB,UAAA,CAAY,CAAA,EAAGI,sBAAAA,CAAa,GAAG,CAAA,CAAA,EAAID,CAAAA,EAAS,SAAA,EAAW,IAAI,CAAA,CAAA,CAE3D,OAAA,CAASA,CAAAA,CAAQ,QAEjB,OAAA,CAASA,CAAAA,CAAQ,OAAA,CAEjB,MAAA,CAAQA,CAAAA,CAAQ,KAAA,EAAO,OAAA,CAAQ,OAAA,CAAQ,IAAA,CAAK,CAAC,CAAA,CAE7C,WAAA,CAAaA,CAAAA,CAAQ,WACvB,CAAC,EACH,CACF,CAAC,CAAA,CAGM,IACT,CC3BO,SAASE,CAAAA,EAAuB,CAErC,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qBAAA,CAAsBuB,CAAAA,EAAe,CAAA,CAAK,CAC1F,CAAC,CAAA,CAEMI,cAAAA,CAAC/B,CAAAA,CAAsB,QAAA,CAAtB,CAA+B,KAAA,CAAOI,CAAAA,CAAQ,QAAA,CAAAsB,EAAS,CACjE","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 the useInitializeAutoConnect hook.\n */\ninterface InitializeAutoConnectProps {\n /** Function to initialize auto connect logic */\n initializeAutoConnect: () => Promise<void>;\n /** Optional error handler callback */\n onError?: (error: Error) => void;\n}\n\n/**\n * Custom hook for initializing wallet auto-connection with error handling.\n *\n * @remarks\n * This hook handles the initial connection logic (e.g., checking for a previously\n * connected wallet) 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.initializeAutoConnect - Async function that executes the auto-connect logic\n * @param props.onError - Optional custom error handler\n *\n * @example\n * ```tsx\n * // Basic usage with default error handling\n * useInitializeAutoConnect({\n * initializeAutoConnect: store.initializeAutoConnect\n * });\n *\n * // With custom error handling\n * useInitializeAutoConnect({\n * initializeAutoConnect: store.initializeAutoConnect,\n * onError: (error) => {\n * toast.error(`Failed to auto-connect: ${error.message}`);\n * }\n * });\n * ```\n */\nexport const useInitializeAutoConnect = ({ initializeAutoConnect, onError }: InitializeAutoConnectProps): void => {\n useEffect(() => {\n const initializeAutoConnectLocal = async () => {\n try {\n await initializeAutoConnect();\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 auto connect:', e));\n errorHandler(error as Error);\n }\n };\n // Initialize auto connect when component mounts\n initializeAutoConnectLocal();\n }, []); // Empty dependency array ensures single execution\n};\n","import { createSatelliteConnectStore, SatelliteConnectStoreInitialParameters } from '@tuwaio/satellite-core';\nimport { useMemo } from 'react';\n\nimport { SatelliteStoreContext } from '../hooks/satteliteHook';\nimport { useInitializeAutoConnect } from '../hooks/useInitializeAutoConnect';\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 useInitializeAutoConnect({\n initializeAutoConnect: () => store.getState().initializeAutoConnect(autoConnect ?? false),\n });\n\n return <SatelliteStoreContext.Provider value={store}>{children}</SatelliteStoreContext.Provider>;\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/hooks/satteliteHook.ts","../src/components/EVMWalletsWatcher.tsx","../src/components/SolanaWalletsWatcher.tsx","../src/hooks/useInitializeAutoConnect.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","useInitializeAutoConnect","initializeAutoConnect","onError","error","e","SatelliteConnectProvider","children","autoConnect","parameters","useMemo","createSatelliteConnectStore","jsx"],"mappings":"yQAQO,IAAMA,CAAAA,CAAwBC,mBAAAA,CAAuD,IAAI,CAAA,CAqBnFC,CAAAA,CAA+BC,CAAAA,EAAsD,CAEh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A,CAAE,QAElC,WAAA,CAAa,IAAA,CAEb,gBAAA,CAAkBA,CAAAA,CAAa,QAAA,CAAS,CAAC,CAAA,CACzC,eAAA,CAAiBA,CACnB,CAAC,EAEL,CAAA,CAAG,CAACH,CAAO,CAAC,CAAA,CAGL,IACT,CCJO,IAAMK,CAAAA,CAA2B,CAAC,CAAE,qBAAA,CAAAC,CAAAA,CAAuB,OAAA,CAAAC,CAAQ,CAAA,GAAwC,CAChHL,eAAAA,CAAU,IAAM,CAAA,CACqB,SAAY,CAC7C,GAAI,CACF,MAAMI,CAAAA,GACR,CAAA,MAASE,CAAAA,CAAO,CAAA,CAEOD,CAAAA,GAAaE,CAAAA,EAAa,OAAA,CAAQ,KAAA,CAAM,oCAAA,CAAsCA,CAAC,CAAA,CAAA,EACvFD,CAAc,EAC7B,CACF,CAAA,IAGF,CAAA,CAAG,EAAE,EACP,ECNO,SAASE,CAAAA,CAAyB,CAAE,QAAA,CAAAC,CAAAA,CAAU,WAAA,CAAAC,CAAAA,CAAa,GAAGC,CAAW,CAAA,CAAkC,CAEhH,IAAMxB,CAAAA,CAAQyB,aAAAA,CAAQ,IACbC,yCAAAA,CAA4B,CACjC,GAAGF,CACL,CAAC,CAAA,CACA,EAAE,CAAA,CAEL,OAAAR,CAAAA,CAAyB,CACvB,qBAAA,CAAuB,IAAMhB,CAAAA,CAAM,QAAA,EAAS,CAAE,qBAAA,CAAsBuB,CAAAA,EAAe,CAAA,CAAK,CAC1F,CAAC,CAAA,CAEMI,cAAAA,CAAC/B,CAAAA,CAAsB,QAAA,CAAtB,CAA+B,KAAA,CAAOI,CAAAA,CAAQ,QAAA,CAAAsB,EAAS,CACjE","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 if (account.isConnected) {\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\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 the useInitializeAutoConnect hook.\n */\ninterface InitializeAutoConnectProps {\n /** Function to initialize auto connect logic */\n initializeAutoConnect: () => Promise<void>;\n /** Optional error handler callback */\n onError?: (error: Error) => void;\n}\n\n/**\n * Custom hook for initializing wallet auto-connection with error handling.\n *\n * @remarks\n * This hook handles the initial connection logic (e.g., checking for a previously\n * connected wallet) 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.initializeAutoConnect - Async function that executes the auto-connect logic\n * @param props.onError - Optional custom error handler\n *\n * @example\n * ```tsx\n * // Basic usage with default error handling\n * useInitializeAutoConnect({\n * initializeAutoConnect: store.initializeAutoConnect\n * });\n *\n * // With custom error handling\n * useInitializeAutoConnect({\n * initializeAutoConnect: store.initializeAutoConnect,\n * onError: (error) => {\n * toast.error(`Failed to auto-connect: ${error.message}`);\n * }\n * });\n * ```\n */\nexport const useInitializeAutoConnect = ({ initializeAutoConnect, onError }: InitializeAutoConnectProps): void => {\n useEffect(() => {\n const initializeAutoConnectLocal = async () => {\n try {\n await initializeAutoConnect();\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 auto connect:', e));\n errorHandler(error as Error);\n }\n };\n // Initialize auto connect when component mounts\n initializeAutoConnectLocal();\n }, []); // Empty dependency array ensures single execution\n};\n","import { createSatelliteConnectStore, SatelliteConnectStoreInitialParameters } from '@tuwaio/satellite-core';\nimport { useMemo } from 'react';\n\nimport { SatelliteStoreContext } from '../hooks/satteliteHook';\nimport { useInitializeAutoConnect } from '../hooks/useInitializeAutoConnect';\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 useInitializeAutoConnect({\n initializeAutoConnect: () => store.getState().initializeAutoConnect(autoConnect ?? false),\n });\n\n return <SatelliteStoreContext.Provider value={store}>{children}</SatelliteStoreContext.Provider>;\n}\n"]}
|
package/dist/index.js
CHANGED
|
@@ -1,2 +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 {jsx}from'react/jsx-runtime';var i=createContext(null),n=e=>{let o=useContext(i);if(!o)throw new Error("useSatelliteConnectStore must be used within a SatelliteConnectProvider");return useStore(o,e)};function y({wagmiConfig:e}){let o=n(t=>t.updateActiveWallet);return watchAccount(e,{onChange:async t=>{o({walletType:`${OrbitAdapter.EVM}:${t?.connector?.type}`,address:t.address,chainId:t.chainId,rpcURL:t.chain?.rpcUrls.default.http[0],isConnected:t.isConnected});}}),null}function R(){let e=useWallets(),o=n(t=>t.updateActiveWallet);return useEffect(()=>{let t=e.filter(r=>r.accounts.length>0)[0];t&&o({address:t.accounts[0].address,isConnected:true,connectedAccount:t.accounts[0],connectedWallet:t});},[e]),null}var l=({initializeAutoConnect:e,onError:o})=>{useEffect(()=>{(async()=>{try{await e();}catch(r){(o??(a=>console.error("Failed to initialize auto connect:",a)))(r);}})();},[]);};function q({children:e,autoConnect:o,...t}){let r=useMemo(()=>createSatelliteConnectStore({...t}),[]);return l({initializeAutoConnect:()=>r.getState().initializeAutoConnect(o??!1)}),jsx(i.Provider,{value:r,children:e})}export{y as EVMWalletsWatcher,q as SatelliteConnectProvider,i as SatelliteStoreContext,R as SolanaWalletsWatcher,l as useInitializeAutoConnect,n as useSatelliteConnectStore};//# sourceMappingURL=index.js.map
|
|
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 {jsx}from'react/jsx-runtime';var i=createContext(null),n=e=>{let o=useContext(i);if(!o)throw new Error("useSatelliteConnectStore must be used within a SatelliteConnectProvider");return useStore(o,e)};function y({wagmiConfig:e}){let o=n(t=>t.updateActiveWallet);return watchAccount(e,{onChange:async t=>{t.isConnected&&o({walletType:`${OrbitAdapter.EVM}:${t?.connector?.type}`,address:t.address,chainId:t.chainId,rpcURL:t.chain?.rpcUrls.default.http[0],isConnected:t.isConnected});}}),null}function R(){let e=useWallets(),o=n(t=>t.updateActiveWallet);return useEffect(()=>{let t=e.filter(r=>r.accounts.length>0)[0];t&&o({address:t.accounts[0].address,isConnected:true,connectedAccount:t.accounts[0],connectedWallet:t});},[e]),null}var l=({initializeAutoConnect:e,onError:o})=>{useEffect(()=>{(async()=>{try{await e();}catch(r){(o??(a=>console.error("Failed to initialize auto connect:",a)))(r);}})();},[]);};function q({children:e,autoConnect:o,...t}){let r=useMemo(()=>createSatelliteConnectStore({...t}),[]);return l({initializeAutoConnect:()=>r.getState().initializeAutoConnect(o??!1)}),jsx(i.Provider,{value:r,children:e})}export{y as EVMWalletsWatcher,q as SatelliteConnectProvider,i as SatelliteStoreContext,R as SolanaWalletsWatcher,l as useInitializeAutoConnect,n as useSatelliteConnectStore};//# sourceMappingURL=index.js.map
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/hooks/satteliteHook.ts","../src/components/EVMWalletsWatcher.tsx","../src/components/SolanaWalletsWatcher.tsx","../src/hooks/useInitializeAutoConnect.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","useInitializeAutoConnect","initializeAutoConnect","onError","error","e","SatelliteConnectProvider","children","autoConnect","parameters","useMemo","createSatelliteConnectStore","jsx"],"mappings":"wUAQO,IAAMA,CAAAA,CAAwBC,aAAAA,CAAuD,IAAI,CAAA,CAqBnFC,CAAAA,CAA+BC,CAAAA,EAAsD,CAEhG,IAAMC,CAAAA,CAAQC,UAAAA,CAAWL,CAAqB,CAAA,CAG9C,GAAI,CAACI,CAAAA,CACH,MAAM,IAAI,KAAA,CAAM,yEAAyE,CAAA,CAI3F,OAAOE,QAAAA,CAASF,CAAAA,CAAOD,CAAQ,CACjC,ECtBO,SAASI,EAAkB,CAAE,WAAA,CAAAC,CAAY,CAAA,CAA4B,CAE1E,IAAMC,CAAAA,CAAqBP,CAAAA,CAA0BQ,CAAAA,EAAUA,CAAAA,CAAM,kBAAkB,CAAA,CAGvF,OAAAC,YAAAA,CAAaH,CAAAA,CAAa,CACxB,SAAU,MAAOI,CAAAA,EAAY,CAE3BH,CAAAA,CAAmB,CAEjB,UAAA,CAAY,CAAA,EAAGI,YAAAA,CAAa,GAAG,CAAA,CAAA,EAAID,CAAAA,EAAS,SAAA,EAAW,IAAI,CAAA,CAAA,CAE3D,OAAA,CAASA,CAAAA,CAAQ,QAEjB,OAAA,CAASA,CAAAA,CAAQ,OAAA,CAEjB,MAAA,CAAQA,CAAAA,CAAQ,KAAA,EAAO,OAAA,CAAQ,OAAA,CAAQ,IAAA,CAAK,CAAC,CAAA,CAE7C,WAAA,CAAaA,CAAAA,CAAQ,WACvB,CAAC,EACH,CACF,CAAC,CAAA,CAGM,IACT,C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CAAAA,CAAM,QAAA,EAAS,CAAE,qBAAA,CAAsBuB,CAAAA,EAAe,CAAA,CAAK,CAC1F,CAAC,CAAA,CAEMI,GAAAA,CAAC/B,CAAAA,CAAsB,QAAA,CAAtB,CAA+B,KAAA,CAAOI,CAAAA,CAAQ,QAAA,CAAAsB,EAAS,CACjE","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 the useInitializeAutoConnect hook.\n */\ninterface InitializeAutoConnectProps {\n /** Function to initialize auto connect logic */\n initializeAutoConnect: () => Promise<void>;\n /** Optional error handler callback */\n onError?: (error: Error) => void;\n}\n\n/**\n * Custom hook for initializing wallet auto-connection with error handling.\n *\n * @remarks\n * This hook handles the initial connection logic (e.g., checking for a previously\n * connected wallet) 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.initializeAutoConnect - Async function that executes the auto-connect logic\n * @param props.onError - Optional custom error handler\n *\n * @example\n * ```tsx\n * // Basic usage with default error handling\n * useInitializeAutoConnect({\n * initializeAutoConnect: store.initializeAutoConnect\n * });\n *\n * // With custom error handling\n * useInitializeAutoConnect({\n * initializeAutoConnect: store.initializeAutoConnect,\n * onError: (error) => {\n * toast.error(`Failed to auto-connect: ${error.message}`);\n * }\n * });\n * ```\n */\nexport const useInitializeAutoConnect = ({ initializeAutoConnect, onError }: InitializeAutoConnectProps): void => {\n useEffect(() => {\n const initializeAutoConnectLocal = async () => {\n try {\n await initializeAutoConnect();\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 auto connect:', e));\n errorHandler(error as Error);\n }\n };\n // Initialize auto connect when component mounts\n initializeAutoConnectLocal();\n }, []); // Empty dependency array ensures single execution\n};\n","import { createSatelliteConnectStore, SatelliteConnectStoreInitialParameters } from '@tuwaio/satellite-core';\nimport { useMemo } from 'react';\n\nimport { SatelliteStoreContext } from '../hooks/satteliteHook';\nimport { useInitializeAutoConnect } from '../hooks/useInitializeAutoConnect';\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 useInitializeAutoConnect({\n initializeAutoConnect: () => store.getState().initializeAutoConnect(autoConnect ?? false),\n });\n\n return <SatelliteStoreContext.Provider value={store}>{children}</SatelliteStoreContext.Provider>;\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/hooks/satteliteHook.ts","../src/components/EVMWalletsWatcher.tsx","../src/components/SolanaWalletsWatcher.tsx","../src/hooks/useInitializeAutoConnect.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","useInitializeAutoConnect","initializeAutoConnect","onError","error","e","SatelliteConnectProvider","children","autoConnect","parameters","useMemo","createSatelliteConnectStore","jsx"],"mappings":"wUAQO,IAAMA,CAAAA,CAAwBC,aAAAA,CAAuD,IAAI,CAAA,CAqBnFC,CAAAA,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QAAA,CAAS,CAAC,CAAA,CAAE,QAElC,WAAA,CAAa,IAAA,CAEb,gBAAA,CAAkBA,CAAAA,CAAa,QAAA,CAAS,CAAC,CAAA,CACzC,eAAA,CAAiBA,CACnB,CAAC,EAEL,CAAA,CAAG,CAACH,CAAO,CAAC,CAAA,CAGL,IACT,CCJO,IAAMK,CAAAA,CAA2B,CAAC,CAAE,qBAAA,CAAAC,CAAAA,CAAuB,OAAA,CAAAC,CAAQ,CAAA,GAAwC,CAChHL,SAAAA,CAAU,IAAM,CAAA,CACqB,SAAY,CAC7C,GAAI,CACF,MAAMI,CAAAA,GACR,CAAA,MAASE,CAAAA,CAAO,CAAA,CAEOD,CAAAA,GAAaE,CAAAA,EAAa,OAAA,CAAQ,KAAA,CAAM,oCAAA,CAAsCA,CAAC,CAAA,CAAA,EACvFD,CAAc,EAC7B,CACF,CAAA,IAGF,CAAA,CAAG,EAAE,EACP,ECNO,SAASE,CAAAA,CAAyB,CAAE,QAAA,CAAAC,CAAAA,CAAU,WAAA,CAAAC,CAAAA,CAAa,GAAGC,CAAW,CAAA,CAAkC,CAEhH,IAAMxB,CAAAA,CAAQyB,OAAAA,CAAQ,IACbC,2BAAAA,CAA4B,CACjC,GAAGF,CACL,CAAC,CAAA,CACA,EAAE,CAAA,CAEL,OAAAR,CAAAA,CAAyB,CACvB,qBAAA,CAAuB,IAAMhB,CAAAA,CAAM,QAAA,EAAS,CAAE,qBAAA,CAAsBuB,CAAAA,EAAe,CAAA,CAAK,CAC1F,CAAC,CAAA,CAEMI,GAAAA,CAAC/B,CAAAA,CAAsB,QAAA,CAAtB,CAA+B,KAAA,CAAOI,CAAAA,CAAQ,QAAA,CAAAsB,EAAS,CACjE","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 if (account.isConnected) {\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\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 the useInitializeAutoConnect hook.\n */\ninterface InitializeAutoConnectProps {\n /** Function to initialize auto connect logic */\n initializeAutoConnect: () => Promise<void>;\n /** Optional error handler callback */\n onError?: (error: Error) => void;\n}\n\n/**\n * Custom hook for initializing wallet auto-connection with error handling.\n *\n * @remarks\n * This hook handles the initial connection logic (e.g., checking for a previously\n * connected wallet) 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.initializeAutoConnect - Async function that executes the auto-connect logic\n * @param props.onError - Optional custom error handler\n *\n * @example\n * ```tsx\n * // Basic usage with default error handling\n * useInitializeAutoConnect({\n * initializeAutoConnect: store.initializeAutoConnect\n * });\n *\n * // With custom error handling\n * useInitializeAutoConnect({\n * initializeAutoConnect: store.initializeAutoConnect,\n * onError: (error) => {\n * toast.error(`Failed to auto-connect: ${error.message}`);\n * }\n * });\n * ```\n */\nexport const useInitializeAutoConnect = ({ initializeAutoConnect, onError }: InitializeAutoConnectProps): void => {\n useEffect(() => {\n const initializeAutoConnectLocal = async () => {\n try {\n await initializeAutoConnect();\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 auto connect:', e));\n errorHandler(error as Error);\n }\n };\n // Initialize auto connect when component mounts\n initializeAutoConnectLocal();\n }, []); // Empty dependency array ensures single execution\n};\n","import { createSatelliteConnectStore, SatelliteConnectStoreInitialParameters } from '@tuwaio/satellite-core';\nimport { useMemo } from 'react';\n\nimport { SatelliteStoreContext } from '../hooks/satteliteHook';\nimport { useInitializeAutoConnect } from '../hooks/useInitializeAutoConnect';\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 useInitializeAutoConnect({\n initializeAutoConnect: () => store.getState().initializeAutoConnect(autoConnect ?? false),\n });\n\n return <SatelliteStoreContext.Provider value={store}>{children}</SatelliteStoreContext.Provider>;\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tuwaio/satellite-react",
|
|
3
|
-
"version": "1.0.0-fix-test-alpha.
|
|
3
|
+
"version": "1.0.0-fix-test-alpha.13.79d73b8",
|
|
4
4
|
"private": false,
|
|
5
5
|
"author": "Oleksandr Tkach",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -58,9 +58,9 @@
|
|
|
58
58
|
"tsup": "^8.5.0",
|
|
59
59
|
"typescript": "^5.9.2",
|
|
60
60
|
"zustand": "^5.0.8",
|
|
61
|
-
"@tuwaio/orbit-
|
|
62
|
-
"@tuwaio/
|
|
63
|
-
"@tuwaio/
|
|
61
|
+
"@tuwaio/orbit-solana": "^1.0.0-fix-test-alpha.13.79d73b8",
|
|
62
|
+
"@tuwaio/satellite-core": "^1.0.0-fix-test-alpha.13.79d73b8",
|
|
63
|
+
"@tuwaio/orbit-core": "^1.0.0-fix-test-alpha.13.79d73b8"
|
|
64
64
|
},
|
|
65
65
|
"scripts": {
|
|
66
66
|
"start": "tsup src/index.ts --watch",
|