refactor: remove duplicate function

This commit is contained in:
José Oliveira 2021-04-05 17:48:18 +01:00 committed by Josh Harvey
parent e62245098b
commit dd3b4116a6

View file

@ -30,6 +30,7 @@ function authorize (account, toAddress, cryptoAtoms, cryptoCode, isBitcoindAvail
return axios.get(url) return axios.get(url)
.then(r => { .then(r => {
const data = r.data const data = r.data
const sumTxRefs = txrefs => _.sumBy(txref => highConfidence(confidence, txref), txrefs)
if (isBitcoindAvailable && isRBFEnabled && data.unconfirmed_txrefs) { if (isBitcoindAvailable && isRBFEnabled && data.unconfirmed_txrefs) {
_.map(unconfirmedTxref => { _.map(unconfirmedTxref => {
promise.push(new Promise((resolve, reject) => { resolve(fetchRBF(unconfirmedTxref.tx_hash)) })) promise.push(new Promise((resolve, reject) => { resolve(fetchRBF(unconfirmedTxref.tx_hash)) }))
@ -41,12 +42,10 @@ function authorize (account, toAddress, cryptoAtoms, cryptoCode, isBitcoindAvail
if (rbfInfo.tx_hash === unconfirmedTxref.tx_hash) unconfirmedTxref.rbf = rbfInfo['bip125-replaceable'] if (rbfInfo.tx_hash === unconfirmedTxref.tx_hash) unconfirmedTxref.rbf = rbfInfo['bip125-replaceable']
}, data.unconfirmed_txrefs) }, data.unconfirmed_txrefs)
}, values) }, values)
const sumTxRefs = txrefs => _.sumBy(txref => highConfidence(confidence, txref), txrefs)
const authorizedValue = sumTxRefs(data.txrefs) + sumTxRefs(data.unconfirmed_txrefs) const authorizedValue = sumTxRefs(data.txrefs) + sumTxRefs(data.unconfirmed_txrefs)
return cryptoAtoms.lte(authorizedValue) return cryptoAtoms.lte(authorizedValue)
}) })
} else { } else {
const sumTxRefs = txrefs => _.sumBy(txref => highConfidence(confidence, txref), txrefs)
const authorizedValue = sumTxRefs(data.txrefs) + sumTxRefs(data.unconfirmed_txrefs) const authorizedValue = sumTxRefs(data.txrefs) + sumTxRefs(data.unconfirmed_txrefs)
return cryptoAtoms.lte(authorizedValue) return cryptoAtoms.lte(authorizedValue)
} }