Skip to content

Commit

Permalink
Add additional fiat currencies
Browse files Browse the repository at this point in the history
  • Loading branch information
elibroftw committed Mar 15, 2022
1 parent 562162f commit a852d7c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
18 changes: 10 additions & 8 deletions main.qml
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,9 @@ ApplicationWindow {
// {provider name: {ticker: price_api_url}}
// API response schema depends on the provider
// fiat currencies also hard coded in SettingsLayout.qml
property var fiatPriceAPIs: ["usd", "eur"].reduce(function(obj, x) {
property var fiatPriceAPIs: ["usd", "eur", "aed", "ars", "aud", "bdt", "bhd", "brl", "cad", "chf", "clp", "cny", "czk", "gbp", "hkd",
"huf", "idr", "ils", "inr", "jpy", "krw", "kwd", "lkr", "mmk", "mxn", "myr", "ngn", "nok", "nzd", "php",
"pkr", "pln", "rub", "sar", "sek", "sgd", "thb", "try", "twd", "uah", "vef", "vnd", "zar", "xau"].reduce(function(obj, x) {
const key = `xmr${x}`; // e.g. xmrusd
const xUp = x.toUpperCase(); // e.g. usd -> USD
obj["kraken"][key] = `https://api.kraken.com/0/public/Ticker?pair=XMR${xUp}`;
Expand Down Expand Up @@ -1153,20 +1155,21 @@ ApplicationWindow {
appWindow.fiatApiError("Kraken API has error(s)");
return;
}
// currency is of the form xmr[a-Z]+. Replaces only starting XMR
var key = `${currency}`.replace("xmr", "xxmrz").toUpperCase();
// i.e. xmr[a-z]+ -> XXMRZ[A-Z]+
var key = `XXMRZ${currency.substring(3)}`;
var ticker = resp.result[key]["c"][0];
return ticker;
} else if(url.startsWith("https://api.coingecko.com/api/v3/")){
// i.e. xmr[a-Z]+ -> [a-Z]+
var key = currency.replace("xmr", "");
// i.e. xmr[a-z]+ -> [a-z]+
var key = currency.substring(3);
if(!resp.hasOwnProperty("monero") || !resp["monero"].hasOwnProperty(key)){
appWindow.fiatApiError("Coingecko API has error(s)");
return;
}
return resp["monero"][key];
} else if(url.startsWith("https://min-api.cryptocompare.com/data/")){
var key = currency.replace("xmr", "").toUpperCase();
// i.e. xmr[a-z]+ -> [A-Z]+
var key = currency.substring(3).toUpperCase();
if(!resp.hasOwnProperty(key)){
appWindow.fiatApiError("cryptocompare API has error(s)");
return;
Expand Down Expand Up @@ -1245,7 +1248,7 @@ ApplicationWindow {
}

function fiatApiCurrencySymbol() {
return persistentSettings.fiatPriceCurrency.replace("xmr", "").toUpperCase();
return persistentSettings.fiatPriceCurrency.substring(3).toUpperCase();
}

function fiatApiConvertToFiat(amount) {
Expand Down Expand Up @@ -2152,7 +2155,6 @@ ApplicationWindow {
console.log("close accepted");
// Close wallet non async on exit
daemonManager.exit();

closeWallet(Qt.quit);
}

Expand Down
4 changes: 3 additions & 1 deletion pages/settings/SettingsLayout.qml
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,9 @@ Rectangle {
id: fiatPriceCurrencyModel
// from https://agateau.com/2018/working-around-listmodel-limitations/
Component.onCompleted: {
["usd", "eur"].forEach(el => {
["usd", "eur", "aed", "ars", "aud", "bdt", "bhd", "brl", "cad", "chf", "clp", "cny", "czk", "gbp", "hkd",
"huf", "idr", "ils", "inr", "jpy", "krw", "kwd", "lkr", "mmk", "mxn", "myr", "ngn", "nok", "nzd", "php",
"pkr", "pln", "rub", "sar", "sek", "sgd", "thb", "try", "twd", "uah", "vef", "vnd", "zar", "xau"].forEach(el => {
append({
data: `xmr${el}`,
column1: el.toUpperCase()
Expand Down

0 comments on commit a852d7c

Please sign in to comment.