Skip to content

Commit

Permalink
fix: sometimes account signer is not found after page refresh
Browse files Browse the repository at this point in the history
  • Loading branch information
chybisov committed Jul 5, 2022
1 parent c016e15 commit 054648e
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions packages/widget/src/hooks/useRouteExecution.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Route } from '@lifinance/sdk';
import { useCallback, useEffect } from 'react';
import { useCallback, useEffect, useRef } from 'react';
import { useMutation } from 'react-query';
import shallow from 'zustand/shallow';
import { LiFi } from '../lifi';
Expand All @@ -9,6 +9,7 @@ import { deepClone } from '../utils/deepClone';

export const useRouteExecution = (routeId: string) => {
const { account, switchChain } = useWallet();
const resumedAfterMount = useRef(false);
const { route, status } = useRouteStore(
(state) => state.routes[routeId] ?? {},
);
Expand Down Expand Up @@ -139,12 +140,19 @@ export const useRouteExecution = (routeId: string) => {
(step) => step.execution?.status === 'FAILED',
);
const alreadyStarted = route.steps.some((step) => step.execution);
if (!isDone && !isFailed && alreadyStarted) {
if (
!isDone &&
!isFailed &&
alreadyStarted &&
account.signer &&
!resumedAfterMount.current
) {
resumedAfterMount.current = true;
resumeRoute();
}
return () => LiFi.moveExecutionToBackground(route);
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);
}, [account.signer]);

return {
executeRoute,
Expand Down

0 comments on commit 054648e

Please sign in to comment.