Modern Apps git

← Modern-Apps.git

shop: delete in-progress orders from Orders page

Commit
6e1f3aac3045813048c1070c7a0fc513102004b7
Author
Vayun Mathur <[email protected]>
When
2026-12-02 03:05 UTC (4 days ago)
Parents
d80685d
In-progress orders on the Orders tab (the not-completed records
shown as Continue in browser) now show a delete icon in the row
header. Completed orders show no delete icon.

Deletion is real, not just hiding the row: PlacedOrder gains an
isInProgress projection (status != completed), OrderStore.remove
rewrites the persisted shop_orders list without the record matched
by checkoutId/shopDomain/placedAtMs, and ShopViewModel.deleteOrder
guards on isInProgress, updates the in-memory orders from the store
result, and reschedules order tracking. OrdersScreen wires the
callback and reports Order deleted through the messenger pattern;
no confirmation route is needed because deletion is direct.

The icon uses only the generated library/ui IconDelete wrapper
inside the library IconButton, per the icons.tsv convention.

shop/AGENTS.md documents the new Orders-tab behaviour.

Verified with ./gradlew :shop:lint :shop:lintVitalRelease
:shop:testDevUnitTest (BUILD SUCCESSFUL; lintVitalRelease task
was SKIPPED by Gradle while lintVitalAnalyzeRelease ran). New
tests pin that an in-progress order shows exactly one Delete
action while a completed order shows none, and that deleting an
in-progress order through OrdersScreen removes it from both the
ViewModel list and the persisted OrderStore, leaving the
completed order untouched.

Diff

shop/AGENTS.md
diff --git a/shop/AGENTS.md b/shop/AGENTS.mdindex 0754c34501..107f2c57ea 100644--- a/shop/AGENTS.md+++ b/shop/AGENTS.md@@ -15,6 +15,7 @@ Entry types: MainActivity, Route, Navigation. Navigation remains a root-only gra - Checkout takes no buyer input: every session field comes from the saved profile (`ProfileCheckout`). Merchant shipping-option choices remain selectable. Merchant totals and legal links are authoritative. - Checkout is one tap (a per-store Checkout button in Cart, or Buy now): `ShopViewModel.checkoutStore` creates a fresh session carrying the whole profile (name, contact, address) with a stable idempotency key, then opens the merchant's `continue_url` (from the session or a rejection) in Embedded Checkout. There is no in-app review screen. Never replay an uncertain mutation automatically. - Preserve cart lines through partial failures and browser handoffs. A session or browser return is not a paid order.+- In-progress orders (not completed, shown as "Continue in browser") show a delete icon on the Orders tab; deleting removes that record entirely from `OrderStore`. Completed orders show no delete icon and are not deletable from the Orders tab. - Delivery tracking comes from UCP order webhooks received server-side (`POST /shop/v1/order-webhooks`: RFC 9421 from generic UCP businesses via the platform profile's `webhook_url`, or Shopify HMAC once a partner manager has registered the URL) and from UCP `get_order`. The server identifies the platform the spec-native way, with no API keys: when `SHOP_SIGNING_KEY` is set it signs every merchant request (RFC 9421, ES256) and publishes the public JWK in `/.well-known/ucp` (`keys[]`; plus `signing_keys[]` in 2026-04-08). A 401 from a business retries once unsigned. Checkout creation returns an opaque `trackingToken`; the app stores it on the pending record, and `ec.complete` updates that same record (adding the merchant `orderId`) rather than adding a new one. The Orders tab and an hourly `OrderTrackingWorker` (scheduled only while a placed order is undelivered) poll `POST /shop/v1/orders/status` with `{token, orderId}`; the server reads `get_order` at most every 10 minutes per order and accepts a result only if its `checkout_id` matches that token's checkout. Status changes post "Delivery updates" notifications. Tracking records are PII-free (no destinations or buyer data); the merchant's `permalink_url` stays the authoritative order page. - Payment happens only inside the merchant's own checkout via UCP Embedded Checkout (ECP) without payment delegation: `ui/EmbeddedCheckoutScreen` loads the merchant `continue_url` with `ec_version`/`ec_color_scheme`/`ec_delegate=window.open` in a WebView. The app never sees card data or tokens and never calls Complete Checkout. The `EmbeddedCheckoutProtocolConsumer` bridge is an origin-scoped `WebViewCompat.addWebMessageListener` (merchant domain, its subdomains, the handoff host, shop.app); `domain/EmbeddedCheckout` answers `ec.ready`, opens `ec.window.open_request` links in a Custom Tab, and treats `ec.complete` as the only completion signal. Only the order id, order permalink and total are persisted; the session URL stays in memory. - Only supported integer quantities can be added. Detail refresh sends the product ID and selected options, and must confirm the exact variant before cart actions. If a valid detail response returns only another featured option, one fresh advertised merchant search may confirm the exact SKU. Cached snapshots and empty lookup responses are not verification; denied/rate-limited calls are never retried automatically.
shop/src/main/java/com/vayunmathur/shop/data/OrderStore.kt
diff --git a/shop/src/main/java/com/vayunmathur/shop/data/OrderStore.kt b/shop/src/main/java/com/vayunmathur/shop/data/OrderStore.ktindex c385b83bd5..b40c979dd4 100644--- a/shop/src/main/java/com/vayunmathur/shop/data/OrderStore.kt+++ b/shop/src/main/java/com/vayunmathur/shop/data/OrderStore.kt@@ -23,6 +23,14 @@ object OrderStore {         runCatching { json.decodeFromString<List<PlacedOrder>>(raw) }.getOrDefault(emptyList())     } +    /** Removes one stored record entirely, matched by its list identity. */+    suspend fun remove(context: Context, order: PlacedOrder): List<PlacedOrder> = update(context) { current ->+        current.filterNot {+            it.checkoutId == order.checkoutId && it.shopDomain == order.shopDomain &&+                it.placedAtMs == order.placedAtMs+        }+    }+     suspend fun add(context: Context, order: PlacedOrder) = update(context) { current ->         val others = current.filterNot {             it.checkoutId == order.checkoutId && it.shopDomain == order.shopDomain
shop/src/main/java/com/vayunmathur/shop/data/UcpModels.kt
diff --git a/shop/src/main/java/com/vayunmathur/shop/data/UcpModels.kt b/shop/src/main/java/com/vayunmathur/shop/data/UcpModels.ktindex bb9804fe69..36a4cfe132 100644--- a/shop/src/main/java/com/vayunmathur/shop/data/UcpModels.kt+++ b/shop/src/main/java/com/vayunmathur/shop/data/UcpModels.kt@@ -167,6 +167,9 @@ data class PlacedOrder(     val tracking: OrderTracking? = null, ) {     val displayName: String get() = storeName.ifBlank { shopDomain }++    /** In-progress checkouts are the not-yet-completed records shown as "Continue in browser". */+    val isInProgress: Boolean get() = status != "completed" }  /** Contract for ucp error. */
shop/src/main/java/com/vayunmathur/shop/platform/ShopViewModel.kt
diff --git a/shop/src/main/java/com/vayunmathur/shop/platform/ShopViewModel.kt b/shop/src/main/java/com/vayunmathur/shop/platform/ShopViewModel.ktindex 762cbb91a3..f584044081 100644--- a/shop/src/main/java/com/vayunmathur/shop/platform/ShopViewModel.kt+++ b/shop/src/main/java/com/vayunmathur/shop/platform/ShopViewModel.kt@@ -319,6 +319,15 @@ class ShopViewModel(         }     } +    /** Deletes an in-progress order entirely from the persisted store. Completed orders are kept. */+    fun deleteOrder(order: PlacedOrder, context: Context) {+        if (!order.isInProgress) return+        viewModelScope.launch {+            orders = OrderStore.remove(context, order)+            OrderTrackingSync.schedule(context, orders)+        }+    }+     fun refreshTracking(context: Context) {         if (refreshingTracking) return         refreshingTracking = true
shop/src/main/java/com/vayunmathur/shop/ui/OrdersContent.kt
diff --git a/shop/src/main/java/com/vayunmathur/shop/ui/OrdersContent.kt b/shop/src/main/java/com/vayunmathur/shop/ui/OrdersContent.ktindex 5546ec671e..9523383208 100644--- a/shop/src/main/java/com/vayunmathur/shop/ui/OrdersContent.kt+++ b/shop/src/main/java/com/vayunmathur/shop/ui/OrdersContent.kt@@ -22,6 +22,8 @@ import androidx.compose.ui.unit.dp import com.vayunmathur.library.ui.AppScaffold import com.vayunmathur.library.ui.Button import com.vayunmathur.library.ui.Card+import com.vayunmathur.library.ui.IconButton+import com.vayunmathur.library.ui.IconDelete import com.vayunmathur.library.ui.MaterialTheme import com.vayunmathur.library.ui.OutlinedButton import com.vayunmathur.library.ui.Text@@ -46,6 +48,7 @@ fun OrdersContent(     refreshing: Boolean,     onRefresh: () -> Unit,     onOpenUrl: (String) -> Unit,+    onDeleteOrder: (PlacedOrder) -> Unit = {}, ) {     AppScaffold(         title = stringResource(R.string.orders),@@ -69,7 +72,7 @@ fun OrdersContent(                 modifier = Modifier.fillMaxSize().padding(padding),             ) {                 items(orders, key = { "${it.shopDomain}-${it.checkoutId}-${it.placedAtMs}" }) { order ->-                    OrderRow(order = order, onOpen = onOpenUrl)+                    OrderRow(order = order, onOpen = onOpenUrl, onDelete = { onDeleteOrder(order) })                 }             }         }@@ -77,7 +80,7 @@ fun OrdersContent( }  @Composable-private fun OrderRow(order: PlacedOrder, onOpen: (String) -> Unit) {+private fun OrderRow(order: PlacedOrder, onOpen: (String) -> Unit, onDelete: () -> Unit = {}) {     val tracking = order.tracking     val completed = order.status == "completed"     Card {@@ -89,6 +92,9 @@ private fun OrderRow(order: PlacedOrder, onOpen: (String) -> Unit) {                     modifier = Modifier.weight(1f),                 )                 tracking?.label?.let { Text(it, style = MaterialTheme.typography.labelMedium) }+                if (order.isInProgress) {+                    IconButton(onClick = onDelete) { IconDelete() }+                }             }             Text(                 stringResource(
shop/src/main/java/com/vayunmathur/shop/ui/OrdersScreen.kt
diff --git a/shop/src/main/java/com/vayunmathur/shop/ui/OrdersScreen.kt b/shop/src/main/java/com/vayunmathur/shop/ui/OrdersScreen.ktindex 388595ef28..89ef0c7330 100644--- a/shop/src/main/java/com/vayunmathur/shop/ui/OrdersScreen.kt+++ b/shop/src/main/java/com/vayunmathur/shop/ui/OrdersScreen.kt@@ -2,6 +2,9 @@ package com.vayunmathur.shop.ui  import androidx.compose.runtime.Composable import androidx.compose.ui.platform.LocalContext+import androidx.compose.ui.res.stringResource+import com.vayunmathur.library.ui.rememberMessenger+import com.vayunmathur.shop.R import com.vayunmathur.shop.platform.ShopViewModel  /**@@ -11,10 +14,16 @@ import com.vayunmathur.shop.platform.ShopViewModel @Composable fun OrdersScreen(viewModel: ShopViewModel) {     val context = LocalContext.current+    val messenger = rememberMessenger()+    val orderDeletedMessage = stringResource(R.string.order_deleted)     OrdersContent(         orders = viewModel.orders,         refreshing = viewModel.refreshingTracking,         onRefresh = { viewModel.refreshTracking(context) },         onOpenUrl = { url -> openContinueUrl(context, url) },+        onDeleteOrder = { order ->+            viewModel.deleteOrder(order, context)+            messenger.show(orderDeletedMessage)+        },     ) }
shop/src/main/res/values/strings.xml
diff --git a/shop/src/main/res/values/strings.xml b/shop/src/main/res/values/strings.xmlindex 682412d87e..d5d0cdda77 100644--- a/shop/src/main/res/values/strings.xml+++ b/shop/src/main/res/values/strings.xml@@ -17,6 +17,8 @@     <string name="orders">Orders</string>     <string name="no_orders_yet">No orders yet</string>     <string name="continue_in_browser">Continue in browser</string>+    <!-- OrdersScreen: confirmation after an in-progress order is deleted from the orders list -->+    <string name="order_deleted">Order deleted</string>     <string name="estimated_subtotal">Estimated subtotal</string>     <string name="checkout_pending">Payment not confirmed</string>     <string name="order_placed">Order placed</string>
shop/src/test/java/com/vayunmathur/shop/ui/ShopScreensTest.kt
diff --git a/shop/src/test/java/com/vayunmathur/shop/ui/ShopScreensTest.kt b/shop/src/test/java/com/vayunmathur/shop/ui/ShopScreensTest.ktindex b5ca4d3318..f8f50c830d 100644--- a/shop/src/test/java/com/vayunmathur/shop/ui/ShopScreensTest.kt+++ b/shop/src/test/java/com/vayunmathur/shop/ui/ShopScreensTest.kt@@ -2,8 +2,11 @@ package com.vayunmathur.shop.ui  import android.content.Context import androidx.compose.ui.test.assertIsDisplayed+import androidx.compose.ui.test.assertCountEquals import androidx.compose.ui.test.junit4.createComposeRule+import androidx.compose.ui.test.onAllNodesWithContentDescription import androidx.compose.ui.test.onAllNodesWithText+import androidx.compose.ui.test.onNodeWithContentDescription import androidx.compose.ui.test.onNodeWithText import androidx.compose.ui.test.performClick import androidx.compose.ui.test.hasScrollAction@@ -249,6 +252,54 @@ class ShopScreensTest {         composeRule.onNodeWithText(str(R.string.track_package)).assertIsDisplayed()     } +    @Test+    fun ordersContent_inProgressShowsDeleteCompletedDoesNot() {+        val pending = PlacedOrder(+            checkoutId = "chk-pending", placedAtMs = 1_700_000_000_000, total = Money(5_000, "USD"),+            itemCount = 1, continueUrl = "https://cool.example/checkout", status = "pending",+            shopDomain = "cool.example", storeName = "Cool Store",+        )+        val completed = PlacedOrder(+            checkoutId = "chk-done", placedAtMs = 1_700_000_100_000, total = Money(9_000, "USD"),+            itemCount = 1, continueUrl = "https://kitchen.example/orders/1", status = "completed",+            shopDomain = "kitchen.example", storeName = "Kitchen",+        )+        var deleted: PlacedOrder? = null+        composeRule.setContent {+            OrdersContent(+                orders = listOf(pending, completed), refreshing = false, onRefresh = {},+                onOpenUrl = {}, onDeleteOrder = { deleted = it },+            )+        }+        composeRule.onNodeWithText(str(R.string.continue_in_browser)).assertIsDisplayed()+        composeRule.onAllNodesWithContentDescription("Delete").assertCountEquals(1)+        composeRule.onNodeWithContentDescription("Delete").performClick()+        assertEquals(pending, deleted)+    }++    @Test+    fun ordersScreen_deleteInProgressRemovesItFromStore() {+        val pending = PlacedOrder(+            checkoutId = "chk-pending", placedAtMs = 1_700_000_000_000, total = Money(5_000, "USD"),+            itemCount = 1, continueUrl = "https://cool.example/checkout", status = "pending",+            shopDomain = "cool.example", storeName = "Cool Store",+        )+        val completed = PlacedOrder(+            checkoutId = "chk-done", placedAtMs = 1_700_000_100_000, total = Money(9_000, "USD"),+            itemCount = 1, status = "completed", shopDomain = "kitchen.example", storeName = "Kitchen",+        )+        runBlocking { OrderStore.add(context, completed); OrderStore.add(context, pending) }+        val vm = ShopViewModel()+        vm.loadOrders(context)+        await { vm.orders.size == 2 }+        composeRule.setContent { OrdersScreen(vm) }+        composeRule.waitForIdle()+        composeRule.onAllNodesWithContentDescription("Delete").assertCountEquals(1)+        composeRule.onNodeWithContentDescription("Delete").performClick()+        await { vm.orders == listOf(completed) }+        runBlocking { assertEquals(listOf(completed), OrderStore.getAll(context)) }+    }+     @Test     fun ordersScreen_emptyShowsPrompt() {         val vm = ShopViewModel()