Wallet/src/js/services/incomingData.js

103 lines
3.1 KiB
JavaScript
Raw Normal View History

2016-08-25 11:18:10 -03:00
'use strict';
angular.module('copayApp.services').factory('incomingData', function(externalLinkService, bitcoinUriService, $log, $state, $timeout, $ionicHistory, bitcore, bitcoreCash, $rootScope, payproService, scannerService, sendFlowService, appConfigService, popupService, gettextCatalog, bitcoinCashJsService) {
2016-08-25 11:18:10 -03:00
var root = {};
root.showMenu = function(data) {
$rootScope.$broadcast('incomingDataMenu.showMenu', data);
};
2018-08-31 18:37:04 +09:00
root.redir = function(data) {
2018-09-03 08:28:22 +09:00
var parsed = bitcoinUriService.parse(data);
2018-09-03 08:28:22 +09:00
if (parsed.isValid && parsed.isTestnet) {
popupService.showAlert(
gettextCatalog.getString('Unsupported'),
gettextCatalog.getString('Testnet is not supported.')
);
return false;
2018-08-31 18:37:04 +09:00
} 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
*/
2018-09-03 09:08:12 +09:00
if (parsed.copayInvitation) {
$state.go('tabs.home').then(function() {
$state.transitionTo('tabs.add.join', {
url: data
});
});
} else if (
2018-09-03 08:28:22 +09:00
!parsed.isValid
|| parsed.privateKey
|| (sendFlowService.state.isEmpty() && !parsed.url && !parsed.amount)
2018-08-31 18:37:04 +09:00
) {
root.showMenu({
original: data,
2018-09-03 08:28:22 +09:00
parsed: parsed
2018-08-31 18:37:04 +09:00
});
} 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,
2018-09-03 08:28:22 +09:00
parsed: parsed
2018-08-31 18:37:04 +09:00
});
});
}
}
2018-09-03 08:28:22 +09:00
}
2018-08-31 18:37:04 +09:00
/**
* The legacy code in the bottom needs to be checked and removed if any case is forgotten.
2018-09-03 08:28:22 +09:00
* else if (data && data.match(/^copay:[0-9A-HJ-NP-Za-km-z]{70,80}$/)) {
2016-11-22 11:37:19 -03:00
$state.go('tabs.home', {}, {
'reload': true,
'notify': $state.current.name == 'tabs.home' ? false : true
}).then(function() {
$state.transitionTo('tabs.add.join', {
url: data
});
2016-10-12 09:38:41 -03:00
});
return true;
2016-08-25 11:18:10 -03:00
2016-11-22 11:37:19 -03:00
// Old join
2016-09-22 19:27:59 -03:00
} else if (data && data.match(/^[0-9A-HJ-NP-Za-km-z]{70,80}$/)) {
2016-11-22 11:37:19 -03:00
$state.go('tabs.home', {}, {
'reload': true,
'notify': $state.current.name == 'tabs.home' ? false : true
}).then(function() {
$state.transitionTo('tabs.add.join', {
url: data
});
2016-10-12 09:38:41 -03:00
});
return true;
2016-11-22 11:37:19 -03:00
} 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
});
});
2018-09-03 08:28:22 +09:00
*
*/
2016-08-25 11:18:10 -03:00
return root;
});