diff --git a/lib/models/buy/response_objects/quote.dart b/lib/models/buy/response_objects/quote.dart index b422ff1af..121275248 100644 --- a/lib/models/buy/response_objects/quote.dart +++ b/lib/models/buy/response_objects/quote.dart @@ -8,11 +8,11 @@ class SimplexQuote { final Crypto crypto; final Fiat fiat; - final Decimal youPayFiatPrice; - final Decimal youReceiveCryptoAmount; + late final Decimal youPayFiatPrice; + late final Decimal youReceiveCryptoAmount; - final String purchaseId; - final String receivingAddress; + late final String purchaseId; + late final String receivingAddress; SimplexQuote({ required this.crypto, diff --git a/lib/pages/buy_view/buy_form.dart b/lib/pages/buy_view/buy_form.dart index ebcd60f70..75ae7f7c1 100644 --- a/lib/pages/buy_view/buy_form.dart +++ b/lib/pages/buy_view/buy_form.dart @@ -350,17 +350,20 @@ class _BuyFormState extends ConsumerState { ), ); + buyWithFiat; quote = SimplexQuote( crypto: selectedCrypto!, fiat: selectedFiat!, - youPayFiatPrice: Decimal.parse(_buyAmountController.text), - youReceiveCryptoAmount: Decimal.parse("1.021312"), // Ternary for this - purchaseId: "Someid", + youPayFiatPrice: buyWithFiat + ? Decimal.parse(_buyAmountController.text) + : Decimal.parse("100"), // dummy value + youReceiveCryptoAmount: buyWithFiat + ? Decimal.parse("0.000420282") // dummy value + : Decimal.parse(_buyAmountController.text), // Ternary for this + purchaseId: "purchaseId", // anything; we get an ID back receivingAddress: _receiveAddressController.text, ); - print(quote.purchaseId); - await _loadQuote(quote); shouldPop = true; if (mounted) { diff --git a/lib/services/buy/simplex/simplex_api.dart b/lib/services/buy/simplex/simplex_api.dart index 8e0ecc32f..a49f1496f 100644 --- a/lib/services/buy/simplex/simplex_api.dart +++ b/lib/services/buy/simplex/simplex_api.dart @@ -132,6 +132,8 @@ class SimplexAPI { final jsonArray = jsonDecode(res.body); + jsonArray['quote'] = quote; // Add and pass this on + return await compute(_parseQuote, jsonArray); } catch (e, s) { Logging.instance.log("getAvailableCurrencies exception: $e\n$s", @@ -150,28 +152,16 @@ class SimplexAPI { String fiatPrice = "${jsonArray['result']['fiat_money']['total_amount']}"; String cryptoAmount = "${jsonArray['result']['digital_money']['amount']}"; - final quote = SimplexQuote( - crypto: Crypto.fromJson({ - 'ticker': jsonArray['result']['digital_money'][ - 'currency'], // // TODO a Crypto.fromTicker here, requiring enums there? - 'name': 'Bitcoin', - 'image': '' - }), - fiat: Fiat.fromJson({ - 'ticker': jsonArray['result']['fiat_money'][ - 'currency'], // // TODO a Fiat.fromTicker here, requiring enums there? - 'name': 'Bitcoin', - 'image': '' - }), - youPayFiatPrice: Decimal.parse(fiatPrice), - youReceiveCryptoAmount: Decimal.parse(cryptoAmount), - purchaseId: jsonArray['result']['quote_id'] as String, - receivingAddress: '', - ); - // - // try { + SimplexQuote quote = jsonArray['quote'] as SimplexQuote; + final SimplexQuote _quote = SimplexQuote( + crypto: quote.crypto, + fiat: quote.fiat, + youPayFiatPrice: Decimal.parse(fiatPrice), + youReceiveCryptoAmount: Decimal.parse(cryptoAmount), + purchaseId: jsonArray['result']['quote_id'] as String, + receivingAddress: quote.receivingAddress); - return BuyResponse(value: quote); + return BuyResponse(value: _quote); } catch (e, s) { Logging.instance .log("_parseSupported exception: $e\n$s", level: LogLevel.Error);