From ff6348a2335708e88adfd3de6a458eeea0c779d1 Mon Sep 17 00:00:00 2001 From: Javier Date: Thu, 7 Jul 2016 16:55:04 -0300 Subject: [PATCH] calculator --- public/views/send2.html | 47 ++++++++++++++++++++++ src/css/ionic-migration.css | 28 +++++++++++++ src/js/controllers/send2.js | 80 +++++++++++++++++++++++++++++++++++++ src/sass/main.scss | 8 ++++ 4 files changed, 163 insertions(+) create mode 100644 public/views/send2.html create mode 100644 src/js/controllers/send2.js diff --git a/public/views/send2.html b/public/views/send2.html new file mode 100644 index 000000000..bb51d26e4 --- /dev/null +++ b/public/views/send2.html @@ -0,0 +1,47 @@ + + +
+ Close +
+

Enter amount

+ +
+ +
+
${{amount}}
+
= ${{result}}
+
+ +
+ + + + +
+ +
+
+ + + +
+
+ + + +
+
+ + + +
+
+ + + +
+
+
\ No newline at end of file diff --git a/src/css/ionic-migration.css b/src/css/ionic-migration.css index bd311bb26..f853b59c8 100644 --- a/src/css/ionic-migration.css +++ b/src/css/ionic-migration.css @@ -16,6 +16,14 @@ display: inherit; } +.df { + display: flex; +} + +.button-content { + margin-bottom: -20px; +} + .behind { z-index: -1; } @@ -79,6 +87,26 @@ font-size: 14px; } +.button.button-light:hover { + background-color: #fff; + border: 1px solid #E9E9EC; +} + +.button.button-light:active { + background-color: #ababab; + border: 1px solid #E9E9EC; +} + +.button.button-stable:hover { + background-color: transparent; + border: 1px solid #E9E9EC; +} + +.button.button-stable:active { + background-color: #ababab; + border: 1px solid #E9E9EC; +} + button, .button { min-width: inherit; min-height: inherit; diff --git a/src/js/controllers/send2.js b/src/js/controllers/send2.js new file mode 100644 index 000000000..1fbfc7746 --- /dev/null +++ b/src/js/controllers/send2.js @@ -0,0 +1,80 @@ +'use strict'; + +angular.module('copayApp.controllers').controller('send2Controller', + function($scope, lodash, configService, go) { + var config = configService.getSync().wallet.settings; + $scope.unitName = config.unitName; + $scope.alternativeIsoCode = config.alternativeIsoCode; + $scope.amount = $scope.result = 0; + $scope.showAlternative = false; + + $scope.toggleAlternative = function() { + $scope.showAlternative = !$scope.showAlternative; + }; + + $scope.close = function() { + go.walletHome(); + }; + + $scope.pushDigit = function(digit) { + if ($scope.amount.length >= 10) return; + var amount; + if ($scope.amount == 0 && digit == 0) return; + amount = $scope.amount ? $scope.amount + digit : digit; + evaluate(amount); + }; + + $scope.pushOperator = function(operator) { + if (!$scope.amount || $scope.amount.length == 0) return; + if (!isOperator(lodash.last($scope.amount))) { + $scope.amount = $scope.amount + operator; + } else + $scope.amount = $scope.amount.slice(0, -1) + operator; + }; + + $scope.removeDigit = function() { + if (!$scope.amount || $scope.amount.length == 0) { + resetAmount(); + return; + } + + var amount; + $scope.amount = amount = $scope.amount.slice(0, -1); + evaluate(amount); + }; + + function isOperator(val) { + var regex = /[\/\-\+\*]/; + var match = regex.exec(val); + if (match) return true; + return false; + }; + + function resetAmount() { + $scope.amount = $scope.result = 0; + }; + + function evaluate(val) { + if (!val) { + resetAmount(); + return; + } + + if ($scope.amount == 0 && val == '.') { + $scope.amount += val; + return; + } + + var result; + try { + result = eval(val); + } catch (e) { + return; + } + + if (lodash.isNumber(result)) { + $scope.result = result; + $scope.amount = val; + } + }; + }); diff --git a/src/sass/main.scss b/src/sass/main.scss index 41f1a7904..fdab2fa47 100644 --- a/src/sass/main.scss +++ b/src/sass/main.scss @@ -1572,6 +1572,14 @@ input.ng-invalid-match { margin-bottom: 25px; } +.send-amount { + width: 100%; + text-align: center; + padding-top: 10px; + color: #fff; + height: 150px; +} + .alternative-amount { height: 25px; text-align: center;