diff --git a/backend/moonstream/data.py b/backend/moonstream/data.py index 89926bb3..b58b871a 100644 --- a/backend/moonstream/data.py +++ b/backend/moonstream/data.py @@ -88,10 +88,10 @@ class ContractABI(BaseModel): class EthereumTransaction(BaseModel): gas: int - gasPrice: int + gas_price: int value: int - from_address: str - to_address: Optional[str] + from_address: str = Field(alias="from") + to_address: Optional[str] = Field(alias="to") hash: Optional[str] = None block_hash: Optional[str] = Field(default=None, alias="blockHash") block_number: Optional[int] = Field(default=None, alias="blockNumber") diff --git a/frontend/pages/stream/index.js b/frontend/pages/stream/index.js index dc00884c..c56a5357 100644 --- a/frontend/pages/stream/index.js +++ b/frontend/pages/stream/index.js @@ -17,15 +17,15 @@ const Entry = () => { useEffect(() => { if (typeof window !== "undefined") { - if (ui.currentTransaction) { + if (ui?.currentTransaction) { document.title = `Stream details: ${ui.currentTransaction.hash}`; } else { document.title = `Stream`; } } - }, [ui.currentTransaction]); + }, [ui?.currentTransaction]); - if (ui.currentTransaction) { + if (ui?.currentTransaction) { return ; } else return ( diff --git a/frontend/src/core/hooks/useTxInfo.js b/frontend/src/core/hooks/useTxInfo.js index 602eda5a..92dd11f6 100644 --- a/frontend/src/core/hooks/useTxInfo.js +++ b/frontend/src/core/hooks/useTxInfo.js @@ -3,19 +3,46 @@ import { TxInfoService } from "../services"; import { queryCacheProps } from "./hookCommon"; import { useToast } from "."; -const useTxInfo = (transaction) => { +const useTxInfo = (wrappedEvent) => { const toast = useToast(); + + let event = {}; + if (wrappedEvent?.tx) { + event = wrappedEvent.tx; + } + + console.log("TXINFO: wrappedEvent:", wrappedEvent); + console.log("TXINFO: event:", event); + + let transaction = null; + if (event.event_type === "ethereum_blockchain") { + transaction = event.event_data; + } else if (event.event_type === "ethereum_txpool") { + transaction = { + from: event.event_data.from, + nonce: event.event_data.nonce, + ...event.event_data.transaction, + }; + } + + console.log("TXINFO: transaction:", transaction); + const getTxInfo = async () => { - const response = await TxInfoService.getTxInfo(transaction); + const response = await TxInfoService.getTxInfo({ tx: { ...transaction } }); + console.log("TXINFO: response:", response); return response.data; }; const { data, isLoading, isFetchedAfterMount, refetch, isError, error } = - useQuery(["txinfo", transaction.tx && transaction.tx.hash], getTxInfo, { - ...queryCacheProps, - enabled: !!transaction.tx, - onError: (error) => toast(error, "error"), - }); - const isFetching = !!transaction.tx; + useQuery( + ["txinfo", transaction ? transaction.hash : "unknown"], + getTxInfo, + { + ...queryCacheProps, + enabled: !!transaction, + onError: (error) => toast(error, "error"), + } + ); + const isFetching = !!transaction; return { data, isFetchedAfterMount,