Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

redeem #277

Merged
merged 1 commit into from
Aug 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/huma-widget/API.md
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,7 @@ To be used when re-enabling autopay and other pool actions that require allowanc
| Name | Type | Description |
| --- | --- | --- |
| poolName | <code>POOL\_NAME</code> | <p>The name of the pool.</p> |
| tranche | <code>POOL\_NTrancheTypeAME</code> | <p>The tranche type.</p> |
| handleClose | <code>function</code> | <p>Function to notify to close the widget modal when user clicks the 'x' close button.</p> |
| handleSuccess | <code>function</code> | <p>Optional function to notify that the lending pool withdraw action is successful.</p> |

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@ import {
useLPConfigV2,
useNextEpochStartTimeV2,
} from '@huma-finance/web-shared'
import { useWeb3React } from '@web3-react/core'
import dayjs from 'dayjs'
import { ethers } from 'ethers'
import React, { useEffect, useState } from 'react'

import { useWeb3React } from '@web3-react/core'
import { TrancheInfo } from '.'
import { useAppDispatch } from '../../../hooks/useRedux'
import {
Expand Down Expand Up @@ -62,20 +63,18 @@ export function ChooseAmount({
useEffect(() => {
if (depositRecord && lpConfig && nextEpochStartTime) {
const SECONDS_IN_A_DAY = 24 * 60 * 60
if (
nextEpochStartTime <
const lockupEndTime =
depositRecord.lastDepositTime.toNumber() +
lpConfig.withdrawalLockoutPeriodInDays * SECONDS_IN_A_DAY
) {
lpConfig.withdrawalLockoutPeriodInDays * SECONDS_IN_A_DAY
if (nextEpochStartTime < lockupEndTime) {
const lockupEndTimeDayjs = dayjs.unix(lockupEndTime).date(1)
dispatch(setStep(WIDGET_STEP.Error))
dispatch(
setError({
errorReason: 'Redemption too soon',
errorMessage: `Your last deposit was on ${timestampToLL(
depositRecord!.lastDepositTime.toNumber(),
)}. Depositors need to wait ${
lpConfig!.withdrawalLockoutPeriodInDays
} days before redemption`,
)}. You can redeem on ${timestampToLL(lockupEndTimeDayjs.unix())}.`,
}),
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,20 @@ export type TrancheInfo = {
* Lend pool add redemption props
* @typedef {Object} AddRedemptionPropsV2
* @property {POOL_NAME} poolName The name of the pool.
* @property {POOL_NTrancheTypeAME} tranche The tranche type.
* @property {function():void} handleClose Function to notify to close the widget modal when user clicks the 'x' close button.
* @property {function((number|undefined)):void|undefined} handleSuccess Optional function to notify that the lending pool withdraw action is successful.
*/
export type AddRedemptionPropsV2 = {
poolName: keyof typeof POOL_NAME
tranche?: TrancheType
handleClose: () => void
handleSuccess?: (blockNumber?: number) => void
}

export function AddRedemptionV2({
poolName: poolNameStr,
tranche,
handleClose,
handleSuccess,
}: AddRedemptionPropsV2): React.ReactElement | null {
Expand Down Expand Up @@ -80,6 +83,14 @@ export function AddRedemptionV2({

useEffect(() => {
if (!step && trancheInfoFetched) {
if (tranche) {
setTrancheInfo(
tranche === 'junior' ? juniorTrancheInfo : seniorTrancheInfo,
)
dispatch(setStep(WIDGET_STEP.ChooseAmount))
return
}

if (juniorTrancheInfo.assets.gt(0) && seniorTrancheInfo.assets.lte(0)) {
setTrancheInfo(juniorTrancheInfo)
dispatch(setStep(WIDGET_STEP.ChooseAmount))
Expand All @@ -96,7 +107,14 @@ export function AddRedemptionV2({
dispatch(setStep(WIDGET_STEP.ChooseTranche))
}
}
}, [dispatch, juniorTrancheInfo, seniorTrancheInfo, step, trancheInfoFetched])
}, [
dispatch,
juniorTrancheInfo,
seniorTrancheInfo,
step,
tranche,
trancheInfoFetched,
])

const handleRedeemSuccess = useCallback(
(blockNumber: number) => {
Expand Down
Loading