From 6532f696c07ab79422724f28781185a589df9513 Mon Sep 17 00:00:00 2001 From: jacogr Date: Sat, 22 Oct 2016 14:36:08 +0200 Subject: [PATCH] Pass value & type through from event log params --- js/src/api/contract/contract.js | 4 +++- js/src/dapps/basiccoin/Deploy/Events/events.js | 4 ++++ js/src/dapps/basiccoin/Transfer/Events/events.js | 5 ++++- js/src/dapps/gavcoin/Events/events.js | 5 ++++- js/src/dapps/registry/Events/events.js | 8 ++++---- js/src/dapps/signaturereg/services.js | 5 ++++- js/src/dapps/tokenreg/Status/actions.js | 16 ++++++++-------- js/src/views/Contract/Events/Event/event.js | 16 ++++++++-------- 8 files changed, 39 insertions(+), 24 deletions(-) diff --git a/js/src/api/contract/contract.js b/js/src/api/contract/contract.js index 40caa764334..cef75eda734 100644 --- a/js/src/api/contract/contract.js +++ b/js/src/api/contract/contract.js @@ -150,7 +150,9 @@ export default class Contract { log.event = event.name; decoded.params.forEach((param) => { - log.params[param.name] = param.token.value; + const { type, value } = param.token; + + log.params[param.name] = { type, value }; }); return log; diff --git a/js/src/dapps/basiccoin/Deploy/Events/events.js b/js/src/dapps/basiccoin/Deploy/Events/events.js index a21672a8efc..4b51afb59b6 100644 --- a/js/src/dapps/basiccoin/Deploy/Events/events.js +++ b/js/src/dapps/basiccoin/Deploy/Events/events.js @@ -110,6 +110,10 @@ export default class Events extends Component { logToEvent = (log) => { log.key = api.util.sha3(JSON.stringify(log)); + log.params = Object.keys(log.params).reduce((params, name) => { + params[name] = log.params[name].value; + return params; + }, {}); return log; } diff --git a/js/src/dapps/basiccoin/Transfer/Events/events.js b/js/src/dapps/basiccoin/Transfer/Events/events.js index dcead03bb78..101c77f73a3 100644 --- a/js/src/dapps/basiccoin/Transfer/Events/events.js +++ b/js/src/dapps/basiccoin/Transfer/Events/events.js @@ -114,6 +114,10 @@ export default class Events extends Component { logToEvent = (log) => { log.key = api.util.sha3(JSON.stringify(log)); + log.params = Object.keys(log.params).reduce((params, name) => { + params[name] = log.params[name].value; + return params; + }, {}); return log; } @@ -139,7 +143,6 @@ export default class Events extends Component { .concat(pendingEvents) .filter((log) => !minedNew.find((event) => event.transactionHash === log.transactionHash)); const events = [].concat(pendingNew).concat(minedNew); - console.log('*** events', events.map((event) => event.address)); this.setState({ loading: false, events, minedEvents: minedNew, pendingEvents: pendingNew }); } } diff --git a/js/src/dapps/gavcoin/Events/events.js b/js/src/dapps/gavcoin/Events/events.js index cb287b3a7f3..ba71d65413c 100644 --- a/js/src/dapps/gavcoin/Events/events.js +++ b/js/src/dapps/gavcoin/Events/events.js @@ -106,7 +106,10 @@ export default class Events extends Component { logIndex, transactionHash, transactionIndex, - params, + params: Object.keys(params).reduce((data, name) => { + data[name] = params[name].value; + return data; + }, {}), key }; }; diff --git a/js/src/dapps/registry/Events/events.js b/js/src/dapps/registry/Events/events.js index ffb1fc9190a..10280ae5232 100644 --- a/js/src/dapps/registry/Events/events.js +++ b/js/src/dapps/registry/Events/events.js @@ -48,9 +48,9 @@ const renderEvent = (classNames, verb) => (e, accounts, contacts) => { return ( - { renderAddress(e.parameters.owner, accounts, contacts) } + { renderAddress(e.parameters.owner.value, accounts, contacts) } { verb } - { renderHash(bytesToHex(e.parameters.name)) } + { renderHash(bytesToHex(e.parameters.name.value)) } { renderStatus(e.timestamp, e.state === 'pending') } ); @@ -64,10 +64,10 @@ const renderDataChanged = (e, accounts, contacts) => { return ( - { renderAddress(e.parameters.owner, accounts, contacts) } + { renderAddress(e.parameters.owner.value, accounts, contacts) } updated - key { new Buffer(e.parameters.plainKey).toString('utf8') } of { renderHash(bytesToHex(e.parameters.name)) } + key { new Buffer(e.parameters.plainKey.value).toString('utf8') } of { renderHash(bytesToHex(e.parameters.name.value)) } { renderStatus(e.timestamp, e.state === 'pending') } diff --git a/js/src/dapps/signaturereg/services.js b/js/src/dapps/signaturereg/services.js index 3963d394c7f..0b124589791 100644 --- a/js/src/dapps/signaturereg/services.js +++ b/js/src/dapps/signaturereg/services.js @@ -30,7 +30,10 @@ const logToEvent = (log) => { logIndex, transactionHash, transactionIndex, - params, + params: Object.keys(params).reduce((data, name) => { + data[name] = params[name].value; + return data; + }, {}), key }; }; diff --git a/js/src/dapps/tokenreg/Status/actions.js b/js/src/dapps/tokenreg/Status/actions.js index a479179b223..d02c8e77576 100644 --- a/js/src/dapps/tokenreg/Status/actions.js +++ b/js/src/dapps/tokenreg/Status/actions.js @@ -148,27 +148,27 @@ export const subscribeEvents = () => (dispatch, getState) => { return dispatch(setTokenData(params.id.toNumber(), { tla: '...', base: -1, - address: params.addr, - name: params.name, + address: params.addr.value, + name: params.name.value, isPending: true })); } if (event === 'Registered' && type === 'mined') { - return dispatch(loadToken(params.id.toNumber())); + return dispatch(loadToken(params.id.value.toNumber())); } if (event === 'Unregistered' && type === 'pending') { - return dispatch(setTokenPending(params.id.toNumber(), true)); + return dispatch(setTokenPending(params.id.value.toNumber(), true)); } if (event === 'Unregistered' && type === 'mined') { - return dispatch(deleteToken(params.id.toNumber())); + return dispatch(deleteToken(params.id.value.toNumber())); } if (event === 'MetaChanged' && type === 'pending') { return dispatch(setTokenData( - params.id.toNumber(), + params.id.value.toNumber(), { metaPending: true, metaMined: false } )); } @@ -176,13 +176,13 @@ export const subscribeEvents = () => (dispatch, getState) => { if (event === 'MetaChanged' && type === 'mined') { setTimeout(() => { dispatch(setTokenData( - params.id.toNumber(), + params.id.value.toNumber(), { metaPending: false, metaMined: false } )); }, 5000); return dispatch(setTokenData( - params.id.toNumber(), + params.id.value.toNumber(), { metaPending: false, metaMined: true } )); } diff --git a/js/src/views/Contract/Events/Event/event.js b/js/src/views/Contract/Events/Event/event.js index cee243bac8e..17d06cb37f0 100644 --- a/js/src/views/Contract/Events/Event/event.js +++ b/js/src/views/Contract/Events/Event/event.js @@ -52,10 +52,10 @@ class Event extends Component { const keys = Object.keys(event.params).map((key, index) => { return
{ key }
; }); - const values = Object.values(event.params).map((value, index) => { + const values = Object.values(event.params).map((param, index) => { return (
- { this.renderValue(value) } + { this.renderParam(param) }
); }); @@ -82,16 +82,16 @@ class Event extends Component { ); } - renderValue (value) { + renderParam (param) { const { api } = this.context; - if (api.util.isInstanceOf(value, BigNumber)) { - return value.toFormat(0); - } else if (api.util.isArray(value)) { - return api.util.bytesToHex(value); + if (api.util.isInstanceOf(param.value, BigNumber)) { + return param.value.toFormat(0); + } else if (api.util.isArray(param.value)) { + return api.util.bytesToHex(param.value); } - return value.toString(); + return param.value.toString(); } formatBlockTimestamp (block) {