Skip to content

Add support for payout status #14063

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

Merged
merged 1 commit into from
Jul 11, 2022
Merged

Add support for payout status #14063

merged 1 commit into from
Jul 11, 2022

Conversation

emerick
Copy link
Contributor

@emerick emerick commented Jul 6, 2022

Resolves brave/brave-browser#23429

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
  • Squashed any review feedback or "fixup" commits before merge, so that history is a record of what happened in the repo, not your PR
  • 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:

Testing is similar to brave/brave-browser#18602 with the additional caveat that payout status is now controlled via a server endpoint which returns one of the following values for a wallet provider or unverified account:

  • off (no payment message will be shown at all)
  • processing (blue "Rewards are on the way" banner is shown)
  • complete (green "Your Rewards have arrived" banner is shown)

Scenario 1: Payment pending messaging

  • Given that user has ad earnings for the previous month
  • And the current day of month is before the payout day
  • When the user opens the panel, the NTP, or the rewards page
  • Then the user should see the "payment pending" message.

Scenario 1: Payment processing messaging

  • Given that user has ad earnings for the previous month
  • And the user has not received an Ad grant this month
  • And the server indicates that the payout status is "processing" for this provider
  • When the user opens the panel, the NTP, or the rewards page
  • Then the user should see the "payment processing" message.

Scenario 3: Payment arrived messaging

  • Given that user has ad earnings for the previous month
  • And the user has received an Ad grant this month
  • And the server indicates that the payout status is "complete" for this provider
  • When the user opens the panel, the NTP, or the rewards page
  • Then the user should see the "payment arrived" message.

@emerick emerick self-assigned this Jul 6, 2022
@github-actions github-actions bot added the CI/storybook-url Deploy storybook and provide a unique URL for each build label Jul 6, 2022
@emerick emerick force-pushed the emerick-rewards-payout-status branch 2 times, most recently from bd5cff4 to f6c926f Compare July 6, 2022 21:00
@brave-builds
Copy link
Collaborator

A Storybook has been deployed to preview UI for the latest push

@emerick emerick force-pushed the emerick-rewards-payout-status branch from f6c926f to 6df470f Compare July 6, 2022 21:50
@brave-builds
Copy link
Collaborator

A Storybook has been deployed to preview UI for the latest push

@emerick emerick force-pushed the emerick-rewards-payout-status branch from 6df470f to a4da516 Compare July 7, 2022 00:28
@brave-builds
Copy link
Collaborator

A Storybook has been deployed to preview UI for the latest push

@emerick emerick marked this pull request as ready for review July 7, 2022 17:09
@emerick emerick requested a review from a team as a code owner July 7, 2022 17:09
Copy link
Collaborator

@zenparsing zenparsing left a comment

Choose a reason for hiding this comment

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

Looks great - mostly just need to look at the any things.

return type::Result::LEDGER_ERROR;
}

for (const auto [key, value] : *payout_status_dict) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is this copying key and value? Is that 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.

Yeah, it is copying them due to this (new I think?) error in clang:

../../brave/vendor/bat-native-ledger/src/bat/ledger/internal/endpoint/api/get_parameters/get_parameters.cc(139,20): error: loop variable '[key, value]' binds to a temporary value produced by a range of type 'const base::Value::Dict' [-Werror,-Wrange-loop-bind-reference]
  for (const auto& [key, value] : *payout_status_dict) {
                   ^
../../brave/vendor/bat-native-ledger/src/bat/ledger/internal/endpoint/api/get_parameters/get_parameters.cc(139,8): note: use non-reference type 'base::detail::const_dict_iterator::reference' (aka 'pair<const basic_string<char, char_traits<char>, allocator<char>> &, const base::Value &>')
  for (const auto& [key, value] : *payout_status_dict) {
       ^~~~~~~~~~~~~~~~~~~~~~~~~~
1 error generated.

I'll use an iterator instead to avoid the copy.

Copy link
Collaborator

@zenparsing zenparsing Jul 8, 2022

Choose a reason for hiding this comment

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

I see, the dict iterator constructs a pair when dereferenced, whose lifetime gets extended by the destructured binding, and we have a compiler setting on to complain about that.

Does for (const auto& pair : *payout_status_dict) work?

Or maybe it needs to be for (const auto pair : *payout_status_dict).

Copy link
Collaborator

Choose a reason for hiding this comment

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

Also curious if for (const auto&& [key, value] : *payout_status_dict) works :)

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 that does work, perfect!

Copy link
Collaborator

@szilardszaloki szilardszaloki Jul 11, 2022

Choose a reason for hiding this comment

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

Ha, that's super weird. That's because base::detail::const_dict_iterator is a proxy iterator, and Clang warns you that you're extending the lifetime of a std::pair<const std::string&, const base::Value&> temporary. Not sure why it doesn't complain about const auto&&, as you're still extending the lifetime... let's remove this const, though, since it doesn't convey too much semantic meaning here. 🙂
Also, you can use emplace<>():

for (auto&& [key, value] : *payout_status_dict) {
  if (value.is_string()) {
    parameters->payout_status.emplace(key, value.GetString());
  }
}

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, I always forget about emplace!

Copy link
Collaborator

Choose a reason for hiding this comment

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

Regarding the && - it's a little cryptic, but I suppose it means that we're extending lifetimes explicitly instead of implicitly, which is better?

Copy link
Collaborator

@szilardszaloki szilardszaloki Jul 11, 2022

Choose a reason for hiding this comment

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

Clang complains about lifetime extension, so it should emit the same warning regardless of whether you're extending the lifetime via a const lvalue reference, or an rvalue reference. As far as extending lifetime via &&, this is more like implicit, since auto&& doesn't necessarily have to be an rvalue reference, it depends on type deduction (although in this specific case, it is). const auto&, however, is an lvalue reference-to-const (and not a universal/forwarding reference), hence it's more explicit.

Copy link
Collaborator

Choose a reason for hiding this comment

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

@emerick emerick force-pushed the emerick-rewards-payout-status branch 2 times, most recently from 42cdbb1 to 1bcb3e3 Compare July 11, 2022 12:59
@emerick emerick requested a review from zenparsing July 11, 2022 13:04
@brave-builds
Copy link
Collaborator

A Storybook has been deployed to preview UI for the latest push

@emerick emerick force-pushed the emerick-rewards-payout-status branch from 1bcb3e3 to 5f5c6f5 Compare July 11, 2022 14:17
@emerick emerick requested a review from szilardszaloki July 11, 2022 14:17
@emerick emerick force-pushed the emerick-rewards-payout-status branch from 5f5c6f5 to f7809e8 Compare July 11, 2022 14:36
@emerick emerick force-pushed the emerick-rewards-payout-status branch from f7809e8 to b52a882 Compare July 11, 2022 14:54
@@ -126,7 +128,7 @@ export function PaymentStatusView (props: Props) {
return null
}

if (props.earningsReceived) {
if (props.earningsReceived && props.providerPayoutStatus === 'complete') {
Copy link
Collaborator

Choose a reason for hiding this comment

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

It seems like we'll still show the processing messaging if the status is "processing", even if props.earningsReceived is true (meaning that the user has accepted the grant). Could that mean that we still show "processing" even after the user claims the grant?

Also, we still use the 3 day window for determining whether to show this messaging at all. Do we still want that?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed up the processing issue, good catch.

Regarding the 3-day window, I did intentionally leave that as-is but maybe that wasn't a good idea. @Miyayes do you have any thoughts on that?

Copy link

@Miyayes Miyayes Jul 11, 2022

Choose a reason for hiding this comment

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

Conclusion:

  • Remove 3-day window and just display banner based on status from /parameters endpoint
  • Only exception is for props.earningsReceived, whereby if it is true, no banner will show (regardless of what is received from /parameters) until the following month

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Spoke with @Miyayes privately and we decided to remove the 3-day window and just rely on the endpoint.

@brave-builds
Copy link
Collaborator

A Storybook has been deployed to preview UI for the latest push

@emerick emerick force-pushed the emerick-rewards-payout-status branch from b52a882 to 95bd02a Compare July 11, 2022 16:33
@brave-builds
Copy link
Collaborator

A Storybook has been deployed to preview UI for the latest push

@emerick emerick force-pushed the emerick-rewards-payout-status branch from 95bd02a to 3262beb Compare July 11, 2022 18:51
@brave-builds
Copy link
Collaborator

A Storybook has been deployed to preview UI for the latest push

@emerick emerick force-pushed the emerick-rewards-payout-status branch from 3262beb to f983339 Compare July 11, 2022 21:09
@emerick emerick force-pushed the emerick-rewards-payout-status branch from f983339 to a4cf4c4 Compare July 11, 2022 21:13
@brave-builds
Copy link
Collaborator

A Storybook has been deployed to preview UI for the latest push

@emerick
Copy link
Contributor Author

emerick commented Jul 11, 2022

Windows-based CI runs failed in S3 upload step; other than that, all CI platforms passed.

@emerick emerick merged commit d4d8d96 into master Jul 11, 2022
@emerick emerick deleted the emerick-rewards-payout-status branch July 11, 2022 22:51
@emerick emerick added this to the 1.43.x - Nightly milestone Jul 11, 2022
@Miyayes
Copy link

Miyayes commented Aug 8, 2022

Test Plan:

Check for crashes on older versions of Brave

Older versions of Brave also hit the /parameters endpoint. However, they don't necessarily contain logic to handle responses that contain "payoutStatus"-related values. As a result, we should make sure that older versions of Brave do not crash or have problems simply because some new values are coming back from /parameters.

  • Check 1.42.x does not error out or crash
  • Check 1.41.x does not error out or crash
  • Check 1.40.x does not error out or crash

Check new payout banner logic

The response from /parameters endpoint is the same for everybody. The values inside "payoutStatus" are set on the server side.

Example response:

"payoutStatus": {                                                                                                                      
    "unverified": "off",                                                                                                                 
    "uphold": "processing",                                                                                                              
    "gemini": "off",                                                                                                                     
    "bitflyer": "off"
  }
  • If user is Uphold, then the browser logic only cares about the value from "uphold":"value"
  • If user is unverified, the browser logic only cares about the value from "unverified":"value"
  • If user is Gemini, then the browser logic only cares about value from “"gemini":"value"
  • If user is bitFlyer, then the browser logic only cares about value from "bitflyer":"value"

When value is "off"

No payout banner should be shown.

When value is "processing"

The following banner should be shown:

When value is "complete"

The following banner should be shown:

  • Test unverified (no custodial connection) case
    • Test "off"
    • Test "processing"
    • Test "complete"
  • Test connected to Uphold case
    • Test "off"
    • Test "processing"
    • Test "complete"
  • Test connected to Gemini case
    • Test "off"
    • Test "processing"
    • Test "complete"
  • Test connected to bitFlyer case
    • Test "off"
    • Test "processing"
    • Test "complete"

Note: If the payout countdown banner ("your payout will arrive in x days") banner is present, it will take precedence over payoutStatus banner. For example, if payout date == 7th and it is the 4th, it will say "your payout will arrive in 3 days", and not show any payoutStatus banner.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CI/storybook-url Deploy storybook and provide a unique URL for each build
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement fetch Payout Status
5 participants