2023-01-11 23:04:03 +00:00
|
|
|
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 {
|
2023-01-11 23:04:03 +00:00
|
|
|
try {
|
|
|
|
await Future.wait([
|
2023-01-12 00:13:34 +00:00
|
|
|
_loadSimplexCurrencies(ref),
|
2023-01-11 23:04:03 +00:00
|
|
|
]);
|
|
|
|
} 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 {
|
2023-01-13 02:21:19 +00:00
|
|
|
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-13 02:21:19 +00:00
|
|
|
if (response['supportedCryptos'] != null) {
|
|
|
|
ref
|
2023-01-13 19:14:56 +00:00
|
|
|
.read(supportedSimplexCurrenciesProvider)
|
2023-01-14 00:07:27 +00:00
|
|
|
.updateSupportedCryptos(response['supportedCryptos']);
|
2023-01-13 02:21:19 +00:00
|
|
|
} else {
|
|
|
|
error = true;
|
|
|
|
Logging.instance.log(
|
|
|
|
"_loadSimplexCurrencies: $response",
|
|
|
|
level: LogLevel.Warning,
|
|
|
|
);
|
|
|
|
}
|
2023-01-14 00:07:27 +00:00
|
|
|
|
2023-01-13 02:21:19 +00:00
|
|
|
if (response['supportedFiats'] != null) {
|
|
|
|
ref
|
2023-01-13 19:14:56 +00:00
|
|
|
.read(supportedSimplexCurrenciesProvider)
|
2023-01-14 00:07:27 +00:00
|
|
|
.updateSupportedFiats(response['supportedFiats']);
|
2023-01-13 02:21:19 +00:00
|
|
|
} else {
|
|
|
|
error = true;
|
|
|
|
Logging.instance.log(
|
|
|
|
"_loadSimplexCurrencies: $response",
|
|
|
|
level: LogLevel.Warning,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (error) {
|
|
|
|
// _loadSimplexCurrencies() again?
|
|
|
|
} else {
|
2023-01-14 00:07:27 +00:00
|
|
|
ref.read(simplexLoadStatusStateProvider.state).state =
|
|
|
|
SimplexLoadStatus.success;
|
2023-01-13 02:21:19 +00:00
|
|
|
}
|
2023-01-11 23:04:03 +00:00
|
|
|
}
|
|
|
|
}
|