Skip to content

Commit

Permalink
feat: enhance SetupEoaFunding and SetupWelcomeLogin components with i…
Browse files Browse the repository at this point in the history
…mproved navigation logic and documentation
  • Loading branch information
mohandast52 committed Dec 6, 2024
1 parent 084304b commit 21d84f5
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 20 deletions.
3 changes: 3 additions & 0 deletions frontend/components/SetupPage/Create/SetupEoaFunding.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,9 @@ const EOA_FUNDING_MAP: Record<
// }
};

/**
* EOA funding setup screen
*/
export const SetupEoaFunding = () => {
const { goto } = useSetup();
const { selectedAgentType, selectedAgentConfig } = useServices();
Expand Down
33 changes: 13 additions & 20 deletions frontend/components/SetupPage/SetupWelcome.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import Image from 'next/image';
import { useCallback, useEffect, useMemo, useState } from 'react';

import { MiddlewareAccountIsSetup } from '@/client';
import { MIN_ETH_BALANCE_THRESHOLDS } from '@/constants/thresholds';
import { Pages } from '@/enums/Pages';
import { SetupScreen } from '@/enums/SetupScreen';
import {
Expand Down Expand Up @@ -132,6 +131,7 @@ export const SetupWelcomeCreate = () => {
};

export const SetupWelcomeLogin = () => {
const [form] = Form.useForm();
const { goto } = useSetup();
const { goto: gotoPage } = usePageState();

Expand Down Expand Up @@ -164,8 +164,6 @@ export const SetupWelcomeLogin = () => {
const [isLoggingIn, setIsLoggingIn] = useState(false);
const [canNavigate, setCanNavigate] = useState(false);

const [form] = Form.useForm();

const handleLogin = useCallback(
async ({ password }: { password: string }) => {
setIsLoggingIn(true);
Expand All @@ -184,24 +182,19 @@ export const SetupWelcomeLogin = () => {
);

useEffect(() => {
if (!canNavigate) return;

// Navigate only when wallets and balances are loaded
// To check if some setup steps were missed
// if (canNavigate && wallets?.length && isBalanceLoaded) {

// TODO: fix wallet and balance loads
if (canNavigate) {
setIsLoggingIn(false);
if (
!eoaBalanceEth ||
eoaBalanceEth <
MIN_ETH_BALANCE_THRESHOLDS[selectedServiceOrAgentChainId].safeCreation
) {
goto(SetupScreen.SetupEoaFundingIncomplete);
} else if (!masterSafe?.address) {
goto(SetupScreen.SetupCreateSafe);
} else {
gotoPage(Pages.Main);
}
if (!isBalanceLoaded) return;

setIsLoggingIn(false);

if (!eoaBalanceEth) {
goto(SetupScreen.SetupEoaFundingIncomplete);
} else if (!masterSafe?.address) {
goto(SetupScreen.SetupCreateSafe);
} else {
gotoPage(Pages.Main);
}
}, [
canNavigate,
Expand Down

0 comments on commit 21d84f5

Please sign in to comment.