Skip to content

Commit

Permalink
MBL-1760: Update 3DS snackbar with new copy and duration when user fa…
Browse files Browse the repository at this point in the history
…ils authentication (#2146)

* update 3ds copy and add duration to method

* linter

* fix tests

* linter

---------

Co-authored-by: Leigh Douglas <[email protected]>
Co-authored-by: Isabel Martin <[email protected]>
  • Loading branch information
3 people authored Oct 7, 2024
1 parent d061220 commit 0e8181e
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import androidx.activity.result.contract.ActivityResultContracts
import androidx.activity.viewModels
import androidx.appcompat.app.AppCompatActivity
import androidx.compose.foundation.lazy.rememberLazyListState
import androidx.compose.material.SnackbarDuration
import androidx.compose.material.SnackbarHostState
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
Expand Down Expand Up @@ -165,11 +166,12 @@ class PledgedProjectsOverviewActivity : AppCompatActivity() {
}
}

viewModel.provideSnackbarMessage { stringId, type ->
viewModel.provideSnackbarMessage { stringId, type, duration ->
lifecycleScope.launch {
snackbarHostState.showSnackbar(
message = getString(stringId),
actionLabel = type
actionLabel = type,
duration = duration
)
}
}
Expand Down Expand Up @@ -258,7 +260,7 @@ class PledgedProjectsOverviewActivity : AppCompatActivity() {
} else if (result.outcome == StripeIntentResult.Outcome.FAILED ||
result.outcome == StripeIntentResult.Outcome.TIMEDOUT ||
result.outcome == StripeIntentResult.Outcome.UNKNOWN
) viewModel.showErrorSnackbar(R.string.Authentication_failed_please_try_again)
) viewModel.showErrorSnackbar(R.string.We_are_unable_to_authenticate_your_payment_method_please_pull_to_refresh_and_choose_a_different_payment_method, duration = SnackbarDuration.Long)
}
override fun onError(e: Exception) {
lifecycleScope.launch {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.kickstarter.features.pledgedprojectsoverview.viewmodel

import androidx.compose.material.SnackbarDuration
import androidx.lifecycle.ViewModel
import androidx.lifecycle.ViewModelProvider
import androidx.lifecycle.viewModelScope
Expand Down Expand Up @@ -94,7 +95,7 @@ class PledgedProjectsOverviewViewModel(

private val mutablePpoCards = MutableStateFlow<PagingData<PPOCard>>(PagingData.empty())
private var mutableProjectFlow = MutableSharedFlow<Project>()
private var snackbarMessage: (stringID: Int, type: String) -> Unit = { _, _ -> }
private var snackbarMessage: (stringID: Int, type: String, duration: SnackbarDuration) -> Unit = { _, _, _ -> }
private val apolloClient = requireNotNull(environment.apolloClientV2())
private val analyticEvents = requireNotNull(environment.analytics())

Expand Down Expand Up @@ -201,7 +202,7 @@ class PledgedProjectsOverviewViewModel(
}
}

fun provideSnackbarMessage(snackBarMessage: (Int, String) -> Unit) {
fun provideSnackbarMessage(snackBarMessage: (Int, String, SnackbarDuration) -> Unit) {
this.snackbarMessage = snackBarMessage
}

Expand All @@ -218,12 +219,12 @@ class PledgedProjectsOverviewViewModel(
)
}

fun showHeadsUpSnackbar(messageId: Int) {
snackbarMessage.invoke(messageId, KSSnackbarTypes.KS_HEADS_UP.name)
fun showHeadsUpSnackbar(messageId: Int, duration: SnackbarDuration = SnackbarDuration.Short) {
snackbarMessage.invoke(messageId, KSSnackbarTypes.KS_HEADS_UP.name, duration)
}

fun showErrorSnackbar(messageId: Int) {
snackbarMessage.invoke(messageId, KSSnackbarTypes.KS_ERROR.name)
fun showErrorSnackbar(messageId: Int, duration: SnackbarDuration = SnackbarDuration.Short) {
snackbarMessage.invoke(messageId, KSSnackbarTypes.KS_ERROR.name, duration)
}

class Factory(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ class PledgedProjectsOverviewViewModelTest : KSRobolectricTestCase() {
}).build()
).create(PledgedProjectsOverviewViewModel::class.java)

viewModel.provideSnackbarMessage { message, _ -> snackbarAction = message }
viewModel.provideSnackbarMessage { message, _, _ -> snackbarAction = message }
viewModel.onMessageCreatorClicked("test_project_slug", "projectID", "creatorID", listOf(PPOCardFactory.confirmAddressCard()), 10)

// Should equal error string id
Expand Down Expand Up @@ -106,7 +106,7 @@ class PledgedProjectsOverviewViewModelTest : KSRobolectricTestCase() {
viewModel.ppoUIState.toList(uiState)
}

viewModel.provideSnackbarMessage { message, _ -> snackbarAction = message }
viewModel.provideSnackbarMessage { message, _, _ -> snackbarAction = message }
viewModel.confirmAddress("addressID", "backingID")

assertEquals(
Expand Down Expand Up @@ -143,7 +143,7 @@ class PledgedProjectsOverviewViewModelTest : KSRobolectricTestCase() {
viewModel.ppoUIState.toList(uiState)
}

viewModel.provideSnackbarMessage { message, _ -> snackbarAction = message }
viewModel.provideSnackbarMessage { message, _, _ -> snackbarAction = message }
viewModel.confirmAddress("addressID", "backingID")

assertEquals(
Expand Down Expand Up @@ -178,7 +178,7 @@ class PledgedProjectsOverviewViewModelTest : KSRobolectricTestCase() {
backgroundScope.launch(UnconfinedTestDispatcher(testScheduler)) {
viewModel.ppoUIState.toList(uiState)
}
viewModel.provideSnackbarMessage { message, _ -> snackbarAction = message }
viewModel.provideSnackbarMessage { message, _, _ -> snackbarAction = message }
viewModel.confirmAddress("addressID", "backingID")

assertEquals(
Expand Down

0 comments on commit 0e8181e

Please sign in to comment.