@@ -101,22 +101,18 @@ ApplicationWindow {
101101
102102 // fiat price conversion
103103 property real fiatPrice: 0
104- property var fiatPriceAPIs: {
105- return {
106- " kraken" : {
107- " xmrusd" : " https://api.kraken.com/0/public/Ticker?pair=XMRUSD" ,
108- " xmreur" : " https://api.kraken.com/0/public/Ticker?pair=XMREUR"
109- },
110- " coingecko" : {
111- " xmrusd" : " https://api.coingecko.com/api/v3/simple/price?ids=monero&vs_currencies=usd" ,
112- " xmreur" : " https://api.coingecko.com/api/v3/simple/price?ids=monero&vs_currencies=eur"
113- },
114- " cryptocompare" : {
115- " xmrusd" : " https://min-api.cryptocompare.com/data/price?fsym=XMR&tsyms=USD" ,
116- " xmreur" : " https://min-api.cryptocompare.com/data/price?fsym=XMR&tsyms=EUR" ,
117- }
118- }
119- }
104+
105+ // {provider name: {ticker: price_api_url}}
106+ // API response schema depends on the provider
107+ // fiat currencies also hard coded in SettingsLayout.qml
108+ property var fiatPriceAPIs: [" usd" , " eur" ].reduce (function (obj , x ) {
109+ const key = ` xmr${ x} ` ; // e.g. xmrusd
110+ const xUp = x .toUpperCase (); // e.g. usd -> USD
111+ obj[" kraken" ][key] = ` https://api.kraken.com/0/public/Ticker?pair=XMR${ xUp} ` ;
112+ obj[" coingecko" ][key] = ` https://api.coingecko.com/api/v3/simple/price?ids=monero&vs_currencies=${ x} ` ;
113+ obj[" cryptocompare" ][key] = ` https://min-api.cryptocompare.com/data/price?fsym=XMR&tsyms=${ xUp} ` ;
114+ return obj;
115+ }, {" kraken" : {}, " coingecko" : {}, " cryptocompare" : {}})
120116
121117 // true if wallet ever synchronized
122118 property bool walletInitialized : false
@@ -1032,10 +1028,10 @@ ApplicationWindow {
10321028 var isReserveProof = signature .indexOf (" ReserveProofV" ) === 0 ;
10331029 if (address .length > 0 && ! isReserveProof) {
10341030 result = currentWallet .checkTxProof (txid, address, message, signature);
1035- }
1031+ }
10361032 else if (isReserveProof) {
10371033 result = currentWallet .checkReserveProof (address, message, signature);
1038- }
1034+ }
10391035 else {
10401036 result = currentWallet .checkSpendProof (txid, message, signature);
10411037 }
@@ -1068,7 +1064,7 @@ ApplicationWindow {
10681064 informationPopup .title = qsTr (" Payment proof check" ) + translationManager .emptyString ;
10691065 informationPopup .icon = good ? StandardIcon .Information : StandardIcon .Critical ;
10701066 informationPopup .text = good ? qsTr (" Good signature" ) : qsTr (" Bad signature" );
1071- }
1067+ }
10721068 else if (isReserveProof && results[0 ] === " true" ) {
10731069 var good = results[1 ] === " true" ;
10741070 informationPopup .title = qsTr (" Reserve proof check" ) + translationManager .emptyString ;
@@ -1157,19 +1153,20 @@ ApplicationWindow {
11571153 appWindow .fiatApiError (" Kraken API has error(s)" );
11581154 return ;
11591155 }
1160-
1161- var key = currency === " xmreur " ? " XXMRZEUR " : " XXMRZUSD " ;
1156+ // currency is of the form xmr[a-Z]+. Replaces only starting XMR
1157+ var key = ` ${ currency} ` . replace ( " xmr " , " xxmrz " ). toUpperCase () ;
11621158 var ticker = resp .result [key][" c" ][0 ];
11631159 return ticker;
11641160 } else if (url .startsWith (" https://api.coingecko.com/api/v3/" )){
1165- var key = currency === " xmreur" ? " eur" : " usd" ;
1161+ // i.e. xmr[a-Z]+ -> [a-Z]+
1162+ var key = currency .replace (" xmr" , " " );
11661163 if (! resp .hasOwnProperty (" monero" ) || ! resp[" monero" ].hasOwnProperty (key)){
11671164 appWindow .fiatApiError (" Coingecko API has error(s)" );
11681165 return ;
11691166 }
11701167 return resp[" monero" ][key];
11711168 } else if (url .startsWith (" https://min-api.cryptocompare.com/data/" )){
1172- var key = currency === " xmreur " ? " EUR " : " USD " ;
1169+ var key = currency . replace ( " xmr " , " " ). toUpperCase () ;
11731170 if (! resp .hasOwnProperty (key)){
11741171 appWindow .fiatApiError (" cryptocompare API has error(s)" );
11751172 return ;
@@ -1248,15 +1245,7 @@ ApplicationWindow {
12481245 }
12491246
12501247 function fiatApiCurrencySymbol () {
1251- switch (persistentSettings .fiatPriceCurrency ) {
1252- case " xmrusd" :
1253- return " USD" ;
1254- case " xmreur" :
1255- return " EUR" ;
1256- default :
1257- console .error (" unsupported currency" , persistentSettings .fiatPriceCurrency );
1258- return " UNSUPPORTED" ;
1259- }
1248+ return persistentSettings .fiatPriceCurrency .replace (" xmr" , " " ).toUpperCase ();
12601249 }
12611250
12621251 function fiatApiConvertToFiat (amount ) {
@@ -2163,7 +2152,7 @@ ApplicationWindow {
21632152 console .log (" close accepted" );
21642153 // Close wallet non async on exit
21652154 daemonManager .exit ();
2166-
2155+
21672156 closeWallet (Qt .quit );
21682157 }
21692158
0 commit comments