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

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 (43) hide show
  1. package/API.md +195 -0
  2. package/dist/cjs/index.cjs +1871 -299
  3. package/dist/cjs/index.cjs.map +1 -1
  4. package/dist/index.d.ts +138 -2
  5. package/dist/index.js +1869 -302
  6. package/dist/index.js.map +1 -1
  7. package/package.json +18 -8
  8. package/src/components/CreditLine/paymentV2/1-ChooseAmount.tsx +1 -0
  9. package/src/components/CreditLine/solanaBorrow/1-ChooseAmount.tsx +67 -0
  10. package/src/components/CreditLine/solanaBorrow/2-Transfer.tsx +159 -0
  11. package/src/components/CreditLine/solanaBorrow/3-Done.tsx +38 -0
  12. package/src/components/CreditLine/solanaBorrow/index.tsx +93 -0
  13. package/src/components/CreditLine/solanaPayment/1-ChooseAmount.tsx +75 -0
  14. package/src/components/CreditLine/solanaPayment/2-Transfer.tsx +92 -0
  15. package/src/components/CreditLine/solanaPayment/3-Done.tsx +60 -0
  16. package/src/components/CreditLine/solanaPayment/index.tsx +86 -0
  17. package/src/components/InputAmountModal.tsx +13 -2
  18. package/src/components/Lend/{supplyV2/components → components}/PersonaEvaluation.tsx +19 -13
  19. package/src/components/Lend/{supplyV2/components → components}/SecuritizeEvaluation.tsx +7 -8
  20. package/src/components/Lend/solanaAddRedemption/1-ChooseTranche.tsx +114 -0
  21. package/src/components/Lend/solanaAddRedemption/2-ChooseAmount.tsx +183 -0
  22. package/src/components/Lend/solanaAddRedemption/3-Transfer.tsx +102 -0
  23. package/src/components/Lend/solanaAddRedemption/4-Done.tsx +29 -0
  24. package/src/components/Lend/solanaAddRedemption/index.tsx +155 -0
  25. package/src/components/Lend/solanaCancelRedemption/1-ChooseTranche.tsx +114 -0
  26. package/src/components/Lend/solanaCancelRedemption/2-Transfer.tsx +99 -0
  27. package/src/components/Lend/solanaCancelRedemption/3-Done.tsx +55 -0
  28. package/src/components/Lend/solanaCancelRedemption/index.tsx +162 -0
  29. package/src/components/Lend/solanaSupply/1-Evaluation.tsx +43 -0
  30. package/src/components/Lend/solanaSupply/2-ChooseTranche.tsx +116 -0
  31. package/src/components/Lend/solanaSupply/3-ChooseAmount.tsx +131 -0
  32. package/src/components/Lend/solanaSupply/4-Transfer.tsx +137 -0
  33. package/src/components/Lend/solanaSupply/5-Success.tsx +52 -0
  34. package/src/components/Lend/solanaSupply/index.tsx +155 -0
  35. package/src/components/Lend/supplyV2/2-Evaluation.tsx +4 -3
  36. package/src/components/Lend/supplyV2/6-Success.tsx +3 -3
  37. package/src/components/SolanaTxDoneModal.tsx +119 -0
  38. package/src/components/SolanaTxSendModal.tsx +61 -0
  39. package/src/components/SolanaViewOnExplorer.tsx +29 -0
  40. package/src/components/WidgetWrapper.tsx +6 -4
  41. package/src/index.tsx +139 -0
  42. package/src/store/widgets.reducers.ts +5 -0
  43. package/src/store/widgets.store.ts +1 -0
@@ -0,0 +1,119 @@
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
+ }
@@ -0,0 +1,61 @@
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
+ }
@@ -0,0 +1,29 @@
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
+ }
@@ -31,7 +31,7 @@ export function WidgetWrapper({
31
31
  }: WCProps<Props>): React.ReactElement | null {
32
32
  const theme = useTheme()
33
33
  const dispatch = useAppDispatch()
34
- const { step } = useAppSelector(selectWidgetState)
34
+ const { step, solanaSignature } = useAppSelector(selectWidgetState)
35
35
  const [{ state, failReason, txReceipt }] = useAtom(sendTxAtom)
36
36
  const reset = useResetAtom(txAtom)
37
37
 
@@ -42,12 +42,14 @@ export function WidgetWrapper({
42
42
  }, [dispatch, failReason, state])
43
43
 
44
44
  useEffect(() => {
45
- if (step === WIDGET_STEP.Done && txReceipt) {
46
- if (handleSuccess) {
45
+ if (step === WIDGET_STEP.Done && (txReceipt || solanaSignature)) {
46
+ if (handleSuccess && txReceipt) {
47
47
  handleSuccess(txReceipt.blockNumber)
48
+ } else if (handleSuccess && solanaSignature) {
49
+ handleSuccess(0) // solana tx doesn't have block number
48
50
  }
49
51
  }
50
- }, [handleSuccess, step, txReceipt])
52
+ }, [handleSuccess, solanaSignature, step, txReceipt])
51
53
 
52
54
  const handleCloseModal = useCallback(() => {
53
55
  reset()
package/src/index.tsx CHANGED
@@ -73,6 +73,26 @@ import { SuperfluidFactoring } from './components/SuperfluidFactoring'
73
73
  import { store } from './store'
74
74
  import { themeHuma } from './theme'
75
75
  import { WCProps } from './utilTypes'
76
+ import {
77
+ SolanaLendSupply,
78
+ SolanaLendSupplyProps,
79
+ } from './components/Lend/solanaSupply'
80
+ import {
81
+ SolanaLendAddRedemption,
82
+ SolanaLendAddRedemptionProps,
83
+ } from './components/Lend/solanaAddRedemption'
84
+ import {
85
+ SolanaLendCancelRedemption,
86
+ SolanaLendCancelRedemptionProps,
87
+ } from './components/Lend/solanaCancelRedemption'
88
+ import {
89
+ SolanaBorrow,
90
+ SolanaBorrowProps,
91
+ } from './components/CreditLine/solanaBorrow'
92
+ import {
93
+ SolanaPayment,
94
+ SolanaPaymentProps,
95
+ } from './components/CreditLine/solanaPayment'
76
96
  import { NotifiContextWrapper } from './components/Notifi/NotifiContextWrapper'
77
97
 
78
98
  /**
@@ -534,4 +554,123 @@ export function ReceivableBackedCreditLinePaymentWidgetV2(
534
554
  )
535
555
  }
536
556
 
557
+ /**
558
+ * Object representing the props passed to Solana widgets
559
+ * @typedef {Object} SolanaWidgetProps
560
+ */
561
+ type SolanaWidgetProps = {
562
+ handleClose?: () => void
563
+ }
564
+
565
+ function SolanaWidget(props: WCProps<SolanaWidgetProps>) {
566
+ const { children } = props
567
+
568
+ return (
569
+ <ThemeProvider theme={themeHuma}>
570
+ <ReduxProvider store={store}>{children}</ReduxProvider>
571
+ </ThemeProvider>
572
+ )
573
+ }
574
+
575
+ /**
576
+ * Lend pool supply widget props for Solana pools
577
+ * @typedef {Object} SolanaLendSupplyWidgetProps
578
+ */
579
+ type SolanaLendSupplyWidgetProps = SolanaLendSupplyProps & SolanaWidgetProps
580
+
581
+ /**
582
+ * Lend pool supply widget for Solana pools
583
+ *
584
+ * @param {SolanaLendSupplyWidgetProps} props - Widget props
585
+ */
586
+ export function SolanaLendSupplyWidget(props: SolanaLendSupplyWidgetProps) {
587
+ return (
588
+ <SolanaWidget {...props}>
589
+ <SolanaLendSupply {...props} />
590
+ </SolanaWidget>
591
+ )
592
+ }
593
+
594
+ /**
595
+ * Lend pool supply widget props for Solana pools
596
+ * @typedef {Object} SolanaLendAddRedemptionWidgetProps
597
+ */
598
+ type SolanaLendAddRedemptionWidgetProps = SolanaLendAddRedemptionProps &
599
+ SolanaWidgetProps
600
+
601
+ /**
602
+ * Lend pool supply widget for Solana pools
603
+ *
604
+ * @param {SolanaLendAddRedemptionWidgetProps} props - Widget props
605
+ */
606
+ export function SolanaLendAddRedemptionWidget(
607
+ props: SolanaLendAddRedemptionWidgetProps,
608
+ ) {
609
+ return (
610
+ <SolanaWidget {...props}>
611
+ <SolanaLendAddRedemption {...props} />
612
+ </SolanaWidget>
613
+ )
614
+ }
615
+
616
+ /**
617
+ * Lend pool supply widget props for Solana pools
618
+ * @typedef {Object} SolanaLendCancelRedemptionWidgetProps
619
+ */
620
+ type SolanaLendCancelRedemptionWidgetProps = SolanaLendCancelRedemptionProps &
621
+ SolanaWidgetProps
622
+
623
+ /**
624
+ * Lend pool supply widget for Solana pools
625
+ *
626
+ * @param {SolanaLendCancelRedemptionWidgetProps} props - Widget props
627
+ */
628
+ export function SolanaLendCancelRedemptionWidget(
629
+ props: SolanaLendCancelRedemptionWidgetProps,
630
+ ) {
631
+ return (
632
+ <SolanaWidget {...props}>
633
+ <SolanaLendCancelRedemption {...props} />
634
+ </SolanaWidget>
635
+ )
636
+ }
637
+
638
+ /**
639
+ * Lend pool supply widget props for Solana pools
640
+ * @typedef {Object} SolanaBorrowWidgetProps
641
+ */
642
+ type SolanaBorrowWidgetProps = SolanaBorrowProps & SolanaWidgetProps
643
+
644
+ /**
645
+ * Lend pool supply widget for Solana pools
646
+ *
647
+ * @param {SolanaBorrowWidgetProps} props - Widget props
648
+ */
649
+ export function SolanaBorrowWidget(props: SolanaBorrowWidgetProps) {
650
+ return (
651
+ <SolanaWidget {...props}>
652
+ <SolanaBorrow {...props} />
653
+ </SolanaWidget>
654
+ )
655
+ }
656
+
657
+ /**
658
+ * Lend pool supply widget props for Solana pools
659
+ * @typedef {Object} SolanaPaymentWidgetProps
660
+ */
661
+ type SolanaPaymentWidgetProps = SolanaPaymentProps & SolanaWidgetProps
662
+
663
+ /**
664
+ * Lend pool supply widget for Solana pools
665
+ *
666
+ * @param {SolanaPaymentWidgetProps} props - Widget props
667
+ */
668
+ export function SolanaPaymentWidget(props: SolanaPaymentWidgetProps) {
669
+ return (
670
+ <SolanaWidget {...props}>
671
+ <SolanaPayment {...props} />
672
+ </SolanaWidget>
673
+ )
674
+ }
675
+
537
676
  export * from './components/Notifi/NotifiContextWrapper'
@@ -32,6 +32,7 @@ export const widgetSlice = createSlice({
32
32
  state.withdrawShares = undefined
33
33
  state.redeemAmount = undefined
34
34
  state.redeemShares = undefined
35
+ state.solanaSignature = undefined
35
36
  },
36
37
  setStep: (state, { payload }: PayloadAction<WIDGET_STEP>) => {
37
38
  state.step = payload
@@ -102,6 +103,9 @@ export const widgetSlice = createSlice({
102
103
  setMultisend: (state, { payload }: PayloadAction<MultisendPayload>) => {
103
104
  state.multisend = payload
104
105
  },
106
+ setSolanaSignature: (state, { payload }: PayloadAction<string>) => {
107
+ state.solanaSignature = payload
108
+ },
105
109
  setError: (
106
110
  state,
107
111
  {
@@ -130,6 +134,7 @@ export const {
130
134
  setWithdrawShares,
131
135
  setRedeemAmount,
132
136
  setRedeemShares,
137
+ setSolanaSignature,
133
138
  } = widgetSlice.actions
134
139
 
135
140
  export default widgetSlice.reducer
@@ -58,6 +58,7 @@ export type WidgetState = {
58
58
  tokenId?: string
59
59
  stream?: WidgetStream
60
60
  multisend?: MultisendPayload
61
+ solanaSignature?: string
61
62
  }
62
63
 
63
64
  export const initialWidgetState: WidgetState = {}