store id with certifiers

This commit is contained in:
Jannis R 2016-12-09 13:35:10 +01:00
parent 3dc943e854
commit fd88421e88
No known key found for this signature in database
GPG Key ID: 0FE83946296A88A5
4 changed files with 13 additions and 9 deletions

View File

@ -53,7 +53,7 @@ export default class BadgeReg {
name = name === ZERO32 ? null : hex2Ascii(name);
return this.fetchMeta(id)
.then(({ title, icon }) => {
const data = { address, name, title, icon };
const data = { address, id, name, title, icon };
this.certifiers[id] = data;
return data;
});

View File

@ -22,6 +22,10 @@ export const fetchCertifications = (address) => ({
type: 'fetchCertifications', address
});
export const addCertification = (address, name, title, icon) => ({
type: 'addCertification', address, name, title, icon
export const addCertification = (address, id, name, title, icon) => ({
type: 'addCertification', address, id, name, title, icon
});
export const removeCertification = (address, id, name, title, icon) => ({
type: 'removeCertification', address, id, name, title, icon
});

View File

@ -44,8 +44,8 @@ export default class CertificationsMiddleware {
logs.forEach((log) => {
const certifier = certifiers.find((c) => c.address === log.address);
if (!certifier) throw new Error(`Could not find certifier at ${log.address}.`);
const { name, title, icon } = certifier;
dispatch(addCertification(log.params.who.value, name, title, icon));
const { id, name, title, icon } = certifier;
dispatch(addCertification(log.params.who.value, id, name, title, icon));
});
})
.catch((err) => {
@ -59,7 +59,7 @@ export default class CertificationsMiddleware {
new Array(+count).fill(null).forEach((_, id) => {
badgeReg.fetchCertifier(id)
.then((cert) => {
if (!certifiers.some((c) => c.address === cert.address)) {
if (!certifiers.some((c) => c.id === cert.id)) {
certifiers = certifiers.concat(cert);
fetchConfirmedEvents(store.dispatch);
}

View File

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