Skip to content

Commit

Permalink
feature: add balance to account selector UI
Browse files Browse the repository at this point in the history
  • Loading branch information
jackson-dean committed Sep 22, 2023
1 parent c1828e6 commit 74ffe12
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/app/backend-api.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ export class BackendAPIService {
publicKeys: string[]
): Observable<{ [key: string]: UserProfile }> {
const userProfiles: { [key: string]: any } = {};
const req = this.GetUsersStateless(publicKeys, true);
const req = this.GetUsersStateless(publicKeys, true, true);
if (publicKeys.length > 0) {
return req
.pipe(
Expand All @@ -358,6 +358,7 @@ export class BackendAPIService {
userProfiles[user.PublicKeyBase58Check] = {
username: user.ProfileEntryResponse?.Username,
profilePic: user.ProfileEntryResponse?.ProfilePic,
balanceNanos: user.BalanceNanos,
};
}
return userProfiles;
Expand Down
32 changes: 32 additions & 0 deletions src/app/global-vars.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,4 +180,36 @@ export class GlobalVarsService {
formatTxCountLimit(count: number = 0): string {
return count >= 1e9 ? 'UNLIMITED' : count.toLocaleString();
}

abbreviateNumber(value: number) {
if (value === 0) {
return '0';
}

if (value < 0) {
return value.toString();
}
if (value < 0.01) {
return value.toFixed(5);
}
if (value < 0.1) {
return value.toFixed(4);
}

let shortValue;
const suffixes = ['', 'K', 'M', 'B', 'e12', 'e15', 'e18', 'e21'];
const suffixNum = Math.floor((('' + value.toFixed(0)).length - 1) / 3);
shortValue = value / Math.pow(1000, suffixNum);
if (
Math.floor(shortValue / 100) > 0 ||
shortValue / 1 === 0 ||
suffixNum > 3
) {
return shortValue.toFixed(0) + suffixes[suffixNum];
}
if (Math.floor(shortValue / 10) > 0 || Math.floor(shortValue) > 0) {
return shortValue.toFixed(2) + suffixes[suffixNum];
}
return shortValue.toFixed(3) + suffixes[suffixNum];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,13 @@
*ngIf="!this.globalVars.isMobile()"
class="display--flex flex--column items--end"
>
<span
class="font-weight--bold font-size--xsmall margin-right--small"
>{{
globalVars.abbreviateNumber(account.balanceNanos / 1e9)
}}
$DESO</span
>
<span class="font-size--xsmall margin-right--small"
>Account: {{ account.accountNumber }}</span
>
Expand Down

0 comments on commit 74ffe12

Please sign in to comment.