71 lines
1.8 KiB
Dart
71 lines
1.8 KiB
Dart
import 'package:flutter/material.dart';
|
|
|
|
import 'package:pshared/models/payment/payment.dart';
|
|
import 'package:pshared/models/payment/fx/quote.dart';
|
|
import 'package:pshared/utils/currency.dart';
|
|
|
|
import 'package:pweb/pages/report/details/section.dart';
|
|
import 'package:pweb/pages/report/details/sections/rows.dart';
|
|
|
|
import 'package:pweb/generated/i18n/app_localizations.dart';
|
|
|
|
|
|
class PaymentFxSection extends StatelessWidget {
|
|
final Payment payment;
|
|
|
|
const PaymentFxSection({
|
|
super.key,
|
|
required this.payment,
|
|
});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final loc = AppLocalizations.of(context)!;
|
|
final fx = payment.lastQuote?.fxQuote;
|
|
final rows = buildDetailRows([
|
|
DetailValue(
|
|
label: loc.fxRateLabel,
|
|
value: _formatRate(fx),
|
|
),
|
|
]);
|
|
|
|
return DetailsSection(
|
|
title: loc.paymentDetailsFx,
|
|
children: rows,
|
|
);
|
|
}
|
|
|
|
String? _formatRate(FxQuote? fx) {
|
|
if (fx == null) return null;
|
|
final price = fx.price?.trim();
|
|
if (price == null || price.isEmpty) return null;
|
|
|
|
final base = _firstNonEmpty([
|
|
currencySymbolFromCode(fx.baseCurrency),
|
|
currencySymbolFromCode(fx.baseAmount?.currency),
|
|
fx.baseCurrency,
|
|
fx.baseAmount?.currency,
|
|
]);
|
|
final quote = _firstNonEmpty([
|
|
currencySymbolFromCode(fx.quoteCurrency),
|
|
currencySymbolFromCode(fx.quoteAmount?.currency),
|
|
fx.quoteCurrency,
|
|
fx.quoteAmount?.currency,
|
|
]);
|
|
|
|
if (base == null || quote == null) {
|
|
return price;
|
|
}
|
|
|
|
return '1 $base = $price $quote';
|
|
}
|
|
|
|
String? _firstNonEmpty(List<String?> values) {
|
|
for (final value in values) {
|
|
final trimmed = value?.trim();
|
|
if (trimmed != null && trimmed.isNotEmpty) return trimmed;
|
|
}
|
|
return null;
|
|
}
|
|
}
|