Ref and clean code

This commit is contained in:
Gustavo Maximiliano Cortez 2016-10-12 09:38:41 -03:00
commit 95c0371f9b
No known key found for this signature in database
GPG key ID: 15EDAD8D9F2EB1AF
4 changed files with 24 additions and 33 deletions

View file

@ -1,6 +1,6 @@
'use strict';
angular.module('copayApp.controllers').controller('bitpayCardController', function($scope, $timeout, $log, $state, lodash, bitpayCardService, configService, profileService, walletService, ongoingProcess, moment, popupService, gettextCatalog, bwcError, $ionicHistory) {
angular.module('copayApp.controllers').controller('bitpayCardController', function($scope, $timeout, $log, $state, lodash, bitpayCardService, moment, popupService, gettextCatalog, $ionicHistory) {
var self = this;
$scope.dateRange = 'last30Days';

View file

@ -1,5 +1,5 @@
'use strict';
angular.module('copayApp.controllers').controller('bitpayCardIntroController', function($scope, $log, $state, $timeout, $ionicHistory, storageService, externalLinkService, bitpayCardService, gettextCatalog, popupService) {
angular.module('copayApp.controllers').controller('bitpayCardIntroController', function($scope, $log, $state, $ionicHistory, storageService, externalLinkService, bitpayCardService, gettextCatalog, popupService) {
var checkOtp = function(obj, cb) {
if (obj.otp) {
@ -41,12 +41,11 @@ angular.module('copayApp.controllers').controller('bitpayCardIntroController', f
$ionicHistory.nextViewOptions({
disableAnimate: true
});
$state.go('tabs.home');
if (data.cards[0]) {
$timeout(function() {
$state.go('tabs.home').then(function() {
if (data.cards[0]) {
$state.transitionTo('tabs.bitpayCard', {id: data.cards[0].id});
}, 100);
}
}
});
});
}
});

View file

@ -1,6 +1,6 @@
'use strict';
angular.module('copayApp.services').factory('bitpayCardService', function($http, $log, $window, lodash, storageService, bitauthService, platformInfo) {
angular.module('copayApp.services').factory('bitpayCardService', function($http, $log, lodash, storageService, bitauthService, platformInfo) {
var root = {};
var BITPAY_CARD_NETWORK = 'livenet';
var BITPAY_CARD_API_URL = BITPAY_CARD_NETWORK == 'livenet' ? 'https://bitpay.com' : 'https://test.bitpay.com';

View file

@ -1,6 +1,6 @@
'use strict';
angular.module('copayApp.services').factory('incomingData', function($log, $ionicModal, $state, $window, $timeout, bitcore, lodash) {
angular.module('copayApp.services').factory('incomingData', function($log, $state, $window, bitcore, lodash) {
var root = {};
@ -45,10 +45,9 @@ angular.module('copayApp.services').factory('incomingData', function($log, $ioni
// data extensions for Payment Protocol with non-backwards-compatible request
if ((/^bitcoin:\?r=[\w+]/).exec(data)) {
data = decodeURIComponent(data.replace('bitcoin:?r=', ''));
$state.go('tabs.send');
$timeout(function() {
$state.go('tabs.send').then(function() {
$state.transitionTo('tabs.send.confirm', {paypro: data});
}, 100);
});
return true;
}
@ -63,8 +62,7 @@ angular.module('copayApp.services').factory('incomingData', function($log, $ioni
var amount = parsed.amount ? parsed.amount : '';
$state.go('tabs.send');
$timeout(function() {
$state.go('tabs.send').then(function() {
if (parsed.r) {
$state.transitionTo('tabs.send.confirm', {paypro: parsed.r});
} else {
@ -74,31 +72,28 @@ angular.module('copayApp.services').factory('incomingData', function($log, $ioni
$state.transitionTo('tabs.send.amount', {toAddress: addr});
}
}
}, 100);
});
return true;
// Plain URL
} else if (/^https?:\/\//.test(data)) {
var currentState = $state.current.name;
if (lodash.indexOf(ignoreState, currentState) != -1) return false;
$state.go('tabs.send');
$timeout(function() {
$state.go('tabs.send').then(function() {
$state.transitionTo('tabs.send.confirm', {paypro: data});
}, 100);
});
return true;
// Plain Address
} else if (bitcore.Address.isValid(data, 'livenet')) {
$state.go('tabs.send');
$timeout(function() {
$state.go('tabs.send').then(function() {
$state.transitionTo('tabs.send.amount', {toAddress: data});
}, 100);
});
return true;
} else if (bitcore.Address.isValid(data, 'testnet')) {
$state.go('tabs.send');
$timeout(function() {
$state.go('tabs.send').then(function() {
$state.transitionTo('tabs.send.amount', {toAddress: data});
}, 100);
});
return true;
// Protocol
@ -112,30 +107,27 @@ angular.module('copayApp.services').factory('incomingData', function($log, $ioni
var secret = getParameterByName('secret', data);
var email = getParameterByName('email', data);
var otp = getParameterByName('otp', data);
$state.go('tabs.home');
$timeout(function() {
$state.go('tabs.home').then(function() {
$state.transitionTo('tabs.bitpayCardIntro', {
secret: secret,
email: email,
otp: otp
});
}, 100);
});
return true;
// Join
} else if (data && data.match(/^copay:[0-9A-HJ-NP-Za-km-z]{70,80}$/)) {
$state.go('tabs.home');
$timeout(function() {
$state.go('tabs.home').then(function() {
$state.transitionTo('tabs.add.join', {url: data});
}, 100);
});
return true;
// Old join
} else if (data && data.match(/^[0-9A-HJ-NP-Za-km-z]{70,80}$/)) {
$state.go('tabs.home');
$timeout(function() {
$state.go('tabs.home').then(function() {
$state.transitionTo('tabs.add.join', {url: data});
}, 100);
});
return true;
}