Updated on 2026-08-14
This commit is contained in:
parent
37054e453d
commit
b925625342
16 changed files with 223 additions and 3 deletions
|
|
@ -109,6 +109,7 @@ dependencies {
|
||||||
implementation(project(":domain"))
|
implementation(project(":domain"))
|
||||||
implementation(project(":network"))
|
implementation(project(":network"))
|
||||||
implementation(project(":common"))
|
implementation(project(":common"))
|
||||||
|
implementation(project(":libs:crypto"))
|
||||||
|
|
||||||
/** AndroidX libraries */
|
/** AndroidX libraries */
|
||||||
implementation(AndroidX.coreKtx)
|
implementation(AndroidX.coreKtx)
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,14 @@
|
||||||
|
package com.tangem.tap.proxy
|
||||||
|
|
||||||
|
import com.tangem.crypto.DerivationManager
|
||||||
|
|
||||||
|
class DerivationManagerImpl : DerivationManager {
|
||||||
|
|
||||||
|
override fun deriveMissingBlockchains(networkId: String?) {
|
||||||
|
TODO("Not yet implemented")
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun hasDerivation(): Boolean {
|
||||||
|
TODO("Not yet implemented")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,27 @@
|
||||||
|
package com.tangem.tap.proxy
|
||||||
|
|
||||||
|
import com.tangem.crypto.UserWalletManager
|
||||||
|
import com.tangem.crypto.models.Token
|
||||||
|
|
||||||
|
class UserWalletManagerImpl : UserWalletManager {
|
||||||
|
|
||||||
|
override fun getUserTokens(): List<Token> {
|
||||||
|
TODO("Not yet implemented")
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun getWalletId(): String {
|
||||||
|
TODO("Not yet implemented")
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun isTokenAdded(token: Token): Boolean {
|
||||||
|
TODO("Not yet implemented")
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun addToken(token: Token) {
|
||||||
|
TODO("Not yet implemented")
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun getWalletAddress(token: Token): String {
|
||||||
|
TODO("Not yet implemented")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -26,7 +26,7 @@ data class Token(
|
||||||
@Json(name = "symbol") val symbol: String,
|
@Json(name = "symbol") val symbol: String,
|
||||||
@Json(name = "networkId") val networkId: String?,
|
@Json(name = "networkId") val networkId: String?,
|
||||||
@Json(name = "contractAddress") val contractAddress: String?,
|
@Json(name = "contractAddress") val contractAddress: String?,
|
||||||
@Json(name = "decimalCount") val decimalCount: Int,
|
@Json(name = "decimalCount") val decimalCount: Int?,
|
||||||
)
|
)
|
||||||
|
|
||||||
data class Referral(
|
data class Referral(
|
||||||
|
|
|
||||||
|
|
@ -26,6 +26,10 @@ android {
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
|
|
||||||
|
/** Libs */
|
||||||
|
implementation(project(":core:utils"))
|
||||||
|
implementation(project(":libs:crypto"))
|
||||||
|
|
||||||
/** Time */
|
/** Time */
|
||||||
implementation(Library.jodatime)
|
implementation(Library.jodatime)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,10 @@
|
||||||
|
package com.tangem.feature.referral.domain
|
||||||
|
|
||||||
|
import com.tangem.feature.referral.domain.models.ReferralData
|
||||||
|
|
||||||
|
interface ReferralInteractor {
|
||||||
|
|
||||||
|
suspend fun getReferralStatus(): ReferralData
|
||||||
|
|
||||||
|
suspend fun startReferral(): ReferralData
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,54 @@
|
||||||
|
package com.tangem.feature.referral.domain
|
||||||
|
|
||||||
|
import com.tangem.crypto.DerivationManager
|
||||||
|
import com.tangem.crypto.UserWalletManager
|
||||||
|
import com.tangem.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
|
||||||
|
|
||||||
|
internal class ReferralInteractorImpl(
|
||||||
|
private val repository: ReferralRepository,
|
||||||
|
private val derivationManager: DerivationManager,
|
||||||
|
private val userWalletManager: UserWalletManager,
|
||||||
|
private val tokensConverter: TokensConverter,
|
||||||
|
) : ReferralInteractor {
|
||||||
|
|
||||||
|
private val tokensForReferral = mutableListOf<TokenData>()
|
||||||
|
|
||||||
|
override suspend fun getReferralStatus(): ReferralData {
|
||||||
|
val refStatus = repository.getReferralStatus(userWalletManager.getWalletId())
|
||||||
|
saveRefTokens(refStatus.tokens)
|
||||||
|
return refStatus
|
||||||
|
}
|
||||||
|
|
||||||
|
override suspend fun startReferral(): ReferralData {
|
||||||
|
if (tokensForReferral.isNotEmpty()) {
|
||||||
|
val token = tokensConverter.convert(tokensForReferral.first())
|
||||||
|
deriveOrAddTokens(token)
|
||||||
|
val publicAddress = userWalletManager.getWalletAddress(token)
|
||||||
|
return repository.startReferral(
|
||||||
|
walletId = userWalletManager.getWalletId(),
|
||||||
|
networkId = token.networkId ?: "",
|
||||||
|
tokenId = token.id,
|
||||||
|
address = publicAddress,
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
throw IllegalStateException("tokens for ref is empty")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun deriveOrAddTokens(token: Token) {
|
||||||
|
if (!derivationManager.hasDerivation()) {
|
||||||
|
derivationManager.deriveMissingBlockchains(token.networkId)
|
||||||
|
}
|
||||||
|
if (!userWalletManager.isTokenAdded(token)) {
|
||||||
|
userWalletManager.addToken(token)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun saveRefTokens(tokens: List<TokenData>) {
|
||||||
|
tokensForReferral.clear()
|
||||||
|
tokensForReferral.addAll(tokens)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,19 @@
|
||||||
|
package com.tangem.feature.referral.domain.converter
|
||||||
|
|
||||||
|
import com.tangem.crypto.models.Token
|
||||||
|
import com.tangem.feature.referral.domain.models.TokenData
|
||||||
|
import com.tangem.utils.converter.Converter
|
||||||
|
|
||||||
|
class TokensConverter : Converter<TokenData, Token> {
|
||||||
|
|
||||||
|
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,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -36,7 +36,7 @@ data class TokenData(
|
||||||
val symbol: String,
|
val symbol: String,
|
||||||
val networkId: String?,
|
val networkId: String?,
|
||||||
val contractAddress: String?,
|
val contractAddress: String?,
|
||||||
val decimalCount: Int,
|
val decimalCount: Int?,
|
||||||
)
|
)
|
||||||
|
|
||||||
data class ReferralInfo(
|
data class ReferralInfo(
|
||||||
|
|
|
||||||
1
libs/crypto/.gitignore
vendored
Normal file
1
libs/crypto/.gitignore
vendored
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
/build
|
||||||
29
libs/crypto/build.gradle.kts
Normal file
29
libs/crypto/build.gradle.kts
Normal file
|
|
@ -0,0 +1,29 @@
|
||||||
|
plugins {
|
||||||
|
id("com.android.library")
|
||||||
|
kotlin("android")
|
||||||
|
}
|
||||||
|
|
||||||
|
android {
|
||||||
|
|
||||||
|
defaultConfig {
|
||||||
|
compileSdk = AppConfig.compileSdkVersion
|
||||||
|
minSdk = AppConfig.minSdkVersion
|
||||||
|
targetSdk = AppConfig.targetSdkVersion
|
||||||
|
}
|
||||||
|
|
||||||
|
kotlinOptions {
|
||||||
|
jvmTarget = JavaVersion.VERSION_1_8.toString()
|
||||||
|
}
|
||||||
|
|
||||||
|
compileOptions {
|
||||||
|
sourceCompatibility = JavaVersion.VERSION_1_8
|
||||||
|
targetCompatibility = JavaVersion.VERSION_1_8
|
||||||
|
isCoreLibraryDesugaringEnabled = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
|
||||||
|
/** Coroutines */
|
||||||
|
implementation(Library.coroutine)
|
||||||
|
}
|
||||||
2
libs/crypto/src/main/AndroidManifest.xml
Normal file
2
libs/crypto/src/main/AndroidManifest.xml
Normal file
|
|
@ -0,0 +1,2 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<manifest package="com.tangem.lib.crypto" />
|
||||||
|
|
@ -0,0 +1,8 @@
|
||||||
|
package com.tangem.crypto
|
||||||
|
|
||||||
|
interface DerivationManager {
|
||||||
|
|
||||||
|
fun deriveMissingBlockchains(networkId: String?)
|
||||||
|
|
||||||
|
fun hasDerivation(): Boolean
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,40 @@
|
||||||
|
package com.tangem.crypto
|
||||||
|
|
||||||
|
import com.tangem.crypto.models.Token
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Provider for user tokens data
|
||||||
|
*/
|
||||||
|
interface UserWalletManager {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns all user tokens (merged from local and backend)
|
||||||
|
*/
|
||||||
|
fun getUserTokens(): List<Token>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns user walletId
|
||||||
|
*/
|
||||||
|
fun getWalletId(): String
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks that token added to user wallet
|
||||||
|
*
|
||||||
|
* @param token to receive referral payments
|
||||||
|
*/
|
||||||
|
fun isTokenAdded(token: Token): Boolean
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds token to wallet if its not
|
||||||
|
*
|
||||||
|
* @param token to add to wallet
|
||||||
|
*/
|
||||||
|
fun addToken(token: Token)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns wallet public address for token
|
||||||
|
*
|
||||||
|
* @param token for which find address
|
||||||
|
*/
|
||||||
|
fun getWalletAddress(token: Token): String
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,10 @@
|
||||||
|
package com.tangem.crypto.models
|
||||||
|
|
||||||
|
data class Token(
|
||||||
|
val id: String,
|
||||||
|
val name: String,
|
||||||
|
val symbol: String,
|
||||||
|
val networkId: String?,
|
||||||
|
val contractAddress: String?,
|
||||||
|
val decimalCount: Int?,
|
||||||
|
)
|
||||||
|
|
@ -6,4 +6,5 @@ include(":core:datasource")
|
||||||
include(":core:utils")
|
include(":core:utils")
|
||||||
include(":features:referral:data")
|
include(":features:referral:data")
|
||||||
include(":features:referral:domain")
|
include(":features:referral:domain")
|
||||||
include(":features:referral:presentation")
|
include(":features:referral:presentation")
|
||||||
|
include(":libs:crypto")
|
||||||
Loading…
Add table
Add a link
Reference in a new issue