Skip to content

Commit

Permalink
fix: disable selection of the same tokens
Browse files Browse the repository at this point in the history
  • Loading branch information
chybisov committed Jun 7, 2022
1 parent 70a1691 commit 9fb33e9
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions packages/widget/src/components/TokenList/TokenList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export const TokenList: FC<TokenListProps> = ({
}) => {
const { t } = useTranslation();
const { account } = useWallet();
const { setValue } = useFormContext();
const { setValue, getValues } = useFormContext();
const [selectedChainId] = useWatch({
name: [SwapFormKeyHelper.getChainKey(formType)],
});
Expand All @@ -30,7 +30,7 @@ export const TokenList: FC<TokenListProps> = ({
250,
);

const { tokens, isLoading, isFetching } = useTokenBalances(selectedChainId);
const { tokens, isLoading } = useTokenBalances(selectedChainId);

const chainTokens = useMemo(() => {
let chainTokens = tokens ?? [];
Expand Down Expand Up @@ -67,9 +67,16 @@ export const TokenList: FC<TokenListProps> = ({
(tokenAddress: string) => {
setValue(SwapFormKeyHelper.getTokenKey(formType), tokenAddress);
setValue(SwapFormKeyHelper.getAmountKey(formType), '');
const oppositeFormType = formType === 'from' ? 'to' : 'from';
const [selectedOppositeToken] = getValues([
SwapFormKeyHelper.getTokenKey(oppositeFormType),
]);
if (selectedOppositeToken === tokenAddress) {
setValue(SwapFormKeyHelper.getTokenKey(oppositeFormType), '');
}
onClick?.();
},
[formType, onClick, setValue],
[formType, getValues, onClick, setValue],
);

return (
Expand Down

0 comments on commit 9fb33e9

Please sign in to comment.