diff --git a/lib/coinatmradar/test/coinatmradar.test.js b/lib/coinatmradar/test/coinatmradar.test.js index 732a1ac0..8a48f82a 100644 --- a/lib/coinatmradar/test/coinatmradar.test.js +++ b/lib/coinatmradar/test/coinatmradar.test.js @@ -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, diff --git a/lib/notifier/index.js b/lib/notifier/index.js index 65f22192..7c3841fb 100644 --- a/lib/notifier/index.js +++ b/lib/notifier/index.js @@ -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({}) diff --git a/lib/notifier/test/notifier.test.js b/lib/notifier/test/notifier.test.js index 797a1e77..c4189733 100644 --- a/lib/notifier/test/notifier.test.js +++ b/lib/notifier/test/notifier.test.js @@ -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 } }) diff --git a/lib/plugins.js b/lib/plugins.js index b6be4363..78730cf7 100644 --- a/lib/plugins.js +++ b/lib/plugins.js @@ -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) } diff --git a/lib/routes/pollingRoutes.js b/lib/routes/pollingRoutes.js index e24df87d..47932a16 100644 --- a/lib/routes/pollingRoutes.js +++ b/lib/routes/pollingRoutes.js @@ -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, diff --git a/lib/wallet.js b/lib/wallet.js index fe122d1d..f454e1a5 100644 --- a/lib/wallet.js +++ b/lib/wallet.js @@ -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!')) diff --git a/new-lamassu-admin/src/pages/Wallet/WizardStep.js b/new-lamassu-admin/src/pages/Wallet/WizardStep.js index 8ad2c016..475b40b8 100644 --- a/new-lamassu-admin/src/pages/Wallet/WizardStep.js +++ b/new-lamassu-admin/src/pages/Wallet/WizardStep.js @@ -174,7 +174,7 @@ const WizardStep = ({ ]} validationSchema={zeroConfLimitSchema} buttonLabel={label} - value={0} + value={null} /> )} diff --git a/new-lamassu-admin/src/pages/Wizard/components/Wallet/ZeroConfLimit.js b/new-lamassu-admin/src/pages/Wizard/components/Wallet/ZeroConfLimit.js index 2d8c62b5..b9c705d3 100644 --- a/new-lamassu-admin/src/pages/Wizard/components/Wallet/ZeroConfLimit.js +++ b/new-lamassu-admin/src/pages/Wizard/components/Wallet/ZeroConfLimit.js @@ -38,7 +38,7 @@ const ZeroConfLimit = ({ data: currentData, addData }) => { ]} validationSchema={zeroConfLimitSchema} buttonLabel={'Continue'} - value={0} + value={null} save={it => submit(Number(it.zeroConfLimit))} /> diff --git a/package.json b/package.json index e05355b9..b9ad1196 100644 --- a/package.json +++ b/package.json @@ -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",