CAKE-306 | fixed onEnabled() method in the moonpay_buy_provider.dart

This commit is contained in:
OleksandrSobol 2021-06-07 14:28:53 +03:00
parent ee6b8767d6
commit 6ac8dabf87
3 changed files with 13 additions and 25 deletions

View file

@ -23,7 +23,7 @@ class MoonPayBuyProvider extends BuyProvider {
static const _currenciesSuffix = '/v3/currencies'; static const _currenciesSuffix = '/v3/currencies';
static const _quoteSuffix = '/buy_quote'; static const _quoteSuffix = '/buy_quote';
static const _transactionsSuffix = '/v1/transactions'; static const _transactionsSuffix = '/v1/transactions';
static const _countrySuffix = '/v3/countries'; static const _ipAddressSuffix = '/v4/ip_address';
static const _apiKey = secrets.moonPayApiKey; static const _apiKey = secrets.moonPayApiKey;
static const _secretKey = secrets.moonPaySecretKey; static const _secretKey = secrets.moonPaySecretKey;
@ -125,23 +125,15 @@ class MoonPayBuyProvider extends BuyProvider {
); );
} }
static Future<bool> onEnabled(String deviceCountryCode) async { static Future<bool> onEnabled() async {
final url = _apiUrl + _countrySuffix; final url = _apiUrl + _ipAddressSuffix + '?apiKey=' + _apiKey;
var isBuyEnable = false; var isBuyEnable = false;
final response = await get(url); final response = await get(url);
try { try {
final responseJSON = json.decode(response.body) as List<dynamic>; final responseJSON = json.decode(response.body) as Map<String, dynamic>;
isBuyEnable = responseJSON['isBuyAllowed'] as bool;
for (var element in responseJSON) {
final countryMap = element as Map<String, dynamic>;
final countryCode = countryMap['alpha2'] as String;
if (countryCode == deviceCountryCode) {
isBuyEnable = countryMap['isBuyAllowed'] as bool;
break;
}
}
} catch (e) { } catch (e) {
isBuyEnable = false; isBuyEnable = false;
print(e.toString()); print(e.toString());

View file

@ -155,19 +155,17 @@ Future setup(
(secrets.wyreApiKey?.isNotEmpty ?? false) && (secrets.wyreApiKey?.isNotEmpty ?? false) &&
(secrets.wyreAccountId?.isNotEmpty ?? false); (secrets.wyreAccountId?.isNotEmpty ?? false);
/*var isMoonPayEnabled = false; var isMoonPayEnabled = false;
try { try {
final locale = await Devicelocale.currentLocale; isMoonPayEnabled = await MoonPayBuyProvider.onEnabled();
final deviceCountryCode = locale.split('_').last;
isMoonPayEnabled = await MoonPayBuyProvider.onEnabled(deviceCountryCode);
} catch (e) { } catch (e) {
isMoonPayEnabled = false; isMoonPayEnabled = false;
print(e.toString()); print(e.toString());
}*/ }
final settingsStore = await SettingsStoreBase.load( final settingsStore = await SettingsStoreBase.load(
nodeSource: _nodeSource, isBitcoinBuyEnabled: isBitcoinBuyEnabled, nodeSource: _nodeSource, isBitcoinBuyEnabled: isBitcoinBuyEnabled,
isMoonPayEnabled: true); isMoonPayEnabled: isMoonPayEnabled);
if (_isSetupFinished) { if (_isSetupFinished) {
return; return;

View file

@ -253,20 +253,18 @@ abstract class SettingsStoreBase with Store {
(secrets.wyreApiKey?.isNotEmpty ?? false) && (secrets.wyreApiKey?.isNotEmpty ?? false) &&
(secrets.wyreAccountId?.isNotEmpty ?? false); (secrets.wyreAccountId?.isNotEmpty ?? false);
/*var isMoonPayEnabled = false; var isMoonPayEnabled = false;
try { try {
final locale = await Devicelocale.currentLocale; isMoonPayEnabled = await MoonPayBuyProvider.onEnabled();
final deviceCountryCode = locale.split('_').last;
isMoonPayEnabled = await MoonPayBuyProvider.onEnabled(deviceCountryCode);
} catch (e) { } catch (e) {
isMoonPayEnabled = false; isMoonPayEnabled = false;
print(e.toString()); print(e.toString());
}*/ }
final settings = await SettingsStoreBase.load( final settings = await SettingsStoreBase.load(
nodeSource: nodeSource, nodeSource: nodeSource,
isBitcoinBuyEnabled: isBitcoinBuyEnabled, isBitcoinBuyEnabled: isBitcoinBuyEnabled,
isMoonPayEnabled: true, isMoonPayEnabled: isMoonPayEnabled,
initialBalanceDisplayMode: initialBalanceDisplayMode, initialBalanceDisplayMode: initialBalanceDisplayMode,
initialFiatCurrency: initialFiatCurrency, initialFiatCurrency: initialFiatCurrency,
initialMoneroTransactionPriority: initialMoneroTransactionPriority, initialMoneroTransactionPriority: initialMoneroTransactionPriority,