@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,155 +0,0 @@
1
- import { SolanaPoolInfo, TrancheType } from '@huma-finance/shared'
2
- import {
3
- SolanaPoolState,
4
- useLenderAccounts,
5
- useTokenAccount,
6
- } from '@huma-finance/web-shared'
7
- import React, { useCallback, useEffect, useState } from 'react'
8
- import { useDispatch } from 'react-redux'
9
-
10
- import { useAppSelector } from '../../../hooks/useRedux'
11
- import { setStep } from '../../../store/widgets.reducers'
12
- import { selectWidgetState } from '../../../store/widgets.selectors'
13
- import { WIDGET_STEP } from '../../../store/widgets.store'
14
- import { ErrorModal } from '../../ErrorModal'
15
- import { WidgetWrapper } from '../../WidgetWrapper'
16
- import { Evaluation } from './1-Evaluation'
17
- import { ChooseTranche } from './2-ChooseTranche'
18
- import { ChooseAmount } from './3-ChooseAmount'
19
- import { Transfer } from './4-Transfer'
20
- import { Success } from './5-Success'
21
-
22
- /**
23
- * Lend pool supply props
24
- * @typedef {Object} SolanaLendSupplyProps
25
- * @property {SolanaPoolInfo} poolInfo The metadata of the pool.
26
- * @property {SolanaPoolState} poolState The current state config of the pool.
27
- * @property {function():void} handleClose Function to notify to close the widget modal when user clicks the 'x' close button.
28
- * @property {function():void|undefined} handleSuccess Optional function to notify that the lending pool supply action is successful.
29
- */
30
- export interface SolanaLendSupplyProps {
31
- poolInfo: SolanaPoolInfo
32
- poolState: SolanaPoolState
33
- handleClose: () => void
34
- handleSuccess?: () => void
35
- }
36
-
37
- export function SolanaLendSupply({
38
- poolInfo,
39
- poolState,
40
- handleClose,
41
- handleSuccess,
42
- }: SolanaLendSupplyProps): React.ReactElement | null {
43
- const dispatch = useDispatch()
44
- const { isUniTranche } = poolState
45
- const {
46
- seniorLenderApproved,
47
- juniorLenderApproved,
48
- loading: isLoadingLenderAccounts,
49
- refresh: refreshLenderAccounts,
50
- } = useLenderAccounts(poolInfo.chainId, poolInfo.poolName)
51
- const [tokenAccount, isLoadingTokenAccount] = useTokenAccount(poolInfo)
52
- const { step, errorMessage } = useAppSelector(selectWidgetState)
53
- const [selectedTranche, setSelectedTranche] = useState<TrancheType>()
54
-
55
- useEffect(() => {
56
- if (!step && !isLoadingLenderAccounts && !isLoadingTokenAccount) {
57
- if (!juniorLenderApproved && !seniorLenderApproved) {
58
- dispatch(setStep(WIDGET_STEP.Evaluation))
59
- return
60
- }
61
-
62
- if (juniorLenderApproved && !seniorLenderApproved) {
63
- setSelectedTranche('junior')
64
- dispatch(setStep(WIDGET_STEP.ChooseAmount))
65
- return
66
- }
67
-
68
- if (seniorLenderApproved && !juniorLenderApproved) {
69
- setSelectedTranche('senior')
70
- dispatch(setStep(WIDGET_STEP.ChooseAmount))
71
- return
72
- }
73
-
74
- if (juniorLenderApproved && seniorLenderApproved) {
75
- dispatch(setStep(WIDGET_STEP.ChooseTranche))
76
- }
77
- }
78
- }, [
79
- dispatch,
80
- handleClose,
81
- poolInfo,
82
- step,
83
- isLoadingLenderAccounts,
84
- juniorLenderApproved,
85
- seniorLenderApproved,
86
- isLoadingTokenAccount,
87
- ])
88
-
89
- const handleApproveSuccess = useCallback(() => {
90
- refreshLenderAccounts()
91
- }, [refreshLenderAccounts])
92
-
93
- if (isLoadingLenderAccounts || isLoadingTokenAccount) {
94
- return (
95
- <WidgetWrapper
96
- isOpen
97
- isLoading
98
- loadingTitle='Supply'
99
- handleClose={handleClose}
100
- handleSuccess={handleSuccess}
101
- />
102
- )
103
- }
104
-
105
- return (
106
- <WidgetWrapper
107
- isOpen
108
- loadingTitle={`Supply ${poolInfo.underlyingMint.symbol}`}
109
- handleClose={handleClose}
110
- handleSuccess={handleSuccess}
111
- >
112
- {step === WIDGET_STEP.Evaluation && (
113
- <Evaluation
114
- poolInfo={poolInfo}
115
- isUniTranche={isUniTranche}
116
- handleApproveSuccess={handleApproveSuccess}
117
- />
118
- )}
119
- {step === WIDGET_STEP.ChooseTranche && (
120
- <ChooseTranche
121
- poolUnderlyingToken={poolInfo.underlyingMint}
122
- selectedTranche={selectedTranche}
123
- changeTranche={setSelectedTranche}
124
- />
125
- )}
126
- {step === WIDGET_STEP.ChooseAmount && (
127
- <ChooseAmount
128
- poolInfo={poolInfo}
129
- poolState={poolState}
130
- tokenAccount={tokenAccount}
131
- selectedTranche={selectedTranche}
132
- isUniTranche={isUniTranche}
133
- />
134
- )}
135
- {step === WIDGET_STEP.Transfer && selectedTranche && (
136
- <Transfer poolInfo={poolInfo} selectedTranche={selectedTranche} />
137
- )}
138
- {step === WIDGET_STEP.Done && (
139
- <Success
140
- poolInfo={poolInfo}
141
- poolState={poolState}
142
- handleAction={handleClose}
143
- />
144
- )}
145
- {step === WIDGET_STEP.Error && (
146
- <ErrorModal
147
- title='Supply'
148
- errorReason='Sorry there was an error'
149
- errorMessage={errorMessage}
150
- handleOk={handleClose}
151
- />
152
- )}
153
- </WidgetWrapper>
154
- )
155
- }
@@ -1,119 +0,0 @@
1
- import { Box, Button, css, Typography, useTheme } from '@mui/material'
2
- import React, { useCallback } from 'react'
3
-
4
- import { SolanaChainEnum } from '@huma-finance/shared'
5
- import { useAppDispatch } from '../hooks/useRedux'
6
- import { resetState } from '../store/widgets.reducers'
7
- import { CheckIcon } from './icons'
8
- import { SolanaViewOnExplorer } from './SolanaViewOnExplorer'
9
-
10
- type Props = {
11
- content: string[]
12
- subContent?: string[]
13
- buttonText?: string
14
- solanaSignature?: string
15
- chainId?: SolanaChainEnum
16
- handleAction: () => void
17
- }
18
-
19
- export function SolanaTxDoneModal({
20
- content,
21
- subContent,
22
- handleAction,
23
- solanaSignature,
24
- chainId,
25
- buttonText,
26
- }: Props): React.ReactElement {
27
- const theme = useTheme()
28
- const dispatch = useAppDispatch()
29
-
30
- const styles = {
31
- wrapper: css`
32
- height: 518px;
33
- position: relative;
34
- `,
35
- header: css`
36
- ${theme.cssMixins.rowHCentered};
37
- margin-top: ${theme.spacing(-0.5)};
38
- `,
39
- content: css`
40
- ${theme.cssMixins.colVCentered};
41
- font-weight: ${subContent ? 700 : 400};
42
- font-size: 18px;
43
- color: ${theme.palette.text.secondary};
44
- margin-top: ${theme.spacing(8)};
45
- text-align: center;
46
- `,
47
- subContent: css`
48
- ${theme.cssMixins.colVCentered};
49
- font-weight: 400;
50
- font-size: 18px;
51
- color: ${theme.palette.text.primary};
52
- margin-top: ${theme.spacing(2)};
53
- text-align: center;
54
- `,
55
- check: css`
56
- width: 100%;
57
- ${theme.cssMixins.rowHCentered};
58
- margin-top: ${theme.spacing(10)};
59
- `,
60
- bottomButtonGroup: css`
61
- width: 100%;
62
- position: absolute;
63
- bottom: 0;
64
- display: flex;
65
- row-gap: ${theme.spacing(1)};
66
- column-gap: ${theme.spacing(1)};
67
-
68
- button {
69
- height: 40px;
70
- margin-top: ${theme.spacing(1)};
71
- }
72
- `,
73
- }
74
-
75
- const handleCloseModal = useCallback(() => {
76
- dispatch(resetState())
77
- handleAction()
78
- }, [dispatch, handleAction])
79
-
80
- return (
81
- <Box css={styles.wrapper}>
82
- <Typography variant='h6' css={styles.header}>
83
- Transaction Completed
84
- </Typography>
85
- <Box css={styles.check}>
86
- <CheckIcon />
87
- </Box>
88
- <Box css={styles.content}>
89
- {content.map((item) => (
90
- <Box sx={{ marginTop: theme.spacing(1) }} key={item}>
91
- {item}
92
- </Box>
93
- ))}
94
- </Box>
95
- {subContent && (
96
- <Box css={styles.subContent}>
97
- {subContent.map((item) => (
98
- <Box sx={{ marginTop: theme.spacing(1) }} key={item}>
99
- {item}
100
- </Box>
101
- ))}
102
- </Box>
103
- )}
104
- <Box css={styles.bottomButtonGroup}>
105
- {solanaSignature && chainId && (
106
- <SolanaViewOnExplorer signature={solanaSignature} chainId={chainId} />
107
- )}
108
- <Button
109
- className='transaction-done-modal-close-btn'
110
- variant='contained'
111
- fullWidth
112
- onClick={handleCloseModal}
113
- >
114
- {!buttonText ? 'DONE' : buttonText}
115
- </Button>
116
- </Box>
117
- </Box>
118
- )
119
- }
@@ -1,61 +0,0 @@
1
- import { SolanaChainEnum } from '@huma-finance/shared'
2
- import React, { useEffect, useState } from 'react'
3
-
4
- import { useConnection, useWallet } from '@solana/wallet-adapter-react'
5
- import { Transaction } from '@solana/web3.js'
6
- import { setError, setSolanaSignature } from '../store/widgets.reducers'
7
- import { LoadingModal } from './LoadingModal'
8
- import { SolanaViewOnExplorer } from './SolanaViewOnExplorer'
9
- import { useAppDispatch } from '../hooks/useRedux'
10
-
11
- type Props = {
12
- chainId: SolanaChainEnum
13
- tx?: Transaction
14
- handleSuccess: () => void
15
- }
16
-
17
- export function SolanaTxSendModal({
18
- chainId,
19
- tx,
20
- handleSuccess,
21
- }: Props): React.ReactElement | null {
22
- const dispatch = useAppDispatch()
23
- const { sendTransaction } = useWallet()
24
- const { connection } = useConnection()
25
- const [signature, setSignature] = useState<string>('')
26
-
27
- useEffect(() => {
28
- async function sendTx() {
29
- if (!connection || !tx) {
30
- return
31
- }
32
-
33
- try {
34
- const latestBlockHash = await connection.getLatestBlockhash()
35
- const signature = await sendTransaction(tx, connection)
36
- setSignature(signature)
37
- dispatch(setSolanaSignature(signature))
38
-
39
- await connection.confirmTransaction({
40
- blockhash: latestBlockHash.blockhash,
41
- lastValidBlockHeight: latestBlockHash.lastValidBlockHeight,
42
- signature,
43
- })
44
- handleSuccess()
45
- } catch (error: unknown) {
46
- const err = error as Error
47
- dispatch(setError({ errorMessage: err?.message || '' }))
48
- }
49
- }
50
- sendTx()
51
- }, [connection, dispatch, handleSuccess, sendTransaction, tx])
52
-
53
- return (
54
- <LoadingModal
55
- title='Transaction Pending'
56
- description='Waiting for confirmation...'
57
- >
58
- <SolanaViewOnExplorer chainId={chainId} signature={signature} />
59
- </LoadingModal>
60
- )
61
- }
@@ -1,29 +0,0 @@
1
- import { Box, Button } from '@mui/material'
2
- import {
3
- getSolanaExplorerUrl,
4
- openInNewTab,
5
- SolanaChainEnum,
6
- } from '@huma-finance/shared'
7
- import React from 'react'
8
-
9
- type Props = {
10
- chainId: SolanaChainEnum
11
- signature: string
12
- }
13
-
14
- export function SolanaViewOnExplorer({
15
- chainId,
16
- signature,
17
- }: Props): React.ReactElement | null {
18
- const link = getSolanaExplorerUrl(chainId, signature, 'tx')
19
-
20
- if (!link) {
21
- return null
22
- }
23
-
24
- return (
25
- <Button fullWidth variant='outlined' onClick={() => openInNewTab(link)}>
26
- <Box component='span'>VIEW ON EXPLORER</Box>
27
- </Button>
28
- )
29
- }