|
|
@ -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; |
|
|
|
}); |
|
|
|
|
|
|
|
}); |
|
|
|