CWA-199 | changed possibility to enter amount in the deposit card only (exchange page); changed request for XMRTOExchangeProvider in the createTrade() (exchange_store); fixed calculation limits for XMR in the fetchLimits(), fixed post body in the createTrade() (xmrto_exchange_provider); created limits_format

This commit is contained in:
Oleksandr Sobol
2020-04-13 19:05:27 +03:00
parent b85c332b24
commit ef750cb454
4 changed files with 43 additions and 42 deletions
@@ -0,0 +1,7 @@
import 'package:intl/intl.dart';
final amountFormat = NumberFormat()
..maximumFractionDigits = 3
..minimumFractionDigits = 1;
double limitsFormat(double limit) => double.parse(amountFormat.format(limit));
@@ -12,6 +12,7 @@ import 'package:cake_wallet/src/domain/exchange/xmrto/xmrto_trade_request.dart';
import 'package:cake_wallet/src/domain/exchange/trade_not_created_exeption.dart';
import 'package:cake_wallet/src/domain/exchange/exchange_provider_description.dart';
import 'package:cake_wallet/src/domain/exchange/trade_not_found_exeption.dart';
import 'package:cake_wallet/src/domain/exchange/limits_format.dart';
class XMRTOExchangeProvider extends ExchangeProvider {
XMRTOExchangeProvider()
@@ -54,14 +55,31 @@ class XMRTOExchangeProvider extends ExchangeProvider {
Future<Limits> fetchLimits({CryptoCurrency from, CryptoCurrency to}) async {
final url = await getApiUri() + _orderParameterUriSufix;
final response = await get(url);
final correction = 0.001;
if (response.statusCode != 200) {
return Limits(min: 0, max: 0);
}
final responseJSON = json.decode(response.body) as Map<String, dynamic>;
final min = responseJSON['lower_limit'] as double;
final max = responseJSON['upper_limit'] as double;
double min = responseJSON['lower_limit'] as double;
double max = responseJSON['upper_limit'] as double;
final price = responseJSON['price'] as double;
if (price > 0) {
try {
min /= price;
min = limitsFormat(min) + correction;
max /= price;
max = limitsFormat(max);
} catch (e) {
min = 0;
max = 0;
}
} else {
min = 0;
max = 0;
}
return Limits(min: min, max: max);
}
@@ -71,7 +89,7 @@ class XMRTOExchangeProvider extends ExchangeProvider {
final _request = request as XMRTOTradeRequest;
final url = await getApiUri() + _orderCreateUriSufix;
final body = {
'btc_amount': _request.amount,
'xmr_amount': _request.amount,
'btc_dest_address': _request.address
};
final response = await post(url,
@@ -168,8 +186,7 @@ class XMRTOExchangeProvider extends ExchangeProvider {
final response =
await get(url, headers: {'Content-Type': 'application/json'});
final responseJSON = json.decode(response.body) as Map<String, dynamic>;
final btcprice = responseJSON['price'] as double;
final price = 1 / btcprice;
final price = responseJSON['price'] as double;
return price;
} catch (e) {