otterscan/src/useErigonHooks.ts

31 lines
961 B
TypeScript
Raw Normal View History

2021-07-17 18:00:08 +00:00
import { ethers } from "ethers";
import { useState, useEffect } from "react";
2021-07-21 19:06:51 +00:00
import { getInternalOperations } from "./nodeFunctions";
import { TransactionData, InternalOperation } from "./types";
2021-07-17 18:00:08 +00:00
2021-07-21 19:06:51 +00:00
export const useInternalOperations = (
2021-07-17 18:00:08 +00:00
provider: ethers.providers.JsonRpcProvider | undefined,
txData: TransactionData | undefined
2021-07-21 19:06:51 +00:00
): InternalOperation[] | undefined => {
const [intTransfers, setIntTransfers] = useState<InternalOperation[]>();
2021-07-17 18:00:08 +00:00
useEffect(() => {
const traceTransfers = async () => {
if (!provider || !txData) {
return;
}
2021-07-21 19:06:51 +00:00
const _transfers = await getInternalOperations(provider, txData);
2021-07-19 23:49:54 +00:00
for (const t of _transfers) {
t.from = provider.formatter.address(t.from);
t.to = provider.formatter.address(t.to);
t.value = provider.formatter.bigNumber(t.value);
2021-07-17 18:58:33 +00:00
}
2021-07-19 23:49:54 +00:00
setIntTransfers(_transfers);
2021-07-17 18:00:08 +00:00
};
traceTransfers();
}, [provider, txData]);
2021-07-17 18:58:33 +00:00
return intTransfers;
2021-07-17 18:00:08 +00:00
};