From dbe9dcb998446be53e676ccb72daa865e4a7701d Mon Sep 17 00:00:00 2001 From: Carson Locke Ross Date: Fri, 18 Feb 2022 21:29:58 +0800 Subject: [PATCH 1/5] chore: truncate no. of peers to unit of "k" when > 999 --- add-on/src/lib/ipfs-companion.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/add-on/src/lib/ipfs-companion.js b/add-on/src/lib/ipfs-companion.js index cf7a9db9e..f3cffd06d 100644 --- a/add-on/src/lib/ipfs-companion.js +++ b/add-on/src/lib/ipfs-companion.js @@ -507,7 +507,8 @@ module.exports = async function init () { } let badgeText, badgeColor, badgeIcon - badgeText = state.peerCount.toString() + // prevent text overflow when peer count has more than 3 digits + badgeText = (state.peerCount > 999) ? (Math.floor(state.peerCount/1000).toFixed(0) + "k") : state.peerCount.toString(); if (state.peerCount > 0) { // All is good (online with peers) badgeColor = '#418B8E' From 3f1fceeab2aa773fa9fb6a62577dfd73b1b09069 Mon Sep 17 00:00:00 2001 From: Carson Locke Ross Date: Sat, 19 Feb 2022 10:25:21 +0800 Subject: [PATCH 2/5] fix: fix js lint and remove extra string method --- add-on/src/lib/ipfs-companion.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/add-on/src/lib/ipfs-companion.js b/add-on/src/lib/ipfs-companion.js index f3cffd06d..63f4c40aa 100644 --- a/add-on/src/lib/ipfs-companion.js +++ b/add-on/src/lib/ipfs-companion.js @@ -508,7 +508,7 @@ module.exports = async function init () { let badgeText, badgeColor, badgeIcon // prevent text overflow when peer count has more than 3 digits - badgeText = (state.peerCount > 999) ? (Math.floor(state.peerCount/1000).toFixed(0) + "k") : state.peerCount.toString(); + badgeText = (state.peerCount > 999) ? (Math.floor(state.peerCount / 1000).toString() + 'k') : state.peerCount.toString() if (state.peerCount > 0) { // All is good (online with peers) badgeColor = '#418B8E' From f4217cef40594a7d6b3297fd29454aee1b2885d1 Mon Sep 17 00:00:00 2001 From: Russell Dempsey <1173416+SgtPooki@users.noreply.github.com> Date: Mon, 11 Jul 2022 11:07:16 -0700 Subject: [PATCH 3/5] fix: check peerCount > 999 only if peerCount>0 --- add-on/src/lib/ipfs-companion.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/add-on/src/lib/ipfs-companion.js b/add-on/src/lib/ipfs-companion.js index 63f4c40aa..90f2a3e0f 100644 --- a/add-on/src/lib/ipfs-companion.js +++ b/add-on/src/lib/ipfs-companion.js @@ -507,12 +507,13 @@ module.exports = async function init () { } let badgeText, badgeColor, badgeIcon - // 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() 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' From 5a702b85b953e384b1758d6899ab8558dc5ac879 Mon Sep 17 00:00:00 2001 From: Russell Dempsey <1173416+SgtPooki@users.noreply.github.com> Date: Mon, 11 Jul 2022 11:08:38 -0700 Subject: [PATCH 4/5] fix: badgeText defaults to empty --- add-on/src/lib/ipfs-companion.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/add-on/src/lib/ipfs-companion.js b/add-on/src/lib/ipfs-companion.js index 90f2a3e0f..6c10761af 100644 --- a/add-on/src/lib/ipfs-companion.js +++ b/add-on/src/lib/ipfs-companion.js @@ -507,6 +507,8 @@ module.exports = async function init () { } let badgeText, badgeColor, badgeIcon + + badgeText = '' if (state.peerCount > 0) { // All is good (online with peers) badgeColor = '#418B8E' @@ -520,7 +522,6 @@ module.exports = async function init () { badgeIcon = '/icons/ipfs-logo-on.svg' } else { // API is offline - badgeText = '' badgeColor = '#8C8C8C' badgeIcon = '/icons/ipfs-logo-off.svg' } From 4568072b696786c2850bc01a5ea8fa71c6477748 Mon Sep 17 00:00:00 2001 From: Marcin Rataj Date: Mon, 26 Sep 2022 23:50:27 +0200 Subject: [PATCH 5/5] chore: fix lint --- add-on/src/lib/ipfs-companion.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/add-on/src/lib/ipfs-companion.js b/add-on/src/lib/ipfs-companion.js index 6c10761af..eab27a95f 100644 --- a/add-on/src/lib/ipfs-companion.js +++ b/add-on/src/lib/ipfs-companion.js @@ -507,13 +507,13 @@ module.exports = async function init () { } let badgeText, badgeColor, badgeIcon - + 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) {