@huma-finance/widgets 0.0.26 → 0.0.27

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.26",
3
+ "version": "0.0.27",
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.26",
34
- "@huma-finance/shared": "^0.0.26",
33
+ "@huma-finance/sdk": "^0.0.27",
34
+ "@huma-finance/shared": "^0.0.27",
35
35
  "@mui/icons-material": "^5.3.0",
36
36
  "@mui/material": "^5.0.6",
37
37
  "@mui/styles": "^5.0.2",
@@ -191,5 +191,5 @@
191
191
  "optionalDependencies": {
192
192
  "encoding": "^0.1.13"
193
193
  },
194
- "gitHead": "56be2f72a82a3bb86d04115a909ad1507ff5b2e2"
194
+ "gitHead": "6b5806b0d29519bd5c10724b207f5c50c88085f9"
195
195
  }
@@ -5,11 +5,13 @@ import { WCProps } from '../utilTypes'
5
5
 
6
6
  type Props = {
7
7
  variant: 'contained' | 'outlined'
8
+ disabled?: boolean
8
9
  onClick?: () => void
9
10
  }
10
11
 
11
12
  export function BottomButton({
12
13
  variant,
14
+ disabled = false,
13
15
  onClick,
14
16
  children,
15
17
  }: WCProps<Props>): React.ReactElement {
@@ -23,7 +25,7 @@ export function BottomButton({
23
25
 
24
26
  return (
25
27
  <Box css={styles}>
26
- <Button variant={variant} onClick={onClick}>
28
+ <Button variant={variant} onClick={onClick} disabled={disabled}>
27
29
  {children}
28
30
  </Button>
29
31
  </Box>
@@ -1,7 +1,12 @@
1
+ import {
2
+ EAService,
3
+ IdentityService,
4
+ PoolInfoType,
5
+ VerificationStatusResult,
6
+ } from '@huma-finance/shared'
1
7
  import { Box, css, useTheme } from '@mui/material'
2
8
  import { useWeb3React } from '@web3-react/core'
3
- import { EAService, PoolInfoType } from '@huma-finance/shared'
4
- import React, { useState } from 'react'
9
+ import React, { useEffect, useState } from 'react'
5
10
 
6
11
  import { useAppDispatch } from '../../../hooks/useRedux'
7
12
  import { setError, setStep } from '../../../store/widgets.reducers'
@@ -11,6 +16,7 @@ import { BottomButton } from '../../BottomButton'
11
16
  import { ApproveLenderIcon } from '../../icons'
12
17
  import { LoadingModal } from '../../LoadingModal'
13
18
  import { WrapperModal } from '../../WrapperModal'
19
+ import { envUtil } from '../../../utils/env'
14
20
 
15
21
  type Props = {
16
22
  poolInfo: PoolInfoType
@@ -23,8 +29,18 @@ export function Evaluation({
23
29
  }: Props): React.ReactElement | null {
24
30
  const theme = useTheme()
25
31
  const dispatch = useAppDispatch()
32
+ const isDev = envUtil.checkIsDev()
26
33
  const { account, chainId } = useWeb3React()
27
34
  const [loading, setLoading] = useState(false)
35
+ const [description, setDescription] = useState<string>()
36
+ const [KYCVerifyStatus, setKYCVerifyStatus] =
37
+ useState<VerificationStatusResult>()
38
+ const lenderApprovalProvider = poolInfo.extra?.lenderApprovalProvider
39
+ const isKYC = lenderApprovalProvider?.type === 'KYC'
40
+ const [subTitle, setSubTitle] = useState<string>(
41
+ 'This pool requires lender approval',
42
+ )
43
+ const [buttonText, setButtonText] = useState<string>('GET APPROVED')
28
44
 
29
45
  const styles = {
30
46
  iconWrapper: css`
@@ -40,39 +56,108 @@ export function Evaluation({
40
56
  `,
41
57
  }
42
58
 
43
- const approveLender = async () => {
44
- if (account) {
45
- try {
46
- setLoading(true)
47
- const payload = {
48
- poolAddress: poolInfo.pool,
49
- lenderWalletAddress: account,
59
+ useEffect(() => {
60
+ if (isKYC) {
61
+ setDescription(
62
+ `Approval process is run by ${lenderApprovalProvider.provider}`,
63
+ )
64
+ }
65
+ }, [lenderApprovalProvider?.provider, isKYC])
66
+
67
+ useEffect(() => {
68
+ const fetchData = async () => {
69
+ if (account && chainId && isKYC) {
70
+ try {
71
+ setLoading(true)
72
+ const verificationStatus =
73
+ await IdentityService.getVerificationStatus(
74
+ account,
75
+ poolInfo.pool,
76
+ chainId,
77
+ isDev,
78
+ )
79
+ setKYCVerifyStatus(verificationStatus)
80
+ if (verificationStatus.isVerified) {
81
+ setSubTitle(
82
+ 'Approval process in progress. Please contact Pool Owner.',
83
+ )
84
+ setButtonText('CONTACT POOL OWNER')
85
+ }
86
+ } finally {
87
+ setLoading(false)
50
88
  }
51
- await EAService.approveLender(payload, chainId!)
52
- handleApproveSuccess()
53
- setLoading(false)
54
- dispatch(setStep(WIDGET_STEP.ChooseAmount))
55
- } catch (e: unknown) {
56
- const error = e as CustomError
57
- setLoading(false)
58
- dispatch(setError({ errorMessage: error.message }))
59
89
  }
60
90
  }
91
+ fetchData()
92
+ }, [account, chainId, isDev, isKYC, poolInfo.pool])
93
+
94
+ const approveLenderByEA = async () => {
95
+ try {
96
+ setLoading(true)
97
+ const payload = {
98
+ poolAddress: poolInfo.pool,
99
+ lenderWalletAddress: account!,
100
+ }
101
+ await EAService.approveLender(payload, chainId!)
102
+ handleApproveSuccess()
103
+ setLoading(false)
104
+ dispatch(setStep(WIDGET_STEP.ChooseAmount))
105
+ } catch (e: unknown) {
106
+ const error = e as CustomError
107
+ setLoading(false)
108
+ dispatch(setError({ errorMessage: error.message }))
109
+ }
110
+ }
111
+
112
+ const approveLenderByKYC = () => {
113
+ switch (lenderApprovalProvider?.provider) {
114
+ case 'Securitize':
115
+ {
116
+ const issuerId = '53a66b32-583e-40e7-ba90-baf516d2cadd'
117
+ const baseUrl = `https://id${isDev ? '.sandbox' : ''}.securitize.io`
118
+ const originUrl = window.location.href.split('?')[0]
119
+ const redirectUrl = `${originUrl}?type=KYC&pool=${poolInfo.pool}`
120
+ const providerAuthorizeUrl = `${baseUrl}/#/authorize?issuerId=${issuerId}&scope=details&details=verification&redirectUrl=${redirectUrl}`
121
+ const { isNotOnboarded } = KYCVerifyStatus || {}
122
+ const providerUrl = isNotOnboarded ? providerAuthorizeUrl : baseUrl
123
+ window.location.href = providerUrl
124
+ }
125
+ break
126
+ default:
127
+ break
128
+ }
129
+ }
130
+
131
+ const approveLender = () => {
132
+ switch (lenderApprovalProvider?.type) {
133
+ case 'EA':
134
+ approveLenderByEA()
135
+ break
136
+ case 'KYC':
137
+ approveLenderByKYC()
138
+ break
139
+ default:
140
+ approveLenderByEA()
141
+ break
142
+ }
61
143
  }
62
144
 
63
145
  if (!loading) {
64
146
  return (
65
- <WrapperModal
66
- title='Lender Approval'
67
- subTitle='This pool requires lender approval'
68
- >
147
+ <WrapperModal title='Lender Approval' subTitle={subTitle}>
69
148
  <Box css={styles.iconWrapper}>
70
149
  <ApproveLenderIcon />
71
150
  </Box>
72
- <Box css={styles.description} />
73
- <BottomButton variant='contained' onClick={approveLender}>
74
- GET APPROVED
75
- </BottomButton>
151
+ <Box css={styles.description}>{description}</Box>
152
+ {true && (
153
+ <BottomButton
154
+ variant='contained'
155
+ onClick={approveLender}
156
+ disabled={KYCVerifyStatus?.isVerified}
157
+ >
158
+ {buttonText}
159
+ </BottomButton>
160
+ )}
76
161
  </WrapperModal>
77
162
  )
78
163
  }
package/src/index.tsx CHANGED
@@ -61,8 +61,9 @@ type WidgetProps = {
61
61
 
62
62
  function Widget(props: WCProps<WidgetProps>) {
63
63
  const { children, desiredChainId } = props
64
+ const { ethereum } = window
64
65
  // @ts-ignore
65
- const netWorkVersion = window.ethereum?.networkVersion
66
+ const netWorkVersion = ethereum?.networkVersion || ethereum?.chainId
66
67
  const [currentChainId, setCurrentChainId] = useState<number | undefined>(
67
68
  netWorkVersion ? Number(netWorkVersion) : undefined,
68
69
  )
package/src/utils/env.ts CHANGED
@@ -1,7 +1,8 @@
1
1
  const checkIsDev = () =>
2
2
  !!(
3
- window.REACT_APP_FORCE_DEV_PREFIX_FOR_URLS ||
4
- window.location.hostname.startsWith('dev')
3
+ window.location.hostname.startsWith('dev') ||
4
+ window.location.hostname.startsWith('deploy-preview') ||
5
+ process.env.NODE_ENV === 'development'
5
6
  )
6
7
 
7
8
  export const envUtil = {