1- import React from ' react'
2- import web3 from ' ./ethereum/web3'
3- import generateEvidence from ' ./ethereum/generate-evidence'
4- import generateMetaevidence from ' ./ethereum/generate-meta-evidence'
5- import * as SimpleEscrowWithERC1497 from ' ./ethereum/simple-escrow-with-erc1497'
6- import * as Arbitrator from ' ./ethereum/arbitrator'
7- import Ipfs from ' ipfs-http-client'
8- import ipfsPublish from ' ./ipfs-publish'
9-
10- import Container from ' react-bootstrap/Container'
11- import Jumbotron from ' react-bootstrap/Jumbotron'
12- import Button from ' react-bootstrap/Button'
13- import Form from ' react-bootstrap/Form'
14- import Row from ' react-bootstrap/Row'
15- import Col from ' react-bootstrap/Col'
16- import Deploy from ' ./deploy.js'
17- import Interact from ' ./interact.js'
1+ import React from " react" ;
2+ import web3 from " ./ethereum/web3" ;
3+ import generateEvidence from " ./ethereum/generate-evidence" ;
4+ import generateMetaevidence from " ./ethereum/generate-meta-evidence" ;
5+ import * as SimpleEscrowWithERC1497 from " ./ethereum/simple-escrow-with-erc1497" ;
6+ import * as Arbitrator from " ./ethereum/arbitrator" ;
7+ import Ipfs from " ipfs-http-client" ;
8+ import ipfsPublish from " ./ipfs-publish" ;
9+
10+ import Container from " react-bootstrap/Container" ;
11+ import Jumbotron from " react-bootstrap/Jumbotron" ;
12+ import Button from " react-bootstrap/Button" ;
13+ import Form from " react-bootstrap/Form" ;
14+ import Row from " react-bootstrap/Row" ;
15+ import Col from " react-bootstrap/Col" ;
16+ import Deploy from " ./deploy.js" ;
17+ import Interact from " ./interact.js" ;
1818
1919class App extends React . Component {
2020 constructor ( props ) {
21- super ( props )
21+ super ( props ) ;
2222 this . state = {
23- activeAddress : ' 0x0000000000000000000000000000000000000000' ,
24- lastDeployedAddress : ' 0x0000000000000000000000000000000000000000'
25- }
23+ activeAddress : " 0x0000000000000000000000000000000000000000" ,
24+ lastDeployedAddress : " 0x0000000000000000000000000000000000000000" ,
25+ } ;
2626 this . ipfs = new Ipfs ( {
27- host : ' ipfs.kleros.io' ,
27+ host : " ipfs.kleros.io" ,
2828 port : 5001 ,
29- protocol : ' https'
30- } )
29+ protocol : " https" ,
30+ } ) ;
3131 }
3232
3333 deploy = async ( amount , payee , arbitrator , title , description ) => {
34- const { activeAddress } = this . state
34+ const { activeAddress } = this . state ;
3535
3636 let metaevidence = generateMetaevidence (
3737 web3 . utils . toChecksumAddress ( activeAddress ) ,
3838 web3 . utils . toChecksumAddress ( payee ) ,
3939 amount ,
4040 title ,
4141 description
42- )
43- const enc = new TextEncoder ( )
44- const ipfsHashMetaEvidenceObj = await ipfsPublish (
45- 'metaEvidence.json' ,
46- enc . encode ( JSON . stringify ( metaevidence ) )
47- )
42+ ) ;
43+ const enc = new TextEncoder ( ) ;
44+ const ipfsHashMetaEvidenceObj = await ipfsPublish ( "metaEvidence.json" , enc . encode ( JSON . stringify ( metaevidence ) ) ) ;
4845
4946 let result = await SimpleEscrowWithERC1497 . deploy (
5047 activeAddress ,
5148 payee ,
5249 amount ,
5350 arbitrator ,
5451
55- '/ipfs/' +
56- ipfsHashMetaEvidenceObj [ 1 ] [ 'hash' ] +
57- ipfsHashMetaEvidenceObj [ 0 ] [ 'path' ]
58- )
52+ "/ipfs/" + ipfsHashMetaEvidenceObj [ 1 ] [ "hash" ] + ipfsHashMetaEvidenceObj [ 0 ] [ "path" ]
53+ ) ;
5954
60- this . setState ( { lastDeployedAddress : result . _address } )
61- }
55+ this . setState ( { lastDeployedAddress : result . _address } ) ;
56+ } ;
6257
63- load = contractAddress =>
64- SimpleEscrowWithERC1497 . contractInstance ( contractAddress )
58+ load = ( contractAddress ) => SimpleEscrowWithERC1497 . contractInstance ( contractAddress ) ;
6559
6660 reclaimFunds = async ( contractAddress , value ) => {
67- const { activeAddress } = this . state
68- await SimpleEscrowWithERC1497 . reclaimFunds (
69- activeAddress ,
70- contractAddress ,
71- value
72- )
73- }
61+ const { activeAddress } = this . state ;
62+ await SimpleEscrowWithERC1497 . reclaimFunds ( activeAddress , contractAddress , value ) ;
63+ } ;
7464
75- releaseFunds = async contractAddress => {
76- const { activeAddress } = this . state
65+ releaseFunds = async ( contractAddress ) => {
66+ const { activeAddress } = this . state ;
7767
78- await SimpleEscrowWithERC1497 . releaseFunds ( activeAddress , contractAddress )
79- }
68+ await SimpleEscrowWithERC1497 . releaseFunds ( activeAddress , contractAddress ) ;
69+ } ;
8070
8171 depositArbitrationFeeForPayee = ( contractAddress , value ) => {
82- const { activeAddress } = this . state
72+ const { activeAddress } = this . state ;
8373
84- SimpleEscrowWithERC1497 . depositArbitrationFeeForPayee (
85- activeAddress ,
86- contractAddress ,
87- value
88- )
89- }
74+ SimpleEscrowWithERC1497 . depositArbitrationFeeForPayee ( activeAddress , contractAddress , value ) ;
75+ } ;
9076
91- reclamationPeriod = contractAddress =>
92- SimpleEscrowWithERC1497 . reclamationPeriod ( contractAddress )
77+ reclamationPeriod = ( contractAddress ) => SimpleEscrowWithERC1497 . reclamationPeriod ( contractAddress ) ;
9378
94- arbitrationFeeDepositPeriod = contractAddress =>
95- SimpleEscrowWithERC1497 . arbitrationFeeDepositPeriod ( contractAddress )
79+ arbitrationFeeDepositPeriod = ( contractAddress ) =>
80+ SimpleEscrowWithERC1497 . arbitrationFeeDepositPeriod ( contractAddress ) ;
9681
97- remainingTimeToReclaim = contractAddress =>
98- SimpleEscrowWithERC1497 . remainingTimeToReclaim ( contractAddress )
82+ remainingTimeToReclaim = ( contractAddress ) => SimpleEscrowWithERC1497 . remainingTimeToReclaim ( contractAddress ) ;
9983
100- remainingTimeToDepositArbitrationFee = contractAddress =>
101- SimpleEscrowWithERC1497 . remainingTimeToDepositArbitrationFee (
102- contractAddress
103- )
84+ remainingTimeToDepositArbitrationFee = ( contractAddress ) =>
85+ SimpleEscrowWithERC1497 . remainingTimeToDepositArbitrationFee ( contractAddress ) ;
10486
105- arbitrationCost = ( arbitratorAddress , extraData ) =>
106- Arbitrator . arbitrationCost ( arbitratorAddress , extraData )
87+ arbitrationCost = ( arbitratorAddress , extraData ) => Arbitrator . arbitrationCost ( arbitratorAddress , extraData ) ;
10788
108- arbitrator = contractAddress =>
109- SimpleEscrowWithERC1497 . arbitrator ( contractAddress )
89+ arbitrator = ( contractAddress ) => SimpleEscrowWithERC1497 . arbitrator ( contractAddress ) ;
11090
111- status = contractAddress => SimpleEscrowWithERC1497 . status ( contractAddress )
91+ status = ( contractAddress ) => SimpleEscrowWithERC1497 . status ( contractAddress ) ;
11292
113- value = contractAddress => SimpleEscrowWithERC1497 . value ( contractAddress )
93+ value = ( contractAddress ) => SimpleEscrowWithERC1497 . value ( contractAddress ) ;
11494
11595 submitEvidence = async ( contractAddress , evidenceBuffer ) => {
116- const { activeAddress } = this . state
117-
118- const result = await ipfsPublish ( 'name' , evidenceBuffer )
119-
120- let evidence = generateEvidence (
121- '/ipfs/' + result [ 0 ] [ 'hash' ] ,
122- 'name' ,
123- 'description'
124- )
125- const enc = new TextEncoder ( )
126- const ipfsHashEvidenceObj = await ipfsPublish (
127- 'evidence.json' ,
128- enc . encode ( JSON . stringify ( evidence ) )
129- )
130-
131- SimpleEscrowWithERC1497 . submitEvidence (
132- contractAddress ,
133- activeAddress ,
134- '/ipfs/' + ipfsHashEvidenceObj [ 0 ] [ 'hash' ]
135- )
136- }
96+ const { activeAddress } = this . state ;
97+
98+ const result = await ipfsPublish ( "name" , evidenceBuffer ) ;
99+
100+ let evidence = generateEvidence ( "/ipfs/" + result [ 0 ] [ "hash" ] , "name" , "description" ) ;
101+ const enc = new TextEncoder ( ) ;
102+ const ipfsHashEvidenceObj = await ipfsPublish ( "evidence.json" , enc . encode ( JSON . stringify ( evidence ) ) ) ;
103+
104+ SimpleEscrowWithERC1497 . submitEvidence ( contractAddress , activeAddress , "/ipfs/" + ipfsHashEvidenceObj [ 0 ] [ "hash" ] ) ;
105+ } ;
137106
138107 async componentDidMount ( ) {
139- if ( window . web3 && window . web3 . currentProvider . isMetaMask )
140- window . web3 . eth . getAccounts ( ( _ , accounts ) => {
141- this . setState ( { activeAddress : accounts [ 0 ] } )
142- } )
143- else console . error ( ' MetaMask account not detected :(' )
144-
145- window . ethereum . on ( ' accountsChanged' , accounts => {
146- this . setState ( { activeAddress : accounts [ 0 ] } )
147- } )
108+ if ( window . ethereum && window . ethereum . isMetaMask )
109+ window . ethereum . request ( { method : "eth_requestAccounts" } ) . then ( ( accounts ) => {
110+ this . setState ( { activeAddress : accounts [ 0 ] } ) ;
111+ } ) ;
112+ else console . error ( " MetaMask account not detected :(" ) ;
113+
114+ window . ethereum . on ( " accountsChanged" , ( accounts ) => {
115+ this . setState ( { activeAddress : accounts [ 0 ] } ) ;
116+ } ) ;
148117 }
149118
150119 render ( ) {
151- const { lastDeployedAddress } = this . state
120+ const { lastDeployedAddress } = this . state ;
152121 return (
153122 < Container >
154123 < Row >
155124 < Col >
156- < h1 className = "text-center my-5" >
157- A Simple DAPP Using SimpleEscrowWithERC1497
158- </ h1 >
125+ < h1 className = "text-center my-5" > A Simple DAPP Using SimpleEscrowWithERC1497</ h1 >
159126 </ Col >
160127 </ Row >
161128
@@ -171,13 +138,9 @@ class App extends React.Component {
171138 loadCallback = { this . load }
172139 reclaimFundsCallback = { this . reclaimFunds }
173140 releaseFundsCallback = { this . releaseFunds }
174- depositArbitrationFeeForPayeeCallback = {
175- this . depositArbitrationFeeForPayee
176- }
141+ depositArbitrationFeeForPayeeCallback = { this . depositArbitrationFeeForPayee }
177142 remainingTimeToReclaimCallback = { this . remainingTimeToReclaim }
178- remainingTimeToDepositArbitrationFeeCallback = {
179- this . remainingTimeToDepositArbitrationFee
180- }
143+ remainingTimeToDepositArbitrationFeeCallback = { this . remainingTimeToDepositArbitrationFee }
181144 statusCallback = { this . status }
182145 valueCallback = { this . value }
183146 submitEvidenceCallback = { this . submitEvidence }
@@ -190,8 +153,8 @@ class App extends React.Component {
190153 < Jumbotron className = "m-5 text-center" >
191154 < h1 > Need to interact with your arbitrator contract?</ h1 >
192155 < p >
193- We have a general purpose user interface for centralized
194- arbitrators (like we have developed in the tutorial) already.
156+ We have a general purpose user interface for centralized arbitrators (like we have developed in the
157+ tutorial) already.
195158 </ p >
196159 < p >
197160 < Button type = "submit" variant = "primary" >
@@ -203,8 +166,8 @@ class App extends React.Component {
203166 </ Col >
204167 </ Row >
205168 </ Container >
206- )
169+ ) ;
207170 }
208171}
209172
210- export default App
173+ export default App ;
0 commit comments