@huma-finance/widgets 0.0.21 → 0.0.24

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 (165) hide show
  1. package/.env.example +2 -2
  2. package/.eslintignore +2 -2
  3. package/.eslintrc.js +64 -64
  4. package/.prettierignore +4 -4
  5. package/.prettierrc.js +16 -16
  6. package/API.md +332 -332
  7. package/LICENSE +660 -660
  8. package/README.md +48 -48
  9. package/babel.config.js +15 -15
  10. package/config-overrides.js +9 -9
  11. package/cosmos.config.json +7 -7
  12. package/cypress/e2e/01-invoice-factoring-borrow.test.ts +62 -62
  13. package/cypress/support/e2e.ts +76 -76
  14. package/cypress/support/ethereum.ts +142 -142
  15. package/cypress/tsconfig.json +9 -9
  16. package/cypress/utils/index.ts +54 -54
  17. package/cypress.config.ts +20 -20
  18. package/dist/cjs/index.cjs +119 -119
  19. package/dist/cjs/index.cjs.map +1 -1
  20. package/dist/index.d.ts +193 -193
  21. package/dist/index.js +119 -119
  22. package/dist/index.js.map +1 -1
  23. package/jsdoc2md.json +20 -20
  24. package/package.json +4 -4
  25. package/public/index.html +40 -40
  26. package/public/manifest.json +25 -25
  27. package/public/robots.txt +3 -3
  28. package/rollup.config.js +81 -81
  29. package/src/components/Activity.tsx +132 -123
  30. package/src/components/ApolloWrapper.tsx +15 -15
  31. package/src/components/ApproveAllowanceModal.tsx +121 -121
  32. package/src/components/BottomButton.tsx +31 -31
  33. package/src/components/ChainNotSupportedModal.tsx +33 -33
  34. package/src/components/ConfirmTransferModal.tsx +153 -153
  35. package/src/components/CreditLine/borrow/1-Evaluation.tsx +157 -157
  36. package/src/components/CreditLine/borrow/2-ChooseAmount.tsx +68 -68
  37. package/src/components/CreditLine/borrow/3-Transfer.tsx +44 -44
  38. package/src/components/CreditLine/borrow/4-ApproveAllowance.tsx +29 -29
  39. package/src/components/CreditLine/borrow/5-Success.tsx +30 -30
  40. package/src/components/CreditLine/borrow/index.tsx +117 -117
  41. package/src/components/CreditLine/payment/1-ChooseAmount.tsx +67 -67
  42. package/src/components/CreditLine/payment/2-ApproveAllowance.tsx +23 -23
  43. package/src/components/CreditLine/payment/3-Transfer.tsx +34 -34
  44. package/src/components/CreditLine/payment/4-Success.tsx +39 -39
  45. package/src/components/CreditLine/payment/index.tsx +94 -94
  46. package/src/components/ErrorModal.tsx +132 -132
  47. package/src/components/Factoring/FactoredList.tsx +143 -143
  48. package/src/components/Factoring/UpcomingList.tsx +90 -90
  49. package/src/components/Factoring/index.ts +2 -2
  50. package/src/components/HumaLoading.tsx +68 -68
  51. package/src/components/HumaTable.tsx +158 -158
  52. package/src/components/InvoiceFactoring/borrow/1-Evaluation.tsx +49 -49
  53. package/src/components/InvoiceFactoring/borrow/2-ChooseAmount.tsx +88 -88
  54. package/src/components/InvoiceFactoring/borrow/3-ConfirmTransfer.tsx +37 -37
  55. package/src/components/InvoiceFactoring/borrow/4-ApproveNFT.tsx +55 -55
  56. package/src/components/InvoiceFactoring/borrow/5-Transfer.tsx +34 -34
  57. package/src/components/InvoiceFactoring/borrow/6-Success.tsx +20 -20
  58. package/src/components/InvoiceFactoring/borrow/index.tsx +94 -94
  59. package/src/components/InvoiceFactoring/payment/1-ChooseAmount.tsx +67 -67
  60. package/src/components/InvoiceFactoring/payment/2-ApproveAllowance.tsx +23 -23
  61. package/src/components/InvoiceFactoring/payment/3-Transfer.tsx +34 -34
  62. package/src/components/InvoiceFactoring/payment/4-Success.tsx +23 -23
  63. package/src/components/InvoiceFactoring/payment/index.tsx +86 -86
  64. package/src/components/Lend/supply/1-Evaluation.tsx +86 -86
  65. package/src/components/Lend/supply/2-ChooseAmount.tsx +70 -70
  66. package/src/components/Lend/supply/3-ApproveAllowance.tsx +25 -25
  67. package/src/components/Lend/supply/4-ConfirmTransfer.tsx +104 -104
  68. package/src/components/Lend/supply/6-Transfer.tsx +32 -32
  69. package/src/components/Lend/supply/7-Success.tsx +49 -49
  70. package/src/components/Lend/supply/index.tsx +144 -144
  71. package/src/components/Lend/withdraw/1-CheckWithdrawble.tsx +73 -73
  72. package/src/components/Lend/withdraw/2-ChooseAmount.tsx +50 -50
  73. package/src/components/Lend/withdraw/3-Transfer.tsx +32 -32
  74. package/src/components/Lend/withdraw/4-Success.tsx +49 -49
  75. package/src/components/Lend/withdraw/index.tsx +101 -101
  76. package/src/components/LoadingModal.tsx +49 -49
  77. package/src/components/StreamFactoring/borrow/1-Evaluation.tsx +55 -55
  78. package/src/components/StreamFactoring/borrow/2-ChooseAmount.tsx +127 -127
  79. package/src/components/StreamFactoring/borrow/3-ConfirmTransfer.tsx +42 -42
  80. package/src/components/StreamFactoring/borrow/4-ApproveAllowance.tsx +33 -33
  81. package/src/components/StreamFactoring/borrow/5-Permit.tsx +144 -144
  82. package/src/components/StreamFactoring/borrow/6-Transfer.tsx +37 -37
  83. package/src/components/StreamFactoring/borrow/7-Success.tsx +20 -20
  84. package/src/components/StreamFactoring/borrow/index.tsx +94 -94
  85. package/src/components/StreamFactoring/payment/ChooseAmount.tsx +54 -54
  86. package/src/components/StreamFactoring/payment/Success.tsx +23 -23
  87. package/src/components/StreamFactoring/payment/Transfer.tsx +34 -34
  88. package/src/components/StreamFactoring/payment/index.tsx +66 -66
  89. package/src/components/SuperfluidFactoring/SuperfluidFactoredList.tsx +70 -70
  90. package/src/components/SuperfluidFactoring/SuperfluidUpcomingList.tsx +167 -167
  91. package/src/components/SuperfluidFactoring/index.tsx +85 -85
  92. package/src/components/TxDoneModal.tsx +83 -83
  93. package/src/components/TxSendModal.tsx +59 -59
  94. package/src/components/ViewOnExplorer.tsx +26 -26
  95. package/src/components/WidgetWrapper.tsx +74 -74
  96. package/src/components/WrapperModal.tsx +54 -54
  97. package/src/components/buttons/TableActionButton.tsx +36 -36
  98. package/src/components/buttons/index.ts +1 -1
  99. package/src/components/humaModal/HumaModal.tsx +68 -68
  100. package/src/components/humaModal/HumaModalHeader.tsx +70 -70
  101. package/src/components/humaModal/index.tsx +2 -2
  102. package/src/components/icons/approve-lender.svg +30 -30
  103. package/src/components/icons/auto-payback.svg +40 -40
  104. package/src/components/icons/check-circle.svg +3 -3
  105. package/src/components/icons/check-green.svg +3 -3
  106. package/src/components/icons/check.svg +10 -10
  107. package/src/components/icons/donut.svg +904 -904
  108. package/src/components/icons/ellipse.svg +3 -3
  109. package/src/components/icons/huma-full.svg +22 -22
  110. package/src/components/icons/huma.svg +15 -15
  111. package/src/components/icons/index.tsx +93 -93
  112. package/src/components/icons/loader.svg +229 -229
  113. package/src/components/icons/metamask.svg +31 -31
  114. package/src/components/icons/polygon.svg +16 -16
  115. package/src/components/icons/receipt.svg +3 -3
  116. package/src/components/icons/separator.svg +3 -3
  117. package/src/components/icons/sorry.svg +31 -31
  118. package/src/components/icons/usdc.svg +5 -5
  119. package/src/components/icons/wallet-connect.svg +11 -11
  120. package/src/cosmos/CreditLineBorrow.fixture.tsx +86 -86
  121. package/src/cosmos/CreditLinePayment.fixture.tsx +50 -50
  122. package/src/cosmos/InvoiceFactoringBorrow.fixture.tsx +111 -111
  123. package/src/cosmos/InvoiceFactoringPayment.fixture.tsx +67 -67
  124. package/src/cosmos/LendSupply.fixture.tsx +75 -75
  125. package/src/cosmos/LendWithdraw.fixture.tsx +43 -43
  126. package/src/cosmos/SuperfluidFactoringBorrow.fixture.tsx +15 -15
  127. package/src/cosmos/WalletWrapper.tsx +52 -52
  128. package/src/cosmos/abis/InvoiceNFT.json +644 -644
  129. package/src/cosmos/abis/ReceivableFactoringPool.json +1529 -1529
  130. package/src/cosmos/utils/env.ts +6 -6
  131. package/src/cosmos/utils/index.ts +169 -169
  132. package/src/fonts/Recoleta/Recoleta-Black.otf +0 -0
  133. package/src/fonts/Recoleta/Recoleta-Bold.otf +0 -0
  134. package/src/fonts/Recoleta/Recoleta-Light.otf +0 -0
  135. package/src/fonts/Recoleta/Recoleta-Medium.otf +0 -0
  136. package/src/fonts/Recoleta/Recoleta-Regular.otf +0 -0
  137. package/src/fonts/Recoleta/Recoleta-RegularDEMO.otf +0 -0
  138. package/src/fonts/Recoleta/Recoleta-SemiBold.otf +0 -0
  139. package/src/fonts/Recoleta/Recoleta-Thin.otf +0 -0
  140. package/src/hooks/useEA.ts +53 -53
  141. package/src/hooks/useRedux.ts +6 -6
  142. package/src/index.css +61 -61
  143. package/src/index.tsx +300 -300
  144. package/src/react-app-env.d.ts +1 -1
  145. package/src/reportWebVitals.ts +15 -15
  146. package/src/setupTests.ts +6 -6
  147. package/src/store/index.ts +27 -27
  148. package/src/store/widgets.reducers.ts +120 -120
  149. package/src/store/widgets.selectors.ts +3 -3
  150. package/src/store/widgets.store.ts +54 -54
  151. package/src/theme/breakpoints.ts +10 -10
  152. package/src/theme/components.ts +70 -70
  153. package/src/theme/coreThemeConstants.ts +29 -29
  154. package/src/theme/cssMixins.ts +92 -92
  155. package/src/theme/hooks/useGetSizes.ts +31 -31
  156. package/src/theme/index.ts +24 -24
  157. package/src/theme/palette.ts +150 -150
  158. package/src/theme/shape.ts +7 -7
  159. package/src/theme/theme.types.ts +80 -80
  160. package/src/theme/typography.ts +117 -117
  161. package/src/utilTypes.d.ts +31 -31
  162. package/src/utils/env.ts +9 -9
  163. package/tsconfig.build.json +7 -7
  164. package/tsconfig.json +32 -32
  165. package/webpack.cosmos.js +54 -54
package/src/index.tsx CHANGED
@@ -1,300 +1,300 @@
1
- import './index.css'
2
-
3
- import { JsonRpcProvider } from '@ethersproject/providers'
4
- import {
5
- Provider as Web3Provider,
6
- ProviderProps as Web3Props,
7
- supportedChainId,
8
- } from '@huma-finance/shared'
9
- import { ThemeProvider } from '@mui/material'
10
- import { Provider as Eip1193Provider } from '@web3-react/types'
11
- import { Provider as AtomProvider } from 'jotai'
12
- import { useCallback, useEffect, useState } from 'react'
13
- import { Provider as ReduxProvider } from 'react-redux'
14
-
15
- import { ChainNotSupportedModal } from './components/ChainNotSupportedModal'
16
- import {
17
- CreditLineBorrow,
18
- CreditLineBorrowProps,
19
- } from './components/CreditLine/borrow'
20
- import {
21
- CreditLinePayment,
22
- CreditLinePaymentProps,
23
- } from './components/CreditLine/payment'
24
- import {
25
- InvoiceFactoringBorrow,
26
- InvoiceFactoringBorrowProps,
27
- } from './components/InvoiceFactoring/borrow'
28
- import {
29
- InvoiceFactoringPayment,
30
- InvoiceFactoringPaymentProps,
31
- } from './components/InvoiceFactoring/payment'
32
- import { LendSupply, LendSupplyProps } from './components/Lend/supply'
33
- import { LendWithdraw, LendWithdrawProps } from './components/Lend/withdraw'
34
- import { SuperfluidFactoring } from './components/SuperfluidFactoring'
35
- import { store } from './store'
36
- import { themeHuma } from './theme'
37
- import { WCProps } from './utilTypes'
38
-
39
- /**
40
- * Mapping of your JSON-RPC connections indexed by chainId
41
- * @typedef {Object} JsonRpcConnectionMap
42
- * @property {Object.<number, string|Array<string>|JsonRpcProvider|Array<JsonRpcProvider>>} chainId Chain id to map the JSON-RPC URL/URLs or JsonRpcProvider/JsonRpcProviders
43
- */
44
- type JsonRpcConnectionMap = {
45
- [chainId: number]: string | string[] | JsonRpcProvider | JsonRpcProvider[]
46
- }
47
-
48
- /**
49
- * Object representing the props passed to web3 provider
50
- * @typedef {Object} WidgetProps
51
- * @property {desiredChainId|undefined} desiredChainId Optional desired chain id, will trigger the switch network action if different from the current chain id
52
- * @property {JsonRpcConnectionMap|undefined} jsonRpcUrlMap Optional mapping of your JSON-RPC connections indexed by chainId
53
- * @property {Eip1193Provider|JsonRpcProvider|null|undefined} provider Optional EIP-1193 provider or JsonRpc Provider
54
- */
55
- type WidgetProps = {
56
- handleClose?: () => void
57
- desiredChainId?: number
58
- jsonRpcUrlMap?: JsonRpcConnectionMap
59
- provider?: Eip1193Provider | JsonRpcProvider | null
60
- }
61
-
62
- function Widget(props: WCProps<WidgetProps>) {
63
- const { children, desiredChainId } = props
64
- // @ts-ignore
65
- const netWorkVersion = window.ethereum?.networkVersion
66
- const [currentChainId, setCurrentChainId] = useState<number | undefined>(
67
- netWorkVersion ? Number(netWorkVersion) : undefined,
68
- )
69
- const chainSupported = !!supportedChainId(currentChainId)
70
- const [chainNotSupportedOpen, setChainNotSupportedOpen] = useState(false)
71
-
72
- useEffect(() => {
73
- setCurrentChainId(netWorkVersion ? Number(netWorkVersion) : undefined)
74
- }, [netWorkVersion])
75
-
76
- useEffect(() => {
77
- if (chainSupported) {
78
- setChainNotSupportedOpen(false)
79
- } else {
80
- setChainNotSupportedOpen(true)
81
- }
82
- }, [chainSupported])
83
-
84
- useEffect(() => {
85
- const chainChangeListener = (chainId: number) => {
86
- setCurrentChainId(chainId)
87
- }
88
-
89
- if (window.ethereum) {
90
- // @ts-ignore
91
- window.ethereum?.on('chainChanged', chainChangeListener)
92
- }
93
- return () => {
94
- if (window.ethereum) {
95
- // @ts-ignore
96
- window.ethereum?.removeListener('chainChanged', chainChangeListener)
97
- }
98
- }
99
- }, [])
100
-
101
- useEffect(() => {
102
- if (
103
- window.ethereum &&
104
- desiredChainId &&
105
- currentChainId !== desiredChainId
106
- ) {
107
- const changeNetwork = async () => {
108
- try {
109
- // @ts-ignore
110
- await window.ethereum.request({
111
- method: 'wallet_switchEthereumChain',
112
- params: [{ chainId: `0x${Number(desiredChainId).toString(16)}` }],
113
- })
114
- } catch (error) {
115
- console.error(error)
116
- }
117
- }
118
- changeNetwork()
119
- }
120
- }, [currentChainId, desiredChainId])
121
-
122
- const handleCloseCallback = useCallback(() => {
123
- setChainNotSupportedOpen(false)
124
- }, [])
125
-
126
- if (!chainSupported) {
127
- return (
128
- <ThemeProvider theme={themeHuma}>
129
- <ReduxProvider store={store}>
130
- <ChainNotSupportedModal
131
- isOpen={chainNotSupportedOpen}
132
- handleClose={handleCloseCallback}
133
- />
134
- </ReduxProvider>
135
- </ThemeProvider>
136
- )
137
- }
138
-
139
- return (
140
- <ThemeProvider theme={themeHuma}>
141
- <ReduxProvider store={store}>
142
- <Web3Provider {...(props as Web3Props)}>
143
- <AtomProvider>{children}</AtomProvider>
144
- </Web3Provider>
145
- </ReduxProvider>
146
- </ThemeProvider>
147
- )
148
- }
149
-
150
- /**
151
- * Invoice factoring pool borrow widget props
152
- * @typedef {Object} InvoiceFactoringBorrowWidgetProps
153
- * @property {InvoiceFactoringBorrowProps} InvoiceFactoringBorrowProps - Invoice factoring pool borrow props.
154
- * @property {WidgetProps} WidgetProps - Widget general props.
155
- */
156
- type InvoiceFactoringBorrowWidgetProps = InvoiceFactoringBorrowProps &
157
- WidgetProps
158
-
159
- /**
160
- * Invoice factoring borrow widget
161
- *
162
- * @param {InvoiceFactoringBorrowProps | WidgetProps} props - The invoice factoring pool borrow widget props.
163
- * @returns Invoice factoring pool borrow widget component
164
- */
165
- export function InvoiceFactoringBorrowWidget(
166
- props: InvoiceFactoringBorrowWidgetProps,
167
- ) {
168
- return (
169
- <Widget {...props}>
170
- <InvoiceFactoringBorrow {...props} />
171
- </Widget>
172
- )
173
- }
174
-
175
- /**
176
- * Invoice factoring pool payment widget props
177
- * @typedef {Object} InvoiceFactoringPaymentWidgetProps
178
- * @property {InvoiceFactoringPaymentProps} InvoiceFactoringPaymentProps - Invoice factoring pool payment props.
179
- * @property {WidgetProps} WidgetProps - Widget general props.
180
- */
181
- type InvoiceFactoringPaymentWidgetProps = InvoiceFactoringPaymentProps &
182
- WidgetProps
183
-
184
- /**
185
- * Invoice factoring payment widget
186
- *
187
- * @param {InvoiceFactoringPaymentProps | WidgetProps} props - The invoice factoring pool payment widget props.
188
- * @returns Invoice factoring pool payment widget component
189
- */
190
- export function InvoiceFactoringPaymentWidget(
191
- props: InvoiceFactoringPaymentWidgetProps,
192
- ) {
193
- return (
194
- <Widget {...props}>
195
- <InvoiceFactoringPayment {...props} />
196
- </Widget>
197
- )
198
- }
199
-
200
- /**
201
- * Credit line pool borrow widget props
202
- * @typedef {Object} CreditLineBorrowWidgetProps
203
- * @property {CreditLineBorrowProps} CreditLineBorrowProps - Credit line pool borrow props.
204
- * @property {WidgetProps} WidgetProps - Widget general props.
205
- */
206
- type CreditLineBorrowWidgetProps = CreditLineBorrowProps & WidgetProps
207
-
208
- /**
209
- * Credit line borrow widget
210
- *
211
- * @param {CreditLineBorrowProps | WidgetProps} props - The credit line pool borrow widget props.
212
- * @returns Credit line pool borrow widget component
213
- */
214
- export function CreditLineBorrowWidget(props: CreditLineBorrowWidgetProps) {
215
- return (
216
- <Widget {...props}>
217
- <CreditLineBorrow {...props} />
218
- </Widget>
219
- )
220
- }
221
-
222
- /**
223
- * Credit line pool payment widget props
224
- * @typedef {Object} CreditLinePaymentWidgetProps
225
- * @property {CreditLinePaymentProps} CreditLinePaymentProps - Credit line pool payment props.
226
- * @property {WidgetProps} WidgetProps - Widget general props.
227
- */
228
- type CreditLinePaymentWidgetProps = CreditLinePaymentProps & WidgetProps
229
-
230
- /**
231
- * Credit line payment widget
232
- *
233
- * @param {CreditLinePaymentProps | WidgetProps} props - The credit line pool payment widget props.
234
- * @returns Credit line pool payment widget component
235
- */
236
- export function CreditLinePaymentWidget(props: CreditLinePaymentWidgetProps) {
237
- return (
238
- <Widget {...props}>
239
- <CreditLinePayment {...props} />
240
- </Widget>
241
- )
242
- }
243
-
244
- /**
245
- * Lend pool supply widget props
246
- * @typedef {Object} LendSupplyWidgetProps
247
- * @property {LendSupplyProps} LendSupplyProps - Lend pool supply props.
248
- * @property {WidgetProps} WidgetProps - Widget general props.
249
- */
250
- type LendSupplyWidgetProps = LendSupplyProps & WidgetProps
251
-
252
- /**
253
- * Lend supply widget
254
- *
255
- * @param {LendSupplyProps | WidgetProps} props - The lend pool supply widget props.
256
- * @returns Lend pool supply widget component
257
- */
258
- export function LendSupplyWidget(props: LendSupplyWidgetProps) {
259
- return (
260
- <Widget {...props}>
261
- <LendSupply {...props} />
262
- </Widget>
263
- )
264
- }
265
-
266
- /**
267
- * Lend pool withdraw widget props
268
- * @typedef {Object} LendWithdrawWidgetProps
269
- * @property {LendWithdrawProps} LendWithdrawProps - Lend pool withdraw props.
270
- * @property {WidgetProps} WidgetProps - Widget general props.
271
- */
272
- type LendWithdrawWidgetProps = LendWithdrawProps & WidgetProps
273
-
274
- /**
275
- * Lend withdraw widget
276
- *
277
- * @param {LendWithdrawProps | WidgetProps} props The lend pool withdraw widget props
278
- * @returns Lend pool withdraw widget component
279
- */
280
- export function LendWithdrawWidget(props: LendWithdrawWidgetProps) {
281
- return (
282
- <Widget {...props}>
283
- <LendWithdraw {...props} />
284
- </Widget>
285
- )
286
- }
287
-
288
- /**
289
- * Superfluid factoring widget
290
- *
291
- * @param {WidgetProps} props - The superfluid factoring widget props.
292
- * @returns Superfluid factoring widget component
293
- */
294
- export function SuperfluidFactoringWidget(props: WidgetProps) {
295
- return (
296
- <Widget {...props}>
297
- <SuperfluidFactoring />
298
- </Widget>
299
- )
300
- }
1
+ import './index.css'
2
+
3
+ import { JsonRpcProvider } from '@ethersproject/providers'
4
+ import {
5
+ Provider as Web3Provider,
6
+ ProviderProps as Web3Props,
7
+ supportedChainId,
8
+ } from '@huma-finance/shared'
9
+ import { ThemeProvider } from '@mui/material'
10
+ import { Provider as Eip1193Provider } from '@web3-react/types'
11
+ import { Provider as AtomProvider } from 'jotai'
12
+ import { useCallback, useEffect, useState } from 'react'
13
+ import { Provider as ReduxProvider } from 'react-redux'
14
+
15
+ import { ChainNotSupportedModal } from './components/ChainNotSupportedModal'
16
+ import {
17
+ CreditLineBorrow,
18
+ CreditLineBorrowProps,
19
+ } from './components/CreditLine/borrow'
20
+ import {
21
+ CreditLinePayment,
22
+ CreditLinePaymentProps,
23
+ } from './components/CreditLine/payment'
24
+ import {
25
+ InvoiceFactoringBorrow,
26
+ InvoiceFactoringBorrowProps,
27
+ } from './components/InvoiceFactoring/borrow'
28
+ import {
29
+ InvoiceFactoringPayment,
30
+ InvoiceFactoringPaymentProps,
31
+ } from './components/InvoiceFactoring/payment'
32
+ import { LendSupply, LendSupplyProps } from './components/Lend/supply'
33
+ import { LendWithdraw, LendWithdrawProps } from './components/Lend/withdraw'
34
+ import { SuperfluidFactoring } from './components/SuperfluidFactoring'
35
+ import { store } from './store'
36
+ import { themeHuma } from './theme'
37
+ import { WCProps } from './utilTypes'
38
+
39
+ /**
40
+ * Mapping of your JSON-RPC connections indexed by chainId
41
+ * @typedef {Object} JsonRpcConnectionMap
42
+ * @property {Object.<number, string|Array<string>|JsonRpcProvider|Array<JsonRpcProvider>>} chainId Chain id to map the JSON-RPC URL/URLs or JsonRpcProvider/JsonRpcProviders
43
+ */
44
+ type JsonRpcConnectionMap = {
45
+ [chainId: number]: string | string[] | JsonRpcProvider | JsonRpcProvider[]
46
+ }
47
+
48
+ /**
49
+ * Object representing the props passed to web3 provider
50
+ * @typedef {Object} WidgetProps
51
+ * @property {desiredChainId|undefined} desiredChainId Optional desired chain id, will trigger the switch network action if different from the current chain id
52
+ * @property {JsonRpcConnectionMap|undefined} jsonRpcUrlMap Optional mapping of your JSON-RPC connections indexed by chainId
53
+ * @property {Eip1193Provider|JsonRpcProvider|null|undefined} provider Optional EIP-1193 provider or JsonRpc Provider
54
+ */
55
+ type WidgetProps = {
56
+ handleClose?: () => void
57
+ desiredChainId?: number
58
+ jsonRpcUrlMap?: JsonRpcConnectionMap
59
+ provider?: Eip1193Provider | JsonRpcProvider | null
60
+ }
61
+
62
+ function Widget(props: WCProps<WidgetProps>) {
63
+ const { children, desiredChainId } = props
64
+ // @ts-ignore
65
+ const netWorkVersion = window.ethereum?.networkVersion
66
+ const [currentChainId, setCurrentChainId] = useState<number | undefined>(
67
+ netWorkVersion ? Number(netWorkVersion) : undefined,
68
+ )
69
+ const chainSupported = !!supportedChainId(currentChainId)
70
+ const [chainNotSupportedOpen, setChainNotSupportedOpen] = useState(false)
71
+
72
+ useEffect(() => {
73
+ setCurrentChainId(netWorkVersion ? Number(netWorkVersion) : undefined)
74
+ }, [netWorkVersion])
75
+
76
+ useEffect(() => {
77
+ if (chainSupported) {
78
+ setChainNotSupportedOpen(false)
79
+ } else {
80
+ setChainNotSupportedOpen(true)
81
+ }
82
+ }, [chainSupported])
83
+
84
+ useEffect(() => {
85
+ const chainChangeListener = (chainId: number) => {
86
+ setCurrentChainId(chainId)
87
+ }
88
+
89
+ if (window.ethereum) {
90
+ // @ts-ignore
91
+ window.ethereum?.on('chainChanged', chainChangeListener)
92
+ }
93
+ return () => {
94
+ if (window.ethereum) {
95
+ // @ts-ignore
96
+ window.ethereum?.removeListener('chainChanged', chainChangeListener)
97
+ }
98
+ }
99
+ }, [])
100
+
101
+ useEffect(() => {
102
+ if (
103
+ window.ethereum &&
104
+ desiredChainId &&
105
+ currentChainId !== desiredChainId
106
+ ) {
107
+ const changeNetwork = async () => {
108
+ try {
109
+ // @ts-ignore
110
+ await window.ethereum.request({
111
+ method: 'wallet_switchEthereumChain',
112
+ params: [{ chainId: `0x${Number(desiredChainId).toString(16)}` }],
113
+ })
114
+ } catch (error) {
115
+ console.error(error)
116
+ }
117
+ }
118
+ changeNetwork()
119
+ }
120
+ }, [currentChainId, desiredChainId])
121
+
122
+ const handleCloseCallback = useCallback(() => {
123
+ setChainNotSupportedOpen(false)
124
+ }, [])
125
+
126
+ if (!chainSupported) {
127
+ return (
128
+ <ThemeProvider theme={themeHuma}>
129
+ <ReduxProvider store={store}>
130
+ <ChainNotSupportedModal
131
+ isOpen={chainNotSupportedOpen}
132
+ handleClose={handleCloseCallback}
133
+ />
134
+ </ReduxProvider>
135
+ </ThemeProvider>
136
+ )
137
+ }
138
+
139
+ return (
140
+ <ThemeProvider theme={themeHuma}>
141
+ <ReduxProvider store={store}>
142
+ <Web3Provider {...(props as Web3Props)}>
143
+ <AtomProvider>{children}</AtomProvider>
144
+ </Web3Provider>
145
+ </ReduxProvider>
146
+ </ThemeProvider>
147
+ )
148
+ }
149
+
150
+ /**
151
+ * Invoice factoring pool borrow widget props
152
+ * @typedef {Object} InvoiceFactoringBorrowWidgetProps
153
+ * @property {InvoiceFactoringBorrowProps} InvoiceFactoringBorrowProps - Invoice factoring pool borrow props.
154
+ * @property {WidgetProps} WidgetProps - Widget general props.
155
+ */
156
+ type InvoiceFactoringBorrowWidgetProps = InvoiceFactoringBorrowProps &
157
+ WidgetProps
158
+
159
+ /**
160
+ * Invoice factoring borrow widget
161
+ *
162
+ * @param {InvoiceFactoringBorrowProps | WidgetProps} props - The invoice factoring pool borrow widget props.
163
+ * @returns Invoice factoring pool borrow widget component
164
+ */
165
+ export function InvoiceFactoringBorrowWidget(
166
+ props: InvoiceFactoringBorrowWidgetProps,
167
+ ) {
168
+ return (
169
+ <Widget {...props}>
170
+ <InvoiceFactoringBorrow {...props} />
171
+ </Widget>
172
+ )
173
+ }
174
+
175
+ /**
176
+ * Invoice factoring pool payment widget props
177
+ * @typedef {Object} InvoiceFactoringPaymentWidgetProps
178
+ * @property {InvoiceFactoringPaymentProps} InvoiceFactoringPaymentProps - Invoice factoring pool payment props.
179
+ * @property {WidgetProps} WidgetProps - Widget general props.
180
+ */
181
+ type InvoiceFactoringPaymentWidgetProps = InvoiceFactoringPaymentProps &
182
+ WidgetProps
183
+
184
+ /**
185
+ * Invoice factoring payment widget
186
+ *
187
+ * @param {InvoiceFactoringPaymentProps | WidgetProps} props - The invoice factoring pool payment widget props.
188
+ * @returns Invoice factoring pool payment widget component
189
+ */
190
+ export function InvoiceFactoringPaymentWidget(
191
+ props: InvoiceFactoringPaymentWidgetProps,
192
+ ) {
193
+ return (
194
+ <Widget {...props}>
195
+ <InvoiceFactoringPayment {...props} />
196
+ </Widget>
197
+ )
198
+ }
199
+
200
+ /**
201
+ * Credit line pool borrow widget props
202
+ * @typedef {Object} CreditLineBorrowWidgetProps
203
+ * @property {CreditLineBorrowProps} CreditLineBorrowProps - Credit line pool borrow props.
204
+ * @property {WidgetProps} WidgetProps - Widget general props.
205
+ */
206
+ type CreditLineBorrowWidgetProps = CreditLineBorrowProps & WidgetProps
207
+
208
+ /**
209
+ * Credit line borrow widget
210
+ *
211
+ * @param {CreditLineBorrowProps | WidgetProps} props - The credit line pool borrow widget props.
212
+ * @returns Credit line pool borrow widget component
213
+ */
214
+ export function CreditLineBorrowWidget(props: CreditLineBorrowWidgetProps) {
215
+ return (
216
+ <Widget {...props}>
217
+ <CreditLineBorrow {...props} />
218
+ </Widget>
219
+ )
220
+ }
221
+
222
+ /**
223
+ * Credit line pool payment widget props
224
+ * @typedef {Object} CreditLinePaymentWidgetProps
225
+ * @property {CreditLinePaymentProps} CreditLinePaymentProps - Credit line pool payment props.
226
+ * @property {WidgetProps} WidgetProps - Widget general props.
227
+ */
228
+ type CreditLinePaymentWidgetProps = CreditLinePaymentProps & WidgetProps
229
+
230
+ /**
231
+ * Credit line payment widget
232
+ *
233
+ * @param {CreditLinePaymentProps | WidgetProps} props - The credit line pool payment widget props.
234
+ * @returns Credit line pool payment widget component
235
+ */
236
+ export function CreditLinePaymentWidget(props: CreditLinePaymentWidgetProps) {
237
+ return (
238
+ <Widget {...props}>
239
+ <CreditLinePayment {...props} />
240
+ </Widget>
241
+ )
242
+ }
243
+
244
+ /**
245
+ * Lend pool supply widget props
246
+ * @typedef {Object} LendSupplyWidgetProps
247
+ * @property {LendSupplyProps} LendSupplyProps - Lend pool supply props.
248
+ * @property {WidgetProps} WidgetProps - Widget general props.
249
+ */
250
+ type LendSupplyWidgetProps = LendSupplyProps & WidgetProps
251
+
252
+ /**
253
+ * Lend supply widget
254
+ *
255
+ * @param {LendSupplyProps | WidgetProps} props - The lend pool supply widget props.
256
+ * @returns Lend pool supply widget component
257
+ */
258
+ export function LendSupplyWidget(props: LendSupplyWidgetProps) {
259
+ return (
260
+ <Widget {...props}>
261
+ <LendSupply {...props} />
262
+ </Widget>
263
+ )
264
+ }
265
+
266
+ /**
267
+ * Lend pool withdraw widget props
268
+ * @typedef {Object} LendWithdrawWidgetProps
269
+ * @property {LendWithdrawProps} LendWithdrawProps - Lend pool withdraw props.
270
+ * @property {WidgetProps} WidgetProps - Widget general props.
271
+ */
272
+ type LendWithdrawWidgetProps = LendWithdrawProps & WidgetProps
273
+
274
+ /**
275
+ * Lend withdraw widget
276
+ *
277
+ * @param {LendWithdrawProps | WidgetProps} props The lend pool withdraw widget props
278
+ * @returns Lend pool withdraw widget component
279
+ */
280
+ export function LendWithdrawWidget(props: LendWithdrawWidgetProps) {
281
+ return (
282
+ <Widget {...props}>
283
+ <LendWithdraw {...props} />
284
+ </Widget>
285
+ )
286
+ }
287
+
288
+ /**
289
+ * Superfluid factoring widget
290
+ *
291
+ * @param {WidgetProps} props - The superfluid factoring widget props.
292
+ * @returns Superfluid factoring widget component
293
+ */
294
+ export function SuperfluidFactoringWidget(props: WidgetProps) {
295
+ return (
296
+ <Widget {...props}>
297
+ <SuperfluidFactoring />
298
+ </Widget>
299
+ )
300
+ }
@@ -1 +1 @@
1
- /// <reference types="react-scripts" />
1
+ /// <reference types="react-scripts" />
@@ -1,15 +1,15 @@
1
- import { ReportHandler } from 'web-vitals'
2
-
3
- const reportWebVitals = (onPerfEntry?: ReportHandler) => {
4
- if (onPerfEntry && onPerfEntry instanceof Function) {
5
- import('web-vitals').then(({ getCLS, getFID, getFCP, getLCP, getTTFB }) => {
6
- getCLS(onPerfEntry)
7
- getFID(onPerfEntry)
8
- getFCP(onPerfEntry)
9
- getLCP(onPerfEntry)
10
- getTTFB(onPerfEntry)
11
- })
12
- }
13
- }
14
-
15
- export default reportWebVitals
1
+ import { ReportHandler } from 'web-vitals'
2
+
3
+ const reportWebVitals = (onPerfEntry?: ReportHandler) => {
4
+ if (onPerfEntry && onPerfEntry instanceof Function) {
5
+ import('web-vitals').then(({ getCLS, getFID, getFCP, getLCP, getTTFB }) => {
6
+ getCLS(onPerfEntry)
7
+ getFID(onPerfEntry)
8
+ getFCP(onPerfEntry)
9
+ getLCP(onPerfEntry)
10
+ getTTFB(onPerfEntry)
11
+ })
12
+ }
13
+ }
14
+
15
+ export default reportWebVitals
package/src/setupTests.ts CHANGED
@@ -1,6 +1,6 @@
1
- /* eslint-disable import/no-extraneous-dependencies */
2
- // jest-dom adds custom jest matchers for asserting on DOM nodes.
3
- // allows you to do things like:
4
- // expect(element).toHaveTextContent(/react/i)
5
- // learn more: https://github.com/testing-library/jest-dom
6
- import '@testing-library/jest-dom/extend-expect'
1
+ /* eslint-disable import/no-extraneous-dependencies */
2
+ // jest-dom adds custom jest matchers for asserting on DOM nodes.
3
+ // allows you to do things like:
4
+ // expect(element).toHaveTextContent(/react/i)
5
+ // learn more: https://github.com/testing-library/jest-dom
6
+ import '@testing-library/jest-dom/extend-expect'