Skip to content

Commit

Permalink
reworked cooldown bypass logic
Browse files Browse the repository at this point in the history
  • Loading branch information
maikelmclauflin committed Apr 4, 2019
1 parent 2ba2651 commit f1c6e6a
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions ledger/controllers/grants.js
Expand Up @@ -283,7 +283,7 @@ const getGrant = (protocolVersion) => (runtime) => {
wallet.grants.forEach((grant) => { promotionIds.push(grant.promotionId) })
}
underscore.extend(query, { promotionId: { $nin: promotionIds } })
walletTooYoung = walletCooldown(runtime, wallet, bypassCooldown)
walletTooYoung = walletCooldown(wallet, bypassCooldown)
}

if (protocolVersion === 4 && !paymentId) {
Expand Down Expand Up @@ -1173,16 +1173,13 @@ function uploadTypedGrants (protocolVersion, uploadSchema, contentSchema) {
}
}

function walletCooldown (runtime, wallet, bypassCooldown) {
const { paymentId, _id } = wallet
function walletCooldown (wallet, bypassCooldown) {
const { _id } = wallet
const { WALLET_COOLDOWN_BYPASS_TOKEN } = process.env
if (bypassCooldown !== WALLET_COOLDOWN_BYPASS_TOKEN) {
if (isProduction || bypassCooldown !== WALLET_COOLDOWN_BYPASS_TOKEN) {
const offset = cooldownOffset()
const createdTime = braveUtils.createdTimestamp(_id)
return createdTime > (new Date() - offset)
} else if (WALLET_COOLDOWN_BYPASS_TOKEN && isProduction) {
// report to sentry that a bypass is being used
runtime.captureException(new Error('wallet bypass used'), { paymentId })
}
return false
}

0 comments on commit f1c6e6a

Please sign in to comment.