return nbBlocks = null when fee level is unavailable
This commit is contained in:
parent
86d1818940
commit
fc94c2e0cf
|
@ -792,35 +792,21 @@ WalletService.prototype.getFeeLevels = function(opts, cb) {
|
|||
if (network != 'livenet' && network != 'testnet')
|
||||
return cb(new ClientError('Invalid network'));
|
||||
|
||||
var levels = [{
|
||||
name: 'priority',
|
||||
nbBlocks: 1,
|
||||
defaultValue: 50000
|
||||
}, {
|
||||
name: 'normal',
|
||||
nbBlocks: 4,
|
||||
defaultValue: 20000
|
||||
}, {
|
||||
name: 'economy',
|
||||
nbBlocks: 12,
|
||||
defaultValue: 10000
|
||||
}, ];
|
||||
|
||||
var levels = WalletUtils.FEE_LEVELS;
|
||||
var samplePoints = _.uniq(_.pluck(levels, 'nbBlocks'));
|
||||
self._sampleFeeLevels(network, samplePoints, function(err, feeSamples) {
|
||||
var values = _.map(levels, function(level) {
|
||||
var feePerKB;
|
||||
if (err) {
|
||||
feePerKB = level.defaultValue;
|
||||
} else {
|
||||
var sample = feeSamples[level.nbBlocks];
|
||||
feePerKB = (sample < 0) ? level.defaultValue : sample;
|
||||
}
|
||||
return {
|
||||
var result = {
|
||||
level: level.name,
|
||||
feePerKB: feePerKB,
|
||||
nbBlocks: level.nbBlocks,
|
||||
};
|
||||
if (err || feeSamples[level.nbBlocks] < 0) {
|
||||
result.feePerKB = level.defaultValue;
|
||||
result.nbBlocks = null;
|
||||
} else {
|
||||
result.feePerKB = feeSamples[level.nbBlocks];
|
||||
result.nbBlocks = level.nbBlocks;
|
||||
}
|
||||
return result;
|
||||
});
|
||||
|
||||
return cb(null, values);
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
"name": "bitcore-wallet-service",
|
||||
"description": "A service for Mutisig HD Bitcoin Wallets",
|
||||
"author": "BitPay Inc",
|
||||
"version": "0.0.45",
|
||||
"version": "0.0.46",
|
||||
"keywords": [
|
||||
"bitcoin",
|
||||
"copay",
|
||||
|
@ -20,7 +20,7 @@
|
|||
"dependencies": {
|
||||
"async": "^0.9.0",
|
||||
"bitcore": "^0.12.9",
|
||||
"bitcore-wallet-utils": "^0.0.21",
|
||||
"bitcore-wallet-utils": "^0.0.22",
|
||||
"body-parser": "^1.11.0",
|
||||
"coveralls": "^2.11.2",
|
||||
"email-validator": "^1.0.1",
|
||||
|
|
|
@ -1512,11 +1512,16 @@ describe('Wallet service', function() {
|
|||
server.getFeeLevels({}, function(err, fees) {
|
||||
should.not.exist(err);
|
||||
fees = _.zipObject(_.map(fees, function(item) {
|
||||
return [item.level, item.feePerKB];
|
||||
return [item.level, item];
|
||||
}));
|
||||
fees.priority.should.equal(50000);
|
||||
fees.normal.should.equal(18000);
|
||||
fees.economy.should.equal(0);
|
||||
fees.priority.feePerKB.should.equal(50000);
|
||||
should.not.exist(fees.priority.nbBlocks);
|
||||
|
||||
fees.normal.feePerKB.should.equal(18000);
|
||||
fees.normal.nbBlocks.should.equal(4);
|
||||
|
||||
fees.economy.feePerKB.should.equal(0);
|
||||
fees.economy.nbBlocks.should.equal(12);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue