CAKE-306 | fixed onEnabled() method in the moonpay_buy_provider.dart
OleksandrSobol committed
Jun 7, 2021 at 14:28 UTC
6ac8dabf87a8402bbc548367251680a83f077564
3 files changed
+13
-25
lib/buy/moonpay/moonpay_buy_provider.dart
+5
-13
@@ -23,7 +23,7 @@ class MoonPayBuyProvider extends BuyProvider {
23
static const _currenciesSuffix = '/v3/currencies';
24
static const _quoteSuffix = '/buy_quote';
25
static const _transactionsSuffix = '/v1/transactions';
26
- static const _countrySuffix = '/v3/countries';
26
+ static const _ipAddressSuffix = '/v4/ip_address';
27
static const _apiKey = secrets.moonPayApiKey;
28
static const _secretKey = secrets.moonPaySecretKey;
29
@@ -125,23 +125,15 @@ class MoonPayBuyProvider extends BuyProvider {
125
);
126
}
127
128
- static Future<bool> onEnabled(String deviceCountryCode) async {
129
- final url = _apiUrl + _countrySuffix;
128
+ static Future<bool> onEnabled() async {
129
+ final url = _apiUrl + _ipAddressSuffix + '?apiKey=' + _apiKey;
130
var isBuyEnable = false;
131
132
final response = await get(url);
133
134
try {
135
- final responseJSON = json.decode(response.body) as List<dynamic>;
136
-
137
- for (var element in responseJSON) {
138
- final countryMap = element as Map<String, dynamic>;
139
- final countryCode = countryMap['alpha2'] as String;
140
- if (countryCode == deviceCountryCode) {
141
- isBuyEnable = countryMap['isBuyAllowed'] as bool;
142
- break;
143
- }
144
- }
135
+ final responseJSON = json.decode(response.body) as Map<String, dynamic>;
136
+ isBuyEnable = responseJSON['isBuyAllowed'] as bool;
137
} catch (e) {
138
isBuyEnable = false;
139
print(e.toString());
lib/di.dart
+4
-6
@@ -155,19 +155,17 @@ Future setup(
155
(secrets.wyreApiKey?.isNotEmpty ?? false) &&
156
(secrets.wyreAccountId?.isNotEmpty ?? false);
157
158
- /*var isMoonPayEnabled = false;
158
+ var isMoonPayEnabled = false;
159
try {
160
- final locale = await Devicelocale.currentLocale;
161
- final deviceCountryCode = locale.split('_').last;
162
- isMoonPayEnabled = await MoonPayBuyProvider.onEnabled(deviceCountryCode);
160
+ isMoonPayEnabled = await MoonPayBuyProvider.onEnabled();
161
} catch (e) {
162
isMoonPayEnabled = false;
163
print(e.toString());
166
- }*/
164
+ }
165
166
final settingsStore = await SettingsStoreBase.load(
167
nodeSource: _nodeSource, isBitcoinBuyEnabled: isBitcoinBuyEnabled,
170
- isMoonPayEnabled: true);
168
+ isMoonPayEnabled: isMoonPayEnabled);
169
170
if (_isSetupFinished) {
171
return;
lib/store/settings_store.dart
+4
-6
@@ -253,20 +253,18 @@ abstract class SettingsStoreBase with Store {
253
(secrets.wyreApiKey?.isNotEmpty ?? false) &&
254
(secrets.wyreAccountId?.isNotEmpty ?? false);
255
256
- /*var isMoonPayEnabled = false;
256
+ var isMoonPayEnabled = false;
257
try {
258
- final locale = await Devicelocale.currentLocale;
259
- final deviceCountryCode = locale.split('_').last;
260
- isMoonPayEnabled = await MoonPayBuyProvider.onEnabled(deviceCountryCode);
258
+ isMoonPayEnabled = await MoonPayBuyProvider.onEnabled();
259
} catch (e) {
260
isMoonPayEnabled = false;
261
print(e.toString());
264
- }*/
262
+ }
263
264
final settings = await SettingsStoreBase.load(
265
nodeSource: nodeSource,
266
isBitcoinBuyEnabled: isBitcoinBuyEnabled,
269
- isMoonPayEnabled: true,
267
+ isMoonPayEnabled: isMoonPayEnabled,
268
initialBalanceDisplayMode: initialBalanceDisplayMode,
269
initialFiatCurrency: initialFiatCurrency,
270
initialMoneroTransactionPriority: initialMoneroTransactionPriority,