From 78bea24433cb9e7751b7e0b8a781465e9090e36e Mon Sep 17 00:00:00 2001 From: Manuel Wedler Date: Tue, 30 Jul 2024 11:54:06 +0200 Subject: [PATCH] Add proxy inputs to VerifyView --- .../src/app/components/AccordionReceipt.tsx | 28 +++++++++---------- .../src/app/types/VerificationTypes.ts | 22 +++------------ .../src/app/views/VerifyView.tsx | 18 +++++++++--- 3 files changed, 31 insertions(+), 37 deletions(-) diff --git a/apps/contract-verification/src/app/components/AccordionReceipt.tsx b/apps/contract-verification/src/app/components/AccordionReceipt.tsx index 037d792847..ef4eb8aa39 100644 --- a/apps/contract-verification/src/app/components/AccordionReceipt.tsx +++ b/apps/contract-verification/src/app/components/AccordionReceipt.tsx @@ -1,10 +1,10 @@ import React, { useMemo } from 'react' -import { SubmittedContract, SubmittedProxyContract, isContract, isProxy } from '../types' +import { SubmittedContract } from '../types' import { shortenAddress, CustomTooltip } from '@remix-ui/helper' import { AppContext } from '../AppContext' interface AccordionReceiptProps { - contract: SubmittedContract | SubmittedProxyContract + contract: SubmittedContract index: number } @@ -13,11 +13,8 @@ export const AccordionReceipt: React.FC = ({ contract, in const [expanded, setExpanded] = React.useState(false) - const address = isProxy(contract) ? contract.implementation.address : contract.address - const chainName = useMemo(() => { - const chainId = isProxy(contract) ? contract.implementation.chainId : contract.chainId - return chains.find((chain) => chain.chainId === parseInt(chainId))?.name ?? 'Unknown Chain' + return chains.find((chain) => chain.chainId === parseInt(contract.chainId))?.name ?? 'Unknown Chain' }, [contract, chains]) const toggleAccordion = () => { @@ -25,21 +22,21 @@ export const AccordionReceipt: React.FC = ({ contract, in } return ( -
+

- {isContract(contract) ? ( + {!contract.proxyAddress ? ( ) : ( <> @@ -47,16 +44,17 @@ export const AccordionReceipt: React.FC = ({ contract, in Implementation - +
Proxy {' '} - - {shortenAddress(contract.proxy.address)} + + {shortenAddress(contract.proxyAddress)} - + {/* TODO add body for proxies */} + {/* */}
)} diff --git a/apps/contract-verification/src/app/types/VerificationTypes.ts b/apps/contract-verification/src/app/types/VerificationTypes.ts index 24289b5132..767ed68f53 100644 --- a/apps/contract-verification/src/app/types/VerificationTypes.ts +++ b/apps/contract-verification/src/app/types/VerificationTypes.ts @@ -31,10 +31,10 @@ export interface VerificationReceipt { status: VerificationStatus message?: string contractId: string + isProxyReceipt: boolean } export interface SubmittedContract { - type: 'contract' id: string filePath: string contractName: string @@ -43,30 +43,16 @@ export interface SubmittedContract { abiEncodedConstructorArgs?: string date: string receipts: VerificationReceipt[] -} - -export interface SubmittedProxyContract { - type: 'proxy' - id: string - implementation: SubmittedContract - proxy: SubmittedContract + // Only present if the contract is behind a proxy + proxyAddress?: string + proxyReceipts?: VerificationReceipt[] } // This and all nested subtypes should be pure interfaces, so they can be converted to JSON easily export interface SubmittedContracts { - // TODO implement Proxy verification - // [id: string]: SubmittedContract | SubmittedProxyContract [id: string]: SubmittedContract } -export function isProxy(contract: SubmittedContract | SubmittedProxyContract): contract is SubmittedProxyContract { - return contract.type === 'proxy' -} - -export function isContract(contract: SubmittedContract | SubmittedProxyContract): contract is SubmittedContract { - return contract.type === 'contract' -} - type SourcifyStatus = 'fully verified' | 'partially verified' type EtherscanStatus = 'verified' export type VerificationStatus = SourcifyStatus | EtherscanStatus | 'failed' | 'pending' | 'not verified' | 'unknown' | 'lookup failed' diff --git a/apps/contract-verification/src/app/views/VerifyView.tsx b/apps/contract-verification/src/app/views/VerifyView.tsx index a2c6f1667b..196cd2d797 100644 --- a/apps/contract-verification/src/app/views/VerifyView.tsx +++ b/apps/contract-verification/src/app/views/VerifyView.tsx @@ -20,11 +20,14 @@ export const VerifyView = () => { const [abiEncodingError, setAbiEncodingError] = useState('') const [selectedContract, setSelectedContract] = useState() const [enabledVerifiers, setEnabledVerifiers] = useState>>({}) + const [hasProxy, setHasProxy] = useState(false) + const [proxyAddress, setProxyAddress] = useState('') + const [proxyAddressError, setProxyAddressError] = useState('') const navigate = useNavigate() const chainSettings = selectedChain ? mergeChainSettingsWithDefaults(selectedChain.chainId.toString(), settings) : undefined - const submitDisabled = !!contractAddressError || !contractAddress || !selectedChain || !selectedContract + const submitDisabled = !!contractAddressError || !contractAddress || !selectedChain || !selectedContract || (hasProxy && !!proxyAddressError) || (hasProxy && !proxyAddress) // Enable all verifiers with valid configuration useEffect(() => { @@ -62,11 +65,10 @@ export const VerifyView = () => { apiUrl: chainSettings.verifiers[verifierId].apiUrl, name: verifierId as VerifierIdentifier, } - receipts.push({ verifierInfo, status: 'pending', contractId }) + receipts.push({ verifierInfo, status: 'pending', contractId, isProxyReceipt: false }) } const newSubmittedContract: SubmittedContract = { - type: 'contract', id: contractId, address: contractAddress, chainId: selectedChain?.chainId.toString(), @@ -116,7 +118,15 @@ export const VerifyView = () => { {selectedContract && } -
+
+ setHasProxy(e.target.checked)} /> + + {hasProxy && } +
+ +
Verify on: {VERIFIERS.map((verifierId) => { return (