2022-03-02 09:46:43 +00:00
|
|
|
import React, { useContext } from "react";
|
2022-04-11 17:56:16 +00:00
|
|
|
import { BigNumber } from "@ethersproject/bignumber";
|
2021-08-08 22:49:45 +00:00
|
|
|
import { formatEther } from "@ethersproject/units";
|
2021-07-05 03:03:01 +00:00
|
|
|
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
|
2021-08-08 06:51:21 +00:00
|
|
|
import { faAngleRight } from "@fortawesome/free-solid-svg-icons/faAngleRight";
|
2022-04-06 04:15:40 +00:00
|
|
|
import { faCaretRight } from "@fortawesome/free-solid-svg-icons/faCaretRight";
|
|
|
|
import { faSackDollar } from "@fortawesome/free-solid-svg-icons/faSackDollar";
|
2021-07-14 07:43:58 +00:00
|
|
|
import AddressHighlighter from "./AddressHighlighter";
|
2021-07-19 03:38:38 +00:00
|
|
|
import DecoratedAddressLink from "./DecoratedAddressLink";
|
2022-04-11 17:56:16 +00:00
|
|
|
import USDAmount from "./USDAmount";
|
2022-03-02 09:46:43 +00:00
|
|
|
import { RuntimeContext } from "../useRuntime";
|
|
|
|
import { useHasCode } from "../useErigonHooks";
|
2022-03-26 00:38:12 +00:00
|
|
|
import { useChainInfo } from "../useChainInfo";
|
2021-07-21 19:06:51 +00:00
|
|
|
import { TransactionData, InternalOperation } from "../types";
|
2021-07-05 03:03:01 +00:00
|
|
|
|
|
|
|
type InternalTransferProps = {
|
|
|
|
txData: TransactionData;
|
2021-07-21 19:06:51 +00:00
|
|
|
internalOp: InternalOperation;
|
2022-04-11 17:56:16 +00:00
|
|
|
// TODO: migrate all this logic to SWR
|
|
|
|
ethUSDPrice: BigNumber | undefined;
|
2021-07-05 03:03:01 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
const InternalTransfer: React.FC<InternalTransferProps> = ({
|
|
|
|
txData,
|
2021-07-21 19:06:51 +00:00
|
|
|
internalOp,
|
2022-04-11 17:56:16 +00:00
|
|
|
ethUSDPrice,
|
2021-07-05 03:03:01 +00:00
|
|
|
}) => {
|
2022-04-02 17:56:36 +00:00
|
|
|
const {
|
2022-04-11 17:56:16 +00:00
|
|
|
nativeCurrency: { symbol, decimals },
|
2022-04-02 17:56:36 +00:00
|
|
|
} = useChainInfo();
|
2021-07-05 03:03:01 +00:00
|
|
|
const fromMiner =
|
2021-09-04 06:19:42 +00:00
|
|
|
txData.confirmedData?.miner !== undefined &&
|
|
|
|
internalOp.from === txData.confirmedData.miner;
|
|
|
|
const toMiner =
|
|
|
|
txData.confirmedData?.miner !== undefined &&
|
|
|
|
internalOp.to === txData.confirmedData.miner;
|
2021-07-05 03:03:01 +00:00
|
|
|
|
2022-03-02 09:46:43 +00:00
|
|
|
const { provider } = useContext(RuntimeContext);
|
|
|
|
const fromHasCode = useHasCode(
|
|
|
|
provider,
|
|
|
|
internalOp.from,
|
|
|
|
txData.confirmedData ? txData.confirmedData.blockNumber - 1 : undefined
|
|
|
|
);
|
|
|
|
const toHasCode = useHasCode(
|
|
|
|
provider,
|
|
|
|
internalOp.to,
|
|
|
|
txData.confirmedData ? txData.confirmedData.blockNumber - 1 : undefined
|
|
|
|
);
|
|
|
|
|
2021-07-05 03:03:01 +00:00
|
|
|
return (
|
2022-04-06 04:15:40 +00:00
|
|
|
<div className="flex items-baseline space-x-1 truncate">
|
|
|
|
<div className="grid grid-cols-6 gap-x-1 w-full items-baseline">
|
|
|
|
<div className="col-span-2 flex items-baseline space-x-1">
|
|
|
|
<span className="text-gray-500">
|
|
|
|
<FontAwesomeIcon icon={faAngleRight} size="1x" /> TRANSFER
|
|
|
|
</span>
|
|
|
|
<div className="flex items-baseline truncate">
|
|
|
|
<AddressHighlighter address={internalOp.from}>
|
|
|
|
<div
|
|
|
|
className={`flex items-baseline space-x-1 ${
|
|
|
|
fromMiner ? "rounded px-2 py-1 bg-yellow-100" : ""
|
|
|
|
}`}
|
|
|
|
>
|
|
|
|
<DecoratedAddressLink
|
|
|
|
address={internalOp.from}
|
|
|
|
miner={fromMiner}
|
|
|
|
txFrom={internalOp.from === txData.from}
|
|
|
|
txTo={internalOp.from === txData.to}
|
|
|
|
eoa={fromHasCode === undefined ? undefined : !fromHasCode}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</AddressHighlighter>
|
2021-07-14 18:35:53 +00:00
|
|
|
</div>
|
2022-04-06 04:15:40 +00:00
|
|
|
</div>
|
|
|
|
<div className="col-span-2 flex items-baseline space-x-1">
|
|
|
|
<span className="text-gray-500">
|
|
|
|
<FontAwesomeIcon icon={faCaretRight} size="1x" />
|
|
|
|
</span>
|
|
|
|
<AddressHighlighter address={internalOp.to}>
|
|
|
|
<div
|
|
|
|
className={`flex items-baseline space-x-1 ${
|
|
|
|
toMiner ? "rounded px-2 py-1 bg-yellow-100" : ""
|
|
|
|
}`}
|
|
|
|
>
|
|
|
|
<DecoratedAddressLink
|
|
|
|
address={internalOp.to}
|
|
|
|
miner={toMiner}
|
|
|
|
txFrom={internalOp.to === txData.from}
|
|
|
|
txTo={internalOp.to === txData.to}
|
|
|
|
eoa={toHasCode === undefined ? undefined : !toHasCode}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</AddressHighlighter>
|
|
|
|
</div>
|
|
|
|
<div className="col-span-2 flex items-baseline space-x-1">
|
|
|
|
<span className="text-gray-500">
|
|
|
|
<FontAwesomeIcon icon={faSackDollar} size="1x" />
|
|
|
|
</span>
|
|
|
|
<span>
|
|
|
|
{formatEther(internalOp.value)} {symbol}
|
|
|
|
</span>
|
2022-04-11 17:56:16 +00:00
|
|
|
{ethUSDPrice && (
|
|
|
|
<span className="px-2 border-gray-200 border rounded-lg bg-gray-100 text-gray-600">
|
|
|
|
<USDAmount
|
|
|
|
amount={internalOp.value}
|
|
|
|
amountDecimals={decimals}
|
|
|
|
quote={ethUSDPrice}
|
|
|
|
// TODO: migrate to SWR and standardize this magic number
|
|
|
|
quoteDecimals={8}
|
|
|
|
/>
|
|
|
|
</span>
|
|
|
|
)}
|
2022-04-06 04:15:40 +00:00
|
|
|
</div>
|
2021-07-14 18:35:53 +00:00
|
|
|
</div>
|
2021-07-05 03:03:01 +00:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2021-11-18 18:51:08 +00:00
|
|
|
export default InternalTransfer;
|