2021-07-17 18:00:08 +00:00
|
|
|
import { ethers } from "ethers";
|
|
|
|
import { useState, useEffect } from "react";
|
2021-07-17 18:58:33 +00:00
|
|
|
import {
|
|
|
|
getTransactionSelfDestructs,
|
|
|
|
getTransactionTransfers,
|
|
|
|
} from "./nodeFunctions";
|
|
|
|
import { InternalTransfers, TransactionData } from "./types";
|
2021-07-17 18:00:08 +00:00
|
|
|
|
|
|
|
export const useInternalTransfers = (
|
|
|
|
provider: ethers.providers.JsonRpcProvider | undefined,
|
|
|
|
txData: TransactionData | undefined
|
2021-07-17 18:58:33 +00:00
|
|
|
): InternalTransfers | undefined => {
|
|
|
|
const [intTransfers, setIntTransfers] = useState<InternalTransfers>();
|
2021-07-17 18:00:08 +00:00
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
const traceTransfers = async () => {
|
|
|
|
if (!provider || !txData) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const _transfers = await getTransactionTransfers(provider, txData);
|
2021-07-17 18:58:33 +00:00
|
|
|
const _selfDestructs = await getTransactionSelfDestructs(
|
|
|
|
provider,
|
|
|
|
txData
|
|
|
|
);
|
|
|
|
for (const s of _selfDestructs) {
|
2021-07-19 07:14:56 +00:00
|
|
|
s.from = provider.formatter.address(s.from);
|
|
|
|
s.to = provider.formatter.address(s.to);
|
2021-07-17 18:58:33 +00:00
|
|
|
s.value = provider.formatter.bigNumber(s.value);
|
|
|
|
}
|
|
|
|
setIntTransfers({ transfers: _transfers, selfDestructs: _selfDestructs });
|
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
|
|
|
};
|