Skip to content

Commit

Permalink
Added notifications for Dropped transactions
Browse files Browse the repository at this point in the history
  • Loading branch information
spylogsster committed May 18, 2022
1 parent 96b30ee commit 59e6ff2
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 9 deletions.
23 changes: 17 additions & 6 deletions browser/brave_wallet/wallet_notification_service.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<message_center::Notification> CreateMessageCenterNotification(
const std::u16string& title,
Expand Down Expand Up @@ -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)));
Expand Down
6 changes: 3 additions & 3 deletions browser/brave_wallet/wallet_notification_service_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}

Expand All @@ -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));
}
Expand Down
1 change: 1 addition & 0 deletions components/resources/wallet_strings.grdp
Original file line number Diff line number Diff line change
Expand Up @@ -458,4 +458,5 @@
<message name="IDS_WALLET_TRANSACTION_STATUS_UPDATE_MESSAGE_TEXT" desc="Notification message text when transaction status updated">Click here to check transaction details for <ph name="VALUE">$1<ex>0xABC</ex></ph></message>
<message name="IDS_WALLET_TRANSACTION_STATUS_UPDATE_MESSAGE_TITLE_CONFIRMED" desc="Notification message title when transaction confirmed">Transaction confirmed</message>
<message name="IDS_WALLET_TRANSACTION_STATUS_UPDATE_MESSAGE_TITLE_ERROR" desc="Notification message title when transaction error">Transaction error</message>
<message name="IDS_WALLET_TRANSACTION_STATUS_UPDATE_MESSAGE_TITLE_DROPPED" desc="Notification message title when transaction dropped">Transaction dropped</message>
</grit-part>

0 comments on commit 59e6ff2

Please sign in to comment.