Merge pull request #296 from isocolsky/fix/first_seen
fix tx history normalization
This commit is contained in:
commit
30721018f8
|
@ -1446,6 +1446,8 @@ WalletService.prototype.getNotifications = function(opts, cb) {
|
||||||
|
|
||||||
|
|
||||||
WalletService.prototype._normalizeTxHistory = function(txs) {
|
WalletService.prototype._normalizeTxHistory = function(txs) {
|
||||||
|
var now = Math.floor(Date.now() / 1000);
|
||||||
|
|
||||||
return _.map(txs, function(tx) {
|
return _.map(txs, function(tx) {
|
||||||
var inputs = _.map(tx.vin, function(item) {
|
var inputs = _.map(tx.vin, function(item) {
|
||||||
return {
|
return {
|
||||||
|
@ -1471,7 +1473,7 @@ WalletService.prototype._normalizeTxHistory = function(txs) {
|
||||||
txid: tx.txid,
|
txid: tx.txid,
|
||||||
confirmations: tx.confirmations,
|
confirmations: tx.confirmations,
|
||||||
fees: parseInt((tx.fees * 1e8).toFixed(0)),
|
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,
|
inputs: inputs,
|
||||||
outputs: outputs,
|
outputs: outputs,
|
||||||
};
|
};
|
||||||
|
@ -1517,8 +1519,6 @@ WalletService.prototype.getTxHistory = function(opts, cb) {
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
var now = Math.floor(Date.now() / 1000);
|
|
||||||
|
|
||||||
return _.map(txs, function(tx) {
|
return _.map(txs, function(tx) {
|
||||||
|
|
||||||
var amountIn, amountOut, amountOutChange;
|
var amountIn, amountOut, amountOutChange;
|
||||||
|
@ -1557,7 +1557,7 @@ WalletService.prototype.getTxHistory = function(opts, cb) {
|
||||||
action: action,
|
action: action,
|
||||||
amount: amount,
|
amount: amount,
|
||||||
fees: tx.fees,
|
fees: tx.fees,
|
||||||
time: tx.firstSeenTs || tx.time || now,
|
time: tx.time,
|
||||||
addressTo: addressTo,
|
addressTo: addressTo,
|
||||||
confirmations: tx.confirmations,
|
confirmations: tx.confirmations,
|
||||||
};
|
};
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
"name": "bitcore-wallet-service",
|
"name": "bitcore-wallet-service",
|
||||||
"description": "A service for Mutisig HD Bitcoin Wallets",
|
"description": "A service for Mutisig HD Bitcoin Wallets",
|
||||||
"author": "BitPay Inc",
|
"author": "BitPay Inc",
|
||||||
"version": "0.0.44",
|
"version": "0.0.45",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"bitcoin",
|
"bitcoin",
|
||||||
"copay",
|
"copay",
|
||||||
|
|
|
@ -3472,7 +3472,6 @@ describe('Wallet service', function() {
|
||||||
confirmations: 1,
|
confirmations: 1,
|
||||||
fees: 100,
|
fees: 100,
|
||||||
time: 20,
|
time: 20,
|
||||||
firstSeenTs: 2,
|
|
||||||
inputs: [{
|
inputs: [{
|
||||||
address: 'external',
|
address: 'external',
|
||||||
amount: 500,
|
amount: 500,
|
||||||
|
@ -3491,7 +3490,7 @@ describe('Wallet service', function() {
|
||||||
tx.action.should.equal('received');
|
tx.action.should.equal('received');
|
||||||
tx.amount.should.equal(200);
|
tx.amount.should.equal(200);
|
||||||
tx.fees.should.equal(100);
|
tx.fees.should.equal(100);
|
||||||
tx.time.should.equal(2);
|
tx.time.should.equal(20);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -147,7 +147,7 @@ var history = [{
|
||||||
}
|
}
|
||||||
}],
|
}],
|
||||||
confirmations: 2,
|
confirmations: 2,
|
||||||
time: 1424471041,
|
firstSeenTs: 1424471041,
|
||||||
blocktime: 1424471041,
|
blocktime: 1424471041,
|
||||||
valueOut: 0.01345753,
|
valueOut: 0.01345753,
|
||||||
valueIn: 0.01371235,
|
valueIn: 0.01371235,
|
||||||
|
|
Loading…
Reference in New Issue