otterscan/src/useErigonHooks.ts

26 lines
698 B
TypeScript
Raw Normal View History

2021-07-17 18:00:08 +00:00
import { ethers } from "ethers";
import { useState, useEffect } from "react";
import { getTransactionTransfers } from "./nodeFunctions";
import { TransactionData, Transfer } from "./types";
export const useInternalTransfers = (
provider: ethers.providers.JsonRpcProvider | undefined,
txData: TransactionData | undefined
) => {
const [transfers, setTransfers] = useState<Transfer[]>();
useEffect(() => {
const traceTransfers = async () => {
if (!provider || !txData) {
return;
}
const _transfers = await getTransactionTransfers(provider, txData);
setTransfers(_transfers);
};
traceTransfers();
}, [provider, txData]);
return transfers;
};