load exchange data everytime on button or swipe to exchange screen

This commit is contained in:
julian 2022-10-17 13:42:10 -06:00
parent 135bf24426
commit a62d8f49a8
3 changed files with 16 additions and 37 deletions

View file

@ -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<HomeView> {
bool _exitEnabled = false;
final _cnLoadingService = ExchangeDataLoadingService();
final _exchangeDataLoadingService = ExchangeDataLoadingService();
Future<bool> _onWillPop() async {
// go to home view when tapping back on the main exchange view
@ -88,7 +86,7 @@ class _HomeViewState extends ConsumerState<HomeView> {
//
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<HomeView> {
_ref.listen(homeViewPageIndexStateProvider,
(previous, next) {
if (next is int) {
if (next == 1) {
_loadCNData();
}
if (next >= 0 && next <= 1) {
_pageController.animateToPage(
next,

View file

@ -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<HomeViewButtonBar> {
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<HomeViewButtonBar> {
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<dynamic>(
// 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",

View file

@ -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;