@huma-finance/widgets 0.0.8 → 0.0.11

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