@huma-finance/widgets 0.0.62-beta.627 → 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.
@@ -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
- }