From dbfbadffdaef761abad0b493b27714c51fb22b01 Mon Sep 17 00:00:00 2001 From: Godwin Asuquo Date: Wed, 1 Mar 2023 15:50:31 +0200 Subject: [PATCH] Filter to use Tor only exchange --- lib/src/widgets/check_box_picker.dart | 16 ++++++++-------- .../exchange/exchange_view_model.dart | 19 ++++++++++++++++++- 2 files changed, 26 insertions(+), 9 deletions(-) diff --git a/lib/src/widgets/check_box_picker.dart b/lib/src/widgets/check_box_picker.dart index e2f817fc4..80461e26d 100644 --- a/lib/src/widgets/check_box_picker.dart +++ b/lib/src/widgets/check_box_picker.dart @@ -38,7 +38,7 @@ class CheckBoxPickerState extends State { Column( mainAxisSize: MainAxisSize.min, children: [ - if (widget.title?.isNotEmpty ?? false) + if (widget.title.isNotEmpty) Container( padding: EdgeInsets.symmetric(horizontal: 24), child: Text( @@ -58,7 +58,7 @@ class CheckBoxPickerState extends State { child: ClipRRect( borderRadius: BorderRadius.all(Radius.circular(30)), child: Container( - color: Theme.of(context).accentTextTheme!.headline6!.color!, + color: Theme.of(context).accentTextTheme.headline6!.color!, child: ConstrainedBox( constraints: BoxConstraints( maxHeight: MediaQuery.of(context).size.height * 0.65, @@ -70,7 +70,7 @@ class CheckBoxPickerState extends State { child: Stack( alignment: Alignment.center, children: [ - (items?.length ?? 0) > 3 + (items.length) > 3 ? Scrollbar( controller: controller, child: itemsList(), @@ -95,14 +95,14 @@ class CheckBoxPickerState extends State { Widget itemsList() { return Container( - color: Theme.of(context).accentTextTheme!.headline6!.backgroundColor!, + color: Theme.of(context).accentTextTheme.headline6!.backgroundColor!, child: ListView.separated( padding: EdgeInsets.zero, controller: controller, shrinkWrap: true, separatorBuilder: (context, index) => widget.isSeparated ? Divider( - color: Theme.of(context).accentTextTheme!.headline6!.backgroundColor!, + color: Theme.of(context).accentTextTheme.headline6!.backgroundColor!, height: 1, ) : const SizedBox(), @@ -121,13 +121,13 @@ class CheckBoxPickerState extends State { }, child: Container( height: 55, - color: Theme.of(context).accentTextTheme!.headline6!.color!, + color: Theme.of(context).accentTextTheme.headline6!.color!, padding: EdgeInsets.only(left: 24, right: 24), child: CheckboxListTile( value: item.value, activeColor: item.value ? Palette.blueCraiola - : Theme.of(context).accentTextTheme!.subtitle1!.decorationColor!, + : Theme.of(context).accentTextTheme.subtitle1!.decorationColor!, checkColor: Colors.white, title: widget.displayItem?.call(item) ?? Text( @@ -138,7 +138,7 @@ class CheckBoxPickerState extends State { fontWeight: FontWeight.w600, color: item.isDisabled ? Colors.grey.withOpacity(0.5) - : Theme.of(context).primaryTextTheme!.headline6!.color!, + : Theme.of(context).primaryTextTheme.headline6!.color!, decoration: TextDecoration.none, ), ), diff --git a/lib/view_model/exchange/exchange_view_model.dart b/lib/view_model/exchange/exchange_view_model.dart index f9f5683d9..7921115c6 100644 --- a/lib/view_model/exchange/exchange_view_model.dart +++ b/lib/view_model/exchange/exchange_view_model.dart @@ -2,6 +2,7 @@ import 'dart:async'; import 'dart:collection'; import 'dart:convert'; +import 'package:cake_wallet/entities/fiat_api_mode.dart'; import 'package:cake_wallet/entities/preferences_key.dart'; import 'package:cake_wallet/exchange/sideshift/sideshift_exchange_provider.dart'; import 'package:cake_wallet/exchange/sideshift/sideshift_request.dart'; @@ -62,8 +63,9 @@ abstract class ExchangeViewModelBase with Store { limitsState = LimitsInitialState(), receiveCurrency = wallet.currency, depositCurrency = wallet.currency, - providerList = [ChangeNowExchangeProvider(), SideShiftExchangeProvider(), SimpleSwapExchangeProvider(), TrocadorExchangeProvider()], + providerList = [], selectedProviders = ObservableList() { + _setProviders(); const excludeDepositCurrencies = [CryptoCurrency.btt, CryptoCurrency.nano]; const excludeReceiveCurrencies = [CryptoCurrency.xlm, CryptoCurrency.xrp, CryptoCurrency.bnb, CryptoCurrency.btt, CryptoCurrency.nano]; @@ -126,6 +128,13 @@ abstract class ExchangeViewModelBase with Store { final TradesStore tradesStore; final SharedPreferences sharedPreferences; + final _allProviders = [ + ChangeNowExchangeProvider(), + SideShiftExchangeProvider(), + SimpleSwapExchangeProvider(), + TrocadorExchangeProvider(), + ]; + @observable ExchangeProvider? provider; @@ -683,4 +692,12 @@ abstract class ExchangeViewModelBase with Store { break; } } + + void _setProviders(){ + if (_settingsStore.exchangeStatus == FiatApiMode.torOnly) { + providerList = _allProviders.where((provider) => provider.shouldUseOnionAddress).toList(); + } else { + providerList = _allProviders; + } + } }