Updated on 2026-08-14

This commit is contained in:
Tangem 2025-05-20 15:13:47 +04:00
parent 33b7a53905
commit c5560c3c6a
101 changed files with 274 additions and 272 deletions

View file

@ -41,7 +41,7 @@ internal class DefaultDerivationsRepository(
derivePublicKeysByNetworks(userWalletId = userWalletId, networks = currencies.map(CryptoCurrency::network))
}
override suspend fun derivePublicKeysByNetworkIds(userWalletId: UserWalletId, networkIds: List<Network.ID>) {
override suspend fun derivePublicKeysByNetworkIds(userWalletId: UserWalletId, networkIds: List<Network.RawID>) {
val userWallet = userWalletsStore.getSyncOrNull(userWalletId) ?: error("User wallet not found")
derivePublicKeysByNetworks(

View file

@ -49,7 +49,7 @@ internal class MissedDerivationsFinder(private val scanResponse: ScanResponse) {
private fun List<Network>.mapToNewDerivations(): List<DerivationData> {
val config = CardConfig.createConfig(scanResponse.card)
return mapNotNull { network ->
val blockchain = Blockchain.fromId(id = network.id.value)
val blockchain = Blockchain.fromId(id = network.rawId)
val curve = config.primaryCurve(blockchain) ?: return@mapNotNull null
findNewDerivations(curve = curve, scanResponse = scanResponse, network = network)
@ -74,7 +74,7 @@ internal class MissedDerivationsFinder(private val scanResponse: ScanResponse) {
}
private fun Network.getDerivationCandidates(curve: EllipticCurve): List<DerivationPath> {
val blockchain = Blockchain.fromId(id = this.id.value)
val blockchain = Blockchain.fromId(id = rawId)
return buildList {
add(blockchain.getDerivationPath(curve = curve))

View file

@ -419,7 +419,7 @@ class WalletConnectInteractor(
private suspend fun getAccountsForWc(userWallet: UserWallet, networks: List<Network>): List<Account> {
val walletManagers = networks.mapNotNull {
val blockchain = Blockchain.fromId(it.id.value)
val blockchain = Blockchain.fromId(it.rawId)
walletManagersFacade.getOrCreateWalletManager(
userWalletId = userWallet.walletId,
blockchain = blockchain,

View file

@ -79,7 +79,7 @@ object TradeCryptoMiddleware {
val status = action.cryptoCurrencyStatus
val currency = status.currency
val blockchain = Blockchain.fromId(currency.network.id.value)
val blockchain = Blockchain.fromId(currency.network.rawId)
val exchangeManager = store.state.globalState.exchangeManager
val topUrl = exchangeManager.getUrl(
action = CurrencyExchangeManager.Action.Buy,

View file

@ -44,7 +44,7 @@ internal class CryptoCurrencyConverter(
}
override fun convertBack(value: CryptoCurrency): Currency {
val blockchain = Blockchain.fromId(value.network.id.value)
val blockchain = Blockchain.fromId(value.network.rawId)
if (blockchain == Blockchain.Unknown) error("CryptoCurrencyConverter convertBack Unknown blockchain")
return when (value) {
is CryptoCurrency.Coin -> Currency.Blockchain(

View file

@ -68,7 +68,7 @@ class CurrencyExchangeManager(
walletAddress: String,
isDarkTheme: Boolean,
): String? {
val blockchain = Blockchain.fromId(cryptoCurrency.network.id.value)
val blockchain = Blockchain.fromId(cryptoCurrency.network.rawId)
if (blockchain.isTestnet()) return blockchain.getTestnetTopUpUrl()
val urlBuilder = getExchangeUrlBuilder(action)

View file

@ -77,7 +77,7 @@ internal class MercuryoService(private val environment: MercuryoEnvironment) : E
): String {
if (action == CurrencyExchangeManager.Action.Sell) throw UnsupportedOperationException()
val blockchain = Blockchain.fromId(cryptoCurrency.network.id.value)
val blockchain = Blockchain.fromId(cryptoCurrency.network.rawId)
val builder = Uri.Builder()
.scheme(ExchangeUrlBuilder.SCHEME)

View file

@ -133,7 +133,7 @@ class MoonPayService(
): String? {
if (action == CurrencyExchangeManager.Action.Buy) throw UnsupportedOperationException()
val blockchain = Blockchain.fromId(cryptoCurrency.network.id.value)
val blockchain = Blockchain.fromId(cryptoCurrency.network.rawId)
val supportedCurrency = blockchain.moonPaySupportedCurrency ?: return null
val moonpayCurrency = status?.availableForSell?.firstOrNull {
when (cryptoCurrency) {

View file

@ -47,16 +47,18 @@ class MockCryptoCurrencyFactory(private val scanResponse: ScanResponse = default
}
fun createCoin(blockchain: Blockchain): CryptoCurrency {
val derivationPath = getNetworkDerivationPath(
blockchain = blockchain,
extraDerivationPath = null,
cardDerivationStyleProvider = scanResponse.derivationStyleProvider,
)
val network = Network(
id = Network.ID(blockchain.id),
id = Network.ID(blockchain.id, derivationPath),
backendId = blockchain.toNetworkId(),
name = blockchain.fullName,
isTestnet = blockchain.isTestnet(),
derivationPath = getNetworkDerivationPath(
blockchain = blockchain,
extraDerivationPath = null,
cardDerivationStyleProvider = scanResponse.derivationStyleProvider,
),
derivationPath = derivationPath,
currencySymbol = blockchain.currency,
standardType = getNetworkStandardType(blockchain),
hasFiatFeeRate = blockchain.feePaidCurrency() !is FeePaidCurrency.FeeResource,
@ -69,6 +71,12 @@ class MockCryptoCurrencyFactory(private val scanResponse: ScanResponse = default
// Impossible to create custom token by CryptoCurrencyFactory because it works with URI under the hood
fun createCustomToken(blockchain: Blockchain, derivationBlockchain: Blockchain): CryptoCurrency {
val derivationPath = Network.DerivationPath.Custom(
value = derivationBlockchain.derivationPath(
scanResponse.derivationStyleProvider.getDerivationStyle(),
)!!.rawPath,
)
return CryptoCurrency.Token(
id = CryptoCurrency.ID(
prefix = CryptoCurrency.ID.Prefix.TOKEN_PREFIX,
@ -76,15 +84,11 @@ class MockCryptoCurrencyFactory(private val scanResponse: ScanResponse = default
suffix = CryptoCurrency.ID.Suffix.RawID(blockchain.id),
),
network = Network(
id = Network.ID(value = blockchain.id),
id = Network.ID(value = blockchain.id, derivationPath),
backendId = "NEVER-MIND",
name = blockchain.fullName,
currencySymbol = "NEVER-MIND",
derivationPath = Network.DerivationPath.Custom(
value = derivationBlockchain.derivationPath(
scanResponse.derivationStyleProvider.getDerivationStyle(),
)!!.rawPath,
),
derivationPath = derivationPath,
isTestnet = false,
standardType = Network.StandardType.ERC20,
hasFiatFeeRate = true,

View file

@ -59,7 +59,7 @@ private fun Set<NetworkAddress.Address>.mapToAddressModels(name: TextReference,
}
private fun Network.getAddressDisplayName(addressType: NetworkAddress.Address.Type): TextReference {
return when (id.value) {
return when (rawId) {
"decimal", "decimal/test" -> {
when (addressType) {
NetworkAddress.Address.Type.Primary -> stringReference(value = DEL_ADDRESS_NAME)

View file

@ -4,7 +4,6 @@ import com.tangem.blockchain.common.BlockchainSdkError
import com.tangem.common.ui.R
import com.tangem.common.ui.amountScreen.models.AmountFieldModel
import com.tangem.common.ui.amountScreen.utils.getFiatString
import com.tangem.common.ui.notifications.NotificationUM.Warning
import com.tangem.core.ui.extensions.networkIconResId
import com.tangem.core.ui.format.bigdecimal.crypto
import com.tangem.core.ui.format.bigdecimal.format
@ -460,7 +459,7 @@ object NotificationsFactory {
onCloseClick: (Class<out NotificationUM>) -> Unit,
) {
val balance = cryptoCurrencyStatus.value.amount ?: BigDecimal.ZERO
val isTezos = isTezos(cryptoCurrencyStatus.currency.network.id.value)
val isTezos = isTezos(cryptoCurrencyStatus.currency.network.rawId)
val threshold = getTezosThreshold()
val isTotalBalance = enteredAmountValue >= balance && balance > threshold
if (!ignoreAmountReduce && isTotalBalance && isTezos) {

View file

@ -141,7 +141,7 @@ class TokenItemStateConverter(
}
private fun CryptoCurrencyStatus.getStakedBalance() = (value.yieldBalance as? YieldBalance.Data)
?.getTotalWithRewardsStakingBalance(blockchainId = currency.network.id.value).orZero()
?.getTotalWithRewardsStakingBalance(blockchainId = currency.network.rawId).orZero()
private fun createTitleState(currencyStatus: CryptoCurrencyStatus): TokenItemState.TitleState {
return when (val value = currencyStatus.value) {

View file

@ -64,7 +64,7 @@ class NFTPersistenceStoreFactory @Inject constructor(
scope = CoroutineScope(context = dispatchers.io + SupervisorJob()),
)
private fun Network.ID.formatted(): String = value
private fun Network.ID.formatted(): String = rawId.value
.filter(Char::isLetterOrDigit)
.lowercase()

View file

@ -57,7 +57,7 @@ object NFTSdkAssetConverter : TwoWayConverter<Pair<Network, SdkNFTAsset>, NFTAss
return value.network to SdkNFTAsset(
identifier = assetId,
collectionIdentifier = collectionId,
blockchainId = value.network.id.value,
blockchainId = value.network.rawId,
contractType = value.contractType,
owner = value.owner,
name = value.name,

View file

@ -27,7 +27,7 @@ val CryptoCurrency.networkIconResId: Int
* @return Drawable resource ID for the network.
*/
val Network.iconResId: Int
get() = getActiveIconRes(id.value)
get() = getActiveIconRes(rawId)
/**
* Tries to extract a background color from the contract address of a token.

View file

@ -84,7 +84,7 @@ class CryptoCurrencyFactory(
}
fun createCoin(network: Network): CryptoCurrency.Coin {
val blockchain = Blockchain.fromId(network.id.value)
val blockchain = Blockchain.fromId(network.rawId)
return CryptoCurrency.Coin(
id = getCoinId(network, blockchain.toCoinId()),

View file

@ -13,7 +13,7 @@ import com.tangem.domain.models.scan.ScanResponse
import timber.log.Timber
fun getBlockchain(networkId: Network.ID): Blockchain {
return Blockchain.fromId(networkId.value)
return Blockchain.fromId(networkId.rawId.value)
}
fun getNetwork(
@ -27,16 +27,18 @@ fun getNetwork(
return null
}
val derivationPath = getNetworkDerivationPath(
blockchain = blockchain,
extraDerivationPath = extraDerivationPath,
cardDerivationStyleProvider = derivationStyleProvider,
)
return Network(
id = Network.ID(blockchain.id),
id = Network.ID(value = blockchain.id, derivationPath = derivationPath),
backendId = blockchain.toNetworkId(),
name = blockchain.fullName,
isTestnet = blockchain.isTestnet(),
derivationPath = getNetworkDerivationPath(
blockchain = blockchain,
extraDerivationPath = extraDerivationPath,
cardDerivationStyleProvider = derivationStyleProvider,
),
derivationPath = derivationPath,
currencySymbol = blockchain.currency,
standardType = getNetworkStandardType(blockchain),
hasFiatFeeRate = blockchain.feePaidCurrency() !is FeePaidCurrency.FeeResource,

View file

@ -78,12 +78,12 @@ fun List<UserTokensResponse.Token>.hasCoinForToken(network: Network): Boolean {
private fun getCurrencyIdBody(network: Network): CurrencyIdBody {
return when (val path = network.derivationPath) {
is Network.DerivationPath.Custom -> CurrencyIdBody.NetworkIdWithDerivationPath(
rawId = network.id.value,
rawId = network.rawId,
derivationPath = path.value,
)
is Network.DerivationPath.Card,
is Network.DerivationPath.None,
-> CurrencyIdBody.NetworkId(network.id.value)
-> CurrencyIdBody.NetworkId(network.rawId)
}
}

View file

@ -48,7 +48,7 @@ internal class DefaultCustomTokensRepository(
override suspend fun validateContractAddress(contractAddress: String, networkId: Network.ID): Boolean =
withContext(dispatchers.io) {
when (val blockchain = Blockchain.fromId(networkId.value)) {
when (val blockchain = Blockchain.fromId(networkId.rawId.value)) {
Blockchain.Unknown,
Blockchain.Binance,
Blockchain.BinanceTestnet,
@ -76,7 +76,7 @@ internal class DefaultCustomTokensRepository(
}
storedCurrencies.tokens.none { token ->
Blockchain.fromId(networkId.value).toNetworkId() == token.networkId &&
Blockchain.fromId(networkId.rawId.value).toNetworkId() == token.networkId &&
derivationPath.value == token.derivationPath &&
contractAddress.equals(token.contractAddress, ignoreCase = true)
}

View file

@ -20,7 +20,7 @@ internal object NetworkStatusSupplierModule {
return object : SingleNetworkStatusSupplier(
factory = factory,
keyCreator = {
"single_network_status_${it.userWalletId.stringValue}_${it.network.id.value}_" +
"single_network_status_${it.userWalletId.stringValue}_${it.network.rawId}_" +
it.network.derivationPath.value
},
) {}

View file

@ -62,7 +62,7 @@ internal class CommonNetworkStatusFetcher @Inject constructor(
networksStatusesStore.storeStatus(userWalletId = userWalletId, status = status)
}
.onLeft {
Timber.e("Failed to fetch network status for $userWalletId [${network.id.value}]: $it")
Timber.e("Failed to fetch network status for $userWalletId [${network.rawId}]: $it")
networksStatusesStore.setSourceAsOnlyCache(userWalletId = userWalletId, network = network)
}
}

View file

@ -533,7 +533,7 @@ internal class DefaultNFTRepository @Inject constructor(
private fun Pair<UserWalletId, Network>.formatted(): String {
val (walletId, network) = this
return walletId.stringValue + "_" + network.id.value + "_" + network.derivationPath.value
return walletId.stringValue + "_" + network.rawId + "_" + network.derivationPath.value
}
private fun Network.canHandleNFTs(): Boolean {

View file

@ -19,7 +19,7 @@ internal class MercuryoTopUpRepository @Inject constructor(
override suspend fun getTopUpUrl(cryptoCurrency: CryptoCurrency, walletAddress: String): String =
withContext(dispatchersProvider.default) {
val blockchain = Blockchain.fromId(cryptoCurrency.network.id.value)
val blockchain = Blockchain.fromId(cryptoCurrency.network.rawId)
val environmentConfig = environmentConfigStorage.getConfigSync()
val builder = Uri.Builder()

View file

@ -7,7 +7,10 @@ import com.tangem.domain.qrscanning.models.SourceType
import com.tangem.domain.qrscanning.repository.QrScanningEventsRepository
import com.tangem.domain.tokens.model.CryptoCurrency
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.flow.*
import kotlinx.coroutines.flow.MutableSharedFlow
import kotlinx.coroutines.flow.filter
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.onEach
import kotlinx.coroutines.yield
import java.math.BigDecimal
import java.net.URLDecoder
@ -87,7 +90,7 @@ internal class DefaultQrScanningEventsRepository : QrScanningEventsRepository {
}
private fun stripSchema(raw: String, currency: CryptoCurrency): String {
val qrSchemas = Blockchain.fromId(currency.network.id.value).getShareScheme()
val qrSchemas = Blockchain.fromId(currency.network.rawId).getShareScheme()
// The most specific (i.e. the most lengthy) prefixes always come first
qrSchemas

View file

@ -76,7 +76,7 @@ internal class DefaultQrScanningEventsRepositoryTest {
@Test
fun testBip021() {
every { network.id } returns Network.ID(Blockchain.Bitcoin.id)
every { network.rawId } returns Blockchain.Bitcoin.id
positiveCase(
"$schema1:$address1",
QrResult(address = address1),
@ -126,7 +126,7 @@ internal class DefaultQrScanningEventsRepositoryTest {
@Test
fun testErc681Coin() {
every { network.id } returns Network.ID(Blockchain.Ethereum.id)
every { network.rawId } returns Blockchain.Ethereum.id
positiveCase(
address2,
QrResult(address = address2),
@ -181,7 +181,7 @@ internal class DefaultQrScanningEventsRepositoryTest {
@Test
fun testErc681Token() {
every { network.id } returns Network.ID(Blockchain.Ethereum.id)
every { network.rawId } returns Blockchain.Ethereum.id
positiveCase(
address2,
QrResult(address = address2),

View file

@ -245,7 +245,7 @@ internal class DefaultStakingRepository(
}
private fun checkFeatureToggleEnabled(networkId: Network.ID): Boolean {
return when (Blockchain.fromId(networkId.value)) {
return when (Blockchain.fromId(networkId.rawId.value)) {
Blockchain.TON -> stakingFeatureToggles.isTonStakingEnabled
Blockchain.Cardano -> stakingFeatureToggles.isCardanoStakingEnabled
else -> true
@ -256,7 +256,7 @@ internal class DefaultStakingRepository(
val userWallet = getUserWalletUseCase(userWalletId).getOrElse {
error("Failed to get user wallet")
}
val blockchainId = cryptoCurrency.network.id.value
val blockchainId = cryptoCurrency.network.rawId
return when {
isSolana(blockchainId) -> INVALID_BATCHES_FOR_SOLANA.contains(userWallet.scanResponse.card.batchId)
isCardano(blockchainId) -> !userWallet.scanResponse.card.isWallet2

View file

@ -39,7 +39,7 @@ internal object YieldBalanceSupplierModule {
return object : SingleYieldBalanceSupplier(
factory = factory,
keyCreator = {
"single_yield_balance_${it.userWalletId.stringValue}_${it.network.id.value}_" +
"single_yield_balance_${it.userWalletId.stringValue}_${it.network.rawId}_" +
it.network.derivationPath.value
},
) {}

View file

@ -354,7 +354,7 @@ internal class DefaultCurrenciesRepository(
"Unable to find tokens response for user wallet with provided ID: $userWalletId"
},
)
val blockchain = Blockchain.fromId(networkId.value)
val blockchain = Blockchain.fromId(networkId.rawId.value)
val blockchainNetworkId = blockchain.toNetworkId()
val coinId = blockchain.toCoinId()
@ -407,7 +407,7 @@ internal class DefaultCurrenciesRepository(
cryptoCurrencyStatus: CryptoCurrencyStatus,
coinStatus: CryptoCurrencyStatus?,
): Boolean {
val blockchain = Blockchain.fromId(cryptoCurrencyStatus.currency.network.id.value)
val blockchain = Blockchain.fromId(cryptoCurrencyStatus.currency.network.rawId)
val isBitcoinBlockchain = blockchain == Blockchain.Bitcoin || blockchain == Blockchain.BitcoinTestnet
return when {
cryptoCurrencyStatus.currency is CryptoCurrency.Coin && isBitcoinBlockchain -> {
@ -422,7 +422,7 @@ internal class DefaultCurrenciesRepository(
override suspend fun getFeePaidCurrency(userWalletId: UserWalletId, network: Network): FeePaidCurrency {
return withContext(dispatchers.io) {
val blockchain = Blockchain.fromId(network.id.value)
val blockchain = Blockchain.fromId(network.rawId)
when (val feePaidCurrency = blockchain.feePaidCurrency()) {
FeePaidSdkCurrency.Coin -> FeePaidCurrency.Coin
FeePaidSdkCurrency.SameCurrency -> FeePaidCurrency.SameCurrency

View file

@ -136,7 +136,7 @@ internal class DefaultCurrencyChecksRepository(
val balanceValue = currencyStatus.value as? CryptoCurrencyStatus.Loaded ?: return null
val stakingBalance = balanceValue.yieldBalance as? YieldBalance.Data
val stakingTotalBalance = stakingBalance?.getTotalStakingBalance(
blockchainId = currencyStatus.currency.network.id.value,
blockchainId = currencyStatus.currency.network.rawId,
).orZero()
return when {
balanceValue.amount.isZero() && stakingTotalBalance.isZero() -> null

View file

@ -39,7 +39,7 @@ internal class DefaultPolkadotAccountHealthCheckRepository(
override suspend fun runCheck(userWalletId: UserWalletId, network: Network) {
// Run Polkadot account health check
if (Blockchain.fromId(network.id.value) != Blockchain.Polkadot) return
if (Blockchain.fromId(network.rawId) != Blockchain.Polkadot) return
val walletManager = walletManagersFacade.getOrCreateWalletManager(userWalletId, network)
val address = requireNotNull(walletManager?.wallet?.address) {

View file

@ -7,7 +7,7 @@ import com.tangem.domain.transaction.FeeRepository
internal class DefaultFeeRepository : FeeRepository {
override fun isFeeApproximate(networkId: Network.ID, amountType: AmountType): Boolean {
val blockchain = Blockchain.fromId(networkId.value)
val blockchain = Blockchain.fromId(networkId.rawId.value)
return blockchain.isFeeApproximate(amountType)
}
}

View file

@ -47,14 +47,14 @@ internal class DefaultTransactionRepository(
network: Network,
txExtras: TransactionExtras?,
): TransactionData.Uncompiled = withContext(coroutineDispatcherProvider.io) {
val blockchain = Blockchain.fromId(network.id.value)
val blockchain = Blockchain.fromId(network.rawId)
val walletManager = walletManagersFacade.getOrCreateWalletManager(
userWalletId = userWalletId,
blockchain = blockchain,
derivationPath = network.derivationPath.value,
) ?: error("Wallet manager not found")
val extras = txExtras ?: getMemoExtras(networkId = network.id.value, memo)
val extras = txExtras ?: getMemoExtras(networkId = network.rawId, memo)
return@withContext if (fee != null) {
walletManager.createTransaction(
@ -83,7 +83,7 @@ internal class DefaultTransactionRepository(
userWalletId: UserWalletId,
network: Network,
): TransactionData.Uncompiled = withContext(coroutineDispatcherProvider.io) {
val blockchain = Blockchain.fromId(network.id.value)
val blockchain = Blockchain.fromId(network.rawId)
val walletManager = walletManagersFacade.getOrCreateWalletManager(
userWalletId = userWalletId,
blockchain = blockchain,
@ -115,14 +115,14 @@ internal class DefaultTransactionRepository(
destination = destination,
userWalletId = userWalletId,
network = network,
txExtras = getMemoExtras(networkId = network.id.value, memo = memo) ?: extras,
txExtras = getMemoExtras(networkId = network.rawId, memo = memo) ?: extras,
)
} else {
TransactionData.Uncompiled(
amount = amount,
sourceAddress = walletManager.wallet.address,
destinationAddress = destination,
extras = getMemoExtras(networkId = network.id.value, memo = memo) ?: extras,
extras = getMemoExtras(networkId = network.rawId, memo = memo) ?: extras,
fee = null,
)
}
@ -137,7 +137,7 @@ internal class DefaultTransactionRepository(
userWalletId: UserWalletId,
network: Network,
): TransactionData.Uncompiled = withContext(coroutineDispatcherProvider.io) {
val blockchain = Blockchain.fromId(network.id.value)
val blockchain = Blockchain.fromId(network.rawId)
val extras = createTransactionDataExtras(
callData = SmartContractCallDataProviderFactory.getApprovalCallData(
@ -170,7 +170,7 @@ internal class DefaultTransactionRepository(
userWalletId: UserWalletId,
network: Network,
): TransactionData.Uncompiled = withContext(coroutineDispatcherProvider.io) {
val blockchain = Blockchain.fromId(network.id.value)
val blockchain = Blockchain.fromId(network.rawId)
// For now transfer one nft asset at a time
val updatedNFTAsset = nftAsset.copy(
@ -228,7 +228,7 @@ internal class DefaultTransactionRepository(
userWalletId: UserWalletId,
network: Network,
): Result<Unit> = withContext(coroutineDispatcherProvider.io) {
val blockchain = Blockchain.fromId(network.id.value)
val blockchain = Blockchain.fromId(network.rawId)
val walletManager = walletManagersStore.getSyncOrNull(
userWalletId = userWalletId,
blockchain = blockchain,
@ -243,7 +243,7 @@ internal class DefaultTransactionRepository(
fee = fee ?: Fee.Common(amount = amount),
destination = destination,
).copy(
extras = getMemoExtras(networkId = network.id.value, memo = memo),
extras = getMemoExtras(networkId = network.rawId, memo = memo),
)
validator.validate(transactionData = transactionData)
@ -259,7 +259,7 @@ internal class DefaultTransactionRepository(
userWalletId: UserWalletId,
network: Network,
) = withContext(coroutineDispatcherProvider.io) {
val blockchain = Blockchain.fromId(network.id.value)
val blockchain = Blockchain.fromId(network.rawId)
val walletManager = walletManagersFacade.getOrCreateWalletManager(
userWalletId = userWalletId,
blockchain = blockchain,
@ -275,7 +275,7 @@ internal class DefaultTransactionRepository(
network: Network,
mode: TransactionSender.MultipleTransactionSendMode,
) = withContext(coroutineDispatcherProvider.io) {
val blockchain = Blockchain.fromId(network.id.value)
val blockchain = Blockchain.fromId(network.rawId)
val walletManager = walletManagersFacade.getOrCreateWalletManager(
userWalletId = userWalletId,
blockchain = blockchain,
@ -315,7 +315,7 @@ internal class DefaultTransactionRepository(
spenderAddress: String,
): BigDecimal {
val walletManager = walletManagersFacade.getOrCreateWalletManager(userWalletId, cryptoCurrency.network)
val blockchain = Blockchain.fromId(cryptoCurrency.network.id.value)
val blockchain = Blockchain.fromId(cryptoCurrency.network.rawId)
val allowanceResult = (walletManager as? Approver)?.getAllowance(
spenderAddress,
Token(
@ -388,7 +388,7 @@ internal class DefaultTransactionRepository(
}
private suspend fun getPreparer(network: Network, userWalletId: UserWalletId): TransactionPreparer {
val blockchain = Blockchain.fromId(network.id.value)
val blockchain = Blockchain.fromId(network.rawId)
val walletManager = walletManagersFacade.getOrCreateWalletManager(
userWalletId = userWalletId,
blockchain = blockchain,

View file

@ -21,7 +21,7 @@ class DefaultWalletAddressServiceRepository(
override suspend fun validateAddress(userWalletId: UserWalletId, network: Network, address: String): Boolean =
withContext(dispatchers.io) {
val blockchain = Blockchain.fromId(network.id.value)
val blockchain = Blockchain.fromId(network.rawId)
if (blockchain.isNear()) {
val walletManager = walletManagersFacade.getOrCreateWalletManager(
@ -37,7 +37,7 @@ class DefaultWalletAddressServiceRepository(
override fun validateMemo(network: Network, memo: String): Boolean {
if (memo.isEmpty()) return true
return when (network.id.value) {
return when (network.rawId) {
Blockchain.XRP.id -> {
val tag = memo.toLongOrNull()
tag != null && tag <= XRP_TAG_MAX_NUMBER
@ -50,7 +50,7 @@ class DefaultWalletAddressServiceRepository(
}
override suspend fun parseSharedAddress(input: String, network: Network): ParsedQrCode {
val blockchain = Blockchain.fromId(network.id.value)
val blockchain = Blockchain.fromId(network.rawId)
val addressSchemeSplit = when (blockchain) {
Blockchain.BitcoinCash, Blockchain.Kaspa -> listOf(input)
else -> input.split(":")

View file

@ -77,7 +77,7 @@ class DefaultTxHistoryRepository(
@Deprecated("Replace with getTxExploreUrl [UserWalletId, Network] instead")
override fun getTxExploreUrl(txHash: String, networkId: Network.ID): String {
val blockchain = Blockchain.fromId(networkId.value)
val blockchain = Blockchain.fromId(networkId.rawId.value)
return when (val txExploreState = blockchain.getExploreTxUrl(txHash)) {
is TxExploreState.Url -> txExploreState.url
is TxExploreState.Unsupported -> ""
@ -85,7 +85,7 @@ class DefaultTxHistoryRepository(
}
override suspend fun getTxExploreUrl(userWalletId: UserWalletId, network: Network): String {
val blockchain = Blockchain.fromId(network.id.value)
val blockchain = Blockchain.fromId(network.rawId)
val walletManager = walletManagersFacade.getOrCreateWalletManager(
userWalletId = userWalletId,
network = network,

View file

@ -9,12 +9,8 @@ import com.tangem.data.walletconnect.request.WcRequestToUseCaseConverter
import com.tangem.data.walletconnect.request.WcRequestToUseCaseConverter.Companion.fromJson
import com.tangem.data.walletconnect.sign.WcMethodUseCaseContext
import com.tangem.data.walletconnect.utils.WcNamespaceConverter
import com.tangem.domain.walletconnect.model.WcEthAddChain
import com.tangem.domain.models.network.Network
import com.tangem.domain.walletconnect.model.WcEthMethod
import com.tangem.domain.walletconnect.model.WcEthMethodName
import com.tangem.domain.walletconnect.model.WcEthSignTypedDataParams
import com.tangem.domain.walletconnect.model.WcEthTransactionParams
import com.tangem.domain.walletconnect.model.*
import com.tangem.domain.walletconnect.model.sdkcopy.WcSdkSessionRequest
import com.tangem.domain.walletconnect.repository.WcSessionsManager
import com.tangem.domain.walletconnect.usecase.method.WcMethodUseCase
@ -129,7 +125,7 @@ internal class WcEthNetwork(
}
override fun toCAIP2(network: Network): CAIP2? {
val blockchain = Blockchain.fromId(network.id.value)
val blockchain = Blockchain.fromId(network.rawId)
if (!blockchain.isEvm()) return null
val chainId = blockchain.getChainId() ?: return null
return CAIP2(

View file

@ -20,7 +20,7 @@ internal object WcEthTxHelper {
val gasLimit = txParams.gas?.hexToBigDecimal() ?: return null
val gasPrice = txParams.gasPrice?.hexToBigDecimal() ?: return null
val blockchain = Blockchain.fromId(network.id.value)
val blockchain = Blockchain.fromId(network.rawId)
var feeDecimal = (gasLimit * gasPrice)
.movePointLeft(blockchain.decimals())
@ -38,7 +38,7 @@ internal object WcEthTxHelper {
txParams: WcEthTransactionParams,
): TransactionData.Uncompiled? {
val destinationAddress = txParams.to ?: return null
val blockchain = Blockchain.fromId(network.id.value)
val blockchain = Blockchain.fromId(network.rawId)
val value = (txParams.value ?: "0")
.hexToBigDecimal()
.movePointLeft(blockchain.decimals())

View file

@ -57,7 +57,7 @@ internal class WcSolanaNetwork(
private suspend fun getAccountAddress(network: Network): String? {
return try {
walletManager.getWalletAddress(network.id.value, network.derivationPath.value)
walletManager.getWalletAddress(network.rawId, network.derivationPath.value)
} catch (exception: Exception) {
Timber.e(exception)
null
@ -84,7 +84,7 @@ internal class WcSolanaNetwork(
}
override fun toCAIP2(network: Network): CAIP2? {
val blockchain = Blockchain.fromId(network.id.value)
val blockchain = Blockchain.fromId(network.rawId)
val chainId = when (blockchain) {
Blockchain.Solana -> MAINNET_CHAIN_ID
Blockchain.SolanaTestnet -> TESTNET_CHAIN_ID

View file

@ -26,7 +26,7 @@ class GetExtendedPublicKeyForCurrencyUseCase(
val userWallet = walletManagersFacade.getOrCreateWalletManager(userWalletId, network)
?: error("Wallet not found")
val blockchain = Blockchain.fromId(network.id.value)
val blockchain = Blockchain.fromId(network.rawId)
val isSecp256k1Blockchain = Blockchain.secp256k1Blockchains(network.isTestnet).contains(blockchain)
val hdKey = if (isSecp256k1Blockchain) {
@ -76,7 +76,7 @@ class GetExtendedPublicKeyForCurrencyUseCase(
val userWallet = walletManagersFacade.getOrCreateWalletManager(userWalletId, network)
?: error("Wallet not found")
val blockchain = Blockchain.fromId(network.id.value)
val blockchain = Blockchain.fromId(network.rawId)
val isSecp256k1Blockchain = Blockchain.secp256k1Blockchains(network.isTestnet).contains(blockchain)
val isHdKey = userWallet.wallet.publicKey.derivationType?.hdKey

View file

@ -9,7 +9,7 @@ import com.tangem.domain.models.scan.ScanResponse
class NetworkHasDerivationUseCase {
operator fun invoke(scanResponse: ScanResponse, network: Network): Either<Throwable, Boolean> {
val blockchain = Blockchain.fromId(network.id.value)
val blockchain = Blockchain.fromId(network.rawId)
val derivationPath = network.derivationPath.value
return Either.catch { derivationPath != null && scanResponse.hasDerivation(blockchain, derivationPath) }
}

View file

@ -13,7 +13,7 @@ interface DerivationsRepository {
@Throws
suspend fun derivePublicKeys(userWalletId: UserWalletId, currencies: List<CryptoCurrency>)
suspend fun derivePublicKeysByNetworkIds(userWalletId: UserWalletId, networkIds: List<Network.ID>)
suspend fun derivePublicKeysByNetworkIds(userWalletId: UserWalletId, networkIds: List<Network.RawID>)
@Throws
suspend fun derivePublicKeysByNetworks(userWalletId: UserWalletId, networks: List<Network>)

View file

@ -78,7 +78,7 @@ class DefaultWalletManagersFacade(
extraTokens: Set<CryptoCurrency.Token>,
): UpdateWalletManagerResult {
val userWallet = getUserWallet(userWalletId)
val blockchain = Blockchain.fromId(network.id.value)
val blockchain = Blockchain.fromId(network.rawId)
val derivationPath = network.derivationPath.value
return getAndUpdateWalletManager(userWallet, blockchain, derivationPath, extraTokens)
@ -88,7 +88,7 @@ class DefaultWalletManagersFacade(
if (networks.isEmpty()) return
val blockchainsToDerivationPaths = networks.map {
Blockchain.fromId(it.id.value) to it.derivationPath.value
Blockchain.fromId(it.rawId) to it.derivationPath.value
}
withContext(dispatchers.io) {
@ -141,7 +141,7 @@ class DefaultWalletManagersFacade(
withContext(dispatchers.io) {
val walletManager = walletManagersStore.getSyncOrNull(
userWalletId = userWalletId,
blockchain = Blockchain.fromId(network.id.value),
blockchain = Blockchain.fromId(network.rawId),
derivationPath = network.derivationPath.value,
) ?: return@withContext
@ -158,7 +158,7 @@ class DefaultWalletManagersFacade(
network: Network,
): UpdateWalletManagerResult {
val userWallet = getUserWallet(userWalletId)
val blockchain = Blockchain.fromId(network.id.value)
val blockchain = Blockchain.fromId(network.rawId)
val derivationPath = network.derivationPath.value
if (derivationPath != null && !userWallet.scanResponse.hasDerivation(blockchain, derivationPath)) {
@ -181,7 +181,7 @@ class DefaultWalletManagersFacade(
addressType: AddressType,
contractAddress: String?,
): String {
val blockchain = Blockchain.fromId(network.id.value)
val blockchain = Blockchain.fromId(network.rawId)
val walletManager = getOrCreateWalletManager(
userWalletId = userWalletId,
network = network,
@ -385,7 +385,7 @@ class DefaultWalletManagersFacade(
@Deprecated("Will be removed in future")
override suspend fun getOrCreateWalletManager(userWalletId: UserWalletId, network: Network): WalletManager? {
val blockchain = Blockchain.fromId(network.id.value)
val blockchain = Blockchain.fromId(network.rawId)
return getOrCreateWalletManager(
userWalletId = userWalletId,
blockchain = blockchain,
@ -477,7 +477,7 @@ class DefaultWalletManagersFacade(
userWalletId: UserWalletId,
network: Network,
): Result<TransactionFee>? = withContext(dispatchers.io) {
val blockchain = Blockchain.fromId(network.id.value)
val blockchain = Blockchain.fromId(network.rawId)
val walletManager = getOrCreateWalletManager(
userWalletId = userWalletId,
blockchain = blockchain,
@ -566,7 +566,7 @@ class DefaultWalletManagersFacade(
decimals: Int,
id: String?,
): BigDecimal {
val blockchain = Blockchain.fromId(network.id.value)
val blockchain = Blockchain.fromId(network.rawId)
val walletManager = getOrCreateWalletManager(
userWalletId = userWalletId,
blockchain = blockchain,
@ -637,7 +637,7 @@ class DefaultWalletManagersFacade(
}
override suspend fun checkUtxoConsolidationAvailability(userWalletId: UserWalletId, network: Network): Boolean {
val blockchain = Blockchain.fromId(network.id.value)
val blockchain = Blockchain.fromId(network.rawId)
val walletManager = getOrCreateWalletManager(
userWalletId = userWalletId,
blockchain = blockchain,
@ -648,7 +648,7 @@ class DefaultWalletManagersFacade(
}
override suspend fun getNFTCollections(userWalletId: UserWalletId, network: Network): List<NFTCollection> {
val blockchain = Blockchain.fromId(network.id.value)
val blockchain = Blockchain.fromId(network.rawId)
val walletManager = getOrCreateWalletManager(
userWalletId = userWalletId,
blockchain = blockchain,
@ -663,7 +663,7 @@ class DefaultWalletManagersFacade(
network: Network,
collectionIdentifier: NFTCollection.Identifier,
): List<NFTAsset> {
val blockchain = Blockchain.fromId(network.id.value)
val blockchain = Blockchain.fromId(network.rawId)
val walletManager = getOrCreateWalletManager(
userWalletId = userWalletId,
blockchain = blockchain,
@ -679,7 +679,7 @@ class DefaultWalletManagersFacade(
collectionIdentifier: NFTCollection.Identifier,
assetIdentifier: NFTAsset.Identifier,
): NFTAsset? {
val blockchain = Blockchain.fromId(network.id.value)
val blockchain = Blockchain.fromId(network.rawId)
val walletManager = getOrCreateWalletManager(
userWalletId = userWalletId,
blockchain = blockchain,
@ -694,7 +694,7 @@ class DefaultWalletManagersFacade(
collectionIdentifier: NFTCollection.Identifier,
assetIdentifier: NFTAsset.Identifier,
): NFTAsset.SalePrice? {
val blockchain = Blockchain.fromId(network.id.value)
val blockchain = Blockchain.fromId(network.rawId)
val walletManager = getOrCreateWalletManager(
userWalletId = userWalletId,
blockchain = blockchain,
@ -704,7 +704,7 @@ class DefaultWalletManagersFacade(
}
override suspend fun getNFTExploreUrl(network: Network, assetIdentifier: NFTAsset.Identifier): String? {
val blockchain = Blockchain.fromId(network.id.value)
val blockchain = Blockchain.fromId(network.rawId)
return blockchain.getNFTExploreUrl(assetIdentifier)
}

View file

@ -59,7 +59,7 @@ class SaveMarketTokensUseCase(
if (addedNetworks.isNotEmpty()) {
derivationsRepository.derivePublicKeysByNetworkIds(
userWalletId = userWalletId,
networkIds = addedNetworks.map { Network.ID(it.networkId) },
networkIds = addedNetworks.map { Network.RawID(it.networkId) },
)
val addedCurrencies = addedNetworks.mapNotNull {

View file

@ -35,18 +35,37 @@ data class Network(
val transactionExtrasType: TransactionExtrasType,
) {
/** Raw ID */
val rawId: String
get() = id.rawId.value
init {
require(name.isNotBlank()) { "Network name must not be blank" }
require(id.derivationPath == derivationPath) { "Derivation path must be the same as in the ID" }
}
/** Represents a unique identifier [value] for a blockchain network */
@JvmInline
/**
* Represents a unique identifier for a blockchain network
*
* @property rawId raw network ID
* @property derivationPath derivation path
*/
@Serializable
value class ID(val value: String) {
data class ID(val rawId: RawID, val derivationPath: DerivationPath) {
init {
require(value.isNotBlank()) { "Network ID must not be blank" }
require(rawId.value.isNotBlank()) { "Network ID must not be blank" }
}
constructor(value: String, derivationPath: DerivationPath) : this(
rawId = RawID(value),
derivationPath = derivationPath,
)
}
@Serializable
data class RawID(val value: String) {
override fun toString(): String = value
}
/**

View file

@ -10,7 +10,7 @@ class IncrementNotificationsShowCountUseCase(
suspend operator fun invoke(cryptoCurrency: CryptoCurrency) {
val isTronToken = cryptoCurrency is CryptoCurrency.Token &&
isTron(cryptoCurrency.network.id.value)
isTron(cryptoCurrency.network.rawId)
if (isTronToken) {
notificationsRepository.incrementTronTokenFeeNotificationShowCounter()

View file

@ -58,7 +58,7 @@ class GetCurrencyWarningsUseCase(
* coinRelatedWarnings.toTypedArray(),
getNetworkUnavailableWarning(currencyStatus),
getNetworkNoAccountWarning(currencyStatus),
getBeaconChainShutdownWarning(currency.network.id),
getBeaconChainShutdownWarning(rawId = currency.network.id.rawId),
getAssetRequirementsWarning(userWalletId = userWalletId, currency = currency),
getMigrationFromMaticToPolWarning(currency),
)
@ -147,7 +147,7 @@ class GetCurrencyWarningsUseCase(
}
private fun getIsBetaTokensWarning(currency: CryptoCurrency): CryptoCurrencyWarning? {
val isTokenBetaFunctionality = BlockchainUtils.isTokenBetaFunctionality(currency.network.id.value)
val isTokenBetaFunctionality = BlockchainUtils.isTokenBetaFunctionality(currency.network.rawId)
return if (currency is CryptoCurrency.Token && isTokenBetaFunctionality) {
CryptoCurrencyWarning.TokensInBetaWarning
} else {
@ -194,7 +194,7 @@ class GetCurrencyWarningsUseCase(
private fun getNetworkNoAccountWarning(currencyStatus: CryptoCurrencyStatus): CryptoCurrencyWarning? {
return (currencyStatus.value as? CryptoCurrencyStatus.NoAccount)?.let {
if (isNeedToCreateAccountWithoutReserve(networkId = currencyStatus.currency.network.id.value)) {
if (isNeedToCreateAccountWithoutReserve(networkId = currencyStatus.currency.network.rawId)) {
CryptoCurrencyWarning.TopUpWithoutReserve
} else {
CryptoCurrencyWarning.SomeNetworksNoAccount(
@ -205,8 +205,8 @@ class GetCurrencyWarningsUseCase(
}
}
private fun getBeaconChainShutdownWarning(networkId: Network.ID): CryptoCurrencyWarning.BeaconChainShutdown? {
return if (BlockchainUtils.isBeaconChain(networkId.value)) CryptoCurrencyWarning.BeaconChainShutdown else null
private fun getBeaconChainShutdownWarning(rawId: Network.RawID): CryptoCurrencyWarning.BeaconChainShutdown? {
return if (BlockchainUtils.isBeaconChain(rawId.value)) CryptoCurrencyWarning.BeaconChainShutdown else null
}
private fun getExistentialDepositWarning(
@ -253,7 +253,7 @@ class GetCurrencyWarningsUseCase(
}
private fun getMigrationFromMaticToPolWarning(currency: CryptoCurrency): CryptoCurrencyWarning? {
return if (currency.symbol == MATIC_SYMBOL && !BlockchainUtils.isPolygonChain(currency.network.id.value)) {
return if (currency.symbol == MATIC_SYMBOL && !BlockchainUtils.isPolygonChain(currency.network.rawId)) {
CryptoCurrencyWarning.MigrationMaticToPol
} else {
null

View file

@ -22,7 +22,7 @@ internal class TokenListFiatBalanceOperations(
if (isAnyTokenLoading) return fiatBalance
for (token in currencies) {
val blockchainId = token.currency.network.id.value
val blockchainId = token.currency.network.rawId
when (val status = token.value) {
is CryptoCurrencyStatus.Loading -> {
fiatBalance = TotalFiatBalance.Loading

View file

@ -103,7 +103,7 @@ internal class TokenListSortingOperations(
private fun CryptoCurrencyStatus.getTotalBalance(): BigDecimal {
val yieldBalance = value.yieldBalance as? YieldBalance.Data
val totalYieldBalance = yieldBalance?.getTotalWithRewardsStakingBalance(currency.network.id.value).orZero()
val totalYieldBalance = yieldBalance?.getTotalWithRewardsStakingBalance(currency.network.rawId).orZero()
val totalFiatYieldBalance = totalYieldBalance.multiply(value.fiatRate.orZero())
return value.fiatAmount?.plus(totalFiatYieldBalance).orZero()
}

View file

@ -14,7 +14,7 @@ internal object MockNetworks {
val amountToCreateAccount: BigDecimal = BigDecimal.TEN
val network1 = Network(
id = Network.ID("network1"),
id = Network.ID(value = "network1", derivationPath = Network.DerivationPath.None),
name = "Network One",
isTestnet = false,
standardType = Network.StandardType.ERC20,
@ -27,7 +27,7 @@ internal object MockNetworks {
)
val network2 = Network(
id = Network.ID("network2"),
id = Network.ID(value = "network2", derivationPath = Network.DerivationPath.None),
name = "Network Two",
isTestnet = false,
standardType = Network.StandardType.ERC20,
@ -40,7 +40,7 @@ internal object MockNetworks {
)
val network3 = Network(
id = Network.ID("network3"),
id = Network.ID(value = "network3", derivationPath = Network.DerivationPath.None),
name = "Network Three",
isTestnet = false,
standardType = Network.StandardType.ERC20,

View file

@ -9,7 +9,7 @@ internal object MockTokens {
get() = CryptoCurrency.Coin(
id = ID(
ID.Prefix.COIN_PREFIX,
ID.Body.NetworkId(MockNetworks.network1.id.value),
ID.Body.NetworkId(MockNetworks.network1.rawId),
ID.Suffix.RawID("token1"),
),
network = MockNetworks.network1,
@ -23,7 +23,7 @@ internal object MockTokens {
get() = CryptoCurrency.Token(
id = ID(
ID.Prefix.TOKEN_PREFIX,
ID.Body.NetworkId(MockNetworks.network1.id.value),
ID.Body.NetworkId(MockNetworks.network1.rawId),
ID.Suffix.RawID("token2"),
),
network = MockNetworks.network1,
@ -38,7 +38,7 @@ internal object MockTokens {
get() = CryptoCurrency.Token(
id = ID(
ID.Prefix.TOKEN_PREFIX,
ID.Body.NetworkId(MockNetworks.network1.id.value),
ID.Body.NetworkId(MockNetworks.network1.rawId),
ID.Suffix.RawID("token3"),
),
network = MockNetworks.network1,
@ -53,7 +53,7 @@ internal object MockTokens {
get() = CryptoCurrency.Coin(
id = ID(
ID.Prefix.COIN_PREFIX,
ID.Body.NetworkId(MockNetworks.network2.id.value),
ID.Body.NetworkId(MockNetworks.network2.rawId),
ID.Suffix.RawID("token4"),
),
network = MockNetworks.network2,
@ -67,7 +67,7 @@ internal object MockTokens {
get() = CryptoCurrency.Token(
id = ID(
ID.Prefix.TOKEN_PREFIX,
ID.Body.NetworkId(MockNetworks.network2.id.value),
ID.Body.NetworkId(MockNetworks.network2.rawId),
ID.Suffix.RawID("token5"),
),
network = MockNetworks.network2,
@ -82,7 +82,7 @@ internal object MockTokens {
get() = CryptoCurrency.Token(
id = ID(
ID.Prefix.TOKEN_PREFIX,
ID.Body.NetworkId(MockNetworks.network2.id.value),
ID.Body.NetworkId(MockNetworks.network2.rawId),
ID.Suffix.RawID("token6"),
),
network = MockNetworks.network2,
@ -97,7 +97,7 @@ internal object MockTokens {
get() = CryptoCurrency.Coin(
id = ID(
ID.Prefix.COIN_PREFIX,
ID.Body.NetworkId(MockNetworks.network3.id.value),
ID.Body.NetworkId(MockNetworks.network3.rawId),
ID.Suffix.RawID("token7"),
),
network = MockNetworks.network3,
@ -111,7 +111,7 @@ internal object MockTokens {
get() = CryptoCurrency.Token(
id = ID(
ID.Prefix.TOKEN_PREFIX,
ID.Body.NetworkId(MockNetworks.network3.id.value),
ID.Body.NetworkId(MockNetworks.network3.rawId),
ID.Suffix.RawID("token8"),
),
network = MockNetworks.network3,
@ -126,7 +126,7 @@ internal object MockTokens {
get() = CryptoCurrency.Token(
id = ID(
ID.Prefix.TOKEN_PREFIX,
ID.Body.NetworkId(MockNetworks.network3.id.value),
ID.Body.NetworkId(MockNetworks.network3.rawId),
ID.Suffix.RawID("token9"),
),
network = MockNetworks.network3,
@ -141,7 +141,7 @@ internal object MockTokens {
get() = CryptoCurrency.Token(
id = ID(
ID.Prefix.TOKEN_PREFIX,
ID.Body.NetworkId(MockNetworks.network3.id.value),
ID.Body.NetworkId(MockNetworks.network3.rawId),
ID.Suffix.RawID("token10"),
),
network = MockNetworks.network3,

View file

@ -26,7 +26,7 @@ class ValidateWalletAddressUseCase(
address: String,
currencyAddress: Set<NetworkAddress.Address>?,
): AddressValidationResult {
val decodedXAddress = BlockchainUtils.decodeRippleXAddress(address, network.id.value)
val decodedXAddress = BlockchainUtils.decodeRippleXAddress(address, network.rawId)
val isUtxoConsolidationAvailable =
walletManagersFacade.checkUtxoConsolidationAvailability(userWalletId, network)
@ -50,7 +50,7 @@ class ValidateWalletAddressUseCase(
address: String,
senderAddresses: List<CryptoCurrencyAddress>,
): AddressValidationResult {
val decodedXAddress = BlockchainUtils.decodeRippleXAddress(address, network.id.value)
val decodedXAddress = BlockchainUtils.decodeRippleXAddress(address, network.rawId)
val isUtxoConsolidationAvailable =
walletManagersFacade.checkUtxoConsolidationAvailability(userWalletId, network)

View file

@ -26,17 +26,19 @@ internal class PreviewCustomTokenSelectorComponent(
) : CustomTokenSelectorComponent {
private val previewItems = List(size = itemsSize) { index ->
val derivationPath = Network.DerivationPath.Card("m/44'/0'/0'/0/$index")
when (params) {
is Params.DerivationPathSelector -> {
val d = SelectedDerivationPath(
id = Network.ID(index.toString()),
value = Network.DerivationPath.Card("m/44'/0'/0'/0/$index"),
id = Network.ID(value = index.toString(), derivationPath = derivationPath),
value = derivationPath,
name = "Network $index",
isDefault = false,
)
DerivationPathUM(
id = d.id?.value ?: "",
id = d.id?.rawId?.value ?: "",
value = d.value.value.orEmpty(),
networkName = stringReference(d.name),
isSelected = d.value == params.selectedDerivationPath?.value,
@ -45,16 +47,16 @@ internal class PreviewCustomTokenSelectorComponent(
}
is Params.NetworkSelector -> {
val n = SelectedNetwork(
id = Network.ID(index.toString()),
id = Network.ID(value = index.toString(), derivationPath = derivationPath),
name = "Network $index",
derivationPath = Network.DerivationPath.Card("m/44'/0'/0'/0/$index"),
derivationPath = derivationPath,
canHandleTokens = false,
)
CurrencyNetworkUM(
network = Network(
id = n.id,
backendId = n.id.value,
backendId = n.id.rawId.value,
name = "Network $index",
currencySymbol = "N$index",
derivationPath = Network.DerivationPath.Card(""),
@ -76,7 +78,7 @@ internal class PreviewCustomTokenSelectorComponent(
}
}.toImmutableList()
val previewState = CustomTokenSelectorUM(
private val previewState = CustomTokenSelectorUM(
header = when (params) {
is Params.DerivationPathSelector -> CustomTokenSelectorUM.HeaderUM.CustomDerivationButton(
value = null,

View file

@ -150,13 +150,14 @@ internal class PreviewManageTokensComponent(
)
private fun getCurrencyNetworks(currencyIndex: Int) = List(size = 3) { networkIndex ->
val derivationPath = Network.DerivationPath.Card("")
CurrencyNetworkUM(
network = Network(
id = Network.ID(networkIndex.toString()),
id = Network.ID(value = networkIndex.toString(), derivationPath = derivationPath),
backendId = networkIndex.toString(),
name = "Network $networkIndex",
currencySymbol = "N$networkIndex",
derivationPath = Network.DerivationPath.Card(""),
derivationPath = derivationPath,
isTestnet = false,
standardType = Network.StandardType.ERC20,
hasFiatFeeRate = false,

View file

@ -90,13 +90,15 @@ internal class PreviewOnboardingManageTokensComponent(
)
private fun getCurrencyNetworks() = List(size = 3) { networkIndex ->
val derivationPath = Network.DerivationPath.Card("")
CurrencyNetworkUM(
network = Network(
id = Network.ID(networkIndex.toString()),
id = Network.ID(value = networkIndex.toString(), derivationPath = derivationPath),
backendId = networkIndex.toString(),
name = "Network $networkIndex",
currencySymbol = "N$networkIndex",
derivationPath = Network.DerivationPath.Card(""),
derivationPath = derivationPath,
isTestnet = false,
standardType = Network.StandardType.ERC20,
hasFiatFeeRate = false,

View file

@ -13,5 +13,5 @@ internal data class CurrencyNetworkUM(
override val onSelectedStateChange: (Boolean) -> Unit,
) : SelectableItemUM {
override val id: String = network.id.value
override val id: String = network.rawId
}

View file

@ -76,7 +76,7 @@ private class AddCustomTokenComponentPreviewProvider : PreviewParameterProvider<
userWalletId = UserWalletId(stringValue = "321"),
step = AddCustomTokenConfig.Step.FORM,
selectedNetwork = SelectedNetwork(
id = Network.ID(value = "1"),
id = Network.ID(value = "1", derivationPath = Network.DerivationPath.None),
name = "Ethereum",
derivationPath = Network.DerivationPath.None,
canHandleTokens = false,
@ -88,7 +88,7 @@ private class AddCustomTokenComponentPreviewProvider : PreviewParameterProvider<
userWalletId = UserWalletId(stringValue = "321"),
step = AddCustomTokenConfig.Step.NETWORK_SELECTOR,
selectedNetwork = SelectedNetwork(
id = Network.ID(value = "0"),
id = Network.ID(value = "0", derivationPath = Network.DerivationPath.None),
name = "Ethereum",
derivationPath = Network.DerivationPath.None,
canHandleTokens = false,
@ -100,7 +100,7 @@ private class AddCustomTokenComponentPreviewProvider : PreviewParameterProvider<
userWalletId = UserWalletId(stringValue = "321"),
step = AddCustomTokenConfig.Step.DERIVATION_PATH_SELECTOR,
selectedDerivationPath = SelectedDerivationPath(
id = Network.ID(value = "0"),
id = Network.ID(value = "0", derivationPath = Network.DerivationPath.None),
value = Network.DerivationPath.None,
name = "Ethereum",
isDefault = false,

View file

@ -266,20 +266,23 @@ private fun Preview_CustomTokenNetworkSelectorContent(
private class CustomTokenNetworkSelectorComponentPreviewProvider :
PreviewParameterProvider<CustomTokenSelectorComponent> {
private val derivationPath = Network.DerivationPath.Card("m/44'/0'/0'/0/0")
override val values: Sequence<CustomTokenSelectorComponent>
get() = sequenceOf(
PreviewCustomTokenSelectorComponent(
params = CustomTokenSelectorComponent.Params.DerivationPathSelector(
userWalletId = UserWalletId(stringValue = "321"),
selectedNetwork = SelectedNetwork(
id = Network.ID(value = "0"),
id = Network.ID(value = "0", derivationPath = derivationPath),
name = "Ethereum",
derivationPath = Network.DerivationPath.Card("m/44'/0'/0'/0/0"),
derivationPath = derivationPath,
canHandleTokens = true,
),
selectedDerivationPath = SelectedDerivationPath(
id = Network.ID(value = "0"),
value = Network.DerivationPath.Card("m/44'/0'/0'/0/0"),
id = Network.ID(value = "0", derivationPath = derivationPath),
value = derivationPath,
name = "",
isDefault = false,
),
@ -290,9 +293,9 @@ private class CustomTokenNetworkSelectorComponentPreviewProvider :
params = CustomTokenSelectorComponent.Params.NetworkSelector(
userWalletId = UserWalletId(stringValue = "321"),
selectedNetwork = SelectedNetwork(
id = Network.ID(value = "0"),
id = Network.ID(value = "0", derivationPath = derivationPath),
name = "Ethereum",
derivationPath = Network.DerivationPath.Card("m/44'/0'/0'/0/0"),
derivationPath = derivationPath,
canHandleTokens = true,
),
onNetworkSelected = {},

View file

@ -12,7 +12,7 @@ internal fun Network.toDerivationPathModel(
onSelectedStateChange: (Boolean) -> Unit,
): DerivationPathUM? {
return DerivationPathUM(
id = id.value,
id = rawId,
value = derivationPath.value ?: return null,
networkName = stringReference(name),
isSelected = isSelected,
@ -25,7 +25,7 @@ internal fun SelectedNetwork.toDerivationPathModel(
onSelectedStateChange: (Boolean) -> Unit,
): DerivationPathUM? {
return DerivationPathUM(
id = id.value,
id = id.rawId.value,
value = derivationPath.value ?: return null,
networkName = resourceReference(R.string.custom_token_derivation_path_default),
isSelected = isSelected,

View file

@ -15,7 +15,7 @@ internal fun CurrencyNetworkUM.select(isSelected: Boolean): CurrencyNetworkUM {
@DrawableRes
internal fun Network.ID.getIconRes(isColored: Boolean): Int = if (isColored) {
getActiveIconRes(value)
getActiveIconRes(rawId.value)
} else {
getGreyedOutIconRes(value)
getGreyedOutIconRes(rawId.value)
}

View file

@ -76,7 +76,7 @@ internal class UpdateDataStateTransformer(
private fun List<NFTCollection>.transform(state: NFTCollectionsStateUM): ImmutableList<NFTCollectionUM> = map {
NFTCollectionUM(
id = it.collectionIdProvider(),
networkIconId = getActiveIconRes(it.network.id.value),
networkIconId = getActiveIconRes(it.network.rawId),
name = it.name.orEmpty(),
description = TextReference.PluralRes(
R.plurals.nft_collections_count,

View file

@ -22,7 +22,7 @@ class DefaultNFTDetailsBlockComponent @AssistedInject constructor(
assetName = stringReference(params.nftAsset.name.orEmpty()),
collectionName = stringReference(params.nftCollectionName),
assetImage = params.nftAsset.media?.url,
networkIconRes = getActiveIconRes(params.nftAsset.network.id.value),
networkIconRes = getActiveIconRes(params.nftAsset.network.rawId),
)
}

View file

@ -33,13 +33,13 @@ internal class UpdateDataStateTransformer(
private fun Network.transform(enabled: Boolean): NFTNetworkUM {
val custom = derivationPath is Network.DerivationPath.Custom
return NFTNetworkUM(
id = id.value + derivationPath.value,
id = rawId + derivationPath.value,
chainRowUM = ChainRowUM(
name = name,
type = "",
icon = CurrencyIconState.CoinIcon(
url = null,
fallbackResId = getActiveIconRes(id.value),
fallbackResId = getActiveIconRes(rawId),
isGrayscale = !enabled,
showCustomBadge = custom,
),

View file

@ -256,7 +256,7 @@ internal class SendConfirmModel @Inject constructor(
saveBlockchainErrorUseCase(
error = BlockchainErrorInfo(
errorMessage = errorMessage,
blockchainId = cryptoCurrency.network.id.value,
blockchainId = cryptoCurrency.network.rawId,
derivationPath = cryptoCurrency.network.derivationPath.value,
destinationAddress = confirmData.enteredDestination.orEmpty(),
tokenSymbol = if (amount?.type is AmountType.Token) {

View file

@ -23,8 +23,8 @@ import com.tangem.domain.feedback.models.FeedbackEmailType
import com.tangem.domain.qrscanning.models.SourceType
import com.tangem.domain.qrscanning.usecases.ListenToQrScanningUseCase
import com.tangem.domain.qrscanning.usecases.ParseQrCodeUseCase
import com.tangem.domain.tokens.GetSingleCryptoCurrencyStatusUseCase
import com.tangem.domain.tokens.GetFeePaidCryptoCurrencyStatusSyncUseCase
import com.tangem.domain.tokens.GetSingleCryptoCurrencyStatusUseCase
import com.tangem.domain.tokens.error.CurrencyStatusError
import com.tangem.domain.tokens.model.CryptoCurrencyStatus
import com.tangem.domain.transaction.error.GetFeeError
@ -301,7 +301,7 @@ internal class SendModel @Inject constructor(
saveBlockchainErrorUseCase(
error = BlockchainErrorInfo(
errorMessage = errorMessage.orEmpty(),
blockchainId = cryptoCurrency.network.id.value,
blockchainId = cryptoCurrency.network.rawId,
derivationPath = cryptoCurrency.network.derivationPath.value,
destinationAddress = "",
tokenSymbol = "",

View file

@ -201,7 +201,7 @@ internal class NFTSendConfirmModel @Inject constructor(
saveBlockchainErrorUseCase(
error = BlockchainErrorInfo(
errorMessage = errorMessage,
blockchainId = cryptoCurrency.network.id.value,
blockchainId = cryptoCurrency.network.rawId,
derivationPath = cryptoCurrency.network.derivationPath.value,
destinationAddress = confirmData.enteredDestination.orEmpty(),
tokenSymbol = null,

View file

@ -19,8 +19,8 @@ import com.tangem.domain.feedback.SendFeedbackEmailUseCase
import com.tangem.domain.feedback.models.BlockchainErrorInfo
import com.tangem.domain.feedback.models.FeedbackEmailType
import com.tangem.domain.tokens.GetCryptoCurrenciesUseCase
import com.tangem.domain.tokens.GetSingleCryptoCurrencyStatusUseCase
import com.tangem.domain.tokens.GetFeePaidCryptoCurrencyStatusSyncUseCase
import com.tangem.domain.tokens.GetSingleCryptoCurrencyStatusUseCase
import com.tangem.domain.tokens.model.CryptoCurrency
import com.tangem.domain.tokens.model.CryptoCurrencyStatus
import com.tangem.domain.transaction.error.GetFeeError
@ -166,7 +166,7 @@ internal class NFTSendModel @Inject constructor(
saveBlockchainErrorUseCase(
error = BlockchainErrorInfo(
errorMessage = errorMessage.orEmpty(),
blockchainId = cryptoCurrency.network.id.value,
blockchainId = cryptoCurrency.network.rawId,
derivationPath = cryptoCurrency.network.derivationPath.value,
destinationAddress = "",
tokenSymbol = null,

View file

@ -30,7 +30,7 @@ internal class BitcoinCustomFeeConverter(
) : CustomFeeConverter<Fee.Bitcoin> {
private val currencyStatus = feeCryptoCurrencyStatus.value
private val network = feeCryptoCurrencyStatus.currency.network.id.value
private val network = feeCryptoCurrencyStatus.currency.network.rawId
override fun convert(value: Fee.Bitcoin): ImmutableList<CustomFeeFieldUM> {
val feeValue = value.amount.value

View file

@ -28,7 +28,7 @@ internal class SendFeeInitialStateTransformer(
isCustomSelected = false,
isFeeConvertibleToFiat = feeCryptoCurrencyStatus.currency.network.hasFiatFeeRate,
isTronToken = cryptoCurrency is CryptoCurrency.Token &&
isTron(cryptoCurrency.network.id.value),
isTron(cryptoCurrency.network.rawId),
)
}
}

View file

@ -255,7 +255,7 @@ internal class NotificationsModel @Inject constructor(
)
},
)
if (!BlockchainUtils.isCardano(currency.network.id.value)) {
if (!BlockchainUtils.isCardano(currency.network.rawId)) {
addDustWarningNotification(
dustValue = currencyCheck.dustValue,
feeValue = feeValue,
@ -375,7 +375,7 @@ internal class NotificationsModel @Inject constructor(
private suspend fun MutableList<NotificationUM>.addTronNetworkFeesNotification() {
val cryptoCurrency = cryptoCurrencyStatus.currency
val isTronToken = cryptoCurrency is CryptoCurrency.Token &&
isTron(cryptoCurrency.network.id.value)
isTron(cryptoCurrency.network.rawId)
if (isTronToken && getTronFeeNotificationShowCountUseCase() <= TRON_FEE_NOTIFICATION_MAX_SHOW_COUNT) {
add(

View file

@ -592,7 +592,7 @@ internal class SendModel @Inject constructor(
saveBlockchainErrorUseCase(
error = BlockchainErrorInfo(
errorMessage = errorMessage,
blockchainId = cryptoCurrency.network.id.value,
blockchainId = cryptoCurrency.network.rawId,
derivationPath = cryptoCurrency.network.derivationPath.value,
destinationAddress = recipient.orEmpty(),
tokenSymbol = if (amount?.type is AmountType.Token) {
@ -742,7 +742,7 @@ internal class SendModel @Inject constructor(
}
private suspend fun checkIfXrpAddressValue(value: String): Boolean {
return BlockchainUtils.decodeRippleXAddress(value, cryptoCurrency.network.id.value)?.let { decodedAddress ->
return BlockchainUtils.decodeRippleXAddress(value, cryptoCurrency.network.rawId)?.let { decodedAddress ->
uiState.value =
recipientStateFactory.onRecipientAddressValueChange(value, isXAddress = true, isValuePasted = true)
uiState.value = recipientStateFactory.getOnXAddressMemoState()

View file

@ -213,7 +213,7 @@ internal class SendNotificationFactory(
)
},
)
if (!BlockchainUtils.isCardano(currency.network.id.value)) {
if (!BlockchainUtils.isCardano(currency.network.rawId)) {
addDustWarningNotification(
dustValue = currencyCheck.dustValue,
feeValue = feeValue,
@ -306,7 +306,7 @@ internal class SendNotificationFactory(
) {
val cryptoCurrencyStatus = cryptoCurrencyStatusProvider()
val balance = cryptoCurrencyStatus.value.amount ?: BigDecimal.ZERO
val isTezos = isTezos(cryptoCurrencyStatus.currency.network.id.value)
val isTezos = isTezos(cryptoCurrencyStatus.currency.network.rawId)
val threshold = getTezosThreshold()
val isTotalBalance = sendAmount >= balance && balance > threshold
if (!ignoreAmountReduce && isTotalBalance && isTezos) {
@ -356,7 +356,7 @@ internal class SendNotificationFactory(
private suspend fun MutableList<NotificationUM>.addTronNetworkFeesNotification() {
val cryptoCurrency = cryptoCurrencyStatusProvider().currency
val isTronToken = cryptoCurrency is CryptoCurrency.Token &&
isTron(cryptoCurrency.network.id.value)
isTron(cryptoCurrency.network.rawId)
if (isTronToken && getTronFeeNotificationShowCountUseCase() <= TRON_FEE_NOTIFICATION_MAX_SHOW_COUNT) {
add(

View file

@ -26,7 +26,7 @@ internal class SendFeeStateConverter(
isCustomSelected = false,
isFeeConvertibleToFiat = cryptoCurrencyStatusProvider().currency.network.hasFiatFeeRate,
isTronToken = cryptoCurrencyStatusProvider().currency is CryptoCurrency.Token &&
isTron(cryptoCurrencyStatusProvider().currency.network.id.value),
isTron(cryptoCurrencyStatusProvider().currency.network.rawId),
)
}
}

View file

@ -12,10 +12,10 @@ import com.tangem.core.ui.utils.parseToBigDecimal
import com.tangem.domain.appcurrency.model.AppCurrency
import com.tangem.domain.tokens.model.CryptoCurrencyStatus
import com.tangem.features.send.impl.R
import com.tangem.features.send.impl.presentation.model.SendClickIntents
import com.tangem.features.send.impl.presentation.state.StateRouter
import com.tangem.features.send.impl.presentation.state.fee.checkExceedBalance
import com.tangem.features.send.impl.presentation.state.fields.SendTextField
import com.tangem.features.send.impl.presentation.model.SendClickIntents
import com.tangem.lib.crypto.BlockchainUtils.isUseBitcoinFeeConverter
import com.tangem.utils.Provider
import kotlinx.collections.immutable.ImmutableList
@ -34,7 +34,7 @@ internal class BitcoinCustomFeeConverter(
override fun convert(value: Fee.Bitcoin): ImmutableList<SendTextField.CustomFee> {
val feeValue = value.amount.value
val feeCurrency = feeCryptoCurrencyStatusProvider()?.value
val network = feeCryptoCurrencyStatusProvider()?.currency?.network?.id?.value
val network = feeCryptoCurrencyStatusProvider()?.currency?.network?.rawId
return if (network != null && isUseBitcoinFeeConverter(network)) {
persistentListOf(
SendTextField.CustomFee(

View file

@ -12,8 +12,8 @@ import com.tangem.core.ui.utils.parseToBigDecimal
import com.tangem.domain.appcurrency.model.AppCurrency
import com.tangem.domain.tokens.model.CryptoCurrencyStatus
import com.tangem.features.send.impl.R
import com.tangem.features.send.impl.presentation.state.fields.SendTextField
import com.tangem.features.send.impl.presentation.model.SendClickIntents
import com.tangem.features.send.impl.presentation.state.fields.SendTextField
import com.tangem.utils.Provider
import kotlinx.collections.immutable.ImmutableList
import kotlinx.collections.immutable.persistentListOf
@ -29,7 +29,7 @@ internal class KaspaCustomFeeConverter(
override fun convert(value: Fee.Kaspa): ImmutableList<SendTextField.CustomFee> {
val feeValue = value.amount.value
val feeCurrency = feeCryptoCurrencyStatusProvider()?.value
val network = feeCryptoCurrencyStatusProvider()?.currency?.network?.id?.value
val network = feeCryptoCurrencyStatusProvider()?.currency?.network?.rawId
return if (network != null) {
persistentListOf(
SendTextField.CustomFee(

View file

@ -549,7 +549,7 @@ internal class StakingModel @Inject constructor(
}
override fun onActiveStake(activeStake: BalanceState) {
val networkId = cryptoCurrencyStatus.currency.network.id.value
val networkId = cryptoCurrencyStatus.currency.network.rawId
if (isSingleAction(networkId, activeStake)) {
prepareForConfirmation(
balanceType = activeStake.type,
@ -854,7 +854,7 @@ internal class StakingModel @Inject constructor(
saveBlockchainErrorUseCase(
error = BlockchainErrorInfo(
errorMessage = errorMessage,
blockchainId = network.id.value,
blockchainId = network.rawId,
derivationPath = network.derivationPath.value,
destinationAddress = validator?.address.orEmpty(),
tokenSymbol = (cryptoCurrencyStatus.currency as? CryptoCurrency.Token)?.symbol,

View file

@ -73,7 +73,7 @@ internal class BalanceItemConverter(
private fun BalanceItem.getBalanceValue(): BigDecimal {
val isIncludeStakingTotalBalance = BlockchainUtils.isIncludeStakingTotalBalance(
blockchainId = cryptoCurrencyStatus.currency.network.id.value,
blockchainId = cryptoCurrencyStatus.currency.network.rawId,
)
val yieldBalance = cryptoCurrencyStatus.value.yieldBalance as? YieldBalance.Data
return if (isIncludeStakingTotalBalance) {

View file

@ -78,7 +78,7 @@ internal class YieldBalancesConverter(
.toPersistentList()
private fun getRewardBlockType(): RewardBlockType {
val blockchainId = cryptoCurrencyStatus.currency.network.id.value
val blockchainId = cryptoCurrencyStatus.currency.network.rawId
val yieldBalance = cryptoCurrencyStatus.value.yieldBalance as? YieldBalance.Data
val rewards = yieldBalance?.balance?.items
?.filter { it.type == BalanceType.REWARDS && !it.amount.isZero() }

View file

@ -102,7 +102,7 @@ internal class StakingFeeTransactionLoader @AssistedInject constructor(
?: error("No available address")
val gasEstimate = if (isCompositePendingActions(
networkId = cryptoCurrencyStatus.currency.network.id.value,
networkId = cryptoCurrencyStatus.currency.network.rawId,
pendingActions = pendingActions,
)
) {

View file

@ -120,8 +120,8 @@ internal class StakingTransactionSender @AssistedInject constructor(
onConstructError: (StakingError) -> Unit,
) = coroutineScope {
val isComposePendingActions = isCompositePendingActions(
cryptoCurrencyStatus.currency.network.id.value,
confirmationState.pendingActions,
networkId = cryptoCurrencyStatus.currency.network.rawId,
pendingActions = confirmationState.pendingActions,
)
if (isComposePendingActions) {
confirmationState.pendingActions?.map { action ->
@ -156,7 +156,7 @@ internal class StakingTransactionSender @AssistedInject constructor(
?.map { transaction ->
async {
getConstructedStakingTransactionUseCase(
networkId = cryptoCurrencyStatus.currency.network.id.value,
networkId = cryptoCurrencyStatus.currency.network.rawId,
fee = fee,
amount = amount.convertToSdkAmount(cryptoCurrencyStatus.currency),
transactionId = transaction.id,

View file

@ -30,7 +30,7 @@ internal class SetConfirmationStateInitTransformer(
) : Transformer<StakingUiState> {
private val networkId
get() = cryptoCurrencyStatus.currency.network.id.value
get() = cryptoCurrencyStatus.currency.network.rawId
private val isComposePendingActions
get() = isCompositePendingActions(networkId, pendingActions)

View file

@ -11,7 +11,9 @@ import com.tangem.domain.staking.model.stakekit.Yield
import com.tangem.domain.staking.model.stakekit.action.StakingActionCommonType
import com.tangem.domain.tokens.model.CryptoCurrency
import com.tangem.features.staking.impl.R
import com.tangem.features.staking.impl.presentation.state.*
import com.tangem.features.staking.impl.presentation.state.FeeState
import com.tangem.features.staking.impl.presentation.state.StakingStates
import com.tangem.features.staking.impl.presentation.state.StakingUiState
import com.tangem.features.staking.impl.presentation.state.utils.getRewardScheduleText
import com.tangem.utils.transformer.Transformer
@ -47,7 +49,7 @@ internal class SetConfirmationStateLoadingTransformer(
}
val rewardSchedule = getRewardScheduleText(
rewardSchedule = yield.metadata.rewardSchedule,
networkId = cryptoCurrency.network.id.value,
networkId = cryptoCurrency.network.rawId,
decapitalize = true,
)
return if (isEnterAction && amountDecimal != null && rewardSchedule != null) {

View file

@ -67,7 +67,7 @@ internal class SetInitialDataStateTransformer(
title = TextReference.EMPTY,
cryptoCurrencyName = cryptoCurrency.name,
cryptoCurrencySymbol = cryptoCurrency.symbol,
cryptoCurrencyBlockchainId = cryptoCurrency.network.id.value,
cryptoCurrencyBlockchainId = cryptoCurrency.network.rawId,
clickIntents = clickIntents,
currentStep = StakingStep.InitialInfo,
initialInfoState = createInitialInfoState(),
@ -150,7 +150,7 @@ internal class SetInitialDataStateTransformer(
cryptoCurrencyStatus: CryptoCurrencyStatus,
): RoundedListWithDividersItemData? {
val minimumCryptoAmount = yield.args.enter.args[Yield.Args.ArgType.AMOUNT]?.minimum ?: return null
val blockchainId = cryptoCurrencyStatus.currency.network.id.value
val blockchainId = cryptoCurrencyStatus.currency.network.rawId
if (!showMinimumRequirementInfo(blockchainId)) return null
val formattedAmount = minimumCryptoAmount.format { crypto(cryptoCurrencyStatus.currency) }
@ -193,7 +193,7 @@ internal class SetInitialDataStateTransformer(
private fun createRewardScheduleItem(): RoundedListWithDividersItemData? {
val endTextReference = getRewardScheduleText(
rewardSchedule = yield.metadata.rewardSchedule,
networkId = cryptoCurrencyStatus.currency.network.id.value,
networkId = cryptoCurrencyStatus.currency.network.rawId,
decapitalize = false,
) ?: return null

View file

@ -111,7 +111,7 @@ internal class AmountRequirementStateTransformer(
val cryptoAmountValue = amountState.amountTextField.cryptoAmount.value ?: return false
val isEnterOrExit = actionType is StakingActionCommonType.Enter || actionType is StakingActionCommonType.Exit
val isTron = isTron(cryptoCurrencyStatus.currency.network.id.value)
val isTron = isTron(cryptoCurrencyStatus.currency.network.rawId)
val isIntegerOnly = cryptoAmountValue.isZero() || cryptoAmountValue.remainder(BigDecimal.ONE).isZero()

View file

@ -188,7 +188,7 @@ internal class AddStakingNotificationsTransformer(
onClick = prevState.clickIntents::openTokenDetails,
onAnalyticsEvent = { /* no-op */ },
)
if (!BlockchainUtils.isCardano(network.id.value)) {
if (!BlockchainUtils.isCardano(network.rawId)) {
addDustWarningNotification(
dustValue = currencyCheck.dustValue,
feeValue = feeValue,
@ -278,7 +278,7 @@ internal class AddStakingNotificationsTransformer(
private fun MutableList<NotificationUM>.addTonUnstakeNotification(actionType: StakingActionCommonType) {
val amount = cryptoCurrencyStatusProvider().value.amount.orZero()
val cryptoCurrencyNetworkIdValue = cryptoCurrencyStatusProvider().currency.network.id.value
val cryptoCurrencyNetworkIdValue = cryptoCurrencyStatusProvider().currency.network.rawId
if (isTon(cryptoCurrencyNetworkIdValue) && actionType !is StakingActionCommonType.Enter) {
val notification = if (amount < TON_BALANCE_EXTRA_FEE_THRESHOLD) {

View file

@ -59,7 +59,7 @@ internal class StakingInfoNotificationsFactory(
private fun MutableList<NotificationUM>.addExitInfoNotifications(prevState: StakingUiState) {
val cooldownPeriodDays = yield.metadata.cooldownPeriod?.days
val cryptoCurrencyNetworkIdValue = cryptoCurrencyStatusProvider().currency.network.id.value
val cryptoCurrencyNetworkIdValue = cryptoCurrencyStatusProvider().currency.network.rawId
if (cooldownPeriodDays != null) {
add(
StakingNotification.Info.Unstake(
@ -155,7 +155,7 @@ internal class StakingInfoNotificationsFactory(
private fun MutableList<NotificationUM>.addTronRevoteNotification() {
val cryptoCurrencyStatus = cryptoCurrencyStatusProvider()
val isTron = isTron(cryptoCurrencyStatus.currency.network.id.value)
val isTron = isTron(cryptoCurrencyStatus.currency.network.rawId)
val hasStakedBalance = (cryptoCurrencyStatus.value.yieldBalance as? YieldBalance.Data)?.balance
?.items?.any {
it.type == BalanceType.PREPARING ||
@ -174,7 +174,7 @@ internal class StakingInfoNotificationsFactory(
private fun MutableList<NotificationUM>.addCardanoStakeNotification() {
val cryptoCurrencyStatus = cryptoCurrencyStatusProvider()
val isCardano = isCardano(cryptoCurrencyStatus.currency.network.id.value)
val isCardano = isCardano(cryptoCurrencyStatus.currency.network.rawId)
if (isCardano) {
add(
@ -188,7 +188,7 @@ internal class StakingInfoNotificationsFactory(
private fun MutableList<NotificationUM>.addCardanoStakeMinimumAmountNotification(feeValue: BigDecimal) {
val cryptoCurrencyStatus = cryptoCurrencyStatusProvider()
val isCardano = isCardano(cryptoCurrencyStatus.currency.network.id.value)
val isCardano = isCardano(cryptoCurrencyStatus.currency.network.rawId)
val balance = cryptoCurrencyStatus.value.amount.orZero()
if (isCardano && balance - feeValue < MINIMUM_STAKE_BALANCE) {
add(
@ -202,7 +202,7 @@ internal class StakingInfoNotificationsFactory(
private fun MutableList<NotificationUM>.addCardanoRestakeMinimumAmountNotification(feeValue: BigDecimal) {
val cryptoCurrencyStatus = cryptoCurrencyStatusProvider()
val isCardano = isCardano(cryptoCurrencyStatus.currency.network.id.value)
val isCardano = isCardano(cryptoCurrencyStatus.currency.network.rawId)
val balance = cryptoCurrencyStatus.value.amount.orZero()
if (isCardano && balance - feeValue < MINIMUM_RESTAKE_BALANCE) {
add(
@ -223,7 +223,7 @@ internal class StakingInfoNotificationsFactory(
val isEntireBalance = sendingAmount.plus(feeValue) == balance
if (isEntireBalance && isSubtractAvailable && !isCardano(cryptoCurrencyStatus.currency.network.id.value)) {
if (isEntireBalance && isSubtractAvailable && !isCardano(cryptoCurrencyStatus.currency.network.rawId)) {
add(StakingNotification.Info.StakeEntireBalance)
}
}

View file

@ -17,7 +17,7 @@ internal fun checkAndCalculateSubtractedAmount(
reduceAmountBy: BigDecimal,
): BigDecimal {
val balance = cryptoCurrencyStatus.value.amount ?: return amountValue
val isTron = isTron(cryptoCurrencyStatus.currency.network.id.value)
val isTron = isTron(cryptoCurrencyStatus.currency.network.rawId)
val feeValueRounded = if (isTron) {
feeValue.round(MathContext(0, RoundingMode.UP))
} else {
@ -32,7 +32,7 @@ internal fun checkAndCalculateSubtractedAmount(
)
return if (isFeeCoverage) {
val reducedAmount = balance.minus(reduceAmountBy).minus(feeValueRounded)
if (isTron(cryptoCurrencyStatus.currency.network.id.value)) {
if (isTron(cryptoCurrencyStatus.currency.network.rawId)) {
reducedAmount.setScale(0, RoundingMode.DOWN)
} else {
reducedAmount

View file

@ -466,7 +466,7 @@ internal class SwapInteractorImpl @AssistedInject constructor(
is TxFeeState.MultipleFeeState -> feeState.normalFee.feeValue
is TxFeeState.SingleFeeState -> feeState.fee.feeValue
},
blockchain = Blockchain.fromId(currency.network.id.value),
blockchain = Blockchain.fromId(currency.network.rawId),
),
)
@ -1387,7 +1387,7 @@ internal class SwapInteractorImpl @AssistedInject constructor(
val callData = SmartContractCallDataProviderFactory.getApprovalCallData(
spenderAddress = requireNotNull(spenderAddress) { "Spender address is null" },
amount = swapAmount.value.convertToSdkAmount(fromToken),
blockchain = Blockchain.fromId(fromToken.network.id.value),
blockchain = Blockchain.fromId(fromToken.network.rawId),
)
val feeData = try {
val extras = createTransactionExtrasUseCase(

View file

@ -1,31 +0,0 @@
package com.tangem.feature.swap.domain.converters
import com.tangem.domain.tokens.model.CryptoCurrency
import com.tangem.lib.crypto.models.Currency
import com.tangem.utils.converter.Converter
class SwapCurrencyConverter : Converter<CryptoCurrency, Currency> {
override fun convert(value: CryptoCurrency): Currency {
return when (value) {
is CryptoCurrency.Token -> {
Currency.NonNativeToken(
id = value.id.value,
name = value.name,
symbol = value.symbol,
networkId = value.network.id.value,
contractAddress = value.contractAddress,
decimalCount = value.decimals,
)
}
is CryptoCurrency.Coin -> {
Currency.NativeToken(
id = value.id.value,
name = value.name,
symbol = value.symbol,
networkId = value.network.id.value,
)
}
}
}
}

View file

@ -1353,7 +1353,7 @@ internal class SwapModel @Inject constructor(
saveBlockchainErrorUseCase(
error = BlockchainErrorInfo(
errorMessage = errorMessage,
blockchainId = network.id.value,
blockchainId = network.rawId,
derivationPath = network.derivationPath.value,
destinationAddress = transaction?.txTo.orEmpty(),
tokenSymbol = fromCurrencyStatus.currency.symbol,
@ -1375,7 +1375,7 @@ internal class SwapModel @Inject constructor(
private fun CryptoCurrency.getNetworkInfo(): NetworkInfo {
return NetworkInfo(
name = this.network.name,
blockchainId = this.network.id.value,
blockchainId = this.network.rawId,
)
}

View file

@ -154,7 +154,7 @@ internal class SwapNotificationsFactory(
}
is TxFeeState.SingleFeeState -> feeState.fee
}
val isCardano = BlockchainUtils.isCardano(fromCurrencyStatus.currency.network.id.value)
val isCardano = BlockchainUtils.isCardano(fromCurrencyStatus.currency.network.rawId)
// blockchain specific
addExistentialWarningNotification(
@ -305,7 +305,7 @@ internal class SwapNotificationsFactory(
fromAmount: SwapAmount,
onReduceByAmount: (SwapAmount, BigDecimal) -> Unit,
) {
val isTezos = isTezos(cryptoCurrencyStatus.currency.network.id.value)
val isTezos = isTezos(cryptoCurrencyStatus.currency.network.rawId)
val balance = cryptoCurrencyStatus.value.amount ?: BigDecimal.ZERO
val threshold = getTezosThreshold()
val isTotalBalance = fromAmount.value >= balance && balance > threshold

View file

@ -29,13 +29,13 @@ import com.tangem.feature.swap.domain.models.domain.IncludeFeeInAmount
import com.tangem.feature.swap.domain.models.domain.NetworkInfo
import com.tangem.feature.swap.domain.models.domain.SwapProvider
import com.tangem.feature.swap.domain.models.ui.*
import com.tangem.feature.swap.model.SwapNotificationsFactory
import com.tangem.feature.swap.model.SwapProcessDataState
import com.tangem.feature.swap.models.*
import com.tangem.feature.swap.models.states.*
import com.tangem.feature.swap.models.states.events.SwapEvent
import com.tangem.feature.swap.presentation.R
import com.tangem.feature.swap.model.SwapNotificationsFactory
import com.tangem.feature.swap.utils.formatToUIRepresentation
import com.tangem.feature.swap.model.SwapProcessDataState
import com.tangem.utils.Provider
import com.tangem.utils.StringsSigns.DASH_SIGN
import com.tangem.utils.StringsSigns.PERCENT
@ -93,7 +93,7 @@ internal class StateBuilder(
canSelectAnotherToken = false,
isNotNativeToken = initialCurrencyFrom is CryptoCurrency.Token,
balance = "",
networkIconRes = getActiveIconRes(initialCurrencyFrom.network.id.value),
networkIconRes = getActiveIconRes(initialCurrencyFrom.network.rawId),
isBalanceHidden = true,
),
receiveCardData = SwapCardState.SwapCardData(
@ -106,7 +106,7 @@ internal class StateBuilder(
canSelectAnotherToken = false,
balance = "",
isNotNativeToken = initialCurrencyTo is CryptoCurrency.Token,
networkIconRes = initialCurrencyTo?.let { getActiveIconRes(it.network.id.value) },
networkIconRes = initialCurrencyTo?.let { getActiveIconRes(it.network.rawId) },
coinId = initialCurrencyTo?.network?.backendId,
isBalanceHidden = true,
),
@ -153,7 +153,7 @@ internal class StateBuilder(
tokenCurrency = uiStateHolder.sendCardData.tokenCurrency,
canSelectAnotherToken = uiStateHolder.sendCardData.canSelectAnotherToken,
balance = fromToken.getFormattedAmount(isNeedSymbol = false),
networkIconRes = getActiveIconRes(fromToken.currency.network.id.value),
networkIconRes = getActiveIconRes(fromToken.currency.network.rawId),
isBalanceHidden = isBalanceHiddenProvider(),
),
receiveCardData = SwapCardState.Empty(
@ -206,7 +206,7 @@ internal class StateBuilder(
isNotNativeToken = fromToken is CryptoCurrency.Token,
canSelectAnotherToken = canSelectSendToken,
balance = if (!canSelectSendToken) uiStateHolder.sendCardData.balance else "",
networkIconRes = getActiveIconRes(fromToken.network.id.value),
networkIconRes = getActiveIconRes(fromToken.network.rawId),
isBalanceHidden = isBalanceHiddenProvider(),
),
receiveCardData = SwapCardState.SwapCardData(
@ -220,7 +220,7 @@ internal class StateBuilder(
isNotNativeToken = toToken is CryptoCurrency.Token,
canSelectAnotherToken = canSelectReceiveToken,
balance = if (!canSelectReceiveToken) uiStateHolder.receiveCardData.balance else "",
networkIconRes = getActiveIconRes(toToken.network.id.value),
networkIconRes = getActiveIconRes(toToken.network.rawId),
isBalanceHidden = isBalanceHiddenProvider(),
),
notifications = persistentListOf(),

View file

@ -31,7 +31,7 @@ internal class TokenDetailsBalanceSelectStateConverter(
val yieldBalance = cryptoCurrencyStatus.value.yieldBalance as? YieldBalance.Data
val stakingCryptoAmount = yieldBalance?.getTotalWithRewardsStakingBalance(
cryptoCurrencyStatus.currency.network.id.value,
cryptoCurrencyStatus.currency.network.rawId,
)
val stakingFiatAmount = stakingCryptoAmount?.let { cryptoCurrencyStatus.value.fiatRate?.multiply(it) }
copy(

View file

@ -88,7 +88,7 @@ internal class TokenDetailsLoadedBalanceConverter(
): TokenDetailsBalanceBlockState {
val stakingCryptoAmount =
(status.value.yieldBalance as? YieldBalance.Data)?.getTotalWithRewardsStakingBalance(
status.currency.network.id.value,
status.currency.network.rawId,
)
val stakingFiatAmount = stakingCryptoAmount?.let { status.value.fiatRate?.multiply(it) }
val isBalanceSelectorEnabled = !stakingCryptoAmount.isNullOrZero()

View file

@ -98,7 +98,7 @@ internal class TokenDetailsSkeletonStateConverter(
private fun MutableList<TangemDropdownMenuItem>.addGenerateXPubMenuItem(cryptoCurrency: CryptoCurrency) {
val userWallet = getUserWalletUseCase(userWalletId).getOrNull() ?: return
val isBitcoin = isBitcoin(cryptoCurrency.network.id.value)
val isBitcoin = isBitcoin(cryptoCurrency.network.rawId)
val hasDerivations = networkHasDerivationUseCase(
scanResponse = userWallet.scanResponse,
network = cryptoCurrency.network,

View file

@ -56,7 +56,7 @@ internal class TokenDetailsStakingInfoConverter(
private fun getStakingInfoBlock(status: CryptoCurrencyStatus, state: TokenDetailsState): StakingBlockUM? {
val yieldBalance = status.value.yieldBalance as? YieldBalance.Data
val stakingCryptoAmount = yieldBalance?.getTotalStakingBalance(status.currency.network.id.value)
val stakingCryptoAmount = yieldBalance?.getTotalStakingBalance(status.currency.network.rawId)
val pendingBalances = yieldBalance?.balance?.items ?: emptyList()
val iconState = state.tokenInfoBlockState.iconState
@ -144,7 +144,7 @@ internal class TokenDetailsStakingInfoConverter(
}
private fun getRewardText(status: CryptoCurrencyStatus, stakingRewardAmount: BigDecimal?): TextReference {
val blockchainId = status.currency.network.id.value
val blockchainId = status.currency.network.rawId
val rewardBlockType = when {
isSolana(blockchainId) || isBSC(blockchainId) -> RewardBlockType.RewardUnavailable
stakingRewardAmount.isNullOrZero() -> RewardBlockType.NoRewards

View file

@ -85,7 +85,7 @@ class ExpressStatusBottomSheetStateProvider : PreviewParameterProvider<ExpressSt
get() = CryptoCurrency.Coin(
id = ID(
ID.Prefix.COIN_PREFIX,
ID.Body.NetworkId(network.id.value),
ID.Body.NetworkId(network.rawId),
ID.Suffix.RawID("token1"),
),
network = network,
@ -97,7 +97,7 @@ class ExpressStatusBottomSheetStateProvider : PreviewParameterProvider<ExpressSt
)
private val network = Network(
id = Network.ID("network1"),
id = Network.ID(value = "network1", derivationPath = Network.DerivationPath.None),
name = "Network One",
isTestnet = false,
standardType = Network.StandardType.ERC20,

View file

@ -65,7 +65,7 @@ internal class CryptoCurrencyToDraggableItemConverter(
private fun getFormattedFiatAmount(currency: CryptoCurrencyStatus, appCurrency: AppCurrency): String {
val yieldBalance = currency.value.yieldBalance as? YieldBalance.Data
val fiatRate = currency.value.fiatRate ?: BigDecimal.ZERO
val fiatYieldBalance = yieldBalance?.getTotalWithRewardsStakingBalance(currency.currency.network.id.value)
val fiatYieldBalance = yieldBalance?.getTotalWithRewardsStakingBalance(currency.currency.network.rawId)
?.multiply(fiatRate).orZero()
val fiatAmount = currency.value.fiatAmount ?: return BigDecimalFormatConstants.EMPTY_BALANCE_SIGN

View file

@ -96,7 +96,7 @@ internal class WcAppInfoModel @Inject constructor(
),
)
// TODO: [REDACTED_JIRA] Change it to UiManager
private val tempAvailableNetworksState = MutableStateFlow<Set<Network.ID>>(setOf())
private val tempAvailableNetworksState = MutableStateFlow<Set<Network.RawID>>(setOf())
init {
loadDAppInfo()
@ -157,7 +157,7 @@ internal class WcAppInfoModel @Inject constructor(
private fun onConnect() {
val enabledAvailableNetworks =
proposalNetwork.available.filter { network -> network.id in tempAvailableNetworksState.value }
proposalNetwork.available.filter { network -> network.id.rawId in tempAvailableNetworksState.value }
wcPairUseCase.approve(
WcSessionApprove(
wallet = selectedUserWalletFlow.value,
@ -191,7 +191,7 @@ internal class WcAppInfoModel @Inject constructor(
private fun onCheckedChange(isChecked: Boolean, networkId: String) {
tempAvailableNetworksState.update {
if (isChecked) it.plus(Network.ID(networkId)) else it.minus(Network.ID(networkId))
if (isChecked) it.plus(Network.RawID(networkId)) else it.minus(Network.RawID(networkId))
}
networksState.transformerUpdate(WcSelectNetworksCheckedTransformer(networkId, isChecked))
}

View file

@ -61,7 +61,7 @@ internal class WcConnectedAppInfoModel @Inject constructor(
networks = session.networks
.map {
WcNetworkInfoItem.Required(
id = it.id.value,
id = it.rawId,
icon = it.iconResId,
name = it.name,
symbol = it.currencySymbol,

View file

@ -19,7 +19,7 @@ internal object WcNetworksInfoConverter : Converter<WcSessionProposal.ProposalNe
items = (value.required + value.available)
.map {
WcNetworkInfoItem.Required(
id = it.id.value,
id = it.rawId,
icon = it.iconResId,
name = it.name,
symbol = it.currencySymbol,

View file

@ -16,7 +16,7 @@ internal class WcSelectNetworksTransformer(
return prevState.copy(
missing = proposalNetwork.missingRequired.map { network ->
WcNetworkInfoItem.Required(
id = network.id.value,
id = network.rawId,
icon = network.iconResId,
name = network.name,
symbol = network.currencySymbol,
@ -24,7 +24,7 @@ internal class WcSelectNetworksTransformer(
}.toImmutableList(),
required = proposalNetwork.required.map { network ->
WcNetworkInfoItem.Checked(
id = network.id.value,
id = network.rawId,
icon = network.iconResId,
name = network.name,
symbol = network.currencySymbol,
@ -32,18 +32,18 @@ internal class WcSelectNetworksTransformer(
}.toImmutableList(),
available = proposalNetwork.available.map { network ->
WcNetworkInfoItem.Checkable(
id = network.id.value,
id = network.rawId,
icon = network.iconResId,
name = network.name,
symbol = network.currencySymbol,
checked = false,
onCheckedChange = { onCheckedChange(it, network.id.value) },
onCheckedChange = { onCheckedChange(it, network.rawId) },
)
}.toImmutableList(),
notAdded = proposalNetwork.notAdded.map { network ->
WcNetworkInfoItem.ReadOnly(
id = network.id.value,
icon = getGreyedOutIconRes(network.id.value),
id = network.rawId,
icon = getGreyedOutIconRes(network.rawId),
name = network.name,
symbol = network.currencySymbol,
)

Some files were not shown because too many files have changed in this diff Show more