Merge pull request #296 from isocolsky/fix/first_seen

fix tx history normalization
This commit is contained in:
Matias Alejo Garcia 2015-07-20 16:26:07 -03:00
commit 30721018f8
4 changed files with 7 additions and 8 deletions

View File

@ -1446,6 +1446,8 @@ WalletService.prototype.getNotifications = function(opts, cb) {
WalletService.prototype._normalizeTxHistory = function(txs) {
var now = Math.floor(Date.now() / 1000);
return _.map(txs, function(tx) {
var inputs = _.map(tx.vin, function(item) {
return {
@ -1471,7 +1473,7 @@ WalletService.prototype._normalizeTxHistory = function(txs) {
txid: tx.txid,
confirmations: tx.confirmations,
fees: parseInt((tx.fees * 1e8).toFixed(0)),
time: !_.isNaN(tx.time) ? tx.time : Math.floor(Date.now() / 1000),
time: tx.firstSeenTs || (!_.isNaN(tx.time) ? tx.time : now) || now,
inputs: inputs,
outputs: outputs,
};
@ -1517,8 +1519,6 @@ WalletService.prototype.getTxHistory = function(opts, cb) {
});
};
var now = Math.floor(Date.now() / 1000);
return _.map(txs, function(tx) {
var amountIn, amountOut, amountOutChange;
@ -1557,7 +1557,7 @@ WalletService.prototype.getTxHistory = function(opts, cb) {
action: action,
amount: amount,
fees: tx.fees,
time: tx.firstSeenTs || tx.time || now,
time: tx.time,
addressTo: addressTo,
confirmations: tx.confirmations,
};

View File

@ -2,7 +2,7 @@
"name": "bitcore-wallet-service",
"description": "A service for Mutisig HD Bitcoin Wallets",
"author": "BitPay Inc",
"version": "0.0.44",
"version": "0.0.45",
"keywords": [
"bitcoin",
"copay",

View File

@ -3472,7 +3472,6 @@ describe('Wallet service', function() {
confirmations: 1,
fees: 100,
time: 20,
firstSeenTs: 2,
inputs: [{
address: 'external',
amount: 500,
@ -3491,7 +3490,7 @@ describe('Wallet service', function() {
tx.action.should.equal('received');
tx.amount.should.equal(200);
tx.fees.should.equal(100);
tx.time.should.equal(2);
tx.time.should.equal(20);
done();
});
});

View File

@ -147,7 +147,7 @@ var history = [{
}
}],
confirmations: 2,
time: 1424471041,
firstSeenTs: 1424471041,
blocktime: 1424471041,
valueOut: 0.01345753,
valueIn: 0.01371235,