@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,33 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,207 @@
|
|
|
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
|
+
}
|
|
@@ -87,8 +87,11 @@ export function EvaluationKYC({
|
|
|
87
87
|
const isDev = checkIsDev()
|
|
88
88
|
const { account, chainId } = useWeb3React()
|
|
89
89
|
const { kycProvider, code, kycPool } = useParamsSearch()
|
|
90
|
-
const {
|
|
91
|
-
|
|
90
|
+
const {
|
|
91
|
+
isWalletOwnershipVerified,
|
|
92
|
+
setError: setAuthError,
|
|
93
|
+
error: authError,
|
|
94
|
+
} = useAuthErrorHandling(isDev)
|
|
92
95
|
const [loadingType, setLoadingType] = useState<
|
|
93
96
|
'verificationStatus' | 'sendDocSignatureLink'
|
|
94
97
|
>()
|
|
@@ -250,6 +253,20 @@ export function EvaluationKYC({
|
|
|
250
253
|
isWalletOwnershipVerified,
|
|
251
254
|
])
|
|
252
255
|
|
|
256
|
+
useEffect(() => {
|
|
257
|
+
if (
|
|
258
|
+
authError &&
|
|
259
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
260
|
+
[4001, 'ACTION_REJECTED'].includes((authError as any).code)
|
|
261
|
+
) {
|
|
262
|
+
dispatch(
|
|
263
|
+
setError({
|
|
264
|
+
errorMessage: 'User has rejected the transaction.',
|
|
265
|
+
}),
|
|
266
|
+
)
|
|
267
|
+
}
|
|
268
|
+
}, [authError, dispatch])
|
|
269
|
+
|
|
253
270
|
const approveLender = async () => {
|
|
254
271
|
if (docSignatureCompleted) {
|
|
255
272
|
handleClose()
|
|
@@ -52,33 +52,47 @@ export function LendSupply({
|
|
|
52
52
|
handleSuccess,
|
|
53
53
|
}: LendSupplyProps): React.ReactElement | null {
|
|
54
54
|
const dispatch = useDispatch()
|
|
55
|
-
const { account, chainId } = useWeb3React()
|
|
55
|
+
const { account, chainId, provider } = useWeb3React()
|
|
56
56
|
const poolName = POOL_NAME[poolNameStr]
|
|
57
57
|
const poolType = POOL_TYPE[poolTypeStr]
|
|
58
|
-
const poolInfo = usePoolInfo(poolName, poolType)
|
|
58
|
+
const poolInfo = usePoolInfo(poolName, poolType, chainId)
|
|
59
59
|
const { decimals } = poolInfo?.poolUnderlyingToken || {}
|
|
60
60
|
const { step, errorMessage } = useAppSelector(selectWidgetState)
|
|
61
|
-
const { allowance } = usePoolAllowance(
|
|
61
|
+
const { allowance } = usePoolAllowance(
|
|
62
|
+
poolName,
|
|
63
|
+
poolType,
|
|
64
|
+
chainId,
|
|
65
|
+
account,
|
|
66
|
+
provider,
|
|
67
|
+
)
|
|
62
68
|
const { isFirstTimeNotifiUser } = useIsFirstTimeNotifiUser(account, chainId)
|
|
63
69
|
const { notifiChainSupported } = useDoesChainSupportNotifi(account, chainId)
|
|
64
70
|
const [lenderApproved, refreshLenderApproved] = useLenderApproved(
|
|
65
71
|
poolName,
|
|
66
72
|
poolType,
|
|
73
|
+
chainId,
|
|
67
74
|
account,
|
|
75
|
+
provider,
|
|
68
76
|
)
|
|
69
77
|
const [, refreshLenderPosition] = useLenderPosition(
|
|
70
78
|
poolName,
|
|
71
79
|
poolType,
|
|
80
|
+
chainId,
|
|
72
81
|
account,
|
|
82
|
+
provider,
|
|
73
83
|
)
|
|
74
84
|
const withdrawlLockoutSeconds = useWithdrawlLockoutInSeconds(
|
|
75
85
|
poolName,
|
|
76
86
|
poolType,
|
|
87
|
+
chainId,
|
|
88
|
+
provider,
|
|
77
89
|
)
|
|
78
90
|
const underlyingTokenBalance = usePoolUnderlyingTokenBalance(
|
|
79
91
|
poolName,
|
|
80
92
|
poolType,
|
|
93
|
+
chainId,
|
|
81
94
|
account,
|
|
95
|
+
provider,
|
|
82
96
|
)
|
|
83
97
|
const balanceWithoutDecimals = downScale(underlyingTokenBalance, decimals)
|
|
84
98
|
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
import {
|
|
2
|
+
openInNewTab,
|
|
3
|
+
PoolInfoV2,
|
|
4
|
+
TrancheType,
|
|
5
|
+
UnderlyingTokenInfo,
|
|
6
|
+
useLenderApprovedV2,
|
|
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 React from 'react'
|
|
19
|
+
|
|
20
|
+
import { useAppDispatch } from '../../../hooks/useRedux'
|
|
21
|
+
import { setStep } from '../../../store/widgets.reducers'
|
|
22
|
+
import { WIDGET_STEP } from '../../../store/widgets.store'
|
|
23
|
+
import { BottomButton } from '../../BottomButton'
|
|
24
|
+
import { WrapperModal } from '../../WrapperModal'
|
|
25
|
+
import { LoadingModal } from '../../LoadingModal'
|
|
26
|
+
|
|
27
|
+
type Props = {
|
|
28
|
+
poolInfo: PoolInfoV2
|
|
29
|
+
poolUnderlyingToken: UnderlyingTokenInfo
|
|
30
|
+
selectedTranche: TrancheType | undefined
|
|
31
|
+
changeTranche: (tranche: TrancheType) => void
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export function ChooseTranche({
|
|
35
|
+
poolInfo,
|
|
36
|
+
poolUnderlyingToken,
|
|
37
|
+
selectedTranche,
|
|
38
|
+
changeTranche,
|
|
39
|
+
}: Props): React.ReactElement | null {
|
|
40
|
+
const theme = useTheme()
|
|
41
|
+
const { poolName } = poolInfo
|
|
42
|
+
const dispatch = useAppDispatch()
|
|
43
|
+
const { account, provider } = useWeb3React()
|
|
44
|
+
const [lenderApprovedSenior] = useLenderApprovedV2(
|
|
45
|
+
poolName,
|
|
46
|
+
'senior',
|
|
47
|
+
account,
|
|
48
|
+
provider,
|
|
49
|
+
)
|
|
50
|
+
const [lenderApprovedJunior] = useLenderApprovedV2(
|
|
51
|
+
poolName,
|
|
52
|
+
'junior',
|
|
53
|
+
account,
|
|
54
|
+
provider,
|
|
55
|
+
)
|
|
56
|
+
const isLoading =
|
|
57
|
+
lenderApprovedSenior === undefined || lenderApprovedJunior === undefined
|
|
58
|
+
|
|
59
|
+
const styles = {
|
|
60
|
+
subTitle: css`
|
|
61
|
+
color: ${theme.palette.text.primary} !important;
|
|
62
|
+
font-family: 'Uni-Neue-Regular';
|
|
63
|
+
font-size: 16px;
|
|
64
|
+
line-height: 150%;
|
|
65
|
+
letter-spacing: 0.15px;
|
|
66
|
+
margin-top: ${theme.spacing(5)};
|
|
67
|
+
margin-left: ${theme.spacing(2)};
|
|
68
|
+
`,
|
|
69
|
+
radioGroup: css`
|
|
70
|
+
margin-left: ${theme.spacing(3)};
|
|
71
|
+
margin-top: ${theme.spacing(3)};
|
|
72
|
+
`,
|
|
73
|
+
formControl: css`
|
|
74
|
+
margin-bottom: ${theme.spacing(1)};
|
|
75
|
+
|
|
76
|
+
.MuiFormControlLabel-label {
|
|
77
|
+
color: ${theme.palette.text.primary};
|
|
78
|
+
font-family: 'Uni-Neue-Regular';
|
|
79
|
+
font-size: 16px;
|
|
80
|
+
line-height: 150%;
|
|
81
|
+
letter-spacing: 0.15px;
|
|
82
|
+
}
|
|
83
|
+
`,
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
const handleNext = () => {
|
|
87
|
+
if (
|
|
88
|
+
(selectedTranche === 'senior' && lenderApprovedSenior) ||
|
|
89
|
+
(selectedTranche === 'junior' && lenderApprovedJunior)
|
|
90
|
+
) {
|
|
91
|
+
dispatch(setStep(WIDGET_STEP.ChooseAmount))
|
|
92
|
+
} else if (poolInfo.KYC) {
|
|
93
|
+
dispatch(setStep(WIDGET_STEP.Evaluation))
|
|
94
|
+
} else if (poolInfo.supplyLink) {
|
|
95
|
+
openInNewTab(poolInfo.supplyLink)
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
const items: {
|
|
100
|
+
label: string
|
|
101
|
+
value: TrancheType
|
|
102
|
+
}[] = [
|
|
103
|
+
{
|
|
104
|
+
label: 'Senior',
|
|
105
|
+
value: 'senior',
|
|
106
|
+
},
|
|
107
|
+
{
|
|
108
|
+
label: 'Junior',
|
|
109
|
+
value: 'junior',
|
|
110
|
+
},
|
|
111
|
+
]
|
|
112
|
+
|
|
113
|
+
if (isLoading) {
|
|
114
|
+
return <LoadingModal title={`Supply ${poolUnderlyingToken.symbol}`} />
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
return (
|
|
118
|
+
<WrapperModal title={`Supply ${poolUnderlyingToken.symbol}`}>
|
|
119
|
+
<FormControl>
|
|
120
|
+
<FormLabel css={styles.subTitle}>Select Tranche Type</FormLabel>
|
|
121
|
+
<RadioGroup
|
|
122
|
+
aria-labelledby='buttons-group-label'
|
|
123
|
+
name='radio-buttons-group'
|
|
124
|
+
css={styles.radioGroup}
|
|
125
|
+
onChange={(e) => changeTranche(e.target.value as TrancheType)}
|
|
126
|
+
>
|
|
127
|
+
{items.map((item) => (
|
|
128
|
+
<FormControlLabel
|
|
129
|
+
key={item.label}
|
|
130
|
+
value={item.value}
|
|
131
|
+
control={
|
|
132
|
+
<Radio
|
|
133
|
+
sx={{
|
|
134
|
+
'& .MuiSvgIcon-root': {
|
|
135
|
+
fontSize: 24,
|
|
136
|
+
},
|
|
137
|
+
}}
|
|
138
|
+
/>
|
|
139
|
+
}
|
|
140
|
+
label={item.label}
|
|
141
|
+
css={styles.formControl}
|
|
142
|
+
/>
|
|
143
|
+
))}
|
|
144
|
+
</RadioGroup>
|
|
145
|
+
</FormControl>
|
|
146
|
+
<BottomButton
|
|
147
|
+
variant='contained'
|
|
148
|
+
disabled={!selectedTranche}
|
|
149
|
+
onClick={handleNext}
|
|
150
|
+
>
|
|
151
|
+
NEXT
|
|
152
|
+
</BottomButton>
|
|
153
|
+
</WrapperModal>
|
|
154
|
+
)
|
|
155
|
+
}
|