diff --git a/src/execution/address/AddressERC20Results.tsx b/src/execution/address/AddressERC20Results.tsx index 1ca286b44..a5f98097c 100644 --- a/src/execution/address/AddressERC20Results.tsx +++ b/src/execution/address/AddressERC20Results.tsx @@ -6,6 +6,7 @@ import { } from "../../ots2/usePrototypeTransferHooks"; import { usePageNumber } from "../../ots2/useUIHooks"; import { PAGE_SIZE } from "../../params"; +import { findTokenTransfersInLogs } from "../../useErigonHooks"; import { RuntimeContext } from "../../useRuntime"; import { usePageTitle } from "../../useTitle"; import { AddressAwareComponentProps } from "../types"; @@ -53,6 +54,7 @@ const AddressERC20Results: FC = ({ address }) => { to: m.receipt.to, value: m.transaction.value, type: m.transaction.type, + tokenTransfers: findTokenTransfersInLogs(m.receipt.logs), }), ), [results], diff --git a/src/execution/address/AddressERC721Results.tsx b/src/execution/address/AddressERC721Results.tsx index 4b48a3096..9447eae33 100644 --- a/src/execution/address/AddressERC721Results.tsx +++ b/src/execution/address/AddressERC721Results.tsx @@ -39,6 +39,8 @@ const AddressERC721Results: FC = ({ address }) => { to: m.receipt.to, value: m.transaction.value, type: m.transaction.type, + // TODO: Token transfers for ERC-721 tokens + tokenTransfers: [], }), ), [results], diff --git a/src/execution/address/ERC20Item.tsx b/src/execution/address/ERC20Item.tsx index 1fa0ed385..921d7326f 100644 --- a/src/execution/address/ERC20Item.tsx +++ b/src/execution/address/ERC20Item.tsx @@ -7,7 +7,6 @@ import TransactionDirection from "../../components/TransactionDirection"; import TransactionLink from "../../components/TransactionLink"; import { TokenTransfer } from "../../types"; import { BlockNumberContext } from "../../useBlockTagContext"; -import { useTokenTransfers, useTxData } from "../../useErigonHooks"; import { RuntimeContext } from "../../useRuntime"; import TransactionAddress from "../components/TransactionAddress"; import { AddressAwareComponentProps } from "../types"; @@ -23,6 +22,7 @@ export type ERC20ItemProps = AddressAwareComponentProps & { to: string | null; value: bigint; type: number; + tokenTransfers: TokenTransfer[]; }; const ERC20Item: FC = ({ @@ -36,10 +36,9 @@ const ERC20Item: FC = ({ to, value, type, + tokenTransfers, }) => { const { provider } = useContext(RuntimeContext); - const txData = useTxData(provider, hash); - const tokenTransfers = useTokenTransfers(txData); return ( diff --git a/src/useErigonHooks.ts b/src/useErigonHooks.ts index 9f934b8e3..78d08ec6c 100644 --- a/src/useErigonHooks.ts +++ b/src/useErigonHooks.ts @@ -4,6 +4,7 @@ import { BlockTag, Contract, JsonRpcApiProvider, + Log, TransactionReceiptParams, TransactionResponseParams, ZeroAddress, @@ -327,6 +328,19 @@ export const useTxData = ( return txData; }; +export const findTokenTransfersInLogs = ( + logs: readonly Log[], +): TokenTransfer[] => { + return logs + .filter((l) => l.topics.length === 3 && l.topics[0] === TRANSFER_TOPIC) + .map((l) => ({ + token: l.address, + from: getAddress(dataSlice(getBytes(l.topics[1]), 12)), + to: getAddress(dataSlice(getBytes(l.topics[2]), 12)), + value: BigInt(l.data), + })); +}; + export const useTokenTransfers = ( txData?: TransactionData | null, ): TokenTransfer[] | undefined => { @@ -338,14 +352,7 @@ export const useTokenTransfers = ( return undefined; } - return txData.confirmedData.logs - .filter((l) => l.topics.length === 3 && l.topics[0] === TRANSFER_TOPIC) - .map((l) => ({ - token: l.address, - from: getAddress(dataSlice(getBytes(l.topics[1]), 12)), - to: getAddress(dataSlice(getBytes(l.topics[2]), 12)), - value: BigInt(l.data), - })); + return findTokenTransfersInLogs(txData.confirmedData.logs); }, [txData]); return transfers;