@huma-finance/widgets 0.0.62-beta.693 → 0.0.62-beta.699

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.
@@ -1,250 +0,0 @@
1
- import {
2
- CampaignService,
3
- CHAIN_TYPE,
4
- checkIsDev,
5
- formatNumber,
6
- isEmpty,
7
- } from '@huma-finance/shared'
8
- import {
9
- SolanaPoolState,
10
- txAtom,
11
- useAuthErrorHandling,
12
- useChainInfo,
13
- } from '@huma-finance/web-shared'
14
- import { Box, css, useTheme } from '@mui/material'
15
- import { useResetAtom } from 'jotai/utils'
16
- import React, { useCallback, useEffect, useState } from 'react'
17
- import { useDispatch } from 'react-redux'
18
-
19
- import { resetState, setError } from '../../../store/widgets.reducers'
20
- import { BottomButton } from '../../BottomButton'
21
- import { CongratulationsIcon, HumaPointsIcon, RibbonIcon } from '../../icons'
22
- import { LoadingModal } from '../../LoadingModal'
23
- import { SignIn } from '../../SignIn'
24
-
25
- enum STATE {
26
- Loading = 'Loading',
27
- SignIn = 'SignIn',
28
- Congrats = 'Congrats',
29
- }
30
-
31
- const ERROR_MESSAGE =
32
- 'Failed to update wallet points. Be assured that your points will be added later.'
33
-
34
- type Props = {
35
- transactionHash: string
36
- poolState: SolanaPoolState
37
- pointsTestnetExperience: boolean
38
- handleAction: () => void
39
- }
40
-
41
- export function PointsEarned({
42
- transactionHash,
43
- poolState,
44
- pointsTestnetExperience,
45
- handleAction,
46
- }: Props): React.ReactElement {
47
- const theme = useTheme()
48
- const isDev = checkIsDev()
49
- const dispatch = useDispatch()
50
- const reset = useResetAtom(txAtom)
51
- const { account, chainId } = useChainInfo(isDev, CHAIN_TYPE.SOLANA)
52
- const [pointsAccumulated, setPointsAccumulated] = useState<
53
- number | undefined
54
- >()
55
- const hasPointsAccumulated =
56
- !isEmpty(pointsAccumulated) && pointsAccumulated! > 0
57
- const lockupMonths = Math.round(
58
- poolState.withdrawalLockupPeriodDays ?? 0 / 30,
59
- )
60
- const monthText =
61
- lockupMonths > 1 ? `${lockupMonths} months` : `${lockupMonths} month`
62
-
63
- const {
64
- errorType,
65
- setError: setAuthError,
66
- isWalletOwnershipVerified,
67
- isWalletOwnershipVerificationRequired,
68
- } = useAuthErrorHandling(isDev)
69
- const [walletOwnership, setWalletOwnership] = useState<boolean | undefined>()
70
- const [state, setState] = useState<STATE>(STATE.Loading)
71
-
72
- useEffect(() => {
73
- if (isWalletOwnershipVerificationRequired) {
74
- setState(STATE.Loading)
75
- }
76
- }, [isWalletOwnershipVerificationRequired])
77
-
78
- useEffect(() => {
79
- if (isWalletOwnershipVerified) {
80
- setWalletOwnership(true)
81
- }
82
- }, [isWalletOwnershipVerified])
83
-
84
- useEffect(() => {
85
- const checkWalletOwnership = async () => {
86
- if (account) {
87
- const ownership = await CampaignService.checkWalletOwnership(
88
- account,
89
- isDev,
90
- pointsTestnetExperience,
91
- )
92
- setWalletOwnership(ownership)
93
- if (!ownership) {
94
- setAuthError('WalletNotSignInException')
95
- }
96
- }
97
- }
98
- checkWalletOwnership()
99
- }, [account, isDev, pointsTestnetExperience, setAuthError])
100
-
101
- useEffect(() => {
102
- if (errorType === 'NotSignedIn') {
103
- setState(STATE.SignIn)
104
- } else if (errorType === 'UserRejected') {
105
- dispatch(
106
- setError({
107
- errorMessage: 'User has rejected the transaction.',
108
- }),
109
- )
110
- } else if (errorType === 'Other') {
111
- dispatch(
112
- setError({
113
- errorMessage: ERROR_MESSAGE,
114
- }),
115
- )
116
- }
117
- }, [dispatch, errorType])
118
-
119
- useEffect(() => {
120
- const updateWalletPoints = async () => {
121
- if (walletOwnership) {
122
- try {
123
- const result = await CampaignService.updateWalletPoints(
124
- account!,
125
- transactionHash,
126
- chainId!,
127
- isDev,
128
- pointsTestnetExperience,
129
- )
130
- setPointsAccumulated(result.pointsAccumulated)
131
- setState(STATE.Congrats)
132
- } catch (error) {
133
- console.error('Failed to update wallet points', error)
134
- }
135
- }
136
- }
137
- updateWalletPoints()
138
- }, [
139
- account,
140
- chainId,
141
- dispatch,
142
- isDev,
143
- pointsTestnetExperience,
144
- transactionHash,
145
- walletOwnership,
146
- ])
147
-
148
- const handleCloseModal = useCallback(() => {
149
- reset()
150
- dispatch(resetState())
151
- handleAction()
152
- }, [dispatch, handleAction, reset])
153
-
154
- const styles = {
155
- wrapper: css`
156
- height: 518px;
157
- position: relative;
158
- `,
159
- congrats: css`
160
- margin: ${theme.spacing(-4, -4.5, 0, -4.5)};
161
- `,
162
- ribbon: css`
163
- position: relative;
164
- ${theme.cssMixins.rowHCentered};
165
- font-weight: 700;
166
- margin-top: ${theme.spacing(-8)};
167
- color: ${theme.palette.text.primary};
168
- font-size: 20px;
169
- line-height: 160%;
170
- letter-spacing: 0.15px;
171
- `,
172
- ribbonContent: css`
173
- ${theme.cssMixins.rowVCentered};
174
- position: absolute;
175
- top: ${theme.spacing(1)};
176
-
177
- svg {
178
- margin-right: ${theme.spacing(1)};
179
- }
180
- `,
181
- entirePoints: css`
182
- color: ${theme.palette.text.tertiary};
183
- text-align: center;
184
- font-weight: 700;
185
- font-size: 20px;
186
- line-height: 160%;
187
- letter-spacing: 0.15px;
188
- margin-top: ${theme.spacing(7)};
189
- `,
190
- entirePointsDetails: css`
191
- color: ${theme.palette.text.tertiary};
192
- text-align: center;
193
- font-weight: 400;
194
- font-size: 16px;
195
- line-height: 150%;
196
- letter-spacing: 0.15px;
197
- margin-top: ${theme.spacing(4)};
198
- `,
199
- everyday: css`
200
- font-weight: 700;
201
- `,
202
- }
203
-
204
- if (state === STATE.SignIn) {
205
- return (
206
- <SignIn description='Please sign in to check the points that you earned.' />
207
- )
208
- }
209
-
210
- if (state === STATE.Congrats) {
211
- return (
212
- <Box css={styles.wrapper}>
213
- <Box css={styles.congrats}>
214
- <CongratulationsIcon />
215
- </Box>
216
- <Box css={styles.ribbon}>
217
- <RibbonIcon />
218
- <Box css={styles.ribbonContent}>
219
- <HumaPointsIcon />
220
- <Box>
221
- {hasPointsAccumulated
222
- ? `${formatNumber(pointsAccumulated)} Points`
223
- : 'Points earned'}
224
- </Box>
225
- </Box>
226
- </Box>
227
- <Box css={styles.entirePoints}>
228
- {hasPointsAccumulated ? (
229
- <>
230
- <Box>Congratulations,</Box>
231
- <Box>you've earned {pointsAccumulated} points</Box>
232
- </>
233
- ) : (
234
- <Box>Congratulations on joining the Huma Protocol!</Box>
235
- )}
236
- </Box>
237
- <Box css={styles.entirePointsDetails}>
238
- You'll earn points <span css={styles.everyday}>everyday</span> for{' '}
239
- {monthText} straight. Plus, If you keep your investment till after{' '}
240
- {monthText}, you’ll gain extra points daily.
241
- </Box>
242
- <BottomButton variant='contained' onClick={handleCloseModal}>
243
- GREAT
244
- </BottomButton>
245
- </Box>
246
- )
247
- }
248
-
249
- return <LoadingModal title='SUPPLY' />
250
- }
@@ -1,243 +0,0 @@
1
- import {
2
- CampaignService,
3
- checkIsDev,
4
- formatNumber,
5
- isEmpty,
6
- } from '@huma-finance/shared'
7
- import { txAtom, useAuthErrorHandling } from '@huma-finance/web-shared'
8
- import { Box, css, useTheme } from '@mui/material'
9
- import { useWeb3React } from '@web3-react/core'
10
- import { useResetAtom } from 'jotai/utils'
11
- import React, { useCallback, useEffect, useState } from 'react'
12
- import { useDispatch } from 'react-redux'
13
-
14
- import { resetState, setError } from '../../../store/widgets.reducers'
15
- import { BottomButton } from '../../BottomButton'
16
- import { CongratulationsIcon, HumaPointsIcon, RibbonIcon } from '../../icons'
17
- import { LoadingModal } from '../../LoadingModal'
18
- import { SignIn } from '../../SignIn'
19
-
20
- enum STATE {
21
- Loading = 'Loading',
22
- SignIn = 'SignIn',
23
- Congrats = 'Congrats',
24
- }
25
-
26
- const ERROR_MESSAGE =
27
- 'Failed to update wallet points. Be assured that your points will be added later.'
28
-
29
- type Props = {
30
- transactionHash: string
31
- lpConfig: { withdrawalLockoutPeriodInDays: number }
32
- pointsTestnetExperience: boolean
33
- handleAction: () => void
34
- }
35
-
36
- export function PointsEarned({
37
- transactionHash,
38
- lpConfig,
39
- pointsTestnetExperience,
40
- handleAction,
41
- }: Props): React.ReactElement {
42
- const theme = useTheme()
43
- const isDev = checkIsDev()
44
- const dispatch = useDispatch()
45
- const reset = useResetAtom(txAtom)
46
- const { account, chainId } = useWeb3React()
47
- const [pointsAccumulated, setPointsAccumulated] = useState<
48
- number | undefined
49
- >()
50
- const hasPointsAccumulated =
51
- !isEmpty(pointsAccumulated) && pointsAccumulated! > 0
52
- const lockupMonths = Math.round(lpConfig.withdrawalLockoutPeriodInDays / 30)
53
- const monthText =
54
- lockupMonths > 1 ? `${lockupMonths} months` : `${lockupMonths} month`
55
-
56
- const {
57
- errorType,
58
- setError: setAuthError,
59
- isWalletOwnershipVerified,
60
- isWalletOwnershipVerificationRequired,
61
- } = useAuthErrorHandling(isDev)
62
- const [walletOwnership, setWalletOwnership] = useState<boolean | undefined>()
63
- const [state, setState] = useState<STATE>(STATE.Loading)
64
-
65
- useEffect(() => {
66
- if (isWalletOwnershipVerificationRequired) {
67
- setState(STATE.Loading)
68
- }
69
- }, [isWalletOwnershipVerificationRequired])
70
-
71
- useEffect(() => {
72
- if (isWalletOwnershipVerified) {
73
- setWalletOwnership(true)
74
- }
75
- }, [isWalletOwnershipVerified])
76
-
77
- useEffect(() => {
78
- const checkWalletOwnership = async () => {
79
- if (account) {
80
- const ownership = await CampaignService.checkWalletOwnership(
81
- account,
82
- isDev,
83
- pointsTestnetExperience,
84
- )
85
- setWalletOwnership(ownership)
86
- if (!ownership) {
87
- setAuthError('WalletNotSignInException')
88
- }
89
- }
90
- }
91
- checkWalletOwnership()
92
- }, [account, isDev, pointsTestnetExperience, setAuthError])
93
-
94
- useEffect(() => {
95
- if (errorType === 'NotSignedIn') {
96
- setState(STATE.SignIn)
97
- } else if (errorType === 'UserRejected') {
98
- dispatch(
99
- setError({
100
- errorMessage: 'User has rejected the transaction.',
101
- }),
102
- )
103
- } else if (errorType === 'Other') {
104
- dispatch(
105
- setError({
106
- errorMessage: ERROR_MESSAGE,
107
- }),
108
- )
109
- }
110
- }, [dispatch, errorType])
111
-
112
- useEffect(() => {
113
- const updateWalletPoints = async () => {
114
- if (walletOwnership) {
115
- try {
116
- const result = await CampaignService.updateWalletPoints(
117
- account!,
118
- transactionHash,
119
- chainId!,
120
- isDev,
121
- pointsTestnetExperience,
122
- )
123
- setPointsAccumulated(result.pointsAccumulated)
124
- setState(STATE.Congrats)
125
- } catch (error) {
126
- console.error('Failed to update wallet points', error)
127
- }
128
- }
129
- }
130
- updateWalletPoints()
131
- }, [
132
- account,
133
- chainId,
134
- dispatch,
135
- isDev,
136
- pointsTestnetExperience,
137
- transactionHash,
138
- walletOwnership,
139
- ])
140
-
141
- const handleCloseModal = useCallback(() => {
142
- reset()
143
- dispatch(resetState())
144
- handleAction()
145
- }, [dispatch, handleAction, reset])
146
-
147
- const styles = {
148
- wrapper: css`
149
- height: 518px;
150
- position: relative;
151
- `,
152
- congrats: css`
153
- margin: ${theme.spacing(-4, -4.5, 0, -4.5)};
154
- `,
155
- ribbon: css`
156
- position: relative;
157
- ${theme.cssMixins.rowHCentered};
158
- font-weight: 700;
159
- margin-top: ${theme.spacing(-8)};
160
- color: ${theme.palette.text.primary};
161
- font-size: 20px;
162
- line-height: 160%;
163
- letter-spacing: 0.15px;
164
- `,
165
- ribbonContent: css`
166
- ${theme.cssMixins.rowVCentered};
167
- position: absolute;
168
- top: ${theme.spacing(1)};
169
-
170
- svg {
171
- margin-right: ${theme.spacing(1)};
172
- }
173
- `,
174
- entirePoints: css`
175
- color: ${theme.palette.text.tertiary};
176
- text-align: center;
177
- font-weight: 700;
178
- font-size: 20px;
179
- line-height: 160%;
180
- letter-spacing: 0.15px;
181
- margin-top: ${theme.spacing(7)};
182
- `,
183
- entirePointsDetails: css`
184
- color: ${theme.palette.text.tertiary};
185
- text-align: center;
186
- font-weight: 400;
187
- font-size: 16px;
188
- line-height: 150%;
189
- letter-spacing: 0.15px;
190
- margin-top: ${theme.spacing(4)};
191
- `,
192
- everyday: css`
193
- font-weight: 700;
194
- `,
195
- }
196
-
197
- if (state === STATE.SignIn) {
198
- return (
199
- <SignIn description='Please sign in to check the points that you earned.' />
200
- )
201
- }
202
-
203
- if (state === STATE.Congrats) {
204
- return (
205
- <Box css={styles.wrapper}>
206
- <Box css={styles.congrats}>
207
- <CongratulationsIcon />
208
- </Box>
209
- <Box css={styles.ribbon}>
210
- <RibbonIcon />
211
- <Box css={styles.ribbonContent}>
212
- <HumaPointsIcon />
213
- <Box>
214
- {hasPointsAccumulated
215
- ? `${formatNumber(pointsAccumulated)} Points`
216
- : 'Points earned'}
217
- </Box>
218
- </Box>
219
- </Box>
220
- <Box css={styles.entirePoints}>
221
- {hasPointsAccumulated ? (
222
- <>
223
- <Box>Congratulations,</Box>
224
- <Box>you've earned {pointsAccumulated} points</Box>
225
- </>
226
- ) : (
227
- <Box>Congratulations on joining the Huma Protocol!</Box>
228
- )}
229
- </Box>
230
- <Box css={styles.entirePointsDetails}>
231
- You'll earn points <span css={styles.everyday}>everyday</span> for{' '}
232
- {monthText} straight. Plus, If you keep your investment till after{' '}
233
- {monthText}, you’ll gain extra points daily.
234
- </Box>
235
- <BottomButton variant='contained' onClick={handleCloseModal}>
236
- GREAT
237
- </BottomButton>
238
- </Box>
239
- )
240
- }
241
-
242
- return <LoadingModal title='SUPPLY' />
243
- }