Updated on 2026-08-14
This commit is contained in:
parent
62a032e3d1
commit
ebcf2f40e5
13 changed files with 222 additions and 81 deletions
|
|
@ -1,11 +1,11 @@
|
|||
package com.tangem.feature.referral.domain
|
||||
|
||||
import com.tangem.lib.crypto.DerivationManager
|
||||
import com.tangem.lib.crypto.UserWalletManager
|
||||
import com.tangem.lib.crypto.models.Token
|
||||
import com.tangem.feature.referral.domain.converter.TokensConverter
|
||||
import com.tangem.feature.referral.domain.models.ReferralData
|
||||
import com.tangem.feature.referral.domain.models.TokenData
|
||||
import com.tangem.lib.crypto.DerivationManager
|
||||
import com.tangem.lib.crypto.UserWalletManager
|
||||
import com.tangem.lib.crypto.models.Currency
|
||||
|
||||
internal class ReferralInteractorImpl(
|
||||
private val repository: ReferralRepository,
|
||||
|
|
@ -24,13 +24,13 @@ internal class ReferralInteractorImpl(
|
|||
|
||||
override suspend fun startReferral(): ReferralData {
|
||||
if (tokensForReferral.isNotEmpty()) {
|
||||
val token = tokensConverter.convert(tokensForReferral.first())
|
||||
deriveOrAddTokens(token)
|
||||
val publicAddress = userWalletManager.getWalletAddress(token)
|
||||
val currency = tokensConverter.convert(tokensForReferral.first())
|
||||
deriveOrAddTokens(currency)
|
||||
val publicAddress = userWalletManager.getWalletAddress(currency)
|
||||
return repository.startReferral(
|
||||
walletId = userWalletManager.getWalletId(),
|
||||
networkId = token.networkId ?: "",
|
||||
tokenId = token.id,
|
||||
networkId = currency.networkId,
|
||||
tokenId = currency.id,
|
||||
address = publicAddress,
|
||||
)
|
||||
} else {
|
||||
|
|
@ -38,12 +38,12 @@ internal class ReferralInteractorImpl(
|
|||
}
|
||||
}
|
||||
|
||||
private fun deriveOrAddTokens(token: Token) {
|
||||
if (!derivationManager.hasDerivation()) {
|
||||
derivationManager.deriveMissingBlockchains(token.networkId)
|
||||
private suspend fun deriveOrAddTokens(currency: Currency) {
|
||||
if (!derivationManager.hasDerivation(currency.networkId)) {
|
||||
derivationManager.deriveMissingBlockchains(currency)
|
||||
}
|
||||
if (!userWalletManager.isTokenAdded(token)) {
|
||||
userWalletManager.addToken(token)
|
||||
if (!userWalletManager.isTokenAdded(currency)) {
|
||||
userWalletManager.addToken(currency)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,19 +1,32 @@
|
|||
package com.tangem.feature.referral.domain.converter
|
||||
|
||||
import com.tangem.lib.crypto.models.Token
|
||||
import com.tangem.feature.referral.domain.models.TokenData
|
||||
import com.tangem.lib.crypto.models.Currency
|
||||
import com.tangem.lib.crypto.models.NativeToken
|
||||
import com.tangem.lib.crypto.models.NonNativeToken
|
||||
import com.tangem.utils.converter.Converter
|
||||
|
||||
class TokensConverter : Converter<TokenData, Token> {
|
||||
class TokensConverter : Converter<TokenData, Currency> {
|
||||
|
||||
override fun convert(value: TokenData): Token {
|
||||
return Token(
|
||||
id = value.id,
|
||||
name = value.name,
|
||||
symbol = value.symbol,
|
||||
networkId = value.networkId,
|
||||
contractAddress = value.contractAddress,
|
||||
decimalCount = value.decimalCount,
|
||||
)
|
||||
override fun convert(value: TokenData): Currency {
|
||||
return if (value.decimalCount != null &&
|
||||
value.contractAddress != null
|
||||
) {
|
||||
NonNativeToken(
|
||||
id = value.id,
|
||||
name = value.name,
|
||||
symbol = value.symbol,
|
||||
networkId = value.networkId,
|
||||
contractAddress = value.contractAddress,
|
||||
decimalCount = value.decimalCount,
|
||||
)
|
||||
} else {
|
||||
NativeToken(
|
||||
id = value.id,
|
||||
name = value.name,
|
||||
symbol = value.symbol,
|
||||
networkId = value.networkId,
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -34,7 +34,7 @@ data class TokenData(
|
|||
val id: String,
|
||||
val name: String,
|
||||
val symbol: String,
|
||||
val networkId: String?,
|
||||
val networkId: String,
|
||||
val contractAddress: String?,
|
||||
val decimalCount: Int?,
|
||||
)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue