Browse Source

format total numbers better

pull/137/head
Trent Larson 1 day ago
parent
commit
6a47f0d3e7
  1. 13
      src/libs/util.ts
  2. 7
      src/views/ProjectViewView.vue

13
src/libs/util.ts

@ -42,7 +42,6 @@ import { createPeerDid } from "../libs/crypto/vc/didPeer";
import { registerCredential } from "../libs/crypto/vc/passkeyDidPeer"; import { registerCredential } from "../libs/crypto/vc/passkeyDidPeer";
import { logger } from "../utils/logger"; import { logger } from "../utils/logger";
import { PlatformServiceFactory } from "@/services/PlatformServiceFactory"; import { PlatformServiceFactory } from "@/services/PlatformServiceFactory";
import OfferDetailsView from "@/views/OfferDetailsView.vue";
export interface GiverReceiverInputInfo { export interface GiverReceiverInputInfo {
did?: string; did?: string;
@ -81,18 +80,21 @@ export const UNIT_LONG: Record<string, string> = {
}; };
/* eslint-enable prettier/prettier */ /* eslint-enable prettier/prettier */
const UNIT_CODES: Record<string, Record<string, string>> = { const UNIT_CODES: Record<string, { name: string; faIcon: string; decimals: number }> = {
BTC: { BTC: {
name: "Bitcoin", name: "Bitcoin",
faIcon: "bitcoin-sign", faIcon: "bitcoin-sign",
decimals: 4,
}, },
HUR: { HUR: {
name: "hours", name: "hours",
faIcon: "clock", faIcon: "clock",
decimals: 0,
}, },
USD: { USD: {
name: "US Dollars", name: "US Dollars",
faIcon: "dollar", faIcon: "dollar",
decimals: 2,
}, },
}; };
@ -100,6 +102,13 @@ export function iconForUnitCode(unitCode: string) {
return UNIT_CODES[unitCode]?.faIcon || "question"; 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 // 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 // ... though it appears even this isn't precisely right so keep doing "|| 0" or something in sensitive places
// //

7
src/views/ProjectViewView.vue

@ -386,11 +386,10 @@
> >
<!-- just show the hours, or alternatively whatever is first --> <!-- just show the hours, or alternatively whatever is first -->
<span v-if="givenTotalHours() > 0"> <span v-if="givenTotalHours() > 0">
{{ givenTotalHours() }} {{ libsUtil.UNIT_SHORT["HUR"] }} {{ libsUtil.formattedAmount(givenTotalHours(), "HUR") }}
</span> </span>
<span v-else> <span v-else>
{{ givesTotalsByUnit[0].amount }} {{ libsUtil.formattedAmount(givesTotalsByUnit[0].amount, givesTotalsByUnit[0].unit) }}
{{ libsUtil.UNIT_SHORT[givesTotalsByUnit[0].unit] }}
</span> </span>
<span v-if="givesTotalsByUnit.length > 1">...</span> <span v-if="givesTotalsByUnit.length > 1">...</span>
<span> <span>
@ -411,7 +410,7 @@
:icon="libsUtil.iconForUnitCode(total.unit)" :icon="libsUtil.iconForUnitCode(total.unit)"
class="fa-fw text-slate-400 mr-1" class="fa-fw text-slate-400 mr-1"
/> />
{{ total.amount }} {{ libsUtil.UNIT_LONG[total.unit] }} {{ libsUtil.formattedAmount(total.amount, total.unit) }}
</div> </div>
</div> </div>
</span> </span>

Loading…
Cancel
Save