Updated on 2026-08-14
This commit is contained in:
parent
7e765758b4
commit
efe271e1a0
24 changed files with 751 additions and 75 deletions
|
|
@ -0,0 +1,123 @@
|
|||
package com.tangem.feature.learn2earn.domain
|
||||
|
||||
import android.net.Uri
|
||||
import com.tangem.datasource.api.promotion.models.PromotionInfoResponse
|
||||
import com.tangem.feature.learn2earn.data.api.Learn2earnRepository
|
||||
import com.tangem.feature.learn2earn.domain.api.Learn2earnInteractor
|
||||
import com.tangem.feature.learn2earn.domain.models.CardType
|
||||
import com.tangem.feature.learn2earn.domain.models.Promotion
|
||||
import com.tangem.feature.learn2earn.domain.models.PromotionError
|
||||
import com.tangem.feature.learn2earn.domain.models.PromotionError.Companion.toDomainError
|
||||
import com.tangem.feature.learn2earn.domain.models.RedirectConsequences
|
||||
import com.tangem.lib.auth.BasicAuthProvider
|
||||
|
||||
/**
|
||||
[REDACTED_AUTHOR]
|
||||
*/
|
||||
class DefaultLearn2earnInteractor(
|
||||
private val repository: Learn2earnRepository,
|
||||
basicAuthProvider: BasicAuthProvider,
|
||||
userCountryCodeProvider: () -> String,
|
||||
) : Learn2earnInteractor {
|
||||
|
||||
private val webViewUriBuilder = WebViewUriBuilder(
|
||||
basicAuthProvider = basicAuthProvider,
|
||||
userCountryCodeProvider = userCountryCodeProvider,
|
||||
promoCodeProvider = { repository.getPromoCode() },
|
||||
promoNameProvider = { repository.getProgramName() },
|
||||
)
|
||||
|
||||
private lateinit var promotion: Promotion
|
||||
|
||||
override suspend fun init() {
|
||||
initPromotionInfo()
|
||||
}
|
||||
|
||||
override fun isNeedToShowViewOnStoriesScreen(): Boolean {
|
||||
return promotionIsActive()
|
||||
}
|
||||
|
||||
override fun getBasicAuthHeaders(): Map<String, String> {
|
||||
return webViewUriBuilder.getBasicAuthHeaders()
|
||||
}
|
||||
|
||||
override suspend fun isNeedToShowViewOnWalletScreen(walletId: String): Boolean {
|
||||
val response = repository.validate(walletId)
|
||||
|
||||
return if (response.valid == false && response.isError()) {
|
||||
false
|
||||
} else {
|
||||
promotionIsActive()
|
||||
}
|
||||
}
|
||||
|
||||
override fun buildUriForStories(): Uri {
|
||||
val type = if (repository.isHadActivatedCards()) {
|
||||
CardType.NEW
|
||||
} else {
|
||||
CardType.EXISTED
|
||||
}
|
||||
|
||||
return webViewUriBuilder.buildUriForStories(type)
|
||||
}
|
||||
|
||||
override fun buildUriForMainPage(walletId: String, cardId: String, cardPubKey: String): Uri {
|
||||
return webViewUriBuilder.buildUriForMainPage(walletId, cardId, cardPubKey)
|
||||
}
|
||||
|
||||
override fun handleWebViewRedirect(uri: Uri): RedirectConsequences {
|
||||
if (webViewUriBuilder.isReadyForExistedCardAwardRedirect(uri)) {
|
||||
return RedirectConsequences.FINISH_SESSION
|
||||
}
|
||||
|
||||
return if (webViewUriBuilder.isPromoCodeRedirect(uri)) {
|
||||
webViewUriBuilder.extractPromoCode(uri)?.let { repository.savePromoCode(it) }
|
||||
RedirectConsequences.NOTHING
|
||||
} else {
|
||||
RedirectConsequences.PROCEED
|
||||
}
|
||||
}
|
||||
|
||||
private fun promotionIsActive(): Boolean {
|
||||
val isActive = when {
|
||||
repository.isAlreadyReceivedAward() -> false
|
||||
promotion.isError() -> false
|
||||
else -> promotion.getInfo().status == PromotionInfoResponse.Status.ACTIVE
|
||||
}
|
||||
|
||||
return isActive
|
||||
}
|
||||
|
||||
private suspend fun initPromotionInfo() {
|
||||
// return Promotion.dummyActive()
|
||||
|
||||
promotion = repository.getPromotionInfo()
|
||||
.fold(
|
||||
onSuccess = { response ->
|
||||
val responseError = response.error
|
||||
if (responseError == null) {
|
||||
Promotion(
|
||||
info = Promotion.PromotionInfo(
|
||||
status = response.status!!,
|
||||
awardForNewCard = response.awardForNewCard!!,
|
||||
awardForOldCard = response.awardForOldCard!!,
|
||||
awardPaymentToken = response.awardPaymentToken!!,
|
||||
),
|
||||
error = null,
|
||||
)
|
||||
} else {
|
||||
Promotion(
|
||||
info = null,
|
||||
error = responseError.toDomainError(),
|
||||
)
|
||||
}
|
||||
},
|
||||
onFailure = {
|
||||
Promotion(
|
||||
info = null,
|
||||
error = PromotionError.NetworkUnreachable,
|
||||
)
|
||||
},
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,98 @@
|
|||
package com.tangem.feature.learn2earn.domain
|
||||
|
||||
import android.net.Uri
|
||||
import com.tangem.feature.learn2earn.domain.models.CardType
|
||||
import com.tangem.feature.learn2earn.impl.BuildConfig
|
||||
import com.tangem.lib.auth.BasicAuthProvider
|
||||
|
||||
/**
|
||||
[REDACTED_AUTHOR]
|
||||
*/
|
||||
class WebViewUriBuilder(
|
||||
private val basicAuthProvider: BasicAuthProvider,
|
||||
private val userCountryCodeProvider: () -> String,
|
||||
private val promoCodeProvider: () -> String?,
|
||||
private val promoNameProvider: () -> String,
|
||||
) {
|
||||
|
||||
fun buildUriForStories(type: CardType): Uri {
|
||||
val builder = makeWebViewUriBuilder()
|
||||
.appendQueryParameter("type", type.typeName)
|
||||
|
||||
promoCodeProvider.invoke()?.let {
|
||||
builder.appendQueryParameter("code", it)
|
||||
}
|
||||
|
||||
return builder.build()
|
||||
}
|
||||
|
||||
fun buildUriForMainPage(walletId: String, cardId: String, cardPubKey: String): Uri {
|
||||
val builder = makeWebViewUriBuilder()
|
||||
.appendQueryParameter("type", CardType.EXISTED.typeName)
|
||||
.appendQueryParameter("cardPublicKey", cardPubKey)
|
||||
.appendQueryParameter("cardId", cardId)
|
||||
.appendQueryParameter("walletId", walletId)
|
||||
.appendQueryParameter("programName", promoNameProvider.invoke())
|
||||
|
||||
promoCodeProvider.invoke()?.let {
|
||||
builder.appendQueryParameter("code", it)
|
||||
}
|
||||
|
||||
return builder.build()
|
||||
}
|
||||
|
||||
fun getBasicAuthHeaders(): Map<String, String> {
|
||||
return basicAuthProvider.getCredentials()?.let {
|
||||
mapOf("Authorization" to "Basic $it")
|
||||
} ?: mapOf()
|
||||
}
|
||||
|
||||
fun isPromoCodeRedirect(uri: Uri): Boolean {
|
||||
return uri.toString().contains(SUFFIX_CODE_CREATED)
|
||||
}
|
||||
|
||||
fun isReadyForExistedCardAwardRedirect(uri: Uri): Boolean {
|
||||
return uri.toString().endsWith(SUFFIX_READY_FOR_AWARD)
|
||||
}
|
||||
|
||||
fun extractPromoCode(uri: Uri): String? {
|
||||
val url = uri.toString()
|
||||
|
||||
return if (isPromoCodeRedirect(uri)) {
|
||||
val replaceString = makeWebViewUriBuilder().build().toString() + SUFFIX_CODE_CREATED
|
||||
val code = url.replace(replaceString, "")
|
||||
code
|
||||
} else {
|
||||
null
|
||||
}
|
||||
}
|
||||
|
||||
private fun makeWebViewUriBuilder(): Uri.Builder {
|
||||
val builder = Uri.Builder()
|
||||
builder.scheme("https")
|
||||
|
||||
if (BuildConfig.DEBUG) {
|
||||
builder.authority(DEV_WEB_VIEW_BASE_URL)
|
||||
builder.appendPath(userCountryCodeProvider.invoke())
|
||||
builder.appendPath("promotion-test")
|
||||
} else {
|
||||
builder.authority(WEB_VIEW_BASE_URL)
|
||||
builder.appendPath(userCountryCodeProvider.invoke())
|
||||
builder.appendPath("promotion")
|
||||
}
|
||||
|
||||
return builder
|
||||
}
|
||||
|
||||
private companion object {
|
||||
const val WEB_VIEW_BASE_URL = "tangem.com"
|
||||
|
||||
const val DEV_WEB_VIEW_BASE_URL = "devweb.tangem.com"
|
||||
const val DEV_WEB_VIEW_BASIC_AUTH = "Basic dGFuZ2VtOnRhbmdlbWRldjc="
|
||||
// TODO: 1inch: replace by invalid auth
|
||||
// const val DEV_WEB_VIEW_BASIC_AUTH = "Basic paste valid value"
|
||||
|
||||
const val SUFFIX_CODE_CREATED = "/code-created?code="
|
||||
const val SUFFIX_READY_FOR_AWARD = "/ready-for-exsited-card-award"
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,18 @@
|
|||
package com.tangem.feature.learn2earn.domain.api
|
||||
|
||||
import android.net.Uri
|
||||
import com.tangem.feature.learn2earn.domain.models.RedirectConsequences
|
||||
|
||||
/**
|
||||
[REDACTED_AUTHOR]
|
||||
*/
|
||||
interface Learn2earnInteractor {
|
||||
|
||||
suspend fun init()
|
||||
fun isNeedToShowViewOnStoriesScreen(): Boolean
|
||||
suspend fun isNeedToShowViewOnWalletScreen(walletId: String): Boolean
|
||||
fun getBasicAuthHeaders(): Map<String, String>
|
||||
fun buildUriForStories(): Uri
|
||||
fun buildUriForMainPage(walletId: String, cardId: String, cardPubKey: String): Uri
|
||||
fun handleWebViewRedirect(uri: Uri): RedirectConsequences
|
||||
}
|
||||
|
|
@ -0,0 +1,39 @@
|
|||
package com.tangem.feature.learn2earn.domain.di
|
||||
|
||||
import android.content.Context
|
||||
import com.tangem.feature.learn2earn.data.api.Learn2earnRepository
|
||||
import com.tangem.feature.learn2earn.domain.DefaultLearn2earnInteractor
|
||||
import com.tangem.feature.learn2earn.domain.api.Learn2earnInteractor
|
||||
import com.tangem.feature.learn2earn.presentation.Learn2earnRouter
|
||||
import com.tangem.lib.auth.BasicAuthProvider
|
||||
import com.tangem.utils.extensions.toWeakReference
|
||||
import dagger.Module
|
||||
import dagger.Provides
|
||||
import dagger.hilt.InstallIn
|
||||
import dagger.hilt.android.qualifiers.ApplicationContext
|
||||
import dagger.hilt.components.SingletonComponent
|
||||
import javax.inject.Singleton
|
||||
|
||||
@Module
|
||||
@InstallIn(SingletonComponent::class)
|
||||
class Learn2earnDomainModule {
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
fun provideRouter(@ApplicationContext context: Context): Learn2earnRouter {
|
||||
return Learn2earnRouter(context.toWeakReference())
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
fun provideInteractor(
|
||||
repository: Learn2earnRepository,
|
||||
basicAuthProvider: BasicAuthProvider,
|
||||
): Learn2earnInteractor {
|
||||
return DefaultLearn2earnInteractor(
|
||||
repository = repository,
|
||||
basicAuthProvider = basicAuthProvider,
|
||||
userCountryCodeProvider = { "ru" },
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
package com.tangem.feature.learn2earn.domain.models
|
||||
|
||||
/**
|
||||
[REDACTED_AUTHOR]
|
||||
*/
|
||||
enum class CardType(val typeName: String) {
|
||||
NEW("new-card"),
|
||||
EXISTED("existed-card"),
|
||||
}
|
||||
|
|
@ -0,0 +1,76 @@
|
|||
package com.tangem.feature.learn2earn.domain.models
|
||||
|
||||
import com.tangem.datasource.api.promotion.models.PromotionInfoResponse
|
||||
|
||||
/**
|
||||
[REDACTED_AUTHOR]
|
||||
*/
|
||||
internal fun Promotion.Companion.dummyPending(): Promotion {
|
||||
return Promotion(
|
||||
info = Promotion.PromotionInfo.dummy().copy(
|
||||
status = PromotionInfoResponse.Status.PENDING,
|
||||
),
|
||||
error = null,
|
||||
)
|
||||
}
|
||||
|
||||
internal fun Promotion.Companion.dummyActive(): Promotion {
|
||||
return Promotion(
|
||||
info = Promotion.PromotionInfo.dummy().copy(
|
||||
status = PromotionInfoResponse.Status.ACTIVE,
|
||||
),
|
||||
error = null,
|
||||
)
|
||||
}
|
||||
|
||||
internal fun Promotion.Companion.dummyFinished(): Promotion {
|
||||
return Promotion(
|
||||
info = Promotion.PromotionInfo.dummy().copy(
|
||||
status = PromotionInfoResponse.Status.FINISHED,
|
||||
),
|
||||
error = null,
|
||||
)
|
||||
}
|
||||
|
||||
internal fun Promotion.Companion.dummyError(): Promotion {
|
||||
return Promotion(
|
||||
info = null,
|
||||
error = PromotionError.Error(
|
||||
code = 105,
|
||||
description = "any",
|
||||
),
|
||||
)
|
||||
}
|
||||
|
||||
internal fun Promotion.Companion.dummyErrorUnreachable(): Promotion {
|
||||
return Promotion(
|
||||
info = null,
|
||||
error = PromotionError.NetworkUnreachable,
|
||||
)
|
||||
}
|
||||
|
||||
private fun Promotion.PromotionInfo.Companion.dummy(): Promotion.PromotionInfo {
|
||||
return Promotion.PromotionInfo(
|
||||
status = PromotionInfoResponse.Status.ACTIVE,
|
||||
awardForNewCard = 10f,
|
||||
awardForOldCard = 5.5f,
|
||||
awardPaymentToken = Promotion.tokenInfo(),
|
||||
)
|
||||
}
|
||||
|
||||
private fun Promotion.Companion.tokenInfo(): PromotionInfoResponse.TokenInfo {
|
||||
return PromotionInfoResponse.TokenInfo(
|
||||
id = "1inch",
|
||||
name = "1inch",
|
||||
symbol = "1INCH",
|
||||
active = true,
|
||||
networks = listOf(
|
||||
PromotionInfoResponse.TokenInfo.Network(
|
||||
networkId = "polygon-pos",
|
||||
exchangeable = false,
|
||||
contractAddress = "0x9c2c5fd7b07e95ee044ddeba0e97a665f142394f",
|
||||
decimalCount = 1,
|
||||
),
|
||||
),
|
||||
)
|
||||
}
|
||||
|
|
@ -0,0 +1,30 @@
|
|||
package com.tangem.feature.learn2earn.domain.models
|
||||
|
||||
import com.tangem.datasource.api.promotion.models.PromotionInfoResponse
|
||||
|
||||
/**
|
||||
[REDACTED_AUTHOR]
|
||||
*/
|
||||
data class Promotion(
|
||||
val info: PromotionInfo?,
|
||||
val error: PromotionError?,
|
||||
) {
|
||||
|
||||
@Throws(NullPointerException::class)
|
||||
fun getInfo(): PromotionInfo = info!!
|
||||
|
||||
fun isError(): Boolean = error != null
|
||||
|
||||
fun isUnreachable(): Boolean = error == PromotionError.NetworkUnreachable
|
||||
|
||||
data class PromotionInfo(
|
||||
val status: PromotionInfoResponse.Status,
|
||||
val awardForNewCard: Float,
|
||||
val awardForOldCard: Float,
|
||||
val awardPaymentToken: PromotionInfoResponse.TokenInfo,
|
||||
) {
|
||||
companion object
|
||||
}
|
||||
|
||||
companion object
|
||||
}
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
package com.tangem.feature.learn2earn.domain.models
|
||||
|
||||
import com.tangem.datasource.api.promotion.models.AbstractPromotionResponse
|
||||
|
||||
/**
|
||||
[REDACTED_AUTHOR]
|
||||
*/
|
||||
sealed class PromotionError(val code: Int, val description: String) {
|
||||
object NetworkUnreachable : PromotionError(-1, "Network or service is unreachable")
|
||||
class Error(code: Int, description: String) : PromotionError(code, description)
|
||||
|
||||
companion object {
|
||||
fun AbstractPromotionResponse.Error.toDomainError(): PromotionError = Error(code, description)
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,17 @@
|
|||
package com.tangem.feature.learn2earn.domain.models
|
||||
|
||||
import android.net.Uri
|
||||
|
||||
/**
|
||||
[REDACTED_AUTHOR]
|
||||
*/
|
||||
interface WebViewHelper {
|
||||
fun handleWebViewRedirect(uri: Uri): RedirectConsequences
|
||||
fun getWebViewHeaders(): Map<String, String>
|
||||
}
|
||||
|
||||
enum class RedirectConsequences {
|
||||
NOTHING,
|
||||
PROCEED,
|
||||
FINISH_SESSION,
|
||||
}
|
||||
|
|
@ -0,0 +1,23 @@
|
|||
package com.tangem.feature.learn2earn.presentation
|
||||
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import timber.log.Timber
|
||||
import java.lang.ref.WeakReference
|
||||
|
||||
/**
|
||||
[REDACTED_AUTHOR]
|
||||
*/
|
||||
class Learn2earnRouter(
|
||||
private val wContext: WeakReference<Context>,
|
||||
) {
|
||||
|
||||
fun openWebView() {
|
||||
val context = wContext.get()
|
||||
if (context == null) {
|
||||
Timber.e("Can't open the Learn2earnWebViewActivity")
|
||||
} else {
|
||||
context.startActivity(Intent(context, Learn2earnWebViewActivity::class.java))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,58 @@
|
|||
package com.tangem.feature.learn2earn.presentation
|
||||
|
||||
import android.net.Uri
|
||||
import androidx.lifecycle.ViewModel
|
||||
import androidx.lifecycle.viewModelScope
|
||||
import com.tangem.feature.learn2earn.domain.api.Learn2earnInteractor
|
||||
import com.tangem.feature.learn2earn.domain.models.RedirectConsequences
|
||||
import com.tangem.feature.learn2earn.domain.models.WebViewHelper
|
||||
import com.tangem.utils.coroutines.AppCoroutineDispatcherProvider
|
||||
import dagger.hilt.android.lifecycle.HiltViewModel
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.withContext
|
||||
import javax.inject.Inject
|
||||
|
||||
/**
|
||||
[REDACTED_AUTHOR]
|
||||
*/
|
||||
@HiltViewModel
|
||||
class Learn2earnViewModel @Inject constructor(
|
||||
private val interactor: Learn2earnInteractor,
|
||||
private val router: Learn2earnRouter,
|
||||
private val dispatchers: AppCoroutineDispatcherProvider,
|
||||
) : ViewModel(), WebViewHelper {
|
||||
|
||||
var webViewUri: Uri = Uri.parse("https://localhost")
|
||||
private set
|
||||
|
||||
fun isNeedToShowViewOnStoriesScreen(): Boolean = interactor.isNeedToShowViewOnStoriesScreen()
|
||||
|
||||
fun onStoriesClick() {
|
||||
webViewUri = interactor.buildUriForStories()
|
||||
router.openWebView()
|
||||
}
|
||||
|
||||
fun isNeedToShowViewOnWalletScreen(walletId: String, callback: (Boolean) -> Unit) {
|
||||
viewModelScope.launch(dispatchers.io) {
|
||||
val isNeedToShow = interactor.isNeedToShowViewOnWalletScreen(walletId)
|
||||
withContext(dispatchers.main) {
|
||||
callback(isNeedToShow)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun onMainPageClick(walletId: String, cardId: String, cardPubKey: String) {
|
||||
webViewUri = interactor.buildUriForMainPage(walletId, cardId, cardPubKey)
|
||||
router.openWebView()
|
||||
}
|
||||
|
||||
// region WebViewHelper
|
||||
override fun handleWebViewRedirect(uri: Uri): RedirectConsequences {
|
||||
return interactor.handleWebViewRedirect(uri)
|
||||
}
|
||||
|
||||
override fun getWebViewHeaders(): Map<String, String> {
|
||||
return interactor.getBasicAuthHeaders()
|
||||
}
|
||||
// endregion WebViewHelper
|
||||
}
|
||||
|
|
@ -0,0 +1,90 @@
|
|||
package com.tangem.feature.learn2earn.presentation
|
||||
|
||||
import android.os.Bundle
|
||||
import android.view.MenuItem
|
||||
import android.webkit.WebResourceRequest
|
||||
import android.webkit.WebView
|
||||
import android.webkit.WebViewClient
|
||||
import androidx.activity.viewModels
|
||||
import androidx.appcompat.app.ActionBar
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import com.tangem.feature.learn2earn.domain.models.RedirectConsequences
|
||||
import com.tangem.feature.learn2earn.domain.models.WebViewHelper
|
||||
import com.tangem.feature.learn2earn.impl.R
|
||||
import dagger.hilt.android.AndroidEntryPoint
|
||||
|
||||
/**
|
||||
[REDACTED_AUTHOR]
|
||||
*/
|
||||
@AndroidEntryPoint
|
||||
class Learn2earnWebViewActivity : AppCompatActivity() {
|
||||
|
||||
private val learn2earnViewModel by viewModels<Learn2earnViewModel>()
|
||||
|
||||
private lateinit var actionBar: ActionBar
|
||||
private lateinit var webView: WebView
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
setContentView(R.layout.activity_web_view)
|
||||
|
||||
setSupportActionBar(findViewById(R.id.toolbar))
|
||||
actionBar = supportActionBar!!
|
||||
actionBar.setDisplayHomeAsUpEnabled(true)
|
||||
actionBar.setDisplayShowHomeEnabled(true)
|
||||
actionBar.title = learn2earnViewModel.webViewUri.authority
|
||||
|
||||
webView = findViewById(R.id.web_view)
|
||||
webView.settings.javaScriptEnabled = true
|
||||
webView.settings.domStorageEnabled = true
|
||||
webView.settings.loadsImagesAutomatically = true
|
||||
|
||||
webView.webViewClient = Learn2earnWebViewClient(
|
||||
helper = learn2earnViewModel,
|
||||
finishSessionHandler = { finish() },
|
||||
)
|
||||
webView.loadUrl(
|
||||
learn2earnViewModel.webViewUri.toString(),
|
||||
learn2earnViewModel.getWebViewHeaders(),
|
||||
)
|
||||
}
|
||||
|
||||
override fun onOptionsItemSelected(item: MenuItem): Boolean {
|
||||
return when (item.itemId) {
|
||||
android.R.id.home -> {
|
||||
finish()
|
||||
true
|
||||
}
|
||||
else -> super.onOptionsItemSelected(item)
|
||||
}
|
||||
}
|
||||
|
||||
override fun onDestroy() {
|
||||
webView.clearHistory()
|
||||
webView.clearCache(true)
|
||||
webView.destroy()
|
||||
|
||||
super.onDestroy()
|
||||
}
|
||||
}
|
||||
|
||||
private class Learn2earnWebViewClient(
|
||||
private val helper: WebViewHelper,
|
||||
private val finishSessionHandler: () -> Unit,
|
||||
) : WebViewClient() {
|
||||
|
||||
override fun shouldOverrideUrlLoading(view: WebView, request: WebResourceRequest): Boolean {
|
||||
when (helper.handleWebViewRedirect(request.url)) {
|
||||
RedirectConsequences.NOTHING -> Unit
|
||||
RedirectConsequences.PROCEED -> {
|
||||
val headers = helper.getWebViewHeaders().toMutableMap()
|
||||
request.requestHeaders?.let { headers.putAll(it) }
|
||||
view.loadUrl(request.url.toString(), headers)
|
||||
}
|
||||
RedirectConsequences.FINISH_SESSION -> {
|
||||
finishSessionHandler.invoke()
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
|
@ -24,9 +24,9 @@ import com.tangem.feature.learn2earn.presentation.ui.component.GradientCircle
|
|||
/**
|
||||
[REDACTED_AUTHOR]
|
||||
*/
|
||||
// TODO: fixme: make function as internal after adding feature interface
|
||||
// TODO: 1inch: make function as internal after adding feature interface
|
||||
@Composable
|
||||
fun OneInchStoriesScreen(onLearnClick: () -> Unit, modifier: Modifier = Modifier) {
|
||||
fun StoriesScreen(onLearnClick: () -> Unit, modifier: Modifier = Modifier) {
|
||||
Box(modifier = modifier.fillMaxSize()) {
|
||||
ContentBackground(
|
||||
modifier = Modifier
|
||||
|
|
@ -111,7 +111,7 @@ private fun OneInchStoriesContentPreview_Light() {
|
|||
TangemTheme(
|
||||
isDark = false,
|
||||
) {
|
||||
OneInchStoriesScreen(
|
||||
StoriesScreen(
|
||||
onLearnClick = {},
|
||||
)
|
||||
}
|
||||
|
|
@ -123,7 +123,7 @@ private fun OneInchStoriesContentPreview_Dark() {
|
|||
TangemTheme(
|
||||
isDark = true,
|
||||
) {
|
||||
OneInchStoriesScreen(
|
||||
StoriesScreen(
|
||||
onLearnClick = {},
|
||||
)
|
||||
}
|
||||
|
|
@ -0,0 +1,29 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:id="@+id/coordinator_wallet"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical">
|
||||
|
||||
<com.google.android.material.appbar.AppBarLayout
|
||||
android:id="@+id/app_bar"
|
||||
style="@style/Widget.MaterialComponents.Toolbar.Surface"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<com.google.android.material.appbar.MaterialToolbar
|
||||
android:id="@+id/toolbar"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="?attr/actionBarSize"
|
||||
app:navigationIcon="@drawable/ic_close_24" />
|
||||
|
||||
</com.google.android.material.appbar.AppBarLayout>
|
||||
|
||||
<WebView
|
||||
android:id="@+id/web_view"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
app:layout_behavior="@string/appbar_scrolling_view_behavior" />
|
||||
|
||||
</androidx.coordinatorlayout.widget.CoordinatorLayout>
|
||||
Loading…
Add table
Add a link
Reference in a new issue