add usage to wallets table

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

View File

@ -49,6 +49,12 @@
<i class="fi-loop icon-rotate"></i>
<span translate> <strong class="size-16">Network Error</strong>.<br> Attempting to reconnect..</span>
</span>
<span class="status" ng-if="$root.needsEmailConfirmation">
<i class="fi-alert"></i>
<span translate> <strong class="size-16">email not confirmed</strong>.<br> Please confirm your email address
using the confirmation link at the message we sent you</span>
</span>
<nav class="tab-bar" ng-if="$root.iden" >
<section class="left-small">
<a class="left-off-canvas-toggle menu-icon" ><span></span></a>

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

View File

@ -1,4 +1,4 @@
<div class="backup" ng-controller="ProfileController" ng-init="setWallets()">
<div class="backup" ng-controller="ProfileController" ng-init="init()">
<div class="row hide-for-large-up">
<div class="large-12 medium-12 small-12 columns">
<h1>{{$root.title}}</h1>
@ -39,7 +39,7 @@
</div>
<div class="line-dashed-h m20b"></div>
<div class="row" ng-init="getWallets()">
<div class="row" ng-init="setWallets()">
<div class="large-12 columns">
<h2>Manage wallets</h2>
<table>
@ -72,7 +72,8 @@
</td>
<td>
<span>
{{item.sizes().total/1000}} kB
{{item.kb}} kB
({{item.usage}}%)
</span>
</td>
@ -92,6 +93,15 @@
</tr>
</tbody>
</table>
<div class="size-12">
<div ng-if="perItem">
<p> Your current Insight server usage quotas are: {{perItem}}kB per walelt and up to {{nrWallets}} wallets.
</div>
<div ng-if="$root.needsEmailConfirmation">
<p> <i class="fi-alert"></i> Confirming for email with increase your storage usage limits.
</div>
</div>
</div>
</div>
</div>