From 7eefe196c9951520df26fa7f2f736b3dbb3746b0 Mon Sep 17 00:00:00 2001 From: sneurlax Date: Mon, 16 Jan 2023 15:07:45 -0600 Subject: [PATCH] simplex supported currencies provider -> simplex provider we may need to store a quote or "estimate" in the provider for UI dataflow purposes (because we can't run async functions in widget builds/constructors?) --- ...supported_currencies.dart => simplex.dart} | 4 +++- lib/pages/buy_view/buy_form.dart | 20 ++++++++----------- lib/providers/buy/simplex_provider.dart | 6 ++++++ ...simplex_supported_currencies_provider.dart | 6 ------ lib/providers/providers.dart | 2 +- 5 files changed, 18 insertions(+), 20 deletions(-) rename lib/models/buy/simplex/{simplex_supported_currencies.dart => simplex.dart} (79%) create mode 100644 lib/providers/buy/simplex_provider.dart delete mode 100644 lib/providers/buy/simplex_supported_currencies_provider.dart diff --git a/lib/models/buy/simplex/simplex_supported_currencies.dart b/lib/models/buy/simplex/simplex.dart similarity index 79% rename from lib/models/buy/simplex/simplex_supported_currencies.dart rename to lib/models/buy/simplex/simplex.dart index 047f1cd2d..e2fadee5a 100644 --- a/lib/models/buy/simplex/simplex_supported_currencies.dart +++ b/lib/models/buy/simplex/simplex.dart @@ -1,8 +1,10 @@ +import 'package:decimal/decimal.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/quote.dart'; // import 'package:stackwallet/models/buy/response_objects/pair.dart'; -class SimplexSupportedCurrencies { +class Simplex { List supportedCryptos = []; List supportedFiats = []; diff --git a/lib/pages/buy_view/buy_form.dart b/lib/pages/buy_view/buy_form.dart index 24143f574..1877bc2f2 100644 --- a/lib/pages/buy_view/buy_form.dart +++ b/lib/pages/buy_view/buy_form.dart @@ -84,7 +84,7 @@ class _BuyFormState extends ConsumerState { void cryptoFieldOnChanged(String value) async {} void selectCrypto() async { - if (ref.read(supportedSimplexCurrenciesProvider).supportedCryptos.isEmpty) { + if (ref.read(simplexProvider).supportedCryptos.isEmpty) { bool shouldPop = false; unawaited( showDialog( @@ -106,7 +106,7 @@ class _BuyFormState extends ConsumerState { } await _showFloatingCryptoSelectionSheet( - coins: ref.read(supportedSimplexCurrenciesProvider).supportedCryptos, + coins: ref.read(simplexProvider).supportedCryptos, onSelected: (crypto) { setState(() { selectedCrypto = crypto; @@ -188,7 +188,7 @@ class _BuyFormState extends ConsumerState { } Future selectFiat() async { - if (ref.read(supportedSimplexCurrenciesProvider).supportedFiats.isEmpty) { + if (ref.read(simplexProvider).supportedFiats.isEmpty) { bool shouldPop = false; unawaited( showDialog( @@ -210,7 +210,7 @@ class _BuyFormState extends ConsumerState { } await _showFloatingFiatSelectionSheet( - fiats: ref.read(supportedSimplexCurrenciesProvider).supportedFiats, + fiats: ref.read(simplexProvider).supportedFiats, onSelected: (fiat) { setState(() { selectedFiat = fiat; @@ -223,12 +223,8 @@ class _BuyFormState extends ConsumerState { final response = await SimplexAPI.instance.getSupported(); if (response.value != null) { - ref - .read(supportedSimplexCurrenciesProvider) - .updateSupportedCryptos(response.value!.item1); - ref - .read(supportedSimplexCurrenciesProvider) - .updateSupportedFiats(response.value!.item2); + ref.read(simplexProvider).updateSupportedCryptos(response.value!.item1); + ref.read(simplexProvider).updateSupportedFiats(response.value!.item2); } else { Logging.instance.log( "_loadSimplexCurrencies: $response", @@ -334,8 +330,8 @@ class _BuyFormState extends ConsumerState { clipboard = widget.clipboard; scanner = widget.scanner; - coins = ref.read(supportedSimplexCurrenciesProvider).supportedCryptos; - fiats = ref.read(supportedSimplexCurrenciesProvider).supportedFiats; + coins = ref.read(simplexProvider).supportedCryptos; + fiats = ref.read(simplexProvider).supportedFiats; // TODO set initial crypto to open wallet if a wallet is open diff --git a/lib/providers/buy/simplex_provider.dart b/lib/providers/buy/simplex_provider.dart new file mode 100644 index 000000000..d15d335a5 --- /dev/null +++ b/lib/providers/buy/simplex_provider.dart @@ -0,0 +1,6 @@ +import 'package:flutter_riverpod/flutter_riverpod.dart'; +import 'package:stackwallet/models/buy/simplex/simplex.dart'; + +final simplexProvider = Provider( + (ref) => Simplex(), +); diff --git a/lib/providers/buy/simplex_supported_currencies_provider.dart b/lib/providers/buy/simplex_supported_currencies_provider.dart deleted file mode 100644 index 17c27f9bd..000000000 --- a/lib/providers/buy/simplex_supported_currencies_provider.dart +++ /dev/null @@ -1,6 +0,0 @@ -import 'package:flutter_riverpod/flutter_riverpod.dart'; -import 'package:stackwallet/models/buy/simplex/simplex_supported_currencies.dart'; - -final supportedSimplexCurrenciesProvider = Provider( - (ref) => SimplexSupportedCurrencies(), -); diff --git a/lib/providers/providers.dart b/lib/providers/providers.dart index 99af94fb1..210d36420 100644 --- a/lib/providers/providers.dart +++ b/lib/providers/providers.dart @@ -1,6 +1,6 @@ export './buy/buy_form_state_provider.dart'; export './buy/simplex_initial_load_status.dart'; -export './buy/simplex_supported_currencies_provider.dart'; +export './buy/simplex_provider.dart'; export './exchange/available_changenow_currencies_provider.dart'; export './exchange/available_simpleswap_currencies_provider.dart'; export './exchange/changenow_initial_load_status.dart';