Skip to content

Commit cf0b572

Browse files
committed
fix: standardise balance and branding footer
- Add a shared formatBalance helper (3 decimals + ℏ) and use it for the menu and profile balances so they no longer differ in precision/unit. - Let the branding page grow with its content so the fixed action bar no longer overlaps the last card. Signed-off-by: Alex Piatakov <alex.piatakov@swirldslabs.com>
1 parent 16909fa commit cf0b572

6 files changed

Lines changed: 34 additions & 14 deletions

File tree

frontend/src/app/utils/balance.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
const HBAR_SYMBOL = 'ℏ';
2+
3+
/**
4+
* Standardise a balance for display: 3 decimal places and the ℏ symbol.
5+
* Accepts a raw number or a string that may already carry a unit
6+
* (e.g. "42.8073534 ℏ" or a value paired with "HBar"). Non-numeric values
7+
* are returned unchanged so error states like "N\A" still show through.
8+
*/
9+
export function formatBalance(balance: string | number | null | undefined): string {
10+
if (balance === null || balance === undefined || balance === '') {
11+
return '';
12+
}
13+
const value = typeof balance === 'number' ? balance : parseFloat(balance);
14+
if (!isFinite(value)) {
15+
return typeof balance === 'string' ? balance : '';
16+
}
17+
return `${value.toFixed(3)} ${HBAR_SYMBOL}`;
18+
}

frontend/src/app/utils/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ export { EntityAccess, EntityGroup } from "./permissions-entity";
44
export { PermissionsGroup } from "./permissions";
55
export { MergeUtils } from "./merge-utils";
66
export { getUserInitials } from "./user-initials";
7+
export { formatBalance } from "./balance";

frontend/src/app/views/branding/branding.component.scss

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
11
.guardian-page {
2+
// The shared .guardian-page is height: 100% + flex, so a plain padding-bottom
3+
// can't reserve room for the fixed actions bar — overflowing content scrolls
4+
// flush under it. Let the page grow with its content instead so the padding
5+
// becomes real scroll space below the last card.
6+
height: auto;
7+
min-height: 100%;
28
padding-bottom: 88px;
39
}
410

frontend/src/app/views/new-header/new-header.component.ts

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Component, Input, OnInit, OnDestroy, AfterViewInit, ElementRef, ViewChild, NgZone, AfterViewChecked } from '@angular/core';
22
import { MenuItem } from 'primeng/api';
33
import { getMenuItems, NavbarMenuItem } from './menu.model';
4-
import { getUserInitials } from '../../utils';
4+
import { formatBalance, getUserInitials } from '../../utils';
55
import { MenuLayout, MenuLayoutService } from '../../services/menu-layout.service';
66
import { IUser, UserCategory, UserPermissions, UserRole } from '@guardian/interfaces';
77
import { AuthStateService } from '../../services/auth-state.service';
@@ -96,8 +96,7 @@ export class NewHeaderComponent implements OnInit, OnDestroy, AfterViewChecked {
9696
this.ws = this.webSocketService.profileSubscribe((event) => {
9797
if (event.type === 'PROFILE_BALANCE') {
9898
if (event.data && event.data.balance) {
99-
const b = parseFloat(event.data.balance);
100-
this.balance = `${b.toFixed(3)} ${event.data.unit}`;
99+
this.balance = formatBalance(event.data.balance);
101100
} else {
102101
this.balance = 'N\\A';
103102
this.balanceType = '';
@@ -166,15 +165,7 @@ export class NewHeaderComponent implements OnInit, OnDestroy, AfterViewChecked {
166165
this.auth.balance().subscribe((balance: any) => {
167166
if (balance && balance.balance) {
168167
const b = parseFloat(balance.balance);
169-
if (b > 999) {
170-
this.balance = `${b.toFixed(0)} ${balance.unit}`;
171-
} else if (b > 99) {
172-
this.balance = `${b.toFixed(2)} ${balance.unit}`;
173-
} else if (b > 9) {
174-
this.balance = `${b.toFixed(3)} ${balance.unit}`;
175-
} else {
176-
this.balance = `${b.toFixed(4)} ${balance.unit}`;
177-
}
168+
this.balance = formatBalance(b);
178169
if (b > 100) {
179170
this.balanceType = 'normal';
180171
} else if (b > 20) {

frontend/src/app/views/root-profile/root-profile.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@
6565
</div>
6666
<div class="profile-row">
6767
<span class="profile-label">Balance</span>
68-
<span class="profile-value">{{ balance }}</span>
68+
<span class="profile-value">{{ formatBalance(balance) }}</span>
6969
</div>
7070
</div>
7171
</p-card>

frontend/src/app/views/root-profile/root-profile.component.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import { ToastrService } from 'ngx-toastr';
2626
import { AppTheme, AppThemeOption, AppThemeService } from '../../services/app-theme.service';
2727
import { MenuLayout, MenuLayoutOption, MenuLayoutService } from '../../services/menu-layout.service';
2828
import { DocWidgetService } from '../../services/doc-widget.service';
29-
import { getUserInitials } from '../../utils';
29+
import { formatBalance, getUserInitials } from '../../utils';
3030

3131
enum OperationMode {
3232
None,
@@ -865,6 +865,10 @@ export class RootProfileComponent implements OnInit, OnDestroy {
865865
return getUserInitials(username);
866866
}
867867

868+
formatBalance(balance: string | null): string {
869+
return formatBalance(balance);
870+
}
871+
868872
formatRole(role: string | undefined): string {
869873
if (!role) { return ''; }
870874
return role.split('_').map(w => w.charAt(0).toUpperCase() + w.slice(1).toLowerCase()).join(' ');

0 commit comments

Comments
 (0)