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';
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 = {
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
// that has a string data.result.
contents = contents.result || contents;
incomingData.redir(contents, function onError(err) {
incomingDataService.redir(contents, function onError(err) {
if (err) {
var title = gettextCatalog.getString('Scan Failed');
popupService.showAlert(title, err.message, function onAlertShown() {

View file

@ -1,6 +1,6 @@
'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 clipboardHasContent = false;
var originalList;
@ -62,14 +62,6 @@ angular.module('copayApp.controllers').controller('tabSendController', function(
});
$scope.findContact = function(search) {
sendFlowService.start({
data: search
});
return;
//if (incomingData.redir(search)) {
//return;
//}
if (!search || search.length < 1) {
$scope.list = originalList;
$timeout(function() {
@ -78,12 +70,16 @@ angular.module('copayApp.controllers').controller('tabSendController', function(
return;
}
var result = lodash.filter(originalList, function(item) {
var val = item.name;
return lodash.startsWith(val.toLowerCase(), search.toLowerCase());
var params = sendFlowService.state.getClone();
params.data = search;
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() {
@ -190,26 +186,17 @@ angular.module('copayApp.controllers').controller('tabSendController', function(
$log.debug('Got toAddress:' + toAddress + ' | ' + item.name);
var stateParams = sendFlowService.state.getClone();
stateParams.toAddress = toAddress,
stateParams.toAddress = toAddress;
stateParams.coin = item.coin;
sendFlowService.goNext(stateParams);
/*if (!stateParams.fromWalletId) { // If we have no toAddress or fromWallet
$state.transitionTo('tabs.send.origin');
} else {
$state.transitionTo('tabs.send.amount');
}*/
sendFlowService.start(stateParams);
});
};
$scope.startWalletToWalletTransfer = function() {
console.log('startWalletToWalletTransfer()');
var params = sendFlowService.state.getClone();
sendFlowService.goNext({
isWalletTransfer: true,
fromWalletId: params.fromWalletId
});
params.isWalletTransfer = true;
sendFlowService.start(params);
}
// This could probably be enhanced refactoring the routes abstract states

View file

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

View file

@ -1,6 +1,6 @@
'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 {
restrict: 'E',
transclude: true,
@ -112,7 +112,7 @@ angular.module('copayApp.directives').directive('shapeshiftCoinTrader', function
};
// How to handle this
if (incomingData.redir(sendAddress, 'shapeshift', shapeshiftData)) {
if (incomingDataService.redir(sendAddress, 'shapeshift', shapeshiftData)) {
ongoingProcess.set('connectingShapeshift', false);
return;
}

View file

@ -1,10 +1,10 @@
'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.
*/
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 = {};

View file

@ -1,6 +1,6 @@
'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 handleOpenURL = function(args) {
@ -23,7 +23,7 @@ angular.module('copayApp.services').factory('openURLService', function($rootScop
document.addEventListener('handleopenurl', handleOpenURL, false);
incomingData.redir(url, function onError(err) {
incomingDataService.redir(url, function onError(err) {
if (err) {
$log.warn('Unknown URL! : ' + url);
popupService.showAlert(gettextCatalog.getString('Error'), err.message);

View file

@ -12,9 +12,6 @@ angular
) {
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
start: start,
goNext: goNext,
@ -24,7 +21,7 @@ angular
return service;
/**
*
* Start new send flow
*/
function start() {
var state = sendFlowStateService.state;
@ -48,8 +45,8 @@ angular
}
/**
* Strategy
* https://bitcoindotcom.atlassian.net/wiki/x/BQDWKQ
* Go to the next page
* Routing strategy : https://bitcoindotcom.atlassian.net/wiki/x/BQDWKQ
*/
function goNext() {
var state = sendFlowStateService.state;
@ -77,11 +74,10 @@ angular
}
}
/**
* Go to the previous page
*/
function goBack() {
/**
* Strategy
*/
$ionicHistory.goBack();
}
};

View file

@ -6,11 +6,10 @@ angular
.module('copayApp.services')
.factory('sendFlowStateService', sendFlowStateService);
function sendFlowStateService() {
function sendFlowStateService($log) {
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")
// Variables
state: {
amount: '',
displayAddress: null,
@ -34,7 +33,13 @@ angular
return service;
/**
* Init state & stack
* @param {Object} params
*/
function init(params) {
$log.debug("send-flow-state init()");
clear();
if (params) {
@ -42,14 +47,22 @@ angular
}
}
/**
* Clear a state & stack
*/
function clear() {
console.log("sendFlow clear()");
$log.debug("send-flow-state clear()");
clearCurrent();
service.previousStates = [];
}
/**
* Clear current state only
*/
function clearCurrent() {
console.log("sendFlow clearCurrent()");
$log.debug("send-flow-state clearCurrent()");
service.state = {
amount: '',
displayAddress: null,
@ -62,7 +75,7 @@ angular
}
/**
* Handy for debugging
* Get a clone of the current state
*/
function getClone() {
var currentState = {};
@ -74,14 +87,22 @@ angular
return currentState;
}
/**
* Fill in the current state from the params
* @param {Object} params
*/
function map(params) {
Object.keys(params).forEach(function forNewParam(key) {
service.state[key] = params[key];
});
};
/**
* Pop state
*/
function pop() {
console.log('sendFlow pop');
$log.debug('send-flow-state pop');
if (service.previousStates.length) {
var params = service.previousStates.pop();
clearCurrent();
@ -91,14 +112,22 @@ angular
}
};
/**
* Push state
* @param {Object} params
*/
function push(params) {
console.log('sendFlow push');
$log.debug('send-flow-state push');
var currentParams = getClone();
service.previousStates.push(currentParams);
clearCurrent();
map(params);
};
/**
* Is empty stack
*/
function isEmpty() {
return service.previousStates.length == 0;
};

View file

@ -10,12 +10,11 @@ angular
sendFlowStateService, sendFlowRouterService
, bitcoinUriService, payproService, bitcoinCashJsService
, popupService, gettextCatalog
, $state
, $state, $log
) {
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")
// Variables
state: sendFlowStateService,
router: sendFlowRouterService,
@ -28,19 +27,19 @@ angular
return service;
/**
* Clears all previous state
* Start a new send flow
* @param {Object} params
* @param {Function} onError
*/
function start(params, onError) {
console.log('start()');
$log.debug('send-flow start()');
if (params && params.data) {
var res = bitcoinUriService.parse(params.data);
if (res.isValid) {
/**
* If BIP70
*/
// If BIP70 (url)
if (res.url) {
var url = res.url;
var coin = res.coin || '';
@ -81,18 +80,14 @@ angular
verified: true
};
/**
* Fill in params
*/
// Fill in params
params.amount = thirdPartyData.amount,
params.toAddress = thirdPartyData.toAddress,
params.coin = coin,
params.thirdParty = thirdPartyData
}
/**
* Resolve
*/
// Resolve
_next();
});
} else {
@ -107,7 +102,8 @@ angular
if (res.publicAddress) {
var prefix = res.isTestnet ? 'bchtest:' : 'bitcoincash:';
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();
@ -126,32 +122,35 @@ angular
function _next() {
sendFlowStateService.init(params);
/**
* Routing strategy to -> send-flow-router.service
*/
// Routing strategy to -> send-flow-router.service
sendFlowRouterService.start();
}
}
/**
* Go to the next step
* @param {Object} state
*/
function goNext(state) {
/**
* Save the current route before leaving
*/
$log.debug('send-flow goNext()');
// Save the current route before leaving
state.route = $state.current.name;
/**
* Save the state and redirect the user
*/
// Save the state and redirect the user
sendFlowStateService.push(state);
sendFlowRouterService.goNext();
}
/**
* Go to the previous step
*/
function goBack() {
/**
* Remove the state on top and redirect the user
*/
sendFlowStateService.pop();
sendFlowRouterService.goBack();
$log.debug('send-flow goBack()');
// Remove the state on top and redirect the user
sendFlowStateService.pop();
sendFlowRouterService.goBack();
}
};

View file

@ -1,6 +1,6 @@
'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 = {};
root.ShiftState = 'Shift';
root.coinIn = '';
@ -111,7 +111,7 @@ angular.module('copayApp.services').factory('shapeshiftService', function ($http
toAddress: txData.deposit
};
//
// if (incomingData.redir(sendAddress, 'shapeshift', shapeshiftData)) {
// if (incomingDataService.redir(sendAddress, 'shapeshift', shapeshiftData)) {
ongoingProcess.set('connectingShapeshift', false);
// return;
// }