From a62d8f49a82c6696c461a17760566f090b483367 Mon Sep 17 00:00:00 2001 From: julian Date: Mon, 17 Oct 2022 13:42:10 -0600 Subject: [PATCH] load exchange data everytime on button or swipe to exchange screen --- lib/pages/home_view/home_view.dart | 13 ++++--- .../sub_widgets/home_view_button_bar.dart | 38 ++++--------------- lib/utilities/prefs.dart | 2 + 3 files changed, 16 insertions(+), 37 deletions(-) diff --git a/lib/pages/home_view/home_view.dart b/lib/pages/home_view/home_view.dart index 2bdcbace0..2e7c38202 100644 --- a/lib/pages/home_view/home_view.dart +++ b/lib/pages/home_view/home_view.dart @@ -16,15 +16,13 @@ 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'; import 'package:stackwallet/widgets/stack_dialog.dart'; -import 'package:stackwallet/utilities/logger.dart'; - -import 'package:stackwallet/utilities/prefs.dart'; - class HomeView extends ConsumerStatefulWidget { const HomeView({Key? key}) : super(key: key); @@ -45,7 +43,7 @@ class _HomeViewState extends ConsumerState { bool _exitEnabled = false; - final _cnLoadingService = ExchangeDataLoadingService(); + final _exchangeDataLoadingService = ExchangeDataLoadingService(); Future _onWillPop() async { // go to home view when tapping back on the main exchange view @@ -88,7 +86,7 @@ class _HomeViewState extends ConsumerState { // final externalCalls = Prefs.instance.externalCalls; if (externalCalls) { - _cnLoadingService.loadAll(ref); + _exchangeDataLoadingService.loadAll(ref); } else { Logging.instance.log("User does not want to use external calls", level: LogLevel.Info); @@ -290,6 +288,9 @@ class _HomeViewState extends ConsumerState { _ref.listen(homeViewPageIndexStateProvider, (previous, next) { if (next is int) { + if (next == 1) { + _loadCNData(); + } if (next >= 0 && next <= 1) { _pageController.animateToPage( next, diff --git a/lib/pages/home_view/sub_widgets/home_view_button_bar.dart b/lib/pages/home_view/sub_widgets/home_view_button_bar.dart index e502d4537..61a6c4185 100644 --- a/lib/pages/home_view/sub_widgets/home_view_button_bar.dart +++ b/lib/pages/home_view/sub_widgets/home_view_button_bar.dart @@ -1,5 +1,3 @@ -import 'dart:async'; - import 'package:flutter/material.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:stackwallet/providers/providers.dart'; @@ -8,8 +6,6 @@ import 'package:stackwallet/utilities/text_styles.dart'; import 'package:stackwallet/utilities/theme/stack_colors.dart'; import 'package:stackwallet/widgets/stack_dialog.dart'; -import 'package:stackwallet/utilities/prefs.dart'; - class HomeViewButtonBar extends ConsumerStatefulWidget { const HomeViewButtonBar({Key? key}) : super(key: key); @@ -18,8 +14,8 @@ class HomeViewButtonBar extends ConsumerStatefulWidget { } class _HomeViewButtonBarState extends ConsumerState { - final DateTime _lastRefreshed = DateTime.now(); - final Duration _refreshInterval = const Duration(hours: 1); + // final DateTime _lastRefreshed = DateTime.now(); + // final Duration _refreshInterval = const Duration(hours: 1); @override void initState() { @@ -104,34 +100,14 @@ class _HomeViewButtonBarState extends ConsumerState { if (selectedIndex != 1) { ref.read(homeViewPageIndexStateProvider.state).state = 1; } - DateTime now = DateTime.now(); - final _cnLoadingService = ExchangeDataLoadingService(); - final externalCalls = Prefs.instance.externalCalls; - if (!externalCalls) { + // DateTime now = DateTime.now(); + if (ref.read(prefsChangeNotifierProvider).externalCalls) { print("loading?"); - unawaited(_cnLoadingService.loadAll(ref)); - } - if (now.difference(_lastRefreshed) > _refreshInterval) { - // bool okPressed = false; - // showDialog( - // context: context, - // barrierDismissible: false, - // builder: (_) => const StackDialog( - // // builder: (_) => StackOkDialog( - // title: "Refreshing ChangeNOW data", - // message: "This may take a while", - // // onOkPressed: (value) { - // // if (value == "OK") { - // // okPressed = true; - // // } - // // }, - // ), - // ); await ExchangeDataLoadingService().loadAll(ref); - // if (!okPressed && mounted) { - // Navigator.of(context).pop(); - // } } + // if (now.difference(_lastRefreshed) > _refreshInterval) { + // await ExchangeDataLoadingService().loadAll(ref); + // } }, child: Text( "Exchange", diff --git a/lib/utilities/prefs.dart b/lib/utilities/prefs.dart index cc818f982..0109755f7 100644 --- a/lib/utilities/prefs.dart +++ b/lib/utilities/prefs.dart @@ -546,6 +546,8 @@ class Prefs extends ChangeNotifier { boxName: DB.boxNamePrefs, key: "startupWalletId") as String?; } + // incognito mode off by default + // allow external network calls such as exchange data and price info bool _externalCalls = true; bool get externalCalls => _externalCalls;