ledger top up functionality and few small fixes for project architechture and design
This commit is contained in:
@@ -3,7 +3,8 @@ import 'package:flutter/foundation.dart';
|
||||
import 'package:pshared/controllers/balance_mask/wallets.dart';
|
||||
import 'package:pshared/provider/ledger.dart';
|
||||
|
||||
import 'package:pweb/pages/dashboard/buttons/balance/balance_item.dart';
|
||||
import 'package:pweb/models/dashboard/balance_item.dart';
|
||||
|
||||
|
||||
class BalanceCarouselController with ChangeNotifier {
|
||||
WalletsController? _walletsController;
|
||||
@@ -73,14 +74,19 @@ class BalanceCarouselController with ChangeNotifier {
|
||||
String? _currentWalletRef(List<BalanceItem> items, int index) {
|
||||
if (items.isEmpty || index < 0 || index >= items.length) return null;
|
||||
final current = items[index];
|
||||
if (!current.isWallet) return null;
|
||||
return current.wallet?.id;
|
||||
return switch (current) {
|
||||
WalletBalanceItem(:final wallet) => wallet.id,
|
||||
_ => null,
|
||||
};
|
||||
}
|
||||
|
||||
int? _walletIndexByRef(List<BalanceItem> items, String? walletRef) {
|
||||
if (walletRef == null || walletRef.isEmpty) return null;
|
||||
final idx = items.indexWhere(
|
||||
(item) => item.isWallet && item.wallet?.id == walletRef,
|
||||
(item) => switch (item) {
|
||||
WalletBalanceItem(:final wallet) => wallet.id == walletRef,
|
||||
_ => false,
|
||||
},
|
||||
);
|
||||
if (idx < 0) return null;
|
||||
return idx;
|
||||
@@ -97,17 +103,17 @@ class BalanceCarouselController with ChangeNotifier {
|
||||
for (var i = 0; i < left.length; i++) {
|
||||
final a = left[i];
|
||||
final b = right[i];
|
||||
if (a.type != b.type) return false;
|
||||
if (a.runtimeType != b.runtimeType) return false;
|
||||
if (_itemIdentity(a) != _itemIdentity(b)) return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
String _itemIdentity(BalanceItem item) => switch (item.type) {
|
||||
BalanceItemType.wallet => item.wallet?.id ?? '',
|
||||
BalanceItemType.ledger => item.account?.ledgerAccountRef ?? '',
|
||||
BalanceItemType.addAction => 'add',
|
||||
String _itemIdentity(BalanceItem item) => switch (item) {
|
||||
WalletBalanceItem(:final wallet) => wallet.id,
|
||||
LedgerBalanceItem(:final account) => account.ledgerAccountRef,
|
||||
AddBalanceActionItem() => 'add',
|
||||
};
|
||||
|
||||
void _syncSelectedWallet() {
|
||||
@@ -115,9 +121,8 @@ class BalanceCarouselController with ChangeNotifier {
|
||||
if (walletsController == null || _items.isEmpty) return;
|
||||
|
||||
final current = _items[_index];
|
||||
if (!current.isWallet || current.wallet == null) return;
|
||||
|
||||
final wallet = current.wallet!;
|
||||
if (current is! WalletBalanceItem) return;
|
||||
final wallet = current.wallet;
|
||||
if (walletsController.selectedWallet?.id == wallet.id) return;
|
||||
walletsController.selectWallet(wallet);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user