From f59f7c57730c1280f499e4c6dbe46a4c3d5e221c Mon Sep 17 00:00:00 2001 From: Jannis R Date: Thu, 15 Dec 2016 13:48:24 +0100 Subject: [PATCH] address style grumbles :lipstick: --- js/src/contracts/badgereg.js | 11 +++- .../providers/certifications/middleware.js | 62 +++++++++++-------- .../redux/providers/certifications/reducer.js | 4 +- js/src/ui/Certifications/certifications.js | 1 + 4 files changed, 49 insertions(+), 29 deletions(-) diff --git a/js/src/contracts/badgereg.js b/js/src/contracts/badgereg.js index 10943c43e..8075f456e 100644 --- a/js/src/contracts/badgereg.js +++ b/js/src/contracts/badgereg.js @@ -31,7 +31,7 @@ export default class BadgeReg { this.contracts = {}; // by name } - nrOfCertifiers () { + certifierCount () { return this._registry.getContract('badgereg') .then((badgeReg) => { return badgeReg.instance.badgeCount.call({}, []) @@ -48,9 +48,14 @@ export default class BadgeReg { return badgeReg.instance.badge.call({}, [ id ]); }) .then(([ address, name ]) => { - if (address === ZERO20) throw new Error(`Certifier ${id} does not exist.`); + if (address === ZERO20) { + throw new Error(`Certifier ${id} does not exist.`); + } + name = bytesToHex(name); - name = name === ZERO32 ? null : hex2Ascii(name); + name = name === ZERO32 + ? null + : hex2Ascii(name); return this.fetchMeta(id) .then(({ title, icon }) => { const data = { address, id, name, title, icon }; diff --git a/js/src/redux/providers/certifications/middleware.js b/js/src/redux/providers/certifications/middleware.js index 6cbfffa72..6e4b898d0 100644 --- a/js/src/redux/providers/certifications/middleware.js +++ b/js/src/redux/providers/certifications/middleware.js @@ -44,8 +44,11 @@ export default class CertificationsMiddleware { .then((logs) => { logs.forEach((log) => { const certifier = certifiers.find((c) => c.address === log.address); - if (!certifier) throw new Error(`Could not find certifier at ${log.address}.`); + if (!certifier) { + throw new Error(`Could not find certifier at ${log.address}.`); + } const { id, name, title, icon } = certifier; + if (log.event === 'Revoked') { dispatch(removeCertification(log.params.who.value, id)); } else { @@ -59,33 +62,42 @@ export default class CertificationsMiddleware { }; return (store) => (next) => (action) => { - if (action.type === 'fetchCertifiers') { - badgeReg.nrOfCertifiers().then((count) => { - new Array(+count).fill(null).forEach((_, id) => { - badgeReg.fetchCertifier(id) - .then((cert) => { - if (!certifiers.some((c) => c.id === cert.id)) { - certifiers = certifiers.concat(cert); - fetchConfirmedEvents(store.dispatch); - } - }) - .catch((err) => { - console.warn(`Could not fetch certifier ${id}:`, err); - }); + switch (action.type) { + case 'fetchCertifiers': + badgeReg.certifierCount().then((count) => { + new Array(+count).fill(null).forEach((_, id) => { + badgeReg.fetchCertifier(id) + .then((cert) => { + if (!certifiers.some((c) => c.id === cert.id)) { + certifiers = certifiers.concat(cert); + fetchConfirmedEvents(store.dispatch); + } + }) + .catch((err) => { + console.warn(`Could not fetch certifier ${id}:`, err); + }); + }); }); - }); - } else if (action.type === 'fetchCertifications') { - const { address } = action; - if (!accounts.includes(address)) { - accounts = accounts.concat(address); + break; + case 'fetchCertifications': + const { address } = action; + + if (!accounts.includes(address)) { + accounts = accounts.concat(address); + fetchConfirmedEvents(store.dispatch); + } + + break; + case 'setVisibleAccounts': + const { addresses } = action; + accounts = uniq(accounts.concat(addresses)); fetchConfirmedEvents(store.dispatch); - } - } else if (action.type === 'setVisibleAccounts') { - const { addresses } = action; - accounts = uniq(accounts.concat(addresses)); - fetchConfirmedEvents(store.dispatch); - } else return next(action); + + break; + default: + next(action); + } }; } } diff --git a/js/src/redux/providers/certifications/reducer.js b/js/src/redux/providers/certifications/reducer.js index d96ed1d65..bb2681cf6 100644 --- a/js/src/redux/providers/certifications/reducer.js +++ b/js/src/redux/providers/certifications/reducer.js @@ -24,8 +24,10 @@ export default (state = initialState, action) => { if (certifications.some((c) => c.id === id)) { return state; } - const newCertifications = certifications.concat({ id, name, icon, title }); + const newCertifications = certifications.concat({ + id, name, icon, title + }); return { ...state, [address]: newCertifications }; } diff --git a/js/src/ui/Certifications/certifications.js b/js/src/ui/Certifications/certifications.js index 6c9b2fe2c..bafd06f35 100644 --- a/js/src/ui/Certifications/certifications.js +++ b/js/src/ui/Certifications/certifications.js @@ -65,6 +65,7 @@ function mapStateToProps (_, initProps) { return (state) => { const certifications = state.certifications[account] || []; const dappsUrl = state.api.dappsUrl; + return { certifications, dappsUrl }; }; }