mirror of
https://github.com/mempool/mempool.git
synced 2026-08-19 13:18:06 +02:00
Address copilot feedback
This commit is contained in:
parent
66eb41001d
commit
f1f3dd0634
1 changed files with 11 additions and 3 deletions
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue