From 59e6ff2a1047d038dace43597938eaf121cf5872 Mon Sep 17 00:00:00 2001 From: Sergey P Date: Tue, 17 May 2022 11:13:16 +0300 Subject: [PATCH] Added notifications for Dropped transactions --- .../wallet_notification_service.cc | 23 ++++++++++++++----- .../wallet_notification_service_unittest.cc | 6 ++--- components/resources/wallet_strings.grdp | 1 + 3 files changed, 21 insertions(+), 9 deletions(-) diff --git a/browser/brave_wallet/wallet_notification_service.cc b/browser/brave_wallet/wallet_notification_service.cc index 6ff36d43f5a1..4d3dfa499177 100644 --- a/browser/brave_wallet/wallet_notification_service.cc +++ b/browser/brave_wallet/wallet_notification_service.cc @@ -21,6 +21,20 @@ #include "ui/message_center/public/cpp/notifier_id.h" namespace { +int GetStatusTitle(brave_wallet::mojom::TransactionStatus status) { + switch (status) { + case brave_wallet::mojom::TransactionStatus::Confirmed: + return IDS_WALLET_TRANSACTION_STATUS_UPDATE_MESSAGE_TITLE_CONFIRMED; + case brave_wallet::mojom::TransactionStatus::Error: + return IDS_WALLET_TRANSACTION_STATUS_UPDATE_MESSAGE_TITLE_ERROR; + case brave_wallet::mojom::TransactionStatus::Dropped: + return IDS_WALLET_TRANSACTION_STATUS_UPDATE_MESSAGE_TITLE_DROPPED; + default: + break; + } + VLOG(1) << "No title for " << int(status) << " transaction status"; + return -1; +} std::unique_ptr CreateMessageCenterNotification( const std::u16string& title, @@ -69,19 +83,16 @@ WalletNotificationService::~WalletNotificationService() {} bool WalletNotificationService::ShouldDisplayUserNotification( mojom::TransactionStatus status) { return (status == mojom::TransactionStatus::Confirmed || - status == mojom::TransactionStatus::Error); + status == mojom::TransactionStatus::Error || + status == mojom::TransactionStatus::Dropped); } void WalletNotificationService::DisplayUserNotification( mojom::TransactionStatus status, const std::string& address, const std::string& tx_id) { - auto status_title = - status == mojom::TransactionStatus::Confirmed - ? IDS_WALLET_TRANSACTION_STATUS_UPDATE_MESSAGE_TITLE_CONFIRMED - : IDS_WALLET_TRANSACTION_STATUS_UPDATE_MESSAGE_TITLE_ERROR; PushNotification(context_, tx_id, address, - l10n_util::GetStringUTF16(status_title), + l10n_util::GetStringUTF16(GetStatusTitle(status)), l10n_util::GetStringFUTF16( IDS_WALLET_TRANSACTION_STATUS_UPDATE_MESSAGE_TEXT, base::UTF8ToUTF16(address))); diff --git a/browser/brave_wallet/wallet_notification_service_unittest.cc b/browser/brave_wallet/wallet_notification_service_unittest.cc index 3e12349cf249..f21c014ee751 100644 --- a/browser/brave_wallet/wallet_notification_service_unittest.cc +++ b/browser/brave_wallet/wallet_notification_service_unittest.cc @@ -82,10 +82,10 @@ class WalletNotificationServiceUnitTest : public testing::Test { TEST_F(WalletNotificationServiceUnitTest, ShouldShowNotifications) { EXPECT_TRUE(ShouldDisplayNotifications(mojom::TransactionStatus::Confirmed)); EXPECT_TRUE(ShouldDisplayNotifications(mojom::TransactionStatus::Error)); + EXPECT_TRUE(ShouldDisplayNotifications(mojom::TransactionStatus::Dropped)); EXPECT_FALSE(ShouldDisplayNotifications(mojom::TransactionStatus::Approved)); EXPECT_FALSE(ShouldDisplayNotifications(mojom::TransactionStatus::Rejected)); - EXPECT_FALSE(ShouldDisplayNotifications(mojom::TransactionStatus::Dropped)); EXPECT_FALSE(ShouldDisplayNotifications(mojom::TransactionStatus::Submitted)); } @@ -94,13 +94,13 @@ TEST_F(WalletNotificationServiceUnitTest, TransactionStatusChanged) { mojom::TransactionStatus::Confirmed)); EXPECT_TRUE( WasNotificationDisplayedOnStatusChange(mojom::TransactionStatus::Error)); + EXPECT_TRUE(WasNotificationDisplayedOnStatusChange( + mojom::TransactionStatus::Dropped)); EXPECT_FALSE(WasNotificationDisplayedOnStatusChange( mojom::TransactionStatus::Approved)); EXPECT_FALSE(WasNotificationDisplayedOnStatusChange( mojom::TransactionStatus::Rejected)); - EXPECT_FALSE(WasNotificationDisplayedOnStatusChange( - mojom::TransactionStatus::Dropped)); EXPECT_FALSE(WasNotificationDisplayedOnStatusChange( mojom::TransactionStatus::Submitted)); } diff --git a/components/resources/wallet_strings.grdp b/components/resources/wallet_strings.grdp index d0d94da3d5d7..7cea822a4a42 100644 --- a/components/resources/wallet_strings.grdp +++ b/components/resources/wallet_strings.grdp @@ -458,4 +458,5 @@ Click here to check transaction details for $10xABC Transaction confirmed Transaction error + Transaction dropped