fixes in homeWallet
This commit is contained in:
parent
03f2c463ba
commit
a69fb99206
2 changed files with 53 additions and 25 deletions
|
|
@ -1,6 +1,6 @@
|
||||||
'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';
|
||||||
|
|
||||||
|
|
@ -8,10 +8,8 @@ angular.module('copayApp.controllers').controller('HomeWalletController', functi
|
||||||
$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;
|
||||||
|
|
@ -20,26 +18,54 @@ angular.module('copayApp.controllers').controller('HomeWalletController', functi
|
||||||
};
|
};
|
||||||
|
|
||||||
// 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) {
|
||||||
|
|
||||||
|
if (removeWatch)
|
||||||
|
removeWatch();
|
||||||
|
|
||||||
|
if (oldWallet) {
|
||||||
|
var oldw = $rootScope.iden.getWalletById(oldWallet);
|
||||||
|
if (oldw)
|
||||||
|
oldw.removeListener('txProposalEvent', _updateTxs);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
var w = $rootScope.wallet;
|
var w = $rootScope.wallet;
|
||||||
$rootScope.pendingTxCount = 0;
|
$rootScope.pendingTxCount = 0;
|
||||||
w.on('txProposalEvent', function() { _updateTxs()});
|
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);
|
||||||
|
|
@ -69,7 +95,9 @@ angular.module('copayApp.controllers').controller('HomeWalletController', functi
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
$scope.txps = res.txs;
|
$scope.txps = res.txs;
|
||||||
console.log('[homeWallet.js:45]',$scope.txps); //TODO
|
$timeout(function(){
|
||||||
|
$scope.$digest();
|
||||||
|
},1)
|
||||||
}, 100);
|
}, 100);
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -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':
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue