add usage to wallets table

This commit is contained in:
Matias Alejo Garcia 2014-12-01 17:21:39 -03:00
commit 2402a22f0a
5 changed files with 81 additions and 7 deletions

View file

@ -1,5 +1,5 @@
'use strict';
angular.module('copayApp.controllers').controller('ProfileController', function($scope, $rootScope, $location, $modal, backupService, identityService) {
angular.module('copayApp.controllers').controller('ProfileController', function($scope, $rootScope, $location, $modal, $filter, backupService, identityService) {
$scope.username = $rootScope.iden.getName();
$scope.isSafari = Object.prototype.toString.call(window.HTMLElement).indexOf('Constructor') > 0;
@ -25,11 +25,29 @@ angular.module('copayApp.controllers').controller('ProfileController', function(
});
};
$scope.setWallets = function() {
if (!$rootScope.iden) return;
$scope.wallets=$rootScope.iden.listWallets();
$scope.init = function() {
if ($rootScope.quotaPerItem) {
$scope.perItem = $filter('noFractionNumber')($rootScope.quotaPerItem/1000,1);
$scope.nrWallets =parseInt($rootScope.quotaItems) - 1;
}
};
$scope.setWallets = function() {
if (!$rootScope.iden) return;
var wallets = $rootScope.iden.listWallets();
var max =$rootScope.quotaPerItem;
_.each(wallets, function(w) {
var bits = w.sizes().total;
w.kb = $filter('noFractionNumber')(bits/1000, 1);
if (max) {
w.usage = $filter('noFractionNumber')(bits/max * 100, 0);
}
});
$scope.wallets = wallets;
};
$scope.downloadWalletBackup = function(w) {
if (!w) return;

View file

@ -74,6 +74,30 @@ InsightStorage.prototype.getPassphrase = function() {
return bitcore.util.twoSha256(this.getKey()).toString('base64');
};
/**
* XmlHttpRequest's getAllResponseHeaders() method returns a string of response
* headers according to the format described here:
* http://www.w3.org/TR/XMLHttpRequest/#the-getallresponseheaders-method
* This method parses that string into a user-friendly key/value pair object.
*/
InsightStorage.parseResponseHeaders = function (headerStr) {
var headers = {};
if (!headerStr) {
return headers;
}
var headerPairs = headerStr.split('\u000d\u000a');
for (var i = 0, len = headerPairs.length; i < len; i++) {
var headerPair = headerPairs[i];
var index = headerPair.indexOf('\u003a\u0020');
if (index > 0) {
var key = headerPair.substring(0, index);
var val = headerPair.substring(index + 2);
headers[key] = val;
}
}
return headers;
}
InsightStorage.prototype._makeGetRequest = function(passphrase, key, callback) {
var authHeader = new buffers.Buffer(this.email + ':' + passphrase).toString('base64');
var retrieveUrl = this.storeUrl + '/retrieve';
@ -96,7 +120,7 @@ InsightStorage.prototype._makeGetRequest = function(passphrase, key, callback) {
if (response.statusCode !== 200) {
return callback('Connection error');
}
return callback(null, body, response.getAllResponseHeaders());
return callback(null, body, InsightStorage.parseResponseHeaders(response.getAllResponseHeaders()));
}
);
};

View file

@ -67,6 +67,21 @@ angular.module('copayApp.services')
};
root.setServerStatus = function(headers) {
if (!headers)
return;
if (headers['X-Email-Needs-Validation'])
$rootScope.needsEmailConfirmation = true;
else
$rootScope.needsEmailConfirmation = null;
if (headers['X-Quota-Per-Item'])
$rootScope.quotaPerItem = parseInt(headers['X-Quota-Per-Item']);
if (headers['X-Quota-Items-Limit'])
$rootScope.quotaItems = parseInt(headers['X-Quota-Items-Limit']);
};
root.open = function(email, password, cb) {
var opts = {
@ -81,6 +96,7 @@ angular.module('copayApp.services')
copay.Identity.open(opts, function(err, iden, headers) {
if (err) return cb(err);
root.setServerStatus(headers);
root.bind(iden);
return cb(null, iden);
});