Skip to content

Commit a719dcd

Browse files
committed
fix(verification): differentiate between notifiable errors and alerts
Signed-off-by: Brandon McAnsh <git@bmcreations.dev>
1 parent 8270dbd commit a719dcd

1 file changed

Lines changed: 21 additions & 10 deletions

File tree

apps/flipcash/features/contact-verification/src/main/kotlin/com/flipcash/app/contact/verification/internal/phone/PhoneVerificationViewModel.kt

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import com.flipcash.services.user.UserManager
1717
import com.flipcash.services.models.PhoneVerificationError
1818
import com.getcode.manager.BottomBarManager
1919
import com.getcode.util.resources.ResourceHelper
20+
import com.getcode.utils.NotifiableError
2021
import com.getcode.utils.TraceType
2122
import com.getcode.utils.trace
2223
import com.getcode.view.BaseViewModel
@@ -204,25 +205,35 @@ internal class PhoneVerificationViewModel @Inject constructor(
204205
dispatchEvent(Event.OnVerifyingCodeChanged())
205206
}
206207
},
207-
onError = {
208-
trace(message = "Code verification failed: $it", type = TraceType.Error)
208+
onError = { cause ->
209+
trace(message = "Code verification failed: $cause", type = TraceType.Error)
209210
dispatchEvent(Event.OnVerifyingCodeChanged())
210-
val (title, message) = when (it) {
211-
is PhoneVerificationError -> when (it) {
211+
val (title, message) = when (cause) {
212+
is PhoneVerificationError -> when (cause) {
212213
is PhoneVerificationError.Denied -> "Something went wrong" to "You have already sent a verification code"
213214
is PhoneVerificationError.InvalidVerificationCode -> "Something went wrong" to resources.getString(R.string.error_description_invalidVerificationCode)
214215
is PhoneVerificationError.NoVerification -> "Something went wrong" to resources.getString(R.string.error_description_codeTimedOut)
215216
is PhoneVerificationError.RateLimited -> "Something went wrong" to "Too many requests"
216217
is PhoneVerificationError.UnsupportedPhoneType -> resources.getString(R.string.error_title_deviceNotSupported) to resources.getString(R.string.error_description_deviceNotSupported)
217-
else -> null to null
218+
is PhoneVerificationError.InvalidPhoneNumber -> resources.getString(R.string.error_title_failedToSendCodeToPhone) to resources.getString(R.string.error_description_failedToSendCodeToPhone)
219+
is PhoneVerificationError.Other -> resources.getString(R.string.error_title_failedToSendCodeToPhone) to resources.getString(R.string.error_description_failedToSendCodeToPhone)
220+
is PhoneVerificationError.Unrecognized -> resources.getString(R.string.error_title_failedToSendCodeToPhone) to resources.getString(R.string.error_description_failedToSendCodeToPhone)
218221
}
219-
else -> null to null
222+
else -> resources.getString(R.string.error_title_failedToSendCodeToPhone) to resources.getString(R.string.error_description_failedToSendCodeToPhone)
220223
}
221224

222-
BottomBarManager.showError(
223-
title = title ?: resources.getString(R.string.error_title_failedToSendCodeToPhone),
224-
message = message ?: resources.getString(R.string.error_description_failedToSendCodeToPhone),
225-
)
225+
val isError = cause is NotifiableError
226+
if (isError) {
227+
BottomBarManager.showError(
228+
title = title,
229+
message = message,
230+
)
231+
} else {
232+
BottomBarManager.showAlert(
233+
title = title,
234+
message = message,
235+
)
236+
}
226237
}
227238
).launchIn(viewModelScope)
228239

0 commit comments

Comments
 (0)