refactor
This commit is contained in:
parent
88b2ed63ff
commit
7e26f5b6e9
3 changed files with 36 additions and 24 deletions
|
|
@ -2,7 +2,6 @@
|
||||||
|
|
||||||
angular.module('copayApp.controllers').controller('confirmController', function($rootScope, $scope, $interval, $filter, $timeout, $ionicScrollDelegate, gettextCatalog, walletService, platformInfo, lodash, configService, rateService, $stateParams, $window, $state, $log, profileService, bitcore, gettext, txFormatService, ongoingProcess, $ionicModal, popupService, $ionicHistory, $ionicConfig, payproService, feeService, amazonService) {
|
angular.module('copayApp.controllers').controller('confirmController', function($rootScope, $scope, $interval, $filter, $timeout, $ionicScrollDelegate, gettextCatalog, walletService, platformInfo, lodash, configService, rateService, $stateParams, $window, $state, $log, profileService, bitcore, gettext, txFormatService, ongoingProcess, $ionicModal, popupService, $ionicHistory, $ionicConfig, payproService, feeService, amazonService) {
|
||||||
var cachedTxp = {};
|
var cachedTxp = {};
|
||||||
var amountStr;
|
|
||||||
var toAmount;
|
var toAmount;
|
||||||
var isChromeApp = platformInfo.isChromeApp;
|
var isChromeApp = platformInfo.isChromeApp;
|
||||||
var countDown = null;
|
var countDown = null;
|
||||||
|
|
@ -44,6 +43,7 @@ angular.module('copayApp.controllers').controller('confirmController', function(
|
||||||
var config = configService.getSync().wallet;
|
var config = configService.getSync().wallet;
|
||||||
$scope.feeLevel = config.settings && config.settings.feeLevel ? config.settings.feeLevel : 'normal';
|
$scope.feeLevel = config.settings && config.settings.feeLevel ? config.settings.feeLevel : 'normal';
|
||||||
$scope.network = (new bitcore.Address($scope.toAddress)).network.name;
|
$scope.network = (new bitcore.Address($scope.toAddress)).network.name;
|
||||||
|
resetValues();
|
||||||
setwallets();
|
setwallets();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -54,8 +54,16 @@ angular.module('copayApp.controllers').controller('confirmController', function(
|
||||||
n: $scope.isGiftCard ? true : false
|
n: $scope.isGiftCard ? true : false
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!$scope.wallets || !$scope.wallets.length)
|
if (!$scope.wallets || !$scope.wallets.length) {
|
||||||
$scope.noMatchingWallet = true;
|
$scope.noMatchingWallet = true;
|
||||||
|
if ($scope.paypro) {
|
||||||
|
displayValues();
|
||||||
|
}
|
||||||
|
$timeout(function() {
|
||||||
|
$scope.$apply();
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
var filteredWallets = [];
|
var filteredWallets = [];
|
||||||
var index = 0;
|
var index = 0;
|
||||||
|
|
@ -92,23 +100,26 @@ angular.module('copayApp.controllers').controller('confirmController', function(
|
||||||
};
|
};
|
||||||
|
|
||||||
var initConfirm = function() {
|
var initConfirm = function() {
|
||||||
toAmount = parseInt(toAmount);
|
|
||||||
amountStr = txFormatService.formatAmountStr(toAmount);
|
|
||||||
$scope.displayAmount = getDisplayAmount(amountStr);
|
|
||||||
$scope.displayUnit = getDisplayUnit(amountStr);
|
|
||||||
|
|
||||||
txFormatService.formatAlternativeStr(toAmount, function(v) {
|
|
||||||
$scope.alternativeAmountStr = v;
|
|
||||||
});
|
|
||||||
|
|
||||||
if ($scope.paypro) _paymentTimeControl($scope.paypro.expires);
|
if ($scope.paypro) _paymentTimeControl($scope.paypro.expires);
|
||||||
|
|
||||||
|
displayValues();
|
||||||
$scope.showWalletSelector();
|
$scope.showWalletSelector();
|
||||||
|
|
||||||
$timeout(function() {
|
$timeout(function() {
|
||||||
$scope.$apply();
|
$scope.$apply();
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
function displayValues() {
|
||||||
|
toAmount = parseInt(toAmount);
|
||||||
|
$scope.amountStr = txFormatService.formatAmountStr(toAmount);
|
||||||
|
$scope.displayAmount = getDisplayAmount($scope.amountStr);
|
||||||
|
$scope.displayUnit = getDisplayUnit($scope.amountStr);
|
||||||
|
txFormatService.formatAlternativeStr(toAmount, function(v) {
|
||||||
|
$scope.alternativeAmountStr = v;
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
function resetValues() {
|
function resetValues() {
|
||||||
$scope.displayAmount = $scope.displayUnit = $scope.fee = $scope.alternativeAmountStr = $scope.insufficientFunds = $scope.noMatchingWallet = null;
|
$scope.displayAmount = $scope.displayUnit = $scope.fee = $scope.alternativeAmountStr = $scope.insufficientFunds = $scope.noMatchingWallet = null;
|
||||||
};
|
};
|
||||||
|
|
@ -133,7 +144,6 @@ angular.module('copayApp.controllers').controller('confirmController', function(
|
||||||
}, function(err, resp) {
|
}, function(err, resp) {
|
||||||
ongoingProcess.set('retrievingInputs', false);
|
ongoingProcess.set('retrievingInputs', false);
|
||||||
if (err) {
|
if (err) {
|
||||||
$scope.insufficientFunds = true;
|
|
||||||
popupService.showAlert(gettextCatalog.getString('Error'), err);
|
popupService.showAlert(gettextCatalog.getString('Error'), err);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
@ -154,13 +164,13 @@ angular.module('copayApp.controllers').controller('confirmController', function(
|
||||||
|
|
||||||
cachedSendMax[$scope.wallet.id] = $scope.sendMaxInfo;
|
cachedSendMax[$scope.wallet.id] = $scope.sendMaxInfo;
|
||||||
|
|
||||||
var msg = gettextCatalog.getString("{{fee}} will be deducted for bitcoin networking fees", {
|
var msg = gettextCatalog.getString("{{fee}} will be deducted for bitcoin networking fees.", {
|
||||||
fee: txFormatService.formatAmountStr(resp.fee)
|
fee: txFormatService.formatAmountStr(resp.fee)
|
||||||
});
|
});
|
||||||
var warningMsg = verifyExcludedUtxos();
|
var warningMsg = verifyExcludedUtxos();
|
||||||
|
|
||||||
if (!lodash.isEmpty(warningMsg))
|
if (!lodash.isEmpty(warningMsg))
|
||||||
msg += '. \n' + warningMsg;
|
msg += '\n' + warningMsg;
|
||||||
|
|
||||||
popupService.showAlert(null, msg, function() {
|
popupService.showAlert(null, msg, function() {
|
||||||
setSendMaxValues(resp);
|
setSendMaxValues(resp);
|
||||||
|
|
@ -181,7 +191,7 @@ angular.module('copayApp.controllers').controller('confirmController', function(
|
||||||
}
|
}
|
||||||
|
|
||||||
if (resp.utxosAboveMaxSize > 0) {
|
if (resp.utxosAboveMaxSize > 0) {
|
||||||
warningMsg.push(gettextCatalog.getString("A total of {{amountAboveMaxSizeStr}} were excluded. The maximum size allowed for a transaction was exceeded", {
|
warningMsg.push(gettextCatalog.getString("A total of {{amountAboveMaxSizeStr}} were excluded. The maximum size allowed for a transaction was exceeded.", {
|
||||||
amountAboveMaxSizeStr: txFormatService.formatAmountStr(resp.amountAboveMaxSize)
|
amountAboveMaxSizeStr: txFormatService.formatAmountStr(resp.amountAboveMaxSize)
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
@ -248,11 +258,11 @@ angular.module('copayApp.controllers').controller('confirmController', function(
|
||||||
};
|
};
|
||||||
|
|
||||||
function getDisplayAmount(amountStr) {
|
function getDisplayAmount(amountStr) {
|
||||||
return amountStr.split(' ')[0];
|
return $scope.amountStr.split(' ')[0];
|
||||||
};
|
};
|
||||||
|
|
||||||
function getDisplayUnit(amountStr) {
|
function getDisplayUnit(amountStr) {
|
||||||
return amountStr.split(' ')[1];
|
return $scope.amountStr.split(' ')[1];
|
||||||
};
|
};
|
||||||
|
|
||||||
function _paymentTimeControl(expirationTime) {
|
function _paymentTimeControl(expirationTime) {
|
||||||
|
|
@ -355,7 +365,8 @@ angular.module('copayApp.controllers').controller('confirmController', function(
|
||||||
|
|
||||||
var txp = {};
|
var txp = {};
|
||||||
var amount;
|
var amount;
|
||||||
if ($scope.useSendMax) amount = parseFloat((toAmount * unitToSatoshi));
|
|
||||||
|
if ($scope.useSendMax) amount = parseFloat((toAmount * unitToSatoshi).toFixed(0));
|
||||||
else amount = toAmount;
|
else amount = toAmount;
|
||||||
|
|
||||||
txp.outputs = [{
|
txp.outputs = [{
|
||||||
|
|
@ -397,8 +408,6 @@ angular.module('copayApp.controllers').controller('confirmController', function(
|
||||||
};
|
};
|
||||||
|
|
||||||
$scope.approve = function(onSendStatusChange) {
|
$scope.approve = function(onSendStatusChange) {
|
||||||
if (!toAmount || $scope.insufficientFunds || $scope.noMatchingWallet) return;
|
|
||||||
|
|
||||||
if ($scope.paypro && $scope.paymentExpired.value) {
|
if ($scope.paypro && $scope.paymentExpired.value) {
|
||||||
popupService.showAlert(null, gettextCatalog.getString('This bitcoin payment request has expired.'));
|
popupService.showAlert(null, gettextCatalog.getString('This bitcoin payment request has expired.'));
|
||||||
$scope.sendStatus = '';
|
$scope.sendStatus = '';
|
||||||
|
|
@ -432,7 +441,7 @@ angular.module('copayApp.controllers').controller('confirmController', function(
|
||||||
var isCordova = $scope.isCordova;
|
var isCordova = $scope.isCordova;
|
||||||
var bigAmount = parseFloat(txFormatService.formatToUSD(txp.amount)) > 20;
|
var bigAmount = parseFloat(txFormatService.formatToUSD(txp.amount)) > 20;
|
||||||
var message = gettextCatalog.getString('Sending {{amountStr}} from your {{name}} wallet', {
|
var message = gettextCatalog.getString('Sending {{amountStr}} from your {{name}} wallet', {
|
||||||
amountStr: amountStr,
|
amountStr: $scope.amountStr,
|
||||||
name: wallet.name
|
name: wallet.name
|
||||||
});
|
});
|
||||||
var okText = gettextCatalog.getString('Confirm');
|
var okText = gettextCatalog.getString('Confirm');
|
||||||
|
|
|
||||||
|
|
@ -26,10 +26,13 @@ angular.module('copayApp.services').factory('feeService', function($log, $stateP
|
||||||
level: feeLevel
|
level: feeLevel
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!feeLevelValue || !feeLevelValue.feePerKB)
|
if (!feeLevelValue || !feeLevelValue.feePerKB) {
|
||||||
return cb({
|
return cb({
|
||||||
message: gettextCatalog.getString('Could not get dynamic fee for level: ') + feeLevel
|
message: gettextCatalog.getString("Could not get dynamic fee for level: {{feeLevel}}", {
|
||||||
|
feeLevel: feeLevel
|
||||||
|
})
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
var fee = feeLevelValue.feePerKB;
|
var fee = feeLevelValue.feePerKB;
|
||||||
$log.debug('Dynamic fee: ' + feeLevel + ' ' + fee + ' SAT');
|
$log.debug('Dynamic fee: ' + feeLevel + ' ' + fee + ' SAT');
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,7 @@
|
||||||
<div class="sending-label">
|
<div class="sending-label">
|
||||||
<img src="img/icon-tx-sent-outline.svg">
|
<img src="img/icon-tx-sent-outline.svg">
|
||||||
<span translate ng-if="!useSendMax">Sending</span>
|
<span translate ng-if="!useSendMax">Sending</span>
|
||||||
<span translate ng-if="useSendMax">Sending maximum amount <i class="icon ion-ios-navigate-outline"></i></span>
|
<span translate ng-if="useSendMax">Sending maximum amount</span>
|
||||||
</div>
|
</div>
|
||||||
<div class="amount-label">
|
<div class="amount-label">
|
||||||
<div class="amount">{{displayAmount || '...'}} <span class="unit">{{displayUnit}}</span></div>
|
<div class="amount">{{displayAmount || '...'}} <span class="unit">{{displayUnit}}</span></div>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue