This commit is contained in:
Arseni
2026-03-11 18:26:21 +03:00
parent fdd8dd8845
commit 0172176978
46 changed files with 678 additions and 643 deletions

View File

@@ -1,31 +1,31 @@
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(Wallet wallet) {
final symbol = currencyCodeToSymbol(wallet.currency);
return '$symbol ${amountToString(wallet.balance)}';
String walletBalance(BuildContext context, Wallet wallet) {
return formatMoneyUi(
context,
Money(
amount: amountToString(wallet.balance),
currency: currencyCodeToString(wallet.currency),
),
);
}
String ledgerBalance(LedgerAccount account) {
String ledgerBalance(BuildContext context, LedgerAccount account) {
final money = account.balance?.balance;
final rawAmount = money?.amount.trim();
final amount = parseMoneyAmount(rawAmount, fallback: double.nan);
final amountText = amount.isNaN
? (rawAmount == null || rawAmount.isEmpty ? '--' : rawAmount)
: amountToString(amount);
final effectiveCurrency = (money?.currency.trim().isNotEmpty ?? false)
? money!.currency
: account.currency;
final currencyCode = (money?.currency ?? account.currency)
.trim()
.toUpperCase();
final symbol = currencySymbolFromCode(currencyCode);
if (symbol != null && symbol.trim().isNotEmpty) {
return '$symbol $amountText';
}
if (currencyCode.isNotEmpty) {
return '$amountText $currencyCode';
}
return amountText;
return formatMoneyUi(
context,
Money(amount: money?.amount ?? '', currency: effectiveCurrency),
);
}

View File

@@ -11,6 +11,7 @@ import 'package:pweb/generated/i18n/app_localizations.dart';
List<DropdownMenuItem<SourceOptionKey>> buildSourceSelectorItems({
required BuildContext context,
required List<Wallet> wallets,
required List<LedgerAccount> ledgerAccounts,
required AppLocalizations l10n,
@@ -20,7 +21,7 @@ List<DropdownMenuItem<SourceOptionKey>> buildSourceSelectorItems({
return DropdownMenuItem<SourceOptionKey>(
value: walletOptionKey(wallet.id),
child: Text(
'${walletDisplayName(wallet, l10n)} - ${walletBalance(wallet)}',
'${walletDisplayName(wallet, l10n)} - ${walletBalance(context, wallet)}',
overflow: TextOverflow.ellipsis,
),
);
@@ -29,7 +30,7 @@ List<DropdownMenuItem<SourceOptionKey>> buildSourceSelectorItems({
return DropdownMenuItem<SourceOptionKey>(
value: ledgerOptionKey(ledger.ledgerAccountRef),
child: Text(
'${ledgerDisplayName(ledger, l10n)} - ${ledgerBalance(ledger)}',
'${ledgerDisplayName(ledger, l10n)} - ${ledgerBalance(context, ledger)}',
overflow: TextOverflow.ellipsis,
),
);

View File

@@ -25,6 +25,7 @@ Widget buildSourceSelectorField({
}
final items = buildSourceSelectorItems(
context: context,
wallets: wallets,
ledgerAccounts: ledgerAccounts,
l10n: l10n,