redir cb
This commit is contained in:
parent
e8b3476ea1
commit
6f28f6ba2b
6 changed files with 84 additions and 111 deletions
|
|
@ -111,27 +111,17 @@ angular.module('copayApp.controllers').controller('tabScanController', function(
|
|||
// Sometimes (testing in Chrome, when reading QR Code) data is an object
|
||||
// that has a string data.result.
|
||||
contents = contents.result || contents;
|
||||
|
||||
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() {
|
||||
incomingData.redir(contents, function onError(err) {
|
||||
if (err) {
|
||||
var title = gettextCatalog.getString('Scan Failed');
|
||||
popupService.showAlert(title, err.message, 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() {
|
||||
|
|
|
|||
|
|
@ -3,9 +3,11 @@
|
|||
angular.module('copayApp.controllers').controller('tabsController', function($rootScope, $log, $scope, $state, $stateParams, $timeout, platformInfo, incomingData, lodash, popupService, gettextCatalog, scannerService, sendFlowService) {
|
||||
|
||||
$scope.onScan = function(data) {
|
||||
if (!incomingData.redir(data)) {
|
||||
popupService.showAlert(gettextCatalog.getString('Error'), gettextCatalog.getString('Invalid data'));
|
||||
}
|
||||
incomingData.redir(data, function onError(err) {
|
||||
if (err) {
|
||||
popupService.showAlert(gettextCatalog.getString('Error'), err.message);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
$scope.setScanFn = function(scanFn) {
|
||||
|
|
@ -36,10 +38,14 @@ angular.module('copayApp.controllers').controller('tabsController', function($ro
|
|||
|
||||
scannerService.useOldScanner(function(err, contents) {
|
||||
if (err) {
|
||||
popupService.showAlert(gettextCatalog.getString('Error'), err);
|
||||
return;
|
||||
popupService.showAlert(gettextCatalog.getString('Error'), err.message);
|
||||
} else {
|
||||
incomingData.redir(contents, function onError(err) {
|
||||
if (err) {
|
||||
popupService.showAlert(gettextCatalog.getString('Error'), err.message);
|
||||
}
|
||||
});
|
||||
}
|
||||
incomingData.redir(contents);
|
||||
});
|
||||
|
||||
};
|
||||
|
|
|
|||
|
|
@ -111,6 +111,7 @@ angular.module('copayApp.directives').directive('shapeshiftCoinTrader', function
|
|||
orderId: $scope.depositInfo.orderId
|
||||
};
|
||||
|
||||
// How to handle this
|
||||
if (incomingData.redir(sendAddress, 'shapeshift', shapeshiftData)) {
|
||||
ongoingProcess.set('connectingShapeshift', false);
|
||||
return;
|
||||
|
|
|
|||
|
|
@ -1,5 +1,9 @@
|
|||
'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) {
|
||||
|
||||
var root = {};
|
||||
|
|
@ -8,96 +12,68 @@ angular.module('copayApp.services').factory('incomingData', function(externalLin
|
|||
$rootScope.$broadcast('incomingDataMenu.showMenu', data);
|
||||
};
|
||||
|
||||
root.redir = function(data) {
|
||||
root.redir = function(data, cbError) {
|
||||
var parsed = bitcoinUriService.parse(data);
|
||||
|
||||
if (parsed.isValid && parsed.isTestnet) {
|
||||
popupService.showAlert(
|
||||
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();
|
||||
console.log(parsed);
|
||||
$log.debug(parsed);
|
||||
|
||||
/**
|
||||
* Strategy for the action
|
||||
*/
|
||||
if (parsed.copayInvitation) {
|
||||
$state.go('tabs.home').then(function() {
|
||||
$state.transitionTo('tabs.add.join', {
|
||||
url: data
|
||||
});
|
||||
});
|
||||
} else if (
|
||||
!parsed.isValid
|
||||
|| parsed.privateKey
|
||||
|| (sendFlowService.state.isEmpty() && !parsed.url && !parsed.amount)
|
||||
) {
|
||||
root.showMenu({
|
||||
original: data,
|
||||
parsed: parsed
|
||||
});
|
||||
|
||||
if (parsed.isValid) {
|
||||
if (parsed.isTestnet) {
|
||||
if (cbError) {
|
||||
var errorMessage = gettextCatalog.getString('Testnet is not supported.');
|
||||
cbError(new Error(errorMessage));
|
||||
}
|
||||
} else {
|
||||
var state = sendFlowService.state.getClone();
|
||||
state.data = data;
|
||||
|
||||
sendFlowService.start(state, function onError(err) {
|
||||
/**
|
||||
* OnError, open the menu (link not validated)
|
||||
*/
|
||||
scannerService.pausePreview();
|
||||
|
||||
/**
|
||||
* Strategy for the action
|
||||
*/
|
||||
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({
|
||||
original: data,
|
||||
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;
|
||||
});
|
||||
|
|
|
|||
|
|
@ -23,9 +23,12 @@ angular.module('copayApp.services').factory('openURLService', function($rootScop
|
|||
|
||||
document.addEventListener('handleopenurl', handleOpenURL, false);
|
||||
|
||||
if (!incomingData.redir(url)) {
|
||||
$log.warn('Unknown URL! : ' + url);
|
||||
}
|
||||
incomingData.redir(url, function onError(err) {
|
||||
if (err) {
|
||||
$log.warn('Unknown URL! : ' + url);
|
||||
popupService.showAlert(gettextCatalog.getString('Error'), err.message);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
var handleResume = function() {
|
||||
|
|
|
|||
|
|
@ -100,11 +100,8 @@ angular
|
|||
params.coin = res.coin;
|
||||
}
|
||||
|
||||
if (res.amount) {
|
||||
if (res.currency) {
|
||||
params.currency = res.currency;
|
||||
}
|
||||
params.amount = res.amount;
|
||||
if (res.amountInSatoshis) {
|
||||
params.amount = res.amountInSatoshis;
|
||||
}
|
||||
|
||||
if (res.publicAddress) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue