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

Commit

Permalink
Merge pull request #12657 from NejcZdovc/hotfix/#12355-random
Browse files Browse the repository at this point in the history
Randomise promotions intervals
  • Loading branch information
bsclifton authored and NejcZdovc committed Feb 24, 2018
1 parent ce127d1 commit cd11167
Showing 1 changed file with 17 additions and 8 deletions.
25 changes: 17 additions & 8 deletions app/browser/api/ledger.js
Original file line number Diff line number Diff line change
Expand Up @@ -1169,6 +1169,19 @@ const initSynopsis = (state) => {
return state
}

const checkPromotions = () => {
if (promotionTimeoutId) {
clearInterval(promotionTimeoutId)
}

// get promotions
appActions.onPromotionGet()

promotionTimeoutId = setTimeout(() => {
checkPromotions()
}, random.randomInt({min: 20 * ledgerUtil.milliseconds.hour, max: 24 * ledgerUtil.milliseconds.hour}))
}

const enable = (state, paymentsEnabled) => {
if (paymentsEnabled) {
state = checkBtcBatMigrated(state, paymentsEnabled)
Expand All @@ -1180,19 +1193,15 @@ const enable = (state, paymentsEnabled) => {

if (paymentsEnabled === getSetting(settings.PAYMENTS_ENABLED)) {
// on start
if (promotionTimeoutId) {
clearInterval(promotionTimeoutId)
}
promotionTimeoutId = setInterval(() => {
appActions.onPromotionGet()
}, 24 * ledgerUtil.milliseconds.hour)

if (togglePromotionTimeoutId) {
clearTimeout(togglePromotionTimeoutId)
}

togglePromotionTimeoutId = setTimeout(() => {
appActions.onPromotionGet()
}, 15 * ledgerUtil.milliseconds.second)
checkPromotions()
}, random.randomInt({min: 10 * ledgerUtil.milliseconds.second, max: 15 * ledgerUtil.milliseconds.second}))

} else if (paymentsEnabled) {
// on toggle
if (togglePromotionTimeoutId) {
Expand Down

0 comments on commit cd11167

Please sign in to comment.