Updated on 2026-08-14
This commit is contained in:
commit
6dbe6359dd
5 changed files with 50 additions and 33 deletions
|
|
@ -32,6 +32,7 @@ internal class DefaultScanCardProcessor : ScanCardProcessor {
|
||||||
onProgressStateChange: suspend (showProgress: Boolean) -> Unit,
|
onProgressStateChange: suspend (showProgress: Boolean) -> Unit,
|
||||||
onWalletNotCreated: suspend () -> Unit,
|
onWalletNotCreated: suspend () -> Unit,
|
||||||
disclaimerWillShow: () -> Unit,
|
disclaimerWillShow: () -> Unit,
|
||||||
|
onCancel: suspend () -> Unit,
|
||||||
onFailure: suspend (error: TangemError) -> Unit,
|
onFailure: suspend (error: TangemError) -> Unit,
|
||||||
onSuccess: suspend (scanResponse: ScanResponse) -> Unit,
|
onSuccess: suspend (scanResponse: ScanResponse) -> Unit,
|
||||||
) {
|
) {
|
||||||
|
|
@ -52,6 +53,7 @@ internal class DefaultScanCardProcessor : ScanCardProcessor {
|
||||||
onProgressStateChange,
|
onProgressStateChange,
|
||||||
onWalletNotCreated,
|
onWalletNotCreated,
|
||||||
disclaimerWillShow,
|
disclaimerWillShow,
|
||||||
|
onCancel,
|
||||||
onFailure,
|
onFailure,
|
||||||
onSuccess,
|
onSuccess,
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -57,6 +57,7 @@ internal object LegacyScanProcessor {
|
||||||
onProgressStateChange: suspend (showProgress: Boolean) -> Unit,
|
onProgressStateChange: suspend (showProgress: Boolean) -> Unit,
|
||||||
onWalletNotCreated: suspend () -> Unit,
|
onWalletNotCreated: suspend () -> Unit,
|
||||||
disclaimerWillShow: () -> Unit,
|
disclaimerWillShow: () -> Unit,
|
||||||
|
onCancel: suspend () -> Unit,
|
||||||
onFailure: suspend (error: TangemError) -> Unit,
|
onFailure: suspend (error: TangemError) -> Unit,
|
||||||
onSuccess: suspend (scanResponse: ScanResponse) -> Unit,
|
onSuccess: suspend (scanResponse: ScanResponse) -> Unit,
|
||||||
) = withMainContext {
|
) = withMainContext {
|
||||||
|
|
@ -88,6 +89,7 @@ internal object LegacyScanProcessor {
|
||||||
onProgressStateChange = onProgressStateChange,
|
onProgressStateChange = onProgressStateChange,
|
||||||
onSuccess = onSuccess,
|
onSuccess = onSuccess,
|
||||||
onWalletNotCreated = onWalletNotCreated,
|
onWalletNotCreated = onWalletNotCreated,
|
||||||
|
onCancel = onCancel,
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
@ -138,13 +140,19 @@ internal object LegacyScanProcessor {
|
||||||
scanResponse: ScanResponse,
|
scanResponse: ScanResponse,
|
||||||
crossinline onProgressStateChange: suspend (showProgress: Boolean) -> Unit,
|
crossinline onProgressStateChange: suspend (showProgress: Boolean) -> Unit,
|
||||||
crossinline onWalletNotCreated: suspend () -> Unit,
|
crossinline onWalletNotCreated: suspend () -> Unit,
|
||||||
|
crossinline onCancel: suspend () -> Unit,
|
||||||
crossinline onSuccess: suspend (ScanResponse) -> Unit,
|
crossinline onSuccess: suspend (ScanResponse) -> Unit,
|
||||||
) {
|
) {
|
||||||
store.dispatchOnMain(TwinCardsAction.IfTwinsPrepareState(scanResponse))
|
store.dispatchOnMain(TwinCardsAction.IfTwinsPrepareState(scanResponse))
|
||||||
|
|
||||||
checkCardWasUsedInApp(
|
checkCardWasUsedInApp(
|
||||||
scanResponse = scanResponse,
|
scanResponse = scanResponse,
|
||||||
onCancel = { mainScope.launch { onProgressStateChange.invoke(false) } },
|
onCancel = {
|
||||||
|
mainScope.launch {
|
||||||
|
onProgressStateChange.invoke(false)
|
||||||
|
onCancel()
|
||||||
|
}
|
||||||
|
},
|
||||||
) {
|
) {
|
||||||
if (OnboardingHelper.isOnboardingCase(scanResponse)) {
|
if (OnboardingHelper.isOnboardingCase(scanResponse)) {
|
||||||
Analytics.addContext(scanResponse)
|
Analytics.addContext(scanResponse)
|
||||||
|
|
|
||||||
|
|
@ -18,6 +18,7 @@ interface ScanCardProcessor {
|
||||||
onProgressStateChange: suspend (showProgress: Boolean) -> Unit = {},
|
onProgressStateChange: suspend (showProgress: Boolean) -> Unit = {},
|
||||||
onWalletNotCreated: suspend () -> Unit = {},
|
onWalletNotCreated: suspend () -> Unit = {},
|
||||||
disclaimerWillShow: () -> Unit = {},
|
disclaimerWillShow: () -> Unit = {},
|
||||||
|
onCancel: suspend () -> Unit = {},
|
||||||
onFailure: suspend (error: TangemError) -> Unit = {},
|
onFailure: suspend (error: TangemError) -> Unit = {},
|
||||||
onSuccess: suspend (scanResponse: ScanResponse) -> Unit = {},
|
onSuccess: suspend (scanResponse: ScanResponse) -> Unit = {},
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -64,6 +64,6 @@ internal class UserWalletListModel @Inject constructor(
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun addUserWallet() = withProgress(isWalletSavingInProgress) {
|
private fun addUserWallet() = withProgress(isWalletSavingInProgress) {
|
||||||
userWalletSaver.scanAndSaveUserWallet()
|
userWalletSaver.scanAndSaveUserWallet(modelScope)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -28,7 +28,11 @@ import com.tangem.domain.wallets.usecase.GenerateWalletNameUseCase
|
||||||
import com.tangem.domain.wallets.usecase.SaveWalletUseCase
|
import com.tangem.domain.wallets.usecase.SaveWalletUseCase
|
||||||
import com.tangem.domain.wallets.usecase.ShouldSaveUserWalletsSyncUseCase
|
import com.tangem.domain.wallets.usecase.ShouldSaveUserWalletsSyncUseCase
|
||||||
import com.tangem.features.details.impl.R
|
import com.tangem.features.details.impl.R
|
||||||
|
import kotlinx.coroutines.CoroutineScope
|
||||||
|
import kotlinx.coroutines.launch
|
||||||
|
import kotlinx.coroutines.suspendCancellableCoroutine
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
import kotlin.coroutines.resume
|
||||||
|
|
||||||
@ComponentScoped
|
@ComponentScoped
|
||||||
@Suppress("LongParameterList")
|
@Suppress("LongParameterList")
|
||||||
|
|
@ -42,9 +46,9 @@ internal class UserWalletSaver @Inject constructor(
|
||||||
private val router: Router,
|
private val router: Router,
|
||||||
) {
|
) {
|
||||||
|
|
||||||
suspend fun scanAndSaveUserWallet() = recover(
|
suspend fun scanAndSaveUserWallet(scope: CoroutineScope) = recover(
|
||||||
block = {
|
block = {
|
||||||
val response = scanCard() ?: return@recover
|
val response = scanCard(scope) ?: return@recover
|
||||||
val userWallet = createUserWallet(response)
|
val userWallet = createUserWallet(response)
|
||||||
|
|
||||||
saveWallet(userWallet)
|
saveWallet(userWallet)
|
||||||
|
|
@ -105,36 +109,38 @@ internal class UserWalletSaver @Inject constructor(
|
||||||
return ensureNotNull(userWallet) { Error.Unknown }
|
return ensureNotNull(userWallet) { Error.Unknown }
|
||||||
}
|
}
|
||||||
|
|
||||||
private suspend fun Raise<Error>.scanCard(): ScanResponse? {
|
private suspend fun Raise<Error>.scanCard(scope: CoroutineScope) = suspendCancellableCoroutine { continuation ->
|
||||||
var response: ScanResponse? = null
|
scope.launch {
|
||||||
|
scanCardProcessor.scan(
|
||||||
|
analyticsSource = AnalyticsParam.ScreensSources.Settings,
|
||||||
|
onWalletNotCreated = {
|
||||||
|
/* no-op */
|
||||||
|
},
|
||||||
|
disclaimerWillShow = {
|
||||||
|
continuation.resume(null)
|
||||||
|
router.pop()
|
||||||
|
},
|
||||||
|
onSuccess = {
|
||||||
|
continuation.resume(it)
|
||||||
|
},
|
||||||
|
onCancel = {
|
||||||
|
continuation.resume(null)
|
||||||
|
},
|
||||||
|
onFailure = { tangemError ->
|
||||||
|
val error = if (!tangemError.silent) {
|
||||||
|
val message = tangemError.messageResId
|
||||||
|
?.let(::resourceReference)
|
||||||
|
?: stringReference(tangemError.customMessage)
|
||||||
|
|
||||||
scanCardProcessor.scan(
|
Error.Message(message)
|
||||||
analyticsSource = AnalyticsParam.ScreensSources.Settings,
|
} else {
|
||||||
onWalletNotCreated = {
|
Error.Silent
|
||||||
/* no-op */
|
}
|
||||||
},
|
continuation.resume(null)
|
||||||
disclaimerWillShow = {
|
raise(error)
|
||||||
router.pop()
|
},
|
||||||
},
|
)
|
||||||
onSuccess = {
|
}
|
||||||
response = it
|
|
||||||
},
|
|
||||||
onFailure = { tangemError ->
|
|
||||||
val error = if (!tangemError.silent) {
|
|
||||||
val message = tangemError.messageResId
|
|
||||||
?.let(::resourceReference)
|
|
||||||
?: stringReference(tangemError.customMessage)
|
|
||||||
|
|
||||||
Error.Message(message)
|
|
||||||
} else {
|
|
||||||
Error.Silent
|
|
||||||
}
|
|
||||||
|
|
||||||
raise(error)
|
|
||||||
},
|
|
||||||
)
|
|
||||||
|
|
||||||
return response
|
|
||||||
}
|
}
|
||||||
|
|
||||||
sealed class Error {
|
sealed class Error {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue