From 82c32a09106c1927aa8e5455e4f6ef109ac3dcfd Mon Sep 17 00:00:00 2001 From: Blazebrain Date: Wed, 27 Sep 2023 01:33:39 +0100 Subject: [PATCH] chore: refactoring code --- .../on_authentication_state_change.dart | 49 ++++++++++--------- 1 file changed, 26 insertions(+), 23 deletions(-) diff --git a/lib/reactions/on_authentication_state_change.dart b/lib/reactions/on_authentication_state_change.dart index c37f22ea4..8b65ba321 100644 --- a/lib/reactions/on_authentication_state_change.dart +++ b/lib/reactions/on_authentication_state_change.dart @@ -20,34 +20,37 @@ void startAuthenticationStateChange( final state = authenticationStore.state; if (state == AuthenticationState.installed) { - try { - await loadCurrentWallet(); - } catch (error, stack) { - loginError = error; - ExceptionHandler.onError(FlutterErrorDetails(exception: error, stack: stack)); - } + await _loadCurrentWallet(); return; } if (state == AuthenticationState.allowed) { - final typeRaw = - getIt.get().getInt(PreferencesKey.currentWalletType) ?? 0; - - final type = deserializeFromInt(typeRaw); - - if (type == WalletType.haven) { - await navigatorKey.currentState! - .pushNamedAndRemoveUntil(Routes.preSeed, (route) => false, arguments: type); - await navigatorKey.currentState!.pushNamed(Routes.seed, arguments: true); - await navigatorKey.currentState! - .pushNamedAndRemoveUntil(Routes.welcome, (route) => false); - return; - } else { - await navigatorKey.currentState! - .pushNamedAndRemoveUntil(Routes.dashboard, (route) => false); - return; - } + await _navigateBasedOnWalletType(navigatorKey); } }, ); } + +Future _loadCurrentWallet() async { + try { + await loadCurrentWallet(); + } catch (error, stack) { + loginError = error; + ExceptionHandler.onError(FlutterErrorDetails(exception: error, stack: stack)); + } +} + +Future _navigateBasedOnWalletType(GlobalKey navigatorKey) async { + final typeRaw = getIt.get().getInt(PreferencesKey.currentWalletType) ?? 0; + final type = deserializeFromInt(typeRaw); + + if (type == WalletType.haven) { + await navigatorKey.currentState! + .pushNamedAndRemoveUntil(Routes.preSeed, (route) => false, arguments: type); + await navigatorKey.currentState!.pushNamed(Routes.seed, arguments: true); + await navigatorKey.currentState!.pushNamedAndRemoveUntil(Routes.welcome, (route) => false); + return; + } else { + await navigatorKey.currentState!.pushNamedAndRemoveUntil(Routes.dashboard, (route) => false); + } +}