implement basic badges/certifications/flair (#3665)
* sms verification: Certifications component
* sms verification: actions & reducers for certifications
* sms verification: put Certifications component into place
* sms verification: show certification icons
* sms verification: show certification titles
* sms verification: default icon for certifications
* sms verificaiton: lint issue 👕, fix testnet detection
The sms verification store got created when `isTestnet` (from the
Redux state) was still `undefined`.
* move certification helpers into middleware file
* connect Certifications to Redux
* don't pass certifications as prop
* move default certification icon into assets
* separate file for BadgeReg.sol
* don't pass certifications as prop
* Fix import name
* make BadgeReg a class
* make certifications middleware a class
* Certifications: pass in certifications of account
This commit is contained in:
committed by
Jaco Greeff
parent
837ff1bc7d
commit
784dcaff7c
@@ -20,17 +20,20 @@ import SettingsMiddleware from '../views/Settings/middleware';
|
||||
import SignerMiddleware from './providers/signerMiddleware';
|
||||
|
||||
import statusMiddleware from '../views/Status/middleware';
|
||||
import CertificationsMiddleware from './providers/certifications/middleware';
|
||||
|
||||
export default function (api) {
|
||||
const errors = new ErrorsMiddleware();
|
||||
const signer = new SignerMiddleware(api);
|
||||
const settings = new SettingsMiddleware();
|
||||
const status = statusMiddleware();
|
||||
const certifications = new CertificationsMiddleware();
|
||||
|
||||
const middleware = [
|
||||
settings.toMiddleware(),
|
||||
signer.toMiddleware(),
|
||||
errors.toMiddleware()
|
||||
errors.toMiddleware(),
|
||||
certifications.toMiddleware()
|
||||
];
|
||||
|
||||
return middleware.concat(status, thunk);
|
||||
|
||||
23
js/src/redux/providers/certifications/actions.js
Normal file
23
js/src/redux/providers/certifications/actions.js
Normal file
@@ -0,0 +1,23 @@
|
||||
// Copyright 2015, 2016 Ethcore (UK) Ltd.
|
||||
// This file is part of Parity.
|
||||
|
||||
// Parity is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
|
||||
// Parity is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
export const fetchCertifications = (address) => ({
|
||||
type: 'fetchCertifications', address
|
||||
});
|
||||
|
||||
export const addCertification = (address, name, title, icon) => ({
|
||||
type: 'addCertification', address, name, title, icon
|
||||
});
|
||||
51
js/src/redux/providers/certifications/middleware.js
Normal file
51
js/src/redux/providers/certifications/middleware.js
Normal file
@@ -0,0 +1,51 @@
|
||||
// Copyright 2015, 2016 Ethcore (UK) Ltd.
|
||||
// This file is part of Parity.
|
||||
|
||||
// Parity is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
|
||||
// Parity is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
import Contracts from '../../../contracts';
|
||||
import { addCertification } from './actions';
|
||||
|
||||
const knownCertifiers = [ 'smsverification' ];
|
||||
|
||||
export default class CertificationsMiddleware {
|
||||
toMiddleware () {
|
||||
return (store) => (next) => (action) => {
|
||||
if (action.type !== 'fetchCertifications') {
|
||||
return next(action);
|
||||
}
|
||||
|
||||
const { address } = action;
|
||||
const badgeReg = Contracts.get().badgeReg;
|
||||
|
||||
knownCertifiers.forEach((name) => {
|
||||
badgeReg.fetchCertifier(name)
|
||||
.then((cert) => {
|
||||
return badgeReg.checkIfCertified(cert.address, address)
|
||||
.then((isCertified) => {
|
||||
if (isCertified) {
|
||||
const { name, title, icon } = cert;
|
||||
store.dispatch(addCertification(address, name, title, icon));
|
||||
}
|
||||
});
|
||||
})
|
||||
.catch((err) => {
|
||||
if (err) {
|
||||
console.error(`Failed to check if ${address} certified by ${name}:`, err);
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
}
|
||||
}
|
||||
33
js/src/redux/providers/certifications/reducer.js
Normal file
33
js/src/redux/providers/certifications/reducer.js
Normal file
@@ -0,0 +1,33 @@
|
||||
// Copyright 2015, 2016 Ethcore (UK) Ltd.
|
||||
// This file is part of Parity.
|
||||
|
||||
// Parity is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
|
||||
// Parity is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
const initialState = {};
|
||||
|
||||
export default (state = initialState, action) => {
|
||||
if (action.type !== 'addCertification') {
|
||||
return state;
|
||||
}
|
||||
|
||||
const { address, name, icon, title } = action;
|
||||
const certifications = state[address] || [];
|
||||
|
||||
if (certifications.some((c) => c.name === name)) {
|
||||
return state;
|
||||
}
|
||||
const newCertifications = certifications.concat({ name, icon, title });
|
||||
|
||||
return { ...state, [address]: newCertifications };
|
||||
};
|
||||
@@ -18,6 +18,7 @@ import { combineReducers } from 'redux';
|
||||
import { routerReducer } from 'react-router-redux';
|
||||
|
||||
import { apiReducer, balancesReducer, blockchainReducer, compilerReducer, imagesReducer, personalReducer, signerReducer, statusReducer as nodeStatusReducer, snackbarReducer } from './providers';
|
||||
import certificationsReducer from './providers/certifications/reducer';
|
||||
|
||||
import errorReducer from '../ui/Errors/reducers';
|
||||
import settingsReducer from '../views/Settings/reducers';
|
||||
@@ -32,6 +33,7 @@ export default function () {
|
||||
settings: settingsReducer,
|
||||
|
||||
balances: balancesReducer,
|
||||
certifications: certificationsReducer,
|
||||
blockchain: blockchainReducer,
|
||||
compiler: compilerReducer,
|
||||
images: imagesReducer,
|
||||
|
||||
Reference in New Issue
Block a user