From 12b09a13266d86487382597b5a47181656b590f9 Mon Sep 17 00:00:00 2001 From: NejcZdovc Date: Fri, 12 Apr 2019 18:51:07 +0200 Subject: [PATCH] Adds personaId, userId and bootStamp to rewards internal page Resolves https://github.com/brave/brave-browser/issues/3624 --- .../ui/webui/brave_rewards_internals_ui.cc | 3 +++ browser/ui/webui/brave_webui_source.cc | 3 +++ .../browser/rewards_internals_info.h | 3 +++ .../browser/rewards_service_impl.cc | 4 ++++ .../resources/ui/internals/components/app.tsx | 19 ++++++++++++++----- .../resources/ui/internals/storage.ts | 5 ++++- components/definitions/rewardsInternals.d.ts | 9 ++++++--- .../resources/brave_components_strings.grd | 3 +++ .../bat/ledger/rewards_internals_info.h | 3 +++ .../src/bat/ledger/internal/bat_helper.cc | 9 +++++++++ .../src/bat/ledger/internal/ledger_impl.cc | 9 +++++++++ .../src/bat/ledger/ledger.cc | 4 ++++ 12 files changed, 65 insertions(+), 9 deletions(-) diff --git a/browser/ui/webui/brave_rewards_internals_ui.cc b/browser/ui/webui/brave_rewards_internals_ui.cc index 8cb482b0a018..54eb61163f10 100644 --- a/browser/ui/webui/brave_rewards_internals_ui.cc +++ b/browser/ui/webui/brave_rewards_internals_ui.cc @@ -133,6 +133,9 @@ void RewardsInternalsDOMHandler::OnGetRewardsInternalsInfo( current_reconciles->Append(std::move(reconcile_info)); } info_dict.SetList("currentReconciles", std::move(current_reconciles)); + info_dict.SetString("personaId", info->persona_id); + info_dict.SetString("userId", info->user_id); + info_dict.SetInteger("bootStamp", info->boot_stamp); } web_ui()->CallJavascriptFunctionUnsafe( "brave_rewards_internals.onGetRewardsInternalsInfo", info_dict); diff --git a/browser/ui/webui/brave_webui_source.cc b/browser/ui/webui/brave_webui_source.cc index 64ca5caee44d..4160d2abc6e4 100644 --- a/browser/ui/webui/brave_webui_source.cc +++ b/browser/ui/webui/brave_webui_source.cc @@ -569,9 +569,11 @@ void CustomizeWebUIHTMLSource(const std::string &name, }, { std::string("rewards-internals"), { { "amount", IDS_BRAVE_REWARDS_INTERNALS_AMOUNT }, + { "bootStamp", IDS_BRAVE_REWARDS_INTERNALS_BOOT_STAMP }, { "currentReconcile", IDS_BRAVE_REWARDS_INTERNALS_CURRENT_RECONCILE }, { "invalid", IDS_BRAVE_REWARDS_INTERNALS_INVALID }, { "keyInfoSeed", IDS_BRAVE_REWARDS_INTERNALS_KEY_INFO_SEED }, + { "personaId", IDS_BRAVE_REWARDS_INTERNALS_PERSONA_ID }, { "refreshButton", IDS_BRAVE_REWARDS_INTERNALS_REFRESH_BUTTON }, { "retryLevel", IDS_BRAVE_REWARDS_INTERNALS_RETRY_LEVEL }, { "retryStep", IDS_BRAVE_REWARDS_INTERNALS_RETRY_STEP }, @@ -587,6 +589,7 @@ void CustomizeWebUIHTMLSource(const std::string &name, { "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 + { "userId", IDS_BRAVE_REWARDS_INTERNALS_USER_ID }, { "valid", IDS_BRAVE_REWARDS_INTERNALS_VALID }, { "viewingId", IDS_BRAVE_REWARDS_INTERNALS_VIEWING_ID }, { "walletPaymentId", IDS_BRAVE_REWARDS_INTERNALS_WALLET_PAYMENT_ID }, diff --git a/components/brave_rewards/browser/rewards_internals_info.h b/components/brave_rewards/browser/rewards_internals_info.h index 9513f630e053..f00ee26eaf07 100644 --- a/components/brave_rewards/browser/rewards_internals_info.h +++ b/components/brave_rewards/browser/rewards_internals_info.h @@ -20,6 +20,9 @@ struct RewardsInternalsInfo { std::string payment_id; bool is_key_info_seed_valid; + std::string persona_id; + std::string user_id; + uint64_t boot_stamp; std::map current_reconciles; }; diff --git a/components/brave_rewards/browser/rewards_service_impl.cc b/components/brave_rewards/browser/rewards_service_impl.cc index 8d91fe965c05..d8a06723d842 100644 --- a/components/brave_rewards/browser/rewards_service_impl.cc +++ b/components/brave_rewards/browser/rewards_service_impl.cc @@ -843,6 +843,10 @@ void RewardsServiceImpl::OnGetRewardsInternalsInfo( std::make_unique(); rewards_internals_info->payment_id = info.payment_id; rewards_internals_info->is_key_info_seed_valid = info.is_key_info_seed_valid; + rewards_internals_info->persona_id = info.persona_id; + rewards_internals_info->user_id = info.user_id; + rewards_internals_info->boot_stamp = info.boot_stamp; + for (const auto& item : info.current_reconciles) { ReconcileInfo reconcile_info; reconcile_info.viewing_id_ = item.second.viewingId_; diff --git a/components/brave_rewards/resources/ui/internals/components/app.tsx b/components/brave_rewards/resources/ui/internals/components/app.tsx index 46a0f7c1c66a..2aa267ecf44d 100644 --- a/components/brave_rewards/resources/ui/internals/components/app.tsx +++ b/components/brave_rewards/resources/ui/internals/components/app.tsx @@ -30,13 +30,13 @@ export class RewardsInternalsPage extends React.Component { } render () { - const { rewardsInternalsData } = this.props - if (rewardsInternalsData.isRewardsEnabled) { + const { isRewardsEnabled, info } = this.props.rewardsInternalsData + if (isRewardsEnabled) { return (
- - - {rewardsInternalsData.info.currentReconciles.map((item, index) => ( + + + {info.currentReconciles.map((item, index) => (
@@ -45,6 +45,15 @@ export class RewardsInternalsPage extends React.Component {
))} +
+ : {info.personaId} +
+
+ : {info.userId} +
+
+ : {new Date(info.bootStamp * 1000).toLocaleDateString()} +
) } else { diff --git a/components/brave_rewards/resources/ui/internals/storage.ts b/components/brave_rewards/resources/ui/internals/storage.ts index f6a3b44252d2..bae707d663e5 100644 --- a/components/brave_rewards/resources/ui/internals/storage.ts +++ b/components/brave_rewards/resources/ui/internals/storage.ts @@ -11,7 +11,10 @@ const defaultState: RewardsInternals.State = { info: { isKeyInfoSeedValid: false, walletPaymentId: '', - currentReconciles: [] + currentReconciles: [], + personaId: '', + userId: '', + bootStamp: 0 } } diff --git a/components/definitions/rewardsInternals.d.ts b/components/definitions/rewardsInternals.d.ts index 16f5f14207d3..e955b9fc8a97 100644 --- a/components/definitions/rewardsInternals.d.ts +++ b/components/definitions/rewardsInternals.d.ts @@ -4,11 +4,14 @@ declare namespace RewardsInternals { } export interface State { - isRewardsEnabled: boolean, + isRewardsEnabled: boolean info: { - isKeyInfoSeedValid: boolean, - walletPaymentId: string, + isKeyInfoSeedValid: boolean + walletPaymentId: string currentReconciles: CurrentReconcile[] + personaId: string + userId: string + bootStamp: number } } diff --git a/components/resources/brave_components_strings.grd b/components/resources/brave_components_strings.grd index 44d5268706b2..4ac0f60325b4 100644 --- a/components/resources/brave_components_strings.grd +++ b/components/resources/brave_components_strings.grd @@ -283,6 +283,9 @@ Valid Viewing ID: Wallet Payment ID: + Persona ID + User ID + Wallet created about diff --git a/vendor/bat-native-ledger/include/bat/ledger/rewards_internals_info.h b/vendor/bat-native-ledger/include/bat/ledger/rewards_internals_info.h index aa132931c4a3..edb3d0db7414 100644 --- a/vendor/bat-native-ledger/include/bat/ledger/rewards_internals_info.h +++ b/vendor/bat-native-ledger/include/bat/ledger/rewards_internals_info.h @@ -23,6 +23,9 @@ LEDGER_EXPORT struct RewardsInternalsInfo { std::string payment_id; bool is_key_info_seed_valid; + std::string persona_id; + std::string user_id; + uint64_t boot_stamp; std::map current_reconciles; }; diff --git a/vendor/bat-native-ledger/src/bat/ledger/internal/bat_helper.cc b/vendor/bat-native-ledger/src/bat/ledger/internal/bat_helper.cc index 94991bb5acf0..66cfbbe6ae0a 100644 --- a/vendor/bat-native-ledger/src/bat/ledger/internal/bat_helper.cc +++ b/vendor/bat-native-ledger/src/bat/ledger/internal/bat_helper.cc @@ -3093,6 +3093,15 @@ void saveToJson(JsonWriter* writer, const ledger::RewardsInternalsInfo& info) { saveToJson(writer, reconcile.second); writer->EndArray(); + writer->String("persona_id"); + writer->String(info.persona_id.c_str()); + + writer->String("user_id"); + writer->String(info.user_id.c_str()); + + writer->String("boot_stamp"); + writer->Uint64(info.boot_stamp); + writer->EndObject(); } diff --git a/vendor/bat-native-ledger/src/bat/ledger/internal/ledger_impl.cc b/vendor/bat-native-ledger/src/bat/ledger/internal/ledger_impl.cc index 6eed557b097b..36bcc807d589 100644 --- a/vendor/bat-native-ledger/src/bat/ledger/internal/ledger_impl.cc +++ b/vendor/bat-native-ledger/src/bat/ledger/internal/ledger_impl.cc @@ -1206,6 +1206,15 @@ void LedgerImpl::GetRewardsInternalsInfo(ledger::RewardsInternalsInfo* info) { // Retrieve the payment id. info->payment_id = bat_state_->GetPaymentId(); + // Retrieve the persona id. + info->persona_id = bat_state_->GetPersonaId(); + + // Retrieve the user id. + info->user_id = bat_state_->GetUserId(); + + // Retrieve the boot stamp. + info->boot_stamp = bat_state_->GetBootStamp(); + // Retrieve the key info seed and validate it. const braveledger_bat_helper::WALLET_INFO_ST wallet_info = bat_state_->GetWalletInfo(); diff --git a/vendor/bat-native-ledger/src/bat/ledger/ledger.cc b/vendor/bat-native-ledger/src/bat/ledger/ledger.cc index eb117dc66e40..044420a4680b 100644 --- a/vendor/bat-native-ledger/src/bat/ledger/ledger.cc +++ b/vendor/bat-native-ledger/src/bat/ledger/ledger.cc @@ -705,6 +705,10 @@ bool RewardsInternalsInfo::loadFromJson(const std::string& json) { current_reconciles.insert( std::make_pair(reconcile_info.viewingId_, reconcile_info)); } + + persona_id = d["persona_id"].GetString(); + user_id = d["user_id"].GetString(); + boot_stamp = d["boot_stamp"].GetUint64(); } return !error;