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

@ -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();
}
};