Skip to content

Commit

Permalink
feat: set default last selected agent type to 'trader' and clean up u…
Browse files Browse the repository at this point in the history
…nused code in MainPage component
  • Loading branch information
mohandast52 committed Dec 5, 2024
1 parent a812cc6 commit 0b9b197
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 28 deletions.
2 changes: 1 addition & 1 deletion electron/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const schema = {
currentStakingProgram: { type: 'string', default: '' },

// agent settings
lastSelectedAgentType: { type: 'string', default: '' },
lastSelectedAgentType: { type: 'string', default: 'trader' },
};

/**
Expand Down
24 changes: 0 additions & 24 deletions frontend/components/MainPage/index.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@
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 {
useStakingContractContext,
useStakingContractDetails,
} from '@/hooks/useStakingContractDetails';
import { useStakingProgram } from '@/hooks/useStakingProgram';
import { useStore } from '@/hooks/useStore';

// import { useMasterWalletContext } from '@/hooks/useWallet';
import { MainHeader } from './header';
Expand All @@ -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',
);
Expand Down
6 changes: 3 additions & 3 deletions frontend/context/StakingContractDetailsProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit 0b9b197

Please sign in to comment.