Skip to content

Commit

Permalink
Merge branch 'main' into upgrade-to-pnpm-10.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
gregnazario authored Feb 5, 2025
2 parents be361d1 + 009cb32 commit 8bd0a04
Showing 1 changed file with 23 additions and 2 deletions.
25 changes: 23 additions & 2 deletions src/pages/Transaction/Tabs/Components/CoinBalanceChangeTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ import GeneralTableHeaderCell from "../../../../components/Table/GeneralTableHea
import {assertNever} from "../../../../utils";
import HashButton, {HashType} from "../../../../components/HashButton";
import {BalanceChange} from "../../utils";
import CurrencyValue from "../../../../components/IndividualPageContent/ContentValue/CurrencyValue";
import CurrencyValue, {
getFormattedBalanceStr,
} from "../../../../components/IndividualPageContent/ContentValue/CurrencyValue";
import {
negativeColor,
primary,
Expand All @@ -15,6 +17,8 @@ import GeneralTableBody from "../../../../components/Table/GeneralTableBody";
import GeneralTableCell from "../../../../components/Table/GeneralTableCell";
import {VerifiedCoinCell} from "../../../../components/Table/VerifiedCell";
import {getLearnMoreTooltip} from "../../helpers";
import {ContentCopy} from "@mui/icons-material";
import StyledTooltip from "../../../../components/StyledTooltip";

type BalanceChangeCellProps = {
balanceChange: BalanceChange;
Expand Down Expand Up @@ -80,20 +84,37 @@ function AmountCell({balanceChange}: BalanceChangeCellProps) {
const isNegative = balanceChange.amount < 0;
const amount =
balanceChange.amount < 0 ? -balanceChange.amount : balanceChange.amount;
const [showCopied, setShowCopied] = React.useState(false);

const handleCopy = async () => {
const formattedValue = getFormattedBalanceStr(
amount.toString(),
balanceChange.asset.decimals,
);
await navigator.clipboard.writeText(
`${isNegative ? "-" : ""}${formattedValue}`,
);
setShowCopied(true);
setTimeout(() => setShowCopied(false), 1500);
};

return (
<GeneralTableCell
sx={{
textAlign: "right",
color: isNegative ? negativeColor : primary[600],
}}
onClick={handleCopy}
>
{isNegative ? "-" : "+"}
<CurrencyValue
amount={amount.toString()}
currencyCode={balanceChange.asset.symbol}
decimals={balanceChange.asset.decimals}
/>
/>{" "}
<StyledTooltip open={showCopied} title="Copied!" placement="top">
<ContentCopy style={{height: "1rem", width: "1.25rem"}} />
</StyledTooltip>
</GeneralTableCell>
);
}
Expand Down

0 comments on commit 8bd0a04

Please sign in to comment.