Skip to content

Commit d6f4139

Browse files
committed
Fixed Coindesk API.
Migration from Fantom to Sonic
1 parent 9d31809 commit d6f4139

File tree

16 files changed

+46
-26
lines changed

16 files changed

+46
-26
lines changed

.idea/kotlinc.xml

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

bitcoin/build.gradle.kts

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ android {
1515
applicationId = "com.brentpanther.bitcoinwidget"
1616
minSdk = 23
1717
targetSdk = 35
18-
versionCode = 337
19-
versionName = "8.6.2"
18+
versionCode = 338
19+
versionName = "8.6.3"
2020
}
2121

2222
buildFeatures {

bitcoin/src/fdroid/java/com/brentpanther/bitcoinwidget/ui/home/AdditionalGlobalSettings.kt

+2-3
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import androidx.compose.runtime.Composable
99
import androidx.compose.ui.platform.LocalContext
1010
import androidx.compose.ui.res.painterResource
1111
import androidx.compose.ui.res.stringResource
12-
import androidx.core.content.ContextCompat
1312
import androidx.core.net.toUri
1413
import com.brentpanther.bitcoinwidget.R
1514
import com.brentpanther.bitcoinwidget.ui.settings.SettingsButton
@@ -31,8 +30,8 @@ fun AdditionalSettings() {
3130
},
3231
onClick = {
3332
try {
34-
ContextCompat.startActivity(context, Intent(Intent.ACTION_VIEW, address), null)
35-
} catch (e: ActivityNotFoundException) {
33+
context.startActivity(Intent(Intent.ACTION_VIEW, address))
34+
} catch (_: ActivityNotFoundException) {
3635
Toast.makeText(context, donateError, Toast.LENGTH_SHORT).show()
3736
}
3837
}

bitcoin/src/main/java/com/brentpanther/bitcoinwidget/Coin.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@ enum class Coin(val coinName: String, val coinGeckoId: String, private vararg va
6565
FIL("Filecoin", "filecoin", IconTheme(SOLID, ic_fil)),
6666
FIRO("Firo", "zcoin", IconTheme(SOLID, ic_firo, ic_firo_dark)),
6767
FLR("Flare", "flare-networks", IconTheme(SOLID, ic_flr)),
68-
FTM("Fantom", "fantom", IconTheme(SOLID, ic_ftm)),
6968
FTT("FTX Token", "ftx-token", IconTheme(SOLID, ic_ftt)),
7069
GALA("Gala", "gala", IconTheme(SOLID, ic_gala, ic_gala_white)),
7170
GNO("Gnosis", "gnosis", IconTheme(SOLID, ic_gno_color)),
@@ -131,6 +130,7 @@ enum class Coin(val coinName: String, val coinGeckoId: String, private vararg va
131130
SNX("Synthetix Network Token", "havven", IconTheme(SOLID, ic_snx)),
132131
SOL("Solana", "solana", IconTheme(SOLID, ic_sol)),
133132
SOLO("Sologenic", "solo-coin", IconTheme(SOLID, ic_solo)),
133+
S("Sonic", "sonic-3", IconTheme(SOLID, ic_s)),
134134
SPACE("MicrovisionChain", "microvisionchain", IconTheme(SOLID, ic_space)),
135135
STG("Stargate Finance", "stargate-finance", IconTheme(SOLID, ic_stg)),
136136
STORJ("Storj", "storj", IconTheme(SOLID, ic_storj)),

bitcoin/src/main/java/com/brentpanther/bitcoinwidget/db/DataMigration.kt

+5
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,14 @@ object DataMigration {
1616
migrateBitcludeToEgera(db)
1717
migrateCoinbaseProToCoinbase(db)
1818
migrateOkCoinToOkx(db)
19+
migrateFtmToSonic(db)
1920
fixRemovedExchanges(db)
2021
}
2122

23+
private fun migrateFtmToSonic(db: SupportSQLiteDatabase) {
24+
db.execSQL("UPDATE Widget SET coin = 'S' WHERE coin = 'FTM'")
25+
}
26+
2227
private fun migrateKaspaToKas(db: SupportSQLiteDatabase) {
2328
db.execSQL("UPDATE Widget SET coin = 'KAS' WHERE coin = 'KASPA'")
2429
}

bitcoin/src/main/java/com/brentpanther/bitcoinwidget/exchange/Exchange.kt

+2-2
Original file line numberDiff line numberDiff line change
@@ -211,8 +211,8 @@ enum class Exchange(val exchangeName: String, shortName: String? = null) {
211211
COINDESK("Coindesk") {
212212

213213
override fun getValue(coin: String, currency: String): String? {
214-
val url = "https://api.coindesk.com/v1/bpi/currentprice/$currency.json"
215-
return getJsonObject(url)["bpi"]?.jsonObject?.get(currency)?.jsonObject?.get("rate_float").asString
214+
val url = "https://min-api.cryptocompare.com/data/price?fsym=$coin&tsyms=$currency"
215+
return getJsonObject(url)[currency]?.asString
216216
}
217217
},
218218
COINGECKO("CoinGecko") {

bitcoin/src/main/java/com/brentpanther/bitcoinwidget/ui/BannersViewModel.kt

+1-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import android.os.Build
66
import android.os.PowerManager
77
import androidx.compose.runtime.mutableStateListOf
88
import androidx.core.content.edit
9-
import androidx.core.net.ConnectivityManagerCompat
109
import androidx.lifecycle.ViewModel
1110
import androidx.lifecycle.viewModelScope
1211
import com.brentpanther.bitcoinwidget.WidgetApplication
@@ -28,7 +27,7 @@ class BannersViewModel : ViewModel() {
2827
val connectivityManager = application.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager
2928
val restrictBackgroundStatus = connectivityManager.restrictBackgroundStatus
3029
if (restrictBackgroundStatus == ConnectivityManager.RESTRICT_BACKGROUND_STATUS_ENABLED &&
31-
ConnectivityManagerCompat.isActiveNetworkMetered(connectivityManager) &&
30+
connectivityManager.isActiveNetworkMetered &&
3231
!isDismissed(application, "data")) {
3332
visibleBanners.add("data")
3433
}
-3.46 KB
Binary file not shown.
10.9 KB
Loading

bitcoin/src/main/res/raw/cryptowidgetcoins_v2.json

+1-1
Large diffs are not rendered by default.

bitcoin/src/main/res/values/strings.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@
9898
<item>ISO</item>
9999
<item>NONE</item>
100100
</string-array>
101-
<string name="json_last_modified" translatable="false">Tue, 07 Jan 2025 02:28:34 GMT</string>
101+
<string name="json_last_modified" translatable="false">Tue, 18 Feb 2025 16:28:11 GMT</string>
102102
<string name="json_url" translatable="false">https://www.brentpanther.com/cryptowidgetcoins_v2.json</string>
103103

104104
<string name="error_restricted_battery_saver">Unable to refresh, Battery Saver is on</string>

bitcoin/src/playstore/java/com/brentpanther/bitcoinwidget/ui/home/AdditionalGlobalSettings.kt

+1-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import androidx.compose.runtime.Composable
88
import androidx.compose.ui.platform.LocalContext
99
import androidx.compose.ui.res.painterResource
1010
import androidx.compose.ui.res.stringResource
11-
import androidx.core.content.ContextCompat
1211
import androidx.core.net.toUri
1312
import com.brentpanther.bitcoinwidget.R
1413
import com.brentpanther.bitcoinwidget.ui.settings.SettingsButton
@@ -26,7 +25,7 @@ fun AdditionalSettings() {
2625
onClick = {
2726
try {
2827
val uri = "http://play.google.com/store/apps/details?id=${context.packageName}".toUri()
29-
ContextCompat.startActivity(context, Intent(Intent.ACTION_VIEW, uri), null)
28+
context.startActivity(Intent(Intent.ACTION_VIEW, uri))
3029
} catch (_: ActivityNotFoundException) {
3130
}
3231
}

bitcoin/src/test/java/com/brentpanther/bitcoinwidget/GenerateSupportedCoinsJson.kt

+19-3
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import com.brentpanther.bitcoinwidget.exchange.ExchangeData.JsonExchangeObject
77
import com.brentpanther.bitcoinwidget.exchange.ExchangeHelper.asString
88
import com.jayway.jsonpath.JsonPath
99
import kotlinx.serialization.ExperimentalSerializationApi
10-
import kotlinx.serialization.encodeToString
1110
import kotlinx.serialization.json.Json
1211
import kotlinx.serialization.json.JsonObject
1312
import kotlinx.serialization.json.decodeFromStream
@@ -409,8 +408,25 @@ class GenerateSupportedCoinsJson {
409408
}
410409

411410
private fun coindesk(): List<String> {
412-
val currencies = parse("https://api.coindesk.com/v1/bpi/supported-currencies.json", "$[*].currency")
413-
return currencies.map { "BTC_$it" }
411+
val coinLists = Coin.entries.map { it.name }.chunked(50)
412+
val coins = mutableListOf<String>()
413+
val currencies = mutableListOf<String>()
414+
coinLists.forEach { coinList ->
415+
val url = "https://min-api.cryptocompare.com/data/pricemulti?fsyms=${coinList.joinToString(",")}&tsyms=USD"
416+
val response = parseKeys(url, "$")
417+
coins.addAll(response)
418+
}
419+
val currencyLists = Currency.getAvailableCurrencies().map { it.currencyCode }.sorted().chunked(25)
420+
currencyLists.forEach { currencyList ->
421+
val url = "https://min-api.cryptocompare.com/data/pricemulti?fsyms=BTC&tsyms=${currencyList.joinToString(",")}"
422+
val response = parseKeys(url, "$.BTC")
423+
currencies.addAll(response)
424+
}
425+
return coins.flatMap { coin ->
426+
currencies.map { currency ->
427+
"${coin}_$currency"
428+
}
429+
}
414430
}
415431

416432
private fun coingecko(): List<String> {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Fixed Coindesk.
2+
Migrated Fantom (FTM) to Sonic (S).

gradle/libs.versions.toml

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
[versions]
2-
agp = "8.7.3"
3-
activityKtx = "1.9.3"
2+
agp = "8.8.1"
3+
activityKtx = "1.10.0"
44
coil = "2.7.0"
5-
compose = "2024.12.01"
5+
compose = "2025.02.00"
66
coreKtx = "1.15.0"
77
jsonPath = "2.9.0"
88
junit = "4.13.2"
9-
kotlin = "2.0.21"
10-
ksp = "2.0.21-1.0.25"
9+
kotlin = "2.1.10"
10+
ksp = "2.1.10-1.0.30"
1111
lifecycle = "2.8.7"
12-
navigation = "2.8.5"
12+
navigation = "2.8.7"
1313
okhttp = "4.12.0"
1414
preferences = "1.2.1"
1515
room = "2.6.1"
16-
serialization = "1.7.3"
16+
serialization = "1.8.0"
1717
work = "2.10.0"
1818

1919
[libraries]
+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
distributionBase=GRADLE_USER_HOME
22
distributionPath=wrapper/dists
3-
distributionUrl=https\://services.gradle.org/distributions/gradle-8.9-bin.zip
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-8.10.2-bin.zip
44
networkTimeout=10000
55
zipStoreBase=GRADLE_USER_HOME
66
zipStorePath=wrapper/dists

0 commit comments

Comments
 (0)