Skip to content

Commit 87c1d38

Browse files
committed
Merge branch 'feature/campaign-new' into develop
2 parents cdc9e94 + 9bfaa81 commit 87c1d38

File tree

4 files changed

+73
-3
lines changed

4 files changed

+73
-3
lines changed

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"main": "index.js",
66
"scripts": {
77
"test": "mocha",
8-
"dev": "next dev"
8+
"dev": "node server.js"
99
},
1010
"author": "Devin Herath",
1111
"license": "MIT",
@@ -14,6 +14,7 @@
1414
"ganache-cli": "^6.4.3",
1515
"mocha": "^6.1.4",
1616
"next": "^4.1.4",
17+
"next-routes": "^1.4.2",
1718
"react": "^16.8.6",
1819
"react-dom": "^16.8.6",
1920
"semantic-ui-css": "^2.4.1",
@@ -22,4 +23,4 @@
2223
"truffle-hdwallet-provider": "0.0.3",
2324
"web3": "^1.0.0-beta.37"
2425
}
25-
}
26+
}

pages/campaigns/new.js

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,59 @@
11
import React, { Component } from 'react';
2+
import { Form, Button, Input, Message } from 'semantic-ui-react';
23
import Layout from '../../components/Layout';
4+
import factory from '../../ethereum/factory';
5+
import web3 from '../../ethereum/web3';
6+
import { Router } from '../../routes';
37

48
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+
536
render() {
637
return (
738
<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>
957
</Layout>
1058
)
1159
}

routes.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
const routes = require('next-routes')();
2+
3+
module.exports = routes;

server.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
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+
});

0 commit comments

Comments
 (0)