import React, { useEffect, useState } from "react"; import { Popover } from "@headlessui/react"; import { toast } from "react-toastify"; import Image from "next/image"; import { formatWalletAddress } from "utils/formatters"; import ConnectModal from "./ConnectModal"; import useWalletStore from "stores/useWalletStore"; import useInjectiveBalance from "hooks/useInjectiveBalance"; const WalletPopover = ({ children }: { children: React.ReactNode }) => { const address = useWalletStore((state) => state.address); const actions = useWalletStore((state) => state.actions); const { data } = useInjectiveBalance(); return ( {children} INJ{" "} {data?.toFixed(2)} actions.setAddress("")} > Disconnect {address} { navigator.clipboard.writeText(address).then(() => { toast.success("Address copied to your clipboard"); }); }} > Copy Address ); }; const Wallet = () => { const [showConnectModal, setShowConnectModal] = useState(false); const [hasHydrated, setHasHydrated] = useState(false); const address = useWalletStore((state) => state.address); // avoid server-client hydration mismatch useEffect(() => { setHasHydrated(true); }, []); return ( <> {hasHydrated && address ? ( {formatWalletAddress(address)} ) : ( setShowConnectModal(true)} > Connect Wallet )} setShowConnectModal(false)} /> > ); }; export default Wallet;
INJ{" "} {data?.toFixed(2)}
{address}