From 1472fddc68ccda5da54612de1bdc5020cd7cbbfe Mon Sep 17 00:00:00 2001 From: yann300 Date: Tue, 23 May 2023 10:51:27 +0200 Subject: [PATCH 1/3] make sure to print a message --- apps/etherscan/src/app/views/ReceiptsView.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/etherscan/src/app/views/ReceiptsView.tsx b/apps/etherscan/src/app/views/ReceiptsView.tsx index 51615b5985..7878e254ec 100644 --- a/apps/etherscan/src/app/views/ReceiptsView.tsx +++ b/apps/etherscan/src/app/views/ReceiptsView.tsx @@ -35,7 +35,7 @@ export const ReceiptsView: React.FC = () => { ) setResults({ succeed: result.status === '1' ? true : false, - message: result.result + message: result.result || (result.status === '0' ? 'Verification failed' : result.message) }) } catch (error: any) { setResults({ From 9be22e0b11e8c0da66d5c9b079bab33c178f357f Mon Sep 17 00:00:00 2001 From: yann300 Date: Tue, 23 May 2023 12:27:07 +0200 Subject: [PATCH 2/3] clear receipts list --- apps/etherscan/src/app/views/ReceiptsView.tsx | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/apps/etherscan/src/app/views/ReceiptsView.tsx b/apps/etherscan/src/app/views/ReceiptsView.tsx index 7878e254ec..f1643ac3ad 100644 --- a/apps/etherscan/src/app/views/ReceiptsView.tsx +++ b/apps/etherscan/src/app/views/ReceiptsView.tsx @@ -6,6 +6,7 @@ import { Receipt } from "../types" import { AppContext } from "../AppContext" import { SubmitButton } from "../components" import { Navigate } from "react-router-dom" +import { Button } from "react-bootstrap" interface FormValues { receiptGuid: string @@ -47,7 +48,7 @@ export const ReceiptsView: React.FC = () => { return ( - {({ apiKey, clientInstance, receipts }) => { + {({ apiKey, clientInstance, receipts, setReceipts }) => { if (!apiKey && clientInstance && clientInstance.call) clientInstance.call('notification' as any, 'toast', 'Please add API key to continue') return !apiKey ? ( { /> + ) } From 82148190d84cc5c5c1a0b816d00509de887b4558 Mon Sep 17 00:00:00 2001 From: yann300 Date: Tue, 23 May 2023 12:27:25 +0200 Subject: [PATCH 3/3] avoid api rate limit exceed --- apps/etherscan/src/app/app.tsx | 63 ++++++++++--------- apps/etherscan/src/app/types/Receipt.ts | 2 +- .../components/workspace-hamburger-item.tsx | 2 +- 3 files changed, 36 insertions(+), 31 deletions(-) diff --git a/apps/etherscan/src/app/app.tsx b/apps/etherscan/src/app/app.tsx index e7978f403a..be6564d422 100644 --- a/apps/etherscan/src/app/app.tsx +++ b/apps/etherscan/src/app/app.tsx @@ -36,6 +36,7 @@ const App = () => { const [receipts, setReceipts] = useLocalStorage("receipts", []) const [contracts, setContracts] = useState([] as string[]) const [themeType, setThemeType] = useState("dark" as ThemeType) + const timer = useRef(null) const clientInstanceRef = useRef(clientInstance) clientInstanceRef.current = clientInstance @@ -80,31 +81,35 @@ const App = () => { }, []) useEffect(() => { - if (!clientInstance) { - return - } - - const receiptsNotVerified: Receipt[] = receipts.filter((item: Receipt) => { - return item.status === "Pending in queue" + let receiptsNotVerified: Receipt[] = receipts.filter((item: Receipt) => { + return item.status === "Pending in queue" || item.status === "Max rate limit reached" }) if (receiptsNotVerified.length > 0) { - const timer1 = setInterval(() => { - receiptsNotVerified.forEach(async (item) => { - if (!clientInstanceRef.current) { - return {} - } - const { network, networkId } = await getNetworkName(clientInstanceRef.current) - if (network === "vm") { - return {} - } + if (timer.current) { + clearInterval(timer.current) + timer.current = null + } + timer.current = setInterval(async () => { + const { network, networkId } = await getNetworkName(clientInstanceRef.current) + if (!clientInstanceRef.current) { + return + } + + if (network === "vm") { + return + } + let newReceipts = receipts + for (const item of receiptsNotVerified) { + await new Promise(r => setTimeout(r, 500)) // avoid api rate limit exceed. + console.log('checking receipt', item.guid) const status = await getReceiptStatus( item.guid, apiKey, getEtherScanApi(network, networkId) ) if (status.result === "Pass - Verified" || status.result === "Already Verified") { - const newReceipts = receipts.map((currentReceipt: Receipt) => { + newReceipts = newReceipts.map((currentReceipt: Receipt) => { if (currentReceipt.guid === item.guid) { return { ...currentReceipt, @@ -112,20 +117,20 @@ const App = () => { } } return currentReceipt - }) - - clearInterval(timer1) - setReceipts(newReceipts) - - return () => { - clearInterval(timer1) - } - } - return {} + }) + } + } + receiptsNotVerified = newReceipts.filter((item: Receipt) => { + return item.status === "Pending in queue" || item.status === "Max rate limit reached" }) - }, 5000) + if (timer.current && receiptsNotVerified.length === 0) { + clearInterval(timer.current) + timer.current = null + } + setReceipts(newReceipts) + }, 10000) } - }, [receipts, clientInstance, apiKey, setReceipts]) + }, [receipts]) return ( { ) } -export default App +export default App \ No newline at end of file diff --git a/apps/etherscan/src/app/types/Receipt.ts b/apps/etherscan/src/app/types/Receipt.ts index 0ba32da969..2469aa02a8 100644 --- a/apps/etherscan/src/app/types/Receipt.ts +++ b/apps/etherscan/src/app/types/Receipt.ts @@ -1,4 +1,4 @@ -export type ReceiptStatus = "Pending in queue" | "Pass - Verified" | "Already Verified" +export type ReceiptStatus = "Pending in queue" | "Pass - Verified" | "Already Verified" | "Max rate limit reached" export interface Receipt { guid: string diff --git a/libs/remix-ui/workspace/src/lib/components/workspace-hamburger-item.tsx b/libs/remix-ui/workspace/src/lib/components/workspace-hamburger-item.tsx index dc333d301a..082746eec5 100644 --- a/libs/remix-ui/workspace/src/lib/components/workspace-hamburger-item.tsx +++ b/libs/remix-ui/workspace/src/lib/components/workspace-hamburger-item.tsx @@ -48,4 +48,4 @@ export function HamburgerMenuItem (props: HamburgerMenuItemProps) { ) - } + } \ No newline at end of file