import { Box, Button, Divider, IconButton, Paper, SvgIcon, Typography, useMediaQuery, useTheme, } from "@mui/material"; import { styled } from '@mui/material/styles'; import CloseIcon from '@mui/icons-material/Close'; import LoopIcon from '@mui/icons-material/Loop'; import { ReactElement, useState, useEffect } from "react"; import { useNavigate, createSearchParams } from "react-router-dom"; import GhostStyledIcon from "../../Icon/GhostIcon"; import { Tokens, useWallet } from "./Token"; import { PrimaryButton, SecondaryButton } from "../../Button"; import ArrowUpIcon from "../../../assets/icons/arrow-up.svg?react"; import { formatCurrency, shorten } from "../../../helpers"; import { DecimalBigNumber } from "../../../helpers/DecimalBigNumber"; import { RESERVE_ADDRESSES, FTSO_ADDRESSES } from "../../../constants/addresses"; import { useAccount, useDisconnect, useSwitchChain } from "wagmi"; const DisconnectButton = ({ onClose }) => { const { disconnect } = useDisconnect(); return ( { disconnect(); onClose(); }} variant="contained" fullWidth > Disconnect ); }; const CloseButton = styled(IconButton)(theme => ({ root: { ...theme.overrides?.MuiButton?.containedSecondary, width: "30px", height: "30px", }, })); const WalletTotalValue = ({ address, tokens }) => { const ghstPrice = tokens.ghst.price; const [currency, setCurrency] = useState("USD"); const [topHovered, setTopHovered] = useState(false); const walletTotalValueUSD = Object.values(tokens).reduce( (totalValue, token) => totalValue.add(token.balance.mul(token.price)), new DecimalBigNumber(0n, 0), ); const walletValue = { USD: walletTotalValueUSD ? walletTotalValueUSD : new DecimalBigNumber(0n, 0), GHST: walletTotalValueUSD && ghstPrice.gt(new DecimalBigNumber(0, 0)) ? walletTotalValueUSD.div(ghstPrice) : new DecimalBigNumber(0n, 0), }; return ( setCurrency(currency === "USD" ? "GHST" : "USD")} onMouseEnter={() => setTopHovered(true)} onMouseLeave={() => setTopHovered(false)} > MY WALLET {shorten(address)} {formatCurrency(walletValue[currency], 2, currency === "USD" ? "USD" : "👻" )} ); }; function InitialWalletView({ isWalletOpen, address, chainId, onClose }) { const theme = useTheme(); const navigate = useNavigate(); const tokens = useWallet(chainId, address); const { chains } = useSwitchChain(); const onBtnClick = (dexName, from, to) => { navigate({ pathname: `${chains.find(chain => chain.id === chainId).name.toLowerCase()}/dex/` + dexName, search: createSearchParams({ pool: true, from: from, to: to, }).toString() }) onClose(); } useEffect(() => { if (isWalletOpen) { Object.values(tokens ?? {}).forEach(token => token.refetch()); } }, [isWalletOpen, tokens]) return ( ); } export default InitialWalletView;