From 850739e17e6f15c6ec05e294d01f7780264178bd Mon Sep 17 00:00:00 2001 From: JDonadio Date: Mon, 27 Mar 2017 16:59:01 -0300 Subject: [PATCH 1/2] paste evaluated amount --- src/js/controllers/amount.js | 30 +++++++++++++++++++++++------- 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/src/js/controllers/amount.js b/src/js/controllers/amount.js index 4202b8e01..8901f1a8d 100644 --- a/src/js/controllers/amount.js +++ b/src/js/controllers/amount.js @@ -1,6 +1,6 @@ '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 unitToSatoshi; var satToUnit; @@ -8,6 +8,7 @@ angular.module('copayApp.controllers').controller('amountController', function($ var satToBtc; var SMALL_FONT_SIZE_LIMIT = 10; var LENGTH_EXPRESSION_LIMIT = 19; + var isNW = platformInfo.isNW; $scope.isChromeApp = platformInfo.isChromeApp; $scope.$on('$ionicView.leave', function() { @@ -15,7 +16,6 @@ angular.module('copayApp.controllers').controller('amountController', function($ }); $scope.$on("$ionicView.beforeEnter", function(event, data) { - // Go to... _cardId = data.stateParams.id; // Optional (BitPay Card ID) $scope.nextStep = data.stateParams.nextStep; @@ -42,18 +42,20 @@ angular.module('copayApp.controllers').controller('amountController', function($ var reOp = /^[\*\+\-\/]$/; var disableKeys = angular.element($window).on('keydown', function(e) { + if (!e.key) return; if (e.which === 8) { // you can add others here inside brackets. e.preventDefault(); $scope.removeDigit(); } - if (e.key && e.key.match(reNr)) + if (e.key.match(reNr)) { $scope.pushDigit(e.key); - - else if (e.key && e.key.match(reOp)) + } else if (e.key.match(reOp)) { $scope.pushOperator(e.key); - - else if (e.key && e.key == 'Enter') + } else if (e.keyCode === 86) { + if (e.ctrlKey || e.metaKey) + processClipboard(); + } else if (e.keyCode === 13) $scope.finish(); $timeout(function() { @@ -89,6 +91,20 @@ angular.module('copayApp.controllers').controller('amountController', function($ }, 10); }); + function paste(value) { + $scope.amount = value; + processAmount(value); + $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.showSendMax = true; }; From 1ca3f24fa75de7292e3dfc096acd69e6bc4d0de1 Mon Sep 17 00:00:00 2001 From: JDonadio Date: Tue, 4 Apr 2017 09:34:01 -0300 Subject: [PATCH 2/2] remove unnecessary parameter --- src/js/controllers/amount.js | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/src/js/controllers/amount.js b/src/js/controllers/amount.js index 8901f1a8d..726dffcc3 100644 --- a/src/js/controllers/amount.js +++ b/src/js/controllers/amount.js @@ -84,7 +84,7 @@ angular.module('copayApp.controllers').controller('amountController', function($ $scope.amount = (($stateParams.toAmount) * satToUnit).toFixed(unitDecimals); } - processAmount($scope.amount); + processAmount(); $timeout(function() { $ionicScrollDelegate.resize(); @@ -93,7 +93,7 @@ angular.module('copayApp.controllers').controller('amountController', function($ function paste(value) { $scope.amount = value; - processAmount(value); + processAmount(); $timeout(function() { $scope.$apply(); }); @@ -144,7 +144,7 @@ angular.module('copayApp.controllers').controller('amountController', function($ $scope.amount = ($scope.amount + digit).replace('..', '.'); checkFontSize(); - processAmount($scope.amount); + processAmount(); }; $scope.pushOperator = function(operator) { @@ -172,7 +172,7 @@ angular.module('copayApp.controllers').controller('amountController', function($ $scope.removeDigit = function() { $scope.amount = $scope.amount.slice(0, -1); - processAmount($scope.amount); + processAmount(); checkFontSize(); }; @@ -182,17 +182,12 @@ angular.module('copayApp.controllers').controller('amountController', function($ checkFontSize(); }; - function processAmount(val) { - if (!val) { - $scope.resetAmount(); - return; - } - - var formatedValue = format(val); + function processAmount() { + var formatedValue = format($scope.amount); var result = evaluate(formatedValue); $scope.allowSend = lodash.isNumber(result) && +result > 0; if (lodash.isNumber(result)) { - $scope.globalResult = isExpression(val) ? '= ' + processResult(result) : ''; + $scope.globalResult = isExpression($scope.amount) ? '= ' + processResult(result) : ''; $scope.amountResult = $filter('formatFiatAmount')(toFiat(result)); $scope.alternativeResult = txFormatService.formatAmount(fromFiat(result) * unitToSatoshi, true); }