|
|
@ -2,8 +2,7 @@ import React, {useState, useEffect, useRef} from 'react' |
|
|
|
|
|
|
|
|
|
|
|
import {CompilationFileSources, CompilationResult} from '@remixproject/plugin-api' |
|
|
|
import {CompilationFileSources, CompilationResult} from '@remixproject/plugin-api' |
|
|
|
|
|
|
|
|
|
|
|
import {RemixClient} from './RemixPlugin' |
|
|
|
import { EtherscanPluginClient } from './EtherscanPluginClient' |
|
|
|
import {createClient} from '@remixproject/plugin-webview' |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import {AppContext} from './AppContext' |
|
|
|
import {AppContext} from './AppContext' |
|
|
|
import {DisplayRoutes} from './routes' |
|
|
|
import {DisplayRoutes} from './routes' |
|
|
@ -21,32 +20,29 @@ export const getNewContractNames = (compilationResult: CompilationResult) => { |
|
|
|
|
|
|
|
|
|
|
|
for (const file of Object.keys(compiledContracts)) { |
|
|
|
for (const file of Object.keys(compiledContracts)) { |
|
|
|
const newContractNames = Object.keys(compiledContracts[file]) |
|
|
|
const newContractNames = Object.keys(compiledContracts[file]) |
|
|
|
|
|
|
|
|
|
|
|
result = [...result, ...newContractNames] |
|
|
|
result = [...result, ...newContractNames] |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return result |
|
|
|
return result |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const plugin = new EtherscanPluginClient() |
|
|
|
|
|
|
|
|
|
|
|
const App = () => { |
|
|
|
const App = () => { |
|
|
|
const [apiKey, setAPIKey] = useLocalStorage('apiKey', '') |
|
|
|
const [apiKey, setAPIKey] = useLocalStorage('apiKey', '') |
|
|
|
const [clientInstance, setClientInstance] = useState(undefined as any) |
|
|
|
const [receipts, setReceipts] = useLocalStorage('receipts', [])
|
|
|
|
const [receipts, setReceipts] = useLocalStorage('receipts', []) |
|
|
|
const [contracts, setContracts] = useState<string[]>([]) |
|
|
|
const [contracts, setContracts] = useState([] as string[]) |
|
|
|
const [themeType, setThemeType] = useState<ThemeType>('dark') |
|
|
|
const [themeType, setThemeType] = useState('dark' as ThemeType) |
|
|
|
const [networkName, setNetworkName] = useState('Loading...') |
|
|
|
const timer = useRef(null) |
|
|
|
const timer = useRef(null) |
|
|
|
|
|
|
|
|
|
|
|
const clientInstanceRef = useRef(clientInstance) |
|
|
|
|
|
|
|
clientInstanceRef.current = clientInstance |
|
|
|
|
|
|
|
const contractsRef = useRef(contracts) |
|
|
|
const contractsRef = useRef(contracts) |
|
|
|
|
|
|
|
|
|
|
|
contractsRef.current = contracts |
|
|
|
contractsRef.current = contracts |
|
|
|
|
|
|
|
|
|
|
|
useEffect(() => { |
|
|
|
useEffect(() => { |
|
|
|
const client = new RemixClient() |
|
|
|
plugin.internalEvents.on('etherscan_activated', () => { |
|
|
|
createClient(client) |
|
|
|
plugin.on('solidity', 'compilationFinished', (fileName: string, source: CompilationFileSources, languageVersion: string, data: CompilationResult) => { |
|
|
|
const loadClient = async () => { |
|
|
|
|
|
|
|
await client.onload() |
|
|
|
|
|
|
|
setClientInstance(client) |
|
|
|
|
|
|
|
client.on('solidity', 'compilationFinished', (fileName: string, source: CompilationFileSources, languageVersion: string, data: CompilationResult) => { |
|
|
|
|
|
|
|
const newContractsNames = getNewContractNames(data) |
|
|
|
const newContractsNames = getNewContractNames(data) |
|
|
|
|
|
|
|
|
|
|
|
const newContractsToSave: string[] = [...contractsRef.current, ...newContractsNames] |
|
|
|
const newContractsToSave: string[] = [...contractsRef.current, ...newContractsNames] |
|
|
@ -55,21 +51,16 @@ const App = () => { |
|
|
|
|
|
|
|
|
|
|
|
setContracts(uniqueContracts) |
|
|
|
setContracts(uniqueContracts) |
|
|
|
}) |
|
|
|
}) |
|
|
|
|
|
|
|
plugin.on('blockchain' as any, 'networkStatus', (result) => { |
|
|
|
//const currentTheme = await client.call("theme", "currentTheme")
|
|
|
|
setNetworkName(`${result.network.name} ${result.network.id !== '-' ? `(Chain id: ${result.network.id})` : '(Not supported)'}`) |
|
|
|
//setThemeType(currentTheme.quality)
|
|
|
|
}) |
|
|
|
//client.on("theme", "themeChanged", (theme) => {
|
|
|
|
// @ts-ignore
|
|
|
|
// setThemeType(theme.quality)
|
|
|
|
plugin.call('blockchain', 'getCurrentNetworkStatus').then((result: any) => setNetworkName(`${result.network.name} ${result.network.id !== '-' ? `(Chain id: ${result.network.id})` : '(Not supported)'}`)) |
|
|
|
//})
|
|
|
|
}) |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
loadClient() |
|
|
|
|
|
|
|
}, []) |
|
|
|
}, []) |
|
|
|
|
|
|
|
|
|
|
|
useEffect(() => { |
|
|
|
useEffect(() => { |
|
|
|
let receiptsNotVerified: Receipt[] = receipts.filter((item: Receipt) => { |
|
|
|
let receiptsNotVerified: Receipt[] = receipts.filter((item: Receipt) => item.status === 'Pending in queue' || item.status === 'Max rate limit reached') |
|
|
|
return item.status === 'Pending in queue' || item.status === 'Max rate limit reached' |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (receiptsNotVerified.length > 0) { |
|
|
|
if (receiptsNotVerified.length > 0) { |
|
|
|
if (timer.current) { |
|
|
|
if (timer.current) { |
|
|
@ -77,15 +68,12 @@ const App = () => { |
|
|
|
timer.current = null |
|
|
|
timer.current = null |
|
|
|
} |
|
|
|
} |
|
|
|
timer.current = setInterval(async () => { |
|
|
|
timer.current = setInterval(async () => { |
|
|
|
const {network, networkId} = await getNetworkName(clientInstanceRef.current) |
|
|
|
const {network, networkId} = await getNetworkName(plugin) |
|
|
|
if (!clientInstanceRef.current) { |
|
|
|
|
|
|
|
return |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (network === 'vm') { |
|
|
|
if (!plugin) return |
|
|
|
return |
|
|
|
if (network === 'vm') return |
|
|
|
} |
|
|
|
|
|
|
|
let newReceipts = receipts |
|
|
|
let newReceipts = receipts |
|
|
|
|
|
|
|
|
|
|
|
for (const item of receiptsNotVerified) { |
|
|
|
for (const item of receiptsNotVerified) { |
|
|
|
await new Promise((r) => setTimeout(r, 500)) // avoid api rate limit exceed.
|
|
|
|
await new Promise((r) => setTimeout(r, 500)) // avoid api rate limit exceed.
|
|
|
|
let status |
|
|
|
let status |
|
|
@ -110,9 +98,7 @@ const App = () => { |
|
|
|
}) |
|
|
|
}) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
receiptsNotVerified = newReceipts.filter((item: Receipt) => { |
|
|
|
receiptsNotVerified = newReceipts.filter((item: Receipt) => item.status === 'Pending in queue' || item.status === 'Max rate limit reached') |
|
|
|
return item.status === 'Pending in queue' || item.status === 'Max rate limit reached' |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
if (timer.current && receiptsNotVerified.length === 0) { |
|
|
|
if (timer.current && receiptsNotVerified.length === 0) { |
|
|
|
clearInterval(timer.current) |
|
|
|
clearInterval(timer.current) |
|
|
|
timer.current = null |
|
|
|
timer.current = null |
|
|
@ -127,16 +113,17 @@ const App = () => { |
|
|
|
value={{ |
|
|
|
value={{ |
|
|
|
apiKey, |
|
|
|
apiKey, |
|
|
|
setAPIKey, |
|
|
|
setAPIKey, |
|
|
|
clientInstance, |
|
|
|
clientInstance: plugin, |
|
|
|
receipts, |
|
|
|
receipts, |
|
|
|
setReceipts, |
|
|
|
setReceipts, |
|
|
|
contracts, |
|
|
|
contracts, |
|
|
|
setContracts, |
|
|
|
setContracts, |
|
|
|
themeType, |
|
|
|
themeType, |
|
|
|
setThemeType |
|
|
|
setThemeType, |
|
|
|
|
|
|
|
networkName |
|
|
|
}} |
|
|
|
}} |
|
|
|
> |
|
|
|
> |
|
|
|
<DisplayRoutes /> |
|
|
|
{ plugin && <DisplayRoutes /> } |
|
|
|
</AppContext.Provider> |
|
|
|
</AppContext.Provider> |
|
|
|
) |
|
|
|
) |
|
|
|
} |
|
|
|
} |
|
|
|