second step enhancement

This commit is contained in:
Jean-Baptiste Dominguez 2018-08-29 17:28:07 +09:00
commit 162fd685e5
7 changed files with 101 additions and 84 deletions

View file

@ -68,13 +68,14 @@ function amountController(configService, $filter, gettextCatalog, $ionicHistory,
function onBeforeEnter(event, data) {
if (data.direction == "back") {
sendFlowService.popState();
sendFlowService.state.pop();
}
console.log('amount onBeforeEnter after back sendflow ', sendFlowService.state);
initCurrencies();
passthroughParams = sendFlowService.getStateClone();
passthroughParams = sendFlowService.state.getClone();
console.log('amount onBeforeEnter after back sendflow ', passthroughParams);
vm.fromWalletId = passthroughParams.fromWalletId;
vm.toWalletId = passthroughParams.toWalletId;
@ -214,7 +215,7 @@ function amountController(configService, $filter, gettextCatalog, $ionicHistory,
}
function goBack() {
$ionicHistory.goBack();
sendFlowService.router.goBack();
}
function paste(value) {
@ -467,11 +468,10 @@ function amountController(configService, $filter, gettextCatalog, $ionicHistory,
confirmData.thirdParty = vm.thirdParty;
}
sendFlowService.pushState(confirmData);
if (!confirmData.fromWalletId) {
$state.transitionTo('tabs.paymentRequest.confirm', confirmData);
} else {
$state.transitionTo('tabs.send.review', confirmData);
sendFlowService.goNext(confirmData);
$scope.useSendMax = null;
}
}

View file

@ -80,7 +80,7 @@ function reviewController(addressbookService, bitcoinCashJsService, bitcore, bit
function onBeforeEnter(event, data) {
console.log('walletSelector onBeforeEnter sendflow ', sendFlowService.state);
defaults = configService.getDefaults();
sendFlowData = sendFlowService.getStateClone();
sendFlowData = sendFlowService.state.getClone();
originWalletId = sendFlowData.fromWalletId;
satoshis = parseInt(sendFlowData.amount, 10);
toAddress = sendFlowData.toAddress;
@ -403,7 +403,7 @@ function reviewController(addressbookService, bitcoinCashJsService, bitcore, bit
}
function goBack() {
$ionicHistory.goBack();
sendFlowService.router.goBack();
}
function handleDestinationAsAddress(address, originCoin) {

View file

@ -29,7 +29,7 @@ angular.module('copayApp.controllers').controller('tabSendController', function(
$scope.$on("$ionicView.enter", function(event, data) {
var stateParams = sendFlowService.getStateClone();
var stateParams = sendFlowService.state.getClone();
$scope.fromWallet = profileService.getWallet(stateParams.fromWalletId);
clipboardService.readFromClipboard(function(text) {
@ -60,10 +60,13 @@ angular.module('copayApp.controllers').controller('tabSendController', function(
});
$scope.findContact = function(search) {
if (incomingData.redir(search)) {
return;
}
sendFlowService.start({
data: search
});
return;
//if (incomingData.redir(search)) {
//return;
//}
if (!search || search.length < 1) {
$scope.list = originalList;
@ -184,26 +187,26 @@ angular.module('copayApp.controllers').controller('tabSendController', function(
$log.debug('Got toAddress:' + toAddress + ' | ' + item.name);
var stateParams = sendFlowService.getStateClone();
var stateParams = sendFlowService.state.getClone();
stateParams.toAddress = toAddress,
stateParams.coin = item.coin;
sendFlowService.pushState(stateParams);
sendFlowService.goNext(stateParams);
if (!stateParams.fromWalletId) { // If we have no toAddress or fromWallet
/*if (!stateParams.fromWalletId) { // If we have no toAddress or fromWallet
$state.transitionTo('tabs.send.origin');
} else {
$state.transitionTo('tabs.send.amount');
}
}*/
});
};
$scope.startWalletToWalletTransfer = function() {
console.log('startWalletToWalletTransfer()');
var params = sendFlowService.getStateClone();
sendFlowService.pushState(params);
$state.transitionTo('tabs.send.wallet-to-wallet', {
fromWalletId: sendFlowService.fromWalletId
var params = sendFlowService.state.getClone();
sendFlowService.goNext({
isWalletTransfer: true,
fromWalletId: params.fromWalletId
});
}
@ -238,7 +241,7 @@ angular.module('copayApp.controllers').controller('tabSendController', function(
});
if (data.direction == "back") {
sendFlowService.clear();
sendFlowService.state.clear();
}
});

View file

@ -1,6 +1,6 @@
'use strict';
angular.module('copayApp.controllers').controller('walletSelectorController', function($scope, $rootScope, $state, $log, $ionicHistory, sendFlowService, configService, gettextCatalog, profileService, txFormatService) {
angular.module('copayApp.controllers').controller('walletSelectorController', function($scope, $state, sendFlowService, configService, gettextCatalog, profileService, txFormatService) {
var fromWalletId = '';
var priceDisplayAsFiat = false;
@ -12,31 +12,22 @@ angular.module('copayApp.controllers').controller('walletSelectorController', fu
function onBeforeEnter(event, data) {
if (data.direction == "back") {
sendFlowService.popState();
sendFlowService.state.pop();
}
console.log('walletSelector onBeforeEnter after back sendflow', sendFlowService.state);
$scope.params = sendFlowService.getStateClone();
$scope.params = sendFlowService.state.getClone();
console.log('walletSelector onBeforeEnter after back sendflow', $scope.params);
var config = configService.getSync().wallet.settings;
priceDisplayAsFiat = config.priceDisplay === 'fiat';
unitDecimals = config.unitDecimals;
unitsFromSatoshis = 1 / config.unitToSatoshi;
switch($state.current.name) {
case 'tabs.send.wallet-to-wallet':
$scope.sendFlowTitle = gettextCatalog.getString('Transfer between wallets');
break;
case 'tabs.send.destination':
if ($scope.params.fromWalletId && !$scope.params.thirdParty) {
$scope.sendFlowTitle = gettextCatalog.getString('Transfer between wallets');
}
break;
default:
if (!$scope.params.thirdParty) {
$scope.sendFlowTitle = gettextCatalog.getString('Send');
}
// nop
if ($scope.params.isWalletTransfer) {
$scope.sendFlowTitle = gettextCatalog.getString('Transfer between wallets');
} else if (!$scope.params.thirdParty) {
$scope.sendFlowTitle = gettextCatalog.getString('Send');
}
$scope.coin = false; // Wallets to show (for destination screen or contacts)
@ -105,16 +96,6 @@ angular.module('copayApp.controllers').controller('walletSelectorController', fu
}
}
function getNextStep(params) {
if (!params.toWalletId && !params.toAddress) { // If we have no toAddress or fromWallet
return 'tabs.send.destination';
} else if (!params.amount) { // If we have no amount
return 'tabs.send.amount';
} else { // If we do have them
return 'tabs.send.review';
}
}
function handleThirdPartyIfShapeshift() {
console.log($scope.thirdParty, $scope.coin);
if ($scope.thirdParty.id === 'shapeshift' && $scope.type === 'destination') { // Shapeshift wants to know the
@ -192,20 +173,17 @@ angular.module('copayApp.controllers').controller('walletSelectorController', fu
$scope.useWallet = function(wallet) {
var params = sendFlowService.getStateClone();
var params = sendFlowService.state.getClone();
if ($scope.type === 'origin') { // we're on the origin screen, set wallet to send from
params.fromWalletId = wallet.id;
} else { // we're on the destination screen, set wallet to send to
params.toWalletId = wallet.id;
}
sendFlowService.pushState(params);
var nextStep = getNextStep(params);
console.log('walletSelector nextStep', nextStep);
$state.transitionTo(nextStep, $scope.params);
sendFlowService.goNext(params);
};
$scope.goBack = function() {
$ionicHistory.goBack();
sendFlowService.router.goBack();
}
});

View file

@ -6,9 +6,12 @@ angular
.module('copayApp.services')
.factory('sendFlowRouterService', sendFlowRouterService);
function sendFlowRouterService($state, $ionicHistory) {
function sendFlowRouterService(
sendFlowStateService
, $state, $ionicHistory
) {
var router = {
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")
@ -18,26 +21,41 @@ angular
goBack: goBack,
};
return router;
return service;
/**
*
*/
function start() {
$ionicHistory.clearHistory();
$state.go('tabs.send');
if ($state.current.name != 'tabs.send') {
$state.go('tabs.home').then(function () {
$ionicHistory.clearHistory();
$state.go('tabs.send');
goNext();
});
} else {
goNext();
}
}
/**
*
*/
function goNext(state) {
function goNext() {
var state = sendFlowStateService.state;
/**
* Strategy
* Clean the history & and go to the send tab.
*/
// need to complete here
if (!state.fromWalletId && (state.isWalletTransfer || (state.toWalletId || state.toAddress))) {
$state.transitionTo('tabs.send.origin');
} else if (state.fromWalletId && !state.toWalletId && !state.toAddress) {
$state.transitionTo('tabs.send.destination');
} else if (state.fromWalletId && (state.toWalletId || state.toAddress) && !state.amount) {
$state.transitionTo('tabs.send.amount');
} else if (state.fromWalletId && (state.toWalletId || state.toAddress) && state.amount) {
$state.transitionTo('tabs.send.review');
}
}
function goBack() {

View file

@ -35,7 +35,7 @@ angular
function init(params) {
clear();
map(params);
push(params);
}
function clear() {

View file

@ -10,17 +10,19 @@ angular
sendFlowStateService, sendFlowRouterService
, bitcoinUriService, payproService
, popupService
, $state
) {
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")
state: sendFlowStateService,
router: sendFlowRouterService,
// Functions
start: start,
goNext: goNext,
goBack: goBack,
getStateClone: getStateClone
goBack: goBack
};
return service;
@ -37,7 +39,9 @@ angular
if (res.isValid) {
// If BIP70
/**
* If BIP70
*/
if (res.url) {
var url = res.url;
var coin = res.coin || '';
@ -79,14 +83,18 @@ 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
*/
resolve();
});
});
@ -94,9 +102,10 @@ angular
}
}
// Init the state if params is defined
/**
* Init the state if params is defined
*/
sendFlowStateService.init(params);
console.log(params);
}
/**
@ -106,23 +115,32 @@ angular
}
function goNext(state) {
// Push the new state
/**
* Save the current route before leaving
*/
state.route = $state.current.name;
/**
* Push the new state
*/
sendFlowStateService.push(state);
// Go next
sendFlowRouterService.goNext(state);
/**
* Go next
*/
sendFlowRouterService.goNext();
}
function goBack() {
// Pop the current state
sendFlowStateService.pop();
/**
* Pop the current state
*/
sendFlowStateService.pop();
// Go back
sendFlowRouterService.goBack();
}
function getStateClone () {
return sendFlowStateService.getClone();
/**
* Go back
*/
sendFlowRouterService.goBack();
}
};