Skip to content

Commit

Permalink
fix: disable route cards if form is not valid
Browse files Browse the repository at this point in the history
  • Loading branch information
chybisov committed Sep 23, 2022
1 parent a1bded4 commit 7165164
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions packages/widget/src/components/SwapRoutes/SwapRoutesExpanded.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/* eslint-disable react/no-array-index-key */
import type { Route } from '@lifi/sdk';
import { Collapse, Grow, Stack, Typography } from '@mui/material';
import { useFormState } from 'react-hook-form';
import { useTranslation } from 'react-i18next';
import { useLocation, useNavigate } from 'react-router-dom';
import { useSwapRoutes } from '../../hooks';
Expand Down Expand Up @@ -33,7 +34,7 @@ export const SwapRoutesExpanded = () => {
refetchTime,
refetch,
} = useSwapRoutes();

const { isValid, isValidating } = useFormState();
const setExecutableRoute = useSetExecutableRoute();

const { pathname } = useLocation();
Expand All @@ -44,10 +45,12 @@ export const SwapRoutesExpanded = () => {
const hasPath = navigationRoutesValues.includes(path);

const handleRouteClick = (route: Route) => {
setExecutableRoute(route);
navigate(navigationRoutes.swapExecution, {
state: { routeId: route.id },
});
if (isValid && !isValidating) {
setExecutableRoute(route);
navigate(navigationRoutes.swapExecution, {
state: { routeId: route.id },
});
}
};

const currentRoute = routes?.[0];
Expand Down

0 comments on commit 7165164

Please sign in to comment.