Improve country code extraction

Use new formatting in phone number change section too
This commit is contained in:
Ilya Laktyushin
2020-08-25 19:06:24 +03:00
parent b901cdfb0d
commit 8d89ad6a38
6 changed files with 114 additions and 41 deletions

View File

@@ -152,6 +152,18 @@ private final class AuthorizationSequenceCountrySelectionNavigationContentNode:
}
}
private func removePlus(_ text: String?) -> String {
var result = ""
if let text = text {
for c in text {
if c != "+" {
result += String(c)
}
}
}
return result
}
public final class AuthorizationSequenceCountrySelectionController: ViewController {
static func countries() -> [Country] {
return countryCodes
@@ -176,6 +188,7 @@ public final class AuthorizationSequenceCountrySelectionController: ViewControll
}
public static func lookupCountryIdByNumber(_ number: String, preferredCountries: [String: String]) -> (Country, Country.CountryCode)? {
let number = removePlus(number)
var results: [(Country, Country.CountryCode)]? = nil
if number.count == 1, let preferredCountryId = preferredCountries[number], let country = lookupCountryById(preferredCountryId), let code = country.countryCodes.first {
return (country, code)