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')