@huma-finance/widgets 0.0.51-beta.346 → 0.0.51-beta.347
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/dist/cjs/index.cjs +34 -1
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/index.js +35 -2
- package/dist/index.js.map +1 -1
- package/package.json +4 -4
- package/src/components/Lend/addRedemptionV2/2-ChooseAmount.tsx +54 -2
- package/src/components/Lend/addRedemptionV2/index.tsx +1 -0
- package/src/components/Lend/supplyV2/3-ChooseAmount.tsx +11 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@huma-finance/widgets",
|
|
3
|
-
"version": "0.0.51-beta.
|
|
3
|
+
"version": "0.0.51-beta.347+91129f3",
|
|
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.51-beta.
|
|
34
|
-
"@huma-finance/shared": "^0.0.51-beta.
|
|
33
|
+
"@huma-finance/sdk": "^0.0.51-beta.347+91129f3",
|
|
34
|
+
"@huma-finance/shared": "^0.0.51-beta.347+91129f3",
|
|
35
35
|
"@mui/icons-material": "^5.3.0",
|
|
36
36
|
"@mui/material": "^5.0.6",
|
|
37
37
|
"@mui/styles": "^5.0.2",
|
|
@@ -193,5 +193,5 @@
|
|
|
193
193
|
"optionalDependencies": {
|
|
194
194
|
"encoding": "^0.1.13"
|
|
195
195
|
},
|
|
196
|
-
"gitHead": "
|
|
196
|
+
"gitHead": "91129f368c265e7b589b93b13a110770151d10c5"
|
|
197
197
|
}
|
|
@@ -1,28 +1,42 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
formatNumber,
|
|
3
|
+
PoolInfoV2,
|
|
4
|
+
timestampToLL,
|
|
5
|
+
UnderlyingTokenInfo,
|
|
6
|
+
useLenderDepositRecordV2,
|
|
7
|
+
useLPConfigV2,
|
|
8
|
+
useNextEpochStartTimeV2,
|
|
9
|
+
} from '@huma-finance/shared'
|
|
2
10
|
import { ethers } from 'ethers'
|
|
3
|
-
import React, { useState } from 'react'
|
|
11
|
+
import React, { useEffect, useState } from 'react'
|
|
4
12
|
|
|
13
|
+
import { useWeb3React } from '@web3-react/core'
|
|
5
14
|
import { TrancheInfo } from '.'
|
|
6
15
|
import { useAppDispatch } from '../../../hooks/useRedux'
|
|
7
16
|
import {
|
|
17
|
+
setError,
|
|
8
18
|
setRedeemAmount,
|
|
9
19
|
setRedeemShares,
|
|
10
20
|
setStep,
|
|
11
21
|
} from '../../../store/widgets.reducers'
|
|
12
22
|
import { WIDGET_STEP } from '../../../store/widgets.store'
|
|
13
23
|
import { InputAmountModal } from '../../InputAmountModal'
|
|
24
|
+
import { LoadingModal } from '../../LoadingModal'
|
|
14
25
|
|
|
15
26
|
type Props = {
|
|
27
|
+
poolInfo: PoolInfoV2
|
|
16
28
|
poolUnderlyingToken: UnderlyingTokenInfo
|
|
17
29
|
trancheInfo: TrancheInfo
|
|
18
30
|
}
|
|
19
31
|
|
|
20
32
|
export function ChooseAmount({
|
|
33
|
+
poolInfo,
|
|
21
34
|
poolUnderlyingToken,
|
|
22
35
|
trancheInfo,
|
|
23
36
|
}: Props): React.ReactElement | null {
|
|
24
37
|
const dispatch = useAppDispatch()
|
|
25
38
|
const { symbol } = poolUnderlyingToken
|
|
39
|
+
const { account, provider } = useWeb3React()
|
|
26
40
|
const [currentAmount, setCurrentAmount] = useState<number>(0)
|
|
27
41
|
const [currentShares, setCurrentShares] = useState<number>(0)
|
|
28
42
|
const maxSharesFormatted = ethers.utils.formatUnits(
|
|
@@ -31,6 +45,40 @@ export function ChooseAmount({
|
|
|
31
45
|
)
|
|
32
46
|
const sharePrice =
|
|
33
47
|
trancheInfo.assets.toNumber() / trancheInfo.shares.toNumber()
|
|
48
|
+
const [depositRecord] = useLenderDepositRecordV2(
|
|
49
|
+
poolInfo.poolName,
|
|
50
|
+
trancheInfo.tranche,
|
|
51
|
+
account,
|
|
52
|
+
provider,
|
|
53
|
+
)
|
|
54
|
+
const lpConfig = useLPConfigV2(poolInfo.poolName, provider)
|
|
55
|
+
const nextEpochStartTime = useNextEpochStartTimeV2(
|
|
56
|
+
poolInfo.poolName,
|
|
57
|
+
provider,
|
|
58
|
+
)
|
|
59
|
+
|
|
60
|
+
useEffect(() => {
|
|
61
|
+
if (depositRecord && lpConfig && nextEpochStartTime) {
|
|
62
|
+
const SECONDS_IN_A_DAY = 24 * 60 * 60
|
|
63
|
+
if (
|
|
64
|
+
nextEpochStartTime <
|
|
65
|
+
depositRecord.lastDepositTime.toNumber() +
|
|
66
|
+
lpConfig.withdrawalLockoutPeriodInDays * SECONDS_IN_A_DAY
|
|
67
|
+
) {
|
|
68
|
+
dispatch(setStep(WIDGET_STEP.Error))
|
|
69
|
+
dispatch(
|
|
70
|
+
setError({
|
|
71
|
+
errorReason: 'Redemption too soon',
|
|
72
|
+
errorMessage: `Your last deposit was on ${timestampToLL(
|
|
73
|
+
depositRecord!.lastDepositTime.toNumber(),
|
|
74
|
+
)}. Depositors need to wait ${
|
|
75
|
+
lpConfig!.withdrawalLockoutPeriodInDays
|
|
76
|
+
} days before redemption`,
|
|
77
|
+
}),
|
|
78
|
+
)
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}, [depositRecord, dispatch, lpConfig, nextEpochStartTime])
|
|
34
82
|
|
|
35
83
|
const handleChangeShares = (newShares: number) => {
|
|
36
84
|
const amount = Number(newShares) * sharePrice
|
|
@@ -44,6 +92,10 @@ export function ChooseAmount({
|
|
|
44
92
|
dispatch(setStep(WIDGET_STEP.Transfer))
|
|
45
93
|
}
|
|
46
94
|
|
|
95
|
+
if (!depositRecord || !lpConfig || !nextEpochStartTime) {
|
|
96
|
+
return <LoadingModal title='Redemption' />
|
|
97
|
+
}
|
|
98
|
+
|
|
47
99
|
return (
|
|
48
100
|
<InputAmountModal
|
|
49
101
|
title='Redemption'
|
|
@@ -3,6 +3,7 @@ import {
|
|
|
3
3
|
TrancheType,
|
|
4
4
|
UnderlyingTokenInfo,
|
|
5
5
|
formatNumber,
|
|
6
|
+
useLPConfigV2,
|
|
6
7
|
usePoolSafeAllowanceV2,
|
|
7
8
|
usePoolUnderlyingTokenBalanceV2,
|
|
8
9
|
} from '@huma-finance/shared'
|
|
@@ -14,6 +15,7 @@ import { useAppDispatch } from '../../../hooks/useRedux'
|
|
|
14
15
|
import { setStep, setSupplyAmount } from '../../../store/widgets.reducers'
|
|
15
16
|
import { WIDGET_STEP } from '../../../store/widgets.store'
|
|
16
17
|
import { InputAmountModal } from '../../InputAmountModal'
|
|
18
|
+
import { LoadingModal } from '../../LoadingModal'
|
|
17
19
|
|
|
18
20
|
type Props = {
|
|
19
21
|
poolInfo: PoolInfoV2
|
|
@@ -44,6 +46,8 @@ export function ChooseAmount({
|
|
|
44
46
|
balance,
|
|
45
47
|
poolUnderlyingToken.decimals,
|
|
46
48
|
)
|
|
49
|
+
const lpConfig = useLPConfigV2(poolInfo.poolName, provider)
|
|
50
|
+
const isUniTranche = lpConfig?.maxSeniorJuniorRatio === 0
|
|
47
51
|
|
|
48
52
|
const handleChangeAmount = (newAmount: number) => {
|
|
49
53
|
setCurrentAmount(newAmount)
|
|
@@ -61,10 +65,16 @@ export function ChooseAmount({
|
|
|
61
65
|
dispatch(setStep(step))
|
|
62
66
|
}
|
|
63
67
|
|
|
68
|
+
if (!lpConfig) {
|
|
69
|
+
return <LoadingModal title='Supply' />
|
|
70
|
+
}
|
|
71
|
+
|
|
64
72
|
return (
|
|
65
73
|
<InputAmountModal
|
|
66
74
|
title='Enter Amount'
|
|
67
|
-
subTitle={`Supplying ${symbol} with ${
|
|
75
|
+
subTitle={`Supplying ${symbol} with ${
|
|
76
|
+
isUniTranche ? 'uni tranche' : selectedTranche
|
|
77
|
+
}`}
|
|
68
78
|
tokenSymbol={symbol}
|
|
69
79
|
currentAmount={currentAmount}
|
|
70
80
|
handleChangeAmount={handleChangeAmount}
|