@huma-finance/widgets 0.0.6-alpha.0

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 (203) hide show
  1. package/.env.example +3 -0
  2. package/.eslintignore +2 -0
  3. package/.eslintrc.js +64 -0
  4. package/.prettierignore +4 -0
  5. package/.prettierrc.js +16 -0
  6. package/API.md +331 -0
  7. package/LICENSE +661 -0
  8. package/README.md +48 -0
  9. package/babel.config.js +15 -0
  10. package/config-overrides.js +9 -0
  11. package/cosmos.config.json +7 -0
  12. package/cypress/e2e/01-invoice-factoring-borrow.test.ts +62 -0
  13. package/cypress/support/e2e.ts +76 -0
  14. package/cypress/support/ethereum.ts +142 -0
  15. package/cypress/tsconfig.json +9 -0
  16. package/cypress/utils/index.ts +54 -0
  17. package/cypress.config.ts +20 -0
  18. package/dist/assets/output-15e10f9f.css +44 -0
  19. package/dist/cjs/assets/output-15e10f9f.css +44 -0
  20. package/dist/cjs/index.cjs +17576 -0
  21. package/dist/cjs/index.cjs.map +1 -0
  22. package/dist/index.d.ts +211 -0
  23. package/dist/index.js +17529 -0
  24. package/dist/index.js.map +1 -0
  25. package/jsdoc2md.json +20 -0
  26. package/package.json +193 -0
  27. package/public/favicon.ico +0 -0
  28. package/public/index.html +40 -0
  29. package/public/logo192.png +0 -0
  30. package/public/logo512.png +0 -0
  31. package/public/manifest.json +25 -0
  32. package/public/robots.txt +3 -0
  33. package/rollup.config.js +81 -0
  34. package/src/components/Activity.tsx +123 -0
  35. package/src/components/AllowListModal.tsx +113 -0
  36. package/src/components/ApolloWrapper.tsx +15 -0
  37. package/src/components/ApproveAllowanceModal.tsx +118 -0
  38. package/src/components/BottomButton.tsx +31 -0
  39. package/src/components/ChooseAmountModal.tsx +315 -0
  40. package/src/components/CreditLine/borrow/1-Evaluation.tsx +159 -0
  41. package/src/components/CreditLine/borrow/2-AllowList.tsx +34 -0
  42. package/src/components/CreditLine/borrow/3-ChooseAmount.tsx +74 -0
  43. package/src/components/CreditLine/borrow/4-ApproveAllowance.tsx +29 -0
  44. package/src/components/CreditLine/borrow/5-Transfer.tsx +30 -0
  45. package/src/components/CreditLine/borrow/6-Success.tsx +30 -0
  46. package/src/components/CreditLine/borrow/index.tsx +119 -0
  47. package/src/components/CreditLine/payment/1-ChooseAmount.tsx +67 -0
  48. package/src/components/CreditLine/payment/2-ApproveAllowance.tsx +23 -0
  49. package/src/components/CreditLine/payment/3-Transfer.tsx +34 -0
  50. package/src/components/CreditLine/payment/4-Success.tsx +39 -0
  51. package/src/components/CreditLine/payment/index.tsx +94 -0
  52. package/src/components/ErrorModal.tsx +132 -0
  53. package/src/components/Factoring/FactoredList.tsx +143 -0
  54. package/src/components/Factoring/UpcomingList.tsx +90 -0
  55. package/src/components/Factoring/index.ts +2 -0
  56. package/src/components/HumaLoading.tsx +68 -0
  57. package/src/components/HumaTable.tsx +158 -0
  58. package/src/components/InvoiceFactoring/borrow/1-Evaluation.tsx +46 -0
  59. package/src/components/InvoiceFactoring/borrow/2-AllowList.tsx +34 -0
  60. package/src/components/InvoiceFactoring/borrow/3-ChooseAmount.tsx +92 -0
  61. package/src/components/InvoiceFactoring/borrow/4-ConfirmTransfer.tsx +104 -0
  62. package/src/components/InvoiceFactoring/borrow/5-ApproveNFT.tsx +55 -0
  63. package/src/components/InvoiceFactoring/borrow/6-Transfer.tsx +34 -0
  64. package/src/components/InvoiceFactoring/borrow/7-Success.tsx +20 -0
  65. package/src/components/InvoiceFactoring/borrow/index.tsx +96 -0
  66. package/src/components/InvoiceFactoring/payment/1-ChooseAmount.tsx +67 -0
  67. package/src/components/InvoiceFactoring/payment/2-ApproveAllowance.tsx +23 -0
  68. package/src/components/InvoiceFactoring/payment/3-Transfer.tsx +34 -0
  69. package/src/components/InvoiceFactoring/payment/4-Success.tsx +23 -0
  70. package/src/components/InvoiceFactoring/payment/index.tsx +86 -0
  71. package/src/components/Lend/supply/1-Evaluation.tsx +86 -0
  72. package/src/components/Lend/supply/2-ChooseAmount.tsx +70 -0
  73. package/src/components/Lend/supply/3-ApproveAllowance.tsx +25 -0
  74. package/src/components/Lend/supply/4-ConfirmTransfer.tsx +104 -0
  75. package/src/components/Lend/supply/6-Transfer.tsx +32 -0
  76. package/src/components/Lend/supply/7-Success.tsx +49 -0
  77. package/src/components/Lend/supply/index.tsx +144 -0
  78. package/src/components/Lend/withdraw/1-CheckWithdrawble.tsx +73 -0
  79. package/src/components/Lend/withdraw/2-ChooseAmount.tsx +50 -0
  80. package/src/components/Lend/withdraw/3-Transfer.tsx +32 -0
  81. package/src/components/Lend/withdraw/4-Success.tsx +49 -0
  82. package/src/components/Lend/withdraw/index.tsx +101 -0
  83. package/src/components/LoadingModal.tsx +49 -0
  84. package/src/components/StreamFactoring/borrow/1-Evaluation.tsx +57 -0
  85. package/src/components/StreamFactoring/borrow/2-ChooseAmount.tsx +124 -0
  86. package/src/components/StreamFactoring/borrow/3-ConfirmTransfer.tsx +104 -0
  87. package/src/components/StreamFactoring/borrow/4-ApproveAllowance.tsx +65 -0
  88. package/src/components/StreamFactoring/borrow/5-Permit.tsx +144 -0
  89. package/src/components/StreamFactoring/borrow/6-Transfer.tsx +37 -0
  90. package/src/components/StreamFactoring/borrow/7-Success.tsx +20 -0
  91. package/src/components/StreamFactoring/borrow/index.tsx +95 -0
  92. package/src/components/StreamFactoring/payment/ChooseAmount.tsx +54 -0
  93. package/src/components/StreamFactoring/payment/Success.tsx +23 -0
  94. package/src/components/StreamFactoring/payment/Transfer.tsx +34 -0
  95. package/src/components/StreamFactoring/payment/index.tsx +66 -0
  96. package/src/components/SuperfluidFactoring/SuperfluidFactoredList.tsx +61 -0
  97. package/src/components/SuperfluidFactoring/SuperfluidUpcomingList.tsx +185 -0
  98. package/src/components/SuperfluidFactoring/index.tsx +85 -0
  99. package/src/components/TxDoneModal.tsx +83 -0
  100. package/src/components/TxSendModal.tsx +59 -0
  101. package/src/components/ViewOnExplorer.tsx +26 -0
  102. package/src/components/WidgetWrapper.tsx +74 -0
  103. package/src/components/WrapperModal.tsx +54 -0
  104. package/src/components/buttons/TableActionButton.tsx +36 -0
  105. package/src/components/buttons/index.ts +1 -0
  106. package/src/components/humaModal/HumaModal.tsx +68 -0
  107. package/src/components/humaModal/HumaModalHeader.tsx +70 -0
  108. package/src/components/humaModal/index.tsx +2 -0
  109. package/src/components/icons/approve-lender.svg +30 -0
  110. package/src/components/icons/auto-payback.svg +40 -0
  111. package/src/components/icons/check-circle.svg +3 -0
  112. package/src/components/icons/check-green.svg +3 -0
  113. package/src/components/icons/check.svg +10 -0
  114. package/src/components/icons/donut.svg +904 -0
  115. package/src/components/icons/ellipse.svg +3 -0
  116. package/src/components/icons/ethereum.svg +1 -0
  117. package/src/components/icons/huma-full.svg +22 -0
  118. package/src/components/icons/huma.svg +15 -0
  119. package/src/components/icons/index.tsx +93 -0
  120. package/src/components/icons/loader.svg +229 -0
  121. package/src/components/icons/metamask.svg +31 -0
  122. package/src/components/icons/polygon.svg +16 -0
  123. package/src/components/icons/receipt.svg +3 -0
  124. package/src/components/icons/separator.svg +3 -0
  125. package/src/components/icons/sorry.svg +31 -0
  126. package/src/components/icons/spinner.gif +0 -0
  127. package/src/components/icons/usdc.svg +5 -0
  128. package/src/components/icons/wallet-connect.svg +12 -0
  129. package/src/cosmos/CreditLineBorrow.fixture.tsx +85 -0
  130. package/src/cosmos/CreditLinePayment.fixture.tsx +49 -0
  131. package/src/cosmos/InvoiceFactoringBorrow.fixture.tsx +111 -0
  132. package/src/cosmos/InvoiceFactoringPayment.fixture.tsx +67 -0
  133. package/src/cosmos/LendSupply.fixture.tsx +75 -0
  134. package/src/cosmos/LendWithdraw.fixture.tsx +43 -0
  135. package/src/cosmos/SDKTesting.fixture.tsx +507 -0
  136. package/src/cosmos/SuperfluidFactoringBorrow.fixture.tsx +12 -0
  137. package/src/cosmos/WalletWrapper.tsx +52 -0
  138. package/src/cosmos/abis/InvoiceNFT.json +644 -0
  139. package/src/cosmos/abis/ReceivableFactoringPool.json +1529 -0
  140. package/src/cosmos/utils/index.ts +169 -0
  141. package/src/fonts/Inter/Inter-Black.ttf +0 -0
  142. package/src/fonts/Inter/Inter-Bold.ttf +0 -0
  143. package/src/fonts/Inter/Inter-ExtraBold.ttf +0 -0
  144. package/src/fonts/Inter/Inter-ExtraLight.ttf +0 -0
  145. package/src/fonts/Inter/Inter-Light.ttf +0 -0
  146. package/src/fonts/Inter/Inter-Medium.ttf +0 -0
  147. package/src/fonts/Inter/Inter-Regular.ttf +0 -0
  148. package/src/fonts/Inter/Inter-SemiBold.ttf +0 -0
  149. package/src/fonts/Inter/Inter-Thin.ttf +0 -0
  150. package/src/fonts/Recoleta/Recoleta-Black.otf +0 -0
  151. package/src/fonts/Recoleta/Recoleta-Bold.otf +0 -0
  152. package/src/fonts/Recoleta/Recoleta-Light.otf +0 -0
  153. package/src/fonts/Recoleta/Recoleta-Medium.otf +0 -0
  154. package/src/fonts/Recoleta/Recoleta-Regular.otf +0 -0
  155. package/src/fonts/Recoleta/Recoleta-RegularDEMO.otf +0 -0
  156. package/src/fonts/Recoleta/Recoleta-SemiBold.otf +0 -0
  157. package/src/fonts/Recoleta/Recoleta-Thin.otf +0 -0
  158. package/src/fonts/Roboto/LICENSE.txt +202 -0
  159. package/src/fonts/Roboto/Roboto-Black.ttf +0 -0
  160. package/src/fonts/Roboto/Roboto-BlackItalic.ttf +0 -0
  161. package/src/fonts/Roboto/Roboto-Bold.ttf +0 -0
  162. package/src/fonts/Roboto/Roboto-BoldItalic.ttf +0 -0
  163. package/src/fonts/Roboto/Roboto-Italic.ttf +0 -0
  164. package/src/fonts/Roboto/Roboto-Light.ttf +0 -0
  165. package/src/fonts/Roboto/Roboto-LightItalic.ttf +0 -0
  166. package/src/fonts/Roboto/Roboto-Medium.ttf +0 -0
  167. package/src/fonts/Roboto/Roboto-MediumItalic.ttf +0 -0
  168. package/src/fonts/Roboto/Roboto-Regular.ttf +0 -0
  169. package/src/fonts/Roboto/Roboto-Thin.ttf +0 -0
  170. package/src/fonts/Roboto/Roboto-ThinItalic.ttf +0 -0
  171. package/src/fonts/UniNeue/UniNeue-Black.ttf +0 -0
  172. package/src/fonts/UniNeue/UniNeue-Bold.ttf +0 -0
  173. package/src/fonts/UniNeue/UniNeue-Book.ttf +0 -0
  174. package/src/fonts/UniNeue/UniNeue-Heavy.ttf +0 -0
  175. package/src/fonts/UniNeue/UniNeue-Light.ttf +0 -0
  176. package/src/fonts/UniNeue/UniNeue-Regular.ttf +0 -0
  177. package/src/fonts/UniNeue/UniNeue-Thin.ttf +0 -0
  178. package/src/hooks/useEA.ts +70 -0
  179. package/src/hooks/useRedux.ts +6 -0
  180. package/src/index.css +61 -0
  181. package/src/index.tsx +219 -0
  182. package/src/react-app-env.d.ts +1 -0
  183. package/src/reportWebVitals.ts +15 -0
  184. package/src/setupTests.ts +6 -0
  185. package/src/store/index.ts +27 -0
  186. package/src/store/widgets.reducers.ts +120 -0
  187. package/src/store/widgets.selectors.ts +3 -0
  188. package/src/store/widgets.store.ts +55 -0
  189. package/src/theme/breakpoints.ts +10 -0
  190. package/src/theme/components.ts +70 -0
  191. package/src/theme/coreThemeConstants.ts +29 -0
  192. package/src/theme/cssMixins.ts +92 -0
  193. package/src/theme/hooks/useGetSizes.ts +34 -0
  194. package/src/theme/index.ts +24 -0
  195. package/src/theme/palette.ts +150 -0
  196. package/src/theme/shape.ts +7 -0
  197. package/src/theme/theme.types.ts +80 -0
  198. package/src/theme/typography.ts +117 -0
  199. package/src/utilTypes.d.ts +29 -0
  200. package/src/utils/env.ts +9 -0
  201. package/tsconfig.build.json +7 -0
  202. package/tsconfig.json +32 -0
  203. package/webpack.cosmos.js +54 -0
@@ -0,0 +1,95 @@
1
+ import { useWeb3React } from '@web3-react/core'
2
+ import { POOL_NAME, POOL_TYPE, usePoolInfo } from '@huma-finance/shared'
3
+ import React, { useEffect } from 'react'
4
+ import { useDispatch } from 'react-redux'
5
+
6
+ import { useAppSelector } from '../../../hooks/useRedux'
7
+ import { setStep } from '../../../store/widgets.reducers'
8
+ import { selectWidgetState } from '../../../store/widgets.selectors'
9
+ import { WIDGET_STEP } from '../../../store/widgets.store'
10
+ import { ErrorModal } from '../../ErrorModal'
11
+ import { WidgetWrapper } from '../../WidgetWrapper'
12
+ import { Evaluation } from './1-Evaluation'
13
+ import { ChooseAmount } from './2-ChooseAmount'
14
+ import { ConfirmTransfer } from './3-ConfirmTransfer'
15
+ import { ApproveAllowance } from './4-ApproveAllowance'
16
+ import { Permit } from './5-Permit'
17
+ import { Transfer } from './6-Transfer'
18
+ import { Success } from './7-Success'
19
+
20
+ export type StreamFactoringBorrowProps = {
21
+ poolName: POOL_NAME
22
+ poolType: POOL_TYPE
23
+ payerAddress: string
24
+ superToken: string
25
+ currentFlowRate: string
26
+ isOpen: boolean
27
+ handleClose: () => void
28
+ handleSuccess: (blockNumber: number) => void
29
+ }
30
+
31
+ export function StreamFactoringBorrow({
32
+ poolName,
33
+ poolType,
34
+ payerAddress,
35
+ superToken,
36
+ currentFlowRate,
37
+ isOpen,
38
+ handleClose,
39
+ handleSuccess,
40
+ }: StreamFactoringBorrowProps): React.ReactElement | null {
41
+ const dispatch = useDispatch()
42
+ const { account, chainId } = useWeb3React()
43
+ const poolInfo = usePoolInfo(poolName, poolType)
44
+ const { step, errorMessage } = useAppSelector(selectWidgetState)
45
+
46
+ useEffect(() => {
47
+ dispatch(setStep(WIDGET_STEP.Evaluation))
48
+ }, [dispatch])
49
+
50
+ if (!poolInfo) {
51
+ return null
52
+ }
53
+
54
+ return (
55
+ <WidgetWrapper
56
+ isOpen={isOpen}
57
+ handleClose={handleClose}
58
+ handleSuccess={handleSuccess}
59
+ >
60
+ {step === WIDGET_STEP.Evaluation && (
61
+ <Evaluation
62
+ poolInfo={poolInfo}
63
+ payerAddress={payerAddress}
64
+ superToken={superToken}
65
+ currentFlowRate={currentFlowRate}
66
+ />
67
+ )}
68
+ {step === WIDGET_STEP.ChooseAmount && (
69
+ <ChooseAmount poolInfo={poolInfo} currentFlowRate={currentFlowRate} />
70
+ )}
71
+ {step === WIDGET_STEP.ConfirmTransfer && <ConfirmTransfer />}
72
+ {step === WIDGET_STEP.ApproveAllowance && (
73
+ <ApproveAllowance poolInfo={poolInfo} />
74
+ )}
75
+ {step === WIDGET_STEP.Permit && account && chainId && (
76
+ <Permit
77
+ poolInfo={poolInfo}
78
+ payerAddress={payerAddress}
79
+ chainId={chainId}
80
+ borrower={account}
81
+ superToken={superToken}
82
+ />
83
+ )}
84
+ {step === WIDGET_STEP.Transfer && <Transfer poolInfo={poolInfo} />}
85
+ {step === WIDGET_STEP.Done && <Success handleAction={handleClose} />}
86
+ {step === WIDGET_STEP.Error && (
87
+ <ErrorModal
88
+ title='Stream Borrowing'
89
+ errorMessage={errorMessage}
90
+ handleOk={handleClose}
91
+ />
92
+ )}
93
+ </WidgetWrapper>
94
+ )
95
+ }
@@ -0,0 +1,54 @@
1
+ import { CreditRecordType, downScale, PoolInfoType } from '@huma-finance/shared'
2
+ import React, { useCallback, useState } from 'react'
3
+
4
+ import { useAppDispatch } from '../../../hooks/useRedux'
5
+ import { setPaymentAmount, setStep } from '../../../store/widgets.reducers'
6
+ import { WIDGET_STEP } from '../../../store/widgets.store'
7
+ import { ChooseAmountModal } from '../../ChooseAmountModal'
8
+
9
+ type Props = {
10
+ creditRecord: CreditRecordType
11
+ poolInfo: PoolInfoType
12
+ }
13
+
14
+ export function ChooseAmount({
15
+ creditRecord,
16
+ poolInfo,
17
+ }: Props): React.ReactElement | null {
18
+ const dispatch = useAppDispatch()
19
+ const { symbol, decimals } = poolInfo.poolUnderlyingToken
20
+ const totalDue = downScale<number>(creditRecord.totalDue.toString(), decimals)
21
+ const [remainingDue, setRemainingDue] = useState(totalDue)
22
+ const [currentAmount, setCurrentAmount] = useState(0)
23
+
24
+ const handleChangeAmount = useCallback(
25
+ (newAmount: number) => {
26
+ setCurrentAmount(newAmount)
27
+ const remainDueAmount = totalDue - newAmount
28
+ setRemainingDue(remainDueAmount)
29
+ dispatch(setPaymentAmount({ paymentAmount: newAmount, remainDueAmount }))
30
+ },
31
+ [dispatch, totalDue],
32
+ )
33
+
34
+ const handleAction = useCallback(() => {
35
+ dispatch(setStep(WIDGET_STEP.Transfer))
36
+ }, [dispatch])
37
+
38
+ return (
39
+ <ChooseAmountModal
40
+ title='Make the payment'
41
+ description1='Choose amount'
42
+ sliderMax={totalDue}
43
+ currentAmount={currentAmount}
44
+ tokenSymbol={symbol}
45
+ topLeft='Total Due'
46
+ topRight={`${totalDue} ${symbol}`}
47
+ downLeft='Remaining Due'
48
+ downRight={`${remainingDue} ${symbol}`}
49
+ handleChangeAmount={handleChangeAmount}
50
+ handleAction={handleAction}
51
+ actionText='make payment'
52
+ />
53
+ )
54
+ }
@@ -0,0 +1,23 @@
1
+ import { PoolInfoType } from '@huma-finance/shared'
2
+ import React from 'react'
3
+
4
+ import { useAppSelector } from '../../../hooks/useRedux'
5
+ import { selectWidgetState } from '../../../store/widgets.selectors'
6
+ import { TxDoneModal } from '../../TxDoneModal'
7
+
8
+ type Props = {
9
+ poolInfo: PoolInfoType
10
+ handleAction: () => void
11
+ }
12
+
13
+ export function Success({ poolInfo, handleAction }: Props): React.ReactElement {
14
+ const { symbol } = poolInfo.poolUnderlyingToken
15
+ const { paymentAmount, remainDueAmount } = useAppSelector(selectWidgetState)
16
+
17
+ const content = [
18
+ `You have successfully made a payment of ${paymentAmount} ${symbol}.`,
19
+ `The remaining due amount is ${remainDueAmount} ${symbol}.`,
20
+ ]
21
+
22
+ return <TxDoneModal handleAction={handleAction} content={content} />
23
+ }
@@ -0,0 +1,34 @@
1
+ import { useWeb3React } from '@web3-react/core'
2
+ import { PoolInfoType, toBigNumber, upScale } from '@huma-finance/shared'
3
+ import React, { useCallback } from 'react'
4
+
5
+ import { useAppDispatch, useAppSelector } from '../../../hooks/useRedux'
6
+ import { setStep } from '../../../store/widgets.reducers'
7
+ import { selectWidgetState } from '../../../store/widgets.selectors'
8
+ import { WIDGET_STEP } from '../../../store/widgets.store'
9
+ import { TxSendModal } from '../../TxSendModal'
10
+
11
+ type Props = {
12
+ poolInfo: PoolInfoType
13
+ }
14
+
15
+ export function Transfer({ poolInfo }: Props): React.ReactElement {
16
+ const dispatch = useAppDispatch()
17
+ const { account } = useWeb3React()
18
+ const { decimals } = poolInfo.poolUnderlyingToken
19
+ const { paymentAmount } = useAppSelector(selectWidgetState)
20
+ const paymentBigNumber = toBigNumber(upScale(paymentAmount!, decimals))
21
+
22
+ const handleSuccess = useCallback(() => {
23
+ dispatch(setStep(WIDGET_STEP.Done))
24
+ }, [dispatch])
25
+
26
+ return (
27
+ <TxSendModal
28
+ poolInfo={poolInfo}
29
+ method='makePayment'
30
+ params={[account, paymentBigNumber]}
31
+ handleSuccess={handleSuccess}
32
+ />
33
+ )
34
+ }
@@ -0,0 +1,66 @@
1
+ import { useWeb3React } from '@web3-react/core'
2
+ import { PoolInfoType, useAccountStats } from '@huma-finance/shared'
3
+ import React, { useEffect } from 'react'
4
+ import { useDispatch } from 'react-redux'
5
+
6
+ import { useAppSelector } from '../../../hooks/useRedux'
7
+ import { setStep } from '../../../store/widgets.reducers'
8
+ import { selectWidgetState } from '../../../store/widgets.selectors'
9
+ import { WIDGET_STEP } from '../../../store/widgets.store'
10
+ import { ErrorModal } from '../../ErrorModal'
11
+ import { WidgetWrapper } from '../../WidgetWrapper'
12
+ import { ChooseAmount } from './ChooseAmount'
13
+ import { Success } from './Success'
14
+ import { Transfer } from './Transfer'
15
+
16
+ type Props = {
17
+ poolInfo: PoolInfoType
18
+ isOpen: boolean
19
+ handleClose: () => void
20
+ handleSuccess: (blockNumber: number) => void
21
+ }
22
+
23
+ export function StreamFactoringPayment({
24
+ poolInfo,
25
+ isOpen,
26
+ handleClose,
27
+ handleSuccess,
28
+ }: Props): React.ReactElement | null {
29
+ const dispatch = useDispatch()
30
+ const { account } = useWeb3React()
31
+ const { step, errorMessage } = useAppSelector(selectWidgetState)
32
+ const [{ creditRecord }] = useAccountStats(
33
+ poolInfo.poolName,
34
+ poolInfo.poolType,
35
+ account,
36
+ )
37
+
38
+ useEffect(() => {
39
+ dispatch(setStep(WIDGET_STEP.ChooseAmount))
40
+ }, [dispatch])
41
+
42
+ return (
43
+ <WidgetWrapper
44
+ isOpen={isOpen}
45
+ isLoading={!creditRecord}
46
+ loadingTitle='Payment'
47
+ handleClose={handleClose}
48
+ handleSuccess={handleSuccess}
49
+ >
50
+ {step === WIDGET_STEP.ChooseAmount && (
51
+ <ChooseAmount creditRecord={creditRecord!} poolInfo={poolInfo} />
52
+ )}
53
+ {step === WIDGET_STEP.Transfer && <Transfer poolInfo={poolInfo} />}
54
+ {step === WIDGET_STEP.Done && (
55
+ <Success poolInfo={poolInfo} handleAction={handleClose} />
56
+ )}
57
+ {step === WIDGET_STEP.Error && (
58
+ <ErrorModal
59
+ title='Make Payment'
60
+ errorMessage={errorMessage}
61
+ handleOk={handleClose}
62
+ />
63
+ )}
64
+ </WidgetWrapper>
65
+ )
66
+ }
@@ -0,0 +1,61 @@
1
+ import { EmotionJSX } from '@emotion/react/types/jsx-namespace'
2
+ import { AccountStats, PoolInfoType } from '@huma-finance/shared'
3
+ import React 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
+ noSeparator: true,
35
+ width: 10,
36
+ style: { padding: '0 0 0 16px' },
37
+ },
38
+ { title: 'Streams', dataIndex: 'name' },
39
+ { title: 'Due', dataIndex: 'due' },
40
+ { title: 'Amount', dataIndex: 'amount' },
41
+ { title: 'Factored', dataIndex: 'factored' },
42
+ { title: 'Remaining', dataIndex: 'remained' },
43
+ ]
44
+
45
+ export function SuperfluidFactoredList({
46
+ poolInfo,
47
+ loading,
48
+ accountStats,
49
+ handlePayManually,
50
+ }: Props): React.ReactElement {
51
+ return (
52
+ <FactoredList
53
+ title='Streams'
54
+ poolInfo={poolInfo}
55
+ loading={loading}
56
+ handlePayManually={handlePayManually}
57
+ getColumns={getColumns}
58
+ accountStats={accountStats}
59
+ />
60
+ )
61
+ }
@@ -0,0 +1,185 @@
1
+ import { gql, useQuery } from '@apollo/client'
2
+ import { EmotionJSX } from '@emotion/react/types/jsx-namespace'
3
+ import { Button } from '@mui/material'
4
+ import { useWeb3React } from '@web3-react/core'
5
+ import { History } from 'history'
6
+ import {
7
+ downScale,
8
+ getWalletAddressAbbr,
9
+ PoolInfoType,
10
+ toBigNumber,
11
+ } from '@huma-finance/shared'
12
+ import React, { useCallback, useEffect, useState } from 'react'
13
+ import { useHistory } from 'react-router'
14
+
15
+ import { ColumnType } from '../../utilTypes'
16
+ import { TableActionButton } from '../buttons'
17
+ import { UpcomingList } from '../Factoring'
18
+ import { ReceiptIcon } from '../icons'
19
+
20
+ const GET_RECEIVED_STREAMS = gql`
21
+ query GetReceivedStreams($receiver: String!, $tokenIds: [String]!) {
22
+ streams(
23
+ where: { receiver: $receiver, token_in: $tokenIds, currentFlowRate_gt: 0 }
24
+ orderBy: updatedAtTimestamp
25
+ orderDirection: desc
26
+ ) {
27
+ id
28
+ currentFlowRate
29
+ sender {
30
+ id
31
+ }
32
+ token {
33
+ id
34
+ symbol
35
+ decimals
36
+ }
37
+ }
38
+ }
39
+ `
40
+
41
+ export type StreamItem = {
42
+ id: string
43
+ icon: EmotionJSX.Element
44
+ token: string
45
+ tokenId: string
46
+ payer: string
47
+ flowrate: string
48
+ flowrateMonth: string
49
+ }
50
+
51
+ type Stream = {
52
+ id: string
53
+ currentFlowRate: string
54
+ sender: {
55
+ id: string
56
+ }
57
+ token: {
58
+ id: string
59
+ symbol: string
60
+ decimals: number
61
+ }
62
+ }
63
+
64
+ type Props = {
65
+ hasActiveLoan: boolean
66
+ poolInfo?: PoolInfoType
67
+ loading: boolean
68
+ handleGetPaid: (item: StreamItem) => void
69
+ }
70
+
71
+ const getUpcomingColumns = (
72
+ userHasActiveLoan: boolean,
73
+ handleGetPaid: (id: StreamItem) => void,
74
+ history: History,
75
+ ): ColumnType<StreamItem>[] => [
76
+ {
77
+ title: '',
78
+ dataIndex: 'icon',
79
+ noSeparator: true,
80
+ width: 10,
81
+ style: { padding: '0 0 0 16px' },
82
+ },
83
+ { title: 'Stream', dataIndex: 'token' },
84
+ {
85
+ title: 'Payer',
86
+ dataIndex: 'payerAbbr',
87
+ },
88
+ { title: 'Flow rate', dataIndex: 'flowrateMonth' },
89
+ {
90
+ title: 'Payer Approve',
91
+ action: (record) => (
92
+ <TableActionButton
93
+ title='Go To Approve'
94
+ handleClick={() =>
95
+ history.push(
96
+ `/superfluid?payer=${record.payer}&superToken=${record.tokenId}`,
97
+ )
98
+ }
99
+ disabled={userHasActiveLoan}
100
+ />
101
+ ),
102
+ },
103
+ {
104
+ title: 'Get Paid',
105
+ action: (record) => (
106
+ <TableActionButton
107
+ title='GET PAID NOW'
108
+ handleClick={() => handleGetPaid(record)}
109
+ disabled={userHasActiveLoan}
110
+ />
111
+ ),
112
+ },
113
+ ]
114
+
115
+ export function SuperfluidUpcomingList({
116
+ hasActiveLoan,
117
+ poolInfo,
118
+ loading,
119
+ handleGetPaid,
120
+ }: Props): React.ReactElement {
121
+ const history = useHistory()
122
+ const { account, isActive } = useWeb3React()
123
+ const [streams, setStreams] = useState<StreamItem[] | undefined>()
124
+ const { data } = useQuery<{ streams: Stream[] }>(GET_RECEIVED_STREAMS, {
125
+ variables: {
126
+ receiver: account ? account.toLowerCase() : undefined,
127
+ tokenIds: poolInfo?.extra?.superTokens.map((item) => item.id) ?? [],
128
+ },
129
+ })
130
+
131
+ useEffect(() => {
132
+ if (data?.streams?.length) {
133
+ let result: Array<StreamItem | undefined> = data.streams.map((item) => {
134
+ const ONE_MONTH_SECONDS = 30 * 24 * 60 * 60
135
+ const flowrateMonth = downScale(
136
+ toBigNumber(item.currentFlowRate).mul(ONE_MONTH_SECONDS),
137
+ item.token.decimals,
138
+ )
139
+ if (Number(Number(flowrateMonth).toFixed(0)) > 0) {
140
+ return {
141
+ id: item.id,
142
+ icon: <ReceiptIcon css={{ width: '18px' }} />,
143
+ token: item.token.symbol,
144
+ tokenId: item.token.id,
145
+ payer: item.sender.id,
146
+ payerAbbr: getWalletAddressAbbr(item.sender.id),
147
+ flowrate: item.currentFlowRate,
148
+ flowrateMonth: `${Number(flowrateMonth).toFixed(0)}/mo`,
149
+ }
150
+ }
151
+ return undefined
152
+ })
153
+ result = result.filter((item) => !!item)
154
+ setStreams(result as StreamItem[])
155
+ }
156
+ }, [data])
157
+
158
+ const goToCreateStream = useCallback(() => {}, [])
159
+
160
+ return (
161
+ <UpcomingList<StreamItem>
162
+ items={streams}
163
+ loading={loading}
164
+ columns={getUpcomingColumns(hasActiveLoan, handleGetPaid, history)}
165
+ title='Ongoing Streams'
166
+ connectWalletDesc='Please connect wallet to check your ongoing streams.'
167
+ noItemDesc='You don’t have any ongoing streams eligible for factoring. For now, you can click the button
168
+ below to create streams.'
169
+ >
170
+ {isActive && (
171
+ <Button
172
+ onClick={goToCreateStream}
173
+ type='link'
174
+ size='small'
175
+ variant='contained'
176
+ sx={{ marginTop: '20px' }}
177
+ href='https://app.superfluid.finance/'
178
+ target='_blank'
179
+ >
180
+ CREATE STREAM
181
+ </Button>
182
+ )}
183
+ </UpcomingList>
184
+ )
185
+ }
@@ -0,0 +1,85 @@
1
+ import { Box } from '@mui/material'
2
+ import { useWeb3React } from '@web3-react/core'
3
+ import {
4
+ CreditEvent,
5
+ POOL_NAME,
6
+ POOL_TYPE,
7
+ PoolContractMap,
8
+ PoolMap,
9
+ useFactoring,
10
+ } from '@huma-finance/shared'
11
+ import React from 'react'
12
+
13
+ import { Activity } from '../Activity'
14
+ import { ApolloWrapper } from '../ApolloWrapper'
15
+ import { StreamFactoringBorrow } from '../StreamFactoring/borrow'
16
+ import { SuperfluidFactoredList } from './SuperfluidFactoredList'
17
+ import { StreamItem, SuperfluidUpcomingList } from './SuperfluidUpcomingList'
18
+
19
+ export function SuperfluidFactoring(): React.ReactElement {
20
+ const poolName = POOL_NAME.Superfluid
21
+ const { chainId } = useWeb3React()
22
+ const {
23
+ accountStats,
24
+ accountHasActiveLoan,
25
+ actionType,
26
+ loading,
27
+ poolInfo,
28
+ modalIsOpen,
29
+ selectedItem,
30
+ styles,
31
+ handleGetPaid,
32
+ handleGetPaidSuccess,
33
+ handlePayManually,
34
+ handleClose,
35
+ } = useFactoring<StreamItem>(poolName, POOL_TYPE.Stream)
36
+
37
+ return (
38
+ <Box css={styles.wrapper}>
39
+ <Box css={styles.title}>Stream Factoring</Box>
40
+ <Box css={styles.description} marginBottom='47px'>
41
+ {PoolMap.Stream[poolName].borrowDesc}
42
+ </Box>
43
+ {poolInfo && (
44
+ <SuperfluidFactoredList
45
+ poolInfo={poolInfo}
46
+ handlePayManually={handlePayManually}
47
+ loading={loading && actionType === 'payment'}
48
+ accountStats={accountStats}
49
+ />
50
+ )}
51
+ <ApolloWrapper uri={poolInfo?.extra?.subgraph!}>
52
+ <SuperfluidUpcomingList
53
+ poolInfo={poolInfo}
54
+ handleGetPaid={handleGetPaid}
55
+ hasActiveLoan={accountHasActiveLoan}
56
+ loading={loading && actionType === 'borrow'}
57
+ />
58
+ </ApolloWrapper>
59
+ <ApolloWrapper uri={PoolContractMap[chainId!]?.subgraph}>
60
+ {poolInfo && (
61
+ <Activity
62
+ poolInfo={poolInfo}
63
+ targetEvents={[
64
+ CreditEvent.DrawdownMadeWithReceivable,
65
+ CreditEvent.PaymentMade,
66
+ CreditEvent.ReceivedPaymentProcessed,
67
+ ]}
68
+ />
69
+ )}
70
+ </ApolloWrapper>
71
+ {poolInfo && selectedItem && actionType === 'borrow' && (
72
+ <StreamFactoringBorrow
73
+ poolName={POOL_NAME.Superfluid}
74
+ poolType={POOL_TYPE.Stream}
75
+ payerAddress={selectedItem.payer}
76
+ superToken={selectedItem.tokenId}
77
+ currentFlowRate={selectedItem.flowrate}
78
+ isOpen={modalIsOpen}
79
+ handleClose={handleClose}
80
+ handleSuccess={handleGetPaidSuccess}
81
+ />
82
+ )}
83
+ </Box>
84
+ )
85
+ }
@@ -0,0 +1,83 @@
1
+ import { Box, Button, css, Typography, useTheme } from '@mui/material'
2
+ import { txAtom } from '@huma-finance/shared'
3
+ import { useResetAtom } from 'jotai/utils'
4
+ import React, { useCallback } from 'react'
5
+
6
+ import { useAppDispatch } from '../hooks/useRedux'
7
+ import { resetState } from '../store/widgets.reducers'
8
+ import { CheckIcon } from './icons'
9
+
10
+ type Props = {
11
+ content: string[]
12
+ handleAction: () => void
13
+ }
14
+
15
+ export function TxDoneModal({
16
+ content,
17
+ handleAction,
18
+ }: Props): React.ReactElement {
19
+ const theme = useTheme()
20
+ const dispatch = useAppDispatch()
21
+ const reset = useResetAtom(txAtom)
22
+
23
+ const styles = {
24
+ wrapper: css`
25
+ height: 518px;
26
+ position: relative;
27
+ `,
28
+ header: css`
29
+ ${theme.cssMixins.rowHCentered};
30
+ margin-top: -5px;
31
+ `,
32
+ content: css`
33
+ ${theme.cssMixins.colVCentered};
34
+ font-family: 'Uni-Neue-Regular';
35
+ font-size: 18px;
36
+ color: #423b46;
37
+ margin-top: 64px;
38
+ text-align: center;
39
+ `,
40
+ check: css`
41
+ width: 100%;
42
+ ${theme.cssMixins.rowHCentered};
43
+ margin-top: 82px;
44
+ `,
45
+ doneButton: css`
46
+ width: 100%;
47
+ position: absolute;
48
+ bottom: 0;
49
+ `,
50
+ }
51
+
52
+ const handleCloseModal = useCallback(() => {
53
+ reset()
54
+ dispatch(resetState())
55
+ handleAction()
56
+ }, [dispatch, handleAction, reset])
57
+
58
+ return (
59
+ <Box css={styles.wrapper}>
60
+ <Typography variant='h6' css={styles.header}>
61
+ Transaction Completed
62
+ </Typography>
63
+ <Box css={styles.check}>
64
+ <CheckIcon />
65
+ </Box>
66
+ <Box css={styles.content}>
67
+ {content.map((item) => (
68
+ <Box sx={{ marginTop: '10px' }} key={item}>
69
+ {item}
70
+ </Box>
71
+ ))}
72
+ </Box>
73
+ <Button
74
+ className='transaction-done-modal-close-btn'
75
+ variant='contained'
76
+ css={styles.doneButton}
77
+ onClick={handleCloseModal}
78
+ >
79
+ DONE
80
+ </Button>
81
+ </Box>
82
+ )
83
+ }