Refactor customized amount

This commit is contained in:
Gustavo Maximiliano Cortez 2015-06-26 14:25:53 -03:00
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> </nav>
<div class="modal-content"> <div class="modal-content">
<div ng-show="customizedAmount"> <div ng-show="customizedAmountBtc">
<h4 class="title m0" translate>QR Code</h4> <h4 class="title m0" translate>QR Code</h4>
<ul class="no-bullet size-14 m0"> <ul class="no-bullet size-14 m0">
<li class="line-b p10 oh text-center"> <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> </li>
</ul> </ul>
<h4 class="title m0" translate>Details</h4> <h4 class="title m0" translate>Details</h4>
@ -30,13 +30,13 @@
<li class="line-b p10 oh"> <li class="line-b p10 oh">
<span class="text-gray" translate>Amount</span>: <span class="text-gray" translate>Amount</span>:
<span class="right"> <span class="right">
{{customizedAmount}} {{customizedAmountUnit}}
<span class="label gray radius">{{customizedAlternative}}</span> <span class="label gray radius">{{customizedAlternativeUnit}}</span>
</span> </span>
</li> </li>
</ul> </ul>
</div> </div>
<div ng-show="!customizedAmount" class="row m20t"> <div ng-show="!customizedAmountBtc" class="row m20t">
<div class="large-12 large-centered columns"> <div class="large-12 large-centered columns">
<form name="amountForm" ng-submit="submitForm(amountForm)" novalidate> <form name="amountForm" ng-submit="submitForm(amountForm)" novalidate>
<div class="right" ng-hide="amountForm.amount.$pristine && !amountForm.amount.$modelValue "> <div class="right" ng-hide="amountForm.amount.$pristine && !amountForm.amount.$modelValue ">
@ -54,7 +54,7 @@
</label> </label>
<div class="input"> <div class="input">
<input type="number" id="amount" name="amount" ng-attr-placeholder="{{'Amount'|translate}}" <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"> <input type="number" id="alternative" name="alternative" ng-model="_customAlternative" style="display:none">
<a class="postfix" ng-click="toggleAlternative()">{{unitName}}</a> <a class="postfix" ng-click="toggleAlternative()">{{unitName}}</a>
</div> </div>

View file

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