Move network event to app root

pull/5370/head
ioedeveloper 1 year ago committed by yann300
parent a7ab49bc01
commit d6f291145c
  1. 3
      apps/etherscan/src/app/AppContext.tsx
  2. 20
      apps/etherscan/src/app/app.tsx
  3. 3
      apps/etherscan/src/app/views/HomeView.tsx
  4. 18
      apps/etherscan/src/app/views/VerifyView.tsx
  5. 2
      apps/remix-ide/src/blockchain/blockchain.tsx

@ -20,5 +20,6 @@ export const AppContext = React.createContext({
themeType: 'dark' as ThemeType, themeType: 'dark' as ThemeType,
setThemeType: (themeType: ThemeType) => { setThemeType: (themeType: ThemeType) => {
console.log('Calling Set Theme Type') console.log('Calling Set Theme Type')
} },
networkName: ''
}) })

@ -16,13 +16,12 @@ import './App.css'
export const getNewContractNames = (compilationResult: CompilationResult) => { export const getNewContractNames = (compilationResult: CompilationResult) => {
const compiledContracts = compilationResult.contracts const compiledContracts = compilationResult.contracts
const result: string[] = [] let result: string[] = []
for (const file of Object.keys(compiledContracts)) { for (const file of Object.keys(compiledContracts)) {
const filePathArray = file.split('/') const newContractNames = Object.keys(compiledContracts[file])
const newContractNames = filePathArray[filePathArray.length - 1]
result.push(newContractNames) result = [...result, ...newContractNames]
} }
return result return result
@ -32,9 +31,10 @@ const plugin = new EtherscanPluginClient()
const App = () => { const App = () => {
const [apiKey, setAPIKey] = useLocalStorage('apiKey', '') const [apiKey, setAPIKey] = useLocalStorage('apiKey', '')
const [receipts, setReceipts] = useLocalStorage('receipts', []) const [receipts, setReceipts] = useLocalStorage('receipts', [])
const [contracts, setContracts] = useState<string[]>([]) const [contracts, setContracts] = useState<string[]>([])
const [themeType, setThemeType] = useState<ThemeType>('dark') const [themeType, setThemeType] = useState<ThemeType>('dark')
const [networkName, setNetworkName] = useState('Loading...')
const timer = useRef(null) const timer = useRef(null)
const contractsRef = useRef(contracts) const contractsRef = useRef(contracts)
@ -51,6 +51,11 @@ const App = () => {
setContracts(uniqueContracts) setContracts(uniqueContracts)
}) })
plugin.on('blockchain' as any, 'networkStatus', (result) => {
setNetworkName(`${result.network.name} ${result.network.id !== '-' ? `(Chain id: ${result.network.id})` : '(Not supported)'}`)
})
// @ts-ignore
plugin.call('blockchain', 'getCurrentNetworkStatus').then((result: any) => setNetworkName(`${result.network.name} ${result.network.id !== '-' ? `(Chain id: ${result.network.id})` : '(Not supported)'}`))
}) })
}, []) }, [])
@ -114,10 +119,11 @@ const App = () => {
contracts, contracts,
setContracts, setContracts,
themeType, themeType,
setThemeType setThemeType,
networkName
}} }}
> >
<DisplayRoutes /> { plugin && <DisplayRoutes /> }
</AppContext.Provider> </AppContext.Provider>
) )
} }

@ -10,7 +10,7 @@ import {VerifyView} from './VerifyView'
export const HomeView: React.FC = () => { export const HomeView: React.FC = () => {
return ( return (
<AppContext.Consumer> <AppContext.Consumer>
{({apiKey, clientInstance, setReceipts, receipts, contracts}) => { {({apiKey, clientInstance, setReceipts, receipts, contracts, networkName}) => {
return !apiKey ? ( return !apiKey ? (
<Navigate <Navigate
to={{ to={{
@ -26,6 +26,7 @@ export const HomeView: React.FC = () => {
const newReceipts = [...receipts, receipt] const newReceipts = [...receipts, receipt]
setReceipts(newReceipts) setReceipts(newReceipts)
}} }}
networkName={networkName}
/> />
) )
}} }}

@ -14,7 +14,8 @@ interface Props {
client: PluginClient client: PluginClient
apiKey: string apiKey: string
onVerifiedContract: (receipt: Receipt) => void onVerifiedContract: (receipt: Receipt) => void
contracts: string[] contracts: string[],
networkName: string
} }
interface FormValues { interface FormValues {
@ -23,27 +24,14 @@ interface FormValues {
expectedImplAddress?: string expectedImplAddress?: string
} }
export const VerifyView: React.FC<Props> = ({apiKey, client, contracts, onVerifiedContract}) => { export const VerifyView: React.FC<Props> = ({apiKey, client, contracts, onVerifiedContract, networkName}) => {
const [results, setResults] = useState('') const [results, setResults] = useState('')
const [networkName, setNetworkName] = useState('Loading...')
const [selectedContract, setSelectedContract] = useState('') const [selectedContract, setSelectedContract] = useState('')
const [showConstructorArgs, setShowConstructorArgs] = useState(false) const [showConstructorArgs, setShowConstructorArgs] = useState(false)
const [isProxyContract, setIsProxyContract] = useState(false) const [isProxyContract, setIsProxyContract] = useState(false)
const [constructorInputs, setConstructorInputs] = useState([]) const [constructorInputs, setConstructorInputs] = useState([])
const verificationResult = useRef({}) const verificationResult = useRef({})
useEffect(() => {
if (client && client.on) {
client.on('blockchain' as any, 'networkStatus', (result) => {
setNetworkName(`${result.network.name} ${result.network.id !== '-' ? `(Chain id: ${result.network.id})` : '(Not supported)'}`)
})
}
return () => {
// To fix memory leak
if (client && client.off) client.off('blockchain' as any, 'networkStatus')
}
}, [client])
useEffect(() => { useEffect(() => {
if (contracts.includes(selectedContract)) updateConsFields(selectedContract) if (contracts.includes(selectedContract)) updateConsFields(selectedContract)
}, [contracts]) }, [contracts])

@ -23,7 +23,7 @@ const profile = {
name: 'blockchain', name: 'blockchain',
displayName: 'Blockchain', displayName: 'Blockchain',
description: 'Blockchain - Logic', description: 'Blockchain - Logic',
methods: ['getCode', 'getTransactionReceipt', 'addProvider', 'removeProvider', 'getCurrentFork', 'getAccounts', 'web3VM', 'web3', 'getProvider'], methods: ['getCode', 'getTransactionReceipt', 'addProvider', 'removeProvider', 'getCurrentFork', 'getAccounts', 'web3VM', 'web3', 'getProvider', 'getCurrentNetworkStatus'],
version: packageJson.version version: packageJson.version
} }

Loading…
Cancel
Save