Skip to content

Commit 2f380f8

Browse files
committed
Add additional fiat currencies
1 parent 562162f commit 2f380f8

File tree

2 files changed

+13
-9
lines changed

2 files changed

+13
-9
lines changed

main.qml

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,9 @@ ApplicationWindow {
105105
// {provider name: {ticker: price_api_url}}
106106
// API response schema depends on the provider
107107
// fiat currencies also hard coded in SettingsLayout.qml
108-
property var fiatPriceAPIs: ["usd", "eur"].reduce(function(obj, x) {
108+
property var fiatPriceAPIs: ["usd", "eur", "aed", "ars", "aud", "bdt", "bhd", "brl", "cad", "chf", "clp", "cny", "czk", "gbp", "hkd",
109+
"huf", "idr", "ils", "inr", "jpy", "krw", "kwd", "lkr", "mmk", "mxn", "myr", "ngn", "nok", "nzd", "php",
110+
"pkr", "pln", "rub", "sar", "sek", "sgd", "thb", "try", "twd", "uah", "vef", "vnd", "zar", "xau"].reduce(function(obj, x) {
109111
const key = `xmr${x}`; // e.g. xmrusd
110112
const xUp = x.toUpperCase(); // e.g. usd -> USD
111113
obj["kraken"][key] = `https://api.kraken.com/0/public/Ticker?pair=XMR${xUp}`;
@@ -1153,20 +1155,21 @@ ApplicationWindow {
11531155
appWindow.fiatApiError("Kraken API has error(s)");
11541156
return;
11551157
}
1156-
// currency is of the form xmr[a-Z]+. Replaces only starting XMR
1157-
var key = `${currency}`.replace("xmr", "xxmrz").toUpperCase();
1158+
// i.e. xmr[a-z]+ -> XXMRZ[A-Z]+
1159+
var key = `XXMRZ${currency.substring(3)}`;
11581160
var ticker = resp.result[key]["c"][0];
11591161
return ticker;
11601162
} else if(url.startsWith("https://api.coingecko.com/api/v3/")){
1161-
// i.e. xmr[a-Z]+ -> [a-Z]+
1162-
var key = currency.replace("xmr", "");
1163+
// i.e. xmr[a-zz]+ -> [a-z]+
1164+
var key = currency.substring(3);
11631165
if(!resp.hasOwnProperty("monero") || !resp["monero"].hasOwnProperty(key)){
11641166
appWindow.fiatApiError("Coingecko API has error(s)");
11651167
return;
11661168
}
11671169
return resp["monero"][key];
11681170
} else if(url.startsWith("https://min-api.cryptocompare.com/data/")){
1169-
var key = currency.replace("xmr", "").toUpperCase();
1171+
// i.e. xmr[a-z]+ -> [A-Z]+
1172+
var key = currency.substring(3).toUpperCase();
11701173
if(!resp.hasOwnProperty(key)){
11711174
appWindow.fiatApiError("cryptocompare API has error(s)");
11721175
return;
@@ -1245,7 +1248,7 @@ ApplicationWindow {
12451248
}
12461249

12471250
function fiatApiCurrencySymbol() {
1248-
return persistentSettings.fiatPriceCurrency.replace("xmr", "").toUpperCase();
1251+
return persistentSettings.fiatPriceCurrency.substring(3).toUpperCase();
12491252
}
12501253

12511254
function fiatApiConvertToFiat(amount) {
@@ -2152,7 +2155,6 @@ ApplicationWindow {
21522155
console.log("close accepted");
21532156
// Close wallet non async on exit
21542157
daemonManager.exit();
2155-
21562158
closeWallet(Qt.quit);
21572159
}
21582160

pages/settings/SettingsLayout.qml

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

0 commit comments

Comments
 (0)