Updated on 2026-08-14
This commit is contained in:
parent
c4603c4cbd
commit
c613890b9a
8 changed files with 241 additions and 13 deletions
|
|
@ -0,0 +1,58 @@
|
|||
package com.tangem.features.onramp.deeplink
|
||||
|
||||
import com.tangem.common.routing.AppRoute
|
||||
import com.tangem.common.routing.AppRouter
|
||||
import com.tangem.features.onramp.success.OnrampSuccessScreenTrigger
|
||||
import dagger.assisted.Assisted
|
||||
import dagger.assisted.AssistedFactory
|
||||
import dagger.assisted.AssistedInject
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.launch
|
||||
import timber.log.Timber
|
||||
|
||||
class DefaultOnrampDeepLinkHandler @AssistedInject constructor(
|
||||
appRouter: AppRouter,
|
||||
private val onrampSuccessScreenTrigger: OnrampSuccessScreenTrigger,
|
||||
@Assisted private val scope: CoroutineScope,
|
||||
@Assisted params: Map<String, String>,
|
||||
) : OnrampDeepLinkHandler {
|
||||
|
||||
init {
|
||||
val txId = params[TX_ID_KEY]
|
||||
val result = OnrampRedirectResult.getResult(params[RESULT_KEY])
|
||||
|
||||
when {
|
||||
!txId.isNullOrEmpty() -> {
|
||||
// finish current onramp flow and show onramp success screen
|
||||
val replaceOnrampScreens = appRouter.stack
|
||||
.filterNot { it is AppRoute.Onramp || it is AppRoute.OnrampSuccess }
|
||||
.toMutableList() + AppRoute.OnrampSuccess(txId)
|
||||
|
||||
appRouter.replaceAll(*replaceOnrampScreens.toTypedArray())
|
||||
}
|
||||
result != OnrampRedirectResult.Unknown -> {
|
||||
scope.launch {
|
||||
onrampSuccessScreenTrigger.triggerOnrampSuccess(result == OnrampRedirectResult.Success)
|
||||
}
|
||||
}
|
||||
else -> {
|
||||
Timber.e(
|
||||
"""
|
||||
Invalid parameters for ONRAMP deeplink
|
||||
|- Params: $params
|
||||
""".trimIndent(),
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@AssistedFactory
|
||||
interface Factory : OnrampDeepLinkHandler.Factory {
|
||||
override fun create(coroutineScope: CoroutineScope, params: Map<String, String>): DefaultOnrampDeepLinkHandler
|
||||
}
|
||||
|
||||
private companion object {
|
||||
const val TX_ID_KEY = "tx_id"
|
||||
const val RESULT_KEY = "result"
|
||||
}
|
||||
}
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
package com.tangem.features.onramp.deeplink.di
|
||||
|
||||
import com.tangem.features.onramp.deeplink.*
|
||||
import com.tangem.features.onramp.deeplink.DefaultOnrampDeepLink
|
||||
import com.tangem.features.onramp.deeplink.OnrampDeepLink
|
||||
import dagger.Binds
|
||||
import dagger.Module
|
||||
import dagger.hilt.InstallIn
|
||||
|
|
@ -15,4 +15,8 @@ internal interface OnrampDeeplinkModule {
|
|||
@Binds
|
||||
@Singleton
|
||||
fun bindFactory(impl: DefaultOnrampDeepLink.Factory): OnrampDeepLink.Factory
|
||||
|
||||
@Binds
|
||||
@Singleton
|
||||
fun bindFactoryV2(impl: DefaultOnrampDeepLinkHandler.Factory): OnrampDeepLinkHandler.Factory
|
||||
}
|
||||
|
|
@ -153,7 +153,9 @@ internal class OnrampSuccessComponentModel @Inject constructor(
|
|||
} else {
|
||||
resourceReference(R.string.express_error_code, wrappedList(errorCode))
|
||||
},
|
||||
onDismissRequest = router::pop,
|
||||
firstActionBuilder = {
|
||||
okAction(router::pop)
|
||||
},
|
||||
)
|
||||
|
||||
messageSender.send(message)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue