Fix Glidera URI. Uses showAlert service

This commit is contained in:
Gustavo Maximiliano Cortez 2016-08-31 16:43:52 -03:00
commit 092e8308b0
No known key found for this signature in database
GPG key ID: 15EDAD8D9F2EB1AF
16 changed files with 216 additions and 340 deletions

View file

@ -1,19 +1,26 @@
'use strict';
angular.module('copayApp.controllers').controller('buyGlideraController',
function($scope, $timeout, $log, $ionicModal, profileService, walletService, glideraService, bwcError, lodash, ongoingProcess) {
function($scope, $timeout, $log, profileService, walletService, glideraService, bwcError, lodash, ongoingProcess, popupService, gettextCatalog) {
var wallet;
var self = this;
this.show2faCodeInput = null;
this.error = null;
this.success = null;
$scope.$on('Wallet/Changed', function(event, w) {
if (lodash.isEmpty(w)) {
$log.debug('No wallet provided');
return;
}
wallet = w;
$log.debug('Wallet changed: ' + w.name);
});
$scope.init = function(accessToken) {
$scope.network = glideraService.getEnvironment();
$scope.token = accessToken;
$scope.error = null;
$scope.permissions = null;
$scope.email = null;
$scope.personalInfo = null;
@ -25,7 +32,7 @@ angular.module('copayApp.controllers').controller('buyGlideraController',
glideraService.init($scope.token, function(err, glidera) {
ongoingProcess.set('connectingGlidera');
if (err || !glidera) {
$scope.error = err;
if (err) popupService.showAlert(gettextCatalog.getString('Error'), err);
return;
}
$scope.token = glidera.token;
@ -33,21 +40,11 @@ angular.module('copayApp.controllers').controller('buyGlideraController',
$scope.update({fullUpdate: true});
});
self.allWallets = profileService.getWallets({
$scope.wallets = profileService.getWallets({
network: $scope.network,
n: 1,
onlyComplete: true
});
if (lodash.isEmpty(self.allWallets)) return;
wallet = self.allWallets[0];
if (wallet) {
$timeout(function() {
self.selectedWalletId = wallet.credentials.walletId;
self.selectedWalletName = wallet.credentials.walletName;
$scope.$apply();
}, 100);
}
};
$scope.update = function(opts) {
@ -84,33 +81,6 @@ angular.module('copayApp.controllers').controller('buyGlideraController',
}
};
$scope.openWalletsModal = function(wallets) {
self.error = null;
$scope.type = 'BUY';
$scope.wallets = wallets;
$scope.noColor = true;
$scope.self = self;
$ionicModal.fromTemplateUrl('views/modals/wallets.html', {
scope: $scope,
animation: 'slide-in-up'
}).then(function(modal) {
$scope.walletsModal = modal;
$scope.walletsModal.show();
});
$scope.$on('walletSelected', function(ev, walletId) {
$timeout(function() {
wallet = profileService.getClient(walletId);
self.selectedWalletId = walletId;
self.selectedWalletName = wallet.credentials.walletName;
$scope.$apply();
}, 100);
$scope.walletsModal.hide();
});
};
this.getBuyPrice = function(token, price) {
var self = this;
this.error = null;
@ -122,7 +92,7 @@ angular.module('copayApp.controllers').controller('buyGlideraController',
glideraService.buyPrice(token, price, function(err, buyPrice) {
self.gettingBuyPrice = false;
if (err) {
self.error = 'Could not get exchange information. Please, try again.';
popupService.showAlert(gettextCatalog.getString('Error'), gettextCatalog.getString('Could not get exchange information. Please, try again'));
return;
}
self.buyPrice = buyPrice;
@ -131,13 +101,12 @@ angular.module('copayApp.controllers').controller('buyGlideraController',
this.get2faCode = function(token) {
var self = this;
self.error = null;
ongoingProcess.set('Sending 2FA code...', true);
$timeout(function() {
glideraService.get2faCode(token, function(err, sent) {
ongoingProcess.set('Sending 2FA code...', false);
if (err) {
self.error = 'Could not send confirmation code to your phone';
popupService.showAlert(gettextCatalog.getString('Error'), gettextCatalog.getString('Could not send confirmation code to your phone'));
return;
}
self.show2faCodeInput = sent;
@ -147,13 +116,12 @@ angular.module('copayApp.controllers').controller('buyGlideraController',
this.sendRequest = function(token, permissions, twoFaCode) {
var self = this;
self.error = null;
ongoingProcess.set('Buying Bitcoin...', true);
$timeout(function() {
walletService.getAddress(wallet, false, function(err, walletAddr) {
if (err) {
ongoingProcess.set('Buying Bitcoin...', false);
self.error = bwcError.cb(err, 'Could not create address');
popupService.showAlert(gettextCatalog.getString('Error'), bwcError.cb(err, 'Could not create address'));
return;
}
var data = {
@ -166,11 +134,13 @@ angular.module('copayApp.controllers').controller('buyGlideraController',
glideraService.buy(token, twoFaCode, data, function(err, data) {
ongoingProcess.set('Buying Bitcoin...', false);
if (err) {
self.error = err;
popupService.showAlert(gettextCatalog.getString('Error'), err);
return;
}
self.success = data;
$scope.$emit('Local/GlideraTx');
$timeout(function() {
$scope.$digest();
});
});
});
}, 100);