Use more specific import to allow ethers tree shaking
This commit is contained in:
parent
a774e85ea0
commit
46c229169b
|
@ -1,6 +1,6 @@
|
||||||
import React, { useState, useEffect, useMemo, useContext } from "react";
|
import React, { useState, useEffect, useMemo, useContext } from "react";
|
||||||
import { useParams, useLocation, useHistory } from "react-router-dom";
|
import { useParams, useLocation, useHistory } from "react-router-dom";
|
||||||
import { ethers } from "ethers";
|
import { getAddress, isAddress } from "@ethersproject/address";
|
||||||
import queryString from "query-string";
|
import queryString from "query-string";
|
||||||
import Blockies from "react-blockies";
|
import Blockies from "react-blockies";
|
||||||
import StandardFrame from "./StandardFrame";
|
import StandardFrame from "./StandardFrame";
|
||||||
|
@ -43,12 +43,12 @@ const AddressTransactions: React.FC = () => {
|
||||||
|
|
||||||
// If it looks like it is an ENS name, try to resolve it
|
// If it looks like it is an ENS name, try to resolve it
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (ethers.utils.isAddress(params.addressOrName)) {
|
if (isAddress(params.addressOrName)) {
|
||||||
setENS(false);
|
setENS(false);
|
||||||
setError(false);
|
setError(false);
|
||||||
|
|
||||||
// Normalize to checksummed address
|
// Normalize to checksummed address
|
||||||
const _checksummedAddress = ethers.utils.getAddress(params.addressOrName);
|
const _checksummedAddress = getAddress(params.addressOrName);
|
||||||
if (_checksummedAddress !== params.addressOrName) {
|
if (_checksummedAddress !== params.addressOrName) {
|
||||||
// Request came with a non-checksummed address; fix the URL
|
// Request came with a non-checksummed address; fix the URL
|
||||||
history.replace(
|
history.replace(
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
import React, { useEffect, useMemo, useContext } from "react";
|
import React, { useEffect, useMemo, useContext } from "react";
|
||||||
import { useParams, NavLink } from "react-router-dom";
|
import { useParams, NavLink } from "react-router-dom";
|
||||||
import { BigNumber, ethers } from "ethers";
|
import { BigNumber } from "@ethersproject/bignumber";
|
||||||
|
import { commify } from "@ethersproject/units";
|
||||||
|
import { toUtf8String } from "@ethersproject/strings";
|
||||||
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
|
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
|
||||||
import { faBurn } from "@fortawesome/free-solid-svg-icons/faBurn";
|
import { faBurn } from "@fortawesome/free-solid-svg-icons/faBurn";
|
||||||
import StandardFrame from "./StandardFrame";
|
import StandardFrame from "./StandardFrame";
|
||||||
|
@ -38,7 +40,7 @@ const Block: React.FC = () => {
|
||||||
|
|
||||||
const extraStr = useMemo(() => {
|
const extraStr = useMemo(() => {
|
||||||
try {
|
try {
|
||||||
return block && ethers.utils.toUtf8String(block.extraData);
|
return block && toUtf8String(block.extraData);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error("Error while converting block extra data to string");
|
console.error("Error while converting block extra data to string");
|
||||||
console.error(err);
|
console.error(err);
|
||||||
|
@ -71,9 +73,7 @@ const Block: React.FC = () => {
|
||||||
{block && (
|
{block && (
|
||||||
<ContentFrame>
|
<ContentFrame>
|
||||||
<InfoRow title="Block Height">
|
<InfoRow title="Block Height">
|
||||||
<span className="font-bold">
|
<span className="font-bold">{commify(block.number)}</span>
|
||||||
{ethers.utils.commify(block.number)}
|
|
||||||
</span>
|
|
||||||
</InfoRow>
|
</InfoRow>
|
||||||
<InfoRow title="Timestamp">
|
<InfoRow title="Timestamp">
|
||||||
<Timestamp value={block.timestamp} />
|
<Timestamp value={block.timestamp} />
|
||||||
|
@ -109,9 +109,7 @@ const Block: React.FC = () => {
|
||||||
<InfoRow title="Uncles Reward">
|
<InfoRow title="Uncles Reward">
|
||||||
<TransactionValue value={block.unclesReward} />
|
<TransactionValue value={block.unclesReward} />
|
||||||
</InfoRow>
|
</InfoRow>
|
||||||
<InfoRow title="Size">
|
<InfoRow title="Size">{commify(block.size)} bytes</InfoRow>
|
||||||
{ethers.utils.commify(block.size)} bytes
|
|
||||||
</InfoRow>
|
|
||||||
{block.baseFeePerGas && (
|
{block.baseFeePerGas && (
|
||||||
<InfoRow title="Base Fee">
|
<InfoRow title="Base Fee">
|
||||||
<span>
|
<span>
|
||||||
|
@ -156,11 +154,9 @@ const Block: React.FC = () => {
|
||||||
<span className="font-data">{block.extraData}</span>)
|
<span className="font-data">{block.extraData}</span>)
|
||||||
</InfoRow>
|
</InfoRow>
|
||||||
<InfoRow title="Ether Price">N/A</InfoRow>
|
<InfoRow title="Ether Price">N/A</InfoRow>
|
||||||
<InfoRow title="Difficult">
|
<InfoRow title="Difficult">{commify(block.difficulty)}</InfoRow>
|
||||||
{ethers.utils.commify(block.difficulty)}
|
|
||||||
</InfoRow>
|
|
||||||
<InfoRow title="Total Difficult">
|
<InfoRow title="Total Difficult">
|
||||||
{ethers.utils.commify(block.totalDifficulty.toString())}
|
{commify(block.totalDifficulty.toString())}
|
||||||
</InfoRow>
|
</InfoRow>
|
||||||
<InfoRow title="Hash">
|
<InfoRow title="Hash">
|
||||||
<HexValue value={block.hash} />
|
<HexValue value={block.hash} />
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import React, { useMemo, useContext } from "react";
|
import React, { useMemo, useContext } from "react";
|
||||||
import { useParams, useLocation } from "react-router";
|
import { useParams, useLocation } from "react-router";
|
||||||
import { ethers } from "ethers";
|
import { BigNumber } from "@ethersproject/bignumber";
|
||||||
import queryString from "query-string";
|
import queryString from "query-string";
|
||||||
import StandardFrame from "./StandardFrame";
|
import StandardFrame from "./StandardFrame";
|
||||||
import BlockTransactionHeader from "./block/BlockTransactionHeader";
|
import BlockTransactionHeader from "./block/BlockTransactionHeader";
|
||||||
|
@ -30,7 +30,7 @@ const BlockTransactions: React.FC = () => {
|
||||||
}
|
}
|
||||||
|
|
||||||
const blockNumber = useMemo(
|
const blockNumber = useMemo(
|
||||||
() => ethers.BigNumber.from(params.blockNumber),
|
() => BigNumber.from(params.blockNumber),
|
||||||
[params.blockNumber]
|
[params.blockNumber]
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import React, { useState, useContext } from "react";
|
import React, { useState, useContext } from "react";
|
||||||
import { NavLink, useHistory } from "react-router-dom";
|
import { NavLink, useHistory } from "react-router-dom";
|
||||||
import { ethers } from "ethers";
|
import { commify } from "@ethersproject/units";
|
||||||
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
|
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
|
||||||
import { faBurn } from "@fortawesome/free-solid-svg-icons/faBurn";
|
import { faBurn } from "@fortawesome/free-solid-svg-icons/faBurn";
|
||||||
import Logo from "./Logo";
|
import Logo from "./Logo";
|
||||||
|
@ -74,7 +74,7 @@ const Home: React.FC = () => {
|
||||||
className="mx-auto flex flex-col items-center space-y-1 mt-5 text-sm text-gray-500 hover:text-link-blue"
|
className="mx-auto flex flex-col items-center space-y-1 mt-5 text-sm text-gray-500 hover:text-link-blue"
|
||||||
to={blockURL(latestBlock.number)}
|
to={blockURL(latestBlock.number)}
|
||||||
>
|
>
|
||||||
<div>Latest block: {ethers.utils.commify(latestBlock.number)}</div>
|
<div>Latest block: {commify(latestBlock.number)}</div>
|
||||||
<Timestamp value={latestBlock.timestamp} />
|
<Timestamp value={latestBlock.timestamp} />
|
||||||
</NavLink>
|
</NavLink>
|
||||||
)}
|
)}
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
import React, { useState, useEffect, useMemo, useContext } from "react";
|
import React, { useState, useEffect, useMemo, useContext } from "react";
|
||||||
import { ethers } from "ethers";
|
import { Contract } from "@ethersproject/contracts";
|
||||||
|
import { commify, formatUnits } from "@ethersproject/units";
|
||||||
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
|
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
|
||||||
import { faGasPump } from "@fortawesome/free-solid-svg-icons/faGasPump";
|
import { faGasPump } from "@fortawesome/free-solid-svg-icons/faGasPump";
|
||||||
import AggregatorV3Interface from "@chainlink/contracts/abi/v0.8/AggregatorV3Interface.json";
|
import AggregatorV3Interface from "@chainlink/contracts/abi/v0.8/AggregatorV3Interface.json";
|
||||||
|
@ -19,17 +20,13 @@ const PriceBox: React.FC = () => {
|
||||||
const ethFeed = useMemo(
|
const ethFeed = useMemo(
|
||||||
() =>
|
() =>
|
||||||
provider &&
|
provider &&
|
||||||
new ethers.Contract("eth-usd.data.eth", AggregatorV3Interface, provider),
|
new Contract("eth-usd.data.eth", AggregatorV3Interface, provider),
|
||||||
[provider]
|
[provider]
|
||||||
);
|
);
|
||||||
const gasFeed = useMemo(
|
const gasFeed = useMemo(
|
||||||
() =>
|
() =>
|
||||||
provider &&
|
provider &&
|
||||||
new ethers.Contract(
|
new Contract("fast-gas-gwei.data.eth", AggregatorV3Interface, provider),
|
||||||
"fast-gas-gwei.data.eth",
|
|
||||||
AggregatorV3Interface,
|
|
||||||
provider
|
|
||||||
),
|
|
||||||
[provider]
|
[provider]
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -57,9 +54,7 @@ const PriceBox: React.FC = () => {
|
||||||
}
|
}
|
||||||
|
|
||||||
const price = latestPriceData.answer.div(10 ** (ETH_FEED_DECIMALS - 2));
|
const price = latestPriceData.answer.div(10 ** (ETH_FEED_DECIMALS - 2));
|
||||||
const formattedPrice = ethers.utils.commify(
|
const formattedPrice = commify(formatUnits(price, 2));
|
||||||
ethers.utils.formatUnits(price, 2)
|
|
||||||
);
|
|
||||||
|
|
||||||
const timestamp = new Date(latestPriceData.updatedAt * 1000);
|
const timestamp = new Date(latestPriceData.updatedAt * 1000);
|
||||||
return [formattedPrice, timestamp];
|
return [formattedPrice, timestamp];
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
import { useLocation, useHistory } from "react-router-dom";
|
import { useLocation, useHistory } from "react-router-dom";
|
||||||
import { ethers } from "ethers";
|
import { isAddress } from "@ethersproject/address";
|
||||||
|
import { isHexString } from "@ethersproject/bytes";
|
||||||
import queryString from "query-string";
|
import queryString from "query-string";
|
||||||
|
|
||||||
type SearchParams = {
|
type SearchParams = {
|
||||||
|
@ -12,11 +13,11 @@ const Search: React.FC = () => {
|
||||||
|
|
||||||
const qs = queryString.parse(location.search);
|
const qs = queryString.parse(location.search);
|
||||||
const q = (qs.q ?? "").toString();
|
const q = (qs.q ?? "").toString();
|
||||||
if (ethers.utils.isAddress(q)) {
|
if (isAddress(q)) {
|
||||||
history.replace(`/address/${q}`);
|
history.replace(`/address/${q}`);
|
||||||
return <></>;
|
return <></>;
|
||||||
}
|
}
|
||||||
if (ethers.utils.isHexString(q, 32)) {
|
if (isHexString(q, 32)) {
|
||||||
history.replace(`/tx/${q}`);
|
history.replace(`/tx/${q}`);
|
||||||
return <></>;
|
return <></>;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import React, { useContext } from "react";
|
import React, { useContext } from "react";
|
||||||
import { ethers } from "ethers";
|
import { BlockTag } from "@ethersproject/abstract-provider";
|
||||||
import StandardSubtitle from "../StandardSubtitle";
|
import StandardSubtitle from "../StandardSubtitle";
|
||||||
import BlockLink from "../components/BlockLink";
|
import BlockLink from "../components/BlockLink";
|
||||||
import NavBlock from "./NavBlock";
|
import NavBlock from "./NavBlock";
|
||||||
|
@ -8,7 +8,7 @@ import { useLatestBlockNumber } from "../useLatestBlock";
|
||||||
import { blockTxsURL } from "../url";
|
import { blockTxsURL } from "../url";
|
||||||
|
|
||||||
type BlockTransactionHeaderProps = {
|
type BlockTransactionHeaderProps = {
|
||||||
blockTag: ethers.providers.BlockTag;
|
blockTag: BlockTag;
|
||||||
};
|
};
|
||||||
|
|
||||||
const BlockTransactionHeader: React.FC<BlockTransactionHeaderProps> = ({
|
const BlockTransactionHeader: React.FC<BlockTransactionHeaderProps> = ({
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import React from "react";
|
import React from "react";
|
||||||
import { ethers } from "ethers";
|
import { BlockTag } from "@ethersproject/abstract-provider";
|
||||||
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
|
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
|
||||||
import { faChevronLeft } from "@fortawesome/free-solid-svg-icons/faChevronLeft";
|
import { faChevronLeft } from "@fortawesome/free-solid-svg-icons/faChevronLeft";
|
||||||
import { faChevronRight } from "@fortawesome/free-solid-svg-icons/faChevronRight";
|
import { faChevronRight } from "@fortawesome/free-solid-svg-icons/faChevronRight";
|
||||||
|
@ -8,7 +8,7 @@ import NavButton from "./NavButton";
|
||||||
type NavBlockProps = {
|
type NavBlockProps = {
|
||||||
blockNumber: number;
|
blockNumber: number;
|
||||||
latestBlockNumber: number | undefined;
|
latestBlockNumber: number | undefined;
|
||||||
urlBuilder?: (blockNumber: ethers.providers.BlockTag) => string;
|
urlBuilder?: (blockNumber: BlockTag) => string;
|
||||||
};
|
};
|
||||||
|
|
||||||
const NavBlock: React.FC<NavBlockProps> = ({
|
const NavBlock: React.FC<NavBlockProps> = ({
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
import { ethers } from "ethers";
|
|
||||||
import { NavLink } from "react-router-dom";
|
import { NavLink } from "react-router-dom";
|
||||||
|
import { BlockTag } from "@ethersproject/abstract-provider";
|
||||||
import { blockURL } from "../url";
|
import { blockURL } from "../url";
|
||||||
|
|
||||||
type NavButtonProps = {
|
type NavButtonProps = {
|
||||||
blockNum: number;
|
blockNum: number;
|
||||||
disabled?: boolean;
|
disabled?: boolean;
|
||||||
urlBuilder?: (blockNumber: ethers.providers.BlockTag) => string;
|
urlBuilder?: (blockNumber: BlockTag) => string;
|
||||||
};
|
};
|
||||||
|
|
||||||
const NavButton: React.FC<NavButtonProps> = ({
|
const NavButton: React.FC<NavButtonProps> = ({
|
||||||
|
|
|
@ -1,17 +1,18 @@
|
||||||
import React from "react";
|
import React from "react";
|
||||||
import { NavLink } from "react-router-dom";
|
import { NavLink } from "react-router-dom";
|
||||||
import { ethers } from "ethers";
|
import { BlockTag } from "@ethersproject/abstract-provider";
|
||||||
|
import { commify } from "@ethersproject/units";
|
||||||
import { blockURL } from "../url";
|
import { blockURL } from "../url";
|
||||||
|
|
||||||
type BlockLinkProps = {
|
type BlockLinkProps = {
|
||||||
blockTag: ethers.providers.BlockTag;
|
blockTag: BlockTag;
|
||||||
};
|
};
|
||||||
|
|
||||||
const BlockLink: React.FC<BlockLinkProps> = ({ blockTag }) => {
|
const BlockLink: React.FC<BlockLinkProps> = ({ blockTag }) => {
|
||||||
const isNum = typeof blockTag === "number";
|
const isNum = typeof blockTag === "number";
|
||||||
let text = blockTag;
|
let text = blockTag;
|
||||||
if (isNum) {
|
if (isNum) {
|
||||||
text = ethers.utils.commify(blockTag);
|
text = commify(blockTag);
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
import React from "react";
|
import React from "react";
|
||||||
import { ethers, BigNumber } from "ethers";
|
import { BigNumber } from "@ethersproject/bignumber";
|
||||||
|
import { commify, formatUnits } from "@ethersproject/units";
|
||||||
|
|
||||||
type FormatterBalanceProps = {
|
type FormatterBalanceProps = {
|
||||||
value: BigNumber;
|
value: BigNumber;
|
||||||
|
@ -10,9 +11,7 @@ const FormattedBalance: React.FC<FormatterBalanceProps> = ({
|
||||||
value,
|
value,
|
||||||
decimals = 18,
|
decimals = 18,
|
||||||
}) => {
|
}) => {
|
||||||
const formatted = ethers.utils.commify(
|
const formatted = commify(formatUnits(value, decimals));
|
||||||
ethers.utils.formatUnits(value, decimals)
|
|
||||||
);
|
|
||||||
const stripZeroDec = formatted.endsWith(".0")
|
const stripZeroDec = formatted.endsWith(".0")
|
||||||
? formatted.slice(0, formatted.length - 2)
|
? formatted.slice(0, formatted.length - 2)
|
||||||
: formatted;
|
: formatted;
|
||||||
|
|
|
@ -1,12 +1,13 @@
|
||||||
import React from "react";
|
import React from "react";
|
||||||
import { BigNumber, ethers } from "ethers";
|
import { BigNumber } from "@ethersproject/bignumber";
|
||||||
|
import { commify, formatUnits } from "@ethersproject/units";
|
||||||
|
|
||||||
type GasValueProps = {
|
type GasValueProps = {
|
||||||
value: BigNumber;
|
value: BigNumber;
|
||||||
};
|
};
|
||||||
|
|
||||||
const GasValue: React.FC<GasValueProps> = ({ value }) => {
|
const GasValue: React.FC<GasValueProps> = ({ value }) => {
|
||||||
return <>{ethers.utils.commify(ethers.utils.formatUnits(value, 0))}</>;
|
return <>{commify(formatUnits(value, 0))}</>;
|
||||||
};
|
};
|
||||||
|
|
||||||
export default React.memo(GasValue);
|
export default React.memo(GasValue);
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import React, { useContext } from "react";
|
import React, { useContext } from "react";
|
||||||
import { ethers } from "ethers";
|
import { formatEther } from "@ethersproject/units";
|
||||||
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
|
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
|
||||||
import { faAngleRight } from "@fortawesome/free-solid-svg-icons/faAngleRight";
|
import { faAngleRight } from "@fortawesome/free-solid-svg-icons/faAngleRight";
|
||||||
import AddressHighlighter from "./AddressHighlighter";
|
import AddressHighlighter from "./AddressHighlighter";
|
||||||
|
@ -48,7 +48,7 @@ const InternalSelfDestruct: React.FC<InternalSelfDestructProps> = ({
|
||||||
<span className="text-gray-500">
|
<span className="text-gray-500">
|
||||||
<FontAwesomeIcon icon={faAngleRight} size="1x" /> TRANSFER
|
<FontAwesomeIcon icon={faAngleRight} size="1x" /> TRANSFER
|
||||||
</span>
|
</span>
|
||||||
<span>{ethers.utils.formatEther(internalOp.value)} Ether</span>
|
<span>{formatEther(internalOp.value)} Ether</span>
|
||||||
<div className="flex items-baseline">
|
<div className="flex items-baseline">
|
||||||
<span className="text-gray-500">To</span>
|
<span className="text-gray-500">To</span>
|
||||||
<AddressHighlighter address={internalOp.to}>
|
<AddressHighlighter address={internalOp.to}>
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import React from "react";
|
import React from "react";
|
||||||
import { ethers } from "ethers";
|
import { formatEther } from "@ethersproject/units";
|
||||||
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
|
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
|
||||||
import { faAngleRight } from "@fortawesome/free-solid-svg-icons/faAngleRight";
|
import { faAngleRight } from "@fortawesome/free-solid-svg-icons/faAngleRight";
|
||||||
import AddressHighlighter from "./AddressHighlighter";
|
import AddressHighlighter from "./AddressHighlighter";
|
||||||
|
@ -24,7 +24,7 @@ const InternalTransfer: React.FC<InternalTransferProps> = ({
|
||||||
<span className="text-gray-500">
|
<span className="text-gray-500">
|
||||||
<FontAwesomeIcon icon={faAngleRight} size="1x" /> TRANSFER
|
<FontAwesomeIcon icon={faAngleRight} size="1x" /> TRANSFER
|
||||||
</span>
|
</span>
|
||||||
<span>{ethers.utils.formatEther(internalOp.value)} Ether</span>
|
<span>{formatEther(internalOp.value)} Ether</span>
|
||||||
<div className="flex items-baseline">
|
<div className="flex items-baseline">
|
||||||
<span className="text-gray-500">From</span>
|
<span className="text-gray-500">From</span>
|
||||||
<AddressHighlighter address={internalOp.from}>
|
<AddressHighlighter address={internalOp.from}>
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import React from "react";
|
import React from "react";
|
||||||
import { BigNumber } from "ethers";
|
import { BigNumber } from "@ethersproject/bignumber";
|
||||||
import { formatValue } from "./formatter";
|
import { formatValue } from "./formatter";
|
||||||
|
|
||||||
type TransactionValueProps = {
|
type TransactionValueProps = {
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import React from "react";
|
import React from "react";
|
||||||
import { BigNumber } from "ethers";
|
import { BigNumber } from "@ethersproject/bignumber";
|
||||||
import { useSelectionContext } from "../useSelection";
|
import { useSelectionContext } from "../useSelection";
|
||||||
|
|
||||||
type ValueHighlighterProps = React.PropsWithChildren<{
|
type ValueHighlighterProps = React.PropsWithChildren<{
|
||||||
|
|
|
@ -1,9 +1,8 @@
|
||||||
import { ethers, BigNumber } from "ethers";
|
import { BigNumber } from "@ethersproject/bignumber";
|
||||||
|
import { commify, formatUnits } from "@ethersproject/units";
|
||||||
|
|
||||||
export const formatValue = (value: BigNumber, decimals: number): string => {
|
export const formatValue = (value: BigNumber, decimals: number): string => {
|
||||||
const formatted = ethers.utils.commify(
|
const formatted = commify(formatUnits(value, decimals));
|
||||||
ethers.utils.formatUnits(value, decimals)
|
|
||||||
);
|
|
||||||
return formatted.endsWith(".0")
|
return formatted.endsWith(".0")
|
||||||
? formatted.slice(0, formatted.length - 2)
|
? formatted.slice(0, formatted.length - 2)
|
||||||
: formatted;
|
: formatted;
|
||||||
|
|
|
@ -1,8 +1,9 @@
|
||||||
import { ethers } from "ethers";
|
import { JsonRpcProvider } from "@ethersproject/providers";
|
||||||
|
import { getAddress } from "@ethersproject/address";
|
||||||
import { InternalOperation } from "./types";
|
import { InternalOperation } from "./types";
|
||||||
|
|
||||||
export const getInternalOperations = async (
|
export const getInternalOperations = async (
|
||||||
provider: ethers.providers.JsonRpcProvider,
|
provider: JsonRpcProvider,
|
||||||
txHash: string
|
txHash: string
|
||||||
) => {
|
) => {
|
||||||
const rawTransfers = await provider.send("ots_getInternalOperations", [
|
const rawTransfers = await provider.send("ots_getInternalOperations", [
|
||||||
|
@ -13,8 +14,8 @@ export const getInternalOperations = async (
|
||||||
for (const t of rawTransfers) {
|
for (const t of rawTransfers) {
|
||||||
_transfers.push({
|
_transfers.push({
|
||||||
type: t.type,
|
type: t.type,
|
||||||
from: ethers.utils.getAddress(t.from),
|
from: getAddress(t.from),
|
||||||
to: ethers.utils.getAddress(t.to),
|
to: getAddress(t.to),
|
||||||
value: t.value,
|
value: t.value,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import { ethers } from "ethers";
|
import { JsonRpcProvider, TransactionResponse } from "@ethersproject/providers";
|
||||||
import { PAGE_SIZE } from "../params";
|
import { PAGE_SIZE } from "../params";
|
||||||
import { ProcessedTransaction, TransactionChunk } from "../types";
|
import { ProcessedTransaction, TransactionChunk } from "../types";
|
||||||
|
|
||||||
|
@ -26,12 +26,9 @@ export class SearchController {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static rawToProcessed = (
|
private static rawToProcessed = (provider: JsonRpcProvider, _rawRes: any) => {
|
||||||
provider: ethers.providers.JsonRpcProvider,
|
const _res: TransactionResponse[] = _rawRes.txs.map((t: any) =>
|
||||||
_rawRes: any
|
provider.formatter.transactionResponse(t)
|
||||||
) => {
|
|
||||||
const _res: ethers.providers.TransactionResponse[] = _rawRes.txs.map(
|
|
||||||
(t: any) => provider.formatter.transactionResponse(t)
|
|
||||||
);
|
);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
@ -59,7 +56,7 @@ export class SearchController {
|
||||||
};
|
};
|
||||||
|
|
||||||
private static async readBackPage(
|
private static async readBackPage(
|
||||||
provider: ethers.providers.JsonRpcProvider,
|
provider: JsonRpcProvider,
|
||||||
address: string,
|
address: string,
|
||||||
baseBlock: number
|
baseBlock: number
|
||||||
): Promise<TransactionChunk> {
|
): Promise<TransactionChunk> {
|
||||||
|
@ -72,7 +69,7 @@ export class SearchController {
|
||||||
}
|
}
|
||||||
|
|
||||||
private static async readForwardPage(
|
private static async readForwardPage(
|
||||||
provider: ethers.providers.JsonRpcProvider,
|
provider: JsonRpcProvider,
|
||||||
address: string,
|
address: string,
|
||||||
baseBlock: number
|
baseBlock: number
|
||||||
): Promise<TransactionChunk> {
|
): Promise<TransactionChunk> {
|
||||||
|
@ -85,7 +82,7 @@ export class SearchController {
|
||||||
}
|
}
|
||||||
|
|
||||||
static async firstPage(
|
static async firstPage(
|
||||||
provider: ethers.providers.JsonRpcProvider,
|
provider: JsonRpcProvider,
|
||||||
address: string
|
address: string
|
||||||
): Promise<SearchController> {
|
): Promise<SearchController> {
|
||||||
const newTxs = await SearchController.readBackPage(provider, address, 0);
|
const newTxs = await SearchController.readBackPage(provider, address, 0);
|
||||||
|
@ -99,7 +96,7 @@ export class SearchController {
|
||||||
}
|
}
|
||||||
|
|
||||||
static async middlePage(
|
static async middlePage(
|
||||||
provider: ethers.providers.JsonRpcProvider,
|
provider: JsonRpcProvider,
|
||||||
address: string,
|
address: string,
|
||||||
hash: string,
|
hash: string,
|
||||||
next: boolean
|
next: boolean
|
||||||
|
@ -122,7 +119,7 @@ export class SearchController {
|
||||||
}
|
}
|
||||||
|
|
||||||
static async lastPage(
|
static async lastPage(
|
||||||
provider: ethers.providers.JsonRpcProvider,
|
provider: JsonRpcProvider,
|
||||||
address: string
|
address: string
|
||||||
): Promise<SearchController> {
|
): Promise<SearchController> {
|
||||||
const newTxs = await SearchController.readForwardPage(provider, address, 0);
|
const newTxs = await SearchController.readForwardPage(provider, address, 0);
|
||||||
|
@ -140,7 +137,7 @@ export class SearchController {
|
||||||
}
|
}
|
||||||
|
|
||||||
async prevPage(
|
async prevPage(
|
||||||
provider: ethers.providers.JsonRpcProvider,
|
provider: JsonRpcProvider,
|
||||||
hash: string
|
hash: string
|
||||||
): Promise<SearchController> {
|
): Promise<SearchController> {
|
||||||
// Already on this page
|
// Already on this page
|
||||||
|
@ -169,7 +166,7 @@ export class SearchController {
|
||||||
}
|
}
|
||||||
|
|
||||||
async nextPage(
|
async nextPage(
|
||||||
provider: ethers.providers.JsonRpcProvider,
|
provider: JsonRpcProvider,
|
||||||
hash: string
|
hash: string
|
||||||
): Promise<SearchController> {
|
): Promise<SearchController> {
|
||||||
// Already on this page
|
// Already on this page
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
import React from "react";
|
import React from "react";
|
||||||
import { ethers, FixedNumber } from "ethers";
|
import { FixedNumber } from "@ethersproject/bignumber";
|
||||||
|
import { commify, formatEther } from "@ethersproject/units";
|
||||||
import BlockLink from "../../components/BlockLink";
|
import BlockLink from "../../components/BlockLink";
|
||||||
import TimestampAge from "../../components/TimestampAge";
|
import TimestampAge from "../../components/TimestampAge";
|
||||||
import { ExtendedBlock } from "../../useErigonHooks";
|
import { ExtendedBlock } from "../../useErigonHooks";
|
||||||
|
@ -34,10 +35,10 @@ const BlockRow: React.FC<BlockRowProps> = ({ now, block, baseFeeDelta }) => {
|
||||||
: ""
|
: ""
|
||||||
}`}
|
}`}
|
||||||
>
|
>
|
||||||
{ethers.utils.commify(block.gasUsed.toString())}
|
{commify(block.gasUsed.toString())}
|
||||||
</div>
|
</div>
|
||||||
<div className="text-right text-gray-400">
|
<div className="text-right text-gray-400">
|
||||||
{ethers.utils.commify(gasTarget.toString())}
|
{commify(gasTarget.toString())}
|
||||||
</div>
|
</div>
|
||||||
<div className="text-right">
|
<div className="text-right">
|
||||||
<div className="relative">
|
<div className="relative">
|
||||||
|
@ -52,13 +53,10 @@ const BlockRow: React.FC<BlockRowProps> = ({ now, block, baseFeeDelta }) => {
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div className="text-right col-span-2">
|
<div className="text-right col-span-2">
|
||||||
{ethers.utils.commify(ethers.utils.formatEther(totalReward))} Ether
|
{commify(formatEther(totalReward))} Ether
|
||||||
</div>
|
</div>
|
||||||
<div className="text-right col-span-2 line-through text-orange-500">
|
<div className="text-right col-span-2 line-through text-orange-500">
|
||||||
{ethers.utils.commify(
|
{commify(formatEther(block.gasUsed.mul(block.baseFeePerGas!)))} Ether
|
||||||
ethers.utils.formatEther(block.gasUsed.mul(block.baseFeePerGas!))
|
|
||||||
)}{" "}
|
|
||||||
Ether
|
|
||||||
</div>
|
</div>
|
||||||
<div className="text-right text-gray-400">
|
<div className="text-right text-gray-400">
|
||||||
<TimestampAge now={now / 1000} timestamp={block.timestamp} />
|
<TimestampAge now={now / 1000} timestamp={block.timestamp} />
|
||||||
|
|
|
@ -5,7 +5,8 @@ import React, {
|
||||||
useMemo,
|
useMemo,
|
||||||
useCallback,
|
useCallback,
|
||||||
} from "react";
|
} from "react";
|
||||||
import { ethers, FixedNumber } from "ethers";
|
import { Block } from "@ethersproject/abstract-provider";
|
||||||
|
import { FixedNumber } from "@ethersproject/bignumber";
|
||||||
import { Line } from "react-chartjs-2";
|
import { Line } from "react-chartjs-2";
|
||||||
import { Transition } from "@headlessui/react";
|
import { Transition } from "@headlessui/react";
|
||||||
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
|
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
|
||||||
|
@ -29,7 +30,7 @@ const MAX_BLOCK_HISTORY = 20;
|
||||||
const PREV_BLOCK_COUNT = 15;
|
const PREV_BLOCK_COUNT = 15;
|
||||||
|
|
||||||
type BlocksProps = {
|
type BlocksProps = {
|
||||||
latestBlock: ethers.providers.Block;
|
latestBlock: Block;
|
||||||
targetBlockNumber: number;
|
targetBlockNumber: number;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -1,9 +1,10 @@
|
||||||
import React, { useEffect, useState } from "react";
|
import React, { useEffect, useState } from "react";
|
||||||
import { ethers } from "ethers";
|
import { JsonRpcProvider, Block } from "@ethersproject/providers";
|
||||||
|
import { commify } from "@ethersproject/units";
|
||||||
|
|
||||||
type CountdownProps = {
|
type CountdownProps = {
|
||||||
provider: ethers.providers.JsonRpcProvider;
|
provider: JsonRpcProvider;
|
||||||
currentBlock: ethers.providers.Block;
|
currentBlock: Block;
|
||||||
targetBlock: number;
|
targetBlock: number;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -31,12 +32,12 @@ const Countdown: React.FC<CountdownProps> = ({
|
||||||
<div className="m-auto text-center">
|
<div className="m-auto text-center">
|
||||||
<h1 className="text-6xl mb-10">London Network Upgrade</h1>
|
<h1 className="text-6xl mb-10">London Network Upgrade</h1>
|
||||||
<h2 className="text-5xl">
|
<h2 className="text-5xl">
|
||||||
{ethers.utils.commify(targetBlock - currentBlock.number)}
|
{commify(targetBlock - currentBlock.number)}
|
||||||
</h2>
|
</h2>
|
||||||
<h6 className="text-sm mb-10">Blocks remaining</h6>
|
<h6 className="text-sm mb-10">Blocks remaining</h6>
|
||||||
<h2 className="inline-flex space-x-10 text-base mb-10">
|
<h2 className="inline-flex space-x-10 text-base mb-10">
|
||||||
<div>Current block: {ethers.utils.commify(currentBlock.number)}</div>
|
<div>Current block: {commify(currentBlock.number)}</div>
|
||||||
<div>Target block: {ethers.utils.commify(targetBlock)}</div>
|
<div>Target block: {commify(targetBlock)}</div>
|
||||||
</h2>
|
</h2>
|
||||||
{targetTimestamp && (
|
{targetTimestamp && (
|
||||||
<div className="text-lg">
|
<div className="text-lg">
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import { ethers } from "ethers";
|
import { commify } from "@ethersproject/units";
|
||||||
import { ChartData, ChartOptions } from "chart.js";
|
import { ChartData, ChartOptions } from "chart.js";
|
||||||
import { ExtendedBlock } from "../../useErigonHooks";
|
import { ExtendedBlock } from "../../useErigonHooks";
|
||||||
|
|
||||||
|
@ -14,7 +14,7 @@ export const burntFeesChartOptions: ChartOptions = {
|
||||||
ticks: {
|
ticks: {
|
||||||
callback: function (v) {
|
callback: function (v) {
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
return ethers.utils.commify(this.getLabelForValue(v));
|
return commify(this.getLabelForValue(v));
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -84,7 +84,7 @@ export const gasChartOptions: ChartOptions = {
|
||||||
ticks: {
|
ticks: {
|
||||||
callback: function (v) {
|
callback: function (v) {
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
return ethers.utils.commify(this.getLabelForValue(v));
|
return commify(this.getLabelForValue(v));
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import React from "react";
|
import React from "react";
|
||||||
import { ethers } from "ethers";
|
import { formatEther } from "@ethersproject/units";
|
||||||
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
|
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
|
||||||
import { faCheckCircle } from "@fortawesome/free-solid-svg-icons/faCheckCircle";
|
import { faCheckCircle } from "@fortawesome/free-solid-svg-icons/faCheckCircle";
|
||||||
import { faCube } from "@fortawesome/free-solid-svg-icons/faCube";
|
import { faCube } from "@fortawesome/free-solid-svg-icons/faCube";
|
||||||
|
@ -159,7 +159,7 @@ const Details: React.FC<DetailsProps> = ({
|
||||||
)}
|
)}
|
||||||
<InfoRow title="Value">
|
<InfoRow title="Value">
|
||||||
<span className="rounded bg-gray-100 px-2 py-1 text-xs">
|
<span className="rounded bg-gray-100 px-2 py-1 text-xs">
|
||||||
{ethers.utils.formatEther(txData.value)} Ether
|
{formatEther(txData.value)} Ether
|
||||||
</span>
|
</span>
|
||||||
</InfoRow>
|
</InfoRow>
|
||||||
<InfoRow
|
<InfoRow
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
import { ethers, BigNumber } from "ethers";
|
import { BigNumber } from "@ethersproject/bignumber";
|
||||||
|
import { Log } from "@ethersproject/providers";
|
||||||
|
|
||||||
export enum ConnectionStatus {
|
export enum ConnectionStatus {
|
||||||
CONNECTING,
|
CONNECTING,
|
||||||
|
@ -60,7 +61,7 @@ export type TransactionData = {
|
||||||
gasLimit: BigNumber;
|
gasLimit: BigNumber;
|
||||||
nonce: number;
|
nonce: number;
|
||||||
data: string;
|
data: string;
|
||||||
logs: ethers.providers.Log[];
|
logs: Log[];
|
||||||
};
|
};
|
||||||
|
|
||||||
// The VOID...
|
// The VOID...
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import { ethers } from "ethers";
|
import { BlockTag } from "@ethersproject/abstract-provider";
|
||||||
|
|
||||||
export const fourBytesURL = (
|
export const fourBytesURL = (
|
||||||
assetsURLPrefix: string,
|
assetsURLPrefix: string,
|
||||||
|
@ -10,8 +10,6 @@ export const tokenLogoURL = (
|
||||||
address: string
|
address: string
|
||||||
): string => `${assetsURLPrefix}/assets/${address}/logo.png`;
|
): string => `${assetsURLPrefix}/assets/${address}/logo.png`;
|
||||||
|
|
||||||
export const blockURL = (blockNum: ethers.providers.BlockTag) =>
|
export const blockURL = (blockNum: BlockTag) => `/block/${blockNum}`;
|
||||||
`/block/${blockNum}`;
|
|
||||||
|
|
||||||
export const blockTxsURL = (blockNum: ethers.providers.BlockTag) =>
|
export const blockTxsURL = (blockNum: BlockTag) => `/block/${blockNum}/txs`;
|
||||||
`/block/${blockNum}/txs`;
|
|
||||||
|
|
|
@ -1,6 +1,10 @@
|
||||||
import { useState, useEffect } from "react";
|
import { useState, useEffect } from "react";
|
||||||
import { ethers, BigNumber } from "ethers";
|
import { Block, BlockWithTransactions } from "@ethersproject/abstract-provider";
|
||||||
import { BlockWithTransactions } from "@ethersproject/abstract-provider";
|
import { JsonRpcProvider } from "@ethersproject/providers";
|
||||||
|
import { getAddress } from "@ethersproject/address";
|
||||||
|
import { Contract } from "@ethersproject/contracts";
|
||||||
|
import { BigNumber } from "@ethersproject/bignumber";
|
||||||
|
import { arrayify, hexDataSlice, isHexString } from "@ethersproject/bytes";
|
||||||
import { getInternalOperations } from "./nodeFunctions";
|
import { getInternalOperations } from "./nodeFunctions";
|
||||||
import {
|
import {
|
||||||
TokenMetas,
|
TokenMetas,
|
||||||
|
@ -15,7 +19,7 @@ import erc20 from "./erc20.json";
|
||||||
const TRANSFER_TOPIC =
|
const TRANSFER_TOPIC =
|
||||||
"0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef";
|
"0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef";
|
||||||
|
|
||||||
export interface ExtendedBlock extends ethers.providers.Block {
|
export interface ExtendedBlock extends Block {
|
||||||
blockReward: BigNumber;
|
blockReward: BigNumber;
|
||||||
unclesReward: BigNumber;
|
unclesReward: BigNumber;
|
||||||
feeReward: BigNumber;
|
feeReward: BigNumber;
|
||||||
|
@ -27,11 +31,11 @@ export interface ExtendedBlock extends ethers.providers.Block {
|
||||||
}
|
}
|
||||||
|
|
||||||
export const readBlock = async (
|
export const readBlock = async (
|
||||||
provider: ethers.providers.JsonRpcProvider,
|
provider: JsonRpcProvider,
|
||||||
blockNumberOrHash: string
|
blockNumberOrHash: string
|
||||||
) => {
|
) => {
|
||||||
let blockPromise: Promise<any>;
|
let blockPromise: Promise<any>;
|
||||||
if (ethers.utils.isHexString(blockNumberOrHash, 32)) {
|
if (isHexString(blockNumberOrHash, 32)) {
|
||||||
// TODO: fix
|
// TODO: fix
|
||||||
blockPromise = provider.send("eth_getBlockByHash", [
|
blockPromise = provider.send("eth_getBlockByHash", [
|
||||||
blockNumberOrHash,
|
blockNumberOrHash,
|
||||||
|
@ -65,7 +69,7 @@ export const readBlock = async (
|
||||||
};
|
};
|
||||||
|
|
||||||
export const useBlockTransactions = (
|
export const useBlockTransactions = (
|
||||||
provider: ethers.providers.JsonRpcProvider | undefined,
|
provider: JsonRpcProvider | undefined,
|
||||||
blockNumber: number,
|
blockNumber: number,
|
||||||
pageNumber: number,
|
pageNumber: number,
|
||||||
pageSize: number
|
pageSize: number
|
||||||
|
@ -129,7 +133,7 @@ export const useBlockTransactions = (
|
||||||
(op) =>
|
(op) =>
|
||||||
op.type === OperationType.TRANSFER &&
|
op.type === OperationType.TRANSFER &&
|
||||||
res.miner !== undefined &&
|
res.miner !== undefined &&
|
||||||
res.miner === ethers.utils.getAddress(op.to)
|
res.miner === getAddress(op.to)
|
||||||
) !== -1
|
) !== -1
|
||||||
);
|
);
|
||||||
})
|
})
|
||||||
|
@ -149,7 +153,7 @@ export const useBlockTransactions = (
|
||||||
};
|
};
|
||||||
|
|
||||||
export const useBlockData = (
|
export const useBlockData = (
|
||||||
provider: ethers.providers.JsonRpcProvider | undefined,
|
provider: JsonRpcProvider | undefined,
|
||||||
blockNumberOrHash: string
|
blockNumberOrHash: string
|
||||||
) => {
|
) => {
|
||||||
const [block, setBlock] = useState<ExtendedBlock>();
|
const [block, setBlock] = useState<ExtendedBlock>();
|
||||||
|
@ -169,7 +173,7 @@ export const useBlockData = (
|
||||||
};
|
};
|
||||||
|
|
||||||
export const useTxData = (
|
export const useTxData = (
|
||||||
provider: ethers.providers.JsonRpcProvider | undefined,
|
provider: JsonRpcProvider | undefined,
|
||||||
txhash: string
|
txhash: string
|
||||||
): TransactionData | undefined => {
|
): TransactionData | undefined => {
|
||||||
const [txData, setTxData] = useState<TransactionData>();
|
const [txData, setTxData] = useState<TransactionData>();
|
||||||
|
@ -198,12 +202,8 @@ export const useTxData = (
|
||||||
}
|
}
|
||||||
tokenTransfers.push({
|
tokenTransfers.push({
|
||||||
token: l.address,
|
token: l.address,
|
||||||
from: ethers.utils.getAddress(
|
from: getAddress(hexDataSlice(arrayify(l.topics[1]), 12)),
|
||||||
ethers.utils.hexDataSlice(ethers.utils.arrayify(l.topics[1]), 12)
|
to: getAddress(hexDataSlice(arrayify(l.topics[2]), 12)),
|
||||||
),
|
|
||||||
to: ethers.utils.getAddress(
|
|
||||||
ethers.utils.hexDataSlice(ethers.utils.arrayify(l.topics[2]), 12)
|
|
||||||
),
|
|
||||||
value: BigNumber.from(l.data),
|
value: BigNumber.from(l.data),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -214,7 +214,7 @@ export const useTxData = (
|
||||||
if (tokenMetas[t.token]) {
|
if (tokenMetas[t.token]) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
const erc20Contract = new ethers.Contract(t.token, erc20, provider);
|
const erc20Contract = new Contract(t.token, erc20, provider);
|
||||||
const [name, symbol, decimals] = await Promise.all([
|
const [name, symbol, decimals] = await Promise.all([
|
||||||
erc20Contract.name(),
|
erc20Contract.name(),
|
||||||
erc20Contract.symbol(),
|
erc20Contract.symbol(),
|
||||||
|
@ -262,7 +262,7 @@ export const useTxData = (
|
||||||
};
|
};
|
||||||
|
|
||||||
export const useInternalOperations = (
|
export const useInternalOperations = (
|
||||||
provider: ethers.providers.JsonRpcProvider | undefined,
|
provider: JsonRpcProvider | undefined,
|
||||||
txData: TransactionData | undefined
|
txData: TransactionData | undefined
|
||||||
): InternalOperation[] | undefined => {
|
): InternalOperation[] | undefined => {
|
||||||
const [intTransfers, setIntTransfers] = useState<InternalOperation[]>();
|
const [intTransfers, setIntTransfers] = useState<InternalOperation[]>();
|
||||||
|
|
|
@ -1,8 +1,9 @@
|
||||||
import { useState, useEffect } from "react";
|
import { useState, useEffect } from "react";
|
||||||
import { ethers } from "ethers";
|
import { Block } from "@ethersproject/abstract-provider";
|
||||||
|
import { JsonRpcProvider } from "@ethersproject/providers";
|
||||||
|
|
||||||
export const useLatestBlock = (provider?: ethers.providers.JsonRpcProvider) => {
|
export const useLatestBlock = (provider?: JsonRpcProvider) => {
|
||||||
const [latestBlock, setLatestBlock] = useState<ethers.providers.Block>();
|
const [latestBlock, setLatestBlock] = useState<Block>();
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!provider) {
|
if (!provider) {
|
||||||
|
@ -34,9 +35,7 @@ export const useLatestBlock = (provider?: ethers.providers.JsonRpcProvider) => {
|
||||||
return latestBlock;
|
return latestBlock;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const useLatestBlockNumber = (
|
export const useLatestBlockNumber = (provider?: JsonRpcProvider) => {
|
||||||
provider?: ethers.providers.JsonRpcProvider
|
|
||||||
) => {
|
|
||||||
const [latestBlock, setLatestBlock] = useState<number>();
|
const [latestBlock, setLatestBlock] = useState<number>();
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import { useEffect, useState } from "react";
|
import { useEffect, useState } from "react";
|
||||||
import { ethers } from "ethers";
|
import { JsonRpcProvider, WebSocketProvider } from "@ethersproject/providers";
|
||||||
import { ConnectionStatus } from "./types";
|
import { ConnectionStatus } from "./types";
|
||||||
import { MIN_API_LEVEL } from "./params";
|
import { MIN_API_LEVEL } from "./params";
|
||||||
|
|
||||||
|
@ -7,7 +7,7 @@ export const DEFAULT_ERIGON_URL = "http://127.0.0.1:8545";
|
||||||
|
|
||||||
export const useProvider = (
|
export const useProvider = (
|
||||||
erigonURL?: string
|
erigonURL?: string
|
||||||
): [ConnectionStatus, ethers.providers.JsonRpcProvider | undefined] => {
|
): [ConnectionStatus, JsonRpcProvider | undefined] => {
|
||||||
const [connStatus, setConnStatus] = useState<ConnectionStatus>(
|
const [connStatus, setConnStatus] = useState<ConnectionStatus>(
|
||||||
ConnectionStatus.CONNECTING
|
ConnectionStatus.CONNECTING
|
||||||
);
|
);
|
||||||
|
@ -21,9 +21,7 @@ export const useProvider = (
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const [provider, setProvider] = useState<
|
const [provider, setProvider] = useState<JsonRpcProvider | undefined>();
|
||||||
ethers.providers.JsonRpcProvider | undefined
|
|
||||||
>();
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (erigonURL === undefined) {
|
if (erigonURL === undefined) {
|
||||||
setConnStatus(ConnectionStatus.NOT_ETH_NODE);
|
setConnStatus(ConnectionStatus.NOT_ETH_NODE);
|
||||||
|
@ -33,11 +31,11 @@ export const useProvider = (
|
||||||
setConnStatus(ConnectionStatus.CONNECTING);
|
setConnStatus(ConnectionStatus.CONNECTING);
|
||||||
|
|
||||||
const tryToConnect = async () => {
|
const tryToConnect = async () => {
|
||||||
let provider: ethers.providers.JsonRpcProvider;
|
let provider: JsonRpcProvider;
|
||||||
if (erigonURL?.startsWith("ws://") || erigonURL?.startsWith("wss://")) {
|
if (erigonURL?.startsWith("ws://") || erigonURL?.startsWith("wss://")) {
|
||||||
provider = new ethers.providers.WebSocketProvider(erigonURL);
|
provider = new WebSocketProvider(erigonURL);
|
||||||
} else {
|
} else {
|
||||||
provider = new ethers.providers.JsonRpcProvider(erigonURL);
|
provider = new JsonRpcProvider(erigonURL);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if it is at least a regular ETH node
|
// Check if it is at least a regular ETH node
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
import { useState, useEffect } from "react";
|
import { useState, useEffect } from "react";
|
||||||
import { ethers } from "ethers";
|
import { JsonRpcProvider } from "@ethersproject/providers";
|
||||||
import { ENSReverseCache, ProcessedTransaction } from "./types";
|
import { ENSReverseCache, ProcessedTransaction } from "./types";
|
||||||
|
|
||||||
export const useENSCache = (
|
export const useENSCache = (
|
||||||
provider?: ethers.providers.JsonRpcProvider,
|
provider?: JsonRpcProvider,
|
||||||
page?: ProcessedTransaction[]
|
page?: ProcessedTransaction[]
|
||||||
) => {
|
) => {
|
||||||
const [reverseCache, setReverseCache] = useState<ENSReverseCache>();
|
const [reverseCache, setReverseCache] = useState<ENSReverseCache>();
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import React, { useMemo } from "react";
|
import React, { useMemo } from "react";
|
||||||
import { ethers } from "ethers";
|
import { JsonRpcProvider } from "@ethersproject/providers";
|
||||||
import { OtterscanConfig, useConfig } from "./useConfig";
|
import { OtterscanConfig, useConfig } from "./useConfig";
|
||||||
import { useProvider } from "./useProvider";
|
import { useProvider } from "./useProvider";
|
||||||
import { ConnectionStatus } from "./types";
|
import { ConnectionStatus } from "./types";
|
||||||
|
@ -7,7 +7,7 @@ import { ConnectionStatus } from "./types";
|
||||||
export type OtterscanRuntime = {
|
export type OtterscanRuntime = {
|
||||||
config?: OtterscanConfig;
|
config?: OtterscanConfig;
|
||||||
connStatus: ConnectionStatus;
|
connStatus: ConnectionStatus;
|
||||||
provider?: ethers.providers.JsonRpcProvider;
|
provider?: JsonRpcProvider;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const useRuntime = (): OtterscanRuntime => {
|
export const useRuntime = (): OtterscanRuntime => {
|
||||||
|
|
Loading…
Reference in New Issue