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

@ -32,15 +32,21 @@
</div>
<div class="large-4 medium-4 columns line-dashed-v">
Balance:
<span ng-if="$root.updatingBalance">...</span>
<span ng-if="!$root.updatingBalance">{{totalBalance || 0}}</span>
<i class="fi-bitcoin"></i><br>
<span ng-if="$root.updatingBalance">
<i class="fi-bitcoin-circle icon-rotate spinner"></i>
</span>
<span ng-if="!$root.updatingBalance">{{totalBalance || 0}}
<i class="fi-bitcoin"></i>
</span>
</div>
<div class="large-4 medium-4 columns">
Available to Spend:
<span ng-if="$root.updatingBalance">...</span>
<span ng-if="!$root.updatingBalance">{{availableBalance || 0}}</span>
<i class="fi-bitcoin"></i>
<span ng-if="$root.updatingBalance">
<i class="fi-bitcoin-circle icon-rotate spinner"></i>
</span>
<span ng-if="!$root.updatingBalance">{{availableBalance || 0}}
<i class="fi-bitcoin"></i>
</span>
</div>
</div>
@ -317,37 +323,58 @@
<div class="addresses" ng-controller="AddressesController">
<div ng-show='$root.wallet.publicKeyRing.isComplete()'>
<div class="row">
<div class="large-9 medium-12 columns" ng-if="addrInfos[0]">
<div class="large-9 medium-12 columns" ng-if="addresses[0]">
<div class="large-8 medium-8 columns">
<a class="panel radius db" ng-repeat="addrInfo in addrInfos" ng-click="$root.selectedAddr = addrInfo.address.toString()" ng-class="selectAddr('{{addrInfo.address.toString()}}')">
<span>{{addrInfo.address.toString()}}</span>
<span ng-if="addrInfo.isChange">(change)</span>
<a class="panel radius db" ng-repeat="addr in addresses"
ng-click="selectAddress(addr)"
ng-class="{selected : addr.address == selectedAddr.address}">
<span>{{addr.address}}</span>
<span ng-if="addr.isChange">(change)</span>
<span class="right">
<span ng-if="$root.updatingBalance">...</span>
<span ng-if="!$root.updatingBalance">{{balanceByAddr[addrInfo.address.toString()] || 0}}</span>
<i class="fi-bitcoin"></i>
<span ng-if="$root.receivedFund[1] == addr.address">
<span ng-if="$root.updatingBalance">
<i class="fi-bitcoin-circle icon-rotate spinner"></i>
</span>
<span ng-if="!$root.updatingBalance">
{{$root.balanceByAddr[addr.address]}}
<i class="fi-bitcoin"></i>
</span>
</span>
<span ng-if="$root.receivedFund[1] != addr.address">
{{addr.balance || 0}}
<i class="fi-bitcoin"></i>
</span>
</span>
</a>
</div>
<div class="large-4 medium-4 columns line-dashed-v text-center">
<qrcode size="160" data="{{selectedAddr}}"></qrcode>
<div class="large-4 medium-4 columns line-dashed-v text-center" ng-show="selectedAddr">
<qrcode size="160" data="{{selectedAddr.address}}"></qrcode>
<p class="m10t">
<strong>
<span ng-if="$root.updatingBalance">...</span>
<span ng-if="!$root.updatingBalance">{{balanceByAddr[selectedAddr] || 0}}</span>
<i class="fi-bitcoin"></i>
<span ng-if="$root.receivedFund[1] == selectedAddr.address">
<span ng-if="$root.updatingBalance">
<i class="fi-bitcoin-circle icon-rotate spinner"></i>
</span>
<span ng-if="!$root.updatingBalance">{{balanceByAddr[selectedAddr.address] || 0}}
<i class="fi-bitcoin"></i>
</span>
</span>
<span ng-if="$root.receivedFund[1] != selectedAddr.address">
{{selectedAddr.balance || 0}}
<i class="fi-bitcoin"></i>
</span>
</strong>
</p>
</div>
</div>
<div class="columns text-center m10t" ng-class="{'large-3' : !!addrInfos[0]}">
<div class="columns text-center m10t" ng-class="{'large-3' : !!addresses[0]}">
<p> Create a New <strong> Address </strong> </p>
<button class="secondary radius expandi new-address" ng-click="newAddr()"
ng-disabled="loading" loading="Creating"> Create </button>
</div>
</div>
</div>
</div>
</div>
</script>
<!-- TRANSACTIONS -->
@ -362,19 +389,17 @@
<li> <button ng-click="show()" ng-disabled="loading || !onlyPending" loading="Updating"> All </button>
</ul>
<div class="panel radius pending" ng-repeat="tx in txs | orderBy: 'createdTs':true">
<div class="txheader">
<div class="row m10">
<div class="large-8 medium-8 small-12 columns">
<div class="row" ng-repeat="out in tx.outs">
<div class="large-3 medium-3 small-3 columns ellipsis"> {{out.value}} <i class="fi-bitcoin size-18"></i></div>
<div class="large-1 medium-1 small-2 columns fi-arrow-right size-24"> </div>
<div class="large-8 medium-8 small-7 columns ellipsis"> {{out.address}} </div>
</div>
</div>
<div class="large-4 medium-4 small-12 columns text-right">
<h6>{{tx.createdTs | amCalendar}}</h6>
<div class="txheader row m10">
<div class="large-8 medium-8 small-12 columns">
<div class="row" ng-repeat="out in tx.outs">
<div class="large-3 medium-3 small-3 columns ellipsis"> {{out.value}} <i class="fi-bitcoin size-18"></i></div>
<div class="large-1 medium-1 small-2 columns fi-arrow-right size-24"> </div>
<div class="large-8 medium-8 small-7 columns ellipsis"> {{out.address}} </div>
</div>
</div>
<div class="large-4 medium-4 small-12 columns text-right">
<h6>{{tx.createdTs | amCalendar}}</h6>
</div>
</div>
<div class="tx-copayers">
@ -409,7 +434,7 @@
</div>
<div class="row m10">
<div class="large-5 columns" ng-show="!tx.sentTs" style="padding-left: 5px;">
<div class="large-5 medium-5 columns" ng-show="!tx.sentTs">
<div ng-show="!tx.signedByUs && !tx.rejectedByUs && !tx.finallyRejected && tx.missingSignatures">
<button class="secondary radius m10r" ng-click="sign(tx.ntxid)" ng-disabled="loading" loading="Signing">
<i class="fi-check"></i> Sign
@ -418,14 +443,14 @@
<i class="fi-x" ></i> Reject
</button>
</div>
<span ng-show="!tx.missingSignatures && !tx.sentTs">
<div ng-show="!tx.missingSignatures && !tx.sentTs">
<button class="primary radius" ng-click="send(tx.ntxid)" ng-disabled="loading" loading="Broadcasting"> <i class=".fi-upload-cloud"></i>
Broadcast Transaction
</button>
</span>
</div>
</div>
<div class="large-7 columns text-right">
<div class="large-7 medium-7 columns text-right">
<div ng-show="tx.finallyRejected" class="text-warning m10b">
Transaction finally rejected
</div>

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);

BIN
sound/transaction.mp3 Normal file

Binary file not shown.