diff --git a/lib/services/exchange/trocador/response_objects/trocador_trade.dart b/lib/services/exchange/trocador/response_objects/trocador_trade.dart index ce0f1b933..5768a9423 100644 --- a/lib/services/exchange/trocador/response_objects/trocador_trade.dart +++ b/lib/services/exchange/trocador/response_objects/trocador_trade.dart @@ -1,5 +1,4 @@ import 'package:decimal/decimal.dart'; -import 'package:stackwallet/services/exchange/trocador/response_objects/trocador_quote.dart'; class TrocadorTrade { final String tradeId; @@ -23,7 +22,10 @@ class TrocadorTrade { final String refundAddressMemo; final String password; final String idProvider; - final List quotes; + + // dynamic is the devil but this could be anything... because json. + final dynamic quotes; + final bool payment; TrocadorTrade({ @@ -53,10 +55,6 @@ class TrocadorTrade { }); factory TrocadorTrade.fromMap(Map map) { - final list = - List>.from(map['quotes']['quotes'] as List); - final quotes = list.map((quote) => TrocadorQuote.fromMap(quote)).toList(); - return TrocadorTrade( tradeId: map['trade_id'] as String, date: DateTime.parse(map['date'] as String), @@ -79,14 +77,13 @@ class TrocadorTrade { refundAddressMemo: map['refund_address_memo'] as String, password: map['password'] as String, idProvider: map['id_provider'] as String, - quotes: quotes, + quotes: map['quotes'], payment: map['payment'] as bool, ); } @override String toString() { - final quotesString = quotes.map((quote) => quote.toString()).join(', '); return 'TrocadorTrade( ' 'tradeId: $tradeId, ' 'date: $date, ' @@ -109,7 +106,7 @@ class TrocadorTrade { 'refundAddressMemo: $refundAddressMemo, ' 'password: $password, ' 'idProvider: $idProvider, ' - 'quotes: [ $quotesString ], ' + 'quotes: $quotes, ' 'payment: $payment ' ')'; } diff --git a/lib/services/exchange/trocador/response_objects/trocador_trade_new.dart b/lib/services/exchange/trocador/response_objects/trocador_trade_new.dart index 7228ff781..4dc8ae380 100644 --- a/lib/services/exchange/trocador/response_objects/trocador_trade_new.dart +++ b/lib/services/exchange/trocador/response_objects/trocador_trade_new.dart @@ -14,8 +14,8 @@ class TrocadorTradeNew { final String provider; final bool fixed; final String status; - final String? addressProvider; - final String? addressProviderMemo; + final String addressProvider; + final String addressProviderMemo; final String addressUser; final String addressUserMemo; final String refundAddress; diff --git a/lib/services/exchange/trocador/trocador_api.dart b/lib/services/exchange/trocador/trocador_api.dart index e4d2ca582..36935cc0b 100644 --- a/lib/services/exchange/trocador/trocador_api.dart +++ b/lib/services/exchange/trocador/trocador_api.dart @@ -34,7 +34,7 @@ abstract class TrocadorAPI { static Future _makeGetRequest(Uri uri) async { int code = -1; try { - print("URI: $uri"); + // print("URI: $uri"); final response = await http.get( uri, headers: {'Content-Type': 'application/json'}, @@ -42,8 +42,8 @@ abstract class TrocadorAPI { code = response.statusCode; - print("CODE: $code"); - print("BODY: ${response.body}"); + // print("CODE: $code"); + // print("BODY: ${response.body}"); final json = jsonDecode(response.body); @@ -113,7 +113,7 @@ abstract class TrocadorAPI { try { final json = await _makeGetRequest(uri); - final map = Map.from(json as Map); + final map = Map.from((json as List).first as Map); return ExchangeResponse(value: TrocadorTrade.fromMap(map)); } catch (e, s) { @@ -128,7 +128,7 @@ abstract class TrocadorAPI { } /// get standard/floating rate - static Future> getNewStandardRate({ + static Future> getNewStandardRate({ required bool isOnion, required String fromTicker, required String fromNetwork, @@ -139,11 +139,12 @@ abstract class TrocadorAPI { final params = { "api_key": kTrocadorApiKey, "ref": kTrocadorRefCode, - "ticker_from": fromTicker, + "ticker_from": fromTicker.toLowerCase(), "network_from": fromNetwork, - "ticker_to": toTicker, + "ticker_to": toTicker.toLowerCase(), "network_to": toNetwork, "amount_from": fromAmount, + "payment": "false", "min_kycrating": minKYCRating, "markup": markup, }; @@ -152,7 +153,7 @@ abstract class TrocadorAPI { } /// get fixed rate/payment rate - static Future> getNewPaymentRate({ + static Future> getNewPaymentRate({ required bool isOnion, required String fromTicker, required String fromNetwork, @@ -163,11 +164,12 @@ abstract class TrocadorAPI { final params = { "api_key": kTrocadorApiKey, "ref": kTrocadorRefCode, - "ticker_from": fromTicker, + "ticker_from": fromTicker.toLowerCase(), "network_from": fromNetwork, - "ticker_to": toTicker, + "ticker_to": toTicker.toLowerCase(), "network_to": toNetwork, "amount_to": toAmount, + "payment": "true", "min_kycrating": minKYCRating, "markup": markup, }; @@ -221,10 +223,9 @@ abstract class TrocadorAPI { final Map params = { "api_key": kTrocadorApiKey, "ref": kTrocadorRefCode, - "id": rateId ?? "", - "ticker_from": fromTicker, + "ticker_from": fromTicker.toLowerCase(), "network_from": fromNetwork, - "ticker_to": toTicker, + "ticker_to": toTicker.toLowerCase(), "network_to": toNetwork, "amount_from": fromAmount, "address": receivingAddress, @@ -238,11 +239,16 @@ abstract class TrocadorAPI { "markup": markup, }; + if (rateId != null) { + params["id"] = rateId; + } + return await _getNewTrade(isOnion: isOnion, params: params); } static Future> createNewPaymentRateTrade({ required bool isOnion, + required String? rateId, required String fromTicker, required String fromNetwork, required String toTicker, @@ -258,9 +264,9 @@ abstract class TrocadorAPI { final params = { "api_key": kTrocadorApiKey, "ref": kTrocadorRefCode, - "ticker_from": fromTicker, + "ticker_from": fromTicker.toLowerCase(), "network_from": fromNetwork, - "ticker_to": toTicker, + "ticker_to": toTicker.toLowerCase(), "network_to": toNetwork, "amount_to": toAmount, "address": receivingAddress, @@ -274,6 +280,10 @@ abstract class TrocadorAPI { "markup": markup, }; + if (rateId != null) { + params["id"] = rateId; + } + return await _getNewTrade(isOnion: isOnion, params: params); }