import React, { useState } from 'react'; import { useSoulStream } from '../contexts/SoulStreamContext'; interface ChainSwitcherProps { onSwitch?: (chainId: string, success: boolean) => void; className?: string; } /** * A component that allows users to switch between configured chains */ const ChainSwitcher: React.FC = ({ onSwitch, className = '' }) => { const { chains, switchChain, currentChainId } = useSoulStream(); const [isLoading, setIsLoading] = useState(false); const [error, setError] = useState(null); const handleSwitchChain = async (chainId: string) => { if (chainId === currentChainId) return; try { setIsLoading(true); setError(null); const success = await switchChain(chainId); if (success) { if (onSwitch) { onSwitch(chainId, true); } } else { setError(`Failed to switch to chain ${chainId}`); if (onSwitch) { onSwitch(chainId, false); } } } catch (err) { console.error('Error switching chain:', err); setError('Error switching chain'); if (onSwitch) { onSwitch(chainId, false); } } finally { setIsLoading(false); } }; if (!chains.chainA && !chains.chainB) { return
No chains configured
; } return (

Network

{chains.chainA && ( )} {chains.chainB && ( )}
{isLoading &&
Switching networks...
} {error &&
{error}
}
); }; export default ChainSwitcher;