diff --git a/src/components/DecoratedAddressLink.tsx b/src/components/DecoratedAddressLink.tsx
index 62ccd3a..4659e68 100644
--- a/src/components/DecoratedAddressLink.tsx
+++ b/src/components/DecoratedAddressLink.tsx
@@ -9,7 +9,6 @@ import { faCoins } from "@fortawesome/free-solid-svg-icons/faCoins";
import SourcifyLogo from "../sourcify/SourcifyLogo";
import PlainAddress from "./PlainAddress";
import { RuntimeContext } from "../useRuntime";
-import { useAppConfigContext } from "../useAppConfig";
import { useSourcifyMetadata } from "../sourcify/useSourcify";
import { useResolvedAddress } from "../useResolvedAddresses";
import { AddressContext, ChecksummedAddress, ZERO_ADDRESS } from "../types";
@@ -39,12 +38,7 @@ const DecoratedAddressLink: React.FC = ({
eoa,
}) => {
const { provider } = useContext(RuntimeContext);
- const { sourcifySource } = useAppConfigContext();
- const metadata = useSourcifyMetadata(
- address,
- provider?.network.chainId,
- sourcifySource
- );
+ const metadata = useSourcifyMetadata(address, provider?.network.chainId);
const mint = addressCtx === AddressContext.FROM && address === ZERO_ADDRESS;
const burn = addressCtx === AddressContext.TO && address === ZERO_ADDRESS;
diff --git a/src/components/ETH2USDValue.tsx b/src/components/ETH2USDValue.tsx
deleted file mode 100644
index 53ece53..0000000
--- a/src/components/ETH2USDValue.tsx
+++ /dev/null
@@ -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 = ({
- ethAmount,
- eth2USDValue,
-}) => {
- const value = ethAmount.mul(eth2USDValue).div(10 ** 8);
-
- return (
-
- $
-
- {commify(FixedNumber.fromValue(value, 18).round(2).toString())}
-
-
- );
-};
-
-export default React.memo(ETH2USDValue);
diff --git a/src/components/FiatValue.tsx b/src/components/FiatValue.tsx
new file mode 100644
index 0000000..ae950c9
--- /dev/null
+++ b/src/components/FiatValue.tsx
@@ -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 = ({ value }) => (
+
+ $
+
+ {commify(FixedNumber.fromValue(value, 18).round(2).toString())}
+
+
+);
+
+export default FiatValue;
diff --git a/src/components/InternalTransactionOperation.tsx b/src/components/InternalTransactionOperation.tsx
index 3037dd2..d102be9 100644
--- a/src/components/InternalTransactionOperation.tsx
+++ b/src/components/InternalTransactionOperation.tsx
@@ -1,5 +1,4 @@
import React from "react";
-import { BigNumber } from "@ethersproject/bignumber";
import InternalTransfer from "./InternalTransfer";
import InternalSelfDestruct from "./InternalSelfDestruct";
import InternalCreate from "./InternalCreate";
@@ -8,20 +7,14 @@ import { TransactionData, InternalOperation, OperationType } from "../types";
type InternalTransactionOperationProps = {
txData: TransactionData;
internalOp: InternalOperation;
- // TODO: migrate all this logic to SWR
- ethUSDPrice: BigNumber | undefined;
};
const InternalTransactionOperation: React.FC<
InternalTransactionOperationProps
-> = ({ txData, internalOp, ethUSDPrice }) => (
+> = ({ txData, internalOp }) => (
<>
{internalOp.type === OperationType.TRANSFER && (
-
+
)}
{internalOp.type === OperationType.SELF_DESTRUCT && (
diff --git a/src/components/InternalTransfer.tsx b/src/components/InternalTransfer.tsx
index 173c74e..0faeb77 100644
--- a/src/components/InternalTransfer.tsx
+++ b/src/components/InternalTransfer.tsx
@@ -1,5 +1,4 @@
import React, { useContext } from "react";
-import { BigNumber } from "@ethersproject/bignumber";
import { formatEther } from "@ethersproject/units";
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import { faAngleRight } from "@fortawesome/free-solid-svg-icons/faAngleRight";
@@ -11,19 +10,17 @@ import USDAmount from "./USDAmount";
import { RuntimeContext } from "../useRuntime";
import { useHasCode } from "../useErigonHooks";
import { useChainInfo } from "../useChainInfo";
+import { useETHUSDOracle } from "../usePriceOracle";
import { TransactionData, InternalOperation } from "../types";
type InternalTransferProps = {
txData: TransactionData;
internalOp: InternalOperation;
- // TODO: migrate all this logic to SWR
- ethUSDPrice: BigNumber | undefined;
};
const InternalTransfer: React.FC = ({
txData,
internalOp,
- ethUSDPrice,
}) => {
const {
nativeCurrency: { symbol, decimals },
@@ -36,6 +33,10 @@ const InternalTransfer: React.FC = ({
internalOp.to === txData.confirmedData.miner;
const { provider } = useContext(RuntimeContext);
+ const blockETHUSDPrice = useETHUSDOracle(
+ provider,
+ txData.confirmedData?.blockNumber
+ );
const fromHasCode = useHasCode(
provider,
internalOp.from,
@@ -99,12 +100,12 @@ const InternalTransfer: React.FC = ({
{formatEther(internalOp.value)} {symbol}
- {ethUSDPrice && (
+ {blockETHUSDPrice && (
diff --git a/src/components/TransactionDetailsValue.tsx b/src/components/TransactionDetailsValue.tsx
new file mode 100644
index 0000000..4d09e25
--- /dev/null
+++ b/src/components/TransactionDetailsValue.tsx
@@ -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 = ({
+ 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 (
+ <>
+ {symbol}{" "}
+ {fiatValue && (
+
+
+
+ )}
+ >
+ );
+};
+
+export default TransactionDetailsValue;
diff --git a/src/search/TransactionItem.tsx b/src/search/TransactionItem.tsx
index 3fee32c..94e4820 100644
--- a/src/search/TransactionItem.tsx
+++ b/src/search/TransactionItem.tsx
@@ -1,6 +1,4 @@
import React, { useContext } from "react";
-import { BlockTag } from "@ethersproject/abstract-provider";
-import { BigNumber } from "@ethersproject/bignumber";
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import { faExclamationCircle } from "@fortawesome/free-solid-svg-icons/faExclamationCircle";
import MethodName from "../components/MethodName";
@@ -14,25 +12,23 @@ import TransactionDirection, {
Flags,
} from "../components/TransactionDirection";
import TransactionValue from "../components/TransactionValue";
+import TransactionItemFiatFee from "./TransactionItemFiatFee";
import { ProcessedTransaction } from "../types";
import { FeeDisplay } from "./useFeeToggler";
import { RuntimeContext } from "../useRuntime";
import { useHasCode } from "../useErigonHooks";
import { formatValue } from "../components/formatter";
-import ETH2USDValue from "../components/ETH2USDValue";
type TransactionItemProps = {
tx: ProcessedTransaction;
selectedAddress?: string;
feeDisplay: FeeDisplay;
- priceMap: Record;
};
const TransactionItem: React.FC = ({
tx,
selectedAddress,
feeDisplay,
- priceMap,
}) => {
const { provider } = useContext(RuntimeContext);
const toHasCode = useHasCode(
@@ -130,15 +126,9 @@ const TransactionItem: React.FC = ({
{feeDisplay === FeeDisplay.TX_FEE && formatValue(tx.fee, 18)}
- {feeDisplay === FeeDisplay.TX_FEE_USD &&
- (priceMap[tx.blockNumber] ? (
-
- ) : (
- "N/A"
- ))}
+ {feeDisplay === FeeDisplay.TX_FEE_USD && (
+
+ )}
{feeDisplay === FeeDisplay.GAS_PRICE && formatValue(tx.gasPrice, 9)}
diff --git a/src/search/TransactionItemFiatFee.tsx b/src/search/TransactionItemFiatFee.tsx
new file mode 100644
index 0000000..813bd22
--- /dev/null
+++ b/src/search/TransactionItemFiatFee.tsx
@@ -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
= ({
+ blockTag,
+ fee,
+}) => {
+ const { provider } = useContext(RuntimeContext);
+ const eth2USDValue = useETHUSDOracle(provider, blockTag);
+ const fiatValue =
+ eth2USDValue !== undefined ? fee.mul(eth2USDValue).div(10 ** 8) : undefined;
+
+ return fiatValue ? : <>N/A>;
+};
+
+export default TransactionItemFiatFee;
diff --git a/src/sourcify/useSourcify.ts b/src/sourcify/useSourcify.ts
index 0ae3958..1ef4150 100644
--- a/src/sourcify/useSourcify.ts
+++ b/src/sourcify/useSourcify.ts
@@ -4,6 +4,7 @@ import { ErrorDescription } from "@ethersproject/abi/lib/interface";
import useSWRImmutable from "swr/immutable";
import { ChecksummedAddress, TransactionData } from "../types";
import { sourcifyMetadata, SourcifySource, sourcifySourceFile } from "../url";
+import { useAppConfigContext } from "../useAppConfig";
export type UserMethod = {
notice?: string | undefined;
@@ -98,13 +99,13 @@ const sourcifyFetcher = async (url: string) => {
export const useSourcifyMetadata = (
address: ChecksummedAddress | undefined,
- chainId: number | undefined,
- source: SourcifySource
+ chainId: number | undefined
): Metadata | null | undefined => {
+ const { sourcifySource } = useAppConfigContext();
const metadataURL = () =>
address === undefined || chainId === undefined
? null
- : sourcifyMetadata(address, chainId, source);
+ : sourcifyMetadata(address, chainId, sourcifySource);
const { data, error } = useSWRImmutable(
metadataURL,
sourcifyFetcher
diff --git a/src/special/london/London.tsx b/src/special/london/London.tsx
index 60e22f2..369d215 100644
--- a/src/special/london/London.tsx
+++ b/src/special/london/London.tsx
@@ -1,5 +1,5 @@
import React, { useContext } from "react";
-import { useLatestBlock } from "../../useLatestBlock";
+import { useLatestBlockHeader } from "../../useLatestBlock";
import { RuntimeContext } from "../../useRuntime";
import Countdown from "./Countdown";
import Blocks from "./Blocks";
@@ -7,7 +7,7 @@ import { londonBlockNumber } from "./params";
const London: React.FC = () => {
const { provider } = useContext(RuntimeContext);
- const block = useLatestBlock(provider);
+ const block = useLatestBlockHeader(provider);
if (!provider || !block) {
return ;
}
diff --git a/src/transaction/Details.tsx b/src/transaction/Details.tsx
index a34a212..62844ff 100644
--- a/src/transaction/Details.tsx
+++ b/src/transaction/Details.tsx
@@ -17,12 +17,13 @@ import NavNonce from "./NavNonce";
import Timestamp from "../components/Timestamp";
import InternalTransactionOperation from "../components/InternalTransactionOperation";
import MethodName from "../components/MethodName";
+import TransactionDetailsValue from "../components/TransactionDetailsValue";
import TransactionType from "../components/TransactionType";
+import TransactionFee from "./TransactionFee";
import RewardSplit from "./RewardSplit";
import GasValue from "../components/GasValue";
import USDValue from "../components/USDValue";
import FormattedBalance from "../components/FormattedBalance";
-import ETH2USDValue from "../components/ETH2USDValue";
import TokenTransferItem from "../TokenTransferItem";
import { TransactionData } from "../types";
import PercentageBar from "../components/PercentageBar";
@@ -36,7 +37,6 @@ import {
use4Bytes,
useTransactionDescription,
} from "../use4Bytes";
-import { useAppConfigContext } from "../useAppConfig";
import {
useError,
useSourcifyMetadata,
@@ -81,12 +81,7 @@ const Details: React.FC = ({ txData }) => {
return false;
}, [txData, internalOps]);
- const { sourcifySource } = useAppConfigContext();
- const metadata = useSourcifyMetadata(
- txData?.to,
- provider?.network.chainId,
- sourcifySource
- );
+ const metadata = useSourcifyMetadata(txData?.to, provider?.network.chainId);
const txDesc = useSourcifyTransactionDescription(metadata, txData);
const userDoc = metadata?.output.userdoc;
@@ -285,7 +280,6 @@ const Details: React.FC = ({ txData }) => {
key={i}
txData={txData}
internalOp={op}
- ethUSDPrice={blockETHUSDPrice}
/>
))}
@@ -308,15 +302,10 @@ const Details: React.FC