Skip to content

Commit 7bc1869

Browse files
authored
Merge pull request #875 from synonymdev/fix/crash-return-foreground
fix: crash when returning to foreground
2 parents 4945e47 + 2f70434 commit 7bc1869

5 files changed

Lines changed: 32 additions & 5 deletions

File tree

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
### Fixed
11+
- Fix crash when returning app to foreground on Receive screen #875
12+
- Show loading state on Spending tab when node is not running #875
13+
1014
### Added
1115
- Lightning Connections empty state with onboarding screen #857
1216
- Unified PIN management screen (enable/disable/change in one place) #857

app/src/main/java/to/bitkit/ui/screens/wallets/activity/components/CustomTabRowWithSpacing.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,9 @@ fun <T : TabItem> CustomTabRowWithSpacing(
3939
horizontalArrangement = Arrangement.SpaceEvenly,
4040
modifier = Modifier.fillMaxWidth()
4141
) {
42+
val safeIndex = currentTabIndex.coerceIn(0, tabs.lastIndex)
4243
tabs.forEachIndexed { index, tab ->
43-
val isSelected = tabs[currentTabIndex] == tab
44+
val isSelected = tabs[safeIndex] == tab
4445

4546
Column(
4647
modifier = Modifier.weight(1f)

app/src/main/java/to/bitkit/ui/screens/wallets/receive/ReceiveInvoiceUtils.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@ fun getInvoiceForTab(
3232
}
3333

3434
ReceiveTab.SPENDING -> {
35-
// Lightning only: prefer CJIT > bolt11
35+
// Lightning only: prefer CJIT > bolt11, empty when node is not running
3636
cjitInvoice?.takeIf { it.isNotEmpty() && isNodeRunning }
37-
?: bolt11
37+
?: bolt11.takeIf { isNodeRunning }.orEmpty()
3838
}
3939
}
4040
}

app/src/main/java/to/bitkit/ui/screens/wallets/receive/ReceiveQrScreen.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,12 @@ fun ReceiveQrScreen(
145145
mutableStateOf(initialTab ?: ReceiveTab.SAVINGS)
146146
}
147147

148+
LaunchedEffect(visibleTabs) {
149+
if (selectedTab !in visibleTabs) {
150+
selectedTab = visibleTabs.first()
151+
}
152+
}
153+
148154
LaunchedEffect(lazyListState, visibleTabs.size) {
149155
snapshotFlow { lazyListState.firstVisibleItemIndex }
150156
.distinctUntilChanged()

app/src/test/java/to/bitkit/ui/screens/wallets/receive/ReceiveInvoiceUtilsTest.kt

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ class ReceiveInvoiceUtilsTest {
200200
}
201201

202202
@Test
203-
fun `getInvoiceForTab SPENDING returns bolt11 when node not running even with CJIT`() {
203+
fun `getInvoiceForTab SPENDING returns empty when node not running even with CJIT`() {
204204
val bip21 = "bitcoin:$testAddress?lightning=$testBolt11"
205205

206206
val result = getInvoiceForTab(
@@ -212,7 +212,23 @@ class ReceiveInvoiceUtilsTest {
212212
onchainAddress = testAddress
213213
)
214214

215-
assertEquals(testBolt11, result)
215+
assertEquals("", result)
216+
}
217+
218+
@Test
219+
fun `getInvoiceForTab SPENDING returns empty when node not running and no CJIT`() {
220+
val bip21 = "bitcoin:$testAddress?lightning=$testBolt11"
221+
222+
val result = getInvoiceForTab(
223+
tab = ReceiveTab.SPENDING,
224+
bip21 = bip21,
225+
bolt11 = testBolt11,
226+
cjitInvoice = null,
227+
isNodeRunning = false,
228+
onchainAddress = testAddress
229+
)
230+
231+
assertEquals("", result)
216232
}
217233

218234
@Test

0 commit comments

Comments
 (0)