Skip to content

Commit b9ca476

Browse files
authored
Merge branch 'release/2.1.13' into fix/connect-account-scaffold
2 parents 76167f0 + 7453849 commit b9ca476

1 file changed

Lines changed: 27 additions & 4 deletions

File tree

app/src/main/java/com/getcode/view/login/PhoneVerifyViewModel.kt

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,11 @@ import com.getcode.manager.TopBarManager
1313
import com.getcode.navigation.core.CodeNavigator
1414
import com.getcode.navigation.screens.LoginPhoneConfirmationScreen
1515
import com.getcode.navigation.screens.PhoneConfirmationScreen
16+
import com.getcode.network.repository.ErrorSubmitIntent
1617
import com.getcode.network.repository.PhoneRepository
1718
import com.getcode.util.PhoneUtils
1819
import com.getcode.util.resources.ResourceHelper
20+
import com.getcode.utils.ErrorUtils
1921
import com.getcode.utils.makeE164
2022
import com.getcode.view.*
2123
import com.google.android.gms.auth.api.phone.SmsRetriever
@@ -175,7 +177,7 @@ class PhoneVerifyViewModel @Inject constructor(
175177
}
176178
.doOnComplete { setIsLoading(false) }
177179
.map { res ->
178-
when (res) {
180+
val message = when (res) {
179181
PhoneVerificationService.SendVerificationCodeResponse.Result.OK -> null
180182

181183
PhoneVerificationService.SendVerificationCodeResponse.Result.INVALID_PHONE_NUMBER,
@@ -185,12 +187,24 @@ class PhoneVerifyViewModel @Inject constructor(
185187
PhoneVerificationService.SendVerificationCodeResponse.Result.UNSUPPORTED_COUNTRY -> {
186188
getUnsupportedCountryError()
187189
}
188-
PhoneVerificationService.SendVerificationCodeResponse.Result.UNRECOGNIZED -> {
190+
PhoneVerificationService.SendVerificationCodeResponse.Result.UNRECOGNIZED,
191+
PhoneVerificationService.SendVerificationCodeResponse.Result.UNSUPPORTED_DEVICE -> {
189192
getUnsupportedDeviceError()
190193
}
191194
else -> getGenericError()
192-
}?.let { message -> TopBarManager.showMessage(message) }
193-
res == PhoneVerificationService.SendVerificationCodeResponse.Result.OK
195+
}
196+
197+
if (message != null) {
198+
TopBarManager.showMessage(message)
199+
}
200+
201+
val success = res == PhoneVerificationService.SendVerificationCodeResponse.Result.OK
202+
203+
if (!success) {
204+
ErrorUtils.handleError(PhoneVerifyException(reason = res.name))
205+
}
206+
207+
success
194208
}
195209
.concatMapSingle { isSuccess ->
196210
Single.just(isSuccess).delay(500L, TimeUnit.MILLISECONDS)
@@ -255,3 +269,12 @@ class PhoneVerifyViewModel @Inject constructor(
255269
resources.getString(R.string.error_description_countryNotSupported)
256270
)
257271
}
272+
273+
private class PhoneVerifyException(
274+
cause: Throwable? = null,
275+
val reason: String,
276+
) : Exception(cause) {
277+
override val message: String
278+
get() = "Failed to verify phone number: $reason"
279+
}
280+

0 commit comments

Comments
 (0)