Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Rewards 3.0] Add creator ID parameter to Rewards page #27001

Merged
merged 1 commit into from
Dec 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 10 additions & 12 deletions browser/ui/webui/brave_rewards/rewards_page_handler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down
10 changes: 6 additions & 4 deletions browser/ui/webui/brave_rewards/rewards_page_handler.h
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
12 changes: 8 additions & 4 deletions components/brave_rewards/common/mojom/rewards_page.mojom
Original file line number Diff line number Diff line change
Expand Up @@ -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<PublisherInfo> contributions);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ export function createModel(): AppModel {
const stateManager = createStateManager<AppState>(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, {
Expand Down Expand Up @@ -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) {
Expand Down
Loading