fixes
This commit is contained in:
96
frontend/pweb/lib/utils/money_display.dart
Normal file
96
frontend/pweb/lib/utils/money_display.dart
Normal file
@@ -0,0 +1,96 @@
|
||||
import 'package:flutter/widgets.dart';
|
||||
|
||||
import 'package:pshared/models/asset.dart';
|
||||
import 'package:pshared/models/money.dart';
|
||||
import 'package:pshared/utils/currency.dart';
|
||||
import 'package:pshared/utils/money.dart';
|
||||
|
||||
import 'package:pweb/generated/i18n/app_localizations.dart';
|
||||
|
||||
|
||||
String unavailableMoneyValue(BuildContext context) {
|
||||
return AppLocalizations.of(context)!.valueUnavailable;
|
||||
}
|
||||
|
||||
String unavailableMoneyValueFromL10n(AppLocalizations l10n) {
|
||||
return l10n.valueUnavailable;
|
||||
}
|
||||
|
||||
String formatMoneyUi(
|
||||
BuildContext context,
|
||||
Money? money, {
|
||||
String separator = ' ',
|
||||
}) {
|
||||
return formatMoneyUiWithL10n(
|
||||
AppLocalizations.of(context)!,
|
||||
money,
|
||||
separator: separator,
|
||||
);
|
||||
}
|
||||
|
||||
String formatMoneyUiWithL10n(
|
||||
AppLocalizations l10n,
|
||||
Money? money, {
|
||||
String separator = ' ',
|
||||
}) {
|
||||
final unavailableValue = unavailableMoneyValueFromL10n(l10n);
|
||||
return formatMoneyDisplay(
|
||||
money,
|
||||
fallback: unavailableValue,
|
||||
invalidAmountFallback: unavailableValue,
|
||||
separator: separator,
|
||||
);
|
||||
}
|
||||
|
||||
String formatAmountUi(
|
||||
BuildContext context, {
|
||||
required double amount,
|
||||
required String currency,
|
||||
String separator = ' ',
|
||||
}) {
|
||||
return formatAmountUiWithL10n(
|
||||
AppLocalizations.of(context)!,
|
||||
amount: amount,
|
||||
currency: currency,
|
||||
separator: separator,
|
||||
);
|
||||
}
|
||||
|
||||
String formatAmountUiWithL10n(
|
||||
AppLocalizations l10n, {
|
||||
required double amount,
|
||||
required String currency,
|
||||
String separator = ' ',
|
||||
}) {
|
||||
return formatMoneyUiWithL10n(
|
||||
l10n,
|
||||
Money(amount: amountToString(amount), currency: currency),
|
||||
separator: separator,
|
||||
);
|
||||
}
|
||||
|
||||
String formatAssetUi(
|
||||
BuildContext context,
|
||||
Asset? asset, {
|
||||
String separator = ' ',
|
||||
}) {
|
||||
return formatAssetUiWithL10n(
|
||||
AppLocalizations.of(context)!,
|
||||
asset,
|
||||
separator: separator,
|
||||
);
|
||||
}
|
||||
|
||||
String formatAssetUiWithL10n(
|
||||
AppLocalizations l10n,
|
||||
Asset? asset, {
|
||||
String separator = ' ',
|
||||
}) {
|
||||
if (asset == null) return unavailableMoneyValueFromL10n(l10n);
|
||||
return formatAmountUiWithL10n(
|
||||
l10n,
|
||||
amount: asset.amount,
|
||||
currency: currencyCodeToString(asset.currency),
|
||||
separator: separator,
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user