3rd step enhancement send flow

This commit is contained in:
Jean-Baptiste Dominguez 2018-08-30 16:03:51 +09:00
commit 2c0432e292
7 changed files with 77 additions and 110 deletions

View file

@ -21,28 +21,22 @@ angular.module('copayApp.controllers').controller('addressbookViewController', f
}); });
$scope.sendTo = function() { $scope.sendTo = function() {
$ionicHistory.removeBackView(); var to = '';
sendFlowService.clear(); if ($scope.addressbookEntry.coin == 'bch') {
$state.go('tabs.send'); var a = 'bitcoincash:' + $scope.addressbookEntry.address;
$timeout(function() { to = bitcoinCashJsService.readAddress(a).legacy;
var to = ''; } else {
if ($scope.addressbookEntry.coin == 'bch') { to = $scope.addressbookEntry.address;
var a = 'bitcoincash:' + $scope.addressbookEntry.address; }
to = bitcoinCashJsService.readAddress(a).legacy;
} else {
to = $scope.addressbookEntry.address;
}
var stateParams = { var stateParams = {
toAddress: to, toAddress: to,
toName: $scope.addressbookEntry.name, toName: $scope.addressbookEntry.name,
toEmail: $scope.addressbookEntry.email, toEmail: $scope.addressbookEntry.email,
coin: $scope.addressbookEntry.coin coin: $scope.addressbookEntry.coin
}; };
sendFlowService.pushState(stateParams); sendFlowService.start(stateParams);
$state.transitionTo('tabs.send.origin');
}, 100);
}; };
$scope.remove = function(addressbookEntry) { $scope.remove = function(addressbookEntry) {

View file

@ -62,18 +62,7 @@ angular.module('copayApp.controllers').controller('shapeshiftController', functi
id: 'shapeshift' id: 'shapeshift'
} }
}; };
sendFlowService.start(stateParams);
// Starting new send flow, so ensure everything is reset
sendFlowService.clear();
$state.go('tabs.home').then(function() {
$ionicHistory.clearHistory();
$state.go('tabs.send').then(function() {
$timeout(function () {
sendFlowService.pushState(stateParams);
$state.transitionTo('tabs.send.origin');
}, 60);
});
});
} }
function showMyAddress() { function showMyAddress() {

View file

@ -122,8 +122,7 @@ angular.module('copayApp.controllers').controller('tabHomeController',
}; };
$scope.startFreshSend = function() { $scope.startFreshSend = function() {
sendFlowService.clear(); sendFlowService.start();
$state.go('tabs.send');
} }
$scope.openExternalLink = function() { $scope.openExternalLink = function() {

View file

@ -27,7 +27,6 @@ angular.module('copayApp.controllers').controller('tabsController', function($ro
}; };
$scope.chooseScanner = function() { $scope.chooseScanner = function() {
sendFlowService.clear();
var isWindowsPhoneApp = platformInfo.isCordova && platformInfo.isWP; var isWindowsPhoneApp = platformInfo.isCordova && platformInfo.isWP;
if (!isWindowsPhoneApp) { if (!isWindowsPhoneApp) {

View file

@ -378,8 +378,6 @@ angular.module('copayApp.controllers').controller('walletDetailsController', fun
}); });
$scope.$on("$ionicView.beforeEnter", function(event, data) { $scope.$on("$ionicView.beforeEnter", function(event, data) {
sendFlowService.clear();
configService.whenAvailable(function (config) { configService.whenAvailable(function (config) {
$scope.selectedPriceDisplay = config.wallet.settings.priceDisplay; $scope.selectedPriceDisplay = config.wallet.settings.priceDisplay;
@ -477,15 +475,15 @@ angular.module('copayApp.controllers').controller('walletDetailsController', fun
} }
$scope.goToSend = function() { $scope.goToSend = function() {
sendFlowService.startSend({ sendFlowService.start({
fromWalletId: $scope.wallet.id fromWalletId: $scope.wallet.id
}); });
// Go home first so that the Home tab works properly // Go home first so that the Home tab works properly
$state.go('tabs.home').then(function () { /*$state.go('tabs.home').then(function () {
$ionicHistory.clearHistory(); $ionicHistory.clearHistory();
$state.go('tabs.send'); $state.go('tabs.send');
}); });*/
}; };
$scope.goToReceive = function() { $scope.goToReceive = function() {

View file

@ -85,69 +85,44 @@ angular.module('copayApp.services').factory('incomingData', function(bitcoinUriS
} }
function goSend(addr, amount, message, coin, serviceId, serviceData) { function goSend(addr, amount, message, coin, serviceId, serviceData) {
$state.go('tabs.send', {}, { var params = sendFlowService.state.getClone();
'reload': true,
'notify': $state.current.name == 'tabs.send' ? false : true
});
// Timeout is required to enable the "Back" button
$timeout(function() {
var params = sendFlowService.getStateClone();
if (amount) { if (amount) {
params.amount = amount; params.amount = amount;
} }
if (addr) { if (addr) {
params.toAddress = addr; params.toAddress = addr;
params.displayAddress = originalAddress ? originalAddress : addr; params.displayAddress = originalAddress ? originalAddress : addr;
} }
if (coin) { if (coin) {
params.coin = coin; params.coin = coin;
} }
if (noPrefixInAddress) { if (noPrefixInAddress) {
params.noPrefixInAddress = noPrefixInAddress; params.noPrefixInAddress = noPrefixInAddress;
} }
if (serviceId) { if (serviceId) {
params.thirdParty = []; params.thirdParty = [];
params.thirdParty.id = serviceId; params.thirdParty.id = serviceId;
params.thirdParty.data = serviceData; params.thirdParty.data = serviceData;
sendFlowService.pushState(params); }
$state.transitionTo('tabs.send.amount');
} else { sendFlowService.start(params);
sendFlowService.pushState(params);
$state.transitionTo('tabs.send.origin');
}
}, 100);
} }
// data extensions for Payment Protocol with non-backwards-compatible request // data extensions for Payment Protocol with non-backwards-compatible request
if (allParsed.isValid && allParsed.coin && allParsed.url && !allParsed.testnet) { if (allParsed.isValid && allParsed.coin && allParsed.url && !allParsed.testnet) {
var coin = allParsed.coin; var coin = allParsed.coin;
data = allParsed.url; data = allParsed.url;
if (allParsed.coin == 'bch') { payproService.getPayProDetails(data, allParsed.coin, function onGetPayProDetails(err, details) {
payproService.getPayProDetailsViaHttp(data, function onGetPayProDetailsViaHttp(err, details) { if (err) {
if (err) { popupService.showAlert(gettextCatalog.getString('Error'), err);
var message = err.toString(); } else {
if (typeof err.data === 'string') { handlePayPro(details, allParsed.coin);
// i.e. 'This invoice is no longer accepting payments' }
message = gettextCatalog.getString(err.data); });
}
popupService.showAlert(gettextCatalog.getString('Error'), message)
} else {
handlePayPro(details, allParsed.coin);
}
});
} else {
payproService.getPayProDetails(data, allParsed.coin, function onGetPayProDetails(err, details) {
if (err) {
popupService.showAlert(gettextCatalog.getString('Error'), err);
} else {
handlePayPro(details, allParsed.coin);
}
});
}
return true; return true;
} }

View file

@ -8,7 +8,7 @@ angular
function sendFlowRouterService( function sendFlowRouterService(
sendFlowStateService sendFlowStateService
, $state, $ionicHistory , $state, $ionicHistory, $timeout
) { ) {
var service = { var service = {
@ -30,8 +30,11 @@ angular
if ($state.current.name != 'tabs.send') { if ($state.current.name != 'tabs.send') {
$state.go('tabs.home').then(function () { $state.go('tabs.home').then(function () {
$ionicHistory.clearHistory(); $ionicHistory.clearHistory();
$state.go('tabs.send'); $state.go('tabs.send').then(function () {
goNext(); $timeout(function () {
goNext();
}, 60);
});
}); });
} else { } else {
goNext(); goNext();
@ -39,22 +42,32 @@ angular
} }
/** /**
* * Strategy
* https://bitcoindotcom.atlassian.net/wiki/x/BQDWKQ
*/ */
function goNext() { function goNext() {
var state = sendFlowStateService.state; var state = sendFlowStateService.state;
/** var needsDestination = !state.toWalletId && !state.toAddress;
* Strategy var needsOrigin = !state.fromWalletId;
*/ var needsAmount = !state.amount && !state.sendMax;
if (!state.fromWalletId && (state.isWalletTransfer || (state.toWalletId || state.toAddress))) {
$state.transitionTo('tabs.send.origin'); if (needsDestination) {
} else if (state.fromWalletId && !state.toWalletId && !state.toAddress) { if (!state.isWalletTransfer && !state.thirdParty) {
$state.transitionTo('tabs.send.destination'); $state.go('tabs.send');
} else if (state.fromWalletId && (state.toWalletId || state.toAddress) && !state.amount) { return;
$state.transitionTo('tabs.send.amount'); } else if (!needsOrigin) {
} else if (state.fromWalletId && (state.toWalletId || state.toAddress) && state.amount) { $state.go('tabs.send.destination');
$state.transitionTo('tabs.send.review'); return;
}
}
if (needsOrigin) {
$state.go('tabs.send.origin');
} else if (needsAmount) {
$state.go('tabs.send.amount');
} else {
$state.go('tabs.send.review');
} }
} }