Skip to content

Commit e8d170a

Browse files
Carson12345SgtPookilidel
authored
fix: truncate no. of peers to unit of "k" when > 999 (#1053)
* chore: truncate no. of peers to unit of "k" when > 999 Co-authored-by: Russell Dempsey <[email protected]> Co-authored-by: Marcin Rataj <[email protected]>
1 parent 8a33b6c commit e8d170a

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

add-on/src/lib/ipfs-companion.js

+5-2
Original file line numberDiff line numberDiff line change
@@ -507,18 +507,21 @@ module.exports = async function init () {
507507
}
508508

509509
let badgeText, badgeColor, badgeIcon
510-
badgeText = state.peerCount.toString()
510+
511+
badgeText = ''
511512
if (state.peerCount > 0) {
512513
// All is good (online with peers)
513514
badgeColor = '#418B8E'
514515
badgeIcon = '/icons/ipfs-logo-on.svg'
516+
517+
// prevent text overflow when peer count has more than 3 digits
518+
badgeText = (state.peerCount > 999) ? (Math.floor(state.peerCount / 1000).toString() + 'k') : state.peerCount.toString()
515519
} else if (state.peerCount === 0) {
516520
// API is online but no peers
517521
badgeColor = 'red'
518522
badgeIcon = '/icons/ipfs-logo-on.svg'
519523
} else {
520524
// API is offline
521-
badgeText = ''
522525
badgeColor = '#8C8C8C'
523526
badgeIcon = '/icons/ipfs-logo-off.svg'
524527
}

0 commit comments

Comments
 (0)