refactor of money utils with new money2 package
This commit is contained in:
@@ -23,17 +23,12 @@ List<Widget> buildOperationCardItems(
|
||||
if (items.isNotEmpty) {
|
||||
items.add(const SizedBox(height: 16));
|
||||
}
|
||||
items.add(_DateHeader(
|
||||
label: _dateLabel(context, operation.date, loc),
|
||||
));
|
||||
items.add(_DateHeader(label: _dateLabel(context, operation.date, loc)));
|
||||
items.add(const SizedBox(height: 8));
|
||||
currentKey = dateKey;
|
||||
}
|
||||
|
||||
items.add(OperationCard(
|
||||
operation: operation,
|
||||
onTap: onTap,
|
||||
));
|
||||
items.add(OperationCard(operation: operation, onTap: onTap));
|
||||
items.add(const SizedBox(height: 12));
|
||||
}
|
||||
|
||||
@@ -66,9 +61,7 @@ class _DateHeader extends StatelessWidget {
|
||||
final theme = Theme.of(context);
|
||||
return Text(
|
||||
label,
|
||||
style: theme.textTheme.titleSmall?.copyWith(
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
style: theme.textTheme.titleSmall?.copyWith(fontWeight: FontWeight.w600),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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));
|
||||
|
||||
|
||||
@@ -12,11 +12,9 @@ Future<void> pickOperationsRange(
|
||||
ReportOperationsController controller,
|
||||
) async {
|
||||
final now = DateTime.now();
|
||||
final initial = controller.selectedRange ??
|
||||
DateTimeRange(
|
||||
start: now.subtract(const Duration(days: 30)),
|
||||
end: now,
|
||||
);
|
||||
final initial =
|
||||
controller.selectedRange ??
|
||||
DateTimeRange(start: now.subtract(const Duration(days: 30)), end: now);
|
||||
|
||||
final picked = await showDateRangePicker(
|
||||
context: context,
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'package:pshared/models/money.dart';
|
||||
import 'package:pshared/models/payment/operation.dart';
|
||||
import 'package:pshared/models/payment/status.dart';
|
||||
import 'package:pshared/utils/currency.dart';
|
||||
|
||||
import 'package:pweb/pages/report/table/badge.dart';
|
||||
import 'package:pweb/utils/money_display.dart';
|
||||
@@ -38,13 +36,15 @@ class OperationRow {
|
||||
label: Text(loc.downloadAct),
|
||||
)
|
||||
: Text(op.fileName ?? '');
|
||||
final amountLabel = formatMoneyUiWithL10n(
|
||||
loc,
|
||||
Money(amount: amountToString(op.amount), currency: op.currency),
|
||||
final amountLabel = formatAmountUi(
|
||||
context,
|
||||
amount: op.amount,
|
||||
currency: op.currency,
|
||||
);
|
||||
final toAmountLabel = formatMoneyUiWithL10n(
|
||||
loc,
|
||||
Money(amount: amountToString(op.toAmount), currency: op.toCurrency),
|
||||
final toAmountLabel = formatAmountUi(
|
||||
context,
|
||||
amount: op.toAmount,
|
||||
currency: op.toCurrency,
|
||||
);
|
||||
|
||||
return DataRow(
|
||||
|
||||
Reference in New Issue
Block a user