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?)
This commit is contained in:
sneurlax 2023-01-16 15:07:45 -06:00
parent bda6865657
commit 7eefe196c9
5 changed files with 18 additions and 20 deletions

View file

@ -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<Crypto> supportedCryptos = [];
List<Fiat> supportedFiats = [];

View file

@ -84,7 +84,7 @@ class _BuyFormState extends ConsumerState<BuyForm> {
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<BuyForm> {
}
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<BuyForm> {
}
Future<void> 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<BuyForm> {
}
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<BuyForm> {
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<BuyForm> {
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

View file

@ -0,0 +1,6 @@
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:stackwallet/models/buy/simplex/simplex.dart';
final simplexProvider = Provider<Simplex>(
(ref) => Simplex(),
);

View file

@ -1,6 +0,0 @@
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:stackwallet/models/buy/simplex/simplex_supported_currencies.dart';
final supportedSimplexCurrenciesProvider = Provider<SimplexSupportedCurrencies>(
(ref) => SimplexSupportedCurrencies(),
);

View file

@ -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';