Skip to content

Commit

Permalink
feat: address Josh review changes
Browse files Browse the repository at this point in the history
  • Loading branch information
mohandast52 committed Sep 6, 2024
1 parent 7a7e485 commit f36c8f2
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { InfoBreakdownList } from '@/components/InfoBreakdown';
import { StakingProgram } from '@/enums/StakingProgram';
import { useStakingContractInfo } from '@/hooks/useStakingContractInfo';

export const StakingContractInfo = ({ name }: { name: StakingProgram }) => {
export const StakingContractDetails = ({ name }: { name: StakingProgram }) => {
const { stakingContractInfoRecord } = useStakingContractInfo();

const balances = useMemo(() => {
Expand All @@ -25,7 +25,7 @@ export const StakingContractInfo = ({ name }: { name: StakingProgram }) => {
},
{
left: 'Required OLAS for staking',
right: `${details.stakeRequired} OLAS`,
right: `${details.olasStakeRequired} OLAS`,
},
];
}, [stakingContractInfoRecord, name]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import { ServicesService } from '@/service/Services';
import { getMinimumStakedAmountRequired } from '@/utils/service';

import { AlertInsufficientMigrationFunds, AlertNoSlots } from './alerts';
import { StakingContractInfo } from './StakingContractInfo';
import { StakingContractDetails } from './StakingContractDetails';
import { StakingContractTag } from './StakingContractTag';

const { Title } = Typography;
Expand Down Expand Up @@ -244,7 +244,7 @@ export const StakingContractSection = ({
<StakingContractTag status={contractTagStatus} />
</Flex>

<StakingContractInfo name={stakingProgram} />
<StakingContractDetails name={stakingProgram} />
<a
href={`https://gnosisscan.io/address/${stakingContractAddress}`}
target="_blank"
Expand Down
11 changes: 5 additions & 6 deletions frontend/components/ManageStakingPage/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,11 @@ export const ManageStakingPage = () => {
return [...acc, stakingProgram];
}, []);

const activeStakingContract = orderedStakingPrograms[0];
const otherStakingContracts = orderedStakingPrograms.filter(
const otherStakingPrograms = orderedStakingPrograms.filter(
(stakingProgram) => {
const info = STAKING_PROGRAM_META[stakingProgram];
if (!info) return false;
if (activeStakingContract === stakingProgram) return false;
if (activeStakingProgram === stakingProgram) return false;
if (info.deprecated) return false;
return true;
},
Expand All @@ -52,13 +51,13 @@ export const ManageStakingPage = () => {
}
>
<WhatAreStakingContractsSection />
<StakingContractSection stakingProgram={activeStakingContract} />
<StakingContractSection stakingProgram={orderedStakingPrograms[0]} />

<CardSection borderbottom="true" vertical gap={16}>
{`Browse ${otherStakingContracts.length} staking contract${otherStakingContracts.length > 1 ? 's' : ''}.`}
{`Browse ${otherStakingPrograms.length} staking contract${otherStakingPrograms.length > 1 ? 's' : ''}.`}
</CardSection>

{otherStakingContracts.map((stakingProgram) => (
{otherStakingPrograms.map((stakingProgram) => (
<StakingContractSection
key={stakingProgram}
stakingProgram={stakingProgram}
Expand Down
13 changes: 8 additions & 5 deletions frontend/context/StakingContractInfoProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,18 @@ import { CHAINS } from '@/constants/chains';
import { FIVE_SECONDS_INTERVAL } from '@/constants/intervals';
import { StakingProgram } from '@/enums/StakingProgram';
import { AutonolasService } from '@/service/Autonolas';
import { StakingContractInfo, StakingContractRecord } from '@/types/Autonolas';
import { StakingContractInfo } from '@/types/Autonolas';

import { ServicesContext } from './ServicesProvider';
import { StakingProgramContext } from './StakingProgramContext';

type StakingContractInfoContextProps = {
updateActiveStakingContractInfo: () => Promise<void>;
activeStakingContractInfo?: StakingContractInfo;
stakingContractInfoRecord?: Record<StakingProgram, StakingContractRecord>;
activeStakingContractInfo?: Partial<StakingContractInfo>;
stakingContractInfoRecord?: Record<
StakingProgram,
Partial<StakingContractInfo>
>;
};

export const StakingContractInfoContext =
Expand All @@ -38,10 +41,10 @@ export const StakingContractInfoProvider = ({
const { activeStakingProgram } = useContext(StakingProgramContext);

const [activeStakingContractInfo, setActiveStakingContractInfo] =
useState<StakingContractInfo>();
useState<Partial<StakingContractInfo>>();

const [stakingContractInfoRecord, setStakingContractInfoRecord] =
useState<Record<StakingProgram, StakingContractRecord>>();
useState<Record<StakingProgram, Partial<StakingContractInfo>>>();

const serviceId = useMemo(
() => services?.[0]?.chain_configs[CHAINS.GNOSIS.chainId].chain_data?.token,
Expand Down
14 changes: 5 additions & 9 deletions frontend/service/Autonolas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,7 @@ import { gnosisMulticallProvider } from '@/constants/providers';
import { ServiceRegistryL2ServiceState } from '@/enums/ServiceRegistryL2ServiceState';
import { StakingProgram } from '@/enums/StakingProgram';
import { Address } from '@/types/Address';
import {
StakingContractInfo,
StakingContractRecord,
StakingRewardsInfo,
} from '@/types/Autonolas';
import { StakingContractInfo, StakingRewardsInfo } from '@/types/Autonolas';

const ONE_YEAR = 1 * 24 * 60 * 60 * 365;
const REQUIRED_MECH_REQUESTS_SAFETY_MARGIN = 1;
Expand Down Expand Up @@ -196,7 +192,7 @@ const getAvailableRewardsForEpoch = async (
const getStakingContractInfoByServiceIdStakingProgram = async (
serviceId: number,
stakingProgram: StakingProgram,
): Promise<StakingContractInfo | undefined> => {
): Promise<Partial<StakingContractInfo> | undefined> => {
if (!serviceId) return;

const contractCalls = [
Expand Down Expand Up @@ -249,7 +245,7 @@ const getStakingContractInfoByServiceIdStakingProgram = async (
*/
const getStakingContractInfoByStakingProgram = async (
stakingProgram: StakingProgram,
): Promise<StakingContractRecord> => {
): Promise<Partial<StakingContractInfo>> => {
const contractCalls = [
serviceStakingTokenMechUsageContracts[stakingProgram].availableRewards(),
serviceStakingTokenMechUsageContracts[stakingProgram].maxNumServices(),
Expand Down Expand Up @@ -291,7 +287,7 @@ const getStakingContractInfoByStakingProgram = async (
const stakeRequiredInWei = minStakingDeposit.add(
minStakingDeposit.mul(numAgentInstances),
);
const stakeRequired = Number(formatEther(stakeRequiredInWei));
const olasStakeRequired = Number(formatEther(stakeRequiredInWei));

// Rewards per work period
const rewardsPerWorkPeriod =
Expand All @@ -305,7 +301,7 @@ const getStakingContractInfoByStakingProgram = async (
minimumStakingDuration: minStakingDurationInBN.toNumber(),
minStakingDeposit: parseFloat(ethers.utils.formatEther(minStakingDeposit)),
apy,
stakeRequired,
olasStakeRequired,
rewardsPerWorkPeriod,
};
};
Expand Down
8 changes: 1 addition & 7 deletions frontend/types/Autonolas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,10 @@ export type StakingContractInfo = {
serviceStakingState: number;
/** OLAS cost of staking */
minStakingDeposit: number;
};

export type OtherStakingContractInfo = {
/** annual percentage yield */
apy: number;
/** amount of OLAS required to stake */
stakeRequired: number;
olasStakeRequired: number;
/** rewards per work period */
rewardsPerWorkPeriod: number;
};

export type StakingContractRecord = Partial<StakingContractInfo> &
OtherStakingContractInfo;

0 comments on commit f36c8f2

Please sign in to comment.