forked from syspect-sec/auroracoin-browser-wallet
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Changed exchange rate API calls and re-enabled currency selection
- Loading branch information
Showing
6 changed files
with
1,077 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
/** | ||
* currency-manager.js | ||
* Copyright (c) 2014 Andrew Toth | ||
* | ||
* This program is free software; you can redistribute it and/or modify | ||
* it under the terms of the MIT license. | ||
* | ||
* Currency manager handles the exchange rate of the currency | ||
* and the proper formatting of the currency value | ||
*/ | ||
|
||
(function (window) { | ||
var currencyInstance; | ||
var currencyManager = function () {}; | ||
currencyManager.prototype = { | ||
updateExchangeRate: function () { | ||
//upadate the value of AuroraCoin to bitcoin | ||
var tickresult | ||
util.getJSON('https://bittrex.com/api/v1.1/public/getticker?market=btc-aur').then(function (response){ | ||
tickresult = response ; | ||
AURExchangeRate = tickresult.result.Last; | ||
//console.log(AURExchangeRate); | ||
}); | ||
return preferences.getCurrency().then(function (currency) { | ||
return util.getJSON('https://apiv2.bitcoinaverage.com/indices/global/ticker/BTC' + currency); | ||
}).then(function (response) { | ||
return preferences.setExchangeRate(response.last * AURExchangeRate ); | ||
}); | ||
}, | ||
|
||
getSymbol: function () { | ||
return preferences.getCurrency().then(function (currency) { | ||
switch (currency) { | ||
case 'AUD': | ||
case 'CAD': | ||
case 'NZD': | ||
case 'SGD': | ||
case 'USD': | ||
return(['$', 'before']); | ||
case 'BRL': | ||
return(['R$', 'before']); | ||
case 'CHF': | ||
return([' Fr.', 'after']); | ||
case 'CNY': | ||
case 'JPY': | ||
return(['¥', 'before']); | ||
case 'EUR': | ||
return(['€', 'before']); | ||
case 'GBP': | ||
return(['£', 'before']); | ||
case 'ILS': | ||
return(['₪', 'before']); | ||
case 'NOK': | ||
case 'SEK': | ||
case 'ISK': | ||
return([' ISK', 'after']); | ||
case 'PLN': | ||
return(['zł', 'after']); | ||
case 'RUB': | ||
return([' RUB', 'after']); | ||
case 'ZAR': | ||
return([' R', 'after']); | ||
default: | ||
return(['$', 'before']); | ||
} | ||
}); | ||
}, | ||
|
||
getAvailableCurrencies: function () { | ||
return ['AUD', 'BRL', 'CAD', 'CHF', 'CNY', 'ISK', 'EUR', 'GBP', 'ILS', 'JPY', 'NOK', 'NZD', 'PLN', 'RUB', 'SEK', 'SGD', 'USD', 'ZAR']; | ||
}, | ||
|
||
formatAmount: function (value) { | ||
return Promise.all([preferences.getExchangeRate(), this.getSymbol()]).then(function (values) { | ||
var rate = values[0], | ||
symbol = values[1][0], | ||
beforeOrAfter = values[1][1], | ||
SATOSHIS = 100000000, | ||
text = (value / SATOSHIS * rate).formatMoney(2); | ||
if (beforeOrAfter === 'before') { | ||
text = symbol + text; | ||
} else { | ||
text += symbol; | ||
} | ||
return text; | ||
}); | ||
} | ||
}; | ||
|
||
Number.prototype.formatMoney = function(c, d, t){ | ||
var n = this, | ||
c = isNaN(c = Math.abs(c)) ? 2 : c, | ||
d = d == undefined ? "." : d, | ||
t = t == undefined ? "," : t, | ||
s = n < 0 ? "-" : "", | ||
i = parseInt(n = Math.abs(+n || 0).toFixed(c)) + "", | ||
j = (j = i.length) > 3 ? j % 3 : 0; | ||
return s + (j ? i.substr(0, j) + t : "") + i.substr(j).replace(/(\d{3})(?=\d)/g, "$1" + t) + (c ? d + Math.abs(n - i).toFixed(c).slice(2) : ""); | ||
}; | ||
|
||
var ret = new currencyManager(); | ||
ret.updateExchangeRate(); | ||
window.currencyManager = ret; | ||
|
||
})(window); |
Oops, something went wrong.