Skip to content

Validate default exchange selection against active exchanges#150

Merged
hwki merged 1 commit intohwki:masterfrom
reddink:fix/getDefaultExchange
Mar 29, 2026
Merged

Validate default exchange selection against active exchanges#150
hwki merged 1 commit intohwki:masterfrom
reddink:fix/getDefaultExchange

Conversation

@reddink
Copy link
Copy Markdown
Contributor

@reddink reddink commented Mar 27, 2026

was noticing the following error when trying to setup a couple of different coins on a new device
It was preventing the addition of some coins on device

FATAL EXCEPTION: main
Process: com.brentpanther.bitcoinwidget.debug, PID: 17457
java.lang.IllegalArgumentException: No enum constant com.brentpanther.bitcoinwidget.exchange.Exchange.COINDESK
	at java.lang.Enum.valueOf(Enum.java:300)
	at com.brentpanther.bitcoinwidget.exchange.Exchange.valueOf(Unknown Source:2)
	at com.brentpanther.bitcoinwidget.ui.selection.CoinSelectionViewModel$createWidget$2.invokeSuspend(CoinSelectionViewModel.kt:49)
	at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:34)
	at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:100)
	at kotlinx.coroutines.internal.LimitedDispatcher$Worker.run(LimitedDispatcher.kt:124)
	at kotlinx.coroutines.scheduling.TaskImpl.run(Tasks.kt:89)
	at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:586)
	at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:820)
	at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:717)
	at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:704)
	Suppressed: kotlinx.coroutines.internal.DiagnosticCoroutineContextException: [androidx.compose.ui.platform.MotionDurationScaleImpl@c0b2818, androidx.compose.runtime.BroadcastFrameClock@1879271, StandaloneCoroutine{Cancelling}@9bdf856, AndroidUiDispatcher@1120d7]

The following change should allow for fallback to CoinGecko if enum is missing.
Its going to:

  • look up all exchange names that support the given currency (e.g. "USD"). If none are found, immediately return "COINGECKO" as the default.
  • get the list of all exchange names currently defined in the Exchange enum
  • find the first exchange from the JSON data that also exists in the enum, and if no match is found, fall back to COINGECKO.

Previously getDefaultExchange() could return an exchange that had been removed from the codebase but still existed in the cached JSON file. Now it filters candidates against the Exchange enum before selecting a default, falling back to CoinGecko if no valid match is found.
@hwki
Copy link
Copy Markdown
Owner

hwki commented Mar 27, 2026

@reddink Do you have an example of how to get this error to occur? I'm having trouble reproducing it.

@reddink
Copy link
Copy Markdown
Contributor Author

reddink commented Mar 28, 2026

in my case, i was using both reddcoin and vertcoin.
in my testing,
Add widget
select current price -> add
search redd or vert -> go
select the result

it is at this point the app will close for both these items ( i didnt check others)
selecting other coins bitcoin, litecoin and doge works as expected

from what i could tell, there was a attempt to reuse the last created widgets exchange,
if the coin was not avaulable on that exchange (eg binance) it would fall through to getdefaultexchange
returns exchanges?.get(0) — the first exchange in the list for that currency.
Based on the available JSON and ordering, for reddcoin and vertcoin that was COINDESK (not COINGECKO).

COINDESK is in the available json, but it is not in the exchange enum

@hwki
Copy link
Copy Markdown
Owner

hwki commented Mar 29, 2026

Ok, that makes sense now. The real reason this is coming up is that when I removed exchanges like CoinDesk, I neglected to remove them from the json file as well. I'll merge this, in case it happens again but ideally it shouldn't.

@hwki hwki merged commit 125da43 into hwki:master Mar 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants