Skip to content

Commit

Permalink
fix: avoid setting up multiple tc timeouts
Browse files Browse the repository at this point in the history
  • Loading branch information
josepfo authored and siiky committed Jun 14, 2022
1 parent 8b7178e commit e01a747
Show file tree
Hide file tree
Showing 4 changed files with 37 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
10 changes: 10 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.

10 changes: 10 additions & 0 deletions ui/src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -1198,9 +1198,19 @@ 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');
if (!data.acceptDisabled) {
acceptButton.prop('disabled', false);
} else {
acceptButton.prop('disabled', true);
}
}

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

0 comments on commit e01a747

Please sign in to comment.