Move default api urls to a json structure

pull/5285/head
Manuel Wedler 4 months ago committed by Aniket
parent a3427b4795
commit cc6c24677e
  1. 3
      apps/contract-verification/src/app/app.tsx
  2. 46
      apps/contract-verification/src/app/types/defaults.ts
  3. 1
      apps/contract-verification/src/app/types/index.ts
  4. 17
      apps/contract-verification/src/app/utils/default-apis.json
  5. 28
      apps/contract-verification/src/app/utils/default-settings.ts
  6. 1
      apps/contract-verification/src/app/utils/index.ts
  7. 4
      apps/contract-verification/src/app/views/LookupView.tsx
  8. 2
      apps/contract-verification/src/app/views/SettingsView.tsx
  9. 4
      apps/contract-verification/src/app/views/VerifyView.tsx
  10. 1
      apps/contract-verification/tsconfig.json

@ -4,7 +4,8 @@ import { ContractVerificationPluginClient } from './ContractVerificationPluginCl
import { AppContext } from './AppContext'
import DisplayRoutes from './routes'
import { ContractVerificationSettings, ThemeType, Chain, SubmittedContracts, VerificationReceipt, mergeChainSettingsWithDefaults } from './types'
import type { ContractVerificationSettings, ThemeType, Chain, SubmittedContracts, VerificationReceipt } from './types'
import { mergeChainSettingsWithDefaults } from './utils'
import './App.css'
import { CompilerAbstract } from '@remix-project/remix-solidity'

@ -1,46 +0,0 @@
import type { ChainSettings, ContractVerificationSettings, SettingsForVerifier, VerifierSettings } from './SettingsTypes'
import { VerifierIdentifier, VERIFIERS } from './VerificationTypes'
const DEFAULTS: SettingsForVerifier = {
Sourcify: {
apiUrl: 'https://sourcify.dev/server',
explorerUrl: 'https://repo.sourcify.dev',
},
Etherscan: {
apiUrl: 'https://api.etherscan.io',
explorerUrl: 'https://etherscan.io',
apiKey: undefined,
},
Blockscout: {
apiUrl: 'https://eth.blockscout.com',
},
}
export function mergeChainSettingsWithDefaults(chainId: string, userSettings: ContractVerificationSettings): ChainSettings {
const verifiers: SettingsForVerifier = {}
for (const verifierId of VERIFIERS) {
const userSetting: VerifierSettings = userSettings.chains[chainId]?.verifiers[verifierId]
if (userSetting) {
verifiers[verifierId] = { ...userSetting }
// Only apply default settings for Etherscan and Blockscout on mainnet
if (verifierId === 'Sourcify' || chainId === '1') {
// Add keys not defined by user
for (const key of Object.keys(DEFAULTS[verifierId])) {
if (!verifiers[verifierId][key]) {
verifiers[verifierId][key] = DEFAULTS[verifierId][key]
}
}
}
// Only apply default settings for Etherscan and Blockscout on mainnet
} else if (verifierId === 'Sourcify' || chainId === '1') {
verifiers[verifierId] = DEFAULTS[verifierId]
}
}
return { verifiers }
}
export function validConfiguration(chainSettings: ChainSettings | undefined, verifierId: VerifierIdentifier) {
return !!chainSettings && !!chainSettings.verifiers[verifierId]?.apiUrl && (verifierId !== 'Etherscan' || !!chainSettings.verifiers[verifierId]?.apiKey)
}

@ -1,4 +1,3 @@
export * from './ThemeType'
export * from './SettingsTypes'
export * from './VerificationTypes'
export * from './defaults'

@ -0,0 +1,17 @@
{
"Sourcify": {
"apiUrl": "https://sourcify.dev/server",
"explorerUrl": "https://repo.sourcify.dev"
},
"Etherscan": {
"1": {
"apiUrl": "https://api.etherscan.io",
"explorerUrl": "https://etherscan.io"
}
},
"Blockscout": {
"1": {
"apiUrl": "https://eth.blockscout.com"
}
}
}

@ -0,0 +1,28 @@
import type { ChainSettings, ContractVerificationSettings, SettingsForVerifier, VerifierSettings } from '../types/SettingsTypes'
import { VerifierIdentifier, VERIFIERS } from '../types/VerificationTypes'
import DEFAULT_APIS from './default-apis.json'
export function mergeChainSettingsWithDefaults(chainId: string, userSettings: ContractVerificationSettings): ChainSettings {
const verifiers: SettingsForVerifier = {}
for (const verifierId of VERIFIERS) {
const userSetting: VerifierSettings = userSettings.chains[chainId]?.verifiers[verifierId] ?? {}
verifiers[verifierId] = { ...userSetting }
let defaultsForVerifier: VerifierSettings
if (verifierId === 'Sourcify') {
defaultsForVerifier = DEFAULT_APIS['Sourcify']
} else {
defaultsForVerifier = DEFAULT_APIS[verifierId][chainId] ?? {}
}
// Prefer user settings over defaults
verifiers[verifierId] = Object.assign({}, defaultsForVerifier, userSetting)
}
return { verifiers }
}
export function validConfiguration(chainSettings: ChainSettings | undefined, verifierId: VerifierIdentifier) {
return !!chainSettings && !!chainSettings.verifiers[verifierId]?.apiUrl && (verifierId !== 'Etherscan' || !!chainSettings.verifiers[verifierId]?.apiKey)
}

@ -0,0 +1 @@
export * from './default-settings'

@ -1,6 +1,8 @@
import { useContext, useState } from 'react'
import { SearchableChainDropdown, ContractAddressInput } from '../components'
import { LookupResponse, mergeChainSettingsWithDefaults, validConfiguration, VerifierIdentifier, VERIFIERS, type Chain } from '../types'
import { mergeChainSettingsWithDefaults, validConfiguration } from '../utils'
import type { LookupResponse, VerifierIdentifier, Chain } from '../types'
import { VERIFIERS } from '../types'
import { AppContext } from '../AppContext'
import { CustomTooltip } from '@remix-ui/helper'
import { getVerifier } from '../Verifiers'

@ -1,7 +1,7 @@
import { useContext, useState } from 'react'
import { SearchableChainDropdown, ConfigInput } from '../components'
import type { VerifierIdentifier, Chain, VerifierSettings, ContractVerificationSettings } from '../types'
import { mergeChainSettingsWithDefaults } from '../types'
import { mergeChainSettingsWithDefaults } from '../utils'
import { AppContext } from '../AppContext'
export const SettingsView = () => {

@ -2,7 +2,9 @@ import { useContext, useEffect, useState } from 'react'
import { AppContext } from '../AppContext'
import { SearchableChainDropdown, ContractDropdown, ContractAddressInput } from '../components'
import { mergeChainSettingsWithDefaults, type VerifierIdentifier, VERIFIERS, type Chain, type SubmittedContract, type VerificationReceipt, type VerifierInfo, validConfiguration } from '../types'
import type { VerifierIdentifier, Chain, SubmittedContract, VerificationReceipt, VerifierInfo } from '../types'
import { VERIFIERS } from '../types'
import { mergeChainSettingsWithDefaults, validConfiguration } from '../utils'
import { useNavigate } from 'react-router-dom'
import { ConstructorArguments } from '../components/ConstructorArguments'
import { ContractDropdownSelection } from '../components/ContractDropdown'

@ -5,6 +5,7 @@
"allowJs": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"resolveJsonModule": true,
// "strict": true
},
"files": [],

Loading…
Cancel
Save