From 23c2b2f50f7d06c455a8b5821b4907da0303ef42 Mon Sep 17 00:00:00 2001 From: julian Date: Mon, 17 Oct 2022 15:41:58 -0600 Subject: [PATCH 1/6] read from provider instead of directly from prefs singleton --- lib/pages/home_view/home_view.dart | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/lib/pages/home_view/home_view.dart b/lib/pages/home_view/home_view.dart index 2e7c38202..b4c643b65 100644 --- a/lib/pages/home_view/home_view.dart +++ b/lib/pages/home_view/home_view.dart @@ -11,13 +11,13 @@ import 'package:stackwallet/pages/settings_views/global_settings_view/global_set import 'package:stackwallet/pages/settings_views/global_settings_view/hidden_settings.dart'; import 'package:stackwallet/pages/wallets_view/wallets_view.dart'; import 'package:stackwallet/providers/global/notifications_provider.dart'; +import 'package:stackwallet/providers/global/prefs_provider.dart'; import 'package:stackwallet/providers/ui/home_view_index_provider.dart'; import 'package:stackwallet/providers/ui/unread_notifications_provider.dart'; import 'package:stackwallet/services/exchange/exchange_data_loading_service.dart'; import 'package:stackwallet/utilities/assets.dart'; import 'package:stackwallet/utilities/constants.dart'; import 'package:stackwallet/utilities/logger.dart'; -import 'package:stackwallet/utilities/prefs.dart'; import 'package:stackwallet/utilities/text_styles.dart'; import 'package:stackwallet/utilities/theme/stack_colors.dart'; import 'package:stackwallet/widgets/custom_buttons/app_bar_icon_button.dart'; @@ -83,9 +83,7 @@ class _HomeViewState extends ConsumerState { void _loadCNData() { // unawaited future - // - final externalCalls = Prefs.instance.externalCalls; - if (externalCalls) { + if (ref.read(prefsChangeNotifierProvider).externalCalls) { _exchangeDataLoadingService.loadAll(ref); } else { Logging.instance.log("User does not want to use external calls", From cfc8f2ab9df36726e9c9747974078e22288a9c37 Mon Sep 17 00:00:00 2001 From: julian Date: Mon, 17 Oct 2022 15:56:03 -0600 Subject: [PATCH 2/6] hide price values on favorite card when incognito mode enabled --- .../sub_widgets/favorite_card.dart | 74 +++++++++++-------- 1 file changed, 44 insertions(+), 30 deletions(-) diff --git a/lib/pages/wallets_view/sub_widgets/favorite_card.dart b/lib/pages/wallets_view/sub_widgets/favorite_card.dart index bc95d51b5..924e904f3 100644 --- a/lib/pages/wallets_view/sub_widgets/favorite_card.dart +++ b/lib/pages/wallets_view/sub_widgets/favorite_card.dart @@ -49,6 +49,8 @@ class _FavoriteCardState extends ConsumerState { @override Widget build(BuildContext context) { final coin = ref.watch(managerProvider.select((value) => value.coin)); + final externalCalls = ref.watch( + prefsChangeNotifierProvider.select((value) => value.externalCalls)); return GestureDetector( onTap: () { @@ -70,7 +72,9 @@ class _FavoriteCardState extends ConsumerState { width: widget.width, height: widget.height, decoration: BoxDecoration( - color: Theme.of(context).extension()!.colorForCoin(coin), + color: Theme.of(context) + .extension()! + .colorForCoin(coin), borderRadius: BorderRadius.circular( Constants.size.circularBorderRadius, ), @@ -138,7 +142,9 @@ class _FavoriteCardState extends ConsumerState { ref.watch(managerProvider .select((value) => value.walletName)), style: STextStyles.itemSubtitle12(context).copyWith( - color: Theme.of(context).extension()!.textFavoriteCard, + color: Theme.of(context) + .extension()! + .textFavoriteCard, ), overflow: TextOverflow.fade, ), @@ -159,14 +165,16 @@ class _FavoriteCardState extends ConsumerState { snapshot.hasData) { if (snapshot.data != null) { _cachedBalance = snapshot.data!; - _cachedFiatValue = _cachedBalance * - ref - .watch( - priceAnd24hChangeNotifierProvider.select( - (value) => value.getPrice(coin), - ), - ) - .item1; + if (externalCalls) { + _cachedFiatValue = _cachedBalance * + ref + .watch( + priceAnd24hChangeNotifierProvider.select( + (value) => value.getPrice(coin), + ), + ) + .item1; + } } } return Column( @@ -185,30 +193,36 @@ class _FavoriteCardState extends ConsumerState { )} ${coin.ticker}", style: STextStyles.titleBold12(context).copyWith( fontSize: 16, - color: Theme.of(context).extension()!.textFavoriteCard, + color: Theme.of(context) + .extension()! + .textFavoriteCard, ), ), ), - const SizedBox( - height: 4, - ), - Text( - "${Format.localizedStringAsFixed( - decimalPlaces: 2, - value: _cachedFiatValue, - locale: ref.watch( - localeServiceChangeNotifierProvider - .select((value) => value.locale), - ), - )} ${ref.watch( - prefsChangeNotifierProvider - .select((value) => value.currency), - )}", - style: STextStyles.itemSubtitle12(context).copyWith( - fontSize: 10, - color: Theme.of(context).extension()!.textFavoriteCard, + if (externalCalls) + const SizedBox( + height: 4, + ), + if (externalCalls) + Text( + "${Format.localizedStringAsFixed( + decimalPlaces: 2, + value: _cachedFiatValue, + locale: ref.watch( + localeServiceChangeNotifierProvider + .select((value) => value.locale), + ), + )} ${ref.watch( + prefsChangeNotifierProvider + .select((value) => value.currency), + )}", + style: STextStyles.itemSubtitle12(context).copyWith( + fontSize: 10, + color: Theme.of(context) + .extension()! + .textFavoriteCard, + ), ), - ), ], ); }, From 44523427e094ec3bbf052e4f74503c24dbfd66b2 Mon Sep 17 00:00:00 2001 From: julian Date: Mon, 17 Oct 2022 16:00:26 -0600 Subject: [PATCH 3/6] hide price values on wallet summary card when incognito mode enabled --- .../sub_widgets/wallet_summary_info.dart | 25 +++++++++++-------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/lib/pages/wallet_view/sub_widgets/wallet_summary_info.dart b/lib/pages/wallet_view/sub_widgets/wallet_summary_info.dart index 853e4dd9b..0d6ddd305 100644 --- a/lib/pages/wallet_view/sub_widgets/wallet_summary_info.dart +++ b/lib/pages/wallet_view/sub_widgets/wallet_summary_info.dart @@ -70,6 +70,8 @@ class _WalletSummaryInfoState extends State { builder: (_, ref, __) { final Coin coin = ref.watch(managerProvider.select((value) => value.coin)); + final externalCalls = ref.watch(prefsChangeNotifierProvider + .select((value) => value.externalCalls)); Future? totalBalanceFuture; Future? availableBalanceFuture; @@ -176,18 +178,19 @@ class _WalletSummaryInfoState extends State { ), ), ), - Text( - "${Format.localizedStringAsFixed( - value: priceTuple.item1 * balanceToShow, - locale: locale, - decimalPlaces: 2, - )} $baseCurrency", - style: STextStyles.subtitle500(context).copyWith( - color: Theme.of(context) - .extension()! - .textFavoriteCard, + if (externalCalls) + Text( + "${Format.localizedStringAsFixed( + value: priceTuple.item1 * balanceToShow, + locale: locale, + decimalPlaces: 2, + )} $baseCurrency", + style: STextStyles.subtitle500(context).copyWith( + color: Theme.of(context) + .extension()! + .textFavoriteCard, + ), ), - ), ], ); } else { From 643e0640c9668893b4f8f73ed4ac932240e651ca Mon Sep 17 00:00:00 2001 From: julian Date: Mon, 17 Oct 2022 16:07:40 -0600 Subject: [PATCH 4/6] hide price values on tx card+details view when incognito mode enabled --- .../transaction_details_view.dart | 24 ++++---- lib/widgets/transaction_card.dart | 56 ++++++++++--------- 2 files changed, 43 insertions(+), 37 deletions(-) diff --git a/lib/pages/wallet_view/transaction_views/transaction_details_view.dart b/lib/pages/wallet_view/transaction_views/transaction_details_view.dart index fdb8bf1a9..8d7aac85f 100644 --- a/lib/pages/wallet_view/transaction_views/transaction_details_view.dart +++ b/lib/pages/wallet_view/transaction_views/transaction_details_view.dart @@ -255,17 +255,19 @@ class _TransactionDetailsViewState const SizedBox( height: 2, ), - SelectableText( - "${Format.localizedStringAsFixed(value: (coin == Coin.monero ? (amount / 10000.toDecimal()).toDecimal() : coin == Coin.wownero ? (amount / 1000.toDecimal()).toDecimal() : amount) * ref.watch(priceAnd24hChangeNotifierProvider.select((value) => value.getPrice(coin).item1)), locale: ref.watch( - localeServiceChangeNotifierProvider - .select((value) => value.locale), - ), decimalPlaces: 2)} ${ref.watch( - prefsChangeNotifierProvider.select( - (value) => value.currency, - ), - )}", - style: STextStyles.itemSubtitle(context), - ), + if (ref.watch(prefsChangeNotifierProvider + .select((value) => value.externalCalls))) + SelectableText( + "${Format.localizedStringAsFixed(value: (coin == Coin.monero ? (amount / 10000.toDecimal()).toDecimal() : coin == Coin.wownero ? (amount / 1000.toDecimal()).toDecimal() : amount) * ref.watch(priceAnd24hChangeNotifierProvider.select((value) => value.getPrice(coin).item1)), locale: ref.watch( + localeServiceChangeNotifierProvider + .select((value) => value.locale), + ), decimalPlaces: 2)} ${ref.watch( + prefsChangeNotifierProvider.select( + (value) => value.currency, + ), + )}", + style: STextStyles.itemSubtitle(context), + ), ], ), TxIcon( diff --git a/lib/widgets/transaction_card.dart b/lib/widgets/transaction_card.dart index b2feaca7a..cb737ae08 100644 --- a/lib/widgets/transaction_card.dart +++ b/lib/widgets/transaction_card.dart @@ -202,35 +202,39 @@ class _TransactionCardState extends ConsumerState { ), ), ), - const SizedBox( - width: 10, - ), - Flexible( - child: FittedBox( - fit: BoxFit.scaleDown, - child: Builder( - builder: (_) { - // TODO: modify Format. to take optional Coin parameter so this type oif check isn't done in ui - int value = _transaction.amount; - if (coin == Coin.monero) { - value = (value ~/ 10000); - } else if (coin == Coin.wownero) { - value = (value ~/ 1000); - } + if (ref.watch(prefsChangeNotifierProvider + .select((value) => value.externalCalls))) + const SizedBox( + width: 10, + ), + if (ref.watch(prefsChangeNotifierProvider + .select((value) => value.externalCalls))) + Flexible( + child: FittedBox( + fit: BoxFit.scaleDown, + child: Builder( + builder: (_) { + // TODO: modify Format. to take optional Coin parameter so this type oif check isn't done in ui + int value = _transaction.amount; + if (coin == Coin.monero) { + value = (value ~/ 10000); + } else if (coin == Coin.wownero) { + value = (value ~/ 1000); + } - return Text( - "${Format.localizedStringAsFixed( - value: Format.satoshisToAmount(value) * - price, - locale: locale, - decimalPlaces: 2, - )} $baseCurrency", - style: STextStyles.label(context), - ); - }, + return Text( + "${Format.localizedStringAsFixed( + value: Format.satoshisToAmount(value) * + price, + locale: locale, + decimalPlaces: 2, + )} $baseCurrency", + style: STextStyles.label(context), + ); + }, + ), ), ), - ), ], ), ], From 86646994842edf639f4cbe373f34418a471b3d2a Mon Sep 17 00:00:00 2001 From: julian Date: Mon, 17 Oct 2022 16:37:47 -0600 Subject: [PATCH 5/6] default incognito mode fix --- lib/utilities/prefs.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/utilities/prefs.dart b/lib/utilities/prefs.dart index 0109755f7..2fc21a78d 100644 --- a/lib/utilities/prefs.dart +++ b/lib/utilities/prefs.dart @@ -569,6 +569,6 @@ class Prefs extends ChangeNotifier { Future _getHasExternalCalls() async { return await DB.instance.get( boxName: DB.boxNamePrefs, key: "externalCalls") as bool? ?? - false; + true; } } From e1e9cb71267c971bc67261f91c1c2ec1c3aa5c5a Mon Sep 17 00:00:00 2001 From: julian Date: Mon, 17 Oct 2022 17:20:08 -0600 Subject: [PATCH 6/6] disable checking trade history for updates in incognito mode --- .../exchange_view/trade_details_view.dart | 30 ++++++++++--------- lib/services/notifications_service.dart | 4 ++- 2 files changed, 19 insertions(+), 15 deletions(-) diff --git a/lib/pages/exchange_view/trade_details_view.dart b/lib/pages/exchange_view/trade_details_view.dart index bba561ead..76c845027 100644 --- a/lib/pages/exchange_view/trade_details_view.dart +++ b/lib/pages/exchange_view/trade_details_view.dart @@ -79,23 +79,25 @@ class _TradeDetailsViewState extends ConsumerState { transactionIfSentFromStack = widget.transactionIfSentFromStack; walletId = widget.walletId; - WidgetsBinding.instance.addPostFrameCallback((timeStamp) async { - final trade = ref - .read(tradesServiceProvider) - .trades - .firstWhere((e) => e.tradeId == tradeId); + if (ref.read(prefsChangeNotifierProvider).externalCalls) { + WidgetsBinding.instance.addPostFrameCallback((timeStamp) async { + final trade = ref + .read(tradesServiceProvider) + .trades + .firstWhere((e) => e.tradeId == tradeId); - if (mounted) { - final exchange = Exchange.fromName(trade.exchangeName); - final response = await exchange.updateTrade(trade); + if (mounted) { + final exchange = Exchange.fromName(trade.exchangeName); + final response = await exchange.updateTrade(trade); - if (mounted && response.value != null) { - await ref - .read(tradesServiceProvider) - .edit(trade: response.value!, shouldNotifyListeners: true); + if (mounted && response.value != null) { + await ref + .read(tradesServiceProvider) + .edit(trade: response.value!, shouldNotifyListeners: true); + } } - } - }); + }); + } super.initState(); } diff --git a/lib/services/notifications_service.dart b/lib/services/notifications_service.dart index 8ade3e969..2368adeab 100644 --- a/lib/services/notifications_service.dart +++ b/lib/services/notifications_service.dart @@ -84,7 +84,9 @@ class NotificationsService extends ChangeNotifier { _timer = Timer.periodic(notificationRefreshInterval, (_) { Logging.instance .log("Periodic notifications update check", level: LogLevel.Info); - _checkTrades(); + if (prefs.externalCalls) { + _checkTrades(); + } _checkTransactions(); }); }