@huma-finance/widgets 0.0.62-beta.612 → 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 +955 -2880
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/index.d.ts +8 -116
- package/dist/index.js +658 -2601
- 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,183 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
formatNumber,
|
|
3
|
-
SolanaPoolInfo,
|
|
4
|
-
SolanaTokenUtils,
|
|
5
|
-
timestampToLL,
|
|
6
|
-
TrancheType,
|
|
7
|
-
} from '@huma-finance/shared'
|
|
8
|
-
import {
|
|
9
|
-
LenderStateAccount,
|
|
10
|
-
SolanaPoolState,
|
|
11
|
-
useTrancheMintAccounts,
|
|
12
|
-
useTrancheTokenAccounts,
|
|
13
|
-
} from '@huma-finance/web-shared'
|
|
14
|
-
import dayjs from 'dayjs'
|
|
15
|
-
import React, { useEffect, useMemo, useState } from 'react'
|
|
16
|
-
|
|
17
|
-
import { BN } from '@coral-xyz/anchor'
|
|
18
|
-
import { useAppDispatch } from '../../../hooks/useRedux'
|
|
19
|
-
import {
|
|
20
|
-
setError,
|
|
21
|
-
setRedeemAmount,
|
|
22
|
-
setRedeemShares,
|
|
23
|
-
setStep,
|
|
24
|
-
} from '../../../store/widgets.reducers'
|
|
25
|
-
import { WIDGET_STEP } from '../../../store/widgets.store'
|
|
26
|
-
import { InputAmountModal } from '../../InputAmountModal'
|
|
27
|
-
import { LoadingModal } from '../../LoadingModal'
|
|
28
|
-
|
|
29
|
-
type Props = {
|
|
30
|
-
poolInfo: SolanaPoolInfo
|
|
31
|
-
poolState: SolanaPoolState
|
|
32
|
-
selectedTranche: TrancheType
|
|
33
|
-
lenderState: LenderStateAccount | null | undefined
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
export function ChooseAmount({
|
|
37
|
-
poolInfo,
|
|
38
|
-
poolState,
|
|
39
|
-
selectedTranche,
|
|
40
|
-
lenderState,
|
|
41
|
-
}: Props): React.ReactElement {
|
|
42
|
-
const dispatch = useAppDispatch()
|
|
43
|
-
const { symbol } = poolInfo.underlyingMint
|
|
44
|
-
const [currentAmount, setCurrentAmount] = useState<number>(0)
|
|
45
|
-
const [currentShares, setCurrentShares] = useState<number>(0)
|
|
46
|
-
const { mintAccount, loading: isLoadingTrancheMintAccounts } =
|
|
47
|
-
useTrancheMintAccounts(poolInfo, selectedTranche)
|
|
48
|
-
const {
|
|
49
|
-
seniorTokenAccount,
|
|
50
|
-
juniorTokenAccount,
|
|
51
|
-
loading: isLoadingTokenAccounts,
|
|
52
|
-
} = useTrancheTokenAccounts(poolInfo)
|
|
53
|
-
|
|
54
|
-
const maxSharesFormatted = useMemo(() => {
|
|
55
|
-
if (!mintAccount?.decimals) {
|
|
56
|
-
return 0
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
return SolanaTokenUtils.formatUnits(
|
|
60
|
-
selectedTranche === 'senior'
|
|
61
|
-
? new BN(seniorTokenAccount?.amount)
|
|
62
|
-
: new BN(juniorTokenAccount?.amount),
|
|
63
|
-
mintAccount.decimals,
|
|
64
|
-
)
|
|
65
|
-
}, [
|
|
66
|
-
mintAccount,
|
|
67
|
-
juniorTokenAccount?.amount,
|
|
68
|
-
selectedTranche,
|
|
69
|
-
seniorTokenAccount?.amount,
|
|
70
|
-
])
|
|
71
|
-
|
|
72
|
-
const sharePrice = useMemo(() => {
|
|
73
|
-
if (!mintAccount?.decimals || !mintAccount?.supply) {
|
|
74
|
-
return 0
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
const mintSupplyFormatted = Number(
|
|
78
|
-
SolanaTokenUtils.formatUnits(
|
|
79
|
-
new BN(mintAccount.supply),
|
|
80
|
-
mintAccount.decimals,
|
|
81
|
-
),
|
|
82
|
-
)
|
|
83
|
-
|
|
84
|
-
if (mintSupplyFormatted === 0) {
|
|
85
|
-
return 0
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
const seniorTrancheAssetsFormatted = Number(
|
|
89
|
-
SolanaTokenUtils.formatUnits(
|
|
90
|
-
new BN(poolState?.seniorTrancheAssets),
|
|
91
|
-
mintAccount.decimals,
|
|
92
|
-
),
|
|
93
|
-
)
|
|
94
|
-
|
|
95
|
-
if (selectedTranche === 'senior') {
|
|
96
|
-
return seniorTrancheAssetsFormatted / mintSupplyFormatted
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
const juniorTrancheAssetsFormatted = Number(
|
|
100
|
-
SolanaTokenUtils.formatUnits(
|
|
101
|
-
new BN(poolState?.juniorTrancheAssets),
|
|
102
|
-
mintAccount.decimals,
|
|
103
|
-
),
|
|
104
|
-
)
|
|
105
|
-
|
|
106
|
-
return juniorTrancheAssetsFormatted / mintSupplyFormatted
|
|
107
|
-
}, [
|
|
108
|
-
mintAccount?.decimals,
|
|
109
|
-
mintAccount?.supply,
|
|
110
|
-
poolState?.juniorTrancheAssets,
|
|
111
|
-
poolState?.seniorTrancheAssets,
|
|
112
|
-
selectedTranche,
|
|
113
|
-
])
|
|
114
|
-
|
|
115
|
-
useEffect(() => {
|
|
116
|
-
if (
|
|
117
|
-
poolState?.withdrawalLockupPeriodDays &&
|
|
118
|
-
poolState?.epochEndTime &&
|
|
119
|
-
lenderState
|
|
120
|
-
) {
|
|
121
|
-
const SECONDS_IN_A_DAY = 24 * 60 * 60
|
|
122
|
-
const lastDepositTime = Number(lenderState.depositRecord.lastDepositTime)
|
|
123
|
-
const lockupEndTime =
|
|
124
|
-
lastDepositTime +
|
|
125
|
-
poolState.withdrawalLockupPeriodDays * SECONDS_IN_A_DAY
|
|
126
|
-
if (poolState.epochEndTime < lockupEndTime) {
|
|
127
|
-
const lockupEndTimeDayjs = dayjs.unix(lockupEndTime).date(1)
|
|
128
|
-
dispatch(setStep(WIDGET_STEP.Error))
|
|
129
|
-
dispatch(
|
|
130
|
-
setError({
|
|
131
|
-
errorReason: 'Redemption too soon',
|
|
132
|
-
errorMessage: `Your last deposit was on ${timestampToLL(
|
|
133
|
-
lastDepositTime,
|
|
134
|
-
)}. You can redeem on ${timestampToLL(lockupEndTimeDayjs.unix())}.`,
|
|
135
|
-
}),
|
|
136
|
-
)
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
}, [
|
|
140
|
-
dispatch,
|
|
141
|
-
lenderState,
|
|
142
|
-
poolState.epochEndTime,
|
|
143
|
-
poolState.withdrawalLockupPeriodDays,
|
|
144
|
-
])
|
|
145
|
-
|
|
146
|
-
const handleChangeShares = (newShares: number) => {
|
|
147
|
-
const amount = Number(newShares) * sharePrice
|
|
148
|
-
setCurrentShares(Number(newShares))
|
|
149
|
-
setCurrentAmount(amount)
|
|
150
|
-
dispatch(setRedeemShares(Number(newShares)))
|
|
151
|
-
dispatch(setRedeemAmount(amount))
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
const handleAction = () => {
|
|
155
|
-
dispatch(setStep(WIDGET_STEP.Transfer))
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
if (
|
|
159
|
-
isLoadingTokenAccounts ||
|
|
160
|
-
isLoadingTrancheMintAccounts ||
|
|
161
|
-
!lenderState ||
|
|
162
|
-
poolState?.withdrawalLockupPeriodDays === undefined || // withdrawalLockupPeriodDays can be 0
|
|
163
|
-
!poolState?.epochEndTime
|
|
164
|
-
) {
|
|
165
|
-
return <LoadingModal title='Redemption' />
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
return (
|
|
169
|
-
<InputAmountModal
|
|
170
|
-
title='Redemption'
|
|
171
|
-
subTitle={`Enter number of shares to redeem from the ${selectedTranche} tranche`}
|
|
172
|
-
tokenSymbol={symbol}
|
|
173
|
-
currentAmount={currentShares}
|
|
174
|
-
handleChangeAmount={handleChangeShares}
|
|
175
|
-
maxAmount={maxSharesFormatted}
|
|
176
|
-
infos={[`${String(formatNumber(currentAmount))} ${symbol}`]}
|
|
177
|
-
maxAmountTitle={`${formatNumber(maxSharesFormatted)} Shares`}
|
|
178
|
-
suffix='Shares'
|
|
179
|
-
handleAction={handleAction}
|
|
180
|
-
actionText='REQUEST'
|
|
181
|
-
/>
|
|
182
|
-
)
|
|
183
|
-
}
|
|
@@ -1,102 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
getTokenAccounts,
|
|
3
|
-
SolanaPoolInfo,
|
|
4
|
-
SolanaTokenUtils,
|
|
5
|
-
TrancheType,
|
|
6
|
-
} from '@huma-finance/shared'
|
|
7
|
-
import React, { useCallback, useEffect, useMemo, useState } from 'react'
|
|
8
|
-
|
|
9
|
-
import { TOKEN_2022_PROGRAM_ID } from '@solana/spl-token'
|
|
10
|
-
import { useWallet } from '@solana/wallet-adapter-react'
|
|
11
|
-
import {
|
|
12
|
-
useHumaProgram,
|
|
13
|
-
useTrancheMintAccounts,
|
|
14
|
-
} from '@huma-finance/web-shared'
|
|
15
|
-
import { Transaction } from '@solana/web3.js'
|
|
16
|
-
import { useAppDispatch, useAppSelector } from '../../../hooks/useRedux'
|
|
17
|
-
import { setStep } from '../../../store/widgets.reducers'
|
|
18
|
-
import { WIDGET_STEP } from '../../../store/widgets.store'
|
|
19
|
-
import { selectWidgetState } from '../../../store/widgets.selectors'
|
|
20
|
-
import { SolanaTxSendModal } from '../../SolanaTxSendModal'
|
|
21
|
-
|
|
22
|
-
type Props = {
|
|
23
|
-
poolInfo: SolanaPoolInfo
|
|
24
|
-
selectedTranche: TrancheType
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
export function Transfer({
|
|
28
|
-
poolInfo,
|
|
29
|
-
selectedTranche,
|
|
30
|
-
}: Props): React.ReactElement | null {
|
|
31
|
-
const dispatch = useAppDispatch()
|
|
32
|
-
const { publicKey } = useWallet()
|
|
33
|
-
const { redeemShares } = useAppSelector(selectWidgetState)
|
|
34
|
-
const { mintAccount } = useTrancheMintAccounts(poolInfo, selectedTranche)
|
|
35
|
-
const [transaction, setTransaction] = useState<Transaction>()
|
|
36
|
-
const program = useHumaProgram(poolInfo.chainId)
|
|
37
|
-
const redeemBN = useMemo(() => {
|
|
38
|
-
if (!mintAccount) {
|
|
39
|
-
return null
|
|
40
|
-
}
|
|
41
|
-
return SolanaTokenUtils.parseUnits(
|
|
42
|
-
String(redeemShares),
|
|
43
|
-
mintAccount?.decimals,
|
|
44
|
-
)
|
|
45
|
-
}, [mintAccount, redeemShares])
|
|
46
|
-
|
|
47
|
-
const handleSuccess = useCallback(() => {
|
|
48
|
-
dispatch(setStep(WIDGET_STEP.Done))
|
|
49
|
-
}, [dispatch])
|
|
50
|
-
|
|
51
|
-
useEffect(() => {
|
|
52
|
-
async function getTx() {
|
|
53
|
-
if (!publicKey || !redeemBN || transaction) {
|
|
54
|
-
return
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
const {
|
|
58
|
-
seniorTrancheATA,
|
|
59
|
-
juniorTrancheATA,
|
|
60
|
-
poolSeniorTrancheATA,
|
|
61
|
-
poolJuniorTrancheATA,
|
|
62
|
-
} = getTokenAccounts(poolInfo, publicKey)
|
|
63
|
-
const tx = await program.methods
|
|
64
|
-
.addRedemptionRequest(redeemBN)
|
|
65
|
-
.accountsPartial({
|
|
66
|
-
lender: publicKey,
|
|
67
|
-
humaConfig: poolInfo.humaConfig,
|
|
68
|
-
poolConfig: poolInfo.poolConfig,
|
|
69
|
-
trancheMint:
|
|
70
|
-
selectedTranche === 'senior'
|
|
71
|
-
? poolInfo.seniorTrancheMint
|
|
72
|
-
: poolInfo.juniorTrancheMint,
|
|
73
|
-
poolTrancheToken:
|
|
74
|
-
selectedTranche === 'senior'
|
|
75
|
-
? poolSeniorTrancheATA
|
|
76
|
-
: poolJuniorTrancheATA,
|
|
77
|
-
lenderTrancheToken:
|
|
78
|
-
selectedTranche === 'senior' ? seniorTrancheATA : juniorTrancheATA,
|
|
79
|
-
tokenProgram: TOKEN_2022_PROGRAM_ID,
|
|
80
|
-
})
|
|
81
|
-
.transaction()
|
|
82
|
-
|
|
83
|
-
setTransaction(tx)
|
|
84
|
-
}
|
|
85
|
-
getTx()
|
|
86
|
-
}, [
|
|
87
|
-
poolInfo,
|
|
88
|
-
program.methods,
|
|
89
|
-
publicKey,
|
|
90
|
-
redeemBN,
|
|
91
|
-
selectedTranche,
|
|
92
|
-
transaction,
|
|
93
|
-
])
|
|
94
|
-
|
|
95
|
-
return (
|
|
96
|
-
<SolanaTxSendModal
|
|
97
|
-
tx={transaction}
|
|
98
|
-
chainId={poolInfo.chainId}
|
|
99
|
-
handleSuccess={handleSuccess}
|
|
100
|
-
/>
|
|
101
|
-
)
|
|
102
|
-
}
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { formatNumber, SolanaPoolInfo } from '@huma-finance/shared'
|
|
2
|
-
import React from 'react'
|
|
3
|
-
|
|
4
|
-
import { useAppSelector } from '../../../hooks/useRedux'
|
|
5
|
-
import { selectWidgetState } from '../../../store/widgets.selectors'
|
|
6
|
-
import { SolanaTxDoneModal } from '../../SolanaTxDoneModal'
|
|
7
|
-
|
|
8
|
-
type Props = {
|
|
9
|
-
poolInfo: SolanaPoolInfo
|
|
10
|
-
handleAction: () => void
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export function Done({ poolInfo, handleAction }: Props): React.ReactElement {
|
|
14
|
-
const { redeemShares, solanaSignature } = useAppSelector(selectWidgetState)
|
|
15
|
-
|
|
16
|
-
const content = [
|
|
17
|
-
`${formatNumber(redeemShares)} shares requested for redemption`,
|
|
18
|
-
]
|
|
19
|
-
|
|
20
|
-
return (
|
|
21
|
-
<SolanaTxDoneModal
|
|
22
|
-
handleAction={handleAction}
|
|
23
|
-
content={content}
|
|
24
|
-
chainId={poolInfo.chainId}
|
|
25
|
-
solanaSignature={solanaSignature}
|
|
26
|
-
buttonText='DONE'
|
|
27
|
-
/>
|
|
28
|
-
)
|
|
29
|
-
}
|
|
@@ -1,140 +0,0 @@
|
|
|
1
|
-
import { SolanaPoolInfo, TrancheType } from '@huma-finance/shared'
|
|
2
|
-
import {
|
|
3
|
-
SolanaPoolState,
|
|
4
|
-
useLenderAccounts,
|
|
5
|
-
useTrancheTokenAccounts,
|
|
6
|
-
} from '@huma-finance/web-shared'
|
|
7
|
-
import React, { useEffect, useState } from 'react'
|
|
8
|
-
import { useDispatch } from 'react-redux'
|
|
9
|
-
|
|
10
|
-
import { BN } from '@coral-xyz/anchor'
|
|
11
|
-
import { useAppSelector } from '../../../hooks/useRedux'
|
|
12
|
-
import { selectWidgetState } from '../../../store/widgets.selectors'
|
|
13
|
-
import { WidgetWrapper } from '../../WidgetWrapper'
|
|
14
|
-
import { WIDGET_STEP } from '../../../store/widgets.store'
|
|
15
|
-
import { ChooseAmount } from './2-ChooseAmount'
|
|
16
|
-
import { setStep } from '../../../store/widgets.reducers'
|
|
17
|
-
import { ErrorModal } from '../../ErrorModal'
|
|
18
|
-
import { ChooseTranche } from './1-ChooseTranche'
|
|
19
|
-
import { Done } from './4-Done'
|
|
20
|
-
import { Transfer } from './3-Transfer'
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* Lend pool supply props
|
|
24
|
-
* @typedef {Object} SolanaLendAddRedemptionProps
|
|
25
|
-
* @property {SolanaPoolInfo} poolInfo The metadata of the pool.
|
|
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 {function():void|undefined} handleSuccess Optional function to notify that the lending pool supply action is successful.
|
|
28
|
-
*/
|
|
29
|
-
export interface SolanaLendAddRedemptionProps {
|
|
30
|
-
poolInfo: SolanaPoolInfo
|
|
31
|
-
poolState: SolanaPoolState
|
|
32
|
-
handleClose: () => void
|
|
33
|
-
handleSuccess?: () => void
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
export function SolanaLendAddRedemption({
|
|
37
|
-
poolInfo,
|
|
38
|
-
poolState,
|
|
39
|
-
handleClose,
|
|
40
|
-
handleSuccess,
|
|
41
|
-
}: SolanaLendAddRedemptionProps): React.ReactElement | null {
|
|
42
|
-
const dispatch = useDispatch()
|
|
43
|
-
const {
|
|
44
|
-
seniorLenderStateAccount,
|
|
45
|
-
juniorLenderStateAccount,
|
|
46
|
-
loading: isLoadingLenderAccounts,
|
|
47
|
-
} = useLenderAccounts(poolInfo.chainId, poolInfo.poolName)
|
|
48
|
-
const {
|
|
49
|
-
seniorTokenAccount,
|
|
50
|
-
juniorTokenAccount,
|
|
51
|
-
loading: isLoadingTokenAccounts,
|
|
52
|
-
} = useTrancheTokenAccounts(poolInfo)
|
|
53
|
-
const { step, errorMessage } = useAppSelector(selectWidgetState)
|
|
54
|
-
const [selectedTranche, setSelectedTranche] = useState<TrancheType>()
|
|
55
|
-
|
|
56
|
-
useEffect(() => {
|
|
57
|
-
if (!step && !isLoadingLenderAccounts && !isLoadingTokenAccounts) {
|
|
58
|
-
const seniorTrancheShares = new BN(seniorTokenAccount?.amount)
|
|
59
|
-
const juniorTrancheShares = new BN(juniorTokenAccount?.amount)
|
|
60
|
-
|
|
61
|
-
if (juniorTrancheShares.gtn(0) && seniorTrancheShares.lten(0)) {
|
|
62
|
-
setSelectedTranche('junior')
|
|
63
|
-
dispatch(setStep(WIDGET_STEP.ChooseAmount))
|
|
64
|
-
return
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
if (seniorTrancheShares.gtn(0) && juniorTrancheShares.lten(0)) {
|
|
68
|
-
setSelectedTranche('senior')
|
|
69
|
-
dispatch(setStep(WIDGET_STEP.ChooseAmount))
|
|
70
|
-
return
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
if (seniorTrancheShares.gtn(0) && juniorTrancheShares.gtn(0)) {
|
|
74
|
-
dispatch(setStep(WIDGET_STEP.ChooseTranche))
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
}, [
|
|
78
|
-
dispatch,
|
|
79
|
-
step,
|
|
80
|
-
isLoadingLenderAccounts,
|
|
81
|
-
isLoadingTokenAccounts,
|
|
82
|
-
seniorTokenAccount?.amount,
|
|
83
|
-
juniorTokenAccount?.amount,
|
|
84
|
-
])
|
|
85
|
-
|
|
86
|
-
const title = 'Redemption'
|
|
87
|
-
if (isLoadingLenderAccounts || isLoadingTokenAccounts) {
|
|
88
|
-
return (
|
|
89
|
-
<WidgetWrapper
|
|
90
|
-
isOpen
|
|
91
|
-
isLoading
|
|
92
|
-
loadingTitle={title}
|
|
93
|
-
handleClose={handleClose}
|
|
94
|
-
handleSuccess={handleSuccess}
|
|
95
|
-
/>
|
|
96
|
-
)
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
return (
|
|
100
|
-
<WidgetWrapper
|
|
101
|
-
isOpen
|
|
102
|
-
loadingTitle={title}
|
|
103
|
-
handleClose={handleClose}
|
|
104
|
-
handleSuccess={handleSuccess}
|
|
105
|
-
>
|
|
106
|
-
{step === WIDGET_STEP.ChooseTranche && (
|
|
107
|
-
<ChooseTranche
|
|
108
|
-
selectedTranche={selectedTranche}
|
|
109
|
-
changeTranche={setSelectedTranche}
|
|
110
|
-
/>
|
|
111
|
-
)}
|
|
112
|
-
{step === WIDGET_STEP.ChooseAmount && selectedTranche && (
|
|
113
|
-
<ChooseAmount
|
|
114
|
-
poolInfo={poolInfo}
|
|
115
|
-
poolState={poolState}
|
|
116
|
-
lenderState={
|
|
117
|
-
selectedTranche === 'senior'
|
|
118
|
-
? seniorLenderStateAccount
|
|
119
|
-
: juniorLenderStateAccount
|
|
120
|
-
}
|
|
121
|
-
selectedTranche={selectedTranche}
|
|
122
|
-
/>
|
|
123
|
-
)}
|
|
124
|
-
{step === WIDGET_STEP.Transfer && selectedTranche && (
|
|
125
|
-
<Transfer poolInfo={poolInfo} selectedTranche={selectedTranche} />
|
|
126
|
-
)}
|
|
127
|
-
{step === WIDGET_STEP.Done && (
|
|
128
|
-
<Done poolInfo={poolInfo} handleAction={handleClose} />
|
|
129
|
-
)}
|
|
130
|
-
{step === WIDGET_STEP.Error && (
|
|
131
|
-
<ErrorModal
|
|
132
|
-
title={title}
|
|
133
|
-
errorReason='Sorry there was an error'
|
|
134
|
-
errorMessage={errorMessage}
|
|
135
|
-
handleOk={handleClose}
|
|
136
|
-
/>
|
|
137
|
-
)}
|
|
138
|
-
</WidgetWrapper>
|
|
139
|
-
)
|
|
140
|
-
}
|
|
@@ -1,114 +0,0 @@
|
|
|
1
|
-
import { TrancheType } 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
|
-
selectedTranche: TrancheType | undefined
|
|
21
|
-
changeTranche: (tranche: TrancheType) => void
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
export function ChooseTranche({
|
|
25
|
-
selectedTranche,
|
|
26
|
-
changeTranche,
|
|
27
|
-
}: Props): React.ReactElement | null {
|
|
28
|
-
const theme = useTheme()
|
|
29
|
-
const dispatch = useAppDispatch()
|
|
30
|
-
|
|
31
|
-
const styles = {
|
|
32
|
-
subTitle: css`
|
|
33
|
-
color: ${theme.palette.text.primary} !important;
|
|
34
|
-
font-weight: 400;
|
|
35
|
-
font-size: 16px;
|
|
36
|
-
line-height: 150%;
|
|
37
|
-
letter-spacing: 0.15px;
|
|
38
|
-
margin-top: ${theme.spacing(5)};
|
|
39
|
-
margin-left: ${theme.spacing(2)};
|
|
40
|
-
`,
|
|
41
|
-
radioGroup: css`
|
|
42
|
-
margin-left: ${theme.spacing(3)};
|
|
43
|
-
margin-top: ${theme.spacing(3)};
|
|
44
|
-
`,
|
|
45
|
-
formControl: css`
|
|
46
|
-
margin-bottom: ${theme.spacing(1)};
|
|
47
|
-
|
|
48
|
-
.MuiFormControlLabel-label {
|
|
49
|
-
color: ${theme.palette.text.primary};
|
|
50
|
-
font-weight: 400;
|
|
51
|
-
font-size: 16px;
|
|
52
|
-
line-height: 150%;
|
|
53
|
-
letter-spacing: 0.15px;
|
|
54
|
-
}
|
|
55
|
-
`,
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
const handleNext = () => {
|
|
59
|
-
dispatch(setStep(WIDGET_STEP.ChooseAmount))
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
const items: {
|
|
63
|
-
label: string
|
|
64
|
-
value: TrancheType
|
|
65
|
-
}[] = [
|
|
66
|
-
{
|
|
67
|
-
label: 'Senior',
|
|
68
|
-
value: 'senior',
|
|
69
|
-
},
|
|
70
|
-
{
|
|
71
|
-
label: 'Junior',
|
|
72
|
-
value: 'junior',
|
|
73
|
-
},
|
|
74
|
-
]
|
|
75
|
-
|
|
76
|
-
return (
|
|
77
|
-
<WrapperModal title='Cancel Redemption'>
|
|
78
|
-
<FormControl>
|
|
79
|
-
<FormLabel css={styles.subTitle}>Select Tranche Type</FormLabel>
|
|
80
|
-
<RadioGroup
|
|
81
|
-
aria-labelledby='buttons-group-label'
|
|
82
|
-
name='radio-buttons-group'
|
|
83
|
-
css={styles.radioGroup}
|
|
84
|
-
onChange={(e) => changeTranche(e.target.value as TrancheType)}
|
|
85
|
-
>
|
|
86
|
-
{items.map((item) => (
|
|
87
|
-
<FormControlLabel
|
|
88
|
-
key={item.label}
|
|
89
|
-
value={item.value}
|
|
90
|
-
control={
|
|
91
|
-
<Radio
|
|
92
|
-
sx={{
|
|
93
|
-
'& .MuiSvgIcon-root': {
|
|
94
|
-
fontSize: 24,
|
|
95
|
-
},
|
|
96
|
-
}}
|
|
97
|
-
/>
|
|
98
|
-
}
|
|
99
|
-
label={item.label}
|
|
100
|
-
css={styles.formControl}
|
|
101
|
-
/>
|
|
102
|
-
))}
|
|
103
|
-
</RadioGroup>
|
|
104
|
-
</FormControl>
|
|
105
|
-
<BottomButton
|
|
106
|
-
variant='contained'
|
|
107
|
-
disabled={!selectedTranche}
|
|
108
|
-
onClick={handleNext}
|
|
109
|
-
>
|
|
110
|
-
NEXT
|
|
111
|
-
</BottomButton>
|
|
112
|
-
</WrapperModal>
|
|
113
|
-
)
|
|
114
|
-
}
|
|
@@ -1,99 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
getTokenAccounts,
|
|
3
|
-
SolanaPoolInfo,
|
|
4
|
-
TrancheType,
|
|
5
|
-
} from '@huma-finance/shared'
|
|
6
|
-
import React, { useCallback, useEffect, useState } from 'react'
|
|
7
|
-
|
|
8
|
-
import { TOKEN_2022_PROGRAM_ID } from '@solana/spl-token'
|
|
9
|
-
import { useWallet } from '@solana/wallet-adapter-react'
|
|
10
|
-
import { LenderStateAccount, useHumaProgram } from '@huma-finance/web-shared'
|
|
11
|
-
import { Transaction } from '@solana/web3.js'
|
|
12
|
-
import { useAppDispatch } from '../../../hooks/useRedux'
|
|
13
|
-
import { setStep } from '../../../store/widgets.reducers'
|
|
14
|
-
import { WIDGET_STEP } from '../../../store/widgets.store'
|
|
15
|
-
import { SolanaTxSendModal } from '../../SolanaTxSendModal'
|
|
16
|
-
|
|
17
|
-
type Props = {
|
|
18
|
-
poolInfo: SolanaPoolInfo
|
|
19
|
-
lenderState: LenderStateAccount | null | undefined
|
|
20
|
-
lenderStatePDA: string | null | undefined
|
|
21
|
-
selectedTranche: TrancheType
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
export function Transfer({
|
|
25
|
-
poolInfo,
|
|
26
|
-
lenderState,
|
|
27
|
-
lenderStatePDA,
|
|
28
|
-
selectedTranche,
|
|
29
|
-
}: Props): React.ReactElement | null {
|
|
30
|
-
const dispatch = useAppDispatch()
|
|
31
|
-
const { publicKey } = useWallet()
|
|
32
|
-
const [transaction, setTransaction] = useState<Transaction>()
|
|
33
|
-
const program = useHumaProgram(poolInfo.chainId)
|
|
34
|
-
|
|
35
|
-
const handleSuccess = useCallback(() => {
|
|
36
|
-
dispatch(setStep(WIDGET_STEP.Done))
|
|
37
|
-
}, [dispatch])
|
|
38
|
-
|
|
39
|
-
useEffect(() => {
|
|
40
|
-
async function getTx() {
|
|
41
|
-
if (!publicKey || !lenderState || !lenderStatePDA || transaction) {
|
|
42
|
-
return
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
const {
|
|
46
|
-
seniorTrancheATA,
|
|
47
|
-
juniorTrancheATA,
|
|
48
|
-
poolSeniorTrancheATA,
|
|
49
|
-
poolJuniorTrancheATA,
|
|
50
|
-
} = getTokenAccounts(poolInfo, publicKey)
|
|
51
|
-
const tx = await program.methods
|
|
52
|
-
.cancelRedemptionRequest(
|
|
53
|
-
lenderState.redemptionRecord.numSharesRequested,
|
|
54
|
-
)
|
|
55
|
-
.accountsPartial({
|
|
56
|
-
lender: publicKey,
|
|
57
|
-
humaConfig: poolInfo.humaConfig,
|
|
58
|
-
poolConfig: poolInfo.poolConfig,
|
|
59
|
-
trancheMint:
|
|
60
|
-
selectedTranche === 'senior'
|
|
61
|
-
? poolInfo.seniorTrancheMint
|
|
62
|
-
: poolInfo.juniorTrancheMint,
|
|
63
|
-
trancheState:
|
|
64
|
-
selectedTranche === 'senior'
|
|
65
|
-
? poolInfo.seniorTrancheState
|
|
66
|
-
: poolInfo.juniorTrancheState,
|
|
67
|
-
lenderState: lenderStatePDA,
|
|
68
|
-
poolAuthority: poolInfo.poolAuthority,
|
|
69
|
-
poolTrancheToken:
|
|
70
|
-
selectedTranche === 'senior'
|
|
71
|
-
? poolSeniorTrancheATA
|
|
72
|
-
: poolJuniorTrancheATA,
|
|
73
|
-
lenderTrancheToken:
|
|
74
|
-
selectedTranche === 'senior' ? seniorTrancheATA : juniorTrancheATA,
|
|
75
|
-
tokenProgram: TOKEN_2022_PROGRAM_ID,
|
|
76
|
-
})
|
|
77
|
-
.transaction()
|
|
78
|
-
|
|
79
|
-
setTransaction(tx)
|
|
80
|
-
}
|
|
81
|
-
getTx()
|
|
82
|
-
}, [
|
|
83
|
-
lenderState,
|
|
84
|
-
lenderStatePDA,
|
|
85
|
-
poolInfo,
|
|
86
|
-
program.methods,
|
|
87
|
-
publicKey,
|
|
88
|
-
selectedTranche,
|
|
89
|
-
transaction,
|
|
90
|
-
])
|
|
91
|
-
|
|
92
|
-
return (
|
|
93
|
-
<SolanaTxSendModal
|
|
94
|
-
tx={transaction}
|
|
95
|
-
chainId={poolInfo.chainId}
|
|
96
|
-
handleSuccess={handleSuccess}
|
|
97
|
-
/>
|
|
98
|
-
)
|
|
99
|
-
}
|