breez fixes

This commit is contained in:
Matthew Fosse 2024-05-23 12:20:22 -07:00
parent 9459b74f94
commit 362c0bd231
10 changed files with 20 additions and 14 deletions

View file

@ -831,7 +831,7 @@ abstract class ElectrumWalletBase
Future<void> rescan({required int height}) async => throw UnimplementedError();
@override
Future<void> close() async {
Future<void> close({bool? switchingToSameWalletType}) async {
try {
await electrumClient.close();
} catch (_) {}

View file

@ -80,7 +80,7 @@ abstract class WalletBase<BalanceType extends Balance, HistoryType extends Trans
Future<void> rescan({required int height});
void close();
void close({bool? switchingToSameWalletType});
Future<void> changePassword(String password);

View file

@ -177,7 +177,7 @@ abstract class EVMChainWalletBase
}
@override
void close() {
void close({bool? switchingToSameWalletType}) {
_client.stop();
_transactionsUpdateTimer?.cancel();
}

View file

@ -233,10 +233,12 @@ abstract class LightningWalletBase extends ElectrumWallet with Store {
print("initialized breez: ${(await sdk.isInitialized())}");
}
Future<void> stopBreez() async {
final sdk = await BreezSDK();
if (await sdk.isInitialized()) {
await sdk.disconnect();
Future<void> stopBreez(bool disconnect) async {
if (disconnect) {
final sdk = await BreezSDK();
if (await sdk.isInitialized()) {
await sdk.disconnect();
}
}
await _nodeStateSub?.cancel();
await _paymentsSub?.cancel();
@ -363,12 +365,13 @@ abstract class LightningWalletBase extends ElectrumWallet with Store {
Future<String> makePath() async => pathForWallet(name: walletInfo.name, type: walletInfo.type);
@override
Future<void> close() async {
Future<void> close({bool? switchingToSameWalletType}) async {
try {
await electrumClient.close();
} catch (_) {}
try {
await stopBreez();
bool shouldDisconnect = switchingToSameWalletType == null || !switchingToSameWalletType;
await stopBreez(shouldDisconnect);
} catch (e, s) {
print("Error stopping breez: $e\n$s");
}

View file

@ -142,7 +142,7 @@ abstract class MoneroWalletBase
Future<void>? updateBalance() => null;
@override
void close() {
void close({bool? switchingToSameWalletType}) {
_listener?.stop();
_onAccountChangeReaction?.reaction.dispose();
_autoSaveTimer?.cancel();

View file

@ -138,7 +138,7 @@ abstract class NanoWalletBase
}
@override
void close() {
void close({bool? switchingToSameWalletType}) {
_client.stop();
_receiveTimer?.cancel();
}

View file

@ -165,7 +165,7 @@ abstract class SolanaWalletBase
Future<void> changePassword(String password) => throw UnimplementedError("changePassword");
@override
void close() {
void close({bool? switchingToSameWalletType}) {
_client.stop();
_transactionsUpdateTimer?.cancel();
}

View file

@ -186,7 +186,7 @@ abstract class TronWalletBase
}
@override
void close() {
void close({bool? switchingToSameWalletType}) {
_transactionsUpdateTimer?.cancel();
}

View file

@ -80,6 +80,7 @@ class WalletCreationService {
case WalletType.solana:
case WalletType.tron:
return true;
case WalletType.lightning:
case WalletType.monero:
case WalletType.none:
case WalletType.bitcoin:

View file

@ -3,6 +3,7 @@ import 'package:cake_wallet/di.dart';
import 'package:cake_wallet/reactions/wallet_connect.dart';
import 'package:cake_wallet/utils/exception_handler.dart';
import 'package:cw_core/transaction_info.dart';
import 'package:cw_core/wallet_type.dart';
import 'package:mobx/mobx.dart';
import 'package:cw_core/balance.dart';
import 'package:cw_core/wallet_base.dart';
@ -37,7 +38,8 @@ abstract class AppStoreBase with Store {
@action
Future<void> changeCurrentWallet(
WalletBase<Balance, TransactionHistoryBase<TransactionInfo>, TransactionInfo> wallet) async {
this.wallet?.close();
bool switchingToSameWalletType = this.wallet?.type == wallet.type;
this.wallet?.close(switchingToSameWalletType: switchingToSameWalletType);
this.wallet = wallet;
this.wallet!.setExceptionHandler(ExceptionHandler.onError);