Merge pull request #266 from Bitcoin-com/wallet/task/427

Manage the currency state
This commit is contained in:
Jean-Baptiste Dominguez 2018-08-13 14:14:34 +09:00 committed by GitHub
commit 08ff6f2a6c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 11 deletions

View file

@ -26,9 +26,14 @@
}
});
function formattedAmountController($scope, $timeout, uxLanguage) {
$scope.canShow = false;
function formattedAmountController($scope, uxLanguage) {
$scope.vm = {};
var vm = $scope.vm;
vm.currency = '';
vm.value = '';
$scope.canShow = false
$scope.displaySizeEqual = !!$scope.sizeEqual;
var decimalPlaces = {
@ -90,17 +95,19 @@
// During watch, may be changed from having a separate currency value,
// to both being in value. Don't want to use previous currency value.
// Try to extract currency from value..
$scope.currency = $scope.currency || '';
var currencySplit = $scope.value.split(" ");
if (currencySplit.length >= 2 && $scope.currency.length === 0) {
$scope.currency = currencySplit[currencySplit.length - 1];
if (!$scope.currency || $scope.currency.length === 0) {
var currencySplit = $scope.value.split(" ");
if (currencySplit.length >= 2) {
vm.currency = currencySplit[currencySplit.length - 1];
}
} else {
vm.currency = $scope.currency;
}
// Redo this when we have proper formatting for low fees
if ($scope.value.indexOf("<") === 0) {
buildAmount($scope.value, '', '');
$scope.currency = '';
vm.currency = '';
$scope.canShow = true;
return;
}
@ -111,7 +118,7 @@
var parsed = parseFloat($scope.value);
var valueFormatted = '';
var valueProcessing = '';
switch (getDecimalPlaces($scope.currency)) {
switch (getDecimalPlaces(vm.currency)) {
case '0':
if (isNaN(parsed)) {
buildAmount('-', '', '');
@ -158,6 +165,7 @@
break;
}
$scope.canShow = true;
$scope.$apply();
};
function getDecimalPlaces(currency) {

View file

@ -1,4 +1,4 @@
<div class="formatted-amount"
ng-class="{ 'size-equal': displaySizeEqual }" ng-show="canShow">
<span ng-if="start.length > 0" class="start">{{start}}</span><span ng-if="middle.length > 0" class="middle">{{middle}}</span><span ng-if="end.length > 0" class="end">{{end}}</span><span ng-if="currency.length > 0" class="currency">{{currency}}</span>
<span ng-if="start.length > 0" class="start">{{start}}</span><span ng-if="middle.length > 0" class="middle">{{middle}}</span><span ng-if="end.length > 0" class="end">{{end}}</span><span ng-if="vm.currency.length > 0" class="currency">{{vm.currency}}</span>
</div>