From 687184ecc5dbcdb3737d0936155de5ab8246b36f Mon Sep 17 00:00:00 2001 From: Erdem Yerebasmaz Date: Thu, 28 Mar 2024 11:13:06 +0300 Subject: [PATCH] Only restore existing nodes --- lib/bloc/account/account_bloc.dart | 15 ++++++++------- lib/handlers/node_connectivity_handler.dart | 2 +- .../initial_walkthrough/initial_walkthrough.dart | 2 +- test/bloc/account/account_bloc_test.dart | 2 +- 4 files changed, 11 insertions(+), 10 deletions(-) diff --git a/lib/bloc/account/account_bloc.dart b/lib/bloc/account/account_bloc.dart index 4a1db1572..94be08bcc 100644 --- a/lib/bloc/account/account_bloc.dart +++ b/lib/bloc/account/account_bloc.dart @@ -76,23 +76,23 @@ class AccountBloc extends Cubit with HydratedMixin { Future connect({ String? mnemonic, - bool restored = false, + bool isRestore = true, }) async { - _log.info("connect new mnemonic: ${mnemonic != null}, restored: $restored"); + _log.info("connect new mnemonic: ${mnemonic != null}, restored: $isRestore"); emit(state.copyWith(connectionStatus: ConnectionStatus.CONNECTING)); if (mnemonic != null) { await _credentialsManager.storeMnemonic(mnemonic: mnemonic); emit(state.copyWith( initial: false, - verificationStatus: restored ? VerificationStatus.VERIFIED : null, + verificationStatus: isRestore ? VerificationStatus.VERIFIED : null, )); } - await _startSdkForever(); + await _startSdkForever(isRestore: isRestore); } - Future _startSdkForever() async { + Future _startSdkForever({bool isRestore = true}) async { _log.info("starting sdk forever"); - await _startSdkOnce(); + await _startSdkOnce(isRestore: isRestore); // in case we failed to start (lack of inet connection probably) if (state.connectionStatus == ConnectionStatus.DISCONNECTED) { @@ -113,7 +113,7 @@ class AccountBloc extends Cubit with HydratedMixin { } } - Future _startSdkOnce() async { + Future _startSdkOnce({bool isRestore = true}) async { _log.info("starting sdk once"); var config = await Config.instance(); if (config.sdkConfig.apiKey != null) { @@ -133,6 +133,7 @@ class AccountBloc extends Cubit with HydratedMixin { final req = sdk.ConnectRequest( config: config.sdkConfig, seed: seed, + restoreOnly: isRestore, ); await _breezSDK.connect(req: req); _log.info("connected to breez lib"); diff --git a/lib/handlers/node_connectivity_handler.dart b/lib/handlers/node_connectivity_handler.dart index b0f5b9183..ba9888f2a 100644 --- a/lib/handlers/node_connectivity_handler.dart +++ b/lib/handlers/node_connectivity_handler.dart @@ -103,7 +103,7 @@ class NodeConnectivityHandler extends Handler { final accountBloc = context.read(); Future.delayed(const Duration(milliseconds: 500), () async { try { - await accountBloc.connect(restored: true); + await accountBloc.connect(); } catch (error) { _log.severe("Failed to reconnect"); rethrow; diff --git a/lib/routes/initial_walkthrough/initial_walkthrough.dart b/lib/routes/initial_walkthrough/initial_walkthrough.dart index e88072ae0..0615bdcfe 100644 --- a/lib/routes/initial_walkthrough/initial_walkthrough.dart +++ b/lib/routes/initial_walkthrough/initial_walkthrough.dart @@ -172,7 +172,7 @@ class InitialWalkthroughPageState extends State try { await accountBloc.connect( mnemonic: mnemonic ?? bip39.generateMnemonic(strength: 128), - restored: isRestore, + isRestore: isRestore, ); themeProvider.setTheme('dark'); navigator.pushReplacementNamed('/'); diff --git a/test/bloc/account/account_bloc_test.dart b/test/bloc/account/account_bloc_test.dart index ed780299b..f4ebef60b 100644 --- a/test/bloc/account/account_bloc_test.dart +++ b/test/bloc/account/account_bloc_test.dart @@ -39,7 +39,7 @@ void main() { injector.keychain.write(CredentialsManager.accountMnemonic, "a3eed"); AccountBloc accBloc = AccountBloc(breezSDK, CredentialsManager(keyChain: injector.keychain)); - await accBloc.connect(mnemonic: testMnemonic, restored: true); + await accBloc.connect(mnemonic: testMnemonic, isRestore: true); var accountState = accBloc.state; expect(accountState.blockheight, greaterThan(1)); expect(accountState.id?.length, equals(66));