mirror of
https://github.com/cake-tech/cake_wallet.git
synced 2025-01-23 19:16:09 +00:00
54 lines
1.6 KiB
Dart
54 lines
1.6 KiB
Dart
import 'package:cake_wallet/routes.dart';
|
|
import 'package:cake_wallet/store/app_store.dart';
|
|
import 'package:cake_wallet/utils/exception_handler.dart';
|
|
import 'package:cw_core/wallet_type.dart';
|
|
import 'package:flutter/widgets.dart';
|
|
import 'package:mobx/mobx.dart';
|
|
import 'package:cake_wallet/entities/load_current_wallet.dart';
|
|
import 'package:cake_wallet/store/authentication_store.dart';
|
|
|
|
ReactionDisposer? _onAuthenticationStateChange;
|
|
|
|
dynamic loginError;
|
|
|
|
void startAuthenticationStateChange(AuthenticationStore authenticationStore,
|
|
GlobalKey<NavigatorState> navigatorKey, AppStore appStore) {
|
|
_onAuthenticationStateChange ??= autorun(
|
|
(_) async {
|
|
final state = authenticationStore.state;
|
|
|
|
if (state == AuthenticationState.installed) {
|
|
await _loadCurrentWallet();
|
|
return;
|
|
}
|
|
|
|
if (state == AuthenticationState.allowed) {
|
|
await _navigateBasedOnWalletType(navigatorKey, appStore);
|
|
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, AppStore appStore) async {
|
|
final wallet = appStore.wallet!;
|
|
|
|
if (wallet.type == WalletType.haven) {
|
|
await navigatorKey.currentState!
|
|
.pushNamed(Routes.havenRemovalNoticePage, arguments: [wallet, true]);
|
|
return;
|
|
} else {
|
|
await navigatorKey.currentState!.pushNamedAndRemoveUntil(Routes.dashboard, (route) => false);
|
|
return;
|
|
}
|
|
}
|