Skip to content

Commit

Permalink
Fix lockup date calc
Browse files Browse the repository at this point in the history
  • Loading branch information
mliu committed Nov 4, 2024
1 parent d4756b7 commit 503ded6
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
7 changes: 6 additions & 1 deletion packages/huma-web-shared/src/utils/getLenderLockupDates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -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 (
<WrapperModal title='Auto-Redemption'>
Expand All @@ -51,9 +49,9 @@ export function ApproveAllowance({ poolState }: Props): React.ReactElement {
<Box css={styles.description}>
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)}.
</Box>
<BottomButton variant='contained' onClick={handleNext}>
APPROVE ALLOWANCE
Expand Down

0 comments on commit 503ded6

Please sign in to comment.