@huma-finance/widgets 0.0.48-beta.296 → 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 +2062 -2185
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/index.d.ts +45 -14
- package/dist/index.js +2061 -2185
- package/dist/index.js.map +1 -1
- package/package.json +4 -4
- package/src/components/CreditLine/paymentV2/1-ChooseAmount.tsx +5 -0
- package/src/components/InputAmountModal.tsx +3 -1
- package/src/components/Lend/{withdrawV2 → addRedemptionV2}/1-ChooseTranche.tsx +25 -30
- 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/supplyV2/1-ChooseTranche.tsx +23 -21
- package/src/components/Lend/supplyV2/3-ChooseAmount.tsx +20 -30
- package/src/components/Lend/supplyV2/4-ApproveAllowance.tsx +2 -15
- package/src/components/Lend/supplyV2/5-Transfer.tsx +14 -58
- package/src/components/Lend/supplyV2/6-Success.tsx +5 -2
- package/src/components/Lend/supplyV2/index.tsx +31 -59
- package/src/components/Lend/withdrawV2/1-ConfirmTransfer.tsx +131 -0
- package/src/components/Lend/withdrawV2/2-Transfer.tsx +48 -0
- package/src/components/Lend/withdrawV2/index.tsx +53 -136
- 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/2-ChooseAmount.tsx +0 -88
- package/src/components/Lend/withdrawV2/3-Transfer.tsx +0 -110
- /package/src/components/Lend/withdrawV2/{4-Done.tsx → 3-Done.tsx} +0 -0
|
@@ -1,17 +1,13 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
FirstLossCoverIndex,
|
|
4
|
-
formatBNFixed,
|
|
2
|
+
getTrancheRedemptionStatusV2,
|
|
5
3
|
POOL_NAME,
|
|
6
|
-
|
|
4
|
+
TrancheRedemptionStatus,
|
|
5
|
+
TrancheType,
|
|
7
6
|
usePoolInfoV2,
|
|
8
|
-
usePoolIsReadyForFlcWithdrawalV2,
|
|
9
7
|
usePoolUnderlyingTokenInfoV2,
|
|
10
|
-
useTrancheWithdrawableAssetsV2,
|
|
11
8
|
} from '@huma-finance/shared'
|
|
12
9
|
import { useWeb3React } from '@web3-react/core'
|
|
13
|
-
import {
|
|
14
|
-
import React, { useCallback, useEffect, useState } from 'react'
|
|
10
|
+
import React, { useCallback, useEffect } from 'react'
|
|
15
11
|
import { useDispatch } from 'react-redux'
|
|
16
12
|
|
|
17
13
|
import { useAppSelector } from '../../../hooks/useRedux'
|
|
@@ -20,33 +16,28 @@ import { selectWidgetState } from '../../../store/widgets.selectors'
|
|
|
20
16
|
import { WIDGET_STEP } from '../../../store/widgets.store'
|
|
21
17
|
import { ErrorModal } from '../../ErrorModal'
|
|
22
18
|
import { WidgetWrapper } from '../../WidgetWrapper'
|
|
23
|
-
import {
|
|
24
|
-
import {
|
|
25
|
-
import {
|
|
26
|
-
import { Done } from './4-Done'
|
|
27
|
-
|
|
28
|
-
export type WithdrawType = {
|
|
29
|
-
label: string
|
|
30
|
-
value: string
|
|
31
|
-
type: 'tranche' | 'firstLossCover'
|
|
32
|
-
withdrawableAmount: BigNumber
|
|
33
|
-
}
|
|
19
|
+
import { ConfirmTransfer } from './1-ConfirmTransfer'
|
|
20
|
+
import { Transfer } from './2-Transfer'
|
|
21
|
+
import { Done } from './3-Done'
|
|
34
22
|
|
|
35
23
|
/**
|
|
36
24
|
* Lend pool withdraw props
|
|
37
25
|
* @typedef {Object} LendWithdrawPropsV2
|
|
38
26
|
* @property {POOL_NAME} poolName The name of the pool.
|
|
27
|
+
* @property {TrancheType} trancheType The type of the tranche.
|
|
39
28
|
* @property {function():void} handleClose Function to notify to close the widget modal when user clicks the 'x' close button.
|
|
40
29
|
* @property {function((number|undefined)):void|undefined} handleSuccess Optional function to notify that the lending pool withdraw action is successful.
|
|
41
30
|
*/
|
|
42
31
|
export type LendWithdrawPropsV2 = {
|
|
43
32
|
poolName: keyof typeof POOL_NAME
|
|
33
|
+
trancheType: TrancheType
|
|
44
34
|
handleClose: () => void
|
|
45
35
|
handleSuccess?: (blockNumber?: number) => void
|
|
46
36
|
}
|
|
47
37
|
|
|
48
38
|
export function LendWithdrawV2({
|
|
49
39
|
poolName: poolNameStr,
|
|
40
|
+
trancheType,
|
|
50
41
|
handleClose,
|
|
51
42
|
handleSuccess,
|
|
52
43
|
}: LendWithdrawPropsV2): React.ReactElement | null {
|
|
@@ -55,159 +46,85 @@ export function LendWithdrawV2({
|
|
|
55
46
|
const poolName = POOL_NAME[poolNameStr]
|
|
56
47
|
const poolInfo = usePoolInfoV2(poolName, chainId)
|
|
57
48
|
const { step, errorMessage } = useAppSelector(selectWidgetState)
|
|
58
|
-
const [withdrawTypes, setWithdrawTypes] = useState<WithdrawType[]>([])
|
|
59
|
-
const [selectedWithdrawType, setSelectedWithdrawType] =
|
|
60
|
-
useState<WithdrawType>()
|
|
61
|
-
|
|
62
|
-
const [seniorWithdrawableAmount, refreshSeniorWithdrawableAmount] =
|
|
63
|
-
useTrancheWithdrawableAssetsV2(poolName, 'senior', account, provider)
|
|
64
|
-
const [juniorWithdrawableAmount, refreshJuniorWithdrawableAmount] =
|
|
65
|
-
useTrancheWithdrawableAssetsV2(poolName, 'junior', account, provider)
|
|
66
|
-
const isReadyForFlcWithdrawal = usePoolIsReadyForFlcWithdrawalV2(
|
|
67
|
-
poolName,
|
|
68
|
-
provider,
|
|
69
|
-
)
|
|
70
|
-
const [flcStats, refreshFlcStats] = useFirstLossCoverStatsV2(
|
|
71
|
-
poolName,
|
|
72
|
-
account,
|
|
73
|
-
provider,
|
|
74
|
-
)
|
|
75
|
-
|
|
76
49
|
const poolUnderlyingToken = usePoolUnderlyingTokenInfoV2(poolName, provider)
|
|
77
|
-
const
|
|
50
|
+
const title = poolUnderlyingToken
|
|
51
|
+
? `Withdraw ${poolUnderlyingToken.symbol}`
|
|
52
|
+
: 'Withdraw'
|
|
78
53
|
|
|
79
|
-
const
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
isReadyForFlcWithdrawal === undefined ||
|
|
83
|
-
!seniorWithdrawableAmount ||
|
|
84
|
-
!juniorWithdrawableAmount ||
|
|
85
|
-
!flcStats
|
|
54
|
+
const [redemptionStatus, setRedemptionStatus] = React.useState<
|
|
55
|
+
TrancheRedemptionStatus | undefined
|
|
56
|
+
>()
|
|
86
57
|
|
|
87
58
|
useEffect(() => {
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
type: 'tranche',
|
|
98
|
-
withdrawableAmount: seniorWithdrawableAmount,
|
|
99
|
-
})
|
|
100
|
-
}
|
|
101
|
-
if (juniorWithdrawableAmount.gt(0)) {
|
|
102
|
-
items.push({
|
|
103
|
-
label: `Withdraw ${formatBNFixed(
|
|
104
|
-
juniorWithdrawableAmount,
|
|
105
|
-
decimals!,
|
|
106
|
-
)} ${symbol} from Junior Tranche`,
|
|
107
|
-
value: 'junior',
|
|
108
|
-
type: 'tranche',
|
|
109
|
-
withdrawableAmount: juniorWithdrawableAmount,
|
|
110
|
-
})
|
|
111
|
-
}
|
|
112
|
-
if (isReadyForFlcWithdrawal) {
|
|
113
|
-
flcStats
|
|
114
|
-
.filter((flc) => flc.totalAssets.gt(0))
|
|
115
|
-
.forEach((flc) => {
|
|
116
|
-
items.push({
|
|
117
|
-
label: `Withdraw ${symbol} from ${capitalizeFirstLetter(
|
|
118
|
-
FirstLossCoverIndex[flc.firstLossCoverIndex],
|
|
119
|
-
)} First Loss Cover`,
|
|
120
|
-
value: String(flc.firstLossCoverIndex),
|
|
121
|
-
type: 'firstLossCover',
|
|
122
|
-
withdrawableAmount: flc.totalAssets,
|
|
123
|
-
})
|
|
124
|
-
})
|
|
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)
|
|
125
68
|
}
|
|
69
|
+
}
|
|
70
|
+
fetchData()
|
|
71
|
+
}, [account, poolName, provider, trancheType])
|
|
126
72
|
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
const step =
|
|
131
|
-
items[0].type === 'firstLossCover'
|
|
132
|
-
? WIDGET_STEP.ChooseAmount
|
|
133
|
-
: WIDGET_STEP.Transfer
|
|
134
|
-
dispatch(setStep(step))
|
|
135
|
-
} else if (items.length > 1) {
|
|
136
|
-
dispatch(setStep(WIDGET_STEP.ChooseTranche))
|
|
137
|
-
}
|
|
73
|
+
useEffect(() => {
|
|
74
|
+
if (!step) {
|
|
75
|
+
dispatch(setStep(WIDGET_STEP.ConfirmTransfer))
|
|
138
76
|
}
|
|
139
|
-
}, [
|
|
140
|
-
decimals,
|
|
141
|
-
dispatch,
|
|
142
|
-
flcStats,
|
|
143
|
-
isLoading,
|
|
144
|
-
isReadyForFlcWithdrawal,
|
|
145
|
-
juniorWithdrawableAmount,
|
|
146
|
-
seniorWithdrawableAmount,
|
|
147
|
-
step,
|
|
148
|
-
symbol,
|
|
149
|
-
])
|
|
77
|
+
}, [dispatch, step])
|
|
150
78
|
|
|
151
79
|
const handleWithdrawSuccess = useCallback(
|
|
152
80
|
(blockNumber: number) => {
|
|
153
|
-
refreshSeniorWithdrawableAmount()
|
|
154
|
-
refreshJuniorWithdrawableAmount()
|
|
155
|
-
refreshFlcStats()
|
|
156
81
|
if (handleSuccess) {
|
|
157
82
|
handleSuccess(blockNumber)
|
|
158
83
|
}
|
|
159
84
|
},
|
|
160
|
-
[
|
|
161
|
-
handleSuccess,
|
|
162
|
-
refreshFlcStats,
|
|
163
|
-
refreshJuniorWithdrawableAmount,
|
|
164
|
-
refreshSeniorWithdrawableAmount,
|
|
165
|
-
],
|
|
85
|
+
[handleSuccess],
|
|
166
86
|
)
|
|
167
87
|
|
|
168
|
-
if (
|
|
169
|
-
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
|
+
)
|
|
170
98
|
}
|
|
171
99
|
|
|
172
100
|
return (
|
|
173
101
|
<WidgetWrapper
|
|
174
102
|
isOpen
|
|
175
|
-
loadingTitle=
|
|
103
|
+
loadingTitle={title}
|
|
176
104
|
handleClose={handleClose}
|
|
177
105
|
handleSuccess={handleWithdrawSuccess}
|
|
178
106
|
>
|
|
179
|
-
{step === WIDGET_STEP.
|
|
180
|
-
<
|
|
181
|
-
poolUnderlyingToken={poolUnderlyingToken}
|
|
182
|
-
selectedWithdrawType={selectedWithdrawType}
|
|
183
|
-
withdrawTypes={withdrawTypes}
|
|
184
|
-
changeWithdrawType={setSelectedWithdrawType}
|
|
185
|
-
/>
|
|
186
|
-
)}
|
|
187
|
-
{step === WIDGET_STEP.ChooseAmount && selectedWithdrawType && (
|
|
188
|
-
<ChooseAmount
|
|
107
|
+
{step === WIDGET_STEP.ConfirmTransfer && (
|
|
108
|
+
<ConfirmTransfer
|
|
189
109
|
poolInfo={poolInfo}
|
|
110
|
+
tranche={trancheType}
|
|
111
|
+
redemptionStatus={redemptionStatus}
|
|
190
112
|
poolUnderlyingToken={poolUnderlyingToken}
|
|
191
|
-
selectedWithdrawType={selectedWithdrawType}
|
|
192
113
|
/>
|
|
193
114
|
)}
|
|
194
|
-
{step === WIDGET_STEP.Transfer &&
|
|
195
|
-
<Transfer
|
|
196
|
-
poolInfo={poolInfo}
|
|
197
|
-
poolUnderlyingToken={poolUnderlyingToken}
|
|
198
|
-
selectedWithdrawType={selectedWithdrawType}
|
|
199
|
-
/>
|
|
115
|
+
{step === WIDGET_STEP.Transfer && (
|
|
116
|
+
<Transfer poolInfo={poolInfo} tranche={trancheType} />
|
|
200
117
|
)}
|
|
201
|
-
{step === WIDGET_STEP.Done &&
|
|
118
|
+
{step === WIDGET_STEP.Done && (
|
|
202
119
|
<Done
|
|
203
120
|
poolUnderlyingToken={poolUnderlyingToken}
|
|
204
|
-
withdrawAmount={
|
|
121
|
+
withdrawAmount={redemptionStatus.withdrawableAssets}
|
|
205
122
|
handleAction={handleClose}
|
|
206
123
|
/>
|
|
207
124
|
)}
|
|
208
125
|
{step === WIDGET_STEP.Error && (
|
|
209
126
|
<ErrorModal
|
|
210
|
-
title=
|
|
127
|
+
title={title}
|
|
211
128
|
errorReason='Sorry there was an error'
|
|
212
129
|
errorMessage={errorMessage}
|
|
213
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
|
-
}
|
|
@@ -1,101 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
getTrancheVaultContractV2,
|
|
3
|
-
PoolInfoV2,
|
|
4
|
-
UnderlyingTokenInfo,
|
|
5
|
-
} from '@huma-finance/shared'
|
|
6
|
-
import { useWeb3React } from '@web3-react/core'
|
|
7
|
-
import { BigNumber, ethers } from 'ethers'
|
|
8
|
-
import React, { useEffect, useState } from 'react'
|
|
9
|
-
|
|
10
|
-
import { REDEMPTION_TYPE, RedemptionActionInfo } from '.'
|
|
11
|
-
import { useAppDispatch } from '../../../hooks/useRedux'
|
|
12
|
-
import {
|
|
13
|
-
setRedeemAmount,
|
|
14
|
-
setRedeemShares,
|
|
15
|
-
setStep,
|
|
16
|
-
} from '../../../store/widgets.reducers'
|
|
17
|
-
import { WIDGET_STEP } from '../../../store/widgets.store'
|
|
18
|
-
import { InputAmountModal } from '../../InputAmountModal'
|
|
19
|
-
import { LoadingModal } from '../../LoadingModal'
|
|
20
|
-
|
|
21
|
-
type Props = {
|
|
22
|
-
poolInfo: PoolInfoV2
|
|
23
|
-
poolUnderlyingToken: UnderlyingTokenInfo
|
|
24
|
-
redemptionType: REDEMPTION_TYPE
|
|
25
|
-
maxAmount: BigNumber
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
export function ChooseAmount({
|
|
29
|
-
poolInfo,
|
|
30
|
-
poolUnderlyingToken,
|
|
31
|
-
redemptionType,
|
|
32
|
-
maxAmount,
|
|
33
|
-
}: Props): React.ReactElement | null {
|
|
34
|
-
const dispatch = useAppDispatch()
|
|
35
|
-
const { provider } = useWeb3React()
|
|
36
|
-
const { symbol } = poolUnderlyingToken
|
|
37
|
-
const [sharePrice, setSharePrice] = useState(0)
|
|
38
|
-
const [currentAmount, setCurrentAmount] = useState<number>(0)
|
|
39
|
-
const [currentShares, setCurrentShares] = useState<number>(0)
|
|
40
|
-
const redemptionActionInfo = RedemptionActionInfo[redemptionType]
|
|
41
|
-
const maxAmountFormatted = ethers.utils.formatUnits(
|
|
42
|
-
maxAmount,
|
|
43
|
-
poolUnderlyingToken.decimals,
|
|
44
|
-
)
|
|
45
|
-
|
|
46
|
-
useEffect(() => {
|
|
47
|
-
if (maxAmount.gt(0)) {
|
|
48
|
-
const fetchData = async () => {
|
|
49
|
-
const vaultContract = await getTrancheVaultContractV2(
|
|
50
|
-
poolInfo.poolName,
|
|
51
|
-
redemptionActionInfo.tranche,
|
|
52
|
-
provider,
|
|
53
|
-
)
|
|
54
|
-
if (vaultContract) {
|
|
55
|
-
const shares = await vaultContract.convertToShares(maxAmount)
|
|
56
|
-
const price = maxAmount.div(shares)
|
|
57
|
-
setSharePrice(price.toNumber())
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
fetchData()
|
|
61
|
-
}
|
|
62
|
-
}, [maxAmount, poolInfo.poolName, provider, redemptionActionInfo.tranche])
|
|
63
|
-
|
|
64
|
-
const handleChangeAmount = (newAmount: number) => {
|
|
65
|
-
const shares = Number(newAmount) / sharePrice
|
|
66
|
-
setCurrentShares(shares)
|
|
67
|
-
setCurrentAmount(Number(newAmount))
|
|
68
|
-
dispatch(setRedeemAmount(Number(newAmount)))
|
|
69
|
-
dispatch(setRedeemShares(shares))
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
const handleAction = () => {
|
|
73
|
-
dispatch(setStep(WIDGET_STEP.Transfer))
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
if (sharePrice === 0) {
|
|
77
|
-
return (
|
|
78
|
-
<LoadingModal
|
|
79
|
-
title={`${redemptionActionInfo.action} Redemption Request`}
|
|
80
|
-
/>
|
|
81
|
-
)
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
return (
|
|
85
|
-
<InputAmountModal
|
|
86
|
-
title={`${redemptionActionInfo.action} Redemption Request`}
|
|
87
|
-
subTitle={
|
|
88
|
-
redemptionActionInfo.action === 'Create'
|
|
89
|
-
? `Input ${symbol} amount to redeem from ${redemptionActionInfo.tranche} tranche`
|
|
90
|
-
: `Input the amount of the redemption request in ${symbol} that you wish to cancel from the ${redemptionActionInfo.tranche} tranche`
|
|
91
|
-
}
|
|
92
|
-
tokenSymbol={symbol}
|
|
93
|
-
currentAmount={currentAmount}
|
|
94
|
-
handleChangeAmount={handleChangeAmount}
|
|
95
|
-
maxAmount={maxAmountFormatted}
|
|
96
|
-
info={`${currentShares.toFixed(1)} Shares`}
|
|
97
|
-
handleAction={handleAction}
|
|
98
|
-
actionText='SUBMIT'
|
|
99
|
-
/>
|
|
100
|
-
)
|
|
101
|
-
}
|