Force added User-Agent header field to all requests to xmr.to

This commit is contained in:
M 2020-12-15 20:41:06 +02:00
parent c20d57e9a9
commit 48c48bd3db

View file

@ -27,11 +27,14 @@ class XMRTOExchangeProvider extends ExchangeProvider {
static const _orderParameterUriSuffix = '/order_parameter_query'; static const _orderParameterUriSuffix = '/order_parameter_query';
static const _orderStatusUriSuffix = '/order_status_query/'; static const _orderStatusUriSuffix = '/order_status_query/';
static const _orderCreateUriSuffix = '/order_create/'; static const _orderCreateUriSuffix = '/order_create/';
static const _headers = {
'Content-Type': 'application/json',
'User-Agent': userAgent
};
static Future<bool> _checkIsAvailable() async { static Future<bool> _checkIsAvailable() async {
const url = originalApiUri + _orderParameterUriSuffix; const url = originalApiUri + _orderParameterUriSuffix;
final response = final response = await get(url, headers: _headers);
await get(url, headers: {'Content-Type': 'application/json'});
return !(response.statusCode == 403); return !(response.statusCode == 403);
} }
@ -91,9 +94,8 @@ class XMRTOExchangeProvider extends ExchangeProvider {
Future<Trade> createTrade({TradeRequest request}) async { Future<Trade> createTrade({TradeRequest request}) async {
final _request = request as XMRTOTradeRequest; final _request = request as XMRTOTradeRequest;
final url = originalApiUri + _orderCreateUriSuffix; final url = originalApiUri + _orderCreateUriSuffix;
final _amount = _request.isBTCRequest final _amount =
? _request.receiveAmount _request.isBTCRequest ? _request.receiveAmount : _request.amount;
: _request.amount;
final _amountCurrency = _request.isBTCRequest final _amountCurrency = _request.isBTCRequest
? _request.to.toString() ? _request.to.toString()
@ -112,8 +114,8 @@ class XMRTOExchangeProvider extends ExchangeProvider {
'amount_currency': _amountCurrency, 'amount_currency': _amountCurrency,
'btc_dest_address': _request.address 'btc_dest_address': _request.address
}; };
final response = await post(url, final response =
headers: {'Content-Type': 'application/json'}, body: json.encode(body)); await post(url, headers: _headers, body: json.encode(body));
if (response.statusCode != 201) { if (response.statusCode != 201) {
if (response.statusCode == 400) { if (response.statusCode == 400) {
@ -141,13 +143,10 @@ class XMRTOExchangeProvider extends ExchangeProvider {
@override @override
Future<Trade> findTradeById({@required String id}) async { Future<Trade> findTradeById({@required String id}) async {
const headers = {
'Content-Type': 'application/json',
'User-Agent': userAgent
};
final url = originalApiUri + _orderStatusUriSuffix; final url = originalApiUri + _orderStatusUriSuffix;
final body = {'uuid': id}; final body = {'uuid': id};
final response = await post(url, headers: headers, body: json.encode(body)); final response =
await post(url, headers: _headers, body: json.encode(body));
if (response.statusCode != 200) { if (response.statusCode != 200) {
if (response.statusCode == 400) { if (response.statusCode == 400) {
@ -210,8 +209,7 @@ class XMRTOExchangeProvider extends ExchangeProvider {
Future<double> _fetchRates() async { Future<double> _fetchRates() async {
try { try {
final url = originalApiUri + _orderParameterUriSuffix; final url = originalApiUri + _orderParameterUriSuffix;
final response = final response = await get(url, headers: _headers);
await get(url, headers: {'Content-Type': 'application/json'});
final responseJSON = json.decode(response.body) as Map<String, dynamic>; final responseJSON = json.decode(response.body) as Map<String, dynamic>;
final price = double.parse(responseJSON['price'] as String); final price = double.parse(responseJSON['price'] as String);