From 2d287c43f3e2ea916df93c94c2b72effa6a1e96a Mon Sep 17 00:00:00 2001 From: Anthony Laibe Date: Wed, 10 Oct 2018 09:28:31 +0100 Subject: [PATCH] Ignore badly formatted message --- embark-ui/src/components/ContractLogger.js | 9 +++++++-- embark-ui/src/sagas/index.js | 7 ++++++- lib/modules/blockchain_connector/index.js | 11 +++++++---- templates/demo/contracts/simple_storage.sol | 2 -- 4 files changed, 20 insertions(+), 9 deletions(-) diff --git a/embark-ui/src/components/ContractLogger.js b/embark-ui/src/components/ContractLogger.js index 8de94692..9f9a5d83 100644 --- a/embark-ui/src/components/ContractLogger.js +++ b/embark-ui/src/components/ContractLogger.js @@ -8,6 +8,11 @@ import { } from "tabler-react"; const TX_STATES = {Success: '0x1', Fail: '0x0', Any: ''}; +const EVENT = 'event'; +const FUNCTION = 'function'; +const CONSTRUCTOR = 'constructor'; +const PURE = 'pure'; +const VIEW = 'view'; class ContractLogger extends React.Component { constructor(props) { @@ -21,7 +26,7 @@ class ContractLogger extends React.Component { } return this.props.contract.abiDefinition.filter(method => ( - method.name !== 'constructor' && method.mutability !== 'view' && method.mutability !== 'pure' && method.constant !== true && method.type === 'function' + method.name !== CONSTRUCTOR && method.mutability !== VIEW && method.mutability !== PURE && method.constant !== true && method.type === FUNCTION )); } @@ -29,7 +34,7 @@ class ContractLogger extends React.Component { if (!this.props.contract.abiDefinition) { return []; } - return this.props.contract.abiDefinition.filter(method => method.type === 'event'); + return this.props.contract.abiDefinition.filter(method => method.type === EVENT); } updateState(key, value) { diff --git a/embark-ui/src/sagas/index.js b/embark-ui/src/sagas/index.js index 2412953d..1da39075 100644 --- a/embark-ui/src/sagas/index.js +++ b/embark-ui/src/sagas/index.js @@ -215,7 +215,12 @@ export function *watchLogout() { function createChannel(socket) { return eventChannel(emit => { socket.onmessage = ((message) => { - emit(JSON.parse(message.data)); + try { + emit(JSON.parse(message.data)); + } catch(_error) { + // Ignore the message if not formatted correctly + // For example message like outputDone (for live reload) + } }); return () => { socket.close(); diff --git a/lib/modules/blockchain_connector/index.js b/lib/modules/blockchain_connector/index.js index a3af97cb..eca3d4f2 100644 --- a/lib/modules/blockchain_connector/index.js +++ b/lib/modules/blockchain_connector/index.js @@ -374,8 +374,8 @@ class BlockchainConnector { plugin.registerAPICall( 'ws', '/embark-api/blockchain/contracts/event', - (ws, _req) => { - this.events.on('blockchain:contracts:event', function(data) { + (ws) => { + this.events.on('blockchain:contracts:event', (data) => { ws.send(JSON.stringify(data), () => {}); }); } @@ -640,9 +640,12 @@ class BlockchainConnector { this.contractsSubscriptions.push(eventEmitter); eventEmitter.on('data', (data) => { const dataWithName = Object.assign(data, {name: contractObject.className}); - this.contractsEvents.push(dataWithName) - this.events.emit('blockchain:contract:event', dataWithName); + this.contractsEvents.push(dataWithName); + this.events.emit('blockchain:contracts:event', dataWithName); }); + eventEmitter.on('error', () => { + console.log('error') + }) }); callback(); }); diff --git a/templates/demo/contracts/simple_storage.sol b/templates/demo/contracts/simple_storage.sol index 7810f582..d2ab0073 100644 --- a/templates/demo/contracts/simple_storage.sol +++ b/templates/demo/contracts/simple_storage.sol @@ -1,7 +1,6 @@ pragma solidity ^0.4.25; contract SimpleStorage { - event SetCalled(uint x); uint public storedData; constructor(uint initialValue) public { @@ -10,7 +9,6 @@ contract SimpleStorage { function set(uint x) public { storedData = x; - emit SetCalled(x); } function get() public view returns (uint retVal) {