Skip to content

Commit

Permalink
Merge pull request #402 from thanhson1085/master
Browse files Browse the repository at this point in the history
fix bug status in detail page
  • Loading branch information
pqv199x authored Dec 22, 2018
2 parents 00f9752 + 22ca392 commit 412dc8c
Show file tree
Hide file tree
Showing 2 changed files with 3,627 additions and 3,592 deletions.
27 changes: 27 additions & 0 deletions apis/candidates.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,33 @@ router.get('/:candidate', async function (req, res, next) {
candidate: address
}) || {})

let latestSigners = await db.Signer.findOne({}).sort({ _id: 'desc' })
let latestPenalties = await db.Penalty.findOne({}).sort({ _id: 'desc' })

const signers = (latestSigners || {}).signers || []
const penalties = (latestPenalties || {}).penalties || []

const setS = new Set()
for (let i = 0; i < signers.length; i++) {
setS.add((signers[i] || '').toLowerCase())
}

const setP = new Set()
for (let i = 0; i < penalties.length; i++) {
setP.add((penalties[i] || '').toLowerCase())
}

if (signers.length === 0) {
candidate.isMasternode = !!candidate.latestSignedBlock
} else {
candidate.isMasternode = setS.has((candidate.candidate || '').toLowerCase())
}

candidate.isPenalty = setP.has((candidate.candidate || '').toLowerCase())

candidate.status = (candidate.isMasternode) ? 'MASTERNODE' : candidate.status
candidate.status = (candidate.isPenalty) ? 'SLASHED' : candidate.status

return res.json(candidate)
})

Expand Down
Loading

0 comments on commit 412dc8c

Please sign in to comment.