Merge branch 'feature/swr-everything-2' into develop
This commit is contained in:
commit
f0c325cbf4
|
@ -21,7 +21,6 @@ import SourcifyLogo from "./sourcify/SourcifyLogo";
|
||||||
import AddressTransactionResults from "./address/AddressTransactionResults";
|
import AddressTransactionResults from "./address/AddressTransactionResults";
|
||||||
import Contracts from "./address/Contracts";
|
import Contracts from "./address/Contracts";
|
||||||
import { RuntimeContext } from "./useRuntime";
|
import { RuntimeContext } from "./useRuntime";
|
||||||
import { useAppConfigContext } from "./useAppConfig";
|
|
||||||
import { useAddressOrENS } from "./useResolvedAddresses";
|
import { useAddressOrENS } from "./useResolvedAddresses";
|
||||||
import { useSourcifyMetadata } from "./sourcify/useSourcify";
|
import { useSourcifyMetadata } from "./sourcify/useSourcify";
|
||||||
import { ChecksummedAddress } from "./types";
|
import { ChecksummedAddress } from "./types";
|
||||||
|
@ -66,11 +65,9 @@ const Address: React.FC = () => {
|
||||||
}, [addressOrName, checksummedAddress, isENS]);
|
}, [addressOrName, checksummedAddress, isENS]);
|
||||||
|
|
||||||
const hasCode = useHasCode(provider, checksummedAddress, "latest");
|
const hasCode = useHasCode(provider, checksummedAddress, "latest");
|
||||||
const { sourcifySource } = useAppConfigContext();
|
|
||||||
const addressMetadata = useSourcifyMetadata(
|
const addressMetadata = useSourcifyMetadata(
|
||||||
hasCode ? checksummedAddress : undefined,
|
hasCode ? checksummedAddress : undefined,
|
||||||
provider?.network.chainId,
|
provider?.network.chainId
|
||||||
sourcifySource
|
|
||||||
);
|
);
|
||||||
|
|
||||||
const { network, faucets } = useChainInfo();
|
const { network, faucets } = useChainInfo();
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
import React, { useEffect, useMemo, useContext } from "react";
|
import React, { useEffect, useMemo, useContext } from "react";
|
||||||
import { useParams, NavLink } from "react-router-dom";
|
import { useParams, NavLink } from "react-router-dom";
|
||||||
import { BigNumber } from "@ethersproject/bignumber";
|
|
||||||
import { commify } from "@ethersproject/units";
|
import { commify } from "@ethersproject/units";
|
||||||
import { toUtf8String } from "@ethersproject/strings";
|
import { toUtf8String } from "@ethersproject/strings";
|
||||||
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
|
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
|
||||||
|
@ -12,13 +11,13 @@ import ContentFrame from "./ContentFrame";
|
||||||
import BlockNotFound from "./components/BlockNotFound";
|
import BlockNotFound from "./components/BlockNotFound";
|
||||||
import InfoRow from "./components/InfoRow";
|
import InfoRow from "./components/InfoRow";
|
||||||
import Timestamp from "./components/Timestamp";
|
import Timestamp from "./components/Timestamp";
|
||||||
|
import BlockReward from "./BlockReward";
|
||||||
import GasValue from "./components/GasValue";
|
import GasValue from "./components/GasValue";
|
||||||
import PercentageBar from "./components/PercentageBar";
|
import PercentageBar from "./components/PercentageBar";
|
||||||
import BlockLink from "./components/BlockLink";
|
import BlockLink from "./components/BlockLink";
|
||||||
import DecoratedAddressLink from "./components/DecoratedAddressLink";
|
import DecoratedAddressLink from "./components/DecoratedAddressLink";
|
||||||
import TransactionValue from "./components/TransactionValue";
|
import TransactionValue from "./components/TransactionValue";
|
||||||
import FormattedBalance from "./components/FormattedBalance";
|
import FormattedBalance from "./components/FormattedBalance";
|
||||||
import ETH2USDValue from "./components/ETH2USDValue";
|
|
||||||
import USDValue from "./components/USDValue";
|
import USDValue from "./components/USDValue";
|
||||||
import HexValue from "./components/HexValue";
|
import HexValue from "./components/HexValue";
|
||||||
import { RuntimeContext } from "./useRuntime";
|
import { RuntimeContext } from "./useRuntime";
|
||||||
|
@ -55,7 +54,6 @@ const Block: React.FC = () => {
|
||||||
}, [block]);
|
}, [block]);
|
||||||
const burntFees =
|
const burntFees =
|
||||||
block?.baseFeePerGas && block.baseFeePerGas.mul(block.gasUsed);
|
block?.baseFeePerGas && block.baseFeePerGas.mul(block.gasUsed);
|
||||||
const netFeeReward = block?.feeReward ?? BigNumber.from(0);
|
|
||||||
const gasUsedPerc =
|
const gasUsedPerc =
|
||||||
block && block.gasUsed.mul(10000).div(block.gasLimit).toNumber() / 100;
|
block && block.gasUsed.mul(10000).div(block.gasLimit).toNumber() / 100;
|
||||||
|
|
||||||
|
@ -100,25 +98,7 @@ const Block: React.FC = () => {
|
||||||
<DecoratedAddressLink address={block.miner} miner />
|
<DecoratedAddressLink address={block.miner} miner />
|
||||||
</InfoRow>
|
</InfoRow>
|
||||||
<InfoRow title="Block Reward">
|
<InfoRow title="Block Reward">
|
||||||
<TransactionValue value={block.blockReward.add(netFeeReward)} />
|
<BlockReward block={block} />
|
||||||
{!netFeeReward.isZero() && (
|
|
||||||
<>
|
|
||||||
{" "}
|
|
||||||
(<TransactionValue value={block.blockReward} hideUnit /> +{" "}
|
|
||||||
<TransactionValue value={netFeeReward} hideUnit />)
|
|
||||||
</>
|
|
||||||
)}
|
|
||||||
{blockETHUSDPrice && (
|
|
||||||
<>
|
|
||||||
{" "}
|
|
||||||
<span className="px-2 border-amber-200 border rounded-lg bg-amber-100 text-amber-600">
|
|
||||||
<ETH2USDValue
|
|
||||||
ethAmount={block.blockReward.add(netFeeReward)}
|
|
||||||
eth2USDValue={blockETHUSDPrice}
|
|
||||||
/>
|
|
||||||
</span>
|
|
||||||
</>
|
|
||||||
)}
|
|
||||||
</InfoRow>
|
</InfoRow>
|
||||||
<InfoRow title="Uncles Reward">
|
<InfoRow title="Uncles Reward">
|
||||||
<TransactionValue value={block.unclesReward} />
|
<TransactionValue value={block.unclesReward} />
|
||||||
|
|
|
@ -0,0 +1,47 @@
|
||||||
|
import React, { useContext } from "react";
|
||||||
|
import { BigNumber } from "@ethersproject/bignumber";
|
||||||
|
import TransactionValue from "./components/TransactionValue";
|
||||||
|
import FiatValue from "./components/FiatValue";
|
||||||
|
import { RuntimeContext } from "./useRuntime";
|
||||||
|
import { ExtendedBlock } from "./useErigonHooks";
|
||||||
|
import { useETHUSDOracle } from "./usePriceOracle";
|
||||||
|
|
||||||
|
type BlockRewardProps = {
|
||||||
|
block: ExtendedBlock;
|
||||||
|
};
|
||||||
|
|
||||||
|
const BlockReward: React.FC<BlockRewardProps> = ({ block }) => {
|
||||||
|
const { provider } = useContext(RuntimeContext);
|
||||||
|
const eth2USDValue = useETHUSDOracle(provider, block.number);
|
||||||
|
|
||||||
|
const netFeeReward = block?.feeReward ?? BigNumber.from(0);
|
||||||
|
const value = eth2USDValue
|
||||||
|
? block.blockReward
|
||||||
|
.add(netFeeReward)
|
||||||
|
.mul(eth2USDValue)
|
||||||
|
.div(10 ** 8)
|
||||||
|
: undefined;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<TransactionValue value={block.blockReward.add(netFeeReward)} />
|
||||||
|
{!netFeeReward.isZero() && (
|
||||||
|
<>
|
||||||
|
{" "}
|
||||||
|
(<TransactionValue value={block.blockReward} hideUnit /> +{" "}
|
||||||
|
<TransactionValue value={netFeeReward} hideUnit />)
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
{value && (
|
||||||
|
<>
|
||||||
|
{" "}
|
||||||
|
<span className="px-2 border-amber-200 border rounded-lg bg-amber-100 text-amber-600">
|
||||||
|
<FiatValue value={value} />
|
||||||
|
</span>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default BlockReward;
|
|
@ -40,7 +40,6 @@ const BlockTransactions: React.FC = () => {
|
||||||
<StandardFrame>
|
<StandardFrame>
|
||||||
<BlockTransactionHeader blockTag={blockNumber.toNumber()} />
|
<BlockTransactionHeader blockTag={blockNumber.toNumber()} />
|
||||||
<BlockTransactionResults
|
<BlockTransactionResults
|
||||||
blockTag={blockNumber.toNumber()}
|
|
||||||
page={txs}
|
page={txs}
|
||||||
total={totalTxs ?? 0}
|
total={totalTxs ?? 0}
|
||||||
pageNumber={pageNumber}
|
pageNumber={pageNumber}
|
||||||
|
|
|
@ -7,7 +7,7 @@ import { faQrcode } from "@fortawesome/free-solid-svg-icons/faQrcode";
|
||||||
import Logo from "./Logo";
|
import Logo from "./Logo";
|
||||||
import Timestamp from "./components/Timestamp";
|
import Timestamp from "./components/Timestamp";
|
||||||
import { RuntimeContext } from "./useRuntime";
|
import { RuntimeContext } from "./useRuntime";
|
||||||
import { useLatestBlock } from "./useLatestBlock";
|
import { useLatestBlockHeader } from "./useLatestBlock";
|
||||||
import { blockURL } from "./url";
|
import { blockURL } from "./url";
|
||||||
import { useGenericSearch } from "./search/search";
|
import { useGenericSearch } from "./search/search";
|
||||||
|
|
||||||
|
@ -17,7 +17,7 @@ const Home: React.FC = () => {
|
||||||
const { provider } = useContext(RuntimeContext);
|
const { provider } = useContext(RuntimeContext);
|
||||||
const [searchRef, handleChange, handleSubmit] = useGenericSearch();
|
const [searchRef, handleChange, handleSubmit] = useGenericSearch();
|
||||||
|
|
||||||
const latestBlock = useLatestBlock(provider);
|
const latestBlock = useLatestBlockHeader(provider);
|
||||||
const [isScanning, setScanning] = useState<boolean>(false);
|
const [isScanning, setScanning] = useState<boolean>(false);
|
||||||
|
|
||||||
document.title = "Home | Otterscan";
|
document.title = "Home | Otterscan";
|
||||||
|
|
|
@ -6,7 +6,7 @@ import { faGasPump } from "@fortawesome/free-solid-svg-icons/faGasPump";
|
||||||
import AggregatorV3Interface from "@chainlink/contracts/abi/v0.8/AggregatorV3Interface.json";
|
import AggregatorV3Interface from "@chainlink/contracts/abi/v0.8/AggregatorV3Interface.json";
|
||||||
import { RuntimeContext } from "./useRuntime";
|
import { RuntimeContext } from "./useRuntime";
|
||||||
import { formatValue } from "./components/formatter";
|
import { formatValue } from "./components/formatter";
|
||||||
import { useLatestBlock } from "./useLatestBlock";
|
import { useLatestBlockHeader } from "./useLatestBlock";
|
||||||
import { useChainInfo } from "./useChainInfo";
|
import { useChainInfo } from "./useChainInfo";
|
||||||
|
|
||||||
const ETH_FEED_DECIMALS = 8;
|
const ETH_FEED_DECIMALS = 8;
|
||||||
|
@ -17,7 +17,7 @@ const PriceBox: React.FC = () => {
|
||||||
const {
|
const {
|
||||||
nativeCurrency: { symbol },
|
nativeCurrency: { symbol },
|
||||||
} = useChainInfo();
|
} = useChainInfo();
|
||||||
const latestBlock = useLatestBlock(provider);
|
const latestBlock = useLatestBlockHeader(provider);
|
||||||
|
|
||||||
const maybeOutdated: boolean =
|
const maybeOutdated: boolean =
|
||||||
latestBlock !== undefined &&
|
latestBlock !== undefined &&
|
||||||
|
|
|
@ -0,0 +1,32 @@
|
||||||
|
import React, { useContext } from "react";
|
||||||
|
import { BigNumber } from "@ethersproject/bignumber";
|
||||||
|
import TransactionValue from "../components/TransactionValue";
|
||||||
|
import FiatValue from "../components/FiatValue";
|
||||||
|
import { RuntimeContext } from "../useRuntime";
|
||||||
|
import { useETHUSDOracle } from "../usePriceOracle";
|
||||||
|
|
||||||
|
type AddressBalanceProps = {
|
||||||
|
balance: BigNumber;
|
||||||
|
};
|
||||||
|
|
||||||
|
const AddressBalance: React.FC<AddressBalanceProps> = ({ balance }) => {
|
||||||
|
const { provider } = useContext(RuntimeContext);
|
||||||
|
const eth2USDValue = useETHUSDOracle(provider, "latest");
|
||||||
|
const fiatValue =
|
||||||
|
!balance.isZero() && eth2USDValue !== undefined
|
||||||
|
? balance.mul(eth2USDValue).div(10 ** 8)
|
||||||
|
: undefined;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<TransactionValue value={balance} />
|
||||||
|
{fiatValue && (
|
||||||
|
<span className="px-2 border-emerald-200 border rounded-lg bg-emerald-100 text-emerald-600">
|
||||||
|
<FiatValue value={fiatValue} />
|
||||||
|
</span>
|
||||||
|
)}
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default AddressBalance;
|
|
@ -1,9 +1,7 @@
|
||||||
import React, { useContext, useEffect, useMemo, useState } from "react";
|
import React, { useContext, useEffect, useMemo, useState } from "react";
|
||||||
import { BlockTag } from "@ethersproject/providers";
|
|
||||||
import ContentFrame from "../ContentFrame";
|
import ContentFrame from "../ContentFrame";
|
||||||
import InfoRow from "../components/InfoRow";
|
import InfoRow from "../components/InfoRow";
|
||||||
import TransactionValue from "../components/TransactionValue";
|
import AddressBalance from "./AddressBalance";
|
||||||
import ETH2USDValue from "../components/ETH2USDValue";
|
|
||||||
import TransactionAddress from "../components/TransactionAddress";
|
import TransactionAddress from "../components/TransactionAddress";
|
||||||
import Copy from "../components/Copy";
|
import Copy from "../components/Copy";
|
||||||
import TransactionLink from "../components/TransactionLink";
|
import TransactionLink from "../components/TransactionLink";
|
||||||
|
@ -14,7 +12,6 @@ import TransactionItem from "../search/TransactionItem";
|
||||||
import UndefinedPageControl from "../search/UndefinedPageControl";
|
import UndefinedPageControl from "../search/UndefinedPageControl";
|
||||||
import { useFeeToggler } from "../search/useFeeToggler";
|
import { useFeeToggler } from "../search/useFeeToggler";
|
||||||
import { SelectionContext, useSelection } from "../useSelection";
|
import { SelectionContext, useSelection } from "../useSelection";
|
||||||
import { useMultipleETHUSDOracle } from "../usePriceOracle";
|
|
||||||
import { RuntimeContext } from "../useRuntime";
|
import { RuntimeContext } from "../useRuntime";
|
||||||
import { useParams, useSearchParams } from "react-router-dom";
|
import { useParams, useSearchParams } from "react-router-dom";
|
||||||
import { ChecksummedAddress, ProcessedTransaction } from "../types";
|
import { ChecksummedAddress, ProcessedTransaction } from "../types";
|
||||||
|
@ -98,19 +95,6 @@ const AddressTransactionResults: React.FC<AddressTransactionResultsProps> = ({
|
||||||
|
|
||||||
const page = useMemo(() => controller?.getPage(), [controller]);
|
const page = useMemo(() => controller?.getPage(), [controller]);
|
||||||
|
|
||||||
// Extract block number from all txs on current page
|
|
||||||
// TODO: dedup blockTags
|
|
||||||
const blockTags: BlockTag[] = useMemo(() => {
|
|
||||||
if (!page) {
|
|
||||||
return ["latest"];
|
|
||||||
}
|
|
||||||
|
|
||||||
const blockTags: BlockTag[] = page.map((t) => t.blockNumber);
|
|
||||||
blockTags.push("latest");
|
|
||||||
return blockTags;
|
|
||||||
}, [page]);
|
|
||||||
const priceMap = useMultipleETHUSDOracle(provider, blockTags);
|
|
||||||
|
|
||||||
const balance = useAddressBalance(provider, address);
|
const balance = useAddressBalance(provider, address);
|
||||||
const creator = useContractCreator(provider, address);
|
const creator = useContractCreator(provider, address);
|
||||||
|
|
||||||
|
@ -121,15 +105,7 @@ const AddressTransactionResults: React.FC<AddressTransactionResultsProps> = ({
|
||||||
{balance && (
|
{balance && (
|
||||||
<InfoRow title="Balance">
|
<InfoRow title="Balance">
|
||||||
<div className="space-x-2">
|
<div className="space-x-2">
|
||||||
<TransactionValue value={balance} />
|
<AddressBalance balance={balance} />
|
||||||
{!balance.isZero() && priceMap["latest"] !== undefined && (
|
|
||||||
<span className="px-2 border-emerald-200 border rounded-lg bg-emerald-100 text-emerald-600">
|
|
||||||
<ETH2USDValue
|
|
||||||
ethAmount={balance}
|
|
||||||
eth2USDValue={priceMap["latest"]}
|
|
||||||
/>
|
|
||||||
</span>
|
|
||||||
)}
|
|
||||||
</div>
|
</div>
|
||||||
</InfoRow>
|
</InfoRow>
|
||||||
)}
|
)}
|
||||||
|
@ -163,7 +139,6 @@ const AddressTransactionResults: React.FC<AddressTransactionResultsProps> = ({
|
||||||
tx={tx}
|
tx={tx}
|
||||||
selectedAddress={address}
|
selectedAddress={address}
|
||||||
feeDisplay={feeDisplay}
|
feeDisplay={feeDisplay}
|
||||||
priceMap={priceMap}
|
|
||||||
/>
|
/>
|
||||||
))}
|
))}
|
||||||
<NavBar address={address} page={page} controller={controller} />
|
<NavBar address={address} page={page} controller={controller} />
|
||||||
|
|
|
@ -1,35 +1,27 @@
|
||||||
import React, { useContext, useMemo } from "react";
|
import React from "react";
|
||||||
import { BlockTag } from "@ethersproject/abstract-provider";
|
|
||||||
import ContentFrame from "../ContentFrame";
|
import ContentFrame from "../ContentFrame";
|
||||||
import PageControl from "../search/PageControl";
|
import PageControl from "../search/PageControl";
|
||||||
import ResultHeader from "../search/ResultHeader";
|
import ResultHeader from "../search/ResultHeader";
|
||||||
import PendingResults from "../search/PendingResults";
|
import PendingResults from "../search/PendingResults";
|
||||||
import TransactionItem from "../search/TransactionItem";
|
import TransactionItem from "../search/TransactionItem";
|
||||||
import { useFeeToggler } from "../search/useFeeToggler";
|
import { useFeeToggler } from "../search/useFeeToggler";
|
||||||
import { RuntimeContext } from "../useRuntime";
|
|
||||||
import { SelectionContext, useSelection } from "../useSelection";
|
import { SelectionContext, useSelection } from "../useSelection";
|
||||||
import { ProcessedTransaction } from "../types";
|
import { ProcessedTransaction } from "../types";
|
||||||
import { PAGE_SIZE } from "../params";
|
import { PAGE_SIZE } from "../params";
|
||||||
import { useMultipleETHUSDOracle } from "../usePriceOracle";
|
|
||||||
|
|
||||||
type BlockTransactionResultsProps = {
|
type BlockTransactionResultsProps = {
|
||||||
blockTag: BlockTag;
|
|
||||||
page?: ProcessedTransaction[];
|
page?: ProcessedTransaction[];
|
||||||
total: number;
|
total: number;
|
||||||
pageNumber: number;
|
pageNumber: number;
|
||||||
};
|
};
|
||||||
|
|
||||||
const BlockTransactionResults: React.FC<BlockTransactionResultsProps> = ({
|
const BlockTransactionResults: React.FC<BlockTransactionResultsProps> = ({
|
||||||
blockTag,
|
|
||||||
page,
|
page,
|
||||||
total,
|
total,
|
||||||
pageNumber,
|
pageNumber,
|
||||||
}) => {
|
}) => {
|
||||||
const { provider } = useContext(RuntimeContext);
|
|
||||||
const selectionCtx = useSelection();
|
const selectionCtx = useSelection();
|
||||||
const [feeDisplay, feeDisplayToggler] = useFeeToggler();
|
const [feeDisplay, feeDisplayToggler] = useFeeToggler();
|
||||||
const blockTags = useMemo(() => [blockTag], [blockTag]);
|
|
||||||
const priceMap = useMultipleETHUSDOracle(provider, blockTags);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<ContentFrame>
|
<ContentFrame>
|
||||||
|
@ -54,12 +46,7 @@ const BlockTransactionResults: React.FC<BlockTransactionResultsProps> = ({
|
||||||
{page ? (
|
{page ? (
|
||||||
<SelectionContext.Provider value={selectionCtx}>
|
<SelectionContext.Provider value={selectionCtx}>
|
||||||
{page.map((tx) => (
|
{page.map((tx) => (
|
||||||
<TransactionItem
|
<TransactionItem key={tx.hash} tx={tx} feeDisplay={feeDisplay} />
|
||||||
key={tx.hash}
|
|
||||||
tx={tx}
|
|
||||||
feeDisplay={feeDisplay}
|
|
||||||
priceMap={priceMap}
|
|
||||||
/>
|
|
||||||
))}
|
))}
|
||||||
<div className="flex justify-between items-baseline py-3">
|
<div className="flex justify-between items-baseline py-3">
|
||||||
<div className="text-sm text-gray-500">
|
<div className="text-sm text-gray-500">
|
||||||
|
|
|
@ -9,7 +9,6 @@ import { faCoins } from "@fortawesome/free-solid-svg-icons/faCoins";
|
||||||
import SourcifyLogo from "../sourcify/SourcifyLogo";
|
import SourcifyLogo from "../sourcify/SourcifyLogo";
|
||||||
import PlainAddress from "./PlainAddress";
|
import PlainAddress from "./PlainAddress";
|
||||||
import { RuntimeContext } from "../useRuntime";
|
import { RuntimeContext } from "../useRuntime";
|
||||||
import { useAppConfigContext } from "../useAppConfig";
|
|
||||||
import { useSourcifyMetadata } from "../sourcify/useSourcify";
|
import { useSourcifyMetadata } from "../sourcify/useSourcify";
|
||||||
import { useResolvedAddress } from "../useResolvedAddresses";
|
import { useResolvedAddress } from "../useResolvedAddresses";
|
||||||
import { AddressContext, ChecksummedAddress, ZERO_ADDRESS } from "../types";
|
import { AddressContext, ChecksummedAddress, ZERO_ADDRESS } from "../types";
|
||||||
|
@ -39,12 +38,7 @@ const DecoratedAddressLink: React.FC<DecoratedAddressLinkProps> = ({
|
||||||
eoa,
|
eoa,
|
||||||
}) => {
|
}) => {
|
||||||
const { provider } = useContext(RuntimeContext);
|
const { provider } = useContext(RuntimeContext);
|
||||||
const { sourcifySource } = useAppConfigContext();
|
const metadata = useSourcifyMetadata(address, provider?.network.chainId);
|
||||||
const metadata = useSourcifyMetadata(
|
|
||||||
address,
|
|
||||||
provider?.network.chainId,
|
|
||||||
sourcifySource
|
|
||||||
);
|
|
||||||
|
|
||||||
const mint = addressCtx === AddressContext.FROM && address === ZERO_ADDRESS;
|
const mint = addressCtx === AddressContext.FROM && address === ZERO_ADDRESS;
|
||||||
const burn = addressCtx === AddressContext.TO && address === ZERO_ADDRESS;
|
const burn = addressCtx === AddressContext.TO && address === ZERO_ADDRESS;
|
||||||
|
|
|
@ -1,33 +0,0 @@
|
||||||
import React from "react";
|
|
||||||
import { BigNumber, FixedNumber } from "@ethersproject/bignumber";
|
|
||||||
import { commify } from "@ethersproject/units";
|
|
||||||
|
|
||||||
type ETH2USDValueProps = {
|
|
||||||
ethAmount: BigNumber;
|
|
||||||
eth2USDValue: BigNumber;
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Basic display of ETH -> USD values WITHOUT box decoration, only
|
|
||||||
* text formatting.
|
|
||||||
*
|
|
||||||
* USD amounts are displayed commified with 2 decimals places and $ prefix,
|
|
||||||
* i.e., "$1,000.00".
|
|
||||||
*/
|
|
||||||
const ETH2USDValue: React.FC<ETH2USDValueProps> = ({
|
|
||||||
ethAmount,
|
|
||||||
eth2USDValue,
|
|
||||||
}) => {
|
|
||||||
const value = ethAmount.mul(eth2USDValue).div(10 ** 8);
|
|
||||||
|
|
||||||
return (
|
|
||||||
<span className="text-xs">
|
|
||||||
$
|
|
||||||
<span className="font-balance">
|
|
||||||
{commify(FixedNumber.fromValue(value, 18).round(2).toString())}
|
|
||||||
</span>
|
|
||||||
</span>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
export default React.memo(ETH2USDValue);
|
|
|
@ -0,0 +1,25 @@
|
||||||
|
import React from "react";
|
||||||
|
import { BigNumber, FixedNumber } from "@ethersproject/bignumber";
|
||||||
|
import { commify } from "@ethersproject/units";
|
||||||
|
|
||||||
|
type FiatValueProps = {
|
||||||
|
value: BigNumber;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Basic display of ETH -> USD values WITHOUT box decoration, only
|
||||||
|
* text formatting.
|
||||||
|
*
|
||||||
|
* USD amounts are displayed commified with 2 decimals places and $ prefix,
|
||||||
|
* i.e., "$1,000.00".
|
||||||
|
*/
|
||||||
|
const FiatValue: React.FC<FiatValueProps> = ({ value }) => (
|
||||||
|
<span className="text-xs">
|
||||||
|
$
|
||||||
|
<span className="font-balance">
|
||||||
|
{commify(FixedNumber.fromValue(value, 18).round(2).toString())}
|
||||||
|
</span>
|
||||||
|
</span>
|
||||||
|
);
|
||||||
|
|
||||||
|
export default FiatValue;
|
|
@ -1,5 +1,4 @@
|
||||||
import React from "react";
|
import React from "react";
|
||||||
import { BigNumber } from "@ethersproject/bignumber";
|
|
||||||
import InternalTransfer from "./InternalTransfer";
|
import InternalTransfer from "./InternalTransfer";
|
||||||
import InternalSelfDestruct from "./InternalSelfDestruct";
|
import InternalSelfDestruct from "./InternalSelfDestruct";
|
||||||
import InternalCreate from "./InternalCreate";
|
import InternalCreate from "./InternalCreate";
|
||||||
|
@ -8,20 +7,14 @@ import { TransactionData, InternalOperation, OperationType } from "../types";
|
||||||
type InternalTransactionOperationProps = {
|
type InternalTransactionOperationProps = {
|
||||||
txData: TransactionData;
|
txData: TransactionData;
|
||||||
internalOp: InternalOperation;
|
internalOp: InternalOperation;
|
||||||
// TODO: migrate all this logic to SWR
|
|
||||||
ethUSDPrice: BigNumber | undefined;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const InternalTransactionOperation: React.FC<
|
const InternalTransactionOperation: React.FC<
|
||||||
InternalTransactionOperationProps
|
InternalTransactionOperationProps
|
||||||
> = ({ txData, internalOp, ethUSDPrice }) => (
|
> = ({ txData, internalOp }) => (
|
||||||
<>
|
<>
|
||||||
{internalOp.type === OperationType.TRANSFER && (
|
{internalOp.type === OperationType.TRANSFER && (
|
||||||
<InternalTransfer
|
<InternalTransfer txData={txData} internalOp={internalOp} />
|
||||||
txData={txData}
|
|
||||||
internalOp={internalOp}
|
|
||||||
ethUSDPrice={ethUSDPrice}
|
|
||||||
/>
|
|
||||||
)}
|
)}
|
||||||
{internalOp.type === OperationType.SELF_DESTRUCT && (
|
{internalOp.type === OperationType.SELF_DESTRUCT && (
|
||||||
<InternalSelfDestruct txData={txData} internalOp={internalOp} />
|
<InternalSelfDestruct txData={txData} internalOp={internalOp} />
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
import React, { useContext } from "react";
|
import React, { useContext } from "react";
|
||||||
import { BigNumber } from "@ethersproject/bignumber";
|
|
||||||
import { formatEther } from "@ethersproject/units";
|
import { formatEther } from "@ethersproject/units";
|
||||||
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
|
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
|
||||||
import { faAngleRight } from "@fortawesome/free-solid-svg-icons/faAngleRight";
|
import { faAngleRight } from "@fortawesome/free-solid-svg-icons/faAngleRight";
|
||||||
|
@ -11,19 +10,17 @@ import USDAmount from "./USDAmount";
|
||||||
import { RuntimeContext } from "../useRuntime";
|
import { RuntimeContext } from "../useRuntime";
|
||||||
import { useHasCode } from "../useErigonHooks";
|
import { useHasCode } from "../useErigonHooks";
|
||||||
import { useChainInfo } from "../useChainInfo";
|
import { useChainInfo } from "../useChainInfo";
|
||||||
|
import { useETHUSDOracle } from "../usePriceOracle";
|
||||||
import { TransactionData, InternalOperation } from "../types";
|
import { TransactionData, InternalOperation } from "../types";
|
||||||
|
|
||||||
type InternalTransferProps = {
|
type InternalTransferProps = {
|
||||||
txData: TransactionData;
|
txData: TransactionData;
|
||||||
internalOp: InternalOperation;
|
internalOp: InternalOperation;
|
||||||
// TODO: migrate all this logic to SWR
|
|
||||||
ethUSDPrice: BigNumber | undefined;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const InternalTransfer: React.FC<InternalTransferProps> = ({
|
const InternalTransfer: React.FC<InternalTransferProps> = ({
|
||||||
txData,
|
txData,
|
||||||
internalOp,
|
internalOp,
|
||||||
ethUSDPrice,
|
|
||||||
}) => {
|
}) => {
|
||||||
const {
|
const {
|
||||||
nativeCurrency: { symbol, decimals },
|
nativeCurrency: { symbol, decimals },
|
||||||
|
@ -36,6 +33,10 @@ const InternalTransfer: React.FC<InternalTransferProps> = ({
|
||||||
internalOp.to === txData.confirmedData.miner;
|
internalOp.to === txData.confirmedData.miner;
|
||||||
|
|
||||||
const { provider } = useContext(RuntimeContext);
|
const { provider } = useContext(RuntimeContext);
|
||||||
|
const blockETHUSDPrice = useETHUSDOracle(
|
||||||
|
provider,
|
||||||
|
txData.confirmedData?.blockNumber
|
||||||
|
);
|
||||||
const fromHasCode = useHasCode(
|
const fromHasCode = useHasCode(
|
||||||
provider,
|
provider,
|
||||||
internalOp.from,
|
internalOp.from,
|
||||||
|
@ -99,12 +100,12 @@ const InternalTransfer: React.FC<InternalTransferProps> = ({
|
||||||
<span>
|
<span>
|
||||||
{formatEther(internalOp.value)} {symbol}
|
{formatEther(internalOp.value)} {symbol}
|
||||||
</span>
|
</span>
|
||||||
{ethUSDPrice && (
|
{blockETHUSDPrice && (
|
||||||
<span className="px-2 border-gray-200 border rounded-lg bg-gray-100 text-gray-600">
|
<span className="px-2 border-gray-200 border rounded-lg bg-gray-100 text-gray-600">
|
||||||
<USDAmount
|
<USDAmount
|
||||||
amount={internalOp.value}
|
amount={internalOp.value}
|
||||||
amountDecimals={decimals}
|
amountDecimals={decimals}
|
||||||
quote={ethUSDPrice}
|
quote={blockETHUSDPrice}
|
||||||
// TODO: migrate to SWR and standardize this magic number
|
// TODO: migrate to SWR and standardize this magic number
|
||||||
quoteDecimals={8}
|
quoteDecimals={8}
|
||||||
/>
|
/>
|
||||||
|
|
|
@ -0,0 +1,41 @@
|
||||||
|
import React, { useContext } from "react";
|
||||||
|
import { BlockTag } from "@ethersproject/providers";
|
||||||
|
import { BigNumber } from "@ethersproject/bignumber";
|
||||||
|
import FormattedBalance from "./FormattedBalance";
|
||||||
|
import { RuntimeContext } from "../useRuntime";
|
||||||
|
import { useChainInfo } from "../useChainInfo";
|
||||||
|
import { useETHUSDOracle } from "../usePriceOracle";
|
||||||
|
import FiatValue from "./FiatValue";
|
||||||
|
|
||||||
|
type TransactionDetailsValueProps = {
|
||||||
|
blockTag: BlockTag | undefined;
|
||||||
|
value: BigNumber;
|
||||||
|
};
|
||||||
|
|
||||||
|
const TransactionDetailsValue: React.FC<TransactionDetailsValueProps> = ({
|
||||||
|
blockTag,
|
||||||
|
value,
|
||||||
|
}) => {
|
||||||
|
const { provider } = useContext(RuntimeContext);
|
||||||
|
const blockETHUSDPrice = useETHUSDOracle(provider, blockTag);
|
||||||
|
const {
|
||||||
|
nativeCurrency: { symbol },
|
||||||
|
} = useChainInfo();
|
||||||
|
const fiatValue =
|
||||||
|
!value.isZero() && blockETHUSDPrice !== undefined
|
||||||
|
? value.mul(blockETHUSDPrice).div(10 ** 8)
|
||||||
|
: undefined;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<FormattedBalance value={value} /> {symbol}{" "}
|
||||||
|
{fiatValue && (
|
||||||
|
<span className="px-2 border-skin-from border rounded-lg bg-skin-from text-skin-from">
|
||||||
|
<FiatValue value={fiatValue} />
|
||||||
|
</span>
|
||||||
|
)}
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default TransactionDetailsValue;
|
|
@ -1,6 +1,4 @@
|
||||||
import React, { useContext } from "react";
|
import React, { useContext } from "react";
|
||||||
import { BlockTag } from "@ethersproject/abstract-provider";
|
|
||||||
import { BigNumber } from "@ethersproject/bignumber";
|
|
||||||
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
|
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
|
||||||
import { faExclamationCircle } from "@fortawesome/free-solid-svg-icons/faExclamationCircle";
|
import { faExclamationCircle } from "@fortawesome/free-solid-svg-icons/faExclamationCircle";
|
||||||
import MethodName from "../components/MethodName";
|
import MethodName from "../components/MethodName";
|
||||||
|
@ -14,25 +12,23 @@ import TransactionDirection, {
|
||||||
Flags,
|
Flags,
|
||||||
} from "../components/TransactionDirection";
|
} from "../components/TransactionDirection";
|
||||||
import TransactionValue from "../components/TransactionValue";
|
import TransactionValue from "../components/TransactionValue";
|
||||||
|
import TransactionItemFiatFee from "./TransactionItemFiatFee";
|
||||||
import { ProcessedTransaction } from "../types";
|
import { ProcessedTransaction } from "../types";
|
||||||
import { FeeDisplay } from "./useFeeToggler";
|
import { FeeDisplay } from "./useFeeToggler";
|
||||||
import { RuntimeContext } from "../useRuntime";
|
import { RuntimeContext } from "../useRuntime";
|
||||||
import { useHasCode } from "../useErigonHooks";
|
import { useHasCode } from "../useErigonHooks";
|
||||||
import { formatValue } from "../components/formatter";
|
import { formatValue } from "../components/formatter";
|
||||||
import ETH2USDValue from "../components/ETH2USDValue";
|
|
||||||
|
|
||||||
type TransactionItemProps = {
|
type TransactionItemProps = {
|
||||||
tx: ProcessedTransaction;
|
tx: ProcessedTransaction;
|
||||||
selectedAddress?: string;
|
selectedAddress?: string;
|
||||||
feeDisplay: FeeDisplay;
|
feeDisplay: FeeDisplay;
|
||||||
priceMap: Record<BlockTag, BigNumber>;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const TransactionItem: React.FC<TransactionItemProps> = ({
|
const TransactionItem: React.FC<TransactionItemProps> = ({
|
||||||
tx,
|
tx,
|
||||||
selectedAddress,
|
selectedAddress,
|
||||||
feeDisplay,
|
feeDisplay,
|
||||||
priceMap,
|
|
||||||
}) => {
|
}) => {
|
||||||
const { provider } = useContext(RuntimeContext);
|
const { provider } = useContext(RuntimeContext);
|
||||||
const toHasCode = useHasCode(
|
const toHasCode = useHasCode(
|
||||||
|
@ -130,15 +126,9 @@ const TransactionItem: React.FC<TransactionItemProps> = ({
|
||||||
</span>
|
</span>
|
||||||
<span className="font-balance text-xs text-gray-500 truncate">
|
<span className="font-balance text-xs text-gray-500 truncate">
|
||||||
{feeDisplay === FeeDisplay.TX_FEE && formatValue(tx.fee, 18)}
|
{feeDisplay === FeeDisplay.TX_FEE && formatValue(tx.fee, 18)}
|
||||||
{feeDisplay === FeeDisplay.TX_FEE_USD &&
|
{feeDisplay === FeeDisplay.TX_FEE_USD && (
|
||||||
(priceMap[tx.blockNumber] ? (
|
<TransactionItemFiatFee blockTag={tx.blockNumber} fee={tx.fee} />
|
||||||
<ETH2USDValue
|
)}
|
||||||
ethAmount={tx.fee}
|
|
||||||
eth2USDValue={priceMap[tx.blockNumber]}
|
|
||||||
/>
|
|
||||||
) : (
|
|
||||||
"N/A"
|
|
||||||
))}
|
|
||||||
{feeDisplay === FeeDisplay.GAS_PRICE && formatValue(tx.gasPrice, 9)}
|
{feeDisplay === FeeDisplay.GAS_PRICE && formatValue(tx.gasPrice, 9)}
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -0,0 +1,25 @@
|
||||||
|
import React, { useContext } from "react";
|
||||||
|
import { BlockTag } from "@ethersproject/providers";
|
||||||
|
import { BigNumber } from "@ethersproject/bignumber";
|
||||||
|
import FiatValue from "../components/FiatValue";
|
||||||
|
import { RuntimeContext } from "../useRuntime";
|
||||||
|
import { useETHUSDOracle } from "../usePriceOracle";
|
||||||
|
|
||||||
|
type TransactionItemFiatFeeProps = {
|
||||||
|
blockTag: BlockTag;
|
||||||
|
fee: BigNumber;
|
||||||
|
};
|
||||||
|
|
||||||
|
const TransactionItemFiatFee: React.FC<TransactionItemFiatFeeProps> = ({
|
||||||
|
blockTag,
|
||||||
|
fee,
|
||||||
|
}) => {
|
||||||
|
const { provider } = useContext(RuntimeContext);
|
||||||
|
const eth2USDValue = useETHUSDOracle(provider, blockTag);
|
||||||
|
const fiatValue =
|
||||||
|
eth2USDValue !== undefined ? fee.mul(eth2USDValue).div(10 ** 8) : undefined;
|
||||||
|
|
||||||
|
return fiatValue ? <FiatValue value={fiatValue} /> : <>N/A</>;
|
||||||
|
};
|
||||||
|
|
||||||
|
export default TransactionItemFiatFee;
|
|
@ -4,6 +4,7 @@ import { ErrorDescription } from "@ethersproject/abi/lib/interface";
|
||||||
import useSWRImmutable from "swr/immutable";
|
import useSWRImmutable from "swr/immutable";
|
||||||
import { ChecksummedAddress, TransactionData } from "../types";
|
import { ChecksummedAddress, TransactionData } from "../types";
|
||||||
import { sourcifyMetadata, SourcifySource, sourcifySourceFile } from "../url";
|
import { sourcifyMetadata, SourcifySource, sourcifySourceFile } from "../url";
|
||||||
|
import { useAppConfigContext } from "../useAppConfig";
|
||||||
|
|
||||||
export type UserMethod = {
|
export type UserMethod = {
|
||||||
notice?: string | undefined;
|
notice?: string | undefined;
|
||||||
|
@ -98,13 +99,13 @@ const sourcifyFetcher = async (url: string) => {
|
||||||
|
|
||||||
export const useSourcifyMetadata = (
|
export const useSourcifyMetadata = (
|
||||||
address: ChecksummedAddress | undefined,
|
address: ChecksummedAddress | undefined,
|
||||||
chainId: number | undefined,
|
chainId: number | undefined
|
||||||
source: SourcifySource
|
|
||||||
): Metadata | null | undefined => {
|
): Metadata | null | undefined => {
|
||||||
|
const { sourcifySource } = useAppConfigContext();
|
||||||
const metadataURL = () =>
|
const metadataURL = () =>
|
||||||
address === undefined || chainId === undefined
|
address === undefined || chainId === undefined
|
||||||
? null
|
? null
|
||||||
: sourcifyMetadata(address, chainId, source);
|
: sourcifyMetadata(address, chainId, sourcifySource);
|
||||||
const { data, error } = useSWRImmutable<Metadata>(
|
const { data, error } = useSWRImmutable<Metadata>(
|
||||||
metadataURL,
|
metadataURL,
|
||||||
sourcifyFetcher
|
sourcifyFetcher
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import React, { useContext } from "react";
|
import React, { useContext } from "react";
|
||||||
import { useLatestBlock } from "../../useLatestBlock";
|
import { useLatestBlockHeader } from "../../useLatestBlock";
|
||||||
import { RuntimeContext } from "../../useRuntime";
|
import { RuntimeContext } from "../../useRuntime";
|
||||||
import Countdown from "./Countdown";
|
import Countdown from "./Countdown";
|
||||||
import Blocks from "./Blocks";
|
import Blocks from "./Blocks";
|
||||||
|
@ -7,7 +7,7 @@ import { londonBlockNumber } from "./params";
|
||||||
|
|
||||||
const London: React.FC = () => {
|
const London: React.FC = () => {
|
||||||
const { provider } = useContext(RuntimeContext);
|
const { provider } = useContext(RuntimeContext);
|
||||||
const block = useLatestBlock(provider);
|
const block = useLatestBlockHeader(provider);
|
||||||
if (!provider || !block) {
|
if (!provider || !block) {
|
||||||
return <div className="grow"></div>;
|
return <div className="grow"></div>;
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,12 +17,13 @@ import NavNonce from "./NavNonce";
|
||||||
import Timestamp from "../components/Timestamp";
|
import Timestamp from "../components/Timestamp";
|
||||||
import InternalTransactionOperation from "../components/InternalTransactionOperation";
|
import InternalTransactionOperation from "../components/InternalTransactionOperation";
|
||||||
import MethodName from "../components/MethodName";
|
import MethodName from "../components/MethodName";
|
||||||
|
import TransactionDetailsValue from "../components/TransactionDetailsValue";
|
||||||
import TransactionType from "../components/TransactionType";
|
import TransactionType from "../components/TransactionType";
|
||||||
|
import TransactionFee from "./TransactionFee";
|
||||||
import RewardSplit from "./RewardSplit";
|
import RewardSplit from "./RewardSplit";
|
||||||
import GasValue from "../components/GasValue";
|
import GasValue from "../components/GasValue";
|
||||||
import USDValue from "../components/USDValue";
|
import USDValue from "../components/USDValue";
|
||||||
import FormattedBalance from "../components/FormattedBalance";
|
import FormattedBalance from "../components/FormattedBalance";
|
||||||
import ETH2USDValue from "../components/ETH2USDValue";
|
|
||||||
import TokenTransferItem from "../TokenTransferItem";
|
import TokenTransferItem from "../TokenTransferItem";
|
||||||
import { TransactionData } from "../types";
|
import { TransactionData } from "../types";
|
||||||
import PercentageBar from "../components/PercentageBar";
|
import PercentageBar from "../components/PercentageBar";
|
||||||
|
@ -36,7 +37,6 @@ import {
|
||||||
use4Bytes,
|
use4Bytes,
|
||||||
useTransactionDescription,
|
useTransactionDescription,
|
||||||
} from "../use4Bytes";
|
} from "../use4Bytes";
|
||||||
import { useAppConfigContext } from "../useAppConfig";
|
|
||||||
import {
|
import {
|
||||||
useError,
|
useError,
|
||||||
useSourcifyMetadata,
|
useSourcifyMetadata,
|
||||||
|
@ -81,12 +81,7 @@ const Details: React.FC<DetailsProps> = ({ txData }) => {
|
||||||
return false;
|
return false;
|
||||||
}, [txData, internalOps]);
|
}, [txData, internalOps]);
|
||||||
|
|
||||||
const { sourcifySource } = useAppConfigContext();
|
const metadata = useSourcifyMetadata(txData?.to, provider?.network.chainId);
|
||||||
const metadata = useSourcifyMetadata(
|
|
||||||
txData?.to,
|
|
||||||
provider?.network.chainId,
|
|
||||||
sourcifySource
|
|
||||||
);
|
|
||||||
|
|
||||||
const txDesc = useSourcifyTransactionDescription(metadata, txData);
|
const txDesc = useSourcifyTransactionDescription(metadata, txData);
|
||||||
const userDoc = metadata?.output.userdoc;
|
const userDoc = metadata?.output.userdoc;
|
||||||
|
@ -285,7 +280,6 @@ const Details: React.FC<DetailsProps> = ({ txData }) => {
|
||||||
key={i}
|
key={i}
|
||||||
txData={txData}
|
txData={txData}
|
||||||
internalOp={op}
|
internalOp={op}
|
||||||
ethUSDPrice={blockETHUSDPrice}
|
|
||||||
/>
|
/>
|
||||||
))}
|
))}
|
||||||
</div>
|
</div>
|
||||||
|
@ -308,15 +302,10 @@ const Details: React.FC<DetailsProps> = ({ txData }) => {
|
||||||
</InfoRow>
|
</InfoRow>
|
||||||
)}
|
)}
|
||||||
<InfoRow title="Value">
|
<InfoRow title="Value">
|
||||||
<FormattedBalance value={txData.value} /> {symbol}{" "}
|
<TransactionDetailsValue
|
||||||
{!txData.value.isZero() && blockETHUSDPrice && (
|
blockTag={txData.confirmedData?.blockNumber}
|
||||||
<span className="px-2 border-skin-from border rounded-lg bg-skin-from text-skin-from">
|
value={txData.value}
|
||||||
<ETH2USDValue
|
/>
|
||||||
ethAmount={txData.value}
|
|
||||||
eth2USDValue={blockETHUSDPrice}
|
|
||||||
/>
|
|
||||||
</span>
|
|
||||||
)}
|
|
||||||
</InfoRow>
|
</InfoRow>
|
||||||
<InfoRow
|
<InfoRow
|
||||||
title={
|
title={
|
||||||
|
@ -402,15 +391,7 @@ const Details: React.FC<DetailsProps> = ({ txData }) => {
|
||||||
<InfoRow title="Transaction Fee">
|
<InfoRow title="Transaction Fee">
|
||||||
<div className="space-y-3">
|
<div className="space-y-3">
|
||||||
<div>
|
<div>
|
||||||
<FormattedBalance value={txData.confirmedData.fee} /> {symbol}{" "}
|
<TransactionFee confirmedData={txData.confirmedData} />
|
||||||
{blockETHUSDPrice && (
|
|
||||||
<span className="px-2 border-skin-from border rounded-lg bg-skin-from text-skin-from">
|
|
||||||
<ETH2USDValue
|
|
||||||
ethAmount={txData.confirmedData.fee}
|
|
||||||
eth2USDValue={blockETHUSDPrice}
|
|
||||||
/>
|
|
||||||
</span>
|
|
||||||
)}
|
|
||||||
</div>
|
</div>
|
||||||
{hasEIP1559 && <RewardSplit txData={txData} />}
|
{hasEIP1559 && <RewardSplit txData={txData} />}
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -9,7 +9,6 @@ import DecodedParamsTable from "./decoder/DecodedParamsTable";
|
||||||
import DecodedLogSignature from "./decoder/DecodedLogSignature";
|
import DecodedLogSignature from "./decoder/DecodedLogSignature";
|
||||||
import { useTopic0 } from "../useTopic0";
|
import { useTopic0 } from "../useTopic0";
|
||||||
import { RuntimeContext } from "../useRuntime";
|
import { RuntimeContext } from "../useRuntime";
|
||||||
import { useAppConfigContext } from "../useAppConfig";
|
|
||||||
import { useSourcifyMetadata } from "../sourcify/useSourcify";
|
import { useSourcifyMetadata } from "../sourcify/useSourcify";
|
||||||
|
|
||||||
type LogEntryProps = {
|
type LogEntryProps = {
|
||||||
|
@ -18,12 +17,7 @@ type LogEntryProps = {
|
||||||
|
|
||||||
const LogEntry: React.FC<LogEntryProps> = ({ log }) => {
|
const LogEntry: React.FC<LogEntryProps> = ({ log }) => {
|
||||||
const { provider } = useContext(RuntimeContext);
|
const { provider } = useContext(RuntimeContext);
|
||||||
const { sourcifySource } = useAppConfigContext();
|
const metadata = useSourcifyMetadata(log.address, provider?.network.chainId);
|
||||||
const metadata = useSourcifyMetadata(
|
|
||||||
log.address,
|
|
||||||
provider?.network.chainId,
|
|
||||||
sourcifySource
|
|
||||||
);
|
|
||||||
|
|
||||||
const logDesc = useMemo(() => {
|
const logDesc = useMemo(() => {
|
||||||
if (!metadata) {
|
if (!metadata) {
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
import { PropsWithChildren } from "react";
|
import React, { PropsWithChildren, useContext, useState } from "react";
|
||||||
import { NavLink } from "react-router-dom";
|
import { NavLink } from "react-router-dom";
|
||||||
|
import { RuntimeContext } from "../useRuntime";
|
||||||
|
import { useTransactionBySenderAndNonce } from "../useErigonHooks";
|
||||||
import { ChecksummedAddress } from "../types";
|
import { ChecksummedAddress } from "../types";
|
||||||
import { addressByNonceURL } from "../url";
|
import { addressByNonceURL } from "../url";
|
||||||
|
|
||||||
|
@ -16,6 +18,8 @@ const NavButton: React.FC<PropsWithChildren<NavButtonProps>> = ({
|
||||||
disabled,
|
disabled,
|
||||||
children,
|
children,
|
||||||
}) => {
|
}) => {
|
||||||
|
const [prefetch, setPrefetch] = useState<boolean>(false);
|
||||||
|
|
||||||
if (disabled) {
|
if (disabled) {
|
||||||
return (
|
return (
|
||||||
<span className="bg-link-blue/10 text-gray-300 rounded px-2 py-1 text-xs">
|
<span className="bg-link-blue/10 text-gray-300 rounded px-2 py-1 text-xs">
|
||||||
|
@ -25,13 +29,36 @@ const NavButton: React.FC<PropsWithChildren<NavButtonProps>> = ({
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<NavLink
|
<>
|
||||||
className="bg-link-blue/10 text-link-blue hover:bg-link-blue/100 hover:text-white rounded px-2 py-1 text-xs"
|
<NavLink
|
||||||
to={addressByNonceURL(sender, nonce)}
|
className="bg-link-blue/10 text-link-blue hover:bg-link-blue/100 hover:text-white rounded px-2 py-1 text-xs"
|
||||||
>
|
to={addressByNonceURL(sender, nonce)}
|
||||||
{children}
|
onMouseOver={() => setPrefetch(true)}
|
||||||
</NavLink>
|
>
|
||||||
|
{children}
|
||||||
|
</NavLink>
|
||||||
|
{prefetch && <Prefetcher checksummedAddress={sender} nonce={nonce} />}
|
||||||
|
</>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
type PrefetcherProps = {
|
||||||
|
checksummedAddress: ChecksummedAddress;
|
||||||
|
nonce: number;
|
||||||
|
};
|
||||||
|
|
||||||
|
const Prefetcher: React.FC<PrefetcherProps> = ({
|
||||||
|
checksummedAddress,
|
||||||
|
nonce,
|
||||||
|
}) => {
|
||||||
|
const { provider } = useContext(RuntimeContext);
|
||||||
|
const _txHash = useTransactionBySenderAndNonce(
|
||||||
|
provider,
|
||||||
|
checksummedAddress,
|
||||||
|
nonce
|
||||||
|
);
|
||||||
|
|
||||||
|
return <></>;
|
||||||
|
};
|
||||||
|
|
||||||
export default NavButton;
|
export default NavButton;
|
||||||
|
|
|
@ -1,15 +1,11 @@
|
||||||
import React, { useContext, useEffect } from "react";
|
import React, { useContext } from "react";
|
||||||
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
|
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
|
||||||
import { faChevronLeft } from "@fortawesome/free-solid-svg-icons/faChevronLeft";
|
import { faChevronLeft } from "@fortawesome/free-solid-svg-icons/faChevronLeft";
|
||||||
import { faChevronRight } from "@fortawesome/free-solid-svg-icons/faChevronRight";
|
import { faChevronRight } from "@fortawesome/free-solid-svg-icons/faChevronRight";
|
||||||
import NavButton from "./NavButton";
|
import NavButton from "./NavButton";
|
||||||
import { ChecksummedAddress } from "../types";
|
import { ChecksummedAddress } from "../types";
|
||||||
import { RuntimeContext } from "../useRuntime";
|
import { RuntimeContext } from "../useRuntime";
|
||||||
import {
|
import { useTransactionCount } from "../useErigonHooks";
|
||||||
prefetchTransactionBySenderAndNonce,
|
|
||||||
useTransactionCount,
|
|
||||||
} from "../useErigonHooks";
|
|
||||||
import { useSWRConfig } from "swr";
|
|
||||||
|
|
||||||
type NavNonceProps = {
|
type NavNonceProps = {
|
||||||
sender: ChecksummedAddress;
|
sender: ChecksummedAddress;
|
||||||
|
@ -20,25 +16,6 @@ const NavNonce: React.FC<NavNonceProps> = ({ sender, nonce }) => {
|
||||||
const { provider } = useContext(RuntimeContext);
|
const { provider } = useContext(RuntimeContext);
|
||||||
const count = useTransactionCount(provider, sender);
|
const count = useTransactionCount(provider, sender);
|
||||||
|
|
||||||
// Prefetch
|
|
||||||
const swrConfig = useSWRConfig();
|
|
||||||
useEffect(() => {
|
|
||||||
if (!provider || !sender || nonce === undefined || count === undefined) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
prefetchTransactionBySenderAndNonce(swrConfig, provider, sender, nonce - 1);
|
|
||||||
prefetchTransactionBySenderAndNonce(swrConfig, provider, sender, nonce + 1);
|
|
||||||
if (count > 0) {
|
|
||||||
prefetchTransactionBySenderAndNonce(
|
|
||||||
swrConfig,
|
|
||||||
provider,
|
|
||||||
sender,
|
|
||||||
count - 1
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}, [swrConfig, provider, sender, nonce, count]);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="pl-2 self-center flex space-x-1">
|
<div className="pl-2 self-center flex space-x-1">
|
||||||
<NavButton sender={sender} nonce={nonce - 1} disabled={nonce === 0}>
|
<NavButton sender={sender} nonce={nonce - 1} disabled={nonce === 0}>
|
||||||
|
|
|
@ -0,0 +1,36 @@
|
||||||
|
import React, { useContext } from "react";
|
||||||
|
import FormattedBalance from "../components/FormattedBalance";
|
||||||
|
import FiatValue from "../components/FiatValue";
|
||||||
|
import { RuntimeContext } from "../useRuntime";
|
||||||
|
import { useETHUSDOracle } from "../usePriceOracle";
|
||||||
|
import { useChainInfo } from "../useChainInfo";
|
||||||
|
import { ConfirmedTransactionData } from "../types";
|
||||||
|
|
||||||
|
type TransactionFeeProps = {
|
||||||
|
confirmedData: ConfirmedTransactionData;
|
||||||
|
};
|
||||||
|
|
||||||
|
const TransactionFee: React.FC<TransactionFeeProps> = ({ confirmedData }) => {
|
||||||
|
const { provider } = useContext(RuntimeContext);
|
||||||
|
const blockETHUSDPrice = useETHUSDOracle(provider, confirmedData.blockNumber);
|
||||||
|
const {
|
||||||
|
nativeCurrency: { symbol },
|
||||||
|
} = useChainInfo();
|
||||||
|
const fiatValue =
|
||||||
|
blockETHUSDPrice !== undefined
|
||||||
|
? confirmedData.fee.mul(blockETHUSDPrice).div(10 ** 8)
|
||||||
|
: undefined;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<FormattedBalance value={confirmedData.fee} /> {symbol}{" "}
|
||||||
|
{fiatValue && (
|
||||||
|
<span className="px-2 border-skin-from border rounded-lg bg-skin-from text-skin-from">
|
||||||
|
<FiatValue value={fiatValue} />
|
||||||
|
</span>
|
||||||
|
)}
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default TransactionFee;
|
|
@ -1,4 +1,5 @@
|
||||||
import { createContext, useContext, useEffect, useState } from "react";
|
import { createContext, useContext } from "react";
|
||||||
|
import useSWRImmutable from "swr/immutable";
|
||||||
import { chainInfoURL } from "./url";
|
import { chainInfoURL } from "./url";
|
||||||
import { OtterscanRuntime } from "./useRuntime";
|
import { OtterscanRuntime } from "./useRuntime";
|
||||||
|
|
||||||
|
@ -24,40 +25,33 @@ export const defaultChainInfo: ChainInfo = {
|
||||||
|
|
||||||
export const ChainInfoContext = createContext<ChainInfo | undefined>(undefined);
|
export const ChainInfoContext = createContext<ChainInfo | undefined>(undefined);
|
||||||
|
|
||||||
|
const chainInfoFetcher = async (assetsURLPrefix: string, chainId: number) => {
|
||||||
|
const url = chainInfoURL(assetsURLPrefix, chainId);
|
||||||
|
const res = await fetch(url);
|
||||||
|
if (!res.ok) {
|
||||||
|
return defaultChainInfo;
|
||||||
|
}
|
||||||
|
|
||||||
|
const info: ChainInfo = await res.json();
|
||||||
|
return info;
|
||||||
|
};
|
||||||
|
|
||||||
export const useChainInfoFromMetadataFile = (
|
export const useChainInfoFromMetadataFile = (
|
||||||
runtime: OtterscanRuntime | undefined
|
runtime: OtterscanRuntime | undefined
|
||||||
): ChainInfo | undefined => {
|
): ChainInfo | undefined => {
|
||||||
const assetsURLPrefix = runtime?.config?.assetsURLPrefix;
|
const assetsURLPrefix = runtime?.config?.assetsURLPrefix;
|
||||||
const chainId = runtime?.provider?.network.chainId;
|
const chainId = runtime?.provider?.network.chainId;
|
||||||
|
|
||||||
const [chainInfo, setChainInfo] = useState<ChainInfo | undefined>(undefined);
|
const { data, error } = useSWRImmutable(
|
||||||
|
assetsURLPrefix !== undefined && chainId !== undefined
|
||||||
useEffect(() => {
|
? [assetsURLPrefix, chainId]
|
||||||
if (assetsURLPrefix === undefined || chainId === undefined) {
|
: null,
|
||||||
setChainInfo(undefined);
|
chainInfoFetcher
|
||||||
return;
|
);
|
||||||
}
|
if (error) {
|
||||||
|
return defaultChainInfo;
|
||||||
const readChainInfo = async () => {
|
}
|
||||||
try {
|
return data;
|
||||||
const res = await fetch(chainInfoURL(assetsURLPrefix, chainId));
|
|
||||||
if (!res.ok) {
|
|
||||||
setChainInfo(defaultChainInfo);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const info: ChainInfo = await res.json();
|
|
||||||
setChainInfo(info);
|
|
||||||
} catch (err) {
|
|
||||||
// ignore
|
|
||||||
setChainInfo(defaultChainInfo);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
readChainInfo();
|
|
||||||
}, [assetsURLPrefix, chainId]);
|
|
||||||
|
|
||||||
return chainInfo;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export const useChainInfo = (): ChainInfo => {
|
export const useChainInfo = (): ChainInfo => {
|
||||||
|
|
|
@ -10,7 +10,7 @@ import { Contract } from "@ethersproject/contracts";
|
||||||
import { defaultAbiCoder } from "@ethersproject/abi";
|
import { defaultAbiCoder } from "@ethersproject/abi";
|
||||||
import { BigNumber } from "@ethersproject/bignumber";
|
import { BigNumber } from "@ethersproject/bignumber";
|
||||||
import { arrayify, hexDataSlice, isHexString } from "@ethersproject/bytes";
|
import { arrayify, hexDataSlice, isHexString } from "@ethersproject/bytes";
|
||||||
import useSWR, { useSWRConfig } from "swr";
|
import useSWR from "swr";
|
||||||
import useSWRImmutable from "swr/immutable";
|
import useSWRImmutable from "swr/immutable";
|
||||||
import { getInternalOperations } from "./nodeFunctions";
|
import { getInternalOperations } from "./nodeFunctions";
|
||||||
import {
|
import {
|
||||||
|
@ -527,25 +527,6 @@ const getTransactionBySenderAndNonceFetcher =
|
||||||
return result;
|
return result;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const prefetchTransactionBySenderAndNonce = (
|
|
||||||
{ mutate }: ReturnType<typeof useSWRConfig>,
|
|
||||||
provider: JsonRpcProvider,
|
|
||||||
sender: ChecksummedAddress,
|
|
||||||
nonce: number
|
|
||||||
) => {
|
|
||||||
const key: TransactionBySenderAndNonceKey = {
|
|
||||||
network: provider.network.chainId,
|
|
||||||
sender,
|
|
||||||
nonce,
|
|
||||||
};
|
|
||||||
mutate(key, (curr: any) => {
|
|
||||||
if (curr) {
|
|
||||||
return curr;
|
|
||||||
}
|
|
||||||
return getTransactionBySenderAndNonceFetcher(provider)(key);
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
export const useTransactionBySenderAndNonce = (
|
export const useTransactionBySenderAndNonce = (
|
||||||
provider: JsonRpcProvider | undefined,
|
provider: JsonRpcProvider | undefined,
|
||||||
sender: ChecksummedAddress | undefined,
|
sender: ChecksummedAddress | undefined,
|
||||||
|
|
|
@ -2,7 +2,12 @@ import { useState, useEffect } from "react";
|
||||||
import { Block } from "@ethersproject/abstract-provider";
|
import { Block } from "@ethersproject/abstract-provider";
|
||||||
import { JsonRpcProvider } from "@ethersproject/providers";
|
import { JsonRpcProvider } from "@ethersproject/providers";
|
||||||
|
|
||||||
export const useLatestBlock = (provider?: JsonRpcProvider) => {
|
/**
|
||||||
|
* Returns the latest block header AND hook an internal listener
|
||||||
|
* that'll update and trigger a component render as a side effect
|
||||||
|
* every time it is notified of a new block by the web3 provider.
|
||||||
|
*/
|
||||||
|
export const useLatestBlockHeader = (provider?: JsonRpcProvider) => {
|
||||||
const [latestBlock, setLatestBlock] = useState<Block>();
|
const [latestBlock, setLatestBlock] = useState<Block>();
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
@ -10,15 +15,7 @@ export const useLatestBlock = (provider?: JsonRpcProvider) => {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const readLatestBlock = async () => {
|
const getAndSetBlockHeader = async (blockNumber: number) => {
|
||||||
const blockNum = await provider.getBlockNumber();
|
|
||||||
const _raw = await provider.send("erigon_getHeaderByNumber", [blockNum]);
|
|
||||||
const _block = provider.formatter.block(_raw);
|
|
||||||
setLatestBlock(_block);
|
|
||||||
};
|
|
||||||
readLatestBlock();
|
|
||||||
|
|
||||||
const listener = async (blockNumber: number) => {
|
|
||||||
const _raw = await provider.send("erigon_getHeaderByNumber", [
|
const _raw = await provider.send("erigon_getHeaderByNumber", [
|
||||||
blockNumber,
|
blockNumber,
|
||||||
]);
|
]);
|
||||||
|
@ -26,15 +23,31 @@ export const useLatestBlock = (provider?: JsonRpcProvider) => {
|
||||||
setLatestBlock(_block);
|
setLatestBlock(_block);
|
||||||
};
|
};
|
||||||
|
|
||||||
provider.on("block", listener);
|
// Immediately read and set the latest block header
|
||||||
|
const readLatestBlock = async () => {
|
||||||
|
const blockNum = await provider.getBlockNumber();
|
||||||
|
await getAndSetBlockHeader(blockNum);
|
||||||
|
};
|
||||||
|
readLatestBlock();
|
||||||
|
|
||||||
|
// Hook a listener that'll update the latest block header
|
||||||
|
// every time it is notified of a new block
|
||||||
|
provider.on("block", getAndSetBlockHeader);
|
||||||
return () => {
|
return () => {
|
||||||
provider.removeListener("block", listener);
|
provider.removeListener("block", getAndSetBlockHeader);
|
||||||
};
|
};
|
||||||
}, [provider]);
|
}, [provider]);
|
||||||
|
|
||||||
return latestBlock;
|
return latestBlock;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the latest block number AND hook an internal listener
|
||||||
|
* that'll update and trigger a component render as a side effect
|
||||||
|
* every time it is notified of a new block by the web3 provider.
|
||||||
|
*
|
||||||
|
* This hook is cheaper than useLatestBlockHeader.
|
||||||
|
*/
|
||||||
export const useLatestBlockNumber = (provider?: JsonRpcProvider) => {
|
export const useLatestBlockNumber = (provider?: JsonRpcProvider) => {
|
||||||
const [latestBlock, setLatestBlock] = useState<number>();
|
const [latestBlock, setLatestBlock] = useState<number>();
|
||||||
|
|
||||||
|
@ -43,12 +56,15 @@ export const useLatestBlockNumber = (provider?: JsonRpcProvider) => {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Immediately read and set the latest block number
|
||||||
const readLatestBlock = async () => {
|
const readLatestBlock = async () => {
|
||||||
const blockNum = await provider.getBlockNumber();
|
const blockNum = await provider.getBlockNumber();
|
||||||
setLatestBlock(blockNum);
|
setLatestBlock(blockNum);
|
||||||
};
|
};
|
||||||
readLatestBlock();
|
readLatestBlock();
|
||||||
|
|
||||||
|
// Hook a listener that'll update the latest block number
|
||||||
|
// every time it is notified of a new block
|
||||||
const listener = async (blockNumber: number) => {
|
const listener = async (blockNumber: number) => {
|
||||||
setLatestBlock(blockNumber);
|
setLatestBlock(blockNumber);
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
import { useEffect, useMemo, useState } from "react";
|
|
||||||
import { JsonRpcProvider, BlockTag } from "@ethersproject/providers";
|
import { JsonRpcProvider, BlockTag } from "@ethersproject/providers";
|
||||||
import { Contract } from "@ethersproject/contracts";
|
import { Contract } from "@ethersproject/contracts";
|
||||||
import { BigNumber } from "@ethersproject/bignumber";
|
import { BigNumber } from "@ethersproject/bignumber";
|
||||||
|
@ -70,77 +69,34 @@ export const useTokenUSDOracle = (
|
||||||
return data ?? [undefined, undefined];
|
return data ?? [undefined, undefined];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const ethUSDFetcherKey = (blockTag: BlockTag | undefined) => {
|
||||||
|
if (blockTag === undefined) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return ["ethusd", blockTag];
|
||||||
|
};
|
||||||
|
|
||||||
|
const ethUSDFetcher =
|
||||||
|
(
|
||||||
|
provider: JsonRpcProvider | undefined
|
||||||
|
): Fetcher<BigNumber | undefined, ["ethusd", BlockTag | undefined]> =>
|
||||||
|
async (_, blockTag) => {
|
||||||
|
if (provider?.network.chainId !== 1) {
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
const c = new Contract("eth-usd.data.eth", AggregatorV3Interface, provider);
|
||||||
|
const priceData = await c.latestRoundData({ blockTag });
|
||||||
|
return BigNumber.from(priceData.answer);
|
||||||
|
};
|
||||||
|
|
||||||
export const useETHUSDOracle = (
|
export const useETHUSDOracle = (
|
||||||
provider: JsonRpcProvider | undefined,
|
provider: JsonRpcProvider | undefined,
|
||||||
blockTag: BlockTag | undefined
|
blockTag: BlockTag | undefined
|
||||||
) => {
|
): BigNumber | undefined => {
|
||||||
const blockTags = useMemo(() => [blockTag], [blockTag]);
|
const fetcher = ethUSDFetcher(provider);
|
||||||
const priceMap = useMultipleETHUSDOracle(provider, blockTags);
|
const { data, error } = useSWRImmutable(ethUSDFetcherKey(blockTag), fetcher);
|
||||||
|
if (error) {
|
||||||
if (blockTag === undefined) {
|
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
return priceMap[blockTag];
|
return data;
|
||||||
};
|
|
||||||
|
|
||||||
export const useMultipleETHUSDOracle = (
|
|
||||||
provider: JsonRpcProvider | undefined,
|
|
||||||
blockTags: (BlockTag | undefined)[]
|
|
||||||
) => {
|
|
||||||
const ethFeed = useMemo(() => {
|
|
||||||
// TODO: it currently is hardcoded to support only mainnet
|
|
||||||
if (!provider || provider.network.chainId !== 1) {
|
|
||||||
return undefined;
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
return new Contract("eth-usd.data.eth", AggregatorV3Interface, provider);
|
|
||||||
} catch (err) {
|
|
||||||
console.error(err);
|
|
||||||
return undefined;
|
|
||||||
}
|
|
||||||
}, [provider]);
|
|
||||||
|
|
||||||
const [latestPriceData, setLatestPriceData] = useState<
|
|
||||||
Record<BlockTag, BigNumber>
|
|
||||||
>({});
|
|
||||||
useEffect(() => {
|
|
||||||
if (!ethFeed) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const priceReaders: Promise<BigNumber | undefined>[] = [];
|
|
||||||
for (const blockTag of blockTags) {
|
|
||||||
priceReaders.push(
|
|
||||||
(async () => {
|
|
||||||
try {
|
|
||||||
const priceData = await ethFeed.latestRoundData({ blockTag });
|
|
||||||
return BigNumber.from(priceData.answer);
|
|
||||||
} catch (err) {
|
|
||||||
// Silently ignore on purpose; it means the network or block number does
|
|
||||||
// not contain the chainlink feed contract
|
|
||||||
return undefined;
|
|
||||||
}
|
|
||||||
})()
|
|
||||||
);
|
|
||||||
}
|
|
||||||
const readData = async () => {
|
|
||||||
const results = await Promise.all(priceReaders);
|
|
||||||
const priceMap: Record<BlockTag, BigNumber> = {};
|
|
||||||
for (let i = 0; i < blockTags.length; i++) {
|
|
||||||
const blockTag = blockTags[i];
|
|
||||||
const result = results[i];
|
|
||||||
if (blockTag === undefined || result === undefined) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
priceMap[blockTag] = result;
|
|
||||||
}
|
|
||||||
|
|
||||||
setLatestPriceData(priceMap);
|
|
||||||
};
|
|
||||||
readData();
|
|
||||||
}, [ethFeed, blockTags]);
|
|
||||||
|
|
||||||
return latestPriceData;
|
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue