Glidera Integration

This commit is contained in:
Gustavo Maximiliano Cortez 2015-08-28 18:23:24 -03:00
commit 4ed39a22d4
8 changed files with 314 additions and 0 deletions

View file

@ -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();

View file

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

View file

@ -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,

View file

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

View file

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