mirror of
https://github.com/cypherstack/stack_wallet.git
synced 2025-01-10 20:54:33 +00:00
load exchange data everytime on button or swipe to exchange screen
This commit is contained in:
parent
135bf24426
commit
a62d8f49a8
3 changed files with 16 additions and 37 deletions
|
@ -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/services/exchange/exchange_data_loading_service.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/logger.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/theme/stack_colors.dart';
|
import 'package:stackwallet/utilities/theme/stack_colors.dart';
|
||||||
import 'package:stackwallet/widgets/custom_buttons/app_bar_icon_button.dart';
|
import 'package:stackwallet/widgets/custom_buttons/app_bar_icon_button.dart';
|
||||||
import 'package:stackwallet/widgets/stack_dialog.dart';
|
import 'package:stackwallet/widgets/stack_dialog.dart';
|
||||||
|
|
||||||
import 'package:stackwallet/utilities/logger.dart';
|
|
||||||
|
|
||||||
import 'package:stackwallet/utilities/prefs.dart';
|
|
||||||
|
|
||||||
class HomeView extends ConsumerStatefulWidget {
|
class HomeView extends ConsumerStatefulWidget {
|
||||||
const HomeView({Key? key}) : super(key: key);
|
const HomeView({Key? key}) : super(key: key);
|
||||||
|
|
||||||
|
@ -45,7 +43,7 @@ class _HomeViewState extends ConsumerState<HomeView> {
|
||||||
|
|
||||||
bool _exitEnabled = false;
|
bool _exitEnabled = false;
|
||||||
|
|
||||||
final _cnLoadingService = ExchangeDataLoadingService();
|
final _exchangeDataLoadingService = ExchangeDataLoadingService();
|
||||||
|
|
||||||
Future<bool> _onWillPop() async {
|
Future<bool> _onWillPop() async {
|
||||||
// go to home view when tapping back on the main exchange view
|
// 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;
|
final externalCalls = Prefs.instance.externalCalls;
|
||||||
if (externalCalls) {
|
if (externalCalls) {
|
||||||
_cnLoadingService.loadAll(ref);
|
_exchangeDataLoadingService.loadAll(ref);
|
||||||
} else {
|
} else {
|
||||||
Logging.instance.log("User does not want to use external calls",
|
Logging.instance.log("User does not want to use external calls",
|
||||||
level: LogLevel.Info);
|
level: LogLevel.Info);
|
||||||
|
@ -290,6 +288,9 @@ class _HomeViewState extends ConsumerState<HomeView> {
|
||||||
_ref.listen(homeViewPageIndexStateProvider,
|
_ref.listen(homeViewPageIndexStateProvider,
|
||||||
(previous, next) {
|
(previous, next) {
|
||||||
if (next is int) {
|
if (next is int) {
|
||||||
|
if (next == 1) {
|
||||||
|
_loadCNData();
|
||||||
|
}
|
||||||
if (next >= 0 && next <= 1) {
|
if (next >= 0 && next <= 1) {
|
||||||
_pageController.animateToPage(
|
_pageController.animateToPage(
|
||||||
next,
|
next,
|
||||||
|
|
|
@ -1,5 +1,3 @@
|
||||||
import 'dart:async';
|
|
||||||
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||||
import 'package:stackwallet/providers/providers.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/utilities/theme/stack_colors.dart';
|
||||||
import 'package:stackwallet/widgets/stack_dialog.dart';
|
import 'package:stackwallet/widgets/stack_dialog.dart';
|
||||||
|
|
||||||
import 'package:stackwallet/utilities/prefs.dart';
|
|
||||||
|
|
||||||
class HomeViewButtonBar extends ConsumerStatefulWidget {
|
class HomeViewButtonBar extends ConsumerStatefulWidget {
|
||||||
const HomeViewButtonBar({Key? key}) : super(key: key);
|
const HomeViewButtonBar({Key? key}) : super(key: key);
|
||||||
|
|
||||||
|
@ -18,8 +14,8 @@ class HomeViewButtonBar extends ConsumerStatefulWidget {
|
||||||
}
|
}
|
||||||
|
|
||||||
class _HomeViewButtonBarState extends ConsumerState<HomeViewButtonBar> {
|
class _HomeViewButtonBarState extends ConsumerState<HomeViewButtonBar> {
|
||||||
final DateTime _lastRefreshed = DateTime.now();
|
// final DateTime _lastRefreshed = DateTime.now();
|
||||||
final Duration _refreshInterval = const Duration(hours: 1);
|
// final Duration _refreshInterval = const Duration(hours: 1);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
|
@ -104,34 +100,14 @@ class _HomeViewButtonBarState extends ConsumerState<HomeViewButtonBar> {
|
||||||
if (selectedIndex != 1) {
|
if (selectedIndex != 1) {
|
||||||
ref.read(homeViewPageIndexStateProvider.state).state = 1;
|
ref.read(homeViewPageIndexStateProvider.state).state = 1;
|
||||||
}
|
}
|
||||||
DateTime now = DateTime.now();
|
// DateTime now = DateTime.now();
|
||||||
final _cnLoadingService = ExchangeDataLoadingService();
|
if (ref.read(prefsChangeNotifierProvider).externalCalls) {
|
||||||
final externalCalls = Prefs.instance.externalCalls;
|
|
||||||
if (!externalCalls) {
|
|
||||||
print("loading?");
|
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);
|
await ExchangeDataLoadingService().loadAll(ref);
|
||||||
// if (!okPressed && mounted) {
|
|
||||||
// Navigator.of(context).pop();
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
|
// if (now.difference(_lastRefreshed) > _refreshInterval) {
|
||||||
|
// await ExchangeDataLoadingService().loadAll(ref);
|
||||||
|
// }
|
||||||
},
|
},
|
||||||
child: Text(
|
child: Text(
|
||||||
"Exchange",
|
"Exchange",
|
||||||
|
|
|
@ -546,6 +546,8 @@ class Prefs extends ChangeNotifier {
|
||||||
boxName: DB.boxNamePrefs, key: "startupWalletId") as String?;
|
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 _externalCalls = true;
|
||||||
|
|
||||||
bool get externalCalls => _externalCalls;
|
bool get externalCalls => _externalCalls;
|
||||||
|
|
Loading…
Reference in a new issue