From 82f89966bc78a31a03c468b3252b8333bfc1932e Mon Sep 17 00:00:00 2001 From: sneurlax <sneurlax@gmail.com> Date: Tue, 24 Jan 2023 16:02:25 -0600 Subject: [PATCH] add userID to quotes and don't init userID in main TODO test what happens for a fresh install, I already have a userID set in my prefs --- lib/main.dart | 7 ++++--- lib/services/buy/simplex/simplex_api.dart | 12 ++++++++++-- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/lib/main.dart b/lib/main.dart index 826672a25..8296d739a 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -318,9 +318,10 @@ class _MaterialAppWithThemeState extends ConsumerState<MaterialAppWithTheme> } } - ref - .read(prefsChangeNotifierProvider) - .userID; // Just reading the ref should set it if it's not already set + // ref + // .read(prefsChangeNotifierProvider) + // .userID; // Just reading the ref should set it if it's not already set + // We shouldn't need to do this, instead only generating an ID when (or if) the userID is looked up when creating a quote } catch (e, s) { Logger.print("$e $s", normalLength: false); } diff --git a/lib/services/buy/simplex/simplex_api.dart b/lib/services/buy/simplex/simplex_api.dart index 787d1f638..9b8e8b4ee 100644 --- a/lib/services/buy/simplex/simplex_api.dart +++ b/lib/services/buy/simplex/simplex_api.dart @@ -13,12 +13,15 @@ import 'package:stackwallet/models/buy/response_objects/quote.dart'; import 'package:stackwallet/services/buy/buy_response.dart'; import 'package:stackwallet/utilities/enums/fiat_enum.dart'; import 'package:stackwallet/utilities/logger.dart'; +import 'package:stackwallet/utilities/prefs.dart'; import 'package:url_launcher/url_launcher.dart'; class SimplexAPI { static const String scheme = "https"; static const String authority = "sandbox-api.stackwallet.com"; + final _prefs = Prefs.instance; + SimplexAPI._(); static final SimplexAPI _instance = SimplexAPI._(); static SimplexAPI get instance => _instance; @@ -149,6 +152,9 @@ class SimplexAPI { Future<BuyResponse<SimplexQuote>> getQuote(SimplexQuote quote) async { try { + await _prefs.init(); + String? userID = _prefs.userID; + Map<String, String> headers = { 'Content-Type': 'application/x-www-form-urlencoded', }; @@ -163,7 +169,9 @@ class SimplexAPI { ? "${quote.youPayFiatPrice}" : "${quote.youReceiveCryptoAmount}", }; - // TODO add USER_ID + if (userID != null) { + data['USER_ID'] = userID; + } Uri url = Uri.https('simplex-sandbox.stackwallet.com', 'api.php', data); // TODO update to stackwallet.com hosted API and use HTTPS @@ -175,7 +183,7 @@ class SimplexAPI { jsonArray['quote'] = quote; // Add and pass this on - return await compute(_parseQuote, jsonArray); + return await _parseQuote(jsonArray); } catch (e, s) { Logging.instance.log("getQuote exception: $e\n$s", level: LogLevel.Error); return BuyResponse(