@huma-finance/widgets 0.0.62-beta.611 → 0.0.62-beta.616
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/API.md +0 -185
- package/dist/cjs/index.cjs +481 -1661
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/index.d.ts +8 -116
- package/dist/index.js +484 -1661
- package/dist/index.js.map +1 -1
- package/package.json +9 -12
- package/src/components/InputAmountModal.tsx +2 -12
- package/src/components/Lend/addRedemptionV2/2-ChooseAmount.tsx +6 -1
- package/src/components/Lend/supplyV2/6-Success.tsx +10 -8
- package/src/components/Lend/supplyV2/7-Notifications.tsx +6 -1
- package/src/components/Notifi/NotifiContextWrapper.tsx +57 -0
- package/src/components/Notifi/NotifiSubscriptionModal.tsx +118 -113
- package/src/components/WidgetWrapper.tsx +4 -6
- package/src/hooks/useNotifi.ts +28 -17
- package/src/index.tsx +7 -124
- package/src/store/widgets.reducers.ts +0 -5
- package/src/store/widgets.store.ts +0 -1
- package/src/theme/coreThemeConstants.ts +1 -1
- package/src/components/CreditLine/solanaBorrow/1-ChooseAmount.tsx +0 -86
- package/src/components/CreditLine/solanaBorrow/2-ApproveAllowance.tsx +0 -87
- package/src/components/CreditLine/solanaBorrow/index.tsx +0 -96
- package/src/components/Lend/solanaAddRedemption/1-ChooseTranche.tsx +0 -114
- package/src/components/Lend/solanaAddRedemption/2-ChooseAmount.tsx +0 -183
- package/src/components/Lend/solanaAddRedemption/3-Transfer.tsx +0 -102
- package/src/components/Lend/solanaAddRedemption/4-Done.tsx +0 -29
- package/src/components/Lend/solanaAddRedemption/index.tsx +0 -140
- package/src/components/Lend/solanaCancelRedemption/1-ChooseTranche.tsx +0 -114
- package/src/components/Lend/solanaCancelRedemption/2-Transfer.tsx +0 -99
- package/src/components/Lend/solanaCancelRedemption/3-Done.tsx +0 -55
- package/src/components/Lend/solanaCancelRedemption/index.tsx +0 -152
- package/src/components/Lend/solanaSupply/1-ChooseTranche.tsx +0 -116
- package/src/components/Lend/solanaSupply/2-Evaluation.tsx +0 -0
- package/src/components/Lend/solanaSupply/3-ChooseAmount.tsx +0 -130
- package/src/components/Lend/solanaSupply/4-Transfer.tsx +0 -89
- package/src/components/Lend/solanaSupply/5-Success.tsx +0 -50
- package/src/components/Lend/solanaSupply/index.tsx +0 -143
- package/src/components/SolanaTxDoneModal.tsx +0 -115
- package/src/components/SolanaTxSendModal.tsx +0 -61
- package/src/components/SolanaViewOnExplorer.tsx +0 -29
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
formatNumber,
|
|
3
|
-
SolanaPoolInfo,
|
|
4
|
-
SolanaTokenUtils,
|
|
5
|
-
TrancheType,
|
|
6
|
-
} from '@huma-finance/shared'
|
|
7
|
-
import React from 'react'
|
|
8
|
-
|
|
9
|
-
import {
|
|
10
|
-
LenderStateAccount,
|
|
11
|
-
useTrancheMintAccounts,
|
|
12
|
-
} from '@huma-finance/web-shared'
|
|
13
|
-
import { SolanaTxDoneModal } from '../../SolanaTxDoneModal'
|
|
14
|
-
import { useAppSelector } from '../../../hooks/useRedux'
|
|
15
|
-
import { selectWidgetState } from '../../../store/widgets.selectors'
|
|
16
|
-
|
|
17
|
-
type Props = {
|
|
18
|
-
poolInfo: SolanaPoolInfo
|
|
19
|
-
lenderState: LenderStateAccount | null | undefined
|
|
20
|
-
selectedTranche: TrancheType
|
|
21
|
-
handleAction: () => void
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
export function Done({
|
|
25
|
-
poolInfo,
|
|
26
|
-
lenderState,
|
|
27
|
-
selectedTranche,
|
|
28
|
-
handleAction,
|
|
29
|
-
}: Props): React.ReactElement | null {
|
|
30
|
-
const { mintAccount, loading: isLoadingTrancheMintAccounts } =
|
|
31
|
-
useTrancheMintAccounts(poolInfo, selectedTranche)
|
|
32
|
-
const { solanaSignature } = useAppSelector(selectWidgetState)
|
|
33
|
-
|
|
34
|
-
const content =
|
|
35
|
-
!lenderState || isLoadingTrancheMintAccounts || !mintAccount
|
|
36
|
-
? ['']
|
|
37
|
-
: [
|
|
38
|
-
`Your request to cancel the redemption of ${formatNumber(
|
|
39
|
-
SolanaTokenUtils.formatUnits(
|
|
40
|
-
lenderState.redemptionRecord.numSharesRequested,
|
|
41
|
-
mintAccount.decimals,
|
|
42
|
-
),
|
|
43
|
-
)} shares has been successfully processed.`,
|
|
44
|
-
]
|
|
45
|
-
|
|
46
|
-
return (
|
|
47
|
-
<SolanaTxDoneModal
|
|
48
|
-
handleAction={handleAction}
|
|
49
|
-
content={content}
|
|
50
|
-
chainId={poolInfo.chainId}
|
|
51
|
-
solanaSignature={solanaSignature}
|
|
52
|
-
buttonText='DONE'
|
|
53
|
-
/>
|
|
54
|
-
)
|
|
55
|
-
}
|
|
@@ -1,152 +0,0 @@
|
|
|
1
|
-
import { SolanaPoolInfo, TrancheType } from '@huma-finance/shared'
|
|
2
|
-
import { useLenderAccounts } from '@huma-finance/web-shared'
|
|
3
|
-
import React, { useEffect, useState } from 'react'
|
|
4
|
-
import { useDispatch } from 'react-redux'
|
|
5
|
-
|
|
6
|
-
import { BN } from '@coral-xyz/anchor'
|
|
7
|
-
import { useAppSelector } from '../../../hooks/useRedux'
|
|
8
|
-
import { selectWidgetState } from '../../../store/widgets.selectors'
|
|
9
|
-
import { WidgetWrapper } from '../../WidgetWrapper'
|
|
10
|
-
import { WIDGET_STEP } from '../../../store/widgets.store'
|
|
11
|
-
import { setStep } from '../../../store/widgets.reducers'
|
|
12
|
-
import { ErrorModal } from '../../ErrorModal'
|
|
13
|
-
import { Transfer } from './2-Transfer'
|
|
14
|
-
import { ChooseTranche } from './1-ChooseTranche'
|
|
15
|
-
import { Done } from './3-Done'
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* Lend pool supply props
|
|
19
|
-
* @typedef {Object} SolanaLendCancelRedemptionProps
|
|
20
|
-
* @property {SolanaPoolInfo} poolInfo The metadata of the pool.
|
|
21
|
-
* @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.
|
|
22
|
-
* @property {function():void|undefined} handleSuccess Optional function to notify that the lending pool supply action is successful.
|
|
23
|
-
*/
|
|
24
|
-
export interface SolanaLendCancelRedemptionProps {
|
|
25
|
-
poolInfo: SolanaPoolInfo
|
|
26
|
-
handleClose: () => void
|
|
27
|
-
handleSuccess?: () => void
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
export function SolanaLendCancelRedemption({
|
|
31
|
-
poolInfo,
|
|
32
|
-
handleClose,
|
|
33
|
-
handleSuccess,
|
|
34
|
-
}: SolanaLendCancelRedemptionProps): React.ReactElement | null {
|
|
35
|
-
const dispatch = useDispatch()
|
|
36
|
-
const {
|
|
37
|
-
seniorLenderStateAccount,
|
|
38
|
-
juniorLenderStateAccount,
|
|
39
|
-
juniorLenderStateAccountPDA,
|
|
40
|
-
seniorLenderStateAccountPDA,
|
|
41
|
-
loading: isLoadingLenderAccounts,
|
|
42
|
-
} = useLenderAccounts(poolInfo.chainId, poolInfo.poolName)
|
|
43
|
-
const { step, errorMessage } = useAppSelector(selectWidgetState)
|
|
44
|
-
const [selectedTranche, setSelectedTranche] = useState<TrancheType>()
|
|
45
|
-
|
|
46
|
-
useEffect(() => {
|
|
47
|
-
if (!step && !isLoadingLenderAccounts) {
|
|
48
|
-
const seniorTrancheSharesRequested = new BN(
|
|
49
|
-
seniorLenderStateAccount?.redemptionRecord.numSharesRequested,
|
|
50
|
-
)
|
|
51
|
-
const juniorTrancheSharesRequested = new BN(
|
|
52
|
-
juniorLenderStateAccount?.redemptionRecord.numSharesRequested,
|
|
53
|
-
)
|
|
54
|
-
|
|
55
|
-
if (
|
|
56
|
-
juniorTrancheSharesRequested.gtn(0) &&
|
|
57
|
-
seniorTrancheSharesRequested.lten(0)
|
|
58
|
-
) {
|
|
59
|
-
setSelectedTranche('junior')
|
|
60
|
-
dispatch(setStep(WIDGET_STEP.Transfer))
|
|
61
|
-
return
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
if (
|
|
65
|
-
seniorTrancheSharesRequested.gtn(0) &&
|
|
66
|
-
juniorTrancheSharesRequested.lten(0)
|
|
67
|
-
) {
|
|
68
|
-
setSelectedTranche('senior')
|
|
69
|
-
dispatch(setStep(WIDGET_STEP.Transfer))
|
|
70
|
-
return
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
if (
|
|
74
|
-
seniorTrancheSharesRequested.gtn(0) &&
|
|
75
|
-
juniorTrancheSharesRequested.gtn(0)
|
|
76
|
-
) {
|
|
77
|
-
dispatch(setStep(WIDGET_STEP.ChooseTranche))
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
}, [
|
|
81
|
-
dispatch,
|
|
82
|
-
step,
|
|
83
|
-
isLoadingLenderAccounts,
|
|
84
|
-
seniorLenderStateAccount?.redemptionRecord.numSharesRequested,
|
|
85
|
-
juniorLenderStateAccount?.redemptionRecord.numSharesRequested,
|
|
86
|
-
])
|
|
87
|
-
|
|
88
|
-
const title = 'Cancel Redemption'
|
|
89
|
-
if (isLoadingLenderAccounts) {
|
|
90
|
-
return (
|
|
91
|
-
<WidgetWrapper
|
|
92
|
-
isOpen
|
|
93
|
-
isLoading
|
|
94
|
-
loadingTitle={title}
|
|
95
|
-
handleClose={handleClose}
|
|
96
|
-
handleSuccess={handleSuccess}
|
|
97
|
-
/>
|
|
98
|
-
)
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
return (
|
|
102
|
-
<WidgetWrapper
|
|
103
|
-
isOpen
|
|
104
|
-
loadingTitle={title}
|
|
105
|
-
handleClose={handleClose}
|
|
106
|
-
handleSuccess={handleSuccess}
|
|
107
|
-
>
|
|
108
|
-
{step === WIDGET_STEP.ChooseTranche && (
|
|
109
|
-
<ChooseTranche
|
|
110
|
-
selectedTranche={selectedTranche}
|
|
111
|
-
changeTranche={setSelectedTranche}
|
|
112
|
-
/>
|
|
113
|
-
)}
|
|
114
|
-
{step === WIDGET_STEP.Transfer && selectedTranche && (
|
|
115
|
-
<Transfer
|
|
116
|
-
poolInfo={poolInfo}
|
|
117
|
-
lenderState={
|
|
118
|
-
selectedTranche === 'senior'
|
|
119
|
-
? seniorLenderStateAccount
|
|
120
|
-
: juniorLenderStateAccount
|
|
121
|
-
}
|
|
122
|
-
lenderStatePDA={
|
|
123
|
-
selectedTranche === 'senior'
|
|
124
|
-
? seniorLenderStateAccountPDA
|
|
125
|
-
: juniorLenderStateAccountPDA
|
|
126
|
-
}
|
|
127
|
-
selectedTranche={selectedTranche}
|
|
128
|
-
/>
|
|
129
|
-
)}
|
|
130
|
-
{step === WIDGET_STEP.Done && selectedTranche && (
|
|
131
|
-
<Done
|
|
132
|
-
poolInfo={poolInfo}
|
|
133
|
-
lenderState={
|
|
134
|
-
selectedTranche === 'senior'
|
|
135
|
-
? seniorLenderStateAccount
|
|
136
|
-
: juniorLenderStateAccount
|
|
137
|
-
}
|
|
138
|
-
selectedTranche={selectedTranche}
|
|
139
|
-
handleAction={handleClose}
|
|
140
|
-
/>
|
|
141
|
-
)}
|
|
142
|
-
{step === WIDGET_STEP.Error && (
|
|
143
|
-
<ErrorModal
|
|
144
|
-
title={title}
|
|
145
|
-
errorReason='Sorry there was an error'
|
|
146
|
-
errorMessage={errorMessage}
|
|
147
|
-
handleOk={handleClose}
|
|
148
|
-
/>
|
|
149
|
-
)}
|
|
150
|
-
</WidgetWrapper>
|
|
151
|
-
)
|
|
152
|
-
}
|
|
@@ -1,116 +0,0 @@
|
|
|
1
|
-
import { TrancheType, UnderlyingTokenInfo } from '@huma-finance/shared'
|
|
2
|
-
import {
|
|
3
|
-
css,
|
|
4
|
-
FormControl,
|
|
5
|
-
FormControlLabel,
|
|
6
|
-
FormLabel,
|
|
7
|
-
Radio,
|
|
8
|
-
RadioGroup,
|
|
9
|
-
useTheme,
|
|
10
|
-
} from '@mui/material'
|
|
11
|
-
import React from 'react'
|
|
12
|
-
|
|
13
|
-
import { useAppDispatch } from '../../../hooks/useRedux'
|
|
14
|
-
import { setStep } from '../../../store/widgets.reducers'
|
|
15
|
-
import { WIDGET_STEP } from '../../../store/widgets.store'
|
|
16
|
-
import { BottomButton } from '../../BottomButton'
|
|
17
|
-
import { WrapperModal } from '../../WrapperModal'
|
|
18
|
-
|
|
19
|
-
type Props = {
|
|
20
|
-
poolUnderlyingToken: UnderlyingTokenInfo
|
|
21
|
-
selectedTranche: TrancheType | undefined
|
|
22
|
-
changeTranche: (tranche: TrancheType) => void
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
export function ChooseTranche({
|
|
26
|
-
poolUnderlyingToken,
|
|
27
|
-
selectedTranche,
|
|
28
|
-
changeTranche,
|
|
29
|
-
}: Props): React.ReactElement | null {
|
|
30
|
-
const theme = useTheme()
|
|
31
|
-
const dispatch = useAppDispatch()
|
|
32
|
-
|
|
33
|
-
const styles = {
|
|
34
|
-
subTitle: css`
|
|
35
|
-
color: ${theme.palette.text.primary} !important;
|
|
36
|
-
font-weight: 400;
|
|
37
|
-
font-size: 16px;
|
|
38
|
-
line-height: 150%;
|
|
39
|
-
letter-spacing: 0.15px;
|
|
40
|
-
margin-top: ${theme.spacing(5)};
|
|
41
|
-
margin-left: ${theme.spacing(2)};
|
|
42
|
-
`,
|
|
43
|
-
radioGroup: css`
|
|
44
|
-
margin-left: ${theme.spacing(3)};
|
|
45
|
-
margin-top: ${theme.spacing(3)};
|
|
46
|
-
`,
|
|
47
|
-
formControl: css`
|
|
48
|
-
margin-bottom: ${theme.spacing(1)};
|
|
49
|
-
|
|
50
|
-
.MuiFormControlLabel-label {
|
|
51
|
-
color: ${theme.palette.text.primary};
|
|
52
|
-
font-weight: 400;
|
|
53
|
-
font-size: 16px;
|
|
54
|
-
line-height: 150%;
|
|
55
|
-
letter-spacing: 0.15px;
|
|
56
|
-
}
|
|
57
|
-
`,
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
const handleNext = () => {
|
|
61
|
-
dispatch(setStep(WIDGET_STEP.ChooseAmount))
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
const items: {
|
|
65
|
-
label: string
|
|
66
|
-
value: TrancheType
|
|
67
|
-
}[] = [
|
|
68
|
-
{
|
|
69
|
-
label: 'Senior',
|
|
70
|
-
value: 'senior',
|
|
71
|
-
},
|
|
72
|
-
{
|
|
73
|
-
label: 'Junior',
|
|
74
|
-
value: 'junior',
|
|
75
|
-
},
|
|
76
|
-
]
|
|
77
|
-
|
|
78
|
-
return (
|
|
79
|
-
<WrapperModal title={`Supply ${poolUnderlyingToken.symbol}`}>
|
|
80
|
-
<FormControl>
|
|
81
|
-
<FormLabel css={styles.subTitle}>Select Tranche Type</FormLabel>
|
|
82
|
-
<RadioGroup
|
|
83
|
-
aria-labelledby='buttons-group-label'
|
|
84
|
-
name='radio-buttons-group'
|
|
85
|
-
css={styles.radioGroup}
|
|
86
|
-
onChange={(e) => changeTranche(e.target.value as TrancheType)}
|
|
87
|
-
>
|
|
88
|
-
{items.map((item) => (
|
|
89
|
-
<FormControlLabel
|
|
90
|
-
key={item.label}
|
|
91
|
-
value={item.value}
|
|
92
|
-
control={
|
|
93
|
-
<Radio
|
|
94
|
-
sx={{
|
|
95
|
-
'& .MuiSvgIcon-root': {
|
|
96
|
-
fontSize: 24,
|
|
97
|
-
},
|
|
98
|
-
}}
|
|
99
|
-
/>
|
|
100
|
-
}
|
|
101
|
-
label={item.label}
|
|
102
|
-
css={styles.formControl}
|
|
103
|
-
/>
|
|
104
|
-
))}
|
|
105
|
-
</RadioGroup>
|
|
106
|
-
</FormControl>
|
|
107
|
-
<BottomButton
|
|
108
|
-
variant='contained'
|
|
109
|
-
disabled={!selectedTranche}
|
|
110
|
-
onClick={handleNext}
|
|
111
|
-
>
|
|
112
|
-
NEXT
|
|
113
|
-
</BottomButton>
|
|
114
|
-
</WrapperModal>
|
|
115
|
-
)
|
|
116
|
-
}
|
|
File without changes
|
|
@@ -1,130 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
formatNumber,
|
|
3
|
-
SolanaPoolInfo,
|
|
4
|
-
SolanaTokenUtils,
|
|
5
|
-
TrancheType,
|
|
6
|
-
} from '@huma-finance/shared'
|
|
7
|
-
import { SolanaPoolState } from '@huma-finance/web-shared'
|
|
8
|
-
import React, { useMemo, useState } from 'react'
|
|
9
|
-
import { BN } from '@coral-xyz/anchor'
|
|
10
|
-
import { Account } from '@solana/spl-token'
|
|
11
|
-
import { useAppDispatch } from '../../../hooks/useRedux'
|
|
12
|
-
import { setStep, setSupplyAmount } from '../../../store/widgets.reducers'
|
|
13
|
-
import { WIDGET_STEP } from '../../../store/widgets.store'
|
|
14
|
-
import { InputAmountModal } from '../../InputAmountModal'
|
|
15
|
-
|
|
16
|
-
type Props = {
|
|
17
|
-
poolInfo: SolanaPoolInfo
|
|
18
|
-
poolState: SolanaPoolState
|
|
19
|
-
tokenAccount: Account
|
|
20
|
-
selectedTranche: TrancheType | undefined
|
|
21
|
-
isUniTranche: boolean
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
export function ChooseAmount({
|
|
25
|
-
poolInfo,
|
|
26
|
-
poolState,
|
|
27
|
-
tokenAccount,
|
|
28
|
-
selectedTranche,
|
|
29
|
-
isUniTranche,
|
|
30
|
-
}: Props): React.ReactElement | null {
|
|
31
|
-
const dispatch = useAppDispatch()
|
|
32
|
-
const { symbol, decimals } = poolInfo.underlyingMint
|
|
33
|
-
const [currentAmount, setCurrentAmount] = useState<number | string>(0)
|
|
34
|
-
const balance = useMemo(
|
|
35
|
-
() => new BN(tokenAccount.amount),
|
|
36
|
-
[tokenAccount.amount],
|
|
37
|
-
)
|
|
38
|
-
|
|
39
|
-
const { juniorAvailableCapBN, seniorAvailableCapBN } = useMemo(() => {
|
|
40
|
-
const {
|
|
41
|
-
maxSeniorJuniorRatio,
|
|
42
|
-
liquidityCap,
|
|
43
|
-
seniorTrancheAssets,
|
|
44
|
-
juniorTrancheAssets,
|
|
45
|
-
} = poolState
|
|
46
|
-
const juniorTrancheAssetsBN = new BN(juniorTrancheAssets)
|
|
47
|
-
const seniorTrancheAssetsBN = new BN(seniorTrancheAssets)
|
|
48
|
-
const totalDeployedBN = seniorTrancheAssetsBN.add(juniorTrancheAssetsBN)
|
|
49
|
-
const totalAvailableCapBN = new BN(liquidityCap).sub(totalDeployedBN)
|
|
50
|
-
const maxSeniorAssetsBN = juniorTrancheAssetsBN.muln(maxSeniorJuniorRatio)
|
|
51
|
-
let seniorAvailableCapBN = maxSeniorAssetsBN.sub(seniorTrancheAssetsBN)
|
|
52
|
-
seniorAvailableCapBN = seniorAvailableCapBN.gt(totalAvailableCapBN)
|
|
53
|
-
? totalAvailableCapBN
|
|
54
|
-
: seniorAvailableCapBN
|
|
55
|
-
|
|
56
|
-
return {
|
|
57
|
-
juniorAvailableCapBN: totalAvailableCapBN.sub(seniorAvailableCapBN),
|
|
58
|
-
seniorAvailableCapBN,
|
|
59
|
-
}
|
|
60
|
-
}, [poolState])
|
|
61
|
-
|
|
62
|
-
const handleChangeAmount = (newAmount: number) => {
|
|
63
|
-
setCurrentAmount(newAmount)
|
|
64
|
-
dispatch(setSupplyAmount(Number(newAmount)))
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
const handleAction = () => {
|
|
68
|
-
dispatch(setStep(WIDGET_STEP.Transfer))
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
const getTrancheCap = () => {
|
|
72
|
-
if (selectedTranche === 'junior') {
|
|
73
|
-
return juniorAvailableCapBN
|
|
74
|
-
}
|
|
75
|
-
return seniorAvailableCapBN
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
const getMinAmount = (): number => {
|
|
79
|
-
const minAmount = poolState.minDepositAmount
|
|
80
|
-
? SolanaTokenUtils.formatUnits(
|
|
81
|
-
new BN(poolState.minDepositAmount),
|
|
82
|
-
decimals,
|
|
83
|
-
)
|
|
84
|
-
: 0
|
|
85
|
-
return Math.max(0, Math.ceil(Number(minAmount)))
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
const getMaxAmount = (): BN => {
|
|
89
|
-
const trancheCap = getTrancheCap()
|
|
90
|
-
return balance.gt(trancheCap) ? trancheCap : balance
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
const getInfos = () => {
|
|
94
|
-
const trancheCap = getTrancheCap()
|
|
95
|
-
const currentAmountBN = SolanaTokenUtils.parseUnits(
|
|
96
|
-
String(currentAmount),
|
|
97
|
-
decimals,
|
|
98
|
-
)
|
|
99
|
-
const remainingCap = trancheCap.sub(currentAmountBN)
|
|
100
|
-
|
|
101
|
-
if (remainingCap.ltn(0)) {
|
|
102
|
-
return ['0 remaining capacity']
|
|
103
|
-
}
|
|
104
|
-
return [
|
|
105
|
-
`${formatNumber(
|
|
106
|
-
SolanaTokenUtils.formatUnits(remainingCap, decimals),
|
|
107
|
-
)} remaining capacity`,
|
|
108
|
-
]
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
return (
|
|
112
|
-
<InputAmountModal
|
|
113
|
-
title='Enter Amount'
|
|
114
|
-
subTitle={`Depositing to ${
|
|
115
|
-
isUniTranche ? 'uni tranche' : selectedTranche
|
|
116
|
-
} tranche`}
|
|
117
|
-
tokenSymbol={symbol}
|
|
118
|
-
currentAmount={currentAmount}
|
|
119
|
-
handleChangeAmount={handleChangeAmount}
|
|
120
|
-
minimumAmount={getMinAmount()}
|
|
121
|
-
maxAmount={Number(SolanaTokenUtils.formatUnits(getMaxAmount(), decimals))}
|
|
122
|
-
maxAmountTitle={`${formatNumber(
|
|
123
|
-
SolanaTokenUtils.formatUnits(balance, decimals),
|
|
124
|
-
)} balance`}
|
|
125
|
-
infos={getInfos()}
|
|
126
|
-
handleAction={handleAction}
|
|
127
|
-
actionText='SUPPLY'
|
|
128
|
-
/>
|
|
129
|
-
)
|
|
130
|
-
}
|
|
@@ -1,89 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
getTokenAccounts,
|
|
3
|
-
SolanaPoolInfo,
|
|
4
|
-
SolanaTokenUtils,
|
|
5
|
-
TrancheType,
|
|
6
|
-
} from '@huma-finance/shared'
|
|
7
|
-
import React, { useCallback, useEffect, useState } from 'react'
|
|
8
|
-
|
|
9
|
-
import { TOKEN_2022_PROGRAM_ID } from '@solana/spl-token'
|
|
10
|
-
import { useWallet } from '@solana/wallet-adapter-react'
|
|
11
|
-
import { useHumaProgram } from '@huma-finance/web-shared'
|
|
12
|
-
import { Transaction } from '@solana/web3.js'
|
|
13
|
-
import { useAppDispatch, useAppSelector } from '../../../hooks/useRedux'
|
|
14
|
-
import { setStep } from '../../../store/widgets.reducers'
|
|
15
|
-
import { WIDGET_STEP } from '../../../store/widgets.store'
|
|
16
|
-
import { selectWidgetState } from '../../../store/widgets.selectors'
|
|
17
|
-
import { SolanaTxSendModal } from '../../SolanaTxSendModal'
|
|
18
|
-
|
|
19
|
-
type Props = {
|
|
20
|
-
poolInfo: SolanaPoolInfo
|
|
21
|
-
selectedTranche: TrancheType
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
export function Transfer({
|
|
25
|
-
poolInfo,
|
|
26
|
-
selectedTranche,
|
|
27
|
-
}: Props): React.ReactElement | null {
|
|
28
|
-
const dispatch = useAppDispatch()
|
|
29
|
-
const { publicKey } = useWallet()
|
|
30
|
-
const { supplyAmount } = useAppSelector(selectWidgetState)
|
|
31
|
-
const { decimals } = poolInfo.underlyingMint
|
|
32
|
-
const supplyBigNumber = SolanaTokenUtils.parseUnits(
|
|
33
|
-
String(supplyAmount),
|
|
34
|
-
decimals,
|
|
35
|
-
)
|
|
36
|
-
const [transaction, setTransaction] = useState<Transaction>()
|
|
37
|
-
const program = useHumaProgram(poolInfo.chainId)
|
|
38
|
-
|
|
39
|
-
const handleSuccess = useCallback(() => {
|
|
40
|
-
dispatch(setStep(WIDGET_STEP.Done))
|
|
41
|
-
}, [dispatch])
|
|
42
|
-
|
|
43
|
-
useEffect(() => {
|
|
44
|
-
async function getTx() {
|
|
45
|
-
if (!publicKey || transaction) {
|
|
46
|
-
return
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
const { underlyingTokenATA, seniorTrancheATA, juniorTrancheATA } =
|
|
50
|
-
getTokenAccounts(poolInfo, publicKey)
|
|
51
|
-
const tx = await program.methods
|
|
52
|
-
.deposit(supplyBigNumber)
|
|
53
|
-
.accountsPartial({
|
|
54
|
-
depositor: publicKey,
|
|
55
|
-
poolConfig: poolInfo.poolConfig,
|
|
56
|
-
underlyingMint: poolInfo.underlyingMint.address,
|
|
57
|
-
trancheMint:
|
|
58
|
-
selectedTranche === 'senior'
|
|
59
|
-
? poolInfo.seniorTrancheMint
|
|
60
|
-
: poolInfo.juniorTrancheMint,
|
|
61
|
-
poolUnderlyingToken: poolInfo.poolUnderlyingTokenAccount,
|
|
62
|
-
depositorUnderlyingToken: underlyingTokenATA,
|
|
63
|
-
depositorTrancheToken:
|
|
64
|
-
selectedTranche === 'senior' ? seniorTrancheATA : juniorTrancheATA,
|
|
65
|
-
humaConfig: poolInfo.humaConfig,
|
|
66
|
-
tokenProgram: TOKEN_2022_PROGRAM_ID,
|
|
67
|
-
})
|
|
68
|
-
.transaction()
|
|
69
|
-
|
|
70
|
-
setTransaction(tx)
|
|
71
|
-
}
|
|
72
|
-
getTx()
|
|
73
|
-
}, [
|
|
74
|
-
poolInfo,
|
|
75
|
-
program.methods,
|
|
76
|
-
publicKey,
|
|
77
|
-
selectedTranche,
|
|
78
|
-
supplyBigNumber,
|
|
79
|
-
transaction,
|
|
80
|
-
])
|
|
81
|
-
|
|
82
|
-
return (
|
|
83
|
-
<SolanaTxSendModal
|
|
84
|
-
tx={transaction}
|
|
85
|
-
chainId={poolInfo.chainId}
|
|
86
|
-
handleSuccess={handleSuccess}
|
|
87
|
-
/>
|
|
88
|
-
)
|
|
89
|
-
}
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
import { formatMoney, SolanaPoolInfo, timeUtil } from '@huma-finance/shared'
|
|
2
|
-
import { SolanaPoolState } from '@huma-finance/web-shared'
|
|
3
|
-
import moment from 'moment'
|
|
4
|
-
import React from 'react'
|
|
5
|
-
|
|
6
|
-
import { selectWidgetState } from '../../../store/widgets.selectors'
|
|
7
|
-
import { useAppSelector } from '../../../hooks/useRedux'
|
|
8
|
-
import { SolanaTxDoneModal } from '../../SolanaTxDoneModal'
|
|
9
|
-
|
|
10
|
-
type Props = {
|
|
11
|
-
poolInfo: SolanaPoolInfo
|
|
12
|
-
poolState: SolanaPoolState
|
|
13
|
-
handleAction: () => void
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export function Success({
|
|
17
|
-
poolInfo,
|
|
18
|
-
poolState,
|
|
19
|
-
handleAction,
|
|
20
|
-
}: Props): React.ReactElement {
|
|
21
|
-
const { supplyAmount, solanaSignature } = useAppSelector(selectWidgetState)
|
|
22
|
-
const { symbol } = poolInfo.underlyingMint
|
|
23
|
-
|
|
24
|
-
const content = [
|
|
25
|
-
`You successfully supplied ${formatMoney(supplyAmount)} ${symbol}.`,
|
|
26
|
-
]
|
|
27
|
-
|
|
28
|
-
const getSubContent = () => {
|
|
29
|
-
const currentTime = moment().add(
|
|
30
|
-
poolState.withdrawalLockupPeriodDays,
|
|
31
|
-
'days',
|
|
32
|
-
)
|
|
33
|
-
return [
|
|
34
|
-
`First redemption date: ${timeUtil.timestampToLL(
|
|
35
|
-
currentTime.unix(),
|
|
36
|
-
)}. You can redeem end of each month after.`,
|
|
37
|
-
]
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
return (
|
|
41
|
-
<SolanaTxDoneModal
|
|
42
|
-
handleAction={handleAction}
|
|
43
|
-
content={content}
|
|
44
|
-
subContent={getSubContent()}
|
|
45
|
-
chainId={poolInfo.chainId}
|
|
46
|
-
solanaSignature={solanaSignature}
|
|
47
|
-
buttonText='DONE'
|
|
48
|
-
/>
|
|
49
|
-
)
|
|
50
|
-
}
|