import { useEffect, useRef } from 'react'; import useTransactionStore from '@/helpers/store_transaction'; import ModelViewer from '@metamask/logo'; import Image from 'next/image'; import Card from '@components/Card'; import ConnectButton from '@components/ConnectButton'; import EthereumIcon from '@components/icons/EthereumIcon'; import Link from '@components/Link'; import LoadingSpinner from '@components/LoadingSpinner'; import PrimaryButton from '@components/PrimaryButton'; import styles from '@styles/modules/ConnectWallet.module.css'; interface ConnectWalletProps { isLoading: boolean; displayError: boolean; handleConnectWallet: () => void; } // Need any here as MetaMask library doesn't supply types // eslint-disable-next-line @typescript-eslint/no-explicit-any let viewer: any; const ConnectWallet = ({ isLoading, displayError, handleConnectWallet, }: ConnectWalletProps) => { const walletAddress = useTransactionStore((state) => state.walletAddress); const walletBalance = useTransactionStore((state) => state.walletBalance); const logoContainer = useRef(null); useEffect(() => { if (!logoContainer.current || viewer) return; viewer = ModelViewer({ pxNotRatio: true, width: 200, height: 160, followMouse: false, slowDrift: false, }); // add viewer to DOM const container = logoContainer.current as HTMLDivElement; container.appendChild(viewer.container); // const container = document.getElementById('logo-container'); // container?.appendChild(viewer.container); // look at something on the page viewer.lookAt({ x: 100, y: 100, }); // enable mouse follow viewer.setFollowMouse(true); // deallocate nicely viewer.stopAnimation(); }, []); return ( <>
{walletBalance != null ? ( <>

Connected to MetaMask

MetaMask Fox

Balance:

{parseFloat(walletBalance.toFixed(4))}

Next ) : ( <> {/* */} MetaMask Fox

Connect Wallet

Add some testnet ETH {' '} and connect your MetaMask{' '} wallet to start sending transactions

)}
{!walletAddress && ( {isLoading ? : 'Connect Wallet'} )} {displayError && (

We couldn't detect your wallet. Please click{' '} here {' '} to download the MetaMask extension and set up a wallet.

)} ); }; export default ConnectWallet;