Fix fiat balance price source
This commit is contained in:
parent
d7fa096714
commit
59ee1e0bb9
1 changed files with 50 additions and 11 deletions
|
|
@ -1825,22 +1825,56 @@ class WalletActivity : FragmentActivity() {
|
||||||
) {
|
) {
|
||||||
Thread {
|
Thread {
|
||||||
try {
|
try {
|
||||||
val nestExJson =
|
fun readJson(url: String): org.json.JSONObject {
|
||||||
org.json.JSONObject(
|
val connection =
|
||||||
java.net.URL(
|
java.net.URL(url)
|
||||||
"https://trade.nestex.one/api/cg/tickers/VTX_USDT"
|
.openConnection() as
|
||||||
).readText()
|
java.net.HttpURLConnection
|
||||||
|
|
||||||
|
try {
|
||||||
|
connection.requestMethod = "GET"
|
||||||
|
connection.connectTimeout = 10_000
|
||||||
|
connection.readTimeout = 10_000
|
||||||
|
connection.useCaches = false
|
||||||
|
connection.setRequestProperty(
|
||||||
|
"User-Agent",
|
||||||
|
"Mozilla/5.0"
|
||||||
|
)
|
||||||
|
connection.setRequestProperty(
|
||||||
|
"Accept",
|
||||||
|
"application/json"
|
||||||
|
)
|
||||||
|
|
||||||
|
if (connection.responseCode !in 200..299) {
|
||||||
|
throw java.io.IOException(
|
||||||
|
"HTTP ${connection.responseCode} for $url"
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
return org.json.JSONObject(
|
||||||
|
connection.inputStream
|
||||||
|
.bufferedReader()
|
||||||
|
.use { it.readText() }
|
||||||
|
)
|
||||||
|
} finally {
|
||||||
|
connection.disconnect()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
val priceJson =
|
||||||
|
readJson(
|
||||||
|
"https://vexta-pool.co.uk/vextaprice.json"
|
||||||
)
|
)
|
||||||
|
|
||||||
val vtxUsdt =
|
val vtxUsdt =
|
||||||
nestExJson.getString("last_price")
|
priceJson.getString("price")
|
||||||
.toDouble()
|
.toDouble()
|
||||||
|
|
||||||
|
require(vtxUsdt > 0.0)
|
||||||
|
|
||||||
val fxJson =
|
val fxJson =
|
||||||
org.json.JSONObject(
|
readJson(
|
||||||
java.net.URL(
|
"https://api.frankfurter.app/latest?from=USD&to=GBP,EUR"
|
||||||
"https://api.frankfurter.app/latest?from=USD&to=GBP,EUR"
|
|
||||||
).readText()
|
|
||||||
)
|
)
|
||||||
|
|
||||||
val rates =
|
val rates =
|
||||||
|
|
@ -1869,7 +1903,12 @@ class WalletActivity : FragmentActivity() {
|
||||||
runOnUiThread {
|
runOnUiThread {
|
||||||
onLoaded(values)
|
onLoaded(values)
|
||||||
}
|
}
|
||||||
} catch (_: Exception) {
|
} catch (error: Exception) {
|
||||||
|
android.util.Log.e(
|
||||||
|
"VextaFiat",
|
||||||
|
"Unable to load fiat values",
|
||||||
|
error
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}.start()
|
}.start()
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue