cake_wallet/lib/di.dart

372 lines
16 KiB
Dart
Raw Normal View History

2020-09-15 20:35:49 +00:00
import 'package:cake_wallet/bitcoin/bitcoin_wallet_service.dart';
2020-07-06 20:09:03 +00:00
import 'package:cake_wallet/core/contact_service.dart';
2020-09-15 20:35:49 +00:00
import 'package:cake_wallet/core/wallet_service.dart';
2020-09-21 11:50:26 +00:00
import 'package:cake_wallet/entities/biometric_auth.dart';
2020-09-15 20:35:49 +00:00
import 'package:cake_wallet/monero/monero_wallet_service.dart';
2020-09-21 11:50:26 +00:00
import 'package:cake_wallet/entities/contact.dart';
import 'package:cake_wallet/entities/node.dart';
import 'package:cake_wallet/exchange/trade.dart';
2020-09-15 20:35:49 +00:00
// import 'package:cake_wallet/src/domain/services/wallet_service.dart';
2020-07-06 20:09:03 +00:00
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/exchange_trade/exchange_confirm_page.dart';
import 'package:cake_wallet/src/screens/exchange_trade/exchange_trade_page.dart';
2020-07-06 20:09:03 +00:00
import 'package:cake_wallet/src/screens/nodes/node_create_or_edit_page.dart';
import 'package:cake_wallet/src/screens/nodes/nodes_list_page.dart';
2020-09-21 11:50:26 +00:00
import 'package:cake_wallet/src/screens/rescan/rescan_page.dart';
2020-07-06 20:09:03 +00:00
import 'package:cake_wallet/src/screens/seed/wallet_seed_page.dart';
import 'package:cake_wallet/src/screens/send/send_template_page.dart';
2020-07-06 20:09:03 +00:00
import 'package:cake_wallet/src/screens/settings/settings.dart';
2020-09-21 11:50:26 +00:00
import 'package:cake_wallet/src/screens/setup_pin_code/setup_pin_code.dart';
2020-07-06 20:09:03 +00:00
import 'package:cake_wallet/src/screens/wallet_keys/wallet_keys_page.dart';
import 'package:cake_wallet/src/screens/exchange/exchange_page.dart';
import 'package:cake_wallet/src/screens/exchange/exchange_template_page.dart';
2020-07-06 20:09:03 +00:00
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';
2020-06-20 07:10:00 +00:00
import 'package:cake_wallet/core/auth_service.dart';
2020-07-06 20:09:03 +00:00
import 'package:cake_wallet/core/key_service.dart';
import 'package:cake_wallet/monero/monero_wallet.dart';
2020-09-21 11:50:26 +00:00
import 'package:cake_wallet/entities/wallet_info.dart';
2020-07-06 20:09:03 +00:00
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';
2020-06-20 07:10:00 +00:00
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';
2020-07-06 20:09:03 +00:00
import 'package:cake_wallet/src/screens/send/send_page.dart';
2020-06-20 07:10:00 +00:00
import 'package:cake_wallet/src/screens/subaddress/address_edit_or_create_page.dart';
2020-07-06 20:09:03 +00:00
import 'package:cake_wallet/src/screens/wallet_list/wallet_list_page.dart';
import 'package:cake_wallet/store/theme_changer_store.dart';
2020-07-06 20:09:03 +00:00
import 'package:cake_wallet/store/wallet_list_store.dart';
2020-08-27 16:54:34 +00:00
import 'package:cake_wallet/utils/mobx.dart';
import 'package:cake_wallet/theme_changer.dart';
2020-07-06 20:09:03 +00:00
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/exchange/exchange_trade_view_model.dart';
2020-07-06 20:09:03 +00:00
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';
2020-09-21 11:50:26 +00:00
import 'package:cake_wallet/view_model/rescan_view_model.dart';
import 'package:cake_wallet/view_model/setup_pin_code_view_model.dart';
2020-07-06 20:09:03 +00:00
import 'package:cake_wallet/view_model/wallet_address_list/wallet_address_edit_or_create_view_model.dart';
2020-06-20 07:10:00 +00:00
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';
2020-07-06 20:09:03 +00:00
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';
2020-08-25 16:32:40 +00:00
import 'package:cake_wallet/view_model/send/send_view_model.dart';
2020-07-06 20:09:03 +00:00
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:cake_wallet/view_model/exchange/exchange_view_model.dart';
2020-07-06 20:09:03 +00:00
import 'package:flutter/foundation.dart';
2020-09-21 11:50:26 +00:00
import 'package:flutter/widgets.dart';
2020-06-20 07:10:00 +00:00
import 'package:get_it/get_it.dart';
2020-07-06 20:09:03 +00:00
import 'package:hive/hive.dart';
2020-06-20 07:10:00 +00:00
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/view_model/wallet_restoration_from_keys_vm.dart';
2020-06-20 07:10:00 +00:00
import 'package:cake_wallet/core/wallet_creation_service.dart';
import 'package:cake_wallet/store/app_store.dart';
2020-09-21 11:50:26 +00:00
import 'package:cake_wallet/entities/wallet_type.dart';
2020-06-20 07:10:00 +00:00
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';
2020-09-21 11:50:26 +00:00
import 'package:cake_wallet/store/dashboard/fiat_conversion_store.dart';
import 'package:cake_wallet/store/templates/send_template_store.dart';
import 'package:cake_wallet/store/templates/exchange_template_store.dart';
2020-09-21 11:50:26 +00:00
import 'package:cake_wallet/entities/template.dart';
import 'package:cake_wallet/exchange/exchange_template.dart';
2020-06-20 07:10:00 +00:00
final getIt = GetIt.instance;
2020-07-06 20:09:03 +00:00
Future setup(
{Box<WalletInfo> walletInfoSource,
Box<Node> nodeSource,
Box<Contact> contactSource,
Box<Trade> tradesSource,
Box<Template> templates,
Box<ExchangeTemplate> exchangeTemplates}) async {
2020-06-20 07:10:00 +00:00
getIt.registerSingletonAsync<SharedPreferences>(
() => SharedPreferences.getInstance());
2020-07-06 20:09:03 +00:00
final settingsStore = await SettingsStoreBase.load(nodeSource: nodeSource);
2020-09-21 11:50:26 +00:00
getIt.registerSingleton<Box<Node>>(nodeSource);
2020-07-06 20:09:03 +00:00
getIt.registerSingleton<FlutterSecureStorage>(FlutterSecureStorage());
getIt.registerSingleton(AuthenticationStore());
getIt.registerSingleton<WalletListStore>(WalletListStore());
getIt.registerSingleton(ContactListStore());
2020-09-21 11:50:26 +00:00
getIt.registerSingleton(NodeListStoreBase.instance);
2020-07-06 20:09:03 +00:00
getIt.registerSingleton<SettingsStore>(settingsStore);
getIt.registerSingleton<AppStore>(AppStore(
authenticationStore: getIt.get<AuthenticationStore>(),
walletList: getIt.get<WalletListStore>(),
settingsStore: getIt.get<SettingsStore>(),
contactListStore: getIt.get<ContactListStore>(),
nodeListStore: getIt.get<NodeListStore>()));
getIt.registerSingleton<ContactService>(
ContactService(contactSource, getIt.get<AppStore>().contactListStore));
getIt.registerSingleton<TradesStore>(TradesStore(
2020-08-25 16:32:40 +00:00
tradesSource: tradesSource, settingsStore: getIt.get<SettingsStore>()));
getIt.registerSingleton<TradeFilterStore>(TradeFilterStore());
getIt.registerSingleton<TransactionFilterStore>(TransactionFilterStore());
2020-09-21 11:50:26 +00:00
getIt.registerSingleton<FiatConversionStore>(FiatConversionStore());
getIt.registerSingleton<SendTemplateStore>(
SendTemplateStore(templateSource: templates));
getIt.registerSingleton<ExchangeTemplateStore>(
ExchangeTemplateStore(templateSource: exchangeTemplates));
2020-07-06 20:09:03 +00:00
getIt.registerFactory<KeyService>(
() => KeyService(getIt.get<FlutterSecureStorage>()));
2020-06-20 07:10:00 +00:00
getIt.registerFactoryParam<WalletCreationService, WalletType, void>(
(type, _) => WalletCreationService(
initialType: type,
2020-07-06 20:09:03 +00:00
keyService: getIt.get<KeyService>(),
2020-06-20 07:10:00 +00:00
secureStorage: getIt.get<FlutterSecureStorage>(),
sharedPreferences: getIt.get<SharedPreferences>()));
getIt.registerFactoryParam<WalletNewVM, WalletType, void>((type, _) =>
2020-09-21 11:50:26 +00:00
WalletNewVM(getIt.get<AppStore>(),
2020-07-06 20:09:03 +00:00
getIt.get<WalletCreationService>(param1: type), walletInfoSource,
type: type));
2020-06-20 07:10:00 +00:00
getIt
.registerFactoryParam<WalletRestorationFromSeedVM, List, void>((args, _) {
final type = args.first as WalletType;
final language = args[1] as String;
final mnemonic = args[2] as String;
2020-09-21 11:50:26 +00:00
return WalletRestorationFromSeedVM(getIt.get<AppStore>(),
2020-07-06 20:09:03 +00:00
getIt.get<WalletCreationService>(param1: type), walletInfoSource,
type: type, language: language, seed: mnemonic);
2020-06-20 07:10:00 +00:00
});
getIt
.registerFactoryParam<WalletRestorationFromKeysVM, List, void>((args, _) {
final type = args.first as WalletType;
final language = args[1] as String;
2020-09-21 11:50:26 +00:00
return WalletRestorationFromKeysVM(getIt.get<AppStore>(),
getIt.get<WalletCreationService>(param1: type), walletInfoSource,
type: type, language: language);
});
2020-07-06 20:09:03 +00:00
getIt.registerFactory<WalletAddressListViewModel>(
() => WalletAddressListViewModel(wallet: getIt.get<AppStore>().wallet));
2020-06-20 07:10:00 +00:00
2020-08-25 16:32:40 +00:00
getIt.registerFactory(() => BalanceViewModel(
wallet: getIt.get<AppStore>().wallet,
settingsStore: getIt.get<SettingsStore>(),
2020-09-21 11:50:26 +00:00
fiatConvertationStore: getIt.get<FiatConversionStore>()));
2020-08-25 16:32:40 +00:00
getIt.registerFactory(() => DashboardViewModel(
balanceViewModel: getIt.get<BalanceViewModel>(),
appStore: getIt.get<AppStore>(),
tradesStore: getIt.get<TradesStore>(),
tradeFilterStore: getIt.get<TradeFilterStore>(),
2020-09-01 11:18:07 +00:00
transactionFilterStore: getIt.get<TransactionFilterStore>()));
2020-06-20 07:10:00 +00:00
getIt.registerFactory<AuthService>(() => AuthService(
secureStorage: getIt.get<FlutterSecureStorage>(),
sharedPreferences: getIt.get<SharedPreferences>()));
getIt.registerFactory<AuthViewModel>(() => AuthViewModel(
2020-09-21 11:50:26 +00:00
getIt.get<AuthService>(),
getIt.get<SharedPreferences>(),
getIt.get<SettingsStore>(),
BiometricAuth()));
2020-06-20 07:10:00 +00:00
2020-07-06 20:09:03 +00:00
getIt.registerFactory<AuthPage>(
2020-09-21 11:50:26 +00:00
() => AuthPage(getIt.get<AuthViewModel>(),
onAuthenticationFinished: (isAuthenticated, __) {
2020-07-06 20:09:03 +00:00
if (isAuthenticated) {
getIt.get<AuthenticationStore>().allowed();
}
2020-09-21 11:50:26 +00:00
}, closable: false),
2020-07-06 20:09:03 +00:00
instanceName: 'login');
2020-06-20 07:10:00 +00:00
2020-07-06 20:09:03 +00:00
getIt
.registerFactoryParam<AuthPage, void Function(bool, AuthPageState), void>(
2020-09-21 11:50:26 +00:00
(onAuthFinished, _) => AuthPage(getIt.get<AuthViewModel>(),
onAuthenticationFinished: onAuthFinished, closable: false));
2020-07-06 20:09:03 +00:00
2020-08-25 16:32:40 +00:00
getIt.registerFactory<DashboardPage>(() => DashboardPage(
walletViewModel: getIt.get<DashboardViewModel>(),
addressListViewModel: getIt.get<WalletAddressListViewModel>()));
2020-06-20 07:10:00 +00:00
2020-07-06 20:09:03 +00:00
getIt.registerFactory<ReceivePage>(() => ReceivePage(
addressListViewModel: getIt.get<WalletAddressListViewModel>()));
2020-06-20 07:10:00 +00:00
2020-07-06 20:09:03 +00:00
getIt.registerFactoryParam<WalletAddressEditOrCreateViewModel, dynamic, void>(
(dynamic item, _) => WalletAddressEditOrCreateViewModel(
2020-06-20 07:10:00 +00:00
wallet: getIt.get<AppStore>().wallet, item: item));
getIt.registerFactoryParam<AddressEditOrCreatePage, dynamic, void>(
(dynamic item, _) => AddressEditOrCreatePage(
addressEditOrCreateViewModel:
2020-07-06 20:09:03 +00:00
getIt.get<WalletAddressEditOrCreateViewModel>(param1: item)));
2020-09-01 11:18:07 +00:00
// getIt.get<SendTemplateStore>()
2020-07-06 20:09:03 +00:00
getIt.registerFactory<SendViewModel>(() => SendViewModel(
2020-08-25 16:32:40 +00:00
getIt.get<AppStore>().wallet,
getIt.get<AppStore>().settingsStore,
2020-09-21 11:50:26 +00:00
getIt.get<FiatConversionStore>()));
2020-07-06 20:09:03 +00:00
getIt.registerFactory(
() => SendPage(sendViewModel: getIt.get<SendViewModel>()));
2020-09-14 19:07:44 +00:00
getIt.registerFactory(
2020-09-21 11:50:26 +00:00
() => SendTemplatePage(sendViewModel: getIt.get<SendViewModel>()));
2020-07-06 20:09:03 +00:00
getIt.registerFactory(() => WalletListViewModel(
walletInfoSource, getIt.get<AppStore>(), getIt.get<KeyService>()));
2020-06-20 07:10:00 +00:00
2020-07-06 20:09:03 +00:00
getIt.registerFactory(() =>
WalletListPage(walletListViewModel: getIt.get<WalletListViewModel>()));
2020-06-20 07:10:00 +00:00
2020-07-06 20:09:03 +00:00
getIt.registerFactory(() {
final wallet = getIt.get<AppStore>().wallet;
if (wallet is MoneroWallet) {
return MoneroAccountListViewModel(wallet);
}
// FIXME: throw exception.
return null;
2020-06-20 07:10:00 +00:00
});
2020-07-06 20:09:03 +00:00
getIt.registerFactory(() => MoneroAccountListPage(
accountListViewModel: getIt.get<MoneroAccountListViewModel>()));
getIt.registerFactory(() {
final wallet = getIt.get<AppStore>().wallet;
if (wallet is MoneroWallet) {
return MoneroAccountEditOrCreateViewModel(wallet.accountList);
}
// FIXME: throw exception.
return null;
});
getIt.registerFactory(() => MoneroAccountEditOrCreatePage(
moneroAccountCreationViewModel:
getIt.get<MoneroAccountEditOrCreateViewModel>()));
2020-08-25 16:32:40 +00:00
getIt.registerFactory(() {
final appStore = getIt.get<AppStore>();
return SettingsViewModel(appStore.settingsStore, appStore.wallet);
});
2020-07-06 20:09:03 +00:00
getIt.registerFactory(() => SettingsPage(getIt.get<SettingsViewModel>()));
getIt
.registerFactory(() => WalletSeedViewModel(getIt.get<AppStore>().wallet));
getIt.registerFactoryParam<WalletSeedPage, bool, void>(
(bool isWalletCreated, _) => WalletSeedPage(
2020-07-06 20:09:03 +00:00
getIt.get<WalletSeedViewModel>(),
isNewWalletCreated: isWalletCreated));
2020-07-06 20:09:03 +00:00
getIt
.registerFactory(() => WalletKeysViewModel(getIt.get<AppStore>().wallet));
getIt.registerFactory(() => WalletKeysPage(getIt.get<WalletKeysViewModel>()));
getIt.registerFactoryParam<ContactViewModel, Contact, void>(
(Contact contact, _) => ContactViewModel(
2020-09-07 15:13:39 +00:00
contactSource, getIt.get<AppStore>().wallet,
2020-07-06 20:09:03 +00:00
contact: contact));
getIt.registerFactory(() => ContactListViewModel(
2020-09-07 15:13:39 +00:00
getIt.get<AppStore>().contactListStore,
getIt.get<ContactService>(),
contactSource));
2020-07-06 20:09:03 +00:00
2020-09-10 14:51:59 +00:00
getIt.registerFactoryParam<ContactListPage, bool, void>(
(bool isEditable, _) => ContactListPage(getIt.get<ContactListViewModel>(),
isEditable: isEditable));
2020-07-06 20:09:03 +00:00
getIt.registerFactoryParam<ContactPage, Contact, void>((Contact contact, _) =>
ContactPage(getIt.get<ContactViewModel>(param1: contact)));
2020-08-27 16:54:34 +00:00
getIt.registerFactory(() {
final appStore = getIt.get<AppStore>();
return NodeListViewModel(appStore.nodeListStore, nodeSource,
appStore.wallet, appStore.settingsStore);
});
2020-07-06 20:09:03 +00:00
getIt.registerFactory(() => NodeListPage(getIt.get<NodeListViewModel>()));
getIt.registerFactory(() =>
NodeCreateOrEditViewModel(nodeSource, getIt.get<AppStore>().wallet));
getIt.registerFactory(
() => NodeCreateOrEditPage(getIt.get<NodeCreateOrEditViewModel>()));
2020-09-01 11:18:07 +00:00
getIt.registerFactory(() => ExchangeViewModel(
wallet: getIt.get<AppStore>().wallet,
exchangeTemplateStore: getIt.get<ExchangeTemplateStore>(),
trades: tradesSource,
tradesStore: getIt.get<TradesStore>()));
2020-09-01 11:18:07 +00:00
getIt.registerFactory(() => ExchangeTradeViewModel(
wallet: getIt.get<AppStore>().wallet,
trades: tradesSource,
tradesStore: getIt.get<TradesStore>()));
2020-09-01 11:18:07 +00:00
getIt.registerFactory(() => ExchangePage(getIt.get<ExchangeViewModel>()));
2020-09-01 11:18:07 +00:00
getIt.registerFactory(
() => ExchangeConfirmPage(tradesStore: getIt.get<TradesStore>()));
2020-09-01 11:18:07 +00:00
getIt.registerFactory(() => ExchangeTradePage(
exchangeTradeViewModel: getIt.get<ExchangeTradeViewModel>()));
2020-09-01 11:18:07 +00:00
getIt.registerFactory(
() => ExchangeTemplatePage(getIt.get<ExchangeViewModel>()));
2020-09-15 20:35:49 +00:00
getIt.registerFactory(() => MoneroWalletService(walletInfoSource));
getIt.registerFactory(() => BitcoinWalletService());
getIt.registerFactoryParam<WalletService, WalletType, void>(
(WalletType param1, __) {
switch (param1) {
case WalletType.monero:
return getIt.get<MoneroWalletService>();
case WalletType.bitcoin:
return getIt.get<BitcoinWalletService>();
default:
return null;
}
});
2020-09-21 11:50:26 +00:00
getIt.registerFactory<SetupPinCodeViewModel>(() => SetupPinCodeViewModel(
getIt.get<AuthService>(), getIt.get<SettingsStore>()));
getIt.registerFactoryParam<SetupPinCodePage,
void Function(BuildContext, String), void>(
(onSuccessfulPinSetup, _) => SetupPinCodePage(
getIt.get<SetupPinCodeViewModel>(),
onSuccessfulPinSetup: onSuccessfulPinSetup));
getIt.registerFactory(() => RescanViewModel(getIt.get<AppStore>().wallet));
getIt.registerFactory(() => RescanPage(getIt.get<RescanViewModel>()));
2020-06-20 07:10:00 +00:00
}
void setupThemeChangerStore(ThemeChanger themeChanger) {
getIt.registerSingleton<ThemeChangerStore>(
ThemeChangerStore(themeChanger: themeChanger));
2020-06-20 07:10:00 +00:00
}