From c12e6bd06468727cec7e3f98f988014012ece64f Mon Sep 17 00:00:00 2001 From: Atatakai Date: Wed, 29 May 2024 17:00:57 +0400 Subject: [PATCH] Navigate to send funds if eoa balance is empty --- frontend/components/Main/MainNeedsFunds.tsx | 2 +- .../Setup/Create/SetupEoaFunding.tsx | 11 ++++- frontend/components/Setup/Setup.tsx | 2 + frontend/components/Setup/SetupWelcome.tsx | 42 ++++++++++++++----- frontend/enums/SetupScreen.ts | 1 + 5 files changed, 44 insertions(+), 14 deletions(-) diff --git a/frontend/components/Main/MainNeedsFunds.tsx b/frontend/components/Main/MainNeedsFunds.tsx index 738eda62..60554d84 100644 --- a/frontend/components/Main/MainNeedsFunds.tsx +++ b/frontend/components/Main/MainNeedsFunds.tsx @@ -102,7 +102,7 @@ export const MainNeedsFunds = () => { {`${serviceFundRequirements.eth} XDAI `} - - for gas & trading balance. + - for trading balance. )} diff --git a/frontend/components/Setup/Create/SetupEoaFunding.tsx b/frontend/components/Setup/Create/SetupEoaFunding.tsx index 6f0d8ad4..dca8a6c3 100644 --- a/frontend/components/Setup/Create/SetupEoaFunding.tsx +++ b/frontend/components/Setup/Create/SetupEoaFunding.tsx @@ -30,7 +30,11 @@ import { useWallet } from '@/hooks/useWallet'; import { SetupCreateHeader } from './SetupCreateHeader'; -export const SetupEoaFunding = () => { +export const SetupEoaFunding = ({ + isIncomplete, +}: { + isIncomplete?: boolean; +}) => { const { eoaBalance } = useBalance(); const { goto } = useSetup(); @@ -55,7 +59,10 @@ export const SetupEoaFunding = () => { return ( - + Deposit {MIN_ETH_BALANCE_THRESHOLDS[Chain.GNOSIS].safeCreation} XDAI on Gnosis diff --git a/frontend/components/Setup/Setup.tsx b/frontend/components/Setup/Setup.tsx index 799abcbf..9e302585 100644 --- a/frontend/components/Setup/Setup.tsx +++ b/frontend/components/Setup/Setup.tsx @@ -31,6 +31,8 @@ export const Setup = () => { return ; case SetupScreen.SetupEoaFunding: return ; + case SetupScreen.SetupEoaFundingIncomplete: + return ; case SetupScreen.SetupCreateSafe: return ; // Restore account diff --git a/frontend/components/Setup/SetupWelcome.tsx b/frontend/components/Setup/SetupWelcome.tsx index cf78db14..37d51862 100644 --- a/frontend/components/Setup/SetupWelcome.tsx +++ b/frontend/components/Setup/SetupWelcome.tsx @@ -13,7 +13,7 @@ import { useCallback, useEffect, useMemo, useState } from 'react'; import { AccountIsSetup } from '@/client'; import { PageState, SetupScreen } from '@/enums'; -import { usePageState, useSetup } from '@/hooks'; +import { useBalance, usePageState, useSetup } from '@/hooks'; import { useElectronApi } from '@/hooks/useElectronApi'; import { useWallet } from '@/hooks/useWallet'; import { AccountService } from '@/service/Account'; @@ -104,9 +104,11 @@ export const SetupWelcomeLogin = () => { const { goto } = useSetup(); const { goto: gotoPage } = usePageState(); - const { masterEoaAddress, masterSafeAddress } = useWallet(); + const { masterSafeAddress, wallets } = useWallet(); + const { isBalanceLoaded, eoaBalance } = useBalance(); const [isLoggingIn, setIsLoggingIn] = useState(false); + const [canNavigate, setCanNavigate] = useState(false); const [form] = Form.useForm(); @@ -115,22 +117,40 @@ export const SetupWelcomeLogin = () => { setIsLoggingIn(true); AccountService.loginAccount(password) .then(() => { - if (masterEoaAddress && !masterSafeAddress) { - gotoPage(PageState.Setup); - goto(SetupScreen.SetupCreateSafe); - } else { - gotoPage(PageState.Main); - } + setCanNavigate(true); }) .catch((e) => { console.error(e); + setIsLoggingIn(false); message.error('Invalid password'); - }) - .finally(() => setIsLoggingIn(false)); + }); }, - [goto, gotoPage, masterEoaAddress, masterSafeAddress], + [], ); + useEffect(() => { + // Navigate only when wallets and balances are loaded + // To check if some setup steps were missed + if (canNavigate && wallets?.length && isBalanceLoaded) { + setIsLoggingIn(false); + if (!eoaBalance?.ETH) { + goto(SetupScreen.SetupEoaFundingIncomplete); + } else if (!masterSafeAddress) { + goto(SetupScreen.SetupCreateSafe); + } else { + gotoPage(PageState.Main); + } + } + }, [ + canNavigate, + eoaBalance?.ETH, + goto, + gotoPage, + isBalanceLoaded, + masterSafeAddress, + wallets?.length, + ]); + return (