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

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.621+60c42c2",
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.621+60c42c2",
32
+ "@huma-finance/shared": "^0.0.62-beta.621+60c42c2",
33
+ "@huma-finance/web-shared": "^0.0.62-beta.621+60c42c2",
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": "60c42c211d6cf4955f969c8aea9fbabd3ef09df4"
204
204
  }
@@ -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}
@@ -22,7 +22,7 @@ export function SolanaViewOnExplorer({
22
22
  }
23
23
 
24
24
  return (
25
- <Button fullWidth variant='outlined' onClick={() => openInNewTab(link)}>
25
+ <Button fullWidth variant='contained' onClick={() => openInNewTab(link)}>
26
26
  <Box component='span'>VIEW ON EXPLORER</Box>
27
27
  </Button>
28
28
  )
File without changes