redesigned payment page + a lot of fixes

This commit is contained in:
Arseni
2026-02-21 21:55:20 +03:00
parent a68aa2abff
commit 0c6fa03aba
208 changed files with 4062 additions and 2217 deletions

View File

@@ -1,7 +1,5 @@
import 'package:flutter/foundation.dart';
import 'package:collection/collection.dart';
import 'package:pshared/models/payment/wallet.dart';
import 'package:pshared/provider/payment/wallets.dart';
@@ -15,6 +13,9 @@ class WalletsController with ChangeNotifier {
final Set<String> _maskedBalanceWalletRefs = <String>{};
Set<String> _knownWalletRefs = <String>{};
List<Wallet> _walletsList = <Wallet>[];
Map<String, Wallet> _walletsById = <String, Wallet>{};
String? _selectedWalletRef;
bool get isLoading => _wallets.isLoading;
@@ -33,8 +34,11 @@ class WalletsController with ChangeNotifier {
_selectedWalletRef = null;
}
_walletsById = _uniqueWalletsById(wallets.wallets);
_walletsList = _walletsById.values.toList(growable: false);
// Remove ids that no longer exist
final ids = wallets.wallets.map((w) => w.id).toSet();
final ids = _walletsById.keys.toSet();
_maskedBalanceWalletRefs.removeWhere((id) => !ids.contains(id));
final newIds = ids.difference(_knownWalletRefs);
@@ -45,13 +49,13 @@ class WalletsController with ChangeNotifier {
_selectedWalletRef = _resolveSelectedId(
currentRef: _selectedWalletRef,
wallets: wallets.wallets,
wallets: _walletsList,
);
notifyListeners();
}
List<Wallet> get wallets => _wallets.wallets;
List<Wallet> get wallets => _walletsList;
bool isBalanceMasked(String walletRef) => _maskedBalanceWalletRefs.contains(walletRef);
bool isBalanceVisible(String walletRef) => !isBalanceMasked(walletRef);
@@ -62,7 +66,7 @@ class WalletsController with ChangeNotifier {
Wallet? get selectedWallet {
final id = _selectedWalletRef;
if (id == null) return null;
return wallets.firstWhereOrNull((w) => w.id == id);
return _walletsById[id];
}
String? get selectedWalletRef => _selectedWalletRef;
@@ -103,4 +107,12 @@ class WalletsController with ChangeNotifier {
// Fallback to the first wallet
return wallets.first.id;
}
Map<String, Wallet> _uniqueWalletsById(List<Wallet> wallets) {
final result = <String, Wallet>{};
for (final wallet in wallets) {
result.putIfAbsent(wallet.id, () => wallet);
}
return result;
}
}