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

Monthly statement can now be viewed from Rewards page #2733

Closed
wants to merge 0 commits into from

Conversation

jasonrsadler
Copy link
Contributor

@jasonrsadler jasonrsadler commented Jun 18, 2019

Fixes brave/brave-browser#930

UI PR: brave/brave-ui#513

Submitter Checklist:

Test Plan:

  1. Start Brave and enable Rewards.
  2. Add funds to wallet and perform contributions of all types.
  3. Accept Ads and UGP Grants (if available)
  4. open Rewards page and click 'View monthly statement for more details'
  5. View and verify summary, transactions, monthly contributions, auto-contributions, and one-time tips
    --
    After merge it may be necessary to bring in a prepared profile that includes previous months. Required files need to be matching publisher_info_db, ledger_state, and publisher_state

Ensure that monthly dropdown operates correctly.

Note

Currently this PR allows for the current month to be displayed so long as wallet has had activity. Before merge, it is expected that only previous months from the current will be displayed.

Reviewer Checklist:

  • New files have MPL-2.0 license header.
  • Request a security/privacy review as needed.
  • Adequate test coverage exists to prevent regressions
  • Verify test plan is specified in PR before merging to source

After-merge Checklist:

  • The associated issue milestone is set to the smallest version that the
    changes has landed on.
  • All relevant documentation has been updated.

Additional Notes

Was attempting rebase and 403'd

@jasonrsadler jasonrsadler added feature/rewards CI/skip-android Do not run CI builds for Android CI/skip-linux CI/skip-ios Do not run CI builds for iOS labels Jun 18, 2019
@jasonrsadler jasonrsadler added this to the 0.68.x - Nightly milestone Jun 18, 2019
@jasonrsadler jasonrsadler self-assigned this Jun 18, 2019
@jasonrsadler jasonrsadler force-pushed the monthly_statement branch 2 times, most recently from d710dca to a3a272d Compare June 21, 2019 15:10
@jasonrsadler jasonrsadler added CI/skip Do not run CI builds (except noplatform) CI/skip-macos-x64 Do not run CI builds for macOS x64 labels Jun 21, 2019
@jasonrsadler jasonrsadler force-pushed the monthly_statement branch 2 times, most recently from 439da23 to 6ca927e Compare June 26, 2019 15:08
@jasonrsadler jasonrsadler force-pushed the monthly_statement branch 2 times, most recently from 762db26 to 9afe16b Compare July 2, 2019 21:24
@jasonrsadler jasonrsadler force-pushed the monthly_statement branch 4 times, most recently from 6cff332 to 700c2b0 Compare July 10, 2019 14:21
@jasonrsadler jasonrsadler removed CI/skip Do not run CI builds (except noplatform) CI/skip-macos-x64 Do not run CI builds for macOS x64 labels Jul 10, 2019
@jasonrsadler
Copy link
Contributor Author

++ @kylehickinson for iOS

@jasonrsadler jasonrsadler force-pushed the monthly_statement branch 2 times, most recently from 4a1a87b to 073be5c Compare July 15, 2019 10:53
args->GetString(1, &year);
int32_t month_conv;
uint32_t year_conv;
base::StringToInt(month, &month_conv);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we send these as integers from JavaScript?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@@ -240,6 +243,10 @@ class RewardsService : public KeyedService {
const std::string& type,
const std::map<std::string, std::string>& args,
GetShareURLCallback callback) = 0;
virtual void GetMonthlyStatements(
int32_t month,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason that month is signed and year is unsigned?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, month maps to ledger::MONTH which can be -1 for ANY.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, gotcha.

".getElementsByTagName('tbody')[0].childNodes.length",
content::EXECUTE_SCRIPT_DEFAULT_OPTIONS,
content::ISOLATED_WORLD_ID_CONTENT_END);
LOG(ERROR) << "=====table rows: " << acTableCountResult.ExtractInt();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this a leftover debug statement or intentional?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed.

for (let ix = 0; ix < monthsAvailable.length; ix++) {
const date = new Date(parseInt(monthsAvailable[ix].split('_')[0], 10), parseInt(monthsAvailable[ix].split('_')[1], 10) - 1)
const selectionStringValue = date.toLocaleString(navigator.language, { month: 'long' }) ;
(ix + 1) === monthsAvailable.length ? monthsJson += `\"${monthsAvailable[ix]}\" : \"${selectionStringValue} ${date.getFullYear()}\"` : monthsJson += `\"${monthsAvailable[ix]}\" : \"${selectionStringValue} ${date.getFullYear()}\",`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick: I think this would be clearer as an if-else, just given the length of this line

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

transaction->probi = report->grants;
transaction->category = 3; // placeholder for grants on statement
base::Time parsed_time;
std::string time_str =
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've been using base::StringPrintf for this kind of string formatting, just FYI.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. This does work better. changed.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm a bit confused by this. Why do we have BalanceReport and also BalanceReportInfo and then converting again to TransactionStatementInfo?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bridiver removed

base::Time parsed_time;
std::string time_str =
base::StringPrintf("%s/1/%s",
std::to_string(month).c_str(),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably simpler to use the %u format specifier instead of %s, then you don't need to convert to string.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 done

int32 category;
};

struct MonthlyStatements {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should avoid having plural types. We can have a MonthlyStatement type and pass an array of them, but that array does not require a new type.

array<TransactionStatementInfo> transactions;
};

struct AllTransactions {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as above, I'm not sure this type is necessary at all

@@ -1644,4 +1649,161 @@ void LedgerImpl::FetchBalance(ledger::FetchBalanceCallback callback) {
bat_wallet_->FetchBalance(callback);
}

void LedgerImpl::OnGetAllTransactions(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

trying to put all these different types together into a single query seems really overly complicated to me. I think we either need a new type with its own database query or do multiple queries to Ledger to get the different data types

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These have been split out.

ledger::ACTIVITY_MONTH month,
uint32_t year,
double current_balance,
ledger::MonthlyStatementCallback callback);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure if MonthlyStatement is something that ledger should care about. It's just returning some range of Transactions. It also seems a bit strange to me that the method is called GetAllTransactions/OnGetAllTransactions when it isn't getting all the transactions. I'm not really sure what the method should be called though because I'm not following exactly what we are returning since AllTransactions holds different types of data

double value;
uint64 date;
uint32 category;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is much better than a blank field for recurrent tips

ledger::PublisherInfoList list;

if (!backend) {
return all_transactions;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how do we tell the difference between an empty list and an error?

@jasonrsadler jasonrsadler added the CI/skip Do not run CI builds (except noplatform) label Jul 17, 2019
@jasonrsadler jasonrsadler force-pushed the monthly_statement branch 2 times, most recently from 1680d5c to 17c2382 Compare July 18, 2019 02:08
@@ -279,6 +281,11 @@ class LEDGER_EXPORT Ledger {
const ledger::MonthlyStatementCallback& callback,
ledger::ACTIVITY_MONTH month,
uint32_t year) = 0;

virtual void GetOneTimeTipsStatements(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should just add an optional month and year to the existing GetOneTimeTips method

int32_t month = args->GetList()[0].GetInt();
int32_t year = args->GetList()[1].GetInt();
rewards_service_->GetMonthlyStatements(
int32_t month = args->GetList()[1].GetInt();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know this was already like this, but we should avoid args->GetList()[] in favor of args->GetInteger(index, &month)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh... actually I guess not

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

// DEPRECATED, use GetList()::operator[]::GetInt() instead. huh, wouldn't have thought that

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CI/skip Do not run CI builds (except noplatform) feature/rewards PR/Pending Review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Wallet activity - Monthly Statement
5 participants