Skip to content
Snippets Groups Projects
Commit 262efcea authored by vjrj's avatar vjrj
Browse files

Improve notification. Use cron instead of once

parent 5afb7895
No related branches found
No related tags found
No related merge requests found
......@@ -68,7 +68,7 @@ class TransactionsCubit extends HydratedCubit<TransactionsAndBalanceState> {
final Contact to = await ContactsCache().getContact(tx.from);
NotificationController.createNewNotification(
tx.time.millisecondsSinceEpoch.toString(),
amount: tx.amount / 100,
amount: -tx.amount / 100,
to: to.title);
emit(newState.copyWith(lastSentNotification: tx.time));
}
......
import 'dart:io';
import 'package:connectivity_wrapper/connectivity_wrapper.dart';
import 'package:cron/cron.dart';
import 'package:easy_localization/easy_localization.dart';
import 'package:filesystem_picker/filesystem_picker.dart';
import 'package:flutter/foundation.dart';
......@@ -276,6 +277,22 @@ class _GinkgoAppState extends State<GinkgoApp> {
NodeManager().loadFromCubit(context.read<NodeListCubit>());
// Only after at least the action method is set, the notification events are delivered
NotificationController.startListeningNotificationEvents();
final Cron cron = Cron();
cron.schedule(Schedule.parse(kReleaseMode ? '*/10 * * * *' : '*/2 * * * *'),
() async {
logger('---------- fetchTransactions via cron');
fetchTransactions(context);
});
Once.runHourly('load_nodes', callback: () {
logger('load nodes via once');
_loadNodes();
}, fallback: () {
_printNodeStatus(prefix: 'After once hourly having');
});
Once.runDaily('clear_errors', callback: () {
logger('clearErrors via once');
NodeManager().cleanErrorStats();
});
}
@override
......@@ -288,21 +305,6 @@ class _GinkgoAppState extends State<GinkgoApp> {
Widget build(BuildContext context) {
return BlocBuilder<NodeListCubit, NodeListState>(
builder: (BuildContext nodeContext, NodeListState state) {
Once.runHourly('load_nodes',
callback: () => _loadNodes(),
fallback: () {
_printNodeStatus(prefix: 'After once hourly having');
});
Once.runCustom('clear_errors', callback: () {
NodeManager().cleanErrorStats();
}, duration: const Duration(minutes: 90));
Once.runCustom('fetch_transactions', callback: () {
logger('---------- fetchTransactions via once');
fetchTransactions(context);
}, fallback: () {
logger('fetch_transactions fallback, already called');
}, duration: const Duration(minutes: kReleaseMode ? 10 : 2));
// Not necessary with previous one ?? fetchTransactions(context);
return ConnectivityAppWrapper(
app: FilesystemPickerDefaultOptions(
fileTileSelectMode: FileTileSelectMode.wholeTile,
......
......@@ -273,6 +273,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "5.0.2"
cron:
dependency: "direct main"
description:
name: cron
sha256: d98aa8cdad0cccdb6b098e6a1fb89339c180d8a229145fa4cd8c6fc538f0e35f
url: "https://pub.dev"
source: hosted
version: "0.5.1"
cross_file:
dependency: transitive
description:
......
......@@ -72,6 +72,7 @@ dependencies:
path: ^1.8.2
path_provider: ^2.0.14
awesome_notifications: ^0.7.4+1
cron: ^0.5.1
dev_dependencies:
flutter_test:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment