Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(82)

Unified Diff: ios/chrome/browser/ui/payments/address_edit_mediator.mm

Issue 2950843002: [Payment Request] Populates region field if region code/name is valid. (Closed)
Patch Set: Addressed comment Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: ios/chrome/browser/ui/payments/address_edit_mediator.mm
diff --git a/ios/chrome/browser/ui/payments/address_edit_mediator.mm b/ios/chrome/browser/ui/payments/address_edit_mediator.mm
index 568608fb8338ecb9c4b46d5c49626704c24134e4..19a2834e4a32e8cc85f4f058409c3fe70d4a16d5 100644
--- a/ios/chrome/browser/ui/payments/address_edit_mediator.mm
+++ b/ios/chrome/browser/ui/payments/address_edit_mediator.mm
@@ -10,6 +10,7 @@
#include <utility>
#include "base/callback.h"
+#include "base/logging.h"
#include "base/memory/ptr_util.h"
#include "base/strings/sys_string_conversions.h"
#include "base/values.h"
@@ -68,7 +69,6 @@
@synthesize consumer = _consumer;
@synthesize countries = _countries;
@synthesize selectedCountryCode = _selectedCountryCode;
-@synthesize regions = _regions;
@synthesize paymentRequest = _paymentRequest;
@synthesize address = _address;
@synthesize fieldsMap = _fieldsMap;
@@ -126,28 +126,32 @@
#pragma mark - RegionDataLoaderConsumer
- (void)regionDataLoaderDidSucceedWithRegions:
- (NSMutableArray<NSString*>*)regions {
- self.regions = regions;
+ (NSDictionary<NSString*, NSString*>*)regions {
// Enable the previously disabled field.
self.regionField.enabled = YES;
- // If an address is being edited and it has a valid region, the field value is
- // set to that region. Otherwise, set the field value to nil. If creating an
- // address, set the first available region as the field value, if possible.
+ // An autofill profile may have a region code or a region name stored as the
+ // autofill::ADDRESS_HOME_STATE. If an address is being edited whose value for
+ // that field type is a valid region code or a valid region name, the editor
+ // field value is set to the respective region code. Otherwise, it is set to
+ // nil.
+ self.regionField.value = nil;
if (self.address) {
NSString* region =
[self fieldValueFromProfile:self.address
fieldType:autofill::ADDRESS_HOME_STATE];
- self.regionField.value =
- [self.regions containsObject:region] ? region : nil;
- } else {
- self.regionField.value = regions.count ? regions[0] : nil;
+ if ([regions objectForKey:region]) {
+ self.regionField.value = region;
+ } else if ([[regions allKeysForObject:region] count]) {
+ DCHECK(1 == [[regions allKeysForObject:region] count]);
+ self.regionField.value = [regions allKeysForObject:region][0];
+ }
}
// Notify the view controller asynchronously to allow for the view to update.
__weak AddressEditMediator* weakSelf = self;
dispatch_async(dispatch_get_main_queue(), ^{
- [weakSelf.consumer setOptions:weakSelf.regions
+ [weakSelf.consumer setOptions:[regions allKeys]
forEditorField:weakSelf.regionField];
});
}
« no previous file with comments | « ios/chrome/browser/ui/payments/address_edit_mediator.h ('k') | ios/chrome/browser/ui/payments/region_data_loader.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698