Skip to content

Commit 2e8f25f

Browse files
committed
Fix ConcurrentModificationException and NullPointerException
1 parent 97ff76e commit 2e8f25f

File tree

5 files changed

+13
-6
lines changed

5 files changed

+13
-6
lines changed

common/build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ kotlin {
135135
/** ----------------------------------------------------------------------------------------- */
136136

137137
/** --- Misc. ------------------------------------------------------------------------------ */
138+
api(libs.stately.concurrent.collections)
138139
api(libs.sqldelight.coroutines.extensions)
139140
api(libs.kmp.observableviewmodel)
140141
api(libs.uri.kmp)
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package com.blockstream.common.extensions
22

3-
fun <K, V> LinkedHashMap<K, V>.toSortedLinkedHashMap(comparator: Comparator<K>): LinkedHashMap<K, V> {
3+
fun <K, V> MutableMap<K, V>.toSortedLinkedHashMap(comparator: Comparator<K>): LinkedHashMap<K, V> {
44
val sorted = linkedMapOf<K, V>()
55

66
keys.sortedWith(comparator).forEach { k ->
@@ -10,4 +10,4 @@ fun <K, V> LinkedHashMap<K, V>.toSortedLinkedHashMap(comparator: Comparator<K>):
1010
}
1111

1212
return sorted
13-
}
13+
}

common/src/commonMain/kotlin/com/blockstream/common/gdk/GdkSession.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import breez_sdk.InvoicePaidDetails
66
import breez_sdk.LnUrlPayResult
77
import breez_sdk.ReceivePaymentResponse
88
import breez_sdk.SwapInfo
9+
import co.touchlab.stately.collections.ConcurrentMutableMap
910
import com.blockstream.common.BTC_POLICY_ASSET
1011
import com.blockstream.common.BTC_UNIT
1112
import com.blockstream.common.CountlyBase
@@ -376,7 +377,7 @@ class GdkSession constructor(
376377

377378
val activeSinglesig get() = listOfNotNull(activeBitcoinSinglesig, activeLiquidSinglesig)
378379

379-
val gdkSessions = linkedMapOf<Network, GASession>()
380+
val gdkSessions: ConcurrentMutableMap<Network, GASession> = ConcurrentMutableMap()
380381
val activeSessions = mutableSetOf<Network>()
381382

382383
fun hasActiveNetwork(network: Network?) = activeSessions.contains(network)

common/src/commonMain/kotlin/com/blockstream/common/models/lightning/LnUrlWithdrawViewModel.kt

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import com.blockstream.common.events.Event
2222
import com.blockstream.common.events.Events
2323
import com.blockstream.common.extensions.logException
2424
import com.blockstream.common.extensions.previewWallet
25+
import com.blockstream.common.extensions.tryCatch
2526
import com.blockstream.common.lightning.domain
2627
import com.blockstream.common.lightning.maxReceivableSatoshi
2728
import com.blockstream.common.lightning.maxWithdrawableSatoshi
@@ -32,8 +33,8 @@ import com.blockstream.common.utils.Loggable
3233
import com.blockstream.common.utils.StringHolder
3334
import com.blockstream.common.utils.UserInput
3435
import com.blockstream.common.utils.toAmountLook
35-
import com.rickclephas.kmp.observableviewmodel.coroutineScope
3636
import com.rickclephas.kmp.nativecoroutines.NativeCoroutinesState
37+
import com.rickclephas.kmp.observableviewmodel.coroutineScope
3738
import com.rickclephas.kmp.observableviewmodel.launch
3839
import kotlinx.coroutines.flow.MutableStateFlow
3940
import kotlinx.coroutines.flow.StateFlow
@@ -125,8 +126,10 @@ class LnUrlWithdrawViewModel(greenWallet: GreenWallet, val requestData: LnUrlWit
125126
}
126127

127128
amount.onEach {
128-
updateExchange()
129-
check()
129+
tryCatch {
130+
updateExchange()
131+
check()
132+
}
130133
}.launchIn(viewModelScope.coroutineScope)
131134

132135
combine(session.lightningSdk.nodeInfoStateFlow, denomination) { nodeState, denomination ->

gradle/libs.versions.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ android-gradle-plugin = "8.7.3"
1616
androidCompileSdk = "34"
1717
androidTargetSdk = "34"
1818
androidMinSdk = "24"
19+
statelyConcurrentCollections = "2.1.0"
1920
buildTools = "34.0.0"
2021
breez = "0.6.6"
2122
androidx-junit = "1.2.1"
@@ -93,6 +94,7 @@ phosphor-icon = { module = "com.adamglin:phosphor-icon", version.ref = "phosphor
9394
tuulbox-coroutines = { module = "com.juul.tuulbox:coroutines", version.ref = "tuulbox-coroutines" }
9495
desugar = { module = "com.android.tools:desugar_jdk_libs", version.ref = "desugar" }
9596
android-gradle-plugin = { module = "com.android.tools.build:gradle", version.ref = "android-gradle-plugin" }
97+
stately-concurrent-collections = { module = "co.touchlab:stately-concurrent-collections", version.ref = "statelyConcurrentCollections" }
9698
androidx-biometric = { module = "androidx.biometric:biometric", version.ref = "biometric" }
9799
androidx-browser = { module = "androidx.browser:browser", version.ref = "browser" }
98100
androidx-appcompat = { module = "androidx.appcompat:appcompat", version.ref = "appcompat" }

0 commit comments

Comments
 (0)