From f4dbf56ef99b2226b184ae5aa0cb724d4270bb69 Mon Sep 17 00:00:00 2001 From: Felipe Knorr Kuhn Date: Sun, 12 Apr 2026 13:53:01 +0900 Subject: [PATCH] Address copilot feedback --- .../src/app/shared/pipes/fiat-currency.pipe.ts | 18 +++++++++++++++--- .../app/shared/pipes/fiat-shortener.pipe.ts | 8 ++++++-- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/frontend/src/app/shared/pipes/fiat-currency.pipe.ts b/frontend/src/app/shared/pipes/fiat-currency.pipe.ts index 8daee206b..a06c88b1f 100644 --- a/frontend/src/app/shared/pipes/fiat-currency.pipe.ts +++ b/frontend/src/app/shared/pipes/fiat-currency.pipe.ts @@ -1,13 +1,17 @@ import { formatCurrency, getCurrencySymbol } from '@angular/common'; -import { Inject, LOCALE_ID, Pipe, PipeTransform } from '@angular/core'; +import { Inject, LOCALE_ID, OnDestroy, Pipe, PipeTransform } from '@angular/core'; import { Subscription } from 'rxjs'; import { StateService } from '@app/services/state.service'; +// Below this threshold, show 2 decimal places even when digitsInfo requests 0, +// so small fiat amounts (e.g. $3.50) remain readable instead of rounding to $4. +const SMALL_FIAT_THRESHOLD = 1000; + @Pipe({ name: 'fiatCurrency', standalone: false, }) -export class FiatCurrencyPipe implements PipeTransform { +export class FiatCurrencyPipe implements PipeTransform, OnDestroy { fiatSubscription: Subscription; currency: string; private currencyMaxFracCache: Record = {}; @@ -21,6 +25,10 @@ export class FiatCurrencyPipe implements PipeTransform { }); } + ngOnDestroy(): void { + this.fiatSubscription.unsubscribe(); + } + private getCurrencyMaxFrac(currency: string): number { if (!(currency in this.currencyMaxFracCache)) { this.currencyMaxFracCache[currency] = @@ -39,10 +47,14 @@ export class FiatCurrencyPipe implements PipeTransform { if (digitsInfo) { const match = digitsInfo.match(/^(\d+)\.(\d+)-(\d+)$/); if (match) { + const minInt = parseInt(match[1], 10); const minFrac = parseInt(match[2], 10); const maxFrac = parseInt(match[3], 10); const currencyMaxFrac = this.getCurrencyMaxFrac(currency); - if (maxFrac === 0 && Math.abs(num) < 1000) { + if (minInt > 1) { + options.minimumIntegerDigits = minInt; + } + if (maxFrac === 0 && Math.abs(num) < SMALL_FIAT_THRESHOLD) { options.minimumFractionDigits = Math.min(2, currencyMaxFrac); options.maximumFractionDigits = Math.min(2, currencyMaxFrac); } else { diff --git a/frontend/src/app/shared/pipes/fiat-shortener.pipe.ts b/frontend/src/app/shared/pipes/fiat-shortener.pipe.ts index 024e4404c..07a55d43c 100644 --- a/frontend/src/app/shared/pipes/fiat-shortener.pipe.ts +++ b/frontend/src/app/shared/pipes/fiat-shortener.pipe.ts @@ -1,5 +1,5 @@ import { formatCurrency, getCurrencySymbol } from '@angular/common'; -import { Inject, LOCALE_ID, Pipe, PipeTransform } from '@angular/core'; +import { Inject, LOCALE_ID, OnDestroy, Pipe, PipeTransform } from '@angular/core'; import { Subscription } from 'rxjs'; import { StateService } from '@app/services/state.service'; @@ -7,7 +7,7 @@ import { StateService } from '@app/services/state.service'; name: 'fiatShortener', standalone: false, }) -export class FiatShortenerPipe implements PipeTransform { +export class FiatShortenerPipe implements PipeTransform, OnDestroy { fiatSubscription: Subscription; currency: string; @@ -20,6 +20,10 @@ export class FiatShortenerPipe implements PipeTransform { }); } + ngOnDestroy(): void { + this.fiatSubscription.unsubscribe(); + } + transform(num: number, ...args: any[]): unknown { const digits = args[0] || 1; const currency = args[1] || this.currency || 'USD';