Updated on 2026-08-14

This commit is contained in:
Tangem 2023-02-22 17:18:44 +03:00
parent cd7899ba3e
commit b119c29d09
19 changed files with 124 additions and 34 deletions

View file

@ -2,15 +2,42 @@ package com.tangem.tap.common.extensions
import com.tangem.core.analytics.Analytics
import com.tangem.domain.common.ScanResponse
import com.tangem.tap.common.analytics.paramsInterceptor.CardContextInterceptor
import com.tangem.tap.common.analytics.paramsInterceptor.LinkedCardContextInterceptor
/**
[REDACTED_AUTHOR]
*/
fun Analytics.addCardContext(scanResponse: ScanResponse) {
addParamsInterceptor(CardContextInterceptor(scanResponse))
/**
* Sets the new context
*/
fun Analytics.setContext(scanResponse: ScanResponse) {
addParamsInterceptor(LinkedCardContextInterceptor(scanResponse))
}
fun Analytics.eraseCardContext() {
removeParamsInterceptor(CardContextInterceptor.id())
/**
* Erases the context
*/
fun Analytics.eraseContext() {
removeParamsInterceptor(LinkedCardContextInterceptor.id())
}
/**
* Adds a new context and keeps a previous context as the parent of the new one
*/
fun Analytics.addContext(scanResponse: ScanResponse) {
val currentContext = removeParamsInterceptor(LinkedCardContextInterceptor.id()) as? LinkedCardContextInterceptor
val newContext = LinkedCardContextInterceptor(scanResponse, parent = currentContext)
addParamsInterceptor(newContext)
}
/**
* Removes the current context and restores the previous one if it was present.
*/
fun Analytics.removeContext() {
val currentContext = removeParamsInterceptor(LinkedCardContextInterceptor.id()) as? LinkedCardContextInterceptor
val previousContext = currentContext?.parent ?: return
addParamsInterceptor(previousContext)
}