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
+21 -10
View File
@@ -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<BuyProvider> providerList;
@observable
BuyProvider selectedProvider;
@@ -96,4 +87,24 @@ abstract class BuyViewModelBase with Store {
buyAmountViewModel.amount = '';
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();
}
}