import { Box, Button, Divider, Flex, Grid, Image, Spinner, Text, } from "@chakra-ui/react"; import truncate from "smart-truncate"; import { 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 = new providers.JsonRpcProvider( `https://rpc.walletconnect.com/v1/?chainId=eip155:1&projectId=${process.env.NEXT_PUBLIC_PROJECT_ID}` ); const avatar = await provider.getAvatar(address); const bigNumBalance = await provider.getBalance(address); setAvatar(avatar); setBalance(bigNumBalance.toString()); 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;