11import { useDOMRef } from '@interlay/hooks' ;
22import { mergeProps , useId } from '@react-aria/utils' ;
3- import { ChangeEvent , FocusEvent , forwardRef , useCallback , useEffect , useState } from 'react' ;
3+ import { ChangeEvent , FocusEvent , forwardRef , useCallback , useEffect , useMemo , useState } from 'react' ;
44
55import { trimDecimals } from '../utils' ;
66
@@ -13,7 +13,9 @@ const getDefaultCurrency = (props: TokenInputProps) => {
1313 case 'fixed' :
1414 return ( props as FixedTokenInputProps ) . currency ;
1515 case 'selectable' :
16- return ( props . items || [ ] ) . find ( ( item ) => item . currency . symbol === props . selectProps ?. defaultValue ) ;
16+ return ( props . items || [ ] ) . find (
17+ ( item ) => item . currency . symbol === ( props . selectProps ?. value || props . selectProps ?. defaultValue )
18+ ) ?. currency ;
1719 }
1820} ;
1921
@@ -34,8 +36,10 @@ const TokenInput = forwardRef<HTMLInputElement, TokenInputProps>((props, ref): J
3436
3537 const inputRef = useDOMRef < HTMLInputElement > ( ref ) ;
3638
39+ const defaultCurrency = useMemo ( ( ) => getDefaultCurrency ( props ) , [ ] ) ;
40+
3741 const [ value , setValue ] = useState ( defaultValue ) ;
38- const [ currency , setCurrency ] = useState < any | undefined > ( getDefaultCurrency ( props ) ) ;
42+ const [ currency , setCurrency ] = useState < any | undefined > ( defaultCurrency ) ;
3943
4044 const inputId = useId ( ) ;
4145
@@ -119,9 +123,8 @@ const TokenInput = forwardRef<HTMLInputElement, TokenInputProps>((props, ref): J
119123 if ( props . type === 'selectable' ) {
120124 return (
121125 < SelectableTokenInput
122- { ...mergeProps ( otherProps , commonProps ) }
126+ { ...mergeProps ( otherProps , commonProps , { onChangeCurrency : handleChangeCurrency } ) }
123127 currency = { currency }
124- onChangeCurrency = { handleChangeCurrency }
125128 />
126129 ) ;
127130 }
0 commit comments