From 6b6664ccdce9c305ca65b13cdbcc824884063ac2 Mon Sep 17 00:00:00 2001 From: Manuel Wedler Date: Fri, 1 Nov 2024 16:03:52 +0100 Subject: [PATCH] wip --- .../app/ContractVerificationPluginClient.ts | 42 +++++++++++++++++++ .../src/app/views/LookupView.tsx | 15 ++----- 2 files changed, 46 insertions(+), 11 deletions(-) diff --git a/apps/contract-verification/src/app/ContractVerificationPluginClient.ts b/apps/contract-verification/src/app/ContractVerificationPluginClient.ts index 8554cb29f6b..f386fa39cf0 100644 --- a/apps/contract-verification/src/app/ContractVerificationPluginClient.ts +++ b/apps/contract-verification/src/app/ContractVerificationPluginClient.ts @@ -1,12 +1,14 @@ import { PluginClient } from '@remixproject/plugin' import { createClient } from '@remixproject/plugin-webview' import EventManager from 'events' +import type { LookupResponse, VerifierIdentifier } from './types' export class ContractVerificationPluginClient extends PluginClient { public internalEvents: EventManager constructor() { super() + this.methods = ['lookupAndSave'] this.internalEvents = new EventManager() createClient(this) this.onload() @@ -15,4 +17,44 @@ export class ContractVerificationPluginClient extends PluginClient { onActivation(): void { this.internalEvents.emit('verification_activated') } + + // TODO: Find solution for useSourcifySupported + // Maybe define global mapping: apiUrl -> chainId -> supported + // could be part of the plugin client + // implement check method in plugin client: + // if not supportStatus not fetched for api yet, fetch it + // useSourcifySupported could then depend on the client as a dependency + + async lookupAndSave(verifierId: VerifierIdentifier, contractAddress: string, chainId: string): Promise { + // get chainsettings via chainId + // -> settings must be accessible here + + + // Must handle errors and console.error because this is the external function + + } + + async lookup(verifierId: VerifierIdentifier, contractAddress: string, chainId: string): Promise { + + // merge + // check validity + // check sourcify supported + + + } + + async saveToRemix(lookupResponse: LookupResponse): Promise { + for (const source of lookupResponse.sourceFiles ?? []) { + try { + await this.call('fileManager', 'setFile', source.path, source.content) + } catch (err) { + throw new Error(`Error while creating file ${source.path}: ${err.message}`) + } + } + try { + await this.call('fileManager', 'open', lookupResponse.targetFilePath) + } catch (err) { + throw new Error(`Error focusing file ${lookupResponse.targetFilePath}: ${err.message}`) + } + } } diff --git a/apps/contract-verification/src/app/views/LookupView.tsx b/apps/contract-verification/src/app/views/LookupView.tsx index de098887183..52cb4beb8ae 100644 --- a/apps/contract-verification/src/app/views/LookupView.tsx +++ b/apps/contract-verification/src/app/views/LookupView.tsx @@ -24,7 +24,7 @@ export const LookupView = () => { const sourcifySupported = useSourcifySupported(selectedChain, chainSettings) const noVerifierEnabled = VERIFIERS.every((verifierId) => !validConfiguration(chainSettings, verifierId) || (verifierId === 'Sourcify' && !sourcifySupported)) - const submitDisabled = !!contractAddressError || !contractAddress || !selectedChain || noVerifierEnabled + const submitDisabled = !!contractAddressError || !contractAddress || !selectedChain || noVerifierEnabled || Object.values(loadingVerifiers).some((loading) => loading) // Reset results when chain or contract changes useEffect(() => { @@ -63,20 +63,13 @@ export const LookupView = () => { const sendToMatomo = async (eventAction: string, eventName: string) => { await clientInstance.call('matomo' as any, 'track', ['trackEvent', 'ContractVerification', eventAction, eventName]); } - + const handleOpenInRemix = async (lookupResponse: LookupResponse) => { - for (const source of lookupResponse.sourceFiles ?? []) { - try { - await clientInstance.call('fileManager', 'setFile', source.path, source.content) - } catch (err) { - console.error(`Error while creating file ${source.path}: ${err.message}`) - } - } try { - await clientInstance.call('fileManager', 'open', lookupResponse.targetFilePath) + await clientInstance.saveToRemix(lookupResponse) await sendToMatomo('lookup', "openInRemix On: " + selectedChain) } catch (err) { - console.error(`Error focusing file ${lookupResponse.targetFilePath}: ${err.message}`) + console.error(`Error while trying to open in Remix: ${err.message}`) } }