Refactor customized amount

This commit is contained in:
Gustavo Maximiliano Cortez 2015-06-26 14:25:53 -03:00
parent 599f53d39f
commit 0fc3aa9539
No known key found for this signature in database
GPG Key ID: 15EDAD8D9F2EB1AF
2 changed files with 15 additions and 12 deletions

View File

@ -12,11 +12,11 @@
</nav>
<div class="modal-content">
<div ng-show="customizedAmount">
<div ng-show="customizedAmountBtc">
<h4 class="title m0" translate>QR Code</h4>
<ul class="no-bullet size-14 m0">
<li class="line-b p10 oh text-center">
<qrcode size="220" data="bitcoin:{{addr + '?amount=' + customizedAmount}}"></qrcode>
<qrcode size="220" data="bitcoin:{{addr + '?amount=' + customizedAmountBtc}}"></qrcode>
</li>
</ul>
<h4 class="title m0" translate>Details</h4>
@ -30,13 +30,13 @@
<li class="line-b p10 oh">
<span class="text-gray" translate>Amount</span>:
<span class="right">
{{customizedAmount}}
<span class="label gray radius">{{customizedAlternative}}</span>
{{customizedAmountUnit}}
<span class="label gray radius">{{customizedAlternativeUnit}}</span>
</span>
</li>
</ul>
</div>
<div ng-show="!customizedAmount" class="row m20t">
<div ng-show="!customizedAmountBtc" class="row m20t">
<div class="large-12 large-centered columns">
<form name="amountForm" ng-submit="submitForm(amountForm)" novalidate>
<div class="right" ng-hide="amountForm.amount.$pristine && !amountForm.amount.$modelValue ">
@ -54,7 +54,7 @@
</label>
<div class="input">
<input type="number" id="amount" name="amount" ng-attr-placeholder="{{'Amount'|translate}}"
ng-minlength="0.00000001" ng-maxlength="10000000000" ng-model="_customAmount" valid-amount required autocomplete="off">
ng-model="_customAmount" valid-amount required autocomplete="off">
<input type="number" id="alternative" name="alternative" ng-model="_customAlternative" style="display:none">
<a class="postfix" ng-click="toggleAlternative()">{{unitName}}</a>
</div>

View File

@ -463,12 +463,15 @@ angular.module('copayApp.controllers').controller('walletHomeController', functi
$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;
var amountSat = parseInt((amount * $scope.unitToSatoshi).toFixed(0));
$timeout(function() {
$scope.customizedAmountUnit = amount + ' ' + $scope.unitName;
$scope.customizedAlternativeUnit = $filter('noFractionNumber')(form.alternative.$modelValue, 2) + ' ' + $scope.alternativeIsoCode;
if ($scope.unitName == 'bits') {
amount = amountSat * satToBtc;
}
$scope.customizedAmountBtc = amount;
}, 1);
};
$scope.toggleAlternative = function() {