Skip to content

Commit 29fdd32

Browse files
committed
fix: handle pubky send input
1 parent 17c7256 commit 29fdd32

2 files changed

Lines changed: 30 additions & 0 deletions

File tree

app/src/main/java/to/bitkit/viewmodels/AppViewModel.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -939,6 +939,11 @@ class AppViewModel @Inject constructor(
939939
// Skip validation for empty input
940940
if (valueWithoutSpaces.isEmpty()) return
941941

942+
if (PubkyPublicKeyFormat.normalized(valueWithoutSpaces) != null) {
943+
_sendUiState.update { it.copy(isAddressInputValid = true) }
944+
return
945+
}
946+
942947
// Start debounced validation
943948
addressValidationJob = viewModelScope.launch {
944949
delay(ADDRESS_VALIDATION_DEBOUNCE_MS)
@@ -1420,6 +1425,7 @@ class AppViewModel @Inject constructor(
14201425

14211426
if (route != null) {
14221427
clearActiveContactPaymentContext()
1428+
if (currentSheet.value is Sheet.Send) hideSheet()
14231429
mainScreenEffect(MainScreenEffect.Navigate(route))
14241430
return@withContext
14251431
}

app/src/test/java/to/bitkit/viewmodels/AppViewModelSendFlowTest.kt

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import org.mockito.kotlin.any
1818
import org.mockito.kotlin.anyOrNull
1919
import org.mockito.kotlin.clearInvocations
2020
import org.mockito.kotlin.mock
21+
import org.mockito.kotlin.never
2122
import org.mockito.kotlin.verify
2223
import org.mockito.kotlin.whenever
2324
import to.bitkit.data.AppCacheData
@@ -232,6 +233,29 @@ class AppViewModelSendFlowTest : BaseUnitTest() {
232233
}
233234
}
234235

236+
@Test
237+
fun `manual address input accepts pubky without decode error`() = test {
238+
sut.setSendEvent(SendEvent.AddressChange(testPublicKey))
239+
advanceUntilIdle()
240+
241+
assertEquals(testPublicKey, sut.sendUiState.value.addressInput)
242+
assertTrue(sut.sendUiState.value.isAddressInputValid)
243+
verify(coreService, never()).decode(any())
244+
}
245+
246+
@Test
247+
fun `pubky routing dismisses send sheet before navigation`() = test {
248+
sut.showSheet(Sheet.Send())
249+
advanceUntilIdle()
250+
251+
sut.mainScreenEffect.test {
252+
sut.setSendEvent(SendEvent.AddressContinue(testPublicKey))
253+
254+
assertEquals(MainScreenEffect.Navigate(Routes.AddContact(testPublicKey)), awaitItem())
255+
assertNull(sut.currentSheet.value)
256+
}
257+
}
258+
235259
@Test
236260
fun `canSwitchWallet is false when amount exceeds lightning balance`() = test {
237261
balanceState.value = BalanceState(

0 commit comments

Comments
 (0)