Skip to content

Commit

Permalink
fix (#840)
Browse files Browse the repository at this point in the history
* fix

* better logic for expired

* tweak
  • Loading branch information
bryzettler committed Dec 12, 2024
1 parent e1e7a57 commit 57be157
Showing 1 changed file with 17 additions and 10 deletions.
27 changes: 17 additions & 10 deletions src/features/governance/PositionCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ import React, { useCallback, useMemo, useRef, useState } from 'react'
import { useAsync } from 'react-async-hook'
import { useTranslation } from 'react-i18next'
import { FadeIn, FadeOut } from 'react-native-reanimated'
import { EPOCH_LENGTH } from '@helium/helium-sub-daos-sdk'
import { MessagePreview } from '@features/solana/MessagePreview'
import { useSolana } from '@features/solana/SolanaProvider'
import { useWalletSign } from '@features/solana/WalletSignProvider'
Expand Down Expand Up @@ -126,7 +127,7 @@ export const PositionCard = ({
})
}, [position, unixNow, positions])

const { lockup, hasGenesisMultiplier, votingMint } = position
const { lockup, isDelegated, hasGenesisMultiplier, votingMint } = position
const { info: mintAcc } = useMint(votingMint.mint)
const {
loading: loadingMetadata,
Expand All @@ -139,8 +140,13 @@ export const PositionCard = ({
? t('gov.positions.constant')
: t('gov.positions.decaying')
const hasActiveVotes = position.numActiveVotes > 0
const lockupExpired =
!isConstant && lockup.endTs.sub(new BN(unixNow || 0)).lt(new BN(0))
const decayedEpoch = lockup.endTs.div(new BN(EPOCH_LENGTH))
const currentEpoch = new BN(unixNow).div(new BN(EPOCH_LENGTH))
const isDecayed =
!isConstant &&
(isDelegated
? currentEpoch.gt(decayedEpoch)
: lockup.endTs.lte(new BN(unixNow)))

const lockedTokens =
mintAcc && humanReadable(position.amountDepositedNative, mintAcc.decimals)
Expand Down Expand Up @@ -584,7 +590,7 @@ export const PositionCard = ({
)
return (
<>
{position.isDelegated ? (
{isDelegated ? (
<>
<ListItem
key="undelegate"
Expand All @@ -600,7 +606,7 @@ export const PositionCard = ({
</>
) : (
<>
{lockupExpired ? (
{isDecayed ? (
<ListItem
key="close"
title={t('gov.positions.close')}
Expand Down Expand Up @@ -691,7 +697,7 @@ export const PositionCard = ({
/>
</>
)}
{canDelegate && !position.isDelegated && (
{canDelegate && !isDelegated && (
<ListItem
key="delegate"
title={t('gov.positions.delegate')}
Expand Down Expand Up @@ -879,11 +885,12 @@ export const PositionCard = ({
</Text>
<Text variant="textSmRegular" color="primaryText">
{isConstant
? getMinDurationFmt(
position.lockup.startTs,
position.lockup.endTs,
? getMinDurationFmt(lockup.startTs, lockup.endTs)
: isDelegated
? getTimeLeftFromNowFmt(
lockup.endTs.add(new BN(EPOCH_LENGTH)),
)
: getTimeLeftFromNowFmt(position.lockup.endTs)}
: getTimeLeftFromNowFmt(lockup.endTs)}
</Text>
</Box>
{hasGenesisMultiplier && (
Expand Down

0 comments on commit 57be157

Please sign in to comment.