Skip to content

Commit

Permalink
Adds processor to transactions
Browse files Browse the repository at this point in the history
  • Loading branch information
NejcZdovc committed Apr 10, 2020
1 parent 4ec1c13 commit 9ec956c
Show file tree
Hide file tree
Showing 10 changed files with 63 additions and 4 deletions.
2 changes: 2 additions & 0 deletions browser/ui/webui/brave_rewards_page_ui.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1764,6 +1764,7 @@ void RewardsDOMHandler::OnGetMonthlyReport(
base::Value transaction_report(base::Value::Type::DICTIONARY);
transaction_report.SetDoubleKey("amount", item.amount);
transaction_report.SetIntKey("type", item.type);
transaction_report.SetIntKey("processor", item.processor);
transaction_report.SetIntKey("created_at", item.created_at);

transactions.Append(std::move(transaction_report));
Expand All @@ -1789,6 +1790,7 @@ void RewardsDOMHandler::OnGetMonthlyReport(
base::Value contribution_report(base::Value::Type::DICTIONARY);
contribution_report.SetDoubleKey("amount", item.amount);
contribution_report.SetIntKey("type", item.type);
contribution_report.SetIntKey("processor", item.processor);
contribution_report.SetIntKey("created_at", item.created_at);
contribution_report.SetKey("publishers", std::move(publishers));
contributions.Append(std::move(contribution_report));
Expand Down
4 changes: 4 additions & 0 deletions browser/ui/webui/brave_webui_source.cc
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,7 @@ void CustomizeWebUIHTMLSource(const std::string &name,
{ "allowTip", IDS_BRAVE_UI_ALLOW_TIP },
{ "amount", IDS_BRAVE_UI_AMOUNT },
{ "autoContribute", IDS_BRAVE_UI_BRAVE_CONTRIBUTE_TITLE },
{ "autoContributeTransaction", IDS_BRAVE_UI_BRAVE_CONTRIBUTE_TRANSACTION }, // NOLINT
{ "backup", IDS_BRAVE_UI_BACKUP },
{ "braveAdsDesc", IDS_BRAVE_UI_BRAVE_ADS_DESC },
{ "braveAdsDescPoints", IDS_BRAVE_UI_BRAVE_ADS_DESC_POINTS },
Expand Down Expand Up @@ -503,6 +504,9 @@ void CustomizeWebUIHTMLSource(const std::string &name,
{ "print", IDS_BRAVE_UI_PRINT },
{ "processingRequest", IDS_BRAVE_UI_PROCESSING_REQUEST },
{ "processingRequestButton", IDS_BRAVE_UI_PROCESSING_REQUEST_BUTTON },
{ "processorBraveTokens", IDS_BRAVE_UI_PROCESSOR_BRAVE_TOKENS },
{ "processorUphold", IDS_BRAVE_UI_PROCESSOR_UPHOLD },
{ "processorBraveUserFunds", IDS_BRAVE_UI_PROCESSOR_BRAVE_USER_FUNDS },
{ "readyToTakePart", IDS_BRAVE_UI_READY_TO_TAKE_PART },
{ "readyToTakePartOptInText", IDS_BRAVE_UI_READY_TO_TAKE_PART_OPT_IN_TEXT }, // NOLINT
{ "readyToTakePartStart", IDS_BRAVE_UI_READY_TO_TAKE_PART_START },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ struct ContributionReportInfo {

double amount;
uint32_t type;
uint32_t processor;
std::vector<ContentSite> publishers;
uint64_t created_at;
};
Expand Down
2 changes: 2 additions & 0 deletions components/brave_rewards/browser/rewards_service_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3325,6 +3325,7 @@ void ConvertLedgerToServiceTransactionReportList(
for (const auto& item : list) {
info.amount = item->amount;
info.type = static_cast<uint32_t>(item->type);
info.processor = static_cast<uint32_t>(item->processor);
info.created_at = item->created_at;

converted_list->push_back(info);
Expand All @@ -3340,6 +3341,7 @@ void ConvertLedgerToServiceContributionReportList(
for (auto& item : list) {
info.amount = item->amount;
info.type = static_cast<uint32_t>(item->type);
info.processor = static_cast<uint32_t>(item->processor);
info.created_at = item->created_at;
info.publishers = {};
for (auto& publisher : item->publishers) {
Expand Down
1 change: 1 addition & 0 deletions components/brave_rewards/browser/transaction_report_info.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ struct TransactionReportInfo {

double amount;
uint32_t type;
uint32_t processor;
uint64_t created_at;
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -602,9 +602,39 @@ class PageWallet extends React.Component<Props, State> {
return ''
}

getProcessorString = (processor: Rewards.Processor) => {
let text = ''
switch (processor) {
case 0: { // Rewards.Processor.NONE
text = ''
break
}
case 1: { // Rewards.Processor.BRAVE_TOKENS
text = getLocale('processorBraveTokens')
break
}
case 2: { // Rewards.Processor.UPHOLD
text = getLocale('processorUphold')
break
}
case 3: { // Rewards.Processor.BRAVE_USER_FUNDS
text = getLocale('processorBraveUserFunds')
break
}
}

if (text.length === 0) {
return ''
}

return `(${text})`
}

getContributionDescription = (contribution: Rewards.ContributionReport) => {
if (contribution.type === 1) { // Rewards.ReportType.AUTO_CONTRIBUTION
return getLocale('autoContribute')
return getLocale(
'autoContributeTransaction',
{ processor: this.getProcessorString(contribution.processor) })
}

return ''
Expand Down
9 changes: 9 additions & 0 deletions components/definitions/rewards.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,15 +104,24 @@ declare namespace Rewards {
TIP = 5
}

export enum Processor {
NONE = 0,
BRAVE_TOKENS = 1,
UPHOLD = 2,
BRAVE_USER_FUNDS = 3
}

export interface TransactionReport {
amount: number
type: ReportType
processor: Processor
created_at: number
}

export interface ContributionReport {
amount: number
type: ReportType
processor: Processor
created_at: number
publishers: Publisher[]
}
Expand Down
4 changes: 4 additions & 0 deletions components/resources/brave_components_strings.grd
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,7 @@
<message name="IDS_BRAVE_UI_BRAVE_ADS_TITLE" desc="">Ads</message>
<message name="IDS_BRAVE_UI_BRAVE_CONTRIBUTE_DESC" desc="">Support your favorite sites just by browsing – or tip a site any time you like.</message>
<message name="IDS_BRAVE_UI_BRAVE_CONTRIBUTE_TITLE" desc="">Auto-Contribute</message>
<message name="IDS_BRAVE_UI_BRAVE_CONTRIBUTE_TRANSACTION" desc="">Auto-Contribute {{processor}}</message>
<message name="IDS_BRAVE_UI_BRAVE_REWARDS" desc="">Brave Rewards</message>
<message name="IDS_BRAVE_UI_AND" desc="">and</message>
<message name="IDS_BRAVE_UI_PRIVACY_POLICY" desc="">Privacy Policy</message>
Expand Down Expand Up @@ -517,6 +518,9 @@
<message name="IDS_BRAVE_UI_PRINT" desc="">Print</message>
<message name="IDS_BRAVE_UI_PROCESSING_REQUEST" desc="">Your request is still being processed, please wait.</message>
<message name="IDS_BRAVE_UI_PROCESSING_REQUEST_BUTTON" desc="">Try again</message>
<message name="IDS_BRAVE_UI_PROCESSOR_BRAVE_TOKENS" desc="">Rewards BAT</message>
<message name="IDS_BRAVE_UI_PROCESSOR_UPHOLD" desc="">Uphold Wallet</message>
<message name="IDS_BRAVE_UI_PROCESSOR_BRAVE_USER_FUNDS" desc="">Deposited BAT</message>
<message name="IDS_BRAVE_UI_READY_TO_TAKE_PART" desc="">Ready to get started?</message>
<message name="IDS_BRAVE_UI_READY_TO_TAKE_PART_OPT_IN_TEXT" desc="">Yes I'm Ready</message>
<message name="IDS_BRAVE_UI_READY_TO_TAKE_PART_START" desc="">You can start with the</message>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -410,13 +410,15 @@ struct RecurringTip {
struct TransactionReportInfo {
double amount;
ReportType type;
ContributionProcessor processor;
uint64 created_at;
};

struct ContributionReportInfo {
string contribution_id;
double amount;
ReportType type;
ContributionProcessor processor;
array<PublisherInfo> publishers;
uint64 created_at;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -653,8 +653,8 @@ void DatabaseContributionInfo::GetContributionReport(
auto transaction = ledger::DBTransaction::New();

const std::string query = base::StringPrintf(
"SELECT ci.contribution_id, ci.amount, ci.type, ci.created_at "
"FROM %s as ci "
"SELECT ci.contribution_id, ci.amount, ci.type, ci.created_at, "
"ci.processor FROM %s as ci "
"WHERE strftime('%%m', datetime(ci.created_at, 'unixepoch')) = ? AND "
"strftime('%%Y', datetime(ci.created_at, 'unixepoch')) = ? AND step = ?",
kTableName);
Expand All @@ -674,7 +674,8 @@ void DatabaseContributionInfo::GetContributionReport(
ledger::DBCommand::RecordBindingType::STRING_TYPE,
ledger::DBCommand::RecordBindingType::DOUBLE_TYPE,
ledger::DBCommand::RecordBindingType::INT64_TYPE,
ledger::DBCommand::RecordBindingType::INT64_TYPE
ledger::DBCommand::RecordBindingType::INT64_TYPE,
ledger::DBCommand::RecordBindingType::INT_TYPE
};

transaction->commands.push_back(std::move(command));
Expand Down Expand Up @@ -708,6 +709,8 @@ void DatabaseContributionInfo::OnGetContributionReport(
info->type = static_cast<ledger::RewardsType>(
GetInt64Column(record_pointer, 2));
info->created_at = GetInt64Column(record_pointer, 3);
info->processor = static_cast<ledger::ContributionProcessor>(
GetIntColumn(record_pointer, 4));

contribution_ids.push_back(info->contribution_id);
list.push_back(std::move(info));
Expand Down Expand Up @@ -740,6 +743,7 @@ void DatabaseContributionInfo::OnGetContributionReportPublishers(
report->contribution_id = contribution->contribution_id;
report->amount = contribution->amount;
report->type = ConvertRewardsTypeToReportType(contribution->type);
report->processor = contribution->processor;
report->created_at = contribution->created_at;

report_list.push_back(std::move(report));
Expand Down

0 comments on commit 9ec956c

Please sign in to comment.