import 'package:cake_wallet/core/contact_service.dart'; import 'package:cake_wallet/src/domain/common/contact.dart'; import 'package:cake_wallet/src/domain/common/node.dart'; import 'package:cake_wallet/src/domain/exchange/trade.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/nodes/node_create_or_edit_page.dart'; import 'package:cake_wallet/src/screens/nodes/nodes_list_page.dart'; import 'package:cake_wallet/src/screens/seed/wallet_seed_page.dart'; import 'package:cake_wallet/src/screens/settings/settings.dart'; import 'package:cake_wallet/src/screens/wallet_keys/wallet_keys_page.dart'; import 'package:cake_wallet/store/contact_list_store.dart'; import 'package:cake_wallet/store/node_list_store.dart'; import 'package:cake_wallet/store/settings_store.dart'; import 'package:cake_wallet/core/auth_service.dart'; import 'package:cake_wallet/core/key_service.dart'; import 'package:cake_wallet/monero/monero_wallet.dart'; import 'package:cake_wallet/src/domain/common/wallet_info.dart'; import 'package:cake_wallet/src/screens/monero_accounts/monero_account_list_page.dart'; import 'package:cake_wallet/src/screens/monero_accounts/monero_account_edit_or_create_page.dart'; import 'package:cake_wallet/src/screens/auth/auth_page.dart'; import 'package:cake_wallet/src/screens/dashboard/dashboard_page.dart'; import 'package:cake_wallet/src/screens/receive/receive_page.dart'; import 'package:cake_wallet/src/screens/send/send_page.dart'; import 'package:cake_wallet/src/screens/subaddress/address_edit_or_create_page.dart'; import 'package:cake_wallet/src/screens/wallet_list/wallet_list_page.dart'; import 'package:cake_wallet/store/wallet_list_store.dart'; import 'package:cake_wallet/utils/mobx.dart'; import 'package:cake_wallet/view_model/contact_list/contact_list_view_model.dart'; import 'package:cake_wallet/view_model/contact_list/contact_view_model.dart'; import 'package:cake_wallet/view_model/node_list/node_list_view_model.dart'; import 'package:cake_wallet/view_model/node_list/node_create_or_edit_view_model.dart'; import 'package:cake_wallet/view_model/wallet_address_list/wallet_address_edit_or_create_view_model.dart'; import 'package:cake_wallet/view_model/auth_view_model.dart'; import 'package:cake_wallet/view_model/dashboard/dashboard_view_model.dart'; import 'package:cake_wallet/view_model/dashboard/balance_view_model.dart'; import 'package:cake_wallet/view_model/wallet_address_list/wallet_address_list_view_model.dart'; import 'package:cake_wallet/view_model/monero_account_list/monero_account_edit_or_create_view_model.dart'; import 'package:cake_wallet/view_model/monero_account_list/monero_account_list_view_model.dart'; import 'package:cake_wallet/view_model/send/send_view_model.dart'; import 'package:cake_wallet/view_model/settings/settings_view_model.dart'; import 'package:cake_wallet/view_model/wallet_keys_view_model.dart'; import 'package:cake_wallet/view_model/wallet_list/wallet_list_view_model.dart'; import 'package:cake_wallet/view_model/wallet_seed_view_model.dart'; import 'package:flutter/foundation.dart'; import 'package:get_it/get_it.dart'; import 'package:hive/hive.dart'; import 'package:mobx/mobx.dart'; import 'package:shared_preferences/shared_preferences.dart'; import 'package:flutter_secure_storage/flutter_secure_storage.dart'; import 'package:cake_wallet/view_model/wallet_restoration_from_seed_vm.dart'; import 'package:cake_wallet/core/wallet_creation_service.dart'; import 'package:cake_wallet/store/app_store.dart'; import 'package:cake_wallet/src/domain/common/wallet_type.dart'; import 'package:cake_wallet/view_model/wallet_new_vm.dart'; import 'package:cake_wallet/store/authentication_store.dart'; import 'package:cake_wallet/store/dashboard/trades_store.dart'; import 'package:cake_wallet/store/dashboard/trade_filter_store.dart'; import 'package:cake_wallet/store/dashboard/transaction_filter_store.dart'; import 'package:cake_wallet/store/dashboard/fiat_convertation_store.dart'; import 'package:cake_wallet/store/dashboard/page_view_store.dart'; final getIt = GetIt.instance; // FIXME: Move me. Stream _onNodesSourceChange; NodeListStore _nodeListStore; NodeListStore setupNodeListStore(Box nodeSource) { if (_nodeListStore != null) { return _nodeListStore; } _nodeListStore = NodeListStore(); _nodeListStore.replaceValues(nodeSource.values); _onNodesSourceChange = nodeSource.watch(); _onNodesSourceChange.listen((event) { // print(event); if (event.deleted) { _nodeListStore.nodes.removeWhere((n) { return n.key != null ? n.key == event.key : true; }); } if (event.value is Node) { final val = event.value as Node; _nodeListStore.nodes.add(val); } }); return _nodeListStore; } Future setup( {Box walletInfoSource, Box nodeSource, Box contactSource, Box tradesSource}) async { getIt.registerSingletonAsync( () => SharedPreferences.getInstance()); final settingsStore = await SettingsStoreBase.load(nodeSource: nodeSource); getIt.registerSingleton(FlutterSecureStorage()); getIt.registerSingleton(AuthenticationStore()); getIt.registerSingleton(WalletListStore()); getIt.registerSingleton(ContactListStore()); getIt.registerSingleton(setupNodeListStore(nodeSource)); getIt.registerSingleton(settingsStore); getIt.registerSingleton(AppStore( authenticationStore: getIt.get(), walletList: getIt.get(), settingsStore: getIt.get(), contactListStore: getIt.get(), nodeListStore: getIt.get())); getIt.registerSingleton( ContactService(contactSource, getIt.get().contactListStore)); getIt.registerSingleton(TradesStore( tradesSource: tradesSource, settingsStore: getIt.get())); getIt.registerSingleton( TradeFilterStore(wallet: getIt.get().wallet)); getIt.registerSingleton(TransactionFilterStore()); getIt.registerSingleton(FiatConvertationStore()); getIt.registerSingleton(PageViewStore()); getIt.registerFactory( () => KeyService(getIt.get())); getIt.registerFactoryParam( (type, _) => WalletCreationService( initialType: type, appStore: getIt.get(), keyService: getIt.get(), secureStorage: getIt.get(), sharedPreferences: getIt.get())); getIt.registerFactoryParam((type, _) => WalletNewVM( getIt.get(param1: type), walletInfoSource, type: type)); getIt .registerFactoryParam((args, _) { final type = args.first as WalletType; final language = args[1] as String; final mnemonic = args[2] as String; return WalletRestorationFromSeedVM( getIt.get(param1: type), walletInfoSource, type: type, language: language, seed: mnemonic); }); getIt.registerFactory( () => WalletAddressListViewModel(wallet: getIt.get().wallet)); getIt.registerFactory(() => BalanceViewModel( wallet: getIt.get().wallet, settingsStore: getIt.get(), fiatConvertationStore: getIt.get())); getIt.registerFactory(() => DashboardViewModel( balanceViewModel: getIt.get(), appStore: getIt.get(), tradesStore: getIt.get(), tradeFilterStore: getIt.get(), transactionFilterStore: getIt.get(), pageViewStore: getIt.get())); getIt.registerFactory(() => AuthService( secureStorage: getIt.get(), sharedPreferences: getIt.get())); getIt.registerFactory(() => AuthViewModel( authService: getIt.get(), sharedPreferences: getIt.get())); getIt.registerFactory( () => AuthPage( authViewModel: getIt.get(), onAuthenticationFinished: (isAuthenticated, __) { if (isAuthenticated) { getIt.get().allowed(); } }, closable: false), instanceName: 'login'); getIt .registerFactoryParam( (onAuthFinished, _) => AuthPage( authViewModel: getIt.get(), onAuthenticationFinished: onAuthFinished, closable: false)); getIt.registerFactory(() => DashboardPage( walletViewModel: getIt.get(), addressListViewModel: getIt.get())); getIt.registerFactory(() => ReceivePage( addressListViewModel: getIt.get())); getIt.registerFactoryParam( (dynamic item, _) => WalletAddressEditOrCreateViewModel( wallet: getIt.get().wallet, item: item)); getIt.registerFactoryParam( (dynamic item, _) => AddressEditOrCreatePage( addressEditOrCreateViewModel: getIt.get(param1: item))); getIt.registerFactory(() => SendViewModel( getIt.get().wallet, getIt.get().settingsStore, getIt.get())); getIt.registerFactory( () => SendPage(sendViewModel: getIt.get())); getIt.registerFactory(() => WalletListViewModel( walletInfoSource, getIt.get(), getIt.get())); getIt.registerFactory(() => WalletListPage(walletListViewModel: getIt.get())); getIt.registerFactory(() { final wallet = getIt.get().wallet; if (wallet is MoneroWallet) { return MoneroAccountListViewModel(wallet); } // FIXME: throw exception. return null; }); getIt.registerFactory(() => MoneroAccountListPage( accountListViewModel: getIt.get())); getIt.registerFactory(() { final wallet = getIt.get().wallet; if (wallet is MoneroWallet) { return MoneroAccountEditOrCreateViewModel(wallet.accountList); } // FIXME: throw exception. return null; }); getIt.registerFactory(() => MoneroAccountEditOrCreatePage( moneroAccountCreationViewModel: getIt.get())); getIt.registerFactory(() { final appStore = getIt.get(); return SettingsViewModel(appStore.settingsStore, appStore.wallet); }); getIt.registerFactory(() => SettingsPage(getIt.get())); getIt .registerFactory(() => WalletSeedViewModel(getIt.get().wallet)); getIt.registerFactoryParam( (VoidCallback callback, _) => WalletSeedPage( getIt.get(), onCloseCallback: callback)); getIt .registerFactory(() => WalletKeysViewModel(getIt.get().wallet)); getIt.registerFactory(() => WalletKeysPage(getIt.get())); getIt.registerFactoryParam( (Contact contact, _) => ContactViewModel( getIt.get(), getIt.get().wallet, contact: contact)); getIt.registerFactory(() => ContactListViewModel( getIt.get().contactListStore, getIt.get())); getIt.registerFactory( () => ContactListPage(getIt.get())); getIt.registerFactoryParam((Contact contact, _) => ContactPage(getIt.get(param1: contact))); getIt.registerFactory(() { final appStore = getIt.get(); return NodeListViewModel(appStore.nodeListStore, nodeSource, appStore.wallet, appStore.settingsStore); }); getIt.registerFactory(() => NodeListPage(getIt.get())); getIt.registerFactory(() => NodeCreateOrEditViewModel(nodeSource, getIt.get().wallet)); getIt.registerFactory( () => NodeCreateOrEditPage(getIt.get())); }