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