diff --git a/public/views/preferences.html b/public/views/preferences.html
index bf7db5528..696579fdc 100644
--- a/public/views/preferences.html
+++ b/public/views/preferences.html
@@ -50,6 +50,10 @@
Advanced
+
+
+ Glidera
+
diff --git a/public/views/preferencesGlidera.html b/public/views/preferencesGlidera.html
new file mode 100644
index 000000000..381d7c02e
--- /dev/null
+++ b/public/views/preferencesGlidera.html
@@ -0,0 +1,94 @@
+
+
+
+
+
+
+
+
+ Get OAuth Code
+
+
+
+
+
+
+ Revoke Token
+
+
+
Permissions
+
+ - personal_info: {{glidera.permission.personal_info}}
+
- transact: {{glidera.permission.transact}}
+
- transaction_history: {{glidera.permission.transaction_history}}
+
- view_email_address: {{glidera.permission.view_email_address}}
+
+
+
Email
+
+ - Email: {{glidera.email.email}}
+
- userEmailIsSetup: {{glidera.email.userEmailIsSetup}}
+
+
+
Personal Info
+
+ - first name: {{glidera.personalInfo.firstName}}
+
- middleName: {{glidera.personalInfo.middleName}}
+
- last name: {{glidera.personalInfo.lastName}}
+
- birthDate: {{glidera.personalInfo.birthDate}}
+
- address1: {{glidera.personalInfo.address1}}
+
- address2: {{glidera.personalInfo.address2}}
+
- city: {{glidera.personalInfo.city}}
+
- state: {{glidera.personalInfo.state}}
+
- zipCode: {{glidera.personalInfo.zipCode}}
+
- countryCode: {{glidera.personalInfo.countryCode}}
+
- occupation: {{glidera.personalInfo.occupation}}
+
- basicInfoState: {{glidera.personalInfo.basicInfoState}}
+
+
+
Status
+
+ - userCanTransact: {{glidera.status.userCanTransact}}
+
- userCanBuy: {{glidera.status.userCanBuy}}
+
- userCanSell: {{glidera.status.userCanSell}}
+
- userEmailIsSetup: {{glidera.status.userEmailIsSetup}}
+
- userPhoneIsSetup: {{glidera.status.userPhoneIsSetup}}
+
- userBankAccountIsSetup: {{glidera.status.userBankAccountIsSetup}}
+
- personalInfoState: {{glidera.status.personalInfoState}}
+
- bankAccountState: {{glidera.status.bankAccountState}}
+
- country: {{glidera.status.country}}
+
+
+
Limits
+
+ - dailyBuy: {{glidera.limits.dailyBuy}}
+
- dailySell: {{glidera.limits.dailySell}}
+
- monthlyBuy: {{glidera.limits.monthlyBuy}}
+
- monthlySell: {{glidera.limits.monthlySell}}
+
- dailyBuyRemaining: {{glidera.limits.dailyBuyRemaining}}
+
- dailySellRemaining: {{glidera.limits.dailySellRemaining}}
+
- monthlyBuyRemaining: {{glidera.limits.monthlyBuyRemaining}}
+
- monthlySellRemaining: {{glidera.limits.monthlySellRemaining}}
+
- currency: {{glidera.limits.currency}}
+
- transactDisabledPendingFirstTransaction: {{glidera.limits.transactDisabledPendingFirstTransaction}}
+
+
+
+
+
+
+
+
+
diff --git a/public/views/walletHome.html b/public/views/walletHome.html
index 65e1ab513..2488bd6a0 100644
--- a/public/views/walletHome.html
+++ b/public/views/walletHome.html
@@ -112,6 +112,13 @@
ng-style="{'background-color':index.backgroundColor}">{{ (index.alias || index.walletName) | limitTo: 1}}
+
+
+ Glidera
+
+
Preferences
diff --git a/src/js/controllers/index.js b/src/js/controllers/index.js
index 55c0fda22..bde992c7b 100644
--- a/src/js/controllers/index.js
+++ b/src/js/controllers/index.js
@@ -113,6 +113,8 @@ angular.module('copayApp.controllers').controller('indexController', function($r
self.pendingTxProposalsCountForUs = null;
self.setSpendUnconfirmed();
+ self.glideraToken = null;
+
$timeout(function() {
self.hasProfile = true;
self.noFocusedWallet = false;
@@ -134,6 +136,7 @@ angular.module('copayApp.controllers').controller('indexController', function($r
self.copayers = [];
self.updateColor();
self.updateAlias();
+ self.initGlidera();
storageService.getBackupFlag(self.walletId, function(err, val) {
self.needsBackup = self.network == 'testnet' ? false : !val;
@@ -843,6 +846,13 @@ angular.module('copayApp.controllers').controller('indexController', function($r
}), 'name');
};
+ self.initGlidera = function() {
+ storageService.getGlideraToken(self.network, function(err, val) {
+ if (err) return;
+ self.glideraToken = val;
+ });
+ };
+
// UX event handlers
$rootScope.$on('Local/ColorUpdated', function(event) {
self.updateColor();
@@ -892,6 +902,10 @@ angular.module('copayApp.controllers').controller('indexController', function($r
});
});
+ $rootScope.$on('Local/GlideraTokenUpdated', function() {
+ self.initGlidera();
+ });
+
$rootScope.$on('Local/UnitSettingUpdated', function(event) {
self.updateAll();
self.updateTxHistory();
diff --git a/src/js/controllers/preferencesGlidera.js b/src/js/controllers/preferencesGlidera.js
new file mode 100644
index 000000000..5234f9b1a
--- /dev/null
+++ b/src/js/controllers/preferencesGlidera.js
@@ -0,0 +1,55 @@
+'use strict';
+
+angular.module('copayApp.controllers').controller('preferencesGlideraController',
+ function($scope, $timeout, profileService, go, glideraService, storageService) {
+
+ this.authenticateUrl = glideraService.getOauthCodeUrl();
+
+ this.init = function(token) {
+ var self = this;
+ glideraService.getPermissions(token, function(error, permission) {
+ self.permission = permission;
+ });
+
+ glideraService.getEmail(token, function(error, email) {
+ self.email = email;
+ });
+
+ glideraService.getPersonalInfo(token, function(error, info) {
+ self.personalInfo = info;
+ });
+
+ glideraService.getStatus(token, function(error, status) {
+ self.status = status;
+ });
+
+ glideraService.getLimits(token, function(error, limits) {
+ self.limits = limits;
+ });
+ };
+
+ this.submit = function(code) {
+ var fc = profileService.focusedClient;
+ glideraService.getToken(code, function(error, data) {
+ if (data && data.status == 200) {
+ storageService.setGlideraToken(fc.credentials.network, data.data.access_token, function() {
+ $scope.$emit('Local/GlideraTokenUpdated');
+ $timeout(function() {
+ go.walletHome();
+ }, 100);
+ });
+ }
+ });
+ };
+
+ this.revokeToken = function() {
+ var fc = profileService.focusedClient;
+ storageService.removeGlideraToken(fc.credentials.network, function() {
+ $scope.$emit('Local/GlideraTokenUpdated');
+ $timeout(function() {
+ go.walletHome();
+ }, 100);
+ });
+ };
+
+ });
diff --git a/src/js/routes.js b/src/js/routes.js
index 3a36c10eb..5c175d76f 100644
--- a/src/js/routes.js
+++ b/src/js/routes.js
@@ -289,6 +289,18 @@ angular
}
})
+ .state('preferencesGlidera', {
+ url: '/preferencesGlidera',
+ templateUrl: 'views/preferencesGlidera.html',
+ walletShouldBeComplete: true,
+ needProfile: true,
+ views: {
+ 'main': {
+ templateUrl: 'views/preferencesGlidera.html'
+ },
+ }
+ })
+
.state('preferencesAdvanced', {
url: '/preferencesAdvanced',
templateUrl: 'views/preferencesAdvanced.html',
@@ -491,6 +503,7 @@ angular
preferencesColor: 12,
backup: 12,
preferencesAdvanced: 12,
+ preferencesGlidera: 12,
delete: 13,
preferencesLanguage: 12,
preferencesUnit: 12,
diff --git a/src/js/services/glideraService.js b/src/js/services/glideraService.js
new file mode 100644
index 000000000..0c744749a
--- /dev/null
+++ b/src/js/services/glideraService.js
@@ -0,0 +1,115 @@
+'use strict';
+
+angular.module('copayApp.services').factory('glideraService', function($http, $log) {
+ var root = {};
+ var HOST = 'https://sandbox.glidera.io';
+ var REDIRECT_URI = 'urn:ietf:wg:oauth:2.0:oob';
+ var CLIENT_ID = '9915b6ffa6dc3baffb87135ed3873d49';
+ var CLIENT_SECRET = 'd74eda05b9c6a228fd5c85cfbd0eb7eb';
+
+ root.getOauthCodeUrl = function() {
+ return HOST
+ + '/oauth2/auth?response_type=code&client_id='
+ + CLIENT_ID
+ + '&redirect_uri='
+ + REDIRECT_URI;
+ };
+
+ root.getToken = function(code, cb) {
+ var req = {
+ method: 'POST',
+ url: HOST + '/api/v1/oauth/token',
+ headers: {
+ 'Content-Type': 'application/json',
+ 'Accept': 'application/json'
+ },
+ data: {
+ grant_type : 'authorization_code',
+ code: code,
+ client_id : CLIENT_ID,
+ client_secret: CLIENT_SECRET,
+ redirect_uri: REDIRECT_URI
+ }
+ }
+
+ $http(req).then(function(data) {
+ $log.info('Authorization Access Token: SUCCESS');
+ return cb(null, data);
+ }, function(data) {
+ $log.error('Authorization Access Token: ERROR ' + data.statusText);
+ return cb(data.statusText);
+ });
+ };
+
+ var _get = function(endpoint, token) {
+ return {
+ method: 'GET',
+ url: HOST + '/api/v1' + endpoint,
+ headers: {
+ 'Content-Type': 'application/json',
+ 'Accept': 'application/json'
+ },
+ params: {
+ access_token: token
+ }
+ };
+ };
+
+ root.getPermissions = function(token, cb) {
+ if (!token) return cb('Invalid Token');
+ $http(_get('/oauth/token', token)).then(function(data) {
+ $log.info('Access Token Permissions: SUCCESS');
+ return cb(null, data.data);
+ }, function(data) {
+ $log.error('Access Token Permissions: ERROR ' + data.statusText);
+ return cb(data.statusText);
+ });
+ };
+
+ root.getEmail = function(token, cb) {
+ if (!token) return cb('Invalid Token');
+ $http(_get('/user/email', token)).then(function(data) {
+ $log.info('Get Email: SUCCESS');
+ return cb(null, data.data);
+ }, function(data) {
+ $log.error('Get Email: ERROR ' + data.statusText);
+ return cb(data.statusText);
+ });
+ };
+
+ root.getPersonalInfo = function(token, cb) {
+ if (!token) return cb('Invalid Token');
+ $http(_get('/user/personalinfo', token)).then(function(data) {
+ $log.info('Get Personal Info: SUCCESS');
+ return cb(null, data.data);
+ }, function(data) {
+ $log.error('Get Personal Info: ERROR ' + data.statusText);
+ return cb(data.statusText);
+ });
+ };
+
+ root.getStatus = function(token, cb) {
+ if (!token) return cb('Invalid Token');
+ $http(_get('/user/status', token)).then(function(data) {
+ $log.info('User Status: SUCCESS');
+ return cb(null, data.data);
+ }, function(data) {
+ $log.error('User Status: ERROR ' + data.statusText);
+ return cb(data.statusText);
+ });
+ };
+
+ root.getLimits = function(token, cb) {
+ if (!token) return cb('Invalid Token');
+ $http(_get('/user/limits', token)).then(function(data) {
+ $log.info('Transaction Limits: SUCCESS');
+ return cb(null, data.data);
+ }, function(data) {
+ $log.error('Transaction Limits: ERROR ' + data.statusText);
+ return cb(data.statusText);
+ });
+ };
+
+ return root;
+
+});
diff --git a/src/js/services/storageService.js b/src/js/services/storageService.js
index 1916ec032..b7208ea7a 100644
--- a/src/js/services/storageService.js
+++ b/src/js/services/storageService.js
@@ -192,5 +192,17 @@ angular.module('copayApp.services')
storage.get('remotePrefStored', cb);
};
+ root.setGlideraToken = function(network, token, cb) {
+ storage.set('glideraToken-' + network, token, cb);
+ };
+
+ root.getGlideraToken = function(network, cb) {
+ storage.get('glideraToken-' + network, cb);
+ };
+
+ root.removeGlideraToken = function(network, cb) {
+ storage.remove('glideraToken-' + network, cb);
+ };
+
return root;
});