mirror of
https://github.com/cypherstack/stack_wallet.git
synced 2024-11-18 02:07:43 +00:00
Merge pull request #728 from cypherstack/monero
Avoid updating cryptonote wallet information until wallet has finished opening
This commit is contained in:
commit
ec3638682c
3 changed files with 38 additions and 0 deletions
|
@ -55,6 +55,7 @@ class MoneroWallet extends CryptonoteWallet with CwBasedInterface {
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<void> exitCwWallet() async {
|
Future<void> exitCwWallet() async {
|
||||||
|
resetWalletOpenCompleter();
|
||||||
(cwWalletBase as MoneroWalletBase?)?.onNewBlock = null;
|
(cwWalletBase as MoneroWalletBase?)?.onNewBlock = null;
|
||||||
(cwWalletBase as MoneroWalletBase?)?.onNewTransaction = null;
|
(cwWalletBase as MoneroWalletBase?)?.onNewTransaction = null;
|
||||||
(cwWalletBase as MoneroWalletBase?)?.syncStatusChanged = null;
|
(cwWalletBase as MoneroWalletBase?)?.syncStatusChanged = null;
|
||||||
|
@ -63,6 +64,8 @@ class MoneroWallet extends CryptonoteWallet with CwBasedInterface {
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<void> open() async {
|
Future<void> open() async {
|
||||||
|
resetWalletOpenCompleter();
|
||||||
|
|
||||||
String? password;
|
String? password;
|
||||||
try {
|
try {
|
||||||
password = await cwKeysStorage.getWalletPassword(walletName: walletId);
|
password = await cwKeysStorage.getWalletPassword(walletName: walletId);
|
||||||
|
@ -87,6 +90,8 @@ class MoneroWallet extends CryptonoteWallet with CwBasedInterface {
|
||||||
const Duration(seconds: 193),
|
const Duration(seconds: 193),
|
||||||
(_) async => await cwWalletBase?.save(),
|
(_) async => await cwWalletBase?.save(),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
walletOpenCompleter?.complete();
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
@ -152,6 +157,13 @@ class MoneroWallet extends CryptonoteWallet with CwBasedInterface {
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<void> updateTransactions() async {
|
Future<void> updateTransactions() async {
|
||||||
|
try {
|
||||||
|
await waitForWalletOpen().timeout(const Duration(seconds: 30));
|
||||||
|
} catch (e, s) {
|
||||||
|
Logging.instance
|
||||||
|
.log("Failed to wait for wallet open: $e\n$s", level: LogLevel.Fatal);
|
||||||
|
}
|
||||||
|
|
||||||
await (cwWalletBase as MoneroWalletBase?)?.updateTransactions();
|
await (cwWalletBase as MoneroWalletBase?)?.updateTransactions();
|
||||||
final transactions =
|
final transactions =
|
||||||
(cwWalletBase as MoneroWalletBase?)?.transactionHistory?.transactions;
|
(cwWalletBase as MoneroWalletBase?)?.transactionHistory?.transactions;
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
import 'dart:async';
|
||||||
|
|
||||||
import 'package:stackwallet/wallets/crypto_currency/intermediate/cryptonote_currency.dart';
|
import 'package:stackwallet/wallets/crypto_currency/intermediate/cryptonote_currency.dart';
|
||||||
import 'package:stackwallet/wallets/models/tx_data.dart';
|
import 'package:stackwallet/wallets/models/tx_data.dart';
|
||||||
import 'package:stackwallet/wallets/wallet/wallet.dart';
|
import 'package:stackwallet/wallets/wallet/wallet.dart';
|
||||||
|
@ -7,6 +9,20 @@ abstract class CryptonoteWallet<T extends CryptonoteCurrency> extends Wallet<T>
|
||||||
with MnemonicInterface<T> {
|
with MnemonicInterface<T> {
|
||||||
CryptonoteWallet(T currency) : super(currency);
|
CryptonoteWallet(T currency) : super(currency);
|
||||||
|
|
||||||
|
Completer<void>? walletOpenCompleter;
|
||||||
|
|
||||||
|
void resetWalletOpenCompleter() {
|
||||||
|
if (walletOpenCompleter == null || walletOpenCompleter!.isCompleted) {
|
||||||
|
walletOpenCompleter = Completer<void>();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> waitForWalletOpen() async {
|
||||||
|
if (walletOpenCompleter != null && !walletOpenCompleter!.isCompleted) {
|
||||||
|
await walletOpenCompleter!.future;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// ========== Overrides ======================================================
|
// ========== Overrides ======================================================
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
|
|
@ -47,6 +47,8 @@ mixin CwBasedInterface<T extends CryptonoteCurrency> on CryptonoteWallet<T>
|
||||||
|
|
||||||
Timer? autoSaveTimer;
|
Timer? autoSaveTimer;
|
||||||
|
|
||||||
|
static bool walletOperationWaiting = false;
|
||||||
|
|
||||||
Future<String> pathForWalletDir({
|
Future<String> pathForWalletDir({
|
||||||
required String name,
|
required String name,
|
||||||
required WalletType type,
|
required WalletType type,
|
||||||
|
@ -244,6 +246,13 @@ mixin CwBasedInterface<T extends CryptonoteCurrency> on CryptonoteWallet<T>
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<void> updateBalance() async {
|
Future<void> updateBalance() async {
|
||||||
|
try {
|
||||||
|
await waitForWalletOpen().timeout(const Duration(seconds: 30));
|
||||||
|
} catch (e, s) {
|
||||||
|
Logging.instance
|
||||||
|
.log("Failed to wait for wallet open: $e\n$s", level: LogLevel.Fatal);
|
||||||
|
}
|
||||||
|
|
||||||
final total = await totalBalance;
|
final total = await totalBalance;
|
||||||
final available = await availableBalance;
|
final available = await availableBalance;
|
||||||
|
|
||||||
|
@ -300,6 +309,7 @@ mixin CwBasedInterface<T extends CryptonoteCurrency> on CryptonoteWallet<T>
|
||||||
@override
|
@override
|
||||||
Future<void> exit() async {
|
Future<void> exit() async {
|
||||||
if (!_hasCalledExit) {
|
if (!_hasCalledExit) {
|
||||||
|
resetWalletOpenCompleter();
|
||||||
_hasCalledExit = true;
|
_hasCalledExit = true;
|
||||||
autoSaveTimer?.cancel();
|
autoSaveTimer?.cancel();
|
||||||
await exitCwWallet();
|
await exitCwWallet();
|
||||||
|
|
Loading…
Reference in a new issue