@huma-finance/widgets 0.0.11 → 0.0.13

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 (46) hide show
  1. package/API.md +6 -5
  2. package/dist/cjs/index.cjs +5058 -5959
  3. package/dist/cjs/index.cjs.map +1 -1
  4. package/dist/index.d.ts +9 -6
  5. package/dist/index.js +5059 -5960
  6. package/dist/index.js.map +1 -1
  7. package/package.json +16 -16
  8. package/src/components/ApproveAllowanceModal.tsx +5 -2
  9. package/src/components/ChainNotSupportedModal.tsx +31 -0
  10. package/src/components/ChooseAmountModal.tsx +322 -315
  11. package/src/components/ConfirmTransferModal.tsx +153 -0
  12. package/src/components/CreditLine/borrow/1-Evaluation.tsx +1 -2
  13. package/src/components/CreditLine/borrow/{3-ChooseAmount.tsx → 2-ChooseAmount.tsx} +2 -8
  14. package/src/components/CreditLine/borrow/{5-Transfer.tsx → 3-Transfer.tsx} +17 -3
  15. package/src/components/CreditLine/borrow/4-ApproveAllowance.tsx +1 -1
  16. package/src/components/CreditLine/borrow/index.tsx +3 -5
  17. package/src/components/Factoring/FactoredList.tsx +1 -1
  18. package/src/components/InvoiceFactoring/borrow/1-Evaluation.tsx +1 -4
  19. package/src/components/InvoiceFactoring/borrow/{3-ChooseAmount.tsx → 2-ChooseAmount.tsx} +5 -3
  20. package/src/components/InvoiceFactoring/borrow/3-ConfirmTransfer.tsx +37 -0
  21. package/src/components/InvoiceFactoring/borrow/index.tsx +5 -7
  22. package/src/components/StreamFactoring/borrow/1-Evaluation.tsx +11 -3
  23. package/src/components/StreamFactoring/borrow/2-ChooseAmount.tsx +4 -1
  24. package/src/components/StreamFactoring/borrow/3-ConfirmTransfer.tsx +18 -80
  25. package/src/components/StreamFactoring/borrow/4-ApproveAllowance.tsx +4 -36
  26. package/src/components/StreamFactoring/borrow/5-Permit.tsx +14 -14
  27. package/src/components/SuperfluidFactoring/SuperfluidUpcomingList.tsx +1 -1
  28. package/src/cosmos/CreditLineBorrow.fixture.tsx +1 -0
  29. package/src/cosmos/CreditLinePayment.fixture.tsx +1 -0
  30. package/src/cosmos/SDKTesting.fixture.tsx +615 -557
  31. package/src/cosmos/SuperfluidFactoringBorrow.fixture.tsx +3 -0
  32. package/src/cosmos/utils/env.ts +6 -0
  33. package/src/hooks/useEA.ts +10 -29
  34. package/src/index.tsx +75 -7
  35. package/src/reportWebVitals.ts +9 -9
  36. package/src/store/widgets.store.ts +0 -1
  37. package/src/utilTypes.d.ts +2 -0
  38. package/webpack.cosmos.js +9 -9
  39. package/src/components/AllowListModal.tsx +0 -113
  40. package/src/components/CreditLine/borrow/2-AllowList.tsx +0 -34
  41. package/src/components/InvoiceFactoring/borrow/2-AllowList.tsx +0 -34
  42. package/src/components/InvoiceFactoring/borrow/4-ConfirmTransfer.tsx +0 -104
  43. /package/src/components/CreditLine/borrow/{6-Success.tsx → 5-Success.tsx} +0 -0
  44. /package/src/components/InvoiceFactoring/borrow/{5-ApproveNFT.tsx → 4-ApproveNFT.tsx} +0 -0
  45. /package/src/components/InvoiceFactoring/borrow/{6-Transfer.tsx → 5-Transfer.tsx} +0 -0
  46. /package/src/components/InvoiceFactoring/borrow/{7-Success.tsx → 6-Success.tsx} +0 -0
@@ -1,557 +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 [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
- )
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
+ )