Fixed transaction information service on frontend

Also fixed request body on `/txinfo/ethereum_blockchain`.
pull/176/head
Neeraj Kashyap 2021-08-25 06:31:58 -07:00
rodzic 0163012559
commit 8e43fff23a
3 zmienionych plików z 41 dodań i 14 usunięć

Wyświetl plik

@ -88,10 +88,10 @@ class ContractABI(BaseModel):
class EthereumTransaction(BaseModel): class EthereumTransaction(BaseModel):
gas: int gas: int
gasPrice: int gas_price: int
value: int value: int
from_address: str from_address: str = Field(alias="from")
to_address: Optional[str] to_address: Optional[str] = Field(alias="to")
hash: Optional[str] = None hash: Optional[str] = None
block_hash: Optional[str] = Field(default=None, alias="blockHash") block_hash: Optional[str] = Field(default=None, alias="blockHash")
block_number: Optional[int] = Field(default=None, alias="blockNumber") block_number: Optional[int] = Field(default=None, alias="blockNumber")

Wyświetl plik

@ -17,15 +17,15 @@ const Entry = () => {
useEffect(() => { useEffect(() => {
if (typeof window !== "undefined") { if (typeof window !== "undefined") {
if (ui.currentTransaction) { if (ui?.currentTransaction) {
document.title = `Stream details: ${ui.currentTransaction.hash}`; document.title = `Stream details: ${ui.currentTransaction.hash}`;
} else { } else {
document.title = `Stream`; document.title = `Stream`;
} }
} }
}, [ui.currentTransaction]); }, [ui?.currentTransaction]);
if (ui.currentTransaction) { if (ui?.currentTransaction) {
return <StreamEntryDetails />; return <StreamEntryDetails />;
} else } else
return ( return (

Wyświetl plik

@ -3,19 +3,46 @@ import { TxInfoService } from "../services";
import { queryCacheProps } from "./hookCommon"; import { queryCacheProps } from "./hookCommon";
import { useToast } from "."; import { useToast } from ".";
const useTxInfo = (transaction) => { const useTxInfo = (wrappedEvent) => {
const toast = useToast(); 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 getTxInfo = async () => {
const response = await TxInfoService.getTxInfo(transaction); const response = await TxInfoService.getTxInfo({ tx: { ...transaction } });
console.log("TXINFO: response:", response);
return response.data; return response.data;
}; };
const { data, isLoading, isFetchedAfterMount, refetch, isError, error } = const { data, isLoading, isFetchedAfterMount, refetch, isError, error } =
useQuery(["txinfo", transaction.tx && transaction.tx.hash], getTxInfo, { useQuery(
...queryCacheProps, ["txinfo", transaction ? transaction.hash : "unknown"],
enabled: !!transaction.tx, getTxInfo,
onError: (error) => toast(error, "error"), {
}); ...queryCacheProps,
const isFetching = !!transaction.tx; enabled: !!transaction,
onError: (error) => toast(error, "error"),
}
);
const isFetching = !!transaction;
return { return {
data, data,
isFetchedAfterMount, isFetchedAfterMount,