2022-04-08 01:48:59 +00:00
|
|
|
import React, { useContext } from "react";
|
2021-07-06 00:08:58 +00:00
|
|
|
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
|
2021-08-08 06:51:21 +00:00
|
|
|
import { faCaretRight } from "@fortawesome/free-solid-svg-icons/faCaretRight";
|
2022-04-06 03:27:35 +00:00
|
|
|
import { faSackDollar } from "@fortawesome/free-solid-svg-icons/faSackDollar";
|
2021-11-07 11:56:12 +00:00
|
|
|
import TransactionAddress from "./components/TransactionAddress";
|
2021-07-20 02:33:19 +00:00
|
|
|
import ValueHighlighter from "./components/ValueHighlighter";
|
2021-07-06 00:08:58 +00:00
|
|
|
import FormattedBalance from "./components/FormattedBalance";
|
2022-04-08 01:48:59 +00:00
|
|
|
import USDAmount from "./components/USDAmount";
|
|
|
|
import { RuntimeContext } from "./useRuntime";
|
|
|
|
import { useBlockNumberContext } from "./useBlockTagContext";
|
2022-08-23 20:29:54 +00:00
|
|
|
import { useTokenMetadata } from "./useErigonHooks";
|
2022-04-08 01:48:59 +00:00
|
|
|
import { useTokenUSDOracle } from "./usePriceOracle";
|
2022-08-23 20:29:54 +00:00
|
|
|
import { AddressContext, TokenTransfer } from "./types";
|
2021-07-06 00:08:58 +00:00
|
|
|
|
|
|
|
type TokenTransferItemProps = {
|
|
|
|
t: TokenTransfer;
|
|
|
|
};
|
|
|
|
|
2022-08-23 20:29:54 +00:00
|
|
|
const TokenTransferItem: React.FC<TokenTransferItemProps> = ({ t }) => {
|
2022-04-08 01:48:59 +00:00
|
|
|
const { provider } = useContext(RuntimeContext);
|
|
|
|
const blockNumber = useBlockNumberContext();
|
|
|
|
const [quote, decimals] = useTokenUSDOracle(provider, blockNumber, t.token);
|
2022-08-23 20:29:54 +00:00
|
|
|
const tokenMeta = useTokenMetadata(provider, t.token);
|
2022-04-08 01:48:59 +00:00
|
|
|
|
2022-03-02 09:29:59 +00:00
|
|
|
return (
|
|
|
|
<div className="flex items-baseline space-x-2 px-2 py-1 truncate hover:bg-gray-100">
|
2022-04-06 03:27:35 +00:00
|
|
|
<div className="grid grid-cols-4 gap-x-1 w-full items-baseline">
|
|
|
|
<div className="flex items-baseline space-x-1">
|
2022-03-02 09:29:59 +00:00
|
|
|
<TransactionAddress
|
|
|
|
address={t.from}
|
|
|
|
addressCtx={AddressContext.FROM}
|
2022-03-24 18:20:54 +00:00
|
|
|
showCodeIndicator
|
2022-03-02 09:29:59 +00:00
|
|
|
/>
|
|
|
|
</div>
|
2022-04-06 03:27:35 +00:00
|
|
|
<div className="flex items-baseline space-x-1">
|
|
|
|
<span className="text-gray-500">
|
|
|
|
<FontAwesomeIcon icon={faCaretRight} size="1x" />
|
|
|
|
</span>
|
2022-03-02 09:29:59 +00:00
|
|
|
<TransactionAddress
|
|
|
|
address={t.to}
|
|
|
|
addressCtx={AddressContext.TO}
|
2022-03-24 18:20:54 +00:00
|
|
|
showCodeIndicator
|
2022-03-02 09:29:59 +00:00
|
|
|
/>
|
|
|
|
</div>
|
2022-04-06 03:27:35 +00:00
|
|
|
<div className="col-span-2 flex items-baseline space-x-1">
|
|
|
|
<span className="text-gray-500">
|
|
|
|
<FontAwesomeIcon icon={faSackDollar} size="1x" />
|
|
|
|
</span>
|
2022-03-02 09:29:59 +00:00
|
|
|
<span>
|
|
|
|
<ValueHighlighter value={t.value}>
|
|
|
|
<FormattedBalance
|
|
|
|
value={t.value}
|
|
|
|
decimals={tokenMeta?.decimals ?? 0}
|
|
|
|
/>
|
|
|
|
</ValueHighlighter>
|
|
|
|
</span>
|
2022-08-09 23:04:15 +00:00
|
|
|
<TransactionAddress address={t.token} />
|
2022-04-08 01:48:59 +00:00
|
|
|
{tokenMeta && quote !== undefined && decimals !== undefined && (
|
|
|
|
<span className="px-2 border-gray-200 border rounded-lg bg-gray-100 text-gray-600">
|
|
|
|
<USDAmount
|
|
|
|
amount={t.value}
|
|
|
|
amountDecimals={tokenMeta.decimals}
|
|
|
|
quote={quote}
|
|
|
|
quoteDecimals={decimals}
|
|
|
|
/>
|
|
|
|
</span>
|
|
|
|
)}
|
2022-03-02 09:29:59 +00:00
|
|
|
</div>
|
2021-07-06 05:00:54 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
2022-03-02 09:29:59 +00:00
|
|
|
);
|
|
|
|
};
|
2021-07-06 00:08:58 +00:00
|
|
|
|
|
|
|
export default React.memo(TokenTransferItem);
|