import { useEffect, useState } from 'react' import { useDispatch } from 'react-redux' import { useAccount } from 'wagmi' import { switchChain } from '@wagmi/core' import { LoaderIcon } from 'react-hot-toast' import { ConnectButton } from '@rainbow-me/rainbowkit' import { useTranslations } from 'next-intl' import { CHAINS_BY_ID } from '@/constants/chains' import { setFromChainId } from '@/slices/bridge/reducer' import { getNetworkButtonBorderHover, getNetworkHover } from '@/styles/chains' import { joinClassNames } from '@/utils/joinClassNames' import { wagmiConfig } from '@/wagmiConfig' const Indicator = ({ className }) => ( ) export const ConnectedIndicator = () => { const classNames = { flex: 'flex items-center gap-2', space: 'px-3 py-1 rounded-full', hover: 'hover:opacity-80', font: 'text-sm', } const t = useTranslations('Wallet') return ( ) } export const ConnectToNetworkButton = ({ chainId }: { chainId: number }) => { const [isConnecting, setIsConnecting] = useState(false) const dispatch = useDispatch() const chain = CHAINS_BY_ID[chainId] const t = useTranslations('Wallet') function scrollToTop(): void { window.scrollTo({ top: 0, behavior: 'smooth' }) } const handleConnectNetwork: () => Promise = async () => { setIsConnecting(true) try { await switchChain(wagmiConfig, { chainId }).then((success) => { success && dispatch(setFromChainId(chainId)) scrollToTop() }) } catch (error) { error && setIsConnecting(false) } } const classNames = { flex: 'flex items-center gap-2', space: 'px-3 py-1 rounded-full', border: 'border border-transparent', font: 'text-sm', bgHover: getNetworkHover(chain?.color), borderHover: getNetworkButtonBorderHover(chain?.color), active: 'hover:active:opacity-80', } return ( ) } export function ConnectWalletButton() { const [clientReady, setClientReady] = useState(false) const { address } = useAccount() const t = useTranslations('Wallet') useEffect(() => { setClientReady(true) }, []) const classNames = { flex: 'flex items-center gap-2', space: 'px-3 py-1 rounded-full', border: 'border border-transparent', hover: 'hover:bg-fuchsia-50 hover:border-fuchsia-500 hover:dark:bg-fuchsia-950', font: 'text-sm', active: 'active:opacity-80', } return (
{clientReady && ( {({ account, chain, openConnectModal, mounted, openChainModal }) => { return ( <> {(() => { if (!mounted || !account || !chain || !address) { return ( ) } })()} ) }} )}
) }