Clean code. Fix coinbase tx modal

This commit is contained in:
Gustavo Maximiliano Cortez 2017-01-13 01:05:52 -03:00
commit 9ac1e565ac
No known key found for this signature in database
GPG key ID: 15EDAD8D9F2EB1AF
5 changed files with 77 additions and 62 deletions

View file

@ -8,31 +8,34 @@ angular.module('copayApp.controllers').controller('coinbaseController', function
var init = function() {
var config = configService.getSync().wallet.settings;
$scope.currency = getCurrency(config.alternativeIsoCode);
ongoingProcess.set('connectingCoinbase', true);
coinbaseService.init(function(err, data) {
ongoingProcess.set('connectingCoinbase', false);
if (err || lodash.isEmpty(data)) {
if (err) {
popupService.showAlert(gettextCatalog.getString('Error'), err);
coinbaseService.getStoredToken(function(at) {
$scope.accessToken = at;
// Update Access Token if necessary
coinbaseService.init(function(err, data) {
if (err || lodash.isEmpty(data)) {
if (err) {
popupService.showAlert(gettextCatalog.getString('Error'), err);
}
return;
}
return;
}
// Show rates
coinbaseService.buyPrice(data.accessToken, $scope.currency, function(err, b) {
$scope.buyPrice = b.data || null;
});
coinbaseService.sellPrice(data.accessToken, $scope.currency, function(err, s) {
$scope.sellPrice = s.data || null;
});
// Show rates
coinbaseService.buyPrice(data.accessToken, $scope.currency, function(err, b) {
$scope.buyPrice = b.data || null;
});
coinbaseService.sellPrice(data.accessToken, $scope.currency, function(err, s) {
$scope.sellPrice = s.data || null;
});
// Updating accessToken and accountId
$timeout(function() {
$scope.accessToken = data.accessToken;
$scope.accountId = data.accountId;
$scope.updateTransactions();
$scope.$apply();
}, 100);
// Updating accessToken and accountId
$timeout(function() {
$scope.accessToken = data.accessToken;
$scope.accountId = data.accountId;
$scope.updateTransactions();
$scope.$apply();
}, 100);
});
});
};
@ -104,8 +107,8 @@ angular.module('copayApp.controllers').controller('coinbaseController', function
scope: $scope,
animation: 'slide-in-up'
}).then(function(modal) {
$scope.coinbaseTxDetailsModal = modal;
$scope.coinbaseTxDetailsModal.show();
$scope.modal = modal;
$scope.modal.show();
});
};

View file

@ -1,18 +1,28 @@
'use strict';
angular.module('copayApp.controllers').controller('coinbaseTxDetailsController', function($scope, $rootScope, coinbaseService) {
angular.module('copayApp.controllers').controller('coinbaseTxDetailsController', function($scope, coinbaseService, popupService) {
$scope.remove = function() {
coinbaseService.savePendingTransaction($scope.tx, {
remove: true
}, function(err) {
$rootScope.$emit('Local/CoinbaseTx');
$scope.close();
coinbaseService.setCredentials();
$scope.updateRequired = false;
var message = 'Are you sure you want to remove this transaction?';
popupService.showConfirm(null, message, null, null, function(ok) {
if (!ok) {
return;
}
coinbaseService.savePendingTransaction($scope.tx, {
remove: true
}, function(err) {
$scope.updateRequired = true;
$scope.close();
});
});
};
$scope.close = function() {
$scope.coinbaseTxDetailsModal.hide();
$scope.modal.hide().then(function() {
if ($scope.updateRequired) $scope.updateTransactions();
});
};
});