Merge pull request #444 from cmgustavo/feature/01-alert-txs

Feature/01 alert txs
This commit is contained in:
Mario Colque 2014-05-21 10:46:35 -03:00
commit 194ddc8079
6 changed files with 114 additions and 43 deletions

View file

@ -11,14 +11,32 @@ angular.module('copay.addresses').controller('AddressesController',
$timeout(function() {
controllerUtils.setSocketHandlers();
controllerUtils.updateAddressList();
$rootScope.selectedAddr = $rootScope.addrInfos[0].address.toString();
$scope.loading = false;
$rootScope.$digest();
},1);
});
};
$scope.selectAddr = function (addr) {
return addr === $rootScope.selectedAddr ? 'selected' : '';
$scope.selectAddress = function (addr) {
$scope.selectedAddr = addr;
};
$rootScope.$watch('addrInfos', function(addrInfos) {
$scope.addressList(addrInfos);
});
$scope.addressList = function (addrInfos) {
$scope.addresses = [];
if (addrInfos) {
for(var i=0;i<addrInfos.length;i++) {
var addrinfo = addrInfos[i];
$scope.addresses.push({
'address' : addrinfo.address.toString(),
'balance' : $rootScope.balanceByAddr ? $rootScope.balanceByAddr[addrinfo.address.toString()] : 0,
'isChange': addrinfo.isChange
});
}
$scope.selectedAddr = $scope.addresses[0];
}
}
});

View file

@ -20,16 +20,34 @@ angular.module('copay.header').controller('HeaderController',
'icon': 'fi-archive',
'link': '#/backup'
}];
var beep = new Audio('sound/transaction.mp3');
// Initialize alert notification (not show when init wallet)
$rootScope.txAlertCount = 0;
$notification.enableHtml5Mode(); // for chrome: if support, enable it
$rootScope.$watch('txAlertCount', function(txAlertCount) {
if (txAlertCount && txAlertCount > 0) {
$notification.info('New Transaction', ($rootScope.txAlertCount == 1) ? 'You have a pending transaction proposal' : 'You have ' + $rootScope.txAlertCount + ' pending transaction proposals', txAlertCount);
}
});
$rootScope.$watch('receivedFund', function(receivedFund) {
if (receivedFund) {
var currentAddr;
for(var i=0;i<$rootScope.addrInfos.length;i++) {
var addrinfo = $rootScope.addrInfos[i];
if (addrinfo.address.toString() == receivedFund[1] && !addrinfo.isChange) {
currentAddr = addrinfo.address.toString();
break;
}
}
if (currentAddr) {
$notification.funds('Received fund', currentAddr, receivedFund);
beep.play();
}
}
});
$scope.isActive = function(item) {
if (item.link && item.link.replace('#','') == $location.path()) {
return true;
@ -46,6 +64,7 @@ angular.module('copay.header').controller('HeaderController',
var w = $rootScope.wallet;
w.connectToAll();
controllerUtils.updateBalance(function() {
$rootScope.$digest();
});
};

View file

@ -1,7 +1,7 @@
'use strict';
angular.module('copay.controllerUtils')
.factory('controllerUtils', function($rootScope, $sce, $location, Socket, video) {
.factory('controllerUtils', function($rootScope, $sce, $location, $notification, Socket, video) {
var root = {};
var bitcore = require('bitcore');
@ -49,6 +49,9 @@ angular.module('copay.controllerUtils')
};
$rootScope.$digest();
};
$notification.enableHtml5Mode(); // for chrome: if support, enable it
w.on('badMessage', function(peerId) {
$rootScope.$flashMessage = {
type: 'error',
@ -114,7 +117,6 @@ angular.module('copay.controllerUtils')
w.getBalance(function(balance, balanceByAddr, safeBalance) {
$rootScope.totalBalance = balance;
$rootScope.balanceByAddr = balanceByAddr;
$rootScope.selectedAddr = $rootScope.addrInfos[0].address.toString();
$rootScope.availableBalance = safeBalance;
$rootScope.updatingBalance = false;
console.log('Done updating balance.'); //TODO
@ -189,6 +191,7 @@ angular.module('copay.controllerUtils')
newAddrs.forEach(function(addr) {
Socket.on(addr, function(txid) {
console.log('Received!', txid);
$rootScope.receivedFund = [txid, addr];
root.updateBalance(function(){
$rootScope.$digest();
});

View file

@ -3,12 +3,13 @@
angular.module('notifications', []).
factory('$notification', ['$timeout',function($timeout){
console.log('notification service online');
// console.log('notification service online');
var notifications = JSON.parse(localStorage.getItem('$notifications')) || [],
queue = [];
var settings = {
info: { duration: 5000, enabled: true },
funds: { duration: 5000, enabled: true },
warning: { duration: 5000, enabled: true },
error: { duration: 5000, enabled: true },
success: { duration: 5000, enabled: true },
@ -115,6 +116,11 @@ angular.module('notifications', []).
console.log(title, content);
return this.awesomeNotify('info','loop', title, content, userData);
},
funds: function(title, content, userData){
console.log(title, content);
return this.awesomeNotify('funds','bitcoin', title, content, userData);
},
error: function(title, content, userData){
return this.awesomeNotify('error', 'remove', title, content, userData);