Skip to content

Commit

Permalink
Merge branch 'dev' into backport/blacklist-message
Browse files Browse the repository at this point in the history
  • Loading branch information
RafaelTaranto authored Nov 29, 2024
2 parents a5b984a + bedd930 commit ce2fcf1
Show file tree
Hide file tree
Showing 20 changed files with 502 additions and 10 deletions.
2 changes: 1 addition & 1 deletion i18n/parse.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ const app = fs.readFileSync(appPath, {encoding: 'utf8'})
const outPath = path.resolve(__dirname, '../i18n/ui/lbm-ui_en-US.po')

const coins = [
'Bitcoin', 'Ethereum', 'Zcash', 'Litecoin', 'Dash', 'Bitcoin Cash'
'Bitcoin', 'Ethereum', 'Zcash', 'Litecoin', 'Dash', 'Bitcoin Cash', 'Monero', 'USDT'
]

function run (){
Expand Down
28 changes: 28 additions & 0 deletions i18n/ui/lbm-ui_en-US.po
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,10 @@ msgstr "Please contact the operator if you wish to learn more."
msgid "Languages"
msgstr "Languages"

#: On screen: choose_coin
msgid "Rates"
msgstr "Rates"

#: On screen: choose_coin
msgid "Redeem"
msgstr "Redeem"
Expand Down Expand Up @@ -594,6 +598,22 @@ msgstr "If you are sure of the code, please contact the operator for clarificati
msgid "Enter a different code"
msgstr "Enter a different code"

#: On screen: rates
msgid "Exchange Rates"
msgstr "Exchange Rates"

#: On screen: rates
msgid "Buy"
msgstr "Buy"

#: On screen: rates
msgid "Crypto"
msgstr "Crypto"

#: On screen: rates
msgid "Sell"
msgstr "Sell"

#: On screen: recycler-continue
msgid "Depositing bills..."
msgstr "Depositing bills..."
Expand Down Expand Up @@ -1078,3 +1098,11 @@ msgstr "Dash"
msgid "Bitcoin Cash"
msgstr "Bitcoin Cash"

#: On screen: coins
msgid "Monero"
msgstr "Monero"

#: On screen: coins
msgid "USDT"
msgstr "USDT"

33 changes: 31 additions & 2 deletions lib/brain.js
Original file line number Diff line number Diff line change
Expand Up @@ -1098,6 +1098,7 @@ Brain.prototype._connectedBrowser = function _connectedBrowser () {
cryptomatModel,
version,
operatorInfo: this.trader?.operatorInfo ?? { active: false },
screenOpts: this.trader?.machineScreenOpts
}

return this.browser().send(rec)
Expand Down Expand Up @@ -1130,7 +1131,8 @@ Brain.prototype._connectedBrowser = function _connectedBrowser () {
operatorInfo: this.trader.operatorInfo,
cryptomatModel,
areThereAvailablePromoCodes: this.trader.areThereAvailablePromoCodes,
supportedCoins: this.mapCryptoUnitsDisplay(this.trader.coins)
supportedCoins: this.mapCryptoUnitsDisplay(this.trader.coins),
screenOpts: this.trader.machineScreenOpts
}

this.browser().send(fullRec)
Expand Down Expand Up @@ -1375,6 +1377,9 @@ Brain.prototype._processReal = function _processReal (req) {
case 'leftoverBillsRemoved':
this._leftoverBillsRemoved()
break
case 'ratesScreen':
this.ratesScreen()
break
default:
break
}
Expand Down Expand Up @@ -2334,6 +2339,7 @@ Brain.prototype._chooseCoinScreen = function _chooseCoinsScreen (localeInfo, cas
localeInfo: localeInfo,
cassettes: cassettes,
coins: this.trader.coins,
screenOpts: this.trader.machineScreenOpts,
twoWayMode: this.twoWayMode(),
supportedCoins: this.mapCryptoUnitsDisplay(this.trader.coins)
})
Expand Down Expand Up @@ -2670,7 +2676,8 @@ Brain.prototype.sendRates = function sendRates () {
terms: _.assign(this.trader.terms, this._getTermsDelayConfig()),
operatorInfo: this.trader.operatorInfo,
areThereAvailablePromoCodes: this.trader.areThereAvailablePromoCodes,
supportedCoins: this.mapCryptoUnitsDisplay(this.trader.coins)
supportedCoins: this.mapCryptoUnitsDisplay(this.trader.coins),
screenOpts: this.trader.machineScreenOpts
}

this.browser().send(rec)
Expand Down Expand Up @@ -3249,6 +3256,7 @@ Brain.prototype._billsEnabled = function _billsEnabled () {

Brain.prototype._stackerOpen = function _stackerOpen () {
return this.trader.notifyCashboxRemoval()
.then(this._printCashboxReceipt)
}

Brain.prototype._uiCredit = function _uiCredit () {
Expand Down Expand Up @@ -3526,6 +3534,20 @@ Brain.prototype._printReceipt = function _printReceipt () {
})
}

Brain.prototype._printCashboxReceipt = function (data) {
if (!this.printer) {
console.log('[ERROR]: The kiosk printer is not loaded')
return
}

return this.printer.checkStatus(deviceConfig.kioskPrinter, STATUS_QUERY_TIMEOUT)
.then(() => this.printer.printCashboxReceipt(data, deviceConfig.kioskPrinter))
.catch((err) => {
console.log('[ERROR]: The kiosk printer is in an invalid state.', err)
throw err
})
}

Brain.prototype._verifyTransaction = function _verifyTransaction () {
if (!this.idVerify.inProgress()) return

Expand Down Expand Up @@ -4148,6 +4170,13 @@ Brain.prototype.cancelTransaction = function cancelTransaction (previousState) {
}
}

Brain.prototype.ratesScreen = function () {
const coins = _.map(it => it.cryptoCode, this.trader.coins)
const rates = _.reduce((acc, value) => Object.assign({ [value]: _.mapValues(it => it.toString(), this.trader.rates(value)) }, acc), {}, coins)

this._transitionState('rates', { allRates: rates, ratesFiat: this.trader.locale.fiatCode })
}

Brain.prototype.browser = function browser () {
return this.browserObj
}
Expand Down
3 changes: 2 additions & 1 deletion lib/ping.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,9 @@ const checkDownloadSpeed = (packages) => {
const mbps = (kbps / 1000).toFixed(2)
resolve({ bps, kbps, mbps })
})
})
}).on('error', e => reject(e))
}).catch(error => {
console.log('Failed to check download speed')
throw new Error(error)
})
}
Expand Down
93 changes: 93 additions & 0 deletions lib/printer/nippon.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const _ = require('lodash/fp')
const { SerialPort } = require('serialport')
const zplHelper = require('./zpl-helper')

const lineFeed = [0x0a]
const finalLineFeed = [0x1b, 0x64, 0x05]
Expand Down Expand Up @@ -166,6 +167,97 @@ const printReceipt = (data, { address }, receiptConfig) =>
})
)

const printCashboxReceipt = (data, { address }) =>
new Promise((resolve, reject) =>
openSerialPort(address, portOptions)
.then((port) => {
const cmd = []

// disable and enable to get rid of previous buffer
// useful because of possible comm failure
cmd.push(disable)
cmd.push(enable)

// set manual ejection mode
cmd.push(manualEjectionMode)

cmd.push('CASH COLLECTION RECEIPT')
cmd.push(lineFeed)
cmd.push(lineFeed)

if (data.batch) {
if (data.batch.created) {
cmd.push('Date and time: ')
cmd.push(data.batch.created)
cmd.push(lineFeed)
}

if (data.batch.id && data.batch.operationType) {
cmd.push(`Batch creation mode: automatic`)
cmd.push(`Batch ID: ${data.batch.id}`)
cmd.push(lineFeed)
} else {
cmd.push(`Batch creation mode: manual`)
cmd.push(lineFeed)
}

if (data.batch.deviceId) {
cmd.push(`Machine ID: ${data.batch.deviceId}`)
cmd.push(lineFeed)
}

if (data.batch.machineName) {
cmd.push(`Machine name: ${data.batch.machineName}`)
cmd.push(lineFeed)
}

if (data.batch.billCount) {
cmd.push(lineFeed)
cmd.push(`Bill count: ${data.batch.billCount}`)
cmd.push(lineFeed)
}

if (data.batch.fiatTotals) {
cmd.push(lineFeed)
cmd.push(`Total amount per fiat: `)
cmd.push(lineFeed)
cmd.push(`---------------------`)
cmd.push(lineFeed)
cmd.push(_.join(' | ', _.map(it => `${it}: ${data.batch.fiatTotals[it]}`, _.keys(data.batch.fiatTotals))))
cmd.push(lineFeed)
}

if (data.batch.billsByDenomination) {
cmd.push(lineFeed)
cmd.push(`Bills by denomination: `)
cmd.push(lineFeed)
cmd.push(`---------------------`)
cmd.push(lineFeed)
_.forEach(
it => {
cmd.push(`${it}: ${data.batch.billsByDenomination[it]}`)
cmd.push(lineFeed)
},
_.keys(data.batch.billsByDenomination)
)
cmd.push(lineFeed)
}
}

cmd.push(finalLineFeed)
cmd.push(fullCut)

cmd.push(presenterEjection)

port.write(Buffer.concat(cmd.map(Buffer.from)), err => {
if (err) reject(err)

port.close()
resolve()
})
})
)

const printWallet = (wallet, { address }, code) =>
new Promise((resolve, reject) =>
openSerialPort(address, portOptions)
Expand Down Expand Up @@ -217,5 +309,6 @@ const checkStatus = () =>
module.exports = {
printReceipt,
printWallet,
printCashboxReceipt,
checkStatus
}
83 changes: 83 additions & 0 deletions lib/printer/zebra.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,88 @@ const printReceipt = (data, { address }, receiptConfig) =>
})
)

const printCashboxReceipt = (data, printerCfg) =>
new Promise((resolve, reject) =>
openSerialPort(printerCfg, portOptions)
.then((port) => {
let cmd = zplHelper.start()
let yPosition = 250

cmd += zplHelper.header('CASH COLLECTION RECEIPT', yPosition)
yPosition += 80

if (data.batch) {
if (data.batch.created) {
cmd += zplHelper.subheader(`Date and time: ${data.batch.created}`, yPosition)
yPosition += Math.ceil(SPACER * 1.3)
}

if (data.batch.id && data.batch.operationType) {
cmd += zplHelper.text(`Batch creation mode: automatic`, yPosition)
yPosition += SPACER
cmd += zplHelper.text(`Batch ID: ${data.batch.id}`, yPosition)
} else {
cmd += zplHelper.text(`Batch creation mode: manual`, yPosition)
}
yPosition += Math.ceil(SPACER * 1.3)

if (data.batch.deviceId) {
cmd += zplHelper.text(`Machine ID: ${data.batch.deviceId}`, yPosition)
yPosition += SPACER
}

if (data.batch.machineName) {
cmd += zplHelper.text(`Machine name: ${data.batch.machineName}`, yPosition)
yPosition += SPACER
}

if (data.batch.billCount) {
yPosition += SPACER
cmd += zplHelper.text(`Bill count: ${data.batch.billCount}`, yPosition)
yPosition += SPACER
}

if (data.batch.fiatTotals) {
yPosition += SPACER
cmd += zplHelper.text(`Total amount per fiat`, yPosition)
yPosition += SPACER
cmd += zplHelper.text(`---------------------`, yPosition)
yPosition += SPACER
cmd += zplHelper.text(_.join(' | ', _.map(it => `${it}: ${data.batch.fiatTotals[it]}`, _.keys(data.batch.fiatTotals))), yPosition)
yPosition += SPACER
}

if (data.batch.billsByDenomination) {
yPosition += SPACER
cmd += zplHelper.text(`Bills by denomination`, yPosition)
yPosition += SPACER
cmd += zplHelper.text(`---------------------`, yPosition)
yPosition += SPACER
_.forEach(
it => {
cmd += zplHelper.text(`${it}: ${data.batch.billsByDenomination[it]}`, yPosition)
yPosition += SPACER
},
_.keys(data.batch.billsByDenomination)
)
yPosition += SPACER
}
}

cmd += zplHelper.end()

port.write(cmd, 'utf8', (err) => {
if (err) return reject(err)

port.close()
return resolve()
})
})
.catch((err) => {
reject(err)
})
)

const printWallet = (wallet, { address }, code) =>
new Promise((resolve, reject) =>
openSerialPort(address, portOptions)
Expand Down Expand Up @@ -292,5 +374,6 @@ function readStatusCode (statusCode) {
module.exports = {
printReceipt,
printWallet,
printCashboxReceipt,
checkStatus
}
Loading

0 comments on commit ce2fcf1

Please sign in to comment.