Skip to content

Commit bca89e6

Browse files
committed
feat(feature:send-money): format phone numbers in pay anyone
1 parent c2c5fe1 commit bca89e6

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

feature/send-money/src/androidMain/kotlin/org/mifospay/feature/send/money/ContactRepository.android.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,10 @@ class AndroidContactRepository(
3131
}
3232

3333
override suspend fun searchContacts(query: String): List<Contact> {
34+
val normalizedQuery = PhoneNumberUtils.normalizeSearchQuery(query)
35+
// Search by name (contains) and phone number (starts with normalized query)
3436
val selection = "${ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME} LIKE ? OR ${ContactsContract.CommonDataKinds.Phone.NUMBER} LIKE ?"
35-
val selectionArgs = arrayOf("%$query%", "%$query%")
37+
val selectionArgs = arrayOf("%$query%", "$normalizedQuery%")
3638
val rawContacts = queryContacts(selection, selectionArgs)
3739
return PhoneNumberUtils.filterAndFormatContacts(rawContacts)
3840
}

feature/send-money/src/commonMain/kotlin/org/mifospay/feature/send/money/PhoneNumberUtils.kt

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,4 +159,32 @@ object PhoneNumberUtils {
159159
}
160160
.distinctBy { contact -> contact.phoneNumber }
161161
}
162+
163+
/**
164+
* Normalizes a phone number for search purposes by removing country code and spaces
165+
* This allows searching with or without +91 prefix
166+
*/
167+
fun normalizePhoneNumberForSearch(phoneNumber: String): String {
168+
return phoneNumber
169+
.replace("+91", "")
170+
.replace(" ", "")
171+
.replace("-", "")
172+
.replace("(", "")
173+
.replace(")", "")
174+
.trim()
175+
}
176+
177+
/**
178+
* Normalizes a search query for phone number matching
179+
* Removes +91 prefix and spaces to match against normalized phone numbers
180+
*/
181+
fun normalizeSearchQuery(query: String): String {
182+
return query
183+
.replace("+91", "")
184+
.replace(" ", "")
185+
.replace("-", "")
186+
.replace("(", "")
187+
.replace(")", "")
188+
.trim()
189+
}
162190
}

0 commit comments

Comments
 (0)