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 committed Feb 8, 2018
1 parent bde85a5 commit e508df0
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 @@ -1163,6 +1163,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 @@ -1174,19 +1187,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 e508df0

Please sign in to comment.