chore: refactoring code

This commit is contained in:
Blazebrain 2023-09-27 01:33:39 +01:00
parent 591ded61f6
commit 82c32a0910

View file

@ -20,34 +20,37 @@ void startAuthenticationStateChange(
final state = authenticationStore.state; final state = authenticationStore.state;
if (state == AuthenticationState.installed) { if (state == AuthenticationState.installed) {
await _loadCurrentWallet();
return;
}
if (state == AuthenticationState.allowed) {
await _navigateBasedOnWalletType(navigatorKey);
}
},
);
}
Future<void> _loadCurrentWallet() async {
try { try {
await loadCurrentWallet(); await loadCurrentWallet();
} catch (error, stack) { } catch (error, stack) {
loginError = error; loginError = error;
ExceptionHandler.onError(FlutterErrorDetails(exception: error, stack: stack)); ExceptionHandler.onError(FlutterErrorDetails(exception: error, stack: stack));
} }
return;
} }
if (state == AuthenticationState.allowed) { Future<void> _navigateBasedOnWalletType(GlobalKey<NavigatorState> navigatorKey) async {
final typeRaw = final typeRaw = getIt.get<SharedPreferences>().getInt(PreferencesKey.currentWalletType) ?? 0;
getIt.get<SharedPreferences>().getInt(PreferencesKey.currentWalletType) ?? 0;
final type = deserializeFromInt(typeRaw); final type = deserializeFromInt(typeRaw);
if (type == WalletType.haven) { if (type == WalletType.haven) {
await navigatorKey.currentState! await navigatorKey.currentState!
.pushNamedAndRemoveUntil(Routes.preSeed, (route) => false, arguments: type); .pushNamedAndRemoveUntil(Routes.preSeed, (route) => false, arguments: type);
await navigatorKey.currentState!.pushNamed(Routes.seed, arguments: true); await navigatorKey.currentState!.pushNamed(Routes.seed, arguments: true);
await navigatorKey.currentState! await navigatorKey.currentState!.pushNamedAndRemoveUntil(Routes.welcome, (route) => false);
.pushNamedAndRemoveUntil(Routes.welcome, (route) => false);
return; return;
} else { } else {
await navigatorKey.currentState! await navigatorKey.currentState!.pushNamedAndRemoveUntil(Routes.dashboard, (route) => false);
.pushNamedAndRemoveUntil(Routes.dashboard, (route) => false);
return;
} }
} }
},
);
}