Feat: back end support for per coin 0-conf limit
This commit is contained in:
parent
5da28bc830
commit
ac38a40b6c
9 changed files with 32 additions and 21 deletions
|
|
@ -52,6 +52,12 @@ const settings = {
|
||||||
wallets_BCH_wallet: 'mock-wallet',
|
wallets_BCH_wallet: 'mock-wallet',
|
||||||
wallets_BCH_exchange: 'mock-exchange',
|
wallets_BCH_exchange: 'mock-exchange',
|
||||||
wallets_BCH_zeroConf: 'mock-zero-conf',
|
wallets_BCH_zeroConf: 'mock-zero-conf',
|
||||||
|
wallets_BTC_zeroConfLimit: 50,
|
||||||
|
wallets_ETH_zeroConfLimit: 50,
|
||||||
|
wallets_LTC_zeroConfLimit: 50,
|
||||||
|
wallets_BCH_zeroConfLimit: 50,
|
||||||
|
wallets_DASH_zeroConfLimit: 50,
|
||||||
|
wallets_ZEC_zeroConfLimit: 50,
|
||||||
cashOut_7e531a2666987aa27b9917ca17df7998f72771c57fdb21c90bc033999edd17e4_zeroConfLimit: 50,
|
cashOut_7e531a2666987aa27b9917ca17df7998f72771c57fdb21c90bc033999edd17e4_zeroConfLimit: 50,
|
||||||
cashOut_7e531a2666987aa27b9917ca17df7998f72771c57fdb21c90bc033999edd17e4_bottom: 20,
|
cashOut_7e531a2666987aa27b9917ca17df7998f72771c57fdb21c90bc033999edd17e4_bottom: 20,
|
||||||
cashOut_7e531a2666987aa27b9917ca17df7998f72771c57fdb21c90bc033999edd17e4_top: 5,
|
cashOut_7e531a2666987aa27b9917ca17df7998f72771c57fdb21c90bc033999edd17e4_top: 5,
|
||||||
|
|
|
||||||
|
|
@ -147,8 +147,8 @@ function transactionNotify (tx, rec) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// alert through sms or email any transaction or high value transaction, if SMS || email alerts are enabled
|
// alert through sms or email any transaction or high value transaction, if SMS || email alerts are enabled
|
||||||
const cashOutConfig = configManager.getCashOut(tx.deviceId, settings.config)
|
const walletSettings = configManager.getWalletSettings(tx.cryptoCode, settings.config)
|
||||||
const zeroConfLimit = cashOutConfig.zeroConfLimit
|
const zeroConfLimit = walletSettings.zeroConfLimit || 0
|
||||||
const zeroConf = isCashOut && tx.fiat.lte(zeroConfLimit)
|
const zeroConf = isCashOut && tx.fiat.lte(zeroConfLimit)
|
||||||
const notificationsEnabled = notifSettings.sms.transactions || notifSettings.email.transactions
|
const notificationsEnabled = notifSettings.sms.transactions || notifSettings.email.transactions
|
||||||
const customerPromise = tx.customerId ? customers.getById(tx.customerId) : Promise.resolve({})
|
const customerPromise = tx.customerId ? customers.getById(tx.customerId) : Promise.resolve({})
|
||||||
|
|
|
||||||
|
|
@ -283,12 +283,12 @@ test('calls sendRedemptionMessage if !zeroConf and rec.isRedemption', async () =
|
||||||
|
|
||||||
const loadLatest = jest.spyOn(settingsLoader, 'loadLatest')
|
const loadLatest = jest.spyOn(settingsLoader, 'loadLatest')
|
||||||
const getGlobalNotifications = jest.spyOn(configManager, 'getGlobalNotifications')
|
const getGlobalNotifications = jest.spyOn(configManager, 'getGlobalNotifications')
|
||||||
const getCashOut = jest.spyOn(configManager, 'getCashOut')
|
const getWalletSettings = jest.spyOn(configManager, 'getWalletSettings')
|
||||||
|
|
||||||
// sendRedemptionMessage will cause this func to be called
|
// sendRedemptionMessage will cause this func to be called
|
||||||
jest.spyOn(smsFuncs, 'sendMessage').mockImplementation((_, rec) => rec)
|
jest.spyOn(smsFuncs, 'sendMessage').mockImplementation((_, rec) => rec)
|
||||||
|
|
||||||
getCashOut.mockReturnValue({ zeroConfLimit: -Infinity })
|
getWalletSettings.mockReturnValue({ zeroConfLimit: -Infinity })
|
||||||
loadLatest.mockReturnValue(Promise.resolve({}))
|
loadLatest.mockReturnValue(Promise.resolve({}))
|
||||||
getGlobalNotifications.mockReturnValue({ ...notifSettings, sms: { active: true, errors: true, transactions: true }, notificationCenter: { active: true } })
|
getGlobalNotifications.mockReturnValue({ ...notifSettings, sms: { active: true, errors: true, transactions: true }, notificationCenter: { active: true } })
|
||||||
|
|
||||||
|
|
@ -309,20 +309,19 @@ test('calls sendRedemptionMessage if !zeroConf and rec.isRedemption', async () =
|
||||||
test('calls sendTransactionMessage if !zeroConf and !rec.isRedemption', async () => {
|
test('calls sendTransactionMessage if !zeroConf and !rec.isRedemption', async () => {
|
||||||
const configManager = require('../../new-config-manager')
|
const configManager = require('../../new-config-manager')
|
||||||
const settingsLoader = require('../../new-settings-loader')
|
const settingsLoader = require('../../new-settings-loader')
|
||||||
const machineLoader = require('../../machine-loader')
|
const queries = require('../queries')
|
||||||
|
|
||||||
const loadLatest = jest.spyOn(settingsLoader, 'loadLatest')
|
const loadLatest = jest.spyOn(settingsLoader, 'loadLatest')
|
||||||
const getGlobalNotifications = jest.spyOn(configManager, 'getGlobalNotifications')
|
const getGlobalNotifications = jest.spyOn(configManager, 'getGlobalNotifications')
|
||||||
const getCashOut = jest.spyOn(configManager, 'getCashOut')
|
const getWalletSettings = jest.spyOn(configManager, 'getWalletSettings')
|
||||||
const getMachineName = jest.spyOn(machineLoader, 'getMachineName')
|
const getMachineName = jest.spyOn(queries, 'getMachineName')
|
||||||
const buildTransactionMessage = jest.spyOn(utils, 'buildTransactionMessage')
|
const buildTransactionMessage = jest.spyOn(utils, 'buildTransactionMessage')
|
||||||
|
|
||||||
// sendMessage on emailFuncs isn't called because it is disabled in getGlobalNotifications.mockReturnValue
|
// sendMessage on emailFuncs isn't called because it is disabled in getGlobalNotifications.mockReturnValue
|
||||||
jest.spyOn(smsFuncs, 'sendMessage').mockImplementation((_, rec) => ({ prop: rec }))
|
jest.spyOn(smsFuncs, 'sendMessage').mockImplementation((_, rec) => ({ prop: rec }))
|
||||||
buildTransactionMessage.mockImplementation(() => ['mock message', false])
|
buildTransactionMessage.mockImplementation(() => ['mock message', false])
|
||||||
|
|
||||||
getMachineName.mockReturnValue('mockMachineName')
|
getMachineName.mockResolvedValue('mockMachineName')
|
||||||
getCashOut.mockReturnValue({ zeroConfLimit: -Infinity })
|
getWalletSettings.mockReturnValue({ zeroConfLimit: -Infinity })
|
||||||
loadLatest.mockReturnValue(Promise.resolve({}))
|
loadLatest.mockReturnValue(Promise.resolve({}))
|
||||||
getGlobalNotifications.mockReturnValue({ ...notifSettings, sms: { active: true, errors: true, transactions: true }, notificationCenter: { active: true } })
|
getGlobalNotifications.mockReturnValue({ ...notifSettings, sms: { active: true, errors: true, transactions: true }, notificationCenter: { active: true } })
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -101,8 +101,8 @@ function plugins (settings, deviceId) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function isZeroConf (tx) {
|
function isZeroConf (tx) {
|
||||||
const cashOutConfig = configManager.getCashOut(deviceId, settings.config)
|
const walletSettings = configManager.getWalletSettings(tx.cryptoCode, settings.config)
|
||||||
const zeroConfLimit = cashOutConfig.zeroConfLimit
|
const zeroConfLimit = walletSettings.zeroConfLimit || 0
|
||||||
return tx.fiat.lte(zeroConfLimit)
|
return tx.fiat.lte(zeroConfLimit)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -23,6 +23,12 @@ const createTerms = terms => (terms.active && terms.text) ? ({
|
||||||
cancel: terms.cancelButtonText
|
cancel: terms.cancelButtonText
|
||||||
}) : null
|
}) : null
|
||||||
|
|
||||||
|
const buildZeroConfLimits = (cryptoCodes, config) => {
|
||||||
|
const zeroConfLimits = {}
|
||||||
|
_.forEach(cryptoCode => { zeroConfLimits[cryptoCode] = configManager.getWalletSettings(cryptoCode, config).zeroConfLimit }, cryptoCodes)
|
||||||
|
return zeroConfLimits
|
||||||
|
}
|
||||||
|
|
||||||
function poll (req, res, next) {
|
function poll (req, res, next) {
|
||||||
const machineVersion = req.query.version
|
const machineVersion = req.query.version
|
||||||
const machineModel = req.query.model
|
const machineModel = req.query.model
|
||||||
|
|
@ -32,6 +38,7 @@ function poll (req, res, next) {
|
||||||
const pid = req.query.pid
|
const pid = req.query.pid
|
||||||
const settings = req.settings
|
const settings = req.settings
|
||||||
const localeConfig = configManager.getLocale(deviceId, settings.config)
|
const localeConfig = configManager.getLocale(deviceId, settings.config)
|
||||||
|
const zeroConfLimits = buildZeroConfLimits(localeConfig.cryptoCurrencies, settings.config)
|
||||||
const pi = plugins(settings, deviceId)
|
const pi = plugins(settings, deviceId)
|
||||||
const hasLightning = checkHasLightning(settings)
|
const hasLightning = checkHasLightning(settings)
|
||||||
|
|
||||||
|
|
@ -70,7 +77,7 @@ function poll (req, res, next) {
|
||||||
receiptPrintingActive: receipt.active,
|
receiptPrintingActive: receipt.active,
|
||||||
cassettes,
|
cassettes,
|
||||||
twoWayMode: cashOutConfig.active,
|
twoWayMode: cashOutConfig.active,
|
||||||
zeroConfLimit: cashOutConfig.zeroConfLimit,
|
zeroConfLimits,
|
||||||
reboot,
|
reboot,
|
||||||
shutdown,
|
shutdown,
|
||||||
restartServices,
|
restartServices,
|
||||||
|
|
|
||||||
|
|
@ -131,11 +131,10 @@ function getWalletStatus (settings, tx) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function authorizeZeroConf (settings, tx, machineId) {
|
function authorizeZeroConf (settings, tx, machineId) {
|
||||||
const plugin = configManager.getWalletSettings(tx.cryptoCode, settings.config).zeroConf
|
const walletSettings = configManager.getWalletSettings(tx.cryptoCode, settings.config)
|
||||||
const isBitcoindAvailable =
|
const isBitcoindAvailable = walletSettings.wallet === 'bitcoind'
|
||||||
configManager.getWalletSettings(tx.cryptoCode, settings.config).wallet === 'bitcoind'
|
const plugin = walletSettings.zeroConf
|
||||||
const cashOutConfig = configManager.getCashOut(machineId, settings.config)
|
const zeroConfLimit = walletSettings.zeroConfLimit || 0
|
||||||
const zeroConfLimit = cashOutConfig.zeroConfLimit
|
|
||||||
|
|
||||||
if (!_.isObject(tx.fiat)) {
|
if (!_.isObject(tx.fiat)) {
|
||||||
return Promise.reject(new Error('tx.fiat is undefined!'))
|
return Promise.reject(new Error('tx.fiat is undefined!'))
|
||||||
|
|
|
||||||
|
|
@ -174,7 +174,7 @@ const WizardStep = ({
|
||||||
]}
|
]}
|
||||||
validationSchema={zeroConfLimitSchema}
|
validationSchema={zeroConfLimitSchema}
|
||||||
buttonLabel={label}
|
buttonLabel={label}
|
||||||
value={0}
|
value={null}
|
||||||
/>
|
/>
|
||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
|
|
|
||||||
|
|
@ -38,7 +38,7 @@ const ZeroConfLimit = ({ data: currentData, addData }) => {
|
||||||
]}
|
]}
|
||||||
validationSchema={zeroConfLimitSchema}
|
validationSchema={zeroConfLimitSchema}
|
||||||
buttonLabel={'Continue'}
|
buttonLabel={'Continue'}
|
||||||
value={0}
|
value={null}
|
||||||
save={it => submit(Number(it.zeroConfLimit))}
|
save={it => submit(Number(it.zeroConfLimit))}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
|
|
@ -115,7 +115,7 @@
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"start": "node bin/lamassu-server",
|
"start": "node bin/lamassu-server",
|
||||||
"test": "mocha --recursive tests",
|
"test": "mocha --recursive tests",
|
||||||
"jtest": "jest",
|
"jtest": "jest --detectOpenHandles",
|
||||||
"build-admin": "npm run build-admin:css && npm run build-admin:main && npm run build-admin:lamassu",
|
"build-admin": "npm run build-admin:css && npm run build-admin:main && npm run build-admin:lamassu",
|
||||||
"server": "nodemon bin/lamassu-server --mockSms",
|
"server": "nodemon bin/lamassu-server --mockSms",
|
||||||
"admin-server": "nodemon bin/lamassu-admin-server --dev",
|
"admin-server": "nodemon bin/lamassu-admin-server --dev",
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue