[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:
@@ -558,12 +558,19 @@ struct CheckoutView: View {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private var customerAddressName: String {
|
private var customerAddressName: String {
|
||||||
let label = (selectedCustomerAddress?.label ?? "").trimmingCharacters(in: .whitespacesAndNewlines)
|
// appState.address.display is set directly, synchronously, the
|
||||||
if label.isEmpty == false { return label }
|
// 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)
|
let displayLabel = appState.address.display.trimmingCharacters(in: .whitespacesAndNewlines)
|
||||||
if displayLabel.isEmpty == false, displayLabel != "Defina seu endereco" { return displayLabel }
|
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"
|
return "Endereço"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user