From f4b8d07ec4c6bafd710ed027bd66bfa9fa3a7a8f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rui=20Sim=C3=A3o?= Date: Tue, 7 May 2024 10:18:09 +0100 Subject: [PATCH] fix(components): token input items --- .../components/src/TokenInput/TokenInput.tsx | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/packages/components/src/TokenInput/TokenInput.tsx b/packages/components/src/TokenInput/TokenInput.tsx index e07a382ca..288b3cb46 100644 --- a/packages/components/src/TokenInput/TokenInput.tsx +++ b/packages/components/src/TokenInput/TokenInput.tsx @@ -36,13 +36,26 @@ const TokenInput = forwardRef((props, ref): J const inputRef = useDOMRef(ref); - const defaultCurrency = useMemo(() => getDefaultCurrency(props), []); - const [value, setValue] = useState(defaultValue); + + const defaultCurrency = useMemo(() => getDefaultCurrency(props), []); const [currency, setCurrency] = useState(defaultCurrency); const inputId = useId(); + useEffect( + () => { + if (props.type === 'selectable') { + setCurrency( + (props.items || []).find( + (item) => item.currency.symbol === (props.selectProps?.value || props.selectProps?.defaultValue) + )?.currency + ); + } + }, + props.type === 'selectable' ? [props.items] : [] + ); + useEffect(() => { if (valueProp === undefined) return;