import { observer } from "mobx-react-lite"; import styled from "styled-components"; import { useEffect } from "react"; import { LogoutIcon } from "../icons/logout"; import { openBridge, openConnector } from "../router"; import { HotConnector } from "../../HotConnector"; import { formatter } from "../../omni/utils"; import { OmniToken } from "../../omni/config"; import { tokens } from "../../omni/tokens"; import Popup from "../Popup"; import { ImageView, TokenCard } from "./TokenCard"; import ExchangeIcon from "../icons/exchange"; export const Profile = observer(({ hot, onClose }: { hot: HotConnector; onClose: () => void }) => { let totalBalance = 0; const tokensList = hot.wallets .flatMap((wallet) => { return tokens.list.map((token) => ({ token, wallet, balance: hot.balance(wallet, token) })); }) .sort((a, b) => { const balanceA = a.token.float(a.balance) * a.token.usd; const balanceB = b.token.float(b.balance) * b.token.usd; return balanceB - balanceA; }) .map(({ token, wallet, balance }) => { if (token.float(balance) < 0.000001) return null; totalBalance += token.float(balance) * token.usd; return { chain: token.chain, component: ( { if (token.chain === -4) hot.withdraw(token.address as OmniToken, +token.float(balance).toFixed(6), { sender: wallet }); else openBridge(hot, { title: "Exchange", sender: wallet, from: token }); }} key={`${wallet.type}:${wallet.address}:${token.id}`} wallet={wallet} token={token} hot={hot} /> ), }; }); useEffect(() => { if (hot.wallets.length > 0) return; onClose(); }, [hot.wallets.length]); return (
{hot.wallets.map((wallet) => ( wallet.disconnect()}>
{formatter.truncateAddress(wallet.address, 8)}
))} {hot.wallets.length < 6 && ( openConnector(hot)}> Add wallet )}
${formatter.amount(totalBalance)} (onClose(), openBridge(hot, { title: "Exchange" }))}>
{tokensList.filter((t) => t != null && t.chain === -4).length > 0 && (

Tokens to withdraw

{tokensList.filter((t) => t != null && t.chain === -4).map((t) => t?.component)}
)} {tokensList.filter((t) => t != null && t.chain !== -4).length > 0 && ( {/* Tokens to exchange */} {tokensList.filter((t) => t != null && t.chain !== -4).map((t) => t?.component)} )}
); }); const ExchangeButton = styled.button` display: flex; align-items: center; gap: 8px; cursor: pointer; outline: none; border: none; background: transparent; padding: 8px; border-radius: 24px; transition: background 0.2s ease-in-out; &:hover { background: rgba(255, 255, 255, 0.1); } `; const TokenCards = styled.div` display: flex; flex-direction: column; gap: 8px; width: 100%; `; const WalletCard = styled.div` display: flex; align-items: center; gap: 8px; border-radius: 24px; border: 1px solid rgba(255, 255, 255, 0.1); padding: 6px; padding-left: 8px; padding-right: 12px; background: #1a1a1a; cursor: pointer; transition: background 0.2s ease-in-out; &:hover { background: rgba(255, 255, 255, 0.04); } `; const BalanceCard = styled.h2` font-size: 48px; font-weight: 600; color: #fff; `;