[skip ci] working

This commit is contained in:
Matthew Fosse 2025-01-06 12:02:49 -05:00
parent 9f6998b72d
commit 51259a879c
3 changed files with 62 additions and 71 deletions

View file

@ -37,8 +37,10 @@ abstract class MoneroSubaddressListBase with Store {
subaddresses.clear(); subaddresses.clear();
subaddresses.addAll(getAll()); subaddresses.addAll(getAll());
_isUpdating = false; _isUpdating = false;
} catch (e) { } catch (e, s) {
_isUpdating = false; _isUpdating = false;
printV("here");
printV(s.toString());
rethrow; rethrow;
} }
} }
@ -59,7 +61,7 @@ abstract class MoneroSubaddressListBase with Store {
return Subaddress( return Subaddress(
id: id, id: id,
address: address, address: address,
balance: (s.received/1e12).toStringAsFixed(6), balance: (s.received / 1e12).toStringAsFixed(6),
txCount: s.txCount, txCount: s.txCount,
label: label); label: label);
}).toList(); }).toList();
@ -139,24 +141,23 @@ abstract class MoneroSubaddressListBase with Store {
return Subaddress( return Subaddress(
id: id, id: id,
address: address, address: address,
balance: (s.received/1e12).toStringAsFixed(6), balance: (s.received / 1e12).toStringAsFixed(6),
txCount: s.txCount, txCount: s.txCount,
label: id == 0 && label: id == 0 && label.toLowerCase() == 'Primary account'.toLowerCase()
label.toLowerCase() == 'Primary account'.toLowerCase()
? 'Primary address' ? 'Primary address'
: label); : label);
}).toList().reversed.toList(); })
.toList()
.reversed
.toList();
} }
Future<bool> _newSubaddress({required int accountIndex, required String label}) async { Future<bool> _newSubaddress({required int accountIndex, required String label}) async {
await subaddress_list.addSubaddress(accountIndex: accountIndex, label: label); await subaddress_list.addSubaddress(accountIndex: accountIndex, label: label);
return subaddress_list return subaddress_list.getAllSubaddresses().where((s) {
.getAllSubaddresses()
.where((s) {
final address = s.address; final address = s.address;
return !_usedAddresses.contains(address); return !_usedAddresses.contains(address);
}) }).isNotEmpty;
.isNotEmpty;
} }
} }

View file

@ -158,11 +158,16 @@ abstract class MoneroWalletBase
} }
} }
bool isMainThread = Isolate.current.debugName == "main";
printV("isMainThread: $isMainThread");
if (isMainThread) {
_autoSaveTimer = _autoSaveTimer =
Timer.periodic(Duration(seconds: _autoSaveInterval), (_) async => await save()); Timer.periodic(Duration(seconds: _autoSaveInterval), (_) async => await save());
// update transaction details after restore // update transaction details after restore
walletAddresses.subaddressList.update(accountIndex: walletAddresses.account?.id ?? 0); walletAddresses.subaddressList.update(accountIndex: walletAddresses.account?.id ?? 0);
} }
}
@override @override
Future<void>? updateBalance() => null; Future<void>? updateBalance() => null;
@ -198,11 +203,17 @@ abstract class MoneroWalletBase
@override @override
Future<void> startSync({bool isBackgroundSync = false}) async { Future<void> startSync({bool isBackgroundSync = false}) async {
if (isBackgroundSync) { bool isMainThread = Isolate.current.debugName == "main";
printV("isMainThread: $isMainThread");
printV(Isolate.current.debugName);
if (!isMainThread) {
try { try {
syncStatus = AttemptingSyncStatus(); syncStatus = AttemptingSyncStatus();
monero_wallet.startBackgroundSync(); monero_wallet.startBackgroundSync();
isBackgroundSyncing = true; isBackgroundSyncing = true;
_setListeners();
_listener?.start();
return; return;
} catch (e) { } catch (e) {
isBackgroundSyncing = false; isBackgroundSyncing = false;
@ -212,24 +223,6 @@ abstract class MoneroWalletBase
} }
} }
try {
_assertInitialHeight();
} catch (_) {
// our restore height wasn't correct, so lets see if using the backup works:
try {
await resetCache(name); // Resetting the cache removes the TX Keys and Polyseed
_assertInitialHeight();
} catch (e) {
// we still couldn't get a valid height from the backup?!:
// try to use the date instead:
try {
_setHeightFromDate();
} catch (_) {
// we still couldn't get a valid sync height :/
}
}
}
try { try {
syncStatus = AttemptingSyncStatus(); syncStatus = AttemptingSyncStatus();
monero_wallet.startRefresh(); monero_wallet.startRefresh();
@ -280,8 +273,8 @@ abstract class MoneroWalletBase
bool needExportOutputs(int amount) { bool needExportOutputs(int amount) {
// viewOnlyBalance - balance that we can spend // viewOnlyBalance - balance that we can spend
// TODO(mrcyjanek): remove hasUnknownKeyImages when we cleanup coin control // TODO(mrcyjanek): remove hasUnknownKeyImages when we cleanup coin control
return (monero.Wallet_viewOnlyBalance(wptr!, return (monero.Wallet_viewOnlyBalance(wptr!, accountIndex: walletAddresses.account!.id) <
accountIndex: walletAddresses.account!.id) < amount) || amount) ||
monero.Wallet_hasUnknownKeyImages(wptr!); monero.Wallet_hasUnknownKeyImages(wptr!);
} }
@ -303,8 +296,8 @@ abstract class MoneroWalletBase
final inputs = <String>[]; final inputs = <String>[];
final outputs = _credentials.outputs; final outputs = _credentials.outputs;
final hasMultiDestination = outputs.length > 1; final hasMultiDestination = outputs.length > 1;
final unlockedBalance = monero_wallet.getUnlockedBalance( final unlockedBalance =
accountIndex: walletAddresses.account!.id); monero_wallet.getUnlockedBalance(accountIndex: walletAddresses.account!.id);
PendingTransactionDescription pendingTransactionDescription; PendingTransactionDescription pendingTransactionDescription;
@ -350,10 +343,8 @@ abstract class MoneroWalletBase
preferredInputs: inputs); preferredInputs: inputs);
} else { } else {
final output = outputs.first; final output = outputs.first;
final address = final address = output.isParsedAddress ? output.extractedAddress : output.address;
output.isParsedAddress ? output.extractedAddress : output.address; final amount = output.sendAll ? null : output.cryptoAmount!.replaceAll(',', '.');
final amount =
output.sendAll ? null : output.cryptoAmount!.replaceAll(',', '.');
// if ((formattedAmount != null && unlockedBalance < formattedAmount) || // if ((formattedAmount != null && unlockedBalance < formattedAmount) ||
// (formattedAmount == null && unlockedBalance <= 0)) { // (formattedAmount == null && unlockedBalance <= 0)) {
@ -363,10 +354,8 @@ abstract class MoneroWalletBase
// 'You do not have enough unlocked balance. Unlocked: $formattedBalance. Transaction amount: ${output.cryptoAmount}.'); // 'You do not have enough unlocked balance. Unlocked: $formattedBalance. Transaction amount: ${output.cryptoAmount}.');
// } // }
if (inputs.isEmpty) MoneroTransactionCreationException( if (inputs.isEmpty) MoneroTransactionCreationException('No inputs selected');
'No inputs selected'); pendingTransactionDescription = await transaction_history.createTransaction(
pendingTransactionDescription =
await transaction_history.createTransaction(
address: address!, address: address!,
amount: amount, amount: amount,
priorityRaw: _credentials.priority.serialize(), priorityRaw: _credentials.priority.serialize(),
@ -742,8 +731,8 @@ abstract class MoneroWalletBase
Future<void> _askForUpdateTransactionHistory() async => await updateTransactions(); Future<void> _askForUpdateTransactionHistory() async => await updateTransactions();
int _getUnlockedBalance() => monero_wallet.getUnlockedBalance( int _getUnlockedBalance() =>
accountIndex: walletAddresses.account!.id); monero_wallet.getUnlockedBalance(accountIndex: walletAddresses.account!.id);
int _getFrozenBalance() { int _getFrozenBalance() {
var frozenBalance = 0; var frozenBalance = 0;

View file

@ -85,19 +85,20 @@ abstract class MoneroWalletAddressesBase extends WalletAddresses with Store {
addressesMap.clear(); addressesMap.clear();
addressInfos.clear(); addressInfos.clear();
accountList.accounts.forEach((account) { // accountList.accounts.forEach((account) {
_subaddressList.update(accountIndex: account.id); // _subaddressList.update(accountIndex: account.id);
_subaddressList.subaddresses.forEach((subaddress) { // _subaddressList.subaddresses.forEach((subaddress) {
addressesMap[subaddress.address] = subaddress.label; // addressesMap[subaddress.address] = subaddress.label;
addressInfos[account.id] ??= []; // addressInfos[account.id] ??= [];
addressInfos[account.id]?.add(AddressInfo( // addressInfos[account.id]?.add(AddressInfo(
address: subaddress.address, label: subaddress.label, accountIndex: account.id)); // address: subaddress.address, label: subaddress.label, accountIndex: account.id));
}); // });
}); // });
await saveAddressesInBox(); await saveAddressesInBox();
} catch (e) { } catch (e, s) {
printV(e.toString()); printV(e.toString());
printV(s.toString());
} }
} }