Skip to content

Commit

Permalink
fix(components): token input items
Browse files Browse the repository at this point in the history
  • Loading branch information
danielsimao committed May 7, 2024
1 parent 4664ef9 commit 5214b0d
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions packages/components/src/TokenInput/TokenInput.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useDOMRef } from '@interlay/hooks';
import { mergeProps, useId } from '@react-aria/utils';
import { ChangeEvent, FocusEvent, forwardRef, useCallback, useEffect, useState } from 'react';
import { ChangeEvent, FocusEvent, forwardRef, useCallback, useEffect, useMemo, useState } from 'react';

import { trimDecimals } from '../utils';

Expand Down Expand Up @@ -35,10 +35,25 @@ const TokenInput = forwardRef<HTMLInputElement, TokenInputProps>((props, ref): J
const inputRef = useDOMRef<HTMLInputElement>(ref);

const [value, setValue] = useState(defaultValue);
const [currency, setCurrency] = useState<any | undefined>(getDefaultCurrency(props));

const defaultCurrency = useMemo(() => getDefaultCurrency(props), []);
const [currency, setCurrency] = useState<any | undefined>(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;

Expand Down

0 comments on commit 5214b0d

Please sign in to comment.