From 0b9b197071dd8ce7faea34f9ad7abe64d6ef08ac Mon Sep 17 00:00:00 2001 From: mohandast52 Date: Thu, 5 Dec 2024 21:45:55 +0530 Subject: [PATCH] feat: set default last selected agent type to 'trader' and clean up unused code in MainPage component --- electron/store.js | 2 +- frontend/components/MainPage/index.tsx | 24 ------------------- .../StakingContractDetailsProvider.tsx | 6 ++--- 3 files changed, 4 insertions(+), 28 deletions(-) diff --git a/electron/store.js b/electron/store.js index 611e2fb3f..a09727779 100644 --- a/electron/store.js +++ b/electron/store.js @@ -10,7 +10,7 @@ const schema = { currentStakingProgram: { type: 'string', default: '' }, // agent settings - lastSelectedAgentType: { type: 'string', default: '' }, + lastSelectedAgentType: { type: 'string', default: 'trader' }, }; /** diff --git a/frontend/components/MainPage/index.tsx b/frontend/components/MainPage/index.tsx index 6e7d497fb..dd30035cb 100644 --- a/frontend/components/MainPage/index.tsx +++ b/frontend/components/MainPage/index.tsx @@ -1,10 +1,7 @@ import { Card, Flex } from 'antd'; -import { useEffect } from 'react'; import { StakingProgramId } from '@/enums/StakingProgram'; -import { useElectronApi } from '@/hooks/useElectronApi'; import { useFeatureFlag } from '@/hooks/useFeatureFlag'; -import { useServices } from '@/hooks/useServices'; // import { StakingProgramId } from '@/enums/StakingProgram'; // import { useMasterSafe } from '@/hooks/useMasterSafe'; import { @@ -12,7 +9,6 @@ import { useStakingContractDetails, } from '@/hooks/useStakingContractDetails'; import { useStakingProgram } from '@/hooks/useStakingProgram'; -import { useStore } from '@/hooks/useStore'; // import { useMasterWalletContext } from '@/hooks/useWallet'; import { MainHeader } from './header'; @@ -26,27 +22,7 @@ import { RewardsSection } from './sections/RewardsSection'; import { StakingContractSection } from './sections/StakingContractUpdate'; import { SwitchAgentSection } from './sections/SwitchAgentSection'; -// If the lastSelectedAgentType is not set, set it to the current selected agent type. -// Eg. If the single agent app was used before, -// the last selected agent should be set to the single agent type -const useSelectAgentTypeIfNotSet = () => { - const { storeState } = useStore(); - const { selectedAgentType } = useServices(); - const { store } = useElectronApi(); - - useEffect(() => { - if (!store?.set) return; - if (!storeState) return; - if (!selectedAgentType) return; - if (storeState.lastSelectedAgentType === selectedAgentType) return; - - store.set('lastSelectedAgentType', selectedAgentType); - }, [store, storeState, selectedAgentType]); -}; - export const Main = () => { - useSelectAgentTypeIfNotSet(); - const isStakingContractSectionEnabled = useFeatureFlag( 'staking-contract-section', ); diff --git a/frontend/context/StakingContractDetailsProvider.tsx b/frontend/context/StakingContractDetailsProvider.tsx index 1804f40dd..e259efeaa 100644 --- a/frontend/context/StakingContractDetailsProvider.tsx +++ b/frontend/context/StakingContractDetailsProvider.tsx @@ -30,18 +30,18 @@ import { StakingProgramContext } from './StakingProgramProvider'; const useAllStakingContractDetails = () => { const { allStakingProgramIds } = useStakingProgram(); const { selectedAgentConfig } = useServices(); - const { serviceApi, evmHomeChainId: homeChainId } = selectedAgentConfig; + const { serviceApi, evmHomeChainId } = selectedAgentConfig; const queryResults = useQueries({ queries: allStakingProgramIds.map((programId) => ({ queryKey: REACT_QUERY_KEYS.ALL_STAKING_CONTRACT_DETAILS( - homeChainId, + evmHomeChainId, programId, ), queryFn: async () => await serviceApi.getStakingContractDetails( programId as StakingProgramId, - homeChainId, + evmHomeChainId, ), onError: (error: Error) => { console.error(