Add cool-down of 7 days between reports
OmarHatem committed
Feb 7, 2023 at 16:53 UTC
a8025ffbec13f05009c5f688464544a72223fdb5
2 files changed
+16
-2
lib/entities/preferences_key.dart
+1
@@ -29,6 +29,7 @@ class PreferencesKey {
29
static const moneroWalletPasswordUpdateV1Base = 'monero_wallet_update_v1';
30
static const pinTimeOutDuration = 'pin_timeout_duration';
31
static const lastAuthTimeMilliseconds = 'last_auth_time_milliseconds';
32
+ static const lastPopupDate = 'last_popup_date';
33
34
35
static String moneroWalletUpdateV1Key(String name)
lib/utils/exception_handler.dart
+15
-2
@@ -1,6 +1,7 @@
1
import 'dart:convert';
2
import 'dart:io';
3
4
+import 'package:cake_wallet/entities/preferences_key.dart';
5
import 'package:cake_wallet/generated/i18n.dart';
6
import 'package:cake_wallet/main.dart';
7
import 'package:cake_wallet/src/widgets/alert_with_two_actions.dart';
@@ -9,6 +10,7 @@ import 'package:flutter/foundation.dart';
10
import 'package:flutter/material.dart';
11
import 'package:flutter_mailer/flutter_mailer.dart';
12
import 'package:path_provider/path_provider.dart';
13
+import 'package:shared_preferences/shared_preferences.dart';
14
15
class ExceptionHandler {
16
static bool _hasError = false;
@@ -59,7 +61,7 @@ class ExceptionHandler {
61
}
62
}
63
62
- static void onError(FlutterErrorDetails errorDetails) {
64
+ static void onError(FlutterErrorDetails errorDetails) async {
65
if (kDebugMode) {
66
FlutterError.presentError(errorDetails);
67
return;
@@ -71,11 +73,22 @@ class ExceptionHandler {
73
74
_saveException(errorDetails.exception.toString(), errorDetails.stack);
75
74
- if (_hasError) {
76
+ final sharedPrefs = await SharedPreferences.getInstance();
77
+
78
+ final lastPopupDate =
79
+ DateTime.tryParse(sharedPrefs.getString(PreferencesKey.lastPopupDate) ?? '') ??
80
+ DateTime.parse("2001-01-01");
81
+
82
+ final durationSinceLastReport = DateTime.now().difference(lastPopupDate).inDays;
83
+
84
+ // cool-down duration to be 7 days between reports
85
+ if (_hasError || durationSinceLastReport < 7) {
86
return;
87
}
88
_hasError = true;
89
90
+ sharedPrefs.setString(PreferencesKey.lastPopupDate, DateTime.now().toString());
91
+
92
WidgetsBinding.instance.addPostFrameCallback(
93
(timeStamp) async {
94
await showPopUp<void>(