From d5d1afd89b62344332e0c2473d7154267041d41f Mon Sep 17 00:00:00 2001 From: OleksandrSobol Date: Mon, 7 Jun 2021 16:40:25 +0300 Subject: [PATCH] CAKE-306 | merged main branch into current; added _fetchBuyItems() method to buy_view_model.dart; deleted isMoonPayEnabled parameter from settings_store.dart --- lib/di.dart | 14 +-------- lib/entities/push_notifications_service.dart | 2 +- lib/store/settings_store.dart | 16 ---------- lib/view_model/buy/buy_view_model.dart | 31 +++++++++++++------- res/values/strings_hr.arb | 2 ++ res/values/strings_it.arb | 2 ++ 6 files changed, 27 insertions(+), 40 deletions(-) diff --git a/lib/di.dart b/lib/di.dart index eda81d899..0de43a76e 100644 --- a/lib/di.dart +++ b/lib/di.dart @@ -1,11 +1,9 @@ import 'package:cake_wallet/bitcoin/bitcoin_wallet_service.dart'; import 'package:cake_wallet/bitcoin/litecoin_wallet_service.dart'; -import 'package:cake_wallet/buy/moonpay/moonpay_buy_provider.dart'; import 'package:cake_wallet/core/backup_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'; -import 'package:cake_wallet/entities/load_current_wallet.dart'; import 'package:cake_wallet/buy/order.dart'; import 'package:cake_wallet/entities/transaction_description.dart'; import 'package:cake_wallet/entities/transaction_info.dart'; @@ -92,7 +90,6 @@ import 'package:cake_wallet/view_model/wallet_list/wallet_list_view_model.dart'; import 'package:cake_wallet/view_model/wallet_restore_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:devicelocale/devicelocale.dart'; import 'package:flutter/widgets.dart'; import 'package:get_it/get_it.dart'; import 'package:hive/hive.dart'; @@ -156,17 +153,8 @@ Future setup( (secrets.wyreApiKey?.isNotEmpty ?? false) && (secrets.wyreAccountId?.isNotEmpty ?? false); - var isMoonPayEnabled = false; - try { - isMoonPayEnabled = await MoonPayBuyProvider.onEnabled(); - } catch (e) { - isMoonPayEnabled = false; - print(e.toString()); - } - final settingsStore = await SettingsStoreBase.load( - nodeSource: _nodeSource, isBitcoinBuyEnabled: isBitcoinBuyEnabled, - isMoonPayEnabled: isMoonPayEnabled); + nodeSource: _nodeSource, isBitcoinBuyEnabled: isBitcoinBuyEnabled); if (_isSetupFinished) { return; diff --git a/lib/entities/push_notifications_service.dart b/lib/entities/push_notifications_service.dart index 5fe69153c..5fb68bae4 100644 --- a/lib/entities/push_notifications_service.dart +++ b/lib/entities/push_notifications_service.dart @@ -21,7 +21,7 @@ class PushNotificationsService { _firebaseMessaging.requestNotificationPermissions(); _firebaseMessaging.configure( onMessage: (message) async { - Map alert = {}; + Map alert = {}; String msg = ''; String title = ''; diff --git a/lib/store/settings_store.dart b/lib/store/settings_store.dart index 206c3141b..66124a108 100644 --- a/lib/store/settings_store.dart +++ b/lib/store/settings_store.dart @@ -1,5 +1,4 @@ import 'package:cake_wallet/bitcoin/bitcoin_transaction_priority.dart'; -import 'package:cake_wallet/buy/moonpay/moonpay_buy_provider.dart'; import 'package:cake_wallet/entities/preferences_key.dart'; import 'package:cake_wallet/entities/transaction_priority.dart'; import 'package:cake_wallet/themes/theme_base.dart'; @@ -9,7 +8,6 @@ import 'package:flutter/material.dart'; import 'package:hive/hive.dart'; import 'package:mobx/mobx.dart'; import 'package:package_info/package_info.dart'; -import 'package:devicelocale/devicelocale.dart'; import 'package:cake_wallet/di.dart'; import 'package:cake_wallet/entities/wallet_type.dart'; import 'package:shared_preferences/shared_preferences.dart'; @@ -41,7 +39,6 @@ abstract class SettingsStoreBase with Store { @required TransactionPriority initialBitcoinTransactionPriority, @required TransactionPriority initialMoneroTransactionPriority, @required this.isBitcoinBuyEnabled, - @required this.isMoonPayEnabled, this.actionlistDisplayMode}) { fiatCurrency = initialFiatCurrency; balanceDisplayMode = initialBalanceDisplayMode; @@ -150,12 +147,9 @@ abstract class SettingsStoreBase with Store { bool isBitcoinBuyEnabled; - bool isMoonPayEnabled; - static Future load( {@required Box nodeSource, @required bool isBitcoinBuyEnabled, - @required bool isMoonPayEnabled, FiatCurrency initialFiatCurrency = FiatCurrency.usd, MoneroTransactionPriority initialMoneroTransactionPriority = MoneroTransactionPriority.slow, @@ -227,7 +221,6 @@ abstract class SettingsStoreBase with Store { }, appVersion: packageInfo.version, isBitcoinBuyEnabled: isBitcoinBuyEnabled, - isMoonPayEnabled: isMoonPayEnabled, initialFiatCurrency: currentFiatCurrency, initialBalanceDisplayMode: currentBalanceDisplayMode, initialSaveRecipientAddress: shouldSaveRecipientAddress, @@ -253,18 +246,9 @@ abstract class SettingsStoreBase with Store { (secrets.wyreApiKey?.isNotEmpty ?? false) && (secrets.wyreAccountId?.isNotEmpty ?? false); - var isMoonPayEnabled = false; - try { - isMoonPayEnabled = await MoonPayBuyProvider.onEnabled(); - } catch (e) { - isMoonPayEnabled = false; - print(e.toString()); - } - final settings = await SettingsStoreBase.load( nodeSource: nodeSource, isBitcoinBuyEnabled: isBitcoinBuyEnabled, - isMoonPayEnabled: isMoonPayEnabled, initialBalanceDisplayMode: initialBalanceDisplayMode, initialFiatCurrency: initialFiatCurrency, initialMoneroTransactionPriority: initialMoneroTransactionPriority, diff --git a/lib/view_model/buy/buy_view_model.dart b/lib/view_model/buy/buy_view_model.dart index 68afb9577..95739edd0 100644 --- a/lib/view_model/buy/buy_view_model.dart +++ b/lib/view_model/buy/buy_view_model.dart @@ -21,15 +21,9 @@ class BuyViewModel = BuyViewModelBase with _$BuyViewModel; abstract class BuyViewModelBase with Store { BuyViewModelBase(this.ordersSource, this.ordersStore, this.settingsStore, this.buyAmountViewModel, {@required this.wallet}) { - providerList = [WyreBuyProvider(wallet: wallet)]; - if (settingsStore.isMoonPayEnabled ?? false) { - providerList.add(MoonPayBuyProvider(wallet: wallet)); - } + _fetchBuyItems(); - items = providerList.map((provider) => - BuyItem(provider: provider, buyAmountViewModel: buyAmountViewModel)) - .toList(); isRunning = false; isDisabled = true; isShowProviderButtons = false; @@ -41,9 +35,6 @@ abstract class BuyViewModelBase with Store { final BuyAmountViewModel buyAmountViewModel; final WalletBase wallet; - @observable - List providerList; - @observable BuyProvider selectedProvider; @@ -96,4 +87,24 @@ abstract class BuyViewModelBase with Store { buyAmountViewModel.amount = ''; selectedProvider = null; } + + Future _fetchBuyItems() async { + final List _providerList = [WyreBuyProvider(wallet: wallet)]; + + var isMoonPayEnabled = false; + try { + isMoonPayEnabled = await MoonPayBuyProvider.onEnabled(); + } catch (e) { + isMoonPayEnabled = false; + print(e.toString()); + } + + if (isMoonPayEnabled) { + _providerList.add(MoonPayBuyProvider(wallet: wallet)); + } + + items = _providerList.map((provider) => + BuyItem(provider: provider, buyAmountViewModel: buyAmountViewModel)) + .toList(); + } } \ No newline at end of file diff --git a/res/values/strings_hr.arb b/res/values/strings_hr.arb index 0eb24134c..1d3233d0e 100644 --- a/res/values/strings_hr.arb +++ b/res/values/strings_hr.arb @@ -478,5 +478,7 @@ "apk_update" : "APK ažuriranje", + "buy_bitcoin" : "Kupite Bitcoin", + "buy_with" : "Kupite s", "moonpay_alert_text" : "Vrijednost iznosa mora biti veća ili jednaka ${minAmount} ${fiatCurrency}" } \ No newline at end of file diff --git a/res/values/strings_it.arb b/res/values/strings_it.arb index 7f8dc6499..00d88efd8 100644 --- a/res/values/strings_it.arb +++ b/res/values/strings_it.arb @@ -478,5 +478,7 @@ "apk_update" : "Aggiornamento APK", + "buy_bitcoin" : "Acquista Bitcoin", + "buy_with" : "Acquista con", "moonpay_alert_text" : "Il valore dell'importo deve essere maggiore o uguale a ${minAmount} ${fiatCurrency}" } \ No newline at end of file