Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
manuelwedler committed Nov 1, 2024
1 parent b7b4d4e commit 6b6664c
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 11 deletions.
Original file line number Diff line number Diff line change
@@ -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()
Expand All @@ -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<void> {
// 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<void> {

// merge
// check validity
// check sourcify supported


}

async saveToRemix(lookupResponse: LookupResponse): Promise<void> {
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}`)
}
}
}
15 changes: 4 additions & 11 deletions apps/contract-verification/src/app/views/LookupView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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(() => {
Expand Down Expand Up @@ -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}`)
}
}

Expand Down

0 comments on commit 6b6664c

Please sign in to comment.