From fc71228ad5e1c19a55e293d9999d313170afd3ab Mon Sep 17 00:00:00 2001 From: Daniel Arantes Loverde Date: Fri, 10 Jul 2026 11:43:15 -0300 Subject: [PATCH] [cart-checkout] Prefer live appState.address.display over async selectedCustomerAddress for the name MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Same class of bug as the earlier matching-cascade fix: selectedCustomerAddress is resolved asynchronously against the address book and can lag behind or mismatch. appState.address.display is set synchronously the moment the user picks an address (AddressesView.selectAddress) — it's the authoritative live value. customerAddressName had these backwards, checking the async value first. --- Sources/PediFoods/Views/Main/CheckoutView.swift | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/Sources/PediFoods/Views/Main/CheckoutView.swift b/Sources/PediFoods/Views/Main/CheckoutView.swift index fbbe7f6..0c692bd 100644 --- a/Sources/PediFoods/Views/Main/CheckoutView.swift +++ b/Sources/PediFoods/Views/Main/CheckoutView.swift @@ -558,12 +558,19 @@ struct CheckoutView: View { } private var customerAddressName: String { - let label = (selectedCustomerAddress?.label ?? "").trimmingCharacters(in: .whitespacesAndNewlines) - if label.isEmpty == false { return label } - + // appState.address.display is set directly, synchronously, the + // moment the user picks an address (AddressesView.selectAddress) — + // it's live. selectedCustomerAddress is resolved later via an async + // matching cascade against the address book and can briefly (or, + // if matching goes wrong, persistently) lag behind or resolve to + // the wrong entry. Prefer the live value; the async one is only a + // fallback for when nothing's been picked yet this session. let displayLabel = appState.address.display.trimmingCharacters(in: .whitespacesAndNewlines) if displayLabel.isEmpty == false, displayLabel != "Defina seu endereco" { return displayLabel } + let label = (selectedCustomerAddress?.label ?? "").trimmingCharacters(in: .whitespacesAndNewlines) + if label.isEmpty == false { return label } + return "Endereço" }