add tilestate update event handler
This commit is contained in:
parent
232cc5fbc7
commit
686edf6ad8
|
@ -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;
|
||||
|
|
13
app/dapp.js
13
app/dapp.js
|
@ -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() {
|
||||
|
|
Loading…
Reference in New Issue