File tree Expand file tree Collapse file tree 4 files changed +73
-3
lines changed Expand file tree Collapse file tree 4 files changed +73
-3
lines changed Original file line number Diff line number Diff line change 5
5
"main" : " index.js" ,
6
6
"scripts" : {
7
7
"test" : " mocha" ,
8
- "dev" : " next dev "
8
+ "dev" : " node server.js "
9
9
},
10
10
"author" : " Devin Herath" ,
11
11
"license" : " MIT" ,
14
14
"ganache-cli" : " ^6.4.3" ,
15
15
"mocha" : " ^6.1.4" ,
16
16
"next" : " ^4.1.4" ,
17
+ "next-routes" : " ^1.4.2" ,
17
18
"react" : " ^16.8.6" ,
18
19
"react-dom" : " ^16.8.6" ,
19
20
"semantic-ui-css" : " ^2.4.1" ,
22
23
"truffle-hdwallet-provider" : " 0.0.3" ,
23
24
"web3" : " ^1.0.0-beta.37"
24
25
}
25
- }
26
+ }
Original file line number Diff line number Diff line change 1
1
import React , { Component } from 'react' ;
2
+ import { Form , Button , Input , Message } from 'semantic-ui-react' ;
2
3
import Layout from '../../components/Layout' ;
4
+ import factory from '../../ethereum/factory' ;
5
+ import web3 from '../../ethereum/web3' ;
6
+ import { Router } from '../../routes' ;
3
7
4
8
class CampaignNew extends Component {
9
+ state = {
10
+ minimumContribution : '' ,
11
+ errorMessage : '' ,
12
+ loading : false
13
+ } ;
14
+
15
+ onSubmit = async ( event ) => {
16
+ event . preventDefault ( ) ;
17
+
18
+ this . setState ( { loading : true , errorMessage : '' } ) ;
19
+
20
+ try {
21
+ const accounts = await web3 . eth . getAccounts ( ) ;
22
+ await factory . methods
23
+ . createCampaign ( this . state . minimumContribution )
24
+ . send ( {
25
+ from : accounts [ 0 ]
26
+ } ) ;
27
+
28
+ Router . pushRoute ( '/' ) ;
29
+ } catch ( err ) {
30
+ this . setState ( { errorMessage : err . message } ) ;
31
+ }
32
+
33
+ this . setState ( { loading : false } ) ;
34
+ }
35
+
5
36
render ( ) {
6
37
return (
7
38
< Layout >
8
- < h1 > New Campaign!</ h1 >
39
+ < h3 > Create a Campaign</ h3 >
40
+
41
+ < Form onSubmit = { this . onSubmit } error = { ! ! this . state . errorMessage } >
42
+ < Form . Field >
43
+ < label > Minimum Contribution</ label >
44
+ < Input
45
+ label = "wei"
46
+ labelPosition = "right"
47
+ value = { this . state . minimumContribution }
48
+ onChange = { event => this . setState ( { minimumContribution : event . target . value } ) }
49
+ />
50
+ </ Form . Field >
51
+
52
+ < Message error header = "Oops!" content = { this . state . errorMessage } />
53
+ < Button loading = { this . state . loading } primary >
54
+ Create!
55
+ </ Button >
56
+ </ Form >
9
57
</ Layout >
10
58
)
11
59
}
Original file line number Diff line number Diff line change
1
+ const routes = require ( 'next-routes' ) ( ) ;
2
+
3
+ module . exports = routes ;
Original file line number Diff line number Diff line change
1
+ const { createServer } = require ( 'http' ) ;
2
+ const next = require ( 'next' ) ;
3
+
4
+ const app = next ( {
5
+ dev : process . env . NODE_ENV !== 'production'
6
+ } ) ;
7
+
8
+ const routes = require ( './routes' ) ;
9
+ const handler = routes . getRequestHandler ( app ) ;
10
+
11
+ const port = process . env . PORT || 3000 ;
12
+
13
+ app . prepare ( ) . then ( ( ) => {
14
+ createServer ( handler ) . listen ( port , ( err ) => {
15
+ if ( err ) throw err ;
16
+ console . log ( `Server started on port ${ port } ` ) ;
17
+ } ) ;
18
+ } ) ;
You can’t perform that action at this time.
0 commit comments