diff --git a/data/account/src/main/kotlin/com/tangem/data/account/converter/AccountConvertersExt.kt b/data/account/src/main/kotlin/com/tangem/data/account/converter/AccountConvertersExt.kt index 3d35e7327c..312e189d67 100644 --- a/data/account/src/main/kotlin/com/tangem/data/account/converter/AccountConvertersExt.kt +++ b/data/account/src/main/kotlin/com/tangem/data/account/converter/AccountConvertersExt.kt @@ -1,6 +1,7 @@ package com.tangem.data.account.converter import arrow.core.getOrElse +import arrow.core.right import com.tangem.datasource.api.tangemTech.models.account.WalletAccountDTO import com.tangem.domain.models.account.AccountId import com.tangem.domain.models.account.CryptoPortfolioIcon @@ -8,7 +9,10 @@ import com.tangem.domain.models.account.DerivationIndex import com.tangem.domain.models.wallet.UserWalletId internal fun String.toAccountId(userWalletId: UserWalletId): AccountId { - return AccountId.forCryptoPortfolio(value = this, userWalletId = userWalletId).getOrElse { + return when { + startsWith(AccountId.PaymentAccountIdPrefix) -> AccountId.forPaymentAccount(userWalletId).right() + else -> AccountId.forCryptoPortfolio(value = this, userWalletId = userWalletId) + }.getOrElse { error("Unable to create AccountId from value: $this. Cause: $it") } } diff --git a/domain/models/src/main/kotlin/com/tangem/domain/models/account/AccountId.kt b/domain/models/src/main/kotlin/com/tangem/domain/models/account/AccountId.kt index 0c65375595..d4c73a73ef 100644 --- a/domain/models/src/main/kotlin/com/tangem/domain/models/account/AccountId.kt +++ b/domain/models/src/main/kotlin/com/tangem/domain/models/account/AccountId.kt @@ -37,6 +37,8 @@ data class AccountId private constructor( companion object { + const val PaymentAccountIdPrefix = "payment_" + private val sha256Digest: MessageDigest by lazy { MessageDigest.getInstance("SHA-256") } private val hexRegex = Regex("^[a-fA-F0-9]{64}$") @@ -73,7 +75,7 @@ data class AccountId private constructor( } fun forPaymentAccount(userWalletId: UserWalletId): AccountId { - return AccountId(value = "payment_$userWalletId", userWalletId = userWalletId) + return AccountId(value = "$PaymentAccountIdPrefix$userWalletId", userWalletId = userWalletId) } } } \ No newline at end of file