Skip to content

Commit 4d84d8b

Browse files
committed
Basic select compiled contract name
1 parent c203967 commit 4d84d8b

File tree

3 files changed

+29
-11
lines changed

3 files changed

+29
-11
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,5 @@ export const AppContext = React.createContext({
99
chains: [],
1010
selectedChain: null,
1111
setSelectedChain: (chain: string) => {},
12+
contractNames: [],
1213
})

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

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,24 +8,49 @@ import {CustomTooltip} from '@remix-ui/helper'
88
import {ThemeType} from './types'
99

1010
import './App.css'
11+
import {CompilationFileSources, CompilationResult} from '@remixproject/plugin-api'
1112

1213
const plugin = new ContractVerificationPluginClient()
1314

1415
const App = () => {
1516
const [themeType, setThemeType] = useState<ThemeType>('dark')
1617
const [chains, setChains] = useState([]) // State to hold the chains data
1718
const [selectedChain, setSelectedChain] = useState(null)
19+
const [targetFileName, setTargetFileName] = useState('')
20+
const [contractNames, setContractNames] = useState([])
1821

1922
useEffect(() => {
23+
// 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
24+
// Because of this reason we use @ts-expect-error for the next line
25+
// @ts-expect-error:next-line
26+
plugin.on('solidity', 'compilationFinished', (fileName: string, source: CompilationFileSources, languageVersion: string, data: CompilationResult, input: string, version: string) => {
27+
console.log('Compilation output')
28+
console.log(data)
29+
console.log('File Name:', fileName)
30+
console.log('Source:', source)
31+
console.log('Language Version:', languageVersion)
32+
console.log('Compilation Result:', data)
33+
// console.log('Input:', input)
34+
console.log('Compiler Version:', version)
35+
console.log('contractNames')
36+
console.log(Object.keys(data.contracts[fileName]))
37+
38+
setTargetFileName(fileName)
39+
setContractNames(Object.keys(data.contracts[fileName]))
40+
})
2041
// Fetch chains.json and update state
2142
fetch('https://chainid.network/chains.json')
2243
.then((response) => response.json())
2344
.then((data) => setChains(data))
2445
.catch((error) => console.error('Failed to fetch chains.json:', error))
46+
47+
return () => {
48+
plugin.off('solidity', 'compilationFinished') // Clean up on unmount
49+
}
2550
}, [])
2651

2752
return (
28-
<AppContext.Provider value={{themeType, setThemeType, chains, selectedChain, setSelectedChain}}>
53+
<AppContext.Provider value={{themeType, setThemeType, chains, selectedChain, setSelectedChain, contractNames}}>
2954
<DisplayRoutes />
3055
</AppContext.Provider>
3156
)

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

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

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

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

@@ -39,15 +39,7 @@ export const HomeView = () => {
3939
<input type="text" className="form-control" id="contract-address" placeholder="0x2738d13E81e..." />
4040
</div>
4141

42-
<Dropdown
43-
label="Contract Name"
44-
items={[
45-
{value: 'ERC20', name: 'ERC20'},
46-
{value: 'ERC721', name: 'ERC721'},
47-
{value: 'ERC1155', name: 'ERC1155'},
48-
]}
49-
id="contract-name-dropdown"
50-
/>
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>}
5143
<div>
5244
<div>Constructor Arguments</div>
5345
{/* TODO: Add input fields for constructor arguments */}

0 commit comments

Comments
 (0)