From c59e4dfee9916c6647807ca177e44d4bdc674ea5 Mon Sep 17 00:00:00 2001 From: Matthew Fosse Date: Mon, 6 Jan 2025 17:16:20 -0500 Subject: [PATCH] cleanup [skip ci] --- cw_monero/lib/api/wallet.dart | 9 +----- cw_monero/lib/monero_subaddress_list.dart | 37 +++++++++++----------- cw_monero/lib/monero_wallet_addresses.dart | 18 +++++------ lib/entities/background_tasks.dart | 8 +++-- 4 files changed, 34 insertions(+), 38 deletions(-) diff --git a/cw_monero/lib/api/wallet.dart b/cw_monero/lib/api/wallet.dart index 0f07a56fa..050ed2a09 100644 --- a/cw_monero/lib/api/wallet.dart +++ b/cw_monero/lib/api/wallet.dart @@ -80,16 +80,9 @@ String getSeedLegacy(String? language) { Map>> addressCache = {}; String getAddress({int accountIndex = 0, int addressIndex = 0}) { - - int count = 0; - + while (monero.Wallet_numSubaddresses(wptr!, accountIndex: accountIndex) - 1 < addressIndex) { - printV("adding subaddress"); monero.Wallet_addSubaddress(wptr!, accountIndex: accountIndex); - if (count > 10) { - throw Exception("Failed to add subaddress"); - } - count++; } addressCache[wptr!.address] ??= {}; diff --git a/cw_monero/lib/monero_subaddress_list.dart b/cw_monero/lib/monero_subaddress_list.dart index da434b075..bc6f223d7 100644 --- a/cw_monero/lib/monero_subaddress_list.dart +++ b/cw_monero/lib/monero_subaddress_list.dart @@ -37,10 +37,8 @@ abstract class MoneroSubaddressListBase with Store { subaddresses.clear(); subaddresses.addAll(getAll()); _isUpdating = false; - } catch (e, s) { + } catch (e) { _isUpdating = false; - printV("here"); - printV(s.toString()); rethrow; } } @@ -61,7 +59,7 @@ abstract class MoneroSubaddressListBase with Store { return Subaddress( id: id, address: address, - balance: (s.received / 1e12).toStringAsFixed(6), + balance: (s.received/1e12).toStringAsFixed(6), txCount: s.txCount, label: label); }).toList(); @@ -139,25 +137,26 @@ abstract class MoneroSubaddressListBase with Store { final address = s.address; final label = s.label; return Subaddress( - id: id, - address: address, - balance: (s.received / 1e12).toStringAsFixed(6), - txCount: s.txCount, - label: id == 0 && label.toLowerCase() == 'Primary account'.toLowerCase() - ? 'Primary address' - : label); - }) - .toList() - .reversed - .toList(); + id: id, + address: address, + balance: (s.received/1e12).toStringAsFixed(6), + txCount: s.txCount, + label: id == 0 && + label.toLowerCase() == 'Primary account'.toLowerCase() + ? 'Primary address' + : label); + }).toList().reversed.toList(); } Future _newSubaddress({required int accountIndex, required String label}) async { await subaddress_list.addSubaddress(accountIndex: accountIndex, label: label); - return subaddress_list.getAllSubaddresses().where((s) { - final address = s.address; - return !_usedAddresses.contains(address); - }).isNotEmpty; + return subaddress_list + .getAllSubaddresses() + .where((s) { + final address = s.address; + return !_usedAddresses.contains(address); + }) + .isNotEmpty; } } diff --git a/cw_monero/lib/monero_wallet_addresses.dart b/cw_monero/lib/monero_wallet_addresses.dart index f891d495f..2433c1ed4 100644 --- a/cw_monero/lib/monero_wallet_addresses.dart +++ b/cw_monero/lib/monero_wallet_addresses.dart @@ -85,15 +85,15 @@ abstract class MoneroWalletAddressesBase extends WalletAddresses with Store { addressesMap.clear(); addressInfos.clear(); - // accountList.accounts.forEach((account) { - // _subaddressList.update(accountIndex: account.id); - // _subaddressList.subaddresses.forEach((subaddress) { - // addressesMap[subaddress.address] = subaddress.label; - // addressInfos[account.id] ??= []; - // addressInfos[account.id]?.add(AddressInfo( - // address: subaddress.address, label: subaddress.label, accountIndex: account.id)); - // }); - // }); + accountList.accounts.forEach((account) { + _subaddressList.update(accountIndex: account.id); + _subaddressList.subaddresses.forEach((subaddress) { + addressesMap[subaddress.address] = subaddress.label; + addressInfos[account.id] ??= []; + addressInfos[account.id]?.add(AddressInfo( + address: subaddress.address, label: subaddress.label, accountIndex: account.id)); + }); + }); await saveAddressesInBox(); } catch (e, s) { diff --git a/lib/entities/background_tasks.dart b/lib/entities/background_tasks.dart index e04c224d2..5eebceae3 100644 --- a/lib/entities/background_tasks.dart +++ b/lib/entities/background_tasks.dart @@ -213,13 +213,18 @@ Future onStart(ServiceInstance service) async { .where((element) => [WalletType.monero, WalletType.wownero].contains(element.type)) .toList(); + printV("LOADING MONERO WALLETS"); + for (int i = 0; i < moneroWallets.length; i++) { final wallet = await walletLoadingService.load(moneroWallets[i].type, moneroWallets[i].name); // stop regular sync process if it's been started - await wallet.stopSync(isBackgroundSync: false); + // await wallet.stopSync(isBackgroundSync: false); + await Future.delayed(const Duration(seconds: 10)); syncingWallets.add(wallet); } + printV("MONERO WALLETS LOADED"); + // get all litecoin wallets and add them: final List litecoinWallets = walletListViewModel.wallets .where((element) => element.type == WalletType.litecoin) @@ -475,7 +480,6 @@ Future onStart(ServiceInstance service) async { // to detect if we are in the background since it's much faster _bgTimer = Timer.periodic(const Duration(seconds: 1), (timer) async { fgCount++; - printV("fgCount: $fgCount"); // we haven't been pinged in a while, so we are likely in the background: if (fgCount == 4) { setReady();