@huma-finance/widgets 0.0.62-beta.635 → 0.0.62-beta.636
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/dist/cjs/index.cjs +314 -141
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/index.js +314 -141
- package/dist/index.js.map +1 -1
- package/package.json +5 -5
- package/src/components/Lend/solanaSupply/5-Success.tsx +27 -5
- package/src/components/Lend/solanaSupply/6-PointsEarned.tsx +250 -0
- package/src/components/Lend/solanaSupply/index.tsx +18 -0
- package/src/components/Lend/supplyV2/8-PointsEarned.tsx +10 -8
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@huma-finance/widgets",
|
|
3
|
-
"version": "0.0.62-beta.
|
|
3
|
+
"version": "0.0.62-beta.636+9afaa1d",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
@@ -29,9 +29,9 @@
|
|
|
29
29
|
"@ethersproject/experimental": "^5.7.0",
|
|
30
30
|
"@ethersproject/providers": "^5.6.0",
|
|
31
31
|
"@ethersproject/units": "^5.6.0",
|
|
32
|
-
"@huma-finance/sdk": "^0.0.62-beta.
|
|
33
|
-
"@huma-finance/shared": "^0.0.62-beta.
|
|
34
|
-
"@huma-finance/web-shared": "^0.0.62-beta.
|
|
32
|
+
"@huma-finance/sdk": "^0.0.62-beta.636+9afaa1d",
|
|
33
|
+
"@huma-finance/shared": "^0.0.62-beta.636+9afaa1d",
|
|
34
|
+
"@huma-finance/web-shared": "^0.0.62-beta.636+9afaa1d",
|
|
35
35
|
"@mui/icons-material": "^5.3.0",
|
|
36
36
|
"@mui/material": "^5.0.6",
|
|
37
37
|
"@mui/styles": "^5.0.2",
|
|
@@ -207,5 +207,5 @@
|
|
|
207
207
|
"optionalDependencies": {
|
|
208
208
|
"encoding": "^0.1.13"
|
|
209
209
|
},
|
|
210
|
-
"gitHead": "
|
|
210
|
+
"gitHead": "9afaa1d673baaa4ce656cbc6fba229e446d3d927"
|
|
211
211
|
}
|
|
@@ -1,26 +1,40 @@
|
|
|
1
1
|
import { formatMoney, SolanaPoolInfo, timeUtil } from '@huma-finance/shared'
|
|
2
2
|
import { SolanaPoolState } from '@huma-finance/web-shared'
|
|
3
|
-
import React from 'react'
|
|
4
|
-
|
|
5
3
|
import dayjs from 'dayjs'
|
|
6
|
-
import {
|
|
4
|
+
import React, { useCallback, useEffect } from 'react'
|
|
5
|
+
import { useDispatch } from 'react-redux'
|
|
6
|
+
import { Campaign } from '.'
|
|
7
7
|
import { useAppSelector } from '../../../hooks/useRedux'
|
|
8
|
+
import { setStep } from '../../../store/widgets.reducers'
|
|
9
|
+
import { selectWidgetState } from '../../../store/widgets.selectors'
|
|
10
|
+
import { WIDGET_STEP } from '../../../store/widgets.store'
|
|
8
11
|
import { SolanaTxDoneModal } from '../../SolanaTxDoneModal'
|
|
9
12
|
|
|
10
13
|
type Props = {
|
|
11
14
|
poolInfo: SolanaPoolInfo
|
|
12
15
|
poolState: SolanaPoolState
|
|
16
|
+
campaign?: Campaign
|
|
17
|
+
updateTransactionHash: (hash: string) => void
|
|
13
18
|
handleAction: () => void
|
|
14
19
|
}
|
|
15
20
|
|
|
16
21
|
export function Success({
|
|
17
22
|
poolInfo,
|
|
18
23
|
poolState,
|
|
24
|
+
campaign,
|
|
25
|
+
updateTransactionHash,
|
|
19
26
|
handleAction,
|
|
20
27
|
}: Props): React.ReactElement {
|
|
28
|
+
const dispatch = useDispatch()
|
|
21
29
|
const { supplyAmount, solanaSignature } = useAppSelector(selectWidgetState)
|
|
22
30
|
const { symbol } = poolInfo.underlyingMint
|
|
23
31
|
|
|
32
|
+
useEffect(() => {
|
|
33
|
+
if (solanaSignature) {
|
|
34
|
+
updateTransactionHash(solanaSignature)
|
|
35
|
+
}
|
|
36
|
+
}, [solanaSignature, updateTransactionHash])
|
|
37
|
+
|
|
24
38
|
const content = [
|
|
25
39
|
`You successfully supplied ${formatMoney(supplyAmount)} ${symbol}.`,
|
|
26
40
|
]
|
|
@@ -39,14 +53,22 @@ export function Success({
|
|
|
39
53
|
]
|
|
40
54
|
}
|
|
41
55
|
|
|
56
|
+
const handleUserAction = useCallback(() => {
|
|
57
|
+
if (campaign) {
|
|
58
|
+
dispatch(setStep(WIDGET_STEP.PointsEarned))
|
|
59
|
+
} else {
|
|
60
|
+
handleAction()
|
|
61
|
+
}
|
|
62
|
+
}, [campaign, dispatch, handleAction])
|
|
63
|
+
|
|
42
64
|
return (
|
|
43
65
|
<SolanaTxDoneModal
|
|
44
|
-
handleAction={
|
|
66
|
+
handleAction={handleUserAction}
|
|
45
67
|
content={content}
|
|
46
68
|
subContent={getSubContent()}
|
|
47
69
|
chainId={poolInfo.chainId}
|
|
48
70
|
solanaSignature={solanaSignature}
|
|
49
|
-
buttonText='DONE'
|
|
71
|
+
buttonText={campaign ? 'VIEW POINTS' : 'DONE'}
|
|
50
72
|
/>
|
|
51
73
|
)
|
|
52
74
|
}
|
|
@@ -0,0 +1,250 @@
|
|
|
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
|
+
}
|
|
@@ -18,6 +18,12 @@ import { ChooseTranche } from './2-ChooseTranche'
|
|
|
18
18
|
import { ChooseAmount } from './3-ChooseAmount'
|
|
19
19
|
import { Transfer } from './4-Transfer'
|
|
20
20
|
import { Success } from './5-Success'
|
|
21
|
+
import { PointsEarned } from './6-PointsEarned'
|
|
22
|
+
|
|
23
|
+
export interface Campaign {
|
|
24
|
+
id: string
|
|
25
|
+
campaignGroupId: string
|
|
26
|
+
}
|
|
21
27
|
|
|
22
28
|
/**
|
|
23
29
|
* Lend pool supply props
|
|
@@ -53,6 +59,7 @@ export function SolanaLendSupply({
|
|
|
53
59
|
const [tokenAccount, isLoadingTokenAccount] = useTokenAccount(poolInfo)
|
|
54
60
|
const { step, errorMessage } = useAppSelector(selectWidgetState)
|
|
55
61
|
const [selectedTranche, setSelectedTranche] = useState<TrancheType>()
|
|
62
|
+
const [transactionHash, setTransactionHash] = useState<string | undefined>()
|
|
56
63
|
|
|
57
64
|
useEffect(() => {
|
|
58
65
|
if (!step && !isLoadingLenderAccounts && !isLoadingTokenAccount) {
|
|
@@ -112,6 +119,7 @@ export function SolanaLendSupply({
|
|
|
112
119
|
poolInfo={poolInfo}
|
|
113
120
|
isUniTranche={!!isUniTranche}
|
|
114
121
|
pointsTestnetExperience={pointsTestnetExperience}
|
|
122
|
+
campaign={poolState.campaign}
|
|
115
123
|
handleClose={handleClose}
|
|
116
124
|
changeTranche={setSelectedTranche}
|
|
117
125
|
/>
|
|
@@ -139,6 +147,16 @@ export function SolanaLendSupply({
|
|
|
139
147
|
<Success
|
|
140
148
|
poolInfo={poolInfo}
|
|
141
149
|
poolState={poolState}
|
|
150
|
+
campaign={poolState.campaign}
|
|
151
|
+
updateTransactionHash={setTransactionHash}
|
|
152
|
+
handleAction={handleClose}
|
|
153
|
+
/>
|
|
154
|
+
)}
|
|
155
|
+
{step === WIDGET_STEP.PointsEarned && transactionHash && (
|
|
156
|
+
<PointsEarned
|
|
157
|
+
transactionHash={transactionHash}
|
|
158
|
+
poolState={poolState}
|
|
159
|
+
pointsTestnetExperience={pointsTestnetExperience}
|
|
142
160
|
handleAction={handleClose}
|
|
143
161
|
/>
|
|
144
162
|
)}
|
|
@@ -76,14 +76,16 @@ export function PointsEarned({
|
|
|
76
76
|
|
|
77
77
|
useEffect(() => {
|
|
78
78
|
const checkWalletOwnership = async () => {
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
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
|
+
}
|
|
87
89
|
}
|
|
88
90
|
}
|
|
89
91
|
checkWalletOwnership()
|