Skip to content
This repository has been archived by the owner on Dec 11, 2019. It is now read-only.

Fixes publisher toggle (heart), button enables after time requirements satisfied. #13900

Merged
merged 1 commit into from
Apr 27, 2018

Conversation

ryanml
Copy link
Contributor

@ryanml ryanml commented Apr 23, 2018

Fixes #12675

Submitter Checklist:

  • Submitted a ticket for my issue if one did not already exist.
  • Used Github auto-closing keywords in the commit message.
  • Added/updated tests for this change (for new code or code which already has tests).
  • Ran git rebase -i to squash commits (if needed).
  • Tagged reviewers and labelled the pull request as needed.
  • Request a security/privacy review as needed. (Ask a Brave employee to help if you cannot access this document.)

Test Plan:

  1. Enable payments
  2. Select a minimum browsing time and visits in payment settings, (1 visit for ease)
  3. Open web console for error notation.
  4. Navigate to any web page.
  5. Browse the page for the minimum browsing time.
  6. Confirm that the publisher toggle button is enabled (Yellow if site was pinned when included in the ledger, deeper black if merely included in the ledger)
  7. In the same tab, navigate to a different web page
  8. Repeat steps 5 and 6.
  9. Open a new tab, navigate to a new web page
  10. Repeat steps 5 and 6

Reviewer Checklist:

  • Request a security/privacy review as needed if one was not already requested.

Tests

  • Adequate test coverage exists to prevent regressions
  • Tests should be independent and work correctly when run individually or as a suite ref
  • New files have MPL2 license header

Given that there didn't seem to be an appropriate appConstant (or a relatively efficient/telling new one that could be made), it seems to make sense for the Publisher Toggle component to have an attribute of its internal state that can check its ledger status at an interval.

Currently, the interval avoids starting until after APP_TOP_SITE_DATA_AVAILABLE has dispatched. Doing this call to pageDataChanged before that action can break ledger activity recorder.

The interval will clear once the publisher toggle has reached an enabled state (there's no way for a site to become disabled merely by browsing, so this interval does not concern that path), any time the publisherToggle component dismounts, and reset if the tab loads to a new potential publisher.

@ryanml
Copy link
Contributor Author

ryanml commented Apr 24, 2018

WIP has been removed, I may have a way to eliminate the use of setTimeout

Copy link
Contributor

@NejcZdovc NejcZdovc left a comment

Choose a reason for hiding this comment

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

getting this error:

"Warning: setState(...): Can only update a mounted or mounting component. This usually means you called setState() on an unmounted component. This is a no-op. Please check the code for the PublisherToggle component.", source: http://localhost:8080/gen/app.entry.js (5816)

// page visit has started recording. It is important that a
// page data update is not triggered before this has happened.
const topSitesWait = ledgerUtil.milliseconds.second * 6
const updateWait = ledgerUtil.milliseconds.second * 3
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 instead of triggering this every 3s, trigger this only after MIN_VISIT_TIME?

Copy link
Contributor

Choose a reason for hiding this comment

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

also we have min count, so that means if you set this for 10, you need to visit this site 10 times. Maybe we should only add this timer if this visit would hit this minimum. This means that we would not add timer until you have 9 visits already logged and this is your 10 visit. Only in this case we would add timer, which would be min visit time

@ryanml wdyt?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think this approach would be a lot more efficient yes, especially for minimums with multiple visits. It only would not work for one scenario:

Suppose your minimums are 1 visit for 1 minute, and you've made one visit but only for 41 seconds. Visiting the site again with this approach you'd have to wait 60 seconds for the full MIN_VISIT_TIME to pass.

To get around that, maybe we could calculate the time remaining, (In the above scenario, calculate 60000 - 41000 = 19000 and set the timeout to 19000). Does that sound agreeable?

Copy link
Contributor

Choose a reason for hiding this comment

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

yes let's do that

@@ -32,6 +32,7 @@ const fundUnverifiedPublisherImage = require('../../../extensions/brave/img/urlb
class PublisherToggle extends React.Component {
constructor (props) {
super(props)
this.mounted = false
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 for fixing 👍

// page visit has started recording. It is important that a
// page data update is not triggered before this has happened.
const topSitesWait = ledgerUtil.milliseconds.second * 6
const updateWait = ledgerUtil.milliseconds.second * 3
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think this approach would be a lot more efficient yes, especially for minimums with multiple visits. It only would not work for one scenario:

Suppose your minimums are 1 visit for 1 minute, and you've made one visit but only for 41 seconds. Visiting the site again with this approach you'd have to wait 60 seconds for the full MIN_VISIT_TIME to pass.

To get around that, maybe we could calculate the time remaining, (In the above scenario, calculate 60000 - 41000 = 19000 and set the timeout to 19000). Does that sound agreeable?

@ryanml
Copy link
Contributor Author

ryanml commented Apr 25, 2018

@NejcZdovc changes pushed, ready to review. The correct calculations should now be in place so an update is only triggered when it needs to.

@ryanml ryanml force-pushed the ledger-heart-toggle-fix branch 2 times, most recently from 3e19cb6 to ec69a3c Compare April 26, 2018 04:59
@@ -591,6 +592,45 @@ const getMediaProvider = (url, firstPartyUrl, referrer) => {
return provider
}

const shouldSetTimeout = (publisherKey) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Please rename this to something more verbose like hasRequiredVisits

return (visitDifference === 1)
}

const getTimeoutWait = (publisherKey) => {
Copy link
Contributor

@NejcZdovc NejcZdovc Apr 26, 2018

Choose a reason for hiding this comment

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

Please rename this to something more verbose like getRemainingRequiredTime

const publisher = ledgerState.getPublisher(appStore.state, publisherKey)
const publisherVisits = publisher.get('visits')

if (publisherVisits === undefined) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we just check here if publisherVisits is number?

const publisherDuration = publisher.get('duration')

if (
publisherDuration === undefined ||
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we just check here if publisherDuration is number?

@NejcZdovc NejcZdovc self-requested a review April 26, 2018 05:30
@NejcZdovc
Copy link
Contributor

@ryanml please add tests

@codecov-io
Copy link

codecov-io commented Apr 26, 2018

Codecov Report

Merging #13900 into master will increase coverage by 0.03%.
The diff coverage is 80.28%.

@@            Coverage Diff             @@
##           master   #13900      +/-   ##
==========================================
+ Coverage   56.45%   56.49%   +0.03%     
==========================================
  Files         284      284              
  Lines       29220    29302      +82     
  Branches     4851     4864      +13     
==========================================
+ Hits        16495    16553      +58     
- Misses      12725    12749      +24
Flag Coverage Δ
#unittest 56.49% <80.28%> (+0.03%) ⬆️
Impacted Files Coverage Δ
js/constants/appConstants.js 100% <ø> (ø) ⬆️
app/browser/reducers/ledgerReducer.js 44.77% <0%> (-0.42%) ⬇️
app/common/lib/ledgerUtil.js 96.09% <100%> (+0.38%) ⬆️
js/actions/appActions.js 19.26% <100%> (+0.42%) ⬆️
.../renderer/components/navigation/publisherToggle.js 81.25% <70%> (-5.42%) ⬇️
js/stores/appStoreRenderer.js 91.66% <0%> (-8.34%) ⬇️
app/renderer/components/reduxComponent.js 57.75% <0%> (-3.45%) ⬇️
js/stores/windowStore.js 28.46% <0%> (-0.3%) ⬇️
... and 1 more

Copy link
Contributor

@NejcZdovc NejcZdovc left a comment

Choose a reason for hiding this comment

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

works great, after tests are added we can merge it

@ryanml
Copy link
Contributor Author

ryanml commented Apr 26, 2018

@NejcZdovc tests added

Copy link
Contributor

@NejcZdovc NejcZdovc left a comment

Choose a reason for hiding this comment

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

++ works great

@NejcZdovc NejcZdovc added this to the 0.22.x Release 3 (Beta channel) milestone Apr 27, 2018
@NejcZdovc NejcZdovc merged commit 15a6784 into brave:master Apr 27, 2018
NejcZdovc added a commit that referenced this pull request Apr 27, 2018
Fixes publisher toggle (heart), button enables after time requirements satisfied.
NejcZdovc added a commit that referenced this pull request Apr 27, 2018
Fixes publisher toggle (heart), button enables after time requirements satisfied.
@NejcZdovc
Copy link
Contributor

master 15a6784
0.23 b0e14b2
0.22-release3 f5e4dc6

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants