Updated on 2026-08-14

This commit is contained in:
Tangem 2020-12-18 10:29:23 +00:00
commit a09f60a6a7
5 changed files with 52 additions and 15 deletions

View file

@ -0,0 +1,31 @@
package com.tangem.tap.domain.twins
import com.tangem.CardSession
import com.tangem.CardSessionRunnable
import com.tangem.KeyPair
import com.tangem.commands.ReadCommand
import com.tangem.common.CompletionResult
import com.tangem.tap.domain.tasks.ScanNoteResponse
import com.tangem.tap.domain.tasks.ScanNoteTask
class FinalizeTwinTask(
private val twinPublicKey: ByteArray, private val issuerKeys: KeyPair
) : CardSessionRunnable<ScanNoteResponse> {
override val requiresPin2 = true
override fun run(session: CardSession, callback: (result: CompletionResult<ScanNoteResponse>) -> Unit) {
WriteProtectedIssuerDataTask(twinPublicKey, issuerKeys).run(session) { result ->
when (result) {
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))
}
}
}
}

View file

@ -2,7 +2,6 @@ package com.tangem.tap.domain.twins
import com.tangem.KeyPair
import com.tangem.Message
import com.tangem.blockchain.common.WalletManagerFactory
import com.tangem.blockchain.extensions.Result
import com.tangem.blockchain.extensions.SimpleResult
import com.tangem.common.CompletionResult
@ -51,19 +50,11 @@ class TwinCardsManager(private val scanNoteResponse: ScanNoteResponse) {
suspend fun complete(message: Message): Result<ScanNoteResponse> {
val response = tangemSdkManager.runTaskAsync(
WriteProtectedIssuerDataTask(secondCardPublicKey!!.hexToBytes(), issuerKeys),
FinalizeTwinTask(secondCardPublicKey!!.hexToBytes(), issuerKeys),
currentCardId, message
)
return when (response) {
is CompletionResult.Success -> {
val walletManager = WalletManagerFactory.makeMultisigWalletManager(
scanNoteResponse.card, secondCardPublicKey!!.hexToBytes()
)
return Result.Success(scanNoteResponse.copy(
walletManager = walletManager,
secondTwinPublicKey = secondCardPublicKey
))
}
is CompletionResult.Success -> Result.Success(response.data)
is CompletionResult.Failure -> Result.failure(response.error)
}
}

View file

@ -46,6 +46,9 @@ sealed class DetailsAction : Action {
sealed class CreateTwinWalletAction : DetailsAction() {
object ShowWarning : CreateTwinWalletAction()
object NotEmpty : CreateTwinWalletAction(), NotificationAction {
override val messageResource = R.string.details_notification_erase_wallet_not_possible
}
object ShowAlert : CreateTwinWalletAction()
object HideAlert : CreateTwinWalletAction()
data class Proceed(

View file

@ -2,9 +2,9 @@ package com.tangem.tap.features.details.redux.twins
import com.tangem.blockchain.extensions.Result
import com.tangem.blockchain.extensions.SimpleResult
import com.tangem.tap.common.redux.global.GlobalAction
import com.tangem.tap.common.redux.navigation.AppScreen
import com.tangem.tap.common.redux.navigation.NavigationAction
import com.tangem.tap.domain.extensions.toSendableAmounts
import com.tangem.tap.domain.twins.TwinCardsManager
import com.tangem.tap.features.details.redux.DetailsAction
import com.tangem.tap.scope
@ -17,8 +17,16 @@ class CreateTwinWalletMiddleware {
var twinsManager: TwinCardsManager? = null
fun handle(action: DetailsAction.CreateTwinWalletAction) {
when (action) {
DetailsAction.CreateTwinWalletAction.ShowWarning ->
store.dispatch(NavigationAction.NavigateTo(AppScreen.CreateTwinWalletWarning))
DetailsAction.CreateTwinWalletAction.ShowWarning -> {
val wallet = store.state.detailsState.wallet
val notEmpty = wallet?.recentTransactions?.isNullOrEmpty() != true ||
wallet.amounts.toSendableAmounts().isNotEmpty()
if (notEmpty) {
store.dispatch(DetailsAction.CreateTwinWalletAction.NotEmpty)
} else {
store.dispatch(NavigationAction.NavigateTo(AppScreen.CreateTwinWalletWarning))
}
}
is DetailsAction.CreateTwinWalletAction.Proceed ->
store.dispatch(NavigationAction.NavigateTo(AppScreen.CreateTwinWallet))
is DetailsAction.CreateTwinWalletAction.Cancel -> {
@ -93,8 +101,11 @@ class CreateTwinWalletMiddleware {
}
}
is DetailsAction.CreateTwinWalletAction.LaunchThirdStep.Success -> {
store.dispatch(GlobalAction.SaveScanNoteResponse(action.scanNoteResponse))
scope.launch {
store.state.globalState.tapWalletManager.onCardScanned(action.scanNoteResponse)
}
store.dispatch(NavigationAction.PopBackTo(AppScreen.Home))
store.dispatch(NavigationAction.NavigateTo(AppScreen.Wallet))
}
DetailsAction.CreateTwinWalletAction.LaunchThirdStep.Failure -> {

View file

@ -12,6 +12,7 @@ class CreateTwinWalletReducer {
DetailsAction.CreateTwinWalletAction.ShowWarning -> {
state
}
DetailsAction.CreateTwinWalletAction.NotEmpty -> state
DetailsAction.CreateTwinWalletAction.ShowAlert -> {
state.copy(createTwinWalletState = state.createTwinWalletState?.copy(
showAlert = true