From 503ded6858225f17f353ba7e6529b2e2f9629ccb Mon Sep 17 00:00:00 2001 From: Michael Liu Date: Mon, 4 Nov 2024 14:17:53 -0500 Subject: [PATCH] Fix lockup date calc --- .../src/utils/getLenderLockupDates.ts | 7 ++++++- .../1-ApproveAllowance.tsx | 14 ++++++-------- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/packages/huma-web-shared/src/utils/getLenderLockupDates.ts b/packages/huma-web-shared/src/utils/getLenderLockupDates.ts index 5faf124e..4e3ddb08 100644 --- a/packages/huma-web-shared/src/utils/getLenderLockupDates.ts +++ b/packages/huma-web-shared/src/utils/getLenderLockupDates.ts @@ -2,11 +2,16 @@ export const getLenderLockupDates = ( withdrawalLockupPeriodDays: number, ): { lockupEndTimeUnix: number; withdrawTimeUnix: number } => { const now = new Date() - const lockupEndTime = new Date(now.getFullYear(), now.getMonth(), 1) + const lockupEndTime = new Date(now) + + // Add withdrawalLockupPeriodDays to the current date lockupEndTime.setDate( lockupEndTime.getDate() + (withdrawalLockupPeriodDays ?? 0), ) + // Set the day of lockupEndTime to the first of that month + lockupEndTime.setDate(1) + // Calculate withdrawTime by adding 1 month to lockupEndTime const withdrawTime = new Date( lockupEndTime.getFullYear(), lockupEndTime.getMonth() + 1, diff --git a/packages/huma-widget/src/components/Lend/solanaEnableAutoRedemption/1-ApproveAllowance.tsx b/packages/huma-widget/src/components/Lend/solanaEnableAutoRedemption/1-ApproveAllowance.tsx index f48e06bc..fc59a943 100644 --- a/packages/huma-widget/src/components/Lend/solanaEnableAutoRedemption/1-ApproveAllowance.tsx +++ b/packages/huma-widget/src/components/Lend/solanaEnableAutoRedemption/1-ApproveAllowance.tsx @@ -1,6 +1,5 @@ import { timeUtil } from '@huma-finance/shared' -import { SolanaPoolState } from '@huma-finance/web-shared' -import dayjs from 'dayjs' +import { getLenderLockupDates, SolanaPoolState } from '@huma-finance/web-shared' import React, { useCallback } from 'react' import { Box, css, useTheme } from '@mui/material' import { useAppDispatch } from '../../../hooks/useRedux' @@ -38,10 +37,9 @@ export function ApproveAllowance({ poolState }: Props): React.ReactElement { `, } - const lockupEndTime = dayjs() - .add(poolState.withdrawalLockupPeriodDays ?? 0, 'day') - .date(1) - const withdrawTime = lockupEndTime.add(1, 'month') + const { lockupEndTimeUnix, withdrawTimeUnix } = getLenderLockupDates( + poolState.withdrawalLockupPeriodDays ?? 0, + ) return ( @@ -51,9 +49,9 @@ export function ApproveAllowance({ poolState }: Props): React.ReactElement { This allowance transaction will enable auto-redemption for your existing tranche shares. Redemption requests will be automatically submitted on{' '} - {timeUtil.timestampToLL(lockupEndTime.unix())}. Your deposit can be + {timeUtil.timestampToLL(lockupEndTimeUnix)}. Your deposit can be redeemed and yield rewards will stop on{' '} - {timeUtil.timestampToLL(withdrawTime.unix())}. + {timeUtil.timestampToLL(withdrawTimeUnix)}. APPROVE ALLOWANCE