Skip to content

Commit 7a83fcb

Browse files
committed
refactor: ♻️ the counter on the fox shows a maximum value of 9+
1 parent d0e995f commit 7a83fcb

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

app/scripts/background.js

+14-6
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ import { TRIGGER_TYPES } from './controllers/metamask-notifications/constants/no
8484
const BADGE_COLOR_APPROVAL = '#0376C9';
8585
// eslint-disable-next-line @metamask/design-tokens/color-no-hex
8686
const BADGE_COLOR_NOTIFICATION = '#D73847';
87-
const BADGE_MAX_NOTIFICATION_COUNT = 9;
87+
const BADGE_MAX_COUNT = 9;
8888

8989
// Setup global hook for improved Sentry state snapshots during initialization
9090
const inTest = process.env.IN_TEST;
@@ -975,6 +975,17 @@ export function setupController(
975975

976976
controller.txController.initApprovals();
977977

978+
/**
979+
* Formats a count for display as a badge label.
980+
*
981+
* @param {number} count - The count to be formatted.
982+
* @param {number} maxCount - The maximum count to display before using the '+' suffix.
983+
* @returns {string} The formatted badge label.
984+
*/
985+
function getBadgeLabel(count, maxCount) {
986+
return count > maxCount ? `${maxCount}+` : String(count);
987+
}
988+
978989
/**
979990
* Updates the Web Extension's "badge" number, on the little fox in the toolbar.
980991
* The number reflects the current number of pending transactions or message signatures needing user approval.
@@ -987,12 +998,9 @@ export function setupController(
987998
let badgeColor = BADGE_COLOR_APPROVAL;
988999

9891000
if (pendingApprovalCount) {
990-
label = String(pendingApprovalCount);
1001+
label = getBadgeLabel(pendingApprovalCount, BADGE_MAX_COUNT);
9911002
} else if (unreadNotificationsCount > 0) {
992-
label =
993-
unreadNotificationsCount > BADGE_MAX_NOTIFICATION_COUNT
994-
? `${BADGE_MAX_NOTIFICATION_COUNT}+`
995-
: String(unreadNotificationsCount);
1003+
label = getBadgeLabel(unreadNotificationsCount, BADGE_MAX_COUNT);
9961004
badgeColor = BADGE_COLOR_NOTIFICATION;
9971005
}
9981006

0 commit comments

Comments
 (0)