From ba72786dcb6affd3b6fee72621cc57e5457ffa9c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Oliveira?= Date: Thu, 17 Feb 2022 21:50:31 +0000 Subject: [PATCH] feat: support new advanced wallet settings --- lib/new-config-manager.js | 13 +++++++++--- lib/plugins/wallet/bitcoind/bitcoind.js | 10 +++++++-- lib/wallet.js | 10 +++++---- .../src/components/inputs/formik/Checkbox.js | 2 +- .../src/pages/Wallet/AdvancedWallet.js | 21 +++++-------------- new-lamassu-admin/src/pages/Wallet/helper.js | 2 +- new-lamassu-admin/src/utils/config.js | 1 + 7 files changed, 32 insertions(+), 27 deletions(-) diff --git a/lib/new-config-manager.js b/lib/new-config-manager.js index c8196495..4c05b540 100644 --- a/lib/new-config-manager.js +++ b/lib/new-config-manager.js @@ -2,6 +2,7 @@ const _ = require('lodash/fp') const { getCustomInfoRequests } = require('./new-admin/services/customInfoRequests') const namespaces = { + ADVANCED: 'advanced', WALLETS: 'wallets', OPERATOR_INFO: 'operatorInfo', NOTIFICATIONS: 'notifications', @@ -55,8 +56,14 @@ const getLocale = (deviceId, it) => { const getGlobalLocale = it => getLocale(null, it) const getWalletSettings = (key, it) => { - const result = _.compose(fromNamespace(key), fromNamespace(namespaces.WALLETS))(it) - return result + const filter = _.matches({ cryptoCurrency: key }) + + const getAdvancedSettings = it => { + const advancedSettings = fromNamespace(namespaces.ADVANCED)(it) + return _.omit(['overrides', 'cryptoCurrency', 'id'], _.assignAll([advancedSettings, ..._.filter(filter)(advancedSettings.overrides)])) + } + const walletsSettings = fromNamespace(namespaces.WALLETS)(it) + return _.assign(fromNamespace(key)(walletsSettings), getAdvancedSettings(walletsSettings)) } const getCashOut = (key, it) => _.compose(fromNamespace(key), fromNamespace(namespaces.CASH_OUT))(it) const getGlobalCashOut = fromNamespace(namespaces.CASH_OUT) @@ -133,7 +140,7 @@ const getTriggersAutomation = config => { }, {}, overrides) return _.assign(requirements, requirementsOverrides) - }) + }) } const splitGetFirst = _.compose(_.head, _.split('_')) diff --git a/lib/plugins/wallet/bitcoind/bitcoind.js b/lib/plugins/wallet/bitcoind/bitcoind.js index 0f61be64..87f7d717 100644 --- a/lib/plugins/wallet/bitcoind/bitcoind.js +++ b/lib/plugins/wallet/bitcoind/bitcoind.js @@ -11,6 +11,8 @@ const unitScale = cryptoRec.unitScale const rpcConfig = jsonRpc.rpcConfig(cryptoRec) +const SUPPORTS_BATCHING = true + function fetch (method, params) { return jsonRpc.fetch(rpcConfig, method, params) } @@ -63,7 +65,10 @@ function sendCoins (account, tx, settings, operatorId, feeMultiplier) { return checkCryptoCode(cryptoCode) .then(() => calculateFeeDiscount(feeMultiplier)) - .then(newFee => fetch('settxfee', [newFee])) + .then(newFee => { + console.log('** DEBUG MINERS FEE ** - Calculated fee discount: ', newFee) + return fetch('settxfee', [newFee]) + }) .then(() => fetch('sendtoaddress', [toAddress, coins])) .then((txId) => fetch('gettransaction', [txId])) .then((res) => _.pick(['fee', 'txid'], res)) @@ -186,5 +191,6 @@ module.exports = { fetchRBF, estimateFee, sendCoinsBatch, - checkBlockchainStatus + checkBlockchainStatus, + SUPPORTS_BATCHING } diff --git a/lib/wallet.js b/lib/wallet.js index e04aac19..b04b2b7b 100644 --- a/lib/wallet.js +++ b/lib/wallet.js @@ -3,7 +3,6 @@ const mem = require('mem') const hkdf = require('futoin-hkdf') const configManager = require('./new-config-manager') -const { loadLatestConfig } = require('./new-settings-loader') const pify = require('pify') const fs = pify(require('fs')) @@ -63,7 +62,8 @@ function _balance (settings, cryptoCode) { function sendCoins (settings, tx) { return fetchWallet(settings, tx.cryptoCode) .then(r => { - const feeMultiplier = settings[`wallets_${tx.cryptoCode}_feeMultiplier`] + const feeMultiplier = configManager.getWalletSettings(tx.cryptoCode, settings.config).feeMultiplier + console.log('** DEBUG MINERS FEE ** - Fee multiplier: ', feeMultiplier) return r.wallet.sendCoins(r.account, tx, settings, r.operatorId, feeMultiplier) .then(res => { mem.clear(module.exports.balance) @@ -81,7 +81,7 @@ function sendCoins (settings, tx) { function sendCoinsBatch (settings, txs, cryptoCode) { return fetchWallet(settings, cryptoCode) .then(r => { - const feeMultiplier = settings[`wallets_${cryptoCode}_feeMultiplier`] + const feeMultiplier = configManager.getWalletSettings(cryptoCode, settings.config).feeMultiplier return r.wallet.sendCoinsBatch(r.account, txs, cryptoCode, feeMultiplier) .then(res => { mem.clear(module.exports.balance) @@ -233,7 +233,9 @@ function isStrictAddress (settings, cryptoCode, toAddress) { } function supportsBatching (settings, cryptoCode) { - return Promise.resolve(!!configManager.getWalletSettings(cryptoCode, settings.config).allowTransactionBatching) + return fetchWallet(settings, cryptoCode).then(r => { + return Promise.resolve(!!r.wallet.supportsBatching && !!configManager.getWalletSettings(cryptoCode, settings.config).allowTransactionBatching) + }) } function checkBlockchainStatus (settings, cryptoCode) { diff --git a/new-lamassu-admin/src/components/inputs/formik/Checkbox.js b/new-lamassu-admin/src/components/inputs/formik/Checkbox.js index aa1768ad..5c184ab0 100644 --- a/new-lamassu-admin/src/components/inputs/formik/Checkbox.js +++ b/new-lamassu-admin/src/components/inputs/formik/Checkbox.js @@ -11,7 +11,7 @@ const CheckboxInput = memo( disabledMessage = '', ...props }) => { - const { name, onChange, value } = props.field + const { name, onChange, value = true } = props.field const settings = { enabled: enabled, diff --git a/new-lamassu-admin/src/pages/Wallet/AdvancedWallet.js b/new-lamassu-admin/src/pages/Wallet/AdvancedWallet.js index e93aee84..9bed8466 100644 --- a/new-lamassu-admin/src/pages/Wallet/AdvancedWallet.js +++ b/new-lamassu-admin/src/pages/Wallet/AdvancedWallet.js @@ -32,7 +32,7 @@ const GET_INFO = gql` ` const AdvancedWallet = () => { - const ADVANCED = 'advanced' + const ADVANCED = namespaces.ADVANCED const CRYPTOCURRENCY_KEY = 'cryptoCurrency' const SCREEN_KEY = namespaces.WALLETS const { data } = useQuery(GET_INFO) @@ -44,22 +44,15 @@ const AdvancedWallet = () => { refetchQueries: () => ['getData'] }) - const mapConfigKeys = R.curry((fn, obj) => - R.zipObj(R.map(fn, R.keys(obj)), R.values(obj)) - ) - const save = rawConfig => { const config = toNamespace(SCREEN_KEY)( - mapConfigKeys(it => `${ADVANCED}_` + it, rawConfig.wallets[0]) + toNamespace(ADVANCED)(rawConfig.wallets[0]) ) - return saveConfig({ variables: { config } }) } const saveOverrides = rawConfig => { - const config = toNamespace(SCREEN_KEY)( - mapConfigKeys(it => `${ADVANCED}_` + it, rawConfig) - ) + const config = toNamespace(SCREEN_KEY)(toNamespace(ADVANCED)(rawConfig)) return saveConfig({ variables: { config } }) } @@ -68,12 +61,8 @@ const AdvancedWallet = () => { const cryptoCurrencies = data?.cryptoCurrencies ?? [] - const AdvancedWalletSettings = mapConfigKeys( - it => R.tail(R.split('_', it)), - R.pickBy( - (val, key) => R.head(R.split('_', key)) === ADVANCED, - data?.config && fromNamespace(SCREEN_KEY)(data.config) - ) + const AdvancedWalletSettings = fromNamespace(ADVANCED)( + fromNamespace(SCREEN_KEY)(data?.config) ) const AdvancedWalletSettingsOverrides = AdvancedWalletSettings.overrides ?? [] diff --git a/new-lamassu-admin/src/pages/Wallet/helper.js b/new-lamassu-admin/src/pages/Wallet/helper.js index 510a4ac1..be360f5a 100644 --- a/new-lamassu-admin/src/pages/Wallet/helper.js +++ b/new-lamassu-admin/src/pages/Wallet/helper.js @@ -95,7 +95,7 @@ const getAdvancedWalletElements = () => { stripe: true, width: 250, view: (_, ite) => { - return ite.allowTransactionBatching ? 'Yes (Only BTC supports)' : `No` + return ite.allowTransactionBatching ? 'Yes' : `No` }, input: Checkbox }, diff --git a/new-lamassu-admin/src/utils/config.js b/new-lamassu-admin/src/utils/config.js index c50c2e1b..a2f78582 100644 --- a/new-lamassu-admin/src/utils/config.js +++ b/new-lamassu-admin/src/utils/config.js @@ -1,6 +1,7 @@ import * as R from 'ramda' const namespaces = { + ADVANCED: 'advanced', CASH_IN: 'cashIn', CASH_OUT: 'cashOut', WALLETS: 'wallets',