Fix for wallet selection header when in Shapeshift flow. Also fixed a coin already present bug that occurred in subsequent Shapeshift flows.

This commit is contained in:
Brendon Duncan 2018-08-13 10:00:39 +12:00
commit 5445ddbecd
6 changed files with 47 additions and 43 deletions

View file

@ -67,15 +67,14 @@ function amountController(configService, $filter, gettextCatalog, $ionicHistory,
} }
function onBeforeEnter(event, data) { function onBeforeEnter(event, data) {
console.log('amount onBeforeEnter sendflow ', sendFlowService.getState());
if (data.direction == "back") { if (data.direction == "back") {
sendFlowService.popState(); sendFlowService.popState();
} }
console.log('amount onBeforeEnter after back sendflow ', sendFlowService.state);
initCurrencies(); initCurrencies();
passthroughParams = sendFlowService; passthroughParams = sendFlowService.getStateClone();
vm.fromWalletId = passthroughParams.fromWalletId; vm.fromWalletId = passthroughParams.fromWalletId;
vm.toWalletId = passthroughParams.toWalletId; vm.toWalletId = passthroughParams.toWalletId;

View file

@ -75,9 +75,9 @@ function reviewController(addressbookService, bitcoinCashJsService, bitcore, bit
function onBeforeEnter(event, data) { function onBeforeEnter(event, data) {
console.log('walletSelector onBeforeEnter sendflow ', sendFlowService.getState()); console.log('walletSelector onBeforeEnter sendflow ', sendFlowService.state);
defaults = configService.getDefaults(); defaults = configService.getDefaults();
sendFlowData = sendFlowService.getState(); sendFlowData = sendFlowService.getStateClone();
originWalletId = sendFlowData.fromWalletId; originWalletId = sendFlowData.fromWalletId;
satoshis = parseInt(sendFlowData.amount, 10); satoshis = parseInt(sendFlowData.amount, 10);
toAddress = sendFlowData.toAddress; toAddress = sendFlowData.toAddress;

View file

@ -29,7 +29,7 @@ angular.module('copayApp.controllers').controller('tabSendController', function(
$scope.$on("$ionicView.enter", function(event, data) { $scope.$on("$ionicView.enter", function(event, data) {
var stateParams = sendFlowService.getState(); var stateParams = sendFlowService.getStateClone();
$scope.fromWallet = profileService.getWallet(stateParams.fromWalletId); $scope.fromWallet = profileService.getWallet(stateParams.fromWalletId);
clipboardService.readFromClipboard(function(text) { clipboardService.readFromClipboard(function(text) {
@ -184,7 +184,7 @@ angular.module('copayApp.controllers').controller('tabSendController', function(
$log.debug('Got toAddress:' + toAddress + ' | ' + item.name); $log.debug('Got toAddress:' + toAddress + ' | ' + item.name);
var stateParams = sendFlowService.getState(); var stateParams = sendFlowService.getStateClone();
stateParams.toAddress = toAddress, stateParams.toAddress = toAddress,
stateParams.coin = item.coin; stateParams.coin = item.coin;
sendFlowService.pushState(stateParams); sendFlowService.pushState(stateParams);
@ -200,7 +200,7 @@ angular.module('copayApp.controllers').controller('tabSendController', function(
$scope.startWalletToWalletTransfer = function() { $scope.startWalletToWalletTransfer = function() {
console.log('startWalletToWalletTransfer()'); console.log('startWalletToWalletTransfer()');
var params = sendFlowService.getState(); var params = sendFlowService.getStateClone();
sendFlowService.pushState(params); sendFlowService.pushState(params);
$state.transitionTo('tabs.send.wallet-to-wallet', { $state.transitionTo('tabs.send.wallet-to-wallet', {
fromWalletId: sendFlowService.fromWalletId fromWalletId: sendFlowService.fromWalletId
@ -222,7 +222,7 @@ angular.module('copayApp.controllers').controller('tabSendController', function(
$scope.$on("$ionicView.beforeEnter", function(event, data) { $scope.$on("$ionicView.beforeEnter", function(event, data) {
console.log(data); console.log(data);
console.log('tab-send onBeforeEnter sendflow ', sendFlowService.getState()); console.log('tab-send onBeforeEnter sendflow ', sendFlowService.state);
$scope.isIOS = platformInfo.isIOS && platformInfo.isCordova; $scope.isIOS = platformInfo.isIOS && platformInfo.isCordova;
$scope.showWalletsBch = $scope.showWalletsBtc = $scope.showWallets = false; $scope.showWalletsBch = $scope.showWalletsBtc = $scope.showWallets = false;

View file

@ -11,13 +11,12 @@ angular.module('copayApp.controllers').controller('walletSelectorController', fu
$scope.$on("$ionicView.enter", onEnter); $scope.$on("$ionicView.enter", onEnter);
function onBeforeEnter(event, data) { function onBeforeEnter(event, data) {
console.log('walletSelector onBeforeEnter sendflow', sendFlowService.getState());
if (data.direction == "back") { if (data.direction == "back") {
sendFlowService.popState(); sendFlowService.popState();
} }
console.log('walletSelector onBeforeEnter after back sendflow', sendFlowService.state);
$scope.params = sendFlowService.getState(); $scope.params = sendFlowService.getStateClone();
var config = configService.getSync().wallet.settings; var config = configService.getSync().wallet.settings;
priceDisplayAsFiat = config.priceDisplay === 'fiat'; priceDisplayAsFiat = config.priceDisplay === 'fiat';
@ -29,7 +28,7 @@ angular.module('copayApp.controllers').controller('walletSelectorController', fu
$scope.sendFlowTitle = gettextCatalog.getString('Wallet to Wallet Transfer'); $scope.sendFlowTitle = gettextCatalog.getString('Wallet to Wallet Transfer');
break; break;
case 'tabs.send.destination': case 'tabs.send.destination':
if ($scope.params.fromWalletId) { if ($scope.params.fromWalletId && !$scope.params.thirdParty) {
$scope.sendFlowTitle = gettextCatalog.getString('Wallet to Wallet Transfer'); $scope.sendFlowTitle = gettextCatalog.getString('Wallet to Wallet Transfer');
} }
break; break;
@ -45,7 +44,7 @@ angular.module('copayApp.controllers').controller('walletSelectorController', fu
fromWalletId = $scope.params['fromWalletId']; fromWalletId = $scope.params['fromWalletId'];
if ($scope.type === 'destination' && $scope.params.toAddress) { if ($scope.type === 'destination' && $scope.params.toAddress) {
$state.transitionTo(getNextStep()); $state.transitionTo(getNextStep($scope.params));
} }
if ($scope.params.coin) { if ($scope.params.coin) {
@ -105,13 +104,10 @@ angular.module('copayApp.controllers').controller('walletSelectorController', fu
} }
} }
function getNextStep() { function getNextStep(params) {
if ($scope.thirdParty) { if (!params.toWalletId && !params.toAddress) { // If we have no toAddress or fromWallet
$scope.params.thirdParty = $scope.thirdParty
}
if (!$scope.params.toWalletId && !$scope.params.toAddress) { // If we have no toAddress or fromWallet
return 'tabs.send.destination'; return 'tabs.send.destination';
} else if (!$scope.params.amount) { // If we have no amount } else if (!params.amount) { // If we have no amount
return 'tabs.send.amount'; return 'tabs.send.amount';
} else { // If we do have them } else { // If we do have them
return 'tabs.send.review'; return 'tabs.send.review';
@ -195,14 +191,16 @@ angular.module('copayApp.controllers').controller('walletSelectorController', fu
$scope.useWallet = function(wallet) { $scope.useWallet = function(wallet) {
var params = sendFlowService.getState(); var params = sendFlowService.getStateClone();
if ($scope.type === 'origin') { // we're on the origin screen, set wallet to send from if ($scope.type === 'origin') { // we're on the origin screen, set wallet to send from
params.fromWalletId = wallet.id; params.fromWalletId = wallet.id;
} else { // we're on the destination screen, set wallet to send to } else { // we're on the destination screen, set wallet to send to
params.toWalletId = wallet.id; params.toWalletId = wallet.id;
} }
sendFlowService.pushState(params); sendFlowService.pushState(params);
$state.transitionTo(getNextStep(), $scope.params); var nextStep = getNextStep(params);
console.log('walletSelector nextStep', nextStep);
$state.transitionTo(nextStep, $scope.params);
}; };
$scope.goBack = function() { $scope.goBack = function() {

View file

@ -82,7 +82,7 @@ angular.module('copayApp.services').factory('incomingData', function($log, $stat
}); });
// Timeout is required to enable the "Back" button // Timeout is required to enable the "Back" button
$timeout(function() { $timeout(function() {
var params = sendFlowService.getState(); var params = sendFlowService.getStateClone();
if (amount) { if (amount) {
params.amount = amount; params.amount = amount;
@ -455,7 +455,8 @@ angular.module('copayApp.services').factory('incomingData', function($log, $stat
stateParams.requiredFeeRate = thirdPartyData.requiredFeeRate * 1024; stateParams.requiredFeeRate = thirdPartyData.requiredFeeRate * 1024;
} }
sendFlowService.pushState(thirdPartyData); // This does not make sense, thirdPartyData gets added by stateParams below
//sendFlowService.pushState(thirdPartyData);
scannerService.pausePreview(); scannerService.pausePreview();
$state.go('tabs.send', {}, { $state.go('tabs.send', {}, {

View file

@ -9,17 +9,21 @@ angular
function sendFlowService($log) { function sendFlowService($log) {
var service = { var service = {
amount: '', // A separate state variable so we can ensure it is cleared of everything,
fromWalletId: '', // even other properties added that this service does not know about. (such as "coin")
sendMax: false, state: {
thirdParty: null, amount: '',
toAddress: '', fromWalletId: '',
toWalletId: '', sendMax: false,
thirdParty: null,
toAddress: '',
toWalletId: ''
},
previousStates: [], previousStates: [],
// Functions // Functions
clear: clear, clear: clear,
getState: getState, getStateClone: getStateClone,
map: map, map: map,
popState: popState, popState: popState,
pushState: pushState, pushState: pushState,
@ -36,22 +40,24 @@ angular
function clearCurrent() { function clearCurrent() {
console.log("sendFlow clearCurrent()"); console.log("sendFlow clearCurrent()");
service.amount = ''; service.state = {
service.fromWalletId = ''; amount: '',
service.sendMax = false; fromWalletId: '',
service.thirdParty = null; sendMax: false,
service.toAddress = ''; thirdParty: null,
service.toWalletId = ''; toAddress: '',
toWalletId: ''
}
} }
/** /**
* Handy for debugging * Handy for debugging
*/ */
function getState() { function getStateClone() {
var currentState = {}; var currentState = {};
Object.keys(service).forEach(function forCurrentParam(key) { Object.keys(service.state).forEach(function forCurrentParam(key) {
if (typeof service[key] !== 'function' && key !== 'previousStates') { if (typeof service.state[key] !== 'function' && key !== 'previousStates') {
currentState[key] = service[key]; currentState[key] = service.state[key];
} }
}); });
return currentState; return currentState;
@ -68,7 +74,7 @@ angular
function map(params) { function map(params) {
Object.keys(params).forEach(function forNewParam(key) { Object.keys(params).forEach(function forNewParam(key) {
service[key] = params[key]; service.state[key] = params[key];
}); });
}; };
@ -85,7 +91,7 @@ angular
function pushState(params) { function pushState(params) {
console.log('sendFlow push'); console.log('sendFlow push');
var currentParams = getState(); var currentParams = getStateClone();
service.previousStates.push(currentParams); service.previousStates.push(currentParams);
clearCurrent(); clearCurrent();
map(params); map(params);