stack_wallet/lib/services/buy/buy_data_loading_service.dart

63 lines
1.7 KiB
Dart
Raw Normal View History

import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:stackwallet/providers/providers.dart';
import 'package:stackwallet/services/buy/simplex/simplex_api.dart';
import 'package:stackwallet/utilities/logger.dart';
class BuyDataLoadingService {
2023-01-12 00:13:34 +00:00
Future<void> loadAll(WidgetRef ref) async {
try {
await Future.wait([
2023-01-12 00:13:34 +00:00
_loadSimplexCurrencies(ref),
]);
} catch (e, s) {
Logging.instance.log("BuyDataLoadingService.loadAll failed: $e\n$s",
level: LogLevel.Error);
}
}
2023-01-12 00:13:34 +00:00
Future<void> _loadSimplexCurrencies(WidgetRef ref) async {
bool error = false;
// if (ref.read(simplexLoadStatusStateProvider.state).state ==
// SimplexLoadStatus.loading) {
2023-01-12 00:13:34 +00:00
// // already in progress so just
// return;
// }
ref.read(simplexLoadStatusStateProvider.state).state =
SimplexLoadStatus.loading;
final response = await SimplexAPI.instance.getSupported();
2023-01-14 14:21:32 +00:00
if (response.value != null) {
ref
.read(supportedSimplexCurrenciesProvider)
2023-01-14 14:21:32 +00:00
.updateSupportedCryptos(response.value!.item1);
} else {
error = true;
Logging.instance.log(
"_loadSimplexCurrencies: $response",
level: LogLevel.Warning,
);
}
2023-01-14 14:21:32 +00:00
if (response.value != null) {
ref
.read(supportedSimplexCurrenciesProvider)
2023-01-14 14:21:32 +00:00
.updateSupportedFiats(response.value!.item2);
} else {
error = true;
Logging.instance.log(
"_loadSimplexCurrencies: $response",
level: LogLevel.Warning,
);
}
if (error) {
// _loadSimplexCurrencies() again?
} else {
ref.read(simplexLoadStatusStateProvider.state).state =
SimplexLoadStatus.success;
}
}
}