Adds amount directive

This commit is contained in:
Sam Cheng Hung 2018-07-30 16:49:57 +08:00
commit e1d65bc557
6 changed files with 727 additions and 554 deletions

View file

@ -0,0 +1,76 @@
'use strict';
/**
* @desc amount directive that can be used to display formatted financial values
* @example <amount value="12.49382901" currency="BCH"></amount>
*/
angular.module('bitcoincom.directives')
.directive('amount', [
'$timeout',
function($timeout) {
return {
restrict: 'E',
scope: {
value: '=',
currency: '='
},
templateUrl: 'views/includes/amount.html',
controller: ['$scope', function($scope) {
var decimalPlaces = {
'0': ['BIF', 'CLP', 'DJF', 'GNF', 'ILS', 'JPY', 'KMF', 'KRW', 'MGA', 'PYG', 'RWF', 'UGX', 'VND', 'VUV', 'XAF', 'XOF', 'XPF'],
'3': ['BHD', 'IQD', 'JOD', 'KWD', 'OMR', 'TND'],
'8': ['BCH', 'BTC']
};
var numberWithCommas = function(x) {
return parseFloat(x).toLocaleString();
};
var buildAmount = function(start, middle, end) {
$scope.start = start;
$scope.middle = middle;
$scope.end = end;
};
var getDecimalPlaces = function(currency) {
if (decimalPlaces['0'].indexOf($scope.currency.toUpperCase()) > -1) return '0';
if (decimalPlaces['3'].indexOf($scope.currency.toUpperCase()) > -1) return '3';
if (decimalPlaces['8'].indexOf($scope.currency.toUpperCase()) > -1) return '8';
return '2';
};
switch (getDecimalPlaces($scope.currency)) {
case '0':
var valueFormatted = numberWithCommas(Math.round(parseFloat($scope.value)));
buildAmount(valueFormatted, '', '');
break;
case '2':
var valueProcessing = parseFloat(parseFloat($scope.value).toFixed(2));
var valueFormatted = numberWithCommas(valueProcessing);
buildAmount(valueFormatted, '', '');
break;
case '3':
var valueProcessing = parseFloat(parseFloat($scope.value).toFixed(3));
var valueFormatted = numberWithCommas(valueProcessing);
buildAmount(valueFormatted, '', '');
break;
case '8':
var valueFormatted = parseFloat($scope.value).toFixed(8);
if (parseFloat($scope.value) == 0) {
buildAmount('0', '', '');
} else {
buildAmount(valueFormatted, '', '');
var start = numberWithCommas(valueFormatted.slice(0, -5));
var middle = valueFormatted.slice(-5, -2);
var end = valueFormatted.substr(valueFormatted.length - 2);
buildAmount(start, middle, end);
}
break;
}
}]
};
}
]);

View file

@ -0,0 +1,27 @@
.amount {
.start,
.middle,
.end,
.currency {
display: inline-block;
}
.start {
font-size: 1em;
}
.middle {
font-size: 0.7857em;
margin-left: 5px;
}
.end {
font-size: 0.7857em;
margin-left: 5px;
}
.currency {
font-size: 1em;
margin-left: 5px;
}
}

View file

@ -0,0 +1 @@
@import "amount.scss";

View file

@ -9,4 +9,5 @@
@import "mixins/mixins";
@import "views/views";
@import "directives/directives";
@import "components/components";
@import "shame";

File diff suppressed because it is too large Load diff

View file

@ -11,9 +11,8 @@
<link rel="stylesheet" type="text/css" href="css/chartist.css">
<link rel="stylesheet" type="text/css" href="css/bitcoin.com.css">
<link rel="stylesheet" type="text/css" href="css/icomoon.css">
<title>Bitcoin.com Wallet - Bitcoin.com Wallet</title>
<title>Bitcoin.com Wallet</title>
<link rel="shortcut icon" href="img/app/favicon.ico">
<script src="https://www.googletagmanager.com/gtag/js?id=UA-59964190-23"></script>
</head>
<body>