@huma-finance/widgets 0.0.48-beta.200 → 0.0.48-beta.279
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,345 @@
|
|
|
1
|
+
import {
|
|
2
|
+
CHAINS,
|
|
3
|
+
checkIsDev,
|
|
4
|
+
configUtil,
|
|
5
|
+
DocSignatureStatus,
|
|
6
|
+
IdentityService,
|
|
7
|
+
KYCCopy,
|
|
8
|
+
PoolInfoV2,
|
|
9
|
+
timeUtil,
|
|
10
|
+
useAuthErrorHandling,
|
|
11
|
+
useParamsSearch,
|
|
12
|
+
VerificationStatusResult,
|
|
13
|
+
} from '@huma-finance/shared'
|
|
14
|
+
import { Box, css, useTheme } from '@mui/material'
|
|
15
|
+
import { useWeb3React } from '@web3-react/core'
|
|
16
|
+
import React, { useCallback, useEffect, useMemo, useState } from 'react'
|
|
17
|
+
|
|
18
|
+
import { useAppDispatch } from '../../../hooks/useRedux'
|
|
19
|
+
import { setError } from '../../../store/widgets.reducers'
|
|
20
|
+
import { BottomButton } from '../../BottomButton'
|
|
21
|
+
import { HumaSnackBar } from '../../HumaSnackBar'
|
|
22
|
+
import { ApproveLenderImg } from '../../images'
|
|
23
|
+
import { LoadingModal } from '../../LoadingModal'
|
|
24
|
+
import { WrapperModal } from '../../WrapperModal'
|
|
25
|
+
|
|
26
|
+
const LoadingCopiesByType: {
|
|
27
|
+
[key: string]: {
|
|
28
|
+
description: string
|
|
29
|
+
}
|
|
30
|
+
} = {
|
|
31
|
+
verificationStatus: {
|
|
32
|
+
description: `Checking your verification status...`,
|
|
33
|
+
},
|
|
34
|
+
sendDocSignatureLink: {
|
|
35
|
+
description: `Sending signature link...`,
|
|
36
|
+
},
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
type Props = {
|
|
40
|
+
poolInfo: PoolInfoV2
|
|
41
|
+
handleClose: () => void
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export function Evaluation({
|
|
45
|
+
poolInfo,
|
|
46
|
+
handleClose,
|
|
47
|
+
}: Props): React.ReactElement | null {
|
|
48
|
+
const theme = useTheme()
|
|
49
|
+
const dispatch = useAppDispatch()
|
|
50
|
+
const isDev = checkIsDev()
|
|
51
|
+
const { account, chainId } = useWeb3React()
|
|
52
|
+
const { kycProvider, code, kycPool } = useParamsSearch()
|
|
53
|
+
const {
|
|
54
|
+
isWalletOwnershipVerified,
|
|
55
|
+
setError: setAuthError,
|
|
56
|
+
error: authError,
|
|
57
|
+
} = useAuthErrorHandling(isDev)
|
|
58
|
+
const [loadingType, setLoadingType] = useState<
|
|
59
|
+
'verificationStatus' | 'sendDocSignatureLink'
|
|
60
|
+
>()
|
|
61
|
+
const KYCCopies = poolInfo.KYC!
|
|
62
|
+
const [kycCopy, setKYCCopy] = useState<KYCCopy>(KYCCopies.verifyIdentity)
|
|
63
|
+
const [KYCVerifyStatus, setKYCVerifyStatus] =
|
|
64
|
+
useState<VerificationStatusResult>()
|
|
65
|
+
const [docSignatureStatus, setDocSignatureStatus] =
|
|
66
|
+
useState<DocSignatureStatus['status']>()
|
|
67
|
+
const docSignatureCompleted = docSignatureStatus === 'completed'
|
|
68
|
+
const [openSnackBar, setOpenSnackBar] = useState<boolean>(false)
|
|
69
|
+
|
|
70
|
+
const styles = {
|
|
71
|
+
iconWrapper: css`
|
|
72
|
+
${theme.cssMixins.rowCentered};
|
|
73
|
+
margin-top: ${theme.spacing(8)};
|
|
74
|
+
& > img {
|
|
75
|
+
width: 144px;
|
|
76
|
+
}
|
|
77
|
+
`,
|
|
78
|
+
description: css`
|
|
79
|
+
${theme.cssMixins.rowCentered};
|
|
80
|
+
margin-top: ${theme.spacing(10)};
|
|
81
|
+
padding: ${theme.spacing(0, 2)};
|
|
82
|
+
font-family: 'Uni-Neue-Regular';
|
|
83
|
+
font-size: 16px;
|
|
84
|
+
color: #a8a1b2;
|
|
85
|
+
`,
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
const { envelopeKey, envelopeLastQueryTimeKey, envelopeDocuSignStatusKey } =
|
|
89
|
+
useMemo(() => {
|
|
90
|
+
const envelopeKey = `${poolInfo.pool.toLowerCase()}-${account?.toLowerCase()}`
|
|
91
|
+
const envelopeLastQueryTimeKey = `${envelopeKey}-last-query-time`
|
|
92
|
+
const envelopeDocuSignStatusKey = `${envelopeKey}-docuSign-status`
|
|
93
|
+
return {
|
|
94
|
+
envelopeKey,
|
|
95
|
+
envelopeLastQueryTimeKey,
|
|
96
|
+
envelopeDocuSignStatusKey,
|
|
97
|
+
}
|
|
98
|
+
}, [account, poolInfo.pool])
|
|
99
|
+
|
|
100
|
+
// DocuSign GET requests to any specific URL can be called not more often than once every 15 minutes.
|
|
101
|
+
// https://developers.docusign.com/platform/api-guidelines/#:~:text=Polling,not%20once%20every%2010%20minutes
|
|
102
|
+
const checkGetDocSignatureStatusIsAvailable = useCallback(() => {
|
|
103
|
+
const lastQueryTime = localStorage.getItem(envelopeLastQueryTimeKey)
|
|
104
|
+
if (!lastQueryTime) {
|
|
105
|
+
return true
|
|
106
|
+
}
|
|
107
|
+
const lastQueryTimeNumber = Number(lastQueryTime)
|
|
108
|
+
const now = timeUtil.getUnixTimestamp()
|
|
109
|
+
const diff = now - lastQueryTimeNumber
|
|
110
|
+
const fifteenMinutes = 15 * 60
|
|
111
|
+
return diff > fifteenMinutes
|
|
112
|
+
}, [envelopeLastQueryTimeKey])
|
|
113
|
+
|
|
114
|
+
useEffect(() => {
|
|
115
|
+
const docuSignStatus = localStorage.getItem(envelopeDocuSignStatusKey)
|
|
116
|
+
setDocSignatureStatus(docuSignStatus as DocSignatureStatus['status'])
|
|
117
|
+
if (docuSignStatus === 'completed') {
|
|
118
|
+
setKYCCopy(KYCCopies.docUnderReview)
|
|
119
|
+
return
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
const fetchData = async () => {
|
|
123
|
+
try {
|
|
124
|
+
if (kycProvider && kycPool && account && chainId) {
|
|
125
|
+
setLoadingType('verificationStatus')
|
|
126
|
+
await IdentityService.onboard(
|
|
127
|
+
account,
|
|
128
|
+
code as string,
|
|
129
|
+
kycPool as string,
|
|
130
|
+
chainId,
|
|
131
|
+
isDev,
|
|
132
|
+
)
|
|
133
|
+
}
|
|
134
|
+
} catch (e) {
|
|
135
|
+
try {
|
|
136
|
+
setAuthError(e)
|
|
137
|
+
setKYCCopy(KYCCopies.signInRequired)
|
|
138
|
+
} catch (e) {
|
|
139
|
+
// The repeated call will throw an error of 401, so we can ignore it.
|
|
140
|
+
console.log(e)
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
try {
|
|
145
|
+
if (account && chainId) {
|
|
146
|
+
setLoadingType('verificationStatus')
|
|
147
|
+
const verificationStatus =
|
|
148
|
+
await IdentityService.getVerificationStatus(
|
|
149
|
+
account,
|
|
150
|
+
poolInfo.pool,
|
|
151
|
+
chainId,
|
|
152
|
+
isDev,
|
|
153
|
+
)
|
|
154
|
+
setKYCVerifyStatus(verificationStatus)
|
|
155
|
+
if (verificationStatus.isVerified) {
|
|
156
|
+
const envelopeId = localStorage.getItem(envelopeKey)
|
|
157
|
+
if (!envelopeId) {
|
|
158
|
+
setKYCCopy(KYCCopies.emailSignatureLink)
|
|
159
|
+
} else if (!checkGetDocSignatureStatusIsAvailable()) {
|
|
160
|
+
setKYCCopy(KYCCopies.resendSignatureLink)
|
|
161
|
+
} else {
|
|
162
|
+
const { status } = await IdentityService.getDocSignatureStatus(
|
|
163
|
+
envelopeId,
|
|
164
|
+
chainId,
|
|
165
|
+
isDev,
|
|
166
|
+
)
|
|
167
|
+
localStorage.setItem(
|
|
168
|
+
envelopeLastQueryTimeKey,
|
|
169
|
+
String(timeUtil.getUnixTimestamp()),
|
|
170
|
+
)
|
|
171
|
+
localStorage.setItem(envelopeDocuSignStatusKey, status)
|
|
172
|
+
setDocSignatureStatus(status)
|
|
173
|
+
if (status === 'completed') {
|
|
174
|
+
setKYCCopy(KYCCopies.docUnderReview)
|
|
175
|
+
// For voided and declined status, we need to send a new link
|
|
176
|
+
} else if (['voided', 'declined'].includes(status)) {
|
|
177
|
+
localStorage.removeItem(envelopeKey)
|
|
178
|
+
localStorage.removeItem(envelopeLastQueryTimeKey)
|
|
179
|
+
setKYCCopy(KYCCopies.emailSignatureLink)
|
|
180
|
+
} else {
|
|
181
|
+
setKYCCopy(KYCCopies.resendSignatureLink)
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
} else {
|
|
185
|
+
setKYCCopy(KYCCopies.verifyIdentity)
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
} catch (e: unknown) {
|
|
189
|
+
try {
|
|
190
|
+
setAuthError(e)
|
|
191
|
+
setKYCCopy(KYCCopies.signInRequired)
|
|
192
|
+
} catch (e) {
|
|
193
|
+
console.error(e)
|
|
194
|
+
dispatch(
|
|
195
|
+
setError({
|
|
196
|
+
errorMessage: 'Something went wrong, please try again later.',
|
|
197
|
+
}),
|
|
198
|
+
)
|
|
199
|
+
}
|
|
200
|
+
} finally {
|
|
201
|
+
setLoadingType(undefined)
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
fetchData()
|
|
205
|
+
}, [
|
|
206
|
+
KYCCopies.docUnderReview,
|
|
207
|
+
KYCCopies.emailSignatureLink,
|
|
208
|
+
KYCCopies.resendSignatureLink,
|
|
209
|
+
KYCCopies.signInRequired,
|
|
210
|
+
KYCCopies.verifyIdentity,
|
|
211
|
+
account,
|
|
212
|
+
chainId,
|
|
213
|
+
checkGetDocSignatureStatusIsAvailable,
|
|
214
|
+
code,
|
|
215
|
+
dispatch,
|
|
216
|
+
envelopeDocuSignStatusKey,
|
|
217
|
+
envelopeKey,
|
|
218
|
+
envelopeLastQueryTimeKey,
|
|
219
|
+
isDev,
|
|
220
|
+
kycPool,
|
|
221
|
+
kycProvider,
|
|
222
|
+
poolInfo.pool,
|
|
223
|
+
setAuthError,
|
|
224
|
+
isWalletOwnershipVerified,
|
|
225
|
+
])
|
|
226
|
+
|
|
227
|
+
useEffect(() => {
|
|
228
|
+
if (
|
|
229
|
+
authError &&
|
|
230
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
231
|
+
[4001, 'ACTION_REJECTED'].includes((authError as any).code)
|
|
232
|
+
) {
|
|
233
|
+
dispatch(
|
|
234
|
+
setError({
|
|
235
|
+
errorMessage: 'User has rejected the transaction.',
|
|
236
|
+
}),
|
|
237
|
+
)
|
|
238
|
+
}
|
|
239
|
+
}, [authError, dispatch])
|
|
240
|
+
|
|
241
|
+
const approveLender = async () => {
|
|
242
|
+
if (docSignatureCompleted) {
|
|
243
|
+
handleClose()
|
|
244
|
+
return
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
const { isNotOnboarded, isVerified } = KYCVerifyStatus || {}
|
|
248
|
+
|
|
249
|
+
if (!isVerified) {
|
|
250
|
+
const issuerId = CHAINS[chainId!].isTestnet
|
|
251
|
+
? '53a66b32-583e-40e7-ba90-baf516d2cadd'
|
|
252
|
+
: '5557baf5-d3c2-4c80-b522-c05a11c6e586'
|
|
253
|
+
const baseUrl = configUtil.getKYCProviderBaseUrl(
|
|
254
|
+
poolInfo.KYC!.provider,
|
|
255
|
+
chainId!,
|
|
256
|
+
)
|
|
257
|
+
const originUrl = window.location.href.split('?')[0]
|
|
258
|
+
const redirectUrl = `${originUrl}?poolName=${
|
|
259
|
+
poolInfo.poolName
|
|
260
|
+
}&kycProvider=${poolInfo.KYC!.provider}&kycPool=${poolInfo.pool}`
|
|
261
|
+
const providerAuthorizeUrl = `${baseUrl}/#/authorize?issuerId=${issuerId}&scope=details&details=verification&redirectUrl=${redirectUrl}`
|
|
262
|
+
window.location.href = isNotOnboarded ? providerAuthorizeUrl : baseUrl
|
|
263
|
+
} else {
|
|
264
|
+
const envelopeId = localStorage.getItem(envelopeKey)
|
|
265
|
+
try {
|
|
266
|
+
setLoadingType('sendDocSignatureLink')
|
|
267
|
+
if (!envelopeId) {
|
|
268
|
+
const { envelopeId } = await IdentityService.requestDocSignature(
|
|
269
|
+
account!,
|
|
270
|
+
chainId!,
|
|
271
|
+
isDev,
|
|
272
|
+
)
|
|
273
|
+
localStorage.setItem(envelopeKey, envelopeId)
|
|
274
|
+
localStorage.setItem(
|
|
275
|
+
envelopeLastQueryTimeKey,
|
|
276
|
+
String(timeUtil.getUnixTimestamp()),
|
|
277
|
+
)
|
|
278
|
+
setOpenSnackBar(true)
|
|
279
|
+
setKYCCopy(KYCCopies.resendSignatureLink)
|
|
280
|
+
} else {
|
|
281
|
+
await IdentityService.resendDocSignatureLink(
|
|
282
|
+
envelopeId,
|
|
283
|
+
chainId!,
|
|
284
|
+
isDev,
|
|
285
|
+
)
|
|
286
|
+
setOpenSnackBar(true)
|
|
287
|
+
}
|
|
288
|
+
} catch (e: unknown) {
|
|
289
|
+
try {
|
|
290
|
+
const { envelopeId } = await IdentityService.requestDocSignature(
|
|
291
|
+
account!,
|
|
292
|
+
chainId!,
|
|
293
|
+
isDev,
|
|
294
|
+
)
|
|
295
|
+
localStorage.setItem(envelopeKey, envelopeId)
|
|
296
|
+
localStorage.setItem(
|
|
297
|
+
envelopeLastQueryTimeKey,
|
|
298
|
+
String(timeUtil.getUnixTimestamp()),
|
|
299
|
+
)
|
|
300
|
+
setOpenSnackBar(true)
|
|
301
|
+
setKYCCopy(KYCCopies.resendSignatureLink)
|
|
302
|
+
} catch (e) {
|
|
303
|
+
setAuthError(e)
|
|
304
|
+
setKYCCopy(KYCCopies.signInRequired)
|
|
305
|
+
}
|
|
306
|
+
} finally {
|
|
307
|
+
setLoadingType(undefined)
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
const getEmailLinkSentSnackbar = () => (
|
|
313
|
+
<HumaSnackBar
|
|
314
|
+
open={openSnackBar}
|
|
315
|
+
title='Signature Link Sent'
|
|
316
|
+
message='The secure signature session link has been sent to you via email.'
|
|
317
|
+
severity='success'
|
|
318
|
+
onClose={() => setOpenSnackBar(false)}
|
|
319
|
+
/>
|
|
320
|
+
)
|
|
321
|
+
|
|
322
|
+
if (!loadingType) {
|
|
323
|
+
return (
|
|
324
|
+
<WrapperModal title={kycCopy.title}>
|
|
325
|
+
<Box css={styles.iconWrapper}>
|
|
326
|
+
<img src={ApproveLenderImg} alt='approve-lender' />
|
|
327
|
+
</Box>
|
|
328
|
+
<Box css={styles.description}>{kycCopy.description}</Box>
|
|
329
|
+
{Boolean(kycCopy.buttonText) && (
|
|
330
|
+
<BottomButton variant='contained' onClick={approveLender}>
|
|
331
|
+
{kycCopy.buttonText}
|
|
332
|
+
</BottomButton>
|
|
333
|
+
)}
|
|
334
|
+
{getEmailLinkSentSnackbar()}
|
|
335
|
+
</WrapperModal>
|
|
336
|
+
)
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
return (
|
|
340
|
+
<LoadingModal
|
|
341
|
+
title='Lender Approval'
|
|
342
|
+
description={LoadingCopiesByType[loadingType].description}
|
|
343
|
+
/>
|
|
344
|
+
)
|
|
345
|
+
}
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import {
|
|
2
|
+
PoolInfoV2,
|
|
3
|
+
TrancheType,
|
|
4
|
+
UnderlyingTokenInfo,
|
|
5
|
+
usePoolSafeAllowanceV2,
|
|
6
|
+
} from '@huma-finance/shared'
|
|
7
|
+
import { Box, css, TextField, useTheme } from '@mui/material'
|
|
8
|
+
import { useWeb3React } from '@web3-react/core'
|
|
9
|
+
import { BigNumber, ethers } from 'ethers'
|
|
10
|
+
import React, { useState } from 'react'
|
|
11
|
+
|
|
12
|
+
import { useAppDispatch } from '../../../hooks/useRedux'
|
|
13
|
+
import { setStep, setSupplyAmount } from '../../../store/widgets.reducers'
|
|
14
|
+
import { WIDGET_STEP } from '../../../store/widgets.store'
|
|
15
|
+
import { BottomButton } from '../../BottomButton'
|
|
16
|
+
import { NumericFormatCustom } from '../../NumericFormatCustom'
|
|
17
|
+
import { WrapperModal } from '../../WrapperModal'
|
|
18
|
+
|
|
19
|
+
type Props = {
|
|
20
|
+
poolInfo: PoolInfoV2
|
|
21
|
+
poolUnderlyingToken: UnderlyingTokenInfo
|
|
22
|
+
selectedTranche: TrancheType | undefined
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export function ChooseAmount({
|
|
26
|
+
poolInfo,
|
|
27
|
+
poolUnderlyingToken,
|
|
28
|
+
selectedTranche,
|
|
29
|
+
}: Props): React.ReactElement | null {
|
|
30
|
+
const theme = useTheme()
|
|
31
|
+
const dispatch = useAppDispatch()
|
|
32
|
+
const { account, provider } = useWeb3React()
|
|
33
|
+
const { symbol, decimals } = poolUnderlyingToken
|
|
34
|
+
const [currentAmount, setCurrentAmount] = useState<number | string>(0)
|
|
35
|
+
const { allowance = BigNumber.from(0) } = usePoolSafeAllowanceV2(
|
|
36
|
+
poolInfo.poolName,
|
|
37
|
+
account,
|
|
38
|
+
provider,
|
|
39
|
+
)
|
|
40
|
+
const [inputTouched, setInputTouched] = useState(false)
|
|
41
|
+
|
|
42
|
+
const styles = {
|
|
43
|
+
inputAmountWrapper: css`
|
|
44
|
+
margin-bottom: ${theme.spacing(1)};
|
|
45
|
+
margin-top: ${theme.spacing(16)};
|
|
46
|
+
`,
|
|
47
|
+
inputAmount: css`
|
|
48
|
+
${theme.cssMixins.rowSpaceBetweened};
|
|
49
|
+
`,
|
|
50
|
+
inputField: css`
|
|
51
|
+
input {
|
|
52
|
+
width: 100%;
|
|
53
|
+
color: ${theme.palette.text.primary};
|
|
54
|
+
font-family: 'Uni-Neue-Black';
|
|
55
|
+
font-size: 40px;
|
|
56
|
+
line-height: 133.4%;
|
|
57
|
+
}
|
|
58
|
+
`,
|
|
59
|
+
inputFieldSymbol: css`
|
|
60
|
+
color: ${theme.palette.text.primary};
|
|
61
|
+
font-family: 'Uni-Neue-Black';
|
|
62
|
+
font-size: 40px;
|
|
63
|
+
line-height: 133.4%;
|
|
64
|
+
`,
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
const handleChangeAmount = (
|
|
68
|
+
event: React.ChangeEvent<HTMLTextAreaElement | HTMLInputElement>,
|
|
69
|
+
) => {
|
|
70
|
+
setInputTouched(true)
|
|
71
|
+
const newAmount = event.target.value
|
|
72
|
+
setCurrentAmount(newAmount)
|
|
73
|
+
dispatch(setSupplyAmount(Number(newAmount)))
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
const handleAction = () => {
|
|
77
|
+
const currentAmountBN = ethers.utils.parseUnits(
|
|
78
|
+
String(currentAmount),
|
|
79
|
+
decimals,
|
|
80
|
+
)
|
|
81
|
+
const step = currentAmountBN.gt(allowance)
|
|
82
|
+
? WIDGET_STEP.ApproveAllowance
|
|
83
|
+
: WIDGET_STEP.Transfer
|
|
84
|
+
dispatch(setStep(step))
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
return (
|
|
88
|
+
<WrapperModal
|
|
89
|
+
title='Enter Amount'
|
|
90
|
+
subTitle={`Supplying ${symbol} with ${selectedTranche}`}
|
|
91
|
+
>
|
|
92
|
+
<Box css={styles.inputAmountWrapper}>
|
|
93
|
+
<Box css={styles.inputAmount}>
|
|
94
|
+
<TextField
|
|
95
|
+
css={styles.inputField}
|
|
96
|
+
value={!inputTouched && currentAmount === 0 ? '' : currentAmount}
|
|
97
|
+
onChange={handleChangeAmount}
|
|
98
|
+
InputProps={{
|
|
99
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
100
|
+
inputComponent: NumericFormatCustom as any,
|
|
101
|
+
endAdornment: (
|
|
102
|
+
<Box component='span' css={styles.inputFieldSymbol}>
|
|
103
|
+
{symbol}
|
|
104
|
+
</Box>
|
|
105
|
+
),
|
|
106
|
+
}}
|
|
107
|
+
placeholder='0'
|
|
108
|
+
variant='standard'
|
|
109
|
+
/>
|
|
110
|
+
</Box>
|
|
111
|
+
</Box>
|
|
112
|
+
|
|
113
|
+
<BottomButton
|
|
114
|
+
variant='contained'
|
|
115
|
+
onClick={handleAction}
|
|
116
|
+
disabled={Number(currentAmount) <= 0}
|
|
117
|
+
>
|
|
118
|
+
SUPPLY
|
|
119
|
+
</BottomButton>
|
|
120
|
+
</WrapperModal>
|
|
121
|
+
)
|
|
122
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { PoolInfoV2, UnderlyingTokenInfo } from '@huma-finance/shared'
|
|
2
|
+
import React, { useCallback } from 'react'
|
|
3
|
+
|
|
4
|
+
import { useAppDispatch } from '../../../hooks/useRedux'
|
|
5
|
+
import { setStep } from '../../../store/widgets.reducers'
|
|
6
|
+
import { WIDGET_STEP } from '../../../store/widgets.store'
|
|
7
|
+
import { ApproveAllowanceModalV2 } from '../../ApproveAllowanceModalV2'
|
|
8
|
+
|
|
9
|
+
type Props = {
|
|
10
|
+
poolInfo: PoolInfoV2
|
|
11
|
+
poolUnderlyingToken: UnderlyingTokenInfo
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export function ApproveAllowance({
|
|
15
|
+
poolInfo,
|
|
16
|
+
poolUnderlyingToken,
|
|
17
|
+
}: Props): React.ReactElement | null {
|
|
18
|
+
const dispatch = useAppDispatch()
|
|
19
|
+
const spender = poolInfo.poolSafe
|
|
20
|
+
|
|
21
|
+
const handleSuccess = useCallback(() => {
|
|
22
|
+
dispatch(setStep(WIDGET_STEP.Transfer))
|
|
23
|
+
}, [dispatch])
|
|
24
|
+
|
|
25
|
+
return (
|
|
26
|
+
<ApproveAllowanceModalV2
|
|
27
|
+
poolInfo={poolInfo}
|
|
28
|
+
poolUnderlyingToken={poolUnderlyingToken}
|
|
29
|
+
spender={spender}
|
|
30
|
+
handleSuccess={handleSuccess}
|
|
31
|
+
/>
|
|
32
|
+
)
|
|
33
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import {
|
|
2
|
+
PoolInfoV2,
|
|
3
|
+
useTrancheVaultContractV2,
|
|
4
|
+
TrancheType,
|
|
5
|
+
UnderlyingTokenInfo,
|
|
6
|
+
} from '@huma-finance/shared'
|
|
7
|
+
import { useWeb3React } from '@web3-react/core'
|
|
8
|
+
import { ethers } from 'ethers'
|
|
9
|
+
import React, { useCallback } from 'react'
|
|
10
|
+
|
|
11
|
+
import { useAppDispatch, 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 { TxSendModalV2 } from '../../TxSendModalV2'
|
|
16
|
+
|
|
17
|
+
type Props = {
|
|
18
|
+
poolInfo: PoolInfoV2
|
|
19
|
+
poolUnderlyingToken: UnderlyingTokenInfo
|
|
20
|
+
trancheType: TrancheType
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function Transfer({
|
|
24
|
+
poolInfo,
|
|
25
|
+
poolUnderlyingToken,
|
|
26
|
+
trancheType,
|
|
27
|
+
}: Props): React.ReactElement | null {
|
|
28
|
+
const dispatch = useAppDispatch()
|
|
29
|
+
const { account, provider } = useWeb3React()
|
|
30
|
+
const { supplyAmount } = useAppSelector(selectWidgetState)
|
|
31
|
+
const { decimals } = poolUnderlyingToken
|
|
32
|
+
const supplyBigNumber = ethers.utils.parseUnits(
|
|
33
|
+
String(supplyAmount),
|
|
34
|
+
decimals,
|
|
35
|
+
)
|
|
36
|
+
const trancheVaultContract = useTrancheVaultContractV2(
|
|
37
|
+
poolInfo.poolName,
|
|
38
|
+
trancheType,
|
|
39
|
+
provider,
|
|
40
|
+
account,
|
|
41
|
+
)
|
|
42
|
+
|
|
43
|
+
const handleSuccess = useCallback(() => {
|
|
44
|
+
dispatch(setStep(WIDGET_STEP.Done))
|
|
45
|
+
}, [dispatch])
|
|
46
|
+
|
|
47
|
+
if (!trancheVaultContract || !account) {
|
|
48
|
+
return null
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
return (
|
|
52
|
+
<TxSendModalV2
|
|
53
|
+
contract={trancheVaultContract}
|
|
54
|
+
method='deposit'
|
|
55
|
+
params={[supplyBigNumber, account]}
|
|
56
|
+
handleSuccess={handleSuccess}
|
|
57
|
+
/>
|
|
58
|
+
)
|
|
59
|
+
}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import {
|
|
2
|
+
decodeLogs,
|
|
3
|
+
downScale,
|
|
4
|
+
formatMoney,
|
|
5
|
+
PoolInfoV2,
|
|
6
|
+
sendTxAtom,
|
|
7
|
+
TRANSFER_ABI,
|
|
8
|
+
UnderlyingTokenInfo,
|
|
9
|
+
} from '@huma-finance/shared'
|
|
10
|
+
import { useWeb3React } from '@web3-react/core'
|
|
11
|
+
import { useAtom } from 'jotai'
|
|
12
|
+
import React, { useCallback, useEffect, useState } from 'react'
|
|
13
|
+
import { useDispatch } from 'react-redux'
|
|
14
|
+
|
|
15
|
+
import {
|
|
16
|
+
useDoesChainSupportNotifi,
|
|
17
|
+
useIsFirstTimeNotifiUser,
|
|
18
|
+
} from '../../../hooks/useNotifi'
|
|
19
|
+
import { TxDoneModal } from '../../TxDoneModal'
|
|
20
|
+
import { setStep } from '../../../store/widgets.reducers'
|
|
21
|
+
import { WIDGET_STEP } from '../../../store/widgets.store'
|
|
22
|
+
|
|
23
|
+
type Props = {
|
|
24
|
+
poolInfo: PoolInfoV2
|
|
25
|
+
poolUnderlyingToken: UnderlyingTokenInfo
|
|
26
|
+
handleAction: () => void
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export function Success({
|
|
30
|
+
poolInfo,
|
|
31
|
+
poolUnderlyingToken,
|
|
32
|
+
handleAction,
|
|
33
|
+
}: Props): React.ReactElement {
|
|
34
|
+
const dispatch = useDispatch()
|
|
35
|
+
const { account, chainId } = useWeb3React()
|
|
36
|
+
const [{ txReceipt }] = useAtom(sendTxAtom)
|
|
37
|
+
const { symbol, decimals, address } = poolUnderlyingToken
|
|
38
|
+
const [supplyAmount, setSupplyAmount] = useState<string | undefined>()
|
|
39
|
+
const { isFirstTimeNotifiUser } = useIsFirstTimeNotifiUser(account, chainId)
|
|
40
|
+
const { notifiChainSupported } = useDoesChainSupportNotifi(account, chainId)
|
|
41
|
+
const hasNextStep = isFirstTimeNotifiUser
|
|
42
|
+
|
|
43
|
+
useEffect(() => {
|
|
44
|
+
if (txReceipt) {
|
|
45
|
+
const events = decodeLogs(txReceipt.logs, TRANSFER_ABI)
|
|
46
|
+
if (events) {
|
|
47
|
+
events.forEach((event) => {
|
|
48
|
+
const { from, to, value } = event.args
|
|
49
|
+
if (
|
|
50
|
+
from.toLowerCase() === account?.toLowerCase() &&
|
|
51
|
+
to.toLowerCase() === poolInfo.poolSafe.toLowerCase()
|
|
52
|
+
) {
|
|
53
|
+
setSupplyAmount(downScale(value.toString(), decimals))
|
|
54
|
+
}
|
|
55
|
+
})
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}, [account, address, decimals, poolInfo.poolSafe, txReceipt])
|
|
59
|
+
|
|
60
|
+
const setupNotificationsOrClose = useCallback(() => {
|
|
61
|
+
if (isFirstTimeNotifiUser && notifiChainSupported) {
|
|
62
|
+
dispatch(setStep(WIDGET_STEP.Notifications))
|
|
63
|
+
} else {
|
|
64
|
+
handleAction()
|
|
65
|
+
}
|
|
66
|
+
}, [dispatch, handleAction, isFirstTimeNotifiUser, notifiChainSupported])
|
|
67
|
+
|
|
68
|
+
const content = [
|
|
69
|
+
`You successfully supplied ${formatMoney(supplyAmount)} ${symbol}.`,
|
|
70
|
+
]
|
|
71
|
+
|
|
72
|
+
return (
|
|
73
|
+
<TxDoneModal
|
|
74
|
+
handleAction={setupNotificationsOrClose}
|
|
75
|
+
content={content}
|
|
76
|
+
buttonText={hasNextStep ? "WHAT'S NEXT" : undefined}
|
|
77
|
+
/>
|
|
78
|
+
)
|
|
79
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import React from 'react'
|
|
2
|
+
import { NotifiSubscriptionModal } from '../../Notifi/NotifiSubscriptionModal'
|
|
3
|
+
|
|
4
|
+
type Props = {
|
|
5
|
+
handleAction: () => void
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export function Notifications({ handleAction }: Props): React.ReactElement {
|
|
9
|
+
return <NotifiSubscriptionModal handleSuccess={handleAction} />
|
|
10
|
+
}
|