Updated on 2026-08-14

This commit is contained in:
Tangem 2025-04-28 15:50:50 +05:00
parent 68410e14b8
commit 27b6caeaeb
4 changed files with 23 additions and 15 deletions

View file

@ -11,11 +11,11 @@ import android.os.Build
import androidx.core.app.NotificationCompat
import androidx.core.content.ContextCompat
import androidx.core.graphics.drawable.toBitmap
import androidx.core.net.toUri
import coil.executeBlocking
import coil.request.ImageRequest
import com.google.firebase.messaging.FirebaseMessagingService
import com.google.firebase.messaging.RemoteMessage
import com.tangem.core.deeplink.DEEPLINK_KEY
import com.tangem.domain.common.LogConfig
import com.tangem.tap.MainActivity
import com.tangem.tap.common.images.createCoilImageLoader
@ -38,7 +38,7 @@ internal class TangemPushNotificationService : FirebaseMessagingService() {
val channelId = notification.channelId ?: TANGEM_CHANNEL_ID
val intent = Intent(applicationContext, MainActivity::class.java).apply {
data = message.data[DEEPLINK_KEY]?.toUri()
putExtra(DEEPLINK_KEY, message.data[DEEPLINK_KEY])
putExtra(OnPushClickedIntentHandler.OPENED_FROM_GCM_PUSH, true)
addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)
}
@ -103,7 +103,5 @@ internal class TangemPushNotificationService : FirebaseMessagingService() {
private companion object {
const val TANGEM_CHANNEL_ID = "Tangem General" // General channel for notifications
const val PUSH_NOTIFICATION_REQUEST_CODE = 123
const val DEEPLINK_KEY = "deeplink"
}
}

View file

@ -2,6 +2,11 @@ package com.tangem.core.deeplink
import android.content.Intent
/**
* Key to pass deeplink via intent
*/
const val DEEPLINK_KEY = "deeplink"
// TODO: Add tests
/**
* Provides functionality to handle deep links.

View file

@ -3,6 +3,7 @@ package com.tangem.core.deeplink.impl
import android.content.Intent
import android.net.Uri
import androidx.core.net.toUri
import com.tangem.core.deeplink.DEEPLINK_KEY
import com.tangem.core.deeplink.DeepLink
import com.tangem.core.deeplink.DeepLinksRegistry
import timber.log.Timber
@ -10,11 +11,14 @@ import timber.log.Timber
internal class DefaultDeepLinksRegistry : DeepLinksRegistry {
private var registries: List<DeepLink> = emptyList()
private var lastIntent: Intent? = null
private var lastDeepLink: Uri? = null
override fun launch(intent: Intent): Boolean {
lastIntent = intent
val received = intent.data ?: return false
// Try to get deeplink from data (direct deeplink flow)
// Otherwise, try to get from extras (notification deeplink flow)
val deepLinkExtras = intent.getStringExtra(DEEPLINK_KEY)?.toUri()
val received = intent.data ?: deepLinkExtras ?: return false
lastDeepLink = received
var hasMatch = false
Timber.i(
@ -35,7 +39,7 @@ internal class DefaultDeepLinksRegistry : DeepLinksRegistry {
logMatch(hasMatch, expected, received, params)
deepLink.onReceive(params)
lastIntent = null // clear intent if it was handled
lastDeepLink = null // clear deeplink if it was handled
}
if (!hasMatch) {
@ -100,10 +104,9 @@ internal class DefaultDeepLinksRegistry : DeepLinksRegistry {
)
}
override fun triggerDelayedDeeplink() {
if (lastIntent != null) {
val intent = lastIntent
val received = intent?.data ?: return
override fun triggerDelayedDeeplink(deepLinkClass: Class<out DeepLink>) {
val received = lastDeepLink
if (received != null) {
var hasMatch = false
registries
.filterIsInstance(deepLinkClass)
@ -121,12 +124,12 @@ internal class DefaultDeepLinksRegistry : DeepLinksRegistry {
if (!hasMatch) {
logMatch(hasMatch, null, received, null)
}
lastIntent = null // clear intent in any case handle or not
lastDeepLink = null // clear deeplink in any case handle or not
}
}
override fun cancelDelayedDeeplink() {
lastIntent = null
lastDeepLink = null
}
private fun logMatch(hasMatch: Boolean, expected: Uri?, received: Uri?, params: Map<String, String>?) {

View file

@ -39,7 +39,9 @@ internal class DefaultPromoRepository(
default = true,
).map { shouldShow ->
if (promoId == PromoId.Referral) {
!referralRepository.isReferralParticipant(userWalletId) && shouldShow
runCatching {
!referralRepository.isReferralParticipant(userWalletId) && shouldShow
}.getOrDefault(false)
} else {
shouldShow
}