diff --git a/frontend/components/MainPage/index.tsx b/frontend/components/MainPage/index.tsx index f97acf159..d2702d794 100644 --- a/frontend/components/MainPage/index.tsx +++ b/frontend/components/MainPage/index.tsx @@ -17,6 +17,7 @@ import { MainNeedsFunds } from './sections/NeedsFundsSection'; import { NewStakingProgramAlertSection } from './sections/NewStakingProgramAlertSection'; import { MainOlasBalance } from './sections/OlasBalanceSection'; import { MainRewards } from './sections/RewardsSection'; +import { StakingContractUpdate } from './sections/stakingContractUpdate'; export const Main = () => { const { goto } = usePageState(); @@ -59,6 +60,7 @@ export const Main = () => { + diff --git a/frontend/components/MainPage/sections/StakingContractUpdate.tsx b/frontend/components/MainPage/sections/StakingContractUpdate.tsx new file mode 100644 index 000000000..764eb22e2 --- /dev/null +++ b/frontend/components/MainPage/sections/StakingContractUpdate.tsx @@ -0,0 +1,49 @@ +import { RightOutlined } from '@ant-design/icons'; +import { Button, Flex, Skeleton, Typography } from 'antd'; + +import { Pages } from '@/enums/PageState'; +import { usePageState } from '@/hooks/usePageState'; +import { useStakingProgram } from '@/hooks/useStakingProgram'; + +import { CardSection } from '../../styled/CardSection'; + +const { Text } = Typography; + +export const StakingContractUpdate = () => { + const { goto } = usePageState(); + const { activeStakingProgramMeta, isLoadedActiveStakingProgram } = + useStakingProgram(); + + return ( + + + Staking contract + + {isLoadedActiveStakingProgram ? ( + + ) : ( + + )} + + + ); +}; diff --git a/frontend/components/ManageStakingPage/StakingContractSection/StakingContractTag.tsx b/frontend/components/ManageStakingPage/StakingContractSection/StakingContractTag.tsx index b09c11a05..0b6569fe4 100644 --- a/frontend/components/ManageStakingPage/StakingContractSection/StakingContractTag.tsx +++ b/frontend/components/ManageStakingPage/StakingContractSection/StakingContractTag.tsx @@ -10,7 +10,7 @@ export const StakingContractTag = ({ if (status === StakingProgramStatus.New) { return New; } else if (status === StakingProgramStatus.Selected) { - return Selected; + return Active; } return null; }; diff --git a/frontend/components/ManageStakingPage/StakingContractSection/index.tsx b/frontend/components/ManageStakingPage/StakingContractSection/index.tsx index 801b4557e..d49298595 100644 --- a/frontend/components/ManageStakingPage/StakingContractSection/index.tsx +++ b/frontend/components/ManageStakingPage/StakingContractSection/index.tsx @@ -23,7 +23,7 @@ import { getMinimumStakedAmountRequired } from '@/utils/service'; import { AlertInsufficientMigrationFunds, AlertNoSlots } from './alerts'; import { StakingContractTag } from './StakingContractTag'; -// const { Text } = Typography; +const { Title } = Typography; const { useToken } = theme; @@ -94,22 +94,24 @@ export const StakingContractSection = ({ [serviceTemplate, stakingProgram], ); + // Check if there are enough OLAS to migrate const hasEnoughOlasToMigrate = useMemo(() => { if (safeBalance?.OLAS === undefined || totalOlasStakedBalance === undefined) return false; const balanceForMigration = safeBalance.OLAS + totalOlasStakedBalance; - if (minimumOlasRequiredToMigrate === undefined) return false; return balanceForMigration >= minimumOlasRequiredToMigrate; }, [minimumOlasRequiredToMigrate, safeBalance?.OLAS, totalOlasStakedBalance]); - const hasEnoughSlots = - stakingContractInfoForStakingProgram?.maxNumServices && - stakingContractInfoForStakingProgram?.serviceIds && - stakingContractInfoForStakingProgram?.maxNumServices > - stakingContractInfoForStakingProgram?.serviceIds?.length; + // Check if there are enough SLOTS available + const hasEnoughSlots = useMemo(() => { + if (!stakingContractInfoForStakingProgram) return false; + + const { maxNumServices, serviceIds } = stakingContractInfoForStakingProgram; + return maxNumServices && serviceIds && maxNumServices > serviceIds.length; + }, [stakingContractInfoForStakingProgram]); const activeStakingContractSupportsMigration = !activeStakingProgram || @@ -240,6 +242,14 @@ export const StakingContractSection = ({ return; }, [activeStakingProgram, defaultStakingProgram, stakingProgram]); + const cardStyle = useMemo(() => { + if (isSelected || !activeStakingProgram) { + return { background: token.colorPrimaryBg }; + } + return {}; + }, [isSelected, activeStakingProgram, token.colorPrimaryBg]); + + // If the staking program is deprecated, don't render the section if (STAKING_PROGRAM_META[stakingProgram].deprecated) { return null; } @@ -247,27 +257,21 @@ export const StakingContractSection = ({ return ( <> - {/* Title */} - {`${stakingProgramMeta?.name} contract`} + >{`${stakingProgramMeta?.name} contract`} {/* TODO: redisplay once bugs resolved */} - {/* {stakingContractInfo?.availableRewards && ( )} */} + {activeStakingContractSupportsMigration && cantMigrateAlert} + {/* Switch to program button */} {![activeStakingProgram, defaultStakingProgram].includes( stakingProgram, @@ -322,10 +328,12 @@ export const StakingContractSection = ({ } }} > - Switch + Switch and run agent )} + + {/* show funding address */} {!isSelected && activeStakingContractSupportsMigration && !hasEnoughOlasToMigrate && ( diff --git a/frontend/components/SettingsPage/SettingsStakingContractSection.tsx b/frontend/components/SettingsPage/SettingsStakingContractSection.tsx deleted file mode 100644 index 121b36476..000000000 --- a/frontend/components/SettingsPage/SettingsStakingContractSection.tsx +++ /dev/null @@ -1,58 +0,0 @@ -import { Button, Flex, Skeleton, Typography } from 'antd'; - -import { Chain } from '@/client'; -import { SERVICE_STAKING_TOKEN_MECH_USAGE_CONTRACT_ADDRESSES } from '@/constants/contractAddresses'; -import { UNICODE_SYMBOLS } from '@/constants/symbols'; -import { Pages } from '@/enums/PageState'; -import { usePageState } from '@/hooks/usePageState'; -import { useStakingProgram } from '@/hooks/useStakingProgram'; - -import { CardSection } from '../styled/CardSection'; - -const { Text } = Typography; - -export const SettingsStakingContractSection = () => { - const { goto } = usePageState(); - const { - activeStakingProgram, - activeStakingProgramMeta, - defaultStakingProgram, - isLoadedActiveStakingProgram, - } = useStakingProgram(); - - const stakingContractAddress = - SERVICE_STAKING_TOKEN_MECH_USAGE_CONTRACT_ADDRESSES[Chain.GNOSIS][ - activeStakingProgram ?? defaultStakingProgram - ]; - - if (!isLoadedActiveStakingProgram) { - return ; - } - - return ( - - Staking contract - - - {activeStakingProgramMeta - ? activeStakingProgramMeta.name - : 'Not staked'} - - - Contract details {UNICODE_SYMBOLS.EXTERNAL_LINK} - - - - - ); -}; diff --git a/frontend/components/SettingsPage/index.tsx b/frontend/components/SettingsPage/index.tsx index 3170d1e54..9a87a50b9 100644 --- a/frontend/components/SettingsPage/index.tsx +++ b/frontend/components/SettingsPage/index.tsx @@ -16,7 +16,6 @@ import { CardTitle } from '../Card/CardTitle'; import { CardSection } from '../styled/CardSection'; import { AddBackupWalletPage } from './AddBackupWalletPage'; import { DebugInfoSection } from './DebugInfoSection'; -import { SettingsStakingContractSection } from './SettingsStakingContractSection'; const { Text, Paragraph } = Typography; @@ -76,6 +75,7 @@ const SettingsMain = () => { ******** + {/* Wallet backup */} Backup wallet @@ -91,8 +91,7 @@ const SettingsMain = () => { )} - {/* Staking contract section */} - + {/* Debug info */}