Skip to content

Commit

Permalink
Merge pull request #1178 from siiky/fix/lam-1115/button-countdown
Browse files Browse the repository at this point in the history
LAM-1115 fix button countdown
  • Loading branch information
RafaelTaranto authored Sep 12, 2024
2 parents a91f6f7 + e4042f7 commit 4effdec
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 10 deletions.
30 changes: 23 additions & 7 deletions lib/brain.js
Original file line number Diff line number Diff line change
Expand Up @@ -2410,7 +2410,7 @@ Brain.prototype.startScreen = function startScreen () {
// check if terms screen is enabled
// and user still need to accept terms
if (this.mustAcceptTerms()) {
if (this.trader.terms.tcPhoto && this.hasFrontFacingCamera) {
if (this._tcPhotoEnabled() && this.hasFrontFacingCamera) {
this.takeFacePhotoTC()
}
return this._transitionState('termsScreen')
Expand All @@ -2425,8 +2425,7 @@ Brain.prototype.startScreen = function startScreen () {
Brain.prototype.mustAcceptTerms = function mustAcceptTerms () {
return (
// check if terms screen is enabled
this.trader.terms &&
this.trader.terms.active &&
this._tcEnabled() &&
// and user still need to accept terms
!this.tx.termsAccepted
)
Expand Down Expand Up @@ -2815,14 +2814,31 @@ Brain.prototype.balance = function balance () {
return this.trader.balances[cryptoCode]
}

Brain.prototype.hasTermsDelayEnabled = function hasTermsDelayEnabled () {
return _.get('delay', this.trader.terms)
Brain.prototype._tcEnabled = function _tcEnabled () {
return _.get(['active'], this.trader.terms)
}

Brain.prototype._tcPhotoEnabled = function _tcPhotoEnabled () {
return _.get(['tcPhoto'], this.trader.terms)
}

Brain.prototype._getTermsDelayConfig = function _getTermsDelayConfig () {
const ret = { delayTimer: 0, delay: false }
if (!this._tcEnabled()) return ret

const termsDelayEnabled = _.get(['delay'], this.trader.terms)
const buttonDelay = termsDelayEnabled ? TERMS_DELAY : 0
const photoEnabled = this._tcPhotoEnabled()
const photoDelay = photoEnabled ? this.scanner.getDelayMS() : 0

ret.delayTimer = Math.max(photoDelay, buttonDelay)
ret.delay = photoEnabled || termsDelayEnabled
return ret
}

Brain.prototype.sendRates = function sendRates () {
const cryptoCode = this.tx.cryptoCode
if (!cryptoCode) return
const delayTimer = Math.max(this.scanner.getDelayMS(), this.hasTermsDelayEnabled() ? TERMS_DELAY : 0)
const rec = {
fiatCode: this.fiatCode,
rates: {
Expand All @@ -2832,7 +2848,7 @@ Brain.prototype.sendRates = function sendRates () {
},
coins: this.trader.coins,
twoWayMode: this.twoWayMode(),
terms: _.assign(this.trader.terms, { delayTimer, delay: true }),
terms: _.assign(this.trader.terms, this._getTermsDelayConfig()),
operatorInfo: this.trader.operatorInfo,
areThereAvailablePromoCodes: this.trader.areThereAvailablePromoCodes,
supportedCoins: this.mapCryptoUnitsDisplay(this.trader.coins)
Expand Down
2 changes: 1 addition & 1 deletion lib/mocks/scanner.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ function diagnosticPhotos () {
const delayedFacephoto = callback =>
scanFacephoto(callback)

const getDelayMS = () => 0
const getDelayMS = () => 3000

module.exports = {
config,
Expand Down
2 changes: 0 additions & 2 deletions ui/src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ var two = null
var cryptomatModel = null
var termsConditionsTimeout = null
var termsConditionsAcceptanceInterval = null
var termsConditionsAcceptanceTimeout = null
var T_C_TIMEOUT = 30000
var complianceTimeout = null;
var cashDirection = null;
Expand Down Expand Up @@ -1397,7 +1396,6 @@ function setTermsConditionsAcceptanceDelay (screen, data) {

function clearTermsConditionsAcceptanceDelay () {
clearInterval(termsConditionsAcceptanceInterval)
clearTimeout(termsConditionsAcceptanceTimeout)
}

function resetTermsConditionsTimeout () {
Expand Down

0 comments on commit 4effdec

Please sign in to comment.