Refactored sendFlowService and cleared its state before entering the send tab.
This commit is contained in:
parent
e7ce86fb99
commit
dff0d51ef3
11 changed files with 125 additions and 49 deletions
|
|
@ -1,6 +1,6 @@
|
|||
'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 defaults = configService.getDefaults();
|
||||
|
|
@ -22,6 +22,7 @@ angular.module('copayApp.controllers').controller('addressbookViewController', f
|
|||
|
||||
$scope.sendTo = function() {
|
||||
$ionicHistory.removeBackView();
|
||||
sendFlowService.clear();
|
||||
$state.go('tabs.send');
|
||||
$timeout(function() {
|
||||
var to = '';
|
||||
|
|
|
|||
|
|
@ -209,6 +209,7 @@ function amountController(configService, $filter, gettextCatalog, $ionicHistory,
|
|||
}
|
||||
|
||||
function goBack() {
|
||||
sendFlowService.previousState();
|
||||
if (vm.thirdParty && vm.thirdParty.id === 'shapeshift') {
|
||||
$state.go('tabs.send').then(function() {
|
||||
$ionicHistory.clearHistory();
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
'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 walletsBch = [];
|
||||
|
||||
|
|
@ -67,6 +67,7 @@ angular.module('copayApp.controllers').controller('shapeshiftController', functi
|
|||
thirdParty: JSON.stringify({id: 'shapeshift'})
|
||||
};
|
||||
|
||||
sendFlowService.clear();
|
||||
$state.go('tabs.home').then(function() {
|
||||
$ionicHistory.clearHistory();
|
||||
$state.go('tabs.send').then(function() {
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
'use strict';
|
||||
|
||||
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 listeners = [];
|
||||
var notifications = [];
|
||||
|
|
@ -31,7 +31,6 @@ angular.module('copayApp.controllers').controller('tabHomeController',
|
|||
});
|
||||
|
||||
$scope.$on("$ionicView.beforeEnter", function(event, data) {
|
||||
sendFlowService.clear();
|
||||
|
||||
if (!$scope.homeTip) {
|
||||
storageService.getHomeTipAccepted(function(error, value) {
|
||||
|
|
@ -119,6 +118,11 @@ angular.module('copayApp.controllers').controller('tabHomeController',
|
|||
return timeService.withinPastDay(time);
|
||||
};
|
||||
|
||||
$scope.startFreshSend = function() {
|
||||
sendFlowService.clear();
|
||||
$state.go('tabs.send');
|
||||
}
|
||||
|
||||
$scope.openExternalLink = function() {
|
||||
var url = 'https://github.com/Bitcoin-com/Wallet/releases/latest';
|
||||
var optIn = true;
|
||||
|
|
|
|||
|
|
@ -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
|
||||
$scope.createWallet = function() {
|
||||
$state.go('tabs.home').then(function() {
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
'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) {
|
||||
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.fromOnboarding = $stateParams.fromOnboarding;
|
||||
$timeout(function() {
|
||||
|
|
@ -23,7 +28,7 @@ angular.module('copayApp.controllers').controller('tabsController', function($ro
|
|||
};
|
||||
|
||||
$scope.chooseScanner = function() {
|
||||
|
||||
sendFlowService.clear();
|
||||
var isWindowsPhoneApp = platformInfo.isCordova && platformInfo.isWP;
|
||||
|
||||
if (!isWindowsPhoneApp) {
|
||||
|
|
|
|||
|
|
@ -471,13 +471,20 @@ angular.module('copayApp.controllers').controller('walletDetailsController', fun
|
|||
function rgbToHex(r, g, b) {
|
||||
return "#" + componentToHex(r) + componentToHex(g) + componentToHex(b);
|
||||
}
|
||||
|
||||
$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 () {
|
||||
$ionicHistory.clearHistory();
|
||||
$state.go('tabs.send');
|
||||
});
|
||||
|
||||
};
|
||||
|
||||
$scope.goToReceive = function() {
|
||||
$state.go('tabs.home', {
|
||||
walletId: $scope.wallet.id
|
||||
|
|
@ -488,6 +495,7 @@ angular.module('copayApp.controllers').controller('walletDetailsController', fun
|
|||
});
|
||||
});
|
||||
};
|
||||
|
||||
$scope.goToBuy = function() {
|
||||
$state.go('tabs.home', {
|
||||
walletId: $scope.wallet.id
|
||||
|
|
|
|||
|
|
@ -1,48 +1,78 @@
|
|||
'use strict';
|
||||
|
||||
angular.module('copayApp.services').factory('sendFlowService', function ($log) {
|
||||
var vm = this;
|
||||
(function(){
|
||||
|
||||
vm.amount = false;
|
||||
angular
|
||||
.module('copayApp.services')
|
||||
.factory('sendFlowService', sendFlowService);
|
||||
|
||||
function sendFlowService($log) {
|
||||
|
||||
vm.fromWalletId = false;
|
||||
vm.previousStates = [];
|
||||
vm.thirdParty = false;
|
||||
vm.sendMax = false;
|
||||
vm.toAddress = false;
|
||||
vm.toWalletId = false;
|
||||
var service = {
|
||||
amount: '',
|
||||
fromWalletId: '',
|
||||
sendMax: false,
|
||||
thirdParty: null,
|
||||
toAddress: '',
|
||||
toWalletId: '',
|
||||
previousStates: [],
|
||||
|
||||
vm.clear = function() {
|
||||
$log.debug("Reinitialize Send Flow variables");
|
||||
vm.amount = false;
|
||||
vm.fromWalletId = false;
|
||||
vm.thirdParty = false;
|
||||
vm.sendMax = false;
|
||||
vm.toAddress = false;
|
||||
vm.toWalletId = false;
|
||||
vm.previousStates = [];
|
||||
};
|
||||
// Functions
|
||||
clear: clear,
|
||||
map: map,
|
||||
previousState: previousState,
|
||||
startSend: startSend
|
||||
};
|
||||
|
||||
vm.map = function(params) {
|
||||
return service;
|
||||
|
||||
var tempState = {};
|
||||
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) {
|
||||
vm[key] = params[key];
|
||||
});
|
||||
};
|
||||
|
||||
vm.previousState = function() {
|
||||
if (vm.previousStates.length) {
|
||||
vm.map(vm.previousStates.pop());
|
||||
function clear() {
|
||||
$log.debug("Reinitialize Send Flow variables with clear()");
|
||||
service.amount = '';
|
||||
service.fromWalletId = '';
|
||||
service.sendMax = false;
|
||||
service.thirdParty = null;
|
||||
service.toAddress = '';
|
||||
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;
|
||||
});
|
||||
})();
|
||||
|
|
@ -34,7 +34,7 @@
|
|||
<span translate>Buy Bitcoin</span>
|
||||
</div>
|
||||
<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>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -4,6 +4,25 @@
|
|||
</ion-nav-bar>
|
||||
<ion-content>
|
||||
<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 ? ' · ' + ( fromWallet.cachedBalanceUpdatedOn * 1000 | amTimeAgo) : '') : '' ) }}"></formatted-amount>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="send-wrapper item">
|
||||
<div class="row">
|
||||
<div class="input" ng-class="{'focus': searchFocus}">
|
||||
|
|
@ -22,7 +41,7 @@
|
|||
</button>
|
||||
</div>
|
||||
<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/>
|
||||
<span translate>Wallet to Wallet Transfer</span>
|
||||
</button>
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@
|
|||
<ion-nav-view name="tab-scan"></ion-nav-view>
|
||||
</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-tab>
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue