Last active
February 10, 2018 15:50
-
-
Save cipherzzz/4b4d176825ea06accdb0a17cbff989b1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
... | |
class App extends Component { | |
constructor(props) { | |
super(props); | |
this.state = { | |
bet: {}, | |
web3: null, | |
}; | |
} | |
componentWillMount() { | |
getWeb3 | |
.then(results => { | |
this.setState({ | |
web3: results.web3, | |
}); | |
jediBet.setProvider(this.state.web3.currentProvider); | |
this.getBet(); | |
}) | |
.catch((error) => { | |
console.log("Error finding web3. " + error); | |
}); | |
} | |
... | |
placeBet(guess, amount) { | |
jediBet | |
.deployed() | |
.then(instance => { | |
return instance.createBet(guess, { from: this.getAccount(), value: this.state.web3.toWei(amount, "ether") }); | |
}) | |
.then(result => { | |
this.getBet(); | |
}) | |
.catch((error => console.log("Error:" + JSON.stringify(error)))); | |
} | |
takeBet(guess) { | |
jediBet | |
.deployed() | |
.then(instance => { | |
return instance.takeBet(guess, { from: this.getAccount(), value: this.state.web3.toWei(this.state.bet.betAmount, "ether") }); | |
}) | |
.then(result => { | |
this.getBet(); | |
}) | |
.catch((error => console.log("Error:" + JSON.stringify(error)))); | |
} | |
payoutBet() { | |
jediBet | |
.deployed() | |
.then(instance => { | |
return instance.payout({ from: this.getAccount() }); | |
}) | |
.then(result => { | |
this.getBet(); | |
}) | |
.catch((error => console.log("Error:" + JSON.stringify(error)))); | |
} | |
... | |
render() { | |
return ( | |
<div className="App" > | |
... | |
<BetComponent | |
account={this.getAccount()} | |
bet={this.state.bet} | |
placeBet={(guess, amount) => { this.placeBet(guess, amount) }} | |
takeBet={(guess) => { this.takeBet(guess) }} | |
payoutBet={() => { this.payoutBet() }} | |
/> | |
... | |
</div> | |
); | |
} | |
} | |
export default App; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment