Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
Changed exchange rate API calls and re-enabled currency selection
  • Loading branch information
SkateFish authored Mar 29, 2018
1 parent d7f0223 commit 315f6c9
Show file tree
Hide file tree
Showing 6 changed files with 1,077 additions and 4 deletions.
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ Auroracoin Wallet Extension 2.0 - Aurora-node API Version

Auroracoin wallet in the browser. Send and receive instantly on any web page.

Version 1.3 - Updated for Multi-Algo
Version 2.0 - Updated to use Insight exclusively for blockchain access and tx send
Version 1.3 - Updated for Multi-Algo
Version 2.0 - Updated to use Insight exclusively for blockchain access and tx send
Version 2.0.1 - Removed incompatible API, exchange rates currently unavailable
Version 2.0.2 - Fixed API calls, exchange rates and currencies re-enabled

Security
--------
Expand Down
105 changes: 105 additions & 0 deletions currency-manager.js
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);
Loading

0 comments on commit 315f6c9

Please sign in to comment.