Feat: back end support for per coin 0-conf limit

This commit is contained in:
csrapr 2021-04-08 18:41:56 +01:00 committed by Josh Harvey
parent 5da28bc830
commit ac38a40b6c
9 changed files with 32 additions and 21 deletions

View file

@ -52,6 +52,12 @@ const settings = {
wallets_BCH_wallet: 'mock-wallet',
wallets_BCH_exchange: 'mock-exchange',
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_bottom: 20,
cashOut_7e531a2666987aa27b9917ca17df7998f72771c57fdb21c90bc033999edd17e4_top: 5,

View file

@ -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
const cashOutConfig = configManager.getCashOut(tx.deviceId, settings.config)
const zeroConfLimit = cashOutConfig.zeroConfLimit
const walletSettings = configManager.getWalletSettings(tx.cryptoCode, settings.config)
const zeroConfLimit = walletSettings.zeroConfLimit || 0
const zeroConf = isCashOut && tx.fiat.lte(zeroConfLimit)
const notificationsEnabled = notifSettings.sms.transactions || notifSettings.email.transactions
const customerPromise = tx.customerId ? customers.getById(tx.customerId) : Promise.resolve({})

View file

@ -283,12 +283,12 @@ test('calls sendRedemptionMessage if !zeroConf and rec.isRedemption', async () =
const loadLatest = jest.spyOn(settingsLoader, 'loadLatest')
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
jest.spyOn(smsFuncs, 'sendMessage').mockImplementation((_, rec) => rec)
getCashOut.mockReturnValue({ zeroConfLimit: -Infinity })
getWalletSettings.mockReturnValue({ zeroConfLimit: -Infinity })
loadLatest.mockReturnValue(Promise.resolve({}))
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 () => {
const configManager = require('../../new-config-manager')
const settingsLoader = require('../../new-settings-loader')
const machineLoader = require('../../machine-loader')
const queries = require('../queries')
const loadLatest = jest.spyOn(settingsLoader, 'loadLatest')
const getGlobalNotifications = jest.spyOn(configManager, 'getGlobalNotifications')
const getCashOut = jest.spyOn(configManager, 'getCashOut')
const getMachineName = jest.spyOn(machineLoader, 'getMachineName')
const getWalletSettings = jest.spyOn(configManager, 'getWalletSettings')
const getMachineName = jest.spyOn(queries, 'getMachineName')
const buildTransactionMessage = jest.spyOn(utils, 'buildTransactionMessage')
// sendMessage on emailFuncs isn't called because it is disabled in getGlobalNotifications.mockReturnValue
jest.spyOn(smsFuncs, 'sendMessage').mockImplementation((_, rec) => ({ prop: rec }))
buildTransactionMessage.mockImplementation(() => ['mock message', false])
getMachineName.mockReturnValue('mockMachineName')
getCashOut.mockReturnValue({ zeroConfLimit: -Infinity })
getMachineName.mockResolvedValue('mockMachineName')
getWalletSettings.mockReturnValue({ zeroConfLimit: -Infinity })
loadLatest.mockReturnValue(Promise.resolve({}))
getGlobalNotifications.mockReturnValue({ ...notifSettings, sms: { active: true, errors: true, transactions: true }, notificationCenter: { active: true } })

View file

@ -101,8 +101,8 @@ function plugins (settings, deviceId) {
}
function isZeroConf (tx) {
const cashOutConfig = configManager.getCashOut(deviceId, settings.config)
const zeroConfLimit = cashOutConfig.zeroConfLimit
const walletSettings = configManager.getWalletSettings(tx.cryptoCode, settings.config)
const zeroConfLimit = walletSettings.zeroConfLimit || 0
return tx.fiat.lte(zeroConfLimit)
}

View file

@ -23,6 +23,12 @@ const createTerms = terms => (terms.active && terms.text) ? ({
cancel: terms.cancelButtonText
}) : null
const buildZeroConfLimits = (cryptoCodes, config) => {
const zeroConfLimits = {}
_.forEach(cryptoCode => { zeroConfLimits[cryptoCode] = configManager.getWalletSettings(cryptoCode, config).zeroConfLimit }, cryptoCodes)
return zeroConfLimits
}
function poll (req, res, next) {
const machineVersion = req.query.version
const machineModel = req.query.model
@ -32,6 +38,7 @@ function poll (req, res, next) {
const pid = req.query.pid
const settings = req.settings
const localeConfig = configManager.getLocale(deviceId, settings.config)
const zeroConfLimits = buildZeroConfLimits(localeConfig.cryptoCurrencies, settings.config)
const pi = plugins(settings, deviceId)
const hasLightning = checkHasLightning(settings)
@ -70,7 +77,7 @@ function poll (req, res, next) {
receiptPrintingActive: receipt.active,
cassettes,
twoWayMode: cashOutConfig.active,
zeroConfLimit: cashOutConfig.zeroConfLimit,
zeroConfLimits,
reboot,
shutdown,
restartServices,

View file

@ -131,11 +131,10 @@ function getWalletStatus (settings, tx) {
}
function authorizeZeroConf (settings, tx, machineId) {
const plugin = configManager.getWalletSettings(tx.cryptoCode, settings.config).zeroConf
const isBitcoindAvailable =
configManager.getWalletSettings(tx.cryptoCode, settings.config).wallet === 'bitcoind'
const cashOutConfig = configManager.getCashOut(machineId, settings.config)
const zeroConfLimit = cashOutConfig.zeroConfLimit
const walletSettings = configManager.getWalletSettings(tx.cryptoCode, settings.config)
const isBitcoindAvailable = walletSettings.wallet === 'bitcoind'
const plugin = walletSettings.zeroConf
const zeroConfLimit = walletSettings.zeroConfLimit || 0
if (!_.isObject(tx.fiat)) {
return Promise.reject(new Error('tx.fiat is undefined!'))

View file

@ -174,7 +174,7 @@ const WizardStep = ({
]}
validationSchema={zeroConfLimitSchema}
buttonLabel={label}
value={0}
value={null}
/>
</>
)}

View file

@ -38,7 +38,7 @@ const ZeroConfLimit = ({ data: currentData, addData }) => {
]}
validationSchema={zeroConfLimitSchema}
buttonLabel={'Continue'}
value={0}
value={null}
save={it => submit(Number(it.zeroConfLimit))}
/>
</div>

View file

@ -115,7 +115,7 @@
"scripts": {
"start": "node bin/lamassu-server",
"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",
"server": "nodemon bin/lamassu-server --mockSms",
"admin-server": "nodemon bin/lamassu-admin-server --dev",