Skip to content

Commit

Permalink
Navigate to send funds if eoa balance is empty
Browse files Browse the repository at this point in the history
  • Loading branch information
Atatakai authored and Atatakai committed May 29, 2024
1 parent 6217b24 commit c12e6bd
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 14 deletions.
2 changes: 1 addition & 1 deletion frontend/components/Main/MainNeedsFunds.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ export const MainNeedsFunds = () => {
<span className="font-weight-600">
{`${serviceFundRequirements.eth} XDAI `}
</span>
- for gas & trading balance.
- for trading balance.
</Text>
)}
</Flex>
Expand Down
11 changes: 9 additions & 2 deletions frontend/components/Setup/Create/SetupEoaFunding.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand All @@ -55,7 +59,10 @@ export const SetupEoaFunding = () => {

return (
<CardFlex>
<SetupCreateHeader prev={SetupScreen.SetupBackupSigner} />
<SetupCreateHeader
prev={SetupScreen.SetupBackupSigner}
disabled={isIncomplete}
/>
<Typography.Title level={3}>
Deposit {MIN_ETH_BALANCE_THRESHOLDS[Chain.GNOSIS].safeCreation} XDAI on
Gnosis
Expand Down
2 changes: 2 additions & 0 deletions frontend/components/Setup/Setup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ export const Setup = () => {
return <SetupBackupSigner />;
case SetupScreen.SetupEoaFunding:
return <SetupEoaFunding />;
case SetupScreen.SetupEoaFundingIncomplete:
return <SetupEoaFunding isIncomplete />;
case SetupScreen.SetupCreateSafe:
return <SetupCreateSafe />;
// Restore account
Expand Down
42 changes: 31 additions & 11 deletions frontend/components/Setup/SetupWelcome.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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();

Expand All @@ -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 (
<FormFlex form={form} onFinish={handleLogin}>
<Form.Item
Expand Down
1 change: 1 addition & 0 deletions frontend/enums/SetupScreen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export enum SetupScreen {
SetupSeedPhrase,
SetupBackupSigner,
SetupEoaFunding,
SetupEoaFundingIncomplete,
SetupCreateSafe,
Restore,
RestoreViaSeed,
Expand Down

0 comments on commit c12e6bd

Please sign in to comment.