Commit 3d122005 authored by Zvezdin .'s avatar Zvezdin .

Merge branch 'master' of https://gitlab.com/VikVelev/pun

parents d89058e1 b4e19a45
......@@ -14,14 +14,14 @@ function init(){
var inst;
var address = "0x369a165581ba94afcced493d49dc339e13505f29";
var address = "0xefc770f5275dddfc41794e7fdbcab14834c2af42";
var acc;
//temp fix:
//var Web3 = require("web3");
//var web3 = new Web3(new Web3.providers.HttpProvider("http://localhost:8545"));
//init()
init()
function connectContract(){
var Contract = web3.eth.contract(abi);
......@@ -107,6 +107,7 @@ function getEventPlacedBetByIndex(eventID, betIndex) {
function getEventAvailableBets(eventID) {
return new Promise((accept, reject) => {
console.log(eventID)
inst.getEventAvailableBets.call(eventID, {"from": acc}, function(err, res){
if(!err) {
accept(res);
......
......@@ -31,4 +31,8 @@
.event-item:hover {
background-color: #EEE !important;
}
\ No newline at end of file
}
.active {
background-color: #EEE !important;
}
......@@ -6,7 +6,7 @@ import AdminPage from './component/admin'
class App extends Component {
componentDidMount() {
init(); //eslint-disable-line
//init(); //eslint-disable-line
}
routes = {
......
......@@ -13,69 +13,92 @@ export default class BetPage extends Component {
amount: 0,
}
events = []
betTypes = {
1 : {
name: "Match Results",
},
2: {
name: "Correct Score"
},
3: {
name: "Total Score"
},
4: {
name: "Penalty in Match"
}
}
parseEvent(propArray) {
//bigInt
let ts = propArray[0].toFixed()
//strings
let home = propArray[1]
let away = propArray[2]
let sport = propArray[3]
//bigInt
let rawBetTypes = propArray[4]
rawBetTypes = [ rawBetTypes[0].toFixed(), rawBetTypes[1].toFixed() ]
let betTypes = []
rawBetTypes.forEach((betType) => {
betTypes.push(this.betTypes[betType])
})
//bool
let active = propArray[5]
return {
timestamp: ts,
home: home,
away: away,
sport: sport,
betTypes: betTypes,
active: active,
}
}
constructor(props) {
super(props)
// Don't ask
setTimeout(() => getEventIDs(), 1) //eslint-disable-line
this.getAllEvents()
}
handleClick = (e) => {
this.setState({ chosenBetID: e.currentTarget.dataset.id })
for (let i = 0; i < this.state.events.length; i++) {
if (this.state.events[i].id === e.currentTarget.dataset.id ) {
this.setState({ chosenBetID: this.state.events[i] })
}
}
this.getAvailableBets(e.currentTarget.dataset.id)
}
getAvailableBets(id) {
//Query here
for (let i = 0; i < this.events.length; i++) {
if (this.events[i].id == id) {
this.setState({ chosenBet: this.events[i] })
}
}
console.log(id)
console.log(this.state.chosenBet)
async getAvailableBets() {
let availableBets = await getEventAvailableBetsObjects(this.state.chosenBetID); //eslint-disable-line
console.log(availableBets)
this.setState({ availableBets: availableBets })
}
getAllEvents() {
let events = []
for (let i = 0; i < 5; i++) {
let event = {
id: i,
away: "Red Bull",
home: "Ferrari",
eventTime: new Date().toJSON().slice(0,10).replace(/-/g,'/'),
betTypes: [
{
name: "Match Result",
number: i,
bets: [{
number: i + 1,
description: "2-1",
participant: "Ferrari",
odds: i*Math.PI
}, {
number: i + 2,
description: "2-0",
participant: "Ferrari",
odds: i*Math.PI*2
}]
}
]
}
events.push(event);
}
this.events = events;
async getAllEvents() {
let rawEvents = await getEvents() //eslint-disable-line
rawEvents.forEach((event) => {
this.state.events.push(this.parseEvent(event))
})
this.setState({ events: this.state.events })
}
betItem () {
return (
<div>BetItem</div>
<div>
Your bet
</div>
)
}
......@@ -89,7 +112,10 @@ export default class BetPage extends Component {
eventItem(data, i) {
return(
<Segment key={i} data-id={data.id} className="event-item" onClick={this.handleClick}>
<Segment key={i}
data-id={data.id}
className={"event-item"}
onClick={this.handleClick}>
{data.away} vs {data.home}
</Segment>
)
......@@ -97,29 +123,35 @@ export default class BetPage extends Component {
renderAllEvents() {
return (
this.events.map((object, i) => this.eventItem(object, i))
this.state.events.map((object, i) => this.eventItem(object, i))
)
}
renderAvailableBets() {
if (this.state.chosenBet.length !== 0) {
if (this.state.chosenBetID !== "") {
return (
<div className="available-bet">
{this.state.chosenBet.away} vs {this.state.chosenBet.home}
Match Scores
Set Scores
this vs that
{/* {this.availableBets[0]} vs {this.state.availableBets[0]} */}
</div>
)
}
}
renderChosenBet() {
return (
<div className="chosen-bets">
<Segment>
{this.state.chosenBet.away} vs {this.state.chosenBet.home}
odds 1.29
</Segment>
</div>
)
}
render() {
console.log(this.state.chosenBet)
console.log(this.state.chosenBetID)
return(
<div className="bet-page">
......@@ -129,22 +161,22 @@ export default class BetPage extends Component {
<Menu.Item>
<Image size='mini' className="logo" src='/img/logo.png' />
</Menu.Item>
<Menu.Item header>Personal Unified Network (P.U.N.)</Menu.Item>
<Menu.Item header>Personal Unified betting Network (P.U.N.)</Menu.Item>
</Container>
</Menu>
{/* Nav bar */}
<div className="content">
<Segment className="rear all-event-types">
<Header attached> All Bets/Sports </Header>
{this.events.lenght !== 0 ? this.renderAllEvents() : "Nothing here now"}
{this.state.events.length !== 0 ? this.renderAllEvents() : "Nothing here now"}
</Segment>
<Segment className="front all-available-bets">
<Header attached className="titles">'Selected Sport' All Bets </Header>
{this.renderAvailableBets()}
{this.state.chosenBetID !== "" ? this.renderAvailableBets() : "No bet chosen"}
</Segment>
<Segment className="rear bets-to-submit">
<Header attached className="titles"> Current bets </Header>
{this.renderChosenBet()}
{this.state.chosenBet.length !== 0 ? this.renderChosenBet() : "No bet chosen"}
</Segment>
</div>
......
......@@ -5,5 +5,6 @@ import App from './App';
import registerServiceWorker from './registerServiceWorker';
import 'semantic-ui-css/semantic.min.css';
ReactDOM.render(<App />, document.getElementById('root'));
//dont ask
setTimeout(() => ReactDOM.render(<App />, document.getElementById('root')), 1);
registerServiceWorker();
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment