Skip to content

Commit

Permalink
Adds personaId, userId and bootStamp to rewards internal page
Browse files Browse the repository at this point in the history
  • Loading branch information
NejcZdovc committed Apr 12, 2019
1 parent be5b137 commit 12b09a1
Show file tree
Hide file tree
Showing 12 changed files with 65 additions and 9 deletions.
3 changes: 3 additions & 0 deletions browser/ui/webui/brave_rewards_internals_ui.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
3 changes: 3 additions & 0 deletions browser/ui/webui/brave_webui_source.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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 },
Expand All @@ -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 },
Expand Down
3 changes: 3 additions & 0 deletions components/brave_rewards/browser/rewards_internals_info.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::string, ReconcileInfo> current_reconciles;
};
Expand Down
4 changes: 4 additions & 0 deletions components/brave_rewards/browser/rewards_service_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -843,6 +843,10 @@ void RewardsServiceImpl::OnGetRewardsInternalsInfo(
std::make_unique<brave_rewards::RewardsInternalsInfo>();
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_;
Expand Down
19 changes: 14 additions & 5 deletions components/brave_rewards/resources/ui/internals/components/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@ export class RewardsInternalsPage extends React.Component<Props, {}> {
}

render () {
const { rewardsInternalsData } = this.props
if (rewardsInternalsData.isRewardsEnabled) {
const { isRewardsEnabled, info } = this.props.rewardsInternalsData
if (isRewardsEnabled) {
return (
<div id='rewardsInternalsPage'>
<KeyInfoSeed isKeyInfoSeedValid={rewardsInternalsData.info.isKeyInfoSeedValid || false} />
<WalletPaymentId walletPaymentId={rewardsInternalsData.info.walletPaymentId || ''} />
{rewardsInternalsData.info.currentReconciles.map((item, index) => (
<KeyInfoSeed isKeyInfoSeedValid={info.isKeyInfoSeedValid || false} />
<WalletPaymentId walletPaymentId={info.walletPaymentId || ''} />
{info.currentReconciles.map((item, index) => (
<span>
<hr/>
<div>
Expand All @@ -45,6 +45,15 @@ export class RewardsInternalsPage extends React.Component<Props, {}> {
</div>
</span>
))}
<div>
<span i18n-content='personaId'/>: {info.personaId}
</div>
<div>
<span i18n-content='userId'/>: {info.userId}
</div>
<div>
<span i18n-content='bootStamp'/>: {new Date(info.bootStamp * 1000).toLocaleDateString()}
</div>
<button type='button' style={{ marginTop: '10px' }} onClick={this.onRefresh}>{getLocale('refreshButton')}</button>
</div>)
} else {
Expand Down
5 changes: 4 additions & 1 deletion components/brave_rewards/resources/ui/internals/storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ const defaultState: RewardsInternals.State = {
info: {
isKeyInfoSeedValid: false,
walletPaymentId: '',
currentReconciles: []
currentReconciles: [],
personaId: '',
userId: '',
bootStamp: 0
}
}

Expand Down
9 changes: 6 additions & 3 deletions components/definitions/rewardsInternals.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}

Expand Down
3 changes: 3 additions & 0 deletions components/resources/brave_components_strings.grd
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,9 @@
<message name="IDS_BRAVE_REWARDS_INTERNALS_VALID" desc="Valid indicator">Valid</message>
<message name="IDS_BRAVE_REWARDS_INTERNALS_VIEWING_ID" desc="Viewing ID">Viewing ID:</message>
<message name="IDS_BRAVE_REWARDS_INTERNALS_WALLET_PAYMENT_ID" desc="Wallet payment ID">Wallet Payment ID:</message>
<message name="IDS_BRAVE_REWARDS_INTERNALS_PERSONA_ID" desc="Wallet persona ID">Persona ID</message>
<message name="IDS_BRAVE_REWARDS_INTERNALS_USER_ID" desc="Wallet user ID">User ID</message>
<message name="IDS_BRAVE_REWARDS_INTERNALS_BOOT_STAMP" desc="Wallet start time">Wallet created</message>

<!-- WebUI brave ui resources -->
<message name="IDS_BRAVE_UI_ABOUT" desc="">about</message>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::string, ReconcileInfo> current_reconciles;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
4 changes: 4 additions & 0 deletions vendor/bat-native-ledger/src/bat/ledger/ledger.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 12b09a1

Please sign in to comment.