Skip to content
This repository has been archived by the owner on Nov 6, 2020. It is now read-only.

get certifications from BadgeReg, show them in accounts overview #3768

Merged
merged 16 commits into from
Dec 15, 2016

Conversation

derhuerst
Copy link
Contributor

@derhuerst derhuerst commented Dec 9, 2016

The PR makes the certifications/badges show up in the accounts overview and in the address book.

Triggered by the action fetchCertifiers, it uses BadgeReg.sol to fetch the addresses & metadata of all certifiers (contracts issuing certifications/badges). It then uses a filter to check for Confirmed events.

badges

Still to do:

  • Listen for Revoked and remove the certification.
  • Consider renaming "certifications" to "badges". I kept it compatible with the rest of the code for now.

@derhuerst derhuerst added A3-inprogress ⏳ Pull request is in progress. No review needed at this stage. M7-ui labels Dec 9, 2016
@derhuerst derhuerst changed the title use BadgeReg to get list of certifications, display them in accounts overview get certifications from BadgeReg, show them in accounts overview Dec 9, 2016
@coveralls
Copy link

Coverage Status

Changes Unknown when pulling d67a938 on jr-use-badge-reg into ** on master**.

@derhuerst
Copy link
Contributor Author

The tests run locally for me. CI seems to have issues.

@derhuerst derhuerst added A0-pleasereview 🤓 Pull request needs code review. and removed A3-inprogress ⏳ Pull request is in progress. No review needed at this stage. labels Dec 14, 2016
@coveralls
Copy link

Coverage Status

Changes Unknown when pulling 240bab2 on jr-use-badge-reg into ** on master**.

fetchCertifier (name) {
if (this.certifiers[name]) {
return Promise.resolve(this.certifiers[name]);
nrOfCertifiers () {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nr -> number

(or just certifierCount)

return badgeReg.instance.badge.call({}, [ id ]);
})
.then(([ address, name ]) => {
if (address === ZERO20) throw new Error(`Certifier ${id} does not exist.`);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Considder putting this across 2 lines with a blank space between the blocks -

  1. Readability, not gaining anything (I know beauty is in the eye of the beerholder)
  2. When we add the tests and have coverage information, the line will show up as covered even when just the condition is evaluated - when it is in a proper block, the info will show that the error is actually tested for or now. (Goes for everything, even ?:).

.then(([ address, name ]) => {
if (address === ZERO20) throw new Error(`Certifier ${id} does not exist.`);
name = bytesToHex(name);
name = name === ZERO32 ? null : hex2Ascii(name);
Copy link
Contributor

@jacogr jacogr Dec 15, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same split comment as above, would make life easier going forward, hence -

// not crazy about doing this, we do it in a couple of places 
// (I have started testing again BigNum(val).eq(0))
name = name === ZERO32 
  ? null
  : hex2Ascii(name);

.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}.`);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same single-line comment as above for the same reasons.

const certifier = certifiers.find((c) => c.address === log.address);
if (!certifier) throw new Error(`Could not find certifier at ${log.address}.`);
const { id, name, title, icon } = certifier;
if (log.event === 'Revoked') {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Really picky, but would prefer a line before this block, just indicates a break between assigning and doing. (Not a crisis, just aids readability once again)

if (isCertified) {
const { name, title, icon } = cert;
store.dispatch(addCertification(address, name, title, icon));
if (action.type === 'fetchCertifiers') {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider using a switch statement for action.type

if (certifications.some((c) => c.id === id)) {
return state;
}
const newCertifications = certifications.concat({ id, name, icon, title });
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

linebreak before would be good, the rest of the callback is actually nice and readable.

@@ -17,17 +17,25 @@
const initialState = {};

export default (state = initialState, action) => {
if (action.type !== 'addCertification') {
return state;
if (action.type === 'addCertification') {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

switch statement would be good here as well, since we are only checking the type, default is the state return.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changing it to a switch statement in this case means that the variable declarations aren't as local anymore. The linter will complain. Moving them up is ugly because we're assigning stuff we may not need.

@@ -73,15 +64,12 @@ function mapStateToProps (_, initProps) {

return (state) => {
const certifications = state.certifications[account] || [];
return { certifications };
const dappsUrl = state.api.dappsUrl;
return { certifications, dappsUrl };
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Less squashing, break would be good before the return line.

export default connect(
mapStateToProps,
mapDispatchToProps
null
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could remove completely

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I actually like null here because null !== undefined and because connect is commonly known as the function that accepts two params, one function for each direction.

@@ -31,7 +34,11 @@ export default class List extends Component {
empty: PropTypes.bool,
order: PropTypes.string,
orderFallback: PropTypes.string,
handleAddSearchToken: PropTypes.func
certifications: PropTypes.object.isRequired,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Considder adding properties in alphabetical order, they are getting out of hand in some places. (I believe both myself and @ngotchac have been trying to do that lately just to bring in some sanity)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't have a system of ordering "regular" props, but I have at least been trying to put actions at the end and props passed from the parent at the beginning.

@jacogr jacogr added A6-mustntgrumble 💦 Pull request has areas for improvement. The author need not address them before merging. and removed A0-pleasereview 🤓 Pull request needs code review. labels Dec 15, 2016
@jacogr
Copy link
Contributor

jacogr commented Dec 15, 2016

Tiny grumbles & styling comments, none critical.

@gavofyork gavofyork merged commit d76239e into master Dec 15, 2016
@gavofyork gavofyork deleted the jr-use-badge-reg branch December 15, 2016 13:43
@coveralls
Copy link

Coverage Status

Coverage increased (+0.3%) to 85.859% when pulling 4c42ded on jr-use-badge-reg into 03db4d0 on master.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
A6-mustntgrumble 💦 Pull request has areas for improvement. The author need not address them before merging.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants