feat: add transaction batching option to advanced wallet settings

This commit is contained in:
Sérgio Salgado 2022-02-03 17:11:48 +00:00
parent 2da14d64b3
commit 68d9d95dfa
12 changed files with 25 additions and 74 deletions

View file

@ -8,8 +8,6 @@ const { utils: coinUtils } = require('lamassu-coins')
const cryptoRec = coinUtils.getCryptoCurrency('BCH')
const unitScale = cryptoRec.unitScale
const SUPPORTS_BATCHING = false
const rpcConfig = jsonRpc.rpcConfig(cryptoRec)
function fetch (method, params) {
@ -118,11 +116,6 @@ function cryptoNetwork (account, cryptoCode, settings, operatorId) {
.then(() => parseInt(rpcConfig.port, 10) === 18332 ? 'test' : 'main')
}
function supportsBatching (cryptoCode) {
return checkCryptoCode(cryptoCode)
.then(() => SUPPORTS_BATCHING)
}
function checkBlockchainStatus (cryptoCode) {
return checkCryptoCode(cryptoCode)
.then(() => fetch('getblockchaininfo'))
@ -136,6 +129,5 @@ module.exports = {
getStatus,
newFunding,
cryptoNetwork,
supportsBatching,
checkBlockchainStatus
}

View file

@ -9,7 +9,6 @@ const { utils: coinUtils } = require('lamassu-coins')
const cryptoRec = coinUtils.getCryptoCurrency('BTC')
const unitScale = cryptoRec.unitScale
const SUPPORTS_BATCHING = true
const rpcConfig = jsonRpc.rpcConfig(cryptoRec)
function fetch (method, params) {
@ -171,11 +170,6 @@ function fetchRBF (txId) {
})
}
function supportsBatching (cryptoCode) {
return checkCryptoCode(cryptoCode)
.then(() => SUPPORTS_BATCHING)
}
function checkBlockchainStatus (cryptoCode) {
return checkCryptoCode(cryptoCode)
.then(() => fetch('getblockchaininfo'))
@ -192,6 +186,5 @@ module.exports = {
fetchRBF,
estimateFee,
sendCoinsBatch,
supportsBatching,
checkBlockchainStatus
}

View file

@ -14,8 +14,6 @@ const NAME = 'BitGo'
const SUPPORTED_COINS = ['BTC', 'ZEC', 'LTC', 'BCH', 'DASH']
const BCH_CODES = ['BCH', 'TBCH']
const SUPPORTS_BATCHING = false
function buildBitgo (account) {
const env = account.environment === 'test' ? 'test' : 'prod'
return new BitGo.BitGo({ accessToken: account.token.trim(), env, userAgent: userAgent })
@ -159,11 +157,6 @@ function cryptoNetwork (account, cryptoCode, settings, operatorId) {
.then(() => account.environment === 'test' ? 'test' : 'main')
}
function supportsBatching (cryptoCode) {
return checkCryptoCode(cryptoCode)
.then(() => SUPPORTS_BATCHING)
}
function checkBlockchainStatus (cryptoCode) {
return checkCryptoCode(cryptoCode)
.then(() => Promise.resolve('ready'))
@ -177,6 +170,5 @@ module.exports = {
getStatus,
newFunding,
cryptoNetwork,
supportsBatching,
checkBlockchainStatus
}

View file

@ -9,7 +9,6 @@ const E = require('../../../error')
const cryptoRec = coinUtils.getCryptoCurrency('DASH')
const unitScale = cryptoRec.unitScale
const SUPPORTS_BATCHING = false
const rpcConfig = jsonRpc.rpcConfig(cryptoRec)
function fetch (method, params) {
@ -113,11 +112,6 @@ function newFunding (account, cryptoCode, settings, operatorId) {
}))
}
function supportsBatching (cryptoCode) {
return checkCryptoCode(cryptoCode)
.then(() => SUPPORTS_BATCHING)
}
function checkBlockchainStatus (cryptoCode) {
return checkCryptoCode(cryptoCode)
.then(() => fetch('getblockchaininfo'))
@ -130,6 +124,5 @@ module.exports = {
newAddress,
getStatus,
newFunding,
supportsBatching,
checkBlockchainStatus
}

View file

@ -17,8 +17,6 @@ const paymentPrefixPath = "m/44'/60'/0'/0'"
const defaultPrefixPath = "m/44'/60'/1'/0'"
let lastUsedNonces = {}
const SUPPORTS_BATCHING = false
module.exports = {
NAME,
balance,
@ -32,7 +30,6 @@ module.exports = {
privateKey,
isStrictAddress,
connect,
supportsBatching,
checkBlockchainStatus
}
@ -227,11 +224,6 @@ function newFunding (account, cryptoCode, settings, operatorId) {
})
}
function supportsBatching (cryptoCode) {
return checkCryptoCode(cryptoCode)
.then(() => SUPPORTS_BATCHING)
}
function checkBlockchainStatus (cryptoCode) {
return checkCryptoCode(cryptoCode)
.then(pify(web3.eth.isSyncing))

View file

@ -9,7 +9,6 @@ const E = require('../../../error')
const cryptoRec = coinUtils.getCryptoCurrency('LTC')
const unitScale = cryptoRec.unitScale
const SUPPORTS_BATCHING = false
const rpcConfig = jsonRpc.rpcConfig(cryptoRec)
function fetch (method, params) {
@ -113,11 +112,6 @@ function newFunding (account, cryptoCode, settings, operatorId) {
}))
}
function supportsBatching (cryptoCode) {
return checkCryptoCode(cryptoCode)
.then(() => SUPPORTS_BATCHING)
}
function checkBlockchainStatus (cryptoCode) {
return checkCryptoCode(cryptoCode)
.then(() => fetch('getblockchaininfo'))
@ -130,6 +124,5 @@ module.exports = {
newAddress,
getStatus,
newFunding,
supportsBatching,
checkBlockchainStatus
}

View file

@ -5,7 +5,6 @@ const E = require('../../../error')
const { utils: coinUtils } = require('lamassu-coins')
const NAME = 'FakeWallet'
const BATCHABLE_COINS = ['BTC']
const SECONDS = 1000
const PUBLISH_TIME = 3 * SECONDS
@ -111,10 +110,6 @@ function getStatus (account, tx, requested, settings, operatorId) {
return Promise.resolve({status: 'confirmed'})
}
function supportsBatching (cryptoCode) {
return Promise.resolve(_.includes(cryptoCode, BATCHABLE_COINS))
}
function checkBlockchainStatus (cryptoCode) {
return checkCryptoCode(cryptoCode)
.then(() => Promise.resolve('ready'))
@ -128,6 +123,5 @@ module.exports = {
newAddress,
getStatus,
newFunding,
supportsBatching,
checkBlockchainStatus
}

View file

@ -17,8 +17,6 @@ const configPath = utils.configPath(cryptoRec, blockchainDir)
const walletDir = path.resolve(utils.cryptoDir(cryptoRec, blockchainDir), 'wallets')
const unitScale = cryptoRec.unitScale
const SUPPORTS_BATCHING = false
function rpcConfig () {
try {
const config = jsonRpc.parseConf(configPath)
@ -200,11 +198,6 @@ function cryptoNetwork (account, cryptoCode) {
})
}
function supportsBatching (cryptoCode) {
return checkCryptoCode(cryptoCode)
.then(() => SUPPORTS_BATCHING)
}
function checkBlockchainStatus (cryptoCode) {
return checkCryptoCode(cryptoCode)
.then(() => {
@ -236,6 +229,5 @@ module.exports = {
getStatus,
newFunding,
cryptoNetwork,
supportsBatching,
checkBlockchainStatus
}

View file

@ -9,7 +9,6 @@ const E = require('../../../error')
const cryptoRec = coinUtils.getCryptoCurrency('ZEC')
const unitScale = cryptoRec.unitScale
const SUPPORTS_BATCHING = false
const rpcConfig = jsonRpc.rpcConfig(cryptoRec)
@ -139,11 +138,6 @@ function newFunding (account, cryptoCode, settings, operatorId) {
}))
}
function supportsBatching (cryptoCode) {
return checkCryptoCode(cryptoCode)
.then(() => SUPPORTS_BATCHING)
}
function checkBlockchainStatus (cryptoCode) {
return checkCryptoCode(cryptoCode)
.then(() => fetch('getblockchaininfo'))
@ -156,6 +150,5 @@ module.exports = {
newAddress,
getStatus,
newFunding,
supportsBatching,
checkBlockchainStatus
}

View file

@ -233,8 +233,7 @@ function isStrictAddress (settings, cryptoCode, toAddress) {
}
function supportsBatching (settings, cryptoCode) {
return fetchWallet(settings, cryptoCode)
.then(r => r.wallet.supportsBatching(cryptoCode))
return Promise.resolve(!!configManager.getWalletSettings(cryptoCode, settings.config).allowTransactionBatching)
}
function checkBlockchainStatus (settings, cryptoCode) {

View file

@ -7,7 +7,11 @@ import React from 'react'
import { NamespacedTable as EditableTable } from 'src/components/editableTable'
import { fromNamespace, toNamespace, namespaces } from 'src/utils/config'
import { AdvancedWalletSchema, getAdvancedWalletElements } from './helper'
import {
WalletSchema,
AdvancedWalletSchema,
getAdvancedWalletElements
} from './helper'
const SAVE_CONFIG = gql`
mutation Save($config: JSONObject, $accounts: JSONObject) {
@ -51,8 +55,9 @@ const AdvancedWallet = () => {
enableEdit
editWidth={174}
save={save}
stripeWhen={it => !WalletSchema.isValidSync(it)}
validationSchema={AdvancedWalletSchema}
elements={getAdvancedWalletElements(cryptoCurrencies, coinUtils)}
elements={getAdvancedWalletElements(cryptoCurrencies, coinUtils, config)}
/>
)
}

View file

@ -1,8 +1,11 @@
import * as R from 'ramda'
import * as Yup from 'yup'
import { NumberInput } from 'src/components/inputs/formik'
import Autocomplete from 'src/components/inputs/formik/Autocomplete.js'
import {
Autocomplete,
Checkbox,
NumberInput
} from 'src/components/inputs/formik'
import { disabledColor } from 'src/styling/variables'
import { CURRENCY_MAX } from 'src/utils/constants'
import { transformNumber } from 'src/utils/number'
@ -29,10 +32,11 @@ const WalletSchema = Yup.object().shape({
})
const AdvancedWalletSchema = Yup.object().shape({
cryptoUnits: Yup.string().required()
cryptoUnits: Yup.string().required(),
allowTransactionBatching: Yup.boolean().required()
})
const getAdvancedWalletElements = (cryptoCurrencies, coinUtils) => {
const getAdvancedWalletElements = (cryptoCurrencies, coinUtils, config) => {
const viewCryptoCurrency = it =>
R.compose(
R.prop(['display']),
@ -66,6 +70,15 @@ const getAdvancedWalletElements = (cryptoCurrencies, coinUtils) => {
valueProp: 'code',
labelProp: 'display'
}
},
{
name: 'allowTransactionBatching',
size: 'sm',
stripe: true,
width: 250,
view: (_, ite) =>
config[`${ite.id}_allowTransactionBatching`] ? 'Yes' : 'No',
input: Checkbox
}
]
}