From e3678d2cf91e06d3ec0e32142e5c48ef80899f5f Mon Sep 17 00:00:00 2001 From: M Date: Mon, 28 Sep 2020 18:47:43 +0300 Subject: [PATCH] Fixes --- lib/core/contact_service.dart | 38 --- lib/di.dart | 31 +- lib/entities/language.dart | 38 --- lib/entities/language_service.dart | 26 ++ lib/entities/node.dart | 36 ++- lib/entities/record.dart | 3 +- lib/main.dart | 195 +++--------- lib/router.dart | 9 +- lib/src/reactions/set_reactions.dart | 98 ------ lib/src/screens/base_page.dart | 44 ++- .../screens/contact/contact_list_page.dart | 8 +- .../dashboard/create_dashboard_page.dart | 33 -- lib/src/screens/dashboard/dashboard_page.dart | 2 +- .../dashboard/widgets/balance_page.dart | 73 ++--- .../exchange/widgets/exchange_card.dart | 10 +- lib/src/screens/faq/faq_item.dart | 61 ++++ lib/src/screens/faq/faq_page.dart | 140 +------- lib/src/screens/send/send_page.dart | 299 +++++++++--------- lib/src/screens/settings/change_language.dart | 96 +++--- lib/src/widgets/alert_close_button.dart | 2 +- lib/store/app_store.dart | 4 - lib/store/contact_list_store.dart | 12 - lib/store/settings_store.dart | 24 +- lib/store/theme_changer_store.dart | 13 - lib/theme_changer.dart | 16 - lib/utils/date_formatter.dart | 2 +- lib/utils/mobx.dart | 6 +- .../contact_list/contact_list_view_model.dart | 24 +- .../contact_list/contact_view_model.dart | 9 +- lib/view_model/send/send_view_model.dart | 8 +- .../settings/settings_view_model.dart | 24 +- test/widget_test.dart | 2 +- 32 files changed, 482 insertions(+), 904 deletions(-) delete mode 100644 lib/core/contact_service.dart delete mode 100644 lib/entities/language.dart create mode 100644 lib/entities/language_service.dart delete mode 100644 lib/src/reactions/set_reactions.dart delete mode 100644 lib/src/screens/dashboard/create_dashboard_page.dart create mode 100644 lib/src/screens/faq/faq_item.dart delete mode 100644 lib/store/contact_list_store.dart delete mode 100644 lib/store/theme_changer_store.dart delete mode 100644 lib/theme_changer.dart diff --git a/lib/core/contact_service.dart b/lib/core/contact_service.dart deleted file mode 100644 index 3f2a46203..000000000 --- a/lib/core/contact_service.dart +++ /dev/null @@ -1,38 +0,0 @@ -import 'package:hive/hive.dart'; -import 'package:cake_wallet/store/contact_list_store.dart'; -import 'package:cake_wallet/entities/contact.dart'; - -class ContactService { - ContactService(this.contactSource, this.contactListStore) { - _forceUpdateContactListStore(); - } - - final Box contactSource; - final ContactListStore contactListStore; - - Future add(Contact contact) async { - await contactSource.add(contact); - // contactListStore.contacts.add(contact); - } - - Future update(Contact contact) async { - await contact.save(); - final index = contactListStore.contacts.indexOf(contact) ?? -1; - - if (index >= 0) { - _forceUpdateContactListStore(); - } else { - // contactListStore.contacts.add(contact); - } - } - - Future delete(Contact contact) async { - await contact.delete(); - contactListStore.contacts.remove(contact); - } - - void _forceUpdateContactListStore() { - contactListStore.contacts.clear(); - // contactListStore.contacts.addAll(contactSource.values); - } -} diff --git a/lib/di.dart b/lib/di.dart index d6ccde3cc..d133b6ed0 100644 --- a/lib/di.dart +++ b/lib/di.dart @@ -1,5 +1,4 @@ import 'package:cake_wallet/bitcoin/bitcoin_wallet_service.dart'; -import 'package:cake_wallet/core/contact_service.dart'; import 'package:cake_wallet/core/wallet_service.dart'; import 'package:cake_wallet/entities/biometric_auth.dart'; import 'package:cake_wallet/entities/contact_record.dart'; @@ -8,22 +7,22 @@ import 'package:cake_wallet/entities/contact.dart'; import 'package:cake_wallet/entities/node.dart'; import 'package:cake_wallet/exchange/trade.dart'; -// import 'package:cake_wallet/src/domain/services/wallet_service.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/exchange_trade/exchange_confirm_page.dart'; import 'package:cake_wallet/src/screens/exchange_trade/exchange_trade_page.dart'; +import 'package:cake_wallet/src/screens/faq/faq_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/rescan/rescan_page.dart'; import 'package:cake_wallet/src/screens/seed/wallet_seed_page.dart'; import 'package:cake_wallet/src/screens/send/send_template_page.dart'; +import 'package:cake_wallet/src/screens/settings/change_language.dart'; import 'package:cake_wallet/src/screens/settings/settings.dart'; import 'package:cake_wallet/src/screens/setup_pin_code/setup_pin_code.dart'; 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'; -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'; @@ -38,10 +37,7 @@ 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/theme_changer_store.dart'; import 'package:cake_wallet/store/wallet_list_store.dart'; -import 'package:cake_wallet/utils/mobx.dart'; -import 'package:cake_wallet/theme_changer.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/exchange/exchange_trade_view_model.dart'; @@ -62,11 +58,9 @@ 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'; -import 'package:flutter/foundation.dart'; import 'package:flutter/widgets.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'; @@ -104,17 +98,13 @@ Future setup( getIt.registerSingleton(FlutterSecureStorage()); getIt.registerSingleton(AuthenticationStore()); getIt.registerSingleton(WalletListStore()); - getIt.registerSingleton(ContactListStore()); getIt.registerSingleton(NodeListStoreBase.instance); 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()); @@ -285,14 +275,10 @@ Future setup( getIt.registerFactory(() => WalletKeysPage(getIt.get())); getIt.registerFactoryParam( - (ContactRecord contact, _) => ContactViewModel( - contactSource, getIt.get().wallet, - contact: contact)); + (ContactRecord contact, _) => + ContactViewModel(contactSource, contact: contact)); - getIt.registerFactory(() => ContactListViewModel( - getIt.get().contactListStore, - getIt.get(), - contactSource)); + getIt.registerFactory(() => ContactListViewModel(contactSource)); getIt.registerFactoryParam( (bool isEditable, _) => ContactListPage(getIt.get(), @@ -366,9 +352,8 @@ Future setup( getIt.registerFactory(() => RescanViewModel(getIt.get().wallet)); getIt.registerFactory(() => RescanPage(getIt.get())); -} -void setupThemeChangerStore(ThemeChanger themeChanger) { - getIt.registerSingleton( - ThemeChangerStore(themeChanger: themeChanger)); + getIt.registerFactory(() => FaqPage(getIt.get())); + + getIt.registerFactory(() => LanguageListPage(getIt.get())); } diff --git a/lib/entities/language.dart b/lib/entities/language.dart deleted file mode 100644 index 16e1d1a6a..000000000 --- a/lib/entities/language.dart +++ /dev/null @@ -1,38 +0,0 @@ -import 'package:flutter/material.dart'; -import 'package:devicelocale/devicelocale.dart'; -import 'package:intl/intl.dart'; - -const Map languages = { - 'en': 'English', - 'de': 'Deutsch (German)', - 'es': 'Español (Spanish)', - 'hi': 'हिंदी (Hindi)', - 'ja': '日本 (Japanese)', - 'ko': '한국어 (Korean)', - 'nl': 'Nederlands (Dutch)', - 'pl': 'Polski (Polish)', - 'pt': 'Português (Portuguese)', - 'ru': 'Русский (Russian)', - 'uk': 'Українська (Ukrainian)', - 'zh': '中文 (Chinese)' -}; - -class Language with ChangeNotifier { - Language(this._currentLanguage); - - String _currentLanguage; - - String getCurrentLanguage() => _currentLanguage; - - void setCurrentLanguage(String language) { - _currentLanguage = language; - notifyListeners(); - } - - static Future localeDetection() async { - var locale = await Devicelocale.currentLocale; - locale = Intl.shortLocale(locale); - - return languages.keys.contains(locale) ? locale : 'en'; - } -} \ No newline at end of file diff --git a/lib/entities/language_service.dart b/lib/entities/language_service.dart new file mode 100644 index 000000000..4ea158353 --- /dev/null +++ b/lib/entities/language_service.dart @@ -0,0 +1,26 @@ +import 'package:devicelocale/devicelocale.dart'; +import 'package:intl/intl.dart'; + +class LanguageService { + static const Map list = { + 'en': 'English', + 'de': 'Deutsch (German)', + 'es': 'Español (Spanish)', + 'hi': 'हिंदी (Hindi)', + 'ja': '日本 (Japanese)', + 'ko': '한국어 (Korean)', + 'nl': 'Nederlands (Dutch)', + 'pl': 'Polski (Polish)', + 'pt': 'Português (Portuguese)', + 'ru': 'Русский (Russian)', + 'uk': 'Українська (Ukrainian)', + 'zh': '中文 (Chinese)' + }; + + static Future localeDetection() async { + var locale = await Devicelocale.currentLocale; + locale = Intl.shortLocale(locale); + + return list.keys.contains(locale) ? locale : 'en'; + } +} diff --git a/lib/entities/node.dart b/lib/entities/node.dart index f79b8b2e0..d96834dcb 100644 --- a/lib/entities/node.dart +++ b/lib/entities/node.dart @@ -61,24 +61,28 @@ class Node extends HiveObject with Keyable { } Future requestMoneroNode() async { - Map resBody; + try { + Map resBody; - if (login != null && password != null) { - final digestRequest = DigestRequest(); - final response = await digestRequest.request( - uri: uri, login: login, password: password); - resBody = response.data as Map; - } else { - final url = Uri.http(uri, '/json_rpc'); - final headers = {'Content-type': 'application/json'}; - final body = - json.encode({'jsonrpc': '2.0', 'id': '0', 'method': 'get_info'}); - final response = - await http.post(url.toString(), headers: headers, body: body); - resBody = json.decode(response.body) as Map; + if (login != null && password != null) { + final digestRequest = DigestRequest(); + final response = await digestRequest.request( + uri: uri, login: login, password: password); + resBody = response.data as Map; + } else { + final url = Uri.http(uri, '/json_rpc'); + final headers = {'Content-type': 'application/json'}; + final body = + json.encode({'jsonrpc': '2.0', 'id': '0', 'method': 'get_info'}); + final response = + await http.post(url.toString(), headers: headers, body: body); + resBody = json.decode(response.body) as Map; + } + + return !(resBody['result']['offline'] as bool); + } catch (_) { + return false; } - - return !(resBody['result']['offline'] as bool); } Future requestBitcoinElectrumServer() async { diff --git a/lib/entities/record.dart b/lib/entities/record.dart index 3c21441cc..1ca661684 100644 --- a/lib/entities/record.dart +++ b/lib/entities/record.dart @@ -5,6 +5,7 @@ import 'package:hive/hive.dart'; abstract class Record with Keyable { Record(this._source, this.original) { + key = original.key; _listener?.cancel(); _listener = _source.watch(key: original.key).listen((event) { if (!event.deleted) { @@ -16,7 +17,7 @@ abstract class Record with Keyable { toBind(original); } - dynamic get key => original.key; + dynamic key; @override dynamic get keyIndex => key; diff --git a/lib/main.dart b/lib/main.dart index 66cca43a5..4a49b646a 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -1,66 +1,30 @@ -import 'package:cake_wallet/entities/fs_migration.dart'; -import 'package:cake_wallet/entities/transaction_description.dart'; -import 'package:cake_wallet/entities/transaction_description.dart'; -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'; -import 'package:cake_wallet/bitcoin/bitcoin_wallet_service.dart'; -import 'package:cake_wallet/monero/monero_wallet_service.dart'; -import 'package:cake_wallet/core/wallet_creation_service.dart'; -import 'package:cake_wallet/di.dart'; -import 'package:cake_wallet/view_model/wallet_new_vm.dart'; -import 'package:flutter_localizations/flutter_localizations.dart'; -import 'package:get_it/get_it.dart'; -import 'package:path_provider/path_provider.dart'; -import 'package:shared_preferences/shared_preferences.dart'; -import 'package:flutter_secure_storage/flutter_secure_storage.dart'; -import 'package:provider/provider.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:hive/hive.dart'; +import 'package:cake_wallet/di.dart'; +import 'package:path_provider/path_provider.dart'; +import 'package:shared_preferences/shared_preferences.dart'; +import 'package:flutter_localizations/flutter_localizations.dart'; +import 'package:flutter_secure_storage/flutter_secure_storage.dart'; +import 'package:flutter_mobx/flutter_mobx.dart'; import 'package:cw_monero/wallet.dart' as monero_wallet; import 'package:cake_wallet/router.dart'; -import 'theme_changer.dart'; -import 'themes.dart'; +import 'package:cake_wallet/routes.dart'; +import 'package:cake_wallet/generated/i18n.dart'; +import 'package:cake_wallet/reactions/bootstrap.dart'; +import 'package:cake_wallet/store/app_store.dart'; +import 'package:cake_wallet/store/authentication_store.dart'; +import 'package:cake_wallet/entities/transaction_description.dart'; import 'package:cake_wallet/entities/get_encryption_key.dart'; import 'package:cake_wallet/entities/contact.dart'; import 'package:cake_wallet/entities/node.dart'; import 'package:cake_wallet/entities/wallet_info.dart'; -import 'package:cake_wallet/exchange/trade.dart'; - -// import 'package:cake_wallet/monero/transaction_description.dart'; -import 'package:cake_wallet/src/reactions/set_reactions.dart'; - -// import 'package:cake_wallet/src/stores/login/login_store.dart'; -// import 'package:cake_wallet/src/stores/balance/balance_store.dart'; -// import 'package:cake_wallet/src/stores/sync/sync_store.dart'; -// import 'package:cake_wallet/src/stores/wallet/wallet_store.dart'; -// import 'package:cake_wallet/src/stores/send_template/send_template_store.dart'; -// import 'package:cake_wallet/src/stores/exchange_template/exchange_template_store.dart'; -import 'package:cake_wallet/src/screens/root/root.dart'; - -//import 'package:cake_wallet/src/stores/authentication/authentication_store.dart'; -// import 'package:cake_wallet/src/stores/settings/settings_store.dart'; -// import 'package:cake_wallet/src/stores/price/price_store.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/entities/balance_display_mode.dart'; import 'package:cake_wallet/entities/default_settings_migration.dart'; -import 'package:cake_wallet/entities/fiat_currency.dart'; -import 'package:cake_wallet/entities/transaction_priority.dart'; import 'package:cake_wallet/entities/wallet_type.dart'; import 'package:cake_wallet/entities/template.dart'; +import 'package:cake_wallet/exchange/trade.dart'; import 'package:cake_wallet/exchange/exchange_template.dart'; - -// import 'package:cake_wallet/src/domain/services/wallet_service.dart'; -// import 'package:cake_wallet/src/domain/services/fiat_convertation_service.dart'; -import 'package:cake_wallet/generated/i18n.dart'; -import 'package:cake_wallet/entities/language.dart'; -// import 'package:cake_wallet/src/stores/seed_language/seed_language_store.dart'; - -bool isThemeChangerRegistered = false; +import 'package:cake_wallet/src/screens/root/root.dart'; final navigatorKey = GlobalKey(); @@ -94,41 +58,6 @@ void main() async { final templates = await Hive.openBox