Skip to content

Commit

Permalink
fix: debouncing should work from the first value
Browse files Browse the repository at this point in the history
  • Loading branch information
chybisov committed Sep 28, 2022
1 parent 25225fd commit e288dcf
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 6 deletions.
2 changes: 1 addition & 1 deletion packages/widget/src/components/TokenList/TokenList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export const TokenList: FC<TokenListProps> = ({
});
const [tokenSearchFilter]: string[] = useDebouncedWatch(
[SwapFormKey.TokenSearchFilter],
250,
320,
);

const {
Expand Down
5 changes: 1 addition & 4 deletions packages/widget/src/hooks/useDebouncedWatch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,7 @@ export const useDebouncedWatch = (name: any, delay: number) => {
const hasWatchedValue = Array.isArray(watchedValue)
? watchedValue.some((value) => value)
: Boolean(watchedValue);
const hasDebouncedValue = Array.isArray(debouncedValueRef.current)
? debouncedValueRef.current.some((value) => value)
: Boolean(debouncedValueRef.current);
if (hasWatchedValue && hasDebouncedValue) {
if (hasWatchedValue) {
const handler = setTimeout(() => {
setDebouncedValue(watchedValue);
}, delay);
Expand Down
2 changes: 1 addition & 1 deletion packages/widget/src/hooks/useSwapRoutes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export const useSwapRoutes = () => {
SwapFormKey.ToAddress,
],
});
const [fromTokenAmount] = useDebouncedWatch([SwapFormKey.FromAmount], 250);
const [fromTokenAmount] = useDebouncedWatch([SwapFormKey.FromAmount], 320);
const { token } = useToken(fromChainId, fromTokenAddress);
const isEnabled =
// Boolean(account.address) &&
Expand Down

0 comments on commit e288dcf

Please sign in to comment.