Rename incomingData to incomingDataService

This commit is contained in:
Jean-Baptiste Dominguez 2018-09-04 11:24:07 +09:00
commit c715fdcb41
10 changed files with 98 additions and 87 deletions

View file

@ -1,6 +1,6 @@
'use strict'; 'use strict';
angular.module('copayApp.controllers').controller('tabScanController', function(bitcoinUriService, gettextCatalog, popupService, $scope, $log, $timeout, scannerService, incomingData, $state, $ionicHistory, $rootScope, $ionicNavBarDelegate) { angular.module('copayApp.controllers').controller('tabScanController', function(gettextCatalog, popupService, $scope, $log, $timeout, scannerService, incomingDataService, $state, $ionicHistory, $rootScope, $ionicNavBarDelegate) {
var scannerStates = { var scannerStates = {
unauthorized: 'unauthorized', unauthorized: 'unauthorized',
@ -111,7 +111,7 @@ 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) { incomingDataService.redir(contents, function onError(err) {
if (err) { if (err) {
var title = gettextCatalog.getString('Scan Failed'); var title = gettextCatalog.getString('Scan Failed');
popupService.showAlert(title, err.message, function onAlertShown() { popupService.showAlert(title, err.message, function onAlertShown() {

View file

@ -1,6 +1,6 @@
'use strict'; 'use strict';
angular.module('copayApp.controllers').controller('tabSendController', function(bitcoinUriService, $scope, $rootScope, $log, $timeout, $ionicScrollDelegate, $ionicLoading, addressbookService, profileService, lodash, $state, walletService, incomingData, popupService, platformInfo, sendFlowService, bwcError, gettextCatalog, scannerService, configService, bitcoinCashJsService, $ionicPopup, $ionicNavBarDelegate, clipboardService) { angular.module('copayApp.controllers').controller('tabSendController', function(bitcoinUriService, $scope, $log, $timeout, $ionicScrollDelegate, addressbookService, profileService, lodash, $state, walletService, platformInfo, sendFlowService, gettextCatalog, configService, $ionicPopup, $ionicNavBarDelegate, clipboardService, incomingDataService) {
var clipboardHasAddress = false; var clipboardHasAddress = false;
var clipboardHasContent = false; var clipboardHasContent = false;
var originalList; var originalList;
@ -62,14 +62,6 @@ angular.module('copayApp.controllers').controller('tabSendController', function(
}); });
$scope.findContact = function(search) { $scope.findContact = function(search) {
sendFlowService.start({
data: search
});
return;
//if (incomingData.redir(search)) {
//return;
//}
if (!search || search.length < 1) { if (!search || search.length < 1) {
$scope.list = originalList; $scope.list = originalList;
$timeout(function() { $timeout(function() {
@ -78,12 +70,16 @@ angular.module('copayApp.controllers').controller('tabSendController', function(
return; return;
} }
var result = lodash.filter(originalList, function(item) { var params = sendFlowService.state.getClone();
var val = item.name; params.data = search;
return lodash.startsWith(val.toLowerCase(), search.toLowerCase()); sendFlowService.start(params, function onError() {
}); var result = lodash.filter(originalList, function(item) {
var val = item.name;
return lodash.startsWith(val.toLowerCase(), search.toLowerCase());
});
$scope.list = result; $scope.list = result;
});
}; };
var hasWallets = function() { var hasWallets = function() {
@ -190,26 +186,17 @@ angular.module('copayApp.controllers').controller('tabSendController', function(
$log.debug('Got toAddress:' + toAddress + ' | ' + item.name); $log.debug('Got toAddress:' + toAddress + ' | ' + item.name);
var stateParams = sendFlowService.state.getClone(); var stateParams = sendFlowService.state.getClone();
stateParams.toAddress = toAddress, stateParams.toAddress = toAddress;
stateParams.coin = item.coin; stateParams.coin = item.coin;
sendFlowService.goNext(stateParams); sendFlowService.start(stateParams);
/*if (!stateParams.fromWalletId) { // If we have no toAddress or fromWallet
$state.transitionTo('tabs.send.origin');
} else {
$state.transitionTo('tabs.send.amount');
}*/
}); });
}; };
$scope.startWalletToWalletTransfer = function() { $scope.startWalletToWalletTransfer = function() {
console.log('startWalletToWalletTransfer()'); console.log('startWalletToWalletTransfer()');
var params = sendFlowService.state.getClone(); var params = sendFlowService.state.getClone();
sendFlowService.goNext({ params.isWalletTransfer = true;
isWalletTransfer: true, sendFlowService.start(params);
fromWalletId: params.fromWalletId
});
} }
// This could probably be enhanced refactoring the routes abstract states // This could probably be enhanced refactoring the routes abstract states

View file

@ -1,9 +1,9 @@
'use strict'; 'use strict';
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, incomingDataService, lodash, popupService, gettextCatalog, scannerService, sendFlowService) {
$scope.onScan = function(data) { $scope.onScan = function(data) {
incomingData.redir(data, function onError(err) { incomingDataService.redir(data, function onError(err) {
if (err) { if (err) {
popupService.showAlert(gettextCatalog.getString('Error'), err.message); popupService.showAlert(gettextCatalog.getString('Error'), err.message);
} }
@ -40,7 +40,7 @@ angular.module('copayApp.controllers').controller('tabsController', function($ro
if (err) { if (err) {
popupService.showAlert(gettextCatalog.getString('Error'), err.message); popupService.showAlert(gettextCatalog.getString('Error'), err.message);
} else { } else {
incomingData.redir(contents, function onError(err) { incomingDataService.redir(contents, function onError(err) {
if (err) { if (err) {
popupService.showAlert(gettextCatalog.getString('Error'), err.message); popupService.showAlert(gettextCatalog.getString('Error'), err.message);
} }

View file

@ -1,6 +1,6 @@
'use strict'; 'use strict';
angular.module('copayApp.directives').directive('shapeshiftCoinTrader', function($interval, shapeshiftApiService, profileService, incomingData, ongoingProcess) { angular.module('copayApp.directives').directive('shapeshiftCoinTrader', function($interval, shapeshiftApiService, profileService, incomingDataService, ongoingProcess) {
return { return {
restrict: 'E', restrict: 'E',
transclude: true, transclude: true,
@ -112,7 +112,7 @@ angular.module('copayApp.directives').directive('shapeshiftCoinTrader', function
}; };
// How to handle this // How to handle this
if (incomingData.redir(sendAddress, 'shapeshift', shapeshiftData)) { if (incomingDataService.redir(sendAddress, 'shapeshift', shapeshiftData)) {
ongoingProcess.set('connectingShapeshift', false); ongoingProcess.set('connectingShapeshift', false);
return; return;
} }

View file

@ -1,10 +1,10 @@
'use strict'; 'use strict';
/** /**
* incomingData is an intermediate to redirect either to the sendFlow * incomingDataService is an intermediate to redirect either to the sendFlow
* or to import/join a wallet. * 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('incomingDataService', function(bitcoinUriService, $log, $state, $rootScope, scannerService, sendFlowService, gettextCatalog) {
var root = {}; var root = {};

View file

@ -1,6 +1,6 @@
'use strict'; 'use strict';
angular.module('copayApp.services').factory('openURLService', function($rootScope, $ionicHistory, $document, $log, $state, platformInfo, lodash, profileService, incomingData, appConfigService) { angular.module('copayApp.services').factory('openURLService', function($rootScope, $ionicHistory, $document, $log, $state, platformInfo, lodash, profileService, incomingDataService, appConfigService) {
var root = {}; var root = {};
var handleOpenURL = function(args) { var handleOpenURL = function(args) {
@ -23,7 +23,7 @@ angular.module('copayApp.services').factory('openURLService', function($rootScop
document.addEventListener('handleopenurl', handleOpenURL, false); document.addEventListener('handleopenurl', handleOpenURL, false);
incomingData.redir(url, function onError(err) { incomingDataService.redir(url, function onError(err) {
if (err) { if (err) {
$log.warn('Unknown URL! : ' + url); $log.warn('Unknown URL! : ' + url);
popupService.showAlert(gettextCatalog.getString('Error'), err.message); popupService.showAlert(gettextCatalog.getString('Error'), err.message);

View file

@ -12,9 +12,6 @@ angular
) { ) {
var service = { var service = {
// A separate state variable so we can ensure it is cleared of everything,
// even other properties added that this service does not know about. (such as "coin")
// Functions // Functions
start: start, start: start,
goNext: goNext, goNext: goNext,
@ -24,7 +21,7 @@ angular
return service; return service;
/** /**
* * Start new send flow
*/ */
function start() { function start() {
var state = sendFlowStateService.state; var state = sendFlowStateService.state;
@ -48,8 +45,8 @@ angular
} }
/** /**
* Strategy * Go to the next page
* https://bitcoindotcom.atlassian.net/wiki/x/BQDWKQ * Routing strategy : https://bitcoindotcom.atlassian.net/wiki/x/BQDWKQ
*/ */
function goNext() { function goNext() {
var state = sendFlowStateService.state; var state = sendFlowStateService.state;
@ -77,11 +74,10 @@ angular
} }
} }
/**
* Go to the previous page
*/
function goBack() { function goBack() {
/**
* Strategy
*/
$ionicHistory.goBack(); $ionicHistory.goBack();
} }
}; };

View file

@ -6,11 +6,10 @@ angular
.module('copayApp.services') .module('copayApp.services')
.factory('sendFlowStateService', sendFlowStateService); .factory('sendFlowStateService', sendFlowStateService);
function sendFlowStateService() { function sendFlowStateService($log) {
var service = { var service = {
// A separate state variable so we can ensure it is cleared of everything, // Variables
// even other properties added that this service does not know about. (such as "coin")
state: { state: {
amount: '', amount: '',
displayAddress: null, displayAddress: null,
@ -34,7 +33,13 @@ angular
return service; return service;
/**
* Init state & stack
* @param {Object} params
*/
function init(params) { function init(params) {
$log.debug("send-flow-state init()");
clear(); clear();
if (params) { if (params) {
@ -42,14 +47,22 @@ angular
} }
} }
/**
* Clear a state & stack
*/
function clear() { function clear() {
console.log("sendFlow clear()"); $log.debug("send-flow-state clear()");
clearCurrent(); clearCurrent();
service.previousStates = []; service.previousStates = [];
} }
/**
* Clear current state only
*/
function clearCurrent() { function clearCurrent() {
console.log("sendFlow clearCurrent()"); $log.debug("send-flow-state clearCurrent()");
service.state = { service.state = {
amount: '', amount: '',
displayAddress: null, displayAddress: null,
@ -62,7 +75,7 @@ angular
} }
/** /**
* Handy for debugging * Get a clone of the current state
*/ */
function getClone() { function getClone() {
var currentState = {}; var currentState = {};
@ -74,14 +87,22 @@ angular
return currentState; return currentState;
} }
/**
* Fill in the current state from the params
* @param {Object} params
*/
function map(params) { function map(params) {
Object.keys(params).forEach(function forNewParam(key) { Object.keys(params).forEach(function forNewParam(key) {
service.state[key] = params[key]; service.state[key] = params[key];
}); });
}; };
/**
* Pop state
*/
function pop() { function pop() {
console.log('sendFlow pop'); $log.debug('send-flow-state pop');
if (service.previousStates.length) { if (service.previousStates.length) {
var params = service.previousStates.pop(); var params = service.previousStates.pop();
clearCurrent(); clearCurrent();
@ -91,14 +112,22 @@ angular
} }
}; };
/**
* Push state
* @param {Object} params
*/
function push(params) { function push(params) {
console.log('sendFlow push'); $log.debug('send-flow-state push');
var currentParams = getClone(); var currentParams = getClone();
service.previousStates.push(currentParams); service.previousStates.push(currentParams);
clearCurrent(); clearCurrent();
map(params); map(params);
}; };
/**
* Is empty stack
*/
function isEmpty() { function isEmpty() {
return service.previousStates.length == 0; return service.previousStates.length == 0;
}; };

View file

@ -10,12 +10,11 @@ angular
sendFlowStateService, sendFlowRouterService sendFlowStateService, sendFlowRouterService
, bitcoinUriService, payproService, bitcoinCashJsService , bitcoinUriService, payproService, bitcoinCashJsService
, popupService, gettextCatalog , popupService, gettextCatalog
, $state , $state, $log
) { ) {
var service = { var service = {
// A separate state variable so we can ensure it is cleared of everything, // Variables
// even other properties added that this service does not know about. (such as "coin")
state: sendFlowStateService, state: sendFlowStateService,
router: sendFlowRouterService, router: sendFlowRouterService,
@ -28,19 +27,19 @@ angular
return service; return service;
/** /**
* Clears all previous state * Start a new send flow
* @param {Object} params
* @param {Function} onError
*/ */
function start(params, onError) { function start(params, onError) {
console.log('start()'); $log.debug('send-flow start()');
if (params && params.data) { if (params && params.data) {
var res = bitcoinUriService.parse(params.data); var res = bitcoinUriService.parse(params.data);
if (res.isValid) { if (res.isValid) {
/** // If BIP70 (url)
* If BIP70
*/
if (res.url) { if (res.url) {
var url = res.url; var url = res.url;
var coin = res.coin || ''; var coin = res.coin || '';
@ -81,18 +80,14 @@ angular
verified: true verified: true
}; };
/** // Fill in params
* Fill in params
*/
params.amount = thirdPartyData.amount, params.amount = thirdPartyData.amount,
params.toAddress = thirdPartyData.toAddress, params.toAddress = thirdPartyData.toAddress,
params.coin = coin, params.coin = coin,
params.thirdParty = thirdPartyData params.thirdParty = thirdPartyData
} }
/** // Resolve
* Resolve
*/
_next(); _next();
}); });
} else { } else {
@ -107,7 +102,8 @@ angular
if (res.publicAddress) { if (res.publicAddress) {
var prefix = res.isTestnet ? 'bchtest:' : 'bitcoincash:'; var prefix = res.isTestnet ? 'bchtest:' : 'bitcoincash:';
params.displayAddress = res.publicAddress.cashAddr || res.publicAddress.legacy || res.publicAddress.bitpay; params.displayAddress = res.publicAddress.cashAddr || res.publicAddress.legacy || res.publicAddress.bitpay;
params.toAddress = bitcoinCashJsService.readAddress((prefix + res.publicAddress.cashAddr) || res.publicAddress.legacy || res.publicAddress.bitpay).legacy; var formatAddress = res.publicAddress.cashAddr ? prefix + params.displayAddress : params.displayAddress;
params.toAddress = bitcoinCashJsService.readAddress(formatAddress).legacy;
} }
_next(); _next();
@ -126,32 +122,35 @@ angular
function _next() { function _next() {
sendFlowStateService.init(params); sendFlowStateService.init(params);
/** // Routing strategy to -> send-flow-router.service
* Routing strategy to -> send-flow-router.service
*/
sendFlowRouterService.start(); sendFlowRouterService.start();
} }
} }
/**
* Go to the next step
* @param {Object} state
*/
function goNext(state) { function goNext(state) {
/** $log.debug('send-flow goNext()');
* Save the current route before leaving
*/ // Save the current route before leaving
state.route = $state.current.name; state.route = $state.current.name;
/** // Save the state and redirect the user
* Save the state and redirect the user
*/
sendFlowStateService.push(state); sendFlowStateService.push(state);
sendFlowRouterService.goNext(); sendFlowRouterService.goNext();
} }
/**
* Go to the previous step
*/
function goBack() { function goBack() {
/** $log.debug('send-flow goBack()');
* Remove the state on top and redirect the user
*/ // Remove the state on top and redirect the user
sendFlowStateService.pop(); sendFlowStateService.pop();
sendFlowRouterService.goBack(); sendFlowRouterService.goBack();
} }
}; };

View file

@ -1,6 +1,6 @@
'use strict'; 'use strict';
angular.module('copayApp.services').factory('shapeshiftService', function ($http, $interval, $log, lodash, moment, ongoingProcess, shapeshiftApiService, storageService, configService, incomingData, platformInfo, servicesService) { angular.module('copayApp.services').factory('shapeshiftService', function ($http, $interval, $log, lodash, moment, ongoingProcess, shapeshiftApiService, storageService, configService, incomingDataService, platformInfo, servicesService) {
var root = {}; var root = {};
root.ShiftState = 'Shift'; root.ShiftState = 'Shift';
root.coinIn = ''; root.coinIn = '';
@ -111,7 +111,7 @@ angular.module('copayApp.services').factory('shapeshiftService', function ($http
toAddress: txData.deposit toAddress: txData.deposit
}; };
// //
// if (incomingData.redir(sendAddress, 'shapeshift', shapeshiftData)) { // if (incomingDataService.redir(sendAddress, 'shapeshift', shapeshiftData)) {
ongoingProcess.set('connectingShapeshift', false); ongoingProcess.set('connectingShapeshift', false);
// return; // return;
// } // }