mirror of
https://github.com/cypherstack/stack_wallet.git
synced 2024-12-23 11:59:30 +00:00
add newOrder stub method
TODO make it POST and open external browser, or else we'll have to make the inline status widget
This commit is contained in:
parent
4a13189927
commit
f1c686504f
2 changed files with 39 additions and 1 deletions
|
@ -1,6 +1,7 @@
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_svg/svg.dart';
|
||||
import 'package:stackwallet/models/buy/response_objects/quote.dart';
|
||||
import 'package:stackwallet/services/buy/simplex/simplex_api.dart';
|
||||
import 'package:stackwallet/utilities/assets.dart';
|
||||
import 'package:stackwallet/widgets/desktop/primary_button.dart';
|
||||
import 'package:stackwallet/widgets/desktop/secondary_button.dart';
|
||||
|
@ -14,6 +15,10 @@ class BuyWarningPopup extends StatelessWidget {
|
|||
|
||||
final SimplexQuote quote;
|
||||
|
||||
void newOrder(SimplexQuote quote) {
|
||||
final response = SimplexAPI.instance.newOrder(quote);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return StackDialog(
|
||||
|
@ -28,7 +33,7 @@ class BuyWarningPopup extends StatelessWidget {
|
|||
rightButton: PrimaryButton(
|
||||
label: "Continue",
|
||||
onPressed: () async {
|
||||
// todo open simplex page in external browser
|
||||
SimplexAPI.instance.newOrder(quote);
|
||||
},
|
||||
),
|
||||
icon: SizedBox(
|
||||
|
|
|
@ -173,4 +173,37 @@ class SimplexAPI {
|
|||
);
|
||||
}
|
||||
}
|
||||
|
||||
void newOrder(SimplexQuote quote) async {
|
||||
try {
|
||||
// TODO launch URL which POSTs headers like https://integrations.simplex.com/docs/new-window-payment-form-submission-1
|
||||
|
||||
// Not working example so not helpful
|
||||
// curl -H "Content-Type: application/json" -d '{"account_details": {"app_end_user_id": "asd"}, "transaction_details": {"digital_currency": "BTC", "fiat_currency": "USD", "requested_currency": "USD", "requested_amount": 101}}' http://sandbox-api.stackwallet.com/order
|
||||
Map<String, String> headers = {
|
||||
'Content-Type': 'application/json',
|
||||
};
|
||||
String data =
|
||||
'{"account_details": {"app_end_user_id": "${quote.receivingAddress}"}, "transaction_details": {"digital_currency": "${quote.crypto.ticker.toUpperCase()}", "fiat_currency": "${quote.fiat.ticker.toUpperCase()}", "requested_currency": "USD", "requested_amount": ${quote.youPayFiatPrice}}}';
|
||||
Uri url = Uri.parse('http://sandbox-api.stackwallet.com/order');
|
||||
|
||||
var res = await http.post(url, headers: headers, body: data);
|
||||
|
||||
if (res.statusCode != 200) {
|
||||
throw Exception('newOrder exception: statusCode= ${res.statusCode}');
|
||||
}
|
||||
|
||||
final jsonArray = jsonDecode(res.body);
|
||||
|
||||
return;
|
||||
} catch (e, s) {
|
||||
Logging.instance.log("newOrder exception: $e\n$s", level: LogLevel.Error);
|
||||
return; /*BuyResponse(
|
||||
exception: BuyException(
|
||||
e.toString(),
|
||||
BuyExceptionType.generic,
|
||||
),
|
||||
);*/
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue