Merge pull request 'refactor of money utils with new money2 package' (#726) from SEND072 into main
All checks were successful
ci/woodpecker/push/frontend Pipeline was successful
All checks were successful
ci/woodpecker/push/frontend Pipeline was successful
Reviewed-on: #726
This commit was merged in pull request #726.
This commit is contained in:
@@ -2,6 +2,6 @@ import 'package:pshared/models/currency.dart';
|
||||
import 'package:pshared/models/payment/chain_network.dart';
|
||||
|
||||
|
||||
const Currency managedCurrencyDefault = Currency.usdt;
|
||||
const Currency ledgerCurrencyDefault = Currency.rub;
|
||||
const CurrencyCode managedCurrencyDefault = CurrencyCode.usdt;
|
||||
const CurrencyCode ledgerCurrencyDefault = CurrencyCode.rub;
|
||||
const ChainNetwork managedNetworkDefault = ChainNetwork.tronMainnet;
|
||||
|
||||
@@ -8,11 +8,9 @@ import 'package:pshared/models/currency.dart';
|
||||
import 'package:pshared/models/describable.dart';
|
||||
import 'package:pshared/models/payment/chain_network.dart';
|
||||
import 'package:pshared/models/payment/type.dart';
|
||||
import 'package:pshared/models/wallet/chain_asset.dart';
|
||||
import 'package:pshared/provider/accounts/employees.dart';
|
||||
import 'package:pshared/provider/ledger.dart';
|
||||
import 'package:pshared/provider/payment/wallets.dart';
|
||||
import 'package:pshared/utils/currency.dart';
|
||||
|
||||
import 'package:pweb/pages/dashboard/buttons/balance/add/form.dart';
|
||||
import 'package:pweb/pages/dashboard/buttons/balance/add/constants.dart';
|
||||
@@ -42,9 +40,9 @@ class _AddBalanceDialogState extends State<AddBalanceDialog> {
|
||||
|
||||
PaymentType _assetType = PaymentType.managedWallet;
|
||||
String? _ownerRef;
|
||||
Currency _managedCurrency = managedCurrencyDefault;
|
||||
CurrencyCode _managedCurrency = managedCurrencyDefault;
|
||||
ChainNetwork _network = managedNetworkDefault;
|
||||
Currency _ledgerCurrency = ledgerCurrencyDefault;
|
||||
CurrencyCode _ledgerCurrency = ledgerCurrencyDefault;
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
@@ -60,7 +58,7 @@ class _AddBalanceDialogState extends State<AddBalanceDialog> {
|
||||
|
||||
void _setOwnerRef(String? value) => setState(() => _ownerRef = value);
|
||||
|
||||
void _setManagedCurrency(Currency? value) {
|
||||
void _setManagedCurrency(CurrencyCode? value) {
|
||||
if (value == null) return;
|
||||
setState(() => _managedCurrency = value);
|
||||
}
|
||||
@@ -70,7 +68,7 @@ class _AddBalanceDialogState extends State<AddBalanceDialog> {
|
||||
setState(() => _network = value);
|
||||
}
|
||||
|
||||
void _setLedgerCurrency(Currency? value) {
|
||||
void _setLedgerCurrency(CurrencyCode? value) {
|
||||
if (value == null) return;
|
||||
setState(() => _ledgerCurrency = value);
|
||||
}
|
||||
@@ -102,7 +100,8 @@ class _AddBalanceDialogState extends State<AddBalanceDialog> {
|
||||
if (_assetType == PaymentType.managedWallet) {
|
||||
await context.read<WalletsProvider>().create(
|
||||
describable: newDescribable(name: name, description: description),
|
||||
asset: ChainAsset(chain: _network, tokenSymbol: currencyCodeToString(_managedCurrency)),
|
||||
chain: _network,
|
||||
currency: _managedCurrency,
|
||||
ownerRef: owner?.id,
|
||||
);
|
||||
} else {
|
||||
|
||||
@@ -23,12 +23,12 @@ class AddBalanceForm extends StatelessWidget {
|
||||
final ValueChanged<String?> onOwnerChanged;
|
||||
final TextEditingController nameController;
|
||||
final TextEditingController descriptionController;
|
||||
final Currency managedCurrency;
|
||||
final CurrencyCode managedCurrency;
|
||||
final ChainNetwork network;
|
||||
final Currency ledgerCurrency;
|
||||
final ValueChanged<Currency?> onManagedCurrencyChanged;
|
||||
final CurrencyCode ledgerCurrency;
|
||||
final ValueChanged<CurrencyCode?> onManagedCurrencyChanged;
|
||||
final ValueChanged<ChainNetwork?> onNetworkChanged;
|
||||
final ValueChanged<Currency?> onLedgerCurrencyChanged;
|
||||
final ValueChanged<CurrencyCode?> onLedgerCurrencyChanged;
|
||||
final bool showEmployeesLoading;
|
||||
|
||||
const AddBalanceForm({
|
||||
|
||||
@@ -4,7 +4,7 @@ import 'package:pshared/models/currency.dart';
|
||||
import 'package:pshared/utils/currency.dart';
|
||||
|
||||
|
||||
DropdownMenuItem<Currency> currencyItem(Currency currency) => DropdownMenuItem(
|
||||
DropdownMenuItem<CurrencyCode> currencyItem(CurrencyCode currency) => DropdownMenuItem(
|
||||
value: currency,
|
||||
child: Text(currencyCodeToString(currency)),
|
||||
);
|
||||
@@ -10,8 +10,8 @@ import 'package:pweb/generated/i18n/app_localizations.dart';
|
||||
|
||||
|
||||
class LedgerFields extends StatelessWidget {
|
||||
final Currency currency;
|
||||
final ValueChanged<Currency?>? onCurrencyChanged;
|
||||
final CurrencyCode currency;
|
||||
final ValueChanged<CurrencyCode?>? onCurrencyChanged;
|
||||
|
||||
const LedgerFields({
|
||||
super.key,
|
||||
@@ -20,7 +20,7 @@ class LedgerFields extends StatelessWidget {
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) => DropdownButtonFormField<Currency>(
|
||||
Widget build(BuildContext context) => DropdownButtonFormField<CurrencyCode>(
|
||||
initialValue: currency,
|
||||
decoration: getInputDecoration(context, AppLocalizations.of(context)!.currency, true),
|
||||
items: [
|
||||
|
||||
@@ -12,9 +12,9 @@ import 'package:pweb/generated/i18n/app_localizations.dart';
|
||||
|
||||
|
||||
class ManagedWalletFields extends StatelessWidget {
|
||||
final Currency currency;
|
||||
final CurrencyCode currency;
|
||||
final ChainNetwork network;
|
||||
final ValueChanged<Currency?>? onCurrencyChanged;
|
||||
final ValueChanged<CurrencyCode?>? onCurrencyChanged;
|
||||
final ValueChanged<ChainNetwork?>? onNetworkChanged;
|
||||
|
||||
const ManagedWalletFields({
|
||||
@@ -31,7 +31,7 @@ class ManagedWalletFields extends StatelessWidget {
|
||||
return Column(
|
||||
spacing: 12,
|
||||
children: [
|
||||
DropdownButtonFormField<Currency>(
|
||||
DropdownButtonFormField<CurrencyCode>(
|
||||
initialValue: currency,
|
||||
decoration: getInputDecoration(context, l10n.currency, true),
|
||||
items: [
|
||||
|
||||
@@ -3,7 +3,6 @@ import 'package:flutter/material.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
import 'package:pshared/controllers/balance_mask/wallets.dart';
|
||||
import 'package:pshared/models/money.dart';
|
||||
import 'package:pshared/models/payment/wallet.dart';
|
||||
import 'package:pshared/utils/currency.dart';
|
||||
|
||||
@@ -28,12 +27,10 @@ class BalanceAmount extends StatelessWidget {
|
||||
final textTheme = Theme.of(context).textTheme;
|
||||
final colorScheme = Theme.of(context).colorScheme;
|
||||
final currencyBalance = currencyCodeToSymbol(wallet.currency);
|
||||
final formattedBalance = formatMoneyUi(
|
||||
final formattedBalance = formatAmountUi(
|
||||
context,
|
||||
Money(
|
||||
amount: amountToString(wallet.balance),
|
||||
currency: currencyCodeToString(wallet.currency),
|
||||
),
|
||||
amount: wallet.balance,
|
||||
currency: currencyCodeToString(wallet.currency),
|
||||
);
|
||||
final wallets = context.watch<WalletsController>();
|
||||
final isMasked = wallets.isBalanceMasked(wallet.id);
|
||||
|
||||
@@ -36,9 +36,7 @@ class PaymentAmountField extends StatelessWidget {
|
||||
decoration: InputDecoration(
|
||||
labelText: loc.amount,
|
||||
border: const OutlineInputBorder(),
|
||||
prefixText: symbol == null
|
||||
? null
|
||||
: withTrailingNonBreakingSpace(symbol),
|
||||
prefixText: symbol == null ? null : '$symbol ',
|
||||
),
|
||||
onChanged: ui.handleChanged,
|
||||
),
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'package:pshared/utils/currency.dart';
|
||||
|
||||
import 'package:pweb/controllers/payouts/multiple_payouts.dart';
|
||||
import 'package:pweb/models/dashboard/summary_values.dart';
|
||||
import 'package:pweb/pages/dashboard/payouts/summary/widget.dart';
|
||||
@@ -28,21 +26,12 @@ class SourceQuoteSummary extends StatelessWidget {
|
||||
values: PaymentSummaryValues(
|
||||
fee: controller.aggregateFeeAmount == null
|
||||
? l10n.noFee
|
||||
: formatMoneyUiWithL10n(
|
||||
l10n,
|
||||
controller.aggregateFeeAmount,
|
||||
separator: nonBreakingSpace,
|
||||
),
|
||||
recipientReceives: formatMoneyUiWithL10n(
|
||||
l10n,
|
||||
: formatMoneyUi(context, controller.aggregateFeeAmount),
|
||||
recipientReceives: formatMoneyUi(
|
||||
context,
|
||||
controller.aggregateSettlementAmount,
|
||||
separator: nonBreakingSpace,
|
||||
),
|
||||
total: formatMoneyUiWithL10n(
|
||||
l10n,
|
||||
controller.aggregateDebitAmount,
|
||||
separator: nonBreakingSpace,
|
||||
),
|
||||
total: formatMoneyUi(context, controller.aggregateDebitAmount),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -19,7 +19,10 @@ class UploadHistorySection extends StatelessWidget {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return ChangeNotifierProxyProvider<PaymentsProvider, RecentPaymentsController>(
|
||||
return ChangeNotifierProxyProvider<
|
||||
PaymentsProvider,
|
||||
RecentPaymentsController
|
||||
>(
|
||||
create: (_) => RecentPaymentsController(),
|
||||
update: (_, payments, controller) => controller!..update(payments),
|
||||
child: const _RecentPaymentsView(),
|
||||
|
||||
@@ -8,7 +8,6 @@ import 'package:pweb/pages/dashboard/payouts/summary/row.dart';
|
||||
|
||||
import 'package:pweb/generated/i18n/app_localizations.dart';
|
||||
|
||||
|
||||
class PaymentFeeRow extends StatelessWidget {
|
||||
const PaymentFeeRow({super.key});
|
||||
|
||||
@@ -19,7 +18,7 @@ class PaymentFeeRow extends StatelessWidget {
|
||||
final l10 = AppLocalizations.of(context)!;
|
||||
return PaymentSummaryRow(
|
||||
labelFactory: l10.fee,
|
||||
asset: fee,
|
||||
money: fee,
|
||||
value: fee == null ? l10.noFee : null,
|
||||
style: Theme.of(context).textTheme.titleMedium,
|
||||
);
|
||||
|
||||
@@ -8,7 +8,6 @@ import 'package:pweb/pages/dashboard/payouts/summary/row.dart';
|
||||
|
||||
import 'package:pweb/generated/i18n/app_localizations.dart';
|
||||
|
||||
|
||||
class PaymentRecipientReceivesRow extends StatelessWidget {
|
||||
const PaymentRecipientReceivesRow({super.key});
|
||||
|
||||
@@ -16,7 +15,7 @@ class PaymentRecipientReceivesRow extends StatelessWidget {
|
||||
Widget build(BuildContext context) => Consumer<QuotationProvider>(
|
||||
builder: (context, provider, _) => PaymentSummaryRow(
|
||||
labelFactory: AppLocalizations.of(context)!.recipientWillReceive,
|
||||
asset: provider.recipientGets,
|
||||
money: provider.recipientGets,
|
||||
style: Theme.of(context).textTheme.titleMedium,
|
||||
),
|
||||
);
|
||||
|
||||
@@ -1,27 +1,25 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'package:pshared/models/asset.dart';
|
||||
import 'package:money2/money2.dart';
|
||||
|
||||
import 'package:pweb/utils/money_display.dart';
|
||||
|
||||
|
||||
class PaymentSummaryRow extends StatelessWidget {
|
||||
final String Function(String) labelFactory;
|
||||
final Asset? asset;
|
||||
final Money? money;
|
||||
final String? value;
|
||||
final TextStyle? style;
|
||||
|
||||
const PaymentSummaryRow({
|
||||
super.key,
|
||||
required this.labelFactory,
|
||||
required this.asset,
|
||||
required this.money,
|
||||
this.value,
|
||||
this.style,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final formatted = value ?? formatAssetUi(context, asset);
|
||||
final formatted = value ?? formatMoneyUi(context, money);
|
||||
return Text(labelFactory(formatted), style: style);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,7 +8,6 @@ import 'package:pweb/pages/dashboard/payouts/summary/row.dart';
|
||||
|
||||
import 'package:pweb/generated/i18n/app_localizations.dart';
|
||||
|
||||
|
||||
class PaymentTotalRow extends StatelessWidget {
|
||||
const PaymentTotalRow({super.key});
|
||||
|
||||
@@ -16,8 +15,10 @@ class PaymentTotalRow extends StatelessWidget {
|
||||
Widget build(BuildContext context) => Consumer<QuotationProvider>(
|
||||
builder: (context, provider, _) => PaymentSummaryRow(
|
||||
labelFactory: AppLocalizations.of(context)!.total,
|
||||
asset: provider.total,
|
||||
style: Theme.of(context).textTheme.titleMedium!.copyWith(fontWeight: FontWeight.w600),
|
||||
money: provider.total,
|
||||
style: Theme.of(
|
||||
context,
|
||||
).textTheme.titleMedium!.copyWith(fontWeight: FontWeight.w600),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -8,16 +8,11 @@ import 'package:pweb/pages/dashboard/payouts/summary/total.dart';
|
||||
|
||||
import 'package:pweb/generated/i18n/app_localizations.dart';
|
||||
|
||||
|
||||
class PaymentSummary extends StatelessWidget {
|
||||
final double spacing;
|
||||
final PaymentSummaryValues? values;
|
||||
|
||||
const PaymentSummary({
|
||||
super.key,
|
||||
required this.spacing,
|
||||
this.values,
|
||||
});
|
||||
const PaymentSummary({super.key, required this.spacing, this.values});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
@@ -32,20 +27,20 @@ class PaymentSummary extends StatelessWidget {
|
||||
children: [
|
||||
PaymentSummaryRow(
|
||||
labelFactory: loc.fee,
|
||||
asset: null,
|
||||
money: null,
|
||||
value: resolvedValues.fee,
|
||||
style: theme.textTheme.titleMedium,
|
||||
),
|
||||
PaymentSummaryRow(
|
||||
labelFactory: loc.recipientWillReceive,
|
||||
asset: null,
|
||||
money: null,
|
||||
value: resolvedValues.recipientReceives,
|
||||
style: theme.textTheme.titleMedium,
|
||||
),
|
||||
SizedBox(height: spacing),
|
||||
PaymentSummaryRow(
|
||||
labelFactory: loc.total,
|
||||
asset: null,
|
||||
money: null,
|
||||
value: resolvedValues.total,
|
||||
style: theme.textTheme.titleMedium?.copyWith(
|
||||
fontWeight: FontWeight.w600,
|
||||
@@ -69,4 +64,4 @@ class PaymentSummary extends StatelessWidget {
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,11 +3,11 @@ import 'package:flutter/material.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
import 'package:pshared/controllers/balance_mask/wallets.dart';
|
||||
import 'package:pshared/utils/currency.dart';
|
||||
import 'package:pshared/models/payment/wallet.dart';
|
||||
|
||||
import 'package:pweb/models/state/visibility.dart';
|
||||
import 'package:pweb/pages/dashboard/buttons/balance/amount.dart';
|
||||
import 'package:pweb/pages/payout_page/wallet/currency_symbol_avatar.dart';
|
||||
import 'package:pweb/widgets/refresh_balance/wallet.dart';
|
||||
|
||||
import 'package:pweb/generated/i18n/app_localizations.dart';
|
||||
@@ -22,7 +22,7 @@ class WalletCard extends StatelessWidget {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final theme = Theme.of(context);
|
||||
|
||||
|
||||
return Card(
|
||||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12)),
|
||||
elevation: theme.cardTheme.elevation ?? 4,
|
||||
@@ -35,10 +35,7 @@ class WalletCard extends StatelessWidget {
|
||||
child: Row(
|
||||
spacing: 3,
|
||||
children: [
|
||||
CircleAvatar(
|
||||
radius: 24,
|
||||
child: Icon(iconForCurrencyType(wallet.currency), size: 28),
|
||||
),
|
||||
CurrencySymbolAvatar(wallet: wallet),
|
||||
const SizedBox(width: 16),
|
||||
Expanded(
|
||||
child: Column(
|
||||
@@ -51,7 +48,9 @@ class WalletCard extends StatelessWidget {
|
||||
BalanceAmount(
|
||||
wallet: wallet,
|
||||
onToggleMask: () {
|
||||
context.read<WalletsController>().toggleBalanceMask(wallet.id);
|
||||
context.read<WalletsController>().toggleBalanceMask(
|
||||
wallet.id,
|
||||
);
|
||||
},
|
||||
),
|
||||
WalletBalanceRefreshButton(
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'package:pshared/models/payment/wallet.dart';
|
||||
import 'package:pshared/utils/currency.dart';
|
||||
|
||||
|
||||
class CurrencySymbolAvatar extends StatelessWidget {
|
||||
final Wallet wallet;
|
||||
|
||||
const CurrencySymbolAvatar({super.key, required this.wallet});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final code = currencyCodeToString(wallet.currency);
|
||||
final symbol = currencySymbolFromCode(code) ?? code;
|
||||
final textTheme = Theme.of(context).textTheme;
|
||||
|
||||
return CircleAvatar(
|
||||
radius: 24,
|
||||
child: Text(
|
||||
symbol,
|
||||
style: textTheme.titleLarge?.copyWith(fontWeight: FontWeight.w700),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -17,14 +17,10 @@ class LedgerBalanceFormatter {
|
||||
final currency = account.currency.trim();
|
||||
if (currency.isEmpty) return '••••';
|
||||
|
||||
try {
|
||||
final symbol = currencyCodeToSymbol(currencyStringToCode(currency));
|
||||
if (symbol.trim().isEmpty) {
|
||||
return '•••• $currency';
|
||||
}
|
||||
return '•••• $symbol';
|
||||
} catch (_) {
|
||||
final symbol = currencySymbolFromCode(currency);
|
||||
if (symbol == null || symbol.trim().isEmpty) {
|
||||
return '•••• $currency';
|
||||
}
|
||||
return '•••• $symbol';
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,96 +0,0 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'package:pshared/models/payment/status.dart';
|
||||
import 'package:pshared/utils/localization.dart';
|
||||
|
||||
import 'package:pweb/models/wallet/wallet_transaction.dart';
|
||||
import 'package:pweb/controllers/operations/wallet_transactions.dart';
|
||||
|
||||
import 'package:pweb/generated/i18n/app_localizations.dart';
|
||||
|
||||
|
||||
class WalletHistoryFilters extends StatelessWidget {
|
||||
final WalletTransactionsController provider;
|
||||
final VoidCallback onPickRange;
|
||||
|
||||
const WalletHistoryFilters({
|
||||
super.key,
|
||||
required this.provider,
|
||||
required this.onPickRange,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final theme = Theme.of(context);
|
||||
final loc = AppLocalizations.of(context)!;
|
||||
|
||||
return Card(
|
||||
elevation: 2,
|
||||
color: theme.colorScheme.onSecondary,
|
||||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12)),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(16),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Text(
|
||||
loc.walletActivity,
|
||||
style: theme.textTheme.titleMedium,
|
||||
),
|
||||
if (provider.hasFilters)
|
||||
TextButton(
|
||||
onPressed: provider.resetFilters,
|
||||
child: Text(loc.reset),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
Wrap(
|
||||
spacing: 8,
|
||||
runSpacing: 8,
|
||||
children: WalletTransactionType.values.map((type) {
|
||||
final isSelected = provider.selectedTypes.contains(type);
|
||||
return FilterChip(
|
||||
label: Text(type.label(context)),
|
||||
selected: isSelected,
|
||||
onSelected: (_) => provider.toggleType(type),
|
||||
pressElevation: 0,
|
||||
);
|
||||
}).toList(),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
Wrap(
|
||||
spacing: 8,
|
||||
runSpacing: 8,
|
||||
children: OperationStatus.values.map((status) {
|
||||
final isSelected = provider.selectedStatuses.contains(status);
|
||||
return FilterChip(
|
||||
label: Text(status.localized(context)),
|
||||
selected: isSelected,
|
||||
onSelected: (_) => provider.toggleStatus(status),
|
||||
pressElevation: 0,
|
||||
);
|
||||
}).toList(),
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
Align(
|
||||
alignment: Alignment.centerRight,
|
||||
child: OutlinedButton.icon(
|
||||
onPressed: onPickRange,
|
||||
icon: const Icon(Icons.date_range_outlined),
|
||||
label: Text(
|
||||
provider.dateRange == null
|
||||
? loc.selectPeriod
|
||||
: '${dateToLocalFormat(context, provider.dateRange!.start)} – ${dateToLocalFormat(context, provider.dateRange!.end)}',
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -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';
|
||||
@@ -39,13 +37,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