diff --git a/browser/ui/views/brave_actions/brave_actions_container.cc b/browser/ui/views/brave_actions/brave_actions_container.cc index 67075e2a1d61..54ae74925919 100644 --- a/browser/ui/views/brave_actions/brave_actions_container.cc +++ b/browser/ui/views/brave_actions/brave_actions_container.cc @@ -179,7 +179,8 @@ void BraveActionsContainer::AddActionStubForRewards() { return; } #if BUILDFLAG(BRAVE_REWARDS_ENABLED) - actions_[id].view_ = std::make_unique(this); + actions_[id].view_ = std::make_unique( + browser_->profile(), this); AttachAction(actions_[id]); #endif } diff --git a/browser/ui/views/brave_actions/brave_rewards_action_stub_view.cc b/browser/ui/views/brave_actions/brave_rewards_action_stub_view.cc index 222457a93f42..e99a2544b229 100644 --- a/browser/ui/views/brave_actions/brave_rewards_action_stub_view.cc +++ b/browser/ui/views/brave_actions/brave_rewards_action_stub_view.cc @@ -11,10 +11,13 @@ #include "brave/browser/ui/brave_actions/brave_action_icon_with_badge_image_source.h" // NOLINT #include "brave/browser/ui/brave_actions/constants.h" +#include "brave/components/brave_rewards/common/pref_names.h" #include "brave/components/brave_rewards/resources/extension/grit/brave_rewards_extension_resources.h" // NOLINT +#include "chrome/browser/profiles/profile.h" #include "chrome/browser/ui/views/chrome_layout_provider.h" #include "chrome/browser/ui/views/toolbar/toolbar_action_view.h" #include "chrome/browser/ui/views/toolbar/toolbar_ink_drop_util.h" +#include "components/prefs/pref_service.h" #include "third_party/skia/include/core/SkBitmap.h" #include "ui/base/resource/resource_bundle.h" #include "ui/gfx/geometry/rect.h" @@ -29,12 +32,12 @@ namespace { constexpr SkColor kRewardsBadgeBg = SkColorSetRGB(0xfb, 0x54, 0x2b); - const std::string kRewardsInitialBadgeText = "1"; } -BraveRewardsActionStubView::BraveRewardsActionStubView( +BraveRewardsActionStubView::BraveRewardsActionStubView(Profile* profile, BraveRewardsActionStubView::Delegate* delegate) : LabelButton(this, base::string16()), + profile_(profile), delegate_(delegate) { SetInkDropMode(InkDropMode::ON); set_has_ink_drop_action_on_click(true); @@ -55,8 +58,13 @@ BraveRewardsActionStubView::BraveRewardsActionStubView( image_source->SetIcon(gfx::Image(image)); // Set text on badge std::unique_ptr badge; + // TODO(petemill): Provide an observer if this value is expected to change + // during runtime. At time of implementation, this would only be different + // after a restart. + badge_text_pref_.Init( + brave_rewards::prefs::kRewardsBadgeText, profile->GetPrefs()); badge.reset(new IconWithBadgeImageSource::Badge( - kRewardsInitialBadgeText, + badge_text_pref_.GetValue(), SK_ColorWHITE, kRewardsBadgeBg)); image_source->SetBadge(std::move(badge)); @@ -85,6 +93,15 @@ BraveRewardsActionStubView::~BraveRewardsActionStubView() {} void BraveRewardsActionStubView::ButtonPressed( Button* sender, const ui::Event& event) { + // We only show the default badge text once, so once the button + // is clicked then change it back. We consider pressing the button + // as an action to 'dismiss' the badge notification. + // This cannot be done from the rewards service since it is not + // involved in showing the pre-opt-in panel. + if (badge_text_pref_.GetValue() != "") { + profile_->GetPrefs()->SetString(brave_rewards::prefs::kRewardsBadgeText, + ""); + } delegate_->OnRewardsStubButtonClicked(); } diff --git a/browser/ui/views/brave_actions/brave_rewards_action_stub_view.h b/browser/ui/views/brave_actions/brave_rewards_action_stub_view.h index d76da72733ab..6f915f39fa7d 100644 --- a/browser/ui/views/brave_actions/brave_rewards_action_stub_view.h +++ b/browser/ui/views/brave_actions/brave_rewards_action_stub_view.h @@ -8,9 +8,12 @@ #include +#include "components/prefs/pref_member.h" #include "ui/views/controls/button/label_button.h" #include "ui/views/view.h" +class Profile; + // A button to take the place of an extension that will be loaded in the future. // Call SetImage with the BraveActionIconWithBadgeImageSource // Call highlight etc from ToolbarActionView @@ -25,7 +28,7 @@ class BraveRewardsActionStubView : public views::LabelButton, ~Delegate() {} }; - explicit BraveRewardsActionStubView(Delegate* delegate); + explicit BraveRewardsActionStubView(Profile* profile, Delegate* delegate); ~BraveRewardsActionStubView() override; // views::ButtonListener @@ -41,6 +44,8 @@ class BraveRewardsActionStubView : public views::LabelButton, private: gfx::Size CalculatePreferredSize() const override; + StringPrefMember badge_text_pref_; + Profile* profile_; Delegate* delegate_; DISALLOW_COPY_AND_ASSIGN(BraveRewardsActionStubView); diff --git a/components/brave_rewards/browser/rewards_service.cc b/components/brave_rewards/browser/rewards_service.cc index 8b90c877aa84..90496ae64021 100644 --- a/components/brave_rewards/browser/rewards_service.cc +++ b/components/brave_rewards/browser/rewards_service.cc @@ -60,6 +60,7 @@ void RewardsService::RegisterProfilePrefs(PrefRegistrySimple* registry) { registry->RegisterDictionaryPref(prefs::kRewardsExternalWallets); registry->RegisterUint64Pref(prefs::kStateServerPublisherListStamp, 0ull); registry->RegisterStringPref(prefs::kStateUpholdAnonAddress, ""); + registry->RegisterStringPref(prefs::kRewardsBadgeText, "1"); } } // namespace brave_rewards diff --git a/components/brave_rewards/common/pref_names.cc b/components/brave_rewards/common/pref_names.cc index 26aca07e55f5..d277359130b0 100644 --- a/components/brave_rewards/common/pref_names.cc +++ b/components/brave_rewards/common/pref_names.cc @@ -28,7 +28,7 @@ const char kStateServerPublisherListStamp[] = "brave.rewards.server_publisher_list_stamp"; const char kStateUpholdAnonAddress[] = "brave.rewards.uphold_anon_address"; - +const char kRewardsBadgeText[] = "brave.rewards.badge_text"; const char kUseRewardsStagingServer[] = "brave.rewards.use_staging_server"; } // namespace prefs } // namespace brave_rewards diff --git a/components/brave_rewards/common/pref_names.h b/components/brave_rewards/common/pref_names.h index a4ae0283db6d..590bfb8635d7 100644 --- a/components/brave_rewards/common/pref_names.h +++ b/components/brave_rewards/common/pref_names.h @@ -20,6 +20,7 @@ extern const char kRewardsUserHasFunded[]; extern const char kRewardsAddFundsNotification[]; extern const char kRewardsNotificationStartupDelay[]; extern const char kRewardsExternalWallets[]; +extern const char kRewardsBadgeText[]; // Defined in native-ledger extern const char kStateServerPublisherListStamp[];