diff --git a/app/build.gradle.kts b/app/build.gradle.kts
index 1634169316..efe2848d8c 100644
--- a/app/build.gradle.kts
+++ b/app/build.gradle.kts
@@ -39,6 +39,8 @@ dependencies {
/** Features */
implementation(project(":features:onboarding"))
+ implementation(project(":features:learn2earn:api"))
+ implementation(project(":features:learn2earn:impl"))
implementation(project(":features:referral:presentation"))
implementation(project(":features:referral:domain"))
implementation(project(":features:referral:data"))
diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index ef93ea2179..7185ff029d 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -138,6 +138,10 @@
android:name="com.tangem.tap.features.sprinklr.ui.SprinklrActivity"
android:theme="@style/AppTheme" />
+
+
{
- navigateToInitialScreen(intent)
+ navigateToInitialScreenOnResume(intentWhichStartedActivity)
}
backStackIsEmpty -> {
- navigateToInitialScreen(intent)
+ navigateToInitialScreenOnResume(intentWhichStartedActivity)
}
else -> Unit
}
}
- private fun navigateToInitialScreen(intent: Intent?) {
+ private fun navigateToInitialScreenOnResume(intentWhichStartedActivity: Intent?) {
if (store.state.globalState.userWalletsListManager?.hasUserWallets == true) {
store.dispatchOnMain(NavigationAction.NavigateTo(AppScreen.Welcome))
- store.dispatchOnMain(WelcomeAction.HandleIntentIfNeeded(intent))
+ store.dispatchOnMain(WelcomeAction.SetInitialIntent(intentWhichStartedActivity))
+ scope.launch {
+ val handler = BackgroundScanIntentHandler(hasSavedUserWalletsProvider = { true })
+ val isBackgroundScanNotHandled = handler.handleIntent(intentWhichStartedActivity)
+ val hasNotIncompletedBackup = !backupService.hasIncompletedBackup
+ if (isBackgroundScanNotHandled && hasNotIncompletedBackup) {
+ store.dispatchOnMain(WelcomeAction.ProceedWithBiometrics)
+ }
+ }
} else {
store.dispatchOnMain(NavigationAction.NavigateTo(AppScreen.Home))
- intentHandler.handleIntent(intent, hasSavedUserWallets = false)
+ scope.launch {
+ intentProcessor.handleIntent(intentWhichStartedActivity)
+ }
}
store.dispatch(BackupAction.CheckForUnfinishedBackup)
}
diff --git a/app/src/main/java/com/tangem/tap/TapApplication.kt b/app/src/main/java/com/tangem/tap/TapApplication.kt
index 5de365ee79..114746ccdb 100644
--- a/app/src/main/java/com/tangem/tap/TapApplication.kt
+++ b/app/src/main/java/com/tangem/tap/TapApplication.kt
@@ -1,59 +1,67 @@
package com.tangem.tap
-import android.app.*
-import android.content.*
-import android.content.pm.*
-import coil.*
-import com.tangem.*
-import com.tangem.blockchain.common.*
-import com.tangem.blockchain.network.*
-import com.tangem.core.analytics.*
-import com.tangem.core.featuretoggle.manager.*
-import com.tangem.data.source.preferences.*
-import com.tangem.datasource.api.common.*
-import com.tangem.datasource.asset.*
-import com.tangem.datasource.config.*
-import com.tangem.datasource.config.models.*
-import com.tangem.datasource.connection.*
-import com.tangem.domain.*
-import com.tangem.domain.common.*
-import com.tangem.features.wallet.featuretoggles.*
-import com.tangem.tap.common.*
-import com.tangem.tap.common.analytics.*
-import com.tangem.tap.common.analytics.api.*
-import com.tangem.tap.common.analytics.handlers.amplitude.*
-import com.tangem.tap.common.analytics.handlers.appsFlyer.*
-import com.tangem.tap.common.analytics.handlers.firebase.*
-import com.tangem.tap.common.analytics.topup.*
-import com.tangem.tap.common.chat.*
-import com.tangem.tap.common.feedback.*
-import com.tangem.tap.common.images.*
-import com.tangem.tap.common.log.*
-import com.tangem.tap.common.redux.*
-import com.tangem.tap.common.redux.global.*
-import com.tangem.tap.common.shop.*
-import com.tangem.tap.domain.configurable.warningMessage.*
-import com.tangem.tap.domain.tokens.*
-import com.tangem.tap.domain.totalBalance.*
-import com.tangem.tap.domain.totalBalance.di.*
-import com.tangem.tap.domain.walletCurrencies.*
-import com.tangem.tap.domain.walletCurrencies.di.*
-import com.tangem.tap.domain.walletStores.*
-import com.tangem.tap.domain.walletStores.di.*
-import com.tangem.tap.domain.walletStores.repository.*
-import com.tangem.tap.domain.walletStores.repository.di.*
+import android.app.Application
+import android.content.Context
+import android.content.pm.PackageManager
+import coil.ImageLoader
+import coil.ImageLoaderFactory
+import com.tangem.Log
+import com.tangem.LogFormat
+import com.tangem.blockchain.common.BlockchainSdkConfig
+import com.tangem.blockchain.common.WalletManagerFactory
+import com.tangem.blockchain.network.BlockchainSdkRetrofitBuilder
+import com.tangem.core.analytics.Analytics
+import com.tangem.core.featuretoggle.manager.FeatureTogglesManager
+import com.tangem.data.source.preferences.PreferencesDataSource
+import com.tangem.datasource.api.common.MoshiConverter
+import com.tangem.datasource.asset.AssetReader
+import com.tangem.datasource.config.ConfigManager
+import com.tangem.datasource.config.FeaturesLocalLoader
+import com.tangem.datasource.config.models.Config
+import com.tangem.datasource.connection.NetworkConnectionManager
+import com.tangem.domain.DomainLayer
+import com.tangem.domain.common.LogConfig
+import com.tangem.feature.learn2earn.domain.api.Learn2earnInteractor
+import com.tangem.features.wallet.featuretoggles.WalletFeatureToggles
+import com.tangem.tap.common.analytics.AnalyticsFactory
+import com.tangem.tap.common.analytics.api.AnalyticsHandlerBuilder
+import com.tangem.tap.common.analytics.handlers.amplitude.AmplitudeAnalyticsHandler
+import com.tangem.tap.common.analytics.handlers.appsFlyer.AppsFlyerAnalyticsHandler
+import com.tangem.tap.common.analytics.handlers.firebase.FirebaseAnalyticsHandler
+import com.tangem.tap.common.analytics.topup.TopUpController
+import com.tangem.tap.common.chat.ChatManager
+import com.tangem.tap.common.feedback.AdditionalFeedbackInfo
+import com.tangem.tap.common.feedback.FeedbackManager
+import com.tangem.tap.common.images.createCoilImageLoader
+import com.tangem.tap.common.log.TangemLogCollector
+import com.tangem.tap.common.redux.AppState
+import com.tangem.tap.common.redux.appReducer
+import com.tangem.tap.common.redux.global.GlobalAction
+import com.tangem.tap.common.shop.TangemShopService
+import com.tangem.tap.domain.configurable.warningMessage.WarningMessagesManager
+import com.tangem.tap.domain.tokens.UserTokensRepository
+import com.tangem.tap.domain.totalBalance.TotalFiatBalanceCalculator
+import com.tangem.tap.domain.totalBalance.di.provideDefaultImplementation
+import com.tangem.tap.domain.walletCurrencies.WalletCurrenciesManager
+import com.tangem.tap.domain.walletCurrencies.di.provideDefaultImplementation
+import com.tangem.tap.domain.walletStores.WalletStoresManager
+import com.tangem.tap.domain.walletStores.di.provideDefaultImplementation
+import com.tangem.tap.domain.walletStores.repository.WalletAmountsRepository
+import com.tangem.tap.domain.walletStores.repository.WalletManagersRepository
+import com.tangem.tap.domain.walletStores.repository.WalletStoresRepository
+import com.tangem.tap.domain.walletStores.repository.di.provideDefaultImplementation
import com.tangem.tap.domain.walletconnect.WalletConnectRepository
-import com.tangem.tap.domain.walletconnect2.domain.*
-import com.tangem.tap.features.customtoken.api.featuretoggles.*
-import com.tangem.tap.proxy.*
-import com.tangem.tap.proxy.redux.*
+import com.tangem.tap.domain.walletconnect2.domain.WalletConnectSessionsRepository
+import com.tangem.tap.features.customtoken.api.featuretoggles.CustomTokenFeatureToggles
+import com.tangem.tap.proxy.AppStateHolder
+import com.tangem.tap.proxy.redux.DaggerGraphState
import com.tangem.wallet.BuildConfig
-import dagger.hilt.android.*
-import kotlinx.coroutines.*
-import okhttp3.logging.*
-import org.rekotlin.*
-import timber.log.*
-import javax.inject.*
+import dagger.hilt.android.HiltAndroidApp
+import kotlinx.coroutines.runBlocking
+import okhttp3.logging.HttpLoggingInterceptor
+import org.rekotlin.Store
+import timber.log.Timber
+import javax.inject.Inject
import com.tangem.tap.domain.walletconnect2.domain.WalletConnectRepository as WalletConnect2Repository
lateinit var store: Store
@@ -102,7 +110,6 @@ val walletCurrenciesManager by lazy {
val totalFiatBalanceCalculator by lazy {
TotalFiatBalanceCalculator.provideDefaultImplementation()
}
-val intentHandler by lazy { IntentHandler() }
@HiltAndroidApp
class TapApplication : Application(), ImageLoaderFactory {
@@ -137,6 +144,9 @@ class TapApplication : Application(), ImageLoaderFactory {
@Inject
lateinit var walletConnectSessionsRepository: WalletConnectSessionsRepository
+ @Inject
+ lateinit var learn2earnInteractor: Learn2earnInteractor
+
override fun onCreate() {
super.onCreate()
@@ -190,8 +200,11 @@ class TapApplication : Application(), ImageLoaderFactory {
appStateHolder.userTokensRepository = userTokensRepository
appStateHolder.walletStoresManager = walletStoresManager
- scope.launch {
+ // TODO: Try to performance and user experience.
+ // [REDACTED_JIRA]
+ runBlocking {
featureTogglesManager.init()
+ learn2earnInteractor.init()
}
initTopUpController()
diff --git a/app/src/main/java/com/tangem/tap/common/IntentHandler.kt b/app/src/main/java/com/tangem/tap/common/IntentHandler.kt
deleted file mode 100644
index 4d50c59679..0000000000
--- a/app/src/main/java/com/tangem/tap/common/IntentHandler.kt
+++ /dev/null
@@ -1,127 +0,0 @@
-package com.tangem.tap.common
-
-import android.content.Intent
-import android.net.Uri
-import android.nfc.NfcAdapter
-import android.nfc.Tag
-import android.os.Build
-import com.tangem.core.analytics.Analytics
-import com.tangem.tap.common.analytics.events.AnalyticsParam
-import com.tangem.tap.common.analytics.events.Token
-import com.tangem.tap.common.extensions.removePrefixOrNull
-import com.tangem.tap.domain.walletconnect.WalletConnectManager
-import com.tangem.tap.features.details.redux.walletconnect.WalletConnectAction
-import com.tangem.tap.features.home.redux.HomeAction
-import com.tangem.tap.features.wallet.redux.WalletAction
-import com.tangem.tap.features.welcome.redux.WelcomeAction
-import com.tangem.tap.network.exchangeServices.ExchangeUrlBuilder
-import com.tangem.tap.scope
-import com.tangem.tap.store
-import kotlinx.coroutines.delay
-import kotlinx.coroutines.launch
-import timber.log.Timber
-
-class IntentHandler {
-
- private val nfcActions = arrayOf(
- NfcAdapter.ACTION_NDEF_DISCOVERED,
- NfcAdapter.ACTION_TECH_DISCOVERED,
- NfcAdapter.ACTION_TAG_DISCOVERED,
- )
-
- fun handleIntent(intent: Intent?, hasSavedUserWallets: Boolean) {
- handleBackgroundScan(intent, hasSavedUserWallets)
- handleWalletConnectLink(intent)
- handleBuyCurrencyCallback(intent)
- handleSellCurrencyCallback(intent)
- }
-
- fun handleWalletConnectLink(intent: Intent?) {
- val wcUri = when (intent?.scheme) {
- WalletConnectManager.WC_SCHEME -> {
- intent.data?.toString()
- }
- TANGEM_SCHEME -> {
- intent.data?.toString()?.removePrefixOrNull(TANGEM_WC_PREFIX)
- }
- else -> {
- null
- }
- }
- if (wcUri != null) {
- store.dispatch(WalletConnectAction.HandleDeepLink(wcUri))
- }
- }
-
- fun handleBackgroundScan(intent: Intent?, hasSavedUserWallets: Boolean): Boolean {
- if (intent == null || intent.action !in nfcActions) return false
-
- val tag: Tag? = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
- intent.getParcelableExtra(NfcAdapter.EXTRA_TAG, Tag::class.java)
- } else {
- @Suppress("DEPRECATION")
- intent.getParcelableExtra(NfcAdapter.EXTRA_TAG)
- }
- if (tag == null) return false
-
- intent.action = null
- if (hasSavedUserWallets) {
- // TODO: Remove delay after [REDACTED_JIRA]
- scope.launch {
- delay(timeMillis = 200)
- store.dispatch(WelcomeAction.ProceedWithCard)
- }
- } else {
- store.dispatch(HomeAction.ReadCard())
- }
-
- return true
- }
-
- private fun handleBuyCurrencyCallback(intent: Intent?) {
- val data = intent?.data ?: return
-
- val successUri = Uri.parse(ExchangeUrlBuilder.SUCCESS_URL)
- if (data.host == successUri.host && data.authority == successUri.authority) {
- val currency = store.state.walletState.selectedCurrency ?: return
- val currencyType = AnalyticsParam.CurrencyType.Currency(currency)
- Analytics.send(Token.Bought(currencyType))
- }
- }
-
- fun handleSellCurrencyCallback(intent: Intent?) {
- try {
- val transactionID =
- intent?.data?.getQueryParameter(TRANSACTION_ID_PARAM) ?: return
- val currency =
- intent.data?.getQueryParameter(CURRENCY_CODE_PARAM) ?: return
- val amount =
- intent.data?.getQueryParameter(CURRENCY_AMOUNT_PARAM) ?: return
- val destinationAddress =
- intent.data?.getQueryParameter(DEPOSIT_WALLET_ADDRESS_PARAM)
- ?: return
-
- Timber.d("MoonPay Sell: $amount $currency to $destinationAddress")
-
- store.dispatch(
- WalletAction.TradeCryptoAction.SendCrypto(
- currencyId = currency,
- amount = amount,
- destinationAddress = destinationAddress,
- transactionId = transactionID,
- ),
- )
- } catch (exception: Exception) {
- Timber.d("Not MoonPay URL")
- }
- }
-
- companion object {
- private const val TRANSACTION_ID_PARAM = "transactionId"
- private const val CURRENCY_CODE_PARAM = "baseCurrencyCode"
- private const val CURRENCY_AMOUNT_PARAM = "baseCurrencyAmount"
- private const val DEPOSIT_WALLET_ADDRESS_PARAM = "depositWalletAddress"
- private const val TANGEM_SCHEME = "tangem"
- private const val TANGEM_WC_PREFIX = "tangem://wc?uri="
- }
-}
\ No newline at end of file
diff --git a/app/src/main/java/com/tangem/tap/common/analytics/events/Basic.kt b/app/src/main/java/com/tangem/tap/common/analytics/events/Basic.kt
index f4ef3e133f..e5b89b30e5 100644
--- a/app/src/main/java/com/tangem/tap/common/analytics/events/Basic.kt
+++ b/app/src/main/java/com/tangem/tap/common/analytics/events/Basic.kt
@@ -31,12 +31,14 @@ sealed class Basic(
currency: AnalyticsParam.CardCurrency,
batch: String,
signInType: SignInType,
+ walletsCount: String,
) : Basic(
event = "Signed in",
params = mapOf(
AnalyticsParam.CURRENCY to currency.value,
AnalyticsParam.BATCH to batch,
"Sign in type" to signInType.name,
+ "Wallets Count" to walletsCount,
),
) {
enum class SignInType {
diff --git a/app/src/main/java/com/tangem/tap/common/redux/global/GlobalState.kt b/app/src/main/java/com/tangem/tap/common/redux/global/GlobalState.kt
index c4becfb45b..91c1ae14b7 100644
--- a/app/src/main/java/com/tangem/tap/common/redux/global/GlobalState.kt
+++ b/app/src/main/java/com/tangem/tap/common/redux/global/GlobalState.kt
@@ -6,7 +6,6 @@ import com.tangem.tap.common.analytics.topup.TopUpController
import com.tangem.tap.common.entities.FiatCurrency
import com.tangem.tap.common.feedback.FeedbackManager
import com.tangem.tap.common.redux.StateDialog
-import com.tangem.tap.domain.PayIdManager
import com.tangem.tap.domain.TapWalletManager
import com.tangem.tap.domain.configurable.warningMessage.WarningMessagesManager
import com.tangem.tap.domain.userWalletList.UserWalletsListManager
@@ -20,7 +19,6 @@ data class GlobalState(
val onboardingState: OnboardingState = OnboardingState(),
val cardVerifiedOnline: Boolean = false,
val tapWalletManager: TapWalletManager = TapWalletManager(),
- val payIdManager: PayIdManager = PayIdManager(),
val configManager: ConfigManager? = null,
val warningManager: WarningMessagesManager? = null,
val feedbackManager: FeedbackManager? = null,
diff --git a/app/src/main/java/com/tangem/tap/domain/PayIdManager.kt b/app/src/main/java/com/tangem/tap/domain/PayIdManager.kt
deleted file mode 100644
index 11d5300454..0000000000
--- a/app/src/main/java/com/tangem/tap/domain/PayIdManager.kt
+++ /dev/null
@@ -1,56 +0,0 @@
-package com.tangem.tap.domain
-
-import com.tangem.blockchain.common.Blockchain
-import com.tangem.common.services.Result
-import com.tangem.tap.network.payid.PayIdVerifyService
-import com.tangem.tap.network.payid.VerifyPayIdResponse
-import kotlinx.coroutines.Dispatchers
-import kotlinx.coroutines.withContext
-import java.util.*
-
-class PayIdManager {
-
- @Suppress("MagicNumber")
- suspend fun verifyPayId(payId: String, blockchain: Blockchain): Result =
- withContext(Dispatchers.IO) {
- val splitPayId = payId.split("\$")
- val user = splitPayId[0]
- val baseUrl = "https://${splitPayId[1]}/"
- return@withContext PayIdVerifyService(baseUrl).verifyAddress(user, blockchain.getPayIdNetwork())
- }
-
- private fun Blockchain.getPayIdNetwork(): String {
- return when (this) {
- Blockchain.XRP -> "XRPL"
- Blockchain.RSK -> "RSK"
- else -> this.currency
- }.lowercase(Locale.getDefault())
- }
-
- companion object {
- private val payIdRegExp = (
- "^[a-z0-9!#@%&*+/=?^_`{|}~-]+(?:\\.[a-z0-9!#@%&*+/=?^_`{|}~-]+)*\\\$(?:(?:[a-z0-9]" +
- "(?:[a-z0-9-]*[a-z0-9])?\\.)+[a-z0-9](?:[a-z-]*[a-z0-9])?|(?:[0-9]{1,3}\\.){3}[0-9]{1,3})\$"
- ).toRegex()
-
- val payIdSupported: EnumSet = EnumSet.of(
- Blockchain.XRP,
- Blockchain.Ethereum,
- Blockchain.Bitcoin,
- Blockchain.Litecoin,
- Blockchain.Stellar,
- Blockchain.Cardano,
- Blockchain.CardanoShelley,
- Blockchain.BitcoinCash,
- Blockchain.Binance,
- Blockchain.RSK,
- Blockchain.Tezos,
- )
-
- fun isPayId(value: String?): Boolean = value?.contains(payIdRegExp) ?: false
- }
-}
-
-fun Blockchain.isPayIdSupported(): Boolean {
- return PayIdManager.payIdSupported.contains(this)
-}
\ No newline at end of file
diff --git a/app/src/main/java/com/tangem/tap/domain/TapWalletManager.kt b/app/src/main/java/com/tangem/tap/domain/TapWalletManager.kt
index f9be91dcce..4e39b73bbe 100644
--- a/app/src/main/java/com/tangem/tap/domain/TapWalletManager.kt
+++ b/app/src/main/java/com/tangem/tap/domain/TapWalletManager.kt
@@ -1,6 +1,9 @@
package com.tangem.tap.domain
-import com.tangem.blockchain.common.*
+import com.tangem.blockchain.common.BlockchainSdkConfig
+import com.tangem.blockchain.common.Token
+import com.tangem.blockchain.common.Wallet
+import com.tangem.blockchain.common.WalletManagerFactory
import com.tangem.common.doOnFailure
import com.tangem.common.doOnSuccess
import com.tangem.core.analytics.Analytics
@@ -134,22 +137,13 @@ class TapWalletManager(
fun updateConfigManager(data: ScanResponse) {
val configManager = store.state.globalState.configManager
- val blockchain = data.cardTypesResolver.getBlockchain()
+
if (data.cardTypesResolver.isStart2Coin()) {
- configManager?.turnOff(ConfigManager.IS_SENDING_TO_PAY_ID_ENABLED)
configManager?.turnOff(ConfigManager.IS_TOP_UP_ENABLED)
- } else if (blockchain == Blockchain.Bitcoin ||
- data.walletData?.blockchain == Blockchain.Bitcoin.id
- ) {
- configManager?.resetToDefault(ConfigManager.IS_SENDING_TO_PAY_ID_ENABLED)
- configManager?.resetToDefault(ConfigManager.IS_TOP_UP_ENABLED)
} else {
- configManager?.resetToDefault(ConfigManager.IS_SENDING_TO_PAY_ID_ENABLED)
configManager?.resetToDefault(ConfigManager.IS_TOP_UP_ENABLED)
}
}
}
-fun Wallet.getFirstToken(): Token? {
- return getTokens().toList().getOrNull(0)
-}
\ No newline at end of file
+fun Wallet.getFirstToken(): Token? = getTokens().toList().getOrNull(index = 0)
\ No newline at end of file
diff --git a/app/src/main/java/com/tangem/tap/domain/userWalletList/UserWalletsListManager.kt b/app/src/main/java/com/tangem/tap/domain/userWalletList/UserWalletsListManager.kt
index b1c97b594b..249ac0d0f4 100644
--- a/app/src/main/java/com/tangem/tap/domain/userWalletList/UserWalletsListManager.kt
+++ b/app/src/main/java/com/tangem/tap/domain/userWalletList/UserWalletsListManager.kt
@@ -26,6 +26,11 @@ interface UserWalletsListManager {
* */
val hasUserWallets: Boolean
+ /**
+ * Count of saved user wallets
+ */
+ val walletsCount: Int
+
/**
* Set [UserWallet] with provided [UserWalletId] as selected
*
diff --git a/app/src/main/java/com/tangem/tap/domain/userWalletList/implementation/BiometricUserWalletsListManager.kt b/app/src/main/java/com/tangem/tap/domain/userWalletList/implementation/BiometricUserWalletsListManager.kt
index 4ea180e270..568d16fc28 100644
--- a/app/src/main/java/com/tangem/tap/domain/userWalletList/implementation/BiometricUserWalletsListManager.kt
+++ b/app/src/main/java/com/tangem/tap/domain/userWalletList/implementation/BiometricUserWalletsListManager.kt
@@ -53,6 +53,9 @@ internal class BiometricUserWalletsListManager(
override val hasUserWallets: Boolean
get() = keysRepository.hasSavedEncryptionKeys()
+ override val walletsCount: Int
+ get() = state.value.userWallets.size
+
override suspend fun unlock(): CompletionResult {
return unlockWithBiometryInternal()
.mapFailure { error ->
diff --git a/app/src/main/java/com/tangem/tap/domain/userWalletList/implementation/RuntimeUserWalletsListManager.kt b/app/src/main/java/com/tangem/tap/domain/userWalletList/implementation/RuntimeUserWalletsListManager.kt
index c94958d46f..cfcd68bc57 100644
--- a/app/src/main/java/com/tangem/tap/domain/userWalletList/implementation/RuntimeUserWalletsListManager.kt
+++ b/app/src/main/java/com/tangem/tap/domain/userWalletList/implementation/RuntimeUserWalletsListManager.kt
@@ -7,13 +7,7 @@ import com.tangem.tap.domain.model.UserWallet
import com.tangem.tap.domain.userWalletList.UserWalletsListError
import com.tangem.tap.domain.userWalletList.UserWalletsListManager
import kotlinx.coroutines.ExperimentalCoroutinesApi
-import kotlinx.coroutines.flow.Flow
-import kotlinx.coroutines.flow.MutableStateFlow
-import kotlinx.coroutines.flow.distinctUntilChanged
-import kotlinx.coroutines.flow.filterNotNull
-import kotlinx.coroutines.flow.mapLatest
-import kotlinx.coroutines.flow.update
-import kotlinx.coroutines.flow.updateAndGet
+import kotlinx.coroutines.flow.*
@OptIn(ExperimentalCoroutinesApi::class)
internal class RuntimeUserWalletsListManager : UserWalletsListManager {
@@ -36,6 +30,12 @@ internal class RuntimeUserWalletsListManager : UserWalletsListManager {
override val hasUserWallets: Boolean
get() = state.value.userWallet != null
+ /**
+ * only 1 wallet stored in runtime implementation
+ */
+ override val walletsCount: Int
+ get() = 1
+
override suspend fun select(userWalletId: UserWalletId): CompletionResult = catching {
state.value.userWallet
?.takeIf { it.walletId == userWalletId }
diff --git a/app/src/main/java/com/tangem/tap/features/home/HomeFragment.kt b/app/src/main/java/com/tangem/tap/features/home/HomeFragment.kt
index acf3408acf..57598aa099 100644
--- a/app/src/main/java/com/tangem/tap/features/home/HomeFragment.kt
+++ b/app/src/main/java/com/tangem/tap/features/home/HomeFragment.kt
@@ -12,36 +12,47 @@ import androidx.compose.ui.platform.ComposeView
import androidx.core.view.WindowCompat
import androidx.core.view.WindowInsetsControllerCompat
import androidx.fragment.app.Fragment
-import com.google.accompanist.appcompattheme.AppCompatTheme
+import androidx.fragment.app.activityViewModels
import com.tangem.core.analytics.Analytics
+import com.tangem.core.ui.res.TangemTheme
+import com.tangem.feature.learn2earn.presentation.Learn2earnViewModel
import com.tangem.tap.common.analytics.events.IntroductionProcess
import com.tangem.tap.common.redux.navigation.AppScreen
import com.tangem.tap.common.redux.navigation.NavigationAction
import com.tangem.tap.features.home.compose.StoriesScreen
import com.tangem.tap.features.home.redux.HomeAction
import com.tangem.tap.features.home.redux.HomeState
+import com.tangem.tap.features.home.redux.Stories
import com.tangem.tap.features.tokens.legacy.redux.TokensAction
import com.tangem.tap.store
+import dagger.hilt.android.AndroidEntryPoint
import org.rekotlin.StoreSubscriber
+@AndroidEntryPoint
class HomeFragment : Fragment(), StoreSubscriber {
private var homeState: MutableState = mutableStateOf(store.state.homeState)
+ private val learn2earnViewModel by activityViewModels()
+
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
store.dispatch(HomeAction.OnCreate)
store.dispatch(HomeAction.Init)
+ if (learn2earnViewModel.uiState.storyScreenState.isVisible) {
+ store.dispatch(HomeAction.InsertStory(position = 0, Stories.OneInchPromo))
+ // re init homeState after inserting learn2earn story
+ homeState = mutableStateOf(store.state.homeState)
+ }
}
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View {
return ComposeView(inflater.context).apply {
setContent {
- BackHandler {
- requireActivity().finish()
- }
-
- AppCompatTheme {
+ TangemTheme {
+ BackHandler {
+ requireActivity().finish()
+ }
ScreenContent()
}
}
@@ -79,7 +90,8 @@ class HomeFragment : Fragment(), StoreSubscriber {
@Composable
private fun ScreenContent() {
StoriesScreen(
- homeState,
+ homeState = homeState,
+ onLearn2earnClick = learn2earnViewModel.uiState.storyScreenState.onClick,
onScanButtonClick = {
Analytics.send(IntroductionProcess.ButtonScanCard())
store.dispatch(HomeAction.ReadCard())
diff --git a/app/src/main/java/com/tangem/tap/features/home/compose/StoriesScreen.kt b/app/src/main/java/com/tangem/tap/features/home/compose/StoriesScreen.kt
index ef40d850f6..fa3e832436 100644
--- a/app/src/main/java/com/tangem/tap/features/home/compose/StoriesScreen.kt
+++ b/app/src/main/java/com/tangem/tap/features/home/compose/StoriesScreen.kt
@@ -5,29 +5,11 @@ package com.tangem.tap.features.home.compose
import androidx.compose.foundation.Image
import androidx.compose.foundation.background
import androidx.compose.foundation.gestures.detectTapGestures
-import androidx.compose.foundation.layout.Arrangement
-import androidx.compose.foundation.layout.Box
-import androidx.compose.foundation.layout.Column
-import androidx.compose.foundation.layout.Row
-import androidx.compose.foundation.layout.WindowInsets
-import androidx.compose.foundation.layout.fillMaxHeight
-import androidx.compose.foundation.layout.fillMaxSize
-import androidx.compose.foundation.layout.fillMaxWidth
-import androidx.compose.foundation.layout.height
-import androidx.compose.foundation.layout.heightIn
-import androidx.compose.foundation.layout.navigationBarsPadding
-import androidx.compose.foundation.layout.padding
-import androidx.compose.foundation.layout.statusBars
-import androidx.compose.foundation.layout.union
-import androidx.compose.foundation.layout.windowInsetsPadding
+import androidx.compose.foundation.layout.*
import androidx.compose.material.Button
import androidx.compose.material.ButtonDefaults
import androidx.compose.material.Text
-import androidx.compose.runtime.Composable
-import androidx.compose.runtime.LaunchedEffect
-import androidx.compose.runtime.MutableState
-import androidx.compose.runtime.mutableStateOf
-import androidx.compose.runtime.remember
+import androidx.compose.runtime.*
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.alpha
@@ -43,38 +25,40 @@ import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import com.google.accompanist.systemuicontroller.rememberSystemUiController
-import com.tangem.tap.features.home.compose.content.FirstStoriesContent
-import com.tangem.tap.features.home.compose.content.StoriesCurrencies
-import com.tangem.tap.features.home.compose.content.StoriesRevolutionaryWallet
-import com.tangem.tap.features.home.compose.content.StoriesUltraSecureBackup
-import com.tangem.tap.features.home.compose.content.StoriesWalletForEveryone
-import com.tangem.tap.features.home.compose.content.StoriesWeb3
+import com.tangem.core.ui.res.TangemTheme
+import com.tangem.feature.learn2earn.presentation.ui.Learn2earnStoriesScreen
+import com.tangem.tap.features.home.compose.content.*
import com.tangem.tap.features.home.compose.views.HomeButtons
import com.tangem.tap.features.home.compose.views.StoriesProgressBar
import com.tangem.tap.features.home.redux.HomeState
+import com.tangem.tap.features.home.redux.Stories
import com.tangem.wallet.R
import kotlin.math.max
-private const val STEPS = 6
-
@Suppress("LongMethod", "ComplexMethod")
@Composable
fun StoriesScreen(
homeState: MutableState,
+ onLearn2earnClick: () -> Unit,
onScanButtonClick: () -> Unit,
onShopButtonClick: () -> Unit,
onSearchTokensClick: () -> Unit,
) {
- val currentStep = remember { mutableStateOf(1) }
val systemUiController = rememberSystemUiController()
+ val state = homeState.value
- val isDarkBackground = currentStep.value !in 3..5
+ var currentStory by remember { mutableStateOf(state.firstStory) }
+ val currentStep = { state.stepOf(currentStory) }
val goToPreviousScreen = {
- currentStep.value = max(1, currentStep.value - 1)
+ currentStory = state.stories[max(0, currentStep() - 1)]
}
val goToNextScreen = {
- currentStep.value = if (currentStep.value < STEPS) currentStep.value + 1 else 1
+ currentStory = if (currentStep() < state.stories.lastIndex) {
+ state.stories[currentStep() + 1]
+ } else {
+ state.firstStory
+ }
}
val isPressed = remember { mutableStateOf(false) }
@@ -82,10 +66,10 @@ fun StoriesScreen(
val hideContent = remember { mutableStateOf(true) }
- LaunchedEffect(key1 = isDarkBackground) {
+ LaunchedEffect(key1 = currentStory.isDarkBackground) {
systemUiController.setSystemBarsColor(
color = Color.Transparent,
- darkIcons = !isDarkBackground,
+ darkIcons = !currentStory.isDarkBackground,
)
}
@@ -134,7 +118,7 @@ fun StoriesScreen(
},
)
}
- if (!isDarkBackground) {
+ if (!currentStory.isDarkBackground) {
Image(
modifier = Modifier.fillMaxSize(),
painter = painterResource(id = R.drawable.ic_overlay),
@@ -154,9 +138,9 @@ fun StoriesScreen(
verticalArrangement = Arrangement.Center,
) {
StoriesProgressBar(
- steps = STEPS,
- currentStep = currentStep.value,
- stepDuration = currentStep.duration(),
+ steps = state.stories.lastIndex,
+ currentStep = currentStep(),
+ stepDuration = currentStory.duration,
paused = isPaused,
onStepFinish = goToNextScreen,
)
@@ -169,15 +153,16 @@ fun StoriesScreen(
.height(17.dp)
.alpha(if (hideContent.value) 0f else 1f)
.align(Alignment.Start),
- colorFilter = if (isDarkBackground) null else ColorFilter.tint(Color.Black),
+ colorFilter = if (currentStory.isDarkBackground) null else ColorFilter.tint(Color.Black),
)
- when (currentStep.value) {
- 1 -> FirstStoriesContent(isPaused, currentStep.duration()) { hideContent.value = it }
- 2 -> StoriesRevolutionaryWallet(currentStep.duration())
- 3 -> StoriesUltraSecureBackup(isPaused, currentStep.duration())
- 4 -> StoriesCurrencies(isPaused, currentStep.duration())
- 5 -> StoriesWeb3(isPaused, currentStep.duration())
- 6 -> StoriesWalletForEveryone(currentStep.duration())
+ when (currentStory) {
+ Stories.OneInchPromo -> Learn2earnStoriesScreen(onLearn2earnClick)
+ Stories.TangemIntro -> FirstStoriesContent(isPaused, currentStory.duration) { hideContent.value = it }
+ Stories.RevolutionaryWallet -> StoriesRevolutionaryWallet(currentStory.duration)
+ Stories.UltraSecureBackup -> StoriesUltraSecureBackup(isPaused, currentStory.duration)
+ Stories.Currencies -> StoriesCurrencies(isPaused, currentStory.duration)
+ Stories.Web3 -> StoriesWeb3(isPaused, currentStory.duration)
+ Stories.WalletForEveryone -> StoriesWalletForEveryone(currentStory.duration)
}
}
Column(
@@ -186,7 +171,7 @@ fun StoriesScreen(
.align(Alignment.BottomCenter)
.fillMaxWidth(),
) {
- if (currentStep.value == 4) {
+ if (currentStory == Stories.Currencies) {
Button(
onClick = onSearchTokensClick,
modifier = Modifier
@@ -210,29 +195,31 @@ fun StoriesScreen(
)
}
}
- HomeButtons(
- modifier = Modifier
- .padding(start = 16.dp, top = 0.dp, end = 16.dp, bottom = 37.dp)
- .fillMaxWidth(),
- isDarkBackground = isDarkBackground,
- btnScanStateInProgress = homeState.value.btnScanStateInProgress,
- onScanButtonClick = onScanButtonClick,
- onShopButtonClick = onShopButtonClick,
- )
+
+ if (currentStory != Stories.OneInchPromo) {
+ HomeButtons(
+ modifier = Modifier
+ .padding(
+ start = TangemTheme.dimens.size16,
+ end = TangemTheme.dimens.size16,
+ bottom = TangemTheme.dimens.size36,
+ )
+ .fillMaxWidth(),
+ isDarkBackground = currentStory.isDarkBackground,
+ btnScanStateInProgress = homeState.value.btnScanStateInProgress,
+ onScanButtonClick = onScanButtonClick,
+ onShopButtonClick = onShopButtonClick,
+ )
+ }
}
}
}
-@Suppress("MagicNumber")
-private fun MutableState.duration(): Int = when (this.value) {
- 1 -> 8000
- else -> 6000
-}
-
@Preview
@Composable
private fun StoriesScreenPreview() {
StoriesScreen(
+ onLearn2earnClick = {},
onScanButtonClick = {},
onShopButtonClick = {},
onSearchTokensClick = {},
diff --git a/app/src/main/java/com/tangem/tap/features/home/compose/views/StoriesProgressBar.kt b/app/src/main/java/com/tangem/tap/features/home/compose/views/StoriesProgressBar.kt
index f92adcf9d1..2774f0f683 100644
--- a/app/src/main/java/com/tangem/tap/features/home/compose/views/StoriesProgressBar.kt
+++ b/app/src/main/java/com/tangem/tap/features/home/compose/views/StoriesProgressBar.kt
@@ -4,12 +4,7 @@ import androidx.compose.animation.core.Animatable
import androidx.compose.animation.core.LinearEasing
import androidx.compose.animation.core.tween
import androidx.compose.foundation.background
-import androidx.compose.foundation.layout.Box
-import androidx.compose.foundation.layout.Row
-import androidx.compose.foundation.layout.fillMaxHeight
-import androidx.compose.foundation.layout.fillMaxWidth
-import androidx.compose.foundation.layout.height
-import androidx.compose.foundation.layout.padding
+import androidx.compose.foundation.layout.*
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.remember
@@ -52,7 +47,7 @@ fun StoriesProgressBar(
// .height()
.padding(start = 9.dp, end = 9.dp, top = 16.dp),
) {
- for (index in 1..steps) {
+ for (index in 0..steps) {
Row(
modifier = Modifier
.height(2.dp)
diff --git a/app/src/main/java/com/tangem/tap/features/home/redux/HomeAction.kt b/app/src/main/java/com/tangem/tap/features/home/redux/HomeAction.kt
index bb9be2edc3..86b139defb 100644
--- a/app/src/main/java/com/tangem/tap/features/home/redux/HomeAction.kt
+++ b/app/src/main/java/com/tangem/tap/features/home/redux/HomeAction.kt
@@ -11,6 +11,8 @@ sealed class HomeAction : Action {
object OnCreate : HomeAction()
object Init : HomeAction()
+ data class InsertStory(val position: Int, val story: Stories) : HomeAction()
+
data class ReadCard(
val analyticsEvent: AnalyticsEvent? = Basic.CardWasScanned(AnalyticsParam.ScannedFrom.Introduction),
) : HomeAction()
diff --git a/app/src/main/java/com/tangem/tap/features/home/redux/HomeReducer.kt b/app/src/main/java/com/tangem/tap/features/home/redux/HomeReducer.kt
index f9f2911c32..6843253f5a 100644
--- a/app/src/main/java/com/tangem/tap/features/home/redux/HomeReducer.kt
+++ b/app/src/main/java/com/tangem/tap/features/home/redux/HomeReducer.kt
@@ -12,6 +12,13 @@ private fun internalReduce(action: Action, state: AppState): HomeState {
var state = state.homeState
when (action) {
+ is HomeAction.InsertStory -> {
+ state = state.copy(
+ stories = state.stories.toMutableList().apply {
+ add(action.position, action.story)
+ },
+ )
+ }
is HomeAction.ScanInProgress -> {
state = state.copy(scanInProgress = action.scanInProgress)
}
diff --git a/app/src/main/java/com/tangem/tap/features/home/redux/HomeState.kt b/app/src/main/java/com/tangem/tap/features/home/redux/HomeState.kt
index 618e432dec..415deb938d 100644
--- a/app/src/main/java/com/tangem/tap/features/home/redux/HomeState.kt
+++ b/app/src/main/java/com/tangem/tap/features/home/redux/HomeState.kt
@@ -8,8 +8,38 @@ import org.rekotlin.StateType
data class HomeState(
val scanInProgress: Boolean = false,
val btnScanState: IndeterminateProgressButton = IndeterminateProgressButton(ButtonState.ENABLED),
+ val stories: List = initDefaultStories(),
) : StateType {
+ val firstStory: Stories
+ get() = stories[0]
+
val btnScanStateInProgress: Boolean
get() = btnScanState.progressState == ProgressState.Loading
+
+ fun stepOf(story: Stories): Int = stories.indexOf(story)
+
+ companion object {
+ fun initDefaultStories(): List = listOf(
+ Stories.TangemIntro,
+ Stories.RevolutionaryWallet,
+ Stories.UltraSecureBackup,
+ Stories.Currencies,
+ Stories.Web3,
+ Stories.WalletForEveryone,
+ )
+ }
+}
+
+sealed class Stories(
+ val isDarkBackground: Boolean,
+ val duration: Int,
+) {
+ object OneInchPromo : Stories(true, duration = 8000)
+ object TangemIntro : Stories(true, duration = 8000)
+ object RevolutionaryWallet : Stories(true, duration = 6000)
+ object UltraSecureBackup : Stories(false, duration = 6000)
+ object Currencies : Stories(false, duration = 6000)
+ object Web3 : Stories(false, duration = 6000)
+ object WalletForEveryone : Stories(true, duration = 6000)
}
\ No newline at end of file
diff --git a/app/src/main/java/com/tangem/tap/features/intentHandler/IntentHandler.kt b/app/src/main/java/com/tangem/tap/features/intentHandler/IntentHandler.kt
new file mode 100644
index 0000000000..ba008d4e5a
--- /dev/null
+++ b/app/src/main/java/com/tangem/tap/features/intentHandler/IntentHandler.kt
@@ -0,0 +1,10 @@
+package com.tangem.tap.features.intentHandler
+
+import android.content.Intent
+
+/**
+[REDACTED_AUTHOR]
+ */
+interface IntentHandler {
+ suspend fun handleIntent(intent: Intent?): Boolean
+}
\ No newline at end of file
diff --git a/app/src/main/java/com/tangem/tap/features/intentHandler/IntentProcessor.kt b/app/src/main/java/com/tangem/tap/features/intentHandler/IntentProcessor.kt
new file mode 100644
index 0000000000..47cf6a31fd
--- /dev/null
+++ b/app/src/main/java/com/tangem/tap/features/intentHandler/IntentProcessor.kt
@@ -0,0 +1,31 @@
+package com.tangem.tap.features.intentHandler
+
+import android.content.Intent
+import java.util.concurrent.CopyOnWriteArrayList
+
+/**
+[REDACTED_AUTHOR]
+ */
+// TODO: fixme: close it with the combined interfaces IntentHandler and IntentHandlerHolder
+class IntentProcessor {
+
+ private val intentHandlers = CopyOnWriteArrayList()
+
+ fun addHandler(handler: IntentHandler) {
+ intentHandlers.add(handler)
+ }
+
+ fun removeIntentHandler(handler: IntentHandler) {
+ intentHandlers.remove(handler)
+ }
+
+ fun removeAll() {
+ intentHandlers.clear()
+ }
+
+ suspend fun handleIntent(intent: Intent?) {
+ intentHandlers.forEach {
+ it.handleIntent(intent)
+ }
+ }
+}
\ No newline at end of file
diff --git a/app/src/main/java/com/tangem/tap/features/intentHandler/handlers/BackgroundScanIntentHandler.kt b/app/src/main/java/com/tangem/tap/features/intentHandler/handlers/BackgroundScanIntentHandler.kt
new file mode 100644
index 0000000000..18a51c222f
--- /dev/null
+++ b/app/src/main/java/com/tangem/tap/features/intentHandler/handlers/BackgroundScanIntentHandler.kt
@@ -0,0 +1,52 @@
+package com.tangem.tap.features.intentHandler.handlers
+
+import android.content.Intent
+import android.nfc.NfcAdapter
+import android.nfc.Tag
+import android.os.Build
+import com.tangem.tap.features.home.redux.HomeAction
+import com.tangem.tap.features.intentHandler.IntentHandler
+import com.tangem.tap.features.welcome.redux.WelcomeAction
+import com.tangem.tap.scope
+import com.tangem.tap.store
+import kotlinx.coroutines.delay
+import kotlinx.coroutines.launch
+
+/**
+[REDACTED_AUTHOR]
+ */
+class BackgroundScanIntentHandler(
+ private val hasSavedUserWalletsProvider: () -> Boolean,
+) : IntentHandler {
+
+ private val nfcActions = arrayOf(
+ NfcAdapter.ACTION_NDEF_DISCOVERED,
+ NfcAdapter.ACTION_TECH_DISCOVERED,
+ NfcAdapter.ACTION_TAG_DISCOVERED,
+ )
+
+ override suspend fun handleIntent(intent: Intent?): Boolean {
+ if (intent == null || intent.action !in nfcActions) return false
+
+ val tag: Tag? = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
+ intent.getParcelableExtra(NfcAdapter.EXTRA_TAG, Tag::class.java)
+ } else {
+ @Suppress("DEPRECATION")
+ intent.getParcelableExtra(NfcAdapter.EXTRA_TAG)
+ }
+ if (tag == null) return false
+
+ intent.action = null
+ if (hasSavedUserWalletsProvider.invoke()) {
+ // TODO: Remove delay after [REDACTED_JIRA]
+ scope.launch {
+ delay(timeMillis = 200)
+ store.dispatch(WelcomeAction.ProceedWithCard)
+ }
+ } else {
+ store.dispatch(HomeAction.ReadCard())
+ }
+
+ return true
+ }
+}
\ No newline at end of file
diff --git a/app/src/main/java/com/tangem/tap/features/intentHandler/handlers/BuyCurrencyIntentHandler.kt b/app/src/main/java/com/tangem/tap/features/intentHandler/handlers/BuyCurrencyIntentHandler.kt
new file mode 100644
index 0000000000..39dda7cd24
--- /dev/null
+++ b/app/src/main/java/com/tangem/tap/features/intentHandler/handlers/BuyCurrencyIntentHandler.kt
@@ -0,0 +1,30 @@
+package com.tangem.tap.features.intentHandler.handlers
+
+import android.content.Intent
+import android.net.Uri
+import com.tangem.core.analytics.Analytics
+import com.tangem.tap.common.analytics.events.AnalyticsParam
+import com.tangem.tap.common.analytics.events.Token
+import com.tangem.tap.features.intentHandler.IntentHandler
+import com.tangem.tap.network.exchangeServices.ExchangeUrlBuilder
+import com.tangem.tap.store
+
+/**
+[REDACTED_AUTHOR]
+ */
+class BuyCurrencyIntentHandler : IntentHandler {
+
+ override suspend fun handleIntent(intent: Intent?): Boolean {
+ val data = intent?.data ?: return false
+ val currency = store.state.walletState.selectedCurrency ?: return false
+
+ val successUri = Uri.parse(ExchangeUrlBuilder.SUCCESS_URL)
+ return if (data.host == successUri.host && data.authority == successUri.authority) {
+ val currencyType = AnalyticsParam.CurrencyType.Currency(currency)
+ Analytics.send(Token.Bought(currencyType))
+ true
+ } else {
+ false
+ }
+ }
+}
\ No newline at end of file
diff --git a/app/src/main/java/com/tangem/tap/features/intentHandler/handlers/SellCurrencyIntentHandler.kt b/app/src/main/java/com/tangem/tap/features/intentHandler/handlers/SellCurrencyIntentHandler.kt
new file mode 100644
index 0000000000..3fc6c318d6
--- /dev/null
+++ b/app/src/main/java/com/tangem/tap/features/intentHandler/handlers/SellCurrencyIntentHandler.kt
@@ -0,0 +1,44 @@
+package com.tangem.tap.features.intentHandler.handlers
+
+import android.content.Intent
+import com.tangem.tap.features.intentHandler.IntentHandler
+import com.tangem.tap.features.wallet.redux.WalletAction
+import com.tangem.tap.store
+import timber.log.Timber
+
+/**
+[REDACTED_AUTHOR]
+ */
+class SellCurrencyIntentHandler : IntentHandler {
+
+ override suspend fun handleIntent(intent: Intent?): Boolean {
+ return try {
+ val intentData = intent?.data ?: return false
+ val transactionID = intentData.getQueryParameter(TRANSACTION_ID_PARAM) ?: return false
+ val currency = intentData.getQueryParameter(CURRENCY_CODE_PARAM) ?: return false
+ val amount = intentData.getQueryParameter(CURRENCY_AMOUNT_PARAM) ?: return false
+ val destinationAddress = intentData.getQueryParameter(DEPOSIT_WALLET_ADDRESS_PARAM) ?: return false
+
+ Timber.d("MoonPay Sell: $amount $currency to $destinationAddress")
+ store.dispatch(
+ WalletAction.TradeCryptoAction.SendCrypto(
+ currencyId = currency,
+ amount = amount,
+ destinationAddress = destinationAddress,
+ transactionId = transactionID,
+ ),
+ )
+ true
+ } catch (exception: Exception) {
+ Timber.d("Not MoonPay URL")
+ false
+ }
+ }
+
+ private companion object {
+ private const val TRANSACTION_ID_PARAM = "transactionId"
+ private const val CURRENCY_CODE_PARAM = "baseCurrencyCode"
+ private const val CURRENCY_AMOUNT_PARAM = "baseCurrencyAmount"
+ private const val DEPOSIT_WALLET_ADDRESS_PARAM = "depositWalletAddress"
+ }
+}
\ No newline at end of file
diff --git a/app/src/main/java/com/tangem/tap/features/intentHandler/handlers/WalletConnectLinkIntentHandler.kt b/app/src/main/java/com/tangem/tap/features/intentHandler/handlers/WalletConnectLinkIntentHandler.kt
new file mode 100644
index 0000000000..e61d0b74d7
--- /dev/null
+++ b/app/src/main/java/com/tangem/tap/features/intentHandler/handlers/WalletConnectLinkIntentHandler.kt
@@ -0,0 +1,37 @@
+package com.tangem.tap.features.intentHandler.handlers
+
+import android.content.Intent
+import com.tangem.tap.common.extensions.removePrefixOrNull
+import com.tangem.tap.domain.walletconnect.WalletConnectManager
+import com.tangem.tap.features.details.redux.walletconnect.WalletConnectAction
+import com.tangem.tap.features.intentHandler.IntentHandler
+import com.tangem.tap.store
+
+/**
+[REDACTED_AUTHOR]
+ */
+class WalletConnectLinkIntentHandler : IntentHandler {
+
+ override suspend fun handleIntent(intent: Intent?): Boolean {
+ val intentData = intent?.data ?: return false
+ val scheme = intent.scheme ?: return false
+
+ val wcUri = when (scheme) {
+ WalletConnectManager.WC_SCHEME -> intentData.toString()
+ TANGEM_SCHEME -> intentData.toString().removePrefixOrNull(TANGEM_WC_PREFIX)
+ else -> null
+ }
+
+ return if (wcUri == null) {
+ false
+ } else {
+ store.dispatch(WalletConnectAction.HandleDeepLink(wcUri))
+ true
+ }
+ }
+
+ private companion object {
+ private const val TANGEM_SCHEME = "tangem"
+ private const val TANGEM_WC_PREFIX = "tangem://wc?uri="
+ }
+}
\ No newline at end of file
diff --git a/app/src/main/java/com/tangem/tap/features/send/redux/SendScreenAction.kt b/app/src/main/java/com/tangem/tap/features/send/redux/SendScreenAction.kt
index 20c206b37d..5f92c3c10b 100644
--- a/app/src/main/java/com/tangem/tap/features/send/redux/SendScreenAction.kt
+++ b/app/src/main/java/com/tangem/tap/features/send/redux/SendScreenAction.kt
@@ -6,7 +6,6 @@ import com.tangem.blockchain.common.Blockchain
import com.tangem.blockchain.common.WalletManager
import com.tangem.common.core.TangemSdkError
import com.tangem.tap.common.analytics.events.Token.Send.AddressEntered
-import com.tangem.tap.common.redux.ErrorAction
import com.tangem.tap.common.redux.StateDialog
import com.tangem.tap.common.redux.ToastNotificationAction
import com.tangem.tap.domain.TapError
@@ -34,15 +33,14 @@ data class PrepareSendScreen(
val tokenRate: BigDecimal? = null,
) : SendScreenAction
-// Address or PayId
-sealed class AddressPayIdActionUi : SendScreenActionUi {
- data class HandleUserInput(val data: String) : AddressPayIdActionUi()
- data class PasteAddressPayId(val data: String, val sourceType: AddressEntered.SourceType) : AddressPayIdActionUi()
- data class CheckClipboard(val data: String?) : AddressPayIdActionUi()
- data class CheckAddressPayId(val sourceType: AddressEntered.SourceType?) : AddressPayIdActionUi()
- data class SetTruncateHandler(val handler: (String) -> String) : AddressPayIdActionUi()
- data class TruncateOrRestore(val truncate: Boolean) : AddressPayIdActionUi()
- data class ChangePayIdState(val sendingToPayIdEnabled: Boolean) : AddressPayIdActionUi()
+// Address
+sealed class AddressActionUi : SendScreenActionUi {
+ data class HandleUserInput(val data: String) : AddressActionUi()
+ data class PasteAddress(val data: String, val sourceType: AddressEntered.SourceType) : AddressActionUi()
+ data class CheckClipboard(val data: String?) : AddressActionUi()
+ data class CheckAddress(val sourceType: AddressEntered.SourceType?) : AddressActionUi()
+ data class SetTruncateHandler(val handler: (String) -> String) : AddressActionUi()
+ data class TruncateOrRestore(val truncate: Boolean) : AddressActionUi()
}
sealed class TransactionExtrasAction : SendScreenActionUi {
@@ -76,27 +74,15 @@ sealed class TransactionExtrasAction : SendScreenActionUi {
}
}
-sealed class AddressPayIdVerifyAction : SendScreenAction {
+sealed class AddressVerifyAction : SendScreenAction {
enum class Error {
- PAY_ID_UNSUPPORTED_BY_BLOCKCHAIN,
- PAY_ID_NOT_REGISTERED,
- PAY_ID_REQUEST_FAILED,
ADDRESS_INVALID_OR_UNSUPPORTED_BY_BLOCKCHAIN,
ADDRESS_SAME_AS_WALLET,
}
- data class ChangePasteBtnEnableState(val isEnabled: Boolean) : AddressPayIdVerifyAction()
+ data class ChangePasteBtnEnableState(val isEnabled: Boolean) : AddressVerifyAction()
- sealed class PayIdVerification : AddressPayIdVerifyAction() {
- data class SetPayIdError(val error: Error?) : PayIdVerification()
- data class SetPayIdWalletAddress(
- val payId: String,
- val payIdWalletAddress: String,
- val isUserInput: Boolean,
- ) : PayIdVerification()
- }
-
- sealed class AddressVerification : AddressPayIdVerifyAction() {
+ sealed class AddressVerification : AddressVerifyAction() {
data class SetAddressError(val error: Error?) : AddressVerification()
data class SetWalletAddress(val address: String, val isUserInput: Boolean) : AddressVerification()
}
@@ -155,8 +141,6 @@ sealed class SendAction : SendScreenAction {
override val messageResource: Int = R.string.send_transaction_success
}
- data class SendError(override val error: TapError) : SendAction(), ErrorAction
-
sealed class Dialog : SendAction(), StateDialog {
data class TezosWarningDialog(
val reduceCallback: () -> Unit,
diff --git a/app/src/main/java/com/tangem/tap/features/send/redux/middlewares/AddressPayIdMiddleware.kt b/app/src/main/java/com/tangem/tap/features/send/redux/middlewares/AddressMiddleware.kt
similarity index 50%
rename from app/src/main/java/com/tangem/tap/features/send/redux/middlewares/AddressPayIdMiddleware.kt
rename to app/src/main/java/com/tangem/tap/features/send/redux/middlewares/AddressMiddleware.kt
index 406eacd087..576497222e 100644
--- a/app/src/main/java/com/tangem/tap/features/send/redux/middlewares/AddressPayIdMiddleware.kt
+++ b/app/src/main/java/com/tangem/tap/features/send/redux/middlewares/AddressMiddleware.kt
@@ -2,49 +2,39 @@ package com.tangem.tap.features.send.redux.middlewares
import com.tangem.blockchain.common.Blockchain
import com.tangem.blockchain.common.Wallet
-import com.tangem.common.services.Result
import com.tangem.core.analytics.Analytics
import com.tangem.tap.common.analytics.events.Token.Send.AddressEntered
import com.tangem.tap.common.redux.AppState
-import com.tangem.tap.domain.PayIdManager
-import com.tangem.tap.domain.isPayIdSupported
import com.tangem.tap.features.send.redux.*
-import com.tangem.tap.features.send.redux.AddressPayIdVerifyAction.AddressVerification.SetAddressError
-import com.tangem.tap.features.send.redux.AddressPayIdVerifyAction.AddressVerification.SetWalletAddress
-import com.tangem.tap.features.send.redux.AddressPayIdVerifyAction.Error
-import com.tangem.tap.features.send.redux.AddressPayIdVerifyAction.PayIdVerification.SetPayIdError
-import com.tangem.tap.features.send.redux.AddressPayIdVerifyAction.PayIdVerification.SetPayIdWalletAddress
-import com.tangem.tap.scope
-import com.tangem.tap.store
-import kotlinx.coroutines.Dispatchers
-import kotlinx.coroutines.launch
-import kotlinx.coroutines.withContext
+import com.tangem.tap.features.send.redux.AddressVerifyAction.AddressVerification.SetAddressError
+import com.tangem.tap.features.send.redux.AddressVerifyAction.AddressVerification.SetWalletAddress
+import com.tangem.tap.features.send.redux.AddressVerifyAction.Error
import org.rekotlin.Action
import org.rekotlin.DispatchFunction
/**
[REDACTED_AUTHOR]
*/
-internal class AddressPayIdMiddleware {
+internal class AddressMiddleware {
- fun handle(action: AddressPayIdActionUi, appState: AppState?, dispatch: (Action) -> Unit) {
+ fun handle(action: AddressActionUi, appState: AppState?, dispatch: (Action) -> Unit) {
when (action) {
- is AddressPayIdActionUi.HandleUserInput -> handleUserInput(action.data, appState, dispatch)
- is AddressPayIdActionUi.PasteAddressPayId -> pasteAddressPayId(action.data, action.sourceType, dispatch)
- is AddressPayIdActionUi.CheckClipboard -> verifyClipboard(action.data, appState, dispatch)
- is AddressPayIdActionUi.CheckAddressPayId -> verifyAddressPayId(action.sourceType, appState, dispatch)
+ is AddressActionUi.HandleUserInput -> handleUserInput(action.data, appState, dispatch)
+ is AddressActionUi.PasteAddress -> pasteAddress(action.data, action.sourceType, dispatch)
+ is AddressActionUi.CheckClipboard -> verifyClipboard(action.data, appState, dispatch)
+ is AddressActionUi.CheckAddress -> verifyAddress(action.sourceType, appState, dispatch)
else -> return
}
}
private fun handleUserInput(input: String, appState: AppState?, dispatch: DispatchFunction) {
val sendState = appState?.sendState ?: return
- if (input == sendState.addressPayIdState.viewFieldValue.value) return
+ if (input == sendState.addressState.viewFieldValue.value) return
setAddressAndCheck(data = input, sourceType = null, isUserInput = true, dispatch = dispatch)
}
- private fun pasteAddressPayId(data: String, sourceType: AddressEntered.SourceType, dispatch: (Action) -> Unit) {
+ private fun pasteAddress(data: String, sourceType: AddressEntered.SourceType, dispatch: (Action) -> Unit) {
setAddressAndCheck(data = data, sourceType = sourceType, isUserInput = false, dispatch = dispatch)
}
@@ -54,74 +44,27 @@ internal class AddressPayIdMiddleware {
isUserInput: Boolean,
dispatch: (Action) -> Unit,
) {
- val potentialPayId = data.lowercase()
- if (isPayIdEnabled() && PayIdManager.isPayId(potentialPayId)) {
- dispatch(SetPayIdWalletAddress(potentialPayId, "", isUserInput))
- } else {
- dispatch(SetWalletAddress(data, isUserInput))
- }
- dispatch(AddressPayIdActionUi.CheckAddressPayId(sourceType))
+ dispatch(SetWalletAddress(data, isUserInput))
+ dispatch(AddressActionUi.CheckAddress(sourceType))
}
- private fun verifyAddressPayId(
+ private fun verifyAddress(
sourceType: AddressEntered.SourceType?,
appState: AppState?,
dispatch: (Action) -> Unit,
) {
val sendState = appState?.sendState ?: return
val wallet = sendState.walletManager?.wallet ?: return
- val addressPayId = sendState.addressPayIdState.normalFieldValue ?: return
- val isUserInput = sendState.addressPayIdState.viewFieldValue.isFromUserInput
+ val address = sendState.addressState.normalFieldValue ?: return
+ val isUserInput = sendState.addressState.viewFieldValue.isFromUserInput
- if (isPayIdEnabled() && PayIdManager.isPayId(addressPayId)) {
- verifyPayId(addressPayId, wallet, isUserInput, dispatch)
- } else {
- verifyAddress(
- address = addressPayId,
- wallet = wallet,
- isUserInput = isUserInput,
- dispatch = dispatch,
- sourceType = sourceType,
- )
- }
- }
-
- private fun verifyPayId(payId: String, wallet: Wallet, isUserInput: Boolean, dispatch: DispatchFunction) {
- val blockchain = wallet.blockchain
- if (!blockchain.isPayIdSupported()) {
- dispatch(SetPayIdError(Error.PAY_ID_UNSUPPORTED_BY_BLOCKCHAIN))
- return
- }
-
- scope.launch {
- val result = PayIdManager().verifyPayId(payId, blockchain)
- withContext(Dispatchers.Main) {
- when (result) {
- is Result.Success -> {
- val addressDetails = result.data.getAddressDetails()
- if (addressDetails == null) {
- dispatch(SetPayIdError(Error.PAY_ID_NOT_REGISTERED))
- return@withContext
- }
-
- val address = addressDetails.address
- val failReason = isValidBlockchainAddressAndNotTheSameAsWallet(wallet, address)
- if (failReason == null) {
- dispatch(SetPayIdWalletAddress(payId, address, isUserInput))
- dispatch(TransactionExtrasAction.Prepare(wallet.blockchain, address, addressDetails.tag))
- dispatch(FeeAction.RequestFee)
- } else {
- dispatch(SetAddressError(failReason))
- dispatch(TransactionExtrasAction.Release)
- }
- }
- is Result.Failure -> {
- dispatch(SetPayIdError(Error.PAY_ID_REQUEST_FAILED))
- dispatch(TransactionExtrasAction.Release)
- }
- }
- }
- }
+ verifyAddress(
+ address = address,
+ wallet = wallet,
+ isUserInput = isUserInput,
+ dispatch = dispatch,
+ sourceType = sourceType,
+ )
}
private fun verifyAddress(
@@ -219,41 +162,33 @@ internal class AddressPayIdMiddleware {
}
private fun verifyClipboard(input: String?, appState: AppState?, dispatch: DispatchFunction) {
- val addressPayId = input ?: return
+ val address = input ?: return
val wallet = appState?.sendState?.walletManager?.wallet ?: return
val internalDispatcher: (Action) -> Unit = {
when (it) {
- is SetWalletAddress, is SetPayIdWalletAddress -> {
- dispatch(AddressPayIdVerifyAction.ChangePasteBtnEnableState(true))
+ is SetWalletAddress -> {
+ dispatch(AddressVerifyAction.ChangePasteBtnEnableState(true))
}
- is SetAddressError, is SetPayIdError -> {
- dispatch(AddressPayIdVerifyAction.ChangePasteBtnEnableState(false))
+ is SetAddressError -> {
+ dispatch(AddressVerifyAction.ChangePasteBtnEnableState(false))
}
}
}
- if (PayIdManager.isPayId(addressPayId) && isPayIdEnabled()) {
- verifyPayId(addressPayId, wallet, false, internalDispatcher)
- } else {
- verifyAddress(
- address = addressPayId,
- wallet = wallet,
- sourceType = null,
- isUserInput = false,
- dispatch = internalDispatcher,
- )
- }
- }
-
- private fun isPayIdEnabled(): Boolean {
- return store.state.globalState.configManager?.config?.isSendingToPayIdEnabled ?: false
+ verifyAddress(
+ address = address,
+ wallet = wallet,
+ sourceType = null,
+ isUserInput = false,
+ dispatch = internalDispatcher,
+ )
}
}
fun String.splitToMap(firstDelimiter: String, secondDelimiter: String): Map {
- return this.split(firstDelimiter)
+ return this
+ .split(firstDelimiter)
.map { it.split(secondDelimiter) }
- .map { it.first() to it.last().toString() }
- .toMap()
+ .associate { it.first() to it.last() }
}
\ No newline at end of file
diff --git a/app/src/main/java/com/tangem/tap/features/send/redux/middlewares/RequestFeeMiddleware.kt b/app/src/main/java/com/tangem/tap/features/send/redux/middlewares/RequestFeeMiddleware.kt
index 8a0b096c4c..3cbd54e044 100644
--- a/app/src/main/java/com/tangem/tap/features/send/redux/middlewares/RequestFeeMiddleware.kt
+++ b/app/src/main/java/com/tangem/tap/features/send/redux/middlewares/RequestFeeMiddleware.kt
@@ -38,7 +38,7 @@ class RequestFeeMiddleware {
}
val typedAmount = sendState.amountState.amountToExtract ?: return
- val destinationAddress = sendState.addressPayIdState.destinationWalletAddress!!
+ val destinationAddress = sendState.addressState.destinationWalletAddress!!
val destinationAmount = Amount(typedAmount, sendState.amountState.amountToSendCrypto)
val txSender = if (scanResponse.isDemoCard()) {
DemoTransactionSender(walletManager)
diff --git a/app/src/main/java/com/tangem/tap/features/send/redux/middlewares/SendMiddleware.kt b/app/src/main/java/com/tangem/tap/features/send/redux/middlewares/SendMiddleware.kt
index d54adda3d5..5f8d039210 100644
--- a/app/src/main/java/com/tangem/tap/features/send/redux/middlewares/SendMiddleware.kt
+++ b/app/src/main/java/com/tangem/tap/features/send/redux/middlewares/SendMiddleware.kt
@@ -55,18 +55,17 @@ class SendMiddleware {
{ nextDispatch ->
{ action ->
when (action) {
- is AddressPayIdActionUi -> AddressPayIdMiddleware().handle(action, appState(), dispatch)
+ is AddressActionUi -> AddressMiddleware().handle(action, appState(), dispatch)
is AmountActionUi -> AmountMiddleware().handle(action, appState(), dispatch)
is RequestFee -> RequestFeeMiddleware().handle(appState(), dispatch)
is SendActionUi.SendAmountToRecipient ->
verifyAndSendTransaction(action, appState(), dispatch)
- is PrepareSendScreen -> setIfSendingToPayIdEnabled(appState(), dispatch)
is SendAction.Warnings.Update -> updateWarnings(dispatch)
is SendActionUi.CheckIfTransactionDataWasProvided -> {
val transactionData = appState()?.sendState?.externalTransactionData
if (transactionData != null) {
store.dispatchOnMain(
- AddressPayIdVerifyAction.AddressVerification.SetWalletAddress(
+ AddressVerifyAction.AddressVerification.SetWalletAddress(
address = transactionData.destinationAddress,
isUserInput = false,
),
@@ -96,7 +95,7 @@ private fun verifyAndSendTransaction(
val sendState = appState?.sendState ?: return
val walletManager = sendState.walletManager ?: return
val card = appState.globalState.scanResponse?.card ?: return
- val destinationAddress = sendState.addressPayIdState.destinationWalletAddress ?: return
+ val destinationAddress = sendState.addressState.destinationWalletAddress ?: return
val typedAmount = sendState.amountState.amountToExtract ?: return
val feeAmount = sendState.feeState.currentFee ?: return
@@ -391,12 +390,6 @@ fun createValidateTransactionError(
return TapError.ValidateTransactionErrors(tapErrors) { it.joinToString("\r\n") }
}
-private fun setIfSendingToPayIdEnabled(appState: AppState?, dispatch: (Action) -> Unit) {
- val isSendingToPayIdEnabled =
- appState?.globalState?.configManager?.config?.isSendingToPayIdEnabled ?: false
- dispatch(AddressPayIdActionUi.ChangePayIdState(isSendingToPayIdEnabled))
-}
-
private fun updateWarnings(dispatch: (Action) -> Unit) {
val warningsManager = store.state.globalState.warningManager ?: return
val blockchain = store.state.sendState.walletManager?.wallet?.blockchain ?: return
diff --git a/app/src/main/java/com/tangem/tap/features/send/redux/reducers/AddressPayIdReducer.kt b/app/src/main/java/com/tangem/tap/features/send/redux/reducers/AddressPayIdReducer.kt
deleted file mode 100644
index ddacac0df8..0000000000
--- a/app/src/main/java/com/tangem/tap/features/send/redux/reducers/AddressPayIdReducer.kt
+++ /dev/null
@@ -1,72 +0,0 @@
-package com.tangem.tap.features.send.redux.reducers
-
-import com.tangem.tap.features.send.redux.AddressPayIdActionUi
-import com.tangem.tap.features.send.redux.AddressPayIdVerifyAction
-import com.tangem.tap.features.send.redux.AddressPayIdVerifyAction.AddressVerification
-import com.tangem.tap.features.send.redux.AddressPayIdVerifyAction.PayIdVerification
-import com.tangem.tap.features.send.redux.SendScreenAction
-import com.tangem.tap.features.send.redux.states.AddressPayIdState
-import com.tangem.tap.features.send.redux.states.InputViewValue
-import com.tangem.tap.features.send.redux.states.SendState
-
-/**
-[REDACTED_AUTHOR]
- */
-class AddressPayIdReducer : SendInternalReducer {
- override fun handle(action: SendScreenAction, sendState: SendState): SendState = when (action) {
- is AddressPayIdActionUi -> handleUiAction(action, sendState, sendState.addressPayIdState)
- is AddressPayIdVerifyAction -> handleAction(action, sendState, sendState.addressPayIdState)
- else -> sendState
- }
-
- private fun handleUiAction(
- action: AddressPayIdActionUi,
- sendState: SendState,
- state: AddressPayIdState,
- ): SendState {
- val result = when (action) {
- is AddressPayIdActionUi.HandleUserInput -> state
- is AddressPayIdActionUi.SetTruncateHandler -> state.copy(truncateHandler = action.handler)
- is AddressPayIdActionUi.TruncateOrRestore -> {
- val value = if (action.truncate) state.truncatedFieldValue ?: "" else state.normalFieldValue ?: ""
- state.copy(viewFieldValue = state.viewFieldValue.copy(value = value))
- }
- is AddressPayIdActionUi.PasteAddressPayId -> return sendState
- is AddressPayIdActionUi.CheckClipboard -> return sendState
- is AddressPayIdActionUi.CheckAddressPayId -> return sendState
- is AddressPayIdActionUi.ChangePayIdState -> state.copy(sendingToPayIdEnabled = action.sendingToPayIdEnabled)
- }
- return updateLastState(sendState.copy(addressPayIdState = result), result)
- }
-
- private fun handleAction(
- action: AddressPayIdVerifyAction,
- sendState: SendState,
- state: AddressPayIdState,
- ): SendState {
- val result = when (action) {
- is PayIdVerification.SetPayIdWalletAddress -> {
- state.copy(
- viewFieldValue = InputViewValue(action.payId, action.isUserInput),
- normalFieldValue = action.payId,
- truncatedFieldValue = state.truncate(action.payId),
- destinationWalletAddress = action.payIdWalletAddress,
- error = null,
- )
- }
- is AddressVerification.SetWalletAddress -> {
- state.copy(
- viewFieldValue = InputViewValue(action.address, action.isUserInput),
- normalFieldValue = action.address,
- truncatedFieldValue = state.truncate(action.address),
- destinationWalletAddress = action.address,
- error = null,
- )
- }
- is AddressPayIdVerifyAction.ChangePasteBtnEnableState -> state.copy(pasteIsEnabled = action.isEnabled)
- is AddressVerification.SetAddressError -> state.copy(error = action.error, destinationWalletAddress = null)
- is PayIdVerification.SetPayIdError -> state.copy(error = action.error, destinationWalletAddress = null)
- }
- return updateLastState(sendState.copy(addressPayIdState = result), result)
- }
-}
\ No newline at end of file
diff --git a/app/src/main/java/com/tangem/tap/features/send/redux/reducers/AddressReducer.kt b/app/src/main/java/com/tangem/tap/features/send/redux/reducers/AddressReducer.kt
new file mode 100644
index 0000000000..a5b44bff0f
--- /dev/null
+++ b/app/src/main/java/com/tangem/tap/features/send/redux/reducers/AddressReducer.kt
@@ -0,0 +1,52 @@
+package com.tangem.tap.features.send.redux.reducers
+
+import com.tangem.tap.features.send.redux.AddressActionUi
+import com.tangem.tap.features.send.redux.AddressVerifyAction
+import com.tangem.tap.features.send.redux.AddressVerifyAction.AddressVerification
+import com.tangem.tap.features.send.redux.SendScreenAction
+import com.tangem.tap.features.send.redux.states.AddressState
+import com.tangem.tap.features.send.redux.states.InputViewValue
+import com.tangem.tap.features.send.redux.states.SendState
+
+/**
+[REDACTED_AUTHOR]
+ */
+class AddressReducer : SendInternalReducer {
+ override fun handle(action: SendScreenAction, sendState: SendState): SendState = when (action) {
+ is AddressActionUi -> handleUiAction(action, sendState, sendState.addressState)
+ is AddressVerifyAction -> handleAction(action, sendState, sendState.addressState)
+ else -> sendState
+ }
+
+ private fun handleUiAction(action: AddressActionUi, sendState: SendState, state: AddressState): SendState {
+ val result = when (action) {
+ is AddressActionUi.HandleUserInput -> state
+ is AddressActionUi.SetTruncateHandler -> state.copy(truncateHandler = action.handler)
+ is AddressActionUi.TruncateOrRestore -> {
+ val value = if (action.truncate) state.truncatedFieldValue ?: "" else state.normalFieldValue ?: ""
+ state.copy(viewFieldValue = state.viewFieldValue.copy(value = value))
+ }
+ is AddressActionUi.PasteAddress -> return sendState
+ is AddressActionUi.CheckClipboard -> return sendState
+ is AddressActionUi.CheckAddress -> return sendState
+ }
+ return updateLastState(sendState.copy(addressState = result), result)
+ }
+
+ private fun handleAction(action: AddressVerifyAction, sendState: SendState, state: AddressState): SendState {
+ val result = when (action) {
+ is AddressVerification.SetWalletAddress -> {
+ state.copy(
+ viewFieldValue = InputViewValue(action.address, action.isUserInput),
+ normalFieldValue = action.address,
+ truncatedFieldValue = state.truncate(action.address),
+ destinationWalletAddress = action.address,
+ error = null,
+ )
+ }
+ is AddressVerifyAction.ChangePasteBtnEnableState -> state.copy(pasteIsEnabled = action.isEnabled)
+ is AddressVerification.SetAddressError -> state.copy(error = action.error, destinationWalletAddress = null)
+ }
+ return updateLastState(sendState.copy(addressState = result), result)
+ }
+}
\ No newline at end of file
diff --git a/app/src/main/java/com/tangem/tap/features/send/redux/reducers/SendScreenReducer.kt b/app/src/main/java/com/tangem/tap/features/send/redux/reducers/SendScreenReducer.kt
index 4134e8c148..463b0dcaea 100644
--- a/app/src/main/java/com/tangem/tap/features/send/redux/reducers/SendScreenReducer.kt
+++ b/app/src/main/java/com/tangem/tap/features/send/redux/reducers/SendScreenReducer.kt
@@ -25,7 +25,7 @@ object SendScreenReducer {
val reducer: SendInternalReducer = when (action) {
is PrepareSendScreen -> PrepareSendScreenStatesReducer()
- is AddressPayIdActionUi, is AddressPayIdVerifyAction -> AddressPayIdReducer()
+ is AddressActionUi, is AddressVerifyAction -> AddressReducer()
is TransactionExtrasAction -> TransactionExtrasReducer()
is AmountActionUi, is AmountAction -> AmountReducer()
is FeeActionUi, is FeeAction -> FeeReducer()
@@ -71,7 +71,7 @@ private class SendReducer : SendInternalReducer {
amountState = state.amountState.copy(
inputIsEnabled = false,
),
- addressPayIdState = state.addressPayIdState.copy(
+ addressState = state.addressState.copy(
inputIsEnabled = false,
),
)
diff --git a/app/src/main/java/com/tangem/tap/features/send/redux/states/AddressPayIdState.kt b/app/src/main/java/com/tangem/tap/features/send/redux/states/AddressState.kt
similarity index 90%
rename from app/src/main/java/com/tangem/tap/features/send/redux/states/AddressPayIdState.kt
rename to app/src/main/java/com/tangem/tap/features/send/redux/states/AddressState.kt
index 9f0851e06d..b6b65a595f 100644
--- a/app/src/main/java/com/tangem/tap/features/send/redux/states/AddressPayIdState.kt
+++ b/app/src/main/java/com/tangem/tap/features/send/redux/states/AddressState.kt
@@ -2,17 +2,16 @@ package com.tangem.tap.features.send.redux.states
import androidx.core.text.isDigitsOnly
import com.tangem.blockchain.blockchains.stellar.StellarMemo
-import com.tangem.tap.features.send.redux.AddressPayIdVerifyAction
+import com.tangem.tap.features.send.redux.AddressVerifyAction
import java.math.BigInteger
-data class AddressPayIdState(
+data class AddressState(
val viewFieldValue: InputViewValue = InputViewValue(""),
val normalFieldValue: String? = null,
val truncatedFieldValue: String? = null,
val destinationWalletAddress: String? = null,
- val error: AddressPayIdVerifyAction.Error? = null,
+ val error: AddressVerifyAction.Error? = null,
val truncateHandler: ((String) -> String)? = null,
- val sendingToPayIdEnabled: Boolean = false,
val pasteIsEnabled: Boolean = false,
val inputIsEnabled: Boolean = true,
) : SendScreenState {
@@ -22,8 +21,6 @@ data class AddressPayIdState(
fun truncate(value: String): String = truncateHandler?.invoke(value) ?: value
fun isReady(): Boolean = error == null && destinationWalletAddress?.isNotEmpty() ?: false
-
- fun isPayIdState(): Boolean = destinationWalletAddress != null && destinationWalletAddress != normalFieldValue
}
data class TransactionExtrasState(
@@ -98,11 +95,7 @@ data class BinanceMemoState(
val viewFieldValue: InputViewValue = InputViewValue(""),
val memo: BigInteger? = null,
val error: TransactionExtraError? = null,
-) {
- companion object {
- val MAX_NUMBER: BigInteger = BigInteger("FFFFFFFFFFFFFFFF", 16)
- }
-}
+)
// tag must contains only digits
data class XrpDestinationTagState(
diff --git a/app/src/main/java/com/tangem/tap/features/send/redux/states/SendState.kt b/app/src/main/java/com/tangem/tap/features/send/redux/states/SendState.kt
index 6a47e2d342..8400f07c87 100644
--- a/app/src/main/java/com/tangem/tap/features/send/redux/states/SendState.kt
+++ b/app/src/main/java/com/tangem/tap/features/send/redux/states/SendState.kt
@@ -34,7 +34,7 @@ data class SendState(
val coinConverter: CurrencyConverter? = null,
val tokenConverter: CurrencyConverter? = null,
val lastChangedStates: LinkedHashSet = linkedSetOf(),
- val addressPayIdState: AddressPayIdState = AddressPayIdState(),
+ val addressState: AddressState = AddressState(),
val transactionExtrasState: TransactionExtrasState = TransactionExtrasState(),
val amountState: AmountState = AmountState(),
val feeState: FeeState = FeeState(),
@@ -52,7 +52,7 @@ data class SendState(
MainCurrencyType.CRYPTO -> amountState.amountToExtract?.decimals ?: 0
}
- fun convertFiatToCoin(value: BigDecimal): BigDecimal {
+ private fun convertFiatToCoin(value: BigDecimal): BigDecimal {
return if (!this.coinIsConvertible()) value else coinConverter!!.toCrypto(value)
}
@@ -60,14 +60,14 @@ data class SendState(
return if (!this.tokenIsConvertible()) value else tokenConverter!!.toCrypto(value)
}
- fun convertCoinToFiat(value: BigDecimal, scaleWithPrecision: Boolean = false): BigDecimal {
+ private fun convertCoinToFiat(value: BigDecimal, scaleWithPrecision: Boolean = false): BigDecimal {
if (!this.coinIsConvertible()) return value
val converter = coinConverter!!
return if (!scaleWithPrecision) converter.toFiat(value) else converter.toFiatWithPrecision(value)
}
- fun convertTokenToFiat(value: BigDecimal, scaleWithPrecision: Boolean = false): BigDecimal {
+ private fun convertTokenToFiat(value: BigDecimal, scaleWithPrecision: Boolean = false): BigDecimal {
if (!this.tokenIsConvertible()) return value
val converter = tokenConverter!!
@@ -107,13 +107,13 @@ data class SendState(
}
companion object {
- fun addressPayIdIsReady(): Boolean = store.state.sendState.addressPayIdState.isReady()
+ private fun addressIsReady(): Boolean = store.state.sendState.addressState.isReady()
- fun amountIsReady(): Boolean = store.state.sendState.amountState.isReady()
+ private fun amountIsReady(): Boolean = store.state.sendState.amountState.isReady()
- fun isReadyToRequestFee(): Boolean = addressPayIdIsReady() && amountIsReady()
+ fun isReadyToRequestFee(): Boolean = addressIsReady() && amountIsReady()
- fun isReadyToSend(): Boolean = addressPayIdIsReady() && amountIsReady() &&
+ fun isReadyToSend(): Boolean = addressIsReady() && amountIsReady() &&
store.state.sendState.feeState.isReady()
}
}
diff --git a/app/src/main/java/com/tangem/tap/features/send/ui/SendFragment.kt b/app/src/main/java/com/tangem/tap/features/send/ui/SendFragment.kt
index 64c4fc53a7..fec34d9996 100644
--- a/app/src/main/java/com/tangem/tap/features/send/ui/SendFragment.kt
+++ b/app/src/main/java/com/tangem/tap/features/send/ui/SendFragment.kt
@@ -33,7 +33,7 @@ import com.tangem.tap.common.toggleWidget.ViewStateWidget
import com.tangem.tap.features.BaseStoreFragment
import com.tangem.tap.features.addBackPressHandler
import com.tangem.tap.features.send.redux.*
-import com.tangem.tap.features.send.redux.AddressPayIdActionUi.*
+import com.tangem.tap.features.send.redux.AddressActionUi.*
import com.tangem.tap.features.send.redux.AmountActionUi.*
import com.tangem.tap.features.send.redux.FeeActionUi.*
import com.tangem.tap.features.send.redux.states.FeeType
@@ -80,7 +80,7 @@ class SendFragment : BaseStoreFragment(R.layout.fragment_send) {
etAmountToSend = view.findViewById(R.id.etAmountToSend)
initSendButtonStates()
- setupAddressOrPayIdLayout()
+ setupAddressLayout()
setupTransactionExtrasLayout()
setupAmountLayout()
setupFeeLayout()
@@ -99,14 +99,14 @@ class SendFragment : BaseStoreFragment(R.layout.fragment_send) {
sendBtn = IndeterminateProgressButtonWidget(btnSend, progress)
}
- private fun setupAddressOrPayIdLayout() = with(binding.lSendAddressPayid) {
- store.dispatch(SetTruncateHandler { etAddressOrPayId.truncateMiddleWith(it, "...") })
+ private fun setupAddressLayout() = with(binding.lSendAddress) {
+ store.dispatch(SetTruncateHandler { etAddress.truncateMiddleWith(it, "...") })
store.dispatch(CheckClipboard(requireContext().getFromClipboard()?.toString()))
- etAddressOrPayId.apply {
+ etAddress.apply {
setOnSystemPasteButtonClickListener {
store.dispatch(
- PasteAddressPayId(
+ PasteAddress(
data = requireContext().getFromClipboard()?.toString() ?: "",
sourceType = Token.Send.AddressEntered.SourceType.PastePopup,
),
@@ -119,9 +119,9 @@ class SendFragment : BaseStoreFragment(R.layout.fragment_send) {
inputtedTextAsFlow()
.debounce(EDIT_TEXT_INPUT_DEBOUNCE)
- .filter { store.state.sendState.addressPayIdState.viewFieldValue.value != it }
+ .filter { store.state.sendState.addressState.viewFieldValue.value != it }
.onEach {
- store.dispatch(AddressPayIdActionUi.HandleUserInput(it))
+ store.dispatch(AddressActionUi.HandleUserInput(it))
}
.launchIn(mainScope)
}
@@ -129,12 +129,12 @@ class SendFragment : BaseStoreFragment(R.layout.fragment_send) {
imvPaste.setOnClickListener {
Analytics.send(Token.Send.ButtonPaste())
store.dispatch(
- PasteAddressPayId(
+ PasteAddress(
data = requireContext().getFromClipboard()?.toString() ?: "",
sourceType = Token.Send.AddressEntered.SourceType.PasteButton,
),
)
- store.dispatch(TruncateOrRestore(!etAddressOrPayId.isFocused))
+ store.dispatch(TruncateOrRestore(!etAddress.isFocused))
}
imvQrCode.setOnClickListener {
Analytics.send(Token.Send.ButtonQRCode())
@@ -145,7 +145,7 @@ class SendFragment : BaseStoreFragment(R.layout.fragment_send) {
}
}
- private fun setupTransactionExtrasLayout() = with(binding.lSendAddressPayid) {
+ private fun setupTransactionExtrasLayout() = with(binding.lSendAddress) {
// TODO: [REDACTED_TASK_KEY]
etXlmMemo.inputtedTextAsFlow()
.debounce(EDIT_TEXT_INPUT_DEBOUNCE)
@@ -202,15 +202,15 @@ class SendFragment : BaseStoreFragment(R.layout.fragment_send) {
// Delayed launch is needed in order for the UI to be drawn and to process the sent events.
// If do not use the delay, then etAmount error field is not displayed when
// inserting an incorrect amount by shareUri
- binding.lSendAddressPayid.imvQrCode.postDelayed(
+ binding.lSendAddress.imvQrCode.postDelayed(
{
store.dispatch(
- PasteAddressPayId(
+ PasteAddress(
data = scannedCode,
sourceType = Token.Send.AddressEntered.SourceType.QRCode,
),
)
- store.dispatch(TruncateOrRestore(!binding.lSendAddressPayid.etAddressOrPayId.isFocused))
+ store.dispatch(TruncateOrRestore(!binding.lSendAddress.etAddress.isFocused))
},
200,
)
diff --git a/app/src/main/java/com/tangem/tap/features/send/ui/stateSubscribers/SendStateSubscriber.kt b/app/src/main/java/com/tangem/tap/features/send/ui/stateSubscribers/SendStateSubscriber.kt
index 12f16a0274..7c12e82496 100644
--- a/app/src/main/java/com/tangem/tap/features/send/ui/stateSubscribers/SendStateSubscriber.kt
+++ b/app/src/main/java/com/tangem/tap/features/send/ui/stateSubscribers/SendStateSubscriber.kt
@@ -7,30 +7,15 @@ import android.view.View
import android.view.ViewGroup
import androidx.core.text.bold
import com.tangem.common.extensions.remove
-import com.tangem.tap.common.extensions.beginDelayedTransition
-import com.tangem.tap.common.extensions.enableError
-import com.tangem.tap.common.extensions.getColor
-import com.tangem.tap.common.extensions.getString
-import com.tangem.tap.common.extensions.hide
-import com.tangem.tap.common.extensions.show
-import com.tangem.tap.common.extensions.update
+import com.tangem.tap.common.extensions.*
import com.tangem.tap.common.redux.getMessageString
import com.tangem.tap.common.text.DecimalDigitsInputFilter
import com.tangem.tap.domain.MultiMessageError
import com.tangem.tap.domain.assembleErrors
import com.tangem.tap.features.BaseStoreFragment
-import com.tangem.tap.features.send.redux.AddressPayIdVerifyAction.Error
+import com.tangem.tap.features.send.redux.AddressVerifyAction.Error
import com.tangem.tap.features.send.redux.SendAction
-import com.tangem.tap.features.send.redux.states.AddressPayIdState
-import com.tangem.tap.features.send.redux.states.AmountState
-import com.tangem.tap.features.send.redux.states.FeeState
-import com.tangem.tap.features.send.redux.states.MainCurrencyType
-import com.tangem.tap.features.send.redux.states.ReceiptLayoutType
-import com.tangem.tap.features.send.redux.states.ReceiptState
-import com.tangem.tap.features.send.redux.states.SendState
-import com.tangem.tap.features.send.redux.states.StateId
-import com.tangem.tap.features.send.redux.states.TransactionExtraError
-import com.tangem.tap.features.send.redux.states.TransactionExtrasState
+import com.tangem.tap.features.send.redux.states.*
import com.tangem.tap.features.send.ui.FeeUiHelper
import com.tangem.tap.features.send.ui.SendFragment
import com.tangem.tap.features.send.ui.dialogs.KaspaWarningDialog
@@ -61,7 +46,7 @@ class SendStateSubscriber(fragment: BaseStoreFragment) : FragmentStateSubscriber
lastChangedStates.forEach {
when (it) {
StateId.SEND_SCREEN -> handleSendScreen(fg, state)
- StateId.ADDRESS_PAY_ID -> handleAddressPayIdState(fg, state.addressPayIdState)
+ StateId.ADDRESS_PAY_ID -> handleAddressState(fg, state.addressState)
StateId.TRANSACTION_EXTRAS -> handleTransactionExtrasState(fg, state.transactionExtrasState)
StateId.AMOUNT -> handleAmountState(fg, state.amountState)
StateId.FEE -> handleFeeState(fg, state.feeState)
@@ -72,7 +57,7 @@ class SendStateSubscriber(fragment: BaseStoreFragment) : FragmentStateSubscriber
@Suppress("ComplexMethod")
private fun handleTransactionExtrasState(fg: SendFragment, infoState: TransactionExtrasState) =
- with(fg.binding.lSendAddressPayid) {
+ with(fg.binding.lSendAddress) {
fun showView(view: View, info: Any?) {
view.show(info != null)
}
@@ -192,13 +177,10 @@ class SendStateSubscriber(fragment: BaseStoreFragment) : FragmentStateSubscriber
)
}
- private fun handleAddressPayIdState(fg: SendFragment, state: AddressPayIdState) =
- with(fg.binding.lSendAddressPayid) {
+ private fun handleAddressState(fg: SendFragment, state: AddressState) {
+ with(fg.binding.lSendAddress) {
fun parseError(context: Context, error: Error?): String? {
val resId = when (error) {
- Error.PAY_ID_UNSUPPORTED_BY_BLOCKCHAIN -> R.string.send_error_payid_unsupported_by_blockchain
- Error.PAY_ID_NOT_REGISTERED -> R.string.send_error_payid_not_registered
- Error.PAY_ID_REQUEST_FAILED -> R.string.send_error_payid_request_failed
Error.ADDRESS_INVALID_OR_UNSUPPORTED_BY_BLOCKCHAIN -> R.string.send_validation_invalid_address
Error.ADDRESS_SAME_AS_WALLET -> R.string.send_error_address_same_as_wallet
else -> null
@@ -208,8 +190,8 @@ class SendStateSubscriber(fragment: BaseStoreFragment) : FragmentStateSubscriber
imvPaste.isEnabled = state.pasteIsEnabled
- val et = etAddressOrPayId
- val til = tilAddressOrPayId
+ val et = etAddress
+ val til = tilAddress
val parsedError = parseError(til.context, state.error)
til.isEnabled = state.inputIsEnabled
@@ -218,19 +200,15 @@ class SendStateSubscriber(fragment: BaseStoreFragment) : FragmentStateSubscriber
flPaste.show(state.inputIsEnabled)
flQrCode.show(state.inputIsEnabled)
- val hintResId = if (state.sendingToPayIdEnabled) {
- R.string.send_destination_hint_address_payid
- } else {
- R.string.send_destination_hint_address
- }
- til.hint = til.getString(hintResId)
+ til.hint = til.getString(R.string.send_destination_hint_address)
til.error = parsedError
til.isErrorEnabled = parsedError != null
til.helperText = state.destinationWalletAddress
- til.isHelperTextEnabled = state.isPayIdState() && parsedError == null
+ til.isHelperTextEnabled = parsedError == null
if (!state.viewFieldValue.isFromUserInput) et.update(state.viewFieldValue.value)
}
+ }
private fun handleAmountState(fg: SendFragment, state: AmountState) = with(fg.binding.lSendAmount) {
if (state.error != null) {
diff --git a/app/src/main/java/com/tangem/tap/features/wallet/ui/WalletFragment.kt b/app/src/main/java/com/tangem/tap/features/wallet/ui/WalletFragment.kt
index 47d07b91b0..6540470882 100644
--- a/app/src/main/java/com/tangem/tap/features/wallet/ui/WalletFragment.kt
+++ b/app/src/main/java/com/tangem/tap/features/wallet/ui/WalletFragment.kt
@@ -8,7 +8,9 @@ import android.view.View
import androidx.activity.OnBackPressedCallback
import androidx.appcompat.app.AppCompatActivity
import androidx.compose.runtime.mutableStateOf
+import androidx.compose.ui.platform.ViewCompositionStrategy
import androidx.fragment.app.Fragment
+import androidx.fragment.app.activityViewModels
import androidx.fragment.app.viewModels
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.flowWithLifecycle
@@ -22,12 +24,16 @@ import coil.size.Scale
import com.badoo.mvicore.modelWatcher
import com.tangem.core.analytics.Analytics
import com.tangem.core.ui.fragments.setStatusBarColor
+import com.tangem.core.ui.res.TangemTheme
import com.tangem.core.ui.utils.OneTouchClickListener
import com.tangem.datasource.connection.NetworkConnectionManager
+import com.tangem.feature.learn2earn.presentation.Learn2earnViewModel
+import com.tangem.feature.learn2earn.presentation.ui.Learn2earnMainPageScreen
import com.tangem.feature.swap.api.SwapFeatureToggleManager
import com.tangem.feature.swap.domain.SwapInteractor
import com.tangem.tap.MainActivity
import com.tangem.tap.common.analytics.events.Portfolio
+import com.tangem.tap.common.extensions.beginDelayedTransition
import com.tangem.tap.common.extensions.show
import com.tangem.tap.common.recyclerView.SpaceItemDecoration
import com.tangem.tap.common.redux.global.GlobalAction
@@ -73,6 +79,7 @@ class WalletFragment : Fragment(R.layout.fragment_wallet), SafeStoreSubscriber()
private val viewModel by viewModels()
private val totalBalanceWatcher = modelWatcher {
@@ -102,6 +109,7 @@ class WalletFragment : Fragment(R.layout.fragment_wallet), SafeStoreSubscriber 1 && currency.blockchain != Blockchain.BitcoinCash
+ return listOfAddresses.size > 1
}
internal fun WalletDataModel.assembleWarnings(
diff --git a/app/src/main/java/com/tangem/tap/features/welcome/redux/WelcomeAction.kt b/app/src/main/java/com/tangem/tap/features/welcome/redux/WelcomeAction.kt
index a0484fc798..e7ce3e5957 100644
--- a/app/src/main/java/com/tangem/tap/features/welcome/redux/WelcomeAction.kt
+++ b/app/src/main/java/com/tangem/tap/features/welcome/redux/WelcomeAction.kt
@@ -15,7 +15,7 @@ internal sealed interface WelcomeAction : Action {
data class Error(val error: TangemError) : WelcomeAction
}
- data class HandleIntentIfNeeded(val intent: Intent?) : WelcomeAction
+ data class SetInitialIntent(val intent: Intent?) : WelcomeAction
object CloseError : WelcomeAction
diff --git a/app/src/main/java/com/tangem/tap/features/welcome/redux/WelcomeMiddleware.kt b/app/src/main/java/com/tangem/tap/features/welcome/redux/WelcomeMiddleware.kt
index 9955bf6d6d..005bcca0a4 100644
--- a/app/src/main/java/com/tangem/tap/features/welcome/redux/WelcomeMiddleware.kt
+++ b/app/src/main/java/com/tangem/tap/features/welcome/redux/WelcomeMiddleware.kt
@@ -1,6 +1,5 @@
package com.tangem.tap.features.welcome.redux
-import android.content.Intent
import com.tangem.common.core.TangemSdkError
import com.tangem.common.doOnFailure
import com.tangem.common.doOnResult
@@ -19,6 +18,7 @@ import com.tangem.tap.common.redux.navigation.NavigationAction
import com.tangem.tap.domain.model.builders.UserWalletBuilder
import com.tangem.tap.domain.scanCard.ScanCardProcessor
import com.tangem.tap.domain.userWalletList.unlockIfLockable
+import com.tangem.tap.features.intentHandler.handlers.WalletConnectLinkIntentHandler
import com.tangem.tap.features.signin.redux.SignInAction
import kotlinx.coroutines.launch
import org.rekotlin.Middleware
@@ -39,24 +39,10 @@ internal class WelcomeMiddleware {
private fun handleAction(action: WelcomeAction, state: WelcomeState) {
when (action) {
- is WelcomeAction.ProceedWithBiometrics -> {
- proceedWithBiometrics(state)
- }
- is WelcomeAction.ProceedWithCard -> {
- proceedWithCard(state)
- }
- is WelcomeAction.HandleIntentIfNeeded -> {
- handleInitialIntent(action.intent)
- }
- is WelcomeAction.ClearUserWallets -> {
- disableUserWalletsSaving()
- }
- is WelcomeAction.ProceedWithBiometrics.Error,
- is WelcomeAction.ProceedWithCard.Error,
- is WelcomeAction.ProceedWithBiometrics.Success,
- is WelcomeAction.ProceedWithCard.Success,
- is WelcomeAction.CloseError,
- -> Unit
+ is WelcomeAction.ProceedWithBiometrics -> proceedWithBiometrics(state)
+ is WelcomeAction.ProceedWithCard -> proceedWithCard(state)
+ is WelcomeAction.ClearUserWallets -> disableUserWalletsSaving()
+ else -> Unit
}
}
@@ -85,7 +71,9 @@ internal class WelcomeMiddleware {
store.dispatchOnMain(WelcomeAction.ProceedWithBiometrics.Success)
store.onUserWalletSelected(userWallet = selectedUserWallet)
- intentHandler.handleWalletConnectLink(state.intent)
+ state.intent?.let {
+ WalletConnectLinkIntentHandler().handleIntent(it)
+ }
}
}
@@ -104,20 +92,13 @@ internal class WelcomeMiddleware {
store.dispatchOnMain(WelcomeAction.ProceedWithCard.Success)
store.onUserWalletSelected(userWallet = userWallet)
- intentHandler.handleWalletConnectLink(state.intent)
+ state.intent?.let {
+ WalletConnectLinkIntentHandler().handleIntent(it)
+ }
}
}
}
- private fun handleInitialIntent(intent: Intent?) {
- val isBackgroundScanNotHandled = !intentHandler.handleBackgroundScan(intent, hasSavedUserWallets = true)
- val hasNotIncompletedBackup = !backupService.hasIncompletedBackup
-
- if (isBackgroundScanNotHandled && hasNotIncompletedBackup) {
- store.dispatchOnMain(WelcomeAction.ProceedWithBiometrics)
- }
- }
-
private suspend inline fun scanCardInternal(crossinline onCardScanned: suspend (ScanResponse) -> Unit) {
tangemSdkManager.setAccessCodeRequestPolicy(
useBiometricsForAccessCode = preferencesStorage.shouldSaveAccessCodes,
diff --git a/app/src/main/java/com/tangem/tap/features/welcome/redux/WelcomeReducer.kt b/app/src/main/java/com/tangem/tap/features/welcome/redux/WelcomeReducer.kt
index 5f14d1744d..11bfb0ea4a 100644
--- a/app/src/main/java/com/tangem/tap/features/welcome/redux/WelcomeReducer.kt
+++ b/app/src/main/java/com/tangem/tap/features/welcome/redux/WelcomeReducer.kt
@@ -14,7 +14,7 @@ internal object WelcomeReducer {
private fun internalReduce(action: WelcomeAction, state: WelcomeState): WelcomeState {
return when (action) {
- is WelcomeAction.HandleIntentIfNeeded -> state.copy(intent = action.intent)
+ is WelcomeAction.SetInitialIntent -> state.copy(intent = action.intent)
is WelcomeAction.ProceedWithBiometrics -> state.copy(isUnlockWithBiometricsInProgress = true)
is WelcomeAction.ProceedWithCard -> state.copy(isUnlockWithCardInProgress = true)
is WelcomeAction.ProceedWithBiometrics.Error -> state.copy(
diff --git a/app/src/main/java/com/tangem/tap/network/payid/PayIdVerifyApi.kt b/app/src/main/java/com/tangem/tap/network/payid/PayIdVerifyApi.kt
deleted file mode 100644
index d9d00a663b..0000000000
--- a/app/src/main/java/com/tangem/tap/network/payid/PayIdVerifyApi.kt
+++ /dev/null
@@ -1,40 +0,0 @@
-package com.tangem.tap.network.payid
-
-import com.squareup.moshi.JsonClass
-import retrofit2.http.GET
-import retrofit2.http.Header
-import retrofit2.http.Path
-
-/**
-[REDACTED_AUTHOR]
- */
-interface PayIdVerifyApi {
- @GET("{user}")
- suspend fun verifyAddress(
- @Path("user") user: String,
- @Header("Accept") acceptNetworkHeader: String,
- @Header("PayID-Version") payIdVersion: String = "1.0",
- ): VerifyPayIdResponse
-}
-
-@JsonClass(generateAdapter = true)
-data class VerifyPayIdResponse(
- val addresses: List = mutableListOf(),
- val payId: String? = null,
-) {
- fun getAddressDetails(): PayIdAddressDetails? = if (addresses.isNotEmpty()) addresses[0].addressDetails else null
-}
-
-@JsonClass(generateAdapter = true)
-data class PayIdAddress(
- var paymentNetwork: String,
- var environment: String,
- var addressDetailsType: String,
- var addressDetails: PayIdAddressDetails,
-)
-
-@JsonClass(generateAdapter = true)
-data class PayIdAddressDetails(
- var address: String,
- var tag: String? = null,
-)
\ No newline at end of file
diff --git a/app/src/main/java/com/tangem/tap/network/payid/PayIdVerifyService.kt b/app/src/main/java/com/tangem/tap/network/payid/PayIdVerifyService.kt
deleted file mode 100644
index 05d16f8724..0000000000
--- a/app/src/main/java/com/tangem/tap/network/payid/PayIdVerifyService.kt
+++ /dev/null
@@ -1,24 +0,0 @@
-package com.tangem.tap.network.payid
-
-import com.tangem.common.services.Result
-import com.tangem.common.services.performRequest
-import com.tangem.datasource.api.common.createRetrofitInstance
-
-/**
-[REDACTED_AUTHOR]
- */
-class PayIdVerifyService(
- private val baseUrl: String,
-) {
-
- private val api = createRetrofitInstance(
- baseUrl = baseUrl,
- logEnabled = false,
- ).create(PayIdVerifyApi::class.java)
-
- suspend fun verifyAddress(user: String, network: String): Result {
- return performRequest { api.verifyAddress(user, createNetworkHeader(network)) }
- }
-
- private fun createNetworkHeader(network: String): String = "application/$network-mainnet+json"
-}
\ No newline at end of file
diff --git a/app/src/main/java/com/tangem/tap/proxy/di/ProxyModule.kt b/app/src/main/java/com/tangem/tap/proxy/di/ProxyModule.kt
index 1189c0895d..371f1e21bf 100644
--- a/app/src/main/java/com/tangem/tap/proxy/di/ProxyModule.kt
+++ b/app/src/main/java/com/tangem/tap/proxy/di/ProxyModule.kt
@@ -1,6 +1,8 @@
package com.tangem.tap.proxy.di
+import androidx.compose.ui.text.intl.Locale
import com.tangem.core.analytics.api.AnalyticsEventHandler
+import com.tangem.feature.learn2earn.domain.api.Learn2earnDependencyProvider
import com.tangem.lib.crypto.DerivationManager
import com.tangem.lib.crypto.TransactionManager
import com.tangem.lib.crypto.UserWalletManager
@@ -48,4 +50,20 @@ class ProxyModule {
appStateHolder = appStateHolder,
)
}
+
+ // regions FeatureConsumers
+ @Provides
+ @Singleton
+ fun provideLear2earnDependencies(appStateHolder: AppStateHolder): Learn2earnDependencyProvider {
+ return object : Learn2earnDependencyProvider {
+ override fun getUserCountryCodeProvider(): () -> String = {
+ appStateHolder.mainStore?.state?.globalState?.userCountryCode ?: Locale.current.language
+ }
+
+ override fun getWebViewAuthCredentialsProvider(): () -> String? = {
+ appStateHolder.mainStore?.state?.globalState?.configManager?.config?.tangemComAuthorization
+ }
+ }
+ }
+ // endregion FeatureConsumers
}
\ No newline at end of file
diff --git a/app/src/main/res/layout/dialog_wallet_trade.xml b/app/src/main/res/layout/dialog_wallet_trade.xml
index b2e6a5e45b..dea867e05a 100644
--- a/app/src/main/res/layout/dialog_wallet_trade.xml
+++ b/app/src/main/res/layout/dialog_wallet_trade.xml
@@ -23,7 +23,7 @@
android:focusable="true"
android:gravity="center_vertical"
android:padding="16dp"
- android:text="@string/wallet_button_buy"
+ android:text="@string/common_buy"
android:textColor="@color/darkGray3"
android:textSize="14sp"
android:textStyle="bold"
@@ -38,7 +38,7 @@
android:focusable="true"
android:gravity="center_vertical"
android:padding="16dp"
- android:text="@string/wallet_button_sell"
+ android:text="@string/common_sell"
android:textColor="@color/darkGray3"
android:textSize="14sp"
android:textStyle="bold"
diff --git a/app/src/main/res/layout/fragment_send.xml b/app/src/main/res/layout/fragment_send.xml
index fe0eebf2a3..4035f923e2 100644
--- a/app/src/main/res/layout/fragment_send.xml
+++ b/app/src/main/res/layout/fragment_send.xml
@@ -22,7 +22,7 @@
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:navigationIcon="@drawable/ic_baseline_arrow_back_24"
- app:title="@string/send_title" />
+ app:title="@string/common_send" />
@@ -39,8 +39,8 @@
android:orientation="vertical">
@@ -115,7 +115,7 @@
style="@style/TapPrimaryIconButton"
android:layout_width="match_parent"
android:fontFamily="@font/saira_semi_condensed_regular"
- android:text="@string/send_title"
+ android:text="@string/common_send"
app:icon="@drawable/ic_arrow_right" />
+
+
-
-
-
-
-
-
-
-
-
-
diff --git a/app/src/main/res/layout/layout_send_address_payid.xml b/app/src/main/res/layout/layout_send_address.xml
similarity index 84%
rename from app/src/main/res/layout/layout_send_address_payid.xml
rename to app/src/main/res/layout/layout_send_address.xml
index 1bf69a649f..c6dd2873c8 100644
--- a/app/src/main/res/layout/layout_send_address_payid.xml
+++ b/app/src/main/res/layout/layout_send_address.xml
@@ -18,10 +18,9 @@
app:layout_constraintTop_toTopOf="parent">
+ app:layout_constraintTop_toTopOf="@+id/tilAddress">
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+ app:layout_constraintTop_toBottomOf="@+id/tilAddress">
@@ -51,7 +51,7 @@
style="@style/TapPrimaryIconButton"
android:layout_width="0dp"
android:layout_weight="1"
- android:text="@string/wallet_button_send"
+ android:text="@string/common_send"
app:icon="@drawable/ic_send" />
diff --git a/app/src/tangemAccess/java/com/tangem/Test2.java b/app/src/tangemAccess/java/com/tangem/Test2.java
deleted file mode 100644
index c4c336af47..0000000000
--- a/app/src/tangemAccess/java/com/tangem/Test2.java
+++ /dev/null
@@ -1,4 +0,0 @@
-package com.tangem;
-
-public class Test2 {
-}
diff --git a/app/src/tangemAccess/java/com/tangem/ui/ConfirmTransactionFragment.kt b/app/src/tangemAccess/java/com/tangem/ui/ConfirmTransactionFragment.kt
deleted file mode 100644
index f934c827fc..0000000000
--- a/app/src/tangemAccess/java/com/tangem/ui/ConfirmTransactionFragment.kt
+++ /dev/null
@@ -1,305 +0,0 @@
-package com.tangem.ui
-
-import android.app.Activity
-import android.content.SharedPreferences
-import android.nfc.NfcAdapter
-import android.nfc.Tag
-import android.os.Build
-import android.os.Bundle
-import android.preference.PreferenceManager
-import android.text.Editable
-import android.text.Html
-import android.text.TextWatcher
-import android.util.Log
-import android.view.View
-import android.widget.Toast
-import androidx.activity.OnBackPressedCallback
-import androidx.core.os.bundleOf
-import com.tangem.Constant
-import com.tangem.data.Blockchain
-import com.tangem.tangem_card.data.TangemCard
-import com.tangem.tangem_sdk.data.EXTRA_TANGEM_CARD
-import com.tangem.tangem_sdk.data.EXTRA_TANGEM_CARD_UID
-import com.tangem.tangem_sdk.data.loadFromBundle
-import com.tangem.ui.activity.MainActivity
-import com.tangem.ui.fragment.BaseFragment
-import com.tangem.ui.fragment.pin.PinRequestFragment
-import com.tangem.ui.navigation.NavigationResultListener
-import com.tangem.util.UtilHelper
-import com.tangem.wallet.CoinEngine
-import com.tangem.wallet.CoinEngineFactory
-import com.tangem.wallet.R
-import com.tangem.wallet.TangemContext
-import kotlinx.android.synthetic.tangemAccess.fragment_confirm_transaction.*
-import java.io.IOException
-import java.util.*
-
-class ConfirmTransactionFragment : BaseFragment(), NavigationResultListener, NfcAdapter.ReaderCallback {
-
- override val layoutId = R.layout.fragment_confirm_transaction
-
- private lateinit var sp: SharedPreferences
- private lateinit var ctx: TangemContext
- private lateinit var amount: CoinEngine.Amount
-
- private var isIncludeFee: Boolean = true
- private var requestPIN2Count = 0
- private var nodeCheck = true
- private var dtVerified: Date? = null
-
- private var blockchainCallbacks: CoinEngine.BlockchainRequestsCallbacks? = null
-
- override fun onCreate(savedInstanceState: Bundle?) {
- super.onCreate(savedInstanceState)
-
- sp = PreferenceManager.getDefaultSharedPreferences(context)
- ctx = TangemContext.loadFromBundle(requireContext(), arguments)
-
- val callback = object : OnBackPressedCallback(true) {
- override fun handleOnBackPressed() {
- navigateUp()
- }
- }
- requireActivity().onBackPressedDispatcher.addCallback(this, callback)
- }
-
- override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
- super.onViewCreated(view, savedInstanceState)
-
- val engine = CoinEngineFactory.create(ctx)
-
- @Suppress("DEPRECATION") val html = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
- Html.fromHtml(engine!!.balanceHTML, Html.FROM_HTML_MODE_LEGACY)
- else
- Html.fromHtml(engine!!.balanceHTML)
- tvBalance.text = html
-
- isIncludeFee = arguments?.getBoolean(Constant.EXTRA_FEE_INCLUDED, true) ?: true
-
- if (isIncludeFee)
- tvIncFee.setText(R.string.confirm_transaction_including_fee)
- else
- tvIncFee.setText(R.string.confirm_transaction_not_including_fee)
-
- amount = CoinEngine.Amount(arguments?.getString(Constant.EXTRA_AMOUNT) ?: "0",
- arguments?.getString(Constant.EXTRA_AMOUNT_CURRENCY) ?: "")
-
- if (engine.allowSelectFeeInclusion())
- tvIncFee.visibility = View.VISIBLE
- else
- tvIncFee.visibility = View.INVISIBLE
-
- if (ctx.card.blockchainID == Blockchain.Token.id) {
- // for Blockchain.Token limit decimals
- etAmount.setText(amount.toValueString(ctx.card.tokensDecimal))
- } else {
- // for others
- etAmount.setText(amount.toValueString())
- }
-
- tvCurrency.text = engine.balanceCurrency
- tvCurrency2.text = engine.feeCurrency
- tvCardID.text = ctx.card.cidDescription
- etWallet.setText(arguments?.getString(Constant.EXTRA_TARGET_ADDRESS))
-
- btnSend.visibility = View.INVISIBLE
-
- if (!engine.allowSelectFeeLevel()) {
- rgFee.visibility = View.INVISIBLE
- }
-
- etFee.isEnabled = sp.getBoolean(getString(R.string.pref_manual_editing_fee), false)
-
- // set listeners
- rgFee.setOnCheckedChangeListener { _, checkedId -> doSetFee(checkedId) }
- etFee.addTextChangedListener(object : TextWatcher {
- override fun beforeTextChanged(s: CharSequence, start: Int, count: Int, after: Int) {
-
- }
-
- override fun onTextChanged(s: CharSequence, start: Int, before: Int, count: Int) {
- try {
- val eqFee = engine.evaluateFeeEquivalent(etFee!!.text.toString())
- tvFeeEquivalent.text = eqFee
-
- if (!ctx.coinData!!.amountEquivalentDescriptionAvailable) {
- tvFeeEquivalent.error = getString(R.string.confirm_transaction_error_service_unavailable)
- tvCurrency2.visibility = View.GONE
- tvFeeEquivalent.visibility = View.GONE
- } else
- tvFeeEquivalent.error = null
-
- if (sp.getBoolean(getString(R.string.pref_manual_editing_fee), false))
- (activity as MainActivity).toastHelper
- .showSingleToast(context, getString(R.string.confirm_transaction_warning_risk_delaying))
-
- } catch (e: Exception) {
- e.printStackTrace()
- tvFeeEquivalent.text = ""
- }
- }
-
- override fun afterTextChanged(s: Editable) {
-
- }
- })
- btnSend.setOnClickListener {
- if (UtilHelper.isOnline(requireContext())) {
- val calendar = Calendar.getInstance()
- calendar.add(Calendar.MINUTE, -1)
-
- if (dtVerified == null || dtVerified!!.before(calendar.time)) {
- finishWithError(Activity.RESULT_CANCELED, getString(R.string.confirm_transaction_error_data_is_outdated))
- return@setOnClickListener
- }
-
- val engineCoin = CoinEngineFactory.create(ctx)
-
- if (engineCoin!!.isNeedCheckNode && !nodeCheck) {
- Toast.makeText(context, getString(R.string.confirm_transaction_error_cannot_reach_node), Toast.LENGTH_LONG).show()
- return@setOnClickListener
- }
-
- val txFee = engineCoin.convertToAmount(etFee.text.toString(), tvCurrency2.text.toString())
- val txAmount = engineCoin.convertToAmount(etAmount.text.toString(), tvCurrency.text.toString())
-
- if (!engineCoin.hasBalanceInfo()) {
- finishWithError(Activity.RESULT_CANCELED, getString(R.string.confirm_transaction_error_cannot_check_balance))
- return@setOnClickListener
-
- } else if (!engineCoin.isBalanceNotZero) {
- finishWithError(Activity.RESULT_CANCELED, getString(R.string.general_wallet_empty))
- return@setOnClickListener
-
- } else if (!engineCoin.isExtractPossible) {
- finishWithError(Activity.RESULT_CANCELED, getString(R.string.confirm_transaction_error_incoming_transaction_unconfirmed))
- return@setOnClickListener
- }
-
- if (!engineCoin.checkNewTransactionAmountAndFee(txAmount, txFee, isIncludeFee)) {
- finishWithError(Activity.RESULT_CANCELED, getString(R.string.prepare_transaction_error_not_enough_funds))
- return@setOnClickListener
- }
-
- requestPIN2Count = 0
- val data = Bundle()
- data.putString(Constant.EXTRA_MODE, PinRequestFragment.Mode.RequestPIN2.toString())
- ctx.saveToBundle(data)
- data.putBoolean(Constant.EXTRA_FEE_INCLUDED, isIncludeFee)
- navigateForResult(Constant.REQUEST_CODE_REQUEST_PIN2_, R.id.action_confirmTransactionFragment_to_pinRequestFragment, data)
- } else
- Toast.makeText(context, getString(R.string.general_error_no_connection), Toast.LENGTH_SHORT).show()
- }
-
- progressBar.visibility = View.VISIBLE
-
- if (!navigatedBack) requestFee()
- }
-
- private fun requestFee() {
- val coinEngine = CoinEngineFactory.create(ctx)
- coinEngine!!.requestFee(
- object : CoinEngine.BlockchainRequestsCallbacks {
- override fun onComplete(success: Boolean) {
- if (success) {
- progressBar?.visibility = View.INVISIBLE
- dtVerified = Date()
- doSetFee(rgFee?.checkedRadioButtonId ?: R.id.rbNormalFee)
- } else {
- finishWithError(Activity.RESULT_CANCELED, ctx.error)
- }
- }
-
- override fun onProgress() {
- }
-
- override fun allowAdvance(): Boolean {
- return UtilHelper.isOnline(requireContext())
- }
- },
- etWallet.text.toString(),
- amount)
- }
-
- override fun onNavigationResult(requestCode: String, resultCode: Int, data: Bundle?) {
- Log.d("LIFECYCLE", "NavigationResult assessed ${this::class.java.simpleName}")
- if (requestCode == Constant.REQUEST_CODE_SIGN_TRANSACTION) {
- if (data != null) {
- if (data.containsKey(EXTRA_TANGEM_CARD_UID) && data.containsKey(EXTRA_TANGEM_CARD)) {
- val updatedCard = TangemCard(data.getString(EXTRA_TANGEM_CARD_UID))
- updatedCard.loadFromBundle(data.getBundle(EXTRA_TANGEM_CARD))
- ctx.card = updatedCard
- }
- }
- if (resultCode == Constant.RESULT_INVALID_PIN_ && requestPIN2Count < 2) {
- requestPIN2Count++
- val bundle = Bundle()
- bundle.putString(Constant.EXTRA_MODE, PinRequestFragment.Mode.RequestPIN2.toString())
- ctx.saveToBundle(bundle)
- bundle.putBoolean(Constant.EXTRA_FEE_INCLUDED, isIncludeFee)
- navigateForResult(Constant.REQUEST_CODE_REQUEST_PIN2_,
- R.id.action_confirmTransactionFragment_to_pinRequestFragment,
- bundle)
- return
- }
- navigateBackWithResult(resultCode, data)
- } else if (requestCode == Constant.REQUEST_CODE_REQUEST_PIN2_) {
- if (resultCode == Activity.RESULT_OK) {
- val bundle = Bundle()
- ctx.saveToBundle(bundle)
- bundle.putString(Constant.EXTRA_TARGET_ADDRESS, etWallet!!.text.toString())
- bundle.putString(Constant.EXTRA_AMOUNT, etAmount.text.toString())
- bundle.putString(Constant.EXTRA_AMOUNT_CURRENCY, tvCurrency.text.toString())
- bundle.putString(Constant.EXTRA_FEE, etFee.text.toString())
- bundle.putString(Constant.EXTRA_FEE_CURRENCY, tvCurrency2.text.toString())
- bundle.putBoolean(Constant.EXTRA_FEE_INCLUDED, isIncludeFee)
- navigateForResult(Constant.REQUEST_CODE_SIGN_TRANSACTION,
- R.id.action_confirmTransactionFragment_to_signTransactionFragment,
- bundle)
- } else
- Toast.makeText(context, R.string.confirm_transaction_error_pin_2_is_required, Toast.LENGTH_LONG).show()
- }
- }
-
- override fun onTagDiscovered(tag: Tag) {
- try {
- (activity as MainActivity).nfcManager.ignoreTag(tag)
- } catch (e: IOException) {
- e.printStackTrace()
- }
- }
-
- private fun doSetFee(checkedRadioButtonId: Int) {
- var txtFee = ""
- when (checkedRadioButtonId) {
- R.id.rbMinimalFee ->
- if (ctx.coinData.minFee != null) {
- txtFee = ctx.coinData.minFee!!.toValueString()
- btnSend?.visibility = View.VISIBLE
- } else
- btnSend?.visibility = View.INVISIBLE
-
- R.id.rbNormalFee ->
- if (ctx.coinData.normalFee != null) {
- txtFee = ctx.coinData.normalFee!!.toValueString()
- btnSend?.visibility = View.VISIBLE
- } else
- btnSend?.visibility = View.INVISIBLE
-
- R.id.rbMaximumFee ->
- if (ctx.coinData.maxFee != null) {
- txtFee = ctx.coinData.maxFee!!.toValueString()
- btnSend?.visibility = View.VISIBLE
- } else
- btnSend?.visibility = View.INVISIBLE
- }
- etFee?.setText(txtFee.replace(',', '.'))
- }
-
- private fun finishWithError(errorCode: Int, message: String) {
- navigateBackWithResult(
- errorCode,
- bundleOf(Constant.EXTRA_MESSAGE to message),
- R.id.loadedWalletFragment)
- }
-}
\ No newline at end of file
diff --git a/app/src/tangemAccess/java/com/tangem/ui/PrepareTransactionFragment.kt b/app/src/tangemAccess/java/com/tangem/ui/PrepareTransactionFragment.kt
deleted file mode 100644
index 387f992bb6..0000000000
--- a/app/src/tangemAccess/java/com/tangem/ui/PrepareTransactionFragment.kt
+++ /dev/null
@@ -1,182 +0,0 @@
-package com.tangem.ui
-
-import android.app.Activity
-import android.content.Context
-import android.nfc.NfcAdapter
-import android.nfc.Tag
-import android.os.Build
-import android.os.Bundle
-import android.text.Html
-import android.view.View
-import android.view.inputmethod.EditorInfo
-import android.view.inputmethod.InputMethodManager
-import android.widget.Toast
-import com.tangem.Constant
-import com.tangem.data.isPayIdSupported
-import com.tangem.ui.activity.MainActivity
-import com.tangem.ui.fragment.BaseFragment
-import com.tangem.ui.fragment.qr.CameraPermissionManager
-import com.tangem.ui.navigation.NavigationResultListener
-import com.tangem.util.UtilHelper
-import com.tangem.util.extensions.isStart2CoinCard
-import com.tangem.wallet.CoinEngineFactory
-import com.tangem.wallet.R
-import com.tangem.wallet.TangemContext
-import kotlinx.android.synthetic.tangemAccess.fragment_prepare_transaction.*
-import java.io.IOException
-
-class PrepareTransactionFragment : BaseFragment(), NavigationResultListener, NfcAdapter.ReaderCallback {
- companion object {
- val TAG: String = PrepareTransactionFragment::class.java.simpleName
- }
-
- override val layoutId = R.layout.fragment_prepare_transaction
-
- private val ctx: TangemContext by lazy { TangemContext.loadFromBundle(context, arguments) }
- private val cameraPermissionManager: CameraPermissionManager by lazy { CameraPermissionManager(this) }
-
- override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
- super.onViewCreated(view, savedInstanceState)
-
- tvCardID.text = ctx.card?.cidDescription
- val engine = CoinEngineFactory.create(ctx)
-
- @Suppress("DEPRECATION") val html = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
- Html.fromHtml(engine!!.balanceHTML, Html.FROM_HTML_MODE_LEGACY)
- else
- Html.fromHtml(engine!!.balanceHTML)
- tvBalance.text = html
-
- if (ctx.blockchain.isPayIdSupported() && !ctx.card.isStart2CoinCard()) {
- etWallet.hint = getString(R.string.prepare_transaction_hint_address_or_pay_id)
- }
-
- if (!engine.allowSelectFeeInclusion()) {
- rgIncFee.visibility = View.INVISIBLE
- } else {
- rgIncFee.visibility = View.VISIBLE
- }
-
- if (ctx.card!!.remainingSignatures < 2) {
- etAmount.isEnabled = false
- }
-
- if (ctx.card.remainingSignatures == 1) {
- androidx.appcompat.app.AlertDialog.Builder(requireContext())
- .setTitle(R.string.prepare_transaction_warning_last_signature)
- .setMessage(R.string.prepare_transaction_warning_send_full_amount)
- .setPositiveButton(R.string.general_ok) { _, _ -> }
- .create()
- .show()
- }
-
- tvCurrency.text = engine.balance.currency
- etAmount.setText(engine.balance.toValueString())
-
- // limit number of symbols after comma
- etAmount.filters = engine.amountInputFilters
-
- // set listeners
- etAmount.setOnEditorActionListener { lv, actionId, _ ->
- if (actionId == EditorInfo.IME_ACTION_DONE) {
- val imm = lv.context.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
- imm.hideSoftInputFromWindow(lv.windowToken, 0)
- lv.clearFocus()
- true
- } else {
- false
- }
- }
-
- btnVerify.setOnClickListener {
- if (!UtilHelper.isOnline(requireContext())) {
- Toast.makeText(context, R.string.general_error_no_connection, Toast.LENGTH_LONG).show()
- return@setOnClickListener
- }
-
- val engine1 = CoinEngineFactory.create(ctx)
- val strAmount: String = etAmount.text.toString().replace(",", ".")
- val amount = engine1!!.convertToAmount(etAmount.text.toString(), tvCurrency.text.toString())
-
- try {
- if (!engine.checkNewTransactionAmount(amount))
- etAmount.error = getString(R.string.prepare_transaction_error_not_enough_funds)
- else
- etAmount.error = null
- } catch (e: Exception) {
- etAmount.error = getString(R.string.prepare_transaction_error_unknown_amount_format)
- }
-
- // check wallet address
- if (!engine1.validateAddress(etWallet.text.toString())) {
- etWallet.error = getString(R.string.prepare_transaction_error_incorrect_destination)
- return@setOnClickListener
- } else
- etWallet.error = null
-
- if (etWallet.text.toString() == ctx.coinData!!.wallet) {
- etWallet.error = getString(R.string.prepare_transaction_error_same_address)
- return@setOnClickListener
- }
-
- if (!etAmount.error.isNullOrEmpty() || !etWallet.error.isNullOrEmpty()) {
- return@setOnClickListener
- }
-
- val data = Bundle()
- ctx.saveToBundle(data)
- data.putString(Constant.EXTRA_TARGET_ADDRESS, etWallet!!.text.toString())
- data.putBoolean(Constant.EXTRA_FEE_INCLUDED, (rgIncFee!!.checkedRadioButtonId == R.id.rbFeeIn))
- data.putString(Constant.EXTRA_AMOUNT, strAmount)
- data.putString(Constant.EXTRA_AMOUNT_CURRENCY, tvCurrency.text.toString())
- navigateForResult(
- Constant.REQUEST_CODE_SEND_TRANSACTION__,
- R.id.action_prepareTransactionFragment_to_confirmTransactionFragment,
- data)
- }
-
- ivCamera.setOnClickListener {
- if (cameraPermissionManager.isPermissionGranted()) {
- navigateForResult(Constant.REQUEST_CODE_SCAN_QR, R.id.action_prepareTransactionFragment_to_qrScanFragment)
- } else {
- cameraPermissionManager.requirePermission()
- }
- }
- }
-
- override fun onRequestPermissionsResult(requestCode: Int, permissions: Array, grantResults: IntArray) {
- super.onRequestPermissionsResult(requestCode, permissions, grantResults)
- cameraPermissionManager.handleRequestPermissionResult(requestCode, grantResults) {
- navigateForResult(Constant.REQUEST_CODE_SCAN_QR, R.id.action_prepareTransactionFragment_to_qrScanFragment)
- }
- }
-
- override fun onNavigationResult(requestCode: String, resultCode: Int, data: Bundle?) {
- if (requestCode == Constant.REQUEST_CODE_SCAN_QR && resultCode == Activity.RESULT_OK && data != null && data.containsKey("QRCode")) {
- val code = data.getString("QRCode")
- val schemeSplit = code!!.split(":")
- when (schemeSplit.size) {
- 2 -> {
- if (schemeSplit[0] == ctx.blockchain.uriScheme) {
- etWallet?.setText(schemeSplit[1])
- } else {
- etWallet?.setText(code)
- }
- }
- else -> {
- etWallet?.setText(code)
- }
- }
- } else if (requestCode == Constant.REQUEST_CODE_SEND_TRANSACTION__) {
- navigateBackWithResult(resultCode, data)
- }
- }
-
- override fun onTagDiscovered(tag: Tag) {
- try {
- (activity as MainActivity).nfcManager.ignoreTag(tag)
- } catch (e: IOException) {
- e.printStackTrace()
- }
- }
-}
\ No newline at end of file
diff --git a/app/src/tangemAccess/java/com/tangem/ui/SignTransactionFragment.kt b/app/src/tangemAccess/java/com/tangem/ui/SignTransactionFragment.kt
deleted file mode 100644
index fdcdc64a72..0000000000
--- a/app/src/tangemAccess/java/com/tangem/ui/SignTransactionFragment.kt
+++ /dev/null
@@ -1,312 +0,0 @@
-package com.tangem.ui
-
-import android.app.Activity
-import android.content.res.ColorStateList
-import android.graphics.Color
-import android.media.MediaPlayer
-import android.nfc.NfcAdapter
-import android.nfc.Tag
-import android.nfc.tech.IsoDep
-import android.os.Bundle
-import android.view.View
-import androidx.activity.OnBackPressedCallback
-import com.google.firebase.analytics.FirebaseAnalytics
-import com.google.firebase.crashlytics.FirebaseCrashlytics
-import com.tangem.App
-import com.tangem.Constant
-import com.tangem.tangem_card.reader.CardProtocol
-import com.tangem.tangem_card.tasks.SignTask
-import com.tangem.tangem_card.util.Util
-import com.tangem.tangem_sdk.android.nfc.NfcDeviceAntennaLocation
-import com.tangem.tangem_sdk.android.reader.NfcReader
-import com.tangem.tangem_sdk.data.EXTRA_TANGEM_CARD
-import com.tangem.tangem_sdk.data.EXTRA_TANGEM_CARD_UID
-import com.tangem.tangem_sdk.data.asBundle
-import com.tangem.ui.activity.MainActivity
-import com.tangem.ui.dialog.NoExtendedLengthSupportDialog
-import com.tangem.ui.dialog.WaitSecurityDelayDialog
-import com.tangem.ui.fragment.BaseFragment
-import com.tangem.ui.navigation.NavigationResultListener
-import com.tangem.util.Analytics
-import com.tangem.util.AnalyticsEvent
-import com.tangem.util.LOG
-import com.tangem.wallet.CoinEngine
-import com.tangem.wallet.CoinEngineFactory
-import com.tangem.wallet.R
-import com.tangem.wallet.TangemContext
-import kotlinx.android.synthetic.main.layout_progress_horizontal.*
-import kotlinx.android.synthetic.main.layout_touch_card.*
-import kotlinx.android.synthetic.tangemAccess.fragment_sign_transaction.*
-
-
-class SignTransactionFragment : BaseFragment(), NavigationResultListener,
- NfcAdapter.ReaderCallback, CardProtocol.Notifications {
-
- companion object {
- val TAG: String = SignTransactionFragment::class.java.simpleName
- }
-
- override val layoutId = R.layout.fragment_sign_transaction
-
- private lateinit var ctx: TangemContext
- private lateinit var mpFinishSignSound: MediaPlayer
-
- private lateinit var nfcDeviceAntenna: NfcDeviceAntennaLocation
-
- private var signTransactionTask: SignTask? = null
-
- private lateinit var amount: CoinEngine.Amount
- private lateinit var fee: CoinEngine.Amount
- private var isIncludeFee = true
- private var outAddressStr: String? = null
- private var lastReadSuccess = true
-
- override fun onCreate(savedInstanceState: Bundle?) {
- super.onCreate(savedInstanceState)
- ctx = TangemContext.loadFromBundle(context, arguments)
-
- val callback = object : OnBackPressedCallback(true) {
- override fun handleOnBackPressed() {
- navigateBackWithResult(Activity.RESULT_CANCELED)
- }
- }
- requireActivity().onBackPressedDispatcher.addCallback(this, callback)
- }
-
- override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
- super.onViewCreated(view, savedInstanceState)
-
- mpFinishSignSound = MediaPlayer.create(context, R.raw.scan_card_sound)
-
- // init NFC Antenna
- nfcDeviceAntenna = NfcDeviceAntennaLocation(requireContext(), ivHandCardHorizontal, ivHandCardVertical, llHand, llNfc)
- nfcDeviceAntenna.init()
-
- amount = CoinEngine.Amount(arguments?.getString(Constant.EXTRA_AMOUNT), arguments?.getString(Constant.EXTRA_AMOUNT_CURRENCY))
- fee = CoinEngine.Amount(arguments?.getString(Constant.EXTRA_FEE), arguments?.getString(Constant.EXTRA_FEE_CURRENCY))
- isIncludeFee = arguments?.getBoolean(Constant.EXTRA_FEE_INCLUDED, true) ?: true
- outAddressStr = arguments?.getString(Constant.EXTRA_TARGET_ADDRESS)
-
- tvCardID.text = ctx.card!!.cidDescription
- progressBar.progressTintList = ColorStateList.valueOf(Color.DKGRAY)
- progressBar.visibility = View.INVISIBLE
-
- FirebaseAnalytics.getInstance(requireActivity())
- .logEvent(AnalyticsEvent.READY_TO_SIGN.event, Analytics.setCardData(ctx))
- }
-
- override fun onPause() {
- signTransactionTask?.cancel(true)
- super.onPause()
- }
-
- override fun onStop() {
- signTransactionTask?.cancel(true)
- super.onStop()
- }
-
- override fun onNavigationResult(requestCode: String, resultCode: Int, data: Bundle?) {
- if (requestCode == Constant.REQUEST_CODE_SEND_TRANSACTION_) {
- navigateBackWithResult(resultCode, data)
- }
- }
-
- override fun onTagDiscovered(tag: Tag) {
- try {
- // get IsoDep handle and run cardReader thread
- val isoDep = IsoDep.get(tag)
- val uid = tag.id
- val sUID = Util.byteArrayToHexString(uid)
-
- if (sUID == ctx.card.uid) {
- if (lastReadSuccess)
- isoDep.timeout = ctx.card.pauseBeforePIN2 + 5000
- else
- isoDep.timeout = ctx.card.pauseBeforePIN2 + 65000
-
- val coinEngine = CoinEngineFactory.create(ctx)
- coinEngine?.setOnNeedSendTransaction { tx ->
- if (tx != null) {
- val data = Bundle()
- ctx.saveToBundle(data)
- data.putByteArray(Constant.EXTRA_TX, tx)
- navigateForResult(
- Constant.REQUEST_CODE_SEND_TRANSACTION_,
- R.id.action_signTransactionFragment_to_sendTransactionFragment,
- data)
- }
- }
- val transactionToSign = coinEngine?.constructTransaction(amount, fee, isIncludeFee, outAddressStr)
-
- signTransactionTask = SignTask(ctx.card, NfcReader((activity as MainActivity).nfcManager, isoDep),
- App.localStorage, App.pinStorage, this, transactionToSign)
- signTransactionTask?.start()
- } else
- (activity as MainActivity).nfcManager.ignoreTag(isoDep.tag)
-
- } catch (e: CardProtocol.TangemException_WrongAmount) {
- try {
- val data = Bundle()
- data.putString(Constant.EXTRA_MESSAGE, getString(R.string.send_transaction_error_wrong_amount))
- data.putString(EXTRA_TANGEM_CARD_UID, ctx.card.uid)
- data.putBundle(EXTRA_TANGEM_CARD, ctx.card.asBundle)
- navigateBackWithResult(Activity.RESULT_CANCELED, data)
- } catch (e: Exception) {
- e.printStackTrace()
- }
- } catch(e: IllegalArgumentException) {
- val data = Bundle()
- data.putString(Constant.EXTRA_MESSAGE, e.message)
- navigateBackWithResult(Activity.RESULT_CANCELED, data, R.id.loadedWalletFragment)
- } catch (e: Exception) {
- e.printStackTrace()
- }
- }
-
- override fun onReadStart(cardProtocol: CardProtocol) {
- rlProgressBar?.post { rlProgressBar.visibility = View.VISIBLE }
-
- progressBar?.post {
- progressBar?.visibility = View.VISIBLE
- progressBar?.progress = 5
- }
- }
-
- override fun onReadProgress(protocol: CardProtocol, progress: Int) {
- progressBar?.post { progressBar?.progress = progress }
- }
-
- override fun onReadFinish(cardProtocol: CardProtocol?) {
- signTransactionTask = null
- if (cardProtocol != null) {
- if (cardProtocol.error == null) {
-
- FirebaseAnalytics.getInstance(requireActivity())
- .logEvent(AnalyticsEvent.SIGNED.event, Analytics.setCardData(ctx))
-
- rlProgressBar?.post { rlProgressBar?.visibility = View.GONE }
-
- progressBar?.post {
- progressBar?.progress = 100
- progressBar?.progressTintList = ColorStateList.valueOf(Color.GREEN)
- }
-
- mpFinishSignSound.start()
- } else {
- lastReadSuccess = false
- FirebaseCrashlytics.getInstance().recordException(cardProtocol.error)
- if (cardProtocol.error.javaClass == CardProtocol.TangemException_InvalidPIN::class.java) {
- progressBar?.post {
- progressBar?.progress = 100
- progressBar?.progressTintList = ColorStateList.valueOf(Color.RED)
- }
- progressBar?.postDelayed({
- try {
- progressBar?.progress = 0
- progressBar?.progressTintList = ColorStateList.valueOf(Color.DKGRAY)
- progressBar?.visibility = View.INVISIBLE
- val data = Bundle()
- data.putString(Constant.EXTRA_MESSAGE, getString(R.string.send_transaction_error_cannot_sign))
- data.putString(EXTRA_TANGEM_CARD_UID, cardProtocol.card.uid)
- data.putBundle(EXTRA_TANGEM_CARD, cardProtocol.card.asBundle)
- navigateBackWithResult(Constant.RESULT_INVALID_PIN_, data)
- } catch (e: Exception) {
- e.printStackTrace()
- }
- }, 500)
- } else {
- if (cardProtocol.error is CardProtocol.TangemException_WrongAmount) {
- try {
- val data = Bundle()
- data.putString(Constant.EXTRA_MESSAGE, getString(R.string.send_transaction_error_wrong_amount))
- data.putString(EXTRA_TANGEM_CARD_UID, cardProtocol.card.uid)
- data.putBundle(EXTRA_TANGEM_CARD, cardProtocol.card.asBundle)
- navigateBackWithResult(Activity.RESULT_CANCELED, data)
- } catch (e: Exception) {
- e.printStackTrace()
- }
- }
- progressBar?.post {
- if (cardProtocol.error is CardProtocol.TangemException_ExtendedLengthNotSupported) {
- if (!NoExtendedLengthSupportDialog.allReadyShowed) {
- NoExtendedLengthSupportDialog.message = getText(R.string.dialog_the_nfc_adapter_length_apdu).toString() + "\n" + getText(R.string.dialog_the_nfc_adapter_length_apdu_advice).toString()
- NoExtendedLengthSupportDialog().show(requireFragmentManager(), NoExtendedLengthSupportDialog.TAG)
- }
- } else {
- (activity as? MainActivity)?.toastHelper?.showSingleToast(
- context, getString(R.string.general_notification_scan_again)
- )
- }
- progressBar?.progress = 100
- progressBar?.progressTintList = ColorStateList.valueOf(Color.RED)
- }
- }
- }
- }
-
- rlProgressBar?.postDelayed({
- try {
- rlProgressBar?.visibility = View.GONE
- } catch (e: Exception) {
- e.printStackTrace()
- }
- }, 500)
-
- progressBar?.postDelayed({
- try {
- progressBar?.progress = 0
- progressBar?.progressTintList = ColorStateList.valueOf(Color.DKGRAY)
- progressBar?.visibility = View.INVISIBLE
- } catch (e: Exception) {
- e.printStackTrace()
- }
- }, 500)
- }
-
- override fun onReadCancel() {
- signTransactionTask = null
-
- progressBar?.postDelayed({
- try {
- progressBar?.progress = 0
- progressBar?.progressTintList = ColorStateList.valueOf(Color.DKGRAY)
- progressBar?.visibility = View.INVISIBLE
- } catch (e: Exception) {
- e.printStackTrace()
- }
- }, 500)
- }
-
-// private val waitSecurityDelayDialogNew = WaitSecurityDelayDialogNew()
-
- override fun onReadBeforeRequest(timeout: Int) {
- LOG.i(TAG, "onReadBeforeRequest timeout $timeout")
- activity?.let { WaitSecurityDelayDialog.onReadBeforeRequest(it, timeout) }
-
-// if (!waitSecurityDelayDialogNew.isAdded)
-// waitSecurityDelayDialogNew.show(supportFragmentManager, WaitSecurityDelayDialogNew.TAG)
-
-
-// val readBeforeRequest = ReadBeforeRequest()
-// readBeforeRequest.timeout = timeout
-// EventBus.getDefault().post(readBeforeRequest)
- }
-
- override fun onReadAfterRequest() {
- LOG.i(TAG, "onReadAfterRequest")
- activity?.let { WaitSecurityDelayDialog.onReadAfterRequest(it) }
-
-// val readAfterRequest = ReadAfterRequest()
-// EventBus.getDefault().post(readAfterRequest)
- }
-
- override fun onReadWait(msec: Int) {
- LOG.i(TAG, "onReadWait msec $msec")
- activity?.let { WaitSecurityDelayDialog.onReadWait(it, msec) }
-
-// val readWait = ReadWait()
-// readWait.msec = msec
-// EventBus.getDefault().post(readWait)
- }
-
-}
\ No newline at end of file
diff --git a/app/src/tangemAccess/res/layout/fragment_confirm_transaction.xml b/app/src/tangemAccess/res/layout/fragment_confirm_transaction.xml
deleted file mode 100644
index 6bb5f43dda..0000000000
--- a/app/src/tangemAccess/res/layout/fragment_confirm_transaction.xml
+++ /dev/null
@@ -1,343 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/app/src/tangemAccess/res/layout/fragment_prepare_transaction.xml b/app/src/tangemAccess/res/layout/fragment_prepare_transaction.xml
deleted file mode 100644
index 7f675df2a3..0000000000
--- a/app/src/tangemAccess/res/layout/fragment_prepare_transaction.xml
+++ /dev/null
@@ -1,266 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/app/src/tangemAccess/res/layout/fragment_sign_transaction.xml b/app/src/tangemAccess/res/layout/fragment_sign_transaction.xml
deleted file mode 100644
index 19125f6911..0000000000
--- a/app/src/tangemAccess/res/layout/fragment_sign_transaction.xml
+++ /dev/null
@@ -1,61 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/app/src/tangemAccess/res/values/strings.xml b/app/src/tangemAccess/res/values/strings.xml
deleted file mode 100644
index 845dc9021a..0000000000
--- a/app/src/tangemAccess/res/values/strings.xml
+++ /dev/null
@@ -1,6 +0,0 @@
-
-
-
- Tangem
-
-
\ No newline at end of file
diff --git a/buildSrc/src/main/java/Dependency.kt b/buildSrc/src/main/java/Dependency.kt
deleted file mode 100644
index e69de29bb2..0000000000
diff --git a/core/datasource/src/main/java/com/tangem/datasource/api/promotion/PromotionApi.kt b/core/datasource/src/main/java/com/tangem/datasource/api/promotion/PromotionApi.kt
new file mode 100644
index 0000000000..d71061c21a
--- /dev/null
+++ b/core/datasource/src/main/java/com/tangem/datasource/api/promotion/PromotionApi.kt
@@ -0,0 +1,29 @@
+package com.tangem.datasource.api.promotion
+
+import com.tangem.datasource.api.promotion.models.*
+import retrofit2.http.*
+
+/**
+ *
+ * Promotion API
+ * @see Documentation
+[REDACTED_AUTHOR]
+ */
+interface PromotionApi {
+
+ @Headers("Cache-Control: max-age=3600")
+ @GET("promotion")
+ suspend fun getPromotionInfo(@Query("programName") name: String): PromotionInfoResponse
+
+ @POST("promotion/code/validate")
+ suspend fun validateCode(@Body request: CodeValidateRequestBody): CodeValidateResponse
+
+ @POST("promotion/code/award")
+ suspend fun requestAwardByCode(@Body request: CodeAwardRequestBody): CodeAwardResponse
+
+ @POST("promotion/validate")
+ suspend fun validate(@Body request: ValidateRequestBody): ValidateResponse
+
+ @POST("promotion/award")
+ suspend fun requestAward(@Body request: AwardRequestBody): AwardResponse
+}
\ No newline at end of file
diff --git a/core/datasource/src/main/java/com/tangem/datasource/api/promotion/models/AbstractPromotionResponse.kt b/core/datasource/src/main/java/com/tangem/datasource/api/promotion/models/AbstractPromotionResponse.kt
new file mode 100644
index 0000000000..edfc8e990d
--- /dev/null
+++ b/core/datasource/src/main/java/com/tangem/datasource/api/promotion/models/AbstractPromotionResponse.kt
@@ -0,0 +1,18 @@
+package com.tangem.datasource.api.promotion.models
+
+import com.squareup.moshi.Json
+
+/**
+[REDACTED_AUTHOR]
+ */
+abstract class AbstractPromotionResponse {
+
+ abstract val error: Error?
+
+ fun isError(): Boolean = error != null
+
+ data class Error(
+ @Json(name = "code") val code: Int,
+ @Json(name = "message") val message: String,
+ )
+}
\ No newline at end of file
diff --git a/core/datasource/src/main/java/com/tangem/datasource/api/promotion/models/AwardRequestBody.kt b/core/datasource/src/main/java/com/tangem/datasource/api/promotion/models/AwardRequestBody.kt
new file mode 100644
index 0000000000..c8ac7faed1
--- /dev/null
+++ b/core/datasource/src/main/java/com/tangem/datasource/api/promotion/models/AwardRequestBody.kt
@@ -0,0 +1,12 @@
+package com.tangem.datasource.api.promotion.models
+
+import com.squareup.moshi.Json
+
+/**
+[REDACTED_AUTHOR]
+ */
+data class AwardRequestBody(
+ @Json(name = "walletId") val walletId: String,
+ @Json(name = "address") val address: String,
+ @Json(name = "programName") val programName: String,
+)
\ No newline at end of file
diff --git a/core/datasource/src/main/java/com/tangem/datasource/api/promotion/models/AwardResponse.kt b/core/datasource/src/main/java/com/tangem/datasource/api/promotion/models/AwardResponse.kt
new file mode 100644
index 0000000000..c43c59fa45
--- /dev/null
+++ b/core/datasource/src/main/java/com/tangem/datasource/api/promotion/models/AwardResponse.kt
@@ -0,0 +1,11 @@
+package com.tangem.datasource.api.promotion.models
+
+import com.squareup.moshi.Json
+
+/**
+[REDACTED_AUTHOR]
+ */
+data class AwardResponse(
+ @Json(name = "status") val status: Boolean?,
+ @Json(name = "error") override val error: Error? = null,
+) : AbstractPromotionResponse()
\ No newline at end of file
diff --git a/core/datasource/src/main/java/com/tangem/datasource/api/promotion/models/CodeAwardRequestBody.kt b/core/datasource/src/main/java/com/tangem/datasource/api/promotion/models/CodeAwardRequestBody.kt
new file mode 100644
index 0000000000..51e8626d4b
--- /dev/null
+++ b/core/datasource/src/main/java/com/tangem/datasource/api/promotion/models/CodeAwardRequestBody.kt
@@ -0,0 +1,12 @@
+package com.tangem.datasource.api.promotion.models
+
+import com.squareup.moshi.Json
+
+/**
+[REDACTED_AUTHOR]
+ */
+data class CodeAwardRequestBody(
+ @Json(name = "walletId") val walletId: String,
+ @Json(name = "address") val address: String,
+ @Json(name = "code") val code: String?,
+)
\ No newline at end of file
diff --git a/core/datasource/src/main/java/com/tangem/datasource/api/promotion/models/CodeAwardResponse.kt b/core/datasource/src/main/java/com/tangem/datasource/api/promotion/models/CodeAwardResponse.kt
new file mode 100644
index 0000000000..33d9313c42
--- /dev/null
+++ b/core/datasource/src/main/java/com/tangem/datasource/api/promotion/models/CodeAwardResponse.kt
@@ -0,0 +1,11 @@
+package com.tangem.datasource.api.promotion.models
+
+import com.squareup.moshi.Json
+
+/**
+[REDACTED_AUTHOR]
+ */
+data class CodeAwardResponse(
+ @Json(name = "status") val status: Boolean?,
+ @Json(name = "error") override val error: Error? = null,
+) : AbstractPromotionResponse()
\ No newline at end of file
diff --git a/core/datasource/src/main/java/com/tangem/datasource/api/promotion/models/CodeValidateRequestBody.kt b/core/datasource/src/main/java/com/tangem/datasource/api/promotion/models/CodeValidateRequestBody.kt
new file mode 100644
index 0000000000..769ecdad26
--- /dev/null
+++ b/core/datasource/src/main/java/com/tangem/datasource/api/promotion/models/CodeValidateRequestBody.kt
@@ -0,0 +1,11 @@
+package com.tangem.datasource.api.promotion.models
+
+import com.squareup.moshi.Json
+
+/**
+[REDACTED_AUTHOR]
+ */
+data class CodeValidateRequestBody(
+ @Json(name = "walletId") val walletId: String,
+ @Json(name = "code") val code: String?,
+)
\ No newline at end of file
diff --git a/core/datasource/src/main/java/com/tangem/datasource/api/promotion/models/CodeValidateResponse.kt b/core/datasource/src/main/java/com/tangem/datasource/api/promotion/models/CodeValidateResponse.kt
new file mode 100644
index 0000000000..e6e87e0ff3
--- /dev/null
+++ b/core/datasource/src/main/java/com/tangem/datasource/api/promotion/models/CodeValidateResponse.kt
@@ -0,0 +1,11 @@
+package com.tangem.datasource.api.promotion.models
+
+import com.squareup.moshi.Json
+
+/**
+[REDACTED_AUTHOR]
+ */
+data class CodeValidateResponse(
+ @Json(name = "valid") val valid: Boolean?,
+ @Json(name = "error") override val error: Error? = null,
+) : AbstractPromotionResponse()
\ No newline at end of file
diff --git a/core/datasource/src/main/java/com/tangem/datasource/api/promotion/models/PromotionInfoResponse.kt b/core/datasource/src/main/java/com/tangem/datasource/api/promotion/models/PromotionInfoResponse.kt
new file mode 100644
index 0000000000..ca5406aba5
--- /dev/null
+++ b/core/datasource/src/main/java/com/tangem/datasource/api/promotion/models/PromotionInfoResponse.kt
@@ -0,0 +1,40 @@
+package com.tangem.datasource.api.promotion.models
+
+import com.squareup.moshi.Json
+
+/**
+[REDACTED_AUTHOR]
+ */
+data class PromotionInfoResponse(
+ @Json(name = "newCard") val newCard: Data?,
+ @Json(name = "oldCard") val oldCard: Data?,
+ @Json(name = "awardPaymentToken") val awardPaymentToken: TokenData?,
+ @Json(name = "error") override val error: Error? = null,
+) : AbstractPromotionResponse() {
+
+ data class Data(
+ @Json(name = "status") val status: Status,
+ @Json(name = "award") val award: Double,
+ )
+
+ enum class Status(val value: String) {
+ @Json(name = "pending")
+ PENDING("pending"),
+
+ @Json(name = "active")
+ ACTIVE("active"),
+
+ @Json(name = "finished")
+ FINISHED("finished"),
+ }
+
+ data class TokenData(
+ @Json(name = "id") val id: String,
+ @Json(name = "name") val name: String,
+ @Json(name = "symbol") val symbol: String,
+ @Json(name = "active") val active: Boolean,
+ @Json(name = "networkId") val networkId: String,
+ @Json(name = "contractAddress") val contractAddress: String,
+ @Json(name = "decimalCount") val decimalCount: Int,
+ )
+}
\ No newline at end of file
diff --git a/core/datasource/src/main/java/com/tangem/datasource/api/promotion/models/ValidateRequestBody.kt b/core/datasource/src/main/java/com/tangem/datasource/api/promotion/models/ValidateRequestBody.kt
new file mode 100644
index 0000000000..090f0e0d29
--- /dev/null
+++ b/core/datasource/src/main/java/com/tangem/datasource/api/promotion/models/ValidateRequestBody.kt
@@ -0,0 +1,11 @@
+package com.tangem.datasource.api.promotion.models
+
+import com.squareup.moshi.Json
+
+/**
+[REDACTED_AUTHOR]
+ */
+data class ValidateRequestBody(
+ @Json(name = "walletId") val walletId: String,
+ @Json(name = "programName") val programName: String,
+)
\ No newline at end of file
diff --git a/core/datasource/src/main/java/com/tangem/datasource/api/promotion/models/ValidateResponse.kt b/core/datasource/src/main/java/com/tangem/datasource/api/promotion/models/ValidateResponse.kt
new file mode 100644
index 0000000000..97cd74645d
--- /dev/null
+++ b/core/datasource/src/main/java/com/tangem/datasource/api/promotion/models/ValidateResponse.kt
@@ -0,0 +1,11 @@
+package com.tangem.datasource.api.promotion.models
+
+import com.squareup.moshi.Json
+
+/**
+[REDACTED_AUTHOR]
+ */
+data class ValidateResponse(
+ @Json(name = "valid") val valid: Boolean?,
+ @Json(name = "error") override val error: Error? = null,
+) : AbstractPromotionResponse()
\ No newline at end of file
diff --git a/core/datasource/src/main/java/com/tangem/datasource/config/ConfigManager.kt b/core/datasource/src/main/java/com/tangem/datasource/config/ConfigManager.kt
index e3325c77c2..5cfaed8562 100644
--- a/core/datasource/src/main/java/com/tangem/datasource/config/ConfigManager.kt
+++ b/core/datasource/src/main/java/com/tangem/datasource/config/ConfigManager.kt
@@ -17,7 +17,6 @@ interface ConfigManager {
fun resetToDefault(name: String)
companion object {
- const val IS_SENDING_TO_PAY_ID_ENABLED = "isSendingToPayIdEnabled"
const val IS_CREATING_TWIN_CARDS_ALLOWED = "isCreatingTwinCardsAllowed"
const val IS_TOP_UP_ENABLED = "isTopUpEnabled"
}
diff --git a/core/datasource/src/main/java/com/tangem/datasource/config/ConfigManagerImpl.kt b/core/datasource/src/main/java/com/tangem/datasource/config/ConfigManagerImpl.kt
index 4f95438c33..1557e84bf1 100644
--- a/core/datasource/src/main/java/com/tangem/datasource/config/ConfigManagerImpl.kt
+++ b/core/datasource/src/main/java/com/tangem/datasource/config/ConfigManagerImpl.kt
@@ -1,13 +1,7 @@
package com.tangem.datasource.config
-import com.tangem.blockchain.common.BlockchainSdkConfig
-import com.tangem.blockchain.common.BlockchairCredentials
-import com.tangem.blockchain.common.GetBlockCredentials
-import com.tangem.blockchain.common.NowNodeCredentials
-import com.tangem.blockchain.common.QuickNodeCredentials
-import com.tangem.blockchain.common.TonCenterCredentials
+import com.tangem.blockchain.common.*
import com.tangem.datasource.config.ConfigManager.Companion.IS_CREATING_TWIN_CARDS_ALLOWED
-import com.tangem.datasource.config.ConfigManager.Companion.IS_SENDING_TO_PAY_ID_ENABLED
import com.tangem.datasource.config.ConfigManager.Companion.IS_TOP_UP_ENABLED
import com.tangem.datasource.config.models.Config
import com.tangem.datasource.config.models.ConfigModel
@@ -34,7 +28,6 @@ internal class ConfigManagerImpl @Inject constructor() : ConfigManager {
override fun turnOff(name: String) {
when (name) {
- IS_SENDING_TO_PAY_ID_ENABLED -> config = config.copy(isSendingToPayIdEnabled = false)
IS_TOP_UP_ENABLED -> config = config.copy(isTopUpEnabled = false)
IS_CREATING_TWIN_CARDS_ALLOWED -> config = config.copy(isCreatingTwinCardsAllowed = false)
}
@@ -42,13 +35,13 @@ internal class ConfigManagerImpl @Inject constructor() : ConfigManager {
override fun resetToDefault(name: String) {
when (name) {
- IS_SENDING_TO_PAY_ID_ENABLED ->
- config =
- config.copy(isSendingToPayIdEnabled = defaultConfig.isSendingToPayIdEnabled)
- IS_TOP_UP_ENABLED -> config = config.copy(isTopUpEnabled = defaultConfig.isTopUpEnabled)
- IS_CREATING_TWIN_CARDS_ALLOWED ->
- config =
- config.copy(isCreatingTwinCardsAllowed = defaultConfig.isCreatingTwinCardsAllowed)
+ IS_TOP_UP_ENABLED -> {
+ config = config.copy(isTopUpEnabled = defaultConfig.isTopUpEnabled)
+ }
+ IS_CREATING_TWIN_CARDS_ALLOWED -> {
+ config = config.copy(isCreatingTwinCardsAllowed = defaultConfig.isCreatingTwinCardsAllowed)
+ }
+ else -> Unit
}
}
@@ -57,12 +50,11 @@ internal class ConfigManagerImpl @Inject constructor() : ConfigManager {
config = config.copy(
isTopUpEnabled = model.isTopUpEnabled,
- isSendingToPayIdEnabled = model.isSendingToPayIdEnabled,
isCreatingTwinCardsAllowed = model.isCreatingTwinCardsAllowed,
)
+
defaultConfig = defaultConfig.copy(
isTopUpEnabled = model.isTopUpEnabled,
- isSendingToPayIdEnabled = model.isSendingToPayIdEnabled,
isCreatingTwinCardsAllowed = model.isCreatingTwinCardsAllowed,
)
}
@@ -111,6 +103,7 @@ internal class ConfigManagerImpl @Inject constructor() : ConfigManager {
zendesk = configValues.zendesk,
swapReferrerAccount = configValues.swapReferrerAccount,
walletConnectProjectId = configValues.walletConnectProjectId,
+ tangemComAuthorization = configValues.tangemComAuthorization,
)
}
}
\ No newline at end of file
diff --git a/core/datasource/src/main/java/com/tangem/datasource/config/models/Config.kt b/core/datasource/src/main/java/com/tangem/datasource/config/models/Config.kt
index 24d8735376..3d0bf5be7f 100644
--- a/core/datasource/src/main/java/com/tangem/datasource/config/models/Config.kt
+++ b/core/datasource/src/main/java/com/tangem/datasource/config/models/Config.kt
@@ -11,7 +11,6 @@ data class Config(
val appsFlyerDevKey: String = "",
val amplitudeApiKey: String = "",
val blockchainSdkConfig: BlockchainSdkConfig = BlockchainSdkConfig(),
- val isSendingToPayIdEnabled: Boolean = true,
val isTopUpEnabled: Boolean = false,
@Deprecated("Not relevant since version 3.23")
val isCreatingTwinCardsAllowed: Boolean = false,
@@ -19,4 +18,5 @@ data class Config(
val zendesk: ZendeskConfig? = null,
val swapReferrerAccount: SwapReferrerAccount? = null,
val walletConnectProjectId: String = "",
+ val tangemComAuthorization: String? = null,
)
\ No newline at end of file
diff --git a/core/datasource/src/main/java/com/tangem/datasource/config/models/JsonModels.kt b/core/datasource/src/main/java/com/tangem/datasource/config/models/JsonModels.kt
index cd518d4c31..2e195247a6 100644
--- a/core/datasource/src/main/java/com/tangem/datasource/config/models/JsonModels.kt
+++ b/core/datasource/src/main/java/com/tangem/datasource/config/models/JsonModels.kt
@@ -8,7 +8,6 @@ import com.squareup.moshi.Json
class FeatureModel(
val isTopUpEnabled: Boolean,
- val isSendingToPayIdEnabled: Boolean,
val isCreatingTwinCardsAllowed: Boolean,
)
@@ -38,6 +37,7 @@ class ConfigValueModel(
val swapReferrerAccount: SwapReferrerAccount?,
val kaspaSecondaryApiUrl: String,
val walletConnectProjectId: String,
+ val tangemComAuthorization: String?,
)
data class AppsFlyer(
diff --git a/core/datasource/src/main/java/com/tangem/datasource/di/NetworkModule.kt b/core/datasource/src/main/java/com/tangem/datasource/di/NetworkModule.kt
index 4ecc2b2529..c8ae82faa9 100644
--- a/core/datasource/src/main/java/com/tangem/datasource/di/NetworkModule.kt
+++ b/core/datasource/src/main/java/com/tangem/datasource/di/NetworkModule.kt
@@ -2,10 +2,13 @@ package com.tangem.datasource.di
import com.squareup.moshi.Moshi
import com.tangem.datasource.api.paymentology.PaymentologyApi
+import com.tangem.datasource.api.promotion.PromotionApi
import com.tangem.datasource.api.tangemTech.TangemTechApi
import com.tangem.datasource.utils.RequestHeader.*
import com.tangem.datasource.utils.addHeaders
import com.tangem.datasource.utils.allowLogging
+import com.tangem.lib.auth.AuthProvider
+import com.tangem.lib.auth.BuildConfig
import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
@@ -13,6 +16,7 @@ import dagger.hilt.components.SingletonComponent
import okhttp3.OkHttpClient
import retrofit2.Retrofit
import retrofit2.converter.moshi.MoshiConverterFactory
+import java.util.concurrent.TimeUnit
import javax.inject.Singleton
@Module
@@ -54,10 +58,37 @@ class NetworkModule {
.create(PaymentologyApi::class.java)
}
+ @Provides
+ @Singleton
+ @PromotionOneInch
+ fun providePromotionOneInchApi(authProvider: AuthProvider, @NetworkMoshi moshi: Moshi): PromotionApi {
+ val okClient = OkHttpClient.Builder()
+ .addHeaders(
+ AuthenticationHeader(authProvider),
+ )
+ .allowLogging()
+ .callTimeout(API_ONE_INCH_TIMEOUT_MS, TimeUnit.MILLISECONDS)
+ .connectTimeout(API_ONE_INCH_TIMEOUT_MS, TimeUnit.MILLISECONDS)
+ .readTimeout(API_ONE_INCH_TIMEOUT_MS, TimeUnit.MILLISECONDS)
+ .writeTimeout(API_ONE_INCH_TIMEOUT_MS, TimeUnit.MILLISECONDS)
+ .build()
+ return createBasePromotionRetrofit(okClient, moshi)
+ }
+
+ private fun createBasePromotionRetrofit(okHttpClient: OkHttpClient, moshi: Moshi): PromotionApi {
+ return Retrofit.Builder()
+ .addConverterFactory(MoshiConverterFactory.create(moshi))
+ .baseUrl(if (BuildConfig.DEBUG) DEV_TANGEM_TECH_BASE_URL else PROD_TANGEM_TECH_BASE_URL)
+ .client(okHttpClient)
+ .build()
+ .create(PromotionApi::class.java)
+ }
+
private companion object {
const val PROD_TANGEM_TECH_BASE_URL = "https://api.tangem-tech.com/v1/"
const val DEV_TANGEM_TECH_BASE_URL = "https://devapi.tangem-tech.com/v1/"
- private const val PAYMENTOLOGY_BASE_URL: String = "https://paymentologygate.oa.r.appspot.com/"
+ const val PAYMENTOLOGY_BASE_URL: String = "https://paymentologygate.oa.r.appspot.com/"
+ const val API_ONE_INCH_TIMEOUT_MS = 5000L
}
}
\ No newline at end of file
diff --git a/core/datasource/src/main/java/com/tangem/datasource/di/PromotionOneInch.kt b/core/datasource/src/main/java/com/tangem/datasource/di/PromotionOneInch.kt
new file mode 100644
index 0000000000..9e2d6b3981
--- /dev/null
+++ b/core/datasource/src/main/java/com/tangem/datasource/di/PromotionOneInch.kt
@@ -0,0 +1,8 @@
+package com.tangem.datasource.di
+
+import javax.inject.Qualifier
+
+@Qualifier
+@MustBeDocumented
+@Retention(AnnotationRetention.RUNTIME)
+annotation class PromotionOneInch
\ No newline at end of file
diff --git a/core/datasource/src/main/java/com/tangem/datasource/utils/HttpClientExt.kt b/core/datasource/src/main/java/com/tangem/datasource/utils/HttpClientExt.kt
index dffc98c05a..4fd16a0d1d 100644
--- a/core/datasource/src/main/java/com/tangem/datasource/utils/HttpClientExt.kt
+++ b/core/datasource/src/main/java/com/tangem/datasource/utils/HttpClientExt.kt
@@ -13,7 +13,7 @@ internal fun OkHttpClient.Builder.addHeaders(vararg requestHeaders: RequestHeade
val request = chain.request().newBuilder().apply {
requestHeaders
.flatMap(RequestHeader::values)
- .forEach { addHeader(it.first, it.second) }
+ .forEach { addHeader(it.first, it.second.invoke()) }
}.build()
chain.proceed(request)
diff --git a/core/datasource/src/main/java/com/tangem/datasource/utils/RequestHeader.kt b/core/datasource/src/main/java/com/tangem/datasource/utils/RequestHeader.kt
index 66d6c0f90b..5e5067746f 100644
--- a/core/datasource/src/main/java/com/tangem/datasource/utils/RequestHeader.kt
+++ b/core/datasource/src/main/java/com/tangem/datasource/utils/RequestHeader.kt
@@ -7,15 +7,15 @@ import com.tangem.lib.auth.AuthProvider
*
* @param pairs header name and header value pairs
*/
-sealed class RequestHeader(vararg pairs: Pair) {
+sealed class RequestHeader(vararg pairs: Pair String>) {
/** Header list */
- val values: List> = pairs.toList()
+ val values: List String>> = pairs.toList()
- object CacheControlHeader : RequestHeader("Cache-Control" to "max-age=600")
+ object CacheControlHeader : RequestHeader("Cache-Control" to { "max-age=600" })
class AuthenticationHeader(authProvider: AuthProvider) : RequestHeader(
- "card_public_key" to authProvider.getCardPublicKey(),
- "card_id" to authProvider.getCardId(),
+ "card_id" to { authProvider.getCardId() },
+ "card_public_key" to { authProvider.getCardPublicKey() },
)
}
\ No newline at end of file
diff --git a/core/res/src/main/res/values-de/strings.xml b/core/res/src/main/res/values-de/strings.xml
index 3e71b3a98a..93537cff03 100644
--- a/core/res/src/main/res/values-de/strings.xml
+++ b/core/res/src/main/res/values-de/strings.xml
@@ -12,6 +12,7 @@
Erledigt
OK
Änderungen speichern
+ Absenden
Erfolg
Zugangscode
Sie müssen den richtigen Zugangscode eingeben, bevor Sie die Karte scannen.
@@ -34,11 +35,7 @@
Der Betrag enthält nicht einige Ihrer Mittel
Betrag
Adresse
- Adresse oder PayString
Die Adresse stimmt mit der Adresse Ihrer Brieftasche überein
- PayString ist nicht registriert
- PayString-Anfrage ist fehlgeschlagen
- PayString wird von der Blockchain nicht unterstützt
Tag
Memo
inkl. Gebühr
@@ -48,7 +45,6 @@
Priorität
Höchstbetrag
Netzgebühr
- Absenden
Gesamt
%1$s und %2$s werden gesendet
≈ %1$s (inkl. Gebühr: %2$s)
@@ -57,11 +53,9 @@
Ungültige Adresse
Tangem Wallet
Tangem Twin
- PayString erstellen
Die Bilanz wird aufgeladen…
Die Transaktion läuft…
Verifizierte Bilanz
- Absenden
WalletConnect
Das Konto ist nicht erstellt
Diese Karte wird nicht unterstützt
diff --git a/core/res/src/main/res/values-fr/strings.xml b/core/res/src/main/res/values-fr/strings.xml
index 01059b36ff..529af080aa 100644
--- a/core/res/src/main/res/values-fr/strings.xml
+++ b/core/res/src/main/res/values-fr/strings.xml
@@ -12,6 +12,7 @@
Exécuté
OK
Sauvegarder les modifications
+ Envoyer
Avec succès
Code d\'accès
Vous devrez entrer le mot de passe correct avant de scanner la carte
@@ -34,11 +35,7 @@
Le montant n\'inclut pas certains de vos fonds
Somme
Adresse
- Adresse ou PayString
L\'adresse est la même que celle de votre portefeuille
- PayString non enregistré
- La demande de PayString a échoué
- PayString non pris en charge par la blockchain
Tag
Memo
Inclure les commissions
@@ -48,7 +45,6 @@
Priorité
Somme maximale
Commissions du réseau
- Envoyer
Total
Sera envoyé %1$s et %2$s
≈ %1$s (incl. les commissions : %2$s)
@@ -57,11 +53,9 @@
Adresse incorrecte
Tangem Wallet
Tangem Twin
- Créer PayString
Solde est en cours de téléchargement…
Transaction en cours…
Solde confirmé
- Envoyer
WalletConnect
Compte n\'est pas créé
Cette carte n\'est pas prise en charge
diff --git a/core/res/src/main/res/values-it/strings.xml b/core/res/src/main/res/values-it/strings.xml
index bc24145f51..3c294f6376 100644
--- a/core/res/src/main/res/values-it/strings.xml
+++ b/core/res/src/main/res/values-it/strings.xml
@@ -12,6 +12,7 @@
Fatto
OK
Mantieni le modifiche
+ Invia
Con successo
Codice di accesso
Prima di scansionare la carta sarà necessario inserire il codice di accesso corretto
@@ -34,11 +35,7 @@
L\'importo non include alcuni dei tuoi fondi
Importo
Indirizzo
- Indirizzo o PayString
L\'indirizzo corrisponde all\'indirizzo del tuo portafoglio
- PayString non registrato
- Richiesta PayString fallita
- PayString non supportato dalla blockchain
Tag
Memo
Includi commissione
@@ -48,7 +45,6 @@
Prioritario
Importo totale
Costi della rete
- Invia
Totale
Sarà inviato %1$s e %2$s
≈ %1$s (inc. commissione: %2$s)
@@ -57,11 +53,9 @@
Indirizzo non valido
Tangem Wallet
Tangem Twin
- Crea PayString
Il saldo sta per essere caricato…
Transazione in corso…
Saldo verificato
- Invia
WalletConnect
Conto non creato
Questa carta non è supportata
diff --git a/core/res/src/main/res/values-ru/strings.xml b/core/res/src/main/res/values-ru/strings.xml
index 57b1b1dcae..fb5043c0be 100644
--- a/core/res/src/main/res/values-ru/strings.xml
+++ b/core/res/src/main/res/values-ru/strings.xml
@@ -15,7 +15,7 @@
Эта карта не является платежным средством. В настоящее время мы не можем сопоставить количество подписей на карте с информацией в блокчейне. Это нормально, но в редких случаях может означать, что предыдущий владелец удерживает подписанную транзакцию от публикации, что является поводом для беспокойства.\nНе принимайте эту карту в качестве физического платежа от кого-то, кому вы не доверяете.\nВо всех остальных отношениях эта карта совершенно безопасна.\nTangem — единственный аппаратный кошелек, предлагающий защиту методом подсчета подписей.
У вас возникли трудности со сканированием карты?
Эта карта не предназначена для работы с этим приложением
- Перейдите в настройки, чтобы включить биометрическую аутентификацию в приложении Tangem App
+ Перейдите в настройки, чтобы включить биометрическую аутентификацию в приложении Tangem
Включите биометрическую аутентификацию
Все сохраненные коды доступа будут удалены. Вам потребуется вводить код доступа при работе с кошельком.
При отключении функции сохранения кошелька все ранее сохраненные кошельки будут удалены из приложения.
@@ -39,7 +39,7 @@
Восстановление кода доступа
Смена кода доступа
Код доступа будет изменен только на данной карте
- Сброс к заводским настройкам
+ Заводские настройки
Тип безопасности
Настройки карты
Tangem Bot
@@ -52,27 +52,41 @@
Баланс: %s
биометрическую аутентификацию
биометрией
+ Купить
Вы не предоставили доступ к камере, пожалуйста, измените настройки конфиденциальности.
Отмена
Закрыть
Копировать
+ Скопировать адрес
Создать
Удалить
Отключено
+ Не нравится
Готово
Включить
Включено
+ Обменять
+ Посмотреть историю транзакций
Обозреватель
+ Нравится
+ Основная сеть
Нет
- Ок
+ Нет данных
+ OK
Основная карта
+ Получить
Отклонить
+ Перезагрузить
Сохранить изменения
Искать
+ Секретная фраза
+ Продать
+ Отправить
Сервер недоступен, повторите попытку позднее
Поделиться
Подписать
Подписать и отправить
+ Стейкинг
Начать
Отправить
Успешно
@@ -81,6 +95,7 @@
Транзакции
Перевод
Я понял
+ Недоступно
Да
Адрес контракта скопирован!
Доступные сети
@@ -145,11 +160,22 @@
Приложите карту
Внутренняя ошибка: не удается найти менеджер кошельков
Вы обновили данные биометрии, отсканируйте свою карту для входа
+ Вы завершили обучение и можете получить свои токены 1inch
+ Получите бонус
+
+ - Пройдите обучение и получите %d токен 1inch на свой кошелек
+ - Пройдите обучение и получите %d токена 1inch на свой кошелек
+ - Пройдите обучение и получите %d токена 1inch на свой кошелек
+ - Пройдите обучение и получите %d токенов 1inch на свой кошелек
+
+ Бонус за обучение
Управление токенами
Чтобы защитить свои активы, мы советуем вам выполнить эту процедуру
Бэкап кошелька не был произведен
Баланс
В сумме учтены не все монеты
+ Токены 1inch будут зачислены на адрес вашего кошелька в течение 2 дней
+ По вашему промокоду не было покупки кошелька, а значит вы не можете получить бонус. Купите кошелек Tangem, отсканируйте его в приложении и получите бонус.
Чтобы получить доступ ко всем сетям, вам необходимо отсканировать карту
Отсканируйте карту
Вам необходимо установить единый код доступа для защиты всех ваших карт
@@ -173,11 +199,8 @@
Запросить
Перейти к моему кошельку
Завершение бэкапа
- Верифицировать (Utorg)
- Обновить
Установить Код доступа
Получить криптовалюту
- Зарегистрироваться
Сканировать основную карту
Пропустить
Как это работает?
@@ -192,19 +215,9 @@
В этом случае вам будет необходимо начать процесс заново.
Вы хотите выйти из процесса активации?
Подготовка
- Другой кошелек уже был создан на карте, которую вы пытаетесь добавить. Хотите сбросить его и использовать карту для бэкапа?
- Подтвердите свою личность
- Верификация клиента
Код доступа
Подключиться
Резервная копия
- Приложите SaltPay карту
- Для начала процесса бэкапа вам необходимо добавить Tangem карту
- Завершите процесс бэкапа создав код доступа
- Приложите Tangem карту
- Бэкап карта не добавлена
- Бэкап карта создана
- Приготовьте SaltPay карту
Читать про секретную фразу
Запишите эти 12 слов в порядке, указанном ниже, и сохраните их в надежном месте.
Ваша секретная фраза
@@ -220,13 +233,8 @@
Итак, проверим
Для начала работы просто запросите начисление wxDAI на свой кошелек
Это займет несколько секунд
- Более подробная информация отправлена на ваш адрес электронной почты.
- Для начала работы с картой вам необходимо завершить процесс подтверждения личности
- Пожалуйста дождитесь завершения процесса подтверждения личности. Вы будете уведомлены через e-mail. Обычно это занимает не более часа. Вы можете закрыть приложение и вернуться позже.
Чтобы начать процесс резервного копирования, добавьте одну или две резервные карты.
Вы можете добавить еще одну карту или завершить процесс резервного копирования
- Установите 4-х значный код.\nОн будет использован для платежей.
- Подключите вашу карту к децентрализованной платежной системе
Подготовьте резервную карту с номером %s
Подготовьте основную карту
Подготовьте основную карту с номером %s
@@ -237,13 +245,9 @@
Резервная карта #%d
Запросить %s
Запрашивается
- Что-то пошло не так
- Подтвердите свою личность
- Подтверждение личности в процессе
Нет резервных карт
Добавлена одна резервная карта
Код доступа
- Подключите свою карту
Подготовьте свою карту
Добавлены две резервные карты
Пополните кошелек на любую сумму, чтобы начать пользоваться картой
@@ -264,6 +268,9 @@
Группировка
По балансу
Сортировка токенов
+ Разгруппировать
+ %1$s %2$s адрес в сети %3$s
+ %1$s (%2$s) в сети %3$s
Участвовать
Не удалось загрузить информацию по реферальной программе. Пожалуйста, попробуйте позже.
Не удалось загрузить информацию по реферальной программе. Код ошибки: %s. Пожалуйста, попробуйте позже.
@@ -295,12 +302,6 @@
Сброс к заводским настройкам приведет к полному удалению кошелька с выбранной карты. Вы не сможете восстановить текущий кошелек.
У вас есть карта банка другой страны или платежной системы UnionPay?
Карты банков РФ в данный момент не принимаются
- Приложите карту с логотипом Visa
- Внимание
- Пожалуйста обратитесь в службу поддержки
- Недостаточно средств для активации
- Данный Код доступа может быть легко взломан
- Ввод одинаковых цифр является не безопасным
Войдите в приложение и следите за своим балансом без сканирования карты
Доступ в приложение
Использовать биометрию
@@ -317,11 +318,7 @@
Поиск валют
Сумма
Адрес
- Адрес или PayString
Адрес совпадает с адресом кошелька
- PayString не зарегистрирован
- Не удалось выполнить запрос PayString
- PayString не поддерживается блокчейном
Недопустимый Tag. Он не будет добавлен в транзакцию.
Недопустимый Memo. Он не будет добавлен в транзакцию.
Tag
@@ -333,7 +330,6 @@
Приоритетная
Максимальная сумма
Сетевая комиссия
- Отправить
Отправка %s
Всего
%1$s и %2$s будет отправлено
@@ -350,6 +346,7 @@
Сеть Solana взимает арендную плату в размере %1$s каждые 2 дня. Аккаунты, которые не могут позволить себе арендную плату, удаляются из сети. Пополните свой счет более чем на %2$s, чтобы не платить арендную плату.
Держите свои криптосбережения в безопасности. Приватные ключи надежно хранятся на карте.
Революционный аппаратный кошелек
+ До **трех карт** с одним кошельком
До
трех карт
с одним кошельком
@@ -358,6 +355,9 @@
Тысячи криптовалют
Используйте его на ходу, в любом месте, в любое время. Без проводов и батареек. Как только понадобится крипта, просто приложите карту к телефону.
Кошелек для каждого
+ Пройдите обучение и получите возможность купить кошелек Tangem со скидкой и токены 1inch в качестве бонуса
+ Пройти обучение
+ Получите свой бонус
Занимайте
Покупайте
Обменивайте
@@ -410,6 +410,7 @@
Скрыть токен
%1$s — это токен в сети %2$s. Чтобы отправить транзакцию %3$s, необходимо пополнить баланс %4$s (%5$s) для оплаты комиссии сети.
Пожалуйста, дождитесь завершения транзакции %s, чтобы иметь возможность отправить средства
+ %1$s токен в сети %%image%% %2$s
Токен %1$s является основной валютой в сети %2$s и не может быть скрыт до тех пор, пока у вас в списке есть другие токены этой сети.
Невозможно скрыть %s
Нет цены
@@ -424,6 +425,7 @@
Не удалось загрузить историю транзакций.\nНажмите на кнопку перезагрузки, чтобы обновить информацию.
История транзакций в настоящее время не поддерживается для этого блокчейна. Но не волнуйтесь, мы работаем над этим! А пока вы можете проверить ее в обозревателе.
от: %s
+ на: %s
В процессе…
Вы отсканировали ту же карту. Для создания twin-кошелька вам необходимо отсканировать карту с номером %d
Это карта, которую вы держите в руках. У парной карты номер %s.\n\nОбе карты можно использовать для вывода средств из этого кошелька.
@@ -445,7 +447,6 @@
Одновалютные
Мои кошельки
Разблокировать все с %s
- Создать PayString
История транзакций
Сеть недоступна
Блокчейн недоступен. Попробуй позже.
@@ -454,21 +455,26 @@
Транзакция подтверждается…
Подтвержденный баланс
Действия
- Купить
- Продать
- Отправить
Вы хотите купить или продать криптовалюту?
Запрос на подпись сообщения.\n\n%s
Dapp %1$s, запрос на\nподпись транзакции с BNB.\n\n%2$s
Торговый ордер на %1$s\nЦена: %2$s\nСумма к получению: %3$s\nСумма к оплате: %4$s
Детали транзакции:\nОт: %1$s\nК: %2$s\nСумма: %3$s
+ Транзакция с BNB успешно подписана и отправлена в Dapp.
Буфер обмена содержит код WalletConnect. Использовать скопированное значение или отсканировать QR-код
Запрос на создание транзакции для %1$s\n%2$s\n\nСумма: %3$s\nКомиссия: %4$s\nВсего: %5$s\nБаланс: %6$s
Невозможно отправить транзакцию. Недостаточно средств.
Не удалось установить сессию WalletConnect. Пожалуйста, повторите попытку позже.
+ Не все токены добавлены в ваш список. Пожалуйста, добавьте их в начале, а потом попробуйте снова. Недостающие токены: \n
+ Не удалось подписать сообщение.\nПожалуйста, попробуйте еще раз
Не удалось установить сессию WalletConnect за отведённое время. Пожалуйста, повторите попытку позже.
Запрос на подключение через WalletConnect содержит неподдерживаемые блокчеины. Неподдерживаемые блокчеины:\n
Cоединение с этим Dapp сервисом не может быть установлено из-за его технической реализации.
+ Произошла непредвиденная ошибка. Сообщение ошибки: %s Попробуйте, пожалуйста, позже. Если проблема будет продолжать возникать - обратитесь в службу поддержки.
+ Неверная карта выбрана в приложении Tangem
+ Не удалось создать транзакцию из данных Dapp. Код: %s
+ Произошла непредвиденная ошибка. Код ошибки: %d Попробуйте, пожалуйста, позже. Если проблема будет продолжать возникать - обратитесь в службу поддержки.
+ Сообщение было успешно подписано и отправлено в Dapp
Сеть %s не найдена. Пожалуйста, добавьте её и попробуйте заново.
Вставить из буфера обмена
Запрос на открытие сессии для\n%1$s\n\nСЕТЬ: %2$s\n\nURL: %3$s
@@ -477,8 +483,12 @@
Эту карту нельзя использовать с WalletConnect.
Сеть не поддерживается. Пожалуйста, выберите другую сеть.
Выберите сеть
+ Dapp не предоставил необходимые данные для открытия сессии WalletConnect
Подключение к Dapps
WalletConnect
+ Транзакция успешно подписана и отправлена в Dapp
+ Транзакция успешно подписана и отправлена в блокчейн
+ Не удалось найти хэш транзакции
Сеть %s
Аккаунт не создан
Эта карта не поддерживается
diff --git a/core/res/src/main/res/values-zh-rTW/strings.xml b/core/res/src/main/res/values-zh-rTW/strings.xml
index 597be9911d..ccb6abe736 100644
--- a/core/res/src/main/res/values-zh-rTW/strings.xml
+++ b/core/res/src/main/res/values-zh-rTW/strings.xml
@@ -46,23 +46,29 @@
餘額: %s
生物識別
生物
+ 購買
您尚未授予相機訪問權限,請更改您的隱私設置
刪除
關閉
複製
+ 複製地址
創造
刪除
禁用
+ 不喜歡
完成
允許
啟用
交易
+ 喜歡
否
OK
主卡片
拒絕
保存設置
搜索
+ 銷售
+ 發送
伺服器不可用,請稍後在試
分享
簽署
@@ -74,6 +80,7 @@
條款和條件
交易
我了解
+ 無法觸達
是
已複製代幣地址
支持的網路
@@ -164,11 +171,8 @@
獲取
繼續至我的錢包
完成備份過程
- 通過Utorg驗證
- 刷新
設置PIN碼
接收貨幣
- 註冊
掃描主卡
暫時略過
它是如何運作的?
@@ -183,18 +187,9 @@
這此情況,您必須要重新開始
您想要離開啟用程序嗎?
開始
- 驗證身分
- KYC
PIN 碼
連接
創建備份
- 點擊 SaltPay 卡
- 要開始備份過程,您必須添加 Tangem 卡片作為備份
- 通過創建訪問密碼完成備份
- 點擊 Tangem 卡片
- 沒有備份卡片
- 備份卡片已準備完成
- 準備SaltPay卡
閱讀更多關於助記詞的訊息
按照下面給出的順序寫下這 12 個單詞,並將它們存放在安全秘密的地方。
您的助記詞
@@ -210,13 +205,8 @@
那麼,讓我們檢查一下
要開始,只需將 wxDAI 獲取到您的錢包
這會花上幾秒
- 請查看Email已獲得更多指示
- 要開始使用您的卡,您必須通過 KYC驗證
- 請等待驗證完成,您將收到電子郵件通知。通常最多需要 1 小時。您可以關閉該應用程序,稍後再回來
要開始備份過程,最多可添加兩張備份卡。
您可以再添加一張卡或完成備份過程
- 設置一個 4 位密碼。 \n它將用在付款時使用。
- 將您的卡片連接到去中心化支付系統
準備編號為 %s 的備份卡
準備主卡
準備編號為 %s 的主卡
@@ -227,13 +217,9 @@
備份卡 #%d
獲取%s
獲取中
- 有東西出錯了
- 確認你的身分
- KYC 認證中
沒有備用卡
添加了一張備用卡
PIN 碼
- 連接你的錢包
準備好你的卡片
添加了兩張備用卡
要開始使用,只需為錢包充值任意金額
@@ -279,12 +265,6 @@
恢復原廠設置將從所選卡中完全刪除錢包並將其從應用程序中刪除。您將無法恢復當前錢包
您有其他國家的銀行卡或銀聯卡嗎?
目前不接受俄羅斯銀行卡
- 輕觸帶有 visa 標誌的卡片
- 注意
- 請聯繫客服
- 沒有激活資金
- 這樣的 PIN 很容易被暴力破解
- 四個相同的數字不安全
登錄應用程序並在不掃描卡片的情況下檢查您的資產
訪問應用程序
允許使用生物辨識
@@ -301,11 +281,7 @@
搜尋代幣
數量
地址
- 地址或 PayString
地址與錢包地址相同
- PayString 未註冊
- PayString 請求失敗
- PayString 不被區塊鏈支持
標籤無效。它不會被添加到交易中
Memo無效。 它不會被添加到交易中
Tag
@@ -317,7 +293,6 @@
優先
最大值
網路費
- 發送
發送 %s
總計
%1$s 和 %2$s 將被發送
@@ -333,6 +308,7 @@
Solana 網絡每 2 天收取 %1$s 的費用。無法付此費用的帳戶將從網絡中清除。向您的帳戶存入超過 %2$s 即可免費使用
安全地存儲您的加密貨幣,同時將私鑰保存在您的卡中
創新式的硬體錢包
+ 最多 **3張實體卡片** 到一個錢包
最多
3張實體卡片
到一個錢包
@@ -415,7 +391,6 @@
單一幣種
我的錢包
用 %s 解鎖全部
- 創建支付字符串
交易記錄
網路無法使用
區塊鍊無法使用。稍後再試
@@ -424,21 +399,26 @@
交易進行中
檢視餘額
動作
- 購買
- 銷售
- 發送
您想要購買或賣出交易貨幣?
請求籤署消息。%s
Dapp %1$s,請求\n簽署 BNB 交易。\n%2$s
%1$s 的交易訂單\n價格: %2$s\n接收金額:%3$s\n支付數量: %4$s
交易明細:\n從: %1$s\n到: %2$s\n數量: %3$s
+ BNB 交易已成功簽署並發送至 Dapp
剪貼板包含 WalletConnect 代碼。使用複制的值或掃描二維碼
請求為 %1$s 創建交易\n%2$s\n\n數量: %3$s\n費用: %4$s\n全部的: %5$s\n餘額: %6$s
無法交易,無足夠資金
未能建立 WalletConnect 連接。請稍後再試
+ 並非所有代幣都已添加到您的列表中。請先添加它們,然後重試。缺少標記:\n
+ 無法簽署消息。請重試
無法建立 WalletConnect 連接:超時錯誤。請稍後再試
- 會話請求包含不支持 WalletConnect 連接的區塊鏈。不支持的區塊鏈:
+ 會話請求包含不支持 WalletConnect 連接的區塊鏈。不支持的區塊鏈:\n
由於技術問題,無法與此 Dapp 建立連接
+ 我們遇到了未知錯誤。錯誤信息:%s。如果問題仍然存在-請隨時聯繫我們的客服人員
+ 在 Tangem App 中選擇了錯誤的卡
+ 無法從 Dapp 數據創建交易。代碼: %s
+ 我們遇到了未知錯誤。錯誤代碼:%d。如果問題仍然存在-請隨時聯繫我們的支持人員
+ 消息已成功簽名並發送至Dapp
沒有 %s 網路,請先加入後再試一次
從剪貼板貼上
請求開始會話\n%1$s\n\n網絡: %2$s\n\n網址:%3$s
@@ -447,8 +427,12 @@
此卡不能用於建立 WalletConnect 連接
不支持此網絡。請選擇其他網絡
選擇網路
+ Dapp 沒有提供必要的數據來建立 WalletConnect 連接
連結到Dapps
WalletConnect
+ 交易已成功簽署並發送至 Dapp
+ 交易已成功簽署並發送至區塊鏈
+ 未能找到交易哈希
%s 網路
帳號尚未被創造
不支持此卡
diff --git a/core/res/src/main/res/values/strings.xml b/core/res/src/main/res/values/strings.xml
index e68fd193bb..3c95aa8a19 100644
--- a/core/res/src/main/res/values/strings.xml
+++ b/core/res/src/main/res/values/strings.xml
@@ -50,27 +50,41 @@
Balance: %s
biometric authentication
biometrics
+ Buy
You have not given access to your camera, please adjust your privacy settings
Cancel
Close
Copy
+ Copy address
Create
Delete
Disabled
+ Dislike
Done
Enable
Enabled
+ Exchange
+ Explore transaction history
Explorer
+ Like
+ Main network
No
+ No data
OK
Primary Card
+ Receive
Reject
+ Reload
Save changes
Search
+ Seed phrase
+ Sell
+ Send
The server is not available, please try again later
Share
Sign
Sign and send
+ Stake
Start
Submit
Success
@@ -79,6 +93,7 @@
Transactions
Transfer
I understand
+ Unreachable
Yes
Contract address copied!
Available networks
@@ -143,11 +158,20 @@
Tap the card
Internal error: wallet manager not found
You have updated biometrics, scan your card to enter
+ You have completed the training and can get your 1inch tokens
+ Get a bonus
+
+ - Complete the training and get %d 1inch token on your wallet
+ - Complete the training and get %d 1inch tokens on your wallet
+
+ Learn & Earn
Manage tokens
To protect your assets, we advise you to carry out this procedure
Your wallet has not been backed up
Total balance
The amount does not include some of your funds
+ 1inch tokens will be credited to your wallet address within 2 days
+ There was no purchase of a wallet using your promo code, which means you cannot receive a bonus. Buy Tangem wallet, scan it in the app, and get the bonus.
To access all the networks you need to scan the card
Scan your card
You have to set up a single access code to protect all your wallets
@@ -171,11 +195,8 @@
Claim
Continue to my wallet
Finalize the backup
- Verify via Utorg
- Refresh
Set PIN code
Receive crypto
- Register
Scan primary card
Skip for later
How does it work?
@@ -191,18 +212,9 @@
Do you want to exit the activation process?
Getting started
Another wallet has already been created on the card you\'re trying to add. Do you want to reset it and use the card for a new wallet?
- Verify your identity
- KYC
Pin code
Connect
Creating a backup
- Tap the SaltPay card
- To start the backup process you have to add the Tangem card as your backup
- Finalize the backup process by creating an access code
- Tap the Tangem card
- No backup card
- Backup card ready
- Prepare the SaltPay card
Read more about seed phrases
Write these 12 words down in the order given below and store them in a safe and secret place.
Your secret phrase
@@ -218,13 +230,8 @@
So, let’s check
To get started, simply claim wxDAI to your wallet
It will take a few seconds
- Please check your email for further instructions
- To start using your card you have to pass the KYC process
- Please wait until the verification is completed. You\'ll be notified via email. Usually it takes up to 1 hour. You can close the app and come back later.
To start the backup process add up to two backup cards.
You can add one more card or finalize the backup process
- Set up a 4-digit code.\nIt will be used for payments.
- Connect your card to the decentralized payment system
Prepare the backup card with number %s
Prepare the primary card
Prepare the primary card with number %s
@@ -235,13 +242,9 @@
Backup card #%d
Claim %s
Claiming
- Something went wrong
- Verify your identity
- KYC is in progress
No backup cards
One backup card added
PIN Code
- Connect your card
Prepare your card
Two backup cards added
To get started, simply top up the wallet with any amount
@@ -262,6 +265,10 @@
Group
By balance
Organize tokens
+ Ungroup
+ %1$s %2$s address on %3$s network
+ %1$s (%2$s) on %3$s network
+ Send only %s to this address. Sending any other currency will result in its irreversible loss.
Participate
Failed to load the information about the referral program. Please try again later.
Failed to load the information about the referral program. Error code: %s. Please try again later.
@@ -291,12 +298,6 @@
Factory Reset will completely delete the wallet from the selected card and remove it from the app. You will not be able to restore the current wallet.
Do you have a bank card of another country or a UnionPay card?
Russian bank cards are not accepted at the moment
- Tap the card with the visa logo
- Attention
- Please contact support
- No funds for activation
- Such a PIN can be brute-forced easily
- Four identical digits isn\'t safe
Log into the app and check your balance without scanning the card
Access the app
Allow to use biometrics
@@ -313,11 +314,7 @@
Search tokens
Amount
Address
- Address or PayString
Address is the same as wallet address
- PayString not registered
- PayString request failed
- PayString unsupported by blockchain
Invalid Tag. It won\'t be added to the transaction.
Invalid Memo. It won\'t be added to the transaction.
Tag
@@ -329,7 +326,6 @@
Priority
Maximum amount
Network fee
- Send
Sending %s
Total
%1$s and %2$s will be sent
@@ -346,6 +342,7 @@
Solana network charges a rent of %1$s every 2 days. Accounts that can\'t afford the rent are purged from the network. Deposit your account with more than %2$s to use it for free.
Store your crypto assets secure while keeping private keys contained in your card
Revolutionary Hardware Wallet
+ Up to **3 physical cards** to one wallet
Up to
3 physical cards
to one wallet
@@ -354,6 +351,9 @@
Thousands of Currencies
Use it on the go, anywhere, anytime. No wires or batteries. Just tap the card to your phone when you need your crypto.
The Wallet for Everyone
+ Complete the training, get the opportunity to buy Tangem wallet with a discount and receive 1inch tokens on your wallet
+ Learn
+ Learn and get a bonus
Borrow
Buy
Exchange
@@ -404,6 +404,7 @@
Hide token
%1$s is a token in the %2$s network. To make a %3$s transaction you need to deposit some %4$s (%5$s) to cover the network fee.
Please wait for %s transaction to complete to be able to send funds
+ %1$s token in %%image%% %2$s network
The %1$s token is the main currency on the %2$s network and cannot be hidden as long as you have other tokens on this network in the list.
Unable to hide %s
No rate
@@ -438,7 +439,6 @@
Single-currency
My Wallets
Unlock all with %s
- Create PayString
Transaction history
Network is unreachable
Blockchain is unreachable. Try later
@@ -447,21 +447,26 @@
Transaction is in progress…
Verified Balance
Actions
- Buy
- Sell
- Send
Do you want to buy or sell crypto?
Requesting to sign a message.\n\n%s
Dapp %1$s, requesting to\nsign BNB transaction.\n\n%2$s
Trade order for %1$s\nPrice: %2$s\nAmount to receive: %3$s\nAmount to pay: %4$s
Transaction details:\nFrom: %1$s\nTo: %2$s\nAmount: %3$s
+ The BNB transaction has been successfully signed and sent to the Dapp
Clipboard contain WalletConnect code. Use copied value or scan QR-code
Request to create transaction for %1$s\n%2$s\n\nAmount: %3$s\nFee: %4$s\nTotal: %5$s\nBalance: %6$s
Can\'t send transaction. Not enough funds.
Failed to establish WalletConnect session. Please, try again later.
+ Not all tokens were added to your list. Please add them first and try again. Missing tokens:\n
+ Failed to sign message.\nPlease, try again
Failed to establish WalletConnect session: timeout error. Please, try again later.
Session request contains unsupported blockchains for WalletConnect connection. Unsupported blockchains:\n
Connection with this Dapp cannot be established due to its technical implementation.
+ We\'ve encountered unknown error. Error message: %s. If the problem persists — feel free to contact our support
+ Wrong card selected in Tangem App
+ Failed to create transaction from Dapp data. Code: %s
+ We\'ve encountered unknown error. Error code: %d. If the problem persists — feel free to contact our support
+ The message has been successfully signed and sent to the Dapp
%s network not found. Please, add it first and try again.
Paste from clipboard
Request to start a session for\n%1$s\n\nNETWORK: %2$s\n\nURL: %3$s
@@ -470,8 +475,12 @@
This card can\'t be used to establish WalletConnect session
This network is not supported. Please select another network.
Select network
+ Dapp didn\'t provide essential data to establish WalletConnect session
Connect to Dapps
WalletConnect
+ The transaction has been successfully signed and sent to the Dapp
+ The transaction has been succesfully signed and sent to the blockchain
+ Failed to find transaction hash
%s network
Account is not created
This card is not supported
diff --git a/core/ui/src/main/java/com/tangem/core/ui/components/Buttons.kt b/core/ui/src/main/java/com/tangem/core/ui/components/Buttons.kt
index 5ca9a16de8..11682ec1f1 100644
--- a/core/ui/src/main/java/com/tangem/core/ui/components/Buttons.kt
+++ b/core/ui/src/main/java/com/tangem/core/ui/components/Buttons.kt
@@ -2,19 +2,17 @@ package com.tangem.core.ui.components
import androidx.annotation.DrawableRes
import androidx.compose.foundation.background
-import androidx.compose.foundation.layout.*
-import androidx.compose.material.*
-import androidx.compose.runtime.*
-import androidx.compose.ui.Alignment
+import androidx.compose.foundation.layout.Arrangement
+import androidx.compose.foundation.layout.Column
+import androidx.compose.foundation.layout.fillMaxWidth
+import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
-import androidx.compose.ui.graphics.Color
-import androidx.compose.ui.graphics.Shape
-import androidx.compose.ui.res.painterResource
-import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.tooling.preview.Preview
-import androidx.compose.ui.unit.Dp
-import androidx.compose.ui.unit.dp
import com.tangem.core.ui.R
+import com.tangem.core.ui.components.buttons.common.TangemButton
+import com.tangem.core.ui.components.buttons.common.TangemButtonIconPosition
+import com.tangem.core.ui.components.buttons.common.TangemButtonSize
+import com.tangem.core.ui.components.buttons.common.TangemButtonsDefaults
import com.tangem.core.ui.res.TangemTheme
// region TextButton
@@ -26,7 +24,7 @@ fun TextButton(text: String, onClick: () -> Unit, modifier: Modifier = Modifier,
TangemButton(
modifier = modifier,
text = text,
- icon = TangemButtonIcon.None,
+ icon = TangemButtonIconPosition.None,
onClick = onClick,
enabled = enabled,
showProgress = false,
@@ -49,7 +47,7 @@ fun TextButtonIconStart(
TangemButton(
modifier = modifier,
text = text,
- icon = TangemButtonIcon.Start(iconResId),
+ icon = TangemButtonIconPosition.Start(iconResId),
onClick = onClick,
enabled = enabled,
showProgress = false,
@@ -63,7 +61,7 @@ fun WarningTextButton(text: String, onClick: () -> Unit, modifier: Modifier = Mo
TangemButton(
modifier = modifier,
text = text,
- icon = TangemButtonIcon.None,
+ icon = TangemButtonIconPosition.None,
onClick = onClick,
enabled = enabled,
showProgress = false,
@@ -85,7 +83,7 @@ fun PrimaryButton(
TangemButton(
modifier = modifier,
text = text,
- icon = TangemButtonIcon.None,
+ icon = TangemButtonIconPosition.None,
onClick = onClick,
colors = TangemButtonsDefaults.primaryButtonColors,
enabled = enabled,
@@ -108,7 +106,7 @@ fun PrimaryButtonIconEnd(
TangemButton(
modifier = modifier,
text = text,
- icon = TangemButtonIcon.End(iconResId),
+ icon = TangemButtonIconPosition.End(iconResId),
onClick = onClick,
colors = TangemButtonsDefaults.primaryButtonColors,
enabled = enabled,
@@ -131,7 +129,7 @@ fun PrimaryButtonIconStart(
TangemButton(
modifier = modifier,
text = text,
- icon = TangemButtonIcon.Start(iconResId),
+ icon = TangemButtonIconPosition.Start(iconResId),
onClick = onClick,
colors = TangemButtonsDefaults.primaryButtonColors,
enabled = enabled,
@@ -152,7 +150,7 @@ fun SecondaryButton(
TangemButton(
modifier = modifier,
text = text,
- icon = TangemButtonIcon.None,
+ icon = TangemButtonIconPosition.None,
onClick = onClick,
colors = TangemButtonsDefaults.secondaryButtonColors,
enabled = enabled,
@@ -175,7 +173,7 @@ fun SecondaryButtonIconEnd(
TangemButton(
modifier = modifier,
text = text,
- icon = TangemButtonIcon.End(iconResId),
+ icon = TangemButtonIconPosition.End(iconResId),
onClick = onClick,
colors = TangemButtonsDefaults.secondaryButtonColors,
enabled = enabled,
@@ -198,7 +196,7 @@ fun SecondaryButtonIconStart(
TangemButton(
modifier = modifier,
text = text,
- icon = TangemButtonIcon.Start(iconResId),
+ icon = TangemButtonIconPosition.Start(iconResId),
onClick = onClick,
colors = TangemButtonsDefaults.secondaryButtonColors,
enabled = enabled,
@@ -214,7 +212,7 @@ fun SelectorButton(text: String, onClick: () -> Unit, modifier: Modifier = Modif
modifier = modifier,
text = text,
textStyle = TangemTheme.typography.subtitle2,
- icon = TangemButtonIcon.End(iconResId = R.drawable.ic_chevron_24),
+ icon = TangemButtonIconPosition.End(iconResId = R.drawable.ic_chevron_24),
onClick = onClick,
colors = TangemButtonsDefaults.selectorButtonColors,
showProgress = false,
@@ -224,362 +222,6 @@ fun SelectorButton(text: String, onClick: () -> Unit, modifier: Modifier = Modif
}
// endregion Other
-// region Action
-
-/**
- * [Show in Figma](https://www.figma.com/file/14ISV23YB1yVW1uNVwqrKv/Android?type=design&node-id=290-305&t=3z98eFnTeyIx5TH5-4)
- * */
-@Composable
-fun RoundedActionButton(
- text: String,
- @DrawableRes iconResId: Int,
- onClick: () -> Unit,
- modifier: Modifier = Modifier,
- enabled: Boolean = true,
-) {
- TangemButton(
- modifier = modifier,
- text = text,
- icon = TangemButtonIcon.Start(iconResId),
- onClick = onClick,
- enabled = enabled,
- showProgress = false,
- colors = TangemButtonsDefaults.secondaryButtonColors,
- size = TangemButtonSize.RoundedAction,
- )
-}
-
-/**
- * [Show in Figma](https://www.figma.com/file/14ISV23YB1yVW1uNVwqrKv/Android?type=design&node-id=1208-1395&t=3z98eFnTeyIx5TH5-4)
- * */
-@Composable
-fun ActionButton(
- text: String,
- @DrawableRes iconResId: Int,
- onClick: () -> Unit,
- modifier: Modifier = Modifier,
- enabled: Boolean = true,
-) {
- TangemButton(
- modifier = modifier,
- text = text,
- icon = TangemButtonIcon.Start(iconResId),
- onClick = onClick,
- enabled = enabled,
- showProgress = false,
- colors = TangemButtonsDefaults.secondaryButtonColors,
- size = TangemButtonSize.Action,
- )
-}
-
-/**
- * Same as [RoundedActionButton] but colored in primary background color
- * */
-@Composable
-fun BackgroundActionButton(
- text: String,
- @DrawableRes iconResId: Int,
- onClick: () -> Unit,
- modifier: Modifier = Modifier,
- enabled: Boolean = true,
-) {
- TangemButton(
- modifier = modifier,
- text = text,
- icon = TangemButtonIcon.Start(iconResId),
- onClick = onClick,
- enabled = enabled,
- showProgress = false,
- colors = TangemButtonsDefaults.backgroundButtonColors,
- size = TangemButtonSize.RoundedAction,
- )
-}
-// endregion Action
-
-// region Defaults
-@Suppress("LongParameterList")
-@Composable
-private fun TangemButton(
- text: String,
- icon: TangemButtonIcon,
- onClick: () -> Unit,
- colors: ButtonColors,
- showProgress: Boolean,
- enabled: Boolean,
- modifier: Modifier = Modifier,
- size: TangemButtonSize = TangemButtonSize.Default,
- elevation: ButtonElevation = TangemButtonsDefaults.elevation,
- textStyle: TextStyle = TangemTheme.typography.button,
-) {
- Button(
- modifier = modifier.heightIn(min = size.toHeightDp()),
- onClick = { if (!showProgress) onClick() },
- enabled = enabled,
- elevation = elevation,
- shape = size.toShape(),
- colors = colors,
- contentPadding = size.toContentPadding(icon = icon),
- ) {
- ButtonContent(
- text = text,
- textStyle = textStyle,
- buttonIcon = icon,
- colors = colors,
- showProgress = showProgress,
- enabled = enabled,
- size = size,
- )
- }
-}
-
-@Suppress("LongParameterList")
-@Composable
-private fun ButtonContent(
- text: String,
- textStyle: TextStyle,
- buttonIcon: TangemButtonIcon,
- colors: ButtonColors,
- size: TangemButtonSize,
- enabled: Boolean,
- showProgress: Boolean,
-) {
- val icon = @Composable { iconResId: Int ->
- Icon(
- modifier = Modifier.size(TangemTheme.dimens.size20),
- painter = painterResource(id = iconResId),
- tint = colors.contentColor(enabled = enabled).value,
- contentDescription = null,
- )
- }
-
- if (showProgress) {
- Box(modifier = Modifier.wrapContentSize()) {
- CircularProgressIndicator(
- modifier = Modifier
- .align(Alignment.Center)
- .size(TangemTheme.dimens.size24),
- color = colors.contentColor(enabled = enabled).value,
- strokeWidth = TangemTheme.dimens.size4,
- )
- }
- } else {
- Row(
- verticalAlignment = Alignment.CenterVertically,
- horizontalArrangement = Arrangement.spacedBy(size.toIconPadding()),
- ) {
- if (buttonIcon is TangemButtonIcon.Start) {
- icon(buttonIcon.iconResId)
- }
- Text(
- text = text,
- style = textStyle,
- color = colors.contentColor(enabled = enabled).value,
- maxLines = 1,
- )
- if (buttonIcon is TangemButtonIcon.End) {
- icon(buttonIcon.iconResId)
- }
- }
- }
-}
-
-@Immutable
-private sealed interface TangemButtonIcon {
- val iconResId: Int?
-
- data class Start(override val iconResId: Int) : TangemButtonIcon
-
- data class End(override val iconResId: Int) : TangemButtonIcon
-
- object None : TangemButtonIcon {
- override val iconResId: Int? = null
- }
-}
-
-private enum class TangemButtonSize {
- Default,
- Text,
- Selector,
- Action,
- RoundedAction,
-}
-
-@Composable
-@ReadOnlyComposable
-private fun TangemButtonSize.toHeightDp(): Dp = when (this) {
- TangemButtonSize.Default -> TangemTheme.dimens.size48
- TangemButtonSize.Text -> TangemTheme.dimens.size40
- TangemButtonSize.Selector -> TangemTheme.dimens.size24
- TangemButtonSize.Action,
- TangemButtonSize.RoundedAction,
- -> TangemTheme.dimens.size36
-}
-
-@Composable
-@ReadOnlyComposable
-private fun TangemButtonSize.toShape(): Shape = when (this) {
- TangemButtonSize.Default -> TangemTheme.shapes.roundedCornersMedium
- TangemButtonSize.Text -> TangemTheme.shapes.roundedCornersSmall
- TangemButtonSize.Selector -> TangemTheme.shapes.roundedCornersSmall
- TangemButtonSize.Action -> TangemTheme.shapes.roundedCornersMedium
- TangemButtonSize.RoundedAction -> TangemTheme.shapes.roundedCornersLarge
-}
-
-@Composable
-@ReadOnlyComposable
-private fun TangemButtonSize.toIconPadding(): Dp = when (this) {
- TangemButtonSize.Default -> TangemTheme.dimens.spacing8
- TangemButtonSize.Text -> TangemTheme.dimens.spacing8
- TangemButtonSize.Selector -> 0.dp
- TangemButtonSize.Action,
- TangemButtonSize.RoundedAction,
- -> TangemTheme.dimens.spacing8
-}
-
-@Composable
-@ReadOnlyComposable
-private fun TangemButtonSize.toContentPadding(icon: TangemButtonIcon): PaddingValues {
- val horizontalPadding = this.toHorizontalContentPadding(icon = icon)
-
- return when (this) {
- TangemButtonSize.Default -> PaddingValues(
- top = TangemTheme.dimens.spacing14,
- bottom = TangemTheme.dimens.spacing14,
- start = horizontalPadding.first,
- end = horizontalPadding.second,
- )
- TangemButtonSize.Text -> PaddingValues(
- top = TangemTheme.dimens.spacing10,
- bottom = TangemTheme.dimens.spacing10,
- start = horizontalPadding.first,
- end = horizontalPadding.second,
- )
- TangemButtonSize.Selector -> PaddingValues(
- top = TangemTheme.dimens.spacing0_5,
- bottom = TangemTheme.dimens.spacing0_5,
- start = horizontalPadding.first,
- end = horizontalPadding.second,
- )
- TangemButtonSize.Action,
- TangemButtonSize.RoundedAction,
- -> PaddingValues(
- top = TangemTheme.dimens.spacing8,
- bottom = TangemTheme.dimens.spacing8,
- start = horizontalPadding.first,
- end = horizontalPadding.second,
- )
- }
-}
-
-@Composable
-@ReadOnlyComposable
-private fun TangemButtonSize.toHorizontalContentPadding(icon: TangemButtonIcon): Pair {
- return when (this) {
- TangemButtonSize.Default -> TangemTheme.dimens.spacing32 to TangemTheme.dimens.spacing32
- TangemButtonSize.Text -> when (icon) {
- is TangemButtonIcon.None -> TangemTheme.dimens.spacing16 to TangemTheme.dimens.spacing16
- is TangemButtonIcon.Start -> TangemTheme.dimens.spacing14 to TangemTheme.dimens.spacing16
- is TangemButtonIcon.End -> TangemTheme.dimens.spacing16 to TangemTheme.dimens.spacing14
- }
- TangemButtonSize.Selector -> TangemTheme.dimens.spacing0_5 to TangemTheme.dimens.spacing0_5
- TangemButtonSize.Action,
- TangemButtonSize.RoundedAction,
- -> when (icon) {
- is TangemButtonIcon.None -> TangemTheme.dimens.spacing24 to TangemTheme.dimens.spacing24
- is TangemButtonIcon.Start -> TangemTheme.dimens.spacing16 to TangemTheme.dimens.spacing24
- is TangemButtonIcon.End -> TangemTheme.dimens.spacing24 to TangemTheme.dimens.spacing16
- }
- }
-}
-
-private object TangemButtonsDefaults {
- val elevation: ButtonElevation
- @Composable get() = ButtonDefaults
- .elevation(
- defaultElevation = TangemTheme.dimens.elevation0,
- pressedElevation = TangemTheme.dimens.elevation0,
- )
-
- val primaryButtonColors: ButtonColors
- @Composable
- @ReadOnlyComposable
- get() = TangemButtonColors(
- backgroundColor = TangemTheme.colors.button.primary,
- contentColor = TangemTheme.colors.text.primary2,
- disabledBackgroundColor = TangemTheme.colors.button.disabled,
- disabledContentColor = TangemTheme.colors.text.disabled,
- )
-
- val secondaryButtonColors: ButtonColors
- @Composable
- @ReadOnlyComposable
- get() = TangemButtonColors(
- backgroundColor = TangemTheme.colors.button.secondary,
- contentColor = TangemTheme.colors.text.primary1,
- disabledBackgroundColor = TangemTheme.colors.button.disabled,
- disabledContentColor = TangemTheme.colors.text.disabled,
- )
-
- val defaultTextButtonColors: ButtonColors
- @Composable
- @ReadOnlyComposable
- get() = TangemButtonColors(
- backgroundColor = Color.Transparent,
- contentColor = TangemTheme.colors.text.secondary,
- disabledBackgroundColor = Color.Transparent,
- disabledContentColor = TangemTheme.colors.text.disabled,
- )
-
- val warningTextButtonColors: ButtonColors
- @Composable
- @ReadOnlyComposable
- get() = TangemButtonColors(
- backgroundColor = Color.Transparent,
- contentColor = TangemTheme.colors.text.warning,
- disabledBackgroundColor = Color.Transparent,
- disabledContentColor = TangemTheme.colors.text.disabled,
- )
-
- val selectorButtonColors: ButtonColors
- @Composable
- @ReadOnlyComposable
- get() = TangemButtonColors(
- backgroundColor = Color.Transparent,
- contentColor = TangemTheme.colors.text.tertiary,
- disabledBackgroundColor = Color.Transparent,
- disabledContentColor = TangemTheme.colors.text.disabled,
- )
-
- val backgroundButtonColors: ButtonColors
- @Composable
- @ReadOnlyComposable
- get() = TangemButtonColors(
- backgroundColor = TangemTheme.colors.background.primary,
- contentColor = TangemTheme.colors.text.primary1,
- disabledBackgroundColor = TangemTheme.colors.button.disabled,
- disabledContentColor = TangemTheme.colors.text.disabled,
- )
-}
-
-@Immutable
-private open class TangemButtonColors(
- private val backgroundColor: Color,
- private val contentColor: Color,
- private val disabledBackgroundColor: Color,
- private val disabledContentColor: Color,
-) : ButtonColors {
- @Composable
- override fun backgroundColor(enabled: Boolean): State {
- return rememberUpdatedState(newValue = if (enabled) backgroundColor else disabledBackgroundColor)
- }
-
- @Composable
- override fun contentColor(enabled: Boolean): State {
- return rememberUpdatedState(newValue = if (enabled) contentColor else disabledContentColor)
- }
-}
-// endregion Defaults
-
// region Preview
@Composable
private fun PrimaryButtonSample() {
@@ -730,34 +372,4 @@ private fun TextButtonPreview_DarkTheme() {
}
}
-@Composable
-private fun ActionButtonSample() {
- Column(
- modifier = Modifier.background(TangemTheme.colors.background.primary),
- verticalArrangement = Arrangement.spacedBy(TangemTheme.dimens.spacing8),
- ) {
- RoundedActionButton(text = "Send", iconResId = R.drawable.ic_arrow_up_24, onClick = { })
- ActionButton(text = "Send", iconResId = R.drawable.ic_arrow_up_24, onClick = { })
- BackgroundActionButton(text = "Send", iconResId = R.drawable.ic_arrow_up_24, onClick = { })
- RoundedActionButton(text = "Send", iconResId = R.drawable.ic_arrow_up_24, enabled = false, onClick = { })
- ActionButton(text = "Send", iconResId = R.drawable.ic_arrow_up_24, enabled = false, onClick = { })
- BackgroundActionButton(text = "Send", iconResId = R.drawable.ic_arrow_up_24, enabled = false, onClick = { })
- }
-}
-
-@Preview(showBackground = true, widthDp = 360)
-@Composable
-private fun ActionButtonPreview_LightTheme() {
- TangemTheme {
- ActionButtonSample()
- }
-}
-
-@Preview(showBackground = true, widthDp = 360)
-@Composable
-private fun ActionButtonPreview_DarkTheme() {
- TangemTheme(isDark = true) {
- ActionButtonSample()
- }
-}
// endregion Preview
\ No newline at end of file
diff --git a/core/ui/src/main/java/com/tangem/core/ui/components/Notifications.kt b/core/ui/src/main/java/com/tangem/core/ui/components/Notifications.kt
deleted file mode 100644
index e70f571b18..0000000000
--- a/core/ui/src/main/java/com/tangem/core/ui/components/Notifications.kt
+++ /dev/null
@@ -1,202 +0,0 @@
-package com.tangem.core.ui.components
-
-import androidx.annotation.DrawableRes
-import androidx.compose.foundation.Image
-import androidx.compose.foundation.clickable
-import androidx.compose.foundation.layout.*
-import androidx.compose.foundation.shape.RoundedCornerShape
-import androidx.compose.material.*
-import androidx.compose.runtime.Composable
-import androidx.compose.ui.Alignment
-import androidx.compose.ui.Modifier
-import androidx.compose.ui.graphics.Color
-import androidx.compose.ui.res.painterResource
-import androidx.compose.ui.tooling.preview.Preview
-import com.tangem.core.ui.R
-import com.tangem.core.ui.res.TangemTheme
-
-/**
- * Closable notification with custom icon
- * Child of parent component
- * @see Figma component
- *
- * Use to show banner with custom icon and possibility to close
- * i.e. Feedback notification
- *
- * @param title notification title
- * @param icon drawable res on icon
- * @param iconColor icon color
- * @param onClick callback on click
- * @param onCloseClick callback on close icon click
- */
-@Composable
-fun ClosableNotification(
- title: String,
- @DrawableRes icon: Int,
- iconColor: Color,
- onClick: (() -> Unit),
- onCloseClick: (() -> Unit),
-) {
- NotificationCardTemplate(onClick) {
- Icon(
- modifier = Modifier
- .size(TangemTheme.dimens.size20)
- .align(Alignment.CenterStart),
- painter = painterResource(id = icon),
- tint = iconColor,
- contentDescription = null,
- )
- Text(
- modifier = Modifier
- .padding(horizontal = TangemTheme.dimens.spacing28)
- .align(Alignment.CenterStart),
- text = title,
- color = TangemTheme.colors.text.primary1,
- style = TangemTheme.typography.subtitle2,
- )
- Icon(
- modifier = Modifier
- .size(TangemTheme.dimens.size20)
- .align(Alignment.CenterEnd)
- .clickable(onClick = onCloseClick),
- painter = painterResource(id = R.drawable.ic_close_24),
- contentDescription = null,
- tint = TangemTheme.colors.icon.informative,
- )
- }
-}
-
-/**
- * Notification component from Design system
- * There are few states for this component, but only one parent, see link below
- *
- * Use this for Notification with title, subtitle, clickable or not
- *
- * @param title notification title
- * @param subtitle notification subtitle
- * @param onClick click on notification, if its null then no chevron icon
- *
- * @see Figma component
- */
-@Composable
-fun WarningNotification(title: String, subtitle: String?, onClick: (() -> Unit)?) {
- NotificationCardTemplate(onClick) {
- Image(
- modifier = Modifier
- .size(TangemTheme.dimens.size20)
- .align(Alignment.CenterStart),
- painter = painterResource(id = R.drawable.img_attention_20),
- contentDescription = null,
- )
- Column(
- modifier = Modifier
- .padding(horizontal = TangemTheme.dimens.spacing28)
- .align(Alignment.CenterStart),
- ) {
- Text(
- text = title,
- color = TangemTheme.colors.text.primary1,
- style = TangemTheme.typography.subtitle2,
- )
- if (!subtitle.isNullOrEmpty()) {
- SpacerH2()
- Text(
- text = subtitle,
- color = TangemTheme.colors.text.tertiary,
- style = TangemTheme.typography.caption,
- )
- }
- }
- if (onClick != null) {
- Icon(
- modifier = Modifier
- .size(TangemTheme.dimens.size20)
- .align(Alignment.CenterEnd),
- painter = painterResource(id = R.drawable.ic_chevron_right_24),
- contentDescription = null,
- tint = TangemTheme.colors.icon.informative,
- )
- }
- }
-}
-
-@OptIn(ExperimentalMaterialApi::class)
-@Composable
-private fun NotificationCardTemplate(onClick: (() -> Unit)? = null, content: @Composable BoxScope.() -> Unit) {
- Surface(
- color = TangemTheme.colors.button.secondary,
- shape = RoundedCornerShape(TangemTheme.dimens.radius18),
- onClick = onClick ?: {},
- enabled = onClick != null,
- ) {
- Box(
- Modifier
- .padding(
- horizontal = TangemTheme.dimens.spacing12,
- vertical = TangemTheme.dimens.spacing8,
- )
- .wrapContentSize(),
- ) {
- content()
- }
- }
-}
-
-// region Preview
-
-@Composable
-private fun WarningNotificationPreview() {
- Column(modifier = Modifier.fillMaxWidth()) {
- WarningNotification(
- title = "Your wallet hasn’t been backed up",
- subtitle = "Lorem ipsum dolor sit amet, consectetur " +
- "adipiscing elit, sed do eiusmod tempor incididunt ut labore et...",
- onClick = {},
- )
- SpacerH32()
- WarningNotification(
- title = "Your wallet hasn’t been backed up",
- subtitle = null,
- onClick = {},
- )
- SpacerH32()
- WarningNotification(
- title = "Your wallet hasn’t been backed up",
- subtitle = "Lorem ipsum dolor sit amet, consectetur " +
- "adipiscing elit, sed do eiusmod tempor incididunt ut labore et...",
- onClick = null,
- )
- SpacerH32()
- WarningNotification(
- title = "Your wallet hasn’t been backed up",
- subtitle = null,
- onClick = null,
- )
- SpacerH32()
- ClosableNotification(
- title = "Like tangem app?",
- icon = R.drawable.ic_star_24,
- iconColor = TangemTheme.colors.icon.attention,
- onClick = {},
- onCloseClick = {},
- )
- }
-}
-
-@Preview(showBackground = true)
-@Composable
-private fun Preview_WarningNotification_InLightTheme() {
- TangemTheme(isDark = false) {
- WarningNotificationPreview()
- }
-}
-
-@Preview(showBackground = true)
-@Composable
-private fun Preview_WarningNotification_InDarkTheme() {
- TangemTheme(isDark = true) {
- WarningNotificationPreview()
- }
-}
-
-// endregion Preview
\ No newline at end of file
diff --git a/core/ui/src/main/java/com/tangem/core/ui/components/buttons/actions/ActionConfig.kt b/core/ui/src/main/java/com/tangem/core/ui/components/buttons/actions/ActionConfig.kt
new file mode 100644
index 0000000000..dbfc71c767
--- /dev/null
+++ b/core/ui/src/main/java/com/tangem/core/ui/components/buttons/actions/ActionConfig.kt
@@ -0,0 +1,20 @@
+package com.tangem.core.ui.components.buttons.actions
+
+import androidx.annotation.DrawableRes
+
+/**
+ * Action button config
+ *
+ * @property text text
+ * @property iconResId icon resource id
+ * @property onClick lambda be invoked when action component is clicked
+ * @property enabled enabled
+ *
+[REDACTED_AUTHOR]
+ */
+data class ActionConfig(
+ val text: String,
+ @DrawableRes val iconResId: Int,
+ val onClick: () -> Unit,
+ val enabled: Boolean = true,
+)
\ No newline at end of file
diff --git a/core/ui/src/main/java/com/tangem/core/ui/components/buttons/actions/Actions.kt b/core/ui/src/main/java/com/tangem/core/ui/components/buttons/actions/Actions.kt
new file mode 100644
index 0000000000..e755e7c8b9
--- /dev/null
+++ b/core/ui/src/main/java/com/tangem/core/ui/components/buttons/actions/Actions.kt
@@ -0,0 +1,96 @@
+package com.tangem.core.ui.components.buttons.actions
+
+import androidx.compose.foundation.layout.Column
+import androidx.compose.runtime.Composable
+import androidx.compose.ui.Modifier
+import androidx.compose.ui.tooling.preview.Preview
+import androidx.compose.ui.tooling.preview.PreviewParameter
+import androidx.compose.ui.tooling.preview.datasource.CollectionPreviewParameterProvider
+import com.tangem.core.ui.R
+import com.tangem.core.ui.components.buttons.common.TangemButton
+import com.tangem.core.ui.components.buttons.common.TangemButtonIconPosition
+import com.tangem.core.ui.components.buttons.common.TangemButtonSize
+import com.tangem.core.ui.components.buttons.common.TangemButtonsDefaults
+import com.tangem.core.ui.res.TangemTheme
+
+/**
+ * [Show in Figma](https://www.figma.com/file/14ISV23YB1yVW1uNVwqrKv/Android?type=design&node-id=290-305&t=3z98eFnTeyIx5TH5-4)
+ */
+@Composable
+fun RoundedActionButton(config: ActionConfig, modifier: Modifier = Modifier) {
+ TangemButton(
+ modifier = modifier,
+ text = config.text,
+ icon = TangemButtonIconPosition.Start(config.iconResId),
+ onClick = config.onClick,
+ enabled = config.enabled,
+ showProgress = false,
+ colors = TangemButtonsDefaults.secondaryButtonColors,
+ size = TangemButtonSize.RoundedAction,
+ )
+}
+
+/**
+ * [Show in Figma](https://www.figma.com/file/14ISV23YB1yVW1uNVwqrKv/Android?type=design&node-id=1208-1395&t=3z98eFnTeyIx5TH5-4)
+ */
+@Composable
+fun ActionButton(config: ActionConfig, modifier: Modifier = Modifier) {
+ TangemButton(
+ modifier = modifier,
+ text = config.text,
+ icon = TangemButtonIconPosition.Start(config.iconResId),
+ onClick = config.onClick,
+ enabled = config.enabled,
+ showProgress = false,
+ colors = TangemButtonsDefaults.secondaryButtonColors,
+ size = TangemButtonSize.Action,
+ )
+}
+
+/**
+ * Same as [RoundedActionButton] but colored in primary background color
+ */
+@Composable
+fun BackgroundActionButton(config: ActionConfig, modifier: Modifier = Modifier) {
+ TangemButton(
+ modifier = modifier,
+ text = config.text,
+ icon = TangemButtonIconPosition.Start(config.iconResId),
+ onClick = config.onClick,
+ enabled = config.enabled,
+ showProgress = false,
+ colors = TangemButtonsDefaults.backgroundButtonColors,
+ size = TangemButtonSize.RoundedAction,
+ )
+}
+
+@Preview(showBackground = true)
+@Composable
+private fun Preview_ActionButton_Light(@PreviewParameter(ActionStateProvider::class) state: ActionConfig) {
+ TangemTheme(isDark = false) {
+ Column {
+ RoundedActionButton(state)
+ ActionButton(state)
+ BackgroundActionButton(state)
+ }
+ }
+}
+
+@Preview(showBackground = true)
+@Composable
+private fun Preview_ActionButton_Dark(@PreviewParameter(ActionStateProvider::class) state: ActionConfig) {
+ TangemTheme {
+ Column {
+ RoundedActionButton(state)
+ ActionButton(state)
+ BackgroundActionButton(state)
+ }
+ }
+}
+
+private class ActionStateProvider : CollectionPreviewParameterProvider(
+ collection = listOf(
+ ActionConfig(text = "Send", iconResId = R.drawable.ic_arrow_up_24, onClick = {}),
+ ActionConfig(text = "Receive", iconResId = R.drawable.ic_arrow_down_24, enabled = false, onClick = {}),
+ ),
+)
\ No newline at end of file
diff --git a/core/ui/src/main/java/com/tangem/core/ui/components/buttons/common/TangemButton.kt b/core/ui/src/main/java/com/tangem/core/ui/components/buttons/common/TangemButton.kt
new file mode 100644
index 0000000000..b0a5b59116
--- /dev/null
+++ b/core/ui/src/main/java/com/tangem/core/ui/components/buttons/common/TangemButton.kt
@@ -0,0 +1,96 @@
+package com.tangem.core.ui.components.buttons.common
+
+import androidx.compose.foundation.layout.*
+import androidx.compose.material.*
+import androidx.compose.runtime.Composable
+import androidx.compose.ui.Alignment
+import androidx.compose.ui.Modifier
+import androidx.compose.ui.res.painterResource
+import androidx.compose.ui.text.TextStyle
+import com.tangem.core.ui.res.TangemTheme
+
+@Suppress("LongParameterList")
+@Composable
+internal fun TangemButton(
+ text: String,
+ icon: TangemButtonIconPosition,
+ onClick: () -> Unit,
+ colors: ButtonColors,
+ showProgress: Boolean,
+ enabled: Boolean,
+ modifier: Modifier = Modifier,
+ size: TangemButtonSize = TangemButtonSize.Default,
+ elevation: ButtonElevation = TangemButtonsDefaults.elevation,
+ textStyle: TextStyle = TangemTheme.typography.button,
+) {
+ Button(
+ modifier = modifier.heightIn(min = size.toHeightDp()),
+ onClick = { if (!showProgress) onClick() },
+ enabled = enabled,
+ elevation = elevation,
+ shape = size.toShape(),
+ colors = colors,
+ contentPadding = size.toContentPadding(icon = icon),
+ ) {
+ ButtonContent(
+ text = text,
+ textStyle = textStyle,
+ buttonIcon = icon,
+ colors = colors,
+ showProgress = showProgress,
+ enabled = enabled,
+ size = size,
+ )
+ }
+}
+
+@Suppress("LongParameterList")
+@Composable
+private fun ButtonContent(
+ text: String,
+ textStyle: TextStyle,
+ buttonIcon: TangemButtonIconPosition,
+ colors: ButtonColors,
+ size: TangemButtonSize,
+ enabled: Boolean,
+ showProgress: Boolean,
+) {
+ val icon = @Composable { iconResId: Int ->
+ Icon(
+ modifier = Modifier.size(TangemTheme.dimens.size20),
+ painter = painterResource(id = iconResId),
+ tint = colors.contentColor(enabled = enabled).value,
+ contentDescription = null,
+ )
+ }
+
+ if (showProgress) {
+ Box(modifier = Modifier.wrapContentSize()) {
+ CircularProgressIndicator(
+ modifier = Modifier
+ .align(Alignment.Center)
+ .size(TangemTheme.dimens.size24),
+ color = colors.contentColor(enabled = enabled).value,
+ strokeWidth = TangemTheme.dimens.size4,
+ )
+ }
+ } else {
+ Row(
+ verticalAlignment = Alignment.CenterVertically,
+ horizontalArrangement = Arrangement.spacedBy(size.toIconPadding()),
+ ) {
+ if (buttonIcon is TangemButtonIconPosition.Start) {
+ icon(buttonIcon.iconResId)
+ }
+ Text(
+ text = text,
+ style = textStyle,
+ color = colors.contentColor(enabled = enabled).value,
+ maxLines = 1,
+ )
+ if (buttonIcon is TangemButtonIconPosition.End) {
+ icon(buttonIcon.iconResId)
+ }
+ }
+ }
+}
\ No newline at end of file
diff --git a/core/ui/src/main/java/com/tangem/core/ui/components/buttons/common/TangemButtonColors.kt b/core/ui/src/main/java/com/tangem/core/ui/components/buttons/common/TangemButtonColors.kt
new file mode 100644
index 0000000000..92a334a139
--- /dev/null
+++ b/core/ui/src/main/java/com/tangem/core/ui/components/buttons/common/TangemButtonColors.kt
@@ -0,0 +1,25 @@
+package com.tangem.core.ui.components.buttons.common
+
+import androidx.compose.material.ButtonColors
+import androidx.compose.runtime.Composable
+import androidx.compose.runtime.State
+import androidx.compose.runtime.rememberUpdatedState
+import androidx.compose.ui.graphics.Color
+
+internal class TangemButtonColors(
+ private val backgroundColor: Color,
+ private val contentColor: Color,
+ private val disabledBackgroundColor: Color,
+ private val disabledContentColor: Color,
+) : ButtonColors {
+
+ @Composable
+ override fun backgroundColor(enabled: Boolean): State {
+ return rememberUpdatedState(newValue = if (enabled) backgroundColor else disabledBackgroundColor)
+ }
+
+ @Composable
+ override fun contentColor(enabled: Boolean): State {
+ return rememberUpdatedState(newValue = if (enabled) contentColor else disabledContentColor)
+ }
+}
\ No newline at end of file
diff --git a/core/ui/src/main/java/com/tangem/core/ui/components/buttons/common/TangemButtonIconPosition.kt b/core/ui/src/main/java/com/tangem/core/ui/components/buttons/common/TangemButtonIconPosition.kt
new file mode 100644
index 0000000000..0896e671fb
--- /dev/null
+++ b/core/ui/src/main/java/com/tangem/core/ui/components/buttons/common/TangemButtonIconPosition.kt
@@ -0,0 +1,16 @@
+package com.tangem.core.ui.components.buttons.common
+
+import androidx.annotation.DrawableRes
+
+internal sealed interface TangemButtonIconPosition {
+ val iconResId: Int?
+
+ data class Start(@DrawableRes override val iconResId: Int) : TangemButtonIconPosition
+
+ data class End(@DrawableRes override val iconResId: Int) : TangemButtonIconPosition
+
+ object None : TangemButtonIconPosition {
+ @DrawableRes
+ override val iconResId: Int? = null
+ }
+}
\ No newline at end of file
diff --git a/core/ui/src/main/java/com/tangem/core/ui/components/buttons/common/TangemButtonSize.kt b/core/ui/src/main/java/com/tangem/core/ui/components/buttons/common/TangemButtonSize.kt
new file mode 100644
index 0000000000..6ba9b10d72
--- /dev/null
+++ b/core/ui/src/main/java/com/tangem/core/ui/components/buttons/common/TangemButtonSize.kt
@@ -0,0 +1,105 @@
+package com.tangem.core.ui.components.buttons.common
+
+import androidx.compose.foundation.layout.PaddingValues
+import androidx.compose.runtime.Composable
+import androidx.compose.runtime.ReadOnlyComposable
+import androidx.compose.ui.graphics.Shape
+import androidx.compose.ui.unit.Dp
+import androidx.compose.ui.unit.dp
+import com.tangem.core.ui.res.TangemTheme
+
+internal enum class TangemButtonSize {
+ Default,
+ Text,
+ Selector,
+ Action,
+ RoundedAction,
+}
+
+@Composable
+@ReadOnlyComposable
+internal fun TangemButtonSize.toHeightDp(): Dp = when (this) {
+ TangemButtonSize.Default -> TangemTheme.dimens.size48
+ TangemButtonSize.Text -> TangemTheme.dimens.size40
+ TangemButtonSize.Selector -> TangemTheme.dimens.size24
+ TangemButtonSize.Action,
+ TangemButtonSize.RoundedAction,
+ -> TangemTheme.dimens.size36
+}
+
+@Composable
+@ReadOnlyComposable
+internal fun TangemButtonSize.toShape(): Shape = when (this) {
+ TangemButtonSize.Default -> TangemTheme.shapes.roundedCornersMedium
+ TangemButtonSize.Text -> TangemTheme.shapes.roundedCornersSmall
+ TangemButtonSize.Selector -> TangemTheme.shapes.roundedCornersSmall
+ TangemButtonSize.Action -> TangemTheme.shapes.roundedCornersMedium
+ TangemButtonSize.RoundedAction -> TangemTheme.shapes.roundedCornersLarge
+}
+
+@Composable
+@ReadOnlyComposable
+internal fun TangemButtonSize.toIconPadding(): Dp = when (this) {
+ TangemButtonSize.Default -> TangemTheme.dimens.spacing8
+ TangemButtonSize.Text -> TangemTheme.dimens.spacing8
+ TangemButtonSize.Selector -> 0.dp
+ TangemButtonSize.Action,
+ TangemButtonSize.RoundedAction,
+ -> TangemTheme.dimens.spacing8
+}
+
+@Composable
+@ReadOnlyComposable
+internal fun TangemButtonSize.toContentPadding(icon: TangemButtonIconPosition): PaddingValues {
+ val horizontalPadding = this.toHorizontalContentPadding(icon = icon)
+
+ return when (this) {
+ TangemButtonSize.Default -> PaddingValues(
+ top = TangemTheme.dimens.spacing14,
+ bottom = TangemTheme.dimens.spacing14,
+ start = horizontalPadding.first,
+ end = horizontalPadding.second,
+ )
+ TangemButtonSize.Text -> PaddingValues(
+ top = TangemTheme.dimens.spacing10,
+ bottom = TangemTheme.dimens.spacing10,
+ start = horizontalPadding.first,
+ end = horizontalPadding.second,
+ )
+ TangemButtonSize.Selector -> PaddingValues(
+ top = TangemTheme.dimens.spacing0_5,
+ bottom = TangemTheme.dimens.spacing0_5,
+ start = horizontalPadding.first,
+ end = horizontalPadding.second,
+ )
+ TangemButtonSize.Action,
+ TangemButtonSize.RoundedAction,
+ -> PaddingValues(
+ top = TangemTheme.dimens.spacing8,
+ bottom = TangemTheme.dimens.spacing8,
+ start = horizontalPadding.first,
+ end = horizontalPadding.second,
+ )
+ }
+}
+
+@Composable
+@ReadOnlyComposable
+internal fun TangemButtonSize.toHorizontalContentPadding(icon: TangemButtonIconPosition): Pair {
+ return when (this) {
+ TangemButtonSize.Default -> TangemTheme.dimens.spacing32 to TangemTheme.dimens.spacing32
+ TangemButtonSize.Text -> when (icon) {
+ is TangemButtonIconPosition.None -> TangemTheme.dimens.spacing16 to TangemTheme.dimens.spacing16
+ is TangemButtonIconPosition.Start -> TangemTheme.dimens.spacing14 to TangemTheme.dimens.spacing16
+ is TangemButtonIconPosition.End -> TangemTheme.dimens.spacing16 to TangemTheme.dimens.spacing14
+ }
+ TangemButtonSize.Selector -> TangemTheme.dimens.spacing0_5 to TangemTheme.dimens.spacing0_5
+ TangemButtonSize.Action,
+ TangemButtonSize.RoundedAction,
+ -> when (icon) {
+ is TangemButtonIconPosition.None -> TangemTheme.dimens.spacing24 to TangemTheme.dimens.spacing24
+ is TangemButtonIconPosition.Start -> TangemTheme.dimens.spacing16 to TangemTheme.dimens.spacing24
+ is TangemButtonIconPosition.End -> TangemTheme.dimens.spacing24 to TangemTheme.dimens.spacing16
+ }
+ }
+}
\ No newline at end of file
diff --git a/core/ui/src/main/java/com/tangem/core/ui/components/buttons/common/TangemButtonsDefaults.kt b/core/ui/src/main/java/com/tangem/core/ui/components/buttons/common/TangemButtonsDefaults.kt
new file mode 100644
index 0000000000..f6c6211dc5
--- /dev/null
+++ b/core/ui/src/main/java/com/tangem/core/ui/components/buttons/common/TangemButtonsDefaults.kt
@@ -0,0 +1,78 @@
+package com.tangem.core.ui.components.buttons.common
+
+import androidx.compose.material.ButtonColors
+import androidx.compose.material.ButtonDefaults
+import androidx.compose.material.ButtonElevation
+import androidx.compose.runtime.Composable
+import androidx.compose.runtime.ReadOnlyComposable
+import androidx.compose.ui.graphics.Color
+import com.tangem.core.ui.res.TangemTheme
+
+internal object TangemButtonsDefaults {
+
+ val elevation: ButtonElevation
+ @Composable get() = ButtonDefaults.elevation(
+ defaultElevation = TangemTheme.dimens.elevation0,
+ pressedElevation = TangemTheme.dimens.elevation0,
+ )
+
+ val primaryButtonColors: ButtonColors
+ @Composable
+ @ReadOnlyComposable
+ get() = TangemButtonColors(
+ backgroundColor = TangemTheme.colors.button.primary,
+ contentColor = TangemTheme.colors.text.primary2,
+ disabledBackgroundColor = TangemTheme.colors.button.disabled,
+ disabledContentColor = TangemTheme.colors.text.disabled,
+ )
+
+ val secondaryButtonColors: ButtonColors
+ @Composable
+ @ReadOnlyComposable
+ get() = TangemButtonColors(
+ backgroundColor = TangemTheme.colors.button.secondary,
+ contentColor = TangemTheme.colors.text.primary1,
+ disabledBackgroundColor = TangemTheme.colors.button.disabled,
+ disabledContentColor = TangemTheme.colors.text.disabled,
+ )
+
+ val defaultTextButtonColors: ButtonColors
+ @Composable
+ @ReadOnlyComposable
+ get() = TangemButtonColors(
+ backgroundColor = Color.Transparent,
+ contentColor = TangemTheme.colors.text.secondary,
+ disabledBackgroundColor = Color.Transparent,
+ disabledContentColor = TangemTheme.colors.text.disabled,
+ )
+
+ val warningTextButtonColors: ButtonColors
+ @Composable
+ @ReadOnlyComposable
+ get() = TangemButtonColors(
+ backgroundColor = Color.Transparent,
+ contentColor = TangemTheme.colors.text.warning,
+ disabledBackgroundColor = Color.Transparent,
+ disabledContentColor = TangemTheme.colors.text.disabled,
+ )
+
+ val selectorButtonColors: ButtonColors
+ @Composable
+ @ReadOnlyComposable
+ get() = TangemButtonColors(
+ backgroundColor = Color.Transparent,
+ contentColor = TangemTheme.colors.text.tertiary,
+ disabledBackgroundColor = Color.Transparent,
+ disabledContentColor = TangemTheme.colors.text.disabled,
+ )
+
+ val backgroundButtonColors: ButtonColors
+ @Composable
+ @ReadOnlyComposable
+ get() = TangemButtonColors(
+ backgroundColor = TangemTheme.colors.background.primary,
+ contentColor = TangemTheme.colors.text.primary1,
+ disabledBackgroundColor = TangemTheme.colors.button.disabled,
+ disabledContentColor = TangemTheme.colors.text.disabled,
+ )
+}
\ No newline at end of file
diff --git a/core/ui/src/main/java/com/tangem/core/ui/components/notifications/Notification.kt b/core/ui/src/main/java/com/tangem/core/ui/components/notifications/Notification.kt
new file mode 100644
index 0000000000..db338c9721
--- /dev/null
+++ b/core/ui/src/main/java/com/tangem/core/ui/components/notifications/Notification.kt
@@ -0,0 +1,171 @@
+package com.tangem.core.ui.components.notifications
+
+import androidx.annotation.DrawableRes
+import androidx.compose.foundation.Image
+import androidx.compose.foundation.layout.*
+import androidx.compose.foundation.shape.RoundedCornerShape
+import androidx.compose.material3.Icon
+import androidx.compose.material3.Surface
+import androidx.compose.material3.Text
+import androidx.compose.runtime.Composable
+import androidx.compose.ui.Alignment
+import androidx.compose.ui.Modifier
+import androidx.compose.ui.graphics.Color
+import androidx.compose.ui.res.painterResource
+import androidx.compose.ui.tooling.preview.Preview
+import androidx.compose.ui.tooling.preview.PreviewParameter
+import androidx.compose.ui.tooling.preview.datasource.CollectionPreviewParameterProvider
+import com.tangem.core.ui.R
+import com.tangem.core.ui.components.SpacerH2
+import com.tangem.core.ui.res.TangemColorPalette
+import com.tangem.core.ui.res.TangemTheme
+
+/**
+ * Notification component from Design system.
+ * Use this for Notification with title, subtitle, clickable or not.
+ *
+ * @param state component state
+ * @param modifier modifier
+ *
+ * @see Figma component
+ */
+@Composable
+fun Notification(state: NotificationState, modifier: Modifier = Modifier) {
+ Surface(
+ onClick = if (state is NotificationState.Action) {
+ state.onClick
+ } else {
+ {}
+ },
+ modifier = modifier,
+ enabled = when (state) {
+ is NotificationState.Simple -> false
+ is NotificationState.Action -> true
+ },
+ shape = RoundedCornerShape(TangemTheme.dimens.radius18),
+ color = TangemTheme.colors.button.secondary,
+ ) {
+ Box(
+ modifier = Modifier
+ .fillMaxWidth()
+ .padding(horizontal = TangemTheme.dimens.spacing12, vertical = TangemTheme.dimens.spacing8),
+ ) {
+ NotificationIcon(
+ iconResId = state.iconResId,
+ iconTint = state.tint,
+ modifier = Modifier
+ .size(size = TangemTheme.dimens.size20)
+ .align(alignment = Alignment.CenterStart),
+ )
+
+ NotificationInfoBlock(
+ title = state.title,
+ subtitle = state.subtitle,
+ modifier = Modifier.align(alignment = Alignment.CenterStart),
+ )
+
+ if (state is NotificationState.Action) {
+ Icon(
+ modifier = Modifier
+ .size(size = TangemTheme.dimens.size20)
+ .align(alignment = Alignment.CenterEnd),
+ painter = painterResource(id = R.drawable.ic_chevron_right_24),
+ contentDescription = null,
+ tint = TangemTheme.colors.icon.informative,
+ )
+ }
+ }
+ }
+}
+
+@Composable
+private fun NotificationIcon(@DrawableRes iconResId: Int, iconTint: Color?, modifier: Modifier = Modifier) {
+ if (iconTint != null) {
+ Icon(
+ painter = painterResource(id = iconResId),
+ contentDescription = null,
+ modifier = modifier,
+ tint = iconTint,
+ )
+ } else {
+ Image(
+ painter = painterResource(id = iconResId),
+ contentDescription = null,
+ modifier = modifier,
+ )
+ }
+}
+
+@Composable
+private fun NotificationInfoBlock(title: String, subtitle: String?, modifier: Modifier = Modifier) {
+ Column(modifier = modifier.padding(horizontal = TangemTheme.dimens.spacing30)) {
+ Text(
+ text = title,
+ color = TangemTheme.colors.text.primary1,
+ style = TangemTheme.typography.body2,
+ )
+
+ if (!subtitle.isNullOrEmpty()) {
+ SpacerH2()
+ Text(
+ text = subtitle,
+ color = TangemTheme.colors.text.tertiary,
+ style = TangemTheme.typography.caption,
+ )
+ }
+ }
+}
+
+@Preview
+@Composable
+private fun Preview_WarningNotification_Light(
+ @PreviewParameter(NotificationStateProvider::class)
+ state: NotificationState,
+) {
+ TangemTheme(isDark = false) {
+ Notification(state)
+ }
+}
+
+@Preview
+@Composable
+private fun Preview_WarningNotification_Dark(
+ @PreviewParameter(NotificationStateProvider::class)
+ state: NotificationState,
+) {
+ TangemTheme(isDark = true) {
+ Notification(state)
+ }
+}
+
+private class NotificationStateProvider : CollectionPreviewParameterProvider(
+ collection = listOf(
+ NotificationState.Simple(
+ title = "Your wallet hasn’t been backed up",
+ subtitle = "Lorem ipsum dolor sit amet, consectetur " +
+ "adipiscing elit, sed do eiusmod tempor incididunt ut labore et...",
+ iconResId = R.drawable.img_attention_20,
+ ),
+ NotificationState.Simple(
+ title = "Your wallet hasn’t been backed up",
+ subtitle = null,
+ iconResId = R.drawable.ic_alert_circle_24,
+ tint = TangemColorPalette.Amaranth,
+ ),
+ NotificationState.Action(
+ title = "Your wallet hasn’t been backed up",
+ subtitle = "Lorem ipsum dolor sit amet, consectetur " +
+ "adipiscing elit, sed do eiusmod tempor incididunt ut labore et...",
+ iconResId = R.drawable.img_attention_20,
+ onClick = {},
+ ),
+ NotificationState.Action(
+ title = "Your wallet hasn’t been backed up",
+ subtitle = null,
+ iconResId = R.drawable.ic_alert_circle_24,
+ tint = TangemColorPalette.Amaranth,
+ onClick = {},
+ ),
+ ),
+)
\ No newline at end of file
diff --git a/core/ui/src/main/java/com/tangem/core/ui/components/notifications/NotificationState.kt b/core/ui/src/main/java/com/tangem/core/ui/components/notifications/NotificationState.kt
new file mode 100644
index 0000000000..065fa1e125
--- /dev/null
+++ b/core/ui/src/main/java/com/tangem/core/ui/components/notifications/NotificationState.kt
@@ -0,0 +1,54 @@
+package com.tangem.core.ui.components.notifications
+
+import androidx.annotation.DrawableRes
+import androidx.compose.ui.graphics.Color
+
+/**
+ * Notification component state
+ *
+ * @property title title
+ * @property subtitle subtitle
+ * @property iconResId icon resource id
+ * @property tint icon tint
+ *
+[REDACTED_AUTHOR]
+ */
+sealed class NotificationState(
+ open val title: String,
+ open val subtitle: String? = null,
+ @DrawableRes open val iconResId: Int,
+ open val tint: Color? = null,
+) {
+
+ /**
+ * Simple notification state. Non clickable.
+ *
+ * @property title title
+ * @property subtitle subtitle
+ * @property iconResId icon resource id
+ * @property tint icon tint
+ */
+ data class Simple(
+ override val title: String,
+ override val subtitle: String? = null,
+ @DrawableRes override val iconResId: Int,
+ override val tint: Color? = null,
+ ) : NotificationState(title, subtitle, iconResId, tint)
+
+ /**
+ * Clickable notification state
+ *
+ * @property title title
+ * @property subtitle subtitle
+ * @property iconResId icon resource id
+ * @property tint icon tint
+ * @param onClick lambda be invoked when notification component is clicked
+ */
+ data class Action(
+ override val title: String,
+ override val subtitle: String? = null,
+ @DrawableRes override val iconResId: Int,
+ override val tint: Color? = null,
+ val onClick: () -> Unit,
+ ) : NotificationState(title, subtitle, iconResId, tint)
+}
\ No newline at end of file
diff --git a/core/ui/src/main/java/com/tangem/core/ui/extensions/TextReference.kt b/core/ui/src/main/java/com/tangem/core/ui/extensions/TextReference.kt
index a27dcb58c4..92df3daeb9 100644
--- a/core/ui/src/main/java/com/tangem/core/ui/extensions/TextReference.kt
+++ b/core/ui/src/main/java/com/tangem/core/ui/extensions/TextReference.kt
@@ -1,9 +1,11 @@
package com.tangem.core.ui.extensions
+import androidx.annotation.PluralsRes
import androidx.annotation.StringRes
import androidx.compose.runtime.Composable
import androidx.compose.runtime.Immutable
import androidx.compose.runtime.ReadOnlyComposable
+import androidx.compose.ui.res.pluralStringResource
import androidx.compose.ui.res.stringResource
/**
@@ -24,6 +26,8 @@ sealed interface TextReference {
*/
data class Res(@StringRes val id: Int, val formatArgs: WrappedList = WrappedList(emptyList())) : TextReference
+ data class PluralRes(@PluralsRes val id: Int, val count: Int, val formatArgs: WrappedList) : TextReference
+
/**
* Text string
*
@@ -38,6 +42,7 @@ sealed interface TextReference {
fun TextReference.resolveReference(): String {
return when (this) {
is TextReference.Res -> stringResource(id, *formatArgs.toTypedArray())
+ is TextReference.PluralRes -> pluralStringResource(id, count, *formatArgs.toTypedArray())
is TextReference.Str -> value
}
}
\ No newline at end of file
diff --git a/core/ui/src/main/java/com/tangem/core/ui/res/TangemDimens.kt b/core/ui/src/main/java/com/tangem/core/ui/res/TangemDimens.kt
index 421c82c9e1..8c85ac6339 100644
--- a/core/ui/src/main/java/com/tangem/core/ui/res/TangemDimens.kt
+++ b/core/ui/src/main/java/com/tangem/core/ui/res/TangemDimens.kt
@@ -76,6 +76,7 @@ data class TangemDimens internal constructor(
val size200: Dp = 200.dp,
// endregion Size
// region Spacing
+ val spacing0: Dp = 0.dp,
val spacing0_5: Dp = 0.5.dp,
val spacing2: Dp = 2.dp,
val spacing4: Dp = 4.dp,
@@ -91,6 +92,7 @@ data class TangemDimens internal constructor(
val spacing24: Dp = 24.dp,
val spacing26: Dp = 26.dp,
val spacing28: Dp = 28.dp,
+ val spacing30: Dp = 30.dp,
val spacing32: Dp = 32.dp,
val spacing34: Dp = 34.dp,
val spacing36: Dp = 34.dp,
diff --git a/core/utils/src/main/java/com/tangem/utils/extensions/Any.kt b/core/utils/src/main/java/com/tangem/utils/extensions/Any.kt
new file mode 100644
index 0000000000..a4847c4bc2
--- /dev/null
+++ b/core/utils/src/main/java/com/tangem/utils/extensions/Any.kt
@@ -0,0 +1,10 @@
+package com.tangem.utils.extensions
+
+import java.lang.ref.WeakReference
+
+/**
+[REDACTED_AUTHOR]
+ */
+fun T.toWeakReference(): WeakReference {
+ return WeakReference(this)
+}
\ No newline at end of file
diff --git a/data/source/preferences/src/main/kotlin/com/tangem/data/source/preferences/storage/UsedCardsPrefStorage.kt b/data/source/preferences/src/main/kotlin/com/tangem/data/source/preferences/storage/UsedCardsPrefStorage.kt
index b1fbf61361..de987e84fc 100644
--- a/data/source/preferences/src/main/kotlin/com/tangem/data/source/preferences/storage/UsedCardsPrefStorage.kt
+++ b/data/source/preferences/src/main/kotlin/com/tangem/data/source/preferences/storage/UsedCardsPrefStorage.kt
@@ -68,6 +68,10 @@ class UsedCardsPrefStorage internal constructor(
return cardInfo.isActivationStarted && !cardInfo.isActivationFinished
}
+ fun hadFinishedActivation(): Boolean {
+ return restore().any { it.isActivationFinished }
+ }
+
private fun findCardInfo(
cardId: String,
list: MutableList? = null,
diff --git a/domain/legacy/src/main/java/com/tangem/domain/redux/global/DomainGlobalHub.kt b/domain/legacy/src/main/java/com/tangem/domain/redux/global/DomainGlobalHub.kt
index 37f01870cc..f22a14aa64 100644
--- a/domain/legacy/src/main/java/com/tangem/domain/redux/global/DomainGlobalHub.kt
+++ b/domain/legacy/src/main/java/com/tangem/domain/redux/global/DomainGlobalHub.kt
@@ -36,6 +36,7 @@ private class DomainGlobalReducer : ReStoreReducer {
return when (action) {
is DomainGlobalAction.SaveScanNoteResponse -> {
val card = action.scanResponse.card
+ // TODO: AuthHeaders: try to remove it, because now we can use headers with dynamic values
state.networkServices.tangemTechService.addAuthenticationHeader(
RequestHeader.AuthenticationHeader(
object : AuthProvider {
diff --git a/features/learn2earn/api/.gitignore b/features/learn2earn/api/.gitignore
new file mode 100644
index 0000000000..42afabfd2a
--- /dev/null
+++ b/features/learn2earn/api/.gitignore
@@ -0,0 +1 @@
+/build
\ No newline at end of file
diff --git a/features/learn2earn/api/build.gradle.kts b/features/learn2earn/api/build.gradle.kts
new file mode 100644
index 0000000000..7ff7fb7522
--- /dev/null
+++ b/features/learn2earn/api/build.gradle.kts
@@ -0,0 +1,4 @@
+plugins {
+ alias(deps.plugins.kotlin.jvm)
+ id("configuration")
+}
\ No newline at end of file
diff --git a/features/learn2earn/impl/.gitignore b/features/learn2earn/impl/.gitignore
new file mode 100644
index 0000000000..42afabfd2a
--- /dev/null
+++ b/features/learn2earn/impl/.gitignore
@@ -0,0 +1 @@
+/build
\ No newline at end of file
diff --git a/features/learn2earn/impl/build.gradle.kts b/features/learn2earn/impl/build.gradle.kts
new file mode 100644
index 0000000000..b1c4ef9a5a
--- /dev/null
+++ b/features/learn2earn/impl/build.gradle.kts
@@ -0,0 +1,55 @@
+plugins {
+ alias(deps.plugins.android.library)
+ alias(deps.plugins.kotlin.android)
+ alias(deps.plugins.kotlin.kapt)
+ alias(deps.plugins.kotlin.serialization)
+ alias(deps.plugins.hilt.android)
+ id("configuration")
+}
+
+dependencies {
+ /** Core modules */
+ implementation(project(":common"))
+ implementation(project(":core:featuretoggles"))
+ implementation(project(":core:datasource"))
+ implementation(project(":core:utils"))
+ implementation(project(":core:ui"))
+ implementation(project(":core:res"))
+ implementation(project(":data:source:preferences"))
+ implementation(project(":libs:auth"))
+ implementation(project(":libs:crypto"))
+
+ implementation(deps.material)
+
+ /** AndroidX */
+ implementation(deps.androidx.core.ktx)
+ implementation(deps.androidx.appCompat)
+ implementation(deps.androidx.fragment.ktx)
+ implementation(deps.androidx.activity.compose)
+ implementation(deps.androidx.browser)
+
+ /** Compose */
+ implementation(deps.compose.material)
+ implementation(deps.compose.material3)
+ implementation(deps.compose.foundation)
+ implementation(deps.compose.ui)
+ implementation(deps.compose.ui.tooling)
+
+ /** Preferences */
+ implementation(deps.krateSharedPref)
+
+ /** Network */
+ implementation(deps.moshi)
+ implementation(deps.moshi.kotlin)
+ implementation(deps.retrofit)
+ implementation(deps.retrofit.moshi)
+
+ /** Other libraries */
+ implementation(deps.kotlin.immutable.collections)
+ implementation(deps.kotlin.serialization)
+ implementation(deps.timber)
+
+ /** DI */
+ implementation(deps.hilt.android)
+ kapt(deps.hilt.kapt)
+}
\ No newline at end of file
diff --git a/features/learn2earn/impl/src/main/AndroidManifest.xml b/features/learn2earn/impl/src/main/AndroidManifest.xml
new file mode 100644
index 0000000000..472f44a1a5
--- /dev/null
+++ b/features/learn2earn/impl/src/main/AndroidManifest.xml
@@ -0,0 +1,3 @@
+
+
+
\ No newline at end of file
diff --git a/features/learn2earn/impl/src/main/java/com/tangem/feature/learn2earn/data/DefaultLearn2earnRepository.kt b/features/learn2earn/impl/src/main/java/com/tangem/feature/learn2earn/data/DefaultLearn2earnRepository.kt
new file mode 100644
index 0000000000..c10f0d57bb
--- /dev/null
+++ b/features/learn2earn/impl/src/main/java/com/tangem/feature/learn2earn/data/DefaultLearn2earnRepository.kt
@@ -0,0 +1,137 @@
+package com.tangem.feature.learn2earn.data
+
+import com.squareup.moshi.Moshi
+import com.tangem.datasource.api.promotion.PromotionApi
+import com.tangem.datasource.api.promotion.models.*
+import com.tangem.feature.learn2earn.data.api.Learn2earnPreferenceStorage
+import com.tangem.feature.learn2earn.data.api.Learn2earnRepository
+import com.tangem.feature.learn2earn.data.models.PromoUserData
+import com.tangem.utils.coroutines.AppCoroutineDispatcherProvider
+import kotlinx.coroutines.withContext
+import timber.log.Timber
+
+/**
+[REDACTED_AUTHOR]
+ */
+internal class DefaultLearn2earnRepository(
+ private val preferencesStorage: Learn2earnPreferenceStorage,
+ private val api: PromotionApi,
+ private val dispatchers: AppCoroutineDispatcherProvider,
+ moshi: Moshi,
+) : Learn2earnRepository {
+
+ private val promotionInfoAdapter = moshi.adapter(PromotionInfoResponse::class.java)
+ private val userDataAdapter = moshi.adapter(PromoUserData::class.java)
+
+ private var userData: PromoUserData = restoreUserData()
+
+ override fun getUserData(): PromoUserData {
+ return userData
+ }
+
+ override fun updateUserData(userData: PromoUserData) {
+ this.userData = userData
+ saveUserData(userData)
+ }
+
+ override fun getProgramName(): String {
+ return PROGRAM_NAME
+ }
+
+ override suspend fun getPromotionInfo(): Result {
+ return withContext(dispatchers.io) {
+ val promotionInfo = restorePromotionInfo()
+ val data = promotionInfo?.getData(userData.promoCode)
+ if (data?.status == PromotionInfoResponse.Status.FINISHED) {
+ Result.success(promotionInfo)
+ } else {
+ runCatching { api.getPromotionInfo(getProgramName()) }
+ .fold(
+ onSuccess = { infoResponse ->
+ savePromotionInfo(infoResponse)
+ Result.success(infoResponse)
+ },
+ onFailure = { exception -> Result.failure(exception) },
+ )
+ }
+ }
+ }
+
+ override suspend fun validate(walletId: String): ValidateResponse {
+ return withContext(dispatchers.io) {
+ api.validate(ValidateRequestBody(walletId, getProgramName()))
+ }
+ }
+
+ override suspend fun requestAward(walletId: String, address: String): AwardResponse {
+ return withContext(dispatchers.io) {
+ api.requestAward(AwardRequestBody(walletId, address, getProgramName()))
+ }
+ }
+
+ override suspend fun validateCode(walletId: String, code: String?): CodeValidateResponse {
+ return withContext(dispatchers.io) {
+ api.validateCode(CodeValidateRequestBody(walletId, code))
+ }
+ }
+
+ override suspend fun requestAwardByCode(walletId: String, address: String, code: String?): CodeAwardResponse {
+ return withContext(dispatchers.io) {
+ api.requestAwardByCode(CodeAwardRequestBody(walletId, address, code))
+ }
+ }
+
+ private fun restorePromotionInfo(): PromotionInfoResponse? {
+ return try {
+ preferencesStorage.promotionInfo?.let { promotionInfoAdapter.fromJson(it) }
+ } catch (ex: Exception) {
+ Timber.e(ex)
+ preferencesStorage.promotionInfo = null
+ null
+ }
+ }
+
+ private fun savePromotionInfo(infoResponse: PromotionInfoResponse) {
+ try {
+ preferencesStorage.promotionInfo = promotionInfoAdapter.toJson(infoResponse)
+ } catch (ex: Exception) {
+ Timber.e(ex)
+ }
+ }
+
+ private fun restoreUserData(): PromoUserData {
+ return try {
+ preferencesStorage.userData?.let { userDataAdapter.fromJson(it) }
+ ?: createEmptyUserData().apply { saveUserData(this) }
+ } catch (ex: Exception) {
+ Timber.e(ex)
+ createEmptyUserData().apply { saveUserData(this) }
+ }
+ }
+
+ private fun saveUserData(userData: PromoUserData) {
+ try {
+ preferencesStorage.userData = userDataAdapter.toJson(userData)
+ } catch (ex: Exception) {
+ Timber.e(ex)
+ }
+ }
+
+ private fun createEmptyUserData(): PromoUserData = PromoUserData(
+ promoCode = null,
+ isRegisteredInPromotion = false,
+ isAlreadyReceivedAward = false,
+ )
+
+ private companion object {
+ const val PROGRAM_NAME: String = "1inch"
+ }
+}
+
+private fun PromotionInfoResponse.getData(promoCode: String?): PromotionInfoResponse.Data? {
+ return if (promoCode == null) {
+ newCard
+ } else {
+ oldCard
+ }
+}
\ No newline at end of file
diff --git a/features/learn2earn/impl/src/main/java/com/tangem/feature/learn2earn/data/DefaultPreferenceStorage.kt b/features/learn2earn/impl/src/main/java/com/tangem/feature/learn2earn/data/DefaultPreferenceStorage.kt
new file mode 100644
index 0000000000..4c3e39b9ae
--- /dev/null
+++ b/features/learn2earn/impl/src/main/java/com/tangem/feature/learn2earn/data/DefaultPreferenceStorage.kt
@@ -0,0 +1,19 @@
+package com.tangem.feature.learn2earn.data
+
+import android.content.Context
+import com.tangem.feature.learn2earn.data.api.Learn2earnPreferenceStorage
+import hu.autsoft.krate.SimpleKrate
+import hu.autsoft.krate.default.withDefault
+import hu.autsoft.krate.stringPref
+
+/**
+[REDACTED_AUTHOR]
+ */
+internal class DefaultPreferenceStorage(
+ context: Context,
+) : SimpleKrate(context = context, name = "Lear2earnPromotion"), Learn2earnPreferenceStorage {
+
+ override var promotionInfo: String? by stringPref().withDefault(null)
+
+ override var userData: String? by stringPref().withDefault(null)
+}
\ No newline at end of file
diff --git a/features/learn2earn/impl/src/main/java/com/tangem/feature/learn2earn/data/api/Learn2earnPreferenceStorage.kt b/features/learn2earn/impl/src/main/java/com/tangem/feature/learn2earn/data/api/Learn2earnPreferenceStorage.kt
new file mode 100644
index 0000000000..8c8840bb74
--- /dev/null
+++ b/features/learn2earn/impl/src/main/java/com/tangem/feature/learn2earn/data/api/Learn2earnPreferenceStorage.kt
@@ -0,0 +1,11 @@
+package com.tangem.feature.learn2earn.data.api
+
+/**
+[REDACTED_AUTHOR]
+ */
+interface Learn2earnPreferenceStorage {
+
+ var promotionInfo: String?
+
+ var userData: String?
+}
\ No newline at end of file
diff --git a/features/learn2earn/impl/src/main/java/com/tangem/feature/learn2earn/data/api/Learn2earnRepository.kt b/features/learn2earn/impl/src/main/java/com/tangem/feature/learn2earn/data/api/Learn2earnRepository.kt
new file mode 100644
index 0000000000..06e95628d7
--- /dev/null
+++ b/features/learn2earn/impl/src/main/java/com/tangem/feature/learn2earn/data/api/Learn2earnRepository.kt
@@ -0,0 +1,26 @@
+package com.tangem.feature.learn2earn.data.api
+
+import com.tangem.datasource.api.promotion.models.*
+import com.tangem.feature.learn2earn.data.models.PromoUserData
+
+/**
+[REDACTED_AUTHOR]
+ */
+interface Learn2earnRepository {
+
+ fun getUserData(): PromoUserData
+
+ fun updateUserData(userData: PromoUserData)
+
+ fun getProgramName(): String
+
+ suspend fun getPromotionInfo(): Result
+
+ suspend fun validate(walletId: String): ValidateResponse
+
+ suspend fun requestAward(walletId: String, address: String): AwardResponse
+
+ suspend fun validateCode(walletId: String, code: String?): CodeValidateResponse
+
+ suspend fun requestAwardByCode(walletId: String, address: String, code: String?): CodeAwardResponse
+}
\ No newline at end of file
diff --git a/features/learn2earn/impl/src/main/java/com/tangem/feature/learn2earn/data/di/Learn2earnDataModule.kt b/features/learn2earn/impl/src/main/java/com/tangem/feature/learn2earn/data/di/Learn2earnDataModule.kt
new file mode 100644
index 0000000000..98cb9f1b9c
--- /dev/null
+++ b/features/learn2earn/impl/src/main/java/com/tangem/feature/learn2earn/data/di/Learn2earnDataModule.kt
@@ -0,0 +1,45 @@
+package com.tangem.feature.learn2earn.data.di
+
+import android.content.Context
+import com.squareup.moshi.Moshi
+import com.tangem.datasource.api.promotion.PromotionApi
+import com.tangem.datasource.di.NetworkMoshi
+import com.tangem.datasource.di.PromotionOneInch
+import com.tangem.feature.learn2earn.data.DefaultLearn2earnRepository
+import com.tangem.feature.learn2earn.data.DefaultPreferenceStorage
+import com.tangem.feature.learn2earn.data.api.Learn2earnPreferenceStorage
+import com.tangem.feature.learn2earn.data.api.Learn2earnRepository
+import com.tangem.utils.coroutines.AppCoroutineDispatcherProvider
+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 Learn2earnDataModule {
+
+ @Provides
+ @Singleton
+ fun providePreferenceStorage(@ApplicationContext context: Context): Learn2earnPreferenceStorage {
+ return DefaultPreferenceStorage(context)
+ }
+
+ @Provides
+ @Singleton
+ fun provideRepository(
+ preferenceStorage: Learn2earnPreferenceStorage,
+ @NetworkMoshi moshi: Moshi,
+ @PromotionOneInch promotionApi: PromotionApi,
+ dispatchers: AppCoroutineDispatcherProvider,
+ ): Learn2earnRepository {
+ return DefaultLearn2earnRepository(
+ preferencesStorage = preferenceStorage,
+ api = promotionApi,
+ dispatchers = dispatchers,
+ moshi = moshi,
+ )
+ }
+}
\ No newline at end of file
diff --git a/features/learn2earn/impl/src/main/java/com/tangem/feature/learn2earn/data/models/PromoUserData.kt b/features/learn2earn/impl/src/main/java/com/tangem/feature/learn2earn/data/models/PromoUserData.kt
new file mode 100644
index 0000000000..7edf1bc122
--- /dev/null
+++ b/features/learn2earn/impl/src/main/java/com/tangem/feature/learn2earn/data/models/PromoUserData.kt
@@ -0,0 +1,10 @@
+package com.tangem.feature.learn2earn.data.models
+
+/**
+[REDACTED_AUTHOR]
+ */
+data class PromoUserData(
+ val promoCode: String?,
+ val isRegisteredInPromotion: Boolean,
+ val isAlreadyReceivedAward: Boolean,
+)
\ No newline at end of file
diff --git a/features/learn2earn/impl/src/main/java/com/tangem/feature/learn2earn/domain/DefaultLearn2earnInteractor.kt b/features/learn2earn/impl/src/main/java/com/tangem/feature/learn2earn/domain/DefaultLearn2earnInteractor.kt
new file mode 100644
index 0000000000..6ed2706253
--- /dev/null
+++ b/features/learn2earn/impl/src/main/java/com/tangem/feature/learn2earn/domain/DefaultLearn2earnInteractor.kt
@@ -0,0 +1,263 @@
+package com.tangem.feature.learn2earn.domain
+
+import android.net.Uri
+import com.tangem.datasource.api.promotion.models.AbstractPromotionResponse
+import com.tangem.datasource.api.promotion.models.PromotionInfoResponse
+import com.tangem.feature.learn2earn.data.api.Learn2earnRepository
+import com.tangem.feature.learn2earn.data.models.PromoUserData
+import com.tangem.feature.learn2earn.domain.api.*
+import com.tangem.feature.learn2earn.domain.models.Promotion
+import com.tangem.feature.learn2earn.domain.models.PromotionError
+import com.tangem.feature.learn2earn.domain.models.toDomainError
+import com.tangem.lib.crypto.DerivationManager
+import com.tangem.lib.crypto.UserWalletManager
+import com.tangem.lib.crypto.models.Currency
+
+/**
+[REDACTED_AUTHOR]
+ */
+class DefaultLearn2earnInteractor(
+ private val repository: Learn2earnRepository,
+ private val userWalletManager: UserWalletManager,
+ private val derivationManager: DerivationManager,
+ dependencyProvider: Learn2earnDependencyProvider,
+) : Learn2earnInteractor {
+
+ override var webViewResultHandler: WebViewResultHandler? = null
+
+ private lateinit var promotion: Promotion
+
+ private val webViewUriBuilder: WebViewUriBuilder = WebViewUriBuilder(
+ authCredentialsProvider = dependencyProvider.getWebViewAuthCredentialsProvider(),
+ userCountryCodeProvider = dependencyProvider.getUserCountryCodeProvider(),
+ promoCodeProvider = { repository.getUserData().promoCode },
+ )
+
+ override suspend fun init() {
+ initPromotionInfo()
+ }
+
+ override fun isUserHadPromoCode(): Boolean {
+ return repository.getUserData().promoCode != null
+ }
+
+ override fun isNeedToShowViewOnStoriesScreen(): Boolean {
+ return promotionIsActive()
+ }
+
+ override suspend fun isNeedToShowViewOnMainScreen(): Boolean {
+ if (!promotionIsActive()) return false
+
+ val response = repository.validate(userWalletManager.getWalletId())
+ return response.valid == true
+ }
+
+ override fun isUserRegisteredInPromotion(): Boolean {
+ return repository.getUserData().isRegisteredInPromotion
+ }
+
+ override fun getAwardAmount(): Int {
+ val promoCode = repository.getUserData().promoCode
+ val awardAmount = promotion.getPromotionInfo().getData(promoCode).award.toInt()
+
+ return awardAmount
+ }
+
+ @Throws(IllegalArgumentException::class)
+ override suspend fun requestAward(): Result {
+ val awardCurrency = getCurrencyForAward()
+ ?: return Result.failure(PromotionError.UnknownError("Currency for award is null"))
+
+ val walletId = userWalletManager.getWalletId()
+ val promoCode = repository.getUserData().promoCode
+
+ val error = if (promoCode == null) {
+ requestAward(walletId, awardCurrency)
+ } else {
+ requestAwardWithPromoCode(walletId, awardCurrency, promoCode)
+ }
+
+ return if (error == null) {
+ Result.success(Unit)
+ } else {
+ val domainError = error.toDomainError()
+ handlePromotionError(domainError)
+ Result.failure(domainError)
+ }
+ }
+
+ private suspend fun requestAward(walletId: String, awardCurrency: Currency): AbstractPromotionResponse.Error? {
+ val validateResponse = repository.validate(walletId)
+ return if (validateResponse.valid == true) {
+ val address = getWalletAddressForAward(awardCurrency)
+ val awardResponse = repository.requestAward(walletId, address)
+ if (awardResponse.status == true) {
+ updateUserData { it.copy(isAlreadyReceivedAward = true) }
+ null
+ } else {
+ awardResponse.error
+ }
+ } else {
+ validateResponse.error
+ }
+ }
+
+ private suspend fun requestAwardWithPromoCode(
+ walletId: String,
+ awardCurrency: Currency,
+ promoCode: String,
+ ): AbstractPromotionResponse.Error? {
+ val codeValidateResponse = repository.validateCode(walletId, promoCode)
+ return if (codeValidateResponse.valid == true) {
+ val address = getWalletAddressForAward(awardCurrency)
+ val awardWithCodeResponse = repository.requestAwardByCode(walletId, address, promoCode)
+ if (awardWithCodeResponse.status == true) {
+ updateUserData { it.copy(isAlreadyReceivedAward = true) }
+ null
+ } else {
+ awardWithCodeResponse.error
+ }
+ } else {
+ codeValidateResponse.error
+ }
+ }
+
+ private suspend fun getWalletAddressForAward(currency: Currency): String {
+ val derivationPath = deriveOrAddTokens(currency)
+ return userWalletManager.getWalletAddress(currency.networkId, derivationPath)
+ }
+
+ private suspend fun deriveOrAddTokens(currency: Currency): String {
+ val derivationPath = derivationManager.getDerivationPathForBlockchain(currency.networkId)
+ if (derivationPath.isNullOrEmpty()) error("derivationPath shouldn't be empty")
+
+ if (!derivationManager.hasDerivation(currency.networkId, derivationPath)) {
+ derivationManager.deriveMissingBlockchains(currency)
+ }
+ if (!userWalletManager.isTokenAdded(currency, derivationPath)) {
+ userWalletManager.addToken(currency, derivationPath)
+ }
+ return derivationPath
+ }
+
+ private fun handlePromotionError(error: PromotionError) {
+ when (error) {
+ is PromotionError.CodeNotFound -> {
+ updateUserData { it.copy(promoCode = null) }
+ }
+ is PromotionError.CardAlreadyHasAward, is PromotionError.WalletAlreadyHasAward,
+ is PromotionError.CodeWasAlreadyUsed,
+ -> {
+ updateUserData { it.copy(isAlreadyReceivedAward = true) }
+ }
+ else -> Unit
+ }
+ }
+
+ override fun buildUriForNewUser(): Uri {
+ return webViewUriBuilder.buildUriForNewUser()
+ }
+
+ override fun buildUriForOldUser(): Uri {
+ return webViewUriBuilder.buildUriForOldUser()
+ }
+
+ override fun getBasicAuthHeaders(): ArrayList {
+ return HeadersConverter().convert(webViewUriBuilder.getBasicAuthHeaders())
+ }
+
+ override fun handleRedirect(uri: Uri): RedirectConsequences {
+ if (webViewUriBuilder.isReadyForExistedCardAwardRedirect(uri)) {
+ updateUserData { it.copy(isRegisteredInPromotion = true) }
+ webViewResultHandler?.handleResult(WebViewResult.ReadyForAward)
+ return RedirectConsequences.FINISH_SESSION
+ }
+
+ return if (webViewUriBuilder.isPromoCodeRedirect(uri)) {
+ webViewUriBuilder.extractPromoCode(uri)?.let { code ->
+ updateUserData {
+ it.copy(
+ promoCode = code,
+ isRegisteredInPromotion = true,
+ )
+ }
+ webViewResultHandler?.handleResult(WebViewResult.PromoCodeReceived)
+ }
+ RedirectConsequences.NOTHING
+ } else {
+ RedirectConsequences.PROCEED
+ }
+ }
+
+ private fun promotionIsActive(): Boolean {
+ val userData = repository.getUserData()
+ val isActive = when {
+ userData.isAlreadyReceivedAward -> false
+ promotion.isError() -> false
+ else -> {
+ val data = promotion.getPromotionInfo().getData(userData.promoCode)
+ data.status == PromotionInfoResponse.Status.ACTIVE
+ }
+ }
+
+ return isActive
+ }
+
+ private suspend fun initPromotionInfo() {
+ promotion = repository.getPromotionInfo()
+ .fold(
+ onSuccess = { response ->
+ val responseError = response.error
+ if (responseError == null) {
+ val npeMessage = { "Shouldn't be null" }
+ Promotion(
+ info = Promotion.PromotionInfo(
+ newCard = requireNotNull(response.newCard, npeMessage),
+ oldCard = requireNotNull(response.oldCard, npeMessage),
+ awardPaymentToken = requireNotNull(response.awardPaymentToken, npeMessage),
+ ),
+ error = null,
+ )
+ } else {
+ Promotion(
+ info = null,
+ error = responseError.toDomainError(),
+ )
+ }
+ },
+ onFailure = {
+ Promotion(
+ info = null,
+ error = PromotionError.NetworkUnreachable,
+ )
+ },
+ )
+ }
+
+ private fun getCurrencyForAward(): Currency? {
+ val token = promotion.info?.awardPaymentToken ?: return null
+
+ return Currency.NonNativeToken(
+ id = token.id,
+ name = token.name,
+ symbol = token.symbol,
+ networkId = token.networkId,
+ contractAddress = token.contractAddress,
+ decimalCount = token.decimalCount,
+ )
+ }
+
+ private fun updateUserData(updateBlock: (PromoUserData) -> PromoUserData): PromoUserData {
+ return updateBlock(repository.getUserData()).apply {
+ repository.updateUserData(this)
+ }
+ }
+}
+
+private fun Promotion.PromotionInfo.getData(promoCode: String?): PromotionInfoResponse.Data {
+ return if (promoCode == null) {
+ newCard
+ } else {
+ oldCard
+ }
+}
\ No newline at end of file
diff --git a/features/learn2earn/impl/src/main/java/com/tangem/feature/learn2earn/domain/HeadersConverter.kt b/features/learn2earn/impl/src/main/java/com/tangem/feature/learn2earn/domain/HeadersConverter.kt
new file mode 100644
index 0000000000..439091ba1a
--- /dev/null
+++ b/features/learn2earn/impl/src/main/java/com/tangem/feature/learn2earn/domain/HeadersConverter.kt
@@ -0,0 +1,28 @@
+package com.tangem.feature.learn2earn.domain
+
+import com.tangem.utils.converter.TwoWayConverter
+
+/**
+ * A converter that helps prepare a list of headers to be added to the Bundle.
+ * ArrayList is used to prevent cast exceptions when the convert result is placed in a Bundle.
+ * @see Learn2earnRouter#openWebView() putStringArrayListExtra
+ *
+[REDACTED_AUTHOR]
+ */
+internal class HeadersConverter : TwoWayConverter