CAKE-306 | merged main branch into current; added _fetchBuyItems() method to buy_view_model.dart; deleted isMoonPayEnabled parameter from settings_store.dart

This commit is contained in:
OleksandrSobol 2021-06-07 16:40:25 +03:00
parent 68f1e39620
commit d5d1afd89b
6 changed files with 27 additions and 40 deletions

View file

@ -1,11 +1,9 @@
import 'package:cake_wallet/bitcoin/bitcoin_wallet_service.dart'; import 'package:cake_wallet/bitcoin/bitcoin_wallet_service.dart';
import 'package:cake_wallet/bitcoin/litecoin_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/backup_service.dart';
import 'package:cake_wallet/core/wallet_service.dart'; import 'package:cake_wallet/core/wallet_service.dart';
import 'package:cake_wallet/entities/biometric_auth.dart'; import 'package:cake_wallet/entities/biometric_auth.dart';
import 'package:cake_wallet/entities/contact_record.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/buy/order.dart';
import 'package:cake_wallet/entities/transaction_description.dart'; import 'package:cake_wallet/entities/transaction_description.dart';
import 'package:cake_wallet/entities/transaction_info.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_restore_view_model.dart';
import 'package:cake_wallet/view_model/wallet_seed_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:cake_wallet/view_model/exchange/exchange_view_model.dart';
import 'package:devicelocale/devicelocale.dart';
import 'package:flutter/widgets.dart'; import 'package:flutter/widgets.dart';
import 'package:get_it/get_it.dart'; import 'package:get_it/get_it.dart';
import 'package:hive/hive.dart'; import 'package:hive/hive.dart';
@ -156,17 +153,8 @@ Future setup(
(secrets.wyreApiKey?.isNotEmpty ?? false) && (secrets.wyreApiKey?.isNotEmpty ?? false) &&
(secrets.wyreAccountId?.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( final settingsStore = await SettingsStoreBase.load(
nodeSource: _nodeSource, isBitcoinBuyEnabled: isBitcoinBuyEnabled, nodeSource: _nodeSource, isBitcoinBuyEnabled: isBitcoinBuyEnabled);
isMoonPayEnabled: isMoonPayEnabled);
if (_isSetupFinished) { if (_isSetupFinished) {
return; return;

View file

@ -21,7 +21,7 @@ class PushNotificationsService {
_firebaseMessaging.requestNotificationPermissions(); _firebaseMessaging.requestNotificationPermissions();
_firebaseMessaging.configure( _firebaseMessaging.configure(
onMessage: (message) async { onMessage: (message) async {
Map<dynamic, dynamic> alert = {}; Map<dynamic, dynamic> alert = <dynamic, dynamic>{};
String msg = ''; String msg = '';
String title = ''; String title = '';

View file

@ -1,5 +1,4 @@
import 'package:cake_wallet/bitcoin/bitcoin_transaction_priority.dart'; 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/preferences_key.dart';
import 'package:cake_wallet/entities/transaction_priority.dart'; import 'package:cake_wallet/entities/transaction_priority.dart';
import 'package:cake_wallet/themes/theme_base.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:hive/hive.dart';
import 'package:mobx/mobx.dart'; import 'package:mobx/mobx.dart';
import 'package:package_info/package_info.dart'; import 'package:package_info/package_info.dart';
import 'package:devicelocale/devicelocale.dart';
import 'package:cake_wallet/di.dart'; import 'package:cake_wallet/di.dart';
import 'package:cake_wallet/entities/wallet_type.dart'; import 'package:cake_wallet/entities/wallet_type.dart';
import 'package:shared_preferences/shared_preferences.dart'; import 'package:shared_preferences/shared_preferences.dart';
@ -41,7 +39,6 @@ abstract class SettingsStoreBase with Store {
@required TransactionPriority initialBitcoinTransactionPriority, @required TransactionPriority initialBitcoinTransactionPriority,
@required TransactionPriority initialMoneroTransactionPriority, @required TransactionPriority initialMoneroTransactionPriority,
@required this.isBitcoinBuyEnabled, @required this.isBitcoinBuyEnabled,
@required this.isMoonPayEnabled,
this.actionlistDisplayMode}) { this.actionlistDisplayMode}) {
fiatCurrency = initialFiatCurrency; fiatCurrency = initialFiatCurrency;
balanceDisplayMode = initialBalanceDisplayMode; balanceDisplayMode = initialBalanceDisplayMode;
@ -150,12 +147,9 @@ abstract class SettingsStoreBase with Store {
bool isBitcoinBuyEnabled; bool isBitcoinBuyEnabled;
bool isMoonPayEnabled;
static Future<SettingsStore> load( static Future<SettingsStore> load(
{@required Box<Node> nodeSource, {@required Box<Node> nodeSource,
@required bool isBitcoinBuyEnabled, @required bool isBitcoinBuyEnabled,
@required bool isMoonPayEnabled,
FiatCurrency initialFiatCurrency = FiatCurrency.usd, FiatCurrency initialFiatCurrency = FiatCurrency.usd,
MoneroTransactionPriority initialMoneroTransactionPriority = MoneroTransactionPriority initialMoneroTransactionPriority =
MoneroTransactionPriority.slow, MoneroTransactionPriority.slow,
@ -227,7 +221,6 @@ abstract class SettingsStoreBase with Store {
}, },
appVersion: packageInfo.version, appVersion: packageInfo.version,
isBitcoinBuyEnabled: isBitcoinBuyEnabled, isBitcoinBuyEnabled: isBitcoinBuyEnabled,
isMoonPayEnabled: isMoonPayEnabled,
initialFiatCurrency: currentFiatCurrency, initialFiatCurrency: currentFiatCurrency,
initialBalanceDisplayMode: currentBalanceDisplayMode, initialBalanceDisplayMode: currentBalanceDisplayMode,
initialSaveRecipientAddress: shouldSaveRecipientAddress, initialSaveRecipientAddress: shouldSaveRecipientAddress,
@ -253,18 +246,9 @@ abstract class SettingsStoreBase with Store {
(secrets.wyreApiKey?.isNotEmpty ?? false) && (secrets.wyreApiKey?.isNotEmpty ?? false) &&
(secrets.wyreAccountId?.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( final settings = await SettingsStoreBase.load(
nodeSource: nodeSource, nodeSource: nodeSource,
isBitcoinBuyEnabled: isBitcoinBuyEnabled, isBitcoinBuyEnabled: isBitcoinBuyEnabled,
isMoonPayEnabled: isMoonPayEnabled,
initialBalanceDisplayMode: initialBalanceDisplayMode, initialBalanceDisplayMode: initialBalanceDisplayMode,
initialFiatCurrency: initialFiatCurrency, initialFiatCurrency: initialFiatCurrency,
initialMoneroTransactionPriority: initialMoneroTransactionPriority, initialMoneroTransactionPriority: initialMoneroTransactionPriority,

View file

@ -21,15 +21,9 @@ class BuyViewModel = BuyViewModelBase with _$BuyViewModel;
abstract class BuyViewModelBase with Store { abstract class BuyViewModelBase with Store {
BuyViewModelBase(this.ordersSource, this.ordersStore, this.settingsStore, BuyViewModelBase(this.ordersSource, this.ordersStore, this.settingsStore,
this.buyAmountViewModel, {@required this.wallet}) { this.buyAmountViewModel, {@required this.wallet}) {
providerList = [WyreBuyProvider(wallet: wallet)];
if (settingsStore.isMoonPayEnabled ?? false) { _fetchBuyItems();
providerList.add(MoonPayBuyProvider(wallet: wallet));
}
items = providerList.map((provider) =>
BuyItem(provider: provider, buyAmountViewModel: buyAmountViewModel))
.toList();
isRunning = false; isRunning = false;
isDisabled = true; isDisabled = true;
isShowProviderButtons = false; isShowProviderButtons = false;
@ -41,9 +35,6 @@ abstract class BuyViewModelBase with Store {
final BuyAmountViewModel buyAmountViewModel; final BuyAmountViewModel buyAmountViewModel;
final WalletBase wallet; final WalletBase wallet;
@observable
List<BuyProvider> providerList;
@observable @observable
BuyProvider selectedProvider; BuyProvider selectedProvider;
@ -96,4 +87,24 @@ abstract class BuyViewModelBase with Store {
buyAmountViewModel.amount = ''; buyAmountViewModel.amount = '';
selectedProvider = null; selectedProvider = null;
} }
Future<void> _fetchBuyItems() async {
final List<BuyProvider> _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();
}
} }

View file

@ -478,5 +478,7 @@
"apk_update" : "APK ažuriranje", "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}" "moonpay_alert_text" : "Vrijednost iznosa mora biti veća ili jednaka ${minAmount} ${fiatCurrency}"
} }

View file

@ -478,5 +478,7 @@
"apk_update" : "Aggiornamento APK", "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}" "moonpay_alert_text" : "Il valore dell'importo deve essere maggiore o uguale a ${minAmount} ${fiatCurrency}"
} }