@huma-finance/widgets 0.0.62-beta.624 → 0.0.62-beta.630

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 (36) hide show
  1. package/API.md +34 -26
  2. package/dist/cjs/index.cjs +742 -1110
  3. package/dist/cjs/index.cjs.map +1 -1
  4. package/dist/index.d.ts +33 -9
  5. package/dist/index.js +997 -1343
  6. package/dist/index.js.map +1 -1
  7. package/package.json +12 -5
  8. package/src/components/CreditLine/paymentV2/1-ChooseAmount.tsx +1 -0
  9. package/src/components/CreditLine/solanaBorrow/1-ChooseAmount.tsx +2 -21
  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 +19 -25
  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 +59 -0
  16. package/src/components/CreditLine/solanaPayment/index.tsx +83 -0
  17. package/src/components/InputAmountModal.tsx +1 -0
  18. package/src/components/Lend/addRedemptionV2/2-ChooseAmount.tsx +6 -1
  19. package/src/components/Lend/solanaCancelRedemption/index.tsx +11 -1
  20. package/src/components/Lend/solanaSupply/5-Success.tsx +10 -8
  21. package/src/components/Lend/supplyV2/6-Success.tsx +10 -8
  22. package/src/components/Lend/supplyV2/7-Notifications.tsx +6 -1
  23. package/src/components/Notifi/NotifiContextWrapper.tsx +57 -0
  24. package/src/components/Notifi/NotifiSubscriptionModal.tsx +118 -113
  25. package/src/components/SuperfluidFactoring/index.tsx +12 -46
  26. package/src/hooks/useNotifi.ts +28 -17
  27. package/src/index.tsx +31 -9
  28. package/src/theme/coreThemeConstants.ts +1 -1
  29. package/src/components/Activity.tsx +0 -128
  30. package/src/components/CreditLine/solanaBorrow/2-ApproveAllowance.tsx +0 -89
  31. package/src/components/Factoring/FactoredList.tsx +0 -143
  32. package/src/components/Factoring/UpcomingList.tsx +0 -90
  33. package/src/components/Factoring/index.ts +0 -2
  34. package/src/components/HumaTable.tsx +0 -203
  35. package/src/components/SuperfluidFactoring/SuperfluidFactoredList.tsx +0 -69
  36. package/src/components/SuperfluidFactoring/SuperfluidUpcomingList.tsx +0 -169
@@ -1,203 +0,0 @@
1
- import { Box, css, Skeleton, TablePagination, useTheme } from '@mui/material'
2
- import Table from '@mui/material/Table'
3
- import TableBody from '@mui/material/TableBody'
4
- import TableCell from '@mui/material/TableCell'
5
- import TableContainer from '@mui/material/TableContainer'
6
- import TableHead from '@mui/material/TableHead'
7
- import TableRow from '@mui/material/TableRow'
8
- import * as React from 'react'
9
-
10
- import { useElementDimensions } from '../hooks/useElementDimensions'
11
- import { ColumnType } from '../utilTypes'
12
- import { SeparatorIcon } from './icons'
13
-
14
- type Props<T> = {
15
- columns: ColumnType<T>[]
16
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
17
- rows?: any[]
18
- hideRowsPerPage?: boolean
19
- }
20
-
21
- // @TODO: Move HumaTable along with Superfluid widget to Dapp package
22
- export function HumaTable<T>({
23
- columns,
24
- rows,
25
- hideRowsPerPage = false,
26
- }: Props<T>): React.ReactElement | null {
27
- const theme = useTheme()
28
- const ref = React.useRef()
29
- const [page, setPage] = React.useState(0)
30
- const [rowsPerPage, setRowsPerPage] = React.useState(5)
31
- const noPagination = rows ? rows.length <= 5 : true
32
- const rowPerPageOptions = hideRowsPerPage ? [] : [5, 10, 25]
33
- const { width } = useElementDimensions(ref)
34
- const isLoading = !columns || !rows
35
-
36
- const styles = {
37
- tableHeader: css`
38
- font-weight: 400;
39
- ${theme.cssMixins.rowVCentered}
40
- font-size: 14px;
41
- color: rgba(0, 0, 0, 0.87);
42
- `,
43
- tableBody: css`
44
- font-weight: 400;
45
- font-size: 14px;
46
- color: rgba(0, 0, 0, 0.87);
47
- `,
48
- empty: css`
49
- display: flex;
50
- flex-direction: column;
51
- align-items: center;
52
- margin-top: ${theme.spacing(2)};
53
- font-weight: 400;
54
- font-size: 14px;
55
- `,
56
- }
57
-
58
- const handleChangePage = (event: unknown, newPage: number) => {
59
- setPage(newPage)
60
- }
61
-
62
- const handleChangeRowsPerPage = (
63
- event: React.ChangeEvent<HTMLInputElement>,
64
- ) => {
65
- setRowsPerPage(parseInt(event.target.value, 10))
66
- setPage(0)
67
- }
68
-
69
- const getTableHeader = () => (
70
- <TableHead>
71
- <TableRow>
72
- {columns.map((column, index) => (
73
- <TableCell key={column.title} width={column.width}>
74
- <Box css={styles.tableHeader}>
75
- {index !== 0 && <SeparatorIcon />}
76
- <Box component='span' sx={{ marginLeft: index ? '12px' : '0' }}>
77
- {column.title}
78
- </Box>
79
- </Box>
80
- </TableCell>
81
- ))}
82
- </TableRow>
83
- </TableHead>
84
- )
85
-
86
- if (isLoading) {
87
- return (
88
- <Box ref={ref}>
89
- <Box sx={{ width }}>
90
- <Skeleton />
91
- <Skeleton />
92
- <Skeleton />
93
- </Box>
94
- </Box>
95
- )
96
- }
97
-
98
- if (rows.length === 0) {
99
- return (
100
- <TableContainer>
101
- <Table aria-label='simple table'>{getTableHeader()}</Table>
102
- <Box css={styles.empty}>
103
- <Box>No Data</Box>
104
- </Box>
105
- </TableContainer>
106
- )
107
- }
108
-
109
- return (
110
- <>
111
- <TableContainer>
112
- <Table aria-label='simple table'>
113
- {getTableHeader()}
114
- <TableBody>
115
- {rows
116
- .slice(page * rowsPerPage, page * rowsPerPage + rowsPerPage)
117
- .map((row) => (
118
- <TableRow key={row.id || row.name}>
119
- {columns.map((column, index) => (
120
- <TableCell
121
- // eslint-disable-next-line react/no-array-index-key
122
- key={`${column.dataIndex}-${index}`}
123
- component='th'
124
- scope='row'
125
- css={styles.tableBody}
126
- width={column.width}
127
- sx={column.style}
128
- >
129
- {column.dataIndex && (
130
- <Box
131
- component='span'
132
- sx={{
133
- display: 'flex',
134
- alignItems: 'center',
135
- marginLeft: theme.spacing(index ? 1 : 0),
136
- }}
137
- >
138
- {row[column.dataIndex]}
139
- </Box>
140
- )}
141
- {column.action && (
142
- <Box
143
- component='span'
144
- sx={{
145
- display: 'flex',
146
- alignItems: 'center',
147
- marginLeft: theme.spacing(index ? 1 : 0),
148
- lineHeight: 0,
149
- height: 0,
150
- }}
151
- >
152
- {column.action(row)}
153
- </Box>
154
- )}
155
- </TableCell>
156
- ))}
157
- </TableRow>
158
- ))}
159
- </TableBody>
160
- </Table>
161
- </TableContainer>
162
- {!noPagination && (
163
- <TablePagination
164
- size='small'
165
- sx={{
166
- '.MuiTablePagination-selectLabel': {
167
- fontSize: '12px',
168
- },
169
- '.MuiTablePagination-select': {
170
- fontSize: '12px',
171
- },
172
- '.MuiTablePagination-displayedRows': {
173
- fontSize: '12px',
174
- },
175
- '.MuiTablePagination-menuItem': {
176
- fontSize: '14px',
177
- },
178
- }}
179
- rowsPerPageOptions={rowPerPageOptions}
180
- component='div'
181
- count={rows ? rows.length : 0}
182
- rowsPerPage={rowsPerPage}
183
- page={page}
184
- onPageChange={handleChangePage}
185
- onRowsPerPageChange={handleChangeRowsPerPage}
186
- SelectProps={{
187
- MenuProps: {
188
- sx: {
189
- '.MuiTablePagination-menuItem': {
190
- padding: theme.spacing(1, 0),
191
- display: 'flex',
192
- justifyContent: 'center',
193
- fontSize: '14px',
194
- lineHeight: '1.2',
195
- },
196
- },
197
- },
198
- }}
199
- />
200
- )}
201
- </>
202
- )
203
- }
@@ -1,69 +0,0 @@
1
- import { EmotionJSX } from '@emotion/react/types/jsx-namespace'
2
- import { AccountStats, PoolInfoType } from '@huma-finance/shared'
3
- import React, { useCallback } from 'react'
4
-
5
- import { ColumnType } from '../../utilTypes'
6
- import { FactoredList } from '../Factoring'
7
-
8
- type FactoredStreamType = {
9
- id: string
10
- icon: EmotionJSX.Element
11
- name: string
12
- payer: string
13
- amount?: string | number
14
- factored?: string | number
15
- token: string
16
- tokenId: string
17
- flowrate: string
18
- flowrateMonth: string
19
- due?: string
20
- remained?: string | number
21
- }
22
-
23
- type Props = {
24
- poolInfo: PoolInfoType
25
- loading: boolean
26
- accountStats: AccountStats
27
- handlePayManually: (item: FactoredStreamType) => void
28
- }
29
-
30
- const getColumns = (): ColumnType<FactoredStreamType>[] => [
31
- {
32
- title: '',
33
- dataIndex: 'icon',
34
- width: 10,
35
- style: { padding: '0 0 0 16px' },
36
- },
37
- { title: 'Streams', dataIndex: 'name' },
38
- { title: 'Due', dataIndex: 'due' },
39
- { title: 'Amount', dataIndex: 'amount' },
40
- { title: 'Factored', dataIndex: 'factored' },
41
- { title: 'Remaining', dataIndex: 'remained' },
42
- ]
43
-
44
- export function SuperfluidFactoredList({
45
- poolInfo,
46
- loading,
47
- accountStats,
48
- handlePayManually,
49
- }: Props): React.ReactElement {
50
- const setItem = useCallback(
51
- () =>
52
- Promise.resolve({
53
- name: poolInfo?.extra?.superToken?.symbol ?? '',
54
- }),
55
- [poolInfo?.extra?.superToken],
56
- )
57
-
58
- return (
59
- <FactoredList
60
- title='Streams'
61
- poolInfo={poolInfo}
62
- loading={loading}
63
- handlePayManually={handlePayManually}
64
- getColumns={getColumns}
65
- accountStats={accountStats}
66
- setItem={setItem}
67
- />
68
- )
69
- }
@@ -1,169 +0,0 @@
1
- import { gql, useQuery } from '@apollo/client'
2
- import { EmotionJSX } from '@emotion/react/types/jsx-namespace'
3
- import {
4
- downScale,
5
- getWalletAddressAbbr,
6
- PoolInfoType,
7
- toBigNumber,
8
- } from '@huma-finance/shared'
9
- import { Button, useTheme } from '@mui/material'
10
- import { useWeb3React } from '@web3-react/core'
11
- import React, { useCallback, useEffect, useState } from 'react'
12
-
13
- import { ColumnType } from '../../utilTypes'
14
- import { TableActionButton } from '../buttons'
15
- import { UpcomingList } from '../Factoring'
16
- import { ReceiptIcon } from '../icons'
17
-
18
- const GET_RECEIVED_STREAMS = gql`
19
- query GetReceivedStreams($receiver: String!, $tokenIds: [String]!) {
20
- streams(
21
- where: { receiver: $receiver, token_in: $tokenIds, currentFlowRate_gt: 0 }
22
- orderBy: updatedAtTimestamp
23
- orderDirection: desc
24
- ) {
25
- id
26
- currentFlowRate
27
- sender {
28
- id
29
- }
30
- token {
31
- id
32
- symbol
33
- decimals
34
- }
35
- }
36
- }
37
- `
38
-
39
- export type StreamItem = {
40
- id: string
41
- icon: EmotionJSX.Element
42
- token: string
43
- tokenId: string
44
- payer: string
45
- flowrate: string
46
- flowrateMonth: string
47
- }
48
-
49
- type Stream = {
50
- id: string
51
- currentFlowRate: string
52
- sender: {
53
- id: string
54
- }
55
- token: {
56
- id: string
57
- symbol: string
58
- decimals: number
59
- }
60
- }
61
-
62
- type Props = {
63
- hasActiveLoan: boolean
64
- poolInfo?: PoolInfoType
65
- loading: boolean
66
- handleGetPaid: (item: StreamItem) => void
67
- }
68
-
69
- const getUpcomingColumns = (
70
- userHasActiveLoan: boolean,
71
- handleGetPaid: (id: StreamItem) => void,
72
- ): ColumnType<StreamItem>[] => [
73
- {
74
- title: '',
75
- dataIndex: 'icon',
76
- width: 10,
77
- style: { padding: '0 0 0 16px' },
78
- },
79
- { title: 'Stream', dataIndex: 'token' },
80
- {
81
- title: 'Payer',
82
- dataIndex: 'payerAbbr',
83
- },
84
- { title: 'Flow rate', dataIndex: 'flowrateMonth' },
85
- {
86
- title: 'Get Paid',
87
- action: (record) => (
88
- <TableActionButton
89
- title='GET PAID NOW'
90
- handleClick={() => handleGetPaid(record)}
91
- disabled={userHasActiveLoan}
92
- />
93
- ),
94
- },
95
- ]
96
-
97
- export function SuperfluidUpcomingList({
98
- hasActiveLoan,
99
- poolInfo,
100
- loading,
101
- handleGetPaid,
102
- }: Props): React.ReactElement {
103
- const theme = useTheme()
104
- const { account, isActive } = useWeb3React()
105
- const [streams, setStreams] = useState<StreamItem[] | undefined>()
106
- const { data } = useQuery<{ streams: Stream[] }>(GET_RECEIVED_STREAMS, {
107
- variables: {
108
- receiver: account ? account.toLowerCase() : undefined,
109
- tokenIds: poolInfo?.extra?.superToken
110
- ? [poolInfo.extra.superToken.id]
111
- : [],
112
- },
113
- })
114
-
115
- useEffect(() => {
116
- if (data?.streams?.length) {
117
- let result: Array<StreamItem | undefined> = data.streams.map((item) => {
118
- const ONE_MONTH_SECONDS = 30 * 24 * 60 * 60
119
- const flowrateMonth = downScale(
120
- toBigNumber(item.currentFlowRate).mul(ONE_MONTH_SECONDS),
121
- item.token.decimals,
122
- )
123
- if (Number(Number(flowrateMonth).toFixed(0)) > 0) {
124
- return {
125
- id: item.id,
126
- icon: <ReceiptIcon css={{ width: '24px' }} />,
127
- token: item.token.symbol,
128
- tokenId: item.token.id,
129
- payer: item.sender.id,
130
- payerAbbr: getWalletAddressAbbr(item.sender.id),
131
- flowrate: item.currentFlowRate,
132
- flowrateMonth: `${Number(flowrateMonth).toFixed(0)}/mo`,
133
- }
134
- }
135
- return undefined
136
- })
137
- result = result.filter((item) => !!item)
138
- setStreams(result as StreamItem[])
139
- }
140
- }, [data])
141
-
142
- const goToCreateStream = useCallback(() => {}, [])
143
-
144
- return (
145
- <UpcomingList<StreamItem>
146
- items={streams}
147
- loading={loading}
148
- columns={getUpcomingColumns(hasActiveLoan, handleGetPaid)}
149
- title='Ongoing Streams'
150
- connectWalletDesc='Please connect wallet to check your ongoing streams.'
151
- noItemDesc='You don’t have any ongoing streams eligible for factoring. For now, you can click the button
152
- below to create streams.'
153
- >
154
- {isActive && (
155
- <Button
156
- onClick={goToCreateStream}
157
- type='link'
158
- size='small'
159
- variant='contained'
160
- sx={{ marginTop: theme.spacing(2) }}
161
- href='https://app.superfluid.finance/'
162
- target='_blank'
163
- >
164
- CREATE STREAM
165
- </Button>
166
- )}
167
- </UpcomingList>
168
- )
169
- }