From 41aec50599cb36d7c1c8b74e87aa35e63c1e8b36 Mon Sep 17 00:00:00 2001 From: mohandast52 Date: Thu, 21 Nov 2024 22:57:08 +0530 Subject: [PATCH 1/9] feat: enhance StakingContractSection to use selected service's chain ID for contract details link --- .../StakingContractSection/index.tsx | 22 +++++-- .../SetupPage/Create/SetupBackupSigner.tsx | 2 +- frontend/config/mechs.ts | 9 ++- frontend/config/stakingPrograms/index.ts | 14 ++-- frontend/pages/_app.tsx | 64 ++++++++++--------- 5 files changed, 63 insertions(+), 48 deletions(-) diff --git a/frontend/components/ManageStakingPage/StakingContractSection/index.tsx b/frontend/components/ManageStakingPage/StakingContractSection/index.tsx index b23ffea35..51206d27f 100644 --- a/frontend/components/ManageStakingPage/StakingContractSection/index.tsx +++ b/frontend/components/ManageStakingPage/StakingContractSection/index.tsx @@ -1,13 +1,14 @@ import { Flex, Tag, theme, Typography } from 'antd'; import { useMemo } from 'react'; -import { MiddlewareChain } from '@/client'; import { CardSection } from '@/components/styled/CardSection'; import { UNICODE_SYMBOLS } from '@/constants/symbols'; import { EXPLORER_URL } from '@/constants/urls'; import { StakingProgramId } from '@/enums/StakingProgram'; import { StakingProgramStatus } from '@/enums/StakingProgramStatus'; +import { useServices } from '@/hooks/useServices'; import { useStakingProgram } from '@/hooks/useStakingProgram'; +import { Maybe } from '@/types/Util'; import { CantMigrateAlert } from './CantMigrateAlert'; import { MigrateButton } from './MigrateButton'; @@ -41,6 +42,7 @@ export const StakingContractSection = ({ activeStakingProgramMeta, activeStakingProgramAddress, } = useStakingProgram(); + const { selectedService } = useServices(); // /** // * Returns `true` if this stakingProgram is active, @@ -84,6 +86,9 @@ export const StakingContractSection = ({ ); }, [migrateValidation]); + const chainId: Maybe = + selectedService?.home_chain_id; + return ( <> - - View contract details {UNICODE_SYMBOLS.EXTERNAL_LINK} - + + {chainId && ( + + View contract details {UNICODE_SYMBOLS.EXTERNAL_LINK} + + )} {!migrateValidation.canMigrate && ( { const handleFinish = (values: { 'backup-signer': string }) => { const checksummedAddress = getAddress( - // important to lowercase the address before checksumming, invalid checksums will cause ethers to throw + // important to lowercase the address before check summing, invalid checksums will cause ethers to throw values['backup-signer'].toLowerCase(), ) as Address | null; // returns null if invalid, ethers type is incorrect... diff --git a/frontend/config/mechs.ts b/frontend/config/mechs.ts index 375171852..c55eb15c9 100644 --- a/frontend/config/mechs.ts +++ b/frontend/config/mechs.ts @@ -1,3 +1,4 @@ +import { JsonFragment } from '@ethersproject/abi'; import { Contract as MulticallContract } from 'ethers-multicall'; import { AGENT_MECH_ABI } from '@/abis/agentMech'; @@ -24,14 +25,18 @@ export const MECHS: Mechs = { name: 'Agent Mech', contract: new MulticallContract( '0x77af31De935740567Cf4fF1986D04B2c964A786a', - AGENT_MECH_ABI, + AGENT_MECH_ABI.filter( + (abi) => (abi as JsonFragment).type === 'function', + ) as JsonFragment[], ), }, [MechType.Marketplace]: { name: 'Mech Marketplace', contract: new MulticallContract( '0x4554fE75c1f5576c1d7F765B2A036c199Adae329', - MECH_MARKETPLACE_ABI, + MECH_MARKETPLACE_ABI.filter( + (abi) => (abi as JsonFragment).type === 'function', + ) as JsonFragment[], ), }, }, diff --git a/frontend/config/stakingPrograms/index.ts b/frontend/config/stakingPrograms/index.ts index 735d44e8d..6a2e9adf9 100644 --- a/frontend/config/stakingPrograms/index.ts +++ b/frontend/config/stakingPrograms/index.ts @@ -9,10 +9,10 @@ import { GNOSIS_STAKING_PROGRAMS, GNOSIS_STAKING_PROGRAMS_CONTRACT_ADDRESSES, } from './gnosis'; -import { - OPTIMISM_STAKING_PROGRAMS, - OPTIMISM_STAKING_PROGRAMS_CONTRACT_ADDRESSES, -} from './optimism'; +// import { +// OPTIMISM_STAKING_PROGRAMS, +// OPTIMISM_STAKING_PROGRAMS_CONTRACT_ADDRESSES, +// } from './optimism'; /** * Single non-chain specific staking program configuration @@ -38,19 +38,19 @@ export const STAKING_PROGRAMS: { [chainId: number | ChainId]: StakingProgramMap; } = { [ChainId.Gnosis]: GNOSIS_STAKING_PROGRAMS, - [ChainId.Optimism]: OPTIMISM_STAKING_PROGRAMS, + // [ChainId.Optimism]: OPTIMISM_STAKING_PROGRAMS, }; export const STAKING_PROGRAM_ADDRESS: { [chainId: number | ChainId]: Record; } = { [ChainId.Gnosis]: GNOSIS_STAKING_PROGRAMS_CONTRACT_ADDRESSES, - [ChainId.Optimism]: OPTIMISM_STAKING_PROGRAMS_CONTRACT_ADDRESSES, + // [ChainId.Optimism]: OPTIMISM_STAKING_PROGRAMS_CONTRACT_ADDRESSES, }; export const INITIAL_DEFAULT_STAKING_PROGRAM_IDS: { [chainId: number | ChainId]: StakingProgramId; } = { [ChainId.Gnosis]: StakingProgramId.PearlBeta, - [ChainId.Optimism]: StakingProgramId.OptimusAlpha, + // [ChainId.Optimism]: StakingProgramId.OptimusAlpha, }; diff --git a/frontend/pages/_app.tsx b/frontend/pages/_app.tsx index 86d81156d..f95270214 100644 --- a/frontend/pages/_app.tsx +++ b/frontend/pages/_app.tsx @@ -38,37 +38,39 @@ export default function App({ Component, pageProps }: AppProps) { - - - - - - - - - - - - {isMounted ? ( - - - - - - - - ) : null} - - - - - - - - - - - + + + + + + + + + + + + + {isMounted ? ( + + + + + + + + ) : null} + + + + + + + + + + + + From 6eaa540cc6b6e261fac9baee68d57049f6ab2641 Mon Sep 17 00:00:00 2001 From: mohandast52 Date: Thu, 21 Nov 2024 23:29:50 +0530 Subject: [PATCH 2/9] feat: update SetupWelcomeLogin to utilize selected service's chain ID for master safe and balance checks --- .../components/SetupPage/SetupWelcome.tsx | 25 ++++++++++++------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/frontend/components/SetupPage/SetupWelcome.tsx b/frontend/components/SetupPage/SetupWelcome.tsx index 789501cf4..a86fa4735 100644 --- a/frontend/components/SetupPage/SetupWelcome.tsx +++ b/frontend/components/SetupPage/SetupWelcome.tsx @@ -17,6 +17,7 @@ import { SetupScreen } from '@/enums/SetupScreen'; import { useBalanceContext } from '@/hooks/useBalanceContext'; import { useElectronApi } from '@/hooks/useElectronApi'; import { usePageState } from '@/hooks/usePageState'; +import { useServices } from '@/hooks/useServices'; import { useSetup } from '@/hooks/useSetup'; import { useMasterWalletContext } from '@/hooks/useWallet'; import { AccountService } from '@/service/Account'; @@ -129,9 +130,15 @@ export const SetupWelcomeLogin = () => { const { goto } = useSetup(); const { goto: gotoPage } = usePageState(); - const { masterSafeAddress, masterWallets: wallets } = - useMasterWalletContext(); - const { isBalanceLoaded, masterEoaBalance: eoaBalance } = useBalanceContext(); + const { selectedService } = useServices(); + const { masterSafes, masterWallets: wallets } = useMasterWalletContext(); + const { isLoaded, walletBalances } = useBalanceContext(); + + const masterSafe = + masterSafes?.find( + (safe) => safe.chainId === selectedService?.home_chain_id, + ) ?? null; + const eoaBalanceEth = walletBalances?.find((balance) => balance.isNative); const [isLoggingIn, setIsLoggingIn] = useState(false); const [canNavigate, setCanNavigate] = useState(false); @@ -157,11 +164,11 @@ export const SetupWelcomeLogin = () => { useEffect(() => { // Navigate only when wallets and balances are loaded // To check if some setup steps were missed - if (canNavigate && wallets?.length && isBalanceLoaded) { + if (canNavigate && wallets?.length && isLoaded) { setIsLoggingIn(false); - if (!eoaBalance?.ETH) { + if (!eoaBalanceEth) { goto(SetupScreen.SetupEoaFundingIncomplete); - } else if (!masterSafeAddress) { + } else if (!masterSafe?.address) { goto(SetupScreen.SetupCreateSafe); } else { gotoPage(Pages.Main); @@ -169,11 +176,11 @@ export const SetupWelcomeLogin = () => { } }, [ canNavigate, - eoaBalance?.ETH, + eoaBalanceEth, goto, gotoPage, - isBalanceLoaded, - masterSafeAddress, + isLoaded, + masterSafe?.address, wallets?.length, ]); From 931e13009e76d4f60826fda25edfa5f83840a931 Mon Sep 17 00:00:00 2001 From: mohandast52 Date: Thu, 21 Nov 2024 23:50:53 +0530 Subject: [PATCH 3/9] feat: refactor Setup components for improved chain support and address validation --- .../SetupPage/Create/SetupBackupSigner.tsx | 5 +- .../SetupPage/Create/SetupEoaFunding.tsx | 88 +++++++++++-------- .../SetupPage/Create/SetupPassword.tsx | 3 +- .../SetupPage/Create/SetupSeedPhrase.tsx | 2 + frontend/constants/thresholds.ts | 10 ++- 5 files changed, 63 insertions(+), 45 deletions(-) diff --git a/frontend/components/SetupPage/Create/SetupBackupSigner.tsx b/frontend/components/SetupPage/Create/SetupBackupSigner.tsx index aa1908b11..8fab9334c 100644 --- a/frontend/components/SetupPage/Create/SetupBackupSigner.tsx +++ b/frontend/components/SetupPage/Create/SetupBackupSigner.tsx @@ -17,10 +17,11 @@ export const SetupBackupSigner = () => { const [form] = Form.useForm(); const handleFinish = (values: { 'backup-signer': string }) => { + // important to lowercase the address before check summing, invalid checksums will cause ethers to throw + // returns null if invalid, ethers type is incorrect... const checksummedAddress = getAddress( - // important to lowercase the address before check summing, invalid checksums will cause ethers to throw values['backup-signer'].toLowerCase(), - ) as Address | null; // returns null if invalid, ethers type is incorrect... + ) as Address | null; // If the address is invalid, show an error message if (!checksummedAddress) { diff --git a/frontend/components/SetupPage/Create/SetupEoaFunding.tsx b/frontend/components/SetupPage/Create/SetupEoaFunding.tsx index 9b566ca37..bf7c80ddf 100644 --- a/frontend/components/SetupPage/Create/SetupEoaFunding.tsx +++ b/frontend/components/SetupPage/Create/SetupEoaFunding.tsx @@ -1,7 +1,7 @@ import { CopyOutlined } from '@ant-design/icons'; import { Flex, message, Tooltip, Typography } from 'antd'; import { BigNumber, ethers } from 'ethers'; -import { useCallback, useEffect, useMemo, useState } from 'react'; +import { useCallback, useEffect, useState } from 'react'; import styled from 'styled-components'; import { useInterval } from 'usehooks-ts'; @@ -10,15 +10,13 @@ import { CustomAlert } from '@/components/Alert'; import { CardFlex } from '@/components/styled/CardFlex'; import { CardSection } from '@/components/styled/CardSection'; import { CHAIN_CONFIG } from '@/config/chains'; -import { - BASE_PROVIDER, - ETHEREUM_PROVIDER, - OPTIMISM_PROVIDER, -} from '@/constants/providers'; +import { PROVIDERS } from '@/constants/providers'; import { MIN_ETH_BALANCE_THRESHOLDS } from '@/constants/thresholds'; +import { ChainId } from '@/enums/Chain'; import { SetupScreen } from '@/enums/SetupScreen'; +import { useBalanceContext } from '@/hooks/useBalanceContext'; import { useSetup } from '@/hooks/useSetup'; -import { useWallet } from '@/hooks/useWallet'; +import { useMasterWalletContext } from '@/hooks/useWallet'; import { Address } from '@/types/Address'; import { copyToClipboard } from '@/utils/copyToClipboard'; import { delayInSeconds } from '@/utils/delay'; @@ -40,9 +38,18 @@ const AccountCreationCard = styled.div` const ICON_STYLE = { color: '#606F85' }; +const statusMessage = (isFunded?: boolean) => { + if (isFunded) { + return 'Funds have been received!'; + } else { + return 'Waiting for transaction'; + } +}; + type SetupEoaFundingWaitingProps = { chainName: string }; const SetupEoaFundingWaiting = ({ chainName }: SetupEoaFundingWaitingProps) => { - const { masterEoaAddress } = useWallet(); + const { masterEoa } = useMasterWalletContext(); + const masterEoaAddress = masterEoa?.address; return ( <> @@ -110,14 +117,6 @@ export const SetupEoaFundingForChain = ({ }: SetupEoaFundingProps) => { const { goto } = useSetup(); - const statusMessage = useMemo(() => { - if (isFunded) { - return 'Funds have been received!'; - } else { - return 'Waiting for transaction'; - } - }, [isFunded]); - useEffect(() => { message.success(`${chainName} funds have been received!`); @@ -141,7 +140,7 @@ export const SetupEoaFundingForChain = ({ borderbottom={isFunded ? 'true' : 'false'} > - Status: {statusMessage} + Status: {statusMessage(isFunded)} {!isFunded && } @@ -149,29 +148,38 @@ export const SetupEoaFundingForChain = ({ ); }; +// TODO: chain independent const eoaFundingMap = { - [MiddlewareChain.OPTIMISM]: { - provider: OPTIMISM_PROVIDER, - chainConfig: CHAIN_CONFIG.OPTIMISM, - requiredEth: - MIN_ETH_BALANCE_THRESHOLDS[MiddlewareChain.OPTIMISM].safeCreation, - }, - [MiddlewareChain.ETHEREUM]: { - provider: ETHEREUM_PROVIDER, - chainConfig: CHAIN_CONFIG.ETHEREUM, - requiredEth: - MIN_ETH_BALANCE_THRESHOLDS[MiddlewareChain.ETHEREUM].safeCreation, - }, - [MiddlewareChain.BASE]: { - provider: BASE_PROVIDER, - chainConfig: CHAIN_CONFIG.BASE, - requiredEth: MIN_ETH_BALANCE_THRESHOLDS[MiddlewareChain.BASE].safeCreation, + // [MiddlewareChain.OPTIMISM]: { + // provider: OPTIMISM_PROVIDER, + // chainConfig: CHAIN_CONFIG.OPTIMISM, + // requiredEth: + // MIN_ETH_BALANCE_THRESHOLDS[MiddlewareChain.OPTIMISM].safeCreation, + // }, + // [MiddlewareChain.ETHEREUM]: { + // provider: ETHEREUM_PROVIDER, + // chainConfig: CHAIN_CONFIG.ETHEREUM, + // requiredEth: + // MIN_ETH_BALANCE_THRESHOLDS[MiddlewareChain.ETHEREUM].safeCreation, + // }, + // [MiddlewareChain.BASE]: { + // provider: BASE_PROVIDER, + // chainConfig: CHAIN_CONFIG.BASE, + // requiredEth: MIN_ETH_BALANCE_THRESHOLDS[MiddlewareChain.BASE].safeCreation, + // }, + [MiddlewareChain.GNOSIS]: { + provider: PROVIDERS[ChainId.Gnosis].provider, + chainConfig: CHAIN_CONFIG[ChainId.Gnosis], + requiredEth: MIN_ETH_BALANCE_THRESHOLDS[ChainId.Gnosis].safeCreation, }, }; export const SetupEoaFunding = () => { const { goto } = useSetup(); - const { masterEoaAddress } = useWallet(); + const { masterEoa } = useMasterWalletContext(); + const { walletBalances } = useBalanceContext(); + const masterEoaAddress = masterEoa?.address; + const [currentChain, setCurrentChain] = useState( +Object.keys(eoaFundingMap)[0] as MiddlewareChain, ); @@ -225,6 +233,12 @@ export const SetupEoaFunding = () => { goto(SetupScreen.SetupCreateSafe); }, 5000); + const eoaBalance = walletBalances.find((e) => e.isNative); + const isFunded = + eoaBalance?.chainId === ChainId.Ethereum && + eoaBalance.balance >= + MIN_ETH_BALANCE_THRESHOLDS[ChainId.Gnosis].safeCreation; + return ( @@ -235,15 +249,15 @@ export const SetupEoaFunding = () => { The app needs these funds to create your account on-chain. - {/* - Status: {statusMessage} + Status: {statusMessage(isFunded)} - */} + { const [form] = Form.useForm<{ password: string; terms: boolean }>(); const [isLoading, setIsLoading] = useState(false); - const isTermsAccepted = Form.useWatch('terms', form); const handleCreateEoa = async ({ password }: { password: string }) => { @@ -26,7 +25,7 @@ export const SetupPassword = () => { setIsLoading(true); AccountService.createAccount(password) .then(() => AccountService.loginAccount(password)) - .then(() => WalletService.createEoa(MiddlewareChain.OPTIMISM)) + .then(() => WalletService.createEoa(MiddlewareChain.GNOSIS)) // TODO: chain independent .then(({ mnemonic }: { mnemonic: string[] }) => { setMnemonic(mnemonic); goto(SetupScreen.SetupSeedPhrase); diff --git a/frontend/components/SetupPage/Create/SetupSeedPhrase.tsx b/frontend/components/SetupPage/Create/SetupSeedPhrase.tsx index 46a8d1bca..dd8811f61 100644 --- a/frontend/components/SetupPage/Create/SetupSeedPhrase.tsx +++ b/frontend/components/SetupPage/Create/SetupSeedPhrase.tsx @@ -18,6 +18,7 @@ export const SetupSeedPhrase = () => { Back up seed phrase + Seed phrase is needed to regain access to your account if you forget @@ -33,6 +34,7 @@ export const SetupSeedPhrase = () => { ))} + + If you don’t have the seed phrase but added a backup wallet to your @@ -134,6 +136,7 @@ export const SetupRestoreViaSeed = () => { export const SetupRestoreSetPassword = () => { const { goto } = useSetup(); const [password, setPassword] = useState(''); + return ( Date: Fri, 22 Nov 2024 00:35:20 +0530 Subject: [PATCH 6/9] Update frontend/components/SetupPage/Create/SetupEoaFunding.tsx Co-authored-by: Josh Miller <31908788+truemiller@users.noreply.github.com> --- frontend/components/SetupPage/Create/SetupEoaFunding.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontend/components/SetupPage/Create/SetupEoaFunding.tsx b/frontend/components/SetupPage/Create/SetupEoaFunding.tsx index e23cb2419..36b6d7f40 100644 --- a/frontend/components/SetupPage/Create/SetupEoaFunding.tsx +++ b/frontend/components/SetupPage/Create/SetupEoaFunding.tsx @@ -88,7 +88,7 @@ const SetupEoaFundingWaiting = ({ chainName }: SetupEoaFundingWaitingProps) => { - {`ETH: ${masterEoaAddress || NA}`} + {`XDAI: ${masterEoaAddress || NA}`} {/* Date: Fri, 22 Nov 2024 00:37:35 +0530 Subject: [PATCH 7/9] Update frontend/components/SetupPage/Create/SetupEoaFunding.tsx Co-authored-by: Josh Miller <31908788+truemiller@users.noreply.github.com> --- frontend/components/SetupPage/Create/SetupEoaFunding.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontend/components/SetupPage/Create/SetupEoaFunding.tsx b/frontend/components/SetupPage/Create/SetupEoaFunding.tsx index 36b6d7f40..6d20713ab 100644 --- a/frontend/components/SetupPage/Create/SetupEoaFunding.tsx +++ b/frontend/components/SetupPage/Create/SetupEoaFunding.tsx @@ -236,7 +236,7 @@ export const SetupEoaFunding = () => { const eoaBalance = walletBalances.find((e) => e.isNative); const isFunded = - eoaBalance?.chainId === ChainId.Ethereum && + eoaBalance?.chainId === ChainId.Gnosis && eoaBalance.balance >= MIN_ETH_BALANCE_THRESHOLDS[ChainId.Gnosis].safeCreation; From 5e23c2bd92d7fc11a9d461df0779b78e78ff4a52 Mon Sep 17 00:00:00 2001 From: Mohan Date: Fri, 22 Nov 2024 00:37:43 +0530 Subject: [PATCH 8/9] Update frontend/components/SetupPage/Create/SetupEoaFunding.tsx Co-authored-by: Josh Miller <31908788+truemiller@users.noreply.github.com> --- frontend/components/SetupPage/Create/SetupEoaFunding.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontend/components/SetupPage/Create/SetupEoaFunding.tsx b/frontend/components/SetupPage/Create/SetupEoaFunding.tsx index 6d20713ab..9d894c7e5 100644 --- a/frontend/components/SetupPage/Create/SetupEoaFunding.tsx +++ b/frontend/components/SetupPage/Create/SetupEoaFunding.tsx @@ -234,7 +234,7 @@ export const SetupEoaFunding = () => { goto(SetupScreen.SetupCreateSafe); }, 5000); - const eoaBalance = walletBalances.find((e) => e.isNative); + const eoaBalance = walletBalances.find((e) => e.isNative); // TODO: ensure we pull correct native with chainId when implementing multi-chain const isFunded = eoaBalance?.chainId === ChainId.Gnosis && eoaBalance.balance >= From 5d8b82e5bd0434c675f648b2e250781c551e8bd3 Mon Sep 17 00:00:00 2001 From: mohandast52 Date: Fri, 22 Nov 2024 01:02:07 +0530 Subject: [PATCH 9/9] feat: refactor Setup components to use master wallet balances and simplify logic --- .../SetupPage/Create/SetupCreateSafe.tsx | 6 +----- .../SetupPage/Create/SetupEoaFunding.tsx | 10 ++++++---- frontend/components/SetupPage/SetupWelcome.tsx | 18 ++++++++++++++---- frontend/pages/_app.tsx | 12 +++++------- 4 files changed, 26 insertions(+), 20 deletions(-) diff --git a/frontend/components/SetupPage/Create/SetupCreateSafe.tsx b/frontend/components/SetupPage/Create/SetupCreateSafe.tsx index 6aac976f0..d063157d5 100644 --- a/frontend/components/SetupPage/Create/SetupCreateSafe.tsx +++ b/frontend/components/SetupPage/Create/SetupCreateSafe.tsx @@ -7,7 +7,6 @@ import { CardSection } from '@/components/styled/CardSection'; import { UNICODE_SYMBOLS } from '@/constants/symbols'; import { SUPPORT_URL } from '@/constants/urls'; import { Pages } from '@/enums/Pages'; -import { WalletOwnerType } from '@/enums/Wallet'; import { usePageState } from '@/hooks/usePageState'; import { useSetup } from '@/hooks/useSetup'; import { useMasterWalletContext } from '@/hooks/useWallet'; @@ -62,10 +61,7 @@ export const SetupCreateSafe = () => { const masterSafeAddress = useMemo(() => { if (!masterSafes) return; - const master = masterSafes.find( - (safe) => safe.owner === WalletOwnerType.Master, - ); - return master?.address; + return masterSafes[0]?.address; }, [masterSafes]); const [isCreatingSafe, setIsCreatingSafe] = useState(false); diff --git a/frontend/components/SetupPage/Create/SetupEoaFunding.tsx b/frontend/components/SetupPage/Create/SetupEoaFunding.tsx index e23cb2419..9263abf41 100644 --- a/frontend/components/SetupPage/Create/SetupEoaFunding.tsx +++ b/frontend/components/SetupPage/Create/SetupEoaFunding.tsx @@ -15,7 +15,7 @@ import { NA } from '@/constants/symbols'; import { MIN_ETH_BALANCE_THRESHOLDS } from '@/constants/thresholds'; import { ChainId } from '@/enums/Chain'; import { SetupScreen } from '@/enums/SetupScreen'; -import { useBalanceContext } from '@/hooks/useBalanceContext'; +import { useMasterBalances } from '@/hooks/useBalanceContext'; import { useSetup } from '@/hooks/useSetup'; import { useMasterWalletContext } from '@/hooks/useWallet'; import { Address } from '@/types/Address'; @@ -178,7 +178,7 @@ const eoaFundingMap = { export const SetupEoaFunding = () => { const { goto } = useSetup(); const { masterEoa } = useMasterWalletContext(); - const { walletBalances } = useBalanceContext(); + const { masterWalletBalances } = useMasterBalances(); const masterEoaAddress = masterEoa?.address; const [currentChain, setCurrentChain] = useState( @@ -234,9 +234,11 @@ export const SetupEoaFunding = () => { goto(SetupScreen.SetupCreateSafe); }, 5000); - const eoaBalance = walletBalances.find((e) => e.isNative); + const eoaBalance = masterWalletBalances?.find( + (balance) => balance.walletAddress === masterEoaAddress, + ); const isFunded = - eoaBalance?.chainId === ChainId.Ethereum && + eoaBalance?.chainId === ChainId.Gnosis && eoaBalance.balance >= MIN_ETH_BALANCE_THRESHOLDS[ChainId.Gnosis].safeCreation; diff --git a/frontend/components/SetupPage/SetupWelcome.tsx b/frontend/components/SetupPage/SetupWelcome.tsx index a86fa4735..b6f252df5 100644 --- a/frontend/components/SetupPage/SetupWelcome.tsx +++ b/frontend/components/SetupPage/SetupWelcome.tsx @@ -14,7 +14,10 @@ import { useCallback, useEffect, useMemo, useState } from 'react'; import { MiddlewareAccountIsSetup } from '@/client'; import { Pages } from '@/enums/Pages'; import { SetupScreen } from '@/enums/SetupScreen'; -import { useBalanceContext } from '@/hooks/useBalanceContext'; +import { + useBalanceContext, + useMasterBalances, +} from '@/hooks/useBalanceContext'; import { useElectronApi } from '@/hooks/useElectronApi'; import { usePageState } from '@/hooks/usePageState'; import { useServices } from '@/hooks/useServices'; @@ -131,14 +134,21 @@ export const SetupWelcomeLogin = () => { const { goto: gotoPage } = usePageState(); const { selectedService } = useServices(); - const { masterSafes, masterWallets: wallets } = useMasterWalletContext(); - const { isLoaded, walletBalances } = useBalanceContext(); + const { + masterSafes, + masterWallets: wallets, + masterEoa, + } = useMasterWalletContext(); + const { isLoaded } = useBalanceContext(); + const { masterWalletBalances } = useMasterBalances(); const masterSafe = masterSafes?.find( (safe) => safe.chainId === selectedService?.home_chain_id, ) ?? null; - const eoaBalanceEth = walletBalances?.find((balance) => balance.isNative); + const eoaBalanceEth = masterWalletBalances?.find( + (balance) => balance.walletAddress === masterEoa?.address, + ); const [isLoggingIn, setIsLoggingIn] = useState(false); const [canNavigate, setCanNavigate] = useState(false); diff --git a/frontend/pages/_app.tsx b/frontend/pages/_app.tsx index f95270214..63ecbdf74 100644 --- a/frontend/pages/_app.tsx +++ b/frontend/pages/_app.tsx @@ -51,13 +51,11 @@ export default function App({ Component, pageProps }: AppProps) { {isMounted ? ( - - - - - - - + + + + + ) : null}