@huma-finance/widgets 0.0.62-beta.620 → 0.0.62-beta.622

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@huma-finance/widgets",
3
- "version": "0.0.62-beta.620+c0e0d29",
3
+ "version": "0.0.62-beta.622+137e1dc",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -28,9 +28,9 @@
28
28
  "@ethersproject/experimental": "^5.7.0",
29
29
  "@ethersproject/providers": "^5.6.0",
30
30
  "@ethersproject/units": "^5.6.0",
31
- "@huma-finance/sdk": "^0.0.61",
32
- "@huma-finance/shared": "^0.0.61",
33
- "@huma-finance/web-shared": "^0.0.62-beta.620+c0e0d29",
31
+ "@huma-finance/sdk": "^0.0.62-beta.622+137e1dc",
32
+ "@huma-finance/shared": "^0.0.62-beta.622+137e1dc",
33
+ "@huma-finance/web-shared": "^0.0.61",
34
34
  "@notifi-network/notifi-frontend-client": "^0.91.1",
35
35
  "@reduxjs/toolkit": "^1.8.6",
36
36
  "@types/utf8": "^3.0.1",
@@ -200,5 +200,5 @@
200
200
  "optionalDependencies": {
201
201
  "encoding": "^0.1.13"
202
202
  },
203
- "gitHead": "c0e0d29e4570dd75f346f1b8a61dcb7abf174df2"
203
+ "gitHead": "137e1dc3d62ae552c1f93c6c489440ccc0e569d7"
204
204
  }
@@ -24,11 +24,13 @@ import { Transfer } from './3-Transfer'
24
24
  * @typedef {Object} SolanaLendAddRedemptionProps
25
25
  * @property {SolanaPoolInfo} poolInfo The metadata of the pool.
26
26
  * @property {SolanaPoolState} poolState The current state config of the pool. * @property {function():void} handleClose Function to notify to close the widget modal when user clicks the 'x' close button.
27
+ * @property {POOL_NTrancheTypeAME} tranche The tranche type.
27
28
  * @property {function():void|undefined} handleSuccess Optional function to notify that the lending pool supply action is successful.
28
29
  */
29
30
  export interface SolanaLendAddRedemptionProps {
30
31
  poolInfo: SolanaPoolInfo
31
32
  poolState: SolanaPoolState
33
+ tranche?: TrancheType
32
34
  handleClose: () => void
33
35
  handleSuccess?: () => void
34
36
  }
@@ -36,6 +38,7 @@ export interface SolanaLendAddRedemptionProps {
36
38
  export function SolanaLendAddRedemption({
37
39
  poolInfo,
38
40
  poolState,
41
+ tranche,
39
42
  handleClose,
40
43
  handleSuccess,
41
44
  }: SolanaLendAddRedemptionProps): React.ReactElement | null {
@@ -51,7 +54,9 @@ export function SolanaLendAddRedemption({
51
54
  loading: isLoadingTokenAccounts,
52
55
  } = useTrancheTokenAccounts(poolInfo)
53
56
  const { step, errorMessage } = useAppSelector(selectWidgetState)
54
- const [selectedTranche, setSelectedTranche] = useState<TrancheType>()
57
+ const [selectedTranche, setSelectedTranche] = useState<
58
+ TrancheType | undefined
59
+ >(tranche)
55
60
 
56
61
  useEffect(() => {
57
62
  if (!step && !isLoadingLenderAccounts && !isLoadingTokenAccounts) {
@@ -62,6 +67,11 @@ export function SolanaLendAddRedemption({
62
67
  juniorTokenAccount?.amount?.toString() ?? 0,
63
68
  )
64
69
 
70
+ if (selectedTranche) {
71
+ dispatch(setStep(WIDGET_STEP.ChooseAmount))
72
+ return
73
+ }
74
+
65
75
  if (juniorTrancheShares.gtn(0) && seniorTrancheShares.lten(0)) {
66
76
  setSelectedTranche('junior')
67
77
  dispatch(setStep(WIDGET_STEP.ChooseAmount))
@@ -85,6 +95,7 @@ export function SolanaLendAddRedemption({
85
95
  isLoadingTokenAccounts,
86
96
  seniorTokenAccount?.amount,
87
97
  juniorTokenAccount?.amount,
98
+ selectedTranche,
88
99
  ])
89
100
 
90
101
  const title = 'Redemption'
@@ -0,0 +1,106 @@
1
+ import {
2
+ checkIsDev,
3
+ IdentityServiceV2,
4
+ SolanaPoolInfo,
5
+ } from '@huma-finance/shared'
6
+ import { Box, css, useTheme } from '@mui/material'
7
+ import { useWallet } from '@solana/wallet-adapter-react'
8
+ import React, { useState } from 'react'
9
+
10
+ import { useAppDispatch } from '../../../hooks/useRedux'
11
+ import { setError, setStep } from '../../../store/widgets.reducers'
12
+ import { WIDGET_STEP } from '../../../store/widgets.store'
13
+ import { CustomError } from '../../../utilTypes'
14
+ import { BottomButton } from '../../BottomButton'
15
+ import { ApproveLenderImg } from '../../images'
16
+ import { LoadingModal } from '../../LoadingModal'
17
+ import { WrapperModal } from '../../WrapperModal'
18
+
19
+ type Props = {
20
+ poolInfo: SolanaPoolInfo
21
+ isUniTranche?: boolean
22
+ handleApproveSuccess: () => void
23
+ }
24
+
25
+ export function Evaluation({
26
+ poolInfo,
27
+ isUniTranche,
28
+ handleApproveSuccess,
29
+ }: Props): React.ReactElement | null {
30
+ const theme = useTheme()
31
+ const isDev = checkIsDev()
32
+ const dispatch = useAppDispatch()
33
+ const { publicKey } = useWallet()
34
+ const [loading, setLoading] = useState(false)
35
+
36
+ const styles = {
37
+ iconWrapper: css`
38
+ ${theme.cssMixins.rowCentered};
39
+ margin-top: ${theme.spacing(8)};
40
+ & > img {
41
+ width: 144px;
42
+ }
43
+ `,
44
+ description: css`
45
+ ${theme.cssMixins.rowCentered};
46
+ margin-top: ${theme.spacing(10)};
47
+ padding: ${theme.spacing(0, 2)};
48
+ font-weight: 400;
49
+ font-size: 16px;
50
+ color: ${theme.palette.text.secondary};
51
+ `,
52
+ }
53
+
54
+ const approveLender = async () => {
55
+ if (publicKey) {
56
+ try {
57
+ setLoading(true)
58
+ await IdentityServiceV2.approveSolanaLender(
59
+ publicKey.toString(),
60
+ poolInfo.chainId,
61
+ poolInfo.juniorTrancheMint,
62
+ isDev,
63
+ )
64
+ if (!isUniTranche) {
65
+ await IdentityServiceV2.approveSolanaLender(
66
+ publicKey.toString(),
67
+ poolInfo.chainId,
68
+ poolInfo.seniorTrancheMint,
69
+ isDev,
70
+ )
71
+ }
72
+ handleApproveSuccess()
73
+ setLoading(false)
74
+ dispatch(setStep(WIDGET_STEP.ChooseTranche))
75
+ } catch (e: unknown) {
76
+ const error = e as CustomError
77
+ setLoading(false)
78
+ dispatch(setError({ errorMessage: error.message }))
79
+ }
80
+ }
81
+ }
82
+
83
+ if (!loading) {
84
+ return (
85
+ <WrapperModal
86
+ title='Lender Approval'
87
+ subTitle='This pool requires lender approval'
88
+ >
89
+ <Box css={styles.iconWrapper}>
90
+ <img src={ApproveLenderImg} alt='approve-lender' />
91
+ </Box>
92
+ <Box css={styles.description} />
93
+ <BottomButton variant='contained' onClick={approveLender}>
94
+ GET APPROVED
95
+ </BottomButton>
96
+ </WrapperModal>
97
+ )
98
+ }
99
+
100
+ return (
101
+ <LoadingModal
102
+ title='Approval Pending'
103
+ description='Waiting for approval confirmation...'
104
+ />
105
+ )
106
+ }
@@ -16,7 +16,7 @@ import { InputAmountModal } from '../../InputAmountModal'
16
16
  type Props = {
17
17
  poolInfo: SolanaPoolInfo
18
18
  poolState: SolanaPoolState
19
- tokenAccount: Account
19
+ tokenAccount?: Account
20
20
  selectedTranche: TrancheType | undefined
21
21
  isUniTranche?: boolean
22
22
  }
@@ -31,10 +31,9 @@ export function ChooseAmount({
31
31
  const dispatch = useAppDispatch()
32
32
  const { symbol, decimals } = poolInfo.underlyingMint
33
33
  const [currentAmount, setCurrentAmount] = useState<number | string>(0)
34
- const balance = useMemo(
35
- () => new BN(tokenAccount.amount.toString()),
36
- [tokenAccount.amount],
37
- )
34
+ const balance = tokenAccount
35
+ ? new BN(tokenAccount.amount.toString())
36
+ : new BN(0)
38
37
 
39
38
  const { juniorAvailableCapBN, seniorAvailableCapBN } = useMemo(() => {
40
39
  const {
@@ -4,17 +4,18 @@ import {
4
4
  useLenderAccounts,
5
5
  useTokenAccount,
6
6
  } from '@huma-finance/web-shared'
7
- import React, { useEffect, useState } from 'react'
7
+ import React, { useCallback, useEffect, useState } from 'react'
8
8
  import { useDispatch } from 'react-redux'
9
9
 
10
10
  import { useAppSelector } from '../../../hooks/useRedux'
11
+ import { setStep } from '../../../store/widgets.reducers'
11
12
  import { selectWidgetState } from '../../../store/widgets.selectors'
12
- import { WidgetWrapper } from '../../WidgetWrapper'
13
13
  import { WIDGET_STEP } from '../../../store/widgets.store'
14
- import { ChooseTranche } from './1-ChooseTranche'
15
- import { ChooseAmount } from './3-ChooseAmount'
16
- import { setStep } from '../../../store/widgets.reducers'
17
14
  import { ErrorModal } from '../../ErrorModal'
15
+ import { WidgetWrapper } from '../../WidgetWrapper'
16
+ import { Evaluation } from './1-Evaluation'
17
+ import { ChooseTranche } from './2-ChooseTranche'
18
+ import { ChooseAmount } from './3-ChooseAmount'
18
19
  import { Transfer } from './4-Transfer'
19
20
  import { Success } from './5-Success'
20
21
 
@@ -45,6 +46,7 @@ export function SolanaLendSupply({
45
46
  seniorLenderApproved,
46
47
  juniorLenderApproved,
47
48
  loading: isLoadingLenderAccounts,
49
+ refresh: refreshLenderAccounts,
48
50
  } = useLenderAccounts(poolInfo.chainId, poolInfo.poolName)
49
51
  const [tokenAccount, isLoadingTokenAccount] = useTokenAccount(poolInfo)
50
52
  const { step, errorMessage } = useAppSelector(selectWidgetState)
@@ -52,6 +54,11 @@ export function SolanaLendSupply({
52
54
 
53
55
  useEffect(() => {
54
56
  if (!step && !isLoadingLenderAccounts && !isLoadingTokenAccount) {
57
+ if (!juniorLenderApproved && !seniorLenderApproved) {
58
+ dispatch(setStep(WIDGET_STEP.Evaluation))
59
+ return
60
+ }
61
+
55
62
  if (juniorLenderApproved && !seniorLenderApproved) {
56
63
  setSelectedTranche('junior')
57
64
  dispatch(setStep(WIDGET_STEP.ChooseAmount))
@@ -66,13 +73,7 @@ export function SolanaLendSupply({
66
73
 
67
74
  if (juniorLenderApproved && seniorLenderApproved) {
68
75
  dispatch(setStep(WIDGET_STEP.ChooseTranche))
69
- // return
70
76
  }
71
-
72
- // if (poolInfo.supplyLink) {
73
- // openInNewTab(poolInfo.supplyLink)
74
- // handleClose()
75
- // }
76
77
  }
77
78
  }, [
78
79
  dispatch,
@@ -85,6 +86,10 @@ export function SolanaLendSupply({
85
86
  isLoadingTokenAccount,
86
87
  ])
87
88
 
89
+ const handleApproveSuccess = useCallback(() => {
90
+ refreshLenderAccounts()
91
+ }, [refreshLenderAccounts])
92
+
88
93
  if (isLoadingLenderAccounts || isLoadingTokenAccount) {
89
94
  return (
90
95
  <WidgetWrapper
@@ -104,6 +109,13 @@ export function SolanaLendSupply({
104
109
  handleClose={handleClose}
105
110
  handleSuccess={handleSuccess}
106
111
  >
112
+ {step === WIDGET_STEP.Evaluation && (
113
+ <Evaluation
114
+ poolInfo={poolInfo}
115
+ isUniTranche={isUniTranche}
116
+ handleApproveSuccess={handleApproveSuccess}
117
+ />
118
+ )}
107
119
  {step === WIDGET_STEP.ChooseTranche && (
108
120
  <ChooseTranche
109
121
  poolUnderlyingToken={poolInfo.underlyingMint}
@@ -115,7 +127,7 @@ export function SolanaLendSupply({
115
127
  <ChooseAmount
116
128
  poolInfo={poolInfo}
117
129
  poolState={poolState}
118
- tokenAccount={tokenAccount!}
130
+ tokenAccount={tokenAccount}
119
131
  selectedTranche={selectedTranche}
120
132
  isUniTranche={isUniTranche}
121
133
  />
@@ -61,9 +61,14 @@ export function SolanaTxDoneModal({
61
61
  width: 100%;
62
62
  position: absolute;
63
63
  bottom: 0;
64
- `,
65
- bottomButton: css`
66
- margin-top: ${theme.spacing(1)};
64
+ display: flex;
65
+ row-gap: ${theme.spacing(1)};
66
+ column-gap: ${theme.spacing(1)};
67
+
68
+ button {
69
+ height: 40px;
70
+ margin-top: ${theme.spacing(1)};
71
+ }
67
72
  `,
68
73
  }
69
74
 
@@ -104,7 +109,6 @@ export function SolanaTxDoneModal({
104
109
  className='transaction-done-modal-close-btn'
105
110
  variant='contained'
106
111
  fullWidth
107
- css={styles.bottomButton}
108
112
  onClick={handleCloseModal}
109
113
  >
110
114
  {!buttonText ? 'DONE' : buttonText}
File without changes