Updated on 2026-08-14

This commit is contained in:
Tangem 2024-03-13 21:48:15 +05:00
parent a0834799ea
commit 263ee55122
28 changed files with 114 additions and 59 deletions

1
domain/qr-scanning/.gitignore vendored Normal file
View file

@ -0,0 +1 @@
/build

View file

@ -0,0 +1,13 @@
plugins {
alias(deps.plugins.kotlin.jvm)
id("configuration")
}
dependencies {
/** Domain */
implementation(projects.domain.qrScanning.models)
implementation(deps.kotlin.coroutines)
implementation(deps.arrow.core)
}

1
domain/qr-scanning/models/.gitignore vendored Normal file
View file

@ -0,0 +1 @@
/build

View file

@ -0,0 +1,4 @@
plugins {
alias(deps.plugins.kotlin.jvm)
id("configuration")
}

View file

@ -0,0 +1,6 @@
package com.tangem.domain.qrscanning.models
enum class SourceType {
WALLET_CONNECT,
SEND,
}

View file

@ -0,0 +1,11 @@
package com.tangem.domain.qrscanning.repository
import com.tangem.domain.qrscanning.models.SourceType
import kotlinx.coroutines.flow.Flow
interface QrScanningEventsRepository {
suspend fun emitResult(type: SourceType, qrCode: String)
fun subscribeToScanningResults(type: SourceType): Flow<String>
}

View file

@ -0,0 +1,20 @@
package com.tangem.domain.qrscanning.usecases
import arrow.core.Either
import arrow.core.left
import arrow.core.right
import com.tangem.domain.qrscanning.models.SourceType
import com.tangem.domain.qrscanning.repository.QrScanningEventsRepository
class EmitQrScannedEventUseCase(
private val repository: QrScanningEventsRepository,
) {
suspend operator fun invoke(type: SourceType, qrCode: String): Either<Exception, Unit> {
return try {
repository.emitResult(type, qrCode)
Unit.right()
} catch (e: Exception) {
e.left()
}
}
}

View file

@ -0,0 +1,21 @@
package com.tangem.domain.qrscanning.usecases
import arrow.core.Either
import arrow.core.left
import arrow.core.right
import com.tangem.domain.qrscanning.models.SourceType
import com.tangem.domain.qrscanning.repository.QrScanningEventsRepository
import kotlinx.coroutines.flow.Flow
class ListenToQrScanningUseCase(
val repository: QrScanningEventsRepository,
) {
operator fun invoke(type: SourceType): Either<Exception, Flow<String>> {
return try {
repository.subscribeToScanningResults(type).right()
} catch (e: Exception) {
e.left()
}
}
}