Merge pull request #1113 from josepfo/fix/fee-priority-selector-up-to-spec
feat: advanced wallet settings up to spec
This commit is contained in:
commit
6f0c735be8
11 changed files with 263 additions and 153 deletions
|
|
@ -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',
|
||||
|
|
@ -54,7 +55,16 @@ const getLocale = (deviceId, it) => {
|
|||
|
||||
const getGlobalLocale = it => getLocale(null, it)
|
||||
|
||||
const getWalletSettings = (key, it) => _.compose(fromNamespace(key), fromNamespace(namespaces.WALLETS))(it)
|
||||
const getWalletSettings = (key, it) => {
|
||||
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)
|
||||
const getOperatorInfo = fromNamespace(namespaces.OPERATOR_INFO)
|
||||
|
|
@ -130,7 +140,7 @@ const getTriggersAutomation = config => {
|
|||
}, {}, overrides)
|
||||
|
||||
return _.assign(requirements, requirementsOverrides)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
const splitGetFirst = _.compose(_.head, _.split('_'))
|
||||
|
|
|
|||
|
|
@ -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 => {
|
||||
logger.info('** 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))
|
||||
|
|
@ -82,7 +87,10 @@ function sendCoins (account, tx, settings, operatorId, feeMultiplier) {
|
|||
function sendCoinsBatch (account, txs, cryptoCode, feeMultiplier) {
|
||||
return checkCryptoCode(cryptoCode)
|
||||
.then(() => calculateFeeDiscount(feeMultiplier))
|
||||
.then(newFee => fetch('settxfee', [newFee]))
|
||||
.then(newFee => {
|
||||
logger.info('** DEBUG MINERS FEE ** - Calculated fee discount: ', newFee)
|
||||
return fetch('settxfee', [newFee])
|
||||
})
|
||||
.then(() => {
|
||||
const txAddressAmountPairs = _.map(tx => [tx.toAddress, BN(tx.cryptoAtoms).shiftedBy(-unitScale).toFixed(8)], txs)
|
||||
return _.fromPairs(txAddressAmountPairs)
|
||||
|
|
@ -186,5 +194,6 @@ module.exports = {
|
|||
fetchRBF,
|
||||
estimateFee,
|
||||
sendCoinsBatch,
|
||||
checkBlockchainStatus
|
||||
checkBlockchainStatus,
|
||||
SUPPORTS_BATCHING
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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.SUPPORTS_BATCHING && !!configManager.getWalletSettings(cryptoCode, settings.config).allowTransactionBatching)
|
||||
})
|
||||
}
|
||||
|
||||
function checkBlockchainStatus (settings, cryptoCode) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue