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

Fixes estimated pending rewards does not reset to expected value when you have uncashed in tokens - follow up to #16678 #9309

Merged
merged 1 commit into from
Jul 2, 2021

Conversation

tmancey
Copy link
Collaborator

@tmancey tmancey commented Jul 1, 2021

Resolves brave/brave-browser#16744

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:

  • Fresh install
  • Enable ads
  • Wait for ads to initialize (see the console log)
  • Quit the browser
  • Use Charles Proxy to rewrite the GetPayments GET /v1/confirmation/payment/{payment_id} endpoint to return
            [
              {
                "month": "2021-07",
                "transactionCount": "5",
                "balance": "0.05"
              },
              {
                "month": "2021-06",
                "transactionCount": "234",
                "balance": "1.9475"
              },
              {
                "month": "2021-05",
                "transactionCount": "170",
                "balance": "1.0385"
              },
              {
                "month": "2021-04",
                "transactionCount": "290",
                "balance": "2.8025"
              },
              {
                "month": "2021-03",
                "transactionCount": "342",
                "balance": "4.25"
              },
              {
                "month": "2021-02",
                "transactionCount": "420",
                "balance": "6.73"
              },
              {
                "month": "2021-01",
                "transactionCount": "432",
                "balance": "5.775"
              },
              {
                "month": "2020-12",
                "transactionCount": "180",
                "balance": "5.475"
              },
              {
                "month": "2020-11",
                "transactionCount": "151",
                "balance": "5.405"
              },
              {
                "month": "2020-10",
                "transactionCount": "33",
                "balance": "0.825"
              },
              {
                "month": "2020-09",
                "transactionCount": "80",
                "balance": "1.625"
              },
              {
                "month": "2020-08",
                "transactionCount": "156",
                "balance": "6.45"
              },
              {
                "month": "2020-07",
                "transactionCount": "241",
                "balance": "12.2"
              },
              {
                "month": "2020-06",
                "transactionCount": "242",
                "balance": "11.79"
              },
              {
                "month": "2020-05",
                "transactionCount": "238",
                "balance": "12.45"
              },
              {
                "month": "2020-04",
                "transactionCount": "293",
                "balance": "15.55"
              },
              {
                "month": "2020-03",
                "transactionCount": "284",
                "balance": "15.05"
              },
              {
                "month": "2020-02",
                "transactionCount": "149",
                "balance": "7.65"
              },
              {
                "month": "2020-01",
                "transactionCount": "65",
                "balance": "3.45"
              },
              {
                "month": "2019-12",
                "transactionCount": "110",
                "balance": "5.5"
              },
              {
                "month": "2019-11",
                "transactionCount": "42",
                "balance": "2.1"
              },
              {
                "month": "2019-10",
                "transactionCount": "124",
                "balance": "6.2"
              },
              {
                "month": "2019-09",
                "transactionCount": "115",
                "balance": "7.25"
              },
              {
                "month": "2019-08",
                "transactionCount": "225",
                "balance": "13.65"
              },
              {
                "month": "2019-07",
                "transactionCount": "114",
                "balance": "6.1"
              },
              {
                "month": "2019-06",
                "transactionCount": "253",
                "balance": "12.65"
              }
            ]
  • Replace the ad_rewards node in the confirmations.json file with:
  "ads_rewards": {
    "payments": [
      {
        "balance": 0.28,
        "month": "2021-05",
        "transaction_count": "48"
      },
      {
        "balance": 2.8025,
        "month": "2021-04",
        "transaction_count": "290"
      },
      {
        "balance": 4.25,
        "month": "2021-03",
        "transaction_count": "342"
      },
      {
        "balance": 6.73,
        "month": "2021-02",
        "transaction_count": "420"
      },
      {
        "balance": 5.775,
        "month": "2021-01",
        "transaction_count": "432"
      },
      {
        "balance": 5.475,
        "month": "2020-12",
        "transaction_count": "180"
      },
      {
        "balance": 5.405,
        "month": "2020-11",
        "transaction_count": "151"
      },
      {
        "balance": 0.825,
        "month": "2020-10",
        "transaction_count": "33"
      },
      {
        "balance": 1.625,
        "month": "2020-09",
        "transaction_count": "80"
      },
      {
        "balance": 6.45,
        "month": "2020-08",
        "transaction_count": "156"
      },
      {
        "balance": 12.2,
        "month": "2020-07",
        "transaction_count": "241"
      },
      {
        "balance": 11.79,
        "month": "2020-06",
        "transaction_count": "242"
      },
      {
        "balance": 12.45,
        "month": "2020-05",
        "transaction_count": "238"
      },
      {
        "balance": 15.55,
        "month": "2020-04",
        "transaction_count": "293"
      },
      {
        "balance": 15.05,
        "month": "2020-03",
        "transaction_count": "284"
      },
      {
        "balance": 7.65,
        "month": "2020-02",
        "transaction_count": "149"
      },
      {
        "balance": 3.45,
        "month": "2020-01",
        "transaction_count": "65"
      },
      {
        "balance": 5.5,
        "month": "2019-12",
        "transaction_count": "110"
      },
      {
        "balance": 2.1,
        "month": "2019-11",
        "transaction_count": "42"
      },
      {
        "balance": 6.2,
        "month": "2019-10",
        "transaction_count": "124"
      },
      {
        "balance": 7.25,
        "month": "2019-09",
        "transaction_count": "115"
      },
      {
        "balance": 13.65,
        "month": "2019-08",
        "transaction_count": "225"
      },
      {
        "balance": 6.1,
        "month": "2019-07",
        "transaction_count": "114"
      },
      {
        "balance": 12.65,
        "month": "2019-06",
        "transaction_count": "253"
      }
    ],
    "unreconciled_estimated_pending_rewards": 2.8034999999999997,
    "grants_balance": 169.68
  },
  • Launch the browser
  • Navigate to brave://rewards

EXPECTED RESULT:
Current earnings this month (estimated): 0.08 (1.27.x or 1.28.x) or Estimated pending rewards: 4.3135 (1.26.x)

  • View another ad and confirm the earnings are incremented
  • Relaunch the browser and confirm the values are correct

We should no longer see the following in the logs:

[10741:775:0629/112116.477230:INFO:ad_rewards.cc(280)] Payment balance is not ready
[10741:775:0629/112116.477303:VERBOSE1:ad_rewards.cc(355)] Failed to reconcile ad rewards

@tmancey tmancey self-assigned this Jul 1, 2021
@tmancey tmancey force-pushed the issues/16744 branch 4 times, most recently from 4f07a8d to b99af6e Compare July 2, 2021 12:52
@@ -0,0 +1,182 @@
{
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Mocked confirmations state to replicate the issue from @LaurenWags state

// Arrange
const URLEndpoints endpoints = {
{"/v1/confirmation/payment/c387c2d8-a26d-4451-83e4-5c0c6fd942be",
{{net::HTTP_OK,
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Mocked endpoint response to replicate the issue from @LaurenWags

Copy link
Contributor

@emerick emerick left a comment

Choose a reason for hiding this comment

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

LGTM

@LaurenWags
Copy link
Member

LaurenWags commented Jul 5, 2021

Verified using

Brave | 1.28.51 Chromium: 92.0.4515.81 (Official Build) nightly (x86_64)
-- | --
Revision | dba3af0a9a48954c8b188bc641e651580b7cb7b5-refs/branch-heads/4515@{#1162}
OS | macOS Version 10.15.7 (Build 19H1217)

Confirmed that my ad panel on brave://rewards correctly reflected my expectations and the expected new UI to show upcoming ad grant when I had uncashed in tokens.

1.27.x 1.28.x
1 27 x 1 28 x

Compared the 1.28.x "Current earnings this month (estimated)" to the response received from the server. "Current earnings this month (estimated)" value is taking the server value (0.245) plus the value of any uncashed in tokens (0.04) and reflecting the sum (0.285 BAT) as I expect.

My OnGetPayments response and associated messaging:

[29451:775:0705/090024.068837:VERBOSE1:ad_rewards.cc(268)] OnGetPayments
[29451:775:0705/090024.068929:VERBOSE6:ad_rewards.cc(270)] URL Response:
  URL: https://ads-serve.brave.com/v1/confirmation/payment/d.........
  Response Status Code: 200
  Response: [{"month":"2021-07","transactionCount":"22","balance":"0.245"},{"month":"2021-06","transactionCount":"234","balance":"1.9475"},{"month":"2021-05","transactionCount":"170","balance":"1.0385"},{"month":"2021-04","transactionCount":"290","balance":"2.8025"}.....................
[29451:775:0705/090024.129874:VERBOSE1:ad_rewards.cc(299)] GetAdGrants
[29451:775:0705/090024.129998:VERBOSE2:ad_rewards.cc(300)] GET /v1/promotions/ads/grants/summary?paymentId={payment_id}
[29451:775:0705/090024.130065:VERBOSE5:ad_rewards.cc(304)] URL Request:
  URL: https://grant.rewards.brave.com/v1/promotions/ads/grants/summary?paymentId=d...........
  Method: GET
[29451:775:0705/090024.294848:VERBOSE1:ad_rewards.cc(313)] OnGetAdGrants
[29451:775:0705/090024.298372:VERBOSE6:ad_rewards.cc(315)] URL Response:
  URL: https://grant.rewards.brave.com/v1/promotions/ads/grants/summary?paymentId=d................
  Response Status Code: 200
  Response: {"amount":"170.926000000000000128","earnings":"170.926000000000000128","lastClaim":"2021-06-04T19:03:31Z","type":"ads"}

[29451:775:0705/090024.305714:VERBOSE1:ad_rewards.cc(343)] Successfully reconciled ad rewards
[29451:775:0705/090024.732615:VERBOSE6:ads_impl.cc(647)] Successfully purged expired ad events

Additionally, I no longer see Payment balance is not ready and Failed to reconcile ad rewards messages in my logs.

tmancey added a commit that referenced this pull request Jul 8, 2021
This reverts commit 7bb1de4, reversing
changes made to f1c434d.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants