2020-09-21 14:50:26 +03:00
|
|
|
import 'package:cake_wallet/routes.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';
|
|
|
|
|
2022-10-12 13:09:57 -04:00
|
|
|
ReactionDisposer? _onAuthenticationStateChange;
|
2020-09-21 14:50:26 +03:00
|
|
|
|
2020-11-12 22:02:37 +02:00
|
|
|
dynamic loginError;
|
|
|
|
|
2020-09-21 14:50:26 +03:00
|
|
|
void startAuthenticationStateChange(AuthenticationStore authenticationStore,
|
2021-01-08 20:10:37 +02:00
|
|
|
GlobalKey<NavigatorState> navigatorKey) {
|
2020-09-21 14:50:26 +03:00
|
|
|
_onAuthenticationStateChange ??= autorun((_) async {
|
|
|
|
final state = authenticationStore.state;
|
|
|
|
|
|
|
|
if (state == AuthenticationState.installed) {
|
2020-11-12 22:02:37 +02:00
|
|
|
try {
|
|
|
|
await loadCurrentWallet();
|
2021-01-08 20:10:37 +02:00
|
|
|
} catch (e) {
|
2020-11-12 22:02:37 +02:00
|
|
|
loginError = e;
|
|
|
|
}
|
2020-10-09 21:34:21 +03:00
|
|
|
return;
|
2020-09-21 14:50:26 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (state == AuthenticationState.allowed) {
|
2022-12-03 23:34:23 +02:00
|
|
|
await navigatorKey.currentState!.pushNamedAndRemoveUntil(Routes.dashboard, (route) => false);
|
2020-10-09 21:34:21 +03:00
|
|
|
return;
|
2020-09-21 14:50:26 +03:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|