add tilestate update event handler

This commit is contained in:
Barry Gitarts 2018-07-26 16:26:36 -04:00
parent 232cc5fbc7
commit 686edf6ad8
2 changed files with 8 additions and 11 deletions

View File

@ -6,7 +6,7 @@ import {
import Web3 from 'web3'
import EmbarkJS from 'Embark/EmbarkJS';
export const createContract = async () => {
export const createContract = async (tileStateUpdateHandler) => {
const privateKey = CryptoUtils.generatePrivateKey()
const publicKey = CryptoUtils.publicKeyFromPrivateKey(privateKey)
@ -28,9 +28,7 @@ export const createContract = async () => {
contract.events.OnTileMapStateUpdate({}, (err, event) => {
if (err) return;
if (this.onEvent) {
this.onEvent(event)
}
tileStateUpdateHandler(event);
})
return contract;

View File

@ -33,16 +33,15 @@ class App extends React.Component {
}
async createContract() {
this.contractClient = await createContract();
this.createContractEventListener();
const { tileStateUpdateHandler } = this;
this.contractClient = await createContract(tileStateUpdateHandler);
this.requestUpdateTilesOnCanvas();
}
createContractEventListener = async () => {
// THIS CURRENTLY DOES NOT WORK DUE POSSIBLE LOOM PROVIDER BUG
this.contractClient.onEvent = tileData => {
console.log('tiledata', tileData)
}
tileStateUpdateHandler = tileData => {
const { returnValues: { state } } = tileData;
console.log('tile state update event received');
this.setState({ canvasState: state });
}
async requestUpdateTilesOnCanvas() {