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,27 +111,17 @@ 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) {
var parsed = bitcoinUriService.parse(contents); if (err) {
var title = ''; var title = gettextCatalog.getString('Scan Failed');
var msg = ''; popupService.showAlert(title, err.message, function onAlertShown() {
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(); scannerService.resumePreview();
}); });
} else { } else {
incomingData.redir(contents);
}
} else {
title = gettextCatalog.getString('Scan Failed');
msg = gettextCatalog.getString('Data not recognised.');
popupService.showAlert(title, msg, function onAlertShown() {
scannerService.resumePreview(); scannerService.resumePreview();
});
} }
});
} }
$rootScope.$on('incomingDataMenu.menuHidden', function() { $rootScope.$on('incomingDataMenu.menuHidden', function() {

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,96 +12,68 @@ 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.')
);
return false;
} 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();
/**
* Strategy for the action if (parsed.isValid) {
*/ if (parsed.isTestnet) {
if (parsed.copayInvitation) { if (cbError) {
$state.go('tabs.home').then(function() { var errorMessage = gettextCatalog.getString('Testnet is not supported.');
$state.transitionTo('tabs.add.join', { cbError(new Error(errorMessage));
url: data }
});
});
} else if (
!parsed.isValid
|| parsed.privateKey
|| (sendFlowService.state.isEmpty() && !parsed.url && !parsed.amount)
) {
root.showMenu({
original: data,
parsed: parsed
});
} else { } else {
var state = sendFlowService.state.getClone(); scannerService.pausePreview();
state.data = data;
sendFlowService.start(state, function onError(err) { /**
/** * Strategy for the action
* OnError, open the menu (link not validated) */
*/ if (parsed.copayInvitation) {
$state.go('tabs.home').then(function() {
$state.transitionTo('tabs.add.join', {
url: data
});
});
} else if (parsed.import) {
$state.go('tabs.home').then(function() {
$state.transitionTo('tabs.add.import', {
code: data
});
});
} else if (
!parsed.isValid
|| parsed.privateKey
|| (sendFlowService.state.isEmpty() && !parsed.url && !parsed.amount)
) {
root.showMenu({ root.showMenu({
original: data, original: data,
parsed: parsed parsed: parsed
}); });
}); } else {
var state = sendFlowService.state.getClone();
state.data = data;
sendFlowService.start(state, function onError(err) {
/**
* OnError, open the menu (link not validated)
*/
root.showMenu({
original: data,
parsed: parsed
});
});
}
}
} 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) {
$log.warn('Unknown URL! : ' + url); if (err) {
} $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) {