@huma-finance/widgets 0.0.10 → 0.0.12

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 (169) 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 +331 -331
  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/assets/output-15e10f9f.css +44 -0
  19. package/dist/cjs/assets/output-15e10f9f.css +44 -0
  20. package/dist/cjs/index.cjs +7740 -0
  21. package/dist/cjs/index.cjs.map +1 -0
  22. package/dist/index.d.ts +211 -0
  23. package/dist/index.js +7696 -0
  24. package/dist/index.js.map +1 -0
  25. package/jsdoc2md.json +20 -20
  26. package/package.json +4 -4
  27. package/public/index.html +40 -40
  28. package/public/manifest.json +25 -25
  29. package/public/robots.txt +3 -3
  30. package/rollup.config.js +81 -81
  31. package/src/components/Activity.tsx +123 -123
  32. package/src/components/AllowListModal.tsx +113 -113
  33. package/src/components/ApolloWrapper.tsx +15 -15
  34. package/src/components/ApproveAllowanceModal.tsx +118 -118
  35. package/src/components/BottomButton.tsx +31 -31
  36. package/src/components/ChooseAmountModal.tsx +322 -315
  37. package/src/components/CreditLine/borrow/1-Evaluation.tsx +158 -159
  38. package/src/components/CreditLine/borrow/2-AllowList.tsx +34 -34
  39. package/src/components/CreditLine/borrow/3-ChooseAmount.tsx +68 -74
  40. package/src/components/CreditLine/borrow/{5-Transfer.tsx → 4-Transfer.tsx} +44 -30
  41. package/src/components/CreditLine/borrow/{4-ApproveAllowance.tsx → 5-ApproveAllowance.tsx} +29 -29
  42. package/src/components/CreditLine/borrow/6-Success.tsx +30 -30
  43. package/src/components/CreditLine/borrow/index.tsx +119 -119
  44. package/src/components/CreditLine/payment/1-ChooseAmount.tsx +67 -67
  45. package/src/components/CreditLine/payment/2-ApproveAllowance.tsx +23 -23
  46. package/src/components/CreditLine/payment/3-Transfer.tsx +34 -34
  47. package/src/components/CreditLine/payment/4-Success.tsx +39 -39
  48. package/src/components/CreditLine/payment/index.tsx +94 -94
  49. package/src/components/ErrorModal.tsx +132 -132
  50. package/src/components/Factoring/FactoredList.tsx +143 -143
  51. package/src/components/Factoring/UpcomingList.tsx +90 -90
  52. package/src/components/Factoring/index.ts +2 -2
  53. package/src/components/HumaLoading.tsx +68 -68
  54. package/src/components/HumaTable.tsx +158 -158
  55. package/src/components/InvoiceFactoring/borrow/1-Evaluation.tsx +52 -46
  56. package/src/components/InvoiceFactoring/borrow/2-AllowList.tsx +34 -34
  57. package/src/components/InvoiceFactoring/borrow/3-ChooseAmount.tsx +86 -86
  58. package/src/components/InvoiceFactoring/borrow/4-ConfirmTransfer.tsx +104 -104
  59. package/src/components/InvoiceFactoring/borrow/5-ApproveNFT.tsx +55 -55
  60. package/src/components/InvoiceFactoring/borrow/6-Transfer.tsx +34 -34
  61. package/src/components/InvoiceFactoring/borrow/7-Success.tsx +20 -20
  62. package/src/components/InvoiceFactoring/borrow/index.tsx +96 -96
  63. package/src/components/InvoiceFactoring/payment/1-ChooseAmount.tsx +67 -67
  64. package/src/components/InvoiceFactoring/payment/2-ApproveAllowance.tsx +23 -23
  65. package/src/components/InvoiceFactoring/payment/3-Transfer.tsx +34 -34
  66. package/src/components/InvoiceFactoring/payment/4-Success.tsx +23 -23
  67. package/src/components/InvoiceFactoring/payment/index.tsx +86 -86
  68. package/src/components/Lend/supply/1-Evaluation.tsx +86 -86
  69. package/src/components/Lend/supply/2-ChooseAmount.tsx +70 -70
  70. package/src/components/Lend/supply/3-ApproveAllowance.tsx +25 -25
  71. package/src/components/Lend/supply/4-ConfirmTransfer.tsx +104 -104
  72. package/src/components/Lend/supply/6-Transfer.tsx +32 -32
  73. package/src/components/Lend/supply/7-Success.tsx +49 -49
  74. package/src/components/Lend/supply/index.tsx +144 -144
  75. package/src/components/Lend/withdraw/1-CheckWithdrawble.tsx +73 -73
  76. package/src/components/Lend/withdraw/2-ChooseAmount.tsx +50 -50
  77. package/src/components/Lend/withdraw/3-Transfer.tsx +32 -32
  78. package/src/components/Lend/withdraw/4-Success.tsx +49 -49
  79. package/src/components/Lend/withdraw/index.tsx +101 -101
  80. package/src/components/LoadingModal.tsx +49 -49
  81. package/src/components/StreamFactoring/borrow/1-Evaluation.tsx +47 -57
  82. package/src/components/StreamFactoring/borrow/2-ChooseAmount.tsx +124 -124
  83. package/src/components/StreamFactoring/borrow/3-ConfirmTransfer.tsx +104 -104
  84. package/src/components/StreamFactoring/borrow/4-ApproveAllowance.tsx +65 -65
  85. package/src/components/StreamFactoring/borrow/5-Permit.tsx +144 -144
  86. package/src/components/StreamFactoring/borrow/6-Transfer.tsx +37 -37
  87. package/src/components/StreamFactoring/borrow/7-Success.tsx +20 -20
  88. package/src/components/StreamFactoring/borrow/index.tsx +94 -95
  89. package/src/components/StreamFactoring/payment/ChooseAmount.tsx +54 -54
  90. package/src/components/StreamFactoring/payment/Success.tsx +23 -23
  91. package/src/components/StreamFactoring/payment/Transfer.tsx +34 -34
  92. package/src/components/StreamFactoring/payment/index.tsx +66 -66
  93. package/src/components/SuperfluidFactoring/SuperfluidFactoredList.tsx +61 -61
  94. package/src/components/SuperfluidFactoring/SuperfluidUpcomingList.tsx +185 -185
  95. package/src/components/SuperfluidFactoring/index.tsx +85 -85
  96. package/src/components/TxDoneModal.tsx +83 -83
  97. package/src/components/TxSendModal.tsx +59 -59
  98. package/src/components/ViewOnExplorer.tsx +26 -26
  99. package/src/components/WidgetWrapper.tsx +74 -74
  100. package/src/components/WrapperModal.tsx +54 -54
  101. package/src/components/buttons/TableActionButton.tsx +36 -36
  102. package/src/components/buttons/index.ts +1 -1
  103. package/src/components/humaModal/HumaModal.tsx +68 -68
  104. package/src/components/humaModal/HumaModalHeader.tsx +70 -70
  105. package/src/components/humaModal/index.tsx +2 -2
  106. package/src/components/icons/approve-lender.svg +30 -30
  107. package/src/components/icons/auto-payback.svg +40 -40
  108. package/src/components/icons/check-circle.svg +3 -3
  109. package/src/components/icons/check-green.svg +3 -3
  110. package/src/components/icons/check.svg +10 -10
  111. package/src/components/icons/donut.svg +904 -904
  112. package/src/components/icons/ellipse.svg +3 -3
  113. package/src/components/icons/huma-full.svg +22 -22
  114. package/src/components/icons/huma.svg +15 -15
  115. package/src/components/icons/index.tsx +93 -93
  116. package/src/components/icons/loader.svg +229 -229
  117. package/src/components/icons/metamask.svg +31 -31
  118. package/src/components/icons/polygon.svg +16 -16
  119. package/src/components/icons/receipt.svg +3 -3
  120. package/src/components/icons/separator.svg +3 -3
  121. package/src/components/icons/sorry.svg +31 -31
  122. package/src/components/icons/usdc.svg +5 -5
  123. package/src/components/icons/wallet-connect.svg +11 -11
  124. package/src/cosmos/CreditLineBorrow.fixture.tsx +85 -85
  125. package/src/cosmos/CreditLinePayment.fixture.tsx +49 -49
  126. package/src/cosmos/InvoiceFactoringBorrow.fixture.tsx +111 -111
  127. package/src/cosmos/InvoiceFactoringPayment.fixture.tsx +67 -67
  128. package/src/cosmos/LendSupply.fixture.tsx +75 -75
  129. package/src/cosmos/LendWithdraw.fixture.tsx +43 -43
  130. package/src/cosmos/SDKTesting.fixture.tsx +615 -516
  131. package/src/cosmos/SuperfluidFactoringBorrow.fixture.tsx +12 -12
  132. package/src/cosmos/WalletWrapper.tsx +52 -52
  133. package/src/cosmos/abis/InvoiceNFT.json +644 -644
  134. package/src/cosmos/abis/ReceivableFactoringPool.json +1529 -1529
  135. package/src/cosmos/utils/index.ts +169 -169
  136. package/src/fonts/Recoleta/Recoleta-Black.otf +0 -0
  137. package/src/fonts/Recoleta/Recoleta-Bold.otf +0 -0
  138. package/src/fonts/Recoleta/Recoleta-Light.otf +0 -0
  139. package/src/fonts/Recoleta/Recoleta-Medium.otf +0 -0
  140. package/src/fonts/Recoleta/Recoleta-Regular.otf +0 -0
  141. package/src/fonts/Recoleta/Recoleta-RegularDEMO.otf +0 -0
  142. package/src/fonts/Recoleta/Recoleta-SemiBold.otf +0 -0
  143. package/src/fonts/Recoleta/Recoleta-Thin.otf +0 -0
  144. package/src/hooks/useEA.ts +72 -72
  145. package/src/hooks/useRedux.ts +6 -6
  146. package/src/index.css +61 -61
  147. package/src/index.tsx +219 -213
  148. package/src/react-app-env.d.ts +1 -1
  149. package/src/reportWebVitals.ts +15 -15
  150. package/src/setupTests.ts +6 -6
  151. package/src/store/index.ts +27 -27
  152. package/src/store/widgets.reducers.ts +120 -120
  153. package/src/store/widgets.selectors.ts +3 -3
  154. package/src/store/widgets.store.ts +55 -55
  155. package/src/theme/breakpoints.ts +10 -10
  156. package/src/theme/components.ts +70 -70
  157. package/src/theme/coreThemeConstants.ts +29 -29
  158. package/src/theme/cssMixins.ts +92 -92
  159. package/src/theme/hooks/useGetSizes.ts +31 -31
  160. package/src/theme/index.ts +24 -24
  161. package/src/theme/palette.ts +150 -150
  162. package/src/theme/shape.ts +7 -7
  163. package/src/theme/theme.types.ts +80 -80
  164. package/src/theme/typography.ts +117 -117
  165. package/src/utilTypes.d.ts +29 -29
  166. package/src/utils/env.ts +9 -9
  167. package/tsconfig.build.json +7 -7
  168. package/tsconfig.json +32 -32
  169. package/webpack.cosmos.js +54 -54
@@ -1,516 +1,615 @@
1
- /* eslint-disable jsx-a11y/label-has-associated-control */
2
- /* eslint-disable react/jsx-boolean-value */
3
- /* eslint-disable @typescript-eslint/no-explicit-any */
4
- import { useEffect, useState } from 'react'
5
- import {
6
- EAService,
7
- useCreditRecordDetails,
8
- usePoolContract,
9
- ARWeaveService,
10
- ReceivableService,
11
- } from '@huma-finance/sdk'
12
- import { POOL_NAME, POOL_TYPE } from '@huma-finance/shared'
13
- import { useAccount } from 'wagmi'
14
- import { ethers } from 'ethers'
15
- import { JsonRpcProvider, Web3Provider } from '@ethersproject/providers'
16
-
17
- import { WalletWrapper } from './WalletWrapper'
18
-
19
- const TEST_PRIVATE_KEY = 'REPLACE_WITH_YOUR_PRIVATE_KEY'
20
- const INFURA_PROVIDER_KEY = 'REPLACE_WITH_YOUR_INFURA_PROVIDER_KEY'
21
-
22
- function Fixture() {
23
- const { address, connector } = useAccount()
24
- const [chainId, setChainId] = useState(0)
25
- const [signer, setSigner] = useState<Web3Provider | null>(null)
26
-
27
- if (TEST_PRIVATE_KEY === 'REPLACE_WITH_YOUR_PRIVATE_KEY') {
28
- console.error('Please replace TEST_PRIVATE_KEY with your own private key')
29
- }
30
- if (INFURA_PROVIDER_KEY === 'REPLACE_WITH_YOUR_INFURA_PROVIDER_KEY') {
31
- console.error('Please replace INFURA_PROVIDER_KEY with your own key')
32
- }
33
-
34
- // useCreditRecordDetails
35
- const [userAddress, setUserAddress] = useState('')
36
- const [poolName, setPoolName] = useState<POOL_NAME>(POOL_NAME.RequestNetwork)
37
- const [poolType, setPoolType] = useState<POOL_TYPE>(POOL_TYPE.Invoice)
38
- const provider = new JsonRpcProvider(
39
- `https://goerli.infura.io/v3/${INFURA_PROVIDER_KEY}`,
40
- {
41
- name: 'goerli',
42
- chainId: 5,
43
- },
44
- )
45
- const [creditRecordDetails, refreshCreditRecordDetails] =
46
- useCreditRecordDetails(userAddress, provider, chainId, poolName, poolType)
47
-
48
- // mintReceivableWithMetadata
49
- const [recipientAddress, setRecipientAddress] = useState(address)
50
- const [receivableAmount, setReceivableAmount] = useState(100)
51
- const [maturityDate, setMaturityDate] = useState(Date.now())
52
- const [paymentMethod, setPaymentMethod] = useState(0)
53
- const [metadata, setMetadata] = useState(JSON.stringify({ exampleKey: 1 }))
54
- // Used to set an example tag on the metadata uploaded to ARweave which we can use to query by later
55
- const [internalID, setInternalID] = useState('3')
56
- const [mintResult, setMintResult] = useState<any>('')
57
-
58
- // usePoolContract
59
- const poolContract = usePoolContract(
60
- signer!,
61
- chainId,
62
- POOL_NAME.RequestNetwork,
63
- POOL_TYPE.Invoice,
64
- )
65
-
66
- // EAService.approve
67
- const [borrowerAddress, setBorrowerAddress] = useState('')
68
- const [receivableAddress, setReceivableAddress] = useState(
69
- '0xC2AC172a293d68f548ea343414584aA37eb29Dcd',
70
- )
71
- const [receivableParam, setReceivableParam] = useState('')
72
- const [approveResult, setApproveResult] = useState<any>('')
73
-
74
- const [queryResult, setQueryResult] = useState<any>('')
75
-
76
- useEffect(() => {
77
- ;(async () => {
78
- if (address && connector && window.ethereum) {
79
- setChainId(await connector.getChainId())
80
- setRecipientAddress(address)
81
- // @ts-ignore
82
- const tmp = new ethers.providers.Web3Provider(window.ethereum)
83
- setSigner(tmp)
84
- }
85
- })()
86
- }, [address, connector])
87
-
88
- const handleRefreshCreditRecordDetailsSubmit = (event: any) => {
89
- event.preventDefault()
90
- refreshCreditRecordDetails()
91
- }
92
-
93
- const handleEAApproveSubmit = async (event: any) => {
94
- event.preventDefault()
95
- try {
96
- const data = await EAService.approve(
97
- {
98
- poolAddress: poolContract!.address,
99
- borrowerWalletAddress: borrowerAddress,
100
- receivableAddress,
101
- receivableParam,
102
- },
103
- 5,
104
- )
105
- setApproveResult('Success')
106
- console.log(data)
107
- } catch (error) {
108
- setApproveResult('Failed')
109
- console.log(error)
110
- }
111
- }
112
-
113
- const handleMintReceivableWithMetadataSubmit = async (event: any) => {
114
- event.preventDefault()
115
-
116
- if (signer === null) return
117
-
118
- try {
119
- const data = await ReceivableService.mintReceivableWithMetadata(
120
- signer,
121
- TEST_PRIVATE_KEY!,
122
- chainId,
123
- poolName,
124
- poolType,
125
- receivableAmount,
126
- maturityDate,
127
- paymentMethod,
128
- JSON.parse(metadata),
129
- internalID,
130
- [],
131
- )
132
- setMintResult(`Success, Tx Hash: ${data.transactionHash}`)
133
- console.log(data)
134
- } catch (error) {
135
- setMintResult(`Failed, check console for errors`)
136
- console.log(error)
137
- }
138
- }
139
-
140
- const queryARWeaveSubmit = async (event: any) => {
141
- event.preventDefault()
142
-
143
- if (address == null) return
144
-
145
- try {
146
- const data = await ARWeaveService.queryForMetadata(
147
- chainId,
148
- poolName,
149
- poolType,
150
- address,
151
- internalID,
152
- )
153
- setQueryResult(data)
154
- console.log(data)
155
- } catch (error) {
156
- setQueryResult(`Failed, check console for errors`)
157
- console.log(error)
158
- }
159
- }
160
-
161
- return (
162
- <div
163
- style={{
164
- fontFamily: 'Helvetica',
165
- display: 'flex',
166
- flexDirection: 'column',
167
- gap: '15px',
168
- }}
169
- >
170
- <div
171
- style={{
172
- border: '1px solid gray',
173
- padding: '0px 10px 20px 10px',
174
- borderRadius: '10px',
175
- }}
176
- >
177
- <h3>Test useCreditRecordDetails</h3>
178
- <form
179
- onSubmit={handleRefreshCreditRecordDetailsSubmit}
180
- style={{ display: 'flex', flexDirection: 'column', gap: '5px' }}
181
- >
182
- <label>
183
- Network: <input disabled type='text' defaultValue='Goerli' />
184
- </label>
185
- <br />
186
- <label>
187
- User Address:
188
- <input
189
- type='text'
190
- value={userAddress}
191
- onChange={(event: any) => {
192
- setUserAddress(event.target.value)
193
- }}
194
- />
195
- </label>
196
- <br />
197
- <label>
198
- Pool Name:
199
- <select
200
- name='pool_name'
201
- value={poolName}
202
- onChange={(event: any) => {
203
- setPoolName(event.target.value)
204
- }}
205
- >
206
- <option value='RequestNetwork'>RequestNetwork</option>
207
- <option value='HumaCreditLine'>HumaCreditLine</option>
208
- <option value='Superfluid'>Superfluid</option>
209
- <option value='Jia'>Jia</option>
210
- </select>
211
- </label>
212
- <br />
213
- <label>
214
- Pool Type:
215
- <select
216
- name='pool_type'
217
- value={poolType}
218
- onChange={(event: any) => {
219
- setPoolType(event.target.value)
220
- }}
221
- >
222
- <option value='Invoice'>Invoice</option>
223
- <option value='CreditLine'>CreditLine</option>
224
- <option value='Stream'>Stream</option>
225
- </select>
226
- </label>
227
- <br />
228
- <button type='submit' style={{ width: 'fit-content' }}>
229
- Get Credit Record Details
230
- </button>
231
- </form>
232
- {creditRecordDetails && (
233
- <div>
234
- <h2>Credit Record Details:</h2>
235
- <ul>aprInBps: {creditRecordDetails.aprInBps}</ul>
236
- <ul>correction: {creditRecordDetails.correction.toString()}</ul>
237
- <ul>creditLimit: {creditRecordDetails.creditLimit.toString()}</ul>
238
- <ul>
239
- defaultAmount: {creditRecordDetails.defaultAmount.toString()}
240
- </ul>
241
- <ul>dueDate: {creditRecordDetails.dueDate.toString()}</ul>
242
- <ul>
243
- feesAndInterestDue:{' '}
244
- {creditRecordDetails.feesAndInterestDue.toString()}
245
- </ul>
246
- <ul>intervalInDays: {creditRecordDetails.intervalInDays}</ul>
247
- <ul>missedPeriods: {creditRecordDetails.missedPeriods}</ul>
248
- <ul>remainingPeriods: {creditRecordDetails.remainingPeriods}</ul>
249
- <ul>state: {creditRecordDetails.state}</ul>
250
- <ul>totalDue: {creditRecordDetails.totalDue.toString()}</ul>
251
- <ul>
252
- unbilledPrincipal:{' '}
253
- {creditRecordDetails.unbilledPrincipal.toString()}
254
- </ul>
255
- </div>
256
- )}
257
- </div>
258
- <div
259
- style={{
260
- border: '1px solid gray',
261
- padding: '0px 10px 20px 10px',
262
- borderRadius: '10px',
263
- }}
264
- >
265
- <h3>Test usePoolContract</h3>
266
- {poolContract?.address}
267
- </div>
268
- <div
269
- style={{
270
- border: '1px solid gray',
271
- padding: '0px 10px 20px 10px',
272
- borderRadius: '10px',
273
- }}
274
- >
275
- <form
276
- onSubmit={handleEAApproveSubmit}
277
- style={{ display: 'flex', flexDirection: 'column', gap: '5px' }}
278
- >
279
- <h3>Test EAService.approve</h3>
280
- <label>
281
- Borrower Address:
282
- <input
283
- type='text'
284
- value={borrowerAddress}
285
- onChange={(event: any) => {
286
- setBorrowerAddress(event.target.value)
287
- }}
288
- />
289
- </label>
290
- <br />
291
- <label>
292
- Receivable Address:
293
- <input
294
- type='text'
295
- value={receivableAddress}
296
- onChange={(event: any) => {
297
- setReceivableAddress(event.target.value)
298
- }}
299
- />
300
- </label>
301
- <br />
302
- <label>
303
- Receivable Parameter (Token ID):
304
- <input
305
- type='text'
306
- value={receivableParam}
307
- onChange={(event: any) => {
308
- setReceivableParam(event.target.value)
309
- }}
310
- />
311
- </label>
312
- <br />
313
- <button type='submit' style={{ width: 'fit-content' }}>
314
- Get Credit Record Details
315
- </button>
316
- </form>
317
- {approveResult}
318
- </div>
319
- <div
320
- style={{
321
- border: '1px solid gray',
322
- padding: '0px 10px 20px 10px',
323
- borderRadius: '10px',
324
- }}
325
- >
326
- <form
327
- onSubmit={handleMintReceivableWithMetadataSubmit}
328
- style={{ display: 'flex', flexDirection: 'column', gap: '5px' }}
329
- >
330
- <h3>Test mintReceivableWithMetadata</h3>
331
- <label>
332
- Recipient Address:
333
- <input
334
- type='text'
335
- value={recipientAddress}
336
- onChange={(event: any) => {
337
- setRecipientAddress(event.target.value)
338
- }}
339
- />
340
- </label>
341
- <br />
342
- <label>
343
- Pool Name:
344
- <select
345
- name='pool_name'
346
- value={poolName}
347
- onChange={(event: any) => {
348
- setPoolName(event.target.value)
349
- }}
350
- >
351
- <option value='RequestNetwork'>RequestNetwork</option>
352
- <option value='HumaCreditLine'>HumaCreditLine</option>
353
- <option value='Superfluid'>Superfluid</option>
354
- <option value='Jia'>Jia</option>
355
- </select>
356
- </label>
357
- <br />
358
- <label>
359
- Pool Type:
360
- <select
361
- name='pool_type'
362
- value={poolType}
363
- onChange={(event: any) => {
364
- setPoolType(event.target.value)
365
- }}
366
- >
367
- <option value='Invoice'>Invoice</option>
368
- <option value='CreditLine'>CreditLine</option>
369
- <option value='Stream'>Stream</option>
370
- </select>
371
- </label>
372
- <br />
373
- <label>
374
- Receivable Amount:
375
- <input
376
- type='text'
377
- value={receivableAmount}
378
- onChange={(event: any) => {
379
- setReceivableAmount(event.target.value)
380
- }}
381
- />
382
- </label>
383
- <label>
384
- Maturity Date:
385
- <input
386
- type='text'
387
- value={maturityDate}
388
- onChange={(event: any) => {
389
- setMaturityDate(event.target.value)
390
- }}
391
- />
392
- </label>
393
- <br />
394
- <label>
395
- Payment Method:
396
- <select
397
- name='payment_method'
398
- value={paymentMethod}
399
- onChange={(event: any) => {
400
- setPaymentMethod(event.target.value)
401
- }}
402
- >
403
- <option value='0'>Declarative</option>
404
- <option value='1'>Payable</option>
405
- </select>
406
- </label>
407
- <br />
408
- <label>
409
- Metadata:
410
- <input
411
- type='text'
412
- value={metadata}
413
- onChange={(event: any) => {
414
- setMetadata(event.target.value)
415
- }}
416
- />
417
- </label>
418
- <br />
419
- <label>
420
- Reference ID (For querying through ARWeave):
421
- <input
422
- type='text'
423
- value={internalID}
424
- onChange={(event: any) => {
425
- setInternalID(event.target.value)
426
- }}
427
- />
428
- </label>
429
- <button type='submit' style={{ width: 'fit-content' }}>
430
- Mint Receivable With Metadata
431
- </button>
432
- <br />
433
- {mintResult}
434
- </form>
435
- {approveResult}
436
- </div>
437
- <div
438
- style={{
439
- border: '1px solid gray',
440
- padding: '0px 10px 20px 10px',
441
- borderRadius: '10px',
442
- }}
443
- >
444
- <h3>Test queryForMetadata</h3>
445
- <form
446
- onSubmit={queryARWeaveSubmit}
447
- style={{ display: 'flex', flexDirection: 'column', gap: '5px' }}
448
- >
449
- <label>
450
- Transaction sender:
451
- <input type='text' value={address} disabled />
452
- </label>
453
- <br />
454
- <label>
455
- Pool Name:
456
- <select
457
- name='pool_name'
458
- value={poolName}
459
- onChange={(event: any) => {
460
- setPoolName(event.target.value)
461
- }}
462
- >
463
- <option value='RequestNetwork'>RequestNetwork</option>
464
- <option value='HumaCreditLine'>HumaCreditLine</option>
465
- <option value='Superfluid'>Superfluid</option>
466
- <option value='Jia'>Jia</option>
467
- </select>
468
- </label>
469
- <br />
470
- <label>
471
- Pool Type:
472
- <select
473
- name='pool_type'
474
- value={poolType}
475
- onChange={(event: any) => {
476
- setPoolType(event.target.value)
477
- }}
478
- >
479
- <option value='Invoice'>Invoice</option>
480
- <option value='CreditLine'>CreditLine</option>
481
- <option value='Stream'>Stream</option>
482
- </select>
483
- </label>
484
- <label>
485
- Reference ID (For querying through ARWeave):
486
- <input
487
- type='text'
488
- value={internalID}
489
- onChange={(event: any) => {
490
- setInternalID(event.target.value)
491
- }}
492
- />
493
- </label>
494
- <br />
495
- <button type='submit' style={{ width: 'fit-content' }}>
496
- Query Metadata
497
- </button>
498
- <br />
499
- <a
500
- href={`https://arweave.net/${queryResult}`}
501
- target='_blank'
502
- rel='noreferrer'
503
- >
504
- {queryResult}
505
- </a>
506
- </form>
507
- </div>
508
- </div>
509
- )
510
- }
511
-
512
- export default (
513
- <WalletWrapper>
514
- <Fixture />
515
- </WalletWrapper>
516
- )
1
+ /* eslint-disable jsx-a11y/label-has-associated-control */
2
+ /* eslint-disable react/jsx-boolean-value */
3
+ /* eslint-disable @typescript-eslint/no-explicit-any */
4
+ import { useEffect, useState } from 'react'
5
+ import {
6
+ EAService,
7
+ useCreditRecordDetails,
8
+ usePoolContract,
9
+ ARWeaveService,
10
+ ReceivableService,
11
+ } from '@huma-finance/sdk'
12
+ import { POOL_NAME, POOL_TYPE } from '@huma-finance/shared'
13
+ import { useAccount } from 'wagmi'
14
+ import { ethers } from 'ethers'
15
+ import { JsonRpcProvider, Web3Provider } from '@ethersproject/providers'
16
+
17
+ import { WalletWrapper } from './WalletWrapper'
18
+
19
+ const TEST_PRIVATE_KEY = 'REPLACE_WITH_YOUR_PRIVATE_KEY'
20
+ const INFURA_PROVIDER_KEY = 'REPLACE_WITH_YOUR_INFURA_PROVIDER_KEY'
21
+
22
+ function Fixture() {
23
+ const { address, connector } = useAccount()
24
+ const [chainId, setChainId] = useState(0)
25
+ const [signer, setSigner] = useState<Web3Provider | null>(null)
26
+
27
+ // useCreditRecordDetails
28
+ const [userAddress, setUserAddress] = useState('')
29
+ const [poolName, setPoolName] = useState<POOL_NAME>(POOL_NAME.HumaCreditLine)
30
+ const [poolType, setPoolType] = useState<POOL_TYPE>(POOL_TYPE.CreditLine)
31
+ const provider = new JsonRpcProvider(
32
+ `https://goerli.infura.io/v3/${INFURA_PROVIDER_KEY}`,
33
+ {
34
+ name: 'goerli',
35
+ chainId: 5,
36
+ },
37
+ )
38
+ const [creditRecordDetails, refreshCreditRecordDetails] =
39
+ useCreditRecordDetails(userAddress, provider, chainId, poolName, poolType)
40
+
41
+ // mintReceivableWithMetadata
42
+ const [recipientAddress, setRecipientAddress] = useState(address)
43
+ const [receivableAmount, setReceivableAmount] = useState(100)
44
+ const [maturityDate, setMaturityDate] = useState(Date.now())
45
+ const [metadata, setMetadata] = useState(JSON.stringify({ exampleKey: 1 }))
46
+ // Used to set an example tag on the metadata uploaded to ARweave which we can use to query by later
47
+ const [referenceId, setReferenceId] = useState('3')
48
+ const [mintResult, setMintResult] = useState<any>('')
49
+
50
+ // usePoolContract
51
+ const poolContract = usePoolContract(
52
+ signer!,
53
+ chainId,
54
+ POOL_NAME.HumaCreditLine,
55
+ POOL_TYPE.CreditLine,
56
+ )
57
+
58
+ // EAService.approve
59
+ const [borrowerAddress, setBorrowerAddress] = useState('')
60
+ const [receivableAddress, setReceivableAddress] = useState(
61
+ '0xC2AC172a293d68f548ea343414584aA37eb29Dcd',
62
+ )
63
+ const [receivableParam, setReceivableParam] = useState('')
64
+ const [approveResult, setApproveResult] = useState<any>('')
65
+
66
+ const [queryResult, setQueryResult] = useState<any>('')
67
+
68
+ useEffect(() => {
69
+ ;(async () => {
70
+ if (address && connector && window.ethereum) {
71
+ setChainId(await connector.getChainId())
72
+ setRecipientAddress(address)
73
+ // @ts-ignore
74
+ const tmp = new ethers.providers.Web3Provider(window.ethereum)
75
+ setSigner(tmp)
76
+ }
77
+ })()
78
+ }, [address, connector])
79
+
80
+ const handleRefreshCreditRecordDetailsSubmit = (event: any) => {
81
+ event.preventDefault()
82
+ refreshCreditRecordDetails()
83
+ }
84
+
85
+ const handleEAApproveSubmit = async (event: any) => {
86
+ event.preventDefault()
87
+ try {
88
+ const data = await EAService.approve(
89
+ {
90
+ poolAddress: poolContract!.address,
91
+ borrowerWalletAddress: borrowerAddress,
92
+ receivableAddress,
93
+ receivableParam,
94
+ },
95
+ 5,
96
+ )
97
+ setApproveResult('Success')
98
+ console.log(data)
99
+ } catch (error) {
100
+ setApproveResult('Failed')
101
+ console.log(error)
102
+ }
103
+ }
104
+
105
+ const handleMintReceivableWithMetadataSubmit = async (event: any) => {
106
+ event.preventDefault()
107
+
108
+ if (signer === null) return
109
+
110
+ try {
111
+ const data = await ReceivableService.createReceivableWithMetadata(
112
+ signer,
113
+ TEST_PRIVATE_KEY!,
114
+ chainId,
115
+ poolName,
116
+ poolType,
117
+ 840, // currency code for USD
118
+ receivableAmount,
119
+ maturityDate,
120
+ JSON.parse(metadata),
121
+ referenceId,
122
+ [],
123
+ )
124
+ const txResult = await data.wait()
125
+ setMintResult(`Success, Tx Hash: ${txResult.transactionHash}`)
126
+ console.log(data)
127
+ } catch (error) {
128
+ setMintResult(`Failed, check console for errors`)
129
+ console.log(error)
130
+ }
131
+ }
132
+
133
+ const queryARWeaveSubmit = async (event: any) => {
134
+ event.preventDefault()
135
+
136
+ if (address == null) return
137
+
138
+ try {
139
+ const data = await ARWeaveService.queryForMetadata(
140
+ chainId,
141
+ address,
142
+ referenceId,
143
+ )
144
+ setQueryResult(data)
145
+ console.log(data)
146
+ } catch (error) {
147
+ setQueryResult(`Failed, check console for errors`)
148
+ console.log(error)
149
+ }
150
+ }
151
+
152
+ const [prefundAmt, setPrefundAmt] = useState<number>(0)
153
+ const [prefundResult, setPrefundResult] = useState<string>('')
154
+ const prefundARWeaveSubmit = async (event: any) => {
155
+ event.preventDefault()
156
+
157
+ try {
158
+ const data = await ARWeaveService.prefundBundlr(
159
+ ARWeaveService.getBundlrNetworkConfig(5),
160
+ signer,
161
+ prefundAmt,
162
+ )
163
+ setPrefundResult('Success')
164
+ console.log(data)
165
+ } catch (error) {
166
+ setPrefundResult(`Failed, check console for errors`)
167
+ console.log(error)
168
+ }
169
+ }
170
+
171
+ const [paymentAmount, setPaymentAmount] = useState<number>(0)
172
+ const [paymentResult, setPaymentResult] = useState<string>('')
173
+ const declarePaymentSubmit = async (event: any) => {
174
+ event.preventDefault()
175
+
176
+ try {
177
+ const data =
178
+ await ReceivableService.declareReceivablePaymentByReferenceId(
179
+ signer?.getSigner()!,
180
+ referenceId,
181
+ paymentAmount,
182
+ )
183
+ const txResult = await data.wait()
184
+ setPaymentResult(`Success, Tx Hash: ${txResult.transactionHash}`)
185
+ console.log(data)
186
+ } catch (error) {
187
+ setPaymentResult(`Failed, check console for errors`)
188
+ console.log(error)
189
+ }
190
+ }
191
+
192
+ return (
193
+ <div
194
+ style={{
195
+ fontFamily: 'Helvetica',
196
+ display: 'flex',
197
+ flexDirection: 'column',
198
+ gap: '15px',
199
+ }}
200
+ >
201
+ <div
202
+ style={{
203
+ border: '1px solid gray',
204
+ padding: '0px 10px 20px 10px',
205
+ borderRadius: '10px',
206
+ }}
207
+ >
208
+ <h3>Example 1. React hooks to get credit loan details</h3>
209
+ <form
210
+ onSubmit={handleRefreshCreditRecordDetailsSubmit}
211
+ style={{ display: 'flex', flexDirection: 'column', gap: '5px' }}
212
+ >
213
+ <label>
214
+ Network: <input disabled type='text' defaultValue='Goerli' />
215
+ </label>
216
+ <br />
217
+ <label>
218
+ User Address:
219
+ <input
220
+ type='text'
221
+ value={userAddress}
222
+ onChange={(event: any) => {
223
+ setUserAddress(event.target.value)
224
+ }}
225
+ />
226
+ </label>
227
+ <br />
228
+ <label>
229
+ Pool Name:
230
+ <select
231
+ name='pool_name'
232
+ value={poolName}
233
+ onChange={(event: any) => {
234
+ setPoolName(event.target.value)
235
+ }}
236
+ >
237
+ <option value='RequestNetwork'>RequestNetwork</option>
238
+ <option value='HumaCreditLine'>HumaCreditLine</option>
239
+ <option value='Superfluid'>Superfluid</option>
240
+ <option value='Jia'>Jia</option>
241
+ </select>
242
+ </label>
243
+ <br />
244
+ <label>
245
+ Pool Type:
246
+ <select
247
+ name='pool_type'
248
+ value={poolType}
249
+ onChange={(event: any) => {
250
+ setPoolType(event.target.value)
251
+ }}
252
+ >
253
+ <option value='Invoice'>Invoice</option>
254
+ <option value='CreditLine'>CreditLine</option>
255
+ <option value='Stream'>Stream</option>
256
+ </select>
257
+ </label>
258
+ <br />
259
+ <button type='submit' style={{ width: 'fit-content' }}>
260
+ Get Credit Record Details
261
+ </button>
262
+ </form>
263
+ {creditRecordDetails && (
264
+ <div>
265
+ <h2>Credit Record Details:</h2>
266
+ <ul>aprInBps: {creditRecordDetails.aprInBps}</ul>
267
+ <ul>correction: {creditRecordDetails.correction.toString()}</ul>
268
+ <ul>creditLimit: {creditRecordDetails.creditLimit.toString()}</ul>
269
+ <ul>
270
+ defaultAmount: {creditRecordDetails.defaultAmount.toString()}
271
+ </ul>
272
+ <ul>dueDate: {creditRecordDetails.dueDate.toString()}</ul>
273
+ <ul>
274
+ feesAndInterestDue:{' '}
275
+ {creditRecordDetails.feesAndInterestDue.toString()}
276
+ </ul>
277
+ <ul>intervalInDays: {creditRecordDetails.intervalInDays}</ul>
278
+ <ul>missedPeriods: {creditRecordDetails.missedPeriods}</ul>
279
+ <ul>remainingPeriods: {creditRecordDetails.remainingPeriods}</ul>
280
+ <ul>state: {creditRecordDetails.state}</ul>
281
+ <ul>totalDue: {creditRecordDetails.totalDue.toString()}</ul>
282
+ <ul>
283
+ unbilledPrincipal:{' '}
284
+ {creditRecordDetails.unbilledPrincipal.toString()}
285
+ </ul>
286
+ </div>
287
+ )}
288
+ </div>
289
+ <div
290
+ style={{
291
+ border: '1px solid gray',
292
+ padding: '0px 10px 20px 10px',
293
+ borderRadius: '10px',
294
+ }}
295
+ >
296
+ <h3>Example 2. React hooks to get ethers.js contract instances</h3>
297
+ {poolContract?.address}
298
+ </div>
299
+ <div
300
+ style={{
301
+ border: '1px solid gray',
302
+ padding: '0px 10px 20px 10px',
303
+ borderRadius: '10px',
304
+ }}
305
+ >
306
+ <form
307
+ onSubmit={handleEAApproveSubmit}
308
+ style={{ display: 'flex', flexDirection: 'column', gap: '5px' }}
309
+ >
310
+ <h3>Test EAService.approve</h3>
311
+ <label>
312
+ Borrower Address:
313
+ <input
314
+ type='text'
315
+ value={borrowerAddress}
316
+ onChange={(event: any) => {
317
+ setBorrowerAddress(event.target.value)
318
+ }}
319
+ />
320
+ </label>
321
+ <br />
322
+ <label>
323
+ Receivable Address:
324
+ <input
325
+ type='text'
326
+ value={receivableAddress}
327
+ onChange={(event: any) => {
328
+ setReceivableAddress(event.target.value)
329
+ }}
330
+ />
331
+ </label>
332
+ <br />
333
+ <label>
334
+ Receivable Parameter (Token ID):
335
+ <input
336
+ type='text'
337
+ value={receivableParam}
338
+ onChange={(event: any) => {
339
+ setReceivableParam(event.target.value)
340
+ }}
341
+ />
342
+ </label>
343
+ <br />
344
+ <button type='submit' style={{ width: 'fit-content' }}>
345
+ Get Credit Record Details
346
+ </button>
347
+ </form>
348
+ {approveResult}
349
+ </div>
350
+ <div
351
+ style={{
352
+ border: '1px solid gray',
353
+ padding: '0px 10px 20px 10px',
354
+ borderRadius: '10px',
355
+ }}
356
+ >
357
+ <form
358
+ onSubmit={handleMintReceivableWithMetadataSubmit}
359
+ style={{ display: 'flex', flexDirection: 'column', gap: '5px' }}
360
+ >
361
+ <h3>
362
+ Example 3. Create RealWorldReceivable token with metadata on ARWeave
363
+ </h3>
364
+ <label>
365
+ Recipient Address:
366
+ <input
367
+ type='text'
368
+ value={recipientAddress}
369
+ onChange={(event: any) => {
370
+ setRecipientAddress(event.target.value)
371
+ }}
372
+ />
373
+ </label>
374
+ <br />
375
+ <label>
376
+ Pool Name:
377
+ <select
378
+ name='pool_name'
379
+ value={poolName}
380
+ onChange={(event: any) => {
381
+ setPoolName(event.target.value)
382
+ }}
383
+ >
384
+ <option value='RequestNetwork'>RequestNetwork</option>
385
+ <option value='HumaCreditLine'>HumaCreditLine</option>
386
+ <option value='Superfluid'>Superfluid</option>
387
+ <option value='Jia'>Jia</option>
388
+ </select>
389
+ </label>
390
+ <br />
391
+ <label>
392
+ Pool Type:
393
+ <select
394
+ name='pool_type'
395
+ value={poolType}
396
+ onChange={(event: any) => {
397
+ setPoolType(event.target.value)
398
+ }}
399
+ >
400
+ <option value='Invoice'>Invoice</option>
401
+ <option value='CreditLine'>CreditLine</option>
402
+ <option value='Stream'>Stream</option>
403
+ </select>
404
+ </label>
405
+ <br />
406
+ <label>
407
+ Receivable Amount:
408
+ <input
409
+ type='text'
410
+ value={receivableAmount}
411
+ onChange={(event: any) => {
412
+ setReceivableAmount(event.target.value)
413
+ }}
414
+ />
415
+ </label>
416
+ <label>
417
+ Maturity Date:
418
+ <input
419
+ type='text'
420
+ value={maturityDate}
421
+ onChange={(event: any) => {
422
+ setMaturityDate(event.target.value)
423
+ }}
424
+ />
425
+ </label>
426
+ <br />
427
+ <label>
428
+ Metadata:
429
+ <input
430
+ type='text'
431
+ value={metadata}
432
+ onChange={(event: any) => {
433
+ setMetadata(event.target.value)
434
+ }}
435
+ />
436
+ </label>
437
+ <br />
438
+ <label>
439
+ Reference ID (For querying through ARWeave):
440
+ <input
441
+ type='text'
442
+ value={referenceId}
443
+ onChange={(event: any) => {
444
+ setReferenceId(event.target.value)
445
+ }}
446
+ />
447
+ </label>
448
+ <button type='submit' style={{ width: 'fit-content' }}>
449
+ Create Receivable With Metadata
450
+ </button>
451
+ <br />
452
+ {mintResult}
453
+ </form>
454
+ {approveResult}
455
+ </div>
456
+ <div
457
+ style={{
458
+ border: '1px solid gray',
459
+ padding: '0px 10px 20px 10px',
460
+ borderRadius: '10px',
461
+ }}
462
+ >
463
+ <h3>Example 4. Query for metadata on ARWeave</h3>
464
+ <form
465
+ onSubmit={queryARWeaveSubmit}
466
+ style={{ display: 'flex', flexDirection: 'column', gap: '5px' }}
467
+ >
468
+ <label>
469
+ Transaction sender:
470
+ <input type='text' value={address} disabled />
471
+ </label>
472
+ <br />
473
+ <label>
474
+ Pool Name:
475
+ <select
476
+ name='pool_name'
477
+ value={poolName}
478
+ onChange={(event: any) => {
479
+ setPoolName(event.target.value)
480
+ }}
481
+ >
482
+ <option value='RequestNetwork'>RequestNetwork</option>
483
+ <option value='HumaCreditLine'>HumaCreditLine</option>
484
+ <option value='Superfluid'>Superfluid</option>
485
+ <option value='Jia'>Jia</option>
486
+ </select>
487
+ </label>
488
+ <br />
489
+ <label>
490
+ Pool Type:
491
+ <select
492
+ name='pool_type'
493
+ value={poolType}
494
+ onChange={(event: any) => {
495
+ setPoolType(event.target.value)
496
+ }}
497
+ >
498
+ <option value='Invoice'>Invoice</option>
499
+ <option value='CreditLine'>CreditLine</option>
500
+ <option value='Stream'>Stream</option>
501
+ </select>
502
+ </label>
503
+ <label>
504
+ Reference ID (For querying through ARWeave):
505
+ <input
506
+ type='text'
507
+ value={referenceId}
508
+ onChange={(event: any) => {
509
+ setReferenceId(event.target.value)
510
+ }}
511
+ />
512
+ </label>
513
+ <br />
514
+ <button type='submit' style={{ width: 'fit-content' }}>
515
+ Query Metadata
516
+ </button>
517
+ <br />
518
+ <a
519
+ href={`https://arweave.net/${queryResult}`}
520
+ target='_blank'
521
+ rel='noreferrer'
522
+ >
523
+ {queryResult}
524
+ </a>
525
+ </form>
526
+ </div>
527
+ <div
528
+ style={{
529
+ border: '1px solid gray',
530
+ padding: '0px 10px 20px 10px',
531
+ borderRadius: '10px',
532
+ }}
533
+ >
534
+ <h3>Example 5. Declare payment for Receivable by reference ID</h3>
535
+ <form
536
+ onSubmit={declarePaymentSubmit}
537
+ style={{ display: 'flex', flexDirection: 'column', gap: '5px' }}
538
+ >
539
+ <label>
540
+ Transaction sender:
541
+ <input type='text' value={address} disabled />
542
+ </label>
543
+ <br />
544
+ <label>
545
+ Reference ID (For querying through ARWeave):
546
+ <input
547
+ type='text'
548
+ value={referenceId}
549
+ onChange={(event: any) => {
550
+ setReferenceId(event.target.value)
551
+ }}
552
+ />
553
+ </label>
554
+ <br />
555
+ <label>
556
+ Payment Amount:
557
+ <input
558
+ type='text'
559
+ value={paymentAmount}
560
+ onChange={(event: any) => {
561
+ setPaymentAmount(event.target.value)
562
+ }}
563
+ />
564
+ </label>
565
+ <br />
566
+ <button type='submit' style={{ width: 'fit-content' }}>
567
+ Declare Payment
568
+ </button>
569
+ <br />
570
+ {paymentResult}
571
+ </form>
572
+ </div>
573
+ <div
574
+ style={{
575
+ border: '1px solid gray',
576
+ padding: '0px 10px 20px 10px',
577
+ borderRadius: '10px',
578
+ }}
579
+ >
580
+ <h3>Example 6. Prefund ARWeave</h3>
581
+ <form
582
+ onSubmit={prefundARWeaveSubmit}
583
+ style={{ display: 'flex', flexDirection: 'column', gap: '5px' }}
584
+ >
585
+ <label>
586
+ Transaction sender:
587
+ <input type='text' value={address} disabled />
588
+ </label>
589
+ <br />
590
+ <label>
591
+ Amount (Atomic Units):
592
+ <input
593
+ type='text'
594
+ value={prefundAmt}
595
+ onChange={(event: any) => {
596
+ setPrefundAmt(event.target.value)
597
+ }}
598
+ />
599
+ </label>
600
+ <br />
601
+ <button type='submit' style={{ width: 'fit-content' }}>
602
+ Prefund ARWeave
603
+ </button>
604
+ {prefundResult}
605
+ </form>
606
+ </div>
607
+ </div>
608
+ )
609
+ }
610
+
611
+ export default (
612
+ <WalletWrapper>
613
+ <Fixture />
614
+ </WalletWrapper>
615
+ )