@huma-finance/widgets 0.0.62-beta.630 → 0.0.62-beta.633

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 (40) hide show
  1. package/API.md +0 -194
  2. package/dist/cjs/index.cjs +258 -1866
  3. package/dist/cjs/index.cjs.map +1 -1
  4. package/dist/index.d.ts +2 -136
  5. package/dist/index.js +261 -1864
  6. package/dist/index.js.map +1 -1
  7. package/package.json +7 -17
  8. package/src/components/CreditLine/paymentV2/1-ChooseAmount.tsx +0 -1
  9. package/src/components/InputAmountModal.tsx +2 -13
  10. package/src/components/Lend/supplyV2/6-Success.tsx +3 -3
  11. package/src/components/WidgetWrapper.tsx +4 -6
  12. package/src/index.tsx +0 -139
  13. package/src/store/widgets.reducers.ts +0 -5
  14. package/src/store/widgets.store.ts +0 -1
  15. package/src/components/CreditLine/solanaBorrow/1-ChooseAmount.tsx +0 -67
  16. package/src/components/CreditLine/solanaBorrow/2-Transfer.tsx +0 -159
  17. package/src/components/CreditLine/solanaBorrow/3-Done.tsx +0 -38
  18. package/src/components/CreditLine/solanaBorrow/index.tsx +0 -90
  19. package/src/components/CreditLine/solanaPayment/1-ChooseAmount.tsx +0 -75
  20. package/src/components/CreditLine/solanaPayment/2-Transfer.tsx +0 -92
  21. package/src/components/CreditLine/solanaPayment/3-Done.tsx +0 -59
  22. package/src/components/CreditLine/solanaPayment/index.tsx +0 -83
  23. package/src/components/Lend/solanaAddRedemption/1-ChooseTranche.tsx +0 -114
  24. package/src/components/Lend/solanaAddRedemption/2-ChooseAmount.tsx +0 -183
  25. package/src/components/Lend/solanaAddRedemption/3-Transfer.tsx +0 -102
  26. package/src/components/Lend/solanaAddRedemption/4-Done.tsx +0 -29
  27. package/src/components/Lend/solanaAddRedemption/index.tsx +0 -155
  28. package/src/components/Lend/solanaCancelRedemption/1-ChooseTranche.tsx +0 -114
  29. package/src/components/Lend/solanaCancelRedemption/2-Transfer.tsx +0 -99
  30. package/src/components/Lend/solanaCancelRedemption/3-Done.tsx +0 -55
  31. package/src/components/Lend/solanaCancelRedemption/index.tsx +0 -162
  32. package/src/components/Lend/solanaSupply/1-Evaluation.tsx +0 -106
  33. package/src/components/Lend/solanaSupply/2-ChooseTranche.tsx +0 -116
  34. package/src/components/Lend/solanaSupply/3-ChooseAmount.tsx +0 -131
  35. package/src/components/Lend/solanaSupply/4-Transfer.tsx +0 -137
  36. package/src/components/Lend/solanaSupply/5-Success.tsx +0 -52
  37. package/src/components/Lend/solanaSupply/index.tsx +0 -155
  38. package/src/components/SolanaTxDoneModal.tsx +0 -119
  39. package/src/components/SolanaTxSendModal.tsx +0 -61
  40. package/src/components/SolanaViewOnExplorer.tsx +0 -29
@@ -1,162 +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
- tranche?: TrancheType
27
- handleClose: () => void
28
- handleSuccess?: () => void
29
- }
30
-
31
- export function SolanaLendCancelRedemption({
32
- poolInfo,
33
- tranche,
34
- handleClose,
35
- handleSuccess,
36
- }: SolanaLendCancelRedemptionProps): React.ReactElement | null {
37
- const dispatch = useDispatch()
38
- const {
39
- seniorLenderStateAccount,
40
- juniorLenderStateAccount,
41
- juniorLenderStateAccountPDA,
42
- seniorLenderStateAccountPDA,
43
- loading: isLoadingLenderAccounts,
44
- } = useLenderAccounts(poolInfo.chainId, poolInfo.poolName)
45
- const { step, errorMessage } = useAppSelector(selectWidgetState)
46
- const [selectedTranche, setSelectedTranche] = useState<
47
- TrancheType | undefined
48
- >(tranche)
49
-
50
- useEffect(() => {
51
- if (!step && !isLoadingLenderAccounts) {
52
- const seniorTrancheSharesRequested = new BN(
53
- seniorLenderStateAccount?.redemptionRecord.numSharesRequested ?? 0,
54
- )
55
- const juniorTrancheSharesRequested = new BN(
56
- juniorLenderStateAccount?.redemptionRecord.numSharesRequested ?? 0,
57
- )
58
-
59
- if (selectedTranche) {
60
- dispatch(setStep(WIDGET_STEP.Transfer))
61
- return
62
- }
63
-
64
- if (
65
- juniorTrancheSharesRequested.gtn(0) &&
66
- seniorTrancheSharesRequested.lten(0)
67
- ) {
68
- setSelectedTranche('junior')
69
- dispatch(setStep(WIDGET_STEP.Transfer))
70
- return
71
- }
72
-
73
- if (
74
- seniorTrancheSharesRequested.gtn(0) &&
75
- juniorTrancheSharesRequested.lten(0)
76
- ) {
77
- setSelectedTranche('senior')
78
- dispatch(setStep(WIDGET_STEP.Transfer))
79
- return
80
- }
81
-
82
- if (
83
- seniorTrancheSharesRequested.gtn(0) &&
84
- juniorTrancheSharesRequested.gtn(0)
85
- ) {
86
- dispatch(setStep(WIDGET_STEP.ChooseTranche))
87
- }
88
- }
89
- }, [
90
- dispatch,
91
- step,
92
- isLoadingLenderAccounts,
93
- seniorLenderStateAccount?.redemptionRecord.numSharesRequested,
94
- juniorLenderStateAccount?.redemptionRecord.numSharesRequested,
95
- selectedTranche,
96
- ])
97
-
98
- const title = 'Cancel Redemption'
99
- if (isLoadingLenderAccounts) {
100
- return (
101
- <WidgetWrapper
102
- isOpen
103
- isLoading
104
- loadingTitle={title}
105
- handleClose={handleClose}
106
- handleSuccess={handleSuccess}
107
- />
108
- )
109
- }
110
-
111
- return (
112
- <WidgetWrapper
113
- isOpen
114
- loadingTitle={title}
115
- handleClose={handleClose}
116
- handleSuccess={handleSuccess}
117
- >
118
- {step === WIDGET_STEP.ChooseTranche && (
119
- <ChooseTranche
120
- selectedTranche={selectedTranche}
121
- changeTranche={setSelectedTranche}
122
- />
123
- )}
124
- {step === WIDGET_STEP.Transfer && selectedTranche && (
125
- <Transfer
126
- poolInfo={poolInfo}
127
- lenderState={
128
- selectedTranche === 'senior'
129
- ? seniorLenderStateAccount
130
- : juniorLenderStateAccount
131
- }
132
- lenderStatePDA={
133
- selectedTranche === 'senior'
134
- ? seniorLenderStateAccountPDA
135
- : juniorLenderStateAccountPDA
136
- }
137
- selectedTranche={selectedTranche}
138
- />
139
- )}
140
- {step === WIDGET_STEP.Done && selectedTranche && (
141
- <Done
142
- poolInfo={poolInfo}
143
- lenderState={
144
- selectedTranche === 'senior'
145
- ? seniorLenderStateAccount
146
- : juniorLenderStateAccount
147
- }
148
- selectedTranche={selectedTranche}
149
- handleAction={handleClose}
150
- />
151
- )}
152
- {step === WIDGET_STEP.Error && (
153
- <ErrorModal
154
- title={title}
155
- errorReason='Sorry there was an error'
156
- errorMessage={errorMessage}
157
- handleOk={handleClose}
158
- />
159
- )}
160
- </WidgetWrapper>
161
- )
162
- }
@@ -1,106 +0,0 @@
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
- }
@@ -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
- }
@@ -1,131 +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 = tokenAccount
35
- ? new BN(tokenAccount.amount.toString())
36
- : new BN(0)
37
-
38
- const { juniorAvailableCapBN, seniorAvailableCapBN } = useMemo(() => {
39
- const {
40
- maxSeniorJuniorRatio,
41
- liquidityCap,
42
- seniorTrancheAssets,
43
- juniorTrancheAssets,
44
- } = poolState
45
- const juniorTrancheAssetsBN = new BN(juniorTrancheAssets ?? 0)
46
- const seniorTrancheAssetsBN = new BN(seniorTrancheAssets ?? 0)
47
- const totalDeployedBN = seniorTrancheAssetsBN.add(juniorTrancheAssetsBN)
48
- const totalAvailableCapBN = new BN(liquidityCap ?? 0).sub(totalDeployedBN)
49
- const maxSeniorAssetsBN = juniorTrancheAssetsBN.muln(
50
- maxSeniorJuniorRatio ?? 0,
51
- )
52
- let seniorAvailableCapBN = maxSeniorAssetsBN.sub(seniorTrancheAssetsBN)
53
- seniorAvailableCapBN = seniorAvailableCapBN.gt(totalAvailableCapBN)
54
- ? totalAvailableCapBN
55
- : seniorAvailableCapBN
56
-
57
- return {
58
- juniorAvailableCapBN: totalAvailableCapBN.sub(seniorAvailableCapBN),
59
- seniorAvailableCapBN,
60
- }
61
- }, [poolState])
62
-
63
- const handleChangeAmount = (newAmount: number) => {
64
- setCurrentAmount(newAmount)
65
- dispatch(setSupplyAmount(Number(newAmount)))
66
- }
67
-
68
- const handleAction = () => {
69
- dispatch(setStep(WIDGET_STEP.Transfer))
70
- }
71
-
72
- const getTrancheCap = () => {
73
- if (selectedTranche === 'junior') {
74
- return juniorAvailableCapBN
75
- }
76
- return seniorAvailableCapBN
77
- }
78
-
79
- const getMinAmount = (): number => {
80
- const minAmount = poolState.minDepositAmount
81
- ? SolanaTokenUtils.formatUnits(
82
- new BN(poolState.minDepositAmount),
83
- decimals,
84
- )
85
- : 0
86
- return Math.max(0, Math.ceil(Number(minAmount)))
87
- }
88
-
89
- const getMaxAmount = (): BN => {
90
- const trancheCap = getTrancheCap()
91
- return balance.gt(trancheCap) ? trancheCap : balance
92
- }
93
-
94
- const getInfos = () => {
95
- const trancheCap = getTrancheCap()
96
- const currentAmountBN = SolanaTokenUtils.parseUnits(
97
- String(currentAmount),
98
- decimals,
99
- )
100
- const remainingCap = trancheCap.sub(currentAmountBN)
101
-
102
- if (remainingCap.ltn(0)) {
103
- return ['0 remaining capacity']
104
- }
105
- return [
106
- `${formatNumber(
107
- SolanaTokenUtils.formatUnits(remainingCap, decimals),
108
- )} remaining capacity`,
109
- ]
110
- }
111
-
112
- return (
113
- <InputAmountModal
114
- title='Enter Amount'
115
- subTitle={`Depositing to ${
116
- isUniTranche ? 'uni tranche' : selectedTranche
117
- } tranche`}
118
- tokenSymbol={symbol}
119
- currentAmount={currentAmount}
120
- handleChangeAmount={handleChangeAmount}
121
- minimumAmount={getMinAmount()}
122
- maxAmount={Number(SolanaTokenUtils.formatUnits(getMaxAmount(), decimals))}
123
- maxAmountTitle={`${formatNumber(
124
- SolanaTokenUtils.formatUnits(balance, decimals),
125
- )} balance`}
126
- infos={getInfos()}
127
- handleAction={handleAction}
128
- actionText='SUPPLY'
129
- />
130
- )
131
- }
@@ -1,137 +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, useLenderAccounts } 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
- import { LoadingModal } from '../../LoadingModal'
19
-
20
- type Props = {
21
- poolInfo: SolanaPoolInfo
22
- selectedTranche: TrancheType
23
- }
24
-
25
- export function Transfer({
26
- poolInfo,
27
- selectedTranche,
28
- }: Props): React.ReactElement | null {
29
- const dispatch = useAppDispatch()
30
- const { publicKey } = useWallet()
31
- const { supplyAmount } = useAppSelector(selectWidgetState)
32
- const { decimals } = poolInfo.underlyingMint
33
- const supplyBigNumber = SolanaTokenUtils.parseUnits(
34
- String(supplyAmount),
35
- decimals,
36
- )
37
- const [transaction, setTransaction] = useState<Transaction>()
38
- const {
39
- juniorLenderApprovedAccountPDA,
40
- seniorLenderApprovedAccountPDA,
41
- seniorLenderStateAccount,
42
- juniorLenderStateAccount,
43
- loading: isLoadingLenderAccounts,
44
- } = useLenderAccounts(poolInfo.chainId, poolInfo.poolName)
45
- const program = useHumaProgram(poolInfo.chainId)
46
-
47
- const handleSuccess = useCallback(() => {
48
- dispatch(setStep(WIDGET_STEP.Done))
49
- }, [dispatch])
50
-
51
- useEffect(() => {
52
- async function getTx() {
53
- if (!publicKey || transaction || isLoadingLenderAccounts) {
54
- return
55
- }
56
-
57
- const tx = new Transaction()
58
-
59
- const { underlyingTokenATA, seniorTrancheATA, juniorTrancheATA } =
60
- getTokenAccounts(poolInfo, publicKey)
61
- if (
62
- (selectedTranche === 'senior' && !seniorLenderStateAccount) ||
63
- (selectedTranche === 'junior' && !juniorLenderStateAccount)
64
- ) {
65
- const createLenderAccountsTx = await program.methods
66
- .createLenderAccounts()
67
- .accountsPartial({
68
- lender: publicKey,
69
- humaConfig: poolInfo.humaConfig,
70
- poolConfig: poolInfo.poolConfig,
71
- approvedLender:
72
- selectedTranche === 'senior'
73
- ? seniorLenderApprovedAccountPDA!
74
- : juniorLenderApprovedAccountPDA!,
75
- trancheMint:
76
- selectedTranche === 'senior'
77
- ? poolInfo.seniorTrancheMint
78
- : poolInfo.juniorTrancheMint,
79
- lenderTrancheToken:
80
- selectedTranche === 'senior'
81
- ? seniorTrancheATA
82
- : juniorTrancheATA,
83
- tokenProgram: TOKEN_2022_PROGRAM_ID,
84
- })
85
- .transaction()
86
- tx.add(createLenderAccountsTx)
87
- }
88
-
89
- const depositTx = await program.methods
90
- .deposit(supplyBigNumber)
91
- .accountsPartial({
92
- depositor: publicKey,
93
- poolConfig: poolInfo.poolConfig,
94
- underlyingMint: poolInfo.underlyingMint.address,
95
- trancheMint:
96
- selectedTranche === 'senior'
97
- ? poolInfo.seniorTrancheMint
98
- : poolInfo.juniorTrancheMint,
99
- poolUnderlyingToken: poolInfo.poolUnderlyingTokenAccount,
100
- depositorUnderlyingToken: underlyingTokenATA,
101
- depositorTrancheToken:
102
- selectedTranche === 'senior' ? seniorTrancheATA : juniorTrancheATA,
103
- humaConfig: poolInfo.humaConfig,
104
- tokenProgram: TOKEN_2022_PROGRAM_ID,
105
- })
106
- .transaction()
107
- tx.add(depositTx)
108
-
109
- setTransaction(tx)
110
- }
111
- getTx()
112
- }, [
113
- isLoadingLenderAccounts,
114
- juniorLenderApprovedAccountPDA,
115
- juniorLenderStateAccount,
116
- poolInfo,
117
- program.methods,
118
- publicKey,
119
- selectedTranche,
120
- seniorLenderApprovedAccountPDA,
121
- seniorLenderStateAccount,
122
- supplyBigNumber,
123
- transaction,
124
- ])
125
-
126
- if (isLoadingLenderAccounts) {
127
- return <LoadingModal title='Supply' />
128
- }
129
-
130
- return (
131
- <SolanaTxSendModal
132
- tx={transaction}
133
- chainId={poolInfo.chainId}
134
- handleSuccess={handleSuccess}
135
- />
136
- )
137
- }
@@ -1,52 +0,0 @@
1
- import { formatMoney, SolanaPoolInfo, timeUtil } from '@huma-finance/shared'
2
- import { SolanaPoolState } from '@huma-finance/web-shared'
3
- import React from 'react'
4
-
5
- import dayjs from 'dayjs'
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 lockupEndTime = dayjs()
30
- .add(poolState.withdrawalLockupPeriodDays ?? 0, 'day')
31
- .date(1)
32
- const withdrawTime = lockupEndTime.add(1, 'month')
33
- return [
34
- `You can begin submitting redemption requests on ${timeUtil.timestampToLL(
35
- lockupEndTime.unix(),
36
- )}, which can be redeemed starting ${timeUtil.timestampToLL(
37
- withdrawTime.unix(),
38
- )}.`,
39
- ]
40
- }
41
-
42
- return (
43
- <SolanaTxDoneModal
44
- handleAction={handleAction}
45
- content={content}
46
- subContent={getSubContent()}
47
- chainId={poolInfo.chainId}
48
- solanaSignature={solanaSignature}
49
- buttonText='DONE'
50
- />
51
- )
52
- }