Updated on 2026-08-14
This commit is contained in:
parent
db1d205bae
commit
cb1ede0531
5 changed files with 116 additions and 0 deletions
|
|
@ -2,6 +2,7 @@ package com.tangem.core.deeplink.global
|
|||
|
||||
import com.tangem.core.deeplink.DeepLink
|
||||
|
||||
@Deprecated("Use SellDeepLinkHandler")
|
||||
class SellCurrencyDeepLink(
|
||||
val onReceive: (data: Data) -> Unit,
|
||||
shouldHandleDelayed: Boolean,
|
||||
|
|
|
|||
|
|
@ -17,4 +17,7 @@ dependencies {
|
|||
implementation(projects.domain.wallets.models)
|
||||
implementation(projects.domain.tokens.models)
|
||||
implementation(projects.domain.nft.models)
|
||||
|
||||
/* Compose */
|
||||
implementation(deps.compose.runtime)
|
||||
}
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
package com.tangem.features.send.v2.api.deeplink
|
||||
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
|
||||
interface SellDeepLinkHandler {
|
||||
|
||||
interface Factory {
|
||||
fun create(coroutineScope: CoroutineScope, params: Map<String, String>): SellDeepLinkHandler
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,84 @@
|
|||
package com.tangem.features.send.v2.deeplink
|
||||
|
||||
import arrow.core.getOrElse
|
||||
import com.tangem.common.routing.AppRoute
|
||||
import com.tangem.common.routing.AppRouter
|
||||
import com.tangem.domain.tokens.GetCryptoCurrencyUseCase
|
||||
import com.tangem.domain.wallets.usecase.GetSelectedWalletSyncUseCase
|
||||
import com.tangem.features.send.v2.api.deeplink.SellDeepLinkHandler
|
||||
import dagger.assisted.Assisted
|
||||
import dagger.assisted.AssistedFactory
|
||||
import dagger.assisted.AssistedInject
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.launch
|
||||
import timber.log.Timber
|
||||
|
||||
@Suppress("ComplexCondition")
|
||||
internal class DefaultSellDeepLinkHandler @AssistedInject constructor(
|
||||
@Assisted scope: CoroutineScope,
|
||||
@Assisted params: 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]
|
||||
|
||||
// It is okay here, we are navigating from outside, and there is no other way to getting UserWallet
|
||||
getSelectedWalletSyncUseCase()
|
||||
.fold(
|
||||
ifLeft = {
|
||||
Timber.e("Error on getting user wallet: $it")
|
||||
},
|
||||
ifRight = { userWallet ->
|
||||
if (currencyId.isNullOrEmpty() || transactionId.isNullOrEmpty() ||
|
||||
amount.isNullOrEmpty() || destinationAddress.isNullOrEmpty()
|
||||
) {
|
||||
Timber.e(
|
||||
"""
|
||||
Invalid parameters for SELL deeplink
|
||||
|- Params: $params
|
||||
""".trimIndent(),
|
||||
)
|
||||
return@fold
|
||||
}
|
||||
|
||||
scope.launch {
|
||||
val cryptoCurrency = getCryptoCurrencyUseCase(userWallet, currencyId).getOrElse {
|
||||
Timber.e("Error on getting cryptoCurrency: $it")
|
||||
return@launch
|
||||
}
|
||||
|
||||
appRouter.push(
|
||||
AppRoute.Send(
|
||||
currency = cryptoCurrency,
|
||||
userWalletId = userWallet.walletId,
|
||||
transactionId = transactionId,
|
||||
destinationAddress = destinationAddress,
|
||||
amount = amount,
|
||||
tag = memo,
|
||||
),
|
||||
)
|
||||
}
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
@AssistedFactory
|
||||
interface Factory : SellDeepLinkHandler.Factory {
|
||||
override fun create(coroutineScope: CoroutineScope, params: Map<String, String>): DefaultSellDeepLinkHandler
|
||||
}
|
||||
|
||||
private companion object {
|
||||
const val TRANSACTION_ID_KEY = "transactionId"
|
||||
const val CURRENCY_ID_KEY = "currency_id"
|
||||
const val AMOUNT_KEY = "baseCurrencyAmount"
|
||||
const val DESTINATION_ADDRESS_KEY = "depositWalletAddress"
|
||||
const val MEMO_KEY = "depositWalletAddressTag"
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,18 @@
|
|||
package com.tangem.features.send.v2.deeplink.di
|
||||
|
||||
import com.tangem.features.send.v2.api.deeplink.SellDeepLinkHandler
|
||||
import com.tangem.features.send.v2.deeplink.DefaultSellDeepLinkHandler
|
||||
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 SendDeepLinkModule {
|
||||
|
||||
@Binds
|
||||
@Singleton
|
||||
fun bindFactory(impl: DefaultSellDeepLinkHandler.Factory): SellDeepLinkHandler.Factory
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue