diff --git a/src/components/PositionManager/PositionCallout.tsx b/src/components/PositionManager/PositionCallout.tsx index efd354c..86c840a 100644 --- a/src/components/PositionManager/PositionCallout.tsx +++ b/src/components/PositionManager/PositionCallout.tsx @@ -1,6 +1,7 @@ "use client"; import { + EPOCH_LENGTH, getMinDurationFmt, getPositionVoteMultiplier, getTimeLeftFromNowFmt, @@ -32,14 +33,22 @@ export const PositionCallout: FC<{ setManagerAction, handleClaimRewards, }) => { - const { lockup, hasGenesisMultiplier } = position; + const { lockup, isDelegated, hasGenesisMultiplier } = position; const { loading: loadingGov, network, mintAcc, subDaos } = useGovernance(); const unixNow = useSolanaUnixNow() || Date.now() / 1000; const lockupKind = Object.keys(lockup.kind)[0] as string; const isConstant = lockupKind === "constant"; - const isDecayed = !isConstant && lockup.endTs.lte(new BN(unixNow)); + 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 elapsedTime = new BN(unixNow).sub(lockup.startTs); - const totalTime = lockup.endTs.sub(lockup.startTs); + const totalTime = isDelegated + ? decayedEpoch.add(new BN(1)).mul(new BN(EPOCH_LENGTH)).sub(lockup.startTs) + : lockup.endTs.sub(lockup.startTs); const decayedPercentage = elapsedTime.muln(100).div(totalTime); const canDelegate = network === "hnt"; @@ -93,11 +102,10 @@ export const PositionCallout: FC<{

{isConstant - ? getMinDurationFmt( - position.lockup.startTs, - position.lockup.endTs - ) - : getTimeLeftFromNowFmt(position.lockup.endTs)}{" "} + ? getMinDurationFmt(lockup.startTs, lockup.endTs) + : isDelegated + ? getTimeLeftFromNowFmt(lockup.endTs.add(new BN(EPOCH_LENGTH))) + : getTimeLeftFromNowFmt(lockup.endTs)}{" "} time left

diff --git a/src/components/PositionManager/PositionManager.tsx b/src/components/PositionManager/PositionManager.tsx index 1b8c8e2..9de26ca 100644 --- a/src/components/PositionManager/PositionManager.tsx +++ b/src/components/PositionManager/PositionManager.tsx @@ -1,6 +1,6 @@ "use client"; -import { onInstructions, secsToDays } from "@/lib/utils"; +import { EPOCH_LENGTH, onInstructions, secsToDays } from "@/lib/utils"; import { useGovernance } from "@/providers/GovernanceProvider"; import { useAnchorProvider, @@ -97,6 +97,7 @@ export const PositionManager: FC = ({ position, initAction, }) => { + const unixNow = useSolanaUnixNow() || Date.now() / 1000; const [action, setAction] = useState(initAction); const provider = useAnchorProvider(); const { @@ -107,11 +108,15 @@ export const PositionManager: FC = ({ refetch: refetchState, } = useGovernance(); const router = useRouter(); - const { lockup } = position; - + const { lockup, isDelegated } = position; const isConstant = Object.keys(lockup.kind)[0] === "constant"; - const unixNow = useSolanaUnixNow() || Date.now() / 1000; - const isDecayed = !isConstant && lockup.endTs.lte(new BN(unixNow)); + 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 canDelegate = network === "hnt"; const mergablePositions: PositionWithMeta[] = useMemo(() => { if (!unixNow || !positions || !positions.length) { @@ -187,7 +192,7 @@ export const PositionManager: FC = ({ await unassignProxies({ positions: [position], onInstructions: onInstructions(provider, { - useFirstEstimateForAll: true + useFirstEstimateForAll: true, }), }); } else { @@ -196,7 +201,7 @@ export const PositionManager: FC = ({ recipient: new PublicKey(proxy || ""), expirationTime: new BN(expirationTime || 0), onInstructions: onInstructions(provider, { - useFirstEstimateForAll: true + useFirstEstimateForAll: true, }), }); } diff --git a/src/lib/utils.ts b/src/lib/utils.ts index 4f265b9..0cc1eb6 100644 --- a/src/lib/utils.ts +++ b/src/lib/utils.ts @@ -315,7 +315,7 @@ export const onInstructions = : HELIUM_COMMON_LUT, ], useFirstEstimateForAll, - computeScaleUp: useFirstEstimateForAll ? 1.4 : 1.1 + computeScaleUp: useFirstEstimateForAll ? 1.4 : 1.1, } ); const asVersionedTx = transactions.map(toVersionedTx); @@ -413,3 +413,5 @@ export function debounce( }); }; } + +export const EPOCH_LENGTH = 60 * 60 * 24;