mirror of
https://github.com/cypherstack/stack_wallet.git
synced 2025-02-02 11:16:36 +00:00
replace simple return with an await open
This commit is contained in:
parent
f52b950650
commit
7f6b069017
3 changed files with 33 additions and 7 deletions
|
@ -55,7 +55,7 @@ class MoneroWallet extends CryptonoteWallet with CwBasedInterface {
|
|||
|
||||
@override
|
||||
Future<void> exitCwWallet() async {
|
||||
walletOpen = false;
|
||||
resetWalletOpenCompleter();
|
||||
(cwWalletBase as MoneroWalletBase?)?.onNewBlock = null;
|
||||
(cwWalletBase as MoneroWalletBase?)?.onNewTransaction = null;
|
||||
(cwWalletBase as MoneroWalletBase?)?.syncStatusChanged = null;
|
||||
|
@ -64,7 +64,7 @@ class MoneroWallet extends CryptonoteWallet with CwBasedInterface {
|
|||
|
||||
@override
|
||||
Future<void> open() async {
|
||||
walletOpen = false;
|
||||
resetWalletOpenCompleter();
|
||||
|
||||
String? password;
|
||||
try {
|
||||
|
@ -91,7 +91,7 @@ class MoneroWallet extends CryptonoteWallet with CwBasedInterface {
|
|||
(_) async => await cwWalletBase?.save(),
|
||||
);
|
||||
|
||||
walletOpen = true;
|
||||
walletOpenCompleter?.complete();
|
||||
}
|
||||
|
||||
@override
|
||||
|
@ -157,7 +157,12 @@ class MoneroWallet extends CryptonoteWallet with CwBasedInterface {
|
|||
|
||||
@override
|
||||
Future<void> updateTransactions() async {
|
||||
if (!walletOpen) return;
|
||||
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();
|
||||
final transactions =
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
import 'dart:async';
|
||||
|
||||
import 'package:stackwallet/wallets/crypto_currency/intermediate/cryptonote_currency.dart';
|
||||
import 'package:stackwallet/wallets/models/tx_data.dart';
|
||||
import 'package:stackwallet/wallets/wallet/wallet.dart';
|
||||
|
@ -7,7 +9,19 @@ abstract class CryptonoteWallet<T extends CryptonoteCurrency> extends Wallet<T>
|
|||
with MnemonicInterface<T> {
|
||||
CryptonoteWallet(T currency) : super(currency);
|
||||
|
||||
bool walletOpen = false;
|
||||
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 ======================================================
|
||||
|
||||
|
|
|
@ -47,6 +47,8 @@ mixin CwBasedInterface<T extends CryptonoteCurrency> on CryptonoteWallet<T>
|
|||
|
||||
Timer? autoSaveTimer;
|
||||
|
||||
static bool walletOperationWaiting = false;
|
||||
|
||||
Future<String> pathForWalletDir({
|
||||
required String name,
|
||||
required WalletType type,
|
||||
|
@ -244,7 +246,12 @@ mixin CwBasedInterface<T extends CryptonoteCurrency> on CryptonoteWallet<T>
|
|||
|
||||
@override
|
||||
Future<void> updateBalance() async {
|
||||
if (!walletOpen) return;
|
||||
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 available = await availableBalance;
|
||||
|
@ -302,7 +309,7 @@ mixin CwBasedInterface<T extends CryptonoteCurrency> on CryptonoteWallet<T>
|
|||
@override
|
||||
Future<void> exit() async {
|
||||
if (!_hasCalledExit) {
|
||||
walletOpen = false;
|
||||
resetWalletOpenCompleter();
|
||||
_hasCalledExit = true;
|
||||
autoSaveTimer?.cancel();
|
||||
await exitCwWallet();
|
||||
|
|
Loading…
Reference in a new issue