refactor of money utils with new money2 package
This commit is contained in:
@@ -6,7 +6,6 @@ import 'package:pshared/models/payment/payment.dart';
|
||||
import 'package:pweb/pages/report/details/sections/fx.dart';
|
||||
import 'package:pweb/pages/report/details/sections/operations/section.dart';
|
||||
|
||||
|
||||
class PaymentDetailsSections extends StatelessWidget {
|
||||
final Payment payment;
|
||||
final bool Function(PaymentExecutionOperation operation)?
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'package:pshared/models/money.dart';
|
||||
import 'package:pshared/models/payment/payment.dart';
|
||||
import 'package:pshared/models/payment/fx/quote.dart';
|
||||
import 'package:pshared/utils/currency.dart';
|
||||
@@ -33,39 +32,36 @@ class PaymentFxSection extends StatelessWidget {
|
||||
final price = fx.price?.trim();
|
||||
if (price == null || price.isEmpty) return null;
|
||||
|
||||
final baseCurrency = _firstNonEmpty([
|
||||
final baseCurrency = _resolveCurrencyCode([
|
||||
fx.baseCurrency,
|
||||
fx.baseAmount?.currency,
|
||||
currencySymbolFromCode(fx.baseCurrency),
|
||||
currencySymbolFromCode(fx.baseAmount?.currency),
|
||||
fx.baseAmount?.currency.isoCode,
|
||||
]);
|
||||
final quoteCurrency = _firstNonEmpty([
|
||||
final quoteCurrency = _resolveCurrencyCode([
|
||||
fx.quoteCurrency,
|
||||
fx.quoteAmount?.currency,
|
||||
currencySymbolFromCode(fx.quoteCurrency),
|
||||
currencySymbolFromCode(fx.quoteAmount?.currency),
|
||||
fx.quoteAmount?.currency.isoCode,
|
||||
]);
|
||||
|
||||
if (baseCurrency == null || quoteCurrency == null) return price;
|
||||
|
||||
final baseDisplay = formatMoneyDisplay(
|
||||
Money(amount: '1', currency: baseCurrency),
|
||||
fallback: '1 $baseCurrency',
|
||||
invalidAmountFallback: '1',
|
||||
);
|
||||
final quoteDisplay = formatMoneyDisplay(
|
||||
Money(amount: _normalizeAmount(price), currency: quoteCurrency),
|
||||
fallback: '$price $quoteCurrency',
|
||||
invalidAmountFallback: price,
|
||||
);
|
||||
final baseDisplay =
|
||||
parseMoneyWithCurrencyCode('1', baseCurrency)?.toString() ??
|
||||
'1 $baseCurrency';
|
||||
final quoteDisplay =
|
||||
parseMoneyWithCurrencyCode(
|
||||
_normalizeAmount(price),
|
||||
quoteCurrency,
|
||||
)?.toString() ??
|
||||
'$price $quoteCurrency';
|
||||
|
||||
return '$baseDisplay = $quoteDisplay';
|
||||
}
|
||||
|
||||
String? _firstNonEmpty(List<String?> values) {
|
||||
String? _resolveCurrencyCode(List<String?> values) {
|
||||
for (final value in values) {
|
||||
final trimmed = value?.trim();
|
||||
if (trimmed != null && trimmed.isNotEmpty) return trimmed;
|
||||
if (value == null || value.isEmpty) continue;
|
||||
final resolved = money2CurrencyFromCode(value);
|
||||
if (resolved != null) return resolved.isoCode;
|
||||
return value;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -9,13 +9,11 @@ import 'package:pweb/pages/report/details/summary_card/info_line.dart';
|
||||
import 'package:pweb/pages/report/table/badge.dart';
|
||||
import 'package:pweb/utils/report/amount_parts.dart';
|
||||
import 'package:pweb/utils/report/format.dart';
|
||||
import 'package:pweb/utils/money_display.dart';
|
||||
import 'package:pweb/utils/report/payment_mapper.dart';
|
||||
import 'package:pweb/utils/clipboard.dart';
|
||||
|
||||
import 'package:pweb/generated/i18n/app_localizations.dart';
|
||||
|
||||
|
||||
class PaymentSummaryCard extends StatelessWidget {
|
||||
final Payment payment;
|
||||
|
||||
@@ -25,7 +23,7 @@ class PaymentSummaryCard extends StatelessWidget {
|
||||
Widget build(BuildContext context) {
|
||||
final loc = AppLocalizations.of(context)!;
|
||||
final theme = Theme.of(context);
|
||||
final unavailableValue = unavailableMoneyValue(context);
|
||||
final unavailableValue = loc.valueUnavailable;
|
||||
final status = statusFromPayment(payment);
|
||||
final dateLabel = formatDateLabel(context, resolvePaymentDate(payment));
|
||||
|
||||
|
||||
Reference in New Issue
Block a user