Merge pull request #5832 from JDonadio/feat/paste-amount-desktop
Paste amount - Desktop
This commit is contained in:
commit
aba86e3db5
1 changed files with 29 additions and 18 deletions
|
|
@ -1,6 +1,6 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
angular.module('copayApp.controllers').controller('amountController', function($scope, $filter, $timeout, $ionicScrollDelegate, $ionicHistory, gettextCatalog, platformInfo, lodash, configService, rateService, $stateParams, $window, $state, $log, txFormatService, ongoingProcess, popupService, bwcError, payproService, profileService, bitcore, amazonService) {
|
angular.module('copayApp.controllers').controller('amountController', function($scope, $filter, $timeout, $ionicScrollDelegate, $ionicHistory, gettextCatalog, platformInfo, lodash, configService, rateService, $stateParams, $window, $state, $log, txFormatService, ongoingProcess, popupService, bwcError, payproService, profileService, bitcore, amazonService, nodeWebkitService) {
|
||||||
var _cardId;
|
var _cardId;
|
||||||
var unitToSatoshi;
|
var unitToSatoshi;
|
||||||
var satToUnit;
|
var satToUnit;
|
||||||
|
|
@ -8,6 +8,7 @@ angular.module('copayApp.controllers').controller('amountController', function($
|
||||||
var satToBtc;
|
var satToBtc;
|
||||||
var SMALL_FONT_SIZE_LIMIT = 10;
|
var SMALL_FONT_SIZE_LIMIT = 10;
|
||||||
var LENGTH_EXPRESSION_LIMIT = 19;
|
var LENGTH_EXPRESSION_LIMIT = 19;
|
||||||
|
var isNW = platformInfo.isNW;
|
||||||
$scope.isChromeApp = platformInfo.isChromeApp;
|
$scope.isChromeApp = platformInfo.isChromeApp;
|
||||||
|
|
||||||
$scope.$on('$ionicView.leave', function() {
|
$scope.$on('$ionicView.leave', function() {
|
||||||
|
|
@ -15,7 +16,6 @@ angular.module('copayApp.controllers').controller('amountController', function($
|
||||||
});
|
});
|
||||||
|
|
||||||
$scope.$on("$ionicView.beforeEnter", function(event, data) {
|
$scope.$on("$ionicView.beforeEnter", function(event, data) {
|
||||||
|
|
||||||
// Go to...
|
// Go to...
|
||||||
_cardId = data.stateParams.id; // Optional (BitPay Card ID)
|
_cardId = data.stateParams.id; // Optional (BitPay Card ID)
|
||||||
$scope.nextStep = data.stateParams.nextStep;
|
$scope.nextStep = data.stateParams.nextStep;
|
||||||
|
|
@ -42,18 +42,20 @@ angular.module('copayApp.controllers').controller('amountController', function($
|
||||||
var reOp = /^[\*\+\-\/]$/;
|
var reOp = /^[\*\+\-\/]$/;
|
||||||
|
|
||||||
var disableKeys = angular.element($window).on('keydown', function(e) {
|
var disableKeys = angular.element($window).on('keydown', function(e) {
|
||||||
|
if (!e.key) return;
|
||||||
if (e.which === 8) { // you can add others here inside brackets.
|
if (e.which === 8) { // you can add others here inside brackets.
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
$scope.removeDigit();
|
$scope.removeDigit();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (e.key && e.key.match(reNr))
|
if (e.key.match(reNr)) {
|
||||||
$scope.pushDigit(e.key);
|
$scope.pushDigit(e.key);
|
||||||
|
} else if (e.key.match(reOp)) {
|
||||||
else if (e.key && e.key.match(reOp))
|
|
||||||
$scope.pushOperator(e.key);
|
$scope.pushOperator(e.key);
|
||||||
|
} else if (e.keyCode === 86) {
|
||||||
else if (e.key && e.key == 'Enter')
|
if (e.ctrlKey || e.metaKey)
|
||||||
|
processClipboard();
|
||||||
|
} else if (e.keyCode === 13)
|
||||||
$scope.finish();
|
$scope.finish();
|
||||||
|
|
||||||
$timeout(function() {
|
$timeout(function() {
|
||||||
|
|
@ -82,13 +84,27 @@ angular.module('copayApp.controllers').controller('amountController', function($
|
||||||
$scope.amount = (($stateParams.toAmount) * satToUnit).toFixed(unitDecimals);
|
$scope.amount = (($stateParams.toAmount) * satToUnit).toFixed(unitDecimals);
|
||||||
}
|
}
|
||||||
|
|
||||||
processAmount($scope.amount);
|
processAmount();
|
||||||
|
|
||||||
$timeout(function() {
|
$timeout(function() {
|
||||||
$ionicScrollDelegate.resize();
|
$ionicScrollDelegate.resize();
|
||||||
}, 10);
|
}, 10);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
function paste(value) {
|
||||||
|
$scope.amount = value;
|
||||||
|
processAmount();
|
||||||
|
$timeout(function() {
|
||||||
|
$scope.$apply();
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
function processClipboard() {
|
||||||
|
if (!isNW) return;
|
||||||
|
var value = nodeWebkitService.readFromClipboard();
|
||||||
|
if (value && evaluate(value) > 0) paste(evaluate(value));
|
||||||
|
};
|
||||||
|
|
||||||
$scope.showSendMaxMenu = function() {
|
$scope.showSendMaxMenu = function() {
|
||||||
$scope.showSendMax = true;
|
$scope.showSendMax = true;
|
||||||
};
|
};
|
||||||
|
|
@ -128,7 +144,7 @@ angular.module('copayApp.controllers').controller('amountController', function($
|
||||||
|
|
||||||
$scope.amount = ($scope.amount + digit).replace('..', '.');
|
$scope.amount = ($scope.amount + digit).replace('..', '.');
|
||||||
checkFontSize();
|
checkFontSize();
|
||||||
processAmount($scope.amount);
|
processAmount();
|
||||||
};
|
};
|
||||||
|
|
||||||
$scope.pushOperator = function(operator) {
|
$scope.pushOperator = function(operator) {
|
||||||
|
|
@ -156,7 +172,7 @@ angular.module('copayApp.controllers').controller('amountController', function($
|
||||||
|
|
||||||
$scope.removeDigit = function() {
|
$scope.removeDigit = function() {
|
||||||
$scope.amount = $scope.amount.slice(0, -1);
|
$scope.amount = $scope.amount.slice(0, -1);
|
||||||
processAmount($scope.amount);
|
processAmount();
|
||||||
checkFontSize();
|
checkFontSize();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -166,17 +182,12 @@ angular.module('copayApp.controllers').controller('amountController', function($
|
||||||
checkFontSize();
|
checkFontSize();
|
||||||
};
|
};
|
||||||
|
|
||||||
function processAmount(val) {
|
function processAmount() {
|
||||||
if (!val) {
|
var formatedValue = format($scope.amount);
|
||||||
$scope.resetAmount();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
var formatedValue = format(val);
|
|
||||||
var result = evaluate(formatedValue);
|
var result = evaluate(formatedValue);
|
||||||
$scope.allowSend = lodash.isNumber(result) && +result > 0;
|
$scope.allowSend = lodash.isNumber(result) && +result > 0;
|
||||||
if (lodash.isNumber(result)) {
|
if (lodash.isNumber(result)) {
|
||||||
$scope.globalResult = isExpression(val) ? '= ' + processResult(result) : '';
|
$scope.globalResult = isExpression($scope.amount) ? '= ' + processResult(result) : '';
|
||||||
$scope.amountResult = $filter('formatFiatAmount')(toFiat(result));
|
$scope.amountResult = $filter('formatFiatAmount')(toFiat(result));
|
||||||
$scope.alternativeResult = txFormatService.formatAmount(fromFiat(result) * unitToSatoshi, true);
|
$scope.alternativeResult = txFormatService.formatAmount(fromFiat(result) * unitToSatoshi, true);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue