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

Add contributions back into brave://rewards-internals page #5739

Merged
merged 1 commit into from
Jun 5, 2020
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
66 changes: 56 additions & 10 deletions browser/ui/webui/brave_rewards_internals_ui.cc
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ class RewardsInternalsDOMHandler : public content::WebUIMessageHandler {
void OnGetBalance(
int32_t result,
std::unique_ptr<brave_rewards::Balance> balance);
void GetContributions(const base::ListValue* args);
void OnGetContributions(
const std::vector<brave_rewards::ContributionInfo>& list);
void GetPromotions(const base::ListValue* args);
void OnGetPromotions(const std::vector<brave_rewards::Promotion>& list);
void GetPartialLog(const base::ListValue* args);
Expand Down Expand Up @@ -89,6 +92,11 @@ void RewardsInternalsDOMHandler::RegisterMessages() {
base::BindRepeating(
&RewardsInternalsDOMHandler::GetBalance,
base::Unretained(this)));
web_ui()->RegisterMessageCallback(
"brave_rewards_internals.getContributions",
base::BindRepeating(
&RewardsInternalsDOMHandler::GetContributions,
base::Unretained(this)));
web_ui()->RegisterMessageCallback(
"brave_rewards_internals.getPromotions",
base::BindRepeating(
Expand Down Expand Up @@ -162,16 +170,6 @@ void RewardsInternalsDOMHandler::OnGetRewardsInternalsInfo(
if (info) {
info_dict.SetString("walletPaymentId", info->payment_id);
info_dict.SetBoolean("isKeyInfoSeedValid", info->is_key_info_seed_valid);
auto current_reconciles = std::make_unique<base::ListValue>();
for (const auto& item : info->current_reconciles) {
auto reconcile_info = std::make_unique<base::DictionaryValue>();
reconcile_info->SetString("viewingId", item.second.viewing_id_);
reconcile_info->SetString("amount", item.second.amount_);
reconcile_info->SetInteger("retryStep", item.second.retry_step_);
reconcile_info->SetInteger("retryLevel", item.second.retry_level_);
current_reconciles->Append(std::move(reconcile_info));
}
info_dict.SetList("currentReconciles", std::move(current_reconciles));
info_dict.SetInteger("bootStamp", info->boot_stamp);
}
web_ui()->CallJavascriptFunctionUnsafe(
Expand Down Expand Up @@ -211,6 +209,54 @@ void RewardsInternalsDOMHandler::OnGetBalance(
std::move(balance_value));
}

void RewardsInternalsDOMHandler::GetContributions(const base::ListValue *args) {
if (!rewards_service_) {
return;
}

rewards_service_->GetAllContributions(base::BindOnce(
&RewardsInternalsDOMHandler::OnGetContributions,
weak_ptr_factory_.GetWeakPtr()));
}

void RewardsInternalsDOMHandler::OnGetContributions(
const std::vector<brave_rewards::ContributionInfo>& list) {
if (!web_ui()->CanCallJavascript()) {
return;
}

base::Value contributions(base::Value::Type::LIST);
for (const auto & item : list) {
base::Value contribution(base::Value::Type::DICTIONARY);
contribution.SetStringKey("id", item.contribution_id);
contribution.SetDoubleKey("amount", item.amount);
contribution.SetIntKey("type", item.type);
contribution.SetIntKey("step", item.step);
contribution.SetIntKey("retryCount", item.retry_count);
contribution.SetIntKey("createdAt", item.created_at);
contribution.SetIntKey("processor", item.processor);
base::Value publishers(base::Value::Type::LIST);
for (const auto& publisher_item : item.publishers) {
base::Value publisher(base::Value::Type::DICTIONARY);
publisher.SetStringKey(
"contributionId",
publisher_item.contribution_id);
publisher.SetStringKey("publisherKey", publisher_item.publisher_key);
publisher.SetDoubleKey("totalAmount", publisher_item.total_amount);
publisher.SetDoubleKey(
"contributedAmount",
publisher_item.contributed_amount);
publishers.Append(std::move(publisher));
}
contribution.SetPath("publishers", std::move(publishers));
contributions.Append(std::move(contribution));
}

web_ui()->CallJavascriptFunctionUnsafe(
"brave_rewards_internals.contributions",
std::move(contributions));
}

void RewardsInternalsDOMHandler::GetPromotions(const base::ListValue *args) {
if (!rewards_service_) {
return;
Expand Down
41 changes: 23 additions & 18 deletions browser/ui/webui/brave_webui_source.cc
Original file line number Diff line number Diff line change
Expand Up @@ -834,8 +834,26 @@ void CustomizeWebUIHTMLSource(const std::string &name,
{ "bat", IDS_BRAVE_UI_BAT_TEXT },
{ "bootStamp", IDS_BRAVE_REWARDS_INTERNALS_BOOT_STAMP },
{ "clearButton", IDS_BRAVE_REWARDS_INTERNALS_CLEAR_BUTTON },
{ "contributionsInProgress", IDS_BRAVE_REWARDS_INTERNALS_CONTRIBUTIONS_IN_PROGRESS }, // NOLINT
{ "currentReconcile", IDS_BRAVE_REWARDS_INTERNALS_CURRENT_RECONCILE },
{ "contributedAmount", IDS_BRAVE_REWARDS_INTERNALS_CONTRIBUTED_AMOUNT },
{ "contribution", IDS_BRAVE_REWARDS_INTERNALS_CONTRIBUTION },
{ "contributionProcessor", IDS_BRAVE_REWARDS_INTERNALS_CONTRIBUTION_PROCESSOR }, // NOLINT
{ "contributionStep", IDS_BRAVE_REWARDS_INTERNALS_CONTRIBUTION_STEP },
{ "contributionStepAutoContributeTableEmpty", IDS_BRAVE_REWARDS_INTERNALS_CONTRIBUTION_STEP_AUTO_CONTRIBUTE_TABLE_EMPTY }, // NOLINT
{ "contributionStepNotEnoughFunds", IDS_BRAVE_REWARDS_INTERNALS_CONTRIBUTION_STEP_NOT_ENOUGH_FUNDS }, // NOLINT
{ "contributionStepFailed", IDS_BRAVE_REWARDS_INTERNALS_CONTRIBUTION_STEP_FAILED }, // NOLINT
{ "contributionStepCompleted", IDS_BRAVE_REWARDS_INTERNALS_CONTRIBUTION_STEP_COMPLETED },// NOLINT
{ "contributionStepNo", IDS_BRAVE_REWARDS_INTERNALS_CONTRIBUTION_STEP_NO }, // NOLINT
{ "contributionStepStart", IDS_BRAVE_REWARDS_INTERNALS_CONTRIBUTION_STEP_START }, // NOLINT
{ "contributionStepPrepare", IDS_BRAVE_REWARDS_INTERNALS_CONTRIBUTION_STEP_PREPARE }, // NOLINT
{ "contributionStepReserve", IDS_BRAVE_REWARDS_INTERNALS_CONTRIBUTION_STEP_RESERVE }, // NOLINT
{ "contributionStepExternalTransaction", IDS_BRAVE_REWARDS_INTERNALS_CONTRIBUTION_STEP_EXTERNAL_TRANSACTION }, // NOLINT
{ "contributionStepCreds", IDS_BRAVE_REWARDS_INTERNALS_CONTRIBUTION_STEP_CREDS }, // NOLINT
{ "rewardsNotEnabled", IDS_BRAVE_REWARDS_INTERNALS_REWARDS_NOT_ENABLED }, // NOLINT
{ "rewardsTypeAuto", IDS_BRAVE_REWARDS_INTERNALS_REWARDS_TYPE_AUTO }, // NOLINT
{ "rewardsTypeOneTimeTip", IDS_BRAVE_REWARDS_INTERNALS_REWARDS_TYPE_ONE_TIME_TIP }, // NOLINT
{ "rewardsTypeRecurringTip", IDS_BRAVE_REWARDS_INTERNALS_REWARDS_TYPE_RECURRING_TIP }, // NOLINT
{ "contributionType", IDS_BRAVE_REWARDS_INTERNALS_CONTRIBUTION_TYPE },
{ "contributions", IDS_BRAVE_REWARDS_INTERNALS_CONTRIBUTIONS },
{ "downloadButton", IDS_BRAVE_REWARDS_INTERNALS_DOWNLOAD_BUTTON },
{ "invalid", IDS_BRAVE_REWARDS_INTERNALS_INVALID },
{ "keyInfoSeed", IDS_BRAVE_REWARDS_INTERNALS_KEY_INFO_SEED },
Expand All @@ -847,7 +865,7 @@ void CustomizeWebUIHTMLSource(const std::string &name,
{ "processorBraveUserFunds", IDS_BRAVE_UI_PROCESSOR_BRAVE_USER_FUNDS },
{ "promotionAds", IDS_BRAVE_REWARDS_INTERNALS_PROMOTION_ADS },
{ "promotionAmount", IDS_BRAVE_REWARDS_INTERNALS_PROMOTION_AMOUNT },
{ "promotionClaimedAt", IDS_BRAVE_REWARDS_INTERNALS_PROMOTION_CLAIMED_AT }, // NOLINT
{ "promotionClaimedAt", IDS_BRAVE_REWARDS_INTERNALS_PROMOTION_CLAIMED_AT }, // NOLINT
{ "promotionClaimId", IDS_BRAVE_REWARDS_INTERNALS_PROMOTION_CLAIM_ID },
{ "promotionExpiresAt", IDS_BRAVE_REWARDS_INTERNALS_PROMOTION_EXPIRES_AT }, // NOLINT
{ "promotionId", IDS_BRAVE_REWARDS_INTERNALS_PROMOTION_ID },
Expand All @@ -864,28 +882,15 @@ void CustomizeWebUIHTMLSource(const std::string &name,
{ "promotionUGP", IDS_BRAVE_REWARDS_INTERNALS_PROMOTION_UGP },
{ "promotionVersion", IDS_BRAVE_REWARDS_INTERNALS_PROMOTION_VERSION },
{ "refreshButton", IDS_BRAVE_REWARDS_INTERNALS_REFRESH_BUTTON },
{ "retryLevel", IDS_BRAVE_REWARDS_INTERNALS_RETRY_LEVEL },
{ "retryStep", IDS_BRAVE_REWARDS_INTERNALS_RETRY_STEP },
{ "retryStepCurrent", IDS_BRAVE_REWARDS_INTERNALS_RETRY_STEP_CURRENT },
{ "retryStepFinal", IDS_BRAVE_REWARDS_INTERNALS_RETRY_STEP_FINAL },
{ "retryStepPayload", IDS_BRAVE_REWARDS_INTERNALS_RETRY_STEP_PAYLOAD },
{ "retryStepPrepare", IDS_BRAVE_REWARDS_INTERNALS_RETRY_STEP_PREPARE },
{ "retryStepProof", IDS_BRAVE_REWARDS_INTERNALS_RETRY_STEP_PROOF },
{ "retryStepReconcile", IDS_BRAVE_REWARDS_INTERNALS_RETRY_STEP_RECONCILE }, // NOLINT
{ "retryStepRegister", IDS_BRAVE_REWARDS_INTERNALS_RETRY_STEP_REGISTER }, // NOLINT
{ "retryStepUnknown", IDS_BRAVE_REWARDS_INTERNALS_RETRY_STEP_UNKNOWN },
{ "retryStepViewing", IDS_BRAVE_REWARDS_INTERNALS_RETRY_STEP_VIEWING },
{ "retryStepVote", IDS_BRAVE_REWARDS_INTERNALS_RETRY_STEP_VOTE },
{ "retryStepWinners", IDS_BRAVE_REWARDS_INTERNALS_RETRY_STEP_WINNERS },
{ "rewardsNotEnabled", IDS_BRAVE_REWARDS_INTERNALS_REWARDS_NOT_ENABLED }, // NOLINT
{ "retryCount", IDS_BRAVE_REWARDS_INTERNALS_RETRY_COUNT },
{ "tabGeneralInfo", IDS_BRAVE_REWARDS_INTERNALS_TAB_GENERAL_INFO },
{ "tabLogs", IDS_BRAVE_REWARDS_INTERNALS_TAB_LOGS },
{ "tabPromotions", IDS_BRAVE_REWARDS_INTERNALS_TAB_PROMOTIONS },
{ "tabContributions", IDS_BRAVE_REWARDS_INTERNALS_TAB_CONTRIBUTIONS },
{ "totalAmount", IDS_BRAVE_REWARDS_INTERNALS_TOTAL_AMOUNT },
{ "totalBalance", IDS_BRAVE_REWARDS_INTERNALS_TOTAL_BALANCE },
{ "userId", IDS_BRAVE_REWARDS_INTERNALS_USER_ID },
{ "valid", IDS_BRAVE_REWARDS_INTERNALS_VALID },
{ "viewingId", IDS_BRAVE_REWARDS_INTERNALS_VIEWING_ID },
{ "walletInfo", IDS_BRAVE_REWARDS_INTERNALS_WALLET_INFO },
{ "walletPaymentId", IDS_BRAVE_REWARDS_INTERNALS_WALLET_PAYMENT_ID },
}
Expand Down
3 changes: 3 additions & 0 deletions components/brave_ads/browser/ads_service_impl_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,9 @@ class MockRewardsService : public RewardsService {
MOCK_METHOD1(GetAllMonthlyReportIds, void(
brave_rewards::GetAllMonthlyReportIdsCallback callback));

MOCK_METHOD1(GetAllContributions, void(
brave_rewards::GetAllContributionsCallback callback));

MOCK_METHOD1(GetAllPromotions, void(
brave_rewards::GetAllPromotionsCallback callback));

Expand Down
6 changes: 4 additions & 2 deletions components/brave_rewards/browser/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ source_set("browser") {
"rewards_notification_service_observer.h",
"content_site.cc",
"content_site.h",
"contribution_info.cc",
"contribution_info.h",
"contribution_publisher.cc",
"contribution_publisher.h",
"rewards_p3a.cc",
"rewards_p3a.h",
"rewards_parameters.cc",
Expand All @@ -38,8 +42,6 @@ source_set("browser") {
"pending_contribution.h",
"publisher_banner.cc",
"publisher_banner.h",
"reconcile_info.cc",
"reconcile_info.h",
"rewards_internals_info.cc",
"rewards_internals_info.h",
"balance.cc",
Expand Down
16 changes: 16 additions & 0 deletions components/brave_rewards/browser/contribution_info.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/* Copyright (c) 2020 The Brave Authors. All rights reserved.
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */

#include "brave/components/brave_rewards/browser/contribution_info.h"

namespace brave_rewards {

ContributionInfo::ContributionInfo() = default;

ContributionInfo::~ContributionInfo() = default;

ContributionInfo::ContributionInfo(const ContributionInfo& info) = default;

} // namespace brave_rewards
34 changes: 34 additions & 0 deletions components/brave_rewards/browser/contribution_info.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/* Copyright (c) 2020 The Brave Authors. All rights reserved.
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */

#ifndef BRAVE_COMPONENTS_BRAVE_REWARDS_BROWSER_CONTRIBUTION_INFO_H_
#define BRAVE_COMPONENTS_BRAVE_REWARDS_BROWSER_CONTRIBUTION_INFO_H_

#include <string>
#include <vector>

#include "brave/components/brave_rewards/browser/contribution_publisher.h"

namespace brave_rewards {

struct ContributionInfo {
ContributionInfo();
~ContributionInfo();
ContributionInfo(const ContributionInfo& info);

std::string contribution_id;
double amount;
int type;
int step;
int retry_count;
uint64_t created_at;
int processor;

std::vector<ContributionPublisher> publishers;
};

} // namespace brave_rewards

#endif // BRAVE_COMPONENTS_BRAVE_REWARDS_BROWSER_CONTRIBUTION_INFO_H_
17 changes: 17 additions & 0 deletions components/brave_rewards/browser/contribution_publisher.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/* Copyright (c) 2020 The Brave Authors. All rights reserved.
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */

#include "brave/components/brave_rewards/browser/contribution_publisher.h"

namespace brave_rewards {

ContributionPublisher::ContributionPublisher() = default;

ContributionPublisher::~ContributionPublisher() = default;

ContributionPublisher::ContributionPublisher(
zenparsing marked this conversation as resolved.
Show resolved Hide resolved
const ContributionPublisher& info) = default;

} // namespace brave_rewards
26 changes: 26 additions & 0 deletions components/brave_rewards/browser/contribution_publisher.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/* Copyright (c) 2020 The Brave Authors. All rights reserved.
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */

#ifndef BRAVE_COMPONENTS_BRAVE_REWARDS_BROWSER_CONTRIBUTION_PUBLISHER_H_
#define BRAVE_COMPONENTS_BRAVE_REWARDS_BROWSER_CONTRIBUTION_PUBLISHER_H_

#include <string>

namespace brave_rewards {

struct ContributionPublisher {
ContributionPublisher();
~ContributionPublisher();
ContributionPublisher(const ContributionPublisher& info);

std::string contribution_id;
std::string publisher_key;
double total_amount;
double contributed_amount;
};

} // namespace brave_rewards

#endif // BRAVE_COMPONENTS_BRAVE_REWARDS_BROWSER_CONTRIBUTION_PUBLISHER_H_
22 changes: 0 additions & 22 deletions components/brave_rewards/browser/reconcile_info.cc

This file was deleted.

41 changes: 0 additions & 41 deletions components/brave_rewards/browser/reconcile_info.h

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ RewardsInternalsInfo::RewardsInternalsInfo() {}

RewardsInternalsInfo::RewardsInternalsInfo(const RewardsInternalsInfo& info)
: payment_id(info.payment_id),
is_key_info_seed_valid(info.is_key_info_seed_valid),
current_reconciles(info.current_reconciles) {
is_key_info_seed_valid(info.is_key_info_seed_valid) {
}

RewardsInternalsInfo::~RewardsInternalsInfo() {}
Expand Down
4 changes: 0 additions & 4 deletions components/brave_rewards/browser/rewards_internals_info.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
#include <map>
#include <string>

#include "brave/components/brave_rewards/browser/reconcile_info.h"

namespace brave_rewards {

struct RewardsInternalsInfo {
Expand All @@ -21,8 +19,6 @@ struct RewardsInternalsInfo {
std::string payment_id;
bool is_key_info_seed_valid;
uint64_t boot_stamp;

std::map<std::string, ReconcileInfo> current_reconciles;
};

} // namespace brave_rewards
Expand Down
Loading