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 _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<bool> onEnabled(String deviceCountryCode) async {
final url = _apiUrl + _countrySuffix;
static Future<bool> 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<dynamic>;
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;
}
}
final responseJSON = json.decode(response.body) as Map<String, dynamic>;
isBuyEnable = responseJSON['isBuyAllowed'] as bool;
} catch (e) {
isBuyEnable = false;
print(e.toString());

View file

@ -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;

View file

@ -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,