@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
|
@@ -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
|
-
}
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import { formatMoney, UnderlyingTokenInfo } from '@huma-finance/shared'
|
|
2
|
-
import React from 'react'
|
|
3
|
-
|
|
4
|
-
import { REDEMPTION_TYPE, RedemptionActionInfo } from '.'
|
|
5
|
-
import { useAppSelector } from '../../../hooks/useRedux'
|
|
6
|
-
import { selectWidgetState } from '../../../store/widgets.selectors'
|
|
7
|
-
import { TxDoneModal } from '../../TxDoneModal'
|
|
8
|
-
|
|
9
|
-
type Props = {
|
|
10
|
-
poolUnderlyingToken: UnderlyingTokenInfo
|
|
11
|
-
redemptionType: REDEMPTION_TYPE
|
|
12
|
-
handleAction: () => void
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export function Done({
|
|
16
|
-
poolUnderlyingToken,
|
|
17
|
-
redemptionType,
|
|
18
|
-
handleAction,
|
|
19
|
-
}: Props): React.ReactElement {
|
|
20
|
-
const { symbol } = poolUnderlyingToken
|
|
21
|
-
const { redeemAmount, redeemShares } = useAppSelector(selectWidgetState)
|
|
22
|
-
const redemptionActionInfo = RedemptionActionInfo[redemptionType]
|
|
23
|
-
const isCreate = redemptionActionInfo.action === 'Create'
|
|
24
|
-
|
|
25
|
-
const content = [
|
|
26
|
-
`You successfully ${isCreate ? 'created' : 'canceled'} ${formatMoney(
|
|
27
|
-
redeemAmount,
|
|
28
|
-
)} ${symbol} (${redeemShares} shares) redemption request.`,
|
|
29
|
-
isCreate ? `Note: Exact redemption amounts may vary once processed.` : '',
|
|
30
|
-
]
|
|
31
|
-
|
|
32
|
-
return <TxDoneModal handleAction={handleAction} content={content} />
|
|
33
|
-
}
|
|
@@ -1,207 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
POOL_NAME,
|
|
3
|
-
useCancellableRedemptionInfoV2,
|
|
4
|
-
useLenderPositionV2,
|
|
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 { ChooseAction } from './1-ChooseAction'
|
|
20
|
-
import { ChooseAmount } from './2-ChooseAmount'
|
|
21
|
-
import { Transfer } from './3-Transfer'
|
|
22
|
-
import { Done } from './4-Done'
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* Lend pool withdraw props
|
|
26
|
-
* @typedef {Object} LendRedeemPropsV2
|
|
27
|
-
* @property {POOL_NAME} poolName The name of the pool.
|
|
28
|
-
* @property {function():void} handleClose Function to notify to close the widget modal when user clicks the 'x' close button.
|
|
29
|
-
* @property {function((number|undefined)):void|undefined} handleSuccess Optional function to notify that the lending pool withdraw action is successful.
|
|
30
|
-
*/
|
|
31
|
-
export type LendRedeemPropsV2 = {
|
|
32
|
-
poolName: keyof typeof POOL_NAME
|
|
33
|
-
handleClose: () => void
|
|
34
|
-
handleSuccess?: (blockNumber?: number) => void
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
export enum REDEMPTION_TYPE {
|
|
38
|
-
AddSeniorRedemption = 1,
|
|
39
|
-
CancelSeniorRedemption = 2,
|
|
40
|
-
AddJuniorRedemption = 3,
|
|
41
|
-
CancelJuniorRedemption = 4,
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
export const RedemptionActionInfo: {
|
|
45
|
-
[key in REDEMPTION_TYPE]: {
|
|
46
|
-
action: 'Create' | 'Cancel'
|
|
47
|
-
tranche: 'senior' | 'junior'
|
|
48
|
-
}
|
|
49
|
-
} = {
|
|
50
|
-
[REDEMPTION_TYPE.AddSeniorRedemption]: {
|
|
51
|
-
action: 'Create',
|
|
52
|
-
tranche: 'senior',
|
|
53
|
-
},
|
|
54
|
-
[REDEMPTION_TYPE.CancelSeniorRedemption]: {
|
|
55
|
-
action: 'Cancel',
|
|
56
|
-
tranche: 'senior',
|
|
57
|
-
},
|
|
58
|
-
[REDEMPTION_TYPE.AddJuniorRedemption]: {
|
|
59
|
-
action: 'Create',
|
|
60
|
-
tranche: 'junior',
|
|
61
|
-
},
|
|
62
|
-
[REDEMPTION_TYPE.CancelJuniorRedemption]: {
|
|
63
|
-
action: 'Cancel',
|
|
64
|
-
tranche: 'junior',
|
|
65
|
-
},
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
export type RedemptionInfo = {
|
|
69
|
-
shares: BigNumber
|
|
70
|
-
amount: BigNumber
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
export function LendRedeemV2({
|
|
74
|
-
poolName: poolNameStr,
|
|
75
|
-
handleClose,
|
|
76
|
-
handleSuccess,
|
|
77
|
-
}: LendRedeemPropsV2): React.ReactElement | null {
|
|
78
|
-
const dispatch = useDispatch()
|
|
79
|
-
const { account, chainId, provider } = useWeb3React()
|
|
80
|
-
const poolName = POOL_NAME[poolNameStr]
|
|
81
|
-
const poolInfo = usePoolInfoV2(poolName, chainId)
|
|
82
|
-
const { step, errorMessage, errorReason } = useAppSelector(selectWidgetState)
|
|
83
|
-
const [seniorRedemptionInfo, refreshSeniorRedemptionInfo] =
|
|
84
|
-
useCancellableRedemptionInfoV2(poolName, 'senior', account, provider)
|
|
85
|
-
const [juniorRedemptionInfo, refreshJuniorRedemptionInfo] =
|
|
86
|
-
useCancellableRedemptionInfoV2(poolName, 'junior', account, provider)
|
|
87
|
-
const poolUnderlyingToken = usePoolUnderlyingTokenInfoV2(poolName, provider)
|
|
88
|
-
const [seniorPosition, refreshSeniorPosition] = useLenderPositionV2(
|
|
89
|
-
poolName,
|
|
90
|
-
'senior',
|
|
91
|
-
account,
|
|
92
|
-
provider,
|
|
93
|
-
)
|
|
94
|
-
const [juniorPosition, refreshJuniorPosition] = useLenderPositionV2(
|
|
95
|
-
poolName,
|
|
96
|
-
'junior',
|
|
97
|
-
account,
|
|
98
|
-
provider,
|
|
99
|
-
)
|
|
100
|
-
const [redemptionType, setRedemptionType] = useState<REDEMPTION_TYPE>()
|
|
101
|
-
const redemptionActionInfo = redemptionType
|
|
102
|
-
? RedemptionActionInfo[redemptionType]
|
|
103
|
-
: undefined
|
|
104
|
-
|
|
105
|
-
useEffect(() => {
|
|
106
|
-
if (!step) {
|
|
107
|
-
dispatch(setStep(WIDGET_STEP.ChooseTranche))
|
|
108
|
-
}
|
|
109
|
-
}, [dispatch, step])
|
|
110
|
-
|
|
111
|
-
const handleRedeemSuccess = useCallback(
|
|
112
|
-
(blockNumber: number) => {
|
|
113
|
-
refreshSeniorRedemptionInfo()
|
|
114
|
-
refreshJuniorRedemptionInfo()
|
|
115
|
-
refreshSeniorPosition()
|
|
116
|
-
refreshJuniorPosition()
|
|
117
|
-
if (handleSuccess) {
|
|
118
|
-
handleSuccess(blockNumber)
|
|
119
|
-
}
|
|
120
|
-
},
|
|
121
|
-
[
|
|
122
|
-
handleSuccess,
|
|
123
|
-
refreshJuniorPosition,
|
|
124
|
-
refreshJuniorRedemptionInfo,
|
|
125
|
-
refreshSeniorPosition,
|
|
126
|
-
refreshSeniorRedemptionInfo,
|
|
127
|
-
],
|
|
128
|
-
)
|
|
129
|
-
|
|
130
|
-
const getMaxAmount = () => {
|
|
131
|
-
if (redemptionActionInfo?.tranche === 'senior') {
|
|
132
|
-
return redemptionActionInfo?.action === 'Create'
|
|
133
|
-
? seniorPosition
|
|
134
|
-
: seniorRedemptionInfo?.amount
|
|
135
|
-
}
|
|
136
|
-
if (redemptionActionInfo?.tranche === 'junior') {
|
|
137
|
-
return redemptionActionInfo?.action === 'Create'
|
|
138
|
-
? juniorPosition
|
|
139
|
-
: juniorRedemptionInfo?.amount
|
|
140
|
-
}
|
|
141
|
-
return undefined
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
if (!poolInfo || !poolUnderlyingToken) {
|
|
145
|
-
return (
|
|
146
|
-
<WidgetWrapper
|
|
147
|
-
isOpen
|
|
148
|
-
isLoading
|
|
149
|
-
loadingTitle='Redeem'
|
|
150
|
-
handleClose={handleClose}
|
|
151
|
-
handleSuccess={handleSuccess}
|
|
152
|
-
/>
|
|
153
|
-
)
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
return (
|
|
157
|
-
<WidgetWrapper
|
|
158
|
-
isOpen
|
|
159
|
-
loadingTitle='Redeem'
|
|
160
|
-
handleClose={handleClose}
|
|
161
|
-
handleSuccess={handleRedeemSuccess}
|
|
162
|
-
>
|
|
163
|
-
{step === WIDGET_STEP.ChooseTranche && (
|
|
164
|
-
<ChooseAction
|
|
165
|
-
poolInfo={poolInfo}
|
|
166
|
-
poolUnderlyingToken={poolUnderlyingToken}
|
|
167
|
-
seniorRedemptionInfo={seniorRedemptionInfo}
|
|
168
|
-
juniorRedemptionInfo={juniorRedemptionInfo}
|
|
169
|
-
redemptionType={redemptionType}
|
|
170
|
-
changeRedemptionType={setRedemptionType}
|
|
171
|
-
seniorPosition={seniorPosition}
|
|
172
|
-
juniorPosition={juniorPosition}
|
|
173
|
-
/>
|
|
174
|
-
)}
|
|
175
|
-
{step === WIDGET_STEP.ChooseAmount && redemptionType && (
|
|
176
|
-
<ChooseAmount
|
|
177
|
-
poolInfo={poolInfo}
|
|
178
|
-
poolUnderlyingToken={poolUnderlyingToken}
|
|
179
|
-
redemptionType={redemptionType}
|
|
180
|
-
maxAmount={getMaxAmount() ?? BigNumber.from(0)}
|
|
181
|
-
/>
|
|
182
|
-
)}
|
|
183
|
-
{step === WIDGET_STEP.Transfer && redemptionType && (
|
|
184
|
-
<Transfer
|
|
185
|
-
poolInfo={poolInfo}
|
|
186
|
-
poolUnderlyingToken={poolUnderlyingToken}
|
|
187
|
-
redemptionType={redemptionType}
|
|
188
|
-
/>
|
|
189
|
-
)}
|
|
190
|
-
{step === WIDGET_STEP.Done && redemptionType && (
|
|
191
|
-
<Done
|
|
192
|
-
poolUnderlyingToken={poolUnderlyingToken}
|
|
193
|
-
handleAction={handleClose}
|
|
194
|
-
redemptionType={redemptionType}
|
|
195
|
-
/>
|
|
196
|
-
)}
|
|
197
|
-
{step === WIDGET_STEP.Error && (
|
|
198
|
-
<ErrorModal
|
|
199
|
-
title='Redeem'
|
|
200
|
-
errorReason={errorReason}
|
|
201
|
-
errorMessage={errorMessage}
|
|
202
|
-
handleOk={handleClose}
|
|
203
|
-
/>
|
|
204
|
-
)}
|
|
205
|
-
</WidgetWrapper>
|
|
206
|
-
)
|
|
207
|
-
}
|
|
@@ -1,201 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
formatBNFixed,
|
|
3
|
-
getTrancheVaultContractV2,
|
|
4
|
-
PoolInfoV2,
|
|
5
|
-
TrancheType,
|
|
6
|
-
UnderlyingTokenInfo,
|
|
7
|
-
} from '@huma-finance/shared'
|
|
8
|
-
import {
|
|
9
|
-
css,
|
|
10
|
-
FormControl,
|
|
11
|
-
FormControlLabel,
|
|
12
|
-
FormLabel,
|
|
13
|
-
Radio,
|
|
14
|
-
RadioGroup,
|
|
15
|
-
useTheme,
|
|
16
|
-
} from '@mui/material'
|
|
17
|
-
import { useWeb3React } from '@web3-react/core'
|
|
18
|
-
import { BigNumber } from 'ethers'
|
|
19
|
-
import React, { useEffect, useState } from 'react'
|
|
20
|
-
|
|
21
|
-
import { useAppDispatch } from '../../../hooks/useRedux'
|
|
22
|
-
import { setStep } from '../../../store/widgets.reducers'
|
|
23
|
-
import { WIDGET_STEP } from '../../../store/widgets.store'
|
|
24
|
-
import { BottomButton } from '../../BottomButton'
|
|
25
|
-
import { LoadingModal } from '../../LoadingModal'
|
|
26
|
-
import { WrapperModal } from '../../WrapperModal'
|
|
27
|
-
|
|
28
|
-
type Props = {
|
|
29
|
-
poolInfo: PoolInfoV2
|
|
30
|
-
poolUnderlyingToken: UnderlyingTokenInfo
|
|
31
|
-
selectedTranche: TrancheType | undefined
|
|
32
|
-
seniorWithdrawableAmount: BigNumber | undefined
|
|
33
|
-
juniorWithdrawableAmount: BigNumber | undefined
|
|
34
|
-
changeTranche: (tranche: TrancheType) => void
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
export function ChooseTranche({
|
|
38
|
-
poolInfo,
|
|
39
|
-
poolUnderlyingToken,
|
|
40
|
-
selectedTranche,
|
|
41
|
-
seniorWithdrawableAmount,
|
|
42
|
-
juniorWithdrawableAmount,
|
|
43
|
-
changeTranche,
|
|
44
|
-
}: Props): React.ReactElement | null {
|
|
45
|
-
const theme = useTheme()
|
|
46
|
-
const dispatch = useAppDispatch()
|
|
47
|
-
const { provider } = useWeb3React()
|
|
48
|
-
const { symbol, decimals } = poolUnderlyingToken
|
|
49
|
-
const [seniorWithdrawableShares, setSeniorWithdrawableShares] = useState(
|
|
50
|
-
BigNumber.from(0),
|
|
51
|
-
)
|
|
52
|
-
const [juniorWithdrawableShares, setJuniorWithdrawableShares] = useState(
|
|
53
|
-
BigNumber.from(0),
|
|
54
|
-
)
|
|
55
|
-
|
|
56
|
-
const isLoading =
|
|
57
|
-
seniorWithdrawableAmount === undefined ||
|
|
58
|
-
juniorWithdrawableAmount === undefined
|
|
59
|
-
|
|
60
|
-
useEffect(() => {
|
|
61
|
-
const fetchData = async () => {
|
|
62
|
-
if (seniorWithdrawableAmount?.gt(0)) {
|
|
63
|
-
const seniorVaultContract = await getTrancheVaultContractV2(
|
|
64
|
-
poolInfo.poolName,
|
|
65
|
-
'senior',
|
|
66
|
-
provider,
|
|
67
|
-
)
|
|
68
|
-
if (seniorVaultContract) {
|
|
69
|
-
const shares = await seniorVaultContract.convertToShares(
|
|
70
|
-
seniorWithdrawableAmount,
|
|
71
|
-
)
|
|
72
|
-
setSeniorWithdrawableShares(shares)
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
fetchData()
|
|
77
|
-
}, [poolInfo.poolName, provider, seniorWithdrawableAmount])
|
|
78
|
-
|
|
79
|
-
useEffect(() => {
|
|
80
|
-
const fetchData = async () => {
|
|
81
|
-
if (juniorWithdrawableAmount?.gt(0)) {
|
|
82
|
-
const juniorVaultContract = await getTrancheVaultContractV2(
|
|
83
|
-
poolInfo.poolName,
|
|
84
|
-
'senior',
|
|
85
|
-
provider,
|
|
86
|
-
)
|
|
87
|
-
if (juniorVaultContract) {
|
|
88
|
-
const shares = await juniorVaultContract.convertToShares(
|
|
89
|
-
juniorWithdrawableAmount,
|
|
90
|
-
)
|
|
91
|
-
setJuniorWithdrawableShares(shares)
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
fetchData()
|
|
96
|
-
}, [poolInfo.poolName, provider, juniorWithdrawableAmount])
|
|
97
|
-
|
|
98
|
-
const styles = {
|
|
99
|
-
subTitle: css`
|
|
100
|
-
color: ${theme.palette.text.primary} !important;
|
|
101
|
-
font-family: 'Uni-Neue-Regular';
|
|
102
|
-
font-size: 16px;
|
|
103
|
-
line-height: 150%;
|
|
104
|
-
letter-spacing: 0.15px;
|
|
105
|
-
margin-top: ${theme.spacing(5)};
|
|
106
|
-
margin-left: ${theme.spacing(2)};
|
|
107
|
-
`,
|
|
108
|
-
radioGroup: css`
|
|
109
|
-
margin-left: ${theme.spacing(3)};
|
|
110
|
-
margin-top: ${theme.spacing(3)};
|
|
111
|
-
`,
|
|
112
|
-
formControl: css`
|
|
113
|
-
margin-bottom: ${theme.spacing(1)};
|
|
114
|
-
|
|
115
|
-
.MuiFormControlLabel-label {
|
|
116
|
-
color: ${theme.palette.text.primary};
|
|
117
|
-
font-family: 'Uni-Neue-Regular';
|
|
118
|
-
font-size: 16px;
|
|
119
|
-
line-height: 150%;
|
|
120
|
-
letter-spacing: 0.15px;
|
|
121
|
-
}
|
|
122
|
-
`,
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
const handleNext = () => {
|
|
126
|
-
dispatch(setStep(WIDGET_STEP.Transfer))
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
const items: {
|
|
130
|
-
label: string
|
|
131
|
-
value: TrancheType
|
|
132
|
-
disabled: boolean | undefined
|
|
133
|
-
}[] = [
|
|
134
|
-
{
|
|
135
|
-
label: `Withdraw ${formatBNFixed(
|
|
136
|
-
seniorWithdrawableAmount,
|
|
137
|
-
decimals,
|
|
138
|
-
)} ${symbol} from Senior vault (${formatBNFixed(
|
|
139
|
-
seniorWithdrawableShares,
|
|
140
|
-
decimals,
|
|
141
|
-
)} shares)`,
|
|
142
|
-
value: 'senior',
|
|
143
|
-
disabled: seniorWithdrawableAmount?.lte(0) ?? true,
|
|
144
|
-
},
|
|
145
|
-
{
|
|
146
|
-
label: `Withdraw ${formatBNFixed(
|
|
147
|
-
juniorWithdrawableAmount,
|
|
148
|
-
decimals,
|
|
149
|
-
)} ${symbol} from Junior vault (${formatBNFixed(
|
|
150
|
-
juniorWithdrawableShares,
|
|
151
|
-
decimals,
|
|
152
|
-
)} shares)`,
|
|
153
|
-
value: 'junior',
|
|
154
|
-
disabled: juniorWithdrawableAmount?.lte(0) ?? true,
|
|
155
|
-
},
|
|
156
|
-
]
|
|
157
|
-
|
|
158
|
-
if (isLoading) {
|
|
159
|
-
return <LoadingModal title={`Withdraw ${symbol}`} />
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
return (
|
|
163
|
-
<WrapperModal title={`Withdraw ${symbol}`}>
|
|
164
|
-
<FormControl>
|
|
165
|
-
<FormLabel css={styles.subTitle}>Select Withdraw Type</FormLabel>
|
|
166
|
-
<RadioGroup
|
|
167
|
-
aria-labelledby='buttons-group-label'
|
|
168
|
-
name='radio-buttons-group'
|
|
169
|
-
css={styles.radioGroup}
|
|
170
|
-
onChange={(e) => changeTranche(e.target.value as TrancheType)}
|
|
171
|
-
>
|
|
172
|
-
{items.map((item) => (
|
|
173
|
-
<FormControlLabel
|
|
174
|
-
key={item.label}
|
|
175
|
-
value={item.value}
|
|
176
|
-
disabled={item.disabled}
|
|
177
|
-
control={
|
|
178
|
-
<Radio
|
|
179
|
-
sx={{
|
|
180
|
-
'& .MuiSvgIcon-root': {
|
|
181
|
-
fontSize: 24,
|
|
182
|
-
},
|
|
183
|
-
}}
|
|
184
|
-
/>
|
|
185
|
-
}
|
|
186
|
-
label={item.label}
|
|
187
|
-
css={styles.formControl}
|
|
188
|
-
/>
|
|
189
|
-
))}
|
|
190
|
-
</RadioGroup>
|
|
191
|
-
</FormControl>
|
|
192
|
-
<BottomButton
|
|
193
|
-
variant='contained'
|
|
194
|
-
disabled={!selectedTranche}
|
|
195
|
-
onClick={handleNext}
|
|
196
|
-
>
|
|
197
|
-
NEXT
|
|
198
|
-
</BottomButton>
|
|
199
|
-
</WrapperModal>
|
|
200
|
-
)
|
|
201
|
-
}
|