@huma-finance/widgets 0.0.59-beta.489 → 0.0.59-beta.492

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.
Files changed (41) hide show
  1. package/API.md +1 -0
  2. package/dist/cjs/index.cjs +1095 -323
  3. package/dist/cjs/index.cjs.map +1 -1
  4. package/dist/index.d.ts +6 -0
  5. package/dist/index.js +1096 -325
  6. package/dist/index.js.map +1 -1
  7. package/package.json +6 -4
  8. package/src/components/Activity.tsx +1 -2
  9. package/src/components/ApproveAllowanceModal.tsx +1 -1
  10. package/src/components/ApproveAllowanceModalV2.tsx +1 -1
  11. package/src/components/ChooseAmountModal.tsx +10 -8
  12. package/src/components/ConfirmTransferModal.tsx +3 -3
  13. package/src/components/CreditLine/borrow/1-Evaluation.tsx +2 -2
  14. package/src/components/ErrorModal.tsx +3 -10
  15. package/src/components/InputAmountModal.tsx +7 -5
  16. package/src/components/Lend/supply/1-Evaluation/EvaluationEA.tsx +1 -1
  17. package/src/components/Lend/supply/1-Evaluation/EvaluationKYC.tsx +1 -1
  18. package/src/components/Lend/supplyV2/2-Evaluation.tsx +28 -329
  19. package/src/components/Lend/supplyV2/3-ChooseAmount.tsx +54 -9
  20. package/src/components/Lend/supplyV2/6-Success.tsx +49 -6
  21. package/src/components/Lend/supplyV2/7-Notifications.tsx +22 -3
  22. package/src/components/Lend/supplyV2/8-PointsEarned.tsx +219 -0
  23. package/src/components/Lend/supplyV2/components/PersonaEvaluation.tsx +426 -0
  24. package/src/components/Lend/supplyV2/components/SecuritizeEvaluation.tsx +345 -0
  25. package/src/components/Lend/supplyV2/index.tsx +61 -5
  26. package/src/components/Lend/withdrawV2/1-ConfirmTransfer.tsx +1 -1
  27. package/src/components/Notifi/NotifiSubscriptionModal.tsx +1 -1
  28. package/src/components/SignIn.tsx +8 -3
  29. package/src/components/TxDoneModal.tsx +22 -3
  30. package/src/components/WrapperModal.tsx +1 -1
  31. package/src/components/humaModal/HumaModal.tsx +4 -3
  32. package/src/components/humaModal/HumaModalHeader.tsx +1 -0
  33. package/src/components/icons/congratulations.svg +54 -0
  34. package/src/components/icons/huma-points.svg +15 -0
  35. package/src/components/icons/index.tsx +15 -0
  36. package/src/components/icons/ribbon.svg +9 -0
  37. package/src/store/widgets.reducers.ts +0 -1
  38. package/src/store/widgets.store.ts +1 -0
  39. package/src/theme/components.ts +2 -1
  40. package/src/theme/palette.ts +7 -7
  41. package/src/theme/typography.ts +0 -1
@@ -1,37 +1,47 @@
1
1
  import {
2
+ CampaignService,
3
+ checkIsDev,
4
+ formatNumber,
2
5
  PoolInfoV2,
3
6
  TrancheType,
4
7
  UnderlyingTokenInfo,
5
- formatNumber,
6
- useLPConfigV2,
8
+ useDebouncedValue,
7
9
  usePoolSafeAllowanceV2,
8
10
  usePoolUnderlyingTokenBalanceV2,
9
11
  } from '@huma-finance/shared'
10
12
  import { useWeb3React } from '@web3-react/core'
11
13
  import { BigNumber, ethers } from 'ethers'
12
- import React, { useState } from 'react'
14
+ import React, { useEffect, useState } from 'react'
13
15
 
14
16
  import { useAppDispatch } from '../../../hooks/useRedux'
15
17
  import { setStep, setSupplyAmount } from '../../../store/widgets.reducers'
16
18
  import { WIDGET_STEP } from '../../../store/widgets.store'
17
19
  import { InputAmountModal } from '../../InputAmountModal'
18
- import { LoadingModal } from '../../LoadingModal'
20
+ import { Campaign } from '.'
19
21
 
20
22
  type Props = {
21
23
  poolInfo: PoolInfoV2
22
24
  poolUnderlyingToken: UnderlyingTokenInfo
23
25
  selectedTranche: TrancheType | undefined
26
+ isUniTranche: boolean
27
+ campaign?: Campaign
24
28
  }
25
29
 
26
30
  export function ChooseAmount({
27
31
  poolInfo,
28
32
  poolUnderlyingToken,
29
33
  selectedTranche,
34
+ isUniTranche,
35
+ campaign,
30
36
  }: Props): React.ReactElement | null {
37
+ const isDev = checkIsDev()
31
38
  const dispatch = useAppDispatch()
32
39
  const { account, provider } = useWeb3React()
33
40
  const { symbol, decimals } = poolUnderlyingToken
34
41
  const [currentAmount, setCurrentAmount] = useState<number | string>(0)
42
+ const debouncedValue = useDebouncedValue(currentAmount)
43
+ const [campaignPoints, setCampaignPoints] = useState<number>(0)
44
+ const [lockupPeriodMonths, setLockupPeriodMonths] = useState<number>(0)
35
45
  const { allowance = BigNumber.from(0) } = usePoolSafeAllowanceV2(
36
46
  poolInfo.poolName,
37
47
  account,
@@ -46,8 +56,40 @@ export function ChooseAmount({
46
56
  balance,
47
57
  poolUnderlyingToken.decimals,
48
58
  )
49
- const lpConfig = useLPConfigV2(poolInfo.poolName, provider)
50
- const isUniTranche = lpConfig?.maxSeniorJuniorRatio === 0
59
+
60
+ useEffect(() => {
61
+ const getBasePoints = async () => {
62
+ if (campaign && selectedTranche && Number(debouncedValue) > 0) {
63
+ const estimatedPoints = await CampaignService.getEstimatedPoints(
64
+ campaign.campaignGroupId,
65
+ ethers.utils
66
+ .parseUnits(
67
+ String(debouncedValue),
68
+ poolInfo.poolUnderlyingToken.decimals,
69
+ )
70
+ .toString(),
71
+ isDev,
72
+ )
73
+ const campaignPoints = estimatedPoints.find(
74
+ (item) => item.campaignId === campaign.id,
75
+ )
76
+ if (campaignPoints) {
77
+ setCampaignPoints(campaignPoints[`${selectedTranche}TranchePoints`])
78
+ setLockupPeriodMonths(campaignPoints.lockupPeriodMonths)
79
+ }
80
+ } else {
81
+ setCampaignPoints(0)
82
+ }
83
+ }
84
+ getBasePoints()
85
+ }, [
86
+ campaign,
87
+ debouncedValue,
88
+ decimals,
89
+ isDev,
90
+ poolInfo.poolUnderlyingToken.decimals,
91
+ selectedTranche,
92
+ ])
51
93
 
52
94
  const handleChangeAmount = (newAmount: number) => {
53
95
  setCurrentAmount(newAmount)
@@ -65,8 +107,11 @@ export function ChooseAmount({
65
107
  dispatch(setStep(step))
66
108
  }
67
109
 
68
- if (!lpConfig) {
69
- return <LoadingModal title='Supply' />
110
+ let info = `${formatNumber(maxAmountFormatted)} Available`
111
+ if (campaign && campaignPoints > 0) {
112
+ info = `You will earn ${formatNumber(
113
+ campaignPoints,
114
+ )} points for the entire ${lockupPeriodMonths} months right away.`
70
115
  }
71
116
 
72
117
  return (
@@ -79,7 +124,7 @@ export function ChooseAmount({
79
124
  currentAmount={currentAmount}
80
125
  handleChangeAmount={handleChangeAmount}
81
126
  maxAmount={maxAmountFormatted}
82
- info={`${formatNumber(maxAmountFormatted)} Available`}
127
+ info={info}
83
128
  handleAction={handleAction}
84
129
  actionText='SUPPLY'
85
130
  />
@@ -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
- const setupNotificationsOrClose = useCallback(() => {
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
- }, [dispatch, handleAction, isFirstTimeNotifiUser, notifiChainSupported])
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={setupNotificationsOrClose}
116
+ handleAction={handleUserAction}
75
117
  content={content}
76
- buttonText={hasNextStep ? "WHAT'S NEXT" : undefined}
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({ handleAction }: Props): React.ReactElement {
9
- return <NotifiSubscriptionModal handleSuccess={handleAction} />
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,219 @@
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
+ handleAction: () => void
31
+ }
32
+
33
+ export function PointsEarned({
34
+ transactionHash,
35
+ lpConfig,
36
+ handleAction,
37
+ }: Props): React.ReactElement {
38
+ const theme = useTheme()
39
+ const isDev = checkIsDev()
40
+ const dispatch = useDispatch()
41
+ const { account, chainId } = useWeb3React()
42
+ const [pointsAccumulated, setPointsAccumulated] = useState<
43
+ number | undefined
44
+ >()
45
+ const lockupMonths = Math.round(lpConfig.withdrawalLockoutPeriodInDays / 30)
46
+ const monthText =
47
+ lockupMonths > 1 ? `${lockupMonths} months` : `${lockupMonths} month`
48
+
49
+ const {
50
+ errorType,
51
+ setError: setAuthError,
52
+ isWalletOwnershipVerified,
53
+ isWalletOwnershipVerificationRequired,
54
+ } = useAuthErrorHandling(isDev)
55
+ const [walletOwnership, setWalletOwnership] = useState<boolean | undefined>()
56
+ const [state, setState] = useState<STATE>(STATE.Loading)
57
+
58
+ useEffect(() => {
59
+ if (isWalletOwnershipVerificationRequired) {
60
+ setState(STATE.Loading)
61
+ }
62
+ }, [isWalletOwnershipVerificationRequired])
63
+
64
+ useEffect(() => {
65
+ if (isWalletOwnershipVerified) {
66
+ setWalletOwnership(true)
67
+ }
68
+ }, [isWalletOwnershipVerified])
69
+
70
+ useEffect(() => {
71
+ const checkWalletOwnership = async () => {
72
+ const ownership = await CampaignService.checkWalletOwnership(
73
+ account!,
74
+ isDev,
75
+ )
76
+ setWalletOwnership(ownership)
77
+ if (!ownership) {
78
+ setAuthError('WalletNotSignInException')
79
+ }
80
+ }
81
+ checkWalletOwnership()
82
+ }, [account, isDev, setAuthError])
83
+
84
+ useEffect(() => {
85
+ if (errorType === 'NotSignedIn') {
86
+ setState(STATE.SignIn)
87
+ } else if (errorType === 'UserRejected') {
88
+ dispatch(
89
+ setError({
90
+ errorMessage: 'User has rejected the transaction.',
91
+ }),
92
+ )
93
+ } else if (errorType === 'Other') {
94
+ dispatch(
95
+ setError({
96
+ errorMessage: ERROR_MESSAGE,
97
+ }),
98
+ )
99
+ }
100
+ }, [dispatch, errorType])
101
+
102
+ useEffect(() => {
103
+ const updateWalletPoints = async () => {
104
+ if (walletOwnership) {
105
+ try {
106
+ const result = await CampaignService.updateWalletPoints(
107
+ chainId!,
108
+ account!,
109
+ transactionHash,
110
+ isDev,
111
+ )
112
+ if (!result.pointsAccumulated) {
113
+ dispatch(
114
+ setError({
115
+ errorMessage: ERROR_MESSAGE,
116
+ }),
117
+ )
118
+ }
119
+ setPointsAccumulated(result.pointsAccumulated)
120
+ setState(STATE.Congrats)
121
+ } catch (error) {
122
+ dispatch(
123
+ setError({
124
+ errorMessage: ERROR_MESSAGE,
125
+ }),
126
+ )
127
+ }
128
+ }
129
+ }
130
+ updateWalletPoints()
131
+ }, [account, chainId, dispatch, isDev, transactionHash, walletOwnership])
132
+
133
+ const styles = {
134
+ wrapper: css`
135
+ height: 518px;
136
+ position: relative;
137
+ `,
138
+ congrats: css`
139
+ margin: ${theme.spacing(-4, -4.5, 0, -4.5)};
140
+ `,
141
+ ribbon: css`
142
+ position: relative;
143
+ ${theme.cssMixins.rowHCentered};
144
+ font-weight: 700;
145
+ margin-top: ${theme.spacing(-8)};
146
+ color: ${theme.palette.text.primary};
147
+ font-size: 20px;
148
+ line-height: 160%;
149
+ letter-spacing: 0.15px;
150
+ `,
151
+ ribbonContent: css`
152
+ ${theme.cssMixins.rowVCentered};
153
+ position: absolute;
154
+ top: ${theme.spacing(1)};
155
+
156
+ svg {
157
+ margin-right: ${theme.spacing(1)};
158
+ }
159
+ `,
160
+ entirePoints: css`
161
+ color: ${theme.palette.text.tertiary};
162
+ text-align: center;
163
+ font-weight: 700;
164
+ font-size: 20px;
165
+ line-height: 160%;
166
+ letter-spacing: 0.15px;
167
+ margin-top: ${theme.spacing(7)};
168
+ `,
169
+ entirePointsDetails: css`
170
+ color: ${theme.palette.text.tertiary};
171
+ text-align: center;
172
+ font-weight: 400;
173
+ font-size: 16px;
174
+ line-height: 150%;
175
+ letter-spacing: 0.15px;
176
+ margin-top: ${theme.spacing(4)};
177
+ `,
178
+ everyday: css`
179
+ font-weight: 700;
180
+ `,
181
+ }
182
+
183
+ if (state === STATE.SignIn) {
184
+ return (
185
+ <SignIn description='Please sign in to check the points that you earned.' />
186
+ )
187
+ }
188
+
189
+ if (state === STATE.Congrats) {
190
+ return (
191
+ <Box css={styles.wrapper}>
192
+ <Box css={styles.congrats}>
193
+ <CongratulationsIcon />
194
+ </Box>
195
+ <Box css={styles.ribbon}>
196
+ <RibbonIcon />
197
+ <Box css={styles.ribbonContent}>
198
+ <HumaPointsIcon />
199
+ <Box>{formatNumber(pointsAccumulated)} Points</Box>
200
+ </Box>
201
+ </Box>
202
+ <Box css={styles.entirePoints}>
203
+ <Box>Congratulations,</Box>
204
+ <Box>you've earned {pointsAccumulated} points</Box>
205
+ </Box>
206
+ <Box css={styles.entirePointsDetails}>
207
+ You'll earn points <span css={styles.everyday}>everyday</span> for{' '}
208
+ {monthText} straight. Plus, If you keep your investment till after{' '}
209
+ {monthText}, you’ll gain extra points daily.
210
+ </Box>
211
+ <BottomButton variant='contained' onClick={handleAction}>
212
+ GREAT
213
+ </BottomButton>
214
+ </Box>
215
+ )
216
+ }
217
+
218
+ return <LoadingModal title='SUPPLY' />
219
+ }