refactor of money utils with new money2 package
This commit is contained in:
@@ -1,102 +0,0 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'package:pshared/models/payment/status.dart';
|
||||
|
||||
import 'package:pweb/models/wallet/wallet_transaction.dart';
|
||||
import 'package:pweb/providers/wallet_transactions.dart';
|
||||
|
||||
|
||||
class WalletTransactionsController extends ChangeNotifier {
|
||||
List<WalletTransaction> _filteredTransactions = [];
|
||||
DateTimeRange? _dateRange;
|
||||
final Set<OperationStatus> _selectedStatuses = {};
|
||||
final Set<WalletTransactionType> _selectedTypes = {};
|
||||
WalletTransactionsProvider? _provider;
|
||||
|
||||
List<WalletTransaction> get transactions =>
|
||||
_provider?.transactions ?? const [];
|
||||
List<WalletTransaction> get filteredTransactions => _filteredTransactions;
|
||||
DateTimeRange? get dateRange => _dateRange;
|
||||
Set<OperationStatus> get selectedStatuses => _selectedStatuses;
|
||||
Set<WalletTransactionType> get selectedTypes => _selectedTypes;
|
||||
bool get isLoading => _provider?.isLoading ?? false;
|
||||
String? get error => _provider?.error;
|
||||
bool get hasFilters =>
|
||||
_dateRange != null ||
|
||||
_selectedStatuses.isNotEmpty ||
|
||||
_selectedTypes.isNotEmpty;
|
||||
|
||||
void update(WalletTransactionsProvider provider) {
|
||||
if (identical(_provider, provider)) return;
|
||||
_provider?.removeListener(_onProviderChanged);
|
||||
_provider = provider;
|
||||
_provider?.addListener(_onProviderChanged);
|
||||
_rebuildFiltered(notify: false);
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
void setDateRange(DateTimeRange? range) {
|
||||
_dateRange = range;
|
||||
_rebuildFiltered();
|
||||
}
|
||||
|
||||
void toggleStatus(OperationStatus status) {
|
||||
if (_selectedStatuses.contains(status)) {
|
||||
_selectedStatuses.remove(status);
|
||||
} else {
|
||||
_selectedStatuses.add(status);
|
||||
}
|
||||
_rebuildFiltered();
|
||||
}
|
||||
|
||||
void toggleType(WalletTransactionType type) {
|
||||
if (_selectedTypes.contains(type)) {
|
||||
_selectedTypes.remove(type);
|
||||
} else {
|
||||
_selectedTypes.add(type);
|
||||
}
|
||||
_rebuildFiltered();
|
||||
}
|
||||
|
||||
void resetFilters() {
|
||||
_dateRange = null;
|
||||
_selectedStatuses.clear();
|
||||
_selectedTypes.clear();
|
||||
_rebuildFiltered();
|
||||
}
|
||||
|
||||
void _onProviderChanged() {
|
||||
_rebuildFiltered();
|
||||
}
|
||||
|
||||
void _rebuildFiltered({bool notify = true}) {
|
||||
final source = _provider?.transactions ?? const <WalletTransaction>[];
|
||||
final activeWalletId = _provider?.walletId;
|
||||
_filteredTransactions = source.where((tx) {
|
||||
final walletMatch =
|
||||
activeWalletId == null || tx.walletId == activeWalletId;
|
||||
final statusMatch =
|
||||
_selectedStatuses.isEmpty || _selectedStatuses.contains(tx.status);
|
||||
final typeMatch =
|
||||
_selectedTypes.isEmpty || _selectedTypes.contains(tx.type);
|
||||
final dateMatch =
|
||||
_dateRange == null ||
|
||||
(tx.date.isAfter(
|
||||
_dateRange!.start.subtract(const Duration(seconds: 1)),
|
||||
) &&
|
||||
tx.date.isBefore(
|
||||
_dateRange!.end.add(const Duration(seconds: 1)),
|
||||
));
|
||||
|
||||
return walletMatch && statusMatch && typeMatch && dateMatch;
|
||||
}).toList();
|
||||
|
||||
if (notify) notifyListeners();
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_provider?.removeListener(_onProviderChanged);
|
||||
super.dispose();
|
||||
}
|
||||
}
|
||||
@@ -1,10 +1,11 @@
|
||||
import 'package:money2/money2.dart';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'package:pshared/controllers/payment/source.dart';
|
||||
import 'package:pshared/models/payment/settlement_mode.dart';
|
||||
import 'package:pshared/provider/payment/amount.dart';
|
||||
import 'package:pshared/utils/currency.dart';
|
||||
import 'package:pshared/utils/money.dart';
|
||||
|
||||
import 'package:pweb/models/payment/amount/mode.dart';
|
||||
|
||||
@@ -22,7 +23,7 @@ class PaymentAmountFieldController extends ChangeNotifier {
|
||||
|
||||
PaymentAmountFieldController({required double? initialAmount})
|
||||
: textController = TextEditingController(
|
||||
text: initialAmount == null ? '' : amountToString(initialAmount),
|
||||
text: initialAmount == null ? '' : initialAmount.toString(),
|
||||
);
|
||||
|
||||
PaymentAmountMode get mode => _mode;
|
||||
@@ -122,18 +123,14 @@ class PaymentAmountFieldController extends ChangeNotifier {
|
||||
};
|
||||
|
||||
double? _parseAmount(String value) {
|
||||
final parsed = parseMoneyAmount(
|
||||
value.replaceAll(',', '.'),
|
||||
fallback: double.nan,
|
||||
);
|
||||
return parsed.isNaN ? null : parsed;
|
||||
return double.tryParse(value.replaceAll(',', '.').trim());
|
||||
}
|
||||
|
||||
void _syncTextWithAmount(double? amount) {
|
||||
final parsedText = _parseAmount(textController.text);
|
||||
if (parsedText == amount) return;
|
||||
|
||||
final nextText = amount == null ? '' : amountToString(amount);
|
||||
final nextText = amount == null ? '' : _formatAmount(amount);
|
||||
_isSyncingText = true;
|
||||
textController.value = TextEditingValue(
|
||||
text: nextText,
|
||||
@@ -142,6 +139,12 @@ class PaymentAmountFieldController extends ChangeNotifier {
|
||||
_isSyncingText = false;
|
||||
}
|
||||
|
||||
String _formatAmount(double amount) {
|
||||
final currency = money2CurrencyFromCode(activeCurrencyCode);
|
||||
if (currency == null) return amount.toString();
|
||||
return Money.fromNumWithCurrency(amount, currency).toDecimal().toString();
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_provider?.removeListener(_handleProviderChanged);
|
||||
|
||||
@@ -29,5 +29,4 @@ class RecentPaymentsController extends ChangeNotifier {
|
||||
_recent = sortOperations(operations).take(5).toList();
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -2,8 +2,9 @@ import 'dart:async';
|
||||
|
||||
import 'package:flutter/foundation.dart';
|
||||
|
||||
import 'package:money2/money2.dart';
|
||||
|
||||
import 'package:pshared/controllers/payment/source.dart';
|
||||
import 'package:pshared/models/money.dart';
|
||||
import 'package:pshared/models/payment/asset.dart';
|
||||
import 'package:pshared/models/payment/chain_network.dart';
|
||||
import 'package:pshared/models/payment/methods/data.dart';
|
||||
@@ -17,6 +18,7 @@ import 'package:pweb/models/payment/multiple_payouts/state.dart';
|
||||
import 'package:pweb/providers/multiple_payouts.dart';
|
||||
import 'package:pweb/services/payments/csv_input.dart';
|
||||
|
||||
|
||||
class MultiplePayoutsController extends ChangeNotifier {
|
||||
final CsvInputService _csvInput;
|
||||
MultiplePayoutsProvider? _provider;
|
||||
|
||||
@@ -31,10 +31,7 @@ import 'package:pweb/app/app.dart';
|
||||
import 'package:pweb/pages/invitations/widgets/list/view_model.dart';
|
||||
import 'package:pweb/app/timeago.dart';
|
||||
import 'package:pweb/providers/two_factor.dart';
|
||||
import 'package:pweb/controllers/operations/wallet_transactions.dart';
|
||||
import 'package:pweb/providers/wallet_transactions.dart';
|
||||
import 'package:pweb/services/posthog.dart';
|
||||
import 'package:pweb/services/wallet_transactions.dart';
|
||||
import 'package:pweb/providers/account.dart';
|
||||
import 'package:pweb/providers/locale.dart';
|
||||
|
||||
@@ -142,18 +139,6 @@ void main() async {
|
||||
create: (_) => WalletsController(),
|
||||
update: (_, wallets, controller) => controller!..update(wallets),
|
||||
),
|
||||
ChangeNotifierProvider(
|
||||
create: (_) => WalletTransactionsProvider(
|
||||
MockWalletTransactionsService(),
|
||||
),
|
||||
),
|
||||
ChangeNotifierProxyProvider<
|
||||
WalletTransactionsProvider,
|
||||
WalletTransactionsController
|
||||
>(
|
||||
create: (_) => WalletTransactionsController(),
|
||||
update: (_, provider, controller) => controller!..update(provider),
|
||||
),
|
||||
],
|
||||
child: const PayApp(),
|
||||
),
|
||||
|
||||
@@ -29,7 +29,7 @@ class WalletTransaction {
|
||||
final WalletTransactionType type;
|
||||
final OperationStatus status;
|
||||
final double amount;
|
||||
final Currency currency;
|
||||
final CurrencyCode currency;
|
||||
final DateTime date;
|
||||
final String description;
|
||||
final String? counterparty;
|
||||
@@ -56,7 +56,7 @@ class WalletTransaction {
|
||||
WalletTransactionType? type,
|
||||
OperationStatus? status,
|
||||
double? amount,
|
||||
Currency? currency,
|
||||
CurrencyCode? currency,
|
||||
DateTime? date,
|
||||
String? description,
|
||||
String? counterparty,
|
||||
|
||||
@@ -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';
|
||||
@@ -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(
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import 'package:flutter/foundation.dart';
|
||||
|
||||
import 'package:pshared/models/money.dart';
|
||||
import 'package:money2/money2.dart';
|
||||
|
||||
import 'package:pshared/models/payment/payment.dart';
|
||||
import 'package:pshared/models/payment/quote/quote.dart';
|
||||
import 'package:pshared/models/payment/quote/status_type.dart';
|
||||
@@ -89,14 +90,16 @@ class MultiplePayoutsProvider extends ChangeNotifier {
|
||||
Money? get requestedSentAmount {
|
||||
if (_rows.isEmpty) return null;
|
||||
const currency = 'RUB';
|
||||
final rubCurrency = money2CurrencyFromCode(currency);
|
||||
if (rubCurrency == null) return null;
|
||||
|
||||
double total = 0;
|
||||
Money? total;
|
||||
for (final row in _rows) {
|
||||
final value = parseMoneyAmount(row.amount, fallback: double.nan);
|
||||
if (value.isNaN) return null;
|
||||
total += value;
|
||||
final value = parseMoneyWithCurrency(row.amount, rubCurrency);
|
||||
if (value == null) return null;
|
||||
total = total == null ? value : total + value;
|
||||
}
|
||||
return Money(amount: amountToString(total), currency: currency);
|
||||
return total;
|
||||
}
|
||||
|
||||
Money? aggregateSettlementAmountForCurrency(String? sourceCurrencyCode) {
|
||||
@@ -118,11 +121,11 @@ class MultiplePayoutsProvider extends ChangeNotifier {
|
||||
final fee = aggregateFeeAmountForCurrency(sourceCurrencyCode);
|
||||
if (debit == null || fee == null) return null;
|
||||
|
||||
final debitValue = parseMoneyAmount(debit.amount, fallback: double.nan);
|
||||
final feeValue = parseMoneyAmount(fee.amount, fallback: double.nan);
|
||||
if (debit.currency.toUpperCase() != fee.currency.toUpperCase()) return null;
|
||||
if (debitValue.isNaN || feeValue.isNaN || debitValue <= 0) return null;
|
||||
return (feeValue / debitValue) * 100;
|
||||
final debitValue = debit;
|
||||
final feeValue = fee;
|
||||
if (debitValue.currency.isoCode != feeValue.currency.isoCode) return null;
|
||||
if (!debitValue.isPositive) return null;
|
||||
return (feeValue.toDecimal() / debitValue.toDecimal()).toDouble() * 100;
|
||||
}
|
||||
|
||||
Future<void> quoteFromCsv({
|
||||
@@ -279,8 +282,8 @@ class MultiplePayoutsProvider extends ChangeNotifier {
|
||||
final sentAmount = requestedSentAmount;
|
||||
if (sentAmount == null) return null;
|
||||
return <String, String>{
|
||||
UploadMetadataKeys.amount: sentAmount.amount,
|
||||
UploadMetadataKeys.currency: sentAmount.currency,
|
||||
UploadMetadataKeys.amount: sentAmount.toDecimal().toString(),
|
||||
UploadMetadataKeys.currency: sentAmount.currency.isoCode,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -290,10 +293,12 @@ class MultiplePayoutsProvider extends ChangeNotifier {
|
||||
) {
|
||||
if (values == null || values.isEmpty) return null;
|
||||
|
||||
if (sourceCurrencyCode != null && sourceCurrencyCode.isNotEmpty) {
|
||||
final sourceCurrency = sourceCurrencyCode.trim().toUpperCase();
|
||||
final sourceCurrency =
|
||||
money2CurrencyFromCode(sourceCurrencyCode)?.isoCode ??
|
||||
sourceCurrencyCode;
|
||||
if (sourceCurrency != null) {
|
||||
for (final value in values) {
|
||||
if (value.currency.toUpperCase() == sourceCurrency) {
|
||||
if (value.currency.isoCode == sourceCurrency) {
|
||||
return value;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,48 +0,0 @@
|
||||
import 'package:flutter/foundation.dart';
|
||||
|
||||
import 'package:pweb/models/wallet/wallet_transaction.dart';
|
||||
import 'package:pweb/services/wallet_transactions.dart';
|
||||
|
||||
|
||||
class WalletTransactionsProvider extends ChangeNotifier {
|
||||
final WalletTransactionsService _service;
|
||||
|
||||
WalletTransactionsProvider(this._service);
|
||||
|
||||
List<WalletTransaction> _transactions = const [];
|
||||
bool _isLoading = false;
|
||||
String? _error;
|
||||
String? _walletId;
|
||||
int _loadSeq = 0;
|
||||
|
||||
List<WalletTransaction> get transactions => List.unmodifiable(_transactions);
|
||||
bool get isLoading => _isLoading;
|
||||
String? get error => _error;
|
||||
String? get walletId => _walletId;
|
||||
|
||||
Future<void> load({String? walletId}) async {
|
||||
final targetWalletId = walletId ?? _walletId;
|
||||
final requestSeq = ++_loadSeq;
|
||||
_walletId = targetWalletId;
|
||||
_isLoading = true;
|
||||
_error = null;
|
||||
notifyListeners();
|
||||
|
||||
try {
|
||||
final fetched = await _service.fetchHistory(walletId: targetWalletId);
|
||||
if (requestSeq != _loadSeq) return;
|
||||
|
||||
_transactions = targetWalletId == null
|
||||
? fetched
|
||||
: fetched.where((tx) => tx.walletId == targetWalletId).toList();
|
||||
} catch (e) {
|
||||
if (requestSeq != _loadSeq) return;
|
||||
_error = e.toString();
|
||||
} finally {
|
||||
if (requestSeq == _loadSeq) {
|
||||
_isLoading = false;
|
||||
notifyListeners();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,109 +0,0 @@
|
||||
import 'package:pshared/models/payment/status.dart';
|
||||
import 'package:pshared/models/currency.dart';
|
||||
|
||||
import 'package:pweb/models/wallet/wallet_transaction.dart';
|
||||
|
||||
|
||||
abstract class WalletTransactionsService {
|
||||
Future<List<WalletTransaction>> fetchHistory({String? walletId});
|
||||
}
|
||||
|
||||
class MockWalletTransactionsService implements WalletTransactionsService {
|
||||
final List<WalletTransaction> _history = [
|
||||
WalletTransaction(
|
||||
id: 'wt-001',
|
||||
walletId: '1124',
|
||||
type: WalletTransactionType.topUp,
|
||||
status: OperationStatus.success,
|
||||
amount: 150000,
|
||||
currency: Currency.rub,
|
||||
date: DateTime(2024, 9, 14, 10, 12),
|
||||
counterparty: 'VISA ••0019',
|
||||
description: 'Top up via corporate card',
|
||||
balanceAfter: 10150000,
|
||||
),
|
||||
WalletTransaction(
|
||||
id: 'wt-002',
|
||||
walletId: '1124',
|
||||
type: WalletTransactionType.payout,
|
||||
status: OperationStatus.processing,
|
||||
amount: 2500,
|
||||
currency: Currency.rub,
|
||||
date: DateTime(2024, 9, 15, 12, 10),
|
||||
counterparty: 'Bank transfer RU239',
|
||||
description: 'Invoice #239 shipping',
|
||||
balanceAfter: 10147500,
|
||||
),
|
||||
WalletTransaction(
|
||||
id: 'wt-003',
|
||||
walletId: '1124',
|
||||
type: WalletTransactionType.payout,
|
||||
status: OperationStatus.error,
|
||||
amount: 1200,
|
||||
currency: Currency.rub,
|
||||
date: DateTime(2024, 9, 13, 16, 40),
|
||||
counterparty: '4000 **** 0077',
|
||||
description: 'Payout to card declined',
|
||||
balanceAfter: 10000000,
|
||||
),
|
||||
WalletTransaction(
|
||||
id: 'wt-004',
|
||||
walletId: '2124',
|
||||
type: WalletTransactionType.topUp,
|
||||
status: OperationStatus.success,
|
||||
amount: 1800,
|
||||
currency: Currency.usd,
|
||||
date: DateTime(2024, 9, 12, 9, 0),
|
||||
counterparty: 'Wire payment 8831',
|
||||
description: 'Top up via USD wire',
|
||||
balanceAfter: 4300.5,
|
||||
),
|
||||
WalletTransaction(
|
||||
id: 'wt-005',
|
||||
walletId: '2124',
|
||||
type: WalletTransactionType.payout,
|
||||
status: OperationStatus.success,
|
||||
amount: 400,
|
||||
currency: Currency.usd,
|
||||
date: DateTime(2024, 9, 16, 14, 30),
|
||||
counterparty: 'IBAN DE09••1122',
|
||||
description: 'Payout to John Snow',
|
||||
balanceAfter: 3900.5,
|
||||
),
|
||||
WalletTransaction(
|
||||
id: 'wt-006',
|
||||
walletId: '1124',
|
||||
type: WalletTransactionType.payout,
|
||||
status: OperationStatus.success,
|
||||
amount: 70000,
|
||||
currency: Currency.rub,
|
||||
date: DateTime(2024, 9, 17, 8, 45),
|
||||
counterparty: 'Payroll batch',
|
||||
description: 'Monthly reimbursements',
|
||||
balanceAfter: 10080000,
|
||||
),
|
||||
WalletTransaction(
|
||||
id: 'wt-007',
|
||||
walletId: '1124',
|
||||
type: WalletTransactionType.topUp,
|
||||
status: OperationStatus.processing,
|
||||
amount: 200000,
|
||||
currency: Currency.rub,
|
||||
date: DateTime(2024, 9, 18, 9, 30),
|
||||
counterparty: 'Bank wire RU511',
|
||||
description: 'Top up pending confirmation',
|
||||
balanceAfter: 10280000,
|
||||
),
|
||||
];
|
||||
|
||||
@override
|
||||
Future<List<WalletTransaction>> fetchHistory({String? walletId}) async {
|
||||
await Future.delayed(const Duration(milliseconds: 350));
|
||||
|
||||
final source = walletId == null
|
||||
? _history
|
||||
: _history.where((tx) => tx.walletId == walletId).toList();
|
||||
|
||||
return List<WalletTransaction>.from(source);
|
||||
}
|
||||
}
|
||||
@@ -1,96 +1,27 @@
|
||||
import 'package:flutter/widgets.dart';
|
||||
|
||||
import 'package:pshared/models/asset.dart';
|
||||
import 'package:pshared/models/money.dart';
|
||||
import 'package:money2/money2.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 formatMoneyUi(BuildContext context, Money? money) {
|
||||
final l10n = AppLocalizations.of(context)!;
|
||||
if (money == null) return l10n.valueUnavailable;
|
||||
return money.toString();
|
||||
}
|
||||
|
||||
String formatAmountUi(
|
||||
BuildContext context, {
|
||||
required double amount,
|
||||
required String currency,
|
||||
String separator = ' ',
|
||||
}) {
|
||||
return formatAmountUiWithL10n(
|
||||
AppLocalizations.of(context)!,
|
||||
amount: amount,
|
||||
currency: currency,
|
||||
separator: separator,
|
||||
);
|
||||
}
|
||||
final l10n = AppLocalizations.of(context)!;
|
||||
final moneyCurrency = money2CurrencyFromCode(currency);
|
||||
if (moneyCurrency == null) return l10n.valueUnavailable;
|
||||
|
||||
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,
|
||||
);
|
||||
final money = Money.fromNumWithCurrency(amount, moneyCurrency);
|
||||
return money.toString();
|
||||
}
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
import 'package:pshared/utils/money.dart';
|
||||
|
||||
import 'package:pweb/models/payment/multiple_payouts/csv_row.dart';
|
||||
|
||||
|
||||
@@ -82,8 +80,8 @@ class MultipleCsvParser {
|
||||
throw FormatException('CSV row ${i + 1}: amount is required');
|
||||
}
|
||||
|
||||
final parsedAmount = parseMoneyAmount(amount, fallback: double.nan);
|
||||
if (parsedAmount.isNaN || parsedAmount <= 0) {
|
||||
final parsedAmount = double.tryParse(amount);
|
||||
if (parsedAmount == null || parsedAmount <= 0) {
|
||||
throw FormatException(
|
||||
'CSV row ${i + 1}: amount must be greater than 0',
|
||||
);
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import 'package:pshared/models/money.dart';
|
||||
import 'package:pshared/models/payment/customer.dart';
|
||||
import 'package:pshared/models/payment/fees/treatment.dart';
|
||||
import 'package:pshared/models/payment/intent.dart';
|
||||
@@ -6,6 +5,7 @@ import 'package:pshared/models/payment/kind.dart';
|
||||
import 'package:pshared/models/payment/methods/card.dart';
|
||||
import 'package:pshared/models/payment/methods/data.dart';
|
||||
import 'package:pshared/models/payment/settlement_mode.dart';
|
||||
import 'package:pshared/utils/money.dart';
|
||||
import 'package:pshared/utils/payment/fx_helpers.dart';
|
||||
|
||||
import 'package:pweb/models/payment/multiple_payouts/csv_row.dart';
|
||||
@@ -30,7 +30,12 @@ class MultipleIntentBuilder {
|
||||
.map((entry) {
|
||||
final rowIndex = entry.key;
|
||||
final row = entry.value;
|
||||
final amount = Money(amount: row.amount, currency: _currency);
|
||||
final amount = parseMoneyWithCurrencyCode(row.amount, _currency);
|
||||
if (amount == null) {
|
||||
throw FormatException(
|
||||
'Invalid CSV amount at row ${rowIndex + 1}: ${row.amount}',
|
||||
);
|
||||
}
|
||||
final destination = CardPaymentMethod(
|
||||
pan: row.pan,
|
||||
firstName: row.firstName,
|
||||
|
||||
@@ -2,15 +2,14 @@ import 'package:flutter/material.dart';
|
||||
|
||||
import 'package:intl/intl.dart';
|
||||
|
||||
import 'package:pshared/models/money.dart';
|
||||
import 'package:money2/money2.dart';
|
||||
|
||||
import 'package:pshared/utils/localization.dart';
|
||||
|
||||
import 'package:pweb/utils/money_display.dart';
|
||||
|
||||
|
||||
String formatMoney(BuildContext context, Money? money) {
|
||||
if (money == null || money.amount.trim().isEmpty) {
|
||||
return unavailableMoneyValue(context);
|
||||
}
|
||||
return formatMoneyUi(context, money);
|
||||
}
|
||||
|
||||
|
||||
@@ -3,7 +3,6 @@ import 'package:pshared/models/payment/operation.dart';
|
||||
import 'package:pshared/models/payment/payment.dart';
|
||||
import 'package:pshared/models/payment/state.dart';
|
||||
import 'package:pshared/models/payment/status.dart';
|
||||
import 'package:pshared/utils/money.dart';
|
||||
|
||||
import 'package:pweb/utils/payment/upload_metadata.dart';
|
||||
import 'package:pweb/utils/report/operations/document_rule.dart';
|
||||
@@ -14,12 +13,12 @@ OperationItem mapPaymentToOperation(Payment payment) {
|
||||
final settlement = payment.lastQuote?.amounts?.destinationSettlement;
|
||||
final amountMoney = debit ?? settlement;
|
||||
|
||||
final amount = parseMoneyAmount(amountMoney?.amount);
|
||||
final currency = amountMoney?.currency ?? '';
|
||||
final amount = amountMoney?.toDouble() ?? 0;
|
||||
final currency = amountMoney?.currency.isoCode ?? '';
|
||||
final toAmount = settlement == null
|
||||
? amount
|
||||
: parseMoneyAmount(settlement.amount);
|
||||
final toCurrency = settlement?.currency ?? currency;
|
||||
: settlement.toDouble();
|
||||
final toCurrency = settlement?.currency.isoCode ?? currency;
|
||||
|
||||
final payId = _firstNonEmpty([payment.paymentRef]) ?? '-';
|
||||
final name =
|
||||
|
||||
@@ -1,31 +1,28 @@
|
||||
import 'package:flutter/widgets.dart';
|
||||
|
||||
import 'package:pshared/models/ledger/account.dart';
|
||||
import 'package:pshared/models/money.dart';
|
||||
import 'package:pshared/models/payment/wallet.dart';
|
||||
import 'package:pshared/utils/currency.dart';
|
||||
import 'package:pshared/utils/money.dart';
|
||||
|
||||
import 'package:pweb/utils/money_display.dart';
|
||||
|
||||
|
||||
String walletBalance(BuildContext context, Wallet wallet) {
|
||||
return formatMoneyUi(
|
||||
return formatAmountUi(
|
||||
context,
|
||||
Money(
|
||||
amount: amountToString(wallet.balance),
|
||||
currency: currencyCodeToString(wallet.currency),
|
||||
),
|
||||
amount: wallet.balance,
|
||||
currency: currencyCodeToString(wallet.currency),
|
||||
);
|
||||
}
|
||||
|
||||
String ledgerBalance(BuildContext context, LedgerAccount account) {
|
||||
final money = account.balance?.balance;
|
||||
final effectiveCurrency = (money?.currency.trim().isNotEmpty ?? false)
|
||||
? money!.currency
|
||||
final effectiveCurrency = (money?.currency.isoCode.trim().isNotEmpty ?? false)
|
||||
? money!.currency.isoCode
|
||||
: account.currency;
|
||||
final effectiveMoney =
|
||||
money ?? parseMoneyWithCurrencyCode('0', effectiveCurrency);
|
||||
|
||||
return formatMoneyUi(
|
||||
context,
|
||||
Money(amount: money?.amount ?? '', currency: effectiveCurrency),
|
||||
);
|
||||
return formatMoneyUi(context, effectiveMoney);
|
||||
}
|
||||
|
||||
@@ -70,7 +70,7 @@ dependencies:
|
||||
qr_flutter: ^4.1.0
|
||||
duration: ^4.0.3
|
||||
universal_html: ^2.3.0
|
||||
|
||||
money2: ^6.3.0
|
||||
|
||||
|
||||
dev_dependencies:
|
||||
|
||||
Reference in New Issue
Block a user