From 8edd142cd629caef6d962103527cbe57cdd4649a Mon Sep 17 00:00:00 2001 From: Joao Victor Sena Date: Sun, 29 Nov 2026 17:30:08 -0300 Subject: [PATCH 01/38] refactor: remove pay on watch from the phone's send review Co-Authored-By: Claude Opus 5.5 --- .../to/bitkit/repositories/WatchLinkRepo.kt | 76 ----- .../ui/screens/wallets/send/PayOnWatch.kt | 97 ------- .../wallets/send/PayOnWatchViewModel.kt | 59 ---- .../screens/wallets/send/SendConfirmScreen.kt | 29 -- .../java/to/bitkit/ui/sheets/SendSheet.kt | 7 - app/src/main/res/values-ar/strings.xml | 5 - app/src/main/res/values-b+es+419/strings.xml | 5 - app/src/main/res/values-ca/strings.xml | 5 - app/src/main/res/values-cs/strings.xml | 5 - app/src/main/res/values-de/strings.xml | 5 - app/src/main/res/values-el/strings.xml | 5 - app/src/main/res/values-es-rES/strings.xml | 5 - app/src/main/res/values-es/strings.xml | 5 - app/src/main/res/values-fr/strings.xml | 5 - app/src/main/res/values-it/strings.xml | 5 - app/src/main/res/values-nl/strings.xml | 5 - app/src/main/res/values-pl/strings.xml | 5 - app/src/main/res/values-pt-rBR/strings.xml | 5 - app/src/main/res/values-pt/strings.xml | 5 - app/src/main/res/values-ru/strings.xml | 5 - app/src/main/res/values/strings.xml | 5 - .../bitkit/repositories/WatchLinkRepoTest.kt | 131 --------- .../wallets/send/PayOnWatchInputTest.kt | 117 -------- .../wallets/send/PayOnWatchViewModelTest.kt | 61 ---- docs/wear.md | 49 +--- journeys/README.md | 4 +- journeys/wear/README.md | 17 +- journeys/wear/pay-request-from-phone.xml | 33 --- wear/src/main/AndroidManifest.xml | 9 +- .../java/to/bitkit/wear/data/HandoffStore.kt | 73 ----- .../bitkit/wear/repositories/PhoneLinkRepo.kt | 28 +- .../main/java/to/bitkit/wear/ui/LaunchGate.kt | 34 +-- .../java/to/bitkit/wear/ui/LaunchRequest.kt | 36 +-- .../java/to/bitkit/wear/ui/MainActivity.kt | 1 - .../src/main/java/to/bitkit/wear/ui/Routes.kt | 11 +- .../java/to/bitkit/wear/ui/WearNavHost.kt | 29 +- .../wear/ui/screens/send/SendViewModel.kt | 10 +- .../to/bitkit/wear/link/PhoneLinkRepoTest.kt | 89 +----- .../java/to/bitkit/wear/ui/LaunchGateTest.kt | 93 +----- .../to/bitkit/wear/ui/LaunchRequestTest.kt | 54 ---- .../wear/ui/screens/send/SendViewModelTest.kt | 19 -- .../kotlin/to/bitkit/wearlink/LinkDocs.kt | 25 -- .../to/bitkit/wearlink/LinkEndpoints.kt | 61 ---- .../kotlin/to/bitkit/wearlink/LinkHandoff.kt | 62 ---- .../to/bitkit/wearlink/LinkTransport.kt | 14 - .../to/bitkit/wearlink/LinkHandoffTest.kt | 265 ------------------ .../kotlin/to/bitkit/wearlink/LinkHarness.kt | 9 - 47 files changed, 31 insertions(+), 1651 deletions(-) delete mode 100644 app/src/main/java/to/bitkit/ui/screens/wallets/send/PayOnWatch.kt delete mode 100644 app/src/main/java/to/bitkit/ui/screens/wallets/send/PayOnWatchViewModel.kt delete mode 100644 app/src/test/java/to/bitkit/ui/screens/wallets/send/PayOnWatchInputTest.kt delete mode 100644 app/src/test/java/to/bitkit/ui/screens/wallets/send/PayOnWatchViewModelTest.kt delete mode 100644 journeys/wear/pay-request-from-phone.xml delete mode 100644 wear/src/main/java/to/bitkit/wear/data/HandoffStore.kt delete mode 100644 wearlink/src/main/kotlin/to/bitkit/wearlink/LinkHandoff.kt delete mode 100644 wearlink/src/test/kotlin/to/bitkit/wearlink/LinkHandoffTest.kt diff --git a/app/src/main/java/to/bitkit/repositories/WatchLinkRepo.kt b/app/src/main/java/to/bitkit/repositories/WatchLinkRepo.kt index d8ca2a092a..510992b2a2 100644 --- a/app/src/main/java/to/bitkit/repositories/WatchLinkRepo.kt +++ b/app/src/main/java/to/bitkit/repositories/WatchLinkRepo.kt @@ -17,7 +17,6 @@ import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.CoroutineStart import kotlinx.coroutines.Job import kotlinx.coroutines.SupervisorJob -import kotlinx.coroutines.async import kotlinx.coroutines.coroutineScope import kotlinx.coroutines.ensureActive import kotlinx.coroutines.flow.Flow @@ -25,18 +24,14 @@ import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.StateFlow import kotlinx.coroutines.flow.asStateFlow import kotlinx.coroutines.flow.catch -import kotlinx.coroutines.flow.channelFlow import kotlinx.coroutines.flow.collectLatest import kotlinx.coroutines.flow.combine import kotlinx.coroutines.flow.distinctUntilChanged -import kotlinx.coroutines.flow.filter import kotlinx.coroutines.flow.first -import kotlinx.coroutines.flow.flowOn import kotlinx.coroutines.flow.map import kotlinx.coroutines.flow.update import kotlinx.coroutines.launch import kotlinx.coroutines.withContext -import kotlinx.coroutines.withTimeoutOrNull import kotlinx.datetime.TimeZone import kotlinx.datetime.toLocalDateTime import to.bitkit.data.AppCacheData @@ -54,20 +49,16 @@ import to.bitkit.utils.Logger import to.bitkit.wearlink.AttestationPolicy import to.bitkit.wearlink.AttestationStatusList import to.bitkit.wearlink.AttestationVerifier -import to.bitkit.wearlink.HandoffInbox import to.bitkit.wearlink.LinkCrypto import to.bitkit.wearlink.LinkGuards -import to.bitkit.wearlink.LinkHandoff import to.bitkit.wearlink.LinkKeyStore import to.bitkit.wearlink.LinkNode import to.bitkit.wearlink.LinkPacket -import to.bitkit.wearlink.LinkPaths import to.bitkit.wearlink.LinkRecord import to.bitkit.wearlink.LinkTransport import to.bitkit.wearlink.OpenSend import to.bitkit.wearlink.PairingState import to.bitkit.wearlink.PairingThrottle -import to.bitkit.wearlink.PayResult import to.bitkit.wearlink.PeerInvoice import to.bitkit.wearlink.PeerStateListener import to.bitkit.wearlink.PhoneLink @@ -78,11 +69,9 @@ import to.bitkit.wearlink.SeedPayload import to.bitkit.wearlink.SettingsDoc import to.bitkit.wearlink.WalletLink import java.io.ByteArrayOutputStream -import java.security.SecureRandom import javax.inject.Inject import javax.inject.Singleton import kotlin.time.Clock -import kotlin.time.Duration.Companion.milliseconds import kotlin.time.Duration.Companion.seconds import kotlin.time.ExperimentalTime @@ -140,9 +129,6 @@ class WatchLinkRepo internal constructor( /** The Play listing of an app, completed with its application id. */ private const val MARKET_URI = "market://details?id=" - /** How long the phone waits for the watch to answer a handed-off request before it calls it unreachable. */ - private val HANDOFF_ANSWER_TIMEOUT = 10.seconds - /** * Reads Google's attestation status list: one GET of a public file that is the same for everyone. The * request names no user, wallet or watch. A response longer than the list may be is refused by its @@ -389,61 +375,6 @@ class WatchLinkRepo internal constructor( .onFailure { Logger.warn("Failed to open the Play listing on the watch", it, context = TAG) } } - /** Whether the paired watch, with Bitkit, is connected to this phone now. */ - suspend fun isWatchReachable(): Boolean = withContext(ioDispatcher) { - runSuspendCatching { - val record = store.load()?.takeIf { it.removal == null } ?: return@runSuspendCatching false - transport.nodes().any { it.id == record.peerNodeId && it.hasApp } - }.onFailure { Logger.warn("Failed to look for the paired watch", it, context = TAG) }.getOrDefault(false) - } - - /** - * Hands the payment request [input] to the paired watch, to be reviewed and held to pay there, never under - * QuickPay (`docs/wear.md`, Pairing › Payment handoff). The request goes over the link as a one-shot message; - * once the watch kept it, the phone opens its link on the watch, which names only the request's id. Emits what - * became of it: [PayOnWatchResult.Sent], [PayOnWatchResult.Busy], [PayOnWatchResult.Refused] when the watch - * answered that it does not take it, or [PayOnWatchResult.Unreachable] when it could not be reached or did not - * answer; and after a [PayOnWatchResult.Sent] a later [PayOnWatchResult.Busy] or [PayOnWatchResult.Refused] when - * the watch dropped it, for a send under way or because it could not show it. Neither the request nor its input - * is logged. - */ - @OptIn(ExperimentalStdlibApi::class) - fun payOnWatch(input: String): Flow = channelFlow { - val id = ByteArray(LinkHandoff.ID_CHARS / 2).also(SecureRandom()::nextBytes).toHexString() - val answers = link.payResults.filter { it.id == id } - val answer = async(start = CoroutineStart.UNDISPATCHED) { - withTimeoutOrNull(HANDOFF_ANSWER_TIMEOUT) { answers.first() } - } - val sent = runSuspendCatching { link.requestPay(id, input) } - .onFailure { Logger.warn("Failed to hand a payment request to the watch", it, context = TAG) } - if (sent.isFailure) { - answer.cancel() - send(PayOnWatchResult.Unreachable) - return@channelFlow - } - val result = answer.await()?.result - Logger.info("Handed a payment request to the watch, which answered '$result'", context = TAG) - when (result) { - PayResult.Busy -> send(PayOnWatchResult.Busy) - PayResult.Received -> { - val opened = runSuspendCatching { link.openOnWatch(LinkPaths.payUri(id)) } - .onFailure { Logger.warn("Failed to open the handed-off request on the watch", it, context = TAG) } - if (opened.isFailure) { - send(PayOnWatchResult.Unreachable) - return@channelFlow - } - send(PayOnWatchResult.Sent) - val dropped = withTimeoutOrNull(HandoffInbox.WINDOW_MS.milliseconds) { - answers.first { it.result != PayResult.Received } - } ?: return@channelFlow - Logger.info("Heard the watch dropped the handed-off request as '${dropped.result}'", context = TAG) - send(if (dropped.result == PayResult.Busy) PayOnWatchResult.Busy else PayOnWatchResult.Refused) - } - PayResult.Refused -> send(PayOnWatchResult.Refused) - null -> send(PayOnWatchResult.Unreachable) - } - }.flowOn(ioDispatcher) - /** * Ends the pairing that runs, as when its screen goes away, and forgets the last one's end. A pairing that has * not found the watch yet ends without opening anything on it. @@ -587,13 +518,6 @@ sealed interface WatchPairingStatus { data class Failed(val error: Throwable) : WatchPairingStatus } -/** - * What became of a payment request handed to the watch: the one line the send review shows. [Refused] when the watch - * was reached and answered that it does not take the request, or dropped it where it could not show it; - * [Unreachable] when it was not reached or did not answer. - */ -enum class PayOnWatchResult { Sent, Busy, Refused, Unreachable } - sealed class WatchLinkError(message: String) : AppError(message) { /** No connected watch has Bitkit and is reached directly. */ class NoWatch : WatchLinkError("No watch with Bitkit is connected nearby") diff --git a/app/src/main/java/to/bitkit/ui/screens/wallets/send/PayOnWatch.kt b/app/src/main/java/to/bitkit/ui/screens/wallets/send/PayOnWatch.kt deleted file mode 100644 index 690fac4230..0000000000 --- a/app/src/main/java/to/bitkit/ui/screens/wallets/send/PayOnWatch.kt +++ /dev/null @@ -1,97 +0,0 @@ -package to.bitkit.ui.screens.wallets.send - -import androidx.compose.foundation.layout.Column -import androidx.compose.foundation.layout.size -import androidx.compose.material3.Icon -import androidx.compose.runtime.Composable -import androidx.compose.runtime.LaunchedEffect -import androidx.compose.runtime.getValue -import androidx.compose.ui.Alignment -import androidx.compose.ui.Modifier -import androidx.compose.ui.platform.testTag -import androidx.compose.ui.res.painterResource -import androidx.compose.ui.res.stringResource -import androidx.compose.ui.text.style.TextAlign -import androidx.compose.ui.tooling.preview.Preview -import androidx.compose.ui.unit.dp -import androidx.hilt.lifecycle.viewmodel.compose.hiltViewModel -import androidx.lifecycle.compose.collectAsStateWithLifecycle -import to.bitkit.R -import to.bitkit.repositories.PayOnWatchResult -import to.bitkit.ui.components.BodyS -import to.bitkit.ui.components.ButtonSize -import to.bitkit.ui.components.SecondaryButton -import to.bitkit.ui.components.VerticalSpacer -import to.bitkit.ui.theme.AppThemeSurface -import to.bitkit.ui.theme.Colors - -/** - * The send review's secondary action for a Lightning request while the paired watch is reachable: it hands [input] - * to the watch, which shows its review and asks for its hold to pay, and then shows one line of what became of it. - */ -@Composable -fun PayOnWatch( - input: String, - modifier: Modifier = Modifier, - viewModel: PayOnWatchViewModel = hiltViewModel(), -) { - val uiState by viewModel.uiState.collectAsStateWithLifecycle() - LaunchedEffect(viewModel) { viewModel.refresh() } - if (!uiState.isAvailable) return - Content( - uiState = uiState, - onClick = { viewModel.onPayOnWatchClick(input) }, - modifier = modifier, - ) -} - -@Composable -private fun Content( - uiState: PayOnWatchUiState, - modifier: Modifier = Modifier, - onClick: () -> Unit = {}, -) { - Column(horizontalAlignment = Alignment.CenterHorizontally, modifier = modifier) { - SecondaryButton( - text = stringResource(R.string.wallet__send_pay_on_watch), - onClick = onClick, - icon = { - Icon( - painter = painterResource(R.drawable.ic_watch), - contentDescription = null, - tint = Colors.Purple, - modifier = Modifier.size(16.dp) - ) - }, - isLoading = uiState.isSending, - size = ButtonSize.Small, - fullWidth = false, - testTag = "SendPayOnWatch", - ) - uiState.result?.let { result -> - VerticalSpacer(8.dp) - BodyS( - text = stringResource( - when (result) { - PayOnWatchResult.Sent -> R.string.wallet__send_pay_on_watch_sent - PayOnWatchResult.Busy -> R.string.wallet__send_pay_on_watch_busy - PayOnWatchResult.Refused -> R.string.wallet__send_pay_on_watch_refused - PayOnWatchResult.Unreachable -> R.string.wallet__send_pay_on_watch_unreachable - }, - ), - color = if (result == PayOnWatchResult.Sent) Colors.White64 else Colors.Red, - textAlign = TextAlign.Center, - modifier = Modifier.testTag("SendPayOnWatchResult") - ) - } - VerticalSpacer(8.dp) - } -} - -@Preview(showBackground = true) -@Composable -private fun Preview() { - AppThemeSurface { - Content(uiState = PayOnWatchUiState(isAvailable = true, result = PayOnWatchResult.Sent)) - } -} diff --git a/app/src/main/java/to/bitkit/ui/screens/wallets/send/PayOnWatchViewModel.kt b/app/src/main/java/to/bitkit/ui/screens/wallets/send/PayOnWatchViewModel.kt deleted file mode 100644 index ab5d368469..0000000000 --- a/app/src/main/java/to/bitkit/ui/screens/wallets/send/PayOnWatchViewModel.kt +++ /dev/null @@ -1,59 +0,0 @@ -package to.bitkit.ui.screens.wallets.send - -import androidx.compose.runtime.Immutable -import androidx.lifecycle.ViewModel -import androidx.lifecycle.viewModelScope -import dagger.hilt.android.lifecycle.HiltViewModel -import kotlinx.coroutines.Job -import kotlinx.coroutines.flow.MutableStateFlow -import kotlinx.coroutines.flow.StateFlow -import kotlinx.coroutines.flow.asStateFlow -import kotlinx.coroutines.flow.update -import kotlinx.coroutines.launch -import to.bitkit.repositories.PayOnWatchResult -import to.bitkit.repositories.WatchLinkRepo -import javax.inject.Inject - -/** - * Pay on Watch on the send review: offered for a Lightning request while the paired watch is reachable, it hands the - * request to the watch, which reviews it and asks for its hold to pay (`docs/wear.md`, Pairing › Payment handoff). - * Only created while the watch link is enabled. - */ -@HiltViewModel -class PayOnWatchViewModel @Inject constructor( - private val watchLinkRepo: WatchLinkRepo, -) : ViewModel() { - private val _uiState = MutableStateFlow(PayOnWatchUiState()) - val uiState: StateFlow = _uiState.asStateFlow() - - private var handoff: Job? = null - - /** Looks whether the paired watch is reachable, as the review shows. */ - fun refresh() { - viewModelScope.launch { - val isAvailable = watchLinkRepo.isWatchReachable() - _uiState.update { it.copy(isAvailable = isAvailable) } - } - } - - /** Hands [input], the request under review, to the watch; a tap while one is on its way does nothing. */ - fun onPayOnWatchClick(input: String) { - if (_uiState.value.isSending) return - handoff?.cancel() - _uiState.update { it.copy(isSending = true, result = null) } - handoff = viewModelScope.launch { - watchLinkRepo.payOnWatch(input).collect { result -> - _uiState.update { it.copy(isSending = false, result = result) } - } - _uiState.update { it.copy(isSending = false) } - } - } -} - -/** [isAvailable] while the paired watch is reachable; [result] is the one line shown after a tap. */ -@Immutable -data class PayOnWatchUiState( - val isAvailable: Boolean = false, - val isSending: Boolean = false, - val result: PayOnWatchResult? = null, -) diff --git a/app/src/main/java/to/bitkit/ui/screens/wallets/send/SendConfirmScreen.kt b/app/src/main/java/to/bitkit/ui/screens/wallets/send/SendConfirmScreen.kt index 9913cc5b26..509a556446 100644 --- a/app/src/main/java/to/bitkit/ui/screens/wallets/send/SendConfirmScreen.kt +++ b/app/src/main/java/to/bitkit/ui/screens/wallets/send/SendConfirmScreen.kt @@ -147,7 +147,6 @@ fun SendConfirmScreen( onLockChange: (Boolean) -> Unit = {}, syncNodeVariant: SyncNodeVariant = SyncNodeVariant.LIGHTNING, autoPayContent: (@Composable () -> Unit)? = null, - payOnWatchContent: (@Composable (String) -> Unit)? = null, ) { val scope = rememberCoroutineScope() var isLoading by rememberSaveable { mutableStateOf(false) } @@ -226,7 +225,6 @@ fun SendConfirmScreen( syncNodeVariant = syncNodeVariant, initialShowDetails = uiState.isInitialSubscriptionPayment && !uiState.shouldAutomaticallyPay, autoPayContent = autoPayContent, - payOnWatchContent = payOnWatchContent, onBack = onBack, onEvent = onEvent, onClickAddTag = onClickAddTag, @@ -308,7 +306,6 @@ internal fun SendConfirmContent( initialShowDetails: Boolean = false, syncNodeVariant: SyncNodeVariant = SyncNodeVariant.LIGHTNING, autoPayContent: (@Composable () -> Unit)? = null, - payOnWatchContent: (@Composable (String) -> Unit)? = null, onBack: () -> Unit = {}, onEvent: (SendEvent) -> Unit = {}, onClickAddTag: () -> Unit = {}, @@ -366,7 +363,6 @@ internal fun SendConfirmContent( preparingRequest = preparingRequest, preparingContact = preparingContact, initialShowDetails = initialShowDetails, - payOnWatchContent = payOnWatchContent.takeIf { !isLocked && !isLoading }, // The payment's inputs stay as swiped while the swipe runs onEvent = { if (!isLocked) onEvent(it) }, onClickAddTag = { if (!isLocked) onClickAddTag() }, @@ -425,7 +421,6 @@ private fun ContentRunning( preparingRequest: PaykitPaymentRequest? = null, preparingContact: PubkyProfile? = null, initialShowDetails: Boolean = false, - payOnWatchContent: (@Composable (String) -> Unit)? = null, onEvent: (SendEvent) -> Unit = {}, onClickAddTag: () -> Unit = {}, onClickTag: (String) -> Unit = {}, @@ -550,11 +545,6 @@ private fun ContentRunning( } } - val payOnWatchInput = uiState.payOnWatchInput().takeIf { !isPreparing } - if (payOnWatchContent != null && payOnWatchInput != null) { - Box(modifier = Modifier.align(Alignment.CenterHorizontally)) { payOnWatchContent(payOnWatchInput) } - } - if ((!isLnurlPay || uiState.isPaymentRequest) && !isPreparing) { PrimaryButton( text = stringResource( @@ -1019,25 +1009,6 @@ private val SendUiState.paysLnurl: Boolean get() = lnurl is LnurlParams.LnurlPay && payMethod == SendMethod.LIGHTNING && routedPaykitRoute?.serviceLeg == null && activePaykitSwapRoute == null -/** - * The BOLT11 invoice the paired watch can be handed to pay, or null: the invoice of a plain Lightning send from the - * wallet that carries its amount. Not an invoice without an amount, since only the invoice is handed over and the - * amount typed on the phone would be lost; nor an LNURL, a contact's payment request or one that goes over a Spark - * leg or a swap instead of the invoice, a subscription or a hardware wallet's send. - */ -internal fun SendUiState.payOnWatchInput(): String? = decodedInvoice?.takeIf { - it.bolt11.isNotBlank() && - it.amountSatoshis > 0uL && - payMethod == SendMethod.LIGHTNING && - !paysLnurl && - routedPaykitRoute?.serviceLeg == null && - activePaykitSwapRoute == null && - !isPaymentRequest && - !isSubscriptionPayment && - !isInitialSubscriptionPayment && - hardwareWalletId == null -}?.bolt11 - private val SendUiState.confirmationRequestNote: String? get() = paymentRequestNote?.trim()?.takeIf { isPaymentRequest && it.isNotEmpty() } diff --git a/app/src/main/java/to/bitkit/ui/sheets/SendSheet.kt b/app/src/main/java/to/bitkit/ui/sheets/SendSheet.kt index f24e612906..df8dfbe392 100644 --- a/app/src/main/java/to/bitkit/ui/sheets/SendSheet.kt +++ b/app/src/main/java/to/bitkit/ui/sheets/SendSheet.kt @@ -41,7 +41,6 @@ import kotlinx.coroutines.isActive import kotlinx.coroutines.launch import kotlinx.serialization.Serializable import to.bitkit.R -import to.bitkit.env.Env import to.bitkit.ext.getSatsPerVByteFor import to.bitkit.ext.supportPaymentRequest import to.bitkit.ext.toSendFailureDetails @@ -71,7 +70,6 @@ import to.bitkit.ui.screens.wallets.send.AddTagScreen import to.bitkit.ui.screens.wallets.send.HwSendSignScreen import to.bitkit.ui.screens.wallets.send.HwSendViewModel import to.bitkit.ui.screens.wallets.send.PIN_CHECK_RESULT_KEY -import to.bitkit.ui.screens.wallets.send.PayOnWatch import to.bitkit.ui.screens.wallets.send.RECOVERY_PIN_CHECK_RESULT_KEY import to.bitkit.ui.screens.wallets.send.SEND_CONFIRM_RESET_RESULT_KEY import to.bitkit.ui.screens.wallets.send.SendAddressScreen @@ -608,11 +606,6 @@ fun SendSheet( onNavigateToPin = { navController.navigateTo(SendRoute.PinCheck) }, isSwipeRunning = isSwipeRunning, onLockChange = onConfirmLockChange, - payOnWatchContent = if (Env.isWatchLinkEnabled) { - { input -> PayOnWatch(input = input) } - } else { - null - }, autoPayContent = initialSubscription?.let { subscription -> { SubscriptionFirstPaymentProgress( diff --git a/app/src/main/res/values-ar/strings.xml b/app/src/main/res/values-ar/strings.xml index 099ad2db9d..0995358411 100644 --- a/app/src/main/res/values-ar/strings.xml +++ b/app/src/main/res/values-ar/strings.xml @@ -1243,11 +1243,6 @@ انتهاء صلاحية الفاتورة الحد الأقصى القابل للإنفاق أقل قليلاً بسبب الرصيد الاحتياطي المطلوب. الرصيد الاحتياطي - ادفع على الساعة - ساعتك مشغولة بدفعة أخرى. - تعذّر على ساعتك استلام هذه الدفعة. - أُرسل إلى ساعتك. اضغط مطولًا هناك للدفع. - تعذّر الوصول إلى ساعتك. ليس لدى جهة الاتصال هذه أي طريقة دفع يمكن لـ Bitkit استخدامها الآن. لا يمكن الدفع لجهة الاتصال هذه لا يزال سحب سابق من رصيد الإنفاق قيد التسوية. حاول مرة أخرى بعد اكتماله. diff --git a/app/src/main/res/values-b+es+419/strings.xml b/app/src/main/res/values-b+es+419/strings.xml index 0c2467dbbd..7f96c86fcb 100644 --- a/app/src/main/res/values-b+es+419/strings.xml +++ b/app/src/main/res/values-b+es+419/strings.xml @@ -1274,11 +1274,6 @@ Expiración de la factura La cantidad máxima que se puede gastar es un poco más baja debido al saldo de reserva exigido. Saldo de reserva - Pagar en el reloj - Tu reloj está ocupado con otro pago. - Tu reloj no pudo recibir este pago. - Enviado a tu reloj. Mantén presionado allí para pagar. - Tu reloj no está disponible. Este contacto no tiene ningún método de pago que Bitkit pueda usar ahora. No se puede pagar a este contacto Un retiro anterior de tu saldo para gastos aún se está liquidando. Inténtalo de nuevo cuando termine. diff --git a/app/src/main/res/values-ca/strings.xml b/app/src/main/res/values-ca/strings.xml index 376f1f2f8a..bb42a64e5c 100644 --- a/app/src/main/res/values-ca/strings.xml +++ b/app/src/main/res/values-ca/strings.xml @@ -1268,11 +1268,6 @@ Caducitat de la factura L\'import màxim gastable és una mica inferior a causa d\'un saldo de reserva requerit. Saldo de reserva - Paga al rellotge - El rellotge està ocupat amb un altre pagament. - El rellotge no ha pogut rebre aquest pagament. - Enviat al rellotge. Mantén premut allà per pagar. - El rellotge no és accessible. Aquest contacte no té cap mètode de pagament que Bitkit pugui fer servir ara. No es pot pagar aquest contacte Una retirada anterior del teu saldo de despesa encara s\'està liquidant. Torna-ho a provar quan es completi. diff --git a/app/src/main/res/values-cs/strings.xml b/app/src/main/res/values-cs/strings.xml index 5e9af241bc..09f7735658 100644 --- a/app/src/main/res/values-cs/strings.xml +++ b/app/src/main/res/values-cs/strings.xml @@ -1272,11 +1272,6 @@ Expirace faktury Maximální částka, kterou lze utratit, je o něco nižší kvůli požadovanému zůstatku rezervy. Zůstatek rezervy - Zaplatit na hodinkách - Hodinky zpracovávají jinou platbu. - Hodinky tuto platbu nemohly přijmout. - Odesláno do hodinek. Podržením na nich zaplatíte. - Hodinky nejsou dostupné. Tento kontakt nemá žádnou platební metodu, kterou by Bitkit mohl nyní použít. Tomuto kontaktu nelze zaplatit Dřívější výběr z vašeho zůstatku pro výdaje se stále vypořádává. Zkuste to znovu, až se dokončí. diff --git a/app/src/main/res/values-de/strings.xml b/app/src/main/res/values-de/strings.xml index 0d27bc288f..81284c900c 100644 --- a/app/src/main/res/values-de/strings.xml +++ b/app/src/main/res/values-de/strings.xml @@ -1107,11 +1107,6 @@ Senden Empfangen Bitcoin senden - Auf der Uhr zahlen - Deine Uhr ist mit einer anderen Zahlung beschäftigt. - Deine Uhr konnte diese Zahlung nicht annehmen. - An deine Uhr gesendet. Halte dort gedrückt, um zu zahlen. - Deine Uhr ist nicht erreichbar. Dieser Kontakt hat derzeit keine Zahlungsmethode, die Bitkit nutzen kann. Zahlung an diesen Kontakt nicht möglich Eine frühere Auszahlung von deinem Ausgabenguthaben wird noch abgewickelt. Versuche es erneut, sobald sie abgeschlossen ist. diff --git a/app/src/main/res/values-el/strings.xml b/app/src/main/res/values-el/strings.xml index 3f684bc1c4..6ac11cfd60 100644 --- a/app/src/main/res/values-el/strings.xml +++ b/app/src/main/res/values-el/strings.xml @@ -1248,11 +1248,6 @@ Λήξη τιμολογίου Το μέγιστο δαπανήσιμο ποσό είναι λίγο χαμηλότερο λόγω απαιτούμενου αποθεματικού υπολοίπου. Αποθεματικό υπόλοιπο - Πληρωμή στο ρολόι - Το ρολόι σας είναι απασχολημένο με άλλη πληρωμή. - Το ρολόι σας δεν μπόρεσε να δεχτεί αυτή την πληρωμή. - Στάλθηκε στο ρολόι σας. Πατήστε παρατεταμένα εκεί για πληρωμή. - Το ρολόι σας δεν είναι προσβάσιμο. Αυτή η επαφή δεν έχει τρόπο πληρωμής που μπορεί να χρησιμοποιήσει το Bitkit αυτή τη στιγμή. Δεν είναι δυνατή η πληρωμή αυτής της επαφής Μια προηγούμενη ανάληψη από το υπόλοιπο δαπανών σου διακανονίζεται ακόμη. Δοκίμασε ξανά μόλις ολοκληρωθεί. diff --git a/app/src/main/res/values-es-rES/strings.xml b/app/src/main/res/values-es-rES/strings.xml index 569abefc79..88abfccf3f 100644 --- a/app/src/main/res/values-es-rES/strings.xml +++ b/app/src/main/res/values-es-rES/strings.xml @@ -1269,11 +1269,6 @@ Expiración de la factura La cantidad máxima gastable es un poco menor debido a un saldo de reserva requerido. Saldo de reserva - Pagar en el reloj - Tu reloj está ocupado con otro pago. - Tu reloj no ha podido recibir este pago. - Enviado a tu reloj. Mantén pulsado allí para pagar. - Tu reloj no está disponible. Este contacto no tiene ningún método de pago que Bitkit pueda usar ahora. No se puede pagar a este contacto Un retiro anterior de tu saldo de gasto aún se está liquidando. Inténtalo de nuevo cuando termine. diff --git a/app/src/main/res/values-es/strings.xml b/app/src/main/res/values-es/strings.xml index 004e097c11..861958cc8b 100644 --- a/app/src/main/res/values-es/strings.xml +++ b/app/src/main/res/values-es/strings.xml @@ -1105,11 +1105,6 @@ Recibir Transferencia Entrante: Enviar Bitcoin - Pagar en el reloj - Tu reloj está ocupado con otro pago. - Tu reloj no ha podido recibir este pago. - Enviado a tu reloj. Mantén pulsado allí para pagar. - Tu reloj no está disponible. Este contacto no tiene ningún método de pago que Bitkit pueda usar ahora. No se puede pagar a este contacto Un retiro anterior de tu saldo de gasto aún se está liquidando. Inténtalo de nuevo cuando termine. diff --git a/app/src/main/res/values-fr/strings.xml b/app/src/main/res/values-fr/strings.xml index 4bb96d9303..edb66fa16c 100644 --- a/app/src/main/res/values-fr/strings.xml +++ b/app/src/main/res/values-fr/strings.xml @@ -1108,11 +1108,6 @@ Envoyer Recevoir Envoyer des bitcoins - Payer sur la montre - Votre montre traite un autre paiement. - Votre montre n\'a pas pu prendre ce paiement. - Envoyé à votre montre. Maintenez pour payer sur la montre. - Votre montre est injoignable. Ce contact n\'a aucun moyen de paiement que Bitkit peut utiliser pour le moment. Impossible de payer ce contact Un retrait précédent de votre solde dépenses est encore en cours de règlement. Réessayez une fois terminé. diff --git a/app/src/main/res/values-it/strings.xml b/app/src/main/res/values-it/strings.xml index 3114685e44..dbdbc4f941 100644 --- a/app/src/main/res/values-it/strings.xml +++ b/app/src/main/res/values-it/strings.xml @@ -1270,11 +1270,6 @@ Scadenza invoice L\'importo massimo spendibile e\' leggermente inferiore a causa di un saldo di riserva richiesto. Saldo di Riserva - Paga sull\'orologio - L\'orologio è impegnato con un altro pagamento. - L\'orologio non ha potuto accettare questo pagamento. - Inviato all\'orologio. Tieni premuto lì per pagare. - L\'orologio non è raggiungibile. Questo contatto non ha alcun metodo di pagamento che Bitkit possa usare ora. Impossibile pagare questo contatto Un precedente prelievo dal tuo saldo di spesa è ancora in fase di regolamento. Riprova al termine. diff --git a/app/src/main/res/values-nl/strings.xml b/app/src/main/res/values-nl/strings.xml index 5bb726f5ec..ec459c74d7 100644 --- a/app/src/main/res/values-nl/strings.xml +++ b/app/src/main/res/values-nl/strings.xml @@ -1265,11 +1265,6 @@ Factuutvervaldatum Het maximaal te besteden bedrag is iets lager vanwege een vereist reservesaldo. Reservesaldo - Betalen op horloge - Je horloge is bezig met een andere betaling. - Je horloge kon deze betaling niet aannemen. - Naar je horloge gestuurd. Houd daar ingedrukt om te betalen. - Je horloge is niet bereikbaar. Dit contact heeft nu geen betaalmethode die Bitkit kan gebruiken. Kan dit contact niet betalen Een eerdere opname van je bestedingssaldo wordt nog verwerkt. Probeer het opnieuw zodra die is voltooid. diff --git a/app/src/main/res/values-pl/strings.xml b/app/src/main/res/values-pl/strings.xml index 553dbda4d5..0dd7cd3c73 100644 --- a/app/src/main/res/values-pl/strings.xml +++ b/app/src/main/res/values-pl/strings.xml @@ -1110,11 +1110,6 @@ Wyślij Otrzymaj Wyślij Bitcoin - Zapłać na zegarku - Zegarek jest zajęty inną płatnością. - Zegarek nie mógł przyjąć tej płatności. - Wysłano na zegarek. Przytrzymaj tam, aby zapłacić. - Zegarek jest nieosiągalny. Ten kontakt nie ma teraz metody płatności, której Bitkit może użyć. Nie można zapłacić temu kontaktowi Wcześniejsza wypłata z Twojego salda wydatków wciąż się rozlicza. Spróbuj ponownie po jej zakończeniu. diff --git a/app/src/main/res/values-pt-rBR/strings.xml b/app/src/main/res/values-pt-rBR/strings.xml index 39c8818b00..2103c430f5 100644 --- a/app/src/main/res/values-pt-rBR/strings.xml +++ b/app/src/main/res/values-pt-rBR/strings.xml @@ -1274,11 +1274,6 @@ Vencimento do invoice O valor máximo utilizável é um pouco menor devido a um saldo de reserva obrigatório. Saldo de reserva - Pagar no relógio - Seu relógio está ocupado com outro pagamento. - Seu relógio não pôde receber este pagamento. - Enviado para o seu relógio. Segure lá para pagar. - Seu relógio não está acessível. Este contato não tem nenhum método de pagamento que o Bitkit possa usar agora. Não é possível pagar este contato Um levantamento anterior do seu saldo de gastos ainda está a ser concluído. Tente novamente quando for concluído. diff --git a/app/src/main/res/values-pt/strings.xml b/app/src/main/res/values-pt/strings.xml index 921ee16736..645ab23022 100644 --- a/app/src/main/res/values-pt/strings.xml +++ b/app/src/main/res/values-pt/strings.xml @@ -974,11 +974,6 @@ Enviar Receber Enviar Bitcoin - Pagar no relógio - O relógio está ocupado com outro pagamento. - O relógio não pôde receber este pagamento. - Enviado para o relógio. Mantenha premido lá para pagar. - O relógio não está acessível. Este contacto não tem nenhum método de pagamento que a Bitkit possa usar agora. Não é possível pagar a este contacto Um levantamento anterior do seu saldo de gastos ainda está a ser concluído. Tente novamente quando terminar. diff --git a/app/src/main/res/values-ru/strings.xml b/app/src/main/res/values-ru/strings.xml index ca5ba22a98..9f49eca1fa 100644 --- a/app/src/main/res/values-ru/strings.xml +++ b/app/src/main/res/values-ru/strings.xml @@ -1287,11 +1287,6 @@ Срок действия инвойса Максимальная сумма для траты немного меньше из-за необходимого резервного баланса. Резервный баланс - Оплатить На Часах - Часы заняты другим платежом. - Часы не смогли принять этот платёж. - Отправлено на часы. Удерживайте там для оплаты. - Часы недоступны. У этого контакта сейчас нет способа оплаты, который может использовать Bitkit. Невозможно оплатить этому контакту Предыдущий вывод с вашего баланса расходов ещё проводится. Попробуйте ещё раз после его завершения. diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index efaee5867c..982ff57887 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -1837,11 +1837,6 @@ Invoice expiration The maximum spendable amount is a bit lower due to a required reserve balance. Reserve Balance - Pay on Watch - Your watch is busy with another payment. - Your watch couldn\'t take this payment. - Sent to your watch. Hold to pay there. - Your watch is not reachable. This contact has no payment method Bitkit can use right now. Can\'t pay this contact An earlier withdrawal from your spending balance is still settling. Try again once it completes. diff --git a/app/src/test/java/to/bitkit/repositories/WatchLinkRepoTest.kt b/app/src/test/java/to/bitkit/repositories/WatchLinkRepoTest.kt index c98e8d8d99..b0bacf00fa 100644 --- a/app/src/test/java/to/bitkit/repositories/WatchLinkRepoTest.kt +++ b/app/src/test/java/to/bitkit/repositories/WatchLinkRepoTest.kt @@ -6,7 +6,6 @@ import kotlinx.coroutines.async import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.first import kotlinx.coroutines.flow.update -import kotlinx.coroutines.launch import kotlinx.coroutines.test.StandardTestDispatcher import kotlinx.coroutines.test.TestScope import kotlinx.coroutines.test.runCurrent @@ -39,8 +38,6 @@ import to.bitkit.wearlink.LinkTransport import to.bitkit.wearlink.OpenSend import to.bitkit.wearlink.PairingState import to.bitkit.wearlink.PairingThrottle -import to.bitkit.wearlink.PayRequestDoc -import to.bitkit.wearlink.PayResult import to.bitkit.wearlink.PeerInvoice import to.bitkit.wearlink.QuickPayDoc import to.bitkit.wearlink.Removal @@ -78,7 +75,6 @@ class WatchLinkRepoTest : BaseUnitTest(StandardTestDispatcher()) { const val NOW = 1_800_000_000_000L const val MNEMONIC = "abandon abandon about" const val PASSPHRASE = "pass" - const val INVOICE = "lnbcrt10u1pexample" val HASH = "ab".repeat(32) val OWN_HASH = "cd".repeat(32) @@ -111,10 +107,6 @@ class WatchLinkRepoTest : BaseUnitTest(StandardTestDispatcher()) { var quickPay: QuickPayDoc? = null var sends: List? = null } - - /** The payment requests the watch was handed, and what it answers. */ - private val payRequests = mutableListOf() - private var payAnswer = PayResult.Received private val storedSeeds = mutableListOf() private var erases = 0 private var nowMs = NOW @@ -164,11 +156,6 @@ class WatchLinkRepoTest : BaseUnitTest(StandardTestDispatcher()) { override suspend fun clearPeerState() = Unit override fun onPhonePaired() = Unit - - override suspend fun onPayRequest(request: PayRequestDoc): PayResult { - payRequests += request - return payAnswer - } }, info = { WatchInfo("1.0", isLockSet = false) }, nowMs = { nowMs }, @@ -866,124 +853,6 @@ class WatchLinkRepoTest : BaseUnitTest(StandardTestDispatcher()) { assertTrue(first.contentEquals(store.installId())) } - // region payment handoff - - private fun TestScope.handOff(): MutableList { - val results = mutableListOf() - backgroundScope.launch { sut.payOnWatch(INVOICE).collect { results += it } } - runCurrent() - return results - } - - @Test - fun `the paired watch is reachable only while it is paired and connected`() = test { - setUp() - assertFalse(sut.isWatchReachable()) - - pair() - assertTrue(sut.isWatchReachable()) - - network.isConnected = false - assertFalse(sut.isWatchReachable()) - } - - @Test - fun `a handed-off request reaches the watch and its link opens there`() = test { - setUp() - pair() - - val results = handOff() - - assertEquals(listOf(PayOnWatchResult.Sent), results) - val request = payRequests.single() - assertEquals(INVOICE, request.input) - assertEquals(LinkPaths.payUri(request.id), network.opened.last()) - } - - @Test - fun `a busy watch is said to be busy, and nothing opens on it`() = test { - setUp() - pair() - payAnswer = PayResult.Busy - val opened = network.opened.size - - assertEquals(listOf(PayOnWatchResult.Busy), handOff()) - assertEquals(opened, network.opened.size) - } - - @Test - fun `a watch that refuses is said to have refused, and one that is away is not reachable`() = test { - setUp() - pair() - payAnswer = PayResult.Refused - val opened = network.opened.size - assertEquals(listOf(PayOnWatchResult.Refused), handOff()) - assertEquals(opened, network.opened.size) - - network.isConnected = false - assertEquals(listOf(PayOnWatchResult.Unreachable), handOff()) - } - - @Test - fun `a watch that never answers is not reachable once the wait ends`() = test { - setUp() - pair() - network.intercept = { if (it.path.endsWith(LinkPaths.PAY_RESULT)) null else it.payload } - - val results = handOff() - assertTrue(results.isEmpty()) - testScheduler.advanceTimeBy(11_000) - runCurrent() - - assertEquals(listOf(PayOnWatchResult.Unreachable), results) - } - - @Test - fun `a request the watch dropped later for a send under way turns the line to busy`() = test { - setUp() - pair() - val results = handOff() - - watchLink.answerPay(payRequests.single().id, PayResult.Busy) - runCurrent() - - assertEquals(listOf(PayOnWatchResult.Sent, PayOnWatchResult.Busy), results) - } - - @Test - fun `a request the watch dropped later where it cannot show it turns the line to refused`() = test { - setUp() - pair() - val results = handOff() - - watchLink.answerPay(payRequests.single().id, PayResult.Refused) - runCurrent() - - assertEquals(listOf(PayOnWatchResult.Sent, PayOnWatchResult.Refused), results) - } - - @Test - fun `the answer to another request never turns the line`() = test { - setUp() - pair() - val results = handOff() - - watchLink.answerPay("ef".repeat(16), PayResult.Refused) - runCurrent() - - assertEquals(listOf(PayOnWatchResult.Sent), results) - } - - @Test - fun `no request is handed over without a pairing`() = test { - setUp() - - assertEquals(listOf(PayOnWatchResult.Unreachable), handOff()) - assertTrue(payRequests.isEmpty()) - } - - // endregion - // region install prompt @Test diff --git a/app/src/test/java/to/bitkit/ui/screens/wallets/send/PayOnWatchInputTest.kt b/app/src/test/java/to/bitkit/ui/screens/wallets/send/PayOnWatchInputTest.kt deleted file mode 100644 index de524c4e71..0000000000 --- a/app/src/test/java/to/bitkit/ui/screens/wallets/send/PayOnWatchInputTest.kt +++ /dev/null @@ -1,117 +0,0 @@ -package to.bitkit.ui.screens.wallets.send - -import com.synonym.bitkitcore.LightningInvoice -import com.synonym.bitkitcore.LnurlPayData -import com.synonym.bitkitcore.NetworkType -import com.synonym.bitkitcore.PaykitEndpoint -import com.synonym.bitkitcore.ServiceRouteLeg -import kotlinx.collections.immutable.persistentListOf -import org.junit.Test -import to.bitkit.viewmodels.LnurlParams -import to.bitkit.viewmodels.PaykitRouteUi -import to.bitkit.viewmodels.PaykitSwapRouteUi -import to.bitkit.viewmodels.SendMethod -import to.bitkit.viewmodels.SendUiState -import kotlin.test.assertEquals -import kotlin.test.assertNull - -/** Which send states offer Pay on Watch, and what they hand over. */ -class PayOnWatchInputTest { - private companion object { - const val INVOICE = "lnbcrt10u1pexample" - const val SATS = 1_000uL - - val ENDPOINT = PaykitEndpoint(methodId = "btc-regtest-p2wpkh", value = "bcrt1qexample") - val LNURL = LnurlPayData( - uri = "lnurl1example", - callback = "https://example.com/pay", - minSendable = 1_000_000u, - maxSendable = 1_000_000u, - metadataStr = "[]", - commentAllowed = null, - allowsNostr = false, - nostrPubkey = null, - ) - } - - private fun invoice(bolt11: String = INVOICE, sats: ULong = SATS) = LightningInvoice( - bolt11 = bolt11, - paymentHash = byteArrayOf(1, 2, 3), - amountSatoshis = sats, - timestampSeconds = 0uL, - expirySeconds = 86_400uL, - isExpired = false, - description = "test", - networkType = NetworkType.REGTEST, - payeeNodeId = null, - ) - - private fun lightning() = SendUiState( - amount = SATS, - payMethod = SendMethod.LIGHTNING, - decodedInvoice = invoice(), - ) - - @Test - fun `a bolt11 invoice with an amount is handed over as decoded`() { - assertEquals(INVOICE, lightning().payOnWatchInput()) - } - - @Test - fun `the unused bolt11 field of the send state offers nothing`() { - assertNull(SendUiState(payMethod = SendMethod.LIGHTNING, bolt11 = INVOICE).payOnWatchInput()) - } - - @Test - fun `an invoice without an amount is not offered, whatever was typed on the phone`() { - assertNull(lightning().copy(decodedInvoice = invoice(sats = 0uL)).payOnWatchInput()) - } - - @Test - fun `a blank invoice is not offered`() { - assertNull(lightning().copy(decodedInvoice = invoice(bolt11 = " ")).payOnWatchInput()) - } - - @Test - fun `an onchain send is not offered`() { - assertNull(lightning().copy(payMethod = SendMethod.ONCHAIN).payOnWatchInput()) - } - - @Test - fun `an lnurl pay is not offered`() { - assertNull(lightning().copy(lnurl = LnurlParams.LnurlPay(LNURL)).payOnWatchInput()) - } - - @Test - fun `a payment request is not offered`() { - assertNull(lightning().copy(isPaymentRequest = true).payOnWatchInput()) - } - - @Test - fun `a subscription payment is not offered`() { - assertNull(lightning().copy(isSubscriptionPayment = true).payOnWatchInput()) - assertNull(lightning().copy(isInitialSubscriptionPayment = true).payOnWatchInput()) - } - - @Test - fun `a hardware wallet's send is not offered`() { - assertNull(lightning().copy(hardwareWalletId = "trezor").payOnWatchInput()) - } - - @Test - fun `a contact payment over a spark leg or a swap is not offered`() { - val leg = ServiceRouteLeg( - service = "spark", - endpoint = ENDPOINT, - deliveredSat = SATS, - debitSat = SATS, - atomicity = "trusted", - validUntilUnix = 0uL, - ) - val route = PaykitRouteUi(persistentListOf(ENDPOINT), offersSparkLeg = true, serviceLeg = leg) - - assertNull(lightning().copy(paykitRoute = route).payOnWatchInput()) - assertNull(lightning().copy(paykitSwapRoute = PaykitSwapRouteUi(ENDPOINT)).payOnWatchInput()) - assertEquals(INVOICE, lightning().copy(paykitRoute = route.copy(serviceLeg = null)).payOnWatchInput()) - } -} diff --git a/app/src/test/java/to/bitkit/ui/screens/wallets/send/PayOnWatchViewModelTest.kt b/app/src/test/java/to/bitkit/ui/screens/wallets/send/PayOnWatchViewModelTest.kt deleted file mode 100644 index 231cfab571..0000000000 --- a/app/src/test/java/to/bitkit/ui/screens/wallets/send/PayOnWatchViewModelTest.kt +++ /dev/null @@ -1,61 +0,0 @@ -package to.bitkit.ui.screens.wallets.send - -import kotlinx.coroutines.flow.MutableSharedFlow -import kotlinx.coroutines.flow.flowOf -import org.junit.Test -import org.mockito.kotlin.mock -import org.mockito.kotlin.times -import org.mockito.kotlin.verify -import org.mockito.kotlin.whenever -import to.bitkit.repositories.PayOnWatchResult -import to.bitkit.repositories.WatchLinkRepo -import to.bitkit.test.BaseUnitTest -import kotlin.test.assertEquals -import kotlin.test.assertFalse -import kotlin.test.assertNull -import kotlin.test.assertTrue - -class PayOnWatchViewModelTest : BaseUnitTest() { - private companion object { - const val INVOICE = "lnbcrt10u1pexample" - } - - private val repo = mock() - - @Test - fun `pay on watch is offered only while the paired watch is reachable`() = test { - whenever { repo.isWatchReachable() }.thenReturn(false) - val sut = PayOnWatchViewModel(repo) - - sut.refresh() - assertFalse(sut.uiState.value.isAvailable) - - whenever { repo.isWatchReachable() }.thenReturn(true) - sut.refresh() - assertTrue(sut.uiState.value.isAvailable) - } - - @Test - fun `a tap shows each result line the handoff gives`() = test { - whenever(repo.payOnWatch(INVOICE)).thenReturn(flowOf(PayOnWatchResult.Sent, PayOnWatchResult.Busy)) - val sut = PayOnWatchViewModel(repo) - - sut.onPayOnWatchClick(INVOICE) - - assertEquals(PayOnWatchResult.Busy, sut.uiState.value.result) - assertFalse(sut.uiState.value.isSending) - } - - @Test - fun `a tap while a handoff is on its way hands nothing more over`() = test { - whenever(repo.payOnWatch(INVOICE)).thenReturn(MutableSharedFlow()) - val sut = PayOnWatchViewModel(repo) - - sut.onPayOnWatchClick(INVOICE) - sut.onPayOnWatchClick(INVOICE) - - assertTrue(sut.uiState.value.isSending) - assertNull(sut.uiState.value.result) - verify(repo, times(1)).payOnWatch(INVOICE) - } -} diff --git a/docs/wear.md b/docs/wear.md index a5d5f2bdd2..313835d276 100644 --- a/docs/wear.md +++ b/docs/wear.md @@ -489,8 +489,6 @@ usual result screens, only when every one of these holds: paired phone last said it made today they stay within the phone's daily limit, the wallet's. The payment counts as its dollar value in cents, rounded half up and at least one cent, as on the phone. - The wearer is there: the first of the two differences below. -- The request was not handed over by the paired phone (Pairing › Payment handoff): such a request always ends on the - review and the hold. The rate is the last one the watch fetched, whatever its age: the phone has no age limit on its rates either. The phone keeps its rates across restarts and the watch does not, so when QuickPay is on and no dollar rate is in yet, @@ -550,8 +548,7 @@ or a count that cannot be read. counts and stay together within the phone's daily limit (Pairing › Shared guards). **Known gap:** unpaired, the watch allows its own daily limit and the phone its own, together up to the sum a day; paired but apart, the two can go over the phone's limit by what the other spent since they last reached each other. -- **Known limit: a link sent from another app on the phone.** Bitkit's own Pay on Watch never goes out under - QuickPay (Pairing › Payment handoff). Being there is measured as the watch unlocked, the app on screen +- **Known limit: a link sent from another app on the phone.** Being there is measured as the watch unlocked, the app on screen and out of ambient mode. It is not measured as a look or a touch: the watch has no sensor it could ask. An app on the paired phone can open a `lightning:` link on the watch (`RemoteActivityHelper`) while the wearer looks at the phone. A tapped NFC tag is measured the same way: the tap itself is the wearer's act, and Android reads a tag @@ -883,7 +880,7 @@ the phone unpair the watch or erase its wallet. The watch still works without it Part 2 of the pairing work adds the shared guards: the self-send guard's invoice hashes, the QuickPay counts and the open sends travel both ways (Shared guards, below). Part 3 adds the watch's own QuickPay limits, set on the -phone (Watch limits), a payment handed from the phone to the watch (Payment handoff), the prompt to install the +phone (Watch limits), the prompt to install the watch app (Install prompt) and the prompt to pair a watch that has it (Pair prompt). - **Off on mainnet.** `Env.isWatchLinkEnabled` is false on mainnet for as long as the watch app is (#2152). The @@ -1262,42 +1259,6 @@ for delivery after a reconnect. Each device publishes its three when the pairing - **Defaults.** Off, $5 and 5×. A watch that was paired before part 3 follows the phone's QuickPay no longer: its QuickPay is off until the user turns it on for the watch. -### Payment handoff - -On the phone's send review, a BOLT11 invoice that carries its amount and that the wallet pays over Lightning, while -the paired watch is reachable, offers **Pay on Watch** (`SendPayOnWatch`), a small secondary button above the -details (`payOnWatchInput`, which reads the review's decoded invoice). An invoice without an amount does not: only -the invoice is handed over, so the amount typed on the phone would be lost and the watch would ask for it again. -Nor do LNURL, a contact's payment request or one that goes over a Spark leg or a swap, a subscription and a hardware -wallet's send. A tap hands the request to the watch, which reviews it and asks -for its hold to pay; the phone's swipe stays, and the phone shows one line (`SendPayOnWatchResult`): "Sent to your -watch. Hold to pay there.", "Your watch is busy with another payment.", "Your watch couldn't take this payment." or -"Your watch is not reachable." - -1. **The request** goes over the link as a one-shot message, `p2w/pay` (`PayRequestDoc`: a random 16-byte id and - the invoice as the phone read it), in the envelope, so it is authenticated, encrypted and never stored by the - carrier. A watch that is away fails it at once. -2. **The watch** (`PhoneLinkRepo.onPayRequest`) takes only a BOLT11 invoice that carries its amount, with or without - the `lightning:` scheme (`HandoffStore.lightningLink`, which reads the invoice's human-readable part: mainnet, - testnet, signet or regtest, and an amount). It refuses everything else, as an invoice without an amount, an - LNURL, a Lightning address or another scheme, and anything without a wallet; answers busy while a send is under way; and otherwise keeps it in memory (`HandoffStore`, over - `:wearlink`'s `HandoffInbox`) and answers `w2p/pay` received. It takes a request once, only within 60 s of its - arrival, and remembers the last 20 ids; the counters of the envelope already refuse a replay. -3. **The link.** A listener service may not start an activity on Wear OS, so the phone then opens - `bitkitwear://pay?id=` on the watch (`RemoteActivityHelper`). The link carries the id alone, so any app may - send it: without the request that arrived over the link it opens nothing. -4. **On the watch** `LaunchGate` takes the request by its id and opens the existing Send flow with it. The flow ends - on the review and the hold whatever QuickPay says (`SendViewModel`, `Routes.SEND_HANDOFF`): the wearer did not - start it on the watch. A request the watch kept and then drops is answered again, which turns the phone's line - while the phone still listens, 60 s: busy for a send under way (`LaunchGate.admit`, and the screens' own check - of a send that started a frame before, `LaunchGate.onDrop`), and refused where nothing can show it, as outside - Home during the restore or on the Wallet removed notice. -5. **The phone's line** follows the answer: received and the link opened reads sent; busy reads busy; a refusal, - at once or later, reads "Your watch couldn't take this payment."; no answer within 10 s, a watch that is away - and a link that cannot be opened read not reachable. - -Not logged: the invoice. The apps log the answer. - ### Install prompt A timed sheet (`docs/timed-sheets.md`), `WatchInstallTimedSheet`, shown once from Home when a connected watch has @@ -1458,12 +1419,6 @@ Watch: reconnect (Shared guards). A send started on both within the moment it takes a document to cross is refused by neither, and neither is one started more than 5 minutes after the other's that Spark never listed; Spark's shared idempotency key for an invoice still pays it once. -- A handed-off request that the watch kept and then dropped, for a send under way or outside Home, turns the - phone's line to busy or refused only while the phone still listens, 60 s, and only when the watch's later answer - reaches the phone. The phone still shows "Sent" for a request that opens nothing on the watch when the watch's app - never sees the link in time: a link Wear OS did not deliver or a remote launch it ignored, and a link that arrives - more than 60 s after the request. Nothing is paid in any of these: the request is only ever paid by the hold on the - watch. - **Unreleased version skew.** A watch still on a part 2 build, paired with a phone on part 3, does not know the three watch keys: it ignores QuickPay on Watch and follows the phone's own QuickPay as before, also while QuickPay on Watch is off. No such build was released (the link is off on mainnet), so the two parts ship together and no diff --git a/journeys/README.md b/journeys/README.md index f06c6d7799..991cb450f1 100644 --- a/journeys/README.md +++ b/journeys/README.md @@ -140,7 +140,7 @@ journey PR, which is what made this file conflict on every merge. | A watch to run the Wear OS app on | a Wear OS watch emulator (`Wear_Large_Round_API37`, `Wear_Small_Round_API34`), or a physical watch over Wi-Fi debugging — [wear](wear/README.md) | | Watch gestures: pager swipes, swipe-to-dismiss, rotary crown, ambient mode | `adb shell input swipe`, `adb shell input rotaryencoder scroll --axis SCROLL,` and `KEYCODE_SLEEP`/`KEYCODE_WAKEUP` on the emulator; the real crown, bezel and wrist on a physical watch — [wear](wear/README.md#watch-gestures) | | The phone's settings on the watch (units, currency, QuickPay) | a phone dev build with the same private settings wallet (the test phrase with a passphrase kept on this machine), never the public test phrase alone, writes them to the hosted staging VSS, and the watch imports them; nothing runs locally — [wear](wear/README.md#phone-settings-on-vss) | -| A phone and a watch that reach each other, for pairing and, on the local `./spark` stack only, the shared guards, the watch limits and Pay on Watch | a phone emulator (`Bitkit_Phone_API36`) and a watch emulator with debug builds of both apps, joined by the debug socket carrier over `adb forward` and `adb reverse`; the Wear Data Layer itself, the watch's hardware Keystore and its attestation, and so a release-build seed transfer, the remote launch of Pay on Watch and the install prompt's Play listing, are not covered — [wear](wear/README.md#phone-and-watch-over-the-debug-socket) | +| A phone and a watch that reach each other, for pairing and, on the local `./spark` stack only, the shared guards and the watch limits | a phone emulator (`Bitkit_Phone_API36`) and a watch emulator with debug builds of both apps, joined by the debug socket carrier over `adb forward` and `adb reverse`; the Wear Data Layer itself, the watch's hardware Keystore and its attestation, and so a release-build seed transfer and the install prompt's Play listing, are not covered — [wear](wear/README.md#phone-and-watch-over-the-debug-socket) | | Typing on the watch keyboard | `adb shell input text` after closing the Wear OS keyboard with Back, which otherwise swallows the input — [wear](wear/README.md#typing) | ## Cross-platform @@ -222,7 +222,7 @@ Known differences in the corpus, as of the iOS port (synonymdev/bitkit-ios#691): | — | `hardware-wallet/transfer-to-spending-over-max.xml` exists only on iOS | | `wear/*` | not ported — Android only for now; bitkit-ios has no watch app yet, and the watch journeys port with that follow-up | | `settings/watch-quickpay-pin.xml` | not ported — Android only for now; bitkit-ios has no watch app, so no QuickPay on Watch | -| `settings/watch-no-watch-connected.xml` | not ported — Android only for now; bitkit-ios has no watch pairing. The phone's pairing tags are `PairedWatch…`, since the watch app's own start with `Watch…`; an iOS twin takes the same names. The send review's Pay on Watch (`SendPayOnWatch`, `SendPayOnWatchResult`), the install prompt (`WatchInstallSheet`, `WatchInstallConfirm`, `WatchInstallLater`) and the pair prompt (`PairedWatchPrompt`, `PairedWatchPromptPair`, `PairedWatchPromptLater`) are Android only for the same reason | +| `settings/watch-no-watch-connected.xml` | not ported — Android only for now; bitkit-ios has no watch pairing. The phone's pairing tags are `PairedWatch…`, since the watch app's own start with `Watch…`; an iOS twin takes the same names. The install prompt (`WatchInstallSheet`, `WatchInstallConfirm`, `WatchInstallLater`) and the pair prompt (`PairedWatchPrompt`, `PairedWatchPromptPair`, `PairedWatchPromptLater`) are Android only for the same reason | ### Running one on iOS diff --git a/journeys/wear/README.md b/journeys/wear/README.md index b30d4c8726..6b58427146 100644 --- a/journeys/wear/README.md +++ b/journeys/wear/README.md @@ -141,7 +141,6 @@ the command line. Run `receive-paid.xml` first: it funds the wallet the send jou | `quickpay-off-holds.xml` | as `quickpay-skips-hold.xml`, after it | yes, 2 000 sats | | `send-phone-invoice-guard.xml` | local only, phone and watch paired over the debug socket ([Two apps on one wallet](#two-apps-on-one-wallet)) | no | | `quickpay-shared-daily-limit.xml` | local only, phone and watch paired over the debug socket ([Two apps on one wallet](#two-apps-on-one-wallet)) | yes, 20 000 sats | -| `pay-request-from-phone.xml` | local only, phone and watch paired over the debug socket ([Two apps on one wallet](#two-apps-on-one-wallet)) | yes, 5 000 sats | | `quickpay-watch-limit.xml` | local only, phone and watch paired over the debug socket ([Two apps on one wallet](#two-apps-on-one-wallet)) | yes, 5 000 sats | The six settings journeys read the phone's settings backup from Blocktank's hosted staging VSS, which every dev @@ -474,7 +473,7 @@ keep: - **The `pair-*.xml` journeys** use a wallet created in the phone's onboarding for the run, with no funds, and make no payment. Wipe both apps when the run is over ([Fresh app](#fresh-app)). - **The shared-guard and part 3 journeys** (`send-phone-invoice-guard.xml`, `quickpay-shared-daily-limit.xml`, - `pay-request-from-phone.xml`, `quickpay-watch-limit.xml`) receive and pay on both devices, so they run **only on the local `./spark` stack, with throwaway funds**: the watch as in + `quickpay-watch-limit.xml`) receive and pay on both devices, so they run **only on the local `./spark` stack, with throwaway funds**: the watch as in [Local ./spark stack](#local-spark-stack), the phone as in the `spark-regtest` skill (`.claude/plugins/spark-regtest`), with the same `SPARK_LOCAL_CONFIG_B64`. Never run them on hosted regtest or any other Spark network. Build both apps for the local stack before the first pairing journey of the chain, so @@ -941,19 +940,7 @@ builds (`assembleDevRelease` of both apps with a local keystore). - 10c. With the watch out of range, make an invoice on the watch and open it on the phone: the phone pays it while the two are apart (known gap); back in range and after a few seconds, a second watch invoice is refused. - Not run yet. -11. **Pay on Watch over the Data Layer.** Paired as in test 2, on the local `./spark` stack with throwaway funds - ([Two apps on one wallet](#two-apps-on-one-wallet)). Open an invoice on the phone and tap Pay on Watch on its - review. - - Expected: the watch app comes to the front by itself on the review with the hold, also with the app closed - and the screen off before; the phone reads "Sent to your watch. Hold to pay there." Note whether the remote - launch lights the screen and whether it needs the watch unlocked. - - 11a. With a payment sending on the watch: the phone reads "Your watch is busy with another payment.", and the - watch's send screen stays. - - 11b. With the watch out of Bluetooth range or switched off: Pay on Watch is not offered on a review opened - then; on one already open, a tap reads "Your watch is not reachable." - - 11c. With the watch connected only through the cloud (Wi-Fi, phone's Bluetooth off): note whether the - request and the remote launch arrive. - - Not run yet. +11. Retired: Pay on Watch was removed from the phone. 12. **Install prompt.** A phone with a wallet and a connected watch without Bitkit, whose listing has a watch build (internal testing at least; none exists until #2152 is resolved). Open the phone app on Home. - Expected: within a few seconds "Bitkit on Your Watch" (`WatchInstallSheet`); Install opens Bitkit's Play diff --git a/journeys/wear/pay-request-from-phone.xml b/journeys/wear/pay-request-from-phone.xml deleted file mode 100644 index 4dc8909fb1..0000000000 --- a/journeys/wear/pay-request-from-phone.xml +++ /dev/null @@ -1,33 +0,0 @@ - - - A Lightning invoice under review on the phone can be handed to the paired watch (docs/wear.md › Pairing › - Payment handoff): Pay on Watch sends it over the link, the watch opens its own review with the hold to pay, and - the phone shows one line. The watch asks for its hold with QuickPay on Watch on. That a handed-off request never - goes out under QuickPay is held by unit tests (SendViewModelTest, LaunchGateTest), not proven here: an invoice - the phone reviews is above the phone's QuickPay amount, which also caps one QuickPay payment on the watch. Two - emulators over the debug socket. - - Both apps are open on one wallet and the watch pays, which is unsafe on a wallet you keep (#2152): run this only - on the local ./spark stack with throwaway funds, never on hosted regtest (journeys/wear/README.md › Two apps on - one wallet). - - Precondition: journeys/wear/README.md › Phone and watch over the debug socket, with both apps built for the - local ./spark stack from the start and one wallet on both, paired (after pair-receive-wallet.xml), a Spark - balance of at least 5 000 sats and no QuickPay payment on either today. Phone: QuickPay on at $1 and 5×, and - QuickPay on Watch on at $5 and 5× (README › Phone settings on VSS, step 3), Local Currency USD, on Home. Watch: on - the Balance page with the loading ring stopped and a fiat value showing. Note N, the sats worth about $2 at the - dollar rate the phone shows (Settings › Local Currency): above the phone's QuickPay amount, so the phone shows - its review. - - - Run `adb -s $WATCH logcat -c`, then `../bitkit-docker/spark invoice N` and note the BOLT11 invoice it prints as <invoice> - Run `adb -s $PHONE shell am start -a android.intent.action.VIEW -d "lightning:<invoice>" to.bitkit.dev` - Wait up to 15 s until the phone shows the review (tag "SendConfirm") with "SendPayOnWatch" - Tap "SendPayOnWatch" on the phone - Wait up to 10 s until "SendPayOnWatchResult" on the phone reads "Sent to your watch. Hold to pay there." - Wait up to 15 s until "WatchSendHold" is listed on the watch, touching nothing, and verify "WatchSendAmount" reads N, grouped as the watch writes it - Wait 5 s and verify "WatchSendHold" is still listed and `adb -s $WATCH logcat -d -s BitkitWear` does not list "Skipped the hold to pay under QuickPay": the handed-off request waits for the hold - Hold "WatchSendHold" for 2 s as in README › Holding to pay - Wait up to 15 s until "WatchSendSent" is listed on the watch - - diff --git a/wear/src/main/AndroidManifest.xml b/wear/src/main/AndroidManifest.xml index 11ab67dd98..80bb872103 100644 --- a/wear/src/main/AndroidManifest.xml +++ b/wear/src/main/AndroidManifest.xml @@ -95,17 +95,16 @@ - + - - - + - - - diff --git a/wear/src/main/res/drawable/ic_received.xml b/wear/src/main/res/drawable/ic_received.xml new file mode 100644 index 0000000000..b9a852e1d8 --- /dev/null +++ b/wear/src/main/res/drawable/ic_received.xml @@ -0,0 +1,14 @@ + + + + diff --git a/wear/src/main/res/drawable/ic_sent.xml b/wear/src/main/res/drawable/ic_sent.xml new file mode 100644 index 0000000000..02b516e207 --- /dev/null +++ b/wear/src/main/res/drawable/ic_sent.xml @@ -0,0 +1,14 @@ + + + + diff --git a/wear/src/main/res/drawable/ic_south_west.xml b/wear/src/main/res/drawable/ic_south_west.xml deleted file mode 100644 index 348f5b5909..0000000000 --- a/wear/src/main/res/drawable/ic_south_west.xml +++ /dev/null @@ -1,11 +0,0 @@ - - - - - diff --git a/wear/src/main/res/drawable/ic_x.xml b/wear/src/main/res/drawable/ic_x.xml new file mode 100644 index 0000000000..40c28ca482 --- /dev/null +++ b/wear/src/main/res/drawable/ic_x.xml @@ -0,0 +1,15 @@ + + + + From 560811cc18dc725f894607f022bdbf0e3dcba989 Mon Sep 17 00:00:00 2001 From: Joao Victor Sena Date: Sun, 29 Nov 2026 17:47:58 -0300 Subject: [PATCH 07/38] feat: show the watch's activity times as the phone does Co-Authored-By: Claude Opus 5.5 --- docs/wear.md | 10 ++- .../main/java/to/bitkit/wear/ext/DateTime.kt | 63 +++++++++++++++++++ .../screens/activity/ActivityDetailScreen.kt | 12 ++-- .../ui/screens/activity/ActivityScreen.kt | 60 +++++++++++++----- .../screens/activity/ActivityTimeTextTest.kt | 36 +++++++++++ 5 files changed, 153 insertions(+), 28 deletions(-) create mode 100644 wear/src/main/java/to/bitkit/wear/ext/DateTime.kt create mode 100644 wear/src/test/java/to/bitkit/wear/ui/screens/activity/ActivityTimeTextTest.kt diff --git a/docs/wear.md b/docs/wear.md index f357494d18..68914c40b5 100644 --- a/docs/wear.md +++ b/docs/wear.md @@ -288,11 +288,15 @@ On-screen copy stays short: a title or one line of at most about six words per s invoice and an own invoice end there before any hold. - **Activity.** The Activity page lists the newest 20 payments from Spark's local list: the phone's activity icon of a Lightning payment (`ActivityIcon`, copied from the phone's: the up or down arrow of its direction, an - hourglass for pending, a cross for failed, in the spending purple on its 16 % circle), the amount with its sign and how long ago (`WatchActivityItem-0` onwards). + hourglass for pending, a cross for failed, in the spending purple on its 16 % circle), the amount with its sign and when it was made (`WatchActivityItem-0` onwards), as the phone's + activity list writes it (`uiDateText` with `uiDateStyleFor`, copied to `ext/DateTime.kt`): the time alone for a + payment of today ("9:05 AM", or "09:05" in 24 hours, as the watch is set), the day and time earlier this year + ("March 3, 6:40 PM") and the year too before that. An amount too long for one line, as with eight decimals on a small screen, takes a second line. It is read when Spark connects and after every payment or sync, and the last list stays while Spark is - disconnected, with its times counted again every minute; a list just read counts from its own time. A tap opens the detail: the amount, the fee of a send, the - date and time and the status (`WatchActivityDetailAmount`, `…Fee`, `…Time`, `…Status`); Spark's list carries no payee or description. With no + disconnected; the clock its times are written by is read again every minute, so a payment of today reads as a + day once midnight passed, and a list just read counts from its own time. A tap opens the detail: the amount, the + fee of a send, the day and time as the phone's detail writes them ("March 3, 6:40 PM", no year) and the status (`WatchActivityDetailAmount`, `…Fee`, `…Time`, `…Status`); Spark's list carries no payee or description. With no payments it shows a dimmed icon and "No activity" (`WatchActivityEmpty`). A detail whose payment the list does not hold, while it loads or after newer payments pushed it out, shows the dimmed icon (`WatchActivityDetailMissing`). Ambient mode hides the amounts. diff --git a/wear/src/main/java/to/bitkit/wear/ext/DateTime.kt b/wear/src/main/java/to/bitkit/wear/ext/DateTime.kt new file mode 100644 index 0000000000..9fb2039e80 --- /dev/null +++ b/wear/src/main/java/to/bitkit/wear/ext/DateTime.kt @@ -0,0 +1,63 @@ +// Copied from app/src/main/java/to/bitkit/ext/DateTime.kt (UiDateStyle, uiDateStyleFor, dateTimeFormatterOf) and the +// formatting of app/src/main/java/to/bitkit/ui/utils/DateText.kt; keep both in sync until a shared module exists. +package to.bitkit.wear.ext + +import java.time.Instant +import java.time.LocalDate +import java.time.ZoneId +import java.time.format.DateTimeFormatter +import java.util.Locale + +fun dateTimeFormatterOf( + pattern: String, + locale: Locale = Locale.getDefault(), + zone: ZoneId = ZoneId.systemDefault(), +): DateTimeFormatter = DateTimeFormatter.ofPattern(pattern, locale).withZone(zone) + +/** How the phone's activity shows a time: the time alone today, with the day this year, with the year before. */ +fun uiDateStyleFor( + timestamp: ULong, + today: LocalDate = LocalDate.now(), + zone: ZoneId = ZoneId.systemDefault(), +): UiDateStyle { + val date = Instant.ofEpochSecond(timestamp.toLong()).atZone(zone).toLocalDate() + return when { + date == today -> UiDateStyle.TIME + date.year == today.year -> UiDateStyle.DATE_TIME + else -> UiDateStyle.DATE_TIME_YEAR + } +} + +/** [timestamp], in epoch seconds, in [style], as the phone's `uiDateText` writes it. */ +fun uiDateText( + timestamp: ULong, + style: UiDateStyle, + is24Hour: Boolean, + locale: Locale = Locale.getDefault(), + zone: ZoneId = ZoneId.systemDefault(), +): String = dateTimeFormatterOf(style.pattern(is24Hour), locale, zone).format(Instant.ofEpochSecond(timestamp.toLong())) + +enum class UiDateStyle { + TIME, + DATE, + DATE_TIME, + DATE_TIME_YEAR, + ; + + fun pattern(is24Hour: Boolean): String { + val time = if (is24Hour) TIME_24H else TIME_12H + return when (this) { + TIME -> time + DATE -> DAY + DATE_TIME -> "$DAY, $time" + DATE_TIME_YEAR -> "$DAY_WITH_YEAR, $time" + } + } + + private companion object { + const val TIME_12H = "h:mm a" + const val TIME_24H = "HH:mm" + const val DAY = "MMMM d" + const val DAY_WITH_YEAR = "MMMM d yyyy" + } +} diff --git a/wear/src/main/java/to/bitkit/wear/ui/screens/activity/ActivityDetailScreen.kt b/wear/src/main/java/to/bitkit/wear/ui/screens/activity/ActivityDetailScreen.kt index 0fe8ec8ad2..c7ceddc155 100644 --- a/wear/src/main/java/to/bitkit/wear/ui/screens/activity/ActivityDetailScreen.kt +++ b/wear/src/main/java/to/bitkit/wear/ui/screens/activity/ActivityDetailScreen.kt @@ -1,6 +1,5 @@ package to.bitkit.wear.ui.screens.activity -import android.text.format.DateUtils import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.BoxWithConstraints import androidx.compose.foundation.layout.Row @@ -9,7 +8,6 @@ import androidx.compose.runtime.Composable import androidx.compose.runtime.getValue import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier -import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.platform.testTag import androidx.compose.ui.res.stringResource import androidx.compose.ui.text.style.TextAlign @@ -18,6 +16,8 @@ import androidx.lifecycle.compose.collectAsStateWithLifecycle import androidx.wear.compose.material3.MaterialTheme import androidx.wear.compose.material3.Text import to.bitkit.wear.R +import to.bitkit.wear.ext.UiDateStyle +import to.bitkit.wear.ext.uiDateText import to.bitkit.wear.models.BitcoinDisplayUnit import to.bitkit.wear.models.PaymentState import to.bitkit.wear.models.WatchPayment @@ -91,13 +91,9 @@ private fun Content( modifier = Modifier.testTag("WatchActivityDetailFee") ) } - val context = LocalContext.current + // The phone's activity detail writes the day and the time, without the year. Line( - text = DateUtils.formatDateTime( - context, - payment.timestampSecs.toLong() * DateUtils.SECOND_IN_MILLIS, - DateUtils.FORMAT_SHOW_DATE or DateUtils.FORMAT_SHOW_TIME or DateUtils.FORMAT_ABBREV_MONTH, - ), + text = uiDateText(payment.timestampSecs, UiDateStyle.DATE_TIME, rememberIs24HourFormat()), modifier = Modifier.testTag("WatchActivityDetailTime") ) Row( diff --git a/wear/src/main/java/to/bitkit/wear/ui/screens/activity/ActivityScreen.kt b/wear/src/main/java/to/bitkit/wear/ui/screens/activity/ActivityScreen.kt index fdbe027f96..c412950acb 100644 --- a/wear/src/main/java/to/bitkit/wear/ui/screens/activity/ActivityScreen.kt +++ b/wear/src/main/java/to/bitkit/wear/ui/screens/activity/ActivityScreen.kt @@ -1,6 +1,6 @@ package to.bitkit.wear.ui.screens.activity -import android.text.format.DateUtils +import android.text.format.DateFormat import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.fillMaxWidth @@ -8,7 +8,9 @@ import androidx.compose.foundation.layout.size import androidx.compose.runtime.Composable import androidx.compose.runtime.getValue import androidx.compose.runtime.produceState +import androidx.compose.runtime.remember import androidx.compose.ui.Modifier +import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.platform.testTag import androidx.compose.ui.res.painterResource import androidx.compose.ui.res.stringResource @@ -25,6 +27,8 @@ import androidx.wear.compose.material3.lazy.transformedHeight import kotlinx.collections.immutable.persistentListOf import kotlinx.coroutines.delay import to.bitkit.wear.R +import to.bitkit.wear.ext.uiDateStyleFor +import to.bitkit.wear.ext.uiDateText import to.bitkit.wear.models.BITCOIN_SYMBOL import to.bitkit.wear.models.BitcoinDisplayUnit import to.bitkit.wear.models.PaymentState @@ -38,6 +42,8 @@ import to.bitkit.wear.ui.components.WearPreviewDevices import to.bitkit.wear.ui.components.isAmbient import to.bitkit.wear.ui.theme.Colors import java.time.Instant +import java.time.ZoneId +import java.util.Locale import kotlin.time.Duration.Companion.minutes /** The size of the empty state's icon. */ @@ -46,12 +52,12 @@ private val EMPTY_ICON_SIZE = 40.dp /** The opacity of the icons that stand in for the list while it is empty, loading or hidden. */ private const val DIM_ALPHA = 0.4f -/** How often the relative times are counted again. */ -private val RELATIVE_TIME_TICK = 1.minutes +/** How often the clock the times are written by is read again, so a payment of today reads as a day once it passed. */ +private val TIME_TICK = 1.minutes /** - * The activity page of the home pager: the newest payments, each with its direction, amount and how long ago it - * was. A tap opens its detail ([onPaymentClick]). Ambient mode hides the amounts. + * The activity page of the home pager: the newest payments, each with its direction, amount and when it was made, + * as the phone's activity list writes it. A tap opens its detail ([onPaymentClick]). Ambient mode hides the amounts. */ @Composable fun ActivityScreen( @@ -69,9 +75,9 @@ fun ActivityScreen( } /** - * The time the relative times count from, in epoch seconds: when the list was read ([loadedSecs]), moved on by a - * tick of [clock] every minute, so the times also move while the page stays open and Spark reports nothing new. A - * list read after the last tick counts from its own time at once. + * The time the times are written by, in epoch seconds: when the list was read ([loadedSecs]), moved on by a tick of + * [clock] every minute, so the times also move on while the page stays open and Spark reports nothing new. A list + * read after the last tick counts from its own time at once. */ @Composable internal fun rememberNowSecs( @@ -80,7 +86,7 @@ internal fun rememberNowSecs( ): Long { val tickSecs by produceState(initialValue = clock()) { while (true) { - delay(RELATIVE_TIME_TICK) + delay(TIME_TICK) value = clock() } } @@ -116,6 +122,7 @@ private fun List( onPaymentClick: (String) -> Unit, modifier: Modifier = Modifier, ) { + val is24Hour = rememberIs24HourFormat() Box(modifier = modifier.fillMaxSize()) { ListScreen { spec -> item { @@ -133,7 +140,10 @@ private fun List( icon = { ActivityIcon(payment = payment) }, label = { Text(text = payment.amountText(uiState.unit), maxLines = 2) }, secondaryLabel = { - Text(text = relativeTime(payment.timestampSecs.toLong(), uiState.nowSecs), maxLines = 1) + Text( + text = activityTimeText(payment.timestampSecs.toLong(), uiState.nowSecs, is24Hour), + maxLines = 2, + ) }, transformation = SurfaceTransformation(spec), modifier = Modifier @@ -153,13 +163,29 @@ internal fun WatchPayment.amountText(unit: BitcoinDisplayUnit = BitcoinDisplayUn return "$sign $BITCOIN_SYMBOL ${amountSats.toLong().formatMoney(unit)}" } -/** How long ago [timestampSecs] was; a time ahead of the watch's clock, set by Spark's servers, counts as now. */ -private fun relativeTime(timestampSecs: Long, nowSecs: Long): String = DateUtils.getRelativeTimeSpanString( - timestampSecs.coerceAtMost(nowSecs) * DateUtils.SECOND_IN_MILLIS, - nowSecs * DateUtils.SECOND_IN_MILLIS, - DateUtils.MINUTE_IN_MILLIS, - DateUtils.FORMAT_ABBREV_RELATIVE, -).toString() +/** + * When the payment at [timestampSecs] was made, as the phone's activity list writes it (`uiDateText` with + * `uiDateStyleFor`): the time alone on the day of [nowSecs], with the day earlier that year, and with the year + * before it. + */ +internal fun activityTimeText( + timestampSecs: Long, + nowSecs: Long, + is24Hour: Boolean, + locale: Locale = Locale.getDefault(), + zone: ZoneId = ZoneId.systemDefault(), +): String { + val timestamp = timestampSecs.toULong() + val today = Instant.ofEpochSecond(nowSecs).atZone(zone).toLocalDate() + return uiDateText(timestamp, uiDateStyleFor(timestamp, today, zone), is24Hour, locale, zone) +} + +/** Whether the watch writes times in 24 hours, as the phone's activity reads its own setting. */ +@Composable +internal fun rememberIs24HourFormat(): Boolean { + val context = LocalContext.current + return remember(context) { DateFormat.is24HourFormat(context) } +} @Composable internal fun DimIcon(modifier: Modifier = Modifier) { diff --git a/wear/src/test/java/to/bitkit/wear/ui/screens/activity/ActivityTimeTextTest.kt b/wear/src/test/java/to/bitkit/wear/ui/screens/activity/ActivityTimeTextTest.kt new file mode 100644 index 0000000000..b50f8dcceb --- /dev/null +++ b/wear/src/test/java/to/bitkit/wear/ui/screens/activity/ActivityTimeTextTest.kt @@ -0,0 +1,36 @@ +package to.bitkit.wear.ui.screens.activity + +import org.junit.Test +import java.time.ZoneOffset +import java.time.ZonedDateTime +import java.util.Locale +import kotlin.test.assertEquals + +/** The activity list writes its times as the phone's does: the time today, the day this year, the year before. */ +class ActivityTimeTextTest { + private fun text(timestamp: ZonedDateTime, is24Hour: Boolean = false) = + activityTimeText(timestamp.toEpochSecond(), NOW.toEpochSecond(), is24Hour, Locale.US, ZoneOffset.UTC) + + @Test + fun `a payment of today shows its time alone, in 12 or 24 hours`() { + val payment = NOW.withHour(9).withMinute(5) + + assertEquals("9:05 AM", text(payment)) + assertEquals("09:05", text(payment, is24Hour = true)) + } + + @Test + fun `a payment earlier this year shows its day and time`() { + assertEquals("March 3, 6:40 PM", text(ZonedDateTime.of(2026, 3, 3, 18, 40, 0, 0, ZoneOffset.UTC))) + assertEquals("November 28, 23:59", text(NOW.minusDays(1).withHour(23).withMinute(59), is24Hour = true)) + } + + @Test + fun `a payment of an earlier year shows the year too`() { + assertEquals("December 31 2025, 11:00 PM", text(ZonedDateTime.of(2025, 12, 31, 23, 0, 0, 0, ZoneOffset.UTC))) + } + + private companion object { + val NOW: ZonedDateTime = ZonedDateTime.of(2026, 11, 29, 14, 30, 0, 0, ZoneOffset.UTC) + } +} From 8c037fc177135bff633c2e93e547ee9c7f8df769 Mon Sep 17 00:00:00 2001 From: Joao Victor Sena Date: Sun, 29 Nov 2026 17:48:29 -0300 Subject: [PATCH 08/38] test: keep the watch's fiat currency the phone's alone Co-Authored-By: Claude Opus 5.5 --- .../to/bitkit/wear/data/SettingsStoreTest.kt | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/wear/src/test/java/to/bitkit/wear/data/SettingsStoreTest.kt b/wear/src/test/java/to/bitkit/wear/data/SettingsStoreTest.kt index 86a51f8746..79683d44b7 100644 --- a/wear/src/test/java/to/bitkit/wear/data/SettingsStoreTest.kt +++ b/wear/src/test/java/to/bitkit/wear/data/SettingsStoreTest.kt @@ -12,6 +12,7 @@ import to.bitkit.wear.models.BitcoinDisplayUnit import to.bitkit.wear.models.PhoneSettings import to.bitkit.wear.models.PrimaryDisplay import to.bitkit.wear.models.QuickPayLimits +import to.bitkit.wear.models.USD import to.bitkit.wear.security.FakeDeviceLock import to.bitkit.wear.security.FakeSeedKey import to.bitkit.wear.security.KeystoreSeedStore @@ -150,6 +151,22 @@ class SettingsStoreTest : BaseUnitTest() { close() } + @Test + fun `the currency is the phone's alone, kept by the wearer's unit swap and changed only by an import`() = test { + val sut = open() + assertEquals(USD, sut.data.first().selectedCurrency) + sut.applyPhoneSettings(PHONE_SETTINGS, syncedAtMs = 5_000L) + + sut.setPrimaryDisplay(PrimaryDisplay.BITCOIN) + sut.setPrimaryDisplay(PrimaryDisplay.FIAT) + assertEquals("EUR", sut.data.first().selectedCurrency) + + val pushed = PHONE_SETTINGS.copy(selectedCurrency = "CHF") + sut.applyPushedSettings(pushed, syncedAtMs = 6_000L, changedAtMs = 6_000L) + assertEquals("CHF", sut.data.first().selectedCurrency) + close() + } + @Test fun `clearing quickpay keeps the display values and forgets the import time`() = test { val sut = open() From 8763b343615442ce95ca7c15b7f42ef145abb1c1 Mon Sep 17 00:00:00 2001 From: Joao Victor Sena Date: Sun, 29 Nov 2026 17:49:46 -0300 Subject: [PATCH 09/38] feat: show a payment's note on the watch's activity detail Co-Authored-By: Claude Opus 5.5 --- docs/wear.md | 2 +- .../java/to/bitkit/wear/models/Payments.kt | 6 +++++- .../bitkit/wear/repositories/PaymentsRepo.kt | 15 +++++++++++++++ .../screens/activity/ActivityDetailScreen.kt | 19 +++++++++++++++++-- .../wear/repositories/PaymentsRepoTest.kt | 15 +++++++++++++++ .../to/bitkit/wear/services/SparkFixtures.kt | 3 ++- 6 files changed, 55 insertions(+), 5 deletions(-) diff --git a/docs/wear.md b/docs/wear.md index 68914c40b5..6a1381bde4 100644 --- a/docs/wear.md +++ b/docs/wear.md @@ -296,7 +296,7 @@ On-screen copy stays short: a title or one line of at most about six words per s It is read when Spark connects and after every payment or sync, and the last list stays while Spark is disconnected; the clock its times are written by is read again every minute, so a payment of today reads as a day once midnight passed, and a list just read counts from its own time. A tap opens the detail: the amount, the - fee of a send, the day and time as the phone's detail writes them ("March 3, 6:40 PM", no year) and the status (`WatchActivityDetailAmount`, `…Fee`, `…Time`, `…Status`); Spark's list carries no payee or description. With no + fee of a send, the day and time as the phone's detail writes them ("March 3, 6:40 PM", no year) and the status (`WatchActivityDetailAmount`, `…Fee`, `…Time`, `…Status`), and the payment's note in up to two lines (`WatchActivityDetailMessage`) when it has one, as the phone's detail shows it: an LNURL comment of the payer, or else the invoice's description, from Spark's payment details (`PaymentsRepo`, `Payment.message`); a blank one shows nothing, and ambient mode hides it. Spark's list carries no payee. With no payments it shows a dimmed icon and "No activity" (`WatchActivityEmpty`). A detail whose payment the list does not hold, while it loads or after newer payments pushed it out, shows the dimmed icon (`WatchActivityDetailMissing`). Ambient mode hides the amounts. diff --git a/wear/src/main/java/to/bitkit/wear/models/Payments.kt b/wear/src/main/java/to/bitkit/wear/models/Payments.kt index a7b7c7ac96..1e03563efc 100644 --- a/wear/src/main/java/to/bitkit/wear/models/Payments.kt +++ b/wear/src/main/java/to/bitkit/wear/models/Payments.kt @@ -86,7 +86,10 @@ class PreparedSend internal constructor( enum class PaymentState { Completed, Pending, Failed } -/** A payment of this wallet as the activity list shows it. [timestampSecs] is in epoch seconds. */ +/** + * A payment of this wallet as the activity list shows it. [timestampSecs] is in epoch seconds. [message] is its + * note, as the phone's activity shows it, or null when it has none. + */ data class WatchPayment( val id: String, val isSent: Boolean, @@ -94,6 +97,7 @@ data class WatchPayment( val feeSats: ULong, val timestampSecs: ULong, val state: PaymentState, + val message: String? = null, ) /** diff --git a/wear/src/main/java/to/bitkit/wear/repositories/PaymentsRepo.kt b/wear/src/main/java/to/bitkit/wear/repositories/PaymentsRepo.kt index fd2e179c5d..fe7837b1fa 100644 --- a/wear/src/main/java/to/bitkit/wear/repositories/PaymentsRepo.kt +++ b/wear/src/main/java/to/bitkit/wear/repositories/PaymentsRepo.kt @@ -776,8 +776,23 @@ private fun Payment.toWatchPayment() = WatchPayment( PaymentStatus.PENDING -> PaymentState.Pending PaymentStatus.FAILED -> PaymentState.Failed }, + message = message(), ) +/** + * The payment's note: an LNURL comment the payer wrote, which the phone keeps over the invoice's description, or + * else the invoice's description. Null when it has none. + */ +private fun Payment.message(): String? { + val note = when (val details = details) { + is PaymentDetails.Lightning -> + details.lnurlPayInfo?.comment ?: details.lnurlReceiveMetadata?.senderComment ?: details.description + is PaymentDetails.Spark -> details.invoiceDetails?.description + else -> null + } + return note?.trim()?.takeIf { it.isNotEmpty() } +} + /** Spark refuses an expired Lightning invoice with this input error, at prepare and again at send. */ private fun Throwable.isInvoiceExpired(): Boolean = this is SdkException.InvalidInput && v1.contains("invoice has expired", ignoreCase = true) diff --git a/wear/src/main/java/to/bitkit/wear/ui/screens/activity/ActivityDetailScreen.kt b/wear/src/main/java/to/bitkit/wear/ui/screens/activity/ActivityDetailScreen.kt index c7ceddc155..0ddf69070f 100644 --- a/wear/src/main/java/to/bitkit/wear/ui/screens/activity/ActivityDetailScreen.kt +++ b/wear/src/main/java/to/bitkit/wear/ui/screens/activity/ActivityDetailScreen.kt @@ -11,6 +11,7 @@ import androidx.compose.ui.Modifier import androidx.compose.ui.platform.testTag import androidx.compose.ui.res.stringResource import androidx.compose.ui.text.style.TextAlign +import androidx.compose.ui.text.style.TextOverflow import androidx.compose.ui.unit.dp import androidx.lifecycle.compose.collectAsStateWithLifecycle import androidx.wear.compose.material3.MaterialTheme @@ -33,8 +34,12 @@ import to.bitkit.wear.ui.theme.Colors /** The size of the status icon beside the status word. */ private val STATUS_ICON_SIZE = 24.dp +/** The most lines a payment's note takes; a longer one ends in an ellipsis. */ +private const val MESSAGE_MAX_LINES = 2 + /** - * One payment of the activity list: its amount, the fee of a send, when it was made and its status. It reads the + * One payment of the activity list: its amount, the fee of a send, its note when it has one, when it was made and + * its status. It reads the * payment from the list's [viewModel], which belongs to Home. */ @Composable @@ -91,6 +96,16 @@ private fun Content( modifier = Modifier.testTag("WatchActivityDetailFee") ) } + payment.message?.takeIf { !isAmbient }?.let { + Text( + text = it, + style = MaterialTheme.typography.bodySmall, + textAlign = TextAlign.Center, + maxLines = MESSAGE_MAX_LINES, + overflow = TextOverflow.Ellipsis, + modifier = Modifier.testTag("WatchActivityDetailMessage") + ) + } // The phone's activity detail writes the day and the time, without the year. Line( text = uiDateText(payment.timestampSecs, UiDateStyle.DATE_TIME, rememberIs24HourFormat()), @@ -135,6 +150,6 @@ private fun Line( @Composable private fun Preview() { WearPreview { - Content(payment = PreviewPayment, unit = BitcoinDisplayUnit.MODERN, isAmbient = false) + Content(payment = PreviewPayment.copy(message = "Coffee"), unit = BitcoinDisplayUnit.MODERN, isAmbient = false) } } diff --git a/wear/src/test/java/to/bitkit/wear/repositories/PaymentsRepoTest.kt b/wear/src/test/java/to/bitkit/wear/repositories/PaymentsRepoTest.kt index 77ebd55add..85a42c9255 100644 --- a/wear/src/test/java/to/bitkit/wear/repositories/PaymentsRepoTest.kt +++ b/wear/src/test/java/to/bitkit/wear/repositories/PaymentsRepoTest.kt @@ -1762,6 +1762,21 @@ class PaymentsRepoTest : BaseUnitTest() { assertEquals(SparkFixtures.TIMESTAMP, payments[0].timestampSecs) } + @Test + fun `a payment's note is its invoice's description, and none when it is blank or missing`() = test { + whenever(sparkService.listPayments(20u)).thenReturn( + listOf( + payment("described", PaymentStatus.COMPLETED, description = " Coffee "), + payment("blank", PaymentStatus.COMPLETED, description = " "), + payment("plain", PaymentStatus.COMPLETED), + ), + ) + + val payments = sut.recentPayments().getOrThrow() + + assertEquals(listOf("Coffee", null, null), payments.map { it.message }) + } + @Test fun `recent payments fail while spark is not connected`() = test { whenever(sparkService.listPayments(anyOrNull())).doSuspendableAnswer { throw SparkError.NotConnected() } diff --git a/wear/src/test/java/to/bitkit/wear/services/SparkFixtures.kt b/wear/src/test/java/to/bitkit/wear/services/SparkFixtures.kt index cbb1fcab16..ec48a8b66c 100644 --- a/wear/src/test/java/to/bitkit/wear/services/SparkFixtures.kt +++ b/wear/src/test/java/to/bitkit/wear/services/SparkFixtures.kt @@ -99,6 +99,7 @@ object SparkFixtures { amountSats: Long = 1_000, feeSats: Long = 3, timestamp: ULong = TIMESTAMP, + description: String? = null, ) = Payment( id = id, paymentType = type, @@ -109,7 +110,7 @@ object SparkFixtures { method = PaymentMethod.LIGHTNING, details = paymentHash?.let { PaymentDetails.Lightning( - description = null, + description = description, invoice = "lnbcrt1invoice", destinationPubkey = PROVIDER_NODE, htlcDetails = SparkHtlcDetails(it, null, TIMESTAMP + EXPIRY, SparkHtlcStatus.WAITING_FOR_PREIMAGE), From bb0b3751cc16fa15a1e1942d5ddcd248c4c7b8af Mon Sep 17 00:00:00 2001 From: Joao Victor Sena Date: Sun, 29 Nov 2026 17:52:45 -0300 Subject: [PATCH 10/38] feat: pop the watch's success check in with the phone's confetti Co-Authored-By: Claude Opus 5.5 --- docs/wear.md | 11 +- .../to/bitkit/wear/ui/components/Confetti.kt | 141 ++++++++++++++++++ .../wear/ui/components/SendOutcomeOverlay.kt | 70 +++++---- .../ui/screens/receive/ReceiveQrScreen.kt | 26 +++- .../bitkit/wear/ui/screens/send/SendScreen.kt | 19 ++- .../wear/ui/screens/send/SendResultTest.kt | 22 +++ 6 files changed, 252 insertions(+), 37 deletions(-) create mode 100644 wear/src/main/java/to/bitkit/wear/ui/components/Confetti.kt diff --git a/docs/wear.md b/docs/wear.md index 6a1381bde4..594da5d204 100644 --- a/docs/wear.md +++ b/docs/wear.md @@ -205,6 +205,14 @@ On-screen copy stays short: a title or one line of at most about six words per s amount and without the button, with the same haptic, so the always-on screen shows no amount; the amount shows once the watch wakes. Debug builds log each invoice shown (`Showing invoice`), which is how the journeys read it. While the QR shows, the watch also offers the invoice as an NFC tag, with the NFC hint below the QR (`WatchReceiveNfc`, or `WatchReceiveNfcOff` with NFC off): see NFC › Receive by tap. +- **Celebration.** A success shows the way the phone's new-payment sheet does, with no new library: the check of + a sent result, of a paid receive and of a sent outcome pops in from small with a spring bounce (`PopIn`), and + `Confetti` falls over the screen once, a native Compose canvas copy of the phone's Lottie `confetti_purple` + (squares in the spending purple, swaying, turning and flipping as they fall), over 2 s, then draws nothing more. + Both start on the frame the screen plays its success haptic (the confirm haptic of a send, the firm click of a + receive), so the three come together. In ambient mode there is neither: the always-on screen stays still, and the + haptic plays alone. With animations turned off both end at once. `SendResultTest` checks that only a sent result + has the confetti and that it is gone within 2 s; how it looks on a device is not checked. - **Tile.** The Bitkit tile (`BalanceTileService`) uses the tiles and ProtoLayout Material 3 libraries: a primary layout with the balance in the main slot and an edge button below. With a wallet it shows the balance in bitcoin, in the unit (Modern or Classic) imported from the phone, white, as on the Balance page, and a round Brand orange @@ -270,7 +278,8 @@ On-screen copy stays short: a title or one line of at most about six words per s and while the wallet is offline (`WalletStatus.Offline`), as when the network drops after that sync. With the wallet online and the payment handed to Spark the ring shows alone, also while a hold invoice settles. The screen stays on and the flow cannot be swiped away or left with Back while the send runs. - - Result: sent shows a check, "Sent" and the amount with the confirm haptic, and closes after 2 s. A payment that + - Result: sent shows a check, "Sent" and the amount with the confirm haptic, and closes after 2 s; the check pops + in and the confetti falls (Celebration, below). A payment that did not settle within 10 s, as on the phone, or one that was already under way, from the watch or the phone, shows a clock, "Pending" and the amount (`WatchSendPending`, `WatchSendResultAmount`) with a soft click; an outcome Spark could not report shows "Check activity", never a failure; both stay for 5 s. An outcome that diff --git a/wear/src/main/java/to/bitkit/wear/ui/components/Confetti.kt b/wear/src/main/java/to/bitkit/wear/ui/components/Confetti.kt new file mode 100644 index 0000000000..cb55534ff9 --- /dev/null +++ b/wear/src/main/java/to/bitkit/wear/ui/components/Confetti.kt @@ -0,0 +1,141 @@ +package to.bitkit.wear.ui.components + +import androidx.compose.animation.core.Animatable +import androidx.compose.animation.core.LinearEasing +import androidx.compose.animation.core.Spring +import androidx.compose.animation.core.spring +import androidx.compose.animation.core.tween +import androidx.compose.foundation.Canvas +import androidx.compose.foundation.layout.Box +import androidx.compose.foundation.layout.fillMaxSize +import androidx.compose.runtime.Composable +import androidx.compose.runtime.LaunchedEffect +import androidx.compose.runtime.derivedStateOf +import androidx.compose.runtime.getValue +import androidx.compose.runtime.remember +import androidx.compose.ui.Modifier +import androidx.compose.ui.geometry.Offset +import androidx.compose.ui.geometry.Size +import androidx.compose.ui.graphics.Color +import androidx.compose.ui.graphics.drawscope.rotate +import androidx.compose.ui.graphics.drawscope.scale +import androidx.compose.ui.graphics.graphicsLayer +import androidx.compose.ui.platform.testTag +import to.bitkit.wear.ui.theme.Colors +import kotlin.math.PI +import kotlin.math.abs +import kotlin.math.cos +import kotlin.math.sin +import kotlin.random.Random + +/** How many pieces fall: the phone's rain, thinned for a small screen and one short burst. */ +private const val PIECES = 28 + +/** A piece's side as a share of the screen's width; the phone's are 32 px on its 2 000 px canvas, drawn larger here. */ +private const val PIECE_SIZE = 0.035f + +/** How long the burst lasts, every piece included: one fall, never a loop, within the 2 s a sent result shows. */ +private const val DURATION_MS = 2_000 + +/** The latest start of a piece, as a share of the burst, so the pieces arrive one after another as on the phone. */ +private const val MAX_DELAY = 0.35f + +/** How far a piece sways to either side as it falls, as a share of the screen's width. */ +private const val SWAY = 0.04f + +/** The seed of the pieces, so every burst looks the same. */ +private const val SEED = 2_105 + +/** + * The phone's confetti (`NewTransactionSheet`'s Lottie `confetti_purple`) drawn natively, with no animation + * library: squares in the phone's spending purple that fall from the top, swaying, turning and flipping as they go. + * It plays once over [DURATION_MS] and then draws nothing, so nothing runs after it; the caller leaves it out in + * ambient mode. With animations turned off it ends at once. It takes no touches. + */ +@Composable +fun Confetti( + modifier: Modifier = Modifier, + color: Color = Colors.Purple, +) { + val pieces = remember { confettiPieces() } + val progress = remember { Animatable(0f) } + // Read while drawing only, so the burst redraws each frame without composing again. + val isDone by remember { derivedStateOf { progress.value >= 1f } } + LaunchedEffect(Unit) { progress.animateTo(1f, tween(DURATION_MS, easing = LinearEasing)) } + if (isDone) return + Canvas(modifier = modifier.fillMaxSize().testTag("WatchConfetti")) { + val side = size.width * PIECE_SIZE + val time = progress.value + pieces.forEach { piece -> + val fall = ((time - piece.delay) / piece.duration).takeIf { it in 0f..1f } ?: return@forEach + val turn = 2 * PI.toFloat() * fall + val x = size.width * (piece.x + SWAY * sin(turn * piece.sways + piece.phase)) + val y = -side + (size.height + 2 * side) * fall + val center = Offset(x, y) + rotate(degrees = piece.angle + piece.spin * fall, pivot = center) { + // The phone's pieces flip about one axis as they fall, which reads as a flutter. + scale(scaleX = 1f, scaleY = abs(cos(turn * piece.flips)).coerceAtLeast(MIN_FLIP), pivot = center) { + drawRect(color, topLeft = center - Offset(side / 2, side / 2), size = Size(side, side)) + } + } + } + } +} + +/** The thinnest a flipping piece gets, so it never vanishes edge on. */ +private const val MIN_FLIP = 0.05f + +/** The scale a success icon pops in from. */ +private const val POP_FROM = 0.3f + +/** + * A success icon's entrance, with the confetti and the haptic of a success: [content] pops in from small with a + * bounce, starting on the frame it is first shown, the frame its screen plays the haptic on. + */ +@Composable +fun PopIn( + modifier: Modifier = Modifier, + content: @Composable () -> Unit, +) { + val scale = remember { Animatable(POP_FROM) } + LaunchedEffect(Unit) { + scale.animateTo(1f, spring(dampingRatio = Spring.DampingRatioMediumBouncy, stiffness = Spring.StiffnessMedium)) + } + Box( + modifier = modifier.graphicsLayer { + scaleX = scale.value + scaleY = scale.value + alpha = ((scale.value - POP_FROM) / (1f - POP_FROM)).coerceIn(0f, 1f) + } + ) { + content() + } +} + +private class ConfettiPiece( + val x: Float, + val delay: Float, + val duration: Float, + val phase: Float, + val sways: Float, + val flips: Float, + val angle: Float, + val spin: Float, +) + +private fun confettiPieces(): List { + val random = Random(SEED) + return List(PIECES) { + val delay = random.nextFloat() * MAX_DELAY + ConfettiPiece( + x = 0.1f + random.nextFloat() * 0.8f, + delay = delay, + duration = (1f - delay) * (0.75f + random.nextFloat() * 0.25f), + phase = random.nextFloat() * 2 * PI.toFloat(), + sways = 0.8f + random.nextFloat() * 0.8f, + flips = 1f + random.nextFloat() * 1.5f, + angle = random.nextFloat() * 360f, + spin = 180f + random.nextFloat() * 180f, + ) + } +} diff --git a/wear/src/main/java/to/bitkit/wear/ui/components/SendOutcomeOverlay.kt b/wear/src/main/java/to/bitkit/wear/ui/components/SendOutcomeOverlay.kt index 196325386a..c39b397df1 100644 --- a/wear/src/main/java/to/bitkit/wear/ui/components/SendOutcomeOverlay.kt +++ b/wear/src/main/java/to/bitkit/wear/ui/components/SendOutcomeOverlay.kt @@ -3,12 +3,14 @@ package to.bitkit.wear.ui.components import androidx.activity.compose.BackHandler import androidx.compose.foundation.background import androidx.compose.foundation.layout.Arrangement +import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.size import androidx.compose.runtime.Composable import androidx.compose.runtime.LaunchedEffect import androidx.compose.runtime.getValue +import androidx.compose.runtime.key import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.hapticfeedback.HapticFeedbackType @@ -54,7 +56,8 @@ fun SendOutcomeOverlay( haptic.performHapticFeedback(if (outcome.isSent) HapticFeedbackType.Confirm else HapticFeedbackType.Reject) } BackHandler {} - SpendingTheme { OutcomeContent(outcome = outcome, modifier = modifier) } + // Each outcome pops in, with its own confetti, also when it follows another. + key(outcome.id) { SpendingTheme { OutcomeContent(outcome = outcome, modifier = modifier) } } } @Composable @@ -68,37 +71,50 @@ internal fun OutcomeContent( "${outcome.amount.symbol} ${outcome.amount.text}", ) val tag = if (outcome.isSent) "WatchOutcomeSent" else "WatchOutcomeFailed" - Column( - horizontalAlignment = Alignment.CenterHorizontally, - verticalArrangement = Arrangement.spacedBy(8.dp, Alignment.CenterVertically), - modifier = modifier - .fillMaxSize() - .background(MaterialTheme.colorScheme.background) - .pointerInput(Unit) { - awaitPointerEventScope { - while (true) awaitPointerEvent().changes.forEach { it.consume() } + Box(modifier = modifier.fillMaxSize()) { + Column( + horizontalAlignment = Alignment.CenterHorizontally, + verticalArrangement = Arrangement.spacedBy(8.dp, Alignment.CenterVertically), + modifier = Modifier + .fillMaxSize() + .background(MaterialTheme.colorScheme.background) + .pointerInput(Unit) { + awaitPointerEventScope { + while (true) awaitPointerEvent().changes.forEach { it.consume() } + } } + // One node with the status and the amount, which the icon alone would not say. It is a pane with that + // title, as a screen reader is told of a pane that appears and of its title changing, while a live + // region is announced only on a node that was already there. The tag sits here too, as the children's + // own semantics are dropped. + .clearAndSetSemantics { + testTag = tag + contentDescription = description + paneTitle = description + } + ) { + if (outcome.isSent) { + // The check pops in under the confetti on the frame the confirm haptic plays. + PopIn { OutcomeIcon(outcome) } + } else { + OutcomeIcon(outcome) } - // One node with the status and the amount, which the icon alone would not say. It is a pane with that - // title, as a screen reader is told of a pane that appears and of its title changing, while a live - // region is announced only on a node that was already there. The tag sits here too, as the children's - // own semantics are dropped. - .clearAndSetSemantics { - testTag = tag - contentDescription = description - paneTitle = description - } - ) { - Icon( - painter = painterResource(if (outcome.isSent) R.drawable.ic_check else R.drawable.ic_close), - contentDescription = null, - tint = if (outcome.isSent) MaterialTheme.colorScheme.primary else MaterialTheme.colorScheme.error, - modifier = Modifier.size(OUTCOME_ICON_SIZE) - ) - SmallAmountRow(amount = outcome.amount, amountTag = "WatchOutcomeAmount") + SmallAmountRow(amount = outcome.amount, amountTag = "WatchOutcomeAmount") + } + if (outcome.isSent) Confetti() } } +@Composable +private fun OutcomeIcon(outcome: ShownOutcome) { + Icon( + painter = painterResource(if (outcome.isSent) R.drawable.ic_check else R.drawable.ic_close), + contentDescription = null, + tint = if (outcome.isSent) MaterialTheme.colorScheme.primary else MaterialTheme.colorScheme.error, + modifier = Modifier.size(OUTCOME_ICON_SIZE) + ) +} + @WearPreviewDevices @Composable private fun PreviewSent() { diff --git a/wear/src/main/java/to/bitkit/wear/ui/screens/receive/ReceiveQrScreen.kt b/wear/src/main/java/to/bitkit/wear/ui/screens/receive/ReceiveQrScreen.kt index ba7aaccb3b..02b680f588 100644 --- a/wear/src/main/java/to/bitkit/wear/ui/screens/receive/ReceiveQrScreen.kt +++ b/wear/src/main/java/to/bitkit/wear/ui/screens/receive/ReceiveQrScreen.kt @@ -18,6 +18,7 @@ import androidx.compose.runtime.rememberUpdatedState import androidx.compose.runtime.setValue import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier +import androidx.compose.ui.graphics.Color import androidx.compose.ui.hapticfeedback.HapticFeedbackType import androidx.compose.ui.input.pointer.PointerEventPass import androidx.compose.ui.input.pointer.pointerInput @@ -48,9 +49,11 @@ import to.bitkit.wear.data.NfcState import to.bitkit.wear.ext.openNfcSettings import to.bitkit.wear.ui.components.BezelLoading import to.bitkit.wear.ui.components.CenteredScreen +import to.bitkit.wear.ui.components.Confetti import to.bitkit.wear.ui.components.NfcHint import to.bitkit.wear.ui.components.NfcHintState import to.bitkit.wear.ui.components.NfcTagEffect +import to.bitkit.wear.ui.components.PopIn import to.bitkit.wear.ui.components.QrCode import to.bitkit.wear.ui.components.ScreenAwake import to.bitkit.wear.ui.components.SmallAmountRow @@ -322,6 +325,8 @@ private fun Paid( val isDimmed = amount == null CenteredScreen( edgeButton = amount?.let { { NewInvoiceButton(onClick) } }, + // The check pops in under the confetti on the frame its haptic plays; never on the always-on screen. + overlay = { if (!isDimmed) Confetti() }, modifier = modifier ) { Column( @@ -331,17 +336,26 @@ private fun Paid( .semantics(mergeDescendants = true) {} .testTag("WatchReceivePaid") ) { - Icon( - painter = painterResource(R.drawable.ic_check), - contentDescription = stringResource(R.string.receive__paid), - tint = if (isDimmed) Colors.White.copy(alpha = HIDDEN_ALPHA) else MaterialTheme.colorScheme.primary, - modifier = Modifier.size(MARK_SIZE) - ) + if (isDimmed) { + PaidCheck(tint = Colors.White.copy(alpha = HIDDEN_ALPHA)) + } else { + PopIn { PaidCheck(tint = MaterialTheme.colorScheme.primary) } + } amount?.let { SmallAmountRow(amount = it, amountTag = "WatchReceivePaidAmount") } } } } +@Composable +private fun PaidCheck(tint: Color) { + Icon( + painter = painterResource(R.drawable.ic_check), + contentDescription = stringResource(R.string.receive__paid), + tint = tint, + modifier = Modifier.size(MARK_SIZE) + ) +} + @Composable private fun NewInvoiceButton(onClick: () -> Unit) { EdgeButton( diff --git a/wear/src/main/java/to/bitkit/wear/ui/screens/send/SendScreen.kt b/wear/src/main/java/to/bitkit/wear/ui/screens/send/SendScreen.kt index d758acf2be..026dbad025 100644 --- a/wear/src/main/java/to/bitkit/wear/ui/screens/send/SendScreen.kt +++ b/wear/src/main/java/to/bitkit/wear/ui/screens/send/SendScreen.kt @@ -52,8 +52,10 @@ import to.bitkit.wear.R import to.bitkit.wear.models.formatToModernDisplay import to.bitkit.wear.ui.components.BezelLoading import to.bitkit.wear.ui.components.CenteredScreen +import to.bitkit.wear.ui.components.Confetti import to.bitkit.wear.ui.components.HoldToPayRing import to.bitkit.wear.ui.components.LargeAmountRow +import to.bitkit.wear.ui.components.PopIn import to.bitkit.wear.ui.components.ScreenAwake import to.bitkit.wear.ui.components.SmallAmountRow import to.bitkit.wear.ui.components.WearPreview @@ -435,11 +437,16 @@ private fun Ended( textStyle = if (result == null) MaterialTheme.typography.titleSmall else MaterialTheme.typography.titleMedium, amount = (step as? SendStep.Done)?.amount.takeIf { isAmountShown && result != SendResult.Unknown }, onCloseClick = onCloseClick.takeIf { result == null }, - modifier = modifier + modifier = modifier, + // Sent pops its check in under the confetti, on the frame its haptic plays; never on the always-on screen. + isCelebrated = result == SendResult.Sent && isAmountShown, ) } -/** [icon] and the one line [text], with the [amount] of a result or, for a refusal, the action that closes it. */ +/** + * [icon] and the one line [text], with the [amount] of a result or, for a refusal, the action that closes it. + * [isCelebrated] pops the icon in and lets the confetti fall over the screen. + */ @Composable private fun StatusScreen( @DrawableRes icon: Int, @@ -450,8 +457,10 @@ private fun StatusScreen( amount: DisplayAmount?, onCloseClick: (() -> Unit)?, modifier: Modifier = Modifier, + isCelebrated: Boolean = false, ) { CenteredScreen( + overlay = { if (isCelebrated) Confetti() }, edgeButton = onCloseClick?.let { onClick -> { EdgeButton( @@ -465,7 +474,11 @@ private fun StatusScreen( }, modifier = modifier ) { - StatusIcon(icon = icon, tint = tint) + if (isCelebrated) { + PopIn { StatusIcon(icon = icon, tint = tint) } + } else { + StatusIcon(icon = icon, tint = tint) + } Text( text = text, style = textStyle, diff --git a/wear/src/test/java/to/bitkit/wear/ui/screens/send/SendResultTest.kt b/wear/src/test/java/to/bitkit/wear/ui/screens/send/SendResultTest.kt index aa31acec2f..b04ee06068 100644 --- a/wear/src/test/java/to/bitkit/wear/ui/screens/send/SendResultTest.kt +++ b/wear/src/test/java/to/bitkit/wear/ui/screens/send/SendResultTest.kt @@ -74,6 +74,28 @@ class SendResultTest { composeRule.onNodeWithTag("WatchSendResultAmount").assertDoesNotExist() } + @Test + fun `a sent result pops its check in under confetti that falls once and is gone within 2 s`() { + composeRule.mainClock.autoAdvance = false + setResult(SendStep.Done(SendResult.Sent, AMOUNT), isAmbient = false) + composeRule.mainClock.advanceTimeByFrame() + + composeRule.onNodeWithTag("WatchSendSent").assertIsDisplayed() + composeRule.onNodeWithTag("WatchConfetti").assertExists() + + composeRule.mainClock.advanceTimeBy(2_100) + composeRule.onNodeWithTag("WatchConfetti").assertDoesNotExist() + composeRule.onNodeWithTag("WatchSendSent").assertIsDisplayed() + } + + @Test + fun `only a sent result has confetti`() { + setResult(SendStep.Done(SendResult.Pending, AMOUNT), isAmbient = false) + + composeRule.onNodeWithTag("WatchSendPending").assertIsDisplayed() + composeRule.onNodeWithTag("WatchConfetti").assertDoesNotExist() + } + @Test fun `a pending result that turns sent or failed changes the one live line, which a screen reader is told of`() { val isLive = SemanticsMatcher.expectValue(SemanticsProperties.LiveRegion, LiveRegionMode.Polite) From efff81473042fbfca93612706239a763bc0bb36b Mon Sep 17 00:00:00 2001 From: Joao Victor Sena Date: Sun, 29 Nov 2026 17:53:37 -0300 Subject: [PATCH 11/38] test: check the watch ui follow-up in the wear journeys Co-Authored-By: Claude Opus 5.5 --- journeys/settings/watch-no-watch-connected.xml | 1 + journeys/wear/activity-list.xml | 12 ++++++++---- journeys/wear/pair-prompt.xml | 1 + journeys/wear/receive-paid.xml | 1 + journeys/wear/send-deeplink-bolt11.xml | 2 ++ 5 files changed, 13 insertions(+), 4 deletions(-) diff --git a/journeys/settings/watch-no-watch-connected.xml b/journeys/settings/watch-no-watch-connected.xml index 0bbc5705a2..b67956f830 100644 --- a/journeys/settings/watch-no-watch-connected.xml +++ b/journeys/settings/watch-no-watch-connected.xml @@ -13,6 +13,7 @@ On the General tab, scroll to Watch (tag "PairedWatchSettings") and verify its value reads "Not paired" Tap "PairedWatchSettings" and verify the Watch sheet opens: "PairedWatchStatus" is listed Wait up to 10 s until "PairedWatchStatus" reads "No watch connected. Connect a Wear OS watch to this phone first." + Verify from a screenshot that the sheet shows a large orange watch icon centred above Pair Watch, not the 3D phone illustration Tap Pair Watch (tag "PairedWatchPair") and verify nothing starts: "PairedWatchPairConnecting" is not listed Press Back and verify the sheet closes: "PairedWatchStatus" is not listed and "PairedWatchSettings" is diff --git a/journeys/wear/activity-list.xml b/journeys/wear/activity-list.xml index 80116eaadb..a6284805de 100644 --- a/journeys/wear/activity-list.xml +++ b/journeys/wear/activity-list.xml @@ -1,7 +1,9 @@ - The Activity page, after Receive, lists the newest payments with a direction icon, the amount and how long ago; - a tap opens the detail with the amount, the fee of a send, the time and the status. Emulator and physical watch. + The Activity page, after Receive, lists the newest payments with the phone's activity icon (a purple arrow on a + purple circle), the amount and the time as the phone's activity writes it (the time alone today); a tap opens the + detail with the amount, the fee of a send, the payment's note when it has one, the day and time and the status. + Emulator and physical watch. Precondition: Restored wallet on the local ./spark stack after receive-paid.xml and send-deeplink-bolt11.xml, so the newest payment is the 1 000 sat send, see journeys/wear/README.md › Local ./spark stack, on the Balance page @@ -12,12 +14,14 @@ Swipe the pager left to Activity: `adb shell input swipe 400 227 60 227 300` Wait up to 10 s until "WatchActivityItem-0" is listed Verify "WatchActivityItem-0" shows "- ₿ 1 000" - Verify "WatchActivityItem-0" shows a relative time such as "1 min. ago" + Verify "WatchActivityItem-0" shows the payment's time alone, such as "3:04 PM" (or "15:04" with the watch set to 24 hours), and no "ago" + Verify from a screenshot that each row's icon is a purple arrow on a purple circle, up for the send and down for the receive Verify "WatchActivityItem-1" shows "+ ₿ 50 000" Tap "WatchActivityItem-0" Verify "WatchActivityDetailAmount" reads "1 000" Verify "WatchActivityDetailStatus" reads "Completed" - Verify "WatchActivityDetailTime" shows today's date + Verify "WatchActivityDetailTime" shows today's day and the time, such as "November 29, 3:04 PM" + Verify "WatchActivityDetailMessage" is listed only when the paid invoice carried a description, and then reads it Swipe to dismiss from the left edge: `adb shell input swipe 20 227 400 227 300` Verify "WatchActivityItem-0" is listed again diff --git a/journeys/wear/pair-prompt.xml b/journeys/wear/pair-prompt.xml index 3f6aace794..41be27f3a5 100644 --- a/journeys/wear/pair-prompt.xml +++ b/journeys/wear/pair-prompt.xml @@ -17,6 +17,7 @@ Verify the watch lists "WatchOnboardingRestore", "WatchOnboardingStartOnPhone" reading "Start on phone", and no "WatchOnboardingFromPhone" Start the phone app and unlock it with the PIN: tap "N1" four times Wait up to 15 s on Home until the phone lists "PairedWatchPrompt" with "PairedWatchPromptPair" and "PairedWatchPromptLater" + Verify from a screenshot that the prompt shows a large orange watch icon centred above its title, not the 3D phone illustration Tap Pair (tag "PairedWatchPromptPair") Wait up to 10 s until the watch lists "WatchPairScreen": the phone opened the Pair screen above onboarding Wait up to 15 s until the phone lists "PairedWatchCode" and note its six digits diff --git a/journeys/wear/receive-paid.xml b/journeys/wear/receive-paid.xml index 550474df55..74f6edf48d 100644 --- a/journeys/wear/receive-paid.xml +++ b/journeys/wear/receive-paid.xml @@ -19,6 +19,7 @@ Run `../bitkit-docker/spark pay <invoice> 50000` from this repo's parent checkout Wait up to 20 s until "WatchReceivePaid" is listed Verify "WatchReceivePaidAmount" reads "50 000" + Verify from a screenshot taken at once that the check is purple and purple confetti falls over the screen, and from one taken 3 s later that the confetti is gone and the check stays Verify the button below the check reads "New invoice" (tag "WatchReceiveNew") Tap the check (tag "WatchReceivePaid") and verify "WatchReceivePaid" is still listed 2 s later: the check is no button Tap New invoice (tag "WatchReceiveNew") diff --git a/journeys/wear/send-deeplink-bolt11.xml b/journeys/wear/send-deeplink-bolt11.xml index a4ffcedaf5..4493ec4a71 100644 --- a/journeys/wear/send-deeplink-bolt11.xml +++ b/journeys/wear/send-deeplink-bolt11.xml @@ -12,11 +12,13 @@ Run `../bitkit-docker/spark invoice 1000` and note the BOLT11 invoice it prints as <invoice> Run `adb shell am start -a android.intent.action.VIEW -d "lightning:<invoice>" to.bitkit.dev` Wait up to 10 s until "WatchSendHold" is listed + Verify from a screenshot that the Hold to pay button is purple, not orange Verify "WatchSendAmount" reads "1 000" Verify "WatchSendAmountSymbol" reads "₿" Hold "WatchSendHold" for 2 s as in README › Holding to pay Wait up to 15 s until "WatchSendSent" is listed Verify "WatchSendResultAmount" reads "1 000" + Verify from a screenshot taken at once that the check is purple and purple confetti falls over the screen Wait 4 s Verify the Balance page: "WatchHomeBalance" is listed Verify "WatchSendSent" is not listed From 63f687aad666088919ed50b284ec60610a3066cb Mon Sep 17 00:00:00 2001 From: Joao Victor Sena Date: Sun, 29 Nov 2026 18:30:39 -0300 Subject: [PATCH 12/38] fix: unmark a watch erase that could not be stored and show an error Co-Authored-By: Claude Opus 5.5 --- .../bitkit/ui/sheets/watch/WatchSheetViewModel.kt | 14 ++++++++++++-- .../ui/sheets/watch/WatchSheetViewModelTest.kt | 14 ++++++++++++++ docs/wear.md | 3 ++- .../kotlin/to/bitkit/wearlink/LinkEndpoints.kt | 8 ++++++-- .../kotlin/to/bitkit/wearlink/LinkEndpointsTest.kt | 14 ++++++++++++++ .../kotlin/to/bitkit/wearlink/testing/Fakes.kt | 4 ++++ 6 files changed, 52 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/to/bitkit/ui/sheets/watch/WatchSheetViewModel.kt b/app/src/main/java/to/bitkit/ui/sheets/watch/WatchSheetViewModel.kt index d9a619df8d..e2e12404df 100644 --- a/app/src/main/java/to/bitkit/ui/sheets/watch/WatchSheetViewModel.kt +++ b/app/src/main/java/to/bitkit/ui/sheets/watch/WatchSheetViewModel.kt @@ -15,9 +15,11 @@ import kotlinx.coroutines.flow.first import kotlinx.coroutines.flow.update import kotlinx.coroutines.launch import to.bitkit.R +import to.bitkit.models.Toast import to.bitkit.repositories.WatchLinkError import to.bitkit.repositories.WatchLinkRepo import to.bitkit.repositories.WatchPairingStatus +import to.bitkit.ui.shared.toast.ToastEventBus import to.bitkit.wearlink.AbortReason import to.bitkit.wearlink.AttestationFailure import to.bitkit.wearlink.AttestationVerdict @@ -186,11 +188,19 @@ class WatchSheetViewModel @Inject constructor( fun onUnpairDismiss() = _uiState.update { it.copy(isUnpairDialogShown = false) } - /** Unpairs the watch and erases its wallet. */ + /** Unpairs the watch and erases its wallet, or says it could not ask the watch to. */ fun onUnpairConfirm() { if (!_uiState.value.isUnpairDialogShown) return _uiState.update { it.copy(isUnpairDialogShown = false) } - viewModelScope.launch { watchLinkRepo.unpair() } + viewModelScope.launch { + watchLinkRepo.unpair().onFailure { + ToastEventBus.send( + type = Toast.ToastType.ERROR, + title = context.getString(R.string.common__error), + description = context.getString(R.string.common__error_body), + ) + } + } } /** Drops a watch whose removal was never acknowledged. */ diff --git a/app/src/test/java/to/bitkit/ui/sheets/watch/WatchSheetViewModelTest.kt b/app/src/test/java/to/bitkit/ui/sheets/watch/WatchSheetViewModelTest.kt index 4c527ea22d..bba98c2db5 100644 --- a/app/src/test/java/to/bitkit/ui/sheets/watch/WatchSheetViewModelTest.kt +++ b/app/src/test/java/to/bitkit/ui/sheets/watch/WatchSheetViewModelTest.kt @@ -602,6 +602,20 @@ class WatchSheetViewModelTest : BaseUnitTest() { // endregion + @Test + fun `an unpair that cannot reach the watch's store shows an error`() = test { + whenever { repo.unpair() }.thenReturn(Result.failure(LinkError.Unreachable())) + whenever(context.getString(R.string.common__error_body)).thenReturn("Unknown error") + val toasts = toasts() + val sut = WatchSheetViewModel(context, repo) + record.update { record() } + + sut.onUnpairClick() + sut.onUnpairConfirm() + + assertEquals(listOf(Toast.ToastType.ERROR to "Unknown error"), toasts.map { it.type to it.description }) + } + @Test fun `install opens the play listing on the connected watch without bitkit, and only on one`() = test { val watch = LinkNode("node", "Pixel Watch", isNearby = true, hasApp = false) diff --git a/docs/wear.md b/docs/wear.md index 594da5d204..578de8551b 100644 --- a/docs/wear.md +++ b/docs/wear.md @@ -1275,7 +1275,8 @@ When it shows again: - **Unpair from the phone** unpairs the watch and erases its wallet: the phone's Watch sheet offers no unpair that leaves the wallet on the watch, so a watch handed on or lost does not keep a wallet the phone forgot. It asks first (`PairedWatchUnpair`, then the dialog's Unpair). The phone publishes "erase" and keeps that command stored until - the watch acknowledges. The watch first writes the wipe's note to disk (`WalletRepo.noteEraseByPhone`), then acknowledges + the watch acknowledges. A command that cannot be stored (a Data Layer write that fails) leaves the watch paired + as before, with an error toast, so the Unpair can be tried again. The watch first writes the wipe's note to disk (`WalletRepo.noteEraseByPhone`), then acknowledges while its keys still exist, then runs the wallet's own wipe (`WalletRepo.eraseByPhone`), which leaves the Wallet removed notice and takes the pairing's record with the settings. From the note on, the wipe is finished when the app's process next starts at the latest, whatever starts it (`PhoneLinkRepo` runs `WalletRepo.recover` at its diff --git a/wearlink/src/main/kotlin/to/bitkit/wearlink/LinkEndpoints.kt b/wearlink/src/main/kotlin/to/bitkit/wearlink/LinkEndpoints.kt index 7b441ded8d..f7b22640e7 100644 --- a/wearlink/src/main/kotlin/to/bitkit/wearlink/LinkEndpoints.kt +++ b/wearlink/src/main/kotlin/to/bitkit/wearlink/LinkEndpoints.kt @@ -196,14 +196,18 @@ class PhoneLink( /** * Asks the watch to forget the phone, and with [isErase] to delete its wallet too. The record stays, marked, * until the watch acknowledges or [forget] drops it: an erase is best effort, since a watch that never - * reconnects never reads it. + * reconnects never reads it. A removal that could not be stored for the watch is unmarked again and fails, so + * the phone never waits for a watch that was told nothing. */ suspend fun remove(isErase: Boolean): Unit = locked { val record = store.load() ?: throw LinkError.NotPaired() val state = if (isErase) ControlDoc.State.Erase else ControlDoc.State.Revoked val removal = if (isErase) Removal.Erase else Removal.Unpair store.update { if (it?.pairingId == record.pairingId) it.copy(removal = removal) else it } - publish(record, LinkPaths.CONTROL, encode(ControlDoc(state))) + runSuspendCatching { publish(record, LinkPaths.CONTROL, encode(ControlDoc(state))) }.onFailure { error -> + store.update { if (it?.pairingId == record.pairingId) it.copy(removal = record.removal) else it } + throw error + } } /** diff --git a/wearlink/src/test/kotlin/to/bitkit/wearlink/LinkEndpointsTest.kt b/wearlink/src/test/kotlin/to/bitkit/wearlink/LinkEndpointsTest.kt index 50b0c9b976..2fc33e47a0 100644 --- a/wearlink/src/test/kotlin/to/bitkit/wearlink/LinkEndpointsTest.kt +++ b/wearlink/src/test/kotlin/to/bitkit/wearlink/LinkEndpointsTest.kt @@ -8,6 +8,7 @@ import kotlinx.coroutines.test.runCurrent import kotlinx.coroutines.test.runTest import kotlin.test.Test import kotlin.test.assertEquals +import kotlin.test.assertFailsWith import kotlin.test.assertFalse import kotlin.test.assertIs import kotlin.test.assertNotNull @@ -217,6 +218,19 @@ class LinkEndpointsTest { assertTrue(harness.phoneKeys.keys.isEmpty()) } + @Test + fun `an erase that cannot be stored for the watch fails and leaves the watch paired and unmarked`() = runTest { + val harness = paired() + harness.network.isStateWriteFailing = true + + assertFailsWith { harness.phoneLink.remove(isErase = true) } + runCurrent() + + assertNull(assertNotNull(harness.phoneStore.load()).removal) + assertNotNull(harness.watchStore.load()) + assertEquals(0, harness.erases) + } + @Test fun `an erase reaches a watch that was away, after the phone stopped waiting`() = runTest { val harness = paired() diff --git a/wearlink/src/testFixtures/kotlin/to/bitkit/wearlink/testing/Fakes.kt b/wearlink/src/testFixtures/kotlin/to/bitkit/wearlink/testing/Fakes.kt index ff72a34901..e0e8cea27a 100644 --- a/wearlink/src/testFixtures/kotlin/to/bitkit/wearlink/testing/Fakes.kt +++ b/wearlink/src/testFixtures/kotlin/to/bitkit/wearlink/testing/Fakes.kt @@ -35,6 +35,9 @@ class FakeLinkNetwork(private val scope: CoroutineScope) { var hasWatchApp = true var isWatchNearby = true + /** While true, storing a state document fails, as a Data Layer write that throws does. */ + var isStateWriteFailing = false + /** Sees every packet on its way and returns what is delivered instead, or null to drop it. */ var intercept: (Sent) -> ByteArray? = { it.payload } @@ -77,6 +80,7 @@ class FakeLinkNetwork(private val scope: CoroutineScope) { } override suspend fun putState(path: String, payload: ByteArray) { + if (isStateWriteFailing) throw LinkError.Unreachable() states[path] = payload if (isConnected) deliver(path, payload, isState = true) } From 87ae198f9c2887d9f3be121e01984c4074e0798a Mon Sep 17 00:00:00 2001 From: Joao Victor Sena Date: Sun, 29 Nov 2026 18:31:27 -0300 Subject: [PATCH 13/38] refactor: drop the phone's watch removal that does not erase Co-Authored-By: Claude Opus 5.5 --- .../to/bitkit/repositories/WatchLinkRepo.kt | 2 +- .../to/bitkit/wear/link/PhoneLinkRepoTest.kt | 16 ++++----- .../kotlin/to/bitkit/wearlink/LinkDocs.kt | 4 +-- .../to/bitkit/wearlink/LinkEndpoints.kt | 17 +++++----- .../to/bitkit/wearlink/LinkEndpointsTest.kt | 34 +++++-------------- 5 files changed, 28 insertions(+), 45 deletions(-) diff --git a/app/src/main/java/to/bitkit/repositories/WatchLinkRepo.kt b/app/src/main/java/to/bitkit/repositories/WatchLinkRepo.kt index 9d43e8e847..c0d1470bfa 100644 --- a/app/src/main/java/to/bitkit/repositories/WatchLinkRepo.kt +++ b/app/src/main/java/to/bitkit/repositories/WatchLinkRepo.kt @@ -385,7 +385,7 @@ class WatchLinkRepo internal constructor( * marked, until it acknowledges: the erase is best effort, since a watch that never reconnects never reads it. */ suspend fun unpair(): Result = withContext(ioDispatcher) { - runSuspendCatching { link.remove(isErase = true) } + runSuspendCatching { link.remove() } .onFailure { Logger.warn("Failed to remove the watch", it, context = TAG) } } diff --git a/wear/src/test/java/to/bitkit/wear/link/PhoneLinkRepoTest.kt b/wear/src/test/java/to/bitkit/wear/link/PhoneLinkRepoTest.kt index 73cf9c393c..c9a27fd97e 100644 --- a/wear/src/test/java/to/bitkit/wear/link/PhoneLinkRepoTest.kt +++ b/wear/src/test/java/to/bitkit/wear/link/PhoneLinkRepoTest.kt @@ -312,7 +312,7 @@ class PhoneLinkRepoTest : BaseUnitTest(StandardTestDispatcher()) { seedStore.seed = WalletSeed(MNEMONIC, PASSPHRASE) pair().getOrThrow() - phoneLink.remove(isErase = true) + phoneLink.remove() runCurrent() inOrder(walletRepo) { @@ -331,7 +331,7 @@ class PhoneLinkRepoTest : BaseUnitTest(StandardTestDispatcher()) { pair().getOrThrow() whenever { walletRepo.noteEraseByPhone() }.thenReturn(Result.failure(SeedStoreError.Failed())) - phoneLink.remove(isErase = true) + phoneLink.remove() runCurrent() verify(walletRepo, never()).eraseByPhone() @@ -348,12 +348,12 @@ class PhoneLinkRepoTest : BaseUnitTest(StandardTestDispatcher()) { } @Test - fun `the phone's unpair keeps the wallet and lets the backup import hold again`() = test { + fun `the phone's revoke, as on a wipe, keeps the wallet and lets the backup import hold again`() = test { setUp() seedStore.seed = WalletSeed(MNEMONIC, PASSPHRASE) pair().getOrThrow() - phoneLink.remove(isErase = false) + phoneLink.forget() runCurrent() verify(walletRepo, never()).eraseByPhone() @@ -421,20 +421,20 @@ class PhoneLinkRepoTest : BaseUnitTest(StandardTestDispatcher()) { } @Test - fun `a new pairing and an unpair each clear what a phone said for the guards`() = test { + fun `a new pairing and a revoke each clear what a phone said for the guards`() = test { setUp() seedStore.seed = WalletSeed(MNEMONIC, PASSPHRASE) pair().getOrThrow() verify(sink).clearPeerState() - phoneLink.remove(isErase = false) + phoneLink.forget() runCurrent() verify(sink, times(2)).clearPeerState() } @Test - fun `a clear of what a phone said that fails does not stop a new pairing or an unpair`() = test { + fun `a clear of what a phone said that fails does not stop a new pairing or a revoke`() = test { setUp() seedStore.seed = WalletSeed(MNEMONIC, PASSPHRASE) whenever { sink.clearPeerState() }.thenThrow(IllegalStateException("disk")) @@ -442,7 +442,7 @@ class PhoneLinkRepoTest : BaseUnitTest(StandardTestDispatcher()) { pair().getOrThrow() assertNotNull(store.load()) - phoneLink.remove(isErase = false) + phoneLink.forget() runCurrent() assertNull(store.load()) diff --git a/wearlink/src/main/kotlin/to/bitkit/wearlink/LinkDocs.kt b/wearlink/src/main/kotlin/to/bitkit/wearlink/LinkDocs.kt index 2993480e13..62febe9c4e 100644 --- a/wearlink/src/main/kotlin/to/bitkit/wearlink/LinkDocs.kt +++ b/wearlink/src/main/kotlin/to/bitkit/wearlink/LinkDocs.kt @@ -59,8 +59,8 @@ data class StatusDoc( } } -/** A removal the phone asked for and the watch has not acknowledged. */ -enum class Removal { Unpair, Erase } +/** A removal the phone asked for and the watch has not acknowledged: the phone only ever asks for an erase. */ +enum class Removal { Erase } /** * One device's note of its pairing. It holds nothing secret: the keys are in the key store, under [pairingId]. diff --git a/wearlink/src/main/kotlin/to/bitkit/wearlink/LinkEndpoints.kt b/wearlink/src/main/kotlin/to/bitkit/wearlink/LinkEndpoints.kt index f7b22640e7..f49a2f7e91 100644 --- a/wearlink/src/main/kotlin/to/bitkit/wearlink/LinkEndpoints.kt +++ b/wearlink/src/main/kotlin/to/bitkit/wearlink/LinkEndpoints.kt @@ -194,17 +194,16 @@ class PhoneLink( } /** - * Asks the watch to forget the phone, and with [isErase] to delete its wallet too. The record stays, marked, - * until the watch acknowledges or [forget] drops it: an erase is best effort, since a watch that never - * reconnects never reads it. A removal that could not be stored for the watch is unmarked again and fails, so - * the phone never waits for a watch that was told nothing. + * Asks the watch to forget the phone and to delete its wallet: the phone's only removal that waits for the + * watch. The record stays, marked, until the watch acknowledges or [forget] drops it: an erase is best effort, + * since a watch that never reconnects never reads it. An erase that could not be stored for the watch is + * unmarked again and fails, so the phone never waits for a watch that was told nothing. */ - suspend fun remove(isErase: Boolean): Unit = locked { + suspend fun remove(): Unit = locked { val record = store.load() ?: throw LinkError.NotPaired() - val state = if (isErase) ControlDoc.State.Erase else ControlDoc.State.Revoked - val removal = if (isErase) Removal.Erase else Removal.Unpair - store.update { if (it?.pairingId == record.pairingId) it.copy(removal = removal) else it } - runSuspendCatching { publish(record, LinkPaths.CONTROL, encode(ControlDoc(state))) }.onFailure { error -> + store.update { if (it?.pairingId == record.pairingId) it.copy(removal = Removal.Erase) else it } + val erase = encode(ControlDoc(ControlDoc.State.Erase)) + runSuspendCatching { publish(record, LinkPaths.CONTROL, erase) }.onFailure { error -> store.update { if (it?.pairingId == record.pairingId) it.copy(removal = record.removal) else it } throw error } diff --git a/wearlink/src/test/kotlin/to/bitkit/wearlink/LinkEndpointsTest.kt b/wearlink/src/test/kotlin/to/bitkit/wearlink/LinkEndpointsTest.kt index 2fc33e47a0..aac0244dac 100644 --- a/wearlink/src/test/kotlin/to/bitkit/wearlink/LinkEndpointsTest.kt +++ b/wearlink/src/test/kotlin/to/bitkit/wearlink/LinkEndpointsTest.kt @@ -184,27 +184,11 @@ class LinkEndpointsTest { assertEquals(listOf(500L, 501L), harness.appliedSettings.map { it.changedAtMs }) } - @Test - fun `unpair from the phone ends the pairing on both sides and keeps the watch's wallet`() = runTest { - val harness = paired() - - harness.phoneLink.remove(isErase = false) - assertEquals(Removal.Unpair, assertNotNull(harness.phoneStore.load()).removal) - runCurrent() - - assertNull(harness.watchStore.load()) - assertNull(harness.phoneStore.load()) - assertTrue(harness.watchKeys.keys.isEmpty()) - assertTrue(harness.phoneKeys.keys.isEmpty()) - assertEquals(1, harness.unpairs) - assertEquals(0, harness.erases) - } - @Test fun `erase from the phone is acknowledged before the wallet goes, then the keys`() = runTest { val harness = paired() - harness.phoneLink.remove(isErase = true) + harness.phoneLink.remove() runCurrent() assertEquals(1, harness.erases) @@ -223,7 +207,7 @@ class LinkEndpointsTest { val harness = paired() harness.network.isStateWriteFailing = true - assertFailsWith { harness.phoneLink.remove(isErase = true) } + assertFailsWith { harness.phoneLink.remove() } runCurrent() assertNull(assertNotNull(harness.phoneStore.load()).removal) @@ -236,7 +220,7 @@ class LinkEndpointsTest { val harness = paired() harness.network.isConnected = false - harness.phoneLink.remove(isErase = true) + harness.phoneLink.remove() runCurrent() assertEquals(Removal.Erase, assertNotNull(harness.phoneStore.load()).removal) harness.phoneLink.forget() @@ -254,7 +238,7 @@ class LinkEndpointsTest { fun `an erase that failed is run again when the command is delivered again`() = runTest { val harness = paired() harness.eraseFailure = IllegalStateException("disk") - harness.phoneLink.remove(isErase = true) + harness.phoneLink.remove() runCurrent() assertEquals(0, harness.erases) assertNotNull(harness.watchStore.load()) @@ -272,7 +256,7 @@ class LinkEndpointsTest { val harness = paired() val statuses = harness.statePackets(LinkPaths.STATUS).size - harness.phoneLink.remove(isErase = true) + harness.phoneLink.remove() runCurrent() assertEquals(1, harness.eraseNotes) @@ -288,7 +272,7 @@ class LinkEndpointsTest { val harness = paired() val statuses = harness.statePackets(LinkPaths.STATUS).size harness.noteFailure = IllegalStateException("crash") - harness.phoneLink.remove(isErase = true) + harness.phoneLink.remove() runCurrent() assertEquals(0, harness.erases) @@ -313,7 +297,7 @@ class LinkEndpointsTest { val harness = paired() val statuses = harness.statePackets(LinkPaths.STATUS).size harness.crashAfterNote = IllegalStateException("crash") - harness.phoneLink.remove(isErase = true) + harness.phoneLink.remove() runCurrent() assertTrue(harness.eraseNotes > 0) assertEquals(statuses, harness.statePackets(LinkPaths.STATUS).size) @@ -332,7 +316,7 @@ class LinkEndpointsTest { @Test fun `an erase command of an earlier pairing does nothing`() = runTest { val harness = paired() - harness.phoneLink.remove(isErase = true) + harness.phoneLink.remove() runCurrent() val oldErase = harness.statePackets(LinkPaths.CONTROL).last() assertEquals(1, harness.erases) @@ -404,7 +388,7 @@ class LinkEndpointsTest { fun `nothing is published once a removal waits`() = runTest { val harness = paired() harness.network.isConnected = false - harness.phoneLink.remove(isErase = false) + harness.phoneLink.remove() val sent = harness.network.sent.size harness.phoneLink.publishSettings(quickPayOn) From afe911e3870fd4017940bd43566bfafc8c51c993 Mon Sep 17 00:00:00 2001 From: Joao Victor Sena Date: Sun, 29 Nov 2026 18:32:01 -0300 Subject: [PATCH 14/38] test: pin that the removed watch quickpay keys are ignored Co-Authored-By: Claude Opus 5.5 --- .../java/to/bitkit/models/BackupJsonTest.kt | 11 +++++++++++ .../wear/models/PhoneSettingsParserTest.kt | 11 +++++++++++ .../kotlin/to/bitkit/wearlink/LinkDocsTest.kt | 17 +++++++++++++++++ 3 files changed, 39 insertions(+) create mode 100644 wearlink/src/test/kotlin/to/bitkit/wearlink/LinkDocsTest.kt diff --git a/app/src/test/java/to/bitkit/models/BackupJsonTest.kt b/app/src/test/java/to/bitkit/models/BackupJsonTest.kt index 87f1ee3c6f..bb6ab2b17b 100644 --- a/app/src/test/java/to/bitkit/models/BackupJsonTest.kt +++ b/app/src/test/java/to/bitkit/models/BackupJsonTest.kt @@ -69,6 +69,17 @@ class BackupJsonTest { assertEquals(SettingsData().quickPayAmount, settings.quickPayAmount) } + @Test + fun `a backup with the watch's own quickpay keys of an earlier build decodes and keeps the phone's quickpay`() { + val raw = """{"version":1,"createdAt":1,"settings":{"isQuickPayEnabled":true,"quickPayAmount":10,""" + + """"isWatchQuickPayEnabled":true,"watchQuickPayAmount":20,"watchQuickPayDailyLimitMultiplier":2}}""" + + val settings = decodeSettingsBackup(raw).settings + + assertEquals(true, settings.isQuickPayEnabled) + assertEquals(10, settings.quickPayAmount) + } + @Test fun `a backup without the watch install prompt key, as from an older build or bitkit-ios, gives its default`() { val settings = decodeSettingsBackup(iosFixture("settings")).settings diff --git a/wear/src/test/java/to/bitkit/wear/models/PhoneSettingsParserTest.kt b/wear/src/test/java/to/bitkit/wear/models/PhoneSettingsParserTest.kt index e64841d057..5e3d168ddf 100644 --- a/wear/src/test/java/to/bitkit/wear/models/PhoneSettingsParserTest.kt +++ b/wear/src/test/java/to/bitkit/wear/models/PhoneSettingsParserTest.kt @@ -46,6 +46,17 @@ class PhoneSettingsParserTest { assertEquals(3_000L, settings.quickPay?.dailyCapCents) } + @Test + fun `the watch's own quickpay keys of an earlier build are ignored, and the phone's quickpay holds`() { + val settings = parse( + """{"version":1,"settings":{"isQuickPayEnabled":true,"quickPayAmount":5,""" + + """"quickPayDailyLimitMultiplier":5,"isWatchQuickPayEnabled":true,"watchQuickPayAmount":20,""" + + """"watchQuickPayDailyLimitMultiplier":2}}""", + ) + + assertEquals(QuickPayLimits(isEnabled = true, amountUsd = 5, dailyMultiplier = 5), settings.quickPay) + } + @Test fun `enums written by ios are read too`() { val settings = parse( diff --git a/wearlink/src/test/kotlin/to/bitkit/wearlink/LinkDocsTest.kt b/wearlink/src/test/kotlin/to/bitkit/wearlink/LinkDocsTest.kt new file mode 100644 index 0000000000..d1f2a2d59b --- /dev/null +++ b/wearlink/src/test/kotlin/to/bitkit/wearlink/LinkDocsTest.kt @@ -0,0 +1,17 @@ +package to.bitkit.wearlink + +import kotlin.test.Test +import kotlin.test.assertEquals + +class LinkDocsTest { + @Test + fun `a settings push with the watch's own quickpay keys of an earlier build reads as one without them`() { + val raw = """{"primaryDisplay":"BITCOIN","displayUnit":"MODERN","selectedCurrency":"EUR",""" + + """"isQuickPayEnabled":true,"quickPayAmount":5,"quickPayDailyLimitMultiplier":5,"changedAtMs":100,""" + + """"isWatchQuickPayEnabled":true,"watchQuickPayAmount":20,"watchQuickPayDailyLimitMultiplier":2}""" + + val settings = linkJson.decodeFromString(raw) + + assertEquals(SettingsDoc("BITCOIN", "MODERN", "EUR", true, 5, 5, changedAtMs = 100), settings) + } +} From 3f5e6ec177ffb3c392b51e4f208b7ea7be229d1a Mon Sep 17 00:00:00 2001 From: Joao Victor Sena Date: Sun, 29 Nov 2026 18:40:35 -0300 Subject: [PATCH 15/38] fix: celebrate a watch success once, never again on waking Co-Authored-By: Claude Opus 5.5 --- docs/wear.md | 8 +- journeys/wear/receive-paid-ambient.xml | 4 +- .../to/bitkit/wear/ui/components/Confetti.kt | 27 ++++++ .../wear/ui/components/SendOutcomeOverlay.kt | 24 ++++-- .../ui/screens/receive/ReceiveQrScreen.kt | 21 +++-- .../ui/screens/receive/ReceiveViewModel.kt | 6 +- .../bitkit/wear/ui/screens/send/SendScreen.kt | 14 +++- .../wear/ui/components/CelebrationTest.kt | 82 +++++++++++++++++++ .../ui/components/SendOutcomeOverlayTest.kt | 37 +++++++++ .../screens/receive/ReceiveQrContentTest.kt | 76 ++++++++++++++++- .../wear/ui/screens/send/SendResultTest.kt | 48 ++++++++++- 11 files changed, 323 insertions(+), 24 deletions(-) create mode 100644 wear/src/test/java/to/bitkit/wear/ui/components/CelebrationTest.kt diff --git a/docs/wear.md b/docs/wear.md index 578de8551b..6a58876919 100644 --- a/docs/wear.md +++ b/docs/wear.md @@ -211,8 +211,12 @@ On-screen copy stays short: a title or one line of at most about six words per s (squares in the spending purple, swaying, turning and flipping as they fall), over 2 s, then draws nothing more. Both start on the frame the screen plays its success haptic (the confirm haptic of a send, the firm click of a receive), so the three come together. In ambient mode there is neither: the always-on screen stays still, and the - haptic plays alone. With animations turned off both end at once. `SendResultTest` checks that only a sent result - has the confetti and that it is gone within 2 s; how it looks on a device is not checked. + haptic plays alone. Whether a success is celebrated is decided once, keyed on it (the payment's id, the outcome's + id, a flow's one send), as it is first shown (`rememberCelebration`): only one first shown awake is, and only + until the watch next goes ambient, so waking the watch on a Paid or Sent screen never plays it again; the decision + survives the screen being made again. With animations turned off both end at once. `CelebrationTest` checks the + decision; `SendResultTest`, `ReceiveQrContentTest` and `SendOutcomeOverlayTest` check where the confetti falls, + that it is gone within 2 s and that no wake plays it again; how it looks on a device is not checked. - **Tile.** The Bitkit tile (`BalanceTileService`) uses the tiles and ProtoLayout Material 3 libraries: a primary layout with the balance in the main slot and an edge button below. With a wallet it shows the balance in bitcoin, in the unit (Modern or Classic) imported from the phone, white, as on the Balance page, and a round Brand orange diff --git a/journeys/wear/receive-paid-ambient.xml b/journeys/wear/receive-paid-ambient.xml index a840c75c44..ef81a08128 100644 --- a/journeys/wear/receive-paid-ambient.xml +++ b/journeys/wear/receive-paid-ambient.xml @@ -1,7 +1,7 @@ An invoice paid while the watch is in ambient mode shows the check without the amount, so the always-on screen - shows no amount; waking the watch shows the amount. Emulator and physical watch. + shows no amount; waking the watch shows the amount, with no confetti then either. Emulator and physical watch. Precondition: Restored wallet on the local ./spark stack, see journeys/wear/README.md › Local ./spark stack and › Restored wallet, on the Balance page with the loading ring stopped, and the always-on screen on (README › Watch @@ -17,8 +17,10 @@ Run `../bitkit-docker/spark pay <invoice> 1000` from this repo's parent checkout Wait up to 20 s until "WatchReceivePaid" is listed Verify neither "WatchReceivePaidAmount" nor "WatchReceiveNew" is listed + Verify `adb shell uiautomator dump` does not list "WatchConfetti": the always-on screen has no confetti Run `adb shell input keyevent KEYCODE_WAKEUP` Wait up to 5 s until "WatchReceivePaidAmount" reads "1 000" + Verify at once that `adb shell uiautomator dump` does not list "WatchConfetti": waking plays no celebration Verify "WatchReceiveNew" is listed diff --git a/wear/src/main/java/to/bitkit/wear/ui/components/Confetti.kt b/wear/src/main/java/to/bitkit/wear/ui/components/Confetti.kt index cb55534ff9..eaabae34b1 100644 --- a/wear/src/main/java/to/bitkit/wear/ui/components/Confetti.kt +++ b/wear/src/main/java/to/bitkit/wear/ui/components/Confetti.kt @@ -10,9 +10,13 @@ import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.runtime.Composable import androidx.compose.runtime.LaunchedEffect +import androidx.compose.runtime.SideEffect import androidx.compose.runtime.derivedStateOf import androidx.compose.runtime.getValue +import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.remember +import androidx.compose.runtime.saveable.rememberSaveable +import androidx.compose.runtime.setValue import androidx.compose.ui.Modifier import androidx.compose.ui.geometry.Offset import androidx.compose.ui.geometry.Size @@ -82,6 +86,29 @@ fun Confetti( } } +/** + * Whether the success [key] names is celebrated right now, with [Confetti] and [PopIn]. That is decided once per + * success, on the frame it is first shown, the frame its haptic plays: only a success first shown awake is + * celebrated, and only until the screen next goes ambient, so waking the watch never plays it again, without its + * haptic. The decision outlives the screen being made again, so a success is celebrated at most once. A null [key] + * is no success; a caller whose success does not show in ambient mode passes null meanwhile. + */ +@Composable +fun rememberCelebration(key: String?, isAmbient: Boolean): Boolean { + var shownKey by rememberSaveable { mutableStateOf(null) } + var celebratedKey by remember { mutableStateOf(null) } + val isNew = key != null && key != shownKey + SideEffect { + if (isNew) { + shownKey = key + if (!isAmbient) celebratedKey = key + } + if (isAmbient) celebratedKey = null + } + // Answered on the first frame already, so the confetti starts on the same frame as the haptic. + return key != null && !isAmbient && (isNew || key == celebratedKey) +} + /** The thinnest a flipping piece gets, so it never vanishes edge on. */ private const val MIN_FLIP = 0.05f diff --git a/wear/src/main/java/to/bitkit/wear/ui/components/SendOutcomeOverlay.kt b/wear/src/main/java/to/bitkit/wear/ui/components/SendOutcomeOverlay.kt index c39b397df1..2dd351bb29 100644 --- a/wear/src/main/java/to/bitkit/wear/ui/components/SendOutcomeOverlay.kt +++ b/wear/src/main/java/to/bitkit/wear/ui/components/SendOutcomeOverlay.kt @@ -49,21 +49,32 @@ fun SendOutcomeOverlay( viewModel: SendOutcomeViewModel = hiltViewModel(), ) { val uiState by viewModel.uiState.collectAsStateWithLifecycle() + val isAmbient = isAmbient() + // Decided above the returns, as the outcome is first shown awake, so that waking the watch while it still shows + // neither plays its haptic nor its confetti again. + val isFirstShown = rememberCelebration(key = uiState.outcome?.id?.takeUnless { isAmbient }, isAmbient = isAmbient) val outcome = uiState.outcome ?: return - if (isAmbient()) return + if (isAmbient) return val haptic = LocalHapticFeedback.current LaunchedEffect(outcome.id) { + if (!isFirstShown) return@LaunchedEffect haptic.performHapticFeedback(if (outcome.isSent) HapticFeedbackType.Confirm else HapticFeedbackType.Reject) } BackHandler {} // Each outcome pops in, with its own confetti, also when it follows another. - key(outcome.id) { SpendingTheme { OutcomeContent(outcome = outcome, modifier = modifier) } } + key(outcome.id) { + SpendingTheme { + OutcomeContent(outcome = outcome, isCelebrated = isFirstShown && outcome.isSent, modifier = modifier) + } + } } +/** [isCelebrated] pops a sent outcome's check in under the confetti; see [rememberCelebration]. */ @Composable internal fun OutcomeContent( outcome: ShownOutcome, modifier: Modifier = Modifier, + isCelebrated: Boolean = false, ) { val description = stringResource( R.string.send__outcome_description, @@ -93,7 +104,7 @@ internal fun OutcomeContent( paneTitle = description } ) { - if (outcome.isSent) { + if (isCelebrated) { // The check pops in under the confetti on the frame the confirm haptic plays. PopIn { OutcomeIcon(outcome) } } else { @@ -101,7 +112,7 @@ internal fun OutcomeContent( } SmallAmountRow(amount = outcome.amount, amountTag = "WatchOutcomeAmount") } - if (outcome.isSent) Confetti() + if (isCelebrated) Confetti() } } @@ -119,7 +130,10 @@ private fun OutcomeIcon(outcome: ShownOutcome) { @Composable private fun PreviewSent() { WearPreview { - OutcomeContent(outcome = ShownOutcome("id", isSent = true, DisplayAmount(symbol = "₿", text = "21 000"))) + OutcomeContent( + outcome = ShownOutcome("id", isSent = true, DisplayAmount(symbol = "₿", text = "21 000")), + isCelebrated = true, + ) } } diff --git a/wear/src/main/java/to/bitkit/wear/ui/screens/receive/ReceiveQrScreen.kt b/wear/src/main/java/to/bitkit/wear/ui/screens/receive/ReceiveQrScreen.kt index 02b680f588..339c63b9ad 100644 --- a/wear/src/main/java/to/bitkit/wear/ui/screens/receive/ReceiveQrScreen.kt +++ b/wear/src/main/java/to/bitkit/wear/ui/screens/receive/ReceiveQrScreen.kt @@ -60,6 +60,7 @@ import to.bitkit.wear.ui.components.SmallAmountRow import to.bitkit.wear.ui.components.WearPreview import to.bitkit.wear.ui.components.WearPreviewDevices import to.bitkit.wear.ui.components.isAmbient +import to.bitkit.wear.ui.components.rememberCelebration import to.bitkit.wear.ui.modifiers.clickableAlpha import to.bitkit.wear.ui.screens.home.DisplayAmount import to.bitkit.wear.ui.theme.Colors @@ -214,9 +215,12 @@ internal fun ReceiveQrContent( ) { val qrContent = uiState.qrContent val paidAmount = uiState.paidAmount + // Kept here, above the paid check, so that the decision outlives ambient mode. + val isCelebrated = rememberCelebration(key = uiState.paidId, isAmbient = isAmbient) when { paidAmount != null -> Paid( amount = paidAmount.takeUnless { isAmbient }, + isCelebrated = isCelebrated, onClick = onRefreshClick, modifier = modifier ) @@ -316,17 +320,18 @@ private fun QrIcon(modifier: Modifier = Modifier) { ) } +/** [isCelebrated] pops the check in under the confetti, on the frame its haptic plays; see [rememberCelebration]. */ @Composable private fun Paid( amount: DisplayAmount?, + isCelebrated: Boolean, onClick: () -> Unit, modifier: Modifier = Modifier, ) { val isDimmed = amount == null CenteredScreen( edgeButton = amount?.let { { NewInvoiceButton(onClick) } }, - // The check pops in under the confetti on the frame its haptic plays; never on the always-on screen. - overlay = { if (!isDimmed) Confetti() }, + overlay = { if (isCelebrated) Confetti() }, modifier = modifier ) { Column( @@ -336,10 +341,10 @@ private fun Paid( .semantics(mergeDescendants = true) {} .testTag("WatchReceivePaid") ) { - if (isDimmed) { - PaidCheck(tint = Colors.White.copy(alpha = HIDDEN_ALPHA)) - } else { - PopIn { PaidCheck(tint = MaterialTheme.colorScheme.primary) } + when { + isDimmed -> PaidCheck(tint = Colors.White.copy(alpha = HIDDEN_ALPHA)) + isCelebrated -> PopIn { PaidCheck(tint = MaterialTheme.colorScheme.primary) } + else -> PaidCheck(tint = MaterialTheme.colorScheme.primary) } amount?.let { SmallAmountRow(amount = it, amountTag = "WatchReceivePaidAmount") } } @@ -436,7 +441,7 @@ private fun PreviewNfcOff() { private fun PreviewPaid() { WearPreview { ReceiveQrContent( - uiState = ReceiveUiState(paidAmount = DisplayAmount(symbol = "₿", text = "21 000")), + uiState = ReceiveUiState(paidId = "id", paidAmount = DisplayAmount(symbol = "₿", text = "21 000")), isAmbient = false, onRefreshClick = {}, ) @@ -448,7 +453,7 @@ private fun PreviewPaid() { private fun PreviewPaidAmbient() { WearPreview { ReceiveQrContent( - uiState = ReceiveUiState(paidAmount = DisplayAmount(symbol = "₿", text = "21 000")), + uiState = ReceiveUiState(paidId = "id", paidAmount = DisplayAmount(symbol = "₿", text = "21 000")), isAmbient = true, onRefreshClick = {}, ) diff --git a/wear/src/main/java/to/bitkit/wear/ui/screens/receive/ReceiveViewModel.kt b/wear/src/main/java/to/bitkit/wear/ui/screens/receive/ReceiveViewModel.kt index 35fddf99d2..301fb64dd6 100644 --- a/wear/src/main/java/to/bitkit/wear/ui/screens/receive/ReceiveViewModel.kt +++ b/wear/src/main/java/to/bitkit/wear/ui/screens/receive/ReceiveViewModel.kt @@ -168,7 +168,9 @@ class ReceiveViewModel internal constructor( Logger.info("Received payment '${payment.id}'", context = TAG) val unit = runSuspendCatching { settingsStore.data.first().displayUnit } .getOrDefault(BitcoinDisplayUnit.MODERN) - _uiState.update { ReceiveUiState(paidAmount = bitcoinAmount(payment.amountSats.toLong(), unit)) } + _uiState.update { + ReceiveUiState(paidId = payment.id, paidAmount = bitcoinAmount(payment.amountSats.toLong(), unit)) + } } } @@ -303,6 +305,8 @@ data class ReceiveUiState( val expiresAtSecs: Long? = null, val isLoading: Boolean = false, val isError: Boolean = false, + /** The payment that paid the invoice, which its celebration is decided for once. */ + val paidId: String? = null, /** What the paid invoice brought in, shown with the check. */ val paidAmount: DisplayAmount? = null, ) diff --git a/wear/src/main/java/to/bitkit/wear/ui/screens/send/SendScreen.kt b/wear/src/main/java/to/bitkit/wear/ui/screens/send/SendScreen.kt index 026dbad025..f3ea17a185 100644 --- a/wear/src/main/java/to/bitkit/wear/ui/screens/send/SendScreen.kt +++ b/wear/src/main/java/to/bitkit/wear/ui/screens/send/SendScreen.kt @@ -62,6 +62,7 @@ import to.bitkit.wear.ui.components.WearPreview import to.bitkit.wear.ui.components.WearPreviewDevices import to.bitkit.wear.ui.components.amountRowGap import to.bitkit.wear.ui.components.isAmbient +import to.bitkit.wear.ui.components.rememberCelebration import to.bitkit.wear.ui.components.rememberHoldToPayState import to.bitkit.wear.ui.screens.home.DisplayAmount import to.bitkit.wear.ui.theme.Colors @@ -72,6 +73,9 @@ private val STATUS_ICON_SIZE = 48.dp /** The opacity of the bolt that shows while the send is loading or under way. */ private const val LOADING_ICON_ALPHA = 0.4f +/** The celebration key of a flow's one sent result. */ +private const val SENT_KEY = "sent" + /** * The send flow of a deeplink: review with the hold to pay, the send under way, and its result, which closes the * flow by itself ([onClose]). The amount entry shows only for an input that names no amount. Offline before the @@ -166,6 +170,8 @@ internal fun Content( val step = uiState.step // The always-on screen shows no amount, typed, reviewed or sent, and nothing to hold. val isSent = step is SendStep.Done && step.result == SendResult.Sent + // Decided above the ambient screen, so that waking the watch does not play it again. A flow sends once. + val isCelebrated = rememberCelebration(key = SENT_KEY.takeIf { isSent }, isAmbient = isAmbient) if (isAmbient && (step is SendStep.Amount || step is SendStep.Review || isSent)) { Hidden(modifier = modifier) return @@ -190,6 +196,7 @@ internal fun Content( is SendStep.Done, is SendStep.Failed, SendStep.Offline -> Ended( step = step, isAmountShown = !isAmbient, + isCelebrated = isCelebrated, onCloseClick = onCloseClick, modifier = modifier ) @@ -412,6 +419,7 @@ private fun Sending( private fun Ended( step: SendStep, isAmountShown: Boolean, + isCelebrated: Boolean, onCloseClick: () -> Unit, modifier: Modifier = Modifier, ) { @@ -437,9 +445,9 @@ private fun Ended( textStyle = if (result == null) MaterialTheme.typography.titleSmall else MaterialTheme.typography.titleMedium, amount = (step as? SendStep.Done)?.amount.takeIf { isAmountShown && result != SendResult.Unknown }, onCloseClick = onCloseClick.takeIf { result == null }, - modifier = modifier, - // Sent pops its check in under the confetti, on the frame its haptic plays; never on the always-on screen. - isCelebrated = result == SendResult.Sent && isAmountShown, + // Sent pops its check in under the confetti, on the frame its haptic plays; see rememberCelebration. + isCelebrated = isCelebrated && result == SendResult.Sent, + modifier = modifier ) } diff --git a/wear/src/test/java/to/bitkit/wear/ui/components/CelebrationTest.kt b/wear/src/test/java/to/bitkit/wear/ui/components/CelebrationTest.kt new file mode 100644 index 0000000000..4ddf2f253b --- /dev/null +++ b/wear/src/test/java/to/bitkit/wear/ui/components/CelebrationTest.kt @@ -0,0 +1,82 @@ +package to.bitkit.wear.ui.components + +import androidx.activity.ComponentActivity +import androidx.compose.runtime.getValue +import androidx.compose.runtime.mutableStateOf +import androidx.compose.runtime.setValue +import androidx.compose.ui.test.junit4.StateRestorationTester +import androidx.compose.ui.test.junit4.createAndroidComposeRule +import org.junit.Rule +import org.junit.Test +import org.junit.runner.RunWith +import org.robolectric.RobolectricTestRunner +import org.robolectric.annotation.Config +import kotlin.test.assertEquals +import kotlin.test.assertFalse +import kotlin.test.assertTrue + +/** When a success is celebrated: once, as it is first shown awake, and never again on waking or a new screen. */ +@Config(sdk = [34]) +@RunWith(RobolectricTestRunner::class) +class CelebrationTest { + @get:Rule + val composeRule = createAndroidComposeRule() + + private var key by mutableStateOf("payment-0") + private var isAmbient by mutableStateOf(false) + private var isCelebrated: Boolean? = null + + private fun setContent() = composeRule.setContent { isCelebrated = rememberCelebration(key, isAmbient) } + + private fun isCelebrated(): Boolean { + composeRule.waitForIdle() + return checkNotNull(isCelebrated) + } + + @Test + fun `a success first shown awake is celebrated until the watch goes ambient, and not again on waking`() { + setContent() + assertTrue(isCelebrated()) + + isAmbient = true + assertFalse(isCelebrated()) + + isAmbient = false + assertFalse(isCelebrated()) + } + + @Test + fun `a success first shown in ambient mode is never celebrated`() { + isAmbient = true + setContent() + assertFalse(isCelebrated()) + + isAmbient = false + assertFalse(isCelebrated()) + } + + @Test + fun `no success is no celebration, and the next success is celebrated`() { + key = null + setContent() + assertFalse(isCelebrated()) + + key = "payment-0" + assertTrue(isCelebrated()) + key = null + assertFalse(isCelebrated()) + key = "payment-1" + assertTrue(isCelebrated()) + } + + @Test + fun `a success is not celebrated again when the screen is made again`() { + val restoration = StateRestorationTester(composeRule) + restoration.setContent { isCelebrated = rememberCelebration(key, isAmbient) } + assertTrue(isCelebrated()) + + restoration.emulateSavedInstanceStateRestore() + + assertEquals(false, isCelebrated) + } +} diff --git a/wear/src/test/java/to/bitkit/wear/ui/components/SendOutcomeOverlayTest.kt b/wear/src/test/java/to/bitkit/wear/ui/components/SendOutcomeOverlayTest.kt index 63416e26c8..297c9647ef 100644 --- a/wear/src/test/java/to/bitkit/wear/ui/components/SendOutcomeOverlayTest.kt +++ b/wear/src/test/java/to/bitkit/wear/ui/components/SendOutcomeOverlayTest.kt @@ -1,6 +1,10 @@ package to.bitkit.wear.ui.components import androidx.activity.ComponentActivity +import androidx.compose.runtime.getValue +import androidx.compose.runtime.mutableStateOf +import androidx.compose.runtime.setValue +import androidx.compose.runtime.snapshots.Snapshot import androidx.compose.ui.semantics.SemanticsProperties import androidx.compose.ui.test.SemanticsMatcher import androidx.compose.ui.test.assert @@ -24,6 +28,10 @@ import to.bitkit.wear.ui.screens.home.DisplayAmount class SendOutcomeOverlayTest { private companion object { val AMOUNT = DisplayAmount(symbol = "₿", text = "1 000") + + /** A few frames, enough for a change of state to show, well within the confetti's 2 s. */ + const val FRAMES_MS = 100L + fun isPane(title: String) = SemanticsMatcher.expectValue(SemanticsProperties.PaneTitle, title) val isLiveRegion = SemanticsMatcher.keyIsDefined(SemanticsProperties.LiveRegion) } @@ -31,6 +39,12 @@ class SendOutcomeOverlayTest { @get:Rule val composeRule = createAndroidComposeRule() + /** Tells Compose of the test's own changes of state, then lets a few frames run, as the clock is driven here. */ + private fun advanceFrames() { + Snapshot.sendApplyNotifications() + composeRule.mainClock.advanceTimeBy(FRAMES_MS) + } + @Test fun `a sent outcome is a pane titled with its status and amount`() { composeRule.setContent { WearPreview { OutcomeContent(ShownOutcome("id", isSent = true, AMOUNT)) } } @@ -52,6 +66,29 @@ class SendOutcomeOverlayTest { .assert(isPane("Payment failed, ₿ 1 000")) } + @Test + fun `a sent outcome shown for the first time lets the confetti fall, and a failed one has none`() { + composeRule.mainClock.autoAdvance = false + var outcome by mutableStateOf(ShownOutcome("id", isSent = true, AMOUNT)) + composeRule.setContent { WearPreview { OutcomeContent(outcome, isCelebrated = outcome.isSent) } } + advanceFrames() + composeRule.onNodeWithTag("WatchConfetti").assertExists() + + outcome = ShownOutcome("id-1", isSent = false, AMOUNT) + advanceFrames() + composeRule.onNodeWithTag("WatchConfetti").assertDoesNotExist() + } + + @Test + fun `an outcome that is not celebrated, as one shown again after ambient mode, has no confetti`() { + composeRule.mainClock.autoAdvance = false + composeRule.setContent { WearPreview { OutcomeContent(ShownOutcome("id", isSent = true, AMOUNT)) } } + advanceFrames() + + composeRule.onNodeWithTag("WatchOutcomeSent").assertExists() + composeRule.onNodeWithTag("WatchConfetti").assertDoesNotExist() + } + @Test fun `the outcome is one node, with nothing of its own beneath for a screen reader to step through`() { composeRule.setContent { WearPreview { OutcomeContent(ShownOutcome("id", isSent = true, AMOUNT)) } } diff --git a/wear/src/test/java/to/bitkit/wear/ui/screens/receive/ReceiveQrContentTest.kt b/wear/src/test/java/to/bitkit/wear/ui/screens/receive/ReceiveQrContentTest.kt index d7bbe720c1..17f64746e1 100644 --- a/wear/src/test/java/to/bitkit/wear/ui/screens/receive/ReceiveQrContentTest.kt +++ b/wear/src/test/java/to/bitkit/wear/ui/screens/receive/ReceiveQrContentTest.kt @@ -1,6 +1,10 @@ package to.bitkit.wear.ui.screens.receive import androidx.activity.ComponentActivity +import androidx.compose.runtime.getValue +import androidx.compose.runtime.mutableStateOf +import androidx.compose.runtime.setValue +import androidx.compose.runtime.snapshots.Snapshot import androidx.compose.ui.semantics.SemanticsActions import androidx.compose.ui.semantics.getOrNull import androidx.compose.ui.test.SemanticsMatcher @@ -33,10 +37,21 @@ import kotlin.time.toJavaDuration @Config(sdk = [34], qualifiers = "w227dp-h227dp-round") @RunWith(RobolectricTestRunner::class) class ReceiveQrContentTest { + private companion object { + /** A few frames, enough for a change of state to show, well within the confetti's 2 s. */ + const val FRAMES_MS = 100L + } + @get:Rule val composeRule = createAndroidComposeRule() - private val paid = ReceiveUiState(paidAmount = DisplayAmount(symbol = "₿", text = "50 000")) + /** Tells Compose of the test's own changes of state, then lets a few frames run, as the clock is driven here. */ + private fun advanceFrames() { + Snapshot.sendApplyNotifications() + composeRule.mainClock.advanceTimeBy(FRAMES_MS) + } + + private val paid = ReceiveUiState(paidId = "payment-0", paidAmount = DisplayAmount(symbol = "₿", text = "50 000")) private val shown = ReceiveUiState(qrContent = "LNBCRT1TEST") private var shows = 0 private var refreshes = 0 @@ -88,6 +103,56 @@ class ReceiveQrContentTest { composeRule.onNodeWithTag("WatchReceiveHidden").assertDoesNotExist() } + @Test + fun `a paid invoice celebrates once, and waking from ambient mode does not play it again`() { + composeRule.mainClock.autoAdvance = false + var isAmbient by mutableStateOf(false) + setContent(paid, isAmbient = { isAmbient }) + advanceFrames() + composeRule.onNodeWithTag("WatchConfetti").assertExists() + + isAmbient = true + advanceFrames() + composeRule.onNodeWithTag("WatchConfetti").assertDoesNotExist() + + isAmbient = false + advanceFrames() + composeRule.onNodeWithTag("WatchConfetti").assertDoesNotExist() + composeRule.onNodeWithTag("WatchReceivePaidAmount", useUnmergedTree = true).assertExists() + } + + @Test + fun `an invoice paid in ambient mode has no confetti, then or on waking`() { + composeRule.mainClock.autoAdvance = false + var isAmbient by mutableStateOf(true) + setContent(paid, isAmbient = { isAmbient }) + advanceFrames() + composeRule.onNodeWithTag("WatchConfetti").assertDoesNotExist() + + isAmbient = false + advanceFrames() + composeRule.onNodeWithTag("WatchConfetti").assertDoesNotExist() + composeRule.onNodeWithTag("WatchReceivePaid").assertExists() + } + + @Test + fun `the next paid invoice is celebrated too`() { + composeRule.mainClock.autoAdvance = false + var uiState by mutableStateOf(paid) + composeRule.setContent { + WearPreview { ReceiveQrContent(uiState = uiState, isAmbient = false, onRefreshClick = {}) } + } + composeRule.mainClock.advanceTimeBy(2_100) + composeRule.onNodeWithTag("WatchConfetti").assertDoesNotExist() + + uiState = shown + advanceFrames() + uiState = paid.copy(paidId = "payment-1") + advanceFrames() + + composeRule.onNodeWithTag("WatchConfetti").assertExists() + } + @Test fun `a tap anywhere on the resting screen shows the qr again`() { setContent(shown, isAmbient = false, isResting = true) @@ -204,12 +269,19 @@ class ReceiveQrContentTest { isAmbient: Boolean, isResting: Boolean = false, nfcHint: NfcHintState = NfcHintState.Hidden, + ) = setContent(uiState, isAmbient = { isAmbient }, isResting = isResting, nfcHint = nfcHint) + + private fun setContent( + uiState: ReceiveUiState, + isAmbient: () -> Boolean, + isResting: Boolean = false, + nfcHint: NfcHintState = NfcHintState.Hidden, ) { composeRule.setContent { WearPreview { ReceiveQrContent( uiState = uiState, - isAmbient = isAmbient, + isAmbient = isAmbient(), onRefreshClick = { refreshes++ }, isResting = isResting, nfcHint = nfcHint, diff --git a/wear/src/test/java/to/bitkit/wear/ui/screens/send/SendResultTest.kt b/wear/src/test/java/to/bitkit/wear/ui/screens/send/SendResultTest.kt index b04ee06068..ab288d4fe9 100644 --- a/wear/src/test/java/to/bitkit/wear/ui/screens/send/SendResultTest.kt +++ b/wear/src/test/java/to/bitkit/wear/ui/screens/send/SendResultTest.kt @@ -4,6 +4,7 @@ import androidx.activity.ComponentActivity import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.setValue +import androidx.compose.runtime.snapshots.Snapshot import androidx.compose.ui.semantics.LiveRegionMode import androidx.compose.ui.semantics.SemanticsProperties import androidx.compose.ui.test.SemanticsMatcher @@ -27,11 +28,20 @@ import kotlin.test.assertEquals class SendResultTest { private companion object { val AMOUNT = DisplayAmount(symbol = "₿", text = "1 000") + + /** A few frames, enough for a change of state to show, well within the confetti's 2 s. */ + const val FRAMES_MS = 100L } @get:Rule val composeRule = createAndroidComposeRule() + /** Tells Compose of the test's own changes of state, then lets a few frames run, as the clock is driven here. */ + private fun advanceFrames() { + Snapshot.sendApplyNotifications() + composeRule.mainClock.advanceTimeBy(FRAMES_MS) + } + @Test fun `a pending result shows its amount`() { setResult(SendStep.Done(SendResult.Pending, AMOUNT), isAmbient = false) @@ -88,6 +98,38 @@ class SendResultTest { composeRule.onNodeWithTag("WatchSendSent").assertIsDisplayed() } + @Test + fun `a sent result celebrates once, and waking from ambient mode does not play it again`() { + composeRule.mainClock.autoAdvance = false + var isAmbient by mutableStateOf(false) + setResult(SendStep.Done(SendResult.Sent, AMOUNT), isAmbient = { isAmbient }) + advanceFrames() + composeRule.onNodeWithTag("WatchConfetti").assertExists() + + isAmbient = true + advanceFrames() + composeRule.onNodeWithTag("WatchSendHidden").assertExists() + composeRule.onNodeWithTag("WatchConfetti").assertDoesNotExist() + + isAmbient = false + advanceFrames() + composeRule.onNodeWithTag("WatchSendSent").assertExists() + composeRule.onNodeWithTag("WatchConfetti").assertDoesNotExist() + } + + @Test + fun `a payment sent while in ambient mode has no confetti on waking`() { + composeRule.mainClock.autoAdvance = false + var isAmbient by mutableStateOf(true) + setResult(SendStep.Done(SendResult.Sent, AMOUNT), isAmbient = { isAmbient }) + advanceFrames() + + isAmbient = false + advanceFrames() + composeRule.onNodeWithTag("WatchSendSent").assertExists() + composeRule.onNodeWithTag("WatchConfetti").assertDoesNotExist() + } + @Test fun `only a sent result has confetti`() { setResult(SendStep.Done(SendResult.Pending, AMOUNT), isAmbient = false) @@ -138,12 +180,14 @@ class SendResultTest { composeRule.onNodeWithTag("WatchSendWaiting").assertDoesNotExist() } - private fun setResult(step: SendStep, isAmbient: Boolean) { + private fun setResult(step: SendStep, isAmbient: Boolean) = setResult(step, isAmbient = { isAmbient }) + + private fun setResult(step: SendStep, isAmbient: () -> Boolean) { composeRule.setContent { WearPreview { Content( uiState = SendUiState(step = step), - isAmbient = isAmbient, + isAmbient = isAmbient(), onAmountChange = {}, onAmountConfirm = {}, onHoldComplete = {}, From c6f35528c9c175043421b780150f69300af54094 Mon Sep 17 00:00:00 2001 From: Joao Victor Sena Date: Sun, 29 Nov 2026 18:43:36 -0300 Subject: [PATCH 16/38] fix: scroll the watch's activity detail and follow the 24 h setting Co-Authored-By: Claude Opus 5.5 --- .../main/java/to/bitkit/wear/ext/Context.kt | 5 + .../screens/activity/ActivityDetailScreen.kt | 132 +++++++++++------- .../ui/screens/activity/ActivityScreen.kt | 50 +++++-- .../activity/ActivityDetailContentTest.kt | 71 ++++++++++ 4 files changed, 202 insertions(+), 56 deletions(-) create mode 100644 wear/src/test/java/to/bitkit/wear/ui/screens/activity/ActivityDetailContentTest.kt diff --git a/wear/src/main/java/to/bitkit/wear/ext/Context.kt b/wear/src/main/java/to/bitkit/wear/ext/Context.kt index a8ac908d0b..9e7e85e55b 100644 --- a/wear/src/main/java/to/bitkit/wear/ext/Context.kt +++ b/wear/src/main/java/to/bitkit/wear/ext/Context.kt @@ -7,6 +7,7 @@ import android.content.Intent import android.net.ConnectivityManager import android.nfc.NfcAdapter import android.provider.Settings +import android.text.format.DateFormat import to.bitkit.wear.utils.Logger private const val TAG = "Context" @@ -17,6 +18,10 @@ val Context.keyguardManager: KeyguardManager val Context.connectivityManager: ConnectivityManager get() = getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager +/** Whether the watch writes times in 24 hours. */ +val Context.is24HourTimeFormat: Boolean + get() = DateFormat.is24HourFormat(this) + /** Whether the wearer turned animations off, so motion that only decorates should stay still. */ val Context.areAnimationsDisabled: Boolean get() = Settings.Global.getFloat(contentResolver, Settings.Global.ANIMATOR_DURATION_SCALE, 1f) == 0f diff --git a/wear/src/main/java/to/bitkit/wear/ui/screens/activity/ActivityDetailScreen.kt b/wear/src/main/java/to/bitkit/wear/ui/screens/activity/ActivityDetailScreen.kt index 0ddf69070f..9a97712d0c 100644 --- a/wear/src/main/java/to/bitkit/wear/ui/screens/activity/ActivityDetailScreen.kt +++ b/wear/src/main/java/to/bitkit/wear/ui/screens/activity/ActivityDetailScreen.kt @@ -6,8 +6,10 @@ import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.runtime.Composable import androidx.compose.runtime.getValue +import androidx.compose.runtime.remember import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier +import androidx.compose.ui.graphics.Color import androidx.compose.ui.platform.testTag import androidx.compose.ui.res.stringResource import androidx.compose.ui.text.style.TextAlign @@ -25,6 +27,7 @@ import to.bitkit.wear.models.WatchPayment import to.bitkit.wear.ui.components.BezelLoading import to.bitkit.wear.ui.components.CenteredScreen import to.bitkit.wear.ui.components.LargeAmountRow +import to.bitkit.wear.ui.components.ListScreen import to.bitkit.wear.ui.components.WearPreview import to.bitkit.wear.ui.components.WearPreviewDevices import to.bitkit.wear.ui.components.isAmbient @@ -34,13 +37,15 @@ import to.bitkit.wear.ui.theme.Colors /** The size of the status icon beside the status word. */ private val STATUS_ICON_SIZE = 24.dp -/** The most lines a payment's note takes; a longer one ends in an ellipsis. */ -private const val MESSAGE_MAX_LINES = 2 +/** + * The most lines a line of the detail takes: a payment's note, or a day and time that a long month name or a large + * font pushes past one line, as the list gives it; a longer one ends in an ellipsis. + */ +private const val LINE_MAX_LINES = 2 /** * One payment of the activity list: its amount, the fee of a send, its note when it has one, when it was made and - * its status. It reads the - * payment from the list's [viewModel], which belongs to Home. + * its status. It reads the payment from the list's [viewModel], which belongs to Home. */ @Composable fun ActivityDetailScreen( @@ -54,7 +59,7 @@ fun ActivityDetailScreen( Missing(isLoading = !uiState.isLoaded, modifier = modifier) return } - Content(payment = payment, unit = uiState.unit, isAmbient = isAmbient(), modifier = modifier) + ActivityDetailContent(payment = payment, unit = uiState.unit, isAmbient = isAmbient(), modifier = modifier) } /** Stands in for a payment the list does not hold: while the list loads, or after newer payments pushed it out. */ @@ -71,56 +76,69 @@ private fun Missing( } } +/** + * A list that scrolls, also with the rotary input, so that a payment with a fee and a note still reaches its status on + * the smallest round screen. + */ @Composable -private fun Content( +internal fun ActivityDetailContent( payment: WatchPayment, unit: BitcoinDisplayUnit, isAmbient: Boolean, modifier: Modifier = Modifier, ) { - CenteredScreen(modifier = modifier) { + val is24Hour = rememberIs24HourFormat() + // The phone's activity detail writes the day and the time, without the year. + val time = remember(payment.timestampSecs, is24Hour) { + uiDateText(payment.timestampSecs, UiDateStyle.DATE_TIME, is24Hour) + } + ListScreen(modifier = modifier) { if (!isAmbient) { - BoxWithConstraints(contentAlignment = Alignment.Center, modifier = Modifier.fillMaxWidth()) { - LargeAmountRow( - amount = bitcoinAmount(payment.amountSats.toLong(), unit), - maxWidth = maxWidth, - amountTag = "WatchActivityDetailAmount", - symbolTag = "WatchActivityDetailSymbol", - ) + item { + BoxWithConstraints(contentAlignment = Alignment.Center, modifier = Modifier.fillMaxWidth()) { + LargeAmountRow( + amount = bitcoinAmount(payment.amountSats.toLong(), unit), + maxWidth = maxWidth, + amountTag = "WatchActivityDetailAmount", + symbolTag = "WatchActivityDetailSymbol", + ) + } } } if (payment.isSent && payment.feeSats > 0uL && !isAmbient) { - val fee = bitcoinAmount(payment.feeSats.toLong(), unit) - Line( - text = stringResource(R.string.send__fee, "${fee.symbol} ${fee.text}"), - modifier = Modifier.testTag("WatchActivityDetailFee") - ) + item { + val fee = bitcoinAmount(payment.feeSats.toLong(), unit) + Line( + text = stringResource(R.string.send__fee, "${fee.symbol} ${fee.text}"), + modifier = Modifier.testTag("WatchActivityDetailFee") + ) + } + } + payment.message?.takeIf { !isAmbient }?.let { message -> + item { + Line( + text = message, + color = Color.Unspecified, + modifier = Modifier.testTag("WatchActivityDetailMessage") + ) + } } - payment.message?.takeIf { !isAmbient }?.let { - Text( - text = it, - style = MaterialTheme.typography.bodySmall, - textAlign = TextAlign.Center, - maxLines = MESSAGE_MAX_LINES, - overflow = TextOverflow.Ellipsis, - modifier = Modifier.testTag("WatchActivityDetailMessage") - ) + item { + Line(text = time, modifier = Modifier.testTag("WatchActivityDetailTime")) } - // The phone's activity detail writes the day and the time, without the year. - Line( - text = uiDateText(payment.timestampSecs, UiDateStyle.DATE_TIME, rememberIs24HourFormat()), - modifier = Modifier.testTag("WatchActivityDetailTime") - ) - Row( - verticalAlignment = Alignment.CenterVertically, - horizontalArrangement = Arrangement.spacedBy(4.dp), - ) { - ActivityIcon(payment = payment, size = STATUS_ICON_SIZE) - Text( - text = stringResource(payment.state.text()), - style = MaterialTheme.typography.bodyMedium, - modifier = Modifier.testTag("WatchActivityDetailStatus") - ) + item { + Row( + verticalAlignment = Alignment.CenterVertically, + horizontalArrangement = Arrangement.spacedBy(4.dp, Alignment.CenterHorizontally), + modifier = Modifier.fillMaxWidth() + ) { + ActivityIcon(payment = payment, size = STATUS_ICON_SIZE) + Text( + text = stringResource(payment.state.text()), + style = MaterialTheme.typography.bodyMedium, + modifier = Modifier.testTag("WatchActivityDetailStatus") + ) + } } } } @@ -135,14 +153,16 @@ private fun PaymentState.text(): Int = when (this) { private fun Line( text: String, modifier: Modifier = Modifier, + color: Color = Colors.White64, ) { Text( text = text, style = MaterialTheme.typography.bodySmall, - color = Colors.White64, + color = color, textAlign = TextAlign.Center, - maxLines = 1, - modifier = modifier + maxLines = LINE_MAX_LINES, + overflow = TextOverflow.Ellipsis, + modifier = modifier.fillMaxWidth() ) } @@ -150,6 +170,24 @@ private fun Line( @Composable private fun Preview() { WearPreview { - Content(payment = PreviewPayment.copy(message = "Coffee"), unit = BitcoinDisplayUnit.MODERN, isAmbient = false) + ActivityDetailContent( + payment = PreviewPayment.copy(message = PREVIEW_NOTE), + unit = BitcoinDisplayUnit.MODERN, + isAmbient = false, + ) + } +} + +@WearPreviewDevices +@Composable +private fun PreviewAmbient() { + WearPreview { + ActivityDetailContent( + payment = PreviewPayment.copy(message = PREVIEW_NOTE), + unit = BitcoinDisplayUnit.MODERN, + isAmbient = true, + ) } } + +private const val PREVIEW_NOTE = "Coffee and two croissants at the corner bakery" diff --git a/wear/src/main/java/to/bitkit/wear/ui/screens/activity/ActivityScreen.kt b/wear/src/main/java/to/bitkit/wear/ui/screens/activity/ActivityScreen.kt index c412950acb..7dcfed2955 100644 --- a/wear/src/main/java/to/bitkit/wear/ui/screens/activity/ActivityScreen.kt +++ b/wear/src/main/java/to/bitkit/wear/ui/screens/activity/ActivityScreen.kt @@ -1,20 +1,27 @@ package to.bitkit.wear.ui.screens.activity -import android.text.format.DateFormat +import android.content.BroadcastReceiver +import android.content.Context +import android.content.Intent +import android.content.IntentFilter import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.size import androidx.compose.runtime.Composable +import androidx.compose.runtime.DisposableEffect import androidx.compose.runtime.getValue +import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.produceState import androidx.compose.runtime.remember +import androidx.compose.runtime.setValue import androidx.compose.ui.Modifier import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.platform.testTag import androidx.compose.ui.res.painterResource import androidx.compose.ui.res.stringResource import androidx.compose.ui.unit.dp +import androidx.core.content.ContextCompat import androidx.hilt.lifecycle.viewmodel.compose.hiltViewModel import androidx.lifecycle.compose.collectAsStateWithLifecycle import androidx.wear.compose.material3.FilledTonalButton @@ -27,6 +34,7 @@ import androidx.wear.compose.material3.lazy.transformedHeight import kotlinx.collections.immutable.persistentListOf import kotlinx.coroutines.delay import to.bitkit.wear.R +import to.bitkit.wear.ext.is24HourTimeFormat import to.bitkit.wear.ext.uiDateStyleFor import to.bitkit.wear.ext.uiDateText import to.bitkit.wear.models.BITCOIN_SYMBOL @@ -123,6 +131,10 @@ private fun List( modifier: Modifier = Modifier, ) { val is24Hour = rememberIs24HourFormat() + // A row's time depends on the day only, so each is written again when the day or the time format changes. + val today = remember(uiState.nowSecs) { + Instant.ofEpochSecond(uiState.nowSecs).atZone(ZoneId.systemDefault()).toLocalDate() + } Box(modifier = modifier.fillMaxSize()) { ListScreen { spec -> item { @@ -135,15 +147,15 @@ private fun List( } uiState.payments.forEachIndexed { index, payment -> item(key = payment.id) { + val time = remember(payment.timestampSecs, today, is24Hour) { + activityTimeText(payment.timestampSecs.toLong(), uiState.nowSecs, is24Hour) + } FilledTonalButton( onClick = { onPaymentClick(payment.id) }, icon = { ActivityIcon(payment = payment) }, label = { Text(text = payment.amountText(uiState.unit), maxLines = 2) }, secondaryLabel = { - Text( - text = activityTimeText(payment.timestampSecs.toLong(), uiState.nowSecs, is24Hour), - maxLines = 2, - ) + Text(text = time, maxLines = 2) }, transformation = SurfaceTransformation(spec), modifier = Modifier @@ -180,11 +192,31 @@ internal fun activityTimeText( return uiDateText(timestamp, uiDateStyleFor(timestamp, today, zone), is24Hour, locale, zone) } -/** Whether the watch writes times in 24 hours, as the phone's activity reads its own setting. */ +/** + * Whether the watch writes times in 24 hours, as the phone's activity reads its own setting, and again whenever the + * time format or the clock changes. Copied from app/src/main/java/to/bitkit/ui/utils/DateText.kt; keep both in sync. + */ @Composable -internal fun rememberIs24HourFormat(): Boolean { - val context = LocalContext.current - return remember(context) { DateFormat.is24HourFormat(context) } +internal fun rememberIs24HourFormat(context: Context = LocalContext.current): Boolean { + var is24Hour by remember(context) { mutableStateOf(context.is24HourTimeFormat) } + + DisposableEffect(context) { + val receiver = object : BroadcastReceiver() { + override fun onReceive(receiverContext: Context?, intent: Intent?) = run { + is24Hour = context.is24HourTimeFormat + } + } + ContextCompat.registerReceiver( + context, + receiver, + IntentFilter(Intent.ACTION_TIME_CHANGED), + ContextCompat.RECEIVER_NOT_EXPORTED, + ) + + onDispose { context.unregisterReceiver(receiver) } + } + + return is24Hour } @Composable diff --git a/wear/src/test/java/to/bitkit/wear/ui/screens/activity/ActivityDetailContentTest.kt b/wear/src/test/java/to/bitkit/wear/ui/screens/activity/ActivityDetailContentTest.kt new file mode 100644 index 0000000000..30d701bc8c --- /dev/null +++ b/wear/src/test/java/to/bitkit/wear/ui/screens/activity/ActivityDetailContentTest.kt @@ -0,0 +1,71 @@ +package to.bitkit.wear.ui.screens.activity + +import androidx.activity.ComponentActivity +import androidx.compose.runtime.getValue +import androidx.compose.runtime.mutableStateOf +import androidx.compose.runtime.setValue +import androidx.compose.ui.test.assertIsDisplayed +import androidx.compose.ui.test.assertTextEquals +import androidx.compose.ui.test.junit4.createAndroidComposeRule +import androidx.compose.ui.test.onNodeWithTag +import androidx.compose.ui.test.onRoot +import androidx.compose.ui.test.performTouchInput +import androidx.compose.ui.test.swipeUp +import org.junit.Rule +import org.junit.Test +import org.junit.runner.RunWith +import org.robolectric.RobolectricTestRunner +import org.robolectric.annotation.Config +import to.bitkit.wear.models.BitcoinDisplayUnit +import to.bitkit.wear.ui.components.WearPreview + +/** A payment's detail: its note, hidden in ambient mode, and a status that every round screen reaches. */ +@Config(sdk = [34], qualifiers = "w227dp-h227dp-round") +@RunWith(RobolectricTestRunner::class) +class ActivityDetailContentTest { + private companion object { + val NOTED = PreviewPayment.copy(feeSats = 250uL, message = "Coffee and two croissants at the corner bakery") + } + + @get:Rule + val composeRule = createAndroidComposeRule() + + private var isAmbient by mutableStateOf(false) + + @Test + fun `a sent payment with a fee and a note scrolls to its status`() = assertStatusReached() + + @Test + @Config(sdk = [34], qualifiers = "w192dp-h192dp-round") + fun `a sent payment with a fee and a note scrolls to its status on the smallest round screen`() = + assertStatusReached() + + @Test + fun `the note shows awake and hides in ambient mode, with the amount`() { + setContent() + composeRule.onNodeWithTag("WatchActivityDetailMessage").assertTextEquals(NOTED.message.orEmpty()) + + isAmbient = true + composeRule.onNodeWithTag("WatchActivityDetailMessage").assertDoesNotExist() + composeRule.onNodeWithTag("WatchActivityDetailAmount", useUnmergedTree = true).assertDoesNotExist() + composeRule.onNodeWithTag("WatchActivityDetailStatus").assertIsDisplayed() + } + + private fun assertStatusReached() { + setContent() + composeRule.onNodeWithTag("WatchActivityDetailAmount", useUnmergedTree = true).assertIsDisplayed() + + composeRule.onRoot().performTouchInput { swipeUp() } + + composeRule.onNodeWithTag("WatchActivityDetailStatus").assertIsDisplayed() + composeRule.onNodeWithTag("WatchActivityDetailTime").assertIsDisplayed() + } + + private fun setContent() { + composeRule.setContent { + WearPreview { + ActivityDetailContent(payment = NOTED, unit = BitcoinDisplayUnit.MODERN, isAmbient = isAmbient) + } + } + } +} From cc1bf0f384f7d2453a8f214a738bbf6007d047fa Mon Sep 17 00:00:00 2001 From: Joao Victor Sena Date: Sun, 29 Nov 2026 18:43:36 -0300 Subject: [PATCH 17/38] docs: reflow the watch ui notes and fix a cross-reference Co-Authored-By: Claude Opus 5.5 --- docs/wear.md | 86 +++++++++++++++++++++++++++------------------------- 1 file changed, 45 insertions(+), 41 deletions(-) diff --git a/docs/wear.md b/docs/wear.md index 6a58876919..cd762801b2 100644 --- a/docs/wear.md +++ b/docs/wear.md @@ -282,37 +282,40 @@ On-screen copy stays short: a title or one line of at most about six words per s and while the wallet is offline (`WalletStatus.Offline`), as when the network drops after that sync. With the wallet online and the payment handed to Spark the ring shows alone, also while a hold invoice settles. The screen stays on and the flow cannot be swiped away or left with Back while the send runs. - - Result: sent shows a check, "Sent" and the amount with the confirm haptic, and closes after 2 s; the check pops - in and the confetti falls (Celebration, below). A payment that - did not settle within 10 s, as on the phone, or one that was already under way, from the watch or the phone, - shows a clock, "Pending" and the amount (`WatchSendPending`, `WatchSendResultAmount`) with a soft click; an - outcome Spark could not report shows "Check activity", never a failure; both stay for 5 s. An outcome that - arrives while they show replaces them at once: the check, "Sent" and the confirm haptic, closing 2 s later, - or the cross, "Payment failed", the reject haptic and OK. Only a result the wearer can read is switched: in - ambient mode, with the app off screen, with the watch locked or with the flow's screen gone, the outcome is - left to the outcome overlay, as a later one is (see Pending payments). The result and failure line is one - element that is a polite live region, and the switch changes its text, so it is designed to be said by a screen - reader; `SendResultTest` checks that the line stays the same element, and whether TalkBack on a watch says it is - a manual test, not tried yet. A line that only appears with its screen is not announced by this. The amount is - the one Spark paid. A request that was not sent because another send still holds the wallet shows "Wallet busy" - as a failure, never "Pending"; the request whose own stalled call Spark still holds shows "Pending", since that - call may still pay. A refusal or a failure shows a cross, one line of at most four words and an OK button - (`WatchSendError`, `WatchSendClose`), with the reject haptic. Insufficient funds, an expired or unreadable - invoice and an own invoice end there before any hold. -- **Activity.** The Activity page lists the newest 20 payments from Spark's local list: the phone's activity icon - of a Lightning payment (`ActivityIcon`, copied from the phone's: the up or down arrow of its direction, an - hourglass for pending, a cross for failed, in the spending purple on its 16 % circle), the amount with its sign and when it was made (`WatchActivityItem-0` onwards), as the phone's - activity list writes it (`uiDateText` with `uiDateStyleFor`, copied to `ext/DateTime.kt`): the time alone for a - payment of today ("9:05 AM", or "09:05" in 24 hours, as the watch is set), the day and time earlier this year - ("March 3, 6:40 PM") and the year too before that. - An amount too long for one line, as with eight decimals on a small screen, takes a second line. - It is read when Spark connects and after every payment or sync, and the last list stays while Spark is - disconnected; the clock its times are written by is read again every minute, so a payment of today reads as a - day once midnight passed, and a list just read counts from its own time. A tap opens the detail: the amount, the - fee of a send, the day and time as the phone's detail writes them ("March 3, 6:40 PM", no year) and the status (`WatchActivityDetailAmount`, `…Fee`, `…Time`, `…Status`), and the payment's note in up to two lines (`WatchActivityDetailMessage`) when it has one, as the phone's detail shows it: an LNURL comment of the payer, or else the invoice's description, from Spark's payment details (`PaymentsRepo`, `Payment.message`); a blank one shows nothing, and ambient mode hides it. Spark's list carries no payee. With no - payments it shows a dimmed icon and "No activity" (`WatchActivityEmpty`). A detail whose payment the list does not - hold, while it loads or after newer payments pushed it out, shows the dimmed icon (`WatchActivityDetailMissing`). - Ambient mode hides the amounts. + - Result: sent shows a check, "Sent" and the amount with the confirm haptic, and closes after 2 s; the check pops in + and the confetti falls (Receive › Celebration, above). A payment that did not settle within 10 s, as on the phone, + or one that was already under way, from the watch or the phone, shows a clock, "Pending" and the amount + (`WatchSendPending`, `WatchSendResultAmount`) with a soft click; an outcome Spark could not report shows "Check + activity", never a failure; both stay for 5 s. An outcome that arrives while they show replaces them at once: the + check, "Sent" and the confirm haptic, closing 2 s later, or the cross, "Payment failed", the reject haptic and OK. + Only a result the wearer can read is switched: in ambient mode, with the app off screen, with the watch locked or + with the flow's screen gone, the outcome is left to the outcome overlay, as a later one is (see Pending payments). + The result and failure line is one element that is a polite live region, and the switch changes its text, so it is + designed to be said by a screen reader; `SendResultTest` checks that the line stays the same element, and whether + TalkBack on a watch says it is a manual test, not tried yet. A line that only appears with its screen is not + announced by this. The amount is the one Spark paid. A request that was not sent because another send still holds + the wallet shows "Wallet busy" as a failure, never "Pending"; the request whose own stalled call Spark still holds + shows "Pending", since that call may still pay. A refusal or a failure shows a cross, one line of at most four + words and an OK button (`WatchSendError`, `WatchSendClose`), with the reject haptic. Insufficient funds, an + expired or unreadable invoice and an own invoice end there before any hold. +- **Activity.** The Activity page lists the newest 20 payments from Spark's local list: the phone's activity icon of a + Lightning payment (`ActivityIcon`, copied from the phone's: the up or down arrow of its direction, an hourglass for + pending, a cross for failed, in the spending purple on its 16 % circle), the amount with its sign and when it was + made (`WatchActivityItem-0` onwards), as the phone's activity list writes it (`uiDateText` with `uiDateStyleFor`, + copied to `ext/DateTime.kt`): the time alone for a payment of today ("9:05 AM", or "09:05" in 24 hours, as the watch + is set), the day and time earlier this year ("March 3, 6:40 PM") and the year too before that. An amount too long + for one line, as with eight decimals on a small screen, takes a second line. It is read when Spark connects and + after every payment or sync, and the last list stays while Spark is disconnected; the clock its times are written by + is read again every minute, so a payment of today reads as a day once midnight passed, and a list just read counts + from its own time. A tap opens the detail: the amount, the fee of a send, the day and time as the phone's detail + writes them ("March 3, 6:40 PM", no year) and the status (`WatchActivityDetailAmount`, `…Fee`, `…Time`, `…Status`), + and the payment's note in up to two lines (`WatchActivityDetailMessage`) when it has one, in a list that scrolls, + also with the rotary input, so the status stays reachable on the smallest round screen; the day and time also take + up to two lines, ending in an ellipsis. The note is as the phone's detail shows it: an LNURL comment of the payer, + or else the invoice's description, from Spark's payment details (`PaymentsRepo`, `Payment.message`); a blank one + shows nothing, and ambient mode hides it. Spark's list carries no payee. With no payments it shows a dimmed icon and + "No activity" (`WatchActivityEmpty`). A detail whose payment the list does not hold, while it loads or after newer + payments pushed it out, shows the dimmed icon (`WatchActivityDetailMissing`). Ambient mode hides the amounts. - **Settings.** A short list of icon rows: About, Phone settings and Remove wallet. The watch has no settings of its own to edit: the units, the currency and QuickPay come from the phone (see Settings sync). The Phone settings row (`WatchSettingsSync`) shows how long ago they were last imported (`WatchSettingsSyncTime`, absent until a first @@ -329,16 +332,17 @@ On-screen copy stays short: a title or one line of at most about six words per s (`BezelLoading`) is a stroke-sized spot at the top of the ring, and the content beneath stays reachable by TalkBack and `android layout`. `BezelPadding` and `BezelStrokeWidth` hold the ring's padding and stroke for other edge rings, such as hold-to-pay. -- **Style.** Black background; Brand orange only on the one primary action (an `EdgeButton`) and accents; Inter - Tight; the send and receive screens (the Receive page, the receive QR, the send flow and the outcome overlay) in - the phone's spending purple instead (`SpendingTheme`, `Colors.Purple`, the phone's `Colors.Purple`), on their - buttons, rings and success icons, to say that the watch only spends and receives from the spending balance; content centered inside the round screen and clear of the time; icons rather than labels where the icon is - clear; no stacked button lists. A check icon is a success status (Sent, Paid, Paired) and never a screen's - button, anywhere on the watch: a confirm action is a short text `EdgeButton` named by what it does ("Match", - "OK", "Remove", "Unpair", "New invoice"), and cancelling is the watch's swipe-to-dismiss. - The two questions asked in a dialog (Remove wallet, Unpair phone) are the platform's alert dialog with that one - button. Icon and text buttons morph their shape on press and the theme uses the expressive - (spring) motion scheme. Icons are vector drawables in `res/drawable`, with no icon library. +- **Style.** Black background; Brand orange only on the one primary action (an `EdgeButton`) and accents; Inter Tight; + the send and receive screens (the Receive page, the receive QR, the send flow and the outcome overlay) in the + phone's spending purple instead (`SpendingTheme`, `Colors.Purple`, the phone's `Colors.Purple`), on their buttons, + rings and success icons, to say that the watch only spends and receives from the spending balance; content centered + inside the round screen and clear of the time; icons rather than labels where the icon is clear; no stacked button + lists. A check icon is a success status (Sent, Paid, Paired) and never a screen's button, anywhere on the watch: a + confirm action is a short text `EdgeButton` named by what it does ("Match", "OK", "Remove", "Unpair", "New + invoice"), and cancelling is the watch's swipe-to-dismiss. The two questions asked in a dialog (Remove wallet, + Unpair phone) are the platform's alert dialog with that one button. Icon and text buttons morph their shape on press + and the theme uses the expressive (spring) motion scheme. Icons are vector drawables in `res/drawable`, with no icon + library. ## Payments From b2f2a9e1d86bd037028decb953a15ce0684ca6d4 Mon Sep 17 00:00:00 2001 From: Joao Victor Sena Date: Sun, 29 Nov 2026 18:43:59 -0300 Subject: [PATCH 18/38] fix: make the watch tile's receive button purple Co-Authored-By: Claude Opus 5.5 --- docs/wear.md | 15 ++++++++------- journeys/wear/tile-balance.xml | 2 +- .../to/bitkit/wear/tile/BalanceTileService.kt | 3 ++- wear/src/main/res/drawable/tile_preview.xml | 2 +- 4 files changed, 12 insertions(+), 10 deletions(-) diff --git a/docs/wear.md b/docs/wear.md index cd762801b2..6cbc808eda 100644 --- a/docs/wear.md +++ b/docs/wear.md @@ -218,12 +218,13 @@ On-screen copy stays short: a title or one line of at most about six words per s decision; `SendResultTest`, `ReceiveQrContentTest` and `SendOutcomeOverlayTest` check where the confetti falls, that it is gone within 2 s and that no wake plays it again; how it looks on a device is not checked. - **Tile.** The Bitkit tile (`BalanceTileService`) uses the tiles and ProtoLayout Material 3 libraries: a primary - layout with the balance in the main slot and an edge button below. With a wallet it shows the balance in bitcoin, - in the unit (Modern or Classic) imported from the phone, white, as on the Balance page, and a round Brand orange - edge button with the QR icon ("Receive" to accessibility services), which opens the app on the receive QR: the - launch intent carries the extra `to.bitkit.wear.OPEN` with `receive`, which `LaunchRequest` reads as `Receive`, - and the receive QR opens above Home, as a payment link's send does. Without a wallet it shows the Bitkit mark and - a "Restore" edge button that opens the app. Tiles cannot use the app's fonts, so the balance is in the system font. + layout with the balance in the main slot and an edge button below. With a wallet it shows the balance in bitcoin, in + the unit (Modern or Classic) imported from the phone, white, as on the Balance page, and a round edge button in the + spending purple, as the receive screens, with the QR icon ("Receive" to accessibility services), which opens the app + on the receive QR: the launch intent carries the extra `to.bitkit.wear.OPEN` with `receive`, which `LaunchRequest` + reads as `Receive`, and the receive QR opens above Home, as a payment link's send does. Without a wallet it shows + the Bitkit mark and a "Restore" edge button in Brand orange that opens the app. Tiles cannot use the app's fonts, so + the balance is in the system font. - The tile only reads `WalletRepo`'s state in memory and never starts the wallet, so the balance shows only once the app loaded it in this process and a sync confirmed it, as on the Balance page; until then, and while the watch is locked, the dimmed mark stands in for it. A removed wallet shows the signed-out tile at once. @@ -235,7 +236,7 @@ On-screen copy stays short: a title or one line of at most about six words per s because the watch locked (`WalletStatus.Locked`). Tiles have no ambient mode: in ambient the system shows the watch face, so the app's rule that the always-on screen shows no amount holds without code in the tile. The tile carries no secret: the receive invoice is made by the app after the tap, never by the tile. - - The tile picker shows `tile_preview` (a drawing of the balance and the Receive button, no real amount). + - The tile picker shows `tile_preview` (a drawing of the balance and the purple Receive button, no real amount). `tile_logo` and `tile_logo_dim` are the mark's letters and dot without its black outline, the dim one at 40% opacity baked into its colours, since a tile image cannot be drawn half transparent or tinted per path. - **Send.** There is no Send page or button. A tapped NFC tag with a payment link opens the same flow as the link diff --git a/journeys/wear/tile-balance.xml b/journeys/wear/tile-balance.xml index 61c8817e8e..660ce292b9 100644 --- a/journeys/wear/tile-balance.xml +++ b/journeys/wear/tile-balance.xml @@ -13,7 +13,7 @@ Note the text of "WatchHomeBalance" as <balance> Add the tile as in README › Tiles Show the tile as in README › Tiles and wait 3 s - Verify from a screenshot that the tile shows "₿ <balance>" and an orange QR edge button below it + Verify from a screenshot that the tile shows "₿ <balance>" and a purple QR edge button below it Tap the QR edge button at the point the screenshot shows Wait up to 10 s until `adb shell uiautomator dump` lists "WatchReceiveQr" (README, top) Swipe to dismiss from the left edge: `adb shell input swipe 20 227 400 227 300` diff --git a/wear/src/main/java/to/bitkit/wear/tile/BalanceTileService.kt b/wear/src/main/java/to/bitkit/wear/tile/BalanceTileService.kt index 64d06d07f5..37d82b2104 100644 --- a/wear/src/main/java/to/bitkit/wear/tile/BalanceTileService.kt +++ b/wear/src/main/java/to/bitkit/wear/tile/BalanceTileService.kt @@ -105,7 +105,8 @@ class BalanceTileService : TileService() { deviceConfiguration = device, allowDynamicTheme = false, defaultColorScheme = ColorScheme( - primary = Colors.Brand.toArgb().argb, + // The wallet's Receive in the spending purple, as the receive QR it opens; Restore stays Brand orange. + primary = (if (state is TileState.Wallet) Colors.Purple else Colors.Brand).toArgb().argb, onPrimary = Colors.Black.toArgb().argb, onSurface = Colors.White.toArgb().argb, ), diff --git a/wear/src/main/res/drawable/tile_preview.xml b/wear/src/main/res/drawable/tile_preview.xml index edbbb97dde..b4b285afc1 100644 --- a/wear/src/main/res/drawable/tile_preview.xml +++ b/wear/src/main/res/drawable/tile_preview.xml @@ -12,7 +12,7 @@ android:fillColor="#FFFFFFFF" android:pathData="M56,82h80a7,7 0,0 1,0 14h-80a7,7 0,0 1,0 -14z" /> Date: Sun, 29 Nov 2026 18:44:42 -0300 Subject: [PATCH 19/38] refactor: share the sheet intro's tinted icon with the watch sheet Co-Authored-By: Claude Opus 5.5 --- .../to/bitkit/ui/components/SheetIntro.kt | 72 ++++++++++++------- .../ui/sheets/watch/WatchInstallSheet.kt | 2 +- .../bitkit/ui/sheets/watch/WatchPairSheet.kt | 2 +- .../to/bitkit/ui/sheets/watch/WatchSheet.kt | 25 +------ docs/wear.md | 4 +- 5 files changed, 54 insertions(+), 51 deletions(-) diff --git a/app/src/main/java/to/bitkit/ui/components/SheetIntro.kt b/app/src/main/java/to/bitkit/ui/components/SheetIntro.kt index 1f18ffa512..71be3a5fb3 100644 --- a/app/src/main/java/to/bitkit/ui/components/SheetIntro.kt +++ b/app/src/main/java/to/bitkit/ui/components/SheetIntro.kt @@ -5,6 +5,7 @@ import androidx.compose.foundation.Image import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.ColumnScope import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.fillMaxWidth @@ -30,7 +31,33 @@ import to.bitkit.ui.theme.Colors const val SHEET_INTRO_IMAGE_WIDTH_FRACTION = 0.8f /** The size of a one-colour icon that stands in for intro sheet artwork, centred in the artwork's slot. */ -val SHEET_INTRO_ICON_SIZE = 160.dp +private val SHEET_INTRO_ICON_SIZE = 160.dp + +/** + * A one-colour [icon] that stands in for intro sheet artwork where none exists, enlarged and centred in the artwork's + * slot, in [tint]: Brand orange, as the intro sheets' accented titles. + */ +@Composable +fun ColumnScope.SheetIntroIcon( + @DrawableRes icon: Int, + modifier: Modifier = Modifier, + tint: Color = Colors.Brand, +) { + Box( + contentAlignment = Alignment.Center, + modifier = Modifier + .fillMaxWidth() + .weight(1f) + ) { + Image( + painter = painterResource(icon), + contentDescription = null, + contentScale = ContentScale.Fit, + colorFilter = ColorFilter.tint(tint), + modifier = modifier.size(SHEET_INTRO_ICON_SIZE) + ) + } +} @Composable fun SheetIntro( @@ -48,7 +75,7 @@ fun SheetIntro( testTag: String = "SheetIntro", cancelTestTag: String = "${testTag}Cancel", continueTestTag: String = "${testTag}Continue", - imageTint: Color? = null, + isImageIcon: Boolean = false, ) { Column( modifier = modifier @@ -62,30 +89,25 @@ fun SheetIntro( Column( modifier = Modifier.padding(horizontal = 32.dp), ) { - Box( - // A tinted icon is centred, where artwork sits on the slot's bottom. - contentAlignment = if (imageTint == null) Alignment.BottomCenter else Alignment.Center, - modifier = Modifier - .fillMaxWidth() - .weight(1f) - ) { - Image( - painter = painterResource(image), - contentDescription = null, - contentScale = ContentScale.Fit, - colorFilter = imageTint?.let { ColorFilter.tint(it) }, + if (isImageIcon) { + SheetIntroIcon(icon = image, modifier = Modifier.testTag("${testTag}Image")) + } else { + Box( + contentAlignment = Alignment.BottomCenter, modifier = Modifier - .then( - if (imageTint == null) { - Modifier - .fillMaxWidth(SHEET_INTRO_IMAGE_WIDTH_FRACTION) - .heightIn(max = 320.dp) - } else { - Modifier.size(SHEET_INTRO_ICON_SIZE) - } - ) - .testTag("${testTag}Image") - ) + .fillMaxWidth() + .weight(1f) + ) { + Image( + painter = painterResource(image), + contentDescription = null, + contentScale = ContentScale.Fit, + modifier = Modifier + .fillMaxWidth(SHEET_INTRO_IMAGE_WIDTH_FRACTION) + .heightIn(max = 320.dp) + .testTag("${testTag}Image") + ) + } } VerticalSpacer(32.dp) diff --git a/app/src/main/java/to/bitkit/ui/sheets/watch/WatchInstallSheet.kt b/app/src/main/java/to/bitkit/ui/sheets/watch/WatchInstallSheet.kt index d54aa458d6..8d5bdb80d4 100644 --- a/app/src/main/java/to/bitkit/ui/sheets/watch/WatchInstallSheet.kt +++ b/app/src/main/java/to/bitkit/ui/sheets/watch/WatchInstallSheet.kt @@ -46,7 +46,7 @@ private fun Content( title = stringResource(R.string.settings__watch__install_title).withAccent(accentColor = Colors.Brand), description = AnnotatedString(stringResource(R.string.settings__watch__install_text).replace("{name}", name)), image = R.drawable.ic_watch, - imageTint = Colors.Brand, + isImageIcon = true, continueText = stringResource(R.string.settings__watch__install_button), onContinue = onInstall, cancelText = stringResource(R.string.common__later), diff --git a/app/src/main/java/to/bitkit/ui/sheets/watch/WatchPairSheet.kt b/app/src/main/java/to/bitkit/ui/sheets/watch/WatchPairSheet.kt index 8d2b7ee9d4..f2f56daec6 100644 --- a/app/src/main/java/to/bitkit/ui/sheets/watch/WatchPairSheet.kt +++ b/app/src/main/java/to/bitkit/ui/sheets/watch/WatchPairSheet.kt @@ -28,7 +28,7 @@ fun WatchPairSheet( title = stringResource(R.string.settings__watch__pair_prompt_title).withAccent(accentColor = Colors.Brand), description = AnnotatedString(stringResource(R.string.settings__watch__pair_prompt_text)), image = R.drawable.ic_watch, - imageTint = Colors.Brand, + isImageIcon = true, continueText = stringResource(R.string.settings__watch__pair_confirm), onContinue = onPair, cancelText = stringResource(R.string.common__later), diff --git a/app/src/main/java/to/bitkit/ui/sheets/watch/WatchSheet.kt b/app/src/main/java/to/bitkit/ui/sheets/watch/WatchSheet.kt index 23cfeb27d9..b4540b035f 100644 --- a/app/src/main/java/to/bitkit/ui/sheets/watch/WatchSheet.kt +++ b/app/src/main/java/to/bitkit/ui/sheets/watch/WatchSheet.kt @@ -12,7 +12,6 @@ import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.navigationBarsPadding import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.size -import androidx.compose.material3.Icon import androidx.compose.runtime.Composable import androidx.compose.runtime.DisposableEffect import androidx.compose.runtime.LaunchedEffect @@ -39,8 +38,8 @@ import to.bitkit.ui.components.BodyMSB import to.bitkit.ui.components.BottomSheetPreview import to.bitkit.ui.components.Display import to.bitkit.ui.components.PrimaryButton -import to.bitkit.ui.components.SHEET_INTRO_ICON_SIZE import to.bitkit.ui.components.SecondaryButton +import to.bitkit.ui.components.SheetIntroIcon import to.bitkit.ui.components.SheetSize import to.bitkit.ui.components.Title import to.bitkit.ui.components.VerticalSpacer @@ -196,7 +195,7 @@ private fun ColumnScope.Unpaired( color = Colors.White64, modifier = Modifier.testTag("PairedWatchStatus") ) - WatchIllustration() + SheetIntroIcon(icon = R.drawable.ic_watch) if (connected != null && !connected.hasApp) { PrimaryButton( text = stringResource(R.string.settings__watch__install_on_watch), @@ -287,7 +286,7 @@ private fun ColumnScope.Pairing( when (step) { WatchPairStep.Connecting -> { Message(R.string.settings__watch__pair_connecting, "PairedWatchPairConnecting") - WatchIllustration() + SheetIntroIcon(icon = R.drawable.ic_watch) SecondaryButton( text = stringResource(R.string.common__cancel), onClick = onClose, @@ -416,24 +415,6 @@ private fun ColumnScope.Illustration(@DrawableRes image: Int) { } } -/** The watch, as the phone's other watch sheets show it: no 3D watch illustration exists, so the icon, enlarged. */ -@Composable -private fun ColumnScope.WatchIllustration() { - Box( - contentAlignment = Alignment.Center, - modifier = Modifier - .fillMaxWidth() - .weight(1f) - ) { - Icon( - painter = painterResource(R.drawable.ic_watch), - contentDescription = null, - tint = Colors.Brand, - modifier = Modifier.size(SHEET_INTRO_ICON_SIZE) - ) - } -} - @Preview(showSystemUi = true) @Composable private fun PreviewUnpaired() { diff --git a/docs/wear.md b/docs/wear.md index 6cbc808eda..58bdcbb6ad 100644 --- a/docs/wear.md +++ b/docs/wear.md @@ -1341,8 +1341,8 @@ reopened: still sending, the line that says why it failed, or the paired watch. The phone's tags start with `PairedWatch` because the watch app's own start with `Watch`. Where the sheet, the Pair prompt and the install prompt would show the 3D phone illustration, they show the watch -icon (`ic_watch`) instead, enlarged and centred in the illustration's place, in Brand orange: no 3D watch -illustration exists. The other steps keep their illustrations (shield, keyring, transfer, check, cross). +icon (`ic_watch`) instead, enlarged and centred in the illustration's place, in Brand orange, all three through +`SheetIntroIcon`: no 3D watch illustration exists. The other steps keep their illustrations (shield, keyring, transfer, check, cross). Watch: From f6615208578c9a4be7961e27aa7d6513b819a636 Mon Sep 17 00:00:00 2001 From: Joao Victor Sena Date: Sun, 29 Nov 2026 18:45:40 -0300 Subject: [PATCH 20/38] fix: theme the watch's send and receive screens inside them Co-Authored-By: Claude Opus 5.5 --- .../java/to/bitkit/wear/ui/WearNavHost.kt | 13 ++++----- .../wear/ui/components/SendOutcomeOverlay.kt | 6 ++--- .../bitkit/wear/ui/screens/home/HomeScreen.kt | 3 +-- .../ui/screens/receive/ReceiveQrScreen.kt | 3 ++- .../wear/ui/screens/receive/ReceiveScreen.kt | 5 ++-- .../bitkit/wear/ui/screens/send/SendScreen.kt | 27 ++++++++++--------- 6 files changed, 28 insertions(+), 29 deletions(-) diff --git a/wear/src/main/java/to/bitkit/wear/ui/WearNavHost.kt b/wear/src/main/java/to/bitkit/wear/ui/WearNavHost.kt index 16aef596da..6432682513 100644 --- a/wear/src/main/java/to/bitkit/wear/ui/WearNavHost.kt +++ b/wear/src/main/java/to/bitkit/wear/ui/WearNavHost.kt @@ -37,7 +37,6 @@ import to.bitkit.wear.ui.screens.send.SendScreen import to.bitkit.wear.ui.screens.send.TagRefusedScreen import to.bitkit.wear.ui.screens.settings.AboutScreen import to.bitkit.wear.ui.screens.unsupported.UnsupportedScreen -import to.bitkit.wear.ui.theme.SpendingTheme import to.bitkit.wear.utils.Logger @Composable @@ -99,18 +98,16 @@ fun WearNavHost( AboutScreen() } composable(Routes.RECEIVE_QR) { - SpendingTheme { ReceiveQrScreen() } + ReceiveQrScreen() } composable( route = Routes.SEND, arguments = listOf(navArgument(Routes.SEND_INPUT) { type = NavType.StringType }), ) { - SpendingTheme { - SendScreen( - onClose = { navController.popBackStack(Routes.SEND, inclusive = true) }, - onBusyChange = { isSending = it }, - ) - } + SendScreen( + onClose = { navController.popBackStack(Routes.SEND, inclusive = true) }, + onBusyChange = { isSending = it }, + ) } composable(Routes.TAG_REFUSED) { TagRefusedScreen(onClose = { navController.popBackStack(Routes.TAG_REFUSED, inclusive = true) }) diff --git a/wear/src/main/java/to/bitkit/wear/ui/components/SendOutcomeOverlay.kt b/wear/src/main/java/to/bitkit/wear/ui/components/SendOutcomeOverlay.kt index 2dd351bb29..6e3842e27d 100644 --- a/wear/src/main/java/to/bitkit/wear/ui/components/SendOutcomeOverlay.kt +++ b/wear/src/main/java/to/bitkit/wear/ui/components/SendOutcomeOverlay.kt @@ -63,9 +63,7 @@ fun SendOutcomeOverlay( BackHandler {} // Each outcome pops in, with its own confetti, also when it follows another. key(outcome.id) { - SpendingTheme { - OutcomeContent(outcome = outcome, isCelebrated = isFirstShown && outcome.isSent, modifier = modifier) - } + OutcomeContent(outcome = outcome, isCelebrated = isFirstShown && outcome.isSent, modifier = modifier) } } @@ -75,7 +73,7 @@ internal fun OutcomeContent( outcome: ShownOutcome, modifier: Modifier = Modifier, isCelebrated: Boolean = false, -) { +) = SpendingTheme { val description = stringResource( R.string.send__outcome_description, stringResource(if (outcome.isSent) R.string.send__sent else R.string.send__error_failed), diff --git a/wear/src/main/java/to/bitkit/wear/ui/screens/home/HomeScreen.kt b/wear/src/main/java/to/bitkit/wear/ui/screens/home/HomeScreen.kt index 66b5f3c3f8..cf7c37dddd 100644 --- a/wear/src/main/java/to/bitkit/wear/ui/screens/home/HomeScreen.kt +++ b/wear/src/main/java/to/bitkit/wear/ui/screens/home/HomeScreen.kt @@ -19,7 +19,6 @@ import to.bitkit.wear.ui.components.PageIndicatorPadding import to.bitkit.wear.ui.screens.activity.ActivityScreen import to.bitkit.wear.ui.screens.receive.ReceiveScreen import to.bitkit.wear.ui.screens.settings.SettingsScreen -import to.bitkit.wear.ui.theme.SpendingTheme /** * The app's top level: pages swiped horizontally with a page indicator, opening on the balance. Swiping right on the @@ -52,7 +51,7 @@ fun HomeScreen( CompositionLocalProvider(LocalListBottomInset provides PageIndicatorPadding) { when (pages[page]) { HomePage.Balance -> BalancePage(viewModel = viewModel) - HomePage.Receive -> SpendingTheme { ReceiveScreen(onQrClick = onReceiveClick) } + HomePage.Receive -> ReceiveScreen(onQrClick = onReceiveClick) HomePage.Activity -> ActivityScreen(onPaymentClick = onPaymentClick) HomePage.Settings -> SettingsScreen(onAboutClick = onAboutClick) } diff --git a/wear/src/main/java/to/bitkit/wear/ui/screens/receive/ReceiveQrScreen.kt b/wear/src/main/java/to/bitkit/wear/ui/screens/receive/ReceiveQrScreen.kt index 339c63b9ad..010844c478 100644 --- a/wear/src/main/java/to/bitkit/wear/ui/screens/receive/ReceiveQrScreen.kt +++ b/wear/src/main/java/to/bitkit/wear/ui/screens/receive/ReceiveQrScreen.kt @@ -64,6 +64,7 @@ import to.bitkit.wear.ui.components.rememberCelebration import to.bitkit.wear.ui.modifiers.clickableAlpha import to.bitkit.wear.ui.screens.home.DisplayAmount import to.bitkit.wear.ui.theme.Colors +import to.bitkit.wear.ui.theme.SpendingTheme import kotlin.time.Duration.Companion.minutes /** The QR's side as a share of the screen: the largest square inside the round screen (1/√2). */ @@ -212,7 +213,7 @@ internal fun ReceiveQrContent( onQrTouch: () -> Unit = {}, onShowClick: () -> Unit = {}, onNfcSettingsClick: () -> Unit = {}, -) { +) = SpendingTheme { val qrContent = uiState.qrContent val paidAmount = uiState.paidAmount // Kept here, above the paid check, so that the decision outlives ambient mode. diff --git a/wear/src/main/java/to/bitkit/wear/ui/screens/receive/ReceiveScreen.kt b/wear/src/main/java/to/bitkit/wear/ui/screens/receive/ReceiveScreen.kt index 512f15cb9d..e0172ebee6 100644 --- a/wear/src/main/java/to/bitkit/wear/ui/screens/receive/ReceiveScreen.kt +++ b/wear/src/main/java/to/bitkit/wear/ui/screens/receive/ReceiveScreen.kt @@ -17,6 +17,7 @@ import to.bitkit.wear.R import to.bitkit.wear.ui.components.CenteredScreen import to.bitkit.wear.ui.components.WearPreview import to.bitkit.wear.ui.components.WearPreviewDevices +import to.bitkit.wear.ui.theme.SpendingTheme /** The size of the receive button: the page's one large control. */ private val BUTTON_SIZE = 88.dp @@ -24,12 +25,12 @@ private val BUTTON_SIZE = 88.dp /** The size of the QR icon inside the button. */ private val ICON_SIZE = 44.dp -/** The receive page of the home pager: one large round button that opens the receive QR. */ +/** The receive page of the home pager: one large round button that opens the receive QR, in the spending purple. */ @Composable fun ReceiveScreen( onQrClick: () -> Unit, modifier: Modifier = Modifier, -) { +) = SpendingTheme { CenteredScreen(modifier = modifier) { FilledIconButton( onClick = onQrClick, diff --git a/wear/src/main/java/to/bitkit/wear/ui/screens/send/SendScreen.kt b/wear/src/main/java/to/bitkit/wear/ui/screens/send/SendScreen.kt index f3ea17a185..08c0bc1549 100644 --- a/wear/src/main/java/to/bitkit/wear/ui/screens/send/SendScreen.kt +++ b/wear/src/main/java/to/bitkit/wear/ui/screens/send/SendScreen.kt @@ -66,6 +66,7 @@ import to.bitkit.wear.ui.components.rememberCelebration import to.bitkit.wear.ui.components.rememberHoldToPayState import to.bitkit.wear.ui.screens.home.DisplayAmount import to.bitkit.wear.ui.theme.Colors +import to.bitkit.wear.ui.theme.SpendingTheme /** The size of the icon that tops a status: the check, the cross, the clock, the cloud and the bolt while loading. */ private val STATUS_ICON_SIZE = 48.dp @@ -145,16 +146,18 @@ fun TagRefusedScreen( ) { val haptic = LocalHapticFeedback.current LaunchedEffect(Unit) { haptic.performHapticFeedback(HapticFeedbackType.Reject) } - StatusScreen( - icon = R.drawable.ic_close, - tint = MaterialTheme.colorScheme.error, - text = stringResource(R.string.send__error_unsupported), - textTag = "WatchTagRefused", - textStyle = MaterialTheme.typography.titleSmall, - amount = null, - onCloseClick = onClose, - modifier = modifier - ) + SpendingTheme { + StatusScreen( + icon = R.drawable.ic_close, + tint = MaterialTheme.colorScheme.error, + text = stringResource(R.string.send__error_unsupported), + textTag = "WatchTagRefused", + textStyle = MaterialTheme.typography.titleSmall, + amount = null, + onCloseClick = onClose, + modifier = modifier + ) + } } @Composable @@ -166,7 +169,7 @@ internal fun Content( onHoldComplete: () -> Unit, onCloseClick: () -> Unit, modifier: Modifier = Modifier, -) { +) = SpendingTheme { val step = uiState.step // The always-on screen shows no amount, typed, reviewed or sent, and nothing to hold. val isSent = step is SendStep.Done && step.result == SendResult.Sent @@ -174,7 +177,7 @@ internal fun Content( val isCelebrated = rememberCelebration(key = SENT_KEY.takeIf { isSent }, isAmbient = isAmbient) if (isAmbient && (step is SendStep.Amount || step is SendStep.Review || isSent)) { Hidden(modifier = modifier) - return + return@SpendingTheme } when (step) { SendStep.Loading -> Loading(modifier = modifier) From 2742a0f6f36c50456911289fb52345b08f1e206d Mon Sep 17 00:00:00 2001 From: Joao Victor Sena Date: Sun, 29 Nov 2026 18:46:13 -0300 Subject: [PATCH 21/38] test: check the watch confetti and payment note without timing luck Co-Authored-By: Claude Opus 5.5 --- journeys/wear/README.md | 3 +++ journeys/wear/activity-list.xml | 8 ++++++-- journeys/wear/receive-paid.xml | 4 +++- journeys/wear/send-deeplink-bolt11.xml | 8 +++++--- 4 files changed, 17 insertions(+), 6 deletions(-) diff --git a/journeys/wear/README.md b/journeys/wear/README.md index 40de5c2ad7..b577619003 100644 --- a/journeys/wear/README.md +++ b/journeys/wear/README.md @@ -17,6 +17,9 @@ What `android layout` misses on the watch, verified on the API 37 emulator: - **The receive QR.** `WatchReceiveQr` is an image with no text or action, so `android layout` leaves it out; `adb shell uiautomator dump` lists it. Check it there or from a screenshot. `WatchReceiveHidden`, the screen with the dimmed icon that replaces it in ambient mode and once it rests, has a content-desc and is listed. +- **The confetti.** `WatchConfetti`, the canvas the confetti of a success falls on, has no text or action, so + `android layout` leaves it out; `adb shell uiautomator dump` lists it while it falls, for under 2 s, so dump at once. + A screenshot rarely catches the pieces in time: check the confetti with the dump and the colours from a screenshot. - **Suggestion chips.** A chip's tag (`RestoreSuggestion-0`, counted from 0) is on the button and its word is a text node at the same `center`. A chip below the screen edge is not listed until the screen scrolls. - **The keyboard.** The Wear OS keyboard is a full-screen window that `android layout` does not show. It lists the diff --git a/journeys/wear/activity-list.xml b/journeys/wear/activity-list.xml index a6284805de..bae3a67ffe 100644 --- a/journeys/wear/activity-list.xml +++ b/journeys/wear/activity-list.xml @@ -2,7 +2,8 @@ The Activity page, after Receive, lists the newest payments with the phone's activity icon (a purple arrow on a purple circle), the amount and the time as the phone's activity writes it (the time alone today); a tap opens the - detail with the amount, the fee of a send, the payment's note when it has one, the day and time and the status. + detail with the amount, the fee of a send, the payment's note when it has one, the day and time and the status, + in a list that scrolls. Emulator and physical watch. Precondition: Restored wallet on the local ./spark stack after receive-paid.xml and send-deeplink-bolt11.xml, so @@ -21,8 +22,11 @@ Verify "WatchActivityDetailAmount" reads "1 000" Verify "WatchActivityDetailStatus" reads "Completed" Verify "WatchActivityDetailTime" shows today's day and the time, such as "November 29, 3:04 PM" - Verify "WatchActivityDetailMessage" is listed only when the paid invoice carried a description, and then reads it + Verify "WatchActivityDetailMessage" reads "Coffee", the description of the invoice send-deeplink-bolt11.xml paid Swipe to dismiss from the left edge: `adb shell input swipe 20 227 400 227 300` Verify "WatchActivityItem-0" is listed again + Tap "WatchActivityItem-1" + Verify "WatchActivityDetailStatus" reads "Completed" and "WatchActivityDetailMessage" is not listed: the receive's invoice has no description + Swipe to dismiss from the left edge: `adb shell input swipe 20 227 400 227 300` diff --git a/journeys/wear/receive-paid.xml b/journeys/wear/receive-paid.xml index 74f6edf48d..704fd30dd4 100644 --- a/journeys/wear/receive-paid.xml +++ b/journeys/wear/receive-paid.xml @@ -18,8 +18,10 @@ Read the invoice from the log as in README › Reading the receive invoice and note it as <invoice> Run `../bitkit-docker/spark pay <invoice> 50000` from this repo's parent checkout Wait up to 20 s until "WatchReceivePaid" is listed + Verify at once that `adb shell uiautomator dump` lists "WatchConfetti" (README, top): the confetti falls for under 2 s Verify "WatchReceivePaidAmount" reads "50 000" - Verify from a screenshot taken at once that the check is purple and purple confetti falls over the screen, and from one taken 3 s later that the confetti is gone and the check stays + Wait 3 s, then verify `adb shell uiautomator dump` no longer lists "WatchConfetti" and still lists "WatchReceivePaid" + Verify from a screenshot that the check is purple Verify the button below the check reads "New invoice" (tag "WatchReceiveNew") Tap the check (tag "WatchReceivePaid") and verify "WatchReceivePaid" is still listed 2 s later: the check is no button Tap New invoice (tag "WatchReceiveNew") diff --git a/journeys/wear/send-deeplink-bolt11.xml b/journeys/wear/send-deeplink-bolt11.xml index 4493ec4a71..50320a08e2 100644 --- a/journeys/wear/send-deeplink-bolt11.xml +++ b/journeys/wear/send-deeplink-bolt11.xml @@ -1,7 +1,8 @@ A `lightning:` link to a BOLT11 invoice opens the review with the amount; holding the pay button fills the ring - around the bezel and pays; the check shows "Sent" and the flow closes by itself after about 2 s. Emulator and + around the bezel and pays; the check shows "Sent" under purple confetti and the flow closes by itself after about + 2 s. Emulator and physical watch. Precondition: Restored wallet on the local ./spark stack with at least 2 000 sats (run receive-paid.xml first), @@ -9,7 +10,7 @@ stopped. README › Holding to pay has the hold gesture. - Run `../bitkit-docker/spark invoice 1000` and note the BOLT11 invoice it prints as <invoice> + From the bitkit-docker checkout, with `ALICE` set as in README › Hold invoices, run `$ALICE bolt11-receive 1000sat -d Coffee | jq -r .invoice` and note the BOLT11 invoice it prints as <invoice>: its description, "Coffee", is the note activity-list.xml checks Run `adb shell am start -a android.intent.action.VIEW -d "lightning:<invoice>" to.bitkit.dev` Wait up to 10 s until "WatchSendHold" is listed Verify from a screenshot that the Hold to pay button is purple, not orange @@ -17,8 +18,9 @@ Verify "WatchSendAmountSymbol" reads "₿" Hold "WatchSendHold" for 2 s as in README › Holding to pay Wait up to 15 s until "WatchSendSent" is listed + Verify at once that `adb shell uiautomator dump` lists "WatchConfetti" (README, top): the confetti falls for under 2 s Verify "WatchSendResultAmount" reads "1 000" - Verify from a screenshot taken at once that the check is purple and purple confetti falls over the screen + Verify from a screenshot that the check is purple Wait 4 s Verify the Balance page: "WatchHomeBalance" is listed Verify "WatchSendSent" is not listed From 5523733ed7f4ff329cae582fc39776f767896559 Mon Sep 17 00:00:00 2001 From: Joao Victor Sena Date: Sun, 29 Nov 2026 19:15:45 -0300 Subject: [PATCH 22/38] fix: play a watch success haptic once, not again on a new screen Co-Authored-By: Claude Opus 5.5 --- docs/wear.md | 15 +++-- .../to/bitkit/wear/ui/components/Confetti.kt | 28 ++++++--- .../wear/ui/components/SendOutcomeOverlay.kt | 28 ++++++--- .../ui/screens/receive/ReceiveQrScreen.kt | 16 ++--- .../bitkit/wear/ui/screens/send/SendScreen.kt | 29 ++++----- .../wear/ui/components/CelebrationTest.kt | 42 ++++++++++--- .../ui/components/RecordingHapticFeedback.kt | 13 ++++ .../ui/components/SendOutcomeOverlayTest.kt | 61 ++++++++++++++++++- .../screens/receive/ReceiveQrContentTest.kt | 45 +++++++++++++- .../wear/ui/screens/send/SendResultTest.kt | 34 ++++++++++- 10 files changed, 257 insertions(+), 54 deletions(-) create mode 100644 wear/src/test/java/to/bitkit/wear/ui/components/RecordingHapticFeedback.kt diff --git a/docs/wear.md b/docs/wear.md index 58bdcbb6ad..02ed5770fc 100644 --- a/docs/wear.md +++ b/docs/wear.md @@ -213,10 +213,13 @@ On-screen copy stays short: a title or one line of at most about six words per s receive), so the three come together. In ambient mode there is neither: the always-on screen stays still, and the haptic plays alone. Whether a success is celebrated is decided once, keyed on it (the payment's id, the outcome's id, a flow's one send), as it is first shown (`rememberCelebration`): only one first shown awake is, and only - until the watch next goes ambient, so waking the watch on a Paid or Sent screen never plays it again; the decision - survives the screen being made again. With animations turned off both end at once. `CelebrationTest` checks the - decision; `SendResultTest`, `ReceiveQrContentTest` and `SendOutcomeOverlayTest` check where the confetti falls, - that it is gone within 2 s and that no wake plays it again; how it looks on a device is not checked. + while it stays shown awake, so neither waking the watch on a Paid or Sent screen nor an outcome cut short and shown + again plays it again. Its haptic plays once too, on the frame it is first shown, in ambient mode as well. Both + decisions survive the screen being made again, so neither plays again then. With animations turned off both end + at once. `CelebrationTest` checks the decision; `SendResultTest`, `ReceiveQrContentTest` and + `SendOutcomeOverlayTest` check where the confetti falls, that it is gone within 2 s, and that neither a wake, a + new screen nor (for the overlay) an outcome cut short plays the confetti or the haptic again; how it looks on a + device is not checked. - **Tile.** The Bitkit tile (`BalanceTileService`) uses the tiles and ProtoLayout Material 3 libraries: a primary layout with the balance in the main slot and an edge button below. With a wallet it shows the balance in bitcoin, in the unit (Modern or Classic) imported from the phone, white, as on the Balance page, and a round edge button in the @@ -403,8 +406,8 @@ in any other state. (`SendOutcomeOverlay`), not a screen and not a button: touches and Back do nothing until it is gone (turning the crown only scrolls the list beneath, and pressing it leaves the app as always). It shows only with the app on screen, out of ambient mode and with the watch unlocked (the lock screen covers the app without stopping - it): until then it waits, and one that was cut short shows again in full. Only an - outcome that showed for its 2 s is forgotten. Several show one after the other. The pending result itself + it): until then it waits, and one that was cut short shows again in full, without its haptic or confetti a second + time. Only an outcome that showed for its 2 s is forgotten. Several show one after the other. The pending result itself takes the outcome in place of the overlay while it is on screen. There is no system notification and nothing runs in the background, so an outcome that arrives while the app is closed is told at the next open. - Never over a payment. The overlay does not cover a screen where it could be taken for something else diff --git a/wear/src/main/java/to/bitkit/wear/ui/components/Confetti.kt b/wear/src/main/java/to/bitkit/wear/ui/components/Confetti.kt index eaabae34b1..9114b45ee2 100644 --- a/wear/src/main/java/to/bitkit/wear/ui/components/Confetti.kt +++ b/wear/src/main/java/to/bitkit/wear/ui/components/Confetti.kt @@ -9,6 +9,7 @@ import androidx.compose.foundation.Canvas import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.runtime.Composable +import androidx.compose.runtime.Immutable import androidx.compose.runtime.LaunchedEffect import androidx.compose.runtime.SideEffect import androidx.compose.runtime.derivedStateOf @@ -87,14 +88,22 @@ fun Confetti( } /** - * Whether the success [key] names is celebrated right now, with [Confetti] and [PopIn]. That is decided once per - * success, on the frame it is first shown, the frame its haptic plays: only a success first shown awake is - * celebrated, and only until the screen next goes ambient, so waking the watch never plays it again, without its - * haptic. The decision outlives the screen being made again, so a success is celebrated at most once. A null [key] - * is no success; a caller whose success does not show in ambient mode passes null meanwhile. + * What [rememberCelebration] decided for a success. [isFirstShown] holds on the frame it is first shown, awake or in + * ambient mode, the frame its haptic plays. [isCelebrated] holds while its [Confetti] and [PopIn] show. + */ +@Immutable +data class Celebration(val isFirstShown: Boolean, val isCelebrated: Boolean) + +/** + * Whether the success [key] names is first shown and celebrated right now, with [Confetti] and [PopIn]. That is + * decided once per success, on the frame it is first shown, the frame its haptic plays: only a success first shown + * awake is celebrated, and only while it stays shown awake. Once the screen goes ambient or [key] turns null, as for + * an outcome cut short, it is over, so neither waking the watch nor the same success shown again plays it or its + * haptic again. The decision outlives the screen being made again, so a success is first shown and celebrated at most + * once. A null [key] is no success; a caller whose success does not show in ambient mode passes null meanwhile. */ @Composable -fun rememberCelebration(key: String?, isAmbient: Boolean): Boolean { +fun rememberCelebration(key: String?, isAmbient: Boolean): Celebration { var shownKey by rememberSaveable { mutableStateOf(null) } var celebratedKey by remember { mutableStateOf(null) } val isNew = key != null && key != shownKey @@ -103,10 +112,13 @@ fun rememberCelebration(key: String?, isAmbient: Boolean): Boolean { shownKey = key if (!isAmbient) celebratedKey = key } - if (isAmbient) celebratedKey = null + if (isAmbient || key == null) celebratedKey = null } // Answered on the first frame already, so the confetti starts on the same frame as the haptic. - return key != null && !isAmbient && (isNew || key == celebratedKey) + return Celebration( + isFirstShown = isNew, + isCelebrated = key != null && !isAmbient && (isNew || key == celebratedKey), + ) } /** The thinnest a flipping piece gets, so it never vanishes edge on. */ diff --git a/wear/src/main/java/to/bitkit/wear/ui/components/SendOutcomeOverlay.kt b/wear/src/main/java/to/bitkit/wear/ui/components/SendOutcomeOverlay.kt index 6e3842e27d..debcbb2361 100644 --- a/wear/src/main/java/to/bitkit/wear/ui/components/SendOutcomeOverlay.kt +++ b/wear/src/main/java/to/bitkit/wear/ui/components/SendOutcomeOverlay.kt @@ -49,21 +49,33 @@ fun SendOutcomeOverlay( viewModel: SendOutcomeViewModel = hiltViewModel(), ) { val uiState by viewModel.uiState.collectAsStateWithLifecycle() - val isAmbient = isAmbient() - // Decided above the returns, as the outcome is first shown awake, so that waking the watch while it still shows - // neither plays its haptic nor its confetti again. - val isFirstShown = rememberCelebration(key = uiState.outcome?.id?.takeUnless { isAmbient }, isAmbient = isAmbient) - val outcome = uiState.outcome ?: return - if (isAmbient) return + OutcomeOverlay(outcome = uiState.outcome, isAmbient = isAmbient(), modifier = modifier) +} + +/** The overlay for the [outcome] the view model shows, or nothing for none; see [SendOutcomeOverlay]. */ +@Composable +internal fun OutcomeOverlay( + outcome: ShownOutcome?, + isAmbient: Boolean, + modifier: Modifier = Modifier, +) { + // Decided above the returns, as the outcome is first shown awake, so that neither waking the watch while it still + // shows nor the outcome cut short and shown again plays its haptic or its confetti again. + val celebration = rememberCelebration(key = outcome?.id?.takeUnless { isAmbient }, isAmbient = isAmbient) + if (outcome == null || isAmbient) return val haptic = LocalHapticFeedback.current LaunchedEffect(outcome.id) { - if (!isFirstShown) return@LaunchedEffect + if (!celebration.isFirstShown) return@LaunchedEffect haptic.performHapticFeedback(if (outcome.isSent) HapticFeedbackType.Confirm else HapticFeedbackType.Reject) } BackHandler {} // Each outcome pops in, with its own confetti, also when it follows another. key(outcome.id) { - OutcomeContent(outcome = outcome, isCelebrated = isFirstShown && outcome.isSent, modifier = modifier) + OutcomeContent( + outcome = outcome, + isCelebrated = celebration.isCelebrated && outcome.isSent, + modifier = modifier + ) } } diff --git a/wear/src/main/java/to/bitkit/wear/ui/screens/receive/ReceiveQrScreen.kt b/wear/src/main/java/to/bitkit/wear/ui/screens/receive/ReceiveQrScreen.kt index 010844c478..4900b91d2d 100644 --- a/wear/src/main/java/to/bitkit/wear/ui/screens/receive/ReceiveQrScreen.kt +++ b/wear/src/main/java/to/bitkit/wear/ui/screens/receive/ReceiveQrScreen.kt @@ -140,12 +140,7 @@ fun ReceiveQrScreen( viewModel: ReceiveViewModel = hiltViewModel(), ) { val uiState by viewModel.uiState.collectAsStateWithLifecycle() - val haptic = LocalHapticFeedback.current val isPaid = uiState.paidAmount != null - LaunchedEffect(isPaid) { - // A firm click, unlike the confirm pattern a send ends with, so the two never feel alike. - if (isPaid) haptic.performHapticFeedback(HapticFeedbackType.LongPress) - } val isAmbient = isAmbient() var isResting by remember { mutableStateOf(false) } var touches by remember { mutableIntStateOf(0) } @@ -217,11 +212,17 @@ internal fun ReceiveQrContent( val qrContent = uiState.qrContent val paidAmount = uiState.paidAmount // Kept here, above the paid check, so that the decision outlives ambient mode. - val isCelebrated = rememberCelebration(key = uiState.paidId, isAmbient = isAmbient) + val celebration = rememberCelebration(key = uiState.paidId, isAmbient = isAmbient) + val haptic = LocalHapticFeedback.current + LaunchedEffect(uiState.paidId) { + // A firm click, unlike the confirm pattern a send ends with, so the two never feel alike. It plays in ambient + // mode too, and not again when the screen is made again. + if (celebration.isFirstShown) haptic.performHapticFeedback(HapticFeedbackType.LongPress) + } when { paidAmount != null -> Paid( amount = paidAmount.takeUnless { isAmbient }, - isCelebrated = isCelebrated, + isCelebrated = celebration.isCelebrated, onClick = onRefreshClick, modifier = modifier ) @@ -321,7 +322,6 @@ private fun QrIcon(modifier: Modifier = Modifier) { ) } -/** [isCelebrated] pops the check in under the confetti, on the frame its haptic plays; see [rememberCelebration]. */ @Composable private fun Paid( amount: DisplayAmount?, diff --git a/wear/src/main/java/to/bitkit/wear/ui/screens/send/SendScreen.kt b/wear/src/main/java/to/bitkit/wear/ui/screens/send/SendScreen.kt index 08c0bc1549..c48e22341b 100644 --- a/wear/src/main/java/to/bitkit/wear/ui/screens/send/SendScreen.kt +++ b/wear/src/main/java/to/bitkit/wear/ui/screens/send/SendScreen.kt @@ -95,7 +95,6 @@ fun SendScreen( val uiState by viewModel.uiState.collectAsStateWithLifecycle() val currentOnClose by rememberUpdatedState(onClose) val currentOnBusyChange by rememberUpdatedState(onBusyChange) - val haptic = LocalHapticFeedback.current LaunchedEffect(viewModel) { viewModel.effects.collect { when (it) { @@ -112,17 +111,6 @@ fun SendScreen( // A screen that leaves while busy must not leave the swipe to dismiss off for every other screen. DisposableEffect(Unit) { onDispose { currentOnBusyChange(false) } } val step = uiState.step - // Keyed by the result too, so a pending payment that turns sent or failed while it shows is felt again. - LaunchedEffect((step as? SendStep.Done)?.result, step is SendStep.Failed, step is SendStep.Offline) { - when (step) { - is SendStep.Done if step.result == SendResult.Sent -> - haptic.performHapticFeedback(HapticFeedbackType.Confirm) - // Softer than the other two: the payment is under way, neither done nor refused. - is SendStep.Done -> haptic.performHapticFeedback(HapticFeedbackType.ContextClick) - is SendStep.Failed, SendStep.Offline -> haptic.performHapticFeedback(HapticFeedbackType.Reject) - else -> Unit - } - } BackHandler(enabled = uiState.isBusy) {} Content( uiState = uiState, @@ -174,7 +162,20 @@ internal fun Content( // The always-on screen shows no amount, typed, reviewed or sent, and nothing to hold. val isSent = step is SendStep.Done && step.result == SendResult.Sent // Decided above the ambient screen, so that waking the watch does not play it again. A flow sends once. - val isCelebrated = rememberCelebration(key = SENT_KEY.takeIf { isSent }, isAmbient = isAmbient) + val celebration = rememberCelebration(key = SENT_KEY.takeIf { isSent }, isAmbient = isAmbient) + val haptic = LocalHapticFeedback.current + // Keyed by the result too, so a pending payment that turns sent or failed while it shows is felt again. Sent is + // felt once, in ambient mode too, and not again when the screen is made again. + LaunchedEffect((step as? SendStep.Done)?.result, step is SendStep.Failed, step is SendStep.Offline) { + when (step) { + is SendStep.Done if step.result == SendResult.Sent -> + if (celebration.isFirstShown) haptic.performHapticFeedback(HapticFeedbackType.Confirm) + // Softer than the other two: the payment is under way, neither done nor refused. + is SendStep.Done -> haptic.performHapticFeedback(HapticFeedbackType.ContextClick) + is SendStep.Failed, SendStep.Offline -> haptic.performHapticFeedback(HapticFeedbackType.Reject) + else -> Unit + } + } if (isAmbient && (step is SendStep.Amount || step is SendStep.Review || isSent)) { Hidden(modifier = modifier) return@SpendingTheme @@ -199,7 +200,7 @@ internal fun Content( is SendStep.Done, is SendStep.Failed, SendStep.Offline -> Ended( step = step, isAmountShown = !isAmbient, - isCelebrated = isCelebrated, + isCelebrated = celebration.isCelebrated, onCloseClick = onCloseClick, modifier = modifier ) diff --git a/wear/src/test/java/to/bitkit/wear/ui/components/CelebrationTest.kt b/wear/src/test/java/to/bitkit/wear/ui/components/CelebrationTest.kt index 4ddf2f253b..dd2c6fcb9a 100644 --- a/wear/src/test/java/to/bitkit/wear/ui/components/CelebrationTest.kt +++ b/wear/src/test/java/to/bitkit/wear/ui/components/CelebrationTest.kt @@ -15,7 +15,10 @@ import kotlin.test.assertEquals import kotlin.test.assertFalse import kotlin.test.assertTrue -/** When a success is celebrated: once, as it is first shown awake, and never again on waking or a new screen. */ +/** + * When a success is first shown and celebrated: once, as it is first shown awake, and never again on waking, on being + * shown again or on a new screen. + */ @Config(sdk = [34]) @RunWith(RobolectricTestRunner::class) class CelebrationTest { @@ -24,13 +27,13 @@ class CelebrationTest { private var key by mutableStateOf("payment-0") private var isAmbient by mutableStateOf(false) - private var isCelebrated: Boolean? = null + private var celebration: Celebration? = null - private fun setContent() = composeRule.setContent { isCelebrated = rememberCelebration(key, isAmbient) } + private fun setContent() = composeRule.setContent { celebration = rememberCelebration(key, isAmbient) } private fun isCelebrated(): Boolean { composeRule.waitForIdle() - return checkNotNull(isCelebrated) + return checkNotNull(celebration).isCelebrated } @Test @@ -70,13 +73,38 @@ class CelebrationTest { } @Test - fun `a success is not celebrated again when the screen is made again`() { + fun `a success cut short awake and shown again is not celebrated again`() { + setContent() + assertTrue(isCelebrated()) + + key = null + assertFalse(isCelebrated()) + key = "payment-0" + assertFalse(isCelebrated()) + assertFalse(checkNotNull(celebration).isFirstShown) + } + + @Test + fun `a success is first shown once, in ambient mode too`() { + isAmbient = true + var firstShows = 0 + composeRule.setContent { if (rememberCelebration(key, isAmbient).isFirstShown) firstShows++ } + composeRule.waitForIdle() + assertEquals(1, firstShows) + + isAmbient = false + composeRule.waitForIdle() + assertEquals(1, firstShows) + } + + @Test + fun `a success is neither celebrated nor first shown again when the screen is made again`() { val restoration = StateRestorationTester(composeRule) - restoration.setContent { isCelebrated = rememberCelebration(key, isAmbient) } + restoration.setContent { celebration = rememberCelebration(key, isAmbient) } assertTrue(isCelebrated()) restoration.emulateSavedInstanceStateRestore() - assertEquals(false, isCelebrated) + assertEquals(Celebration(isFirstShown = false, isCelebrated = false), celebration) } } diff --git a/wear/src/test/java/to/bitkit/wear/ui/components/RecordingHapticFeedback.kt b/wear/src/test/java/to/bitkit/wear/ui/components/RecordingHapticFeedback.kt new file mode 100644 index 0000000000..f25db86268 --- /dev/null +++ b/wear/src/test/java/to/bitkit/wear/ui/components/RecordingHapticFeedback.kt @@ -0,0 +1,13 @@ +package to.bitkit.wear.ui.components + +import androidx.compose.ui.hapticfeedback.HapticFeedback +import androidx.compose.ui.hapticfeedback.HapticFeedbackType + +/** A haptic that plays nothing and keeps each one asked for, in order. */ +internal class RecordingHapticFeedback : HapticFeedback { + val played = mutableListOf() + + override fun performHapticFeedback(hapticFeedbackType: HapticFeedbackType) { + played += hapticFeedbackType + } +} diff --git a/wear/src/test/java/to/bitkit/wear/ui/components/SendOutcomeOverlayTest.kt b/wear/src/test/java/to/bitkit/wear/ui/components/SendOutcomeOverlayTest.kt index 297c9647ef..032a8bc7a1 100644 --- a/wear/src/test/java/to/bitkit/wear/ui/components/SendOutcomeOverlayTest.kt +++ b/wear/src/test/java/to/bitkit/wear/ui/components/SendOutcomeOverlayTest.kt @@ -1,10 +1,13 @@ package to.bitkit.wear.ui.components import androidx.activity.ComponentActivity +import androidx.compose.runtime.CompositionLocalProvider import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.setValue import androidx.compose.runtime.snapshots.Snapshot +import androidx.compose.ui.hapticfeedback.HapticFeedbackType +import androidx.compose.ui.platform.LocalHapticFeedback import androidx.compose.ui.semantics.SemanticsProperties import androidx.compose.ui.test.SemanticsMatcher import androidx.compose.ui.test.assert @@ -18,6 +21,7 @@ import org.robolectric.RobolectricTestRunner import org.robolectric.annotation.Config import to.bitkit.wear.ui.ShownOutcome import to.bitkit.wear.ui.screens.home.DisplayAmount +import kotlin.test.assertEquals /** * The outcome overlay as a screen reader gets it: one line with the status and the amount, which is also its pane @@ -39,7 +43,6 @@ class SendOutcomeOverlayTest { @get:Rule val composeRule = createAndroidComposeRule() - /** Tells Compose of the test's own changes of state, then lets a few frames run, as the clock is driven here. */ private fun advanceFrames() { Snapshot.sendApplyNotifications() composeRule.mainClock.advanceTimeBy(FRAMES_MS) @@ -89,6 +92,62 @@ class SendOutcomeOverlayTest { composeRule.onNodeWithTag("WatchConfetti").assertDoesNotExist() } + @Test + fun `an outcome hidden by ambient mode or cut short plays neither its haptic nor its confetti again`() { + composeRule.mainClock.autoAdvance = false + val haptic = RecordingHapticFeedback() + val sent = ShownOutcome("id", isSent = true, AMOUNT) + var outcome by mutableStateOf(sent) + var isAmbient by mutableStateOf(false) + composeRule.setContent { + WearPreview { + CompositionLocalProvider(LocalHapticFeedback provides haptic) { + OutcomeOverlay(outcome = outcome, isAmbient = isAmbient) + } + } + } + advanceFrames() + composeRule.onNodeWithTag("WatchConfetti").assertExists() + assertEquals(listOf(HapticFeedbackType.Confirm), haptic.played) + + isAmbient = true + advanceFrames() + composeRule.onNodeWithTag("WatchOutcomeSent").assertDoesNotExist() + isAmbient = false + advanceFrames() + composeRule.onNodeWithTag("WatchOutcomeSent").assertExists() + composeRule.onNodeWithTag("WatchConfetti").assertDoesNotExist() + + // As when the lock screen or leaving the app cuts it short, and it shows again after. + outcome = null + advanceFrames() + outcome = sent + advanceFrames() + composeRule.onNodeWithTag("WatchOutcomeSent").assertExists() + composeRule.onNodeWithTag("WatchConfetti").assertDoesNotExist() + assertEquals(listOf(HapticFeedbackType.Confirm), haptic.played) + } + + @Test + fun `the next outcome plays its own haptic and confetti`() { + composeRule.mainClock.autoAdvance = false + val haptic = RecordingHapticFeedback() + var outcome by mutableStateOf(ShownOutcome("id", isSent = false, AMOUNT)) + composeRule.setContent { + WearPreview { + CompositionLocalProvider(LocalHapticFeedback provides haptic) { + OutcomeOverlay(outcome = outcome, isAmbient = false) + } + } + } + advanceFrames() + outcome = ShownOutcome("id-1", isSent = true, AMOUNT) + advanceFrames() + + composeRule.onNodeWithTag("WatchConfetti").assertExists() + assertEquals(listOf(HapticFeedbackType.Reject, HapticFeedbackType.Confirm), haptic.played) + } + @Test fun `the outcome is one node, with nothing of its own beneath for a screen reader to step through`() { composeRule.setContent { WearPreview { OutcomeContent(ShownOutcome("id", isSent = true, AMOUNT)) } } diff --git a/wear/src/test/java/to/bitkit/wear/ui/screens/receive/ReceiveQrContentTest.kt b/wear/src/test/java/to/bitkit/wear/ui/screens/receive/ReceiveQrContentTest.kt index 17f64746e1..f47bce42b9 100644 --- a/wear/src/test/java/to/bitkit/wear/ui/screens/receive/ReceiveQrContentTest.kt +++ b/wear/src/test/java/to/bitkit/wear/ui/screens/receive/ReceiveQrContentTest.kt @@ -1,10 +1,13 @@ package to.bitkit.wear.ui.screens.receive import androidx.activity.ComponentActivity +import androidx.compose.runtime.CompositionLocalProvider import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.setValue import androidx.compose.runtime.snapshots.Snapshot +import androidx.compose.ui.hapticfeedback.HapticFeedbackType +import androidx.compose.ui.platform.LocalHapticFeedback import androidx.compose.ui.semantics.SemanticsActions import androidx.compose.ui.semantics.getOrNull import androidx.compose.ui.test.SemanticsMatcher @@ -12,6 +15,7 @@ import androidx.compose.ui.test.assert import androidx.compose.ui.test.assertContentDescriptionEquals import androidx.compose.ui.test.assertHasNoClickAction import androidx.compose.ui.test.click +import androidx.compose.ui.test.junit4.StateRestorationTester import androidx.compose.ui.test.junit4.createAndroidComposeRule import androidx.compose.ui.test.onNodeWithContentDescription import androidx.compose.ui.test.onNodeWithTag @@ -26,6 +30,7 @@ import org.robolectric.RobolectricTestRunner import org.robolectric.annotation.Config import org.robolectric.shadows.ShadowSystemClock import to.bitkit.wear.ui.components.NfcHintState +import to.bitkit.wear.ui.components.RecordingHapticFeedback import to.bitkit.wear.ui.components.WearPreview import to.bitkit.wear.ui.screens.home.DisplayAmount import kotlin.test.assertEquals @@ -45,7 +50,6 @@ class ReceiveQrContentTest { @get:Rule val composeRule = createAndroidComposeRule() - /** Tells Compose of the test's own changes of state, then lets a few frames run, as the clock is driven here. */ private fun advanceFrames() { Snapshot.sendApplyNotifications() composeRule.mainClock.advanceTimeBy(FRAMES_MS) @@ -153,6 +157,45 @@ class ReceiveQrContentTest { composeRule.onNodeWithTag("WatchConfetti").assertExists() } + @Test + fun `a paid invoice plays its haptic once, and not again when the screen is made again`() { + val haptic = RecordingHapticFeedback() + val restoration = StateRestorationTester(composeRule) + restoration.setContent { + WearPreview { + CompositionLocalProvider(LocalHapticFeedback provides haptic) { + ReceiveQrContent(uiState = paid, isAmbient = false, onRefreshClick = {}) + } + } + } + composeRule.waitForIdle() + assertEquals(listOf(HapticFeedbackType.LongPress), haptic.played) + + restoration.emulateSavedInstanceStateRestore() + composeRule.waitForIdle() + + assertEquals(listOf(HapticFeedbackType.LongPress), haptic.played) + composeRule.onNodeWithTag("WatchConfetti").assertDoesNotExist() + } + + @Test + fun `an invoice paid in ambient mode plays its haptic, and waking does not play it again`() { + val haptic = RecordingHapticFeedback() + var isAmbient by mutableStateOf(true) + composeRule.setContent { + WearPreview { + CompositionLocalProvider(LocalHapticFeedback provides haptic) { + ReceiveQrContent(uiState = paid, isAmbient = isAmbient, onRefreshClick = {}) + } + } + } + composeRule.waitForIdle() + isAmbient = false + composeRule.waitForIdle() + + assertEquals(listOf(HapticFeedbackType.LongPress), haptic.played) + } + @Test fun `a tap anywhere on the resting screen shows the qr again`() { setContent(shown, isAmbient = false, isResting = true) diff --git a/wear/src/test/java/to/bitkit/wear/ui/screens/send/SendResultTest.kt b/wear/src/test/java/to/bitkit/wear/ui/screens/send/SendResultTest.kt index ab288d4fe9..5aaf9241fd 100644 --- a/wear/src/test/java/to/bitkit/wear/ui/screens/send/SendResultTest.kt +++ b/wear/src/test/java/to/bitkit/wear/ui/screens/send/SendResultTest.kt @@ -1,16 +1,20 @@ package to.bitkit.wear.ui.screens.send import androidx.activity.ComponentActivity +import androidx.compose.runtime.CompositionLocalProvider import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.setValue import androidx.compose.runtime.snapshots.Snapshot +import androidx.compose.ui.hapticfeedback.HapticFeedbackType +import androidx.compose.ui.platform.LocalHapticFeedback import androidx.compose.ui.semantics.LiveRegionMode import androidx.compose.ui.semantics.SemanticsProperties import androidx.compose.ui.test.SemanticsMatcher import androidx.compose.ui.test.assert import androidx.compose.ui.test.assertIsDisplayed import androidx.compose.ui.test.assertTextEquals +import androidx.compose.ui.test.junit4.StateRestorationTester import androidx.compose.ui.test.junit4.createAndroidComposeRule import androidx.compose.ui.test.onNodeWithTag import org.junit.Rule @@ -18,6 +22,7 @@ import org.junit.Test import org.junit.runner.RunWith import org.robolectric.RobolectricTestRunner import org.robolectric.annotation.Config +import to.bitkit.wear.ui.components.RecordingHapticFeedback import to.bitkit.wear.ui.components.WearPreview import to.bitkit.wear.ui.screens.home.DisplayAmount import kotlin.test.assertEquals @@ -36,7 +41,6 @@ class SendResultTest { @get:Rule val composeRule = createAndroidComposeRule() - /** Tells Compose of the test's own changes of state, then lets a few frames run, as the clock is driven here. */ private fun advanceFrames() { Snapshot.sendApplyNotifications() composeRule.mainClock.advanceTimeBy(FRAMES_MS) @@ -130,6 +134,34 @@ class SendResultTest { composeRule.onNodeWithTag("WatchConfetti").assertDoesNotExist() } + @Test + fun `a sent result plays its haptic once, and not again when the screen is made again`() { + val haptic = RecordingHapticFeedback() + val restoration = StateRestorationTester(composeRule) + restoration.setContent { + WearPreview { + CompositionLocalProvider(LocalHapticFeedback provides haptic) { + Content( + uiState = SendUiState(step = SendStep.Done(SendResult.Sent, AMOUNT)), + isAmbient = false, + onAmountChange = {}, + onAmountConfirm = {}, + onHoldComplete = {}, + onCloseClick = {}, + ) + } + } + } + composeRule.waitForIdle() + assertEquals(listOf(HapticFeedbackType.Confirm), haptic.played) + + restoration.emulateSavedInstanceStateRestore() + composeRule.waitForIdle() + + assertEquals(listOf(HapticFeedbackType.Confirm), haptic.played) + composeRule.onNodeWithTag("WatchConfetti").assertDoesNotExist() + } + @Test fun `only a sent result has confetti`() { setResult(SendStep.Done(SendResult.Pending, AMOUNT), isAmbient = false) From dda7e77e880a557045925b12cbaafec7396c42e1 Mon Sep 17 00:00:00 2001 From: Joao Victor Sena Date: Sun, 29 Nov 2026 19:17:54 -0300 Subject: [PATCH 23/38] fix: keep the watch link store of an earlier build's unpair Co-Authored-By: Claude Opus 5.5 --- .../serializers/WatchLinkSerializerTest.kt | 29 +++++++++++++++++ .../kotlin/to/bitkit/wearlink/LinkDocs.kt | 31 ++++++++++++++++++- .../kotlin/to/bitkit/wearlink/LinkDocsTest.kt | 17 ++++++++++ 3 files changed, 76 insertions(+), 1 deletion(-) create mode 100644 app/src/test/java/to/bitkit/data/serializers/WatchLinkSerializerTest.kt diff --git a/app/src/test/java/to/bitkit/data/serializers/WatchLinkSerializerTest.kt b/app/src/test/java/to/bitkit/data/serializers/WatchLinkSerializerTest.kt new file mode 100644 index 0000000000..fb9c479357 --- /dev/null +++ b/app/src/test/java/to/bitkit/data/serializers/WatchLinkSerializerTest.kt @@ -0,0 +1,29 @@ +package to.bitkit.data.serializers + +import kotlinx.serialization.encodeToString +import org.junit.Test +import to.bitkit.data.WatchLinkData +import to.bitkit.di.json +import to.bitkit.test.BaseUnitTest +import to.bitkit.wearlink.LinkRecord +import to.bitkit.wearlink.Removal +import java.io.ByteArrayInputStream +import kotlin.test.assertEquals + +class WatchLinkSerializerTest : BaseUnitTest() { + @Test + fun `read keeps the store of a record with the unpair removal of an earlier build, without the removal`() = test { + val record = LinkRecord("pairing", "peer", "node", "Watch", pairedAtMs = 1, removal = Removal.Erase) + val stored = WatchLinkData( + record = record, + transferAttempts = 2, + transferLockedUntilMs = 100, + pairPromptNodeIds = listOf("node"), + ) + val raw = json.encodeToString(stored).replace("\"Erase\"", "\"Unpair\"") + + val result = WatchLinkSerializer.readFrom(ByteArrayInputStream(raw.encodeToByteArray())) + + assertEquals(stored.copy(record = record.copy(removal = null)), result) + } +} diff --git a/wearlink/src/main/kotlin/to/bitkit/wearlink/LinkDocs.kt b/wearlink/src/main/kotlin/to/bitkit/wearlink/LinkDocs.kt index 62febe9c4e..e34093c6e3 100644 --- a/wearlink/src/main/kotlin/to/bitkit/wearlink/LinkDocs.kt +++ b/wearlink/src/main/kotlin/to/bitkit/wearlink/LinkDocs.kt @@ -1,7 +1,15 @@ package to.bitkit.wearlink import kotlinx.coroutines.flow.Flow +import kotlinx.serialization.ExperimentalSerializationApi +import kotlinx.serialization.KSerializer import kotlinx.serialization.Serializable +import kotlinx.serialization.descriptors.PrimitiveKind +import kotlinx.serialization.descriptors.PrimitiveSerialDescriptor +import kotlinx.serialization.descriptors.SerialDescriptor +import kotlinx.serialization.descriptors.nullable +import kotlinx.serialization.encoding.Decoder +import kotlinx.serialization.encoding.Encoder import kotlinx.serialization.json.Json /** The state documents of a pairing. Each has one writer and is a full snapshot, so applying one twice is harmless. */ @@ -59,9 +67,29 @@ data class StatusDoc( } } -/** A removal the phone asked for and the watch has not acknowledged: the phone only ever asks for an erase. */ +/** + * A removal the phone asked for and the watch has not acknowledged: the phone only ever asks for an erase. A record + * reads a removal this build does not know, as the `Unpair` of an earlier build, as none, so that the rest of the + * record and its store are kept, and the watch's wallet is not erased for a request that did not ask for it. + */ enum class Removal { Erase } +@OptIn(ExperimentalSerializationApi::class) +private object LenientRemovalSerializer : KSerializer { + override val descriptor: SerialDescriptor = + PrimitiveSerialDescriptor("to.bitkit.wearlink.Removal", PrimitiveKind.STRING).nullable + + override fun serialize(encoder: Encoder, value: Removal?) { + if (value == null) encoder.encodeNull() else encoder.encodeString(value.name) + } + + override fun deserialize(decoder: Decoder): Removal? { + if (!decoder.decodeNotNullMark()) return decoder.decodeNull() + val name = decoder.decodeString() + return Removal.entries.firstOrNull { it.name == name } + } +} + /** * One device's note of its pairing. It holds nothing secret: the keys are in the key store, under [pairingId]. * [settingsSent] is the counter of the phone's last settings document, and [settingsApplied] the last one the watch @@ -81,6 +109,7 @@ data class LinkRecord( val isPeerLockSet: Boolean = false, val sendCounter: Long = 0, val received: Map = emptyMap(), + @Serializable(with = LenientRemovalSerializer::class) val removal: Removal? = null, val settingsSent: Long = 0, val settingsApplied: Long = 0, diff --git a/wearlink/src/test/kotlin/to/bitkit/wearlink/LinkDocsTest.kt b/wearlink/src/test/kotlin/to/bitkit/wearlink/LinkDocsTest.kt index d1f2a2d59b..e97f21cd05 100644 --- a/wearlink/src/test/kotlin/to/bitkit/wearlink/LinkDocsTest.kt +++ b/wearlink/src/test/kotlin/to/bitkit/wearlink/LinkDocsTest.kt @@ -14,4 +14,21 @@ class LinkDocsTest { assertEquals(SettingsDoc("BITCOIN", "MODERN", "EUR", true, 5, 5, changedAtMs = 100), settings) } + + @Test + fun `a record with the unpair removal of an earlier build reads as one without a removal`() { + val record = LinkRecord("pairing", "peer", "node", "Watch", pairedAtMs = 1, removal = Removal.Erase) + val raw = linkJson.encodeToString(record).replace("\"Erase\"", "\"Unpair\"") + + assertEquals(record.copy(removal = null), linkJson.decodeFromString(raw)) + } + + @Test + fun `a record keeps its erase removal and its lack of one`() { + val record = LinkRecord("pairing", "peer", "node", "Watch", pairedAtMs = 1, removal = Removal.Erase) + + assertEquals(record, linkJson.decodeFromString(linkJson.encodeToString(record))) + val none = record.copy(removal = null) + assertEquals(none, linkJson.decodeFromString(linkJson.encodeToString(none))) + } } From fef4f81b95a5d6268021e617ddd36814d89f868d Mon Sep 17 00:00:00 2001 From: Joao Victor Sena Date: Sun, 29 Nov 2026 19:18:47 -0300 Subject: [PATCH 24/38] fix: morph the watch's activity detail lines at the screen edge Co-Authored-By: Claude Opus 5.5 --- .../screens/activity/ActivityDetailScreen.kt | 29 +++++++++++++++---- 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/wear/src/main/java/to/bitkit/wear/ui/screens/activity/ActivityDetailScreen.kt b/wear/src/main/java/to/bitkit/wear/ui/screens/activity/ActivityDetailScreen.kt index 9a97712d0c..233f2b6000 100644 --- a/wear/src/main/java/to/bitkit/wear/ui/screens/activity/ActivityDetailScreen.kt +++ b/wear/src/main/java/to/bitkit/wear/ui/screens/activity/ActivityDetailScreen.kt @@ -18,6 +18,7 @@ import androidx.compose.ui.unit.dp import androidx.lifecycle.compose.collectAsStateWithLifecycle import androidx.wear.compose.material3.MaterialTheme import androidx.wear.compose.material3.Text +import androidx.wear.compose.material3.lazy.transformedHeight import to.bitkit.wear.R import to.bitkit.wear.ext.UiDateStyle import to.bitkit.wear.ext.uiDateText @@ -92,10 +93,15 @@ internal fun ActivityDetailContent( val time = remember(payment.timestampSecs, is24Hour) { uiDateText(payment.timestampSecs, UiDateStyle.DATE_TIME, is24Hour) } - ListScreen(modifier = modifier) { + ListScreen(modifier = modifier) { spec -> if (!isAmbient) { item { - BoxWithConstraints(contentAlignment = Alignment.Center, modifier = Modifier.fillMaxWidth()) { + BoxWithConstraints( + contentAlignment = Alignment.Center, + modifier = Modifier + .fillMaxWidth() + .transformedHeight(this, spec) + ) { LargeAmountRow( amount = bitcoinAmount(payment.amountSats.toLong(), unit), maxWidth = maxWidth, @@ -110,7 +116,9 @@ internal fun ActivityDetailContent( val fee = bitcoinAmount(payment.feeSats.toLong(), unit) Line( text = stringResource(R.string.send__fee, "${fee.symbol} ${fee.text}"), - modifier = Modifier.testTag("WatchActivityDetailFee") + modifier = Modifier + .transformedHeight(this, spec) + .testTag("WatchActivityDetailFee") ) } } @@ -119,18 +127,27 @@ internal fun ActivityDetailContent( Line( text = message, color = Color.Unspecified, - modifier = Modifier.testTag("WatchActivityDetailMessage") + modifier = Modifier + .transformedHeight(this, spec) + .testTag("WatchActivityDetailMessage") ) } } item { - Line(text = time, modifier = Modifier.testTag("WatchActivityDetailTime")) + Line( + text = time, + modifier = Modifier + .transformedHeight(this, spec) + .testTag("WatchActivityDetailTime") + ) } item { Row( verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.spacedBy(4.dp, Alignment.CenterHorizontally), - modifier = Modifier.fillMaxWidth() + modifier = Modifier + .fillMaxWidth() + .transformedHeight(this, spec) ) { ActivityIcon(payment = payment, size = STATUS_ICON_SIZE) Text( From 10b27446c419f061078d94b01d3f49e0aea2b0b4 Mon Sep 17 00:00:00 2001 From: Joao Victor Sena Date: Sun, 29 Nov 2026 19:19:52 -0300 Subject: [PATCH 25/38] refactor: drop the sheet intro icon's unused tint Co-Authored-By: Claude Opus 5.5 --- app/src/main/java/to/bitkit/ui/components/SheetIntro.kt | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/to/bitkit/ui/components/SheetIntro.kt b/app/src/main/java/to/bitkit/ui/components/SheetIntro.kt index 71be3a5fb3..82e54c8531 100644 --- a/app/src/main/java/to/bitkit/ui/components/SheetIntro.kt +++ b/app/src/main/java/to/bitkit/ui/components/SheetIntro.kt @@ -16,7 +16,6 @@ import androidx.compose.foundation.layout.size import androidx.compose.runtime.Composable import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier -import androidx.compose.ui.graphics.Color import androidx.compose.ui.graphics.ColorFilter import androidx.compose.ui.layout.ContentScale import androidx.compose.ui.platform.testTag @@ -35,13 +34,12 @@ private val SHEET_INTRO_ICON_SIZE = 160.dp /** * A one-colour [icon] that stands in for intro sheet artwork where none exists, enlarged and centred in the artwork's - * slot, in [tint]: Brand orange, as the intro sheets' accented titles. + * slot, in Brand orange, as the intro sheets' accented titles. */ @Composable fun ColumnScope.SheetIntroIcon( @DrawableRes icon: Int, modifier: Modifier = Modifier, - tint: Color = Colors.Brand, ) { Box( contentAlignment = Alignment.Center, @@ -53,7 +51,7 @@ fun ColumnScope.SheetIntroIcon( painter = painterResource(icon), contentDescription = null, contentScale = ContentScale.Fit, - colorFilter = ColorFilter.tint(tint), + colorFilter = ColorFilter.tint(Colors.Brand), modifier = modifier.size(SHEET_INTRO_ICON_SIZE) ) } From b431da1530456db356cbe932df7fd148e3a82958 Mon Sep 17 00:00:00 2001 From: Joao Victor Sena Date: Sun, 29 Nov 2026 19:19:53 -0300 Subject: [PATCH 26/38] style: drop the kdoc of a private watch payment helper Co-Authored-By: Claude Opus 5.5 --- .../src/main/java/to/bitkit/wear/repositories/PaymentsRepo.kt | 4 ---- 1 file changed, 4 deletions(-) diff --git a/wear/src/main/java/to/bitkit/wear/repositories/PaymentsRepo.kt b/wear/src/main/java/to/bitkit/wear/repositories/PaymentsRepo.kt index fe7837b1fa..707b20a570 100644 --- a/wear/src/main/java/to/bitkit/wear/repositories/PaymentsRepo.kt +++ b/wear/src/main/java/to/bitkit/wear/repositories/PaymentsRepo.kt @@ -779,10 +779,6 @@ private fun Payment.toWatchPayment() = WatchPayment( message = message(), ) -/** - * The payment's note: an LNURL comment the payer wrote, which the phone keeps over the invoice's description, or - * else the invoice's description. Null when it has none. - */ private fun Payment.message(): String? { val note = when (val details = details) { is PaymentDetails.Lightning -> From 569fe89004e9362b2404ac98d6d40c4f407af136 Mon Sep 17 00:00:00 2001 From: Joao Victor Sena Date: Sun, 29 Nov 2026 19:20:45 -0300 Subject: [PATCH 27/38] test: check the watch confetti in the dump that finds the success Co-Authored-By: Claude Opus 5.5 --- journeys/wear/README.md | 12 +++++++++--- journeys/wear/receive-paid-ambient.xml | 5 ++--- journeys/wear/receive-paid.xml | 5 ++--- journeys/wear/send-deeplink-bolt11.xml | 3 +-- 4 files changed, 14 insertions(+), 11 deletions(-) diff --git a/journeys/wear/README.md b/journeys/wear/README.md index b577619003..4a98455f33 100644 --- a/journeys/wear/README.md +++ b/journeys/wear/README.md @@ -17,9 +17,6 @@ What `android layout` misses on the watch, verified on the API 37 emulator: - **The receive QR.** `WatchReceiveQr` is an image with no text or action, so `android layout` leaves it out; `adb shell uiautomator dump` lists it. Check it there or from a screenshot. `WatchReceiveHidden`, the screen with the dimmed icon that replaces it in ambient mode and once it rests, has a content-desc and is listed. -- **The confetti.** `WatchConfetti`, the canvas the confetti of a success falls on, has no text or action, so - `android layout` leaves it out; `adb shell uiautomator dump` lists it while it falls, for under 2 s, so dump at once. - A screenshot rarely catches the pieces in time: check the confetti with the dump and the colours from a screenshot. - **Suggestion chips.** A chip's tag (`RestoreSuggestion-0`, counted from 0) is on the button and its word is a text node at the same `center`. A chip below the screen edge is not listed until the screen scrolls. - **The keyboard.** The Wear OS keyboard is a full-screen window that `android layout` does not show. It lists the @@ -28,6 +25,15 @@ What `android layout` misses on the watch, verified on the API 37 emulator: release builds only, as on the phone; debug builds capture them. Never capture the word or passphrase screens with a recovery phrase on them. +Not yet confirmed on an emulator: + +- **The confetti.** `WatchConfetti`, the canvas the confetti of a success falls on, has no text or action, so + `android layout` leaves it out; `adb shell uiautomator dump` should list it while it falls, for under 2 s. That is + too short for a wait in one step and a dump in the next, so a journey waits for the success and looks for the + confetti in the same dump, in one `adb shell` loop that runs on the watch, and checks that waking plays none by + dumping repeatedly over the 2 s after the wake. A screenshot rarely catches the pieces in time: check the confetti + with the dump and the colours from a screenshot. + ## Emulators | AVD | Screen | System image | diff --git a/journeys/wear/receive-paid-ambient.xml b/journeys/wear/receive-paid-ambient.xml index ef81a08128..c9573bbc28 100644 --- a/journeys/wear/receive-paid-ambient.xml +++ b/journeys/wear/receive-paid-ambient.xml @@ -18,9 +18,8 @@ Wait up to 20 s until "WatchReceivePaid" is listed Verify neither "WatchReceivePaidAmount" nor "WatchReceiveNew" is listed Verify `adb shell uiautomator dump` does not list "WatchConfetti": the always-on screen has no confetti - Run `adb shell input keyevent KEYCODE_WAKEUP` - Wait up to 5 s until "WatchReceivePaidAmount" reads "1 000" - Verify at once that `adb shell uiautomator dump` does not list "WatchConfetti": waking plays no celebration + Run `adb shell 'input keyevent KEYCODE_WAKEUP; for i in 1 2 3; do rm -f /sdcard/x.xml; uiautomator dump /sdcard/x.xml >/dev/null 2>&1; echo "$i: $(grep -oE "WatchReceivePaidAmount|WatchConfetti" /sdcard/x.xml | sort -u | tr "\n" " ")"; done'`, which wakes the watch and dumps three times over the 2 s a confetti would fall, and verify that no line prints "WatchConfetti", and that a line prints "WatchReceivePaidAmount": waking plays no celebration + Verify "WatchReceivePaidAmount" reads "1 000" Verify "WatchReceiveNew" is listed diff --git a/journeys/wear/receive-paid.xml b/journeys/wear/receive-paid.xml index 704fd30dd4..5f0be73949 100644 --- a/journeys/wear/receive-paid.xml +++ b/journeys/wear/receive-paid.xml @@ -17,10 +17,9 @@ Wait up to 10 s until `adb shell uiautomator dump` lists "WatchReceiveQr" (README, top) Read the invoice from the log as in README › Reading the receive invoice and note it as <invoice> Run `../bitkit-docker/spark pay <invoice> 50000` from this repo's parent checkout - Wait up to 20 s until "WatchReceivePaid" is listed - Verify at once that `adb shell uiautomator dump` lists "WatchConfetti" (README, top): the confetti falls for under 2 s + Run `adb shell 'for i in $(seq 30); do rm -f /sdcard/x.xml; uiautomator dump /sdcard/x.xml >/dev/null 2>&1; d=$(cat /sdcard/x.xml 2>/dev/null); case "$d" in *WatchReceivePaid*) break;; esac; done; echo "$d" | grep -oE "WatchReceivePaid|WatchConfetti" | sort -u'`, which waits up to about 30 s for the check and looks in that same dump for the confetti (README › The confetti), and verify it prints both "WatchConfetti" and "WatchReceivePaid" Verify "WatchReceivePaidAmount" reads "50 000" - Wait 3 s, then verify `adb shell uiautomator dump` no longer lists "WatchConfetti" and still lists "WatchReceivePaid" + Run `adb shell 'sleep 3; rm -f /sdcard/x.xml; uiautomator dump /sdcard/x.xml >/dev/null 2>&1; grep -oE "WatchReceivePaid|WatchConfetti" /sdcard/x.xml | sort -u'` and verify it prints "WatchReceivePaid" and not "WatchConfetti": the confetti is gone Verify from a screenshot that the check is purple Verify the button below the check reads "New invoice" (tag "WatchReceiveNew") Tap the check (tag "WatchReceivePaid") and verify "WatchReceivePaid" is still listed 2 s later: the check is no button diff --git a/journeys/wear/send-deeplink-bolt11.xml b/journeys/wear/send-deeplink-bolt11.xml index 50320a08e2..e16d0d67a8 100644 --- a/journeys/wear/send-deeplink-bolt11.xml +++ b/journeys/wear/send-deeplink-bolt11.xml @@ -17,8 +17,7 @@ Verify "WatchSendAmount" reads "1 000" Verify "WatchSendAmountSymbol" reads "₿" Hold "WatchSendHold" for 2 s as in README › Holding to pay - Wait up to 15 s until "WatchSendSent" is listed - Verify at once that `adb shell uiautomator dump` lists "WatchConfetti" (README, top): the confetti falls for under 2 s + Run `adb shell 'for i in $(seq 20); do rm -f /sdcard/x.xml; uiautomator dump /sdcard/x.xml >/dev/null 2>&1; d=$(cat /sdcard/x.xml 2>/dev/null); case "$d" in *WatchSendSent*) break;; esac; done; echo "$d" | grep -oE "WatchSendSent|WatchConfetti" | sort -u'`, which waits up to about 20 s for the check and looks in that same dump for the confetti (README › The confetti), and verify it prints both "WatchConfetti" and "WatchSendSent" Verify "WatchSendResultAmount" reads "1 000" Verify from a screenshot that the check is purple Wait 4 s From 4802de9f5b0b479aa1a97a596aacced8d7345e0e Mon Sep 17 00:00:00 2001 From: Joao Victor Sena Date: Sun, 29 Nov 2026 19:39:16 -0300 Subject: [PATCH 28/38] test: read the wear sent amount and screenshot in the same command Co-Authored-By: Claude Opus 5.5 --- journeys/wear/README.md | 9 ++++++--- journeys/wear/receive-paid-ambient.xml | 6 ++---- journeys/wear/receive-paid.xml | 2 +- journeys/wear/send-deeplink-bolt11.xml | 5 ++--- 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/journeys/wear/README.md b/journeys/wear/README.md index 4a98455f33..06f3cc0717 100644 --- a/journeys/wear/README.md +++ b/journeys/wear/README.md @@ -30,9 +30,12 @@ Not yet confirmed on an emulator: - **The confetti.** `WatchConfetti`, the canvas the confetti of a success falls on, has no text or action, so `android layout` leaves it out; `adb shell uiautomator dump` should list it while it falls, for under 2 s. That is too short for a wait in one step and a dump in the next, so a journey waits for the success and looks for the - confetti in the same dump, in one `adb shell` loop that runs on the watch, and checks that waking plays none by - dumping repeatedly over the 2 s after the wake. A screenshot rarely catches the pieces in time: check the confetti - with the dump and the colours from a screenshot. + confetti in the same dump, in one `adb shell` loop that runs on the watch. Each `uiautomator dump` waits about 1 s + for the screen to settle before its snapshot, so a pass of the loop takes about 2 s. The Sent screen closes 2 s after + it shows, so the send journey reads its amount from that dump and takes its screenshot with `screencap` in the same + command. That waking plays no confetti is checked only best-effort, by dumping a few times after the wake: the + first snapshot can land after the 2 s. A screenshot rarely catches the pieces in time: check the confetti with the + dump and the colours from a screenshot. ## Emulators diff --git a/journeys/wear/receive-paid-ambient.xml b/journeys/wear/receive-paid-ambient.xml index c9573bbc28..156e78593a 100644 --- a/journeys/wear/receive-paid-ambient.xml +++ b/journeys/wear/receive-paid-ambient.xml @@ -15,10 +15,8 @@ Run `adb shell input keyevent KEYCODE_SLEEP` Wait up to 5 s until "WatchReceiveHidden" is listed Run `../bitkit-docker/spark pay <invoice> 1000` from this repo's parent checkout - Wait up to 20 s until "WatchReceivePaid" is listed - Verify neither "WatchReceivePaidAmount" nor "WatchReceiveNew" is listed - Verify `adb shell uiautomator dump` does not list "WatchConfetti": the always-on screen has no confetti - Run `adb shell 'input keyevent KEYCODE_WAKEUP; for i in 1 2 3; do rm -f /sdcard/x.xml; uiautomator dump /sdcard/x.xml >/dev/null 2>&1; echo "$i: $(grep -oE "WatchReceivePaidAmount|WatchConfetti" /sdcard/x.xml | sort -u | tr "\n" " ")"; done'`, which wakes the watch and dumps three times over the 2 s a confetti would fall, and verify that no line prints "WatchConfetti", and that a line prints "WatchReceivePaidAmount": waking plays no celebration + Run `adb shell 'for i in $(seq 20); do rm -f /sdcard/x.xml; uiautomator dump /sdcard/x.xml >/dev/null 2>&1; d=$(cat /sdcard/x.xml 2>/dev/null); case "$d" in *WatchReceivePaid*) break;; esac; done; echo "$d" | grep -oE "WatchReceivePaidAmount|WatchReceivePaid|WatchReceiveNew|WatchConfetti" | sort -u'`, which dumps up to 20 times (about 2 s a dump) until the check shows and looks in that same dump for the amount, the button and the confetti, and verify it prints "WatchReceivePaid" alone: the always-on screen shows no amount and no confetti + Run `adb shell 'input keyevent KEYCODE_WAKEUP; for i in 1 2 3; do rm -f /sdcard/x.xml; uiautomator dump /sdcard/x.xml >/dev/null 2>&1; echo "$i: $(grep -oE "WatchReceivePaidAmount|WatchConfetti" /sdcard/x.xml | sort -u | tr "\n" " ")"; done'`, which wakes the watch and dumps three times, and verify that no line prints "WatchConfetti", and that a line prints "WatchReceivePaidAmount": waking plays no celebration. This check is best-effort: each dump waits for the screen to settle, so the first one can land up to about 2.5 s after the wake, past the 2 s a confetti would fall, and the others only confirm none started later. `CelebrationTest` and `ReceiveQrContentTest` are the real guard Verify "WatchReceivePaidAmount" reads "1 000" Verify "WatchReceiveNew" is listed diff --git a/journeys/wear/receive-paid.xml b/journeys/wear/receive-paid.xml index 5f0be73949..2af55b2c14 100644 --- a/journeys/wear/receive-paid.xml +++ b/journeys/wear/receive-paid.xml @@ -17,7 +17,7 @@ Wait up to 10 s until `adb shell uiautomator dump` lists "WatchReceiveQr" (README, top) Read the invoice from the log as in README › Reading the receive invoice and note it as <invoice> Run `../bitkit-docker/spark pay <invoice> 50000` from this repo's parent checkout - Run `adb shell 'for i in $(seq 30); do rm -f /sdcard/x.xml; uiautomator dump /sdcard/x.xml >/dev/null 2>&1; d=$(cat /sdcard/x.xml 2>/dev/null); case "$d" in *WatchReceivePaid*) break;; esac; done; echo "$d" | grep -oE "WatchReceivePaid|WatchConfetti" | sort -u'`, which waits up to about 30 s for the check and looks in that same dump for the confetti (README › The confetti), and verify it prints both "WatchConfetti" and "WatchReceivePaid" + Run `adb shell 'for i in $(seq 30); do rm -f /sdcard/x.xml; uiautomator dump /sdcard/x.xml >/dev/null 2>&1; d=$(cat /sdcard/x.xml 2>/dev/null); case "$d" in *WatchReceivePaid*) break;; esac; done; echo "$d" | grep -oE "WatchReceivePaid|WatchConfetti" | sort -u'`, which dumps up to 30 times (about 2 s a dump) until the check shows and looks in that same dump for the confetti (README › The confetti), and verify it prints both "WatchConfetti" and "WatchReceivePaid" Verify "WatchReceivePaidAmount" reads "50 000" Run `adb shell 'sleep 3; rm -f /sdcard/x.xml; uiautomator dump /sdcard/x.xml >/dev/null 2>&1; grep -oE "WatchReceivePaid|WatchConfetti" /sdcard/x.xml | sort -u'` and verify it prints "WatchReceivePaid" and not "WatchConfetti": the confetti is gone Verify from a screenshot that the check is purple diff --git a/journeys/wear/send-deeplink-bolt11.xml b/journeys/wear/send-deeplink-bolt11.xml index e16d0d67a8..c6e6811523 100644 --- a/journeys/wear/send-deeplink-bolt11.xml +++ b/journeys/wear/send-deeplink-bolt11.xml @@ -17,9 +17,8 @@ Verify "WatchSendAmount" reads "1 000" Verify "WatchSendAmountSymbol" reads "₿" Hold "WatchSendHold" for 2 s as in README › Holding to pay - Run `adb shell 'for i in $(seq 20); do rm -f /sdcard/x.xml; uiautomator dump /sdcard/x.xml >/dev/null 2>&1; d=$(cat /sdcard/x.xml 2>/dev/null); case "$d" in *WatchSendSent*) break;; esac; done; echo "$d" | grep -oE "WatchSendSent|WatchConfetti" | sort -u'`, which waits up to about 20 s for the check and looks in that same dump for the confetti (README › The confetti), and verify it prints both "WatchConfetti" and "WatchSendSent" - Verify "WatchSendResultAmount" reads "1 000" - Verify from a screenshot that the check is purple + Run `adb shell 'for i in $(seq 20); do rm -f /sdcard/x.xml; uiautomator dump /sdcard/x.xml >/dev/null 2>&1; d=$(cat /sdcard/x.xml 2>/dev/null); case "$d" in *WatchSendSent*) break;; esac; done; screencap -p /sdcard/sent.png; echo "$d" | grep -oE "WatchSendSent|WatchConfetti|text=.[^>]*resource-id=.WatchSendResultAmount" | sort -u'`, which dumps up to 20 times (about 2 s a dump) until the check shows, looks in that same dump for the confetti (README › The confetti) and the amount, and takes a screenshot right after it, since the Sent screen closes 2 s after it shows. Verify it prints "WatchConfetti", "WatchSendSent" and `text="1 000" resource-id="WatchSendResultAmount"` + Run `adb pull /sdcard/sent.png && adb shell rm /sdcard/sent.png` and verify from sent.png, the screenshot the step above took, that the check is purple Wait 4 s Verify the Balance page: "WatchHomeBalance" is listed Verify "WatchSendSent" is not listed From 5db849fc278101a5ef892e8b81caf45f88805248 Mon Sep 17 00:00:00 2001 From: Joao Victor Sena Date: Sun, 29 Nov 2026 20:20:03 -0300 Subject: [PATCH 29/38] feat: drop the start on phone hint from watch onboarding Co-Authored-By: Claude Opus 5.5 --- docs/wear.md | 4 +-- journeys/wear/README.md | 3 +-- journeys/wear/pair-prompt.xml | 2 +- journeys/wear/pair-receive-wallet.xml | 2 +- .../ui/screens/onboarding/OnboardingScreen.kt | 27 ++++--------------- wear/src/main/res/values-ar/strings.xml | 1 - wear/src/main/res/values-b+es+419/strings.xml | 1 - wear/src/main/res/values-ca/strings.xml | 1 - wear/src/main/res/values-cs/strings.xml | 1 - wear/src/main/res/values-de/strings.xml | 1 - wear/src/main/res/values-el/strings.xml | 1 - wear/src/main/res/values-es-rES/strings.xml | 1 - wear/src/main/res/values-es/strings.xml | 1 - wear/src/main/res/values-fr/strings.xml | 1 - wear/src/main/res/values-it/strings.xml | 1 - wear/src/main/res/values-nl/strings.xml | 1 - wear/src/main/res/values-pl/strings.xml | 1 - wear/src/main/res/values-pt-rBR/strings.xml | 1 - wear/src/main/res/values-pt/strings.xml | 1 - wear/src/main/res/values-ru/strings.xml | 1 - wear/src/main/res/values/strings.xml | 1 - 21 files changed, 10 insertions(+), 44 deletions(-) diff --git a/docs/wear.md b/docs/wear.md index 02ed5770fc..a261b07605 100644 --- a/docs/wear.md +++ b/docs/wear.md @@ -1349,8 +1349,8 @@ icon (`ic_watch`) instead, enlarged and centred in the illustration's place, in Watch: -- **Onboarding** (`OnboardingScreen`): the Bitkit mark (`WatchOnboardingLogo`), the phone icon with "Start on - phone" (`WatchOnboardingStartOnPhone`), which is text and no button, and Restore (`WatchOnboardingRestore`). +- **Onboarding** (`OnboardingScreen`): the Bitkit mark (`WatchOnboardingLogo`) and Restore + (`WatchOnboardingRestore`), nothing else: pairing starts on the phone. - **Pair** (`PairScreen`, `WatchPairScreen`): "Connecting…" (`WatchPairWaiting`) while it waits for the phone's hello, then the phone's name (`WatchPairPhone`), the code (`WatchPairCode`) and one `EdgeButton` that says "Match" (`WatchPairConfirm`), then diff --git a/journeys/wear/README.md b/journeys/wear/README.md index 06f3cc0717..40f23286f9 100644 --- a/journeys/wear/README.md +++ b/journeys/wear/README.md @@ -243,8 +243,7 @@ adb shell pm clear to.bitkit.dev adb shell am start -n to.bitkit.dev/to.bitkit.wear.ui.MainActivity ``` -`android layout` lists `WatchOnboardingLogo`, `WatchOnboardingStartOnPhone` ("Start on phone") and -`WatchOnboardingRestore`. +`android layout` lists `WatchOnboardingLogo` and `WatchOnboardingRestore`, and nothing else. ### Restored wallet diff --git a/journeys/wear/pair-prompt.xml b/journeys/wear/pair-prompt.xml index 41be27f3a5..12874ea046 100644 --- a/journeys/wear/pair-prompt.xml +++ b/journeys/wear/pair-prompt.xml @@ -14,7 +14,7 @@ Timing: a pairing lasts at most 90 s from the prompt's Pair tap; read each screen once and move on. - Verify the watch lists "WatchOnboardingRestore", "WatchOnboardingStartOnPhone" reading "Start on phone", and no "WatchOnboardingFromPhone" + Verify the watch lists "WatchOnboardingLogo" and "WatchOnboardingRestore", and no "WatchOnboardingFromPhone" or "WatchOnboardingStartOnPhone" Start the phone app and unlock it with the PIN: tap "N1" four times Wait up to 15 s on Home until the phone lists "PairedWatchPrompt" with "PairedWatchPromptPair" and "PairedWatchPromptLater" Verify from a screenshot that the prompt shows a large orange watch icon centred above its title, not the 3D phone illustration diff --git a/journeys/wear/pair-receive-wallet.xml b/journeys/wear/pair-receive-wallet.xml index 45cfe85a36..ec87edea18 100644 --- a/journeys/wear/pair-receive-wallet.xml +++ b/journeys/wear/pair-receive-wallet.xml @@ -13,7 +13,7 @@ Wait 3 s on the phone's Home; if it then lists "PairedWatchPrompt" (README › Phone and watch over the debug socket, The Pair prompt), tap Later (tag "PairedWatchPromptLater") - Verify the watch lists "WatchOnboardingRestore", "WatchOnboardingStartOnPhone" reading "Start on phone", and no button that starts a pairing ("WatchOnboardingFromPhone" is not listed) + Verify the watch lists "WatchOnboardingLogo" and "WatchOnboardingRestore", no "WatchOnboardingStartOnPhone", and no button that starts a pairing ("WatchOnboardingFromPhone" is not listed) On the phone, open Settings and tap Watch (tag "PairedWatchSettings") Wait up to 10 s until "PairedWatchStatus" names the watch as ready to pair (the sheet looks again every 3 s), then tap "PairedWatchPair" Wait up to 10 s until the watch lists "WatchPairScreen": the phone opened the Pair screen above onboarding diff --git a/wear/src/main/java/to/bitkit/wear/ui/screens/onboarding/OnboardingScreen.kt b/wear/src/main/java/to/bitkit/wear/ui/screens/onboarding/OnboardingScreen.kt index 458374417e..8fb8ec49a6 100644 --- a/wear/src/main/java/to/bitkit/wear/ui/screens/onboarding/OnboardingScreen.kt +++ b/wear/src/main/java/to/bitkit/wear/ui/screens/onboarding/OnboardingScreen.kt @@ -11,8 +11,6 @@ import androidx.compose.ui.Modifier import androidx.compose.ui.platform.testTag import androidx.compose.ui.res.painterResource import androidx.compose.ui.res.stringResource -import androidx.compose.ui.text.style.TextAlign -import androidx.compose.ui.text.style.TextOverflow import androidx.compose.ui.unit.dp import androidx.hilt.lifecycle.viewmodel.compose.hiltViewModel import androidx.lifecycle.ViewModel @@ -21,7 +19,6 @@ import androidx.lifecycle.viewModelScope import androidx.wear.compose.material3.EdgeButton import androidx.wear.compose.material3.EdgeButtonSize import androidx.wear.compose.material3.Icon -import androidx.wear.compose.material3.MaterialTheme import androidx.wear.compose.material3.Text import dagger.hilt.android.lifecycle.HiltViewModel import kotlinx.coroutines.flow.MutableSharedFlow @@ -36,10 +33,10 @@ import to.bitkit.wear.ui.components.WearPreviewDevices import javax.inject.Inject /** - * The Bitkit mark, a line that says to start on the phone, and Restore. Receiving the wallet from the phone needs - * no button: the Pair screen opens above this one when the phone starts a pairing. Each time it comes on screen it - * checks for a stored wallet and leaves through [onWalletFind] when there is one, as after a restore whose save - * finished while the wearer was away. + * The Bitkit mark and Restore. The other way in, receiving the wallet from the phone, needs no button: the Pair + * screen opens above this one when the phone starts a pairing. Each time it comes on screen it checks for a stored + * wallet and leaves through [onWalletFind] when there is one, as after a restore whose save finished while the wearer + * was away. */ @Composable fun OnboardingScreen( @@ -88,23 +85,9 @@ private fun Content( painter = painterResource(R.drawable.bitkit_logo), contentDescription = stringResource(R.string.app_name), modifier = Modifier - .fillMaxWidth(0.6f) + .fillMaxWidth(0.7f) .testTag("WatchOnboardingLogo") ) - Icon( - painter = painterResource(R.drawable.ic_phone), - contentDescription = null, - tint = MaterialTheme.colorScheme.onSurfaceVariant, - modifier = Modifier.size(24.dp) - ) - Text( - text = stringResource(R.string.onboarding__start_on_phone), - style = MaterialTheme.typography.bodyMedium, - textAlign = TextAlign.Center, - maxLines = 2, - overflow = TextOverflow.Ellipsis, - modifier = Modifier.testTag("WatchOnboardingStartOnPhone") - ) } } diff --git a/wear/src/main/res/values-ar/strings.xml b/wear/src/main/res/values-ar/strings.xml index 07b502ec18..a4fb2762da 100644 --- a/wear/src/main/res/values-ar/strings.xml +++ b/wear/src/main/res/values-ar/strings.xml @@ -20,7 +20,6 @@ فتح إعدادات NFC طلب دفع Bitkit استعادة - ابدأ من الهاتف متطابقة جارٍ الاتصال… تم الإقران diff --git a/wear/src/main/res/values-b+es+419/strings.xml b/wear/src/main/res/values-b+es+419/strings.xml index f276708aa1..180b9be055 100644 --- a/wear/src/main/res/values-b+es+419/strings.xml +++ b/wear/src/main/res/values-b+es+419/strings.xml @@ -20,7 +20,6 @@ Abrir ajustes de NFC Solicitud de pago de Bitkit Restaurar - Ve al teléfono Coinciden Conectando… Vinculado diff --git a/wear/src/main/res/values-ca/strings.xml b/wear/src/main/res/values-ca/strings.xml index 738d8c83bb..8ac04d4585 100644 --- a/wear/src/main/res/values-ca/strings.xml +++ b/wear/src/main/res/values-ca/strings.xml @@ -20,7 +20,6 @@ Obre la configuració de l\'NFC Sol·licitud de pagament de Bitkit Restaurar - Comença al telèfon Coincideixen Connectant… Vinculat diff --git a/wear/src/main/res/values-cs/strings.xml b/wear/src/main/res/values-cs/strings.xml index bce28c5a40..bb88c6b1be 100644 --- a/wear/src/main/res/values-cs/strings.xml +++ b/wear/src/main/res/values-cs/strings.xml @@ -20,7 +20,6 @@ Otevřít nastavení NFC Žádost o platbu Bitkit Obnovit - Začněte v telefonu Shodují se Připojování… Spárováno diff --git a/wear/src/main/res/values-de/strings.xml b/wear/src/main/res/values-de/strings.xml index 3d0afaf39c..c8f7ce29b0 100644 --- a/wear/src/main/res/values-de/strings.xml +++ b/wear/src/main/res/values-de/strings.xml @@ -20,7 +20,6 @@ NFC-Einstellungen öffnen Bitkit-Zahlungsanforderung Wiederherstellen - Am Telefon starten Stimmt Verbinden… Gekoppelt diff --git a/wear/src/main/res/values-el/strings.xml b/wear/src/main/res/values-el/strings.xml index c4cea4fa61..5b4459e062 100644 --- a/wear/src/main/res/values-el/strings.xml +++ b/wear/src/main/res/values-el/strings.xml @@ -20,7 +20,6 @@ Άνοιγμα ρυθμίσεων NFC Αίτημα πληρωμής Bitkit Επαναφορά - Ξεκίνα στο τηλέφωνο Ταιριάζουν Σύνδεση… Συζεύχθηκε diff --git a/wear/src/main/res/values-es-rES/strings.xml b/wear/src/main/res/values-es-rES/strings.xml index 73217668c6..eea8769a27 100644 --- a/wear/src/main/res/values-es-rES/strings.xml +++ b/wear/src/main/res/values-es-rES/strings.xml @@ -20,7 +20,6 @@ Abrir ajustes de NFC Solicitud de pago de Bitkit Restaurar - Ve al teléfono Coinciden Conectando… Vinculado diff --git a/wear/src/main/res/values-es/strings.xml b/wear/src/main/res/values-es/strings.xml index 73217668c6..eea8769a27 100644 --- a/wear/src/main/res/values-es/strings.xml +++ b/wear/src/main/res/values-es/strings.xml @@ -20,7 +20,6 @@ Abrir ajustes de NFC Solicitud de pago de Bitkit Restaurar - Ve al teléfono Coinciden Conectando… Vinculado diff --git a/wear/src/main/res/values-fr/strings.xml b/wear/src/main/res/values-fr/strings.xml index a309ba24a3..bd2ec61f56 100644 --- a/wear/src/main/res/values-fr/strings.xml +++ b/wear/src/main/res/values-fr/strings.xml @@ -20,7 +20,6 @@ Ouvrir les réglages NFC Demande de paiement Bitkit Restaurer - Depuis le téléphone Identiques Connexion… Associée diff --git a/wear/src/main/res/values-it/strings.xml b/wear/src/main/res/values-it/strings.xml index 27a9807479..b3b51d524a 100644 --- a/wear/src/main/res/values-it/strings.xml +++ b/wear/src/main/res/values-it/strings.xml @@ -20,7 +20,6 @@ Apri impostazioni NFC Richiesta di pagamento Bitkit Ripristina - Avvia dal telefono Uguali Connessione… Associato diff --git a/wear/src/main/res/values-nl/strings.xml b/wear/src/main/res/values-nl/strings.xml index 3cd6b0a687..f53767f7f7 100644 --- a/wear/src/main/res/values-nl/strings.xml +++ b/wear/src/main/res/values-nl/strings.xml @@ -20,7 +20,6 @@ NFC-instellingen openen Bitkit-betaalverzoek Herstellen - Start op telefoon Gelijk Verbinden… Gekoppeld diff --git a/wear/src/main/res/values-pl/strings.xml b/wear/src/main/res/values-pl/strings.xml index a1b46d6554..26e01597bb 100644 --- a/wear/src/main/res/values-pl/strings.xml +++ b/wear/src/main/res/values-pl/strings.xml @@ -20,7 +20,6 @@ Otwórz ustawienia NFC Żądanie płatności Bitkit Odzyskaj - Zacznij na telefonie Zgodne Łączenie… Sparowano diff --git a/wear/src/main/res/values-pt-rBR/strings.xml b/wear/src/main/res/values-pt-rBR/strings.xml index aa9519e61f..94e3d83d91 100644 --- a/wear/src/main/res/values-pt-rBR/strings.xml +++ b/wear/src/main/res/values-pt-rBR/strings.xml @@ -20,7 +20,6 @@ Abrir configurações de NFC Solicitação de pagamento Bitkit Restaurar - Inicie no celular Coincidem Conectando… Pareado diff --git a/wear/src/main/res/values-pt/strings.xml b/wear/src/main/res/values-pt/strings.xml index 30583dc617..1ceb62f9ef 100644 --- a/wear/src/main/res/values-pt/strings.xml +++ b/wear/src/main/res/values-pt/strings.xml @@ -20,7 +20,6 @@ Abrir definições de NFC Pedido de pagamento Bitkit Restaurar - Inicie no telemóvel Coincidem A ligar… Emparelhado diff --git a/wear/src/main/res/values-ru/strings.xml b/wear/src/main/res/values-ru/strings.xml index 75b051a8e4..eb48f6391e 100644 --- a/wear/src/main/res/values-ru/strings.xml +++ b/wear/src/main/res/values-ru/strings.xml @@ -20,7 +20,6 @@ Открыть настройки NFC Запрос на оплату Bitkit Восстановить - Начните на телефоне Совпадают Подключение… Сопряжено diff --git a/wear/src/main/res/values/strings.xml b/wear/src/main/res/values/strings.xml index b2656b1986..c71831fa70 100644 --- a/wear/src/main/res/values/strings.xml +++ b/wear/src/main/res/values/strings.xml @@ -20,7 +20,6 @@ Open NFC settings Bitkit payment request Restore - Start on phone Match Connecting… Paired From 8ff2b1c81159abb45d6b3cf528cfb9ed8b472fe3 Mon Sep 17 00:00:00 2001 From: Joao Victor Sena Date: Sun, 29 Nov 2026 20:25:29 -0300 Subject: [PATCH 30/38] fix: center the watch's activity detail when it fits Co-Authored-By: Claude Opus 5.5 --- docs/wear.md | 5 ++- journeys/wear/activity-list.xml | 3 +- .../bitkit/wear/ui/components/ListScreen.kt | 42 +++++++++++++++---- .../screens/activity/ActivityDetailScreen.kt | 6 +-- .../activity/ActivityDetailContentTest.kt | 36 ++++++++++++++-- 5 files changed, 75 insertions(+), 17 deletions(-) diff --git a/docs/wear.md b/docs/wear.md index a261b07605..39e1895689 100644 --- a/docs/wear.md +++ b/docs/wear.md @@ -313,8 +313,9 @@ On-screen copy stays short: a title or one line of at most about six words per s is read again every minute, so a payment of today reads as a day once midnight passed, and a list just read counts from its own time. A tap opens the detail: the amount, the fee of a send, the day and time as the phone's detail writes them ("March 3, 6:40 PM", no year) and the status (`WatchActivityDetailAmount`, `…Fee`, `…Time`, `…Status`), - and the payment's note in up to two lines (`WatchActivityDetailMessage`) when it has one, in a list that scrolls, - also with the rotary input, so the status stays reachable on the smallest round screen; the day and time also take + and the payment's note in up to two lines (`WatchActivityDetailMessage`) when it has one, in the middle of the + screen while the lines fit, else in a list that scrolls, also with the rotary input, so the status stays reachable + on the smallest round screen (`ListScreen`'s `isCentered`); the day and time also take up to two lines, ending in an ellipsis. The note is as the phone's detail shows it: an LNURL comment of the payer, or else the invoice's description, from Spark's payment details (`PaymentsRepo`, `Payment.message`); a blank one shows nothing, and ambient mode hides it. Spark's list carries no payee. With no payments it shows a dimmed icon and diff --git a/journeys/wear/activity-list.xml b/journeys/wear/activity-list.xml index bae3a67ffe..d8d038bf0b 100644 --- a/journeys/wear/activity-list.xml +++ b/journeys/wear/activity-list.xml @@ -3,7 +3,7 @@ The Activity page, after Receive, lists the newest payments with the phone's activity icon (a purple arrow on a purple circle), the amount and the time as the phone's activity writes it (the time alone today); a tap opens the detail with the amount, the fee of a send, the payment's note when it has one, the day and time and the status, - in a list that scrolls. + in the middle of the screen while it fits, else in a list that scrolls. Emulator and physical watch. Precondition: Restored wallet on the local ./spark stack after receive-paid.xml and send-deeplink-bolt11.xml, so @@ -27,6 +27,7 @@ Verify "WatchActivityItem-0" is listed again Tap "WatchActivityItem-1" Verify "WatchActivityDetailStatus" reads "Completed" and "WatchActivityDetailMessage" is not listed: the receive's invoice has no description + Verify the detail sits in the middle of the screen: the middle of the top of "WatchActivityDetailAmount" and the bottom of "WatchActivityDetailStatus" is within 20 px of y 227 Swipe to dismiss from the left edge: `adb shell input swipe 20 227 400 227 300` diff --git a/wear/src/main/java/to/bitkit/wear/ui/components/ListScreen.kt b/wear/src/main/java/to/bitkit/wear/ui/components/ListScreen.kt index 409fc05c5f..d5ae8f88ef 100644 --- a/wear/src/main/java/to/bitkit/wear/ui/components/ListScreen.kt +++ b/wear/src/main/java/to/bitkit/wear/ui/components/ListScreen.kt @@ -5,13 +5,18 @@ import androidx.compose.foundation.layout.PaddingValues import androidx.compose.foundation.layout.calculateEndPadding import androidx.compose.foundation.layout.calculateStartPadding import androidx.compose.runtime.Composable +import androidx.compose.runtime.derivedStateOf +import androidx.compose.runtime.getValue +import androidx.compose.runtime.remember import androidx.compose.runtime.staticCompositionLocalOf import androidx.compose.ui.Modifier import androidx.compose.ui.focus.FocusRequester +import androidx.compose.ui.platform.LocalDensity import androidx.compose.ui.platform.LocalLayoutDirection import androidx.compose.ui.unit.Dp import androidx.compose.ui.unit.dp import androidx.wear.compose.foundation.lazy.TransformingLazyColumn +import androidx.wear.compose.foundation.lazy.TransformingLazyColumnLayoutInfo import androidx.wear.compose.foundation.lazy.TransformingLazyColumnScope import androidx.wear.compose.foundation.lazy.TransformingLazyColumnState import androidx.wear.compose.foundation.lazy.rememberTransformingLazyColumnState @@ -35,12 +40,14 @@ val LocalListBottomInset = staticCompositionLocalOf { 0.dp } /** * A screen whose items scroll in a [TransformingLazyColumn], morphing at the round screen's edges, with an optional * [edgeButton] that collapses as the list scrolls. The rotary input scrolls the list. A screen that also holds a text - * field passes [rotaryFocusRequester] and requests focus through it to hand the rotary back to the list. + * field passes [rotaryFocusRequester] and requests focus through it to hand the rotary back to the list. With + * [isCentered] the items sit in the middle of the screen while they all fit, and scroll only when they do not. */ @Composable fun ListScreen( modifier: Modifier = Modifier, rotaryFocusRequester: FocusRequester? = null, + isCentered: Boolean = false, edgeButton: (@Composable BoxScope.() -> Unit)? = null, items: TransformingLazyColumnScope.(TransformationSpec) -> Unit, ) { @@ -48,12 +55,14 @@ fun ListScreen( val transformationSpec = rememberTransformationSpec() if (edgeButton != null) { ScreenScaffold(scrollState = listState, edgeButton = edgeButton, modifier = modifier) { contentPadding -> - List(listState, contentPadding, rotaryFocusRequester) { items(transformationSpec) } + val padding = if (isCentered) contentPadding.centeredIn(listState) else contentPadding + List(listState, padding, rotaryFocusRequester) { items(transformationSpec) } } } else { - val padding = ScreenScaffoldDefaults.contentPadding.plusBottom(LocalListBottomInset.current) + val padding = ScreenScaffoldDefaults.contentPadding.plus(bottom = LocalListBottomInset.current) ScreenScaffold(scrollState = listState, contentPadding = padding, modifier = modifier) { contentPadding -> - List(listState, contentPadding, rotaryFocusRequester) { items(transformationSpec) } + val listPadding = if (isCentered) contentPadding.centeredIn(listState) else contentPadding + List(listState, listPadding, rotaryFocusRequester) { items(transformationSpec) } } } } @@ -82,13 +91,30 @@ private fun List( } @Composable -private fun PaddingValues.plusBottom(extra: Dp): PaddingValues { - if (extra == 0.dp) return this +private fun PaddingValues.centeredIn(state: TransformingLazyColumnState): PaddingValues { + val density = LocalDensity.current + val paddingPx = with(density) { (calculateTopPadding() + calculateBottomPadding()).roundToPx() } + val freePx by remember(state, paddingPx) { derivedStateOf { state.layoutInfo.freeHeight(paddingPx) } } + return plus(top = with(density) { (freePx / 2).toDp() }) +} + +private fun TransformingLazyColumnLayoutInfo.freeHeight(paddingPx: Int): Int { + if (visibleItems.isEmpty() || visibleItems.size < totalItemsCount) return 0 + val first = visibleItems.first() + val last = visibleItems.last() + val gaps = last.offset - first.offset - visibleItems.dropLast(1).sumOf { it.transformedHeight } + val contentHeight = visibleItems.sumOf { it.measuredHeight } + gaps + return (viewportSize.height - paddingPx - contentHeight).coerceAtLeast(0) +} + +@Composable +private fun PaddingValues.plus(top: Dp = 0.dp, bottom: Dp = 0.dp): PaddingValues { + if (top == 0.dp && bottom == 0.dp) return this val layoutDirection = LocalLayoutDirection.current return PaddingValues( start = calculateStartPadding(layoutDirection), - top = calculateTopPadding(), + top = calculateTopPadding() + top, end = calculateEndPadding(layoutDirection), - bottom = calculateBottomPadding() + extra, + bottom = calculateBottomPadding() + bottom, ) } diff --git a/wear/src/main/java/to/bitkit/wear/ui/screens/activity/ActivityDetailScreen.kt b/wear/src/main/java/to/bitkit/wear/ui/screens/activity/ActivityDetailScreen.kt index 233f2b6000..020e73b022 100644 --- a/wear/src/main/java/to/bitkit/wear/ui/screens/activity/ActivityDetailScreen.kt +++ b/wear/src/main/java/to/bitkit/wear/ui/screens/activity/ActivityDetailScreen.kt @@ -78,8 +78,8 @@ private fun Missing( } /** - * A list that scrolls, also with the rotary input, so that a payment with a fee and a note still reaches its status on - * the smallest round screen. + * The payment's lines in the middle of the screen while they fit, and a list that scrolls, also with the rotary input, + * when they do not, so that a payment with a fee and a note still reaches its status on the smallest round screen. */ @Composable internal fun ActivityDetailContent( @@ -93,7 +93,7 @@ internal fun ActivityDetailContent( val time = remember(payment.timestampSecs, is24Hour) { uiDateText(payment.timestampSecs, UiDateStyle.DATE_TIME, is24Hour) } - ListScreen(modifier = modifier) { spec -> + ListScreen(isCentered = true, modifier = modifier) { spec -> if (!isAmbient) { item { BoxWithConstraints( diff --git a/wear/src/test/java/to/bitkit/wear/ui/screens/activity/ActivityDetailContentTest.kt b/wear/src/test/java/to/bitkit/wear/ui/screens/activity/ActivityDetailContentTest.kt index 30d701bc8c..6457732367 100644 --- a/wear/src/test/java/to/bitkit/wear/ui/screens/activity/ActivityDetailContentTest.kt +++ b/wear/src/test/java/to/bitkit/wear/ui/screens/activity/ActivityDetailContentTest.kt @@ -6,25 +6,36 @@ import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.setValue import androidx.compose.ui.test.assertIsDisplayed import androidx.compose.ui.test.assertTextEquals +import androidx.compose.ui.test.getUnclippedBoundsInRoot import androidx.compose.ui.test.junit4.createAndroidComposeRule import androidx.compose.ui.test.onNodeWithTag import androidx.compose.ui.test.onRoot import androidx.compose.ui.test.performTouchInput import androidx.compose.ui.test.swipeUp +import androidx.compose.ui.unit.dp import org.junit.Rule import org.junit.Test import org.junit.runner.RunWith import org.robolectric.RobolectricTestRunner import org.robolectric.annotation.Config import to.bitkit.wear.models.BitcoinDisplayUnit +import to.bitkit.wear.models.WatchPayment import to.bitkit.wear.ui.components.WearPreview +import kotlin.test.assertTrue -/** A payment's detail: its note, hidden in ambient mode, and a status that every round screen reaches. */ +/** + * A payment's detail: in the middle of the screen when it fits, its note hidden in ambient mode, and a status that + * every round screen reaches. + */ @Config(sdk = [34], qualifiers = "w227dp-h227dp-round") @RunWith(RobolectricTestRunner::class) class ActivityDetailContentTest { private companion object { val NOTED = PreviewPayment.copy(feeSats = 250uL, message = "Coffee and two croissants at the corner bakery") + val SHORT = PreviewPayment.copy(isSent = false, feeSats = 0uL) + + /** How far the middle of a centered detail may sit from the middle of the screen. */ + val CENTER_TOLERANCE = 6.dp } @get:Rule @@ -40,6 +51,13 @@ class ActivityDetailContentTest { fun `a sent payment with a fee and a note scrolls to its status on the smallest round screen`() = assertStatusReached() + @Test + fun `a payment that fits sits in the middle of the screen`() = assertCentered() + + @Test + @Config(sdk = [34], qualifiers = "w192dp-h192dp-round") + fun `a payment that fits sits in the middle of the smallest round screen`() = assertCentered() + @Test fun `the note shows awake and hides in ambient mode, with the amount`() { setContent() @@ -61,10 +79,22 @@ class ActivityDetailContentTest { composeRule.onNodeWithTag("WatchActivityDetailTime").assertIsDisplayed() } - private fun setContent() { + private fun assertCentered() { + setContent(SHORT) + composeRule.waitForIdle() + + val screen = composeRule.onRoot().getUnclippedBoundsInRoot() + val top = composeRule.onNodeWithTag("WatchActivityDetailAmount", useUnmergedTree = true) + .getUnclippedBoundsInRoot().top + val bottom = composeRule.onNodeWithTag("WatchActivityDetailStatus").getUnclippedBoundsInRoot().bottom + val offset = (top + bottom) / 2 - (screen.top + screen.bottom) / 2 + assertTrue(offset < CENTER_TOLERANCE && -offset < CENTER_TOLERANCE, "content middle is $offset off center") + } + + private fun setContent(payment: WatchPayment = NOTED) { composeRule.setContent { WearPreview { - ActivityDetailContent(payment = NOTED, unit = BitcoinDisplayUnit.MODERN, isAmbient = isAmbient) + ActivityDetailContent(payment = payment, unit = BitcoinDisplayUnit.MODERN, isAmbient = isAmbient) } } } From f0e295d9bf22e595f2c9a8218b3028b1c3132f5f Mon Sep 17 00:00:00 2001 From: Joao Victor Sena Date: Sun, 29 Nov 2026 20:27:03 -0300 Subject: [PATCH 31/38] feat: show the watch icon on the paired watch sheet Co-Authored-By: Claude Opus 5.5 --- .../java/to/bitkit/ui/sheets/watch/WatchSheet.kt | 2 +- docs/wear.md | 12 +++++++----- journeys/wear/pair-unpair-from-phone.xml | 1 + 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/to/bitkit/ui/sheets/watch/WatchSheet.kt b/app/src/main/java/to/bitkit/ui/sheets/watch/WatchSheet.kt index b4540b035f..ee363f03ae 100644 --- a/app/src/main/java/to/bitkit/ui/sheets/watch/WatchSheet.kt +++ b/app/src/main/java/to/bitkit/ui/sheets/watch/WatchSheet.kt @@ -268,7 +268,7 @@ private fun ColumnScope.Paired( ) return } - Illustration(if (watch.keyLevel == null) R.drawable.shield else R.drawable.shield_check) + SheetIntroIcon(icon = R.drawable.ic_watch) SecondaryButton( text = stringResource(R.string.settings__watch__unpair), onClick = onUnpairClick, diff --git a/docs/wear.md b/docs/wear.md index 39e1895689..e19f1f0b6f 100644 --- a/docs/wear.md +++ b/docs/wear.md @@ -1335,8 +1335,9 @@ with the watch it offered, as if Pair Watch had been tapped: verdict (`PairedWatchKeyLevel`), the settings state (`PairedWatchSettingsState`) and one button, Unpair (`PairedWatchUnpair`), which unpairs the watch and erases its wallet, behind a dialog that says so (`DialogConfirm`, `DialogCancel`); or a pending removal (`PairedWatchRemovePending`, `PairedWatchStopWaiting`). - A watch whose secure hardware was not verified shows a plain shield instead of the checked one. A dialog stays - open while the watch's reports rewrite its record, and closes when that watch is gone. + It shows the watch icon, as the unpaired sheet does; the key's verdict line says whether the watch's secure + hardware was verified. A dialog stays open while the watch's reports rewrite its record, and closes when that + watch is gone. Closing the sheet cancels a pairing under way, at any step, except while the wallet is on its way to the watch: that transfer is left to finish, so the two devices agree on how it ended, and the sheet shows it again when @@ -1344,9 +1345,10 @@ reopened: still sending, the line that says why it failed, or the paired watch. The phone's tags start with `PairedWatch` because the watch app's own start with `Watch`. -Where the sheet, the Pair prompt and the install prompt would show the 3D phone illustration, they show the watch -icon (`ic_watch`) instead, enlarged and centred in the illustration's place, in Brand orange, all three through -`SheetIntroIcon`: no 3D watch illustration exists. The other steps keep their illustrations (shield, keyring, transfer, check, cross). +Where the sheet, the Pair prompt and the install prompt would show the 3D phone illustration, and on the paired +watch's sheet, they show the watch icon (`ic_watch`) instead, enlarged and centred in the illustration's place, in +Brand orange, all through `SheetIntroIcon`: no 3D watch illustration exists. The other steps keep their +illustrations (hourglass, keyring, transfer, check, cross). Watch: diff --git a/journeys/wear/pair-unpair-from-phone.xml b/journeys/wear/pair-unpair-from-phone.xml index 11b0463ff8..be1b328fb8 100644 --- a/journeys/wear/pair-unpair-from-phone.xml +++ b/journeys/wear/pair-unpair-from-phone.xml @@ -13,6 +13,7 @@ Run `adb -s $WATCH shell run-as to.bitkit.dev ls no_backup/seed` and verify it lists one file On the phone, open Settings and tap Watch (tag "PairedWatchSettings") Verify "PairedWatchUnpair" is listed and neither "PairedWatchErase" nor "PairedWatchClose" is + Verify from a screenshot that the sheet shows a large orange watch icon above Unpair, not a shield, with the secure hardware line "PairedWatchKeyLevel" still listed Tap Unpair (tag "PairedWatchUnpair") Tap Cancel in the dialog (tag "DialogCancel") and verify "PairedWatchName" is still listed and the watch still lists "WatchHomeBalance" Tap Unpair (tag "PairedWatchUnpair") again, verify the dialog says the watch will delete its wallet and that a watch that never reconnects keeps it, then tap Unpair in the dialog (tag "DialogConfirm") From 857fc621ea938a464b7cfdb6ce67d945a48d64b9 Mon Sep 17 00:00:00 2001 From: Joao Victor Sena Date: Sun, 29 Nov 2026 20:29:57 -0300 Subject: [PATCH 32/38] chore: log the watch's success celebration as it starts Co-Authored-By: Claude Opus 5.5 --- docs/wear.md | 3 ++- .../main/java/to/bitkit/wear/ui/components/Confetti.kt | 9 ++++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/docs/wear.md b/docs/wear.md index e19f1f0b6f..22ba0b4472 100644 --- a/docs/wear.md +++ b/docs/wear.md @@ -216,7 +216,8 @@ On-screen copy stays short: a title or one line of at most about six words per s while it stays shown awake, so neither waking the watch on a Paid or Sent screen nor an outcome cut short and shown again plays it again. Its haptic plays once too, on the frame it is first shown, in ambient mode as well. Both decisions survive the screen being made again, so neither plays again then. With animations turned off both end - at once. `CelebrationTest` checks the decision; `SendResultTest`, `ReceiveQrContentTest` and + at once. A celebration logs one debug line as it starts (`Showed the success celebration for ''`), which the + journeys read, since a screen dump waits for the confetti to end. `CelebrationTest` checks the decision; `SendResultTest`, `ReceiveQrContentTest` and `SendOutcomeOverlayTest` check where the confetti falls, that it is gone within 2 s, and that neither a wake, a new screen nor (for the overlay) an outcome cut short plays the confetti or the haptic again; how it looks on a device is not checked. diff --git a/wear/src/main/java/to/bitkit/wear/ui/components/Confetti.kt b/wear/src/main/java/to/bitkit/wear/ui/components/Confetti.kt index 9114b45ee2..0e137949c0 100644 --- a/wear/src/main/java/to/bitkit/wear/ui/components/Confetti.kt +++ b/wear/src/main/java/to/bitkit/wear/ui/components/Confetti.kt @@ -27,12 +27,15 @@ import androidx.compose.ui.graphics.drawscope.scale import androidx.compose.ui.graphics.graphicsLayer import androidx.compose.ui.platform.testTag import to.bitkit.wear.ui.theme.Colors +import to.bitkit.wear.utils.Logger import kotlin.math.PI import kotlin.math.abs import kotlin.math.cos import kotlin.math.sin import kotlin.random.Random +private const val TAG = "Confetti" + /** How many pieces fall: the phone's rain, thinned for a small screen and one short burst. */ private const val PIECES = 28 @@ -101,6 +104,7 @@ data class Celebration(val isFirstShown: Boolean, val isCelebrated: Boolean) * an outcome cut short, it is over, so neither waking the watch nor the same success shown again plays it or its * haptic again. The decision outlives the screen being made again, so a success is first shown and celebrated at most * once. A null [key] is no success; a caller whose success does not show in ambient mode passes null meanwhile. + * A celebration logs one debug line as it starts, which journeys read since a screen dump misses the moving confetti. */ @Composable fun rememberCelebration(key: String?, isAmbient: Boolean): Celebration { @@ -110,7 +114,10 @@ fun rememberCelebration(key: String?, isAmbient: Boolean): Celebration { SideEffect { if (isNew) { shownKey = key - if (!isAmbient) celebratedKey = key + if (!isAmbient) { + celebratedKey = key + Logger.debug("Showed the success celebration for '$key'", context = TAG) + } } if (isAmbient || key == null) celebratedKey = null } From 4b0f6243edc7dda1d71d5ac8e2de7e8611a04663 Mon Sep 17 00:00:00 2001 From: Joao Victor Sena Date: Sun, 29 Nov 2026 20:29:57 -0300 Subject: [PATCH 33/38] test: check the watch confetti from the log in journeys Co-Authored-By: Claude Opus 5.5 --- journeys/wear/README.md | 24 ++++++++++++------------ journeys/wear/receive-paid-ambient.xml | 7 +++++-- journeys/wear/receive-paid.xml | 7 ++++--- journeys/wear/send-deeplink-bolt11.xml | 7 +++++-- 4 files changed, 26 insertions(+), 19 deletions(-) diff --git a/journeys/wear/README.md b/journeys/wear/README.md index 40f23286f9..c7c969410f 100644 --- a/journeys/wear/README.md +++ b/journeys/wear/README.md @@ -24,18 +24,18 @@ What `android layout` misses on the watch, verified on the API 37 emulator: - **Screens with `FLAG_SECURE`.** The word, passphrase and Pair screens block screenshots and screen recordings in release builds only, as on the phone; debug builds capture them. Never capture the word or passphrase screens with a recovery phrase on them. - -Not yet confirmed on an emulator: - -- **The confetti.** `WatchConfetti`, the canvas the confetti of a success falls on, has no text or action, so - `android layout` leaves it out; `adb shell uiautomator dump` should list it while it falls, for under 2 s. That is - too short for a wait in one step and a dump in the next, so a journey waits for the success and looks for the - confetti in the same dump, in one `adb shell` loop that runs on the watch. Each `uiautomator dump` waits about 1 s - for the screen to settle before its snapshot, so a pass of the loop takes about 2 s. The Sent screen closes 2 s after - it shows, so the send journey reads its amount from that dump and takes its screenshot with `screencap` in the same - command. That waking plays no confetti is checked only best-effort, by dumping a few times after the wake: the - first snapshot can land after the 2 s. A screenshot rarely catches the pieces in time: check the confetti with the - dump and the colours from a screenshot. +- **The confetti.** `WatchConfetti`, the canvas the confetti of a success falls on for 2 s, has no text or action, + and no screen dump catches it: `uiautomator dump`, and `android layout` with it, waits for the screen to go idle, + and the falling confetti keeps it busy, so the dump lands once the confetti has ended, and on the Sent screen, + which closes 2 s after it shows, often once the screen has closed too (seen on the API 37 emulator). Check the log + instead: the watch logs one debug line as a celebration starts, `[Confetti] Showed the success celebration for + ''`, the key being the paid payment's id on Receive, `sent` on a send's flow and the outcome's id on a send result shown + outside it. A journey clears the log with + `adb logcat -c` before the payment, then checks `adb logcat -d -s BitkitWear | grep "Showed the success + celebration"`: one line where the confetti plays, none in ambient mode or after a wake. A send's Sent screen is + checked from the log too, by "Finished send with outcome 'Sent'". The one screenshot of the confetti, for the + colours, comes from one `adb shell` loop that runs on the watch, polls the log for that line and runs `screencap` + the moment it appears. A dump taken after the 2 s shows that the confetti is gone. ## Emulators diff --git a/journeys/wear/receive-paid-ambient.xml b/journeys/wear/receive-paid-ambient.xml index 156e78593a..4478794aa0 100644 --- a/journeys/wear/receive-paid-ambient.xml +++ b/journeys/wear/receive-paid-ambient.xml @@ -14,9 +14,12 @@ Read the invoice from the log as in README › Reading the receive invoice and note it as <invoice> Run `adb shell input keyevent KEYCODE_SLEEP` Wait up to 5 s until "WatchReceiveHidden" is listed + Run `adb logcat -c` Run `../bitkit-docker/spark pay <invoice> 1000` from this repo's parent checkout - Run `adb shell 'for i in $(seq 20); do rm -f /sdcard/x.xml; uiautomator dump /sdcard/x.xml >/dev/null 2>&1; d=$(cat /sdcard/x.xml 2>/dev/null); case "$d" in *WatchReceivePaid*) break;; esac; done; echo "$d" | grep -oE "WatchReceivePaidAmount|WatchReceivePaid|WatchReceiveNew|WatchConfetti" | sort -u'`, which dumps up to 20 times (about 2 s a dump) until the check shows and looks in that same dump for the amount, the button and the confetti, and verify it prints "WatchReceivePaid" alone: the always-on screen shows no amount and no confetti - Run `adb shell 'input keyevent KEYCODE_WAKEUP; for i in 1 2 3; do rm -f /sdcard/x.xml; uiautomator dump /sdcard/x.xml >/dev/null 2>&1; echo "$i: $(grep -oE "WatchReceivePaidAmount|WatchConfetti" /sdcard/x.xml | sort -u | tr "\n" " ")"; done'`, which wakes the watch and dumps three times, and verify that no line prints "WatchConfetti", and that a line prints "WatchReceivePaidAmount": waking plays no celebration. This check is best-effort: each dump waits for the screen to settle, so the first one can land up to about 2.5 s after the wake, past the 2 s a confetti would fall, and the others only confirm none started later. `CelebrationTest` and `ReceiveQrContentTest` are the real guard + Run `adb shell 'for i in $(seq 20); do rm -f /sdcard/x.xml; uiautomator dump /sdcard/x.xml >/dev/null 2>&1; d=$(cat /sdcard/x.xml 2>/dev/null); case "$d" in *WatchReceivePaid*) break;; esac; done; echo "$d" | grep -oE "WatchReceivePaidAmount|WatchReceivePaid|WatchReceiveNew" | sort -u'`, which dumps up to 20 times (about 2 s a dump) until the check shows and looks in that same dump for the amount and the button, and verify it prints "WatchReceivePaid" alone: the always-on screen shows no amount + Run `adb logcat -d -s BitkitWear | grep "Showed the success celebration"` and verify it prints nothing: the always-on screen played no confetti (README › The confetti) + Run `adb shell input keyevent KEYCODE_WAKEUP`, wait 3 s, then verify "WatchReceivePaidAmount" is listed + Run `adb logcat -d -s BitkitWear | grep "Showed the success celebration"` again and verify it still prints nothing: waking plays no celebration Verify "WatchReceivePaidAmount" reads "1 000" Verify "WatchReceiveNew" is listed diff --git a/journeys/wear/receive-paid.xml b/journeys/wear/receive-paid.xml index 2af55b2c14..7f8738e160 100644 --- a/journeys/wear/receive-paid.xml +++ b/journeys/wear/receive-paid.xml @@ -16,10 +16,11 @@ Tap "WatchReceiveOpen" Wait up to 10 s until `adb shell uiautomator dump` lists "WatchReceiveQr" (README, top) Read the invoice from the log as in README › Reading the receive invoice and note it as <invoice> + Run `adb logcat -c` Run `../bitkit-docker/spark pay <invoice> 50000` from this repo's parent checkout - Run `adb shell 'for i in $(seq 30); do rm -f /sdcard/x.xml; uiautomator dump /sdcard/x.xml >/dev/null 2>&1; d=$(cat /sdcard/x.xml 2>/dev/null); case "$d" in *WatchReceivePaid*) break;; esac; done; echo "$d" | grep -oE "WatchReceivePaid|WatchConfetti" | sort -u'`, which dumps up to 30 times (about 2 s a dump) until the check shows and looks in that same dump for the confetti (README › The confetti), and verify it prints both "WatchConfetti" and "WatchReceivePaid" - Verify "WatchReceivePaidAmount" reads "50 000" - Run `adb shell 'sleep 3; rm -f /sdcard/x.xml; uiautomator dump /sdcard/x.xml >/dev/null 2>&1; grep -oE "WatchReceivePaid|WatchConfetti" /sdcard/x.xml | sort -u'` and verify it prints "WatchReceivePaid" and not "WatchConfetti": the confetti is gone + Run `for i in $(seq 30); do adb logcat -d -s BitkitWear | grep "Showed the success celebration" && break; sleep 1; done` and verify it prints one line, "Showed the success celebration for '<payment id>'": the confetti started (README › The confetti) + Wait 3 s for the confetti to end, then verify "WatchReceivePaid" is listed and "WatchReceivePaidAmount" reads "50 000" + Run `adb shell 'rm -f /sdcard/x.xml; uiautomator dump /sdcard/x.xml >/dev/null 2>&1; grep -oE "WatchReceivePaid|WatchConfetti" /sdcard/x.xml | sort -u'` and verify it prints "WatchReceivePaid" and not "WatchConfetti": the confetti is gone Verify from a screenshot that the check is purple Verify the button below the check reads "New invoice" (tag "WatchReceiveNew") Tap the check (tag "WatchReceivePaid") and verify "WatchReceivePaid" is still listed 2 s later: the check is no button diff --git a/journeys/wear/send-deeplink-bolt11.xml b/journeys/wear/send-deeplink-bolt11.xml index c6e6811523..2952204f94 100644 --- a/journeys/wear/send-deeplink-bolt11.xml +++ b/journeys/wear/send-deeplink-bolt11.xml @@ -16,11 +16,14 @@ Verify from a screenshot that the Hold to pay button is purple, not orange Verify "WatchSendAmount" reads "1 000" Verify "WatchSendAmountSymbol" reads "₿" + Run `adb logcat -c` Hold "WatchSendHold" for 2 s as in README › Holding to pay - Run `adb shell 'for i in $(seq 20); do rm -f /sdcard/x.xml; uiautomator dump /sdcard/x.xml >/dev/null 2>&1; d=$(cat /sdcard/x.xml 2>/dev/null); case "$d" in *WatchSendSent*) break;; esac; done; screencap -p /sdcard/sent.png; echo "$d" | grep -oE "WatchSendSent|WatchConfetti|text=.[^>]*resource-id=.WatchSendResultAmount" | sort -u'`, which dumps up to 20 times (about 2 s a dump) until the check shows, looks in that same dump for the confetti (README › The confetti) and the amount, and takes a screenshot right after it, since the Sent screen closes 2 s after it shows. Verify it prints "WatchConfetti", "WatchSendSent" and `text="1 000" resource-id="WatchSendResultAmount"` - Run `adb pull /sdcard/sent.png && adb shell rm /sdcard/sent.png` and verify from sent.png, the screenshot the step above took, that the check is purple + Run `adb shell 'for i in $(seq 100); do logcat -d -s BitkitWear | grep -q "Showed the success celebration" && break; sleep 0.1; done; screencap -p /sdcard/sent.png'`, which waits on the watch for the celebration's log line and takes a screenshot as soon as it appears, since the Sent screen closes 2 s after it shows (README › The confetti) + Run `adb logcat -d -s BitkitWear | grep -oE "Finished send with outcome '[^']*'|Showed the success celebration for '[^']*'"` and verify it prints "Finished send with outcome 'Sent'" and "Showed the success celebration for 'sent'": the send went out and the confetti started + Run `adb pull /sdcard/sent.png && adb shell rm /sdcard/sent.png` and verify from sent.png, the screenshot the step above took, that it shows the purple check, "Sent" and "1 000" Wait 4 s Verify the Balance page: "WatchHomeBalance" is listed Verify "WatchSendSent" is not listed + Run `adb logcat -d -s BitkitWear | grep -c "Showed the success celebration"` and verify it prints "1": the send celebrated once From 1587f804a6345cd77f5a22fd34bbcae864de7d98 Mon Sep 17 00:00:00 2001 From: Joao Victor Sena Date: Sun, 29 Nov 2026 20:29:58 -0300 Subject: [PATCH 34/38] test: find the watch's activity rows by what they show Co-Authored-By: Claude Opus 5.5 --- journeys/wear/activity-list.xml | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/journeys/wear/activity-list.xml b/journeys/wear/activity-list.xml index d8d038bf0b..b28809e52f 100644 --- a/journeys/wear/activity-list.xml +++ b/journeys/wear/activity-list.xml @@ -14,18 +14,19 @@ Swipe the pager left to Receive: `adb shell input swipe 400 227 60 227 300` Swipe the pager left to Activity: `adb shell input swipe 400 227 60 227 300` Wait up to 10 s until "WatchActivityItem-0" is listed - Verify "WatchActivityItem-0" shows "- ₿ 1 000" - Verify "WatchActivityItem-0" shows the payment's time alone, such as "3:04 PM" (or "15:04" with the watch set to 24 hours), and no "ago" + Verify "WatchActivityItem-0", the newest row, shows "- ₿ 1 000", and note it as <send> + Verify <send> shows the payment's time alone, such as "3:04 PM" (or "15:04" with the watch set to 24 hours), and no "ago" + Find the row that shows "+ ₿ 50 000", scrolling down with `adb shell input swipe 227 380 227 120 300` until it is listed, and note its "WatchActivityItem-N" tag as <receive>: rows are found by what they show, since an earlier rerun of a send journey adds rows above it Verify from a screenshot that each row's icon is a purple arrow on a purple circle, up for the send and down for the receive - Verify "WatchActivityItem-1" shows "+ ₿ 50 000" - Tap "WatchActivityItem-0" + Scroll back up with `adb shell input swipe 227 120 227 380 300` until <send> is listed + Tap <send> Verify "WatchActivityDetailAmount" reads "1 000" Verify "WatchActivityDetailStatus" reads "Completed" Verify "WatchActivityDetailTime" shows today's day and the time, such as "November 29, 3:04 PM" Verify "WatchActivityDetailMessage" reads "Coffee", the description of the invoice send-deeplink-bolt11.xml paid Swipe to dismiss from the left edge: `adb shell input swipe 20 227 400 227 300` - Verify "WatchActivityItem-0" is listed again - Tap "WatchActivityItem-1" + Verify <send> is listed again + Find <receive> as above and tap it Verify "WatchActivityDetailStatus" reads "Completed" and "WatchActivityDetailMessage" is not listed: the receive's invoice has no description Verify the detail sits in the middle of the screen: the middle of the top of "WatchActivityDetailAmount" and the bottom of "WatchActivityDetailStatus" is within 20 px of y 227 Swipe to dismiss from the left edge: `adb shell input swipe 20 227 400 227 300` From ce8ec5342f5a0910941e67be0770d78384c98f65 Mon Sep 17 00:00:00 2001 From: Joao Victor Sena Date: Sun, 29 Nov 2026 20:29:58 -0300 Subject: [PATCH 35/38] test: read sent from the log and confirm the dialog in quickpay Co-Authored-By: Claude Opus 5.5 --- journeys/wear/quickpay-shared-daily-limit.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/journeys/wear/quickpay-shared-daily-limit.xml b/journeys/wear/quickpay-shared-daily-limit.xml index 1e1c0fd12d..51c4e171ad 100644 --- a/journeys/wear/quickpay-shared-daily-limit.xml +++ b/journeys/wear/quickpay-shared-daily-limit.xml @@ -24,11 +24,11 @@ Wait up to 10 s until `adb -s $WATCH logcat -d -s BitkitWear` lists "Applied the settings the phone pushed" Run `../bitkit-docker/spark invoice N` and note the BOLT11 invoice it prints as <first> Run `adb -s $WATCH shell am start -a android.intent.action.VIEW -d "lightning:<first>" to.bitkit.dev` - Wait up to 20 s until "WatchSendSent" is listed on the watch, touching nothing, and verify `adb -s $WATCH logcat -d -s BitkitWear` lists "Skipped the hold to pay under QuickPay": the watch paid by QuickPay + Wait up to 20 s, touching nothing, until `adb -s $WATCH logcat -d -s BitkitWear` lists "Finished send with outcome 'Sent'", and verify it also lists "Skipped the hold to pay under QuickPay": the watch paid by QuickPay. Read the log, not a dump: the Sent screen's confetti keeps a dump waiting past the 2 s it shows (README › The confetti) Wait 5 s for the watch's count to reach the phone Run `../bitkit-docker/spark invoice N` and note the BOLT11 invoice it prints as <second> Run `adb -s $PHONE shell am start -a android.intent.action.VIEW -d "lightning:<second>" to.bitkit.dev` Wait up to 15 s until the phone shows the review with the swipe (tags "SendConfirm" and "GRAB"), and verify `adb -s $PHONE logcat -d -s APP` lists "Skipping QuickPay: daily spend '<about 300>' + '<about 300>' exceeds cap '500'": the day's limit counts the watch's payment, not an unreadable count (which shows as 10^18) - Swipe "GRAB" to pay, complete authorization if requested, and verify it ends on the sent sheet + Swipe "GRAB" to pay; if the "Are You Sure?" dialog then warns about sending over 50% of the balance, tap "Yes, Send" (tag "DialogConfirm"). Complete authorization if requested, and verify it ends on the sent sheet From a71b5bae8753f4a49bc1d8b07e6b39c05ff31fb6 Mon Sep 17 00:00:00 2001 From: Joao Victor Sena Date: Sun, 29 Nov 2026 20:45:02 -0300 Subject: [PATCH 36/38] test: read wear sent outcomes from the log in journeys Co-Authored-By: Claude Opus 5.5 --- journeys/wear/nfc-pay-background.xml | 5 +++-- journeys/wear/quickpay-off-holds.xml | 5 +++-- journeys/wear/quickpay-on-app-start.xml | 5 +++-- journeys/wear/quickpay-over-limit-holds.xml | 5 +++-- journeys/wear/quickpay-skips-hold.xml | 6 ++++-- journeys/wear/send-hold-invoice-settle.xml | 9 +++++---- journeys/wear/send-outcome-after-restart.xml | 5 +++-- journeys/wear/send-paid-reopen.xml | 3 ++- 8 files changed, 26 insertions(+), 17 deletions(-) diff --git a/journeys/wear/nfc-pay-background.xml b/journeys/wear/nfc-pay-background.xml index 535f2d4003..5db68b27ea 100644 --- a/journeys/wear/nfc-pay-background.xml +++ b/journeys/wear/nfc-pay-background.xml @@ -25,8 +25,9 @@ Verify "WatchSendAmount" reads "1 000" Run `adb logcat -d -s BitkitWear | grep -c "Dropped a repeat of an NFC tap"` and verify it prints 1: the repeat opened no second flow Hold "WatchSendHold" for 2 s as in README › Holding to pay - Wait up to 15 s until "WatchSendSent" is listed - Verify "WatchSendResultAmount" reads "1 000" + Run `adb shell 'for i in $(seq 150); do logcat -d -s BitkitWear | grep -q "Showed the success celebration" && break; sleep 0.1; done; screencap -p /sdcard/sent.png'`, which waits on the watch up to about 15 s for the celebration's log line and takes a screenshot as soon as it appears, since the screen closes 2 s after it shows and its confetti keeps a dump waiting past that (README › The confetti) + Run `adb logcat -d -s BitkitWear | grep -oE "Finished send with outcome '[^']*'|Showed the success celebration for '[^']*'"` and verify it prints "Finished send with outcome 'Sent'" and "Showed the success celebration for 'sent'": the send went out and the confetti started + Run `adb pull /sdcard/sent.png && adb shell rm /sdcard/sent.png` and verify from sent.png, the screenshot the step above took, that it shows the check, "Sent" and "1 000" Wait up to 6 s until "WatchHomeBalance" is listed: the flow closed by itself on the Balance page diff --git a/journeys/wear/quickpay-off-holds.xml b/journeys/wear/quickpay-off-holds.xml index aa17ea6546..027d79e068 100644 --- a/journeys/wear/quickpay-off-holds.xml +++ b/journeys/wear/quickpay-off-holds.xml @@ -18,11 +18,12 @@ Wait up to 15 s until `adb logcat -d -s BitkitWear` lists "Imported the phone's settings" Swipe right three times to the Balance page Run `../bitkit-docker/spark invoice 200` and note the BOLT11 invoice it prints as <invoice> + Run `adb logcat -c` Run `adb shell am start -a android.intent.action.VIEW -d "lightning:<invoice>" to.bitkit.dev` Wait up to 10 s until "WatchSendHold" is listed Verify "WatchSendAmount" reads "200" - Verify "WatchSendSent" does not get listed within 5 s: nothing was paid + Wait 5 s, then verify "WatchSendHold" is still listed and `adb logcat -d -s BitkitWear | grep -c "Finished send with outcome"` prints 0: nothing was paid. Count in the log, not a dump: a Sent screen's confetti would keep a dump waiting past the 2 s it shows (README › The confetti) Hold "WatchSendHold" for 2 s as in README › Holding to pay - Wait up to 15 s until "WatchSendSent" is listed + Wait up to 15 s until `adb logcat -d -s BitkitWear` lists "Finished send with outcome 'Sent'", and verify it also lists "Showed the success celebration for 'sent'": the send went out and the confetti started. Read the log, not a dump: the Sent screen's confetti keeps a dump waiting past the 2 s it shows (README › The confetti) diff --git a/journeys/wear/quickpay-on-app-start.xml b/journeys/wear/quickpay-on-app-start.xml index e309cb8d11..c25a48e952 100644 --- a/journeys/wear/quickpay-on-app-start.xml +++ b/journeys/wear/quickpay-on-app-start.xml @@ -18,8 +18,9 @@ Run `../bitkit-docker/spark invoice 200` and note the BOLT11 invoice it prints as <invoice> Run `adb logcat -c` Run `adb shell am start -a android.intent.action.VIEW -d "lightning:<invoice>" to.bitkit.dev`, which starts the app - Wait up to 40 s until "WatchSendSent" is listed, touching nothing - Verify "WatchSendResultAmount" reads "200" + Run `adb shell 'for i in $(seq 400); do logcat -d -s BitkitWear | grep -q "Showed the success celebration" && break; sleep 0.1; done; screencap -p /sdcard/sent.png'`, which waits on the watch up to about 40 s for the celebration's log line and takes a screenshot as soon as it appears, since the screen closes 2 s after it shows and its confetti keeps a dump waiting past that (README › The confetti), touching nothing + Run `adb logcat -d -s BitkitWear | grep -oE "Finished send with outcome '[^']*'|Showed the success celebration for '[^']*'"` and verify it prints "Finished send with outcome 'Sent'" and "Showed the success celebration for 'sent'": the send went out and the confetti started + Run `adb pull /sdcard/sent.png && adb shell rm /sdcard/sent.png` and verify from sent.png, the screenshot the step above took, that it shows the check, "Sent" and "200" Verify `adb logcat -d -s BitkitWear` lists "Skipped the hold to pay under QuickPay" diff --git a/journeys/wear/quickpay-over-limit-holds.xml b/journeys/wear/quickpay-over-limit-holds.xml index 3fc1dc40f8..7adf223b22 100644 --- a/journeys/wear/quickpay-over-limit-holds.xml +++ b/journeys/wear/quickpay-over-limit-holds.xml @@ -19,10 +19,11 @@ Swipe right three times to the Balance page Wait up to 1 minute until "WatchHomeBalanceSecondary" reads a fiat value: without the rates QuickPay holds whatever the amount Run `../bitkit-docker/spark invoice 10000` and note the BOLT11 invoice it prints as <invoice> + Run `adb logcat -c` Run `adb shell am start -a android.intent.action.VIEW -d "lightning:<invoice>" to.bitkit.dev` Wait up to 10 s until "WatchSendHold" is listed - Verify "WatchSendSent" does not get listed within 5 s: nothing was paid + Wait 5 s, then verify "WatchSendHold" is still listed and `adb logcat -d -s BitkitWear | grep -c "Finished send with outcome"` prints 0: nothing was paid. Count in the log, not a dump: a Sent screen's confetti would keep a dump waiting past the 2 s it shows (README › The confetti) Hold "WatchSendHold" for 2 s as in README › Holding to pay - Wait up to 15 s until "WatchSendSent" is listed + Wait up to 15 s until `adb logcat -d -s BitkitWear` lists "Finished send with outcome 'Sent'", and verify it also lists "Showed the success celebration for 'sent'": the send went out and the confetti started. Read the log, not a dump: the Sent screen's confetti keeps a dump waiting past the 2 s it shows (README › The confetti) diff --git a/journeys/wear/quickpay-skips-hold.xml b/journeys/wear/quickpay-skips-hold.xml index 513ea02e9d..4a952c4883 100644 --- a/journeys/wear/quickpay-skips-hold.xml +++ b/journeys/wear/quickpay-skips-hold.xml @@ -22,9 +22,11 @@ Swipe right three times to the Balance page Wait up to 1 minute until "WatchHomeBalanceSecondary" reads a fiat value: QuickPay needs the rates Run `../bitkit-docker/spark invoice 200` and note the BOLT11 invoice it prints as <invoice> + Run `adb logcat -c` Run `adb shell am start -a android.intent.action.VIEW -d "lightning:<invoice>" to.bitkit.dev` - Wait up to 20 s until "WatchSendSent" is listed, touching nothing - Verify "WatchSendResultAmount" reads "200" + Run `adb shell 'for i in $(seq 200); do logcat -d -s BitkitWear | grep -q "Showed the success celebration" && break; sleep 0.1; done; screencap -p /sdcard/sent.png'`, which waits on the watch up to about 20 s for the celebration's log line and takes a screenshot as soon as it appears, since the screen closes 2 s after it shows and its confetti keeps a dump waiting past that (README › The confetti), touching nothing + Run `adb logcat -d -s BitkitWear | grep -oE "Finished send with outcome '[^']*'|Showed the success celebration for '[^']*'"` and verify it prints "Finished send with outcome 'Sent'" and "Showed the success celebration for 'sent'": the send went out and the confetti started + Run `adb pull /sdcard/sent.png && adb shell rm /sdcard/sent.png` and verify from sent.png, the screenshot the step above took, that it shows the check, "Sent" and "200" Verify `adb logcat -d -s BitkitWear` lists "Skipped the hold to pay under QuickPay" Wait up to 6 s until "WatchHomeBalance" is listed: the flow closed by itself diff --git a/journeys/wear/send-hold-invoice-settle.xml b/journeys/wear/send-hold-invoice-settle.xml index 16ca61923d..0e3eafeb50 100644 --- a/journeys/wear/send-hold-invoice-settle.xml +++ b/journeys/wear/send-hold-invoice-settle.xml @@ -6,14 +6,15 @@ Precondition: send-hold-invoice-pending.xml was run just before, on the same emulator or watch, and its payment is still pending: keep its <preimage> and <hash>. The app is still open on the Balance page. README - › Hold invoices has the claim command. The outcome shows for 2 s, so read the layout at least once a second - while waiting for it. The app stays on screen for the whole journey. + › Hold invoices has the claim command. The outcome shows for 2 s under confetti that keeps a dump + waiting past that, so it is read from the log and a screenshot (README › The confetti). The app stays on screen for the whole journey. Run `adb logcat -c` Claim the payment as in README › Hold invoices, with <preimage> and <hash> - Wait up to 20 s until "WatchOutcomeSent" is listed - Verify "WatchOutcomeSent" has the content-desc "Sent, ₿ 1 000" + Run `adb shell 'for i in $(seq 200); do logcat -d -s BitkitWear | grep -q "Showed the success celebration" && break; sleep 0.1; done; screencap -p /sdcard/outcome.png'`, which waits on the watch up to about 20 s for the celebration's log line and takes a screenshot as soon as it appears, since the check shows for 2 s and its confetti keeps a dump waiting past that (README › The confetti) + Run `adb logcat -d -s BitkitWear | grep -oE "Resolved watched payment '[^']*' as '[^']*'|Showed the success celebration for '[^']*'"` and verify it prints "Resolved watched payment '<id>' as 'COMPLETED'" and "Showed the success celebration for '<id>'", with the same <id>: the payment was found sent and its check celebrated + Run `adb pull /sdcard/outcome.png && adb shell rm /sdcard/outcome.png` and verify from outcome.png, the screenshot the step above took, that it shows the purple check and "1 000". The screen reader's line, "Sent, ₿ 1 000", is SendOutcomeOverlayTest's to check: no dump catches the check while the confetti falls Wait 3 s Verify "WatchOutcomeSent" is not listed Verify "WatchHomeBalance" is listed diff --git a/journeys/wear/send-outcome-after-restart.xml b/journeys/wear/send-outcome-after-restart.xml index 1e38761b89..a6d4016d01 100644 --- a/journeys/wear/send-outcome-after-restart.xml +++ b/journeys/wear/send-outcome-after-restart.xml @@ -17,8 +17,9 @@ Run `adb shell am kill to.bitkit.dev` Verify `adb shell pidof to.bitkit.dev` prints nothing: the process ended before the outcome was shown Run `adb shell am start -n to.bitkit.dev/to.bitkit.wear.ui.MainActivity` - Wait up to 15 s until "WatchOutcomeSent" is listed, reading the layout at least once a second - Verify "WatchOutcomeSent" has the content-desc "Sent, ₿ 1 000" + Run `adb shell 'for i in $(seq 150); do logcat -d -s BitkitWear | grep -q "Showed the success celebration" && break; sleep 0.1; done; screencap -p /sdcard/outcome.png'`, which waits on the watch up to about 15 s for the celebration's log line and takes a screenshot as soon as it appears, since the check shows for 2 s and its confetti keeps a dump waiting past that (README › The confetti) + Run `adb logcat -d -s BitkitWear | grep -oE "Resolved watched payment '[^']*' as '[^']*'|Showed the success celebration for '[^']*'"` and verify it prints "Resolved watched payment '<id>' as 'COMPLETED'" and "Showed the success celebration for '<id>'", with the same <id>: the payment was found sent and its check celebrated + Run `adb pull /sdcard/outcome.png && adb shell rm /sdcard/outcome.png` and verify from outcome.png, the screenshot the step above took, that it shows the purple check and "1 000". The screen reader's line, "Sent, ₿ 1 000", is SendOutcomeOverlayTest's to check: no dump catches the check while the confetti falls Wait 3 s Verify "WatchOutcomeSent" is not listed Verify `adb logcat -d -s BitkitWear | grep -c "Resolved watched payment"` prints 1: it was not found a second time diff --git a/journeys/wear/send-paid-reopen.xml b/journeys/wear/send-paid-reopen.xml index c6286a8118..900533ad79 100644 --- a/journeys/wear/send-paid-reopen.xml +++ b/journeys/wear/send-paid-reopen.xml @@ -8,8 +8,9 @@ <invoice>. The app is still open on the Balance page. README › Hold invoices has the claim command. + Run `adb logcat -c` Claim the payment as in README › Hold invoices, with <preimage> and <hash> - Wait up to 20 s until "WatchOutcomeSent" is listed, reading the layout at least once a second + Wait up to 20 s until `adb logcat -d -s BitkitWear` lists "Showed the success celebration", and verify it also lists "Resolved watched payment '<id>' as 'COMPLETED'": the check of the sent payment showed. Read the log, not a dump: the check shows for 2 s and its confetti keeps a dump waiting past that (README › The confetti) Wait up to 5 s until "WatchHomeBalance" is listed Note the text of "WatchHomeBalance" as <paid balance> Run `adb shell am start -a android.intent.action.VIEW -d "lightning:<invoice>" to.bitkit.dev` From f29e26cbd0246f64da8a339ee3517875d3cfe431 Mon Sep 17 00:00:00 2001 From: Joao Victor Sena Date: Sun, 29 Nov 2026 20:45:34 -0300 Subject: [PATCH 37/38] fix: log the watch celebration only for a success Co-Authored-By: Claude Opus 5.5 --- .../src/main/java/to/bitkit/wear/ui/components/Confetti.kt | 7 ++++--- .../to/bitkit/wear/ui/components/SendOutcomeOverlay.kt | 6 +++++- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/wear/src/main/java/to/bitkit/wear/ui/components/Confetti.kt b/wear/src/main/java/to/bitkit/wear/ui/components/Confetti.kt index 0e137949c0..a8b7a949b3 100644 --- a/wear/src/main/java/to/bitkit/wear/ui/components/Confetti.kt +++ b/wear/src/main/java/to/bitkit/wear/ui/components/Confetti.kt @@ -104,10 +104,11 @@ data class Celebration(val isFirstShown: Boolean, val isCelebrated: Boolean) * an outcome cut short, it is over, so neither waking the watch nor the same success shown again plays it or its * haptic again. The decision outlives the screen being made again, so a success is first shown and celebrated at most * once. A null [key] is no success; a caller whose success does not show in ambient mode passes null meanwhile. - * A celebration logs one debug line as it starts, which journeys read since a screen dump misses the moving confetti. + * A celebration logs one debug line as it starts, for an [isSuccess] only, which journeys read since a screen dump + * misses the moving confetti. */ @Composable -fun rememberCelebration(key: String?, isAmbient: Boolean): Celebration { +fun rememberCelebration(key: String?, isAmbient: Boolean, isSuccess: Boolean = true): Celebration { var shownKey by rememberSaveable { mutableStateOf(null) } var celebratedKey by remember { mutableStateOf(null) } val isNew = key != null && key != shownKey @@ -116,7 +117,7 @@ fun rememberCelebration(key: String?, isAmbient: Boolean): Celebration { shownKey = key if (!isAmbient) { celebratedKey = key - Logger.debug("Showed the success celebration for '$key'", context = TAG) + if (isSuccess) Logger.debug("Showed the success celebration for '$key'", context = TAG) } } if (isAmbient || key == null) celebratedKey = null diff --git a/wear/src/main/java/to/bitkit/wear/ui/components/SendOutcomeOverlay.kt b/wear/src/main/java/to/bitkit/wear/ui/components/SendOutcomeOverlay.kt index debcbb2361..94d1c35a9f 100644 --- a/wear/src/main/java/to/bitkit/wear/ui/components/SendOutcomeOverlay.kt +++ b/wear/src/main/java/to/bitkit/wear/ui/components/SendOutcomeOverlay.kt @@ -61,7 +61,11 @@ internal fun OutcomeOverlay( ) { // Decided above the returns, as the outcome is first shown awake, so that neither waking the watch while it still // shows nor the outcome cut short and shown again plays its haptic or its confetti again. - val celebration = rememberCelebration(key = outcome?.id?.takeUnless { isAmbient }, isAmbient = isAmbient) + val celebration = rememberCelebration( + key = outcome?.id?.takeUnless { isAmbient }, + isAmbient = isAmbient, + isSuccess = outcome?.isSent == true, + ) if (outcome == null || isAmbient) return val haptic = LocalHapticFeedback.current LaunchedEffect(outcome.id) { From d8989961f119df39420e9b205771eb1b293f3e10 Mon Sep 17 00:00:00 2001 From: Joao Victor Sena Date: Mon, 30 Nov 2026 06:46:27 -0300 Subject: [PATCH 38/38] feat: show the purple lightning logo while the watch qr loads Co-Authored-By: Claude Opus 5.5 --- docs/wear.md | 3 ++- .../wear/ui/screens/receive/ReceiveQrScreen.kt | 9 ++++++++- wear/src/main/res/drawable/ic_ln_circle.xml | 12 ++++++++++++ 3 files changed, 22 insertions(+), 2 deletions(-) create mode 100644 wear/src/main/res/drawable/ic_ln_circle.xml diff --git a/docs/wear.md b/docs/wear.md index 22ba0b4472..aaed3b5cf2 100644 --- a/docs/wear.md +++ b/docs/wear.md @@ -192,7 +192,8 @@ On-screen copy stays short: a title or one line of at most about six words per s the QR rests: it hides behind the dimmed QR icon (`WatchReceiveHidden`, "Show QR") and the screen may turn off again, so a forgotten QR does not hold the screen at full brightness; a tap anywhere on that screen, or waking the watch from ambient mode, shows it for another 2 min. The invoice is made once the - wallet is ready, under the loading ring; a failure shows one line and a retry (`WatchReceiveError`, + wallet is ready, under the loading ring with the purple Lightning logo the phone puts on its spending QR + (`WatchReceiveLoading`); a failure shows one line and a retry (`WatchReceiveError`, `WatchReceiveRetry`). An invoice is replaced by a new one a minute before it expires, and it stays on screen until the new one exists; a replacement that fails is tried again every 5 s meanwhile, and when none exists by then, the loading ring, or the error, takes its place as it expires. A replaced invoice is still watched until it expires, so diff --git a/wear/src/main/java/to/bitkit/wear/ui/screens/receive/ReceiveQrScreen.kt b/wear/src/main/java/to/bitkit/wear/ui/screens/receive/ReceiveQrScreen.kt index 4900b91d2d..27e9689f5a 100644 --- a/wear/src/main/java/to/bitkit/wear/ui/screens/receive/ReceiveQrScreen.kt +++ b/wear/src/main/java/to/bitkit/wear/ui/screens/receive/ReceiveQrScreen.kt @@ -1,5 +1,6 @@ package to.bitkit.wear.ui.screens.receive +import androidx.compose.foundation.Image import androidx.compose.foundation.gestures.awaitEachGesture import androidx.compose.foundation.gestures.awaitFirstDown import androidx.compose.foundation.layout.Arrangement @@ -240,7 +241,13 @@ internal fun ReceiveQrContent( overlay = { BezelLoading() }, modifier = modifier ) { - QrIcon(modifier = Modifier.testTag("WatchReceiveLoading")) + Image( + painter = painterResource(R.drawable.ic_ln_circle), + contentDescription = null, + modifier = Modifier + .size(MARK_SIZE) + .testTag("WatchReceiveLoading") + ) } } } diff --git a/wear/src/main/res/drawable/ic_ln_circle.xml b/wear/src/main/res/drawable/ic_ln_circle.xml new file mode 100644 index 0000000000..b3c9a8790f --- /dev/null +++ b/wear/src/main/res/drawable/ic_ln_circle.xml @@ -0,0 +1,12 @@ + + + +