diff --git a/apps/contract-verification/src/app/ContractVerificationPluginClient.ts b/apps/contract-verification/src/app/ContractVerificationPluginClient.ts index be2b40ea9f5..498ab5d75f4 100644 --- a/apps/contract-verification/src/app/ContractVerificationPluginClient.ts +++ b/apps/contract-verification/src/app/ContractVerificationPluginClient.ts @@ -9,6 +9,7 @@ import { CompilerAbstract } from '@remix-project/remix-solidity' export class ContractVerificationPluginClient extends PluginClient { public internalEvents: EventManager + private _isActivated: boolean = false constructor() { super() @@ -19,9 +20,14 @@ export class ContractVerificationPluginClient extends PluginClient { } onActivation(): void { + this._isActivated = true this.internalEvents.emit('verification_activated') } + isActivated(): boolean { + return this._isActivated + } + async lookupAndSave(verifierId: string, chainId: string, contractAddress: string): Promise { const canonicalVerifierId = VERIFIERS.find((id) => id.toLowerCase() === verifierId.toLowerCase()) if (!canonicalVerifierId) { diff --git a/apps/contract-verification/src/app/app.tsx b/apps/contract-verification/src/app/app.tsx index 235b8c2679a..8a3237204ea 100644 --- a/apps/contract-verification/src/app/app.tsx +++ b/apps/contract-verification/src/app/app.tsx @@ -41,7 +41,7 @@ const App = () => { const timer = useRef(null) useEffect(() => { - plugin.internalEvents.on('verification_activated', () => { + const initializePlugin = () => { // @ts-ignore plugin.call('locale', 'currentLocale').then((locale: any) => { setLocale(locale) @@ -51,6 +51,7 @@ const App = () => { plugin.on('locale', 'localeChanged', (locale: any) => { setLocale(locale) }) + // Fetch compiler artefacts initially plugin.call('compilerArtefacts' as any, 'getAllCompilerAbstracts').then((obj: any) => { setCompilationOutput(obj) @@ -60,7 +61,17 @@ const App = () => { plugin.on('compilerArtefacts' as any, 'compilationSaved', (compilerAbstracts: { [key: string]: CompilerAbstract }) => { setCompilationOutput((prev) => ({ ...(prev || {}), ...compilerAbstracts })) }) - }) + } + + // Check if plugin is already activated + if (plugin.isActivated()) { + initializePlugin() + } else { + // Listen for activation event if not yet activated + plugin.internalEvents.once('verification_activated', () => { + initializePlugin() + }) + } // Fetch chains.json and update state fetch('https://chainid.network/chains.json')