feat: support new advanced wallet settings

This commit is contained in:
José Oliveira 2022-02-17 21:50:31 +00:00
parent 4120d58a1b
commit ba72786dcb
7 changed files with 32 additions and 27 deletions

View file

@ -2,6 +2,7 @@ const _ = require('lodash/fp')
const { getCustomInfoRequests } = require('./new-admin/services/customInfoRequests') const { getCustomInfoRequests } = require('./new-admin/services/customInfoRequests')
const namespaces = { const namespaces = {
ADVANCED: 'advanced',
WALLETS: 'wallets', WALLETS: 'wallets',
OPERATOR_INFO: 'operatorInfo', OPERATOR_INFO: 'operatorInfo',
NOTIFICATIONS: 'notifications', NOTIFICATIONS: 'notifications',
@ -55,8 +56,14 @@ const getLocale = (deviceId, it) => {
const getGlobalLocale = it => getLocale(null, it) const getGlobalLocale = it => getLocale(null, it)
const getWalletSettings = (key, it) => { const getWalletSettings = (key, it) => {
const result = _.compose(fromNamespace(key), fromNamespace(namespaces.WALLETS))(it) const filter = _.matches({ cryptoCurrency: key })
return result
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 getCashOut = (key, it) => _.compose(fromNamespace(key), fromNamespace(namespaces.CASH_OUT))(it)
const getGlobalCashOut = fromNamespace(namespaces.CASH_OUT) const getGlobalCashOut = fromNamespace(namespaces.CASH_OUT)
@ -133,7 +140,7 @@ const getTriggersAutomation = config => {
}, {}, overrides) }, {}, overrides)
return _.assign(requirements, requirementsOverrides) return _.assign(requirements, requirementsOverrides)
}) })
} }
const splitGetFirst = _.compose(_.head, _.split('_')) const splitGetFirst = _.compose(_.head, _.split('_'))

View file

@ -11,6 +11,8 @@ const unitScale = cryptoRec.unitScale
const rpcConfig = jsonRpc.rpcConfig(cryptoRec) const rpcConfig = jsonRpc.rpcConfig(cryptoRec)
const SUPPORTS_BATCHING = true
function fetch (method, params) { function fetch (method, params) {
return jsonRpc.fetch(rpcConfig, method, params) return jsonRpc.fetch(rpcConfig, method, params)
} }
@ -63,7 +65,10 @@ function sendCoins (account, tx, settings, operatorId, feeMultiplier) {
return checkCryptoCode(cryptoCode) return checkCryptoCode(cryptoCode)
.then(() => calculateFeeDiscount(feeMultiplier)) .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(() => fetch('sendtoaddress', [toAddress, coins]))
.then((txId) => fetch('gettransaction', [txId])) .then((txId) => fetch('gettransaction', [txId]))
.then((res) => _.pick(['fee', 'txid'], res)) .then((res) => _.pick(['fee', 'txid'], res))
@ -186,5 +191,6 @@ module.exports = {
fetchRBF, fetchRBF,
estimateFee, estimateFee,
sendCoinsBatch, sendCoinsBatch,
checkBlockchainStatus checkBlockchainStatus,
SUPPORTS_BATCHING
} }

View file

@ -3,7 +3,6 @@ const mem = require('mem')
const hkdf = require('futoin-hkdf') const hkdf = require('futoin-hkdf')
const configManager = require('./new-config-manager') const configManager = require('./new-config-manager')
const { loadLatestConfig } = require('./new-settings-loader')
const pify = require('pify') const pify = require('pify')
const fs = pify(require('fs')) const fs = pify(require('fs'))
@ -63,7 +62,8 @@ function _balance (settings, cryptoCode) {
function sendCoins (settings, tx) { function sendCoins (settings, tx) {
return fetchWallet(settings, tx.cryptoCode) return fetchWallet(settings, tx.cryptoCode)
.then(r => { .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) return r.wallet.sendCoins(r.account, tx, settings, r.operatorId, feeMultiplier)
.then(res => { .then(res => {
mem.clear(module.exports.balance) mem.clear(module.exports.balance)
@ -81,7 +81,7 @@ function sendCoins (settings, tx) {
function sendCoinsBatch (settings, txs, cryptoCode) { function sendCoinsBatch (settings, txs, cryptoCode) {
return fetchWallet(settings, cryptoCode) return fetchWallet(settings, cryptoCode)
.then(r => { .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) return r.wallet.sendCoinsBatch(r.account, txs, cryptoCode, feeMultiplier)
.then(res => { .then(res => {
mem.clear(module.exports.balance) mem.clear(module.exports.balance)
@ -233,7 +233,9 @@ function isStrictAddress (settings, cryptoCode, toAddress) {
} }
function supportsBatching (settings, cryptoCode) { 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) { function checkBlockchainStatus (settings, cryptoCode) {

View file

@ -11,7 +11,7 @@ const CheckboxInput = memo(
disabledMessage = '', disabledMessage = '',
...props ...props
}) => { }) => {
const { name, onChange, value } = props.field const { name, onChange, value = true } = props.field
const settings = { const settings = {
enabled: enabled, enabled: enabled,

View file

@ -32,7 +32,7 @@ const GET_INFO = gql`
` `
const AdvancedWallet = () => { const AdvancedWallet = () => {
const ADVANCED = 'advanced' const ADVANCED = namespaces.ADVANCED
const CRYPTOCURRENCY_KEY = 'cryptoCurrency' const CRYPTOCURRENCY_KEY = 'cryptoCurrency'
const SCREEN_KEY = namespaces.WALLETS const SCREEN_KEY = namespaces.WALLETS
const { data } = useQuery(GET_INFO) const { data } = useQuery(GET_INFO)
@ -44,22 +44,15 @@ const AdvancedWallet = () => {
refetchQueries: () => ['getData'] refetchQueries: () => ['getData']
}) })
const mapConfigKeys = R.curry((fn, obj) =>
R.zipObj(R.map(fn, R.keys(obj)), R.values(obj))
)
const save = rawConfig => { const save = rawConfig => {
const config = toNamespace(SCREEN_KEY)( const config = toNamespace(SCREEN_KEY)(
mapConfigKeys(it => `${ADVANCED}_` + it, rawConfig.wallets[0]) toNamespace(ADVANCED)(rawConfig.wallets[0])
) )
return saveConfig({ variables: { config } }) return saveConfig({ variables: { config } })
} }
const saveOverrides = rawConfig => { const saveOverrides = rawConfig => {
const config = toNamespace(SCREEN_KEY)( const config = toNamespace(SCREEN_KEY)(toNamespace(ADVANCED)(rawConfig))
mapConfigKeys(it => `${ADVANCED}_` + it, rawConfig)
)
return saveConfig({ variables: { config } }) return saveConfig({ variables: { config } })
} }
@ -68,12 +61,8 @@ const AdvancedWallet = () => {
const cryptoCurrencies = data?.cryptoCurrencies ?? [] const cryptoCurrencies = data?.cryptoCurrencies ?? []
const AdvancedWalletSettings = mapConfigKeys( const AdvancedWalletSettings = fromNamespace(ADVANCED)(
it => R.tail(R.split('_', it)), fromNamespace(SCREEN_KEY)(data?.config)
R.pickBy(
(val, key) => R.head(R.split('_', key)) === ADVANCED,
data?.config && fromNamespace(SCREEN_KEY)(data.config)
)
) )
const AdvancedWalletSettingsOverrides = AdvancedWalletSettings.overrides ?? [] const AdvancedWalletSettingsOverrides = AdvancedWalletSettings.overrides ?? []

View file

@ -95,7 +95,7 @@ const getAdvancedWalletElements = () => {
stripe: true, stripe: true,
width: 250, width: 250,
view: (_, ite) => { view: (_, ite) => {
return ite.allowTransactionBatching ? 'Yes (Only BTC supports)' : `No` return ite.allowTransactionBatching ? 'Yes' : `No`
}, },
input: Checkbox input: Checkbox
}, },

View file

@ -1,6 +1,7 @@
import * as R from 'ramda' import * as R from 'ramda'
const namespaces = { const namespaces = {
ADVANCED: 'advanced',
CASH_IN: 'cashIn', CASH_IN: 'cashIn',
CASH_OUT: 'cashOut', CASH_OUT: 'cashOut',
WALLETS: 'wallets', WALLETS: 'wallets',