Skip to content

Commit

Permalink
Merge pull request #1248 from RafaelTaranto/backport/automatic-receip…
Browse files Browse the repository at this point in the history
…t-printing

LAM-411 backport: automatic receipt printing
  • Loading branch information
RafaelTaranto authored Nov 29, 2024
2 parents 96f0cd0 + 84b141a commit eaecd77
Show file tree
Hide file tree
Showing 13 changed files with 321 additions and 119 deletions.
27 changes: 20 additions & 7 deletions lib/brain.js
Original file line number Diff line number Diff line change
Expand Up @@ -2037,7 +2037,10 @@ Brain.prototype.minimumFiat = function minimumFiat () {
}

Brain.prototype.authFlowHandleReturnState = function authFlowHandleReturnState () {
this.browser().send({ smsReceiptStatus: this.trader.smsReceiptActive ? 'available' : 'disabled' })
this.browser().send({
smsReceiptStatus: this.trader.smsReceiptActive ? 'available' : 'disabled',
automaticPrint: this.isAutomaticPrintActive()
})

/**
* No need to check compliance on redeem,
Expand Down Expand Up @@ -2442,7 +2445,8 @@ Brain.prototype._start = function _start () {
this.browser().send({
tx: this.tx,
receiptStatus: this.trader.receiptPrintingActive ? 'available' : 'disabled',
smsReceiptStatus: this.trader.smsReceiptActive && this.customer ? 'available' : 'disabled'
smsReceiptStatus: this.trader.smsReceiptActive && this.customer ? 'available' : 'disabled',
automaticPrint: this.isAutomaticPrintActive()
})

if (printPaperWallet) {
Expand Down Expand Up @@ -3486,9 +3490,15 @@ Brain.prototype._cashInComplete = function _cashInComplete () {
txId: this.tx.id
})

if (this.isAutomaticPrintActive()) this._startPrintReceipt()

this._screenTimeout(this._completed.bind(this), COMPLETED_TIMEOUT)
}

Brain.prototype.isAutomaticPrintActive = function () {
return this.trader.receiptPrintingActive && this.trader.automaticReceiptPrintActive
}

Brain.prototype._sendSmsReceipt = function _sendSmsReceipt () {
const customer = this.customer
const data = {
Expand All @@ -3508,13 +3518,13 @@ Brain.prototype._sendSmsReceipt = function _sendSmsReceipt () {
}

Brain.prototype._startPrintReceipt = function _startPrintReceipt () {
this.browser().send({ receiptStatus: 'printing' })
this.browser().send({ receiptStatus: 'printing', automaticPrint: this.isAutomaticPrintActive() })
this._printReceipt()
.then(() => this.browser().send({ receiptStatus: 'success' }))
.then(() => this.browser().send({ receiptStatus: 'success', automaticPrint: this.isAutomaticPrintActive() }))
.catch(() => {
this.browser().send({ receiptStatus: 'failed' })
this.browser().send({ receiptStatus: 'failed', automaticPrint: this.isAutomaticPrintActive() })
setTimeout(() => {
this.browser().send({ receiptStatus: 'available' })
this.browser().send({ receiptStatus: 'available', automaticPrint: this.isAutomaticPrintActive() })
}, 2500)
})
}
Expand Down Expand Up @@ -3803,7 +3813,8 @@ Brain.prototype._chooseFiat = function _chooseFiat () {
this._transitionState('chooseFiat', {
chooseFiat: response,
isCashInOnlyCoin: coin.isCashInOnly,
receiptStatus: this.trader.receiptPrintingActive ? 'available' : 'disabled'
receiptStatus: this.trader.receiptPrintingActive ? 'available' : 'disabled',
automaticPrint: this.isAutomaticPrintActive()
})
const self = this
this.dirtyScreen = false
Expand Down Expand Up @@ -4061,6 +4072,8 @@ Brain.prototype._batchesFinished = function _batchesFinished ({ dispenseRecords,

this._transitionState('fiatComplete', { tx: displayTx, smsReceiptStatus: this.trader.smsReceiptActive && this.customer ? 'available' : 'disabled' })

if (this.isAutomaticPrintActive()) this._startPrintReceipt()

pDelay(COMPLETED_TIMEOUT).then(() => {
emit({ action: 'billDispenserCollected' })
if (tx.id !== _.get('id')(this.tx)) {
Expand Down
3 changes: 3 additions & 0 deletions lib/trader.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ query($configVersion: Int, $currentHash: String) {
}
receiptInfo {
automaticPrint
paper
sms
operatorWebsite
Expand Down Expand Up @@ -728,8 +729,10 @@ Trader.prototype.pollHandler = function pollHandler (data) {
this.smsReceiptActive = data.receiptInfo && data.receiptInfo.sms
if (data.receiptInfo && (this.receiptPrintingActive || this.smsReceiptActive)) {
this.receiptOptions = _.omit(['paper','sms'], data.receiptInfo)
this.automaticReceiptPrintActive = data.receiptInfo.automaticPrint
} else {
this.receiptOptions = null
this.automaticReceiptPrintActive = null
}

this.locale = {
Expand Down
16 changes: 8 additions & 8 deletions ui/css/main.scss
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,12 @@ footer {
min-height: 12vh;
}

.print-receipt-wrapper {
display: flex;
align-items: center;
flex-direction: row;
}

@media (max-height: 900px) {
.take-a-photo {
display: flex;
Expand Down Expand Up @@ -1341,26 +1347,20 @@ footer {
display: block;
}

#print-receipt-cash-in-button, #print-receipt-cash-out-button, #print-receipt-cash-in-fail-button {
margin-top: 3vh;
}
#print-receipt-cash-in-button, #print-receipt-cash-out-button, #print-receipt-cash-in-fail-button {}

#send-sms-receipt-cash-in-button, #send-sms-receipt-cash-out-button, #send-sms-receipt-cash-in-fail-button {
margin-left: 3vh;
margin-top: 3vh;
}

#fiat_complete_viewport #print-receipt-cash-out-button #send-sms-receipt-cash-out-button {
margin-top: 18vh;
}

#print-receipt-cash-in-message, #print-receipt-cash-out-message, #print-receipt-cash-in-fail-message {
margin-top: 4vh;
}
#print-receipt-cash-in-message, #print-receipt-cash-out-message, #print-receipt-cash-in-fail-message {}

#send-sms-receipt-cash-in-message, #send-sms-receipt-cash-out-message, #send-sms-receipt-cash-in-fail-message {
margin-left: 3vh;
margin-top: 4vh;
}

.promo-code-title-wrapper {
Expand Down
4 changes: 2 additions & 2 deletions ui/html/completed.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ <h2 class="js-i18n primary-side-title">Thank you!</h2>
<p class="tl2 amount-deposited"></p>
<p class="js-i18n d2 coins-to-address">Your coins are on their way to:</p>
<p class="m2 crypto-address"></p>
<footer>
<div class="print-receipt-wrapper">
<button id="print-receipt-cash-in-button" class="js-i18n bordered-progress-button button tl2">
Print receipt
</button>
Expand All @@ -26,7 +26,7 @@ <h2 class="js-i18n primary-side-title">Thank you!</h2>
Send SMS receipt
</button>
<p id="send-sms-receipt-cash-in-message" class="d2 hide"></p>
</footer>
</div>
</section>
<section class="secondary-side qr-secondary-side">
<div class="qr-wrapper">
Expand Down
4 changes: 2 additions & 2 deletions ui/html/fiat-complete.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ <h2 class="js-i18n primary-side-title">Thank you!</h2>
<span class="js-crypto-display-units"></span>
</p>
</div>
<footer>
<div class="print-receipt-wrapper">
<button id="print-receipt-cash-out-button" class="js-i18n bordered-progress-button button tl2">
Print receipt
</button>
Expand All @@ -30,7 +30,7 @@ <h2 class="js-i18n primary-side-title">Thank you!</h2>
Send SMS receipt
</button>
<p id="send-sms-receipt-cash-out-message" class="d2 hide"></p>
</footer>
</div>
</section>
<section class="secondary-side qr-secondary-side">
<div class="qr-wrapper">
Expand Down
4 changes: 2 additions & 2 deletions ui/html/withdraw-failure.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ <h2 class="js-i18n primary-side-title no-margin-top xs-margin-bottom">We got thi
<p class="tl2 amount-deposited sm-margin-top"></p>
<p class="js-i18n d2 no-margin-bottom sm-margin-top">Your coins are on their way to:</p>
<p class="m2 crypto-address"></p>
<footer>
<div class="print-receipt-wrapper">
<button id="print-receipt-cash-in-fail-button" class="js-i18n bordered-progress-button button tl2">
Print receipt
</button>
Expand All @@ -28,7 +28,7 @@ <h2 class="js-i18n primary-side-title no-margin-top xs-margin-bottom">We got thi
Send SMS receipt
</button>
<p id="send-sms-receipt-cash-in-fail-message" class="d2 hide"></p>
</footer>
</div>
</section>
<section class="secondary-side qr-secondary-side">
<section class="qr-section">
Expand Down
Loading

0 comments on commit eaecd77

Please sign in to comment.