feat: support new advanced wallet settings
This commit is contained in:
parent
4120d58a1b
commit
ba72786dcb
7 changed files with 32 additions and 27 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',
|
||||
|
|
@ -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('_'))
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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) {
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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 ?? []
|
||||
|
|
|
|||
|
|
@ -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
|
||||
},
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
import * as R from 'ramda'
|
||||
|
||||
const namespaces = {
|
||||
ADVANCED: 'advanced',
|
||||
CASH_IN: 'cashIn',
|
||||
CASH_OUT: 'cashOut',
|
||||
WALLETS: 'wallets',
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue