retrieving label from address book
This commit is contained in:
parent
6e2ade54bc
commit
b6f5b342f2
3 changed files with 54 additions and 11 deletions
|
|
@ -82,16 +82,7 @@ angular.module('copayApp.controllers').controller('SendController',
|
|||
}
|
||||
|
||||
$scope.showAddressBook = function() {
|
||||
var flag;
|
||||
if (w) {
|
||||
for (var k in w.addressBook) {
|
||||
if (w.addressBook[k]) {
|
||||
flag = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return flag;
|
||||
return w && _.keys(w.addressBook).length > 0;
|
||||
};
|
||||
|
||||
if ($rootScope.pendingPayment) {
|
||||
|
|
|
|||
|
|
@ -2943,11 +2943,13 @@ Wallet.prototype.getTransactionHistory = function(cb) {
|
|||
addressStr: itemAddr,
|
||||
});
|
||||
}
|
||||
|
||||
return {
|
||||
type: 'out',
|
||||
address: addr ? addr : itemAddr,
|
||||
isMine: !_.isUndefined(addr),
|
||||
isChange: addr ? !!addr.isChange : false,
|
||||
label: self.addressBook[itemAddr] ? self.addressBook[itemAddr].label : undefined,
|
||||
amountSat: parseInt((item.value * bitcore.util.COIN).toFixed(0)),
|
||||
}
|
||||
});
|
||||
|
|
@ -2986,13 +2988,16 @@ Wallet.prototype.getTransactionHistory = function(cb) {
|
|||
var amount;
|
||||
if (amountIn == (amountOut + amountOutChange + (amountIn > 0 ? fees : 0))) {
|
||||
tx.action = 'moved';
|
||||
// TODO: subtract amount from change addresses
|
||||
amount = amountOut;
|
||||
} else {
|
||||
amount = amountIn - amountOut - amountOutChange - (amountIn > 0 ? fees : 0);
|
||||
tx.action = amount > 0 ? 'sent' : 'received';
|
||||
}
|
||||
|
||||
var firstOut = _.findWhere(items, {
|
||||
type: 'out'
|
||||
});
|
||||
tx.labelTo = firstOut ? firstOut.label : undefined;
|
||||
tx.amountSat = Math.abs(amount);
|
||||
tx.amount = tx.amountSat * satToUnit;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -2081,6 +2081,53 @@ describe('Wallet model', function() {
|
|||
done();
|
||||
});
|
||||
});
|
||||
it('should assign label when address in address book', function(done) {
|
||||
var w = cachedCreateW2();
|
||||
var txs = [{
|
||||
vin: [{
|
||||
addr: 'addr_in_1',
|
||||
valueSat: 3000
|
||||
}, {
|
||||
addr: 'addr_in_2',
|
||||
valueSat: 2000
|
||||
}],
|
||||
vout: [{
|
||||
scriptPubKey: {
|
||||
addresses: ['addr_out_1'],
|
||||
},
|
||||
value: '0.00003900',
|
||||
}, {
|
||||
scriptPubKey: {
|
||||
addresses: ['change'],
|
||||
},
|
||||
value: '0.00001000',
|
||||
}],
|
||||
fees: 0.00000100
|
||||
}];
|
||||
|
||||
w.blockchain.getTransactions = sinon.stub().yields(null, txs);
|
||||
w.getAddressesInfo = sinon.stub().returns([{
|
||||
addressStr: 'addr_in_1'
|
||||
}, {
|
||||
addressStr: 'addr_in_2'
|
||||
}, {
|
||||
addressStr: 'change',
|
||||
isChange: true,
|
||||
}]);
|
||||
|
||||
w.addressBook = {
|
||||
'addr_out_1': {
|
||||
label: 'Address out one'
|
||||
},
|
||||
};
|
||||
|
||||
w.getTransactionHistory(function(err, res) {
|
||||
res.should.exist;
|
||||
res[0].labelTo.should.equal('Address out one');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue