Adds amount directive
This commit is contained in:
parent
fb275d4b08
commit
e1d65bc557
6 changed files with 727 additions and 554 deletions
76
src/js/directives/amount.js
Normal file
76
src/js/directives/amount.js
Normal 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;
|
||||||
|
}
|
||||||
|
}]
|
||||||
|
};
|
||||||
|
}
|
||||||
|
]);
|
||||||
27
src/sass/components/amount.scss
Normal file
27
src/sass/components/amount.scss
Normal 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
1
src/sass/components/components.scss
Normal file
1
src/sass/components/components.scss
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
@import "amount.scss";
|
||||||
|
|
@ -9,4 +9,5 @@
|
||||||
@import "mixins/mixins";
|
@import "mixins/mixins";
|
||||||
@import "views/views";
|
@import "views/views";
|
||||||
@import "directives/directives";
|
@import "directives/directives";
|
||||||
|
@import "components/components";
|
||||||
@import "shame";
|
@import "shame";
|
||||||
|
|
|
||||||
1183
www/css/main.css
1183
www/css/main.css
File diff suppressed because it is too large
Load diff
|
|
@ -11,9 +11,8 @@
|
||||||
<link rel="stylesheet" type="text/css" href="css/chartist.css">
|
<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/bitcoin.com.css">
|
||||||
<link rel="stylesheet" type="text/css" href="css/icomoon.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">
|
<link rel="shortcut icon" href="img/app/favicon.ico">
|
||||||
<script src="https://www.googletagmanager.com/gtag/js?id=UA-59964190-23"></script>
|
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
|
||||||
|
|
@ -31,7 +30,7 @@
|
||||||
|
|
||||||
<script src="lib/ionic.bundle.min.js"></script>
|
<script src="lib/ionic.bundle.min.js"></script>
|
||||||
<script src="lib/angular-components.js"></script>
|
<script src="lib/angular-components.js"></script>
|
||||||
<script src="lib/bitcoin-cash-js.js"></script>
|
<script src="lib/bitcoin-cash-js.js"></script>
|
||||||
<script src="lib/bitanalytics.js"></script>
|
<script src="lib/bitanalytics.js"></script>
|
||||||
|
|
||||||
<script type="text/javascript" charset="utf-8" src="cordova.js"></script>
|
<script type="text/javascript" charset="utf-8" src="cordova.js"></script>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue