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

fix: agent login redirect due to balances #548

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