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
}
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 };

View File

@ -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);
}
};
}
}

View File

@ -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 };
}

View File

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