From 615cec2da9789fbee054675416efa1ed5302f9e9 Mon Sep 17 00:00:00 2001 From: zenparsing Date: Thu, 12 Dec 2024 15:08:01 -0500 Subject: [PATCH] [Rewards 3.0] Add creator ID parameter to Rewards page --- .../brave_rewards/rewards_page_handler.cc | 22 +++++++++---------- .../brave_rewards/rewards_page_handler.h | 10 +++++---- .../common/mojom/rewards_page.mojom | 12 ++++++---- .../rewards_page/webui/webui_model.ts | 10 +++++++-- 4 files changed, 32 insertions(+), 22 deletions(-) diff --git a/browser/ui/webui/brave_rewards/rewards_page_handler.cc b/browser/ui/webui/brave_rewards/rewards_page_handler.cc index 576635c9127f..56c3bf1811b2 100644 --- a/browser/ui/webui/brave_rewards/rewards_page_handler.cc +++ b/browser/ui/webui/brave_rewards/rewards_page_handler.cc @@ -319,14 +319,17 @@ void RewardsPageHandler::DismissSelfCustodyInvite( std::move(callback).Run(); } -void RewardsPageHandler::GetPublisherForActiveTab( - GetPublisherForActiveTabCallback callback) { +void RewardsPageHandler::GetPublisherIdForActiveTab( + GetPublisherIdForActiveTabCallback callback) { if (!bubble_delegate_) { - std::move(callback).Run(nullptr); + std::move(callback).Run(""); return; } + std::move(callback).Run(bubble_delegate_->GetPublisherIdForActiveTab()); +} - std::string publisher_id = bubble_delegate_->GetPublisherIdForActiveTab(); +void RewardsPageHandler::GetPublisherInfo(const std::string& publisher_id, + GetPublisherInfoCallback callback) { if (publisher_id.empty()) { std::move(callback).Run(nullptr); return; @@ -347,14 +350,9 @@ void RewardsPageHandler::GetPublisherForActiveTab( base::BindOnce(get_publisher_callback, std::move(callback))); } -void RewardsPageHandler::GetPublisherBannerForActiveTab( - GetPublisherBannerForActiveTabCallback callback) { - if (!bubble_delegate_) { - std::move(callback).Run(nullptr); - return; - } - - std::string publisher_id = bubble_delegate_->GetPublisherIdForActiveTab(); +void RewardsPageHandler::GetPublisherBanner( + const std::string& publisher_id, + GetPublisherBannerCallback callback) { if (publisher_id.empty()) { std::move(callback).Run(nullptr); return; diff --git a/browser/ui/webui/brave_rewards/rewards_page_handler.h b/browser/ui/webui/brave_rewards/rewards_page_handler.h index a8c4186ff6dd..6ae583653107 100644 --- a/browser/ui/webui/brave_rewards/rewards_page_handler.h +++ b/browser/ui/webui/brave_rewards/rewards_page_handler.h @@ -76,10 +76,12 @@ class RewardsPageHandler : public mojom::RewardsPageHandler { GetSelfCustodyInviteDismissedCallback callback) override; void DismissSelfCustodyInvite( DismissSelfCustodyInviteCallback callback) override; - void GetPublisherForActiveTab( - GetPublisherForActiveTabCallback callback) override; - void GetPublisherBannerForActiveTab( - GetPublisherBannerForActiveTabCallback callback) override; + void GetPublisherIdForActiveTab( + GetPublisherIdForActiveTabCallback callback) override; + void GetPublisherInfo(const std::string& publisher_id, + GetPublisherInfoCallback callback) override; + void GetPublisherBanner(const std::string& publisher_id, + GetPublisherBannerCallback callback) override; void GetRecurringContributions( GetRecurringContributionsCallback callback) override; void RemoveRecurringContribution( diff --git a/components/brave_rewards/common/mojom/rewards_page.mojom b/components/brave_rewards/common/mojom/rewards_page.mojom index ca7c1c7e0c6e..a679496dcbaa 100644 --- a/components/brave_rewards/common/mojom/rewards_page.mojom +++ b/components/brave_rewards/common/mojom/rewards_page.mojom @@ -124,11 +124,15 @@ interface RewardsPageHandler { // Called when the user dismisses the self-custody invite. DismissSelfCustodyInvite() => (); - // Returns data about the publisher associated with the active tab. - GetPublisherForActiveTab() => (PublisherInfo? publisher_info); + // Returns the publisher ID associated with the active tab. + GetPublisherIdForActiveTab() => (string publisher_id); - // Returns banner data for the publisher associated with the active tab. - GetPublisherBannerForActiveTab() => (PublisherBanner? publisher_banner); + // Returns data about the specified publisher. + GetPublisherInfo(string publisher_id) => (PublisherInfo? publisher_info); + + // Returns banner data for the specified publisher. + GetPublisherBanner(string publisher_id) + => (PublisherBanner? publisher_banner); // Returns the recurring contributions set up for the current user. GetRecurringContributions() => (array contributions); diff --git a/components/brave_rewards/resources/rewards_page/webui/webui_model.ts b/components/brave_rewards/resources/rewards_page/webui/webui_model.ts index 78be74e852c8..aee07da0c14c 100644 --- a/components/brave_rewards/resources/rewards_page/webui/webui_model.ts +++ b/components/brave_rewards/resources/rewards_page/webui/webui_model.ts @@ -56,6 +56,7 @@ export function createModel(): AppModel { const stateManager = createStateManager(defaultState()) const isBubble = loadTimeData.getBoolean('isBubble') const platform = normalizePlatform(loadTimeData.getString('platform')) + const creatorParam = new URLSearchParams(location.search).get('creator') ?? '' // Expose the state manager for devtools diagnostic purposes. Object.assign(self, { @@ -192,9 +193,14 @@ export function createModel(): AppModel { } async function updateCurrentCreator() { + let id = creatorParam + if (!id) { + id = (await pageHandler.getPublisherIdForActiveTab()).publisherId + } + const [{ publisherInfo }, { publisherBanner }] = await Promise.all([ - pageHandler.getPublisherForActiveTab(), - pageHandler.getPublisherBannerForActiveTab() + pageHandler.getPublisherInfo(id), + pageHandler.getPublisherBanner(id) ]) if (!publisherInfo) {