mirror of
https://github.com/cake-tech/cake_wallet.git
synced 2025-01-10 04:44:43 +00:00
[skip ci] working
This commit is contained in:
parent
9f6998b72d
commit
51259a879c
3 changed files with 62 additions and 71 deletions
|
@ -37,8 +37,10 @@ abstract class MoneroSubaddressListBase with Store {
|
|||
subaddresses.clear();
|
||||
subaddresses.addAll(getAll());
|
||||
_isUpdating = false;
|
||||
} catch (e) {
|
||||
} catch (e, s) {
|
||||
_isUpdating = false;
|
||||
printV("here");
|
||||
printV(s.toString());
|
||||
rethrow;
|
||||
}
|
||||
}
|
||||
|
@ -141,22 +143,21 @@ abstract class MoneroSubaddressListBase with Store {
|
|||
address: address,
|
||||
balance: (s.received / 1e12).toStringAsFixed(6),
|
||||
txCount: s.txCount,
|
||||
label: id == 0 &&
|
||||
label.toLowerCase() == 'Primary account'.toLowerCase()
|
||||
label: id == 0 && label.toLowerCase() == 'Primary account'.toLowerCase()
|
||||
? 'Primary address'
|
||||
: label);
|
||||
}).toList().reversed.toList();
|
||||
})
|
||||
.toList()
|
||||
.reversed
|
||||
.toList();
|
||||
}
|
||||
|
||||
Future<bool> _newSubaddress({required int accountIndex, required String label}) async {
|
||||
await subaddress_list.addSubaddress(accountIndex: accountIndex, label: label);
|
||||
|
||||
return subaddress_list
|
||||
.getAllSubaddresses()
|
||||
.where((s) {
|
||||
return subaddress_list.getAllSubaddresses().where((s) {
|
||||
final address = s.address;
|
||||
return !_usedAddresses.contains(address);
|
||||
})
|
||||
.isNotEmpty;
|
||||
}).isNotEmpty;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -158,11 +158,16 @@ abstract class MoneroWalletBase
|
|||
}
|
||||
}
|
||||
|
||||
bool isMainThread = Isolate.current.debugName == "main";
|
||||
printV("isMainThread: $isMainThread");
|
||||
|
||||
if (isMainThread) {
|
||||
_autoSaveTimer =
|
||||
Timer.periodic(Duration(seconds: _autoSaveInterval), (_) async => await save());
|
||||
// update transaction details after restore
|
||||
walletAddresses.subaddressList.update(accountIndex: walletAddresses.account?.id ?? 0);
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void>? updateBalance() => null;
|
||||
|
@ -198,11 +203,17 @@ abstract class MoneroWalletBase
|
|||
|
||||
@override
|
||||
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 {
|
||||
syncStatus = AttemptingSyncStatus();
|
||||
monero_wallet.startBackgroundSync();
|
||||
isBackgroundSyncing = true;
|
||||
_setListeners();
|
||||
_listener?.start();
|
||||
return;
|
||||
} catch (e) {
|
||||
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 {
|
||||
syncStatus = AttemptingSyncStatus();
|
||||
monero_wallet.startRefresh();
|
||||
|
@ -280,8 +273,8 @@ abstract class MoneroWalletBase
|
|||
bool needExportOutputs(int amount) {
|
||||
// viewOnlyBalance - balance that we can spend
|
||||
// TODO(mrcyjanek): remove hasUnknownKeyImages when we cleanup coin control
|
||||
return (monero.Wallet_viewOnlyBalance(wptr!,
|
||||
accountIndex: walletAddresses.account!.id) < amount) ||
|
||||
return (monero.Wallet_viewOnlyBalance(wptr!, accountIndex: walletAddresses.account!.id) <
|
||||
amount) ||
|
||||
monero.Wallet_hasUnknownKeyImages(wptr!);
|
||||
}
|
||||
|
||||
|
@ -303,8 +296,8 @@ abstract class MoneroWalletBase
|
|||
final inputs = <String>[];
|
||||
final outputs = _credentials.outputs;
|
||||
final hasMultiDestination = outputs.length > 1;
|
||||
final unlockedBalance = monero_wallet.getUnlockedBalance(
|
||||
accountIndex: walletAddresses.account!.id);
|
||||
final unlockedBalance =
|
||||
monero_wallet.getUnlockedBalance(accountIndex: walletAddresses.account!.id);
|
||||
|
||||
PendingTransactionDescription pendingTransactionDescription;
|
||||
|
||||
|
@ -350,10 +343,8 @@ abstract class MoneroWalletBase
|
|||
preferredInputs: inputs);
|
||||
} else {
|
||||
final output = outputs.first;
|
||||
final address =
|
||||
output.isParsedAddress ? output.extractedAddress : output.address;
|
||||
final amount =
|
||||
output.sendAll ? null : output.cryptoAmount!.replaceAll(',', '.');
|
||||
final address = output.isParsedAddress ? output.extractedAddress : output.address;
|
||||
final amount = output.sendAll ? null : output.cryptoAmount!.replaceAll(',', '.');
|
||||
|
||||
// if ((formattedAmount != null && unlockedBalance < formattedAmount) ||
|
||||
// (formattedAmount == null && unlockedBalance <= 0)) {
|
||||
|
@ -363,10 +354,8 @@ abstract class MoneroWalletBase
|
|||
// 'You do not have enough unlocked balance. Unlocked: $formattedBalance. Transaction amount: ${output.cryptoAmount}.');
|
||||
// }
|
||||
|
||||
if (inputs.isEmpty) MoneroTransactionCreationException(
|
||||
'No inputs selected');
|
||||
pendingTransactionDescription =
|
||||
await transaction_history.createTransaction(
|
||||
if (inputs.isEmpty) MoneroTransactionCreationException('No inputs selected');
|
||||
pendingTransactionDescription = await transaction_history.createTransaction(
|
||||
address: address!,
|
||||
amount: amount,
|
||||
priorityRaw: _credentials.priority.serialize(),
|
||||
|
@ -742,8 +731,8 @@ abstract class MoneroWalletBase
|
|||
|
||||
Future<void> _askForUpdateTransactionHistory() async => await updateTransactions();
|
||||
|
||||
int _getUnlockedBalance() => monero_wallet.getUnlockedBalance(
|
||||
accountIndex: walletAddresses.account!.id);
|
||||
int _getUnlockedBalance() =>
|
||||
monero_wallet.getUnlockedBalance(accountIndex: walletAddresses.account!.id);
|
||||
|
||||
int _getFrozenBalance() {
|
||||
var frozenBalance = 0;
|
||||
|
|
|
@ -85,19 +85,20 @@ 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) {
|
||||
} catch (e, s) {
|
||||
printV(e.toString());
|
||||
printV(s.toString());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue