Refactor incomingData

This commit is contained in:
Jean-Baptiste Dominguez 2018-08-31 18:37:04 +09:00
commit ddd867092c
6 changed files with 90 additions and 55 deletions

View file

@ -8,9 +8,7 @@ angular.module('copayApp.services').factory('incomingData', function(externalLin
$rootScope.$broadcast('incomingDataMenu.showMenu', data);
};
root.redir = function(data, serviceId, serviceData) {
var originalAddress = null;
var noPrefixInAddress = 0;
root.redir = function(data) {
var allParsed = bitcoinUriService.parse(data);
if (allParsed.isValid && allParsed.isTestnet) {
@ -19,7 +17,49 @@ angular.module('copayApp.services').factory('incomingData', function(externalLin
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 (
!allParsed.isValid
|| allParsed.privateKey
|| (sendFlowService.state.isEmpty() && !allParsed.url && !allParsed.amount)
) {
root.showMenu({
original: data,
parsed: allParsed
});
} 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: allParsed
});
});
}
}
// No need to go more far
return;
/**
* The legacy code in the bottom needs to be checked and removed if any case is forgotten.
*/
if (data.toLowerCase().indexOf('bitcoin') < 0) {
noPrefixInAddress = 1;

View file

@ -29,13 +29,17 @@ angular
map: map,
pop: pop,
push: push,
isEmpty: isEmpty
};
return service;
function init(params) {
clear();
push(params);
if (params) {
push(params);
}
}
function clear() {
@ -94,6 +98,10 @@ angular
clearCurrent();
map(params);
};
function isEmpty() {
return service.previousStates.length == 0;
};
};
})();

View file

@ -30,7 +30,7 @@ angular
/**
* Clears all previous state
*/
function start(params) {
function start(params, onError) {
console.log('start()');
if (params && params.data) {
@ -101,11 +101,14 @@ angular
}
if (res.amount) {
if (res.currency) {
params.currency = res.currency;
}
params.amount = res.amount;
}
if (res.publicAddress) {
var prefix = res.testnet ? 'bchtest:' : 'bitcoincash:';
var prefix = res.isTestnet ? 'bchtest:' : 'bitcoincash:';
params.displayAddress = (prefix + res.publicAddress.cashAddr) || res.publicAddress.legacy || res.publicAddress.bitpay;
params.toAddress = bitcoinCashJsService.readAddress(params.displayAddress).legacy;
}
@ -113,7 +116,9 @@ angular
_next();
}
} else {
_next();
if (onError) {
onError();
}
}
} else {
_next();
@ -122,13 +127,7 @@ angular
// Next used for sync the async task
function _next() {
/**
* Init the state if params is defined
*/
if (params) {
sendFlowStateService.init(params);
}
sendFlowStateService.init(params);
/**
* Routing strategy to -> send-flow-router.service