@huma-finance/widgets 0.0.48-beta.202 → 0.0.48-beta.280
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 +407 -0
- package/dist/cjs/index.cjs +6063 -3827
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/index.d.ts +248 -1
- package/dist/index.js +6056 -3829
- package/dist/index.js.map +1 -1
- package/package.json +5 -4
- package/src/components/ApproveAllowanceModal.tsx +3 -8
- package/src/components/ApproveAllowanceModalV2.tsx +141 -0
- package/src/components/CreditLine/approve/index.tsx +9 -3
- package/src/components/CreditLine/autoPaybackV2/1-ApproveAllowance.tsx +33 -0
- package/src/components/CreditLine/autoPaybackV2/2-Success.tsx +13 -0
- package/src/components/CreditLine/autoPaybackV2/index.tsx +87 -0
- package/src/components/CreditLine/borrow/2-ChooseAmount.tsx +12 -3
- package/src/components/CreditLine/borrow/index.tsx +4 -2
- package/src/components/CreditLine/borrowV2/1-ChooseAmount.tsx +79 -0
- package/src/components/CreditLine/borrowV2/2-ApproveAllowance.tsx +33 -0
- package/src/components/CreditLine/borrowV2/3-Transfer.tsx +50 -0
- package/src/components/CreditLine/borrowV2/4-Success.tsx +41 -0
- package/src/components/CreditLine/borrowV2/5-Notifications.tsx +10 -0
- package/src/components/CreditLine/borrowV2/index.tsx +140 -0
- package/src/components/CreditLine/payment/1-ChooseAmount.tsx +7 -2
- package/src/components/CreditLine/payment/index.tsx +4 -2
- package/src/components/CreditLine/paymentV2/1-ChooseAmount.tsx +86 -0
- package/src/components/CreditLine/paymentV2/2-ApproveAllowance.tsx +33 -0
- package/src/components/CreditLine/paymentV2/3-Transfer.tsx +55 -0
- package/src/components/CreditLine/paymentV2/4-Success.tsx +42 -0
- package/src/components/CreditLine/paymentV2/index.tsx +111 -0
- package/src/components/CreditLine/supplyFLC/1-ApproveAllowance.tsx +40 -0
- package/src/components/CreditLine/supplyFLC/2-Transfer.tsx +53 -0
- package/src/components/CreditLine/supplyFLC/3-Success.tsx +26 -0
- package/src/components/CreditLine/supplyFLC/index.tsx +121 -0
- package/src/components/Factoring/FactoredList.tsx +2 -1
- package/src/components/InvoiceFactoring/borrow/2-ChooseAmount.tsx +8 -1
- package/src/components/InvoiceFactoring/borrow/4-ApproveNFT.tsx +6 -2
- package/src/components/InvoiceFactoring/borrow/index.tsx +9 -3
- package/src/components/InvoiceFactoring/payment/1-ChooseAmount.tsx +7 -2
- package/src/components/InvoiceFactoring/payment/index.tsx +9 -3
- package/src/components/Lend/redeemV2/1-ChooseAction.tsx +236 -0
- package/src/components/Lend/redeemV2/2-ChooseAmount.tsx +162 -0
- package/src/components/Lend/redeemV2/3-Transfer.tsx +61 -0
- package/src/components/Lend/redeemV2/4-Done.tsx +33 -0
- package/src/components/Lend/redeemV2/index.tsx +207 -0
- package/src/components/Lend/supply/1-Evaluation/EvaluationKYC.tsx +19 -2
- package/src/components/Lend/supply/index.tsx +17 -3
- package/src/components/Lend/supplyV2/1-ChooseTranche.tsx +155 -0
- package/src/components/Lend/supplyV2/2-Evaluation.tsx +345 -0
- package/src/components/Lend/supplyV2/3-ChooseAmount.tsx +122 -0
- package/src/components/Lend/supplyV2/4-ApproveAllowance.tsx +33 -0
- package/src/components/Lend/supplyV2/5-Transfer.tsx +59 -0
- package/src/components/Lend/supplyV2/6-Success.tsx +79 -0
- package/src/components/Lend/supplyV2/7-Notifications.tsx +10 -0
- package/src/components/Lend/supplyV2/index.tsx +127 -0
- package/src/components/Lend/withdraw/1-CheckWithdrawble.tsx +5 -1
- package/src/components/Lend/withdraw/2-ChooseAmount.tsx +1 -7
- package/src/components/Lend/withdraw/index.tsx +8 -13
- package/src/components/Lend/withdrawV2/1-ChooseTranche.tsx +201 -0
- package/src/components/Lend/withdrawV2/2-Transfer.tsx +48 -0
- package/src/components/Lend/withdrawV2/3-Done.tsx +31 -0
- package/src/components/Lend/withdrawV2/index.tsx +129 -0
- package/src/components/Notifi/NotifiSubscriptionModal.tsx +29 -37
- package/src/components/NumericFormatCustom.tsx +31 -0
- package/src/components/ReceivableBackedCreditLine/borrow/1-ChooseAmount.tsx +101 -0
- package/src/components/ReceivableBackedCreditLine/borrow/2-ApproveAllowance.tsx +33 -0
- package/src/components/ReceivableBackedCreditLine/borrow/3-ApproveReceivable.tsx +64 -0
- package/src/components/ReceivableBackedCreditLine/borrow/4-Transfer.tsx +61 -0
- package/src/components/ReceivableBackedCreditLine/borrow/5-Success.tsx +41 -0
- package/src/components/ReceivableBackedCreditLine/borrow/6-Notifications.tsx +10 -0
- package/src/components/ReceivableBackedCreditLine/borrow/index.tsx +148 -0
- package/src/components/ReceivableBackedCreditLine/payment/1-ChoosePaymentType.tsx +115 -0
- package/src/components/ReceivableBackedCreditLine/payment/2-ChooseAmount.tsx +84 -0
- package/src/components/ReceivableBackedCreditLine/payment/3-ApproveAllowance.tsx +41 -0
- package/src/components/ReceivableBackedCreditLine/payment/4-CreateReceivable.tsx +107 -0
- package/src/components/ReceivableBackedCreditLine/payment/5-ApproveReceivable.tsx +64 -0
- package/src/components/ReceivableBackedCreditLine/payment/6-Transfer.tsx +107 -0
- package/src/components/ReceivableBackedCreditLine/payment/7-Success.tsx +49 -0
- package/src/components/ReceivableBackedCreditLine/payment/index.tsx +159 -0
- package/src/components/StreamFactoring/borrow/1-Evaluation.tsx +3 -4
- package/src/components/StreamFactoring/borrow/2-ChooseAmount.tsx +23 -22
- package/src/components/StreamFactoring/borrow/3-ConfirmTransfer.tsx +8 -3
- package/src/components/StreamFactoring/borrow/5-Permit.tsx +35 -2
- package/src/components/StreamFactoring/borrow/6-Transfer.tsx +3 -1
- package/src/components/StreamFactoring/borrow/index.tsx +4 -3
- package/src/components/SuperfluidFactoring/SuperfluidFactoredList.tsx +2 -2
- package/src/components/SuperfluidFactoring/SuperfluidUpcomingList.tsx +1 -3
- package/src/components/TxDoneModal.tsx +1 -1
- package/src/components/TxSendModal.tsx +8 -2
- package/src/components/TxSendModalV2.tsx +51 -0
- package/src/index.tsx +239 -1
- package/src/store/widgets.reducers.ts +15 -0
- package/src/store/widgets.store.ts +6 -0
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import {
|
|
2
|
+
POOL_NAME,
|
|
3
|
+
TrancheType,
|
|
4
|
+
usePoolInfoV2,
|
|
5
|
+
usePoolUnderlyingTokenInfoV2,
|
|
6
|
+
} from '@huma-finance/shared'
|
|
7
|
+
import { useWeb3React } from '@web3-react/core'
|
|
8
|
+
import React, { useEffect, useState } from 'react'
|
|
9
|
+
import { useDispatch } from 'react-redux'
|
|
10
|
+
|
|
11
|
+
import { useAppSelector } from '../../../hooks/useRedux'
|
|
12
|
+
import { setStep } from '../../../store/widgets.reducers'
|
|
13
|
+
import { selectWidgetState } from '../../../store/widgets.selectors'
|
|
14
|
+
import { WIDGET_STEP } from '../../../store/widgets.store'
|
|
15
|
+
import { ErrorModal } from '../../ErrorModal'
|
|
16
|
+
import { WidgetWrapper } from '../../WidgetWrapper'
|
|
17
|
+
import { ChooseTranche } from './1-ChooseTranche'
|
|
18
|
+
import { Evaluation } from './2-Evaluation'
|
|
19
|
+
import { ChooseAmount } from './3-ChooseAmount'
|
|
20
|
+
import { ApproveAllowance } from './4-ApproveAllowance'
|
|
21
|
+
import { Transfer } from './5-Transfer'
|
|
22
|
+
import { Success } from './6-Success'
|
|
23
|
+
import { Notifications } from './7-Notifications'
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Lend pool supply props
|
|
27
|
+
* @typedef {Object} LendSupplyPropsV2
|
|
28
|
+
* @property {POOL_NAME} poolName The name of the pool.
|
|
29
|
+
* @property {function():void} handleClose Function to notify to close the widget modal when user clicks the 'x' close button.
|
|
30
|
+
* @property {function((number|undefined)):void|undefined} handleSuccess Optional function to notify that the lending pool supply action is successful.
|
|
31
|
+
*/
|
|
32
|
+
export interface LendSupplyPropsV2 {
|
|
33
|
+
poolName: keyof typeof POOL_NAME
|
|
34
|
+
handleClose: () => void
|
|
35
|
+
handleSuccess?: (blockNumber?: number) => void
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export function LendSupplyV2({
|
|
39
|
+
poolName: poolNameStr,
|
|
40
|
+
handleClose,
|
|
41
|
+
handleSuccess,
|
|
42
|
+
}: LendSupplyPropsV2): React.ReactElement | null {
|
|
43
|
+
const dispatch = useDispatch()
|
|
44
|
+
const poolName = POOL_NAME[poolNameStr]
|
|
45
|
+
const { chainId, provider } = useWeb3React()
|
|
46
|
+
const poolInfo = usePoolInfoV2(poolName, chainId)
|
|
47
|
+
const { step, errorMessage } = useAppSelector(selectWidgetState)
|
|
48
|
+
const [selectedTranche, setSelectedTranche] = useState<TrancheType>()
|
|
49
|
+
const poolUnderlyingToken = usePoolUnderlyingTokenInfoV2(poolName, provider)
|
|
50
|
+
|
|
51
|
+
useEffect(() => {
|
|
52
|
+
if (!step) {
|
|
53
|
+
dispatch(setStep(WIDGET_STEP.ChooseTranche))
|
|
54
|
+
}
|
|
55
|
+
}, [dispatch, step])
|
|
56
|
+
|
|
57
|
+
if (!poolInfo || !poolUnderlyingToken) {
|
|
58
|
+
return (
|
|
59
|
+
<WidgetWrapper
|
|
60
|
+
isOpen
|
|
61
|
+
isLoading
|
|
62
|
+
loadingTitle='Supply'
|
|
63
|
+
handleClose={handleClose}
|
|
64
|
+
handleSuccess={handleSuccess}
|
|
65
|
+
/>
|
|
66
|
+
)
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
return (
|
|
70
|
+
<WidgetWrapper
|
|
71
|
+
isOpen
|
|
72
|
+
loadingTitle={`Supply ${poolUnderlyingToken.symbol}`}
|
|
73
|
+
handleClose={handleClose}
|
|
74
|
+
handleSuccess={handleSuccess}
|
|
75
|
+
>
|
|
76
|
+
{step === WIDGET_STEP.ChooseTranche && (
|
|
77
|
+
<ChooseTranche
|
|
78
|
+
poolInfo={poolInfo}
|
|
79
|
+
poolUnderlyingToken={poolUnderlyingToken}
|
|
80
|
+
selectedTranche={selectedTranche}
|
|
81
|
+
changeTranche={setSelectedTranche}
|
|
82
|
+
/>
|
|
83
|
+
)}
|
|
84
|
+
{step === WIDGET_STEP.Evaluation && (
|
|
85
|
+
<Evaluation poolInfo={poolInfo} handleClose={handleClose} />
|
|
86
|
+
)}
|
|
87
|
+
{step === WIDGET_STEP.ChooseAmount && (
|
|
88
|
+
<ChooseAmount
|
|
89
|
+
poolInfo={poolInfo}
|
|
90
|
+
poolUnderlyingToken={poolUnderlyingToken}
|
|
91
|
+
selectedTranche={selectedTranche}
|
|
92
|
+
/>
|
|
93
|
+
)}
|
|
94
|
+
{step === WIDGET_STEP.ApproveAllowance && (
|
|
95
|
+
<ApproveAllowance
|
|
96
|
+
poolInfo={poolInfo}
|
|
97
|
+
poolUnderlyingToken={poolUnderlyingToken}
|
|
98
|
+
/>
|
|
99
|
+
)}
|
|
100
|
+
{step === WIDGET_STEP.Transfer && selectedTranche && (
|
|
101
|
+
<Transfer
|
|
102
|
+
poolInfo={poolInfo}
|
|
103
|
+
poolUnderlyingToken={poolUnderlyingToken}
|
|
104
|
+
trancheType={selectedTranche}
|
|
105
|
+
/>
|
|
106
|
+
)}
|
|
107
|
+
{step === WIDGET_STEP.Done && (
|
|
108
|
+
<Success
|
|
109
|
+
poolInfo={poolInfo}
|
|
110
|
+
poolUnderlyingToken={poolUnderlyingToken}
|
|
111
|
+
handleAction={handleClose}
|
|
112
|
+
/>
|
|
113
|
+
)}
|
|
114
|
+
{step === WIDGET_STEP.Notifications && (
|
|
115
|
+
<Notifications handleAction={handleClose} />
|
|
116
|
+
)}
|
|
117
|
+
{step === WIDGET_STEP.Error && (
|
|
118
|
+
<ErrorModal
|
|
119
|
+
title='Supply'
|
|
120
|
+
errorReason='Sorry there was an error'
|
|
121
|
+
errorMessage={errorMessage}
|
|
122
|
+
handleOk={handleClose}
|
|
123
|
+
/>
|
|
124
|
+
)}
|
|
125
|
+
</WidgetWrapper>
|
|
126
|
+
)
|
|
127
|
+
}
|
|
@@ -23,15 +23,19 @@ export function CheckWithdrawable({
|
|
|
23
23
|
handleClose,
|
|
24
24
|
}: Props): React.ReactElement | null {
|
|
25
25
|
const dispatch = useAppDispatch()
|
|
26
|
-
const { account } = useWeb3React()
|
|
26
|
+
const { account, chainId, provider } = useWeb3React()
|
|
27
27
|
const withdrawlLockoutSeconds = useWithdrawlLockoutInSeconds(
|
|
28
28
|
poolInfo.poolName,
|
|
29
29
|
poolInfo.poolType,
|
|
30
|
+
chainId,
|
|
31
|
+
provider,
|
|
30
32
|
)
|
|
31
33
|
const lastDepositTime = useLastDepositTime(
|
|
32
34
|
poolInfo.poolName,
|
|
33
35
|
poolInfo.poolType,
|
|
36
|
+
chainId,
|
|
34
37
|
account,
|
|
38
|
+
provider,
|
|
35
39
|
)
|
|
36
40
|
|
|
37
41
|
const { symbol } = poolInfo.poolUnderlyingToken
|
|
@@ -9,24 +9,18 @@ import { ChooseAmountModal } from '../../ChooseAmountModal'
|
|
|
9
9
|
|
|
10
10
|
type Props = {
|
|
11
11
|
lenderPosition: BigNumber
|
|
12
|
-
poolBalance: BigNumber
|
|
13
12
|
poolInfo: PoolInfoType
|
|
14
13
|
}
|
|
15
14
|
|
|
16
15
|
export function ChooseAmount({
|
|
17
16
|
lenderPosition,
|
|
18
|
-
poolBalance,
|
|
19
17
|
poolInfo,
|
|
20
18
|
}: Props): React.ReactElement | null {
|
|
21
19
|
const dispatch = useAppDispatch()
|
|
22
20
|
const { poolUnderlyingToken } = poolInfo
|
|
23
21
|
const { symbol, decimals } = poolUnderlyingToken
|
|
24
22
|
const [currentAmount, setCurrentAmount] = useState(0)
|
|
25
|
-
|
|
26
|
-
const withdrawableAmountBN = lenderPosition.lt(poolBalance)
|
|
27
|
-
? lenderPosition
|
|
28
|
-
: poolBalance
|
|
29
|
-
const withdrawableAmount = downScale<number>(withdrawableAmountBN, decimals)
|
|
23
|
+
const withdrawableAmount = downScale<number>(lenderPosition, decimals)
|
|
30
24
|
|
|
31
25
|
const handleChangeAmount = useCallback(
|
|
32
26
|
(newAmount: number) => {
|
|
@@ -3,7 +3,6 @@ import {
|
|
|
3
3
|
POOL_NAME,
|
|
4
4
|
POOL_TYPE,
|
|
5
5
|
useLenderPosition,
|
|
6
|
-
usePoolBalance,
|
|
7
6
|
usePoolInfo,
|
|
8
7
|
} from '@huma-finance/shared'
|
|
9
8
|
import React, { useCallback, useEffect } from 'react'
|
|
@@ -42,33 +41,33 @@ export function LendWithdraw({
|
|
|
42
41
|
handleSuccess,
|
|
43
42
|
}: LendWithdrawProps): React.ReactElement | null {
|
|
44
43
|
const dispatch = useDispatch()
|
|
45
|
-
const { account } = useWeb3React()
|
|
44
|
+
const { account, chainId, provider } = useWeb3React()
|
|
46
45
|
const poolName = POOL_NAME[poolNameStr]
|
|
47
46
|
const poolType = POOL_TYPE[poolTypeStr]
|
|
48
|
-
const poolInfo = usePoolInfo(poolName, poolType)
|
|
47
|
+
const poolInfo = usePoolInfo(poolName, poolType, chainId)
|
|
49
48
|
const { step, errorMessage } = useAppSelector(selectWidgetState)
|
|
50
49
|
const [lenderPosition, refreshLenderPosition] = useLenderPosition(
|
|
51
50
|
poolName,
|
|
52
51
|
poolType,
|
|
52
|
+
chainId,
|
|
53
53
|
account,
|
|
54
|
+
provider,
|
|
54
55
|
)
|
|
55
|
-
const [poolBalance, refreshPoolBalance] = usePoolBalance(poolName, poolType)
|
|
56
56
|
|
|
57
57
|
useEffect(() => {
|
|
58
|
-
if (!step && lenderPosition
|
|
58
|
+
if (!step && lenderPosition) {
|
|
59
59
|
dispatch(setStep(WIDGET_STEP.CheckWithdrawable))
|
|
60
60
|
}
|
|
61
|
-
}, [dispatch, lenderPosition,
|
|
61
|
+
}, [dispatch, lenderPosition, step])
|
|
62
62
|
|
|
63
63
|
const handleWithdrawSuccess = useCallback(
|
|
64
64
|
(blockNumber: number) => {
|
|
65
65
|
refreshLenderPosition()
|
|
66
|
-
refreshPoolBalance()
|
|
67
66
|
if (handleSuccess) {
|
|
68
67
|
handleSuccess(blockNumber)
|
|
69
68
|
}
|
|
70
69
|
},
|
|
71
|
-
[handleSuccess, refreshLenderPosition
|
|
70
|
+
[handleSuccess, refreshLenderPosition],
|
|
72
71
|
)
|
|
73
72
|
|
|
74
73
|
if (!poolInfo) {
|
|
@@ -85,11 +84,7 @@ export function LendWithdraw({
|
|
|
85
84
|
<CheckWithdrawable poolInfo={poolInfo} handleClose={handleClose} />
|
|
86
85
|
)}
|
|
87
86
|
{step === WIDGET_STEP.ChooseAmount && (
|
|
88
|
-
<ChooseAmount
|
|
89
|
-
poolInfo={poolInfo}
|
|
90
|
-
lenderPosition={lenderPosition!}
|
|
91
|
-
poolBalance={poolBalance!}
|
|
92
|
-
/>
|
|
87
|
+
<ChooseAmount poolInfo={poolInfo} lenderPosition={lenderPosition!} />
|
|
93
88
|
)}
|
|
94
89
|
{step === WIDGET_STEP.Transfer && <Transfer poolInfo={poolInfo} />}
|
|
95
90
|
{step === WIDGET_STEP.Done && (
|
|
@@ -0,0 +1,201 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
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 { useAppDispatch } from '../../../hooks/useRedux'
|
|
10
|
+
import { setStep } from '../../../store/widgets.reducers'
|
|
11
|
+
import { WIDGET_STEP } from '../../../store/widgets.store'
|
|
12
|
+
import { TxSendModalV2 } from '../../TxSendModalV2'
|
|
13
|
+
|
|
14
|
+
type Props = {
|
|
15
|
+
poolInfo: PoolInfoV2
|
|
16
|
+
selectedTranche: TrancheType
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function Transfer({
|
|
20
|
+
poolInfo,
|
|
21
|
+
selectedTranche,
|
|
22
|
+
}: Props): React.ReactElement | null {
|
|
23
|
+
const dispatch = useAppDispatch()
|
|
24
|
+
const { account, provider } = useWeb3React()
|
|
25
|
+
const trancheVaultContract = useTrancheVaultContractV2(
|
|
26
|
+
poolInfo.poolName,
|
|
27
|
+
selectedTranche,
|
|
28
|
+
provider,
|
|
29
|
+
account,
|
|
30
|
+
)
|
|
31
|
+
|
|
32
|
+
const handleSuccess = useCallback(() => {
|
|
33
|
+
dispatch(setStep(WIDGET_STEP.Done))
|
|
34
|
+
}, [dispatch])
|
|
35
|
+
|
|
36
|
+
if (!trancheVaultContract || !account) {
|
|
37
|
+
return null
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
return (
|
|
41
|
+
<TxSendModalV2
|
|
42
|
+
contract={trancheVaultContract}
|
|
43
|
+
method='disburse'
|
|
44
|
+
params={[]}
|
|
45
|
+
handleSuccess={handleSuccess}
|
|
46
|
+
/>
|
|
47
|
+
)
|
|
48
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { formatMoney, UnderlyingTokenInfo } from '@huma-finance/shared'
|
|
2
|
+
import { BigNumber, ethers } from 'ethers'
|
|
3
|
+
import React from 'react'
|
|
4
|
+
|
|
5
|
+
import { TxDoneModal } from '../../TxDoneModal'
|
|
6
|
+
|
|
7
|
+
type Props = {
|
|
8
|
+
poolUnderlyingToken: UnderlyingTokenInfo
|
|
9
|
+
withdrawAmount: BigNumber
|
|
10
|
+
handleAction: () => void
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export function Done({
|
|
14
|
+
poolUnderlyingToken,
|
|
15
|
+
withdrawAmount,
|
|
16
|
+
handleAction,
|
|
17
|
+
}: Props): React.ReactElement {
|
|
18
|
+
const { symbol } = poolUnderlyingToken
|
|
19
|
+
const withdrawAmountFormatted = ethers.utils.formatUnits(
|
|
20
|
+
withdrawAmount,
|
|
21
|
+
poolUnderlyingToken.decimals,
|
|
22
|
+
)
|
|
23
|
+
|
|
24
|
+
const content = [
|
|
25
|
+
`You successfully withdrew ${formatMoney(
|
|
26
|
+
withdrawAmountFormatted,
|
|
27
|
+
)} ${symbol}.`,
|
|
28
|
+
]
|
|
29
|
+
|
|
30
|
+
return <TxDoneModal handleAction={handleAction} content={content} />
|
|
31
|
+
}
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import {
|
|
2
|
+
POOL_NAME,
|
|
3
|
+
TrancheType,
|
|
4
|
+
usePoolInfoV2,
|
|
5
|
+
usePoolUnderlyingTokenInfoV2,
|
|
6
|
+
useWithdrawableAssetsV2,
|
|
7
|
+
} from '@huma-finance/shared'
|
|
8
|
+
import { useWeb3React } from '@web3-react/core'
|
|
9
|
+
import React, { useCallback, useEffect, useState } from 'react'
|
|
10
|
+
import { useDispatch } from 'react-redux'
|
|
11
|
+
|
|
12
|
+
import { BigNumber } from 'ethers'
|
|
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 { Transfer } from './2-Transfer'
|
|
21
|
+
import { Done } from './3-Done'
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Lend pool withdraw props
|
|
25
|
+
* @typedef {Object} LendWithdrawPropsV2
|
|
26
|
+
* @property {POOL_NAME} poolName The name of the pool.
|
|
27
|
+
* @property {function():void} handleClose Function to notify to close the widget modal when user clicks the 'x' close button.
|
|
28
|
+
* @property {function((number|undefined)):void|undefined} handleSuccess Optional function to notify that the lending pool withdraw action is successful.
|
|
29
|
+
*/
|
|
30
|
+
export type LendWithdrawPropsV2 = {
|
|
31
|
+
poolName: keyof typeof POOL_NAME
|
|
32
|
+
handleClose: () => void
|
|
33
|
+
handleSuccess?: (blockNumber?: number) => void
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export function LendWithdrawV2({
|
|
37
|
+
poolName: poolNameStr,
|
|
38
|
+
handleClose,
|
|
39
|
+
handleSuccess,
|
|
40
|
+
}: LendWithdrawPropsV2): React.ReactElement | null {
|
|
41
|
+
const dispatch = useDispatch()
|
|
42
|
+
const { account, chainId, provider } = useWeb3React()
|
|
43
|
+
const poolName = POOL_NAME[poolNameStr]
|
|
44
|
+
const poolInfo = usePoolInfoV2(poolName, chainId)
|
|
45
|
+
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
|
+
const poolUnderlyingToken = usePoolUnderlyingTokenInfoV2(poolName, provider)
|
|
51
|
+
const [selectedTranche, setSelectedTranche] = useState<TrancheType>()
|
|
52
|
+
const [withdrawAmount, setWithdrawAmount] = useState<BigNumber>()
|
|
53
|
+
|
|
54
|
+
useEffect(() => {
|
|
55
|
+
if (!step) {
|
|
56
|
+
dispatch(setStep(WIDGET_STEP.ChooseTranche))
|
|
57
|
+
}
|
|
58
|
+
}, [dispatch, step])
|
|
59
|
+
|
|
60
|
+
const handleWithdrawSuccess = useCallback(
|
|
61
|
+
(blockNumber: number) => {
|
|
62
|
+
refreshSeniorWithdrawableAmount()
|
|
63
|
+
refreshJuniorWithdrawableAmount()
|
|
64
|
+
if (handleSuccess) {
|
|
65
|
+
handleSuccess(blockNumber)
|
|
66
|
+
}
|
|
67
|
+
},
|
|
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],
|
|
86
|
+
)
|
|
87
|
+
|
|
88
|
+
if (!poolInfo || !poolUnderlyingToken) {
|
|
89
|
+
return null
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
return (
|
|
93
|
+
<WidgetWrapper
|
|
94
|
+
isOpen
|
|
95
|
+
loadingTitle='Withdraw'
|
|
96
|
+
handleClose={handleClose}
|
|
97
|
+
handleSuccess={handleWithdrawSuccess}
|
|
98
|
+
>
|
|
99
|
+
{step === WIDGET_STEP.ChooseTranche && (
|
|
100
|
+
<ChooseTranche
|
|
101
|
+
poolInfo={poolInfo}
|
|
102
|
+
poolUnderlyingToken={poolUnderlyingToken}
|
|
103
|
+
selectedTranche={selectedTranche}
|
|
104
|
+
changeTranche={handleChangeTranche}
|
|
105
|
+
seniorWithdrawableAmount={seniorWithdrawableAmount}
|
|
106
|
+
juniorWithdrawableAmount={juniorWithdrawableAmount}
|
|
107
|
+
/>
|
|
108
|
+
)}
|
|
109
|
+
{step === WIDGET_STEP.Transfer && selectedTranche && (
|
|
110
|
+
<Transfer poolInfo={poolInfo} selectedTranche={selectedTranche} />
|
|
111
|
+
)}
|
|
112
|
+
{step === WIDGET_STEP.Done && withdrawAmount && (
|
|
113
|
+
<Done
|
|
114
|
+
poolUnderlyingToken={poolUnderlyingToken}
|
|
115
|
+
withdrawAmount={withdrawAmount}
|
|
116
|
+
handleAction={handleClose}
|
|
117
|
+
/>
|
|
118
|
+
)}
|
|
119
|
+
{step === WIDGET_STEP.Error && (
|
|
120
|
+
<ErrorModal
|
|
121
|
+
title='Withdraw'
|
|
122
|
+
errorReason='Sorry there was an error'
|
|
123
|
+
errorMessage={errorMessage}
|
|
124
|
+
handleOk={handleClose}
|
|
125
|
+
/>
|
|
126
|
+
)}
|
|
127
|
+
</WidgetWrapper>
|
|
128
|
+
)
|
|
129
|
+
}
|