Skip to content
This repository has been archived by the owner on Jul 1, 2024. It is now read-only.

Commit

Permalink
Add email loading state until user info resolved
Browse files Browse the repository at this point in the history
  • Loading branch information
Jared Deckard committed Nov 21, 2014
1 parent 5cc4216 commit de83699
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 11 deletions.
25 changes: 21 additions & 4 deletions app/scripts/controllers/settings-email-controller.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,29 @@
angular.module('stellarClient').controller('SettingsEmailCtrl', function($scope, $http, $state, $q, session, singletonPromise) {
$scope.loading = true;
$scope.error = null;

$scope.$on('settings-refresh', function () {
$scope.email = session.getUser().getEmailAddress();
$scope.emailVerified = session.getUser().isEmailVerified();
$scope.verifyToken = null;
$scope.resetEmailState();
$scope.refresh();
});

$scope.refresh = function() {
$scope.loading = true;
$scope.error = null;

session.getUserInfo()
.then(function(userInfo) {
$scope.loading = false;

$scope.email = session.getUser().getEmailAddress();
$scope.emailVerified = session.getUser().isEmailVerified();
$scope.verifyToken = null;
$scope.resetEmailState();
})
.catch(function(err) {
$scope.error = "Unable to contact server!";
});
};

$scope.resetEmailState = function () {
if ($scope.email) {
$scope.emailState = 'added';
Expand Down
19 changes: 13 additions & 6 deletions app/scripts/services/session.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ var sc = angular.module('stellarClient');

var cache = {};

sc.service('session', function($rootScope, $http, $timeout, StellarNetwork, Wallet, contacts, UserPrivateInfo) {
var Session = function() {};
sc.service('session', function($rootScope, $http, $timeout, $q, StellarNetwork, Wallet, contacts, UserPrivateInfo) {
var Session = function() {
this.waitingForUserInfo = $q.defer();
};

Session.prototype.get = function(name){ return cache[name]; };
Session.prototype.put = function(name, value){
Expand Down Expand Up @@ -85,12 +87,13 @@ sc.service('session', function($rootScope, $http, $timeout, StellarNetwork, Wall
UserPrivateInfo.load(this.get('username'), this.get('wallet').keychainData.updateToken)
.then(function (user) {
self.put('userPrivateInfo', user);
})
.then(function () {
self.waitingForUserInfo.resolve(user);
$rootScope.$broadcast('userLoaded');
})
.then(function () {

self.identifyToAnalytics();
})
.catch(function(err) {
self.waitingForUserInfo.reject(err);
});

// check for the most up to date fairy address
Expand Down Expand Up @@ -165,6 +168,10 @@ sc.service('session', function($rootScope, $http, $timeout, StellarNetwork, Wall
return this.get('userPrivateInfo');
};

Session.prototype.getUserInfo = function() {
return this.waitingForUserInfo.promise;
};

Session.prototype.identifyToAnalytics = function() {
window.analytics.identify(this.get('username'), this.getAnalyticsTraits());
};
Expand Down
16 changes: 15 additions & 1 deletion app/states/settings.html
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,21 @@ <h1 class="title">Settings<span class="link-dashboard"><a href="/#/dashboard">&#
<div class="row" ng-controller="SettingsEmailCtrl">
<div class="settings-label col-md-3 col-xs-6">EMAIL</div>
<div class="settings-control col-md-9 col-xs-6">
<div class="row">
<!-- User data hasn't loaded yet -->
<div class="row" ng-show="loading">
<div class="icon-col col-xs-1">
<span class="icon icon-email"/>
</div>
<div class="col-xs-10">Loading...</div>
</div>
<div class="row" ng-show="error">
<div class="icon-col col-xs-1">
<span class="icon icon-email"/>
</div>
<div class="col-xs-10">{{ error }}</div>
</div>
<!-- User data has loaded -->
<div class="row" ng-hide="loading || error">
<div class="icon-col col-xs-1">
<span class="icon icon-email"/>
</div>
Expand Down

0 comments on commit de83699

Please sign in to comment.