mirror of
https://github.com/cypherstack/stack_wallet.git
synced 2024-11-17 09:47:37 +00:00
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:
parent
595d7e760d
commit
2ad0659cbc
5 changed files with 54 additions and 25 deletions
17
lib/models/buy/response_objects/order.dart
Normal file
17
lib/models/buy/response_objects/order.dart
Normal 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,
|
||||
});
|
||||
}
|
|
@ -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,
|
||||
SimplexQuote({
|
||||
required this.crypto,
|
||||
required this.fiat,
|
||||
required this.youPayFiatPrice,
|
||||
required this.youReceiveCryptoAmount,
|
||||
required this.id,
|
||||
required this.receivingAddress,
|
||||
required this.buyWithFiat});
|
||||
required this.buyWithFiat,
|
||||
});
|
||||
}
|
||||
|
|
|
@ -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';
|
||||
|
|
|
@ -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(
|
||||
|
|
|
@ -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,
|
||||
),
|
||||
);*/
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue