2023-09-23 11:37:50 +00:00
|
|
|
import 'package:cake_wallet/di.dart';
|
|
|
|
import 'package:cake_wallet/entities/preferences_key.dart';
|
2020-09-21 11:50:26 +00:00
|
|
|
import 'package:cake_wallet/routes.dart';
|
2023-02-20 20:25:54 +00:00
|
|
|
import 'package:cake_wallet/utils/exception_handler.dart';
|
2023-09-23 11:37:50 +00:00
|
|
|
import 'package:cw_core/wallet_type.dart';
|
2020-09-21 11:50:26 +00:00
|
|
|
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';
|
2023-09-23 11:37:50 +00:00
|
|
|
import 'package:shared_preferences/shared_preferences.dart';
|
2020-09-21 11:50:26 +00:00
|
|
|
|
2022-10-12 17:09:57 +00:00
|
|
|
ReactionDisposer? _onAuthenticationStateChange;
|
2020-09-21 11:50:26 +00:00
|
|
|
|
2020-11-12 20:02:37 +00:00
|
|
|
dynamic loginError;
|
|
|
|
|
2023-04-14 04:39:08 +00:00
|
|
|
void startAuthenticationStateChange(
|
|
|
|
AuthenticationStore authenticationStore, GlobalKey<NavigatorState> navigatorKey) {
|
2023-09-23 11:37:50 +00:00
|
|
|
_onAuthenticationStateChange ??= autorun(
|
|
|
|
(_) async {
|
|
|
|
final state = authenticationStore.state;
|
2020-09-21 11:50:26 +00:00
|
|
|
|
2023-09-23 11:37:50 +00:00
|
|
|
if (state == AuthenticationState.installed) {
|
|
|
|
try {
|
|
|
|
await loadCurrentWallet();
|
|
|
|
} catch (error, stack) {
|
|
|
|
loginError = error;
|
|
|
|
ExceptionHandler.onError(FlutterErrorDetails(exception: error, stack: stack));
|
|
|
|
}
|
|
|
|
return;
|
2020-11-12 20:02:37 +00:00
|
|
|
}
|
2020-09-21 11:50:26 +00:00
|
|
|
|
2023-09-23 11:37:50 +00:00
|
|
|
if (state == AuthenticationState.allowed) {
|
|
|
|
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);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
);
|
2020-09-21 11:50:26 +00:00
|
|
|
}
|