Updated on 2026-08-14
This commit is contained in:
parent
a0834799ea
commit
263ee55122
28 changed files with 114 additions and 59 deletions
1
domain/qr-scanning/.gitignore
vendored
Normal file
1
domain/qr-scanning/.gitignore
vendored
Normal file
|
|
@ -0,0 +1 @@
|
|||
/build
|
||||
13
domain/qr-scanning/build.gradle.kts
Normal file
13
domain/qr-scanning/build.gradle.kts
Normal 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
1
domain/qr-scanning/models/.gitignore
vendored
Normal file
|
|
@ -0,0 +1 @@
|
|||
/build
|
||||
4
domain/qr-scanning/models/build.gradle.kts
Normal file
4
domain/qr-scanning/models/build.gradle.kts
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
plugins {
|
||||
alias(deps.plugins.kotlin.jvm)
|
||||
id("configuration")
|
||||
}
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
package com.tangem.domain.qrscanning.models
|
||||
|
||||
enum class SourceType {
|
||||
WALLET_CONNECT,
|
||||
SEND,
|
||||
}
|
||||
|
|
@ -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>
|
||||
}
|
||||
|
|
@ -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()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -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()
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue