Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Navigate to send funds if eoa balance is empty #153

Merged
merged 1 commit into from
May 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, looks good

</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
Loading