mirror of
https://github.com/cake-tech/cake_wallet.git
synced 2025-01-23 11:15:33 +00:00
Merge redesign part 6.
This commit is contained in:
parent
6e6a081685
commit
d67ab4934d
4 changed files with 137 additions and 75 deletions
|
@ -1,4 +1,5 @@
|
|||
import 'package:cake_wallet/reactions/bootstrap.dart';
|
||||
import 'package:cake_wallet/routes.dart';
|
||||
import 'package:cake_wallet/store/app_store.dart';
|
||||
import 'package:cake_wallet/store/authentication_store.dart';
|
||||
import 'package:cake_wallet/core/auth_service.dart';
|
||||
|
@ -55,6 +56,8 @@ import 'package:cake_wallet/src/stores/seed_language/seed_language_store.dart';
|
|||
|
||||
bool isThemeChangerRegistered = false;
|
||||
|
||||
final navigatorKey = GlobalKey<NavigatorState>();
|
||||
|
||||
void main() async {
|
||||
WidgetsFlutterBinding.ensureInitialized();
|
||||
|
||||
|
@ -188,7 +191,9 @@ Future<void> initialSetup(
|
|||
tradesSource: tradesSource,
|
||||
templates: templates,
|
||||
exchangeTemplates: exchangeTemplates);
|
||||
await bootstrap(fiatConvertationService: fiatConvertationService);
|
||||
await bootstrap(
|
||||
fiatConvertationService: fiatConvertationService,
|
||||
navigatorKey: navigatorKey);
|
||||
monero_wallet.onStartup();
|
||||
}
|
||||
|
||||
|
@ -252,34 +257,37 @@ class MaterialAppWithTheme extends StatelessWidget {
|
|||
statusBarBrightness: statusBarBrightness,
|
||||
statusBarIconBrightness: statusBarIconBrightness));
|
||||
|
||||
return MaterialApp(
|
||||
debugShowCheckedModeBanner: false,
|
||||
theme: theme.getTheme(),
|
||||
localizationsDelegates: [
|
||||
S.delegate,
|
||||
GlobalCupertinoLocalizations.delegate,
|
||||
GlobalMaterialLocalizations.delegate,
|
||||
GlobalWidgetsLocalizations.delegate,
|
||||
],
|
||||
supportedLocales: S.delegate.supportedLocales,
|
||||
locale: Locale(currentLanguage.getCurrentLanguage()),
|
||||
onGenerateRoute: (settings) => Router.generateRoute(
|
||||
sharedPreferences: sharedPreferences,
|
||||
walletListService: walletListService,
|
||||
walletService: walletService,
|
||||
userService: userService,
|
||||
settings: settings,
|
||||
priceStore: priceStore,
|
||||
walletStore: walletStore,
|
||||
syncStore: syncStore,
|
||||
balanceStore: balanceStore,
|
||||
settingsStore: settingsStore,
|
||||
contacts: contacts,
|
||||
nodes: nodes,
|
||||
trades: trades,
|
||||
transactionDescriptions: transactionDescriptions),
|
||||
home: Root(
|
||||
authenticationStore: getIt.get<AuthenticationStore>(),
|
||||
return Root(
|
||||
authenticationStore: getIt.get<AuthenticationStore>(),
|
||||
child: MaterialApp(
|
||||
navigatorKey: navigatorKey,
|
||||
debugShowCheckedModeBanner: false,
|
||||
theme: theme.getTheme(),
|
||||
localizationsDelegates: [
|
||||
S.delegate,
|
||||
GlobalCupertinoLocalizations.delegate,
|
||||
GlobalMaterialLocalizations.delegate,
|
||||
GlobalWidgetsLocalizations.delegate,
|
||||
],
|
||||
supportedLocales: S.delegate.supportedLocales,
|
||||
locale: Locale(currentLanguage.getCurrentLanguage()),
|
||||
onGenerateRoute: (settings) => Router.generateRoute(
|
||||
sharedPreferences: sharedPreferences,
|
||||
walletListService: walletListService,
|
||||
walletService: walletService,
|
||||
userService: userService,
|
||||
settings: settings,
|
||||
priceStore: priceStore,
|
||||
walletStore: walletStore,
|
||||
syncStore: syncStore,
|
||||
balanceStore: balanceStore,
|
||||
settingsStore: settingsStore,
|
||||
contacts: contacts,
|
||||
nodes: nodes,
|
||||
trades: trades,
|
||||
transactionDescriptions: transactionDescriptions),
|
||||
initialRoute: Routes.login, // FIXME: get initial route!
|
||||
// home: Container(color: Colors.blue),
|
||||
));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,13 @@
|
|||
import 'dart:async';
|
||||
|
||||
import 'package:cake_wallet/core/key_service.dart';
|
||||
import 'package:cake_wallet/router.dart';
|
||||
import 'package:cake_wallet/routes.dart';
|
||||
import 'package:cake_wallet/src/domain/common/sync_status.dart';
|
||||
import 'package:cake_wallet/src/screens/auth/auth_page.dart';
|
||||
import 'package:cake_wallet/src/screens/dashboard/dashboard_page.dart';
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/widgets.dart';
|
||||
import 'package:mobx/mobx.dart';
|
||||
import 'package:cake_wallet/di.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
|
@ -24,8 +30,7 @@ import 'package:cake_wallet/store/dashboard/fiat_convertation_store.dart';
|
|||
// FIXME: move me
|
||||
Future<void> loadCurrentWallet() async {
|
||||
final appStore = getIt.get<AppStore>();
|
||||
final name = 'test';
|
||||
getIt.get<SharedPreferences>().getString('current_wallet_name');
|
||||
final name = getIt.get<SharedPreferences>().getString('current_wallet_name');
|
||||
final typeRaw =
|
||||
getIt.get<SharedPreferences>().getInt('current_wallet_type') ?? 0;
|
||||
final type = deserializeFromInt(typeRaw);
|
||||
|
@ -55,7 +60,8 @@ ReactionDisposer _onCurrentFiatCurrencyChangeDisposer;
|
|||
Timer _reconnectionTimer;
|
||||
|
||||
Future<void> bootstrap(
|
||||
{FiatConvertationService fiatConvertationService}) async {
|
||||
{FiatConvertationService fiatConvertationService,
|
||||
GlobalKey<NavigatorState> navigatorKey}) async {
|
||||
final authenticationStore = getIt.get<AuthenticationStore>();
|
||||
final settingsStore = getIt.get<SettingsStore>();
|
||||
final fiatConvertationStore = getIt.get<FiatConvertationStore>();
|
||||
|
@ -69,10 +75,26 @@ Future<void> bootstrap(
|
|||
|
||||
_initialAuthReaction ??= autorun((_) async {
|
||||
final state = authenticationStore.state;
|
||||
print(state);
|
||||
|
||||
if (state == AuthenticationState.installed) {
|
||||
await loadCurrentWallet();
|
||||
}
|
||||
|
||||
if (state == AuthenticationState.installed) {
|
||||
await navigatorKey.currentState
|
||||
.pushAndRemoveUntil(createLoginRoute(), (_) => false);
|
||||
}
|
||||
|
||||
if (state == AuthenticationState.allowed) {
|
||||
await navigatorKey.currentState
|
||||
.pushAndRemoveUntil(createDashboardRoute(), (_) => false);
|
||||
}
|
||||
|
||||
if (state == AuthenticationState.denied) {
|
||||
await navigatorKey.currentState
|
||||
.pushAndRemoveUntil(createWelcomeRoute(), (_) => false);
|
||||
}
|
||||
});
|
||||
|
||||
_onCurrentWalletChangeReaction ??=
|
||||
|
|
|
@ -95,6 +95,15 @@ import 'package:cake_wallet/src/screens/new_wallet/new_wallet_type_page.dart';
|
|||
import 'package:cake_wallet/src/screens/send/send_template_page.dart';
|
||||
import 'package:cake_wallet/src/screens/exchange/exchange_template_page.dart';
|
||||
|
||||
CupertinoPageRoute<void> createDashboardRoute() =>
|
||||
CupertinoPageRoute<void>(builder: (_) => getIt.get<DashboardPage>());
|
||||
|
||||
CupertinoPageRoute<void> createLoginRoute() => CupertinoPageRoute<void>(
|
||||
builder: (context) => getIt.get<AuthPage>(instanceName: 'login'));
|
||||
|
||||
MaterialPageRoute<void> createWelcomeRoute() =>
|
||||
MaterialPageRoute<void>(builder: (_) => createWelcomePage());
|
||||
|
||||
class Router {
|
||||
static Route<dynamic> generateRoute(
|
||||
{SharedPreferences sharedPreferences,
|
||||
|
@ -239,7 +248,7 @@ class Router {
|
|||
: 'English'; // FIXME: Unnamed constant; English default and only one language for bitcoin.
|
||||
|
||||
final walletRestorationFromKeysVM =
|
||||
getIt.get<WalletRestorationFromKeysVM>(param1: [type, language]);
|
||||
getIt.get<WalletRestorationFromKeysVM>(param1: [type, language]);
|
||||
|
||||
return CupertinoPageRoute<void>(
|
||||
builder: (_) => RestoreWalletFromKeysPage(
|
||||
|
@ -255,7 +264,8 @@ class Router {
|
|||
|
||||
case Routes.sendTemplate:
|
||||
return CupertinoPageRoute<void>(
|
||||
fullscreenDialog: true, builder: (_) => getIt.get<SendTemplatePage>());
|
||||
fullscreenDialog: true,
|
||||
builder: (_) => getIt.get<SendTemplatePage>());
|
||||
|
||||
case Routes.receive:
|
||||
return CupertinoPageRoute<void>(
|
||||
|
@ -320,16 +330,8 @@ class Router {
|
|||
builder: (_) => getIt.get<NodeCreateOrEditPage>());
|
||||
|
||||
case Routes.login:
|
||||
return CupertinoPageRoute<void>(builder: (context) {
|
||||
final authenticationStore = Provider.of<AuthenticationStore>(context);
|
||||
|
||||
return createLoginPage(
|
||||
sharedPreferences: sharedPreferences,
|
||||
userService: userService,
|
||||
walletService: walletService,
|
||||
walletListService: walletListService,
|
||||
authenticationStore: authenticationStore);
|
||||
});
|
||||
return CupertinoPageRoute<void>(
|
||||
builder: (context) => getIt.get<AuthPage>(instanceName: 'login'));
|
||||
|
||||
case Routes.accountCreation:
|
||||
return CupertinoPageRoute<String>(
|
||||
|
@ -361,7 +363,7 @@ class Router {
|
|||
return MaterialPageRoute<void>(
|
||||
builder: (_) => getIt.get<ExchangeConfirmPage>());
|
||||
|
||||
//ExchangeConfirmPage(trade: settings.arguments as Trade));
|
||||
//ExchangeConfirmPage(trade: settings.arguments as Trade));
|
||||
|
||||
case Routes.tradeDetails:
|
||||
return MaterialPageRoute<void>(builder: (context) {
|
||||
|
|
|
@ -25,10 +25,12 @@ import 'package:cake_wallet/src/screens/auth/auth_page.dart';
|
|||
import 'package:cake_wallet/src/screens/welcome/create_welcome_page.dart';
|
||||
|
||||
class Root extends StatefulWidget {
|
||||
Root({Key key, this.authenticationStore, this.appStore}) : super(key: key);
|
||||
Root({Key key, this.authenticationStore, this.appStore, this.child})
|
||||
: super(key: key);
|
||||
|
||||
final AuthenticationStore authenticationStore;
|
||||
final AppStore appStore;
|
||||
final Widget child;
|
||||
|
||||
@override
|
||||
RootState createState() => RootState();
|
||||
|
@ -37,12 +39,18 @@ class Root extends StatefulWidget {
|
|||
class RootState extends State<Root> with WidgetsBindingObserver {
|
||||
bool _isInactive;
|
||||
bool _postFrameCallback;
|
||||
// GlobalKey<NavigatorState> _navKey;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
_isInactive = false;
|
||||
_postFrameCallback = false;
|
||||
WidgetsBinding.instance.addObserver(this);
|
||||
|
||||
// WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
// _navKey.currentState.pushNamed(Routes.login);
|
||||
// });
|
||||
|
||||
super.initState();
|
||||
}
|
||||
|
||||
|
@ -69,6 +77,8 @@ class RootState extends State<Root> with WidgetsBindingObserver {
|
|||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return widget.child;
|
||||
|
||||
// _authenticationStore = Provider.of<AuthenticationStore>(context);
|
||||
// final sharedPreferences = Provider.of<SharedPreferences>(context);
|
||||
// final walletListService = Provider.of<WalletListService>(context);
|
||||
|
@ -82,39 +92,59 @@ class RootState extends State<Root> with WidgetsBindingObserver {
|
|||
// final walletStore = Provider.of<WalletStore>(context);
|
||||
// final settingsStore = Provider.of<SettingsStore>(context);
|
||||
|
||||
if (_isInactive && !_postFrameCallback) {
|
||||
_postFrameCallback = true;
|
||||
// if (_isInactive && !_postFrameCallback) {
|
||||
// _postFrameCallback = true;
|
||||
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
Navigator.of(context).pushNamed(Routes.unlock,
|
||||
arguments: (bool isAuthenticatedSuccessfully, AuthPageState auth) {
|
||||
if (!isAuthenticatedSuccessfully) {
|
||||
return;
|
||||
}
|
||||
// WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
// Navigator.of(context).pushNamed(Routes.unlock,
|
||||
// arguments: (bool isAuthenticatedSuccessfully, AuthPageState auth) {
|
||||
// if (!isAuthenticatedSuccessfully) {
|
||||
// return;
|
||||
// }
|
||||
|
||||
setState(() {
|
||||
_postFrameCallback = false;
|
||||
_isInactive = false;
|
||||
});
|
||||
auth.close();
|
||||
});
|
||||
});
|
||||
}
|
||||
// setState(() {
|
||||
// _postFrameCallback = false;
|
||||
// _isInactive = false;
|
||||
// });
|
||||
// auth.close();
|
||||
// });
|
||||
// });
|
||||
// }
|
||||
|
||||
return Observer(builder: (_) {
|
||||
final state = widget.authenticationStore.state;
|
||||
// return Navigator(
|
||||
// key: _navKey,
|
||||
// initialRoute: Routes.welcome,
|
||||
// onGenerateRoute: Router.generateRoute(
|
||||
// sharedPreferences: sharedPreferences,
|
||||
// walletListService: walletListService,
|
||||
// walletService: walletService,
|
||||
// userService: userService,
|
||||
// settings: settings,
|
||||
// priceStore: priceStore,
|
||||
// walletStore: walletStore,
|
||||
// syncStore: syncStore,
|
||||
// balanceStore: balanceStore,
|
||||
// settingsStore: settingsStore,
|
||||
// contacts: contacts,
|
||||
// nodes: nodes,
|
||||
// trades: trades,
|
||||
// transactionDescriptions: transactionDescriptions),
|
||||
// );
|
||||
|
||||
if (state == AuthenticationState.denied) {
|
||||
return createWelcomePage();
|
||||
}
|
||||
// return Observer(builder: (_) {
|
||||
// final state = widget.authenticationStore.state;
|
||||
|
||||
if (state == AuthenticationState.installed) {
|
||||
return getIt.get<AuthPage>(instanceName: 'login');
|
||||
}
|
||||
// if (state == AuthenticationState.denied) {
|
||||
// return createWelcomePage();
|
||||
// }
|
||||
|
||||
if (state == AuthenticationState.allowed) {
|
||||
return getIt.get<DashboardPage>();
|
||||
}
|
||||
// if (state == AuthenticationState.installed) {
|
||||
// return getIt.get<AuthPage>(instanceName: 'login');
|
||||
// }
|
||||
|
||||
// if (state == AuthenticationState.allowed) {
|
||||
// return getIt.get<DashboardPage>();
|
||||
// }
|
||||
|
||||
// if (state == AuthenticationState.denied) {
|
||||
// return createWelcomePage();
|
||||
|
@ -148,7 +178,7 @@ class RootState extends State<Root> with WidgetsBindingObserver {
|
|||
// _authenticationStore.state = AuthenticationState.authenticated);
|
||||
// }
|
||||
|
||||
return Container(color: Colors.white);
|
||||
});
|
||||
// return Container(color: Colors.white);
|
||||
// });
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue