Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
@@ -1,20 +1,26 @@
package to.bitkit.ui.screens.wallets.send

import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.ui.graphics.toPixelMap
import androidx.compose.ui.platform.LocalInspectionMode
import androidx.compose.ui.test.assertIsDisplayed
import androidx.compose.ui.test.captureToImage
import androidx.compose.ui.test.junit4.v2.createComposeRule
import androidx.compose.ui.test.onNodeWithTag
import androidx.compose.ui.test.onNodeWithText
import androidx.compose.ui.test.onRoot
import androidx.compose.ui.test.performScrollTo
import org.junit.Rule
import org.junit.Test
import to.bitkit.models.FeeRate
import to.bitkit.test.annotations.ComposeUi
import to.bitkit.ui.theme.AppThemeSurface
import to.bitkit.ui.theme.Colors
import to.bitkit.viewmodels.OnchainFeeUi
import to.bitkit.viewmodels.SendMethod
import to.bitkit.viewmodels.SendUiState
import kotlin.test.assertEquals
import kotlin.test.assertTrue

@ComposeUi
class SendConfirmScreenTest {
Expand Down Expand Up @@ -50,4 +56,68 @@ class SendConfirmScreenTest {
composeTestRule.onNodeWithTag("SendConfirmToggleDetails").assertIsDisplayed()
composeTestRule.onNodeWithText("Swipe To Subscribe & Pay").performScrollTo().assertIsDisplayed()
}

@Test
fun onchainSendFromSavingsUsesBrandAccent() {
setConfirmContent(hardwareWalletId = null)

val pixels = accentPixelCounts()

assertTrue(pixels.brand > 0, "expected brand accent pixels, got ${pixels.brand}")
assertEquals(0, pixels.blue, "expected no blue accent pixels")
}

@Test
fun onchainSendFromHardwareWalletUsesBlueAccent() {
setConfirmContent(hardwareWalletId = "hw-wallet-id")

val pixels = accentPixelCounts()

assertTrue(pixels.blue > 0, "expected blue accent pixels, got ${pixels.blue}")
assertEquals(0, pixels.brand, "expected no brand accent pixels")
}

private fun setConfirmContent(hardwareWalletId: String?) {
val state = SendUiState(
amount = 10_000u,
payMethod = SendMethod.ONCHAIN,
isAmountInputValid = true,
hardwareWalletId = hardwareWalletId,
hardwareWalletName = hardwareWalletId?.let { "Trezor Safe 7" },
onchainFeeUi = OnchainFeeUi(rate = FeeRate.NORMAL, sats = 422),
)
composeTestRule.setContent {
AppThemeSurface {
CompositionLocalProvider(LocalInspectionMode provides true) {
SendConfirmContent(
uiState = state,
isNodeRunning = true,
isLoading = false,
showBiometrics = false,
)
}
}
}
}

private fun accentPixelCounts(): AccentPixelCounts {
val pixelMap = composeTestRule.onRoot().captureToImage().toPixelMap()
var brand = 0
var blue = 0
for (y in 0 until pixelMap.height) {
for (x in 0 until pixelMap.width) {
when (pixelMap[x, y]) {
Colors.Brand -> brand++
Colors.Blue -> blue++
else -> Unit
}
}
}
return AccentPixelCounts(brand = brand, blue = blue)
}
}

private data class AccentPixelCounts(
val brand: Int,
val blue: Int,
)
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,7 @@ private fun ContentRunning(
val isHardwareFeeLoading = uiState.hardwareWalletId != null && uiState.onchainFeeUi.isLoading

val accentColor = when (uiState.payMethod) {
SendMethod.ONCHAIN if uiState.hardwareWalletId != null -> Colors.Blue
SendMethod.ONCHAIN -> Colors.Brand
SendMethod.LIGHTNING -> Colors.Purple
}
Expand Down Expand Up @@ -918,6 +919,33 @@ private fun PreviewOnChainDetails() {
}
}

@Suppress("MagicNumber")
@Preview(showSystemUi = true, group = "onchain details")
@Composable
private fun PreviewOnChainHardwareDetails() {
AppThemeSurface {
BottomSheetPreview {
SendConfirmContent(
uiState = sendUiState().copy(
hardwareWalletId = "wallet-id",
hardwareWalletName = "Trezor Safe 7",
canSwitchFundingSource = true,
speed = TransactionSpeed.Medium,
onchainFeeUi = OnchainFeeUi(
rate = FeeRate.NORMAL,
sats = 1_234,
),
),
isNodeRunning = true,
isLoading = false,
showBiometrics = false,
initialShowDetails = true,
modifier = Modifier.sheetHeight()
)
}
}
}

@Suppress("MagicNumber")
@Preview(showSystemUi = true, group = "lightning details")
@Composable
Expand Down
1 change: 1 addition & 0 deletions changelog.d/next/1263.fixed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
The swipe-to-confirm slider on the send confirmation screen now uses the blue hardware accent when the funding source is a hardware wallet.