2020-09-21 11:50:26 +00:00
|
|
|
import 'package:cake_wallet/routes.dart';
|
|
|
|
import 'package:flutter/widgets.dart';
|
|
|
|
import 'package:mobx/mobx.dart';
|
|
|
|
import 'package:cake_wallet/router.dart';
|
|
|
|
import 'package:cake_wallet/entities/load_current_wallet.dart';
|
|
|
|
import 'package:cake_wallet/store/authentication_store.dart';
|
|
|
|
|
|
|
|
ReactionDisposer _onAuthenticationStateChange;
|
|
|
|
|
2020-11-12 20:02:37 +00:00
|
|
|
dynamic loginError;
|
|
|
|
|
2020-09-21 11:50:26 +00:00
|
|
|
void startAuthenticationStateChange(AuthenticationStore authenticationStore,
|
2020-10-09 18:34:21 +00:00
|
|
|
@required GlobalKey<NavigatorState> navigatorKey) {
|
2020-09-21 11:50:26 +00:00
|
|
|
_onAuthenticationStateChange ??= autorun((_) async {
|
|
|
|
final state = authenticationStore.state;
|
|
|
|
|
|
|
|
if (state == AuthenticationState.installed) {
|
2020-11-12 20:02:37 +00:00
|
|
|
try {
|
|
|
|
await loadCurrentWallet();
|
|
|
|
} catch(e) {
|
|
|
|
loginError = e;
|
|
|
|
}
|
2020-10-09 18:34:21 +00:00
|
|
|
return;
|
2020-09-21 11:50:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (state == AuthenticationState.allowed) {
|
|
|
|
await navigatorKey.currentState
|
|
|
|
.pushNamedAndRemoveUntil(Routes.dashboard, (route) => false);
|
2020-10-09 18:34:21 +00:00
|
|
|
return;
|
2020-09-21 11:50:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (state == AuthenticationState.denied) {
|
|
|
|
await navigatorKey.currentState
|
|
|
|
.pushNamedAndRemoveUntil(Routes.welcome, (_) => false);
|
2020-10-09 18:34:21 +00:00
|
|
|
return;
|
2020-09-21 11:50:26 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|