@@ -102,23 +102,24 @@ ApplicationWindow {
102102
103103 // fiat price conversion
104104 property real fiatPrice: 0
105- property var fiatPriceAPIs: {
106- return {
107- " kraken" : {
108- " xmrusd" : " https://api.kraken.com/0/public/Ticker?pair=XMRUSD" ,
109- " xmreur" : " https://api.kraken.com/0/public/Ticker?pair=XMREUR"
110- },
111- " coingecko" : {
112- " xmrusd" : " https://api.coingecko.com/api/v3/simple/price?ids=monero&vs_currencies=usd" ,
113- " xmreur" : " https://api.coingecko.com/api/v3/simple/price?ids=monero&vs_currencies=eur"
114- },
115- " cryptocompare" : {
116- " xmrusd" : " https://min-api.cryptocompare.com/data/price?fsym=XMR&tsyms=USD" ,
117- " xmreur" : " https://min-api.cryptocompare.com/data/price?fsym=XMR&tsyms=EUR" ,
118- }
119- }
120- }
121105
106+ // {provider name: {ticker: price_api_url}}
107+ // API response schema depends on the provider
108+ property var fiatCurrencies: [" 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" ];
111+ property var fiatPriceAPIs: fiatCurrencies .reduce (function (obj , x ) {
112+ const key = ` xmr${ x} ` ; // e.g. xmrusd
113+ if (x === " usd" || x === " eur" ) {
114+ // Kraken only supports XMRUSD and XMREUR
115+ obj[" kraken" ][key] = ` https://api.kraken.com/0/public/Ticker?pair=XMR${ x} ` ;
116+ }
117+ obj[" coingecko" ][key] = ` https://api.coingecko.com/api/v3/simple/price?ids=monero&vs_currencies=${ x} ` ;
118+ obj[" cryptocompare" ][key] = ` https://min-api.cryptocompare.com/data/price?fsym=XMR&tsyms=${ x} ` ;
119+ return obj;
120+ }, {" kraken" : {}, " coingecko" : {}, " cryptocompare" : {}})
121+ // if the user is using Kraken, the following is used if the user wants non USD/EUR
122+ property string fiatPriceBackupProvider: " coingecko"
122123 // true if wallet ever synchronized
123124 property bool walletInitialized : false
124125
@@ -137,7 +138,7 @@ ApplicationWindow {
137138 passwordDialog .onAcceptedCallback = function () {
138139 if (walletPassword === passwordDialog .password )
139140 passwordDialog .close ();
140- else
141+ else
141142 passwordDialog .showError (qsTr (" Wrong password" ) + translationManager .emptyString );
142143 }
143144 passwordDialog .open (usefulName (persistentSettings .wallet_path ));
@@ -1029,10 +1030,10 @@ ApplicationWindow {
10291030 var isReserveProof = signature .indexOf (" ReserveProofV" ) === 0 ;
10301031 if (address .length > 0 && ! isReserveProof) {
10311032 result = currentWallet .checkTxProof (txid, address, message, signature);
1032- }
1033+ }
10331034 else if (isReserveProof) {
10341035 result = currentWallet .checkReserveProof (address, message, signature);
1035- }
1036+ }
10361037 else {
10371038 result = currentWallet .checkSpendProof (txid, message, signature);
10381039 }
@@ -1065,7 +1066,7 @@ ApplicationWindow {
10651066 informationPopup .title = qsTr (" Payment proof check" ) + translationManager .emptyString ;
10661067 informationPopup .icon = good ? StandardIcon .Information : StandardIcon .Critical ;
10671068 informationPopup .text = good ? qsTr (" Good signature" ) : qsTr (" Bad signature" );
1068- }
1069+ }
10691070 else if (isReserveProof && results[0 ] === " true" ) {
10701071 var good = results[1 ] === " true" ;
10711072 informationPopup .title = qsTr (" Reserve proof check" ) + translationManager .emptyString ;
@@ -1152,19 +1153,21 @@ ApplicationWindow {
11521153 appWindow .fiatApiError (" Kraken API has error(s)" );
11531154 return ;
11541155 }
1155-
1156- var key = currency === " xmreur " ? " XXMRZEUR " : " XXMRZUSD " ;
1156+ // i.e. xmr[a-z]+ -> XXMRZ[A-Z]+
1157+ var key = ` XXMRZ ${ currency . substring ( 3 ). toUpperCase () } ` ;
11571158 var ticker = resp .result [key][" c" ][0 ];
11581159 return ticker;
11591160 } else if (url .startsWith (" https://api.coingecko.com/api/v3/" )){
1160- var key = currency === " xmreur" ? " eur" : " usd" ;
1161+ // i.e. xmr[a-z]+ -> [a-z]+
1162+ var key = currency .substring (3 );
11611163 if (! resp .hasOwnProperty (" monero" ) || ! resp[" monero" ].hasOwnProperty (key)){
11621164 appWindow .fiatApiError (" Coingecko API has error(s)" );
11631165 return ;
11641166 }
11651167 return resp[" monero" ][key];
11661168 } else if (url .startsWith (" https://min-api.cryptocompare.com/data/" )){
1167- var key = currency === " xmreur" ? " EUR" : " USD" ;
1169+ // i.e. xmr[a-z]+ -> [A-Z]+
1170+ var key = currency .substring (3 ).toUpperCase ();
11681171 if (! resp .hasOwnProperty (key)){
11691172 appWindow .fiatApiError (" cryptocompare API has error(s)" );
11701173 return ;
@@ -1235,23 +1238,16 @@ ApplicationWindow {
12351238 var provider = appWindow .fiatPriceAPIs [userProvider];
12361239 var userCurrency = persistentSettings .fiatPriceCurrency ;
12371240 if (! provider .hasOwnProperty (userCurrency)){
1238- appWindow .fiatApiError (" currency \" " + userCurrency + " \" not implemented " );
1241+ appWindow .fiatApiError (" currency \" " + userCurrency + " \" is not supported by provider \" " + userProvider + " \" " );
12391242 }
12401243
12411244 var url = provider[userCurrency];
12421245 network .getJSON (url, fiatApiJsonReceived);
12431246 }
12441247
12451248 function fiatApiCurrencySymbol () {
1246- switch (persistentSettings .fiatPriceCurrency ) {
1247- case " xmrusd" :
1248- return " USD" ;
1249- case " xmreur" :
1250- return " EUR" ;
1251- default :
1252- console .error (" unsupported currency" , persistentSettings .fiatPriceCurrency );
1253- return " UNSUPPORTED" ;
1254- }
1249+ let currency = persistentSettings .fiatPriceCurrency .substring (3 );
1250+ return fiatCurrencies .indexOf (currency) === - 1 ? " UNSUPPORTED" ? currency .toUpperCase ();
12551251 }
12561252
12571253 function fiatApiConvertToFiat (amount ) {
0 commit comments