cake_wallet/lib/utils/request_review_handler.dart
Godwin Asuquo a472527c6f
CW-33 Add app review after successful transactions and exchange (#864)
* Add app reveiw on transactions and exchange

* Update Onramper page

* Fix issues in popup review
2023-04-17 20:06:58 +02:00

29 lines
975 B
Dart

import 'package:cake_wallet/entities/preferences_key.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:in_app_review/in_app_review.dart';
class RequestReviewHandler {
static const _coolDownDurationInDays = 30;
static void requestReview() async {
final sharedPrefs = await SharedPreferences.getInstance();
final lastReviewRequestDate =
DateTime.tryParse(sharedPrefs.getString(PreferencesKey.lastAppReviewDate) ?? '') ??
DateTime.now().subtract(Duration(days: _coolDownDurationInDays + 1));
final durationSinceLastRequest = DateTime.now().difference(lastReviewRequestDate).inDays;
if (durationSinceLastRequest < _coolDownDurationInDays) {
return;
}
sharedPrefs.setString(PreferencesKey.lastAppReviewDate, DateTime.now().toString());
final InAppReview inAppReview = InAppReview.instance;
if (await inAppReview.isAvailable()) {
inAppReview.requestReview();
}
}
}