From a472527c6f19f2a3a96956e4dc0a5ca1c7bd7022 Mon Sep 17 00:00:00 2001 From: Godwin Asuquo <41484542+godilite@users.noreply.github.com> Date: Mon, 17 Apr 2023 21:06:58 +0300 Subject: [PATCH] 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 --- lib/entities/preferences_key.dart | 2 ++ .../exchange_trade/exchange_trade_page.dart | 7 +++-- lib/src/screens/send/send_page.dart | 9 ++++-- lib/utils/request_review_handler.dart | 29 +++++++++++++++++++ .../dashboard/dashboard_view_model.dart | 2 +- pubspec_base.yaml | 1 + 6 files changed, 44 insertions(+), 6 deletions(-) create mode 100644 lib/utils/request_review_handler.dart diff --git a/lib/entities/preferences_key.dart b/lib/entities/preferences_key.dart index 589b2a67e..be93300a7 100644 --- a/lib/entities/preferences_key.dart +++ b/lib/entities/preferences_key.dart @@ -31,6 +31,8 @@ class PreferencesKey { static const pinTimeOutDuration = 'pin_timeout_duration'; static const lastAuthTimeMilliseconds = 'last_auth_time_milliseconds'; static const lastPopupDate = 'last_popup_date'; + static const lastAppReviewDate = 'last_app_review_date'; + static String moneroWalletUpdateV1Key(String name) diff --git a/lib/src/screens/exchange_trade/exchange_trade_page.dart b/lib/src/screens/exchange_trade/exchange_trade_page.dart index 9eb17c762..f06e879a9 100644 --- a/lib/src/screens/exchange_trade/exchange_trade_page.dart +++ b/lib/src/screens/exchange_trade/exchange_trade_page.dart @@ -1,4 +1,5 @@ import 'dart:ui'; +import 'package:cake_wallet/utils/request_review_handler.dart'; import 'package:mobx/mobx.dart'; import 'package:flutter_mobx/flutter_mobx.dart'; import 'package:flutter/material.dart'; @@ -351,8 +352,10 @@ class ExchangeTradeState extends State { right: 24, bottom: 24, child: PrimaryButton( - onPressed: () => - Navigator.of(popupContext).pop(), + onPressed: () { + Navigator.of(popupContext).pop(); + RequestReviewHandler.requestReview(); + }, text: S.of(popupContext).send_got_it, color: Theme.of(popupContext) .accentTextTheme! diff --git a/lib/src/screens/send/send_page.dart b/lib/src/screens/send/send_page.dart index c30c46565..544bed39c 100644 --- a/lib/src/screens/send/send_page.dart +++ b/lib/src/screens/send/send_page.dart @@ -6,6 +6,7 @@ import 'package:cake_wallet/src/widgets/alert_with_two_actions.dart'; import 'package:cake_wallet/src/widgets/picker.dart'; import 'package:cake_wallet/src/widgets/template_tile.dart'; import 'package:cake_wallet/utils/payment_request.dart'; +import 'package:cake_wallet/utils/request_review_handler.dart'; import 'package:cake_wallet/utils/responsive_layout_util.dart'; import 'package:cake_wallet/view_model/send/output.dart'; import 'package:flutter/material.dart'; @@ -383,9 +384,11 @@ class SendPage extends BasePage { alertContent: S.of(context).send_success( sendViewModel.selectedCryptoCurrency.toString()), buttonText: S.of(context).ok, - buttonAction: () => - Navigator.of(context).pop()); - } + buttonAction: () { + Navigator.of(context).pop(); + RequestReviewHandler.requestReview(); + }); + } return Offstage(); }); diff --git a/lib/utils/request_review_handler.dart b/lib/utils/request_review_handler.dart new file mode 100644 index 000000000..487a360bf --- /dev/null +++ b/lib/utils/request_review_handler.dart @@ -0,0 +1,29 @@ +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(); + } + } +} diff --git a/lib/view_model/dashboard/dashboard_view_model.dart b/lib/view_model/dashboard/dashboard_view_model.dart index 137dc0a17..6cfbe1455 100644 --- a/lib/view_model/dashboard/dashboard_view_model.dart +++ b/lib/view_model/dashboard/dashboard_view_model.dart @@ -146,7 +146,7 @@ abstract class DashboardViewModelBase with Store { } reaction((_) => appStore.wallet, _onWalletChange); - + connectMapToListWithTransform( appStore.wallet!.transactionHistory.transactions, transactions, diff --git a/pubspec_base.yaml b/pubspec_base.yaml index d427a56d8..c595ce210 100644 --- a/pubspec_base.yaml +++ b/pubspec_base.yaml @@ -67,6 +67,7 @@ dependencies: wakelock: ^0.6.2 flutter_mailer: ^2.0.2 device_info_plus: 8.1.0 + in_app_review: ^2.0.6 cake_backup: git: url: https://github.com/cake-tech/cake_backup.git