Add verification_activated event

pull/5285/head
Manuel Wedler 2 months ago committed by Aniket
parent 375a88b188
commit f2ae242341
  1. 4
      apps/contract-verification/src/app/ContractVerificationPluginClient.ts
  2. 32
      apps/contract-verification/src/app/app.tsx

@ -11,4 +11,8 @@ export class ContractVerificationPluginClient extends PluginClient {
createClient(this) createClient(this)
this.onload() this.onload()
} }
onActivation(): void {
this.internalEvents.emit('verification_activated')
}
} }

@ -36,24 +36,24 @@ const App = () => {
const timer = useRef(null) const timer = useRef(null)
useEffect(() => { useEffect(() => {
// Fetch compiler artefacts initially plugin.internalEvents.on('verification_activated', () => {
plugin.call('compilerArtefacts' as any, 'getAllCompilerAbstracts').then((obj: any) => { // Fetch compiler artefacts initially
setCompilationOutput(obj) 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 // Clean up on unmount
return () => { return () => {
plugin.off('compilerArtefacts' as any, 'compilationSaved') plugin.off('compilerArtefacts' as any, 'compilationSaved')

Loading…
Cancel
Save