mirror of
https://github.com/cypherstack/stack_wallet.git
synced 2024-11-17 01:37:54 +00:00
use new cypherstack/simplex_api for quotes, update SimplexQuote
and add bool buyWithFiat to SimplexQuote to disambiguate request
This commit is contained in:
parent
745a887566
commit
7191e502db
5 changed files with 63 additions and 54 deletions
|
@ -14,12 +14,14 @@ class SimplexQuote {
|
|||
late final String purchaseId;
|
||||
late final String receivingAddress;
|
||||
|
||||
SimplexQuote({
|
||||
required this.crypto,
|
||||
required this.fiat,
|
||||
required this.youPayFiatPrice,
|
||||
required this.youReceiveCryptoAmount,
|
||||
required this.purchaseId,
|
||||
required this.receivingAddress,
|
||||
});
|
||||
late final bool buyWithFiat;
|
||||
|
||||
SimplexQuote(
|
||||
{required this.crypto,
|
||||
required this.fiat,
|
||||
required this.youPayFiatPrice,
|
||||
required this.youReceiveCryptoAmount,
|
||||
required this.purchaseId,
|
||||
required this.receivingAddress,
|
||||
required this.buyWithFiat});
|
||||
}
|
||||
|
|
|
@ -15,6 +15,7 @@ class Simplex {
|
|||
youReceiveCryptoAmount: Decimal.parse("1.0238917"),
|
||||
purchaseId: "someID",
|
||||
receivingAddress: '',
|
||||
buyWithFiat: true,
|
||||
);
|
||||
|
||||
void updateSupportedCryptos(List<Crypto> newCryptos) {
|
||||
|
|
|
@ -81,6 +81,7 @@ class _BuyFormState extends ConsumerState<BuyForm> {
|
|||
youReceiveCryptoAmount: Decimal.parse("1.0238917"),
|
||||
purchaseId: "someID",
|
||||
receivingAddress: '',
|
||||
buyWithFiat: true,
|
||||
); // TODO enum this or something
|
||||
|
||||
bool buyWithFiat = true;
|
||||
|
@ -348,7 +349,6 @@ class _BuyFormState extends ConsumerState<BuyForm> {
|
|||
),
|
||||
);
|
||||
|
||||
buyWithFiat;
|
||||
quote = SimplexQuote(
|
||||
crypto: selectedCrypto!,
|
||||
fiat: selectedFiat!,
|
||||
|
@ -360,6 +360,7 @@ class _BuyFormState extends ConsumerState<BuyForm> {
|
|||
: Decimal.parse(_buyAmountController.text), // Ternary for this
|
||||
purchaseId: "purchaseId", // anything; we get an ID back
|
||||
receivingAddress: _receiveAddressController.text,
|
||||
buyWithFiat: buyWithFiat,
|
||||
);
|
||||
|
||||
await _loadQuote(quote);
|
||||
|
@ -486,6 +487,7 @@ class _BuyFormState extends ConsumerState<BuyForm> {
|
|||
youReceiveCryptoAmount: Decimal.parse("1.0238917"),
|
||||
purchaseId: "someID",
|
||||
receivingAddress: '',
|
||||
buyWithFiat: true,
|
||||
); // TODO enum this or something
|
||||
|
||||
// TODO set defaults better; should probably explicitly enumerate the coins & fiats used and pull the specific ones we need rather than generating them as defaults here
|
||||
|
|
|
@ -108,20 +108,15 @@ class SimplexAPI {
|
|||
}
|
||||
|
||||
Future<BuyResponse<SimplexQuote>> getQuote(SimplexQuote quote) async {
|
||||
// example for quote courtesy of @danrmiller
|
||||
// curl -H "Content-Type: application/json" -d '{"digital_currency": "BTC", "fiat_currency": "USD", "requested_currency": "USD", "requested_amount": 100}' http://sandbox-api.stackwallet.com/quote
|
||||
// official docs reference eg
|
||||
// curl --request GET \
|
||||
// --url https://sandbox.test-simplexcc.com/v2/supported_crypto_currencies \
|
||||
// --header 'accept: application/json'
|
||||
|
||||
try {
|
||||
Map<String, String> headers = {
|
||||
'Content-Type': 'application/json',
|
||||
};
|
||||
String data =
|
||||
'{"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/quote');
|
||||
'{"CRYPTO_TICKER": "${quote.crypto.ticker.toUpperCase()}", "FIAT_TICKER": "${quote.fiat.ticker.toUpperCase()}", "REQUESTED_TICKER": "${quote.buyWithFiat ? quote.fiat.ticker.toUpperCase() : quote.crypto.ticker.toUpperCase()}", "REQUESTED_AMOUNT": ${quote.buyWithFiat ? quote.youPayFiatPrice : quote.youReceiveCryptoAmount}}';
|
||||
// TODO add USER_ID
|
||||
Uri url = Uri.parse('http://localhost/api.php/quote');
|
||||
// TODO update to stackwallet.com hosted API
|
||||
|
||||
var res = await http.post(url, headers: headers, body: data);
|
||||
|
||||
|
@ -147,17 +142,18 @@ class SimplexAPI {
|
|||
|
||||
BuyResponse<SimplexQuote> _parseQuote(dynamic jsonArray) {
|
||||
try {
|
||||
String fiatPrice = "${jsonArray['result']['fiat_money']['total_amount']}";
|
||||
String cryptoAmount = "${jsonArray['result']['digital_money']['amount']}";
|
||||
String cryptoAmount = "${jsonArray['digital_money']['amount']}";
|
||||
|
||||
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);
|
||||
crypto: quote.crypto,
|
||||
fiat: quote.fiat,
|
||||
youPayFiatPrice: quote.youPayFiatPrice,
|
||||
youReceiveCryptoAmount: Decimal.parse(cryptoAmount),
|
||||
purchaseId: jsonArray['quote_id'] as String,
|
||||
receivingAddress: quote.receivingAddress,
|
||||
buyWithFiat: quote.buyWithFiat,
|
||||
);
|
||||
|
||||
return BuyResponse(value: _quote);
|
||||
} catch (e, s) {
|
||||
|
@ -174,6 +170,7 @@ class SimplexAPI {
|
|||
|
||||
void newOrder(SimplexQuote quote) async {
|
||||
try {
|
||||
/*
|
||||
String version = "123"; // TODO pull from app version variable
|
||||
String app_end_user_id =
|
||||
"01e7a0b9-8dfc-4988-a28d-84a34e5f0a63"; // TODO generate per-user ID (pull from wallet?)
|
||||
|
@ -181,19 +178,17 @@ class SimplexAPI {
|
|||
"1994-11-05T08:15:30-05:00"; // TODO supply real signup timestamp (pull from wallet?)
|
||||
String referral_ip = "207.66.86.226"; // TODO update to API server IP
|
||||
String payment_id =
|
||||
"daaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa"; // TODO make unique and save
|
||||
"faaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa"; // TODO make unique and save
|
||||
String order_id = "789"; // TODO generate unique ID per order
|
||||
String referrer = "https://stackwallet.com/simplex"; // TODO update
|
||||
String apiKey = "XXX";
|
||||
String publicKey = "pk_test_XXX";
|
||||
String apiKey =
|
||||
"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJwYXJ0bmVyIjoic3RhY2t3YWxsZXQiLCJpcCI6WyIxLjIuMy40Il0sInNhbmRib3giOnRydWV9.VRaNZKPlc8wtkHGn0XscbsHnBMweZrMEyl2P94GfH94";
|
||||
String publicKey = "pk_test_7cce3f58-680d-420c-9888-f53d44763fe6";
|
||||
|
||||
// Using simplex_api/order; doesn't work:
|
||||
/*
|
||||
Map<String, String> headers = {
|
||||
'Content-Type': 'application/json'
|
||||
};
|
||||
Map<String, String> headers = {'Content-Type': 'application/json'};
|
||||
String data =
|
||||
'{"account_details": {"app_end_user_id": "${app_end_user_id}"}, "transaction_details": {"payment_details": {"fiat_total_amount": {"currency": "${quote.fiat.ticker.toUpperCase()}", "amount": "${quote.youPayFiatPrice}"}, "requested_digital_amount": {"currency": "${quote.crypto.ticker.toUpperCase()}", "amount": "${quote.youReceiveCryptoAmount}"}, "destination_wallet": {"currency": "${quote.crypto.ticker.toUpperCase()}", "address": "${quote.receivingAddress}"}}';
|
||||
'{"account_details": {"app_end_user_id": "${app_end_user_id}"}, "transaction_details": {"payment_details": {"fiat_total_amount": {"currency": "${quote.fiat.ticker.toUpperCase()}", "amount": "${quote.youPayFiatPrice}"}, "requested_digital_amount": {"currency": "${quote.crypto.ticker.toUpperCase()}", "amount": "${quote.youReceiveCryptoAmount}"}, "destination_wallet": {"currency": "${quote.crypto.ticker.toUpperCase()}", "address": "${quote.receivingAddress}", "validation": "bypass"}}';
|
||||
Uri url = Uri.parse('http://sandbox-api.stackwallet.com/order');
|
||||
var res = await http.post(url, headers: headers, body: data);
|
||||
|
||||
|
@ -202,7 +197,7 @@ class SimplexAPI {
|
|||
}
|
||||
final jsonArray = jsonDecode(res.body);
|
||||
print(jsonArray);
|
||||
*/
|
||||
/*
|
||||
|
||||
// Calling Simplex's API manually:
|
||||
// curl --request POST \
|
||||
|
@ -229,7 +224,9 @@ class SimplexAPI {
|
|||
final jsonArray = jsonDecode(res.body);
|
||||
print(jsonArray);
|
||||
// TODO check if {is_key_required: true} (indicates success)
|
||||
*/*/
|
||||
|
||||
print('test');
|
||||
return;
|
||||
} catch (e, s) {
|
||||
Logging.instance.log("newOrder exception: $e\n$s", level: LogLevel.Error);
|
||||
|
|
45
pubspec.lock
45
pubspec.lock
|
@ -42,7 +42,7 @@ packages:
|
|||
name: archive
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "3.3.0"
|
||||
version: "3.1.11"
|
||||
args:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
@ -63,7 +63,7 @@ packages:
|
|||
name: async
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "2.9.0"
|
||||
version: "2.8.2"
|
||||
barcode_scan2:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
|
@ -190,7 +190,14 @@ packages:
|
|||
name: characters
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "1.2.1"
|
||||
version: "1.2.0"
|
||||
charcode:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: charcode
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "1.3.1"
|
||||
checked_yaml:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
@ -211,7 +218,7 @@ packages:
|
|||
name: clock
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "1.1.1"
|
||||
version: "1.1.0"
|
||||
code_builder:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
@ -281,7 +288,7 @@ packages:
|
|||
name: coverage
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "1.5.0"
|
||||
version: "1.2.0"
|
||||
cross_file:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
@ -435,7 +442,7 @@ packages:
|
|||
name: fake_async
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "1.3.1"
|
||||
version: "1.3.0"
|
||||
ffi:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
|
@ -864,21 +871,21 @@ packages:
|
|||
name: matcher
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "0.12.12"
|
||||
version: "0.12.11"
|
||||
material_color_utilities:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: material_color_utilities
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "0.1.5"
|
||||
version: "0.1.4"
|
||||
meta:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: meta
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "1.8.0"
|
||||
version: "1.7.0"
|
||||
mime:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
@ -990,7 +997,7 @@ packages:
|
|||
name: path
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "1.8.2"
|
||||
version: "1.8.1"
|
||||
path_drawing:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
@ -1366,7 +1373,7 @@ packages:
|
|||
name: source_span
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "1.9.0"
|
||||
version: "1.8.2"
|
||||
stack_trace:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
@ -1410,7 +1417,7 @@ packages:
|
|||
name: string_scanner
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "1.1.1"
|
||||
version: "1.1.0"
|
||||
string_validator:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
|
@ -1424,35 +1431,35 @@ packages:
|
|||
name: sync_http
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "0.3.1"
|
||||
version: "0.3.0"
|
||||
term_glyph:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: term_glyph
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "1.2.1"
|
||||
version: "1.2.0"
|
||||
test:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: test
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "1.21.4"
|
||||
version: "1.21.1"
|
||||
test_api:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: test_api
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "0.4.12"
|
||||
version: "0.4.9"
|
||||
test_core:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: test_core
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "0.4.16"
|
||||
version: "0.4.13"
|
||||
time:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
@ -1501,7 +1508,7 @@ packages:
|
|||
name: typed_data
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "1.3.1"
|
||||
version: "1.3.0"
|
||||
universal_io:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
@ -1585,7 +1592,7 @@ packages:
|
|||
name: vm_service
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "9.0.0"
|
||||
version: "8.2.2"
|
||||
wakelock:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
|
|
Loading…
Reference in a new issue