From 11b2afed481f49951f7aa91c147d4b2b3fb41aa2 Mon Sep 17 00:00:00 2001 From: Brandon McAnsh Date: Mon, 15 Jun 2026 17:02:21 -0400 Subject: [PATCH] fix: add missing PhoneUtil for extract i18n numbers Signed-off-by: Brandon McAnsh --- .../com/flipcash/app/phone/PhoneUtils.kt | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/apps/flipcash/shared/phone/src/main/kotlin/com/flipcash/app/phone/PhoneUtils.kt b/apps/flipcash/shared/phone/src/main/kotlin/com/flipcash/app/phone/PhoneUtils.kt index d3a70b75b..d92820f76 100644 --- a/apps/flipcash/shared/phone/src/main/kotlin/com/flipcash/app/phone/PhoneUtils.kt +++ b/apps/flipcash/shared/phone/src/main/kotlin/com/flipcash/app/phone/PhoneUtils.kt @@ -129,6 +129,27 @@ class PhoneUtils @Inject constructor( } } + /** + * Parse an international phone number (e.g. "+15551234567") into its country locale + * and national number digits. Returns null if parsing fails. + */ + fun parseInternationalNumber(number: String): Pair? { + val cleaned = number.filter { it.isDigit() || it == '+' } + if (cleaned.isBlank() || !cleaned.startsWith("+")) return null + + return try { + val parsed = phoneNumberUtil.parse(cleaned, defaultCountryLocale.countryCode) + if (!phoneNumberUtil.isValidNumber(parsed)) return null + + val regionCode = phoneNumberUtil.getRegionCodeForNumber(parsed) ?: return null + val locale = countryLocales.find { it.countryCode == regionCode } ?: return null + val nationalNumber = parsed.nationalNumber.toString() + locale to nationalNumber + } catch (_: NumberParseException) { + null + } + } + fun toE164(rawNumber: String): String? { val cleaned = rawNumber.filter { it.isDigit() || it == '+' } if (cleaned.isBlank()) return null