Skip to content

Commit

Permalink
Fixed Coins.ph.
Browse files Browse the repository at this point in the history
Fixed a crash when adding a coin that does not have an associated image.
  • Loading branch information
hwki committed Dec 10, 2023
1 parent 59f40a5 commit b3490ba
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 24 deletions.
4 changes: 2 additions & 2 deletions bitcoin/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ android {
applicationId "com.brentpanther.bitcoinwidget"
minSdk 23
targetSdk 34
versionCode 323
versionName "8.4.4"
versionCode 324
versionName "8.4.5"

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ object Repository {
return
}

ExchangeHelper.getStream(url).use { stream ->
ExchangeHelper.getStream(url)?.use { stream ->
ByteArrayOutputStream().use { os ->
BitmapFactory.decodeStream(stream)?.let { image ->
image.compress(Bitmap.CompressFormat.PNG, 100, os)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -279,12 +279,8 @@ enum class Exchange(val exchangeName: String, shortName: String? = null) {
COINSPH("Coins.ph") {

override fun getValue(coin: String, currency: String): String? {
val region = if (currency == "THB") "TH" else "PH"
val url = "https://quote.coins.ph/v2/markets/$coin-$currency?region=$region"
val obj = getJsonObject(url)
val bid = obj["bid"].asString?.toDoubleOrNull() ?: return null
val ask = obj["ask"].asString?.toDoubleOrNull() ?: return null
return ((bid + ask) / 2).toString()
val url = "https://api.pro.coins.ph/openapi/quote/v1/avgPrice?symbol=$coin$currency"
return getJsonObject(url)["price"].asString
}
},
COINTREE("Cointree") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,21 @@ object ExchangeHelper {
@Throws(IOException::class)
fun getJsonArray(url: String) = Json.decodeFromString<JsonArray>(getString(url))

fun getStream(url: String): InputStream = get(url).body!!.byteStream()

private fun getString(url: String, headers: Headers? = null) = get(url, headers).body!!.string()

private fun get(url: String, headers: Headers? = null): Response {
var builder = Request.Builder().url(url)
headers?.let {
builder = builder.headers(it)
fun getStream(url: String): InputStream? = get(url)?.body?.byteStream()

private fun getString(url: String, headers: Headers? = null) = get(url, headers)?.body?.string() ?: ""

private fun get(url: String, headers: Headers? = null): Response? {
return try {
var builder = Request.Builder().url(url)
headers?.let {
builder = builder.headers(it)
}
val request = builder.build()
client.newCall(request).execute()
} catch (e: IllegalArgumentException) {
null
}
val request = builder.build()
return client.newCall(request).execute()
}

@Throws(IOException::class)
Expand Down
2 changes: 1 addition & 1 deletion bitcoin/src/main/res/raw/cryptowidgetcoins_v2.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion bitcoin/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@
<item>ISO</item>
<item>NONE</item>
</string-array>
<string name="json_last_modified" translatable="false">Wed, 29 Nov 2023 23:27:06 GMT</string>
<string name="json_last_modified" translatable="false">Sun, 10 Dec 2023 22:44:10 GMT</string>
<string name="json_url" translatable="false">https://www.brentpanther.com/cryptowidgetcoins_v2.json</string>

<string name="error_restricted_battery_saver">Unable to refresh, Battery Saver is on</string>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -441,9 +441,7 @@ class GenerateSupportedCoinsJson {
}

private fun coinsph(): List<String> {
val pairs1 = parse("https://quote.coins.ph/v2/markets", "$.markets[*].symbol")
val pairs2 = parse("https://quote.coins.ph/v2/markets?region=TH", "$.markets[*].symbol")
return pairs1 + pairs2
return parse("https://api.pro.coins.ph/openapi/v1/pairs", "$[*].symbol")
}

private fun cointree(): List<String> {
Expand Down
2 changes: 2 additions & 0 deletions fastlane/metadata/android/en-US/changelogs/324.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Fixed Coins.ph.
Fixed a crash when adding a coin that does not have an associated image.

0 comments on commit b3490ba

Please sign in to comment.