import { Avatar, Button, Flex, HStack, Icon, Text } from "@chakra-ui/react"; import { PublicKey } from "@solana/web3.js"; import { SplTokenBonding } from "@strata-foundation/spl-token-bonding"; import { ITokenWithMetaAndAccount } from "@strata-foundation/spl-token-collective"; import { useOwnedAmount } from "../../hooks/bondingPricing"; import { useErrorHandler } from "../../hooks/useErrorHandler"; import { usePriceInUsd } from "../../hooks/usePriceInUsd"; import { useStrataSdks } from "../../hooks/useStrataSdks"; import { useTwWrappedSolMint } from "../../hooks/useTwWrappedSolMint"; import React from "react"; import { useAsyncCallback } from "react-async-hook"; import { RiCoinLine } from "react-icons/ri"; async function unwrapTwSol( tokenBondingSdk: SplTokenBonding | undefined, account: PublicKey | undefined ): Promise { if (tokenBondingSdk) { await tokenBondingSdk.sellBondingWrappedSol({ amount: 0, // ignored because of all all: true, source: account, }); } } export const TokenInfo = React.memo( ({ tokenWithMeta, onClick, highlighted, }: { highlighted?: boolean; tokenWithMeta: ITokenWithMetaAndAccount; onClick: (tokenWithMeta: ITokenWithMetaAndAccount) => void; }) => { const { metadata, image, account } = tokenWithMeta; const fiatPrice = usePriceInUsd(account?.mint); const ownedAmount = useOwnedAmount(account?.mint); const twSol = useTwWrappedSolMint(); const { tokenBondingSdk } = useStrataSdks(); const { execute: unwrap, loading, error } = useAsyncCallback(unwrapTwSol); const { handleErrors } = useErrorHandler(); handleErrors(error); return ( { e.stopPropagation(); e.preventDefault(); onClick(tokenWithMeta) }} alignItems="center" justify="space-between" justifyItems="center" _hover={{ opacity: "0.5", cursor: "pointer" }} borderColor={highlighted ? "indigo.500" : undefined} borderWidth={highlighted ? "1px" : undefined} borderRadius={highlighted ? "4px" : undefined} > {metadata?.data.name} {ownedAmount?.toFixed(2)} {metadata?.data.symbol} (~$ {fiatPrice && ownedAmount && (fiatPrice * ownedAmount).toFixed(2)} ) {twSol && account && twSol.equals(account.mint) && ( )} ); } );