@huma-finance/widgets 0.0.61-beta.561 → 0.0.61-beta.565

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@huma-finance/widgets",
3
- "version": "0.0.61-beta.561+c7ff7e3",
3
+ "version": "0.0.61-beta.565+3a0dfd5",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -30,8 +30,8 @@
30
30
  "@ethersproject/experimental": "^5.7.0",
31
31
  "@ethersproject/providers": "^5.6.0",
32
32
  "@ethersproject/units": "^5.6.0",
33
- "@huma-finance/sdk": "^0.0.61-beta.561+c7ff7e3",
34
- "@huma-finance/shared": "^0.0.61-beta.561+c7ff7e3",
33
+ "@huma-finance/sdk": "^0.0.60",
34
+ "@huma-finance/shared": "^0.0.60",
35
35
  "@huma-finance/web-shared": "^0.0.60",
36
36
  "@mui/icons-material": "^5.3.0",
37
37
  "@mui/material": "^5.0.6",
@@ -195,5 +195,5 @@
195
195
  "optionalDependencies": {
196
196
  "encoding": "^0.1.13"
197
197
  },
198
- "gitHead": "c7ff7e3e21c8ff5dd04661fffe36afb0154f4c95"
198
+ "gitHead": "3a0dfd54370829f8df6c4ce29a053b8c2f2e1b16"
199
199
  }
@@ -9,10 +9,11 @@ import {
9
9
  useLPConfigV2,
10
10
  useNextEpochStartTimeV2,
11
11
  } from '@huma-finance/web-shared'
12
+ import { useWeb3React } from '@web3-react/core'
13
+ import dayjs from 'dayjs'
12
14
  import { ethers } from 'ethers'
13
15
  import React, { useEffect, useState } from 'react'
14
16
 
15
- import { useWeb3React } from '@web3-react/core'
16
17
  import { TrancheInfo } from '.'
17
18
  import { useAppDispatch } from '../../../hooks/useRedux'
18
19
  import {
@@ -62,20 +63,18 @@ export function ChooseAmount({
62
63
  useEffect(() => {
63
64
  if (depositRecord && lpConfig && nextEpochStartTime) {
64
65
  const SECONDS_IN_A_DAY = 24 * 60 * 60
65
- if (
66
- nextEpochStartTime <
66
+ const lockupEndTime =
67
67
  depositRecord.lastDepositTime.toNumber() +
68
- lpConfig.withdrawalLockoutPeriodInDays * SECONDS_IN_A_DAY
69
- ) {
68
+ lpConfig.withdrawalLockoutPeriodInDays * SECONDS_IN_A_DAY
69
+ if (nextEpochStartTime < lockupEndTime) {
70
+ const lockupEndTimeDayjs = dayjs.unix(lockupEndTime).date(1)
70
71
  dispatch(setStep(WIDGET_STEP.Error))
71
72
  dispatch(
72
73
  setError({
73
74
  errorReason: 'Redemption too soon',
74
75
  errorMessage: `Your last deposit was on ${timestampToLL(
75
76
  depositRecord!.lastDepositTime.toNumber(),
76
- )}. Depositors need to wait ${
77
- lpConfig!.withdrawalLockoutPeriodInDays
78
- } days before redemption`,
77
+ )}. You can redeem on ${timestampToLL(lockupEndTimeDayjs.unix())}.`,
79
78
  }),
80
79
  )
81
80
  }
@@ -33,17 +33,20 @@ export type TrancheInfo = {
33
33
  * Lend pool add redemption props
34
34
  * @typedef {Object} AddRedemptionPropsV2
35
35
  * @property {POOL_NAME} poolName The name of the pool.
36
+ * @property {POOL_NTrancheTypeAME} tranche The tranche type.
36
37
  * @property {function():void} handleClose Function to notify to close the widget modal when user clicks the 'x' close button.
37
38
  * @property {function((number|undefined)):void|undefined} handleSuccess Optional function to notify that the lending pool withdraw action is successful.
38
39
  */
39
40
  export type AddRedemptionPropsV2 = {
40
41
  poolName: keyof typeof POOL_NAME
42
+ tranche?: TrancheType
41
43
  handleClose: () => void
42
44
  handleSuccess?: (blockNumber?: number) => void
43
45
  }
44
46
 
45
47
  export function AddRedemptionV2({
46
48
  poolName: poolNameStr,
49
+ tranche,
47
50
  handleClose,
48
51
  handleSuccess,
49
52
  }: AddRedemptionPropsV2): React.ReactElement | null {
@@ -80,6 +83,14 @@ export function AddRedemptionV2({
80
83
 
81
84
  useEffect(() => {
82
85
  if (!step && trancheInfoFetched) {
86
+ if (tranche) {
87
+ setTrancheInfo(
88
+ tranche === 'junior' ? juniorTrancheInfo : seniorTrancheInfo,
89
+ )
90
+ dispatch(setStep(WIDGET_STEP.ChooseAmount))
91
+ return
92
+ }
93
+
83
94
  if (juniorTrancheInfo.assets.gt(0) && seniorTrancheInfo.assets.lte(0)) {
84
95
  setTrancheInfo(juniorTrancheInfo)
85
96
  dispatch(setStep(WIDGET_STEP.ChooseAmount))
@@ -96,7 +107,14 @@ export function AddRedemptionV2({
96
107
  dispatch(setStep(WIDGET_STEP.ChooseTranche))
97
108
  }
98
109
  }
99
- }, [dispatch, juniorTrancheInfo, seniorTrancheInfo, step, trancheInfoFetched])
110
+ }, [
111
+ dispatch,
112
+ juniorTrancheInfo,
113
+ seniorTrancheInfo,
114
+ step,
115
+ tranche,
116
+ trancheInfoFetched,
117
+ ])
100
118
 
101
119
  const handleRedeemSuccess = useCallback(
102
120
  (blockNumber: number) => {