otterscan/src/components/TransactionValue.tsx

42 lines
1.0 KiB
TypeScript
Raw Normal View History

2021-07-01 18:21:40 +00:00
import React from "react";
import { BigNumber } from "@ethersproject/bignumber";
2021-07-01 18:21:40 +00:00
import { formatValue } from "./formatter";
type TransactionValueProps = {
value: BigNumber;
decimals?: number;
2021-07-03 22:14:03 +00:00
hideUnit?: boolean;
2022-02-19 18:25:37 +00:00
unitName?: string;
2021-07-01 18:21:40 +00:00
};
/**
* Standard component for displaying balances. It:
*
* - Commify non-decimal parts, i.e., 1,000,000.00
* - Light gray absolute zero values
* - Cut out decimal part is it is 0 to reduce UI clutter, i.e., show
* 123 instead of 123.00
*
* TODO: remove duplication with FormattedBalance
*/
2021-07-01 18:21:40 +00:00
const TransactionValue: React.FC<TransactionValueProps> = ({
value,
decimals = 18,
2021-07-03 22:14:03 +00:00
hideUnit,
2022-02-19 18:25:37 +00:00
unitName = "ETH",
2021-07-01 18:21:40 +00:00
}) => {
const formattedValue = formatValue(value, decimals);
return (
<span
className={`text-sm ${value.isZero() ? "text-gray-400" : ""}`}
2022-02-19 18:25:37 +00:00
title={`${formattedValue} ${unitName}`}
2021-07-01 18:21:40 +00:00
>
2021-07-03 22:14:03 +00:00
<span className={`font-balance`}>{formattedValue}</span>
2022-02-19 18:25:37 +00:00
{!hideUnit && ` ${unitName}`}
2021-07-01 18:21:40 +00:00
</span>
);
};
export default React.memo(TransactionValue);