@huma-finance/widgets 0.0.59-beta.494 → 0.0.59-beta.495
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/API.md +2 -0
- package/dist/cjs/index.cjs +967 -191
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/index.d.ts +8 -0
- package/dist/index.js +968 -193
- package/dist/index.js.map +1 -1
- package/package.json +6 -4
- package/src/components/ChooseAmountModal.tsx +2 -3
- package/src/components/ConfirmTransferModal.tsx +2 -2
- package/src/components/ErrorModal.tsx +1 -1
- package/src/components/InputAmountModal.tsx +2 -2
- package/src/components/Lend/supplyV2/2-Evaluation.tsx +31 -329
- package/src/components/Lend/supplyV2/3-ChooseAmount.tsx +58 -9
- package/src/components/Lend/supplyV2/6-Success.tsx +49 -6
- package/src/components/Lend/supplyV2/7-Notifications.tsx +22 -3
- package/src/components/Lend/supplyV2/8-PointsEarned.tsx +231 -0
- package/src/components/Lend/supplyV2/components/PersonaEvaluation.tsx +442 -0
- package/src/components/Lend/supplyV2/components/SecuritizeEvaluation.tsx +345 -0
- package/src/components/Lend/supplyV2/index.tsx +67 -5
- package/src/components/Lend/withdrawV2/1-ConfirmTransfer.tsx +1 -1
- package/src/components/SignIn.tsx +7 -2
- package/src/components/TxDoneModal.tsx +21 -2
- package/src/components/humaModal/HumaModal.tsx +1 -0
- package/src/components/humaModal/HumaModalHeader.tsx +1 -0
- package/src/components/icons/congratulations.svg +54 -0
- package/src/components/icons/huma-points.svg +15 -0
- package/src/components/icons/index.tsx +15 -0
- package/src/components/icons/ribbon.svg +9 -0
- package/src/store/widgets.reducers.ts +0 -1
- package/src/store/widgets.store.ts +1 -0
- package/src/theme/palette.ts +1 -1
|
@@ -4,11 +4,13 @@ import {
|
|
|
4
4
|
formatMoney,
|
|
5
5
|
PoolInfoV2,
|
|
6
6
|
sendTxAtom,
|
|
7
|
+
timeUtil,
|
|
7
8
|
TRANSFER_ABI,
|
|
8
9
|
UnderlyingTokenInfo,
|
|
9
10
|
} from '@huma-finance/shared'
|
|
10
11
|
import { useWeb3React } from '@web3-react/core'
|
|
11
12
|
import { useAtom } from 'jotai'
|
|
13
|
+
import moment from 'moment'
|
|
12
14
|
import React, { useCallback, useEffect, useState } from 'react'
|
|
13
15
|
import { useDispatch } from 'react-redux'
|
|
14
16
|
|
|
@@ -16,24 +18,31 @@ import {
|
|
|
16
18
|
useDoesChainSupportNotifi,
|
|
17
19
|
useIsFirstTimeNotifiUser,
|
|
18
20
|
} from '../../../hooks/useNotifi'
|
|
19
|
-
import { TxDoneModal } from '../../TxDoneModal'
|
|
20
21
|
import { setStep } from '../../../store/widgets.reducers'
|
|
21
22
|
import { WIDGET_STEP } from '../../../store/widgets.store'
|
|
23
|
+
import { TxDoneModal } from '../../TxDoneModal'
|
|
24
|
+
import { Campaign } from '.'
|
|
22
25
|
|
|
23
26
|
type Props = {
|
|
24
27
|
poolInfo: PoolInfoV2
|
|
25
28
|
poolUnderlyingToken: UnderlyingTokenInfo
|
|
29
|
+
lpConfig: { withdrawalLockoutPeriodInDays: number }
|
|
30
|
+
campaign?: Campaign
|
|
31
|
+
updateTransactionHash: (hash: string) => void
|
|
26
32
|
handleAction: () => void
|
|
27
33
|
}
|
|
28
34
|
|
|
29
35
|
export function Success({
|
|
30
36
|
poolInfo,
|
|
31
37
|
poolUnderlyingToken,
|
|
38
|
+
lpConfig,
|
|
39
|
+
campaign,
|
|
40
|
+
updateTransactionHash,
|
|
32
41
|
handleAction,
|
|
33
42
|
}: Props): React.ReactElement {
|
|
34
43
|
const dispatch = useDispatch()
|
|
35
44
|
const { account, chainId } = useWeb3React()
|
|
36
|
-
const [{ txReceipt }] = useAtom(sendTxAtom)
|
|
45
|
+
const [{ txReceipt, txHash }] = useAtom(sendTxAtom)
|
|
37
46
|
const { symbol, decimals, address } = poolUnderlyingToken
|
|
38
47
|
const [supplyAmount, setSupplyAmount] = useState<string | undefined>()
|
|
39
48
|
const { isFirstTimeNotifiUser } = useIsFirstTimeNotifiUser(account, chainId)
|
|
@@ -57,23 +66,57 @@ export function Success({
|
|
|
57
66
|
}
|
|
58
67
|
}, [account, address, decimals, poolInfo.poolSafe, txReceipt])
|
|
59
68
|
|
|
60
|
-
|
|
69
|
+
useEffect(() => {
|
|
70
|
+
if (txHash) {
|
|
71
|
+
updateTransactionHash(txHash)
|
|
72
|
+
}
|
|
73
|
+
}, [txHash, updateTransactionHash])
|
|
74
|
+
|
|
75
|
+
const handleUserAction = useCallback(() => {
|
|
61
76
|
if (isFirstTimeNotifiUser && notifiChainSupported) {
|
|
62
77
|
dispatch(setStep(WIDGET_STEP.Notifications))
|
|
78
|
+
} else if (campaign) {
|
|
79
|
+
dispatch(setStep(WIDGET_STEP.PointsEarned))
|
|
63
80
|
} else {
|
|
64
81
|
handleAction()
|
|
65
82
|
}
|
|
66
|
-
}, [
|
|
83
|
+
}, [
|
|
84
|
+
campaign,
|
|
85
|
+
dispatch,
|
|
86
|
+
handleAction,
|
|
87
|
+
isFirstTimeNotifiUser,
|
|
88
|
+
notifiChainSupported,
|
|
89
|
+
])
|
|
67
90
|
|
|
68
91
|
const content = [
|
|
69
92
|
`You successfully supplied ${formatMoney(supplyAmount)} ${symbol}.`,
|
|
70
93
|
]
|
|
71
94
|
|
|
95
|
+
const getSubContent = () => {
|
|
96
|
+
const currentTime = moment().add(
|
|
97
|
+
lpConfig.withdrawalLockoutPeriodInDays,
|
|
98
|
+
'days',
|
|
99
|
+
)
|
|
100
|
+
return [
|
|
101
|
+
`First redemption date: ${timeUtil.timestampToLL(
|
|
102
|
+
currentTime.unix(),
|
|
103
|
+
)}. You can redeem end of each month after.`,
|
|
104
|
+
]
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
const getButtonText = () => {
|
|
108
|
+
if (hasNextStep) {
|
|
109
|
+
return "WHAT'S NEXT"
|
|
110
|
+
}
|
|
111
|
+
return campaign ? 'VIEW POINTS' : undefined
|
|
112
|
+
}
|
|
113
|
+
|
|
72
114
|
return (
|
|
73
115
|
<TxDoneModal
|
|
74
|
-
handleAction={
|
|
116
|
+
handleAction={handleUserAction}
|
|
75
117
|
content={content}
|
|
76
|
-
|
|
118
|
+
subContent={getSubContent()}
|
|
119
|
+
buttonText={getButtonText()}
|
|
77
120
|
/>
|
|
78
121
|
)
|
|
79
122
|
}
|
|
@@ -1,10 +1,29 @@
|
|
|
1
|
-
import React from 'react'
|
|
1
|
+
import React, { useCallback } from 'react'
|
|
2
|
+
import { useDispatch } from 'react-redux'
|
|
3
|
+
|
|
4
|
+
import { Campaign } from '.'
|
|
2
5
|
import { NotifiSubscriptionModal } from '../../Notifi/NotifiSubscriptionModal'
|
|
6
|
+
import { setStep } from '../../../store/widgets.reducers'
|
|
7
|
+
import { WIDGET_STEP } from '../../../store/widgets.store'
|
|
3
8
|
|
|
4
9
|
type Props = {
|
|
10
|
+
campaign?: Campaign
|
|
5
11
|
handleAction: () => void
|
|
6
12
|
}
|
|
7
13
|
|
|
8
|
-
export function Notifications({
|
|
9
|
-
|
|
14
|
+
export function Notifications({
|
|
15
|
+
campaign,
|
|
16
|
+
handleAction,
|
|
17
|
+
}: Props): React.ReactElement {
|
|
18
|
+
const dispatch = useDispatch()
|
|
19
|
+
|
|
20
|
+
const handleUserAction = useCallback(() => {
|
|
21
|
+
if (campaign) {
|
|
22
|
+
dispatch(setStep(WIDGET_STEP.PointsEarned))
|
|
23
|
+
} else {
|
|
24
|
+
handleAction()
|
|
25
|
+
}
|
|
26
|
+
}, [campaign, dispatch, handleAction])
|
|
27
|
+
|
|
28
|
+
return <NotifiSubscriptionModal handleSuccess={handleUserAction} />
|
|
10
29
|
}
|
|
@@ -0,0 +1,231 @@
|
|
|
1
|
+
import {
|
|
2
|
+
CampaignService,
|
|
3
|
+
checkIsDev,
|
|
4
|
+
formatNumber,
|
|
5
|
+
useAuthErrorHandling,
|
|
6
|
+
} from '@huma-finance/shared'
|
|
7
|
+
import { Box, css, useTheme } from '@mui/material'
|
|
8
|
+
import { useWeb3React } from '@web3-react/core'
|
|
9
|
+
import React, { useEffect, useState } from 'react'
|
|
10
|
+
import { useDispatch } from 'react-redux'
|
|
11
|
+
|
|
12
|
+
import { setError } from '../../../store/widgets.reducers'
|
|
13
|
+
import { BottomButton } from '../../BottomButton'
|
|
14
|
+
import { CongratulationsIcon, HumaPointsIcon, RibbonIcon } from '../../icons'
|
|
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.'
|
|
26
|
+
|
|
27
|
+
type Props = {
|
|
28
|
+
transactionHash: string
|
|
29
|
+
lpConfig: { withdrawalLockoutPeriodInDays: number }
|
|
30
|
+
pointsTestnetExperience: boolean
|
|
31
|
+
handleAction: () => void
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export function PointsEarned({
|
|
35
|
+
transactionHash,
|
|
36
|
+
lpConfig,
|
|
37
|
+
pointsTestnetExperience,
|
|
38
|
+
handleAction,
|
|
39
|
+
}: Props): React.ReactElement {
|
|
40
|
+
const theme = useTheme()
|
|
41
|
+
const isDev = checkIsDev()
|
|
42
|
+
const dispatch = useDispatch()
|
|
43
|
+
const { account, chainId } = useWeb3React()
|
|
44
|
+
const [pointsAccumulated, setPointsAccumulated] = useState<
|
|
45
|
+
number | undefined
|
|
46
|
+
>()
|
|
47
|
+
const lockupMonths = Math.round(lpConfig.withdrawalLockoutPeriodInDays / 30)
|
|
48
|
+
const monthText =
|
|
49
|
+
lockupMonths > 1 ? `${lockupMonths} months` : `${lockupMonths} month`
|
|
50
|
+
|
|
51
|
+
const {
|
|
52
|
+
errorType,
|
|
53
|
+
setError: setAuthError,
|
|
54
|
+
isWalletOwnershipVerified,
|
|
55
|
+
isWalletOwnershipVerificationRequired,
|
|
56
|
+
} = useAuthErrorHandling(isDev)
|
|
57
|
+
const [walletOwnership, setWalletOwnership] = useState<boolean | undefined>()
|
|
58
|
+
const [state, setState] = useState<STATE>(STATE.Loading)
|
|
59
|
+
|
|
60
|
+
useEffect(() => {
|
|
61
|
+
if (isWalletOwnershipVerificationRequired) {
|
|
62
|
+
setState(STATE.Loading)
|
|
63
|
+
}
|
|
64
|
+
}, [isWalletOwnershipVerificationRequired])
|
|
65
|
+
|
|
66
|
+
useEffect(() => {
|
|
67
|
+
if (isWalletOwnershipVerified) {
|
|
68
|
+
setWalletOwnership(true)
|
|
69
|
+
}
|
|
70
|
+
}, [isWalletOwnershipVerified])
|
|
71
|
+
|
|
72
|
+
useEffect(() => {
|
|
73
|
+
const checkWalletOwnership = async () => {
|
|
74
|
+
const ownership = await CampaignService.checkWalletOwnership(
|
|
75
|
+
account!,
|
|
76
|
+
isDev,
|
|
77
|
+
pointsTestnetExperience,
|
|
78
|
+
)
|
|
79
|
+
setWalletOwnership(ownership)
|
|
80
|
+
if (!ownership) {
|
|
81
|
+
setAuthError('WalletNotSignInException')
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
checkWalletOwnership()
|
|
85
|
+
}, [account, isDev, pointsTestnetExperience, setAuthError])
|
|
86
|
+
|
|
87
|
+
useEffect(() => {
|
|
88
|
+
if (errorType === 'NotSignedIn') {
|
|
89
|
+
setState(STATE.SignIn)
|
|
90
|
+
} else if (errorType === 'UserRejected') {
|
|
91
|
+
dispatch(
|
|
92
|
+
setError({
|
|
93
|
+
errorMessage: 'User has rejected the transaction.',
|
|
94
|
+
}),
|
|
95
|
+
)
|
|
96
|
+
} else if (errorType === 'Other') {
|
|
97
|
+
dispatch(
|
|
98
|
+
setError({
|
|
99
|
+
errorMessage: ERROR_MESSAGE,
|
|
100
|
+
}),
|
|
101
|
+
)
|
|
102
|
+
}
|
|
103
|
+
}, [dispatch, errorType])
|
|
104
|
+
|
|
105
|
+
useEffect(() => {
|
|
106
|
+
const updateWalletPoints = async () => {
|
|
107
|
+
if (walletOwnership) {
|
|
108
|
+
try {
|
|
109
|
+
const result = await CampaignService.updateWalletPoints(
|
|
110
|
+
account!,
|
|
111
|
+
transactionHash,
|
|
112
|
+
chainId!,
|
|
113
|
+
isDev,
|
|
114
|
+
pointsTestnetExperience,
|
|
115
|
+
)
|
|
116
|
+
if (!result.pointsAccumulated) {
|
|
117
|
+
dispatch(
|
|
118
|
+
setError({
|
|
119
|
+
errorMessage: ERROR_MESSAGE,
|
|
120
|
+
}),
|
|
121
|
+
)
|
|
122
|
+
}
|
|
123
|
+
setPointsAccumulated(result.pointsAccumulated)
|
|
124
|
+
setState(STATE.Congrats)
|
|
125
|
+
} catch (error) {
|
|
126
|
+
dispatch(
|
|
127
|
+
setError({
|
|
128
|
+
errorMessage: ERROR_MESSAGE,
|
|
129
|
+
}),
|
|
130
|
+
)
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
updateWalletPoints()
|
|
135
|
+
}, [
|
|
136
|
+
account,
|
|
137
|
+
chainId,
|
|
138
|
+
dispatch,
|
|
139
|
+
isDev,
|
|
140
|
+
pointsTestnetExperience,
|
|
141
|
+
transactionHash,
|
|
142
|
+
walletOwnership,
|
|
143
|
+
])
|
|
144
|
+
|
|
145
|
+
const styles = {
|
|
146
|
+
wrapper: css`
|
|
147
|
+
height: 518px;
|
|
148
|
+
position: relative;
|
|
149
|
+
`,
|
|
150
|
+
congrats: css`
|
|
151
|
+
margin: ${theme.spacing(-4, -4.5, 0, -4.5)};
|
|
152
|
+
`,
|
|
153
|
+
ribbon: css`
|
|
154
|
+
position: relative;
|
|
155
|
+
${theme.cssMixins.rowHCentered};
|
|
156
|
+
font-weight: 700;
|
|
157
|
+
margin-top: ${theme.spacing(-8)};
|
|
158
|
+
color: ${theme.palette.text.primary};
|
|
159
|
+
font-size: 20px;
|
|
160
|
+
line-height: 160%;
|
|
161
|
+
letter-spacing: 0.15px;
|
|
162
|
+
`,
|
|
163
|
+
ribbonContent: css`
|
|
164
|
+
${theme.cssMixins.rowVCentered};
|
|
165
|
+
position: absolute;
|
|
166
|
+
top: ${theme.spacing(1)};
|
|
167
|
+
|
|
168
|
+
svg {
|
|
169
|
+
margin-right: ${theme.spacing(1)};
|
|
170
|
+
}
|
|
171
|
+
`,
|
|
172
|
+
entirePoints: css`
|
|
173
|
+
color: ${theme.palette.text.tertiary};
|
|
174
|
+
text-align: center;
|
|
175
|
+
font-weight: 700;
|
|
176
|
+
font-size: 20px;
|
|
177
|
+
line-height: 160%;
|
|
178
|
+
letter-spacing: 0.15px;
|
|
179
|
+
margin-top: ${theme.spacing(7)};
|
|
180
|
+
`,
|
|
181
|
+
entirePointsDetails: css`
|
|
182
|
+
color: ${theme.palette.text.tertiary};
|
|
183
|
+
text-align: center;
|
|
184
|
+
font-weight: 400;
|
|
185
|
+
font-size: 16px;
|
|
186
|
+
line-height: 150%;
|
|
187
|
+
letter-spacing: 0.15px;
|
|
188
|
+
margin-top: ${theme.spacing(4)};
|
|
189
|
+
`,
|
|
190
|
+
everyday: css`
|
|
191
|
+
font-weight: 700;
|
|
192
|
+
`,
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
if (state === STATE.SignIn) {
|
|
196
|
+
return (
|
|
197
|
+
<SignIn description='Please sign in to check the points that you earned.' />
|
|
198
|
+
)
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
if (state === STATE.Congrats) {
|
|
202
|
+
return (
|
|
203
|
+
<Box css={styles.wrapper}>
|
|
204
|
+
<Box css={styles.congrats}>
|
|
205
|
+
<CongratulationsIcon />
|
|
206
|
+
</Box>
|
|
207
|
+
<Box css={styles.ribbon}>
|
|
208
|
+
<RibbonIcon />
|
|
209
|
+
<Box css={styles.ribbonContent}>
|
|
210
|
+
<HumaPointsIcon />
|
|
211
|
+
<Box>{formatNumber(pointsAccumulated)} Points</Box>
|
|
212
|
+
</Box>
|
|
213
|
+
</Box>
|
|
214
|
+
<Box css={styles.entirePoints}>
|
|
215
|
+
<Box>Congratulations,</Box>
|
|
216
|
+
<Box>you've earned {pointsAccumulated} points</Box>
|
|
217
|
+
</Box>
|
|
218
|
+
<Box css={styles.entirePointsDetails}>
|
|
219
|
+
You'll earn points <span css={styles.everyday}>everyday</span> for{' '}
|
|
220
|
+
{monthText} straight. Plus, If you keep your investment till after{' '}
|
|
221
|
+
{monthText}, you’ll gain extra points daily.
|
|
222
|
+
</Box>
|
|
223
|
+
<BottomButton variant='contained' onClick={handleAction}>
|
|
224
|
+
GREAT
|
|
225
|
+
</BottomButton>
|
|
226
|
+
</Box>
|
|
227
|
+
)
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
return <LoadingModal title='SUPPLY' />
|
|
231
|
+
}
|