Skip to content

Commit

Permalink
Merge pull request #808 from siiky/fix/lam-506/tc-button-timeout
Browse files Browse the repository at this point in the history
fix: increase delay on terms and conditions accept button
  • Loading branch information
RafaelTaranto authored Jun 14, 2022
2 parents 8b7178e + bbde18d commit 6f0cdd6
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 7 deletions.
22 changes: 16 additions & 6 deletions lib/brain.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ const Brain = function (config) {
this.scannerTimeout = null
this.manualTriggersDataProvided = _.zipObject(AUTOMATABLE_REQUIREMENTS, Array(AUTOMATABLE_REQUIREMENTS.length).fill(false))
this.txBlockedByManualTrigger = false
this.termsAcceptButtonPressed = false

this.numberOfCassettes = _.isFinite(parseInt(deviceConfig.billDispenser.cassettes))
? deviceConfig.billDispenser.cassettes
Expand Down Expand Up @@ -2291,6 +2292,9 @@ Brain.prototype.completeBillHandling = function completeBillHandling (blockedCus
Brain.prototype.startScreen = function startScreen () {
const direction = this.tx.direction

// reset T&C accept button flag
this.termsAcceptButtonPressed = false

// check if terms screen is enabled
// and user still need to accept terms
if (this.mustAcceptTerms()) {
Expand Down Expand Up @@ -2318,14 +2322,20 @@ Brain.prototype.mustAcceptTerms = function mustAcceptTerms () {

Brain.prototype.acceptTerms = function acceptTerms () {
if (this.scanner.isOpened()) this.scanner.cancel()
// disable accept button after one click
this.browser().send({ terms: _.assign(this.trader.terms, { acceptDisabled: true }) })
if (!this.termsAcceptButtonPressed) {
// timeout is a safety net to ensure that we close
// the camera before opening it for another task
setTimeout(() => {
// mark terms as accepted
// and redirect user to start screen
this.tx = Tx.update(this.tx, { termsAccepted: true })
this.startScreen()
}, 1000)
setTimeout(() => {
// mark terms as accepted
// and redirect user to start screen
this.tx = Tx.update(this.tx, { termsAccepted: true })
this.startScreen()
}, 1000)
}
// avoid setting multiple timeouts
this.termsAcceptButtonPressed = true
}

function chooseBillDispenser (config) {
Expand Down
6 changes: 6 additions & 0 deletions ui/js/app.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion ui/js/app.js.map

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions ui/src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -1198,9 +1198,15 @@ function setTermsScreen (data) {
$screen.find('.js-terms-cancel-button').html(data.cancel)
$screen.find('.js-terms-accept-button').html(data.accept)
setTermsConditionsTimeout()
setAcceptButtonDisabled($screen, data)
setTermsConditionsAcceptanceDelay($screen, data)
}

function setAcceptButtonDisabled (screen, data) {
var acceptButton = screen.find('.js-terms-accept-button');
acceptButton.prop('disabled', Boolean(data.acceptDisabled));
}

function clearTermsConditionsTimeout () {
clearTimeout(termsConditionsTimeout)
}
Expand Down

0 comments on commit 6f0cdd6

Please sign in to comment.