|
1 | | -// Copyright (c) 2014-2024, The Monero Project |
| 1 | +// Copyright (c) 2014-2026, The Monero Project |
2 | 2 | // |
3 | 3 | // All rights reserved. |
4 | 4 | // |
@@ -106,19 +106,18 @@ ApplicationWindow { |
106 | 106 | // fiat price conversion |
107 | 107 | property real fiatPrice: 0 |
108 | 108 | property var fiatPriceAPIs: { |
| 109 | + const currencies = ["xmrusd", "xmreur", "xmrgbp", "xmrcad", "xmraud", "xmrnzd", "xmrchf"]; |
| 110 | + var coingecko = {}; |
| 111 | + var cryptocompare = {}; |
| 112 | + for (var i = 0; i < currencies.length; ++i) { |
| 113 | + const currency = currencies[i]; |
| 114 | + const key = getKeyFromCurrency(currency); |
| 115 | + coingecko[currency] = "https://api.coingecko.com/api/v3/simple/price?ids=monero&vs_currencies=" + key; |
| 116 | + cryptocompare[currency] = "https://min-api.cryptocompare.com/data/price?fsym=XMR&tsyms=" + key.toUpperCase(); |
| 117 | + } |
109 | 118 | return { |
110 | | - "kraken": { |
111 | | - "xmrusd": "https://api.kraken.com/0/public/Ticker?pair=XMRUSD", |
112 | | - "xmreur": "https://api.kraken.com/0/public/Ticker?pair=XMREUR" |
113 | | - }, |
114 | | - "coingecko": { |
115 | | - "xmrusd": "https://api.coingecko.com/api/v3/simple/price?ids=monero&vs_currencies=usd", |
116 | | - "xmreur": "https://api.coingecko.com/api/v3/simple/price?ids=monero&vs_currencies=eur" |
117 | | - }, |
118 | | - "cryptocompare": { |
119 | | - "xmrusd": "https://min-api.cryptocompare.com/data/price?fsym=XMR&tsyms=USD", |
120 | | - "xmreur": "https://min-api.cryptocompare.com/data/price?fsym=XMR&tsyms=EUR", |
121 | | - } |
| 119 | + "coingecko": coingecko, |
| 120 | + "cryptocompare": cryptocompare |
122 | 121 | } |
123 | 122 | } |
124 | 123 |
|
@@ -1233,26 +1232,23 @@ ApplicationWindow { |
1233 | 1232 | triggeredOnStart: true |
1234 | 1233 | } |
1235 | 1234 |
|
| 1235 | + function getKeyFromCurrency(currency) { |
| 1236 | + if (currency.length !== 6 || currency.substring(0, 3) !== "xmr") |
| 1237 | + return undefined; |
| 1238 | + return currency.substring(3); |
| 1239 | + } |
| 1240 | + |
1236 | 1241 | function fiatApiParseTicker(url, resp, currency){ |
1237 | 1242 | // parse & validate incoming JSON |
1238 | | - if(url.startsWith("https://api.kraken.com/0/")){ |
1239 | | - if(resp.hasOwnProperty("error") && resp.error.length > 0 || !resp.hasOwnProperty("result")){ |
1240 | | - appWindow.fiatApiError("Kraken API has error(s)"); |
1241 | | - return; |
1242 | | - } |
1243 | | - |
1244 | | - var key = currency === "xmreur" ? "XXMRZEUR" : "XXMRZUSD"; |
1245 | | - var ticker = resp.result[key]["c"][0]; |
1246 | | - return ticker; |
1247 | | - } else if(url.startsWith("https://api.coingecko.com/api/v3/")){ |
1248 | | - var key = currency === "xmreur" ? "eur" : "usd"; |
| 1243 | + if(url.startsWith("https://api.coingecko.com/api/v3/")){ |
| 1244 | + var key = getKeyFromCurrency(currency) |
1249 | 1245 | if(!resp.hasOwnProperty("monero") || !resp["monero"].hasOwnProperty(key)){ |
1250 | 1246 | appWindow.fiatApiError("Coingecko API has error(s)"); |
1251 | 1247 | return; |
1252 | 1248 | } |
1253 | 1249 | return resp["monero"][key]; |
1254 | 1250 | } else if(url.startsWith("https://min-api.cryptocompare.com/data/")){ |
1255 | | - var key = currency === "xmreur" ? "EUR" : "USD"; |
| 1251 | + var key = getKeyFromCurrency(currency) |
1256 | 1252 | if(!resp.hasOwnProperty(key)){ |
1257 | 1253 | appWindow.fiatApiError("cryptocompare API has error(s)"); |
1258 | 1254 | return; |
@@ -1336,6 +1332,16 @@ ApplicationWindow { |
1336 | 1332 | return "USD"; |
1337 | 1333 | case "xmreur": |
1338 | 1334 | return "EUR"; |
| 1335 | + case "xmrgbp": |
| 1336 | + return "GBP"; |
| 1337 | + case "xmrcad": |
| 1338 | + return "CAD"; |
| 1339 | + case "xmraud": |
| 1340 | + return "AUD"; |
| 1341 | + case "xmrnzd": |
| 1342 | + return "NZD"; |
| 1343 | + case "xmrchf": |
| 1344 | + return "CHF"; |
1339 | 1345 | default: |
1340 | 1346 | console.error("unsupported currency", persistentSettings.fiatPriceCurrency); |
1341 | 1347 | return "UNSUPPORTED"; |
@@ -1517,7 +1523,7 @@ ApplicationWindow { |
1517 | 1523 |
|
1518 | 1524 | property bool fiatPriceEnabled: false |
1519 | 1525 | property bool fiatPriceToggle: false |
1520 | | - property string fiatPriceProvider: "kraken" |
| 1526 | + property string fiatPriceProvider: "coingecko" |
1521 | 1527 | property string fiatPriceCurrency: "xmrusd" |
1522 | 1528 |
|
1523 | 1529 | property string proxyAddress: "127.0.0.1:9050" |
|
0 commit comments