diff --git a/src/js/controllers/amount.js b/src/js/controllers/amount.js index 8ff214d87..6f513663c 100644 --- a/src/js/controllers/amount.js +++ b/src/js/controllers/amount.js @@ -66,6 +66,7 @@ function amountController(configService, $filter, gettextCatalog, $ionicHistory, } function onBeforeEnter(event, data) { + console.log('amount onBeforeEnter sendflow ', sendFlowService.getState()); initCurrencies(); @@ -209,7 +210,7 @@ function amountController(configService, $filter, gettextCatalog, $ionicHistory, } function goBack() { - sendFlowService.previousState(); + sendFlowService.popState(); if (vm.thirdParty && vm.thirdParty.id === 'shapeshift') { $state.go('tabs.send').then(function() { $ionicHistory.clearHistory(); @@ -471,7 +472,7 @@ function amountController(configService, $filter, gettextCatalog, $ionicHistory, confirmData['thirdParty'] = this.thirdParty; } - sendFlowService.map(confirmData); + sendFlowService.pushState(confirmData); if (!confirmData.fromWalletId) { $state.transitionTo('tabs.paymentRequest.confirm', confirmData); diff --git a/src/js/controllers/tab-send.js b/src/js/controllers/tab-send.js index 33befb8f2..3f2c1a250 100644 --- a/src/js/controllers/tab-send.js +++ b/src/js/controllers/tab-send.js @@ -189,6 +189,8 @@ angular.module('copayApp.controllers').controller('tabSendController', function( $scope.startWalletToWalletTransfer = function() { console.log('startWalletToWalletTransfer()'); + var params = sendFlowService.getState(); + sendFlowService.pushState(params); $state.transitionTo('tabs.send.wallet-to-wallet', { fromWalletId: sendFlowService.fromWalletId }); @@ -208,6 +210,7 @@ angular.module('copayApp.controllers').controller('tabSendController', function( }; $scope.$on("$ionicView.beforeEnter", function(event, data) { + console.log('tab-send onBeforeEnter sendflow ', sendFlowService.getState()); $scope.isIOS = platformInfo.isIOS && platformInfo.isCordova; $scope.showWalletsBch = $scope.showWalletsBtc = $scope.showWallets = false; diff --git a/src/js/controllers/walletSelectorController.js b/src/js/controllers/walletSelectorController.js index 69430dbb9..1c23bb24b 100644 --- a/src/js/controllers/walletSelectorController.js +++ b/src/js/controllers/walletSelectorController.js @@ -8,6 +8,8 @@ angular.module('copayApp.controllers').controller('walletSelectorController', fu var unitsFromSatoshis = 0; $scope.$on("$ionicView.beforeEnter", function(event, data) { + console.log('walletSelector onBeforeEnter sendflow', sendFlowService.getState()); + var config = configService.getSync().wallet.settings; priceDisplayAsFiat = config.priceDisplay === 'fiat'; unitDecimals = config.unitDecimals; @@ -182,16 +184,18 @@ angular.module('copayApp.controllers').controller('walletSelectorController', fu $scope.useWallet = function(wallet) { + var params = sendFlowService.getState(); if ($scope.type === 'origin') { // we're on the origin screen, set wallet to send from - $scope.params['fromWalletId'] = wallet.id; + params.fromWalletId = wallet.id; } else { // we're on the destination screen, set wallet to send to - $scope.params['toWalletId'] = wallet.id; + params.toWalletId = wallet.id; } + sendFlowService.pushState(params); $state.transitionTo(getNextStep(), $scope.params); }; $scope.goBack = function() { - sendFlowService.previousState(); + sendFlowService.popState(); $ionicHistory.goBack(); } diff --git a/src/js/services/incomingData.js b/src/js/services/incomingData.js index 91de99cf3..934f53cc7 100644 --- a/src/js/services/incomingData.js +++ b/src/js/services/incomingData.js @@ -105,10 +105,10 @@ angular.module('copayApp.services').factory('incomingData', function($log, $stat params.thirdParty = []; params.thirdParty.id = serviceId; params.thirdParty.data = serviceData; - sendFlowService.map(params); + sendFlowService.pushState(params); $state.transitionTo('tabs.send.amount', params); } else { - sendFlowService.map(params); + sendFlowService.pushState(params); $state.transitionTo('tabs.send.origin', params); } }, 100); @@ -459,7 +459,7 @@ angular.module('copayApp.services').factory('incomingData', function($log, $stat 'notify': $state.current.name == 'tabs.send' ? false : true }).then(function() { $timeout(function() { - sendFlowService.map(stateParams); + sendFlowService.pushState(stateParams); // Need to do more here $state.transitionTo('tabs.send.origin', stateParams); }); }); diff --git a/src/js/services/sendFlowService.js b/src/js/services/sendFlowService.js index 1af112ed2..9daf0f4db 100644 --- a/src/js/services/sendFlowService.js +++ b/src/js/services/sendFlowService.js @@ -19,15 +19,17 @@ angular // Functions clear: clear, + getState: getState, map: map, - previousState: previousState, + popState: popState, + pushState: pushState, startSend: startSend }; return service; function clear() { - $log.debug("Reinitialize Send Flow variables with clear()"); + console.log("sendFlow clear()"); service.amount = ''; service.fromWalletId = ''; service.sendMax = false; @@ -38,41 +40,51 @@ angular } /** - * Clears all previous state - * @param {} params + * Handy for debugging */ - function startSend(params) { - console.log('startSend()'); - clear(); - Object.keys(params).forEach(function forNewParam(key) { - service[key] = params[key]; - }); - } - - function map(params) { - + function getState() { var currentState = {}; Object.keys(service).forEach(function forCurrentParam(key) { if (typeof service[key] !== 'function' && key !== 'previousStates') { currentState[key] = service[key]; } }); - service.previousStates.push(currentState); + return currentState; + } - // Do we want to inherit the previous state here, or clear first before adding new params? + /** + * Clears all previous state + */ + function startSend(params) { + console.log('startSend()'); + clear(); + map(params); + } + function map(params) { Object.keys(params).forEach(function forNewParam(key) { service[key] = params[key]; }); }; - function previousState() { + function popState() { + console.log('sendFlow pop'); if (service.previousStates.length) { - map(service.previousStates.pop()); + var params = service.previousStates.pop(); + clear(); + map(params); } else { clear(); } }; + + function pushState(params) { + console.log('sendFlow push'); + var currentParams = getState(); + service.previousStates.push(currentParams); + clear(); + map(params); + }; }; })(); \ No newline at end of file