[cart-checkout] Prefer live appState.address.display over async selectedCustomerAddress for the name

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.
This commit is contained in:
Daniel Arantes Loverde
2026-07-10 11:43:15 -03:00
parent a5878b8326
commit fc71228ad5

View File

@@ -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"
}