mirror of
https://github.com/cake-tech/cake_wallet.git
synced 2025-01-21 18:24:41 +00:00
chore: refactoring code
This commit is contained in:
parent
591ded61f6
commit
82c32a0910
1 changed files with 26 additions and 23 deletions
|
@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue