diff --git a/lib/data/models/transaction_cubit.dart b/lib/data/models/transaction_cubit.dart index fbb7395047fe23233c5f533aac56017acd3c70a0..6ec5eecaa35de044e6af15c24e015bcb3a69787b 100644 --- a/lib/data/models/transaction_cubit.dart +++ b/lib/data/models/transaction_cubit.dart @@ -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)); } diff --git a/lib/main.dart b/lib/main.dart index a22034f95452af7eb826fb41f70b27a214a1e556..93224a7456cab416baf93be16ae17c64b3b86e8b 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -1,6 +1,7 @@ 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, diff --git a/pubspec.lock b/pubspec.lock index d2a05f1269eb9a7fff873ba5a074391563900cd7..5a1edf2bfea59cb6e26a9786781269d9d4ecc835 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -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: diff --git a/pubspec.yaml b/pubspec.yaml index 0ecf59bb04089848e977eb4a0023cc49a4cdec80..c7cc2eb26af1304880645589ffd29a5b957ea9e2 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -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: