-
Notifications
You must be signed in to change notification settings - Fork 1.7k
get certifications from BadgeReg, show them in accounts overview #3768
Conversation
Changes Unknown when pulling d67a938 on jr-use-badge-reg into ** on master**. |
The tests run locally for me. CI seems to have issues. |
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 () { |
There was a problem hiding this comment.
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.`); |
There was a problem hiding this comment.
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 -
- Readability, not gaining anything (I know beauty is in the eye of the beerholder)
- 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); |
There was a problem hiding this comment.
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}.`); |
There was a problem hiding this comment.
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') { |
There was a problem hiding this comment.
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') { |
There was a problem hiding this comment.
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 }); |
There was a problem hiding this comment.
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') { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 }; |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could remove completely
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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.
Tiny grumbles & styling comments, none critical. |
The PR makes the certifications/badges show up in the accounts overview and in the address book.
Triggered by the action
fetchCertifiers
, it usesBadgeReg.sol
to fetch the addresses & metadata of all certifiers (contracts issuing certifications/badges). It then uses a filter to check forConfirmed
events.Still to do:
Listen forRevoked
and remove the certification.