@huma-finance/widgets 0.0.41 → 0.0.42-beta.91

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.41",
3
+ "version": "0.0.42-beta.91+a796d63",
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.41",
34
- "@huma-finance/shared": "^0.0.41",
33
+ "@huma-finance/sdk": "^0.0.42-beta.91+a796d63",
34
+ "@huma-finance/shared": "^0.0.42-beta.91+a796d63",
35
35
  "@mui/icons-material": "^5.3.0",
36
36
  "@mui/material": "^5.0.6",
37
37
  "@mui/styles": "^5.0.2",
@@ -194,5 +194,5 @@
194
194
  "optionalDependencies": {
195
195
  "encoding": "^0.1.13"
196
196
  },
197
- "gitHead": "2e59758ee0f4bf6cc9dd6c031f2a61a066d2fdfe"
197
+ "gitHead": "a796d634e328eddb1bb0939c9f20bf4d4d125d0d"
198
198
  }
@@ -9,6 +9,7 @@ import { setStep } from '../../../store/widgets.reducers'
9
9
  import { WIDGET_STEP } from '../../../store/widgets.store'
10
10
  import { CheckCircleIcon, CheckGreenIcon } from '../../icons'
11
11
  import spinner from '../../icons/spinner.gif'
12
+ import { SignIn } from '../../SignIn'
12
13
 
13
14
  type Props = {
14
15
  poolInfo: PoolInfoType
@@ -20,7 +21,11 @@ export function Evaluation({
20
21
  handleApprove,
21
22
  }: Props): React.ReactElement {
22
23
  const theme = useTheme()
23
- const { checkingEA } = useEA()
24
+ const {
25
+ checkingEA,
26
+ isWalletOwnershipVerificationRequired,
27
+ isWalletOwnershipVerified,
28
+ } = useEA()
24
29
  const dispatch = useAppDispatch()
25
30
  const { account, chainId } = useWeb3React()
26
31
  const [status, setStatus] = useState<'checking' | 'success'>('checking')
@@ -47,6 +52,7 @@ export function Evaluation({
47
52
  handleApprove,
48
53
  poolInfo.assetAddress,
49
54
  poolInfo.pool,
55
+ isWalletOwnershipVerified,
50
56
  ])
51
57
 
52
58
  const styles = {
@@ -115,6 +121,10 @@ export function Evaluation({
115
121
  dispatch(setStep(WIDGET_STEP.ChooseAmount))
116
122
  }
117
123
 
124
+ if (isWalletOwnershipVerificationRequired) {
125
+ return <SignIn />
126
+ }
127
+
118
128
  return (
119
129
  <Box css={styles.wrapper}>
120
130
  <Typography variant='h6' css={styles.header}>
@@ -5,6 +5,7 @@ import React, { useEffect } from 'react'
5
5
  import useEA from '../../../hooks/useEA'
6
6
  import { LoadingModal } from '../../LoadingModal'
7
7
  import { WIDGET_STEP } from '../../../store/widgets.store'
8
+ import { SignIn } from '../../SignIn'
8
9
 
9
10
  type Props = {
10
11
  poolInfo: PoolInfoType
@@ -12,7 +13,11 @@ type Props = {
12
13
  }
13
14
 
14
15
  export function Evaluation({ poolInfo, tokenId }: Props): React.ReactElement {
15
- const { checkingEA } = useEA()
16
+ const {
17
+ checkingEA,
18
+ isWalletOwnershipVerificationRequired,
19
+ isWalletOwnershipVerified,
20
+ } = useEA()
16
21
  const { account, chainId } = useWeb3React()
17
22
 
18
23
  useEffect(() => {
@@ -38,8 +43,12 @@ export function Evaluation({ poolInfo, tokenId }: Props): React.ReactElement {
38
43
  poolInfo.assetAddress,
39
44
  poolInfo.pool,
40
45
  tokenId,
46
+ isWalletOwnershipVerified,
41
47
  ])
42
48
 
49
+ if (isWalletOwnershipVerificationRequired) {
50
+ return <SignIn />
51
+ }
43
52
  return (
44
53
  <LoadingModal
45
54
  title='Checking Invoice'
@@ -1,12 +1,13 @@
1
1
  import {
2
+ CHAINS,
2
3
  configUtil,
3
4
  DocSignatureStatus,
4
5
  IdentityService,
5
6
  PoolInfoType,
6
7
  timeUtil,
7
- VerificationStatusResult,
8
- CHAINS,
8
+ useAuthErrorHandling,
9
9
  useParamsSearch,
10
+ VerificationStatusResult,
10
11
  } from '@huma-finance/shared'
11
12
  import { Box, css, useTheme } from '@mui/material'
12
13
  import { useWeb3React } from '@web3-react/core'
@@ -26,11 +27,16 @@ const KYCProvider = 'Securitize'
26
27
  type KYCCopy = {
27
28
  title: string
28
29
  description: string
29
- buttonText: string
30
+ buttonText?: string
30
31
  }
31
32
 
32
33
  // TODO: Add copies for the other pools. Currently only the Jia pool is using the KYC process.
33
34
  const JiaPoolCopies = {
35
+ signInRequired: {
36
+ title: 'Sign In',
37
+ description:
38
+ 'Please sign in to verify that you are the owner of the wallet.',
39
+ },
34
40
  verifyIdentity: {
35
41
  title: 'Verify Identity',
36
42
  description: `This pool is only available to accredited investors at the moment, with minimum investments of $10,000. Please complete identity verification and investor accreditation via ${KYCProvider}.`,
@@ -81,6 +87,8 @@ export function EvaluationKYC({
81
87
  const isDev = envUtil.checkIsDev()
82
88
  const { account, chainId } = useWeb3React()
83
89
  const { kycProvider, code, kycPool } = useParamsSearch()
90
+ const { isWalletOwnershipVerified, setError: setAuthError } =
91
+ useAuthErrorHandling(isDev)
84
92
  const [loadingType, setLoadingType] = useState<
85
93
  'verificationStatus' | 'sendDocSignatureLink'
86
94
  >()
@@ -157,8 +165,13 @@ export function EvaluationKYC({
157
165
  )
158
166
  }
159
167
  } catch (e) {
160
- // The repeated call will throw an error of 401, so we can ignore it.
161
- console.error(e)
168
+ try {
169
+ setAuthError(e)
170
+ setKYCCopy(JiaPoolCopies.signInRequired)
171
+ } catch (e) {
172
+ // The repeated call will throw an error of 401, so we can ignore it.
173
+ console.log(e)
174
+ }
162
175
  }
163
176
 
164
177
  try {
@@ -204,12 +217,17 @@ export function EvaluationKYC({
204
217
  }
205
218
  }
206
219
  } catch (e: unknown) {
207
- console.error(e)
208
- dispatch(
209
- setError({
210
- errorMessage: 'Something went wrong, please try again later.',
211
- }),
212
- )
220
+ try {
221
+ setAuthError(e)
222
+ setKYCCopy(JiaPoolCopies.signInRequired)
223
+ } catch (e) {
224
+ console.error(e)
225
+ dispatch(
226
+ setError({
227
+ errorMessage: 'Something went wrong, please try again later.',
228
+ }),
229
+ )
230
+ }
213
231
  } finally {
214
232
  setLoadingType(undefined)
215
233
  }
@@ -228,6 +246,8 @@ export function EvaluationKYC({
228
246
  kycPool,
229
247
  kycProvider,
230
248
  poolInfo.pool,
249
+ setAuthError,
250
+ isWalletOwnershipVerified,
231
251
  ])
232
252
 
233
253
  const approveLender = async () => {
@@ -273,12 +293,23 @@ export function EvaluationKYC({
273
293
  setOpenSnackBar(true)
274
294
  }
275
295
  } catch (e: unknown) {
276
- console.error(e)
277
- dispatch(
278
- setError({
279
- errorMessage: 'Something went wrong, please try again later.',
280
- }),
281
- )
296
+ try {
297
+ const { envelopeId } = await IdentityService.requestDocSignature(
298
+ account!,
299
+ chainId!,
300
+ isDev,
301
+ )
302
+ localStorage.setItem(envelopeKey, envelopeId)
303
+ localStorage.setItem(
304
+ envelopeLastQueryTimeKey,
305
+ String(timeUtil.getUnixTimestamp()),
306
+ )
307
+ setOpenSnackBar(true)
308
+ setKYCCopy(JiaPoolCopies.resendSignatureLink)
309
+ } catch (e) {
310
+ setAuthError(e)
311
+ setKYCCopy(JiaPoolCopies.signInRequired)
312
+ }
282
313
  } finally {
283
314
  setLoadingType(undefined)
284
315
  }
@@ -302,9 +333,11 @@ export function EvaluationKYC({
302
333
  <img src={ApproveLenderImg} alt='approve-lender' />
303
334
  </Box>
304
335
  <Box css={styles.description}>{kycCopy.description}</Box>
305
- <BottomButton variant='contained' onClick={approveLender}>
306
- {kycCopy.buttonText}
307
- </BottomButton>
336
+ {Boolean(kycCopy.buttonText) && (
337
+ <BottomButton variant='contained' onClick={approveLender}>
338
+ {kycCopy.buttonText}
339
+ </BottomButton>
340
+ )}
308
341
  {getEmailLinkSentSnackbar()}
309
342
  </WrapperModal>
310
343
  )
@@ -0,0 +1,48 @@
1
+ import { Box, css, Typography, useTheme } from '@mui/material'
2
+ import React from 'react'
3
+ import { ApproveLenderImg } from './images'
4
+
5
+ export function SignIn(): React.ReactElement {
6
+ const theme = useTheme()
7
+ const styles = {
8
+ wrapper: css`
9
+ height: 518px;
10
+ position: relative;
11
+ `,
12
+ header: css`
13
+ ${theme.cssMixins.rowHCentered};
14
+ margin-top: -5px;
15
+ `,
16
+ icon: css`
17
+ ${theme.cssMixins.rowHCentered};
18
+ margin-top: 100px;
19
+ margin-right: 30px;
20
+ & > img {
21
+ width: 170px;
22
+ }
23
+ `,
24
+ content: css`
25
+ ${theme.cssMixins.rowHCentered};
26
+ margin-top: 30px;
27
+ font-family: 'Uni-Neue-Regular';
28
+ font-size: 16px;
29
+ line-height: 24px;
30
+ color: #49505b;
31
+ margin-bottom: 65px;
32
+ `,
33
+ }
34
+
35
+ return (
36
+ <Box css={styles.wrapper}>
37
+ <Typography variant='h6' css={styles.header}>
38
+ Sign In
39
+ </Typography>
40
+ <Box css={styles.icon}>
41
+ <img src={ApproveLenderImg} alt='approve-lender' />
42
+ </Box>
43
+ <Box css={styles.content}>
44
+ Please sign in to verify your ownership of the wallet.
45
+ </Box>
46
+ </Box>
47
+ )
48
+ }
@@ -5,6 +5,7 @@ import React, { useEffect } from 'react'
5
5
  import useEA from '../../../hooks/useEA'
6
6
  import { LoadingModal } from '../../LoadingModal'
7
7
  import { WIDGET_STEP } from '../../../store/widgets.store'
8
+ import { SignIn } from '../../SignIn'
8
9
 
9
10
  type Props = {
10
11
  poolInfo: PoolInfoType
@@ -17,8 +18,12 @@ export function Evaluation({
17
18
  payerAddress,
18
19
  superToken,
19
20
  }: Props): React.ReactElement {
21
+ const {
22
+ checkingEA,
23
+ isWalletOwnershipVerificationRequired,
24
+ isWalletOwnershipVerified,
25
+ } = useEA()
20
26
  const { account } = useWeb3React()
21
- const { checkingEA } = useEA()
22
27
 
23
28
  useEffect(() => {
24
29
  if (account) {
@@ -44,8 +49,12 @@ export function Evaluation({
44
49
  poolInfo.assetAddress,
45
50
  poolInfo.pool,
46
51
  superToken,
52
+ isWalletOwnershipVerified,
47
53
  ])
48
54
 
55
+ if (isWalletOwnershipVerificationRequired) {
56
+ return <SignIn />
57
+ }
49
58
  return (
50
59
  <LoadingModal
51
60
  title='Checking Stream'
@@ -4,6 +4,7 @@ import {
4
4
  EARejectMessage,
5
5
  EARejectReason,
6
6
  EAService,
7
+ useAuthErrorHandling,
7
8
  } from '@huma-finance/shared'
8
9
  import { useWeb3React } from '@web3-react/core'
9
10
  import { useCallback } from 'react'
@@ -16,6 +17,11 @@ import { useAppDispatch } from './useRedux'
16
17
  const useEA = () => {
17
18
  const dispatch = useAppDispatch()
18
19
  const { chainId } = useWeb3React()
20
+ const {
21
+ isWalletOwnershipVerificationRequired,
22
+ isWalletOwnershipVerified,
23
+ setError: setAuthError,
24
+ } = useAuthErrorHandling(envUtil.checkIsDev())
19
25
 
20
26
  const checkingEA = useCallback(
21
27
  async (payload: EAPayload, nextStep: WIDGET_STEP) => {
@@ -36,18 +42,27 @@ const useEA = () => {
36
42
  }),
37
43
  )
38
44
  } else {
39
- dispatch(
40
- setError({
41
- errorMessage: e.message,
42
- }),
43
- )
45
+ try {
46
+ setAuthError(e)
47
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
48
+ } catch (e: any) {
49
+ dispatch(
50
+ setError({
51
+ errorMessage: e.message,
52
+ }),
53
+ )
54
+ }
44
55
  }
45
56
  }
46
57
  },
47
- [chainId, dispatch],
58
+ [chainId, dispatch, setAuthError],
48
59
  )
49
60
 
50
- return { checkingEA }
61
+ return {
62
+ checkingEA,
63
+ isWalletOwnershipVerificationRequired,
64
+ isWalletOwnershipVerified,
65
+ }
51
66
  }
52
67
 
53
68
  export default useEA
@@ -6,6 +6,7 @@ export enum WIDGET_TYPE {
6
6
  }
7
7
 
8
8
  export enum WIDGET_STEP {
9
+ SignIn = 'SignIn',
9
10
  Evaluation = 'Evaluation',
10
11
  ChooseAmount = 'ChooseAmount',
11
12
  Permit = 'Permit',
package/src/utils/env.ts CHANGED
@@ -1,9 +1,7 @@
1
1
  const checkIsDev = () =>
2
- !!(
3
- window.location.hostname.startsWith('dev') ||
4
- window.location.hostname.startsWith('deploy-preview') ||
5
- process.env.NODE_ENV === 'development'
6
- )
2
+ window.location.hostname.startsWith('dev') ||
3
+ window.location.hostname.startsWith('deploy-preview') ||
4
+ process.env.NODE_ENV === 'development'
7
5
 
8
6
  export const envUtil = {
9
7
  checkIsDev,