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 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,

View file

@ -350,17 +350,20 @@ class _BuyFormState extends ConsumerState<BuyForm> {
),
);
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) {

View file

@ -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);