Updated on 2026-08-14
This commit is contained in:
commit
fdfb07ee33
17 changed files with 263 additions and 20 deletions
|
|
@ -15,6 +15,6 @@ abstract class OnrampDeepLink : DeepLink() {
|
|||
interface OnrampDeepLinkHandler {
|
||||
|
||||
interface Factory {
|
||||
fun create(coroutineScope: CoroutineScope, params: Map<String, String>): OnrampDeepLinkHandler
|
||||
fun create(coroutineScope: CoroutineScope, queryParams: Map<String, String>): OnrampDeepLinkHandler
|
||||
}
|
||||
}
|
||||
|
|
@ -12,14 +12,14 @@ import timber.log.Timber
|
|||
|
||||
internal class DefaultOnrampDeepLinkHandler @AssistedInject constructor(
|
||||
@Assisted scope: CoroutineScope,
|
||||
@Assisted params: Map<String, String>,
|
||||
@Assisted queryParams: Map<String, String>,
|
||||
appRouter: AppRouter,
|
||||
onrampSuccessScreenTrigger: OnrampSuccessScreenTrigger,
|
||||
) : OnrampDeepLinkHandler {
|
||||
|
||||
init {
|
||||
val txId = params[TX_ID_KEY]
|
||||
val result = OnrampRedirectResult.getResult(params[RESULT_KEY])
|
||||
val txId = queryParams[TX_ID_KEY]
|
||||
val result = OnrampRedirectResult.getResult(queryParams[RESULT_KEY])
|
||||
|
||||
when {
|
||||
!txId.isNullOrEmpty() -> {
|
||||
|
|
@ -39,7 +39,7 @@ internal class DefaultOnrampDeepLinkHandler @AssistedInject constructor(
|
|||
Timber.e(
|
||||
"""
|
||||
Invalid parameters for ONRAMP deeplink
|
||||
|- Params: $params
|
||||
|- Params: $queryParams
|
||||
""".trimIndent(),
|
||||
)
|
||||
}
|
||||
|
|
@ -48,7 +48,10 @@ internal class DefaultOnrampDeepLinkHandler @AssistedInject constructor(
|
|||
|
||||
@AssistedFactory
|
||||
interface Factory : OnrampDeepLinkHandler.Factory {
|
||||
override fun create(coroutineScope: CoroutineScope, params: Map<String, String>): DefaultOnrampDeepLinkHandler
|
||||
override fun create(
|
||||
coroutineScope: CoroutineScope,
|
||||
queryParams: Map<String, String>,
|
||||
): DefaultOnrampDeepLinkHandler
|
||||
}
|
||||
|
||||
private companion object {
|
||||
|
|
|
|||
|
|
@ -5,6 +5,6 @@ import kotlinx.coroutines.CoroutineScope
|
|||
interface SellDeepLinkHandler {
|
||||
|
||||
interface Factory {
|
||||
fun create(coroutineScope: CoroutineScope, params: Map<String, String>): SellDeepLinkHandler
|
||||
fun create(coroutineScope: CoroutineScope, queryParams: Map<String, String>): SellDeepLinkHandler
|
||||
}
|
||||
}
|
||||
|
|
@ -16,18 +16,18 @@ import timber.log.Timber
|
|||
@Suppress("ComplexCondition")
|
||||
internal class DefaultSellDeepLinkHandler @AssistedInject constructor(
|
||||
@Assisted scope: CoroutineScope,
|
||||
@Assisted params: Map<String, String>,
|
||||
@Assisted queryParams: Map<String, String>,
|
||||
appRouter: AppRouter,
|
||||
getSelectedWalletSyncUseCase: GetSelectedWalletSyncUseCase,
|
||||
getCryptoCurrencyUseCase: GetCryptoCurrencyUseCase,
|
||||
) : SellDeepLinkHandler {
|
||||
|
||||
init {
|
||||
val currencyId = params[CURRENCY_ID_KEY]
|
||||
val transactionId = params[TRANSACTION_ID_KEY]
|
||||
val amount = params[AMOUNT_KEY]
|
||||
val destinationAddress = params[DESTINATION_ADDRESS_KEY]
|
||||
val memo = params[MEMO_KEY]
|
||||
val currencyId = queryParams[CURRENCY_ID_KEY]
|
||||
val transactionId = queryParams[TRANSACTION_ID_KEY]
|
||||
val amount = queryParams[AMOUNT_KEY]
|
||||
val destinationAddress = queryParams[DESTINATION_ADDRESS_KEY]
|
||||
val memo = queryParams[MEMO_KEY]
|
||||
|
||||
// It is okay here, we are navigating from outside, and there is no other way to getting UserWallet
|
||||
getSelectedWalletSyncUseCase()
|
||||
|
|
@ -42,7 +42,7 @@ internal class DefaultSellDeepLinkHandler @AssistedInject constructor(
|
|||
Timber.e(
|
||||
"""
|
||||
Invalid parameters for SELL deeplink
|
||||
|- Params: $params
|
||||
|- Params: $queryParams
|
||||
""".trimIndent(),
|
||||
)
|
||||
return@fold
|
||||
|
|
@ -71,7 +71,10 @@ internal class DefaultSellDeepLinkHandler @AssistedInject constructor(
|
|||
|
||||
@AssistedFactory
|
||||
interface Factory : SellDeepLinkHandler.Factory {
|
||||
override fun create(coroutineScope: CoroutineScope, params: Map<String, String>): DefaultSellDeepLinkHandler
|
||||
override fun create(
|
||||
coroutineScope: CoroutineScope,
|
||||
queryParams: Map<String, String>,
|
||||
): DefaultSellDeepLinkHandler
|
||||
}
|
||||
|
||||
private companion object {
|
||||
|
|
|
|||
|
|
@ -18,4 +18,7 @@ dependencies {
|
|||
api(projects.domain.models)
|
||||
implementation(projects.domain.tokens.models)
|
||||
implementation(projects.domain.wallets.models)
|
||||
|
||||
/** Compose */
|
||||
implementation(deps.compose.runtime)
|
||||
}
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
package com.tangem.features.tokendetails.deeplink
|
||||
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
|
||||
interface TokenDetailsDeepLinkHandler {
|
||||
|
||||
interface Factory {
|
||||
fun create(coroutineScope: CoroutineScope, queryParams: Map<String, String>): TokenDetailsDeepLinkHandler
|
||||
}
|
||||
}
|
||||
|
|
@ -87,6 +87,7 @@ dependencies {
|
|||
implementation(projects.domain.promo)
|
||||
implementation(projects.domain.promo.models)
|
||||
implementation(projects.domain.quotes)
|
||||
implementation(projects.domain.notifications.models)
|
||||
|
||||
/** Temp dependency to swap domain */
|
||||
implementation(projects.features.swap.domain)
|
||||
|
|
|
|||
|
|
@ -0,0 +1,88 @@
|
|||
package com.tangem.feature.tokendetails.deeplink
|
||||
|
||||
import arrow.core.getOrElse
|
||||
import com.tangem.common.routing.AppRoute
|
||||
import com.tangem.common.routing.AppRouter
|
||||
import com.tangem.domain.notifications.models.NotificationType
|
||||
import com.tangem.domain.tokens.GetCryptoCurrenciesUseCase
|
||||
import com.tangem.domain.wallets.models.UserWalletId
|
||||
import com.tangem.domain.wallets.usecase.GetSelectedWalletSyncUseCase
|
||||
import com.tangem.features.tokendetails.deeplink.TokenDetailsDeepLinkHandler
|
||||
import dagger.assisted.Assisted
|
||||
import dagger.assisted.AssistedFactory
|
||||
import dagger.assisted.AssistedInject
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.launch
|
||||
import timber.log.Timber
|
||||
|
||||
internal class DefaultTokenDetailsDeepLinkHandler @AssistedInject constructor(
|
||||
@Assisted private val scope: CoroutineScope,
|
||||
@Assisted private val queryParams: Map<String, String>,
|
||||
private val appRouter: AppRouter,
|
||||
private val getSelectedWalletSyncUseCase: GetSelectedWalletSyncUseCase,
|
||||
private val getCryptoCurrenciesUseCase: GetCryptoCurrenciesUseCase,
|
||||
) : TokenDetailsDeepLinkHandler {
|
||||
|
||||
init {
|
||||
handleDeepLink()
|
||||
}
|
||||
|
||||
private fun handleDeepLink() {
|
||||
// It is okay here, we are navigating from outside, and there is no other way to getting UserWallet
|
||||
val userWalletId = queryParams[WALLET_ID_KEY]?.let(::UserWalletId)
|
||||
?: getSelectedWalletSyncUseCase().getOrNull()?.walletId
|
||||
|
||||
if (userWalletId == null) {
|
||||
Timber.e("Error on getting user wallet")
|
||||
return
|
||||
}
|
||||
|
||||
val networkId = queryParams[NETWORK_ID_KEY]
|
||||
val tokenId = queryParams[TOKEN_ID_KEY]
|
||||
val type = NotificationType.getType(queryParams[TYPE_KEY])
|
||||
|
||||
if (type == NotificationType.Promo) {
|
||||
scope.launch {
|
||||
val cryptoCurrency = getCryptoCurrenciesUseCase(userWalletId = userWalletId).getOrElse {
|
||||
Timber.e("Error on getting crypto currency list")
|
||||
return@launch
|
||||
}.firstOrNull {
|
||||
it.id.rawNetworkId == networkId && it.id.rawCurrencyId?.value == tokenId
|
||||
}
|
||||
|
||||
if (cryptoCurrency == null) {
|
||||
Timber.e(
|
||||
"""
|
||||
Could not get crypto currency for
|
||||
|- $NETWORK_ID_KEY: $networkId
|
||||
|- $TOKEN_ID_KEY: $tokenId
|
||||
""".trimIndent(),
|
||||
)
|
||||
return@launch
|
||||
}
|
||||
|
||||
appRouter.push(
|
||||
AppRoute.CurrencyDetails(
|
||||
userWalletId = userWalletId,
|
||||
currency = cryptoCurrency,
|
||||
),
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@AssistedFactory
|
||||
interface Factory : TokenDetailsDeepLinkHandler.Factory {
|
||||
override fun create(
|
||||
coroutineScope: CoroutineScope,
|
||||
queryParams: Map<String, String>,
|
||||
): DefaultTokenDetailsDeepLinkHandler
|
||||
}
|
||||
|
||||
private companion object {
|
||||
const val WALLET_ID_KEY = "walletId"
|
||||
const val NETWORK_ID_KEY = "network_id"
|
||||
const val TYPE_KEY = "type"
|
||||
const val TOKEN_ID_KEY = "token_id"
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,20 @@
|
|||
package com.tangem.feature.tokendetails.deeplink.di
|
||||
|
||||
import com.tangem.feature.tokendetails.deeplink.DefaultTokenDetailsDeepLinkHandler
|
||||
import com.tangem.features.tokendetails.deeplink.TokenDetailsDeepLinkHandler
|
||||
import dagger.Binds
|
||||
import dagger.Module
|
||||
import dagger.hilt.InstallIn
|
||||
import dagger.hilt.components.SingletonComponent
|
||||
import javax.inject.Singleton
|
||||
|
||||
@Module
|
||||
@InstallIn(SingletonComponent::class)
|
||||
internal interface TokenDetailsDeepLinkModule {
|
||||
|
||||
@Binds
|
||||
@Singleton
|
||||
fun bindWalletDeepLinkHandlerFactory(
|
||||
impl: DefaultTokenDetailsDeepLinkHandler.Factory,
|
||||
): TokenDetailsDeepLinkHandler.Factory
|
||||
}
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
package com.tangem.features.wallet.deeplink
|
||||
|
||||
interface WalletDeepLinkHandler {
|
||||
|
||||
interface Factory {
|
||||
fun create(): WalletDeepLinkHandler
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
package com.tangem.feature.wallet.deeplink
|
||||
|
||||
import com.tangem.features.wallet.deeplink.WalletDeepLinkHandler
|
||||
import dagger.assisted.AssistedFactory
|
||||
import dagger.assisted.AssistedInject
|
||||
|
||||
internal class DefaultWalletDeepLinkHandler @AssistedInject constructor() : WalletDeepLinkHandler {
|
||||
|
||||
@AssistedFactory
|
||||
interface Factory : WalletDeepLinkHandler.Factory {
|
||||
override fun create(): DefaultWalletDeepLinkHandler
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,18 @@
|
|||
package com.tangem.feature.wallet.deeplink.di
|
||||
|
||||
import com.tangem.feature.wallet.deeplink.DefaultWalletDeepLinkHandler
|
||||
import com.tangem.features.wallet.deeplink.WalletDeepLinkHandler
|
||||
import dagger.Binds
|
||||
import dagger.Module
|
||||
import dagger.hilt.InstallIn
|
||||
import dagger.hilt.components.SingletonComponent
|
||||
import javax.inject.Singleton
|
||||
|
||||
@Module
|
||||
@InstallIn(SingletonComponent::class)
|
||||
internal interface WalletDeepLinkModule {
|
||||
|
||||
@Binds
|
||||
@Singleton
|
||||
fun bindWalletDeepLinkHandlerFactory(impl: DefaultWalletDeepLinkHandler.Factory): WalletDeepLinkHandler.Factory
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue