Need help with React await

This is part of a simple blockchain game, (virusContract)
The problem is displayWinner() is being run before “winner” is returned,
causing winner to be undefined at the time of function call.

async handleForm(event) {
//	listen for winner()
	var winner
	this.props.virusContract.once('Winner', function(error, event) {
		winner = event.returnValues.tokenId
		console.log("find winner = " + winner)	
	await this.props.virusContract.methods.infect(this.state.myVirusID, this.state.enemyVirusID).send({ from: this.props.account })
	await this.displayWinner(winner)		

displayWinner(theWinner) {
	console.log("And the winner is... " + theWinner);

How can I get displayWinner to wait for the “winner” to be defined please?

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.