Merge pull request #738 from matiu/bug/unitname

Bug/unitname
This commit is contained in:
Gustavo Maximiliano Cortez 2014-06-24 15:04:42 -03:00
commit 53e0371b7f
6 changed files with 116 additions and 74 deletions

View file

@ -31,8 +31,8 @@ angular.module('copayApp.controllers').controller('AddressesController',
for (var i = 0; i < addrInfos.length; i++) { for (var i = 0; i < addrInfos.length; i++) {
var addrinfo = addrInfos[i]; var addrinfo = addrInfos[i];
$scope.addresses.push({ $scope.addresses.push({
'address': addrinfo.address.toString(), 'address': addrinfo.addressStr,
'balance': $rootScope.balanceByAddr ? $rootScope.balanceByAddr[addrinfo.address.toString()] : 0, 'balance': $rootScope.balanceByAddr ? $rootScope.balanceByAddr[addrinfo.addressStr] : 0,
'isChange': addrinfo.isChange 'isChange': addrinfo.isChange
}); });
} }
@ -41,5 +41,4 @@ angular.module('copayApp.controllers').controller('AddressesController',
$rootScope.receivedFund = null; $rootScope.receivedFund = null;
} }
} }
}); });

View file

@ -209,8 +209,10 @@ PublicKeyRing.prototype.getAddressesInfo = function(opts) {
var ret = []; var ret = [];
if (!opts.excludeChange) { if (!opts.excludeChange) {
for (var i = 0; i < this.indexes.getChangeIndex(); i++) { for (var i = 0; i < this.indexes.getChangeIndex(); i++) {
var a = this.getAddress(i, true);
ret.unshift({ ret.unshift({
address: this.getAddress(i, true), address: this.getAddress(i, true),
addressStr: a.toString(),
isChange: true isChange: true
}); });
} }
@ -218,8 +220,10 @@ PublicKeyRing.prototype.getAddressesInfo = function(opts) {
if (!opts.excludeMain) { if (!opts.excludeMain) {
for (var i = 0; i < this.indexes.getReceiveIndex(); i++) { for (var i = 0; i < this.indexes.getReceiveIndex(); i++) {
var a = this.getAddress(i, false);
ret.unshift({ ret.unshift({
address: this.getAddress(i, false), address: a,
addressStr: a.toString(),
isChange: false isChange: false
}); });
} }

View file

@ -14,6 +14,8 @@ angular.module('copayApp.services')
}; };
root.logout = function() { root.logout = function() {
Socket.removeAllListeners();
$rootScope.wallet = null; $rootScope.wallet = null;
delete $rootScope['wallet']; delete $rootScope['wallet'];
video.close(); video.close();
@ -70,10 +72,35 @@ angular.module('copayApp.services')
}); });
}; };
root.setupRootVariables = function() {
$rootScope.unitName = config.unitName;
$rootScope.txAlertCount = 0;
$rootScope.insightError = 0;
$rootScope.isCollapsed = true;
$rootScope.$watch('insightError', function(status) {
if (status === -1) {
$rootScope.$flashMessage = {
type: 'success',
message: 'Networking Restored :)',
};
$rootScope.insightError = 0;
}
});
$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);
}
});
};
root.startNetwork = function(w, $scope) { root.startNetwork = function(w, $scope) {
Socket.removeAllListeners();
root.setupRootVariables();
root.installStartupHandlers(w, $scope); root.installStartupHandlers(w, $scope);
root.setSocketHandlers();
var handlePeerVideo = function(err, peerID, url) { var handlePeerVideo = function(err, peerID, url) {
if (err) { if (err) {
@ -103,8 +130,8 @@ angular.module('copayApp.services')
}); });
w.on('publicKeyRingUpdated', function(dontDigest) { w.on('publicKeyRingUpdated', function(dontDigest) {
root.setSocketHandlers();
root.updateAddressList(); root.updateAddressList();
root.setSocketHandlers();
if (!dontDigest) { if (!dontDigest) {
$rootScope.$digest(); $rootScope.$digest();
} }
@ -273,20 +300,23 @@ angular.module('copayApp.services')
if (!$rootScope.wallet) return; if (!$rootScope.wallet) return;
var currentAddrs = Socket.getListeners(); var currentAddrs = Socket.getListeners();
var addrs = $rootScope.wallet.getAddressesStr(); var allAddrs = $rootScope.addrInfos;
var newAddrs = []; var newAddrs = [];
for (var i in addrs) { for (var i in allAddrs) {
var a = addrs[i]; var a = allAddrs[i];
if (!currentAddrs[a]) if (!currentAddrs[a.addressStr])
newAddrs.push(a); newAddrs.push(a);
} }
for (var i = 0; i < newAddrs.length; i++) { for (var i = 0; i < newAddrs.length; i++) {
Socket.emit('subscribe', newAddrs[i]); Socket.emit('subscribe', newAddrs[i].addressStr);
} }
newAddrs.forEach(function(addr) { newAddrs.forEach(function(a) {
Socket.on(addr, function(txid) { Socket.on(a.addressStr, function(txid) {
$rootScope.receivedFund = [txid, addr];
if (!a.isChange)
notification.funds('Received fund', a.addressStr);
root.updateBalance(function() { root.updateBalance(function() {
$rootScope.$digest(); $rootScope.$digest();
}); });

View file

@ -68,7 +68,7 @@ angular.module('copayApp.services').factory('Socket',
removeAllListeners: function() { removeAllListeners: function() {
for (var i = 0; i < listeners.length; i++) { for (var i = 0; i < listeners.length; i++) {
var details = listeners[i]; var details = listeners[i];
socket.removeListener(details.event, details.fn); socket.removeAllListeners(details.event);
} }
listeners = []; listeners = [];

View file

@ -147,11 +147,13 @@ describe('PublicKeyRing model', function() {
for (var i = 0; i < 2; i++) for (var i = 0; i < 2; i++)
w.generateAddress(isChange); w.generateAddress(isChange);
var as = w.getAddresses(); var as = w.getAddressesInfo();
as.length.should.equal(4); as.length.should.equal(4);
for (var j in as) { for (var j in as) {
var a = as[j]; var a = as[j];
a.isValid().should.equal(true); a.address.isValid().should.equal(true);
a.addressStr.should.equal(a.address.toString());
a.isChange.should.equal([false, false, true, true][j]);
} }
}); });

View file

@ -70,65 +70,72 @@ describe("Unit: Walletfactory Service", function() {
}); });
describe("Unit: controllerUtils", function() { describe("Unit: controllerUtils", function() {
beforeEach(angular.mock.module('copayApp.services')); beforeEach(angular.mock.module('copayApp.services'));
it('should updateBalance in bits', inject(function(controllerUtils, $rootScope) { it('should updateBalance in bits', inject(function(controllerUtils, $rootScope) {
expect(controllerUtils.updateBalance).not.to.equal(null); expect(controllerUtils.updateBalance).not.to.equal(null);
scope = $rootScope.$new(); scope = $rootScope.$new();
$rootScope.wallet = new FakeWallet(); $rootScope.wallet = new FakeWallet();
var addr = '1CjPR7Z5ZSyWk6WtXvSFgkptmpoi4UM9BC'; var addr = '1CjPR7Z5ZSyWk6WtXvSFgkptmpoi4UM9BC';
var a = {}; var a = {};
a[addr] = 100; a[addr] = 100;
//SATs //SATs
$rootScope.wallet.set(100000001, 90000002, a); $rootScope.wallet.set(100000001, 90000002, a);
//retuns values in DEFAULT UNIT(bits) //retuns values in DEFAULT UNIT(bits)
controllerUtils.updateBalance(function() { controllerUtils.updateBalance(function() {
expect($rootScope.totalBalanceBTC).to.be.equal('1.0000'); expect($rootScope.totalBalanceBTC).to.be.equal('1.0000');
expect($rootScope.availableBalanceBTC).to.be.equal('0.9000'); expect($rootScope.availableBalanceBTC).to.be.equal('0.9000');
expect($rootScope.totalBalance).to.be.equal(1000000.01); expect($rootScope.totalBalance).to.be.equal(1000000.01);
expect($rootScope.availableBalance).to.be.equal(900000.02); expect($rootScope.availableBalance).to.be.equal(900000.02);
expect($rootScope.addrInfos).not.to.equal(null); expect($rootScope.addrInfos).not.to.equal(null);
expect($rootScope.addrInfos[0].address).to.equal(addr); expect($rootScope.addrInfos[0].address).to.equal(addr);
});
}));
it('should set the rootScope', inject(function(controllerUtils, $rootScope) {
controllerUtils.setupRootVariables(function() {
expect($rootScope.txAlertCount).to.be.equal(0);
expect($rootScope.insightError).to.be.equal(0);
expect($rootScope.isCollapsed).to.be.equal(0);
expect($rootScope.unitName).to.be.equal('bits');
});
}));
}); });
}));
describe("Unit: Notification Service", function() {
beforeEach(angular.mock.module('copayApp.services'));
it('should contain a notification service', inject(function(notification) {
expect(notification).not.to.equal(null);
}));
});
}); describe("Unit: Backup Service", function() {
beforeEach(angular.mock.module('copayApp.services'));
it('should contain a backup service', inject(function(backupService) {
expect(backupService).not.to.equal(null);
}));
it('should backup in file', inject(function(backupService) {
var mock = sinon.mock(window);
var expectation = mock.expects('saveAs');
backupService.download(new FakeWallet());
expectation.once();
}));
});
describe("Unit: Notification Service", function() { describe("Unit: isMobile Service", function() {
beforeEach(angular.mock.module('copayApp.services')); beforeEach(angular.mock.module('copayApp.services'));
it('should contain a notification service', inject(function(notification) { it('should contain a isMobile service', inject(function(isMobile) {
expect(notification).not.to.equal(null); expect(isMobile).not.to.equal(null);
})); }));
}); it('should not detect mobile by default', inject(function(isMobile) {
isMobile.any().should.equal(false);
describe("Unit: Backup Service", function() { }));
beforeEach(angular.mock.module('copayApp.services')); it('should detect mobile if user agent is Android', inject(function(isMobile) {
it('should contain a backup service', inject(function(backupService) { navigator.__defineGetter__('userAgent', function() {
expect(backupService).not.to.equal(null); return 'Android 2.2.3';
})); });
it('should backup in file', inject(function(backupService) { isMobile.any().should.equal(true);
var mock = sinon.mock(window); }));
var expectation = mock.expects('saveAs'); });
backupService.download(new FakeWallet());
expectation.once();
}));
});
describe("Unit: isMobile Service", function() {
beforeEach(angular.mock.module('copayApp.services'));
it('should contain a isMobile service', inject(function(isMobile) {
expect(isMobile).not.to.equal(null);
}));
it('should not detect mobile by default', inject(function(isMobile) {
isMobile.any().should.equal(false);
}));
it('should detect mobile if user agent is Android', inject(function(isMobile) {
navigator.__defineGetter__('userAgent', function() {
return 'Android 2.2.3';
});
isMobile.any().should.equal(true);
}));
});