@huma-finance/widgets 0.0.62-beta.635 → 0.0.62-beta.637
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 +332 -151
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/index.js +334 -153
- package/dist/index.js.map +1 -1
- package/package.json +5 -5
- package/src/components/CreditLine/solanaBorrow/2-Transfer.tsx +9 -9
- package/src/components/CreditLine/solanaPayment/2-Transfer.tsx +5 -5
- package/src/components/Lend/components/PersonaEvaluation.tsx +5 -0
- package/src/components/Lend/solanaAddRedemption/3-Transfer.tsx +3 -3
- package/src/components/Lend/solanaCancelRedemption/2-Transfer.tsx +1 -1
- package/src/components/Lend/solanaSupply/1-Evaluation.tsx +12 -1
- package/src/components/Lend/solanaSupply/4-Transfer.tsx +13 -9
- 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.637+9f3e124",
|
|
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.637+9f3e124",
|
|
33
|
+
"@huma-finance/shared": "^0.0.62-beta.637+9f3e124",
|
|
34
|
+
"@huma-finance/web-shared": "^0.0.62-beta.637+9f3e124",
|
|
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": "9f3e124976998f1d4f21c4db656acbe747756c17"
|
|
211
211
|
}
|
|
@@ -7,24 +7,24 @@ import {
|
|
|
7
7
|
} from '@huma-finance/shared'
|
|
8
8
|
import React, { useCallback, useEffect, useState } from 'react'
|
|
9
9
|
|
|
10
|
+
import { BN } from '@coral-xyz/anchor'
|
|
11
|
+
import { useHumaProgram } from '@huma-finance/web-shared'
|
|
10
12
|
import {
|
|
11
13
|
ASSOCIATED_TOKEN_PROGRAM_ID,
|
|
12
14
|
createApproveCheckedInstruction,
|
|
13
15
|
createAssociatedTokenAccountInstruction,
|
|
14
16
|
getAccount,
|
|
15
|
-
|
|
17
|
+
TOKEN_PROGRAM_ID,
|
|
16
18
|
TokenAccountNotFoundError,
|
|
17
19
|
TokenInvalidAccountOwnerError,
|
|
18
20
|
} from '@solana/spl-token'
|
|
19
21
|
import { useConnection, useWallet } from '@solana/wallet-adapter-react'
|
|
20
22
|
import { PublicKey, Transaction } from '@solana/web3.js'
|
|
21
|
-
import { useHumaProgram } from '@huma-finance/web-shared'
|
|
22
|
-
import { BN } from '@coral-xyz/anchor'
|
|
23
23
|
import { useAppDispatch, useAppSelector } from '../../../hooks/useRedux'
|
|
24
|
-
import { SolanaTxSendModal } from '../../SolanaTxSendModal'
|
|
25
24
|
import { setStep } from '../../../store/widgets.reducers'
|
|
26
|
-
import { WIDGET_STEP } from '../../../store/widgets.store'
|
|
27
25
|
import { selectWidgetState } from '../../../store/widgets.selectors'
|
|
26
|
+
import { WIDGET_STEP } from '../../../store/widgets.store'
|
|
27
|
+
import { SolanaTxSendModal } from '../../SolanaTxSendModal'
|
|
28
28
|
|
|
29
29
|
type Props = {
|
|
30
30
|
poolInfo: SolanaPoolInfo
|
|
@@ -60,7 +60,7 @@ export function Transfer({ poolInfo }: Props): React.ReactElement | null {
|
|
|
60
60
|
connection,
|
|
61
61
|
underlyingTokenATA,
|
|
62
62
|
undefined,
|
|
63
|
-
|
|
63
|
+
TOKEN_PROGRAM_ID,
|
|
64
64
|
)
|
|
65
65
|
} catch (error: unknown) {
|
|
66
66
|
// TokenAccountNotFoundError can be possible if the associated address has already received some lamports,
|
|
@@ -77,7 +77,7 @@ export function Transfer({ poolInfo }: Props): React.ReactElement | null {
|
|
|
77
77
|
underlyingTokenATA,
|
|
78
78
|
publicKey,
|
|
79
79
|
new PublicKey(poolInfo.underlyingMint.address),
|
|
80
|
-
|
|
80
|
+
TOKEN_PROGRAM_ID,
|
|
81
81
|
ASSOCIATED_TOKEN_PROGRAM_ID,
|
|
82
82
|
),
|
|
83
83
|
)
|
|
@@ -105,7 +105,7 @@ export function Transfer({ poolInfo }: Props): React.ReactElement | null {
|
|
|
105
105
|
), // amount
|
|
106
106
|
poolInfo.underlyingMint.decimals,
|
|
107
107
|
undefined, // multiSigners
|
|
108
|
-
|
|
108
|
+
TOKEN_PROGRAM_ID,
|
|
109
109
|
),
|
|
110
110
|
)
|
|
111
111
|
}
|
|
@@ -128,7 +128,7 @@ export function Transfer({ poolInfo }: Props): React.ReactElement | null {
|
|
|
128
128
|
underlyingMint: poolInfo.underlyingMint.address,
|
|
129
129
|
poolUnderlyingToken: poolInfo.poolUnderlyingTokenAccount,
|
|
130
130
|
borrowerUnderlyingToken: underlyingTokenATA,
|
|
131
|
-
tokenProgram:
|
|
131
|
+
tokenProgram: TOKEN_PROGRAM_ID,
|
|
132
132
|
})
|
|
133
133
|
.transaction()
|
|
134
134
|
tx.add(programTx)
|
|
@@ -6,15 +6,15 @@ import {
|
|
|
6
6
|
} from '@huma-finance/shared'
|
|
7
7
|
import React, { useCallback, useEffect, useState } from 'react'
|
|
8
8
|
|
|
9
|
-
import {
|
|
9
|
+
import { useHumaProgram } from '@huma-finance/web-shared'
|
|
10
|
+
import { TOKEN_PROGRAM_ID } from '@solana/spl-token'
|
|
10
11
|
import { useConnection, useWallet } from '@solana/wallet-adapter-react'
|
|
11
12
|
import { Transaction } from '@solana/web3.js'
|
|
12
|
-
import { useHumaProgram } from '@huma-finance/web-shared'
|
|
13
13
|
import { useAppDispatch, useAppSelector } from '../../../hooks/useRedux'
|
|
14
|
-
import { SolanaTxSendModal } from '../../SolanaTxSendModal'
|
|
15
14
|
import { setStep } from '../../../store/widgets.reducers'
|
|
16
|
-
import { WIDGET_STEP } from '../../../store/widgets.store'
|
|
17
15
|
import { selectWidgetState } from '../../../store/widgets.selectors'
|
|
16
|
+
import { WIDGET_STEP } from '../../../store/widgets.store'
|
|
17
|
+
import { SolanaTxSendModal } from '../../SolanaTxSendModal'
|
|
18
18
|
|
|
19
19
|
type Props = {
|
|
20
20
|
poolInfo: SolanaPoolInfo
|
|
@@ -62,7 +62,7 @@ export function Transfer({ poolInfo }: Props): React.ReactElement | null {
|
|
|
62
62
|
underlyingMint: poolInfo.underlyingMint.address,
|
|
63
63
|
poolUnderlyingToken: poolInfo.poolUnderlyingTokenAccount,
|
|
64
64
|
borrowerUnderlyingToken: underlyingTokenATA,
|
|
65
|
-
tokenProgram:
|
|
65
|
+
tokenProgram: TOKEN_PROGRAM_ID,
|
|
66
66
|
})
|
|
67
67
|
.transaction()
|
|
68
68
|
|
|
@@ -36,6 +36,7 @@ type Props = {
|
|
|
36
36
|
isUniTranche: boolean
|
|
37
37
|
pointsTestnetExperience: boolean
|
|
38
38
|
campaign?: Campaign
|
|
39
|
+
chainSpecificData?: Record<string, unknown>
|
|
39
40
|
changeTranche: (tranche: TrancheType) => void
|
|
40
41
|
handleClose: (identityStatus?: IdentityVerificationStatusV2) => void
|
|
41
42
|
}
|
|
@@ -46,6 +47,7 @@ export function PersonaEvaluation({
|
|
|
46
47
|
campaign,
|
|
47
48
|
pointsTestnetExperience,
|
|
48
49
|
chainType,
|
|
50
|
+
chainSpecificData,
|
|
49
51
|
changeTranche,
|
|
50
52
|
handleClose,
|
|
51
53
|
}: Props): React.ReactElement | null {
|
|
@@ -101,6 +103,7 @@ export function PersonaEvaluation({
|
|
|
101
103
|
chainId!,
|
|
102
104
|
poolInfo.juniorTrancheVault,
|
|
103
105
|
isDev,
|
|
106
|
+
chainSpecificData,
|
|
104
107
|
)
|
|
105
108
|
if (!isUniTranche) {
|
|
106
109
|
await IdentityServiceV2.approveLender(
|
|
@@ -108,6 +111,7 @@ export function PersonaEvaluation({
|
|
|
108
111
|
chainId!,
|
|
109
112
|
poolInfo.seniorTrancheVault,
|
|
110
113
|
isDev,
|
|
114
|
+
chainSpecificData,
|
|
111
115
|
)
|
|
112
116
|
}
|
|
113
117
|
if (isUniTranche) {
|
|
@@ -123,6 +127,7 @@ export function PersonaEvaluation({
|
|
|
123
127
|
}, [
|
|
124
128
|
account,
|
|
125
129
|
chainId,
|
|
130
|
+
chainSpecificData,
|
|
126
131
|
changeTranche,
|
|
127
132
|
dispatch,
|
|
128
133
|
isDev,
|
|
@@ -6,17 +6,17 @@ import {
|
|
|
6
6
|
} from '@huma-finance/shared'
|
|
7
7
|
import React, { useCallback, useEffect, useMemo, useState } from 'react'
|
|
8
8
|
|
|
9
|
-
import { TOKEN_2022_PROGRAM_ID } from '@solana/spl-token'
|
|
10
|
-
import { useWallet } from '@solana/wallet-adapter-react'
|
|
11
9
|
import {
|
|
12
10
|
useHumaProgram,
|
|
13
11
|
useTrancheMintAccounts,
|
|
14
12
|
} from '@huma-finance/web-shared'
|
|
13
|
+
import { TOKEN_2022_PROGRAM_ID } from '@solana/spl-token'
|
|
14
|
+
import { useWallet } from '@solana/wallet-adapter-react'
|
|
15
15
|
import { Transaction } from '@solana/web3.js'
|
|
16
16
|
import { useAppDispatch, useAppSelector } from '../../../hooks/useRedux'
|
|
17
17
|
import { setStep } from '../../../store/widgets.reducers'
|
|
18
|
-
import { WIDGET_STEP } from '../../../store/widgets.store'
|
|
19
18
|
import { selectWidgetState } from '../../../store/widgets.selectors'
|
|
19
|
+
import { WIDGET_STEP } from '../../../store/widgets.store'
|
|
20
20
|
import { SolanaTxSendModal } from '../../SolanaTxSendModal'
|
|
21
21
|
|
|
22
22
|
type Props = {
|
|
@@ -5,9 +5,9 @@ import {
|
|
|
5
5
|
} from '@huma-finance/shared'
|
|
6
6
|
import React, { useCallback, useEffect, useState } from 'react'
|
|
7
7
|
|
|
8
|
+
import { LenderStateAccount, useHumaProgram } from '@huma-finance/web-shared'
|
|
8
9
|
import { TOKEN_2022_PROGRAM_ID } from '@solana/spl-token'
|
|
9
10
|
import { useWallet } from '@solana/wallet-adapter-react'
|
|
10
|
-
import { LenderStateAccount, useHumaProgram } from '@huma-finance/web-shared'
|
|
11
11
|
import { Transaction } from '@solana/web3.js'
|
|
12
12
|
import { useAppDispatch } from '../../../hooks/useRedux'
|
|
13
13
|
import { setStep } from '../../../store/widgets.reducers'
|
|
@@ -1,4 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
CHAIN_TYPE,
|
|
3
|
+
SOLANA_CHAIN_INFO,
|
|
4
|
+
SolanaPoolInfo,
|
|
5
|
+
TrancheType,
|
|
6
|
+
} from '@huma-finance/shared'
|
|
2
7
|
import React from 'react'
|
|
3
8
|
|
|
4
9
|
import { PersonaEvaluation } from '../components/PersonaEvaluation'
|
|
@@ -22,6 +27,8 @@ export function Evaluation({
|
|
|
22
27
|
handleClose,
|
|
23
28
|
}: Props): React.ReactElement | null {
|
|
24
29
|
if (poolInfo.KYC?.Persona) {
|
|
30
|
+
const solanChainInfo = SOLANA_CHAIN_INFO[poolInfo.chainId]
|
|
31
|
+
|
|
25
32
|
return (
|
|
26
33
|
<PersonaEvaluation
|
|
27
34
|
poolInfo={{
|
|
@@ -33,6 +40,10 @@ export function Evaluation({
|
|
|
33
40
|
isUniTranche={isUniTranche}
|
|
34
41
|
pointsTestnetExperience={pointsTestnetExperience}
|
|
35
42
|
campaign={campaign}
|
|
43
|
+
chainSpecificData={{
|
|
44
|
+
huma_program_id: solanChainInfo.poolProgram,
|
|
45
|
+
pool_id: poolInfo.poolId,
|
|
46
|
+
}}
|
|
36
47
|
chainType={CHAIN_TYPE.SOLANA}
|
|
37
48
|
changeTranche={changeTranche}
|
|
38
49
|
/>
|
|
@@ -6,16 +6,16 @@ import {
|
|
|
6
6
|
} from '@huma-finance/shared'
|
|
7
7
|
import React, { useCallback, useEffect, useState } from 'react'
|
|
8
8
|
|
|
9
|
-
import { TOKEN_2022_PROGRAM_ID } from '@solana/spl-token'
|
|
10
|
-
import { useWallet } from '@solana/wallet-adapter-react'
|
|
11
9
|
import { useHumaProgram, useLenderAccounts } from '@huma-finance/web-shared'
|
|
10
|
+
import { TOKEN_2022_PROGRAM_ID, TOKEN_PROGRAM_ID } from '@solana/spl-token'
|
|
11
|
+
import { useWallet } from '@solana/wallet-adapter-react'
|
|
12
12
|
import { Transaction } from '@solana/web3.js'
|
|
13
13
|
import { useAppDispatch, useAppSelector } from '../../../hooks/useRedux'
|
|
14
14
|
import { setStep } from '../../../store/widgets.reducers'
|
|
15
|
-
import { WIDGET_STEP } from '../../../store/widgets.store'
|
|
16
15
|
import { selectWidgetState } from '../../../store/widgets.selectors'
|
|
17
|
-
import {
|
|
16
|
+
import { WIDGET_STEP } from '../../../store/widgets.store'
|
|
18
17
|
import { LoadingModal } from '../../LoadingModal'
|
|
18
|
+
import { SolanaTxSendModal } from '../../SolanaTxSendModal'
|
|
19
19
|
|
|
20
20
|
type Props = {
|
|
21
21
|
poolInfo: SolanaPoolInfo
|
|
@@ -58,6 +58,12 @@ export function Transfer({
|
|
|
58
58
|
|
|
59
59
|
const { underlyingTokenATA, seniorTrancheATA, juniorTrancheATA } =
|
|
60
60
|
getTokenAccounts(poolInfo, publicKey)
|
|
61
|
+
|
|
62
|
+
const approvedLender =
|
|
63
|
+
selectedTranche === 'senior'
|
|
64
|
+
? seniorLenderApprovedAccountPDA!
|
|
65
|
+
: juniorLenderApprovedAccountPDA!
|
|
66
|
+
|
|
61
67
|
if (
|
|
62
68
|
(selectedTranche === 'senior' && !seniorLenderStateAccount) ||
|
|
63
69
|
(selectedTranche === 'junior' && !juniorLenderStateAccount)
|
|
@@ -68,10 +74,7 @@ export function Transfer({
|
|
|
68
74
|
lender: publicKey,
|
|
69
75
|
humaConfig: poolInfo.humaConfig,
|
|
70
76
|
poolConfig: poolInfo.poolConfig,
|
|
71
|
-
approvedLender
|
|
72
|
-
selectedTranche === 'senior'
|
|
73
|
-
? seniorLenderApprovedAccountPDA!
|
|
74
|
-
: juniorLenderApprovedAccountPDA!,
|
|
77
|
+
approvedLender,
|
|
75
78
|
trancheMint:
|
|
76
79
|
selectedTranche === 'senior'
|
|
77
80
|
? poolInfo.seniorTrancheMint
|
|
@@ -89,6 +92,7 @@ export function Transfer({
|
|
|
89
92
|
const depositTx = await program.methods
|
|
90
93
|
.deposit(supplyBigNumber)
|
|
91
94
|
.accountsPartial({
|
|
95
|
+
approvedLender,
|
|
92
96
|
depositor: publicKey,
|
|
93
97
|
poolConfig: poolInfo.poolConfig,
|
|
94
98
|
underlyingMint: poolInfo.underlyingMint.address,
|
|
@@ -101,7 +105,7 @@ export function Transfer({
|
|
|
101
105
|
depositorTrancheToken:
|
|
102
106
|
selectedTranche === 'senior' ? seniorTrancheATA : juniorTrancheATA,
|
|
103
107
|
humaConfig: poolInfo.humaConfig,
|
|
104
|
-
|
|
108
|
+
underlyingTokenProgram: TOKEN_PROGRAM_ID,
|
|
105
109
|
})
|
|
106
110
|
.transaction()
|
|
107
111
|
tx.add(depositTx)
|
|
@@ -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()
|