Merge pull request #3606 from ethereum/etherScanImpro

Etherscan plugin improvements
pull/5370/head
yann300 2 years ago committed by GitHub
commit 1146a80499
  1. 20
      apps/etherscan/src/app/views/CaptureKeyView.tsx
  2. 7
      apps/etherscan/src/app/views/HomeView.tsx
  3. 6
      apps/etherscan/src/app/views/ReceiptsView.tsx
  4. 68
      apps/etherscan/src/app/views/VerifyView.tsx

@ -11,8 +11,9 @@ export const CaptureKeyView: React.FC = () => {
const navigate = useNavigate() const navigate = useNavigate()
return ( return (
<AppContext.Consumer> <AppContext.Consumer>
{({ apiKey, setAPIKey }) => ( {({ apiKey, clientInstance, setAPIKey }) => {
<Formik if (!apiKey && clientInstance && clientInstance.call) clientInstance.call('notification' as any, 'toast', 'Please add API key to continue')
return <Formik
initialValues={{ apiKey }} initialValues={{ apiKey }}
validate={(values) => { validate={(values) => {
const errors = {} as any const errors = {} as any
@ -22,23 +23,27 @@ export const CaptureKeyView: React.FC = () => {
return errors return errors
}} }}
onSubmit={(values) => { onSubmit={(values) => {
const apiKey = values.apiKey
if (apiKey.length === 34) {
setAPIKey(values.apiKey) setAPIKey(values.apiKey)
clientInstance.call('notification' as any, 'toast', 'API key saved successfully!!!')
navigate((location.state as any).from) navigate((location.state as any).from)
} else clientInstance.call('notification' as any, 'toast', 'API key should be 34 characters long')
}} }}
> >
{({ errors, touched, handleSubmit }) => ( {({ errors, touched, handleSubmit }) => (
<form onSubmit={handleSubmit}> <form onSubmit={handleSubmit}>
<div className="form-group" style={{ marginBottom: "0.5rem" }}> <div className="form-group" style={{ marginBottom: "0.5rem" }}>
<label htmlFor="apikey">Please Enter your API key</label> <label htmlFor="apikey">Enter Etherscan API Key</label>
<Field <Field
className={ className={
errors.apiKey && touched.apiKey errors.apiKey && touched.apiKey
? "form-control form-control-sm is-invalid" ? "form-control form-control-sm is-invalid"
: "form-control form-control-sm" : "form-control form-control-sm"
} }
type="text" type="password"
name="apiKey" name="apiKey"
placeholder="Example: GM1T20XY6JGSAPWKDCYZ7B2FJXKTJRFVGZ" placeholder="e.g. GM1T20XY6JGSAPWKDCYZ7B2FJXKTJRFVGZ"
/> />
<ErrorMessage <ErrorMessage
className="invalid-feedback" className="invalid-feedback"
@ -48,12 +53,13 @@ export const CaptureKeyView: React.FC = () => {
</div> </div>
<div> <div>
<SubmitButton text="Save API key" dataId="save-api-key" /> <SubmitButton text="Save" dataId="save-api-key" />
</div> </div>
</form> </form>
)} )}
</Formik> </Formik>
)} }
}
</AppContext.Consumer> </AppContext.Consumer>
) )
} }

@ -11,8 +11,9 @@ export const HomeView: React.FC = () => {
// const [hasError, setHasError] = useState(false) // const [hasError, setHasError] = useState(false)
return ( return (
<AppContext.Consumer> <AppContext.Consumer>
{({ apiKey, clientInstance, setReceipts, receipts, contracts }) => {({ apiKey, clientInstance, setReceipts, receipts, contracts }) => {
!apiKey ? ( if (!apiKey && clientInstance && clientInstance.call) clientInstance.call('notification' as any, 'toast', 'Please add API key to continue')
return !apiKey ? (
<Navigate <Navigate
to={{ to={{
pathname: "/settings" pathname: "/settings"
@ -25,12 +26,12 @@ export const HomeView: React.FC = () => {
apiKey={apiKey} apiKey={apiKey}
onVerifiedContract={(receipt: Receipt) => { onVerifiedContract={(receipt: Receipt) => {
const newReceipts = [...receipts, receipt] const newReceipts = [...receipts, receipt]
setReceipts(newReceipts) setReceipts(newReceipts)
}} }}
/> />
) )
} }
}
</AppContext.Consumer> </AppContext.Consumer>
) )
} }

@ -38,8 +38,9 @@ export const ReceiptsView: React.FC = () => {
return ( return (
<AppContext.Consumer> <AppContext.Consumer>
{({ apiKey, clientInstance, receipts }) => {({ apiKey, clientInstance, receipts }) => {
!apiKey ? ( if (!apiKey && clientInstance && clientInstance.call) clientInstance.call('notification' as any, 'toast', 'Please add API key to continue')
return !apiKey ? (
<Navigate <Navigate
to={{ to={{
pathname: "/settings" pathname: "/settings"
@ -102,6 +103,7 @@ export const ReceiptsView: React.FC = () => {
</div> </div>
) )
} }
}
</AppContext.Consumer> </AppContext.Consumer>
) )
} }

@ -1,4 +1,4 @@
import React, { useState } from "react" import React, { useRef, useState } from "react"
import { import {
PluginClient, PluginClient,
@ -30,6 +30,7 @@ export const VerifyView: React.FC<Props> = ({
onVerifiedContract, onVerifiedContract,
}) => { }) => {
const [results, setResults] = useState("") const [results, setResults] = useState("")
const verificationResult = useRef({})
const onVerifyContract = async (values: FormValues) => { const onVerifyContract = async (values: FormValues) => {
const compilationResult = (await client.call( const compilationResult = (await client.call(
@ -43,7 +44,7 @@ export const VerifyView: React.FC<Props> = ({
const contractArguments = values.contractArguments.replace("0x", "") const contractArguments = values.contractArguments.replace("0x", "")
const verificationResult = await verify( verificationResult.current = await verify(
apiKey, apiKey,
values.contractAddress, values.contractAddress,
contractArguments, contractArguments,
@ -53,8 +54,7 @@ export const VerifyView: React.FC<Props> = ({
onVerifiedContract, onVerifiedContract,
setResults, setResults,
) )
setResults(verificationResult.current['message'])
setResults(verificationResult.message)
} }
return ( return (
@ -73,7 +73,8 @@ export const VerifyView: React.FC<Props> = ({
if (!values.contractAddress) { if (!values.contractAddress) {
errors.contractAddress = "Required" errors.contractAddress = "Required"
} }
if (values.contractAddress.trim() === "") { if (values.contractAddress.trim() === "" || !values.contractAddress.startsWith('0x')
|| values.contractAddress.length !== 42) {
errors.contractAddress = "Please enter a valid contract address" errors.contractAddress = "Please enter a valid contract address"
} }
return errors return errors
@ -83,35 +84,12 @@ export const VerifyView: React.FC<Props> = ({
{({ errors, touched, handleSubmit, isSubmitting }) => ( {({ errors, touched, handleSubmit, isSubmitting }) => (
<form onSubmit={handleSubmit}> <form onSubmit={handleSubmit}>
<h6>Verify your smart contracts</h6> <h6>Verify your smart contracts</h6>
<button
type="button"
style={{ padding: "0.25rem 0.4rem", marginRight: "0.5em", marginBottom: "0.5em"}}
className="btn btn-primary"
title="Generate the necessary helpers to start the verification from a TypeScript script"
onClick={async () => {
if (!await client.call('fileManager', 'exists' as any, 'scripts/etherscan/receiptStatus.ts')) {
await client.call('fileManager', 'writeFile', 'scripts/etherscan/receiptStatus.ts', receiptGuidScript)
await client.call('fileManager', 'open', 'scripts/etherscan/receiptStatus.ts')
} else {
client.call('notification' as any, 'toast', 'file receiptStatus.ts already present..')
}
if (!await client.call('fileManager', 'exists' as any, 'scripts/etherscan/verify.ts')) {
await client.call('fileManager', 'writeFile', 'scripts/etherscan/verify.ts', verifyScript)
await client.call('fileManager', 'open', 'scripts/etherscan/verify.ts')
} else {
client.call('notification' as any, 'toast', 'file verify.ts already present..')
}
}}
>
Generate Etherscan helper scripts
</button>
<div className="form-group"> <div className="form-group">
<label htmlFor="contractName">Contract</label> <label htmlFor="contractName">Contract Name</label>
<Field <Field
as="select" as="select"
className={ className={
errors.contractName && touched.contractName errors.contractName && touched.contractName && contracts.length
? "form-control form-control-sm is-invalid" ? "form-control form-control-sm is-invalid"
: "form-control form-control-sm" : "form-control form-control-sm"
} }
@ -143,7 +121,7 @@ export const VerifyView: React.FC<Props> = ({
} }
type="text" type="text"
name="contractArguments" name="contractArguments"
placeholder="hex encoded" placeholder="hex encoded args"
/> />
<ErrorMessage <ErrorMessage
className="invalid-feedback" className="invalid-feedback"
@ -162,7 +140,7 @@ export const VerifyView: React.FC<Props> = ({
} }
type="text" type="text"
name="contractAddress" name="contractAddress"
placeholder="i.e. 0x11b79afc03baf25c631dd70169bb6a3160b2706e" placeholder="e.g. 0x11b79afc03baf25c631dd70169bb6a3160b2706e"
/> />
<ErrorMessage <ErrorMessage
className="invalid-feedback" className="invalid-feedback"
@ -172,12 +150,36 @@ export const VerifyView: React.FC<Props> = ({
</div> </div>
<SubmitButton dataId="verify-contract" text="Verify Contract" isSubmitting={isSubmitting} /> <SubmitButton dataId="verify-contract" text="Verify Contract" isSubmitting={isSubmitting} />
<br/><br/>
<button
type="button"
style={{ padding: "0.25rem 0.4rem", marginRight: "0.5em", marginBottom: "0.5em"}}
className="btn btn-primary"
title="Generate the required TS scripts to verify a contract on Etherscan"
onClick={async () => {
if (!await client.call('fileManager', 'exists' as any, 'scripts/etherscan/receiptStatus.ts')) {
await client.call('fileManager', 'writeFile', 'scripts/etherscan/receiptStatus.ts', receiptGuidScript)
await client.call('fileManager', 'open', 'scripts/etherscan/receiptStatus.ts')
} else {
client.call('notification' as any, 'toast', 'File receiptStatus.ts already exists')
}
if (!await client.call('fileManager', 'exists' as any, 'scripts/etherscan/verify.ts')) {
await client.call('fileManager', 'writeFile', 'scripts/etherscan/verify.ts', verifyScript)
await client.call('fileManager', 'open', 'scripts/etherscan/verify.ts')
} else {
client.call('notification' as any, 'toast', 'File verify.ts already exists')
}
}}
>
Generate Verification Scripts
</button>
</form> </form>
)} )}
</Formik> </Formik>
<div data-id="verify-result" <div data-id="verify-result"
style={{ marginTop: "2em", fontSize: "0.8em", textAlign: "center" }} style={{ marginTop: "2em", fontSize: "0.8em", textAlign: "center", color: verificationResult.current['succeed'] ? "green" : "red" }}
dangerouslySetInnerHTML={{ __html: results }} dangerouslySetInnerHTML={{ __html: results }}
/> />

Loading…
Cancel
Save