@tuwaio/satellite-react 1.0.0-fix-test-alpha.45.9abac57 → 1.0.0-fix-test-alpha.46.00f5d3d
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 +7 -7
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 s=react.createContext(null),
|
|
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 s=react.createContext(null),i=n=>{let t=react.useContext(s);if(!t)throw new Error("useSatelliteConnectStore must be used within a SatelliteConnectProvider");return zustand.useStore(t,n)};function B({wagmiConfig:n,siwe:t}){let r=i(l=>l.activeWallet),o=i(l=>l.updateActiveWallet),c=i(l=>l.walletConnectionError),e=i(l=>l.disconnect);return react.useEffect(()=>{t?.enabled&&!t?.isSignedIn&&t?.isRejected&&e();},[t,e]),react.useEffect(()=>core.watchAccount(n,{onChange:a=>{if(a?.status==="disconnected"&&e(),r&&orbitCore.getAdapterFromWalletType(r.walletType)!==orbitCore.OrbitAdapter.EVM||!a.address||c)return;if(t?.enabled?t.isSignedIn:true){let d=r?.walletType,f=d?{walletType:d,address:a.address,chainId:a.chainId,rpcURL:a.chain?.rpcUrls.default.http[0],isConnected:a.isConnected}:{address:a.address,chainId:a.chainId,rpcURL:a.chain?.rpcUrls.default.http[0],isConnected:a.isConnected};o(f);}}}),[r?.walletType,t,c]),null}function X(){let n=react$1.useWallets(),t=i(e=>e.updateActiveWallet),r=i(e=>e.walletConnectionError),o=i(e=>e.activeWallet),c=i(e=>e.disconnect);return react.useEffect(()=>{if(o&&orbitCore.getAdapterFromWalletType(o.walletType)===orbitCore.OrbitAdapter.SOLANA){let e=n.filter(l=>orbitCore.getWalletTypeFromConnectorName(orbitCore.OrbitAdapter.SOLANA,orbitCore.formatWalletName(l.name))===o.walletType)[0];r||t({address:e?.accounts[0]?.address,isConnected:e?.accounts.length>0,connectedAccount:e?.accounts[0],connectedWallet:e}),e?.accounts.length===0&&c();}},[o?.walletType,n,r,t,c]),null}var u=({initializeAutoConnect:n,onError:t})=>{react.useEffect(()=>{(async()=>{try{await n();}catch(o){(t??(e=>console.error("Failed to initialize auto connect:",e)))(o);}})();},[]);};function re({children:n,autoConnect:t,...r}){let o=react.useMemo(()=>satelliteCore.createSatelliteConnectStore({...r}),[]);return react.useEffect(()=>{o.getState().disconnectAll();},[]),u({initializeAutoConnect:()=>o.getState().initializeAutoConnect(t??!1)}),jsxRuntime.jsx(s.Provider,{value:o,children:n})}exports.EVMWalletsWatcher=B;exports.SatelliteConnectProvider=re;exports.SatelliteStoreContext=s;exports.SolanaWalletsWatcher=X;exports.useInitializeAutoConnect=u;exports.useSatelliteConnectStore=i;//# 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","siwe","updateActiveWallet","state","walletConnectionError","disconnect","lastConnectedWallet","lastConnectedWalletHelpers","useEffect","watchAccount","account","getAdapterFromWalletType","OrbitAdapter","walletType","walletUpdate","SolanaWalletsWatcher","wallets","useWallets","activeWalletFromStore","activeWallet","w","getWalletTypeFromConnectorName","useInitializeAutoConnect","initializeAutoConnect","onError","error","SatelliteConnectProvider","children","autoConnect","parameters","useMemo","createSatelliteConnectStore","jsx"],"mappings":"6QAUaA,CAAAA,CAAwBC,mBAAAA,CAA0E,IAAI,CAAA,CAqBtGC,CAAAA,CAA+BC,GAAyE,CAEnH,IAAMC,CAAAA,CAAQC,gBAAAA,CAAWL,CAAqB,CAAA,CAG9C,GAAI,CAACI,CAAAA,CACH,MAAM,IAAI,KAAA,CAAM,yEAAyE,EAI3F,OAAOE,gBAAAA,CAASF,CAAAA,CAAOD,CAAQ,CACjC,ECpCO,SAASI,CAAAA,CAAkB,CAChC,YAAAC,CAAAA,CACA,IAAA,CAAAC,CACF,CAAA,CAOG,CACD,IAAMC,CAAAA,CAAqBR,CAAAA,CAA0BS,CAAAA,EAAUA,EAAM,kBAAkB,CAAA,CACjFC,CAAAA,CAAwBV,CAAAA,CAA0BS,CAAAA,EAAUA,CAAAA,CAAM,qBAAqB,CAAA,CACvFE,CAAAA,CAAaX,CAAAA,CAA0BS,CAAAA,EAAUA,CAAAA,CAAM,UAAU,EAEjEG,CAAAA,CAAsBC,oCAAAA,CAA2B,wBAAuB,CAE9E,OAAAC,gBAAU,IAAM,CACVP,CAAAA,EAAM,OAAA,EAAW,CAACA,CAAAA,EAAM,YAAcA,CAAAA,EAAM,UAAA,EAC9CI,CAAAA,GAEJ,CAAA,CAAG,CAACJ,EAAMI,CAAU,CAAC,CAAA,CAErBG,eAAAA,CAAU,IAiCQC,iBAAAA,CAAaT,EAAa,CAAE,QAAA,CAhCqBU,GAAY,CAC3E,GACGJ,GAAuBK,kCAAAA,CAAyBL,CAAAA,CAAoB,UAAU,CAAA,GAAMM,sBAAAA,CAAa,GAAA,EAClG,CAACF,CAAAA,CAAQ,OAAA,EACTN,CAAAA,CAEA,OAKF,GAFqBH,CAAAA,EAAM,QAAUA,CAAAA,CAAK,UAAA,C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1B,CAAAA,CAAM,QAAA,EAAS,CAAE,qBAAA,CAAsBgC,CAAAA,EAAe,EAAK,CAC1F,CAAC,CAAA,CAEMI,cAAAA,CAACxC,CAAAA,CAAsB,QAAA,CAAtB,CAA+B,KAAA,CAAOI,CAAAA,CAAQ,QAAA,CAAA+B,CAAAA,CAAS,CACjE","file":"index.cjs","sourcesContent":["import { ISatelliteConnectStore } from '@tuwaio/satellite-core';\nimport { createContext, useContext } from 'react';\nimport { StoreApi, useStore } from 'zustand';\n\nimport { Connector, Wallet } from '../types';\n\n/**\n * React Context for providing Satellite Connect store throughout the application\n * @internal\n */\nexport const SatelliteStoreContext = createContext<StoreApi<ISatelliteConnectStore<Connector, Wallet>> | 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<Connector, Wallet>) => 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 { getAdapterFromWalletType, lastConnectedWalletHelpers, OrbitAdapter } from '@tuwaio/orbit-core';\nimport { Config, watchAccount, WatchAccountParameters } from '@wagmi/core';\nimport { useEffect } from 'react';\n\nimport { useSatelliteConnectStore } from '../hooks/satteliteHook';\n\nexport function EVMWalletsWatcher({\n wagmiConfig,\n siwe,\n}: {\n wagmiConfig: Config;\n siwe?: {\n isRejected: boolean;\n isSignedIn: boolean;\n enabled?: boolean;\n };\n}) {\n const updateActiveWallet = useSatelliteConnectStore((state) => state.updateActiveWallet);\n const walletConnectionError = useSatelliteConnectStore((state) => state.walletConnectionError);\n const disconnect = useSatelliteConnectStore((state) => state.disconnect);\n\n const lastConnectedWallet = lastConnectedWalletHelpers.getLastConnectedWallet();\n\n useEffect(() => {\n if (siwe?.enabled && !siwe?.isSignedIn && siwe?.isRejected) {\n disconnect();\n }\n }, [siwe, disconnect]);\n\n useEffect(() => {\n const handleAccountChange: WatchAccountParameters['onChange'] = (account) => {\n if (\n (lastConnectedWallet && getAdapterFromWalletType(lastConnectedWallet.walletType) !== OrbitAdapter.EVM) ||\n !account.address ||\n walletConnectionError\n ) {\n return;\n }\n\n const shouldUpdate = siwe?.enabled ? siwe.isSignedIn : true;\n\n if (shouldUpdate) {\n const walletType = lastConnectedWallet?.walletType;\n const walletUpdate = walletType\n ? {\n walletType,\n address: account.address,\n chainId: account.chainId,\n rpcURL: account.chain?.rpcUrls.default.http[0],\n isConnected: account.isConnected,\n }\n : {\n address: account.address,\n chainId: account.chainId,\n rpcURL: account.chain?.rpcUrls.default.http[0],\n isConnected: account.isConnected,\n };\n\n updateActiveWallet(walletUpdate);\n }\n };\n\n const unwatch = watchAccount(wagmiConfig, { onChange: handleAccountChange });\n\n return unwatch;\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [lastConnectedWallet?.walletType, wagmiConfig, siwe, updateActiveWallet, walletConnectionError]);\n\n return null;\n}\n","import { getAdapterFromWalletType, getWalletTypeFromConnectorName, OrbitAdapter } from '@tuwaio/orbit-core';\nimport { 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 const wallets = useWallets();\n\n // Get the updateActiveWallet function from the Satellite store\n const updateActiveWallet = useSatelliteConnectStore((state) => state.updateActiveWallet);\n const walletConnectionError = useSatelliteConnectStore((state) => state.walletConnectionError);\n const activeWalletFromStore = useSatelliteConnectStore((state) => state.activeWallet);\n const disconnect = useSatelliteConnectStore((state) => state.disconnect);\n\n // Watch for changes in connected wallets\n useEffect(() => {\n if (activeWalletFromStore && getAdapterFromWalletType(activeWalletFromStore.walletType) === OrbitAdapter.SOLANA) {\n const activeWallet = wallets.filter(\n (w) => getWalletTypeFromConnectorName(OrbitAdapter.SOLANA, w.name) === activeWalletFromStore.walletType,\n )[0];\n\n if (!walletConnectionError) {\n // Update the Satellite store with the active wallet information\n updateActiveWallet({\n // Use the first account's address\n address: activeWallet?.accounts[0]?.address,\n // Set connection status\n isConnected: activeWallet?.accounts.length > 0,\n // Store Wallet Standard specific information\n connectedAccount: activeWallet?.accounts[0],\n connectedWallet: activeWallet,\n });\n }\n if (activeWallet?.accounts.length === 0) {\n // If the wallet is disconnected from the wallet provider, disconnect from Satellite store as well\n disconnect();\n }\n }\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [activeWalletFromStore?.walletType, wallets, walletConnectionError, updateActiveWallet, disconnect]); // 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 { useEffect, useMemo } from 'react';\n\nimport { SatelliteStoreContext } from '../hooks/satteliteHook';\nimport { useInitializeAutoConnect } from '../hooks/useInitializeAutoConnect';\nimport { Connector, Wallet } from '../types';\n\n/**\n * Props for SatelliteConnectProvider component\n */\ninterface SatelliteConnectProviderProps extends SatelliteConnectStoreInitialParameters<Connector, Wallet> {\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<Connector, Wallet>({\n ...parameters,\n });\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, []); // Empty dependency array as store should be created only once\n\n // Disconnect from any existing wallets on mount\n useEffect(() => {\n store.getState().disconnectAll();\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, []);\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","siwe","activeWallet","state","updateActiveWallet","walletConnectionError","disconnect","useEffect","watchAccount","account","getAdapterFromWalletType","OrbitAdapter","walletType","walletUpdate","SolanaWalletsWatcher","wallets","useWallets","activeWalletFromStore","w","getWalletTypeFromConnectorName","formatWalletName","useInitializeAutoConnect","initializeAutoConnect","onError","error","SatelliteConnectProvider","children","autoConnect","parameters","useMemo","createSatelliteConnectStore","jsx"],"mappings":"yQAUO,IAAMA,CAAAA,CAAwBC,oBAA0E,IAAI,CAAA,CAqBtGC,EAA+BC,CAAAA,EAAyE,CAEnH,IAAMC,CAAAA,CAAQC,gBAAAA,CAAWL,CAAqB,CAAA,CAG9C,GAA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AAA8B,CAAAA,CAAS,CACjE","file":"index.cjs","sourcesContent":["import { ISatelliteConnectStore } from '@tuwaio/satellite-core';\nimport { createContext, useContext } from 'react';\nimport { StoreApi, useStore } from 'zustand';\n\nimport { Connector, Wallet } from '../types';\n\n/**\n * React Context for providing Satellite Connect store throughout the application\n * @internal\n */\nexport const SatelliteStoreContext = createContext<StoreApi<ISatelliteConnectStore<Connector, Wallet>> | 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<Connector, Wallet>) => 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 { getAdapterFromWalletType, OrbitAdapter } from '@tuwaio/orbit-core';\nimport { Config, watchAccount, WatchAccountParameters } from '@wagmi/core';\nimport { useEffect } from 'react';\n\nimport { useSatelliteConnectStore } from '../hooks/satteliteHook';\n\nexport function EVMWalletsWatcher({\n wagmiConfig,\n siwe,\n}: {\n wagmiConfig: Config;\n siwe?: {\n isRejected: boolean;\n isSignedIn: boolean;\n enabled?: boolean;\n };\n}) {\n const activeWallet = useSatelliteConnectStore((state) => state.activeWallet);\n const updateActiveWallet = useSatelliteConnectStore((state) => state.updateActiveWallet);\n const walletConnectionError = useSatelliteConnectStore((state) => state.walletConnectionError);\n const disconnect = useSatelliteConnectStore((state) => state.disconnect);\n\n useEffect(() => {\n if (siwe?.enabled && !siwe?.isSignedIn && siwe?.isRejected) {\n disconnect();\n }\n }, [siwe, disconnect]);\n\n useEffect(() => {\n const handleAccountChange: WatchAccountParameters['onChange'] = (account) => {\n if (account?.status === 'disconnected') {\n disconnect();\n }\n\n if (\n (activeWallet && getAdapterFromWalletType(activeWallet.walletType) !== OrbitAdapter.EVM) ||\n !account.address ||\n walletConnectionError\n ) {\n return;\n }\n\n const shouldUpdate = siwe?.enabled ? siwe.isSignedIn : true;\n\n if (shouldUpdate) {\n const walletType = activeWallet?.walletType;\n const walletUpdate = walletType\n ? {\n walletType,\n address: account.address,\n chainId: account.chainId,\n rpcURL: account.chain?.rpcUrls.default.http[0],\n isConnected: account.isConnected,\n }\n : {\n address: account.address,\n chainId: account.chainId,\n rpcURL: account.chain?.rpcUrls.default.http[0],\n isConnected: account.isConnected,\n };\n\n updateActiveWallet(walletUpdate);\n }\n };\n\n const unwatch = watchAccount(wagmiConfig, { onChange: handleAccountChange });\n\n return unwatch;\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [activeWallet?.walletType, siwe, walletConnectionError]);\n\n return null;\n}\n","import {\n formatWalletName,\n getAdapterFromWalletType,\n getWalletTypeFromConnectorName,\n OrbitAdapter,\n} from '@tuwaio/orbit-core';\nimport { 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 const wallets = useWallets();\n\n // Get the updateActiveWallet function from the Satellite store\n const updateActiveWallet = useSatelliteConnectStore((state) => state.updateActiveWallet);\n const walletConnectionError = useSatelliteConnectStore((state) => state.walletConnectionError);\n const activeWalletFromStore = useSatelliteConnectStore((state) => state.activeWallet);\n const disconnect = useSatelliteConnectStore((state) => state.disconnect);\n\n // Watch for changes in connected wallets\n useEffect(() => {\n if (activeWalletFromStore && getAdapterFromWalletType(activeWalletFromStore.walletType) === OrbitAdapter.SOLANA) {\n const activeWallet = wallets.filter(\n (w) =>\n getWalletTypeFromConnectorName(OrbitAdapter.SOLANA, formatWalletName(w.name)) ===\n activeWalletFromStore.walletType,\n )[0];\n\n if (!walletConnectionError) {\n // Update the Satellite store with the active wallet information\n updateActiveWallet({\n // Use the first account's address\n address: activeWallet?.accounts[0]?.address,\n // Set connection status\n isConnected: activeWallet?.accounts.length > 0,\n // Store Wallet Standard specific information\n connectedAccount: activeWallet?.accounts[0],\n connectedWallet: activeWallet,\n });\n }\n if (activeWallet?.accounts.length === 0) {\n // If the wallet is disconnected from the wallet provider, disconnect from Satellite store as well\n disconnect();\n }\n }\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [activeWalletFromStore?.walletType, wallets, walletConnectionError, updateActiveWallet, disconnect]); // 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 { useEffect, useMemo } from 'react';\n\nimport { SatelliteStoreContext } from '../hooks/satteliteHook';\nimport { useInitializeAutoConnect } from '../hooks/useInitializeAutoConnect';\nimport { Connector, Wallet } from '../types';\n\n/**\n * Props for SatelliteConnectProvider component\n */\ninterface SatelliteConnectProviderProps extends SatelliteConnectStoreInitialParameters<Connector, Wallet> {\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<Connector, Wallet>({\n ...parameters,\n });\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, []); // Empty dependency array as store should be created only once\n\n // Disconnect from any existing wallets on mount\n useEffect(() => {\n store.getState().disconnectAll();\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, []);\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 {
|
|
1
|
+
import {getAdapterFromWalletType,OrbitAdapter,getWalletTypeFromConnectorName,formatWalletName}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 s=createContext(null),i=n=>{let t=useContext(s);if(!t)throw new Error("useSatelliteConnectStore must be used within a SatelliteConnectProvider");return useStore(t,n)};function B({wagmiConfig:n,siwe:t}){let r=i(l=>l.activeWallet),o=i(l=>l.updateActiveWallet),c=i(l=>l.walletConnectionError),e=i(l=>l.disconnect);return useEffect(()=>{t?.enabled&&!t?.isSignedIn&&t?.isRejected&&e();},[t,e]),useEffect(()=>watchAccount(n,{onChange:a=>{if(a?.status==="disconnected"&&e(),r&&getAdapterFromWalletType(r.walletType)!==OrbitAdapter.EVM||!a.address||c)return;if(t?.enabled?t.isSignedIn:true){let d=r?.walletType,f=d?{walletType:d,address:a.address,chainId:a.chainId,rpcURL:a.chain?.rpcUrls.default.http[0],isConnected:a.isConnected}:{address:a.address,chainId:a.chainId,rpcURL:a.chain?.rpcUrls.default.http[0],isConnected:a.isConnected};o(f);}}}),[r?.walletType,t,c]),null}function X(){let n=useWallets(),t=i(e=>e.updateActiveWallet),r=i(e=>e.walletConnectionError),o=i(e=>e.activeWallet),c=i(e=>e.disconnect);return useEffect(()=>{if(o&&getAdapterFromWalletType(o.walletType)===OrbitAdapter.SOLANA){let e=n.filter(l=>getWalletTypeFromConnectorName(OrbitAdapter.SOLANA,formatWalletName(l.name))===o.walletType)[0];r||t({address:e?.accounts[0]?.address,isConnected:e?.accounts.length>0,connectedAccount:e?.accounts[0],connectedWallet:e}),e?.accounts.length===0&&c();}},[o?.walletType,n,r,t,c]),null}var u=({initializeAutoConnect:n,onError:t})=>{useEffect(()=>{(async()=>{try{await n();}catch(o){(t??(e=>console.error("Failed to initialize auto connect:",e)))(o);}})();},[]);};function re({children:n,autoConnect:t,...r}){let o=useMemo(()=>createSatelliteConnectStore({...r}),[]);return useEffect(()=>{o.getState().disconnectAll();},[]),u({initializeAutoConnect:()=>o.getState().initializeAutoConnect(t??!1)}),jsx(s.Provider,{value:o,children:n})}export{B as EVMWalletsWatcher,re as SatelliteConnectProvider,s as SatelliteStoreContext,X as SolanaWalletsWatcher,u as useInitializeAutoConnect,i 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","siwe","updateActiveWallet","state","walletConnectionError","disconnect","lastConnectedWallet","lastConnectedWalletHelpers","useEffect","watchAccount","account","getAdapterFromWalletType","OrbitAdapter","walletType","walletUpdate","SolanaWalletsWatcher","wallets","useWallets","activeWalletFromStore","activeWallet","w","getWalletTypeFromConnectorName","useInitializeAutoConnect","initializeAutoConnect","onError","error","SatelliteConnectProvider","children","autoConnect","parameters","useMemo","createSatelliteConnectStore","jsx"],"mappings":"+ZAUaA,CAAAA,CAAwBC,aAAAA,CAA0E,IAAI,CAAA,CAqBtGC,CAAAA,CAA+BC,GAAyE,CAEnH,IAAMC,CAAAA,CAAQC,UAAAA,CAAWL,CAAqB,CAAA,CAG9C,GAAI,CAACI,CAAAA,CACH,MAAM,IAAI,KAAA,CAAM,yEAAyE,EAI3F,OAAOE,QAAAA,CAASF,CAAAA,CAAOD,CAAQ,CACjC,ECpCO,SAASI,CAAAA,CAAkB,CAChC,YAAAC,CAAAA,CACA,IAAA,CAAAC,CACF,CAAA,CAOG,CACD,IAAMC,CAAAA,CAAqBR,CAAAA,CAA0BS,CAAAA,EAAUA,EAAM,kBAAkB,CAAA,CACjFC,CAAAA,CAAwBV,CAAAA,CAA0BS,CAAAA,EAAUA,CAAAA,CAAM,qBAAqB,CAAA,CACvFE,CAAAA,CAAaX,CAAAA,CAA0BS,CAAAA,EAAUA,CAAAA,CAAM,UAAU,EAEjEG,CAAAA,CAAsBC,0BAAAA,CAA2B,wBAAuB,CAE9E,OAAAC,UAAU,IAAM,CACVP,CAAAA,EAAM,OAAA,EAAW,CAACA,CAAAA,EAAM,YAAcA,CAAAA,EAAM,UAAA,EAC9CI,CAAAA,GAEJ,CAAA,CAAG,CAACJ,EAAMI,CAAU,CAAC,CAAA,CAErBG,SAAAA,CAAU,IAiCQC,YAAAA,CAAaT,EAAa,CAAE,QAAA,CAhCqBU,GAAY,CAC3E,GACGJ,GAAuBK,wBAAAA,CAAyBL,CAAAA,CAAoB,UAAU,CAAA,GAAMM,YAAAA,CAAa,GAAA,EAClG,CAACF,CAAAA,CAAQ,OAAA,EACTN,CAAAA,CAEA,OAKF,GAFqBH,CAAAA,EAAM,QAAUA,CAAAA,CAAK,UAAA,CAAa,IAAA,CAErC,CAChB,IAAMY,CAAAA,CAAaP,GA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,CAAAA,EAAe,EAAK,CAC1F,CAAC,CAAA,CAEMI,GAAAA,CAACxC,CAAAA,CAAsB,QAAA,CAAtB,CAA+B,KAAA,CAAOI,CAAAA,CAAQ,QAAA,CAAA+B,CAAAA,CAAS,CACjE","file":"index.js","sourcesContent":["import { ISatelliteConnectStore } from '@tuwaio/satellite-core';\nimport { createContext, useContext } from 'react';\nimport { StoreApi, useStore } from 'zustand';\n\nimport { Connector, Wallet } from '../types';\n\n/**\n * React Context for providing Satellite Connect store throughout the application\n * @internal\n */\nexport const SatelliteStoreContext = createContext<StoreApi<ISatelliteConnectStore<Connector, Wallet>> | 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<Connector, Wallet>) => 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 { getAdapterFromWalletType, lastConnectedWalletHelpers, OrbitAdapter } from '@tuwaio/orbit-core';\nimport { Config, watchAccount, WatchAccountParameters } from '@wagmi/core';\nimport { useEffect } from 'react';\n\nimport { useSatelliteConnectStore } from '../hooks/satteliteHook';\n\nexport function EVMWalletsWatcher({\n wagmiConfig,\n siwe,\n}: {\n wagmiConfig: Config;\n siwe?: {\n isRejected: boolean;\n isSignedIn: boolean;\n enabled?: boolean;\n };\n}) {\n const updateActiveWallet = useSatelliteConnectStore((state) => state.updateActiveWallet);\n const walletConnectionError = useSatelliteConnectStore((state) => state.walletConnectionError);\n const disconnect = useSatelliteConnectStore((state) => state.disconnect);\n\n const lastConnectedWallet = lastConnectedWalletHelpers.getLastConnectedWallet();\n\n useEffect(() => {\n if (siwe?.enabled && !siwe?.isSignedIn && siwe?.isRejected) {\n disconnect();\n }\n }, [siwe, disconnect]);\n\n useEffect(() => {\n const handleAccountChange: WatchAccountParameters['onChange'] = (account) => {\n if (\n (lastConnectedWallet && getAdapterFromWalletType(lastConnectedWallet.walletType) !== OrbitAdapter.EVM) ||\n !account.address ||\n walletConnectionError\n ) {\n return;\n }\n\n const shouldUpdate = siwe?.enabled ? siwe.isSignedIn : true;\n\n if (shouldUpdate) {\n const walletType = lastConnectedWallet?.walletType;\n const walletUpdate = walletType\n ? {\n walletType,\n address: account.address,\n chainId: account.chainId,\n rpcURL: account.chain?.rpcUrls.default.http[0],\n isConnected: account.isConnected,\n }\n : {\n address: account.address,\n chainId: account.chainId,\n rpcURL: account.chain?.rpcUrls.default.http[0],\n isConnected: account.isConnected,\n };\n\n updateActiveWallet(walletUpdate);\n }\n };\n\n const unwatch = watchAccount(wagmiConfig, { onChange: handleAccountChange });\n\n return unwatch;\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [lastConnectedWallet?.walletType, wagmiConfig, siwe, updateActiveWallet, walletConnectionError]);\n\n return null;\n}\n","import { getAdapterFromWalletType, getWalletTypeFromConnectorName, OrbitAdapter } from '@tuwaio/orbit-core';\nimport { 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 const wallets = useWallets();\n\n // Get the updateActiveWallet function from the Satellite store\n const updateActiveWallet = useSatelliteConnectStore((state) => state.updateActiveWallet);\n const walletConnectionError = useSatelliteConnectStore((state) => state.walletConnectionError);\n const activeWalletFromStore = useSatelliteConnectStore((state) => state.activeWallet);\n const disconnect = useSatelliteConnectStore((state) => state.disconnect);\n\n // Watch for changes in connected wallets\n useEffect(() => {\n if (activeWalletFromStore && getAdapterFromWalletType(activeWalletFromStore.walletType) === OrbitAdapter.SOLANA) {\n const activeWallet = wallets.filter(\n (w) => getWalletTypeFromConnectorName(OrbitAdapter.SOLANA, w.name) === activeWalletFromStore.walletType,\n )[0];\n\n if (!walletConnectionError) {\n // Update the Satellite store with the active wallet information\n updateActiveWallet({\n // Use the first account's address\n address: activeWallet?.accounts[0]?.address,\n // Set connection status\n isConnected: activeWallet?.accounts.length > 0,\n // Store Wallet Standard specific information\n connectedAccount: activeWallet?.accounts[0],\n connectedWallet: activeWallet,\n });\n }\n if (activeWallet?.accounts.length === 0) {\n // If the wallet is disconnected from the wallet provider, disconnect from Satellite store as well\n disconnect();\n }\n }\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [activeWalletFromStore?.walletType, wallets, walletConnectionError, updateActiveWallet, disconnect]); // 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 { useEffect, useMemo } from 'react';\n\nimport { SatelliteStoreContext } from '../hooks/satteliteHook';\nimport { useInitializeAutoConnect } from '../hooks/useInitializeAutoConnect';\nimport { Connector, Wallet } from '../types';\n\n/**\n * Props for SatelliteConnectProvider component\n */\ninterface SatelliteConnectProviderProps extends SatelliteConnectStoreInitialParameters<Connector, Wallet> {\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<Connector, Wallet>({\n ...parameters,\n });\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, []); // Empty dependency array as store should be created only once\n\n // Disconnect from any existing wallets on mount\n useEffect(() => {\n store.getState().disconnectAll();\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, []);\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","siwe","activeWallet","state","updateActiveWallet","walletConnectionError","disconnect","useEffect","watchAccount","account","getAdapterFromWalletType","OrbitAdapter","walletType","walletUpdate","SolanaWalletsWatcher","wallets","useWallets","activeWalletFromStore","w","getWalletTypeFromConnectorName","formatWalletName","useInitializeAutoConnect","initializeAutoConnect","onError","error","SatelliteConnectProvider","children","autoConnect","parameters","useMemo","createSatelliteConnectStore","jsx"],"mappings":"iZAUO,IAAMA,CAAAA,CAAwBC,cAA0E,IAAI,CAAA,CAqBtGC,EAA+BC,CAAAA,EAAyE,CAEnH,IAAMC,CAAAA,CAAQC,UAAAA,CAAWL,CAAqB,CAAA,CAG9C,GAAI,CAACI,EACH,MAAM,IAAI,KAAA,CAAM,yEAAyE,CAAA,CAI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@tuwaio/satellite-core';\nimport { createContext, useContext } from 'react';\nimport { StoreApi, useStore } from 'zustand';\n\nimport { Connector, Wallet } from '../types';\n\n/**\n * React Context for providing Satellite Connect store throughout the application\n * @internal\n */\nexport const SatelliteStoreContext = createContext<StoreApi<ISatelliteConnectStore<Connector, Wallet>> | 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<Connector, Wallet>) => 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 { getAdapterFromWalletType, OrbitAdapter } from '@tuwaio/orbit-core';\nimport { Config, watchAccount, WatchAccountParameters } from '@wagmi/core';\nimport { useEffect } from 'react';\n\nimport { useSatelliteConnectStore } from '../hooks/satteliteHook';\n\nexport function EVMWalletsWatcher({\n wagmiConfig,\n siwe,\n}: {\n wagmiConfig: Config;\n siwe?: {\n isRejected: boolean;\n isSignedIn: boolean;\n enabled?: boolean;\n };\n}) {\n const activeWallet = useSatelliteConnectStore((state) => state.activeWallet);\n const updateActiveWallet = useSatelliteConnectStore((state) => state.updateActiveWallet);\n const walletConnectionError = useSatelliteConnectStore((state) => state.walletConnectionError);\n const disconnect = useSatelliteConnectStore((state) => state.disconnect);\n\n useEffect(() => {\n if (siwe?.enabled && !siwe?.isSignedIn && siwe?.isRejected) {\n disconnect();\n }\n }, [siwe, disconnect]);\n\n useEffect(() => {\n const handleAccountChange: WatchAccountParameters['onChange'] = (account) => {\n if (account?.status === 'disconnected') {\n disconnect();\n }\n\n if (\n (activeWallet && getAdapterFromWalletType(activeWallet.walletType) !== OrbitAdapter.EVM) ||\n !account.address ||\n walletConnectionError\n ) {\n return;\n }\n\n const shouldUpdate = siwe?.enabled ? siwe.isSignedIn : true;\n\n if (shouldUpdate) {\n const walletType = activeWallet?.walletType;\n const walletUpdate = walletType\n ? {\n walletType,\n address: account.address,\n chainId: account.chainId,\n rpcURL: account.chain?.rpcUrls.default.http[0],\n isConnected: account.isConnected,\n }\n : {\n address: account.address,\n chainId: account.chainId,\n rpcURL: account.chain?.rpcUrls.default.http[0],\n isConnected: account.isConnected,\n };\n\n updateActiveWallet(walletUpdate);\n }\n };\n\n const unwatch = watchAccount(wagmiConfig, { onChange: handleAccountChange });\n\n return unwatch;\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [activeWallet?.walletType, siwe, walletConnectionError]);\n\n return null;\n}\n","import {\n formatWalletName,\n getAdapterFromWalletType,\n getWalletTypeFromConnectorName,\n OrbitAdapter,\n} from '@tuwaio/orbit-core';\nimport { 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 const wallets = useWallets();\n\n // Get the updateActiveWallet function from the Satellite store\n const updateActiveWallet = useSatelliteConnectStore((state) => state.updateActiveWallet);\n const walletConnectionError = useSatelliteConnectStore((state) => state.walletConnectionError);\n const activeWalletFromStore = useSatelliteConnectStore((state) => state.activeWallet);\n const disconnect = useSatelliteConnectStore((state) => state.disconnect);\n\n // Watch for changes in connected wallets\n useEffect(() => {\n if (activeWalletFromStore && getAdapterFromWalletType(activeWalletFromStore.walletType) === OrbitAdapter.SOLANA) {\n const activeWallet = wallets.filter(\n (w) =>\n getWalletTypeFromConnectorName(OrbitAdapter.SOLANA, formatWalletName(w.name)) ===\n activeWalletFromStore.walletType,\n )[0];\n\n if (!walletConnectionError) {\n // Update the Satellite store with the active wallet information\n updateActiveWallet({\n // Use the first account's address\n address: activeWallet?.accounts[0]?.address,\n // Set connection status\n isConnected: activeWallet?.accounts.length > 0,\n // Store Wallet Standard specific information\n connectedAccount: activeWallet?.accounts[0],\n connectedWallet: activeWallet,\n });\n }\n if (activeWallet?.accounts.length === 0) {\n // If the wallet is disconnected from the wallet provider, disconnect from Satellite store as well\n disconnect();\n }\n }\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [activeWalletFromStore?.walletType, wallets, walletConnectionError, updateActiveWallet, disconnect]); // 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 { useEffect, useMemo } from 'react';\n\nimport { SatelliteStoreContext } from '../hooks/satteliteHook';\nimport { useInitializeAutoConnect } from '../hooks/useInitializeAutoConnect';\nimport { Connector, Wallet } from '../types';\n\n/**\n * Props for SatelliteConnectProvider component\n */\ninterface SatelliteConnectProviderProps extends SatelliteConnectStoreInitialParameters<Connector, Wallet> {\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<Connector, Wallet>({\n ...parameters,\n });\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, []); // Empty dependency array as store should be created only once\n\n // Disconnect from any existing wallets on mount\n useEffect(() => {\n store.getState().disconnectAll();\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, []);\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.46.00f5d3d",
|
|
4
4
|
"private": false,
|
|
5
5
|
"author": "Oleksandr Tkach",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -68,12 +68,12 @@
|
|
|
68
68
|
"tsup": "^8.5.0",
|
|
69
69
|
"typescript": "^5.9.3",
|
|
70
70
|
"zustand": "^5.0.8",
|
|
71
|
-
"@tuwaio/orbit-core": "^1.0.0-fix-test-alpha.
|
|
72
|
-
"@tuwaio/
|
|
73
|
-
"@tuwaio/
|
|
74
|
-
"@tuwaio/
|
|
75
|
-
"@tuwaio/
|
|
76
|
-
"@tuwaio/satellite-solana": "^1.0.0-fix-test-alpha.
|
|
71
|
+
"@tuwaio/orbit-core": "^1.0.0-fix-test-alpha.46.00f5d3d",
|
|
72
|
+
"@tuwaio/satellite-core": "^1.0.0-fix-test-alpha.46.00f5d3d",
|
|
73
|
+
"@tuwaio/orbit-solana": "^1.0.0-fix-test-alpha.46.00f5d3d",
|
|
74
|
+
"@tuwaio/satellite-evm": "^1.0.0-fix-test-alpha.46.00f5d3d",
|
|
75
|
+
"@tuwaio/orbit-evm": "^1.0.0-fix-test-alpha.46.00f5d3d",
|
|
76
|
+
"@tuwaio/satellite-solana": "^1.0.0-fix-test-alpha.46.00f5d3d"
|
|
77
77
|
},
|
|
78
78
|
"scripts": {
|
|
79
79
|
"start": "tsup src/index.ts --watch",
|