calculator
This commit is contained in:
parent
6d79a5da72
commit
ff6348a233
4 changed files with 163 additions and 0 deletions
47
public/views/send2.html
Normal file
47
public/views/send2.html
Normal file
|
|
@ -0,0 +1,47 @@
|
||||||
|
<ion-content ng-controller="send2Controller">
|
||||||
|
<ion-header-bar align-title="center" class="tab-bar" ng-style="{'background-color':index.backgroundColor}">
|
||||||
|
<div class="left-small">
|
||||||
|
<a class="p10" ng-click="close()"><span class="text-close" translate>Close</span></a>
|
||||||
|
</div>
|
||||||
|
<h1 class="title ellipsis" translate>Enter amount</h1>
|
||||||
|
<div class="right-small m5r">
|
||||||
|
<a class="postfix" ng-show="showAlternative" ng-click="toggleAlternative()">{{alternativeIsoCode}}</a>
|
||||||
|
<a class="postfix" ng-show="!showAlternative" ng-click="toggleAlternative()">{{unitName}}</a>
|
||||||
|
</div>
|
||||||
|
</ion-header-bar>
|
||||||
|
|
||||||
|
<div class="send-amount row" ng-style="{'background-color':index.backgroundColor}">
|
||||||
|
<div class="size-48">${{amount}}</div>
|
||||||
|
<div class="size-21 text-light">= ${{result}}</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="button-content ext-center df">
|
||||||
|
<button class="button expand button-stable" ng-click="pushOperator('*')">*</button>
|
||||||
|
<button class="button expand button-stable" ng-click="pushOperator('/')">/</button>
|
||||||
|
<button class="button expand button-stable" ng-click="pushOperator('+')">+</button>
|
||||||
|
<button class="button expand button-stable" ng-click="pushOperator('-')">-</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="m10b">
|
||||||
|
<div class="button-content text-center df">
|
||||||
|
<button class="button expand button-light" ng-click="pushDigit('1')">1</button>
|
||||||
|
<button class="button expand button-light" ng-click="pushDigit('2')">2</button>
|
||||||
|
<button class="button expand button-light" ng-click="pushDigit('3')">3</button>
|
||||||
|
</div>
|
||||||
|
<div class="button-content text-center df">
|
||||||
|
<button class="button expand button-light" ng-click="pushDigit('4')">4</button>
|
||||||
|
<button class="button expand button-light" ng-click="pushDigit('5')">5</button>
|
||||||
|
<button class="button expand button-light" ng-click="pushDigit('6')">6</button>
|
||||||
|
</div>
|
||||||
|
<div class="button-content text-center df">
|
||||||
|
<button class="button expand button-light" ng-click="pushDigit('7')">7</button>
|
||||||
|
<button class="button expand button-light" ng-click="pushDigit('8')">8</button>
|
||||||
|
<button class="button expand button-light" ng-click="pushDigit('9')">9</button>
|
||||||
|
</div>
|
||||||
|
<div class="button-content text-center df">
|
||||||
|
<button class="button expand button-light" ng-click="pushDigit('.')">.</button>
|
||||||
|
<button class="button expand button-light" ng-click="pushDigit('0')">0</button>
|
||||||
|
<button class="button expand button-light" ng-click="removeDigit()"><</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</ion-content>
|
||||||
|
|
@ -16,6 +16,14 @@
|
||||||
display: inherit;
|
display: inherit;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.df {
|
||||||
|
display: flex;
|
||||||
|
}
|
||||||
|
|
||||||
|
.button-content {
|
||||||
|
margin-bottom: -20px;
|
||||||
|
}
|
||||||
|
|
||||||
.behind {
|
.behind {
|
||||||
z-index: -1;
|
z-index: -1;
|
||||||
}
|
}
|
||||||
|
|
@ -79,6 +87,26 @@
|
||||||
font-size: 14px;
|
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 {
|
button, .button {
|
||||||
min-width: inherit;
|
min-width: inherit;
|
||||||
min-height: inherit;
|
min-height: inherit;
|
||||||
|
|
|
||||||
80
src/js/controllers/send2.js
Normal file
80
src/js/controllers/send2.js
Normal file
|
|
@ -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;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
@ -1572,6 +1572,14 @@ input.ng-invalid-match {
|
||||||
margin-bottom: 25px;
|
margin-bottom: 25px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.send-amount {
|
||||||
|
width: 100%;
|
||||||
|
text-align: center;
|
||||||
|
padding-top: 10px;
|
||||||
|
color: #fff;
|
||||||
|
height: 150px;
|
||||||
|
}
|
||||||
|
|
||||||
.alternative-amount {
|
.alternative-amount {
|
||||||
height: 25px;
|
height: 25px;
|
||||||
text-align: center;
|
text-align: center;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue