@huma-finance/widgets 0.0.48-beta.294 → 0.0.48-beta.297
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/API.md +69 -22
- package/dist/cjs/index.cjs +1991 -1991
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/index.d.ts +45 -14
- package/dist/index.js +1991 -1992
- package/dist/index.js.map +1 -1
- package/package.json +4 -4
- package/src/components/InputAmountModal.tsx +3 -1
- package/src/components/Lend/addRedemptionV2/1-ChooseTranche.tsx +114 -0
- package/src/components/Lend/addRedemptionV2/2-ChooseAmount.tsx +61 -0
- package/src/components/Lend/{redeemV2 → addRedemptionV2}/3-Transfer.tsx +7 -12
- package/src/components/Lend/addRedemptionV2/4-Done.tsx +20 -0
- package/src/components/Lend/addRedemptionV2/index.tsx +172 -0
- package/src/components/Lend/cancelRedemptionV2 /1-Transfer.tsx +51 -0
- package/src/components/Lend/cancelRedemptionV2 /2-Done.tsx +29 -0
- package/src/components/Lend/cancelRedemptionV2 /index.tsx +120 -0
- package/src/components/Lend/withdrawV2/1-ConfirmTransfer.tsx +131 -0
- package/src/components/Lend/withdrawV2/2-Transfer.tsx +3 -3
- package/src/components/Lend/withdrawV2/index.tsx +51 -45
- package/src/index.tsx +44 -15
- package/src/components/Lend/redeemV2/1-ChooseAction.tsx +0 -237
- package/src/components/Lend/redeemV2/2-ChooseAmount.tsx +0 -101
- package/src/components/Lend/redeemV2/4-Done.tsx +0 -33
- package/src/components/Lend/redeemV2/index.tsx +0 -207
- package/src/components/Lend/withdrawV2/1-ChooseTranche.tsx +0 -201
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import {
|
|
2
|
+
PoolInfoV2,
|
|
3
|
+
TrancheRedemptionStatus,
|
|
4
|
+
TrancheType,
|
|
5
|
+
UnderlyingTokenInfo,
|
|
6
|
+
formatAmount,
|
|
7
|
+
getTrancheVaultContractV2,
|
|
8
|
+
} from '@huma-finance/shared'
|
|
9
|
+
import { Box, Divider, css, useTheme } from '@mui/material'
|
|
10
|
+
import React, { useEffect, useState } from 'react'
|
|
11
|
+
import { useDispatch } from 'react-redux'
|
|
12
|
+
|
|
13
|
+
import { useWeb3React } from '@web3-react/core'
|
|
14
|
+
import { setStep } from '../../../store/widgets.reducers'
|
|
15
|
+
import { WIDGET_STEP } from '../../../store/widgets.store'
|
|
16
|
+
import { BottomButton } from '../../BottomButton'
|
|
17
|
+
import { WrapperModal } from '../../WrapperModal'
|
|
18
|
+
|
|
19
|
+
type Props = {
|
|
20
|
+
poolInfo: PoolInfoV2
|
|
21
|
+
tranche: TrancheType
|
|
22
|
+
poolUnderlyingToken: UnderlyingTokenInfo
|
|
23
|
+
redemptionStatus: TrancheRedemptionStatus
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export function ConfirmTransfer({
|
|
27
|
+
poolInfo,
|
|
28
|
+
tranche,
|
|
29
|
+
poolUnderlyingToken,
|
|
30
|
+
redemptionStatus,
|
|
31
|
+
}: Props): React.ReactElement {
|
|
32
|
+
const theme = useTheme()
|
|
33
|
+
const dispatch = useDispatch()
|
|
34
|
+
const { provider } = useWeb3React()
|
|
35
|
+
const { symbol, decimals } = poolUnderlyingToken
|
|
36
|
+
const { lenderRedemptionRecords, cancellableRedemptionShares } =
|
|
37
|
+
redemptionStatus
|
|
38
|
+
const { numSharesRequested } = lenderRedemptionRecords
|
|
39
|
+
const sharesProcessed = formatAmount(
|
|
40
|
+
numSharesRequested.sub(cancellableRedemptionShares),
|
|
41
|
+
decimals,
|
|
42
|
+
)
|
|
43
|
+
const withdrawableAmount = formatAmount(
|
|
44
|
+
redemptionStatus.withdrawableAssets,
|
|
45
|
+
decimals,
|
|
46
|
+
)
|
|
47
|
+
const [sharePrice, setSharePrice] = useState(0)
|
|
48
|
+
|
|
49
|
+
useEffect(() => {
|
|
50
|
+
const fetchData = async () => {
|
|
51
|
+
const vaultContract = await getTrancheVaultContractV2(
|
|
52
|
+
poolInfo.poolName,
|
|
53
|
+
tranche,
|
|
54
|
+
provider,
|
|
55
|
+
)
|
|
56
|
+
if (vaultContract) {
|
|
57
|
+
const shares = await vaultContract.convertToShares(
|
|
58
|
+
redemptionStatus.withdrawableAssets,
|
|
59
|
+
)
|
|
60
|
+
setSharePrice(
|
|
61
|
+
redemptionStatus.withdrawableAssets.toNumber() / shares.toNumber(),
|
|
62
|
+
)
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
fetchData()
|
|
66
|
+
}, [
|
|
67
|
+
poolInfo.poolName,
|
|
68
|
+
provider,
|
|
69
|
+
redemptionStatus.withdrawableAssets,
|
|
70
|
+
tranche,
|
|
71
|
+
])
|
|
72
|
+
|
|
73
|
+
const goToWithdraw = () => {
|
|
74
|
+
dispatch(setStep(WIDGET_STEP.Transfer))
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
const styles = {
|
|
78
|
+
itemWrapper: css`
|
|
79
|
+
margin-top: ${theme.spacing(9)};
|
|
80
|
+
color: ${theme.palette.text.primary};
|
|
81
|
+
font-family: 'Uni-Neue-Regular';
|
|
82
|
+
font-size: 16px;
|
|
83
|
+
line-height: 175%;
|
|
84
|
+
letter-spacing: 0.15px;
|
|
85
|
+
`,
|
|
86
|
+
item: css`
|
|
87
|
+
display: flex;
|
|
88
|
+
justify-content: space-between;
|
|
89
|
+
align-items: center;
|
|
90
|
+
margin-bottom: ${theme.spacing(3)};
|
|
91
|
+
`,
|
|
92
|
+
itemValue: css`
|
|
93
|
+
font-size: 20px;
|
|
94
|
+
font-family: 'Uni-Neue-Bold';
|
|
95
|
+
`,
|
|
96
|
+
divider: css`
|
|
97
|
+
border-color: #eae6f0;
|
|
98
|
+
margin-bottom: ${theme.spacing(3)};
|
|
99
|
+
`,
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
return (
|
|
103
|
+
<WrapperModal
|
|
104
|
+
title={`Withdraw ${symbol}`}
|
|
105
|
+
subTitle='Withdraw all the available amount'
|
|
106
|
+
>
|
|
107
|
+
<Box css={styles.itemWrapper}>
|
|
108
|
+
<Box css={styles.item}>
|
|
109
|
+
<Box>Shares processed</Box>
|
|
110
|
+
<Box css={styles.itemValue}>{sharesProcessed}</Box>
|
|
111
|
+
</Box>
|
|
112
|
+
<Box css={styles.item}>
|
|
113
|
+
<Box>Price Per Share</Box>
|
|
114
|
+
<Box css={styles.itemValue}>
|
|
115
|
+
{sharePrice.toFixed(1)} {symbol}
|
|
116
|
+
</Box>
|
|
117
|
+
</Box>
|
|
118
|
+
<Divider css={styles.divider} orientation='horizontal' />
|
|
119
|
+
<Box css={styles.item}>
|
|
120
|
+
<Box fontWeight={700}>Available to withdraw</Box>
|
|
121
|
+
<Box css={styles.itemValue}>
|
|
122
|
+
{withdrawableAmount} {symbol}
|
|
123
|
+
</Box>
|
|
124
|
+
</Box>
|
|
125
|
+
</Box>
|
|
126
|
+
<BottomButton variant='contained' onClick={goToWithdraw}>
|
|
127
|
+
WITHDRAW
|
|
128
|
+
</BottomButton>
|
|
129
|
+
</WrapperModal>
|
|
130
|
+
)
|
|
131
|
+
}
|
|
@@ -13,18 +13,18 @@ import { TxSendModalV2 } from '../../TxSendModalV2'
|
|
|
13
13
|
|
|
14
14
|
type Props = {
|
|
15
15
|
poolInfo: PoolInfoV2
|
|
16
|
-
|
|
16
|
+
tranche: TrancheType
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
export function Transfer({
|
|
20
20
|
poolInfo,
|
|
21
|
-
|
|
21
|
+
tranche,
|
|
22
22
|
}: Props): React.ReactElement | null {
|
|
23
23
|
const dispatch = useAppDispatch()
|
|
24
24
|
const { account, provider } = useWeb3React()
|
|
25
25
|
const trancheVaultContract = useTrancheVaultContractV2(
|
|
26
26
|
poolInfo.poolName,
|
|
27
|
-
|
|
27
|
+
tranche,
|
|
28
28
|
provider,
|
|
29
29
|
account,
|
|
30
30
|
)
|
|
@@ -1,22 +1,22 @@
|
|
|
1
1
|
import {
|
|
2
|
+
getTrancheRedemptionStatusV2,
|
|
2
3
|
POOL_NAME,
|
|
4
|
+
TrancheRedemptionStatus,
|
|
3
5
|
TrancheType,
|
|
4
6
|
usePoolInfoV2,
|
|
5
7
|
usePoolUnderlyingTokenInfoV2,
|
|
6
|
-
useWithdrawableAssetsV2,
|
|
7
8
|
} from '@huma-finance/shared'
|
|
8
9
|
import { useWeb3React } from '@web3-react/core'
|
|
9
|
-
import React, { useCallback, useEffect
|
|
10
|
+
import React, { useCallback, useEffect } from 'react'
|
|
10
11
|
import { useDispatch } from 'react-redux'
|
|
11
12
|
|
|
12
|
-
import { BigNumber } from 'ethers'
|
|
13
13
|
import { useAppSelector } from '../../../hooks/useRedux'
|
|
14
14
|
import { setStep } from '../../../store/widgets.reducers'
|
|
15
15
|
import { selectWidgetState } from '../../../store/widgets.selectors'
|
|
16
16
|
import { WIDGET_STEP } from '../../../store/widgets.store'
|
|
17
17
|
import { ErrorModal } from '../../ErrorModal'
|
|
18
18
|
import { WidgetWrapper } from '../../WidgetWrapper'
|
|
19
|
-
import {
|
|
19
|
+
import { ConfirmTransfer } from './1-ConfirmTransfer'
|
|
20
20
|
import { Transfer } from './2-Transfer'
|
|
21
21
|
import { Done } from './3-Done'
|
|
22
22
|
|
|
@@ -24,17 +24,20 @@ import { Done } from './3-Done'
|
|
|
24
24
|
* Lend pool withdraw props
|
|
25
25
|
* @typedef {Object} LendWithdrawPropsV2
|
|
26
26
|
* @property {POOL_NAME} poolName The name of the pool.
|
|
27
|
+
* @property {TrancheType} trancheType The type of the tranche.
|
|
27
28
|
* @property {function():void} handleClose Function to notify to close the widget modal when user clicks the 'x' close button.
|
|
28
29
|
* @property {function((number|undefined)):void|undefined} handleSuccess Optional function to notify that the lending pool withdraw action is successful.
|
|
29
30
|
*/
|
|
30
31
|
export type LendWithdrawPropsV2 = {
|
|
31
32
|
poolName: keyof typeof POOL_NAME
|
|
33
|
+
trancheType: TrancheType
|
|
32
34
|
handleClose: () => void
|
|
33
35
|
handleSuccess?: (blockNumber?: number) => void
|
|
34
36
|
}
|
|
35
37
|
|
|
36
38
|
export function LendWithdrawV2({
|
|
37
39
|
poolName: poolNameStr,
|
|
40
|
+
trancheType,
|
|
38
41
|
handleClose,
|
|
39
42
|
handleSuccess,
|
|
40
43
|
}: LendWithdrawPropsV2): React.ReactElement | null {
|
|
@@ -43,82 +46,85 @@ export function LendWithdrawV2({
|
|
|
43
46
|
const poolName = POOL_NAME[poolNameStr]
|
|
44
47
|
const poolInfo = usePoolInfoV2(poolName, chainId)
|
|
45
48
|
const { step, errorMessage } = useAppSelector(selectWidgetState)
|
|
46
|
-
const [seniorWithdrawableAmount, refreshSeniorWithdrawableAmount] =
|
|
47
|
-
useWithdrawableAssetsV2(poolName, 'senior', account, provider)
|
|
48
|
-
const [juniorWithdrawableAmount, refreshJuniorWithdrawableAmount] =
|
|
49
|
-
useWithdrawableAssetsV2(poolName, 'junior', account, provider)
|
|
50
49
|
const poolUnderlyingToken = usePoolUnderlyingTokenInfoV2(poolName, provider)
|
|
51
|
-
const
|
|
52
|
-
|
|
50
|
+
const title = poolUnderlyingToken
|
|
51
|
+
? `Withdraw ${poolUnderlyingToken.symbol}`
|
|
52
|
+
: 'Withdraw'
|
|
53
|
+
|
|
54
|
+
const [redemptionStatus, setRedemptionStatus] = React.useState<
|
|
55
|
+
TrancheRedemptionStatus | undefined
|
|
56
|
+
>()
|
|
57
|
+
|
|
58
|
+
useEffect(() => {
|
|
59
|
+
const fetchData = async () => {
|
|
60
|
+
if (account && provider) {
|
|
61
|
+
const result = await getTrancheRedemptionStatusV2(
|
|
62
|
+
poolName,
|
|
63
|
+
trancheType,
|
|
64
|
+
account,
|
|
65
|
+
provider,
|
|
66
|
+
)
|
|
67
|
+
setRedemptionStatus(result)
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
fetchData()
|
|
71
|
+
}, [account, poolName, provider, trancheType])
|
|
53
72
|
|
|
54
73
|
useEffect(() => {
|
|
55
74
|
if (!step) {
|
|
56
|
-
dispatch(setStep(WIDGET_STEP.
|
|
75
|
+
dispatch(setStep(WIDGET_STEP.ConfirmTransfer))
|
|
57
76
|
}
|
|
58
77
|
}, [dispatch, step])
|
|
59
78
|
|
|
60
79
|
const handleWithdrawSuccess = useCallback(
|
|
61
80
|
(blockNumber: number) => {
|
|
62
|
-
refreshSeniorWithdrawableAmount()
|
|
63
|
-
refreshJuniorWithdrawableAmount()
|
|
64
81
|
if (handleSuccess) {
|
|
65
82
|
handleSuccess(blockNumber)
|
|
66
83
|
}
|
|
67
84
|
},
|
|
68
|
-
[
|
|
69
|
-
handleSuccess,
|
|
70
|
-
refreshJuniorWithdrawableAmount,
|
|
71
|
-
refreshSeniorWithdrawableAmount,
|
|
72
|
-
],
|
|
73
|
-
)
|
|
74
|
-
|
|
75
|
-
const handleChangeTranche = useCallback(
|
|
76
|
-
(tranche: TrancheType) => {
|
|
77
|
-
setSelectedTranche(tranche)
|
|
78
|
-
if (tranche === 'senior') {
|
|
79
|
-
setWithdrawAmount(seniorWithdrawableAmount)
|
|
80
|
-
}
|
|
81
|
-
if (tranche === 'junior') {
|
|
82
|
-
setWithdrawAmount(juniorWithdrawableAmount)
|
|
83
|
-
}
|
|
84
|
-
},
|
|
85
|
-
[juniorWithdrawableAmount, seniorWithdrawableAmount],
|
|
85
|
+
[handleSuccess],
|
|
86
86
|
)
|
|
87
87
|
|
|
88
|
-
if (!poolInfo || !poolUnderlyingToken) {
|
|
89
|
-
return
|
|
88
|
+
if (!poolInfo || !poolUnderlyingToken || !redemptionStatus) {
|
|
89
|
+
return (
|
|
90
|
+
<WidgetWrapper
|
|
91
|
+
isOpen
|
|
92
|
+
isLoading
|
|
93
|
+
loadingTitle={title}
|
|
94
|
+
handleClose={handleClose}
|
|
95
|
+
handleSuccess={handleSuccess}
|
|
96
|
+
/>
|
|
97
|
+
)
|
|
90
98
|
}
|
|
91
99
|
|
|
92
100
|
return (
|
|
93
101
|
<WidgetWrapper
|
|
94
102
|
isOpen
|
|
95
|
-
loadingTitle=
|
|
103
|
+
loadingTitle={title}
|
|
96
104
|
handleClose={handleClose}
|
|
97
105
|
handleSuccess={handleWithdrawSuccess}
|
|
98
106
|
>
|
|
99
|
-
{step === WIDGET_STEP.
|
|
100
|
-
<
|
|
107
|
+
{step === WIDGET_STEP.ConfirmTransfer && (
|
|
108
|
+
<ConfirmTransfer
|
|
101
109
|
poolInfo={poolInfo}
|
|
110
|
+
tranche={trancheType}
|
|
111
|
+
redemptionStatus={redemptionStatus}
|
|
102
112
|
poolUnderlyingToken={poolUnderlyingToken}
|
|
103
|
-
selectedTranche={selectedTranche}
|
|
104
|
-
changeTranche={handleChangeTranche}
|
|
105
|
-
seniorWithdrawableAmount={seniorWithdrawableAmount}
|
|
106
|
-
juniorWithdrawableAmount={juniorWithdrawableAmount}
|
|
107
113
|
/>
|
|
108
114
|
)}
|
|
109
|
-
{step === WIDGET_STEP.Transfer &&
|
|
110
|
-
<Transfer poolInfo={poolInfo}
|
|
115
|
+
{step === WIDGET_STEP.Transfer && (
|
|
116
|
+
<Transfer poolInfo={poolInfo} tranche={trancheType} />
|
|
111
117
|
)}
|
|
112
|
-
{step === WIDGET_STEP.Done &&
|
|
118
|
+
{step === WIDGET_STEP.Done && (
|
|
113
119
|
<Done
|
|
114
120
|
poolUnderlyingToken={poolUnderlyingToken}
|
|
115
|
-
withdrawAmount={
|
|
121
|
+
withdrawAmount={redemptionStatus.withdrawableAssets}
|
|
116
122
|
handleAction={handleClose}
|
|
117
123
|
/>
|
|
118
124
|
)}
|
|
119
125
|
{step === WIDGET_STEP.Error && (
|
|
120
126
|
<ErrorModal
|
|
121
|
-
title=
|
|
127
|
+
title={title}
|
|
122
128
|
errorReason='Sorry there was an error'
|
|
123
129
|
errorMessage={errorMessage}
|
|
124
130
|
handleOk={handleClose}
|
package/src/index.tsx
CHANGED
|
@@ -48,7 +48,14 @@ import {
|
|
|
48
48
|
InvoiceFactoringPayment,
|
|
49
49
|
InvoiceFactoringPaymentProps,
|
|
50
50
|
} from './components/InvoiceFactoring/payment'
|
|
51
|
-
import {
|
|
51
|
+
import {
|
|
52
|
+
AddRedemptionPropsV2,
|
|
53
|
+
AddRedemptionV2,
|
|
54
|
+
} from './components/Lend/addRedemptionV2'
|
|
55
|
+
import {
|
|
56
|
+
CancelRedemptionPropsV2,
|
|
57
|
+
CancelRedemptionV2,
|
|
58
|
+
} from './components/Lend/cancelRedemptionV2 '
|
|
52
59
|
import { LendSupply, LendSupplyProps } from './components/Lend/supply'
|
|
53
60
|
import { LendSupplyPropsV2, LendSupplyV2 } from './components/Lend/supplyV2'
|
|
54
61
|
import { LendWithdraw, LendWithdrawProps } from './components/Lend/withdraw'
|
|
@@ -60,14 +67,14 @@ import {
|
|
|
60
67
|
ReceivableBackedCreditLineBorrowPropsV2,
|
|
61
68
|
ReceivableBackedCreditLineBorrowV2,
|
|
62
69
|
} from './components/ReceivableBackedCreditLine/borrow'
|
|
63
|
-
import { SuperfluidFactoring } from './components/SuperfluidFactoring'
|
|
64
|
-
import { store } from './store'
|
|
65
|
-
import { themeHuma } from './theme'
|
|
66
|
-
import { WCProps } from './utilTypes'
|
|
67
70
|
import {
|
|
68
71
|
ReceivableBackedCreditLinePaymentPropsV2,
|
|
69
72
|
ReceivableBackedCreditLinePaymentV2,
|
|
70
73
|
} from './components/ReceivableBackedCreditLine/payment'
|
|
74
|
+
import { SuperfluidFactoring } from './components/SuperfluidFactoring'
|
|
75
|
+
import { store } from './store'
|
|
76
|
+
import { themeHuma } from './theme'
|
|
77
|
+
import { WCProps } from './utilTypes'
|
|
71
78
|
|
|
72
79
|
/**
|
|
73
80
|
* Mapping of your JSON-RPC connections indexed by chainId
|
|
@@ -350,7 +357,7 @@ export function LendWithdrawWidget(props: LendWithdrawWidgetProps) {
|
|
|
350
357
|
|
|
351
358
|
/**
|
|
352
359
|
* Lend pool supply widget props V2
|
|
353
|
-
* @typedef {Object}
|
|
360
|
+
* @typedef {Object} LendWithdrawWidgetPropsV2
|
|
354
361
|
* @property {LendWithdrawPropsV2} LendSupplyPropsV2 - Lend pool supply props V2.
|
|
355
362
|
* @property {WidgetProps} WidgetProps - Widget general props.
|
|
356
363
|
*/
|
|
@@ -371,23 +378,45 @@ export function LendWithdrawWidgetV2(props: LendWithdrawWidgetPropsV2) {
|
|
|
371
378
|
}
|
|
372
379
|
|
|
373
380
|
/**
|
|
374
|
-
* Lend pool
|
|
375
|
-
* @typedef {Object}
|
|
376
|
-
* @property {
|
|
381
|
+
* Lend pool add redemption widget props V2
|
|
382
|
+
* @typedef {Object} AddRedemptionWidgetPropsV2
|
|
383
|
+
* @property {AddRedemptionWidgetPropsV2} AddRedemptionWidgetPropsV2 - Lend pool add redemption props V2.
|
|
384
|
+
* @property {WidgetProps} WidgetProps - Widget general props.
|
|
385
|
+
*/
|
|
386
|
+
type AddRedemptionWidgetPropsV2 = AddRedemptionPropsV2 & WidgetProps
|
|
387
|
+
|
|
388
|
+
/**
|
|
389
|
+
* Add redemption widget V2
|
|
390
|
+
*
|
|
391
|
+
* @param {AddRedemptionWidgetPropsV2} props - The lend pool add redemption widget props V2.
|
|
392
|
+
* @returns Lend pool add redemption widget component V2
|
|
393
|
+
*/
|
|
394
|
+
export function AddRedemptionWidgetV2(props: AddRedemptionWidgetPropsV2) {
|
|
395
|
+
return (
|
|
396
|
+
<Widget {...props}>
|
|
397
|
+
<AddRedemptionV2 {...props} />
|
|
398
|
+
</Widget>
|
|
399
|
+
)
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
/**
|
|
403
|
+
* Lend pool cancel redemption widget props V2
|
|
404
|
+
* @typedef {Object} CancelRedemptionWidgetPropsV2
|
|
405
|
+
* @property {CancelRedemptionWidgetPropsV2} CancelRedemptionWidgetPropsV2 - Lend pool cancel redemption props V2.
|
|
377
406
|
* @property {WidgetProps} WidgetProps - Widget general props.
|
|
378
407
|
*/
|
|
379
|
-
type
|
|
408
|
+
type CancelRedemptionWidgetPropsV2 = CancelRedemptionPropsV2 & WidgetProps
|
|
380
409
|
|
|
381
410
|
/**
|
|
382
|
-
*
|
|
411
|
+
* Cancel redemption widget V2
|
|
383
412
|
*
|
|
384
|
-
* @param {
|
|
385
|
-
* @returns Lend pool
|
|
413
|
+
* @param {CancelRedemptionWidgetPropsV2} props - The lend pool cancel redemption widget props V2.
|
|
414
|
+
* @returns Lend pool cancel redemption widget component V2
|
|
386
415
|
*/
|
|
387
|
-
export function
|
|
416
|
+
export function CancelRedemptionWidgetV2(props: CancelRedemptionWidgetPropsV2) {
|
|
388
417
|
return (
|
|
389
418
|
<Widget {...props}>
|
|
390
|
-
<
|
|
419
|
+
<CancelRedemptionV2 {...props} />
|
|
391
420
|
</Widget>
|
|
392
421
|
)
|
|
393
422
|
}
|
|
@@ -1,237 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
PoolInfoV2,
|
|
3
|
-
timestampToLL,
|
|
4
|
-
UnderlyingTokenInfo,
|
|
5
|
-
useLenderDepositRecordV2,
|
|
6
|
-
useLPConfigV2,
|
|
7
|
-
useNextEpochStartTimeV2,
|
|
8
|
-
} from '@huma-finance/shared'
|
|
9
|
-
import {
|
|
10
|
-
Box,
|
|
11
|
-
css,
|
|
12
|
-
FormControl,
|
|
13
|
-
FormControlLabel,
|
|
14
|
-
FormLabel,
|
|
15
|
-
Radio,
|
|
16
|
-
RadioGroup,
|
|
17
|
-
useTheme,
|
|
18
|
-
} from '@mui/material'
|
|
19
|
-
import { useWeb3React } from '@web3-react/core'
|
|
20
|
-
import { BigNumber, ethers } from 'ethers'
|
|
21
|
-
import React from 'react'
|
|
22
|
-
|
|
23
|
-
import { REDEMPTION_TYPE, RedemptionInfo } from '.'
|
|
24
|
-
import { useAppDispatch } from '../../../hooks/useRedux'
|
|
25
|
-
import { setError, setStep } from '../../../store/widgets.reducers'
|
|
26
|
-
import { WIDGET_STEP } from '../../../store/widgets.store'
|
|
27
|
-
import { BottomButton } from '../../BottomButton'
|
|
28
|
-
import { LoadingModal } from '../../LoadingModal'
|
|
29
|
-
import { WrapperModal } from '../../WrapperModal'
|
|
30
|
-
|
|
31
|
-
type Props = {
|
|
32
|
-
poolInfo: PoolInfoV2
|
|
33
|
-
poolUnderlyingToken: UnderlyingTokenInfo
|
|
34
|
-
seniorRedemptionInfo: RedemptionInfo | undefined
|
|
35
|
-
juniorRedemptionInfo: RedemptionInfo | undefined
|
|
36
|
-
redemptionType: REDEMPTION_TYPE | undefined
|
|
37
|
-
seniorPosition: BigNumber | undefined
|
|
38
|
-
juniorPosition: BigNumber | undefined
|
|
39
|
-
changeRedemptionType: (tranche: REDEMPTION_TYPE) => void
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
export function ChooseAction({
|
|
43
|
-
poolInfo,
|
|
44
|
-
poolUnderlyingToken,
|
|
45
|
-
seniorRedemptionInfo,
|
|
46
|
-
juniorRedemptionInfo,
|
|
47
|
-
redemptionType,
|
|
48
|
-
seniorPosition,
|
|
49
|
-
juniorPosition,
|
|
50
|
-
changeRedemptionType,
|
|
51
|
-
}: Props): React.ReactElement | null {
|
|
52
|
-
const theme = useTheme()
|
|
53
|
-
const dispatch = useAppDispatch()
|
|
54
|
-
const { symbol } = poolUnderlyingToken
|
|
55
|
-
const { account, provider } = useWeb3React()
|
|
56
|
-
const [seniorDepositRecord] = useLenderDepositRecordV2(
|
|
57
|
-
poolInfo.poolName,
|
|
58
|
-
'senior',
|
|
59
|
-
account,
|
|
60
|
-
provider,
|
|
61
|
-
)
|
|
62
|
-
const [juniorDepositRecord] = useLenderDepositRecordV2(
|
|
63
|
-
poolInfo.poolName,
|
|
64
|
-
'junior',
|
|
65
|
-
account,
|
|
66
|
-
provider,
|
|
67
|
-
)
|
|
68
|
-
const lpConfig = useLPConfigV2(poolInfo.poolName, provider)
|
|
69
|
-
const nextEpochStartTime = useNextEpochStartTimeV2(
|
|
70
|
-
poolInfo.poolName,
|
|
71
|
-
provider,
|
|
72
|
-
)
|
|
73
|
-
|
|
74
|
-
const isLoading =
|
|
75
|
-
seniorRedemptionInfo === undefined ||
|
|
76
|
-
juniorRedemptionInfo === undefined ||
|
|
77
|
-
seniorDepositRecord === undefined ||
|
|
78
|
-
juniorDepositRecord === undefined ||
|
|
79
|
-
lpConfig === undefined ||
|
|
80
|
-
nextEpochStartTime === undefined
|
|
81
|
-
|
|
82
|
-
const styles = {
|
|
83
|
-
subTitle: css`
|
|
84
|
-
color: ${theme.palette.text.primary} !important;
|
|
85
|
-
font-family: 'Uni-Neue-Regular';
|
|
86
|
-
font-size: 16px;
|
|
87
|
-
line-height: 150%;
|
|
88
|
-
letter-spacing: 0.15px;
|
|
89
|
-
margin-top: ${theme.spacing(5)};
|
|
90
|
-
margin-left: ${theme.spacing(2)};
|
|
91
|
-
`,
|
|
92
|
-
radioGroup: css`
|
|
93
|
-
margin-left: ${theme.spacing(3)};
|
|
94
|
-
margin-top: ${theme.spacing(3)};
|
|
95
|
-
`,
|
|
96
|
-
formControl: css`
|
|
97
|
-
margin-bottom: ${theme.spacing(1)};
|
|
98
|
-
|
|
99
|
-
.MuiFormControlLabel-label {
|
|
100
|
-
color: ${theme.palette.text.primary};
|
|
101
|
-
font-family: 'Uni-Neue-Regular';
|
|
102
|
-
font-size: 16px;
|
|
103
|
-
line-height: 150%;
|
|
104
|
-
letter-spacing: 0.15px;
|
|
105
|
-
}
|
|
106
|
-
`,
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
const handleNext = () => {
|
|
110
|
-
if (isLoading) {
|
|
111
|
-
return
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
const depositRecord =
|
|
115
|
-
redemptionType === REDEMPTION_TYPE.AddSeniorRedemption
|
|
116
|
-
? seniorDepositRecord
|
|
117
|
-
: juniorDepositRecord
|
|
118
|
-
|
|
119
|
-
const SECONDS_IN_A_DAY = 24 * 60 * 60
|
|
120
|
-
if (
|
|
121
|
-
nextEpochStartTime <
|
|
122
|
-
depositRecord.lastDepositTime.toNumber() +
|
|
123
|
-
lpConfig.withdrawalLockoutPeriodInDays * SECONDS_IN_A_DAY
|
|
124
|
-
) {
|
|
125
|
-
dispatch(setStep(WIDGET_STEP.Error))
|
|
126
|
-
dispatch(
|
|
127
|
-
setError({
|
|
128
|
-
errorReason: 'Redemption request too soon',
|
|
129
|
-
errorMessage: `Your last deposit was on ${timestampToLL(
|
|
130
|
-
depositRecord.lastDepositTime.toNumber(),
|
|
131
|
-
)}. Depositors need to wait ${
|
|
132
|
-
lpConfig.withdrawalLockoutPeriodInDays
|
|
133
|
-
} days before redemption request`,
|
|
134
|
-
}),
|
|
135
|
-
)
|
|
136
|
-
return
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
dispatch(setStep(WIDGET_STEP.ChooseAmount))
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
const formatAmount = (amount?: BigNumber) => {
|
|
143
|
-
if (!amount || amount.lte(0)) {
|
|
144
|
-
return undefined
|
|
145
|
-
}
|
|
146
|
-
return ethers.utils.formatUnits(amount, poolUnderlyingToken.decimals)
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
const items: {
|
|
150
|
-
label: string
|
|
151
|
-
value: REDEMPTION_TYPE
|
|
152
|
-
amount?: string
|
|
153
|
-
show: boolean
|
|
154
|
-
}[] = [
|
|
155
|
-
{
|
|
156
|
-
label: 'Request Senior Tranche Redemption',
|
|
157
|
-
value: REDEMPTION_TYPE.AddSeniorRedemption,
|
|
158
|
-
show: seniorPosition?.gt(0) ?? false,
|
|
159
|
-
},
|
|
160
|
-
{
|
|
161
|
-
label: 'Cancel Senior Tranche Redemption',
|
|
162
|
-
value: REDEMPTION_TYPE.CancelSeniorRedemption,
|
|
163
|
-
amount: formatAmount(seniorRedemptionInfo?.amount),
|
|
164
|
-
show: seniorRedemptionInfo?.amount.gt(0) ?? false,
|
|
165
|
-
},
|
|
166
|
-
{
|
|
167
|
-
label: 'Request Junior Tranche Redemption',
|
|
168
|
-
value: REDEMPTION_TYPE.AddJuniorRedemption,
|
|
169
|
-
show: juniorPosition?.gt(0) ?? false,
|
|
170
|
-
},
|
|
171
|
-
{
|
|
172
|
-
label: 'Cancel Junior Tranche Redemption',
|
|
173
|
-
value: REDEMPTION_TYPE.CancelJuniorRedemption,
|
|
174
|
-
amount: formatAmount(juniorRedemptionInfo?.amount),
|
|
175
|
-
show: juniorRedemptionInfo?.amount.gt(0) ?? false,
|
|
176
|
-
},
|
|
177
|
-
]
|
|
178
|
-
|
|
179
|
-
if (isLoading) {
|
|
180
|
-
return <LoadingModal title={`Redeem ${symbol}`} />
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
return (
|
|
184
|
-
<WrapperModal title={`Redeem ${symbol}`}>
|
|
185
|
-
<FormControl>
|
|
186
|
-
<FormLabel css={styles.subTitle}>Select Redemption Type</FormLabel>
|
|
187
|
-
<RadioGroup
|
|
188
|
-
aria-labelledby='buttons-group-label'
|
|
189
|
-
name='radio-buttons-group'
|
|
190
|
-
css={styles.radioGroup}
|
|
191
|
-
onChange={(e) => changeRedemptionType(Number(e.target.value))}
|
|
192
|
-
>
|
|
193
|
-
{items
|
|
194
|
-
.filter((item) => item.show)
|
|
195
|
-
.map((item) => {
|
|
196
|
-
const { label } = item
|
|
197
|
-
let labelNode = <Box>{label}</Box>
|
|
198
|
-
if (item.amount) {
|
|
199
|
-
labelNode = (
|
|
200
|
-
<>
|
|
201
|
-
<Box>{label}</Box>
|
|
202
|
-
<Box>
|
|
203
|
-
({item.amount} {symbol} available)
|
|
204
|
-
</Box>
|
|
205
|
-
</>
|
|
206
|
-
)
|
|
207
|
-
}
|
|
208
|
-
return (
|
|
209
|
-
<FormControlLabel
|
|
210
|
-
key={item.label}
|
|
211
|
-
value={item.value}
|
|
212
|
-
control={
|
|
213
|
-
<Radio
|
|
214
|
-
sx={{
|
|
215
|
-
'& .MuiSvgIcon-root': {
|
|
216
|
-
fontSize: 24,
|
|
217
|
-
},
|
|
218
|
-
}}
|
|
219
|
-
/>
|
|
220
|
-
}
|
|
221
|
-
label={labelNode}
|
|
222
|
-
css={styles.formControl}
|
|
223
|
-
/>
|
|
224
|
-
)
|
|
225
|
-
})}
|
|
226
|
-
</RadioGroup>
|
|
227
|
-
</FormControl>
|
|
228
|
-
<BottomButton
|
|
229
|
-
variant='contained'
|
|
230
|
-
disabled={redemptionType === undefined}
|
|
231
|
-
onClick={handleNext}
|
|
232
|
-
>
|
|
233
|
-
NEXT
|
|
234
|
-
</BottomButton>
|
|
235
|
-
</WrapperModal>
|
|
236
|
-
)
|
|
237
|
-
}
|