mirror of https://github.com/BTCPrivate/copay.git
clean code
This commit is contained in:
parent
0f7f6d9493
commit
ec56a7c044
|
@ -6,10 +6,13 @@
|
||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
<h1 class="title ellipsis" translate>Enter amount</h1>
|
<h1 class="title ellipsis" translate>Enter amount</h1>
|
||||||
<div class="buttons m5r m3t" ng-show="!specificAmount" ng-click="toggleAlternative()">
|
<div class="buttons m5r m3t" ng-if="!specificAmount" ng-click="toggleAlternative()">
|
||||||
<button class="button black" ng-show="showAlternativeAmount">{{alternativeIsoCode}}</button>
|
<button class="button black" ng-show="showAlternativeAmount">{{alternativeIsoCode}}</button>
|
||||||
<button class="button" ng-style="{'background-color':color}" ng-show="!showAlternativeAmount">{{unitName}}</button>
|
<button class="button" ng-style="{'background-color':color}" ng-show="!showAlternativeAmount">{{unitName}}</button>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="buttons m3t" ng-if="specificAmount" ng-click="init()">
|
||||||
|
<button class="button right" ng-style="{'background-color':color}"><span translate>Cancel</span></button>
|
||||||
|
</div>
|
||||||
</ion-header-bar>
|
</ion-header-bar>
|
||||||
|
|
||||||
<div>
|
<div>
|
||||||
|
@ -63,10 +66,10 @@
|
||||||
<h4 class="title m10l" translate>QR Code</h4>
|
<h4 class="title m10l" 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:{{address + '?amount=' + specificAmountBtc}}"></qrcode>
|
<qrcode size="220" data="bitcoin:{{addr + '?amount=' + specificAmount}}"></qrcode>
|
||||||
<div class="m10t text-center" ng-show="isCordova">
|
<div class="m10t text-center" ng-show="isCordova">
|
||||||
<span class="button outline dark-gray tiny round"
|
<span class="button outline dark-gray tiny round"
|
||||||
ng-click="shareAddress('bitcoin:' + address + '?amount=' + specificAmountBtc)">
|
ng-click="shareAddress('bitcoin:' + addr + '?amount=' + specificAmount)">
|
||||||
<i class="fi-share"></i>
|
<i class="fi-share"></i>
|
||||||
<span translate>Share address</span>
|
<span translate>Share address</span>
|
||||||
</span>
|
</span>
|
||||||
|
@ -90,16 +93,6 @@
|
||||||
</span>
|
</span>
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
|
|
||||||
<div class="row">
|
|
||||||
<div class="columns">
|
|
||||||
<button class="round expand m20t"
|
|
||||||
ng-style="{'background-color':index.backgroundColor}"
|
|
||||||
ng-click="init()">
|
|
||||||
<span translate>Cancel</span>
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</ion-modal-view>
|
</ion-modal-view>
|
||||||
|
|
|
@ -5,6 +5,8 @@ angular.module('copayApp.controllers').controller('inputAmountController', funct
|
||||||
var satToUnit;
|
var satToUnit;
|
||||||
var unitDecimals;
|
var unitDecimals;
|
||||||
var self = $scope.self;
|
var self = $scope.self;
|
||||||
|
var SMALL_FONT_SIZE_LIMIT = 13;
|
||||||
|
var LENGTH_EXPRESSION_LIMIT = 19;
|
||||||
|
|
||||||
$scope.init = function() {
|
$scope.init = function() {
|
||||||
var config = configService.getSync().wallet.settings;
|
var config = configService.getSync().wallet.settings;
|
||||||
|
@ -32,23 +34,20 @@ angular.module('copayApp.controllers').controller('inputAmountController', funct
|
||||||
|
|
||||||
if ($scope.amount && isExpression($scope.amount)) {
|
if ($scope.amount && isExpression($scope.amount)) {
|
||||||
var amount = evaluate(format($scope.amount));
|
var amount = evaluate(format($scope.amount));
|
||||||
if ($scope.showAlternativeAmount)
|
$scope.globalResult = '= ' + processResult(amount);
|
||||||
$scope.globalResult = '= ' + $filter('formatFiatAmount')(amount);
|
|
||||||
else
|
|
||||||
$scope.globalResult = '= ' + profileService.formatAmount(amount * unitToSatoshi, true);
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
function checkFontSize() {
|
function checkFontSize() {
|
||||||
if ($scope.amount && $scope.amount.length >= 13) $scope.smallFont = true;
|
if ($scope.amount && $scope.amount.length >= SMALL_FONT_SIZE_LIMIT) $scope.smallFont = true;
|
||||||
else $scope.smallFont = false;
|
else $scope.smallFont = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
$scope.pushDigit = function(digit) {
|
$scope.pushDigit = function(digit) {
|
||||||
checkFontSize();
|
if ($scope.amount && $scope.amount.length >= LENGTH_EXPRESSION_LIMIT) return;
|
||||||
if ($scope.amount && $scope.amount.length >= 19) return;
|
|
||||||
|
|
||||||
$scope.amount = ($scope.amount + digit).replace('..', '.');
|
$scope.amount = ($scope.amount + digit).replace('..', '.');
|
||||||
|
checkFontSize();
|
||||||
processAmount($scope.amount);
|
processAmount($scope.amount);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -67,25 +66,16 @@ angular.module('copayApp.controllers').controller('inputAmountController', funct
|
||||||
|
|
||||||
function isOperator(val) {
|
function isOperator(val) {
|
||||||
var regex = /[\/\-\+\x\*]/;
|
var regex = /[\/\-\+\x\*]/;
|
||||||
var match = regex.exec(val);
|
return regex.test(val);
|
||||||
if (match) return true;
|
|
||||||
return false;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
function isExpression(val) {
|
function isExpression(val) {
|
||||||
var regex = /^\.?\d+(\.?\d+)?([\/\-\+\*x]\d?\.?\d+)+$/;
|
var regex = /^\.?\d+(\.?\d+)?([\/\-\+\*x]\d?\.?\d+)+$/;
|
||||||
var match = regex.exec(val);
|
|
||||||
|
|
||||||
if (match) return true;
|
return regex.test(val);
|
||||||
return false;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
$scope.removeDigit = function() {
|
$scope.removeDigit = function() {
|
||||||
if ($scope.amount.toString().length == 1) {
|
|
||||||
$scope.resetAmount();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
$scope.amount = $scope.amount.slice(0, -1);
|
$scope.amount = $scope.amount.slice(0, -1);
|
||||||
processAmount($scope.amount);
|
processAmount($scope.amount);
|
||||||
checkFontSize();
|
checkFontSize();
|
||||||
|
@ -106,16 +96,19 @@ angular.module('copayApp.controllers').controller('inputAmountController', funct
|
||||||
var result = evaluate(formatedValue);
|
var result = evaluate(formatedValue);
|
||||||
|
|
||||||
if (lodash.isNumber(result)) {
|
if (lodash.isNumber(result)) {
|
||||||
if ($scope.showAlternativeAmount)
|
$scope.globalResult = isExpression(val) ? '= ' + processResult(result) : '';
|
||||||
$scope.globalResult = isExpression(val) ? '= ' + $filter('formatFiatAmount')(result) : '';
|
|
||||||
else
|
|
||||||
$scope.globalResult = isExpression(val) ? '= ' + profileService.formatAmount(result * unitToSatoshi, true) : '';
|
|
||||||
|
|
||||||
$scope.amountResult = $filter('formatFiatAmount')(toFiat(result));
|
$scope.amountResult = $filter('formatFiatAmount')(toFiat(result));
|
||||||
$scope.alternativeResult = profileService.formatAmount(fromFiat(result) * unitToSatoshi, true);
|
$scope.alternativeResult = profileService.formatAmount(fromFiat(result) * unitToSatoshi, true);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
function processResult(val) {
|
||||||
|
if ($scope.showAlternativeAmount)
|
||||||
|
return $filter('formatFiatAmount')(val);
|
||||||
|
else
|
||||||
|
return profileService.formatAmount(val.toFixed(unitDecimals) * unitToSatoshi, true);
|
||||||
|
};
|
||||||
|
|
||||||
function fromFiat(val) {
|
function fromFiat(val) {
|
||||||
return parseFloat((rateService.fromFiat(val, $scope.alternativeIsoCode) * satToUnit).toFixed(unitDecimals), 10);
|
return parseFloat((rateService.fromFiat(val, $scope.alternativeIsoCode) * satToUnit).toFixed(unitDecimals), 10);
|
||||||
};
|
};
|
||||||
|
@ -131,7 +124,7 @@ angular.module('copayApp.controllers').controller('inputAmountController', funct
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
if (result == 'Infinity' || lodash.isNaN(result)) return 0;
|
if (!lodash.isFinite(result)) return 0;
|
||||||
return result;
|
return result;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -145,26 +138,15 @@ angular.module('copayApp.controllers').controller('inputAmountController', funct
|
||||||
};
|
};
|
||||||
|
|
||||||
$scope.finish = function() {
|
$scope.finish = function() {
|
||||||
var amount;
|
var amount = evaluate(format($scope.amount)).toFixed(unitDecimals);
|
||||||
var alternativeAmount;
|
var alternativeAmount = fromFiat(amount).toFixed(unitDecimals);
|
||||||
|
|
||||||
if ($scope.showAlternativeAmount) {
|
if (amount % 1 == 0) amount = parseInt(amount);
|
||||||
amount = fromFiat($scope.globalResult);
|
|
||||||
alternativeAmount = profileService.formatAmount(evaluate(format($scope.amount)) * unitToSatoshi, true);
|
|
||||||
} else {
|
|
||||||
amount = profileService.formatAmount(evaluate(format($scope.amount)) * unitToSatoshi, true);
|
|
||||||
alternativeAmount = toFiat(amount);
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($scope.address) {
|
if ($scope.addr) {
|
||||||
var satToBtc = 1 / 100000000;
|
$scope.specificAmount = amount;
|
||||||
var amountSat = parseInt((amount * unitToSatoshi).toFixed(0));
|
$scope.specificAlternativeAmount = $filter('formatFiatAmount')(toFiat(amount));
|
||||||
if ($scope.unitName == 'bits') {
|
|
||||||
$scope.specificAmountBtc = (amountSat * satToBtc).toFixed(8);
|
|
||||||
}
|
|
||||||
|
|
||||||
$scope.specificAmount = profileService.formatAmount(amount * unitToSatoshi, true);
|
|
||||||
$scope.specificAlternativeAmount = $filter('formatFiatAmount')(alternativeAmount);
|
|
||||||
$timeout(function() {
|
$timeout(function() {
|
||||||
$ionicScrollDelegate.resize();
|
$ionicScrollDelegate.resize();
|
||||||
}, 100);
|
}, 100);
|
||||||
|
|
|
@ -348,14 +348,9 @@ angular.module('copayApp.controllers').controller('walletHomeController', functi
|
||||||
};
|
};
|
||||||
|
|
||||||
this.setAmount = function(amount, alternativeAmount, useAlternativeAmount) {
|
this.setAmount = function(amount, alternativeAmount, useAlternativeAmount) {
|
||||||
|
var amountResult = useAlternativeAmount ? alternativeAmount : amount;
|
||||||
$scope.showAlternative = useAlternativeAmount;
|
$scope.showAlternative = useAlternativeAmount;
|
||||||
var amountResult;
|
|
||||||
|
|
||||||
if (useAlternativeAmount) {
|
|
||||||
amountResult = parseFloat((rateService.fromFiat(alternativeAmount, self.alternativeIsoCode) * self.satToUnit).toFixed(self.unitDecimals), 10);
|
|
||||||
} else {
|
|
||||||
amountResult = amount;
|
|
||||||
}
|
|
||||||
self.fromInputAmount = true;
|
self.fromInputAmount = true;
|
||||||
self.setForm(null, amountResult, null);
|
self.setForm(null, amountResult, null);
|
||||||
};
|
};
|
||||||
|
@ -543,7 +538,7 @@ angular.module('copayApp.controllers').controller('walletHomeController', functi
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
$scope.openCustomAmountModal = function(addr) {
|
$scope.openCustomInputAmountModal = function(addr) {
|
||||||
var fc = profileService.focusedClient;
|
var fc = profileService.focusedClient;
|
||||||
$scope.color = fc.backgroundColor;
|
$scope.color = fc.backgroundColor;
|
||||||
$scope.self = self;
|
$scope.self = self;
|
||||||
|
@ -557,19 +552,19 @@ angular.module('copayApp.controllers').controller('walletHomeController', functi
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
$scope.openAmountModal = function(address) {
|
$scope.openAmountModal = function(addr) {
|
||||||
if (isCordova)
|
if (isCordova)
|
||||||
$scope.openInputAmountModal(address);
|
$scope.openInputAmountModal(addr);
|
||||||
else
|
else
|
||||||
$scope.openCustomAmountModal(address);
|
$scope.openCustomInputAmountModal(addr);
|
||||||
};
|
};
|
||||||
|
|
||||||
$scope.openInputAmountModal = function(addr) {
|
$scope.openInputAmountModal = function(addr) {
|
||||||
var fc = profileService.focusedClient;
|
var fc = profileService.focusedClient;
|
||||||
$scope.color = fc.backgroundColor;
|
$scope.color = fc.backgroundColor;
|
||||||
$scope.showAlternativeAmount = $scope.showAlternative || null;
|
$scope.showAlternativeAmount = $scope.showAlternative || null;
|
||||||
$scope.address = addr || null;
|
|
||||||
$scope.self = self;
|
$scope.self = self;
|
||||||
|
$scope.addr = addr;
|
||||||
|
|
||||||
$ionicModal.fromTemplateUrl('views/modals/inputAmount.html', {
|
$ionicModal.fromTemplateUrl('views/modals/inputAmount.html', {
|
||||||
scope: $scope
|
scope: $scope
|
||||||
|
|
Loading…
Reference in New Issue