Wallet/src/js/services/send-flow-router.service.js

83 lines
1.8 KiB
JavaScript
Raw Normal View History

'use strict';
(function(){
angular
.module('copayApp.services')
.factory('sendFlowRouterService', sendFlowRouterService);
2018-08-29 17:28:07 +09:00
function sendFlowRouterService(
sendFlowStateService
2018-08-30 16:03:51 +09:00
, $state, $ionicHistory, $timeout
2018-08-29 17:28:07 +09:00
) {
2018-08-29 17:28:07 +09:00
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")
// Functions
start: start,
goNext: goNext,
goBack: goBack,
};
2018-08-29 17:28:07 +09:00
return service;
/**
*
*/
function start() {
2018-08-29 17:28:07 +09:00
if ($state.current.name != 'tabs.send') {
$state.go('tabs.home').then(function () {
$ionicHistory.clearHistory();
2018-08-30 16:03:51 +09:00
$state.go('tabs.send').then(function () {
$timeout(function () {
goNext();
}, 60);
});
2018-08-29 17:28:07 +09:00
});
} else {
goNext();
}
}
/**
2018-08-30 16:03:51 +09:00
* Strategy
* https://bitcoindotcom.atlassian.net/wiki/x/BQDWKQ
*/
2018-08-29 17:28:07 +09:00
function goNext() {
var state = sendFlowStateService.state;
2018-08-30 16:03:51 +09:00
var needsDestination = !state.toWalletId && !state.toAddress;
var needsOrigin = !state.fromWalletId;
var needsAmount = !state.amount && !state.sendMax;
if (needsDestination) {
if (!state.isWalletTransfer && !state.thirdParty) {
$state.go('tabs.send');
return;
} else if (!needsOrigin) {
$state.go('tabs.send.destination');
return;
}
}
if (needsOrigin) {
$state.go('tabs.send.origin');
} else if (needsAmount) {
$state.go('tabs.send.amount');
} else {
$state.go('tabs.send.review');
2018-08-29 17:28:07 +09:00
}
}
function goBack() {
/**
* Strategy
*/
$ionicHistory.goBack();
}
};
})();