Skip to content

Commit

Permalink
fix: insurance card isn't shown in some cases
Browse files Browse the repository at this point in the history
  • Loading branch information
chybisov committed May 15, 2023
1 parent d31f7e4 commit a8eb1ef
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 15 deletions.
12 changes: 3 additions & 9 deletions packages/widget/src/components/Insurance/InsuranceCollapsed.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import type { Route } from '@lifi/sdk';
import { Collapse } from '@mui/material';
import { useState } from 'react';
import { useSwapRoutes } from '../../hooks';
import {
RouteExecutionStatus,
Expand All @@ -18,20 +16,16 @@ export const InsuranceCollapsed: React.FC<InsuranceProps> = ({
onChange,
...props
}) => {
const [insuredRoute, setInsuredRoute] = useState<Route>();
const setExecutableRoute = useSetExecutableRoute();
const routeExecution = useRouteExecutionStore(
(state) => state.routes[insurableRouteId],
);
useSwapRoutes({
const { routes } = useSwapRoutes({
insurableRoute: routeExecution?.route,
onSettled(data) {
if (data?.routes?.[0]) {
setInsuredRoute(data.routes[0]);
}
},
});

const insuredRoute = routes?.[0];

const toggleInsurance = (checked: boolean) => {
if (insuredRoute) {
if (checked) {
Expand Down
7 changes: 1 addition & 6 deletions packages/widget/src/hooks/useSwapRoutes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,10 @@ import { useSwapOnly } from './useSwapOnly';
const refetchTime = 60_000;

interface SwapRoutesProps {
onSettled?: (data?: RoutesResponse) => void;
insurableRoute?: Route;
}

export const useSwapRoutes = ({
onSettled,
insurableRoute,
}: SwapRoutesProps = {}) => {
export const useSwapRoutes = ({ insurableRoute }: SwapRoutesProps = {}) => {
const lifi = useLiFi();
const { variant, sdkConfig, insurance, contractTool } = useWidgetConfig();
const { account } = useWallet();
Expand Down Expand Up @@ -300,7 +296,6 @@ export const useSwapRoutes = ({
});
}
},
onSettled,
},
);

Expand Down

0 comments on commit a8eb1ef

Please sign in to comment.