Merge pull request 'fixed default wallet balance visibility' (#302) from visibility-301 into main
Some checks failed
ci/woodpecker/push/billing_fees Pipeline was successful
ci/woodpecker/push/db Pipeline was successful
ci/woodpecker/push/bff Pipeline was successful
ci/woodpecker/push/discovery Pipeline was successful
ci/woodpecker/push/fx_ingestor Pipeline was successful
ci/woodpecker/push/frontend Pipeline was successful
ci/woodpecker/push/fx_oracle Pipeline was successful
ci/woodpecker/push/gateway_mntx Pipeline was successful
ci/woodpecker/push/gateway_chain Pipeline was successful
ci/woodpecker/push/gateway_tgsettle Pipeline was successful
ci/woodpecker/push/nats Pipeline was successful
ci/woodpecker/push/ledger Pipeline was successful
ci/woodpecker/push/notification Pipeline was successful
ci/woodpecker/push/payments_orchestrator Pipeline failed
Some checks failed
ci/woodpecker/push/billing_fees Pipeline was successful
ci/woodpecker/push/db Pipeline was successful
ci/woodpecker/push/bff Pipeline was successful
ci/woodpecker/push/discovery Pipeline was successful
ci/woodpecker/push/fx_ingestor Pipeline was successful
ci/woodpecker/push/frontend Pipeline was successful
ci/woodpecker/push/fx_oracle Pipeline was successful
ci/woodpecker/push/gateway_mntx Pipeline was successful
ci/woodpecker/push/gateway_chain Pipeline was successful
ci/woodpecker/push/gateway_tgsettle Pipeline was successful
ci/woodpecker/push/nats Pipeline was successful
ci/woodpecker/push/ledger Pipeline was successful
ci/woodpecker/push/notification Pipeline was successful
ci/woodpecker/push/payments_orchestrator Pipeline failed
Reviewed-on: #302
This commit was merged in pull request #302.
This commit is contained in:
@@ -22,7 +22,7 @@ require (
|
|||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/Microsoft/go-winio v0.6.2 // indirect
|
github.com/Microsoft/go-winio v0.6.2 // indirect
|
||||||
github.com/ProjectZKM/Ziren/crates/go-runtime/zkvm_runtime v0.0.0-20260120135015-58f41aaaee16 // indirect
|
github.com/ProjectZKM/Ziren/crates/go-runtime/zkvm_runtime v0.0.0-20260122132314-be8c717b4581 // indirect
|
||||||
github.com/beorn7/perks v1.0.1 // indirect
|
github.com/beorn7/perks v1.0.1 // indirect
|
||||||
github.com/bits-and-blooms/bitset v1.24.4 // indirect
|
github.com/bits-and-blooms/bitset v1.24.4 // indirect
|
||||||
github.com/bmatcuk/doublestar/v4 v4.9.2 // indirect
|
github.com/bmatcuk/doublestar/v4 v4.9.2 // indirect
|
||||||
|
|||||||
@@ -6,8 +6,8 @@ github.com/DataDog/zstd v1.4.5 h1:EndNeuB0l9syBZhut0wns3gV1hL8zX8LIu6ZiVHWLIQ=
|
|||||||
github.com/DataDog/zstd v1.4.5/go.mod h1:1jcaCB/ufaK+sKp1NBhlGmpz41jOoPQ35bpF36t7BBo=
|
github.com/DataDog/zstd v1.4.5/go.mod h1:1jcaCB/ufaK+sKp1NBhlGmpz41jOoPQ35bpF36t7BBo=
|
||||||
github.com/Microsoft/go-winio v0.6.2 h1:F2VQgta7ecxGYO8k3ZZz3RS8fVIXVxONVUPlNERoyfY=
|
github.com/Microsoft/go-winio v0.6.2 h1:F2VQgta7ecxGYO8k3ZZz3RS8fVIXVxONVUPlNERoyfY=
|
||||||
github.com/Microsoft/go-winio v0.6.2/go.mod h1:yd8OoFMLzJbo9gZq8j5qaps8bJ9aShtEA8Ipt1oGCvU=
|
github.com/Microsoft/go-winio v0.6.2/go.mod h1:yd8OoFMLzJbo9gZq8j5qaps8bJ9aShtEA8Ipt1oGCvU=
|
||||||
github.com/ProjectZKM/Ziren/crates/go-runtime/zkvm_runtime v0.0.0-20260120135015-58f41aaaee16 h1:zhGT51SYKfpAlhdhfHqJbNMpjT5Q0E6/31byd8yTnxY=
|
github.com/ProjectZKM/Ziren/crates/go-runtime/zkvm_runtime v0.0.0-20260122132314-be8c717b4581 h1:f3iYtltzPQL8IH3+BsIgEnHQ4iGMl/T0Gg0gloD1Kx0=
|
||||||
github.com/ProjectZKM/Ziren/crates/go-runtime/zkvm_runtime v0.0.0-20260120135015-58f41aaaee16/go.mod h1:ioLG6R+5bUSO1oeGSDxOV3FADARuMoytZCSX6MEMQkI=
|
github.com/ProjectZKM/Ziren/crates/go-runtime/zkvm_runtime v0.0.0-20260122132314-be8c717b4581/go.mod h1:ioLG6R+5bUSO1oeGSDxOV3FADARuMoytZCSX6MEMQkI=
|
||||||
github.com/VictoriaMetrics/fastcache v1.13.0 h1:AW4mheMR5Vd9FkAPUv+NH6Nhw+fmbTMGMsNAoA/+4G0=
|
github.com/VictoriaMetrics/fastcache v1.13.0 h1:AW4mheMR5Vd9FkAPUv+NH6Nhw+fmbTMGMsNAoA/+4G0=
|
||||||
github.com/VictoriaMetrics/fastcache v1.13.0/go.mod h1:hHXhl4DA2fTL2HTZDJFXWgW0LNjo6B+4aj2Wmng3TjU=
|
github.com/VictoriaMetrics/fastcache v1.13.0/go.mod h1:hHXhl4DA2fTL2HTZDJFXWgW0LNjo6B+4aj2Wmng3TjU=
|
||||||
github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
|
github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import 'package:collection/collection.dart';
|
|
||||||
|
|
||||||
import 'package:flutter/foundation.dart';
|
import 'package:flutter/foundation.dart';
|
||||||
|
|
||||||
|
import 'package:collection/collection.dart';
|
||||||
|
|
||||||
import 'package:pshared/models/payment/wallet.dart';
|
import 'package:pshared/models/payment/wallet.dart';
|
||||||
import 'package:pshared/provider/payment/wallets.dart';
|
import 'package:pshared/provider/payment/wallets.dart';
|
||||||
|
|
||||||
@@ -9,57 +9,52 @@ import 'package:pshared/provider/payment/wallets.dart';
|
|||||||
class WalletsController with ChangeNotifier {
|
class WalletsController with ChangeNotifier {
|
||||||
late WalletsProvider _wallets;
|
late WalletsProvider _wallets;
|
||||||
|
|
||||||
// If you want per-org isolation, we reset when org changes.
|
|
||||||
String? _orgRef;
|
String? _orgRef;
|
||||||
|
|
||||||
// Visibility is UI-only: store hidden wallet ids here.
|
/// UI-only: which wallets are allowed to be visible
|
||||||
final Set<String> _hiddenWalletIds = <String>{};
|
final Set<String> _visibleWalletIds = <String>{};
|
||||||
|
|
||||||
String? _selectedWalletId;
|
String? _selectedWalletId;
|
||||||
|
|
||||||
bool get isLoading => _wallets.isLoading;
|
bool get isLoading => _wallets.isLoading;
|
||||||
|
|
||||||
Exception? get error => _wallets.error;
|
Exception? get error => _wallets.error;
|
||||||
|
|
||||||
/// Inject / update dependency (use ProxyProvider).
|
|
||||||
void update(WalletsProvider wallets) {
|
void update(WalletsProvider wallets) {
|
||||||
_wallets = wallets;
|
_wallets = wallets;
|
||||||
|
|
||||||
final nextOrgRef = wallets.organizationId;
|
final nextOrgRef = wallets.organizationId;
|
||||||
final orgChanged = nextOrgRef != _orgRef;
|
final orgChanged = nextOrgRef != _orgRef;
|
||||||
|
|
||||||
if (orgChanged) {
|
if (orgChanged) {
|
||||||
_orgRef = nextOrgRef;
|
_orgRef = nextOrgRef;
|
||||||
_hiddenWalletIds.clear();
|
_visibleWalletIds.clear(); // All wallets hidden on org change
|
||||||
_selectedWalletId = null;
|
_selectedWalletId = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Prune hidden ids for wallets that no longer exist.
|
// Remove ids that no longer exist
|
||||||
final ids = wallets.wallets.map((w) => w.id).toSet();
|
final ids = wallets.wallets.map((w) => w.id).toSet();
|
||||||
final beforeHiddenLen = _hiddenWalletIds.length;
|
_visibleWalletIds.removeWhere((id) => !ids.contains(id));
|
||||||
_hiddenWalletIds.removeWhere((id) => !ids.contains(id));
|
|
||||||
|
|
||||||
// Ensure selection is valid.
|
|
||||||
final beforeSelected = _selectedWalletId;
|
final beforeSelected = _selectedWalletId;
|
||||||
|
|
||||||
_selectedWalletId = _resolveSelectedId(
|
_selectedWalletId = _resolveSelectedId(
|
||||||
currentId: _selectedWalletId,
|
currentId: _selectedWalletId,
|
||||||
wallets: wallets.wallets,
|
wallets: wallets.wallets,
|
||||||
hiddenIds: _hiddenWalletIds,
|
visibleIds: _visibleWalletIds,
|
||||||
);
|
);
|
||||||
|
|
||||||
final selectionChanged = beforeSelected != _selectedWalletId;
|
if (beforeSelected != _selectedWalletId || orgChanged) {
|
||||||
final hiddenChanged = beforeHiddenLen != _hiddenWalletIds.length;
|
|
||||||
|
|
||||||
if (orgChanged || selectionChanged || hiddenChanged) {
|
|
||||||
notifyListeners();
|
notifyListeners();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
List<Wallet> get wallets => _wallets.wallets;
|
List<Wallet> get wallets => _wallets.wallets;
|
||||||
|
|
||||||
bool isHidden(String walletId) => _hiddenWalletIds.contains(walletId);
|
bool isVisible(String walletId) => _visibleWalletIds.contains(walletId);
|
||||||
|
bool isHidden(String walletId) => !isVisible(walletId);
|
||||||
|
|
||||||
List<Wallet> get visibleWallets =>
|
List<Wallet> get visibleWallets =>
|
||||||
wallets.where((w) => !_hiddenWalletIds.contains(w.id)).toList(growable: false);
|
wallets.where((w) => _visibleWalletIds.contains(w.id)).toList(growable: false);
|
||||||
|
|
||||||
Wallet? get selectedWallet {
|
Wallet? get selectedWallet {
|
||||||
final id = _selectedWalletId;
|
final id = _selectedWalletId;
|
||||||
@@ -74,56 +69,59 @@ class WalletsController with ChangeNotifier {
|
|||||||
void selectWalletId(String walletId) {
|
void selectWalletId(String walletId) {
|
||||||
if (_selectedWalletId == walletId) return;
|
if (_selectedWalletId == walletId) return;
|
||||||
|
|
||||||
// Allow selecting hidden wallet if you want; if not, block it:
|
// Prevent selecting a hidden wallet
|
||||||
// if (isHidden(walletId)) return;
|
if (!_visibleWalletIds.contains(walletId)) return;
|
||||||
|
|
||||||
_selectedWalletId = walletId;
|
_selectedWalletId = walletId;
|
||||||
notifyListeners();
|
notifyListeners();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Toggle wallet visibility
|
||||||
void toggleVisibility(String walletId) {
|
void toggleVisibility(String walletId) {
|
||||||
final existed = _hiddenWalletIds.remove(walletId);
|
final existed = _visibleWalletIds.remove(walletId);
|
||||||
if (!existed) _hiddenWalletIds.add(walletId);
|
if (!existed) _visibleWalletIds.add(walletId);
|
||||||
|
|
||||||
// If we hid the selected wallet, move selection to next visible.
|
|
||||||
_selectedWalletId = _resolveSelectedId(
|
_selectedWalletId = _resolveSelectedId(
|
||||||
currentId: _selectedWalletId,
|
currentId: _selectedWalletId,
|
||||||
wallets: wallets,
|
wallets: wallets,
|
||||||
hiddenIds: _hiddenWalletIds,
|
visibleIds: _visibleWalletIds,
|
||||||
);
|
);
|
||||||
|
|
||||||
notifyListeners();
|
notifyListeners();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Show all wallets (bulk action)
|
||||||
void showAll() {
|
void showAll() {
|
||||||
if (_hiddenWalletIds.isEmpty) return;
|
final allIds = wallets.map((w) => w.id);
|
||||||
_hiddenWalletIds.clear();
|
_visibleWalletIds
|
||||||
|
..clear()
|
||||||
|
..addAll(allIds);
|
||||||
|
|
||||||
_selectedWalletId = _resolveSelectedId(
|
_selectedWalletId = _resolveSelectedId(
|
||||||
currentId: _selectedWalletId,
|
currentId: _selectedWalletId,
|
||||||
wallets: wallets,
|
wallets: wallets,
|
||||||
hiddenIds: _hiddenWalletIds,
|
visibleIds: _visibleWalletIds,
|
||||||
);
|
);
|
||||||
|
|
||||||
notifyListeners();
|
notifyListeners();
|
||||||
}
|
}
|
||||||
|
|
||||||
String? _resolveSelectedId({
|
String? _resolveSelectedId({
|
||||||
required String? currentId,
|
required String? currentId,
|
||||||
required List<Wallet> wallets,
|
required List<Wallet> wallets,
|
||||||
required Set<String> hiddenIds,
|
required Set<String> visibleIds,
|
||||||
}) {
|
}) {
|
||||||
if (wallets.isEmpty) return null;
|
if (wallets.isEmpty) return null;
|
||||||
|
|
||||||
// Keep current if exists and is not hidden.
|
// Keep current selection if it still exists and is visible
|
||||||
if (currentId != null) {
|
if (currentId != null &&
|
||||||
final exists = wallets.any((w) => w.id == currentId);
|
visibleIds.contains(currentId) &&
|
||||||
if (exists && !hiddenIds.contains(currentId)) return currentId;
|
wallets.any((w) => w.id == currentId)) {
|
||||||
|
return currentId;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Pick first visible.
|
// Select the first visible wallet
|
||||||
final firstVisible = wallets.firstWhereOrNull((w) => !hiddenIds.contains(w.id));
|
final firstVisible = wallets.firstWhereOrNull((w) => visibleIds.contains(w.id));
|
||||||
if (firstVisible != null) return firstVisible.id;
|
return firstVisible?.id;
|
||||||
|
|
||||||
// All hidden: fall back to first wallet id (or return null if you prefer).
|
|
||||||
return wallets.first.id;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user