import { Box, Button, Divider, Flex, Grid, Image, Spinner, Text, } from "@chakra-ui/react"; import truncate from "smart-truncate"; import { BigNumber, providers } from "ethers"; import { useCallback, useEffect, useState } from "react"; const SignedInView: React.FC<{ address: string }> = ({ address }) => { const [balance, setBalance] = useState(); const [avatar, setAvatar] = useState(); const [isLoading, setLoading] = useState(false); useEffect(() => { const innerEffect = async (address: string) => { setLoading(true); const provider = providers.getDefaultProvider(); const avatar = await provider.getAvatar(address); const balance = await provider.getBalance(address); setAvatar(avatar); setBalance(balance.toNumber()); setLoading(false); }; if (address) { innerEffect(address); } }, [setBalance, address]); const onSignOut = useCallback(() => { window.location.reload(); }, []); return ( {isLoading ? ( ) : ( avatar && avatar )} Connected {truncate(address, 12, { position: 7 })} Balance {isLoading ? ( ) : ( ETH {balance} ETH )} ); }; export default SignedInView;