Updated on 2026-08-14
This commit is contained in:
parent
a382970483
commit
ba09a8d44a
6 changed files with 33 additions and 4 deletions
|
|
@ -35,6 +35,7 @@ interface OnrampApi {
|
|||
@GET("onramp-quote")
|
||||
suspend fun getQuote(
|
||||
@Query("fromCurrencyCode") fromCurrencyCode: String,
|
||||
@Query("fromPrecision") fromPrecision: Int,
|
||||
@Query("toContractAddress") toContractAddress: String,
|
||||
@Query("toNetwork") toNetwork: String,
|
||||
@Query("paymentMethod") paymentMethod: String,
|
||||
|
|
@ -47,6 +48,7 @@ interface OnrampApi {
|
|||
@GET("onramp-data")
|
||||
suspend fun getData(
|
||||
@Query("fromCurrencyCode") fromCurrencyCode: String,
|
||||
@Query("fromPrecision") fromPrecision: Int,
|
||||
@Query("toContractAddress") toContractAddress: String,
|
||||
@Query("toNetwork") toNetwork: String,
|
||||
@Query("paymentMethod") paymentMethod: String,
|
||||
|
|
|
|||
|
|
@ -25,6 +25,9 @@ data class OnrampDataJson(
|
|||
@Json(name = "widgetUrl")
|
||||
val widgetUrl: String,
|
||||
|
||||
@Json(name = "requestId")
|
||||
val requestId: String,
|
||||
|
||||
@Json(name = "externalTxId")
|
||||
val externalTxId: String,
|
||||
|
||||
|
|
|
|||
|
|
@ -21,6 +21,7 @@ dependencies {
|
|||
/** Domain modules */
|
||||
implementation(projects.domain.onramp)
|
||||
implementation(projects.domain.legacy)
|
||||
implementation(projects.domain.appTheme.models)
|
||||
|
||||
// region DI
|
||||
|
||||
|
|
|
|||
|
|
@ -30,8 +30,10 @@ import com.tangem.datasource.local.onramp.quotes.OnrampQuotesStore
|
|||
import com.tangem.datasource.local.preferences.AppPreferencesStore
|
||||
import com.tangem.datasource.local.preferences.PreferencesKeys
|
||||
import com.tangem.datasource.local.preferences.utils.getObject
|
||||
import com.tangem.datasource.local.preferences.utils.getObjectSyncOrDefault
|
||||
import com.tangem.datasource.local.preferences.utils.getObjectSyncOrNull
|
||||
import com.tangem.datasource.local.preferences.utils.storeObject
|
||||
import com.tangem.domain.apptheme.model.AppThemeMode
|
||||
import com.tangem.domain.onramp.model.*
|
||||
import com.tangem.domain.onramp.model.cache.OnrampTransaction
|
||||
import com.tangem.domain.onramp.repositories.OnrampRepository
|
||||
|
|
@ -200,6 +202,7 @@ internal class DefaultOnrampRepository(
|
|||
call = {
|
||||
val response = onrampApi.getQuote(
|
||||
fromCurrencyCode = currency.code,
|
||||
fromPrecision = currency.precision,
|
||||
toContractAddress = cryptoCurrency.getContractAddress(),
|
||||
toNetwork = cryptoCurrency.network.backendId,
|
||||
paymentMethod = paymentMethod.id,
|
||||
|
|
@ -267,10 +270,12 @@ internal class DefaultOnrampRepository(
|
|||
val fromAmountString = quote.fromAmount.value.movePointRight(quote.fromAmount.decimals).toString()
|
||||
val currency = requireNotNull(getDefaultCurrencySync()) { "Default currency must not be null" }
|
||||
val country = requireNotNull(getDefaultCountrySync()) { "Default country must not be null" }
|
||||
val requestId = UUID.randomUUID().toString()
|
||||
val data = safeApiCall(
|
||||
call = {
|
||||
onrampApi.getData(
|
||||
fromCurrencyCode = currency.code,
|
||||
fromPrecision = currency.precision,
|
||||
toContractAddress = cryptoCurrency.getContractAddress(),
|
||||
toNetwork = cryptoCurrency.network.backendId,
|
||||
paymentMethod = quote.paymentMethod.id,
|
||||
|
|
@ -281,8 +286,8 @@ internal class DefaultOnrampRepository(
|
|||
toAddress = address,
|
||||
redirectUrl = "tangem://redirect?action=dismissBrowser",
|
||||
language = null,
|
||||
theme = null,
|
||||
requestId = UUID.randomUUID().toString(),
|
||||
theme = getTheme(),
|
||||
requestId = requestId,
|
||||
).bind()
|
||||
},
|
||||
onError = { e ->
|
||||
|
|
@ -294,6 +299,8 @@ internal class DefaultOnrampRepository(
|
|||
val dataJson = requireNotNull(onrampDataAdapter.fromJson(data.dataJson)) {
|
||||
"Can not parse dataJson. ${data.dataJson}"
|
||||
}
|
||||
if (requestId != dataJson.requestId) throw OnrampRedirectError.WrongRequestId
|
||||
|
||||
createOnrampTransaction(
|
||||
txId = data.txId,
|
||||
onrampDataJson = dataJson,
|
||||
|
|
@ -400,6 +407,19 @@ internal class DefaultOnrampRepository(
|
|||
)
|
||||
}
|
||||
|
||||
private suspend fun getTheme(): String {
|
||||
val appTheme = appPreferencesStore.getObjectSyncOrDefault(
|
||||
key = PreferencesKeys.APP_THEME_MODE_KEY,
|
||||
default = AppThemeMode.DEFAULT,
|
||||
)
|
||||
return when (appTheme) {
|
||||
AppThemeMode.FORCE_DARK -> "dark"
|
||||
AppThemeMode.FORCE_LIGHT,
|
||||
AppThemeMode.FOLLOW_SYSTEM,
|
||||
-> "light"
|
||||
}
|
||||
}
|
||||
|
||||
private fun List<PaymentMethodDTO>.removeApplePay(): List<PaymentMethodDTO> = filterNot { it.id == "apple-pay" }
|
||||
|
||||
private companion object {
|
||||
|
|
|
|||
|
|
@ -5,4 +5,6 @@ sealed class OnrampRedirectError : Throwable() {
|
|||
data class DataError(override val cause: Throwable?) : OnrampRedirectError()
|
||||
|
||||
data object VerificationFailed : OnrampRedirectError()
|
||||
|
||||
data object WrongRequestId : OnrampRedirectError()
|
||||
}
|
||||
|
|
@ -1,9 +1,9 @@
|
|||
package com.tangem.features.onramp.redirect.ui
|
||||
|
||||
import androidx.compose.foundation.Image
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.layout.*
|
||||
import androidx.compose.foundation.shape.CircleShape
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.Scaffold
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
|
|
@ -79,13 +79,14 @@ private fun LogoBlock(providerImageUrl: String, modifier: Modifier = Modifier) {
|
|||
horizontalArrangement = Arrangement.spacedBy(TangemTheme.dimens.spacing12),
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
) {
|
||||
Image(
|
||||
Icon(
|
||||
modifier = Modifier
|
||||
.size(TangemTheme.dimens.size64)
|
||||
.clip(TangemTheme.shapes.roundedCorners8)
|
||||
.background(TangemTheme.colors.background.primary)
|
||||
.padding(vertical = TangemTheme.dimens.spacing8, horizontal = TangemTheme.dimens.spacing12),
|
||||
painter = painterResource(id = R.drawable.ic_tangem_24),
|
||||
tint = TangemTheme.colors.icon.primary1,
|
||||
contentDescription = null,
|
||||
)
|
||||
LoadingDots()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue