Last active
February 10, 2018 15:46
-
-
Save cipherzzz/b3e216fd822f5c107f9379a9460f2a6e 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
... | |
constructor(props) { | |
super(props); | |
this.state = this.generateStateFromProps(props); | |
} | |
componentWillReceiveProps(newProps) { | |
if (newProps.bet !== this.props.bet) { | |
this.setState(this.generateStateFromProps(newProps)); | |
} | |
} | |
generateStateFromProps(props) { | |
return { | |
taker: { guess: props.bet.takerGuess, addr: this.getCurrentAccountForStatus(props.bet.gameStatus, props.bet.taker, false), status: props.bet.takerStatus }, | |
originator: { guess: props.bet.originatorGuess, addr: this.getCurrentAccountForStatus(props.bet.gameStatus, props.bet.originator, true), status: props.bet.originatorStatus }, | |
amount: props.bet.betAmount, | |
gameStatus: props.bet.gameStatus, | |
actualNumber: props.bet.actualNumber, | |
pot: props.bet.pot | |
}; | |
} | |
... | |
render() { | |
let view = this.renderError(); | |
switch (this.state.gameStatus) { | |
case STATUS_NOT_STARTED: | |
view = this.renderPlaceBet(); | |
break; | |
case STATUS_STARTED: | |
view = this.renderTakeBet(); | |
break; | |
case STATUS_COMPLETE: | |
view = this.renderBetOutcome(); | |
break; | |
case STATUS_ERROR: | |
view = this.renderError(); | |
break; | |
default: | |
view = this.renderError() | |
break; | |
} | |
return view; | |
} | |
... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment