refactored the sendFlowController
This commit is contained in:
parent
fd4adbfb57
commit
4093e2ba71
1 changed files with 19 additions and 34 deletions
|
|
@ -2,75 +2,60 @@
|
|||
|
||||
angular.module('copayApp.controllers').controller('sendFlowController', function($scope, $rootScope, $state, $stateParams, $log, configService, gettextCatalog, profileService) {
|
||||
|
||||
var unitToSatoshi;
|
||||
var satToUnit;
|
||||
var unitDecimals;
|
||||
var satToBtc;
|
||||
var nextStep = '';
|
||||
|
||||
$scope.$on("$ionicView.beforeEnter", function(event, data) {
|
||||
var config = configService.getSync().wallet.settings;
|
||||
$scope.params = $stateParams;
|
||||
$scope.specificAmount = $scope.specificAlternativeAmount = '';
|
||||
unitToSatoshi = config.unitToSatoshi;
|
||||
satToUnit = 1 / unitToSatoshi;
|
||||
satToBtc = 1 / 100000000;
|
||||
unitDecimals = config.unitDecimals;
|
||||
|
||||
if ($scope.params.amount) {
|
||||
console.log("is Payment Request", $scope.params.amount);
|
||||
|
||||
if ($scope.params.amount) { // There is an amount, so presume that it a payment request
|
||||
$scope.specificAmount = $scope.specificAlternativeAmount = '';
|
||||
var unitToSatoshi = config.unitToSatoshi;
|
||||
var satToUnit = 1 / unitToSatoshi;
|
||||
var satToBtc = 1 / 100000000;
|
||||
var unitDecimals = config.unitDecimals;
|
||||
$scope.requestAmount = (($stateParams.amount) * satToUnit).toFixed(unitDecimals);
|
||||
$scope.isPaymentRequest = true;
|
||||
}
|
||||
});
|
||||
|
||||
$scope.$on("$ionicView.enter", function(event, data) {
|
||||
console.log(data, $stateParams);
|
||||
configService.whenAvailable(function(config) {
|
||||
$scope.selectedPriceDisplay = config.wallet.settings.priceDisplay;
|
||||
});
|
||||
|
||||
$scope.type = data.stateParams && data.stateParams['fromWalletId'] ? 'destination' : 'origin'; // origin || destination
|
||||
$scope.coin = false; // Wallets to show (for destination screen)
|
||||
$scope.walletsEmpty = [];
|
||||
// Show price-header
|
||||
|
||||
console.log("current type: "+$scope.type);
|
||||
$scope.walletsEmpty = []; // empty wallets for origin screen
|
||||
|
||||
if ($scope.type === 'origin') {
|
||||
$scope.headerTitle = gettextCatalog.getString('Choose a wallet to send from');
|
||||
$scope.walletsEmpty = profileService.getWallets({coin: $scope.coin, hasNoFunds: true});
|
||||
} else if ($scope.type === 'destination') {
|
||||
|
||||
$scope.fromWallet = profileService.getWallet(data.stateParams.fromWalletId);
|
||||
$scope.coin = $scope.fromWallet.coin;
|
||||
|
||||
$scope.coin = $scope.fromWallet.coin; // Only show wallets with the select origin wallet coin
|
||||
$scope.headerTitle = gettextCatalog.getString('Choose a wallet to send to');
|
||||
}
|
||||
|
||||
if (!$scope.coin || $scope.coin === 'bch') {
|
||||
if (!$scope.coin || $scope.coin === 'bch') { // if no specific coin is set or coin is set to bch
|
||||
$scope.walletsBch = profileService.getWallets({coin: 'bch', hasFunds: $scope.type==='origin'});
|
||||
}
|
||||
if (!$scope.coin || $scope.coin === 'btc') {
|
||||
if (!$scope.coin || $scope.coin === 'btc') { // if no specific coin is set or coin is set btc
|
||||
$scope.walletsBtc = profileService.getWallets({coin: 'btc', hasFunds: $scope.type === 'origin'});
|
||||
}
|
||||
|
||||
configService.whenAvailable(function(config) {
|
||||
$scope.selectedPriceDisplay = config.wallet.settings.priceDisplay;
|
||||
});
|
||||
});
|
||||
|
||||
function getNextStep() {
|
||||
if (!$scope.params.toWalletId && !$scope.params.toAddress) {
|
||||
if (!$scope.params.toWalletId && !$scope.params.toAddress) { // If we have no toAddress or fromWallet
|
||||
return 'tabs.send.destination';
|
||||
} else if (!$scope.params.amount) {
|
||||
} else if (!$scope.params.amount) { // If we have no amount
|
||||
return 'tabs.send.amount';
|
||||
} else {
|
||||
} else { // If we do have them
|
||||
return 'tabs.send.confirm';
|
||||
}
|
||||
}
|
||||
|
||||
$scope.useWallet = function(wallet) {
|
||||
if ($scope.type === 'origin') {
|
||||
if ($scope.type === 'origin') { // we're on the origin screen, set wallet to send from
|
||||
$scope.params['fromWalletId'] = wallet.id;
|
||||
} else {
|
||||
} else { // we're on the destination screen, set wallet to send to
|
||||
$scope.params['toWalletId'] = wallet.id;
|
||||
}
|
||||
$state.transitionTo(getNextStep(), $scope.params);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue