2018-07-23 16:58:32 +02:00
|
|
|
'use strict';
|
|
|
|
|
|
2018-07-25 16:05:07 +02:00
|
|
|
angular.module('copayApp.controllers').controller('sendFlowController', function($scope, $rootScope, $state, $stateParams, $log, $ionicHistory, configService, gettextCatalog, profileService) {
|
2018-07-23 16:58:32 +02:00
|
|
|
|
|
|
|
|
$scope.$on("$ionicView.beforeEnter", function(event, data) {
|
|
|
|
|
var config = configService.getSync().wallet.settings;
|
2018-07-24 14:24:22 +02:00
|
|
|
$scope.params = $stateParams;
|
2018-07-25 11:26:33 +02:00
|
|
|
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;
|
2018-07-24 14:24:22 +02:00
|
|
|
$scope.requestAmount = (($stateParams.amount) * satToUnit).toFixed(unitDecimals);
|
2018-07-23 16:58:32 +02:00
|
|
|
$scope.isPaymentRequest = true;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
$scope.$on("$ionicView.enter", function(event, data) {
|
2018-07-25 11:26:33 +02:00
|
|
|
configService.whenAvailable(function(config) {
|
|
|
|
|
$scope.selectedPriceDisplay = config.wallet.settings.priceDisplay;
|
|
|
|
|
});
|
|
|
|
|
|
2018-07-24 14:24:22 +02:00
|
|
|
$scope.type = data.stateParams && data.stateParams['fromWalletId'] ? 'destination' : 'origin'; // origin || destination
|
2018-07-23 16:58:32 +02:00
|
|
|
$scope.coin = false; // Wallets to show (for destination screen)
|
2018-07-25 11:26:33 +02:00
|
|
|
$scope.walletsEmpty = []; // empty wallets for origin screen
|
2018-07-24 14:24:22 +02:00
|
|
|
|
2018-07-23 16:58:32 +02:00
|
|
|
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);
|
2018-07-25 11:26:33 +02:00
|
|
|
$scope.coin = $scope.fromWallet.coin; // Only show wallets with the select origin wallet coin
|
2018-07-23 16:58:32 +02:00
|
|
|
$scope.headerTitle = gettextCatalog.getString('Choose a wallet to send to');
|
|
|
|
|
}
|
|
|
|
|
|
2018-07-25 11:26:33 +02:00
|
|
|
if (!$scope.coin || $scope.coin === 'bch') { // if no specific coin is set or coin is set to bch
|
2018-07-23 16:58:32 +02:00
|
|
|
$scope.walletsBch = profileService.getWallets({coin: 'bch', hasFunds: $scope.type==='origin'});
|
|
|
|
|
}
|
2018-07-25 11:26:33 +02:00
|
|
|
if (!$scope.coin || $scope.coin === 'btc') { // if no specific coin is set or coin is set btc
|
2018-07-23 16:58:32 +02:00
|
|
|
$scope.walletsBtc = profileService.getWallets({coin: 'btc', hasFunds: $scope.type === 'origin'});
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
2018-07-24 14:24:22 +02:00
|
|
|
function getNextStep() {
|
2018-07-25 11:26:33 +02:00
|
|
|
if (!$scope.params.toWalletId && !$scope.params.toAddress) { // If we have no toAddress or fromWallet
|
2018-07-24 14:24:22 +02:00
|
|
|
return 'tabs.send.destination';
|
2018-07-25 11:26:33 +02:00
|
|
|
} else if (!$scope.params.amount) { // If we have no amount
|
2018-07-24 14:24:22 +02:00
|
|
|
return 'tabs.send.amount';
|
2018-07-25 11:26:33 +02:00
|
|
|
} else { // If we do have them
|
2018-07-24 14:24:22 +02:00
|
|
|
return 'tabs.send.confirm';
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-07-23 16:58:32 +02:00
|
|
|
$scope.useWallet = function(wallet) {
|
2018-07-25 11:26:33 +02:00
|
|
|
if ($scope.type === 'origin') { // we're on the origin screen, set wallet to send from
|
2018-07-23 16:58:32 +02:00
|
|
|
$scope.params['fromWalletId'] = wallet.id;
|
2018-07-25 11:26:33 +02:00
|
|
|
} else { // we're on the destination screen, set wallet to send to
|
2018-07-23 16:58:32 +02:00
|
|
|
$scope.params['toWalletId'] = wallet.id;
|
|
|
|
|
}
|
2018-07-24 14:24:22 +02:00
|
|
|
$state.transitionTo(getNextStep(), $scope.params);
|
2018-07-23 16:58:32 +02:00
|
|
|
};
|
2018-07-25 16:05:07 +02:00
|
|
|
|
|
|
|
|
$scope.goBack = function() {
|
|
|
|
|
$ionicHistory.goBack();
|
|
|
|
|
}
|
|
|
|
|
|
2018-07-23 16:58:32 +02:00
|
|
|
});
|