diff --git a/lib/plugins/zero-conf/blockcypher/blockcypher.js b/lib/plugins/zero-conf/blockcypher/blockcypher.js index 6cd3582d..ef48e61f 100644 --- a/lib/plugins/zero-conf/blockcypher/blockcypher.js +++ b/lib/plugins/zero-conf/blockcypher/blockcypher.js @@ -13,7 +13,6 @@ function highConfidence (confidence, txref, txRBF) { } function authorize (account, toAddress, cryptoAtoms, cryptoCode, isBitcoindAvailable) { - let promise = [] return Promise.resolve() .then(() => { if (cryptoCode !== 'BTC') throw new Error('Unsupported crypto: ' + cryptoCode) @@ -31,21 +30,19 @@ function authorize (account, toAddress, cryptoAtoms, cryptoCode, isBitcoindAvail .then(r => { const data = r.data if (isBitcoindAvailable && isRBFEnabled && data.unconfirmed_txrefs) { - _.map(unconfirmedTxref => { - promise.push(new Promise((resolve, reject) => { resolve(fetchRBF(unconfirmedTxref.tx_hash)) })) - }, data.unconfirmed_txrefs) - return Promise.all(promise) + const promises = _.map(unconfirmedTxref => fetchRBF(unconfirmedTxref.tx_hash), data.unconfirmed_txrefs) + return Promise.all(promises) .then(values => { const unconfirmedTxsRBF = _.fromPairs(values) const sumTxRefs = txrefs => _.sumBy(txref => highConfidence(confidence, txref, unconfirmedTxsRBF[txref.tx_hash]), txrefs) const authorizedValue = sumTxRefs(data.txrefs) + sumTxRefs(data.unconfirmed_txrefs) return cryptoAtoms.lte(authorizedValue) }) - } else { - const sumTxRefs = txrefs => _.sumBy(txref => highConfidence(confidence, txref), txrefs) - const authorizedValue = sumTxRefs(data.txrefs) + sumTxRefs(data.unconfirmed_txrefs) - return cryptoAtoms.lte(authorizedValue) } + + const sumTxRefs = txrefs => _.sumBy(txref => highConfidence(confidence, txref), txrefs) + const authorizedValue = sumTxRefs(data.txrefs) + sumTxRefs(data.unconfirmed_txrefs) + return cryptoAtoms.lte(authorizedValue) }) }) }