From e8d170adbeaca80eea1f4a7e52a7f164d085ebe7 Mon Sep 17 00:00:00 2001 From: Carson Y Date: Tue, 27 Sep 2022 05:51:23 +0800 Subject: [PATCH] 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 <1173416+SgtPooki@users.noreply.github.com> Co-authored-by: Marcin Rataj --- add-on/src/lib/ipfs-companion.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/add-on/src/lib/ipfs-companion.js b/add-on/src/lib/ipfs-companion.js index 03399e797..fade77708 100644 --- a/add-on/src/lib/ipfs-companion.js +++ b/add-on/src/lib/ipfs-companion.js @@ -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' }