address style grumbles 💄

This commit is contained in:
Jannis R 2016-12-15 13:48:24 +01:00
parent afba259506
commit f59f7c5773
No known key found for this signature in database
GPG Key ID: 0FE83946296A88A5
4 changed files with 49 additions and 29 deletions

View File

@ -31,7 +31,7 @@ export default class BadgeReg {
this.contracts = {}; // by name this.contracts = {}; // by name
} }
nrOfCertifiers () { certifierCount () {
return this._registry.getContract('badgereg') return this._registry.getContract('badgereg')
.then((badgeReg) => { .then((badgeReg) => {
return badgeReg.instance.badgeCount.call({}, []) return badgeReg.instance.badgeCount.call({}, [])
@ -48,9 +48,14 @@ export default class BadgeReg {
return badgeReg.instance.badge.call({}, [ id ]); return badgeReg.instance.badge.call({}, [ id ]);
}) })
.then(([ address, name ]) => { .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 = bytesToHex(name);
name = name === ZERO32 ? null : hex2Ascii(name); name = name === ZERO32
? null
: hex2Ascii(name);
return this.fetchMeta(id) return this.fetchMeta(id)
.then(({ title, icon }) => { .then(({ title, icon }) => {
const data = { address, id, name, title, icon }; const data = { address, id, name, title, icon };

View File

@ -44,8 +44,11 @@ export default class CertificationsMiddleware {
.then((logs) => { .then((logs) => {
logs.forEach((log) => { logs.forEach((log) => {
const certifier = certifiers.find((c) => c.address === log.address); 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; const { id, name, title, icon } = certifier;
if (log.event === 'Revoked') { if (log.event === 'Revoked') {
dispatch(removeCertification(log.params.who.value, id)); dispatch(removeCertification(log.params.who.value, id));
} else { } else {
@ -59,33 +62,42 @@ export default class CertificationsMiddleware {
}; };
return (store) => (next) => (action) => { return (store) => (next) => (action) => {
if (action.type === 'fetchCertifiers') { switch (action.type) {
badgeReg.nrOfCertifiers().then((count) => { case 'fetchCertifiers':
new Array(+count).fill(null).forEach((_, id) => { badgeReg.certifierCount().then((count) => {
badgeReg.fetchCertifier(id) new Array(+count).fill(null).forEach((_, id) => {
.then((cert) => { badgeReg.fetchCertifier(id)
if (!certifiers.some((c) => c.id === cert.id)) { .then((cert) => {
certifiers = certifiers.concat(cert); if (!certifiers.some((c) => c.id === cert.id)) {
fetchConfirmedEvents(store.dispatch); certifiers = certifiers.concat(cert);
} fetchConfirmedEvents(store.dispatch);
}) }
.catch((err) => { })
console.warn(`Could not fetch certifier ${id}:`, err); .catch((err) => {
}); console.warn(`Could not fetch certifier ${id}:`, err);
});
});
}); });
});
} else if (action.type === 'fetchCertifications') {
const { address } = action;
if (!accounts.includes(address)) { break;
accounts = accounts.concat(address); 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); fetchConfirmedEvents(store.dispatch);
}
} else if (action.type === 'setVisibleAccounts') { break;
const { addresses } = action; default:
accounts = uniq(accounts.concat(addresses)); next(action);
fetchConfirmedEvents(store.dispatch); }
} else return next(action);
}; };
} }
} }

View File

@ -24,8 +24,10 @@ export default (state = initialState, action) => {
if (certifications.some((c) => c.id === id)) { if (certifications.some((c) => c.id === id)) {
return state; return state;
} }
const newCertifications = certifications.concat({ id, name, icon, title });
const newCertifications = certifications.concat({
id, name, icon, title
});
return { ...state, [address]: newCertifications }; return { ...state, [address]: newCertifications };
} }

View File

@ -65,6 +65,7 @@ function mapStateToProps (_, initProps) {
return (state) => { return (state) => {
const certifications = state.certifications[account] || []; const certifications = state.certifications[account] || [];
const dappsUrl = state.api.dappsUrl; const dappsUrl = state.api.dappsUrl;
return { certifications, dappsUrl }; return { certifications, dappsUrl };
}; };
} }