This commit is contained in:
Javier 2016-08-01 17:09:03 -03:00
commit a72bd7fde9
2 changed files with 30 additions and 65 deletions

View file

@ -15,10 +15,9 @@
<ion-content>
<div ng-show="!specificAmount">
<div class="send-amount row" ng-style="{'background-color':index.backgroundColor}">
<div class="size-48" ng-show="!showAlternativeAmount">{{amount}}</div>
<div class="size-21 text-light" ng-show="!showAlternativeAmount">{{globalResult}} {{amountResult}} {{alternativeIsoCode}}</div>
<div class="size-48" ng-show="showAlternativeAmount">${{alternativeAmount}}</div>
<div class="size-21 text-light" ng-show="showAlternativeAmount">{{globalResult}} {{alternativeResult}} {{unitName}}</div>
<div class="size-48">{{amount || '-'}}</div>
<div class="size-21 text-light" ng-show="!showAlternativeAmount">{{globalResult}} [{{amountResult || 0}} {{alternativeIsoCode}}]</div>
<div class="size-21 text-light" ng-show="showAlternativeAmount">{{globalResult}} [{{alternativeResult || 0}} {{unitName}}]</div>
</div>
<div class="button-content text-center size-10 df">

View file

@ -10,7 +10,7 @@ angular.module('copayApp.controllers').controller('inputAmountController', funct
var config = configService.getSync().wallet.settings;
$scope.unitName = config.unitName;
$scope.alternativeIsoCode = config.alternativeIsoCode;
$scope.specificAmount = $scope.specificAlternativeAmount = null;
$scope.specificAmount = $scope.specificAlternativeAmount = '';
$scope.isCordova = platformInfo.isCordova;
unitToSatoshi = config.unitToSatoshi;
satToUnit = 1 / unitToSatoshi;
@ -26,40 +26,18 @@ angular.module('copayApp.controllers').controller('inputAmountController', funct
$scope.toggleAlternative = function() {
$scope.showAlternativeAmount = !$scope.showAlternativeAmount;
var amount;
if ($scope.showAlternativeAmount) {
$scope.alternativeAmount = $scope.amountResult;
amount = format($scope.amount);
$scope.alternativeResult = isOperator(lodash.last(amount)) ? evaluate(amount.slice(0, -1)) : evaluate(amount);
} else {
$scope.amount = $scope.alternativeResult;
amount = format($scope.alternativeAmount);
$scope.amountResult = isOperator(lodash.last(amount)) ? evaluate(amount.slice(0, -1)) : evaluate(amount);
}
$scope.globalResult = null;
};
$scope.pushDigit = function(digit) {
var amount = $scope.showAlternativeAmount ? $scope.alternativeAmount.toString() : $scope.amount.toString();
if ($scope.amount && $scope.amount.length >= 20) return;
if (amount.length >= 20) return;
if (amount == '0') {
if (digit == 0) return;
processAmount(digit);
return;
}
processAmount(amount + digit);
$scope.amount = $scope.amount + digit;
processAmount($scope.amount);
};
$scope.pushOperator = function(operator) {
if ($scope.showAlternativeAmount) {
if (!$scope.alternativeAmount || $scope.alternativeAmount.length == 0) return;
$scope.alternativeAmount = _pushOperator($scope.alternativeAmount);
} else {
if (!$scope.amount || $scope.amount.length == 0) return;
$scope.amount = _pushOperator($scope.amount);
}
if (!$scope.amount || $scope.amount.length == 0) return;
$scope.amount = _pushOperator($scope.amount);
function _pushOperator(val) {
if (!isOperator(lodash.last(val))) {
@ -77,27 +55,26 @@ angular.module('copayApp.controllers').controller('inputAmountController', funct
return false;
};
$scope.removeDigit = function() {
var amount = $scope.showAlternativeAmount ? $scope.alternativeAmount : $scope.amount;
function isExpression(val) {
var regex = /^\d+(\.?\d?)+$/;
var match = regex.exec(val);
if (amount && amount.toString().length == 0) {
if (match) return false;
return true;
};
$scope.removeDigit = function() {
if ($scope.amount.toString().length == 1) {
resetAmount();
return;
}
amount = amount.toString().slice(0, -1);
if ($scope.showAlternativeAmount)
$scope.alternativeAmount = amount;
else
$scope.amount = amount;
processAmount(amount);
$scope.amount = $scope.amount.slice(0, -1);
processAmount($scope.amount);
};
function resetAmount() {
$scope.amount = $scope.alternativeAmount = $scope.alternativeResult = $scope.amountResult = 0;
$scope.globalResult = null;
$scope.amount = $scope.alternativeResult = $scope.amountResult = $scope.globalResult = '';
};
function processAmount(val) {
@ -106,24 +83,13 @@ angular.module('copayApp.controllers').controller('inputAmountController', funct
return;
}
if ($scope.showAlternativeAmount) {
if ($scope.alternativeAmount == 0 && val == '.') {
$scope.alternativeAmount += val;
}
} else {
if ($scope.amount == 0 && val == '.') {
$scope.amount += val;
}
}
var formatedValue = format(val);
var result = evaluate(formatedValue);
if (lodash.isNumber(result)) {
$scope.amount = $scope.alternativeAmount = val;
$scope.globalResult = result + ' =';
$scope.amountResult = toFiat(result);
$scope.alternativeResult = fromFiat(result);
$scope.globalResult = isExpression(val) ? '= ' + result.toFixed(2) : '';
$scope.amountResult = toFiat(result).toFixed(2);
$scope.alternativeResult = fromFiat(result).toFixed(2);
}
};
@ -140,9 +106,9 @@ angular.module('copayApp.controllers').controller('inputAmountController', funct
try {
result = $scope.$eval(val);
} catch (e) {
return null;
return 0;
}
if (result == 'Infinity' || lodash.isNaN(result)) return null;
if (result == 'Infinity' || lodash.isNaN(result)) return 0;
return result;
};
@ -161,7 +127,7 @@ angular.module('copayApp.controllers').controller('inputAmountController', funct
if ($scope.showAlternativeAmount) {
amount = $scope.alternativeResult;
alternativeAmount = evaluate(format($scope.alternativeAmount));
alternativeAmount = evaluate(format($scope.amount));
} else {
amount = evaluate(format($scope.amount));
alternativeAmount = toFiat(amount);
@ -174,10 +140,10 @@ angular.module('copayApp.controllers').controller('inputAmountController', funct
$scope.specificAmountBtc = (amountSat * satToBtc).toFixed(8);
}
$scope.specificAmount = amount.toFixed(2);
$scope.specificAlternativeAmount = alternativeAmount.toFixed(2);
$scope.specificAmount = amount;
$scope.specificAlternativeAmount = alternativeAmount;
} else {
self.setAmount(amount.toFixed(2), alternativeAmount.toFixed(2), $scope.showAlternativeAmount);
self.setAmount(amount, alternativeAmount, $scope.showAlternativeAmount);
$scope.cancel();
}
};