1
- import { Flex , Input , Select , type SelectProps } from "@chakra-ui/react" ;
1
+ import { Button } from "@/components/ui/button" ;
2
+ import { Input } from "@/components/ui/input" ;
3
+ import {
4
+ Select ,
5
+ SelectContent ,
6
+ SelectItem ,
7
+ SelectTrigger ,
8
+ SelectValue ,
9
+ } from "@/components/ui/select" ;
10
+ import { cn } from "@/lib/utils" ;
2
11
import { CURRENCIES , type CurrencyMetadata } from "constants/currencies" ;
3
12
import { useMemo , useState } from "react" ;
4
13
import { NATIVE_TOKEN_ADDRESS , ZERO_ADDRESS , isAddress } from "thirdweb" ;
5
- import { Button } from "tw-components" ;
6
14
import { useAllChainsData } from "../../hooks/chains/allChains" ;
7
15
8
- interface CurrencySelectorProps extends SelectProps {
16
+ interface CurrencySelectorProps {
9
17
value : string ;
18
+ onChange ?: ( event : React . ChangeEvent < HTMLSelectElement > ) => void ;
19
+ className ?: string ;
20
+ isDisabled ?: boolean ;
10
21
small ?: boolean ;
11
22
hideDefaultCurrencies ?: boolean ;
12
23
showCustomCurrency ?: boolean ;
@@ -15,7 +26,7 @@ interface CurrencySelectorProps extends SelectProps {
15
26
contractChainId : number ;
16
27
}
17
28
18
- export const CurrencySelector : React . FC < CurrencySelectorProps > = ( {
29
+ export function CurrencySelector ( {
19
30
value,
20
31
onChange,
21
32
small,
@@ -24,8 +35,9 @@ export const CurrencySelector: React.FC<CurrencySelectorProps> = ({
24
35
isPaymentsSelector = false ,
25
36
defaultCurrencies = [ ] ,
26
37
contractChainId : chainId ,
27
- ...props
28
- } ) => {
38
+ className,
39
+ isDisabled,
40
+ } : CurrencySelectorProps ) {
29
41
const { idToChain } = useAllChainsData ( ) ;
30
42
const chain = chainId ? idToChain . get ( chainId ) : undefined ;
31
43
@@ -92,87 +104,96 @@ export const CurrencySelector: React.FC<CurrencySelectorProps> = ({
92
104
93
105
if ( isAddingCurrency && ! hideDefaultCurrencies ) {
94
106
return (
95
- < div className = "flex flex-col" >
96
- < Flex align = "center" >
97
- < Button
98
- borderRadius = "4px 0px 0px 4px"
99
- colorScheme = "primary"
100
- onClick = { ( ) => setIsAddingCurrency ( false ) }
101
- >
102
- <-
103
- </ Button >
104
- < Input
105
- w = "auto"
106
- isRequired
107
- placeholder = "ERC20 Address"
108
- borderRadius = "none"
109
- value = { editCustomCurrency }
110
- onChange = { ( e ) => setEditCustomCurrency ( e . target . value ) }
111
- />
112
- < Button
113
- borderRadius = "0px 4px 4px 0px"
114
- colorScheme = "primary"
115
- onClick = { addCustomCurrency }
116
- isDisabled = { ! isAddress ( editCustomCurrency ) }
117
- >
118
- Save
119
- </ Button >
120
- </ Flex >
107
+ < div className = "flex items-center" >
108
+ < Button
109
+ className = "rounded-r-none rounded-l-md"
110
+ onClick = { ( ) => setIsAddingCurrency ( false ) }
111
+ >
112
+ <-
113
+ </ Button >
114
+ < Input
115
+ className = "w-full rounded-none"
116
+ required
117
+ placeholder = "ERC20 Address"
118
+ value = { editCustomCurrency }
119
+ onChange = { ( e ) => setEditCustomCurrency ( e . target . value ) }
120
+ />
121
+ < Button
122
+ className = "rounded-r-md rounded-l-none"
123
+ onClick = { addCustomCurrency }
124
+ disabled = { ! isAddress ( editCustomCurrency ) }
125
+ >
126
+ Save
127
+ </ Button >
121
128
</ div >
122
129
) ;
123
130
}
124
131
125
132
return (
126
- < Flex direction = "column" mt = { small && ! hideDefaultCurrencies ? 5 : 0 } >
133
+ < div
134
+ className = { cn (
135
+ "flex flex-col" ,
136
+ small && ! hideDefaultCurrencies && "mt-5" ,
137
+ className ,
138
+ ) }
139
+ >
127
140
< Select
128
- position = "relative"
141
+ disabled = { isDisabled }
129
142
value = {
130
143
isPaymentsSelector
131
144
? value
132
145
: value ?. toLowerCase ( ) === ZERO_ADDRESS . toLowerCase ( )
133
146
? NATIVE_TOKEN_ADDRESS . toLowerCase ( )
134
147
: value ?. toLowerCase ( )
135
148
}
136
- onChange = { ( e ) => {
137
- if ( e . target . value === "custom" ) {
149
+ onValueChange = { ( val ) => {
150
+ if ( val === "custom" ) {
138
151
setIsAddingCurrency ( true ) ;
139
152
} else {
140
- onChange ?.( e ) ;
153
+ onChange ?.( {
154
+ target : { value : val } ,
155
+ } as React . ChangeEvent < HTMLSelectElement > ) ;
141
156
}
142
157
} }
143
- placeholder = "Select Currency"
144
- { ...props }
145
158
>
146
- { chainId &&
147
- ! hideDefaultCurrencies &&
148
- currencyOptions . map ( ( currency : CurrencyMetadata , idx : number ) => (
149
- < option
150
- key = { `${ currency . address } -${ idx } ` }
151
- value = {
152
- isPaymentsSelector
153
- ? currency . symbol
154
- : currency . address . toLowerCase ( )
155
- }
159
+ < SelectTrigger >
160
+ < SelectValue placeholder = "Select Currency" />
161
+ </ SelectTrigger >
162
+ < SelectContent >
163
+ { chainId &&
164
+ ! hideDefaultCurrencies &&
165
+ currencyOptions . map ( ( currency : CurrencyMetadata , idx : number ) => (
166
+ < SelectItem
167
+ key = { `${ currency . address } -${ idx } ` }
168
+ value = {
169
+ isPaymentsSelector
170
+ ? currency . symbol
171
+ : currency . address . toLowerCase ( )
172
+ }
173
+ >
174
+ { currency . symbol } ({ currency . name } )
175
+ </ SelectItem >
176
+ ) ) }
177
+ { isCustomCurrency &&
178
+ ! isPaymentsSelector &&
179
+ initialValue !== NATIVE_TOKEN_ADDRESS . toLowerCase ( ) && (
180
+ < SelectItem key = { initialValue } value = { initialValue } >
181
+ { initialValue }
182
+ </ SelectItem >
183
+ ) }
184
+ { customCurrency && (
185
+ < SelectItem
186
+ key = { customCurrency }
187
+ value = { customCurrency . toLowerCase ( ) }
156
188
>
157
- { currency . symbol } ({ currency . name } )
158
- </ option >
159
- ) ) }
160
- { isCustomCurrency &&
161
- ! isPaymentsSelector &&
162
- initialValue !== NATIVE_TOKEN_ADDRESS . toLowerCase ( ) && (
163
- < option key = { initialValue } value = { initialValue } >
164
- { initialValue }
165
- </ option >
189
+ { customCurrency }
190
+ </ SelectItem >
166
191
) }
167
- { customCurrency && (
168
- < option key = { customCurrency } value = { customCurrency . toLowerCase ( ) } >
169
- { customCurrency }
170
- </ option >
171
- ) }
172
- { ! hideDefaultCurrencies && showCustomCurrency && (
173
- < option value = "custom" > Custom ERC20</ option >
174
- ) }
192
+ { ! hideDefaultCurrencies && showCustomCurrency && (
193
+ < SelectItem value = "custom" > Custom ERC20</ SelectItem >
194
+ ) }
195
+ </ SelectContent >
175
196
</ Select >
176
- </ Flex >
197
+ </ div >
177
198
) ;
178
- } ;
199
+ }
0 commit comments