commit
16c0c58d32
25 changed files with 511 additions and 129 deletions
|
|
@ -1,9 +1,13 @@
|
|||
'use strict';
|
||||
|
||||
angular.module('copayApp.services').factory('incomingData', function($log, $state, $window, $timeout, bitcore, lodash) {
|
||||
angular.module('copayApp.services').factory('incomingData', function($log, $state, $window, $timeout, bitcore, profileService, popupService, ongoingProcess, platformInfo, gettextCatalog, $rootScope) {
|
||||
|
||||
var root = {};
|
||||
|
||||
root.showMenu = function(data) {
|
||||
$rootScope.$broadcast('incomingDataMenu.showMenu', data);
|
||||
};
|
||||
|
||||
root.redir = function(data) {
|
||||
$log.debug('Processing incoming data: ' + data);
|
||||
|
||||
|
|
@ -21,7 +25,7 @@ angular.module('copayApp.services').factory('incomingData', function($log, $stat
|
|||
newUri.replace('://', ':');
|
||||
|
||||
return newUri;
|
||||
};
|
||||
}
|
||||
|
||||
function getParameterByName(name, url) {
|
||||
if (!url) return;
|
||||
|
|
@ -53,59 +57,59 @@ angular.module('copayApp.services').factory('incomingData', function($log, $stat
|
|||
|
||||
var amount = parsed.amount ? parsed.amount : '';
|
||||
|
||||
$state.go('tabs.send');
|
||||
// Timeout is required to enable the "Back" button
|
||||
$timeout(function() {
|
||||
if (parsed.r) {
|
||||
$state.transitionTo('tabs.send.confirm', {paypro: parsed.r});
|
||||
} else {
|
||||
if (parsed.r) {
|
||||
getPayProDetails(parsed.r, function(err, details) {
|
||||
handlePayPro(details);
|
||||
});
|
||||
} else {
|
||||
$state.go('tabs.send');
|
||||
// Timeout is required to enable the "Back" button
|
||||
$timeout(function() {
|
||||
if (amount) {
|
||||
$state.transitionTo('tabs.send.confirm', {toAmount: amount, toAddress: addr, description:message});
|
||||
} else {
|
||||
$state.transitionTo('tabs.send.amount', {toAddress: addr});
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
return true;
|
||||
|
||||
// Plain URL
|
||||
} else if (/^https?:\/\//.test(data)) {
|
||||
$state.go('tabs.send').then(function() {
|
||||
$state.transitionTo('tabs.send.confirm', {paypro: data});
|
||||
});
|
||||
return true;
|
||||
|
||||
// Plain Address
|
||||
} else if (bitcore.Address.isValid(data, 'livenet')) {
|
||||
$state.go('tabs.send').then(function() {
|
||||
$state.transitionTo('tabs.send.amount', {toAddress: data});
|
||||
getPayProDetails(data, function(err, details) {
|
||||
if(err) {
|
||||
root.showMenu({data: data, type: 'url'});
|
||||
return;
|
||||
}
|
||||
handlePayPro(details);
|
||||
return true;
|
||||
});
|
||||
return true;
|
||||
} else if (bitcore.Address.isValid(data, 'testnet')) {
|
||||
$state.go('tabs.send').then(function() {
|
||||
$state.transitionTo('tabs.send.amount', {toAddress: data});
|
||||
});
|
||||
return true;
|
||||
// Plain Address
|
||||
} else if (bitcore.Address.isValid(data, 'livenet') || bitcore.Address.isValid(data, 'testnet')) {
|
||||
if($state.includes('tabs.scan')) {
|
||||
root.showMenu({data: data, type: 'bitcoinAddress'});
|
||||
} else {
|
||||
goToAmountPage(data);
|
||||
}
|
||||
} else if (data && data.indexOf($window.appConfig.name + '://glidera') === 0) {
|
||||
return $state.go('uriglidera', {url: data});
|
||||
} else if (data && data.indexOf($window.appConfig.name + '://coinbase') === 0) {
|
||||
return $state.go('uricoinbase', {url: data});
|
||||
|
||||
// Protocol
|
||||
} else if (data && data.indexOf($window.appConfig.name + '://glidera')==0) {
|
||||
return $state.go('uriglidera', {url: data});
|
||||
} else if (data && data.indexOf($window.appConfig.name + '://coinbase')==0) {
|
||||
return $state.go('uricoinbase', {url: data});
|
||||
|
||||
// BitPayCard Authentication
|
||||
} else if (data && data.indexOf($window.appConfig.name + '://')==0) {
|
||||
var secret = getParameterByName('secret', data);
|
||||
var email = getParameterByName('email', data);
|
||||
var otp = getParameterByName('otp', data);
|
||||
$state.go('tabs.home').then(function() {
|
||||
$state.transitionTo('tabs.bitpayCardIntro', {
|
||||
secret: secret,
|
||||
email: email,
|
||||
otp: otp
|
||||
// BitPayCard Authentication
|
||||
} else if (data && data.indexOf($window.appConfig.name + '://') === 0) {
|
||||
var secret = getParameterByName('secret', data);
|
||||
var email = getParameterByName('email', data);
|
||||
var otp = getParameterByName('otp', data);
|
||||
$state.go('tabs.home').then(function() {
|
||||
$state.transitionTo('tabs.bitpayCardIntro', {
|
||||
secret: secret,
|
||||
email: email,
|
||||
otp: otp
|
||||
});
|
||||
});
|
||||
});
|
||||
return true;
|
||||
return true;
|
||||
|
||||
// Join
|
||||
} else if (data && data.match(/^copay:[0-9A-HJ-NP-Za-km-z]{70,80}$/)) {
|
||||
|
|
@ -120,11 +124,74 @@ angular.module('copayApp.services').factory('incomingData', function($log, $stat
|
|||
$state.transitionTo('tabs.add.join', {url: data});
|
||||
});
|
||||
return true;
|
||||
} else {
|
||||
|
||||
if($state.includes('tabs.scan')) {
|
||||
root.showMenu({data: data, type: 'text'});
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
};
|
||||
|
||||
function getPayProDetails(uri, cb) {
|
||||
if (!cb) cb = function() {};
|
||||
|
||||
var wallet = profileService.getWallets({
|
||||
onlyComplete: true
|
||||
})[0];
|
||||
|
||||
if (!wallet) return cb();
|
||||
|
||||
if (platformInfo.isChromeApp) {
|
||||
popupService.showAlert(gettextCatalog.getString('Payment Protocol not supported on Chrome App'));
|
||||
return cb(true);
|
||||
}
|
||||
|
||||
$log.debug('Fetch PayPro Request...', uri);
|
||||
|
||||
ongoingProcess.set('fetchingPayPro', true);
|
||||
|
||||
wallet.fetchPayPro({
|
||||
payProUrl: uri,
|
||||
}, function(err, paypro) {
|
||||
|
||||
ongoingProcess.set('fetchingPayPro', false);
|
||||
if (err) {
|
||||
return cb(true);
|
||||
}
|
||||
|
||||
if (!paypro.verified) {
|
||||
$log.warn('Failed to verify payment protocol signatures');
|
||||
popupService.showAlert(gettextCatalog.getString('Payment Protocol Invalid'));
|
||||
return cb(true);
|
||||
}
|
||||
cb(null, paypro);
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
function goToAmountPage(toAddress) {
|
||||
$state.go('tabs.send');
|
||||
$timeout(function() {
|
||||
$state.transitionTo('tabs.send.amount', {toAddress: toAddress});
|
||||
}, 100);
|
||||
}
|
||||
|
||||
function handlePayPro(payProDetails){
|
||||
var stateParams = {
|
||||
toAmount: payProDetails.amount,
|
||||
toAddress: payProDetails.toAddress,
|
||||
description: payProDetails.memo,
|
||||
paypro: payProDetails
|
||||
};
|
||||
$state.go('tabs.send').then(function() {
|
||||
$timeout(function() {
|
||||
$state.transitionTo('tabs.send.confirm', stateParams);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
return root;
|
||||
});
|
||||
|
|
|
|||
|
|
@ -1,9 +1,9 @@
|
|||
'use strict';
|
||||
|
||||
angular.module('copayApp.services').service('scannerService', function($log, $timeout, platformInfo, $rootScope) {
|
||||
angular.module('copayApp.services').service('scannerService', function($log, $timeout, platformInfo, $rootScope, $window) {
|
||||
|
||||
var isDesktop = !platformInfo.isCordova;
|
||||
var QRScanner = window.QRScanner;
|
||||
var QRScanner = $window.QRScanner;
|
||||
var lightEnabled = false;
|
||||
var backCamera = true; // the plugin defaults to the back camera
|
||||
|
||||
|
|
@ -55,8 +55,8 @@ angular.module('copayApp.services').service('scannerService', function($log, $ti
|
|||
canEnableLight: canEnableLight,
|
||||
canChangeCamera: canChangeCamera,
|
||||
canOpenSettings: canOpenSettings
|
||||
}
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
var initializeStarted = false;
|
||||
/**
|
||||
|
|
@ -123,10 +123,10 @@ angular.module('copayApp.services').service('scannerService', function($log, $ti
|
|||
}
|
||||
this.isInitialized = function(){
|
||||
return initializeCompleted;
|
||||
}
|
||||
};
|
||||
this.initializeStarted = function(){
|
||||
return initializeStarted;
|
||||
}
|
||||
};
|
||||
|
||||
var nextHide = null;
|
||||
var nextDestroy = null;
|
||||
|
|
@ -167,6 +167,14 @@ angular.module('copayApp.services').service('scannerService', function($log, $ti
|
|||
QRScanner.scan(callback);
|
||||
};
|
||||
|
||||
this.pausePreview = function() {
|
||||
QRScanner.pausePreview();
|
||||
};
|
||||
|
||||
this.resumePreview = function() {
|
||||
QRScanner.resumePreview();
|
||||
};
|
||||
|
||||
/**
|
||||
* Deactivate the QRScanner. To balance user-perceived performance and power
|
||||
* consumption, this kicks off a countdown which will "sleep" the scanner
|
||||
|
|
@ -177,7 +185,7 @@ angular.module('copayApp.services').service('scannerService', function($log, $ti
|
|||
*/
|
||||
this.deactivate = function(callback) {
|
||||
$log.debug('Deactivating scanner...');
|
||||
// QRScanner.cancelScan();
|
||||
QRScanner.cancelScan();
|
||||
nextHide = $timeout(_hide, hideAfterSeconds * 1000);
|
||||
nextDestroy = $timeout(_destroy, destroyAfterSeconds * 1000);
|
||||
};
|
||||
|
|
@ -200,7 +208,7 @@ angular.module('copayApp.services').service('scannerService', function($log, $ti
|
|||
initializeCompleted = false;
|
||||
QRScanner.destroy();
|
||||
initialize(callback);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Toggle the device light (if available).
|
||||
|
|
@ -236,7 +244,7 @@ angular.module('copayApp.services').service('scannerService', function($log, $ti
|
|||
var nextCamera = backCamera? 1 : 0;
|
||||
function cameraToString(index){
|
||||
return index === 1? 'front' : 'back'; // front = 1, back = 0
|
||||
};
|
||||
}
|
||||
$log.debug('Toggling to the ' + cameraToString(nextCamera) + ' camera...');
|
||||
QRScanner.useCamera(nextCamera, function(err, status){
|
||||
if(err){
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue