diff --git a/src/libs/PersonalDetailsUtils.ts b/src/libs/PersonalDetailsUtils.ts index 391cabef0790..fc87d0843734 100644 --- a/src/libs/PersonalDetailsUtils.ts +++ b/src/libs/PersonalDetailsUtils.ts @@ -24,23 +24,19 @@ Onyx.connect({ }, }); -// Index for the substring method to remove the merged account prefix. -const substringStartIndex = CONST.MERGED_ACCOUNT_PREFIX.length; - function getDisplayNameOrDefault(passedPersonalDetails?: Partial | null, defaultValue = '', shouldFallbackToHidden = true, shouldAddCurrentUserPostfix = false): string { let displayName = passedPersonalDetails?.displayName ?? ''; // If the displayName starts with the merged account prefix, remove it. if (displayName.startsWith(CONST.MERGED_ACCOUNT_PREFIX)) { - displayName = displayName.substring(substringStartIndex); + // Remove the merged account prefix from the displayName. + displayName = displayName.substring(CONST.MERGED_ACCOUNT_PREFIX.length); } if (shouldAddCurrentUserPostfix && !!displayName) { displayName = `${displayName} (${Localize.translateLocal('common.you').toLowerCase()})`; } - // If displayName exists, return it early so we don't have to allocate - // memory for the fallback string. if (displayName) { return displayName; }