diff --git a/apps/staking/src/api.ts b/apps/staking/src/api.ts index 3e4d4084fe..96982baa0f 100644 --- a/apps/staking/src/api.ts +++ b/apps/staking/src/api.ts @@ -54,7 +54,7 @@ type Data = { integrityStakingPublishers: { name: string | undefined; publicKey: PublicKey; - isSelf: boolean; + stakeAccount: PublicKey | undefined; selfStake: bigint; poolCapacity: bigint; poolUtilization: bigint; @@ -184,12 +184,7 @@ const loadDataNoStakeAccount = async ( cooldown2: 0n, }, unlockSchedule: [], - integrityStakingPublishers: publishers.map( - ({ stakeAccount, ...publisher }) => ({ - ...publisher, - isSelf: false, - }), - ), + integrityStakingPublishers: publishers, }; }; @@ -242,27 +237,21 @@ const loadDataForStakeAccount = async ( cooldown2: filterGovernancePositions(PositionState.UNLOCKED), }, unlockSchedule, - integrityStakingPublishers: publishers.map( - ({ stakeAccount: publisherStakeAccount, ...publisher }) => ({ - ...publisher, - isSelf: publisherStakeAccount?.equals(stakeAccount.address) ?? false, - positions: { - warmup: filterOISPositions( - publisher.publicKey, - PositionState.LOCKING, - ), - staked: filterOISPositions(publisher.publicKey, PositionState.LOCKED), - cooldown: filterOISPositions( - publisher.publicKey, - PositionState.PREUNLOCKING, - ), - cooldown2: filterOISPositions( - publisher.publicKey, - PositionState.UNLOCKED, - ), - }, - }), - ), + integrityStakingPublishers: publishers.map((publisher) => ({ + ...publisher, + positions: { + warmup: filterOISPositions(publisher.publicKey, PositionState.LOCKING), + staked: filterOISPositions(publisher.publicKey, PositionState.LOCKED), + cooldown: filterOISPositions( + publisher.publicKey, + PositionState.PREUNLOCKING, + ), + cooldown2: filterOISPositions( + publisher.publicKey, + PositionState.UNLOCKED, + ), + }, + })), }; }; @@ -312,7 +301,7 @@ const loadPublisherData = async ( publicKey: publisher.pubkey, qualityRanking: publisherRanking?.rank ?? 0, selfStake: publisher.selfDelegation, - stakeAccount: publisher.stakeAccount, + stakeAccount: publisher.stakeAccount ?? undefined, }; }); }; diff --git a/apps/staking/src/components/OracleIntegrityStaking/index.tsx b/apps/staking/src/components/OracleIntegrityStaking/index.tsx index ba422aeeba..d73ff30bae 100644 --- a/apps/staking/src/components/OracleIntegrityStaking/index.tsx +++ b/apps/staking/src/components/OracleIntegrityStaking/index.tsx @@ -71,18 +71,20 @@ export const OracleIntegrityStaking = ({ yieldRate, }: Props) => { const self = useMemo( - () => publishers.find((publisher) => publisher.isSelf), - [publishers], + () => + api.type === ApiStateType.Loaded && + publishers.find((publisher) => + publisher.stakeAccount?.equals(api.account.address), + ), + [publishers, api], ); const otherPublishers = useMemo( () => - publishers.filter( - (publisher) => - !publisher.isSelf && - (publisher.poolCapacity > 0n || hasAnyPositions(publisher)), - ), - [publishers], + self === undefined + ? publishers + : publishers.filter((publisher) => publisher !== self), + [publishers, self], ); return ( @@ -697,11 +699,11 @@ type PublisherProps = { currentEpoch: bigint; availableToStake: bigint; totalStaked: bigint; - isSelf?: boolean; + isSelf?: boolean | undefined; publisher: { name: string | undefined; publicKey: PublicKey; - isSelf: boolean; + stakeAccount: PublicKey | undefined; selfStake: bigint; poolCapacity: bigint; poolUtilization: bigint; @@ -817,7 +819,7 @@ const Publisher = ({
{calculateApy({ - isSelf: publisher.isSelf, + isSelf: isSelf ?? false, selfStake: publisher.selfStake, poolCapacity: publisher.poolCapacity, poolUtilization: publisher.poolUtilization, @@ -851,6 +853,7 @@ const Publisher = ({ availableToStake={availableToStake} publisher={publisher} yieldRate={yieldRate} + isSelf={isSelf ?? false} /> @@ -950,6 +953,7 @@ type StakeToPublisherButtonProps = { currentEpoch: bigint; availableToStake: bigint; yieldRate: bigint; + isSelf: boolean; }; const StakeToPublisherButton = ({ @@ -958,6 +962,7 @@ const StakeToPublisherButton = ({ availableToStake, publisher, yieldRate, + isSelf, }: StakeToPublisherButtonProps) => { const delegate = useTransferActionForPublisher( api.type === ApiStateType.Loaded ? api.delegateIntegrityStaking : undefined, @@ -981,27 +986,14 @@ const StakeToPublisherButton = ({ <>
APY after staking
-
- {publisher.isSelf - ? calculateApy({ - isSelf: publisher.isSelf, - selfStake: - publisher.selfStake + - (amount.type === AmountType.Valid ? amount.amount : 0n), - poolCapacity: publisher.poolCapacity, - yieldRate, - }) - : calculateApy({ - isSelf: publisher.isSelf, - selfStake: publisher.selfStake, - poolCapacity: publisher.poolCapacity, - poolUtilization: - publisher.poolUtilization + - (amount.type === AmountType.Valid ? amount.amount : 0n), - yieldRate, - })} - % -
+ + {amount.type === AmountType.Valid ? amount.amount : 0n} +
@@ -1010,6 +1002,49 @@ const StakeToPublisherButton = ({ ); }; +type NewApyProps = Omit, "children"> & { + isSelf: boolean; + publisher: PublisherProps["publisher"]; + yieldRate: bigint; + children: bigint; +}; + +const NewApy = ({ + isSelf, + publisher, + yieldRate, + children, + ...props +}: NewApyProps) => { + const apy = useMemo( + () => + calculateApy({ + poolCapacity: publisher.poolCapacity, + yieldRate, + ...(isSelf + ? { + isSelf: true, + selfStake: publisher.selfStake + children, + } + : { + isSelf: false, + selfStake: publisher.selfStake, + poolUtilization: publisher.poolUtilization + children, + }), + }), + [ + publisher.poolCapacity, + yieldRate, + isSelf, + publisher.selfStake, + publisher.poolUtilization, + children, + ], + ); + + return
{apy}%
; +}; + type PublisherNameProps = Omit, "children"> & { children: PublisherProps["publisher"]; fullKey?: boolean | undefined;