@tuwaio/satellite-react 1.0.0-fix-packages-alpha.3.bf8071b → 1.0.0-fix-packages-alpha.5.08c9f96
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -3
- package/dist/chunk-4MZHI7NY.cjs +2 -0
- package/dist/chunk-4MZHI7NY.cjs.map +1 -0
- package/dist/{chunk-VXHPTE35.js → chunk-KZKVF5GG.js} +2 -2
- package/dist/chunk-KZKVF5GG.js.map +1 -0
- package/dist/evm/index.cjs +1 -1
- package/dist/evm/index.cjs.map +1 -1
- package/dist/evm/index.d.cts +9 -9
- package/dist/evm/index.d.ts +9 -9
- package/dist/evm/index.js +1 -1
- package/dist/evm/index.js.map +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +16 -16
- package/dist/index.d.ts +16 -16
- package/dist/index.js +1 -1
- package/dist/solana/index.cjs +1 -1
- package/dist/solana/index.cjs.map +1 -1
- package/dist/solana/index.d.cts +8 -8
- package/dist/solana/index.d.ts +8 -8
- package/dist/solana/index.js +1 -1
- package/dist/solana/index.js.map +1 -1
- package/package.json +14 -14
- package/dist/chunk-BKNDP4VE.cjs +0 -2
- package/dist/chunk-BKNDP4VE.cjs.map +0 -1
- package/dist/chunk-VXHPTE35.js.map +0 -1
package/README.md
CHANGED
|
@@ -55,7 +55,7 @@ yarn add @tuwaio/satellite-react @tuwaio/satellite-core @tuwaio/orbit-core @wagm
|
|
|
55
55
|
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
|
|
56
56
|
import { satelliteEVMAdapter, createDefaultTransports } from '@tuwaio/satellite-evm';
|
|
57
57
|
import { SatelliteConnectProvider } from '@tuwaio/satellite-react';
|
|
58
|
-
import {
|
|
58
|
+
import { EVMConnectorsWatcher } from '@tuwaio/satellite-react/evm';
|
|
59
59
|
import { SolanaWalletsWatcher } from '@tuwaio/satellite-react/solana';
|
|
60
60
|
import { satelliteSolanaAdapter } from '@tuwaio/satellite-solana';
|
|
61
61
|
import { WagmiProvider } from 'wagmi';
|
|
@@ -92,7 +92,7 @@ export function Providers({ children }: { children: ReactNode }) {
|
|
|
92
92
|
adapter={[satelliteEVMAdapter(wagmiConfig), satelliteSolanaAdapter({ rpcUrls: solanaRPCUrls })]}
|
|
93
93
|
autoConnect={true}
|
|
94
94
|
>
|
|
95
|
-
<
|
|
95
|
+
<EVMConnectorsWatcher wagmiConfig={wagmiConfig} />
|
|
96
96
|
<SolanaWalletsWatcher />
|
|
97
97
|
{children}
|
|
98
98
|
</SatelliteConnectProvider>
|
|
@@ -123,7 +123,7 @@ function ExampleGettingActiveWalletFromStore() {
|
|
|
123
123
|
|
|
124
124
|
2. **Provider Components**
|
|
125
125
|
- `SatelliteConnectProvider`: Global context provider with all necessary configurations
|
|
126
|
-
- `
|
|
126
|
+
- `EVMConnectorsWatcher`: EVM wallet connection state management
|
|
127
127
|
- `SolanaWalletsWatcher`: Solana wallet connection state management
|
|
128
128
|
|
|
129
129
|
---
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
'use strict';var react=require('react'),zustand=require('zustand'),satelliteCore=require('@tuwaio/satellite-core'),jsxRuntime=require('react/jsx-runtime');var n=react.createContext(null),A=e=>{let t=react.useContext(n);if(!t)throw new Error("useSatelliteConnectStore must be used within a SatelliteConnectProvider");return zustand.useStore(t,e)};var i=({initializeAutoConnect:e,onError:t})=>{react.useEffect(()=>{(async()=>{try{await e();}catch(o){(t??(c=>console.error("Failed to initialize auto connect:",c)))(o);}})();},[]);};function g({children:e,autoConnect:t,...r}){let o=react.useMemo(()=>satelliteCore.createSatelliteConnectStore({...r}),[]);return react.useEffect(()=>{o.getState().disconnectAll();},[]),i({initializeAutoConnect:()=>o.getState().initializeAutoConnect(t??!1)}),jsxRuntime.jsx(n.Provider,{value:o,children:e})}exports.a=n;exports.b=A;exports.c=i;exports.d=g;//# sourceMappingURL=chunk-4MZHI7NY.cjs.map
|
|
2
|
+
//# sourceMappingURL=chunk-4MZHI7NY.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/hooks/satelliteHook.ts","../src/hooks/useInitializeAutoConnect.tsx","../src/providers/SatelliteConnectProvider.tsx"],"names":["SatelliteStoreContext","createContext","useSatelliteConnectStore","selector","store","useContext","useStore","useInitializeAutoConnect","initializeAutoConnect","onError","useEffect","error","e","SatelliteConnectProvider","children","autoConnect","parameters","useMemo","createSatelliteConnectStore","jsx"],"mappings":"+JAUaA,CAAAA,CAAwBC,mBAAAA,CACnC,IACF,CAAA,CAqBaC,EACXC,CAAAA,EACM,CAEN,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,ECLO,IAAMI,CAAAA,CAA2B,CAAC,CAAE,qBAAA,CAAAC,CAAAA,CAAuB,OAAA,CAAAC,CAAQ,CAAA,GAAwC,CAChHC,eAAAA,CAAU,IAAM,EACqB,SAAY,CAC7C,GAAI,CACF,MAAMF,CAAAA,GACR,CAAA,MAASG,CAAAA,CAAO,EAEOF,CAAAA,GAAaG,CAAAA,EAAa,OAAA,CAAQ,KAAA,CAAM,qCAAsCA,CAAC,CAAA,CAAA,EACvFD,CAAc,EAC7B,CACF,CAAA,IAGF,CAAA,CAAG,EAAE,EACP,ECLO,SAASE,CAAAA,CAAyB,CAAE,SAAAC,CAAAA,CAAU,WAAA,CAAAC,CAAAA,CAAa,GAAGC,CAAW,CAAA,CAAkC,CAEhH,IAAMZ,CAAAA,CAAQa,cAAQ,IACbC,yCAAAA,CAAmD,CACxD,GAAGF,CACL,CAAC,CAAA,CAEA,EAAE,CAAA,CAGL,OAAAN,eAAAA,CAAU,IAAM,CACdN,CAAAA,CAAM,QAAA,EAAS,CAAE,aAAA,GAEnB,CAAA,CAAG,EAAE,CAAA,CAELG,EAAyB,CACvB,qBAAA,CAAuB,IAAMH,CAAAA,CAAM,UAAS,CAAE,qBAAA,CAAsBW,CAAAA,EAAe,CAAA,CAAK,CAC1F,CAAC,CAAA,CAEMI,cAAAA,CAACnB,CAAAA,CAAsB,SAAtB,CAA+B,KAAA,CAAOI,CAAAA,CAAQ,QAAA,CAAAU,EAAS,CACjE","file":"chunk-4MZHI7NY.cjs","sourcesContent":["import { ISatelliteConnectStore } from '@tuwaio/satellite-core';\nimport { createContext, useContext } from 'react';\nimport { StoreApi, useStore } from 'zustand';\n\nimport { Connection, Connector } 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, Connection>> | null>(\n null,\n);\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 connection\n * const activeConnection = useSatelliteConnectStore((state) => state.activeConnection);\n * ```\n */\nexport const useSatelliteConnectStore = <T>(\n selector: (state: ISatelliteConnectStore<Connector, Connection>) => T,\n): 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 { 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 connector auto-connection with error handling.\n *\n * @remarks\n * This hook handles the initial connection logic (e.g., checking for a previously\n * connected connector) 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/satelliteHook';\nimport { useInitializeAutoConnect } from '../hooks/useInitializeAutoConnect';\nimport { Connection, Connector } from '../types';\n\n/**\n * Props for SatelliteConnectProvider component\n */\nexport interface SatelliteConnectProviderProps extends SatelliteConnectStoreInitialParameters<Connector, Connection> {\n /** React child components */\n children: React.ReactNode;\n /** Whether to automatically connect to last used connector */\n autoConnect?: boolean;\n}\n\n/**\n * Provider component that manages connector connections and state\n *\n * @remarks\n * This component creates and provides the Satellite Connect store context to its children.\n * It handles connector 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 connector reconnection\n * @param props.adapter - Blockchain adapter(s) for connector 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, Connection>({\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 connectors 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,2 +1,2 @@
|
|
|
1
|
-
import {createContext,useContext,useEffect,useMemo}from'react';import {useStore}from'zustand';import {createSatelliteConnectStore}from'@tuwaio/satellite-core';import {jsx}from'react/jsx-runtime';var
|
|
2
|
-
//# sourceMappingURL=chunk-
|
|
1
|
+
import {createContext,useContext,useEffect,useMemo}from'react';import {useStore}from'zustand';import {createSatelliteConnectStore}from'@tuwaio/satellite-core';import {jsx}from'react/jsx-runtime';var n=createContext(null),A=e=>{let t=useContext(n);if(!t)throw new Error("useSatelliteConnectStore must be used within a SatelliteConnectProvider");return useStore(t,e)};var i=({initializeAutoConnect:e,onError:t})=>{useEffect(()=>{(async()=>{try{await e();}catch(o){(t??(c=>console.error("Failed to initialize auto connect:",c)))(o);}})();},[]);};function g({children:e,autoConnect:t,...r}){let o=useMemo(()=>createSatelliteConnectStore({...r}),[]);return useEffect(()=>{o.getState().disconnectAll();},[]),i({initializeAutoConnect:()=>o.getState().initializeAutoConnect(t??!1)}),jsx(n.Provider,{value:o,children:e})}export{n as a,A as b,i as c,g as d};//# sourceMappingURL=chunk-KZKVF5GG.js.map
|
|
2
|
+
//# sourceMappingURL=chunk-KZKVF5GG.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/hooks/satelliteHook.ts","../src/hooks/useInitializeAutoConnect.tsx","../src/providers/SatelliteConnectProvider.tsx"],"names":["SatelliteStoreContext","createContext","useSatelliteConnectStore","selector","store","useContext","useStore","useInitializeAutoConnect","initializeAutoConnect","onError","useEffect","error","e","SatelliteConnectProvider","children","autoConnect","parameters","useMemo","createSatelliteConnectStore","jsx"],"mappings":"uMAUaA,CAAAA,CAAwBC,aAAAA,CACnC,IACF,CAAA,CAqBaC,EACXC,CAAAA,EACM,CAEN,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,ECLO,IAAMI,CAAAA,CAA2B,CAAC,CAAE,qBAAA,CAAAC,CAAAA,CAAuB,OAAA,CAAAC,CAAQ,CAAA,GAAwC,CAChHC,SAAAA,CAAU,IAAM,EACqB,SAAY,CAC7C,GAAI,CACF,MAAMF,CAAAA,GACR,CAAA,MAASG,CAAAA,CAAO,EAEOF,CAAAA,GAAaG,CAAAA,EAAa,OAAA,CAAQ,KAAA,CAAM,qCAAsCA,CAAC,CAAA,CAAA,EACvFD,CAAc,EAC7B,CACF,CAAA,IAGF,CAAA,CAAG,EAAE,EACP,ECLO,SAASE,CAAAA,CAAyB,CAAE,SAAAC,CAAAA,CAAU,WAAA,CAAAC,CAAAA,CAAa,GAAGC,CAAW,CAAA,CAAkC,CAEhH,IAAMZ,CAAAA,CAAQa,QAAQ,IACbC,2BAAAA,CAAmD,CACxD,GAAGF,CACL,CAAC,CAAA,CAEA,EAAE,CAAA,CAGL,OAAAN,SAAAA,CAAU,IAAM,CACdN,CAAAA,CAAM,QAAA,EAAS,CAAE,aAAA,GAEnB,CAAA,CAAG,EAAE,CAAA,CAELG,EAAyB,CACvB,qBAAA,CAAuB,IAAMH,CAAAA,CAAM,UAAS,CAAE,qBAAA,CAAsBW,CAAAA,EAAe,CAAA,CAAK,CAC1F,CAAC,CAAA,CAEMI,GAAAA,CAACnB,CAAAA,CAAsB,SAAtB,CAA+B,KAAA,CAAOI,CAAAA,CAAQ,QAAA,CAAAU,EAAS,CACjE","file":"chunk-KZKVF5GG.js","sourcesContent":["import { ISatelliteConnectStore } from '@tuwaio/satellite-core';\nimport { createContext, useContext } from 'react';\nimport { StoreApi, useStore } from 'zustand';\n\nimport { Connection, Connector } 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, Connection>> | null>(\n null,\n);\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 connection\n * const activeConnection = useSatelliteConnectStore((state) => state.activeConnection);\n * ```\n */\nexport const useSatelliteConnectStore = <T>(\n selector: (state: ISatelliteConnectStore<Connector, Connection>) => T,\n): 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 { 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 connector auto-connection with error handling.\n *\n * @remarks\n * This hook handles the initial connection logic (e.g., checking for a previously\n * connected connector) 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/satelliteHook';\nimport { useInitializeAutoConnect } from '../hooks/useInitializeAutoConnect';\nimport { Connection, Connector } from '../types';\n\n/**\n * Props for SatelliteConnectProvider component\n */\nexport interface SatelliteConnectProviderProps extends SatelliteConnectStoreInitialParameters<Connector, Connection> {\n /** React child components */\n children: React.ReactNode;\n /** Whether to automatically connect to last used connector */\n autoConnect?: boolean;\n}\n\n/**\n * Provider component that manages connector connections and state\n *\n * @remarks\n * This component creates and provides the Satellite Connect store context to its children.\n * It handles connector 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 connector reconnection\n * @param props.adapter - Blockchain adapter(s) for connector 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, Connection>({\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 connectors 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/evm/index.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
'use strict';var
|
|
1
|
+
'use strict';var chunk4MZHI7NY_cjs=require('../chunk-4MZHI7NY.cjs'),orbitCore=require('@tuwaio/orbit-core'),core=require('@wagmi/core'),react=require('react');function x({wagmiConfig:c,siwe:t}){let n=chunk4MZHI7NY_cjs.b(e=>e.activeConnection),r=chunk4MZHI7NY_cjs.b(e=>e.disconnect),u=chunk4MZHI7NY_cjs.b(e=>e.connectionError),m=chunk4MZHI7NY_cjs.b(e=>e.updateActiveConnection);return react.useEffect(()=>{t?.enabled&&!t?.isSignedIn&&t?.isRejected&&n&&r(n.connectorType);},[t,r,n]),react.useEffect(()=>core.watchConnections(c,{onChange:a=>{if(n&&orbitCore.getAdapterFromConnectorType(n.connectorType)!==orbitCore.OrbitAdapter.EVM)return;if(a.length===0){n&&r(n.connectorType);return}let s=c.state.current?a.find(i=>i.connector.uid===c.state.current):a[0];if(!s){n&&r(n.connectorType);return}let d=s.accounts[0],p=s.chainId;if(n&&orbitCore.getAdapterFromConnectorType(n.connectorType)!==orbitCore.OrbitAdapter.EVM||!d||u)return;if(t?.enabled?t.isSignedIn:true){let i=n?.connectorType,C=c.chains.find(E=>E.id===p)?.rpcUrls.default.http[0];m(i?{connectorType:i,address:d,chainId:p,rpcURL:C,isConnected:true}:{address:d,chainId:p,rpcURL:C,isConnected:true});}}}),[n?.connectorType,t,u]),null}exports.EVMConnectorsWatcher=x;//# sourceMappingURL=index.cjs.map
|
|
2
2
|
//# sourceMappingURL=index.cjs.map
|
package/dist/evm/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/evm/
|
|
1
|
+
{"version":3,"sources":["../../src/evm/EVMConnectorsWatcher.tsx"],"names":["EVMConnectorsWatcher","wagmiConfig","siwe","activeConnection","useSatelliteConnectStore","store","disconnect","connectionError","updateActiveConnection","useEffect","watchConnections","connections","getAdapterFromConnectorType","OrbitAdapter","currentConnection","c","primaryAccount","chainId","connectorType","rpcURL"],"mappings":"+JAiDO,SAASA,EAAqB,CAAE,WAAA,CAAAC,EAAa,IAAA,CAAAC,CAAK,CAAA,CAA8B,CAUrF,IAAMC,CAAAA,CAAmBC,oBAA0BC,CAAAA,EAAUA,CAAAA,CAAM,gBAAgB,CAAA,CAI7EC,CAAAA,CAAaF,oBAA0BC,CAAAA,EAAUA,CAAAA,CAAM,UAAU,CAAA,CAIjEE,CAAAA,CAAkBH,mBAAAA,CAA0BC,GAAUA,CAAAA,CAAM,eAAe,CAAA,CAI3EG,CAAAA,CAAyBJ,mBAAAA,CAA0BC,CAAAA,EAAUA,EAAM,sBAAsB,CAAA,CAY/F,OAAAI,eAAAA,CAAU,IAAM,CACVP,GAAM,OAAA,EAAW,CAACA,GAAM,UAAA,EAAcA,CAAAA,EAAM,YAC1CC,CAAAA,EACFG,CAAAA,CAAWH,CAAAA,CAAiB,aAAa,EAG/C,CAAA,CAAG,CAACD,CAAAA,CAAMI,CAAAA,CAAYH,CAAgB,CAAC,CAAA,CASvCM,eAAAA,CAAU,IA8FQC,qBAAAA,CAAiBT,CAAAA,CAAa,CAAE,QAAA,CAvFyBU,CAAAA,EAAgB,CAEvF,GAAIR,CAAAA,EAAoBS,qCAAAA,CAA4BT,EAAiB,aAAa,CAAA,GAAMU,uBAAa,GAAA,CACnG,OAIF,GAAIF,CAAAA,CAAY,MAAA,GAAW,CAAA,CAAG,CACxBR,CAAAA,EACFG,CAAAA,CAAWH,CAAAA,CAAiB,aAAa,CAAA,CAE3C,MACF,CAIA,IAAMW,CAAAA,CAAoBb,CAAAA,CAAY,KAAA,CAAM,OAAA,CACxCU,CAAAA,CAAY,KAAMI,CAAAA,EAAMA,CAAAA,CAAE,UAAU,GAAA,GAAQd,CAAAA,CAAY,MAAM,OAAO,CAAA,CACrEU,CAAAA,CAAY,CAAC,CAAA,CAGjB,GAAI,CAACG,CAAAA,CAAmB,CAClBX,GACFG,CAAAA,CAAWH,CAAAA,CAAiB,aAAa,CAAA,CAE3C,MACF,CAGA,IAAMa,CAAAA,CAAiBF,CAAAA,CAAkB,SAAS,CAAC,CAAA,CAC7CG,EAAUH,CAAAA,CAAkB,OAAA,CAQlC,GACGX,CAAAA,EAAoBS,qCAAAA,CAA4BT,CAAAA,CAAiB,aAAa,CAAA,GAAMU,sBAAAA,CAAa,KAClG,CAACG,CAAAA,EACDT,CAAAA,CAEA,OAUF,GAFqBL,CAAAA,EAAM,QAAUA,CAAAA,CAAK,UAAA,CAAa,IAAA,CAErC,CAEhB,IAAMgB,CAAAA,CAAgBf,GAAkB,aAAA,CAIlCgB,CAAAA,CADQlB,EAAY,MAAA,CAAO,IAAA,CAAMc,GAAMA,CAAAA,CAAE,EAAA,GAAOE,CAAO,CAAA,EACvC,OAAA,CAAQ,OAAA,CAAQ,KAAK,CAAC,CAAA,CAuB5CT,CAAAA,CAlByBU,CAAAA,CACrB,CAEE,aAAA,CAAAA,EACA,OAAA,CAASF,CAAAA,CACT,OAAA,CAAAC,CAAAA,CACA,MAAA,CAAAE,CAAAA,CACA,YAAa,IACf,CAAA,CACA,CAEE,OAAA,CAASH,CAAAA,CACT,QAAAC,CAAAA,CACA,MAAA,CAAAE,CAAAA,CACA,WAAA,CAAa,IACf,CAGmC,EACzC,CACF,CAGkF,CAAC,CAAA,CAOlF,CAAChB,CAAAA,EAAkB,cAAeD,CAAAA,CAAMK,CAAe,CAAC,CAAA,CAGpD,IACT","file":"index.cjs","sourcesContent":["import { getAdapterFromConnectorType, OrbitAdapter } from '@tuwaio/orbit-core';\nimport { Config, watchConnections, WatchConnectionsParameters } from '@wagmi/core';\nimport { useEffect } from 'react';\n\nimport { useSatelliteConnectStore } from '../index';\n\n/**\n * Props for the {@link EVMConnectorsWatcher} component.\n */\ninterface EVMConnectorsWatcherProps {\n /**\n * The configuration object from `@wagmi/core`.\n * This is required to initialize the account watcher.\n */\n wagmiConfig: Config;\n\n /**\n * Optional object representing the Sign-In With Ethereum (SIWE) state.\n * If provided, the watcher will use this state to manage updates\n * and disconnections based on SIWE status.\n */\n siwe?: {\n /**\n * Flag indicating if the SIWE authentication request was rejected by the user.\n */\n isRejected: boolean;\n /**\n * Flag indicating if the user is successfully signed in via SIWE.\n */\n isSignedIn: boolean;\n /**\n * Flag indicating if the SIWE flow is enabled.\n */\n enabled?: boolean;\n };\n}\n\n/**\n * A headless React component (renders `null`) that synchronizes the EVM connector\n * state from `@wagmi/core` with the global `useSatelliteConnectStore`.\n *\n * It is responsible for:\n * 1. Automatically disconnecting if a SIWE (Sign-In With Ethereum) request is rejected.\n * 2. Listening for account changes (e.g., account switch, chain switch, disconnect)\n * from `wagmi` and updating the global store accordingly.\n *\n * @param props - The component's props. See {@link EVMConnectorsWatcherProps} for details.\n * @returns {null} This component does not render any UI.\n */\nexport function EVMConnectorsWatcher({ wagmiConfig, siwe }: EVMConnectorsWatcherProps) {\n // --- Global Store State ---\n // Subscribes to parts of the global Zustand store.\n\n /**\n * The currently active wallet object from the global store.\n */\n /**\n * The currently active wallet object from the global store.\n */\n const activeConnection = useSatelliteConnectStore((store) => store.activeConnection);\n /**\n * The global function to trigger a connector disconnection.\n */\n const disconnect = useSatelliteConnectStore((store) => store.disconnect);\n /**\n * The current connection error state, if any.\n */\n const connectionError = useSatelliteConnectStore((store) => store.connectionError);\n /**\n * The global function to update the active connector's details.\n */\n const updateActiveConnection = useSatelliteConnectStore((store) => store.updateActiveConnection);\n\n // --- Effects ---\n\n /**\n * Effect: Handles SIWE rejection.\n *\n * If the SIWE flow is enabled (`siwe.enabled`), the user is not yet\n * signed in (`!siwe.isSignedIn`), and they have explicitly rejected\n * the SIWE signature request (`siwe.isRejected`), this effect\n * will call the global `disconnect` function.\n */\n useEffect(() => {\n if (siwe?.enabled && !siwe?.isSignedIn && siwe?.isRejected) {\n if (activeConnection) {\n disconnect(activeConnection.connectorType);\n }\n }\n }, [siwe, disconnect, activeConnection]);\n\n /**\n * Effect: Subscribes to wagmi connection changes.\n *\n * This effect initializes `watchConnections` from `@wagmi/core` to listen for\n * any changes in the connected connectors' state (like switching accounts,\n * changing networks, or disconnecting). Supports multiple simultaneous connections.\n */\n useEffect(() => {\n /**\n * Callback function triggered by `watchConnections` whenever the\n * wagmi connections state changes.\n *\n * @param connections - Array of all active connections from wagmi.\n */\n const handleConnectionsChange: WatchConnectionsParameters['onChange'] = (connections) => {\n // Guard: If active connection is not EVM, ignore changes\n if (activeConnection && getAdapterFromConnectorType(activeConnection.connectorType) !== OrbitAdapter.EVM) {\n return;\n }\n\n // Case 1: No connections means all connectors were disconnected\n if (connections.length === 0) {\n if (activeConnection) {\n disconnect(activeConnection.connectorType);\n }\n return;\n }\n\n // Get the current connection from wagmi config state\n // The \"current\" connection is typically the most recently used/active one\n const currentConnection = wagmiConfig.state.current\n ? connections.find((c) => c.connector.uid === wagmiConfig.state.current)\n : connections[0]; // Fallback to first connection if no current is set\n\n // If no valid connection is found, disconnect\n if (!currentConnection) {\n if (activeConnection) {\n disconnect(activeConnection.connectorType);\n }\n return;\n }\n\n // Extract the primary account from the current connection\n const primaryAccount = currentConnection.accounts[0];\n const chainId = currentConnection.chainId;\n\n // --- Guard Clauses ---\n // Stop processing if any of these conditions are true:\n // 1. The currently active connector in our store is NOT an EVM connector\n // (we don't want this watcher to override a non-EVM connector).\n // 2. The current connection has no accounts.\n // 3. There is already a connection error in our global store.\n if (\n (activeConnection && getAdapterFromConnectorType(activeConnection.connectorType) !== OrbitAdapter.EVM) ||\n !primaryAccount ||\n connectionError\n ) {\n return;\n }\n\n /**\n * Determines if the global store *should* be updated.\n * - If SIWE is enabled, we only update the store if the user is signed in.\n * - If SIWE is not enabled, we always update the store.\n */\n const shouldUpdate = siwe?.enabled ? siwe.isSignedIn : true;\n\n if (shouldUpdate) {\n // Preserve the `connectorType` if it already exists in the active wallet.\n const connectorType = activeConnection?.connectorType;\n\n // Get the chain information for RPC URL\n const chain = wagmiConfig.chains.find((c) => c.id === chainId);\n const rpcURL = chain?.rpcUrls.default.http[0];\n\n /**\n * The payload to send to the global store update function.\n */\n const updatedConnector = connectorType\n ? {\n // Preserve the connectorType (e.g., 'metamask', 'walletconnect')\n connectorType,\n address: primaryAccount,\n chainId,\n rpcURL,\n isConnected: true,\n }\n : {\n // Fallback if activeConnection was null or had no type\n address: primaryAccount,\n chainId,\n rpcURL,\n isConnected: true,\n };\n\n // Update the global store with the new connector state.\n updateActiveConnection(updatedConnector);\n }\n };\n\n // Activate the watcher\n const unwatch = watchConnections(wagmiConfig, { onChange: handleConnectionsChange });\n\n // Return the cleanup function.\n // This `unwatch` function will be called when the component unmounts\n // or when the dependencies in the array change, preventing memory leaks.\n return unwatch;\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [activeConnection?.connectorType, siwe, connectionError]);\n\n // This component is \"headless\" - it performs logic but renders nothing.\n return null;\n}\n"]}
|
package/dist/evm/index.d.cts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { OrbitAdapter } from '@tuwaio/orbit-core';
|
|
2
|
-
import {
|
|
2
|
+
import { EVMConnection, ConnectorEVM } from '@tuwaio/satellite-evm';
|
|
3
3
|
import { Config } from '@wagmi/core';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
|
-
* Props for the {@link
|
|
6
|
+
* Props for the {@link EVMConnectorsWatcher} component.
|
|
7
7
|
*/
|
|
8
|
-
interface
|
|
8
|
+
interface EVMConnectorsWatcherProps {
|
|
9
9
|
/**
|
|
10
10
|
* The configuration object from `@wagmi/core`.
|
|
11
11
|
* This is required to initialize the account watcher.
|
|
@@ -32,7 +32,7 @@ interface EVMWalletsWatcherProps {
|
|
|
32
32
|
};
|
|
33
33
|
}
|
|
34
34
|
/**
|
|
35
|
-
* A headless React component (renders `null`) that synchronizes the EVM
|
|
35
|
+
* A headless React component (renders `null`) that synchronizes the EVM connector
|
|
36
36
|
* state from `@wagmi/core` with the global `useSatelliteConnectStore`.
|
|
37
37
|
*
|
|
38
38
|
* It is responsible for:
|
|
@@ -40,18 +40,18 @@ interface EVMWalletsWatcherProps {
|
|
|
40
40
|
* 2. Listening for account changes (e.g., account switch, chain switch, disconnect)
|
|
41
41
|
* from `wagmi` and updating the global store accordingly.
|
|
42
42
|
*
|
|
43
|
-
* @param props - The component's props. See {@link
|
|
43
|
+
* @param props - The component's props. See {@link EVMConnectorsWatcherProps} for details.
|
|
44
44
|
* @returns {null} This component does not render any UI.
|
|
45
45
|
*/
|
|
46
|
-
declare function
|
|
46
|
+
declare function EVMConnectorsWatcher({ wagmiConfig, siwe }: EVMConnectorsWatcherProps): null;
|
|
47
47
|
|
|
48
48
|
declare module '@tuwaio/satellite-react' {
|
|
49
|
-
interface
|
|
50
|
-
[OrbitAdapter.EVM]:
|
|
49
|
+
interface AllConnections {
|
|
50
|
+
[OrbitAdapter.EVM]: EVMConnection;
|
|
51
51
|
}
|
|
52
52
|
interface AllConnectors {
|
|
53
53
|
[OrbitAdapter.EVM]: ConnectorEVM;
|
|
54
54
|
}
|
|
55
55
|
}
|
|
56
56
|
|
|
57
|
-
export {
|
|
57
|
+
export { EVMConnectorsWatcher };
|
package/dist/evm/index.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { OrbitAdapter } from '@tuwaio/orbit-core';
|
|
2
|
-
import {
|
|
2
|
+
import { EVMConnection, ConnectorEVM } from '@tuwaio/satellite-evm';
|
|
3
3
|
import { Config } from '@wagmi/core';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
|
-
* Props for the {@link
|
|
6
|
+
* Props for the {@link EVMConnectorsWatcher} component.
|
|
7
7
|
*/
|
|
8
|
-
interface
|
|
8
|
+
interface EVMConnectorsWatcherProps {
|
|
9
9
|
/**
|
|
10
10
|
* The configuration object from `@wagmi/core`.
|
|
11
11
|
* This is required to initialize the account watcher.
|
|
@@ -32,7 +32,7 @@ interface EVMWalletsWatcherProps {
|
|
|
32
32
|
};
|
|
33
33
|
}
|
|
34
34
|
/**
|
|
35
|
-
* A headless React component (renders `null`) that synchronizes the EVM
|
|
35
|
+
* A headless React component (renders `null`) that synchronizes the EVM connector
|
|
36
36
|
* state from `@wagmi/core` with the global `useSatelliteConnectStore`.
|
|
37
37
|
*
|
|
38
38
|
* It is responsible for:
|
|
@@ -40,18 +40,18 @@ interface EVMWalletsWatcherProps {
|
|
|
40
40
|
* 2. Listening for account changes (e.g., account switch, chain switch, disconnect)
|
|
41
41
|
* from `wagmi` and updating the global store accordingly.
|
|
42
42
|
*
|
|
43
|
-
* @param props - The component's props. See {@link
|
|
43
|
+
* @param props - The component's props. See {@link EVMConnectorsWatcherProps} for details.
|
|
44
44
|
* @returns {null} This component does not render any UI.
|
|
45
45
|
*/
|
|
46
|
-
declare function
|
|
46
|
+
declare function EVMConnectorsWatcher({ wagmiConfig, siwe }: EVMConnectorsWatcherProps): null;
|
|
47
47
|
|
|
48
48
|
declare module '@tuwaio/satellite-react' {
|
|
49
|
-
interface
|
|
50
|
-
[OrbitAdapter.EVM]:
|
|
49
|
+
interface AllConnections {
|
|
50
|
+
[OrbitAdapter.EVM]: EVMConnection;
|
|
51
51
|
}
|
|
52
52
|
interface AllConnectors {
|
|
53
53
|
[OrbitAdapter.EVM]: ConnectorEVM;
|
|
54
54
|
}
|
|
55
55
|
}
|
|
56
56
|
|
|
57
|
-
export {
|
|
57
|
+
export { EVMConnectorsWatcher };
|
package/dist/evm/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {b}from'../chunk-
|
|
1
|
+
import {b}from'../chunk-KZKVF5GG.js';import {getAdapterFromConnectorType,OrbitAdapter}from'@tuwaio/orbit-core';import {watchConnections}from'@wagmi/core';import {useEffect}from'react';function x({wagmiConfig:c,siwe:t}){let n=b(e=>e.activeConnection),r=b(e=>e.disconnect),u=b(e=>e.connectionError),m=b(e=>e.updateActiveConnection);return useEffect(()=>{t?.enabled&&!t?.isSignedIn&&t?.isRejected&&n&&r(n.connectorType);},[t,r,n]),useEffect(()=>watchConnections(c,{onChange:a=>{if(n&&getAdapterFromConnectorType(n.connectorType)!==OrbitAdapter.EVM)return;if(a.length===0){n&&r(n.connectorType);return}let s=c.state.current?a.find(i=>i.connector.uid===c.state.current):a[0];if(!s){n&&r(n.connectorType);return}let d=s.accounts[0],p=s.chainId;if(n&&getAdapterFromConnectorType(n.connectorType)!==OrbitAdapter.EVM||!d||u)return;if(t?.enabled?t.isSignedIn:true){let i=n?.connectorType,C=c.chains.find(E=>E.id===p)?.rpcUrls.default.http[0];m(i?{connectorType:i,address:d,chainId:p,rpcURL:C,isConnected:true}:{address:d,chainId:p,rpcURL:C,isConnected:true});}}}),[n?.connectorType,t,u]),null}export{x as EVMConnectorsWatcher};//# sourceMappingURL=index.js.map
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
package/dist/evm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/evm/
|
|
1
|
+
{"version":3,"sources":["../../src/evm/EVMConnectorsWatcher.tsx"],"names":["EVMConnectorsWatcher","wagmiConfig","siwe","activeConnection","useSatelliteConnectStore","store","disconnect","connectionError","updateActiveConnection","useEffect","watchConnections","connections","getAdapterFromConnectorType","OrbitAdapter","currentConnection","c","primaryAccount","chainId","connectorType","rpcURL"],"mappings":"wLAiDO,SAASA,EAAqB,CAAE,WAAA,CAAAC,EAAa,IAAA,CAAAC,CAAK,CAAA,CAA8B,CAUrF,IAAMC,CAAAA,CAAmBC,EAA0BC,CAAAA,EAAUA,CAAAA,CAAM,gBAAgB,CAAA,CAI7EC,CAAAA,CAAaF,EAA0BC,CAAAA,EAAUA,CAAAA,CAAM,UAAU,CAAA,CAIjEE,CAAAA,CAAkBH,CAAAA,CAA0BC,GAAUA,CAAAA,CAAM,eAAe,CAAA,CAI3EG,CAAAA,CAAyBJ,CAAAA,CAA0BC,CAAAA,EAAUA,EAAM,sBAAsB,CAAA,CAY/F,OAAAI,SAAAA,CAAU,IAAM,CACVP,GAAM,OAAA,EAAW,CAACA,GAAM,UAAA,EAAcA,CAAAA,EAAM,YAC1CC,CAAAA,EACFG,CAAAA,CAAWH,CAAAA,CAAiB,aAAa,EAG/C,CAAA,CAAG,CAACD,CAAAA,CAAMI,CAAAA,CAAYH,CAAgB,CAAC,CAAA,CASvCM,SAAAA,CAAU,IA8FQC,gBAAAA,CAAiBT,CAAAA,CAAa,CAAE,QAAA,CAvFyBU,CAAAA,EAAgB,CAEvF,GAAIR,CAAAA,EAAoBS,2BAAAA,CAA4BT,EAAiB,aAAa,CAAA,GAAMU,aAAa,GAAA,CACnG,OAIF,GAAIF,CAAAA,CAAY,MAAA,GAAW,CAAA,CAAG,CACxBR,CAAAA,EACFG,CAAAA,CAAWH,CAAAA,CAAiB,aAAa,CAAA,CAE3C,MACF,CAIA,IAAMW,CAAAA,CAAoBb,CAAAA,CAAY,KAAA,CAAM,OAAA,CACxCU,CAAAA,CAAY,KAAMI,CAAAA,EAAMA,CAAAA,CAAE,UAAU,GAAA,GAAQd,CAAAA,CAAY,MAAM,OAAO,CAAA,CACrEU,CAAAA,CAAY,CAAC,CAAA,CAGjB,GAAI,CAACG,CAAAA,CAAmB,CAClBX,GACFG,CAAAA,CAAWH,CAAAA,CAAiB,aAAa,CAAA,CAE3C,MACF,CAGA,IAAMa,CAAAA,CAAiBF,CAAAA,CAAkB,SAAS,CAAC,CAAA,CAC7CG,EAAUH,CAAAA,CAAkB,OAAA,CAQlC,GACGX,CAAAA,EAAoBS,2BAAAA,CAA4BT,CAAAA,CAAiB,aAAa,CAAA,GAAMU,YAAAA,CAAa,KAClG,CAACG,CAAAA,EACDT,CAAAA,CAEA,OAUF,GAFqBL,CAAAA,EAAM,QAAUA,CAAAA,CAAK,UAAA,CAAa,IAAA,CAErC,CAEhB,IAAMgB,CAAAA,CAAgBf,GAAkB,aAAA,CAIlCgB,CAAAA,CADQlB,EAAY,MAAA,CAAO,IAAA,CAAMc,GAAMA,CAAAA,CAAE,EAAA,GAAOE,CAAO,CAAA,EACvC,OAAA,CAAQ,OAAA,CAAQ,KAAK,CAAC,CAAA,CAuB5CT,CAAAA,CAlByBU,CAAAA,CACrB,CAEE,aAAA,CAAAA,EACA,OAAA,CAASF,CAAAA,CACT,OAAA,CAAAC,CAAAA,CACA,MAAA,CAAAE,CAAAA,CACA,YAAa,IACf,CAAA,CACA,CAEE,OAAA,CAASH,CAAAA,CACT,QAAAC,CAAAA,CACA,MAAA,CAAAE,CAAAA,CACA,WAAA,CAAa,IACf,CAGmC,EACzC,CACF,CAGkF,CAAC,CAAA,CAOlF,CAAChB,CAAAA,EAAkB,cAAeD,CAAAA,CAAMK,CAAe,CAAC,CAAA,CAGpD,IACT","file":"index.js","sourcesContent":["import { getAdapterFromConnectorType, OrbitAdapter } from '@tuwaio/orbit-core';\nimport { Config, watchConnections, WatchConnectionsParameters } from '@wagmi/core';\nimport { useEffect } from 'react';\n\nimport { useSatelliteConnectStore } from '../index';\n\n/**\n * Props for the {@link EVMConnectorsWatcher} component.\n */\ninterface EVMConnectorsWatcherProps {\n /**\n * The configuration object from `@wagmi/core`.\n * This is required to initialize the account watcher.\n */\n wagmiConfig: Config;\n\n /**\n * Optional object representing the Sign-In With Ethereum (SIWE) state.\n * If provided, the watcher will use this state to manage updates\n * and disconnections based on SIWE status.\n */\n siwe?: {\n /**\n * Flag indicating if the SIWE authentication request was rejected by the user.\n */\n isRejected: boolean;\n /**\n * Flag indicating if the user is successfully signed in via SIWE.\n */\n isSignedIn: boolean;\n /**\n * Flag indicating if the SIWE flow is enabled.\n */\n enabled?: boolean;\n };\n}\n\n/**\n * A headless React component (renders `null`) that synchronizes the EVM connector\n * state from `@wagmi/core` with the global `useSatelliteConnectStore`.\n *\n * It is responsible for:\n * 1. Automatically disconnecting if a SIWE (Sign-In With Ethereum) request is rejected.\n * 2. Listening for account changes (e.g., account switch, chain switch, disconnect)\n * from `wagmi` and updating the global store accordingly.\n *\n * @param props - The component's props. See {@link EVMConnectorsWatcherProps} for details.\n * @returns {null} This component does not render any UI.\n */\nexport function EVMConnectorsWatcher({ wagmiConfig, siwe }: EVMConnectorsWatcherProps) {\n // --- Global Store State ---\n // Subscribes to parts of the global Zustand store.\n\n /**\n * The currently active wallet object from the global store.\n */\n /**\n * The currently active wallet object from the global store.\n */\n const activeConnection = useSatelliteConnectStore((store) => store.activeConnection);\n /**\n * The global function to trigger a connector disconnection.\n */\n const disconnect = useSatelliteConnectStore((store) => store.disconnect);\n /**\n * The current connection error state, if any.\n */\n const connectionError = useSatelliteConnectStore((store) => store.connectionError);\n /**\n * The global function to update the active connector's details.\n */\n const updateActiveConnection = useSatelliteConnectStore((store) => store.updateActiveConnection);\n\n // --- Effects ---\n\n /**\n * Effect: Handles SIWE rejection.\n *\n * If the SIWE flow is enabled (`siwe.enabled`), the user is not yet\n * signed in (`!siwe.isSignedIn`), and they have explicitly rejected\n * the SIWE signature request (`siwe.isRejected`), this effect\n * will call the global `disconnect` function.\n */\n useEffect(() => {\n if (siwe?.enabled && !siwe?.isSignedIn && siwe?.isRejected) {\n if (activeConnection) {\n disconnect(activeConnection.connectorType);\n }\n }\n }, [siwe, disconnect, activeConnection]);\n\n /**\n * Effect: Subscribes to wagmi connection changes.\n *\n * This effect initializes `watchConnections` from `@wagmi/core` to listen for\n * any changes in the connected connectors' state (like switching accounts,\n * changing networks, or disconnecting). Supports multiple simultaneous connections.\n */\n useEffect(() => {\n /**\n * Callback function triggered by `watchConnections` whenever the\n * wagmi connections state changes.\n *\n * @param connections - Array of all active connections from wagmi.\n */\n const handleConnectionsChange: WatchConnectionsParameters['onChange'] = (connections) => {\n // Guard: If active connection is not EVM, ignore changes\n if (activeConnection && getAdapterFromConnectorType(activeConnection.connectorType) !== OrbitAdapter.EVM) {\n return;\n }\n\n // Case 1: No connections means all connectors were disconnected\n if (connections.length === 0) {\n if (activeConnection) {\n disconnect(activeConnection.connectorType);\n }\n return;\n }\n\n // Get the current connection from wagmi config state\n // The \"current\" connection is typically the most recently used/active one\n const currentConnection = wagmiConfig.state.current\n ? connections.find((c) => c.connector.uid === wagmiConfig.state.current)\n : connections[0]; // Fallback to first connection if no current is set\n\n // If no valid connection is found, disconnect\n if (!currentConnection) {\n if (activeConnection) {\n disconnect(activeConnection.connectorType);\n }\n return;\n }\n\n // Extract the primary account from the current connection\n const primaryAccount = currentConnection.accounts[0];\n const chainId = currentConnection.chainId;\n\n // --- Guard Clauses ---\n // Stop processing if any of these conditions are true:\n // 1. The currently active connector in our store is NOT an EVM connector\n // (we don't want this watcher to override a non-EVM connector).\n // 2. The current connection has no accounts.\n // 3. There is already a connection error in our global store.\n if (\n (activeConnection && getAdapterFromConnectorType(activeConnection.connectorType) !== OrbitAdapter.EVM) ||\n !primaryAccount ||\n connectionError\n ) {\n return;\n }\n\n /**\n * Determines if the global store *should* be updated.\n * - If SIWE is enabled, we only update the store if the user is signed in.\n * - If SIWE is not enabled, we always update the store.\n */\n const shouldUpdate = siwe?.enabled ? siwe.isSignedIn : true;\n\n if (shouldUpdate) {\n // Preserve the `connectorType` if it already exists in the active wallet.\n const connectorType = activeConnection?.connectorType;\n\n // Get the chain information for RPC URL\n const chain = wagmiConfig.chains.find((c) => c.id === chainId);\n const rpcURL = chain?.rpcUrls.default.http[0];\n\n /**\n * The payload to send to the global store update function.\n */\n const updatedConnector = connectorType\n ? {\n // Preserve the connectorType (e.g., 'metamask', 'walletconnect')\n connectorType,\n address: primaryAccount,\n chainId,\n rpcURL,\n isConnected: true,\n }\n : {\n // Fallback if activeConnection was null or had no type\n address: primaryAccount,\n chainId,\n rpcURL,\n isConnected: true,\n };\n\n // Update the global store with the new connector state.\n updateActiveConnection(updatedConnector);\n }\n };\n\n // Activate the watcher\n const unwatch = watchConnections(wagmiConfig, { onChange: handleConnectionsChange });\n\n // Return the cleanup function.\n // This `unwatch` function will be called when the component unmounts\n // or when the dependencies in the array change, preventing memory leaks.\n return unwatch;\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [activeConnection?.connectorType, siwe, connectionError]);\n\n // This component is \"headless\" - it performs logic but renders nothing.\n return null;\n}\n"]}
|
package/dist/index.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
'use strict';var
|
|
1
|
+
'use strict';var chunk4MZHI7NY_cjs=require('./chunk-4MZHI7NY.cjs');Object.defineProperty(exports,"SatelliteConnectProvider",{enumerable:true,get:function(){return chunk4MZHI7NY_cjs.d}});Object.defineProperty(exports,"SatelliteStoreContext",{enumerable:true,get:function(){return chunk4MZHI7NY_cjs.a}});Object.defineProperty(exports,"useInitializeAutoConnect",{enumerable:true,get:function(){return chunk4MZHI7NY_cjs.c}});Object.defineProperty(exports,"useSatelliteConnectStore",{enumerable:true,get:function(){return chunk4MZHI7NY_cjs.b}});//# sourceMappingURL=index.cjs.map
|
|
2
2
|
//# sourceMappingURL=index.cjs.map
|
package/dist/index.d.cts
CHANGED
|
@@ -7,9 +7,9 @@ import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
|
7
7
|
* @description
|
|
8
8
|
* This interface is intentionally left empty.
|
|
9
9
|
* Other packages (@tuwaio/satellite-*) will use module
|
|
10
|
-
* augmentation to add their specific
|
|
10
|
+
* augmentation to add their specific connection types here.
|
|
11
11
|
*/
|
|
12
|
-
interface
|
|
12
|
+
interface AllConnections {
|
|
13
13
|
}
|
|
14
14
|
/**
|
|
15
15
|
* @description
|
|
@@ -19,11 +19,11 @@ interface AllWallets {
|
|
|
19
19
|
interface AllConnectors {
|
|
20
20
|
}
|
|
21
21
|
/**
|
|
22
|
-
* Union type for all supported
|
|
23
|
-
* It's created from the values of the
|
|
24
|
-
* e.g., { evm:
|
|
22
|
+
* Union type for all supported connection types.
|
|
23
|
+
* It's created from the values of the AllConnections interface.
|
|
24
|
+
* e.g., { evm: EVMConnection, solana: SolanaConnection } -> EVMConnection | SolanaConnection
|
|
25
25
|
*/
|
|
26
|
-
type
|
|
26
|
+
type Connection = AllConnections[keyof AllConnections];
|
|
27
27
|
/**
|
|
28
28
|
* Union type for all supported connector types.
|
|
29
29
|
*/
|
|
@@ -53,7 +53,7 @@ declare const SatelliteStoreContext: react.Context<StoreApi<ISatelliteConnectSto
|
|
|
53
53
|
* const activeConnection = useSatelliteConnectStore((state) => state.activeConnection);
|
|
54
54
|
* ```
|
|
55
55
|
*/
|
|
56
|
-
declare const useSatelliteConnectStore: <T>(selector: (state: ISatelliteConnectStore<Connector,
|
|
56
|
+
declare const useSatelliteConnectStore: <T>(selector: (state: ISatelliteConnectStore<Connector, Connection>) => T) => T;
|
|
57
57
|
|
|
58
58
|
/**
|
|
59
59
|
* Props for the useInitializeAutoConnect hook.
|
|
@@ -65,11 +65,11 @@ interface InitializeAutoConnectProps {
|
|
|
65
65
|
onError?: (error: Error) => void;
|
|
66
66
|
}
|
|
67
67
|
/**
|
|
68
|
-
* Custom hook for initializing
|
|
68
|
+
* Custom hook for initializing connector auto-connection with error handling.
|
|
69
69
|
*
|
|
70
70
|
* @remarks
|
|
71
71
|
* This hook handles the initial connection logic (e.g., checking for a previously
|
|
72
|
-
* connected
|
|
72
|
+
* connected connector) when a component mounts.
|
|
73
73
|
* It provides default error handling with console.error if no custom handler is provided.
|
|
74
74
|
* The initialization runs only once when the component mounts.
|
|
75
75
|
*
|
|
@@ -98,24 +98,24 @@ declare const useInitializeAutoConnect: ({ initializeAutoConnect, onError }: Ini
|
|
|
98
98
|
/**
|
|
99
99
|
* Props for SatelliteConnectProvider component
|
|
100
100
|
*/
|
|
101
|
-
interface SatelliteConnectProviderProps extends SatelliteConnectStoreInitialParameters<Connector,
|
|
101
|
+
interface SatelliteConnectProviderProps extends SatelliteConnectStoreInitialParameters<Connector, Connection> {
|
|
102
102
|
/** React child components */
|
|
103
103
|
children: React.ReactNode;
|
|
104
|
-
/** Whether to automatically connect to last used
|
|
104
|
+
/** Whether to automatically connect to last used connector */
|
|
105
105
|
autoConnect?: boolean;
|
|
106
106
|
}
|
|
107
107
|
/**
|
|
108
|
-
* Provider component that manages
|
|
108
|
+
* Provider component that manages connector connections and state
|
|
109
109
|
*
|
|
110
110
|
* @remarks
|
|
111
111
|
* This component creates and provides the Satellite Connect store context to its children.
|
|
112
|
-
* It handles
|
|
112
|
+
* It handles connector connections, state management, and automatic reconnection functionality.
|
|
113
113
|
* The store is memoized to ensure stable reference across renders.
|
|
114
114
|
*
|
|
115
115
|
* @param props - Component properties including store parameters and children
|
|
116
116
|
* @param props.children - Child components that will have access to the store
|
|
117
|
-
* @param props.autoConnect - Optional flag to enable automatic
|
|
118
|
-
* @param props.adapter - Blockchain adapter(s) for
|
|
117
|
+
* @param props.autoConnect - Optional flag to enable automatic connector reconnection
|
|
118
|
+
* @param props.adapter - Blockchain adapter(s) for connector interactions
|
|
119
119
|
* @param props.callbackAfterConnected - Optional callback for successful connections
|
|
120
120
|
*
|
|
121
121
|
* @example
|
|
@@ -139,4 +139,4 @@ interface SatelliteConnectProviderProps extends SatelliteConnectStoreInitialPara
|
|
|
139
139
|
*/
|
|
140
140
|
declare function SatelliteConnectProvider({ children, autoConnect, ...parameters }: SatelliteConnectProviderProps): react_jsx_runtime.JSX.Element;
|
|
141
141
|
|
|
142
|
-
export { type AllConnectors, type
|
|
142
|
+
export { type AllConnections, type AllConnectors, type Connection, type Connector, SatelliteConnectProvider, type SatelliteConnectProviderProps, SatelliteStoreContext, useInitializeAutoConnect, useSatelliteConnectStore };
|
package/dist/index.d.ts
CHANGED
|
@@ -7,9 +7,9 @@ import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
|
7
7
|
* @description
|
|
8
8
|
* This interface is intentionally left empty.
|
|
9
9
|
* Other packages (@tuwaio/satellite-*) will use module
|
|
10
|
-
* augmentation to add their specific
|
|
10
|
+
* augmentation to add their specific connection types here.
|
|
11
11
|
*/
|
|
12
|
-
interface
|
|
12
|
+
interface AllConnections {
|
|
13
13
|
}
|
|
14
14
|
/**
|
|
15
15
|
* @description
|
|
@@ -19,11 +19,11 @@ interface AllWallets {
|
|
|
19
19
|
interface AllConnectors {
|
|
20
20
|
}
|
|
21
21
|
/**
|
|
22
|
-
* Union type for all supported
|
|
23
|
-
* It's created from the values of the
|
|
24
|
-
* e.g., { evm:
|
|
22
|
+
* Union type for all supported connection types.
|
|
23
|
+
* It's created from the values of the AllConnections interface.
|
|
24
|
+
* e.g., { evm: EVMConnection, solana: SolanaConnection } -> EVMConnection | SolanaConnection
|
|
25
25
|
*/
|
|
26
|
-
type
|
|
26
|
+
type Connection = AllConnections[keyof AllConnections];
|
|
27
27
|
/**
|
|
28
28
|
* Union type for all supported connector types.
|
|
29
29
|
*/
|
|
@@ -53,7 +53,7 @@ declare const SatelliteStoreContext: react.Context<StoreApi<ISatelliteConnectSto
|
|
|
53
53
|
* const activeConnection = useSatelliteConnectStore((state) => state.activeConnection);
|
|
54
54
|
* ```
|
|
55
55
|
*/
|
|
56
|
-
declare const useSatelliteConnectStore: <T>(selector: (state: ISatelliteConnectStore<Connector,
|
|
56
|
+
declare const useSatelliteConnectStore: <T>(selector: (state: ISatelliteConnectStore<Connector, Connection>) => T) => T;
|
|
57
57
|
|
|
58
58
|
/**
|
|
59
59
|
* Props for the useInitializeAutoConnect hook.
|
|
@@ -65,11 +65,11 @@ interface InitializeAutoConnectProps {
|
|
|
65
65
|
onError?: (error: Error) => void;
|
|
66
66
|
}
|
|
67
67
|
/**
|
|
68
|
-
* Custom hook for initializing
|
|
68
|
+
* Custom hook for initializing connector auto-connection with error handling.
|
|
69
69
|
*
|
|
70
70
|
* @remarks
|
|
71
71
|
* This hook handles the initial connection logic (e.g., checking for a previously
|
|
72
|
-
* connected
|
|
72
|
+
* connected connector) when a component mounts.
|
|
73
73
|
* It provides default error handling with console.error if no custom handler is provided.
|
|
74
74
|
* The initialization runs only once when the component mounts.
|
|
75
75
|
*
|
|
@@ -98,24 +98,24 @@ declare const useInitializeAutoConnect: ({ initializeAutoConnect, onError }: Ini
|
|
|
98
98
|
/**
|
|
99
99
|
* Props for SatelliteConnectProvider component
|
|
100
100
|
*/
|
|
101
|
-
interface SatelliteConnectProviderProps extends SatelliteConnectStoreInitialParameters<Connector,
|
|
101
|
+
interface SatelliteConnectProviderProps extends SatelliteConnectStoreInitialParameters<Connector, Connection> {
|
|
102
102
|
/** React child components */
|
|
103
103
|
children: React.ReactNode;
|
|
104
|
-
/** Whether to automatically connect to last used
|
|
104
|
+
/** Whether to automatically connect to last used connector */
|
|
105
105
|
autoConnect?: boolean;
|
|
106
106
|
}
|
|
107
107
|
/**
|
|
108
|
-
* Provider component that manages
|
|
108
|
+
* Provider component that manages connector connections and state
|
|
109
109
|
*
|
|
110
110
|
* @remarks
|
|
111
111
|
* This component creates and provides the Satellite Connect store context to its children.
|
|
112
|
-
* It handles
|
|
112
|
+
* It handles connector connections, state management, and automatic reconnection functionality.
|
|
113
113
|
* The store is memoized to ensure stable reference across renders.
|
|
114
114
|
*
|
|
115
115
|
* @param props - Component properties including store parameters and children
|
|
116
116
|
* @param props.children - Child components that will have access to the store
|
|
117
|
-
* @param props.autoConnect - Optional flag to enable automatic
|
|
118
|
-
* @param props.adapter - Blockchain adapter(s) for
|
|
117
|
+
* @param props.autoConnect - Optional flag to enable automatic connector reconnection
|
|
118
|
+
* @param props.adapter - Blockchain adapter(s) for connector interactions
|
|
119
119
|
* @param props.callbackAfterConnected - Optional callback for successful connections
|
|
120
120
|
*
|
|
121
121
|
* @example
|
|
@@ -139,4 +139,4 @@ interface SatelliteConnectProviderProps extends SatelliteConnectStoreInitialPara
|
|
|
139
139
|
*/
|
|
140
140
|
declare function SatelliteConnectProvider({ children, autoConnect, ...parameters }: SatelliteConnectProviderProps): react_jsx_runtime.JSX.Element;
|
|
141
141
|
|
|
142
|
-
export { type AllConnectors, type
|
|
142
|
+
export { type AllConnections, type AllConnectors, type Connection, type Connector, SatelliteConnectProvider, type SatelliteConnectProviderProps, SatelliteStoreContext, useInitializeAutoConnect, useSatelliteConnectStore };
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export{d as SatelliteConnectProvider,a as SatelliteStoreContext,c as useInitializeAutoConnect,b as useSatelliteConnectStore}from'./chunk-
|
|
1
|
+
export{d as SatelliteConnectProvider,a as SatelliteStoreContext,c as useInitializeAutoConnect,b as useSatelliteConnectStore}from'./chunk-KZKVF5GG.js';//# sourceMappingURL=index.js.map
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
package/dist/solana/index.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
'use strict';var
|
|
1
|
+
'use strict';var chunk4MZHI7NY_cjs=require('../chunk-4MZHI7NY.cjs'),orbitCore=require('@tuwaio/orbit-core'),react=require('@wallet-standard/react'),react$1=require('react');function h(){let c=react.useWallets(),o=chunk4MZHI7NY_cjs.b(n=>n.activeConnection),r=chunk4MZHI7NY_cjs.b(n=>n.updateActiveConnection),a=chunk4MZHI7NY_cjs.b(n=>n.connectionError),i=chunk4MZHI7NY_cjs.b(n=>n.disconnect);return react$1.useEffect(()=>{if(o&&orbitCore.getAdapterFromConnectorType(o.connectorType)===orbitCore.OrbitAdapter.SOLANA){let n=c.filter(e=>orbitCore.getConnectorTypeFromName(orbitCore.OrbitAdapter.SOLANA,orbitCore.formatConnectorName(e.name))===o.connectorType)[0];if(!a){let e={address:n?.accounts[0]?.address,isConnected:n?.accounts.length>0,connectedAccount:n?.accounts[0],connectedWallet:n};(e.address!==o.address||e.isConnected!==o.isConnected)&&r(e);}n?.accounts.length===0&&o.connectorType&&i(o.connectorType);}},[o?.connectorType,c,a,r,i]),null}exports.SolanaConnectorsWatcher=h;//# sourceMappingURL=index.cjs.map
|
|
2
2
|
//# sourceMappingURL=index.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/solana/
|
|
1
|
+
{"version":3,"sources":["../../src/solana/SolanaConnectorsWatcher.tsx"],"names":["SolanaConnectorsWatcher","wallets","useWallets","activeConnectionFromStore","useSatelliteConnectStore","store","updateActiveConnection","connectionError","disconnect","useEffect","getAdapterFromConnectorType","OrbitAdapter","activeConnection","w","getConnectorTypeFromName","formatConnectorName","newState"],"mappings":"6KAsBO,SAASA,CAAAA,EAA0B,CACxC,IAAMC,EAAUC,gBAAAA,EAAW,CAErBC,CAAAA,CAA4BC,mBAAAA,CAA0BC,CAAAA,EAAUA,CAAAA,CAAM,gBAAgB,CAAA,CACtFC,EAAyBF,mBAAAA,CAA0BC,CAAAA,EAAUA,CAAAA,CAAM,sBAAsB,CAAA,CACzFE,CAAAA,CAAkBH,mBAAAA,CAA0BC,CAAAA,EAAUA,EAAM,eAAe,CAAA,CAC3EG,CAAAA,CAAaJ,mBAAAA,CAA0BC,CAAAA,EAAUA,CAAAA,CAAM,UAAU,CAAA,CAGvE,OAAAI,iBAAAA,CAAU,IAAM,CACd,GACEN,CAAAA,EACAO,qCAAAA,CAA4BP,CAAAA,CAA0B,aAAa,IAAMQ,sBAAAA,CAAa,MAAA,CACtF,CACA,IAAMC,CAAAA,CAAmBX,CAAAA,CAAQ,MAAA,CAC9BY,CAAAA,EACCC,mCAAyBH,sBAAAA,CAAa,MAAA,CAAQI,6BAAAA,CAAoBF,CAAAA,CAAE,IAAI,CAAC,CAAA,GACzEV,CAAAA,CAA0B,aAC9B,CAAA,CAAE,CAAC,CAAA,CAEH,GAAI,CAACI,CAAAA,CAAiB,CACpB,IAAMS,CAAAA,CAAW,CAEf,OAAA,CAASJ,CAAAA,EAAkB,QAAA,CAAS,CAAC,CAAA,EAAG,OAAA,CAExC,YAAaA,CAAAA,EAAkB,QAAA,CAAS,MAAA,CAAS,CAAA,CAEjD,gBAAA,CAAkBA,CAAAA,EAAkB,QAAA,CAAS,CAAC,EAC9C,eAAA,CAAiBA,CACnB,CAAA,CAAA,CAMEI,CAAAA,CAAS,OAAA,GAAYb,CAAAA,CAA0B,OAAA,EAC/Ca,CAAAA,CAAS,cAAgBb,CAAAA,CAA0B,WAAA,GAInDG,CAAAA,CAAuBU,CAAQ,EAEnC,CACIJ,CAAAA,EAAkB,QAAA,CAAS,SAAW,CAAA,EAAKT,CAAAA,CAA0B,aAAA,EAEvEK,CAAAA,CAAWL,CAAAA,CAA0B,aAAa,EAEtD,CAEF,EAAG,CAACA,CAAAA,EAA2B,aAAA,CAAeF,CAAAA,CAASM,CAAAA,CAAiBD,CAAAA,CAAwBE,CAAU,CAAC,EAGpG,IACT","file":"index.cjs","sourcesContent":["import {\n formatConnectorName,\n getAdapterFromConnectorType,\n getConnectorTypeFromName,\n OrbitAdapter,\n} from '@tuwaio/orbit-core';\nimport { useWallets } from '@wallet-standard/react';\nimport { useEffect } from 'react';\n\nimport { useSatelliteConnectStore } from '../index';\n\n/**\n * React component that monitors Solana connector connections and updates the Satellite store\n *\n * @remarks\n * This component watches for changes in connected Solana connectors using the Wallet Standard.\n * Currently handles the first active connector only, with multi-connector 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 SolanaConnectorsWatcher() {\n const wallets = useWallets();\n\n const activeConnectionFromStore = useSatelliteConnectStore((store) => store.activeConnection);\n const updateActiveConnection = useSatelliteConnectStore((store) => store.updateActiveConnection);\n const connectionError = useSatelliteConnectStore((store) => store.connectionError);\n const disconnect = useSatelliteConnectStore((store) => store.disconnect);\n\n // Watch for changes in connected connectors\n useEffect(() => {\n if (\n activeConnectionFromStore &&\n getAdapterFromConnectorType(activeConnectionFromStore.connectorType) === OrbitAdapter.SOLANA\n ) {\n const activeConnection = wallets.filter(\n (w) =>\n getConnectorTypeFromName(OrbitAdapter.SOLANA, formatConnectorName(w.name)) ===\n activeConnectionFromStore.connectorType,\n )[0];\n\n if (!connectionError) {\n const newState = {\n // Use the first account's address\n address: activeConnection?.accounts[0]?.address,\n // Set connection status\n isConnected: activeConnection?.accounts.length > 0,\n // Store Wallet Standard specific information\n connectedAccount: activeConnection?.accounts[0],\n connectedWallet: activeConnection,\n };\n\n // Check if anything actually changed to prevent infinite loops\n // We only check address and isConnected because connectedAccount/connectedWallet\n // might be new references on every render, causing infinite loops if checked.\n const hasChanged =\n newState.address !== activeConnectionFromStore.address ||\n newState.isConnected !== activeConnectionFromStore.isConnected;\n\n if (hasChanged) {\n // Update the Satellite store with the active connector information\n updateActiveConnection(newState);\n }\n }\n if (activeConnection?.accounts.length === 0 && activeConnectionFromStore.connectorType) {\n // If the connector is disconnected from the wallet provider, disconnect from Satellite store as well\n disconnect(activeConnectionFromStore.connectorType);\n }\n }\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [activeConnectionFromStore?.connectorType, wallets, connectionError, updateActiveConnection, disconnect]); // Re-run effect when wallets array changes\n\n // This is a headless component, so return null\n return null;\n}\n"]}
|
package/dist/solana/index.d.cts
CHANGED
|
@@ -1,26 +1,26 @@
|
|
|
1
1
|
import { OrbitAdapter } from '@tuwaio/orbit-core';
|
|
2
|
-
import {
|
|
2
|
+
import { SolanaConnection, ConnectorSolana } from '@tuwaio/satellite-solana';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
|
-
* React component that monitors Solana
|
|
5
|
+
* React component that monitors Solana connector connections and updates the Satellite store
|
|
6
6
|
*
|
|
7
7
|
* @remarks
|
|
8
|
-
* This component watches for changes in connected Solana
|
|
9
|
-
* Currently handles the first active
|
|
8
|
+
* This component watches for changes in connected Solana connectors using the Wallet Standard.
|
|
9
|
+
* Currently handles the first active connector only, with multi-connector support planned for future.
|
|
10
10
|
* It's a headless component that manages state synchronization between Wallet Standard and Satellite store.
|
|
11
11
|
*
|
|
12
12
|
* @returns null - This is a headless component
|
|
13
13
|
*
|
|
14
14
|
*/
|
|
15
|
-
declare function
|
|
15
|
+
declare function SolanaConnectorsWatcher(): null;
|
|
16
16
|
|
|
17
17
|
declare module '@tuwaio/satellite-react' {
|
|
18
|
-
interface
|
|
19
|
-
[OrbitAdapter.SOLANA]:
|
|
18
|
+
interface AllConnections {
|
|
19
|
+
[OrbitAdapter.SOLANA]: SolanaConnection;
|
|
20
20
|
}
|
|
21
21
|
interface AllConnectors {
|
|
22
22
|
[OrbitAdapter.SOLANA]: ConnectorSolana;
|
|
23
23
|
}
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
-
export {
|
|
26
|
+
export { SolanaConnectorsWatcher };
|
package/dist/solana/index.d.ts
CHANGED
|
@@ -1,26 +1,26 @@
|
|
|
1
1
|
import { OrbitAdapter } from '@tuwaio/orbit-core';
|
|
2
|
-
import {
|
|
2
|
+
import { SolanaConnection, ConnectorSolana } from '@tuwaio/satellite-solana';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
|
-
* React component that monitors Solana
|
|
5
|
+
* React component that monitors Solana connector connections and updates the Satellite store
|
|
6
6
|
*
|
|
7
7
|
* @remarks
|
|
8
|
-
* This component watches for changes in connected Solana
|
|
9
|
-
* Currently handles the first active
|
|
8
|
+
* This component watches for changes in connected Solana connectors using the Wallet Standard.
|
|
9
|
+
* Currently handles the first active connector only, with multi-connector support planned for future.
|
|
10
10
|
* It's a headless component that manages state synchronization between Wallet Standard and Satellite store.
|
|
11
11
|
*
|
|
12
12
|
* @returns null - This is a headless component
|
|
13
13
|
*
|
|
14
14
|
*/
|
|
15
|
-
declare function
|
|
15
|
+
declare function SolanaConnectorsWatcher(): null;
|
|
16
16
|
|
|
17
17
|
declare module '@tuwaio/satellite-react' {
|
|
18
|
-
interface
|
|
19
|
-
[OrbitAdapter.SOLANA]:
|
|
18
|
+
interface AllConnections {
|
|
19
|
+
[OrbitAdapter.SOLANA]: SolanaConnection;
|
|
20
20
|
}
|
|
21
21
|
interface AllConnectors {
|
|
22
22
|
[OrbitAdapter.SOLANA]: ConnectorSolana;
|
|
23
23
|
}
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
-
export {
|
|
26
|
+
export { SolanaConnectorsWatcher };
|
package/dist/solana/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {b}from'../chunk-
|
|
1
|
+
import {b}from'../chunk-KZKVF5GG.js';import {getAdapterFromConnectorType,OrbitAdapter,getConnectorTypeFromName,formatConnectorName}from'@tuwaio/orbit-core';import {useWallets}from'@wallet-standard/react';import {useEffect}from'react';function h(){let c=useWallets(),o=b(n=>n.activeConnection),r=b(n=>n.updateActiveConnection),a=b(n=>n.connectionError),i=b(n=>n.disconnect);return useEffect(()=>{if(o&&getAdapterFromConnectorType(o.connectorType)===OrbitAdapter.SOLANA){let n=c.filter(e=>getConnectorTypeFromName(OrbitAdapter.SOLANA,formatConnectorName(e.name))===o.connectorType)[0];if(!a){let e={address:n?.accounts[0]?.address,isConnected:n?.accounts.length>0,connectedAccount:n?.accounts[0],connectedWallet:n};(e.address!==o.address||e.isConnected!==o.isConnected)&&r(e);}n?.accounts.length===0&&o.connectorType&&i(o.connectorType);}},[o?.connectorType,c,a,r,i]),null}export{h as SolanaConnectorsWatcher};//# sourceMappingURL=index.js.map
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
package/dist/solana/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/solana/
|
|
1
|
+
{"version":3,"sources":["../../src/solana/SolanaConnectorsWatcher.tsx"],"names":["SolanaConnectorsWatcher","wallets","useWallets","activeConnectionFromStore","useSatelliteConnectStore","store","updateActiveConnection","connectionError","disconnect","useEffect","getAdapterFromConnectorType","OrbitAdapter","activeConnection","w","getConnectorTypeFromName","formatConnectorName","newState"],"mappings":"0OAsBO,SAASA,CAAAA,EAA0B,CACxC,IAAMC,EAAUC,UAAAA,EAAW,CAErBC,CAAAA,CAA4BC,CAAAA,CAA0BC,CAAAA,EAAUA,CAAAA,CAAM,gBAAgB,CAAA,CACtFC,EAAyBF,CAAAA,CAA0BC,CAAAA,EAAUA,CAAAA,CAAM,sBAAsB,CAAA,CACzFE,CAAAA,CAAkBH,CAAAA,CAA0BC,CAAAA,EAAUA,EAAM,eAAe,CAAA,CAC3EG,CAAAA,CAAaJ,CAAAA,CAA0BC,CAAAA,EAAUA,CAAAA,CAAM,UAAU,CAAA,CAGvE,OAAAI,SAAAA,CAAU,IAAM,CACd,GACEN,CAAAA,EACAO,2BAAAA,CAA4BP,CAAAA,CAA0B,aAAa,IAAMQ,YAAAA,CAAa,MAAA,CACtF,CACA,IAAMC,CAAAA,CAAmBX,CAAAA,CAAQ,MAAA,CAC9BY,CAAAA,EACCC,yBAAyBH,YAAAA,CAAa,MAAA,CAAQI,mBAAAA,CAAoBF,CAAAA,CAAE,IAAI,CAAC,CAAA,GACzEV,CAAAA,CAA0B,aAC9B,CAAA,CAAE,CAAC,CAAA,CAEH,GAAI,CAACI,CAAAA,CAAiB,CACpB,IAAMS,CAAAA,CAAW,CAEf,OAAA,CAASJ,CAAAA,EAAkB,QAAA,CAAS,CAAC,CAAA,EAAG,OAAA,CAExC,YAAaA,CAAAA,EAAkB,QAAA,CAAS,MAAA,CAAS,CAAA,CAEjD,gBAAA,CAAkBA,CAAAA,EAAkB,QAAA,CAAS,CAAC,EAC9C,eAAA,CAAiBA,CACnB,CAAA,CAAA,CAMEI,CAAAA,CAAS,OAAA,GAAYb,CAAAA,CAA0B,OAAA,EAC/Ca,CAAAA,CAAS,cAAgBb,CAAAA,CAA0B,WAAA,GAInDG,CAAAA,CAAuBU,CAAQ,EAEnC,CACIJ,CAAAA,EAAkB,QAAA,CAAS,SAAW,CAAA,EAAKT,CAAAA,CAA0B,aAAA,EAEvEK,CAAAA,CAAWL,CAAAA,CAA0B,aAAa,EAEtD,CAEF,EAAG,CAACA,CAAAA,EAA2B,aAAA,CAAeF,CAAAA,CAASM,CAAAA,CAAiBD,CAAAA,CAAwBE,CAAU,CAAC,EAGpG,IACT","file":"index.js","sourcesContent":["import {\n formatConnectorName,\n getAdapterFromConnectorType,\n getConnectorTypeFromName,\n OrbitAdapter,\n} from '@tuwaio/orbit-core';\nimport { useWallets } from '@wallet-standard/react';\nimport { useEffect } from 'react';\n\nimport { useSatelliteConnectStore } from '../index';\n\n/**\n * React component that monitors Solana connector connections and updates the Satellite store\n *\n * @remarks\n * This component watches for changes in connected Solana connectors using the Wallet Standard.\n * Currently handles the first active connector only, with multi-connector 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 SolanaConnectorsWatcher() {\n const wallets = useWallets();\n\n const activeConnectionFromStore = useSatelliteConnectStore((store) => store.activeConnection);\n const updateActiveConnection = useSatelliteConnectStore((store) => store.updateActiveConnection);\n const connectionError = useSatelliteConnectStore((store) => store.connectionError);\n const disconnect = useSatelliteConnectStore((store) => store.disconnect);\n\n // Watch for changes in connected connectors\n useEffect(() => {\n if (\n activeConnectionFromStore &&\n getAdapterFromConnectorType(activeConnectionFromStore.connectorType) === OrbitAdapter.SOLANA\n ) {\n const activeConnection = wallets.filter(\n (w) =>\n getConnectorTypeFromName(OrbitAdapter.SOLANA, formatConnectorName(w.name)) ===\n activeConnectionFromStore.connectorType,\n )[0];\n\n if (!connectionError) {\n const newState = {\n // Use the first account's address\n address: activeConnection?.accounts[0]?.address,\n // Set connection status\n isConnected: activeConnection?.accounts.length > 0,\n // Store Wallet Standard specific information\n connectedAccount: activeConnection?.accounts[0],\n connectedWallet: activeConnection,\n };\n\n // Check if anything actually changed to prevent infinite loops\n // We only check address and isConnected because connectedAccount/connectedWallet\n // might be new references on every render, causing infinite loops if checked.\n const hasChanged =\n newState.address !== activeConnectionFromStore.address ||\n newState.isConnected !== activeConnectionFromStore.isConnected;\n\n if (hasChanged) {\n // Update the Satellite store with the active connector information\n updateActiveConnection(newState);\n }\n }\n if (activeConnection?.accounts.length === 0 && activeConnectionFromStore.connectorType) {\n // If the connector is disconnected from the wallet provider, disconnect from Satellite store as well\n disconnect(activeConnectionFromStore.connectorType);\n }\n }\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [activeConnectionFromStore?.connectorType, wallets, connectionError, updateActiveConnection, disconnect]); // Re-run effect when wallets array changes\n\n // This is a headless component, so return null\n return null;\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tuwaio/satellite-react",
|
|
3
|
-
"version": "1.0.0-fix-packages-alpha.
|
|
3
|
+
"version": "1.0.0-fix-packages-alpha.5.08c9f96",
|
|
4
4
|
"private": false,
|
|
5
5
|
"author": "Oleksandr Tkach",
|
|
6
6
|
"license": "Apache-2.0",
|
|
7
|
-
"description": "An provider and hook with for React for satellite based
|
|
7
|
+
"description": "An provider and hook with for React for satellite based connectors.",
|
|
8
8
|
"type": "module",
|
|
9
9
|
"main": "./dist/index.js",
|
|
10
10
|
"module": "./dist/index.cjs",
|
|
@@ -56,12 +56,12 @@
|
|
|
56
56
|
}
|
|
57
57
|
],
|
|
58
58
|
"peerDependencies": {
|
|
59
|
-
"@tuwaio/orbit-core": ">=0.
|
|
60
|
-
"@tuwaio/orbit-evm": ">=0.
|
|
61
|
-
"@tuwaio/orbit-solana": ">=0.
|
|
62
|
-
"@tuwaio/satellite-core": ">=0.
|
|
63
|
-
"@tuwaio/satellite-evm": ">=0.
|
|
64
|
-
"@tuwaio/satellite-solana": ">=0.
|
|
59
|
+
"@tuwaio/orbit-core": ">=0.2",
|
|
60
|
+
"@tuwaio/orbit-evm": ">=0.2",
|
|
61
|
+
"@tuwaio/orbit-solana": ">=0.2",
|
|
62
|
+
"@tuwaio/satellite-core": ">=0.2",
|
|
63
|
+
"@tuwaio/satellite-evm": ">=0.2",
|
|
64
|
+
"@tuwaio/satellite-solana": ">=0.2",
|
|
65
65
|
"@wagmi/core": "3.x.x",
|
|
66
66
|
"viem": "2.x.x",
|
|
67
67
|
"@wallet-standard/react": "1.x.x",
|
|
@@ -113,9 +113,9 @@
|
|
|
113
113
|
},
|
|
114
114
|
"devDependencies": {
|
|
115
115
|
"@types/react": "^19.2.7",
|
|
116
|
-
"@tuwaio/orbit-core": "1.0.0-fix-packages-alpha.
|
|
117
|
-
"@tuwaio/orbit-evm": "1.0.0-fix-packages-alpha.
|
|
118
|
-
"@tuwaio/orbit-solana": "1.0.0-fix-packages-alpha.
|
|
116
|
+
"@tuwaio/orbit-core": "1.0.0-fix-packages-alpha.3.dc7f910",
|
|
117
|
+
"@tuwaio/orbit-evm": "1.0.0-fix-packages-alpha.3.dc7f910",
|
|
118
|
+
"@tuwaio/orbit-solana": "1.0.0-fix-packages-alpha.3.dc7f910",
|
|
119
119
|
"@wagmi/core": "^3.0.0",
|
|
120
120
|
"@wallet-standard/react": "^1.0.1",
|
|
121
121
|
"@wallet-standard/app": "^1.1.0",
|
|
@@ -131,9 +131,9 @@
|
|
|
131
131
|
"viem": "^2.40.3",
|
|
132
132
|
"typescript": "^5.9.3",
|
|
133
133
|
"zustand": "^5.0.8",
|
|
134
|
-
"@tuwaio/satellite-evm": "^1.0.0-fix-packages-alpha.
|
|
135
|
-
"@tuwaio/satellite-solana": "^1.0.0-fix-packages-alpha.
|
|
136
|
-
"@tuwaio/satellite-core": "^1.0.0-fix-packages-alpha.
|
|
134
|
+
"@tuwaio/satellite-evm": "^1.0.0-fix-packages-alpha.5.08c9f96",
|
|
135
|
+
"@tuwaio/satellite-solana": "^1.0.0-fix-packages-alpha.5.08c9f96",
|
|
136
|
+
"@tuwaio/satellite-core": "^1.0.0-fix-packages-alpha.5.08c9f96"
|
|
137
137
|
},
|
|
138
138
|
"scripts": {
|
|
139
139
|
"start": "tsup src/index.ts --watch",
|
package/dist/chunk-BKNDP4VE.cjs
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
'use strict';var react=require('react'),zustand=require('zustand'),satelliteCore=require('@tuwaio/satellite-core'),jsxRuntime=require('react/jsx-runtime');var r=react.createContext(null),A=e=>{let t=react.useContext(r);if(!t)throw new Error("useSatelliteConnectStore must be used within a SatelliteConnectProvider");return zustand.useStore(t,e)};var i=({initializeAutoConnect:e,onError:t})=>{react.useEffect(()=>{(async()=>{try{await e();}catch(o){(t??(l=>console.error("Failed to initialize auto connect:",l)))(o);}})();},[]);};function b({children:e,autoConnect:t,...n}){let o=react.useMemo(()=>satelliteCore.createSatelliteConnectStore({...n}),[]);return react.useEffect(()=>{o.getState().disconnectAll();},[]),i({initializeAutoConnect:()=>o.getState().initializeAutoConnect(t??!1)}),jsxRuntime.jsx(r.Provider,{value:o,children:e})}exports.a=r;exports.b=A;exports.c=i;exports.d=b;//# sourceMappingURL=chunk-BKNDP4VE.cjs.map
|
|
2
|
-
//# sourceMappingURL=chunk-BKNDP4VE.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/hooks/satteliteHook.ts","../src/hooks/useInitializeAutoConnect.tsx","../src/providers/SatelliteConnectProvider.tsx"],"names":["SatelliteStoreContext","createContext","useSatelliteConnectStore","selector","store","useContext","useStore","useInitializeAutoConnect","initializeAutoConnect","onError","useEffect","error","e","SatelliteConnectProvider","children","autoConnect","parameters","useMemo","createSatelliteConnectStore","jsx"],"mappings":"+JAUaA,CAAAA,CAAwBC,mBAAAA,CAA0E,IAAI,CAAA,CAqBtGC,EAA+BC,CAAAA,EAAyE,CAEnH,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,ECDO,IAAMI,CAAAA,CAA2B,CAAC,CAAE,qBAAA,CAAAC,CAAAA,CAAuB,OAAA,CAAAC,CAAQ,CAAA,GAAwC,CAChHC,eAAAA,CAAU,IAAM,EACqB,SAAY,CAC7C,GAAI,CACF,MAAMF,CAAAA,GACR,CAAA,MAASG,CAAAA,CAAO,EAEOF,CAAAA,GAAaG,CAAAA,EAAa,OAAA,CAAQ,KAAA,CAAM,qCAAsCA,CAAC,CAAA,CAAA,EACvFD,CAAc,EAC7B,CACF,CAAA,IAGF,CAAA,CAAG,EAAE,EACP,ECLO,SAASE,CAAAA,CAAyB,CAAE,SAAAC,CAAAA,CAAU,WAAA,CAAAC,CAAAA,CAAa,GAAGC,CAAW,CAAA,CAAkC,CAEhH,IAAMZ,CAAAA,CAAQa,cAAQ,IACbC,yCAAAA,CAA+C,CACpD,GAAGF,CACL,CAAC,CAAA,CAEA,EAAE,CAAA,CAGL,OAAAN,eAAAA,CAAU,IAAM,CACdN,CAAAA,CAAM,QAAA,EAAS,CAAE,aAAA,GAEnB,CAAA,CAAG,EAAE,CAAA,CAELG,EAAyB,CACvB,qBAAA,CAAuB,IAAMH,CAAAA,CAAM,UAAS,CAAE,qBAAA,CAAsBW,CAAAA,EAAe,CAAA,CAAK,CAC1F,CAAC,CAAA,CAEMI,cAAAA,CAACnB,CAAAA,CAAsB,SAAtB,CAA+B,KAAA,CAAOI,CAAAA,CAAQ,QAAA,CAAAU,EAAS,CACjE","file":"chunk-BKNDP4VE.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 connection\n * const activeConnection = useSatelliteConnectStore((state) => state.activeConnection);\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 { 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 */\nexport interface 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 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/hooks/satteliteHook.ts","../src/hooks/useInitializeAutoConnect.tsx","../src/providers/SatelliteConnectProvider.tsx"],"names":["SatelliteStoreContext","createContext","useSatelliteConnectStore","selector","store","useContext","useStore","useInitializeAutoConnect","initializeAutoConnect","onError","useEffect","error","e","SatelliteConnectProvider","children","autoConnect","parameters","useMemo","createSatelliteConnectStore","jsx"],"mappings":"uMAUaA,CAAAA,CAAwBC,aAAAA,CAA0E,IAAI,CAAA,CAqBtGC,EAA+BC,CAAAA,EAAyE,CAEnH,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,ECDO,IAAMI,CAAAA,CAA2B,CAAC,CAAE,qBAAA,CAAAC,CAAAA,CAAuB,OAAA,CAAAC,CAAQ,CAAA,GAAwC,CAChHC,SAAAA,CAAU,IAAM,EACqB,SAAY,CAC7C,GAAI,CACF,MAAMF,CAAAA,GACR,CAAA,MAASG,CAAAA,CAAO,EAEOF,CAAAA,GAAaG,CAAAA,EAAa,OAAA,CAAQ,KAAA,CAAM,qCAAsCA,CAAC,CAAA,CAAA,EACvFD,CAAc,EAC7B,CACF,CAAA,IAGF,CAAA,CAAG,EAAE,EACP,ECLO,SAASE,CAAAA,CAAyB,CAAE,SAAAC,CAAAA,CAAU,WAAA,CAAAC,CAAAA,CAAa,GAAGC,CAAW,CAAA,CAAkC,CAEhH,IAAMZ,CAAAA,CAAQa,QAAQ,IACbC,2BAAAA,CAA+C,CACpD,GAAGF,CACL,CAAC,CAAA,CAEA,EAAE,CAAA,CAGL,OAAAN,SAAAA,CAAU,IAAM,CACdN,CAAAA,CAAM,QAAA,EAAS,CAAE,aAAA,GAEnB,CAAA,CAAG,EAAE,CAAA,CAELG,EAAyB,CACvB,qBAAA,CAAuB,IAAMH,CAAAA,CAAM,UAAS,CAAE,qBAAA,CAAsBW,CAAAA,EAAe,CAAA,CAAK,CAC1F,CAAC,CAAA,CAEMI,GAAAA,CAACnB,CAAAA,CAAsB,SAAtB,CAA+B,KAAA,CAAOI,CAAAA,CAAQ,QAAA,CAAAU,EAAS,CACjE","file":"chunk-VXHPTE35.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 connection\n * const activeConnection = useSatelliteConnectStore((state) => state.activeConnection);\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 { 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 */\nexport interface 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"]}
|