@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.
Files changed (40) hide show
  1. package/API.md +0 -185
  2. package/dist/cjs/index.cjs +955 -2880
  3. package/dist/cjs/index.cjs.map +1 -1
  4. package/dist/index.d.ts +8 -116
  5. package/dist/index.js +658 -2601
  6. package/dist/index.js.map +1 -1
  7. package/package.json +9 -12
  8. package/src/components/InputAmountModal.tsx +2 -12
  9. package/src/components/Lend/addRedemptionV2/2-ChooseAmount.tsx +6 -1
  10. package/src/components/Lend/supplyV2/6-Success.tsx +10 -8
  11. package/src/components/Lend/supplyV2/7-Notifications.tsx +6 -1
  12. package/src/components/Notifi/NotifiContextWrapper.tsx +57 -0
  13. package/src/components/Notifi/NotifiSubscriptionModal.tsx +118 -113
  14. package/src/components/WidgetWrapper.tsx +4 -6
  15. package/src/hooks/useNotifi.ts +28 -17
  16. package/src/index.tsx +7 -124
  17. package/src/store/widgets.reducers.ts +0 -5
  18. package/src/store/widgets.store.ts +0 -1
  19. package/src/theme/coreThemeConstants.ts +1 -1
  20. package/src/components/CreditLine/solanaBorrow/1-ChooseAmount.tsx +0 -86
  21. package/src/components/CreditLine/solanaBorrow/2-ApproveAllowance.tsx +0 -87
  22. package/src/components/CreditLine/solanaBorrow/index.tsx +0 -96
  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 -140
  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 -152
  32. package/src/components/Lend/solanaSupply/1-ChooseTranche.tsx +0 -116
  33. package/src/components/Lend/solanaSupply/2-Evaluation.tsx +0 -0
  34. package/src/components/Lend/solanaSupply/3-ChooseAmount.tsx +0 -130
  35. package/src/components/Lend/solanaSupply/4-Transfer.tsx +0 -89
  36. package/src/components/Lend/solanaSupply/5-Success.tsx +0 -50
  37. package/src/components/Lend/solanaSupply/index.tsx +0 -143
  38. package/src/components/SolanaTxDoneModal.tsx +0 -115
  39. package/src/components/SolanaTxSendModal.tsx +0 -61
  40. package/src/components/SolanaViewOnExplorer.tsx +0 -29
@@ -1,143 +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, { useEffect, useState } from 'react'
8
- import { useDispatch } from 'react-redux'
9
-
10
- import { useAppSelector } from '../../../hooks/useRedux'
11
- import { selectWidgetState } from '../../../store/widgets.selectors'
12
- import { WidgetWrapper } from '../../WidgetWrapper'
13
- import { WIDGET_STEP } from '../../../store/widgets.store'
14
- import { ChooseTranche } from './1-ChooseTranche'
15
- import { ChooseAmount } from './3-ChooseAmount'
16
- import { setStep } from '../../../store/widgets.reducers'
17
- import { ErrorModal } from '../../ErrorModal'
18
- import { Transfer } from './4-Transfer'
19
- import { Success } from './5-Success'
20
-
21
- /**
22
- * Lend pool supply props
23
- * @typedef {Object} SolanaLendSupplyProps
24
- * @property {SolanaPoolInfo} poolInfo The metadata of the pool.
25
- * @property {SolanaPoolState} poolState The current state config of the pool.
26
- * @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 SolanaLendSupplyProps {
30
- poolInfo: SolanaPoolInfo
31
- poolState: SolanaPoolState
32
- handleClose: () => void
33
- handleSuccess?: () => void
34
- }
35
-
36
- export function SolanaLendSupply({
37
- poolInfo,
38
- poolState,
39
- handleClose,
40
- handleSuccess,
41
- }: SolanaLendSupplyProps): React.ReactElement | null {
42
- const dispatch = useDispatch()
43
- const {
44
- seniorLenderApproved,
45
- juniorLenderApproved,
46
- loading: isLoadingLenderAccounts,
47
- } = useLenderAccounts(poolInfo.chainId, poolInfo.poolName)
48
- const [tokenAccount, isLoadingTokenAccount] = useTokenAccount(poolInfo)
49
- const { step, errorMessage } = useAppSelector(selectWidgetState)
50
- const isUniTranche = poolState.maxSeniorJuniorRatio === 0
51
- const [selectedTranche, setSelectedTranche] = useState<TrancheType>()
52
-
53
- useEffect(() => {
54
- if (!step && !isLoadingLenderAccounts && !isLoadingTokenAccount) {
55
- if (juniorLenderApproved && !seniorLenderApproved) {
56
- setSelectedTranche('junior')
57
- dispatch(setStep(WIDGET_STEP.ChooseAmount))
58
- return
59
- }
60
-
61
- if (seniorLenderApproved && !juniorLenderApproved) {
62
- setSelectedTranche('senior')
63
- dispatch(setStep(WIDGET_STEP.ChooseAmount))
64
- return
65
- }
66
-
67
- if (juniorLenderApproved && seniorLenderApproved) {
68
- dispatch(setStep(WIDGET_STEP.ChooseTranche))
69
- // return
70
- }
71
-
72
- // if (poolInfo.supplyLink) {
73
- // openInNewTab(poolInfo.supplyLink)
74
- // handleClose()
75
- // }
76
- }
77
- }, [
78
- dispatch,
79
- handleClose,
80
- poolInfo,
81
- step,
82
- isLoadingLenderAccounts,
83
- juniorLenderApproved,
84
- seniorLenderApproved,
85
- isLoadingTokenAccount,
86
- ])
87
-
88
- if (isLoadingLenderAccounts || isLoadingTokenAccount) {
89
- return (
90
- <WidgetWrapper
91
- isOpen
92
- isLoading
93
- loadingTitle='Supply'
94
- handleClose={handleClose}
95
- handleSuccess={handleSuccess}
96
- />
97
- )
98
- }
99
-
100
- return (
101
- <WidgetWrapper
102
- isOpen
103
- loadingTitle={`Supply ${poolInfo.underlyingMint.symbol}`}
104
- handleClose={handleClose}
105
- handleSuccess={handleSuccess}
106
- >
107
- {step === WIDGET_STEP.ChooseTranche && (
108
- <ChooseTranche
109
- poolUnderlyingToken={poolInfo.underlyingMint}
110
- selectedTranche={selectedTranche}
111
- changeTranche={setSelectedTranche}
112
- />
113
- )}
114
- {step === WIDGET_STEP.ChooseAmount && (
115
- <ChooseAmount
116
- poolInfo={poolInfo}
117
- poolState={poolState}
118
- tokenAccount={tokenAccount!}
119
- selectedTranche={selectedTranche}
120
- isUniTranche={isUniTranche}
121
- />
122
- )}
123
- {step === WIDGET_STEP.Transfer && selectedTranche && (
124
- <Transfer poolInfo={poolInfo} selectedTranche={selectedTranche} />
125
- )}
126
- {step === WIDGET_STEP.Done && (
127
- <Success
128
- poolInfo={poolInfo}
129
- poolState={poolState}
130
- handleAction={handleClose}
131
- />
132
- )}
133
- {step === WIDGET_STEP.Error && (
134
- <ErrorModal
135
- title='Supply'
136
- errorReason='Sorry there was an error'
137
- errorMessage={errorMessage}
138
- handleOk={handleClose}
139
- />
140
- )}
141
- </WidgetWrapper>
142
- )
143
- }
@@ -1,115 +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
- `,
65
- bottomButton: css`
66
- margin-top: ${theme.spacing(1)};
67
- `,
68
- }
69
-
70
- const handleCloseModal = useCallback(() => {
71
- dispatch(resetState())
72
- handleAction()
73
- }, [dispatch, handleAction])
74
-
75
- return (
76
- <Box css={styles.wrapper}>
77
- <Typography variant='h6' css={styles.header}>
78
- Transaction Completed
79
- </Typography>
80
- <Box css={styles.check}>
81
- <CheckIcon />
82
- </Box>
83
- <Box css={styles.content}>
84
- {content.map((item) => (
85
- <Box sx={{ marginTop: theme.spacing(1) }} key={item}>
86
- {item}
87
- </Box>
88
- ))}
89
- </Box>
90
- {subContent && (
91
- <Box css={styles.subContent}>
92
- {subContent.map((item) => (
93
- <Box sx={{ marginTop: theme.spacing(1) }} key={item}>
94
- {item}
95
- </Box>
96
- ))}
97
- </Box>
98
- )}
99
- <Box css={styles.bottomButtonGroup}>
100
- {solanaSignature && chainId && (
101
- <SolanaViewOnExplorer signature={solanaSignature} chainId={chainId} />
102
- )}
103
- <Button
104
- className='transaction-done-modal-close-btn'
105
- variant='contained'
106
- fullWidth
107
- css={styles.bottomButton}
108
- onClick={handleCloseModal}
109
- >
110
- {!buttonText ? 'DONE' : buttonText}
111
- </Button>
112
- </Box>
113
- </Box>
114
- )
115
- }
@@ -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
- }