Skip to content

Commit 5346453

Browse files
committed
Fix types for contract-verification-plugin
1 parent 419f6e8 commit 5346453

File tree

4 files changed

+31
-13
lines changed

4 files changed

+31
-13
lines changed
Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,28 @@
11
import React from 'react'
22
import {ThemeType} from './types'
3+
import {CompilationResult} from '@remixproject/plugin-api'
34

4-
export const AppContext = React.createContext({
5-
themeType: 'dark' as ThemeType,
5+
// Define the type for the context
6+
type AppContextType = {
7+
themeType: ThemeType
8+
setThemeType: (themeType: ThemeType) => void
9+
chains: any[]
10+
selectedChain: any | undefined
11+
setSelectedChain: (chain: string) => void
12+
compilationOutput: CompilationResult | undefined
13+
}
14+
15+
// Provide a default value with the appropriate types
16+
const defaultContextValue: AppContextType = {
17+
themeType: 'dark',
618
setThemeType: (themeType: ThemeType) => {
719
console.log('Calling Set Theme Type')
820
},
921
chains: [],
10-
selectedChain: null,
22+
selectedChain: undefined,
1123
setSelectedChain: (chain: string) => {},
12-
contractNames: [],
13-
})
24+
compilationOutput: undefined,
25+
}
26+
27+
// Create the context with the type
28+
export const AppContext = React.createContext<AppContextType>(defaultContextValue)

apps/contract-verification/src/app/app.tsx

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,11 @@ const plugin = new ContractVerificationPluginClient()
1414

1515
const App = () => {
1616
const [themeType, setThemeType] = useState<ThemeType>('dark')
17-
const [chains, setChains] = useState([]) // State to hold the chains data
18-
const [selectedChain, setSelectedChain] = useState(null)
17+
// TODO: Types for chains
18+
const [chains, setChains] = useState<any>([]) // State to hold the chains data
19+
const [selectedChain, setSelectedChain] = useState<any | undefined>()
1920
const [targetFileName, setTargetFileName] = useState('')
20-
const [contractNames, setContractNames] = useState([])
21+
const [compilationOutput, setCompilationOutput] = useState<CompilationResult | undefined>()
2122

2223
useEffect(() => {
2324
// TODO: Fix 'compilationFinished' event types. The interface is outdated at https://github.com/ethereum/remix-plugin/blob/master/packages/api/src/lib/compiler/api.ts. It does not include data, input, or version. See the current parameters: https://github.com/ethereum/remix-project/blob/9f6c5be882453a555055f07171701459e4ae88a4/libs/remix-solidity/src/compiler/compiler.ts#L189
@@ -36,7 +37,7 @@ const App = () => {
3637
console.log(Object.keys(data.contracts[fileName]))
3738

3839
setTargetFileName(fileName)
39-
setContractNames(Object.keys(data.contracts[fileName]))
40+
setCompilationOutput(undefined)
4041
})
4142
// Fetch chains.json and update state
4243
fetch('https://chainid.network/chains.json')
@@ -50,7 +51,7 @@ const App = () => {
5051
}, [])
5152

5253
return (
53-
<AppContext.Provider value={{themeType, setThemeType, chains, selectedChain, setSelectedChain, contractNames}}>
54+
<AppContext.Provider value={{themeType, setThemeType, chains, selectedChain, setSelectedChain, compilationOutput}}>
5455
<DisplayRoutes />
5556
</AppContext.Provider>
5657
)

apps/contract-verification/src/app/layouts/Default.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ interface Props {
77
title?: string
88
}
99

10-
export const DefaultLayout = ({children, from, title}) => {
10+
export const DefaultLayout = ({children}: PropsWithChildren<Props>) => {
1111
return (
1212
<div>
1313
<NavMenu />

apps/contract-verification/src/app/views/HomeView.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,12 @@ import {Dropdown} from '../components'
55
import {SearchableDropdown} from '../components'
66

77
export const HomeView = () => {
8-
const {chains, selectedChain, setSelectedChain, contractNames} = React.useContext(AppContext)
8+
const {chains, selectedChain, setSelectedChain, compilationOutput} = React.useContext(AppContext)
99

1010
const ethereumChainIds = [1, 3, 4, 5, 11155111, 17000]
1111

12+
const contractNames = compilationOutput?.contracts && Object.keys(compilationOutput?.contracts)
13+
1214
// Add Ethereum chains to the head of the chains list. Sort the rest alphabetically
1315
const dropdownChains = chains
1416
.map((chain) => ({value: chain.chainId, name: `${chain.title || chain.name} (${chain.chainId})`}))
@@ -39,7 +41,7 @@ export const HomeView = () => {
3941
<input type="text" className="form-control" id="contract-address" placeholder="0x2738d13E81e..." />
4042
</div>
4143

42-
{contractNames.length > 0 ? <Dropdown label="Contract Name" items={contractNames.map((item) => ({value: item, name: item}))} id="contract-name-dropdown" /> : <div> No compiled contracts </div>}
44+
{contractNames && contractNames.length > 0 ? <Dropdown label="Contract Name" items={contractNames.map((item) => ({value: item, name: item}))} id="contract-name-dropdown" /> : <div> No compiled contracts </div>}
4345
<div>
4446
<div>Constructor Arguments</div>
4547
{/* TODO: Add input fields for constructor arguments */}

0 commit comments

Comments
 (0)