@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,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,155 +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 {POOL_NTrancheTypeAME} tranche The tranche type.
28
- * @property {function():void|undefined} handleSuccess Optional function to notify that the lending pool supply action is successful.
29
- */
30
- export interface SolanaLendAddRedemptionProps {
31
- poolInfo: SolanaPoolInfo
32
- poolState: SolanaPoolState
33
- tranche?: TrancheType
34
- handleClose: () => void
35
- handleSuccess?: () => void
36
- }
37
-
38
- export function SolanaLendAddRedemption({
39
- poolInfo,
40
- poolState,
41
- tranche,
42
- handleClose,
43
- handleSuccess,
44
- }: SolanaLendAddRedemptionProps): React.ReactElement | null {
45
- const dispatch = useDispatch()
46
- const {
47
- seniorLenderStateAccount,
48
- juniorLenderStateAccount,
49
- loading: isLoadingLenderAccounts,
50
- } = useLenderAccounts(poolInfo.chainId, poolInfo.poolName)
51
- const {
52
- seniorTokenAccount,
53
- juniorTokenAccount,
54
- loading: isLoadingTokenAccounts,
55
- } = useTrancheTokenAccounts(poolInfo)
56
- const { step, errorMessage } = useAppSelector(selectWidgetState)
57
- const [selectedTranche, setSelectedTranche] = useState<
58
- TrancheType | undefined
59
- >(tranche)
60
-
61
- useEffect(() => {
62
- if (!step && !isLoadingLenderAccounts && !isLoadingTokenAccounts) {
63
- const seniorTrancheShares = new BN(
64
- seniorTokenAccount?.amount?.toString() ?? 0,
65
- )
66
- const juniorTrancheShares = new BN(
67
- juniorTokenAccount?.amount?.toString() ?? 0,
68
- )
69
-
70
- if (selectedTranche) {
71
- dispatch(setStep(WIDGET_STEP.ChooseAmount))
72
- return
73
- }
74
-
75
- if (juniorTrancheShares.gtn(0) && seniorTrancheShares.lten(0)) {
76
- setSelectedTranche('junior')
77
- dispatch(setStep(WIDGET_STEP.ChooseAmount))
78
- return
79
- }
80
-
81
- if (seniorTrancheShares.gtn(0) && juniorTrancheShares.lten(0)) {
82
- setSelectedTranche('senior')
83
- dispatch(setStep(WIDGET_STEP.ChooseAmount))
84
- return
85
- }
86
-
87
- if (seniorTrancheShares.gtn(0) && juniorTrancheShares.gtn(0)) {
88
- dispatch(setStep(WIDGET_STEP.ChooseTranche))
89
- }
90
- }
91
- }, [
92
- dispatch,
93
- step,
94
- isLoadingLenderAccounts,
95
- isLoadingTokenAccounts,
96
- seniorTokenAccount?.amount,
97
- juniorTokenAccount?.amount,
98
- selectedTranche,
99
- ])
100
-
101
- const title = 'Redemption'
102
- if (isLoadingLenderAccounts || isLoadingTokenAccounts) {
103
- return (
104
- <WidgetWrapper
105
- isOpen
106
- isLoading
107
- loadingTitle={title}
108
- handleClose={handleClose}
109
- handleSuccess={handleSuccess}
110
- />
111
- )
112
- }
113
-
114
- return (
115
- <WidgetWrapper
116
- isOpen
117
- loadingTitle={title}
118
- handleClose={handleClose}
119
- handleSuccess={handleSuccess}
120
- >
121
- {step === WIDGET_STEP.ChooseTranche && (
122
- <ChooseTranche
123
- selectedTranche={selectedTranche}
124
- changeTranche={setSelectedTranche}
125
- />
126
- )}
127
- {step === WIDGET_STEP.ChooseAmount && selectedTranche && (
128
- <ChooseAmount
129
- poolInfo={poolInfo}
130
- poolState={poolState}
131
- lenderState={
132
- selectedTranche === 'senior'
133
- ? seniorLenderStateAccount
134
- : juniorLenderStateAccount
135
- }
136
- selectedTranche={selectedTranche}
137
- />
138
- )}
139
- {step === WIDGET_STEP.Transfer && selectedTranche && (
140
- <Transfer poolInfo={poolInfo} selectedTranche={selectedTranche} />
141
- )}
142
- {step === WIDGET_STEP.Done && (
143
- <Done poolInfo={poolInfo} handleAction={handleClose} />
144
- )}
145
- {step === WIDGET_STEP.Error && (
146
- <ErrorModal
147
- title={title}
148
- errorReason='Sorry there was an error'
149
- errorMessage={errorMessage}
150
- handleOk={handleClose}
151
- />
152
- )}
153
- </WidgetWrapper>
154
- )
155
- }
@@ -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
- }
@@ -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
- }