Updated on 2026-08-14
This commit is contained in:
parent
99f62f79ee
commit
cb50b7cf07
15 changed files with 162 additions and 124 deletions
|
|
@ -20,6 +20,7 @@ import com.tangem.blockchain.nft.models.NFTAsset
|
|||
import com.tangem.blockchain.nft.models.NFTCollection
|
||||
import com.tangem.blockchain.transactionhistory.models.TransactionHistoryRequest
|
||||
import com.tangem.blockchainsdk.BlockchainSDKFactory
|
||||
import com.tangem.blockchainsdk.models.UpdateWalletManagerResult
|
||||
import com.tangem.blockchainsdk.utils.toBlockchain
|
||||
import com.tangem.crypto.hdWallet.DerivationPath
|
||||
import com.tangem.datasource.asset.loader.AssetLoader
|
||||
|
|
@ -36,7 +37,6 @@ import com.tangem.domain.txhistory.models.TxHistoryState
|
|||
import com.tangem.domain.walletmanager.model.RentData
|
||||
import com.tangem.domain.walletmanager.model.SmartContractMethod
|
||||
import com.tangem.domain.walletmanager.model.TokenInfo
|
||||
import com.tangem.domain.walletmanager.model.UpdateWalletManagerResult
|
||||
import com.tangem.domain.walletmanager.utils.*
|
||||
import com.tangem.domain.walletmanager.utils.WalletManagerFactory
|
||||
import com.tangem.domain.wallets.models.UserWallet
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@ import com.tangem.blockchain.extensions.Result
|
|||
import com.tangem.blockchain.extensions.SimpleResult
|
||||
import com.tangem.blockchain.nft.models.NFTAsset
|
||||
import com.tangem.blockchain.nft.models.NFTCollection
|
||||
import com.tangem.blockchainsdk.models.UpdateWalletManagerResult
|
||||
import com.tangem.domain.models.currency.CryptoCurrency
|
||||
import com.tangem.domain.models.network.Network
|
||||
import com.tangem.domain.models.network.TxInfo
|
||||
|
|
@ -20,7 +21,6 @@ import com.tangem.domain.txhistory.models.PaginationWrapper
|
|||
import com.tangem.domain.txhistory.models.TxHistoryState
|
||||
import com.tangem.domain.walletmanager.model.RentData
|
||||
import com.tangem.domain.walletmanager.model.TokenInfo
|
||||
import com.tangem.domain.walletmanager.model.UpdateWalletManagerResult
|
||||
import com.tangem.domain.wallets.models.UserWalletId
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import java.math.BigDecimal
|
||||
|
|
|
|||
|
|
@ -1,11 +0,0 @@
|
|||
package com.tangem.domain.walletmanager.model
|
||||
|
||||
data class Address(
|
||||
val value: String,
|
||||
val type: Type,
|
||||
) {
|
||||
|
||||
enum class Type {
|
||||
Primary, Secondary,
|
||||
}
|
||||
}
|
||||
|
|
@ -1,17 +0,0 @@
|
|||
package com.tangem.domain.walletmanager.model
|
||||
|
||||
import com.tangem.domain.models.currency.CryptoCurrency
|
||||
import java.math.BigDecimal
|
||||
|
||||
sealed class CryptoCurrencyAmount {
|
||||
|
||||
abstract val value: BigDecimal
|
||||
|
||||
data class Coin(override val value: BigDecimal) : CryptoCurrencyAmount()
|
||||
|
||||
data class Token(
|
||||
val tokenId: CryptoCurrency.RawID?,
|
||||
val tokenContractAddress: String,
|
||||
override val value: BigDecimal,
|
||||
) : CryptoCurrencyAmount()
|
||||
}
|
||||
|
|
@ -1,17 +0,0 @@
|
|||
package com.tangem.domain.walletmanager.model
|
||||
|
||||
import com.tangem.domain.models.network.TxInfo
|
||||
|
||||
// TODO: [REDACTED_JIRA] move to txhistory module
|
||||
sealed class CryptoCurrencyTransaction {
|
||||
|
||||
abstract val txInfo: TxInfo
|
||||
|
||||
data class Coin(override val txInfo: TxInfo) : CryptoCurrencyTransaction()
|
||||
|
||||
data class Token(
|
||||
val tokenId: String?,
|
||||
val tokenContractAddress: String,
|
||||
override val txInfo: TxInfo,
|
||||
) : CryptoCurrencyTransaction()
|
||||
}
|
||||
|
|
@ -1,27 +0,0 @@
|
|||
package com.tangem.domain.walletmanager.model
|
||||
|
||||
import java.math.BigDecimal
|
||||
|
||||
sealed class UpdateWalletManagerResult {
|
||||
|
||||
data object MissedDerivation : UpdateWalletManagerResult()
|
||||
|
||||
data class Unreachable(
|
||||
val selectedAddress: String? = null,
|
||||
val addresses: Set<Address>? = null,
|
||||
) : UpdateWalletManagerResult()
|
||||
|
||||
data class Verified(
|
||||
val selectedAddress: String,
|
||||
val addresses: Set<Address>,
|
||||
val currenciesAmounts: Set<CryptoCurrencyAmount>,
|
||||
val currentTransactions: Set<CryptoCurrencyTransaction>,
|
||||
) : UpdateWalletManagerResult()
|
||||
|
||||
data class NoAccount(
|
||||
val selectedAddress: String,
|
||||
val addresses: Set<Address>,
|
||||
val amountToCreateAccount: BigDecimal,
|
||||
val errorMessage: String,
|
||||
) : UpdateWalletManagerResult()
|
||||
}
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
package com.tangem.domain.walletmanager.utils
|
||||
|
||||
import com.tangem.blockchain.common.address.AddressType
|
||||
import com.tangem.domain.walletmanager.model.Address
|
||||
import com.tangem.blockchainsdk.models.UpdateWalletManagerResult.Address
|
||||
import com.tangem.utils.converter.Converter
|
||||
import com.tangem.blockchain.common.address.Address as SdkAddress
|
||||
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
package com.tangem.domain.walletmanager.utils
|
||||
|
||||
import com.tangem.blockchain.common.*
|
||||
import com.tangem.blockchainsdk.models.UpdateWalletManagerResult.Address
|
||||
import com.tangem.domain.models.network.TxInfo
|
||||
import com.tangem.domain.walletmanager.model.Address
|
||||
import com.tangem.utils.converter.Converter
|
||||
import timber.log.Timber
|
||||
import java.math.BigDecimal
|
||||
|
|
|
|||
|
|
@ -1,25 +1,23 @@
|
|||
package com.tangem.domain.walletmanager.utils
|
||||
|
||||
import com.tangem.blockchain.common.*
|
||||
import com.tangem.blockchainsdk.models.UpdateWalletManagerResult
|
||||
import com.tangem.blockchainsdk.models.UpdateWalletManagerResult.*
|
||||
import com.tangem.blockchainsdk.utils.amountToCreateAccount
|
||||
import com.tangem.domain.models.currency.CryptoCurrency
|
||||
import com.tangem.domain.walletmanager.model.Address
|
||||
import com.tangem.domain.walletmanager.model.CryptoCurrencyAmount
|
||||
import com.tangem.domain.walletmanager.model.CryptoCurrencyTransaction
|
||||
import com.tangem.domain.walletmanager.model.UpdateWalletManagerResult
|
||||
import timber.log.Timber
|
||||
import java.math.BigDecimal
|
||||
import com.tangem.blockchain.common.address.Address as SdkAddress
|
||||
|
||||
internal class UpdateWalletManagerResultFactory {
|
||||
|
||||
fun getResult(walletManager: WalletManager): UpdateWalletManagerResult.Verified {
|
||||
fun getResult(walletManager: WalletManager): Verified {
|
||||
val wallet = walletManager.wallet
|
||||
val addresses = getAvailableAddresses(wallet.addresses)
|
||||
val feePaidCurrency = wallet.blockchain.feePaidCurrency()
|
||||
val txHistoryItemConverter = TransactionDataToTxHistoryItemConverter(addresses, feePaidCurrency)
|
||||
|
||||
return UpdateWalletManagerResult.Verified(
|
||||
return Verified(
|
||||
selectedAddress = wallet.address,
|
||||
addresses = addresses,
|
||||
currenciesAmounts = getTokensAmounts(wallet.amounts.values.toSet()),
|
||||
|
|
@ -27,13 +25,13 @@ internal class UpdateWalletManagerResultFactory {
|
|||
)
|
||||
}
|
||||
|
||||
fun getDemoResult(walletManager: WalletManager, demoAmount: Amount): UpdateWalletManagerResult.Verified {
|
||||
fun getDemoResult(walletManager: WalletManager, demoAmount: Amount): Verified {
|
||||
val wallet = walletManager.wallet
|
||||
val addresses = getAvailableAddresses(wallet.addresses)
|
||||
val feePaidCurrency = wallet.blockchain.feePaidCurrency()
|
||||
val txHistoryItemConverter = TransactionDataToTxHistoryItemConverter(addresses, feePaidCurrency)
|
||||
|
||||
return UpdateWalletManagerResult.Verified(
|
||||
return Verified(
|
||||
selectedAddress = wallet.address,
|
||||
addresses = addresses,
|
||||
currenciesAmounts = getDemoTokensAmounts(demoAmount, walletManager.cardTokens),
|
||||
|
|
@ -53,12 +51,12 @@ internal class UpdateWalletManagerResultFactory {
|
|||
|
||||
return if (amount == null) {
|
||||
Timber.w("Unable to get required amount to create account for: $blockchain")
|
||||
UpdateWalletManagerResult.Unreachable(
|
||||
Unreachable(
|
||||
selectedAddress = wallet.address,
|
||||
addresses = getAvailableAddresses(wallet.addresses),
|
||||
)
|
||||
} else {
|
||||
UpdateWalletManagerResult.NoAccount(
|
||||
NoAccount(
|
||||
selectedAddress = wallet.address,
|
||||
addresses = getAvailableAddresses(wallet.addresses),
|
||||
amountToCreateAccount = amount,
|
||||
|
|
@ -70,7 +68,7 @@ internal class UpdateWalletManagerResultFactory {
|
|||
fun getUnreachableResult(walletManager: WalletManager): UpdateWalletManagerResult {
|
||||
val wallet = walletManager.wallet
|
||||
|
||||
return UpdateWalletManagerResult.Unreachable(
|
||||
return Unreachable(
|
||||
selectedAddress = wallet.address,
|
||||
addresses = getAvailableAddresses(wallet.addresses),
|
||||
)
|
||||
|
|
@ -86,8 +84,8 @@ internal class UpdateWalletManagerResultFactory {
|
|||
|
||||
return tokens.mapTo(demoAmounts) { token ->
|
||||
CryptoCurrencyAmount.Token(
|
||||
tokenId = token.id?.let { CryptoCurrency.RawID(it) },
|
||||
tokenContractAddress = token.contractAddress,
|
||||
currencyRawId = token.id?.let(CryptoCurrency::RawID),
|
||||
contractAddress = token.contractAddress,
|
||||
value = amountValue,
|
||||
)
|
||||
}
|
||||
|
|
@ -112,8 +110,8 @@ internal class UpdateWalletManagerResultFactory {
|
|||
private fun createCurrencyAmount(amount: Amount): CryptoCurrencyAmount? {
|
||||
return when (val type = amount.type) {
|
||||
is AmountType.Token -> CryptoCurrencyAmount.Token(
|
||||
tokenId = type.token.id?.let { CryptoCurrency.RawID(it) },
|
||||
tokenContractAddress = type.token.contractAddress,
|
||||
currencyRawId = type.token.id?.let(CryptoCurrency::RawID),
|
||||
contractAddress = type.token.contractAddress,
|
||||
value = getCurrencyAmountValue(amount) ?: return null,
|
||||
)
|
||||
is AmountType.Coin -> CryptoCurrencyAmount.Coin(
|
||||
|
|
@ -138,7 +136,7 @@ internal class UpdateWalletManagerResultFactory {
|
|||
val txHistoryItem = txHistoryItemConverter.convert(data) ?: return null
|
||||
CryptoCurrencyTransaction.Token(
|
||||
tokenId = type.token.id,
|
||||
tokenContractAddress = type.token.contractAddress,
|
||||
contractAddress = type.token.contractAddress,
|
||||
txInfo = txHistoryItem,
|
||||
)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue