@tuwaio/satellite-react 1.0.0-fix-adapters-independ-alpha.8.68d5692 → 1.0.0-fix-adapters-independ-alpha.9.583293c

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.
@@ -0,0 +1,2 @@
1
+ 'use strict';var chunkMTPOFZGM_cjs=require('./chunk-MTPOFZGM.cjs'),react=require('react'),satelliteCore=require('@tuwaio/satellite-core'),jsxRuntime=require('react/jsx-runtime');var i=({initializeAutoConnect:e,onError:t})=>{react.useEffect(()=>{(async()=>{try{await e();}catch(o){(t??(a=>console.error("Failed to initialize auto connect:",a)))(o);}})();},[]);};function v({children:e,autoConnect:t,...r}){let o=react.useMemo(()=>satelliteCore.createSatelliteConnectStore({...r}),[]);return i({initializeAutoConnect:()=>o.getState().initializeAutoConnect(t??!1)}),jsxRuntime.jsx(chunkMTPOFZGM_cjs.a.Provider,{value:o,children:e})}exports.a=i;exports.b=v;//# sourceMappingURL=chunk-AGENCROO.cjs.map
2
+ //# sourceMappingURL=chunk-AGENCROO.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/hooks/useInitializeAutoConnect.tsx","../src/providers/SatelliteConnectProvider.tsx"],"names":["useInitializeAutoConnect","initializeAutoConnect","onError","useEffect","error","e","SatelliteConnectProvider","children","autoConnect","parameters","store","useMemo","createSatelliteConnectStore","jsx","SatelliteStoreContext"],"mappings":"kLAyCO,IAAMA,EAA2B,CAAC,CAAE,qBAAA,CAAAC,CAAAA,CAAuB,OAAA,CAAAC,CAAQ,IAAwC,CAChHC,eAAAA,CAAU,IAAM,CAAA,CACqB,SAAY,CAC7C,GAAI,CACF,MAAMF,CAAAA,GACR,CAAA,MAASG,EAAO,CAAA,CAEOF,CAAAA,GAAaG,GAAa,OAAA,CAAQ,KAAA,CAAM,qCAAsCA,CAAC,CAAA,CAAA,EACvFD,CAAc,EAC7B,CACF,CAAA,IAGF,CAAA,CAAG,EAAE,EACP,ECLO,SAASE,CAAAA,CAAyB,CAAE,QAAA,CAAAC,CAAAA,CAAU,WAAA,CAAAC,CAAAA,CAAa,GAAGC,CAAW,EAAkC,CAEhH,IAAMC,EAAQC,aAAAA,CAAQ,IACbC,0CAAmD,CACxD,GAAGH,CACL,CAAC,CAAA,CAEA,EAAE,CAAA,CAEL,OAAAT,EAAyB,CACvB,qBAAA,CAAuB,IAAMU,CAAAA,CAAM,QAAA,EAAS,CAAE,qBAAA,CAAsBF,CAAAA,EAAe,CAAA,CAAK,CAC1F,CAAC,CAAA,CAEMK,eAACC,mBAAAA,CAAsB,QAAA,CAAtB,CAA+B,KAAA,CAAOJ,CAAAA,CAAQ,QAAA,CAAAH,CAAAA,CAAS,CACjE","file":"chunk-AGENCROO.cjs","sourcesContent":["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 { 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 useInitializeAutoConnect({\n initializeAutoConnect: () => store.getState().initializeAutoConnect(autoConnect ?? false),\n });\n\n return <SatelliteStoreContext.Provider value={store}>{children}</SatelliteStoreContext.Provider>;\n}\n"]}
@@ -0,0 +1,2 @@
1
+ 'use strict';var react=require('react'),zustand=require('zustand');var i=react.createContext(null),C=e=>{let t=react.useContext(i);if(!t)throw new Error("useSatelliteConnectStore must be used within a SatelliteConnectProvider");return zustand.useStore(t,e)};exports.a=i;exports.b=C;//# sourceMappingURL=chunk-MTPOFZGM.cjs.map
2
+ //# sourceMappingURL=chunk-MTPOFZGM.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/hooks/satelliteHook.ts"],"names":["SatelliteStoreContext","createContext","useSatelliteConnectStore","selector","store","useContext","useStore"],"mappings":"uEAUaA,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","file":"chunk-MTPOFZGM.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"]}
@@ -0,0 +1,2 @@
1
+ import {createContext,useContext}from'react';import {useStore}from'zustand';var i=createContext(null),C=e=>{let t=useContext(i);if(!t)throw new Error("useSatelliteConnectStore must be used within a SatelliteConnectProvider");return useStore(t,e)};export{i as a,C as b};//# sourceMappingURL=chunk-P73K26ND.js.map
2
+ //# sourceMappingURL=chunk-P73K26ND.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/hooks/satelliteHook.ts"],"names":["SatelliteStoreContext","createContext","useSatelliteConnectStore","selector","store","useContext","useStore"],"mappings":"gFAUaA,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","file":"chunk-P73K26ND.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"]}
@@ -0,0 +1,2 @@
1
+ import {a}from'./chunk-P73K26ND.js';import {useEffect,useMemo}from'react';import {createSatelliteConnectStore}from'@tuwaio/satellite-core';import {jsx}from'react/jsx-runtime';var i=({initializeAutoConnect:e,onError:t})=>{useEffect(()=>{(async()=>{try{await e();}catch(o){(t??(a=>console.error("Failed to initialize auto connect:",a)))(o);}})();},[]);};function v({children:e,autoConnect:t,...r}){let o=useMemo(()=>createSatelliteConnectStore({...r}),[]);return i({initializeAutoConnect:()=>o.getState().initializeAutoConnect(t??!1)}),jsx(a.Provider,{value:o,children:e})}export{i as a,v as b};//# sourceMappingURL=chunk-U2ZTZ52J.js.map
2
+ //# sourceMappingURL=chunk-U2ZTZ52J.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/hooks/useInitializeAutoConnect.tsx","../src/providers/SatelliteConnectProvider.tsx"],"names":["useInitializeAutoConnect","initializeAutoConnect","onError","useEffect","error","e","SatelliteConnectProvider","children","autoConnect","parameters","store","useMemo","createSatelliteConnectStore","jsx","SatelliteStoreContext"],"mappings":"+KAyCO,IAAMA,EAA2B,CAAC,CAAE,qBAAA,CAAAC,CAAAA,CAAuB,OAAA,CAAAC,CAAQ,IAAwC,CAChHC,SAAAA,CAAU,IAAM,CAAA,CACqB,SAAY,CAC7C,GAAI,CACF,MAAMF,CAAAA,GACR,CAAA,MAASG,EAAO,CAAA,CAEOF,CAAAA,GAAaG,GAAa,OAAA,CAAQ,KAAA,CAAM,qCAAsCA,CAAC,CAAA,CAAA,EACvFD,CAAc,EAC7B,CACF,CAAA,IAGF,CAAA,CAAG,EAAE,EACP,ECLO,SAASE,CAAAA,CAAyB,CAAE,QAAA,CAAAC,CAAAA,CAAU,WAAA,CAAAC,CAAAA,CAAa,GAAGC,CAAW,EAAkC,CAEhH,IAAMC,EAAQC,OAAAA,CAAQ,IACbC,4BAAmD,CACxD,GAAGH,CACL,CAAC,CAAA,CAEA,EAAE,CAAA,CAEL,OAAAT,EAAyB,CACvB,qBAAA,CAAuB,IAAMU,CAAAA,CAAM,QAAA,EAAS,CAAE,qBAAA,CAAsBF,CAAAA,EAAe,CAAA,CAAK,CAC1F,CAAC,CAAA,CAEMK,IAACC,CAAAA,CAAsB,QAAA,CAAtB,CAA+B,KAAA,CAAOJ,CAAAA,CAAQ,QAAA,CAAAH,CAAAA,CAAS,CACjE","file":"chunk-U2ZTZ52J.js","sourcesContent":["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 { 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 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
- 'use strict';var chunk23IZMVDP_cjs=require('../chunk-23IZMVDP.cjs'),react=require('react'),jsxRuntime=require('react/jsx-runtime'),orbitCore=require('@tuwaio/orbit-core'),core=require('@wagmi/core');function b(a){let[e,n]=react.useState(null);return react.useEffect(()=>{(async()=>{try{let t=!1;try{await Promise.all([import('@wagmi/core'),import('viem')]),t=!0,console.log("hasDependencies",t);}catch{t=!1;}if(t){let o=await new Function('return import("./EVMConnectorsWatcherImpl").then(module => module.EVMConnectorsWatcherImpl).catch(error => { console.warn("Failed to load EVMConnectorsWatcherImpl:", error); return null; })')();n(()=>o);}}catch(t){console.warn("Failed to load EVM watcher:",t);}})(),console.log("WatcherComponent",e);},[]),e?jsxRuntime.jsx(e,{...a}):null}function R({wagmiConfig:a,siwe:e}){let n=chunk23IZMVDP_cjs.b(o=>o.activeConnection),i=chunk23IZMVDP_cjs.b(o=>o.disconnect),t=chunk23IZMVDP_cjs.b(o=>o.connectionError),p=chunk23IZMVDP_cjs.b(o=>o.updateActiveConnection);return react.useEffect(()=>{e?.enabled&&!e?.isSignedIn&&e?.isRejected&&n&&i(n.connectorType);},[e,i,n]),react.useEffect(()=>core.watchConnections(a,{onChange:m=>{if(n&&orbitCore.getAdapterFromConnectorType(n.connectorType)!==orbitCore.OrbitAdapter.EVM)return;if(m.length===0){n&&i(n.connectorType);return}let r=core.getConnection(a);if(n&&orbitCore.getAdapterFromConnectorType(n.connectorType)!==orbitCore.OrbitAdapter.EVM||!r||t)return;if(e?.enabled?e.isSignedIn:true){let l=r.connector,h={connectorType:l?`${orbitCore.OrbitAdapter.EVM}:${orbitCore.formatConnectorName(l.name)}`:n?.connectorType,address:r.address,chainId:r.chainId,rpcURL:r?.chain?.rpcUrls.default.http[0],isConnected:true};p(h);}}}),[n?.connectorType,e,t]),null}exports.EVMConnectorsWatcher=b;exports.EVMConnectorsWatcherImpl=R;//# sourceMappingURL=index.cjs.map
1
+ 'use strict';require('../chunk-AGENCROO.cjs');var chunkMTPOFZGM_cjs=require('../chunk-MTPOFZGM.cjs'),react=require('react'),jsxRuntime=require('react/jsx-runtime');function w(t){let[r,f]=react.useState(null);return react.useEffect(()=>{(async()=>{try{let n=!1,a=null;try{let[c]=await Promise.all([import('@tuwaio/satellite-evm'),import('@wagmi/core'),import('viem')]);a=c.createEVMConnectionsWatcher,n=!0;}catch{n=!1;}if(n){let c=()=>{let i=chunkMTPOFZGM_cjs.b(e=>e.activeConnection),l=chunkMTPOFZGM_cjs.b(e=>e.disconnect),s=chunkMTPOFZGM_cjs.b(e=>e.connectionError),C=chunkMTPOFZGM_cjs.b(e=>e.updateActiveConnection);return react.useEffect(()=>a({wagmiConfig:t.wagmiConfig,siwe:t.siwe},{activeConnection:i,disconnect:l,connectionError:s,updateActiveConnection:C}),[i?.connectorType,t.siwe,s,t.wagmiConfig,l,C]),null};f(()=>c);}}catch(n){console.warn("Failed to load EVM watcher:",n);}})();},[]),r?jsxRuntime.jsx(r,{...t}):null}exports.EVMConnectorsWatcher=w;//# sourceMappingURL=index.cjs.map
2
2
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/evm/EVMConnectorsWatcherDynamic.tsx","../../src/evm/EVMConnectorsWatcherImpl.tsx"],"names":["EVMConnectorsWatcher","props","WatcherComponent","setWatcherComponent","useState","useEffect","hasDependencies","WatcherImpl","error","jsx","EVMConnectorsWatcherImpl","wagmiConfig","siwe","activeConnection","useSatelliteConnectStore","store","disconnect","connectionError","updateActiveConnection","watchConnections","connections","getAdapterFromConnectorType","OrbitAdapter","currentConnection","getConnection","currentConnector","updatedConnector","formatConnectorName"],"mappings":"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","file":"index.cjs","sourcesContent":["import { useEffect, useState } from 'react';\n\n/**\n * Props for the {@link EVMConnectorsWatcher} component.\n */\nexport interface EVMConnectorsWatcherProps {\n /**\n * The configuration object from `@wagmi/core`.\n * This is required to initialize the account watcher.\n */\n wagmiConfig: any; // Using 'any' to avoid direct import of @wagmi/core types\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 dynamic version of the EVMConnectorsWatcher component that avoids static imports.\n * This component dynamically imports the dependencies only when they are available.\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(props: EVMConnectorsWatcherProps) {\n const [WatcherComponent, setWatcherComponent] = useState<React.ComponentType<EVMConnectorsWatcherProps> | null>(null);\n\n // Load the actual watcher component dynamically\n useEffect(() => {\n const loadWatcher = async () => {\n try {\n let hasDependencies = false;\n\n // Use dynamic imports\n try {\n await Promise.all([import('@wagmi/core'), import('viem')]);\n hasDependencies = true;\n console.log('hasDependencies', hasDependencies);\n } catch {\n hasDependencies = false;\n }\n\n if (hasDependencies) {\n // Dynamically import the actual implementation\n const dynamicImport = new Function(\n 'return import(\"./EVMConnectorsWatcherImpl\").then(module => module.EVMConnectorsWatcherImpl).catch(error => { console.warn(\"Failed to load EVMConnectorsWatcherImpl:\", error); return null; })',\n );\n\n const WatcherImpl = await dynamicImport();\n setWatcherComponent(() => WatcherImpl);\n }\n } catch (error) {\n console.warn('Failed to load EVM watcher:', error);\n }\n };\n\n loadWatcher();\n\n console.log('WatcherComponent', WatcherComponent);\n }, []);\n\n // Render the actual watcher if it's loaded\n if (WatcherComponent) {\n return <WatcherComponent {...props} />;\n }\n\n // This is a headless component, so return null\n return null;\n}\n","import { ConnectorType, formatConnectorName, getAdapterFromConnectorType, OrbitAdapter } from '@tuwaio/orbit-core';\nimport { getConnection, watchConnections, WatchConnectionsParameters } from '@wagmi/core';\nimport { useEffect } from 'react';\n\nimport { useSatelliteConnectStore } from '../index';\nimport { EVMConnectorsWatcherProps } from './EVMConnectorsWatcherDynamic';\n\n/**\n * The actual implementation of the EVMConnectorsWatcher component.\n * This component is dynamically imported only when the required dependencies are available.\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 EVMConnectorsWatcherImpl({ 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 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 const currentConnection = getConnection(wagmiConfig);\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 !currentConnection ||\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 const currentConnector = currentConnection.connector;\n const currentConnectorType = currentConnector\n ? (`${OrbitAdapter.EVM}:${formatConnectorName(currentConnector.name)}` as ConnectorType)\n : activeConnection?.connectorType;\n\n const updatedConnector = {\n connectorType: currentConnectorType,\n address: currentConnection.address,\n chainId: currentConnection.chainId,\n rpcURL: currentConnection?.chain?.rpcUrls.default.http[0],\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"]}
1
+ {"version":3,"sources":["../../src/evm/EVMConnectorsWatcherDynamic.tsx"],"names":["EVMConnectorsWatcher","props","WatcherComponent","setWatcherComponent","useState","useEffect","hasDependencies","createEVMConnectionsWatcher","satelliteEVM","WatcherImpl","activeConnection","useSatelliteConnectStore","store","disconnect","connectionError","updateActiveConnection","error","jsx"],"mappings":"oKA0CO,SAASA,CAAAA,CAAqBC,EAAkC,CACrE,GAAM,CAACC,CAAAA,CAAkBC,CAAmB,CAAA,CAAIC,cAAAA,CAAgE,IAAI,CAAA,CA0DpH,OAvDAC,eAAAA,CAAU,IAAM,CAAA,CACM,SAAY,CAC9B,GAAI,CACF,IAAIC,CAAAA,CAAkB,GAClBC,CAAAA,CAAmC,IAAA,CAGvC,GAAI,CACF,GAAM,CAACC,CAAY,CAAA,CAAI,MAAM,OAAA,CAAQ,IAAI,CACvC,OAAO,uBAAuB,CAAA,CAC9B,OAAO,aAAa,CAAA,CACpB,OAAO,MAAM,CACf,CAAC,CAAA,CACDD,CAAAA,CAA8BC,CAAAA,CAAa,4BAC3CF,CAAAA,CAAkB,CAAA,EACpB,CAAA,KAAQ,CACNA,EAAkB,CAAA,EACpB,CAEA,GAAIA,CAAAA,CAAiB,CACnB,IAAMG,CAAAA,CAAc,IAAM,CACxB,IAAMC,CAAAA,CAAmBC,mBAAAA,CAA0BC,GAAUA,CAAAA,CAAM,gBAAgB,EAC7EC,CAAAA,CAAaF,mBAAAA,CAA0BC,CAAAA,EAAUA,CAAAA,CAAM,UAAU,CAAA,CACjEE,CAAAA,CAAkBH,mBAAAA,CAA0BC,CAAAA,EAAUA,EAAM,eAAe,CAAA,CAC3EG,CAAAA,CAAyBJ,mBAAAA,CAA0BC,GAAUA,CAAAA,CAAM,sBAAsB,CAAA,CAE/F,OAAAP,gBAAU,IACQE,CAAAA,CACd,CAAE,WAAA,CAAaN,EAAM,WAAA,CAAa,IAAA,CAAMA,CAAAA,CAAM,IAAK,EACnD,CAAE,gBAAA,CAAAS,CAAAA,CAAkB,UAAA,CAAAG,EAAY,eAAA,CAAAC,CAAAA,CAAiB,uBAAAC,CAAuB,CAC1E,EAIC,CACDL,CAAAA,EAAkB,aAAA,CAClBT,CAAAA,CAAM,KACNa,CAAAA,CACAb,CAAAA,CAAM,WAAA,CACNY,CAAAA,CACAE,CACF,CAAC,CAAA,CACM,IACT,CAAA,CACAZ,EAAoB,IAAMM,CAAW,EACvC,CACF,OAASO,CAAAA,CAAO,CACd,OAAA,CAAQ,IAAA,CAAK,8BAA+BA,CAAK,EACnD,CACF,CAAA,IAGF,CAAA,CAAG,EAAE,CAAA,CAGDd,EACKe,cAAAA,CAACf,CAAAA,CAAA,CAAkB,GAAGD,CAAAA,CAAO,EAI/B,IACT","file":"index.cjs","sourcesContent":["import { useEffect, useState } from 'react';\n\nimport { useSatelliteConnectStore } from '../index';\n\n/**\n * Props for the {@link EVMConnectorsWatcher} component.\n */\nexport interface EVMConnectorsWatcherProps {\n /**\n * The configuration object from `@wagmi/core`.\n * This is required to initialize the account watcher.\n */\n wagmiConfig: any; // Using 'any' to avoid direct import of @wagmi/core types\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 dynamic version of the EVMConnectorsWatcher component that avoids static imports.\n * This component dynamically imports the dependencies only when they are available.\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(props: EVMConnectorsWatcherProps) {\n const [WatcherComponent, setWatcherComponent] = useState<React.ComponentType<EVMConnectorsWatcherProps> | null>(null);\n\n // Load the actual watcher component dynamically\n useEffect(() => {\n const loadWatcher = async () => {\n try {\n let hasDependencies = false;\n let createEVMConnectionsWatcher: any = null;\n\n // Use dynamic imports\n try {\n const [satelliteEVM] = await Promise.all([\n import('@tuwaio/satellite-evm'),\n import('@wagmi/core'),\n import('viem'),\n ]);\n createEVMConnectionsWatcher = satelliteEVM.createEVMConnectionsWatcher;\n hasDependencies = true;\n } catch {\n hasDependencies = false;\n }\n\n if (hasDependencies) {\n const WatcherImpl = () => {\n const activeConnection = useSatelliteConnectStore((store) => store.activeConnection);\n const disconnect = useSatelliteConnectStore((store) => store.disconnect);\n const connectionError = useSatelliteConnectStore((store) => store.connectionError);\n const updateActiveConnection = useSatelliteConnectStore((store) => store.updateActiveConnection);\n\n useEffect(() => {\n const unwatch = createEVMConnectionsWatcher(\n { wagmiConfig: props.wagmiConfig, siwe: props.siwe },\n { activeConnection, disconnect, connectionError, updateActiveConnection },\n );\n\n return unwatch;\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [\n activeConnection?.connectorType,\n props.siwe,\n connectionError,\n props.wagmiConfig,\n disconnect,\n updateActiveConnection,\n ]);\n return null;\n };\n setWatcherComponent(() => WatcherImpl);\n }\n } catch (error) {\n console.warn('Failed to load EVM watcher:', error);\n }\n };\n\n loadWatcher();\n }, []);\n\n // Render the actual watcher if it's loaded\n if (WatcherComponent) {\n return <WatcherComponent {...props} />;\n }\n\n // This is a headless component, so return null\n return null;\n}\n"]}
@@ -40,15 +40,6 @@ interface EVMConnectorsWatcherProps {
40
40
  */
41
41
  declare function EVMConnectorsWatcher(props: EVMConnectorsWatcherProps): react_jsx_runtime.JSX.Element | null;
42
42
 
43
- /**
44
- * The actual implementation of the EVMConnectorsWatcher component.
45
- * This component is dynamically imported only when the required dependencies are available.
46
- *
47
- * @param props - The component's props. See {@link EVMConnectorsWatcherProps} for details.
48
- * @returns {null} This component does not render any UI.
49
- */
50
- declare function EVMConnectorsWatcherImpl({ wagmiConfig, siwe }: EVMConnectorsWatcherProps): null;
51
-
52
43
  declare module '@tuwaio/satellite-react' {
53
44
  interface AllConnections {
54
45
  [OrbitAdapter.EVM]: EVMConnection;
@@ -58,4 +49,4 @@ declare module '@tuwaio/satellite-react' {
58
49
  }
59
50
  }
60
51
 
61
- export { EVMConnectorsWatcher, EVMConnectorsWatcherImpl, type EVMConnectorsWatcherProps };
52
+ export { EVMConnectorsWatcher, type EVMConnectorsWatcherProps };
@@ -40,15 +40,6 @@ interface EVMConnectorsWatcherProps {
40
40
  */
41
41
  declare function EVMConnectorsWatcher(props: EVMConnectorsWatcherProps): react_jsx_runtime.JSX.Element | null;
42
42
 
43
- /**
44
- * The actual implementation of the EVMConnectorsWatcher component.
45
- * This component is dynamically imported only when the required dependencies are available.
46
- *
47
- * @param props - The component's props. See {@link EVMConnectorsWatcherProps} for details.
48
- * @returns {null} This component does not render any UI.
49
- */
50
- declare function EVMConnectorsWatcherImpl({ wagmiConfig, siwe }: EVMConnectorsWatcherProps): null;
51
-
52
43
  declare module '@tuwaio/satellite-react' {
53
44
  interface AllConnections {
54
45
  [OrbitAdapter.EVM]: EVMConnection;
@@ -58,4 +49,4 @@ declare module '@tuwaio/satellite-react' {
58
49
  }
59
50
  }
60
51
 
61
- export { EVMConnectorsWatcher, EVMConnectorsWatcherImpl, type EVMConnectorsWatcherProps };
52
+ export { EVMConnectorsWatcher, type EVMConnectorsWatcherProps };
package/dist/evm/index.js CHANGED
@@ -1,2 +1,2 @@
1
- import {b as b$1}from'../chunk-4RWO4WUN.js';import {useState,useEffect}from'react';import {jsx}from'react/jsx-runtime';import {getAdapterFromConnectorType,OrbitAdapter,formatConnectorName}from'@tuwaio/orbit-core';import {watchConnections,getConnection}from'@wagmi/core';function b(a){let[e,n]=useState(null);return useEffect(()=>{(async()=>{try{let t=!1;try{await Promise.all([import('@wagmi/core'),import('viem')]),t=!0,console.log("hasDependencies",t);}catch{t=!1;}if(t){let o=await new Function('return import("./EVMConnectorsWatcherImpl").then(module => module.EVMConnectorsWatcherImpl).catch(error => { console.warn("Failed to load EVMConnectorsWatcherImpl:", error); return null; })')();n(()=>o);}}catch(t){console.warn("Failed to load EVM watcher:",t);}})(),console.log("WatcherComponent",e);},[]),e?jsx(e,{...a}):null}function R({wagmiConfig:a,siwe:e}){let n=b$1(o=>o.activeConnection),i=b$1(o=>o.disconnect),t=b$1(o=>o.connectionError),p=b$1(o=>o.updateActiveConnection);return useEffect(()=>{e?.enabled&&!e?.isSignedIn&&e?.isRejected&&n&&i(n.connectorType);},[e,i,n]),useEffect(()=>watchConnections(a,{onChange:m=>{if(n&&getAdapterFromConnectorType(n.connectorType)!==OrbitAdapter.EVM)return;if(m.length===0){n&&i(n.connectorType);return}let r=getConnection(a);if(n&&getAdapterFromConnectorType(n.connectorType)!==OrbitAdapter.EVM||!r||t)return;if(e?.enabled?e.isSignedIn:true){let l=r.connector,h={connectorType:l?`${OrbitAdapter.EVM}:${formatConnectorName(l.name)}`:n?.connectorType,address:r.address,chainId:r.chainId,rpcURL:r?.chain?.rpcUrls.default.http[0],isConnected:true};p(h);}}}),[n?.connectorType,e,t]),null}export{b as EVMConnectorsWatcher,R as EVMConnectorsWatcherImpl};//# sourceMappingURL=index.js.map
1
+ import'../chunk-U2ZTZ52J.js';import {b}from'../chunk-P73K26ND.js';import {useState,useEffect}from'react';import {jsx}from'react/jsx-runtime';function w(t){let[r,f]=useState(null);return useEffect(()=>{(async()=>{try{let n=!1,a=null;try{let[c]=await Promise.all([import('@tuwaio/satellite-evm'),import('@wagmi/core'),import('viem')]);a=c.createEVMConnectionsWatcher,n=!0;}catch{n=!1;}if(n){let c=()=>{let i=b(e=>e.activeConnection),l=b(e=>e.disconnect),s=b(e=>e.connectionError),C=b(e=>e.updateActiveConnection);return useEffect(()=>a({wagmiConfig:t.wagmiConfig,siwe:t.siwe},{activeConnection:i,disconnect:l,connectionError:s,updateActiveConnection:C}),[i?.connectorType,t.siwe,s,t.wagmiConfig,l,C]),null};f(()=>c);}}catch(n){console.warn("Failed to load EVM watcher:",n);}})();},[]),r?jsx(r,{...t}):null}export{w as EVMConnectorsWatcher};//# sourceMappingURL=index.js.map
2
2
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/evm/EVMConnectorsWatcherDynamic.tsx","../../src/evm/EVMConnectorsWatcherImpl.tsx"],"names":["EVMConnectorsWatcher","props","WatcherComponent","setWatcherComponent","useState","useEffect","hasDependencies","WatcherImpl","error","jsx","EVMConnectorsWatcherImpl","wagmiConfig","siwe","activeConnection","useSatelliteConnectStore","store","disconnect","connectionError","updateActiveConnection","watchConnections","connections","getAdapterFromConnectorType","OrbitAdapter","currentConnection","getConnection","currentConnector","updatedConnector","formatConnectorName"],"mappings":"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","file":"index.js","sourcesContent":["import { useEffect, useState } from 'react';\n\n/**\n * Props for the {@link EVMConnectorsWatcher} component.\n */\nexport interface EVMConnectorsWatcherProps {\n /**\n * The configuration object from `@wagmi/core`.\n * This is required to initialize the account watcher.\n */\n wagmiConfig: any; // Using 'any' to avoid direct import of @wagmi/core types\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 dynamic version of the EVMConnectorsWatcher component that avoids static imports.\n * This component dynamically imports the dependencies only when they are available.\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(props: EVMConnectorsWatcherProps) {\n const [WatcherComponent, setWatcherComponent] = useState<React.ComponentType<EVMConnectorsWatcherProps> | null>(null);\n\n // Load the actual watcher component dynamically\n useEffect(() => {\n const loadWatcher = async () => {\n try {\n let hasDependencies = false;\n\n // Use dynamic imports\n try {\n await Promise.all([import('@wagmi/core'), import('viem')]);\n hasDependencies = true;\n console.log('hasDependencies', hasDependencies);\n } catch {\n hasDependencies = false;\n }\n\n if (hasDependencies) {\n // Dynamically import the actual implementation\n const dynamicImport = new Function(\n 'return import(\"./EVMConnectorsWatcherImpl\").then(module => module.EVMConnectorsWatcherImpl).catch(error => { console.warn(\"Failed to load EVMConnectorsWatcherImpl:\", error); return null; })',\n );\n\n const WatcherImpl = await dynamicImport();\n setWatcherComponent(() => WatcherImpl);\n }\n } catch (error) {\n console.warn('Failed to load EVM watcher:', error);\n }\n };\n\n loadWatcher();\n\n console.log('WatcherComponent', WatcherComponent);\n }, []);\n\n // Render the actual watcher if it's loaded\n if (WatcherComponent) {\n return <WatcherComponent {...props} />;\n }\n\n // This is a headless component, so return null\n return null;\n}\n","import { ConnectorType, formatConnectorName, getAdapterFromConnectorType, OrbitAdapter } from '@tuwaio/orbit-core';\nimport { getConnection, watchConnections, WatchConnectionsParameters } from '@wagmi/core';\nimport { useEffect } from 'react';\n\nimport { useSatelliteConnectStore } from '../index';\nimport { EVMConnectorsWatcherProps } from './EVMConnectorsWatcherDynamic';\n\n/**\n * The actual implementation of the EVMConnectorsWatcher component.\n * This component is dynamically imported only when the required dependencies are available.\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 EVMConnectorsWatcherImpl({ 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 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 const currentConnection = getConnection(wagmiConfig);\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 !currentConnection ||\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 const currentConnector = currentConnection.connector;\n const currentConnectorType = currentConnector\n ? (`${OrbitAdapter.EVM}:${formatConnectorName(currentConnector.name)}` as ConnectorType)\n : activeConnection?.connectorType;\n\n const updatedConnector = {\n connectorType: currentConnectorType,\n address: currentConnection.address,\n chainId: currentConnection.chainId,\n rpcURL: currentConnection?.chain?.rpcUrls.default.http[0],\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"]}
1
+ {"version":3,"sources":["../../src/evm/EVMConnectorsWatcherDynamic.tsx"],"names":["EVMConnectorsWatcher","props","WatcherComponent","setWatcherComponent","useState","useEffect","hasDependencies","createEVMConnectionsWatcher","satelliteEVM","WatcherImpl","activeConnection","useSatelliteConnectStore","store","disconnect","connectionError","updateActiveConnection","error","jsx"],"mappings":"6IA0CO,SAASA,CAAAA,CAAqBC,EAAkC,CACrE,GAAM,CAACC,CAAAA,CAAkBC,CAAmB,CAAA,CAAIC,QAAAA,CAAgE,IAAI,CAAA,CA0DpH,OAvDAC,SAAAA,CAAU,IAAM,CAAA,CACM,SAAY,CAC9B,GAAI,CACF,IAAIC,CAAAA,CAAkB,GAClBC,CAAAA,CAAmC,IAAA,CAGvC,GAAI,CACF,GAAM,CAACC,CAAY,CAAA,CAAI,MAAM,OAAA,CAAQ,IAAI,CACvC,OAAO,uBAAuB,CAAA,CAC9B,OAAO,aAAa,CAAA,CACpB,OAAO,MAAM,CACf,CAAC,CAAA,CACDD,CAAAA,CAA8BC,CAAAA,CAAa,4BAC3CF,CAAAA,CAAkB,CAAA,EACpB,CAAA,KAAQ,CACNA,EAAkB,CAAA,EACpB,CAEA,GAAIA,CAAAA,CAAiB,CACnB,IAAMG,CAAAA,CAAc,IAAM,CACxB,IAAMC,CAAAA,CAAmBC,CAAAA,CAA0BC,GAAUA,CAAAA,CAAM,gBAAgB,EAC7EC,CAAAA,CAAaF,CAAAA,CAA0BC,CAAAA,EAAUA,CAAAA,CAAM,UAAU,CAAA,CACjEE,CAAAA,CAAkBH,CAAAA,CAA0BC,CAAAA,EAAUA,EAAM,eAAe,CAAA,CAC3EG,CAAAA,CAAyBJ,CAAAA,CAA0BC,GAAUA,CAAAA,CAAM,sBAAsB,CAAA,CAE/F,OAAAP,UAAU,IACQE,CAAAA,CACd,CAAE,WAAA,CAAaN,EAAM,WAAA,CAAa,IAAA,CAAMA,CAAAA,CAAM,IAAK,EACnD,CAAE,gBAAA,CAAAS,CAAAA,CAAkB,UAAA,CAAAG,EAAY,eAAA,CAAAC,CAAAA,CAAiB,uBAAAC,CAAuB,CAC1E,EAIC,CACDL,CAAAA,EAAkB,aAAA,CAClBT,CAAAA,CAAM,KACNa,CAAAA,CACAb,CAAAA,CAAM,WAAA,CACNY,CAAAA,CACAE,CACF,CAAC,CAAA,CACM,IACT,CAAA,CACAZ,EAAoB,IAAMM,CAAW,EACvC,CACF,OAASO,CAAAA,CAAO,CACd,OAAA,CAAQ,IAAA,CAAK,8BAA+BA,CAAK,EACnD,CACF,CAAA,IAGF,CAAA,CAAG,EAAE,CAAA,CAGDd,EACKe,GAAAA,CAACf,CAAAA,CAAA,CAAkB,GAAGD,CAAAA,CAAO,EAI/B,IACT","file":"index.js","sourcesContent":["import { useEffect, useState } from 'react';\n\nimport { useSatelliteConnectStore } from '../index';\n\n/**\n * Props for the {@link EVMConnectorsWatcher} component.\n */\nexport interface EVMConnectorsWatcherProps {\n /**\n * The configuration object from `@wagmi/core`.\n * This is required to initialize the account watcher.\n */\n wagmiConfig: any; // Using 'any' to avoid direct import of @wagmi/core types\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 dynamic version of the EVMConnectorsWatcher component that avoids static imports.\n * This component dynamically imports the dependencies only when they are available.\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(props: EVMConnectorsWatcherProps) {\n const [WatcherComponent, setWatcherComponent] = useState<React.ComponentType<EVMConnectorsWatcherProps> | null>(null);\n\n // Load the actual watcher component dynamically\n useEffect(() => {\n const loadWatcher = async () => {\n try {\n let hasDependencies = false;\n let createEVMConnectionsWatcher: any = null;\n\n // Use dynamic imports\n try {\n const [satelliteEVM] = await Promise.all([\n import('@tuwaio/satellite-evm'),\n import('@wagmi/core'),\n import('viem'),\n ]);\n createEVMConnectionsWatcher = satelliteEVM.createEVMConnectionsWatcher;\n hasDependencies = true;\n } catch {\n hasDependencies = false;\n }\n\n if (hasDependencies) {\n const WatcherImpl = () => {\n const activeConnection = useSatelliteConnectStore((store) => store.activeConnection);\n const disconnect = useSatelliteConnectStore((store) => store.disconnect);\n const connectionError = useSatelliteConnectStore((store) => store.connectionError);\n const updateActiveConnection = useSatelliteConnectStore((store) => store.updateActiveConnection);\n\n useEffect(() => {\n const unwatch = createEVMConnectionsWatcher(\n { wagmiConfig: props.wagmiConfig, siwe: props.siwe },\n { activeConnection, disconnect, connectionError, updateActiveConnection },\n );\n\n return unwatch;\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [\n activeConnection?.connectorType,\n props.siwe,\n connectionError,\n props.wagmiConfig,\n disconnect,\n updateActiveConnection,\n ]);\n return null;\n };\n setWatcherComponent(() => WatcherImpl);\n }\n } catch (error) {\n console.warn('Failed to load EVM watcher:', error);\n }\n };\n\n loadWatcher();\n }, []);\n\n // Render the actual watcher if it's loaded\n if (WatcherComponent) {\n return <WatcherComponent {...props} />;\n }\n\n // This is a headless component, so return null\n return null;\n}\n"]}
package/dist/index.cjs CHANGED
@@ -1,2 +1,2 @@
1
- 'use strict';var chunk23IZMVDP_cjs=require('./chunk-23IZMVDP.cjs');Object.defineProperty(exports,"SatelliteConnectProvider",{enumerable:true,get:function(){return chunk23IZMVDP_cjs.d}});Object.defineProperty(exports,"SatelliteStoreContext",{enumerable:true,get:function(){return chunk23IZMVDP_cjs.a}});Object.defineProperty(exports,"useInitializeAutoConnect",{enumerable:true,get:function(){return chunk23IZMVDP_cjs.c}});Object.defineProperty(exports,"useSatelliteConnectStore",{enumerable:true,get:function(){return chunk23IZMVDP_cjs.b}});//# sourceMappingURL=index.cjs.map
1
+ 'use strict';var chunkAGENCROO_cjs=require('./chunk-AGENCROO.cjs'),chunkMTPOFZGM_cjs=require('./chunk-MTPOFZGM.cjs');Object.defineProperty(exports,"SatelliteConnectProvider",{enumerable:true,get:function(){return chunkAGENCROO_cjs.b}});Object.defineProperty(exports,"useInitializeAutoConnect",{enumerable:true,get:function(){return chunkAGENCROO_cjs.a}});Object.defineProperty(exports,"SatelliteStoreContext",{enumerable:true,get:function(){return chunkMTPOFZGM_cjs.a}});Object.defineProperty(exports,"useSatelliteConnectStore",{enumerable:true,get:function(){return chunkMTPOFZGM_cjs.b}});//# sourceMappingURL=index.cjs.map
2
2
  //# sourceMappingURL=index.cjs.map
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-4RWO4WUN.js';//# sourceMappingURL=index.js.map
1
+ export{b as SatelliteConnectProvider,a as useInitializeAutoConnect}from'./chunk-U2ZTZ52J.js';export{a as SatelliteStoreContext,b as useSatelliteConnectStore}from'./chunk-P73K26ND.js';//# sourceMappingURL=index.js.map
2
2
  //# sourceMappingURL=index.js.map
@@ -1,2 +1,2 @@
1
- 'use strict';var chunk23IZMVDP_cjs=require('../chunk-23IZMVDP.cjs'),react=require('react'),jsxRuntime=require('react/jsx-runtime'),orbitCore=require('@tuwaio/orbit-core'),react$1=require('@wallet-standard/react');function y(){let[t,n]=react.useState(null);return react.useEffect(()=>{(async()=>{try{let e=!1;try{await import('@wallet-standard/react'),e=!0;}catch{e=!1;}if(e){let o=await new Function('return import("./SolanaConnectorsWatcherImpl").then(module => module.SolanaConnectorsWatcherImpl).catch(error => { console.warn("Failed to load SolanaConnectorsWatcherImpl:", error); return null; })')();n(()=>o);}}catch(e){console.warn("Failed to load Solana watcher:",e);}})();},[]),t?jsxRuntime.jsx(t,{}):null}function F(){let t=react$1.useWallets(),n=chunk23IZMVDP_cjs.b(o=>o.activeConnection),a=chunk23IZMVDP_cjs.b(o=>o.updateActiveConnection),e=chunk23IZMVDP_cjs.b(o=>o.connectionError),l=chunk23IZMVDP_cjs.b(o=>o.disconnect);return react.useEffect(()=>{if(n&&orbitCore.getAdapterFromConnectorType(n.connectorType)===orbitCore.OrbitAdapter.SOLANA){let o=t.filter(r=>orbitCore.getConnectorTypeFromName(orbitCore.OrbitAdapter.SOLANA,orbitCore.formatConnectorName(r.name))===n.connectorType)[0];if(!e){let r={address:o?.accounts[0]?.address,isConnected:o?.accounts.length>0,connectedAccount:o?.accounts[0],connectedWallet:o};(r.address!==n.address||r.isConnected!==n.isConnected)&&a(r);}o?.accounts.length===0&&n.connectorType&&l(n.connectorType);}},[n?.connectorType,t,e,a,l]),null}exports.SolanaConnectorsWatcher=y;exports.SolanaConnectorsWatcherImpl=F;//# sourceMappingURL=index.cjs.map
1
+ 'use strict';var chunkMTPOFZGM_cjs=require('../chunk-MTPOFZGM.cjs'),react=require('react'),jsxRuntime=require('react/jsx-runtime');function W(){let[c,m]=react.useState(null);return react.useEffect(()=>{(async()=>{try{let n=!1,r=null,l=null;try{let[a,o]=await Promise.all([import('@tuwaio/satellite-solana'),import('@wallet-standard/react')]);r=a.createSolanaConnectionsWatcher,l=o.useWallets,n=!0;}catch{n=!1;}if(n){let a=()=>{let o=l(),i=chunkMTPOFZGM_cjs.b(t=>t.activeConnection),s=chunkMTPOFZGM_cjs.b(t=>t.updateActiveConnection),p=chunkMTPOFZGM_cjs.b(t=>t.connectionError),u=chunkMTPOFZGM_cjs.b(t=>t.disconnect);return react.useEffect(()=>r({wallets:o},{activeConnection:i,disconnect:u,connectionError:p,updateActiveConnection:s}),[i?.connectorType,o,p,s,u]),null};m(()=>a);}}catch(n){console.warn("Failed to load Solana watcher:",n);}})();},[]),c?jsxRuntime.jsx(c,{}):null}exports.SolanaConnectorsWatcher=W;//# sourceMappingURL=index.cjs.map
2
2
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/solana/SolanaConnectorsWatcherDynamic.tsx","../../src/solana/SolanaConnectorsWatcherImpl.tsx"],"names":["SolanaConnectorsWatcher","WatcherComponent","setWatcherComponent","useState","useEffect","hasDependencies","WatcherImpl","error","jsx","SolanaConnectorsWatcherImpl","wallets","useWallets","activeConnectionFromStore","useSatelliteConnectStore","store","updateActiveConnection","connectionError","disconnect","getAdapterFromConnectorType","OrbitAdapter","activeConnection","w","getConnectorTypeFromName","formatConnectorName","newState"],"mappings":"qNAQO,SAASA,CAAAA,EAA0B,CACxC,GAAM,CAACC,CAAAA,CAAkBC,CAAmB,CAAA,CAAIC,cAAAA,CAAqC,IAAI,CAAA,CAiCzF,OA9BAC,eAAAA,CAAU,IAAM,CAAA,CACM,SAAY,CAC9B,GAAI,CACF,IAAIC,CAAAA,CAAkB,CAAA,CAAA,CAEtB,GAAI,CACF,aAAa,wBAAwB,CAAA,CACrCA,CAAAA,CAAkB,CAAA,EACpB,CAAA,KAAQ,CACNA,EAAkB,CAAA,EACpB,CAEA,GAAIA,CAAAA,CAAiB,CAMnB,IAAMC,EAAc,MAJE,IAAI,QAAA,CACxB,wMACF,CAAA,EAEwC,CACxCJ,EAAoB,IAAMI,CAAW,EACvC,CACF,CAAA,MAASC,CAAAA,CAAO,CACd,OAAA,CAAQ,IAAA,CAAK,gCAAA,CAAkCA,CAAK,EACtD,CACF,KAGF,CAAA,CAAG,EAAE,CAAA,CAGDN,CAAAA,CACKO,eAACP,CAAAA,CAAA,EAAiB,CAAA,CAIpB,IACT,CC/BO,SAASQ,CAAAA,EAA8B,CAC5C,IAAMC,EAAUC,kBAAAA,EAAW,CAErBC,CAAAA,CAA4BC,mBAAAA,CAA0BC,CAAAA,EAAUA,CAAAA,CAAM,gBAAgB,CAAA,CACtFC,CAAAA,CAAyBF,mBAAAA,CAA0BC,CAAAA,EAAUA,CAAAA,CAAM,sBAAsB,EACzFE,CAAAA,CAAkBH,mBAAAA,CAA0BC,CAAAA,EAAUA,CAAAA,CAAM,eAAe,CAAA,CAC3EG,EAAaJ,mBAAAA,CAA0BC,CAAAA,EAAUA,CAAAA,CAAM,UAAU,CAAA,CAGvE,OAAAV,gBAAU,IAAM,CACd,GACEQ,CAAAA,EACAM,qCAAAA,CAA4BN,CAAAA,CAA0B,aAAa,CAAA,GAAMO,sBAAAA,CAAa,MAAA,CACtF,CACA,IAAMC,CAAAA,CAAmBV,EAAQ,MAAA,CAC9BW,CAAAA,EACCC,kCAAAA,CAAyBH,sBAAAA,CAAa,MAAA,CAAQI,6BAAAA,CAAoBF,EAAE,IAAI,CAAC,CAAA,GACzET,CAAAA,CAA0B,aAC9B,CAAA,CAAE,CAAC,CAAA,CAEH,GAAI,CAACI,CAAAA,CAAiB,CACpB,IAAMQ,EAAW,CAEf,OAAA,CAASJ,CAAAA,EAAkB,QAAA,CAAS,CAAC,CAAA,EAAG,QAExC,WAAA,CAAaA,CAAAA,EAAkB,QAAA,CAAS,MAAA,CAAS,CAAA,CAEjD,gBAAA,CAAkBA,GAAkB,QAAA,CAAS,CAAC,CAAA,CAC9C,eAAA,CAAiBA,CACnB,CAAA,CAAA,CAMEI,EAAS,OAAA,GAAYZ,CAAAA,CAA0B,OAAA,EAC/CY,CAAAA,CAAS,WAAA,GAAgBZ,CAAAA,CAA0B,cAInDG,CAAAA,CAAuBS,CAAQ,EAEnC,CACIJ,CAAAA,EAAkB,QAAA,CAAS,SAAW,CAAA,EAAKR,CAAAA,CAA0B,aAAA,EAEvEK,CAAAA,CAAWL,CAAAA,CAA0B,aAAa,EAEtD,CAEF,CAAA,CAAG,CAACA,CAAAA,EAA2B,aAAA,CAAeF,CAAAA,CAASM,EAAiBD,CAAAA,CAAwBE,CAAU,CAAC,CAAA,CAGpG,IACT","file":"index.cjs","sourcesContent":["import { useEffect, useState } from 'react';\n\n/**\n * A dynamic version of the SolanaConnectorsWatcher component that avoids static imports.\n * This component dynamically imports the dependencies only when they are available.\n *\n * @returns null - This is a headless component\n */\nexport function SolanaConnectorsWatcher() {\n const [WatcherComponent, setWatcherComponent] = useState<React.ComponentType | null>(null);\n\n // Load the actual watcher component dynamically\n useEffect(() => {\n const loadWatcher = async () => {\n try {\n let hasDependencies = false;\n // Use dynamic imports\n try {\n await import('@wallet-standard/react');\n hasDependencies = true;\n } catch {\n hasDependencies = false;\n }\n\n if (hasDependencies) {\n // Dynamically import the actual implementation\n const dynamicImport = new Function(\n 'return import(\"./SolanaConnectorsWatcherImpl\").then(module => module.SolanaConnectorsWatcherImpl).catch(error => { console.warn(\"Failed to load SolanaConnectorsWatcherImpl:\", error); return null; })',\n );\n\n const WatcherImpl = await dynamicImport();\n setWatcherComponent(() => WatcherImpl);\n }\n } catch (error) {\n console.warn('Failed to load Solana watcher:', error);\n }\n };\n\n loadWatcher();\n }, []);\n\n // Render the actual watcher if it's loaded\n if (WatcherComponent) {\n return <WatcherComponent />;\n }\n\n // This is a headless component, so return null\n return null;\n}\n","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 * The actual implementation of the SolanaConnectorsWatcher component.\n * This component is dynamically imported only when the required dependencies are available.\n *\n * @returns null - This is a headless component\n */\nexport function SolanaConnectorsWatcherImpl() {\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"]}
1
+ {"version":3,"sources":["../../src/solana/SolanaConnectorsWatcherDynamic.tsx"],"names":["SolanaConnectorsWatcher","WatcherComponent","setWatcherComponent","useState","useEffect","hasDependencies","createSolanaConnectionsWatcher","useWallets","satelliteSolana","wallets","WatcherImpl","activeConnection","useSatelliteConnectStore","store","updateActiveConnection","connectionError","disconnect","error","jsx"],"mappings":"mIAUO,SAASA,CAAAA,EAA0B,CACxC,GAAM,CAACC,CAAAA,CAAkBC,CAAmB,EAAIC,cAAAA,CAAqC,IAAI,CAAA,CAkDzF,OA/CAC,gBAAU,IAAM,CAAA,CACM,SAAY,CAC9B,GAAI,CACF,IAAIC,CAAAA,CAAkB,CAAA,CAAA,CAClBC,EAAsC,IAAA,CACtCC,CAAAA,CAAkB,IAAA,CAEtB,GAAI,CACF,GAAM,CAACC,CAAAA,CAAiBC,CAAO,EAAI,MAAM,OAAA,CAAQ,GAAA,CAAI,CACnD,OAAO,0BAA0B,CAAA,CACjC,OAAO,wBAAwB,CACjC,CAAC,CAAA,CACDH,CAAAA,CAAiCE,CAAAA,CAAgB,+BACjDD,CAAAA,CAAaE,CAAAA,CAAQ,UAAA,CACrBJ,CAAAA,CAAkB,GACpB,CAAA,KAAQ,CACNA,CAAAA,CAAkB,CAAA,EACpB,CAEA,GAAIA,CAAAA,CAAiB,CACnB,IAAMK,EAAc,IAAM,CACxB,IAAMD,CAAAA,CAAUF,GAAW,CACrBI,CAAAA,CAAmBC,mBAAAA,CAA0BC,CAAAA,EAAUA,EAAM,gBAAgB,CAAA,CAC7EC,CAAAA,CAAyBF,mBAAAA,CAA0BC,GAAUA,CAAAA,CAAM,sBAAsB,CAAA,CACzFE,CAAAA,CAAkBH,oBAA0BC,CAAAA,EAAUA,CAAAA,CAAM,eAAe,CAAA,CAC3EG,EAAaJ,mBAAAA,CAA0BC,CAAAA,EAAUA,CAAAA,CAAM,UAAU,EACvE,OAAAT,eAAAA,CAAU,IACQE,CAAAA,CACd,CAAE,OAAA,CAAAG,CAAQ,CAAA,CACV,CAAE,iBAAAE,CAAAA,CAAkB,UAAA,CAAAK,CAAAA,CAAY,eAAA,CAAAD,EAAiB,sBAAA,CAAAD,CAAuB,CAC1E,CAAA,CAGC,CAACH,CAAAA,EAAkB,aAAA,CAAeF,CAAAA,CAASM,CAAAA,CAAiBD,EAAwBE,CAAU,CAAC,CAAA,CAC3F,IACT,EACAd,CAAAA,CAAoB,IAAMQ,CAAW,EACvC,CACF,CAAA,MAASO,CAAAA,CAAO,CACd,OAAA,CAAQ,KAAK,gCAAA,CAAkCA,CAAK,EACtD,CACF,KAGF,CAAA,CAAG,EAAE,EAGDhB,CAAAA,CACKiB,cAAAA,CAACjB,CAAAA,CAAA,EAAiB,EAIpB,IACT","file":"index.cjs","sourcesContent":["import { useEffect, useState } from 'react';\n\nimport { useSatelliteConnectStore } from '../hooks/satelliteHook';\n\n/**\n * A dynamic version of the SolanaConnectorsWatcher component that avoids static imports.\n * This component dynamically imports the dependencies only when they are available.\n *\n * @returns null - This is a headless component\n */\nexport function SolanaConnectorsWatcher() {\n const [WatcherComponent, setWatcherComponent] = useState<React.ComponentType | null>(null);\n\n // Load the actual watcher component dynamically\n useEffect(() => {\n const loadWatcher = async () => {\n try {\n let hasDependencies = false;\n let createSolanaConnectionsWatcher: any = null;\n let useWallets: any = null;\n // Use dynamic imports\n try {\n const [satelliteSolana, wallets] = await Promise.all([\n import('@tuwaio/satellite-solana'),\n import('@wallet-standard/react'),\n ]);\n createSolanaConnectionsWatcher = satelliteSolana.createSolanaConnectionsWatcher;\n useWallets = wallets.useWallets;\n hasDependencies = true;\n } catch {\n hasDependencies = false;\n }\n\n if (hasDependencies) {\n const WatcherImpl = () => {\n const wallets = useWallets();\n const activeConnection = 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 useEffect(() => {\n const unwatch = createSolanaConnectionsWatcher(\n { wallets },\n { activeConnection, disconnect, connectionError, updateActiveConnection },\n );\n return unwatch;\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [activeConnection?.connectorType, wallets, connectionError, updateActiveConnection, disconnect]);\n return null;\n };\n setWatcherComponent(() => WatcherImpl);\n }\n } catch (error) {\n console.warn('Failed to load Solana watcher:', error);\n }\n };\n\n loadWatcher();\n }, []);\n\n // Render the actual watcher if it's loaded\n if (WatcherComponent) {\n return <WatcherComponent />;\n }\n\n // This is a headless component, so return null\n return null;\n}\n"]}
@@ -10,14 +10,6 @@ import * as react_jsx_runtime from 'react/jsx-runtime';
10
10
  */
11
11
  declare function SolanaConnectorsWatcher(): react_jsx_runtime.JSX.Element | null;
12
12
 
13
- /**
14
- * The actual implementation of the SolanaConnectorsWatcher component.
15
- * This component is dynamically imported only when the required dependencies are available.
16
- *
17
- * @returns null - This is a headless component
18
- */
19
- declare function SolanaConnectorsWatcherImpl(): null;
20
-
21
13
  declare module '@tuwaio/satellite-react' {
22
14
  interface AllConnections {
23
15
  [OrbitAdapter.SOLANA]: SolanaConnection;
@@ -27,4 +19,4 @@ declare module '@tuwaio/satellite-react' {
27
19
  }
28
20
  }
29
21
 
30
- export { SolanaConnectorsWatcher, SolanaConnectorsWatcherImpl };
22
+ export { SolanaConnectorsWatcher };
@@ -10,14 +10,6 @@ import * as react_jsx_runtime from 'react/jsx-runtime';
10
10
  */
11
11
  declare function SolanaConnectorsWatcher(): react_jsx_runtime.JSX.Element | null;
12
12
 
13
- /**
14
- * The actual implementation of the SolanaConnectorsWatcher component.
15
- * This component is dynamically imported only when the required dependencies are available.
16
- *
17
- * @returns null - This is a headless component
18
- */
19
- declare function SolanaConnectorsWatcherImpl(): null;
20
-
21
13
  declare module '@tuwaio/satellite-react' {
22
14
  interface AllConnections {
23
15
  [OrbitAdapter.SOLANA]: SolanaConnection;
@@ -27,4 +19,4 @@ declare module '@tuwaio/satellite-react' {
27
19
  }
28
20
  }
29
21
 
30
- export { SolanaConnectorsWatcher, SolanaConnectorsWatcherImpl };
22
+ export { SolanaConnectorsWatcher };
@@ -1,2 +1,2 @@
1
- import {b}from'../chunk-4RWO4WUN.js';import {useState,useEffect}from'react';import {jsx}from'react/jsx-runtime';import {getAdapterFromConnectorType,OrbitAdapter,getConnectorTypeFromName,formatConnectorName}from'@tuwaio/orbit-core';import {useWallets}from'@wallet-standard/react';function y(){let[t,n]=useState(null);return useEffect(()=>{(async()=>{try{let e=!1;try{await import('@wallet-standard/react'),e=!0;}catch{e=!1;}if(e){let o=await new Function('return import("./SolanaConnectorsWatcherImpl").then(module => module.SolanaConnectorsWatcherImpl).catch(error => { console.warn("Failed to load SolanaConnectorsWatcherImpl:", error); return null; })')();n(()=>o);}}catch(e){console.warn("Failed to load Solana watcher:",e);}})();},[]),t?jsx(t,{}):null}function F(){let t=useWallets(),n=b(o=>o.activeConnection),a=b(o=>o.updateActiveConnection),e=b(o=>o.connectionError),l=b(o=>o.disconnect);return useEffect(()=>{if(n&&getAdapterFromConnectorType(n.connectorType)===OrbitAdapter.SOLANA){let o=t.filter(r=>getConnectorTypeFromName(OrbitAdapter.SOLANA,formatConnectorName(r.name))===n.connectorType)[0];if(!e){let r={address:o?.accounts[0]?.address,isConnected:o?.accounts.length>0,connectedAccount:o?.accounts[0],connectedWallet:o};(r.address!==n.address||r.isConnected!==n.isConnected)&&a(r);}o?.accounts.length===0&&n.connectorType&&l(n.connectorType);}},[n?.connectorType,t,e,a,l]),null}export{y as SolanaConnectorsWatcher,F as SolanaConnectorsWatcherImpl};//# sourceMappingURL=index.js.map
1
+ import {b}from'../chunk-P73K26ND.js';import {useState,useEffect}from'react';import {jsx}from'react/jsx-runtime';function W(){let[c,m]=useState(null);return useEffect(()=>{(async()=>{try{let n=!1,r=null,l=null;try{let[a,o]=await Promise.all([import('@tuwaio/satellite-solana'),import('@wallet-standard/react')]);r=a.createSolanaConnectionsWatcher,l=o.useWallets,n=!0;}catch{n=!1;}if(n){let a=()=>{let o=l(),i=b(t=>t.activeConnection),s=b(t=>t.updateActiveConnection),p=b(t=>t.connectionError),u=b(t=>t.disconnect);return useEffect(()=>r({wallets:o},{activeConnection:i,disconnect:u,connectionError:p,updateActiveConnection:s}),[i?.connectorType,o,p,s,u]),null};m(()=>a);}}catch(n){console.warn("Failed to load Solana watcher:",n);}})();},[]),c?jsx(c,{}):null}export{W as SolanaConnectorsWatcher};//# sourceMappingURL=index.js.map
2
2
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/solana/SolanaConnectorsWatcherDynamic.tsx","../../src/solana/SolanaConnectorsWatcherImpl.tsx"],"names":["SolanaConnectorsWatcher","WatcherComponent","setWatcherComponent","useState","useEffect","hasDependencies","WatcherImpl","error","jsx","SolanaConnectorsWatcherImpl","wallets","useWallets","activeConnectionFromStore","useSatelliteConnectStore","store","updateActiveConnection","connectionError","disconnect","getAdapterFromConnectorType","OrbitAdapter","activeConnection","w","getConnectorTypeFromName","formatConnectorName","newState"],"mappings":"uRAQO,SAASA,CAAAA,EAA0B,CACxC,GAAM,CAACC,CAAAA,CAAkBC,CAAmB,CAAA,CAAIC,QAAAA,CAAqC,IAAI,CAAA,CAiCzF,OA9BAC,SAAAA,CAAU,IAAM,CAAA,CACM,SAAY,CAC9B,GAAI,CACF,IAAIC,CAAAA,CAAkB,CAAA,CAAA,CAEtB,GAAI,CACF,aAAa,wBAAwB,CAAA,CACrCA,CAAAA,CAAkB,CAAA,EACpB,CAAA,KAAQ,CACNA,EAAkB,CAAA,EACpB,CAEA,GAAIA,CAAAA,CAAiB,CAMnB,IAAMC,EAAc,MAJE,IAAI,QAAA,CACxB,wMACF,CAAA,EAEwC,CACxCJ,EAAoB,IAAMI,CAAW,EACvC,CACF,CAAA,MAASC,CAAAA,CAAO,CACd,OAAA,CAAQ,IAAA,CAAK,gCAAA,CAAkCA,CAAK,EACtD,CACF,KAGF,CAAA,CAAG,EAAE,CAAA,CAGDN,CAAAA,CACKO,IAACP,CAAAA,CAAA,EAAiB,CAAA,CAIpB,IACT,CC/BO,SAASQ,CAAAA,EAA8B,CAC5C,IAAMC,EAAUC,UAAAA,EAAW,CAErBC,CAAAA,CAA4BC,CAAAA,CAA0BC,CAAAA,EAAUA,CAAAA,CAAM,gBAAgB,CAAA,CACtFC,CAAAA,CAAyBF,CAAAA,CAA0BC,CAAAA,EAAUA,CAAAA,CAAM,sBAAsB,EACzFE,CAAAA,CAAkBH,CAAAA,CAA0BC,CAAAA,EAAUA,CAAAA,CAAM,eAAe,CAAA,CAC3EG,EAAaJ,CAAAA,CAA0BC,CAAAA,EAAUA,CAAAA,CAAM,UAAU,CAAA,CAGvE,OAAAV,UAAU,IAAM,CACd,GACEQ,CAAAA,EACAM,2BAAAA,CAA4BN,CAAAA,CAA0B,aAAa,CAAA,GAAMO,YAAAA,CAAa,MAAA,CACtF,CACA,IAAMC,CAAAA,CAAmBV,EAAQ,MAAA,CAC9BW,CAAAA,EACCC,wBAAAA,CAAyBH,YAAAA,CAAa,MAAA,CAAQI,mBAAAA,CAAoBF,EAAE,IAAI,CAAC,CAAA,GACzET,CAAAA,CAA0B,aAC9B,CAAA,CAAE,CAAC,CAAA,CAEH,GAAI,CAACI,CAAAA,CAAiB,CACpB,IAAMQ,EAAW,CAEf,OAAA,CAASJ,CAAAA,EAAkB,QAAA,CAAS,CAAC,CAAA,EAAG,QAExC,WAAA,CAAaA,CAAAA,EAAkB,QAAA,CAAS,MAAA,CAAS,CAAA,CAEjD,gBAAA,CAAkBA,GAAkB,QAAA,CAAS,CAAC,CAAA,CAC9C,eAAA,CAAiBA,CACnB,CAAA,CAAA,CAMEI,EAAS,OAAA,GAAYZ,CAAAA,CAA0B,OAAA,EAC/CY,CAAAA,CAAS,WAAA,GAAgBZ,CAAAA,CAA0B,cAInDG,CAAAA,CAAuBS,CAAQ,EAEnC,CACIJ,CAAAA,EAAkB,QAAA,CAAS,SAAW,CAAA,EAAKR,CAAAA,CAA0B,aAAA,EAEvEK,CAAAA,CAAWL,CAAAA,CAA0B,aAAa,EAEtD,CAEF,CAAA,CAAG,CAACA,CAAAA,EAA2B,aAAA,CAAeF,CAAAA,CAASM,EAAiBD,CAAAA,CAAwBE,CAAU,CAAC,CAAA,CAGpG,IACT","file":"index.js","sourcesContent":["import { useEffect, useState } from 'react';\n\n/**\n * A dynamic version of the SolanaConnectorsWatcher component that avoids static imports.\n * This component dynamically imports the dependencies only when they are available.\n *\n * @returns null - This is a headless component\n */\nexport function SolanaConnectorsWatcher() {\n const [WatcherComponent, setWatcherComponent] = useState<React.ComponentType | null>(null);\n\n // Load the actual watcher component dynamically\n useEffect(() => {\n const loadWatcher = async () => {\n try {\n let hasDependencies = false;\n // Use dynamic imports\n try {\n await import('@wallet-standard/react');\n hasDependencies = true;\n } catch {\n hasDependencies = false;\n }\n\n if (hasDependencies) {\n // Dynamically import the actual implementation\n const dynamicImport = new Function(\n 'return import(\"./SolanaConnectorsWatcherImpl\").then(module => module.SolanaConnectorsWatcherImpl).catch(error => { console.warn(\"Failed to load SolanaConnectorsWatcherImpl:\", error); return null; })',\n );\n\n const WatcherImpl = await dynamicImport();\n setWatcherComponent(() => WatcherImpl);\n }\n } catch (error) {\n console.warn('Failed to load Solana watcher:', error);\n }\n };\n\n loadWatcher();\n }, []);\n\n // Render the actual watcher if it's loaded\n if (WatcherComponent) {\n return <WatcherComponent />;\n }\n\n // This is a headless component, so return null\n return null;\n}\n","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 * The actual implementation of the SolanaConnectorsWatcher component.\n * This component is dynamically imported only when the required dependencies are available.\n *\n * @returns null - This is a headless component\n */\nexport function SolanaConnectorsWatcherImpl() {\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"]}
1
+ {"version":3,"sources":["../../src/solana/SolanaConnectorsWatcherDynamic.tsx"],"names":["SolanaConnectorsWatcher","WatcherComponent","setWatcherComponent","useState","useEffect","hasDependencies","createSolanaConnectionsWatcher","useWallets","satelliteSolana","wallets","WatcherImpl","activeConnection","useSatelliteConnectStore","store","updateActiveConnection","connectionError","disconnect","error","jsx"],"mappings":"gHAUO,SAASA,CAAAA,EAA0B,CACxC,GAAM,CAACC,CAAAA,CAAkBC,CAAmB,EAAIC,QAAAA,CAAqC,IAAI,CAAA,CAkDzF,OA/CAC,UAAU,IAAM,CAAA,CACM,SAAY,CAC9B,GAAI,CACF,IAAIC,CAAAA,CAAkB,CAAA,CAAA,CAClBC,EAAsC,IAAA,CACtCC,CAAAA,CAAkB,IAAA,CAEtB,GAAI,CACF,GAAM,CAACC,CAAAA,CAAiBC,CAAO,EAAI,MAAM,OAAA,CAAQ,GAAA,CAAI,CACnD,OAAO,0BAA0B,CAAA,CACjC,OAAO,wBAAwB,CACjC,CAAC,CAAA,CACDH,CAAAA,CAAiCE,CAAAA,CAAgB,+BACjDD,CAAAA,CAAaE,CAAAA,CAAQ,UAAA,CACrBJ,CAAAA,CAAkB,GACpB,CAAA,KAAQ,CACNA,CAAAA,CAAkB,CAAA,EACpB,CAEA,GAAIA,CAAAA,CAAiB,CACnB,IAAMK,EAAc,IAAM,CACxB,IAAMD,CAAAA,CAAUF,GAAW,CACrBI,CAAAA,CAAmBC,CAAAA,CAA0BC,CAAAA,EAAUA,EAAM,gBAAgB,CAAA,CAC7EC,CAAAA,CAAyBF,CAAAA,CAA0BC,GAAUA,CAAAA,CAAM,sBAAsB,CAAA,CACzFE,CAAAA,CAAkBH,EAA0BC,CAAAA,EAAUA,CAAAA,CAAM,eAAe,CAAA,CAC3EG,EAAaJ,CAAAA,CAA0BC,CAAAA,EAAUA,CAAAA,CAAM,UAAU,EACvE,OAAAT,SAAAA,CAAU,IACQE,CAAAA,CACd,CAAE,OAAA,CAAAG,CAAQ,CAAA,CACV,CAAE,iBAAAE,CAAAA,CAAkB,UAAA,CAAAK,CAAAA,CAAY,eAAA,CAAAD,EAAiB,sBAAA,CAAAD,CAAuB,CAC1E,CAAA,CAGC,CAACH,CAAAA,EAAkB,aAAA,CAAeF,CAAAA,CAASM,CAAAA,CAAiBD,EAAwBE,CAAU,CAAC,CAAA,CAC3F,IACT,EACAd,CAAAA,CAAoB,IAAMQ,CAAW,EACvC,CACF,CAAA,MAASO,CAAAA,CAAO,CACd,OAAA,CAAQ,KAAK,gCAAA,CAAkCA,CAAK,EACtD,CACF,KAGF,CAAA,CAAG,EAAE,EAGDhB,CAAAA,CACKiB,GAAAA,CAACjB,CAAAA,CAAA,EAAiB,EAIpB,IACT","file":"index.js","sourcesContent":["import { useEffect, useState } from 'react';\n\nimport { useSatelliteConnectStore } from '../hooks/satelliteHook';\n\n/**\n * A dynamic version of the SolanaConnectorsWatcher component that avoids static imports.\n * This component dynamically imports the dependencies only when they are available.\n *\n * @returns null - This is a headless component\n */\nexport function SolanaConnectorsWatcher() {\n const [WatcherComponent, setWatcherComponent] = useState<React.ComponentType | null>(null);\n\n // Load the actual watcher component dynamically\n useEffect(() => {\n const loadWatcher = async () => {\n try {\n let hasDependencies = false;\n let createSolanaConnectionsWatcher: any = null;\n let useWallets: any = null;\n // Use dynamic imports\n try {\n const [satelliteSolana, wallets] = await Promise.all([\n import('@tuwaio/satellite-solana'),\n import('@wallet-standard/react'),\n ]);\n createSolanaConnectionsWatcher = satelliteSolana.createSolanaConnectionsWatcher;\n useWallets = wallets.useWallets;\n hasDependencies = true;\n } catch {\n hasDependencies = false;\n }\n\n if (hasDependencies) {\n const WatcherImpl = () => {\n const wallets = useWallets();\n const activeConnection = 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 useEffect(() => {\n const unwatch = createSolanaConnectionsWatcher(\n { wallets },\n { activeConnection, disconnect, connectionError, updateActiveConnection },\n );\n return unwatch;\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [activeConnection?.connectorType, wallets, connectionError, updateActiveConnection, disconnect]);\n return null;\n };\n setWatcherComponent(() => WatcherImpl);\n }\n } catch (error) {\n console.warn('Failed to load Solana watcher:', error);\n }\n };\n\n loadWatcher();\n }, []);\n\n // Render the actual watcher if it's loaded\n if (WatcherComponent) {\n return <WatcherComponent />;\n }\n\n // This is a headless component, so return null\n return null;\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tuwaio/satellite-react",
3
- "version": "1.0.0-fix-adapters-independ-alpha.8.68d5692",
3
+ "version": "1.0.0-fix-adapters-independ-alpha.9.583293c",
4
4
  "private": false,
5
5
  "author": "Oleksandr Tkach",
6
6
  "license": "Apache-2.0",
@@ -131,9 +131,9 @@
131
131
  "viem": "^2.42.1",
132
132
  "typescript": "^5.9.3",
133
133
  "zustand": "^5.0.9",
134
- "@tuwaio/satellite-core": "^1.0.0-fix-adapters-independ-alpha.8.68d5692",
135
- "@tuwaio/satellite-evm": "^1.0.0-fix-adapters-independ-alpha.8.68d5692",
136
- "@tuwaio/satellite-solana": "^1.0.0-fix-adapters-independ-alpha.8.68d5692"
134
+ "@tuwaio/satellite-solana": "^1.0.0-fix-adapters-independ-alpha.9.583293c",
135
+ "@tuwaio/satellite-core": "^1.0.0-fix-adapters-independ-alpha.9.583293c",
136
+ "@tuwaio/satellite-evm": "^1.0.0-fix-adapters-independ-alpha.9.583293c"
137
137
  },
138
138
  "scripts": {
139
139
  "start": "tsup src/index.ts --watch",
@@ -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),P=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??(c=>console.error("Failed to initialize auto connect:",c)))(o);}})();},[]);};function b({children:e,autoConnect:t,...n}){let o=react.useMemo(()=>satelliteCore.createSatelliteConnectStore({...n}),[]);return i({initializeAutoConnect:()=>o.getState().initializeAutoConnect(t??!1)}),jsxRuntime.jsx(r.Provider,{value:o,children:e})}exports.a=r;exports.b=P;exports.c=i;exports.d=b;//# sourceMappingURL=chunk-23IZMVDP.cjs.map
2
- //# sourceMappingURL=chunk-23IZMVDP.cjs.map
@@ -1 +0,0 @@
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":"2JAUO,IAAMA,CAAAA,CAAwBC,mBAAAA,CACnC,IACF,CAAA,CAqBaC,CAAAA,CACXC,CAAAA,EACM,CAEN,IAAMC,CAAAA,CAAQC,gBAAAA,CAAWL,CAAqB,EAG9C,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,CAAA,CACqB,SAAY,CAC7C,GAAI,CACF,MAAMF,CAAAA,GACR,CAAA,MAASG,CAAAA,CAAO,CAAA,CAEOF,CAAAA,GAAaG,CAAAA,EAAa,QAAQ,KAAA,CAAM,oCAAA,CAAsCA,CAAC,CAAA,CAAA,EACvFD,CAAc,EAC7B,CACF,CAAA,IAGF,CAAA,CAAG,EAAE,EACP,ECLO,SAASE,CAAAA,CAAyB,CAAE,QAAA,CAAAC,CAAAA,CAAU,WAAA,CAAAC,CAAAA,CAAa,GAAGC,CAAW,EAAkC,CAEhH,IAAMZ,CAAAA,CAAQa,aAAAA,CAAQ,IACbC,yCAAAA,CAAmD,CACxD,GAAGF,CACL,CAAC,CAAA,CAEA,EAAE,CAAA,CAEL,OAAAT,CAAAA,CAAyB,CACvB,sBAAuB,IAAMH,CAAAA,CAAM,QAAA,EAAS,CAAE,qBAAA,CAAsBW,CAAAA,EAAe,CAAA,CAAK,CAC1F,CAAC,CAAA,CAEMI,cAAAA,CAACnB,CAAAA,CAAsB,QAAA,CAAtB,CAA+B,KAAA,CAAOI,CAAAA,CAAQ,QAAA,CAAAU,EAAS,CACjE","file":"chunk-23IZMVDP.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 { 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 useInitializeAutoConnect({\n initializeAutoConnect: () => store.getState().initializeAutoConnect(autoConnect ?? false),\n });\n\n return <SatelliteStoreContext.Provider value={store}>{children}</SatelliteStoreContext.Provider>;\n}\n"]}
@@ -1,2 +0,0 @@
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 r=createContext(null),P=e=>{let t=useContext(r);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 b({children:e,autoConnect:t,...n}){let o=useMemo(()=>createSatelliteConnectStore({...n}),[]);return i({initializeAutoConnect:()=>o.getState().initializeAutoConnect(t??!1)}),jsx(r.Provider,{value:o,children:e})}export{r as a,P as b,i as c,b as d};//# sourceMappingURL=chunk-4RWO4WUN.js.map
2
- //# sourceMappingURL=chunk-4RWO4WUN.js.map
@@ -1 +0,0 @@
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":"mMAUO,IAAMA,CAAAA,CAAwBC,aAAAA,CACnC,IACF,CAAA,CAqBaC,CAAAA,CACXC,CAAAA,EACM,CAEN,IAAMC,CAAAA,CAAQC,UAAAA,CAAWL,CAAqB,EAG9C,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,CAAA,CACqB,SAAY,CAC7C,GAAI,CACF,MAAMF,CAAAA,GACR,CAAA,MAASG,CAAAA,CAAO,CAAA,CAEOF,CAAAA,GAAaG,CAAAA,EAAa,QAAQ,KAAA,CAAM,oCAAA,CAAsCA,CAAC,CAAA,CAAA,EACvFD,CAAc,EAC7B,CACF,CAAA,IAGF,CAAA,CAAG,EAAE,EACP,ECLO,SAASE,CAAAA,CAAyB,CAAE,QAAA,CAAAC,CAAAA,CAAU,WAAA,CAAAC,CAAAA,CAAa,GAAGC,CAAW,EAAkC,CAEhH,IAAMZ,CAAAA,CAAQa,OAAAA,CAAQ,IACbC,2BAAAA,CAAmD,CACxD,GAAGF,CACL,CAAC,CAAA,CAEA,EAAE,CAAA,CAEL,OAAAT,CAAAA,CAAyB,CACvB,sBAAuB,IAAMH,CAAAA,CAAM,QAAA,EAAS,CAAE,qBAAA,CAAsBW,CAAAA,EAAe,CAAA,CAAK,CAC1F,CAAC,CAAA,CAEMI,GAAAA,CAACnB,CAAAA,CAAsB,QAAA,CAAtB,CAA+B,KAAA,CAAOI,CAAAA,CAAQ,QAAA,CAAAU,EAAS,CACjE","file":"chunk-4RWO4WUN.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 { 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 useInitializeAutoConnect({\n initializeAutoConnect: () => store.getState().initializeAutoConnect(autoConnect ?? false),\n });\n\n return <SatelliteStoreContext.Provider value={store}>{children}</SatelliteStoreContext.Provider>;\n}\n"]}