remote ignoreMobilePause, refactor openURL

This commit is contained in:
Matias Alejo Garcia 2016-06-11 13:52:44 -03:00
commit 2a97446ef9
No known key found for this signature in database
GPG key ID: 02470DB551277AB3
23 changed files with 356 additions and 337 deletions

View file

@ -5,7 +5,7 @@
</div>
<div class="content p20v row payment-uri" ng-controller="paymentUriController as payment">
<div class="large-12 columns" ng-init="payment.checkBitcoinUri()">
<div class="large-12 columns" ng-init="payment.init()">
<div class="panel text-center" ng-if="!payment.uri">
<h1 translate>Bitcoin URI is NOT valid!</h1>
</div>

View file

@ -2,8 +2,6 @@
angular.module('copayApp.controllers').controller('buyCoinbaseController',
function($scope, $modal, $log, $ionicModal, $timeout, lodash, profileService, coinbaseService, bwsError, addressService) {
window.ignoreMobilePause = true;
var self = this;
var fc;

View file

@ -8,9 +8,6 @@ angular.module('copayApp.controllers').controller('buyGlideraController',
this.error = null;
this.success = null;
this.loading = null;
window.ignoreMobilePause = true;
var otherWallets = function(testnet) {
var network = testnet ? 'testnet' : 'livenet';
return lodash.filter(profileService.getWallets(network), function(w) {

View file

@ -4,7 +4,6 @@ angular.module('copayApp.controllers').controller('coinbaseController',
function($rootScope, $scope, $timeout, $modal, $ionicModal, profileService, configService, storageService, coinbaseService, lodash, platformInfo) {
var isNW = platformInfo.isNW;
window.ignoreMobilePause = true;
this.openAuthenticateWindow = function() {
var oauthUrl = this.getAuthenticateUrl();

View file

@ -92,9 +92,6 @@ angular.module('copayApp.controllers').controller('copayersController',
self.shareSecret = function(secret) {
if (isCordova) {
if (isAndroid || isWP) {
window.ignoreMobilePause = true;
}
var message = gettextCatalog.getString('Join my Copay wallet. Here is the invitation code: {{secret}} You can download Copay for your phone or desktop at https://copay.io', {
secret: secret
});

View file

@ -126,9 +126,6 @@ angular.module('copayApp.controllers').controller('exportController',
self.sendWalletBackup = function() {
var fc = profileService.focusedClient;
if (isAndroid || isWP) {
window.ignoreMobilePause = true;
}
window.plugins.toast.showShortCenter(gettextCatalog.getString('Preparing backup...'));
var name = (fc.credentials.walletName || fc.credentials.walletId);
if (fc.alias) {

View file

@ -3,6 +3,7 @@ angular.module('copayApp.controllers').controller('glideraUriController',
function($scope, $stateParams, $timeout, profileService, configService, glideraService, storageService, go) {
this.submitOauthCode = function(code) {
console.log('[glideraUri.js.5:code:]'+code); //TODO
var self = this;
var glideraTestnet = configService.getSync().glidera.testnet;
var network = glideraTestnet ? 'testnet' : 'livenet';
@ -31,6 +32,7 @@ angular.module('copayApp.controllers').controller('glideraUriController',
};
this.checkCode = function() {
console.log('[glideraUri.js.35:$stateParams:]' + JSON.stringify($stateParams)); //TODO
this.code = $stateParams.code;
this.submitOauthCode(this.code);
};

View file

@ -15,14 +15,6 @@ angular.module('copayApp.controllers').controller('importController',
$scope.account = 1;
self.importErr = false;
window.ignoreMobilePause = true;
$scope.$on('$destroy', function() {
$timeout(function() {
window.ignoreMobilePause = false;
}, 100);
});
var updateSeedSourceSelect = function() {
self.seedOptions = [];

View file

@ -1,6 +1,6 @@
'use strict';
angular.module('copayApp.controllers').controller('indexController', function($rootScope, $scope, $log, $filter, $timeout, $ionicScrollDelegate, $ionicPopup, latestReleaseService, feeService, bwcService, pushNotificationsService, lodash, go, profileService, configService, rateService, storageService, addressService, gettext, gettextCatalog, amMoment, addonManager, bwsError, txFormatService, uxLanguage, glideraService, coinbaseService, platformInfo, addressbookService) {
angular.module('copayApp.controllers').controller('indexController', function($rootScope, $scope, $log, $filter, $timeout, $ionicScrollDelegate, $ionicPopup, latestReleaseService, feeService, bwcService, pushNotificationsService, lodash, go, profileService, configService, rateService, storageService, addressService, gettext, gettextCatalog, amMoment, addonManager, bwsError, txFormatService, uxLanguage, glideraService, coinbaseService, platformInfo, addressbookService, openURLService) {
var self = this;
var SOFT_CONFIRMATION_LIMIT = 12;
var errors = bwcService.getErrors();
@ -289,6 +289,7 @@ angular.module('copayApp.controllers').controller('indexController', function($r
initStatusHash = _walletStatusHash();
$log.debug('Updating status until it changes. initStatusHash:' + initStatusHash)
}
var get = function(cb) {
if (opts.walletStatus)
return cb(null, opts.walletStatus);
@ -351,6 +352,7 @@ angular.module('copayApp.controllers').controller('indexController', function($r
self.setPendingTxps(walletStatus.pendingTxps);
// Status Shortcuts
self.lastUpdate = Date.now();
self.walletName = walletStatus.wallet.name;
self.walletSecret = walletStatus.wallet.secret;
self.walletStatus = walletStatus.wallet.status;
@ -1492,14 +1494,16 @@ angular.module('copayApp.controllers').controller('indexController', function($r
}
});
self.debouncedUpdate = lodash.throttle(function() {
self.debouncedUpdate = function() {
var now = Date.now();
var oneHr = 1000 * 60 * 60;
if (!self.lastUpdate || (now - self.lastUpdate) > oneHr) {
self.updateAll({
quiet: true
triggerTxUpdate: true,
});
self.debounceUpdateHistory();
}, 2000, {
leading: false,
trailing: true
}
});
$rootScope.$on('Local/Resume', function(event) {
@ -1791,5 +1795,5 @@ angular.module('copayApp.controllers').controller('indexController', function($r
/* Start setup */
lodash.assign(self, vanillaScope);
lodash.assign(self, vanillaScope); openURLService.init();
});

View file

@ -69,9 +69,6 @@ angular.module('copayApp.controllers').controller('customAmountController', func
$scope.shareAddress = function(uri) {
if (platformInfo.isCordova) {
if (platformInfo.isAndroid || platformInfo.isWP) {
window.ignoreMobilePause = true;
}
window.plugins.socialsharing.share(uri, null, null, null);
}
};

View file

@ -1,20 +1,14 @@
'use strict';
angular.module('copayApp.controllers').controller('paymentUriController',
function($rootScope, $stateParams, $location, $timeout, profileService, configService, lodash, bitcore, go) {
window.ignoreMobilePause = true;
function strip(number) {
return (parseFloat(number.toPrecision(12)));
};
// Build bitcoinURI with querystring
this.checkBitcoinUri = function() {
this.init = function() {
var query = [];
angular.forEach($location.search(), function(value, key) {
query.push(key + "=" + value);
});
var queryString = query ? query.join("&") : null;
this.bitcoinURI = $stateParams.data + (queryString ? '?' + queryString : '');
this.bitcoinURI = $stateParams.url;
var URI = bitcore.URI;
var isUriValid = URI.isValid(this.bitcoinURI);

View file

@ -46,10 +46,6 @@ angular.module('copayApp.controllers').controller('preferencesInformation',
this.sendAddrs = function() {
var self = this;
if (platformInfo.isAndroid || platformInfo.isWP) {
window.ignoreMobilePause = true;
}
self.loading = true;
function formatDate(ts) {

View file

@ -3,7 +3,6 @@
angular.module('copayApp.controllers').controller('sellCoinbaseController',
function($rootScope, $scope, $modal, $log, $timeout, $ionicModal, lodash, profileService, coinbaseService, bwsError, configService, walletService, fingerprintService) {
window.ignoreMobilePause = true;
var self = this;
var fc;

View file

@ -12,8 +12,6 @@ angular.module('copayApp.controllers').controller('sellGlideraController',
this.loading = null;
var fc;
window.ignoreMobilePause = true;
var otherWallets = function(testnet) {
var network = testnet ? 'testnet' : 'livenet';
return lodash.filter(profileService.getWallets(network), function(w) {

View file

@ -8,7 +8,6 @@ angular.module('copayApp.controllers').controller('walletHomeController', functi
var isChromeApp = platformInfo.isChromeApp;
var self = this;
window.ignoreMobilePause = false;
$rootScope.shouldHideMenuBar = false;
$rootScope.wpInputFocused = false;
var config = configService.getSync();
@ -217,9 +216,6 @@ angular.module('copayApp.controllers').controller('walletHomeController', functi
this.shareAddress = function(addr) {
if (isCordova) {
if (isAndroid || isWP) {
window.ignoreMobilePause = true;
}
window.plugins.socialsharing.share('bitcoin:' + addr, null, null, null);
}
};

View file

@ -12,7 +12,6 @@ angular.module('copayApp.directives')
var onSuccess = function(result) {
$timeout(function() {
window.plugins.spinnerDialog.hide();
window.ignoreMobilePause = false;
}, 100);
if (isWP && result.cancelled) return;
@ -26,13 +25,11 @@ angular.module('copayApp.directives')
var onError = function(error) {
$timeout(function() {
window.ignoreMobilePause = false;
window.plugins.spinnerDialog.hide();
}, 100);
};
$scope.cordovaOpenScanner = function() {
window.ignoreMobilePause = true;
window.plugins.spinnerDialog.show(null, gettextCatalog.getString('Preparing camera...'), true);
$timeout(function() {
if (isIOS) {

View file

@ -7,42 +7,32 @@ angular.element(document).ready(function() {
angular.bootstrap(document, ['copayApp']);
};
var handleBitcoinURI = function(url) {
if (!url) return;
console.log('Custom URL:' + url); //TODO
var glidera = 'copay://glidera';
var coinbase = 'copay://coinbase';
if (url.indexOf('bitcoin:') == 0) {
url = '#/uri-payment/' + url;
} else if (url.indexOf(glidera) != -1) {
url = '#/uri-glidera' + url.replace(glidera, '');
} else if (url.indexOf(coinbase) != -1) {
url = '#/uri-coinbase' + url.replace(coinbase, '');
function handleOpenURL(url) {
if ('cordova' in window) {
console.log('DEEP LINK:' + url);
cordova.fireDocumentEvent('handleopenurl', {
url: url
});
} else {
console.log('Unknown URL!')
console.log("ERROR: Cannont handle open URL in non-cordova apps")
}
};
setTimeout(function() {
window.location = url;
}, 1000);
};
/* Cordova specific Init */
if (window.cordova !== undefined) {
if ('cordova' in window) {
window.handleOpenURL = handleOpenURL;
document.addEventListener('deviceready', function() {
window.handleOpenURL = handleBitcoinURI;
// Create a sticky event for handling the app being opened via a custom URL
cordova.addStickyDocumentEventHandler('handleopenurl');
startAngular();
}, false);
} else {
try {
window.handleOpenURL = handleBitcoinURI;
} catch (e) {}
startAngular();
}

View file

@ -112,8 +112,8 @@ angular.module('copayApp').config(function(historicLogProvider, $provide, $logPr
}
}
})
.state('payment', {
url: '/uri-payment/:data',
.state('uripayment', {
url: '/uri-payment/:url',
templateUrl: 'views/paymentUri.html',
views: {
'main': {
@ -215,7 +215,7 @@ angular.module('copayApp').config(function(historicLogProvider, $provide, $logPr
}
})
.state('uriglidera', {
url: '/uri-glidera?code',
url: '/uri-glidera/:code',
needProfile: true,
views: {
'main': {
@ -284,7 +284,7 @@ angular.module('copayApp').config(function(historicLogProvider, $provide, $logPr
}
})
.state('uricoinbase', {
url: '/uri-coinbase?code',
url: '/uri-coinbase/:code',
needProfile: true,
views: {
'main': {
@ -520,7 +520,7 @@ angular.module('copayApp').config(function(historicLogProvider, $provide, $logPr
}
});
})
.run(function($rootScope, $state, $log, $timeout, $ionicPlatform, uriHandler, platformInfo, profileService, uxLanguage, animationService, go, gettextCatalog) {
.run(function($rootScope, $state, $location, $log, $timeout, $ionicPlatform, uriHandler, platformInfo, profileService, uxLanguage, animationService, go, gettextCatalog) {
$ionicPlatform.ready(function() {
if (platformInfo.isCordova) {
@ -539,14 +539,8 @@ angular.module('copayApp').config(function(historicLogProvider, $provide, $logPr
});
$ionicPlatform.on('resume', function() {
if (!window.ignoreMobilePause) {
// Nothing to do
$rootScope.$emit('Local/Resume');
}
setTimeout(function() {
var loc = window.location;
var ignoreMobilePause = loc.toString().match(/(buy|sell|buycoinbase|sellcoinbase)/) ? true : false;
window.ignoreMobilePause = ignoreMobilePause;
}, 100);
});
$ionicPlatform.on('backbutton', function(event) {
@ -575,10 +569,6 @@ angular.module('copayApp').config(function(historicLogProvider, $provide, $logPr
}, 100);
go.walletHome();
setTimeout(function() {
window.ignoreMobilePause = false;
}, 100);
});
$ionicPlatform.on('menubutton', function() {
@ -614,6 +604,8 @@ angular.module('copayApp').config(function(historicLogProvider, $provide, $logPr
$rootScope.$on('$stateChangeStart', function(event, toState, toParams, fromState, fromParams) {
$log.debug('Route change from:', fromState.name || '-', ' to:', toState.name);
$log.debug(' toParams:' + JSON.stringify(toParams || {}));
$log.debug(' fromParams:' + JSON.stringify(fromParams || {}));
if (!profileService.profile && toState.needProfile) {
@ -640,17 +632,22 @@ angular.module('copayApp').config(function(historicLogProvider, $provide, $logPr
} else {
if (profileService.focusedClient && !profileService.focusedClient.isComplete() && toState.walletShouldBeComplete) {
event.preventDefault();
$state.transitionTo('copayers');
event.preventDefault();
}
}
if (!animationService.transitionAnimated(fromState, toState)) {
event.preventDefault();
// Time for the backpane to render
setTimeout(function() {
$state.transitionTo(toState);
}, 50);
}
// event.preventDefault();
// $state.transitionTo(toState);
// if (!animationService.transitionAnimated(fromState, toState)) {
//
// console.log('[routes.js.649] ANIMATION!'); //TODO
// event.preventDefault();
// // Time for the backpane to render
// return setTimeout(function() {
//
// console.log('[routes.js.654] TRANSITION'); //TODO
// $state.transitionTo(toState);
// }, 50);
// }
});
});

View file

@ -60,6 +60,7 @@ angular.module('copayApp.services').factory('animationService', function(platfor
};
function cleanUpLater(e, e2) {
console.log('[animationService.js.62:cleanUpLater:]'); //TODO
var cleanedUp = false,
timeoutID;
var cleanUp = function() {

View file

@ -111,11 +111,11 @@ angular.module('copayApp.services').factory('configService', function(storageSer
// Glidera
// Disabled for testnet
configCache.glidera.testnet = false;
configCache.glidera.testnet = true;
// Coinbase
// Disabled for testnet
configCache.coinbase.testnet = false;
configCache.coinbase.testnet = true;
$log.debug('Preferences read:', configCache)
return cb(err, configCache);

View file

@ -48,15 +48,15 @@ angular.module('copayApp.services').factory('go', function($window, $ionicSideMe
};
root.addWallet = function() {
$state.go('add');
$state.transitionTo('add');
};
root.preferences = function() {
$state.go('preferences');
$state.transitionTo('preferences');
};
root.preferencesGlobal = function() {
$state.go('preferencesGlobal');
$state.transitionTo('preferencesGlobal');
};
root.reload = function() {

View file

@ -0,0 +1,69 @@
'use strict';
angular.module('copayApp.services').factory('openURLService', function($ionicHistory, $document, $log, $state, go) {
var root = {};
root.registeredUriHandlers = [{
name: 'Bitcoin BIP21 URL',
startsWith: 'bitcoin:',
transitionTo: 'uripayment',
}, {
name: 'Glidera Authentication Callback',
startsWith: 'copay://glidera',
transitionTo: 'uriglidera',
}, {
name: 'Coinbase Authentication Callback',
startsWith: 'copay://coinbase',
transitionTo: 'uricoinbase',
}];
var handleOpenURL = function(args) {
$log.info('Handling Open URL: ' + JSON.stringify(args));
// Stop it from caching the first view as one to return when the app opens
$ionicHistory.nextViewOptions({
historyRoot: true,
disableBack: true,
disableAnimation: true
});
if (url) {
window.cordova.removeDocumentEventHandler('handleopenurl');
window.cordova.addStickyDocumentEventHandler('handleopenurl');
document.removeEventListener('handleopenurl', root.handleOpenUrl);
}
var url = args.url;
lodash.each(root.registeredUriHandlers, function(x) {
if (url.indexOf(x.startWith) == 0) {
$log.debug('openURL GOT ' + x.name + ' URL');
return $state.transitionTo(x.transitionTo, {
url: url
});
}
});
$log.warn('Unknown URL! : ' + url);
};
var handleResume = function() {
$log.debug('Handle Resume @ openURL...');
document.addEventListener('handleopenurl', handleOpenUrl, false);
};
root.init = function() {
console.log('[openURL.js.29]'); //TODO
document.addEventListener('handleopenurl', handleOpenURL, false);
document.addEventListener('resume', handleResume, false);
};
root.registerHandler = function(x) {
$log.debug('Registering URL Handler: ' + x.name);
root.registeredUriHandlers.push(x);
};
return root;
});

View file

@ -182,7 +182,6 @@ angular.module('copayApp.services')
push.on('notification', function(data) {
if (!data.additionalData.foreground) {
window.ignoreMobilePause = true;
$log.debug('Push notification event: ', data.message);
$timeout(function() {