@huma-finance/widgets 0.0.59-beta.484 → 0.0.59-beta.486

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.484+cd874d1",
3
+ "version": "0.0.59-beta.486+2521877",
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.484+cd874d1",
34
- "@huma-finance/shared": "^0.0.59-beta.484+cd874d1",
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",
@@ -195,5 +195,5 @@
195
195
  "optionalDependencies": {
196
196
  "encoding": "^0.1.13"
197
197
  },
198
- "gitHead": "cd874d11bcdeb78aacd815589f76c482e8bfdf78"
198
+ "gitHead": "2521877d3ec21dd5c552804a945184da05dab0e0"
199
199
  }
@@ -1,4 +1,9 @@
1
- import { CampaignService, formatNumber } from '@huma-finance/shared'
1
+ import {
2
+ CampaignService,
3
+ checkIsDev,
4
+ formatNumber,
5
+ useAuthErrorHandling,
6
+ } from '@huma-finance/shared'
2
7
  import { Box, css, useTheme } from '@mui/material'
3
8
  import { useWeb3React } from '@web3-react/core'
4
9
  import React, { useEffect, useState } from 'react'
@@ -8,6 +13,16 @@ import { setError } from '../../../store/widgets.reducers'
8
13
  import { BottomButton } from '../../BottomButton'
9
14
  import { CongratulationsIcon, HumaPointsIcon, RibbonIcon } from '../../icons'
10
15
  import { LoadingModal } from '../../LoadingModal'
16
+ import { SignIn } from '../../SignIn'
17
+
18
+ enum STATE {
19
+ Loading = 'Loading',
20
+ SignIn = 'SignIn',
21
+ Congrats = 'Congrats',
22
+ }
23
+
24
+ const ERROR_MESSAGE =
25
+ 'Failed to update wallet points. Be assured that your points will be added later.'
11
26
 
12
27
  type Props = {
13
28
  transactionHash: string
@@ -26,41 +41,89 @@ export function PointsEarned({
26
41
  const [pointsAccumulated, setPointsAccumulated] = useState<
27
42
  number | undefined
28
43
  >()
29
- const lockupMonths = lpConfig.withdrawalLockoutPeriodInDays / 30
44
+ const lockupMonths = Math.round(lpConfig.withdrawalLockoutPeriodInDays / 30)
30
45
  const monthText =
31
46
  lockupMonths > 1 ? `${lockupMonths} months` : `${lockupMonths} month`
32
- const [loading, setLoading] = useState(false)
47
+
48
+ const {
49
+ errorType,
50
+ setError: setAuthError,
51
+ isWalletOwnershipVerified,
52
+ isWalletOwnershipVerificationRequired,
53
+ } = useAuthErrorHandling(checkIsDev())
54
+ const [walletOwnership, setWalletOwnership] = useState<boolean | undefined>()
55
+ const [state, setState] = useState<STATE>(STATE.Loading)
33
56
 
34
57
  useEffect(() => {
35
- const updateWalletPoints = async () => {
36
- const setErrorMessage = () => {
37
- dispatch(
38
- setError({
39
- errorMessage:
40
- 'Failed to update wallet points. Be assured that your points will be added later.',
41
- }),
42
- )
58
+ if (isWalletOwnershipVerificationRequired) {
59
+ setState(STATE.Loading)
60
+ }
61
+ }, [isWalletOwnershipVerificationRequired])
62
+
63
+ useEffect(() => {
64
+ if (isWalletOwnershipVerified) {
65
+ setWalletOwnership(true)
66
+ }
67
+ }, [isWalletOwnershipVerified])
68
+
69
+ useEffect(() => {
70
+ const checkWalletOwnership = async () => {
71
+ const ownership = await CampaignService.checkWalletOwnership(account!)
72
+ setWalletOwnership(ownership)
73
+ if (!ownership) {
74
+ setAuthError('WalletNotSignInException')
43
75
  }
76
+ }
77
+ checkWalletOwnership()
78
+ }, [account, setAuthError])
44
79
 
45
- try {
46
- setLoading(true)
47
- const result = await CampaignService.updateWalletPoints(
48
- chainId!,
49
- account!,
50
- transactionHash,
51
- )
52
- if (!result.pointsAccumulated) {
53
- setErrorMessage()
80
+ useEffect(() => {
81
+ if (errorType === 'NotSignedIn') {
82
+ setState(STATE.SignIn)
83
+ } else if (errorType === 'UserRejected') {
84
+ dispatch(
85
+ setError({
86
+ errorMessage: 'User has rejected the transaction.',
87
+ }),
88
+ )
89
+ } else if (errorType === 'Other') {
90
+ dispatch(
91
+ setError({
92
+ errorMessage: ERROR_MESSAGE,
93
+ }),
94
+ )
95
+ }
96
+ }, [dispatch, errorType])
97
+
98
+ useEffect(() => {
99
+ const updateWalletPoints = async () => {
100
+ if (walletOwnership) {
101
+ try {
102
+ const result = await CampaignService.updateWalletPoints(
103
+ chainId!,
104
+ account!,
105
+ transactionHash,
106
+ )
107
+ if (!result.pointsAccumulated) {
108
+ dispatch(
109
+ setError({
110
+ errorMessage: ERROR_MESSAGE,
111
+ }),
112
+ )
113
+ }
114
+ setPointsAccumulated(result.pointsAccumulated)
115
+ setState(STATE.Congrats)
116
+ } catch (error) {
117
+ dispatch(
118
+ setError({
119
+ errorMessage: ERROR_MESSAGE,
120
+ }),
121
+ )
54
122
  }
55
- setPointsAccumulated(result.pointsAccumulated)
56
- } catch (error) {
57
- setErrorMessage()
58
- } finally {
59
- setLoading(false)
60
123
  }
61
124
  }
62
125
  updateWalletPoints()
63
- }, [account, chainId, dispatch, transactionHash])
126
+ }, [account, chainId, dispatch, transactionHash, walletOwnership])
64
127
 
65
128
  const styles = {
66
129
  wrapper: css`
@@ -112,34 +175,40 @@ export function PointsEarned({
112
175
  `,
113
176
  }
114
177
 
115
- if (loading) {
116
- return <LoadingModal title='SUPPLY' />
178
+ if (state === STATE.SignIn) {
179
+ return (
180
+ <SignIn description='Please sign in to check the points that you earned.' />
181
+ )
117
182
  }
118
183
 
119
- return (
120
- <Box css={styles.wrapper}>
121
- <Box css={styles.congrats}>
122
- <CongratulationsIcon />
123
- </Box>
124
- <Box css={styles.ribbon}>
125
- <RibbonIcon />
126
- <Box css={styles.ribbonContent}>
127
- <HumaPointsIcon />
128
- <Box>{formatNumber(pointsAccumulated)} Points</Box>
184
+ if (state === STATE.Congrats) {
185
+ return (
186
+ <Box css={styles.wrapper}>
187
+ <Box css={styles.congrats}>
188
+ <CongratulationsIcon />
129
189
  </Box>
190
+ <Box css={styles.ribbon}>
191
+ <RibbonIcon />
192
+ <Box css={styles.ribbonContent}>
193
+ <HumaPointsIcon />
194
+ <Box>{formatNumber(pointsAccumulated)} Points</Box>
195
+ </Box>
196
+ </Box>
197
+ <Box css={styles.entirePoints}>
198
+ <Box>Congratulations,</Box>
199
+ <Box>you've earned {pointsAccumulated} points</Box>
200
+ </Box>
201
+ <Box css={styles.entirePointsDetails}>
202
+ You'll earn points <span css={styles.everyday}>everyday</span> for{' '}
203
+ {monthText} straight. Plus, If you keep your investment till after{' '}
204
+ {monthText}, you’ll gain extra points daily.
205
+ </Box>
206
+ <BottomButton variant='contained' onClick={handleAction}>
207
+ GREAT
208
+ </BottomButton>
130
209
  </Box>
131
- <Box css={styles.entirePoints}>
132
- <Box>Congratulations,</Box>
133
- <Box>you've earned {pointsAccumulated} points</Box>
134
- </Box>
135
- <Box css={styles.entirePointsDetails}>
136
- You'll earn points <span css={styles.everyday}>everyday</span> for{' '}
137
- {monthText} straight. Plus, If you keep your investment till after{' '}
138
- {monthText}, you’ll gain extra points daily.
139
- </Box>
140
- <BottomButton variant='contained' onClick={handleAction}>
141
- GREAT
142
- </BottomButton>
143
- </Box>
144
- )
210
+ )
211
+ }
212
+
213
+ return <LoadingModal title='SUPPLY' />
145
214
  }
@@ -74,7 +74,6 @@ export function PersonaEvaluation({
74
74
  const KYCCopies = poolInfo.KYC!.Persona!
75
75
  const [loadingType, setLoadingType] = useState<LoadingType>()
76
76
  const [kycCopy, setKYCCopy] = useState<KYCCopy>(KYCCopies.verifyIdentity)
77
- const isVerifyIdentity = kycCopy === KYCCopies.verifyIdentity
78
77
  const [inquiryId, setInquiryId] = useState<string>()
79
78
  const [sessionToken, setSessionToken] = useState<string>()
80
79
  const [verificationStatus, setVerificationStatus] =
@@ -395,7 +394,7 @@ export function PersonaEvaluation({
395
394
  <Box css={styles.iconWrapper}>
396
395
  <img src={ApproveLenderImg} alt='approve-lender' />
397
396
  </Box>
398
- {campaign && isVerifyIdentity ? (
397
+ {campaign && kycCopy === KYCCopies.verifyIdentity ? (
399
398
  <Box css={styles.description}>
400
399
  <span>You’ll be rewarded with a minimum of</span>
401
400
  <span css={styles.points}>
@@ -53,7 +53,6 @@ export function LendSupplyV2({
53
53
  handleClose,
54
54
  handleSuccess,
55
55
  }: LendSupplyPropsV2): React.ReactElement | null {
56
- console.log('campaign', campaign)
57
56
  const dispatch = useDispatch()
58
57
  const poolName = POOL_NAME[poolNameStr]
59
58
  const { chainId, provider, account } = useWeb3React()
@@ -2,7 +2,11 @@ import { Box, css, Typography, useTheme } from '@mui/material'
2
2
  import React from 'react'
3
3
  import { ApproveLenderImg } from './images'
4
4
 
5
- export function SignIn(): React.ReactElement {
5
+ type Props = {
6
+ description?: string
7
+ }
8
+
9
+ export function SignIn({ description }: Props): React.ReactElement {
6
10
  const theme = useTheme()
7
11
  const styles = {
8
12
  wrapper: css`
@@ -41,7 +45,8 @@ export function SignIn(): React.ReactElement {
41
45
  <img src={ApproveLenderImg} alt='approve-lender' />
42
46
  </Box>
43
47
  <Box css={styles.content}>
44
- Please sign in to verify your ownership of the wallet.
48
+ {description ??
49
+ 'Please sign in to verify your ownership of the wallet.'}
45
50
  </Box>
46
51
  </Box>
47
52
  )