mirror of
https://github.com/cake-tech/cake_wallet.git
synced 2025-01-10 12:54:38 +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.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();
|
||||||
|
@ -137,26 +139,25 @@ abstract class MoneroSubaddressListBase with Store {
|
||||||
final address = s.address;
|
final address = s.address;
|
||||||
final label = s.label;
|
final label = s.label;
|
||||||
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()
|
final address = s.address;
|
||||||
.where((s) {
|
return !_usedAddresses.contains(address);
|
||||||
final address = s.address;
|
}).isNotEmpty;
|
||||||
return !_usedAddresses.contains(address);
|
|
||||||
})
|
|
||||||
.isNotEmpty;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -158,10 +158,15 @@ abstract class MoneroWalletBase
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_autoSaveTimer =
|
bool isMainThread = Isolate.current.debugName == "main";
|
||||||
Timer.periodic(Duration(seconds: _autoSaveInterval), (_) async => await save());
|
printV("isMainThread: $isMainThread");
|
||||||
// update transaction details after restore
|
|
||||||
walletAddresses.subaddressList.update(accountIndex: walletAddresses.account?.id ?? 0);
|
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
|
@override
|
||||||
|
@ -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,9 +273,9 @@ 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!);
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
@ -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,15 +354,13 @@ 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 =
|
address: address!,
|
||||||
await transaction_history.createTransaction(
|
amount: amount,
|
||||||
address: address!,
|
priorityRaw: _credentials.priority.serialize(),
|
||||||
amount: amount,
|
accountIndex: walletAddresses.account!.id,
|
||||||
priorityRaw: _credentials.priority.serialize(),
|
preferredInputs: inputs);
|
||||||
accountIndex: walletAddresses.account!.id,
|
|
||||||
preferredInputs: inputs);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// final status = monero.PendingTransaction_status(pendingTransactionDescription);
|
// final status = monero.PendingTransaction_status(pendingTransactionDescription);
|
||||||
|
@ -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;
|
||||||
|
|
|
@ -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());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue