From 599f53d39fa6e7eaba98288279ed96d419c2cdde Mon Sep 17 00:00:00 2001 From: Gustavo Maximiliano Cortez Date: Wed, 24 Jun 2015 17:55:08 -0300 Subject: [PATCH 1/4] Generate QR code with customized amount --- public/views/modals/customized-amount.html | 80 +++++++++++++++++++++ public/views/walletHome.html | 5 ++ src/js/controllers/walletHome.js | 81 ++++++++++++++++++++++ 3 files changed, 166 insertions(+) create mode 100644 public/views/modals/customized-amount.html diff --git a/public/views/modals/customized-amount.html b/public/views/modals/customized-amount.html new file mode 100644 index 000000000..a83f5b59a --- /dev/null +++ b/public/views/modals/customized-amount.html @@ -0,0 +1,80 @@ + + + diff --git a/public/views/walletHome.html b/public/views/walletHome.html index 5e298ed0f..8e724b825 100644 --- a/public/views/walletHome.html +++ b/public/views/walletHome.html @@ -264,6 +264,11 @@ +
+ + Receive a customized amount + +
diff --git a/src/js/controllers/walletHome.js b/src/js/controllers/walletHome.js index 635217a3d..7a8363ab6 100644 --- a/src/js/controllers/walletHome.js +++ b/src/js/controllers/walletHome.js @@ -411,6 +411,87 @@ angular.module('copayApp.controllers').controller('walletHomeController', functi } }; + this.openCustomizedAmountModal = function(addr) { + var self = this; + var fc = profileService.focusedClient; + var ModalInstanceCtrl = function($scope, $modalInstance) { + $scope.addr = addr; + $scope.color = fc.backgroundColor; + $scope.unitName = self.unitName; + $scope.alternativeAmount = self.alternativeAmount; + $scope.alternativeName = self.alternativeName; + $scope.alternativeIsoCode = self.alternativeIsoCode; + $scope.isRateAvailable = self.isRateAvailable; + $scope.unitToSatoshi = self.unitToSatoshi; + $scope.unitDecimals = self.unitDecimals; + var satToUnit = 1 / self.unitToSatoshi; + $scope.showAlternative = false; + + Object.defineProperty($scope, + "_customAlternative", { + get: function() { + return $scope.customAlternative; + }, + set: function(newValue) { + $scope.customAlternative = newValue; + if (typeof(newValue) === 'number' && $scope.isRateAvailable) { + $scope.customAmount = parseFloat((rateService.fromFiat(newValue, $scope.alternativeIsoCode) * satToUnit).toFixed($scope.unitDecimals), 10); + } + }, + enumerable: true, + configurable: true + }); + + Object.defineProperty($scope, + "_customAmount", { + get: function() { + return $scope.customAmount; + }, + set: function(newValue) { + $scope.customAmount = newValue; + if (typeof(newValue) === 'number' && $scope.isRateAvailable) { + $scope.customAlternative = parseFloat((rateService.toFiat(newValue * $scope.unitToSatoshi, $scope.alternativeIsoCode)).toFixed(2), 10); + } else { + $scope.customAlternative = 0; + } + $scope.alternativeAmount = $scope.customAlternative; + }, + enumerable: true, + configurable: true + }); + + $scope.submitForm = function(form) { + var satToBtc = 1 / 100000000; + var amount = form.amount.$modelValue; + var alternative = form.alternative.$modelValue; + if ($scope.unitName == 'bits') { + amount = parseInt((amount * $scope.unitToSatoshi).toFixed(0)) * satToBtc; + } + $scope.customizedAmount = amount; + $scope.customizedAlternative = alternative; + }; + + $scope.toggleAlternative = function() { + $scope.showAlternative = !$scope.showAlternative; + }; + + $scope.cancel = function() { + $modalInstance.dismiss('cancel'); + }; + }; + + var modalInstance = $modal.open({ + templateUrl: 'views/modals/customized-amount.html', + windowClass: 'full animated slideInUp', + controller: ModalInstanceCtrl, + }); + + modalInstance.result.finally(function() { + var m = angular.element(document.getElementsByClassName('reveal-modal')); + m.addClass('slideOutDown'); + }); + }; + // Send this.canShowAlternative = function() { From 0fc3aa9539842f495ac57df02633e5add49743d1 Mon Sep 17 00:00:00 2001 From: Gustavo Maximiliano Cortez Date: Fri, 26 Jun 2015 14:25:53 -0300 Subject: [PATCH 2/4] Refactor customized amount --- public/views/modals/customized-amount.html | 12 ++++++------ src/js/controllers/walletHome.js | 15 +++++++++------ 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/public/views/modals/customized-amount.html b/public/views/modals/customized-amount.html index a83f5b59a..5fbaad998 100644 --- a/public/views/modals/customized-amount.html +++ b/public/views/modals/customized-amount.html @@ -12,11 +12,11 @@