Address copilot feedback

This commit is contained in:
Felipe Knorr Kuhn 2026-04-10 15:30:39 +09:00
parent 66eb41001d
commit f1f3dd0634
No known key found for this signature in database
GPG key ID: 79619B52BB097C1A

View file

@ -10,6 +10,7 @@ import { StateService } from '@app/services/state.service';
export class FiatCurrencyPipe implements PipeTransform {
fiatSubscription: Subscription;
currency: string;
private currencyMaxFracCache: Record<string, number> = {};
constructor(
@Inject(LOCALE_ID) public locale: string,
@ -20,6 +21,15 @@ export class FiatCurrencyPipe implements PipeTransform {
});
}
private getCurrencyMaxFrac(currency: string): number {
if (!(currency in this.currencyMaxFracCache)) {
this.currencyMaxFracCache[currency] =
new Intl.NumberFormat(this.locale, { style: 'currency', currency }).resolvedOptions().maximumFractionDigits ??
Number.POSITIVE_INFINITY;
}
return this.currencyMaxFracCache[currency];
}
transform(num: number, ...args: any[]): unknown {
const digitsInfo = args[0];
const currency = args[1] || this.currency || 'USD';
@ -31,9 +41,7 @@ export class FiatCurrencyPipe implements PipeTransform {
if (match) {
const minFrac = parseInt(match[2], 10);
const maxFrac = parseInt(match[3], 10);
const currencyMaxFrac =
new Intl.NumberFormat(this.locale, { style: 'currency', currency }).resolvedOptions().maximumFractionDigits ??
Number.POSITIVE_INFINITY;
const currencyMaxFrac = this.getCurrencyMaxFrac(currency);
options.minimumFractionDigits = Math.min(minFrac, currencyMaxFrac);
options.maximumFractionDigits = Math.min(maxFrac, currencyMaxFrac);
}