-
Notifications
You must be signed in to change notification settings - Fork 1
Collapse file tree
Files
Search this repository(forward slash) forward slash/
/
Copy pathMyBets.js
More file actions
More file actions
Latest commit
204 lines (188 loc) · 6.32 KB
/
Copy pathMyBets.js
File metadata and controls
204 lines (188 loc) · 6.32 KB
You must be signed in to make or propose changes
More edit options
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
import React, { Component } from 'react';
import { ListGroup, ListGroupItem, Col, Row, Button, Form, FormGroup, Label, Input, InputGroupAddon, InputGroup } from 'reactstrap';
import ContentLoader from "react-content-loader";
import axios from 'axios';
import Moment from 'react-moment';
import { connect } from 'react-redux';
import './MyBets.css';
const MyLoader = props => (
<ContentLoader
speed={2}
width={600}
primaryColor="#f3f3f3"
secondaryColor="#ecebeb"
{...props}
>
<rect x="0" y="15" rx="5" ry="5" width="600" height="20" />
<rect x="0" y="45" rx="5" ry="5" width="600" height="20" />
<rect x="0" y="75" rx="5" ry="5" width="600" height="20" />
<rect x="0" y="105" rx="5" ry="5" width="600" height="25" />
</ContentLoader>
)
class MyBets extends Component {
constructor(props) {
super(props);
this.state = {
error: false,
isLoading: true,
title: undefined,
bets: [],
balance: 0,
showing_transfer_stuff: false,
displayingSuccess: false,
}
this.renderBalance = this.renderBalance.bind(this);
this.setShowStuffToTrue = this.setShowStuffToTrue.bind(this);
this.moneyTransferRequest = this.moneyTransferRequest.bind(this);
// this.displayingSuccess = this.displayingSuccess.bind(this);
}
componentDidMount() {
this.loadBets();
}
loadBets() {
const { currentUser } = this.props;
this.setState({ isLoading: true, error: false, balance: currentUser.balance });
axios.get(`http://localhost:4000/mybets`, { params: {
user_id: currentUser.id
}})
.then(res => {
const bets = res.data.bets;
this.setState({ bets, isLoading: false });
})
.catch(error => {
console.log(error);
this.setState({ isLoading: false, error: true });
});
}
setShowStuffToTrue() {
this.setState({showing_transfer_stuff: true});
}
moneyTransferRequest() {
this.setState({transfer_message: 'Transfer initaited: click here to see the transaction'})
}
renderBalance() {
if (this.state.showing_transfer_stuff == true) {
console.log('inside render balance')
const { currentUser } = this.props;
const { isLoading, error, balance } = this.state;
if (error === true) {
return (
<div>
<h4>Error!</h4>
<span className="closeBButton">x</span>
</div>
)
} else if (isLoading === false && balance != undefined) {
return (
<div>
<Row>
<Col xs={12}>
<h4>Transfer balance</h4>
<span className="closeButton">x</span>
</Col>
</Row>
<Form >
<Row>
<Col md={12}>
<FormGroup>
<Label for="amount">Amount</Label>
<Input type="select" name="category" id="category" onChange={this.handleChange}>
<option value="entertainment"> 1.00 </option>
<option value="sports">Edit amount</option>
</Input>
</FormGroup>
</Col>
<Col md={4}>
<FormGroup>
<Label for="category">Stable coin wallet</Label>
<Input type="select" name="category" id="category" onChange={this.handleChange}>
<option value="entertainment">0x123f681646d4a755815f9cb19e1acc8565a0c2ac</option>
<option value="sports">Add wallet</option>
</Input>
</FormGroup>
</Col>
</Row>
<br/>
</Form>
<button onClick={this.moneyTransferRequest}>Transfer Balance</button>
<a href = 'https://etherscan.io/tx/0xcca83cd362e9a5af42ab4dc6a76286c68b2ee696a433908b376cb65fe6d968f9'>{this.state.transfer_message}</a>
</div>
)
}
}
}
renderBets() {
const { bets, isLoading, error } = this.state;
if (error === true) {
return(<div>An error ocurred. Please reload the page.</div>);
} else if (isLoading === true) {
return <MyLoader />;
} else if (bets.length > 0) {
return(
<div>
<ListGroup className="MyBets">
{bets.map((bet) => (
<ListGroupItem key={"bet-" + bet.id + "-" + bet.option}>
<b>{bet.question.title}</b>
<br />
{bet.option === "yes" ?
<div>
<span className="myBetsOption">YES</span>
<span>{bet.yes_odds_numerator} to {bet.yes_odds_denominator}</span>
<span>${bet.amount}</span>
<span><Moment format="MM/DD HH:mm">{bet.question.settle_date}</Moment></span>
<div className="myBetsResult">{bet.settled ? "SETTLED": "NOT SETTLED"}</div>
</div>
:
<div>
<span className="myBetsOption">NO</span>
<span>{bet.yes_odds_denominator} to {bet.yes_odds_numerator}</span>
<span>${bet.amount}</span>
<span><Moment format="MM/DD HH:mm">{bet.question.settle_date}</Moment></span>
<div className="myBetsResult">{bet.settled ? "SETTLED": "NOT SETTLED"}</div>
</div>
}
</ListGroupItem>
))}
</ListGroup>
</div>
);
} else {
return(<div>No bets.</div>);
}
}
renderBalanceButton() {
const { bets, balance, isLoading, error } = this.state;
if (error === true) {
return (
<div>
<h4>Error!</h4>
<span className="closeBButton">x</span>
</div>
)
} else if (isLoading === false && balance != undefined) {
return (
<div className="Balance">
<button onClick={this.setShowStuffToTrue}> Balance: ${balance} </button>
</div>
)
}
}
// TODO If category doesn't exist, redirect to home or 404 page.
render() {
return (
<div className="Questions">
<div className="questionsHeader">
<h2>My Bets</h2>
</div>
{ this.renderBets() }
{ this.renderBalanceButton() }
{ this.renderBalance() }
</div>
);
}
}
const mapStateToProps = store => ({
currentUser: store.clickState.currentUser
});
export default connect(mapStateToProps)(MyBets);