This commit is contained in:
Jean-Baptiste Dominguez 2018-09-03 13:31:58 +09:00
commit 6f28f6ba2b
6 changed files with 84 additions and 111 deletions

View file

@ -111,28 +111,18 @@ angular.module('copayApp.controllers').controller('tabScanController', function(
// Sometimes (testing in Chrome, when reading QR Code) data is an object // Sometimes (testing in Chrome, when reading QR Code) data is an object
// that has a string data.result. // that has a string data.result.
contents = contents.result || contents; contents = contents.result || contents;
incomingData.redir(contents, function onError(err) {
if (err) {
var title = gettextCatalog.getString('Scan Failed');
popupService.showAlert(title, err.message, function onAlertShown() {
scannerService.resumePreview();
});
} else {
scannerService.resumePreview();
var parsed = bitcoinUriService.parse(contents);
var title = '';
var msg = '';
if (parsed.isValid) {
if (parsed.isTestnet) {
title = gettextCatalog.getString('Unsupported');
msg = gettextCatalog.getString('Testnet is not supported.');
popupService.showAlert(title, msg, function onAlertShown() {
scannerService.resumePreview();
});
} else {
incomingData.redir(contents);
} }
} else {
title = gettextCatalog.getString('Scan Failed');
msg = gettextCatalog.getString('Data not recognised.');
popupService.showAlert(title, msg, function onAlertShown() {
scannerService.resumePreview();
}); });
} }
}
$rootScope.$on('incomingDataMenu.menuHidden', function() { $rootScope.$on('incomingDataMenu.menuHidden', function() {
activate(); activate();

View file

@ -3,9 +3,11 @@
angular.module('copayApp.controllers').controller('tabsController', function($rootScope, $log, $scope, $state, $stateParams, $timeout, platformInfo, incomingData, lodash, popupService, gettextCatalog, scannerService, sendFlowService) { angular.module('copayApp.controllers').controller('tabsController', function($rootScope, $log, $scope, $state, $stateParams, $timeout, platformInfo, incomingData, lodash, popupService, gettextCatalog, scannerService, sendFlowService) {
$scope.onScan = function(data) { $scope.onScan = function(data) {
if (!incomingData.redir(data)) { incomingData.redir(data, function onError(err) {
popupService.showAlert(gettextCatalog.getString('Error'), gettextCatalog.getString('Invalid data')); if (err) {
popupService.showAlert(gettextCatalog.getString('Error'), err.message);
} }
});
}; };
$scope.setScanFn = function(scanFn) { $scope.setScanFn = function(scanFn) {
@ -36,10 +38,14 @@ angular.module('copayApp.controllers').controller('tabsController', function($ro
scannerService.useOldScanner(function(err, contents) { scannerService.useOldScanner(function(err, contents) {
if (err) { if (err) {
popupService.showAlert(gettextCatalog.getString('Error'), err); popupService.showAlert(gettextCatalog.getString('Error'), err.message);
return; } else {
incomingData.redir(contents, function onError(err) {
if (err) {
popupService.showAlert(gettextCatalog.getString('Error'), err.message);
}
});
} }
incomingData.redir(contents);
}); });
}; };

View file

@ -111,6 +111,7 @@ angular.module('copayApp.directives').directive('shapeshiftCoinTrader', function
orderId: $scope.depositInfo.orderId orderId: $scope.depositInfo.orderId
}; };
// How to handle this
if (incomingData.redir(sendAddress, 'shapeshift', shapeshiftData)) { if (incomingData.redir(sendAddress, 'shapeshift', shapeshiftData)) {
ongoingProcess.set('connectingShapeshift', false); ongoingProcess.set('connectingShapeshift', false);
return; return;

View file

@ -1,5 +1,9 @@
'use strict'; 'use strict';
/**
* incomingData is an intermediate to redirect either to the sendFlow
* or to import/join a wallet.
*/
angular.module('copayApp.services').factory('incomingData', function(externalLinkService, bitcoinUriService, $log, $state, $timeout, $ionicHistory, bitcore, bitcoreCash, $rootScope, payproService, scannerService, sendFlowService, appConfigService, popupService, gettextCatalog, bitcoinCashJsService) { angular.module('copayApp.services').factory('incomingData', function(externalLinkService, bitcoinUriService, $log, $state, $timeout, $ionicHistory, bitcore, bitcoreCash, $rootScope, payproService, scannerService, sendFlowService, appConfigService, popupService, gettextCatalog, bitcoinCashJsService) {
var root = {}; var root = {};
@ -8,22 +12,20 @@ angular.module('copayApp.services').factory('incomingData', function(externalLin
$rootScope.$broadcast('incomingDataMenu.showMenu', data); $rootScope.$broadcast('incomingDataMenu.showMenu', data);
}; };
root.redir = function(data) { root.redir = function(data, cbError) {
var parsed = bitcoinUriService.parse(data); var parsed = bitcoinUriService.parse(data);
if (parsed.isValid && parsed.isTestnet) { console.log(parsed);
popupService.showAlert( $log.debug(parsed);
gettextCatalog.getString('Unsupported'),
gettextCatalog.getString('Testnet is not supported.')
); if (parsed.isValid) {
return false; if (parsed.isTestnet) {
if (cbError) {
var errorMessage = gettextCatalog.getString('Testnet is not supported.');
cbError(new Error(errorMessage));
}
} else { } else {
/**
* Hardcore fix, but the legacy code in the bottom needs to be removed.
* BitcoinUriService is making the job of this.
* incomingData should be an intermediate to redirect either to the sendFlow
* or to import a wallet for example.
*/
scannerService.pausePreview(); scannerService.pausePreview();
/** /**
@ -35,6 +37,12 @@ angular.module('copayApp.services').factory('incomingData', function(externalLin
url: data url: data
}); });
}); });
} else if (parsed.import) {
$state.go('tabs.home').then(function() {
$state.transitionTo('tabs.add.import', {
code: data
});
});
} else if ( } else if (
!parsed.isValid !parsed.isValid
|| parsed.privateKey || parsed.privateKey
@ -59,45 +67,13 @@ angular.module('copayApp.services').factory('incomingData', function(externalLin
}); });
} }
} }
} else {
if (cbError) {
var errorMessage = gettextCatalog.getString('Data not recognised.');
cbError(new Error(errorMessage));
} }
}
/** };
* The legacy code in the bottom needs to be checked and removed if any case is forgotten.
* else if (data && data.match(/^copay:[0-9A-HJ-NP-Za-km-z]{70,80}$/)) {
$state.go('tabs.home', {}, {
'reload': true,
'notify': $state.current.name == 'tabs.home' ? false : true
}).then(function() {
$state.transitionTo('tabs.add.join', {
url: data
});
});
return true;
// Old join
} else if (data && data.match(/^[0-9A-HJ-NP-Za-km-z]{70,80}$/)) {
$state.go('tabs.home', {}, {
'reload': true,
'notify': $state.current.name == 'tabs.home' ? false : true
}).then(function() {
$state.transitionTo('tabs.add.join', {
url: data
});
});
return true;
} else if (data && (data.substring(0, 2) == '6P' || checkPrivateKey(data))) {
root.showMenu({
data: data,
type: 'privateKey'
});
} else if (data && ((data.substring(0, 2) == '1|') || (data.substring(0, 2) == '2|') || (data.substring(0, 2) == '3|'))) {
$state.go('tabs.home').then(function() {
$state.transitionTo('tabs.add.import', {
code: data
});
});
*
*/
return root; return root;
}); });

View file

@ -23,9 +23,12 @@ angular.module('copayApp.services').factory('openURLService', function($rootScop
document.addEventListener('handleopenurl', handleOpenURL, false); document.addEventListener('handleopenurl', handleOpenURL, false);
if (!incomingData.redir(url)) { incomingData.redir(url, function onError(err) {
if (err) {
$log.warn('Unknown URL! : ' + url); $log.warn('Unknown URL! : ' + url);
popupService.showAlert(gettextCatalog.getString('Error'), err.message);
} }
});
}; };
var handleResume = function() { var handleResume = function() {

View file

@ -100,11 +100,8 @@ angular
params.coin = res.coin; params.coin = res.coin;
} }
if (res.amount) { if (res.amountInSatoshis) {
if (res.currency) { params.amount = res.amountInSatoshis;
params.currency = res.currency;
}
params.amount = res.amount;
} }
if (res.publicAddress) { if (res.publicAddress) {