fixes in homeWallet

This commit is contained in:
Matias Alejo Garcia 2014-12-04 18:12:29 -03:00
commit a69fb99206
2 changed files with 53 additions and 25 deletions

View file

@ -1,45 +1,71 @@
'use strict'; 'use strict';
angular.module('copayApp.controllers').controller('HomeWalletController', function($scope, $rootScope, $timeout, $filter, rateService) { angular.module('copayApp.controllers').controller('HomeWalletController', function($scope, $rootScope, $timeout, $filter, rateService, notification) {
$scope.init = function() { $scope.init = function() {
$rootScope.title = 'Home'; $rootScope.title = 'Home';
$scope.rateService = rateService; $scope.rateService = rateService;
$scope.isRateAvailable = false; $scope.isRateAvailable = false;
var w = $rootScope.wallet; var w = $rootScope.wallet;
w.on('txProposalEvent', function() { _updateTxs()}); w.on('txProposalEvent', _updateTxs);
$timeout(function() { _updateTxs();
_updateTxs();
}, 1);
rateService.whenAvailable(function() { rateService.whenAvailable(function() {
$scope.isRateAvailable = true; $scope.isRateAvailable = true;
$scope.$digest(); $scope.$digest();
}); });
}; };
// This is necesarry, since wallet can change in homeWallet, without running init() again. // This is necesarry, since wallet can change in homeWallet, without running init() again.
var removeWatch = $rootScope.$watch('wallet.id', function(newWallet, oldWallet) { var removeWatch;
removeWatch = $rootScope.$watch('wallet.id', function(newWallet, oldWallet) {
if ($rootScope.wallet && $rootScope.wallet.isComplete() && newWallet !== oldWallet) { if ($rootScope.wallet && $rootScope.wallet.isComplete() && newWallet !== oldWallet) {
var w = $rootScope.wallet;
$rootScope.pendingTxCount = 0; if (removeWatch)
w.on('txProposalEvent', function() { _updateTxs()}); removeWatch();
if (oldWallet) {
var oldw = $rootScope.iden.getWalletById(oldWallet);
if (oldw)
oldw.removeListener('txProposalEvent', _updateTxs);
}
var w = $rootScope.wallet;
$rootScope.pendingTxCount = 0;
w.on('txProposalEvent', _updateTxs);
_updateTxs(); _updateTxs();
} }
}); });
$scope.$on("$destroy", function(){
// TODO duplicated on controller send. move to a service.
$scope.notifyStatus = function(status) {
if (status == copay.Wallet.TX_BROADCASTED)
notification.success('Success', 'Transaction broadcasted!');
else if (status == copay.Wallet.TX_PROPOSAL_SENT)
notification.info('Success', 'Transaction proposal created');
else if (status == copay.Wallet.TX_SIGNED)
notification.success('Success', 'Transaction proposal was signed');
else if (status == copay.Wallet.TX_SIGNED_AND_BROADCASTED)
notification.success('Success', 'Transaction signed and broadcasted!');
else
notification.error('Error', 'Unknown error occured');
};
$scope.$on("$destroy", function() {
var w = $rootScope.wallet; var w = $rootScope.wallet;
removeWatch(); removeWatch();
w.removeListener('txProposalEvent', function() {_updateTxs()} ); w.removeListener('txProposalEvent', _updateTxs);
}); });
$scope.setAlternativeAmount = function(w, tx, cb) { $scope.setAlternativeAmount = function(w, tx, cb) {
rateService.whenAvailable(function() { rateService.whenAvailable(function() {
_.each(tx.outs, function(out) { _.each(tx.outs, function(out) {
var valueSat = out.valueSat * w.settings.unitToSatoshi; var valueSat = out.valueSat * w.settings.unitToSatoshi;
out.alternativeAmount = $filter('noFractionNumber')(rateService.toFiat(valueSat, $scope.alternativeIsoCode), 2); out.alternativeAmount = $filter('noFractionNumber')(rateService.toFiat(valueSat, $scope.alternativeIsoCode), 2);
out.alternativeIsoCode = $scope.alternativeIsoCode; out.alternativeIsoCode = $scope.alternativeIsoCode;
}); });
if (cb) return cb(tx); if (cb) return cb(tx);
@ -52,7 +78,7 @@ angular.module('copayApp.controllers').controller('HomeWalletController', functi
$scope.alternativeIsoCode = w.settings.alternativeIsoCode; $scope.alternativeIsoCode = w.settings.alternativeIsoCode;
$scope.myId = w.getMyCopayerId(); $scope.myId = w.getMyCopayerId();
var res = w.getPendingTxProposals(); var res = w.getPendingTxProposals();
_.each(res.txs, function(tx) { _.each(res.txs, function(tx) {
$scope.setAlternativeAmount(w, tx); $scope.setAlternativeAmount(w, tx);
@ -66,13 +92,15 @@ angular.module('copayApp.controllers').controller('HomeWalletController', functi
out.valueSat = out.value; out.valueSat = out.value;
out.value = $filter('noFractionNumber')(out.value); out.value = $filter('noFractionNumber')(out.value);
}); });
} }
}); });
$scope.txps = res.txs; $scope.txps = res.txs;
console.log('[homeWallet.js:45]',$scope.txps); //TODO $timeout(function(){
}, 100); $scope.$digest();
},1)
}, 100);
$scope.sign = function(ntxid) { $scope.sign = function(ntxid) {
var w = $rootScope.wallet; var w = $rootScope.wallet;

View file

@ -245,15 +245,15 @@ angular.module('copayApp.services')
$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.success('[' + name + '] Transaction Signed',
$filter('translate')('A transaction was signed by') + ' ' + user); $filter('translate')('A transaction was signed by') + ' ' + user);
break; break;
case 'signedAndBroadcasted': case 'signedAndBroadcasted':
notification.info('[' + name + '] Transaction Approved', notification.success('[' + name + '] Transaction Approved',
$filter('translate')('A transaction was signed and broadcasted by') + ' ' + user); $filter('translate')('A transaction was signed and broadcasted by') + ' ' + user);
break; break;
case 'rejected': case 'rejected':
notification.info('[' + name + '] Transaction Rejected', notification.warning('[' + 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':