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) {
try { await _loadCurrentWallet();
await loadCurrentWallet();
} catch (error, stack) {
loginError = error;
ExceptionHandler.onError(FlutterErrorDetails(exception: error, stack: stack));
}
return; return;
} }
if (state == AuthenticationState.allowed) { if (state == AuthenticationState.allowed) {
final typeRaw = await _navigateBasedOnWalletType(navigatorKey);
getIt.get<SharedPreferences>().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;
}
} }
}, },
); );
} }
Future<void> _loadCurrentWallet() async {
try {
await loadCurrentWallet();
} catch (error, stack) {
loginError = error;
ExceptionHandler.onError(FlutterErrorDetails(exception: error, stack: stack));
}
}
Future<void> _navigateBasedOnWalletType(GlobalKey<NavigatorState> navigatorKey) async {
final typeRaw = getIt.get<SharedPreferences>().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);
}
}