Skip to content

Commit 39ffcb5

Browse files
committed
Add Verify form items. Fetch and format chains form chainid.network/chains.json
1 parent 6b2d612 commit 39ffcb5

File tree

5 files changed

+89
-7
lines changed

5 files changed

+89
-7
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,5 @@ export const AppContext = React.createContext({
66
setThemeType: (themeType: ThemeType) => {
77
console.log('Calling Set Theme Type')
88
},
9+
chains: [],
910
})

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

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,18 @@ const plugin = new ContractVerificationPluginClient()
1313

1414
const App = () => {
1515
const [themeType, setThemeType] = useState<ThemeType>('dark')
16+
const [chains, setChains] = useState([]) // State to hold the chains data
17+
18+
useEffect(() => {
19+
// Fetch chains.json and update state
20+
fetch('https://chainid.network/chains.json')
21+
.then((response) => response.json())
22+
.then((data) => setChains(data))
23+
.catch((error) => console.error('Failed to fetch chains.json:', error))
24+
}, [])
1625

1726
return (
18-
<AppContext.Provider value={{themeType, setThemeType}}>
27+
<AppContext.Provider value={{themeType, setThemeType, chains}}>
1928
<DisplayRoutes />
2029
</AppContext.Provider>
2130
)
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import React from 'react'
2+
3+
interface DropdownItem {
4+
value: string
5+
text: string
6+
}
7+
8+
interface DropdownProps {
9+
label: string
10+
items: DropdownItem[]
11+
id: string
12+
}
13+
14+
export const Dropdown: React.FC<DropdownProps> = ({label, items, id}) => {
15+
return (
16+
<div className="form-group">
17+
<label htmlFor={id}>{label}</label>
18+
<select className="form-control custom-select pr-4" id={id}>
19+
{items.map((item, index) => (
20+
<option value={item.value} key={index}>
21+
{item.text}
22+
</option>
23+
))}
24+
</select>
25+
</div>
26+
)
27+
}

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,10 @@ const NavItem = ({to, icon, title}: NavItemProps) => {
1313
<NavLink
1414
// data-id="home"
1515
to={to}
16-
className={({isActive}) => (isActive ? 'border border-secondary shadow-none btn p-1 m-0' : 'border-0 shadow-none btn p-1 m-0')}
17-
style={({isActive}) => (!isActive ? {width: '1.8rem', filter: 'contrast(0.5)'} : {width: '1.8rem'})}
16+
className={({isActive}) => 'p-2 ' + (isActive ? 'bg-primary text-white' : 'bg-secondary')}
1817
// state={from}
1918
>
20-
<div>
19+
<div className="d-flex flex-column align-items-center justify-content-center">
2120
<div>{icon}</div>
2221
<div>{title}</div>
2322
</div>
@@ -27,7 +26,7 @@ const NavItem = ({to, icon, title}: NavItemProps) => {
2726

2827
export const NavMenu = () => {
2928
return (
30-
<nav className="d-flex flex-row justify-content-between">
29+
<nav className="d-flex flex-row justify-content-around">
3130
<NavItem to="/" icon={<i className="fas fa-home"></i>} title="Verify" />
3231
<NavItem to="/receipts" icon={<i className="fas fa-receipt"></i>} title="Receipts" />
3332
<NavItem to="/lookup" icon={<i className="fas fa-search"></i>} title="Lookup" />
Lines changed: 48 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,55 @@
11
import React from 'react'
22

33
import {AppContext} from '../AppContext'
4+
import {Dropdown} from '../components/Input/Dropdown'
45

56
export const HomeView = () => {
6-
const context = React.useContext(AppContext)
7+
const {chains} = React.useContext(AppContext)
78

8-
return <div>HOME</div>
9+
const ethereumChainIds = [1, 11155111, 17000]
10+
11+
// Add Ethereum chains to the head of the chains list. Sort the rest alphabetically
12+
const dropdownChains = chains
13+
.map((chain) => ({value: chain.chainId, text: `${chain.name} (${chain.chainId})`}))
14+
.sort((a, b) => {
15+
const isAInEthereum = ethereumChainIds.includes(a.value)
16+
const isBInEthereum = ethereumChainIds.includes(b.value)
17+
18+
if (isAInEthereum && !isBInEthereum) return -1
19+
if (!isAInEthereum && isBInEthereum) return 1
20+
if (isAInEthereum && isBInEthereum) return ethereumChainIds.indexOf(a.value) - ethereumChainIds.indexOf(b.value)
21+
22+
return a.text.localeCompare(b.text)
23+
})
24+
25+
return (
26+
<div className="my-4">
27+
<div>
28+
<h2 className="text-center text-uppercase font-weight-bold">Verify</h2>
29+
<p className="text-center" style={{fontSize: '0.8rem'}}>
30+
Verify compiled contracts on different verification services
31+
</p>
32+
</div>
33+
<div>
34+
<Dropdown label="Network" items={dropdownChains} id="network-dropdown" />
35+
<div className="form-group">
36+
<label htmlFor="contract-address">Contract Address</label>
37+
<input type="text" className="form-control" id="contract-address" placeholder="0x2738d13E81e..." />
38+
</div>
39+
<Dropdown
40+
label="Contract Name"
41+
items={[
42+
{value: 'ERC20', text: 'ERC20'},
43+
{value: 'ERC721', text: 'ERC721'},
44+
{value: 'ERC1155', text: 'ERC1155'},
45+
]}
46+
id="contract-name-dropdown"
47+
/>
48+
<div>
49+
<div>Constructor Arguments</div>
50+
{/* TODO: Add input fields for constructor arguments */}
51+
</div>
52+
</div>
53+
</div>
54+
)
955
}

0 commit comments

Comments
 (0)