Merge pull request #2094 from matiu/ref/txproposalevents
refactor tx proposal events
This commit is contained in:
commit
20e19af2c7
12 changed files with 219 additions and 259 deletions
|
|
@ -110,7 +110,6 @@ angular.module('copayApp.services')
|
|||
};
|
||||
|
||||
root.setupGlobalVariables = function(iden) {
|
||||
$rootScope.pendingTxCount = 0;
|
||||
$rootScope.reconnecting = false;
|
||||
$rootScope.iden = iden;
|
||||
};
|
||||
|
|
@ -140,6 +139,32 @@ angular.module('copayApp.services')
|
|||
})
|
||||
};
|
||||
|
||||
root.notifyTxProposalEvent = function(w, e) {
|
||||
if (e.cId == w.getMyCopayerId())
|
||||
return;
|
||||
|
||||
var user = w.publicKeyRing.nicknameForCopayer(e.cId);
|
||||
var name = w.getName();
|
||||
switch (e.type) {
|
||||
case copay.Wallet.TX_NEW:
|
||||
notification.info('[' + name + '] New Transaction',
|
||||
$filter('translate')('You received a transaction proposal from') + ' ' + user);
|
||||
break;
|
||||
case copay.Wallet.TX_SIGNED:
|
||||
notification.success('[' + name + '] Transaction Signed',
|
||||
$filter('translate')('A transaction was signed by') + ' ' + user);
|
||||
break;
|
||||
case copay.Wallet.TX_BROADCASTED:
|
||||
notification.success('[' + name + '] Transaction Approved',
|
||||
$filter('translate')('A transaction was broadcasted by') + ' ' + user);
|
||||
break;
|
||||
case copay.Wallet.TX_REJECTED:
|
||||
notification.warning('[' + name + '] Transaction Rejected',
|
||||
$filter('translate')('A transaction was rejected by') + ' ' + user);
|
||||
break;
|
||||
}
|
||||
};
|
||||
|
||||
root.installWalletHandlers = function(w) {
|
||||
var wid = w.getId();
|
||||
w.on('connectionError', function() {
|
||||
|
|
@ -150,9 +175,7 @@ angular.module('copayApp.services')
|
|||
});
|
||||
|
||||
w.on('corrupt', function(peerId) {
|
||||
if (root.isFocused(wid)) {
|
||||
notification.error('Error', $filter('translate')('Received corrupt message from ') + peerId);
|
||||
}
|
||||
copay.logger.warn('Received corrupt message from ' + peerId);
|
||||
});
|
||||
|
||||
w.on('publicKeyRingUpdated', function() {
|
||||
|
|
@ -200,52 +223,29 @@ angular.module('copayApp.services')
|
|||
// Nothing yet
|
||||
});
|
||||
|
||||
w.on('txProposalsUpdated', function() {
|
||||
if (root.isFocused(wid)) {
|
||||
pendingTxsService.update();
|
||||
}
|
||||
});
|
||||
// Disabled for now, does not seens to have much value for the user
|
||||
// w.on('paymentACK', function(memo) {
|
||||
// notification.success('Payment Acknowledged', memo);
|
||||
// });
|
||||
|
||||
w.on('txProposalEvent', function(ev) {
|
||||
|
||||
w.on('paymentACK', function(memo) {
|
||||
notification.success('Payment Acknowledged', memo);
|
||||
});
|
||||
|
||||
w.on('txProposalEvent', function(e) {
|
||||
if (root.isFocused(wid)) {
|
||||
pendingTxsService.update();
|
||||
}
|
||||
|
||||
// TODO aqui lo unico que cambia son los locked
|
||||
// se puede optimizar
|
||||
balanceService.update(w, function() {
|
||||
$rootScope.$digest();
|
||||
}, root.isFocused(wid));
|
||||
|
||||
// TODO: add wallet name notification
|
||||
var user = w.publicKeyRing.nicknameForCopayer(e.cId);
|
||||
var name = w.getName();
|
||||
switch (e.type) {
|
||||
case 'new':
|
||||
notification.info('[' + name + '] New Transaction',
|
||||
$filter('translate')('You received a transaction proposal from') + ' ' + user);
|
||||
break;
|
||||
case 'signed':
|
||||
notification.success('[' + name + '] Transaction Signed',
|
||||
$filter('translate')('A transaction was signed by') + ' ' + user);
|
||||
break;
|
||||
case 'signedAndBroadcasted':
|
||||
notification.success('[' + name + '] Transaction Approved',
|
||||
$filter('translate')('A transaction was signed and broadcasted by') + ' ' + user);
|
||||
break;
|
||||
case 'rejected':
|
||||
notification.warning('[' + name + '] Transaction Rejected',
|
||||
$filter('translate')('A transaction was rejected by') + ' ' + user);
|
||||
break;
|
||||
case 'corrupt':
|
||||
notification.error('[' + name + '] Transaction Error',
|
||||
$filter('translate')('Received corrupt transaction from') + ' ' + user);
|
||||
break;
|
||||
}
|
||||
$rootScope.$digest();
|
||||
root.notifyTxProposalEvent(w, ev);
|
||||
$timeout(function(){
|
||||
$rootScope.$digest();
|
||||
});
|
||||
});
|
||||
|
||||
w.on('addressBookUpdated', function(dontDigest) {
|
||||
if (root.isFocused(wid)) {
|
||||
if (!dontDigest) {
|
||||
|
|
@ -282,7 +282,7 @@ angular.module('copayApp.services')
|
|||
});
|
||||
|
||||
iden.on('noWallets', function() {
|
||||
notification.warning('No Wallets','Your profile has no wallets. Create one here');
|
||||
notification.warning('No Wallets', 'Your profile has no wallets. Create one here');
|
||||
$rootScope.starting = false;
|
||||
$location.path('/create');
|
||||
$timeout(function() {
|
||||
|
|
|
|||
|
|
@ -1,15 +1,51 @@
|
|||
|
||||
'use strict';
|
||||
|
||||
angular.module('copayApp.services')
|
||||
.factory('pendingTxsService', function($rootScope) {
|
||||
.factory('pendingTxsService', function($rootScope, $filter, rateService) {
|
||||
var root = {};
|
||||
|
||||
root.setAlternativeAmount = function(w, tx, cb) {
|
||||
var alternativeIsoCode = w.settings.alternativeIsoCode;
|
||||
rateService.whenAvailable(function() {
|
||||
_.each(tx.outs, function(out) {
|
||||
var valueSat = out.valueSat * w.settings.unitToSatoshi;
|
||||
out.alternativeAmount = $filter('noFractionNumber')(
|
||||
rateService.toFiat(valueSat, alternativeIsoCode), 2);
|
||||
out.alternativeIsoCode = alternativeIsoCode;
|
||||
});
|
||||
if (cb) return cb(tx);
|
||||
});
|
||||
};
|
||||
|
||||
root.getDecoratedTxProposals = function(w) {
|
||||
var txps = w.getPendingTxProposals();
|
||||
|
||||
_.each(txps, function(tx) {
|
||||
root.setAlternativeAmount(w, tx);
|
||||
if (tx.outs) {
|
||||
_.each(tx.outs, function(out) {
|
||||
out.valueSat = out.value;
|
||||
out.value = $filter('noFractionNumber')(out.value);
|
||||
});
|
||||
}
|
||||
});
|
||||
return txps;
|
||||
};
|
||||
|
||||
/**
|
||||
* @desc adds 2 fields to wallet: pendingTxProposalsCountForUs, pendingTxProposals.
|
||||
*
|
||||
* @param w wallet
|
||||
*/
|
||||
root.update = function(w) {
|
||||
var w = $rootScope.wallet;
|
||||
if (!w) return;
|
||||
|
||||
//pendingTxCount
|
||||
var ret = w.getPendingTxProposalsCount();
|
||||
$rootScope.pendingTxCount = ret.pendingForUs;
|
||||
w.pendingTxProposalsCountForUs = ret.pendingForUs;
|
||||
w.pendingTxProposals = root.getDecoratedTxProposals(w);
|
||||
};
|
||||
|
||||
return root;
|
||||
});
|
||||
|
|
|
|||
|
|
@ -6,19 +6,16 @@ angular.module('copayApp.services').factory('txStatus', function($modal) {
|
|||
root.notify = function(status) {
|
||||
var msg;
|
||||
if (status == copay.Wallet.TX_BROADCASTED)
|
||||
msg = 'Transaction broadcasted!';
|
||||
msg = 'Transaction broadcasted';
|
||||
else if (status == copay.Wallet.TX_PROPOSAL_SENT)
|
||||
msg = 'Transaction proposal created';
|
||||
else if (status == copay.Wallet.TX_SIGNED)
|
||||
msg = 'Transaction proposal was signed';
|
||||
else if (status == copay.Wallet.TX_SIGNED_AND_BROADCASTED)
|
||||
msg = 'Transaction signed and broadcasted!';
|
||||
else if (status == 'txRejected')
|
||||
msg = 'Transaction was rejected!';
|
||||
msg = 'Transaction proposal signed';
|
||||
else if (status == copay.Wallet.TX_REJECTED)
|
||||
msg = 'Transaction was rejected';
|
||||
|
||||
if (msg)
|
||||
root.openModal(msg);
|
||||
return msg ? true : false;
|
||||
};
|
||||
|
||||
root.openModal = function(statusStr) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue