cake_wallet/lib/router.dart

489 lines
21 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:flutter_secure_storage/flutter_secure_storage.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:provider/provider.dart';
import 'package:hive/hive.dart';
import 'package:cake_wallet/routes.dart';
import 'package:cake_wallet/generated/i18n.dart';
// MARK: Import domains
import 'package:cake_wallet/src/domain/common/contact.dart';
import 'package:cake_wallet/src/domain/services/user_service.dart';
import 'package:cake_wallet/src/domain/services/wallet_list_service.dart';
import 'package:cake_wallet/src/domain/services/wallet_service.dart';
import 'package:cake_wallet/src/domain/common/crypto_currency.dart';
import 'package:cake_wallet/src/domain/exchange/changenow/changenow_exchange_provider.dart';
import 'package:cake_wallet/src/domain/exchange/xmrto/xmrto_exchange_provider.dart';
import 'package:cake_wallet/src/domain/exchange/morphtoken/morphtoken_exchange_provider.dart';
2020-01-04 19:31:52 +00:00
import 'package:cake_wallet/src/domain/common/node.dart';
import 'package:cake_wallet/src/domain/monero/transaction_description.dart';
import 'package:cake_wallet/src/domain/exchange/trade.dart';
2020-01-08 12:26:34 +00:00
import 'package:cake_wallet/src/domain/monero/account.dart';
import 'package:cake_wallet/src/domain/common/mnemotic_item.dart';
import 'package:cake_wallet/src/domain/common/transaction_info.dart';
import 'package:cake_wallet/src/domain/monero/subaddress.dart';
2020-01-04 19:31:52 +00:00
// MARK: Import stores
import 'package:cake_wallet/src/stores/authentication/authentication_store.dart';
import 'package:cake_wallet/src/stores/node_list/node_list_store.dart';
import 'package:cake_wallet/src/stores/auth/auth_store.dart';
import 'package:cake_wallet/src/stores/balance/balance_store.dart';
import 'package:cake_wallet/src/stores/send/send_store.dart';
import 'package:cake_wallet/src/stores/subaddress_creation/subaddress_creation_store.dart';
import 'package:cake_wallet/src/stores/subaddress_list/subaddress_list_store.dart';
import 'package:cake_wallet/src/stores/sync/sync_store.dart';
import 'package:cake_wallet/src/stores/user/user_store.dart';
import 'package:cake_wallet/src/stores/wallet/wallet_store.dart';
import 'package:cake_wallet/src/stores/wallet_creation/wallet_creation_store.dart';
import 'package:cake_wallet/src/stores/wallet_list/wallet_list_store.dart';
import 'package:cake_wallet/src/stores/wallet_restoration/wallet_restoration_store.dart';
import 'package:cake_wallet/src/stores/account_list/account_list_store.dart';
import 'package:cake_wallet/src/stores/address_book/address_book_store.dart';
import 'package:cake_wallet/src/stores/settings/settings_store.dart';
import 'package:cake_wallet/src/stores/wallet/wallet_keys_store.dart';
import 'package:cake_wallet/src/stores/exchange_trade/exchange_trade_store.dart';
import 'package:cake_wallet/src/stores/exchange/exchange_store.dart';
import 'package:cake_wallet/src/stores/rescan/rescan_wallet_store.dart';
import 'package:cake_wallet/src/stores/price/price_store.dart';
// MARK: Import screens
import 'package:cake_wallet/src/screens/auth/auth_page.dart';
import 'package:cake_wallet/src/screens/nodes/new_node_page.dart';
import 'package:cake_wallet/src/screens/nodes/nodes_list_page.dart';
import 'package:cake_wallet/src/screens/receive/receive_page.dart';
import 'package:cake_wallet/src/screens/subaddress/new_subaddress_page.dart';
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';
import 'package:cake_wallet/src/screens/accounts/account_page.dart';
import 'package:cake_wallet/src/screens/address_book/address_book_page.dart';
import 'package:cake_wallet/src/screens/address_book/contact_page.dart';
import 'package:cake_wallet/src/screens/show_keys/show_keys_page.dart';
import 'package:cake_wallet/src/screens/exchange_trade/exchange_confirm_page.dart';
import 'package:cake_wallet/src/screens/exchange_trade/exchange_trade_page.dart';
import 'package:cake_wallet/src/screens/subaddress/subaddress_list_page.dart';
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/auth/create_unlock_page.dart';
import 'package:cake_wallet/src/screens/auth/create_login_page.dart';
import 'package:cake_wallet/src/screens/seed/create_seed_page.dart';
import 'package:cake_wallet/src/screens/dashboard/create_dashboard_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';
2020-01-04 19:31:52 +00:00
class Router {
static Route<dynamic> generateRoute(
{SharedPreferences sharedPreferences,
WalletListService walletListService,
WalletService walletService,
UserService userService,
RouteSettings settings,
PriceStore priceStore,
WalletStore walletStore,
SyncStore syncStore,
BalanceStore balanceStore,
SettingsStore settingsStore,
Box<Contact> contacts,
Box<Node> nodes,
Box<TransactionDescription> transactionDescriptions,
Box<Trade> trades}) {
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-01-04 19:31:52 +00:00
builder: (_) => Provider(
create: (_) => UserStore(
accountService: UserService(
secureStorage: FlutterSecureStorage(),
sharedPreferences: sharedPreferences)),
child: SetupPinCodePage(
onPinCodeSetup: (context, _) =>
Navigator.pushNamed(context, Routes.newWalletType))));
case Routes.newWalletType:
return CupertinoPageRoute<void>(builder: (_) => NewWalletTypePage());
2020-01-04 19:31:52 +00:00
case Routes.newWallet:
2020-01-08 12:26:34 +00:00
return CupertinoPageRoute<void>(
2020-01-04 19:31:52 +00:00
builder:
(_) =>
ProxyProvider<AuthenticationStore, WalletCreationStore>(
update: (_, authStore, __) => WalletCreationStore(
authStore: authStore,
sharedPreferences: sharedPreferences,
walletListService: walletListService),
child: NewWalletPage(
walletsService: walletListService,
walletService: walletService,
sharedPreferences: sharedPreferences)));
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-01-04 19:31:52 +00:00
builder: (_) => Provider(
create: (_) => UserStore(
accountService: UserService(
secureStorage: FlutterSecureStorage(),
sharedPreferences: sharedPreferences)),
child: SetupPinCodePage(
onPinCodeSetup: (context, pin) =>
callback == null ? null : callback(context, pin))),
fullscreenDialog: true);
case Routes.restoreOptions:
2020-01-08 12:26:34 +00:00
return CupertinoPageRoute<void>(builder: (_) => RestoreOptionsPage());
2020-01-04 19:31:52 +00:00
case Routes.restoreWalletOptions:
2020-01-08 12:26:34 +00:00
return CupertinoPageRoute<void>(
builder: (_) => RestoreWalletOptionsPage());
2020-01-04 19:31:52 +00:00
case Routes.restoreWalletOptionsFromWelcome:
2020-01-08 12:26:34 +00:00
return CupertinoPageRoute<void>(
2020-01-04 19:31:52 +00:00
builder: (_) => Provider(
create: (_) => UserStore(
accountService: UserService(
secureStorage: FlutterSecureStorage(),
sharedPreferences: sharedPreferences)),
child: SetupPinCodePage(
onPinCodeSetup: (context, _) => Navigator.pushNamed(
context, Routes.restoreWalletOptions))));
case Routes.seed:
2020-01-08 12:26:34 +00:00
return MaterialPageRoute<void>(
2020-01-04 19:31:52 +00:00
builder: (_) => createSeedPage(
settingsStore: settingsStore,
walletService: walletService,
2020-01-08 12:26:34 +00:00
callback: settings.arguments as void Function()));
2020-01-04 19:31:52 +00:00
case Routes.restoreWalletFromSeed:
2020-01-08 12:26:34 +00:00
return CupertinoPageRoute<void>(
2020-01-04 19:31:52 +00:00
builder: (_) =>
ProxyProvider<AuthenticationStore, WalletRestorationStore>(
update: (_, authStore, __) => WalletRestorationStore(
authStore: authStore,
sharedPreferences: sharedPreferences,
walletListService: walletListService),
child: RestoreWalletFromSeedPage(
walletsService: walletListService,
walletService: walletService,
sharedPreferences: sharedPreferences)));
case Routes.restoreWalletFromKeys:
2020-01-08 12:26:34 +00:00
return CupertinoPageRoute<void>(
2020-01-04 19:31:52 +00:00
builder: (_) =>
ProxyProvider<AuthenticationStore, WalletRestorationStore>(
update: (_, authStore, __) => WalletRestorationStore(
authStore: authStore,
sharedPreferences: sharedPreferences,
walletListService: walletListService),
child: RestoreWalletFromKeysPage(
walletsService: walletListService,
walletService: walletService,
sharedPreferences: sharedPreferences)));
case Routes.dashboard:
2020-01-08 12:26:34 +00:00
return CupertinoPageRoute<void>(
2020-01-04 19:31:52 +00:00
builder: (_) => createDashboardPage(
walletService: walletService,
priceStore: priceStore,
settingsStore: settingsStore,
trades: trades,
transactionDescriptions: transactionDescriptions,
walletStore: walletStore));
case Routes.send:
2020-01-08 12:26:34 +00:00
return CupertinoPageRoute<void>(
2020-01-04 19:31:52 +00:00
fullscreenDialog: true,
builder: (_) => MultiProvider(providers: [
ProxyProvider<SettingsStore, BalanceStore>(
update: (_, settingsStore, __) => BalanceStore(
walletService: walletService,
settingsStore: settingsStore,
priceStore: priceStore),
),
Provider(
create: (_) => SyncStore(walletService: walletService),
),
Provider(
create: (_) => SendStore(
walletService: walletService,
priceStore: priceStore,
transactionDescriptions: transactionDescriptions)),
], child: SendPage()));
case Routes.receive:
2020-01-08 12:26:34 +00:00
return CupertinoPageRoute<void>(
2020-01-04 19:31:52 +00:00
fullscreenDialog: true,
builder: (_) => MultiProvider(providers: [
Provider(
create: (_) =>
SubaddressListStore(walletService: walletService)),
Provider(
create: (_) =>
AccountListStore(walletService: walletService))
2020-01-04 19:31:52 +00:00
], child: ReceivePage()));
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-01-08 12:26:34 +00:00
builder: (_) => TransactionDetailsPage(
transactionInfo: 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-01-04 19:31:52 +00:00
builder: (_) => Provider(
create: (_) =>
SubadrressCreationStore(walletService: walletService),
child: NewSubaddressPage()));
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:
return CupertinoPageRoute<void>(builder: (_) => SeedLanguage());
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,
builder: (_) => Provider(
create: (_) => WalletListStore(
walletListService: walletListService,
walletService: walletService),
child: WalletListPage()));
case Routes.auth:
2020-01-08 12:26:34 +00:00
return MaterialPageRoute<void>(
2020-01-04 19:31:52 +00:00
fullscreenDialog: true,
builder: (_) => Provider(
create: (_) => AuthStore(
sharedPreferences: sharedPreferences,
userService: userService,
walletService: walletService),
2020-01-08 12:26:34 +00:00
child: AuthPage(
onAuthenticationFinished:
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,
builder: (_) => createUnlockPage(
sharedPreferences: sharedPreferences,
userService: userService,
walletService: walletService,
2020-01-08 12:26:34 +00:00
onAuthenticationFinished:
settings.arguments as OnAuthenticationFinished));
2020-01-04 19:31:52 +00:00
case Routes.nodeList:
2020-01-08 12:26:34 +00:00
return CupertinoPageRoute<void>(builder: (context) {
2020-01-04 19:31:52 +00:00
return Provider(
create: (_) => NodeListStore(nodesSource: nodes),
child: NodeListPage());
});
case Routes.newNode:
2020-01-08 12:26:34 +00:00
return CupertinoPageRoute<void>(
2020-01-04 19:31:52 +00:00
builder: (_) => Provider<NodeListStore>(
create: (_) => NodeListStore(nodesSource: nodes),
child: NewNodePage()));
case Routes.login:
2020-01-08 12:26:34 +00:00
return CupertinoPageRoute<void>(builder: (context) {
2020-01-04 19:31:52 +00:00
final authenticationStore = Provider.of<AuthenticationStore>(context);
return createLoginPage(
sharedPreferences: sharedPreferences,
userService: userService,
walletService: walletService,
walletListService: walletListService,
authenticationStore: authenticationStore);
});
case Routes.accountCreation:
2020-01-08 12:26:34 +00:00
return CupertinoPageRoute<String>(builder: (context) {
2020-01-04 19:31:52 +00:00
return Provider(
create: (_) => AccountListStore(walletService: walletService),
2020-01-08 12:26:34 +00:00
child: AccountPage(account: settings.arguments as Account));
2020-01-04 19:31:52 +00:00
});
case Routes.addressBook:
2020-01-08 12:26:34 +00:00
return MaterialPageRoute<void>(builder: (context) {
2020-01-04 19:31:52 +00:00
return MultiProvider(
providers: [
Provider(
create: (_) =>
AccountListStore(walletService: walletService)),
Provider(create: (_) => AddressBookStore(contacts: contacts))
],
child: AddressBookPage(),
);
});
case Routes.pickerAddressBook:
2020-01-08 12:26:34 +00:00
return MaterialPageRoute<void>(builder: (context) {
2020-01-04 19:31:52 +00:00
return MultiProvider(
providers: [
Provider(
create: (_) =>
AccountListStore(walletService: walletService)),
Provider(create: (_) => AddressBookStore(contacts: contacts))
],
child: AddressBookPage(isEditable: false),
);
});
case Routes.addressBookAddContact:
2020-01-08 12:26:34 +00:00
return CupertinoPageRoute<void>(builder: (context) {
2020-01-04 19:31:52 +00:00
return MultiProvider(
providers: [
Provider(
create: (_) =>
AccountListStore(walletService: walletService)),
Provider(create: (_) => AddressBookStore(contacts: contacts))
],
2020-01-08 12:26:34 +00:00
child: ContactPage(contact: 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-01-04 19:31:52 +00:00
builder: (context) {
return Provider(
create: (_) => WalletKeysStore(walletService: walletService),
child: ShowKeysPage(),
);
},
fullscreenDialog: true);
case Routes.exchangeTrade:
2020-01-08 12:26:34 +00:00
return CupertinoPageRoute<void>(
2020-01-04 19:31:52 +00:00
builder: (_) => MultiProvider(
providers: [
ProxyProvider<SettingsStore, ExchangeTradeStore>(
update: (_, settingsStore, __) => ExchangeTradeStore(
2020-01-08 12:26:34 +00:00
trade: settings.arguments as Trade,
walletStore: walletStore,
trades: trades),
2020-01-04 19:31:52 +00:00
),
ProxyProvider<SettingsStore, SendStore>(
update: (_, settingsStore, __) => SendStore(
transactionDescriptions: transactionDescriptions,
walletService: walletService,
settingsStore: settingsStore,
priceStore: priceStore)),
],
child: ExchangeTradePage(),
));
case Routes.exchangeConfirm:
2020-01-08 12:26:34 +00:00
return MaterialPageRoute<void>(
builder: (_) =>
ExchangeConfirmPage(trade: settings.arguments as Trade));
2020-01-04 19:31:52 +00:00
case Routes.tradeDetails:
2020-01-08 12:26:34 +00:00
return MaterialPageRoute<void>(builder: (context) {
2020-01-04 19:31:52 +00:00
return MultiProvider(providers: [
ProxyProvider<SettingsStore, ExchangeTradeStore>(
update: (_, settingsStore, __) => ExchangeTradeStore(
trade: settings.arguments as Trade,
walletStore: walletStore,
trades: trades),
2020-01-04 19:31:52 +00:00
)
], child: TradeDetailsPage());
});
case Routes.subaddressList:
2020-01-08 12:26:34 +00:00
return MaterialPageRoute<Subaddress>(
2020-01-04 19:31:52 +00:00
builder: (_) => MultiProvider(providers: [
Provider(
create: (_) =>
SubaddressListStore(walletService: walletService))
], child: SubaddressListPage()));
case Routes.restoreWalletFromSeedDetails:
2020-01-08 12:26:34 +00:00
return CupertinoPageRoute<void>(
2020-01-04 19:31:52 +00:00
builder: (_) =>
ProxyProvider<AuthenticationStore, WalletRestorationStore>(
update: (_, authStore, __) => WalletRestorationStore(
authStore: authStore,
sharedPreferences: sharedPreferences,
walletListService: walletListService,
2020-01-08 12:26:34 +00:00
seed: settings.arguments as List<MnemoticItem>),
2020-01-04 19:31:52 +00:00
child: RestoreWalletFromSeedDetailsPage()));
2020-01-08 12:26:34 +00:00
2020-01-04 19:31:52 +00:00
case Routes.exchange:
2020-01-08 12:26:34 +00:00
return MaterialPageRoute<void>(
2020-01-04 19:31:52 +00:00
builder: (_) => MultiProvider(providers: [
Provider(create: (_) {
final xmrtoprovider = XMRTOExchangeProvider();
return ExchangeStore(
initialProvider: xmrtoprovider,
initialDepositCurrency: CryptoCurrency.xmr,
initialReceiveCurrency: CryptoCurrency.btc,
trades: trades,
providerList: [
xmrtoprovider,
ChangeNowExchangeProvider(),
MorphTokenExchangeProvider(trades: trades)
2020-01-04 19:31:52 +00:00
],
walletStore: walletStore);
}),
], child: ExchangePage()));
case Routes.settings:
2020-01-08 12:26:34 +00:00
return MaterialPageRoute<void>(
2020-01-04 19:31:52 +00:00
builder: (_) => Provider(
create: (_) => NodeListStore(nodesSource: nodes),
child: SettingsPage()));
case Routes.rescan:
2020-01-08 12:26:34 +00:00
return MaterialPageRoute<void>(
2020-01-04 19:31:52 +00:00
builder: (_) => Provider(
create: (_) => RescanWalletStore(walletService: walletService),
child: RescanPage()));
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(
body: Center(
child: Text(S.current.router_no_route(settings.name))),
));
}
}
}