@huma-finance/widgets 0.0.59-beta.480 → 0.0.59-beta.482

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@huma-finance/widgets",
3
- "version": "0.0.59-beta.480+639dcae",
3
+ "version": "0.0.59-beta.482+ea53a78",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -30,8 +30,8 @@
30
30
  "@ethersproject/experimental": "^5.7.0",
31
31
  "@ethersproject/providers": "^5.6.0",
32
32
  "@ethersproject/units": "^5.6.0",
33
- "@huma-finance/sdk": "^0.0.59-beta.480+639dcae",
34
- "@huma-finance/shared": "^0.0.59-beta.480+639dcae",
33
+ "@huma-finance/sdk": "^0.0.58",
34
+ "@huma-finance/shared": "^0.0.58",
35
35
  "@mui/icons-material": "^5.3.0",
36
36
  "@mui/material": "^5.0.6",
37
37
  "@mui/styles": "^5.0.2",
@@ -63,6 +63,7 @@
63
63
  "history": "^5.3.0",
64
64
  "jotai": "^1.13.1",
65
65
  "moment": "^2.29.4",
66
+ "persona": "^5.1.0",
66
67
  "qrcode": "^1.5.1",
67
68
  "query-string": "^7.1.1",
68
69
  "react": "^18.2.0",
@@ -137,6 +138,7 @@
137
138
  "@typechain/ethers-v5": "^10.1.0",
138
139
  "@types/jest": "^27.5.2",
139
140
  "@types/node": "^17.0.45",
141
+ "@types/persona": "^0.0.32",
140
142
  "@types/qrcode": "^1.5.0",
141
143
  "@types/react": "^18.0.21",
142
144
  "@types/react-dom": "^18.0.6",
@@ -193,5 +195,5 @@
193
195
  "optionalDependencies": {
194
196
  "encoding": "^0.1.13"
195
197
  },
196
- "gitHead": "639dcae1caea45b3fe1b3ed1ff522c3c7715f450"
198
+ "gitHead": "ea53a78ba1ad057a3ec46b7c49a27f368842e8b5"
197
199
  }
@@ -1,346 +1,37 @@
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'
1
+ import { PoolInfoV2, TrancheType } from '@huma-finance/shared'
2
+ import React from 'react'
17
3
 
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
- }
4
+ import { PersonaEvaluation } from './components/PersonaEvaluation'
5
+ import { SecuritizeEvaluation } from './components/SecuritizeEvaluation'
38
6
 
39
7
  type Props = {
40
8
  poolInfo: PoolInfoV2
9
+ isUniTranche: boolean
10
+ changeTranche: (tranche: TrancheType) => void
41
11
  handleClose: () => void
42
12
  }
43
13
 
44
14
  export function Evaluation({
45
15
  poolInfo,
16
+ isUniTranche,
17
+ changeTranche,
46
18
  handleClose,
47
19
  }: 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
- setKYCCopy(KYCCopies.verifyIdentity)
116
- const docuSignStatus = localStorage.getItem(envelopeDocuSignStatusKey)
117
- setDocSignatureStatus(docuSignStatus as DocSignatureStatus['status'])
118
- if (docuSignStatus === 'completed') {
119
- setKYCCopy(KYCCopies.docUnderReview)
120
- return
121
- }
122
-
123
- const fetchData = async () => {
124
- try {
125
- if (kycProvider && kycPool && account && chainId) {
126
- setLoadingType('verificationStatus')
127
- await IdentityService.onboard(
128
- account,
129
- code as string,
130
- kycPool as string,
131
- chainId,
132
- isDev,
133
- )
134
- }
135
- } catch (e) {
136
- try {
137
- setAuthError(e)
138
- setKYCCopy(KYCCopies.signInRequired)
139
- } catch (e) {
140
- // The repeated call will throw an error of 401, so we can ignore it.
141
- console.log(e)
142
- }
143
- }
144
-
145
- try {
146
- if (account && chainId) {
147
- setLoadingType('verificationStatus')
148
- const verificationStatus =
149
- await IdentityService.getVerificationStatus(
150
- account,
151
- poolInfo.pool,
152
- chainId,
153
- isDev,
154
- )
155
- setKYCVerifyStatus(verificationStatus)
156
- if (verificationStatus.isVerified) {
157
- const envelopeId = localStorage.getItem(envelopeKey)
158
- if (!envelopeId) {
159
- setKYCCopy(KYCCopies.emailSignatureLink)
160
- } else if (!checkGetDocSignatureStatusIsAvailable()) {
161
- setKYCCopy(KYCCopies.resendSignatureLink)
162
- } else {
163
- const { status } = await IdentityService.getDocSignatureStatus(
164
- envelopeId,
165
- chainId,
166
- isDev,
167
- )
168
- localStorage.setItem(
169
- envelopeLastQueryTimeKey,
170
- String(timeUtil.getUnixTimestamp()),
171
- )
172
- localStorage.setItem(envelopeDocuSignStatusKey, status)
173
- setDocSignatureStatus(status)
174
- if (status === 'completed') {
175
- setKYCCopy(KYCCopies.docUnderReview)
176
- // For voided and declined status, we need to send a new link
177
- } else if (['voided', 'declined'].includes(status)) {
178
- localStorage.removeItem(envelopeKey)
179
- localStorage.removeItem(envelopeLastQueryTimeKey)
180
- setKYCCopy(KYCCopies.emailSignatureLink)
181
- } else {
182
- setKYCCopy(KYCCopies.resendSignatureLink)
183
- }
184
- }
185
- } else {
186
- setKYCCopy(KYCCopies.verifyIdentity)
187
- }
188
- }
189
- } catch (e: unknown) {
190
- try {
191
- setAuthError(e)
192
- setKYCCopy(KYCCopies.signInRequired)
193
- } catch (e) {
194
- console.error(e)
195
- dispatch(
196
- setError({
197
- errorMessage: 'Something went wrong, please try again later.',
198
- }),
199
- )
200
- }
201
- } finally {
202
- setLoadingType(undefined)
203
- }
204
- }
205
- fetchData()
206
- }, [
207
- KYCCopies.docUnderReview,
208
- KYCCopies.emailSignatureLink,
209
- KYCCopies.resendSignatureLink,
210
- KYCCopies.signInRequired,
211
- KYCCopies.verifyIdentity,
212
- account,
213
- chainId,
214
- checkGetDocSignatureStatusIsAvailable,
215
- code,
216
- dispatch,
217
- envelopeDocuSignStatusKey,
218
- envelopeKey,
219
- envelopeLastQueryTimeKey,
220
- isDev,
221
- kycPool,
222
- kycProvider,
223
- poolInfo.pool,
224
- setAuthError,
225
- isWalletOwnershipVerified,
226
- ])
227
-
228
- useEffect(() => {
229
- if (
230
- authError &&
231
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
232
- [4001, 'ACTION_REJECTED'].includes((authError as any).code)
233
- ) {
234
- dispatch(
235
- setError({
236
- errorMessage: 'User has rejected the transaction.',
237
- }),
238
- )
239
- }
240
- }, [authError, dispatch])
241
-
242
- const approveLender = async () => {
243
- if (docSignatureCompleted) {
244
- handleClose()
245
- return
246
- }
247
-
248
- const { isNotOnboarded, isVerified } = KYCVerifyStatus || {}
249
-
250
- if (!isVerified) {
251
- const issuerId = CHAINS[chainId!].isTestnet
252
- ? '53a66b32-583e-40e7-ba90-baf516d2cadd'
253
- : '5557baf5-d3c2-4c80-b522-c05a11c6e586'
254
- const baseUrl = configUtil.getKYCProviderBaseUrl(
255
- poolInfo.KYC!.provider,
256
- chainId!,
257
- )
258
- const originUrl = window.location.href.split('?')[0]
259
- const redirectUrl = `${originUrl}?poolName=${
260
- poolInfo.poolName
261
- }&kycProvider=${poolInfo.KYC!.provider}&kycPool=${poolInfo.pool}`
262
- const providerAuthorizeUrl = `${baseUrl}/#/authorize?issuerId=${issuerId}&scope=details&details=verification&redirectUrl=${redirectUrl}`
263
- window.location.href = isNotOnboarded ? providerAuthorizeUrl : baseUrl
264
- } else {
265
- const envelopeId = localStorage.getItem(envelopeKey)
266
- try {
267
- setLoadingType('sendDocSignatureLink')
268
- if (!envelopeId) {
269
- const { envelopeId } = await IdentityService.requestDocSignature(
270
- account!,
271
- chainId!,
272
- isDev,
273
- )
274
- localStorage.setItem(envelopeKey, envelopeId)
275
- localStorage.setItem(
276
- envelopeLastQueryTimeKey,
277
- String(timeUtil.getUnixTimestamp()),
278
- )
279
- setOpenSnackBar(true)
280
- setKYCCopy(KYCCopies.resendSignatureLink)
281
- } else {
282
- await IdentityService.resendDocSignatureLink(
283
- envelopeId,
284
- chainId!,
285
- isDev,
286
- )
287
- setOpenSnackBar(true)
288
- }
289
- } catch (e: unknown) {
290
- try {
291
- const { envelopeId } = await IdentityService.requestDocSignature(
292
- account!,
293
- chainId!,
294
- isDev,
295
- )
296
- localStorage.setItem(envelopeKey, envelopeId)
297
- localStorage.setItem(
298
- envelopeLastQueryTimeKey,
299
- String(timeUtil.getUnixTimestamp()),
300
- )
301
- setOpenSnackBar(true)
302
- setKYCCopy(KYCCopies.resendSignatureLink)
303
- } catch (e) {
304
- setAuthError(e)
305
- setKYCCopy(KYCCopies.signInRequired)
306
- }
307
- } finally {
308
- setLoadingType(undefined)
309
- }
310
- }
20
+ if (poolInfo.KYC?.Securitize) {
21
+ return (
22
+ <SecuritizeEvaluation poolInfo={poolInfo} handleClose={handleClose} />
23
+ )
311
24
  }
312
-
313
- const getEmailLinkSentSnackbar = () => (
314
- <HumaSnackBar
315
- open={openSnackBar}
316
- title='Signature Link Sent'
317
- message='The secure signature session link has been sent to you via email.'
318
- severity='success'
319
- onClose={() => setOpenSnackBar(false)}
320
- />
321
- )
322
-
323
- if (!loadingType) {
25
+ if (poolInfo.KYC?.Persona) {
324
26
  return (
325
- <WrapperModal title={kycCopy.title}>
326
- <Box css={styles.iconWrapper}>
327
- <img src={ApproveLenderImg} alt='approve-lender' />
328
- </Box>
329
- <Box css={styles.description}>{kycCopy.description}</Box>
330
- {Boolean(kycCopy.buttonText) && (
331
- <BottomButton variant='contained' onClick={approveLender}>
332
- {kycCopy.buttonText}
333
- </BottomButton>
334
- )}
335
- {getEmailLinkSentSnackbar()}
336
- </WrapperModal>
27
+ <PersonaEvaluation
28
+ poolInfo={poolInfo}
29
+ handleClose={handleClose}
30
+ isUniTranche={isUniTranche}
31
+ changeTranche={changeTranche}
32
+ />
337
33
  )
338
34
  }
339
35
 
340
- return (
341
- <LoadingModal
342
- title='Lender Approval'
343
- description={LoadingCopiesByType[loadingType].description}
344
- />
345
- )
36
+ return null
346
37
  }
@@ -1,9 +1,8 @@
1
1
  import {
2
+ formatNumber,
2
3
  PoolInfoV2,
3
4
  TrancheType,
4
5
  UnderlyingTokenInfo,
5
- formatNumber,
6
- useLPConfigV2,
7
6
  usePoolSafeAllowanceV2,
8
7
  usePoolUnderlyingTokenBalanceV2,
9
8
  } from '@huma-finance/shared'
@@ -15,18 +14,19 @@ import { useAppDispatch } from '../../../hooks/useRedux'
15
14
  import { setStep, setSupplyAmount } from '../../../store/widgets.reducers'
16
15
  import { WIDGET_STEP } from '../../../store/widgets.store'
17
16
  import { InputAmountModal } from '../../InputAmountModal'
18
- import { LoadingModal } from '../../LoadingModal'
19
17
 
20
18
  type Props = {
21
19
  poolInfo: PoolInfoV2
22
20
  poolUnderlyingToken: UnderlyingTokenInfo
23
21
  selectedTranche: TrancheType | undefined
22
+ isUniTranche: boolean
24
23
  }
25
24
 
26
25
  export function ChooseAmount({
27
26
  poolInfo,
28
27
  poolUnderlyingToken,
29
28
  selectedTranche,
29
+ isUniTranche,
30
30
  }: Props): React.ReactElement | null {
31
31
  const dispatch = useAppDispatch()
32
32
  const { account, provider } = useWeb3React()
@@ -46,8 +46,6 @@ export function ChooseAmount({
46
46
  balance,
47
47
  poolUnderlyingToken.decimals,
48
48
  )
49
- const lpConfig = useLPConfigV2(poolInfo.poolName, provider)
50
- const isUniTranche = lpConfig?.maxSeniorJuniorRatio === 0
51
49
 
52
50
  const handleChangeAmount = (newAmount: number) => {
53
51
  setCurrentAmount(newAmount)
@@ -65,10 +63,6 @@ export function ChooseAmount({
65
63
  dispatch(setStep(step))
66
64
  }
67
65
 
68
- if (!lpConfig) {
69
- return <LoadingModal title='Supply' />
70
- }
71
-
72
66
  return (
73
67
  <InputAmountModal
74
68
  title='Enter Amount'