Refactored sendFlowService and cleared its state before entering the send tab.

This commit is contained in:
Brendon Duncan 2018-08-09 11:10:26 +12:00
commit dff0d51ef3
11 changed files with 125 additions and 49 deletions

View file

@ -1,6 +1,6 @@
'use strict'; 'use strict';
angular.module('copayApp.controllers').controller('addressbookViewController', function($scope, $state, $timeout, lodash, addressbookService, popupService, $ionicHistory, platformInfo, gettextCatalog, configService, bitcoinCashJsService) { angular.module('copayApp.controllers').controller('addressbookViewController', function($scope, sendFlowService, $state, $timeout, lodash, addressbookService, popupService, $ionicHistory, platformInfo, gettextCatalog, configService, bitcoinCashJsService) {
var config = configService.getSync(); var config = configService.getSync();
var defaults = configService.getDefaults(); var defaults = configService.getDefaults();
@ -22,6 +22,7 @@ angular.module('copayApp.controllers').controller('addressbookViewController', f
$scope.sendTo = function() { $scope.sendTo = function() {
$ionicHistory.removeBackView(); $ionicHistory.removeBackView();
sendFlowService.clear();
$state.go('tabs.send'); $state.go('tabs.send');
$timeout(function() { $timeout(function() {
var to = ''; var to = '';

View file

@ -209,6 +209,7 @@ function amountController(configService, $filter, gettextCatalog, $ionicHistory,
} }
function goBack() { function goBack() {
sendFlowService.previousState();
if (vm.thirdParty && vm.thirdParty.id === 'shapeshift') { if (vm.thirdParty && vm.thirdParty.id === 'shapeshift') {
$state.go('tabs.send').then(function() { $state.go('tabs.send').then(function() {
$ionicHistory.clearHistory(); $ionicHistory.clearHistory();

View file

@ -1,6 +1,6 @@
'use strict'; 'use strict';
angular.module('copayApp.controllers').controller('shapeshiftController', function($scope, $state, $timeout, $ionicHistory, profileService, walletService, popupService, lodash, $ionicNavBarDelegate) { angular.module('copayApp.controllers').controller('shapeshiftController', function($scope, sendFlowService, $state, $timeout, $ionicHistory, profileService, walletService, popupService, lodash, $ionicNavBarDelegate) {
var walletsBtc = []; var walletsBtc = [];
var walletsBch = []; var walletsBch = [];
@ -67,6 +67,7 @@ angular.module('copayApp.controllers').controller('shapeshiftController', functi
thirdParty: JSON.stringify({id: 'shapeshift'}) thirdParty: JSON.stringify({id: 'shapeshift'})
}; };
sendFlowService.clear();
$state.go('tabs.home').then(function() { $state.go('tabs.home').then(function() {
$ionicHistory.clearHistory(); $ionicHistory.clearHistory();
$state.go('tabs.send').then(function() { $state.go('tabs.send').then(function() {

View file

@ -1,7 +1,7 @@
'use strict'; 'use strict';
angular.module('copayApp.controllers').controller('tabHomeController', angular.module('copayApp.controllers').controller('tabHomeController',
function($rootScope, $timeout, $scope, $state, $stateParams, $ionicModal, $ionicScrollDelegate, $window, gettextCatalog, lodash, popupService, ongoingProcess, bannerService, externalLinkService, latestReleaseService, profileService, walletService, configService, $log, platformInfo, sendFlowService, storageService, txpModalService, appConfigService, startupService, addressbookService, bwcError, nextStepsService, buyAndSellService, homeIntegrationsService, bitpayCardService, pushNotificationsService, timeService, bitcoincomService, pricechartService, firebaseEventsService, servicesService, shapeshiftService, $ionicNavBarDelegate, signVerifyMessageService) { function($rootScope, sendFlowService, $timeout, $scope, $state, $stateParams, $ionicModal, $ionicScrollDelegate, $window, gettextCatalog, lodash, popupService, ongoingProcess, bannerService, externalLinkService, latestReleaseService, profileService, walletService, configService, $log, platformInfo, storageService, txpModalService, appConfigService, startupService, addressbookService, bwcError, nextStepsService, buyAndSellService, homeIntegrationsService, bitpayCardService, pushNotificationsService, timeService, bitcoincomService, pricechartService, firebaseEventsService, servicesService, shapeshiftService, $ionicNavBarDelegate, signVerifyMessageService) {
var wallet; var wallet;
var listeners = []; var listeners = [];
var notifications = []; var notifications = [];
@ -31,7 +31,6 @@ angular.module('copayApp.controllers').controller('tabHomeController',
}); });
$scope.$on("$ionicView.beforeEnter", function(event, data) { $scope.$on("$ionicView.beforeEnter", function(event, data) {
sendFlowService.clear();
if (!$scope.homeTip) { if (!$scope.homeTip) {
storageService.getHomeTipAccepted(function(error, value) { storageService.getHomeTipAccepted(function(error, value) {
@ -119,6 +118,11 @@ angular.module('copayApp.controllers').controller('tabHomeController',
return timeService.withinPastDay(time); return timeService.withinPastDay(time);
}; };
$scope.startFreshSend = function() {
sendFlowService.clear();
$state.go('tabs.send');
}
$scope.openExternalLink = function() { $scope.openExternalLink = function() {
var url = 'https://github.com/Bitcoin-com/Wallet/releases/latest'; var url = 'https://github.com/Bitcoin-com/Wallet/releases/latest';
var optIn = true; var optIn = true;

View file

@ -187,6 +187,13 @@ angular.module('copayApp.controllers').controller('tabSendController', function(
}); });
}; };
$scope.startWalletToWalletTransfer = function() {
console.log('startWalletToWalletTransfer()');
$state.transitionTo('tabs.send.wallet-to-wallet', {
fromWalletId: sendFlowService.fromWalletId
});
}
// This could probably be enhanced refactoring the routes abstract states // This could probably be enhanced refactoring the routes abstract states
$scope.createWallet = function() { $scope.createWallet = function() {
$state.go('tabs.home').then(function() { $state.go('tabs.home').then(function() {

View file

@ -1,6 +1,6 @@
'use strict'; 'use strict';
angular.module('copayApp.controllers').controller('tabsController', function($rootScope, $log, $scope, $state, $stateParams, $timeout, platformInfo, incomingData, lodash, popupService, gettextCatalog, scannerService) { angular.module('copayApp.controllers').controller('tabsController', function($rootScope, $log, $scope, $state, $stateParams, $timeout, platformInfo, incomingData, lodash, popupService, gettextCatalog, scannerService, sendFlowService) {
$scope.onScan = function(data) { $scope.onScan = function(data) {
if (!incomingData.redir(data)) { if (!incomingData.redir(data)) {
@ -15,6 +15,11 @@ angular.module('copayApp.controllers').controller('tabsController', function($ro
}; };
}; };
$scope.startFreshSend = function() {
sendFlowService.clear();
$state.go('tabs.send');
};
$scope.importInit = function() { $scope.importInit = function() {
$scope.fromOnboarding = $stateParams.fromOnboarding; $scope.fromOnboarding = $stateParams.fromOnboarding;
$timeout(function() { $timeout(function() {
@ -23,7 +28,7 @@ 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

@ -471,13 +471,20 @@ angular.module('copayApp.controllers').controller('walletDetailsController', fun
function rgbToHex(r, g, b) { function rgbToHex(r, g, b) {
return "#" + componentToHex(r) + componentToHex(g) + componentToHex(b); return "#" + componentToHex(r) + componentToHex(g) + componentToHex(b);
} }
$scope.goToSend = function() { $scope.goToSend = function() {
sendFlowService.fromWalletId = $scope.wallet.id; sendFlowService.startSend({
fromWalletId: $scope.wallet.id
});
// 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() {
$state.go('tabs.home', { $state.go('tabs.home', {
walletId: $scope.wallet.id walletId: $scope.wallet.id
@ -488,6 +495,7 @@ angular.module('copayApp.controllers').controller('walletDetailsController', fun
}); });
}); });
}; };
$scope.goToBuy = function() { $scope.goToBuy = function() {
$state.go('tabs.home', { $state.go('tabs.home', {
walletId: $scope.wallet.id walletId: $scope.wallet.id

View file

@ -1,48 +1,78 @@
'use strict'; 'use strict';
angular.module('copayApp.services').factory('sendFlowService', function ($log) { (function(){
var vm = this;
vm.amount = false; angular
.module('copayApp.services')
.factory('sendFlowService', sendFlowService);
vm.fromWalletId = false; function sendFlowService($log) {
vm.previousStates = [];
vm.thirdParty = false;
vm.sendMax = false;
vm.toAddress = false;
vm.toWalletId = false;
vm.clear = function() { var service = {
$log.debug("Reinitialize Send Flow variables"); amount: '',
vm.amount = false; fromWalletId: '',
vm.fromWalletId = false; sendMax: false,
vm.thirdParty = false; thirdParty: null,
vm.sendMax = false; toAddress: '',
vm.toAddress = false; toWalletId: '',
vm.toWalletId = false; previousStates: [],
vm.previousStates = [];
};
vm.map = function(params) { // Functions
clear: clear,
map: map,
previousState: previousState,
startSend: startSend
};
var tempState = {}; return service;
Object.keys(vm).map(function(key, index) {
if (typeof vm[key] !== 'function' && key !== 'previousStates') {
tempState[key] = vm[key];
}
});
vm.previousStates.push(tempState);
Object.keys(params).map(function(key, index) { function clear() {
vm[key] = params[key]; $log.debug("Reinitialize Send Flow variables with clear()");
}); service.amount = '';
}; service.fromWalletId = '';
service.sendMax = false;
vm.previousState = function() { service.thirdParty = null;
if (vm.previousStates.length) { service.toAddress = '';
vm.map(vm.previousStates.pop()); service.toWalletId = '';
service.previousStates = [];
} }
/**
* Clears all previous state
* @param {} params
*/
function startSend(params) {
console.log('startSend()');
clear();
Object.keys(params).forEach(function forNewParam(key) {
service[key] = params[key];
});
}
function map(params) {
var currentState = {};
Object.keys(service).forEach(function forCurrentParam(key) {
if (typeof service[key] !== 'function' && key !== 'previousStates') {
currentState[key] = service[key];
}
});
service.previousStates.push(currentState);
// Do we want to inherit the previous state here, or clear first before adding new params?
Object.keys(params).forEach(function forNewParam(key) {
service[key] = params[key];
});
};
function previousState() {
if (service.previousStates.length) {
map(service.previousStates.pop());
} else {
clear();
}
};
}; };
return vm; })();
});

View file

@ -34,7 +34,7 @@
<span translate>Buy Bitcoin</span> <span translate>Buy Bitcoin</span>
</div> </div>
<div class="button button-outline button-grey-outline" ng-class="{'ng-hide': !walletsWithFunds.length}" <div class="button button-outline button-grey-outline" ng-class="{'ng-hide': !walletsWithFunds.length}"
ui-sref="tabs.send"> ng-click="startFreshSend()">
<span translate>Send</span> <span translate>Send</span>
</div> </div>
</div> </div>

View file

@ -4,6 +4,25 @@
</ion-nav-bar> </ion-nav-bar>
<ion-content> <ion-content>
<div id="tab-send-header" ng-if="hasFunds"> <div id="tab-send-header" ng-if="hasFunds">
<div class="content-frame" ng-if="fromWallet">
<div class="card card-gutter-compact">
<div class="item item-compact" translate>From:</div>
<div class="item item-gutterless item-complex item-avatar">
<div class="item-content item-content-avatar">
<i class="icon big-icon-svg theme-circle theme-circle-services">
<div class="bg icon-wallet"
style="background-color: {{fromWallet.color}}"
></div>
</i>
<h2>{{fromWallet.name}}</h2>
<!--<p ng-show="vm.origin.balanceAmount">{{vm.origin.balanceAmount}} {{vm.origin.balanceCurrency}}</p>-->
<formatted-amount value="{{fromWallet.status.totalBalanceStr ? fromWallet.status.totalBalanceStr : ( fromWallet.cachedBalance ? fromWallet.cachedBalance + (fromWallet.cachedBalanceUpdatedOn ? ' &middot; ' + ( fromWallet.cachedBalanceUpdatedOn * 1000 | amTimeAgo) : '') : '' ) }}"></formatted-amount>
</div>
</div>
</div>
</div>
<div class="send-wrapper item"> <div class="send-wrapper item">
<div class="row"> <div class="row">
<div class="input" ng-class="{'focus': searchFocus}"> <div class="input" ng-class="{'focus': searchFocus}">
@ -22,7 +41,7 @@
</button> </button>
</div> </div>
<div class="col-60"> <div class="col-60">
<button class="button button-standard button-primary button-outline" ui-sref="tabs.send.wallet-to-wallet"> <button class="button button-standard button-primary button-outline" ng-click="startWalletToWalletTransfer()">
<img src="img/icon-w2w.svg"/><br/> <img src="img/icon-w2w.svg"/><br/>
<span translate>Wallet to Wallet Transfer</span> <span translate>Wallet to Wallet Transfer</span>
</button> </button>

View file

@ -11,7 +11,7 @@
<ion-nav-view name="tab-scan"></ion-nav-view> <ion-nav-view name="tab-scan"></ion-nav-view>
</ion-tab> </ion-tab>
<ion-tab class="track_tab_open" id="tab_open_send" title="{{'Send'|translate}}" icon-off="ico-send" icon-on="ico-send-selected" ui-sref="tabs.send"> <ion-tab class="track_tab_open" id="tab_open_send" title="{{'Send'|translate}}" icon-off="ico-send" icon-on="ico-send-selected" ng-click="startFreshSend()">
<ion-nav-view name="tab-send"></ion-nav-view> <ion-nav-view name="tab-send"></ion-nav-view>
</ion-tab> </ion-tab>