Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
8edd142
refactor: remove pay on watch from the phone's send review
jvsena42 Nov 29, 2026
9c34917
refactor: let the watch follow the phone's quickpay settings again
jvsena42 Nov 29, 2026
24010d9
feat: unpair and erase the watch with one button on the phone
jvsena42 Nov 29, 2026
81dcc37
feat: show the watch's send and receive in the spending purple
jvsena42 Nov 29, 2026
9334a3f
feat: show the watch icon on the phone's watch sheets
jvsena42 Nov 29, 2026
72f1dd6
feat: show the phone's activity icons on the watch's activity
jvsena42 Nov 29, 2026
560811c
feat: show the watch's activity times as the phone does
jvsena42 Nov 29, 2026
8c037fc
test: keep the watch's fiat currency the phone's alone
jvsena42 Nov 29, 2026
8763b34
feat: show a payment's note on the watch's activity detail
jvsena42 Nov 29, 2026
bb0b375
feat: pop the watch's success check in with the phone's confetti
jvsena42 Nov 29, 2026
efff814
test: check the watch ui follow-up in the wear journeys
jvsena42 Nov 29, 2026
63f687a
fix: unmark a watch erase that could not be stored and show an error
jvsena42 Nov 29, 2026
87ae198
refactor: drop the phone's watch removal that does not erase
jvsena42 Nov 29, 2026
afe911e
test: pin that the removed watch quickpay keys are ignored
jvsena42 Nov 29, 2026
3f5e6ec
fix: celebrate a watch success once, never again on waking
jvsena42 Nov 29, 2026
c6f3552
fix: scroll the watch's activity detail and follow the 24 h setting
jvsena42 Nov 29, 2026
cc1bf0f
docs: reflow the watch ui notes and fix a cross-reference
jvsena42 Nov 29, 2026
b2f2a9e
fix: make the watch tile's receive button purple
jvsena42 Nov 29, 2026
235d166
refactor: share the sheet intro's tinted icon with the watch sheet
jvsena42 Nov 29, 2026
f661520
fix: theme the watch's send and receive screens inside them
jvsena42 Nov 29, 2026
2742a0f
test: check the watch confetti and payment note without timing luck
jvsena42 Nov 29, 2026
5523733
fix: play a watch success haptic once, not again on a new screen
jvsena42 Nov 29, 2026
dda7e77
fix: keep the watch link store of an earlier build's unpair
jvsena42 Nov 29, 2026
fef4f81
fix: morph the watch's activity detail lines at the screen edge
jvsena42 Nov 29, 2026
10b2744
refactor: drop the sheet intro icon's unused tint
jvsena42 Nov 29, 2026
b431da1
style: drop the kdoc of a private watch payment helper
jvsena42 Nov 29, 2026
569fe89
test: check the watch confetti in the dump that finds the success
jvsena42 Nov 29, 2026
4802de9
test: read the wear sent amount and screenshot in the same command
jvsena42 Nov 29, 2026
5db849f
feat: drop the start on phone hint from watch onboarding
jvsena42 Nov 29, 2026
8ff2b1c
fix: center the watch's activity detail when it fits
jvsena42 Nov 29, 2026
f0e295d
feat: show the watch icon on the paired watch sheet
jvsena42 Nov 29, 2026
857fc62
chore: log the watch's success celebration as it starts
jvsena42 Nov 29, 2026
4b0f624
test: check the watch confetti from the log in journeys
jvsena42 Nov 29, 2026
1587f80
test: find the watch's activity rows by what they show
jvsena42 Nov 29, 2026
ce8ec53
test: read sent from the log and confirm the dialog in quickpay
jvsena42 Nov 29, 2026
a71b5ba
test: read wear sent outcomes from the log in journeys
jvsena42 Nov 29, 2026
f29e26c
fix: log the watch celebration only for a success
jvsena42 Nov 29, 2026
d898996
feat: show the purple lightning logo while the watch qr loads
jvsena42 Nov 30, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 0 additions & 8 deletions app/src/main/java/to/bitkit/data/SettingsStore.kt
Original file line number Diff line number Diff line change
Expand Up @@ -242,14 +242,6 @@ data class SettingsData(
val isQuickPayEnabled: Boolean = false,
val quickPayAmount: Int = 5,
val quickPayDailyLimitMultiplier: Int = 5,
/**
* The paired Wear OS watch's own QuickPay, set here and pushed to the watch, and carried by the settings backup
* to a watch that reads it. Off until the user turns it on; it holds on the watch only while [isQuickPayEnabled]
* is on too. Older builds and bitkit-ios ignore these keys, and a backup without them gives these defaults.
*/
val isWatchQuickPayEnabled: Boolean = false,
val watchQuickPayAmount: Int = 5,
val watchQuickPayDailyLimitMultiplier: Int = 5,
/** Whether the prompt to install Bitkit on a connected watch was shown; it shows once. */
val watchInstallPromptSeen: Boolean = false,
val isPinEnabled: Boolean = false,
Expand Down
4 changes: 0 additions & 4 deletions app/src/main/java/to/bitkit/data/WatchLinkStore.kt
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,6 @@ class WatchLinkStore internal constructor(

override val record: Flow<LinkRecord?> = store.data.map { it.record }.distinctUntilChanged()

/** The watch's last QuickPay count as it changes, or null without a paired watch or before its first count. */
val watchQuickPayUpdates: Flow<QuickPayDoc?> =
store.data.map { data -> data.watchQuickPay?.takeIf { data.record != null } }.distinctUntilChanged()

override suspend fun load(): LinkRecord? = store.data.first().record

override suspend fun update(transform: (LinkRecord?) -> LinkRecord?): LinkRecord? =
Expand Down
20 changes: 1 addition & 19 deletions app/src/main/java/to/bitkit/repositories/QuickPayRepo.kt
Original file line number Diff line number Diff line change
Expand Up @@ -989,10 +989,7 @@ class QuickPayAuthorization(
val useBiometrics: Boolean,
)

/**
* One QuickPay setting the user asked to change, with its new value: the phone's own QuickPay or the watch's. Both
* follow one rule: a raise asks for the PIN or biometric check while payments need the PIN.
*/
/** One QuickPay setting the user asked to change, with its new value. */
sealed interface QuickPayChange {
fun isRaise(settings: SettingsData): Boolean
fun applyTo(settings: SettingsData): SettingsData
Expand All @@ -1011,21 +1008,6 @@ sealed interface QuickPayChange {
override fun isRaise(settings: SettingsData) = value > settings.quickPayDailyLimitMultiplier
override fun applyTo(settings: SettingsData) = settings.copy(quickPayDailyLimitMultiplier = value)
}

data class WatchEnabled(val value: Boolean) : QuickPayChange {
override fun isRaise(settings: SettingsData) = value && !settings.isWatchQuickPayEnabled
override fun applyTo(settings: SettingsData) = settings.copy(isWatchQuickPayEnabled = value)
}

data class WatchAmount(val value: Int) : QuickPayChange {
override fun isRaise(settings: SettingsData) = value > settings.watchQuickPayAmount
override fun applyTo(settings: SettingsData) = settings.copy(watchQuickPayAmount = value)
}

data class WatchDailyLimitMultiplier(val value: Int) : QuickPayChange {
override fun isRaise(settings: SettingsData) = value > settings.watchQuickPayDailyLimitMultiplier
override fun applyTo(settings: SettingsData) = settings.copy(watchQuickPayDailyLimitMultiplier = value)
}
}

fun interface QuickPayInvoiceParser {
Expand Down
102 changes: 4 additions & 98 deletions app/src/main/java/to/bitkit/repositories/WatchLinkRepo.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,28 +17,21 @@ 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
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
import to.bitkit.data.CacheStore
import to.bitkit.data.SettingsData
Expand All @@ -54,20 +47,15 @@ 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
Expand All @@ -78,11 +66,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

Expand All @@ -99,7 +85,6 @@ import kotlin.time.ExperimentalTime
* wallet and pushes it the settings: nothing secret is sent then.
*
* The phone's settings are published to the paired watch when the pairing is made and whenever one of them changes,
* the watch's own QuickPay limits with them,
* and so are the shared guards' documents: the phone's own unexpired Spark invoices, its QuickPay count of its day,
* and its open Spark sends. Each document has one publisher, which also publishes it again once the watch's first
* status shows it noted the pairing, since the watch drops what arrives before that. What the watch publishes of its
Expand Down Expand Up @@ -140,9 +125,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
Expand Down Expand Up @@ -243,14 +225,6 @@ class WatchLinkRepo internal constructor(
/** The paired watch, or null. */
val record: Flow<LinkRecord?> = store.record

/**
* What the paired watch spent under QuickPay on this phone's day, in US cents, as it last said: 0 before its first
* count or for a count of another day, and null without a paired watch.
*/
val watchSpentTodayCents: Flow<Long?> = combine(store.record, store.watchQuickPayUpdates) { record, quickPay ->
record?.let { LinkGuards.peerCents(quickPay, todayKey()) }
}.distinctUntilChanged()

private val _pairing = MutableStateFlow<WatchPairingStatus>(WatchPairingStatus.Idle)
val pairing: StateFlow<WatchPairingStatus> = _pairing.asStateFlow()

Expand Down Expand Up @@ -389,61 +363,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<PayOnWatchResult> = 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.
Expand All @@ -462,11 +381,11 @@ class WatchLinkRepo internal constructor(
private suspend fun isPinSet(): Boolean = settingsStore.data.first().isPinEnabled

/**
* Asks the watch to forget this phone, and with [isErase] to delete its wallet. The watch stays listed, marked,
* until it acknowledges: an erase is best effort, since a watch that never reconnects never reads it.
* The user's unpair: asks the watch to forget this phone and to delete its wallet. The watch stays listed,
* marked, until it acknowledges: the erase is best effort, since a watch that never reconnects never reads it.
*/
suspend fun remove(isErase: Boolean): Result<Unit> = withContext(ioDispatcher) {
runSuspendCatching { link.remove(isErase) }
suspend fun unpair(): Result<Unit> = withContext(ioDispatcher) {
runSuspendCatching { link.remove() }
.onFailure { Logger.warn("Failed to remove the watch", it, context = TAG) }
}

Expand Down Expand Up @@ -517,14 +436,8 @@ class WatchLinkRepo internal constructor(
isQuickPayEnabled = isQuickPayEnabled,
quickPayAmount = quickPayAmount,
quickPayDailyLimitMultiplier = quickPayDailyLimitMultiplier,
isWatchQuickPayEnabled = isWatchQuickPayEnabled,
watchQuickPayAmount = watchQuickPayAmount,
watchQuickPayDailyLimitMultiplier = watchQuickPayDailyLimitMultiplier,
)

/** The phone's day as its QuickPay count names it: the ISO date of the device's own time zone. */
private fun todayKey(): String = clock.now().toLocalDateTime(TimeZone.currentSystemDefault()).date.toString()

private inner class PairingEnv : PhonePairingEnv {
override val appId: String = this@WatchLinkRepo.appId
override val name: String = Build.MODEL.orEmpty()
Expand Down Expand Up @@ -587,13 +500,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")
Expand Down
64 changes: 50 additions & 14 deletions app/src/main/java/to/bitkit/ui/components/SheetIntro.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,18 @@ 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
import androidx.compose.foundation.layout.heightIn
import androidx.compose.foundation.layout.navigationBarsPadding
import androidx.compose.foundation.layout.padding
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.ColorFilter
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.platform.testTag
import androidx.compose.ui.res.painterResource
Expand All @@ -26,6 +29,34 @@ import to.bitkit.ui.theme.Colors
/** Width fraction used by intro sheet artwork. */
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. */
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 Brand orange, as the intro sheets' accented titles.
*/
@Composable
fun ColumnScope.SheetIntroIcon(
@DrawableRes icon: Int,
modifier: Modifier = Modifier,
) {
Box(
contentAlignment = Alignment.Center,
modifier = Modifier
.fillMaxWidth()
.weight(1f)
) {
Image(
painter = painterResource(icon),
contentDescription = null,
contentScale = ContentScale.Fit,
colorFilter = ColorFilter.tint(Colors.Brand),
modifier = modifier.size(SHEET_INTRO_ICON_SIZE)
)
}
}

@Composable
fun SheetIntro(
navTitle: String,
Expand All @@ -42,6 +73,7 @@ fun SheetIntro(
testTag: String = "SheetIntro",
cancelTestTag: String = "${testTag}Cancel",
continueTestTag: String = "${testTag}Continue",
isImageIcon: Boolean = false,
) {
Column(
modifier = modifier
Expand All @@ -55,21 +87,25 @@ fun SheetIntro(
Column(
modifier = Modifier.padding(horizontal = 32.dp),
) {
Box(
contentAlignment = Alignment.BottomCenter,
modifier = Modifier
.fillMaxWidth()
.weight(1f)
) {
Image(
painter = painterResource(image),
contentDescription = null,
contentScale = ContentScale.Fit,
if (isImageIcon) {
SheetIntroIcon(icon = image, modifier = Modifier.testTag("${testTag}Image"))
} else {
Box(
contentAlignment = Alignment.BottomCenter,
modifier = Modifier
.fillMaxWidth(SHEET_INTRO_IMAGE_WIDTH_FRACTION)
.heightIn(max = 320.dp)
.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)
Expand Down
Loading