Add current balance
This commit is contained in:
parent
d00d6cba0b
commit
22a0bc5888
|
@ -2,6 +2,7 @@ import React, { useContext, useEffect, useMemo, useState } from "react";
|
||||||
import { BlockTag } from "@ethersproject/providers";
|
import { BlockTag } from "@ethersproject/providers";
|
||||||
import ContentFrame from "../ContentFrame";
|
import ContentFrame from "../ContentFrame";
|
||||||
import InfoRow from "../components/InfoRow";
|
import InfoRow from "../components/InfoRow";
|
||||||
|
import FormattedBalance from "../components/FormattedBalance";
|
||||||
import TransactionAddress from "../components/TransactionAddress";
|
import TransactionAddress from "../components/TransactionAddress";
|
||||||
import Copy from "../components/Copy";
|
import Copy from "../components/Copy";
|
||||||
import TransactionLink from "../components/TransactionLink";
|
import TransactionLink from "../components/TransactionLink";
|
||||||
|
@ -17,7 +18,7 @@ import { RuntimeContext } from "../useRuntime";
|
||||||
import { useParams, useSearchParams } from "react-router-dom";
|
import { useParams, useSearchParams } from "react-router-dom";
|
||||||
import { ChecksummedAddress, ProcessedTransaction } from "../types";
|
import { ChecksummedAddress, ProcessedTransaction } from "../types";
|
||||||
import { useContractsMetadata } from "../hooks";
|
import { useContractsMetadata } from "../hooks";
|
||||||
import { useContractCreator } from "../useErigonHooks";
|
import { useAddressBalance, useContractCreator } from "../useErigonHooks";
|
||||||
|
|
||||||
type AddressTransactionResultsProps = {
|
type AddressTransactionResultsProps = {
|
||||||
address: ChecksummedAddress;
|
address: ChecksummedAddress;
|
||||||
|
@ -122,12 +123,17 @@ const AddressTransactionResults: React.FC<AddressTransactionResultsProps> = ({
|
||||||
return _addresses;
|
return _addresses;
|
||||||
}, [address, page]);
|
}, [address, page]);
|
||||||
const metadatas = useContractsMetadata(addresses, provider);
|
const metadatas = useContractsMetadata(addresses, provider);
|
||||||
|
const balance = useAddressBalance(provider, address);
|
||||||
const creator = useContractCreator(provider, address);
|
const creator = useContractCreator(provider, address);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<ContentFrame tabs>
|
<ContentFrame tabs>
|
||||||
<SelectionContext.Provider value={selectionCtx}>
|
<SelectionContext.Provider value={selectionCtx}>
|
||||||
<InfoRow title="Balance"></InfoRow>
|
{balance && (
|
||||||
|
<InfoRow title="Balance">
|
||||||
|
<FormattedBalance value={balance} /> Ether{" "}
|
||||||
|
</InfoRow>
|
||||||
|
)}
|
||||||
{creator && (
|
{creator && (
|
||||||
<InfoRow title="Contract creator">
|
<InfoRow title="Contract creator">
|
||||||
<div className="flex items-baseline space-x-2 -ml-1">
|
<div className="flex items-baseline space-x-2 -ml-1">
|
||||||
|
|
|
@ -658,3 +658,24 @@ const getContractCreatorFetcher =
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const useAddressBalance = (
|
||||||
|
provider: JsonRpcProvider | undefined,
|
||||||
|
address: ChecksummedAddress | undefined
|
||||||
|
): BigNumber | null | undefined => {
|
||||||
|
const [balance, setBalance] = useState<BigNumber | undefined>();
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (!provider || !address) {
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
const readBalance = async () => {
|
||||||
|
const _balance = await provider.getBalance(address);
|
||||||
|
setBalance(_balance);
|
||||||
|
};
|
||||||
|
readBalance();
|
||||||
|
}, [provider, address]);
|
||||||
|
|
||||||
|
return balance;
|
||||||
|
};
|
||||||
|
|
Loading…
Reference in New Issue