From 6a47f0d3e706b1de4d9d4910276e96e33f83e009 Mon Sep 17 00:00:00 2001 From: Trent Larson Date: Fri, 6 Jun 2025 19:40:53 -0600 Subject: [PATCH] format total numbers better --- src/libs/util.ts | 13 +++++++++++-- src/views/ProjectViewView.vue | 7 +++---- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/src/libs/util.ts b/src/libs/util.ts index 7c2dc7a4..b286c7f0 100644 --- a/src/libs/util.ts +++ b/src/libs/util.ts @@ -42,7 +42,6 @@ import { createPeerDid } from "../libs/crypto/vc/didPeer"; import { registerCredential } from "../libs/crypto/vc/passkeyDidPeer"; import { logger } from "../utils/logger"; import { PlatformServiceFactory } from "@/services/PlatformServiceFactory"; -import OfferDetailsView from "@/views/OfferDetailsView.vue"; export interface GiverReceiverInputInfo { did?: string; @@ -81,18 +80,21 @@ export const UNIT_LONG: Record = { }; /* eslint-enable prettier/prettier */ -const UNIT_CODES: Record> = { +const UNIT_CODES: Record = { BTC: { name: "Bitcoin", faIcon: "bitcoin-sign", + decimals: 4, }, HUR: { name: "hours", faIcon: "clock", + decimals: 0, }, USD: { name: "US Dollars", faIcon: "dollar", + decimals: 2, }, }; @@ -100,6 +102,13 @@ export function iconForUnitCode(unitCode: string) { return UNIT_CODES[unitCode]?.faIcon || "question"; } +export function formattedAmount(amount: number, unitCode: string) { + const unit = UNIT_CODES[unitCode]; + const amountStr = amount.toFixed(unit?.decimals ?? 4); + const unitName = unit?.name || "?"; + return amountStr + " " + unitName; +} + // from https://stackoverflow.com/a/175787/845494 // ... though it appears even this isn't precisely right so keep doing "|| 0" or something in sensitive places // diff --git a/src/views/ProjectViewView.vue b/src/views/ProjectViewView.vue index e3876af1..b2f23258 100644 --- a/src/views/ProjectViewView.vue +++ b/src/views/ProjectViewView.vue @@ -386,11 +386,10 @@ > - {{ givenTotalHours() }} {{ libsUtil.UNIT_SHORT["HUR"] }} + {{ libsUtil.formattedAmount(givenTotalHours(), "HUR") }} - {{ givesTotalsByUnit[0].amount }} - {{ libsUtil.UNIT_SHORT[givesTotalsByUnit[0].unit] }} + {{ libsUtil.formattedAmount(givesTotalsByUnit[0].amount, givesTotalsByUnit[0].unit) }} ... @@ -411,7 +410,7 @@ :icon="libsUtil.iconForUnitCode(total.unit)" class="fa-fw text-slate-400 mr-1" /> - {{ total.amount }} {{ libsUtil.UNIT_LONG[total.unit] }} + {{ libsUtil.formattedAmount(total.amount, total.unit) }}