mirror of
https://github.com/cypherstack/stack_wallet.git
synced 2025-01-10 20:54:33 +00:00
replace get supportsTor with an exchangesWithTorSupport List<Exchange>
more convenient to use elsewhere
This commit is contained in:
parent
dcfb6e9dac
commit
45e6354fb6
4 changed files with 64 additions and 20 deletions
|
@ -24,6 +24,7 @@ import 'package:stackwallet/themes/stack_colors.dart';
|
||||||
import 'package:stackwallet/utilities/assets.dart';
|
import 'package:stackwallet/utilities/assets.dart';
|
||||||
import 'package:stackwallet/utilities/constants.dart';
|
import 'package:stackwallet/utilities/constants.dart';
|
||||||
import 'package:stackwallet/utilities/enums/coin_enum.dart';
|
import 'package:stackwallet/utilities/enums/coin_enum.dart';
|
||||||
|
import 'package:stackwallet/utilities/prefs.dart';
|
||||||
import 'package:stackwallet/utilities/text_styles.dart';
|
import 'package:stackwallet/utilities/text_styles.dart';
|
||||||
import 'package:stackwallet/utilities/util.dart';
|
import 'package:stackwallet/utilities/util.dart';
|
||||||
import 'package:stackwallet/widgets/background.dart';
|
import 'package:stackwallet/widgets/background.dart';
|
||||||
|
@ -39,6 +40,8 @@ import 'package:stackwallet/widgets/stack_dialog.dart';
|
||||||
import 'package:stackwallet/widgets/stack_text_field.dart';
|
import 'package:stackwallet/widgets/stack_text_field.dart';
|
||||||
import 'package:stackwallet/widgets/textfield_icon_button.dart';
|
import 'package:stackwallet/widgets/textfield_icon_button.dart';
|
||||||
|
|
||||||
|
import '../../../services/exchange/exchange.dart';
|
||||||
|
|
||||||
class ExchangeCurrencySelectionView extends StatefulWidget {
|
class ExchangeCurrencySelectionView extends StatefulWidget {
|
||||||
const ExchangeCurrencySelectionView({
|
const ExchangeCurrencySelectionView({
|
||||||
Key? key,
|
Key? key,
|
||||||
|
@ -165,20 +168,25 @@ class _ExchangeCurrencySelectionViewState
|
||||||
.rateTypeEqualTo(SupportedRateType.both)
|
.rateTypeEqualTo(SupportedRateType.both)
|
||||||
.or()
|
.or()
|
||||||
.rateTypeEqualTo(SupportedRateType.fixed)
|
.rateTypeEqualTo(SupportedRateType.fixed)
|
||||||
.and()
|
|
||||||
.not()
|
|
||||||
.exchangeNameEqualTo(ChangeNowExchange.exchangeName)
|
|
||||||
: q
|
: q
|
||||||
.rateTypeEqualTo(SupportedRateType.both)
|
.rateTypeEqualTo(SupportedRateType.both)
|
||||||
.or()
|
.or()
|
||||||
.rateTypeEqualTo(SupportedRateType.estimated)
|
.rateTypeEqualTo(SupportedRateType.estimated))
|
||||||
.and()
|
|
||||||
.not()
|
|
||||||
.exchangeNameEqualTo(ChangeNowExchange.exchangeName))
|
|
||||||
.sortByIsStackCoin()
|
.sortByIsStackCoin()
|
||||||
.thenByName()
|
.thenByName()
|
||||||
.findAll();
|
.findAll();
|
||||||
|
|
||||||
|
// If using Tor, filter exchanges which do not support Tor.
|
||||||
|
if (Prefs.instance.useTor) {
|
||||||
|
if (Exchange.exchangesWithTorSupport.isNotEmpty) {
|
||||||
|
currencies
|
||||||
|
.removeWhere((element) => !Exchange.exchangesWithTorSupport.any(
|
||||||
|
(e) => e.name == element.exchangeName,
|
||||||
|
));
|
||||||
|
// Could have also filtered using the List<String> Exchange.exchangeNamesWithTorSupport. But I didn't. This is fancier.
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return _getDistinctCurrenciesFrom(currencies);
|
return _getDistinctCurrenciesFrom(currencies);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -31,15 +31,19 @@ import 'package:stackwallet/pages/exchange_view/sub_widgets/rate_type_toggle.dar
|
||||||
import 'package:stackwallet/pages_desktop_specific/desktop_exchange/exchange_steps/step_scaffold.dart';
|
import 'package:stackwallet/pages_desktop_specific/desktop_exchange/exchange_steps/step_scaffold.dart';
|
||||||
import 'package:stackwallet/providers/providers.dart';
|
import 'package:stackwallet/providers/providers.dart';
|
||||||
import 'package:stackwallet/services/exchange/change_now/change_now_exchange.dart';
|
import 'package:stackwallet/services/exchange/change_now/change_now_exchange.dart';
|
||||||
|
import 'package:stackwallet/services/exchange/exchange.dart';
|
||||||
import 'package:stackwallet/services/exchange/exchange_data_loading_service.dart';
|
import 'package:stackwallet/services/exchange/exchange_data_loading_service.dart';
|
||||||
|
import 'package:stackwallet/services/exchange/exchange_response.dart';
|
||||||
import 'package:stackwallet/services/exchange/majestic_bank/majestic_bank_exchange.dart';
|
import 'package:stackwallet/services/exchange/majestic_bank/majestic_bank_exchange.dart';
|
||||||
import 'package:stackwallet/services/exchange/trocador/trocador_exchange.dart';
|
import 'package:stackwallet/services/exchange/trocador/trocador_exchange.dart';
|
||||||
|
import 'package:stackwallet/services/tor_service.dart';
|
||||||
import 'package:stackwallet/themes/stack_colors.dart';
|
import 'package:stackwallet/themes/stack_colors.dart';
|
||||||
import 'package:stackwallet/utilities/amount/amount_unit.dart';
|
import 'package:stackwallet/utilities/amount/amount_unit.dart';
|
||||||
import 'package:stackwallet/utilities/assets.dart';
|
import 'package:stackwallet/utilities/assets.dart';
|
||||||
import 'package:stackwallet/utilities/constants.dart';
|
import 'package:stackwallet/utilities/constants.dart';
|
||||||
import 'package:stackwallet/utilities/enums/coin_enum.dart';
|
import 'package:stackwallet/utilities/enums/coin_enum.dart';
|
||||||
import 'package:stackwallet/utilities/enums/exchange_rate_type_enum.dart';
|
import 'package:stackwallet/utilities/enums/exchange_rate_type_enum.dart';
|
||||||
|
import 'package:stackwallet/utilities/prefs.dart';
|
||||||
import 'package:stackwallet/utilities/text_styles.dart';
|
import 'package:stackwallet/utilities/text_styles.dart';
|
||||||
import 'package:stackwallet/utilities/util.dart';
|
import 'package:stackwallet/utilities/util.dart';
|
||||||
import 'package:stackwallet/widgets/conditional_parent.dart';
|
import 'package:stackwallet/widgets/conditional_parent.dart';
|
||||||
|
@ -55,8 +59,6 @@ import 'package:stackwallet/widgets/textfields/exchange_textfield.dart';
|
||||||
import 'package:tuple/tuple.dart';
|
import 'package:tuple/tuple.dart';
|
||||||
import 'package:uuid/uuid.dart';
|
import 'package:uuid/uuid.dart';
|
||||||
|
|
||||||
import '../../services/exchange/exchange_response.dart';
|
|
||||||
|
|
||||||
class ExchangeForm extends ConsumerStatefulWidget {
|
class ExchangeForm extends ConsumerStatefulWidget {
|
||||||
const ExchangeForm({
|
const ExchangeForm({
|
||||||
Key? key,
|
Key? key,
|
||||||
|
@ -78,7 +80,7 @@ class _ExchangeFormState extends ConsumerState<ExchangeForm> {
|
||||||
late final Coin? coin;
|
late final Coin? coin;
|
||||||
late final bool walletInitiated;
|
late final bool walletInitiated;
|
||||||
|
|
||||||
final exchanges = [
|
var exchanges = [
|
||||||
MajesticBankExchange.instance,
|
MajesticBankExchange.instance,
|
||||||
ChangeNowExchange.instance,
|
ChangeNowExchange.instance,
|
||||||
TrocadorExchange.instance,
|
TrocadorExchange.instance,
|
||||||
|
@ -773,6 +775,14 @@ class _ExchangeFormState extends ConsumerState<ExchangeForm> {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Instantiate the Tor service.
|
||||||
|
torService = TorService.sharedInstance;
|
||||||
|
|
||||||
|
// Filter exchanges based on Tor support.
|
||||||
|
if (Prefs.instance.useTor) {
|
||||||
|
exchanges = Exchange.exchangesWithTorSupport;
|
||||||
|
}
|
||||||
|
|
||||||
super.initState();
|
super.initState();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1007,4 +1017,7 @@ class _ExchangeFormState extends ConsumerState<ExchangeForm> {
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TorService instance.
|
||||||
|
late TorService torService;
|
||||||
}
|
}
|
||||||
|
|
|
@ -91,6 +91,24 @@ abstract class Exchange {
|
||||||
required bool reversed,
|
required bool reversed,
|
||||||
});
|
});
|
||||||
|
|
||||||
// Flag to indicate that the exchange supports Tor.
|
/// List of exchanges which support Tor.
|
||||||
bool get supportsTor => false;
|
///
|
||||||
|
/// Add to this list when adding a new exchange which supports Tor.
|
||||||
|
static List<Exchange> get exchangesWithTorSupport => [
|
||||||
|
MajesticBankExchange.instance,
|
||||||
|
TrocadorExchange.instance,
|
||||||
|
];
|
||||||
|
|
||||||
|
/// List of exchange names which support Tor.
|
||||||
|
///
|
||||||
|
/// Convenience method for when you just want to check for a String
|
||||||
|
/// .exchangeName instead of Exchange instances. Shouldn't need to be updated
|
||||||
|
/// as long as the above List is updated.
|
||||||
|
static List<String> get exchangeNamesWithTorSupport =>
|
||||||
|
exchangesWithTorSupport.map((exchange) => exchange.name).toList();
|
||||||
|
// Instead of using this, you can do like:
|
||||||
|
// currencies
|
||||||
|
// .removeWhere((element) => !Exchange.exchangesWithTorSupport.any(
|
||||||
|
// (e) => e.name == element.exchangeName,
|
||||||
|
// ));
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,6 +20,7 @@ import 'package:stackwallet/services/exchange/majestic_bank/majestic_bank_exchan
|
||||||
import 'package:stackwallet/services/exchange/trocador/trocador_exchange.dart';
|
import 'package:stackwallet/services/exchange/trocador/trocador_exchange.dart';
|
||||||
import 'package:stackwallet/utilities/enums/exchange_rate_type_enum.dart';
|
import 'package:stackwallet/utilities/enums/exchange_rate_type_enum.dart';
|
||||||
import 'package:stackwallet/utilities/logger.dart';
|
import 'package:stackwallet/utilities/logger.dart';
|
||||||
|
import 'package:stackwallet/utilities/prefs.dart';
|
||||||
import 'package:stackwallet/utilities/stack_file_system.dart';
|
import 'package:stackwallet/utilities/stack_file_system.dart';
|
||||||
import 'package:tuple/tuple.dart';
|
import 'package:tuple/tuple.dart';
|
||||||
|
|
||||||
|
@ -145,6 +146,7 @@ class ExchangeDataLoadingService {
|
||||||
final start = DateTime.now();
|
final start = DateTime.now();
|
||||||
try {
|
try {
|
||||||
/*
|
/*
|
||||||
|
// Old exchange data loading code.
|
||||||
await Future.wait([
|
await Future.wait([
|
||||||
_loadChangeNowCurrencies(),
|
_loadChangeNowCurrencies(),
|
||||||
// _loadChangeNowFixedRatePairs(),
|
// _loadChangeNowFixedRatePairs(),
|
||||||
|
@ -159,16 +161,19 @@ class ExchangeDataLoadingService {
|
||||||
// await _loadChangeNowFixedRatePairs();
|
// await _loadChangeNowFixedRatePairs();
|
||||||
// await _loadChangeNowEstimatedRatePairs();
|
// await _loadChangeNowEstimatedRatePairs();
|
||||||
*/
|
*/
|
||||||
// Use the supportsTor flag to filter out unsupported exchanges.
|
|
||||||
if (ChangeNowExchange.instance.supportsTor) {
|
// If using Tor, don't load data for exchanges which don't support Tor.
|
||||||
|
//
|
||||||
|
// Add to this list when adding an exchange which doesn't supports Tor.
|
||||||
|
if (!Prefs.instance.useTor) {
|
||||||
await _loadChangeNowCurrencies();
|
await _loadChangeNowCurrencies();
|
||||||
}
|
}
|
||||||
if (MajesticBankExchange.instance.supportsTor) {
|
|
||||||
await loadMajesticBankCurrencies();
|
// Exchanges which support Tor just get treated normally.
|
||||||
}
|
await Future.wait([
|
||||||
if (TrocadorExchange.instance.supportsTor) {
|
loadMajesticBankCurrencies(),
|
||||||
await loadTrocadorCurrencies();
|
loadTrocadorCurrencies(),
|
||||||
}
|
]);
|
||||||
|
|
||||||
Logging.instance.log(
|
Logging.instance.log(
|
||||||
"ExchangeDataLoadingService.loadAll finished in ${DateTime.now().difference(start).inSeconds} seconds",
|
"ExchangeDataLoadingService.loadAll finished in ${DateTime.now().difference(start).inSeconds} seconds",
|
||||||
|
|
Loading…
Reference in a new issue