From f2ae24234194cab7f304d0291a2f3d7754e2f95b Mon Sep 17 00:00:00 2001 From: Manuel Wedler Date: Tue, 1 Oct 2024 15:41:35 +0200 Subject: [PATCH] Add verification_activated event --- .../app/ContractVerificationPluginClient.ts | 4 +++ apps/contract-verification/src/app/app.tsx | 32 +++++++++---------- 2 files changed, 20 insertions(+), 16 deletions(-) diff --git a/apps/contract-verification/src/app/ContractVerificationPluginClient.ts b/apps/contract-verification/src/app/ContractVerificationPluginClient.ts index 47e45c8cbc..8554cb29f6 100644 --- a/apps/contract-verification/src/app/ContractVerificationPluginClient.ts +++ b/apps/contract-verification/src/app/ContractVerificationPluginClient.ts @@ -11,4 +11,8 @@ export class ContractVerificationPluginClient extends PluginClient { createClient(this) this.onload() } + + onActivation(): void { + this.internalEvents.emit('verification_activated') + } } diff --git a/apps/contract-verification/src/app/app.tsx b/apps/contract-verification/src/app/app.tsx index 3fcee010ea..0ea4332543 100644 --- a/apps/contract-verification/src/app/app.tsx +++ b/apps/contract-verification/src/app/app.tsx @@ -36,24 +36,24 @@ const App = () => { const timer = useRef(null) useEffect(() => { - // Fetch compiler artefacts initially - plugin.call('compilerArtefacts' as any, 'getAllCompilerAbstracts').then((obj: any) => { - setCompilationOutput(obj) + plugin.internalEvents.on('verification_activated', () => { + // Fetch compiler artefacts initially + plugin.call('compilerArtefacts' as any, 'getAllCompilerAbstracts').then((obj: any) => { + setCompilationOutput(obj) + }) + + // Subscribe to compilations + plugin.on('compilerArtefacts' as any, 'compilationSaved', (compilerAbstracts: { [key: string]: CompilerAbstract }) => { + setCompilationOutput((prev) => ({ ...(prev || {}), ...compilerAbstracts })) + }) + + // Fetch chains.json and update state + fetch('https://chainid.network/chains.json') + .then((response) => response.json()) + .then((data) => setChains(data)) + .catch((error) => console.error('Failed to fetch chains.json:', error)) }) - // Subscribe to compilations - plugin.on('compilerArtefacts' as any, 'compilationSaved', (compilerAbstracts: { [key: string]: CompilerAbstract }) => { - setCompilationOutput((prev) => ({ ...(prev || {}), ...compilerAbstracts })) - }) - - // TODO: Is there a way to get all compilations from the `build-info` files without having to compile again? - - // Fetch chains.json and update state - fetch('https://chainid.network/chains.json') - .then((response) => response.json()) - .then((data) => setChains(data)) - .catch((error) => console.error('Failed to fetch chains.json:', error)) - // Clean up on unmount return () => { plugin.off('compilerArtefacts' as any, 'compilationSaved')