Merge branch 'master' into deactivatewallet

pull/5370/head
David Disu 2 years ago committed by GitHub
commit b689f4a869
  1. 4
      apps/etherscan/src/app/RemixPlugin.tsx
  2. 4
      apps/etherscan/src/app/app.tsx
  3. 2
      apps/etherscan/src/app/routes.tsx
  4. 33
      apps/etherscan/src/app/utils/networks.ts
  5. 22
      apps/etherscan/src/app/utils/utilities.ts
  6. 4
      apps/etherscan/src/app/utils/verify.ts
  7. 4
      apps/etherscan/src/app/views/ReceiptsView.tsx
  8. 2
      apps/etherscan/src/app/views/VerifyView.tsx
  9. 4
      apps/etherscan/src/profile.json

@ -16,11 +16,11 @@ export class RemixClient extends PluginClient {
async receiptStatus (receiptGuid: string, apiKey: string) {
try {
const network = await getNetworkName(this)
const { network, networkId } = await getNetworkName(this)
if (network === "vm") {
throw new Error("Cannot check the receipt status in the selected network")
}
const etherscanApi = getEtherScanApi(network)
const etherscanApi = getEtherScanApi(network, networkId)
const receiptStatus = await getReceiptStatus(receiptGuid, apiKey, etherscanApi)
return {
message: receiptStatus.result,

@ -94,14 +94,14 @@ const App = () => {
if (!clientInstanceRef.current) {
return {}
}
const network = await getNetworkName(clientInstanceRef.current)
const { network, networkId } = await getNetworkName(clientInstanceRef.current)
if (network === "vm") {
return {}
}
const status = await getReceiptStatus(
item.guid,
apiKey,
getEtherScanApi(network)
getEtherScanApi(network, networkId)
)
if (status.result === "Pass - Verified" || status.result === "Already Verified") {
const newReceipts = receipts.map((currentReceipt: Receipt) => {

@ -43,7 +43,7 @@ export const DisplayRoutes = () => (
</DefaultLayout>} />
<Route
path="/settings"
element={<DefaultLayout from="/settings" title="Set Etherscan API Key">
element={<DefaultLayout from="/settings" title="Set Explorer API Key">
<CaptureKeyView />
</DefaultLayout>} />
</Routes>

@ -0,0 +1,33 @@
export const scanAPIurls = {
// all mainnet
56: "https://api.bscscan.com/api",
137: "https://api.polygonscan.com/api",
250: "https://api.ftmscan.com/api",
42161: "https://api.arbiscan.io/api",
43114: "https://api.snowtrace.io/api",
1285: "https://api-moonriver.moonscan.io/api",
1284: "https://api-moonbeam.moonscan.io/api",
25: "https://api.cronoscan.com/api",
199: "https://api.bttcscan.com/api",
10: "https://api-optimistic.etherscan.io/api",
42220: "https://api.celoscan.io/api",
288: "https://api.bobascan.com/api",
100: "https://api.gnosisscan.io/api",
1101: "https://api-zkevm.polygonscan.com/api",
// all testnet
97: "https://api-testnet.bscscan.com/api",
80001: "https://api-testnet.polygonscan.com/api",
4002: "https://api-testnet.ftmscan.com/api",
421611: "https://api-testnet.arbiscan.io/api",
42170: "https://api-nova.arbiscan.io/api",
43113: "https://api-testnet.snowtrace.io/api",
1287: "https://api-moonbase.moonscan.io/api",
338: "https://api-testnet.cronoscan.com/api",
1028: "https://api-testnet.bttcscan.com/api",
420: "https://api-goerli-optimistic.etherscan.io/api",
44787: "https://api-alfajores.celoscan.io/api",
2888: "https://api-testnet.bobascan.com/api",
84531: "https://api-goerli.basescan.org/api",
1442: "https://api-testnet-zkevm.polygonscan.com/api"
}

@ -1,5 +1,6 @@
import { PluginClient } from "@remixproject/plugin"
import axios from 'axios'
import { scanAPIurls } from "./networks"
type RemixClient = PluginClient
/*
@ -13,10 +14,21 @@ export type receiptStatus = {
status: string
}
export const getEtherScanApi = (network: string) => {
return network === "main"
? `https://api.etherscan.io/api`
: `https://api-${network}.etherscan.io/api`
export const getEtherScanApi = (network: string, networkId: any) => {
let apiUrl
if (network === "main") {
apiUrl = "https://api.etherscan.io/api"
} else if (network === "custom") {
if (!(networkId in scanAPIurls)) {
throw new Error("no known network to verify against")
}
apiUrl = (scanAPIurls as any)[networkId]
} else {
apiUrl = `https://api-${network}.etherscan.io/api`
}
return apiUrl
}
export const getNetworkName = async (client: RemixClient) => {
@ -24,7 +36,7 @@ export const getNetworkName = async (client: RemixClient) => {
if (!network) {
throw new Error("no known network to verify against")
}
return network.name!.toLowerCase()
return { network: network.name!.toLowerCase(), networkId: network.id }
}
export const getReceiptStatus = async (

@ -25,14 +25,14 @@ export const verify = async (
onVerifiedContract: (value: EtherScanReturn) => void,
setResults: (value: string) => void
) => {
const network = await getNetworkName(client)
const { network, networkId } = await getNetworkName(client)
if (network === "vm") {
return {
succeed: false,
message: "Cannot verify in the selected network"
}
}
const etherscanApi = getEtherScanApi(network)
const etherscanApi = getEtherScanApi(network, networkId)
try {
const contractMetadata = getContractMetadata(

@ -19,7 +19,7 @@ export const ReceiptsView: React.FC = () => {
apiKey: string
) => {
try {
const network = await getNetworkName(clientInstance)
const { network, networkId } = await getNetworkName(clientInstance)
if (network === "vm") {
setResults({
succeed: false,
@ -27,7 +27,7 @@ export const ReceiptsView: React.FC = () => {
})
return
}
const etherscanApi = getEtherScanApi(network)
const etherscanApi = getEtherScanApi(network, networkId)
const result = await getReceiptStatus(
values.receiptGuid,
apiKey,

@ -38,7 +38,7 @@ export const VerifyView: React.FC<Props> = ({
useEffect(() => {
if (client && client.on) {
client.on("blockchain" as any, 'networkStatus', (result) => {
setNetworkName(result.network.name)
setNetworkName(`${result.network.name} (Chain id: ${result.network.id})`)
})
}
return () => {

@ -1,7 +1,7 @@
{
"name": "etherscan",
"displayName": "Etherscan - Contract verification",
"description": "Verify Solidity contract code using Etherscan API",
"displayName": "Contract verification - Etherscan",
"description": "Verify Solidity contract code using Etherscan, BscScan, PolygonScan etc. APIs",
"version": "0.1.0",
"events": [],
"methods": ["verify", "receiptStatus"],

Loading…
Cancel
Save