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

Calculate account statement from locally persisted state #10956

Merged
merged 1 commit into from
Dec 9, 2021

Conversation

tmancey
Copy link
Collaborator

@tmancey tmancey commented Nov 9, 2021

Resolves brave/brave-browser#16028

Submitter Checklist:

  • I confirm that no security/privacy review is needed, or that I have requested one
  • There is a ticket for my issue
  • Used Github auto-closing keywords in the PR description above
  • Wrote a good PR/commit description
  • Added appropriate labels (QA/Yes or QA/No; release-notes/include or release-notes/exclude; OS/...) to the associated issue
  • Checked the PR locally: npm run test -- brave_browser_tests, npm run test -- brave_unit_tests, npm run lint, npm run gn_check, npm run tslint
  • Ran git rebase master (if needed)

Reviewer Checklist:

  • A security review is not needed, or a link to one is included in the PR description
  • New files have MPL-2.0 license header
  • Adequate test coverage exists to prevent regressions
  • Major classes, functions and non-trivial code blocks are well-commented
  • Changes in component dependencies are properly reflected in gn
  • Code follows the style guide
  • Test plan is specified in PR before merging

After-merge Checklist:

Test Plan:

  • Confirm user is only rewarded if ads are enabled
  • Confirm users are rewarded after viewing an ad
  • Confirm confirmations are sent to the backend
  • Confirm ads are added to 30-day Ads History
  • Confirm 30-day Ads History is showing ads for the last 30-days
  • Confirm brave://rewards "Current earnings this month (estimated)" has the correct value
  • Confirm brave://rewards "Current earnings this month (estimated)" is updated when a user resets Rewards
  • Confirm brave://rewards "Next payment date" shows the correct value
  • Confirm brave://rewards "Next payment date" is updated when a user resets Rewards
  • Confirm brave://rewards "Ads received this month" has the correct value
  • Confirm brave://rewards "Ads received this month" is updated when a user resets Rewards
  • Confirm Rewards widget "Earnings" has the correct value
  • Confirm Rewards widget "Earnings" is updated when a user resets Rewards
  • Confirm Rewards panel "Estimated Earnings" has the correct value
  • Confirm Rewards panel "Estimated Earnings" is updated when a user resets Rewards
  • Confirm Rewards are reset at midnight on the 1st of each month based on the users local time to the total amount of unreconciled transactions for previous months (i.e. carried over)
  • Confirm "Your +#.# BAT payout will begin processing in # day." is working as expected
  • Confirm unblinded payment tokens are removed from confirmations.json when a user resets Rewards
  • Confirm failed confirmations are removed from confirmations.json when a user resets Rewards
  • Confirm transactions are removed from database.sqlite when a user resets Rewards
  • Confirm transactions are migrated from confirmations.json to a new transactions table in database.sqlite (built from a list of transactions for this month, a single transaction for unredeemed transactions for previous months and a single transaction for redeemed transactions last month)
  • Confirm transactions are added to transactions table in database.sqlite
  • Confirm redeemed_at column for the 'transactions' table in database.sqlite is updated for cashed-out tokens
  • Confirm next_token_redemption_date_in_seconds is migrated from confirmations.json to brave.brave_ads.rewards.next_time_redemption_at pref
  • Confirm next token redemption date is working as expected
  • Confirm day parting frequency cap is working as expected
  • Confirm upgrade path from 1.34.x to 1.35.x is working as expected
  • Test performance for transaction tables that have a large amount of transactions (especially on iOS)

NOTE: GET /v1/confirmation/payment/{payment_id} endpoint has been deprecated

@tmancey tmancey requested a review from moritzhaller November 9, 2021 17:30
@tmancey tmancey requested review from a team as code owners November 9, 2021 17:30
@tmancey tmancey self-assigned this Nov 9, 2021
@tmancey tmancey requested review from jumde and zenparsing November 9, 2021 17:30
@tmancey tmancey marked this pull request as draft November 9, 2021 17:31
@tmancey tmancey changed the title Issues/16028 Calculate account statement from locally persisted state Nov 9, 2021
@tmancey tmancey force-pushed the issues/16028 branch 10 times, most recently from e0e4309 to 1422fb8 Compare November 13, 2021 23:29
@tmancey tmancey force-pushed the issues/16028 branch 9 times, most recently from b35703b to 6c14779 Compare November 19, 2021 21:54
@tmancey tmancey force-pushed the issues/16028 branch 14 times, most recently from 5f5b319 to 841f8d6 Compare December 7, 2021 21:55
@@ -1055,9 +1055,9 @@ dependencies = [

[[package]]
Copy link
Collaborator

@aseren aseren Dec 8, 2021

Choose a reason for hiding this comment

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

Do we need to commit changes in this file?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Fixed

@@ -66,19 +66,19 @@ void Account::RemoveObserver(AccountObserver* observer) {
}

bool Account::SetWallet(const std::string& id, const std::string& seed) {
const WalletInfo last_wallet = wallet_->Get();
const WalletInfo& last_wallet = wallet_->Get();
Copy link
Collaborator

Choose a reason for hiding this comment

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

In this case adding a reference & dosn't do any optimizations because wallet_->Get() returns a copy of WalletInfo object.
I think const WalletInfo last_wallet = wallet_->Get(); is better here.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Agreed to followup in a separate issue

void Account::TopUpUnblindedTokens() {
if (!ShouldRewardUser()) {
return;
}

const WalletInfo wallet = GetWallet();
const WalletInfo& wallet = GetWallet();
Copy link
Collaborator

Choose a reason for hiding this comment

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

seems like const WalletInfo wallet = GetWallet(); would be better and in the code below.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Agreed to followup in a separate issue

namespace ads {

base::Time GetNextPaymentDate(const TransactionList& transactions) {
const base::Time& next_token_redemption_at = base::Time::FromDoubleT(
Copy link
Collaborator

Choose a reason for hiding this comment

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

These references are also redundant. Agreed to followup in a separate issue

@tmancey tmancey force-pushed the issues/16028 branch 3 times, most recently from 7c7d414 to 18410e9 Compare December 8, 2021 19:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Calculate account statement from locally persisted state
5 participants