WIP exchange tor support

This commit is contained in:
sneurlax 2023-09-11 16:31:48 -05:00
parent bcb92ae638
commit dcfb6e9dac
6 changed files with 46 additions and 2 deletions

View file

@ -125,7 +125,7 @@ class _ExchangeCurrencySelectionViewState
await showDialog<void>(
context: context,
builder: (context) => StackDialog(
title: "ChangeNOW Error",
title: "Exchange Error",
message: "Failed to load currency data: ${cn.exception}",
leftButton: SecondaryButton(
label: "Ok",
@ -151,6 +151,10 @@ class _ExchangeCurrencySelectionViewState
}
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
.where()
.filter()
@ -161,10 +165,16 @@ class _ExchangeCurrencySelectionViewState
.rateTypeEqualTo(SupportedRateType.both)
.or()
.rateTypeEqualTo(SupportedRateType.fixed)
.and()
.not()
.exchangeNameEqualTo(ChangeNowExchange.exchangeName)
: q
.rateTypeEqualTo(SupportedRateType.both)
.or()
.rateTypeEqualTo(SupportedRateType.estimated))
.rateTypeEqualTo(SupportedRateType.estimated)
.and()
.not()
.exchangeNameEqualTo(ChangeNowExchange.exchangeName))
.sortByIsStackCoin()
.thenByName()
.findAll();

View file

@ -274,4 +274,15 @@ class ChangeNowExchange extends Exchange {
// TODO: implement getTrades
throw UnimplementedError();
}
// ChangeNow does not support Tor.
//
// This code isn't required because the Exchange abstract class has a
// default implementation that returns false. This serves as an example and
// reminder in case ChangeNow files are copied to create a new exchange (or
// if ChangeNow ever supports Tor).
/*
@override
bool get supportsTor => true;
*/
}

View file

@ -90,4 +90,7 @@ abstract class Exchange {
Estimate? estimate,
required bool reversed,
});
// Flag to indicate that the exchange supports Tor.
bool get supportsTor => false;
}

View file

@ -144,6 +144,7 @@ class ExchangeDataLoadingService {
);
final start = DateTime.now();
try {
/*
await Future.wait([
_loadChangeNowCurrencies(),
// _loadChangeNowFixedRatePairs(),
@ -157,6 +158,17 @@ class ExchangeDataLoadingService {
// quicker to load available currencies on the fly for a specific base currency
// await _loadChangeNowFixedRatePairs();
// await _loadChangeNowEstimatedRatePairs();
*/
// Use the supportsTor flag to filter out unsupported exchanges.
if (ChangeNowExchange.instance.supportsTor) {
await _loadChangeNowCurrencies();
}
if (MajesticBankExchange.instance.supportsTor) {
await loadMajesticBankCurrencies();
}
if (TrocadorExchange.instance.supportsTor) {
await loadTrocadorCurrencies();
}
Logging.instance.log(
"ExchangeDataLoadingService.loadAll finished in ${DateTime.now().difference(start).inSeconds} seconds",

View file

@ -324,4 +324,8 @@ class MajesticBankExchange extends Exchange {
return ExchangeResponse(exception: response.exception);
}
}
// Majestic Bank supports tor.
@override
bool get supportsTor => true;
}

View file

@ -401,4 +401,8 @@ class TrocadorExchange extends Exchange {
return ExchangeResponse(exception: response.exception);
}
}
// Trocador supports Tor.
@override
bool get supportsTor => true;
}