-
-
Addresses (available to spend)
+
-
{{balanceByAddr[addr]}}
+
+
+ ...
+ {{balanceByAddr[selectedAddr] || 0}}
+
+
+
-
+
Create a New Address
-
+
diff --git a/js/app.js b/js/app.js
index 6f64a9b30..aa9cdfde1 100644
--- a/js/app.js
+++ b/js/app.js
@@ -1,5 +1,8 @@
'use strict';
+
+var copay = require('copay');
+
var copayApp = window.copayApp = angular.module('copay',[
'ngRoute',
'mm.foundation',
diff --git a/js/controllers/addresses.js b/js/controllers/addresses.js
index 6b2ee0e3c..0a5470ea5 100644
--- a/js/controllers/addresses.js
+++ b/js/controllers/addresses.js
@@ -2,36 +2,21 @@
angular.module('copay.addresses').controller('AddressesController',
function($scope, $rootScope, controllerUtils) {
- $scope.title = 'Home';
- $scope.oneAtATime = true;
- $scope.addrBalance = {};
var w = $rootScope.wallet;
-
- var _updateBalance = function () {
- controllerUtils.setSocketHandlers();
- w.getBalance(true, function (balance, balanceByAddr, isMain) {
- if (balanceByAddr && Object.keys(balanceByAddr).length) {
- $rootScope.balanceByAddr = balanceByAddr;
- $scope.isMain = isMain;
- $scope.addrs = Object.keys(balanceByAddr);
- $scope.selectedAddr = $scope.addrs[0];
- $scope.loading = false;
- $rootScope.$digest();
- }
- });
- };
+ $scope.loading = false;
$scope.newAddr = function() {
$scope.loading = true;
w.generateAddress();
- _updateBalance();
+ controllerUtils.updateBalance(function() {
+ $scope.loading = false;
+ $rootScope.$digest();
+ });
};
$scope.selectAddr = function(addr) {
$scope.selectedAddr = addr;
};
- _updateBalance();
- w.on('refresh', _updateBalance);
});
diff --git a/js/controllers/header.js b/js/controllers/header.js
index f9cf9e1a6..e8a25141e 100644
--- a/js/controllers/header.js
+++ b/js/controllers/header.js
@@ -40,7 +40,13 @@ angular.module('copay.header').controller('HeaderController',
w.disconnect();
controllerUtils.logout();
}
- $rootScope.flashMessage = {};
+ $scope.clearFlashMessage();
+ };
+
+ $scope.refresh = function() {
+ controllerUtils.updateBalance(function() {
+ $rootScope.$digest();
+ });
};
$scope.clearFlashMessage = function() {
diff --git a/js/init.js b/js/init.js
index d9e3481d8..4c8f29b30 100644
--- a/js/init.js
+++ b/js/init.js
@@ -1,5 +1,5 @@
'use strict';
-var copay = require('copay');
+
angular.element(document).ready(function() {
// Init the app
angular.bootstrap(document, ['copay']);
diff --git a/js/models/core/PublicKeyRing.js b/js/models/core/PublicKeyRing.js
index fc73e784c..a99f2c8cc 100644
--- a/js/models/core/PublicKeyRing.js
+++ b/js/models/core/PublicKeyRing.js
@@ -143,7 +143,6 @@ PublicKeyRing.prototype.addCopayer = function (newEpk) {
return newEpk;
};
-
PublicKeyRing.prototype.getPubKeys = function (index, isChange) {
this._checkKeys();
@@ -159,6 +158,7 @@ PublicKeyRing.prototype.getPubKeys = function (index, isChange) {
this.publicKeysCache[path] = pubKeys.map(function(pk){return pk.toString('hex');});
} else {
pubKeys = pubKeys.map(function(s){return new Buffer(s,'hex')});
+ //console.log('public keys cache HIT');
}
return pubKeys;
@@ -183,21 +183,12 @@ PublicKeyRing.prototype.getRedeemScript = function (index, isChange) {
// TODO this could be cached
PublicKeyRing.prototype.getAddress = function (index, isChange) {
- this._checkIndexRange(index, isChange);
var script = this.getRedeemScript(index,isChange);
return Address.fromScript(script, this.network.name);
};
-// TODO this could be cached
-PublicKeyRing.prototype._addScriptMap = function (map, index, isChange) {
- this._checkIndexRange(index, isChange);
- var script = this.getRedeemScript(index,isChange);
- map[Address.fromScript(script, this.network.name).toString()] = script.getBuffer().toString('hex');
-};
-
// TODO this could be cached
PublicKeyRing.prototype.getScriptPubKeyHex = function (index, isChange) {
- this._checkIndexRange(index, isChange);
var addr = this.getAddress(index,isChange);
return Script.createP2SH(addr.payload()).getBuffer().toString('hex');
};
@@ -218,21 +209,39 @@ PublicKeyRing.prototype.generateAddress = function(isChange) {
};
-PublicKeyRing.prototype.getAddresses = function(onlyMain) {
+PublicKeyRing.prototype.getAddresses = function(excludeChange) {
+ return this.getAddressesInfo(excludeChange).map(function(info) {
+ return info.address;
+ });
+};
+
+PublicKeyRing.prototype.getAddressesInfo = function(excludeChange) {
var ret = [];
-
- for (var i=0; i