fix currency filter

This commit is contained in:
sneurlax 2023-09-11 18:12:56 -05:00
parent 474ec39a5f
commit d342dd5cb9
2 changed files with 8 additions and 14 deletions

View file

@ -154,10 +154,6 @@ class _ExchangeCurrencySelectionViewState
} }
Future<List<Currency>> _getCurrencies() async { Future<List<Currency>> _getCurrencies() async {
// This is where exchanges are added to the list of available currencies.
//
// TODO: make an exchange's addition to the list of available currencies
// be dynamic and dependant upon the exchange's supportsTor implementation.
final currencies = await ExchangeDataLoadingService.instance.isar.currencies final currencies = await ExchangeDataLoadingService.instance.isar.currencies
.where() .where()
.filter() .filter()
@ -178,12 +174,10 @@ class _ExchangeCurrencySelectionViewState
// If using Tor, filter exchanges which do not support Tor. // If using Tor, filter exchanges which do not support Tor.
if (Prefs.instance.useTor) { if (Prefs.instance.useTor) {
if (Exchange.exchangesWithTorSupport.isNotEmpty) { if (Exchange.exchangeNamesWithTorSupport.isNotEmpty) {
currencies currencies.removeWhere((element) => !Exchange
.removeWhere((element) => !Exchange.exchangesWithTorSupport.any( .exchangeNamesWithTorSupport
(e) => e.name == element.exchangeName, .contains(element.exchangeName));
));
// Could have also filtered using the List<String> Exchange.exchangeNamesWithTorSupport. But I didn't. This is fancier.
} }
} }

View file

@ -107,8 +107,8 @@ abstract class Exchange {
static List<String> get exchangeNamesWithTorSupport => static List<String> get exchangeNamesWithTorSupport =>
exchangesWithTorSupport.map((exchange) => exchange.name).toList(); exchangesWithTorSupport.map((exchange) => exchange.name).toList();
// Instead of using this, you can do like: // Instead of using this, you can do like:
// currencies // currencies.removeWhere((element) =>
// .removeWhere((element) => !Exchange.exchangesWithTorSupport.any( // !Exchange.exchangesWithTorSupport.any((e) => e.name == element.exchangeName)
// (e) => e.name == element.exchangeName, // );
// )); // But this helper may be more readable.
} }