diff --git a/public/views/modals/customAmount.html b/public/views/modals/customAmount.html new file mode 100644 index 000000000..755b38b1f --- /dev/null +++ b/public/views/modals/customAmount.html @@ -0,0 +1,88 @@ + + + + + Close + + + Request a specific amount + + + + + + QR Code + + + + + + + Share address + + + + + + Details + + + Address: + + {{addr}} + + + + Amount: + + {{customizedAmountUnit}} + {{customizedAlternativeUnit}} + + + + + + + + + + + + Not valid + + + + + + + + Amount + + + + + {{unitName}} + + + + Amount [{{ alternativeIsoCode }}] + + + + + {{ alternativeIsoCode }} + + + + + Generate QR Code + + + + + + + diff --git a/public/views/walletHome.html b/public/views/walletHome.html index b985a6634..4f0b808ae 100644 --- a/public/views/walletHome.html +++ b/public/views/walletHome.html @@ -303,9 +303,16 @@ + + Request a specific amount + + ng-disabled="home.generatingAddress" + ng-show="index.isCordova"> Request a specific amount @@ -420,8 +427,14 @@ Amount [{{home.alternativeIsoCode}}] - - + + + + + + + + {{home.unitName}} {{home.alternativeIsoCode}} diff --git a/src/js/controllers/modals/customAmount.js b/src/js/controllers/modals/customAmount.js new file mode 100644 index 000000000..386ed1073 --- /dev/null +++ b/src/js/controllers/modals/customAmount.js @@ -0,0 +1,79 @@ +'use strict'; + +angular.module('copayApp.controllers').controller('customAmountController', function($scope, $timeout, $filter, platformInfo, rateService) { + var self = $scope.self; + + $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; + $scope.isCordova = platformInfo.isCordova; + + 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); + } else { + $scope.customAmount = null; + } + }, + 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 = null; + } + $scope.alternativeAmount = $scope.customAlternative; + }, + enumerable: true, + configurable: true + }); + + $scope.submitForm = function(form) { + var satToBtc = 1 / 100000000; + var amount = form.amount.$modelValue; + var amountSat = parseInt((amount * $scope.unitToSatoshi).toFixed(0)); + $timeout(function() { + $scope.customizedAmountUnit = amount + ' ' + $scope.unitName; + $scope.customizedAlternativeUnit = $filter('formatFiatAmount')(form.alternative.$modelValue) + ' ' + $scope.alternativeIsoCode; + if ($scope.unitName == 'bits') { + amount = (amountSat * satToBtc).toFixed(8); + } + $scope.customizedAmountBtc = amount; + }, 1); + }; + + $scope.toggleAlternative = function() { + $scope.showAlternative = !$scope.showAlternative; + }; + + $scope.shareAddress = function(uri) { + if (platformInfo.isCordova) { + window.plugins.socialsharing.share(uri, null, null, null); + } + }; + + $scope.cancel = function() { + $scope.customAmountModal.hide(); + }; +}); diff --git a/src/js/controllers/modals/inputAmount.js b/src/js/controllers/modals/inputAmount.js index 7fa6e816c..23a66cf5e 100644 --- a/src/js/controllers/modals/inputAmount.js +++ b/src/js/controllers/modals/inputAmount.js @@ -40,11 +40,10 @@ angular.module('copayApp.controllers').controller('inputAmountController', funct }; $scope.pushDigit = function(digit) { - var amount = $scope.showAlternativeAmount ? $scope.alternativeAmount : $scope.amount; - - if (amount.toString().length >= 10) return; - if (amount == 0 && digit == 0) return; + var amount = $scope.showAlternativeAmount ? $scope.alternativeAmount.toString() : $scope.amount.toString(); + if (amount.length >= 10) return; + if (amount == '0' && digit == 0) return; var val = amount ? amount + digit : digit; processAmount(val); }; @@ -137,7 +136,7 @@ angular.module('copayApp.controllers').controller('inputAmountController', funct } catch (e) { return null; } - if (result == 'Infinity') return null; + if (result == 'Infinity' || lodash.isNaN(result)) return null; return result; }; diff --git a/src/js/controllers/walletHome.js b/src/js/controllers/walletHome.js index c178d472e..4b42929de 100644 --- a/src/js/controllers/walletHome.js +++ b/src/js/controllers/walletHome.js @@ -543,6 +543,20 @@ angular.module('copayApp.controllers').controller('walletHomeController', functi }); }; + $scope.openCustomAmountModal = function(addr) { + var fc = profileService.focusedClient; + $scope.color = fc.backgroundColor; + $scope.self = self; + $scope.addr = addr; + + $ionicModal.fromTemplateUrl('views/modals/customAmount.html', { + scope: $scope + }).then(function(modal) { + $scope.customAmountModal = modal; + $scope.customAmountModal.show(); + }); + }; + $scope.openInputAmountModal = function(addr) { var fc = profileService.focusedClient; $scope.color = fc.backgroundColor;