Skip to content

Commit 56b27c1

Browse files
joeizangAniket-Engg
authored andcommitted
fix contract verification dropdown
1 parent ffa6423 commit 56b27c1

File tree

1 file changed

+51
-24
lines changed

1 file changed

+51
-24
lines changed

Diff for: apps/contract-verification/src/app/components/SearchableChainDropdown.tsx

+51-24
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
import React, { useState, useEffect, useRef, useMemo } from 'react'
1+
import React, { useState, useEffect, useRef, useMemo, Ref } from 'react'
22
import Fuse from 'fuse.js'
33
import type { Chain } from '../types'
44
import { AppContext } from '../AppContext'
5-
import { useIntl } from 'react-intl'
5+
import intl, { useIntl } from 'react-intl'
6+
import { Dropdown } from 'react-bootstrap'
67

78
function getChainDescriptor(chain: Chain): string {
89
if (!chain) return ''
@@ -16,6 +17,44 @@ interface DropdownProps {
1617
selectedChain: Chain
1718
}
1819

20+
export const CustomToggle = React.forwardRef(
21+
(
22+
{
23+
children,
24+
onClick,
25+
icon,
26+
className = ''
27+
}: {
28+
children: React.ReactNode
29+
onClick: (e) => void
30+
icon: string
31+
className: string
32+
},
33+
ref: Ref<HTMLButtonElement>
34+
) => (
35+
<button
36+
ref={ref}
37+
onClick={(e) => {
38+
e.preventDefault()
39+
onClick(e)
40+
}}
41+
className={className.replace('dropdown-toggle', '')}
42+
>
43+
<div className="d-flex">
44+
<div className="mr-auto text-nowrap text-truncate overflow-hidden" data-id={`dropdown-content`}>{children}</div>
45+
{icon && (
46+
<div className="pr-1">
47+
<i className={`${icon} pr-1`}></i>
48+
</div>
49+
)}
50+
<div>
51+
<i className="fad fa-sort-circle"></i>
52+
</div>
53+
</div>
54+
</button>
55+
)
56+
)
57+
1958
export const SearchableChainDropdown: React.FC<DropdownProps> = ({ label, id, setSelectedChain, selectedChain }) => {
2059
const { chains } = React.useContext(AppContext)
2160
const ethereumChainIds = [1, 11155111, 17000]
@@ -88,32 +127,20 @@ export const SearchableChainDropdown: React.FC<DropdownProps> = ({ label, id, se
88127
}
89128

90129
return (
91-
<div className="dropdown mb-3" ref={dropdownRef}>
92-
{' '}
93-
{/* Add ref here */}
94-
<label htmlFor={id}>{label}</label>
95-
<input
96-
type="text"
97-
value={searchTerm}
98-
onChange={handleInputChange}
99-
onClick={openDropdown}
100-
data-id="chainDropdownbox"
101-
placeholder={intl.formatMessage({ id: "contract-verification.searchableChainDropdown", defaultMessage: "Select a chain" })}
102-
className="form-control"
103-
/>
104-
<ul className="dropdown-menu show w-100" style={{ maxHeight: '400px', overflowY: 'auto', display: isOpen ? 'initial' : 'none' }}>
130+
<Dropdown>
131+
<Dropdown.Toggle as={CustomToggle} icon={null} className="btn btn-light btn-block w-100 d-inline-block form-control" data-id="chainDropdownbox">
132+
{searchTerm.length > 0 ? searchTerm : intl.formatMessage({ id: "contract-verification.searchableChainDropdown", defaultMessage: "Select a chain" })}
133+
</Dropdown.Toggle>
134+
<Dropdown.Menu className="w-100 custom-dropdown-items border bg-light">
105135
{filteredOptions.map((chain) => (
106-
<li
107-
key={chain.chainId}
108-
onClick={() => handleOptionClick(chain)}
136+
<Dropdown.Item key={chain.chainId} onClick={() => handleOptionClick(chain)}
137+
className={`${getChainDescriptor(chain).length > 30 ? 'text-truncate text-decoration-none' : 'text-decoration-none'}`}
109138
data-id={chain.chainId}
110-
className={`dropdown-item ${selectedChain?.chainId === chain.chainId ? 'active' : ''}`}
111-
style={{ cursor: 'pointer', whiteSpace: 'normal' }}
112139
>
113140
{getChainDescriptor(chain)}
114-
</li>
141+
</Dropdown.Item>
115142
))}
116-
</ul>
117-
</div>
143+
</Dropdown.Menu>
144+
</Dropdown>
118145
)
119146
}

0 commit comments

Comments
 (0)