Add contract creator panel to address overview page

This commit is contained in:
Willian Mitsuda 2022-02-19 07:42:36 -03:00
parent ee0ea1a2e3
commit d00d6cba0b
3 changed files with 96 additions and 23 deletions

View File

@ -1,6 +1,10 @@
import React, { useContext, useEffect, useMemo, useState } from "react"; 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 TransactionAddress from "../components/TransactionAddress";
import Copy from "../components/Copy";
import TransactionLink from "../components/TransactionLink";
import PendingResults from "../search/PendingResults"; import PendingResults from "../search/PendingResults";
import ResultHeader from "../search/ResultHeader"; import ResultHeader from "../search/ResultHeader";
import { SearchController } from "../search/search"; import { SearchController } from "../search/search";
@ -13,6 +17,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";
type AddressTransactionResultsProps = { type AddressTransactionResultsProps = {
address: ChecksummedAddress; address: ChecksummedAddress;
@ -117,31 +122,46 @@ const AddressTransactionResults: React.FC<AddressTransactionResultsProps> = ({
return _addresses; return _addresses;
}, [address, page]); }, [address, page]);
const metadatas = useContractsMetadata(addresses, provider); const metadatas = useContractsMetadata(addresses, provider);
const creator = useContractCreator(provider, address);
return ( return (
<ContentFrame tabs> <ContentFrame tabs>
<NavBar address={address} page={page} controller={controller} /> <SelectionContext.Provider value={selectionCtx}>
<ResultHeader <InfoRow title="Balance"></InfoRow>
feeDisplay={feeDisplay} {creator && (
feeDisplayToggler={feeDisplayToggler} <InfoRow title="Contract creator">
/> <div className="flex items-baseline space-x-2 -ml-1">
{page ? ( <TransactionAddress address={creator.creator} />
<SelectionContext.Provider value={selectionCtx}> <Copy value={creator.creator} />
{page.map((tx) => ( <span className="text-gray-400 text-xs">at</span>
<TransactionItem <span>tx:</span>
key={tx.hash} <TransactionLink txHash={creator.hash} />
tx={tx} </div>
selectedAddress={address} </InfoRow>
feeDisplay={feeDisplay} )}
priceMap={priceMap} <NavBar address={address} page={page} controller={controller} />
metadatas={metadatas} <ResultHeader
/> feeDisplay={feeDisplay}
))} feeDisplayToggler={feeDisplayToggler}
<NavBar address={address} page={page} controller={controller} /> />
</SelectionContext.Provider> {page ? (
) : ( <>
<PendingResults /> {page.map((tx) => (
)} <TransactionItem
key={tx.hash}
tx={tx}
selectedAddress={address}
feeDisplay={feeDisplay}
priceMap={priceMap}
metadatas={metadatas}
/>
))}
<NavBar address={address} page={page} controller={controller} />
</>
) : (
<PendingResults />
)}
</SelectionContext.Provider>
</ContentFrame> </ContentFrame>
); );
}; };

View File

@ -1,3 +1,3 @@
export const MIN_API_LEVEL = 7; export const MIN_API_LEVEL = 8;
export const PAGE_SIZE = 25; export const PAGE_SIZE = 25;

View File

@ -605,3 +605,56 @@ export const useTransactionBySenderAndNonce = (
} }
return data; return data;
}; };
type ContractCreatorKey = {
type: "cc";
network: number;
address: ChecksummedAddress;
};
type ContractCreator = {
hash: string;
creator: ChecksummedAddress;
};
export const useContractCreator = (
provider: JsonRpcProvider | undefined,
address: ChecksummedAddress | undefined
): ContractCreator | null | undefined => {
const { data, error } = useSWR<
ContractCreator | null | undefined,
any,
ContractCreatorKey | null
>(
provider && address
? {
type: "cc",
network: provider.network.chainId,
address,
}
: null,
getContractCreatorFetcher(provider!)
);
if (error) {
return undefined;
}
return data as ContractCreator;
};
const getContractCreatorFetcher =
(provider: JsonRpcProvider) =>
async ({
network,
address,
}: ContractCreatorKey): Promise<ContractCreator | null | undefined> => {
const result = (await provider.send("ots_experimentalGetContractCreator", [
address,
])) as ContractCreator;
// Empty or success
if (result) {
result.creator = provider.formatter.address(result.creator);
}
return result;
};