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" ;
211import { CURRENCIES , type CurrencyMetadata } from "constants/currencies" ;
312import { useMemo , useState } from "react" ;
413import { NATIVE_TOKEN_ADDRESS , ZERO_ADDRESS , isAddress } from "thirdweb" ;
5- import { Button } from "tw-components" ;
614import { useAllChainsData } from "../../hooks/chains/allChains" ;
715
8- interface CurrencySelectorProps extends SelectProps {
16+ interface CurrencySelectorProps {
917 value : string ;
18+ onChange ?: ( event : React . ChangeEvent < HTMLSelectElement > ) => void ;
19+ className ?: string ;
20+ isDisabled ?: boolean ;
1021 small ?: boolean ;
1122 hideDefaultCurrencies ?: boolean ;
1223 showCustomCurrency ?: boolean ;
@@ -15,7 +26,7 @@ interface CurrencySelectorProps extends SelectProps {
1526 contractChainId : number ;
1627}
1728
18- export const CurrencySelector : React . FC < CurrencySelectorProps > = ( {
29+ export function CurrencySelector ( {
1930 value,
2031 onChange,
2132 small,
@@ -24,8 +35,9 @@ export const CurrencySelector: React.FC<CurrencySelectorProps> = ({
2435 isPaymentsSelector = false ,
2536 defaultCurrencies = [ ] ,
2637 contractChainId : chainId ,
27- ...props
28- } ) => {
38+ className,
39+ isDisabled,
40+ } : CurrencySelectorProps ) {
2941 const { idToChain } = useAllChainsData ( ) ;
3042 const chain = chainId ? idToChain . get ( chainId ) : undefined ;
3143
@@ -92,87 +104,96 @@ export const CurrencySelector: React.FC<CurrencySelectorProps> = ({
92104
93105 if ( isAddingCurrency && ! hideDefaultCurrencies ) {
94106 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 >
121128 </ div >
122129 ) ;
123130 }
124131
125132 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+ >
127140 < Select
128- position = "relative"
141+ disabled = { isDisabled }
129142 value = {
130143 isPaymentsSelector
131144 ? value
132145 : value ?. toLowerCase ( ) === ZERO_ADDRESS . toLowerCase ( )
133146 ? NATIVE_TOKEN_ADDRESS . toLowerCase ( )
134147 : value ?. toLowerCase ( )
135148 }
136- onChange = { ( e ) => {
137- if ( e . target . value === "custom" ) {
149+ onValueChange = { ( val ) => {
150+ if ( val === "custom" ) {
138151 setIsAddingCurrency ( true ) ;
139152 } else {
140- onChange ?.( e ) ;
153+ onChange ?.( {
154+ target : { value : val } ,
155+ } as React . ChangeEvent < HTMLSelectElement > ) ;
141156 }
142157 } }
143- placeholder = "Select Currency"
144- { ...props }
145158 >
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 ( ) }
156188 >
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 >
166191 ) }
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 >
175196 </ Select >
176- </ Flex >
197+ </ div >
177198 ) ;
178- } ;
199+ }
0 commit comments