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

feat: move the staking contract info to the main screen #315

Merged
merged 6 commits into from
Sep 4, 2024
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
2 changes: 2 additions & 0 deletions frontend/components/MainPage/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -59,6 +60,7 @@ export const Main = () => {
<MainOlasBalance />
<MainRewards />
<KeepAgentRunningSection />
<StakingContractUpdate />
<GasBalanceSection />
<MainNeedsFunds />
<AddFundsSection />
Expand Down
49 changes: 49 additions & 0 deletions frontend/components/MainPage/sections/StakingContractUpdate.tsx
Original file line number Diff line number Diff line change
@@ -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 (
<CardSection bordertop="true" padding="16px 24px">
<Flex
gap={16}
justify="space-between"
align="center"
style={{ width: '100%' }}
>
<Text type="secondary">Staking contract</Text>

{isLoadedActiveStakingProgram ? (
<Button
type="link"
className="p-0"
onClick={() => goto(Pages.ManageStaking)}
>
{activeStakingProgramMeta ? (
<>
{activeStakingProgramMeta.name}
&nbsp;
<RightOutlined />
</>
) : (
'Not staked'
)}
</Button>
) : (
<Skeleton.Input />
)}
</Flex>
</CardSection>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export const StakingContractTag = ({
if (status === StakingProgramStatus.New) {
return <Tag color="blue">New</Tag>;
} else if (status === StakingProgramStatus.Selected) {
return <Tag>Selected</Tag>;
return <Tag color="purple">Active</Tag>;
}
return null;
};
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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 ||
Expand Down Expand Up @@ -240,34 +242,36 @@ 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;
}

return (
<>
<CardSection
style={
isSelected || !activeStakingProgram
? { background: token.colorBgContainerDisabled }
: {}
}
style={cardStyle}
bordertop="true"
borderbottom="true"
vertical
gap={16}
>
{/* Title */}
<Flex gap={12}>
<Typography.Title
<Title
level={5}
className="m-0"
>{`${stakingProgramMeta?.name} contract`}</Typography.Title>
>{`${stakingProgramMeta?.name} contract`}</Title>
<StakingContractTag status={contractTagStatus} />
</Flex>

{/* TODO: redisplay once bugs resolved */}

{/*
{stakingContractInfo?.availableRewards && (
<ContractParameter
Expand All @@ -283,13 +287,15 @@ export const StakingContractSection = ({
/>
)}
*/}

<a
href={`https://gnosisscan.io/address/${stakingContractAddress}`}
target="_blank"
>
View contract details {UNICODE_SYMBOLS.EXTERNAL_LINK}
</a>
{activeStakingContractSupportsMigration && cantMigrateAlert}

{/* Switch to program button */}
{![activeStakingProgram, defaultStakingProgram].includes(
stakingProgram,
Expand Down Expand Up @@ -322,10 +328,12 @@ export const StakingContractSection = ({
}
}}
>
Switch
Switch and run agent
</Button>
</Popover>
)}

{/* show funding address */}
{!isSelected &&
activeStakingContractSupportsMigration &&
!hasEnoughOlasToMigrate && (
Expand Down

This file was deleted.

5 changes: 2 additions & 3 deletions frontend/components/SettingsPage/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -76,6 +75,7 @@ const SettingsMain = () => {
<Text style={{ lineHeight: 1 }}>********</Text>
</Flex>
</CardSection>

{/* Wallet backup */}
<CardSection borderbottom="true" vertical gap={8}>
<Text strong>Backup wallet</Text>
Expand All @@ -91,8 +91,7 @@ const SettingsMain = () => {
<NoBackupWallet />
)}
</CardSection>
{/* Staking contract section */}
<SettingsStakingContractSection />

{/* Debug info */}
<DebugInfoSection />
</Card>
Expand Down
Loading