Updated on 2026-08-14
This commit is contained in:
parent
5dd8e68a8d
commit
c2876c2fed
2 changed files with 14 additions and 16 deletions
|
|
@ -2,17 +2,24 @@ package com.tangem.tap.domain.tasks
|
|||
|
||||
import com.tangem.CardSession
|
||||
import com.tangem.CardSessionRunnable
|
||||
import com.tangem.commands.CreateWalletCommand
|
||||
import com.tangem.commands.ReadCommand
|
||||
import com.tangem.common.CompletionResult
|
||||
import com.tangem.tasks.CreateWalletTask
|
||||
|
||||
class CreateWalletAndRescanTask : CardSessionRunnable<ScanNoteResponse> {
|
||||
override val requiresPin2 = false
|
||||
|
||||
override fun run(session: CardSession, callback: (result: CompletionResult<ScanNoteResponse>) -> Unit) {
|
||||
CreateWalletCommand().run(session) { result ->
|
||||
CreateWalletTask().run(session) { result ->
|
||||
when (result) {
|
||||
is CompletionResult.Success -> ScanNoteTask().run(session, callback)
|
||||
|
||||
is CompletionResult.Success -> {
|
||||
ReadCommand().run(session) { readResult ->
|
||||
when (readResult) {
|
||||
is CompletionResult.Success -> ScanNoteTask(readResult.data).run(session, callback)
|
||||
is CompletionResult.Failure -> callback(CompletionResult.Failure(readResult.error))
|
||||
}
|
||||
}
|
||||
}
|
||||
is CompletionResult.Failure -> callback(CompletionResult.Failure(result.error))
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ data class ScanNoteResponse(
|
|||
val verifyResponse: VerifyCardResponse? = null
|
||||
) : CommandResponse
|
||||
|
||||
class ScanNoteTask : CardSessionRunnable<ScanNoteResponse> {
|
||||
class ScanNoteTask(val card: Card? = null) : CardSessionRunnable<ScanNoteResponse> {
|
||||
override val requiresPin2 = false
|
||||
|
||||
override fun run(session: CardSession, callback: (result: CompletionResult<ScanNoteResponse>) -> Unit) {
|
||||
|
|
@ -27,7 +27,8 @@ class ScanNoteTask : CardSessionRunnable<ScanNoteResponse> {
|
|||
is CompletionResult.Failure -> callback(CompletionResult.Failure(result.error))
|
||||
|
||||
is CompletionResult.Success -> {
|
||||
val card = result.data
|
||||
val card = this.card ?: result.data
|
||||
|
||||
val walletManager = try {
|
||||
WalletManagerFactory.makeWalletManager(card)
|
||||
} catch (exception: Exception) {
|
||||
|
|
@ -49,14 +50,4 @@ class ScanNoteTask : CardSessionRunnable<ScanNoteResponse> {
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun Card?.toScanNoteCompletionResult(): CompletionResult<ScanNoteResponse> {
|
||||
this ?: return CompletionResult.Failure(TangemSdkError.CardError())
|
||||
val walletManager = try {
|
||||
WalletManagerFactory.makeWalletManager(this)
|
||||
} catch (exception: Exception) {
|
||||
return CompletionResult.Success(ScanNoteResponse(null, this))
|
||||
}
|
||||
return CompletionResult.Success(ScanNoteResponse(walletManager, this))
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue