From 6ac8dabf87a8402bbc548367251680a83f077564 Mon Sep 17 00:00:00 2001 From: OleksandrSobol Date: Mon, 7 Jun 2021 14:28:53 +0300 Subject: [PATCH] CAKE-306 | fixed onEnabled() method in the moonpay_buy_provider.dart --- lib/buy/moonpay/moonpay_buy_provider.dart | 18 +++++------------- lib/di.dart | 10 ++++------ lib/store/settings_store.dart | 10 ++++------ 3 files changed, 13 insertions(+), 25 deletions(-) diff --git a/lib/buy/moonpay/moonpay_buy_provider.dart b/lib/buy/moonpay/moonpay_buy_provider.dart index 22b349c79..65effe483 100644 --- a/lib/buy/moonpay/moonpay_buy_provider.dart +++ b/lib/buy/moonpay/moonpay_buy_provider.dart @@ -23,7 +23,7 @@ class MoonPayBuyProvider extends BuyProvider { static const _currenciesSuffix = '/v3/currencies'; static const _quoteSuffix = '/buy_quote'; static const _transactionsSuffix = '/v1/transactions'; - static const _countrySuffix = '/v3/countries'; + static const _ipAddressSuffix = '/v4/ip_address'; static const _apiKey = secrets.moonPayApiKey; static const _secretKey = secrets.moonPaySecretKey; @@ -125,23 +125,15 @@ class MoonPayBuyProvider extends BuyProvider { ); } - static Future onEnabled(String deviceCountryCode) async { - final url = _apiUrl + _countrySuffix; + static Future onEnabled() async { + final url = _apiUrl + _ipAddressSuffix + '?apiKey=' + _apiKey; var isBuyEnable = false; final response = await get(url); try { - final responseJSON = json.decode(response.body) as List; - - for (var element in responseJSON) { - final countryMap = element as Map; - final countryCode = countryMap['alpha2'] as String; - if (countryCode == deviceCountryCode) { - isBuyEnable = countryMap['isBuyAllowed'] as bool; - break; - } - } + final responseJSON = json.decode(response.body) as Map; + isBuyEnable = responseJSON['isBuyAllowed'] as bool; } catch (e) { isBuyEnable = false; print(e.toString()); diff --git a/lib/di.dart b/lib/di.dart index b5bb7bfd3..a4e922f7c 100644 --- a/lib/di.dart +++ b/lib/di.dart @@ -155,19 +155,17 @@ Future setup( (secrets.wyreApiKey?.isNotEmpty ?? false) && (secrets.wyreAccountId?.isNotEmpty ?? false); - /*var isMoonPayEnabled = false; + var isMoonPayEnabled = false; try { - final locale = await Devicelocale.currentLocale; - final deviceCountryCode = locale.split('_').last; - isMoonPayEnabled = await MoonPayBuyProvider.onEnabled(deviceCountryCode); + isMoonPayEnabled = await MoonPayBuyProvider.onEnabled(); } catch (e) { isMoonPayEnabled = false; print(e.toString()); - }*/ + } final settingsStore = await SettingsStoreBase.load( nodeSource: _nodeSource, isBitcoinBuyEnabled: isBitcoinBuyEnabled, - isMoonPayEnabled: true); + isMoonPayEnabled: isMoonPayEnabled); if (_isSetupFinished) { return; diff --git a/lib/store/settings_store.dart b/lib/store/settings_store.dart index 207a731c9..206c3141b 100644 --- a/lib/store/settings_store.dart +++ b/lib/store/settings_store.dart @@ -253,20 +253,18 @@ abstract class SettingsStoreBase with Store { (secrets.wyreApiKey?.isNotEmpty ?? false) && (secrets.wyreAccountId?.isNotEmpty ?? false); - /*var isMoonPayEnabled = false; + var isMoonPayEnabled = false; try { - final locale = await Devicelocale.currentLocale; - final deviceCountryCode = locale.split('_').last; - isMoonPayEnabled = await MoonPayBuyProvider.onEnabled(deviceCountryCode); + isMoonPayEnabled = await MoonPayBuyProvider.onEnabled(); } catch (e) { isMoonPayEnabled = false; print(e.toString()); - }*/ + } final settings = await SettingsStoreBase.load( nodeSource: nodeSource, isBitcoinBuyEnabled: isBitcoinBuyEnabled, - isMoonPayEnabled: true, + isMoonPayEnabled: isMoonPayEnabled, initialBalanceDisplayMode: initialBalanceDisplayMode, initialFiatCurrency: initialFiatCurrency, initialMoneroTransactionPriority: initialMoneroTransactionPriority,