bits support. using local storage to remember selected currency

This commit is contained in:
Gustavo Maximiliano Cortez 2014-10-13 02:22:07 -03:00
parent 56c0660c87
commit 8ea1d1e9c4
6 changed files with 15 additions and 4 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -1,6 +1,7 @@
'use strict';
var defaultLanguage = localStorage.getItem('insight-language') || 'en';
var defaultCurrency = localStorage.getItem('insight-currency') || 'BTC';
angular.module('insight',[
'ngAnimate',

View File

@ -2,6 +2,7 @@
angular.module('insight.currency').controller('CurrencyController',
function($scope, $rootScope, Currency) {
$rootScope.currency.symbol = defaultCurrency;
var _roundFloat = function(x, n) {
if(!parseInt(n, 10) || !parseFloat(x)) n = 0;
@ -22,6 +23,9 @@ angular.module('insight.currency').controller('CurrencyController',
} else if (this.symbol === 'mBTC') {
this.factor = 1000;
response = _roundFloat((value * this.factor), 5);
} else if (this.symbol === 'bits') {
this.factor = 1000000;
response = _roundFloat((value * this.factor), 2);
} else {
this.factor = 1;
response = value;
@ -37,6 +41,7 @@ angular.module('insight.currency').controller('CurrencyController',
$scope.setCurrency = function(currency) {
$rootScope.currency.symbol = currency;
localStorage.setItem('insight-currency', currency);
if (currency === 'USD') {
Currency.get({}, function(res) {
@ -44,6 +49,8 @@ angular.module('insight.currency').controller('CurrencyController',
});
} else if (currency === 'mBTC') {
$rootScope.currency.factor = 1000;
} else if (currency === 'bits') {
$rootScope.currency.factor = 1000000;
} else {
$rootScope.currency.factor = 1;
}
@ -51,7 +58,7 @@ angular.module('insight.currency').controller('CurrencyController',
// Get initial value
Currency.get({}, function(res) {
$rootScope.currency.bitstamp = res.data.bitstamp;
$rootScope.currency.factor = $rootScope.currency.bitstamp = res.data.bitstamp;
});
});

View File

@ -11,5 +11,8 @@
<li>
<a href="#" data-ng-click="setCurrency('mBTC')" data-ng-class="{active: currency.symbol == 'mBTC'}">mBTC</a>
</li>
<li>
<a href="#" data-ng-click="setCurrency('bits')" data-ng-class="{active: currency.symbol == 'bits'}">bits</a>
</li>
</ul>