Skip to content

Commit

Permalink
fix: truncate no. of peers to unit of "k" when > 999 (#1053)
Browse files Browse the repository at this point in the history
* chore: truncate no. of peers to unit of "k" when > 999
Co-authored-by: Russell Dempsey <1173416+SgtPooki@users.noreply.github.com>
Co-authored-by: Marcin Rataj <lidel@lidel.org>
  • Loading branch information
Carson12345 authored Sep 26, 2022
1 parent 8a33b6c commit e8d170a
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions add-on/src/lib/ipfs-companion.js
Original file line number Diff line number Diff line change
Expand Up @@ -507,18 +507,21 @@ module.exports = async function init () {
}

let badgeText, badgeColor, badgeIcon
badgeText = state.peerCount.toString()

badgeText = ''
if (state.peerCount > 0) {
// All is good (online with peers)
badgeColor = '#418B8E'
badgeIcon = '/icons/ipfs-logo-on.svg'

// prevent text overflow when peer count has more than 3 digits
badgeText = (state.peerCount > 999) ? (Math.floor(state.peerCount / 1000).toString() + 'k') : state.peerCount.toString()
} else if (state.peerCount === 0) {
// API is online but no peers
badgeColor = 'red'
badgeIcon = '/icons/ipfs-logo-on.svg'
} else {
// API is offline
badgeText = ''
badgeColor = '#8C8C8C'
badgeIcon = '/icons/ipfs-logo-off.svg'
}
Expand Down

0 comments on commit e8d170a

Please sign in to comment.