2021-12-04 19:28:40 +00:00
|
|
|
import React, { useEffect, useContext, useCallback, useMemo } from "react";
|
2021-07-23 18:10:08 +00:00
|
|
|
import {
|
|
|
|
useParams,
|
2021-11-25 09:28:45 +00:00
|
|
|
useNavigate,
|
|
|
|
Routes,
|
2021-07-23 18:10:08 +00:00
|
|
|
Route,
|
2021-11-25 09:28:45 +00:00
|
|
|
useSearchParams,
|
2021-07-23 18:10:08 +00:00
|
|
|
} from "react-router-dom";
|
2021-09-05 20:39:11 +00:00
|
|
|
import { Tab } from "@headlessui/react";
|
2021-07-01 18:21:40 +00:00
|
|
|
import Blockies from "react-blockies";
|
2021-09-10 07:31:24 +00:00
|
|
|
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
|
|
|
|
import { faCircleNotch } from "@fortawesome/free-solid-svg-icons/faCircleNotch";
|
|
|
|
import { faQuestionCircle } from "@fortawesome/free-regular-svg-icons/faQuestionCircle";
|
2021-07-01 18:21:40 +00:00
|
|
|
import StandardFrame from "./StandardFrame";
|
|
|
|
import StandardSubtitle from "./StandardSubtitle";
|
2022-01-29 23:00:01 +00:00
|
|
|
import AddressOrENSNameNotFound from "./components/AddressOrENSNameNotFound";
|
2021-07-01 18:21:40 +00:00
|
|
|
import Copy from "./components/Copy";
|
2022-04-06 01:38:27 +00:00
|
|
|
import Faucet from "./components/Faucet";
|
2021-09-06 06:34:13 +00:00
|
|
|
import NavTab from "./components/NavTab";
|
2021-11-25 18:48:17 +00:00
|
|
|
import SourcifyLogo from "./sourcify/SourcifyLogo";
|
2021-11-25 10:03:29 +00:00
|
|
|
import AddressTransactionResults from "./address/AddressTransactionResults";
|
2021-07-24 23:33:45 +00:00
|
|
|
import Contracts from "./address/Contracts";
|
2021-07-09 05:07:20 +00:00
|
|
|
import { RuntimeContext } from "./useRuntime";
|
2021-09-23 21:25:52 +00:00
|
|
|
import { useAppConfigContext } from "./useAppConfig";
|
2022-01-29 22:54:21 +00:00
|
|
|
import { useAddressOrENS } from "./useResolvedAddresses";
|
2021-12-04 19:28:40 +00:00
|
|
|
import { useMultipleMetadata } from "./sourcify/useSourcify";
|
2021-11-25 19:20:44 +00:00
|
|
|
import { ChecksummedAddress } from "./types";
|
2021-12-04 19:28:40 +00:00
|
|
|
import { useAddressesWithCode } from "./useErigonHooks";
|
2022-04-06 01:38:27 +00:00
|
|
|
import { useChainInfo } from "./useChainInfo";
|
2021-07-01 18:21:40 +00:00
|
|
|
|
2022-01-31 18:37:29 +00:00
|
|
|
const AddressTransactionByNonce = React.lazy(
|
|
|
|
() =>
|
|
|
|
import(
|
|
|
|
/* webpackChunkName: "addresstxbynonce", webpackPrefetch: true */ "./AddressTransactionByNonce"
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
2022-01-24 19:18:28 +00:00
|
|
|
const Address: React.FC = () => {
|
2021-07-09 05:07:20 +00:00
|
|
|
const { provider } = useContext(RuntimeContext);
|
2021-11-25 09:28:45 +00:00
|
|
|
const { addressOrName, direction } = useParams();
|
|
|
|
if (addressOrName === undefined) {
|
|
|
|
throw new Error("addressOrName couldn't be undefined here");
|
|
|
|
}
|
|
|
|
|
|
|
|
const navigate = useNavigate();
|
|
|
|
const [searchParams] = useSearchParams();
|
2021-11-25 19:20:44 +00:00
|
|
|
const urlFixer = useCallback(
|
|
|
|
(address: ChecksummedAddress) => {
|
|
|
|
navigate(
|
|
|
|
`/address/${address}${
|
|
|
|
direction ? "/" + direction : ""
|
|
|
|
}?${searchParams.toString()}`,
|
|
|
|
{ replace: true }
|
|
|
|
);
|
|
|
|
},
|
|
|
|
[navigate, direction, searchParams]
|
|
|
|
);
|
2022-01-29 22:54:21 +00:00
|
|
|
const [checksummedAddress, isENS, error] = useAddressOrENS(
|
2021-11-25 19:20:44 +00:00
|
|
|
addressOrName,
|
|
|
|
urlFixer
|
|
|
|
);
|
2021-07-01 18:21:40 +00:00
|
|
|
|
2021-07-02 19:05:18 +00:00
|
|
|
useEffect(() => {
|
2021-11-25 19:20:44 +00:00
|
|
|
if (isENS || checksummedAddress === undefined) {
|
|
|
|
document.title = `Address ${addressOrName} | Otterscan`;
|
|
|
|
} else {
|
|
|
|
document.title = `Address ${checksummedAddress} | Otterscan`;
|
2021-07-08 19:02:42 +00:00
|
|
|
}
|
2021-11-25 19:20:44 +00:00
|
|
|
}, [addressOrName, checksummedAddress, isENS]);
|
2021-07-01 18:21:40 +00:00
|
|
|
|
2021-09-23 21:25:52 +00:00
|
|
|
const { sourcifySource } = useAppConfigContext();
|
2021-12-04 19:28:40 +00:00
|
|
|
const checksummedAddressAsArray = useMemo(
|
|
|
|
() => (checksummedAddress !== undefined ? [checksummedAddress] : []),
|
|
|
|
[checksummedAddress]
|
|
|
|
);
|
|
|
|
const contractAddresses = useAddressesWithCode(
|
|
|
|
provider,
|
|
|
|
checksummedAddressAsArray
|
|
|
|
);
|
|
|
|
const metadatas = useMultipleMetadata(
|
|
|
|
undefined,
|
|
|
|
contractAddresses,
|
2021-09-06 21:32:11 +00:00
|
|
|
provider?.network.chainId,
|
2021-09-10 21:27:42 +00:00
|
|
|
sourcifySource
|
2021-09-06 00:13:01 +00:00
|
|
|
);
|
2021-12-04 19:28:40 +00:00
|
|
|
const addressMetadata =
|
|
|
|
checksummedAddress !== undefined
|
|
|
|
? metadatas[checksummedAddress]
|
|
|
|
: undefined;
|
2021-07-14 06:52:31 +00:00
|
|
|
|
2022-04-11 04:04:56 +00:00
|
|
|
const { network, faucets } = useChainInfo();
|
2022-04-06 01:38:27 +00:00
|
|
|
|
2022-01-31 18:37:29 +00:00
|
|
|
// Search address by nonce === transaction @ nonce
|
|
|
|
const rawNonce = searchParams.get("nonce");
|
|
|
|
if (rawNonce !== null) {
|
|
|
|
return (
|
|
|
|
<AddressTransactionByNonce
|
|
|
|
checksummedAddress={checksummedAddress}
|
2022-01-31 19:26:27 +00:00
|
|
|
rawNonce={rawNonce}
|
2022-01-31 18:37:29 +00:00
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-07-01 18:21:40 +00:00
|
|
|
return (
|
|
|
|
<StandardFrame>
|
2021-07-02 19:20:50 +00:00
|
|
|
{error ? (
|
2022-02-18 06:46:37 +00:00
|
|
|
<AddressOrENSNameNotFound
|
|
|
|
addressOrENSName={addressOrName}
|
|
|
|
supportsENS={provider?.network.ensAddress !== undefined}
|
|
|
|
/>
|
2021-07-02 19:20:50 +00:00
|
|
|
) : (
|
|
|
|
checksummedAddress && (
|
2021-07-01 18:21:40 +00:00
|
|
|
<>
|
2021-07-02 19:20:50 +00:00
|
|
|
<StandardSubtitle>
|
|
|
|
<div className="flex space-x-2 items-baseline">
|
|
|
|
<Blockies
|
|
|
|
className="self-center rounded"
|
|
|
|
seed={checksummedAddress.toLowerCase()}
|
|
|
|
scale={3}
|
|
|
|
/>
|
|
|
|
<span>Address</span>
|
|
|
|
<span className="font-address text-base text-gray-500">
|
|
|
|
{checksummedAddress}
|
|
|
|
</span>
|
|
|
|
<Copy value={checksummedAddress} rounded />
|
2022-04-06 01:38:27 +00:00
|
|
|
{/* Only display faucets for testnets who actually have any */}
|
2022-04-11 04:04:56 +00:00
|
|
|
{network === "testnet" && faucets && faucets.length > 0 && (
|
2022-04-06 01:38:27 +00:00
|
|
|
<Faucet address={checksummedAddress} rounded />
|
|
|
|
)}
|
2021-07-02 19:20:50 +00:00
|
|
|
{isENS && (
|
|
|
|
<span className="rounded-lg px-2 py-1 bg-gray-200 text-gray-500 text-xs">
|
2021-11-25 09:28:45 +00:00
|
|
|
ENS: {addressOrName}
|
2021-07-02 19:20:50 +00:00
|
|
|
</span>
|
2021-07-01 18:21:40 +00:00
|
|
|
)}
|
|
|
|
</div>
|
2021-07-02 19:20:50 +00:00
|
|
|
</StandardSubtitle>
|
2021-09-05 20:39:11 +00:00
|
|
|
<Tab.Group>
|
|
|
|
<Tab.List className="flex space-x-2 border-l border-r border-t rounded-t-lg bg-white">
|
2021-12-04 19:54:27 +00:00
|
|
|
<NavTab href={`/address/${addressOrName}`}>Overview</NavTab>
|
2021-12-04 19:28:40 +00:00
|
|
|
{(contractAddresses?.length ?? 0) > 0 && (
|
2021-12-04 19:54:27 +00:00
|
|
|
<NavTab href={`/address/${addressOrName}/contract`}>
|
2021-12-04 19:28:40 +00:00
|
|
|
<span
|
|
|
|
className={`flex items-baseline space-x-2 ${
|
|
|
|
addressMetadata === undefined ? "italic opacity-50" : ""
|
|
|
|
}`}
|
|
|
|
>
|
|
|
|
<span>Contract</span>
|
|
|
|
{addressMetadata === undefined ? (
|
|
|
|
<span className="self-center">
|
|
|
|
<FontAwesomeIcon
|
|
|
|
className="animate-spin"
|
|
|
|
icon={faCircleNotch}
|
|
|
|
/>
|
|
|
|
</span>
|
|
|
|
) : addressMetadata === null ? (
|
|
|
|
<span className="self-center text-red-500">
|
|
|
|
<FontAwesomeIcon icon={faQuestionCircle} />
|
|
|
|
</span>
|
|
|
|
) : (
|
|
|
|
<span className="self-center">
|
|
|
|
<SourcifyLogo />
|
|
|
|
</span>
|
|
|
|
)}
|
|
|
|
</span>
|
|
|
|
</NavTab>
|
|
|
|
)}
|
2021-09-05 20:39:11 +00:00
|
|
|
</Tab.List>
|
|
|
|
<Tab.Panels>
|
2021-11-25 09:28:45 +00:00
|
|
|
<Routes>
|
|
|
|
<Route
|
2021-11-26 06:38:24 +00:00
|
|
|
index
|
|
|
|
element={
|
|
|
|
<AddressTransactionResults address={checksummedAddress} />
|
|
|
|
}
|
|
|
|
/>
|
|
|
|
<Route
|
|
|
|
path="txs/:direction"
|
2021-11-25 09:28:45 +00:00
|
|
|
element={
|
2021-11-25 18:41:40 +00:00
|
|
|
<AddressTransactionResults address={checksummedAddress} />
|
2021-11-25 09:28:45 +00:00
|
|
|
}
|
|
|
|
/>
|
|
|
|
<Route
|
|
|
|
path="contract"
|
|
|
|
element={
|
|
|
|
<Contracts
|
|
|
|
checksummedAddress={checksummedAddress}
|
2021-12-04 19:28:40 +00:00
|
|
|
rawMetadata={
|
|
|
|
contractAddresses !== undefined &&
|
|
|
|
contractAddresses.length === 0
|
|
|
|
? null
|
|
|
|
: addressMetadata
|
|
|
|
}
|
2021-11-25 09:28:45 +00:00
|
|
|
/>
|
|
|
|
}
|
|
|
|
/>
|
|
|
|
</Routes>
|
2021-09-05 20:39:11 +00:00
|
|
|
</Tab.Panels>
|
|
|
|
</Tab.Group>
|
2021-07-01 18:21:40 +00:00
|
|
|
</>
|
2021-07-02 19:20:50 +00:00
|
|
|
)
|
|
|
|
)}
|
2021-07-01 18:21:40 +00:00
|
|
|
</StandardFrame>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2022-01-24 19:18:28 +00:00
|
|
|
export default Address;
|