pass receiving address on to preview sheet

This commit is contained in:
sneurlax 2023-01-16 18:08:37 -06:00
parent d9b1fb1fc7
commit e6a19d981d
3 changed files with 23 additions and 30 deletions

View file

@ -8,11 +8,11 @@ class SimplexQuote {
final Crypto crypto; final Crypto crypto;
final Fiat fiat; final Fiat fiat;
final Decimal youPayFiatPrice; late final Decimal youPayFiatPrice;
final Decimal youReceiveCryptoAmount; late final Decimal youReceiveCryptoAmount;
final String purchaseId; late final String purchaseId;
final String receivingAddress; late final String receivingAddress;
SimplexQuote({ SimplexQuote({
required this.crypto, required this.crypto,

View file

@ -350,17 +350,20 @@ class _BuyFormState extends ConsumerState<BuyForm> {
), ),
); );
buyWithFiat;
quote = SimplexQuote( quote = SimplexQuote(
crypto: selectedCrypto!, crypto: selectedCrypto!,
fiat: selectedFiat!, fiat: selectedFiat!,
youPayFiatPrice: Decimal.parse(_buyAmountController.text), youPayFiatPrice: buyWithFiat
youReceiveCryptoAmount: Decimal.parse("1.021312"), // Ternary for this ? Decimal.parse(_buyAmountController.text)
purchaseId: "Someid", : 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, receivingAddress: _receiveAddressController.text,
); );
print(quote.purchaseId);
await _loadQuote(quote); await _loadQuote(quote);
shouldPop = true; shouldPop = true;
if (mounted) { if (mounted) {

View file

@ -132,6 +132,8 @@ class SimplexAPI {
final jsonArray = jsonDecode(res.body); final jsonArray = jsonDecode(res.body);
jsonArray['quote'] = quote; // Add and pass this on
return await compute(_parseQuote, jsonArray); return await compute(_parseQuote, jsonArray);
} catch (e, s) { } catch (e, s) {
Logging.instance.log("getAvailableCurrencies exception: $e\n$s", Logging.instance.log("getAvailableCurrencies exception: $e\n$s",
@ -150,28 +152,16 @@ class SimplexAPI {
String fiatPrice = "${jsonArray['result']['fiat_money']['total_amount']}"; String fiatPrice = "${jsonArray['result']['fiat_money']['total_amount']}";
String cryptoAmount = "${jsonArray['result']['digital_money']['amount']}"; String cryptoAmount = "${jsonArray['result']['digital_money']['amount']}";
final quote = SimplexQuote( SimplexQuote quote = jsonArray['quote'] as SimplexQuote;
crypto: Crypto.fromJson({ final SimplexQuote _quote = SimplexQuote(
'ticker': jsonArray['result']['digital_money'][ crypto: quote.crypto,
'currency'], // // TODO a Crypto.fromTicker here, requiring enums there? fiat: quote.fiat,
'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), youPayFiatPrice: Decimal.parse(fiatPrice),
youReceiveCryptoAmount: Decimal.parse(cryptoAmount), youReceiveCryptoAmount: Decimal.parse(cryptoAmount),
purchaseId: jsonArray['result']['quote_id'] as String, purchaseId: jsonArray['result']['quote_id'] as String,
receivingAddress: '', receivingAddress: quote.receivingAddress);
);
//
// try {
return BuyResponse(value: quote); return BuyResponse(value: _quote);
} catch (e, s) { } catch (e, s) {
Logging.instance Logging.instance
.log("_parseSupported exception: $e\n$s", level: LogLevel.Error); .log("_parseSupported exception: $e\n$s", level: LogLevel.Error);