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