add SimplexOrder model and return it from simplex API

TODO add redirect API call which url_launcher's the redirect endpoint
This commit is contained in:
sneurlax 2023-01-19 23:10:15 -06:00
parent 595d7e760d
commit 2ad0659cbc
5 changed files with 54 additions and 25 deletions

View file

@ -0,0 +1,17 @@
import 'package:stackwallet/models/buy/response_objects/quote.dart';
class SimplexOrder {
final SimplexQuote quote;
late final String paymentId;
late final String orderId;
late final String userId;
// TODO remove after userIds are sourced from isar/storage
SimplexOrder({
required this.quote,
required this.paymentId,
required this.orderId,
required this.userId,
});
}

View file

@ -3,8 +3,6 @@ import 'package:stackwallet/models/buy/response_objects/crypto.dart';
import 'package:stackwallet/models/buy/response_objects/fiat.dart';
class SimplexQuote {
// todo: this class
final Crypto crypto;
final Fiat fiat;
@ -16,12 +14,13 @@ class SimplexQuote {
late final bool buyWithFiat;
SimplexQuote(
{required this.crypto,
required this.fiat,
required this.youPayFiatPrice,
required this.youReceiveCryptoAmount,
required this.id,
required this.receivingAddress,
required this.buyWithFiat});
SimplexQuote({
required this.crypto,
required this.fiat,
required this.youPayFiatPrice,
required this.youReceiveCryptoAmount,
required this.id,
required this.receivingAddress,
required this.buyWithFiat,
});
}

View file

@ -1,3 +1,5 @@
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:flutter_svg/svg.dart';
import 'package:stackwallet/models/buy/response_objects/quote.dart';

View file

@ -1,6 +1,11 @@
import 'dart:async';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter_svg/svg.dart';
import 'package:stackwallet/models/buy/response_objects/order.dart';
import 'package:stackwallet/models/buy/response_objects/quote.dart';
import 'package:stackwallet/services/buy/buy_response.dart';
import 'package:stackwallet/services/buy/simplex/simplex_api.dart';
import 'package:stackwallet/utilities/assets.dart';
import 'package:stackwallet/widgets/desktop/primary_button.dart';
@ -15,8 +20,9 @@ class BuyWarningPopup extends StatelessWidget {
final SimplexQuote quote;
void newOrder(SimplexQuote quote) {
final response = SimplexAPI.instance.newOrder(quote);
Future<BuyResponse<SimplexOrder>> newOrder(SimplexQuote quote) async {
// BuyResponse<SimplexOrder> order = ;
return SimplexAPI.instance.newOrder(quote);
}
@override
@ -33,7 +39,8 @@ class BuyWarningPopup extends StatelessWidget {
rightButton: PrimaryButton(
label: "Continue",
onPressed: () async {
SimplexAPI.instance.newOrder(quote);
BuyResponse<SimplexOrder> order = await newOrder(quote);
// TODO save order and redirect
},
),
icon: SizedBox(

View file

@ -1,16 +1,14 @@
import 'dart:async';
import 'dart:convert';
import 'package:decimal/decimal.dart';
import 'package:flutter/foundation.dart';
import 'package:http/http.dart' as http;
import 'package:stackwallet/models/buy/response_objects/crypto.dart';
// import 'package:stackwallet/models/exchange/response_objects/fixed_rate_market.dart';
// import 'package:stackwallet/models/exchange/response_objects/pair.dart';
// import 'package:stackwallet/models/exchange/response_objects/range.dart';
// import 'package:stackwallet/models/exchange/response_objects/trade.dart';
import 'package:stackwallet/models/buy/response_objects/fiat.dart';
import 'package:stackwallet/models/buy/response_objects/quote.dart';
// import 'package:stackwallet/models/buy/response_objects/crypto.dart';
import 'package:stackwallet/models/buy/response_objects/fiat.dart';
import 'package:stackwallet/models/buy/response_objects/order.dart';
import 'package:stackwallet/models/buy/response_objects/quote.dart';
import 'package:stackwallet/services/buy/buy_response.dart';
import 'package:stackwallet/utilities/logger.dart';
import 'package:tuple/tuple.dart';
@ -175,8 +173,7 @@ class SimplexAPI {
}
}
/*Future<BuyResponse<SimplexOrder>>*/ void newOrder(
SimplexQuote quote) async {
Future<BuyResponse<SimplexOrder>> newOrder(SimplexQuote quote) async {
// Calling Simplex's API manually:
// curl --request POST \
// --url https://sandbox.test-simplexcc.com/wallet/merchant/v2/payments/partner/data \
@ -204,16 +201,23 @@ class SimplexAPI {
}
final jsonArray = jsonDecode(res.body); // TODO check if json
// TODO create and return SimplexOrder here
print(jsonArray);
return;
SimplexOrder _order = SimplexOrder(
quote: quote,
paymentId: "${jsonArray['paymentId']}",
orderId: "${jsonArray['orderId']}",
userId: "${jsonArray['userId']}",
);
return BuyResponse(value: _order);
} catch (e, s) {
Logging.instance.log("newOrder exception: $e\n$s", level: LogLevel.Error);
return; /*BuyResponse(
return BuyResponse(
exception: BuyException(
e.toString(),
BuyExceptionType.generic,
),
);*/
);
}
}
}