mirror of
https://github.com/cake-tech/cake_wallet.git
synced 2025-06-28 12:29:51 +00:00
* - enabled development options in CI builds. - Implemented caching for account retrieval. - refactor transaction handling in `dashboard_view_model.dart` to improve efficiency and reduce unnecessary updates in xmr. - `DevMoneroCallProfilerPage`, for profiling performance of xmr,wow,zano wallet calls. * use FeatureFlag.hasDevOptions * prevent crashes in monero_c by using mutexes properly improve performance of _transactionDisposer remove unnecessary checks * remove logging, bring back simplified logic * update _transactionDisposer on length and confirmation of first and last transaction * address comments from review * don't throw unhandled exceptions in unawaited async code * use cached transaction list in getAllSubaddresses, fix usage of txHistoryMutex * [DNM] fix: crashes when opening wallet, performance issue when syncing and update dependencies * Revert "use cached transaction list in getAllSubaddresses, fix usage of txHistoryMutex" This reverts commit 4c4c33ac6a47603e970a6c8d940e90204525b241. * Revert "[DNM] fix: crashes when opening wallet, performance issue when syncing and update dependencies" This reverts commit d7603445ad6ae76d76bf179c34728ce242c8c610. * Revert "use cached transaction list in getAllSubaddresses, fix usage of txHistoryMutex" This reverts commit 4c4c33ac6a47603e970a6c8d940e90204525b241. * update shared_preferences * improve state management performance by not rendering multiple changes in transaction screen on a single frame * fix wallet switching
97 lines
2.5 KiB
Dart
97 lines
2.5 KiB
Dart
import 'package:cw_core/monero_amount_format.dart';
|
|
import 'package:cw_core/utils/print_verbose.dart';
|
|
import 'package:cw_monero/api/wallet_manager.dart';
|
|
import 'package:mobx/mobx.dart';
|
|
import 'package:cw_core/account.dart';
|
|
import 'package:cw_monero/api/account_list.dart' as account_list;
|
|
import 'package:monero/monero.dart' as monero;
|
|
|
|
part 'monero_account_list.g.dart';
|
|
|
|
class MoneroAccountList = MoneroAccountListBase with _$MoneroAccountList;
|
|
|
|
abstract class MoneroAccountListBase with Store {
|
|
MoneroAccountListBase()
|
|
: accounts = ObservableList<Account>(),
|
|
_isRefreshing = false,
|
|
_isUpdating = false {
|
|
refresh();
|
|
}
|
|
|
|
@observable
|
|
ObservableList<Account> accounts;
|
|
bool _isRefreshing;
|
|
bool _isUpdating;
|
|
|
|
void update() async {
|
|
if (_isUpdating) {
|
|
return;
|
|
}
|
|
|
|
try {
|
|
_isUpdating = true;
|
|
refresh();
|
|
final accounts = getAll();
|
|
|
|
if (accounts.isNotEmpty) {
|
|
this.accounts.clear();
|
|
this.accounts.addAll(accounts);
|
|
}
|
|
|
|
_isUpdating = false;
|
|
} catch (e) {
|
|
_isUpdating = false;
|
|
rethrow;
|
|
}
|
|
}
|
|
|
|
Map<int, List<Account>> _cachedAccounts = {};
|
|
|
|
List<Account> getAll() {
|
|
final allAccounts = account_list.getAllAccount();
|
|
final currentCount = allAccounts.length;
|
|
_cachedAccounts[account_list.wptr!.address] ??= [];
|
|
|
|
if (_cachedAccounts[account_list.wptr!.address]!.length == currentCount) {
|
|
return _cachedAccounts[account_list.wptr!.address]!;
|
|
}
|
|
|
|
_cachedAccounts[account_list.wptr!.address] = allAccounts.map((accountRow) {
|
|
final balance = monero.SubaddressAccountRow_getUnlockedBalance(accountRow);
|
|
|
|
return Account(
|
|
id: monero.SubaddressAccountRow_getRowId(accountRow),
|
|
label: monero.SubaddressAccountRow_getLabel(accountRow),
|
|
balance: moneroAmountToString(amount: monero.Wallet_amountFromString(balance)),
|
|
);
|
|
}).toList();
|
|
|
|
return _cachedAccounts[account_list.wptr!.address]!;
|
|
}
|
|
|
|
Future<void> addAccount({required String label}) async {
|
|
await account_list.addAccount(label: label);
|
|
update();
|
|
}
|
|
|
|
Future<void> setLabelAccount({required int accountIndex, required String label}) async {
|
|
await account_list.setLabelForAccount(accountIndex: accountIndex, label: label);
|
|
update();
|
|
}
|
|
|
|
void refresh() {
|
|
if (_isRefreshing) {
|
|
return;
|
|
}
|
|
|
|
try {
|
|
_isRefreshing = true;
|
|
account_list.refreshAccounts();
|
|
_isRefreshing = false;
|
|
} catch (e) {
|
|
_isRefreshing = false;
|
|
printV(e);
|
|
rethrow;
|
|
}
|
|
}
|
|
}
|