@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
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@huma-finance/widgets",
|
|
3
|
-
"version": "0.0.48-beta.
|
|
3
|
+
"version": "0.0.48-beta.297+48b8509",
|
|
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.48-beta.
|
|
34
|
-
"@huma-finance/shared": "^0.0.48-beta.
|
|
33
|
+
"@huma-finance/sdk": "^0.0.48-beta.297+48b8509",
|
|
34
|
+
"@huma-finance/shared": "^0.0.48-beta.297+48b8509",
|
|
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": "48b8509c9aa8f1d267f77ab0982400b136e027d4"
|
|
197
197
|
}
|
|
@@ -45,6 +45,11 @@ export function ChooseAmount({
|
|
|
45
45
|
ethers.utils.formatUnits(payoffAmountBN, decimals),
|
|
46
46
|
)
|
|
47
47
|
|
|
48
|
+
console.log('totalDueAmountBN', totalDueAmountBN.toString())
|
|
49
|
+
console.log('payoffAmountBN', payoffAmountBN.toString())
|
|
50
|
+
console.log('payoffAmount', payoffAmount)
|
|
51
|
+
console.log('currentAmount', currentAmount)
|
|
52
|
+
|
|
48
53
|
useEffect(() => {
|
|
49
54
|
setCurrentAmount(totalDueAmount)
|
|
50
55
|
}, [totalDueAmount])
|
|
@@ -10,6 +10,7 @@ type Props = {
|
|
|
10
10
|
subTitle: string
|
|
11
11
|
actionText: string
|
|
12
12
|
tokenSymbol: string
|
|
13
|
+
suffix?: string
|
|
13
14
|
currentAmount: number | string
|
|
14
15
|
maxAmount: number | string
|
|
15
16
|
maxAmountText?: string
|
|
@@ -23,6 +24,7 @@ export function InputAmountModal({
|
|
|
23
24
|
subTitle,
|
|
24
25
|
actionText,
|
|
25
26
|
tokenSymbol,
|
|
27
|
+
suffix: defaultSuffix,
|
|
26
28
|
currentAmount,
|
|
27
29
|
maxAmount,
|
|
28
30
|
maxAmountText = 'MAX',
|
|
@@ -32,7 +34,7 @@ export function InputAmountModal({
|
|
|
32
34
|
}: Props): React.ReactElement | null {
|
|
33
35
|
const theme = useTheme()
|
|
34
36
|
const [inputTouched, setInputTouched] = useState(false)
|
|
35
|
-
const suffix = ` ${tokenSymbol}`
|
|
37
|
+
const suffix = ` ${defaultSuffix ?? tokenSymbol}`
|
|
36
38
|
|
|
37
39
|
const styles = {
|
|
38
40
|
inputAmountWrapper: css`
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { TrancheType } from '@huma-finance/shared'
|
|
2
2
|
import {
|
|
3
3
|
css,
|
|
4
4
|
FormControl,
|
|
@@ -10,7 +10,6 @@ import {
|
|
|
10
10
|
} from '@mui/material'
|
|
11
11
|
import React from 'react'
|
|
12
12
|
|
|
13
|
-
import { WithdrawType } from '.'
|
|
14
13
|
import { useAppDispatch } from '../../../hooks/useRedux'
|
|
15
14
|
import { setStep } from '../../../store/widgets.reducers'
|
|
16
15
|
import { WIDGET_STEP } from '../../../store/widgets.store'
|
|
@@ -18,21 +17,16 @@ import { BottomButton } from '../../BottomButton'
|
|
|
18
17
|
import { WrapperModal } from '../../WrapperModal'
|
|
19
18
|
|
|
20
19
|
type Props = {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
withdrawTypes: WithdrawType[]
|
|
24
|
-
changeWithdrawType: (WithdrawType: WithdrawType) => void
|
|
20
|
+
selectedTranche: TrancheType | undefined
|
|
21
|
+
changeTranche: (tranche: TrancheType) => void
|
|
25
22
|
}
|
|
26
23
|
|
|
27
24
|
export function ChooseTranche({
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
withdrawTypes,
|
|
31
|
-
changeWithdrawType,
|
|
25
|
+
selectedTranche,
|
|
26
|
+
changeTranche,
|
|
32
27
|
}: Props): React.ReactElement | null {
|
|
33
28
|
const theme = useTheme()
|
|
34
29
|
const dispatch = useAppDispatch()
|
|
35
|
-
const { symbol } = poolUnderlyingToken
|
|
36
30
|
|
|
37
31
|
const styles = {
|
|
38
32
|
subTitle: css`
|
|
@@ -61,34 +55,35 @@ export function ChooseTranche({
|
|
|
61
55
|
`,
|
|
62
56
|
}
|
|
63
57
|
|
|
64
|
-
const handleChangeWithdrawType = (withdrawTypeValue: string | number) => {
|
|
65
|
-
const withdrawType = withdrawTypes.find(
|
|
66
|
-
(item) => item.value === withdrawTypeValue,
|
|
67
|
-
)
|
|
68
|
-
if (withdrawType) {
|
|
69
|
-
changeWithdrawType(withdrawType)
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
|
|
73
58
|
const handleNext = () => {
|
|
74
|
-
|
|
75
|
-
dispatch(setStep(WIDGET_STEP.ChooseAmount))
|
|
76
|
-
} else {
|
|
77
|
-
dispatch(setStep(WIDGET_STEP.Transfer))
|
|
78
|
-
}
|
|
59
|
+
dispatch(setStep(WIDGET_STEP.ChooseAmount))
|
|
79
60
|
}
|
|
80
61
|
|
|
62
|
+
const items: {
|
|
63
|
+
label: string
|
|
64
|
+
value: TrancheType
|
|
65
|
+
}[] = [
|
|
66
|
+
{
|
|
67
|
+
label: 'Senior',
|
|
68
|
+
value: 'senior',
|
|
69
|
+
},
|
|
70
|
+
{
|
|
71
|
+
label: 'Junior',
|
|
72
|
+
value: 'junior',
|
|
73
|
+
},
|
|
74
|
+
]
|
|
75
|
+
|
|
81
76
|
return (
|
|
82
|
-
<WrapperModal title=
|
|
77
|
+
<WrapperModal title='Redemption'>
|
|
83
78
|
<FormControl>
|
|
84
|
-
<FormLabel css={styles.subTitle}>Select
|
|
79
|
+
<FormLabel css={styles.subTitle}>Select Tranche Type</FormLabel>
|
|
85
80
|
<RadioGroup
|
|
86
81
|
aria-labelledby='buttons-group-label'
|
|
87
82
|
name='radio-buttons-group'
|
|
88
83
|
css={styles.radioGroup}
|
|
89
|
-
onChange={(e) =>
|
|
84
|
+
onChange={(e) => changeTranche(e.target.value as TrancheType)}
|
|
90
85
|
>
|
|
91
|
-
{
|
|
86
|
+
{items.map((item) => (
|
|
92
87
|
<FormControlLabel
|
|
93
88
|
key={item.label}
|
|
94
89
|
value={item.value}
|
|
@@ -109,7 +104,7 @@ export function ChooseTranche({
|
|
|
109
104
|
</FormControl>
|
|
110
105
|
<BottomButton
|
|
111
106
|
variant='contained'
|
|
112
|
-
disabled={!
|
|
107
|
+
disabled={!selectedTranche}
|
|
113
108
|
onClick={handleNext}
|
|
114
109
|
>
|
|
115
110
|
NEXT
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { formatNumber, UnderlyingTokenInfo } from '@huma-finance/shared'
|
|
2
|
+
import { ethers } from 'ethers'
|
|
3
|
+
import React, { useState } from 'react'
|
|
4
|
+
|
|
5
|
+
import { TrancheInfo } from '.'
|
|
6
|
+
import { useAppDispatch } from '../../../hooks/useRedux'
|
|
7
|
+
import {
|
|
8
|
+
setRedeemAmount,
|
|
9
|
+
setRedeemShares,
|
|
10
|
+
setStep,
|
|
11
|
+
} from '../../../store/widgets.reducers'
|
|
12
|
+
import { WIDGET_STEP } from '../../../store/widgets.store'
|
|
13
|
+
import { InputAmountModal } from '../../InputAmountModal'
|
|
14
|
+
|
|
15
|
+
type Props = {
|
|
16
|
+
poolUnderlyingToken: UnderlyingTokenInfo
|
|
17
|
+
trancheInfo: TrancheInfo
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export function ChooseAmount({
|
|
21
|
+
poolUnderlyingToken,
|
|
22
|
+
trancheInfo,
|
|
23
|
+
}: Props): React.ReactElement | null {
|
|
24
|
+
const dispatch = useAppDispatch()
|
|
25
|
+
const { symbol } = poolUnderlyingToken
|
|
26
|
+
const [currentAmount, setCurrentAmount] = useState<number>(0)
|
|
27
|
+
const [currentShares, setCurrentShares] = useState<number>(0)
|
|
28
|
+
const maxSharesFormatted = ethers.utils.formatUnits(
|
|
29
|
+
trancheInfo.shares,
|
|
30
|
+
poolUnderlyingToken.decimals,
|
|
31
|
+
)
|
|
32
|
+
const sharePrice =
|
|
33
|
+
trancheInfo.assets.toNumber() / trancheInfo.shares.toNumber()
|
|
34
|
+
|
|
35
|
+
const handleChangeShares = (newShares: number) => {
|
|
36
|
+
const amount = Number(newShares) * sharePrice
|
|
37
|
+
setCurrentShares(Number(newShares))
|
|
38
|
+
setCurrentAmount(amount)
|
|
39
|
+
dispatch(setRedeemShares(Number(newShares)))
|
|
40
|
+
dispatch(setRedeemAmount(amount))
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const handleAction = () => {
|
|
44
|
+
dispatch(setStep(WIDGET_STEP.Transfer))
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
return (
|
|
48
|
+
<InputAmountModal
|
|
49
|
+
title='Redemption'
|
|
50
|
+
subTitle={`Enter number of shares to redeem from ${trancheInfo.tranche} tranche`}
|
|
51
|
+
tokenSymbol={symbol}
|
|
52
|
+
currentAmount={currentShares}
|
|
53
|
+
handleChangeAmount={handleChangeShares}
|
|
54
|
+
maxAmount={maxSharesFormatted}
|
|
55
|
+
info={`${String(formatNumber(currentAmount))} ${symbol}`}
|
|
56
|
+
suffix='Shares'
|
|
57
|
+
handleAction={handleAction}
|
|
58
|
+
actionText='REQUEST'
|
|
59
|
+
/>
|
|
60
|
+
)
|
|
61
|
+
}
|
|
@@ -4,10 +4,10 @@ import {
|
|
|
4
4
|
useTrancheVaultContractV2,
|
|
5
5
|
} from '@huma-finance/shared'
|
|
6
6
|
import { useWeb3React } from '@web3-react/core'
|
|
7
|
+
import { ethers } from 'ethers'
|
|
7
8
|
import React, { useCallback } from 'react'
|
|
8
9
|
|
|
9
|
-
import {
|
|
10
|
-
import { REDEMPTION_TYPE, RedemptionActionInfo } from '.'
|
|
10
|
+
import { TrancheInfo } from '.'
|
|
11
11
|
import { useAppDispatch, useAppSelector } from '../../../hooks/useRedux'
|
|
12
12
|
import { setStep } from '../../../store/widgets.reducers'
|
|
13
13
|
import { selectWidgetState } from '../../../store/widgets.selectors'
|
|
@@ -17,43 +17,38 @@ import { TxSendModalV2 } from '../../TxSendModalV2'
|
|
|
17
17
|
type Props = {
|
|
18
18
|
poolInfo: PoolInfoV2
|
|
19
19
|
poolUnderlyingToken: UnderlyingTokenInfo
|
|
20
|
-
|
|
20
|
+
trancheInfo: TrancheInfo
|
|
21
21
|
}
|
|
22
22
|
|
|
23
23
|
export function Transfer({
|
|
24
24
|
poolInfo,
|
|
25
25
|
poolUnderlyingToken,
|
|
26
|
-
|
|
26
|
+
trancheInfo,
|
|
27
27
|
}: Props): React.ReactElement | null {
|
|
28
28
|
const dispatch = useAppDispatch()
|
|
29
29
|
const { decimals } = poolUnderlyingToken
|
|
30
30
|
const { account, provider } = useWeb3React()
|
|
31
31
|
const { redeemShares } = useAppSelector(selectWidgetState)
|
|
32
|
-
const redemptionActionInfo = RedemptionActionInfo[redemptionType]
|
|
33
32
|
const trancheVaultContract = useTrancheVaultContractV2(
|
|
34
33
|
poolInfo.poolName,
|
|
35
|
-
|
|
34
|
+
trancheInfo.tranche,
|
|
36
35
|
provider,
|
|
37
36
|
account,
|
|
38
37
|
)
|
|
39
38
|
const redeemSharesBN = ethers.utils.parseUnits(String(redeemShares), decimals)
|
|
40
|
-
const method =
|
|
41
|
-
redemptionActionInfo.action === 'Create'
|
|
42
|
-
? 'addRedemptionRequest'
|
|
43
|
-
: 'cancelRedemptionRequest'
|
|
44
39
|
|
|
45
40
|
const handleSuccess = useCallback(() => {
|
|
46
41
|
dispatch(setStep(WIDGET_STEP.Done))
|
|
47
42
|
}, [dispatch])
|
|
48
43
|
|
|
49
|
-
if (!trancheVaultContract
|
|
44
|
+
if (!trancheVaultContract) {
|
|
50
45
|
return null
|
|
51
46
|
}
|
|
52
47
|
|
|
53
48
|
return (
|
|
54
49
|
<TxSendModalV2
|
|
55
50
|
contract={trancheVaultContract}
|
|
56
|
-
method=
|
|
51
|
+
method='addRedemptionRequest'
|
|
57
52
|
params={[redeemSharesBN]}
|
|
58
53
|
handleSuccess={handleSuccess}
|
|
59
54
|
/>
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { formatNumber } from '@huma-finance/shared'
|
|
2
|
+
import React from 'react'
|
|
3
|
+
|
|
4
|
+
import { useAppSelector } from '../../../hooks/useRedux'
|
|
5
|
+
import { selectWidgetState } from '../../../store/widgets.selectors'
|
|
6
|
+
import { TxDoneModal } from '../../TxDoneModal'
|
|
7
|
+
|
|
8
|
+
type Props = {
|
|
9
|
+
handleAction: () => void
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export function Done({ handleAction }: Props): React.ReactElement {
|
|
13
|
+
const { redeemShares } = useAppSelector(selectWidgetState)
|
|
14
|
+
|
|
15
|
+
const content = [
|
|
16
|
+
`${formatNumber(redeemShares)} shares requested for redemption`,
|
|
17
|
+
]
|
|
18
|
+
|
|
19
|
+
return <TxDoneModal handleAction={handleAction} content={content} />
|
|
20
|
+
}
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
import {
|
|
2
|
+
getTrancheAssetsAndShares,
|
|
3
|
+
POOL_NAME,
|
|
4
|
+
TrancheType,
|
|
5
|
+
usePoolInfoV2,
|
|
6
|
+
usePoolUnderlyingTokenInfoV2,
|
|
7
|
+
} from '@huma-finance/shared'
|
|
8
|
+
import { useWeb3React } from '@web3-react/core'
|
|
9
|
+
import { BigNumber } from 'ethers'
|
|
10
|
+
import React, { useCallback, useEffect, useState } from 'react'
|
|
11
|
+
import { useDispatch } from 'react-redux'
|
|
12
|
+
|
|
13
|
+
import { useAppSelector } from '../../../hooks/useRedux'
|
|
14
|
+
import { setStep } from '../../../store/widgets.reducers'
|
|
15
|
+
import { selectWidgetState } from '../../../store/widgets.selectors'
|
|
16
|
+
import { WIDGET_STEP } from '../../../store/widgets.store'
|
|
17
|
+
import { ErrorModal } from '../../ErrorModal'
|
|
18
|
+
import { WidgetWrapper } from '../../WidgetWrapper'
|
|
19
|
+
import { ChooseTranche } from './1-ChooseTranche'
|
|
20
|
+
import { ChooseAmount } from './2-ChooseAmount'
|
|
21
|
+
import { Transfer } from './3-Transfer'
|
|
22
|
+
import { Done } from './4-Done'
|
|
23
|
+
|
|
24
|
+
export type TrancheInfo = {
|
|
25
|
+
tranche: TrancheType
|
|
26
|
+
assets: BigNumber
|
|
27
|
+
shares: BigNumber
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Lend pool add redemption props
|
|
32
|
+
* @typedef {Object} AddRedemptionPropsV2
|
|
33
|
+
* @property {POOL_NAME} poolName The name of the pool.
|
|
34
|
+
* @property {function():void} handleClose Function to notify to close the widget modal when user clicks the 'x' close button.
|
|
35
|
+
* @property {function((number|undefined)):void|undefined} handleSuccess Optional function to notify that the lending pool withdraw action is successful.
|
|
36
|
+
*/
|
|
37
|
+
export type AddRedemptionPropsV2 = {
|
|
38
|
+
poolName: keyof typeof POOL_NAME
|
|
39
|
+
handleClose: () => void
|
|
40
|
+
handleSuccess?: (blockNumber?: number) => void
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export function AddRedemptionV2({
|
|
44
|
+
poolName: poolNameStr,
|
|
45
|
+
handleClose,
|
|
46
|
+
handleSuccess,
|
|
47
|
+
}: AddRedemptionPropsV2): React.ReactElement | null {
|
|
48
|
+
const title = 'Redemption'
|
|
49
|
+
const dispatch = useDispatch()
|
|
50
|
+
const { account, chainId, provider } = useWeb3React()
|
|
51
|
+
const poolName = POOL_NAME[poolNameStr]
|
|
52
|
+
const poolInfo = usePoolInfoV2(poolName, chainId)
|
|
53
|
+
const { step, errorMessage, errorReason } = useAppSelector(selectWidgetState)
|
|
54
|
+
const poolUnderlyingToken = usePoolUnderlyingTokenInfoV2(poolName, provider)
|
|
55
|
+
const [seniorTrancheInfo, setSeniorTrancheInfo] = useState<TrancheInfo>()
|
|
56
|
+
const [juniorTrancheInfo, setJuniorTrancheInfo] = useState<TrancheInfo>()
|
|
57
|
+
const [trancheInfo, setTrancheInfo] = useState<TrancheInfo>()
|
|
58
|
+
const trancheInfoFetched = seniorTrancheInfo && juniorTrancheInfo
|
|
59
|
+
|
|
60
|
+
useEffect(() => {
|
|
61
|
+
if (account) {
|
|
62
|
+
getTrancheAssetsAndShares(poolName, 'senior', account, provider).then(
|
|
63
|
+
(info) => {
|
|
64
|
+
if (info) {
|
|
65
|
+
setSeniorTrancheInfo({ ...info, tranche: 'senior' })
|
|
66
|
+
}
|
|
67
|
+
},
|
|
68
|
+
)
|
|
69
|
+
getTrancheAssetsAndShares(poolName, 'junior', account, provider).then(
|
|
70
|
+
(info) => {
|
|
71
|
+
if (info) {
|
|
72
|
+
setJuniorTrancheInfo({ ...info, tranche: 'junior' })
|
|
73
|
+
}
|
|
74
|
+
},
|
|
75
|
+
)
|
|
76
|
+
}
|
|
77
|
+
}, [account, poolName, provider])
|
|
78
|
+
|
|
79
|
+
useEffect(() => {
|
|
80
|
+
if (!step && trancheInfoFetched) {
|
|
81
|
+
if (juniorTrancheInfo.assets.gt(0) && seniorTrancheInfo.assets.lte(0)) {
|
|
82
|
+
setTrancheInfo(juniorTrancheInfo)
|
|
83
|
+
dispatch(setStep(WIDGET_STEP.ChooseAmount))
|
|
84
|
+
return
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
if (seniorTrancheInfo.assets.gt(0) && juniorTrancheInfo.assets.lte(0)) {
|
|
88
|
+
setTrancheInfo(seniorTrancheInfo)
|
|
89
|
+
dispatch(setStep(WIDGET_STEP.ChooseAmount))
|
|
90
|
+
return
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
if (juniorTrancheInfo.assets.gt(0) && seniorTrancheInfo.assets.gt(0)) {
|
|
94
|
+
dispatch(setStep(WIDGET_STEP.ChooseTranche))
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
}, [dispatch, juniorTrancheInfo, seniorTrancheInfo, step, trancheInfoFetched])
|
|
98
|
+
|
|
99
|
+
const handleRedeemSuccess = useCallback(
|
|
100
|
+
(blockNumber: number) => {
|
|
101
|
+
if (handleSuccess) {
|
|
102
|
+
handleSuccess(blockNumber)
|
|
103
|
+
}
|
|
104
|
+
},
|
|
105
|
+
[handleSuccess],
|
|
106
|
+
)
|
|
107
|
+
|
|
108
|
+
const handleChangeTranche = useCallback(
|
|
109
|
+
(tranche: TrancheType) => {
|
|
110
|
+
if (tranche === 'senior') {
|
|
111
|
+
setTrancheInfo(seniorTrancheInfo)
|
|
112
|
+
} else if (tranche === 'junior') {
|
|
113
|
+
setTrancheInfo(juniorTrancheInfo)
|
|
114
|
+
} else {
|
|
115
|
+
setTrancheInfo(undefined)
|
|
116
|
+
}
|
|
117
|
+
},
|
|
118
|
+
[juniorTrancheInfo, seniorTrancheInfo],
|
|
119
|
+
)
|
|
120
|
+
|
|
121
|
+
if (!poolInfo || !poolUnderlyingToken || !trancheInfoFetched) {
|
|
122
|
+
return (
|
|
123
|
+
<WidgetWrapper
|
|
124
|
+
isOpen
|
|
125
|
+
isLoading
|
|
126
|
+
loadingTitle={title}
|
|
127
|
+
handleClose={handleClose}
|
|
128
|
+
handleSuccess={handleSuccess}
|
|
129
|
+
/>
|
|
130
|
+
)
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
return (
|
|
134
|
+
<WidgetWrapper
|
|
135
|
+
isOpen
|
|
136
|
+
loadingTitle={title}
|
|
137
|
+
handleClose={handleClose}
|
|
138
|
+
handleSuccess={handleRedeemSuccess}
|
|
139
|
+
>
|
|
140
|
+
{step === WIDGET_STEP.ChooseTranche && (
|
|
141
|
+
<ChooseTranche
|
|
142
|
+
selectedTranche={trancheInfo?.tranche}
|
|
143
|
+
changeTranche={handleChangeTranche}
|
|
144
|
+
/>
|
|
145
|
+
)}
|
|
146
|
+
{step === WIDGET_STEP.ChooseAmount && trancheInfo && (
|
|
147
|
+
<ChooseAmount
|
|
148
|
+
poolUnderlyingToken={poolUnderlyingToken}
|
|
149
|
+
trancheInfo={trancheInfo}
|
|
150
|
+
/>
|
|
151
|
+
)}
|
|
152
|
+
{step === WIDGET_STEP.Transfer && trancheInfo && (
|
|
153
|
+
<Transfer
|
|
154
|
+
poolInfo={poolInfo}
|
|
155
|
+
poolUnderlyingToken={poolUnderlyingToken}
|
|
156
|
+
trancheInfo={trancheInfo}
|
|
157
|
+
/>
|
|
158
|
+
)}
|
|
159
|
+
{step === WIDGET_STEP.Done && trancheInfo && (
|
|
160
|
+
<Done handleAction={handleClose} />
|
|
161
|
+
)}
|
|
162
|
+
{step === WIDGET_STEP.Error && (
|
|
163
|
+
<ErrorModal
|
|
164
|
+
title={title}
|
|
165
|
+
errorReason={errorReason}
|
|
166
|
+
errorMessage={errorMessage}
|
|
167
|
+
handleOk={handleClose}
|
|
168
|
+
/>
|
|
169
|
+
)}
|
|
170
|
+
</WidgetWrapper>
|
|
171
|
+
)
|
|
172
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import {
|
|
2
|
+
PoolInfoV2,
|
|
3
|
+
TrancheType,
|
|
4
|
+
useTrancheVaultContractV2,
|
|
5
|
+
} from '@huma-finance/shared'
|
|
6
|
+
import { useWeb3React } from '@web3-react/core'
|
|
7
|
+
import React, { useCallback } from 'react'
|
|
8
|
+
|
|
9
|
+
import { RedemptionInfo } from '.'
|
|
10
|
+
import { useAppDispatch } from '../../../hooks/useRedux'
|
|
11
|
+
import { setStep } from '../../../store/widgets.reducers'
|
|
12
|
+
import { WIDGET_STEP } from '../../../store/widgets.store'
|
|
13
|
+
import { TxSendModalV2 } from '../../TxSendModalV2'
|
|
14
|
+
|
|
15
|
+
type Props = {
|
|
16
|
+
poolInfo: PoolInfoV2
|
|
17
|
+
trancheType: TrancheType
|
|
18
|
+
redemptionInfo: RedemptionInfo
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export function Transfer({
|
|
22
|
+
poolInfo,
|
|
23
|
+
trancheType,
|
|
24
|
+
redemptionInfo,
|
|
25
|
+
}: Props): React.ReactElement | null {
|
|
26
|
+
const dispatch = useAppDispatch()
|
|
27
|
+
const { account, provider } = useWeb3React()
|
|
28
|
+
const trancheVaultContract = useTrancheVaultContractV2(
|
|
29
|
+
poolInfo.poolName,
|
|
30
|
+
trancheType,
|
|
31
|
+
provider,
|
|
32
|
+
account,
|
|
33
|
+
)
|
|
34
|
+
|
|
35
|
+
const handleSuccess = useCallback(() => {
|
|
36
|
+
dispatch(setStep(WIDGET_STEP.Done))
|
|
37
|
+
}, [dispatch])
|
|
38
|
+
|
|
39
|
+
if (!trancheVaultContract) {
|
|
40
|
+
return null
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
return (
|
|
44
|
+
<TxSendModalV2
|
|
45
|
+
contract={trancheVaultContract}
|
|
46
|
+
method='cancelRedemptionRequest'
|
|
47
|
+
params={[redemptionInfo.shares]}
|
|
48
|
+
handleSuccess={handleSuccess}
|
|
49
|
+
/>
|
|
50
|
+
)
|
|
51
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { UnderlyingTokenInfo } from '@huma-finance/shared'
|
|
2
|
+
import { ethers } from 'ethers'
|
|
3
|
+
import React from 'react'
|
|
4
|
+
|
|
5
|
+
import { RedemptionInfo } from '.'
|
|
6
|
+
import { TxDoneModal } from '../../TxDoneModal'
|
|
7
|
+
|
|
8
|
+
type Props = {
|
|
9
|
+
poolUnderlyingToken: UnderlyingTokenInfo
|
|
10
|
+
redemptionInfo: RedemptionInfo
|
|
11
|
+
handleAction: () => void
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export function Done({
|
|
15
|
+
poolUnderlyingToken,
|
|
16
|
+
redemptionInfo,
|
|
17
|
+
handleAction,
|
|
18
|
+
}: Props): React.ReactElement {
|
|
19
|
+
const shares = ethers.utils.formatUnits(
|
|
20
|
+
redemptionInfo.shares,
|
|
21
|
+
poolUnderlyingToken.decimals,
|
|
22
|
+
)
|
|
23
|
+
|
|
24
|
+
const content = [
|
|
25
|
+
`You successfully canceled ${shares} shares redemption request.`,
|
|
26
|
+
]
|
|
27
|
+
|
|
28
|
+
return <TxDoneModal handleAction={handleAction} content={content} />
|
|
29
|
+
}
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import {
|
|
2
|
+
POOL_NAME,
|
|
3
|
+
TrancheType,
|
|
4
|
+
useCancellableRedemptionInfoV2,
|
|
5
|
+
usePoolInfoV2,
|
|
6
|
+
usePoolUnderlyingTokenInfoV2,
|
|
7
|
+
} from '@huma-finance/shared'
|
|
8
|
+
import { useWeb3React } from '@web3-react/core'
|
|
9
|
+
import { BigNumber } from 'ethers'
|
|
10
|
+
import React, { useCallback, useEffect } from 'react'
|
|
11
|
+
import { useDispatch } from 'react-redux'
|
|
12
|
+
|
|
13
|
+
import { useAppSelector } from '../../../hooks/useRedux'
|
|
14
|
+
import { setStep } from '../../../store/widgets.reducers'
|
|
15
|
+
import { selectWidgetState } from '../../../store/widgets.selectors'
|
|
16
|
+
import { WIDGET_STEP } from '../../../store/widgets.store'
|
|
17
|
+
import { ErrorModal } from '../../ErrorModal'
|
|
18
|
+
import { WidgetWrapper } from '../../WidgetWrapper'
|
|
19
|
+
import { Transfer } from './1-Transfer'
|
|
20
|
+
import { Done } from './2-Done'
|
|
21
|
+
|
|
22
|
+
export type RedemptionInfo = {
|
|
23
|
+
shares: BigNumber
|
|
24
|
+
amount: BigNumber
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Lend pool cancel redemption request props
|
|
29
|
+
* @typedef {Object} CancelRedemptionPropsV2
|
|
30
|
+
* @property {POOL_NAME} poolName The name of the pool.
|
|
31
|
+
* @property {TrancheType} trancheType The type of the tranche.
|
|
32
|
+
* @property {function():void} handleClose Function to notify to close the widget modal when user clicks the 'x' close button.
|
|
33
|
+
* @property {function((number|undefined)):void|undefined} handleSuccess Optional function to notify that the lending pool withdraw action is successful.
|
|
34
|
+
*/
|
|
35
|
+
export type CancelRedemptionPropsV2 = {
|
|
36
|
+
poolName: keyof typeof POOL_NAME
|
|
37
|
+
trancheType: TrancheType
|
|
38
|
+
handleClose: () => void
|
|
39
|
+
handleSuccess?: (blockNumber?: number) => void
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export function CancelRedemptionV2({
|
|
43
|
+
poolName: poolNameStr,
|
|
44
|
+
trancheType,
|
|
45
|
+
handleClose,
|
|
46
|
+
handleSuccess,
|
|
47
|
+
}: CancelRedemptionPropsV2): React.ReactElement | null {
|
|
48
|
+
const title = 'Cancel redemption'
|
|
49
|
+
const dispatch = useDispatch()
|
|
50
|
+
const { account, chainId, provider } = useWeb3React()
|
|
51
|
+
const poolName = POOL_NAME[poolNameStr]
|
|
52
|
+
const poolInfo = usePoolInfoV2(poolName, chainId)
|
|
53
|
+
const { step, errorMessage, errorReason } = useAppSelector(selectWidgetState)
|
|
54
|
+
const poolUnderlyingToken = usePoolUnderlyingTokenInfoV2(poolName, provider)
|
|
55
|
+
const [redemptionInfo] = useCancellableRedemptionInfoV2(
|
|
56
|
+
poolName,
|
|
57
|
+
trancheType,
|
|
58
|
+
account,
|
|
59
|
+
provider,
|
|
60
|
+
)
|
|
61
|
+
|
|
62
|
+
useEffect(() => {
|
|
63
|
+
if (!step) {
|
|
64
|
+
dispatch(setStep(WIDGET_STEP.Transfer))
|
|
65
|
+
}
|
|
66
|
+
}, [dispatch, step])
|
|
67
|
+
|
|
68
|
+
const handleRedeemSuccess = useCallback(
|
|
69
|
+
(blockNumber: number) => {
|
|
70
|
+
if (handleSuccess) {
|
|
71
|
+
handleSuccess(blockNumber)
|
|
72
|
+
}
|
|
73
|
+
},
|
|
74
|
+
[handleSuccess],
|
|
75
|
+
)
|
|
76
|
+
|
|
77
|
+
if (!poolInfo || !poolUnderlyingToken || !redemptionInfo) {
|
|
78
|
+
return (
|
|
79
|
+
<WidgetWrapper
|
|
80
|
+
isOpen
|
|
81
|
+
isLoading
|
|
82
|
+
loadingTitle={title}
|
|
83
|
+
handleClose={handleClose}
|
|
84
|
+
handleSuccess={handleSuccess}
|
|
85
|
+
/>
|
|
86
|
+
)
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
return (
|
|
90
|
+
<WidgetWrapper
|
|
91
|
+
isOpen
|
|
92
|
+
loadingTitle={title}
|
|
93
|
+
handleClose={handleClose}
|
|
94
|
+
handleSuccess={handleRedeemSuccess}
|
|
95
|
+
>
|
|
96
|
+
{step === WIDGET_STEP.Transfer && (
|
|
97
|
+
<Transfer
|
|
98
|
+
poolInfo={poolInfo}
|
|
99
|
+
trancheType={trancheType}
|
|
100
|
+
redemptionInfo={redemptionInfo}
|
|
101
|
+
/>
|
|
102
|
+
)}
|
|
103
|
+
{step === WIDGET_STEP.Done && (
|
|
104
|
+
<Done
|
|
105
|
+
poolUnderlyingToken={poolUnderlyingToken}
|
|
106
|
+
handleAction={handleClose}
|
|
107
|
+
redemptionInfo={redemptionInfo}
|
|
108
|
+
/>
|
|
109
|
+
)}
|
|
110
|
+
{step === WIDGET_STEP.Error && (
|
|
111
|
+
<ErrorModal
|
|
112
|
+
title={title}
|
|
113
|
+
errorReason={errorReason}
|
|
114
|
+
errorMessage={errorMessage}
|
|
115
|
+
handleOk={handleClose}
|
|
116
|
+
/>
|
|
117
|
+
)}
|
|
118
|
+
</WidgetWrapper>
|
|
119
|
+
)
|
|
120
|
+
}
|