diff --git a/apps/etherscan/src/app/views/CaptureKeyView.tsx b/apps/etherscan/src/app/views/CaptureKeyView.tsx index 9703ec10ff..3e3540a145 100644 --- a/apps/etherscan/src/app/views/CaptureKeyView.tsx +++ b/apps/etherscan/src/app/views/CaptureKeyView.tsx @@ -11,8 +11,9 @@ export const CaptureKeyView: React.FC = () => { const navigate = useNavigate() return ( - {({ apiKey, setAPIKey }) => ( - { + if (!apiKey && clientInstance && clientInstance.call) clientInstance.call('notification' as any, 'toast', 'Please add API key to continue') + return { const errors = {} as any @@ -22,23 +23,27 @@ export const CaptureKeyView: React.FC = () => { return errors }} onSubmit={(values) => { - setAPIKey(values.apiKey) - navigate((location.state as any).from) + const apiKey = values.apiKey + if (apiKey.length === 34) { + setAPIKey(values.apiKey) + clientInstance.call('notification' as any, 'toast', 'API key saved successfully!!!') + navigate((location.state as any).from) + } else clientInstance.call('notification' as any, 'toast', 'API key should be 34 characters long') }} > {({ errors, touched, handleSubmit }) => ( - Please Enter your API key + Enter Etherscan API Key { - + )} - )} + } + } ) } diff --git a/apps/etherscan/src/app/views/HomeView.tsx b/apps/etherscan/src/app/views/HomeView.tsx index 0b9d2e3820..14070ee6e0 100644 --- a/apps/etherscan/src/app/views/HomeView.tsx +++ b/apps/etherscan/src/app/views/HomeView.tsx @@ -11,8 +11,9 @@ export const HomeView: React.FC = () => { // const [hasError, setHasError] = useState(false) return ( - {({ apiKey, clientInstance, setReceipts, receipts, contracts }) => - !apiKey ? ( + {({ apiKey, clientInstance, setReceipts, receipts, contracts }) => { + if (!apiKey && clientInstance && clientInstance.call) clientInstance.call('notification' as any, 'toast', 'Please add API key to continue') + return !apiKey ? ( { apiKey={apiKey} onVerifiedContract={(receipt: Receipt) => { const newReceipts = [...receipts, receipt] - setReceipts(newReceipts) }} /> ) } + } ) } diff --git a/apps/etherscan/src/app/views/ReceiptsView.tsx b/apps/etherscan/src/app/views/ReceiptsView.tsx index 4d07953a38..937ea34874 100644 --- a/apps/etherscan/src/app/views/ReceiptsView.tsx +++ b/apps/etherscan/src/app/views/ReceiptsView.tsx @@ -38,8 +38,9 @@ export const ReceiptsView: React.FC = () => { return ( - {({ apiKey, clientInstance, receipts }) => - !apiKey ? ( + {({ apiKey, clientInstance, receipts }) => { + if (!apiKey && clientInstance && clientInstance.call) clientInstance.call('notification' as any, 'toast', 'Please add API key to continue') + return !apiKey ? ( { ) } + } ) } diff --git a/apps/etherscan/src/app/views/VerifyView.tsx b/apps/etherscan/src/app/views/VerifyView.tsx index cc71a46418..5dea0529f0 100644 --- a/apps/etherscan/src/app/views/VerifyView.tsx +++ b/apps/etherscan/src/app/views/VerifyView.tsx @@ -1,4 +1,4 @@ -import React, { useState } from "react" +import React, { useRef, useState } from "react" import { PluginClient, @@ -30,6 +30,7 @@ export const VerifyView: React.FC = ({ onVerifiedContract, }) => { const [results, setResults] = useState("") + const verificationResult = useRef({}) const onVerifyContract = async (values: FormValues) => { const compilationResult = (await client.call( @@ -43,7 +44,7 @@ export const VerifyView: React.FC = ({ const contractArguments = values.contractArguments.replace("0x", "") - const verificationResult = await verify( + verificationResult.current = await verify( apiKey, values.contractAddress, contractArguments, @@ -53,8 +54,7 @@ export const VerifyView: React.FC = ({ onVerifiedContract, setResults, ) - - setResults(verificationResult.message) + setResults(verificationResult.current['message']) } return ( @@ -73,7 +73,8 @@ export const VerifyView: React.FC = ({ if (!values.contractAddress) { 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" } return errors @@ -83,35 +84,12 @@ export const VerifyView: React.FC = ({ {({ errors, touched, handleSubmit, isSubmitting }) => ( Verify your smart contracts - { - 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 - - Contract + Contract Name = ({ } type="text" name="contractArguments" - placeholder="hex encoded" + placeholder="hex encoded args" /> = ({ } type="text" name="contractAddress" - placeholder="i.e. 0x11b79afc03baf25c631dd70169bb6a3160b2706e" + placeholder="e.g. 0x11b79afc03baf25c631dd70169bb6a3160b2706e" /> = ({ + + { + 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 + )}