fix pending notification

This commit is contained in:
Matias Alejo Garcia 2014-11-25 15:09:51 -03:00
commit 4e54fe6cf7
5 changed files with 39 additions and 39 deletions

View file

@ -144,6 +144,8 @@ angular.module('copayApp.controllers').controller('HistoryController',
_.each(items, function(r) { _.each(items, function(r) {
r.ts = r.minedTs || r.sentTs; r.ts = r.minedTs || r.sentTs;
}); });
$scope.blockchain_txs = w.cached_txs = items; $scope.blockchain_txs = w.cached_txs = items;
$scope.nbPages = res.nbPages; $scope.nbPages = res.nbPages;
$scope.totalItems = res.nbItems; $scope.totalItems = res.nbItems;

View file

@ -1897,9 +1897,11 @@ Wallet.prototype.onPayProPaymentAck = function(ntxid, rawData) {
var ack = paypro.makePaymentACK(data); var ack = paypro.makePaymentACK(data);
var memo = ack.get('memo'); var memo = ack.get('memo');
log.debug('Payment Acknowledged!: %s', memo); log.debug('Payment Acknowledged!: %s', memo);
var txp = this.txProposals.get(ntxid);
txp.paymentAckMemo = memo; txp.paymentAckMemo = memo;
self.sendTxProposal(ntxid); this.sendTxProposal(ntxid);
self.emitAndKeepAlive('paymentACK', memo); this.emitAndKeepAlive('paymentACK', memo);
}; };
@ -2571,6 +2573,8 @@ Wallet.prototype.getTransactionHistory = function(opts, cb) {
var proposals = self.getTxProposals(); var proposals = self.getTxProposals();
var satToUnit = 1 / self.settings.unitToSatoshi; var satToUnit = 1 / self.settings.unitToSatoshi;
function extractInsOuts(tx) { function extractInsOuts(tx) {
// Inputs // Inputs
var inputs = _.map(tx.vin, function(item) { var inputs = _.map(tx.vin, function(item) {

View file

@ -46,7 +46,7 @@ angular.module('copayApp.services')
}; };
root.onError = function(scope) { root.onError = function(scope) {
if (scope) { if (scope) {
scope.loading = false; scope.loading = false;
} }
} }
@ -64,12 +64,6 @@ angular.module('copayApp.services')
}; };
root.updateTxsAndBalance = function(w) {
root.updateTxs(w);
root.updateBalance(w, function() {
$rootScope.$digest();
});
};
root.installWalletHandlers = function($scope, w) { root.installWalletHandlers = function($scope, w) {
@ -129,11 +123,13 @@ angular.module('copayApp.services')
} }
}); });
w.on('newAddresses', function() { w.on('newAddresses', function() {
root.updateTxsAndBalance(w); root.updateBalance(w);
}); });
w.on('txProposalsUpdated', function() { w.on('txProposalsUpdated', function() {
root.updateTxsAndBalance(w); if (root.isFocusedWallet(wid)) {
root.updateTxs();
}
}); });
w.on('paymentACK', function(memo) { w.on('paymentACK', function(memo) {
@ -142,26 +138,29 @@ angular.module('copayApp.services')
w.on('txProposalEvent', function(e) { w.on('txProposalEvent', function(e) {
root.updateTxsAndBalance(w); if (root.isFocusedWallet(wid)) {
root.updateTxs();
}
// TODO: add wallet name notification // TODO: add wallet name notification
var user = w.publicKeyRing.nicknameForCopayer(e.cId); var user = w.publicKeyRing.nicknameForCopayer(e.cId);
var name = w.getName(); var name = w.getName();
switch (e.type) { switch (e.type) {
case 'new': case 'new':
notification.info('['+ name +'] New Transaction', notification.info('[' + name + '] New Transaction',
$filter('translate')('You received a transaction proposal from') + ' ' + user); $filter('translate')('You received a transaction proposal from') + ' ' + user);
break; break;
case 'signed': case 'signed':
notification.info('['+ name +'] Transaction Signed', notification.info('[' + name + '] Transaction Signed',
$filter('translate')('A transaction was signed by') + ' ' + user); $filter('translate')('A transaction was signed by') + ' ' + user);
break; break;
case 'rejected': case 'rejected':
notification.info('['+ name +'] Transaction Rejected', notification.info('[' + name + '] Transaction Rejected',
$filter('translate')('A transaction was rejected by') + ' ' + user); $filter('translate')('A transaction was rejected by') + ' ' + user);
break; break;
case 'corrupt': case 'corrupt':
notification.error('['+ name +'] Transaction Error', notification.error('[' + name + '] Transaction Error',
$filter('translate')('Received corrupt transaction from') + ' ' + user); $filter('translate')('Received corrupt transaction from') + ' ' + user);
break; break;
} }
$rootScope.$digest(); $rootScope.$digest();
@ -185,20 +184,12 @@ angular.module('copayApp.services')
notification.enableHtml5Mode(); // for chrome: if support, enable it notification.enableHtml5Mode(); // for chrome: if support, enable it
uriHandler.register(); uriHandler.register();
$rootScope.unitName = config.unitName; $rootScope.unitName = config.unitName;
$rootScope.txAlertCount = 0; $rootScope.pendingTxCount = 0;
$rootScope.initialConnection = true; $rootScope.initialConnection = true;
$rootScope.reconnecting = false; $rootScope.reconnecting = false;
$rootScope.isCollapsed = true; $rootScope.isCollapsed = true;
$rootScope.iden = iden; $rootScope.iden = iden;
// TODO
// $rootScope.$watch('txAlertCount', function(txAlertCount) {
// if (txAlertCount && txAlertCount > 0) {
//
// notification.info('New Transaction', ($rootScope.txAlertCount == 1) ? 'You have a pending transaction proposal' : $filter('translate')('You have') + ' ' + $rootScope.txAlertCount + ' ' + $filter('translate')('pending transaction proposals'), txAlertCount);
// }
// });
}; };
@ -279,7 +270,7 @@ angular.module('copayApp.services')
r.lockedBalanceBTC = (balanceSat - safeBalanceSat) / COIN; r.lockedBalanceBTC = (balanceSat - safeBalanceSat) / COIN;
if (r.safeUnspentCount){ if (r.safeUnspentCount) {
var estimatedFee = copay.Wallet.estimatedFee(r.safeUnspentCount); var estimatedFee = copay.Wallet.estimatedFee(r.safeUnspentCount);
r.topAmount = (((r.availableBalance * w.settings.unitToSatoshi).toFixed(0) - estimatedFee) / w.settings.unitToSatoshi); r.topAmount = (((r.availableBalance * w.settings.unitToSatoshi).toFixed(0) - estimatedFee) / w.settings.unitToSatoshi);
} }
@ -323,8 +314,6 @@ angular.module('copayApp.services')
w.balanceInfo = {}; w.balanceInfo = {};
var scope = root.isFocusedWallet(w.id) && !refreshAll ? $rootScope : w.balanceInfo; var scope = root.isFocusedWallet(w.id) && !refreshAll ? $rootScope : w.balanceInfo;
root.updateAddressList();
var wid = w.getId(); var wid = w.getId();
if (_balanceCache[wid]) { if (_balanceCache[wid]) {
@ -349,7 +338,7 @@ angular.module('copayApp.services')
}); });
}; };
root.computeAlternativeAmount = function(w, tx, cb) { root.setAlternativeAmount = function(w, tx, cb) {
rateService.whenAvailable(function() { rateService.whenAvailable(function() {
_.each(tx.outs, function(out) { _.each(tx.outs, function(out) {
var valueSat = out.value * w.settings.unitToSatoshi; var valueSat = out.value * w.settings.unitToSatoshi;
@ -360,12 +349,13 @@ angular.module('copayApp.services')
}); });
}; };
root.updateTxs = function(w) { root.updateTxs = function() {
w = w || $rootScope.wallet; var w = $rootScope.wallet;
if (!w) return root.onErrorDigest(); if (!w) return;
var res = w.getPendingTxProposals(); var res = w.getPendingTxProposals();
_.each(res.txs, function(tx) { _.each(res.txs, function(tx) {
root.computeAlternativeAmount(w, tx); root.setAlternativeAmount(w, tx);
if (tx.merchant) { if (tx.merchant) {
var url = tx.merchant.request_url; var url = tx.merchant.request_url;
var domain = /^(?:https?)?:\/\/([^\/:]+).*$/.exec(url)[1]; var domain = /^(?:https?)?:\/\/([^\/:]+).*$/.exec(url)[1];
@ -373,14 +363,11 @@ angular.module('copayApp.services')
} }
}); });
$rootScope.txps = res.txs; $rootScope.txps = res.txs;
if ($rootScope.pendingTxCount < res.pendingForUs) {
$rootScope.txAlertCount = res.pendingForUs;
}
$rootScope.pendingTxCount = res.pendingForUs; $rootScope.pendingTxCount = res.pendingForUs;
}; };
root.deleteWallet = function($scope, w, cb) { root.deleteWallet = function($scope, w, cb) {
if (!w) return root.onErrorDigest(); if (!w) return root.onErrorDigest();
var name = w.getName(); var name = w.getName();
$rootScope.iden.deleteWallet(w.id, function() { $rootScope.iden.deleteWallet(w.id, function() {
notification.info(name + ' deleted', $filter('translate')('This wallet was deleted')); notification.info(name + ' deleted', $filter('translate')('This wallet was deleted'));

View file

@ -2462,10 +2462,15 @@ describe('Wallet model', function() {
}); });
}); });
// TODO
describe.skip('#onPayProPaymentAck', function() { describe.skip('#onPayProPaymentAck', function() {
it('should emit', function() { it('should emit', function() {
var w = cachedCreateW2(); var w = cachedCreateW2();
sinon.stub(w,'emitAndKeepAlive');
w.onPayProPaymentAck('id', 'data'); w.onPayProPaymentAck('id', 'data');
w.calledOnce.should.equal(true);
w.getCall(0).args.should.deep.equal(['paymentACK', 'data']);
}); });
}); });

View file

@ -71,9 +71,11 @@
<div ng-show="btx.showDetails" class="m10t"> <div ng-show="btx.showDetails" class="m10t">
<div class="send-note" ng-show="!!btx.merchant"> <div class="send-note" ng-show="!!btx.merchant">
<p> <p>
<b>{{btx.merchant.pr.pd.memo}}</b> <b>{{btx.merchant.pr.pd.memo}}</b>
<p> <p>
<b>{{btx.paymentAckMemo}}</b>
<span ng-show="tx.merchant.domain">[{{btx.merchant.domain}}]</span> <span ng-show="tx.merchant.domain">[{{btx.merchant.domain}}]</span>
</div> </div>
<table class="last-transactions-content" ng-if="btx.actionList.0"> <table class="last-transactions-content" ng-if="btx.actionList.0">
<tbody> <tbody>