remove certification on Revoke
This commit is contained in:
parent
fd88421e88
commit
6d20592f76
@ -26,6 +26,6 @@ export const addCertification = (address, id, name, title, icon) => ({
|
|||||||
type: 'addCertification', address, id, name, title, icon
|
type: 'addCertification', address, id, name, title, icon
|
||||||
});
|
});
|
||||||
|
|
||||||
export const removeCertification = (address, id, name, title, icon) => ({
|
export const removeCertification = (address, id) => ({
|
||||||
type: 'removeCertification', address, id, name, title, icon
|
type: 'removeCertification', address, id
|
||||||
});
|
});
|
||||||
|
@ -19,7 +19,7 @@ import { uniq } from 'lodash';
|
|||||||
import ABI from '~/contracts/abi/certifier.json';
|
import ABI from '~/contracts/abi/certifier.json';
|
||||||
import Contract from '~/api/contract';
|
import Contract from '~/api/contract';
|
||||||
import Contracts from '~/contracts';
|
import Contracts from '~/contracts';
|
||||||
import { addCertification } from './actions';
|
import { addCertification, removeCertification } from './actions';
|
||||||
|
|
||||||
export default class CertificationsMiddleware {
|
export default class CertificationsMiddleware {
|
||||||
toMiddleware () {
|
toMiddleware () {
|
||||||
@ -27,6 +27,7 @@ export default class CertificationsMiddleware {
|
|||||||
const badgeReg = Contracts.get().badgeReg;
|
const badgeReg = Contracts.get().badgeReg;
|
||||||
const contract = new Contract(api, ABI);
|
const contract = new Contract(api, ABI);
|
||||||
const Confirmed = contract.events.find((e) => e.name === 'Confirmed');
|
const Confirmed = contract.events.find((e) => e.name === 'Confirmed');
|
||||||
|
const Revoked = contract.events.find((e) => e.name === 'Revoked');
|
||||||
|
|
||||||
let certifiers = [];
|
let certifiers = [];
|
||||||
let accounts = []; // these are addresses
|
let accounts = []; // these are addresses
|
||||||
@ -37,7 +38,7 @@ export default class CertificationsMiddleware {
|
|||||||
fromBlock: 0,
|
fromBlock: 0,
|
||||||
toBlock: 'latest',
|
toBlock: 'latest',
|
||||||
address: certifiers.map((c) => c.address),
|
address: certifiers.map((c) => c.address),
|
||||||
topics: [ Confirmed.signature, accounts ]
|
topics: [ [ Confirmed.signature, Revoked.signature ], accounts ]
|
||||||
})
|
})
|
||||||
.then((logs) => contract.parseEventLogs(logs))
|
.then((logs) => contract.parseEventLogs(logs))
|
||||||
.then((logs) => {
|
.then((logs) => {
|
||||||
@ -45,7 +46,11 @@ export default class CertificationsMiddleware {
|
|||||||
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') {
|
||||||
|
dispatch(removeCertification(log.params.who.value, id));
|
||||||
|
} else {
|
||||||
dispatch(addCertification(log.params.who.value, id, name, title, icon));
|
dispatch(addCertification(log.params.who.value, id, name, title, icon));
|
||||||
|
}
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
|
@ -17,10 +17,7 @@
|
|||||||
const initialState = {};
|
const initialState = {};
|
||||||
|
|
||||||
export default (state = initialState, action) => {
|
export default (state = initialState, action) => {
|
||||||
if (action.type !== 'addCertification') {
|
if (action.type === 'addCertification') {
|
||||||
return state;
|
|
||||||
}
|
|
||||||
|
|
||||||
const { address, id, name, icon, title } = action;
|
const { address, id, name, icon, title } = action;
|
||||||
const certifications = state[address] || [];
|
const certifications = state[address] || [];
|
||||||
|
|
||||||
@ -30,4 +27,15 @@ export default (state = initialState, action) => {
|
|||||||
const newCertifications = certifications.concat({ id, name, icon, title });
|
const newCertifications = certifications.concat({ id, name, icon, title });
|
||||||
|
|
||||||
return { ...state, [address]: newCertifications };
|
return { ...state, [address]: newCertifications };
|
||||||
|
}
|
||||||
|
|
||||||
|
if (action.type === 'removeCertification') {
|
||||||
|
const { address, id } = action;
|
||||||
|
const certifications = state[address] || [];
|
||||||
|
|
||||||
|
const newCertifications = certifications.filter((c) => c.id !== id);
|
||||||
|
return { ...state, [address]: newCertifications };
|
||||||
|
}
|
||||||
|
|
||||||
|
return state;
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user