cake_wallet/lib/router.dart

310 lines
13 KiB
Dart
Raw Normal View History

2020-01-04 19:31:52 +00:00
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:cake_wallet/routes.dart';
import 'package:cake_wallet/generated/i18n.dart';
2020-09-21 11:50:26 +00:00
import 'package:cake_wallet/di.dart';
import 'package:cake_wallet/utils/language_list.dart';
import 'package:cake_wallet/view_model/wallet_new_vm.dart';
import 'package:cake_wallet/view_model/wallet_restoration_from_seed_vm.dart';
import 'package:cake_wallet/view_model/wallet_restoration_from_keys_vm.dart';
import 'package:cake_wallet/entities/contact.dart';
import 'package:cake_wallet/exchange/trade.dart';
import 'package:cake_wallet/entities/transaction_info.dart';
import 'package:cake_wallet/entities/wallet_type.dart';
import 'package:cake_wallet/src/screens/dashboard/dashboard_page.dart';
import 'package:cake_wallet/src/screens/seed/wallet_seed_page.dart';
2020-01-04 19:31:52 +00:00
import 'package:cake_wallet/src/screens/auth/auth_page.dart';
2020-07-06 20:09:03 +00:00
import 'package:cake_wallet/src/screens/nodes/node_create_or_edit_page.dart';
2020-01-04 19:31:52 +00:00
import 'package:cake_wallet/src/screens/nodes/nodes_list_page.dart';
import 'package:cake_wallet/src/screens/receive/receive_page.dart';
2020-06-20 07:10:00 +00:00
import 'package:cake_wallet/src/screens/subaddress/address_edit_or_create_page.dart';
2020-01-04 19:31:52 +00:00
import 'package:cake_wallet/src/screens/wallet_list/wallet_list_page.dart';
import 'package:cake_wallet/src/screens/new_wallet/new_wallet_page.dart';
import 'package:cake_wallet/src/screens/setup_pin_code/setup_pin_code.dart';
import 'package:cake_wallet/src/screens/restore/restore_options_page.dart';
import 'package:cake_wallet/src/screens/restore/restore_wallet_options_page.dart';
import 'package:cake_wallet/src/screens/restore/restore_wallet_from_seed_page.dart';
import 'package:cake_wallet/src/screens/restore/restore_wallet_from_keys_page.dart';
import 'package:cake_wallet/src/screens/send/send_page.dart';
import 'package:cake_wallet/src/screens/disclaimer/disclaimer_page.dart';
import 'package:cake_wallet/src/screens/seed_language/seed_language_page.dart';
2020-01-04 19:31:52 +00:00
import 'package:cake_wallet/src/screens/transaction_details/transaction_details_page.dart';
2020-07-06 20:09:03 +00:00
import 'package:cake_wallet/src/screens/monero_accounts/monero_account_edit_or_create_page.dart';
import 'package:cake_wallet/src/screens/contact/contact_list_page.dart';
import 'package:cake_wallet/src/screens/contact/contact_page.dart';
import 'package:cake_wallet/src/screens/wallet_keys/wallet_keys_page.dart';
2020-01-04 19:31:52 +00:00
import 'package:cake_wallet/src/screens/settings/change_language.dart';
import 'package:cake_wallet/src/screens/restore/restore_wallet_from_seed_details.dart';
import 'package:cake_wallet/src/screens/exchange/exchange_page.dart';
import 'package:cake_wallet/src/screens/settings/settings.dart';
import 'package:cake_wallet/src/screens/rescan/rescan_page.dart';
import 'package:cake_wallet/src/screens/faq/faq_page.dart';
import 'package:cake_wallet/src/screens/trade_details/trade_details_page.dart';
import 'package:cake_wallet/src/screens/welcome/create_welcome_page.dart';
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';
2020-09-21 11:50:26 +00:00
import 'package:cake_wallet/src/screens/exchange_trade/exchange_confirm_page.dart';
import 'package:cake_wallet/src/screens/exchange_trade/exchange_trade_page.dart';
2020-09-14 12:08:33 +00:00
2020-01-04 19:31:52 +00:00
class Router {
2020-09-21 11:50:26 +00:00
static Route<dynamic> generateRoute(RouteSettings settings) {
2020-01-04 19:31:52 +00:00
switch (settings.name) {
case Routes.welcome:
2020-01-08 12:26:34 +00:00
return MaterialPageRoute<void>(builder: (_) => createWelcomePage());
2020-01-04 19:31:52 +00:00
case Routes.newWalletFromWelcome:
2020-01-08 12:26:34 +00:00
return CupertinoPageRoute<void>(
2020-09-21 11:50:26 +00:00
builder: (_) => getIt.get<SetupPinCodePage>(
param1: (BuildContext context, dynamic _) =>
Navigator.pushNamed(context, Routes.newWalletType)),
fullscreenDialog: true);
2020-06-02 07:47:33 +00:00
case Routes.newWalletType:
2020-06-20 07:10:00 +00:00
return CupertinoPageRoute<void>(
builder: (_) => NewWalletTypePage(
2020-09-21 11:50:26 +00:00
onTypeSelected: (context, type) => Navigator.of(context)
.pushNamed(Routes.newWallet, arguments: type)));
2020-01-04 19:31:52 +00:00
case Routes.newWallet:
2020-05-12 12:04:54 +00:00
final type = settings.arguments as WalletType;
2020-06-20 07:10:00 +00:00
final walletNewVM = getIt.get<WalletNewVM>(param1: type);
2020-05-12 12:04:54 +00:00
2020-01-08 12:26:34 +00:00
return CupertinoPageRoute<void>(
2020-06-20 07:10:00 +00:00
builder: (_) => NewWalletPage(walletNewVM));
2020-01-04 19:31:52 +00:00
case Routes.setupPin:
Function(BuildContext, String) callback;
if (settings.arguments is Function(BuildContext, String)) {
2020-01-08 12:26:34 +00:00
callback = settings.arguments as Function(BuildContext, String);
2020-01-04 19:31:52 +00:00
}
2020-01-08 12:26:34 +00:00
return CupertinoPageRoute<void>(
2020-09-21 11:50:26 +00:00
builder: (_) => getIt.get<SetupPinCodePage>(param1: callback));
2020-01-04 19:31:52 +00:00
2020-06-20 07:10:00 +00:00
case Routes.restoreWalletType:
return CupertinoPageRoute<void>(
builder: (_) => NewWalletTypePage(
onTypeSelected: (context, type) => Navigator.of(context)
.pushNamed(Routes.restoreWalletOptions, arguments: type),
isNewWallet: false,
2020-06-20 07:10:00 +00:00
));
2020-01-04 19:31:52 +00:00
case Routes.restoreOptions:
2020-05-12 12:04:54 +00:00
final type = settings.arguments as WalletType;
return CupertinoPageRoute<void>(
builder: (_) => RestoreOptionsPage(type: type));
2020-01-04 19:31:52 +00:00
case Routes.restoreWalletOptions:
2020-05-12 12:04:54 +00:00
final type = settings.arguments as WalletType;
2020-01-08 12:26:34 +00:00
return CupertinoPageRoute<void>(
2020-06-20 07:10:00 +00:00
builder: (_) => RestoreWalletOptionsPage(
type: type,
onRestoreFromSeed: (context) {
final route = type == WalletType.monero
? Routes.seedLanguage
: Routes.restoreWalletFromSeed;
final args = type == WalletType.monero
? [type, Routes.restoreWalletFromSeed]
: [type];
Navigator.of(context).pushNamed(route, arguments: args);
},
onRestoreFromKeys: (context) {
final route = type == WalletType.monero
? Routes.seedLanguage
: Routes.restoreWalletFromKeys;
final args = type == WalletType.monero
? [type, Routes.restoreWalletFromKeys]
2020-06-20 07:10:00 +00:00
: [type];
Navigator.of(context).pushNamed(route, arguments: args);
}));
2020-01-04 19:31:52 +00:00
case Routes.restoreWalletOptionsFromWelcome:
2020-01-08 12:26:34 +00:00
return CupertinoPageRoute<void>(
2020-09-21 11:50:26 +00:00
builder: (_) => getIt.get<SetupPinCodePage>(
param1: (BuildContext context, dynamic _) =>
Navigator.pushNamed(context, Routes.restoreWalletType)),
fullscreenDialog: true);
2020-01-04 19:31:52 +00:00
case Routes.seed:
2020-01-08 12:26:34 +00:00
return MaterialPageRoute<void>(
2020-09-21 11:50:26 +00:00
builder: (_) =>
getIt.get<WalletSeedPage>(param1: settings.arguments as bool));
2020-01-04 19:31:52 +00:00
case Routes.restoreWalletFromSeed:
2020-06-20 07:10:00 +00:00
final args = settings.arguments as List<dynamic>;
final type = args.first as WalletType;
final language = type == WalletType.monero
? args[1] as String
2020-09-21 11:50:26 +00:00
: LanguageList.english;
2020-05-12 12:04:54 +00:00
2020-01-08 12:26:34 +00:00
return CupertinoPageRoute<void>(
2020-01-04 19:31:52 +00:00
builder: (_) =>
2020-07-06 20:09:03 +00:00
RestoreWalletFromSeedPage(type: type, language: language));
2020-01-04 19:31:52 +00:00
case Routes.restoreWalletFromKeys:
2020-06-20 07:10:00 +00:00
final args = settings.arguments as List<dynamic>;
final type = args.first as WalletType;
final language = type == WalletType.monero
? args[1] as String
2020-09-21 11:50:26 +00:00
: LanguageList.english;
2020-06-20 07:10:00 +00:00
final walletRestorationFromKeysVM =
2020-09-14 12:08:33 +00:00
getIt.get<WalletRestorationFromKeysVM>(param1: [type, language]);
2020-01-08 12:26:34 +00:00
return CupertinoPageRoute<void>(
builder: (_) => RestoreWalletFromKeysPage(
walletRestorationFromKeysVM: walletRestorationFromKeysVM));
2020-01-04 19:31:52 +00:00
case Routes.dashboard:
2020-01-08 12:26:34 +00:00
return CupertinoPageRoute<void>(
builder: (_) => getIt.get<DashboardPage>());
2020-01-04 19:31:52 +00:00
case Routes.send:
2020-01-08 12:26:34 +00:00
return CupertinoPageRoute<void>(
2020-07-06 20:09:03 +00:00
fullscreenDialog: true, builder: (_) => getIt.get<SendPage>());
2020-01-04 19:31:52 +00:00
case Routes.sendTemplate:
return CupertinoPageRoute<void>(
2020-09-14 12:08:33 +00:00
fullscreenDialog: true,
builder: (_) => getIt.get<SendTemplatePage>());
2020-01-04 19:31:52 +00:00
case Routes.receive:
2020-01-08 12:26:34 +00:00
return CupertinoPageRoute<void>(
2020-06-20 07:10:00 +00:00
fullscreenDialog: true, builder: (_) => getIt.get<ReceivePage>());
2020-01-04 19:31:52 +00:00
case Routes.transactionDetails:
2020-01-08 12:26:34 +00:00
return CupertinoPageRoute<void>(
2020-01-04 19:31:52 +00:00
fullscreenDialog: true,
2020-09-21 11:50:26 +00:00
builder: (_) =>
TransactionDetailsPage(settings.arguments as TransactionInfo));
2020-01-04 19:31:52 +00:00
case Routes.newSubaddress:
2020-01-08 12:26:34 +00:00
return CupertinoPageRoute<void>(
2020-06-20 07:10:00 +00:00
builder: (_) =>
getIt.get<AddressEditOrCreatePage>(param1: settings.arguments));
2020-01-04 19:31:52 +00:00
case Routes.disclaimer:
2020-01-08 12:26:34 +00:00
return CupertinoPageRoute<void>(builder: (_) => DisclaimerPage());
2020-01-04 19:31:52 +00:00
case Routes.readDisclaimer:
2020-01-08 12:26:34 +00:00
return CupertinoPageRoute<void>(
2020-01-04 19:31:52 +00:00
builder: (_) => DisclaimerPage(isReadOnly: true));
case Routes.seedLanguage:
2020-06-20 07:10:00 +00:00
final args = settings.arguments as List<dynamic>;
final type = args.first as WalletType;
final redirectRoute = args[1] as String;
return CupertinoPageRoute<void>(builder: (_) {
return SeedLanguage(
onConfirm: (context, lang) => Navigator.of(context)
.popAndPushNamed(redirectRoute, arguments: [type, lang]));
});
2020-01-04 19:31:52 +00:00
case Routes.walletList:
2020-01-08 12:26:34 +00:00
return MaterialPageRoute<void>(
2020-01-04 19:31:52 +00:00
fullscreenDialog: true,
2020-07-06 20:09:03 +00:00
builder: (_) => getIt.get<WalletListPage>());
2020-01-04 19:31:52 +00:00
case Routes.auth:
2020-01-08 12:26:34 +00:00
return MaterialPageRoute<void>(
2020-01-04 19:31:52 +00:00
fullscreenDialog: true,
2020-07-06 20:09:03 +00:00
builder: (_) => getIt.get<AuthPage>(
param1: settings.arguments as OnAuthenticationFinished));
2020-01-04 19:31:52 +00:00
case Routes.unlock:
2020-01-08 12:26:34 +00:00
return MaterialPageRoute<void>(
2020-01-04 19:31:52 +00:00
fullscreenDialog: true,
2020-09-21 11:50:26 +00:00
builder: (_) => getIt.get<AuthPage>(
param1: settings.arguments as OnAuthenticationFinished));
2020-01-04 19:31:52 +00:00
case Routes.nodeList:
2020-07-06 20:09:03 +00:00
return CupertinoPageRoute<void>(
builder: (_) => getIt.get<NodeListPage>());
2020-01-04 19:31:52 +00:00
case Routes.newNode:
2020-01-08 12:26:34 +00:00
return CupertinoPageRoute<void>(
2020-07-06 20:09:03 +00:00
builder: (_) => getIt.get<NodeCreateOrEditPage>());
2020-01-04 19:31:52 +00:00
case Routes.login:
2020-09-14 12:08:33 +00:00
return CupertinoPageRoute<void>(
builder: (context) => getIt.get<AuthPage>(instanceName: 'login'));
2020-01-04 19:31:52 +00:00
case Routes.accountCreation:
2020-07-06 20:09:03 +00:00
return CupertinoPageRoute<String>(
builder: (_) => getIt.get<MoneroAccountEditOrCreatePage>());
2020-01-04 19:31:52 +00:00
case Routes.addressBook:
2020-07-06 20:09:03 +00:00
return MaterialPageRoute<void>(
builder: (_) => getIt.get<ContactListPage>(param1: true));
2020-01-04 19:31:52 +00:00
case Routes.pickerAddressBook:
2020-07-06 20:09:03 +00:00
return MaterialPageRoute<void>(
builder: (_) => getIt.get<ContactListPage>(param1: false));
2020-01-04 19:31:52 +00:00
case Routes.addressBookAddContact:
2020-07-06 20:09:03 +00:00
return CupertinoPageRoute<void>(
builder: (_) =>
getIt.get<ContactPage>(param1: settings.arguments as Contact));
2020-01-04 19:31:52 +00:00
case Routes.showKeys:
2020-01-08 12:26:34 +00:00
return MaterialPageRoute<void>(
2020-07-06 20:09:03 +00:00
builder: (_) => getIt.get<WalletKeysPage>(),
2020-01-04 19:31:52 +00:00
fullscreenDialog: true);
case Routes.exchangeTrade:
2020-01-08 12:26:34 +00:00
return CupertinoPageRoute<void>(
builder: (_) => getIt.get<ExchangeTradePage>());
2020-01-04 19:31:52 +00:00
case Routes.exchangeConfirm:
2020-01-08 12:26:34 +00:00
return MaterialPageRoute<void>(
builder: (_) => getIt.get<ExchangeConfirmPage>());
2020-01-04 19:31:52 +00:00
case Routes.tradeDetails:
2020-09-21 11:50:26 +00:00
return MaterialPageRoute<void>(
builder: (_) => TradeDetailsPage(settings.arguments as Trade));
2020-01-04 19:31:52 +00:00
case Routes.restoreWalletFromSeedDetails:
2020-06-20 07:10:00 +00:00
final args = settings.arguments as List;
final walletRestorationFromSeedVM =
getIt.get<WalletRestorationFromSeedVM>(param1: args);
2020-01-08 12:26:34 +00:00
return CupertinoPageRoute<void>(
2020-06-20 07:10:00 +00:00
builder: (_) => RestoreWalletFromSeedDetailsPage(
walletRestorationFromSeedVM: walletRestorationFromSeedVM));
2020-01-08 12:26:34 +00:00
2020-01-04 19:31:52 +00:00
case Routes.exchange:
return CupertinoPageRoute<void>(
builder: (_) => getIt.get<ExchangePage>());
2020-01-04 19:31:52 +00:00
case Routes.exchangeTemplate:
return CupertinoPageRoute<void>(
builder: (_) => getIt.get<ExchangeTemplatePage>());
2020-01-04 19:31:52 +00:00
case Routes.settings:
2020-01-08 12:26:34 +00:00
return MaterialPageRoute<void>(
2020-07-06 20:09:03 +00:00
builder: (_) => getIt.get<SettingsPage>());
2020-01-04 19:31:52 +00:00
case Routes.rescan:
2020-09-21 11:50:26 +00:00
return MaterialPageRoute<void>(builder: (_) => getIt.get<RescanPage>());
2020-01-04 19:31:52 +00:00
case Routes.faq:
2020-01-08 12:26:34 +00:00
return MaterialPageRoute<void>(builder: (_) => FaqPage());
2020-01-04 19:31:52 +00:00
case Routes.changeLanguage:
2020-01-08 12:26:34 +00:00
return MaterialPageRoute<void>(builder: (_) => ChangeLanguage());
2020-01-04 19:31:52 +00:00
default:
2020-01-08 12:26:34 +00:00
return MaterialPageRoute<void>(
2020-01-04 19:31:52 +00:00
builder: (_) => Scaffold(
2020-09-21 11:50:26 +00:00
body: Center(
child: Text(S.current.router_no_route(settings.name)))));
2020-01-04 19:31:52 +00:00
}
}
}