Glidera Integration

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

View File

@ -50,6 +50,10 @@
<i class="icon-arrow-right3 size-24 right text-gray"></i>
<span translate>Advanced</span>
</li>
<li class="line-b p20" ng-click="$root.go('preferencesGlidera')">
<i class="icon-arrow-right3 size-24 right text-gray"></i>
<span translate>Glidera</span>
</li>
</ul>
<ul class="no-bullet m0 size-14">

View File

@ -0,0 +1,94 @@
<div
class="topbar-container"
ng-include="'views/includes/topbar.html'"
ng-init="titleSection='Glidera'; goBackToState = 'preferences'">
</div>
<div class="content preferences p20v" ng-controller="preferencesGlideraController as glidera">
<div class="row" ng-init="glidera.init(index.glideraToken)">
<div class="large-12 columns">
<a
class="button outline dark-gray"
ng-click="$root.openExternalLink(glidera.authenticateUrl)">
Get OAuth Code
</a>
<form name="form" ng-submit="glidera.submit(code)" novalidate>
<label>OAuth Code
<input type="text" ng-model="code">
</label>
<input type="submit" value="Get Access Token">
</form>
<div ng-show="index.glideraToken">
<a
class="button warning"
ng-click="glidera.revokeToken()">
Revoke Token
</a>
<h2>Permissions</h2>
<ul>
<li>personal_info: {{glidera.permission.personal_info}}
<li>transact: {{glidera.permission.transact}}
<li>transaction_history: {{glidera.permission.transaction_history}}
<li>view_email_address: {{glidera.permission.view_email_address}}
</ul>
<h2>Email</h2>
<ul>
<li>Email: {{glidera.email.email}}
<li>userEmailIsSetup: {{glidera.email.userEmailIsSetup}}
</ul>
<h2>Personal Info</h2>
<ul>
<li>first name: {{glidera.personalInfo.firstName}}
<li>middleName: {{glidera.personalInfo.middleName}}
<li>last name: {{glidera.personalInfo.lastName}}
<li>birthDate: {{glidera.personalInfo.birthDate}}
<li>address1: {{glidera.personalInfo.address1}}
<li>address2: {{glidera.personalInfo.address2}}
<li>city: {{glidera.personalInfo.city}}
<li>state: {{glidera.personalInfo.state}}
<li>zipCode: {{glidera.personalInfo.zipCode}}
<li>countryCode: {{glidera.personalInfo.countryCode}}
<li>occupation: {{glidera.personalInfo.occupation}}
<li>basicInfoState: {{glidera.personalInfo.basicInfoState}}
</ul>
<h2>Status</h2>
<ul>
<li>userCanTransact: {{glidera.status.userCanTransact}}
<li>userCanBuy: {{glidera.status.userCanBuy}}
<li>userCanSell: {{glidera.status.userCanSell}}
<li>userEmailIsSetup: {{glidera.status.userEmailIsSetup}}
<li>userPhoneIsSetup: {{glidera.status.userPhoneIsSetup}}
<li>userBankAccountIsSetup: {{glidera.status.userBankAccountIsSetup}}
<li>personalInfoState: {{glidera.status.personalInfoState}}
<li>bankAccountState: {{glidera.status.bankAccountState}}
<li>country: {{glidera.status.country}}
</ul>
<h2>Limits</h2>
<ul>
<li>dailyBuy: {{glidera.limits.dailyBuy}}
<li>dailySell: {{glidera.limits.dailySell}}
<li>monthlyBuy: {{glidera.limits.monthlyBuy}}
<li>monthlySell: {{glidera.limits.monthlySell}}
<li>dailyBuyRemaining: {{glidera.limits.dailyBuyRemaining}}
<li>dailySellRemaining: {{glidera.limits.dailySellRemaining}}
<li>monthlyBuyRemaining: {{glidera.limits.monthlyBuyRemaining}}
<li>monthlySellRemaining: {{glidera.limits.monthlySellRemaining}}
<li>currency: {{glidera.limits.currency}}
<li>transactDisabledPendingFirstTransaction: {{glidera.limits.transactDisabledPendingFirstTransaction}}
</ul>
</div>
</div>
</div>
</div>
<div class="extra-margin-bottom"></div>

View File

@ -112,6 +112,13 @@
ng-style="{'background-color':index.backgroundColor}">{{ (index.alias || index.walletName) | limitTo: 1}}
</div>
<div class="right">
<a ng-if="index.glideraToken"
class="button outline round light-gray tiny preferences-icon m0"
ng-click="$root.go('preferencesGlidera')">
Glidera
</a>
<a ng-click="$root.go('preferences')" class="button outline round light-gray tiny preferences-icon m0">
<i class="fi-widget size-18 vm"></i>
<span class="show-for-medium-up" translate>Preferences</span>

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