diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 18fd29dc28..a003607888 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -14,6 +14,11 @@ android { testOptions { animationsDisabled = true } + packaging { + jniLibs { + useLegacyPackaging = true + } + } } configurations.all { @@ -22,20 +27,12 @@ configurations.all { resolutionStrategy { dependencySubstitution { - substitute(module("com.facebook.react:react-native")) - .using(module("com.facebook.react:react-android:0.72.4")) - - substitute(module("com.facebook.react:hermes-engine")) - .using(module("com.facebook.react:hermes-android:0.72.4")) - substitute(module("org.bouncycastle:bcprov-jdk15on")) .using(module("org.bouncycastle:bcprov-jdk18on:1.73")) } force( "org.bouncycastle:bcpkix-jdk15on:1.70", - "com.facebook.react:react-android:0.72.4", - "com.facebook.react:hermes-android:0.72.4", ) } } @@ -69,8 +66,10 @@ dependencies { implementation(projects.domain.qrScanning.models) implementation(projects.domain.staking) implementation(projects.domain.walletConnect) + implementation(projects.domain.markets) implementation(projects.common) + implementation(projects.common.routing) implementation(projects.core.analytics) implementation(projects.core.analytics.models) implementation(projects.core.navigation) @@ -103,6 +102,7 @@ dependencies { implementation(projects.data.qrScanning) implementation(projects.data.staking) implementation(projects.data.walletConnect) + implementation(projects.data.markets) /** Features */ implementation(projects.features.onboarding) @@ -130,6 +130,14 @@ dependencies { implementation(projects.features.staking.impl) implementation(projects.features.details.api) implementation(projects.features.details.impl) + implementation(projects.features.disclaimer.api) + implementation(projects.features.disclaimer.impl) + implementation(projects.features.pushNotifications.api) + implementation(projects.features.pushNotifications.impl) + implementation(projects.features.walletSettings.api) + implementation(projects.features.walletSettings.impl) + implementation(projects.features.markets.api) + implementation(projects.features.markets.impl) /** AndroidX libraries */ implementation(deps.androidx.core.ktx) @@ -166,6 +174,7 @@ dependencies { implementation(platform(deps.firebase.bom)) implementation(deps.firebase.analytics) implementation(deps.firebase.crashlytics) + implementation(deps.firebase.messaging) /** Tangem libraries */ implementation(deps.tangem.blockchain) { @@ -207,10 +216,6 @@ dependencies { implementation(deps.walletConnectCore) implementation(deps.walletConnectWeb3) implementation(deps.prettyLogger) - implementation("com.facebook.react:react-android:0.72.4") - implementation(deps.sprClient) { - exclude(group = "com.github.stephenc.jcip") - } /** Testing libraries */ testImplementation(deps.test.coroutine) diff --git a/app/src/debug/res/values/values.xml b/app/src/debug/res/values/values.xml new file mode 100644 index 0000000000..8cc3a85358 --- /dev/null +++ b/app/src/debug/res/values/values.xml @@ -0,0 +1,4 @@ + + + true + \ No newline at end of file diff --git a/app/src/external/res/values/values.xml b/app/src/external/res/values/values.xml new file mode 100644 index 0000000000..8cc3a85358 --- /dev/null +++ b/app/src/external/res/values/values.xml @@ -0,0 +1,4 @@ + + + true + \ No newline at end of file diff --git a/app/src/internal/res/values/values.xml b/app/src/internal/res/values/values.xml new file mode 100644 index 0000000000..8cc3a85358 --- /dev/null +++ b/app/src/internal/res/values/values.xml @@ -0,0 +1,4 @@ + + + true + \ No newline at end of file diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 2754eb4547..0740725de0 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -41,11 +41,11 @@ android:fullBackupContent="false" android:hardwareAccelerated="true" android:icon="@mipmap/ic_launcher" + android:resizeableActivity="@bool/resizeable_activity" android:label="@string/tangem_app_name" android:largeHeap="@bool/largeHeap" android:networkSecurityConfig="@xml/network_security_config" android:roundIcon="@mipmap/ic_launcher" - android:extractNativeLibs="true" android:supportsRtl="true" tools:ignore="GoogleAppIndexingWarning" tools:replace="android:allowBackup, android:fullBackupContent, android:label"> @@ -147,5 +147,19 @@ android:resource="@xml/provider_paths" /> + + + + + + + + diff --git a/app/src/main/assets/tangem-app-config b/app/src/main/assets/tangem-app-config index 35af912b96..095b8f4ea0 160000 --- a/app/src/main/assets/tangem-app-config +++ b/app/src/main/assets/tangem-app-config @@ -1 +1 @@ -Subproject commit 35af912b96ce0f871906061bd483d9cf3af7451d +Subproject commit 095b8f4ea0fa02e7ccea93cf0f437346345297ef diff --git a/app/src/main/java/com/tangem/tap/ActivityResultCaller.kt b/app/src/main/java/com/tangem/tap/ActivityResultCaller.kt index 16a05117ac..3ef77ac909 100644 --- a/app/src/main/java/com/tangem/tap/ActivityResultCaller.kt +++ b/app/src/main/java/com/tangem/tap/ActivityResultCaller.kt @@ -1,8 +1,32 @@ package com.tangem.tap import android.content.Intent +import android.hardware.biometrics.BiometricManager +import android.os.Build +import android.provider.Settings import androidx.activity.result.ActivityResultLauncher interface ActivityResultCaller { val activityResultLauncher: ActivityResultLauncher? +} + +internal fun ActivityResultCaller.openSystemBiometrySettings() { + val settingsAction = when { + Build.VERSION.SDK_INT >= Build.VERSION_CODES.R -> { + Settings.ACTION_BIOMETRIC_ENROLL + } + else -> { + Settings.ACTION_SECURITY_SETTINGS + } + } + val intent = Intent(settingsAction).apply { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) { + putExtra( + Settings.EXTRA_BIOMETRIC_AUTHENTICATORS_ALLOWED, + BiometricManager.Authenticators.BIOMETRIC_STRONG, + ) + } + } + + activityResultLauncher?.launch(intent) } \ No newline at end of file diff --git a/app/src/main/java/com/tangem/tap/ApplicationEntryPoint.kt b/app/src/main/java/com/tangem/tap/ApplicationEntryPoint.kt index c86e0f9392..967026bf4c 100644 --- a/app/src/main/java/com/tangem/tap/ApplicationEntryPoint.kt +++ b/app/src/main/java/com/tangem/tap/ApplicationEntryPoint.kt @@ -2,8 +2,11 @@ package com.tangem.tap import com.tangem.TangemSdkLogger import com.tangem.blockchainsdk.BlockchainSDKFactory +import com.tangem.common.routing.AppRouter import com.tangem.core.analytics.filter.OneTimeEventFilter import com.tangem.core.featuretoggle.manager.FeatureTogglesManager +import com.tangem.core.navigation.share.ShareManager +import com.tangem.core.navigation.url.UrlOpener import com.tangem.datasource.asset.loader.AssetLoader import com.tangem.datasource.config.ConfigManager import com.tangem.datasource.connection.NetworkConnectionManager @@ -15,6 +18,7 @@ import com.tangem.domain.balancehiding.repositories.BalanceHidingRepository import com.tangem.domain.card.ScanCardProcessor import com.tangem.domain.card.repository.CardRepository import com.tangem.domain.feedback.FeedbackManagerFeatureToggles +import com.tangem.domain.feedback.GetCardInfoUseCase import com.tangem.domain.feedback.GetFeedbackEmailUseCase import com.tangem.domain.feedback.SaveBlockchainErrorUseCase import com.tangem.domain.onboarding.SaveTwinsOnboardingShownUseCase @@ -26,9 +30,8 @@ import com.tangem.domain.walletmanager.WalletManagersFacade import com.tangem.domain.wallets.legacy.UserWalletsListManager import com.tangem.domain.wallets.repository.WalletsRepository import com.tangem.domain.wallets.usecase.GenerateWalletNameUseCase -import com.tangem.features.details.DetailsEntryPoint import com.tangem.features.details.DetailsFeatureToggles -import com.tangem.features.managetokens.featuretoggles.ManageTokensFeatureToggles +import com.tangem.features.pushnotifications.api.featuretoggles.PushNotificationsFeatureToggles import com.tangem.features.send.api.featuretoggles.SendFeatureToggles import com.tangem.tap.domain.walletconnect2.domain.WalletConnectSessionsRepository import com.tangem.tap.features.customtoken.api.featuretoggles.CustomTokenFeatureToggles @@ -59,8 +62,6 @@ interface ApplicationEntryPoint { fun getWalletConnectSessionsRepository(): WalletConnectSessionsRepository - fun getManageTokensFeatureToggles(): ManageTokensFeatureToggles - fun getScanCardProcessor(): ScanCardProcessor fun getAppCurrencyRepository(): AppCurrencyRepository @@ -109,5 +110,13 @@ interface ApplicationEntryPoint { fun getDetailsFeatureToggles(): DetailsFeatureToggles - fun getDetailsEntryPoint(): DetailsEntryPoint + fun getGetCardInfoUseCase(): GetCardInfoUseCase + + fun getUrlOpener(): UrlOpener + + fun getShareManager(): ShareManager + + fun getAppRouter(): AppRouter + + fun getPushNotificationsFeatureToggles(): PushNotificationsFeatureToggles } \ No newline at end of file diff --git a/app/src/main/java/com/tangem/tap/DecomposeFragment.kt b/app/src/main/java/com/tangem/tap/DecomposeFragment.kt new file mode 100644 index 0000000000..296704a5e1 --- /dev/null +++ b/app/src/main/java/com/tangem/tap/DecomposeFragment.kt @@ -0,0 +1,71 @@ +package com.tangem.tap + +import androidx.compose.runtime.Composable +import androidx.compose.ui.Modifier +import androidx.core.os.bundleOf +import androidx.fragment.app.Fragment +import com.tangem.core.decompose.context.AppComponentContext +import com.tangem.core.decompose.factory.ComponentFactory +import com.tangem.core.ui.UiDependencies +import com.tangem.core.ui.decompose.ComposableContentComponent +import com.tangem.core.ui.message.EventMessageEffect +import com.tangem.core.ui.screen.ComposeFragment +import com.tangem.utils.Provider +import dagger.hilt.android.AndroidEntryPoint +import java.util.WeakHashMap +import javax.inject.Inject + +@AndroidEntryPoint +internal class DecomposeFragment : ComposeFragment() { + + @Inject + override lateinit var uiDependencies: UiDependencies + + private val component by lazy(mode = LazyThreadSafetyMode.NONE) { + val tag = requireArguments().getString(TAG_KEY) + val builder = componentsBuilders[tag] + + requireNotNull(builder?.build()) { + "Component builder is not set, call newInstance() for DecomposeFragment creation first." + } + } + + @Composable + override fun ScreenContent(modifier: Modifier) { + component.Content(modifier) + + EventMessageEffect( + messageHandler = uiDependencies.eventMessageHandler, + snackbarHostState = uiDependencies.globalSnackbarHostState, + ) + } + + private class ComponentBuilder>( + private val contextProvider: Provider, + private val params: P, + private val componentFactory: F, + ) { + + fun build(): C = componentFactory.create(contextProvider(), params) + } + + companion object { + + private const val TAG_KEY = "tag" + + private val componentsBuilders = WeakHashMap>() + + fun > newInstance( + tag: String, + contextProvider: Provider, + params: P, + componentFactory: F, + ): Fragment { + this@Companion.componentsBuilders[tag] = ComponentBuilder(contextProvider, params, componentFactory) + + return DecomposeFragment().apply { + this.arguments = bundleOf(TAG_KEY to tag) + } + } + } +} \ No newline at end of file diff --git a/app/src/main/java/com/tangem/tap/LockUserWalletsTimer.kt b/app/src/main/java/com/tangem/tap/LockUserWalletsTimer.kt index bb6e616898..8758b045e3 100644 --- a/app/src/main/java/com/tangem/tap/LockUserWalletsTimer.kt +++ b/app/src/main/java/com/tangem/tap/LockUserWalletsTimer.kt @@ -3,13 +3,11 @@ package com.tangem.tap import androidx.lifecycle.DefaultLifecycleObserver import androidx.lifecycle.LifecycleOwner import androidx.lifecycle.lifecycleScope -import com.tangem.core.navigation.AppScreen -import com.tangem.core.navigation.NavigationAction +import com.tangem.common.routing.AppRoute import com.tangem.domain.settings.repositories.SettingsRepository import com.tangem.domain.wallets.legacy.UserWalletsListManager import com.tangem.domain.wallets.legacy.asLockable -import com.tangem.tap.common.extensions.dispatchOnMain -import com.tangem.tap.common.extensions.dispatchWithMain +import com.tangem.tap.common.extensions.dispatchNavigationAction import kotlinx.coroutines.* import timber.log.Timber import kotlin.time.Duration @@ -50,7 +48,7 @@ internal class LockUserWalletsTimer( start() if (shouldOpenWelcomeScreenOnResume) { - store.dispatchOnMain(NavigationAction.PopBackTo(AppScreen.Welcome)) + store.dispatchNavigationAction { replaceAll(AppRoute.Welcome()) } settingsRepository.setShouldOpenWelcomeScreenOnResume(value = false) } } @@ -128,7 +126,7 @@ internal class LockUserWalletsTimer( if (wasApplicationStopped) { settingsRepository.setShouldOpenWelcomeScreenOnResume(value = true) } else { - store.dispatchWithMain(NavigationAction.PopBackTo(AppScreen.Welcome)) + store.dispatchNavigationAction { replaceAll(AppRoute.Welcome()) } } } } diff --git a/app/src/main/java/com/tangem/tap/MainActivity.kt b/app/src/main/java/com/tangem/tap/MainActivity.kt index 87b2bf414d..20808b8396 100644 --- a/app/src/main/java/com/tangem/tap/MainActivity.kt +++ b/app/src/main/java/com/tangem/tap/MainActivity.kt @@ -1,37 +1,38 @@ package com.tangem.tap -import android.Manifest import android.annotation.SuppressLint import android.content.Intent import android.content.pm.ActivityInfo -import android.content.pm.PackageManager import android.content.res.Configuration -import android.os.Build import android.os.Bundle import android.view.View +import androidx.activity.SystemBarStyle +import androidx.activity.enableEdgeToEdge import androidx.activity.viewModels import androidx.annotation.StringRes import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.app.AppCompatDelegate import androidx.appcompat.app.AppCompatDelegate.setDefaultNightMode +import androidx.compose.ui.graphics.Color import androidx.compose.ui.graphics.toArgb import androidx.coordinatorlayout.widget.CoordinatorLayout -import androidx.core.app.ActivityCompat -import androidx.core.content.ContextCompat -import androidx.core.os.bundleOf import androidx.core.splashscreen.SplashScreen.Companion.installSplashScreen -import androidx.core.view.WindowCompat import androidx.lifecycle.Lifecycle import androidx.lifecycle.flowWithLifecycle import androidx.lifecycle.lifecycleScope import arrow.core.getOrElse import by.kirich1409.viewbindingdelegate.viewBinding +import com.arkivanov.decompose.value.observe +import com.arkivanov.essenty.lifecycle.asEssentyLifecycle import com.google.android.material.snackbar.BaseTransientBottomBar import com.google.android.material.snackbar.Snackbar +import com.tangem.common.routing.AppRoute +import com.tangem.common.routing.AppRouter +import com.tangem.common.routing.entity.SerializableIntent import com.tangem.core.analytics.api.AnalyticsEventHandler +import com.tangem.core.decompose.context.AppComponentContext +import com.tangem.core.decompose.di.RootAppComponentContext import com.tangem.core.deeplink.DeepLinksRegistry -import com.tangem.core.navigation.AppScreen -import com.tangem.core.navigation.NavigationAction import com.tangem.core.navigation.email.EmailSender import com.tangem.core.ui.event.StateEvent import com.tangem.core.ui.extensions.TextReference @@ -40,15 +41,20 @@ import com.tangem.core.ui.res.TangemColorPalette import com.tangem.data.card.sdk.CardSdkOwner import com.tangem.domain.apptheme.model.AppThemeMode import com.tangem.domain.card.ScanCardUseCase +import com.tangem.domain.card.repository.CardRepository import com.tangem.domain.card.repository.CardSdkConfigRepository +import com.tangem.domain.settings.ShouldInitiallyAskPermissionUseCase import com.tangem.domain.settings.repositories.SettingsRepository +import com.tangem.domain.staking.SendUnsubmittedHashesUseCase import com.tangem.domain.tokens.GetPolkadotCheckHasImmortalUseCase import com.tangem.domain.tokens.GetPolkadotCheckHasResetUseCase import com.tangem.domain.wallets.legacy.UserWalletsListManager import com.tangem.feature.qrscanning.QrScanningRouter import com.tangem.feature.wallet.presentation.wallet.analytics.WalletScreenAnalyticsEvent -import com.tangem.features.managetokens.navigation.ManageTokensUi +import com.tangem.features.pushnotifications.api.navigation.PushNotificationsRouter +import com.tangem.features.pushnotifications.api.utils.PUSH_PERMISSION import com.tangem.features.send.api.navigation.SendRouter +import com.tangem.features.staking.api.navigation.StakingRouter import com.tangem.features.tester.api.TesterRouter import com.tangem.features.tokendetails.navigation.TokenDetailsRouter import com.tangem.features.wallet.navigation.WalletRouter @@ -59,6 +65,9 @@ import com.tangem.tap.common.DialogManager import com.tangem.tap.common.OnActivityResultCallback import com.tangem.tap.common.SnackbarHandler import com.tangem.tap.common.apptheme.MutableAppThemeModeHolder +import com.tangem.tap.common.extensions.dispatchNavigationAction +import com.tangem.tap.common.extensions.inject +import com.tangem.tap.common.extensions.showFragmentAllowingStateLoss import com.tangem.tap.common.redux.NotificationsHandler import com.tangem.tap.domain.sdk.TangemSdkManager import com.tangem.tap.domain.walletconnect2.domain.WalletConnectInteractor @@ -68,17 +77,18 @@ import com.tangem.tap.features.intentHandler.handlers.WalletConnectLinkIntentHan import com.tangem.tap.features.main.MainViewModel import com.tangem.tap.features.main.model.Toast import com.tangem.tap.features.onboarding.products.wallet.redux.BackupAction -import com.tangem.tap.features.welcome.ui.WelcomeFragment import com.tangem.tap.proxy.AppStateHolder import com.tangem.tap.proxy.redux.DaggerGraphAction +import com.tangem.tap.proxy.redux.DaggerGraphState +import com.tangem.tap.routing.RoutingComponent +import com.tangem.tap.routing.configurator.AppRouterConfig import com.tangem.utils.coroutines.FeatureCoroutineExceptionHandler -import com.tangem.wallet.BuildConfig import com.tangem.wallet.R import com.tangem.wallet.databinding.ActivityMainBinding import dagger.hilt.android.AndroidEntryPoint import kotlinx.coroutines.* import kotlinx.coroutines.flow.* -import java.lang.ref.WeakReference +import timber.log.Timber import javax.inject.Inject import kotlin.coroutines.CoroutineContext @@ -125,9 +135,6 @@ class MainActivity : AppCompatActivity(), SnackbarHandler, ActivityResultCallbac @Inject lateinit var tokenDetailsRouter: TokenDetailsRouter - @Inject - lateinit var manageTokensUi: ManageTokensUi - @Inject lateinit var walletConnectInteractor: WalletConnectInteractor @@ -143,6 +150,9 @@ class MainActivity : AppCompatActivity(), SnackbarHandler, ActivityResultCallbac @Inject lateinit var settingsRepository: SettingsRepository + @Inject + lateinit var sendUnsubmittedHashesUseCase: SendUnsubmittedHashesUseCase + @Inject lateinit var getPolkadotCheckHasResetUseCase: GetPolkadotCheckHasResetUseCase @@ -158,6 +168,31 @@ class MainActivity : AppCompatActivity(), SnackbarHandler, ActivityResultCallbac @Inject lateinit var emailSender: EmailSender + @Inject + lateinit var stakingRouter: StakingRouter + + @Inject + @RootAppComponentContext + internal lateinit var rootComponentContext: AppComponentContext + + @Inject + internal lateinit var appRouterConfig: AppRouterConfig + + @Inject + internal lateinit var routingComponentFactory: RoutingComponent.Factory + + @Inject + internal lateinit var appRouter: AppRouter + + @Inject + lateinit var pushNotificationsRouter: PushNotificationsRouter + + @Inject + lateinit var cardRepository: CardRepository + + @Inject + lateinit var shouldInitiallyAskPermissionUseCase: ShouldInitiallyAskPermissionUseCase + internal val viewModel: MainViewModel by viewModels() private lateinit var appThemeModeFlow: SharedFlow @@ -177,6 +212,13 @@ class MainActivity : AppCompatActivity(), SnackbarHandler, ActivityResultCallbac val splashScreen = installSplashScreen() + enableEdgeToEdge( + navigationBarStyle = SystemBarStyle.auto( + Color.Transparent.toArgb(), + Color.Transparent.toArgb(), + ), + ) + super.onCreate(savedInstanceState) splashScreen.setKeepOnScreenCondition { viewModel.isSplashScreenShown } @@ -185,17 +227,43 @@ class MainActivity : AppCompatActivity(), SnackbarHandler, ActivityResultCallbac observeAppThemeModeUpdates() setContentView(R.layout.activity_main) + installRouting() initContent() - checkForNotificationPermission() observeStateUpdates() observePolkadotAccountHealthCheck() + sendStakingUnsubmittedHashes() if (intent != null) { deepLinksRegistry.launch(intent) } } + private fun installRouting() { + val routingComponent = routingComponentFactory.create( + context = rootComponentContext, + ) + + appRouterConfig.routerScope = lifecycleScope + appRouterConfig.componentRouter = routingComponent.router + + routingComponent.stack.observe(lifecycle.asEssentyLifecycle()) { childStack -> + appRouterConfig.stack = childStack.backStack + .plus(childStack.active) + .map { it.configuration } + + when (val child = childStack.active.instance) { + is RoutingComponent.Child.Initial -> Unit + is RoutingComponent.Child.LegacyFragment -> { + supportFragmentManager.showFragmentAllowingStateLoss(child.name, child.fragmentProvider) + } + is RoutingComponent.Child.LegacyIntent -> { + startActivity(child.intent) + } + } + } + } + private fun observeStateUpdates() { viewModel.state .flowWithLifecycle(lifecycle) @@ -217,8 +285,6 @@ class MainActivity : AppCompatActivity(), SnackbarHandler, ActivityResultCallbac } private fun installActivityDependencies() { - store.dispatch(NavigationAction.ActivityCreated(WeakReference(this))) - cardSdkOwner.register(activity = this) tangemSdkManager = injectedTangemSdkManager appStateHolder.tangemSdkManager = tangemSdkManager @@ -238,11 +304,12 @@ class MainActivity : AppCompatActivity(), SnackbarHandler, ActivityResultCallbac walletRouter = walletRouter, walletConnectInteractor = walletConnectInteractor, tokenDetailsRouter = tokenDetailsRouter, - manageTokensUi = manageTokensUi, cardSdkConfigRepository = cardSdkConfigRepository, sendRouter = sendRouter, qrScanningRouter = qrScanningRouter, emailSender = emailSender, + stakingRouter = stakingRouter, + pushNotificationsRouter = pushNotificationsRouter, ), ) } @@ -263,8 +330,6 @@ class MainActivity : AppCompatActivity(), SnackbarHandler, ActivityResultCallbac @SuppressLint("SourceLockedOrientationActivity") private fun initContent() { - WindowCompat.setDecorFitsSystemWindows(window, false) - supportFragmentManager.registerFragmentLifecycleCallbacks( NavBarInsetsFragmentLifecycleCallback(), true, @@ -308,7 +373,6 @@ class MainActivity : AppCompatActivity(), SnackbarHandler, ActivityResultCallbac } override fun onDestroy() { - store.dispatch(NavigationAction.ActivityDestroyed(WeakReference(this))) intentProcessor.removeAll() super.onDestroy() } @@ -448,8 +512,8 @@ class MainActivity : AppCompatActivity(), SnackbarHandler, ActivityResultCallbac } private fun navigateToInitialScreenIfNeeded(intentWhichStartedActivity: Intent?) { - val backStack = store.state.navigationState.backStack - val isOnInitialScreen = backStack.all { it == AppScreen.Welcome || it == AppScreen.Home } + val backStack = appRouter.stack + val isOnInitialScreen = backStack.all { it is AppRoute.Welcome || it is AppRoute.Home } val isNotScannedBefore = store.state.globalState.scanResponse == null val isOnboardingServiceNotActive = !store.state.globalState.onboardingState.onboardingStarted @@ -466,17 +530,24 @@ class MainActivity : AppCompatActivity(), SnackbarHandler, ActivityResultCallbac private fun navigateToInitialScreen(intentWhichStartedActivity: Intent?) { if (userWalletsListManager.isLockable && userWalletsListManager.hasUserWallets) { - store.dispatch( - NavigationAction.NavigateTo( - screen = AppScreen.Welcome, - bundle = intentWhichStartedActivity?.let { - bundleOf(WelcomeFragment.INITIAL_INTENT_KEY to it) - }, - ), - ) + store.dispatchNavigationAction { + replaceAll(AppRoute.Welcome(intentWhichStartedActivity?.let(::SerializableIntent))) + } } else { - store.dispatch(NavigationAction.NavigateTo(AppScreen.Home)) lifecycleScope.launch { + val toggles = store.inject(getDependency = DaggerGraphState::pushNotificationsFeatureToggles) + val isPushPermissionEnabled = toggles.isPushNotificationsEnabled + val shouldShowTos = !cardRepository.isTangemTOSAccepted() && isPushPermissionEnabled + val wasPushInitiallyAsked = shouldInitiallyAskPermissionUseCase(PUSH_PERMISSION).getOrElse { false } + val shouldShowInitialPush = wasPushInitiallyAsked && isPushPermissionEnabled + + val route = when { + shouldShowTos -> AppRoute.Disclaimer(isTosAccepted = false) + shouldShowInitialPush -> AppRoute.PushNotification + else -> AppRoute.Home + } + + store.dispatchNavigationAction { replaceAll(route) } intentProcessor.handleIntent(intentWhichStartedActivity, false) } } @@ -484,16 +555,6 @@ class MainActivity : AppCompatActivity(), SnackbarHandler, ActivityResultCallbac store.dispatch(BackupAction.CheckForUnfinishedBackup) } - private fun checkForNotificationPermission() { - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU && - BuildConfig.LOG_ENABLED && - ContextCompat.checkSelfPermission(this, Manifest.permission.POST_NOTIFICATIONS) != - PackageManager.PERMISSION_GRANTED - ) { - ActivityCompat.requestPermissions(this, arrayOf(Manifest.permission.POST_NOTIFICATIONS), 0) - } - } - private fun observePolkadotAccountHealthCheck() { lifecycleScope.launch { getPolkadotCheckHasResetUseCase() @@ -514,4 +575,12 @@ class MainActivity : AppCompatActivity(), SnackbarHandler, ActivityResultCallbac } } } + + private fun sendStakingUnsubmittedHashes() { + lifecycleScope.launch { + sendUnsubmittedHashesUseCase.invoke() + .onRight { Timber.d("Submitting hashes succeeded") } + .onLeft { Timber.e(it.toString()) } + } + } } \ No newline at end of file diff --git a/app/src/main/java/com/tangem/tap/TangemApplication.kt b/app/src/main/java/com/tangem/tap/TangemApplication.kt index d9b90a7bb9..eaca995355 100644 --- a/app/src/main/java/com/tangem/tap/TangemApplication.kt +++ b/app/src/main/java/com/tangem/tap/TangemApplication.kt @@ -13,6 +13,7 @@ import com.tangem.LogFormat import com.tangem.TangemSdkLogger import com.tangem.blockchain.network.BlockchainSdkRetrofitBuilder import com.tangem.blockchainsdk.BlockchainSDKFactory +import com.tangem.common.routing.AppRouter import com.tangem.core.analytics.Analytics import com.tangem.core.analytics.filter.OneTimeEventFilter import com.tangem.core.featuretoggle.manager.FeatureTogglesManager @@ -32,6 +33,7 @@ import com.tangem.domain.card.ScanCardProcessor import com.tangem.domain.card.repository.CardRepository import com.tangem.domain.common.LogConfig import com.tangem.domain.feedback.FeedbackManagerFeatureToggles +import com.tangem.domain.feedback.GetCardInfoUseCase import com.tangem.domain.feedback.GetFeedbackEmailUseCase import com.tangem.domain.feedback.SaveBlockchainErrorUseCase import com.tangem.domain.onboarding.SaveTwinsOnboardingShownUseCase @@ -43,17 +45,15 @@ import com.tangem.domain.walletmanager.WalletManagersFacade import com.tangem.domain.wallets.legacy.UserWalletsListManager import com.tangem.domain.wallets.repository.WalletsRepository import com.tangem.domain.wallets.usecase.GenerateWalletNameUseCase -import com.tangem.features.details.DetailsEntryPoint import com.tangem.features.details.DetailsFeatureToggles -import com.tangem.features.managetokens.featuretoggles.ManageTokensFeatureToggles +import com.tangem.features.pushnotifications.api.featuretoggles.PushNotificationsFeatureToggles import com.tangem.features.send.api.featuretoggles.SendFeatureToggles 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.firebase.FirebaseAnalyticsHandler -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.feedback.LegacyFeedbackManager import com.tangem.tap.common.images.createCoilImageLoader import com.tangem.tap.common.log.TangemLogCollector import com.tangem.tap.common.log.TimberFormatStrategy @@ -110,9 +110,6 @@ abstract class TangemApplication : Application(), ImageLoaderFactory { private val walletConnectSessionsRepository: WalletConnectSessionsRepository get() = entryPoint.getWalletConnectSessionsRepository() - private val manageTokensFeatureToggles: ManageTokensFeatureToggles - get() = entryPoint.getManageTokensFeatureToggles() - private val scanCardProcessor: ScanCardProcessor get() = entryPoint.getScanCardProcessor() @@ -181,13 +178,25 @@ abstract class TangemApplication : Application(), ImageLoaderFactory { private val saveBlockchainErrorUseCase: SaveBlockchainErrorUseCase get() = entryPoint.getSaveBlockchainErrorUseCase() - // endregion + + private val getCardInfoUseCase: GetCardInfoUseCase + get() = entryPoint.getGetCardInfoUseCase() private val detailsFeatureToggles: DetailsFeatureToggles get() = entryPoint.getDetailsFeatureToggles() - private val detailsEntryPoint: DetailsEntryPoint - get() = entryPoint.getDetailsEntryPoint() + private val urlOpener + get() = entryPoint.getUrlOpener() + + private val shareManager + get() = entryPoint.getShareManager() + + private val appRouter: AppRouter + get() = entryPoint.getAppRouter() + + private val pushNotificationsFeatureToggles: PushNotificationsFeatureToggles + get() = entryPoint.getPushNotificationsFeatureToggles() + // endregion override fun onCreate() { super.onCreate() @@ -253,7 +262,6 @@ abstract class TangemApplication : Application(), ImageLoaderFactory { customTokenFeatureToggles = customTokenFeatureToggles, walletConnectRepository = walletConnect2Repository, walletConnectSessionsRepository = walletConnectSessionsRepository, - manageTokensFeatureToggles = manageTokensFeatureToggles, scanCardProcessor = scanCardProcessor, appCurrencyRepository = appCurrencyRepository, walletManagersFacade = walletManagersFacade, @@ -274,9 +282,14 @@ abstract class TangemApplication : Application(), ImageLoaderFactory { settingsRepository = settingsRepository, blockchainSDKFactory = blockchainSDKFactory, saveBlockchainErrorUseCase = saveBlockchainErrorUseCase, - detailsFeatureToggles = detailsFeatureToggles, - detailsEntryPoint = detailsEntryPoint, + getFeedbackEmailUseCase = getFeedbackEmailUseCase, + getCardInfoUseCase = getCardInfoUseCase, assetLoader = assetLoader, + detailsFeatureToggles = detailsFeatureToggles, + urlOpener = urlOpener, + shareManager = shareManager, + appRouter = appRouter, + pushNotificationsFeatureToggles = pushNotificationsFeatureToggles, ), ), ) @@ -302,7 +315,7 @@ abstract class TangemApplication : Application(), ImageLoaderFactory { private fun initWithConfigDependency(config: Config) { initAnalytics(this, config) - initFeedbackManager(this, foregroundActivityObserver, store) + initFeedbackManager(this, store) } private fun initAnalytics(application: Application, config: Config) { @@ -323,11 +336,7 @@ abstract class TangemApplication : Application(), ImageLoaderFactory { // ExceptionHandler.append(blockchainExceptionHandler) TODO: [REDACTED_JIRA] } - private fun initFeedbackManager( - context: Context, - foregroundActivityObserver: ForegroundActivityObserver, - store: Store, - ) { + private fun initFeedbackManager(context: Context, store: Store) { fun initAdditionalFeedbackInfo(context: Context): AdditionalFeedbackInfo { return AdditionalFeedbackInfo().apply { appVersion = try { @@ -365,10 +374,9 @@ abstract class TangemApplication : Application(), ImageLoaderFactory { logger = if (feedbackManagerFeatureToggles.isLocalLogsEnabled) tangemSdkLogger else tangemLogCollector, ) - val feedbackManager = FeedbackManager( + val feedbackManager = LegacyFeedbackManager( infoHolder = additionalFeedbackInfo, logCollector = tangemLogCollector, - chatManager = ChatManager(foregroundActivityObserver), feedbackManagerFeatureToggles = feedbackManagerFeatureToggles, getFeedbackEmailUseCase = getFeedbackEmailUseCase, ) diff --git a/app/src/main/java/com/tangem/tap/common/DialogManager.kt b/app/src/main/java/com/tangem/tap/common/DialogManager.kt index 4352a65eb9..a13d000c44 100644 --- a/app/src/main/java/com/tangem/tap/common/DialogManager.kt +++ b/app/src/main/java/com/tangem/tap/common/DialogManager.kt @@ -2,7 +2,7 @@ package com.tangem.tap.common import android.app.Dialog import android.content.Context -import com.tangem.core.navigation.StateDialog +import com.tangem.domain.redux.StateDialog import com.tangem.tap.common.redux.AppDialog import com.tangem.tap.common.redux.global.GlobalState import com.tangem.tap.common.ui.* @@ -46,7 +46,11 @@ class DialogManager : StoreSubscriber { dialog = when (state.dialog) { is AppDialog.SimpleOkDialogRes -> SimpleOkDialog.create(state.dialog, context) - is StateDialog.ScanFailsDialog -> ScanFailsDialog.create(context, state.dialog.source) + is StateDialog.ScanFailsDialog -> ScanFailsDialog.create( + context = context, + source = state.dialog.source, + onTryAgain = state.dialog.onTryAgain, + ) is AppDialog.AddressInfoDialog -> AddressInfoBottomSheetDialog(state.dialog, context) is AppDialog.TestActionsDialog -> TestActionsBottomSheetDialog(state.dialog, context) is AppDialog.RussianCardholdersWarningDialog -> RussianCardholdersWarningBottomSheetDialog( diff --git a/app/src/main/java/com/tangem/tap/common/analytics/DefaultAnalyticsContextProxy.kt b/app/src/main/java/com/tangem/tap/common/analytics/DefaultAnalyticsContextProxy.kt new file mode 100644 index 0000000000..d1aecc29d0 --- /dev/null +++ b/app/src/main/java/com/tangem/tap/common/analytics/DefaultAnalyticsContextProxy.kt @@ -0,0 +1,31 @@ +package com.tangem.tap.common.analytics + +import com.tangem.core.analytics.Analytics +import com.tangem.core.analytics.utils.AnalyticsContextProxy +import com.tangem.domain.models.scan.ScanResponse +import com.tangem.tap.common.extensions.addContext +import com.tangem.tap.common.extensions.eraseContext +import com.tangem.tap.common.extensions.removeContext +import com.tangem.tap.common.extensions.setContext + +/** +[REDACTED_AUTHOR] + */ +internal class DefaultAnalyticsContextProxy : AnalyticsContextProxy { + + override fun setContext(scanResponse: ScanResponse) { + Analytics.setContext(scanResponse) + } + + override fun eraseContext() { + Analytics.eraseContext() + } + + override fun addContext(scanResponse: ScanResponse) { + Analytics.addContext(scanResponse) + } + + override fun removeContext() { + Analytics.removeContext() + } +} \ No newline at end of file diff --git a/app/src/main/java/com/tangem/tap/common/analytics/events/ScanFailsDialogAnalytics.kt b/app/src/main/java/com/tangem/tap/common/analytics/events/ScanFailsDialogAnalytics.kt new file mode 100644 index 0000000000..392f340405 --- /dev/null +++ b/app/src/main/java/com/tangem/tap/common/analytics/events/ScanFailsDialogAnalytics.kt @@ -0,0 +1,17 @@ +package com.tangem.tap.common.analytics.events + +import com.tangem.core.analytics.models.AnalyticsEvent +import com.tangem.core.analytics.models.AnalyticsParam + +class ScanFailsDialogAnalytics(button: Buttons, source: AnalyticsParam.ScreensSources) : AnalyticsEvent( + category = "Cant Scan The Card", + event = button.event, + params = mapOf( + AnalyticsParam.SOURCE to source.value, + ), +) { + enum class Buttons(val event: String) { + TRY_AGAIN("Try again button"), + HOW_TO_SCAN("Button blog"), + } +} \ No newline at end of file diff --git a/app/src/main/java/com/tangem/tap/common/chat/ChatManager.kt b/app/src/main/java/com/tangem/tap/common/chat/ChatManager.kt deleted file mode 100644 index 5bbe3fc679..0000000000 --- a/app/src/main/java/com/tangem/tap/common/chat/ChatManager.kt +++ /dev/null @@ -1,23 +0,0 @@ -package com.tangem.tap.common.chat - -import android.content.Context -import com.tangem.datasource.config.models.ChatConfig -import com.tangem.datasource.config.models.SprinklrConfig -import com.tangem.tap.ForegroundActivityObserver -import com.tangem.tap.common.chat.opener.ChatOpener -import com.tangem.tap.common.chat.opener.implementation.SprinklrChatOpener -import java.io.File - -class ChatManager(private val foregroundActivityObserver: ForegroundActivityObserver) { - private val openers = mutableMapOf() - - fun open(config: ChatConfig, createLogsFile: (Context) -> File?, createFeedbackFile: (Context) -> File?) { - val opener = openers.getOrPut(config) { - when (config) { - is SprinklrConfig -> SprinklrChatOpener(config, foregroundActivityObserver) - } - } - - opener.open(createFeedbackFile, createLogsFile) - } -} \ No newline at end of file diff --git a/app/src/main/java/com/tangem/tap/common/chat/opener/ChatOpener.kt b/app/src/main/java/com/tangem/tap/common/chat/opener/ChatOpener.kt deleted file mode 100644 index aff21cad05..0000000000 --- a/app/src/main/java/com/tangem/tap/common/chat/opener/ChatOpener.kt +++ /dev/null @@ -1,8 +0,0 @@ -package com.tangem.tap.common.chat.opener - -import android.content.Context -import java.io.File - -internal interface ChatOpener { - fun open(createFeedbackFile: (Context) -> File?, createLogsFile: (Context) -> File?) -} \ No newline at end of file diff --git a/app/src/main/java/com/tangem/tap/common/chat/opener/implementation/SprinklrChatOpener.kt b/app/src/main/java/com/tangem/tap/common/chat/opener/implementation/SprinklrChatOpener.kt deleted file mode 100644 index 0fcb2a4cf2..0000000000 --- a/app/src/main/java/com/tangem/tap/common/chat/opener/implementation/SprinklrChatOpener.kt +++ /dev/null @@ -1,57 +0,0 @@ -package com.tangem.tap.common.chat.opener.implementation - -import android.annotation.SuppressLint -import android.app.Application -import android.content.Context -import android.provider.Settings -import com.spr.messengerclient.config.SPRMessenger -import com.spr.messengerclient.config.bean.SPRMessengerConfig -import com.tangem.common.extensions.guard -import com.tangem.datasource.config.models.SprinklrConfig -import com.tangem.tap.ForegroundActivityObserver -import com.tangem.tap.common.chat.opener.ChatOpener -import timber.log.Timber -import java.io.File -import java.util.Locale - -internal class SprinklrChatOpener( - private val config: SprinklrConfig, - private val foregroundActivityObserver: ForegroundActivityObserver, -) : ChatOpener { - - override fun open(createFeedbackFile: (Context) -> File?, createLogsFile: (Context) -> File?) { - val messenger = SPRMessenger.shared() - - if (messenger.config == null) { - initSprConfig(messenger) - } - - messenger.startApplication() - } - - private fun initSprConfig(messenger: SPRMessenger) { - val application = foregroundActivityObserver.foregroundActivity?.application.guard { - Timber.e("The SPR chat cannot be opened because there are no activities in foreground") - return - } - - messenger.takeOff(application, createSprConfig(application, config)) - } - - @SuppressLint("HardwareIds") - private fun createSprConfig(application: Application, config: SprinklrConfig): SPRMessengerConfig { - return SPRMessengerConfig().apply { - appId = config.appId - appKey = CHAT_APP_KEY - deviceId = Settings.Secure.getString(application.contentResolver, Settings.Secure.ANDROID_ID) - environment = config.environment - skin = CHAT_SKIN - locale = Locale.getDefault().language - } - } - - private companion object { - const val CHAT_APP_KEY = "com.sprinklr.messenger.release" - const val CHAT_SKIN = "MODERN" - } -} \ No newline at end of file diff --git a/app/src/main/java/com/tangem/tap/common/extensions/Navigation.kt b/app/src/main/java/com/tangem/tap/common/extensions/Navigation.kt index 4b0a740760..5d7a14709f 100644 --- a/app/src/main/java/com/tangem/tap/common/extensions/Navigation.kt +++ b/app/src/main/java/com/tangem/tap/common/extensions/Navigation.kt @@ -1,171 +1,60 @@ package com.tangem.tap.common.extensions -import android.os.Bundle -import androidx.fragment.app.* -import com.tangem.core.navigation.AppScreen -import com.tangem.core.navigation.FragmentShareTransition -import com.tangem.feature.referral.ReferralFragment -import com.tangem.feature.swap.presentation.SwapFragment -import com.tangem.tap.features.customtoken.impl.presentation.AddCustomTokenFragment -import com.tangem.tap.features.details.ui.appcurrency.AppCurrencySelectorFragment -import com.tangem.tap.features.details.ui.appsettings.AppSettingsFragment -import com.tangem.tap.features.details.ui.cardsettings.CardSettingsFragment -import com.tangem.tap.features.details.ui.cardsettings.coderecovery.AccessCodeRecoveryFragment -import com.tangem.tap.features.details.ui.details.DetailsFragment -import com.tangem.tap.features.details.ui.resetcard.ResetCardFragment -import com.tangem.tap.features.details.ui.securitymode.SecurityModeFragment -import com.tangem.tap.features.details.ui.walletconnect.WalletConnectFragment -import com.tangem.tap.features.disclaimer.ui.DisclaimerFragment -import com.tangem.tap.features.home.HomeFragment -import com.tangem.tap.features.main.ui.ModalNotificationBottomSheetFragment -import com.tangem.tap.features.onboarding.products.note.OnboardingNoteFragment -import com.tangem.tap.features.onboarding.products.otherCards.OnboardingOtherCardsFragment -import com.tangem.tap.features.onboarding.products.twins.ui.OnboardingTwinsFragment -import com.tangem.tap.features.onboarding.products.wallet.ui.OnboardingWalletFragment -import com.tangem.tap.features.saveWallet.ui.SaveWalletBottomSheetFragment -import com.tangem.tap.features.send.ui.SendFragment -import com.tangem.tap.features.tokens.impl.presentation.TokensListFragment -import com.tangem.tap.features.welcome.ui.WelcomeFragment -import com.tangem.tap.proxy.redux.DaggerGraphState -import com.tangem.tap.store +import androidx.fragment.app.DialogFragment +import androidx.fragment.app.Fragment +import androidx.fragment.app.FragmentManager +import com.tangem.utils.Provider import com.tangem.wallet.R import timber.log.Timber -fun FragmentActivity.openFragment( - screen: AppScreen, - addToBackstack: Boolean, - bundle: Bundle? = null, - fgShareTransition: FragmentShareTransition? = null, -) { - val transaction = supportFragmentManager.beginTransaction().apply { - setReorderingAllowed(true) - } +fun FragmentManager.showFragmentAllowingStateLoss(name: String, fragmentProvider: Provider) { + if (backStackEntryCount > 0) { + val currentFragmentName = getBackStackEntryAt(backStackEntryCount - 1).name - val fragment = fragmentFactory(screen).apply { - arguments = bundle - - if (fgShareTransition != null) { - sharedElementEnterTransition = fgShareTransition.enterTransitionSet - sharedElementReturnTransition = fgShareTransition.exitTransitionSet - fgShareTransition.shareElements.forEach { shareElement -> - shareElement.wView.get()?.let { view -> - transaction.addSharedElement(view, shareElement.elementName) - } - } + if (name == currentFragmentName) { + Timber.d("Fragment $name is already at the top of the stack") + return } } - if (screen.isDialogFragment && fragment is DialogFragment) { - fragment.showAllowingStateLoss( - fragmentManager = supportFragmentManager, - baseTransaction = transaction, - tag = screen.name, - addToBackstack = addToBackstack, - ) + Timber.d("Showing $name route") + + val isPoppedBack = popBackStackImmediate(name, 0) + + if (!isPoppedBack) { + val fragment = fragmentProvider() + + if (fragment is DialogFragment) { + fragment.showDialog(fragmentManager = this, name) + } else { + fragment.showFragment(fragmentManager = this, name) + } + + Timber.d("Route $name is shown") } else { - transaction.replace(R.id.fragment_container, fragment, screen.name) - if (addToBackstack) { - transaction.addToBackStack(screen.name) - } + Timber.d("Route $name is found in backstack and shown") + } +} + +private fun DialogFragment.showDialog(fragmentManager: FragmentManager, name: String) { + val transaction = fragmentManager.beginTransaction() + + try { + transaction.addToBackStack(name) + show(transaction, name) + } catch (e: IllegalStateException) { + transaction.add(this, name) + transaction.addToBackStack(name) + transaction.commitAllowingStateLoss() } } -private fun DialogFragment.showAllowingStateLoss( - fragmentManager: FragmentManager, - baseTransaction: FragmentTransaction, - tag: String, - addToBackstack: Boolean, -) { - runCatching { - if (addToBackstack) baseTransaction.addToBackStack(tag) - show(baseTransaction, tag) - } - .onFailure { throwable -> - if (throwable is IllegalStateException) { - val transaction = fragmentManager.beginTransaction() - transaction.add(this, tag) - if (addToBackstack) transaction.addToBackStack(tag) +private fun Fragment.showFragment(fragmentManager: FragmentManager, name: String) { + val transaction = fragmentManager.beginTransaction() - transaction.commitAllowingStateLoss() - } else { - Timber.e(throwable) - } - } -} + transaction.replace(R.id.fragment_container, this, name) + transaction.addToBackStack(name) -fun FragmentActivity.popBackTo(screen: AppScreen?, inclusive: Boolean = false) { - val inclusiveFlag = if (inclusive) FragmentManager.POP_BACK_STACK_INCLUSIVE else 0 - try { - this.supportFragmentManager.popBackStack(screen?.name, inclusiveFlag) - } catch (e: IllegalStateException) { - Timber.e(e) - } -} - -fun FragmentActivity.getPreviousScreen(): AppScreen? { - val indexOfLastFragment = if (this.supportFragmentManager.backStackEntryCount > 0) { - this.supportFragmentManager.backStackEntryCount - 1 - } else { - 0 - } - val tag = if (indexOfLastFragment < this.supportFragmentManager.backStackEntryCount) { - this.supportFragmentManager.getBackStackEntryAt(indexOfLastFragment).name - } else { - null - } - return tag?.let { AppScreen.valueOf(tag) } -} - -@Suppress("ComplexMethod", "LongMethod") -private fun fragmentFactory(screen: AppScreen): Fragment { - return when (screen) { - AppScreen.Home -> HomeFragment() - AppScreen.OnboardingNote -> OnboardingNoteFragment() - AppScreen.OnboardingWallet -> OnboardingWalletFragment() - AppScreen.OnboardingTwins -> OnboardingTwinsFragment() - AppScreen.OnboardingOther -> OnboardingOtherCardsFragment() - AppScreen.Wallet -> { - store.inject(getDependency = DaggerGraphState::walletRouter).getEntryFragment() - } - AppScreen.Send -> { - val featureToggles = store.inject(getDependency = DaggerGraphState::sendFeatureToggles) - - if (featureToggles.isRedesignedSendEnabled) { - store.inject(getDependency = DaggerGraphState::sendRouter).getEntryFragment() - } else { - SendFragment() - } - } - AppScreen.Details -> { - val featureToggles = store.inject(getDependency = DaggerGraphState::detailsFeatureToggles) - - if (featureToggles.isRedesignEnabled) { - store.inject(DaggerGraphState::detailsEntryPoint).entryFragment() - } else { - DetailsFragment() - } - } - AppScreen.DetailsSecurity -> SecurityModeFragment() - AppScreen.CardSettings -> CardSettingsFragment() - AppScreen.AppSettings -> AppSettingsFragment() - AppScreen.ResetToFactory -> ResetCardFragment() - AppScreen.AccessCodeRecovery -> AccessCodeRecoveryFragment() - AppScreen.Disclaimer -> DisclaimerFragment() - AppScreen.ManageTokens -> TokensListFragment() - AppScreen.AddCustomToken -> AddCustomTokenFragment() - AppScreen.WalletDetails -> { - store.inject(getDependency = DaggerGraphState::tokenDetailsRouter).getEntryFragment() - } - AppScreen.WalletConnectSessions -> WalletConnectFragment() - AppScreen.QrScanning -> { - store.inject(getDependency = DaggerGraphState::qrScanningRouter).getEntryFragment() - } - AppScreen.ReferralProgram -> ReferralFragment() - AppScreen.Swap -> SwapFragment() - AppScreen.Welcome -> WelcomeFragment() - AppScreen.SaveWallet -> SaveWalletBottomSheetFragment() - AppScreen.AppCurrencySelector -> AppCurrencySelectorFragment() - AppScreen.ModalNotification -> ModalNotificationBottomSheetFragment() - } + transaction.commitAllowingStateLoss() } \ No newline at end of file diff --git a/app/src/main/java/com/tangem/tap/common/extensions/Store.kt b/app/src/main/java/com/tangem/tap/common/extensions/Store.kt index d16d3488e2..27fc3c3bc3 100644 --- a/app/src/main/java/com/tangem/tap/common/extensions/Store.kt +++ b/app/src/main/java/com/tangem/tap/common/extensions/Store.kt @@ -1,8 +1,8 @@ package com.tangem.tap.common.extensions -import com.tangem.core.navigation.NavigationAction -import com.tangem.core.navigation.StateDialog +import com.tangem.common.routing.AppRouter import com.tangem.domain.common.extensions.withMainContext +import com.tangem.domain.redux.StateDialog import com.tangem.domain.wallets.models.UserWallet import com.tangem.tap.common.redux.AppState import com.tangem.tap.common.redux.global.GlobalAction @@ -82,12 +82,16 @@ suspend fun dispatchOnMain(vararg actions: Action) { withMainContext { actions.forEach { store.dispatch(it) } } } -fun Store<*>.dispatchOpenUrl(url: String) { - dispatch(NavigationAction.OpenUrl(url)) +fun Store.dispatchOpenUrl(url: String) { + inject(DaggerGraphState::urlOpener).openUrl(url) } -fun Store<*>.dispatchShare(url: String) { - dispatch(NavigationAction.Share(url)) +fun Store.dispatchShare(url: String) { + inject(DaggerGraphState::shareManager).shareText(url) +} + +fun Store.dispatchNavigationAction(action: AppRouter.() -> Unit) { + inject(DaggerGraphState::appRouter).action() } inline fun Store.inject(getDependency: DaggerGraphState.() -> T?): T { diff --git a/app/src/main/java/com/tangem/tap/common/extensions/UI.kt b/app/src/main/java/com/tangem/tap/common/extensions/UI.kt index 524edaded8..b14e9e4090 100644 --- a/app/src/main/java/com/tangem/tap/common/extensions/UI.kt +++ b/app/src/main/java/com/tangem/tap/common/extensions/UI.kt @@ -3,7 +3,10 @@ package com.tangem.tap.common.extensions import android.app.Activity -import android.content.* +import android.content.ClipData +import android.content.ClipboardManager +import android.content.Context +import android.content.ContextWrapper import android.graphics.drawable.Drawable import android.view.View import androidx.annotation.* @@ -78,16 +81,6 @@ fun Context.getFromClipboard(default: CharSequence? = null): CharSequence? { return clipData.getItemAt(0).text } -fun Context.shareText(text: String) { - val sendIntent: Intent = Intent().apply { - action = Intent.ACTION_SEND - putExtra(Intent.EXTRA_TEXT, text) - type = "text/plain" - } - val shareIntent = Intent.createChooser(sendIntent, null) - startActivity(shareIntent) -} - fun View.getString(resId: Int, vararg formatArgs: Any?): String { return context.getString(resId, *formatArgs) } \ No newline at end of file diff --git a/app/src/main/java/com/tangem/tap/common/feedback/FeedbackManager.kt b/app/src/main/java/com/tangem/tap/common/feedback/LegacyFeedbackManager.kt similarity index 67% rename from app/src/main/java/com/tangem/tap/common/feedback/FeedbackManager.kt rename to app/src/main/java/com/tangem/tap/common/feedback/LegacyFeedbackManager.kt index 98aa013e84..e7713995ac 100644 --- a/app/src/main/java/com/tangem/tap/common/feedback/FeedbackManager.kt +++ b/app/src/main/java/com/tangem/tap/common/feedback/LegacyFeedbackManager.kt @@ -2,18 +2,17 @@ package com.tangem.tap.common.feedback import android.content.Context import com.tangem.core.navigation.email.EmailSender -import com.tangem.datasource.config.models.ChatConfig import com.tangem.domain.common.TapWorkarounds import com.tangem.domain.feedback.FeedbackManagerFeatureToggles import com.tangem.domain.feedback.GetFeedbackEmailUseCase import com.tangem.domain.feedback.models.FeedbackEmailType -import com.tangem.tap.common.chat.ChatManager +import com.tangem.domain.models.scan.ScanResponse import com.tangem.tap.common.extensions.inject import com.tangem.tap.common.extensions.sendEmail import com.tangem.tap.common.log.TangemLogCollector import com.tangem.tap.foregroundActivityObserver -import com.tangem.tap.mainScope import com.tangem.tap.proxy.redux.DaggerGraphState +import com.tangem.tap.scope import com.tangem.tap.store import com.tangem.tap.withForegroundActivity import kotlinx.coroutines.launch @@ -25,27 +24,33 @@ import java.io.StringWriter /** [REDACTED_AUTHOR] */ -class FeedbackManager( +class LegacyFeedbackManager( val infoHolder: AdditionalFeedbackInfo, private val logCollector: TangemLogCollector, - private val chatManager: ChatManager, private val feedbackManagerFeatureToggles: FeedbackManagerFeatureToggles, private val getFeedbackEmailUseCase: GetFeedbackEmailUseCase, ) { - private var sessionFeedbackFile: File? = null private var sessionLogsFile: File? = null - fun sendEmail(feedbackData: FeedbackData, onFail: ((Exception) -> Unit)? = null) { + fun sendEmail(feedbackData: FeedbackData, scanResponse: ScanResponse?) { if (feedbackManagerFeatureToggles.isLocalLogsEnabled) { - mainScope.launch { + scope.launch { + val getCardInfo = suspend { + scanResponse ?: error("ScanResponse must be not null") + store.inject(DaggerGraphState::getCardInfoUseCase).invoke(scanResponse).getOrNull() + ?: error("CardInfo must be not null") + } + val email = getFeedbackEmailUseCase( - when (feedbackData) { - is FeedbackEmail -> FeedbackEmailType.DirectUserRequest - is RateCanBeBetterEmail -> FeedbackEmailType.RateCanBeBetter + type = when (feedbackData) { + is FeedbackEmail -> FeedbackEmailType.DirectUserRequest(cardInfo = getCardInfo()) + is RateCanBeBetterEmail -> FeedbackEmailType.RateCanBeBetter(cardInfo = getCardInfo()) is ScanFailsEmail -> FeedbackEmailType.ScanningProblem - is SendTransactionFailedEmail -> FeedbackEmailType.TransactionSendingProblem - else -> FeedbackEmailType.DirectUserRequest + is SendTransactionFailedEmail -> { + FeedbackEmailType.TransactionSendingProblem(cardInfo = getCardInfo()) + } + else -> FeedbackEmailType.DirectUserRequest(cardInfo = getCardInfo()) }, ) @@ -66,46 +71,25 @@ class FeedbackManager( subject = activity.getString(feedbackData.subjectResId), message = feedbackData.joinTogether(activity, infoHolder), file = getLogFile(activity), - onFail = onFail, ) } } } - fun openChat(config: ChatConfig, feedbackData: FeedbackData) { - chatManager.open( - config = config, - createLogsFile = ::getLogFile, - createFeedbackFile = { context -> getFeedbackFile(context, feedbackData) }, - ) - } + fun sendEmail(type: FeedbackEmailType) { + if (!feedbackManagerFeatureToggles.isLocalLogsEnabled) error("LOCAL_LOGS feature toggle must be enabled") - private fun getFeedbackFile(context: Context, feedbackData: FeedbackData): File? { - return try { - if (sessionFeedbackFile != null) { - return sessionFeedbackFile - } - val file = File(context.filesDir, FEEDBACK_FILE) - file.delete() - file.createNewFile() + scope.launch { + val email = getFeedbackEmailUseCase(type = type) - val feedback = feedbackData.run { - prepare(infoHolder) - joinTogether(context, infoHolder) - } - val fileWriter = FileWriter(file) - fileWriter.write(feedback) - fileWriter.close() - - if (file.exists()) { - sessionFeedbackFile = file - sessionFeedbackFile - } else { - null - } - } catch (ex: Exception) { - Timber.e(ex, "Can't create the logs file") - null + store.inject(DaggerGraphState::emailSender).send( + email = EmailSender.Email( + address = email.address, + subject = email.subject, + message = email.message, + attachment = email.file, + ), + ) } } @@ -144,10 +128,9 @@ class FeedbackManager( } } - companion object { + private companion object { const val DEFAULT_SUPPORT_EMAIL = "support@tangem.com" const val S2C_SUPPORT_EMAIL = "cardsupport@start2coin.com" - const val FEEDBACK_FILE = "feedback.txt" const val LOGS_FILE = "logs.txt" } } \ No newline at end of file diff --git a/app/src/main/java/com/tangem/tap/common/feedback/ProxyFeedbackManager.kt b/app/src/main/java/com/tangem/tap/common/feedback/ProxyFeedbackManager.kt new file mode 100644 index 0000000000..d013937813 --- /dev/null +++ b/app/src/main/java/com/tangem/tap/common/feedback/ProxyFeedbackManager.kt @@ -0,0 +1,20 @@ +package com.tangem.tap.common.feedback + +import com.tangem.domain.feedback.FeedbackManager +import com.tangem.domain.feedback.models.FeedbackEmailType +import com.tangem.tap.store +import timber.log.Timber + +internal class ProxyFeedbackManager : FeedbackManager { + + override fun sendEmail(type: FeedbackEmailType) { + val manager = store.state.globalState.feedbackManager + + if (manager == null) { + Timber.e("Feedback manager is not initialized") + return + } + + manager.sendEmail(type) + } +} \ No newline at end of file diff --git a/app/src/main/java/com/tangem/tap/common/finisher/AndroidAppFinisher.kt b/app/src/main/java/com/tangem/tap/common/finisher/AndroidAppFinisher.kt new file mode 100644 index 0000000000..10299c8916 --- /dev/null +++ b/app/src/main/java/com/tangem/tap/common/finisher/AndroidAppFinisher.kt @@ -0,0 +1,27 @@ +package com.tangem.tap.common.finisher + +import android.content.Context +import android.content.Intent +import com.tangem.core.navigation.finisher.AppFinisher +import com.tangem.tap.MainActivity +import com.tangem.tap.foregroundActivityObserver +import com.tangem.tap.withForegroundActivity + +internal class AndroidAppFinisher( + private val appContext: Context, +) : AppFinisher { + + override fun finish() { + foregroundActivityObserver.withForegroundActivity { activity -> + activity.finish() + } + } + + override fun restart() { + val intent = Intent(appContext, MainActivity::class.java).apply { + flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK + } + appContext.startActivity(intent) + Runtime.getRuntime().exit(0) + } +} \ No newline at end of file diff --git a/app/src/main/java/com/tangem/tap/common/pushes/TangemPushNotificationService.kt b/app/src/main/java/com/tangem/tap/common/pushes/TangemPushNotificationService.kt new file mode 100644 index 0000000000..4a207104ca --- /dev/null +++ b/app/src/main/java/com/tangem/tap/common/pushes/TangemPushNotificationService.kt @@ -0,0 +1,103 @@ +package com.tangem.tap.common.pushes + +import android.annotation.SuppressLint +import android.app.NotificationChannel +import android.app.NotificationManager +import android.app.PendingIntent +import android.content.Intent +import android.graphics.Bitmap +import android.net.Uri +import android.os.Build +import androidx.core.app.NotificationCompat +import androidx.core.content.ContextCompat +import androidx.core.graphics.drawable.toBitmap +import coil.executeBlocking +import coil.request.ImageRequest +import com.google.firebase.messaging.FirebaseMessagingService +import com.google.firebase.messaging.RemoteMessage +import com.tangem.domain.common.LogConfig +import com.tangem.tap.MainActivity +import com.tangem.tap.common.images.createCoilImageLoader +import com.tangem.wallet.R +import timber.log.Timber + +@SuppressLint("MissingFirebaseInstanceTokenRefresh") +internal class TangemPushNotificationService : FirebaseMessagingService() { + + override fun onNewToken(token: String) { + super.onNewToken(token) + Timber.d("New FCM token received: $token") + } + + override fun onMessageReceived(message: RemoteMessage) { + super.onMessageReceived(message) + + val notification = message.notification ?: return + val channelId = notification.channelId ?: TANGEM_CHANNEL_ID + + // TODO refactoring: [REDACTED_JIRA] + val intent = Intent(applicationContext, MainActivity::class.java) + intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP) + val pendingIntent = PendingIntent.getActivity( + /* context = */ this, + /* requestCode = */ PUSH_NOTIFICATION_REQUEST_CODE, + /* intent = */ intent, + /* flags = */ PendingIntent.FLAG_ONE_SHOT or PendingIntent.FLAG_IMMUTABLE, + ) + + val notificationBuilder = + NotificationCompat.Builder(applicationContext, channelId) + .setSmallIcon(R.drawable.ic_tangem_24) + .setContentTitle(notification.title) + .setContentText(notification.body) + .setPriority(message.priority) + .setAutoCancel(true) + .setContentIntent(pendingIntent) + .setVibrate(notification.vibrateTimings) + .apply { + notification.imageUrl?.let { uri -> + val bitmap = getBitmapImageFromUrl(uri) + setStyle( + NotificationCompat + .BigPictureStyle() + .bigPicture(bitmap), + ).setLargeIcon(bitmap) + } + } + + val notificationManager = applicationContext.getSystemService(NOTIFICATION_SERVICE) as NotificationManager + + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { + val notificationChannel = NotificationChannel( + channelId, + ContextCompat.getString(applicationContext, R.string.tangem_app_name), + NotificationManager.IMPORTANCE_HIGH, + ) + notificationManager.createNotificationChannel(notificationChannel) + } + + // Generating unique notification id + val uniqueId = (System.currentTimeMillis() % Integer.MAX_VALUE).toInt() + + notificationManager.notify( + /* id = */ uniqueId, + /* notification = */ notificationBuilder.build(), + ) + } + + private fun getBitmapImageFromUrl(url: Uri): Bitmap? { + return createCoilImageLoader( + applicationContext, + logEnabled = LogConfig.imageLoader, + ).executeBlocking( + ImageRequest.Builder(applicationContext) + .data(url) + .build(), + ).drawable?.toBitmap() + } + + private companion object { + const val TANGEM_CHANNEL_ID = "Tangem General" // General channel for notifications + const val PUSH_NOTIFICATION_REQUEST_CODE = 123 + } +} \ No newline at end of file diff --git a/app/src/main/java/com/tangem/tap/common/redux/AppDialog.kt b/app/src/main/java/com/tangem/tap/common/redux/AppDialog.kt index a65014a580..04a76036c3 100644 --- a/app/src/main/java/com/tangem/tap/common/redux/AppDialog.kt +++ b/app/src/main/java/com/tangem/tap/common/redux/AppDialog.kt @@ -1,7 +1,7 @@ package com.tangem.tap.common.redux import com.tangem.common.extensions.VoidCallback -import com.tangem.core.navigation.StateDialog +import com.tangem.domain.redux.StateDialog import com.tangem.tap.common.TestAction import com.tangem.tap.domain.model.Currency import com.tangem.tap.domain.model.WalletAddressData diff --git a/app/src/main/java/com/tangem/tap/common/redux/AppReducer.kt b/app/src/main/java/com/tangem/tap/common/redux/AppReducer.kt index 7adedbed8f..d047620b5e 100644 --- a/app/src/main/java/com/tangem/tap/common/redux/AppReducer.kt +++ b/app/src/main/java/com/tangem/tap/common/redux/AppReducer.kt @@ -1,7 +1,6 @@ package com.tangem.tap.common.redux import com.tangem.tap.common.redux.global.globalReducer -import com.tangem.tap.common.redux.navigation.NavigationReducer import com.tangem.tap.features.details.redux.DetailsReducer import com.tangem.tap.features.details.redux.walletconnect.WalletConnectReducer import com.tangem.tap.features.disclaimer.redux.DisclaimerReducer @@ -23,7 +22,6 @@ fun appReducer(action: Action, state: AppState?, appStateHolder: AppStateHolder) if (action is AppAction.RestoreState) return action.state return AppState( - navigationState = NavigationReducer.reduce(action, state), globalState = globalReducer(action, state, appStateHolder), homeState = HomeReducer.reduce(action, state), onboardingNoteState = OnboardingNoteReducer.reduce(action, state), diff --git a/app/src/main/java/com/tangem/tap/common/redux/AppState.kt b/app/src/main/java/com/tangem/tap/common/redux/AppState.kt index 59b899ee8b..2a83cbf4df 100644 --- a/app/src/main/java/com/tangem/tap/common/redux/AppState.kt +++ b/app/src/main/java/com/tangem/tap/common/redux/AppState.kt @@ -1,13 +1,11 @@ package com.tangem.tap.common.redux -import com.tangem.core.navigation.NavigationState import com.tangem.domain.redux.DomainState import com.tangem.domain.redux.domainStore import com.tangem.domain.redux.global.NetworkServices import com.tangem.tap.common.redux.global.GlobalMiddleware import com.tangem.tap.common.redux.global.GlobalState import com.tangem.tap.common.redux.legacy.LegacyMiddleware -import com.tangem.tap.common.redux.navigation.navigationMiddleware import com.tangem.tap.features.details.redux.DetailsMiddleware import com.tangem.tap.features.details.redux.DetailsState import com.tangem.tap.features.details.redux.walletconnect.WalletConnectMiddleware @@ -40,7 +38,6 @@ import org.rekotlin.Middleware import org.rekotlin.StateType data class AppState( - val navigationState: NavigationState = NavigationState(), val globalState: GlobalState = GlobalState(), val homeState: HomeState = HomeState(), val onboardingNoteState: OnboardingNoteState = OnboardingNoteState(), @@ -73,7 +70,6 @@ data class AppState( fun getMiddleware(): List> { return listOf( logMiddleware, - navigationMiddleware, notificationsMiddleware, GlobalMiddleware.handler, HomeMiddleware.handler, diff --git a/app/src/main/java/com/tangem/tap/common/redux/global/GlobalAction.kt b/app/src/main/java/com/tangem/tap/common/redux/global/GlobalAction.kt index 8439279a0a..ade5d123b2 100644 --- a/app/src/main/java/com/tangem/tap/common/redux/global/GlobalAction.kt +++ b/app/src/main/java/com/tangem/tap/common/redux/global/GlobalAction.kt @@ -2,21 +2,19 @@ package com.tangem.tap.common.redux.global import com.tangem.common.CompletionResult import com.tangem.core.analytics.models.AnalyticsParam -import com.tangem.core.navigation.StateDialog import com.tangem.datasource.config.ConfigManager -import com.tangem.datasource.config.models.ChatConfig import com.tangem.domain.appcurrency.model.AppCurrency import com.tangem.domain.apptheme.model.AppThemeMode import com.tangem.domain.models.scan.ScanResponse +import com.tangem.domain.redux.StateDialog import com.tangem.tap.common.feedback.FeedbackData -import com.tangem.tap.common.feedback.FeedbackManager +import com.tangem.tap.common.feedback.LegacyFeedbackManager import com.tangem.tap.common.redux.DebugErrorAction import com.tangem.tap.common.redux.ErrorAction import com.tangem.tap.common.redux.NotificationAction import com.tangem.tap.domain.TapError import com.tangem.tap.domain.configurable.warningMessage.WarningMessage import com.tangem.tap.domain.configurable.warningMessage.WarningMessagesManager -import com.tangem.tap.features.details.redux.SecurityOption import org.rekotlin.Action sealed class GlobalAction : Action { @@ -75,14 +73,12 @@ sealed class GlobalAction : Action { ) : GlobalAction() data class HideWarningMessage(val warning: WarningMessage) : GlobalAction() - data class UpdateSecurityOptions(val securityOption: SecurityOption) : GlobalAction() data class SetConfigManager(val configManager: ConfigManager) : GlobalAction() data class SetWarningManager(val warningManager: WarningMessagesManager) : GlobalAction() - data class SetFeedbackManager(val feedbackManager: FeedbackManager) : GlobalAction() + data class SetFeedbackManager(val feedbackManager: LegacyFeedbackManager) : GlobalAction() - data class SendEmail(val feedbackData: FeedbackData) : GlobalAction() - data class OpenChat(val feedbackData: FeedbackData, val chatConfig: ChatConfig? = null) : GlobalAction() + data class SendEmail(val feedbackData: FeedbackData, val scanResponse: ScanResponse?) : GlobalAction() object ExchangeManager : GlobalAction() { object Init : GlobalAction() { diff --git a/app/src/main/java/com/tangem/tap/common/redux/global/GlobalMiddleware.kt b/app/src/main/java/com/tangem/tap/common/redux/global/GlobalMiddleware.kt index fc584f6b8e..9c6882deda 100644 --- a/app/src/main/java/com/tangem/tap/common/redux/global/GlobalMiddleware.kt +++ b/app/src/main/java/com/tangem/tap/common/redux/global/GlobalMiddleware.kt @@ -4,12 +4,12 @@ import com.tangem.common.CompletionResult import com.tangem.common.core.TangemSdkError import com.tangem.common.extensions.guard import com.tangem.core.analytics.models.AnalyticsParam -import com.tangem.core.navigation.StateDialog import com.tangem.datasource.config.models.Config import com.tangem.domain.appcurrency.model.AppCurrency import com.tangem.domain.common.LogConfig import com.tangem.domain.models.scan.CardDTO import com.tangem.domain.models.scan.ScanResponse +import com.tangem.domain.redux.StateDialog import com.tangem.tap.common.extensions.* import com.tangem.tap.common.redux.AppState import com.tangem.tap.features.send.redux.SendAction @@ -69,27 +69,10 @@ private fun handleAction(action: Action, appState: () -> AppState?) { } } is GlobalAction.SendEmail -> { - store.state.globalState.feedbackManager?.sendEmail(action.feedbackData) - } - is GlobalAction.OpenChat -> { - val globalState = store.state.globalState - val feedbackManager = globalState.feedbackManager.guard { - store.dispatchDebugErrorNotification("FeedbackManager not initialized") - return - } - val config = globalState.configManager?.config.guard { - store.dispatchDebugErrorNotification("Config not initialized") - return - } - - // if config not set -> try to get it based on a scanResponse.productType - val unsafeChatConfig = action.chatConfig ?: config.sprinklr - - val chatConfig = unsafeChatConfig.guard { - store.dispatchDebugErrorNotification("The chat config is not initialized") - return - } - feedbackManager.openChat(chatConfig, action.feedbackData) + store.state.globalState.feedbackManager?.sendEmail( + feedbackData = action.feedbackData, + scanResponse = action.scanResponse, + ) } is GlobalAction.ExchangeManager.Init -> { val appStateSafe = appState() ?: return 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 7a75d16d87..50f8f85f47 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 @@ -1,11 +1,11 @@ package com.tangem.tap.common.redux.global -import com.tangem.core.navigation.StateDialog import com.tangem.datasource.config.ConfigManager import com.tangem.domain.appcurrency.model.AppCurrency import com.tangem.domain.apptheme.model.AppThemeMode import com.tangem.domain.models.scan.ScanResponse -import com.tangem.tap.common.feedback.FeedbackManager +import com.tangem.domain.redux.StateDialog +import com.tangem.tap.common.feedback.LegacyFeedbackManager import com.tangem.tap.domain.TapWalletManager import com.tangem.tap.domain.configurable.warningMessage.WarningMessagesManager import com.tangem.tap.features.onboarding.OnboardingManager @@ -20,7 +20,7 @@ data class GlobalState( val tapWalletManager: TapWalletManager = TapWalletManager(), val configManager: ConfigManager? = null, val warningManager: WarningMessagesManager? = null, - val feedbackManager: FeedbackManager? = null, + val feedbackManager: LegacyFeedbackManager? = null, val appCurrency: AppCurrency = AppCurrency.Default, val scanCardFailsCounter: Int = 0, val dialog: StateDialog? = null, diff --git a/app/src/main/java/com/tangem/tap/common/redux/legacy/LegacyMiddleware.kt b/app/src/main/java/com/tangem/tap/common/redux/legacy/LegacyMiddleware.kt index 4b7bdcdf15..80d9f694c8 100644 --- a/app/src/main/java/com/tangem/tap/common/redux/legacy/LegacyMiddleware.kt +++ b/app/src/main/java/com/tangem/tap/common/redux/legacy/LegacyMiddleware.kt @@ -1,8 +1,11 @@ package com.tangem.tap.common.redux.legacy +import com.tangem.blockchain.common.AmountType +import com.tangem.domain.feedback.models.BlockchainErrorInfo import com.tangem.domain.redux.LegacyAction import com.tangem.domain.tokens.utils.convertToAmount import com.tangem.tap.common.extensions.inject +import com.tangem.tap.common.extensions.stripZeroPlainString import com.tangem.tap.common.feedback.FeedbackEmail import com.tangem.tap.common.feedback.RateCanBeBetterEmail import com.tangem.tap.common.feedback.SendTransactionFailedEmail @@ -20,10 +23,16 @@ internal object LegacyMiddleware { { action -> when (action) { is LegacyAction.SendEmailRateCanBeBetter -> { - store.state.globalState.feedbackManager?.sendEmail(RateCanBeBetterEmail()) + store.state.globalState.feedbackManager?.sendEmail( + feedbackData = RateCanBeBetterEmail(), + scanResponse = action.scanResponse, + ) } is LegacyAction.SendEmailSupport -> { - store.state.globalState.feedbackManager?.sendEmail(FeedbackEmail()) + store.state.globalState.feedbackManager?.sendEmail( + feedbackData = FeedbackEmail(), + scanResponse = action.scanResponse, + ) } is LegacyAction.StartOnboardingProcess -> { store.dispatch( @@ -32,8 +41,28 @@ internal object LegacyMiddleware { } is LegacyAction.SendEmailTransactionFailed -> { if (store.inject(DaggerGraphState::feedbackManagerFeatureToggles).isLocalLogsEnabled) { + + val amount = action.amount?.convertToAmount(action.cryptoCurrency) + store.inject(DaggerGraphState::saveBlockchainErrorUseCase).invoke( + error = BlockchainErrorInfo( + errorMessage = action.errorMessage, + blockchainId = action.cryptoCurrency.network.id.value, + derivationPath = action.cryptoCurrency.network.derivationPath.value, + destinationAddress = action.destinationAddress.orEmpty(), + tokenSymbol = if (amount?.type is AmountType.Token) { + amount.currencySymbol + } else { + "" + }, + amount = amount?.value?.stripZeroPlainString() ?: "unknown", + fee = action.fee?.convertToAmount(action.cryptoCurrency) + ?.value?.stripZeroPlainString() ?: "unknown", + ), + ) + store.state.globalState.feedbackManager?.sendEmail( - SendTransactionFailedEmail(action.errorMessage), + feedbackData = SendTransactionFailedEmail(action.errorMessage), + scanResponse = action.scanResponse, ) } else { scope.launch { @@ -50,7 +79,8 @@ internal object LegacyMiddleware { ) } store.state.globalState.feedbackManager?.sendEmail( - SendTransactionFailedEmail(action.errorMessage), + feedbackData = SendTransactionFailedEmail(action.errorMessage), + scanResponse = null, ) } } diff --git a/app/src/main/java/com/tangem/tap/common/redux/navigation/NavigationMiddleware.kt b/app/src/main/java/com/tangem/tap/common/redux/navigation/NavigationMiddleware.kt deleted file mode 100644 index ad2b8f3178..0000000000 --- a/app/src/main/java/com/tangem/tap/common/redux/navigation/NavigationMiddleware.kt +++ /dev/null @@ -1,91 +0,0 @@ -package com.tangem.tap.common.redux.navigation - -import android.content.Intent -import android.hardware.biometrics.BiometricManager -import android.os.Build -import android.provider.Settings -import com.tangem.core.navigation.AppScreen -import com.tangem.core.navigation.NavigationAction -import com.tangem.tap.activityResultCaller -import com.tangem.tap.common.CustomTabsManager -import com.tangem.tap.common.extensions.* -import com.tangem.tap.common.redux.AppState -import com.tangem.tap.store -import org.rekotlin.Middleware - -val navigationMiddleware: Middleware = { _, state -> - { next -> - { action -> - if (action is NavigationAction) { - val navState = state()?.navigationState - when (action) { - is NavigationAction.NavigateTo -> { - navState?.activity?.get()?.openFragment( - screen = action.screen, - addToBackstack = action.addToBackstack, - fgShareTransition = action.fragmentShareTransition, - bundle = action.bundle, - ) - } - is NavigationAction.PopBackTo -> { - if (navState?.backStack?.lastOrNull() != action.screen) { - when (val screen = action.screen) { - AppScreen.Home, - AppScreen.Welcome, - -> { - if (navState?.backStack?.contains(screen) == false) { - // Pop back to activity - navState.activity?.get()?.popBackTo(screen = null, inclusive = true) - store.dispatchOnMain(NavigationAction.NavigateTo(screen)) - } else { - navState?.activity?.get()?.popBackTo(screen, action.inclusive) - } - } - else -> { - navState?.activity?.get()?.popBackTo(screen, action.inclusive) - } - } - } - } - is NavigationAction.OpenUrl -> { - navState?.activity?.get()?.let { - CustomTabsManager().openUrl(action.url, it) - } - } - is NavigationAction.OpenDocument -> { - val intent = Intent(Intent.ACTION_VIEW) - intent.data = action.url - navState?.activity?.get()?.startActivity(intent) - } - is NavigationAction.OpenDialog -> store.dispatchDialogShow(action.stateDialog) - is NavigationAction.OpenBiometricsSettings -> { - val settingsAction = when { - Build.VERSION.SDK_INT >= Build.VERSION_CODES.R -> { - Settings.ACTION_BIOMETRIC_ENROLL - } - else -> { - Settings.ACTION_SECURITY_SETTINGS - } - } - val intent = Intent(settingsAction).apply { - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) { - putExtra( - Settings.EXTRA_BIOMETRIC_AUTHENTICATORS_ALLOWED, - BiometricManager.Authenticators.BIOMETRIC_STRONG, - ) - } - } - activityResultCaller.activityResultLauncher?.launch(intent) - } - is NavigationAction.Share -> { - navState?.activity?.get()?.shareText(action.data) - } - is NavigationAction.ActivityCreated, - is NavigationAction.ActivityDestroyed, - -> Unit - } - } - next(action) - } - } -} \ No newline at end of file diff --git a/app/src/main/java/com/tangem/tap/common/redux/navigation/NavigationReducer.kt b/app/src/main/java/com/tangem/tap/common/redux/navigation/NavigationReducer.kt deleted file mode 100644 index 1935d1f5d6..0000000000 --- a/app/src/main/java/com/tangem/tap/common/redux/navigation/NavigationReducer.kt +++ /dev/null @@ -1,39 +0,0 @@ -package com.tangem.tap.common.redux.navigation - -import com.tangem.core.navigation.NavigationAction -import com.tangem.core.navigation.NavigationState -import com.tangem.tap.common.extensions.getPreviousScreen -import com.tangem.tap.common.redux.AppState -import org.rekotlin.Action - -object NavigationReducer { - fun reduce(action: Action, state: AppState): NavigationState = internalReduce(action, state) -} - -private fun internalReduce(action: Action, state: AppState): NavigationState { - val navigationAction = action as? NavigationAction ?: return state.navigationState - val navState = state.navigationState - - return when (navigationAction) { - is NavigationAction.NavigateTo -> { - navState.copy(backStack = navState.backStack + navigationAction.screen) - } - is NavigationAction.PopBackTo -> { - if (navState.backStack.lastOrNull() == navigationAction.screen) return navState - - val screen = navigationAction.screen ?: navState.activity?.get()?.getPreviousScreen() - val index = navState.backStack.lastIndexOf(screen) + 1 - state.navigationState.copy(backStack = navState.backStack.subList(0, index)) - } - is NavigationAction.ActivityCreated -> navState.copy(activity = navigationAction.activity) - is NavigationAction.ActivityDestroyed -> { - when { - // Destroy the activity if it invoked for the same activity. Prevents overwriting to null if there is a - // new scan from the background [REDACTED_TASK_KEY] - navState.activity?.get() == navigationAction.activity.get() -> NavigationState() - else -> navState - } - } - else -> navState - } -} \ No newline at end of file diff --git a/app/src/main/java/com/tangem/tap/common/settings/IntentSettingsManager.kt b/app/src/main/java/com/tangem/tap/common/settings/IntentSettingsManager.kt new file mode 100644 index 0000000000..145073e75c --- /dev/null +++ b/app/src/main/java/com/tangem/tap/common/settings/IntentSettingsManager.kt @@ -0,0 +1,20 @@ +package com.tangem.tap.common.settings + +import android.content.Context +import android.content.Intent +import android.content.Intent.FLAG_ACTIVITY_NEW_TASK +import android.net.Uri +import android.provider.Settings +import com.tangem.core.navigation.settings.SettingsManager + +internal class IntentSettingsManager(val context: Context) : SettingsManager { + override fun openSettings() { + val openSettingsIntent = Intent( + Settings.ACTION_APPLICATION_DETAILS_SETTINGS, + Uri.fromParts("package", context.packageName, null), + ).apply { + flags = FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK + } + context.startActivity(openSettingsIntent) + } +} \ No newline at end of file diff --git a/app/src/main/java/com/tangem/tap/common/share/IntentShareManager.kt b/app/src/main/java/com/tangem/tap/common/share/IntentShareManager.kt new file mode 100644 index 0000000000..51b829de5f --- /dev/null +++ b/app/src/main/java/com/tangem/tap/common/share/IntentShareManager.kt @@ -0,0 +1,22 @@ +package com.tangem.tap.common.share + +import android.content.Intent +import com.tangem.core.navigation.share.ShareManager +import com.tangem.tap.foregroundActivityObserver +import com.tangem.tap.withForegroundActivity + +internal class IntentShareManager : ShareManager { + + override fun shareText(text: String) { + foregroundActivityObserver.withForegroundActivity { activity -> + val sendIntent: Intent = Intent().apply { + action = Intent.ACTION_SEND + putExtra(Intent.EXTRA_TEXT, text) + type = "text/plain" + } + val shareIntent = Intent.createChooser(sendIntent, null) + + activity.startActivity(shareIntent) + } + } +} \ No newline at end of file diff --git a/app/src/main/java/com/tangem/tap/common/ui/RussianCardholdersWarningBottomSheetDialog.kt b/app/src/main/java/com/tangem/tap/common/ui/RussianCardholdersWarningBottomSheetDialog.kt index 64763a6216..5b0ac2e000 100644 --- a/app/src/main/java/com/tangem/tap/common/ui/RussianCardholdersWarningBottomSheetDialog.kt +++ b/app/src/main/java/com/tangem/tap/common/ui/RussianCardholdersWarningBottomSheetDialog.kt @@ -5,7 +5,6 @@ import android.os.Bundle import android.view.LayoutInflater import com.google.android.material.bottomsheet.BottomSheetDialog import com.tangem.core.analytics.Analytics -import com.tangem.core.navigation.NavigationAction import com.tangem.tap.common.analytics.events.Token import com.tangem.tap.common.extensions.dispatchDialogHide import com.tangem.tap.common.extensions.dispatchOpenUrl @@ -44,7 +43,7 @@ class RussianCardholdersWarningBottomSheetDialog( dismiss() } binding?.btnNo?.setOnClickListener { - store.dispatch(NavigationAction.OpenUrl(INSTRUCTION_URL)) + store.dispatchOpenUrl(INSTRUCTION_URL) dismiss() } } diff --git a/app/src/main/java/com/tangem/tap/common/ui/ScanFailsDialog.kt b/app/src/main/java/com/tangem/tap/common/ui/ScanFailsDialog.kt index d59f668687..410f81e1c6 100644 --- a/app/src/main/java/com/tangem/tap/common/ui/ScanFailsDialog.kt +++ b/app/src/main/java/com/tangem/tap/common/ui/ScanFailsDialog.kt @@ -1,37 +1,76 @@ package com.tangem.tap.common.ui import android.content.Context +import android.view.View +import android.widget.TextView import androidx.appcompat.app.AlertDialog -import com.google.android.material.dialog.MaterialAlertDialogBuilder +import androidx.core.view.isVisible import com.tangem.core.analytics.Analytics import com.tangem.core.analytics.models.AnalyticsParam import com.tangem.core.analytics.models.Basic -import com.tangem.core.navigation.StateDialog +import com.tangem.domain.redux.StateDialog +import com.tangem.tap.common.analytics.events.ScanFailsDialogAnalytics import com.tangem.tap.common.extensions.dispatchDialogHide +import com.tangem.tap.common.extensions.dispatchOpenUrl import com.tangem.tap.common.feedback.ScanFailsEmail import com.tangem.tap.common.redux.global.GlobalAction +import com.tangem.tap.features.home.LocaleRegionProvider +import com.tangem.tap.features.home.RUSSIA_COUNTRY_CODE import com.tangem.tap.store import com.tangem.wallet.R /** [REDACTED_AUTHOR] */ -object ScanFailsDialog { - fun create(context: Context, source: StateDialog.ScanFailsSource): AlertDialog { - return MaterialAlertDialogBuilder(context, R.style.CustomMaterialDialog).apply { - setTitle(context.getString(R.string.common_warning)) - setMessage(R.string.alert_troubleshooting_scan_card_title) - setPositiveButton(R.string.alert_button_request_support) { _, _ -> - val sourceAnalytics = when (source) { - StateDialog.ScanFailsSource.MAIN -> AnalyticsParam.ScreensSources.Main - StateDialog.ScanFailsSource.SIGN_IN -> AnalyticsParam.ScreensSources.SignIn - StateDialog.ScanFailsSource.SETTINGS -> AnalyticsParam.ScreensSources.Settings - StateDialog.ScanFailsSource.INTRO -> AnalyticsParam.ScreensSources.Intro - } - Analytics.send(Basic.ButtonSupport(sourceAnalytics)) - store.dispatch(GlobalAction.SendEmail(ScanFailsEmail())) +internal object ScanFailsDialog { + + private const val HOW_TO_SCAN_RU_LINK = "https://tangem.com/ru/blog/post/scan-tangem-card/" + private const val HOW_TO_SCAN_LINK = "https://tangem.com/en/blog/post/scan-tangem-card/" + + fun create(context: Context, source: StateDialog.ScanFailsSource, onTryAgain: (() -> Unit)? = null): AlertDialog { + return AlertDialog.Builder(context, R.style.CustomMaterialDialog).apply { + val customView = View.inflate(context, R.layout.dialog_scan_fails, null) + val sourceAnalytics = when (source) { + StateDialog.ScanFailsSource.MAIN -> AnalyticsParam.ScreensSources.Main + StateDialog.ScanFailsSource.SIGN_IN -> AnalyticsParam.ScreensSources.SignIn + StateDialog.ScanFailsSource.SETTINGS -> AnalyticsParam.ScreensSources.Settings + StateDialog.ScanFailsSource.INTRO -> AnalyticsParam.ScreensSources.Intro } - setNeutralButton(R.string.common_cancel) { _, _ -> } + val tryAgainBtn: TextView? = customView.findViewById(R.id.try_again_button) + if (onTryAgain != null) { + tryAgainBtn?.isVisible = true + tryAgainBtn?.setOnClickListener { + store.dispatchDialogHide() + Analytics.send( + ScanFailsDialogAnalytics( + button = ScanFailsDialogAnalytics.Buttons.TRY_AGAIN, + source = sourceAnalytics, + ), + ) + onTryAgain() + } + } else { + tryAgainBtn?.isVisible = false + } + customView.findViewById(R.id.how_to_scan_button)?.setOnClickListener { + Analytics.send( + ScanFailsDialogAnalytics( + button = ScanFailsDialogAnalytics.Buttons.HOW_TO_SCAN, + source = sourceAnalytics, + ), + ) + val locale = LocaleRegionProvider().getRegion() + val link = if (locale.lowercase() == RUSSIA_COUNTRY_CODE) HOW_TO_SCAN_RU_LINK else HOW_TO_SCAN_LINK + store.dispatchOpenUrl(link) + } + customView.findViewById(R.id.request_support_button)?.setOnClickListener { + Analytics.send(Basic.ButtonSupport(sourceAnalytics)) + store.dispatch(GlobalAction.SendEmail(feedbackData = ScanFailsEmail(), scanResponse = null)) + } + customView.findViewById(R.id.cancel_button)?.setOnClickListener { + store.dispatchDialogHide() + } + setView(customView) setOnDismissListener { store.dispatchDialogHide() } }.create() } diff --git a/app/src/main/java/com/tangem/tap/common/CustomTabsManager.kt b/app/src/main/java/com/tangem/tap/common/url/CustomTabsUrlOpener.kt similarity index 69% rename from app/src/main/java/com/tangem/tap/common/CustomTabsManager.kt rename to app/src/main/java/com/tangem/tap/common/url/CustomTabsUrlOpener.kt index 6f1c8151d6..7fe3ef0081 100644 --- a/app/src/main/java/com/tangem/tap/common/CustomTabsManager.kt +++ b/app/src/main/java/com/tangem/tap/common/url/CustomTabsUrlOpener.kt @@ -1,4 +1,4 @@ -package com.tangem.tap.common +package com.tangem.tap.common.url import android.content.Context import android.net.Uri @@ -6,12 +6,22 @@ import androidx.browser.customtabs.CustomTabColorSchemeParams import androidx.browser.customtabs.CustomTabsIntent import androidx.browser.customtabs.CustomTabsIntent.COLOR_SCHEME_DARK import androidx.browser.customtabs.CustomTabsIntent.COLOR_SCHEME_LIGHT +import com.tangem.core.navigation.url.UrlOpener import com.tangem.tap.common.apptheme.MutableAppThemeModeHolder import com.tangem.tap.common.extensions.getColorCompat +import com.tangem.tap.foregroundActivityObserver +import com.tangem.tap.withForegroundActivity import com.tangem.wallet.R -class CustomTabsManager { - fun openUrl(url: String, context: Context) { +internal class CustomTabsUrlOpener : UrlOpener { + + override fun openUrl(url: String) { + foregroundActivityObserver.withForegroundActivity { + openUrl(url, context = it) + } + } + + private fun openUrl(url: String, context: Context) { if (url.isEmpty()) return val customTabsIntent = CustomTabsIntent.Builder() .setDefaultColorSchemeParams( diff --git a/app/src/main/java/com/tangem/tap/data/RuntimeUserWalletsStore.kt b/app/src/main/java/com/tangem/tap/data/RuntimeUserWalletsStore.kt index bd50b28faf..1661cedb1d 100644 --- a/app/src/main/java/com/tangem/tap/data/RuntimeUserWalletsStore.kt +++ b/app/src/main/java/com/tangem/tap/data/RuntimeUserWalletsStore.kt @@ -1,9 +1,11 @@ package com.tangem.tap.data +import com.tangem.common.CompletionResult import com.tangem.datasource.local.userwallet.UserWalletsStore import com.tangem.domain.wallets.legacy.UserWalletsListManager import com.tangem.domain.wallets.models.UserWallet import com.tangem.domain.wallets.models.UserWalletId +import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.firstOrNull // FIXME: Workaround, remove it once the normal UserWalletsStore has been implemented @@ -15,6 +17,9 @@ internal class RuntimeUserWalletsStore( override val selectedUserWalletOrNull: UserWallet? get() = userWalletsListManager.selectedUserWalletSync + override val userWallets: Flow> + get() = userWalletsListManager.userWallets + override suspend fun getSyncOrNull(key: UserWalletId): UserWallet? { return userWalletsListManager .userWallets @@ -26,7 +31,10 @@ internal class RuntimeUserWalletsStore( return userWalletsListManager.userWallets.firstOrNull() } - override suspend fun update(userWalletId: UserWalletId, update: suspend (UserWallet) -> UserWallet) { - userWalletsListManager.update(userWalletId, update) + override suspend fun update( + userWalletId: UserWalletId, + update: suspend (UserWallet) -> UserWallet, + ): CompletionResult { + return userWalletsListManager.update(userWalletId, update) } } \ No newline at end of file diff --git a/app/src/main/java/com/tangem/tap/di/ActivityModule.kt b/app/src/main/java/com/tangem/tap/di/ActivityModule.kt index cbf8eebb27..62f28c043e 100644 --- a/app/src/main/java/com/tangem/tap/di/ActivityModule.kt +++ b/app/src/main/java/com/tangem/tap/di/ActivityModule.kt @@ -6,10 +6,8 @@ import com.tangem.domain.exchange.RampStateManager import com.tangem.domain.tokens.GetPolkadotCheckHasImmortalUseCase import com.tangem.domain.tokens.GetPolkadotCheckHasResetUseCase import com.tangem.domain.tokens.repository.PolkadotAccountHealthCheckRepository -import com.tangem.feature.tester.ActivityClassWrapper -import com.tangem.tap.MainActivity -import com.tangem.tap.domain.sdk.TangemSdkManager import com.tangem.tap.domain.scanCard.repository.DefaultScanCardRepository +import com.tangem.tap.domain.sdk.TangemSdkManager import com.tangem.tap.network.exchangeServices.DefaultRampManager import com.tangem.tap.proxy.AppStateHolder import dagger.Module @@ -67,10 +65,4 @@ internal object ActivityModule { ): GetPolkadotCheckHasImmortalUseCase { return GetPolkadotCheckHasImmortalUseCase(polkadotAccountHealthCheckRepository) } - - @Provides - @Singleton - fun provideActivityClassWrapper(): ActivityClassWrapper { - return ActivityClassWrapper(MainActivity::class.java) - } } \ No newline at end of file diff --git a/app/src/main/java/com/tangem/tap/di/AppStateHolderModule.kt b/app/src/main/java/com/tangem/tap/di/AppStateHolderModule.kt index c6e0267c6b..267fa733f1 100644 --- a/app/src/main/java/com/tangem/tap/di/AppStateHolderModule.kt +++ b/app/src/main/java/com/tangem/tap/di/AppStateHolderModule.kt @@ -1,6 +1,5 @@ package com.tangem.tap.di -import com.tangem.core.navigation.ReduxNavController import com.tangem.domain.redux.ReduxStateHolder import com.tangem.tap.proxy.AppStateHolder import dagger.Binds @@ -13,10 +12,6 @@ import javax.inject.Singleton @InstallIn(SingletonComponent::class) internal interface AppStateHolderModule { - @Binds - @Singleton - fun bindsNavigationStateHolder(appStateHolder: AppStateHolder): ReduxNavController - @Binds @Singleton fun bindsReduxStateHolder(appStateHolder: AppStateHolder): ReduxStateHolder diff --git a/app/src/main/java/com/tangem/tap/di/RootAppComponentContextModule.kt b/app/src/main/java/com/tangem/tap/di/RootAppComponentContextModule.kt index b23a41b8a8..1128b32708 100644 --- a/app/src/main/java/com/tangem/tap/di/RootAppComponentContextModule.kt +++ b/app/src/main/java/com/tangem/tap/di/RootAppComponentContextModule.kt @@ -7,8 +7,7 @@ import com.tangem.core.decompose.context.AppComponentContext import com.tangem.core.decompose.context.DefaultAppComponentContext import com.tangem.core.decompose.di.DecomposeComponent import com.tangem.core.decompose.di.RootAppComponentContext -import com.tangem.core.decompose.ui.UiMessage -import com.tangem.core.decompose.ui.UiMessageHandler +import com.tangem.core.ui.UiDependencies import com.tangem.utils.coroutines.CoroutineDispatcherProvider import dagger.Module import dagger.Provides @@ -16,7 +15,6 @@ import dagger.hilt.InstallIn import dagger.hilt.android.components.ActivityComponent import dagger.hilt.android.qualifiers.ActivityContext import dagger.hilt.android.scopes.ActivityScoped -import timber.log.Timber @Module @InstallIn(ActivityComponent::class) @@ -29,17 +27,11 @@ internal object RootAppComponentContextModule { @ActivityContext context: Context, dispatchers: CoroutineDispatcherProvider, componentBuilder: DecomposeComponent.Builder, + uiDependencies: UiDependencies, ): AppComponentContext { - // TODO: Implement message handler - val dummyMessageHandler = object : UiMessageHandler { - override fun handleMessage(message: UiMessage) { - Timber.w("Unable to handle message: $message") - } - } - return DefaultAppComponentContext( componentContext = (context as AppCompatActivity).defaultComponentContext(), - messageHandler = dummyMessageHandler, + messageHandler = uiDependencies.eventMessageHandler, dispatchers = dispatchers, hiltComponentBuilder = componentBuilder, ) diff --git a/app/src/main/java/com/tangem/tap/di/UiDependenciesModule.kt b/app/src/main/java/com/tangem/tap/di/UiDependenciesModule.kt index 97b0f48bee..22a522e553 100644 --- a/app/src/main/java/com/tangem/tap/di/UiDependenciesModule.kt +++ b/app/src/main/java/com/tangem/tap/di/UiDependenciesModule.kt @@ -1,7 +1,9 @@ package com.tangem.tap.di +import androidx.compose.material3.SnackbarHostState import com.tangem.core.ui.UiDependencies import com.tangem.core.ui.haptic.HapticManager +import com.tangem.core.ui.message.EventMessageHandler import com.tangem.core.ui.theme.AppThemeModeHolder import dagger.Module import dagger.Provides @@ -19,6 +21,8 @@ internal object UiDependenciesModule { return object : UiDependencies { override val hapticManager = hapticManager override val appThemeModeHolder = appThemeModeHolder + override val globalSnackbarHostState: SnackbarHostState = SnackbarHostState() + override val eventMessageHandler: EventMessageHandler = EventMessageHandler() } } } \ No newline at end of file diff --git a/app/src/main/java/com/tangem/tap/di/UtilsModule.kt b/app/src/main/java/com/tangem/tap/di/UtilsModule.kt new file mode 100644 index 0000000000..9c29c8598b --- /dev/null +++ b/app/src/main/java/com/tangem/tap/di/UtilsModule.kt @@ -0,0 +1,44 @@ +package com.tangem.tap.di + +import android.content.Context +import com.tangem.core.navigation.finisher.AppFinisher +import com.tangem.core.navigation.settings.SettingsManager +import com.tangem.core.navigation.share.ShareManager +import com.tangem.core.navigation.url.UrlOpener +import com.tangem.domain.feedback.FeedbackManager +import com.tangem.tap.common.feedback.ProxyFeedbackManager +import com.tangem.tap.common.finisher.AndroidAppFinisher +import com.tangem.tap.common.settings.IntentSettingsManager +import com.tangem.tap.common.share.IntentShareManager +import com.tangem.tap.common.url.CustomTabsUrlOpener +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) +internal object UtilsModule { + + @Provides + @Singleton + fun provideShareManager(): ShareManager = IntentShareManager() + + @Provides + @Singleton + fun provideUrlOpener(): UrlOpener = CustomTabsUrlOpener() + + @Provides + @Singleton + fun provideFeedbackManager(): FeedbackManager = ProxyFeedbackManager() + + @Provides + @Singleton + fun provideAppFinisher(@ApplicationContext context: Context): AppFinisher = AndroidAppFinisher(context) + + @Provides + @Singleton + fun provideSettingsManager(@ApplicationContext context: Context): SettingsManager = IntentSettingsManager(context) +} \ No newline at end of file diff --git a/app/src/main/java/com/tangem/tap/di/analytics/AnalyticsModule.kt b/app/src/main/java/com/tangem/tap/di/analytics/AnalyticsModule.kt index 34dbbd2e11..c687d63c10 100644 --- a/app/src/main/java/com/tangem/tap/di/analytics/AnalyticsModule.kt +++ b/app/src/main/java/com/tangem/tap/di/analytics/AnalyticsModule.kt @@ -1,6 +1,8 @@ package com.tangem.tap.di.analytics +import com.tangem.core.analytics.utils.AnalyticsContextProxy import com.tangem.domain.analytics.ChangeCardAnalyticsContextUseCase +import com.tangem.tap.common.analytics.DefaultAnalyticsContextProxy import com.tangem.tap.common.analytics.DefaultChangeCardAnalyticsContextUseCase import dagger.Module import dagger.Provides @@ -17,4 +19,8 @@ internal object AnalyticsModule { fun provideChangeCardAnalyticsContextUseCase(): ChangeCardAnalyticsContextUseCase { return DefaultChangeCardAnalyticsContextUseCase() } + + @Provides + @Singleton + fun provideAnalyticsContextProxy(): AnalyticsContextProxy = DefaultAnalyticsContextProxy() } \ No newline at end of file diff --git a/app/src/main/java/com/tangem/tap/di/domain/CardDomainModule.kt b/app/src/main/java/com/tangem/tap/di/domain/CardDomainModule.kt index 3d1b711ccf..0f3fab437c 100644 --- a/app/src/main/java/com/tangem/tap/di/domain/CardDomainModule.kt +++ b/app/src/main/java/com/tangem/tap/di/domain/CardDomainModule.kt @@ -84,4 +84,10 @@ internal object CardDomainModule { fun provideResetCardUseCase(tangemSdkManager: TangemSdkManager): ResetCardUseCase { return DefaultResetCardUseCase(tangemSdkManager) } + + @Provides + @Singleton + fun provideNetworkHasDerivationUseCase(): NetworkHasDerivationUseCase { + return NetworkHasDerivationUseCase() + } } \ No newline at end of file diff --git a/app/src/main/java/com/tangem/tap/di/domain/FeedbackDomainModule.kt b/app/src/main/java/com/tangem/tap/di/domain/FeedbackDomainModule.kt index 033e322536..04f4f03fb8 100644 --- a/app/src/main/java/com/tangem/tap/di/domain/FeedbackDomainModule.kt +++ b/app/src/main/java/com/tangem/tap/di/domain/FeedbackDomainModule.kt @@ -1,6 +1,7 @@ package com.tangem.tap.di.domain import android.content.Context +import com.tangem.domain.feedback.GetCardInfoUseCase import com.tangem.domain.feedback.GetFeedbackEmailUseCase import com.tangem.domain.feedback.SaveBlockchainErrorUseCase import com.tangem.domain.feedback.repository.FeedbackRepository @@ -15,6 +16,12 @@ import javax.inject.Singleton @InstallIn(SingletonComponent::class) internal object FeedbackDomainModule { + @Provides + @Singleton + fun provideGetCardInfoUseCase(feedbackRepository: FeedbackRepository): GetCardInfoUseCase { + return GetCardInfoUseCase(feedbackRepository = feedbackRepository) + } + @Provides @Singleton fun provideGetFeedbackEmailUseCase( diff --git a/app/src/main/java/com/tangem/tap/di/domain/MarketsDomainModule.kt b/app/src/main/java/com/tangem/tap/di/domain/MarketsDomainModule.kt new file mode 100644 index 0000000000..765e3bcb7f --- /dev/null +++ b/app/src/main/java/com/tangem/tap/di/domain/MarketsDomainModule.kt @@ -0,0 +1,22 @@ +package com.tangem.tap.di.domain + +import com.tangem.domain.markets.GetMarketsTokenListFlowUseCase +import com.tangem.domain.markets.repositories.MarketsTokenRepository +import dagger.Module +import dagger.Provides +import dagger.hilt.InstallIn +import dagger.hilt.components.SingletonComponent +import javax.inject.Singleton + +@Module +@InstallIn(SingletonComponent::class) +object MarketsDomainModule { + + @Provides + @Singleton + fun provideGetMarketsTokenListFlowUseCase( + marketsTokenRepository: MarketsTokenRepository, + ): GetMarketsTokenListFlowUseCase { + return GetMarketsTokenListFlowUseCase(marketsTokenRepository = marketsTokenRepository) + } +} \ No newline at end of file diff --git a/app/src/main/java/com/tangem/tap/di/domain/SettingsDomainModule.kt b/app/src/main/java/com/tangem/tap/di/domain/SettingsDomainModule.kt index bac2d55655..c05129c777 100644 --- a/app/src/main/java/com/tangem/tap/di/domain/SettingsDomainModule.kt +++ b/app/src/main/java/com/tangem/tap/di/domain/SettingsDomainModule.kt @@ -7,6 +7,7 @@ import com.tangem.domain.balancehiding.UpdateBalanceHidingSettingsUseCase import com.tangem.domain.balancehiding.repositories.BalanceHidingRepository import com.tangem.domain.settings.* import com.tangem.domain.settings.repositories.AppRatingRepository +import com.tangem.domain.settings.repositories.PermissionRepository import com.tangem.domain.settings.repositories.PromoSettingsRepository import com.tangem.domain.settings.repositories.SettingsRepository import com.tangem.tap.domain.sdk.TangemSdkManager @@ -17,6 +18,7 @@ import dagger.hilt.InstallIn import dagger.hilt.components.SingletonComponent import javax.inject.Singleton +@Suppress("TooManyFunctions") @Module @InstallIn(SingletonComponent::class) internal object SettingsDomainModule { @@ -164,4 +166,36 @@ internal object SettingsDomainModule { ): IncrementAppLaunchCounterUseCase { return IncrementAppLaunchCounterUseCase(settingsRepository = settingsRepository) } + + // region PushPermissionRepository + @Provides + @Singleton + fun provideShouldInitiallyAskPermissionUseCase( + permissionRepository: PermissionRepository, + ): ShouldInitiallyAskPermissionUseCase { + return ShouldInitiallyAskPermissionUseCase(repository = permissionRepository) + } + + @Provides + @Singleton + fun provideNeverToInitiallyAskPermissionUseCase( + permissionRepository: PermissionRepository, + ): NeverToInitiallyAskPermissionUseCase { + return NeverToInitiallyAskPermissionUseCase(repository = permissionRepository) + } + + @Provides + @Singleton + fun provideShouldAskPermissionUseCase(permissionRepository: PermissionRepository): ShouldAskPermissionUseCase { + return ShouldAskPermissionUseCase(repository = permissionRepository) + } + + @Provides + @Singleton + fun provideNeverRequestPermissionUseCase( + permissionRepository: PermissionRepository, + ): NeverRequestPermissionUseCase { + return NeverRequestPermissionUseCase(repository = permissionRepository) + } + // endregion } \ No newline at end of file diff --git a/app/src/main/java/com/tangem/tap/di/domain/StakingDomainModule.kt b/app/src/main/java/com/tangem/tap/di/domain/StakingDomainModule.kt index 54bfe9d2b7..c280208083 100644 --- a/app/src/main/java/com/tangem/tap/di/domain/StakingDomainModule.kt +++ b/app/src/main/java/com/tangem/tap/di/domain/StakingDomainModule.kt @@ -1,8 +1,7 @@ package com.tangem.tap.di.domain -import com.tangem.domain.settings.* -import com.tangem.domain.staking.GetStakingAvailabilityUseCase -import com.tangem.domain.staking.GetStakingEntryInfoUseCase +import com.tangem.domain.staking.* +import com.tangem.domain.staking.repositories.StakingErrorResolver import com.tangem.domain.staking.repositories.StakingRepository import dagger.Module import dagger.Provides @@ -16,17 +15,145 @@ internal object StakingDomainModule { @Provides @Singleton - fun provideGetStakingEntryInfoUseCase(stakingRepository: StakingRepository): GetStakingEntryInfoUseCase { - return GetStakingEntryInfoUseCase( + fun provideGetStakingAvailabilityUseCase( + stakingRepository: StakingRepository, + stakingErrorResolver: StakingErrorResolver, + ): GetStakingAvailabilityUseCase { + return GetStakingAvailabilityUseCase( stakingRepository = stakingRepository, + stakingErrorResolver = stakingErrorResolver, ) } @Provides @Singleton - fun provideGetStakingAvailabilityUseCase(stakingRepository: StakingRepository): GetStakingAvailabilityUseCase { - return GetStakingAvailabilityUseCase( + fun provideGetStakingEntryInfoUseCase( + stakingRepository: StakingRepository, + stakingErrorResolver: StakingErrorResolver, + ): GetStakingEntryInfoUseCase { + return GetStakingEntryInfoUseCase( stakingRepository = stakingRepository, + stakingErrorResolver = stakingErrorResolver, + ) + } + + @Provides + @Singleton + fun provideGetYieldUseCase( + stakingRepository: StakingRepository, + stakingErrorResolver: StakingErrorResolver, + ): GetYieldUseCase { + return GetYieldUseCase( + stakingRepository = stakingRepository, + stakingErrorResolver = stakingErrorResolver, + ) + } + + @Provides + @Singleton + fun provideGetStakingTokensUseCase( + stakingRepository: StakingRepository, + stakingErrorResolver: StakingErrorResolver, + ): FetchStakingTokensUseCase { + return FetchStakingTokensUseCase( + stakingRepository = stakingRepository, + stakingErrorResolver = stakingErrorResolver, + ) + } + + @Provides + @Singleton + fun provideFetchStakingYieldBalanceUseCase( + stakingRepository: StakingRepository, + stakingErrorResolver: StakingErrorResolver, + ): FetchStakingYieldBalanceUseCase { + return FetchStakingYieldBalanceUseCase( + stakingRepository = stakingRepository, + stakingErrorResolver = stakingErrorResolver, + ) + } + + @Provides + @Singleton + fun provideGetStakingYieldBalanceUseCase( + stakingRepository: StakingRepository, + stakingErrorResolver: StakingErrorResolver, + ): GetStakingYieldBalanceUseCase { + return GetStakingYieldBalanceUseCase( + stakingRepository = stakingRepository, + stakingErrorResolver = stakingErrorResolver, + ) + } + + @Provides + @Singleton + fun provideInitializeStakingProcessUseCase( + stakingRepository: StakingRepository, + stakingErrorResolver: StakingErrorResolver, + ): GetStakingTransactionUseCase { + return GetStakingTransactionUseCase( + stakingRepository = stakingRepository, + stakingErrorResolver = stakingErrorResolver, + ) + } + + @Provides + @Singleton + fun provideGasEstimateUseCase( + stakingRepository: StakingRepository, + stakingErrorResolver: StakingErrorResolver, + ): EstimateGasUseCase { + return EstimateGasUseCase( + stakingRepository = stakingRepository, + stakingErrorResolver = stakingErrorResolver, + ) + } + + @Provides + @Singleton + fun provideSubmitHashUseCase( + stakingRepository: StakingRepository, + stakingErrorResolver: StakingErrorResolver, + ): SubmitHashUseCase { + return SubmitHashUseCase( + stakingRepository = stakingRepository, + stakingErrorResolver = stakingErrorResolver, + ) + } + + @Provides + @Singleton + fun provideSaveUnsubmittedHashUseCase( + stakingRepository: StakingRepository, + stakingErrorResolver: StakingErrorResolver, + ): SaveUnsubmittedHashUseCase { + return SaveUnsubmittedHashUseCase( + stakingRepository = stakingRepository, + stakingErrorResolver = stakingErrorResolver, + ) + } + + @Provides + @Singleton + fun provideSendUnsubmittedHashesUseCase( + stakingRepository: StakingRepository, + stakingErrorResolver: StakingErrorResolver, + ): SendUnsubmittedHashesUseCase { + return SendUnsubmittedHashesUseCase( + stakingRepository = stakingRepository, + stakingErrorResolver = stakingErrorResolver, + ) + } + + @Provides + @Singleton + fun provideIsStakeMoreAvailableUseCase( + stakingRepository: StakingRepository, + stakingErrorResolver: StakingErrorResolver, + ): IsStakeMoreAvailableUseCase { + return IsStakeMoreAvailableUseCase( + stakingRepository = stakingRepository, + stakingErrorResolver = stakingErrorResolver, ) } } \ No newline at end of file diff --git a/app/src/main/java/com/tangem/tap/di/domain/TokensDomainModule.kt b/app/src/main/java/com/tangem/tap/di/domain/TokensDomainModule.kt index 5990835735..09792b495e 100644 --- a/app/src/main/java/com/tangem/tap/di/domain/TokensDomainModule.kt +++ b/app/src/main/java/com/tangem/tap/di/domain/TokensDomainModule.kt @@ -2,10 +2,12 @@ package com.tangem.tap.di.domain import com.tangem.domain.exchange.RampStateManager import com.tangem.domain.settings.ShouldShowSwapPromoTokenUseCase +import com.tangem.domain.staking.repositories.StakingRepository import com.tangem.domain.tokens.* import com.tangem.domain.tokens.repository.* import com.tangem.domain.walletmanager.WalletManagersFacade import com.tangem.feature.swap.domain.api.SwapRepository +import com.tangem.features.staking.api.featuretoggles.StakingFeatureToggles import com.tangem.utils.coroutines.CoroutineDispatcherProvider import dagger.Module import dagger.Provides @@ -54,8 +56,14 @@ internal object TokensDomainModule { currenciesRepository: CurrenciesRepository, quotesRepository: QuotesRepository, networksRepository: NetworksRepository, + stakingRepository: StakingRepository, ): GetTokenListUseCase { - return GetTokenListUseCase(currenciesRepository, quotesRepository, networksRepository) + return GetTokenListUseCase( + currenciesRepository, + quotesRepository, + networksRepository, + stakingRepository, + ) } @Provides @@ -64,8 +72,9 @@ internal object TokensDomainModule { currenciesRepository: CurrenciesRepository, quotesRepository: QuotesRepository, networksRepository: NetworksRepository, + stakingRepository: StakingRepository, ): GetCardTokensListUseCase { - return GetCardTokensListUseCase(currenciesRepository, quotesRepository, networksRepository) + return GetCardTokensListUseCase(currenciesRepository, quotesRepository, networksRepository, stakingRepository) } @Provides @@ -83,9 +92,16 @@ internal object TokensDomainModule { currenciesRepository: CurrenciesRepository, quotesRepository: QuotesRepository, networksRepository: NetworksRepository, + stakingRepository: StakingRepository, dispatchers: CoroutineDispatcherProvider, ): GetCurrencyStatusUpdatesUseCase { - return GetCurrencyStatusUpdatesUseCase(currenciesRepository, quotesRepository, networksRepository, dispatchers) + return GetCurrencyStatusUpdatesUseCase( + currenciesRepository, + quotesRepository, + networksRepository, + stakingRepository, + dispatchers, + ) } @Provides @@ -100,6 +116,7 @@ internal object TokensDomainModule { currencyChecksRepository: CurrencyChecksRepository, showSwapPromoTokenUseCase: ShouldShowSwapPromoTokenUseCase, promoRepository: PromoRepository, + stakingRepository: StakingRepository, dispatchers: CoroutineDispatcherProvider, ): GetCurrencyWarningsUseCase { return GetCurrencyWarningsUseCase( @@ -112,6 +129,7 @@ internal object TokensDomainModule { swapRepository = swapRepository, showSwapPromoTokenUseCase = showSwapPromoTokenUseCase, promoRepository = promoRepository, + stakingRepository = stakingRepository, dispatchers = dispatchers, ) } @@ -122,12 +140,14 @@ internal object TokensDomainModule { currenciesRepository: CurrenciesRepository, quotesRepository: QuotesRepository, networksRepository: NetworksRepository, + stakingRepository: StakingRepository, dispatchers: CoroutineDispatcherProvider, ): GetPrimaryCurrencyStatusUpdatesUseCase { return GetPrimaryCurrencyStatusUpdatesUseCase( currenciesRepository, quotesRepository, networksRepository, + stakingRepository, dispatchers, ) } @@ -148,8 +168,9 @@ internal object TokensDomainModule { currenciesRepository: CurrenciesRepository, quotesRepository: QuotesRepository, networksRepository: NetworksRepository, + stakingRepository: StakingRepository, ): FetchCardTokenListUseCase { - return FetchCardTokenListUseCase(currenciesRepository, networksRepository, quotesRepository) + return FetchCardTokenListUseCase(currenciesRepository, networksRepository, quotesRepository, stakingRepository) } @Provides @@ -190,6 +211,8 @@ internal object TokensDomainModule { currenciesRepository: CurrenciesRepository, quotesRepository: QuotesRepository, networksRepository: NetworksRepository, + stakingRepository: StakingRepository, + stakingFeatureToggles: StakingFeatureToggles, dispatchers: CoroutineDispatcherProvider, ): GetCryptoCurrencyActionsUseCase { return GetCryptoCurrencyActionsUseCase( @@ -199,6 +222,8 @@ internal object TokensDomainModule { currenciesRepository = currenciesRepository, quotesRepository = quotesRepository, networksRepository = networksRepository, + stakingRepository = stakingRepository, + stakingFeatureToggles = stakingFeatureToggles, dispatchers = dispatchers, ) } @@ -209,12 +234,14 @@ internal object TokensDomainModule { currenciesRepository: CurrenciesRepository, quotesRepository: QuotesRepository, networksRepository: NetworksRepository, + stakingRepository: StakingRepository, dispatchers: CoroutineDispatcherProvider, ): GetNetworkCoinStatusUseCase { return GetNetworkCoinStatusUseCase( currenciesRepository = currenciesRepository, quotesRepository = quotesRepository, networksRepository = networksRepository, + stakingRepository = stakingRepository, dispatchers = dispatchers, ) } @@ -225,12 +252,14 @@ internal object TokensDomainModule { currenciesRepository: CurrenciesRepository, quotesRepository: QuotesRepository, networksRepository: NetworksRepository, + stakingRepository: StakingRepository, dispatchers: CoroutineDispatcherProvider, ): GetFeePaidCryptoCurrencyStatusSyncUseCase { return GetFeePaidCryptoCurrencyStatusSyncUseCase( currenciesRepository = currenciesRepository, quotesRepository = quotesRepository, networksRepository = networksRepository, + stakingRepository = stakingRepository, dispatchers = dispatchers, ) } @@ -363,11 +392,13 @@ internal object TokensDomainModule { currenciesRepository: CurrenciesRepository, quotesRepository: QuotesRepository, networksRepository: NetworksRepository, + stakingRepository: StakingRepository, ): GetWalletTotalBalanceUseCase { return GetWalletTotalBalanceUseCase( currenciesRepository = currenciesRepository, quotesRepository = quotesRepository, networksRepository = networksRepository, + stakingRepository = stakingRepository, ) } diff --git a/app/src/main/java/com/tangem/tap/di/domain/TransactionDomainModule.kt b/app/src/main/java/com/tangem/tap/di/domain/TransactionDomainModule.kt index 9635e67a29..8af69450c8 100644 --- a/app/src/main/java/com/tangem/tap/di/domain/TransactionDomainModule.kt +++ b/app/src/main/java/com/tangem/tap/di/domain/TransactionDomainModule.kt @@ -64,6 +64,23 @@ internal object TransactionDomainModule { return CreateTransactionUseCase(transactionRepository) } + @Provides + @Singleton + fun provideCreateTransactionExtrasUseCase( + transactionRepository: TransactionRepository, + ): CreateTransactionDataExtrasUseCase { + return CreateTransactionDataExtrasUseCase(transactionRepository) + } + + @Provides + @Singleton + fun provideEstimateFeeUseCase(walletManagersFacade: WalletManagersFacade): EstimateFeeUseCase { + return EstimateFeeUseCase( + walletManagersFacade = walletManagersFacade, + demoConfig = DemoConfig(), + ) + } + @Provides @Singleton fun provideIsFeeApproximateUseCase(feeRepository: FeeRepository): IsFeeApproximateUseCase { diff --git a/app/src/main/java/com/tangem/tap/di/domain/WalletsDomainModule.kt b/app/src/main/java/com/tangem/tap/di/domain/WalletsDomainModule.kt index 3dfc085c10..cc9b89e775 100644 --- a/app/src/main/java/com/tangem/tap/di/domain/WalletsDomainModule.kt +++ b/app/src/main/java/com/tangem/tap/di/domain/WalletsDomainModule.kt @@ -1,12 +1,12 @@ package com.tangem.tap.di.domain import com.tangem.domain.redux.ReduxStateHolder -import com.tangem.domain.walletmanager.WalletManagersFacade -import com.tangem.domain.wallets.legacy.UserWalletsListManager import com.tangem.domain.transaction.WalletAddressServiceRepository import com.tangem.domain.transaction.usecase.ParseSharedAddressUseCase import com.tangem.domain.transaction.usecase.ValidateWalletAddressUseCase import com.tangem.domain.transaction.usecase.ValidateWalletMemoUseCase +import com.tangem.domain.walletmanager.WalletManagersFacade +import com.tangem.domain.wallets.legacy.UserWalletsListManager import com.tangem.domain.wallets.repository.WalletNamesMigrationRepository import com.tangem.domain.wallets.repository.WalletsRepository import com.tangem.domain.wallets.usecase.* @@ -95,8 +95,11 @@ internal object WalletsDomainModule { @Provides @Singleton - fun providesRenameWalletUseCase(userWalletsListManager: UserWalletsListManager): RenameWalletUseCase { - return RenameWalletUseCase(userWalletsListManager = userWalletsListManager) + fun providesRenameWalletUseCase( + userWalletsListManager: UserWalletsListManager, + dispatchers: CoroutineDispatcherProvider, + ): RenameWalletUseCase { + return RenameWalletUseCase(userWalletsListManager = userWalletsListManager, dispatchers = dispatchers) } @Provides diff --git a/app/src/main/java/com/tangem/tap/di/routing/AppRouterModule.kt b/app/src/main/java/com/tangem/tap/di/routing/AppRouterModule.kt new file mode 100644 index 0000000000..4f4aa7e79b --- /dev/null +++ b/app/src/main/java/com/tangem/tap/di/routing/AppRouterModule.kt @@ -0,0 +1,26 @@ +package com.tangem.tap.di.routing + +import com.tangem.common.routing.AppRouter +import com.tangem.tap.routing.ProxyAppRouter +import com.tangem.tap.routing.configurator.AppRouterConfig +import com.tangem.tap.routing.configurator.MutableAppRouterConfig +import com.tangem.utils.coroutines.CoroutineDispatcherProvider +import dagger.Module +import dagger.Provides +import dagger.hilt.InstallIn +import dagger.hilt.components.SingletonComponent +import javax.inject.Singleton + +@Module +@InstallIn(SingletonComponent::class) +internal object AppRouterModule { + + @Provides + @Singleton + fun provideAppRouter(config: AppRouterConfig, dispatchers: CoroutineDispatcherProvider): AppRouter = + ProxyAppRouter(config, dispatchers) + + @Provides + @Singleton + fun provideAppRouterConfigurator(): AppRouterConfig = MutableAppRouterConfig() +} \ No newline at end of file diff --git a/app/src/main/java/com/tangem/tap/di/routing/RoutingComponentModule.kt b/app/src/main/java/com/tangem/tap/di/routing/RoutingComponentModule.kt new file mode 100644 index 0000000000..aca0f1678a --- /dev/null +++ b/app/src/main/java/com/tangem/tap/di/routing/RoutingComponentModule.kt @@ -0,0 +1,18 @@ +package com.tangem.tap.di.routing + +import com.tangem.tap.routing.RoutingComponent +import com.tangem.tap.routing.impl.DefaultRoutingComponent +import dagger.Binds +import dagger.Module +import dagger.hilt.InstallIn +import dagger.hilt.android.components.ActivityComponent +import dagger.hilt.android.scopes.ActivityScoped + +@Module +@InstallIn(ActivityComponent::class) +internal interface RoutingComponentModule { + + @Binds + @ActivityScoped + fun bindRoutingComponentFactory(factory: DefaultRoutingComponent.Factory): RoutingComponent.Factory +} \ No newline at end of file diff --git a/app/src/main/java/com/tangem/tap/domain/card/DefaultDerivationsRepository.kt b/app/src/main/java/com/tangem/tap/domain/card/DefaultDerivationsRepository.kt index b7ad02d630..64e1b31472 100644 --- a/app/src/main/java/com/tangem/tap/domain/card/DefaultDerivationsRepository.kt +++ b/app/src/main/java/com/tangem/tap/domain/card/DefaultDerivationsRepository.kt @@ -1,13 +1,17 @@ package com.tangem.tap.domain.card import com.tangem.common.CompletionResult +import com.tangem.common.card.EllipticCurve +import com.tangem.common.core.TangemSdkError import com.tangem.common.doOnFailure import com.tangem.common.doOnSuccess import com.tangem.common.extensions.ByteArrayKey +import com.tangem.common.extensions.toMapKey import com.tangem.crypto.hdWallet.DerivationPath import com.tangem.crypto.hdWallet.bip32.ExtendedPublicKey import com.tangem.datasource.local.userwallet.UserWalletsStore import com.tangem.domain.card.repository.DerivationsRepository +import com.tangem.domain.models.scan.ScanResponse import com.tangem.domain.tokens.model.CryptoCurrency import com.tangem.domain.wallets.builder.UserWalletIdBuilder import com.tangem.domain.wallets.models.UserWallet @@ -15,7 +19,7 @@ import com.tangem.domain.wallets.models.UserWalletId import com.tangem.operations.derivation.ExtendedPublicKeysMap import com.tangem.tap.domain.sdk.TangemSdkManager import com.tangem.utils.coroutines.CoroutineDispatcherProvider -import com.tangem.utils.coroutines.runCatching +import kotlinx.coroutines.withContext import timber.log.Timber internal typealias Derivations = Map> @@ -44,10 +48,12 @@ internal class DefaultDerivationsRepository( tangemSdkManager.derivePublicKeys(cardId = null, derivations = derivations) .doOnSuccess { response -> - updatePublicKeys(userWalletId = userWalletId, keys = response.entries).fold( - onSuccess = { return }, - onFailure = { throw it }, - ) + updatePublicKeys(userWalletId = userWalletId, keys = response.entries) + .doOnSuccess { + validateDerivations(scanResponse = it.scanResponse, derivations = derivations) + return + } + .doOnFailure { throw it } } .doOnFailure { throw it } @@ -76,8 +82,24 @@ internal class DefaultDerivationsRepository( } } - private suspend fun updatePublicKeys(userWalletId: UserWalletId, keys: DerivedKeys): Result { - return runCatching(dispatchers.io) { + /** + * It throws an exception if any of the provided derivations are invalid + * Validation for NonHardened moved to application layer, to avoid fails when derive multiple paths + * It needs to be called after success [derivePublicKeys] or in same flows + */ + private fun validateDerivations(scanResponse: ScanResponse, derivations: Derivations) { + derivations.entries.forEach { derivationForKey -> + val wallet = scanResponse.card.wallets.firstOrNull { it.publicKey.toMapKey() == derivationForKey.key } + if (wallet == null) return@forEach + val hasHardenedNodes = derivationForKey.value.any { path -> path.nodes.any { node -> !node.isHardened } } + if (wallet.curve == EllipticCurve.Ed25519Slip0010 && hasHardenedNodes) { + throw TangemSdkError.NonHardenedDerivationNotSupported() + } + } + } + + private suspend fun updatePublicKeys(userWalletId: UserWalletId, keys: DerivedKeys): CompletionResult { + return withContext(dispatchers.io) { userWalletsStore.update( userWalletId = userWalletId, update = { userWallet -> userWallet.updateDerivedKeys(keys) }, diff --git a/app/src/main/java/com/tangem/tap/domain/card/DefaultResetCardUseCase.kt b/app/src/main/java/com/tangem/tap/domain/card/DefaultResetCardUseCase.kt index 966f9613e9..1e322aeaba 100644 --- a/app/src/main/java/com/tangem/tap/domain/card/DefaultResetCardUseCase.kt +++ b/app/src/main/java/com/tangem/tap/domain/card/DefaultResetCardUseCase.kt @@ -11,8 +11,8 @@ import com.tangem.common.core.TangemError import com.tangem.common.core.TangemSdkError import com.tangem.common.core.UserCodeRequestPolicy import com.tangem.domain.card.ResetCardUseCase +import com.tangem.domain.card.ResetCardUserCodeParams import com.tangem.domain.card.models.ResetCardError -import com.tangem.domain.models.scan.CardDTO import com.tangem.domain.wallets.models.UserWalletId import com.tangem.tap.domain.sdk.TangemSdkManager @@ -20,24 +20,25 @@ internal class DefaultResetCardUseCase( private val tangemSdkManager: TangemSdkManager, ) : ResetCardUseCase { - override suspend fun invoke(card: CardDTO): Either = resourceScope { - either { - withUserCodeRequestPolicy(card) + override suspend fun invoke(cardId: String, params: ResetCardUserCodeParams): Either = + resourceScope { + either { + withUserCodeRequestPolicy(params) - tangemSdkManager.resetToFactorySettings( - cardId = card.cardId, - allowsRequestAccessCodeFromRepository = true, - ).bind(raise = this) + tangemSdkManager.resetToFactorySettings( + cardId = cardId, + allowsRequestAccessCodeFromRepository = true, + ).bind(raise = this) + } } - } override suspend fun invoke( cardNumber: Int, - card: CardDTO, + params: ResetCardUserCodeParams, userWalletId: UserWalletId, - ): Either = resourceScope { + ): Either = resourceScope { either { - withUserCodeRequestPolicy(card) + withUserCodeRequestPolicy(params) tangemSdkManager.resetBackupCard( cardNumber = cardNumber, @@ -46,11 +47,11 @@ internal class DefaultResetCardUseCase( } } - private suspend fun ResourceScope.withUserCodeRequestPolicy(card: CardDTO) { + private suspend fun ResourceScope.withUserCodeRequestPolicy(params: ResetCardUserCodeParams) { install( acquire = { val policyBeforeReset = tangemSdkManager.userCodeRequestPolicy - requestMandatoryAccessCodeEntry(card) + requestMandatoryAccessCodeEntry(params) policyBeforeReset }, @@ -60,10 +61,10 @@ internal class DefaultResetCardUseCase( ) } - private fun requestMandatoryAccessCodeEntry(card: CardDTO) { - val type = if (card.isAccessCodeSet) { + private fun requestMandatoryAccessCodeEntry(params: ResetCardUserCodeParams) { + val type = if (params.isAccessCodeSet) { UserCodeType.AccessCode - } else if (card.isPasscodeSet == true) { + } else if (params.isPasscodeSet == true) { UserCodeType.Passcode } else { null @@ -74,15 +75,14 @@ internal class DefaultResetCardUseCase( } } - private fun CompletionResult<*>.bind(raise: Raise) { + private fun CompletionResult.bind(raise: Raise): Boolean { return when (this) { is CompletionResult.Failure -> { val domainError = error.mapToDomainError() raise.raise(domainError) } - is CompletionResult.Success -> { /* no-op */ - } + is CompletionResult.Success -> data } } diff --git a/app/src/main/java/com/tangem/tap/domain/model/PendingTransaction.kt b/app/src/main/java/com/tangem/tap/domain/model/PendingTransaction.kt index c4a810e12e..8548b11eba 100644 --- a/app/src/main/java/com/tangem/tap/domain/model/PendingTransaction.kt +++ b/app/src/main/java/com/tangem/tap/domain/model/PendingTransaction.kt @@ -5,7 +5,7 @@ import com.tangem.blockchain.common.TransactionStatus import com.tangem.blockchain.common.Wallet data class PendingTransaction( - val transactionData: TransactionData, + val transactionData: TransactionData.Uncompiled, val type: PendingTransactionType, ) { val address: String? = when (type) { @@ -21,7 +21,7 @@ data class PendingTransaction( enum class PendingTransactionType { Incoming, Outgoing, Unknown } -fun TransactionData.toPendingTransaction(walletAddress: String): PendingTransaction? { +fun TransactionData.Uncompiled.toPendingTransaction(walletAddress: String): PendingTransaction? { if (this.status == TransactionStatus.Confirmed) return null val type: PendingTransactionType = when { @@ -32,7 +32,7 @@ fun TransactionData.toPendingTransaction(walletAddress: String): PendingTransact return PendingTransaction(this, type) } -fun List.toPendingTransactions(walletAddress: String): List { +fun List.toPendingTransactions(walletAddress: String): List { return this.mapNotNull { it.toPendingTransaction(walletAddress) } } diff --git a/app/src/main/java/com/tangem/tap/domain/scanCard/LegacyScanProcessor.kt b/app/src/main/java/com/tangem/tap/domain/scanCard/LegacyScanProcessor.kt index ce649ece46..ea7c4ac652 100644 --- a/app/src/main/java/com/tangem/tap/domain/scanCard/LegacyScanProcessor.kt +++ b/app/src/main/java/com/tangem/tap/domain/scanCard/LegacyScanProcessor.kt @@ -5,12 +5,11 @@ import com.tangem.common.core.TangemError import com.tangem.common.core.TangemSdkError import com.tangem.common.doOnFailure import com.tangem.common.doOnSuccess +import com.tangem.common.routing.AppRoute import com.tangem.core.analytics.Analytics import com.tangem.core.analytics.models.AnalyticsEvent import com.tangem.core.analytics.models.AnalyticsParam import com.tangem.core.analytics.models.Basic -import com.tangem.core.navigation.AppScreen -import com.tangem.core.navigation.NavigationAction import com.tangem.domain.common.TapWorkarounds.canSkipBackup import com.tangem.domain.common.extensions.withMainContext import com.tangem.domain.common.util.twinsIsTwinned @@ -21,6 +20,7 @@ import com.tangem.tap.common.redux.global.GlobalAction import com.tangem.tap.features.disclaimer.createDisclaimer import com.tangem.tap.features.disclaimer.redux.DisclaimerAction import com.tangem.tap.features.disclaimer.redux.DisclaimerCallback +import com.tangem.tap.features.disclaimer.redux.DisclaimerSource import com.tangem.tap.features.onboarding.OnboardingHelper import com.tangem.tap.features.onboarding.products.twins.redux.TwinCardsAction import com.tangem.tap.features.onboarding.products.twins.redux.TwinCardsStep @@ -32,6 +32,7 @@ import com.tangem.utils.extensions.DELAY_SDK_DIALOG_CLOSE import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.delay import kotlinx.coroutines.launch +import kotlinx.coroutines.withContext internal object LegacyScanProcessor { @@ -115,24 +116,28 @@ internal object LegacyScanProcessor { } else { scope.launch { delay(DELAY_SDK_DIALOG_CLOSE) - disclaimerWillShow() - store.dispatchWithMain( - DisclaimerAction.Show( - fromScreen = AppScreen.Home, - callback = DisclaimerCallback( - onAccept = { - scope.launch(Dispatchers.Main) { - nextHandler(scanResponse) - } - }, - onDismiss = { - scope.launch(Dispatchers.Main) { - onFailure(TangemSdkError.UserCancelled()) - } - }, + + withContext(Dispatchers.Main.immediate) { + disclaimerWillShow() + + store.dispatch( + DisclaimerAction.Show( + from = DisclaimerSource.Home, + callback = DisclaimerCallback( + onAccept = { + scope.launch(Dispatchers.Main.immediate) { + nextHandler(scanResponse) + } + }, + onDismiss = { + scope.launch(Dispatchers.Main.immediate) { + onFailure(TangemSdkError.UserCancelled()) + } + }, + ), ), - ), - ) + ) + } } } } @@ -170,7 +175,7 @@ internal object LegacyScanProcessor { if (scanResponse.twinsIsTwinned() && !wasTwinsOnboardingShown) { onWalletNotCreated() store.dispatchOnMain(TwinCardsAction.SetStepOfScreen(TwinCardsStep.WelcomeOnly(scanResponse))) - navigateTo(AppScreen.OnboardingTwins) { onProgressStateChange(it) } + navigateTo(AppRoute.OnboardingTwins) { onProgressStateChange(it) } } else { delay(DELAY_SDK_DIALOG_CLOSE) onSuccess(scanResponse) @@ -178,9 +183,9 @@ internal object LegacyScanProcessor { } } - private suspend inline fun navigateTo(screen: AppScreen, onProgressStateChange: (showProgress: Boolean) -> Unit) { + private suspend inline fun navigateTo(route: AppRoute, onProgressStateChange: (showProgress: Boolean) -> Unit) { delay(DELAY_SDK_DIALOG_CLOSE) - store.dispatchOnMain(NavigationAction.NavigateTo(screen)) + store.dispatchNavigationAction { push(route) } onProgressStateChange(false) } } \ No newline at end of file diff --git a/app/src/main/java/com/tangem/tap/domain/scanCard/UseCaseScanProcessor.kt b/app/src/main/java/com/tangem/tap/domain/scanCard/UseCaseScanProcessor.kt index ed777bd666..381d348980 100644 --- a/app/src/main/java/com/tangem/tap/domain/scanCard/UseCaseScanProcessor.kt +++ b/app/src/main/java/com/tangem/tap/domain/scanCard/UseCaseScanProcessor.kt @@ -3,16 +3,15 @@ package com.tangem.tap.domain.scanCard import arrow.fx.coroutines.resourceScope import com.tangem.common.CompletionResult import com.tangem.common.core.TangemError +import com.tangem.common.routing.AppRoute import com.tangem.core.analytics.Analytics import com.tangem.core.analytics.models.AnalyticsParam import com.tangem.core.analytics.models.Basic -import com.tangem.core.navigation.AppScreen -import com.tangem.core.navigation.NavigationAction -import com.tangem.core.navigation.StateDialog import com.tangem.domain.card.ScanCardException import com.tangem.domain.models.scan.ScanResponse +import com.tangem.domain.redux.StateDialog import com.tangem.tap.common.extensions.dispatchDialogShow -import com.tangem.tap.common.extensions.dispatchOnMain +import com.tangem.tap.common.extensions.dispatchNavigationAction import com.tangem.tap.common.extensions.inject import com.tangem.tap.domain.scanCard.chains.* import com.tangem.tap.domain.scanCard.utils.ScanCardExceptionConverter @@ -60,7 +59,11 @@ internal object UseCaseScanProcessor { ), ) add(AnalyticsChain(Basic.CardWasScanned(analyticsSource))) - add(DisclaimerChain(store, disclaimerWillShow)) + val pushNotificationsToggles = + store.inject(getDependency = DaggerGraphState::pushNotificationsFeatureToggles) + if (pushNotificationsToggles.isPushNotificationsEnabled) { + add(DisclaimerChain(store, disclaimerWillShow)) + } add(CheckForOnboardingChain(store, store.state.globalState.tapWalletManager)) } @@ -132,8 +135,8 @@ internal object UseCaseScanProcessor { action() } - private suspend inline fun navigateTo(screen: AppScreen) { + private suspend inline fun navigateTo(route: AppRoute) { delay(DELAY_SDK_DIALOG_CLOSE) - store.dispatchOnMain(NavigationAction.NavigateTo(screen)) + store.dispatchNavigationAction { push(route) } } } \ No newline at end of file diff --git a/app/src/main/java/com/tangem/tap/domain/scanCard/chains/CheckForOnboardingChain.kt b/app/src/main/java/com/tangem/tap/domain/scanCard/chains/CheckForOnboardingChain.kt index 66f708e28d..72d0b6ee59 100644 --- a/app/src/main/java/com/tangem/tap/domain/scanCard/chains/CheckForOnboardingChain.kt +++ b/app/src/main/java/com/tangem/tap/domain/scanCard/chains/CheckForOnboardingChain.kt @@ -2,8 +2,8 @@ package com.tangem.tap.domain.scanCard.chains import arrow.core.left import arrow.core.right +import com.tangem.common.routing.AppRoute import com.tangem.core.analytics.Analytics -import com.tangem.core.navigation.AppScreen import com.tangem.domain.card.ScanCardException import com.tangem.domain.common.TapWorkarounds.canSkipBackup import com.tangem.domain.common.util.twinsIsTwinned @@ -55,8 +55,8 @@ class CheckForOnboardingChain( canSkipBackup = previousChainResult.card.canSkipBackup, ), ) - val appScreen = OnboardingHelper.whereToNavigate(previousChainResult) - ScanChainException.OnboardingNeeded(appScreen).left() + val route = OnboardingHelper.whereToNavigate(previousChainResult) + ScanChainException.OnboardingNeeded(route).left() } else -> { Analytics.setContext(previousChainResult) @@ -69,7 +69,7 @@ class CheckForOnboardingChain( store.dispatchOnMain( TwinCardsAction.SetStepOfScreen(TwinCardsStep.WelcomeOnly(previousChainResult)), ) - ScanChainException.OnboardingNeeded(AppScreen.OnboardingTwins).left() + ScanChainException.OnboardingNeeded(AppRoute.OnboardingTwins).left() } else { delay(DELAY_SDK_DIALOG_CLOSE) previousChainResult.right() diff --git a/app/src/main/java/com/tangem/tap/domain/scanCard/chains/DisclaimerChain.kt b/app/src/main/java/com/tangem/tap/domain/scanCard/chains/DisclaimerChain.kt index 35ad2efbab..8aa003b952 100644 --- a/app/src/main/java/com/tangem/tap/domain/scanCard/chains/DisclaimerChain.kt +++ b/app/src/main/java/com/tangem/tap/domain/scanCard/chains/DisclaimerChain.kt @@ -2,7 +2,6 @@ package com.tangem.tap.domain.scanCard.chains import arrow.core.left import arrow.core.right -import com.tangem.core.navigation.AppScreen import com.tangem.domain.card.ScanCardException import com.tangem.domain.core.chain.Chain import com.tangem.domain.core.chain.ResultChain @@ -13,6 +12,7 @@ import com.tangem.tap.features.disclaimer.Disclaimer import com.tangem.tap.features.disclaimer.createDisclaimer import com.tangem.tap.features.disclaimer.redux.DisclaimerAction import com.tangem.tap.features.disclaimer.redux.DisclaimerCallback +import com.tangem.tap.features.disclaimer.redux.DisclaimerSource import kotlinx.coroutines.suspendCancellableCoroutine import org.rekotlin.Store import kotlin.coroutines.resume @@ -50,7 +50,7 @@ internal class DisclaimerChain( return suspendCancellableCoroutine { continuation -> store.dispatchOnMain( DisclaimerAction.Show( - fromScreen = AppScreen.Home, + from = DisclaimerSource.Home, callback = DisclaimerCallback( onAccept = { if (continuation.isActive) { diff --git a/app/src/main/java/com/tangem/tap/domain/scanCard/chains/ScanChainException.kt b/app/src/main/java/com/tangem/tap/domain/scanCard/chains/ScanChainException.kt index ae5e9f8ad3..b36fb89f0e 100644 --- a/app/src/main/java/com/tangem/tap/domain/scanCard/chains/ScanChainException.kt +++ b/app/src/main/java/com/tangem/tap/domain/scanCard/chains/ScanChainException.kt @@ -1,6 +1,6 @@ package com.tangem.tap.domain.scanCard.chains -import com.tangem.core.navigation.AppScreen +import com.tangem.common.routing.AppRoute import com.tangem.domain.card.ScanCardException sealed class ScanChainException : ScanCardException.ChainException() { @@ -19,5 +19,5 @@ sealed class ScanChainException : ScanCardException.ChainException() { * * @param onboardingRoute route where to navigate * */ - data class OnboardingNeeded(val onboardingRoute: AppScreen) : ScanChainException() + data class OnboardingNeeded(val onboardingRoute: AppRoute) : ScanChainException() } \ No newline at end of file diff --git a/app/src/main/java/com/tangem/tap/domain/sdk/TangemSdkManager.kt b/app/src/main/java/com/tangem/tap/domain/sdk/TangemSdkManager.kt index 0f5e408f5e..2dbfaec5b7 100644 --- a/app/src/main/java/com/tangem/tap/domain/sdk/TangemSdkManager.kt +++ b/app/src/main/java/com/tangem/tap/domain/sdk/TangemSdkManager.kt @@ -70,9 +70,9 @@ interface TangemSdkManager { suspend fun resetToFactorySettings( cardId: String, allowsRequestAccessCodeFromRepository: Boolean, - ): CompletionResult + ): CompletionResult - suspend fun resetBackupCard(cardNumber: Int, userWalletId: UserWalletId): CompletionResult + suspend fun resetBackupCard(cardNumber: Int, userWalletId: UserWalletId): CompletionResult suspend fun saveAccessCode(accessCode: String, cardsIds: Set): CompletionResult diff --git a/app/src/main/java/com/tangem/tap/domain/sdk/impl/DefaultTangemSdkManager.kt b/app/src/main/java/com/tangem/tap/domain/sdk/impl/DefaultTangemSdkManager.kt index 00bacdbe26..835a2fee69 100644 --- a/app/src/main/java/com/tangem/tap/domain/sdk/impl/DefaultTangemSdkManager.kt +++ b/app/src/main/java/com/tangem/tap/domain/sdk/impl/DefaultTangemSdkManager.kt @@ -202,7 +202,7 @@ class DefaultTangemSdkManager( override suspend fun resetToFactorySettings( cardId: String, allowsRequestAccessCodeFromRepository: Boolean, - ): CompletionResult { + ): CompletionResult { return runTaskAsyncReturnOnMain( runnable = ResetToFactorySettingsTask( allowsRequestAccessCodeFromRepository = allowsRequestAccessCodeFromRepository, @@ -210,10 +210,9 @@ class DefaultTangemSdkManager( cardId = cardId, initialMessage = Message(resources.getString(R.string.card_settings_reset_card_to_factory)), ) - .map { CardDTO(it) } } - override suspend fun resetBackupCard(cardNumber: Int, userWalletId: UserWalletId): CompletionResult { + override suspend fun resetBackupCard(cardNumber: Int, userWalletId: UserWalletId): CompletionResult { return runTaskAsyncReturnOnMain( runnable = ResetBackupCardTask(userWalletId), initialMessage = Message( diff --git a/app/src/main/java/com/tangem/tap/domain/sdk/impl/MockTangemSdkManager.kt b/app/src/main/java/com/tangem/tap/domain/sdk/impl/MockTangemSdkManager.kt index dcc850f798..0dffc198a7 100644 --- a/app/src/main/java/com/tangem/tap/domain/sdk/impl/MockTangemSdkManager.kt +++ b/app/src/main/java/com/tangem/tap/domain/sdk/impl/MockTangemSdkManager.kt @@ -87,12 +87,12 @@ class MockTangemSdkManager( override suspend fun resetToFactorySettings( cardId: String, allowsRequestAccessCodeFromRepository: Boolean, - ): CompletionResult { - return MockProvider.getCardDto() + ): CompletionResult { + return CompletionResult.Success(true) } - override suspend fun resetBackupCard(cardNumber: Int, userWalletId: UserWalletId): CompletionResult { - return CompletionResult.Success(Unit) + override suspend fun resetBackupCard(cardNumber: Int, userWalletId: UserWalletId): CompletionResult { + return CompletionResult.Success(true) } override suspend fun saveAccessCode(accessCode: String, cardsIds: Set): CompletionResult { diff --git a/app/src/main/java/com/tangem/tap/domain/tasks/product/ResetBackupCardTask.kt b/app/src/main/java/com/tangem/tap/domain/tasks/product/ResetBackupCardTask.kt index 7de7ceb374..288ca22a9d 100644 --- a/app/src/main/java/com/tangem/tap/domain/tasks/product/ResetBackupCardTask.kt +++ b/app/src/main/java/com/tangem/tap/domain/tasks/product/ResetBackupCardTask.kt @@ -19,11 +19,11 @@ import com.tangem.tap.domain.tasks.UserWalletIdPreflightReadFilter */ internal class ResetBackupCardTask( private val userWalletId: UserWalletId, -) : CardSessionRunnable { +) : CardSessionRunnable { override val allowsRequestAccessCodeFromRepository: Boolean = false - override fun run(session: CardSession, callback: CompletionCallback) { + override fun run(session: CardSession, callback: CompletionCallback) { PreflightReadTask( readMode = PreflightReadMode.FullCardRead, filter = UserWalletIdPreflightReadFilter(expectedUserWalletId = userWalletId), @@ -35,10 +35,10 @@ internal class ResetBackupCardTask( } } - private fun resetCard(session: CardSession, callback: CompletionCallback) { + private fun resetCard(session: CardSession, callback: CompletionCallback) { ResetToFactorySettingsTask(allowsRequestAccessCodeFromRepository).run(session) { result -> when (result) { - is CompletionResult.Success -> callback(CompletionResult.Success(Unit)) + is CompletionResult.Success -> callback(CompletionResult.Success(result.data)) is CompletionResult.Failure -> callback(CompletionResult.Failure(result.error)) } } diff --git a/app/src/main/java/com/tangem/tap/domain/tasks/product/ResetToFactorySettingsTask.kt b/app/src/main/java/com/tangem/tap/domain/tasks/product/ResetToFactorySettingsTask.kt index f06f2f801a..51ff0b2d80 100644 --- a/app/src/main/java/com/tangem/tap/domain/tasks/product/ResetToFactorySettingsTask.kt +++ b/app/src/main/java/com/tangem/tap/domain/tasks/product/ResetToFactorySettingsTask.kt @@ -10,13 +10,15 @@ import com.tangem.operations.wallet.PurgeWalletCommand class ResetToFactorySettingsTask( override val allowsRequestAccessCodeFromRepository: Boolean, -) : CardSessionRunnable { +) : CardSessionRunnable { - override fun run(session: CardSession, callback: (result: CompletionResult) -> Unit) { + private var isResetCompleted = false + + override fun run(session: CardSession, callback: (result: CompletionResult) -> Unit) { deleteWallets(session, callback) } - private fun deleteWallets(session: CardSession, callback: (result: CompletionResult) -> Unit) { + private fun deleteWallets(session: CardSession, callback: (result: CompletionResult) -> Unit) { val wallet = session.environment.card?.wallets?.lastOrNull().guard { resetBackup(session, callback) return @@ -25,6 +27,7 @@ class ResetToFactorySettingsTask( PurgeWalletCommand(wallet.publicKey).run(session) { result -> when (result) { is CompletionResult.Success -> { + isResetCompleted = true deleteWallets(session, callback) } is CompletionResult.Failure -> callback(CompletionResult.Failure(result.error)) @@ -32,18 +35,18 @@ class ResetToFactorySettingsTask( } } - private fun resetBackup(session: CardSession, callback: (result: CompletionResult) -> Unit) { + private fun resetBackup(session: CardSession, callback: (result: CompletionResult) -> Unit) { if (session.environment.card?.backupStatus == null || session.environment.card?.backupStatus == Card.BackupStatus.NoBackup ) { - callback(CompletionResult.Success(session.environment.card!!)) + callback(CompletionResult.Success(isResetCompleted)) return } ResetBackupCommand().run(session) { result -> when (result) { is CompletionResult.Success -> { - callback(CompletionResult.Success(session.environment.card!!)) + callback(CompletionResult.Success(true)) } is CompletionResult.Failure -> callback(CompletionResult.Failure(result.error)) } diff --git a/app/src/main/java/com/tangem/tap/domain/walletconnect/WalletConnectSdkHelper.kt b/app/src/main/java/com/tangem/tap/domain/walletconnect/WalletConnectSdkHelper.kt index 8fae8e9abb..3e8529f150 100644 --- a/app/src/main/java/com/tangem/tap/domain/walletconnect/WalletConnectSdkHelper.kt +++ b/app/src/main/java/com/tangem/tap/domain/walletconnect/WalletConnectSdkHelper.kt @@ -91,9 +91,8 @@ class WalletConnectSdkHelper { val destinationAddress = requireNotNull(transaction.to) { "Destination address is null" } - val transactionData = TransactionData( + val transactionData = TransactionData.Uncompiled( amount = Amount(value, wallet.blockchain), - // TODO refactoring fee = Fee.Common(Amount(fee, wallet.blockchain)), sourceAddress = transaction.from, destinationAddress = destinationAddress, diff --git a/app/src/main/java/com/tangem/tap/domain/walletconnect2/data/DefaultLegacyWalletConnectRepository.kt b/app/src/main/java/com/tangem/tap/domain/walletconnect2/data/DefaultLegacyWalletConnectRepository.kt index 4f9055bfb4..cea126bf75 100644 --- a/app/src/main/java/com/tangem/tap/domain/walletconnect2/data/DefaultLegacyWalletConnectRepository.kt +++ b/app/src/main/java/com/tangem/tap/domain/walletconnect2/data/DefaultLegacyWalletConnectRepository.kt @@ -508,6 +508,6 @@ internal class DefaultLegacyWalletConnectRepository( private companion object { - val unsupportedDApps = listOf("dYdX", "dYdX v4", "Apex Pro") + val unsupportedDApps = listOf("dYdX", "dYdX v4", "Apex Pro", "The Sandbox") } } \ No newline at end of file diff --git a/app/src/main/java/com/tangem/tap/features/BaseFragment.kt b/app/src/main/java/com/tangem/tap/features/BaseFragment.kt index d9e668bf04..6321957ee1 100644 --- a/app/src/main/java/com/tangem/tap/features/BaseFragment.kt +++ b/app/src/main/java/com/tangem/tap/features/BaseFragment.kt @@ -14,7 +14,8 @@ import androidx.lifecycle.Lifecycle import androidx.transition.TransitionInflater import com.google.android.material.snackbar.Snackbar import com.tangem.common.extensions.VoidCallback -import com.tangem.core.navigation.NavigationAction +import com.tangem.common.routing.AppRouter +import com.tangem.tap.common.extensions.dispatchNavigationAction import com.tangem.tap.store import com.tangem.wallet.R @@ -36,7 +37,7 @@ abstract class BaseFragment(layoutId: Int) : Fragment(layoutId), FragmentOnBackP } override fun handleOnBackPressed() { - store.dispatch(NavigationAction.PopBackTo()) + store.dispatchNavigationAction(AppRouter::pop) } override fun onViewCreated(view: View, savedInstanceState: Bundle?) { diff --git a/app/src/main/java/com/tangem/tap/features/customtoken/impl/presentation/AddCustomTokenFragment.kt b/app/src/main/java/com/tangem/tap/features/customtoken/impl/presentation/AddCustomTokenFragment.kt index f2b19a713d..443a8af290 100644 --- a/app/src/main/java/com/tangem/tap/features/customtoken/impl/presentation/AddCustomTokenFragment.kt +++ b/app/src/main/java/com/tangem/tap/features/customtoken/impl/presentation/AddCustomTokenFragment.kt @@ -1,5 +1,6 @@ package com.tangem.tap.features.customtoken.impl.presentation +import androidx.compose.foundation.background import androidx.compose.foundation.layout.systemBarsPadding import androidx.compose.runtime.Composable import androidx.compose.runtime.getValue @@ -8,7 +9,6 @@ import androidx.compose.ui.platform.LocalLifecycleOwner import androidx.hilt.navigation.compose.hiltViewModel import androidx.lifecycle.compose.collectAsStateWithLifecycle import com.tangem.core.ui.UiDependencies -import com.tangem.core.ui.components.SystemBarsEffect import com.tangem.core.ui.res.TangemTheme import com.tangem.core.ui.screen.ComposeFragment import com.tangem.tap.features.customtoken.impl.presentation.ui.AddCustomTokenScreen @@ -32,15 +32,12 @@ internal class AddCustomTokenFragment : ComposeFragment() { val viewModel = hiltViewModel().apply { LocalLifecycleOwner.current.lifecycle.addObserver(this) } - val statusBarColor = TangemTheme.colors.background.secondary - SystemBarsEffect { - setSystemBarsColor(color = statusBarColor) - } - val state by viewModel.uiState.collectAsStateWithLifecycle() AddCustomTokenScreen( - modifier = Modifier.systemBarsPadding(), + modifier = Modifier + .background(TangemTheme.colors.background.primary) + .systemBarsPadding(), stateHolder = state, ) } diff --git a/app/src/main/java/com/tangem/tap/features/customtoken/impl/presentation/routers/DefaultCustomTokenRouter.kt b/app/src/main/java/com/tangem/tap/features/customtoken/impl/presentation/routers/DefaultCustomTokenRouter.kt index 6391cc840f..858d49c31c 100644 --- a/app/src/main/java/com/tangem/tap/features/customtoken/impl/presentation/routers/DefaultCustomTokenRouter.kt +++ b/app/src/main/java/com/tangem/tap/features/customtoken/impl/presentation/routers/DefaultCustomTokenRouter.kt @@ -1,9 +1,11 @@ package com.tangem.tap.features.customtoken.impl.presentation.routers import com.tangem.blockchain.common.Blockchain -import com.tangem.core.navigation.AppScreen -import com.tangem.core.navigation.NavigationAction +import com.tangem.common.routing.AppRoute +import com.tangem.common.routing.AppRouter +import com.tangem.common.routing.utils.popTo import com.tangem.tap.common.extensions.dispatchDialogShow +import com.tangem.tap.common.extensions.dispatchNavigationAction import com.tangem.tap.common.redux.AppDialog import com.tangem.tap.store import com.tangem.wallet.R @@ -12,11 +14,11 @@ import com.tangem.wallet.R internal class DefaultCustomTokenRouter : CustomTokenRouter { override fun popBackStack() { - store.dispatch(NavigationAction.PopBackTo()) + store.dispatchNavigationAction(AppRouter::pop) } override fun openWalletScreen() { - store.dispatch(NavigationAction.PopBackTo(screen = AppScreen.Wallet)) + store.dispatchNavigationAction { popTo() } } override fun openUnsupportedNetworkAlert(blockchain: Blockchain) { @@ -32,7 +34,7 @@ internal class DefaultCustomTokenRouter : CustomTokenRouter { val alert = AppDialog.SimpleOkDialogRes( headerId = R.string.common_error, messageId = R.string.common_unknown_error, - onOk = { store.dispatch(NavigationAction.PopBackTo()) }, + onOk = { store.dispatchNavigationAction(AppRouter::pop) }, ) store.dispatchDialogShow(alert) } diff --git a/app/src/main/java/com/tangem/tap/features/demo/DemoHelper.kt b/app/src/main/java/com/tangem/tap/features/demo/DemoHelper.kt index 7dc282cacd..c8576de418 100644 --- a/app/src/main/java/com/tangem/tap/features/demo/DemoHelper.kt +++ b/app/src/main/java/com/tangem/tap/features/demo/DemoHelper.kt @@ -4,7 +4,6 @@ import com.tangem.domain.demo.DemoConfig import com.tangem.domain.models.scan.ScanResponse import com.tangem.tap.common.extensions.dispatchNotification import com.tangem.tap.common.redux.AppState -import com.tangem.tap.features.details.redux.DetailsAction import com.tangem.tap.features.details.redux.walletconnect.WalletConnectAction import com.tangem.tap.features.onboarding.products.wallet.redux.BackupAction import com.tangem.tap.store @@ -21,7 +20,6 @@ object DemoHelper { private val disabledActionFeatures = listOf( WalletConnectAction.StartWalletConnect::class.java, BackupAction.StartBackup::class.java, - DetailsAction.ResetToFactory.Start::class.java, ) fun isDemoCard(scanResponse: ScanResponse): Boolean = isDemoCardId(scanResponse.card.cardId) diff --git a/app/src/main/java/com/tangem/tap/features/details/redux/DetailsAction.kt b/app/src/main/java/com/tangem/tap/features/details/redux/DetailsAction.kt index fa88770744..10bb1b383d 100644 --- a/app/src/main/java/com/tangem/tap/features/details/redux/DetailsAction.kt +++ b/app/src/main/java/com/tangem/tap/features/details/redux/DetailsAction.kt @@ -14,26 +14,6 @@ sealed class DetailsAction : Action { val shouldSaveUserWallets: Boolean, ) : DetailsAction() - data object ReCreateTwinsWallet : DetailsAction() - - sealed class ResetToFactory : DetailsAction() { - data object Start : ResetToFactory() - data object Proceed : ResetToFactory() - data class AcceptCondition1(val accepted: Boolean) : ResetToFactory() - data class AcceptCondition2(val accepted: Boolean) : ResetToFactory() - data object Failure : ResetToFactory() - data object Success : ResetToFactory() - - data class ShowDialog(val dialog: CardSettingsState.Dialog) : ResetToFactory() - - data object DismissDialog : ResetToFactory() - } - - data object ScanCard : DetailsAction() - - data class PrepareCardSettingsData(val scanResponse: ScanResponse) : DetailsAction() - - data object ResetCardSettingsData : DetailsAction() data object ScanAndSaveUserWallet : DetailsAction() { data object Success : DetailsAction() @@ -43,26 +23,6 @@ sealed class DetailsAction : Action { data object DismissError : DetailsAction() - sealed class AccessCodeRecovery : DetailsAction() { - object Open : AccessCodeRecovery() - data class SaveChanges(val enabled: Boolean) : AccessCodeRecovery() { - data class Success(val enabled: Boolean) : AccessCodeRecovery() - } - - data class SelectOption(val enabled: Boolean) : AccessCodeRecovery() - } - - sealed class ManageSecurity : DetailsAction() { - data object OpenSecurity : ManageSecurity() - data class SelectOption(val option: SecurityOption) : ManageSecurity() - data object SaveChanges : ManageSecurity() { - data object Success : ManageSecurity() - data object Failure : ManageSecurity() - } - - data object ChangeAccessCode : ManageSecurity() - } - sealed class AppSettings : DetailsAction() { data class SwitchPrivacySetting( val enable: Boolean, @@ -96,6 +56,8 @@ sealed class DetailsAction : Action { data class ChangeAppCurrency( val currency: AppCurrency, ) : AppSettings() + + data class Prepare(val state: AppSettingsState) : AppSettings() } data class ChangeAppCurrency(val currency: AppCurrency) : DetailsAction() diff --git a/app/src/main/java/com/tangem/tap/features/details/redux/DetailsMiddleware.kt b/app/src/main/java/com/tangem/tap/features/details/redux/DetailsMiddleware.kt index ba234b662c..14a1147b89 100644 --- a/app/src/main/java/com/tangem/tap/features/details/redux/DetailsMiddleware.kt +++ b/app/src/main/java/com/tangem/tap/features/details/redux/DetailsMiddleware.kt @@ -1,40 +1,36 @@ package com.tangem.tap.features.details.redux import androidx.lifecycle.LifecycleCoroutineScope -import com.tangem.common.* +import com.tangem.common.CompletionResult import com.tangem.common.core.TangemError import com.tangem.common.core.TangemSdkError -import com.tangem.common.core.UserCodeRequestPolicy +import com.tangem.common.doOnFailure +import com.tangem.common.doOnSuccess +import com.tangem.common.routing.AppRoute +import com.tangem.common.routing.AppRouter +import com.tangem.common.routing.utils.popTo import com.tangem.core.analytics.Analytics -import com.tangem.core.navigation.AppScreen -import com.tangem.core.navigation.NavigationAction import com.tangem.core.ui.extensions.TextReference import com.tangem.core.ui.extensions.resourceReference import com.tangem.core.ui.extensions.stringReference import com.tangem.domain.apptheme.model.AppThemeMode -import com.tangem.domain.common.TapWorkarounds.isTangemTwins import com.tangem.domain.models.scan.ScanResponse import com.tangem.domain.wallets.builder.UserWalletBuilder -import com.tangem.domain.wallets.builder.UserWalletIdBuilder import com.tangem.domain.wallets.legacy.UserWalletsListError -import com.tangem.domain.wallets.legacy.asLockable import com.tangem.domain.wallets.models.UserWallet +import com.tangem.tap.* import com.tangem.tap.common.analytics.events.AnalyticsParam import com.tangem.tap.common.analytics.events.Settings -import com.tangem.tap.common.extensions.* -import com.tangem.tap.common.redux.AppDialog +import com.tangem.tap.common.extensions.dispatchNavigationAction +import com.tangem.tap.common.extensions.dispatchWithMain +import com.tangem.tap.common.extensions.inject +import com.tangem.tap.common.extensions.onUserWalletSelected import com.tangem.tap.common.redux.AppState import com.tangem.tap.common.redux.global.GlobalAction import com.tangem.tap.features.demo.DemoHelper -import com.tangem.tap.features.onboarding.products.twins.redux.CreateTwinWalletMode -import com.tangem.tap.features.onboarding.products.twins.redux.TwinCardsAction import com.tangem.tap.proxy.redux.DaggerGraphState -import com.tangem.tap.scope -import com.tangem.tap.store -import com.tangem.tap.tangemSdkManager import com.tangem.utils.coroutines.JobHolder import com.tangem.utils.coroutines.saveIn -import com.tangem.wallet.R import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.delay import kotlinx.coroutines.flow.distinctUntilChanged @@ -42,17 +38,13 @@ import kotlinx.coroutines.flow.flow import kotlinx.coroutines.flow.launchIn import kotlinx.coroutines.flow.onEach import kotlinx.coroutines.launch -import kotlinx.coroutines.withContext import org.rekotlin.Action import org.rekotlin.Middleware import timber.log.Timber import com.tangem.core.analytics.models.AnalyticsParam as CoreAnalyticsParam class DetailsMiddleware { - private val eraseWalletMiddleware = EraseWalletMiddleware() - private val manageSecurityMiddleware = ManageSecurityMiddleware() private val appSettingsMiddleware = AppSettingsMiddleware() - private val accessCodeRecoveryMiddleware = AccessCodeRecoveryMiddleware() val detailsMiddleware: Middleware = { _, stateProvider -> { next -> { action -> @@ -69,152 +61,11 @@ class DetailsMiddleware { private fun handleAction(state: DetailsState, action: Action) { when (action) { - is DetailsAction.ResetToFactory -> eraseWalletMiddleware.handle(action) - is DetailsAction.ManageSecurity -> manageSecurityMiddleware.handle(action, state) is DetailsAction.AppSettings -> appSettingsMiddleware.handle(state, action) - is DetailsAction.ReCreateTwinsWallet -> { - store.dispatch(TwinCardsAction.SetMode(CreateTwinWalletMode.RecreateWallet)) - store.dispatch(NavigationAction.NavigateTo(AppScreen.OnboardingTwins)) - } - is DetailsAction.AccessCodeRecovery -> accessCodeRecoveryMiddleware.handle(state, action) - is DetailsAction.ScanCard -> scanCard(state) is DetailsAction.ScanAndSaveUserWallet -> scanAndSaveUserWallet() } } - class EraseWalletMiddleware { - @Suppress("CyclomaticComplexMethod") - fun handle(action: DetailsAction.ResetToFactory) { - val userWalletsListManager = store.inject(DaggerGraphState::generalUserWalletsListManager) - - when (action) { - is DetailsAction.ResetToFactory.Start -> { - val card = store.state.detailsState.cardSettingsState?.card ?: return - if (card.isTangemTwins) { - store.dispatch(DetailsAction.ReCreateTwinsWallet) - return - } else { - store.dispatch(NavigationAction.NavigateTo(AppScreen.ResetToFactory)) - } - } - is DetailsAction.ResetToFactory.Proceed -> { - val card = store.state.detailsState.cardSettingsState?.card ?: return - scope.launch { - val userWalletId = UserWalletIdBuilder.card(card).build() - - // we must require a password regardless of biometric settings - val policy = tangemSdkManager.userCodeRequestPolicy - val doBeforeErase = { - val type = if (card.isAccessCodeSet) { - UserCodeType.AccessCode - } else if (card.isPasscodeSet == true) { - UserCodeType.Passcode - } else { - null - } - - type?.let { - tangemSdkManager.setUserCodeRequestPolicy(UserCodeRequestPolicy.Always(type)) - } - } - - val doAfterErase = { - tangemSdkManager.setUserCodeRequestPolicy(policy) - } - - doBeforeErase() - tangemSdkManager.resetToFactorySettings(card.cardId, true) - .flatMap { - userWalletsListManager.delete(listOfNotNull(userWalletId)) - } - .flatMap { - tangemSdkManager.deleteSavedUserCodes(setOf(card.cardId)) - } - .doOnSuccess { - Analytics.send(Settings.CardSettings.FactoryResetFinished()) - - val selectedUserWallet = userWalletsListManager.selectedUserWalletSync - if (selectedUserWallet != null) { - store.dispatchOnMain(NavigationAction.PopBackTo(AppScreen.Wallet)) - store.onUserWalletSelected(selectedUserWallet) - } else { - val isLocked = runCatching { userWalletsListManager.asLockable()?.isLockedSync } - .fold(onSuccess = { true }, onFailure = { false }) - if (isLocked && userWalletsListManager.hasUserWallets) { - store.dispatchOnMain(NavigationAction.PopBackTo(AppScreen.Welcome)) - } else { - store.dispatchOnMain(NavigationAction.PopBackTo(AppScreen.Home)) - } - } - } - .doOnFailure { error -> - if (error is TangemSdkError && error !is TangemSdkError.UserCancelled) { - Analytics.send(Settings.CardSettings.FactoryResetFinished(error = error)) - } - } - .doOnResult { - doAfterErase() - } - } - } - else -> Unit - } - } - } - - class ManageSecurityMiddleware { - @Suppress("ComplexMethod") - fun handle(action: DetailsAction.ManageSecurity, detailsState: DetailsState) { - when (action) { - is DetailsAction.ManageSecurity.OpenSecurity -> { - store.dispatch(NavigationAction.NavigateTo(AppScreen.DetailsSecurity)) - } - is DetailsAction.ManageSecurity.SaveChanges -> { - val cardSettingsState = detailsState.cardSettingsState - val cardId = cardSettingsState?.card?.cardId - val selectedOption = cardSettingsState?.manageSecurityState?.selectedOption - scope.launch { - val result = when (selectedOption) { - SecurityOption.LongTap -> tangemSdkManager.setLongTap(cardId) - SecurityOption.PassCode -> tangemSdkManager.setPasscode(cardId) - SecurityOption.AccessCode -> tangemSdkManager.setAccessCode(cardId) - else -> return@launch - } - withContext(Dispatchers.Main) { - val paramValue = AnalyticsParam.SecurityMode.from(selectedOption) - when (result) { - is CompletionResult.Success -> { - Analytics.send(Settings.CardSettings.SecurityModeChanged(paramValue)) - store.dispatch(GlobalAction.UpdateSecurityOptions(selectedOption)) - store.dispatch(NavigationAction.PopBackTo()) - store.dispatch(DetailsAction.ManageSecurity.SaveChanges.Success) - } - is CompletionResult.Failure -> { - val error = result.error - if (error is TangemSdkError && error !is TangemSdkError.UserCancelled) { - Analytics.send(Settings.CardSettings.SecurityModeChanged(paramValue, error)) - } - store.dispatch(DetailsAction.ManageSecurity.SaveChanges.Failure) - } - else -> Unit - } - } - } - } - is DetailsAction.ManageSecurity.ChangeAccessCode -> { - val card = store.state.detailsState.cardSettingsState?.card ?: return - scope.launch { - when (tangemSdkManager.setAccessCode(card.cardId)) { - is CompletionResult.Success -> Analytics.send(Settings.CardSettings.UserCodeChanged()) - is CompletionResult.Failure -> {} - } - } - } - else -> Unit - } - } - } - class AppSettingsMiddleware { private val checkBiometricsStatusJobHolder = JobHolder() @@ -246,6 +97,7 @@ class DetailsMiddleware { is DetailsAction.AppSettings.SwitchPrivacySetting.Success, is DetailsAction.AppSettings.SwitchPrivacySetting.Failure, is DetailsAction.AppSettings.BiometricsStatusChanged, + is DetailsAction.AppSettings.Prepare, -> Unit } } @@ -274,7 +126,7 @@ class DetailsMiddleware { private fun enrollBiometrics() { Analytics.send(Settings.AppSettings.ButtonEnableBiometricAuthentication) - store.dispatchOnMain(NavigationAction.OpenBiometricsSettings) + activityResultCaller.openSystemBiometrySettings() } private fun changeAppThemeMode(appThemeMode: AppThemeMode) { @@ -395,7 +247,7 @@ class DetailsMiddleware { deleteSavedAccessCodes() store.inject(DaggerGraphState::walletsRepository).saveShouldSaveUserWallets(item = false) - store.dispatchWithMain(NavigationAction.PopBackTo(AppScreen.Home)) + store.dispatchNavigationAction { replaceAll(AppRoute.Home) } return CompletionResult.Success(Unit) } @@ -429,63 +281,6 @@ class DetailsMiddleware { } } - class AccessCodeRecoveryMiddleware { - fun handle(state: DetailsState, action: DetailsAction.AccessCodeRecovery) { - when (action) { - is DetailsAction.AccessCodeRecovery.Open -> { - Analytics.send(Settings.CardSettings.AccessCodeRecoveryButton()) - store.dispatch(NavigationAction.NavigateTo(AppScreen.AccessCodeRecovery)) - } - is DetailsAction.AccessCodeRecovery.SaveChanges -> { - scope.launch { - tangemSdkManager - .setAccessCodeRecoveryEnabled(state.cardSettingsState?.card?.cardId, action.enabled) - .doOnSuccess { - Analytics.send( - Settings.CardSettings.AccessCodeRecoveryChanged( - AnalyticsParam.AccessCodeRecoveryStatus.from(action.enabled), - ), - ) - store.dispatchOnMain(NavigationAction.PopBackTo()) - store.dispatchOnMain( - DetailsAction.AccessCodeRecovery.SaveChanges.Success(action.enabled), - ) - } - } - } - is DetailsAction.AccessCodeRecovery.SelectOption -> Unit - is DetailsAction.AccessCodeRecovery.SaveChanges.Success -> Unit - } - } - } - - private fun scanCard(state: DetailsState) = scope.launch { - store.inject(DaggerGraphState::scanCardProcessor) - .scan(allowsRequestAccessCodeFromRepository = true) - .doOnSuccess { scanResponse -> - // if we use biometric, scanResponse in GlobalState is null, and crashes NPE on twin cards - store.dispatch(GlobalAction.SaveScanResponse(scanResponse)) - val currentUserWalletId = state.scanResponse - ?.let { UserWalletIdBuilder.scanResponse(it).build() } - val scannedUserWalletId = UserWalletIdBuilder.scanResponse(scanResponse) - .build() - val isSameWallet = currentUserWalletId == scannedUserWalletId - - if (isSameWallet) { - store.dispatchOnMain( - DetailsAction.PrepareCardSettingsData(scanResponse = scanResponse), - ) - } else { - store.dispatchDialogShow( - AppDialog.SimpleOkDialogRes( - headerId = R.string.common_warning, - messageId = R.string.error_wrong_wallet_tapped, - ), - ) - } - } - } - private fun scanAndSaveUserWallet() = scope.launch(Dispatchers.IO) { val cardSdkConfigRepository = store.inject(DaggerGraphState::cardSdkConfigRepository) @@ -502,7 +297,7 @@ class DetailsMiddleware { store.dispatchWithMain(DetailsAction.ScanAndSaveUserWallet.Success) }, disclaimerWillShow = { - store.dispatchOnMain(NavigationAction.PopBackTo()) + store.dispatchNavigationAction(AppRouter::pop) }, onSuccess = { scanResponse -> createUserWallet(scanResponse) @@ -546,7 +341,7 @@ class DetailsMiddleware { store.onUserWalletSelected(userWallet) store.dispatchWithMain(DetailsAction.ScanAndSaveUserWallet.Success) - store.dispatchWithMain(NavigationAction.PopBackTo(AppScreen.Wallet)) + store.dispatchNavigationAction { popTo() } } .doOnFailure { error -> if (error is UserWalletsListError.WalletAlreadySaved) { @@ -554,7 +349,7 @@ class DetailsMiddleware { store.onUserWalletSelected(userWallet) store.dispatchWithMain(DetailsAction.ScanAndSaveUserWallet.Success) - store.dispatchWithMain(NavigationAction.PopBackTo(AppScreen.Wallet)) + store.dispatchNavigationAction { popTo() } } else { Timber.e(error, "Unable to create user wallet") handleError(error, prevUseBiometricsForAccessCode) diff --git a/app/src/main/java/com/tangem/tap/features/details/redux/DetailsReducer.kt b/app/src/main/java/com/tangem/tap/features/details/redux/DetailsReducer.kt index 68b87d064f..dbb450b426 100644 --- a/app/src/main/java/com/tangem/tap/features/details/redux/DetailsReducer.kt +++ b/app/src/main/java/com/tangem/tap/features/details/redux/DetailsReducer.kt @@ -1,21 +1,15 @@ package com.tangem.tap.features.details.redux -import com.tangem.core.navigation.AppScreen import com.tangem.domain.apptheme.model.AppThemeMode -import com.tangem.domain.common.CardTypesResolver -import com.tangem.domain.common.util.cardTypesResolver import com.tangem.domain.models.scan.CardDTO -import com.tangem.domain.models.scan.ScanResponse import com.tangem.tap.common.extensions.inject import com.tangem.tap.common.redux.AppState -import com.tangem.tap.domain.extensions.signedHashesCount import com.tangem.tap.proxy.redux.DaggerGraphState import com.tangem.tap.store import com.tangem.tap.tangemSdkManager import kotlinx.coroutines.flow.firstOrNull import kotlinx.coroutines.runBlocking import org.rekotlin.Action -import java.util.EnumSet object DetailsReducer { fun reduce(action: Action, state: AppState): DetailsState = internalReduce(action, state) @@ -29,16 +23,6 @@ private fun internalReduce(action: Action, state: AppState): DetailsState { is DetailsAction.PrepareScreen -> { handlePrepareScreen(action, state) } - is DetailsAction.PrepareCardSettingsData -> { - handlePrepareCardSettingsScreen(scanResponse = action.scanResponse, state = detailsState) - } - is DetailsAction.ResetCardSettingsData -> detailsState.copy(cardSettingsState = null) - is DetailsAction.ResetToFactory -> { - handleEraseWallet(action, detailsState) - } - is DetailsAction.ManageSecurity -> { - handleSecurityAction(action, detailsState) - } is DetailsAction.AppSettings -> { handlePrivacyAction(action, detailsState) } @@ -47,7 +31,6 @@ private fun internalReduce(action: Action, state: AppState): DetailsState { selectedAppCurrency = action.currency, ), ) - is DetailsAction.AccessCodeRecovery -> handleAccessCodeRecoveryAction(action, detailsState) is DetailsAction.ScanAndSaveUserWallet -> detailsState.copy( isScanningInProgress = true, ) @@ -61,19 +44,12 @@ private fun internalReduce(action: Action, state: AppState): DetailsState { is DetailsAction.DismissError -> detailsState.copy( error = null, ) - else -> detailsState } } private fun handlePrepareScreen(action: DetailsAction.PrepareScreen, state: AppState): DetailsState { return DetailsState( scanResponse = action.scanResponse, - // If the current screen is ResetToFactory, we must save the ResetToFactory's state - cardSettingsState = if (store.state.navigationState.backStack.lastOrNull() == AppScreen.ResetToFactory) { - state.detailsState.cardSettingsState - } else { - null - }, createBackupAllowed = action.scanResponse.card.backupStatus == CardDTO.BackupStatus.NoBackup, appSettingsState = AppSettingsState( isBiometricsAvailable = runBlocking { @@ -96,139 +72,6 @@ private fun handlePrepareScreen(action: DetailsAction.PrepareScreen, state: AppS ) } -private fun handlePrepareCardSettingsScreen(scanResponse: ScanResponse, state: DetailsState): DetailsState { - val cardTypesResolver = scanResponse.cardTypesResolver - val card = scanResponse.card - val isTangemWallet = cardTypesResolver.isTangemWallet() || cardTypesResolver.isWallet2() - val isShowPasswordResetRadioButton = isTangemWallet && card.backupStatus is CardDTO.BackupStatus.Active - - val cardSettingsState = CardSettingsState( - cardInfo = card.toCardInfo(cardTypesResolver), - scanResponse = scanResponse, - manageSecurityState = prepareSecurityOptions(card, cardTypesResolver), - card = scanResponse.card, - resetCardAllowed = isResetToFactoryAllowedByCard(card, cardTypesResolver), - resetButtonEnabled = false, - condition1Checked = false, - condition2Checked = false, - accessCodeRecovery = if (cardTypesResolver.isWallet2()) { - val enabled = card.userSettings?.isUserCodeRecoveryAllowed ?: false - AccessCodeRecoveryState( - enabledOnCard = enabled, - enabledSelection = enabled, - ) - } else { - null - }, - isShowPasswordResetRadioButton = isShowPasswordResetRadioButton, - dialog = null, - ) - - return state.copy(cardSettingsState = cardSettingsState) -} - -private fun prepareSecurityOptions(card: CardDTO, cardTypesResolver: CardTypesResolver): ManageSecurityState { - val securityOption = when { - card.isAccessCodeSet -> { - SecurityOption.AccessCode - } - - card.isPasscodeSet == true -> { - SecurityOption.PassCode - } - - else -> { - SecurityOption.LongTap - } - } - val allowedSecurityOptions = when { - cardTypesResolver.isStart2Coin() || cardTypesResolver.isTangemNote() -> { - EnumSet.of(SecurityOption.LongTap) - } - card.settings.isBackupAllowed -> { - EnumSet.of(securityOption) - } - else -> - prepareAllowedSecurityOptions(cardTypesResolver = cardTypesResolver, currentSecurityOption = securityOption) - } - return ManageSecurityState( - currentOption = securityOption, - allowedOptions = allowedSecurityOptions, - selectedOption = securityOption, - ) -} - -private fun isResetToFactoryAllowedByCard(card: CardDTO, cardTypesResolver: CardTypesResolver): Boolean { - val hasPermanentWallet = card.wallets.any { it.settings.isPermanent } - val isNotAllowed = hasPermanentWallet || cardTypesResolver.isStart2Coin() - return !isNotAllowed -} - -private fun handleEraseWallet(action: DetailsAction.ResetToFactory, state: DetailsState): DetailsState { - val cardSettingsState = state.cardSettingsState - return when (action) { - is DetailsAction.ResetToFactory.AcceptCondition1 -> { - val warning1Checked = action.accepted - val resetButtonEnabled = if (cardSettingsState?.isShowPasswordResetRadioButton == true) { - warning1Checked && cardSettingsState.condition2Checked - } else { - warning1Checked - } - state.copy( - cardSettingsState = cardSettingsState?.copy( - condition1Checked = action.accepted, - resetButtonEnabled = resetButtonEnabled, - ), - ) - } - is DetailsAction.ResetToFactory.AcceptCondition2 -> { - val warning2Checked = action.accepted - state.copy( - cardSettingsState = cardSettingsState?.copy( - condition2Checked = action.accepted, - resetButtonEnabled = warning2Checked && cardSettingsState.condition1Checked, - ), - ) - } - is DetailsAction.ResetToFactory.ShowDialog -> { - state.copy(cardSettingsState = cardSettingsState?.copy(dialog = action.dialog)) - } - is DetailsAction.ResetToFactory.DismissDialog -> { - state.copy(cardSettingsState = cardSettingsState?.copy(dialog = null)) - } - else -> state - } -} - -private fun handleSecurityAction(action: DetailsAction.ManageSecurity, state: DetailsState): DetailsState { - return when (action) { - is DetailsAction.ManageSecurity.SelectOption -> { - val manageSecurityState = state.cardSettingsState?.manageSecurityState?.copy( - selectedOption = action.option, - ) - state.copy(cardSettingsState = state.cardSettingsState?.copy(manageSecurityState = manageSecurityState)) - } - is DetailsAction.ManageSecurity.SaveChanges.Success -> { - // Setting options to show only LongTap from now on for non-twins - val manageSecurityState = state.cardSettingsState?.manageSecurityState?.copy( - currentOption = state.cardSettingsState.manageSecurityState.selectedOption, - allowedOptions = state.scanResponse?.cardTypesResolver?.let { - prepareAllowedSecurityOptions( - cardTypesResolver = it, - currentSecurityOption = state.cardSettingsState.manageSecurityState.selectedOption, - ) - } ?: EnumSet.of(SecurityOption.LongTap), - ) - state.copy( - cardSettingsState = state.cardSettingsState?.copy( - manageSecurityState = manageSecurityState, - ), - ) - } - else -> state - } -} - private fun handlePrivacyAction(action: DetailsAction.AppSettings, state: DetailsState): DetailsState { return when (action) { is DetailsAction.AppSettings.SwitchPrivacySetting -> state.copy( @@ -281,69 +124,11 @@ private fun handlePrivacyAction(action: DetailsAction.AppSettings, state: Detail isHidingEnabled = action.hideBalance, ), ) + is DetailsAction.AppSettings.Prepare -> state.copy( + appSettingsState = action.state, + ) is DetailsAction.AppSettings.EnrollBiometrics, is DetailsAction.AppSettings.CheckBiometricsStatus, -> state } -} - -private fun handleAccessCodeRecoveryAction( - action: DetailsAction.AccessCodeRecovery, - state: DetailsState, -): DetailsState { - return when (action) { - DetailsAction.AccessCodeRecovery.Open -> { - val accessCodeRecovery = state.cardSettingsState?.accessCodeRecovery?.copy( - enabledSelection = state.cardSettingsState.accessCodeRecovery.enabledOnCard, - ) - state.copy(cardSettingsState = state.cardSettingsState?.copy(accessCodeRecovery = accessCodeRecovery)) - } - is DetailsAction.AccessCodeRecovery.SaveChanges -> state - is DetailsAction.AccessCodeRecovery.SelectOption -> { - val accessCodeRecovery = state.cardSettingsState?.accessCodeRecovery?.copy( - enabledSelection = action.enabled, - ) - state.copy(cardSettingsState = state.cardSettingsState?.copy(accessCodeRecovery = accessCodeRecovery)) - } - is DetailsAction.AccessCodeRecovery.SaveChanges.Success -> { - val accessCodeRecovery = state.cardSettingsState?.accessCodeRecovery?.copy( - enabledOnCard = action.enabled, - enabledSelection = action.enabled, - ) - state.copy(cardSettingsState = state.cardSettingsState?.copy(accessCodeRecovery = accessCodeRecovery)) - } - } -} - -private fun prepareAllowedSecurityOptions( - cardTypesResolver: CardTypesResolver, - currentSecurityOption: SecurityOption?, -): EnumSet { - val allowedSecurityOptions = EnumSet.of(SecurityOption.LongTap) - - if (cardTypesResolver.isTangemTwins()) { - allowedSecurityOptions.add(SecurityOption.PassCode) - } - if (currentSecurityOption == SecurityOption.AccessCode) { - allowedSecurityOptions.add(SecurityOption.AccessCode) - } - if (currentSecurityOption == SecurityOption.PassCode) { - allowedSecurityOptions.add(SecurityOption.PassCode) - } - return allowedSecurityOptions -} - -@Suppress("MagicNumber") -private fun CardDTO.toCardInfo(cardTypesResolver: CardTypesResolver): CardInfo { - val cardId = this.cardId.chunked(4).joinToString(separator = " ") - val issuer = this.issuer.name - val signedHashes = this.signedHashesCount() - - return CardInfo( - cardId = cardId, - issuer = issuer, - signedHashes = signedHashes, - isTwin = cardTypesResolver.isTangemTwins(), - hasBackup = backupStatus?.isActive == true, - ) } \ No newline at end of file diff --git a/app/src/main/java/com/tangem/tap/features/details/redux/DetailsState.kt b/app/src/main/java/com/tangem/tap/features/details/redux/DetailsState.kt index 8e7e583ecf..c35d0c8d83 100644 --- a/app/src/main/java/com/tangem/tap/features/details/redux/DetailsState.kt +++ b/app/src/main/java/com/tangem/tap/features/details/redux/DetailsState.kt @@ -3,15 +3,11 @@ package com.tangem.tap.features.details.redux import com.tangem.core.ui.extensions.TextReference import com.tangem.domain.appcurrency.model.AppCurrency import com.tangem.domain.apptheme.model.AppThemeMode -import com.tangem.domain.models.scan.CardDTO import com.tangem.domain.models.scan.ScanResponse -import com.tangem.tap.common.entities.Button import org.rekotlin.StateType -import java.util.EnumSet data class DetailsState( val scanResponse: ScanResponse? = null, - val cardSettingsState: CardSettingsState? = null, val privacyPolicyUrl: String? = null, val createBackupAllowed: Boolean = false, val isScanningInProgress: Boolean = false, @@ -19,52 +15,13 @@ data class DetailsState( val appSettingsState: AppSettingsState = AppSettingsState(), ) : StateType -data class CardInfo( - val cardId: String, - val issuer: String, - val signedHashes: Int, - val isTwin: Boolean, - val hasBackup: Boolean, -) - -/** - * @property enabledOnCard whether access code recovery is enabled on card - * @property enabledSelection current selected option in app (not saved on card yet) - */ -data class AccessCodeRecoveryState( - val enabledOnCard: Boolean, - val enabledSelection: Boolean, -) - -data class CardSettingsState( - val cardInfo: CardInfo, - val card: CardDTO, - val scanResponse: ScanResponse, - val manageSecurityState: ManageSecurityState?, - val resetCardAllowed: Boolean, - val resetButtonEnabled: Boolean, - val condition1Checked: Boolean, - val condition2Checked: Boolean, - val accessCodeRecovery: AccessCodeRecoveryState? = null, - val isShowPasswordResetRadioButton: Boolean, - val dialog: Dialog?, -) { - - sealed interface Dialog { - data object StartResetDialog : Dialog - data object ContinueResetDialog : Dialog - data object InterruptedResetDialog : Dialog - data object CompletedResetDialog : Dialog - } +sealed class ResetCardDialog { + data object StartResetDialog : ResetCardDialog() + data object ContinueResetDialog : ResetCardDialog() + data object InterruptedResetDialog : ResetCardDialog() + data object CompletedResetDialog : ResetCardDialog() } -data class ManageSecurityState( - val currentOption: SecurityOption = SecurityOption.LongTap, - val selectedOption: SecurityOption = currentOption, - val allowedOptions: EnumSet = EnumSet.allOf(SecurityOption::class.java), - val buttonProceed: Button = Button(true), -) - data class AppSettingsState( val saveWallets: Boolean = false, val saveAccessCodes: Boolean = false, diff --git a/app/src/main/java/com/tangem/tap/features/details/redux/walletconnect/WalletConnectMiddleware.kt b/app/src/main/java/com/tangem/tap/features/details/redux/walletconnect/WalletConnectMiddleware.kt index 3afa643211..6b0e0898ec 100644 --- a/app/src/main/java/com/tangem/tap/features/details/redux/walletconnect/WalletConnectMiddleware.kt +++ b/app/src/main/java/com/tangem/tap/features/details/redux/walletconnect/WalletConnectMiddleware.kt @@ -1,19 +1,17 @@ package com.tangem.tap.features.details.redux.walletconnect -import androidx.core.os.bundleOf import com.tangem.blockchain.common.WalletManager import com.tangem.blockchainsdk.utils.toNetworkId -import com.tangem.core.navigation.AppScreen -import com.tangem.core.navigation.NavigationAction +import com.tangem.common.routing.AppRoute import com.tangem.domain.qrscanning.models.SourceType -import com.tangem.feature.qrscanning.QrScanningRouter +import com.tangem.tap.common.extensions.dispatchNavigationAction import com.tangem.tap.common.extensions.dispatchOnMain import com.tangem.tap.common.extensions.inject import com.tangem.tap.common.redux.AppDialog import com.tangem.tap.common.redux.AppState import com.tangem.tap.common.redux.global.GlobalAction -import com.tangem.tap.domain.walletconnect2.domain.WalletConnectInteractor import com.tangem.tap.domain.walletconnect2.domain.LegacyWalletConnectRepository +import com.tangem.tap.domain.walletconnect2.domain.WalletConnectInteractor import com.tangem.tap.domain.walletconnect2.domain.WcPreparedRequest import com.tangem.tap.domain.walletconnect2.domain.models.Account import com.tangem.tap.domain.walletconnect2.domain.models.WalletConnectError @@ -65,14 +63,7 @@ class WalletConnectMiddleware { // TODO check store.dispatchOnMain(WalletConnectAction.ShowClipboardOrScanQrDialog(uri)) } else { - store.dispatchOnMain( - NavigationAction.NavigateTo( - screen = AppScreen.QrScanning, - bundle = bundleOf( - QrScanningRouter.SOURCE_KEY to SourceType.WALLET_CONNECT, - ), - ), - ) + store.dispatchNavigationAction { push(AppRoute.QrScanning(SourceType.WALLET_CONNECT)) } } } is WalletConnectAction.ShowClipboardOrScanQrDialog -> { diff --git a/app/src/main/java/com/tangem/tap/features/details/redux/walletconnect/WalletConnectState.kt b/app/src/main/java/com/tangem/tap/features/details/redux/walletconnect/WalletConnectState.kt index f407924cca..d1a9368288 100644 --- a/app/src/main/java/com/tangem/tap/features/details/redux/walletconnect/WalletConnectState.kt +++ b/app/src/main/java/com/tangem/tap/features/details/redux/walletconnect/WalletConnectState.kt @@ -5,9 +5,9 @@ import com.tangem.blockchain.common.Blockchain import com.tangem.blockchain.common.TransactionData import com.tangem.blockchain.common.WalletManager import com.tangem.blockchain.common.derivation.DerivationStyle -import com.tangem.core.navigation.StateDialog import com.tangem.crypto.hdWallet.DerivationPath import com.tangem.domain.models.scan.ScanResponse +import com.tangem.domain.redux.StateDialog import com.tangem.tap.domain.walletconnect2.domain.WcPreparedRequest import com.tangem.tap.domain.walletconnect2.domain.WcSignMessage import com.tangem.tap.domain.walletconnect2.domain.models.WalletConnectEvents diff --git a/app/src/main/java/com/tangem/tap/features/details/ui/appcurrency/AppCurrencySelectorFragment.kt b/app/src/main/java/com/tangem/tap/features/details/ui/appcurrency/AppCurrencySelectorFragment.kt index d48050ec85..e4170e8003 100644 --- a/app/src/main/java/com/tangem/tap/features/details/ui/appcurrency/AppCurrencySelectorFragment.kt +++ b/app/src/main/java/com/tangem/tap/features/details/ui/appcurrency/AppCurrencySelectorFragment.kt @@ -6,8 +6,7 @@ import androidx.compose.ui.Modifier import androidx.fragment.app.viewModels import androidx.lifecycle.compose.collectAsStateWithLifecycle import com.tangem.core.ui.UiDependencies -import com.tangem.core.ui.components.SystemBarsEffect -import com.tangem.core.ui.res.TangemTheme +import com.tangem.core.ui.components.NavigationBar3ButtonsScrim import com.tangem.core.ui.screen.ComposeFragment import dagger.hilt.android.AndroidEntryPoint import javax.inject.Inject @@ -22,12 +21,8 @@ internal class AppCurrencySelectorFragment : ComposeFragment() { @Composable override fun ScreenContent(modifier: Modifier) { - val systemBarsColor = TangemTheme.colors.background.secondary - SystemBarsEffect { - setSystemBarsColor(systemBarsColor) - } - val uiState by viewModel.uiState.collectAsStateWithLifecycle() + NavigationBar3ButtonsScrim() AppCurrencySelectorScreen( modifier = modifier, state = uiState, diff --git a/app/src/main/java/com/tangem/tap/features/details/ui/appcurrency/AppCurrencySelectorScreen.kt b/app/src/main/java/com/tangem/tap/features/details/ui/appcurrency/AppCurrencySelectorScreen.kt index b29b503a39..168fccb7e7 100644 --- a/app/src/main/java/com/tangem/tap/features/details/ui/appcurrency/AppCurrencySelectorScreen.kt +++ b/app/src/main/java/com/tangem/tap/features/details/ui/appcurrency/AppCurrencySelectorScreen.kt @@ -16,6 +16,7 @@ import androidx.compose.ui.Modifier import androidx.compose.ui.focus.FocusRequester import androidx.compose.ui.focus.focusRequester import androidx.compose.ui.input.nestedscroll.nestedScroll +import androidx.compose.ui.platform.LocalDensity import androidx.compose.ui.res.painterResource import androidx.compose.ui.res.stringResource import androidx.compose.ui.tooling.preview.Preview @@ -40,7 +41,9 @@ internal fun AppCurrencySelectorScreen(state: AppCurrencySelectorState, modifier val listState = rememberLazyListState() Scaffold( - modifier = modifier.nestedScroll(scrollBehavior.nestedScrollConnection), + modifier = modifier + .imePadding() + .nestedScroll(scrollBehavior.nestedScrollConnection), containerColor = TangemTheme.colors.background.secondary, topBar = { TopBar( @@ -49,6 +52,7 @@ internal fun AppCurrencySelectorScreen(state: AppCurrencySelectorState, modifier state = state, ) }, + contentWindowInsets = ScaffoldDefaults.contentWindowInsets.exclude(WindowInsets.navigationBars), content = { paddingValues -> val contentModifier = Modifier .padding(paddingValues) @@ -62,7 +66,7 @@ internal fun AppCurrencySelectorScreen(state: AppCurrencySelectorState, modifier modifier = contentModifier, listState = listState, currencies = state.items, - selectedId = state.selectedId.orEmpty(), + selectedId = state.selectedId, onCurrencyClick = state.onCurrencyClick, ) } @@ -175,6 +179,7 @@ private fun SearchBar(onInputChange: (String) -> Unit, modifier: Modifier = Modi @Composable private fun LoadingList(modifier: Modifier = Modifier) { + val bottomBarHeight = with(LocalDensity.current) { WindowInsets.systemBars.getBottom(this).toDp() } Column(modifier = modifier) { repeat(times = 10) { Row( @@ -199,6 +204,7 @@ private fun LoadingList(modifier: Modifier = Modifier) { ) } } + Spacer(Modifier.height(bottomBarHeight)) } } @@ -210,9 +216,11 @@ private fun CurrenciesList( onCurrencyClick: (Currency) -> Unit, modifier: Modifier = Modifier, ) { + val bottomBarHeight = with(LocalDensity.current) { WindowInsets.systemBars.getBottom(this).toDp() } LazyColumn( modifier = modifier, state = listState, + contentPadding = PaddingValues(bottom = bottomBarHeight), ) { items( items = currencies, diff --git a/app/src/main/java/com/tangem/tap/features/details/ui/appcurrency/AppCurrencySelectorViewModel.kt b/app/src/main/java/com/tangem/tap/features/details/ui/appcurrency/AppCurrencySelectorViewModel.kt index 7b07e7d471..41d27d02a9 100644 --- a/app/src/main/java/com/tangem/tap/features/details/ui/appcurrency/AppCurrencySelectorViewModel.kt +++ b/app/src/main/java/com/tangem/tap/features/details/ui/appcurrency/AppCurrencySelectorViewModel.kt @@ -2,8 +2,9 @@ package com.tangem.tap.features.details.ui.appcurrency import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope +import com.tangem.common.routing.AppRouter import com.tangem.core.analytics.api.AnalyticsEventHandler -import com.tangem.core.navigation.ReduxNavController + import com.tangem.domain.appcurrency.GetAvailableCurrenciesUseCase import com.tangem.domain.appcurrency.GetSelectedAppCurrencyUseCase import com.tangem.domain.appcurrency.SelectAppCurrencyUseCase @@ -20,7 +21,7 @@ internal class AppCurrencySelectorViewModel @Inject constructor( private val getSelectedAppCurrencyUseCase: GetSelectedAppCurrencyUseCase, private val getAvailableCurrenciesUseCase: GetAvailableCurrenciesUseCase, private val selectAppCurrencyUseCase: SelectAppCurrencyUseCase, - private val reduxNavController: ReduxNavController, + private val router: AppRouter, private val dispatchers: CoroutineDispatcherProvider, private val analyticsEventHandler: AnalyticsEventHandler, ) : ViewModel(), AppCurrencySelectorIntents { @@ -34,7 +35,7 @@ internal class AppCurrencySelectorViewModel @Inject constructor( val uiState: StateFlow = stateController.stateFlow override fun onBackClick() { - reduxNavController.popBackStack() + router.pop() } override fun onSearchClick() { @@ -52,7 +53,7 @@ internal class AppCurrencySelectorViewModel @Inject constructor( analyticsEventHandler.send( event = Settings.AppSettings.MainCurrencyChanged(currencyType = currency.name), ) - reduxNavController.popBackStack() + router.pop() } } } diff --git a/app/src/main/java/com/tangem/tap/features/details/ui/appsettings/AppSettingsFragment.kt b/app/src/main/java/com/tangem/tap/features/details/ui/appsettings/AppSettingsFragment.kt index 2efc912cca..9036d7d1fd 100644 --- a/app/src/main/java/com/tangem/tap/features/details/ui/appsettings/AppSettingsFragment.kt +++ b/app/src/main/java/com/tangem/tap/features/details/ui/appsettings/AppSettingsFragment.kt @@ -6,11 +6,11 @@ import androidx.compose.ui.Modifier import androidx.compose.ui.platform.LocalLifecycleOwner import androidx.hilt.navigation.compose.hiltViewModel import androidx.lifecycle.compose.collectAsStateWithLifecycle -import com.tangem.core.navigation.NavigationAction +import com.tangem.common.routing.AppRouter import com.tangem.core.ui.UiDependencies import com.tangem.core.ui.screen.ComposeFragment import com.tangem.domain.appcurrency.repository.AppCurrencyRepository -import com.tangem.tap.features.details.redux.DetailsAction +import com.tangem.tap.common.extensions.dispatchNavigationAction import com.tangem.tap.store import dagger.hilt.android.AndroidEntryPoint import javax.inject.Inject @@ -35,8 +35,7 @@ internal class AppSettingsFragment : ComposeFragment() { modifier = modifier, state = state, onBackClick = { - store.dispatch(DetailsAction.ResetCardSettingsData) - store.dispatch(NavigationAction.PopBackTo()) + store.dispatchNavigationAction(AppRouter::pop) }, ) } diff --git a/app/src/main/java/com/tangem/tap/features/details/ui/appsettings/AppSettingsScreen.kt b/app/src/main/java/com/tangem/tap/features/details/ui/appsettings/AppSettingsScreen.kt index c60f34ecce..f3d0b721c9 100644 --- a/app/src/main/java/com/tangem/tap/features/details/ui/appsettings/AppSettingsScreen.kt +++ b/app/src/main/java/com/tangem/tap/features/details/ui/appsettings/AppSettingsScreen.kt @@ -1,13 +1,17 @@ package com.tangem.tap.features.details.ui.appsettings import android.content.res.Configuration +import androidx.compose.foundation.layout.PaddingValues +import androidx.compose.foundation.layout.WindowInsets import androidx.compose.foundation.layout.padding +import androidx.compose.foundation.layout.systemBars import androidx.compose.foundation.lazy.LazyColumn import androidx.compose.foundation.lazy.items import androidx.compose.runtime.Composable import androidx.compose.runtime.getValue import androidx.compose.runtime.rememberUpdatedState import androidx.compose.ui.Modifier +import androidx.compose.ui.platform.LocalDensity import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.tooling.preview.PreviewParameter import androidx.compose.ui.tooling.preview.datasource.CollectionPreviewParameterProvider @@ -32,6 +36,7 @@ internal fun AppSettingsScreen(state: AppSettingsScreenState, onBackClick: () -> }, titleRes = R.string.app_settings_title, onBackClick = onBackClick, + addBottomInsets = false, ) } @@ -44,7 +49,11 @@ private fun AppSettings(state: AppSettingsScreenState.Content) { null -> Unit } - LazyColumn { + val bottomBarHeight = with(LocalDensity.current) { WindowInsets.systemBars.getBottom(this).toDp() } + + LazyColumn( + contentPadding = PaddingValues(bottom = bottomBarHeight), + ) { items( items = state.items, key = Item::id, diff --git a/app/src/main/java/com/tangem/tap/features/details/ui/appsettings/AppSettingsViewModel.kt b/app/src/main/java/com/tangem/tap/features/details/ui/appsettings/AppSettingsViewModel.kt index 1a473c49ec..34a693dbb4 100644 --- a/app/src/main/java/com/tangem/tap/features/details/ui/appsettings/AppSettingsViewModel.kt +++ b/app/src/main/java/com/tangem/tap/features/details/ui/appsettings/AppSettingsViewModel.kt @@ -1,16 +1,20 @@ package com.tangem.tap.features.details.ui.appsettings -import androidx.lifecycle.DefaultLifecycleObserver -import androidx.lifecycle.LifecycleOwner -import androidx.lifecycle.ViewModel -import androidx.lifecycle.lifecycleScope +import androidx.lifecycle.* +import com.tangem.common.routing.AppRoute import com.tangem.core.analytics.api.AnalyticsEventHandler -import com.tangem.core.navigation.AppScreen -import com.tangem.core.navigation.NavigationAction +import com.tangem.domain.appcurrency.model.AppCurrency import com.tangem.domain.appcurrency.repository.AppCurrencyRepository import com.tangem.domain.apptheme.model.AppThemeMode +import com.tangem.domain.apptheme.repository.AppThemeModeRepository +import com.tangem.domain.balancehiding.repositories.BalanceHidingRepository +import com.tangem.domain.settings.CanUseBiometryUseCase +import com.tangem.domain.settings.repositories.SettingsRepository +import com.tangem.domain.wallets.repository.WalletsRepository +import com.tangem.features.details.DetailsFeatureToggles import com.tangem.tap.common.analytics.events.AnalyticsParam import com.tangem.tap.common.analytics.events.Settings +import com.tangem.tap.common.extensions.dispatchNavigationAction import com.tangem.tap.common.extensions.dispatchOnMain import com.tangem.tap.common.extensions.dispatchWithMain import com.tangem.tap.features.details.redux.AppSetting @@ -26,14 +30,22 @@ import dagger.hilt.android.lifecycle.HiltViewModel import kotlinx.collections.immutable.ImmutableList import kotlinx.collections.immutable.toImmutableList import kotlinx.coroutines.flow.* +import kotlinx.coroutines.launch import org.rekotlin.StoreSubscriber import javax.inject.Inject +@Suppress("LongParameterList") @HiltViewModel internal class AppSettingsViewModel @Inject constructor( private val appCurrencyRepository: AppCurrencyRepository, + private val walletsRepository: WalletsRepository, + private val canUseBiometryUseCase: CanUseBiometryUseCase, + private val balanceHidingRepository: BalanceHidingRepository, private val analyticsEventHandler: AnalyticsEventHandler, + private val appThemeModeRepository: AppThemeModeRepository, + private val settingsRepository: SettingsRepository, private val appSettingsItemsAnalyticsSender: AppSettingsItemsAnalyticsSender, + private val detailsFeatureToggles: DetailsFeatureToggles, ) : ViewModel(), StoreSubscriber, DefaultLifecycleObserver { @@ -50,6 +62,9 @@ internal class AppSettingsViewModel @Inject constructor( init { bootstrapAppCurrencyUpdates() + if (detailsFeatureToggles.isRedesignEnabled) { + bootstrapBiometricsUpdates() + } subscribeToStoreChanges() sendItemsAnalytics() @@ -128,7 +143,7 @@ internal class AppSettingsViewModel @Inject constructor( } private fun showAppCurrencySelector() { - store.dispatchOnMain(NavigationAction.NavigateTo(AppScreen.AppCurrencySelector)) + store.dispatchNavigationAction { push(AppRoute.AppCurrencySelector) } } private fun showThemeModeSelector(selectedMode: AppThemeMode) { @@ -214,6 +229,19 @@ internal class AppSettingsViewModel @Inject constructor( .saveIn(appCurrencyUpdatesJobHolder) } + private fun bootstrapBiometricsUpdates() = viewModelScope.launch { + val state = AppSettingsState( + saveWallets = walletsRepository.shouldSaveUserWalletsSync(), + saveAccessCodes = settingsRepository.shouldSaveAccessCodes(), + isBiometricsAvailable = canUseBiometryUseCase(), + isHidingEnabled = balanceHidingRepository.getBalanceHidingSettings().isHidingEnabledInSettings, + selectedAppCurrency = appCurrencyRepository.getSelectedAppCurrency().firstOrNull() ?: AppCurrency.Default, + selectedThemeMode = appThemeModeRepository.getAppThemeMode().firstOrNull() ?: AppThemeMode.DEFAULT, + ) + + store.dispatchWithMain(DetailsAction.AppSettings.Prepare(state)) + } + private fun subscribeToStoreChanges() { store.subscribe(subscriber = this) { state -> state.skipRepeats { oldState, newState -> diff --git a/app/src/main/java/com/tangem/tap/features/details/ui/cardsettings/CardSettingsFragment.kt b/app/src/main/java/com/tangem/tap/features/details/ui/cardsettings/CardSettingsFragment.kt index c81e2d819e..328815f377 100644 --- a/app/src/main/java/com/tangem/tap/features/details/ui/cardsettings/CardSettingsFragment.kt +++ b/app/src/main/java/com/tangem/tap/features/details/ui/cardsettings/CardSettingsFragment.kt @@ -1,14 +1,12 @@ package com.tangem.tap.features.details.ui.cardsettings import androidx.compose.runtime.Composable +import androidx.compose.runtime.getValue import androidx.compose.ui.Modifier -import androidx.compose.ui.platform.LocalLifecycleOwner import androidx.fragment.app.viewModels -import com.tangem.core.navigation.NavigationAction +import androidx.lifecycle.compose.collectAsStateWithLifecycle import com.tangem.core.ui.UiDependencies import com.tangem.core.ui.screen.ComposeFragment -import com.tangem.tap.features.details.redux.DetailsAction -import com.tangem.tap.store import dagger.hilt.android.AndroidEntryPoint import javax.inject.Inject @@ -22,15 +20,8 @@ internal class CardSettingsFragment : ComposeFragment() { @Composable override fun ScreenContent(modifier: Modifier) { - LocalLifecycleOwner.current.lifecycle.addObserver(viewModel) + val state by viewModel.screenState.collectAsStateWithLifecycle() - CardSettingsScreen( - modifier = modifier, - state = viewModel.screenState.value, - onBackClick = { - store.dispatch(DetailsAction.ResetCardSettingsData) - store.dispatch(NavigationAction.PopBackTo()) - }, - ) + CardSettingsScreen(modifier = modifier, state = state) } } \ No newline at end of file diff --git a/app/src/main/java/com/tangem/tap/features/details/ui/cardsettings/CardSettingsScreen.kt b/app/src/main/java/com/tangem/tap/features/details/ui/cardsettings/CardSettingsScreen.kt index b0e2785b32..57f1103703 100644 --- a/app/src/main/java/com/tangem/tap/features/details/ui/cardsettings/CardSettingsScreen.kt +++ b/app/src/main/java/com/tangem/tap/features/details/ui/cardsettings/CardSettingsScreen.kt @@ -1,10 +1,13 @@ package com.tangem.tap.features.details.ui.cardsettings import android.content.res.Configuration -import androidx.compose.foundation.* +import androidx.compose.foundation.Image +import androidx.compose.foundation.clickable import androidx.compose.foundation.layout.* import androidx.compose.foundation.lazy.LazyColumn import androidx.compose.foundation.lazy.items +import androidx.compose.foundation.rememberScrollState +import androidx.compose.foundation.verticalScroll import androidx.compose.material.Text import androidx.compose.runtime.Composable import androidx.compose.ui.Modifier @@ -13,18 +16,14 @@ import androidx.compose.ui.layout.ContentScale import androidx.compose.ui.res.painterResource import androidx.compose.ui.res.stringResource import androidx.compose.ui.tooling.preview.Preview -import com.tangem.core.ui.res.TangemThemePreview import com.tangem.core.ui.res.TangemTheme +import com.tangem.core.ui.res.TangemThemePreview import com.tangem.tap.features.details.ui.common.DetailsMainButton import com.tangem.tap.features.details.ui.common.SettingsScreensScaffold import com.tangem.wallet.R @Composable -internal fun CardSettingsScreen( - state: CardSettingsScreenState, - onBackClick: () -> Unit, - modifier: Modifier = Modifier, -) { +internal fun CardSettingsScreen(state: CardSettingsScreenState, modifier: Modifier = Modifier) { val needReadCard = state.cardDetails == null SettingsScreensScaffold( @@ -37,7 +36,7 @@ internal fun CardSettingsScreen( } }, titleRes = R.string.card_settings_title, - onBackClick = onBackClick, + onBackClick = state.onBackClick, ) } @@ -180,7 +179,7 @@ private fun CardSettings(state: CardSettingsScreenState) { // region Preview @Composable private fun CardSettingsScreenStateSample() { - CardSettingsScreen(state = CardSettingsScreenState(onScanCardClick = {}, onElementClick = {}), {}) + CardSettingsScreen(state = CardSettingsScreenState(onBackClick = {}, onScanCardClick = {}, onElementClick = {})) } @Preview(showBackground = true, widthDp = 360) diff --git a/app/src/main/java/com/tangem/tap/features/details/ui/cardsettings/CardSettingsScreenState.kt b/app/src/main/java/com/tangem/tap/features/details/ui/cardsettings/CardSettingsScreenState.kt index 4cf5e68186..bbde2c8579 100644 --- a/app/src/main/java/com/tangem/tap/features/details/ui/cardsettings/CardSettingsScreenState.kt +++ b/app/src/main/java/com/tangem/tap/features/details/ui/cardsettings/CardSettingsScreenState.kt @@ -4,18 +4,15 @@ import androidx.annotation.StringRes import androidx.compose.runtime.Composable import androidx.compose.runtime.ReadOnlyComposable import androidx.compose.ui.res.stringResource -import com.tangem.tap.features.details.redux.AccessCodeRecoveryState import com.tangem.tap.features.details.redux.SecurityOption import com.tangem.tap.features.details.ui.securitymode.toTitleRes -import com.tangem.tap.features.details.ui.utils.toResetCardDescriptionText import com.tangem.wallet.R -import com.tangem.tap.features.details.redux.CardInfo as ReduxCardInfo internal data class CardSettingsScreenState( val cardDetails: List? = null, - val accessCodeRecoveryState: AccessCodeRecoveryState? = null, val onScanCardClick: () -> Unit, val onElementClick: (CardInfo) -> Unit, + val onBackClick: () -> Unit, ) internal sealed class CardInfo( @@ -44,7 +41,7 @@ internal sealed class CardInfo( clickable = clickable, ) - object ChangeAccessCode : CardInfo( + data object ChangeAccessCode : CardInfo( titleRes = TextReference.Res(R.string.card_settings_change_access_code), subtitle = TextReference.Res(R.string.card_settings_change_access_code_footer), clickable = true, @@ -60,9 +57,9 @@ internal sealed class CardInfo( clickable = true, ) - class ResetToFactorySettings(cardInfo: ReduxCardInfo) : CardInfo( + class ResetToFactorySettings(description: TextReference) : CardInfo( titleRes = TextReference.Res(R.string.card_settings_reset_card_to_factory), - subtitle = cardInfo.toResetCardDescriptionText(), + subtitle = description, clickable = true, ) } diff --git a/app/src/main/java/com/tangem/tap/features/details/ui/cardsettings/CardSettingsViewModel.kt b/app/src/main/java/com/tangem/tap/features/details/ui/cardsettings/CardSettingsViewModel.kt index 64c00b50f4..7f972b948d 100644 --- a/app/src/main/java/com/tangem/tap/features/details/ui/cardsettings/CardSettingsViewModel.kt +++ b/app/src/main/java/com/tangem/tap/features/details/ui/cardsettings/CardSettingsViewModel.kt @@ -1,105 +1,132 @@ package com.tangem.tap.features.details.ui.cardsettings -import androidx.compose.runtime.MutableState -import androidx.compose.runtime.mutableStateOf -import androidx.lifecycle.DefaultLifecycleObserver -import androidx.lifecycle.LifecycleOwner +import android.os.Bundle +import androidx.lifecycle.SavedStateHandle import androidx.lifecycle.ViewModel -import arrow.core.Either +import androidx.lifecycle.viewModelScope +import com.tangem.common.CompletionResult +import com.tangem.common.doOnSuccess +import com.tangem.common.routing.AppRoute +import com.tangem.common.routing.AppRouter +import com.tangem.common.routing.bundle.unbundle import com.tangem.core.analytics.Analytics -import com.tangem.domain.common.TapWorkarounds.isTangemTwins -import com.tangem.domain.common.getTwinCardIdForUser -import com.tangem.domain.wallets.usecase.GetSelectedWalletSyncUseCase +import com.tangem.domain.card.ScanCardProcessor +import com.tangem.domain.common.CardTypesResolver +import com.tangem.domain.common.util.cardTypesResolver +import com.tangem.domain.models.scan.CardDTO +import com.tangem.domain.models.scan.ScanResponse +import com.tangem.domain.wallets.builder.UserWalletIdBuilder +import com.tangem.domain.wallets.models.UserWalletId import com.tangem.tap.common.analytics.events.AnalyticsParam import com.tangem.tap.common.analytics.events.Settings -import com.tangem.tap.features.details.redux.CardSettingsState -import com.tangem.tap.features.details.redux.DetailsAction -import com.tangem.tap.features.details.redux.DetailsState +import com.tangem.tap.common.extensions.dispatchDialogShow +import com.tangem.tap.common.extensions.dispatchNavigationAction +import com.tangem.tap.common.redux.AppDialog +import com.tangem.tap.domain.extensions.signedHashesCount +import com.tangem.tap.domain.sdk.TangemSdkManager +import com.tangem.tap.features.details.ui.cardsettings.domain.CardSettingsInteractor +import com.tangem.tap.features.details.ui.common.utils.* +import com.tangem.tap.features.onboarding.products.twins.redux.CreateTwinWalletMode +import com.tangem.tap.features.onboarding.products.twins.redux.TwinCardsAction import com.tangem.tap.store +import com.tangem.wallet.R import dagger.hilt.android.lifecycle.HiltViewModel -import org.rekotlin.StoreSubscriber +import kotlinx.coroutines.flow.* +import kotlinx.coroutines.launch import timber.log.Timber import javax.inject.Inject @HiltViewModel internal class CardSettingsViewModel @Inject constructor( - private val getSelectedWalletSyncUseCase: GetSelectedWalletSyncUseCase, -) : - ViewModel(), DefaultLifecycleObserver, StoreSubscriber { + private val scanCardProcessor: ScanCardProcessor, + private val tangemSdkManager: TangemSdkManager, + private val cardSettingsInteractor: CardSettingsInteractor, + savedStateHandle: SavedStateHandle, +) : ViewModel() { - var screenState: MutableState = - mutableStateOf(updateState(store.state.detailsState.cardSettingsState)) + private val userWalletId = savedStateHandle.get(AppRoute.CardSettings.USER_WALLET_ID_KEY) + ?.unbundle(UserWalletId.serializer()) + ?: error("User wallet ID is required for CardSettingsViewModel") - override fun onStart(owner: LifecycleOwner) { - when (val selectedWalletEither = getSelectedWalletSyncUseCase()) { - is Either.Left -> { - Timber.e(selectedWalletEither.value.toString()) + val screenState: MutableStateFlow = MutableStateFlow(getInitialState()) + + init { + cardSettingsInteractor.scannedScanResponse + .filterNotNull() + .onEach(::updateCardDetails) + .launchIn(viewModelScope) + } + + private fun getInitialState() = CardSettingsScreenState( + cardDetails = null, + onElementClick = ::handleClickingItem, + onScanCardClick = ::scanCard, + onBackClick = ::onBackClick, + ) + + private fun scanCard() = viewModelScope.launch { + scanCardProcessor.scan(allowsRequestAccessCodeFromRepository = true) + .doOnSuccess { scanResponse -> + val scannedUserWalletId = UserWalletIdBuilder.scanResponse(scanResponse).build() + if (userWalletId == scannedUserWalletId || scannedUserWalletId == null) { + cardSettingsInteractor.initialize(scanResponse) + } else { + store.dispatchDialogShow( + AppDialog.SimpleOkDialogRes( + headerId = R.string.common_warning, + messageId = R.string.error_wrong_wallet_tapped, + ), + ) + } + } + } + + private fun updateCardDetails(scanResponse: ScanResponse) { + val card = scanResponse.card + val cardTypesResolver = scanResponse.cardTypesResolver + val cardId = cardTypesResolver.getCardId() + + val currentSecurityOption = getCurrentSecurityOption(card) + val allowedSecurityOptions = getAllowedSecurityOptions( + card = card, + cardTypesResolver = cardTypesResolver, + currentSecurityOption = currentSecurityOption, + ) + val isResetCardAllowed = isResetToFactoryAllowedByCard(card, cardTypesResolver) + + val cardDetails = buildList { + CardInfo.CardId(cardId).let(::add) + CardInfo.Issuer(card.issuer.name).let(::add) + + if (!cardTypesResolver.isTangemTwins()) { + CardInfo.SignedHashes(card.signedHashesCount().toString()).let(::add) + } + + CardInfo.SecurityMode( + currentSecurityOption, + clickable = allowedSecurityOptions.size > 1, + ).let(::add) + + if (card.backupStatus?.isActive == true && card.isAccessCodeSet) { + CardInfo.ChangeAccessCode.let(::add) + } + + if (isAccessCodeRecoveryAllowed(cardTypesResolver)) { + CardInfo.AccessCodeRecovery(isAccessCodeRecoveryEnabled(cardTypesResolver, card)).let(::add) + } + + if (isResetCardAllowed) { + CardInfo.ResetToFactorySettings( + description = getResetToFactoryDescription( + isActiveBackupStatus = card.backupStatus?.isActive == true, + typesResolver = cardTypesResolver, + ), + ).let(::add) } - is Either.Right -> Unit } - store.subscribe(this) { state -> - state.skipRepeats { oldState, newState -> - oldState.detailsState == newState.detailsState - }.select { it.detailsState } - } - } - - override fun onStop(owner: LifecycleOwner) { - store.unsubscribe(this) - } - - override fun newState(state: DetailsState) { - screenState.value = updateState(state.cardSettingsState) - } - - private fun updateState(state: CardSettingsState?): CardSettingsScreenState { - return if (state?.manageSecurityState == null) { - CardSettingsScreenState( - cardDetails = null, - accessCodeRecoveryState = null, - onElementClick = {}, - onScanCardClick = { - store.dispatch(DetailsAction.ScanCard) - }, - ) - } else { - val cardId = if (state.card.isTangemTwins) { - state.card.getTwinCardIdForUser() - } else { - state.cardInfo.cardId - } - val cardDetails: MutableList = mutableListOf( - CardInfo.CardId(cardId), - CardInfo.Issuer(state.cardInfo.issuer), - ) - - if (!state.card.isTangemTwins) { - cardDetails.add(CardInfo.SignedHashes(state.cardInfo.signedHashes.toString())) - } - cardDetails.add( - CardInfo.SecurityMode( - securityOption = state.manageSecurityState.currentOption, - clickable = state.manageSecurityState.allowedOptions.size > 1, - ), - ) - if (state.card.backupStatus?.isActive == true && state.card.isAccessCodeSet) { - cardDetails.add(CardInfo.ChangeAccessCode) - } - if (state.accessCodeRecovery != null) { - cardDetails.add(CardInfo.AccessCodeRecovery(state.accessCodeRecovery.enabledOnCard)) - } - if (state.resetCardAllowed) { - cardDetails.add(CardInfo.ResetToFactorySettings(state.cardInfo)) - } - CardSettingsScreenState( - cardDetails = cardDetails, - accessCodeRecoveryState = state.accessCodeRecovery, - onScanCardClick = { }, - onElementClick = { - handleClickingItem(it) - }, - ) + screenState.update { state -> + state.copy(cardDetails = cardDetails) } } @@ -107,20 +134,77 @@ internal class CardSettingsViewModel @Inject constructor( when (item) { is CardInfo.ChangeAccessCode -> { Analytics.send(Settings.CardSettings.ButtonChangeUserCode(AnalyticsParam.UserCode.AccessCode)) - store.dispatch(DetailsAction.ManageSecurity.ChangeAccessCode) + changeAccessCode() } is CardInfo.ResetToFactorySettings -> { Analytics.send(Settings.CardSettings.ButtonFactoryReset()) - store.dispatch(DetailsAction.ResetToFactory.Start) + resetWalletToFactorySettings() } is CardInfo.SecurityMode -> { Analytics.send(Settings.CardSettings.ButtonChangeSecurityMode()) - store.dispatch(DetailsAction.ManageSecurity.OpenSecurity) + store.dispatchNavigationAction { + push(route = AppRoute.DetailsSecurity(userWalletId)) + } } is CardInfo.AccessCodeRecovery -> { - store.dispatch(DetailsAction.AccessCodeRecovery.Open) + store.dispatchNavigationAction { push(AppRoute.AccessCodeRecovery) } } else -> {} } } + + private fun resetWalletToFactorySettings() { + val scanResponse = requireNotNull(cardSettingsInteractor.scannedScanResponse.value) { + "Impossible to reset card if ScanResponse is null" + } + + if (scanResponse.cardTypesResolver.isTangemTwins()) { + store.dispatch(TwinCardsAction.SetMode(CreateTwinWalletMode.RecreateWallet(scanResponse))) + + cardSettingsInteractor.clear() + + store.dispatchNavigationAction { push(AppRoute.OnboardingTwins) } + } else { + val card = scanResponse.card + + store.dispatchNavigationAction { + push( + route = AppRoute.ResetToFactory( + userWalletId = userWalletId, + cardId = card.cardId, + isActiveBackupStatus = card.backupStatus?.isActive == true, + backupCardsCount = when (val status = card.backupStatus) { + is CardDTO.BackupStatus.Active -> status.cardCount + is CardDTO.BackupStatus.CardLinked, + CardDTO.BackupStatus.NoBackup, + null, + -> 0 + }, + ), + ) + } + } + } + + private fun changeAccessCode() = viewModelScope.launch { + val scanResponse = requireNotNull(cardSettingsInteractor.scannedScanResponse.value) { "Scan response is null" } + + when (val result = tangemSdkManager.setAccessCode(scanResponse.card.cardId)) { + is CompletionResult.Success -> Analytics.send(Settings.CardSettings.UserCodeChanged()) + is CompletionResult.Failure -> { + Timber.e("Failed to change access code: ${result.error}") + } + } + } + + private fun isResetToFactoryAllowedByCard(card: CardDTO, cardTypesResolver: CardTypesResolver): Boolean { + val hasPermanentWallet = card.wallets.any { it.settings.isPermanent } + val isNotAllowed = hasPermanentWallet || cardTypesResolver.isStart2Coin() + return !isNotAllowed + } + + private fun onBackClick() { + cardSettingsInteractor.clear() + store.dispatchNavigationAction(AppRouter::pop) + } } \ No newline at end of file diff --git a/app/src/main/java/com/tangem/tap/features/details/ui/cardsettings/coderecovery/AccessCodeRecoveryFragment.kt b/app/src/main/java/com/tangem/tap/features/details/ui/cardsettings/coderecovery/AccessCodeRecoveryFragment.kt index 7a365126b6..bcfe7cd28d 100644 --- a/app/src/main/java/com/tangem/tap/features/details/ui/cardsettings/coderecovery/AccessCodeRecoveryFragment.kt +++ b/app/src/main/java/com/tangem/tap/features/details/ui/cardsettings/coderecovery/AccessCodeRecoveryFragment.kt @@ -1,54 +1,33 @@ package com.tangem.tap.features.details.ui.cardsettings.coderecovery import androidx.compose.runtime.Composable -import androidx.compose.runtime.MutableState -import androidx.compose.runtime.mutableStateOf +import androidx.compose.runtime.getValue import androidx.compose.ui.Modifier -import com.tangem.core.navigation.NavigationAction +import androidx.fragment.app.viewModels +import androidx.lifecycle.compose.collectAsStateWithLifecycle +import com.tangem.common.routing.AppRouter import com.tangem.core.ui.UiDependencies import com.tangem.core.ui.screen.ComposeFragment -import com.tangem.tap.features.details.redux.DetailsState +import com.tangem.tap.common.extensions.dispatchNavigationAction import com.tangem.tap.store import dagger.hilt.android.AndroidEntryPoint -import org.rekotlin.StoreSubscriber import javax.inject.Inject @AndroidEntryPoint -class AccessCodeRecoveryFragment : ComposeFragment(), StoreSubscriber { +class AccessCodeRecoveryFragment : ComposeFragment() { - private val viewModel = AccessCodeRecoveryViewModel(store) - - private var screenState: MutableState = - mutableStateOf(viewModel.updateState(store.state.detailsState.cardSettingsState?.accessCodeRecovery)) + private val viewModel: AccessCodeRecoveryViewModel by viewModels() @Inject override lateinit var uiDependencies: UiDependencies @Composable override fun ScreenContent(modifier: Modifier) { + val state by viewModel.screenState.collectAsStateWithLifecycle() + AccessCodeRecoveryScreen( - state = screenState.value, - onBackClick = { store.dispatch(NavigationAction.PopBackTo()) }, + state = state, + onBackClick = { store.dispatchNavigationAction(AppRouter::pop) }, ) } - - override fun onStart() { - super.onStart() - store.subscribe(this) { state -> - state.skipRepeats { oldState, newState -> - oldState.detailsState == newState.detailsState - }.select { it.detailsState } - } - } - - override fun onStop() { - super.onStop() - store.unsubscribe(this) - } - - override fun newState(state: DetailsState) { - if (activity == null || view == null) return - screenState.value = - viewModel.updateState(store.state.detailsState.cardSettingsState?.accessCodeRecovery) - } } \ No newline at end of file diff --git a/app/src/main/java/com/tangem/tap/features/details/ui/cardsettings/coderecovery/AccessCodeRecoveryScreen.kt b/app/src/main/java/com/tangem/tap/features/details/ui/cardsettings/coderecovery/AccessCodeRecoveryScreen.kt index 12edf5a47e..d8107e0c4d 100644 --- a/app/src/main/java/com/tangem/tap/features/details/ui/cardsettings/coderecovery/AccessCodeRecoveryScreen.kt +++ b/app/src/main/java/com/tangem/tap/features/details/ui/cardsettings/coderecovery/AccessCodeRecoveryScreen.kt @@ -1,10 +1,6 @@ package com.tangem.tap.features.details.ui.cardsettings.coderecovery -import androidx.compose.foundation.layout.Arrangement -import androidx.compose.foundation.layout.Column -import androidx.compose.foundation.layout.Spacer -import androidx.compose.foundation.layout.fillMaxSize -import androidx.compose.foundation.layout.padding +import androidx.compose.foundation.layout.* import androidx.compose.foundation.rememberScrollState import androidx.compose.foundation.verticalScroll import androidx.compose.runtime.Composable @@ -57,7 +53,7 @@ fun AccessCodeRecoveryOptions(state: AccessCodeRecoveryScreenState) { DetailsMainButton( title = stringResource(id = R.string.common_save_changes), enabled = state.isSaveChangesEnabled, - onClick = { state.onSaveChangesClick(state.enabledSelection) }, + onClick = { state.onSaveChangesClick() }, modifier = Modifier.padding(horizontal = TangemTheme.dimens.spacing20), ) } diff --git a/app/src/main/java/com/tangem/tap/features/details/ui/cardsettings/coderecovery/AccessCodeRecoveryScreenState.kt b/app/src/main/java/com/tangem/tap/features/details/ui/cardsettings/coderecovery/AccessCodeRecoveryScreenState.kt index f1a825067a..b4b6c68535 100644 --- a/app/src/main/java/com/tangem/tap/features/details/ui/cardsettings/coderecovery/AccessCodeRecoveryScreenState.kt +++ b/app/src/main/java/com/tangem/tap/features/details/ui/cardsettings/coderecovery/AccessCodeRecoveryScreenState.kt @@ -11,6 +11,6 @@ data class AccessCodeRecoveryScreenState( val enabledOnCard: Boolean, val enabledSelection: Boolean, val isSaveChangesEnabled: Boolean, - val onSaveChangesClick: (Boolean) -> Unit, + val onSaveChangesClick: () -> Unit, val onOptionClick: (Boolean) -> Unit, ) \ No newline at end of file diff --git a/app/src/main/java/com/tangem/tap/features/details/ui/cardsettings/coderecovery/AccessCodeRecoveryViewModel.kt b/app/src/main/java/com/tangem/tap/features/details/ui/cardsettings/coderecovery/AccessCodeRecoveryViewModel.kt index a2948075f8..d65fb74a54 100644 --- a/app/src/main/java/com/tangem/tap/features/details/ui/cardsettings/coderecovery/AccessCodeRecoveryViewModel.kt +++ b/app/src/main/java/com/tangem/tap/features/details/ui/cardsettings/coderecovery/AccessCodeRecoveryViewModel.kt @@ -1,29 +1,83 @@ package com.tangem.tap.features.details.ui.cardsettings.coderecovery -import com.tangem.tap.common.redux.AppState -import com.tangem.tap.features.details.redux.AccessCodeRecoveryState -import com.tangem.tap.features.details.redux.DetailsAction -import org.rekotlin.Store +import androidx.lifecycle.ViewModel +import androidx.lifecycle.viewModelScope +import com.tangem.common.doOnSuccess +import com.tangem.common.routing.AppRouter +import com.tangem.core.analytics.Analytics +import com.tangem.domain.common.util.cardTypesResolver +import com.tangem.tap.common.analytics.events.AnalyticsParam +import com.tangem.tap.common.analytics.events.Settings +import com.tangem.tap.common.extensions.dispatchNavigationAction +import com.tangem.tap.domain.sdk.TangemSdkManager +import com.tangem.tap.features.details.ui.cardsettings.domain.CardSettingsInteractor +import com.tangem.tap.features.details.ui.common.utils.isAccessCodeRecoveryEnabled +import com.tangem.tap.store +import dagger.hilt.android.lifecycle.HiltViewModel +import kotlinx.coroutines.flow.MutableStateFlow +import kotlinx.coroutines.flow.update +import kotlinx.coroutines.launch +import javax.inject.Inject -class AccessCodeRecoveryViewModel(val store: Store) { +@HiltViewModel +internal class AccessCodeRecoveryViewModel @Inject constructor( + private val tangemSdkManager: TangemSdkManager, + private val cardSettingsInteractor: CardSettingsInteractor, +) : ViewModel() { - fun updateState(state: AccessCodeRecoveryState?): AccessCodeRecoveryScreenState { - // We shouldn't get to this screen here when this state is null - return if (state == null) { - AccessCodeRecoveryScreenState( - enabledOnCard = false, - enabledSelection = false, - isSaveChangesEnabled = false, - onSaveChangesClick = {}, - onOptionClick = {}, - ) - } else { - AccessCodeRecoveryScreenState( - enabledOnCard = state.enabledOnCard, - enabledSelection = state.enabledSelection, - isSaveChangesEnabled = state.enabledOnCard != state.enabledSelection, - onSaveChangesClick = { store.dispatch(DetailsAction.AccessCodeRecovery.SaveChanges(it)) }, - onOptionClick = { store.dispatch(DetailsAction.AccessCodeRecovery.SelectOption(it)) }, + private val scannedScanResponse = cardSettingsInteractor.scannedScanResponse.value + ?: error("Scan response is null") + + val screenState = MutableStateFlow( + value = getInitialState(), + ) + + private fun getInitialState(): AccessCodeRecoveryScreenState { + val isEnabled = isAccessCodeRecoveryEnabled( + typeResolver = scannedScanResponse.cardTypesResolver, + card = scannedScanResponse.card, + ) + + return AccessCodeRecoveryScreenState( + enabledOnCard = isEnabled, + enabledSelection = isEnabled, + isSaveChangesEnabled = false, + onSaveChangesClick = ::saveChanges, + onOptionClick = ::selectOption, + ) + } + + private fun saveChanges() = viewModelScope.launch { + val isEnabled = screenState.value.enabledSelection + + tangemSdkManager + .setAccessCodeRecoveryEnabled(scannedScanResponse.card.cardId, isEnabled) + .doOnSuccess { + Analytics.send( + Settings.CardSettings.AccessCodeRecoveryChanged( + AnalyticsParam.AccessCodeRecoveryStatus.from(isEnabled), + ), + ) + + cardSettingsInteractor.update { scanResponse -> + scanResponse.copy( + card = scanResponse.card.copy( + userSettings = scanResponse.card.userSettings?.copy( + isUserCodeRecoveryAllowed = isEnabled, + ), + ), + ) + } + + store.dispatchNavigationAction(AppRouter::pop) + } + } + + private fun selectOption(isEnabled: Boolean) { + screenState.update { + it.copy( + enabledSelection = isEnabled, + isSaveChangesEnabled = isEnabled != it.enabledOnCard, ) } } diff --git a/app/src/main/java/com/tangem/tap/features/details/ui/cardsettings/domain/CardSettingsInteractor.kt b/app/src/main/java/com/tangem/tap/features/details/ui/cardsettings/domain/CardSettingsInteractor.kt new file mode 100644 index 0000000000..73bbf10991 --- /dev/null +++ b/app/src/main/java/com/tangem/tap/features/details/ui/cardsettings/domain/CardSettingsInteractor.kt @@ -0,0 +1,35 @@ +package com.tangem.tap.features.details.ui.cardsettings.domain + +import com.tangem.domain.models.scan.ScanResponse +import kotlinx.coroutines.flow.MutableStateFlow +import kotlinx.coroutines.flow.StateFlow +import kotlinx.coroutines.flow.update +import javax.inject.Inject +import javax.inject.Singleton + +/** + * Interactor for sharing logic and data between all card settings screens + * +[REDACTED_AUTHOR] + */ +@Singleton +internal class CardSettingsInteractor @Inject constructor() { + + private val _scannedScanResponse = MutableStateFlow(value = null) + val scannedScanResponse: StateFlow = _scannedScanResponse + + fun initialize(scanResponse: ScanResponse) { + _scannedScanResponse.value = scanResponse + } + + fun update(transform: (ScanResponse) -> ScanResponse) { + _scannedScanResponse.update { + requireNotNull(it) + transform(it) + } + } + + fun clear() { + _scannedScanResponse.value = null + } +} \ No newline at end of file diff --git a/app/src/main/java/com/tangem/tap/features/details/ui/common/DetailsComposeElements.kt b/app/src/main/java/com/tangem/tap/features/details/ui/common/DetailsComposeElements.kt index 35b36c0f00..8cdc6777a9 100644 --- a/app/src/main/java/com/tangem/tap/features/details/ui/common/DetailsComposeElements.kt +++ b/app/src/main/java/com/tangem/tap/features/details/ui/common/DetailsComposeElements.kt @@ -13,8 +13,8 @@ import androidx.compose.ui.res.painterResource import androidx.compose.ui.res.stringResource import androidx.compose.ui.unit.dp import com.tangem.core.ui.components.PrimaryButtonIconEnd -import com.tangem.core.ui.components.SystemBarsEffect import com.tangem.core.ui.res.TangemTheme +import com.tangem.core.ui.utils.WindowInsetsZero import com.tangem.wallet.R @Composable @@ -24,31 +24,42 @@ internal fun SettingsScreensScaffold( modifier: Modifier = Modifier, @StringRes titleRes: Int? = null, snackbarHostState: SnackbarHostState = remember { SnackbarHostState() }, + addBottomInsets: Boolean = true, fab: @Composable () -> Unit = {}, ) { val state = rememberScaffoldState(snackbarHostState = snackbarHostState) val backgroundColor = TangemTheme.colors.background.secondary BackHandler(onBack = onBackClick) - SystemBarsEffect { - setSystemBarsColor(backgroundColor) - } Scaffold( scaffoldState = state, topBar = { EmptyTopBarWithNavigation( + modifier = Modifier.statusBarsPadding(), onBackClick = onBackClick, backgroundColor = backgroundColor, ) }, - modifier = modifier.systemBarsPadding(), + modifier = modifier, + contentWindowInsets = WindowInsetsZero, backgroundColor = backgroundColor, - floatingActionButton = fab, - content = { paddings -> + floatingActionButton = { + Box(modifier = Modifier.navigationBarsPadding()) { + fab() + } + }, + content = { paddingValues -> Column( modifier = Modifier - .padding(paddings) + .run { + if (addBottomInsets) { + navigationBarsPadding() + } else { + this + } + } + .padding(paddingValues) .fillMaxSize(), ) { if (titleRes != null) { @@ -81,9 +92,11 @@ internal fun ScreenTitle(titleRes: Int, modifier: Modifier = Modifier) { @Composable internal fun EmptyTopBarWithNavigation( onBackClick: () -> Unit, + modifier: Modifier = Modifier, backgroundColor: Color = TangemTheme.colors.background.primary, ) { TopAppBar( + modifier = modifier, title = { }, navigationIcon = { diff --git a/app/src/main/java/com/tangem/tap/features/details/ui/common/utils/AccessCodeRecovery.kt b/app/src/main/java/com/tangem/tap/features/details/ui/common/utils/AccessCodeRecovery.kt new file mode 100644 index 0000000000..c08b50c4e5 --- /dev/null +++ b/app/src/main/java/com/tangem/tap/features/details/ui/common/utils/AccessCodeRecovery.kt @@ -0,0 +1,13 @@ +package com.tangem.tap.features.details.ui.common.utils + +import com.tangem.domain.common.CardTypesResolver +import com.tangem.domain.models.scan.CardDTO + +internal fun isAccessCodeRecoveryAllowed(typeResolver: CardTypesResolver): Boolean = typeResolver.isWallet2() + +internal fun isAccessCodeRecoveryEnabled(typeResolver: CardTypesResolver, card: CardDTO): Boolean = + if (typeResolver.isWallet2()) { + card.userSettings?.isUserCodeRecoveryAllowed ?: false + } else { + false + } \ No newline at end of file diff --git a/app/src/main/java/com/tangem/tap/features/details/ui/common/utils/ResetToFactory.kt b/app/src/main/java/com/tangem/tap/features/details/ui/common/utils/ResetToFactory.kt new file mode 100644 index 0000000000..b269ee6352 --- /dev/null +++ b/app/src/main/java/com/tangem/tap/features/details/ui/common/utils/ResetToFactory.kt @@ -0,0 +1,16 @@ +package com.tangem.tap.features.details.ui.common.utils + +import com.tangem.domain.common.CardTypesResolver +import com.tangem.tap.features.details.ui.cardsettings.TextReference +import com.tangem.wallet.R + +internal fun getResetToFactoryDescription( + isActiveBackupStatus: Boolean, + typesResolver: CardTypesResolver, +): TextReference { + return if (!isActiveBackupStatus || typesResolver.isTangemTwins()) { + TextReference.Res(R.string.reset_card_without_backup_to_factory_message) + } else { + TextReference.Res(R.string.reset_card_with_backup_to_factory_message) + } +} \ No newline at end of file diff --git a/app/src/main/java/com/tangem/tap/features/details/ui/common/utils/SecurityOptionsUtils.kt b/app/src/main/java/com/tangem/tap/features/details/ui/common/utils/SecurityOptionsUtils.kt new file mode 100644 index 0000000000..0a62abe82e --- /dev/null +++ b/app/src/main/java/com/tangem/tap/features/details/ui/common/utils/SecurityOptionsUtils.kt @@ -0,0 +1,44 @@ +package com.tangem.tap.features.details.ui.common.utils + +import com.tangem.domain.common.CardTypesResolver +import com.tangem.domain.models.scan.CardDTO +import com.tangem.tap.features.details.redux.SecurityOption +import java.util.EnumSet + +internal fun getCurrentSecurityOption(card: CardDTO): SecurityOption = when { + card.isAccessCodeSet -> SecurityOption.AccessCode + card.isPasscodeSet == true -> SecurityOption.PassCode + else -> SecurityOption.LongTap +} + +internal fun getAllowedSecurityOptions( + card: CardDTO, + cardTypesResolver: CardTypesResolver, + currentSecurityOption: SecurityOption, +): EnumSet = when { + cardTypesResolver.isStart2Coin() || cardTypesResolver.isTangemNote() -> EnumSet.of(SecurityOption.LongTap) + card.settings.isBackupAllowed -> EnumSet.of(currentSecurityOption) + else -> prepareAllowedSecurityOptions( + cardTypesResolver = cardTypesResolver, + currentSecurityOption = currentSecurityOption, + ) +} + +private fun prepareAllowedSecurityOptions( + cardTypesResolver: CardTypesResolver, + currentSecurityOption: SecurityOption?, +): EnumSet { + val allowedSecurityOptions = EnumSet.of(SecurityOption.LongTap) + + if (cardTypesResolver.isTangemTwins()) { + allowedSecurityOptions.add(SecurityOption.PassCode) + } + if (currentSecurityOption == SecurityOption.AccessCode) { + allowedSecurityOptions.add(SecurityOption.AccessCode) + } + if (currentSecurityOption == SecurityOption.PassCode) { + allowedSecurityOptions.add(SecurityOption.PassCode) + } + + return allowedSecurityOptions +} \ No newline at end of file diff --git a/app/src/main/java/com/tangem/tap/features/details/ui/details/DetailsFragment.kt b/app/src/main/java/com/tangem/tap/features/details/ui/details/DetailsFragment.kt index a382e52b7f..5b41307402 100644 --- a/app/src/main/java/com/tangem/tap/features/details/ui/details/DetailsFragment.kt +++ b/app/src/main/java/com/tangem/tap/features/details/ui/details/DetailsFragment.kt @@ -3,13 +3,14 @@ package com.tangem.tap.features.details.ui.details import android.os.Bundle import androidx.compose.runtime.Composable import androidx.compose.ui.Modifier +import com.tangem.common.routing.AppRouter import com.tangem.core.analytics.Analytics -import com.tangem.core.navigation.NavigationAction import com.tangem.core.ui.UiDependencies import com.tangem.core.ui.screen.ComposeFragment import com.tangem.domain.wallets.legacy.UserWalletsListManager import com.tangem.domain.wallets.repository.WalletsRepository import com.tangem.tap.common.analytics.events.Settings +import com.tangem.tap.common.extensions.dispatchNavigationAction import com.tangem.tap.features.details.redux.DetailsState import com.tangem.tap.store import dagger.hilt.android.AndroidEntryPoint @@ -45,7 +46,7 @@ internal class DetailsFragment : ComposeFragment(), StoreSubscriber Unit, ) : SettingsItem( - iconResId = R.drawable.ic_more_cards, + iconResId = R.drawable.ic_more_cards_24, title = resourceReference(R.string.details_row_title_create_backup), ) data class CardSettings( override val onClick: () -> Unit, ) : SettingsItem( - iconResId = R.drawable.ic_card_settings, + iconResId = R.drawable.ic_card_settings_24, title = resourceReference(R.string.card_settings_title), ) @@ -95,7 +95,7 @@ internal sealed class SettingsItem( data class ReferralProgram( override val onClick: () -> Unit, ) : SettingsItem( - iconResId = R.drawable.ic_add_friends, + iconResId = R.drawable.ic_add_friends_24, title = resourceReference(R.string.details_referral_title), ) diff --git a/app/src/main/java/com/tangem/tap/features/details/ui/details/DetailsViewModel.kt b/app/src/main/java/com/tangem/tap/features/details/ui/details/DetailsViewModel.kt index 95a6865b3c..d2c84a43db 100644 --- a/app/src/main/java/com/tangem/tap/features/details/ui/details/DetailsViewModel.kt +++ b/app/src/main/java/com/tangem/tap/features/details/ui/details/DetailsViewModel.kt @@ -3,11 +3,11 @@ package com.tangem.tap.features.details.ui.details import androidx.compose.runtime.MutableState import androidx.compose.runtime.mutableStateOf import com.tangem.common.extensions.guard +import com.tangem.common.routing.AppRoute import com.tangem.core.analytics.Analytics import com.tangem.core.analytics.models.AnalyticsParam import com.tangem.core.analytics.models.Basic -import com.tangem.core.navigation.AppScreen -import com.tangem.core.navigation.NavigationAction + import com.tangem.core.ui.event.StateEvent import com.tangem.core.ui.event.consumedEvent import com.tangem.core.ui.event.triggeredEvent @@ -16,15 +16,14 @@ import com.tangem.domain.common.util.cardTypesResolver import com.tangem.domain.wallets.legacy.UserWalletsListManager import com.tangem.domain.wallets.repository.WalletsRepository import com.tangem.tap.common.analytics.events.Settings -import com.tangem.tap.common.extensions.addContext -import com.tangem.tap.common.extensions.dispatchOnMain -import com.tangem.tap.common.extensions.dispatchWithMain +import com.tangem.tap.common.extensions.* import com.tangem.tap.common.feedback.FeedbackEmail import com.tangem.tap.common.redux.AppState import com.tangem.tap.common.redux.global.GlobalAction import com.tangem.tap.features.details.redux.DetailsAction import com.tangem.tap.features.details.redux.DetailsState import com.tangem.tap.features.disclaimer.redux.DisclaimerAction +import com.tangem.tap.features.disclaimer.redux.DisclaimerSource import com.tangem.tap.features.home.LocaleRegionProvider import com.tangem.tap.features.home.RUSSIA_COUNTRY_CODE import com.tangem.tap.scope @@ -40,7 +39,6 @@ import kotlinx.coroutines.flow.onEach import org.rekotlin.Store import timber.log.Timber -// TODO: change to Android ViewModel [REDACTED_JIRA] internal class DetailsViewModel( private val store: Store, private val walletsRepository: WalletsRepository, @@ -91,10 +89,6 @@ internal class DetailsViewModel( SettingsItem.AppSettings(::navigateToAppSettings) .let(::add) - // removed chat in task [REDACTED_TASK_KEY] - // SettingsItem.Chat(::navigateToChat) - // .let(::add) - SettingsItem.SendFeedback(::sendFeedback) .let(::add) @@ -128,30 +122,43 @@ internal class DetailsViewModel( } private fun navigateToTesterMenu() { - store.state.daggerGraphState.testerRouter?.startTesterScreen() + store.dispatchNavigationAction { + push(AppRoute.TesterMenu) + } } private fun navigateToToS() { - store.dispatchOnMain(DisclaimerAction.Show(AppScreen.Details)) + store.dispatchOnMain(DisclaimerAction.Show(DisclaimerSource.Details)) } private fun navigateToReferralProgram() { - store.dispatchOnMain(NavigationAction.NavigateTo(AppScreen.ReferralProgram)) + val userWallet = userWalletsListManager.selectedUserWalletSync + ?: error("Selected wallet must be not null") + + store.dispatchNavigationAction { push(AppRoute.ReferralProgram(userWallet.walletId)) } } private fun sendFeedback() { Analytics.send(Basic.ButtonSupport(AnalyticsParam.ScreensSources.Settings)) - store.dispatchOnMain(GlobalAction.SendEmail(FeedbackEmail())) + store.dispatchOnMain( + GlobalAction.SendEmail( + feedbackData = FeedbackEmail(), + scanResponse = userWalletsListManager.selectedUserWalletSync?.scanResponse + ?: error("ScanResponse must be not null"), + ), + ) } private fun navigateToAppSettings() { Analytics.send(Settings.ButtonAppSettings()) - store.dispatchOnMain(NavigationAction.NavigateTo(AppScreen.AppSettings)) + store.dispatchNavigationAction { push(AppRoute.AppSettings) } } private fun navigateToCardSettings() { + val userWalletId = userWalletsListManager.selectedUserWalletSync?.walletId + ?: error("UserWalletId must be not null") Analytics.send(Settings.ButtonCardSettings()) - store.dispatchOnMain(NavigationAction.NavigateTo(AppScreen.CardSettings)) + store.dispatchNavigationAction { push(AppRoute.CardSettings(userWalletId)) } } private fun linkMoreCards() { @@ -164,7 +171,7 @@ internal class DetailsViewModel( val scanResponse = selectedUserWallet.scanResponse Analytics.addContext(scanResponse) store.dispatch(GlobalAction.Onboarding.Start(scanResponse, canSkipBackup = false)) - store.dispatch(NavigationAction.NavigateTo(AppScreen.OnboardingWallet)) + store.dispatchNavigationAction { push(AppRoute.OnboardingWallet()) } } private fun scanAndSaveUserWallet() { @@ -174,12 +181,12 @@ internal class DetailsViewModel( private fun navigateToWalletConnect() { Analytics.send(Settings.ButtonWalletConnect()) - store.dispatchOnMain(NavigationAction.NavigateTo(AppScreen.WalletConnectSessions)) + store.dispatchNavigationAction { push(AppRoute.WalletConnectSessions) } } private fun handleSocialNetworkClick(link: SocialNetworkLink) { Analytics.send(Settings.ButtonSocialNetwork(link.network)) - store.dispatchOnMain(NavigationAction.OpenUrl(link.url)) + store.dispatchOpenUrl(link.url) } private fun getSocialLinks(): ImmutableList { diff --git a/app/src/main/java/com/tangem/tap/features/details/ui/resetcard/ResetCardFragment.kt b/app/src/main/java/com/tangem/tap/features/details/ui/resetcard/ResetCardFragment.kt index 74424cd8ba..041a91ee08 100644 --- a/app/src/main/java/com/tangem/tap/features/details/ui/resetcard/ResetCardFragment.kt +++ b/app/src/main/java/com/tangem/tap/features/details/ui/resetcard/ResetCardFragment.kt @@ -1,56 +1,34 @@ package com.tangem.tap.features.details.ui.resetcard import androidx.compose.runtime.Composable +import androidx.compose.runtime.getValue import androidx.compose.ui.Modifier import androidx.fragment.app.viewModels import androidx.lifecycle.compose.collectAsStateWithLifecycle -import com.tangem.core.navigation.NavigationAction +import com.tangem.common.routing.AppRouter import com.tangem.core.ui.UiDependencies import com.tangem.core.ui.screen.ComposeFragment -import com.tangem.tap.features.details.redux.DetailsState +import com.tangem.tap.common.extensions.dispatchNavigationAction import com.tangem.tap.store import dagger.hilt.android.AndroidEntryPoint -import kotlinx.coroutines.flow.MutableStateFlow -import org.rekotlin.StoreSubscriber import javax.inject.Inject @AndroidEntryPoint -internal class ResetCardFragment : ComposeFragment(), StoreSubscriber { +internal class ResetCardFragment : ComposeFragment() { @Inject override lateinit var uiDependencies: UiDependencies private val viewModel: ResetCardViewModel by viewModels() - private var screenState = MutableStateFlow(ResetCardScreenState.InitialState) - @Composable override fun ScreenContent(modifier: Modifier) { - val state = screenState.collectAsStateWithLifecycle().value + val state by viewModel.screenState.collectAsStateWithLifecycle() ResetCardScreen( state = state, - onBackClick = { store.dispatch(NavigationAction.PopBackTo()) }, + onBackClick = { store.dispatchNavigationAction(AppRouter::pop) }, modifier = modifier, ) } - - override fun onStart() { - super.onStart() - store.subscribe(this) { state -> - state.skipRepeats { oldState, newState -> - oldState.detailsState == newState.detailsState - }.select { it.detailsState } - } - } - - override fun onStop() { - super.onStop() - store.unsubscribe(this) - } - - override fun newState(state: DetailsState) { - if (activity == null || view == null) return - screenState.value = viewModel.updateState(state.cardSettingsState) - } } \ No newline at end of file diff --git a/app/src/main/java/com/tangem/tap/features/details/ui/resetcard/ResetCardScreen.kt b/app/src/main/java/com/tangem/tap/features/details/ui/resetcard/ResetCardScreen.kt index 85bec44728..1b52a50fd1 100644 --- a/app/src/main/java/com/tangem/tap/features/details/ui/resetcard/ResetCardScreen.kt +++ b/app/src/main/java/com/tangem/tap/features/details/ui/resetcard/ResetCardScreen.kt @@ -20,24 +20,19 @@ import com.tangem.tap.features.details.ui.cardsettings.resolveReference import com.tangem.tap.features.details.ui.common.DetailsMainButton import com.tangem.tap.features.details.ui.common.SettingsScreensScaffold import com.tangem.wallet.R -import com.tangem.tap.features.details.ui.resetcard.ResetCardScreenState.ResetCardScreenContent.Dialog as ResetCardDialog +import com.tangem.tap.features.details.ui.resetcard.ResetCardScreenState.Dialog as ResetCardDialog @Composable internal fun ResetCardScreen(state: ResetCardScreenState, onBackClick: () -> Unit, modifier: Modifier = Modifier) { SettingsScreensScaffold( modifier = modifier, content = { - when (state) { - is ResetCardScreenState.ResetCardScreenContent -> ResetCardView(state = state) - ResetCardScreenState.InitialState -> { - // do nothing for now, just white screen - } - } + ResetCardView(state = state) }, onBackClick = onBackClick, ) - when (val dialog = (state as? ResetCardScreenState.ResetCardScreenContent)?.dialog) { + when (val dialog = state.dialog) { is ResetCardDialog.StartReset, is ResetCardDialog.ContinueReset, is ResetCardDialog.InterruptedReset, @@ -48,7 +43,7 @@ internal fun ResetCardScreen(state: ResetCardScreenState, onBackClick: () -> Uni } @Composable -private fun ResetCardView(state: ResetCardScreenState.ResetCardScreenContent) { +private fun ResetCardView(state: ResetCardScreenState) { val scrollState = rememberScrollState() Column( @@ -110,7 +105,7 @@ private fun Description(text: TextReference) { } @Composable -private fun Conditions(state: ResetCardScreenState.ResetCardScreenContent) { +private fun Conditions(state: ResetCardScreenState) { state.warningsToShow.forEach { when (it) { ResetCardScreenState.WarningsToReset.LOST_WALLET_ACCESS -> { @@ -120,7 +115,6 @@ private fun Conditions(state: ResetCardScreenState.ResetCardScreenContent) { description = TextReference.Res(R.string.reset_card_to_factory_condition_1), ) } - ResetCardScreenState.WarningsToReset.LOST_PASSWORD_RESTORE -> { ConditionCheckBox( checkedState = state.acceptCondition2Checked, @@ -192,7 +186,7 @@ private fun ResetButton(enabled: Boolean, onResetButtonClick: () -> Unit) { } @Composable -private fun CommonResetDialog(dialog: ResetCardScreenState.ResetCardScreenContent.Dialog) { +private fun CommonResetDialog(dialog: ResetCardScreenState.Dialog) { BasicDialog( title = stringResource(dialog.titleResId), message = stringResource(dialog.messageResId), @@ -231,10 +225,13 @@ private fun ResetCardScreenSample(modifier: Modifier = Modifier) { .background(TangemTheme.colors.background.secondary), ) { ResetCardScreen( - state = ResetCardScreenState.ResetCardScreenContent( - accepted = true, + state = ResetCardScreenState( + resetButtonEnabled = true, + showResetPasswordButton = false, warningsToShow = listOf(ResetCardScreenState.WarningsToReset.LOST_WALLET_ACCESS), descriptionText = TextReference.Res(R.string.reset_card_with_backup_to_factory_message), + acceptCondition1Checked = false, + acceptCondition2Checked = false, onAcceptCondition1ToggleClick = {}, onAcceptCondition2ToggleClick = {}, onResetButtonClick = {}, diff --git a/app/src/main/java/com/tangem/tap/features/details/ui/resetcard/ResetCardScreenState.kt b/app/src/main/java/com/tangem/tap/features/details/ui/resetcard/ResetCardScreenState.kt index 0bcff503bc..27dacf387f 100644 --- a/app/src/main/java/com/tangem/tap/features/details/ui/resetcard/ResetCardScreenState.kt +++ b/app/src/main/java/com/tangem/tap/features/details/ui/resetcard/ResetCardScreenState.kt @@ -4,63 +4,57 @@ import androidx.annotation.StringRes import com.tangem.tap.features.details.ui.cardsettings.TextReference import com.tangem.wallet.R -internal sealed class ResetCardScreenState { +internal data class ResetCardScreenState( + val resetButtonEnabled: Boolean, + val descriptionText: TextReference, + val warningsToShow: List, + val showResetPasswordButton: Boolean, + val acceptCondition1Checked: Boolean, + val acceptCondition2Checked: Boolean, + val onAcceptCondition1ToggleClick: (Boolean) -> Unit, + val onAcceptCondition2ToggleClick: (Boolean) -> Unit, + val onResetButtonClick: () -> Unit, + val dialog: Dialog?, +) { - object InitialState : ResetCardScreenState() + sealed class Dialog( + @StringRes val titleResId: Int, + @StringRes val messageResId: Int, + ) { - data class ResetCardScreenContent( - val accepted: Boolean = false, - val descriptionText: TextReference, - val warningsToShow: List, - val acceptCondition1Checked: Boolean = false, - val acceptCondition2Checked: Boolean = false, - val onAcceptCondition1ToggleClick: (Boolean) -> Unit, - val onAcceptCondition2ToggleClick: (Boolean) -> Unit, - val onResetButtonClick: () -> Unit, - val dialog: Dialog? = null, - ) : ResetCardScreenState() { - val resetButtonEnabled: Boolean - get() = accepted + abstract val onConfirmClick: () -> Unit + abstract val onDismiss: () -> Unit - sealed class Dialog( - @StringRes val titleResId: Int, - @StringRes val messageResId: Int, + data class StartReset( + override val onConfirmClick: () -> Unit, + override val onDismiss: () -> Unit, + ) : Dialog( + titleResId = R.string.common_attention, + messageResId = R.string.card_settings_action_sheet_title, + ) + + data class ContinueReset( + override val onConfirmClick: () -> Unit, + override val onDismiss: () -> Unit, + ) : Dialog( + titleResId = R.string.card_settings_continue_reset_alert_title, + messageResId = R.string.card_settings_continue_reset_alert_message, + ) + + data class InterruptedReset( + override val onConfirmClick: () -> Unit, + override val onDismiss: () -> Unit, + ) : Dialog( + titleResId = R.string.card_settings_interrupted_reset_alert_title, + messageResId = R.string.card_settings_interrupted_reset_alert_message, + ) + + data class CompletedReset(override val onConfirmClick: () -> Unit) : Dialog( + titleResId = R.string.card_settings_completed_reset_alert_title, + messageResId = R.string.card_settings_completed_reset_alert_message, ) { - abstract val onConfirmClick: () -> Unit - abstract val onDismiss: () -> Unit - - data class StartReset( - override val onConfirmClick: () -> Unit, - override val onDismiss: () -> Unit, - ) : Dialog( - titleResId = R.string.common_attention, - messageResId = R.string.card_settings_action_sheet_title, - ) - - data class ContinueReset( - override val onConfirmClick: () -> Unit, - override val onDismiss: () -> Unit, - ) : Dialog( - titleResId = R.string.card_settings_continue_reset_alert_title, - messageResId = R.string.card_settings_continue_reset_alert_message, - ) - - data class InterruptedReset( - override val onConfirmClick: () -> Unit, - override val onDismiss: () -> Unit, - ) : Dialog( - titleResId = R.string.card_settings_interrupted_reset_alert_title, - messageResId = R.string.card_settings_interrupted_reset_alert_message, - ) - - data class CompletedReset(override val onConfirmClick: () -> Unit) : Dialog( - titleResId = R.string.card_settings_completed_reset_alert_title, - messageResId = R.string.card_settings_completed_reset_alert_message, - ) { - - override val onDismiss: () -> Unit = {} - } + override val onDismiss: () -> Unit = {} } } diff --git a/app/src/main/java/com/tangem/tap/features/details/ui/resetcard/ResetCardViewModel.kt b/app/src/main/java/com/tangem/tap/features/details/ui/resetcard/ResetCardViewModel.kt index 07f7857126..fefbdf122e 100644 --- a/app/src/main/java/com/tangem/tap/features/details/ui/resetcard/ResetCardViewModel.kt +++ b/app/src/main/java/com/tangem/tap/features/details/ui/resetcard/ResetCardViewModel.kt @@ -1,104 +1,170 @@ package com.tangem.tap.features.details.ui.resetcard +import android.os.Bundle +import androidx.lifecycle.SavedStateHandle import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope +import arrow.core.getOrElse +import com.tangem.common.routing.AppRoute +import com.tangem.common.routing.bundle.unbundle +import com.tangem.common.routing.utils.popTo import com.tangem.core.analytics.api.AnalyticsEventHandler -import com.tangem.core.navigation.AppScreen -import com.tangem.core.navigation.NavigationAction import com.tangem.domain.card.DeleteSavedAccessCodesUseCase import com.tangem.domain.card.ResetCardUseCase +import com.tangem.domain.card.ResetCardUserCodeParams import com.tangem.domain.common.util.cardTypesResolver -import com.tangem.domain.models.scan.CardDTO -import com.tangem.domain.models.scan.ScanResponse -import com.tangem.domain.wallets.builder.UserWalletIdBuilder import com.tangem.domain.wallets.legacy.UserWalletsListManager import com.tangem.domain.wallets.legacy.asLockable import com.tangem.domain.wallets.models.UserWalletId import com.tangem.domain.wallets.usecase.DeleteWalletUseCase import com.tangem.domain.wallets.usecase.GetSelectedWalletSyncUseCase +import com.tangem.domain.wallets.usecase.GetUserWalletUseCase import com.tangem.tap.common.analytics.events.Settings +import com.tangem.tap.common.extensions.dispatchNavigationAction import com.tangem.tap.common.extensions.onUserWalletSelected -import com.tangem.tap.features.details.redux.CardSettingsState -import com.tangem.tap.features.details.redux.DetailsAction.ResetToFactory -import com.tangem.tap.features.details.ui.cardsettings.TextReference -import com.tangem.tap.features.details.ui.resetcard.featuretoggles.ResetCardFeatureToggles -import com.tangem.tap.features.details.ui.utils.toResetCardDescriptionText +import com.tangem.tap.features.details.redux.ResetCardDialog +import com.tangem.tap.features.details.ui.cardsettings.domain.CardSettingsInteractor +import com.tangem.tap.features.details.ui.common.utils.getResetToFactoryDescription import com.tangem.tap.store import com.tangem.utils.extensions.DELAY_SDK_DIALOG_CLOSE import dagger.hilt.android.lifecycle.HiltViewModel import kotlinx.coroutines.delay +import kotlinx.coroutines.flow.MutableStateFlow +import kotlinx.coroutines.flow.update import kotlinx.coroutines.launch +import timber.log.Timber import javax.inject.Inject -import com.tangem.tap.features.details.redux.CardSettingsState.Dialog as CardSettingsDialog @Suppress("LongParameterList") @HiltViewModel internal class ResetCardViewModel @Inject constructor( - private val resetCardFeatureToggles: ResetCardFeatureToggles, + getUserWalletUseCase: GetUserWalletUseCase, private val getSelectedWalletSyncUseCase: GetSelectedWalletSyncUseCase, private val resetCardUseCase: ResetCardUseCase, private val deleteSavedAccessCodesUseCase: DeleteSavedAccessCodesUseCase, private val deleteWalletUseCase: DeleteWalletUseCase, private val userWalletsListManager: UserWalletsListManager, private val analyticsEventHandler: AnalyticsEventHandler, + private val cardSettingsInteractor: CardSettingsInteractor, + savedStateHandle: SavedStateHandle, ) : ViewModel() { - private val firstCardScanResponse = store.state.detailsState.cardSettingsState?.scanResponse - ?: error("ScanResponse can't be null") + // region Card-set specific data. All cards from single set have the same userWalletId and cardTypesResolver + private val currentUserWalletId = savedStateHandle.get(AppRoute.ResetToFactory.USER_WALLET_ID) + ?.unbundle(UserWalletId.serializer()) + ?: error("UserWalletId must be provided for ResetCardViewModel") - private val currentUserWalletId = createUserWalletId(firstCardScanResponse) + // Use only for card-specific data + private val userWallet = getUserWalletUseCase(userWalletId = currentUserWalletId) + .getOrElse { error("Failed to get user wallet: $it") } + + private val currentCardTypesResolver = userWallet.cardTypesResolver + private val currentUserCodeParams = ResetCardUserCodeParams( + isAccessCodeSet = userWallet.scanResponse.card.isAccessCodeSet, + isPasscodeSet = userWallet.scanResponse.card.isPasscodeSet, + ) + // endregion + + // region Data of card that was scanned on CardSettings + private val primaryCardId: String = savedStateHandle.get(AppRoute.ResetToFactory.CARD_ID) + ?: error("CardId must be provided for ResetCardViewModel") + + private val isActiveBackupPrimaryCard = + savedStateHandle.get(AppRoute.ResetToFactory.IS_ACTIVE_BACKUP_STATUS) + ?: error("IsActiveBackupCard must be provided for ResetCardViewModel") + + private val primaryBackupCardsCount = savedStateHandle.get(AppRoute.ResetToFactory.BACKUP_CARDS_COUNT) + ?: error("CardCount must be provided for ResetCardViewModel") + // endregion // TODO: move logic to separate domain entity private var resetBackupCardCount = 0 - fun updateState(state: CardSettingsState?): ResetCardScreenState.ResetCardScreenContent { - val descriptionText = state?.cardInfo - ?.toResetCardDescriptionText() - ?: TextReference.Str(value = "") + val screenState: MutableStateFlow = MutableStateFlow( + value = getInitialState(), + ) + private fun getInitialState(): ResetCardScreenState { + val shouldShowResetPasswordButton = shouldShowResetPasswordButton() val warningsToShow = buildList { add(ResetCardScreenState.WarningsToReset.LOST_WALLET_ACCESS) - if (state?.isShowPasswordResetRadioButton == true) { + if (shouldShowResetPasswordButton) { add(ResetCardScreenState.WarningsToReset.LOST_PASSWORD_RESTORE) } } - return ResetCardScreenState.ResetCardScreenContent( - accepted = state?.resetButtonEnabled ?: false, - descriptionText = descriptionText, + return ResetCardScreenState( + resetButtonEnabled = false, + descriptionText = getResetToFactoryDescription( + isActiveBackupStatus = isActiveBackupPrimaryCard, + typesResolver = currentCardTypesResolver, + ), warningsToShow = warningsToShow, - acceptCondition1Checked = state?.condition1Checked ?: false, - acceptCondition2Checked = state?.condition2Checked ?: false, - onAcceptCondition1ToggleClick = { store.dispatch(ResetToFactory.AcceptCondition1(it)) }, - onAcceptCondition2ToggleClick = { store.dispatch(ResetToFactory.AcceptCondition2(it)) }, - onResetButtonClick = { showDialog(CardSettingsDialog.StartResetDialog) }, - dialog = state?.dialog?.let(::createDialog), + showResetPasswordButton = shouldShowResetPasswordButton, + acceptCondition1Checked = false, + acceptCondition2Checked = false, + onAcceptCondition1ToggleClick = ::toggleFirstCondition, + onAcceptCondition2ToggleClick = ::toggleSecondCondition, + onResetButtonClick = { showDialog(ResetCardDialog.StartResetDialog) }, + dialog = null, ) } - private fun createDialog(dialog: CardSettingsDialog): ResetCardScreenState.ResetCardScreenContent.Dialog { + private fun shouldShowResetPasswordButton(): Boolean { + val isTangemWallet = currentCardTypesResolver.isTangemWallet() || currentCardTypesResolver.isWallet2() + + return isTangemWallet && isActiveBackupPrimaryCard + } + + private fun toggleFirstCondition(isAccepted: Boolean) { + screenState.update { prevState -> + val resetButtonEnabled = if (prevState.showResetPasswordButton) { + isAccepted && prevState.acceptCondition2Checked + } else { + isAccepted + } + + prevState.copy( + acceptCondition1Checked = isAccepted, + resetButtonEnabled = resetButtonEnabled, + ) + } + } + + private fun toggleSecondCondition(isAccepted: Boolean) { + screenState.update { prevState -> + val resetButtonEnabled = prevState.acceptCondition1Checked && isAccepted + + prevState.copy( + acceptCondition2Checked = isAccepted, + resetButtonEnabled = resetButtonEnabled, + ) + } + } + + private fun createDialog(dialog: ResetCardDialog): ResetCardScreenState.Dialog { return when (dialog) { - CardSettingsDialog.StartResetDialog -> { - ResetCardScreenState.ResetCardScreenContent.Dialog.StartReset( + ResetCardDialog.StartResetDialog -> { + ResetCardScreenState.Dialog.StartReset( onConfirmClick = ::onStartResetClick, onDismiss = ::dismissDialog, ) } - CardSettingsDialog.ContinueResetDialog -> { - ResetCardScreenState.ResetCardScreenContent.Dialog.ContinueReset( + ResetCardDialog.ContinueResetDialog -> { + ResetCardScreenState.Dialog.ContinueReset( onConfirmClick = ::onContinueResetClick, onDismiss = ::onContinueResetDialogDismiss, ) } - CardSettingsDialog.InterruptedResetDialog -> { - ResetCardScreenState.ResetCardScreenContent.Dialog.InterruptedReset( + ResetCardDialog.InterruptedResetDialog -> { + ResetCardScreenState.Dialog.InterruptedReset( onConfirmClick = ::onContinueResetClick, onDismiss = ::onInterruptedResetDialogDismiss, ) } - CardSettingsDialog.CompletedResetDialog -> { - ResetCardScreenState.ResetCardScreenContent.Dialog.CompletedReset( + ResetCardDialog.CompletedResetDialog -> { + ResetCardScreenState.Dialog.CompletedReset( onConfirmClick = ::dismissAndFinishFullReset, ) } @@ -108,21 +174,23 @@ internal class ResetCardViewModel @Inject constructor( private fun onStartResetClick() { dismissDialog() - if (resetCardFeatureToggles.isFullResetEnabled) { - makeFullReset() - } else { - store.dispatch(ResetToFactory.Proceed) - } + makeFullReset() } private fun makeFullReset() { viewModelScope.launch { - resetCardUseCase(card = firstCardScanResponse.card).onRight { - deleteSavedAccessCodesUseCase(firstCardScanResponse.card.cardId) - deleteWalletUseCase(currentUserWalletId) + resetCardUseCase(cardId = primaryCardId, params = currentUserCodeParams).onRight { + deleteSavedAccessCodesUseCase(cardId = primaryCardId) + val hasUserWallets = deleteWalletUseCase(userWalletId = currentUserWalletId).getOrElse { + Timber.e("Unable to delete user wallet: $it") + return@launch + } + + if (hasUserWallets) { + val newSelectedWallet = getSelectedWalletSyncUseCase().getOrElse { + error("Failed to get selected wallet: $it") + } - val newSelectedWallet = getSelectedWalletSyncUseCase().getOrNull() - if (newSelectedWallet != null) { store.onUserWalletSelected(newSelectedWallet) } @@ -139,24 +207,26 @@ internal class ResetCardViewModel @Inject constructor( viewModelScope.launch { resetCardUseCase( cardNumber = resetBackupCardCount + 1, - card = firstCardScanResponse.card, + params = currentUserCodeParams, userWalletId = currentUserWalletId, ) - .onRight { - resetBackupCardCount++ + .onRight { isResetCompleted -> + if (isResetCompleted) { + resetBackupCardCount++ + } delay(DELAY_SDK_DIALOG_CLOSE) checkRemainingBackupCards() } - .onLeft { showDialog(CardSettingsDialog.InterruptedResetDialog) } + .onLeft { showDialog(ResetCardDialog.InterruptedResetDialog) } } } private fun onContinueResetDialogDismiss() { dismissDialog() - showDialog(CardSettingsDialog.InterruptedResetDialog) + showDialog(ResetCardDialog.InterruptedResetDialog) } private fun onInterruptedResetDialogDismiss() { @@ -166,15 +236,15 @@ internal class ResetCardViewModel @Inject constructor( } private fun checkRemainingBackupCards() { - val backupCardsCount = firstCardScanResponse.getBackupCardsCount() + val backupCardsCount = getBackupCardsCount() when { - backupCardsCount > resetBackupCardCount -> showDialog(CardSettingsDialog.ContinueResetDialog) + backupCardsCount > resetBackupCardCount -> showDialog(ResetCardDialog.ContinueResetDialog) backupCardsCount == resetBackupCardCount -> { analyticsEventHandler.send( event = Settings.CardSettings.FactoryResetFinished(cardsCount = resetBackupCardCount + 1), ) - showDialog(CardSettingsDialog.CompletedResetDialog) + showDialog(ResetCardDialog.CompletedResetDialog) } else -> finishFullReset() } @@ -187,42 +257,33 @@ internal class ResetCardViewModel @Inject constructor( } private fun finishFullReset() { + cardSettingsInteractor.clear() + val newSelectedWallet = userWalletsListManager.selectedUserWalletSync if (newSelectedWallet != null) { - store.dispatch(NavigationAction.PopBackTo(AppScreen.Wallet)) + store.dispatchNavigationAction { popTo() } } else { val isLocked = runCatching { userWalletsListManager.asLockable()?.isLockedSync }.isSuccess if (isLocked && userWalletsListManager.hasUserWallets) { - store.dispatch(NavigationAction.PopBackTo(AppScreen.Welcome)) + store.dispatchNavigationAction { popTo() } } else { - store.dispatch(NavigationAction.PopBackTo(AppScreen.Home)) + store.dispatchNavigationAction { replaceAll(AppRoute.Home) } } } } - private fun showDialog(dialog: CardSettingsDialog) { - store.dispatch(ResetToFactory.ShowDialog(dialog)) + private fun showDialog(dialog: ResetCardDialog) { + screenState.update { it.copy(dialog = createDialog(dialog)) } } private fun dismissDialog() { - store.dispatch(ResetToFactory.DismissDialog) + screenState.update { it.copy(dialog = null) } } - private fun ScanResponse.getBackupCardsCount(): Int { - if (!cardTypesResolver.isMultiwalletAllowed()) return 0 + private fun getBackupCardsCount(): Int { + if (!currentCardTypesResolver.isMultiwalletAllowed()) return 0 - return when (val status = card.backupStatus) { - is CardDTO.BackupStatus.Active -> status.cardCount - is CardDTO.BackupStatus.CardLinked, - is CardDTO.BackupStatus.NoBackup, - null, - -> 0 - } - } - - private fun createUserWalletId(scanResponse: ScanResponse): UserWalletId { - return UserWalletIdBuilder.scanResponse(scanResponse).build() - ?: error("UserWalletId can't be null") + return primaryBackupCardsCount } } \ No newline at end of file diff --git a/app/src/main/java/com/tangem/tap/features/details/ui/resetcard/di/ResetCardModule.kt b/app/src/main/java/com/tangem/tap/features/details/ui/resetcard/di/ResetCardModule.kt deleted file mode 100644 index 2de1e70012..0000000000 --- a/app/src/main/java/com/tangem/tap/features/details/ui/resetcard/di/ResetCardModule.kt +++ /dev/null @@ -1,21 +0,0 @@ -package com.tangem.tap.features.details.ui.resetcard.di - -import com.tangem.core.featuretoggle.manager.FeatureTogglesManager -import com.tangem.tap.features.details.ui.resetcard.featuretoggles.DefaultResetCardFeatureToggles -import com.tangem.tap.features.details.ui.resetcard.featuretoggles.ResetCardFeatureToggles -import dagger.Module -import dagger.Provides -import dagger.hilt.InstallIn -import dagger.hilt.components.SingletonComponent -import javax.inject.Singleton - -@Module -@InstallIn(SingletonComponent::class) -internal object ResetCardModule { - - @Provides - @Singleton - fun provideResetCardFeatureToggles(featureTogglesManager: FeatureTogglesManager): ResetCardFeatureToggles { - return DefaultResetCardFeatureToggles(featureTogglesManager) - } -} \ No newline at end of file diff --git a/app/src/main/java/com/tangem/tap/features/details/ui/resetcard/featuretoggles/DefaultResetCardFeatureToggles.kt b/app/src/main/java/com/tangem/tap/features/details/ui/resetcard/featuretoggles/DefaultResetCardFeatureToggles.kt deleted file mode 100644 index a5b76a410d..0000000000 --- a/app/src/main/java/com/tangem/tap/features/details/ui/resetcard/featuretoggles/DefaultResetCardFeatureToggles.kt +++ /dev/null @@ -1,11 +0,0 @@ -package com.tangem.tap.features.details.ui.resetcard.featuretoggles - -import com.tangem.core.featuretoggle.manager.FeatureTogglesManager - -internal class DefaultResetCardFeatureToggles( - private val featureTogglesManager: FeatureTogglesManager, -) : ResetCardFeatureToggles { - - override val isFullResetEnabled: Boolean - get() = featureTogglesManager.isFeatureEnabled(name = "FULL_RESET_ENABLED") -} \ No newline at end of file diff --git a/app/src/main/java/com/tangem/tap/features/details/ui/resetcard/featuretoggles/ResetCardFeatureToggles.kt b/app/src/main/java/com/tangem/tap/features/details/ui/resetcard/featuretoggles/ResetCardFeatureToggles.kt deleted file mode 100644 index d290d4d1d9..0000000000 --- a/app/src/main/java/com/tangem/tap/features/details/ui/resetcard/featuretoggles/ResetCardFeatureToggles.kt +++ /dev/null @@ -1,6 +0,0 @@ -package com.tangem.tap.features.details.ui.resetcard.featuretoggles - -interface ResetCardFeatureToggles { - - val isFullResetEnabled: Boolean -} \ No newline at end of file diff --git a/app/src/main/java/com/tangem/tap/features/details/ui/securitymode/SecurityModeFragment.kt b/app/src/main/java/com/tangem/tap/features/details/ui/securitymode/SecurityModeFragment.kt index c44b9ca3fa..1c5fe7f90b 100644 --- a/app/src/main/java/com/tangem/tap/features/details/ui/securitymode/SecurityModeFragment.kt +++ b/app/src/main/java/com/tangem/tap/features/details/ui/securitymode/SecurityModeFragment.kt @@ -1,54 +1,34 @@ package com.tangem.tap.features.details.ui.securitymode import androidx.compose.runtime.Composable -import androidx.compose.runtime.MutableState -import androidx.compose.runtime.mutableStateOf +import androidx.compose.runtime.getValue import androidx.compose.ui.Modifier -import com.tangem.core.navigation.NavigationAction +import androidx.fragment.app.viewModels +import androidx.lifecycle.compose.collectAsStateWithLifecycle +import com.tangem.common.routing.AppRouter import com.tangem.core.ui.UiDependencies import com.tangem.core.ui.screen.ComposeFragment -import com.tangem.tap.features.details.redux.DetailsState +import com.tangem.tap.common.extensions.dispatchNavigationAction import com.tangem.tap.store import dagger.hilt.android.AndroidEntryPoint -import org.rekotlin.StoreSubscriber import javax.inject.Inject @AndroidEntryPoint -internal class SecurityModeFragment : ComposeFragment(), StoreSubscriber { +internal class SecurityModeFragment : ComposeFragment() { @Inject override lateinit var uiDependencies: UiDependencies - private val viewModel = SecurityModeViewModel(store) - - private var screenState: MutableState = - mutableStateOf(viewModel.updateState(store.state.detailsState.cardSettingsState?.manageSecurityState)) + private val viewModel: SecurityModeViewModel by viewModels() @Composable override fun ScreenContent(modifier: Modifier) { + val state by viewModel.screenState.collectAsStateWithLifecycle() + SecurityModeScreen( modifier = modifier, - state = screenState.value, - onBackClick = { store.dispatch(NavigationAction.PopBackTo()) }, + state = state, + onBackClick = { store.dispatchNavigationAction(AppRouter::pop) }, ) } - - override fun onStart() { - super.onStart() - store.subscribe(this) { state -> - state.skipRepeats { oldState, newState -> - oldState.detailsState == newState.detailsState - }.select { it.detailsState } - } - } - - override fun onStop() { - super.onStop() - store.unsubscribe(this) - } - - override fun newState(state: DetailsState) { - if (activity == null || view == null) return - screenState.value = viewModel.updateState(state.cardSettingsState?.manageSecurityState) - } } \ No newline at end of file diff --git a/app/src/main/java/com/tangem/tap/features/details/ui/securitymode/SecurityModeViewModel.kt b/app/src/main/java/com/tangem/tap/features/details/ui/securitymode/SecurityModeViewModel.kt index 7aa863a7df..5f0d54717e 100644 --- a/app/src/main/java/com/tangem/tap/features/details/ui/securitymode/SecurityModeViewModel.kt +++ b/app/src/main/java/com/tangem/tap/features/details/ui/securitymode/SecurityModeViewModel.kt @@ -1,29 +1,109 @@ package com.tangem.tap.features.details.ui.securitymode -import com.tangem.tap.common.redux.AppState -import com.tangem.tap.features.details.redux.DetailsAction -import com.tangem.tap.features.details.redux.ManageSecurityState +import android.os.Bundle +import androidx.lifecycle.SavedStateHandle +import androidx.lifecycle.ViewModel +import androidx.lifecycle.viewModelScope +import arrow.core.getOrElse +import com.tangem.common.CompletionResult +import com.tangem.common.core.TangemSdkError +import com.tangem.common.routing.AppRoute +import com.tangem.common.routing.AppRouter +import com.tangem.common.routing.bundle.unbundle +import com.tangem.core.analytics.Analytics +import com.tangem.domain.common.util.cardTypesResolver +import com.tangem.domain.wallets.models.UserWallet +import com.tangem.domain.wallets.models.UserWalletId +import com.tangem.domain.wallets.usecase.GetUserWalletUseCase +import com.tangem.tap.common.analytics.events.AnalyticsParam +import com.tangem.tap.common.analytics.events.Settings +import com.tangem.tap.common.extensions.dispatchNavigationAction +import com.tangem.tap.domain.sdk.TangemSdkManager import com.tangem.tap.features.details.redux.SecurityOption -import org.rekotlin.Store +import com.tangem.tap.features.details.ui.common.utils.getAllowedSecurityOptions +import com.tangem.tap.features.details.ui.common.utils.getCurrentSecurityOption +import com.tangem.tap.store +import dagger.hilt.android.lifecycle.HiltViewModel +import kotlinx.coroutines.flow.MutableStateFlow +import kotlinx.coroutines.flow.update +import kotlinx.coroutines.launch +import javax.inject.Inject -internal class SecurityModeViewModel(val store: Store) { +@HiltViewModel +internal class SecurityModeViewModel @Inject constructor( + private val getUserWalletUseCase: GetUserWalletUseCase, + private val tangemSdkManager: TangemSdkManager, + savedStateHandle: SavedStateHandle, +) : ViewModel() { + + private val userWalletId = savedStateHandle.get(AppRoute.DetailsSecurity.USER_WALLET_ID_KEY) + ?.unbundle(UserWalletId.serializer()) + ?: error("UserWalletId is required for SecurityModeViewModel") + + val screenState = MutableStateFlow( + value = getInitialState(), + ) + + private fun getInitialState(): SecurityModeScreenState { + val userWallet = getUserWallet() + val scanResponse = userWallet.scanResponse + val card = scanResponse.card + val cardTypesResolver = scanResponse.cardTypesResolver + + val currentSecurityOption = getCurrentSecurityOption(card) + val allowedSecurityOptions = getAllowedSecurityOptions(card, cardTypesResolver, currentSecurityOption) - fun updateState(state: ManageSecurityState?): SecurityModeScreenState { - if (state == null) { - return SecurityModeScreenState( - availableOptions = emptyList(), - selectedSecurityMode = SecurityOption.LongTap, - isSaveChangesEnabled = false, - onNewModeSelected = {}, - onSaveChangesClicked = {}, - ) - } return SecurityModeScreenState( - availableOptions = state.allowedOptions.toList(), - selectedSecurityMode = state.selectedOption, - isSaveChangesEnabled = state.selectedOption != state.currentOption, - onNewModeSelected = { store.dispatch(DetailsAction.ManageSecurity.SelectOption(it)) }, - onSaveChangesClicked = { store.dispatch(DetailsAction.ManageSecurity.SaveChanges) }, + availableOptions = allowedSecurityOptions.toList(), + selectedSecurityMode = currentSecurityOption, + isSaveChangesEnabled = false, + onNewModeSelected = ::selectOption, + onSaveChangesClicked = ::saveChanges, ) } + + private fun selectOption(securityOption: SecurityOption) { + screenState.update { state -> + state.copy( + selectedSecurityMode = securityOption, + isSaveChangesEnabled = securityOption != getCurrentSecurityOption(getUserWallet().scanResponse.card), + ) + } + } + + private fun saveChanges() { + val userWallet = getUserWallet() + val cardId = userWallet.cardId + val selectedOption = screenState.value.selectedSecurityMode + + viewModelScope.launch { + val result = when (selectedOption) { + SecurityOption.LongTap -> tangemSdkManager.setLongTap(cardId) + SecurityOption.PassCode -> tangemSdkManager.setPasscode(cardId) + SecurityOption.AccessCode -> tangemSdkManager.setAccessCode(cardId) + } + + val paramValue = AnalyticsParam.SecurityMode.from(selectedOption) + when (result) { + is CompletionResult.Success -> { + Analytics.send(Settings.CardSettings.SecurityModeChanged(paramValue)) + + store.dispatchNavigationAction(AppRouter::pop) + } + is CompletionResult.Failure -> { + val error = result.error + if (error is TangemSdkError && error !is TangemSdkError.UserCancelled) { + Analytics.send(Settings.CardSettings.SecurityModeChanged(paramValue, error)) + } + } + else -> Unit + } + } + } + + private fun getUserWallet(): UserWallet { + return getUserWalletUseCase(userWalletId).getOrElse { + error("Unable to get user wallet $userWalletId: $it") + } + } } \ No newline at end of file diff --git a/app/src/main/java/com/tangem/tap/features/details/ui/utils/Mappers.kt b/app/src/main/java/com/tangem/tap/features/details/ui/utils/Mappers.kt deleted file mode 100644 index 459e5ba49a..0000000000 --- a/app/src/main/java/com/tangem/tap/features/details/ui/utils/Mappers.kt +++ /dev/null @@ -1,13 +0,0 @@ -package com.tangem.tap.features.details.ui.utils - -import com.tangem.tap.features.details.redux.CardInfo -import com.tangem.tap.features.details.ui.cardsettings.TextReference -import com.tangem.wallet.R - -internal fun CardInfo.toResetCardDescriptionText(): TextReference { - return if (!this.hasBackup || this.isTwin) { - TextReference.Res(R.string.reset_card_without_backup_to_factory_message) - } else { - TextReference.Res(R.string.reset_card_with_backup_to_factory_message) - } -} \ No newline at end of file diff --git a/app/src/main/java/com/tangem/tap/features/details/ui/walletconnect/WalletConnectFragment.kt b/app/src/main/java/com/tangem/tap/features/details/ui/walletconnect/WalletConnectFragment.kt index 19dd0771bc..d720c10ec7 100644 --- a/app/src/main/java/com/tangem/tap/features/details/ui/walletconnect/WalletConnectFragment.kt +++ b/app/src/main/java/com/tangem/tap/features/details/ui/walletconnect/WalletConnectFragment.kt @@ -6,11 +6,12 @@ import androidx.compose.runtime.MutableState import androidx.compose.runtime.mutableStateOf import androidx.compose.ui.Modifier import androidx.fragment.app.viewModels +import com.tangem.common.routing.AppRouter import com.tangem.core.analytics.Analytics -import com.tangem.core.navigation.NavigationAction import com.tangem.core.ui.UiDependencies import com.tangem.core.ui.screen.ComposeFragment import com.tangem.tap.common.analytics.events.WalletConnect +import com.tangem.tap.common.extensions.dispatchNavigationAction import com.tangem.tap.features.details.redux.walletconnect.WalletConnectState import com.tangem.tap.store import dagger.hilt.android.AndroidEntryPoint @@ -41,7 +42,7 @@ internal class WalletConnectFragment : ComposeFragment(), StoreSubscriber - store.dispatch( - NavigationAction.NavigateTo( - screen = AppScreen.QrScanning, - bundle = bundleOf( - QrScanningRouter.SOURCE_KEY to SourceType.WALLET_CONNECT, - ), - ), - ) + store.dispatchNavigationAction { + push(AppRoute.QrScanning(source = SourceType.WALLET_CONNECT)) + } } setOnDismissListener { store.dispatch(GlobalAction.HideDialog) diff --git a/app/src/main/java/com/tangem/tap/features/disclaimer/Disclaimer.kt b/app/src/main/java/com/tangem/tap/features/disclaimer/Disclaimer.kt index f92bc4be2f..9cda07b754 100644 --- a/app/src/main/java/com/tangem/tap/features/disclaimer/Disclaimer.kt +++ b/app/src/main/java/com/tangem/tap/features/disclaimer/Disclaimer.kt @@ -6,14 +6,13 @@ import android.net.Uri [REDACTED_AUTHOR] */ interface Disclaimer { - fun type(): DisclaimerType fun getUri(): Uri suspend fun accept() suspend fun isAccepted(): Boolean } abstract class BaseDisclaimer( - protected val dataProvider: DisclaimerDataProvider, + private val dataProvider: DisclaimerDataProvider, ) : Disclaimer { val baseUrl = "https://tangem.com" @@ -26,46 +25,11 @@ abstract class BaseDisclaimer( } class DummyDisclaimer : Disclaimer { - override fun type(): DisclaimerType = DisclaimerType.Tangem override fun getUri(): Uri = Uri.parse("https://tangem.com/tangem_tos.html") override suspend fun accept() {} override suspend fun isAccepted(): Boolean = false } class TangemDisclaimer(dataProvider: DisclaimerDataProvider) : BaseDisclaimer(dataProvider) { - override fun type(): DisclaimerType = DisclaimerType.Tangem override fun getUri(): Uri = Uri.parse("$baseUrl/tangem_tos.html") -} - -class Start2CoinDisclaimer(dataProvider: DisclaimerDataProvider) : BaseDisclaimer(dataProvider) { - override fun type(): DisclaimerType = DisclaimerType.Start2Coin - override fun getUri(): Uri = Uri.parse("$baseUrl/" + filename(dataProvider.getLanguage(), getRegion())) - - @Suppress("ComplexMethod") - private fun filename(languageCode: String, regionCode: String?): String { - return when { - languageCode == "fr" && regionCode == "ch" -> "start2coin-fr-ch-tangem.html" - languageCode == "de" && regionCode == "ch" -> "start2coin-de-ch-tangem.html" - languageCode == "en" && regionCode == "ch" -> "start2coin-en-ch-tangem.html" - languageCode == "it" && regionCode == "ch" -> "start2coin-it-ch-tangem.html" - languageCode == "fr" && regionCode == "fr" -> "start2coin-fr-fr-tangem.html" - languageCode == "de" && regionCode == "at" -> "start2coin-de-at-tangem.html" - regionCode == "fr" -> "start2coin-fr-fr-tangem.html" - regionCode == "ch" -> "start2coin-en-ch-tangem.html" - regionCode == "at" -> "start2coin-de-at-tangem.html" - else -> "start2coin-fr-fr-tangem.html" - } - } - - private fun getRegion(): String? { - val cardId = dataProvider.getCardId() - if (cardId.isEmpty()) return null - - return when (cardId[1]) { - '0' -> "fr" - '1' -> "ch" - '2' -> "at" - else -> null - } - } } \ No newline at end of file diff --git a/app/src/main/java/com/tangem/tap/features/disclaimer/DisclaimerType.kt b/app/src/main/java/com/tangem/tap/features/disclaimer/DisclaimerType.kt index 796452dcab..90f73cb4ad 100644 --- a/app/src/main/java/com/tangem/tap/features/disclaimer/DisclaimerType.kt +++ b/app/src/main/java/com/tangem/tap/features/disclaimer/DisclaimerType.kt @@ -1,58 +1,28 @@ package com.tangem.tap.features.disclaimer -import com.tangem.domain.common.TapWorkarounds.isStart2Coin import com.tangem.domain.models.scan.CardDTO import com.tangem.tap.common.extensions.inject import com.tangem.tap.proxy.redux.DaggerGraphState import com.tangem.tap.store import java.util.Locale -/** -[REDACTED_AUTHOR] - */ -enum class DisclaimerType { - Tangem, - Start2Coin, - ; - - companion object { - fun get(cardDTO: CardDTO): DisclaimerType { - return when { - cardDTO.isStart2Coin -> Start2Coin - else -> Tangem - } - } - } +fun CardDTO.createDisclaimer(): Disclaimer { + val dataProvider = provideDisclaimerDataProvider(cardId) + return TangemDisclaimer(dataProvider) } -fun DisclaimerType.createDisclaimer(cardDTO: CardDTO): Disclaimer { - val dataProvider = provideDisclaimerDataProvider(cardDTO.cardId, this) - return when (this) { - DisclaimerType.Tangem -> TangemDisclaimer(dataProvider) - DisclaimerType.Start2Coin -> Start2CoinDisclaimer(dataProvider) - } -} - -fun CardDTO.createDisclaimer(): Disclaimer = DisclaimerType.get(this).createDisclaimer(this) - -private fun provideDisclaimerDataProvider(cardId: String, disclaimerType: DisclaimerType): DisclaimerDataProvider { +private fun provideDisclaimerDataProvider(cardId: String): DisclaimerDataProvider { val cardRepository = store.inject(DaggerGraphState::cardRepository) return object : DisclaimerDataProvider { override fun getLanguage(): String = Locale.getDefault().language override fun getCardId(): String = cardId override suspend fun accept() { - when (disclaimerType) { - DisclaimerType.Tangem -> cardRepository.acceptTangemTOS() - DisclaimerType.Start2Coin -> cardRepository.acceptStart2CoinTOS(cardId) - } + cardRepository.acceptTangemTOS() } override suspend fun isAccepted(): Boolean { - return when (disclaimerType) { - DisclaimerType.Tangem -> cardRepository.isTangemTOSAccepted() - DisclaimerType.Start2Coin -> cardRepository.isStart2CoinTOSAccepted(cardId) - } + return cardRepository.isTangemTOSAccepted() } } } \ No newline at end of file diff --git a/app/src/main/java/com/tangem/tap/features/disclaimer/redux/DisclaimerAction.kt b/app/src/main/java/com/tangem/tap/features/disclaimer/redux/DisclaimerAction.kt index 52e3057f46..9611dc80b5 100644 --- a/app/src/main/java/com/tangem/tap/features/disclaimer/redux/DisclaimerAction.kt +++ b/app/src/main/java/com/tangem/tap/features/disclaimer/redux/DisclaimerAction.kt @@ -1,6 +1,5 @@ package com.tangem.tap.features.disclaimer.redux -import com.tangem.core.navigation.AppScreen import com.tangem.tap.common.entities.ProgressState import com.tangem.tap.features.disclaimer.Disclaimer import org.rekotlin.Action @@ -10,7 +9,7 @@ sealed class DisclaimerAction : Action { data class SetDisclaimer(val disclaimer: Disclaimer) : DisclaimerAction() data class Show( - val fromScreen: AppScreen, + val from: DisclaimerSource, val callback: DisclaimerCallback? = null, ) : DisclaimerAction() diff --git a/app/src/main/java/com/tangem/tap/features/disclaimer/redux/DisclaimerMiddleware.kt b/app/src/main/java/com/tangem/tap/features/disclaimer/redux/DisclaimerMiddleware.kt index 3e152187ea..60ffa51781 100644 --- a/app/src/main/java/com/tangem/tap/features/disclaimer/redux/DisclaimerMiddleware.kt +++ b/app/src/main/java/com/tangem/tap/features/disclaimer/redux/DisclaimerMiddleware.kt @@ -1,7 +1,8 @@ package com.tangem.tap.features.disclaimer.redux -import com.tangem.core.navigation.AppScreen -import com.tangem.core.navigation.NavigationAction +import com.tangem.common.routing.AppRoute +import com.tangem.common.routing.AppRouter +import com.tangem.tap.common.extensions.dispatchNavigationAction import com.tangem.tap.common.redux.AppState import com.tangem.tap.mainScope import com.tangem.tap.store @@ -25,17 +26,19 @@ private fun handleDisclaimerMiddleware(action: Action, appState: AppState) { when (action) { is DisclaimerAction.Show -> { - store.dispatch(NavigationAction.NavigateTo(AppScreen.Disclaimer)) + store.dispatchNavigationAction { + push(AppRoute.Disclaimer(isTosAccepted = action.from == DisclaimerSource.Details)) + } } is DisclaimerAction.AcceptDisclaimer -> { mainScope.launch { state.disclaimer.accept() - store.dispatch(NavigationAction.PopBackTo()) + store.dispatchNavigationAction(AppRouter::pop) state.callback?.onAccept?.invoke() } } is DisclaimerAction.OnBackPressed -> { - store.dispatch(NavigationAction.PopBackTo()) + store.dispatchNavigationAction(AppRouter::pop) state.callback?.onDismiss?.invoke() } } diff --git a/app/src/main/java/com/tangem/tap/features/disclaimer/redux/DisclaimerReducer.kt b/app/src/main/java/com/tangem/tap/features/disclaimer/redux/DisclaimerReducer.kt index 6c2205ca01..9b655697ba 100644 --- a/app/src/main/java/com/tangem/tap/features/disclaimer/redux/DisclaimerReducer.kt +++ b/app/src/main/java/com/tangem/tap/features/disclaimer/redux/DisclaimerReducer.kt @@ -17,7 +17,7 @@ private fun internalReduce(action: Action, state: AppState): DisclaimerState { disclaimer = action.disclaimer, ) is DisclaimerAction.Show -> disclaimerState.copy( - showedFromScreen = action.fromScreen, + showedFrom = action.from, callback = action.callback, ) is DisclaimerAction.AcceptDisclaimer, is DisclaimerAction.OnBackPressed -> disclaimerState.copy( diff --git a/app/src/main/java/com/tangem/tap/features/disclaimer/redux/DisclaimerSource.kt b/app/src/main/java/com/tangem/tap/features/disclaimer/redux/DisclaimerSource.kt new file mode 100644 index 0000000000..cdfcbbdb90 --- /dev/null +++ b/app/src/main/java/com/tangem/tap/features/disclaimer/redux/DisclaimerSource.kt @@ -0,0 +1,5 @@ +package com.tangem.tap.features.disclaimer.redux + +enum class DisclaimerSource { + Home, Details +} \ No newline at end of file diff --git a/app/src/main/java/com/tangem/tap/features/disclaimer/redux/DisclaimerState.kt b/app/src/main/java/com/tangem/tap/features/disclaimer/redux/DisclaimerState.kt index 8d37c385eb..c5ccfc7cfc 100644 --- a/app/src/main/java/com/tangem/tap/features/disclaimer/redux/DisclaimerState.kt +++ b/app/src/main/java/com/tangem/tap/features/disclaimer/redux/DisclaimerState.kt @@ -1,7 +1,7 @@ package com.tangem.tap.features.disclaimer.redux import com.tangem.common.extensions.VoidCallback -import com.tangem.core.navigation.AppScreen + import com.tangem.tap.common.entities.ProgressState import com.tangem.tap.features.disclaimer.Disclaimer import com.tangem.tap.features.disclaimer.DummyDisclaimer @@ -9,7 +9,7 @@ import org.rekotlin.StateType data class DisclaimerState( val disclaimer: Disclaimer = DummyDisclaimer(), - val showedFromScreen: AppScreen = AppScreen.Home, + val showedFrom: DisclaimerSource = DisclaimerSource.Home, val callback: DisclaimerCallback? = null, val progressState: ProgressState? = null, ) : StateType diff --git a/app/src/main/java/com/tangem/tap/features/disclaimer/ui/DisclaimerFragment.kt b/app/src/main/java/com/tangem/tap/features/disclaimer/ui/DisclaimerFragment.kt index d6767e13ac..9d217e6111 100644 --- a/app/src/main/java/com/tangem/tap/features/disclaimer/ui/DisclaimerFragment.kt +++ b/app/src/main/java/com/tangem/tap/features/disclaimer/ui/DisclaimerFragment.kt @@ -7,7 +7,7 @@ import android.webkit.WebView import androidx.lifecycle.lifecycleScope import androidx.transition.TransitionInflater import by.kirich1409.viewbindingdelegate.viewBinding -import com.tangem.core.navigation.AppScreen + import com.tangem.core.ui.extensions.setStatusBarColor import com.tangem.tap.common.entities.ProgressState import com.tangem.tap.common.extensions.beginDelayedTransition @@ -18,6 +18,7 @@ import com.tangem.tap.features.BaseFragment import com.tangem.tap.features.addBackPressHandler import com.tangem.tap.features.disclaimer.Disclaimer import com.tangem.tap.features.disclaimer.redux.DisclaimerAction +import com.tangem.tap.features.disclaimer.redux.DisclaimerSource import com.tangem.tap.features.disclaimer.redux.DisclaimerState import com.tangem.tap.store import com.tangem.wallet.R @@ -76,17 +77,14 @@ class DisclaimerFragment : BaseFragment(R.layout.fragment_disclaimer), StoreSubs override fun configureTransitions() { val inflater = TransitionInflater.from(requireContext()) - when (store.state.disclaimerState.showedFromScreen) { - AppScreen.Home -> { + when (store.state.disclaimerState.showedFrom) { + DisclaimerSource.Home -> { enterTransition = inflater.inflateTransition(android.R.transition.slide_bottom) exitTransition = inflater.inflateTransition(android.R.transition.slide_top) } - AppScreen.Details -> { + DisclaimerSource.Details -> { super.configureTransitions() } - else -> { - /* no-op */ - } } } 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 8e081474fb..f3fae68135 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 @@ -6,17 +6,16 @@ import androidx.compose.runtime.Composable import androidx.compose.runtime.MutableState import androidx.compose.runtime.mutableStateOf import androidx.compose.ui.Modifier -import androidx.compose.ui.graphics.Color -import androidx.core.view.WindowCompat import androidx.lifecycle.lifecycleScope +import com.tangem.common.routing.AppRoute import com.tangem.core.analytics.Analytics -import com.tangem.core.navigation.AppScreen -import com.tangem.core.navigation.NavigationAction + import com.tangem.core.ui.UiDependencies -import com.tangem.core.ui.components.SystemBarsEffect +import com.tangem.core.ui.components.SystemBarsIconsDisposable import com.tangem.core.ui.screen.ComposeFragment import com.tangem.domain.tokens.TokensAction import com.tangem.tap.common.analytics.events.IntroductionProcess +import com.tangem.tap.common.extensions.dispatchNavigationAction import com.tangem.tap.common.redux.AppState import com.tangem.tap.features.home.compose.StoriesScreen import com.tangem.tap.features.home.redux.HomeAction @@ -43,15 +42,12 @@ class HomeFragment : ComposeFragment(), StoreSubscriber { @Composable override fun ScreenContent(modifier: Modifier) { BackHandler(onBack = requireActivity()::finish) - SystemBarsEffect { - setSystemBarsColor(color = Color.Transparent, darkIcons = false) - } + SystemBarsIconsDisposable(darkIcons = false) ScreenContent() } override fun onStart() { super.onStart() - activity?.window?.let { WindowCompat.setDecorFitsSystemWindows(it, false) } store.subscribe(subscriber = this) { state -> state @@ -86,7 +82,7 @@ class HomeFragment : ComposeFragment(), StoreSubscriber { }, onSearchTokensClick = { Analytics.send(IntroductionProcess.ButtonTokensList()) - store.dispatch(NavigationAction.NavigateTo(AppScreen.ManageTokens)) + store.dispatchNavigationAction { push(AppRoute.ManageTokens) } store.dispatch(TokensAction.SetArgs.ReadAccess) }, ) diff --git a/app/src/main/java/com/tangem/tap/features/home/redux/HomeMiddleware.kt b/app/src/main/java/com/tangem/tap/features/home/redux/HomeMiddleware.kt index 42f21e542d..38c890dc29 100644 --- a/app/src/main/java/com/tangem/tap/features/home/redux/HomeMiddleware.kt +++ b/app/src/main/java/com/tangem/tap/features/home/redux/HomeMiddleware.kt @@ -6,11 +6,10 @@ import com.tangem.common.doOnFailure import com.tangem.common.doOnResult import com.tangem.common.doOnSuccess import com.tangem.common.extensions.guard +import com.tangem.common.routing.AppRoute import com.tangem.core.analytics.Analytics import com.tangem.core.analytics.models.AnalyticsParam import com.tangem.core.analytics.models.Basic -import com.tangem.core.navigation.AppScreen -import com.tangem.core.navigation.NavigationAction import com.tangem.domain.common.util.cardTypesResolver import com.tangem.domain.models.scan.ScanResponse import com.tangem.domain.wallets.builder.UserWalletBuilder @@ -126,7 +125,7 @@ private fun proceedWithScanResponse(scanResponse: ScanResponse) = scope.launch { scope.launch { store.onUserWalletSelected(userWallet = userWallet) } } .doOnResult { - navigateTo(AppScreen.Wallet) + navigateTo(AppRoute.Wallet) } } @@ -150,8 +149,8 @@ private fun sendSignedInCardAnalyticsEvent(scanResponse: ScanResponse) { } } -private suspend fun navigateTo(appScreen: AppScreen) { - store.dispatchOnMain(NavigationAction.NavigateTo(appScreen)) +private suspend fun navigateTo(route: AppRoute) { + store.dispatchNavigationAction { push(route) } delay(HIDE_PROGRESS_DELAY) store.dispatch(HomeAction.ScanInProgress(scanInProgress = false)) } \ No newline at end of file diff --git a/app/src/main/java/com/tangem/tap/features/main/MainViewModel.kt b/app/src/main/java/com/tangem/tap/features/main/MainViewModel.kt index 53a3565731..fd2b740b37 100644 --- a/app/src/main/java/com/tangem/tap/features/main/MainViewModel.kt +++ b/app/src/main/java/com/tangem/tap/features/main/MainViewModel.kt @@ -3,11 +3,10 @@ package com.tangem.tap.features.main import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope import com.tangem.blockchainsdk.BlockchainSDKFactory +import com.tangem.common.routing.AppRoute +import com.tangem.common.routing.AppRouter import com.tangem.core.analytics.Analytics import com.tangem.core.analytics.models.Basic -import com.tangem.core.navigation.AppScreen -import com.tangem.core.navigation.NavigationAction -import com.tangem.core.navigation.ReduxNavController import com.tangem.domain.appcurrency.FetchAppCurrenciesUseCase import com.tangem.domain.balancehiding.BalanceHidingSettings import com.tangem.domain.balancehiding.GetBalanceHidingSettingsUseCase @@ -16,9 +15,11 @@ import com.tangem.domain.balancehiding.UpdateBalanceHidingSettingsUseCase import com.tangem.domain.feedback.FeedbackManagerFeatureToggles import com.tangem.domain.settings.DeleteDeprecatedLogsUseCase import com.tangem.domain.settings.IncrementAppLaunchCounterUseCase +import com.tangem.domain.staking.FetchStakingTokensUseCase import com.tangem.domain.walletmanager.WalletManagersFacade import com.tangem.domain.wallets.legacy.UserWalletsListManager import com.tangem.features.send.api.featuretoggles.SendFeatureToggles +import com.tangem.features.staking.api.featuretoggles.StakingFeatureToggles import com.tangem.tap.common.extensions.setContext import com.tangem.tap.features.main.model.MainScreenState import com.tangem.tap.store @@ -34,7 +35,7 @@ import javax.inject.Inject internal class MainViewModel @Inject constructor( private val updateBalanceHidingSettingsUseCase: UpdateBalanceHidingSettingsUseCase, private val listenToFlipsUseCase: ListenToFlipsUseCase, - private val reduxNavController: ReduxNavController, + private val router: AppRouter, private val fetchAppCurrenciesUseCase: FetchAppCurrenciesUseCase, private val deleteDeprecatedLogsUseCase: DeleteDeprecatedLogsUseCase, private val incrementAppLaunchCounterUseCase: IncrementAppLaunchCounterUseCase, @@ -44,6 +45,8 @@ internal class MainViewModel @Inject constructor( private val sendFeatureToggles: SendFeatureToggles, private val feedbackManagerFeatureToggles: FeedbackManagerFeatureToggles, private val dispatchers: CoroutineDispatcherProvider, + private val stakingFeatureToggles: StakingFeatureToggles, + private val fetchStakingTokensUseCase: FetchStakingTokensUseCase, getBalanceHidingSettingsUseCase: GetBalanceHidingSettingsUseCase, ) : ViewModel(), MainIntents { @@ -70,6 +73,10 @@ internal class MainViewModel @Inject constructor( displayBalancesHidingStatusToast() displayHiddenBalancesModalNotification() + if (stakingFeatureToggles.isStakingEnabled) { + fetchStakingTokens() + } + viewModelScope.launch(dispatchers.main) { deleteDeprecatedLogsUseCase() } @@ -115,6 +122,14 @@ internal class MainViewModel @Inject constructor( } } + private fun fetchStakingTokens() { + viewModelScope.launch(dispatchers.main) { + fetchStakingTokensUseCase() + .onLeft { Timber.e(it.toString(), "Unable to fetch the staking tokens list") } + .onRight { Timber.d("Staking token list was fetched successfully") } + } + } + private fun updateSendFeatureToggle() { viewModelScope.launch(dispatchers.main) { sendFeatureToggles.fetchNewSendEnabled() @@ -136,7 +151,7 @@ internal class MainViewModel @Inject constructor( if (state.value.modalNotification?.isShow != true && !it.isUpdateFromToast) { listenToFlipsUseCase.changeUpdateEnabled(false) stateHolder.updateWithHiddenBalancesNotification() - reduxNavController.navigate(NavigationAction.NavigateTo(AppScreen.ModalNotification)) + router.push(AppRoute.ModalNotification) } } .launchIn(viewModelScope) diff --git a/app/src/main/java/com/tangem/tap/features/onboarding/OnboardingDialog.kt b/app/src/main/java/com/tangem/tap/features/onboarding/OnboardingDialog.kt index 0134ddaf15..97f17bd9b5 100644 --- a/app/src/main/java/com/tangem/tap/features/onboarding/OnboardingDialog.kt +++ b/app/src/main/java/com/tangem/tap/features/onboarding/OnboardingDialog.kt @@ -1,7 +1,7 @@ package com.tangem.tap.features.onboarding import com.tangem.common.extensions.VoidCallback -import com.tangem.core.navigation.StateDialog +import com.tangem.domain.redux.StateDialog /** [REDACTED_AUTHOR] diff --git a/app/src/main/java/com/tangem/tap/features/onboarding/OnboardingHelper.kt b/app/src/main/java/com/tangem/tap/features/onboarding/OnboardingHelper.kt index 3aca958d05..404a469233 100644 --- a/app/src/main/java/com/tangem/tap/features/onboarding/OnboardingHelper.kt +++ b/app/src/main/java/com/tangem/tap/features/onboarding/OnboardingHelper.kt @@ -3,10 +3,10 @@ package com.tangem.tap.features.onboarding import com.tangem.common.doOnFailure import com.tangem.common.doOnSuccess import com.tangem.common.extensions.guard +import com.tangem.common.routing.AppRoute import com.tangem.core.analytics.Analytics import com.tangem.core.analytics.models.Basic -import com.tangem.core.navigation.AppScreen -import com.tangem.core.navigation.NavigationAction + import com.tangem.domain.common.util.cardTypesResolver import com.tangem.domain.common.util.twinsIsTwinned import com.tangem.domain.models.scan.CardDTO @@ -32,42 +32,43 @@ import timber.log.Timber */ object OnboardingHelper { suspend fun isOnboardingCase(response: ScanResponse): Boolean { - val onboardingManager = store.state.globalState.onboardingState.onboardingManager + val onboardingManager = + store.state.globalState.onboardingState.onboardingManager ?: OnboardingManager(response) val cardId = response.card.cardId return when { response.cardTypesResolver.isTangemTwins() -> { if (!response.twinsIsTwinned()) { true } else { - onboardingManager?.isActivationInProgress(cardId) ?: false + onboardingManager.isActivationInProgress(cardId) ?: false } } response.cardTypesResolver.isWallet2() || response.cardTypesResolver.isShibaWallet() -> { val emptyWallets = response.card.wallets.isEmpty() - val activationInProgress = onboardingManager?.isActivationInProgress(cardId) + val activationInProgress = onboardingManager.isActivationInProgress(cardId) val isNoBackup = response.card.backupStatus == CardDTO.BackupStatus.NoBackup && !DemoHelper.isDemoCard(response) - emptyWallets || activationInProgress == true || isNoBackup + emptyWallets || activationInProgress || isNoBackup } - response.card.wallets.isNotEmpty() -> onboardingManager?.isActivationInProgress(cardId) ?: false + response.card.wallets.isNotEmpty() -> onboardingManager.isActivationInProgress(cardId) ?: false else -> true } } - fun whereToNavigate(scanResponse: ScanResponse): AppScreen { + fun whereToNavigate(scanResponse: ScanResponse): AppRoute { return when (val type = scanResponse.productType) { - ProductType.Note -> AppScreen.OnboardingNote + ProductType.Note -> AppRoute.OnboardingNote ProductType.Wallet, ProductType.Wallet2, ProductType.Ring, -> if (scanResponse.card.settings.isBackupAllowed) { - AppScreen.OnboardingWallet + AppRoute.OnboardingWallet() } else { - AppScreen.OnboardingOther + AppRoute.OnboardingOther } - ProductType.Twins -> AppScreen.OnboardingTwins + ProductType.Twins -> AppRoute.OnboardingTwins ProductType.Start2Coin, ProductType.Visa, -> throw UnsupportedOperationException("Onboarding for ${type.name} cards is not supported") @@ -111,14 +112,14 @@ object OnboardingHelper { backupCardsIds = backupCardsIds?.toSet(), ), ) - store.dispatchOnMain(NavigationAction.NavigateTo(AppScreen.Wallet)) + store.dispatchNavigationAction { push(AppRoute.Wallet) } delay(timeMillis = 1_800) - store.dispatchOnMain(NavigationAction.NavigateTo(AppScreen.SaveWallet)) + store.dispatchNavigationAction { push(AppRoute.SaveWallet) } } // If device has no biometry and save wallet screen has been shown, then go through old scenario else -> { proceedWithScanResponse(scanResponse, backupCardsIds, hasBackupError) - store.dispatchOnMain(NavigationAction.NavigateTo(AppScreen.Wallet)) + store.dispatchNavigationAction { push(AppRoute.Wallet) } } } } diff --git a/app/src/main/java/com/tangem/tap/features/onboarding/OnboardingMenuProvider.kt b/app/src/main/java/com/tangem/tap/features/onboarding/OnboardingMenuProvider.kt index 5e0028b00d..89ffc2161c 100644 --- a/app/src/main/java/com/tangem/tap/features/onboarding/OnboardingMenuProvider.kt +++ b/app/src/main/java/com/tangem/tap/features/onboarding/OnboardingMenuProvider.kt @@ -7,15 +7,20 @@ import androidx.core.view.MenuProvider import com.tangem.core.analytics.Analytics import com.tangem.core.analytics.models.AnalyticsParam import com.tangem.core.analytics.models.Basic +import com.tangem.domain.models.scan.ScanResponse import com.tangem.tap.common.feedback.SupportInfo import com.tangem.tap.common.redux.global.GlobalAction import com.tangem.tap.store +import com.tangem.utils.Provider import com.tangem.wallet.R /** [REDACTED_AUTHOR] */ -class OnboardingMenuProvider : MenuProvider { +class OnboardingMenuProvider( + private val scanResponseProvider: Provider, +) : MenuProvider { + override fun onCreateMenu(menu: Menu, menuInflater: MenuInflater) { menuInflater.inflate(R.menu.menu_onboarding, menu) } @@ -24,7 +29,12 @@ class OnboardingMenuProvider : MenuProvider { R.id.menu_item_chat_support -> { Analytics.send(Basic.ButtonSupport(AnalyticsParam.ScreensSources.Intro)) // changed on email support [REDACTED_TASK_KEY] - store.dispatch(GlobalAction.SendEmail(SupportInfo())) + store.dispatch( + GlobalAction.SendEmail( + feedbackData = SupportInfo(), + scanResponse = scanResponseProvider(), + ), + ) true } else -> false diff --git a/app/src/main/java/com/tangem/tap/features/onboarding/products/BaseOnboardingFragment.kt b/app/src/main/java/com/tangem/tap/features/onboarding/products/BaseOnboardingFragment.kt index 032cce60d3..0922d3f023 100644 --- a/app/src/main/java/com/tangem/tap/features/onboarding/products/BaseOnboardingFragment.kt +++ b/app/src/main/java/com/tangem/tap/features/onboarding/products/BaseOnboardingFragment.kt @@ -9,6 +9,8 @@ import com.tangem.tap.common.extensions.show import com.tangem.tap.common.transitions.HomeToOnboardingTransition import com.tangem.tap.features.BaseStoreFragment import com.tangem.tap.features.onboarding.OnboardingMenuProvider +import com.tangem.tap.store +import com.tangem.utils.Provider import com.tangem.wallet.R import com.tangem.wallet.databinding.FragmentOnboardingMainBinding import com.tangem.wallet.databinding.ViewOnboardingProgressBinding @@ -32,7 +34,13 @@ abstract class BaseOnboardingFragment : BaseStoreFragment(R.layout.fragment_o (activity as? AppCompatActivity)?.setSupportActionBar(binding.toolbar) } - override fun loadToolbarMenu(): MenuProvider? = OnboardingMenuProvider() + override fun loadToolbarMenu(): MenuProvider = OnboardingMenuProvider( + scanResponseProvider = Provider { + store.state.globalState.onboardingState.onboardingManager?.scanResponse + ?: store.state.detailsState.scanResponse + ?: error("ScanResponse must be not null") + }, + ) protected fun showConfetti(show: Boolean) = with(binding.vConfetti) { lavConfetti.show(show) diff --git a/app/src/main/java/com/tangem/tap/features/onboarding/products/note/OnboardingNoteFragment.kt b/app/src/main/java/com/tangem/tap/features/onboarding/products/note/OnboardingNoteFragment.kt index 7ac3806126..757ec91454 100644 --- a/app/src/main/java/com/tangem/tap/features/onboarding/products/note/OnboardingNoteFragment.kt +++ b/app/src/main/java/com/tangem/tap/features/onboarding/products/note/OnboardingNoteFragment.kt @@ -11,12 +11,14 @@ import coil.load import com.tangem.blockchain.common.Blockchain import com.tangem.core.analytics.Analytics import com.tangem.core.navigation.ShareElement +import com.tangem.domain.models.scan.ScanResponse import com.tangem.tap.common.analytics.events.Onboarding import com.tangem.tap.common.extensions.getDrawableCompat import com.tangem.tap.common.extensions.stripZeroPlainString import com.tangem.tap.common.toggleWidget.RefreshBalanceWidget import com.tangem.tap.common.transitions.InternalNoteLayoutTransition import com.tangem.tap.features.addBackPressHandler +import com.tangem.tap.features.onboarding.OnboardingWalletBalance import com.tangem.tap.features.onboarding.products.BaseOnboardingFragment import com.tangem.tap.features.onboarding.products.note.redux.OnboardingNoteAction import com.tangem.tap.features.onboarding.products.note.redux.OnboardingNoteState @@ -134,7 +136,7 @@ class OnboardingNoteFragment : BaseOnboardingFragment() { } private fun setupTopUpWalletState(state: OnboardingNoteState) = with(mainBinding.onboardingActionContainer) { - if (state.isBuyAllowed) { + if (availableForBuy(state.scanResponse, state.walletBalance)) { btnMainAction.setText(R.string.onboarding_top_up_button_but_crypto) btnMainAction.icon = null btnMainAction.setOnClickListener { @@ -217,6 +219,11 @@ class OnboardingNoteFragment : BaseOnboardingFragment() { } } + private fun availableForBuy(scanResponse: ScanResponse?, walletBalance: OnboardingWalletBalance): Boolean { + scanResponse ?: return false + return store.state.globalState.exchangeManager.availableForBuy(scanResponse, walletBalance.currency) + } + override fun handleOnBackPressed() { store.dispatch(OnboardingNoteAction.OnBackPressed) } diff --git a/app/src/main/java/com/tangem/tap/features/onboarding/products/note/redux/OnboardingNoteMiddleware.kt b/app/src/main/java/com/tangem/tap/features/onboarding/products/note/redux/OnboardingNoteMiddleware.kt index ef5296a6b4..ef320383b2 100644 --- a/app/src/main/java/com/tangem/tap/features/onboarding/products/note/redux/OnboardingNoteMiddleware.kt +++ b/app/src/main/java/com/tangem/tap/features/onboarding/products/note/redux/OnboardingNoteMiddleware.kt @@ -2,8 +2,9 @@ package com.tangem.tap.features.onboarding.products.note.redux import com.tangem.common.CompletionResult import com.tangem.common.extensions.guard +import com.tangem.common.routing.AppRouter import com.tangem.core.analytics.Analytics -import com.tangem.core.navigation.NavigationAction + import com.tangem.data.tokens.utils.CryptoCurrencyFactory import com.tangem.domain.common.extensions.makePrimaryWalletManager import com.tangem.domain.common.extensions.withMainContext @@ -204,7 +205,7 @@ private fun handleNoteAction(appState: () -> AppState?, action: Action, dispatch OnboardingDialog.InterruptOnboarding( onOk = { OnboardingHelper.onInterrupted() - store.dispatch(NavigationAction.PopBackTo()) + store.dispatchNavigationAction(AppRouter::pop) }, ), ) diff --git a/app/src/main/java/com/tangem/tap/features/onboarding/products/note/redux/OnboardingNoteReducer.kt b/app/src/main/java/com/tangem/tap/features/onboarding/products/note/redux/OnboardingNoteReducer.kt index 5552fc8b50..14f7989391 100644 --- a/app/src/main/java/com/tangem/tap/features/onboarding/products/note/redux/OnboardingNoteReducer.kt +++ b/app/src/main/java/com/tangem/tap/features/onboarding/products/note/redux/OnboardingNoteReducer.kt @@ -13,7 +13,7 @@ private fun internalReduce(action: Action, appState: AppState): OnboardingNoteSt when (action) { is GlobalAction.Onboarding.Start -> { - state = OnboardingNoteState() + state = OnboardingNoteState(scanResponse = action.scanResponse) } is OnboardingNoteAction.SetArtworkUrl -> { state = state.copy(cardArtworkUrl = action.artworkUrl) diff --git a/app/src/main/java/com/tangem/tap/features/onboarding/products/note/redux/OnboardingNoteState.kt b/app/src/main/java/com/tangem/tap/features/onboarding/products/note/redux/OnboardingNoteState.kt index ae7a2db594..3d659e39da 100644 --- a/app/src/main/java/com/tangem/tap/features/onboarding/products/note/redux/OnboardingNoteState.kt +++ b/app/src/main/java/com/tangem/tap/features/onboarding/products/note/redux/OnboardingNoteState.kt @@ -1,11 +1,10 @@ package com.tangem.tap.features.onboarding.products.note.redux import com.tangem.blockchain.common.WalletManager +import com.tangem.domain.models.scan.ScanResponse import com.tangem.tap.domain.TapError import com.tangem.tap.features.onboarding.OnboardingWalletBalance -import com.tangem.tap.store import org.rekotlin.StateType -import kotlin.properties.ReadOnlyProperty /** [REDACTED_AUTHOR] @@ -20,14 +19,11 @@ data class OnboardingNoteState( val currentStep: OnboardingNoteStep = OnboardingNoteStep.None, val steps: List = OnboardingNoteStep.values().toList(), val showConfetti: Boolean = false, + val scanResponse: ScanResponse? = null, ) : StateType { val progress: Int get() = steps.indexOf(currentStep) - - val isBuyAllowed: Boolean by ReadOnlyProperty { _, _ -> - store.state.globalState.exchangeManager.availableForBuy(walletBalance.currency) - } } enum class OnboardingNoteStep { diff --git a/app/src/main/java/com/tangem/tap/features/onboarding/products/twins/redux/TwinCardsMiddleware.kt b/app/src/main/java/com/tangem/tap/features/onboarding/products/twins/redux/TwinCardsMiddleware.kt index 033b790e84..19d77c509e 100644 --- a/app/src/main/java/com/tangem/tap/features/onboarding/products/twins/redux/TwinCardsMiddleware.kt +++ b/app/src/main/java/com/tangem/tap/features/onboarding/products/twins/redux/TwinCardsMiddleware.kt @@ -3,9 +3,10 @@ package com.tangem.tap.features.onboarding.products.twins.redux import com.tangem.blockchain.extensions.Result import com.tangem.common.CompletionResult import com.tangem.common.extensions.guard +import com.tangem.common.routing.AppRoute +import com.tangem.common.routing.utils.popTo import com.tangem.core.analytics.Analytics -import com.tangem.core.navigation.AppScreen -import com.tangem.core.navigation.NavigationAction + import com.tangem.data.tokens.utils.CryptoCurrencyFactory import com.tangem.domain.common.extensions.makePrimaryWalletManager import com.tangem.domain.common.extensions.withMainContext @@ -39,12 +40,13 @@ import kotlinx.coroutines.runBlocking import org.rekotlin.Action import org.rekotlin.DispatchFunction import org.rekotlin.Middleware +import kotlin.reflect.KClass object TwinCardsMiddleware { val handler = twinsWalletMiddleware } -private val twinsWalletMiddleware: Middleware = { dispatch, state -> +private val twinsWalletMiddleware: Middleware = { dispatch, _ -> { next -> { action -> handle(action, dispatch) @@ -64,15 +66,15 @@ private fun handle(action: Action, dispatch: DispatchFunction) { fun getScanResponse(): ScanResponse { return when (twinCardsState.mode) { - CreateTwinWalletMode.CreateWallet -> onboardingManager?.scanResponse - CreateTwinWalletMode.RecreateWallet -> globalState.scanResponse + is CreateTwinWalletMode.CreateWallet -> onboardingManager?.scanResponse + is CreateTwinWalletMode.RecreateWallet -> globalState.scanResponse } ?: throw NullPointerException("ScanResponse can't be NULL") } fun updateScanResponse(response: ScanResponse) { when (twinCardsState.mode) { - CreateTwinWalletMode.CreateWallet -> onboardingManager?.scanResponse = response - CreateTwinWalletMode.RecreateWallet -> store.dispatchOnMain(GlobalAction.SaveScanResponse(response)) + is CreateTwinWalletMode.CreateWallet -> onboardingManager?.scanResponse = response + is CreateTwinWalletMode.RecreateWallet -> store.dispatchOnMain(GlobalAction.SaveScanResponse(response)) } } @@ -103,6 +105,10 @@ private fun handle(action: Action, dispatch: DispatchFunction) { mainScope.launch { if (twinCardsState.currentStep is TwinCardsStep.WelcomeOnly) return@launch + if (twinCardsState.mode is CreateTwinWalletMode.RecreateWallet) { + store.dispatch(GlobalAction.SaveScanResponse(twinCardsState.mode.scanResponse)) + } + val scanResponse = getScanResponse() onboardingManager?.apply { if (!isActivationStarted(scanResponse.card.cardId)) { @@ -111,7 +117,7 @@ private fun handle(action: Action, dispatch: DispatchFunction) { } when (twinCardsState.mode) { - CreateTwinWalletMode.CreateWallet -> { + is CreateTwinWalletMode.CreateWallet -> { mainScope.launch { val wasTwinsOnboardingShown = store.inject(DaggerGraphState::wasTwinsOnboardingShownUseCase) .invokeSync() @@ -130,7 +136,7 @@ private fun handle(action: Action, dispatch: DispatchFunction) { store.dispatch(dispatchAction) } } - CreateTwinWalletMode.RecreateWallet -> { + is CreateTwinWalletMode.RecreateWallet -> { store.dispatch(TwinCardsAction.SetStepOfScreen(TwinCardsStep.Warning)) } } @@ -224,10 +230,10 @@ private fun handle(action: Action, dispatch: DispatchFunction) { delay(DELAY_SDK_DIALOG_CLOSE) withMainContext { when (twinCardsState.mode) { - CreateTwinWalletMode.CreateWallet -> { + is CreateTwinWalletMode.CreateWallet -> { store.dispatch(TwinCardsAction.SetStepOfScreen(TwinCardsStep.TopUpWallet)) } - CreateTwinWalletMode.RecreateWallet -> { + is CreateTwinWalletMode.RecreateWallet -> { store.dispatch(TwinCardsAction.SetStepOfScreen(TwinCardsStep.Done)) } } @@ -317,18 +323,18 @@ private fun handle(action: Action, dispatch: DispatchFunction) { TwinCardsAction.Done -> { val scanResponse = getScanResponse() when (twinCardsState.mode) { - CreateTwinWalletMode.CreateWallet -> { + is CreateTwinWalletMode.CreateWallet -> { store.dispatchOnMain(GlobalAction.Onboarding.Stop) OnboardingHelper.trySaveWalletAndNavigateToWalletScreen(scanResponse) } - CreateTwinWalletMode.RecreateWallet -> { + is CreateTwinWalletMode.RecreateWallet -> { scope.launch { val walletsRepository = store.inject(DaggerGraphState::walletsRepository) if (walletsRepository.shouldSaveUserWalletsSync()) { OnboardingHelper.trySaveWalletAndNavigateToWalletScreen(scanResponse) } else { - store.dispatchOnMain(NavigationAction.PopBackTo(AppScreen.Home)) + store.dispatchNavigationAction { popTo() } } } } @@ -352,7 +358,7 @@ private fun handle(action: Action, dispatch: DispatchFunction) { store.dispatch(TwinCardsAction.CardsManager.Release) action.shouldResetTwinCardsWidget(shouldReturnCardBack) { - store.dispatchOnMain(NavigationAction.PopBackTo(getPopBackScreen())) + store.dispatchNavigationAction { popTo(routeClass = getPopBackScreen()) } } } store.dispatchDialogShow(OnboardingDialog.InterruptOnboarding(onOkCallback)) @@ -362,18 +368,18 @@ private fun handle(action: Action, dispatch: DispatchFunction) { } } -private fun getPopBackScreen(): AppScreen { +private fun getPopBackScreen(): KClass { val userWalletsListManager = store.inject(DaggerGraphState::generalUserWalletsListManager) return if (userWalletsListManager.hasUserWallets) { - val isLocked = runCatching { userWalletsListManager.asLockable()?.isLockedSync } - .fold(onSuccess = { true }, onFailure = { false }) + val isLocked = runCatching { userWalletsListManager.asLockable()?.isLockedSync!! }.getOrElse { false } + if (isLocked) { - AppScreen.Welcome + AppRoute.Welcome::class } else { - AppScreen.Wallet + AppRoute.Wallet::class } } else { - AppScreen.Home + AppRoute.Home::class } } \ No newline at end of file diff --git a/app/src/main/java/com/tangem/tap/features/onboarding/products/twins/redux/TwinCardsReducer.kt b/app/src/main/java/com/tangem/tap/features/onboarding/products/twins/redux/TwinCardsReducer.kt index 9ba9492c54..594dd4e77c 100644 --- a/app/src/main/java/com/tangem/tap/features/onboarding/products/twins/redux/TwinCardsReducer.kt +++ b/app/src/main/java/com/tangem/tap/features/onboarding/products/twins/redux/TwinCardsReducer.kt @@ -1,7 +1,7 @@ package com.tangem.tap.features.onboarding.products.twins.redux -import com.tangem.domain.common.util.cardTypesResolver import com.tangem.domain.common.getTwinCardNumber +import com.tangem.domain.common.util.cardTypesResolver import com.tangem.tap.common.redux.AppState import org.rekotlin.Action @@ -35,7 +35,10 @@ private fun internalReduce(action: Action, state: AppState): TwinCardsState { ) } is TwinCardsAction.SetStepOfScreen -> { - state = state.copy(currentStep = action.step) + state = state.copy( + currentStep = action.step, + welcomeOnlyScanResponse = (action.step as? TwinCardsStep.WelcomeOnly)?.scanResponse, + ) } is TwinCardsAction.SetUserUnderstand -> { state = state.copy(userWasUnderstandIfWalletRecreate = action.isUnderstand) diff --git a/app/src/main/java/com/tangem/tap/features/onboarding/products/twins/redux/TwinCardsState.kt b/app/src/main/java/com/tangem/tap/features/onboarding/products/twins/redux/TwinCardsState.kt index a5608d4371..83e641bc8a 100644 --- a/app/src/main/java/com/tangem/tap/features/onboarding/products/twins/redux/TwinCardsState.kt +++ b/app/src/main/java/com/tangem/tap/features/onboarding/products/twins/redux/TwinCardsState.kt @@ -1,14 +1,12 @@ package com.tangem.tap.features.onboarding.products.twins.redux import com.tangem.blockchain.common.WalletManager -import com.tangem.domain.models.scan.ScanResponse import com.tangem.domain.common.TwinCardNumber +import com.tangem.domain.models.scan.ScanResponse import com.tangem.tap.domain.TapError import com.tangem.tap.domain.twins.TwinCardsManager import com.tangem.tap.features.onboarding.OnboardingWalletBalance -import com.tangem.tap.store import org.rekotlin.StateType -import kotlin.properties.ReadOnlyProperty /** [REDACTED_AUTHOR] @@ -29,11 +27,12 @@ data class TwinCardsState( val balanceNonCriticalError: TapError? = null, val balanceCriticalError: TapError? = null, val showConfetti: Boolean = false, + val welcomeOnlyScanResponse: ScanResponse? = null, ) : StateType { val steps: List get() = when (mode) { - CreateTwinWalletMode.CreateWallet -> listOf( + is CreateTwinWalletMode.CreateWallet -> listOf( TwinCardsStep.None, TwinCardsStep.CreateFirstWallet, TwinCardsStep.CreateSecondWallet, @@ -41,7 +40,7 @@ data class TwinCardsState( TwinCardsStep.TopUpWallet, TwinCardsStep.Done, ) - CreateTwinWalletMode.RecreateWallet -> listOf( + is CreateTwinWalletMode.RecreateWallet -> listOf( TwinCardsStep.None, TwinCardsStep.CreateFirstWallet, TwinCardsStep.CreateSecondWallet, @@ -55,13 +54,15 @@ data class TwinCardsState( val twinningInProgress: Boolean get() = currentStep == TwinCardsStep.CreateSecondWallet || currentStep == TwinCardsStep.CreateThirdWallet - - val isBuyAllowed: Boolean by ReadOnlyProperty { _, _ -> - store.state.globalState.exchangeManager.availableForBuy(walletBalance.currency) - } } -enum class CreateTwinWalletMode { CreateWallet, RecreateWallet } +sealed class CreateTwinWalletMode { + data object CreateWallet : CreateTwinWalletMode() + + data class RecreateWallet( + val scanResponse: ScanResponse, + ) : CreateTwinWalletMode() +} sealed class TwinCardsStep { object None : TwinCardsStep() diff --git a/app/src/main/java/com/tangem/tap/features/onboarding/products/twins/ui/OnboardingTwinsFragment.kt b/app/src/main/java/com/tangem/tap/features/onboarding/products/twins/ui/OnboardingTwinsFragment.kt index 2cbf5949d1..eda118c3dc 100644 --- a/app/src/main/java/com/tangem/tap/features/onboarding/products/twins/ui/OnboardingTwinsFragment.kt +++ b/app/src/main/java/com/tangem/tap/features/onboarding/products/twins/ui/OnboardingTwinsFragment.kt @@ -6,6 +6,7 @@ import android.view.View import android.view.animation.OvershootInterpolator import androidx.annotation.LayoutRes import androidx.constraintlayout.widget.ConstraintSet +import androidx.core.view.MenuProvider import androidx.core.view.isVisible import androidx.transition.TransitionManager import coil.load @@ -25,12 +26,15 @@ import com.tangem.tap.common.toggleWidget.RefreshBalanceWidget import com.tangem.tap.common.transitions.InternalNoteLayoutTransition import com.tangem.tap.domain.twins.TwinsCardWidget import com.tangem.tap.features.addBackPressHandler +import com.tangem.tap.features.onboarding.OnboardingMenuProvider +import com.tangem.tap.features.onboarding.OnboardingWalletBalance import com.tangem.tap.features.onboarding.products.BaseOnboardingFragment import com.tangem.tap.features.onboarding.products.twins.redux.CreateTwinWalletMode import com.tangem.tap.features.onboarding.products.twins.redux.TwinCardsAction import com.tangem.tap.features.onboarding.products.twins.redux.TwinCardsState import com.tangem.tap.features.onboarding.products.twins.redux.TwinCardsStep import com.tangem.tap.store +import com.tangem.utils.Provider import com.tangem.wallet.R import com.tangem.wallet.databinding.LayoutOnboardingContainerTopBinding import dagger.hilt.android.AndroidEntryPoint @@ -52,15 +56,19 @@ internal class OnboardingTwinsFragment : BaseOnboardingFragment( override fun configureTransitions() { when (store.state.twinCardsState.mode) { - CreateTwinWalletMode.CreateWallet -> { + is CreateTwinWalletMode.CreateWallet -> { super.configureTransitions() } - CreateTwinWalletMode.RecreateWallet -> { + is CreateTwinWalletMode.RecreateWallet -> { configureDefaultTransactions() } } } + override fun loadToolbarMenu(): MenuProvider = OnboardingMenuProvider( + scanResponseProvider = Provider { getActualScanResponse() }, + ) + @Suppress("MagicNumber") override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) @@ -330,7 +338,7 @@ internal class OnboardingTwinsFragment : BaseOnboardingFragment( else -> {} } - if (state.isBuyAllowed) { + if (availableForBuy(getActualScanResponse(), state.walletBalance)) { btnMainAction.setText(R.string.onboarding_top_up_button_but_crypto) btnMainAction.setOnClickListener { store.dispatch(TwinCardsAction.TopUp) @@ -383,8 +391,8 @@ internal class OnboardingTwinsFragment : BaseOnboardingFragment( tvBody.setText(R.string.onboarding_done_body) val layout = when (state.mode) { - CreateTwinWalletMode.CreateWallet -> R.layout.lp_onboarding_done_activation_twins - CreateTwinWalletMode.RecreateWallet -> R.layout.lp_onboarding_done + is CreateTwinWalletMode.CreateWallet -> R.layout.lp_onboarding_done_activation_twins + is CreateTwinWalletMode.RecreateWallet -> R.layout.lp_onboarding_done } updateConstraints(state.currentStep, layout) } @@ -412,6 +420,18 @@ internal class OnboardingTwinsFragment : BaseOnboardingFragment( } } + private fun availableForBuy(scanResponse: ScanResponse?, walletBalance: OnboardingWalletBalance): Boolean { + scanResponse ?: return false + return store.state.globalState.exchangeManager.availableForBuy(scanResponse, walletBalance.currency) + } + + private fun getActualScanResponse(): ScanResponse { + return store.state.twinCardsState.welcomeOnlyScanResponse + ?: store.state.globalState.onboardingState.onboardingManager?.scanResponse + ?: store.state.detailsState.scanResponse + ?: error("ScanResponse must be not null") + } + override fun handleOnBackPressed() { store.dispatch( TwinCardsAction.OnBackPressed { should, popAction -> diff --git a/app/src/main/java/com/tangem/tap/features/onboarding/products/wallet/redux/OnboardingWalletMiddleware.kt b/app/src/main/java/com/tangem/tap/features/onboarding/products/wallet/redux/OnboardingWalletMiddleware.kt index 2bf1bc1b5e..0e32a392c4 100644 --- a/app/src/main/java/com/tangem/tap/features/onboarding/products/wallet/redux/OnboardingWalletMiddleware.kt +++ b/app/src/main/java/com/tangem/tap/features/onboarding/products/wallet/redux/OnboardingWalletMiddleware.kt @@ -7,16 +7,16 @@ import com.tangem.common.core.TangemSdkError import com.tangem.common.extensions.guard import com.tangem.common.extensions.ifNotNull import com.tangem.common.extensions.toHexString +import com.tangem.common.routing.AppRoute +import com.tangem.common.routing.AppRouter import com.tangem.common.services.Result import com.tangem.core.analytics.Analytics -import com.tangem.core.navigation.AppScreen -import com.tangem.core.navigation.NavigationAction import com.tangem.domain.common.extensions.withMainContext import com.tangem.domain.common.util.cardTypesResolver import com.tangem.domain.models.scan.CardDTO import com.tangem.domain.models.scan.ScanResponse -import com.tangem.domain.wallets.models.Artwork import com.tangem.domain.wallets.builder.UserWalletBuilder +import com.tangem.domain.wallets.models.Artwork import com.tangem.feature.onboarding.data.model.CreateWalletResponse import com.tangem.feature.onboarding.presentation.wallet2.analytics.SeedPhraseSource import com.tangem.feature.wallet.presentation.wallet.domain.BackupValidator @@ -25,10 +25,7 @@ import com.tangem.operations.backup.BackupService import com.tangem.tap.* import com.tangem.tap.common.analytics.events.AnalyticsParam import com.tangem.tap.common.analytics.events.Onboarding -import com.tangem.tap.common.extensions.dispatchDialogShow -import com.tangem.tap.common.extensions.dispatchOnMain -import com.tangem.tap.common.extensions.dispatchWithMain -import com.tangem.tap.common.extensions.inject +import com.tangem.tap.common.extensions.* import com.tangem.tap.common.redux.AppState import com.tangem.tap.common.redux.global.GlobalAction import com.tangem.tap.domain.tasks.product.CreateProductWalletTaskResponse @@ -38,6 +35,7 @@ import com.tangem.tap.features.onboarding.OnboardingDialog import com.tangem.tap.features.onboarding.OnboardingHelper import com.tangem.tap.proxy.redux.DaggerGraphState import com.tangem.wallet.R +import kotlinx.coroutines.delay import kotlinx.coroutines.launch import org.rekotlin.Action import org.rekotlin.Middleware @@ -47,6 +45,8 @@ object OnboardingWalletMiddleware { val handler = onboardingWalletMiddleware } +private const val HIDE_PROGRESS_DELAY = 400L + private val onboardingWalletMiddleware: Middleware = { dispatch, state -> { next -> { action -> @@ -164,17 +164,13 @@ private fun handleWalletAction(action: Action) { store.dispatch(GlobalAction.Onboarding.Stop) if (scanResponse == null) { - store.dispatch(NavigationAction.PopBackTo()) - store.dispatch(HomeAction.ReadCard(scope = action.scope)) + action.scope.launch { + readCard { newScanResponse -> + handleFinishOnboardind(newScanResponse) + } + } } else { - val backupState = store.state.onboardingWalletState.backupState - val updatedScanResponse = updateScanResponseAfterBackup(scanResponse, backupState) - OnboardingHelper.trySaveWalletAndNavigateToWalletScreen( - scanResponse = updatedScanResponse, - accessCode = backupState.accessCode, - backupCardsIds = backupState.backupCardIds, - hasBackupError = backupState.hasBackupError, - ) + handleFinishOnboardind(scanResponse) } } is OnboardingWalletAction.ResumeBackup -> { @@ -199,6 +195,43 @@ private fun handleWalletAction(action: Action) { } } +private fun handleFinishOnboardind(scanResponse: ScanResponse) { + val backupState = store.state.onboardingWalletState.backupState + val updatedScanResponse = updateScanResponseAfterBackup(scanResponse, backupState) + OnboardingHelper.trySaveWalletAndNavigateToWalletScreen( + scanResponse = updatedScanResponse, + accessCode = backupState.accessCode, + backupCardsIds = backupState.backupCardIds, + hasBackupError = backupState.hasBackupError, + ) +} + +private suspend fun readCard(onSuccess: (ScanResponse) -> Unit) { + val shouldSaveAccessCodes = store.inject(DaggerGraphState::settingsRepository).shouldSaveAccessCodes() + + store.inject(DaggerGraphState::cardSdkConfigRepository).setAccessCodeRequestPolicy( + isBiometricsRequestPolicy = shouldSaveAccessCodes, + ) + + store.inject(DaggerGraphState::scanCardProcessor).scan( + analyticsSource = com.tangem.core.analytics.models.AnalyticsParam.ScreensSources.Intro, + onProgressStateChange = { showProgress -> + if (showProgress) { + store.dispatch(HomeAction.ScanInProgress(scanInProgress = true)) + } else { + delay(HIDE_PROGRESS_DELAY) + store.dispatch(HomeAction.ScanInProgress(scanInProgress = false)) + } + }, + onFailure = { + Timber.e(it, "Unable to scan card") + delay(HIDE_PROGRESS_DELAY) + store.dispatch(HomeAction.ScanInProgress(scanInProgress = false)) + }, + onSuccess = onSuccess, + ) +} + private suspend fun loadArtworkForUnfinishedBackup( cardId: String, cardPublicKey: ByteArray, @@ -529,7 +562,8 @@ private fun handleBackupAction(appState: () -> AppState?, action: BackupAction) addedBackupCardsCount = backupService.addedBackupCardsCount, ), ) - store.dispatch(NavigationAction.NavigateTo(AppScreen.OnboardingWallet)) + + store.dispatchNavigationAction { push(AppRoute.OnboardingWallet()) } } is BackupAction.SkipBackup -> { Analytics.send(Onboarding.Backup.Skipped()) @@ -614,7 +648,7 @@ private fun handleOnBackPressed(state: OnboardingWalletState) { } BackupStep.Finished -> { OnboardingHelper.onInterrupted() - store.dispatch(NavigationAction.PopBackTo()) + store.dispatchNavigationAction(AppRouter::pop) } } } @@ -625,7 +659,7 @@ private fun showInterruptOnboardingDialog() { onOk = { OnboardingHelper.onInterrupted() store.dispatch(BackupAction.DiscardBackup) - store.dispatch(NavigationAction.PopBackTo()) + store.dispatchNavigationAction(AppRouter::pop) }, ), ) diff --git a/app/src/main/java/com/tangem/tap/features/onboarding/products/wallet/redux/OnboardingWalletState.kt b/app/src/main/java/com/tangem/tap/features/onboarding/products/wallet/redux/OnboardingWalletState.kt index 64b81fc771..6663311df8 100644 --- a/app/src/main/java/com/tangem/tap/features/onboarding/products/wallet/redux/OnboardingWalletState.kt +++ b/app/src/main/java/com/tangem/tap/features/onboarding/products/wallet/redux/OnboardingWalletState.kt @@ -2,7 +2,7 @@ package com.tangem.tap.features.onboarding.products.wallet.redux import android.graphics.Bitmap import android.net.Uri -import com.tangem.core.navigation.StateDialog +import com.tangem.domain.redux.StateDialog import org.rekotlin.StateType /** diff --git a/app/src/main/java/com/tangem/tap/features/onboarding/products/wallet/ui/OnboardingSeedPhraseStateHandler.kt b/app/src/main/java/com/tangem/tap/features/onboarding/products/wallet/ui/OnboardingSeedPhraseStateHandler.kt index e92ebc5ca3..475a6d64b9 100644 --- a/app/src/main/java/com/tangem/tap/features/onboarding/products/wallet/ui/OnboardingSeedPhraseStateHandler.kt +++ b/app/src/main/java/com/tangem/tap/features/onboarding/products/wallet/ui/OnboardingSeedPhraseStateHandler.kt @@ -1,6 +1,10 @@ package com.tangem.tap.features.onboarding.products.wallet.ui +import android.app.Activity +import androidx.compose.foundation.isSystemInDarkTheme import androidx.compose.runtime.collectAsState +import com.tangem.core.ui.res.TangemTheme +import com.tangem.core.ui.windowsize.rememberWindowSize import com.tangem.feature.onboarding.api.OnboardingSeedPhraseScreen import com.tangem.feature.onboarding.api.OnboardingSeedPhraseApi import com.tangem.feature.onboarding.presentation.wallet2.viewmodel.SeedPhraseScreen @@ -16,6 +20,7 @@ import com.tangem.wallet.R */ internal class OnboardingSeedPhraseStateHandler( private val onboardingSeedPhraseApi: OnboardingSeedPhraseApi = OnboardingSeedPhraseScreen(), + private val activity: Activity, ) { fun newState( @@ -49,11 +54,16 @@ internal class OnboardingSeedPhraseStateHandler( val subScreen = viewModel.currentScreen.collectAsState().value setMainScreenToolbarTitle(walletFragment, subScreen) - onboardingSeedPhraseApi.ScreenContent( - uiState = viewModel.uiState, - subScreen = subScreen, - progress = viewModel.progress.collectAsState(0).value.toFloat() / onboardingWalletMaxProgress, - ) + TangemTheme( + isDark = isSystemInDarkTheme(), + windowSize = rememberWindowSize(activity = activity), + ) { + onboardingSeedPhraseApi.ScreenContent( + uiState = viewModel.uiState, + subScreen = subScreen, + progress = viewModel.progress.collectAsState(0).value.toFloat() / onboardingWalletMaxProgress, + ) + } } } diff --git a/app/src/main/java/com/tangem/tap/features/onboarding/products/wallet/ui/OnboardingWalletFragment.kt b/app/src/main/java/com/tangem/tap/features/onboarding/products/wallet/ui/OnboardingWalletFragment.kt index 5c7b1e8589..e0577994f9 100644 --- a/app/src/main/java/com/tangem/tap/features/onboarding/products/wallet/ui/OnboardingWalletFragment.kt +++ b/app/src/main/java/com/tangem/tap/features/onboarding/products/wallet/ui/OnboardingWalletFragment.kt @@ -21,13 +21,13 @@ import com.google.android.material.tabs.TabLayoutMediator import com.tangem.common.CardIdFormatter import com.tangem.common.CompletionResult import com.tangem.common.core.CardIdDisplayFormat +import com.tangem.common.routing.AppRoute import com.tangem.core.analytics.Analytics import com.tangem.core.analytics.models.AnalyticsParam import com.tangem.core.analytics.models.Basic import com.tangem.core.ui.extensions.setStatusBarColor import com.tangem.domain.common.util.cardTypesResolver import com.tangem.feature.onboarding.data.model.CreateWalletResponse -import com.tangem.feature.onboarding.navigation.OnboardingRouter import com.tangem.feature.onboarding.presentation.wallet2.analytics.SeedPhraseSource import com.tangem.feature.onboarding.presentation.wallet2.viewmodel.SeedPhraseMediator import com.tangem.feature.onboarding.presentation.wallet2.viewmodel.SeedPhraseRouter @@ -46,6 +46,7 @@ import com.tangem.tap.features.onboarding.products.wallet.redux.* import com.tangem.tap.features.onboarding.products.wallet.ui.dialogs.AccessCodeDialog import com.tangem.tap.mainScope import com.tangem.tap.store +import com.tangem.utils.Provider import com.tangem.wallet.R import com.tangem.wallet.databinding.FragmentOnboardingWalletBinding import com.tangem.wallet.databinding.LayoutOnboardingSeedPhraseBinding @@ -66,9 +67,10 @@ class OnboardingWalletFragment : internal val bindingSeedPhrase: LayoutOnboardingSeedPhraseBinding by lazy { binding.onboardingSeedPhraseContainer } - private val canSkipBackup by lazy { arguments?.getBoolean(OnboardingRouter.CAN_SKIP_BACKUP) ?: true } + private val canSkipBackup by lazy { arguments?.getBoolean(AppRoute.OnboardingWallet.CAN_SKIP_BACKUP_KEY) ?: true } + + private lateinit var seedPhraseStateHandler: OnboardingSeedPhraseStateHandler - private val seedPhraseStateHandler: OnboardingSeedPhraseStateHandler = OnboardingSeedPhraseStateHandler() private val seedPhraseViewModel by viewModels() private lateinit var cardsWidget: WalletCardsWidget @@ -79,6 +81,7 @@ class OnboardingWalletFragment : override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) + seedPhraseStateHandler = OnboardingSeedPhraseStateHandler(activity = requireActivity()) val newSeedPhraseRouter = makeSeedPhraseRouter() seedPhraseRouter = newSeedPhraseRouter @@ -113,7 +116,12 @@ class OnboardingWalletFragment : ) } - override fun loadToolbarMenu(): MenuProvider = OnboardingMenuProvider() + override fun loadToolbarMenu(): MenuProvider = OnboardingMenuProvider( + scanResponseProvider = Provider { + store.state.globalState.onboardingState.onboardingManager?.scanResponse + ?: error("ScanResponse must be not null") + }, + ) private fun reInitCardsWidgetIfNeeded(backupCardsCounts: Int) = with(binding) { val viewBackupCount = flCardsContainer.childCount - 1 @@ -505,7 +513,13 @@ class OnboardingWalletFragment : onOpenChat = { Analytics.send(Basic.ButtonSupport(AnalyticsParam.ScreensSources.Intro)) // changed on email support [REDACTED_TASK_KEY] - store.dispatch(GlobalAction.SendEmail(SupportInfo())) + store.dispatch( + GlobalAction.SendEmail( + feedbackData = SupportInfo(), + scanResponse = store.state.globalState.onboardingState.onboardingManager?.scanResponse + ?: error("ScanResponse must be not null"), + ), + ) }, onOpenUriClick = { uri -> store.dispatchOpenUrl(uri.toString()) diff --git a/app/src/main/java/com/tangem/tap/features/onboarding/products/wallet/ui/dialogs/AttestationFailedDialog.kt b/app/src/main/java/com/tangem/tap/features/onboarding/products/wallet/ui/dialogs/AttestationFailedDialog.kt index 3e9df5885e..5b6c8b8c85 100644 --- a/app/src/main/java/com/tangem/tap/features/onboarding/products/wallet/ui/dialogs/AttestationFailedDialog.kt +++ b/app/src/main/java/com/tangem/tap/features/onboarding/products/wallet/ui/dialogs/AttestationFailedDialog.kt @@ -13,7 +13,7 @@ internal object AttestationFailedDialog { return MaterialAlertDialogBuilder(context, R.style.CustomMaterialDialog).apply { setTitle(R.string.common_error) setMessage(R.string.issuer_signature_loading_failed) - setPositiveButton(R.string.ok) { dialog, _ -> + setPositiveButton(R.string.common_ok) { dialog, _ -> dialog.dismiss() } setOnDismissListener { diff --git a/app/src/main/java/com/tangem/tap/features/onboarding/products/wallet/ui/dialogs/WalletActivationErrorDialog.kt b/app/src/main/java/com/tangem/tap/features/onboarding/products/wallet/ui/dialogs/WalletActivationErrorDialog.kt index ace9edcf19..45c8213362 100644 --- a/app/src/main/java/com/tangem/tap/features/onboarding/products/wallet/ui/dialogs/WalletActivationErrorDialog.kt +++ b/app/src/main/java/com/tangem/tap/features/onboarding/products/wallet/ui/dialogs/WalletActivationErrorDialog.kt @@ -23,7 +23,13 @@ object WalletActivationErrorDialog { setNegativeButton(R.string.common_support) { _, _ -> // changed on email support [REDACTED_TASK_KEY] Analytics.send(Basic.ButtonSupport(AnalyticsParam.ScreensSources.Intro)) - store.dispatch(GlobalAction.SendEmail(SupportInfo())) + store.dispatch( + GlobalAction.SendEmail( + feedbackData = SupportInfo(), + scanResponse = store.state.globalState.onboardingState.onboardingManager?.scanResponse + ?: error("ScanResponse must be not null"), + ), + ) } setOnDismissListener { store.dispatchDialogHide() } setCancelable(false) diff --git a/app/src/main/java/com/tangem/tap/features/saveWallet/redux/SaveWalletMiddleware.kt b/app/src/main/java/com/tangem/tap/features/saveWallet/redux/SaveWalletMiddleware.kt index 4069551f22..f1b43ae123 100644 --- a/app/src/main/java/com/tangem/tap/features/saveWallet/redux/SaveWalletMiddleware.kt +++ b/app/src/main/java/com/tangem/tap/features/saveWallet/redux/SaveWalletMiddleware.kt @@ -3,29 +3,22 @@ package com.tangem.tap.features.saveWallet.redux import com.tangem.common.* import com.tangem.common.core.TangemSdkError import com.tangem.common.extensions.guard +import com.tangem.common.routing.AppRoute +import com.tangem.common.routing.utils.popTo import com.tangem.core.analytics.Analytics -import com.tangem.core.navigation.AppScreen -import com.tangem.core.navigation.NavigationAction import com.tangem.domain.wallets.builder.UserWalletBuilder import com.tangem.domain.wallets.models.UserWallet +import com.tangem.tap.* import com.tangem.tap.common.analytics.events.AnalyticsParam import com.tangem.tap.common.analytics.events.MainScreen import com.tangem.tap.common.analytics.events.Onboarding -import com.tangem.tap.common.extensions.dispatchOnMain -import com.tangem.tap.common.extensions.dispatchWithMain -import com.tangem.tap.common.extensions.inject -import com.tangem.tap.common.extensions.onUserWalletSelected +import com.tangem.tap.common.extensions.* import com.tangem.tap.common.redux.AppState -import com.tangem.tap.mainScope import com.tangem.tap.proxy.redux.DaggerGraphState -import com.tangem.tap.scope -import com.tangem.tap.store -import com.tangem.tap.tangemSdkManager import com.tangem.utils.coroutines.JobHolder import com.tangem.utils.coroutines.saveIn import kotlinx.coroutines.launch import org.rekotlin.Middleware -import org.rekotlin.Store import timber.log.Timber internal class SaveWalletMiddleware { @@ -83,12 +76,12 @@ internal class SaveWalletMiddleware { Timber.e(error, "Unable to save user wallet") } .doOnSuccess { mainScope.launch { store.onUserWalletSelected(userWallet) } } - .doOnResult { store.navigateToWallet() } + .doOnResult { navigateToWallet() } } } private fun enrollBiometrics() { - store.dispatchOnMain(NavigationAction.OpenBiometricsSettings) + activityResultCaller.openSystemBiometrySettings() } private fun allowToUseBiometrics(state: SaveWalletState) = scope.launch { @@ -131,7 +124,7 @@ internal class SaveWalletMiddleware { ) store.dispatchWithMain(SaveWalletAction.AllowToUseBiometrics.Success) - store.dispatchWithMain(NavigationAction.PopBackTo(AppScreen.Wallet)) + store.dispatchNavigationAction { popTo() } } private fun dismiss(state: SaveWalletState) { @@ -160,13 +153,9 @@ internal class SaveWalletMiddleware { } } - private suspend fun Store.navigateToWallet() { - dispatchWithMain( - if (store.state.navigationState.backStack.contains(AppScreen.Wallet)) { - NavigationAction.PopBackTo(AppScreen.Wallet) - } else { - NavigationAction.NavigateTo(AppScreen.Wallet) - }, - ) + private fun navigateToWallet() { + store.dispatchNavigationAction { + replaceAll(AppRoute.Wallet) + } } } \ No newline at end of file diff --git a/app/src/main/java/com/tangem/tap/features/saveWallet/ui/components/SaveWalletScreenContent.kt b/app/src/main/java/com/tangem/tap/features/saveWallet/ui/components/SaveWalletScreenContent.kt index c7679a466d..4206df1904 100644 --- a/app/src/main/java/com/tangem/tap/features/saveWallet/ui/components/SaveWalletScreenContent.kt +++ b/app/src/main/java/com/tangem/tap/features/saveWallet/ui/components/SaveWalletScreenContent.kt @@ -2,13 +2,7 @@ package com.tangem.tap.features.saveWallet.ui.components import android.content.res.Configuration import androidx.compose.foundation.background -import androidx.compose.foundation.layout.Arrangement -import androidx.compose.foundation.layout.Column -import androidx.compose.foundation.layout.Row -import androidx.compose.foundation.layout.fillMaxWidth -import androidx.compose.foundation.layout.padding -import androidx.compose.foundation.layout.size -import androidx.compose.foundation.layout.widthIn +import androidx.compose.foundation.layout.* import androidx.compose.material.Icon import androidx.compose.material.IconButton import androidx.compose.material.Text @@ -20,16 +14,10 @@ import androidx.compose.ui.res.painterResource import androidx.compose.ui.res.stringResource import androidx.compose.ui.text.style.TextAlign import androidx.compose.ui.tooling.preview.Preview -import com.tangem.core.ui.components.PrimaryButton -import com.tangem.core.ui.components.SpacerH16 -import com.tangem.core.ui.components.SpacerH32 -import com.tangem.core.ui.components.SpacerH4 -import com.tangem.core.ui.components.SpacerHHalf -import com.tangem.core.ui.components.SpacerW24 -import com.tangem.core.ui.components.SpacerW8 +import com.tangem.core.ui.components.* import com.tangem.core.ui.components.atoms.Hand -import com.tangem.core.ui.res.TangemThemePreview import com.tangem.core.ui.res.TangemTheme +import com.tangem.core.ui.res.TangemThemePreview import com.tangem.wallet.R @Composable @@ -37,10 +25,7 @@ internal fun SaveWalletScreenContent(showProgress: Boolean, onSaveWalletClick: ( Column(horizontalAlignment = Alignment.CenterHorizontally) { Header(onCloseClick = onCloseClick) SpacerHHalf() - Title( - modifier = Modifier - .widthIn(max = TangemTheme.dimens.size200), - ) + Title(modifier = Modifier.padding(horizontal = TangemTheme.dimens.spacing22)) SpacerH32() Description( modifier = Modifier 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 3c3409459e..35ee864987 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 @@ -7,7 +7,8 @@ import com.tangem.blockchain.common.FeePaidCurrency import com.tangem.blockchain.common.WalletManager import com.tangem.blockchain.common.transaction.TransactionFee import com.tangem.common.core.TangemSdkError -import com.tangem.core.navigation.StateDialog +import com.tangem.domain.models.scan.ScanResponse +import com.tangem.domain.redux.StateDialog import com.tangem.domain.tokens.model.CryptoCurrency import com.tangem.tap.common.analytics.events.Token.Send.AddressEntered import com.tangem.tap.common.redux.ToastNotificationAction @@ -185,12 +186,16 @@ sealed class SendAction : SendScreenAction { ) : Dialog() sealed class SendTransactionFails : Dialog() { - data class CardSdkError(val error: TangemSdkError) : Dialog() - data class BlockchainSdkError(val error: com.tangem.blockchain.common.BlockchainSdkError) : Dialog() + data class CardSdkError(val error: TangemSdkError, val scanResponse: ScanResponse) : Dialog() + data class BlockchainSdkError( + val error: com.tangem.blockchain.common.BlockchainSdkError, + val scanResponse: ScanResponse, + ) : Dialog() } data class RequestFeeError( val error: com.tangem.blockchain.common.BlockchainSdkError, + val scanResponse: ScanResponse, val onRetry: () -> Unit, ) : Dialog() 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 e3096c6a4f..ea4092c252 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 @@ -1,6 +1,9 @@ package com.tangem.tap.features.send.redux.middlewares -import com.tangem.blockchain.common.* +import com.tangem.blockchain.common.Amount +import com.tangem.blockchain.common.AmountType +import com.tangem.blockchain.common.BlockchainSdkError +import com.tangem.blockchain.common.WalletManager import com.tangem.blockchain.common.transaction.TransactionFee import com.tangem.blockchain.extensions.Result import com.tangem.common.extensions.isZero @@ -92,6 +95,7 @@ class RequestFeeMiddleware { dispatch( SendAction.Dialog.RequestFeeError( error = blockchainSdkError, + scanResponse = scanResponse, onRetry = { dispatch(FeeAction.RequestFee) }, ), ) 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 756b65e48d..ecb0e071d8 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 @@ -14,10 +14,10 @@ import com.tangem.blockchain.common.transaction.Fee import com.tangem.blockchain.extensions.Result import com.tangem.blockchainsdk.utils.minimalAmount import com.tangem.common.core.TangemSdkError +import com.tangem.common.routing.AppRouter import com.tangem.core.analytics.Analytics import com.tangem.core.analytics.models.AnalyticsParam import com.tangem.core.analytics.models.Basic -import com.tangem.core.navigation.NavigationAction import com.tangem.domain.common.TapWorkarounds.isStart2Coin import com.tangem.domain.common.extensions.withMainContext import com.tangem.domain.demo.DemoTransactionSender @@ -270,7 +270,7 @@ private fun sendTransaction( ), ) Analytics.sendSelectedCurrencyEvent(mainCurrencyType) - dispatch(NavigationAction.PopBackTo()) + store.dispatchNavigationAction(AppRouter::pop) } } is Result.Failure -> { @@ -288,11 +288,25 @@ private fun sendTransaction( val tangemSdkError = error.tangemError as? TangemSdkError ?: return@withMainContext if (tangemSdkError is TangemSdkError.UserCancelled) return@withMainContext - dispatch(SendAction.Dialog.SendTransactionFails.CardSdkError(tangemSdkError)) + dispatch( + SendAction.Dialog.SendTransactionFails.CardSdkError( + error = tangemSdkError, + scanResponse = store.inject(DaggerGraphState::generalUserWalletsListManager) + .selectedUserWalletSync?.scanResponse + ?: error("ScanResponse must be not null"), + ), + ) } is BlockchainSdkError.CreateAccountUnderfunded -> { // from XLM, XRP, Polkadot - dispatch(SendAction.Dialog.SendTransactionFails.BlockchainSdkError(error)) + dispatch( + SendAction.Dialog.SendTransactionFails.BlockchainSdkError( + error = error, + scanResponse = store.inject(DaggerGraphState::generalUserWalletsListManager) + .selectedUserWalletSync?.scanResponse + ?: error("ScanResponse must be not null"), + ), + ) } is BlockchainSdkError.Kaspa.UtxoAmountError -> { dispatch( @@ -326,12 +340,19 @@ private fun sendTransaction( AppDialog.SimpleOkDialogRes( headerId = R.string.common_done, messageId = R.string.alert_demo_feature_disabled, - onOk = { dispatch(NavigationAction.PopBackTo()) }, + onOk = { store.dispatchNavigationAction(AppRouter::pop) }, ), ) } else -> { - dispatch(SendAction.Dialog.SendTransactionFails.BlockchainSdkError(error)) + dispatch( + SendAction.Dialog.SendTransactionFails.BlockchainSdkError( + error = error, + scanResponse = store.inject(DaggerGraphState::generalUserWalletsListManager) + .selectedUserWalletSync?.scanResponse + ?: error("ScanResponse must be not null"), + ), + ) } } } diff --git a/app/src/main/java/com/tangem/tap/features/send/redux/reducers/AmountReducer.kt b/app/src/main/java/com/tangem/tap/features/send/redux/reducers/AmountReducer.kt index 1f3b82b267..645fc6ec32 100644 --- a/app/src/main/java/com/tangem/tap/features/send/redux/reducers/AmountReducer.kt +++ b/app/src/main/java/com/tangem/tap/features/send/redux/reducers/AmountReducer.kt @@ -1,6 +1,5 @@ package com.tangem.tap.features.send.redux.reducers -import com.tangem.common.Strings.STARS import com.tangem.common.extensions.isZero import com.tangem.tap.common.extensions.stripZeroPlainString import com.tangem.tap.features.send.redux.AmountAction @@ -11,6 +10,7 @@ import com.tangem.tap.features.send.redux.states.AmountState import com.tangem.tap.features.send.redux.states.InputViewValue import com.tangem.tap.features.send.redux.states.MainCurrencyType import com.tangem.tap.features.send.redux.states.SendState +import com.tangem.utils.StringsSigns.STARS import java.math.BigDecimal /** diff --git a/app/src/main/java/com/tangem/tap/features/send/redux/reducers/ReceiptReducer.kt b/app/src/main/java/com/tangem/tap/features/send/redux/reducers/ReceiptReducer.kt index dbf1db4f40..8d1d46d4cd 100644 --- a/app/src/main/java/com/tangem/tap/features/send/redux/reducers/ReceiptReducer.kt +++ b/app/src/main/java/com/tangem/tap/features/send/redux/reducers/ReceiptReducer.kt @@ -10,6 +10,7 @@ import com.tangem.tap.features.send.redux.ReceiptAction.RefreshReceipt import com.tangem.tap.features.send.redux.SendScreenAction import com.tangem.tap.features.send.redux.states.* import com.tangem.tap.store +import com.tangem.utils.StringsSigns.LOWER_SIGN import java.math.BigDecimal /** @@ -401,11 +402,7 @@ class ReceiptReducer : SendInternalReducer { } private fun String.addPrecisionSign(): String { - val result = if (feeState.feeIsApproximate) "$CAN_BE_LOWER_SIGN $this" else this + val result = if (feeState.feeIsApproximate) "$LOWER_SIGN $this" else this return result.trim() } - - private companion object { - const val CAN_BE_LOWER_SIGN = "<" - } } \ No newline at end of file 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 d3d3cd7e19..115ab92034 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 @@ -4,8 +4,8 @@ import com.tangem.blockchain.common.Amount import com.tangem.blockchain.common.AmountType import com.tangem.blockchain.common.WalletManager import com.tangem.common.extensions.isZero -import com.tangem.core.navigation.StateDialog import com.tangem.domain.appcurrency.model.AppCurrency +import com.tangem.domain.redux.StateDialog import com.tangem.domain.tokens.model.CryptoCurrency import com.tangem.tap.common.CurrencyConverter import com.tangem.tap.common.entities.IndeterminateProgressButton 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 fd6d7105d3..34650ad800 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 @@ -8,7 +8,6 @@ import android.text.method.DigitsKeyListener import android.view.View import android.view.inputmethod.EditorInfo import android.widget.EditText -import androidx.core.os.bundleOf import androidx.core.view.postDelayed import androidx.core.widget.addTextChangedListener import androidx.fragment.app.viewModels @@ -20,19 +19,18 @@ import androidx.recyclerview.widget.RecyclerView import by.kirich1409.viewbindingdelegate.viewBinding import com.google.android.material.textfield.TextInputEditText import com.tangem.Message +import com.tangem.common.routing.AppRoute +import com.tangem.common.routing.AppRouter import com.tangem.core.analytics.Analytics -import com.tangem.core.navigation.AppScreen -import com.tangem.core.navigation.NavigationAction import com.tangem.domain.appcurrency.model.AppCurrency import com.tangem.domain.qrscanning.models.SourceType import com.tangem.domain.qrscanning.usecases.ListenToQrScanningUseCase import com.tangem.domain.qrscanning.usecases.ParseQrCodeUseCase import com.tangem.domain.tokens.legacy.TradeCryptoAction -import com.tangem.feature.qrscanning.QrScanningRouter import com.tangem.sdk.extensions.hideSoftKeyboard import com.tangem.tap.common.KeyboardObserver import com.tangem.tap.common.analytics.events.Token -import com.tangem.tap.common.extensions.dispatchOnMain +import com.tangem.tap.common.extensions.dispatchNavigationAction import com.tangem.tap.common.extensions.getFromClipboard import com.tangem.tap.common.extensions.setOnImeActionListener import com.tangem.tap.common.recyclerView.SpaceItemDecoration @@ -162,14 +160,9 @@ class SendFragment : BaseStoreFragment(R.layout.fragment_send) { imvQrCode.setOnClickListener { Analytics.send(Token.Send.ButtonQRCode()) - store.dispatchOnMain( - NavigationAction.NavigateTo( - screen = AppScreen.QrScanning, - bundle = bundleOf( - QrScanningRouter.SOURCE_KEY to SourceType.SEND, - ), - ), - ) + store.dispatchNavigationAction { + push(AppRoute.QrScanning(source = SourceType.SEND)) + } } } @@ -370,7 +363,7 @@ class SendFragment : BaseStoreFragment(R.layout.fragment_send) { override fun handleOnBackPressed() { val externalTransactionData = store.state.sendState.externalTransactionData if (externalTransactionData == null) { - store.dispatch(NavigationAction.PopBackTo()) + store.dispatchNavigationAction(AppRouter::pop) } else { store.dispatch(TradeCryptoAction.FinishSelling(externalTransactionData.transactionId)) } diff --git a/app/src/main/java/com/tangem/tap/features/send/ui/SendViewModel.kt b/app/src/main/java/com/tangem/tap/features/send/ui/SendViewModel.kt index 9f59533686..881e9f6df2 100644 --- a/app/src/main/java/com/tangem/tap/features/send/ui/SendViewModel.kt +++ b/app/src/main/java/com/tangem/tap/features/send/ui/SendViewModel.kt @@ -2,6 +2,7 @@ package com.tangem.tap.features.send.ui import androidx.lifecycle.* import arrow.core.getOrElse +import com.tangem.common.routing.AppRoute import com.tangem.domain.balancehiding.GetBalanceHidingSettingsUseCase import com.tangem.domain.qrscanning.models.SourceType import com.tangem.domain.qrscanning.usecases.ListenToQrScanningUseCase @@ -12,7 +13,6 @@ import com.tangem.domain.tokens.model.CryptoCurrency import com.tangem.domain.tokens.model.Network import com.tangem.domain.wallets.models.UserWallet import com.tangem.domain.wallets.usecase.GetSelectedWalletSyncUseCase -import com.tangem.features.send.api.navigation.SendRouter import com.tangem.tap.common.analytics.events.Token import com.tangem.tap.di.DelayedWork import com.tangem.tap.features.send.redux.AddressActionUi @@ -52,7 +52,7 @@ internal class SendViewModel @Inject constructor( .launchIn(viewModelScope) } - private val cryptoCurrency: CryptoCurrency? = savedStateHandle[SendRouter.CRYPTO_CURRENCY_KEY] + private val cryptoCurrency: CryptoCurrency? = savedStateHandle[AppRoute.Send.CRYPTO_CURRENCY_KEY] override fun onCreate(owner: LifecycleOwner) { getBalanceHidingSettingsUseCase() diff --git a/app/src/main/java/com/tangem/tap/features/send/ui/dialogs/RequestFeeErrorDialog.kt b/app/src/main/java/com/tangem/tap/features/send/ui/dialogs/RequestFeeErrorDialog.kt index cf27394348..bb8a5ea183 100644 --- a/app/src/main/java/com/tangem/tap/features/send/ui/dialogs/RequestFeeErrorDialog.kt +++ b/app/src/main/java/com/tangem/tap/features/send/ui/dialogs/RequestFeeErrorDialog.kt @@ -23,7 +23,12 @@ object RequestFeeErrorDialog { setMessage(context.getString(R.string.alert_failed_to_send_transaction_message, errorMessage)) setNegativeButton(R.string.details_row_title_contact_to_support) { _, _ -> Analytics.send(Basic.ButtonSupport(AnalyticsParam.ScreensSources.Send)) - store.dispatch(GlobalAction.SendEmail(SendTransactionFailedEmail(errorMessage))) + store.dispatch( + GlobalAction.SendEmail( + feedbackData = SendTransactionFailedEmail(errorMessage), + scanResponse = dialog.scanResponse, + ), + ) } setPositiveButton(R.string.common_retry) { _, _ -> dialog.onRetry() } setNeutralButton(R.string.common_cancel) { _, _ -> } diff --git a/app/src/main/java/com/tangem/tap/features/send/ui/dialogs/SendTransactionFailsDialog.kt b/app/src/main/java/com/tangem/tap/features/send/ui/dialogs/SendTransactionFailsDialog.kt index 5687caa590..a768ea033b 100644 --- a/app/src/main/java/com/tangem/tap/features/send/ui/dialogs/SendTransactionFailsDialog.kt +++ b/app/src/main/java/com/tangem/tap/features/send/ui/dialogs/SendTransactionFailsDialog.kt @@ -8,6 +8,7 @@ import com.tangem.common.module.ModuleMessageConverter import com.tangem.core.analytics.Analytics import com.tangem.core.analytics.models.AnalyticsParam import com.tangem.core.analytics.models.Basic +import com.tangem.domain.models.scan.ScanResponse import com.tangem.sdk.extensions.localizedDescription import com.tangem.tap.common.extensions.stripZeroPlainString import com.tangem.tap.common.feedback.SendTransactionFailedEmail @@ -21,21 +22,21 @@ import com.tangem.wallet.R */ object SendTransactionFailsDialog { fun create(context: Context, dialog: SendAction.Dialog.SendTransactionFails.CardSdkError): AlertDialog { - return create(context, dialog.error.localizedDescription(context)) + return create(context, dialog.error.localizedDescription(context), dialog.scanResponse) } fun create(context: Context, dialog: SendAction.Dialog.SendTransactionFails.BlockchainSdkError): AlertDialog { val errorConverter = BlockchainSdkErrorConverter(context) - return create(context, errorConverter.convert(dialog.error)) + return create(context, errorConverter.convert(dialog.error), dialog.scanResponse) } - private fun create(context: Context, errorMessage: String): AlertDialog { + private fun create(context: Context, errorMessage: String, scanResponse: ScanResponse): AlertDialog { return AlertDialog.Builder(context).apply { setTitle(R.string.alert_failed_to_send_transaction_title) setMessage(context.getString(R.string.alert_failed_to_send_transaction_message, errorMessage)) setNeutralButton(R.string.details_row_title_contact_to_support) { _, _ -> Analytics.send(Basic.ButtonSupport(AnalyticsParam.ScreensSources.Send)) - store.dispatch(GlobalAction.SendEmail(SendTransactionFailedEmail(errorMessage))) + store.dispatch(GlobalAction.SendEmail(SendTransactionFailedEmail(errorMessage), scanResponse)) } setPositiveButton(R.string.common_cancel) { _, _ -> } setOnDismissListener { store.dispatch(SendAction.Dialog.Hide) } diff --git a/app/src/main/java/com/tangem/tap/features/tokens/impl/presentation/TokensListFragment.kt b/app/src/main/java/com/tangem/tap/features/tokens/impl/presentation/TokensListFragment.kt index 272c773c95..ed260691fe 100644 --- a/app/src/main/java/com/tangem/tap/features/tokens/impl/presentation/TokensListFragment.kt +++ b/app/src/main/java/com/tangem/tap/features/tokens/impl/presentation/TokensListFragment.kt @@ -1,13 +1,10 @@ package com.tangem.tap.features.tokens.impl.presentation -import androidx.compose.foundation.layout.systemBarsPadding import androidx.compose.runtime.Composable import androidx.compose.ui.Modifier import androidx.compose.ui.platform.LocalLifecycleOwner import androidx.hilt.navigation.compose.hiltViewModel import com.tangem.core.ui.UiDependencies -import com.tangem.core.ui.components.SystemBarsEffect -import com.tangem.core.ui.res.TangemTheme import com.tangem.core.ui.screen.ComposeFragment import com.tangem.tap.features.tokens.impl.presentation.ui.TokensListScreen import com.tangem.tap.features.tokens.impl.presentation.viewmodels.TokensListViewModel @@ -30,12 +27,7 @@ internal class TokensListFragment : ComposeFragment() { val viewModel = hiltViewModel().apply { LocalLifecycleOwner.current.lifecycle.addObserver(this) } - val statusBarColor = TangemTheme.colors.background.secondary - SystemBarsEffect { - setSystemBarsColor(color = statusBarColor) - } TokensListScreen( - modifier = Modifier.systemBarsPadding(), stateHolder = viewModel.uiState, ) } diff --git a/app/src/main/java/com/tangem/tap/features/tokens/impl/presentation/router/DefaultTokensListRouter.kt b/app/src/main/java/com/tangem/tap/features/tokens/impl/presentation/router/DefaultTokensListRouter.kt index f401253e1e..987034d99b 100644 --- a/app/src/main/java/com/tangem/tap/features/tokens/impl/presentation/router/DefaultTokensListRouter.kt +++ b/app/src/main/java/com/tangem/tap/features/tokens/impl/presentation/router/DefaultTokensListRouter.kt @@ -1,9 +1,11 @@ package com.tangem.tap.features.tokens.impl.presentation.router import com.tangem.blockchain.common.Blockchain -import com.tangem.core.navigation.AppScreen -import com.tangem.core.navigation.NavigationAction +import com.tangem.common.routing.AppRoute +import com.tangem.common.routing.AppRouter + import com.tangem.tap.common.extensions.dispatchDialogShow +import com.tangem.tap.common.extensions.dispatchNavigationAction import com.tangem.tap.common.extensions.dispatchNotification import com.tangem.tap.common.redux.AppDialog import com.tangem.tap.store @@ -18,11 +20,11 @@ import com.tangem.wallet.R internal class DefaultTokensListRouter : TokensListRouter { override fun popBackStack() { - store.dispatch(NavigationAction.PopBackTo()) + store.dispatchNavigationAction(AppRouter::pop) } override fun openAddCustomTokenScreen() { - store.dispatch(NavigationAction.NavigateTo(AppScreen.AddCustomToken)) + store.dispatchNavigationAction { push(AppRoute.AddCustomToken) } } override fun showAddressCopiedNotification() { @@ -58,7 +60,7 @@ internal class DefaultTokensListRouter : TokensListRouter { val alert = AppDialog.SimpleOkDialogRes( headerId = R.string.common_error, messageId = R.string.common_unknown_error, - onOk = { store.dispatch(NavigationAction.PopBackTo()) }, + onOk = { store.dispatchNavigationAction(AppRouter::pop) }, ) store.dispatchDialogShow(alert) } diff --git a/app/src/main/java/com/tangem/tap/features/tokens/impl/presentation/ui/BriefNetworksList.kt b/app/src/main/java/com/tangem/tap/features/tokens/impl/presentation/ui/BriefNetworksList.kt index e122327ff8..4091e53c06 100644 --- a/app/src/main/java/com/tangem/tap/features/tokens/impl/presentation/ui/BriefNetworksList.kt +++ b/app/src/main/java/com/tangem/tap/features/tokens/impl/presentation/ui/BriefNetworksList.kt @@ -4,7 +4,10 @@ import androidx.compose.animation.AnimatedVisibility import androidx.compose.animation.fadeIn import androidx.compose.animation.fadeOut import androidx.compose.foundation.background -import androidx.compose.foundation.layout.* +import androidx.compose.foundation.layout.Arrangement +import androidx.compose.foundation.layout.Box +import androidx.compose.foundation.layout.Row +import androidx.compose.foundation.layout.size import androidx.compose.foundation.shape.CircleShape import androidx.compose.material.Icon import androidx.compose.material.Text @@ -123,14 +126,14 @@ internal fun HasMoreItem(moreCount: Int) { ) { Text( modifier = Modifier - .padding(TangemTheme.dimens.spacing4) .align(Alignment.Center) .drawWithContent { if (readyToDraw) drawContent() }, text = "+$count", style = textStyle, + color = TangemTheme.colors.text.tertiary, overflow = TextOverflow.Clip, onTextLayout = { textLayoutResult -> - if (textLayoutResult.didOverflowHeight) { + if (textLayoutResult.hasVisualOverflow) { textStyle = textStyle.copy(fontSize = textStyle.fontSize * 0.9) } else { readyToDraw = true diff --git a/app/src/main/java/com/tangem/tap/features/tokens/impl/presentation/ui/TokensListScreen.kt b/app/src/main/java/com/tangem/tap/features/tokens/impl/presentation/ui/TokensListScreen.kt index 56366dfb51..d045437bb8 100644 --- a/app/src/main/java/com/tangem/tap/features/tokens/impl/presentation/ui/TokensListScreen.kt +++ b/app/src/main/java/com/tangem/tap/features/tokens/impl/presentation/ui/TokensListScreen.kt @@ -15,7 +15,6 @@ import androidx.compose.material.Scaffold import androidx.compose.material.Text import androidx.compose.runtime.* import androidx.compose.ui.Alignment -import androidx.compose.ui.ExperimentalComposeUiApi import androidx.compose.ui.Modifier import androidx.compose.ui.layout.onSizeChanged import androidx.compose.ui.platform.LocalDensity @@ -34,6 +33,8 @@ import androidx.paging.compose.LazyPagingItems import androidx.paging.compose.collectAsLazyPagingItems import androidx.paging.compose.itemContentType import androidx.paging.compose.itemKey +import com.tangem.core.ui.components.BottomFade +import com.tangem.core.ui.components.NavigationBar3ButtonsScrim import com.tangem.core.ui.components.PrimaryButton import com.tangem.core.ui.res.TangemThemePreview import com.tangem.core.ui.res.TangemTheme @@ -61,32 +62,45 @@ internal fun TokensListScreen(stateHolder: TokensListStateHolder, modifier: Modi Scaffold( modifier = modifier, - topBar = { TokensListToolbar(state = stateHolder.toolbarState) }, + topBar = { + TokensListToolbar(state = stateHolder.toolbarState) + }, floatingActionButton = { if (stateHolder is TokensListStateHolder.ManageContent) { val density = LocalDensity.current val verticalPadding = TangemTheme.dimens.spacing32 SaveChangesButton( - modifier = Modifier.onSizeChanged { - with(density) { floatingButtonHeight = it.height.toDp() + verticalPadding } - }, + modifier = Modifier + .navigationBarsPadding() + .onSizeChanged { + with(density) { floatingButtonHeight = it.height.toDp() + verticalPadding } + }, showProgress = stateHolder.isSavingInProgress, onClick = stateHolder.onSaveButtonClick, ) } }, floatingActionButtonPosition = FabPosition.Center, - backgroundColor = TangemTheme.colors.background.primary, - ) { scaffoldPadding -> + backgroundColor = TangemTheme.colors.background.secondary, + ) { _ -> val tokens = stateHolder.tokens.collectAsLazyPagingItems() - TokensListContent( - isDifferentAddressesBlockVisible = stateHolder.isDifferentAddressesBlockVisible, - tokens = tokens, - scaffoldPadding = scaffoldPadding, - bottomMarginDp = floatingButtonHeight, - ) + if (stateHolder !is TokensListStateHolder.ManageContent) { + NavigationBar3ButtonsScrim() + } + + Box { + TokensListContent( + isDifferentAddressesBlockVisible = stateHolder.isDifferentAddressesBlockVisible, + tokens = tokens, + bottomMarginDp = floatingButtonHeight, + ) + + if (stateHolder is TokensListStateHolder.ManageContent) { + BottomFade(Modifier.align(Alignment.BottomCenter)) + } + } Crossfade(targetState = stateHolder.isLoading, label = "Update progress bar visibility") { if (it) { @@ -112,23 +126,24 @@ private fun LoadingContent() { } } -@OptIn(ExperimentalComposeUiApi::class) @Composable private fun TokensListContent( isDifferentAddressesBlockVisible: Boolean, tokens: LazyPagingItems, - scaffoldPadding: PaddingValues, bottomMarginDp: Dp, ) { val state = rememberLazyListState() + val bottomBarHeight = with(LocalDensity.current) { WindowInsets.systemBars.getBottom(this).toDp() } LazyColumn( modifier = Modifier + .background(color = TangemTheme.colors.background.primary) .imePadding() - .fillMaxSize() - .padding(scaffoldPadding), + .fillMaxSize(), state = state, - contentPadding = PaddingValues(bottom = bottomMarginDp), + contentPadding = PaddingValues( + bottom = bottomMarginDp + bottomBarHeight, + ), ) { item( key = "DifferentAddressesWarning$isDifferentAddressesBlockVisible", diff --git a/app/src/main/java/com/tangem/tap/features/tokens/impl/presentation/ui/TokensListToolbar.kt b/app/src/main/java/com/tangem/tap/features/tokens/impl/presentation/ui/TokensListToolbar.kt index 5e0aafc999..0a4dd9c309 100644 --- a/app/src/main/java/com/tangem/tap/features/tokens/impl/presentation/ui/TokensListToolbar.kt +++ b/app/src/main/java/com/tangem/tap/features/tokens/impl/presentation/ui/TokensListToolbar.kt @@ -1,10 +1,7 @@ package com.tangem.tap.features.tokens.impl.presentation.ui import androidx.compose.foundation.isSystemInDarkTheme -import androidx.compose.foundation.layout.Arrangement -import androidx.compose.foundation.layout.Box -import androidx.compose.foundation.layout.Row -import androidx.compose.foundation.layout.padding +import androidx.compose.foundation.layout.* import androidx.compose.foundation.text.BasicTextField import androidx.compose.foundation.text.KeyboardActions import androidx.compose.foundation.text.KeyboardOptions @@ -16,6 +13,7 @@ import androidx.compose.ui.Modifier import androidx.compose.ui.focus.FocusRequester import androidx.compose.ui.focus.focusRequester import androidx.compose.ui.graphics.SolidColor +import androidx.compose.ui.platform.LocalDensity import androidx.compose.ui.platform.LocalSoftwareKeyboardController import androidx.compose.ui.res.painterResource import androidx.compose.ui.res.stringResource @@ -42,8 +40,15 @@ internal fun TokensListToolbar(state: TokensListToolbarState) { } else { AppBarDefaults.TopAppBarElevation } + val statusBarHeight = with(LocalDensity.current) { WindowInsets.systemBars.getTop(this).toDp() } + TopAppBar( backgroundColor = TangemTheme.colors.background.secondary, + contentPadding = PaddingValues( + start = TangemTheme.dimens.spacing4, + end = TangemTheme.dimens.spacing4, + top = statusBarHeight, + ), elevation = toolbarElevation, ) { IconButton(onClick = state.onBackButtonClick) { diff --git a/app/src/main/java/com/tangem/tap/features/tokens/impl/presentation/viewmodels/TokensListMigration.kt b/app/src/main/java/com/tangem/tap/features/tokens/impl/presentation/viewmodels/TokensListMigration.kt index 050dc5f876..41495924b3 100644 --- a/app/src/main/java/com/tangem/tap/features/tokens/impl/presentation/viewmodels/TokensListMigration.kt +++ b/app/src/main/java/com/tangem/tap/features/tokens/impl/presentation/viewmodels/TokensListMigration.kt @@ -3,8 +3,8 @@ package com.tangem.tap.features.tokens.impl.presentation.viewmodels import arrow.core.Either import com.tangem.blockchain.common.Blockchain import com.tangem.blockchain.common.Token -import com.tangem.core.navigation.AppScreen -import com.tangem.core.navigation.NavigationAction +import com.tangem.common.routing.AppRoute +import com.tangem.common.routing.utils.popTo import com.tangem.data.tokens.utils.CryptoCurrencyFactory import com.tangem.domain.card.DerivePublicKeysUseCase import com.tangem.domain.common.util.derivationStyleProvider @@ -16,7 +16,7 @@ import com.tangem.domain.wallets.models.UserWallet import com.tangem.domain.wallets.models.UserWalletId import com.tangem.domain.wallets.usecase.GetSelectedWalletSyncUseCase import com.tangem.tap.common.extensions.dispatchDebugErrorNotification -import com.tangem.tap.common.extensions.dispatchWithMain +import com.tangem.tap.common.extensions.dispatchNavigationAction import com.tangem.tap.common.extensions.inject import com.tangem.tap.proxy.redux.DaggerGraphState import com.tangem.tap.store @@ -126,7 +126,7 @@ internal class TokensListMigration( val isNothingToDoWithBlockchain = blockchainsToAdd.isEmpty() && blockchainsToRemove.isEmpty() if (isNothingToDoWithTokens && isNothingToDoWithBlockchain) { store.dispatchDebugErrorNotification(message = "Nothing to save") - store.dispatchWithMain(NavigationAction.PopBackTo(screen = AppScreen.Wallet)) + store.dispatchNavigationAction { popTo() } return } @@ -135,6 +135,7 @@ internal class TokensListMigration( derivePublicKeysUseCase(userWalletId = currentUserWallet.walletId, currencies = currencyList) .onRight { addCryptoCurrenciesUseCase(userWalletId = currentUserWallet.walletId, currencies = currencyList) + store.dispatchNavigationAction { popTo() } } .onLeft { Timber.e(it, "Failed to derive public keys") } } diff --git a/app/src/main/java/com/tangem/tap/features/tokens/impl/presentation/viewmodels/TokensListViewModel.kt b/app/src/main/java/com/tangem/tap/features/tokens/impl/presentation/viewmodels/TokensListViewModel.kt index 4874bc303c..6e471d192d 100644 --- a/app/src/main/java/com/tangem/tap/features/tokens/impl/presentation/viewmodels/TokensListViewModel.kt +++ b/app/src/main/java/com/tangem/tap/features/tokens/impl/presentation/viewmodels/TokensListViewModel.kt @@ -12,8 +12,6 @@ import androidx.paging.* import com.tangem.blockchain.common.Blockchain import com.tangem.blockchainsdk.utils.fromNetworkId import com.tangem.core.analytics.api.AnalyticsEventHandler -import com.tangem.core.navigation.AppScreen -import com.tangem.core.navigation.NavigationAction import com.tangem.core.ui.extensions.getActiveIconRes import com.tangem.core.ui.extensions.getGreyedOutIconRes import com.tangem.domain.card.DerivePublicKeysUseCase @@ -26,7 +24,6 @@ import com.tangem.domain.tokens.AddCryptoCurrenciesUseCase import com.tangem.domain.tokens.GetCryptoCurrenciesUseCase import com.tangem.domain.tokens.TokenWithBlockchain import com.tangem.domain.wallets.usecase.GetSelectedWalletSyncUseCase -import com.tangem.tap.common.extensions.dispatchWithMain import com.tangem.tap.common.extensions.fullNameWithoutTestnet import com.tangem.tap.common.extensions.getNetworkName import com.tangem.tap.features.customtoken.impl.presentation.models.SupportBlockchainType @@ -326,7 +323,6 @@ internal class TokensListViewModel @Inject constructor( ) uiState = state.copy(isSavingInProgress = false) - store.dispatchWithMain(NavigationAction.PopBackTo(screen = AppScreen.Wallet)) } } diff --git a/app/src/main/java/com/tangem/tap/features/wallet/redux/middlewares/TradeCryptoMiddleware.kt b/app/src/main/java/com/tangem/tap/features/wallet/redux/middlewares/TradeCryptoMiddleware.kt index 39a0168df7..abb2a86125 100644 --- a/app/src/main/java/com/tangem/tap/features/wallet/redux/middlewares/TradeCryptoMiddleware.kt +++ b/app/src/main/java/com/tangem/tap/features/wallet/redux/middlewares/TradeCryptoMiddleware.kt @@ -1,18 +1,17 @@ package com.tangem.tap.features.wallet.redux.middlewares -import androidx.core.os.bundleOf import com.google.firebase.crashlytics.FirebaseCrashlytics import com.tangem.blockchain.blockchains.ethereum.EthereumWalletManager import com.tangem.blockchain.common.AmountType import com.tangem.blockchain.common.Blockchain +import com.tangem.common.routing.AppRoute +import com.tangem.common.routing.AppRouter import com.tangem.core.analytics.Analytics -import com.tangem.core.navigation.AppScreen -import com.tangem.core.navigation.NavigationAction +import com.tangem.domain.staking.model.stakekit.Yield import com.tangem.domain.tokens.legacy.TradeCryptoAction import com.tangem.domain.tokens.model.CryptoCurrency import com.tangem.domain.tokens.model.NetworkAddress -import com.tangem.feature.swap.presentation.SwapFragment -import com.tangem.features.send.api.navigation.SendRouter +import com.tangem.domain.wallets.models.UserWalletId import com.tangem.tap.common.analytics.events.Token import com.tangem.tap.common.apptheme.MutableAppThemeModeHolder import com.tangem.tap.common.extensions.* @@ -58,6 +57,11 @@ object TradeCryptoMiddleware { is TradeCryptoAction.Buy -> proceedBuyAction(state, action) is TradeCryptoAction.Sell -> proceedSellAction(action) is TradeCryptoAction.Swap -> openSwap(currency = action.cryptoCurrency) + is TradeCryptoAction.Stake -> openStaking( + userWalletId = action.userWalletId, + cryptoCurrencyId = action.cryptoCurrencyId, + yield = action.yield, + ) is TradeCryptoAction.SendToken -> { if (isSendRedesignedEnabled) { handleNewSendToken(action = action) @@ -150,7 +154,7 @@ object TradeCryptoMiddleware { } private fun openReceiptUrl(transactionId: String) { - store.dispatchOnMain(NavigationAction.PopBackTo()) + store.dispatchNavigationAction(AppRouter::pop) store.state.globalState.exchangeManager.getSellCryptoReceiptUrl( action = CurrencyExchangeManager.Action.Sell, transactionId = transactionId, @@ -158,11 +162,19 @@ object TradeCryptoMiddleware { } private fun openSwap(currency: CryptoCurrency) { - val bundle = bundleOf( - SwapFragment.CURRENCY_BUNDLE_KEY to currency, - ) + store.dispatchNavigationAction { push(AppRoute.Swap(currency = currency)) } + } - store.dispatchOnMain(NavigationAction.NavigateTo(screen = AppScreen.Swap, bundle = bundle)) + private fun openStaking(userWalletId: UserWalletId, cryptoCurrencyId: CryptoCurrency.ID, yield: Yield) { + store.dispatchNavigationAction { + push( + AppRoute.Staking( + userWalletId = userWalletId, + cryptoCurrencyId = cryptoCurrencyId, + yield = yield, + ), + ) + } } private fun handleSendToken(action: TradeCryptoAction.SendToken) { @@ -214,11 +226,12 @@ object TradeCryptoMiddleware { ) } - val bundle = bundleOf( - SendRouter.CRYPTO_CURRENCY_KEY to currency, - SendRouter.USER_WALLET_ID_KEY to action.userWallet.walletId.stringValue, + val route = AppRoute.Send( + currency = currency, + userWalletId = action.userWallet.walletId, ) - store.dispatchOnMain(NavigationAction.NavigateTo(screen = AppScreen.Send, bundle = bundle)) + + store.dispatchNavigationAction { push(route) } } } @@ -285,17 +298,17 @@ object TradeCryptoMiddleware { ) } - val bundle = bundleOf( - SendRouter.CRYPTO_CURRENCY_KEY to currency, - SendRouter.USER_WALLET_ID_KEY to action.userWallet.walletId.stringValue, + val route = AppRoute.Send( + currency = currency, + userWalletId = action.userWallet.walletId, ) - store.dispatchOnMain(NavigationAction.NavigateTo(screen = AppScreen.Send, bundle = bundle)) + store.dispatchNavigationAction { push(route) } } } private fun handleNewSendToken(action: TradeCryptoAction.SendToken) { handleNewSend( - userWalletId = action.userWallet.walletId.stringValue, + userWalletId = action.userWallet.walletId, txInfo = action.transactionInfo, currency = action.tokenCurrency, ) @@ -303,25 +316,26 @@ object TradeCryptoMiddleware { private fun handleNewSendCoin(action: TradeCryptoAction.SendCoin) { handleNewSend( - userWalletId = action.userWallet.walletId.stringValue, + userWalletId = action.userWallet.walletId, txInfo = action.transactionInfo, currency = action.coinStatus.currency, ) } private fun handleNewSend( - userWalletId: String, + userWalletId: UserWalletId, txInfo: TradeCryptoAction.TransactionInfo?, currency: CryptoCurrency, ) { - val bundle = bundleOf( - SendRouter.CRYPTO_CURRENCY_KEY to currency, - SendRouter.USER_WALLET_ID_KEY to userWalletId, - SendRouter.TRANSACTION_ID_KEY to txInfo?.transactionId, - SendRouter.DESTINATION_ADDRESS_KEY to txInfo?.destinationAddress, - SendRouter.AMOUNT_KEY to txInfo?.amount, - SendRouter.TAG_KEY to txInfo?.tag, + val route = AppRoute.Send( + currency = currency, + userWalletId = userWalletId, + transactionId = txInfo?.transactionId, + destinationAddress = txInfo?.destinationAddress, + amount = txInfo?.amount, + tag = txInfo?.tag, ) - store.dispatchOnMain(NavigationAction.NavigateTo(screen = AppScreen.Send, bundle = bundle)) + + store.dispatchNavigationAction { push(route) } } } \ No newline at end of file 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 abfc205397..2a564e8a0d 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 @@ -6,11 +6,12 @@ import com.tangem.common.doOnFailure import com.tangem.common.doOnResult import com.tangem.common.doOnSuccess import com.tangem.common.flatMap +import com.tangem.common.routing.AppRoute +import com.tangem.common.routing.utils.popTo import com.tangem.core.analytics.Analytics import com.tangem.core.analytics.models.AnalyticsParam import com.tangem.core.analytics.models.Basic -import com.tangem.core.navigation.AppScreen -import com.tangem.core.navigation.NavigationAction + import com.tangem.domain.common.util.cardTypesResolver import com.tangem.domain.models.scan.ScanResponse import com.tangem.domain.wallets.builder.UserWalletBuilder @@ -98,7 +99,7 @@ internal class WelcomeMiddleware { signInType = Basic.SignedIn.SignInType.Biometric, ) - store.dispatchWithMain(NavigationAction.NavigateTo(AppScreen.Wallet)) + store.dispatchNavigationAction { push(AppRoute.Wallet) } store.dispatchWithMain(WelcomeAction.ProceedWithBiometrics.Success) store.onUserWalletSelected(userWallet = selectedUserWallet) @@ -130,7 +131,7 @@ internal class WelcomeMiddleware { .doOnSuccess { sendSignedInAnalyticsEvent(scanResponse = scanResponse, signInType = Basic.SignedIn.SignInType.Card) - store.dispatchWithMain(NavigationAction.NavigateTo(AppScreen.Wallet)) + store.dispatchNavigationAction { push(AppRoute.Wallet) } store.dispatchWithMain(WelcomeAction.ProceedWithCard.Success) store.onUserWalletSelected(userWallet = userWallet) @@ -170,7 +171,7 @@ internal class WelcomeMiddleware { } .doOnResult { store.dispatchWithMain(WelcomeAction.CloseError) - store.dispatchWithMain(NavigationAction.PopBackTo(AppScreen.Home)) + store.dispatchNavigationAction { popTo() } } } diff --git a/app/src/main/java/com/tangem/tap/features/welcome/ui/WelcomeFragment.kt b/app/src/main/java/com/tangem/tap/features/welcome/ui/WelcomeFragment.kt index 60ab61900f..c34497d9f0 100644 --- a/app/src/main/java/com/tangem/tap/features/welcome/ui/WelcomeFragment.kt +++ b/app/src/main/java/com/tangem/tap/features/welcome/ui/WelcomeFragment.kt @@ -16,7 +16,6 @@ import androidx.hilt.navigation.compose.hiltViewModel import androidx.lifecycle.compose.collectAsStateWithLifecycle import com.tangem.core.analytics.Analytics import com.tangem.core.ui.UiDependencies -import com.tangem.core.ui.components.SystemBarsEffect import com.tangem.core.ui.res.TangemTheme import com.tangem.core.ui.screen.ComposeFragment import com.tangem.tap.common.analytics.events.SignIn @@ -49,19 +48,14 @@ internal class WelcomeFragment : ComposeFragment() { val errorMessage by rememberUpdatedState(newValue = state.error?.resolveReference()) val warning by rememberUpdatedState(newValue = state.warning) - val backgroundColor = TangemTheme.colors.background.primary - SystemBarsEffect { - setSystemBarsColor(backgroundColor) - } - BackHandler { requireActivity().finish() } Box( modifier = modifier - .systemBarsPadding() - .background(backgroundColor), + .background(TangemTheme.colors.background.primary) + .systemBarsPadding(), ) { WelcomeScreenContent( showUnlockProgress = state.showUnlockWithBiometricsProgress, @@ -88,8 +82,4 @@ internal class WelcomeFragment : ComposeFragment() { } } } - - internal companion object { - const val INITIAL_INTENT_KEY = "intent" - } } \ No newline at end of file diff --git a/app/src/main/java/com/tangem/tap/features/welcome/ui/WelcomeViewModel.kt b/app/src/main/java/com/tangem/tap/features/welcome/ui/WelcomeViewModel.kt index bc672b7c2f..0ecd71bd5d 100644 --- a/app/src/main/java/com/tangem/tap/features/welcome/ui/WelcomeViewModel.kt +++ b/app/src/main/java/com/tangem/tap/features/welcome/ui/WelcomeViewModel.kt @@ -1,8 +1,11 @@ package com.tangem.tap.features.welcome.ui -import android.content.Intent +import android.os.Bundle import androidx.lifecycle.* import com.tangem.common.core.TangemError +import com.tangem.common.routing.AppRoute +import com.tangem.common.routing.bundle.unbundle +import com.tangem.common.routing.entity.SerializableIntent import com.tangem.core.analytics.Analytics import com.tangem.domain.wallets.legacy.UserWalletsListError import com.tangem.tap.common.analytics.events.SignIn @@ -26,7 +29,8 @@ internal class WelcomeViewModel @Inject constructor( StoreSubscriber, DefaultLifecycleObserver { - private val initialIntent: Intent? = savedStateHandle[WelcomeFragment.INITIAL_INTENT_KEY] + private val initialIntent: SerializableIntent? = savedStateHandle.get(AppRoute.Welcome.INITIAL_INTENT_KEY) + ?.unbundle(SerializableIntent.serializer()) private val stateInternal = MutableStateFlow(WelcomeScreenState()) val state: StateFlow = stateInternal @@ -38,7 +42,7 @@ internal class WelcomeViewModel @Inject constructor( initGlobalState() val welcomeAction = if (initialIntent != null) { - WelcomeAction.ProceedWithIntent(initialIntent) + WelcomeAction.ProceedWithIntent(initialIntent.toIntent()) } else { WelcomeAction.ProceedWithBiometrics() } diff --git a/app/src/main/java/com/tangem/tap/network/auth/DefaultStakeKitAuthProvider.kt b/app/src/main/java/com/tangem/tap/network/auth/DefaultStakeKitAuthProvider.kt index 7e953fdfd5..a5ef219c9b 100644 --- a/app/src/main/java/com/tangem/tap/network/auth/DefaultStakeKitAuthProvider.kt +++ b/app/src/main/java/com/tangem/tap/network/auth/DefaultStakeKitAuthProvider.kt @@ -8,6 +8,6 @@ internal class DefaultStakeKitAuthProvider( ) : StakeKitAuthProvider { override fun getApiKey(): String { - return configManager.config.express?.apiKey ?: error("No StakeKit api key provided") + return configManager.config.stakeKitApiKey ?: error("No StakeKit api key provided") } } \ No newline at end of file diff --git a/app/src/main/java/com/tangem/tap/network/exchangeServices/BuyExchangeService.kt b/app/src/main/java/com/tangem/tap/network/exchangeServices/BuyExchangeService.kt index e6c523e666..a8861eed2f 100644 --- a/app/src/main/java/com/tangem/tap/network/exchangeServices/BuyExchangeService.kt +++ b/app/src/main/java/com/tangem/tap/network/exchangeServices/BuyExchangeService.kt @@ -1,5 +1,6 @@ package com.tangem.tap.network.exchangeServices +import com.tangem.domain.models.scan.ScanResponse import com.tangem.domain.tokens.model.CryptoCurrency import com.tangem.tap.domain.model.Currency import com.tangem.tap.network.exchangeServices.mercuryo.MercuryoService @@ -32,7 +33,8 @@ internal class BuyExchangeService( override fun isSellAllowed(): Boolean = currentService.isSellAllowed() - override fun availableForBuy(currency: Currency): Boolean = currentService.availableForBuy(currency) + override fun availableForBuy(scanResponse: ScanResponse, currency: Currency): Boolean = + currentService.availableForBuy(scanResponse, currency) override fun availableForSell(currency: Currency): Boolean = currentService.availableForSell(currency) diff --git a/app/src/main/java/com/tangem/tap/network/exchangeServices/CardExchangeRules.kt b/app/src/main/java/com/tangem/tap/network/exchangeServices/CardExchangeRules.kt index 0f4fd42f7d..696f9288bc 100644 --- a/app/src/main/java/com/tangem/tap/network/exchangeServices/CardExchangeRules.kt +++ b/app/src/main/java/com/tangem/tap/network/exchangeServices/CardExchangeRules.kt @@ -2,6 +2,7 @@ package com.tangem.tap.network.exchangeServices import com.tangem.domain.common.TapWorkarounds.isStart2Coin import com.tangem.domain.models.scan.CardDTO +import com.tangem.domain.models.scan.ScanResponse import com.tangem.tap.domain.model.Currency import com.tangem.tap.features.demo.isDemoCard @@ -38,8 +39,8 @@ class CardExchangeRules( } } - override fun availableForBuy(currency: Currency): Boolean { - val card = cardProvider() ?: return false + override fun availableForBuy(scanResponse: ScanResponse, currency: Currency): Boolean { + val card = scanResponse.card return when { card.isDemoCard() -> true diff --git a/app/src/main/java/com/tangem/tap/network/exchangeServices/CurrencyExchangeManager.kt b/app/src/main/java/com/tangem/tap/network/exchangeServices/CurrencyExchangeManager.kt index e962f7ebf4..fb01befe82 100644 --- a/app/src/main/java/com/tangem/tap/network/exchangeServices/CurrencyExchangeManager.kt +++ b/app/src/main/java/com/tangem/tap/network/exchangeServices/CurrencyExchangeManager.kt @@ -8,6 +8,7 @@ import com.tangem.blockchain.common.Blockchain import com.tangem.blockchain.common.transaction.TransactionFee import com.tangem.blockchain.extensions.Result import com.tangem.domain.models.scan.CardDTO +import com.tangem.domain.models.scan.ScanResponse import com.tangem.domain.tokens.model.CryptoCurrency import com.tangem.tap.common.extensions.inject import com.tangem.tap.common.extensions.safeUpdate @@ -38,8 +39,9 @@ class CurrencyExchangeManager( override fun isBuyAllowed(): Boolean = primaryRules.isBuyAllowed() && buyService.isBuyAllowed() override fun isSellAllowed(): Boolean = primaryRules.isSellAllowed() && sellService.isSellAllowed() - override fun availableForBuy(currency: Currency): Boolean { - return primaryRules.availableForBuy(currency) && buyService.availableForBuy(currency) + override fun availableForBuy(scanResponse: ScanResponse, currency: Currency): Boolean { + return primaryRules.availableForBuy(scanResponse, currency) && + buyService.availableForBuy(scanResponse, currency) } override fun availableForSell(currency: Currency): Boolean { diff --git a/app/src/main/java/com/tangem/tap/network/exchangeServices/DefaultRampManager.kt b/app/src/main/java/com/tangem/tap/network/exchangeServices/DefaultRampManager.kt index 76de7375da..904e22c80e 100644 --- a/app/src/main/java/com/tangem/tap/network/exchangeServices/DefaultRampManager.kt +++ b/app/src/main/java/com/tangem/tap/network/exchangeServices/DefaultRampManager.kt @@ -1,13 +1,15 @@ package com.tangem.tap.network.exchangeServices import com.tangem.domain.exchange.RampStateManager +import com.tangem.domain.models.scan.ScanResponse import com.tangem.domain.tokens.model.CryptoCurrency class DefaultRampManager(private val exchangeService: ExchangeService?) : RampStateManager { private val cryptoCurrencyConverter = CryptoCurrencyConverter() - override fun availableForBuy(cryptoCurrency: CryptoCurrency): Boolean { + override fun availableForBuy(scanResponse: ScanResponse, cryptoCurrency: CryptoCurrency): Boolean { return exchangeService?.availableForBuy( + scanResponse, currency = cryptoCurrencyConverter.convertBack(cryptoCurrency), ) ?: false } diff --git a/app/src/main/java/com/tangem/tap/network/exchangeServices/ExchangeService.kt b/app/src/main/java/com/tangem/tap/network/exchangeServices/ExchangeService.kt index e9b17488e3..1cfd8502ed 100644 --- a/app/src/main/java/com/tangem/tap/network/exchangeServices/ExchangeService.kt +++ b/app/src/main/java/com/tangem/tap/network/exchangeServices/ExchangeService.kt @@ -1,5 +1,6 @@ package com.tangem.tap.network.exchangeServices +import com.tangem.domain.models.scan.ScanResponse import com.tangem.domain.tokens.model.CryptoCurrency import com.tangem.tap.common.feature.Feature import com.tangem.tap.domain.model.Currency @@ -7,7 +8,7 @@ import com.tangem.tap.domain.model.Currency interface Exchanger { fun isBuyAllowed(): Boolean fun isSellAllowed(): Boolean - fun availableForBuy(currency: Currency): Boolean + fun availableForBuy(scanResponse: ScanResponse, currency: Currency): Boolean fun availableForSell(currency: Currency): Boolean } @@ -20,7 +21,7 @@ interface ExchangeService : Feature, Exchanger, ExchangeUrlBuilder { override suspend fun update() {} override fun isBuyAllowed(): Boolean = false override fun isSellAllowed(): Boolean = false - override fun availableForBuy(currency: Currency): Boolean = false + override fun availableForBuy(scanResponse: ScanResponse, currency: Currency): Boolean = false override fun availableForSell(currency: Currency): Boolean = false override fun getUrl( action: CurrencyExchangeManager.Action, @@ -45,7 +46,7 @@ interface ExchangeRules : Feature, Exchanger { override fun featureIsSwitchedOn(): Boolean = false override fun isBuyAllowed(): Boolean = false override fun isSellAllowed(): Boolean = false - override fun availableForBuy(currency: Currency): Boolean = false + override fun availableForBuy(scanResponse: ScanResponse, currency: Currency): Boolean = false override fun availableForSell(currency: Currency): Boolean = false } } diff --git a/app/src/main/java/com/tangem/tap/network/exchangeServices/mercuryo/MercuryoService.kt b/app/src/main/java/com/tangem/tap/network/exchangeServices/mercuryo/MercuryoService.kt index d653e2babe..8bcc8168e9 100644 --- a/app/src/main/java/com/tangem/tap/network/exchangeServices/mercuryo/MercuryoService.kt +++ b/app/src/main/java/com/tangem/tap/network/exchangeServices/mercuryo/MercuryoService.kt @@ -6,6 +6,7 @@ import com.tangem.common.extensions.calculateSha512 import com.tangem.common.extensions.toHexString import com.tangem.common.services.Result import com.tangem.common.services.performRequest +import com.tangem.domain.models.scan.ScanResponse import com.tangem.domain.tokens.model.CryptoCurrency import com.tangem.tap.domain.model.Currency import com.tangem.tap.network.exchangeServices.CurrencyExchangeManager @@ -28,7 +29,7 @@ internal class MercuryoService(private val environment: MercuryoEnvironment) : E override fun isSellAllowed(): Boolean = false - override fun availableForBuy(currency: Currency): Boolean { + override fun availableForBuy(scanResponse: ScanResponse, currency: Currency): Boolean { if (!isBuyAllowed()) return false val mercuryoNetwork = currency.blockchain.mercuryoNetwork() diff --git a/app/src/main/java/com/tangem/tap/network/exchangeServices/moonpay/MoonPayService.kt b/app/src/main/java/com/tangem/tap/network/exchangeServices/moonpay/MoonPayService.kt index c004c38b21..de34810420 100644 --- a/app/src/main/java/com/tangem/tap/network/exchangeServices/moonpay/MoonPayService.kt +++ b/app/src/main/java/com/tangem/tap/network/exchangeServices/moonpay/MoonPayService.kt @@ -7,6 +7,7 @@ import com.tangem.common.services.Result import com.tangem.common.services.performRequest import com.tangem.datasource.api.common.createRetrofitInstance import com.tangem.domain.common.extensions.withIOContext +import com.tangem.domain.models.scan.ScanResponse import com.tangem.domain.tokens.model.CryptoCurrency import com.tangem.tap.domain.model.Currency import com.tangem.tap.network.exchangeServices.CurrencyExchangeManager @@ -83,7 +84,7 @@ class MoonPayService( return status?.responseUserStatus?.isSellAllowed ?: false } - override fun availableForBuy(currency: Currency): Boolean = false + override fun availableForBuy(scanResponse: ScanResponse, currency: Currency): Boolean = false override fun availableForSell(currency: Currency): Boolean { if (!isSellAllowed()) return false diff --git a/app/src/main/java/com/tangem/tap/proxy/AppStateHolder.kt b/app/src/main/java/com/tangem/tap/proxy/AppStateHolder.kt index cf7de3bfe1..a2c9dd483f 100644 --- a/app/src/main/java/com/tangem/tap/proxy/AppStateHolder.kt +++ b/app/src/main/java/com/tangem/tap/proxy/AppStateHolder.kt @@ -1,18 +1,14 @@ package com.tangem.tap.proxy -import com.tangem.core.navigation.AppScreen -import com.tangem.core.navigation.NavigationAction -import com.tangem.core.navigation.ReduxNavController import com.tangem.domain.models.scan.CardDTO import com.tangem.domain.models.scan.ScanResponse import com.tangem.domain.redux.ReduxStateHolder +import com.tangem.domain.redux.StateDialog import com.tangem.domain.wallets.models.UserWallet -import com.tangem.tap.common.extensions.dispatchOnMain +import com.tangem.tap.common.extensions.dispatchDialogShow import com.tangem.tap.common.extensions.dispatchWithMain import com.tangem.tap.common.extensions.onUserWalletSelected -import com.tangem.tap.common.feedback.FeedbackEmail import com.tangem.tap.common.redux.AppState -import com.tangem.tap.common.redux.global.GlobalAction import com.tangem.tap.domain.sdk.TangemSdkManager import com.tangem.tap.network.exchangeServices.ExchangeService import org.rekotlin.Action @@ -23,7 +19,7 @@ import javax.inject.Inject * Holds objects from old modules, that missing in DI graph. * Object sets manually to use in new modules and [AppStateHolder] proxies its to DI. */ -class AppStateHolder @Inject constructor() : ReduxNavController, ReduxStateHolder { +class AppStateHolder @Inject constructor() : ReduxStateHolder { @Deprecated("Use scan response from selected user wallet") var scanResponse: ScanResponse? = null @@ -35,16 +31,6 @@ class AppStateHolder @Inject constructor() : ReduxNavController, ReduxStateHolde return scanResponse?.card } - override fun navigate(action: NavigationAction) { - mainStore?.dispatchOnMain(action) - } - - override fun getBackStack(): List = mainStore?.state?.navigationState?.backStack.orEmpty() - - override fun popBackStack(screen: AppScreen?) { - mainStore?.dispatchOnMain(NavigationAction.PopBackTo(screen)) - } - override fun dispatch(action: Action) { mainStore?.dispatch(action) } @@ -57,7 +43,7 @@ class AppStateHolder @Inject constructor() : ReduxNavController, ReduxStateHolde mainStore?.onUserWalletSelected(userWallet) } - override fun sendFeedbackEmail() { - mainStore?.dispatch(GlobalAction.SendEmail(FeedbackEmail())) + override fun dispatchDialogShow(dialog: StateDialog) { + mainStore?.dispatchDialogShow(dialog) } } \ No newline at end of file diff --git a/app/src/main/java/com/tangem/tap/proxy/TransactionManagerImpl.kt b/app/src/main/java/com/tangem/tap/proxy/TransactionManagerImpl.kt index 8177d10df8..cfd1fc53f2 100644 --- a/app/src/main/java/com/tangem/tap/proxy/TransactionManagerImpl.kt +++ b/app/src/main/java/com/tangem/tap/proxy/TransactionManagerImpl.kt @@ -1,37 +1,17 @@ package com.tangem.tap.proxy -import androidx.core.text.isDigitsOnly -import com.google.firebase.crashlytics.FirebaseCrashlytics -import com.tangem.Message -import com.tangem.blockchain.blockchains.algorand.AlgorandTransactionExtras -import com.tangem.blockchain.blockchains.binance.BinanceTransactionExtras -import com.tangem.blockchain.blockchains.cosmos.CosmosTransactionExtras -import com.tangem.blockchain.blockchains.ethereum.EthereumTransactionExtras import com.tangem.blockchain.blockchains.ethereum.EthereumWalletManager -import com.tangem.blockchain.blockchains.hedera.HederaTransactionExtras import com.tangem.blockchain.blockchains.optimism.EthereumOptimisticRollupWalletManager -import com.tangem.blockchain.blockchains.stellar.StellarMemo -import com.tangem.blockchain.blockchains.stellar.StellarTransactionExtras -import com.tangem.blockchain.blockchains.ton.TonTransactionExtras -import com.tangem.blockchain.blockchains.xrp.XrpTransactionBuilder import com.tangem.blockchain.common.* import com.tangem.blockchain.common.transaction.Fee import com.tangem.blockchain.common.transaction.TransactionFee -import com.tangem.blockchain.common.transaction.TransactionSendResult import com.tangem.blockchain.extensions.Result import com.tangem.blockchain.externallinkprovider.TxExploreState -import com.tangem.blockchain.network.ResultChecker import com.tangem.blockchainsdk.utils.fromNetworkId -import com.tangem.common.core.TangemSdkError -import com.tangem.common.extensions.hexToBytes -import com.tangem.domain.card.repository.CardSdkConfigRepository import com.tangem.domain.walletmanager.WalletManagersFacade import com.tangem.domain.wallets.legacy.UserWalletsListManager import com.tangem.lib.crypto.TransactionManager import com.tangem.lib.crypto.models.* -import com.tangem.lib.crypto.models.transactions.SendTxResult -import com.tangem.tap.common.redux.global.GlobalAction -import com.tangem.tap.domain.TangemSigner import java.math.BigDecimal import java.math.BigInteger import java.math.MathContext @@ -39,84 +19,10 @@ import java.math.RoundingMode @Suppress("LargeClass") class TransactionManagerImpl( - private val appStateHolder: AppStateHolder, - private val cardSdkConfigRepository: CardSdkConfigRepository, private val walletManagersFacade: WalletManagersFacade, private val userWalletsListManager: UserWalletsListManager, ) : TransactionManager { - override suspend fun sendApproveTransaction( - txData: ApproveTxData, - derivationPath: String?, - analyticsData: AnalyticsData, - ): SendTxResult { - val blockchain = requireNotNull(Blockchain.fromNetworkId(txData.networkId)) { "blockchain not found" } - val walletManager = getActualWalletManager(blockchain, derivationPath) - walletManager.update() - val amount = Amount(value = BigDecimal.ZERO, blockchain = blockchain) - return sendTransactionInternal( - walletManager = walletManager, - amount = amount, - blockchain = blockchain, - feeAmount = txData.feeAmount, - gasLimit = txData.gasLimit, - destinationAddress = txData.destinationAddress, - dataToSign = txData.dataToSign, - ) - } - - override suspend fun sendTransaction( - txData: SwapTxData, - isSwap: Boolean, - derivationPath: String?, - analyticsData: AnalyticsData, - ): SendTxResult { - val blockchain = requireNotNull(Blockchain.fromNetworkId(txData.networkId)) { "blockchain not found" } - val walletManager = getActualWalletManager(blockchain, derivationPath) - walletManager.update() - val amount = if (isSwap) { - createAmountForSwap(txData.amountToSend, txData.currencyToSend, blockchain) - } else { - createAmount(txData.amountToSend, txData.currencyToSend, blockchain) - } - return sendTransactionInternal( - walletManager = walletManager, - amount = amount, - blockchain = blockchain, - feeAmount = txData.feeAmount, - gasLimit = txData.gasLimit, - destinationAddress = txData.destinationAddress, - dataToSign = txData.dataToSign, - ) - } - - @Suppress("LongParameterList") - private suspend fun sendTransactionInternal( - walletManager: WalletManager, - amount: Amount, - blockchain: Blockchain, - feeAmount: BigDecimal, - gasLimit: Int, - destinationAddress: String, - dataToSign: String, - ): SendTxResult { - val txData = walletManager.createTransaction( - amount = amount, - fee = Fee.Common(Amount(value = feeAmount, blockchain = blockchain)), - destination = destinationAddress, - ).copy(hash = dataToSign, extras = createExtras(walletManager, gasLimit, dataToSign)) - - val signer = transactionSigner(walletManager) - - val sendResult = try { - (walletManager as? TransactionSender)?.send(txData, signer) ?: error("Cannot cast to TransactionSender") - } catch (ex: Exception) { - FirebaseCrashlytics.getInstance().recordException(ex) - return SendTxResult.UnknownError(ex) - } - return handleSendResult(result = sendResult) - } - override fun getExplorerTransactionLink(networkId: String, txAddress: String): String { val blockchain = Blockchain.fromNetworkId(networkId) ?: error("blockchain not found") return when (val txUrlState = blockchain.getExploreTxUrl(txAddress)) { @@ -125,39 +31,11 @@ class TransactionManagerImpl( } } - override fun getMemoExtras(networkId: String, memo: String?): TransactionExtras? { - val blockchain = Blockchain.fromNetworkId(networkId) - if (memo == null) return null - return when (blockchain) { - Blockchain.Stellar -> { - val xlmMemo = if (memo.isNotEmpty() && memo.isDigitsOnly()) { - StellarMemo.Id(memo.toBigInteger()) - } else { - StellarMemo.Text(memo) - } - StellarTransactionExtras(xlmMemo) - } - Blockchain.Binance -> BinanceTransactionExtras(memo) - Blockchain.XRP -> memo.toLongOrNull()?.let { XrpTransactionBuilder.XrpTransactionExtras(it) } - Blockchain.Cosmos -> CosmosTransactionExtras(memo) - Blockchain.TON -> TonTransactionExtras(memo) - Blockchain.Hedera -> HederaTransactionExtras(memo) - Blockchain.Algorand -> AlgorandTransactionExtras(memo) - else -> null - } - } - override suspend fun updateWalletManager(networkId: String, derivationPath: String?) { val blockchain = requireNotNull(Blockchain.fromNetworkId(networkId)) { "blockchain not found" } getActualWalletManager(blockchain, derivationPath).update() } - override fun calculateFee(networkId: String, gasPrice: String, estimatedGas: Int): BigDecimal { - val blockchain = requireNotNull(Blockchain.fromNetworkId(networkId)) { "blockchain not found" } - val gasPriceValue = requireNotNull(gasPrice.toLongOrNull()) { "gasprice should be Long" } - return (gasPriceValue * estimatedGas).toBigDecimal().movePointLeft(blockchain.decimals()) - } - @Throws(IllegalStateException::class) override suspend fun getFee( networkId: String, @@ -364,60 +242,6 @@ class TransactionManagerImpl( return createMultipleProxyFees(gasPrice, gas, blockchain) } - private fun handleSendResult(result: Result): SendTxResult { - when (result) { - is Result.Success -> { - return SendTxResult.Success - } - is Result.Failure -> { - if (ResultChecker.isNetworkError(result)) return SendTxResult.NetworkError(result.error) - val error = result.error as? BlockchainSdkError ?: return SendTxResult.UnknownError() - when (error) { - is BlockchainSdkError.WrappedTangemError -> { - val errorByCode = mapErrorByCode(error) - if (errorByCode != null) { - return errorByCode - } - val tangemSdkError = error.tangemError as? TangemSdkError ?: return SendTxResult.UnknownError() - if (tangemSdkError is TangemSdkError.UserCancelled) return SendTxResult.UserCancelledError - return SendTxResult.TangemSdkError(tangemSdkError.code, tangemSdkError.cause) - } - else -> { - return SendTxResult.TangemSdkError(error.code, error.cause) - } - } - } - } - } - - private fun mapErrorByCode(error: BlockchainSdkError.WrappedTangemError): SendTxResult? { - return when (error.code) { - USER_CANCELLED_ERROR_CODE -> { - return SendTxResult.UserCancelledError - } - else -> { - null - } - } - } - - private fun transactionSigner(walletManager: WalletManager): TransactionSigner { - val actualCard = requireNotNull(appStateHolder.getActualCard()) { "no card found" } - return TangemSigner( - card = actualCard, - tangemSdk = cardSdkConfigRepository.sdk, - initialMessage = Message(), - ) { signResponse -> - appStateHolder.mainStore?.dispatch( - GlobalAction.UpdateWalletSignedHashes( - walletSignedHashes = signResponse.totalSignedHashes, - walletPublicKey = walletManager.wallet.publicKey.seedKey, - remainingSignatures = signResponse.remainingSignatures, - ), - ) - } - } - private suspend fun getActualWalletManager(blockchain: Blockchain, derivationPath: String?): WalletManager { val selectedUserWallet = requireNotNull( userWalletsListManager.selectedUserWalletSync, @@ -431,24 +255,6 @@ class TransactionManagerImpl( return requireNotNull(walletManager) { "no wallet manager found" } } - private fun createExtras( - walletManager: WalletManager, - gasLimit: Int, - transactionHash: String, - ): TransactionExtras? { - return when (walletManager) { - is EthereumWalletManager -> { - return EthereumTransactionExtras( - data = transactionHash.removePrefix(HEX_PREFIX).hexToBytes(), - gasLimit = gasLimit.toBigInteger(), - ) - } - else -> { - null - } - } - } - /** * Create proxy fees * @@ -502,46 +308,6 @@ class TransactionManagerImpl( ) } - private fun createAmount(amount: BigDecimal, currency: Currency, blockchain: Blockchain): Amount { - return when (currency) { - is Currency.NativeToken -> { - Amount(value = amount, blockchain = blockchain) - } - is Currency.NonNativeToken -> { - Amount(convertNonNativeToken(currency), amount) - } - } - } - - private fun createAmountForSwap(amount: BigDecimal, currency: Currency?, blockchain: Blockchain): Amount { - return when (currency) { - is Currency.NativeToken, - null, - -> { - Amount(value = amount, blockchain = blockchain) - } - is Currency.NonNativeToken -> { - // 1. when creates swap amount for NonNativeToken, amount should be ZERO - // 2. Amount has .Coin type, as workaround to use destinationAddress in bsdk, not contractAddress - Amount( - currencySymbol = currency.symbol, - value = BigDecimal.ZERO, - decimals = currency.decimalCount, - ) - } - } - } - - private fun convertNonNativeToken(token: Currency.NonNativeToken): Token { - return Token( - name = token.name, - symbol = token.symbol, - contractAddress = token.contractAddress, - decimals = token.decimalCount, - id = token.id, - ) - } - private fun convertToProxyAmount(amount: Amount): ProxyAmount { return ProxyAmount( currencySymbol = amount.currencySymbol, @@ -565,8 +331,6 @@ class TransactionManagerImpl( } companion object { - private const val HEX_PREFIX = "0x" - private const val USER_CANCELLED_ERROR_CODE = 50002 private const val MULTIPLIER_GAS_PRICE_FOR_NORMAL_FEE = 150 // 50% private const val MULTIPLIER_GAS_PRICE_FOR_PRIORITY_FEE = 200 // 50% } 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 37fc1060b4..5c9c990ba5 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,16 +1,16 @@ package com.tangem.tap.proxy.di -import com.tangem.domain.card.repository.CardSdkConfigRepository import com.tangem.domain.walletmanager.WalletManagersFacade import com.tangem.domain.wallets.legacy.UserWalletsListManager import com.tangem.lib.crypto.TransactionManager import com.tangem.lib.crypto.UserWalletManager -import com.tangem.tap.proxy.* +import com.tangem.tap.proxy.AppStateHolder +import com.tangem.tap.proxy.TransactionManagerImpl +import com.tangem.tap.proxy.UserWalletManagerImpl import dagger.Module import dagger.Provides import dagger.hilt.InstallIn import dagger.hilt.components.SingletonComponent -import kotlinx.coroutines.flow.* import javax.inject.Singleton @Module @@ -38,14 +38,10 @@ internal object ProxyModule { @Provides @Singleton fun provideTransactionManager( - appStateHolder: AppStateHolder, - cardSdkConfigRepository: CardSdkConfigRepository, walletManagersFacade: WalletManagersFacade, userWalletsListManager: UserWalletsListManager, ): TransactionManager { return TransactionManagerImpl( - appStateHolder = appStateHolder, - cardSdkConfigRepository = cardSdkConfigRepository, walletManagersFacade = walletManagersFacade, userWalletsListManager = userWalletsListManager, ) diff --git a/app/src/main/java/com/tangem/tap/proxy/redux/DaggerGraphAction.kt b/app/src/main/java/com/tangem/tap/proxy/redux/DaggerGraphAction.kt index f854ba0dae..0f3c13fbf9 100644 --- a/app/src/main/java/com/tangem/tap/proxy/redux/DaggerGraphAction.kt +++ b/app/src/main/java/com/tangem/tap/proxy/redux/DaggerGraphAction.kt @@ -4,8 +4,9 @@ import com.tangem.core.navigation.email.EmailSender import com.tangem.domain.card.ScanCardUseCase import com.tangem.domain.card.repository.CardSdkConfigRepository import com.tangem.feature.qrscanning.QrScanningRouter -import com.tangem.features.managetokens.navigation.ManageTokensUi +import com.tangem.features.pushnotifications.api.navigation.PushNotificationsRouter import com.tangem.features.send.api.navigation.SendRouter +import com.tangem.features.staking.api.navigation.StakingRouter import com.tangem.features.tester.api.TesterRouter import com.tangem.features.tokendetails.navigation.TokenDetailsRouter import com.tangem.features.wallet.navigation.WalletRouter @@ -20,10 +21,11 @@ sealed interface DaggerGraphAction : Action { val walletRouter: WalletRouter, val walletConnectInteractor: WalletConnectInteractor, val tokenDetailsRouter: TokenDetailsRouter, - val manageTokensUi: ManageTokensUi, val cardSdkConfigRepository: CardSdkConfigRepository, val sendRouter: SendRouter, val qrScanningRouter: QrScanningRouter, val emailSender: EmailSender, + val stakingRouter: StakingRouter, + val pushNotificationsRouter: PushNotificationsRouter, ) : DaggerGraphAction } \ No newline at end of file diff --git a/app/src/main/java/com/tangem/tap/proxy/redux/DaggerGraphReducer.kt b/app/src/main/java/com/tangem/tap/proxy/redux/DaggerGraphReducer.kt index b25fdce12b..2a20bab5b6 100644 --- a/app/src/main/java/com/tangem/tap/proxy/redux/DaggerGraphReducer.kt +++ b/app/src/main/java/com/tangem/tap/proxy/redux/DaggerGraphReducer.kt @@ -18,11 +18,12 @@ object DaggerGraphReducer { walletRouter = action.walletRouter, walletConnectInteractor = action.walletConnectInteractor, tokenDetailsRouter = action.tokenDetailsRouter, - manageTokensUi = action.manageTokensUi, cardSdkConfigRepository = action.cardSdkConfigRepository, sendRouter = action.sendRouter, qrScanningRouter = action.qrScanningRouter, emailSender = action.emailSender, + stakingRouter = action.stakingRouter, + pushNotificationsRouter = action.pushNotificationsRouter, ) } } diff --git a/app/src/main/java/com/tangem/tap/proxy/redux/DaggerGraphState.kt b/app/src/main/java/com/tangem/tap/proxy/redux/DaggerGraphState.kt index a61bdcde57..ee435bc6ec 100644 --- a/app/src/main/java/com/tangem/tap/proxy/redux/DaggerGraphState.kt +++ b/app/src/main/java/com/tangem/tap/proxy/redux/DaggerGraphState.kt @@ -2,7 +2,10 @@ package com.tangem.tap.proxy.redux import com.tangem.TangemSdkLogger import com.tangem.blockchainsdk.BlockchainSDKFactory +import com.tangem.common.routing.AppRouter import com.tangem.core.navigation.email.EmailSender +import com.tangem.core.navigation.share.ShareManager +import com.tangem.core.navigation.url.UrlOpener import com.tangem.datasource.asset.loader.AssetLoader import com.tangem.datasource.connection.NetworkConnectionManager import com.tangem.domain.appcurrency.repository.AppCurrencyRepository @@ -13,6 +16,8 @@ import com.tangem.domain.card.ScanCardUseCase import com.tangem.domain.card.repository.CardRepository import com.tangem.domain.card.repository.CardSdkConfigRepository import com.tangem.domain.feedback.FeedbackManagerFeatureToggles +import com.tangem.domain.feedback.GetCardInfoUseCase +import com.tangem.domain.feedback.GetFeedbackEmailUseCase import com.tangem.domain.feedback.SaveBlockchainErrorUseCase import com.tangem.domain.onboarding.SaveTwinsOnboardingShownUseCase import com.tangem.domain.onboarding.WasTwinsOnboardingShownUseCase @@ -24,17 +29,17 @@ import com.tangem.domain.wallets.legacy.UserWalletsListManager import com.tangem.domain.wallets.repository.WalletsRepository import com.tangem.domain.wallets.usecase.GenerateWalletNameUseCase import com.tangem.feature.qrscanning.QrScanningRouter -import com.tangem.features.details.DetailsEntryPoint import com.tangem.features.details.DetailsFeatureToggles -import com.tangem.features.managetokens.featuretoggles.ManageTokensFeatureToggles -import com.tangem.features.managetokens.navigation.ManageTokensUi +import com.tangem.features.pushnotifications.api.featuretoggles.PushNotificationsFeatureToggles +import com.tangem.features.pushnotifications.api.navigation.PushNotificationsRouter import com.tangem.features.send.api.featuretoggles.SendFeatureToggles import com.tangem.features.send.api.navigation.SendRouter +import com.tangem.features.staking.api.navigation.StakingRouter import com.tangem.features.tester.api.TesterRouter import com.tangem.features.tokendetails.navigation.TokenDetailsRouter import com.tangem.features.wallet.navigation.WalletRouter -import com.tangem.tap.domain.walletconnect2.domain.WalletConnectInteractor import com.tangem.tap.domain.walletconnect2.domain.LegacyWalletConnectRepository +import com.tangem.tap.domain.walletconnect2.domain.WalletConnectInteractor import com.tangem.tap.domain.walletconnect2.domain.WalletConnectSessionsRepository import com.tangem.tap.features.customtoken.api.featuretoggles.CustomTokenFeatureToggles import com.tangem.tap.proxy.AppStateHolder @@ -50,8 +55,6 @@ data class DaggerGraphState( val walletConnectSessionsRepository: WalletConnectSessionsRepository? = null, val walletConnectInteractor: WalletConnectInteractor? = null, val tokenDetailsRouter: TokenDetailsRouter? = null, - val manageTokensFeatureToggles: ManageTokensFeatureToggles? = null, - val manageTokensUi: ManageTokensUi? = null, val scanCardProcessor: ScanCardProcessor? = null, val cardSdkConfigRepository: CardSdkConfigRepository? = null, val appCurrencyRepository: AppCurrencyRepository? = null, @@ -76,7 +79,14 @@ data class DaggerGraphState( val blockchainSDKFactory: BlockchainSDKFactory? = null, val emailSender: EmailSender? = null, val saveBlockchainErrorUseCase: SaveBlockchainErrorUseCase? = null, + val getFeedbackEmailUseCase: GetFeedbackEmailUseCase? = null, + val getCardInfoUseCase: GetCardInfoUseCase? = null, val assetLoader: AssetLoader? = null, val detailsFeatureToggles: DetailsFeatureToggles? = null, - val detailsEntryPoint: DetailsEntryPoint? = null, + val stakingRouter: StakingRouter? = null, + val urlOpener: UrlOpener? = null, + val shareManager: ShareManager? = null, + val appRouter: AppRouter? = null, + val pushNotificationsFeatureToggles: PushNotificationsFeatureToggles? = null, + val pushNotificationsRouter: PushNotificationsRouter? = null, ) : StateType \ No newline at end of file diff --git a/app/src/main/java/com/tangem/tap/routing/ProxyAppRouter.kt b/app/src/main/java/com/tangem/tap/routing/ProxyAppRouter.kt new file mode 100644 index 0000000000..aca4ce8efb --- /dev/null +++ b/app/src/main/java/com/tangem/tap/routing/ProxyAppRouter.kt @@ -0,0 +1,61 @@ +package com.tangem.tap.routing + +import com.tangem.common.routing.AppRoute +import com.tangem.common.routing.AppRouter +import com.tangem.core.decompose.navigation.Router +import com.tangem.tap.routing.configurator.AppRouterConfig +import com.tangem.utils.coroutines.CoroutineDispatcherProvider +import kotlinx.coroutines.CoroutineScope +import kotlinx.coroutines.launch +import kotlin.reflect.KClass + +internal class ProxyAppRouter( + private val config: AppRouterConfig, + private val dispatchers: CoroutineDispatcherProvider, +) : AppRouter { + + private val routerScope: CoroutineScope + get() = requireNotNull(config.routerScope) { + "Router scope is not set in config" + } + + private val innerRouter: Router + get() = requireNotNull(config.componentRouter) { + "Inner router is not set in config" + } + + override val stack: List + get() = requireNotNull(config.stack) { + "Stack is not set in config" + } + + override fun push(route: AppRoute, onComplete: (isSuccess: Boolean) -> Unit) { + routerScope.launch(dispatchers.mainImmediate) { + innerRouter.push(route, onComplete) + } + } + + override fun replaceAll(vararg routes: AppRoute, onComplete: (isSuccess: Boolean) -> Unit) { + routerScope.launch(dispatchers.mainImmediate) { + innerRouter.replaceAll(*routes, onComplete = onComplete) + } + } + + override fun pop(onComplete: (isSuccess: Boolean) -> Unit) { + routerScope.launch(dispatchers.mainImmediate) { + innerRouter.pop(onComplete) + } + } + + override fun popTo(route: AppRoute, onComplete: (isSuccess: Boolean) -> Unit) { + routerScope.launch(dispatchers.mainImmediate) { + innerRouter.popTo(route, onComplete) + } + } + + override fun popTo(routeClass: KClass, onComplete: (isSuccess: Boolean) -> Unit) { + routerScope.launch(dispatchers.mainImmediate) { + innerRouter.popTo(routeClass, onComplete) + } + } +} \ No newline at end of file diff --git a/app/src/main/java/com/tangem/tap/routing/RoutingComponent.kt b/app/src/main/java/com/tangem/tap/routing/RoutingComponent.kt new file mode 100644 index 0000000000..a7f5148b19 --- /dev/null +++ b/app/src/main/java/com/tangem/tap/routing/RoutingComponent.kt @@ -0,0 +1,33 @@ +package com.tangem.tap.routing + +import android.content.Intent +import androidx.fragment.app.Fragment +import com.arkivanov.decompose.router.stack.ChildStack +import com.arkivanov.decompose.value.Value +import com.tangem.common.routing.AppRoute +import com.tangem.core.decompose.context.AppComponentContext +import com.tangem.core.decompose.navigation.Router +import com.tangem.utils.Provider + +internal interface RoutingComponent { + + val router: Router + + val stack: Value> + + sealed class Child { + + data object Initial : Child() + + data class LegacyFragment( + val name: String, + val fragmentProvider: Provider, + ) : Child() + + data class LegacyIntent(val intent: Intent) : Child() + } + + interface Factory { + fun create(context: AppComponentContext): RoutingComponent + } +} \ No newline at end of file diff --git a/app/src/main/java/com/tangem/tap/routing/configurator/AppRouterConfig.kt b/app/src/main/java/com/tangem/tap/routing/configurator/AppRouterConfig.kt new file mode 100644 index 0000000000..470c85f674 --- /dev/null +++ b/app/src/main/java/com/tangem/tap/routing/configurator/AppRouterConfig.kt @@ -0,0 +1,12 @@ +package com.tangem.tap.routing.configurator + +import com.tangem.common.routing.AppRoute +import com.tangem.core.decompose.navigation.Router +import kotlinx.coroutines.CoroutineScope + +internal interface AppRouterConfig { + + var routerScope: CoroutineScope? + var componentRouter: Router? + var stack: List? +} \ No newline at end of file diff --git a/app/src/main/java/com/tangem/tap/routing/configurator/MutableAppRouterConfig.kt b/app/src/main/java/com/tangem/tap/routing/configurator/MutableAppRouterConfig.kt new file mode 100644 index 0000000000..ae724ac04e --- /dev/null +++ b/app/src/main/java/com/tangem/tap/routing/configurator/MutableAppRouterConfig.kt @@ -0,0 +1,12 @@ +package com.tangem.tap.routing.configurator + +import com.tangem.common.routing.AppRoute +import com.tangem.core.decompose.navigation.Router +import kotlinx.coroutines.CoroutineScope + +internal class MutableAppRouterConfig : AppRouterConfig { + + override var routerScope: CoroutineScope? = null + override var componentRouter: Router? = null + override var stack: List? = null +} \ No newline at end of file diff --git a/app/src/main/java/com/tangem/tap/routing/impl/DefaultRoutingComponent.kt b/app/src/main/java/com/tangem/tap/routing/impl/DefaultRoutingComponent.kt new file mode 100644 index 0000000000..e766371cb7 --- /dev/null +++ b/app/src/main/java/com/tangem/tap/routing/impl/DefaultRoutingComponent.kt @@ -0,0 +1,54 @@ +package com.tangem.tap.routing.impl + +import com.arkivanov.decompose.ComponentContext +import com.arkivanov.decompose.router.stack.ChildStack +import com.arkivanov.decompose.router.stack.childStack +import com.arkivanov.decompose.value.Value +import com.arkivanov.essenty.backhandler.BackCallback +import com.arkivanov.essenty.lifecycle.doOnDestroy +import com.tangem.common.routing.AppRoute +import com.tangem.core.decompose.context.AppComponentContext +import com.tangem.core.decompose.context.childByContext +import com.tangem.core.decompose.navigation.getOrCreateTyped +import com.tangem.tap.routing.RoutingComponent +import com.tangem.tap.routing.RoutingComponent.Child +import com.tangem.tap.routing.utils.ChildFactory +import dagger.assisted.Assisted +import dagger.assisted.AssistedFactory +import dagger.assisted.AssistedInject + +@Suppress("LongParameterList") +internal class DefaultRoutingComponent @AssistedInject constructor( + @Assisted context: AppComponentContext, + private val childFactory: ChildFactory, +) : RoutingComponent, AppComponentContext by context { + + private val backCallback = BackCallback(priority = Int.MIN_VALUE, onBack = router::pop) + + override val stack: Value> = childStack( + source = navigationProvider.getOrCreateTyped(), + serializer = AppRoute.serializer(), + initialConfiguration = getInitialRoute(), + handleBackButton = false, + childFactory = ::child, + ) + + init { + backHandler.register(backCallback) + + lifecycle.doOnDestroy { + childFactory.doOnDestroy() + } + } + + private fun getInitialRoute(): AppRoute = AppRoute.Initial + + private fun child(route: AppRoute, context: ComponentContext): Child { + return childFactory.createChild(route, { childByContext(context) }) + } + + @AssistedFactory + interface Factory : RoutingComponent.Factory { + override fun create(context: AppComponentContext): DefaultRoutingComponent + } +} \ No newline at end of file diff --git a/app/src/main/java/com/tangem/tap/routing/utils/ChildFactory.kt b/app/src/main/java/com/tangem/tap/routing/utils/ChildFactory.kt new file mode 100644 index 0000000000..8b3c22a7f9 --- /dev/null +++ b/app/src/main/java/com/tangem/tap/routing/utils/ChildFactory.kt @@ -0,0 +1,194 @@ +package com.tangem.tap.routing.utils + +import com.tangem.common.routing.AppRoute +import com.tangem.core.decompose.context.AppComponentContext +import com.tangem.feature.qrscanning.QrScanningRouter +import com.tangem.feature.referral.ReferralFragment +import com.tangem.feature.swap.presentation.SwapFragment +import com.tangem.feature.walletsettings.component.WalletSettingsComponent +import com.tangem.features.details.DetailsFeatureToggles +import com.tangem.features.details.component.DetailsComponent +import com.tangem.features.disclaimer.api.components.DisclaimerComponent +import com.tangem.features.pushnotifications.api.featuretoggles.PushNotificationsFeatureToggles +import com.tangem.features.pushnotifications.api.navigation.PushNotificationsRouter +import com.tangem.features.send.api.navigation.SendRouter +import com.tangem.features.staking.api.navigation.StakingRouter +import com.tangem.features.tester.api.TesterRouter +import com.tangem.features.tokendetails.navigation.TokenDetailsRouter +import com.tangem.features.wallet.navigation.WalletRouter +import com.tangem.tap.features.customtoken.impl.presentation.AddCustomTokenFragment +import com.tangem.tap.features.details.ui.appcurrency.AppCurrencySelectorFragment +import com.tangem.tap.features.details.ui.appsettings.AppSettingsFragment +import com.tangem.tap.features.details.ui.cardsettings.CardSettingsFragment +import com.tangem.tap.features.details.ui.cardsettings.coderecovery.AccessCodeRecoveryFragment +import com.tangem.tap.features.details.ui.details.DetailsFragment +import com.tangem.tap.features.details.ui.resetcard.ResetCardFragment +import com.tangem.tap.features.details.ui.securitymode.SecurityModeFragment +import com.tangem.tap.features.details.ui.walletconnect.WalletConnectFragment +import com.tangem.tap.features.disclaimer.ui.DisclaimerFragment +import com.tangem.tap.features.home.HomeFragment +import com.tangem.tap.features.main.ui.ModalNotificationBottomSheetFragment +import com.tangem.tap.features.onboarding.products.note.OnboardingNoteFragment +import com.tangem.tap.features.onboarding.products.otherCards.OnboardingOtherCardsFragment +import com.tangem.tap.features.onboarding.products.twins.ui.OnboardingTwinsFragment +import com.tangem.tap.features.onboarding.products.wallet.ui.OnboardingWalletFragment +import com.tangem.tap.features.saveWallet.ui.SaveWalletBottomSheetFragment +import com.tangem.tap.features.tokens.impl.presentation.TokensListFragment +import com.tangem.tap.features.welcome.ui.WelcomeFragment +import com.tangem.tap.routing.RoutingComponent.Child +import com.tangem.utils.Provider +import dagger.hilt.android.scopes.ActivityScoped +import java.util.WeakHashMap +import javax.inject.Inject + +@ActivityScoped +@Suppress("LongParameterList") +internal class ChildFactory @Inject constructor( + private val detailsComponentFactory: DetailsComponent.Factory, + private val walletSettingsComponentFactory: WalletSettingsComponent.Factory, + private val disclaimerComponentFactory: DisclaimerComponent.Factory, + private val sendRouter: SendRouter, + private val tokenDetailsRouter: TokenDetailsRouter, + private val walletRouter: WalletRouter, + private val qrScanningRouter: QrScanningRouter, + private val stakingRouter: StakingRouter, + private val testerRouter: TesterRouter, + private val detailsFeatureToggles: DetailsFeatureToggles, + private val pushNotificationsFeatureToggles: PushNotificationsFeatureToggles, + private val pushNotificationRouter: PushNotificationsRouter, +) { + + @Suppress("LongMethod", "CyclomaticComplexMethod") + fun createChild(route: AppRoute, contextFactory: (route: AppRoute) -> AppComponentContext): Child { + componentContexts[route] = contextFactory(route) + + return when (route) { + is AppRoute.Initial -> { + Child.Initial + } + is AppRoute.AccessCodeRecovery -> { + route.asFragmentChild(Provider { AccessCodeRecoveryFragment() }) + } + is AppRoute.AddCustomToken -> { + route.asFragmentChild(Provider { AddCustomTokenFragment() }) + } + is AppRoute.AppCurrencySelector -> { + route.asFragmentChild(Provider { AppCurrencySelectorFragment() }) + } + is AppRoute.ModalNotification -> { + route.asFragmentChild(Provider { ModalNotificationBottomSheetFragment() }) + } + is AppRoute.SaveWallet -> { + route.asFragmentChild(Provider { SaveWalletBottomSheetFragment() }) + } + is AppRoute.Send -> { + route.asFragmentChild(Provider { sendRouter.getEntryFragment() }) + } + is AppRoute.AppSettings -> { + route.asFragmentChild(Provider { AppSettingsFragment() }) + } + is AppRoute.CardSettings -> { + route.asFragmentChild(Provider { CardSettingsFragment() }) + } + is AppRoute.Details -> { + if (detailsFeatureToggles.isRedesignEnabled) { + route.asComponentChild( + contextProvider = contextProvider(route, contextFactory), + params = DetailsComponent.Params(route.userWalletId), + componentFactory = detailsComponentFactory, + ) + } else { + route.asFragmentChild(Provider { DetailsFragment() }) + } + } + is AppRoute.DetailsSecurity -> { + route.asFragmentChild(Provider { SecurityModeFragment() }) + } + is AppRoute.Disclaimer -> { + if (pushNotificationsFeatureToggles.isPushNotificationsEnabled) { + route.asComponentChild( + contextProvider = contextProvider(route, contextFactory), + params = DisclaimerComponent.Params(route.isTosAccepted), + componentFactory = disclaimerComponentFactory, + ) + } else { + route.asFragmentChild(Provider { DisclaimerFragment() }) + } + } + is AppRoute.Home -> { + route.asFragmentChild(Provider { HomeFragment() }) + } + is AppRoute.ManageTokens -> { + route.asFragmentChild(Provider { TokensListFragment() }) + } + is AppRoute.OnboardingNote -> { + route.asFragmentChild(Provider { OnboardingNoteFragment() }) + } + is AppRoute.OnboardingOther -> { + route.asFragmentChild(Provider { OnboardingOtherCardsFragment() }) + } + is AppRoute.OnboardingTwins -> { + route.asFragmentChild(Provider { OnboardingTwinsFragment() }) + } + is AppRoute.OnboardingWallet -> { + route.asFragmentChild(Provider { OnboardingWalletFragment() }) + } + is AppRoute.QrScanning -> { + route.asFragmentChild(Provider { qrScanningRouter.getEntryFragment() }) + } + is AppRoute.ReferralProgram -> { + route.asFragmentChild(Provider { ReferralFragment() }) + } + is AppRoute.ResetToFactory -> { + route.asFragmentChild(Provider { ResetCardFragment() }) + } + is AppRoute.Swap -> { + route.asFragmentChild(Provider { SwapFragment() }) + } + is AppRoute.Wallet -> { + route.asFragmentChild(Provider { walletRouter.getEntryFragment() }) + } + is AppRoute.WalletConnectSessions -> { + route.asFragmentChild(Provider { WalletConnectFragment() }) + } + is AppRoute.CurrencyDetails -> { + route.asFragmentChild(Provider { tokenDetailsRouter.getEntryFragment() }) + } + is AppRoute.Welcome -> { + route.asFragmentChild(Provider { WelcomeFragment() }) + } + is AppRoute.TesterMenu -> { + Child.LegacyIntent(testerRouter.getEntryIntent()) + } + is AppRoute.Staking -> { + route.asFragmentChild(Provider { stakingRouter.getEntryFragment() }) + } + is AppRoute.PushNotification -> { + route.asFragmentChild(Provider { pushNotificationRouter.entryFragment() }) + } + is AppRoute.WalletSettings -> { + route.asComponentChild( + contextProvider = contextProvider(route, contextFactory), + params = WalletSettingsComponent.Params(route.userWalletId), + componentFactory = walletSettingsComponentFactory, + ) + } + } + } + + fun doOnDestroy() { + componentContexts.clear() + } + + private fun contextProvider( + appRoute: AppRoute, + contextFactory: (route: AppRoute) -> AppComponentContext, + ): Provider = Provider { + componentContexts.getOrPut(appRoute) { contextFactory(appRoute) } + } + + private companion object { + + val componentContexts = WeakHashMap() + } +} \ No newline at end of file diff --git a/app/src/main/java/com/tangem/tap/routing/utils/RouteMappers.kt b/app/src/main/java/com/tangem/tap/routing/utils/RouteMappers.kt new file mode 100644 index 0000000000..bdade79e4e --- /dev/null +++ b/app/src/main/java/com/tangem/tap/routing/utils/RouteMappers.kt @@ -0,0 +1,40 @@ +package com.tangem.tap.routing.utils + +import androidx.fragment.app.Fragment +import com.tangem.common.routing.AppRoute +import com.tangem.common.routing.bundle.RouteBundleParams +import com.tangem.core.decompose.context.AppComponentContext +import com.tangem.core.decompose.factory.ComponentFactory +import com.tangem.core.ui.decompose.ComposableContentComponent +import com.tangem.tap.DecomposeFragment +import com.tangem.tap.routing.RoutingComponent.Child +import com.tangem.utils.Provider + +internal fun AppRoute.asFragmentChild(fragmentProvider: Provider): Child { + val provider = Provider { + val bundle = (this as? RouteBundleParams)?.getBundle() + + fragmentProvider().apply { + arguments = bundle + } + } + + return Child.LegacyFragment(path, provider) +} + +internal fun > AppRoute.asComponentChild( + contextProvider: Provider, + params: P, + componentFactory: F, +): Child { + val fragmentProvider = Provider { + DecomposeFragment.newInstance( + tag = path, + contextProvider = contextProvider, + params = params, + componentFactory = componentFactory, + ) + } + + return Child.LegacyFragment(path, fragmentProvider) +} \ No newline at end of file diff --git a/app/src/main/res/drawable/ic_more_cards.xml b/app/src/main/res/drawable/ic_more_cards.xml deleted file mode 100644 index 0cc559021b..0000000000 --- a/app/src/main/res/drawable/ic_more_cards.xml +++ /dev/null @@ -1,5 +0,0 @@ - - - diff --git a/app/src/main/res/layout/dialog_scan_fails.xml b/app/src/main/res/layout/dialog_scan_fails.xml new file mode 100644 index 0000000000..dd5924f8c5 --- /dev/null +++ b/app/src/main/res/layout/dialog_scan_fails.xml @@ -0,0 +1,84 @@ + + + + + + + + + + + + + + + + diff --git a/app/src/main/res/values/values.xml b/app/src/main/res/values/values.xml new file mode 100644 index 0000000000..5bbea5d78d --- /dev/null +++ b/app/src/main/res/values/values.xml @@ -0,0 +1,4 @@ + + + false + \ No newline at end of file diff --git a/app/src/mocked/res/values/values.xml b/app/src/mocked/res/values/values.xml new file mode 100644 index 0000000000..8cc3a85358 --- /dev/null +++ b/app/src/mocked/res/values/values.xml @@ -0,0 +1,4 @@ + + + true + \ No newline at end of file diff --git a/app/src/test/kotlin/com/tangem/tap/domain/card/DefaultDerivationsRepositoryTest.kt b/app/src/test/kotlin/com/tangem/tap/domain/card/DefaultDerivationsRepositoryTest.kt index fdf0ed8db2..12be6b889d 100644 --- a/app/src/test/kotlin/com/tangem/tap/domain/card/DefaultDerivationsRepositoryTest.kt +++ b/app/src/test/kotlin/com/tangem/tap/domain/card/DefaultDerivationsRepositoryTest.kt @@ -12,7 +12,9 @@ import com.tangem.domain.wallets.models.UserWalletId import com.tangem.operations.derivation.DerivationTaskResponse import com.tangem.tap.domain.sdk.impl.DefaultTangemSdkManager import com.tangem.utils.coroutines.TestingCoroutineDispatcherProvider -import io.mockk.* +import io.mockk.coEvery +import io.mockk.coVerify +import io.mockk.mockk import kotlinx.coroutines.test.runTest import org.junit.Test @@ -144,7 +146,7 @@ internal class DefaultDerivationsRepositoryTest { coEvery { tangemSdkManager.derivePublicKeys(null, any()) } returns CompletionResult.Success( DerivationTaskResponse(DerivedKeysMocks.ethereumDerivedKeys), ) - coEvery { userWalletsStore.update(defaultUserWalletId, any()) } just Runs + coEvery { userWalletsStore.update(defaultUserWalletId, any()) } returns CompletionResult.Success(userWallet) runCatching { repository.derivePublicKeys( diff --git a/common/routing/.gitignore b/common/routing/.gitignore new file mode 100644 index 0000000000..796b96d1c4 --- /dev/null +++ b/common/routing/.gitignore @@ -0,0 +1 @@ +/build diff --git a/common/routing/build.gradle.kts b/common/routing/build.gradle.kts new file mode 100644 index 0000000000..a492ede7aa --- /dev/null +++ b/common/routing/build.gradle.kts @@ -0,0 +1,27 @@ +plugins { + alias(deps.plugins.android.library) + alias(deps.plugins.kotlin.android) + alias(deps.plugins.kotlin.serialization) + id("configuration") +} + +android { + namespace = "com.tangem.common.routing" +} + +dependencies { + /* Core */ + implementation(projects.core.decompose) + + /* Domain */ + implementation(projects.domain.qrScanning.models) + implementation(projects.domain.models) + implementation(projects.domain.tokens.models) + implementation(projects.domain.wallets.models) + implementation(projects.domain.staking.models) + + /* Libs - Other */ + api(deps.kotlin.serialization) + implementation(deps.androidx.core.ktx) + implementation(deps.timber) +} \ No newline at end of file diff --git a/common/routing/src/main/kotlin/com/tangem/common/routing/AppRoute.kt b/common/routing/src/main/kotlin/com/tangem/common/routing/AppRoute.kt new file mode 100644 index 0000000000..6cd73dfcb0 --- /dev/null +++ b/common/routing/src/main/kotlin/com/tangem/common/routing/AppRoute.kt @@ -0,0 +1,261 @@ +package com.tangem.common.routing + +import android.os.Bundle +import com.tangem.common.routing.bundle.RouteBundleParams +import com.tangem.common.routing.bundle.bundle +import com.tangem.common.routing.entity.SerializableIntent +import com.tangem.core.decompose.navigation.Route +import com.tangem.domain.qrscanning.models.SourceType +import com.tangem.domain.staking.model.stakekit.Yield +import com.tangem.domain.tokens.model.CryptoCurrency +import com.tangem.domain.wallets.models.UserWalletId +import kotlinx.serialization.Serializable + +@Serializable +sealed class AppRoute(val path: String) : Route { + + @Serializable + data object Initial : AppRoute(path = "/initial") + + @Serializable + data object Home : AppRoute(path = "/home") + + @Serializable + data class Welcome( + val intent: SerializableIntent? = null, + ) : AppRoute(path = "/welcome"), RouteBundleParams { + + override fun getBundle(): Bundle = bundle(serializer()) + + companion object { + const val INITIAL_INTENT_KEY = "intent" + } + } + + @Serializable + data class Disclaimer( + val isTosAccepted: Boolean, + ) : AppRoute(path = "/disclaimer${if (isTosAccepted) "/tos_accepted" else ""}") + + @Serializable + data object OnboardingNote : AppRoute(path = "/onboarding/note") + + @Serializable + data class OnboardingWallet( + val canSkipBackup: Boolean = true, + ) : AppRoute(path = "/onboarding/wallet${if (canSkipBackup) "/skippable" else ""}"), RouteBundleParams { + + override fun getBundle(): Bundle = bundle(serializer()) + + companion object { + const val CAN_SKIP_BACKUP_KEY = "canSkipBackup" + } + } + + @Serializable + data object OnboardingTwins : AppRoute(path = "/onboarding/twins") + + @Serializable + data object OnboardingOther : AppRoute(path = "/onboarding/other") + + @Serializable + data object Wallet : AppRoute(path = "/wallet") + + @Serializable + data class CurrencyDetails( + val userWalletId: UserWalletId, + val currency: CryptoCurrency, + ) : AppRoute(path = "/currency_details/${userWalletId.stringValue}/${currency.id.value}"), RouteBundleParams { + + override fun getBundle(): Bundle = bundle(serializer()) + + companion object { + const val USER_WALLET_ID_KEY = "userWalletId" + const val CRYPTO_CURRENCY_KEY = "currency" + } + } + + @Serializable + data class Send( + val userWalletId: UserWalletId, + val currency: CryptoCurrency, + val transactionId: String? = null, + val amount: String? = null, + val tag: String? = null, + val destinationAddress: String? = null, + ) : AppRoute( + path = "/send/${userWalletId.stringValue}/${currency.id.value}?" + + "&$transactionId" + + "&$amount" + + "&$tag" + + "&$destinationAddress", + ), + RouteBundleParams { + + override fun getBundle(): Bundle = bundle(serializer()) + + companion object { + const val USER_WALLET_ID_KEY = "userWalletId" + const val CRYPTO_CURRENCY_KEY = "currency" + const val TRANSACTION_ID_KEY = "transactionId" + const val AMOUNT_KEY = "amount" + const val TAG_KEY = "tag" + const val DESTINATION_ADDRESS_KEY = "destinationAddress" + } + } + + @Serializable + data class Details( + val userWalletId: UserWalletId, + ) : AppRoute(path = "/details/${userWalletId.stringValue}") + + @Serializable + data class DetailsSecurity( + val userWalletId: UserWalletId, + ) : AppRoute(path = "/details/security"), RouteBundleParams { + + override fun getBundle(): Bundle = bundle(serializer()) + + companion object { + const val USER_WALLET_ID_KEY = "userWalletId" + } + } + + @Serializable + data class CardSettings( + val userWalletId: UserWalletId, + ) : AppRoute(path = "/card_settings/${userWalletId.stringValue}"), RouteBundleParams { + + override fun getBundle(): Bundle = bundle(serializer()) + + companion object { + const val USER_WALLET_ID_KEY = "userWalletId" + } + } + + @Serializable + data object AppSettings : AppRoute(path = "/app_settings") + + /** + * Reset to factory + * + * @property userWalletId user wallet id + * @property cardId reset card id + * @property isActiveBackupStatus reset backup card status + * @property backupCardsCount backup cards count + */ + @Serializable + data class ResetToFactory( + val userWalletId: UserWalletId, + val cardId: String, + val isActiveBackupStatus: Boolean, + val backupCardsCount: Int, + ) : AppRoute( + path = "/reset_to_factory" + + "/${userWalletId.stringValue}" + + "/$cardId" + + "/$isActiveBackupStatus" + + "/$backupCardsCount", + ), + RouteBundleParams { + + override fun getBundle(): Bundle = bundle(serializer()) + + companion object { + const val USER_WALLET_ID = "userWalletId" + const val CARD_ID = "cardId" + const val IS_ACTIVE_BACKUP_STATUS = "isActiveBackupStatus" + const val BACKUP_CARDS_COUNT = "backupCardsCount" + } + } + + @Serializable + data object AccessCodeRecovery : AppRoute(path = "/access_code_recovery"), RouteBundleParams { + + override fun getBundle(): Bundle = bundle(serializer()) + } + + @Serializable + data object ManageTokens : AppRoute(path = "/manage_tokens") + + @Serializable + data object AddCustomToken : AppRoute(path = "/add_custom_token") + + @Serializable + data object WalletConnectSessions : AppRoute(path = "/wallet_connect_sessions") + + @Serializable + data class QrScanning( + val source: SourceType, + val networkName: String? = null, + ) : AppRoute(path = "/$source/qr_scanning${if (networkName != null) "/$networkName" else ""}"), RouteBundleParams { + + override fun getBundle(): Bundle = bundle(serializer()) + + companion object { + const val SOURCE_KEY = "source" + const val NETWORK_KEY = "networkName" + } + } + + @Serializable + data class ReferralProgram( + val userWalletId: UserWalletId, + ) : AppRoute(path = "/referral_program"), RouteBundleParams { + + override fun getBundle(): Bundle = bundle(serializer()) + + companion object { + const val USER_WALLET_ID_KEY = "userWalletId" + } + } + + @Serializable + data class Swap( + val currency: CryptoCurrency, + ) : AppRoute(path = "/swap/${currency.id.value}"), RouteBundleParams { + + override fun getBundle(): Bundle = bundle(serializer()) + + companion object { + const val CURRENCY_BUNDLE_KEY = "currency" + } + } + + @Serializable + data object TesterMenu : AppRoute(path = "/tester_menu") + + @Serializable + data object SaveWallet : AppRoute(path = "/save_wallet") + + @Serializable + data object AppCurrencySelector : AppRoute(path = "/app_currency_selector") + + @Serializable + data object ModalNotification : AppRoute(path = "/modal_notification") + + @Serializable + data class Staking( + val userWalletId: UserWalletId, + val cryptoCurrencyId: CryptoCurrency.ID, + val yield: Yield, + ) : AppRoute(path = "/staking/${userWalletId.stringValue}/${cryptoCurrencyId.value}/${yield.id}"), + RouteBundleParams { + + override fun getBundle(): Bundle = bundle(serializer()) + + companion object { + const val USER_WALLET_ID_KEY = "userWalletId" + const val CRYPTO_CURRENCY_ID_KEY = "cryptoCurrencyId" + const val YIELD_KEY = "yield" + } + } + + @Serializable + data object PushNotification : AppRoute(path = "/push_notification") + + @Serializable + data class WalletSettings( + val userWalletId: UserWalletId, + ) : AppRoute(path = "/wallet_settings/${userWalletId.stringValue}") +} \ No newline at end of file diff --git a/common/routing/src/main/kotlin/com/tangem/common/routing/AppRouter.kt b/common/routing/src/main/kotlin/com/tangem/common/routing/AppRouter.kt new file mode 100644 index 0000000000..cb0f21a793 --- /dev/null +++ b/common/routing/src/main/kotlin/com/tangem/common/routing/AppRouter.kt @@ -0,0 +1,58 @@ +package com.tangem.common.routing + +import kotlin.reflect.KClass + +/** + * Interface for a router in the application. + * It provides methods for navigating through the application. + * + * Same as [com.tangem.core.decompose.navigation.Router] but without Decompose dependency. + * + * ***Must be removed after Decompose migration.*** + */ +interface AppRouter { + + /** + * The current navigation stack. + */ + val stack: List + + /** + * Pushes a new route to the navigation stack. + * + * @param route The route to push. + * @param onComplete The callback to be invoked when the operation is complete. + */ + fun push(route: AppRoute, onComplete: (isSuccess: Boolean) -> Unit = {}) + + /** + * Replaces ***all*** routes in the navigation stack with the specified [routes]. + * + * @param routes The routes to replace the current stack with. + * @param onComplete The callback to be invoked when the operation is complete. + */ + fun replaceAll(vararg routes: AppRoute, onComplete: (isSuccess: Boolean) -> Unit = {}) + + /** + * Pops the top route from the navigation stack. + * + * @param onComplete The callback to be invoked when the operation is complete. + */ + fun pop(onComplete: (isSuccess: Boolean) -> Unit = {}) + + /** + * Pops routes from the navigation stack until the specified [route] is found. + * + * @param route The route to pop to. + * @param onComplete The callback to be invoked when the operation is complete. + */ + fun popTo(route: AppRoute, onComplete: (isSuccess: Boolean) -> Unit = {}) + + /** + * Pops routes from the navigation stack until the ***first*** specified [routeClass] is found. + * + * @param routeClass The route class to pop to. + * @param onComplete The callback to be invoked when the operation is complete. + */ + fun popTo(routeClass: KClass, onComplete: (isSuccess: Boolean) -> Unit = {}) +} \ No newline at end of file diff --git a/common/routing/src/main/kotlin/com/tangem/common/routing/bundle/BundleDecoder.kt b/common/routing/src/main/kotlin/com/tangem/common/routing/bundle/BundleDecoder.kt new file mode 100644 index 0000000000..6a51004489 --- /dev/null +++ b/common/routing/src/main/kotlin/com/tangem/common/routing/bundle/BundleDecoder.kt @@ -0,0 +1,108 @@ +package com.tangem.common.routing.bundle + +import android.os.Bundle +import kotlinx.serialization.ExperimentalSerializationApi +import kotlinx.serialization.descriptors.SerialDescriptor +import kotlinx.serialization.descriptors.StructureKind +import kotlinx.serialization.encoding.AbstractDecoder +import kotlinx.serialization.encoding.CompositeDecoder +import kotlinx.serialization.modules.SerializersModule + +@ExperimentalSerializationApi +internal class BundleDecoder( + private val bundle: Bundle, + private val elementsCount: Int = -1, + private val isInitializer: Boolean = true, + override val serializersModule: SerializersModule, +) : AbstractDecoder() { + + private var index = -1 + private var elementKey: String? = null + + override fun decodeElementIndex(descriptor: SerialDescriptor): Int { + if (++index >= elementsCount) { + return CompositeDecoder.DECODE_DONE + } + + elementKey = descriptor.getElementName(index) + return index + } + + override fun beginStructure(descriptor: SerialDescriptor): CompositeDecoder { + val b = if (isInitializer) { + bundle + } else { + requireNotNull(bundle.getBundle(elementKey)) { + "Bundle is missing for key $elementKey while decoding" + } + } + + val count = when (descriptor.kind) { + StructureKind.MAP, + StructureKind.LIST, + -> b.getInt("\$size") + else -> descriptor.elementsCount + } + + return BundleDecoder( + bundle = b, + elementsCount = count, + isInitializer = false, + serializersModule = serializersModule, + ) + } + + override fun endStructure(descriptor: SerialDescriptor) { + /* no-op */ + } + + override fun decodeBoolean(): Boolean { + return bundle.getBoolean(elementKey) + } + + override fun decodeByte(): Byte { + return bundle.getByte(elementKey) + } + + override fun decodeChar(): Char { + return bundle.getChar(elementKey) + } + + override fun decodeDouble(): Double { + return bundle.getDouble(elementKey) + } + + override fun decodeEnum(enumDescriptor: SerialDescriptor): Int { + return bundle.getInt(elementKey) + } + + override fun decodeFloat(): Float { + return bundle.getFloat(elementKey) + } + + override fun decodeInt(): Int { + return bundle.getInt(elementKey) + } + + override fun decodeLong(): Long { + return bundle.getLong(elementKey) + } + + override fun decodeNotNullMark(): Boolean { + return bundle.containsKey(elementKey) + } + + override fun decodeNull(): Nothing? { + return null + } + + override fun decodeShort(): Short { + return bundle.getShort(elementKey) + } + + override fun decodeString(): String { + return requireNotNull(bundle.getString(elementKey)) { + "String is missing for key $elementKey while decoding" + } + } +} \ No newline at end of file diff --git a/common/routing/src/main/kotlin/com/tangem/common/routing/bundle/BundleEncoder.kt b/common/routing/src/main/kotlin/com/tangem/common/routing/bundle/BundleEncoder.kt new file mode 100644 index 0000000000..e0be7b8aa3 --- /dev/null +++ b/common/routing/src/main/kotlin/com/tangem/common/routing/bundle/BundleEncoder.kt @@ -0,0 +1,107 @@ +package com.tangem.common.routing.bundle + +import android.os.Bundle +import kotlinx.serialization.ExperimentalSerializationApi +import kotlinx.serialization.descriptors.SerialDescriptor +import kotlinx.serialization.descriptors.StructureKind +import kotlinx.serialization.encoding.AbstractEncoder +import kotlinx.serialization.encoding.CompositeEncoder +import kotlinx.serialization.modules.SerializersModule + +@ExperimentalSerializationApi +internal class BundleEncoder( + private val bundle: Bundle, + private val parentBundle: Bundle? = null, + private val keyInParent: String? = null, + private val isInitializer: Boolean = true, + override val serializersModule: SerializersModule, +) : AbstractEncoder() { + + private var elementKey: String? = null + + override fun encodeElement(descriptor: SerialDescriptor, index: Int): Boolean { + elementKey = descriptor.getElementName(index) + return super.encodeElement(descriptor, index) + } + + override fun beginStructure(descriptor: SerialDescriptor): CompositeEncoder { + return if (isInitializer) { + BundleEncoder( + bundle = bundle, + parentBundle = null, + keyInParent = elementKey, + isInitializer = false, + serializersModule = serializersModule, + ) + } else { + BundleEncoder( + bundle = Bundle(), + parentBundle = bundle, + keyInParent = elementKey, + isInitializer = false, + serializersModule = serializersModule, + ) + } + } + + override fun endStructure(descriptor: SerialDescriptor) { + if (descriptor.kind in arrayOf(StructureKind.LIST, StructureKind.MAP)) { + val size = elementKey?.toIntOrNull()?.let { it + 1 } ?: 0 + bundle.putInt("\$size", size) + } + + if (keyInParent.isNullOrBlank()) { + return + } + + parentBundle?.putBundle(keyInParent, bundle) + } + + override fun encodeBoolean(value: Boolean) { + bundle.putBoolean(elementKey, value) + } + + override fun encodeByte(value: Byte) { + bundle.putByte(elementKey, value) + } + + override fun encodeChar(value: Char) { + bundle.putChar(elementKey, value) + } + + override fun encodeDouble(value: Double) { + bundle.putDouble(elementKey, value) + } + + override fun encodeEnum(enumDescriptor: SerialDescriptor, index: Int) { + bundle.putInt(elementKey, index) + } + + override fun encodeFloat(value: Float) { + bundle.putFloat(elementKey, value) + } + + override fun encodeInt(value: Int) { + bundle.putInt(elementKey, value) + } + + override fun encodeLong(value: Long) { + bundle.putLong(elementKey, value) + } + + override fun encodeNull() { + /* no-op */ + } + + override fun encodeShort(value: Short) { + bundle.putShort(elementKey, value) + } + + override fun encodeString(value: String) { + bundle.putString(elementKey, value) + } + + override fun encodeNotNullMark() { + /* no-op */ + } +} \ No newline at end of file diff --git a/common/routing/src/main/kotlin/com/tangem/common/routing/bundle/BundleUtils.kt b/common/routing/src/main/kotlin/com/tangem/common/routing/bundle/BundleUtils.kt new file mode 100644 index 0000000000..4c638fde65 --- /dev/null +++ b/common/routing/src/main/kotlin/com/tangem/common/routing/bundle/BundleUtils.kt @@ -0,0 +1,60 @@ +package com.tangem.common.routing.bundle + +import android.os.Bundle +import kotlinx.serialization.DeserializationStrategy +import kotlinx.serialization.ExperimentalSerializationApi +import kotlinx.serialization.SerializationStrategy +import kotlinx.serialization.modules.EmptySerializersModule +import kotlinx.serialization.modules.SerializersModule + +val defaultSerializersModule: SerializersModule = EmptySerializersModule() + +/** + * Deserialize this bundle into an object of type [T]. + * + * @receiver [Bundle] to deserialize. + * @param deserializer [DeserializationStrategy] of the [T] class. + * + * @return Object of type T deserialized from bundle. + */ +@OptIn(ExperimentalSerializationApi::class) +fun Bundle.unbundle( + deserializer: DeserializationStrategy, + serializersModule: SerializersModule = defaultSerializersModule, +): T { + val decoder = BundleDecoder( + bundle = this, + elementsCount = -1, + isInitializer = true, + serializersModule = serializersModule, + ) + + return deserializer.deserialize(decoder) +} + +/** + * Serialize [T] into a bundle. + * + * @receiver Object to serialize. + * @param serializer [SerializationStrategy] of the [T] class. + * + * @return bundle serialized from value + */ +@OptIn(ExperimentalSerializationApi::class) +fun T.bundle( + serializer: SerializationStrategy, + serializersModule: SerializersModule = defaultSerializersModule, +): Bundle { + val bundle = Bundle(serializer.descriptor.elementsCount) + val encoder = BundleEncoder( + bundle = bundle, + parentBundle = null, + keyInParent = null, + isInitializer = true, + serializersModule = serializersModule, + ) + + serializer.serialize(encoder, value = this) + + return bundle +} \ No newline at end of file diff --git a/common/routing/src/main/kotlin/com/tangem/common/routing/bundle/RouteBundleParams.kt b/common/routing/src/main/kotlin/com/tangem/common/routing/bundle/RouteBundleParams.kt new file mode 100644 index 0000000000..12ae0795d3 --- /dev/null +++ b/common/routing/src/main/kotlin/com/tangem/common/routing/bundle/RouteBundleParams.kt @@ -0,0 +1,8 @@ +package com.tangem.common.routing.bundle + +import android.os.Bundle + +interface RouteBundleParams { + + fun getBundle(): Bundle +} \ No newline at end of file diff --git a/common/routing/src/main/kotlin/com/tangem/common/routing/entity/SerializableBundle.kt b/common/routing/src/main/kotlin/com/tangem/common/routing/entity/SerializableBundle.kt new file mode 100644 index 0000000000..fcac1b0422 --- /dev/null +++ b/common/routing/src/main/kotlin/com/tangem/common/routing/entity/SerializableBundle.kt @@ -0,0 +1,24 @@ +package com.tangem.common.routing.entity + +import android.os.Bundle +import kotlinx.serialization.Serializable + +@Serializable +data class SerializableBundle( + val map: Map, +) { + + constructor(bundle: Bundle) : this( + map = bundle.keySet().mapNotNull { key -> + bundle.getString(key)?.let { key to it } + }.toMap(), + ) + + fun toBundle(): Bundle { + return Bundle().apply { + map.forEach { (key, value) -> + putString(key, value) + } + } + } +} \ No newline at end of file diff --git a/common/routing/src/main/kotlin/com/tangem/common/routing/entity/SerializableIntent.kt b/common/routing/src/main/kotlin/com/tangem/common/routing/entity/SerializableIntent.kt new file mode 100644 index 0000000000..38ef6f2096 --- /dev/null +++ b/common/routing/src/main/kotlin/com/tangem/common/routing/entity/SerializableIntent.kt @@ -0,0 +1,51 @@ +package com.tangem.common.routing.entity + +import android.content.ComponentName +import android.content.Intent +import android.net.Uri +import kotlinx.serialization.Serializable + +@Serializable +data class SerializableIntent( + val action: String?, + val dataString: String?, + val categories: Set?, + val type: String?, + val packageValue: String?, + val component: String?, + val flags: Int, + val extras: SerializableBundle?, +) { + + constructor(intent: Intent) : this( + action = intent.action, + dataString = intent.dataString, + categories = intent.categories, + type = intent.type, + packageValue = intent.`package`, + component = intent.component?.flattenToString(), + flags = intent.flags, + extras = intent.extras?.let(::SerializableBundle), + ) + + fun toIntent(): Intent { + val intent = Intent() + + intent.action = action + intent.setDataAndType( + dataString?.let { Uri.parse(it) }, + type, + ) + categories?.let { categories -> + for (category in categories) { + intent.addCategory(category) + } + } + intent.`package` = packageValue + intent.component = component?.let { ComponentName.unflattenFromString(it) } + intent.flags = flags + extras?.let { intent.putExtras(it.toBundle()) } + + return intent + } +} \ No newline at end of file diff --git a/common/routing/src/main/kotlin/com/tangem/common/routing/utils/AppRouterExt.kt b/common/routing/src/main/kotlin/com/tangem/common/routing/utils/AppRouterExt.kt new file mode 100644 index 0000000000..1bc85f941f --- /dev/null +++ b/common/routing/src/main/kotlin/com/tangem/common/routing/utils/AppRouterExt.kt @@ -0,0 +1,16 @@ +package com.tangem.common.routing.utils + +import com.tangem.common.routing.AppRoute +import com.tangem.common.routing.AppRouter + +/** + * Pops routes from the navigation stack until the specified route [R] is found. + * + * ***Must be removed after Decompose migration.*** + * + * @param R The route to pop to. + * @param onComplete The callback to be invoked when the operation is complete. + */ +inline fun AppRouter.popTo(noinline onComplete: (isSuccess: Boolean) -> Unit = {}) { + popTo(R::class, onComplete) +} \ No newline at end of file diff --git a/common/src/main/java/com/tangem/common/Strings.kt b/common/src/main/java/com/tangem/common/Strings.kt deleted file mode 100644 index 943b0de614..0000000000 --- a/common/src/main/java/com/tangem/common/Strings.kt +++ /dev/null @@ -1,6 +0,0 @@ -package com.tangem.common - -object Strings { - - const val STARS = "\u2217\u2217\u2217" -} \ No newline at end of file diff --git a/features/manage-tokens/.gitignore b/common/ui-charts/.gitignore similarity index 100% rename from features/manage-tokens/.gitignore rename to common/ui-charts/.gitignore diff --git a/common/ui-charts/build.gradle.kts b/common/ui-charts/build.gradle.kts new file mode 100644 index 0000000000..319c15eebc --- /dev/null +++ b/common/ui-charts/build.gradle.kts @@ -0,0 +1,25 @@ +plugins { + alias(deps.plugins.android.library) + alias(deps.plugins.kotlin.android) + id("configuration") +} + +android { + namespace = "com.tangem.common.ui.charts" +} + +dependencies { + /** Project - Core */ + implementation(projects.core.ui) + + /** Compose */ + implementation(deps.tangem.vico.core) + implementation(deps.tangem.vico.compose) + implementation(deps.tangem.vico.compose.m3) + + implementation(deps.lifecycle.compose) + implementation(deps.compose.foundation) + implementation(deps.compose.material3) + implementation(deps.compose.ui.tooling) + implementation(deps.compose.ui.utils) +} \ No newline at end of file diff --git a/common/ui-charts/src/main/kotlin/com/tangem/common/ui/charts/MarketChart.kt b/common/ui-charts/src/main/kotlin/com/tangem/common/ui/charts/MarketChart.kt new file mode 100644 index 0000000000..9bbaeaa48b --- /dev/null +++ b/common/ui-charts/src/main/kotlin/com/tangem/common/ui/charts/MarketChart.kt @@ -0,0 +1,402 @@ +package com.tangem.common.ui.charts + +import android.content.res.Configuration +import androidx.annotation.FloatRange +import androidx.compose.foundation.background +import androidx.compose.foundation.layout.BoxScope +import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.fillMaxWidth +import androidx.compose.foundation.layout.height +import androidx.compose.material3.Button +import androidx.compose.material3.Text +import androidx.compose.runtime.* +import androidx.compose.ui.Modifier +import androidx.compose.ui.graphics.Color +import androidx.compose.ui.layout.onGloballyPositioned +import androidx.compose.ui.platform.LocalDensity +import androidx.compose.ui.platform.LocalFontFamilyResolver +import androidx.compose.ui.text.TextStyle +import androidx.compose.ui.text.font.FontStyle +import androidx.compose.ui.text.font.FontSynthesis +import androidx.compose.ui.text.font.FontWeight +import androidx.compose.ui.text.font.resolveAsTypeface +import androidx.compose.ui.tooling.preview.Preview +import androidx.compose.ui.tooling.preview.PreviewParameter +import androidx.compose.ui.unit.dp +import com.patrykandpatrick.vico.compose.cartesian.* +import com.patrykandpatrick.vico.compose.cartesian.axis.rememberAxisGuidelineComponent +import com.patrykandpatrick.vico.compose.cartesian.axis.rememberAxisLabelComponent +import com.patrykandpatrick.vico.compose.cartesian.axis.rememberBottomAxis +import com.patrykandpatrick.vico.compose.cartesian.axis.rememberCustomStartAxis +import com.patrykandpatrick.vico.compose.common.of +import com.patrykandpatrick.vico.core.cartesian.HorizontalLayout +import com.patrykandpatrick.vico.core.cartesian.Zoom +import com.patrykandpatrick.vico.core.cartesian.axis.* +import com.patrykandpatrick.vico.core.cartesian.data.AxisValueOverrider +import com.patrykandpatrick.vico.core.cartesian.data.CartesianValueFormatter +import com.patrykandpatrick.vico.core.cartesian.layer.LineCartesianLayer +import com.patrykandpatrick.vico.core.cartesian.marker.CartesianMarker +import com.patrykandpatrick.vico.core.cartesian.marker.CartesianMarkerVisibilityListener +import com.patrykandpatrick.vico.core.cartesian.marker.LineCartesianLayerMarkerTarget +import com.patrykandpatrick.vico.core.common.Dimensions +import com.patrykandpatrick.vico.core.common.component.LineComponent +import com.patrykandpatrick.vico.core.common.shape.Shape +import com.tangem.common.ui.charts.layer.rememberMarketChartLayer +import com.tangem.common.ui.charts.marker.rememberTangemChartMarker +import com.tangem.common.ui.charts.preview.MarketChartPreviewDataProvider +import com.tangem.common.ui.charts.state.* +import com.tangem.core.ui.components.SpacerH16 +import com.tangem.core.ui.res.TangemTheme +import com.tangem.core.ui.res.TangemThemePreview +import com.tangem.core.ui.utils.DateTimeFormatters +import com.tangem.core.ui.utils.toTimeFormat +import kotlinx.coroutines.launch +import java.math.BigDecimal +import java.math.RoundingMode + +private const val GUIDELINES_COUNT = 3 + +/** + * MarketChart ui component for representing coin prices. + * + * @param modifier The modifier to be applied to the chart. + * @param state The state of the Market Chart, which includes data and look of the chart. + * @param splitChartSegmentColor The color of the grayed by marker chart segment. + * @param backgroundSplitChartSegmentColorAlpha The alpha of the background the [splitChartSegmentColor] + * @param backgroundColorAlpha The alpha of the background color of the chart. + * @param noChartContent A composable function that defines the content to be displayed when there is no data to display. + */ +@Composable +fun MarketChart( + modifier: Modifier = Modifier, + state: MarketChartState = rememberMarketChartState(), + splitChartSegmentColor: Color, + @FloatRange(from = 0.0, to = 1.0) backgroundSplitChartSegmentColorAlpha: Float, + @FloatRange(from = 0.0, to = 1.0) backgroundColorAlpha: Float, + noChartContent: @Composable BoxScope.() -> Unit, +) { + var canvasWidth by remember { mutableIntStateOf(0) } + var canvasHeight by remember { mutableIntStateOf(0) } + + val layer = rememberLayerFromState( + state = state, + splitChartSegmentColor = splitChartSegmentColor, + backgroundColorAlpha = backgroundColorAlpha, + backgroundSplitChartSegmentColorAlpha = backgroundSplitChartSegmentColorAlpha, + canvasHeight = canvasHeight, + ) + val chart = rememberCartesianChart( + layer, + startAxis = rememberMarketChartStartAxis( + yValueFormatter = state.yValueFormatter, + ), + bottomAxis = rememberMarketChartBottomAxis( + xValueFormatter = state.xValueFormatter, + ), + ) + val marker = rememberTangemChartMarker( + color = state.chartColor, + innerCircleColor = Color.White, + ) + val density = LocalDensity.current + + CartesianChartHost( + modifier = modifier.onGloballyPositioned { + with(density) { + canvasWidth = it.size.width + canvasHeight = if (it.size.height != 0) { + // FIXME get height bounded to min max chart points + it.size.height - 20.dp.toPx().toInt() - 27.dp.toPx().toInt() + } else { + 0 + } + } + }, + chart = chart, + modelProducer = state.modelProducer, + scrollState = rememberVicoScrollState(scrollEnabled = false), + zoomState = rememberVicoZoomState(initialZoom = Zoom.Content, zoomEnabled = false), + horizontalLayout = HorizontalLayout.fullWidth(), + markerVisibilityListener = state.rememberMarketVisibilityListener(canvasWidth = canvasWidth), + diffAnimationSpec = null, + marker = marker, + placeholder = noChartContent, + ) +} + +@Composable +private fun MarketChartState.rememberMarketVisibilityListener(canvasWidth: Int): CartesianMarkerVisibilityListener { + val state = this + return remember(state.markerVisibilityListener, canvasWidth) { + val maxCanvasXFloat = canvasWidth.toFloat().takeIf { it != 0f } + + object : CartesianMarkerVisibilityListener { + override fun onShown(marker: CartesianMarker, targets: List) { + state.stopDrawingAnimation() + val xCanvas = (targets[0] as LineCartesianLayerMarkerTarget).canvasX + + state.markerFraction = maxCanvasXFloat?.let { xCanvas / it } + state.markerVisibilityListener.onShown(marker, targets) + } + + override fun onHidden(marker: CartesianMarker) { + state.markerFraction = null + state.markerVisibilityListener.onHidden(marker) + } + + override fun onUpdated(marker: CartesianMarker, targets: List) { + val xCanvas = (targets[0] as LineCartesianLayerMarkerTarget).canvasX + + state.markerFraction = maxCanvasXFloat?.let { xCanvas / it } + state.markerVisibilityListener.onUpdated(marker, targets) + } + } + } +} + +@Composable +private fun rememberLayerFromState( + state: MarketChartState, + splitChartSegmentColor: Color, + @FloatRange(from = 0.0, to = 1.0) backgroundColorAlpha: Float, + @FloatRange(from = 0.0, to = 1.0) backgroundSplitChartSegmentColorAlpha: Float, + canvasHeight: Int, +): LineCartesianLayer { + return rememberMarketChartLayer( + lineColor = state.chartColor, + backgroundLineColor = state.chartColor.copy(alpha = backgroundColorAlpha), + secondLineColor = splitChartSegmentColor, + backgroundSecondLineColor = splitChartSegmentColor.copy(alpha = backgroundSplitChartSegmentColorAlpha), + secondColorOnTheRightSide = state.markerHighlightRightSide.not(), + startDrawingAnimation = state.startDrawingAnimationState, + markerFraction = state.markerFraction, + axisValueOverrider = AxisValueOverrider.adaptiveYValues(yFraction = 1.2f, round = true), // FIXME ? + canvasHeight = canvasHeight, + ) +} + +@Composable +private fun rememberMarketChartStartAxis( + yValueFormatter: CartesianValueFormatter, +): VerticalAxis { + return rememberCustomStartAxis( + axis = null, + tick = null, + guideline = null, + labelGuideline = rememberChartAxisGuidelineComponent( + color = TangemTheme.colors.icon.inactive.copy(alpha = 0.12f), + ), + label = rememberAxisLabelComponent( + color = TangemTheme.colors.text.tertiary, + background = null, + padding = Dimensions.of( + start = TangemTheme.dimens.spacing4, + end = TangemTheme.dimens.spacing4, + ), + textSize = TangemTheme.typography.caption2.fontSize, + typeface = TangemTheme.typography.caption2.toGraphicsTypeFace(), + ), + horizontalLabelPosition = VerticalAxis.HorizontalLabelPosition.Inside, + verticalLabelPosition = VerticalAxis.VerticalLabelPosition.Center, + itemPlacer = AxisItemPlacer.Vertical.count({ GUIDELINES_COUNT }, false), + valueFormatter = yValueFormatter, + ) +} + +@Composable +fun rememberMarketChartBottomAxis( + xValueFormatter: CartesianValueFormatter, +): HorizontalAxis { + return rememberBottomAxis( + label = rememberAxisLabelComponent( + color = TangemTheme.colors.text.tertiary, + textSize = TangemTheme.typography.caption2.fontSize, + padding = Dimensions.of(top = TangemTheme.dimens.spacing20), + typeface = TangemTheme.typography.caption2.toGraphicsTypeFace(), + ), + tick = null, + axis = null, + guideline = null, + sizeConstraint = BaseAxis.SizeConstraint.Exact(sizeDp = 37f), // FIXME ? + itemPlacer = remember { + AxisItemPlacer.Horizontal.default( + spacing = 25, // FIXME ? + offset = 60, // FIXME ? + shiftExtremeTicks = false, + addExtremeLabelPadding = false, + ) + }, + valueFormatter = xValueFormatter, + ) +} + +@Composable +private fun rememberChartAxisGuidelineComponent(color: Color): LineComponent { + return rememberAxisGuidelineComponent( + color = color, + shape = Shape.Rectangle, + margins = Dimensions( + startDp = TangemTheme.dimens.spacing4.value, + endDp = TangemTheme.dimens.spacing4.value, + topDp = 0f, + bottomDp = 0f, + ), + thickness = TangemTheme.dimens.size2, + ) +} + +@Composable +internal fun TextStyle.toGraphicsTypeFace(): android.graphics.Typeface { + val resolver = LocalFontFamilyResolver.current + return remember(resolver, this) { + resolver.resolveAsTypeface( + fontFamily = this.fontFamily, + fontWeight = this.fontWeight ?: FontWeight.Normal, + fontStyle = this.fontStyle ?: FontStyle.Normal, + fontSynthesis = this.fontSynthesis ?: FontSynthesis.All, + ) + }.value +} + +// region Preview + +@Suppress("LongMethod") +@Preview(showBackground = true, widthDp = 360) +@Preview(showBackground = true, widthDp = 360, uiMode = Configuration.UI_MODE_NIGHT_YES) +@Composable +private fun MarketChartPreview( + @PreviewParameter(MarketChartPreviewDataProvider::class) previewData: Pair, List>, +) { + val y = previewData.second + val x = previewData.first + + val dataProducer = remember { + MarketChartDataProducer.build { + chartLook = MarketChartLook( + type = MarketChartLook.Type.Growing, + markerHighlightRightSide = true, + animationOnDataChange = true, + ) + } + } + + LaunchedEffect(key1 = Unit) { + dataProducer.runTransactionSuspend { + chartData = MarketChartData.Data( + x = x, + y = y, + ) + updateLook { + it.copy( + xAxisFormatter = { value -> + value.toLong().toTimeFormat(DateTimeFormatters.dateMMMMd) + }, + yAxisFormatter = { value -> + value.setScale(3, RoundingMode.HALF_UP).toPlainString() + }, + ) + } + } + } + var markerPoint by remember { + mutableStateOf(Pair(null, null)) + } + + val coroutineScope = rememberCoroutineScope() + val look by dataProducer.lookState.collectAsState() + + TangemThemePreview { + val growingColor = TangemTheme.colors.icon.accent + val fallingColor = TangemTheme.colors.icon.warning + + val chartState = rememberMarketChartState( + dataProducer = dataProducer, + onMarkerShown = { x, y -> + markerPoint = Pair(x, y) + }, + colorMapper = { + when (it) { + MarketChartLook.Type.Growing -> growingColor + MarketChartLook.Type.Falling -> fallingColor + } + }, + ) + + Column( + modifier = Modifier + .background(TangemTheme.colors.background.primary) + .fillMaxWidth(), + ) { + Text(text = "Point: ${markerPoint.first}, ${markerPoint.second}") + + MarketChart( + modifier = Modifier + .fillMaxWidth() + .background(TangemTheme.colors.background.tertiary) + .height(173.dp), + state = chartState, + splitChartSegmentColor = TangemTheme.colors.icon.inactive, + backgroundSplitChartSegmentColorAlpha = 0.24f, + backgroundColorAlpha = 0.24f, + noChartContent = { }, + ) + SpacerH16() + + Button(onClick = { chartState.startDrawingAnimation() }) { + Text("Start drawing animation") + } + Button( + onClick = { + dataProducer.runTransaction { + updateLook { + it.copy(markerHighlightRightSide = !it.markerHighlightRightSide) + } + } + }, + ) { + Text( + text = "Change marker highlight side", + ) + } + Button(onClick = { + coroutineScope.launch { + dataProducer.runTransactionSuspend { + updateData { + MarketChartData.Data( + x = it.x, + y = it.y.reversed(), + ) + } + } + } + },) { + Text("Change Data") + } + Button(onClick = { + dataProducer.runTransaction { + updateLook { it.copy(animationOnDataChange = it.animationOnDataChange.not()) } + } + },) { + Text("Change animationOnDataChange = ${look.animationOnDataChange}") + } + + Button(onClick = { + dataProducer.runTransaction { + updateLook { + it.copy( + type = if (it.type == MarketChartLook.Type.Growing) { + MarketChartLook.Type.Falling + } else { + MarketChartLook.Type.Growing + }, + ) + } + } + },) { + Text("Change color type") + } + } + } +} + +// endregion Preview \ No newline at end of file diff --git a/common/ui-charts/src/main/kotlin/com/tangem/common/ui/charts/MarketChartMini.kt b/common/ui-charts/src/main/kotlin/com/tangem/common/ui/charts/MarketChartMini.kt new file mode 100644 index 0000000000..d9902450d3 --- /dev/null +++ b/common/ui-charts/src/main/kotlin/com/tangem/common/ui/charts/MarketChartMini.kt @@ -0,0 +1,111 @@ +package com.tangem.common.ui.charts + +import android.content.res.Configuration +import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.lazy.LazyColumn +import androidx.compose.runtime.Composable +import androidx.compose.runtime.remember +import androidx.compose.ui.Modifier +import androidx.compose.ui.graphics.Brush +import androidx.compose.ui.graphics.Color +import androidx.compose.ui.graphics.toArgb +import androidx.compose.ui.tooling.preview.Preview +import androidx.compose.ui.unit.dp +import com.patrykandpatrick.vico.compose.cartesian.* +import com.patrykandpatrick.vico.compose.cartesian.layer.rememberLineCartesianLayer +import com.patrykandpatrick.vico.compose.cartesian.layer.rememberLineSpec +import com.patrykandpatrick.vico.compose.common.shader.BrushShader +import com.patrykandpatrick.vico.core.cartesian.HorizontalLayout +import com.patrykandpatrick.vico.core.cartesian.Zoom +import com.patrykandpatrick.vico.core.cartesian.data.CartesianChartModel +import com.patrykandpatrick.vico.core.cartesian.data.LineCartesianLayerModel +import com.patrykandpatrick.vico.core.common.shader.ColorShader +import com.tangem.common.ui.charts.state.MarketChartLook +import com.tangem.common.ui.charts.state.MarketChartRawData +import com.tangem.core.ui.components.SpacerH16 +import com.tangem.core.ui.res.TangemTheme +import com.tangem.core.ui.res.TangemThemePreview +import kotlin.random.Random + +@Composable +fun MarketChartMini( + rawData: MarketChartRawData, + modifier: Modifier = Modifier, + type: MarketChartLook.Type = MarketChartLook.Type.Growing, + growingColor: Color = TangemTheme.colors.icon.accent, + fallingColor: Color = TangemTheme.colors.icon.warning, +) { + val model = remember(rawData) { + CartesianChartModel(LineCartesianLayerModel.build { series(rawData.y) }) + } + + val lineColor = when (type) { + MarketChartLook.Type.Growing -> growingColor + MarketChartLook.Type.Falling -> fallingColor + } + + val lineSpec = rememberLineSpec( + shader = ColorShader(lineColor.toArgb()), + thickness = 1.dp, + backgroundShader = BrushShader( + brush = Brush.verticalGradient( + colors = listOf(lineColor.copy(alpha = 0.22f), Color.Transparent), + ), + ), + ) + + val layer = rememberLineCartesianLayer(listOf(lineSpec)) + val chart = rememberCartesianChart(layer) + + CartesianChartHost( + modifier = modifier, + chart = chart, + model = model, + zoomState = rememberVicoZoomState(initialZoom = Zoom.Content, zoomEnabled = false), + scrollState = rememberVicoScrollState(scrollEnabled = false), + horizontalLayout = HorizontalLayout.fullWidth(), + ) +} + +// region Preview + +@Preview(showBackground = true, widthDp = 360) +@Preview(showBackground = true, widthDp = 360, uiMode = Configuration.UI_MODE_NIGHT_YES) +@Composable +private fun Preview() { + val data = MarketChartRawData( + x = List(20) { Random.nextFloat() }, + y = List(20) { Random.nextFloat() }, + ) + + TangemThemePreview { + Column { + MarketChartMini(rawData = data, type = MarketChartLook.Type.Growing) + SpacerH16() + MarketChartMini(rawData = data, type = MarketChartLook.Type.Falling) + } + } +} + +@Preview(showBackground = true, widthDp = 360) +@Preview(showBackground = true, widthDp = 360, uiMode = Configuration.UI_MODE_NIGHT_YES) +@Composable +private fun PreviewColumn() { + val data = MarketChartRawData( + x = List(20) { Random.nextFloat() }, + y = List(20) { Random.nextFloat() }, + ) + + TangemThemePreview { + LazyColumn { + items(100) { + MarketChartMini( + rawData = data, + type = if (it % 3 == 0) MarketChartLook.Type.Growing else MarketChartLook.Type.Falling, + ) + } + } + } +} + +// endregion Preview \ No newline at end of file diff --git a/common/ui-charts/src/main/kotlin/com/tangem/common/ui/charts/layer/MarketChartLayer.kt b/common/ui-charts/src/main/kotlin/com/tangem/common/ui/charts/layer/MarketChartLayer.kt new file mode 100644 index 0000000000..b224a1838d --- /dev/null +++ b/common/ui-charts/src/main/kotlin/com/tangem/common/ui/charts/layer/MarketChartLayer.kt @@ -0,0 +1,329 @@ +package com.tangem.common.ui.charts.layer + +import android.content.res.Configuration +import androidx.annotation.FloatRange +import androidx.compose.animation.core.LinearEasing +import androidx.compose.animation.core.animate +import androidx.compose.animation.core.tween +import androidx.compose.foundation.background +import androidx.compose.foundation.layout.Arrangement +import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.fillMaxWidth +import androidx.compose.runtime.* +import androidx.compose.ui.Modifier +import androidx.compose.ui.graphics.Brush +import androidx.compose.ui.graphics.Color +import androidx.compose.ui.graphics.toArgb +import androidx.compose.ui.tooling.preview.Preview +import androidx.compose.ui.tooling.preview.PreviewParameter +import androidx.compose.ui.unit.dp +import com.patrykandpatrick.vico.compose.cartesian.CartesianChartHost +import com.patrykandpatrick.vico.compose.cartesian.fullWidth +import com.patrykandpatrick.vico.compose.cartesian.layer.rememberLineCartesianLayer +import com.patrykandpatrick.vico.compose.cartesian.layer.rememberLineSpec +import com.patrykandpatrick.vico.compose.cartesian.layer.rememberSplitLineSpec +import com.patrykandpatrick.vico.compose.cartesian.rememberCartesianChart +import com.patrykandpatrick.vico.compose.cartesian.rememberVicoZoomState +import com.patrykandpatrick.vico.compose.common.shader.BrushShader +import com.patrykandpatrick.vico.core.cartesian.HorizontalLayout +import com.patrykandpatrick.vico.core.cartesian.Zoom +import com.patrykandpatrick.vico.core.cartesian.data.AxisValueOverrider +import com.patrykandpatrick.vico.core.cartesian.data.CartesianChartModel +import com.patrykandpatrick.vico.core.cartesian.data.LineCartesianLayerModel +import com.patrykandpatrick.vico.core.cartesian.layer.LineCartesianLayer +import com.patrykandpatrick.vico.core.common.shader.ColorShader +import com.patrykandpatrick.vico.core.common.shader.DynamicShader +import com.tangem.common.ui.charts.preview.MarketChartPreviewDataProvider +import com.tangem.core.ui.res.TangemTheme +import com.tangem.core.ui.res.TangemThemePreview +import java.math.BigDecimal + +/** + * Creates and remembers a LineCartesianLayer for a chart with specific characteristics. + * + * @param lineColor The color of the main line in the chart. + * @param backgroundLineColor The color of the line's background. + * @param secondLineColor The color of the line for the second part of the chart. + * @param backgroundSecondLineColor The color of the line's background for the second part of the chart. + * @param startDrawingAnimation A mutable state that triggers the start of the drawing animation when set to true. + * @param axisValueOverrider An AxisValueOverrider that provides custom values for the axis. + * @param secondColorOnTheRightSide A boolean that determines if the second color should be on the right side of the chart. Default is false. + * @param markerFraction A float between 0.0 and 1.0 that represents the fraction of the chart where the marker is located. Default is null. + * + * @return A LineCartesianLayer that represents a layer in a chart with the specified characteristics. + */ +@Suppress("LongParameterList") +@Composable +internal fun rememberMarketChartLayer( + lineColor: Color, + backgroundLineColor: Color, + secondLineColor: Color, + backgroundSecondLineColor: Color, + startDrawingAnimation: MutableState, + axisValueOverrider: AxisValueOverrider, + secondColorOnTheRightSide: Boolean, + @FloatRange(from = 0.0, to = 1.0) markerFraction: Float?, + canvasHeight: Int, +): LineCartesianLayer { + var animationFraction: Float? by remember { mutableStateOf(null) } + + LaunchedEffect(startDrawingAnimation.value) { + animationFraction = null + if (startDrawingAnimation.value) { + animate( + initialValue = 0f, + targetValue = 1f, + animationSpec = tween(easing = LinearEasing, durationMillis = 1000), + ) { start, _ -> + if (start == 1f) { + animationFraction = null + startDrawingAnimation.value = false + } else { + animationFraction = start + } + } + } + } + + return rememberRawMarketChartLayer( + lineColor = lineColor, + backgroundLineColor = backgroundLineColor, + secondLineColor = secondLineColor, + backgroundSecondLineColor = backgroundSecondLineColor, + axisValueOverrider = axisValueOverrider, + secondColorOnTheRightSide = secondColorOnTheRightSide, + markerFraction = markerFraction, + animationFraction = animationFraction, + canvasHeight = canvasHeight, + ) +} + +@Suppress("LongParameterList") +@Composable +private fun rememberRawMarketChartLayer( + lineColor: Color, + backgroundLineColor: Color, + secondLineColor: Color, + backgroundSecondLineColor: Color, + axisValueOverrider: AxisValueOverrider, + canvasHeight: Int, + secondColorOnTheRightSide: Boolean = false, + @FloatRange(from = 0.0, to = 1.0) markerFraction: Float? = null, + @FloatRange(from = 0.0, to = 1.0) animationFraction: Float? = null, +): LineCartesianLayer { + val backgroundColorLineGradient = listOf(backgroundLineColor, Color.Transparent) + val backgroundSecondLineColorGradient = listOf(backgroundSecondLineColor, Color.Transparent) + + val markerSet = markerFraction != null + val animationRunning = animationFraction != null && animationFraction != 1f + + val layerColors = when { + !animationRunning && markerSet && secondColorOnTheRightSide -> { + LayerColors( + lineColor = lineColor, + backLineColor = backgroundColorLineGradient, + lineColorRight = secondLineColor, + backLineColorRight = backgroundSecondLineColorGradient, + ) + } + !animationRunning && markerSet && !secondColorOnTheRightSide -> { + LayerColors( + lineColor = secondLineColor, + backLineColor = backgroundSecondLineColorGradient, + lineColorRight = lineColor, + backLineColorRight = backgroundColorLineGradient, + ) + } + animationRunning -> { + LayerColors( + lineColor = lineColor, + backLineColor = backgroundColorLineGradient, + lineColorRight = Color.Transparent, + backLineColorRight = listOf(Color.Transparent, Color.Transparent), + ) + } + else -> { + LayerColors( + lineColor = lineColor, + backLineColor = backgroundColorLineGradient, + ) + } + } + + return rememberLayer( + fractionValue = animationFraction ?: markerFraction, + axisValueOverrider = axisValueOverrider, + layerColors = layerColors, + canvasHeight = canvasHeight, + ) +} + +private data class LayerColors( + val lineColor: Color, + val backLineColor: List, + val lineColorRight: Color? = null, + val backLineColorRight: List? = null, +) + +@Composable +private fun rememberLayer( + fractionValue: Float?, + axisValueOverrider: AxisValueOverrider, + layerColors: LayerColors, + canvasHeight: Int, +): LineCartesianLayer { + val endGradientColorPosition = if (canvasHeight != 0) { + canvasHeight * END_GRADIENT_COLOR_POSITION_PERCENTAGE + } else { + Float.POSITIVE_INFINITY + } + + return rememberLineCartesianLayer( + listOf( + if (layerColors.lineColorRight == null || layerColors.backLineColorRight == null || fractionValue == null) { + rememberLineSpec( + shader = remember(layerColors.lineColor) { ColorShader(color = layerColors.lineColor.toArgb()) }, + backgroundShader = remember(layerColors.backLineColor, endGradientColorPosition) { + BrushShader( + brush = Brush.verticalGradient( + colors = layerColors.backLineColor, + endY = endGradientColorPosition, + ), + ) + }, + ) + } else { + rememberSplitLineSpec( + shader = remember(layerColors.lineColor, layerColors.lineColorRight, fractionValue) { + DynamicShader.Companion.horizontalGradient( + colors = intArrayOf(layerColors.lineColor.toArgb(), layerColors.lineColorRight.toArgb()), + positions = floatArrayOf(fractionValue, fractionValue), + ) + }, + backgroundShaderFirst = remember(layerColors.backLineColor, endGradientColorPosition) { + BrushShader( + brush = Brush.verticalGradient( + colors = layerColors.backLineColor, + endY = endGradientColorPosition, + ), + ) + }, + backgroundShaderSecond = remember(layerColors.backLineColorRight, endGradientColorPosition) { + BrushShader( + brush = Brush.verticalGradient( + colors = layerColors.backLineColorRight, + endY = endGradientColorPosition, + ), + ) + }, + xSplitFraction = fractionValue, + ) + }, + ), + axisValueOverrider = axisValueOverrider, + ) +} + +private const val END_GRADIENT_COLOR_POSITION_PERCENTAGE = 0.9f + +// region Preview + +@Suppress("LongMethod") +@Preview(showBackground = true, widthDp = 360) +@Preview(showBackground = true, widthDp = 360, uiMode = Configuration.UI_MODE_NIGHT_YES) +@Composable +private fun LayerChartPreview( + @PreviewParameter(MarketChartPreviewDataProvider::class) previewData: Pair, List>, +) { + val y = previewData.second.map { it.toFloat() } + val x = List(y.size) { it.toFloat() } + val model = CartesianChartModel(LineCartesianLayerModel.build { series(x, y) }) + var lineColor by remember { + mutableStateOf(Color.Blue) + } + + TangemThemePreview { + Column( + modifier = Modifier.background(TangemTheme.colors.background.primary), + verticalArrangement = Arrangement.spacedBy(48.dp), + ) { + CartesianChartHost( + modifier = Modifier.fillMaxWidth(), + chart = rememberCartesianChart( + rememberRawMarketChartLayer( + lineColor = lineColor, + backgroundLineColor = lineColor.copy(alpha = 0.24f), + secondLineColor = Color.Gray, + backgroundSecondLineColor = Color.Gray.copy(alpha = 0.24f), + secondColorOnTheRightSide = true, + axisValueOverrider = AxisValueOverrider.fixed(minY = model.models[0].minY), + canvasHeight = 495, + ), + ), + zoomState = rememberVicoZoomState(initialZoom = Zoom.Content, zoomEnabled = false), + horizontalLayout = HorizontalLayout.fullWidth(), + model = model, + ) + + CartesianChartHost( + modifier = Modifier.fillMaxWidth(), + chart = rememberCartesianChart( + rememberRawMarketChartLayer( + lineColor = lineColor, + backgroundLineColor = lineColor.copy(alpha = 0.24f), + secondLineColor = Color.Gray, + backgroundSecondLineColor = Color.Gray.copy(alpha = 0.24f), + markerFraction = 0.35f, + secondColorOnTheRightSide = true, + axisValueOverrider = AxisValueOverrider.fixed(minY = model.models[0].minY), + canvasHeight = 495, + ), + ), + zoomState = rememberVicoZoomState(initialZoom = Zoom.Content, zoomEnabled = false), + horizontalLayout = HorizontalLayout.fullWidth(), + model = model, + ) + + CartesianChartHost( + modifier = Modifier.fillMaxWidth(), + chart = rememberCartesianChart( + rememberRawMarketChartLayer( + lineColor = lineColor, + backgroundLineColor = lineColor.copy(alpha = 0.24f), + secondLineColor = Color.Gray, + backgroundSecondLineColor = Color.Gray.copy(alpha = 0.24f), + markerFraction = 0.35f, + secondColorOnTheRightSide = false, + axisValueOverrider = AxisValueOverrider.fixed(minY = model.models[0].minY), + canvasHeight = 495, + ), + ), + zoomState = rememberVicoZoomState(initialZoom = Zoom.Content, zoomEnabled = false), + horizontalLayout = HorizontalLayout.fullWidth(), + model = model, + ) + + CartesianChartHost( + modifier = Modifier.fillMaxWidth(), + chart = rememberCartesianChart( + rememberRawMarketChartLayer( + lineColor = lineColor, + backgroundLineColor = lineColor.copy(alpha = 0.24f), + secondLineColor = lineColor, + backgroundSecondLineColor = lineColor.copy(alpha = 0.24f), + markerFraction = 0.35f, + secondColorOnTheRightSide = true, + animationFraction = 0.7f, + axisValueOverrider = AxisValueOverrider.fixed(minY = model.models[0].minY), + canvasHeight = 495, + ), + ), + zoomState = rememberVicoZoomState(initialZoom = Zoom.Content, zoomEnabled = false), + horizontalLayout = HorizontalLayout.fullWidth(), + model = model, + ) + } + } +} + +// endregion Preview \ No newline at end of file diff --git a/common/ui-charts/src/main/kotlin/com/tangem/common/ui/charts/marker/ChartMarker.kt b/common/ui-charts/src/main/kotlin/com/tangem/common/ui/charts/marker/ChartMarker.kt new file mode 100644 index 0000000000..e27ce63a70 --- /dev/null +++ b/common/ui-charts/src/main/kotlin/com/tangem/common/ui/charts/marker/ChartMarker.kt @@ -0,0 +1,146 @@ +package com.tangem.common.ui.charts.marker + +import android.content.res.Configuration +import androidx.compose.foundation.background +import androidx.compose.foundation.layout.Box +import androidx.compose.foundation.layout.fillMaxWidth +import androidx.compose.runtime.Composable +import androidx.compose.runtime.remember +import androidx.compose.ui.Modifier +import androidx.compose.ui.graphics.Color +import androidx.compose.ui.tooling.preview.Preview +import androidx.compose.ui.tooling.preview.PreviewParameter +import androidx.compose.ui.unit.dp +import com.patrykandpatrick.vico.compose.cartesian.CartesianChartHost +import com.patrykandpatrick.vico.compose.cartesian.fullWidth +import com.patrykandpatrick.vico.compose.cartesian.layer.rememberLineCartesianLayer +import com.patrykandpatrick.vico.compose.cartesian.layer.rememberLineSpec +import com.patrykandpatrick.vico.compose.cartesian.rememberCartesianChart +import com.patrykandpatrick.vico.compose.cartesian.rememberVicoZoomState +import com.patrykandpatrick.vico.compose.common.component.rememberLayeredComponent +import com.patrykandpatrick.vico.compose.common.component.rememberShapeComponent +import com.patrykandpatrick.vico.compose.common.component.rememberUnboundedLineComponent +import com.patrykandpatrick.vico.compose.common.of +import com.patrykandpatrick.vico.compose.common.shader.color +import com.patrykandpatrick.vico.compose.common.shape.dashed +import com.patrykandpatrick.vico.core.cartesian.* +import com.patrykandpatrick.vico.core.cartesian.data.AxisValueOverrider +import com.patrykandpatrick.vico.core.cartesian.data.CartesianChartModel +import com.patrykandpatrick.vico.core.cartesian.data.LineCartesianLayerModel +import com.patrykandpatrick.vico.core.cartesian.marker.CartesianMarker +import com.patrykandpatrick.vico.core.cartesian.marker.DefaultCartesianMarker +import com.patrykandpatrick.vico.core.common.Dimensions +import com.patrykandpatrick.vico.core.common.component.TextComponent +import com.patrykandpatrick.vico.core.common.shader.DynamicShader +import com.patrykandpatrick.vico.core.common.shape.Shape +import com.tangem.common.ui.charts.preview.MarketChartPreviewDataProvider +import com.tangem.core.ui.res.TangemTheme +import com.tangem.core.ui.res.TangemThemePreview +import java.math.BigDecimal + +/** + * @param color The color of the indicator and guideline. + * @param innerCircleColor The color of the inner circle of the indicator. + * + * @return A [CartesianMarker] that consists of a dashed guideline and a layered indicator with a shadow effect. + */ +@Composable +internal fun rememberTangemChartMarker(color: Color, innerCircleColor: Color): CartesianMarker { + val indicatorFrontComponent = rememberShapeComponent( + shape = Shape.Pill, + color = innerCircleColor, + ) + val indicatorCenterComponent = rememberShapeComponent( + shape = Shape.Pill, + color = color, + ) + val indicatorRearComponent = rememberShapeComponent( + shape = Shape.Pill, + color = if (color == Color.Transparent) { + Color.Transparent + } else { + color.copy(alpha = INDICATOR_REAR_COLOR_ALPHA) + }, + ) + val indicator = rememberLayeredComponent( + rear = indicatorRearComponent, + front = rememberLayeredComponent( + rear = indicatorCenterComponent, + front = indicatorFrontComponent, + padding = indicatorPadding, + ), + padding = indicatorPadding, + ) + val guideline = rememberUnboundedLineComponent( + color = color, + verticalAddDrawSpace = TangemTheme.dimens.spacing24, + shape = remember { Shape.dashed(Shape.Rectangle, 4.dp, 4.dp) }, + ) + return remember(indicator, guideline) { + object : DefaultCartesianMarker( + label = TextComponent.build { textSizeSp = 0f }, + indicator = indicator, + indicatorSizeDp = INDICATOR_SIZE_DP, + guideline = guideline, + ) { + override fun getInsets( + context: CartesianMeasureContext, + outInsets: Insets, + horizontalDimensions: HorizontalDimensions, + ) { + with(context) { + super.getInsets(context, outInsets, horizontalDimensions) + val baseShadowInsetDp = + CLIPPING_FREE_SHADOW_RADIUS_MULTIPLIER * LABEL_BACKGROUND_SHADOW_RADIUS_DP + outInsets.top += (baseShadowInsetDp - LABEL_BACKGROUND_SHADOW_DY_DP).pixels + outInsets.bottom += (baseShadowInsetDp + LABEL_BACKGROUND_SHADOW_DY_DP).pixels + } + } + } + } +} + +private val indicatorPadding = Dimensions.of(3.dp) +private const val LABEL_BACKGROUND_SHADOW_RADIUS_DP = 4f +private const val LABEL_BACKGROUND_SHADOW_DY_DP = 2f +private const val CLIPPING_FREE_SHADOW_RADIUS_MULTIPLIER = 1.4f +private const val INDICATOR_SIZE_DP = 16f +private const val INDICATOR_REAR_COLOR_ALPHA = .24f + +// region Preview + +@Preview(showBackground = true, widthDp = 360) +@Preview(showBackground = true, widthDp = 360, uiMode = Configuration.UI_MODE_NIGHT_YES) +@Composable +private fun TangemChartMarkerPreview( + @PreviewParameter(MarketChartPreviewDataProvider::class) previewData: Pair, List>, +) { + val marker = rememberTangemChartMarker(Color.Red, Color.White) + val y = previewData.second.map { it.toFloat() } + val x = List(y.size) { it.toFloat() } + val model = CartesianChartModel(LineCartesianLayerModel.build { series(x, y) }) + + val centerAprx = (model.models[0].minX + model.models[0].maxX) / 2f + val center = model.models[0].getXDeltaGcd().let { centerAprx - centerAprx % it } + + TangemThemePreview { + Box(modifier = Modifier.background(TangemTheme.colors.background.primary)) { + CartesianChartHost( + modifier = Modifier.fillMaxWidth(), + chart = rememberCartesianChart( + rememberLineCartesianLayer( + listOf(rememberLineSpec(shader = DynamicShader.color(Color.Blue))), + axisValueOverrider = AxisValueOverrider.fixed(minY = model.models[0].minY), + ), + persistentMarkers = mapOf(center to marker), + ), + model = model, + marker = marker, + zoomState = rememberVicoZoomState(initialZoom = Zoom.Content, zoomEnabled = false), + horizontalLayout = HorizontalLayout.fullWidth(), + ) + } + } +} + +// endregion Preview \ No newline at end of file diff --git a/common/ui-charts/src/main/kotlin/com/tangem/common/ui/charts/preview/MarketChartPreviewDataProvider.kt b/common/ui-charts/src/main/kotlin/com/tangem/common/ui/charts/preview/MarketChartPreviewDataProvider.kt new file mode 100644 index 0000000000..662cb41bc6 --- /dev/null +++ b/common/ui-charts/src/main/kotlin/com/tangem/common/ui/charts/preview/MarketChartPreviewDataProvider.kt @@ -0,0 +1,152 @@ +@file:Suppress("MagicNumber") + +package com.tangem.common.ui.charts.preview + +import androidx.compose.ui.tooling.preview.PreviewParameterProvider +import java.math.BigDecimal + +internal class MarketChartPreviewDataProvider : PreviewParameterProvider, List>> { + override val values: Sequence, List>> + get() { + val bitcoinPrice = listOf( + 59270, 61748, 61941, 62889, 62740, 62989, 63858, 63608, 63951, 63917, + 63253, 63765, 63862, 64502, 63876, 64028, 63875, 64531, 64249, 63680, + 63228, 63159, 63249, 63664, 63469, 63711, 63003, 62333, 62882, 62183, + 62231, 62244, 62200, 61188, 61683, 61199, 61036, 62116, 62436, 63065, + 62908, 63067, 63294, 60904, 60677, 60790, 60705, 61041, 60667, 61158, + 61112, 60795, 60900, 60771, 61124, 61343, 61371, 61484, 61133, 62372, + 62704, 63007, 63092, 62905, 62470, 62019, 61756, 61776, 61557, 61540, + 61904, 62151, 62419, 64663, 65955, 66229, 65991, 66176, 66517, 65838, + 65210, 65216, 65611, 66467, 66209, 67247, 66913, 67059, 66978, 66845, + 67240, 66874, 66993, 66940, 67185, 67330, 67340, 66845, 66062, 66273, + 66645, 66865, 67005, 67382, 70049, 71464, 71293, 70875, 71137, 69720, + 69323, 70139, 69964, 69716, 69855, 70442, 69774, 69125, 69404, 69714, + 69967, 68042, 67077, 67938, 67833, 67182, 67306, 68327, 69093, 68517, + 68726, 68759, 69061, 68880, 69148, 69305, 69044, 69313, 69122, 68821, + 68854, 68506, 68823, 68613, 68420, 70356, 69241, 69401, 68004, 67630, + 68311, 68311, 68291, 68302, 68717, 67926, 67690, 67314, 67285, 67567, + 68026, 67552, 67740, 68519, 68611, 68363, 68503, 68171, 68326, 67121, + 67626, 67481, 67657, 67567, 67608, 67607, 67683, 67729, 67733, 67709, + ).map { it.toBigDecimal() } + val bitcoinTimestamps = listOf( + 1714752000000, 1714766400000, 1714780800000, 1714795200000, 1714809600000, + 1714824000000, 1714838400000, 1714852800000, 1714867200000, 1714881600000, + 1714896000000, 1714910400000, 1714924800000, 1714939200000, 1714953600000, + 1714968000000, 1714982400000, 1714996800000, 1715011200000, 1715025600000, + 1715040000000, 1715054400000, 1715068800000, 1715083200000, 1715097600000, + 1715112000000, 1715126400000, 1715140800000, 1715155200000, 1715169600000, + 1715184000000, 1715198400000, 1715212800000, 1715227200000, 1715241600000, + 1715256000000, 1715270400000, 1715284800000, 1715299200000, 1715313600000, + 1715328000000, 1715342400000, 1715356800000, 1715371200000, 1715385600000, + 1715400000000, 1715414400000, 1715428800000, 1715443200000, 1715457600000, + 1715472000000, 1715486400000, 1715500800000, 1715515200000, 1715529600000, + 1715544000000, 1715558400000, 1715572800000, 1715587200000, 1715601600000, + 1715616000000, 1715630400000, 1715644800000, 1715659200000, 1715673600000, + 1715688000000, 1715702400000, 1715716800000, 1715731200000, 1715745600000, + 1715760000000, 1715774400000, 1715788800000, 1715803200000, 1715817600000, + 1715832000000, 1715846400000, 1715860800000, 1715875200000, 1715889600000, + 1715904000000, 1715918400000, 1715932800000, 1715947200000, 1715961600000, + 1715976000000, 1715990400000, 1716004800000, 1716019200000, 1716033600000, + 1716048000000, 1716062400000, 1716076800000, 1716091200000, 1716105600000, + 1716120000000, 1716134400000, 1716148800000, 1716163200000, 1716177600000, + 1716192000000, 1716206400000, 1716220800000, 1716235200000, 1716249600000, + 1716264000000, 1716278400000, 1716292800000, 1716307200000, 1716321600000, + 1716336000000, 1716350400000, 1716364800000, 1716379200000, 1716393600000, + 1716408000000, 1716422400000, 1716436800000, 1716451200000, 1716465600000, + 1716480000000, 1716494400000, 1716508800000, 1716523200000, 1716537600000, + 1716552000000, 1716566400000, 1716580800000, 1716595200000, 1716609600000, + 1716624000000, 1716638400000, 1716652800000, 1716667200000, 1716681600000, + 1716696000000, 1716710400000, 1716724800000, 1716739200000, 1716753600000, + 1716768000000, 1716782400000, 1716796800000, 1716811200000, 1716825600000, + 1716840000000, 1716854400000, 1716868800000, 1716883200000, 1716897600000, + 1716912000000, 1716926400000, 1716940800000, 1716955200000, 1716969600000, + 1716984000000, 1716998400000, 1717012800000, 1717027200000, 1717041600000, + 1717056000000, 1717070400000, 1717084800000, 1717099200000, 1717113600000, + 1717128000000, 1717142400000, 1717156800000, 1717171200000, 1717185600000, + 1717200000000, 1717214400000, 1717228800000, 1717243200000, 1717257600000, + 1717272000000, 1717286400000, 1717300800000, 1717315200000, 1717329600000, + ).map { it.toBigDecimal() } + val notcoinPrice = listOf( + "0.02026708", "0.02033274", "0.02112643", "0.02090579", + "0.02047231", "0.0215645", "0.0089055", "0.00674459", + "0.00733586", "0.00758165", "0.0068592", "0.00680505", + "0.00685493", "0.00702113", "0.00725545", "0.00696515", + "0.00681556", "0.00677416", "0.00669383", "0.00659057", + "0.00668081", "0.0066211", "0.0065232", "0.00612542", + "0.00600531", "0.00570974", "0.00559875", "0.00555247", + "0.005495", "0.00547841", "0.00545514", "0.00553865", + "0.00563302", "0.00568475", "0.00562512", "0.00551265", + "0.005398", "0.00560001", "0.00572701", "0.00563223", + "0.00555209", "0.00549261", "0.00524999", "0.00531381", + "0.00539702", "0.00530647", "0.00533963", "0.00527143", + "0.00525981", "0.00495323", "0.00481584", "0.0048854", + "0.00480298", "0.00471316", "0.00473191", "0.00476389", + "0.00476992", "0.00484649", "0.00471095", "0.00501396", + "0.00495481", "0.00545029", "0.0053947", "0.00533251", + "0.00518064", "0.00504481", "0.00507209", "0.00516952", + "0.00524886", "0.00542661", "0.00544231", "0.00579898", + "0.00681472", "0.00720634", "0.00824023", "0.00856427", + "0.00821144", "0.00818103", "0.00960254", "0.00911172", + "0.00888481", "0.00925911", "0.0091132", "0.009285", + "0.00886256", "0.00938211", "0.00936566", "0.0104387", + "0.01088452", "0.01200575", "0.01217514", "0.011921", + "0.01293908", "0.0126124", "0.01224851", "0.01191149", + "0.01179783", "0.01164533", "0.01175718", "0.01169137", + "0.01212768", "0.01215952", "0.01300256", "0.01589522", + "0.01588223", "0.01780629", "0.01919794", "0.01922187", + "0.02165268", "0.02400163", "0.02290975", "0.02383495", + "0.02088105", "0.02373489", "0.02269442", "0.02226249", + "0.02148038", "0.0232045", "0.02623129", "0.02378975", + "0.02438442", "0.02417507", "0.02269891", "0.02236198", + "0.02209164", "0.02169842", "0.02137774", "0.02188837", + "0.0216619", "0.02238334", "0.02186701", "0.02186521", + "0.0217595", "0.02099916", "0.02129634", "0.02143028", + "0.02192513", "0.02172005", "0.02184525", "0.01873974", + "0.01899164", "0.01957115", "0.0204723", "0.0199247", + "0.01935441", "0.01886976", "0.01856944", "0.0179975", + "0.0178625", "0.01796981", + ).map { BigDecimal(it) } + val notcoinTimestamps = listOf( + 1715428800000, 1715443200000, 1715457600000, 1715472000000, + 1715486400000, 1715860800000, 1715875200000, 1715889600000, + 1715904000000, 1715918400000, 1715932800000, 1715947200000, + 1715961600000, 1715976000000, 1715990400000, 1716004800000, + 1716019200000, 1716033600000, 1716048000000, 1716062400000, + 1716076800000, 1716091200000, 1716105600000, 1716120000000, + 1716134400000, 1716148800000, 1716163200000, 1716177600000, + 1716192000000, 1716206400000, 1716220800000, 1716235200000, + 1716249600000, 1716264000000, 1716278400000, 1716292800000, + 1716307200000, 1716321600000, 1716336000000, 1716350400000, + 1716364800000, 1716379200000, 1716393600000, 1716408000000, + 1716422400000, 1716436800000, 1716451200000, 1716465600000, + 1716480000000, 1716494400000, 1716508800000, 1716523200000, + 1716537600000, 1716552000000, 1716566400000, 1716580800000, + 1716595200000, 1716609600000, 1716624000000, 1716638400000, + 1716652800000, 1716667200000, 1716681600000, 1716696000000, + 1716710400000, 1716724800000, 1716739200000, 1716753600000, + 1716768000000, 1716782400000, 1716796800000, 1716811200000, + 1716825600000, 1716840000000, 1716854400000, 1716868800000, + 1716883200000, 1716897600000, 1716912000000, 1716926400000, + 1716940800000, 1716955200000, 1716969600000, 1716984000000, + 1716998400000, 1717012800000, 1717027200000, 1717041600000, + 1717056000000, 1717070400000, 1717084800000, 1717099200000, + 1717113600000, 1717128000000, 1717142400000, 1717156800000, + 1717171200000, 1717185600000, 1717200000000, 1717214400000, + 1717228800000, 1717243200000, 1717257600000, 1717272000000, + 1717286400000, 1717300800000, 1717315200000, 1717329600000, + 1717344000000, 1717358400000, 1717372800000, 1717387200000, + 1717401600000, 1717416000000, 1717430400000, 1717444800000, + 1717459200000, 1717473600000, 1717488000000, 1717502400000, + 1717516800000, 1717531200000, 1717545600000, 1717560000000, + 1717574400000, 1717588800000, 1717603200000, 1717617600000, + 1717632000000, 1717646400000, 1717660800000, 1717675200000, + 1717689600000, 1717704000000, 1717718400000, 1717732800000, + 1717747200000, 1717761600000, 1717776000000, 1717790400000, + 1717804800000, 1717819200000, 1717833600000, 1717848000000, + 1717862400000, 1717876800000, 1717891200000, 1717905600000, + 1717920000000, 1717934400000, + ).map { it.toBigDecimal() } + + return sequenceOf(bitcoinTimestamps to bitcoinPrice, notcoinTimestamps to notcoinPrice) + } +} \ No newline at end of file diff --git a/common/ui-charts/src/main/kotlin/com/tangem/common/ui/charts/state/AxisLabelFormatter.kt b/common/ui-charts/src/main/kotlin/com/tangem/common/ui/charts/state/AxisLabelFormatter.kt new file mode 100644 index 0000000000..e01681994c --- /dev/null +++ b/common/ui-charts/src/main/kotlin/com/tangem/common/ui/charts/state/AxisLabelFormatter.kt @@ -0,0 +1,17 @@ +package com.tangem.common.ui.charts.state + +import androidx.compose.runtime.Stable +import java.math.BigDecimal + +/** + * Used for formatting the axis labels in a chart. + * It takes a BigDecimal value and returns a CharSequence that represents the formatted label. + * + * @param value The value to be formatted. + * @return The formatted label as a CharSequence. + */ +@Stable +fun interface AxisLabelFormatter { + + fun format(value: BigDecimal): CharSequence +} \ No newline at end of file diff --git a/common/ui-charts/src/main/kotlin/com/tangem/common/ui/charts/state/MarketChartData.kt b/common/ui-charts/src/main/kotlin/com/tangem/common/ui/charts/state/MarketChartData.kt new file mode 100644 index 0000000000..7e4887fedc --- /dev/null +++ b/common/ui-charts/src/main/kotlin/com/tangem/common/ui/charts/state/MarketChartData.kt @@ -0,0 +1,36 @@ +package com.tangem.common.ui.charts.state + +import androidx.compose.runtime.Immutable +import java.math.BigDecimal + +@Immutable +sealed interface MarketChartData { + + /** + * This interface represents the state when there is no data for the Market Chart. + */ + @Immutable + sealed interface NoData : MarketChartData { + @Immutable + data object Empty : NoData + + @Immutable + data object Loading : NoData + + @Immutable + data object ErrorAndRetry : NoData + } + + /** + * This data class represents the data for the Market Chart. + * It includes properties for x and y values. + * + * @property x List of x values. + * @property y List of y values. + */ + @Immutable + data class Data( + val x: List = listOf(), + val y: List = listOf(), + ) : MarketChartData +} \ No newline at end of file diff --git a/common/ui-charts/src/main/kotlin/com/tangem/common/ui/charts/state/MarketChartDataProducer.kt b/common/ui-charts/src/main/kotlin/com/tangem/common/ui/charts/state/MarketChartDataProducer.kt new file mode 100644 index 0000000000..bcad7d3ceb --- /dev/null +++ b/common/ui-charts/src/main/kotlin/com/tangem/common/ui/charts/state/MarketChartDataProducer.kt @@ -0,0 +1,201 @@ +package com.tangem.common.ui.charts.state + +import androidx.compose.runtime.Stable +import com.patrykandpatrick.vico.core.cartesian.data.CartesianChartModelProducer +import com.patrykandpatrick.vico.core.cartesian.data.LineCartesianLayerModel +import com.patrykandpatrick.vico.core.common.data.ExtraStore +import kotlinx.coroutines.CoroutineDispatcher +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.flow.MutableSharedFlow +import kotlinx.coroutines.flow.MutableStateFlow +import kotlinx.coroutines.withContext +import java.math.BigDecimal + +/** + * This class represents a transaction for updating the state and look of a Market Chart. + * + * @property chartLook The updated look of the Market Chart. + * @property chartData The updated state of the Market Chart. + */ +class Transaction( + private val currentData: MarketChartData, + private val currentLook: MarketChartLook, +) { + var chartLook: MarketChartLook? = null + var chartData: MarketChartData.NoData? = null + + fun updateLook(block: (prev: MarketChartLook) -> MarketChartLook) { + chartLook = block(currentLook) + } + + fun updateState(block: (prev: MarketChartData) -> MarketChartData.NoData) { + chartData = block(currentData) + } +} + +/** + * This class represents a transaction for updating the state and look of a Market Chart. + * It extends the Transaction class and allows update state by data. + * + * @property chartData The updated state of the Market Chart. + * @property chartLook The updated look of the Market Chart. + */ +class TransactionSuspend( + private val currentData: MarketChartData, + private val currentLook: MarketChartLook, +) { + internal var nonSuspendTransaction: Transaction? = null + var chartData: MarketChartData? = null + var chartLook: MarketChartLook? + get() = nonSuspendTransaction?.chartLook + set(value) { + if (nonSuspendTransaction == null) { + nonSuspendTransaction = Transaction(currentData, currentLook) + } + nonSuspendTransaction?.chartLook = value + } + + fun updateLook(block: (prev: MarketChartLook) -> MarketChartLook) { + chartLook = block(currentLook) + } + + internal fun updateState(block: (prev: MarketChartData) -> MarketChartData) { + chartData = block(currentData) + } + + internal fun updateData(block: (prev: MarketChartData.Data) -> MarketChartData.Data) { + chartData = when (val currentState = currentData) { + is MarketChartData.Data -> block(currentState) + else -> currentState + } + } +} + +@Stable +class MarketChartDataProducer private constructor( + initialData: MarketChartData, + initialLook: MarketChartLook, + val pointsValuesConverter: PointValuesConverter = DefaultPointValuesConverter, + private val dispatcher: CoroutineDispatcher = Dispatchers.Default, +) { + internal val startDrawingAnimation = MutableSharedFlow() + internal val dataState = MutableStateFlow(initialData) + internal val lookState = MutableStateFlow(initialLook) + internal val entries = MutableStateFlow>(emptyList()) + + internal val modelProducer = CartesianChartModelProducer.build(dispatcher = dispatcher) + + /** + * This function runs a suspending transaction block to update the state and look of the Market Chart. + */ + suspend fun runTransactionSuspend(block: TransactionSuspend.() -> Unit) = + handleTransactionSuspend(transaction = TransactionSuspend(dataState.value, lookState.value).apply(block)) + + /** + * This function runs a non-suspending transaction block to update the state and look of the Market Chart. + */ + fun runTransaction(block: Transaction.() -> Unit) = + handleTransaction(transaction = Transaction(dataState.value, lookState.value).apply(block)) + + private suspend fun handleTransactionSuspend(transaction: TransactionSuspend) { + val nonSuspendTransaction = transaction.nonSuspendTransaction + val chartData = transaction.chartData + val oldData = dataState.value + + if (chartData != null) { + dataState.value = chartData + } + + if (chartData is MarketChartData.Data && (oldData !is MarketChartData.Data || oldData != chartData)) { + if (lookState.value.animationOnDataChange) { + startDrawingAnimation.emit(Unit) + } + withContext(dispatcher) { + val rawData = pointsValuesConverter.convert(chartData) + + val entriesLocal = + rawData.x.mapIndexed { index, fl -> LineCartesianLayerModel.Entry(fl, rawData.y[index]) } + + entries.value = entriesLocal + + modelProducer.runTransaction { + add(LineCartesianLayerModel.Partial(series = listOf(entriesLocal))) + + updateExtras { + it[entriesKey] = entriesLocal + it[xKey] = chartData.x + it[yKey] = chartData.y + } + }.await() + } + } + + nonSuspendTransaction?.let { handleTransaction(it) } + } + + private fun handleTransaction(transaction: Transaction) { + transaction.chartData?.let { + dataState.value = it + } + transaction.chartLook?.let { + lookState.value = it + } + } + + companion object { + internal val entriesKey = ExtraStore.Key>() + internal val xKey = ExtraStore.Key>() + internal val yKey = ExtraStore.Key>() + + private val initialData: MarketChartData = MarketChartData.NoData.Empty + private val initialLook: MarketChartLook = MarketChartLook() + + /** + * This function builds a MarketChartDataProducer with the given parameters. + * It runs a suspending transaction block to initialize the data and look of the Market Chart. + * + * @param dispatcher The dispatcher to be used for data updates. + * @param block The transaction block to be run. + * @return A MarketChartDataProducer. + */ + suspend fun buildSuspend( + pointsValuesConverter: PointValuesConverter = DefaultPointValuesConverter, + dispatcher: CoroutineDispatcher = Dispatchers.Default, + block: TransactionSuspend.() -> Unit, + ): MarketChartDataProducer { + val transaction = TransactionSuspend(initialData, initialLook).apply(block) + + return MarketChartDataProducer( + initialData = initialData, + initialLook = initialLook, + dispatcher = dispatcher, + pointsValuesConverter = pointsValuesConverter, + ).apply { + handleTransactionSuspend(transaction) + } + } + + /** + * This function builds a MarketChartDataProducer with the given parameters. + * It runs a non-suspending transaction block to initialize the data and look of the Market Chart. + * + * @param dispatcher The dispatcher to be used for data updates. + * @param block The transaction block to be run. + * @return A MarketChartDataProducer. + */ + fun build( + pointsValuesConverter: PointValuesConverter = DefaultPointValuesConverter, + dispatcher: CoroutineDispatcher = Dispatchers.Default, + block: Transaction.() -> Unit, + ): MarketChartDataProducer { + val transaction = Transaction(initialData, initialLook).apply(block) + + return MarketChartDataProducer( + initialData = transaction.chartData ?: initialData, + initialLook = transaction.chartLook ?: initialLook, + dispatcher = dispatcher, + pointsValuesConverter = pointsValuesConverter, + ) + } + } +} \ No newline at end of file diff --git a/common/ui-charts/src/main/kotlin/com/tangem/common/ui/charts/state/MarketChartLook.kt b/common/ui-charts/src/main/kotlin/com/tangem/common/ui/charts/state/MarketChartLook.kt new file mode 100644 index 0000000000..c9ecaae2c0 --- /dev/null +++ b/common/ui-charts/src/main/kotlin/com/tangem/common/ui/charts/state/MarketChartLook.kt @@ -0,0 +1,28 @@ +package com.tangem.common.ui.charts.state + +/** + * This class represents the look and feel of a Market Chart. + * It includes properties for type, marker highlight, animation on data change, animate data appearance, + * and formatters for x and y axis. + * + * @property type The type of the chart, can be either Growing or Falling. + * @property markerHighlightRightSide A boolean indicating whether the marker highlights the right side of the chart. + * @property animationOnDataChange A boolean indicating whether to animate on data change. + * @property animateDataAppearance A boolean indicating whether to animate data appearance. + * @property xAxisFormatter A formatter for the x-axis labels. + * @property yAxisFormatter A formatter for the y-axis labels. + */ +data class MarketChartLook( + val type: Type = Type.Growing, + val markerHighlightRightSide: Boolean = true, + val animationOnDataChange: Boolean = false, + val animateDataAppearance: Boolean = false, + val xAxisFormatter: AxisLabelFormatter = AxisLabelFormatter { it.toString() }, + val yAxisFormatter: AxisLabelFormatter = AxisLabelFormatter { it.toString() }, +) { + + enum class Type { + Growing, + Falling, + } +} \ No newline at end of file diff --git a/common/ui-charts/src/main/kotlin/com/tangem/common/ui/charts/state/MarketChartRawData.kt b/common/ui-charts/src/main/kotlin/com/tangem/common/ui/charts/state/MarketChartRawData.kt new file mode 100644 index 0000000000..a1b7e91f2c --- /dev/null +++ b/common/ui-charts/src/main/kotlin/com/tangem/common/ui/charts/state/MarketChartRawData.kt @@ -0,0 +1,9 @@ +package com.tangem.common.ui.charts.state + +import androidx.compose.runtime.Immutable + +@Immutable +data class MarketChartRawData( + val y: List, + val x: List = List(y.size) { 1f }, +) \ No newline at end of file diff --git a/common/ui-charts/src/main/kotlin/com/tangem/common/ui/charts/state/MarketChartState.kt b/common/ui-charts/src/main/kotlin/com/tangem/common/ui/charts/state/MarketChartState.kt new file mode 100644 index 0000000000..92a0379f5d --- /dev/null +++ b/common/ui-charts/src/main/kotlin/com/tangem/common/ui/charts/state/MarketChartState.kt @@ -0,0 +1,139 @@ +package com.tangem.common.ui.charts.state + +import androidx.compose.runtime.* +import androidx.compose.ui.graphics.Color +import androidx.lifecycle.compose.collectAsStateWithLifecycle +import com.patrykandpatrick.vico.core.cartesian.data.CartesianValueFormatter +import com.patrykandpatrick.vico.core.cartesian.marker.CartesianMarker +import com.patrykandpatrick.vico.core.cartesian.marker.CartesianMarkerVisibilityListener +import com.patrykandpatrick.vico.core.cartesian.marker.LineCartesianLayerMarkerTarget +import java.math.BigDecimal + +/** + * MarketChartState used for MarketChart ui component. + * + * @param dataProducer The producer of the data for the Market Chart. + * @param colorMapper A function that maps a MarketChartLook.Type to a Color. + * @param onMarkerShown A callback function that is called when the marker is shown, hidden, or updated. + * @return A MarketChartState. + */ +@Composable +fun rememberMarketChartState( + dataProducer: MarketChartDataProducer = remember { MarketChartDataProducer.build {} }, + colorMapper: (MarketChartLook.Type) -> Color = { + when (it) { + MarketChartLook.Type.Growing -> Color.Green + MarketChartLook.Type.Falling -> Color.Red + } + }, + onMarkerShown: (x: BigDecimal?, y: BigDecimal?) -> Unit = { _, _ -> }, +): MarketChartState { + val lookState = dataProducer.lookState.collectAsStateWithLifecycle() + + val state = remember(dataProducer, lookState, colorMapper, onMarkerShown) { + MarketChartState(dataProducer, lookState, colorMapper, onMarkerShown) + } + + LaunchedEffect(Unit) { + dataProducer.startDrawingAnimation.collect { + state.startDrawingAnimation() + } + } + + return state +} + +/** + * Represents the state of a Market Chart. + * + * @property dataProducer The producer of the data for the Market Chart. + * @property lookState The look state of the Market Chart. + * @property colorMapper A function that maps a MarketChartLook.Type to a Color. + * @property markerCallback A callback function that is called when the marker is shown, hidden, or updated. + * @property isDrawingAnimationInProgress A boolean indicating whether the drawing animation is in progress. + */ +@Stable +class MarketChartState internal constructor( + private val dataProducer: MarketChartDataProducer, + private val lookState: State, + private val colorMapper: (MarketChartLook.Type) -> Color, + private val markerCallback: (x: BigDecimal?, y: BigDecimal?) -> Unit, +) { + internal val startDrawingAnimationState = mutableStateOf(false) + internal val modelProducer = dataProducer.modelProducer + + internal val chartColor by derivedStateOf { + colorMapper(lookState.value.type) + } + + internal val markerHighlightRightSide by derivedStateOf { + lookState.value.markerHighlightRightSide + } + + internal val xValueFormatter by derivedStateOf { + CartesianValueFormatter { value, _, _ -> + val state = dataProducer.dataState.value as? MarketChartData.Data + ?: return@CartesianValueFormatter value.toString() + + lookState.value.xAxisFormatter.format( + value = dataProducer.pointsValuesConverter.prepareRawXForFormat(value, state), + ) + } + } + + internal val yValueFormatter by derivedStateOf { + CartesianValueFormatter { value, _, _ -> + val state = dataProducer.dataState.value as? MarketChartData.Data + ?: return@CartesianValueFormatter value.toString() + + lookState.value.yAxisFormatter.format( + value = dataProducer.pointsValuesConverter.prepareRawYForFormat(value, state), + ) + } + } + + internal var markerFraction: Float? by mutableStateOf(null) + + internal val markerVisibilityListener = object : CartesianMarkerVisibilityListener { + override fun onShown(marker: CartesianMarker, targets: List) { + val point = getPoint(targets) ?: run { + markerCallback(null, null) + return + } + markerCallback(point.first, point.second) + } + + override fun onHidden(marker: CartesianMarker) { + markerCallback(null, null) + } + + override fun onUpdated(marker: CartesianMarker, targets: List) { + val point = getPoint(targets) ?: run { + markerCallback(null, null) + return + } + markerCallback(point.first, point.second) + } + } + + val isDrawingAnimationInProgress: Boolean by derivedStateOf { + startDrawingAnimationState.value + } + + private fun getPoint(targets: List): Pair? { + val entry = (targets[0] as LineCartesianLayerMarkerTarget).points[0].entry + val entryIndex = dataProducer.entries.value.indexOf(entry).takeIf { it != -1 } ?: return null + val state = dataProducer.dataState.value as? MarketChartData.Data ?: return null + val x = state.x.getOrNull(entryIndex) ?: return null + val y = state.y.getOrNull(entryIndex) ?: return null + return x to y + } + + fun startDrawingAnimation() { + startDrawingAnimationState.value = true + } + + fun stopDrawingAnimation() { + startDrawingAnimationState.value = false + } +} \ No newline at end of file diff --git a/common/ui-charts/src/main/kotlin/com/tangem/common/ui/charts/state/PointValuesConverter.kt b/common/ui-charts/src/main/kotlin/com/tangem/common/ui/charts/state/PointValuesConverter.kt new file mode 100644 index 0000000000..1dab1cd0cc --- /dev/null +++ b/common/ui-charts/src/main/kotlin/com/tangem/common/ui/charts/state/PointValuesConverter.kt @@ -0,0 +1,69 @@ +package com.tangem.common.ui.charts.state + +import java.math.BigDecimal + +/** + * Interface to convert chart data values to Floats and backwards. + * + * We need to convert the values on the graph to floating point values in order to display them correctly on the canvas. + * We also need to determine exactly which floating point value on the graph corresponds to the decimal point, + * so that we can format the actual value and display on the x/y axis. + */ +interface PointValuesConverter { + + fun convert(data: MarketChartData.Data): MarketChartRawData + + fun prepareRawXForFormat(rawX: Float, data: MarketChartData.Data): BigDecimal + + fun prepareRawYForFormat(rawY: Float, data: MarketChartData.Data): BigDecimal +} + +object DefaultPointValuesConverter : PointValuesConverter { + + override fun convert(data: MarketChartData.Data): MarketChartRawData { + val minX = data.x.min() + val minY = data.y.min() + + val normY = data.y.map { normalize(it, minY) } + val normX = data.x.map { normalize(it, minX) } + + return MarketChartRawData( + x = normX, + y = normY, + ) + } + + override fun prepareRawXForFormat(rawX: Float, data: MarketChartData.Data): BigDecimal { + val dataMin = data.x.min() + val scale = dataMin.scale() + val bVal = if (scale > 2) { + rawX.toBigDecimal().movePointLeft(scale - 2) + dataMin + } else { + rawX.toBigDecimal() + dataMin + } + + return bVal + } + + override fun prepareRawYForFormat(rawY: Float, data: MarketChartData.Data): BigDecimal { + val dataMin = data.y.min() + val scale = dataMin.scale() + val bVal = if (scale > 2) { + rawY.toBigDecimal().movePointLeft(scale - 2) + dataMin + } else { + rawY.toBigDecimal() + dataMin + } + + return bVal + } + + // TODO enhance algorithm for values with big difference between min and max, which cannot fit in Float + private fun normalize(value: BigDecimal, min: BigDecimal, scale: Int = min.scale()): Float { + val n = value - min + return if (scale > 2) { + n.movePointRight(scale - 2).toFloat() + } else { + n.toFloat() + } + } +} \ No newline at end of file diff --git a/common/ui/.gitignore b/common/ui/.gitignore new file mode 100644 index 0000000000..42afabfd2a --- /dev/null +++ b/common/ui/.gitignore @@ -0,0 +1 @@ +/build \ No newline at end of file diff --git a/common/ui/build.gradle.kts b/common/ui/build.gradle.kts new file mode 100644 index 0000000000..e57cd07bd1 --- /dev/null +++ b/common/ui/build.gradle.kts @@ -0,0 +1,36 @@ +plugins { + alias(deps.plugins.android.library) + alias(deps.plugins.kotlin.android) + id("configuration") +} + +android { + namespace = "com.tangem.common.ui" +} + +dependencies { + + /** Compose */ + implementation(deps.compose.material3) + implementation(deps.compose.material) + implementation(deps.compose.foundation) + implementation(deps.compose.ui) + implementation(deps.compose.ui.tooling) + implementation(deps.compose.navigation) + implementation(deps.compose.navigation.hilt) + + /** Deps */ + implementation(deps.kotlin.immutable.collections) + + /** Project - Common */ + implementation(projects.core.ui) + implementation(projects.core.utils) + + /** Project - Domain */ + implementation(projects.domain.tokens.models) + implementation(projects.domain.wallets.models) + implementation(projects.domain.appCurrency.models) + implementation(deps.tangem.blockchain) { + exclude(module = "joda-time") + } +} \ No newline at end of file diff --git a/common/ui/src/main/java/com/tangem/common/ui/amountScreen/AmountScreenClickIntents.kt b/common/ui/src/main/java/com/tangem/common/ui/amountScreen/AmountScreenClickIntents.kt new file mode 100644 index 0000000000..a913361583 --- /dev/null +++ b/common/ui/src/main/java/com/tangem/common/ui/amountScreen/AmountScreenClickIntents.kt @@ -0,0 +1,24 @@ +package com.tangem.common.ui.amountScreen + +/** Amount screen clicks */ +interface AmountScreenClickIntents { + + /** On amount [value] changed */ + fun onAmountValueChange(value: String) + + /** Click triggered on value paste */ + fun onAmountPasteTriggerDismiss() + + /** On max amount click */ + fun onMaxValueClick() + + /** + * On currency change from crypto currency to app currency clicked + * + * @param isFiat indicates currency to change + */ + fun onCurrencyChangeClick(isFiat: Boolean) + + /** On next screen click */ + fun onAmountNext() +} \ No newline at end of file diff --git a/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/ui/amount/SendAmountContent.kt b/common/ui/src/main/java/com/tangem/common/ui/amountScreen/AmountScreenContent.kt similarity index 67% rename from features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/ui/amount/SendAmountContent.kt rename to common/ui/src/main/java/com/tangem/common/ui/amountScreen/AmountScreenContent.kt index 6181fc2174..64615bc792 100644 --- a/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/ui/amount/SendAmountContent.kt +++ b/common/ui/src/main/java/com/tangem/common/ui/amountScreen/AmountScreenContent.kt @@ -1,4 +1,4 @@ -package com.tangem.features.send.impl.presentation.ui.amount +package com.tangem.common.ui.amountScreen import android.content.res.Configuration import androidx.compose.foundation.background @@ -9,20 +9,24 @@ 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.PreviewParameterProvider -import com.tangem.core.ui.res.TangemThemePreview +import com.tangem.common.ui.amountScreen.models.AmountState +import com.tangem.common.ui.amountScreen.preview.AmountScreenClickIntentsStub +import com.tangem.common.ui.amountScreen.preview.AmountStatePreviewData +import com.tangem.common.ui.amountScreen.ui.amountField +import com.tangem.common.ui.amountScreen.ui.buttons import com.tangem.core.ui.res.TangemTheme -import com.tangem.features.send.impl.presentation.state.SendStates -import com.tangem.features.send.impl.presentation.state.previewdata.AmountStatePreviewData -import com.tangem.features.send.impl.presentation.state.previewdata.SendClickIntentsStub -import com.tangem.features.send.impl.presentation.viewmodel.SendClickIntents +import com.tangem.core.ui.res.TangemThemePreview +/** + * Amount screen with field + * @param amountState amount state + * @param isBalanceHiding flag hidden balances + * @param clickIntents amount screen clicks + */ @Composable -internal fun SendAmountContent( - amountState: SendStates.AmountState?, - isBalanceHiding: Boolean, - clickIntents: SendClickIntents, -) { - if (amountState == null) return +fun AmountScreenContent(amountState: AmountState, isBalanceHiding: Boolean, clickIntents: AmountScreenClickIntents) { + if (amountState !is AmountState.Data) return + // Do not put fillMaxSize() in here LazyColumn( modifier = Modifier @@ -48,19 +52,19 @@ internal fun SendAmountContent( @Preview(showBackground = true, widthDp = 360, uiMode = Configuration.UI_MODE_NIGHT_YES) @Composable private fun SendAmountContentPreview( - @PreviewParameter(SendAmountContentPreviewProvider::class) amountState: SendStates.AmountState, + @PreviewParameter(SendAmountContentPreviewProvider::class) amountState: AmountState, ) { TangemThemePreview { - SendAmountContent( + AmountScreenContent( amountState = amountState, isBalanceHiding = false, - clickIntents = SendClickIntentsStub, + clickIntents = AmountScreenClickIntentsStub, ) } } -private class SendAmountContentPreviewProvider : PreviewParameterProvider { - override val values: Sequence +private class SendAmountContentPreviewProvider : PreviewParameterProvider { + override val values: Sequence get() = sequenceOf( AmountStatePreviewData.amountState, ) diff --git a/common/ui/src/main/java/com/tangem/common/ui/amountScreen/converters/AmountCurrencyTransformer.kt b/common/ui/src/main/java/com/tangem/common/ui/amountScreen/converters/AmountCurrencyTransformer.kt new file mode 100644 index 0000000000..cdacdd3ce7 --- /dev/null +++ b/common/ui/src/main/java/com/tangem/common/ui/amountScreen/converters/AmountCurrencyTransformer.kt @@ -0,0 +1,45 @@ +package com.tangem.common.ui.amountScreen.converters + +import androidx.compose.foundation.text.KeyboardOptions +import androidx.compose.ui.text.input.ImeAction +import androidx.compose.ui.text.input.KeyboardType +import com.tangem.common.ui.amountScreen.models.AmountState +import com.tangem.domain.tokens.model.CryptoCurrencyStatus +import com.tangem.utils.isNullOrZero +import com.tangem.utils.transformer.Transformer + +/** + * Selected currency change from crypto currency to app currency and vice versa + * + * @property cryptoCurrencyStatus current cryptocurrency status + * @property value is crypto currency or app currency + */ +class AmountCurrencyTransformer( + private val cryptoCurrencyStatus: CryptoCurrencyStatus, + private val value: Boolean, +) : Transformer { + + override fun transform(prevState: AmountState): AmountState { + if (prevState !is AmountState.Data) return prevState + + val amountTextField = prevState.amountTextField + + val isValidFiatRate = cryptoCurrencyStatus.value.fiatRate.isNullOrZero() + val isDoneActionEnabled = prevState.isPrimaryButtonEnabled + return if (amountTextField.isFiatValue == value && !isValidFiatRate) { + prevState + } else { + return prevState.copy( + amountTextField = amountTextField.copy( + isFiatValue = value, + isValuePasted = true, + keyboardOptions = KeyboardOptions( + imeAction = if (isDoneActionEnabled) ImeAction.Done else ImeAction.None, + keyboardType = KeyboardType.Number, + ), + ), + selectedButton = prevState.segmentedButtonConfig.indexOfFirst { it.isFiat == value }, + ) + } + } +} \ No newline at end of file diff --git a/common/ui/src/main/java/com/tangem/common/ui/amountScreen/converters/AmountPastedTriggerDismissTransformer.kt b/common/ui/src/main/java/com/tangem/common/ui/amountScreen/converters/AmountPastedTriggerDismissTransformer.kt new file mode 100644 index 0000000000..ebf69ed80d --- /dev/null +++ b/common/ui/src/main/java/com/tangem/common/ui/amountScreen/converters/AmountPastedTriggerDismissTransformer.kt @@ -0,0 +1,19 @@ +package com.tangem.common.ui.amountScreen.converters + +import com.tangem.common.ui.amountScreen.models.AmountState +import com.tangem.utils.transformer.Transformer + +/** + * Dismisses indication on pasted value + */ +class AmountPastedTriggerDismissTransformer : Transformer { + override fun transform(prevState: AmountState): AmountState { + if (prevState !is AmountState.Data) return prevState + + return prevState.copy( + amountTextField = prevState.amountTextField.copy( + isValuePasted = false, + ), + ) + } +} \ No newline at end of file diff --git a/common/ui/src/main/java/com/tangem/common/ui/amountScreen/converters/AmountReduceByTransformer.kt b/common/ui/src/main/java/com/tangem/common/ui/amountScreen/converters/AmountReduceByTransformer.kt new file mode 100644 index 0000000000..78ce58f37d --- /dev/null +++ b/common/ui/src/main/java/com/tangem/common/ui/amountScreen/converters/AmountReduceByTransformer.kt @@ -0,0 +1,68 @@ +package com.tangem.common.ui.amountScreen.converters + +import androidx.compose.foundation.text.KeyboardOptions +import androidx.compose.ui.text.input.KeyboardType +import com.tangem.common.ui.amountScreen.models.AmountState +import com.tangem.common.ui.amountScreen.utils.checkExceedBalance +import com.tangem.common.ui.amountScreen.utils.getFiatValue +import com.tangem.common.ui.amountScreen.utils.getKeyboardAction +import com.tangem.core.ui.utils.parseBigDecimal +import com.tangem.domain.tokens.model.CryptoCurrencyStatus +import com.tangem.utils.isNullOrZero +import com.tangem.utils.transformer.Transformer +import java.math.BigDecimal + +/** + * Reduces amount by specific value + * + * @property cryptoCurrencyStatus current cryptocurrency status + * @property value reduced by value + */ +class AmountReduceByTransformer( + private val cryptoCurrencyStatus: CryptoCurrencyStatus, + private val value: ReduceByData, +) : Transformer { + override fun transform(prevState: AmountState): AmountState { + if (prevState !is AmountState.Data) return prevState + + val amountTextField = prevState.amountTextField + val cryptoDecimals = amountTextField.cryptoAmount.decimals + val fiatDecimals = amountTextField.fiatAmount.decimals + val amountValue = prevState.amountTextField.cryptoAmount.value ?: return prevState + + val decimalCryptoValue = amountValue.minus(value.reduceAmountByDiff) + val cryptoValue = decimalCryptoValue.parseBigDecimal(cryptoDecimals) + val (fiatValue, decimalFiatValue) = cryptoValue.getFiatValue( + fiatRate = cryptoCurrencyStatus.value.fiatRate, + isFiatValue = false, + decimals = fiatDecimals, + ) + + val checkValue = if (amountTextField.isFiatValue) fiatValue else cryptoValue + val isExceedBalance = checkValue.checkExceedBalance(cryptoCurrencyStatus, amountTextField) + val isZero = if (amountTextField.isFiatValue) { + decimalFiatValue.isNullOrZero() + } else { + decimalCryptoValue.isNullOrZero() + } + return prevState.copy( + isPrimaryButtonEnabled = !isExceedBalance && !isZero, + amountTextField = amountTextField.copy( + value = cryptoValue, + fiatValue = fiatValue, + isError = isExceedBalance, + cryptoAmount = amountTextField.cryptoAmount.copy(value = decimalCryptoValue), + fiatAmount = amountTextField.fiatAmount.copy(value = decimalFiatValue), + keyboardOptions = KeyboardOptions( + imeAction = getKeyboardAction(isExceedBalance, decimalCryptoValue), + keyboardType = KeyboardType.Number, + ), + ), + ) + } + + data class ReduceByData( + val reduceAmountBy: BigDecimal, + val reduceAmountByDiff: BigDecimal, + ) +} \ No newline at end of file diff --git a/common/ui/src/main/java/com/tangem/common/ui/amountScreen/converters/AmountReduceToTransformer.kt b/common/ui/src/main/java/com/tangem/common/ui/amountScreen/converters/AmountReduceToTransformer.kt new file mode 100644 index 0000000000..aed8332b0b --- /dev/null +++ b/common/ui/src/main/java/com/tangem/common/ui/amountScreen/converters/AmountReduceToTransformer.kt @@ -0,0 +1,57 @@ +package com.tangem.common.ui.amountScreen.converters + +import androidx.compose.foundation.text.KeyboardOptions +import androidx.compose.ui.text.input.KeyboardType +import com.tangem.common.ui.amountScreen.models.AmountState +import com.tangem.common.ui.amountScreen.utils.checkExceedBalance +import com.tangem.common.ui.amountScreen.utils.getFiatValue +import com.tangem.common.ui.amountScreen.utils.getKeyboardAction +import com.tangem.core.ui.utils.parseBigDecimal +import com.tangem.domain.tokens.model.CryptoCurrencyStatus +import com.tangem.utils.isNullOrZero +import com.tangem.utils.transformer.Transformer +import java.math.BigDecimal + +/** + * Reduces amount to specific value + * + * @property cryptoCurrencyStatus current cryptocurrency status + * @property value reduced to value + */ +class AmountReduceToTransformer( + private val cryptoCurrencyStatus: CryptoCurrencyStatus, + private val value: BigDecimal, +) : Transformer { + override fun transform(prevState: AmountState): AmountState { + if (prevState !is AmountState.Data) return prevState + + val amountTextField = prevState.amountTextField + val cryptoDecimals = amountTextField.cryptoAmount.decimals + val fiatDecimals = amountTextField.fiatAmount.decimals + + val cryptoValue = value.parseBigDecimal(cryptoDecimals) + val (fiatValue, decimalFiatValue) = cryptoValue.getFiatValue( + fiatRate = cryptoCurrencyStatus.value.fiatRate, + isFiatValue = false, + decimals = fiatDecimals, + ) + + val checkValue = if (amountTextField.isFiatValue) fiatValue else cryptoValue + val isExceedBalance = checkValue.checkExceedBalance(cryptoCurrencyStatus, amountTextField) + val isZero = if (amountTextField.isFiatValue) decimalFiatValue.isNullOrZero() else value.isNullOrZero() + return prevState.copy( + isPrimaryButtonEnabled = !isExceedBalance && !isZero, + amountTextField = amountTextField.copy( + value = cryptoValue, + fiatValue = fiatValue, + isError = isExceedBalance, + cryptoAmount = amountTextField.cryptoAmount.copy(value = value), + fiatAmount = amountTextField.fiatAmount.copy(value = decimalFiatValue), + keyboardOptions = KeyboardOptions( + imeAction = getKeyboardAction(isExceedBalance, value), + keyboardType = KeyboardType.Number, + ), + ), + ) + } +} \ No newline at end of file diff --git a/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/state/amount/SendAmountStateConverter.kt b/common/ui/src/main/java/com/tangem/common/ui/amountScreen/converters/AmountStateConverter.kt similarity index 61% rename from features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/state/amount/SendAmountStateConverter.kt rename to common/ui/src/main/java/com/tangem/common/ui/amountScreen/converters/AmountStateConverter.kt index 6afdc1ada8..ad251378f6 100644 --- a/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/state/amount/SendAmountStateConverter.kt +++ b/common/ui/src/main/java/com/tangem/common/ui/amountScreen/converters/AmountStateConverter.kt @@ -1,6 +1,11 @@ -package com.tangem.features.send.impl.presentation.state.amount +package com.tangem.common.ui.amountScreen.converters -import com.tangem.core.ui.components.currency.tokenicon.converter.CryptoCurrencyToIconStateConverter +import com.tangem.common.ui.R +import com.tangem.common.ui.amountScreen.AmountScreenClickIntents +import com.tangem.common.ui.amountScreen.converters.field.AmountFieldConverter +import com.tangem.common.ui.amountScreen.models.AmountState +import com.tangem.common.ui.amountScreen.models.AmountSegmentedButtonsConfig +import com.tangem.core.ui.components.currency.icon.converter.CryptoCurrencyToIconStateConverter import com.tangem.core.ui.extensions.resourceReference import com.tangem.core.ui.extensions.stringReference import com.tangem.core.ui.extensions.wrappedList @@ -9,23 +14,37 @@ import com.tangem.core.ui.utils.BigDecimalFormatter.formatFiatAmount import com.tangem.domain.appcurrency.model.AppCurrency import com.tangem.domain.tokens.model.CryptoCurrencyStatus import com.tangem.domain.wallets.models.UserWallet -import com.tangem.features.send.impl.R -import com.tangem.features.send.impl.presentation.state.SendStates -import com.tangem.features.send.impl.presentation.state.fields.SendAmountFieldConverter import com.tangem.utils.Provider import com.tangem.utils.converter.Converter import com.tangem.utils.isNullOrZero import kotlinx.collections.immutable.persistentListOf -internal class SendAmountStateConverter( +/** + * Converts initial [String] to [AmountState] + * + * @property clickIntents amount screen clicks + * @property appCurrencyProvider selected app currency provider + * @property userWalletProvider selected user wallet provider + * @property cryptoCurrencyStatusProvider current cryptocurrency status provider + * @property iconStateConverter currency icon converter + */ +class AmountStateConverter( + private val clickIntents: AmountScreenClickIntents, private val appCurrencyProvider: Provider, private val userWalletProvider: Provider, private val cryptoCurrencyStatusProvider: Provider, private val iconStateConverter: CryptoCurrencyToIconStateConverter, - private val sendAmountFieldConverter: SendAmountFieldConverter, -) : Converter { +) : Converter { - override fun convert(value: String): SendStates.AmountState { + private val amountFieldConverter by lazy(LazyThreadSafetyMode.NONE) { + AmountFieldConverter( + clickIntents = clickIntents, + cryptoCurrencyStatusProvider = cryptoCurrencyStatusProvider, + appCurrencyProvider = appCurrencyProvider, + ) + } + + override fun convert(value: String): AmountState { val userWallet = userWalletProvider() val appCurrency = appCurrencyProvider() val status = cryptoCurrencyStatusProvider() @@ -33,15 +52,15 @@ internal class SendAmountStateConverter( val crypto = formatCryptoAmount(status.value.amount, status.currency.symbol, status.currency.decimals) val noFeeRate = status.value.fiatRate.isNullOrZero() - return SendStates.AmountState( + return AmountState.Data( walletName = userWallet.name, walletBalance = resourceReference(R.string.send_wallet_balance_format, wrappedList(crypto, fiat)), tokenIconState = iconStateConverter.convert(status), - amountTextField = sendAmountFieldConverter.convert(value), + amountTextField = amountFieldConverter.convert(value), isPrimaryButtonEnabled = false, appCurrencyCode = appCurrency.code, segmentedButtonConfig = persistentListOf( - SendAmountSegmentedButtonsConfig( + AmountSegmentedButtonsConfig( title = stringReference(status.currency.symbol), iconState = iconStateConverter.convertCustom( value = status, @@ -50,7 +69,7 @@ internal class SendAmountStateConverter( ), isFiat = false, ), - SendAmountSegmentedButtonsConfig( + AmountSegmentedButtonsConfig( title = stringReference(appCurrency.code), iconUrl = appCurrency.iconSmallUrl, isFiat = true, diff --git a/common/ui/src/main/java/com/tangem/common/ui/amountScreen/converters/field/AmountFieldChangeTransformer.kt b/common/ui/src/main/java/com/tangem/common/ui/amountScreen/converters/field/AmountFieldChangeTransformer.kt new file mode 100644 index 0000000000..f0be223891 --- /dev/null +++ b/common/ui/src/main/java/com/tangem/common/ui/amountScreen/converters/field/AmountFieldChangeTransformer.kt @@ -0,0 +1,84 @@ +package com.tangem.common.ui.amountScreen.converters.field + +import androidx.compose.foundation.text.KeyboardOptions +import androidx.compose.ui.text.input.KeyboardType +import com.tangem.common.ui.amountScreen.models.AmountState +import com.tangem.common.ui.amountScreen.utils.checkExceedBalance +import com.tangem.common.ui.amountScreen.utils.getCryptoValue +import com.tangem.common.ui.amountScreen.utils.getFiatValue +import com.tangem.common.ui.amountScreen.utils.getKeyboardAction +import com.tangem.core.ui.utils.parseToBigDecimal +import com.tangem.domain.tokens.model.CryptoCurrencyStatus +import com.tangem.utils.isNullOrZero +import com.tangem.utils.transformer.Transformer +import java.math.BigDecimal + +/** + * Amount value change + * + * @property cryptoCurrencyStatus current cryptocurrency status + * @property value amount value + */ +class AmountFieldChangeTransformer( + private val cryptoCurrencyStatus: CryptoCurrencyStatus, + private val value: String, +) : Transformer { + + override fun transform(prevState: AmountState): AmountState { + if (prevState !is AmountState.Data) return prevState + + val amountTextField = prevState.amountTextField + + if (value.isEmpty()) return prevState.emptyState() + val cryptoDecimals = amountTextField.cryptoAmount.decimals + val fiatDecimals = amountTextField.fiatAmount.decimals + + val trimmedValue = value.trim() + val cryptoValue = trimmedValue.getCryptoValue( + fiatRate = cryptoCurrencyStatus.value.fiatRate, + isFiatValue = amountTextField.isFiatValue, + decimals = cryptoDecimals, + ) + val decimalCryptoValue = cryptoValue.parseToBigDecimal(cryptoDecimals) + val (fiatValue, decimalFiatValue) = trimmedValue.getFiatValue( + fiatRate = cryptoCurrencyStatus.value.fiatRate, + isFiatValue = amountTextField.isFiatValue, + decimals = fiatDecimals, + ) + + val checkValue = if (amountTextField.isFiatValue) fiatValue else cryptoValue + val isExceedBalance = checkValue.checkExceedBalance(cryptoCurrencyStatus, amountTextField) + val isZero = if (amountTextField.isFiatValue) { + decimalFiatValue.isNullOrZero() + } else { + decimalCryptoValue.isNullOrZero() + } + return prevState.copy( + isPrimaryButtonEnabled = !isExceedBalance && !isZero, + amountTextField = amountTextField.copy( + value = cryptoValue, + fiatValue = fiatValue, + isError = isExceedBalance, + cryptoAmount = amountTextField.cryptoAmount.copy(value = decimalCryptoValue), + fiatAmount = amountTextField.fiatAmount.copy(value = decimalFiatValue), + keyboardOptions = KeyboardOptions( + imeAction = getKeyboardAction(isExceedBalance, decimalCryptoValue), + keyboardType = KeyboardType.Number, + ), + ), + ) + } + + private fun AmountState.Data.emptyState(): AmountState.Data { + return copy( + isPrimaryButtonEnabled = false, + amountTextField = amountTextField.copy( + value = "", + fiatValue = "", + cryptoAmount = amountTextField.cryptoAmount.copy(value = BigDecimal.ZERO), + fiatAmount = amountTextField.fiatAmount.copy(value = BigDecimal.ZERO), + isError = false, + ), + ) + } +} \ No newline at end of file diff --git a/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/state/fields/SendAmountFieldConverter.kt b/common/ui/src/main/java/com/tangem/common/ui/amountScreen/converters/field/AmountFieldConverter.kt similarity index 72% rename from features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/state/fields/SendAmountFieldConverter.kt rename to common/ui/src/main/java/com/tangem/common/ui/amountScreen/converters/field/AmountFieldConverter.kt index 8bf30c0b57..bfe5259127 100644 --- a/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/state/fields/SendAmountFieldConverter.kt +++ b/common/ui/src/main/java/com/tangem/common/ui/amountScreen/converters/field/AmountFieldConverter.kt @@ -1,11 +1,12 @@ -package com.tangem.features.send.impl.presentation.state.fields +package com.tangem.common.ui.amountScreen.converters.field import androidx.compose.foundation.text.KeyboardActions import androidx.compose.foundation.text.KeyboardOptions import androidx.compose.ui.text.input.ImeAction import androidx.compose.ui.text.input.KeyboardType -import com.tangem.blockchain.extensions.toBigDecimalOrDefault -import com.tangem.common.extensions.isZero +import com.tangem.common.ui.R +import com.tangem.common.ui.amountScreen.AmountScreenClickIntents +import com.tangem.common.ui.amountScreen.models.AmountFieldModel import com.tangem.core.ui.extensions.TextReference import com.tangem.core.ui.utils.parseBigDecimal import com.tangem.domain.appcurrency.model.AppCurrency @@ -13,26 +14,27 @@ import com.tangem.domain.tokens.model.Amount import com.tangem.domain.tokens.model.AmountType import com.tangem.domain.tokens.model.CryptoCurrencyStatus import com.tangem.domain.tokens.model.convertToAmount -import com.tangem.features.send.impl.R -import com.tangem.features.send.impl.presentation.state.StateRouter -import com.tangem.features.send.impl.presentation.viewmodel.SendClickIntents import com.tangem.utils.Provider import com.tangem.utils.converter.Converter import com.tangem.utils.isNullOrZero import java.math.BigDecimal -private const val FIAT_DECIMALS = 2 - -internal class SendAmountFieldConverter( - private val clickIntents: SendClickIntents, - private val stateRouterProvider: Provider, +/** + * Converts initial [String] to [AmountField] + * + * @property clickIntents amount screen clicks + * @property appCurrencyProvider selected app currency provider + * @property cryptoCurrencyStatusProvider current cryptocurrency status provider + */ +class AmountFieldConverter( + private val clickIntents: AmountScreenClickIntents, private val cryptoCurrencyStatusProvider: Provider, private val appCurrencyProvider: Provider, -) : Converter { +) : Converter { - override fun convert(value: String): SendTextField.AmountField { + override fun convert(value: String): AmountFieldModel { val cryptoCurrencyStatus = cryptoCurrencyStatusProvider() - val cryptoDecimal = value.toBigDecimalOrDefault() + val cryptoDecimal = value.toBigDecimalOrNull() ?: BigDecimal.ZERO val cryptoAmount = cryptoDecimal.convertToAmount(cryptoCurrencyStatus.currency) val fiatRate = cryptoCurrencyStatus.value.fiatRate val (fiatValue, fiatDecimal) = when { @@ -44,8 +46,8 @@ internal class SendAmountFieldConverter( fiatValue to fiatDecimal } } - val isDoneActionEnabled = !cryptoDecimal.isZero() - return SendTextField.AmountField( + val isDoneActionEnabled = !cryptoDecimal.isNullOrZero() + return AmountFieldModel( value = value, fiatValue = fiatValue, onValueChange = clickIntents::onAmountValueChange, @@ -54,7 +56,7 @@ internal class SendAmountFieldConverter( keyboardType = KeyboardType.Number, ), keyboardActions = KeyboardActions( - onDone = { clickIntents.onNextClick(stateRouterProvider().isEditState) }, + onDone = { clickIntents.onAmountNext() }, ), isFiatValue = false, cryptoAmount = cryptoAmount, @@ -73,4 +75,8 @@ internal class SendAmountFieldConverter( decimals = FIAT_DECIMALS, type = AmountType.FiatType(appCurrency.code), ) + + private companion object { + private const val FIAT_DECIMALS = 2 + } } \ No newline at end of file diff --git a/common/ui/src/main/java/com/tangem/common/ui/amountScreen/converters/field/AmountFieldMaxAmountTransformer.kt b/common/ui/src/main/java/com/tangem/common/ui/amountScreen/converters/field/AmountFieldMaxAmountTransformer.kt new file mode 100644 index 0000000000..05a8705750 --- /dev/null +++ b/common/ui/src/main/java/com/tangem/common/ui/amountScreen/converters/field/AmountFieldMaxAmountTransformer.kt @@ -0,0 +1,53 @@ +package com.tangem.common.ui.amountScreen.converters.field + +import androidx.compose.foundation.text.KeyboardOptions +import androidx.compose.ui.text.input.ImeAction +import androidx.compose.ui.text.input.KeyboardType +import com.tangem.common.ui.amountScreen.models.AmountState +import com.tangem.core.ui.utils.parseBigDecimal +import com.tangem.domain.tokens.model.CryptoCurrencyStatus +import com.tangem.utils.isNullOrZero +import com.tangem.utils.transformer.Transformer +import java.math.RoundingMode + +/** + * Selects maximum amount value + * + * @property cryptoCurrencyStatus current cryptocurrency status + */ +class AmountFieldMaxAmountTransformer( + private val cryptoCurrencyStatus: CryptoCurrencyStatus, +) : Transformer { + + override fun transform(prevState: AmountState): AmountState { + if (prevState !is AmountState.Data) return prevState + + val amountTextField = prevState.amountTextField + + val cryptoDecimals = amountTextField.cryptoAmount.decimals + val fiatDecimals = amountTextField.fiatAmount.decimals + val decimalCryptoValue = cryptoCurrencyStatus.value.amount + val decimalFiatValue = cryptoCurrencyStatus.value.fiatAmount + + if (decimalCryptoValue.isNullOrZero()) return prevState + + val isDoneActionEnabled = !decimalCryptoValue.isNullOrZero() + val cryptoValue = decimalCryptoValue?.parseBigDecimal(cryptoDecimals).orEmpty() + val fiatValue = decimalFiatValue?.parseBigDecimal(fiatDecimals, roundingMode = RoundingMode.HALF_UP).orEmpty() + return prevState.copy( + isPrimaryButtonEnabled = true, + amountTextField = amountTextField.copy( + isValuePasted = true, + value = cryptoValue, + fiatValue = fiatValue, + isError = false, + cryptoAmount = amountTextField.cryptoAmount.copy(value = decimalCryptoValue), + fiatAmount = amountTextField.fiatAmount.copy(value = decimalFiatValue), + keyboardOptions = KeyboardOptions( + imeAction = if (isDoneActionEnabled) ImeAction.Done else ImeAction.None, + keyboardType = KeyboardType.Number, + ), + ), + ) + } +} \ No newline at end of file diff --git a/common/ui/src/main/java/com/tangem/common/ui/amountScreen/models/AmountFieldModel.kt b/common/ui/src/main/java/com/tangem/common/ui/amountScreen/models/AmountFieldModel.kt new file mode 100644 index 0000000000..572239504d --- /dev/null +++ b/common/ui/src/main/java/com/tangem/common/ui/amountScreen/models/AmountFieldModel.kt @@ -0,0 +1,39 @@ +package com.tangem.common.ui.amountScreen.models + +import androidx.compose.foundation.text.KeyboardActions +import androidx.compose.foundation.text.KeyboardOptions +import com.tangem.core.ui.extensions.TextReference +import com.tangem.domain.tokens.model.Amount + +/** + * Model for amount field + * + * @param value entered value + * @param onValueChange on value change + * @param keyboardOptions keyboard options + * @param keyboardActions keyboard actions + * @param cryptoAmount value as amount + * @param fiatAmount value in fiat as amount + * @param isFiatValue indicates if app currency or crypto currency is selected + * @param fiatValue value in fiat + * @param isFiatUnavailable indicates if fiat rates are unavailable + * @param isValuePasted indicated if value was pasted + * @param onValuePastedTriggerDismiss on value pasted action + * @param isError indicates is value invalid + * @param error error text + */ +data class AmountFieldModel( + val value: String, + val onValueChange: (String) -> Unit, + val keyboardOptions: KeyboardOptions, + val keyboardActions: KeyboardActions, + val cryptoAmount: Amount, + val fiatAmount: Amount, + val isFiatValue: Boolean, + val fiatValue: String, + val isFiatUnavailable: Boolean, + val isValuePasted: Boolean, + val onValuePastedTriggerDismiss: () -> Unit, + val isError: Boolean, + val error: TextReference, +) \ No newline at end of file diff --git a/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/state/amount/SendAmountSegmentedButtonsConfig.kt b/common/ui/src/main/java/com/tangem/common/ui/amountScreen/models/AmountSegmentedButtonsConfig.kt similarity index 61% rename from features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/state/amount/SendAmountSegmentedButtonsConfig.kt rename to common/ui/src/main/java/com/tangem/common/ui/amountScreen/models/AmountSegmentedButtonsConfig.kt index eca219a09d..23469c4c03 100644 --- a/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/state/amount/SendAmountSegmentedButtonsConfig.kt +++ b/common/ui/src/main/java/com/tangem/common/ui/amountScreen/models/AmountSegmentedButtonsConfig.kt @@ -1,7 +1,7 @@ -package com.tangem.features.send.impl.presentation.state.amount +package com.tangem.common.ui.amountScreen.models import androidx.compose.runtime.Immutable -import com.tangem.core.ui.components.currency.tokenicon.TokenIconState +import com.tangem.core.ui.components.currency.icon.CurrencyIconState import com.tangem.core.ui.extensions.TextReference /** @@ -13,9 +13,9 @@ import com.tangem.core.ui.extensions.TextReference * @param isFiat is fiat currency */ @Immutable -internal data class SendAmountSegmentedButtonsConfig( +data class AmountSegmentedButtonsConfig( val title: TextReference, - val iconState: TokenIconState? = null, + val iconState: CurrencyIconState? = null, val iconUrl: String? = null, val isFiat: Boolean, ) \ No newline at end of file diff --git a/common/ui/src/main/java/com/tangem/common/ui/amountScreen/models/AmountState.kt b/common/ui/src/main/java/com/tangem/common/ui/amountScreen/models/AmountState.kt new file mode 100644 index 0000000000..d23a2892bf --- /dev/null +++ b/common/ui/src/main/java/com/tangem/common/ui/amountScreen/models/AmountState.kt @@ -0,0 +1,40 @@ +package com.tangem.common.ui.amountScreen.models + +import androidx.compose.runtime.Stable +import com.tangem.core.ui.components.currency.icon.CurrencyIconState +import com.tangem.core.ui.extensions.TextReference +import kotlinx.collections.immutable.PersistentList + +/** Model for amount state */ +@Stable +sealed class AmountState { + + abstract val isPrimaryButtonEnabled: Boolean + + /** + * @param isPrimaryButtonEnabled indicates if next state button enabled + * @param walletName user wallet name + * @param walletBalance user crypto currency balance in wallet + * @param tokenIconState crypto currency icon state + * @param segmentedButtonConfig currency switcher config + * @param selectedButton selected currency index + * @param isSegmentedButtonsEnabled indicates if currency switches is enabled + * @param amountTextField amount field state + * @param appCurrencyCode app currency code + */ + data class Data( + override val isPrimaryButtonEnabled: Boolean, + val walletName: String, + val walletBalance: TextReference, + val tokenIconState: CurrencyIconState, + val segmentedButtonConfig: PersistentList, + val selectedButton: Int, + val isSegmentedButtonsEnabled: Boolean, + val amountTextField: AmountFieldModel, + val appCurrencyCode: String, + ) : AmountState() + + data class Empty( + override val isPrimaryButtonEnabled: Boolean = false, + ) : AmountState() +} \ No newline at end of file diff --git a/common/ui/src/main/java/com/tangem/common/ui/amountScreen/preview/AmountScreenClickIntentsStub.kt b/common/ui/src/main/java/com/tangem/common/ui/amountScreen/preview/AmountScreenClickIntentsStub.kt new file mode 100644 index 0000000000..9509a15aed --- /dev/null +++ b/common/ui/src/main/java/com/tangem/common/ui/amountScreen/preview/AmountScreenClickIntentsStub.kt @@ -0,0 +1,16 @@ +package com.tangem.common.ui.amountScreen.preview + +import com.tangem.common.ui.amountScreen.AmountScreenClickIntents + +object AmountScreenClickIntentsStub : AmountScreenClickIntents { + + override fun onAmountValueChange(value: String) {} + + override fun onCurrencyChangeClick(isFiat: Boolean) {} + + override fun onMaxValueClick() {} + + override fun onAmountPasteTriggerDismiss() {} + + override fun onAmountNext() {} +} \ No newline at end of file diff --git a/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/state/previewdata/AmountStatePreviewData.kt b/common/ui/src/main/java/com/tangem/common/ui/amountScreen/preview/AmountStatePreviewData.kt similarity index 75% rename from features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/state/previewdata/AmountStatePreviewData.kt rename to common/ui/src/main/java/com/tangem/common/ui/amountScreen/preview/AmountStatePreviewData.kt index 7b2017d6e7..91951b4220 100644 --- a/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/state/previewdata/AmountStatePreviewData.kt +++ b/common/ui/src/main/java/com/tangem/common/ui/amountScreen/preview/AmountStatePreviewData.kt @@ -1,40 +1,38 @@ -package com.tangem.features.send.impl.presentation.state.previewdata +package com.tangem.common.ui.amountScreen.preview import androidx.compose.foundation.text.KeyboardActions import androidx.compose.foundation.text.KeyboardOptions -import com.tangem.core.ui.components.currency.tokenicon.TokenIconState +import com.tangem.common.ui.amountScreen.models.AmountFieldModel +import com.tangem.common.ui.amountScreen.models.AmountSegmentedButtonsConfig +import com.tangem.common.ui.amountScreen.models.AmountState +import com.tangem.core.ui.components.currency.icon.CurrencyIconState import com.tangem.core.ui.extensions.TextReference import com.tangem.core.ui.extensions.stringReference import com.tangem.domain.tokens.model.Amount import com.tangem.domain.tokens.model.AmountType -import com.tangem.features.send.impl.presentation.state.SendStates -import com.tangem.features.send.impl.presentation.state.SendUiStateType -import com.tangem.features.send.impl.presentation.state.amount.SendAmountSegmentedButtonsConfig -import com.tangem.features.send.impl.presentation.state.fields.SendTextField import kotlinx.collections.immutable.persistentListOf import java.math.BigDecimal -internal object AmountStatePreviewData { +object AmountStatePreviewData { - val amountState = SendStates.AmountState( - type = SendUiStateType.Amount, + val amountState = AmountState.Data( isPrimaryButtonEnabled = false, walletName = "Family Wallet", walletBalance = stringReference("2 130,88 USDT (2 129,92 \$)"), - tokenIconState = TokenIconState.Loading, + tokenIconState = CurrencyIconState.Loading, segmentedButtonConfig = persistentListOf( - SendAmountSegmentedButtonsConfig( + AmountSegmentedButtonsConfig( title = stringReference("USDT"), - iconState = TokenIconState.Locked, + iconState = CurrencyIconState.Locked, isFiat = false, ), - SendAmountSegmentedButtonsConfig( + AmountSegmentedButtonsConfig( title = stringReference("USD"), isFiat = true, ), ), appCurrencyCode = "usd", - amountTextField = SendTextField.AmountField( + amountTextField = AmountFieldModel( value = "", onValueChange = {}, keyboardOptions = KeyboardOptions.Default, diff --git a/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/ui/send/AmountBlock.kt b/common/ui/src/main/java/com/tangem/common/ui/amountScreen/ui/AmountBlock.kt similarity index 83% rename from features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/ui/send/AmountBlock.kt rename to common/ui/src/main/java/com/tangem/common/ui/amountScreen/ui/AmountBlock.kt index a4912c792e..b2903b20cc 100644 --- a/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/ui/send/AmountBlock.kt +++ b/common/ui/src/main/java/com/tangem/common/ui/amountScreen/ui/AmountBlock.kt @@ -1,4 +1,4 @@ -package com.tangem.features.send.impl.presentation.ui.send +package com.tangem.common.ui.amountScreen.ui import android.content.res.Configuration import androidx.compose.foundation.background @@ -15,21 +15,17 @@ import androidx.compose.ui.text.style.TextAlign import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.tooling.preview.PreviewParameter import androidx.compose.ui.tooling.preview.PreviewParameterProvider +import com.tangem.common.ui.amountScreen.models.AmountState +import com.tangem.common.ui.amountScreen.preview.AmountStatePreviewData import com.tangem.core.ui.components.ResizableText -import com.tangem.core.ui.components.currency.tokenicon.TokenIcon +import com.tangem.core.ui.components.currency.icon.CurrencyIcon import com.tangem.core.ui.res.TangemThemePreview import com.tangem.core.ui.res.TangemTheme import com.tangem.core.ui.utils.BigDecimalFormatter -import com.tangem.features.send.impl.presentation.state.SendStates -import com.tangem.features.send.impl.presentation.state.previewdata.AmountStatePreviewData @Composable -internal fun AmountBlock( - amountState: SendStates.AmountState, - isClickDisabled: Boolean, - isEditingDisabled: Boolean, - onClick: () -> Unit, -) { +fun AmountBlock(amountState: AmountState, isClickDisabled: Boolean, isEditingDisabled: Boolean, onClick: () -> Unit) { + if (amountState !is AmountState.Data) return val amount = amountState.amountTextField val cryptoAmount = BigDecimalFormatter.formatWithSymbol(amount.value, amount.cryptoAmount.currencySymbol) @@ -58,7 +54,7 @@ internal fun AmountBlock( .clickable(enabled = !isClickDisabled && !isEditingDisabled, onClick = onClick) .padding(TangemTheme.dimens.spacing16), ) { - TokenIcon(state = amountState.tokenIconState) + CurrencyIcon(state = amountState.tokenIconState) ResizableText( text = firstAmount, style = TangemTheme.typography.h2, @@ -85,7 +81,7 @@ internal fun AmountBlock( @Preview @Preview(uiMode = Configuration.UI_MODE_NIGHT_YES) @Composable -private fun AmountBlockPreview(@PreviewParameter(AmountBlockPreviewProvider::class) value: SendStates.AmountState) { +private fun AmountBlockPreview(@PreviewParameter(AmountBlockPreviewProvider::class) value: AmountState) { TangemThemePreview { AmountBlock( amountState = value, @@ -96,8 +92,8 @@ private fun AmountBlockPreview(@PreviewParameter(AmountBlockPreviewProvider::cla } } -private class AmountBlockPreviewProvider : PreviewParameterProvider { - override val values: Sequence +private class AmountBlockPreviewProvider : PreviewParameterProvider { + override val values: Sequence get() = sequenceOf( AmountStatePreviewData.amountState, ) diff --git a/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/ui/amount/AmountButtons.kt b/common/ui/src/main/java/com/tangem/common/ui/amountScreen/ui/AmountButtons.kt similarity index 85% rename from features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/ui/amount/AmountButtons.kt rename to common/ui/src/main/java/com/tangem/common/ui/amountScreen/ui/AmountButtons.kt index 19325703a5..b279e47f6a 100644 --- a/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/ui/amount/AmountButtons.kt +++ b/common/ui/src/main/java/com/tangem/common/ui/amountScreen/ui/AmountButtons.kt @@ -1,4 +1,4 @@ -package com.tangem.features.send.impl.presentation.ui.amount +package com.tangem.common.ui.amountScreen.ui import androidx.compose.foundation.background import androidx.compose.foundation.clickable @@ -13,22 +13,22 @@ import androidx.compose.ui.draw.clip import androidx.compose.ui.hapticfeedback.HapticFeedbackType import androidx.compose.ui.platform.LocalHapticFeedback import androidx.compose.ui.res.stringResource +import com.tangem.common.ui.R +import com.tangem.common.ui.amountScreen.AmountScreenClickIntents +import com.tangem.common.ui.amountScreen.models.AmountSegmentedButtonsConfig import com.tangem.core.ui.components.SpacerWMax import com.tangem.core.ui.components.buttons.segmentedbutton.SegmentedButtons import com.tangem.core.ui.components.currency.fiaticon.FiatIcon -import com.tangem.core.ui.components.currency.tokenicon.TokenIcon +import com.tangem.core.ui.components.currency.icon.CurrencyIcon import com.tangem.core.ui.extensions.resolveReference import com.tangem.core.ui.res.TangemTheme -import com.tangem.features.send.impl.R -import com.tangem.features.send.impl.presentation.state.amount.SendAmountSegmentedButtonsConfig -import com.tangem.features.send.impl.presentation.viewmodel.SendClickIntents import kotlinx.collections.immutable.PersistentList private const val AMOUNT_BUTTONS_KEY = "amountButtonsKey" internal fun LazyListScope.buttons( - segmentedButtonConfig: PersistentList, - clickIntents: SendClickIntents, + segmentedButtonConfig: PersistentList, + clickIntents: AmountScreenClickIntents, isSegmentedButtonsEnabled: Boolean, selectedButton: Int, ) { @@ -53,7 +53,7 @@ internal fun LazyListScope.buttons( initialSelectedItem = segmentedButtonConfig.getOrNull(selectedButton), isEnabled = isSegmentedButtonsEnabled, ) { - SendAmountCurrencyButton( + AmountCurrencyButton( button = it, isSegmentedButtonsEnabled = isSegmentedButtonsEnabled, ) @@ -84,7 +84,7 @@ internal fun LazyListScope.buttons( } @Composable -private fun SendAmountCurrencyButton(button: SendAmountSegmentedButtonsConfig, isSegmentedButtonsEnabled: Boolean) { +private fun AmountCurrencyButton(button: AmountSegmentedButtonsConfig, isSegmentedButtonsEnabled: Boolean) { Row( modifier = Modifier .fillMaxSize() @@ -94,7 +94,8 @@ private fun SendAmountCurrencyButton(button: SendAmountSegmentedButtonsConfig, i horizontalArrangement = Arrangement.Center, verticalAlignment = Alignment.CenterVertically, ) { - val iconModifier = Modifier.size(TangemTheme.dimens.size18) + val iconModifier = Modifier + .size(TangemTheme.dimens.size18) .padding(horizontal = TangemTheme.dimens.spacing1) if (button.isFiat) { FiatIcon( @@ -104,7 +105,7 @@ private fun SendAmountCurrencyButton(button: SendAmountSegmentedButtonsConfig, i modifier = iconModifier, ) } else if (button.iconState != null) { - TokenIcon( + CurrencyIcon( state = button.iconState, shouldDisplayNetwork = false, modifier = iconModifier, diff --git a/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/ui/amount/AmountField.kt b/common/ui/src/main/java/com/tangem/common/ui/amountScreen/ui/AmountField.kt similarity index 78% rename from features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/ui/amount/AmountField.kt rename to common/ui/src/main/java/com/tangem/common/ui/amountScreen/ui/AmountField.kt index 8f7a69c8c1..1144bf4bcd 100644 --- a/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/ui/amount/AmountField.kt +++ b/common/ui/src/main/java/com/tangem/common/ui/amountScreen/ui/AmountField.kt @@ -1,4 +1,4 @@ -package com.tangem.features.send.impl.presentation.ui.amount +package com.tangem.common.ui.amountScreen.ui import androidx.compose.animation.AnimatedVisibility import androidx.compose.animation.fadeIn @@ -7,13 +7,16 @@ import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.requiredHeightIn import androidx.compose.material3.Text -import androidx.compose.runtime.* +import androidx.compose.runtime.Composable +import androidx.compose.runtime.LaunchedEffect +import androidx.compose.runtime.remember import androidx.compose.ui.Alignment.Companion.BottomCenter import androidx.compose.ui.Modifier import androidx.compose.ui.focus.FocusRequester import androidx.compose.ui.focus.focusRequester import androidx.compose.ui.text.style.TextAlign import androidx.compose.ui.text.style.TextDirection +import com.tangem.common.ui.amountScreen.models.AmountFieldModel import com.tangem.core.ui.components.fields.AmountTextField import com.tangem.core.ui.components.fields.visualtransformations.AmountVisualTransformation import com.tangem.core.ui.extensions.TextReference @@ -21,18 +24,17 @@ import com.tangem.core.ui.extensions.resolveReference import com.tangem.core.ui.res.TangemTheme import com.tangem.core.ui.utils.BigDecimalFormatter import com.tangem.core.ui.utils.rememberDecimalFormat -import com.tangem.features.send.impl.presentation.state.fields.SendTextField import kotlinx.coroutines.delay @Composable -internal fun AmountField(sendField: SendTextField.AmountField, appCurrencyCode: String) { +internal fun AmountField(amountField: AmountFieldModel, appCurrencyCode: String) { val decimalFormat = rememberDecimalFormat() - val isFiatValue = sendField.isFiatValue + val isFiatValue = amountField.isFiatValue val currencyCode = if (isFiatValue) appCurrencyCode else null val (primaryAmount, primaryValue) = if (isFiatValue) { - sendField.fiatAmount to sendField.fiatValue + amountField.fiatAmount to amountField.fiatValue } else { - sendField.cryptoAmount to sendField.value + amountField.cryptoAmount to amountField.value } val requester = remember { FocusRequester() } @@ -45,16 +47,16 @@ internal fun AmountField(sendField: SendTextField.AmountField, appCurrencyCode: currencyCode = currencyCode, decimalFormat = decimalFormat, ), - onValueChange = sendField.onValueChange, - keyboardOptions = sendField.keyboardOptions, - keyboardActions = sendField.keyboardActions, + onValueChange = amountField.onValueChange, + keyboardOptions = amountField.keyboardOptions, + keyboardActions = amountField.keyboardActions, textStyle = TangemTheme.typography.h2.copy( color = TangemTheme.colors.text.primary1, textAlign = TextAlign.Center, ), isAutoResize = true, - isValuePasted = sendField.isValuePasted, - onValuePastedTriggerDismiss = sendField.onValuePastedTriggerDismiss, + isValuePasted = amountField.isValuePasted, + onValuePastedTriggerDismiss = amountField.onValuePastedTriggerDismiss, modifier = Modifier .focusRequester(requester) .padding( @@ -70,12 +72,12 @@ internal fun AmountField(sendField: SendTextField.AmountField, appCurrencyCode: requester.requestFocus() } - AmountSecondary(sendField, appCurrencyCode) + AmountSecondary(amountField, appCurrencyCode) } @Composable -private fun AmountSecondary(sendField: SendTextField.AmountField, appCurrencyCode: String) { - val secondaryAmount = if (sendField.isFiatValue) sendField.cryptoAmount else sendField.fiatAmount +private fun AmountSecondary(amountField: AmountFieldModel, appCurrencyCode: String) { + val secondaryAmount = if (amountField.isFiatValue) amountField.cryptoAmount else amountField.fiatAmount Box( modifier = Modifier .padding( @@ -84,7 +86,7 @@ private fun AmountSecondary(sendField: SendTextField.AmountField, appCurrencyCod end = TangemTheme.dimens.spacing12, ), ) { - val text = if (sendField.isFiatValue) { + val text = if (amountField.isFiatValue) { BigDecimalFormatter.formatCryptoAmount( cryptoAmount = secondaryAmount.value, cryptoCurrency = secondaryAmount.currencySymbol, @@ -107,8 +109,8 @@ private fun AmountSecondary(sendField: SendTextField.AmountField, appCurrencyCod .padding(bottom = TangemTheme.dimens.spacing32), ) AmountFieldError( - isError = sendField.isError, - error = sendField.error, + isError = amountField.isError, + error = amountField.error, modifier = Modifier .align(BottomCenter) .padding(bottom = TangemTheme.dimens.spacing12), diff --git a/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/ui/amount/AmountFieldContainer.kt b/common/ui/src/main/java/com/tangem/common/ui/amountScreen/ui/AmountFieldContainer.kt similarity index 86% rename from features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/ui/amount/AmountFieldContainer.kt rename to common/ui/src/main/java/com/tangem/common/ui/amountScreen/ui/AmountFieldContainer.kt index eb78c8d0a1..146c491074 100644 --- a/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/ui/amount/AmountFieldContainer.kt +++ b/common/ui/src/main/java/com/tangem/common/ui/amountScreen/ui/AmountFieldContainer.kt @@ -1,4 +1,4 @@ -package com.tangem.features.send.impl.presentation.ui.amount +package com.tangem.common.ui.amountScreen.ui import androidx.compose.animation.AnimatedContent import androidx.compose.foundation.background @@ -12,16 +12,16 @@ import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.draw.clip import androidx.compose.ui.text.style.TextAlign -import com.tangem.common.Strings.STARS -import com.tangem.core.ui.components.currency.tokenicon.TokenIcon +import com.tangem.common.ui.amountScreen.models.AmountState +import com.tangem.core.ui.components.currency.icon.CurrencyIcon import com.tangem.core.ui.extensions.resolveReference import com.tangem.core.ui.res.TangemTheme -import com.tangem.features.send.impl.presentation.state.SendStates +import com.tangem.utils.StringsSigns.STARS private const val AMOUNT_FIELD_KEY = "amountFieldKey" internal fun LazyListScope.amountField( - amountState: SendStates.AmountState, + amountState: AmountState.Data, isBalanceHiding: Boolean, modifier: Modifier = Modifier, ) { @@ -55,13 +55,13 @@ internal fun LazyListScope.amountField( .padding(top = TangemTheme.dimens.spacing2), ) } - TokenIcon( + CurrencyIcon( state = amountState.tokenIconState, modifier = Modifier .padding(top = TangemTheme.dimens.spacing32), ) AmountField( - sendField = amountState.amountTextField, + amountField = amountState.amountTextField, appCurrencyCode = amountState.appCurrencyCode, ) } diff --git a/common/ui/src/main/java/com/tangem/common/ui/amountScreen/ui/SendDoneButtons.kt b/common/ui/src/main/java/com/tangem/common/ui/amountScreen/ui/SendDoneButtons.kt new file mode 100644 index 0000000000..8689591d9b --- /dev/null +++ b/common/ui/src/main/java/com/tangem/common/ui/amountScreen/ui/SendDoneButtons.kt @@ -0,0 +1,73 @@ +package com.tangem.common.ui.amountScreen.ui + +import android.content.res.Configuration +import androidx.compose.animation.* +import androidx.compose.foundation.layout.Row +import androidx.compose.foundation.layout.padding +import androidx.compose.runtime.Composable +import androidx.compose.ui.Modifier +import androidx.compose.ui.hapticfeedback.HapticFeedbackType +import androidx.compose.ui.platform.LocalContext +import androidx.compose.ui.platform.LocalHapticFeedback +import androidx.compose.ui.res.stringResource +import androidx.compose.ui.tooling.preview.Preview +import com.tangem.core.ui.components.SecondaryButtonIconStart +import com.tangem.core.ui.components.SpacerW12 +import com.tangem.core.ui.extensions.shareText +import com.tangem.core.ui.res.TangemTheme +import com.tangem.common.ui.R +import com.tangem.core.ui.res.TangemThemePreview + +@Composable +fun SendDoneButtons( + txUrl: String, + onExploreClick: () -> Unit, + onShareClick: () -> Unit, + isVisible: Boolean, + modifier: Modifier = Modifier, +) { + val hapticFeedback = LocalHapticFeedback.current + val context = LocalContext.current + + AnimatedVisibility( + visible = isVisible && txUrl.isNotBlank(), + modifier = modifier, + enter = slideInVertically().plus(fadeIn()), + exit = slideOutVertically().plus(fadeOut()), + label = "Animate show sent state buttons", + ) { + Row(modifier = Modifier.padding(bottom = TangemTheme.dimens.spacing12)) { + SecondaryButtonIconStart( + text = stringResource(id = R.string.common_explore), + iconResId = R.drawable.ic_web_24, + onClick = onExploreClick, + modifier = Modifier.weight(1f), + ) + SpacerW12() + SecondaryButtonIconStart( + text = stringResource(id = R.string.common_share), + iconResId = R.drawable.ic_share_24, + onClick = { + hapticFeedback.performHapticFeedback(HapticFeedbackType.LongPress) + context.shareText(txUrl) + onShareClick() + }, + modifier = Modifier.weight(1f), + ) + } + } +} + +@Preview(showBackground = true, widthDp = 328) +@Preview(showBackground = true, widthDp = 328, uiMode = Configuration.UI_MODE_NIGHT_YES) +@Composable +private fun SendDoneButtons_Preview() { + TangemThemePreview { + SendDoneButtons( + txUrl = "txUrl", + onShareClick = {}, + onExploreClick = {}, + isVisible = true, + ) + } +} \ No newline at end of file diff --git a/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/state/amount/AmountUtils.kt b/common/ui/src/main/java/com/tangem/common/ui/amountScreen/utils/AmountUtils.kt similarity index 86% rename from features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/state/amount/AmountUtils.kt rename to common/ui/src/main/java/com/tangem/common/ui/amountScreen/utils/AmountUtils.kt index 3921429828..26492fa913 100644 --- a/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/state/amount/AmountUtils.kt +++ b/common/ui/src/main/java/com/tangem/common/ui/amountScreen/utils/AmountUtils.kt @@ -1,11 +1,11 @@ -package com.tangem.features.send.impl.presentation.state.amount +package com.tangem.common.ui.amountScreen.utils import androidx.compose.ui.text.input.ImeAction -import com.tangem.common.extensions.isZero +import com.tangem.common.ui.amountScreen.models.AmountFieldModel import com.tangem.core.ui.utils.parseBigDecimal import com.tangem.core.ui.utils.parseToBigDecimal import com.tangem.domain.tokens.model.CryptoCurrencyStatus -import com.tangem.features.send.impl.presentation.state.fields.SendTextField +import com.tangem.utils.isNullOrZero import java.math.BigDecimal import java.math.RoundingMode @@ -38,7 +38,7 @@ internal fun String.getFiatValue( internal fun String.checkExceedBalance( cryptoCurrencyStatus: CryptoCurrencyStatus, - amountTextField: SendTextField.AmountField, + amountTextField: AmountFieldModel, ): Boolean { val currencyCryptoAmount = cryptoCurrencyStatus.value.amount ?: BigDecimal.ZERO val currencyFiatAmount = cryptoCurrencyStatus.value.fiatAmount ?: BigDecimal.ZERO @@ -52,7 +52,7 @@ internal fun String.checkExceedBalance( } internal fun getKeyboardAction(isExceedBalance: Boolean, decimalCryptoValue: BigDecimal) = - if (!isExceedBalance && !decimalCryptoValue.isZero()) { + if (!isExceedBalance && !decimalCryptoValue.isNullOrZero()) { ImeAction.Done } else { ImeAction.None diff --git a/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/utils/FormatterUtils.kt b/common/ui/src/main/java/com/tangem/common/ui/amountScreen/utils/FormatterUtils.kt similarity index 79% rename from features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/utils/FormatterUtils.kt rename to common/ui/src/main/java/com/tangem/common/ui/amountScreen/utils/FormatterUtils.kt index 7c8a2becb6..67c6ed8cc9 100644 --- a/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/utils/FormatterUtils.kt +++ b/common/ui/src/main/java/com/tangem/common/ui/amountScreen/utils/FormatterUtils.kt @@ -1,4 +1,4 @@ -package com.tangem.features.send.impl.presentation.utils +package com.tangem.common.ui.amountScreen.utils import com.tangem.blockchain.common.Amount import com.tangem.core.ui.extensions.TextReference @@ -11,7 +11,7 @@ import java.math.BigDecimal private const val CRYPTO_FEE_DECIMALS = 6 -internal fun getCryptoReference(amount: Amount?, isFeeApproximate: Boolean): TextReference? { +fun getCryptoReference(amount: Amount?, isFeeApproximate: Boolean): TextReference? { if (amount == null) return null return combinedReference( if (isFeeApproximate) stringReference("${BigDecimalFormatter.CAN_BE_LOWER_SIGN} ") else TextReference.EMPTY, @@ -25,13 +25,13 @@ internal fun getCryptoReference(amount: Amount?, isFeeApproximate: Boolean): Tex ) } -internal fun getFiatReference(value: BigDecimal?, rate: BigDecimal?, appCurrency: AppCurrency): TextReference? { +fun getFiatReference(value: BigDecimal?, rate: BigDecimal?, appCurrency: AppCurrency): TextReference? { if (value == null || rate == null) return null val formattedFiat = getFiatString(value = value, rate = rate, appCurrency = appCurrency) return stringReference(formattedFiat) } -internal fun getFiatString(value: BigDecimal?, rate: BigDecimal?, appCurrency: AppCurrency): String { +fun getFiatString(value: BigDecimal?, rate: BigDecimal?, appCurrency: AppCurrency): String { if (value == null || rate == null) return EMPTY_BALANCE_SIGN val feeValue = value.multiply(rate) return BigDecimalFormatter.formatFiatAmount( diff --git a/common/ui/src/main/java/com/tangem/common/ui/bottomsheet/permission/GiveTxPermisssionBottomSheet.kt b/common/ui/src/main/java/com/tangem/common/ui/bottomsheet/permission/GiveTxPermisssionBottomSheet.kt new file mode 100644 index 0000000000..f59c494895 --- /dev/null +++ b/common/ui/src/main/java/com/tangem/common/ui/bottomsheet/permission/GiveTxPermisssionBottomSheet.kt @@ -0,0 +1,333 @@ +package com.tangem.common.ui.bottomsheet.permission + +import android.content.res.Configuration +import androidx.compose.foundation.background +import androidx.compose.foundation.clickable +import androidx.compose.foundation.interaction.MutableInteractionSource +import androidx.compose.foundation.layout.* +import androidx.compose.foundation.shape.RoundedCornerShape +import androidx.compose.material.ripple.rememberRipple +import androidx.compose.material3.* +import androidx.compose.runtime.* +import androidx.compose.ui.Alignment +import androidx.compose.ui.Modifier +import androidx.compose.ui.draw.clip +import androidx.compose.ui.graphics.Color +import androidx.compose.ui.graphics.vector.ImageVector +import androidx.compose.ui.graphics.vector.rememberVectorPainter +import androidx.compose.ui.layout.onSizeChanged +import androidx.compose.ui.platform.LocalDensity +import androidx.compose.ui.res.stringResource +import androidx.compose.ui.res.vectorResource +import androidx.compose.ui.text.style.TextAlign +import androidx.compose.ui.tooling.preview.Preview +import androidx.compose.ui.unit.DpOffset +import androidx.compose.ui.unit.IntSize +import androidx.compose.ui.window.PopupProperties +import com.tangem.common.ui.R +import com.tangem.common.ui.bottomsheet.permission.state.* +import com.tangem.core.ui.components.* +import com.tangem.core.ui.components.appbar.models.TopAppBarButtonUM +import com.tangem.core.ui.components.atoms.text.EllipsisText +import com.tangem.core.ui.components.bottomsheets.TangemBottomSheet +import com.tangem.core.ui.components.bottomsheets.TangemBottomSheetConfig +import com.tangem.core.ui.components.containers.FooterContainer +import com.tangem.core.ui.extensions.TextReference +import com.tangem.core.ui.extensions.resolveReference +import com.tangem.core.ui.extensions.resourceReference +import com.tangem.core.ui.res.TangemTheme +import com.tangem.core.ui.res.TangemThemePreview +import kotlinx.collections.immutable.ImmutableList + +@Composable +fun GiveTxPermissionBottomSheet(config: TangemBottomSheetConfig) { + var isPermissionAlertShow by remember { mutableStateOf(false) } + + TangemBottomSheet( + config = config, + containerColor = TangemTheme.colors.background.secondary, + titleText = resourceReference(R.string.give_permission_title), + titleAction = TopAppBarButtonUM( + iconRes = R.drawable.ic_information_24, + onIconClicked = { isPermissionAlertShow = true }, + ), + content = { content: GiveTxPermissionBottomSheetConfig -> + GiveTxPermissionBottomSheetContent(content = content) + + if (isPermissionAlertShow) { + BasicDialog( + message = content.data.dialogText.resolveReference(), + title = stringResource(id = R.string.common_approve), + confirmButton = DialogButton { isPermissionAlertShow = false }, + onDismissDialog = {}, + ) + } + }, + ) +} + +@Composable +private fun GiveTxPermissionBottomSheetContent(content: GiveTxPermissionBottomSheetConfig) { + val data = content.data + Column( + modifier = Modifier + .background(color = TangemTheme.colors.background.secondary) + .fillMaxWidth(), + horizontalAlignment = Alignment.CenterHorizontally, + ) { + Text( + text = content.data.subtitle.resolveReference(), + color = TangemTheme.colors.text.secondary, + style = TangemTheme.typography.body2, + textAlign = TextAlign.Center, + modifier = Modifier.padding(horizontal = TangemTheme.dimens.spacing24), + ) + + SpacerH16() + + ApprovalBottomSheetInfo(data) + + SpacerH(height = TangemTheme.dimens.spacing20) + + PrimaryButtonIconEnd( + text = stringResource(id = R.string.common_approve), + iconResId = R.drawable.ic_tangem_24, + modifier = Modifier + .fillMaxWidth() + .padding(horizontal = TangemTheme.dimens.spacing16), + onClick = data.approveButton.onClick, + ) + + SpacerH12() + + SecondaryButton( + text = stringResource(id = R.string.common_cancel), + modifier = Modifier + .fillMaxWidth() + .padding(horizontal = TangemTheme.dimens.spacing16), + onClick = content.onCancel, + ) + + SpacerH16() + } +} + +@Composable +private fun ApprovalBottomSheetInfo(data: GiveTxPermissionState.ReadyForRequest) { + FooterContainer( + footer = stringResource(id = R.string.give_permission_policy_type_footer), + modifier = Modifier.padding(horizontal = TangemTheme.dimens.spacing16), + ) { + AmountItem( + currency = data.currency, + approveType = data.approveType, + onChangeApproveType = data.onChangeApproveType, + approveItems = data.approveItems, + ) + } + SpacerH16() + FooterContainer( + footer = stringResource(id = R.string.give_permission_fee_footer), + modifier = Modifier.padding(horizontal = TangemTheme.dimens.spacing16), + ) { + FeeItem(fee = data.fee) + } +} + +@Composable +private fun FeeItem(fee: TextReference) { + Row( + modifier = Modifier + .fillMaxWidth() + .clip(TangemTheme.shapes.roundedCornersXMedium) + .background(TangemTheme.colors.background.action) + .padding( + top = TangemTheme.dimens.spacing16, + bottom = TangemTheme.dimens.spacing16, + start = TangemTheme.dimens.spacing12, + end = TangemTheme.dimens.spacing16, + ), + horizontalArrangement = Arrangement.SpaceBetween, + verticalAlignment = Alignment.CenterVertically, + ) { + Text( + text = stringResource(R.string.common_network_fee_title), + color = TangemTheme.colors.text.primary1, + style = TangemTheme.typography.subtitle1, + maxLines = 1, + ) + EllipsisText( + text = fee.resolveReference(), + color = TangemTheme.colors.text.tertiary, + style = TangemTheme.typography.body1, + modifier = Modifier.padding(start = TangemTheme.dimens.spacing16), + ) + } +} + +@Composable +private fun AmountItem( + currency: String, + approveType: ApproveType, + approveItems: ImmutableList, + onChangeApproveType: (ApproveType) -> Unit, +) { + var isExpandSelector by remember { mutableStateOf(false) } + var amountSize by remember { mutableStateOf(IntSize.Zero) } + Box( + modifier = Modifier + .fillMaxWidth() + .clip(TangemTheme.shapes.roundedCornersXMedium) + .background(TangemTheme.colors.background.action) + .clickable( + interactionSource = remember { MutableInteractionSource() }, + indication = rememberRipple(), + onClick = { isExpandSelector = true }, + ), + ) { + Row( + modifier = Modifier + .fillMaxWidth() + .onSizeChanged { amountSize = it } + .padding( + top = TangemTheme.dimens.spacing16, + bottom = TangemTheme.dimens.spacing16, + start = TangemTheme.dimens.spacing12, + end = TangemTheme.dimens.spacing16, + ), + horizontalArrangement = Arrangement.SpaceBetween, + verticalAlignment = Alignment.CenterVertically, + ) { + Text( + text = stringResource(id = R.string.give_permission_rows_amount, currency), + color = TangemTheme.colors.text.primary1, + style = TangemTheme.typography.subtitle1, + maxLines = 1, + ) + Text( + text = stringResource( + when (approveType) { + ApproveType.LIMITED -> R.string.give_permission_current_transaction + ApproveType.UNLIMITED -> R.string.give_permission_unlimited + }, + ), + color = TangemTheme.colors.text.tertiary, + style = TangemTheme.typography.body1, + maxLines = 1, + ) + } + DropdownSelector( + isExpanded = isExpandSelector, + onDismiss = { isExpandSelector = false }, + onItemClick = { approveType -> + isExpandSelector = false + onChangeApproveType.invoke(approveType) + }, + items = approveItems, + selectedType = approveType, + amountSize = amountSize, + ) + } +} + +@Suppress("LongParameterList") +@Composable +private fun DropdownSelector( + isExpanded: Boolean, + onDismiss: () -> Unit, + onItemClick: (ApproveType) -> Unit, + items: ImmutableList, + selectedType: ApproveType, + amountSize: IntSize, +) { + var dropDownWidth by remember { mutableStateOf(IntSize.Zero) } + val offsetY = amountSize.height.times(-1) + val offsetX = amountSize.width - dropDownWidth.width + + // Workaround to set color and shape of dropdown menu + MaterialTheme( + colorScheme = MaterialTheme.colorScheme.copy(surface = TangemTheme.colors.background.action), + shapes = MaterialTheme.shapes.copy(extraSmall = RoundedCornerShape(TangemTheme.dimens.radius16)), + ) { + DropdownMenu( + expanded = isExpanded, + onDismissRequest = onDismiss, + properties = PopupProperties(clippingEnabled = false), + offset = with(LocalDensity.current) { + DpOffset(x = offsetX.toDp(), y = offsetY.toDp()) + }, + modifier = Modifier + .wrapContentSize() + .background(TangemTheme.colors.background.action) + .onSizeChanged { dropDownWidth = it }, + ) { + items.forEach { item -> + val color = if (item == selectedType) TangemTheme.colors.icon.accent else Color.Transparent + + DropdownMenuItem( + modifier = Modifier.fillMaxWidth(), + text = { + Row { + Text( + text = when (item) { + ApproveType.LIMITED -> stringResource( + id = R.string.give_permission_current_transaction, + ) + ApproveType.UNLIMITED -> stringResource(id = R.string.give_permission_unlimited) + }, + color = TangemTheme.colors.text.primary1, + style = TangemTheme.typography.body1, + maxLines = 1, + ) + SpacerWMax() + Icon( + painter = rememberVectorPainter( + image = ImageVector.vectorResource(id = R.drawable.ic_check_24), + ), + tint = color, + contentDescription = null, + modifier = Modifier.padding(start = TangemTheme.dimens.size20), + ) + } + }, + onClick = { + onItemClick.invoke(item) + }, + ) + } + } + } +} + +// region preview +@Composable +@Preview(showBackground = true) +@Preview(showBackground = true, uiMode = Configuration.UI_MODE_NIGHT_YES) +private fun Preview_GiveTxPermissionBottomSheet() { + TangemThemePreview { + GiveTxPermissionBottomSheet( + config = TangemBottomSheetConfig( + isShow = true, + onDismissRequest = {}, + content = previewData, + ), + ) + } +} + +private val previewData = GiveTxPermissionBottomSheetConfig( + data = GiveTxPermissionState.ReadyForRequest( + currency = "DAI", + amount = "1", + walletAddress = "", + spenderAddress = "", + fee = TextReference.Str("2,14$"), + approveType = ApproveType.UNLIMITED, + approveButton = ApprovePermissionButton(true) {}, + cancelButton = CancelPermissionButton(true), + onChangeApproveType = { ApproveType.UNLIMITED }, + subtitle = resourceReference(R.string.give_permission_staking_subtitle), + dialogText = resourceReference(R.string.give_permission_staking_footer), + ), + onCancel = {}, +) \ No newline at end of file diff --git a/common/ui/src/main/java/com/tangem/common/ui/bottomsheet/permission/state/GiveTxPermissionBottomSheetConfig.kt b/common/ui/src/main/java/com/tangem/common/ui/bottomsheet/permission/state/GiveTxPermissionBottomSheetConfig.kt new file mode 100644 index 0000000000..08ffdcc086 --- /dev/null +++ b/common/ui/src/main/java/com/tangem/common/ui/bottomsheet/permission/state/GiveTxPermissionBottomSheetConfig.kt @@ -0,0 +1,8 @@ +package com.tangem.common.ui.bottomsheet.permission.state + +import com.tangem.core.ui.components.bottomsheets.TangemBottomSheetConfigContent + +data class GiveTxPermissionBottomSheetConfig( + val data: GiveTxPermissionState.ReadyForRequest, + val onCancel: () -> Unit, +) : TangemBottomSheetConfigContent \ No newline at end of file diff --git a/features/swap/presentation/src/main/java/com/tangem/feature/swap/models/SwapPermissionStateHolder.kt b/common/ui/src/main/java/com/tangem/common/ui/bottomsheet/permission/state/GiveTxPermissionState.kt similarity index 61% rename from features/swap/presentation/src/main/java/com/tangem/feature/swap/models/SwapPermissionStateHolder.kt rename to common/ui/src/main/java/com/tangem/common/ui/bottomsheet/permission/state/GiveTxPermissionState.kt index 7e31eb9e60..dbdce22ba9 100644 --- a/features/swap/presentation/src/main/java/com/tangem/feature/swap/models/SwapPermissionStateHolder.kt +++ b/common/ui/src/main/java/com/tangem/common/ui/bottomsheet/permission/state/GiveTxPermissionState.kt @@ -1,42 +1,35 @@ -package com.tangem.feature.swap.models +package com.tangem.common.ui.bottomsheet.permission.state import com.tangem.core.ui.extensions.TextReference -import com.tangem.feature.swap.domain.models.domain.SwapApproveType import kotlinx.collections.immutable.ImmutableList import kotlinx.collections.immutable.toImmutableList -sealed class SwapPermissionState { +sealed class GiveTxPermissionState { - object InProgress : SwapPermissionState() + data object InProgress : GiveTxPermissionState() - object Empty : SwapPermissionState() + data object Empty : GiveTxPermissionState() data class ReadyForRequest( - val providerName: String, + val subtitle: TextReference, + val dialogText: TextReference, val currency: String, val amount: String, val walletAddress: String, val spenderAddress: String, val fee: TextReference, val approveType: ApproveType, - val approveItems: ImmutableList = ApproveType.values().toList().toImmutableList(), + val approveItems: ImmutableList = ApproveType.entries.toImmutableList(), val approveButton: ApprovePermissionButton, val cancelButton: CancelPermissionButton, val onChangeApproveType: (ApproveType) -> Unit, - ) : SwapPermissionState() + ) : GiveTxPermissionState() } enum class ApproveType { LIMITED, UNLIMITED } -fun ApproveType.toDomainApproveType(): SwapApproveType { - return when (this) { - ApproveType.LIMITED -> SwapApproveType.LIMITED - ApproveType.UNLIMITED -> SwapApproveType.UNLIMITED - } -} - data class ApprovePermissionButton( val enabled: Boolean, val loading: Boolean = false, diff --git a/core/analytics/build.gradle.kts b/core/analytics/build.gradle.kts index 9d05970191..c61c8e7af2 100644 --- a/core/analytics/build.gradle.kts +++ b/core/analytics/build.gradle.kts @@ -15,6 +15,7 @@ dependencies { /** Domain */ implementation(projects.domain.analytics) + implementation(projects.domain.models) /** Other */ implementation(deps.kotlin.coroutines) diff --git a/core/analytics/models/src/main/java/com/tangem/core/analytics/models/AnalyticsParam.kt b/core/analytics/models/src/main/java/com/tangem/core/analytics/models/AnalyticsParam.kt index c7c73612f8..093769910b 100644 --- a/core/analytics/models/src/main/java/com/tangem/core/analytics/models/AnalyticsParam.kt +++ b/core/analytics/models/src/main/java/com/tangem/core/analytics/models/AnalyticsParam.kt @@ -65,6 +65,7 @@ sealed class AnalyticsParam { data object Intro : ScreensSources("Introduction") data object MyWallets : ScreensSources("My Wallets") data object Token : ScreensSources("Token") + data object Stories : ScreensSources("Stories") } sealed class TxSentFrom(val value: String) { diff --git a/core/analytics/src/main/java/com/tangem/core/analytics/utils/AnalyticsContextProxy.kt b/core/analytics/src/main/java/com/tangem/core/analytics/utils/AnalyticsContextProxy.kt new file mode 100644 index 0000000000..cab4da6a7b --- /dev/null +++ b/core/analytics/src/main/java/com/tangem/core/analytics/utils/AnalyticsContextProxy.kt @@ -0,0 +1,17 @@ +package com.tangem.core.analytics.utils + +import com.tangem.domain.models.scan.ScanResponse + +/** +[REDACTED_AUTHOR] + */ +interface AnalyticsContextProxy { + + fun setContext(scanResponse: ScanResponse) + + fun eraseContext() + + fun addContext(scanResponse: ScanResponse) + + fun removeContext() +} \ No newline at end of file diff --git a/core/datasource/build.gradle.kts b/core/datasource/build.gradle.kts index 4deb2329d1..0a236d6e5a 100644 --- a/core/datasource/build.gradle.kts +++ b/core/datasource/build.gradle.kts @@ -25,6 +25,7 @@ dependencies { implementation(projects.domain.wallets.models) implementation(projects.domain.balanceHiding.models) implementation(projects.domain.txhistory.models) + implementation(projects.domain.staking.models) /** Tangem libraries */ implementation(deps.tangem.blockchain) diff --git a/core/datasource/src/main/java/com/tangem/datasource/api/common/adapter/UnknownEnumMoshiAdapter.kt b/core/datasource/src/main/java/com/tangem/datasource/api/common/adapter/UnknownEnumMoshiAdapter.kt index f61191a104..2e6adf8fe7 100644 --- a/core/datasource/src/main/java/com/tangem/datasource/api/common/adapter/UnknownEnumMoshiAdapter.kt +++ b/core/datasource/src/main/java/com/tangem/datasource/api/common/adapter/UnknownEnumMoshiAdapter.kt @@ -1,13 +1,43 @@ package com.tangem.datasource.api.common.adapter -import com.squareup.moshi.* +import com.squareup.moshi.JsonAdapter +import com.squareup.moshi.Moshi import com.squareup.moshi.adapters.EnumJsonAdapter +import com.tangem.datasource.api.stakekit.models.response.model.BalanceDTO +import com.tangem.datasource.api.stakekit.models.response.model.NetworkTypeDTO +import com.tangem.datasource.api.stakekit.models.response.model.YieldDTO +import com.tangem.datasource.api.stakekit.models.response.model.action.StakingActionStatusDTO +import com.tangem.datasource.api.stakekit.models.response.model.action.StakingActionTypeDTO +import com.tangem.datasource.api.stakekit.models.response.model.transaction.StakingTransactionStatusDTO +import com.tangem.datasource.api.stakekit.models.response.model.transaction.StakingTransactionTypeDTO /** * Object to create a adapter for enum types with support for unknown enum values. */ object UnknownEnumMoshiAdapter { - fun > create(enumType: Class, defaultValue: T): JsonAdapter = - EnumJsonAdapter.create(enumType).withUnknownFallback(defaultValue) + @Suppress("UNCHECKED_CAST") + fun > create(enumType: Class>, defaultValue: Enum<*>): JsonAdapter> { + return EnumJsonAdapter.create(enumType as Class).withUnknownFallback(defaultValue as T) + } +} + +fun Moshi.Builder.addStakeKitEnumFallbackAdapters(): Moshi.Builder { + val map = mapOf( + NetworkTypeDTO::class.java to NetworkTypeDTO.UNKNOWN, + StakingActionTypeDTO::class.java to StakingActionTypeDTO.UNKNOWN, + YieldDTO.RewardTypeDTO::class.java to YieldDTO.RewardTypeDTO.UNKNOWN, + BalanceDTO.BalanceType::class.java to BalanceDTO.BalanceType.UNKNOWN, + StakingTransactionTypeDTO::class.java to StakingTransactionTypeDTO.UNKNOWN, + StakingTransactionStatusDTO::class.java to StakingTransactionStatusDTO.UNKNOWN, + StakingActionStatusDTO::class.java to StakingActionStatusDTO.UNKNOWN, + ) + + return apply { + map.forEach { entry -> + val enumClass = entry.key + val unknownValue = entry.value + add(enumClass, UnknownEnumMoshiAdapter.create(enumClass, unknownValue)) + } + } } \ No newline at end of file diff --git a/core/datasource/src/main/java/com/tangem/datasource/api/markets/TangemTechMarketsApi.kt b/core/datasource/src/main/java/com/tangem/datasource/api/markets/TangemTechMarketsApi.kt new file mode 100644 index 0000000000..014f9adf75 --- /dev/null +++ b/core/datasource/src/main/java/com/tangem/datasource/api/markets/TangemTechMarketsApi.kt @@ -0,0 +1,41 @@ +package com.tangem.datasource.api.markets + +import com.tangem.datasource.api.common.response.ApiResponse +import com.tangem.datasource.api.markets.models.response.* +import retrofit2.http.GET +import retrofit2.http.Path +import retrofit2.http.Query + +interface TangemTechMarketsApi { + + @Suppress("LongParameterList") + @GET("coins/list") + suspend fun getCoinsList( + @Query("currency") currency: String, + @Query("interval") interval: String, + @Query("offset") offset: Int, + @Query("limit") limit: Int, + @Query("order") order: String, + @Query("general_coins") generalCoins: Boolean, + @Query("search") search: String?, + ): ApiResponse + + @GET("coins/{coin_id}") + suspend fun getCoinMarketData( + @Path("coin_id") coinId: String, + @Query("currency") currency: String, + ): ApiResponse + + @GET("coins/{coin_id}/history") + suspend fun getCoinChart( + @Query("currency") currency: String, + @Query("interval") interval: String, + ): ApiResponse + + @GET("coins/history_preview") + suspend fun getCoinsListCharts( + @Query("coin_ids") coinIds: String, + @Query("currency") currency: String, + @Query("interval") interval: String, + ): ApiResponse +} \ No newline at end of file diff --git a/core/datasource/src/main/java/com/tangem/datasource/api/markets/models/response/TokenMarketChartListResponse.kt b/core/datasource/src/main/java/com/tangem/datasource/api/markets/models/response/TokenMarketChartListResponse.kt new file mode 100644 index 0000000000..b2f534b038 --- /dev/null +++ b/core/datasource/src/main/java/com/tangem/datasource/api/markets/models/response/TokenMarketChartListResponse.kt @@ -0,0 +1,3 @@ +package com.tangem.datasource.api.markets.models.response + +typealias TokenMarketChartListResponse = Map \ No newline at end of file diff --git a/core/datasource/src/main/java/com/tangem/datasource/api/markets/models/response/TokenMarketChartResponse.kt b/core/datasource/src/main/java/com/tangem/datasource/api/markets/models/response/TokenMarketChartResponse.kt new file mode 100644 index 0000000000..777bbc1228 --- /dev/null +++ b/core/datasource/src/main/java/com/tangem/datasource/api/markets/models/response/TokenMarketChartResponse.kt @@ -0,0 +1,9 @@ +package com.tangem.datasource.api.markets.models.response + +import com.squareup.moshi.Json +import java.math.BigDecimal + +data class TokenMarketChartResponse( + @Json(name = "prices") + val prices: Map, +) \ No newline at end of file diff --git a/core/datasource/src/main/java/com/tangem/datasource/api/markets/models/response/TokenMarketDetailsResponse.kt b/core/datasource/src/main/java/com/tangem/datasource/api/markets/models/response/TokenMarketDetailsResponse.kt new file mode 100644 index 0000000000..227496a66e --- /dev/null +++ b/core/datasource/src/main/java/com/tangem/datasource/api/markets/models/response/TokenMarketDetailsResponse.kt @@ -0,0 +1,132 @@ +package com.tangem.datasource.api.markets.models.response + +import com.squareup.moshi.Json +import java.math.BigDecimal + +data class TokenMarketDetailsResponse( + @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 = "current_price") + val currentPrice: BigDecimal, + @Json(name = "price_change_percentage") + val priceChangePercentage: PriceChangePercentage, + @Json(name = "networks") + val networks: List, + @Json(name = "short_description") + val shortDescription: String?, + @Json(name = "full_description") + val fullDescription: String?, + @Json(name = "insights") + val insights: List?, + @Json(name = "metrics") + val metrics: Metrics, + @Json(name = "links") + val links: Links, + @Json(name = "price_performance") + val pricePerformance: PricePerformance, +) { + data class PriceChangePercentage( + @Json(name = "24h") + val h24: BigDecimal, + @Json(name = "1w") + val week1: BigDecimal, + @Json(name = "1m") + val month1: BigDecimal, + @Json(name = "3m") + val month3: BigDecimal, + @Json(name = "6m") + val month6: BigDecimal, + @Json(name = "1y") + val year1: BigDecimal, + @Json(name = "all_time") + val allTime: BigDecimal, + ) + + data class Network( + @Json(name = "network_id") + val networkId: String, + @Json(name = "exchangeable") + val exchangeable: Boolean, + @Json(name = "contract_address") + val contractAddress: String, + @Json(name = "decimalCount") + val decimalCount: Int, + ) + + data class Insight( + @Json(name = "holders_change") + val holdersChange: Change, + @Json(name = "liquidity_change") + val liquidityChange: Change, + @Json(name = "buy_pressure_change") + val buyPressureChange: Change, + @Json(name = "experienced_buyer_change") + val experiencedBuyerChange: Change, + ) { + data class Change( + @Json(name = "1d") + val day1: Int, + @Json(name = "1w") + val week1: Int, + @Json(name = "1m") + val month1: Int, + ) + } + + data class Metrics( + @Json(name = "market_rating") + val marketRating: Int, + @Json(name = "circulating_supply") + val circulatingSupply: BigDecimal, + @Json(name = "market_cap") + val marketCap: BigDecimal, + @Json(name = "volume_24h") + val volume24h: BigDecimal, + @Json(name = "total_supply") + val totalSupply: BigDecimal, + @Json(name = "fully_diluted_valuation") + val fullyDilutedValuation: BigDecimal, + ) + + data class Links( + @Json(name = "official_links") + val officialLinks: List = emptyList(), + @Json(name = "social") + val social: List = emptyList(), + @Json(name = "repository") + val repository: List = emptyList(), + @Json(name = "blockchain_site") + val blockchainSite: List = emptyList(), + ) + + data class Link( + @Json(name = "title") + val title: String?, + @Json(name = "id") + val id: String, + @Json(name = "link") + val url: String, + ) + + data class PricePerformance( + @Json(name = "high_price") + val highPrice: Price, + @Json(name = "low_price") + val lowPrice: Price, + ) { + data class Price( + @Json(name = "24h") + val h24: BigDecimal, + @Json(name = "1m") + val month1: BigDecimal, + @Json(name = "all_time") + val allTime: BigDecimal, + ) + } +} \ No newline at end of file diff --git a/core/datasource/src/main/java/com/tangem/datasource/api/markets/models/response/TokenMarketListResponse.kt b/core/datasource/src/main/java/com/tangem/datasource/api/markets/models/response/TokenMarketListResponse.kt new file mode 100644 index 0000000000..b1e8675206 --- /dev/null +++ b/core/datasource/src/main/java/com/tangem/datasource/api/markets/models/response/TokenMarketListResponse.kt @@ -0,0 +1,43 @@ +package com.tangem.datasource.api.markets.models.response + +import com.squareup.moshi.Json +import java.math.BigDecimal + +data class TokenMarketListResponse( + @Json(name = "imageHost") + val imageHost: String?, + @Json(name = "tokens") + val tokens: List, + @Json(name = "total") + val total: Int, + @Json(name = "limit") + val limit: Int, + @Json(name = "offset") + val offset: Int, +) { + data class Token( + @Json(name = "id") + val id: String, + @Json(name = "name") + val name: String, + @Json(name = "symbol") + val symbol: String, + @Json(name = "current_price") + val currentPrice: BigDecimal, + @Json(name = "price_change_percentage") + val priceChangePercentage: PriceChangePercentage, + @Json(name = "market_rating") + val marketRating: Int?, + @Json(name = "market_cap") + val marketCap: BigDecimal?, + ) { + data class PriceChangePercentage( + @Json(name = "24h") + val h24: BigDecimal, + @Json(name = "1w") + val week1: BigDecimal, + @Json(name = "30d") + val day30: BigDecimal, + ) + } +} \ No newline at end of file diff --git a/core/datasource/src/main/java/com/tangem/datasource/api/stakekit/StakeKitApi.kt b/core/datasource/src/main/java/com/tangem/datasource/api/stakekit/StakeKitApi.kt index c7d564c69a..2d5bd551ac 100644 --- a/core/datasource/src/main/java/com/tangem/datasource/api/stakekit/StakeKitApi.kt +++ b/core/datasource/src/main/java/com/tangem/datasource/api/stakekit/StakeKitApi.kt @@ -1,48 +1,77 @@ package com.tangem.datasource.api.stakekit import com.tangem.datasource.api.common.response.ApiResponse -import com.tangem.datasource.api.stakekit.models.request.YieldBalanceRequestBody -import com.tangem.datasource.api.stakekit.models.request.RevenueOption -import com.tangem.datasource.api.stakekit.models.request.YieldType +import com.tangem.datasource.api.stakekit.models.request.* import com.tangem.datasource.api.stakekit.models.response.EnabledYieldsResponse -import com.tangem.datasource.api.stakekit.models.response.model.TokenWithYield -import com.tangem.datasource.api.stakekit.models.response.model.Yield -import com.tangem.datasource.api.stakekit.models.response.model.YieldBalanceWrapper -import retrofit2.http.Body -import retrofit2.http.GET -import retrofit2.http.Path -import retrofit2.http.Query +import com.tangem.datasource.api.stakekit.models.response.EnterActionResponse +import com.tangem.datasource.api.stakekit.models.response.model.BalanceDTO +import com.tangem.datasource.api.stakekit.models.response.model.TokenWithYieldDTO +import com.tangem.datasource.api.stakekit.models.response.model.YieldBalanceWrapperDTO +import com.tangem.datasource.api.stakekit.models.response.model.YieldDTO +import com.tangem.datasource.api.stakekit.models.response.model.transaction.StakingGasEstimateDTO +import com.tangem.datasource.api.stakekit.models.response.model.transaction.StakingTransactionDTO +import retrofit2.http.* @Suppress("LongParameterList") interface StakeKitApi { @GET("yields/enabled") suspend fun getMultipleYields( - @Query("ledgerWalletAPICompatible") ledgerWalletAPICompatible: Boolean, - @Query("type") type: YieldType, - @Query("revenueOption") revenueOption: RevenueOption, - @Query("page") page: Int, - @Query("network") network: String, - @Query("limit") limit: Int, + @Query("ledgerWalletAPICompatible") ledgerWalletAPICompatible: Boolean? = null, + @Query("type") type: YieldType? = null, + @Query("revenueOption") revenueOption: RevenueOption? = null, + @Query("page") page: Int? = null, + @Query("network") network: String? = null, + @Query("limit") limit: Int? = null, ): ApiResponse @GET("yields/{integrationId}") suspend fun getSingleYield( @Path("integrationId") integrationId: String, @Query("ledgerWalletAPICompatible") ledgerWalletAPICompatible: Boolean = false, - ): ApiResponse + ): ApiResponse - @GET("yields/balances") + @POST("yields/balances") suspend fun getMultipleYieldBalances( @Body body: List, - ): ApiResponse> + ): ApiResponse> - @GET("yields/{integrationId}/balances") + @POST("yields/{integrationId}/balances") suspend fun getSingleYieldBalance( @Path("integrationId") integrationId: String, @Body body: YieldBalanceRequestBody, - ): ApiResponse + ): ApiResponse> @GET("tokens") - suspend fun getTokens(): ApiResponse> + suspend fun getTokens(): ApiResponse> + + @POST("actions/enter") + suspend fun createEnterAction(@Body body: ActionRequestBody): ApiResponse + + @POST("actions/exit") + suspend fun createExitAction(@Body body: ActionRequestBody): ApiResponse + + @POST("actions/pending") + suspend fun createPendingAction(@Body body: PendingActionRequestBody): ApiResponse + + @POST("actions/enter/estimate-gas") + suspend fun estimateGasOnEnter(@Body body: ActionRequestBody): ApiResponse + + @POST("actions/exit/estimate-gas") + suspend fun estimateGasOnExit(@Body body: ActionRequestBody): ApiResponse + + @POST("actions/pending/estimate-gas") + suspend fun estimateGasOnPending(@Body body: PendingActionRequestBody): ApiResponse + + @PATCH("transactions/{transactionId}") + suspend fun constructTransaction( + @Path("transactionId") transactionId: String, + @Body body: ConstructTransactionRequestBody, + ): ApiResponse + + @POST("transactions/{transactionId}/submit_hash") + suspend fun submitTransactionHash( + @Path("transactionId") transactionId: String, + @Body body: SubmitTransactionHashRequestBody, + ): ApiResponse } \ No newline at end of file diff --git a/core/datasource/src/main/java/com/tangem/datasource/api/stakekit/models/request/ActionRequestBody.kt b/core/datasource/src/main/java/com/tangem/datasource/api/stakekit/models/request/ActionRequestBody.kt new file mode 100644 index 0000000000..d6c09517c1 --- /dev/null +++ b/core/datasource/src/main/java/com/tangem/datasource/api/stakekit/models/request/ActionRequestBody.kt @@ -0,0 +1,63 @@ +package com.tangem.datasource.api.stakekit.models.request + +import com.squareup.moshi.Json +import com.tangem.datasource.api.stakekit.models.request.ConstructTransactionRequestBody.GasArgs +import com.tangem.datasource.api.stakekit.models.response.model.BalanceDTO +import com.tangem.datasource.api.stakekit.models.response.model.TokenDTO +import com.tangem.domain.staking.model.stakekit.action.StakingActionType + +data class PendingActionRequestBody( + @Json(name = "type") + val type: StakingActionType, + @Json(name = "integrationId") + val integrationId: String, + @Json(name = "passthrough") + val passthrough: String, + @Json(name = "args") + val args: ActionRequestBodyArgs, + @Json(name = "gasArgs") + val gasArgs: GasArgs? = null, // used only in estimate_gas request +) + +data class ActionRequestBody( + @Json(name = "integrationId") + val integrationId: String, + @Json(name = "addresses") + val addresses: Address, + @Json(name = "args") + val args: ActionRequestBodyArgs, + @Json(name = "referralCode") + val referralCode: String? = null, + @Json(name = "gasArgs") + val gasArgs: GasArgs? = null, // used only in estimate_gas request +) + +data class ActionRequestBodyArgs( + @Json(name = "amount") + val amount: String, + @Json(name = "validatorAddress") + val validatorAddress: String? = null, + @Json(name = "validatorAddresses") + val validatorAddresses: List? = null, + @Json(name = "providerId") + val providerId: String? = null, + @Json(name = "duration") + val duration: String? = null, + @Json(name = "nfts") + val nfts: List? = null, + @Json(name = "ledgerWalletAPICompatible") + val ledgerWalletAPICompatible: Boolean? = null, + @Json(name = "tronResource") + val tronResource: String? = null, + @Json(name = "signatureVerification") + val signatureVerification: SignatureVerification? = null, + @Json(name = "inputToken") + val inputToken: TokenDTO? = null, +) + +data class SignatureVerification( + @Json(name = "message") + val message: String, + @Json(name = "signed") + val signed: String, +) \ No newline at end of file diff --git a/core/datasource/src/main/java/com/tangem/datasource/api/stakekit/models/request/Address.kt b/core/datasource/src/main/java/com/tangem/datasource/api/stakekit/models/request/Address.kt new file mode 100644 index 0000000000..4e93f0353a --- /dev/null +++ b/core/datasource/src/main/java/com/tangem/datasource/api/stakekit/models/request/Address.kt @@ -0,0 +1,40 @@ +package com.tangem.datasource.api.stakekit.models.request + +import com.squareup.moshi.Json + +data class Address( + @Json(name = "address") + val address: String, + @Json(name = "additionalAddresses") + val additionalAddresses: AdditionalAddresses? = null, + @Json(name = "explorerUrl") + val explorerUrl: String? = null, +) { + + data class AdditionalAddresses( + // cosmos-specific + @Json(name = "cosmosPubKey") + val cosmosPubKey: String? = null, + + // binance-specific + @Json(name = "binanceBeaconAddress") + val binanceBeaconAddress: String? = null, + + // solana-specific + @Deprecated("Legacy in StakeKit, isn't used in Solana") + @Json(name = "stakeAccounts") + val stakeAccounts: List? = null, + @Json(name = "lidoStakeAccounts") + val lidoStakeAccounts: List? = null, + + // tezos-specific + @Json(name = "tezosPubKey") + val tezosPubKey: String? = null, + + // avalanche-specific + @Json(name = "cAddressBech") + val cAddressBech: String? = null, + @Json(name = "pAddressBech") + val pAddressBech: String? = null, + ) +} \ No newline at end of file diff --git a/core/datasource/src/main/java/com/tangem/datasource/api/stakekit/models/request/ConstructTransactionRequestBody.kt b/core/datasource/src/main/java/com/tangem/datasource/api/stakekit/models/request/ConstructTransactionRequestBody.kt new file mode 100644 index 0000000000..60ee34b310 --- /dev/null +++ b/core/datasource/src/main/java/com/tangem/datasource/api/stakekit/models/request/ConstructTransactionRequestBody.kt @@ -0,0 +1,24 @@ +package com.tangem.datasource.api.stakekit.models.request + +import com.squareup.moshi.Json +import java.math.BigDecimal + +data class ConstructTransactionRequestBody( + @Json(name = "gasArgs") + val gasArgs: GasArgs? = null, + @Json(name = "ledgerWalletAPICompatible") + val ledgerWalletAPICompatible: Boolean? = null, +) { + data class GasArgs( + // cosmos-specific + @Json(name = "gasPrice") + val gasPrice: BigDecimal? = null, + // EVM eip 1559 specific + @Json(name = "type") + val type: Int? = null, + @Json(name = "maxFeePerGas") + val maxFeePerGas: BigDecimal? = null, + @Json(name = "maxPriorityFeePerGas") + val maxPriorityFeePerGas: BigDecimal? = null, + ) +} \ No newline at end of file diff --git a/core/datasource/src/main/java/com/tangem/datasource/api/stakekit/models/request/SubmitTransactionHashRequestBody.kt b/core/datasource/src/main/java/com/tangem/datasource/api/stakekit/models/request/SubmitTransactionHashRequestBody.kt new file mode 100644 index 0000000000..c07a103fe1 --- /dev/null +++ b/core/datasource/src/main/java/com/tangem/datasource/api/stakekit/models/request/SubmitTransactionHashRequestBody.kt @@ -0,0 +1,8 @@ +package com.tangem.datasource.api.stakekit.models.request + +import com.squareup.moshi.Json + +data class SubmitTransactionHashRequestBody( + @Json(name = "hash") + val hash: String, +) \ No newline at end of file diff --git a/core/datasource/src/main/java/com/tangem/datasource/api/stakekit/models/request/YieldBalanceRequestBody.kt b/core/datasource/src/main/java/com/tangem/datasource/api/stakekit/models/request/YieldBalanceRequestBody.kt index 7433386e73..b950b05390 100644 --- a/core/datasource/src/main/java/com/tangem/datasource/api/stakekit/models/request/YieldBalanceRequestBody.kt +++ b/core/datasource/src/main/java/com/tangem/datasource/api/stakekit/models/request/YieldBalanceRequestBody.kt @@ -5,26 +5,9 @@ import com.squareup.moshi.Json data class YieldBalanceRequestBody( @Json(name = "addresses") val addresses: Address, @Json(name = "args") val args: YieldBalanceRequestArgs, - @Json(name = "integrationId") val integrationId: String? = null, + @Json(name = "integrationId") val integrationId: String, ) { - data class Address( - @Json(name = "address") val address: String, - @Json(name = "additionalAddresses") val additionalAddresses: AdditionalAddresses? = null, - @Json(name = "explorerUrl") val explorerUrl: String, - ) { - - data class AdditionalAddresses( - @Json(name = "cosmosPubKey") val cosmosPubKey: String? = null, - @Json(name = "binanceBeaconAddress") val binanceBeaconAddress: String? = null, - @Json(name = "stakeAccounts") val stakeAccounts: List? = null, - @Json(name = "lidoStakeAccounts") val lidoStakeAccounts: List? = null, - @Json(name = "tezosPubKey") val tezosPubKey: String? = null, - @Json(name = "cAddressBech") val cAddressBech: String? = null, - @Json(name = "pAddressBech") val pAddressBech: String? = null, - ) - } - data class YieldBalanceRequestArgs( @Json(name = "validatorAddresses") val validatorAddresses: List, ) diff --git a/core/datasource/src/main/java/com/tangem/datasource/api/stakekit/models/response/EnabledYieldsResponse.kt b/core/datasource/src/main/java/com/tangem/datasource/api/stakekit/models/response/EnabledYieldsResponse.kt index c4a958c435..15605bc27c 100644 --- a/core/datasource/src/main/java/com/tangem/datasource/api/stakekit/models/response/EnabledYieldsResponse.kt +++ b/core/datasource/src/main/java/com/tangem/datasource/api/stakekit/models/response/EnabledYieldsResponse.kt @@ -2,12 +2,12 @@ package com.tangem.datasource.api.stakekit.models.response import com.squareup.moshi.Json import com.squareup.moshi.JsonClass -import com.tangem.datasource.api.stakekit.models.response.model.Yield +import com.tangem.datasource.api.stakekit.models.response.model.YieldDTO @JsonClass(generateAdapter = true) data class EnabledYieldsResponse( @Json(name = "data") - val data: List, + val data: List, @Json(name = "hasNextPage") val hasNextPage: Boolean, @Json(name = "limit") diff --git a/core/datasource/src/main/java/com/tangem/datasource/api/stakekit/models/response/EnterActionResponse.kt b/core/datasource/src/main/java/com/tangem/datasource/api/stakekit/models/response/EnterActionResponse.kt new file mode 100644 index 0000000000..9413c43398 --- /dev/null +++ b/core/datasource/src/main/java/com/tangem/datasource/api/stakekit/models/response/EnterActionResponse.kt @@ -0,0 +1,33 @@ +package com.tangem.datasource.api.stakekit.models.response + +import com.squareup.moshi.Json +import com.squareup.moshi.JsonClass +import com.tangem.datasource.api.stakekit.models.response.model.action.StakingActionStatusDTO +import com.tangem.datasource.api.stakekit.models.response.model.action.StakingActionTypeDTO +import com.tangem.datasource.api.stakekit.models.response.model.transaction.StakingTransactionDTO +import org.joda.time.DateTime +import java.math.BigDecimal + +@JsonClass(generateAdapter = true) +data class EnterActionResponse( + @Json(name = "id") + val id: String, + @Json(name = "integrationId") + val integrationId: String, + @Json(name = "status") + val status: StakingActionStatusDTO, + @Json(name = "type") + val type: StakingActionTypeDTO, + @Json(name = "currentStepIndex") + val currentStepIndex: Int, + @Json(name = "amount") + val amount: BigDecimal, + @Json(name = "validatorAddress") + val validatorAddress: String?, + @Json(name = "validatorAddresses") + val validatorAddresses: List?, + @Json(name = "transactions") + val transactions: List?, + @Json(name = "createdAt") + val createdAt: DateTime, +) \ No newline at end of file diff --git a/core/datasource/src/main/java/com/tangem/datasource/api/stakekit/models/response/model/AddressArgument.kt b/core/datasource/src/main/java/com/tangem/datasource/api/stakekit/models/response/model/AddressArgumentDTO.kt similarity index 77% rename from core/datasource/src/main/java/com/tangem/datasource/api/stakekit/models/response/model/AddressArgument.kt rename to core/datasource/src/main/java/com/tangem/datasource/api/stakekit/models/response/model/AddressArgumentDTO.kt index 301b7b5805..7a4f33b288 100644 --- a/core/datasource/src/main/java/com/tangem/datasource/api/stakekit/models/response/model/AddressArgument.kt +++ b/core/datasource/src/main/java/com/tangem/datasource/api/stakekit/models/response/model/AddressArgumentDTO.kt @@ -4,13 +4,13 @@ import com.squareup.moshi.Json import com.squareup.moshi.JsonClass @JsonClass(generateAdapter = true) -data class AddressArgument( +data class AddressArgumentDTO( @Json(name = "required") val required: Boolean, @Json(name = "network") val network: String? = null, @Json(name = "minimum") - val minimum: Int? = null, + val minimum: Double? = null, @Json(name = "maximum") - val maximum: Int? = null, + val maximum: Double? = null, ) \ No newline at end of file diff --git a/core/datasource/src/main/java/com/tangem/datasource/api/stakekit/models/response/model/NetworkTypeDTO.kt b/core/datasource/src/main/java/com/tangem/datasource/api/stakekit/models/response/model/NetworkTypeDTO.kt new file mode 100644 index 0000000000..c7fedd5ec8 --- /dev/null +++ b/core/datasource/src/main/java/com/tangem/datasource/api/stakekit/models/response/model/NetworkTypeDTO.kt @@ -0,0 +1,205 @@ +package com.tangem.datasource.api.stakekit.models.response.model + +import com.squareup.moshi.Json + +enum class NetworkTypeDTO { + @Json(name = "avalanche-c") + AVALANCHE_C, + + @Json(name = "avalanche-atomic") + AVALANCHE_ATOMIC, + + @Json(name = "avalanche-p") + AVALANCHE_P, + + @Json(name = "arbitrum") + ARBITRUM, + + @Json(name = "binance") + BINANCE, + + @Json(name = "celo") + CELO, + + @Json(name = "ethereum") + ETHEREUM, + + @Json(name = "ethereum-goerli") + ETHEREUM_GOERLI, + + @Json(name = "ethereum-holesky") + ETHEREUM_HOLESKY, + + @Json(name = "fantom") + FANTOM, + + @Json(name = "harmony") + HARMONY, + + @Json(name = "optimism") + OPTIMISM, + + @Json(name = "polygon") + POLYGON, + + @Json(name = "gnosis") + GNOSIS, + + @Json(name = "moonriver") + MOONRIVER, + + @Json(name = "okc") + OKC, + + @Json(name = "zksync") + ZKSYNC, + + @Json(name = "viction") + VICTION, + + @Json(name = "agoric") + AGORIC, + + @Json(name = "akash") + AKASH, + + @Json(name = "axelar") + AXELAR, + + @Json(name = "band-protocol") + BAND_PROTOCOL, + + @Json(name = "bitsong") + BITSONG, + + @Json(name = "canto") + CANTO, + + @Json(name = "chihuahua") + CHIHUAHUA, + + @Json(name = "comdex") + COMDEX, + + @Json(name = "coreum") + COREUM, + + @Json(name = "cosmos") + COSMOS, + + @Json(name = "crescent") + CRESCENT, + + @Json(name = "cronos") + CRONOS, + + @Json(name = "cudos") + CUDOS, + + @Json(name = "desmos") + DESMOS, + + @Json(name = "dydx") + DYDX, + + @Json(name = "evmos") + EVMOS, + + @Json(name = "fetch-ai") + FETCH_AI, + + @Json(name = "gravity-bridge") + GRAVITY_BRIDGE, + + @Json(name = "injective") + INJECTIVE, + + @Json(name = "irisnet") + IRISNET, + + @Json(name = "juno") + JUNO, + + @Json(name = "kava") + KAVA, + + @Json(name = "ki-network") + KI_NETWORK, + + @Json(name = "mars-protocol") + MARS_PROTOCOL, + + @Json(name = "nym") + NYM, + + @Json(name = "okex-chain") + OKEX_CHAIN, + + @Json(name = "onomy") + ONOMY, + + @Json(name = "osmosis") + OSMOSIS, + + @Json(name = "persistence") + PERSISTENCE, + + @Json(name = "quicksilver") + QUICKSILVER, + + @Json(name = "regen") + REGEN, + + @Json(name = "secret") + SECRET, + + @Json(name = "sentinel") + SENTINEL, + + @Json(name = "sommelier") + SOMMELIER, + + @Json(name = "stafi") + STAFI, + + @Json(name = "stargaze") + STARGAZE, + + @Json(name = "stride") + STRIDE, + + @Json(name = "teritori") + TERITORI, + + @Json(name = "tgrade") + TGRADE, + + @Json(name = "umee") + UMEE, + + @Json(name = "polkadot") + POLKADOT, + + @Json(name = "kusama") + KUSAMA, + + @Json(name = "westend") + WESTEND, + + @Json(name = "binancebeacon") + BINANCEBEACON, + + @Json(name = "near") + NEAR, + + @Json(name = "solana") + SOLANA, + + @Json(name = "tezos") + TEZOS, + + @Json(name = "tron") + TRON, + + UNKNOWN, +} \ No newline at end of file diff --git a/core/datasource/src/main/java/com/tangem/datasource/api/stakekit/models/response/model/Token.kt b/core/datasource/src/main/java/com/tangem/datasource/api/stakekit/models/response/model/Token.kt deleted file mode 100644 index 88d5d12b59..0000000000 --- a/core/datasource/src/main/java/com/tangem/datasource/api/stakekit/models/response/model/Token.kt +++ /dev/null @@ -1,218 +0,0 @@ -package com.tangem.datasource.api.stakekit.models.response.model - -import com.squareup.moshi.Json -import com.squareup.moshi.JsonClass - -@JsonClass(generateAdapter = true) -data class Token( - @Json(name = "name") val name: String, - @Json(name = "network") val network: NetworkType, - @Json(name = "symbol") val symbol: String, - @Json(name = "decimals") val decimals: Int, - @Json(name = "address") val address: String?, - @Json(name = "coinGeckoId") val coinGeckoId: String?, - @Json(name = "logoURI") val logoURI: String?, - @Json(name = "isPoints") val isPoints: Boolean?, -) { - enum class NetworkType { - @Json(name = "avalanche-c") - AVALANCHE_C, - - @Json(name = "avalanche-atomic") - AVALANCHE_ATOMIC, - - @Json(name = "avalanche-p") - AVALANCHE_P, - - @Json(name = "arbitrum") - ARBITRUM, - - @Json(name = "binance") - BINANCE, - - @Json(name = "celo") - CELO, - - @Json(name = "ethereum") - ETHEREUM, - - @Json(name = "ethereum-goerli") - ETHEREUM_GOERLI, - - @Json(name = "ethereum-holesky") - ETHEREUM_HOLESKY, - - @Json(name = "fantom") - FANTOM, - - @Json(name = "harmony") - HARMONY, - - @Json(name = "optimism") - OPTIMISM, - - @Json(name = "polygon") - POLYGON, - - @Json(name = "gnosis") - GNOSIS, - - @Json(name = "moonriver") - MOONRIVER, - - @Json(name = "okc") - OKC, - - @Json(name = "zksync") - ZKSYNC, - - @Json(name = "viction") - VICTION, - - @Json(name = "agoric") - AGORIC, - - @Json(name = "akash") - AKASH, - - @Json(name = "axelar") - AXELAR, - - @Json(name = "band-protocol") - BAND_PROTOCOL, - - @Json(name = "bitsong") - BITSONG, - - @Json(name = "canto") - CANTO, - - @Json(name = "chihuahua") - CHIHUAHUA, - - @Json(name = "comdex") - COMDEX, - - @Json(name = "coreum") - COREUM, - - @Json(name = "cosmos") - COSMOS, - - @Json(name = "crescent") - CRESCENT, - - @Json(name = "cronos") - CRONOS, - - @Json(name = "cudos") - CUDOS, - - @Json(name = "desmos") - DESMOS, - - @Json(name = "dydx") - DYDX, - - @Json(name = "evmos") - EVMOS, - - @Json(name = "fetch-ai") - FETCH_AI, - - @Json(name = "gravity-bridge") - GRAVITY_BRIDGE, - - @Json(name = "injective") - INJECTIVE, - - @Json(name = "irisnet") - IRISNET, - - @Json(name = "juno") - JUNO, - - @Json(name = "kava") - KAVA, - - @Json(name = "ki-network") - KI_NETWORK, - - @Json(name = "mars-protocol") - MARS_PROTOCOL, - - @Json(name = "nym") - NYM, - - @Json(name = "okex-chain") - OKEX_CHAIN, - - @Json(name = "onomy") - ONOMY, - - @Json(name = "osmosis") - OSMOSIS, - - @Json(name = "persistence") - PERSISTENCE, - - @Json(name = "quicksilver") - QUICKSILVER, - - @Json(name = "regen") - REGEN, - - @Json(name = "secret") - SECRET, - - @Json(name = "sentinel") - SENTINEL, - - @Json(name = "sommelier") - SOMMELIER, - - @Json(name = "stafi") - STAFI, - - @Json(name = "stargaze") - STARGAZE, - - @Json(name = "stride") - STRIDE, - - @Json(name = "teritori") - TERITORI, - - @Json(name = "tgrade") - TGRADE, - - @Json(name = "umee") - UMEE, - - @Json(name = "polkadot") - POLKADOT, - - @Json(name = "kusama") - KUSAMA, - - @Json(name = "westend") - WESTEND, - - @Json(name = "binancebeacon") - BINANCEBEACON, - - @Json(name = "near") - NEAR, - - @Json(name = "solana") - SOLANA, - - @Json(name = "tezos") - TEZOS, - - @Json(name = "tron") - TRON, - - UNKNOWN, - } -} \ No newline at end of file diff --git a/core/datasource/src/main/java/com/tangem/datasource/api/stakekit/models/response/model/TokenDTO.kt b/core/datasource/src/main/java/com/tangem/datasource/api/stakekit/models/response/model/TokenDTO.kt new file mode 100644 index 0000000000..62eb0a4c95 --- /dev/null +++ b/core/datasource/src/main/java/com/tangem/datasource/api/stakekit/models/response/model/TokenDTO.kt @@ -0,0 +1,24 @@ +package com.tangem.datasource.api.stakekit.models.response.model + +import com.squareup.moshi.Json +import com.squareup.moshi.JsonClass + +@JsonClass(generateAdapter = true) +data class TokenDTO( + @Json(name = "name") + val name: String, + @Json(name = "network") + val network: NetworkTypeDTO, + @Json(name = "symbol") + val symbol: String, + @Json(name = "decimals") + val decimals: Int, + @Json(name = "address") + val address: String?, + @Json(name = "coinGeckoId") + val coinGeckoId: String?, + @Json(name = "logoURI") + val logoURI: String?, + @Json(name = "isPoints") + val isPoints: Boolean?, +) \ No newline at end of file diff --git a/core/datasource/src/main/java/com/tangem/datasource/api/stakekit/models/response/model/TokenWithYield.kt b/core/datasource/src/main/java/com/tangem/datasource/api/stakekit/models/response/model/TokenWithYieldDTO.kt similarity index 75% rename from core/datasource/src/main/java/com/tangem/datasource/api/stakekit/models/response/model/TokenWithYield.kt rename to core/datasource/src/main/java/com/tangem/datasource/api/stakekit/models/response/model/TokenWithYieldDTO.kt index 2bc30185af..15182ef389 100644 --- a/core/datasource/src/main/java/com/tangem/datasource/api/stakekit/models/response/model/TokenWithYield.kt +++ b/core/datasource/src/main/java/com/tangem/datasource/api/stakekit/models/response/model/TokenWithYieldDTO.kt @@ -4,7 +4,7 @@ import com.squareup.moshi.Json import com.squareup.moshi.JsonClass @JsonClass(generateAdapter = true) -data class TokenWithYield( - @Json(name = "token") val token: Token, +data class TokenWithYieldDTO( + @Json(name = "token") val token: TokenDTO, @Json(name = "availableYields") val availableYieldIds: List, ) \ No newline at end of file diff --git a/core/datasource/src/main/java/com/tangem/datasource/api/stakekit/models/response/model/YieldBalanceWrapper.kt b/core/datasource/src/main/java/com/tangem/datasource/api/stakekit/models/response/model/YieldBalanceWrapper.kt deleted file mode 100644 index 01f0e26c16..0000000000 --- a/core/datasource/src/main/java/com/tangem/datasource/api/stakekit/models/response/model/YieldBalanceWrapper.kt +++ /dev/null @@ -1,138 +0,0 @@ -package com.tangem.datasource.api.stakekit.models.response.model - -import com.squareup.moshi.Json -import com.squareup.moshi.JsonClass -import org.joda.time.DateTime -import java.math.BigDecimal - -@JsonClass(generateAdapter = true) -data class YieldBalanceWrapper( - @Json(name = "balances") - val balances: List, - @Json(name = "integrationId") - val integrationId: String?, -) { - - @JsonClass(generateAdapter = true) - data class Balance( - @Json(name = "groupId") - val groupId: String, - @Json(name = "type") - val type: BalanceType, - @Json(name = "amount") - val amount: BigDecimal, - @Json(name = "date") - val date: DateTime?, - @Json(name = "pricePerShare") - val pricePerShare: BigDecimal, - @Json(name = "pendingActions") - val pendingActions: List, - @Json(name = "token") - val token: Token, - @Json(name = "validatorAddress") - val validatorAddress: String?, - @Json(name = "validatorAddresses") - val validatorAddresses: List?, - @Json(name = "providerId") - val providerId: String?, - ) { - - enum class BalanceType { - @Json(name = "available") - AVAILABLE, - - @Json(name = "staked") - STAKED, - - @Json(name = "unstaking") - UNSTAKING, - - @Json(name = "unstaked") - UNSTAKED, - - @Json(name = "preparing") - PREPARING, - - @Json(name = "rewards") - REWARDS, - - @Json(name = "locked") - LOCKED, - - @Json(name = "unlocking") - UNLOCKING, - } - - @JsonClass(generateAdapter = true) - data class PendingAction( - @Json(name = "type") - val type: StakingActionType, - @Json(name = "passthrough") - val passthrough: String, - @Json(name = "args") - val args: PendingActionArgs?, - ) { - @JsonClass(generateAdapter = true) - data class PendingActionArgs( - @Json(name = "amount") - val amount: Amount?, - @Json(name = "duration") - val duration: Duration?, - @Json(name = "validatorAddress") - val validatorAddress: Required?, - @Json(name = "validatorAddresses") - val validatorAddresses: Required?, - @Json(name = "nfts") - val nfts: List?, - @Json(name = "tronResource") - val tronResource: TronResource?, - @Json(name = "signatureVerification") - val signatureVerification: Required?, - ) { - @JsonClass(generateAdapter = true) - data class Amount( - @Json(name = "required") - val required: Boolean, - @Json(name = "minimum") - val minimum: BigDecimal?, - @Json(name = "maximum") - val maximum: BigDecimal?, - ) - - @JsonClass(generateAdapter = true) - data class Duration( - @Json(name = "required") - val required: Boolean, - @Json(name = "minimum") - val minimum: Int?, - @Json(name = "maximum") - val maximum: Int?, - ) - - @JsonClass(generateAdapter = true) - data class Nft( - @Json(name = "baycId") - val baycId: Required?, - @Json(name = "maycId") - val maycId: Required?, - @Json(name = "bakcId") - val bakcId: Required?, - ) - - @JsonClass(generateAdapter = true) - data class TronResource( - @Json(name = "required") - val required: Boolean, - @Json(name = "options") - val options: List, - ) - } - } - - @JsonClass(generateAdapter = true) - data class Required( - @Json(name = "required") - val required: Boolean, - ) - } -} \ No newline at end of file diff --git a/core/datasource/src/main/java/com/tangem/datasource/api/stakekit/models/response/model/YieldBalanceWrapperDTO.kt b/core/datasource/src/main/java/com/tangem/datasource/api/stakekit/models/response/model/YieldBalanceWrapperDTO.kt new file mode 100644 index 0000000000..5be46fc967 --- /dev/null +++ b/core/datasource/src/main/java/com/tangem/datasource/api/stakekit/models/response/model/YieldBalanceWrapperDTO.kt @@ -0,0 +1,140 @@ +package com.tangem.datasource.api.stakekit.models.response.model + +import com.squareup.moshi.Json +import com.squareup.moshi.JsonClass +import com.tangem.datasource.api.stakekit.models.response.model.action.StakingActionTypeDTO +import org.joda.time.DateTime +import java.math.BigDecimal + +@JsonClass(generateAdapter = true) +data class YieldBalanceWrapperDTO( + @Json(name = "balances") + val balances: List, + @Json(name = "integrationId") + val integrationId: String?, +) + +@JsonClass(generateAdapter = true) +data class BalanceDTO( + @Json(name = "groupId") + val groupId: String, + @Json(name = "type") + val type: BalanceType, + @Json(name = "amount") + val amount: BigDecimal, + @Json(name = "date") + val date: DateTime?, + @Json(name = "pricePerShare") + val pricePerShare: BigDecimal, + @Json(name = "pendingActions") + val pendingActions: List, + @Json(name = "token") + val tokenDTO: TokenDTO, + @Json(name = "validatorAddress") + val validatorAddress: String?, + @Json(name = "validatorAddresses") + val validatorAddresses: List?, + @Json(name = "providerId") + val providerId: String?, +) { + + enum class BalanceType { + @Json(name = "available") + AVAILABLE, + + @Json(name = "staked") + STAKED, + + @Json(name = "unstaking") + UNSTAKING, + + @Json(name = "unstaked") + UNSTAKED, + + @Json(name = "preparing") + PREPARING, + + @Json(name = "rewards") + REWARDS, + + @Json(name = "locked") + LOCKED, + + @Json(name = "unlocking") + UNLOCKING, + + UNKNOWN, + } + + @JsonClass(generateAdapter = true) + data class PendingAction( + @Json(name = "type") + val type: StakingActionTypeDTO, + @Json(name = "passthrough") + val passthrough: String, + @Json(name = "args") + val args: PendingActionArgs?, + ) { + @JsonClass(generateAdapter = true) + data class PendingActionArgs( + @Json(name = "amount") + val amount: Amount?, + @Json(name = "duration") + val duration: Duration?, + @Json(name = "validatorAddress") + val validatorAddress: Required?, + @Json(name = "validatorAddresses") + val validatorAddresses: Required?, + @Json(name = "nfts") + val nfts: List?, + @Json(name = "tronResource") + val tronResource: TronResource?, + @Json(name = "signatureVerification") + val signatureVerification: Required?, + ) { + @JsonClass(generateAdapter = true) + data class Amount( + @Json(name = "required") + val required: Boolean, + @Json(name = "minimum") + val minimum: BigDecimal?, + @Json(name = "maximum") + val maximum: BigDecimal?, + ) + + @JsonClass(generateAdapter = true) + data class Duration( + @Json(name = "required") + val required: Boolean, + @Json(name = "minimum") + val minimum: Int?, + @Json(name = "maximum") + val maximum: Int?, + ) + + @JsonClass(generateAdapter = true) + data class Nft( + @Json(name = "baycId") + val baycId: Required?, + @Json(name = "maycId") + val maycId: Required?, + @Json(name = "bakcId") + val bakcId: Required?, + ) + + @JsonClass(generateAdapter = true) + data class TronResource( + @Json(name = "required") + val required: Boolean, + @Json(name = "options") + val options: List, + ) + } + } + + @JsonClass(generateAdapter = true) + data class Required( + @Json(name = "required") + val required: Boolean, + ) +} \ No newline at end of file diff --git a/core/datasource/src/main/java/com/tangem/datasource/api/stakekit/models/response/model/YieldBalances.kt b/core/datasource/src/main/java/com/tangem/datasource/api/stakekit/models/response/model/YieldBalances.kt deleted file mode 100644 index 98637444a4..0000000000 --- a/core/datasource/src/main/java/com/tangem/datasource/api/stakekit/models/response/model/YieldBalances.kt +++ /dev/null @@ -1,138 +0,0 @@ -package com.tangem.datasource.api.stakekit.models.response.model - -import com.squareup.moshi.Json -import com.squareup.moshi.JsonClass -import org.joda.time.DateTime -import java.math.BigDecimal - -@JsonClass(generateAdapter = true) -data class YieldBalances( - @Json(name = "balances") - val balances: List, - @Json(name = "integrationId") - val integrationId: String, -) { - - @JsonClass(generateAdapter = true) - data class Balance( - @Json(name = "groupId") - val groupId: String, - @Json(name = "type") - val type: BalanceType, - @Json(name = "amount") - val amount: BigDecimal, - @Json(name = "date") - val date: DateTime?, - @Json(name = "pricePerShare") - val pricePerShare: BigDecimal, - @Json(name = "pendingActions") - val pendingActions: List, - @Json(name = "token") - val token: Token, - @Json(name = "validatorAddress") - val validatorAddress: String?, - @Json(name = "validatorAddresses") - val validatorAddresses: List?, - @Json(name = "providerId") - val providerId: String?, - ) { - - enum class BalanceType { - @Json(name = "available") - AVAILABLE, - - @Json(name = "staked") - STAKED, - - @Json(name = "unstaking") - UNSTAKING, - - @Json(name = "unstaked") - UNSTAKED, - - @Json(name = "preparing") - PREPARING, - - @Json(name = "rewards") - REWARDS, - - @Json(name = "locked") - LOCKED, - - @Json(name = "unlocking") - UNLOCKING, - } - - @JsonClass(generateAdapter = true) - data class PendingAction( - @Json(name = "type") - val type: StakingActionType, - @Json(name = "passthrough") - val passthrough: String, - @Json(name = "args") - val args: PendingActionArgs?, - ) { - @JsonClass(generateAdapter = true) - data class PendingActionArgs( - @Json(name = "amount") - val amount: Amount?, - @Json(name = "duration") - val duration: Duration?, - @Json(name = "validatorAddress") - val validatorAddress: Required?, - @Json(name = "validatorAddresses") - val validatorAddresses: Required?, - @Json(name = "nfts") - val nfts: List?, - @Json(name = "tronResource") - val tronResource: TronResource?, - @Json(name = "signatureVerification") - val signatureVerification: Required?, - ) { - @JsonClass(generateAdapter = true) - data class Amount( - @Json(name = "required") - val required: Boolean, - @Json(name = "minimum") - val minimum: BigDecimal?, - @Json(name = "maximum") - val maximum: BigDecimal?, - ) - - @JsonClass(generateAdapter = true) - data class Duration( - @Json(name = "required") - val required: Boolean, - @Json(name = "minimum") - val minimum: Int?, - @Json(name = "maximum") - val maximum: Int?, - ) - - @JsonClass(generateAdapter = true) - data class Nft( - @Json(name = "baycId") - val baycId: Required?, - @Json(name = "maycId") - val maycId: Required?, - @Json(name = "bakcId") - val bakcId: Required?, - ) - - @JsonClass(generateAdapter = true) - data class TronResource( - @Json(name = "required") - val required: Boolean, - @Json(name = "options") - val options: List, - ) - } - } - - @JsonClass(generateAdapter = true) - data class Required( - @Json(name = "required") - val required: Boolean, - ) - } -} \ No newline at end of file diff --git a/core/datasource/src/main/java/com/tangem/datasource/api/stakekit/models/response/model/Yield.kt b/core/datasource/src/main/java/com/tangem/datasource/api/stakekit/models/response/model/YieldDTO.kt similarity index 78% rename from core/datasource/src/main/java/com/tangem/datasource/api/stakekit/models/response/model/Yield.kt rename to core/datasource/src/main/java/com/tangem/datasource/api/stakekit/models/response/model/YieldDTO.kt index c122022402..bf8956f11f 100644 --- a/core/datasource/src/main/java/com/tangem/datasource/api/stakekit/models/response/model/Yield.kt +++ b/core/datasource/src/main/java/com/tangem/datasource/api/stakekit/models/response/model/YieldDTO.kt @@ -5,33 +5,33 @@ import com.squareup.moshi.JsonClass import java.math.BigDecimal @JsonClass(generateAdapter = true) -data class Yield( +data class YieldDTO( @Json(name = "id") val id: String, @Json(name = "token") - val token: Token, + val token: TokenDTO, @Json(name = "tokens") - val tokens: List, + val tokens: List, @Json(name = "args") - val args: Args, + val args: ArgsDTO, @Json(name = "status") - val status: Status, + val status: StatusDTO, @Json(name = "apy") val apy: BigDecimal, @Json(name = "rewardRate") val rewardRate: Double, @Json(name = "rewardType") - val rewardType: RewardType, + val rewardType: RewardTypeDTO, @Json(name = "metadata") - val metadata: Metadata, + val metadata: MetadataDTO, @Json(name = "validators") - val validators: List, + val validators: List, @Json(name = "isAvailable") val isAvailable: Boolean, ) { @JsonClass(generateAdapter = true) - data class Status( + data class StatusDTO( @Json(name = "enter") val enter: Boolean, @Json(name = "exit") @@ -39,7 +39,7 @@ data class Yield( ) @JsonClass(generateAdapter = true) - data class Args( + data class ArgsDTO( @Json(name = "enter") val enter: Enter, @Json(name = "exit") @@ -50,20 +50,20 @@ data class Yield( @Json(name = "addresses") val addresses: Addresses, @Json(name = "args") - val args: Map, + val args: Map, ) { @JsonClass(generateAdapter = true) data class Addresses( @Json(name = "address") - val address: AddressArgument, + val address: AddressArgumentDTO, @Json(name = "additionalAddresses") - val additionalAddresses: Map? = null, + val additionalAddresses: Map? = null, ) } } @JsonClass(generateAdapter = true) - data class Validator( + data class ValidatorDTO( @Json(name = "address") val address: String, @Json(name = "status") @@ -75,7 +75,7 @@ data class Yield( @Json(name = "website") val website: String?, @Json(name = "apr") - val apr: Double?, + val apr: BigDecimal?, @Json(name = "commission") val commission: Double?, @Json(name = "stakedBalance") @@ -87,7 +87,7 @@ data class Yield( ) @JsonClass(generateAdapter = true) - data class Metadata( + data class MetadataDTO( @Json(name = "name") val name: String, @Json(name = "logoURI") @@ -97,19 +97,19 @@ data class Yield( @Json(name = "documentation") val documentation: String?, @Json(name = "gasFeeToken") - val gasFeeToken: Token, + val gasFeeTokenDTO: TokenDTO, @Json(name = "token") - val token: Token, + val tokenDTO: TokenDTO, @Json(name = "tokens") - val tokens: List, + val tokensDTO: List, @Json(name = "type") val type: String, @Json(name = "rewardSchedule") val rewardSchedule: String, @Json(name = "cooldownPeriod") - val cooldownPeriod: Period, + val cooldownPeriod: PeriodDTO, @Json(name = "warmupPeriod") - val warmupPeriod: Period, + val warmupPeriod: PeriodDTO, @Json(name = "rewardClaiming") val rewardClaiming: String, @Json(name = "defaultValidator") @@ -119,28 +119,30 @@ data class Yield( @Json(name = "supportsMultipleValidators") val supportsMultipleValidators: Boolean, @Json(name = "revshare") - val revshare: Enabled, + val revshare: EnabledDTO, @Json(name = "fee") - val fee: Enabled, + val fee: EnabledDTO, ) { @JsonClass(generateAdapter = true) - data class Period( + data class PeriodDTO( @Json(name = "days") val days: Int, ) @JsonClass(generateAdapter = true) - data class Enabled( + data class EnabledDTO( @Json(name = "enabled") val enabled: Boolean, ) } - enum class RewardType { + enum class RewardTypeDTO { @Json(name = "apy") - APY, // auto + APY, // compound rate @Json(name = "apr") - APR, // manual + APR, // simple rate, + + UNKNOWN, } } \ No newline at end of file diff --git a/core/datasource/src/main/java/com/tangem/datasource/api/stakekit/models/response/model/action/StakingActionStatusDTO.kt b/core/datasource/src/main/java/com/tangem/datasource/api/stakekit/models/response/model/action/StakingActionStatusDTO.kt new file mode 100644 index 0000000000..040cab01ea --- /dev/null +++ b/core/datasource/src/main/java/com/tangem/datasource/api/stakekit/models/response/model/action/StakingActionStatusDTO.kt @@ -0,0 +1,25 @@ +package com.tangem.datasource.api.stakekit.models.response.model.action + +import com.squareup.moshi.Json + +enum class StakingActionStatusDTO { + @Json(name = "CANCELED") + CANCELED, + + @Json(name = "CREATED") + CREATED, + + @Json(name = "WAITING_FOR_NEXT") + WAITING_FOR_NEXT, + + @Json(name = "PROCESSING") + PROCESSING, + + @Json(name = "FAILED") + FAILED, + + @Json(name = "SUCCESS") + SUCCESS, + + UNKNOWN, +} \ No newline at end of file diff --git a/core/datasource/src/main/java/com/tangem/datasource/api/stakekit/models/response/model/StakingActionType.kt b/core/datasource/src/main/java/com/tangem/datasource/api/stakekit/models/response/model/action/StakingActionTypeDTO.kt similarity index 93% rename from core/datasource/src/main/java/com/tangem/datasource/api/stakekit/models/response/model/StakingActionType.kt rename to core/datasource/src/main/java/com/tangem/datasource/api/stakekit/models/response/model/action/StakingActionTypeDTO.kt index 5e60da84d9..3ba035dc64 100644 --- a/core/datasource/src/main/java/com/tangem/datasource/api/stakekit/models/response/model/StakingActionType.kt +++ b/core/datasource/src/main/java/com/tangem/datasource/api/stakekit/models/response/model/action/StakingActionTypeDTO.kt @@ -1,8 +1,8 @@ -package com.tangem.datasource.api.stakekit.models.response.model +package com.tangem.datasource.api.stakekit.models.response.model.action import com.squareup.moshi.Json -enum class StakingActionType { +enum class StakingActionTypeDTO { @Json(name = "STAKE") STAKE, @@ -47,4 +47,6 @@ enum class StakingActionType { @Json(name = "MIGRATE") MIGRATE, + + UNKNOWN, } \ No newline at end of file diff --git a/core/datasource/src/main/java/com/tangem/datasource/api/stakekit/models/response/model/error/StakeKitErrorResponse.kt b/core/datasource/src/main/java/com/tangem/datasource/api/stakekit/models/response/model/error/StakeKitErrorResponse.kt new file mode 100644 index 0000000000..30396de002 --- /dev/null +++ b/core/datasource/src/main/java/com/tangem/datasource/api/stakekit/models/response/model/error/StakeKitErrorResponse.kt @@ -0,0 +1,160 @@ +package com.tangem.datasource.api.stakekit.models.response.model.error + +import com.squareup.moshi.Json + +class StakeKitErrorResponse( + @Json(name = "details") + val details: StakeKitErrorDetailsDTO? = null, + @Json(name = "message") + val message: StakeKitErrorMessageDTO? = null, + @Json(name = "level") + val level: String? = null, // unused + + // 403 + @Json(name = "type") + val type: AccessDeniedErrorTypeDTO? = null, + @Json(name = "code") + val code: String? = null, + @Json(name = "countryCode") + val countryCode: String, + @Json(name = "regionCode") + val regionCode: String? = null, + @Json(name = "tags") + val tags: List? = null, +) + +data class StakeKitErrorDetailsDTO( + @Json(name = "arguments") + val arguments: String? = null, + @Json(name = "amount") + val amount: String? = null, + @Json(name = "yieldId") + val yieldId: String? = null, +) + +enum class AccessDeniedErrorTypeDTO { + @Json(name = "GEO_LOCATION") + GEO_LOCATION, +} + +enum class StakeKitErrorMessageDTO { + @Json(name = "MissingArgumentsError") + MISSING_ARGUMENTS_ERROR, + + @Json(name = "MinimumAmountNotReached") + MINIMUM_AMOUNT_NOT_REACHED, + + @Json(name = "YieldUnderMaintenanceError") + YIELD_UNDER_MAINTENANCE_ERROR, + + @Json(name = "InsufficientFundsError") + INSUFFICIENT_FUNDS_ERROR, + + @Json(name = "StakedPositionNotFoundError") + STAKED_POSITION_NOT_FOUND_ERROR, + + @Json(name = "InvalidAmountSubmittedError") + INVALID_AMOUNT_SUBMITTED_ERROR, + + @Json(name = "BalanceUnavailableError") + BALANCE_UNAVAILABLE_ERROR, + + @Json(name = "GasPriceUnavailableError") + GAS_PRICE_UNAVAILABLE_ERROR, + + @Json(name = "NotImplementedError") + NOT_IMPLEMENTED_ERROR, + + @Json(name = "TokenNotFoundError") + TOKEN_NOT_FOUND_ERROR, + + @Json(name = "BroadcastTransactionError") + BROADCAST_TRANSACTION_ERROR, + + @Json(name = "MissingGasPriceStrategyError") + MISSING_GAS_PRICE_STRATEGY_ERROR, + + @Json(name = "SubstrateMalformedTransactionHashError") + SUBSTRATE_MALFORMED_TRANSACTION_HASH_ERROR, + + @Json(name = "TronMaximumAmountOfValidatorsExceededError") + TRON_MAXIMUM_AMOUNT_OF_VALIDATORS_EXCEEDED_ERROR, + + @Json(name = "SubstratePoolNotFoundError") + SUBSTRATE_POOL_NOT_FOUND_ERROR, + + @Json(name = "SubstrateBondedAmountTooLowError") + SUBSTRATE_BONDED_AMOUNT_TOO_LOW_ERROR, + + @Json(name = "TronMissingResourceTypeArgumentError") + TRON_MISSING_RESOURCE_TYPE_ARGUMENT_ERROR, + + @Json(name = "AaveV3PoolFrozenError") + AAVE_V3_POOL_FROZEN_ERROR, + + @Json(name = "AaveV3TokenPairNotFoundError") + AAVE_V3_TOKEN_PAIR_NOT_FOUND_ERROR, + + @Json(name = "YearnVaultAtMaxCapacityError") + YEARN_VAULT_AT_MAX_CAPACITY_ERROR, + + @Json(name = "StETHNoWithdrawalRequestsFoundError") + STETH_NO_WITHDRAWAL_REQUESTS_FOUND_ERROR, + + @Json(name = "MorphoLendingPoolPausedError") + MORPHO_LENDING_POOL_PAUSED_ERROR, + + @Json(name = "NonceUnavailableError") + NONCE_UNAVAILABLE_ERROR, + + @Json(name = "CosmosAcccountNotFoundError") + COSMOS_ACCOUNT_NOT_FOUND_ERROR, + + @Json(name = "AvalancheMissingAdditionalAddressesArgumentError") + AVALANCHE_MISSING_ADDITIONAL_ADDRESSES_ARGUMENT_ERROR, + + @Json(name = "AvalancheValidatorInfoNotFoundError") + AVALANCHE_VALIDATOR_INFO_NOT_FOUND_ERROR, + + @Json(name = "SolanaTransactionSignatureVerificationFailureError") + SOLANA_TRANSACTION_SIGNATURE_VERIFICATION_FAILURE_ERROR, + + @Json(name = "SolanaUnableTocreateStakeAccountError") + SOLANA_UNABLE_TO_CREATE_STAKE_ACCOUNT_ERROR, + + @Json(name = "SolanaStakeAmountTooLowError") + SOLANA_STAKE_AMOUNT_TOO_LOW_ERROR, + + @Json(name = "SolanaUnstakeAmountTooLowError") + SOLANA_UNSTAKE_AMOUNT_TOO_LOW_ERROR, + + @Json(name = "SolanaStakeAccountsNotFoundError") + SOLANA_STAKE_ACCOUNTS_NOT_FOUND_ERROR, + + @Json(name = "SolanaEligibleStakeAccountsNotFoundError") + SOLANA_ELIGIBLE_STAKE_ACCOUNTS_NOT_FOUND_ERROR, + + @Json(name = "TezosNoBalanceDelegatedError") + TEZOS_NO_BALANCE_DELEGATED_ERROR, + + @Json(name = "TezosMissingPubkeyArgumentError") + TEZOS_MISSING_PUBKEY_ARGUMENT_ERROR, + + @Json(name = "TezosEstimateRevealGasLimitError") + TEZOS_ESTIMATE_REVEAL_GAS_LIMIT_ERROR, + + @Json(name = "TezosBalanceAlreadyDelegatedError") + TEZOS_BALANCE_ALREADY_DELEGATED_ERROR, + + @Json(name = "BinanceAccountNotFoundError") + BINANCE_ACCOUNT_NOT_FOUND_ERROR, + + @Json(name = "BinanceMissingAccountNumberOrSequenceError") + BINANCE_MISSING_ACCOUNT_NUMBER_OR_SEQUENCE_ERROR, + + @Json(name = "GRTStakingDisabledError") + GRT_STAKING_DISABLED_ERROR, + + @Json(name = "GRTStakingDisabledLedgerLiveError") + GRT_STAKING_DISABLED_LEDGER_LIVE_ERROR, +} \ No newline at end of file diff --git a/core/datasource/src/main/java/com/tangem/datasource/api/stakekit/models/response/model/transaction/StakingGasEstimateDTO.kt b/core/datasource/src/main/java/com/tangem/datasource/api/stakekit/models/response/model/transaction/StakingGasEstimateDTO.kt new file mode 100644 index 0000000000..93ee18f790 --- /dev/null +++ b/core/datasource/src/main/java/com/tangem/datasource/api/stakekit/models/response/model/transaction/StakingGasEstimateDTO.kt @@ -0,0 +1,16 @@ +package com.tangem.datasource.api.stakekit.models.response.model.transaction + +import com.squareup.moshi.Json +import com.squareup.moshi.JsonClass +import com.tangem.datasource.api.stakekit.models.response.model.TokenDTO +import java.math.BigDecimal + +@JsonClass(generateAdapter = true) +data class StakingGasEstimateDTO( + @Json(name = "amount") + val amount: BigDecimal, + @Json(name = "token") + val token: TokenDTO, + @Json(name = "gasLimit") + val gasLimit: String?, +) \ No newline at end of file diff --git a/core/datasource/src/main/java/com/tangem/datasource/api/stakekit/models/response/model/transaction/StakingTransactionDTO.kt b/core/datasource/src/main/java/com/tangem/datasource/api/stakekit/models/response/model/transaction/StakingTransactionDTO.kt new file mode 100644 index 0000000000..0a28baaeee --- /dev/null +++ b/core/datasource/src/main/java/com/tangem/datasource/api/stakekit/models/response/model/transaction/StakingTransactionDTO.kt @@ -0,0 +1,37 @@ +package com.tangem.datasource.api.stakekit.models.response.model.transaction + +import com.squareup.moshi.Json +import com.squareup.moshi.JsonClass +import com.tangem.datasource.api.stakekit.models.response.model.NetworkTypeDTO + +@JsonClass(generateAdapter = true) +data class StakingTransactionDTO( + @Json(name = "id") + val id: String, + @Json(name = "network") + val network: NetworkTypeDTO, + @Json(name = "status") + val status: StakingTransactionStatusDTO, + @Json(name = "type") + val type: StakingTransactionTypeDTO, + @Json(name = "hash") + val hash: String?, + @Json(name = "signedTransaction") + val signedTransaction: String?, + @Json(name = "unsignedTransaction") + val unsignedTransaction: String?, + @Json(name = "stepIndex") + val stepIndex: Int, + @Json(name = "error") + val error: String?, + @Json(name = "gasEstimate") + val gasEstimate: StakingGasEstimateDTO?, + @Json(name = "stakeId") + val stakeId: String?, + @Json(name = "explorerUrl") + val explorerUrl: String?, + @Json(name = "ledgerHwAppId") + val ledgerHwAppId: String?, + @Json(name = "isMessage") + val isMessage: Boolean, +) \ No newline at end of file diff --git a/core/datasource/src/main/java/com/tangem/datasource/api/stakekit/models/response/model/transaction/StakingTransactionStatusDTO.kt b/core/datasource/src/main/java/com/tangem/datasource/api/stakekit/models/response/model/transaction/StakingTransactionStatusDTO.kt new file mode 100644 index 0000000000..f7a4f6d76d --- /dev/null +++ b/core/datasource/src/main/java/com/tangem/datasource/api/stakekit/models/response/model/transaction/StakingTransactionStatusDTO.kt @@ -0,0 +1,37 @@ +package com.tangem.datasource.api.stakekit.models.response.model.transaction + +import com.squareup.moshi.Json + +enum class StakingTransactionStatusDTO { + @Json(name = "NOT_FOUND") + NOT_FOUND, + + @Json(name = "CREATED") + CREATED, + + @Json(name = "BLOCKED") + BLOCKED, + + @Json(name = "WAITING_FOR_SIGNATURE") + WAITING_FOR_SIGNATURE, + + @Json(name = "SIGNED") + SIGNED, + + @Json(name = "BROADCASTED") + BROADCASTED, + + @Json(name = "PENDING") + PENDING, + + @Json(name = "CONFIRMED") + CONFIRMED, + + @Json(name = "FAILED") + FAILED, + + @Json(name = "SKIPPED") + SKIPPED, + + UNKNOWN, +} \ No newline at end of file diff --git a/core/datasource/src/main/java/com/tangem/datasource/api/stakekit/models/response/model/transaction/StakingTransactionTypeDTO.kt b/core/datasource/src/main/java/com/tangem/datasource/api/stakekit/models/response/model/transaction/StakingTransactionTypeDTO.kt new file mode 100644 index 0000000000..e79e28e7bb --- /dev/null +++ b/core/datasource/src/main/java/com/tangem/datasource/api/stakekit/models/response/model/transaction/StakingTransactionTypeDTO.kt @@ -0,0 +1,124 @@ +package com.tangem.datasource.api.stakekit.models.response.model.transaction + +import com.squareup.moshi.Json + +enum class StakingTransactionTypeDTO { + @Json(name = "SWAP") + SWAP, + + @Json(name = "DEPOSIT") + DEPOSIT, + + @Json(name = "APPROVAL") + APPROVAL, + + @Json(name = "STAKE") + STAKE, + + @Json(name = "CLAIM_UNSTAKED") + CLAIM_UNSTAKED, + + @Json(name = "CLAIM_REWARDS") + CLAIM_REWARDS, + + @Json(name = "RESTAKE_REWARDS") + RESTAKE_REWARDS, + + @Json(name = "UNSTAKE") + UNSTAKE, + + @Json(name = "SPLIT") + SPLIT, + + @Json(name = "MERGE") + MERGE, + + @Json(name = "LOCK") + LOCK, + + @Json(name = "UNLOCK") + UNLOCK, + + @Json(name = "SUPPLY") + SUPPLY, + + @Json(name = "BRIDGE") + BRIDGE, + + @Json(name = "VOTE") + VOTE, + + @Json(name = "REVOKE") + REVOKE, + + @Json(name = "RESTAKE") + RESTAKE, + + @Json(name = "REBOND") + REBOND, + + @Json(name = "WITHDRAW") + WITHDRAW, + + @Json(name = "CREATE_ACCOUNT") + CREATE_ACCOUNT, + + @Json(name = "REVEAL") + REVEAL, + + @Json(name = "MIGRATE") + MIGRATE, + + @Json(name = "UTXO_P_TO_C_IMPORT") + UTXO_P_TO_C_IMPORT, + + @Json(name = "UTXO_C_TO_P_IMPORT") + UTXO_C_TO_P_IMPORT, + + @Json(name = "UNFREEZE_LEGACY") + UNFREEZE_LEGACY, + + @Json(name = "UNFREEZE_LEGACY_BANDWIDTH") + UNFREEZE_LEGACY_BANDWIDTH, + + @Json(name = "UNFREEZE_LEGACY_ENERGY") + UNFREEZE_LEGACY_ENERGY, + + @Json(name = "UNFREEZE_BANDWIDTH") + UNFREEZE_BANDWIDTH, + + @Json(name = "UNFREEZE_ENERGY") + UNFREEZE_ENERGY, + + @Json(name = "FREEZE_BANDWIDTH") + FREEZE_BANDWIDTH, + + @Json(name = "FREEZE_ENERGY") + FREEZE_ENERGY, + + @Json(name = "UNDELEGATE_BANDWIDTH") + UNDELEGATE_BANDWIDTH, + + @Json(name = "UNDELEGATE_ENERGY") + UNDELEGATE_ENERGY, + + @Json(name = "P2P_NODE_REQUEST") + P2P_NODE_REQUEST, + + @Json(name = "LUGANODES_PROVISION") + LUGANODES_PROVISION, + + @Json(name = "LUGANODES_EXIT_REQUEST") + LUGANODES_EXIT_REQUEST, + + @Json(name = "INFSTONES_PROVISION") + INFSTONES_PROVISION, + + @Json(name = "INFSTONES_EXIT_REQUEST") + INFSTONES_EXIT_REQUEST, + + @Json(name = "INFSTONES_CLAIM_REQUEST") + INFSTONES_CLAIM_REQUEST, + + UNKNOWN, +} \ No newline at end of file diff --git a/core/datasource/src/main/java/com/tangem/datasource/api/tangemTech/models/QuotesResponse.kt b/core/datasource/src/main/java/com/tangem/datasource/api/tangemTech/models/QuotesResponse.kt index 2155d0bf77..e1e9e07e40 100644 --- a/core/datasource/src/main/java/com/tangem/datasource/api/tangemTech/models/QuotesResponse.kt +++ b/core/datasource/src/main/java/com/tangem/datasource/api/tangemTech/models/QuotesResponse.kt @@ -12,6 +12,10 @@ data class QuotesResponse( @Json(name = "price") val price: BigDecimal?, @Json(name = "priceChange24h") - val priceChange: BigDecimal?, + val priceChange24h: BigDecimal?, + @Json(name = "priceChange1w") + val priceChange1w: BigDecimal?, + @Json(name = "priceChange30d") + val priceChange30d: BigDecimal?, ) } \ No newline at end of file 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 6bda8dd093..36bba25d83 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 @@ -103,6 +103,7 @@ internal class ConfigManagerImpl @Inject constructor() : ConfigManager { polygonScanApiKey = configValues.polygonScanApiKey, bittensorDwellirApiKey = configValues.bittensorDwellirApiKey, bittensorOnfinalityApiKey = configValues.bittensorOnfinalityKey, + koinosProApiKey = configValues.koinosProApiKey, ), amplitudeApiKey = configValues.amplitudeApiKey, sprinklr = configValues.sprinklr, 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 685b4e3ffe..a6929291e1 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 @@ -46,6 +46,7 @@ class ConfigValueModel( val stakeKitApiKey: String?, @Json(name = "bittensorDwellirKey") val bittensorDwellirApiKey: String?, @Json(name = "bittensorOnfinalityKey") val bittensorOnfinalityKey: String?, + @Json(name = "koinosProApiKey") val koinosProApiKey: String?, ) @JsonClass(generateAdapter = true) diff --git a/core/datasource/src/main/java/com/tangem/datasource/di/AssetsStoreModule.kt b/core/datasource/src/main/java/com/tangem/datasource/di/ExpressAssetsStoreModule.kt similarity index 52% rename from core/datasource/src/main/java/com/tangem/datasource/di/AssetsStoreModule.kt rename to core/datasource/src/main/java/com/tangem/datasource/di/ExpressAssetsStoreModule.kt index 43b8e93f5c..cf51b2b006 100644 --- a/core/datasource/src/main/java/com/tangem/datasource/di/AssetsStoreModule.kt +++ b/core/datasource/src/main/java/com/tangem/datasource/di/ExpressAssetsStoreModule.kt @@ -1,8 +1,8 @@ package com.tangem.datasource.di import com.tangem.datasource.local.datastore.RuntimeDataStore -import com.tangem.datasource.local.token.DefaultAssetsStore -import com.tangem.datasource.local.token.AssetsStore +import com.tangem.datasource.local.token.DefaultExpressAssetsStore +import com.tangem.datasource.local.token.ExpressAssetsStore import dagger.Module import dagger.Provides import dagger.hilt.InstallIn @@ -11,11 +11,11 @@ import javax.inject.Singleton @Module @InstallIn(SingletonComponent::class) -internal object AssetsStoreModule { +internal object ExpressAssetsStoreModule { @Provides @Singleton - fun provideAssetsStore(): AssetsStore { - return DefaultAssetsStore(dataStore = RuntimeDataStore()) + fun provideExpressAssetsStore(): ExpressAssetsStore { + return DefaultExpressAssetsStore(dataStore = RuntimeDataStore()) } } \ No newline at end of file diff --git a/core/datasource/src/main/java/com/tangem/datasource/di/MoshiModule.kt b/core/datasource/src/main/java/com/tangem/datasource/di/MoshiModule.kt index ddd3386e58..e04042a8b4 100644 --- a/core/datasource/src/main/java/com/tangem/datasource/di/MoshiModule.kt +++ b/core/datasource/src/main/java/com/tangem/datasource/di/MoshiModule.kt @@ -4,11 +4,10 @@ import com.squareup.moshi.Moshi import com.squareup.moshi.adapters.PolymorphicJsonAdapterFactory import com.squareup.moshi.kotlin.reflect.KotlinJsonAdapterFactory import com.tangem.common.json.MoshiJsonConverter +import com.tangem.datasource.api.common.adapter.* import com.tangem.datasource.api.common.adapter.BigDecimalAdapter import com.tangem.datasource.api.common.adapter.DateTimeAdapter import com.tangem.datasource.api.common.adapter.LocalDateAdapter -import com.tangem.datasource.api.common.adapter.UnknownEnumMoshiAdapter -import com.tangem.datasource.api.stakekit.models.response.model.Token import com.tangem.datasource.config.models.ProviderModel import dagger.Module import dagger.Provides @@ -35,10 +34,7 @@ class MoshiModule { .add(LocalDateAdapter()) .add(DateTimeAdapter()) .add(KotlinJsonAdapterFactory()) - .add( - Token.NetworkType::class.java, - UnknownEnumMoshiAdapter.create(Token.NetworkType::class.java, Token.NetworkType.UNKNOWN), - ) + .addStakeKitEnumFallbackAdapters() .build() } 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 ed7b6b5621..6951732450 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 @@ -5,6 +5,7 @@ import com.squareup.moshi.Moshi import com.tangem.datasource.BuildConfig import com.tangem.datasource.api.common.response.ApiResponseCallAdapterFactory import com.tangem.datasource.api.express.TangemExpressApi +import com.tangem.datasource.api.markets.TangemTechMarketsApi import com.tangem.datasource.api.stakekit.StakeKitApi import com.tangem.datasource.api.tangemTech.TangemTechApi import com.tangem.datasource.api.tangemTech.TangemTechApiV2 @@ -123,7 +124,31 @@ class NetworkModule { context = context, appVersionProvider = appVersionProvider, baseUrl = PROD_V1_TANGEM_TECH_BASE_URL, - timeoutSeconds = TANGEM_TECH_SERVICE_TIMEOUT_SECONDS, + timeouts = Timeouts( + callTimeoutSeconds = TANGEM_TECH_SERVICE_TIMEOUT_SECONDS, + ), + requestHeaders = listOf(AppVersionPlatformHeaders(appVersionProvider)), + ) + } + + @Provides + @DevTangemApi + @Singleton + fun provideTangemTechMarketsApi( + @NetworkMoshi moshi: Moshi, + @ApplicationContext context: Context, + appVersionProvider: AppVersionProvider, + ): TangemTechMarketsApi { + return provideTangemTechApiInternal( + moshi = moshi, + context = context, + appVersionProvider = appVersionProvider, + baseUrl = DEV_V1_TANGEM_TECH_BASE_URL, + timeouts = Timeouts( + callTimeoutSeconds = TANGEM_TECH_MARKETS_SERVICE_TIMEOUT_SECONDS, + connectTimeoutSeconds = TANGEM_TECH_MARKETS_SERVICE_TIMEOUT_SECONDS, + readTimeoutSeconds = TANGEM_TECH_MARKETS_SERVICE_TIMEOUT_SECONDS, + ), requestHeaders = listOf(AppVersionPlatformHeaders(appVersionProvider)), ) } @@ -133,16 +158,25 @@ class NetworkModule { context: Context, appVersionProvider: AppVersionProvider, baseUrl: String, - timeoutSeconds: Long? = null, + timeouts: Timeouts = Timeouts(), requestHeaders: List = listOf(CacheControlHeader, AppVersionPlatformHeaders(appVersionProvider)), ): T { val client = OkHttpClient.Builder() .let { builder -> - if (timeoutSeconds != null) { - builder.callTimeout(timeoutSeconds, TimeUnit.SECONDS) - } else { - builder + var b = builder + if (timeouts.callTimeoutSeconds != null) { + b = b.callTimeout(timeouts.callTimeoutSeconds, TimeUnit.SECONDS) } + if (timeouts.connectTimeoutSeconds != null) { + b = b.connectTimeout(timeouts.connectTimeoutSeconds, TimeUnit.SECONDS) + } + if (timeouts.readTimeoutSeconds != null) { + b = b.readTimeout(timeouts.readTimeoutSeconds, TimeUnit.SECONDS) + } + if (timeouts.writeTimeoutSeconds != null) { + b = b.writeTimeout(timeouts.writeTimeoutSeconds, TimeUnit.SECONDS) + } + b } .addHeaders( *requestHeaders.toTypedArray(), @@ -161,6 +195,13 @@ class NetworkModule { .create(T::class.java) } + private data class Timeouts( + val callTimeoutSeconds: Long? = null, + val connectTimeoutSeconds: Long? = null, + val readTimeoutSeconds: Long? = null, + val writeTimeoutSeconds: Long? = null, + ) + private companion object { const val STAKEKIT_BASE_URL = "https://api.stakek.it/v1/" const val PROD_EXPRESS_BASE_URL = "https://express.tangem.com/v1/" @@ -173,5 +214,6 @@ class NetworkModule { const val PROD_V2_TANGEM_TECH_BASE_URL = "https://api.tangem-tech.com/v2/" const val TANGEM_TECH_SERVICE_TIMEOUT_SECONDS = 5L + const val TANGEM_TECH_MARKETS_SERVICE_TIMEOUT_SECONDS = 60L } } \ No newline at end of file diff --git a/core/datasource/src/main/java/com/tangem/datasource/di/StakingBalanceStoreModule.kt b/core/datasource/src/main/java/com/tangem/datasource/di/StakingBalanceStoreModule.kt new file mode 100644 index 0000000000..21d78318c1 --- /dev/null +++ b/core/datasource/src/main/java/com/tangem/datasource/di/StakingBalanceStoreModule.kt @@ -0,0 +1,21 @@ +package com.tangem.datasource.di + +import com.tangem.datasource.local.datastore.RuntimeDataStore +import com.tangem.datasource.local.token.DefaultStakingBalanceStore +import com.tangem.datasource.local.token.StakingBalanceStore +import dagger.Module +import dagger.Provides +import dagger.hilt.InstallIn +import dagger.hilt.components.SingletonComponent +import javax.inject.Singleton + +@Module +@InstallIn(SingletonComponent::class) +internal object StakingBalanceStoreModule { + + @Provides + @Singleton + fun provideStakingBalanceStore(): StakingBalanceStore { + return DefaultStakingBalanceStore(dataStore = RuntimeDataStore()) + } +} \ No newline at end of file diff --git a/core/datasource/src/main/java/com/tangem/datasource/di/StakingTokensStoreModule.kt b/core/datasource/src/main/java/com/tangem/datasource/di/StakingTokensStoreModule.kt new file mode 100644 index 0000000000..45e280e949 --- /dev/null +++ b/core/datasource/src/main/java/com/tangem/datasource/di/StakingTokensStoreModule.kt @@ -0,0 +1,21 @@ +package com.tangem.datasource.di + +import com.tangem.datasource.local.datastore.RuntimeDataStore +import com.tangem.datasource.local.token.DefaultStakingYieldsStore +import com.tangem.datasource.local.token.StakingYieldsStore +import dagger.Module +import dagger.Provides +import dagger.hilt.InstallIn +import dagger.hilt.components.SingletonComponent +import javax.inject.Singleton + +@Module +@InstallIn(SingletonComponent::class) +internal object StakingTokensStoreModule { + + @Provides + @Singleton + fun provideStakingTokensStore(): StakingYieldsStore { + return DefaultStakingYieldsStore(dataStore = RuntimeDataStore()) + } +} \ No newline at end of file diff --git a/core/datasource/src/main/java/com/tangem/datasource/di/UserTokensStoreModule.kt b/core/datasource/src/main/java/com/tangem/datasource/di/UserTokensStoreModule.kt index 757c01cef5..b2997661fb 100644 --- a/core/datasource/src/main/java/com/tangem/datasource/di/UserTokensStoreModule.kt +++ b/core/datasource/src/main/java/com/tangem/datasource/di/UserTokensStoreModule.kt @@ -1,11 +1,11 @@ package com.tangem.datasource.di -import com.squareup.moshi.Moshi -import com.tangem.datasource.api.tangemTech.models.UserTokensResponse -import com.tangem.datasource.files.FileReader -import com.tangem.datasource.local.datastore.FileDataStore -import com.tangem.datasource.local.token.DefaultUserTokensStore +import com.tangem.datasource.local.preferences.AppPreferencesStore +import com.tangem.datasource.local.token.AppPreferencesUserTokensStore import com.tangem.datasource.local.token.UserTokensStore +import com.tangem.datasource.local.token.UserTokensStoreMigrationRunner +import com.tangem.datasource.local.userwallet.UserWalletsStore +import com.tangem.utils.coroutines.CoroutineDispatcherProvider import dagger.Module import dagger.Provides import dagger.hilt.InstallIn @@ -18,9 +18,17 @@ internal object UserTokensStoreModule { @Provides @Singleton - fun provideUserTokensStore(fileReader: FileReader, @NetworkMoshi moshi: Moshi): UserTokensStore { - return DefaultUserTokensStore( - dataStore = FileDataStore(fileReader, moshi.adapter(UserTokensResponse::class.java)), + fun provideUserTokensStore( + appPreferencesStore: AppPreferencesStore, + userTokensStoreMigrationRunner: UserTokensStoreMigrationRunner, + userWalletsStore: UserWalletsStore, + dispatchers: CoroutineDispatcherProvider, + ): UserTokensStore { + return AppPreferencesUserTokensStore( + appPreferencesStore = appPreferencesStore, + userTokensStoreMigrationRunner = userTokensStoreMigrationRunner, + userWalletsStore = userWalletsStore, + dispatchers = dispatchers, ) } } \ No newline at end of file diff --git a/core/datasource/src/main/java/com/tangem/datasource/local/preferences/PreferencesKeys.kt b/core/datasource/src/main/java/com/tangem/datasource/local/preferences/PreferencesKeys.kt index 52b037fd6d..bb2c5fa1b0 100644 --- a/core/datasource/src/main/java/com/tangem/datasource/local/preferences/PreferencesKeys.kt +++ b/core/datasource/src/main/java/com/tangem/datasource/local/preferences/PreferencesKeys.kt @@ -85,6 +85,8 @@ object PreferencesKeys { val IS_WALLET_NAMES_MIGRATION_DONE_KEY by lazy { booleanPreferencesKey(name = "isWalletNamesMigrationDone") } + val UNSUBMITTED_TRANSACTIONS_KEY by lazy { stringPreferencesKey(name = "unsubmittedTransactions") } + val IS_WALLET_SWAP_PROMO_OKX_SHOW_KEY by lazy { booleanPreferencesKey(name = "isWalletSwapPromoOkxShown") } @@ -93,7 +95,21 @@ object PreferencesKeys { booleanPreferencesKey(name = "isTokenSwapPromoOkxShown") } - fun getStart2CoinTOSAcceptedKey(region: String?) = booleanPreferencesKey(name = "start2Coin_tos_accepted_$region") + // region Permission + fun getShouldShowPermission(permission: String) = booleanPreferencesKey("shouldShowPushPermission_$permission") + + fun getShouldShowInitialPermissionScreen(permission: String) = + booleanPreferencesKey("shouldShowInitialPushPermissionScreen_$permission") + + fun getIsFirstTimeAskingPermission(permission: String) = + booleanPreferencesKey("shouldAskInitialPushPermission_$permission") + + fun getPermissionLaunchCount(permission: String) = intPreferencesKey("pushPermissionLaunchCount_$permission") + + fun getPermissionDaysCount(permission: String) = longPreferencesKey("pushPermissionDaysCount_$permission") + // endregion + + fun getUserTokensKey(userWalletId: String) = stringPreferencesKey(name = "user_tokens_$userWalletId") } /** Preferences keys set that should be migrated from "PreferencesDataSource" to a new DataStore */ diff --git a/core/datasource/src/main/java/com/tangem/datasource/local/preferences/utils/AppPreferencesStoreExt.kt b/core/datasource/src/main/java/com/tangem/datasource/local/preferences/utils/AppPreferencesStoreExt.kt index aa3171803c..26be12c002 100644 --- a/core/datasource/src/main/java/com/tangem/datasource/local/preferences/utils/AppPreferencesStoreExt.kt +++ b/core/datasource/src/main/java/com/tangem/datasource/local/preferences/utils/AppPreferencesStoreExt.kt @@ -6,6 +6,7 @@ import com.squareup.moshi.JsonDataException import com.squareup.moshi.Types import com.tangem.datasource.local.preferences.AppPreferencesStore import kotlinx.coroutines.flow.Flow +import kotlinx.coroutines.flow.distinctUntilChanged import kotlinx.coroutines.flow.firstOrNull import kotlinx.coroutines.flow.map @@ -20,7 +21,7 @@ inline fun AppPreferencesStore.getObject(key: Preferences.Key AppPreferencesStore.getObject(key: Preferences.Key AppPreferencesStore.storeObjectList(key: Preferen /** Get flow of list of data [T] by string [key]. If data is not found, it returns `null` */ inline fun AppPreferencesStore.getObjectList(key: Preferences.Key): Flow?> { val adapter = moshi.adapter>(Types.newParameterizedType(List::class.java, T::class.java)) - return data.map { it[key]?.let(adapter::fromJson) } + return data.map { it[key]?.let(adapter::fromJson) }.distinctUntilChanged() } /** Get list of data [T] by string [key], or empty if data is not found */ diff --git a/core/datasource/src/main/java/com/tangem/datasource/local/token/AppPreferencesUserTokensStore.kt b/core/datasource/src/main/java/com/tangem/datasource/local/token/AppPreferencesUserTokensStore.kt new file mode 100644 index 0000000000..80d70825bf --- /dev/null +++ b/core/datasource/src/main/java/com/tangem/datasource/local/token/AppPreferencesUserTokensStore.kt @@ -0,0 +1,63 @@ +package com.tangem.datasource.local.token + +import com.tangem.datasource.api.tangemTech.models.UserTokensResponse +import com.tangem.datasource.local.preferences.AppPreferencesStore +import com.tangem.datasource.local.preferences.PreferencesKeys +import com.tangem.datasource.local.preferences.utils.getObject +import com.tangem.datasource.local.preferences.utils.getObjectSyncOrNull +import com.tangem.datasource.local.preferences.utils.storeObject +import com.tangem.datasource.local.userwallet.UserWalletsStore +import com.tangem.domain.wallets.models.UserWalletId +import com.tangem.utils.coroutines.CoroutineDispatcherProvider +import kotlinx.coroutines.CoroutineScope +import kotlinx.coroutines.flow.* + +/** + * Implementation of [UserTokensStore] that based on [appPreferencesStore] + * + * @property appPreferencesStore application preference store + * +[REDACTED_AUTHOR] + */ +internal class AppPreferencesUserTokensStore( + private val appPreferencesStore: AppPreferencesStore, + private val userTokensStoreMigrationRunner: UserTokensStoreMigrationRunner, + private val userWalletsStore: UserWalletsStore, + private val dispatchers: CoroutineDispatcherProvider, +) : UserTokensStore { + + init { + runUserTokensMigrations() + } + + override fun get(key: UserWalletId): Flow { + return appPreferencesStore + .getObject(PreferencesKeys.getUserTokensKey(userWalletId = key.stringValue)) + .filterNotNull() + } + + override suspend fun getSyncOrNull(key: UserWalletId): UserTokensResponse? { + return appPreferencesStore.getObjectSyncOrNull( + key = PreferencesKeys.getUserTokensKey(userWalletId = key.stringValue), + ) + } + + override suspend fun store(key: UserWalletId, value: UserTokensResponse) { + appPreferencesStore.storeObject( + key = PreferencesKeys.getUserTokensKey(userWalletId = key.stringValue), + value = value, + ) + } + + // TODO: delete in 5.15 (Mobile Sprint 161) [REDACTED_JIRA] + private fun runUserTokensMigrations() { + userWalletsStore.userWallets + .filter { it.isNotEmpty() } + .take(1) + .onEach { userWallets -> + userTokensStoreMigrationRunner.run(ids = userWallets.map { it.walletId.stringValue }) + } + .flowOn(dispatchers.io) + .launchIn(CoroutineScope(dispatchers.io)) + } +} \ No newline at end of file diff --git a/core/datasource/src/main/java/com/tangem/datasource/local/token/DefaultAssetsStore.kt b/core/datasource/src/main/java/com/tangem/datasource/local/token/DefaultExpressAssetsStore.kt similarity index 89% rename from core/datasource/src/main/java/com/tangem/datasource/local/token/DefaultAssetsStore.kt rename to core/datasource/src/main/java/com/tangem/datasource/local/token/DefaultExpressAssetsStore.kt index 9177ec70b7..c67abc06e5 100644 --- a/core/datasource/src/main/java/com/tangem/datasource/local/token/DefaultAssetsStore.kt +++ b/core/datasource/src/main/java/com/tangem/datasource/local/token/DefaultExpressAssetsStore.kt @@ -4,9 +4,9 @@ import com.tangem.datasource.api.express.models.response.Asset import com.tangem.datasource.local.datastore.core.StringKeyDataStore import com.tangem.domain.wallets.models.UserWalletId -internal class DefaultAssetsStore( +internal class DefaultExpressAssetsStore( private val dataStore: StringKeyDataStore>, -) : AssetsStore { +) : ExpressAssetsStore { override suspend fun getSyncOrNull(userWalletId: UserWalletId): List? { return dataStore.getSyncOrNull(userWalletId.stringValue) diff --git a/core/datasource/src/main/java/com/tangem/datasource/local/token/DefaultStakingBalanceStore.kt b/core/datasource/src/main/java/com/tangem/datasource/local/token/DefaultStakingBalanceStore.kt new file mode 100644 index 0000000000..c88970b238 --- /dev/null +++ b/core/datasource/src/main/java/com/tangem/datasource/local/token/DefaultStakingBalanceStore.kt @@ -0,0 +1,51 @@ +package com.tangem.datasource.local.token + +import com.tangem.datasource.api.stakekit.models.response.model.BalanceDTO +import com.tangem.datasource.api.stakekit.models.response.model.YieldBalanceWrapperDTO +import com.tangem.datasource.local.datastore.core.StringKeyDataStore +import com.tangem.utils.extensions.addOrReplace +import kotlinx.coroutines.flow.Flow +import kotlinx.coroutines.flow.map + +internal class DefaultStakingBalanceStore( + private val dataStore: StringKeyDataStore>, +) : StakingBalanceStore { + + override fun get(): Flow> { + return dataStore.get(STAKING_BALANCE_KEY) + } + + override suspend fun getSyncOrNull(): List? { + return dataStore.getSyncOrNull(STAKING_BALANCE_KEY) + } + + override suspend fun store(items: List) { + return dataStore.store(STAKING_BALANCE_KEY, items) + } + + override fun get(integrationId: String): Flow> { + return dataStore.get(STAKING_BALANCE_KEY) + .map { balances -> + balances.filter { it.integrationId == integrationId } + .flatMap { it.balances } + } + } + + override suspend fun getSyncOrNull(integrationId: String): List? { + return dataStore.getSyncOrNull(STAKING_BALANCE_KEY) + ?.firstOrNull { it.integrationId == integrationId }?.balances + } + + override suspend fun store(integrationId: String, item: YieldBalanceWrapperDTO) { + val balances = dataStore.getSyncOrNull(STAKING_BALANCE_KEY) + ?.toMutableList() + ?.addOrReplace(item) { item.integrationId == integrationId } + ?: listOf(item) + + return dataStore.store(STAKING_BALANCE_KEY, balances) + } + + companion object { + private const val STAKING_BALANCE_KEY = "STAKING_BALANCE_KEY" + } +} \ No newline at end of file diff --git a/core/datasource/src/main/java/com/tangem/datasource/local/token/DefaultStakingTokensStore.kt b/core/datasource/src/main/java/com/tangem/datasource/local/token/DefaultStakingTokensStore.kt new file mode 100644 index 0000000000..a74afc914e --- /dev/null +++ b/core/datasource/src/main/java/com/tangem/datasource/local/token/DefaultStakingTokensStore.kt @@ -0,0 +1,21 @@ +package com.tangem.datasource.local.token + +import com.tangem.datasource.local.datastore.core.StringKeyDataStore +import com.tangem.domain.staking.model.StakingTokenWithYield + +internal class DefaultStakingTokensStore( + private val dataStore: StringKeyDataStore>, +) : StakingTokensStore { + + override suspend fun getSyncOrNull(): List? { + return dataStore.getSyncOrNull(STAKING_TOKENS_KEY) + } + + override suspend fun store(items: List) { + dataStore.store(STAKING_TOKENS_KEY, items) + } + + companion object { + private const val STAKING_TOKENS_KEY = "STAKING_TOKENS_KEY" + } +} \ No newline at end of file diff --git a/core/datasource/src/main/java/com/tangem/datasource/local/token/DefaultStakingYieldsStore.kt b/core/datasource/src/main/java/com/tangem/datasource/local/token/DefaultStakingYieldsStore.kt new file mode 100644 index 0000000000..1cdb6c381c --- /dev/null +++ b/core/datasource/src/main/java/com/tangem/datasource/local/token/DefaultStakingYieldsStore.kt @@ -0,0 +1,21 @@ +package com.tangem.datasource.local.token + +import com.tangem.datasource.api.stakekit.models.response.model.YieldDTO +import com.tangem.datasource.local.datastore.core.StringKeyDataStore + +internal class DefaultStakingYieldsStore( + private val dataStore: StringKeyDataStore>, +) : StakingYieldsStore { + + override suspend fun getSyncOrNull(): List? { + return dataStore.getSyncOrNull(STAKING_YIELDS_KEY) + } + + override suspend fun store(items: List) { + dataStore.store(STAKING_YIELDS_KEY, items) + } + + companion object { + private const val STAKING_YIELDS_KEY = "STAKING_YIELDS_KEY" + } +} \ No newline at end of file diff --git a/core/datasource/src/main/java/com/tangem/datasource/local/token/DefaultUserTokensStore.kt b/core/datasource/src/main/java/com/tangem/datasource/local/token/DefaultUserTokensStore.kt deleted file mode 100644 index 23cea085d6..0000000000 --- a/core/datasource/src/main/java/com/tangem/datasource/local/token/DefaultUserTokensStore.kt +++ /dev/null @@ -1,15 +0,0 @@ -package com.tangem.datasource.local.token - -import com.tangem.datasource.api.tangemTech.models.UserTokensResponse -import com.tangem.datasource.local.datastore.core.StringKeyDataStore -import com.tangem.datasource.local.datastore.core.StringKeyDataStoreDecorator -import com.tangem.domain.wallets.models.UserWalletId - -internal class DefaultUserTokensStore( - dataStore: StringKeyDataStore, -) : UserTokensStore, StringKeyDataStoreDecorator(dataStore) { - - override fun provideStringKey(key: UserWalletId): String { - return "user_tokens_${key.stringValue}" - } -} \ No newline at end of file diff --git a/core/datasource/src/main/java/com/tangem/datasource/local/token/AssetsStore.kt b/core/datasource/src/main/java/com/tangem/datasource/local/token/ExpressAssetsStore.kt similarity index 90% rename from core/datasource/src/main/java/com/tangem/datasource/local/token/AssetsStore.kt rename to core/datasource/src/main/java/com/tangem/datasource/local/token/ExpressAssetsStore.kt index 11d6101843..353a15c7e8 100644 --- a/core/datasource/src/main/java/com/tangem/datasource/local/token/AssetsStore.kt +++ b/core/datasource/src/main/java/com/tangem/datasource/local/token/ExpressAssetsStore.kt @@ -3,7 +3,7 @@ package com.tangem.datasource.local.token import com.tangem.datasource.api.express.models.response.Asset import com.tangem.domain.wallets.models.UserWalletId -interface AssetsStore { +interface ExpressAssetsStore { suspend fun getSyncOrNull(userWalletId: UserWalletId): List? diff --git a/core/datasource/src/main/java/com/tangem/datasource/local/token/StakingBalanceStore.kt b/core/datasource/src/main/java/com/tangem/datasource/local/token/StakingBalanceStore.kt new file mode 100644 index 0000000000..0a9ea06c9e --- /dev/null +++ b/core/datasource/src/main/java/com/tangem/datasource/local/token/StakingBalanceStore.kt @@ -0,0 +1,20 @@ +package com.tangem.datasource.local.token + +import com.tangem.datasource.api.stakekit.models.response.model.BalanceDTO +import com.tangem.datasource.api.stakekit.models.response.model.YieldBalanceWrapperDTO +import kotlinx.coroutines.flow.Flow + +interface StakingBalanceStore { + + fun get(): Flow> + + suspend fun getSyncOrNull(): List? + + suspend fun store(items: List) + + fun get(integrationId: String): Flow> + + suspend fun getSyncOrNull(integrationId: String): List? + + suspend fun store(integrationId: String, item: YieldBalanceWrapperDTO) +} \ No newline at end of file diff --git a/core/datasource/src/main/java/com/tangem/datasource/local/token/StakingTokensStore.kt b/core/datasource/src/main/java/com/tangem/datasource/local/token/StakingTokensStore.kt new file mode 100644 index 0000000000..586674756b --- /dev/null +++ b/core/datasource/src/main/java/com/tangem/datasource/local/token/StakingTokensStore.kt @@ -0,0 +1,10 @@ +package com.tangem.datasource.local.token + +import com.tangem.domain.staking.model.StakingTokenWithYield + +interface StakingTokensStore { + + suspend fun getSyncOrNull(): List? + + suspend fun store(items: List) +} \ No newline at end of file diff --git a/core/datasource/src/main/java/com/tangem/datasource/local/token/StakingYieldsStore.kt b/core/datasource/src/main/java/com/tangem/datasource/local/token/StakingYieldsStore.kt new file mode 100644 index 0000000000..61f46cf15d --- /dev/null +++ b/core/datasource/src/main/java/com/tangem/datasource/local/token/StakingYieldsStore.kt @@ -0,0 +1,10 @@ +package com.tangem.datasource.local.token + +import com.tangem.datasource.api.stakekit.models.response.model.YieldDTO + +interface StakingYieldsStore { + + suspend fun getSyncOrNull(): List? + + suspend fun store(items: List) +} \ No newline at end of file diff --git a/core/datasource/src/main/java/com/tangem/datasource/local/token/UserTokensStore.kt b/core/datasource/src/main/java/com/tangem/datasource/local/token/UserTokensStore.kt index 08fcb31438..f3f12f026b 100644 --- a/core/datasource/src/main/java/com/tangem/datasource/local/token/UserTokensStore.kt +++ b/core/datasource/src/main/java/com/tangem/datasource/local/token/UserTokensStore.kt @@ -4,11 +4,43 @@ import com.tangem.datasource.api.tangemTech.models.UserTokensResponse import com.tangem.domain.wallets.models.UserWalletId import kotlinx.coroutines.flow.Flow +@Deprecated( + message = "Use AppPreferencesStore", + replaceWith = ReplaceWith( + expression = "AppPreferencesStore", + imports = arrayOf("com.tangem.datasource.local.preferences.AppPreferencesStore"), + ), + level = DeprecationLevel.WARNING, +) interface UserTokensStore { + @Deprecated( + message = "Use getObject", + replaceWith = ReplaceWith( + expression = "appPreferencesStore.getObject(userWalletId)", + imports = arrayOf("com.tangem.datasource.local.preferences.AppPreferencesStore"), + ), + level = DeprecationLevel.WARNING, + ) fun get(key: UserWalletId): Flow + @Deprecated( + message = "Use getObjectSyncOrNull", + replaceWith = ReplaceWith( + expression = "appPreferencesStore.getObjectSyncOrNull(userWalletId)", + imports = arrayOf("com.tangem.datasource.local.preferences.AppPreferencesStore"), + ), + level = DeprecationLevel.WARNING, + ) suspend fun getSyncOrNull(key: UserWalletId): UserTokensResponse? + @Deprecated( + message = "Use storeObject", + replaceWith = ReplaceWith( + expression = "appPreferencesStore.storeObject(userWalletId, response)", + imports = arrayOf("com.tangem.datasource.local.preferences.AppPreferencesStore"), + ), + level = DeprecationLevel.WARNING, + ) suspend fun store(key: UserWalletId, value: UserTokensResponse) } \ No newline at end of file diff --git a/core/datasource/src/main/java/com/tangem/datasource/local/token/UserTokensStoreMigration.kt b/core/datasource/src/main/java/com/tangem/datasource/local/token/UserTokensStoreMigration.kt new file mode 100644 index 0000000000..dae09c0616 --- /dev/null +++ b/core/datasource/src/main/java/com/tangem/datasource/local/token/UserTokensStoreMigration.kt @@ -0,0 +1,56 @@ +package com.tangem.datasource.local.token + +import androidx.datastore.core.DataMigration +import com.squareup.moshi.Moshi +import com.squareup.moshi.adapter +import com.tangem.datasource.api.tangemTech.models.UserTokensResponse +import com.tangem.datasource.files.FileReader +import com.tangem.datasource.local.preferences.AppPreferencesStore +import com.tangem.datasource.local.preferences.PreferencesKeys +import com.tangem.datasource.local.preferences.utils.getObjectSyncOrNull +import com.tangem.datasource.local.preferences.utils.storeObject + +/** + * Migration of saving [UserTokensResponse] from file to [AppPreferencesStore] + * + * @param userWalletId user wallet id + * @param moshi moshi + * @property fileReader file reader + * +[REDACTED_AUTHOR] + */ +internal class UserTokensStoreMigration( + userWalletId: String, + moshi: Moshi, + private val fileReader: FileReader, +) : DataMigration { + + private val legacyFileName = "user_tokens_$userWalletId" + private val keyName = PreferencesKeys.getUserTokensKey(userWalletId = userWalletId) + + @OptIn(ExperimentalStdlibApi::class) + private val adapter = moshi.adapter() + + override suspend fun shouldMigrate(currentData: AppPreferencesStore): Boolean = true + + override suspend fun migrate(currentData: AppPreferencesStore): AppPreferencesStore { + val currentKey = currentData.getObjectSyncOrNull(key = keyName) + + if (currentKey != null) return currentData + + val value = runCatching { + val json = fileReader.readFile(legacyFileName) + adapter.fromJson(json) + }.getOrNull() + + if (value != null) { + currentData.storeObject(key = keyName, value = value) + } + + return currentData + } + + override suspend fun cleanUp() { + fileReader.removeFile(legacyFileName) + } +} \ No newline at end of file diff --git a/core/datasource/src/main/java/com/tangem/datasource/local/token/UserTokensStoreMigrationRunner.kt b/core/datasource/src/main/java/com/tangem/datasource/local/token/UserTokensStoreMigrationRunner.kt new file mode 100644 index 0000000000..eafb84aa79 --- /dev/null +++ b/core/datasource/src/main/java/com/tangem/datasource/local/token/UserTokensStoreMigrationRunner.kt @@ -0,0 +1,50 @@ +package com.tangem.datasource.local.token + +import com.squareup.moshi.Moshi +import com.tangem.datasource.di.NetworkMoshi +import com.tangem.datasource.files.FileReader +import com.tangem.datasource.local.preferences.AppPreferencesStore +import com.tangem.utils.coroutines.CoroutineDispatcherProvider +import kotlinx.coroutines.coroutineScope +import kotlinx.coroutines.withContext +import javax.inject.Inject +import javax.inject.Singleton + +/** + * Runner that launch migrations of saving user tokens store + * + * @property appPreferencesStore application preference store + * @property fileReader file reader + * @property moshi moshi + * @property dispatchers dispatchers + * +[REDACTED_AUTHOR] + */ +@Singleton +class UserTokensStoreMigrationRunner @Inject constructor( + private val appPreferencesStore: AppPreferencesStore, + private val fileReader: FileReader, + @NetworkMoshi private val moshi: Moshi, + private val dispatchers: CoroutineDispatcherProvider, +) { + + suspend fun run(ids: List) { + ids.forEach { id -> + coroutineScope { run(id) } + } + } + + private suspend fun run(id: String) { + withContext(dispatchers.io) { + val migration = UserTokensStoreMigration( + userWalletId = id, + moshi = moshi, + fileReader = fileReader, + ) + + migration.migrate(appPreferencesStore) + + migration.cleanUp() + } + } +} \ No newline at end of file diff --git a/core/datasource/src/main/java/com/tangem/datasource/local/userwallet/UserWalletsStore.kt b/core/datasource/src/main/java/com/tangem/datasource/local/userwallet/UserWalletsStore.kt index bfee20e460..54fe4ff322 100644 --- a/core/datasource/src/main/java/com/tangem/datasource/local/userwallet/UserWalletsStore.kt +++ b/core/datasource/src/main/java/com/tangem/datasource/local/userwallet/UserWalletsStore.kt @@ -1,16 +1,22 @@ package com.tangem.datasource.local.userwallet +import com.tangem.common.CompletionResult import com.tangem.domain.wallets.models.UserWallet import com.tangem.domain.wallets.models.UserWalletId +import kotlinx.coroutines.flow.Flow interface UserWalletsStore { val selectedUserWalletOrNull: UserWallet? + val userWallets: Flow> + suspend fun getSyncOrNull(key: UserWalletId): UserWallet? suspend fun getAllSyncOrNull(): List? - @Throws - suspend fun update(userWalletId: UserWalletId, update: suspend (UserWallet) -> UserWallet) + suspend fun update( + userWalletId: UserWalletId, + update: suspend (UserWallet) -> UserWallet, + ): CompletionResult } \ No newline at end of file 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 c9fa81608f..215b56e9f8 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 @@ -35,5 +35,6 @@ sealed class RequestHeader(vararg pairs: Pair String>) { class StakeKit(stakeKitAuthProvider: StakeKitAuthProvider) : RequestHeader( "X-API-KEY" to { stakeKitAuthProvider.getApiKey() }, + "accept" to { "application/json" }, ) } \ No newline at end of file diff --git a/core/decompose/src/main/kotlin/com/tangem/core/decompose/di/DecomposeComponent.kt b/core/decompose/src/main/kotlin/com/tangem/core/decompose/di/DecomposeComponent.kt index b5df451866..74fba5a48e 100644 --- a/core/decompose/src/main/kotlin/com/tangem/core/decompose/di/DecomposeComponent.kt +++ b/core/decompose/src/main/kotlin/com/tangem/core/decompose/di/DecomposeComponent.kt @@ -1,5 +1,6 @@ package com.tangem.core.decompose.di +import com.tangem.core.decompose.model.ParamsContainer import com.tangem.core.decompose.navigation.Router import com.tangem.core.decompose.ui.UiMessageSender import dagger.BindsInstance @@ -37,6 +38,14 @@ interface DecomposeComponent { */ fun uiMessageSender(@BindsInstance uiMessageSender: UiMessageSender): Builder + /** + * Sets the parameters container for the component. + * + * @param container The parameters container to set. + * @return The builder instance. + */ + fun paramsContainer(@BindsInstance container: ParamsContainer): Builder + /** * Builds the Decompose component. * diff --git a/core/decompose/src/main/kotlin/com/tangem/core/decompose/factory/ComponentFactory.kt b/core/decompose/src/main/kotlin/com/tangem/core/decompose/factory/ComponentFactory.kt new file mode 100644 index 0000000000..20c1159324 --- /dev/null +++ b/core/decompose/src/main/kotlin/com/tangem/core/decompose/factory/ComponentFactory.kt @@ -0,0 +1,8 @@ +package com.tangem.core.decompose.factory + +import com.tangem.core.decompose.context.AppComponentContext + +interface ComponentFactory

{ + + fun create(context: AppComponentContext, params: P): C +} \ No newline at end of file diff --git a/core/decompose/src/main/kotlin/com/tangem/core/decompose/model/ModelEntryPoint.kt b/core/decompose/src/main/kotlin/com/tangem/core/decompose/model/ModelEntryPoint.kt index 58cad4cf7a..56b718e970 100644 --- a/core/decompose/src/main/kotlin/com/tangem/core/decompose/model/ModelEntryPoint.kt +++ b/core/decompose/src/main/kotlin/com/tangem/core/decompose/model/ModelEntryPoint.kt @@ -22,24 +22,35 @@ interface ModelsEntryPoint { } /** - * Gets or creates a component's [Model]. + * Gets or creates a component's [Model] with no parameters. */ -inline fun AppComponentContext.getOrCreateModel(): M { - val modelKey = "model_${M::class.simpleName}" +inline fun AppComponentContext.getOrCreateModel(): M = getOrCreateModel(params = null) +/** + * Gets or creates a component's [Model]. + * + * Be careful with objects you pass in parameters as they will be used in [Model] lifecycle. + * If you pass a object with different lifecycle than the [Model] then you can face memory leaks. + * + * @param params The parameters to store in the [ParamsContainer], + + */ +inline fun AppComponentContext.getOrCreateModel(params: P?): M { val entryPoint = instanceKeeper.getOrCreateSimple(key = "modelsEntryPoint") { val hiltComponent = hiltComponentBuilder .router(router) .uiMessageSender(messageSender) + .paramsContainer(MutableParamsContainer(params ?: Unit)) .build() EntryPoints.get(hiltComponent, ModelsEntryPoint::class.java) } + val modelKey = "model_${M::class.simpleName}" val model = instanceKeeper.getOrCreate(modelKey) { requireNotNull(entryPoint.models()[M::class.java]?.get()) { "Model ${M::class.simpleName} is not provided" - } + } as M } val isModelExist = tags.getOrElse(modelKey) { false } as Boolean @@ -47,5 +58,5 @@ inline fun AppComponentContext.getOrCreateModel(): M { tags[modelKey] = true } - return model as M + return model } \ No newline at end of file diff --git a/core/decompose/src/main/kotlin/com/tangem/core/decompose/model/ParamsContainer.kt b/core/decompose/src/main/kotlin/com/tangem/core/decompose/model/ParamsContainer.kt new file mode 100644 index 0000000000..910764d661 --- /dev/null +++ b/core/decompose/src/main/kotlin/com/tangem/core/decompose/model/ParamsContainer.kt @@ -0,0 +1,45 @@ +package com.tangem.core.decompose.model + +/** + * Lazy container for [Model] params. + * + * This contrainer can be accessed by DI because it's provided via [com.tangem.core.decompose.di.DecomposeComponent]. + * */ +interface ParamsContainer { + + /** Returns stored value if it is of type [T], otherwise returns null. */ + fun get(): T? + + /** Returns stored value if it is of type [T], otherwise throws an exception. */ + fun require(): T +} + +/** + * Mutable implementation of [ParamsContainer]. + * + * ***You should not use this class directly in other modules, use immutable [ParamsContainer] instead.*** + * */ +class MutableParamsContainer private constructor() : ParamsContainer { + + private var value: Any? = null + + /** Stores [value] inside a container, replaces any previous stored value. */ + fun set(value: Any) { + this.value = value + } + + @Suppress("UNCHECKED_CAST") + override fun get(): T? = value as? T + + override fun require(): T = get() ?: error("Contrainer is empty or contains a value of a different type.") + + companion object { + + /** Creates a new [MutableParamsContainer] and stores [value] inside it. */ + operator fun invoke(value: T): MutableParamsContainer { + return MutableParamsContainer().apply { + set(value) + } + } + } +} \ No newline at end of file diff --git a/core/decompose/src/main/kotlin/com/tangem/core/decompose/navigation/DefaultRouter.kt b/core/decompose/src/main/kotlin/com/tangem/core/decompose/navigation/DefaultRouter.kt index 50e3840442..86c43706a6 100644 --- a/core/decompose/src/main/kotlin/com/tangem/core/decompose/navigation/DefaultRouter.kt +++ b/core/decompose/src/main/kotlin/com/tangem/core/decompose/navigation/DefaultRouter.kt @@ -6,6 +6,7 @@ import com.arkivanov.decompose.router.stack.pop import com.arkivanov.decompose.router.stack.popWhile import com.arkivanov.decompose.router.stack.pushNew import com.arkivanov.essenty.instancekeeper.InstanceKeeper +import kotlin.reflect.KClass internal class DefaultRouter( private val navigationProvider: AppNavigationProvider, @@ -19,6 +20,15 @@ internal class DefaultRouter( navigation.pushNew(route, onComplete) } + override fun replaceAll(vararg routes: Route, onComplete: (isSuccess: Boolean) -> Unit) { + val newRoutes = routes.toList() + + navigation.navigate( + transformer = { newRoutes }, + onComplete = { newStack, _ -> onComplete(newStack.size == newRoutes.size) }, + ) + } + override fun pop(onComplete: (isSuccess: Boolean) -> Unit) { navigation.pop(onComplete) } @@ -29,4 +39,11 @@ internal class DefaultRouter( onComplete = onComplete, ) } + + override fun popTo(routeClass: KClass, onComplete: (isSuccess: Boolean) -> Unit) { + navigation.popWhile( + predicate = { it::class != routeClass }, + onComplete = onComplete, + ) + } } \ No newline at end of file diff --git a/core/decompose/src/main/kotlin/com/tangem/core/decompose/navigation/DummyRouter.kt b/core/decompose/src/main/kotlin/com/tangem/core/decompose/navigation/DummyRouter.kt new file mode 100644 index 0000000000..77e7a8f59d --- /dev/null +++ b/core/decompose/src/main/kotlin/com/tangem/core/decompose/navigation/DummyRouter.kt @@ -0,0 +1,26 @@ +package com.tangem.core.decompose.navigation + +import kotlin.reflect.KClass + +class DummyRouter : Router { + + override fun push(route: Route, onComplete: (isSuccess: Boolean) -> Unit) { + onComplete(true) + } + + override fun replaceAll(vararg routes: Route, onComplete: (isSuccess: Boolean) -> Unit) { + onComplete(true) + } + + override fun pop(onComplete: (isSuccess: Boolean) -> Unit) { + onComplete(true) + } + + override fun popTo(route: Route, onComplete: (isSuccess: Boolean) -> Unit) { + onComplete(true) + } + + override fun popTo(routeClass: KClass, onComplete: (isSuccess: Boolean) -> Unit) { + onComplete(true) + } +} \ No newline at end of file diff --git a/core/decompose/src/main/kotlin/com/tangem/core/decompose/navigation/Router.kt b/core/decompose/src/main/kotlin/com/tangem/core/decompose/navigation/Router.kt index 3a9b7d93ca..da7f859b8f 100644 --- a/core/decompose/src/main/kotlin/com/tangem/core/decompose/navigation/Router.kt +++ b/core/decompose/src/main/kotlin/com/tangem/core/decompose/navigation/Router.kt @@ -1,8 +1,10 @@ package com.tangem.core.decompose.navigation +import kotlin.reflect.KClass + /** * Interface for a router in the application. - * It provides methods for navigating through the application. + * It provides methods for navigating through the application by stack. */ interface Router { @@ -14,6 +16,14 @@ interface Router { */ fun push(route: Route, onComplete: (isSuccess: Boolean) -> Unit = {}) + /** + * Replaces ***all*** routes in the navigation stack with the specified [routes]. + * + * @param routes The routes to replace the current stack with. + * @param onComplete The callback to be invoked when the operation is complete. + */ + fun replaceAll(vararg routes: Route, onComplete: (isSuccess: Boolean) -> Unit = {}) + /** * Pops the top route from the navigation stack. * @@ -22,10 +32,18 @@ interface Router { fun pop(onComplete: (isSuccess: Boolean) -> Unit = {}) /** - * Pops routes from the navigation stack until the specified route is found. + * Pops routes from the navigation stack until the specified [route] is found. * * @param route The route to pop to. * @param onComplete The callback to be invoked when the operation is complete. */ fun popTo(route: Route, onComplete: (isSuccess: Boolean) -> Unit = {}) + + /** + * Pops routes from the navigation stack until the ***first*** specified [routeClass] is found. + * + * @param routeClass The route class to pop to. + * @param onComplete The callback to be invoked when the operation is complete. + */ + fun popTo(routeClass: KClass, onComplete: (isSuccess: Boolean) -> Unit = {}) } \ No newline at end of file diff --git a/core/decompose/src/main/kotlin/com/tangem/core/decompose/navigation/RouterExt.kt b/core/decompose/src/main/kotlin/com/tangem/core/decompose/navigation/RouterExt.kt new file mode 100644 index 0000000000..777cc78199 --- /dev/null +++ b/core/decompose/src/main/kotlin/com/tangem/core/decompose/navigation/RouterExt.kt @@ -0,0 +1,11 @@ +package com.tangem.core.decompose.navigation + +/** + * Pops routes from the navigation stack until the specified route [R] is found. + * + * @param R The route to pop to. + * @param onComplete The callback to be invoked when the operation is complete. + */ +inline fun Router.popTo(noinline onComplete: (isSuccess: Boolean) -> Unit = {}) { + popTo(R::class, onComplete) +} \ No newline at end of file diff --git a/core/featuretoggles/src/main/assets/configs/feature_toggles_config.json b/core/featuretoggles/src/main/assets/configs/feature_toggles_config.json index a4472cf056..7def5136f7 100644 --- a/core/featuretoggles/src/main/assets/configs/feature_toggles_config.json +++ b/core/featuretoggles/src/main/assets/configs/feature_toggles_config.json @@ -3,10 +3,6 @@ "name": "NEW_CARD_SCANNING_ENABLED", "version": "undefined" }, - { - "name": "REDESIGNED_MANAGE_TOKENS_SCREEN_ENABLED", - "version": "undefined" - }, { "name": "REDESIGNED_SEND_SCREEN_ENABLED", "version": "5.10.0" @@ -23,10 +19,6 @@ "name": "WC_SOLANA_TX_SIGN_ENABLED", "version": "undefined" }, - { - "name": "TOKEN_LIST_LCE_ENABLED", - "version": "5.12.0" - }, { "name": "CARDANO_TOKENS_SUPPORT_ENABLED", "version": "5.12.0" @@ -36,11 +28,15 @@ "version": "undefined" }, { - "name": "FULL_RESET_ENABLED", - "version": "5.12.0" + "name": "DETAILS_REDESIGN_ENABLED", + "version": "5.13.0" }, { - "name": "DETAILS_REDESIGN_ENABLED", + "name": "PUSH_NOTIFICATIONS_ENABLED", + "version": "5.13.0" + }, + { + "name": "MARKETS_ENABLED", "version": "undefined" } ] diff --git a/core/featuretoggles/src/main/kotlin/com/tangem/core/featuretoggle/version/DefaultVersionProvider.kt b/core/featuretoggles/src/main/kotlin/com/tangem/core/featuretoggle/version/DefaultVersionProvider.kt index 7cebaee8a8..c602be463f 100644 --- a/core/featuretoggles/src/main/kotlin/com/tangem/core/featuretoggle/version/DefaultVersionProvider.kt +++ b/core/featuretoggles/src/main/kotlin/com/tangem/core/featuretoggle/version/DefaultVersionProvider.kt @@ -3,6 +3,7 @@ package com.tangem.core.featuretoggle.version import android.content.Context import android.content.pm.PackageManager import android.os.Build +import com.tangem.utils.StringsSigns.MINUS import dagger.hilt.android.qualifiers.ApplicationContext import javax.inject.Inject @@ -34,6 +35,6 @@ internal class DefaultVersionProvider @Inject constructor( } private companion object { - const val VERSION_NAME_DELIMITER = "-" + const val VERSION_NAME_DELIMITER = MINUS } } \ No newline at end of file diff --git a/core/navigation/src/main/java/com/tangem/core/navigation/NavigationAction.kt b/core/navigation/src/main/java/com/tangem/core/navigation/NavigationAction.kt deleted file mode 100644 index 676958ef92..0000000000 --- a/core/navigation/src/main/java/com/tangem/core/navigation/NavigationAction.kt +++ /dev/null @@ -1,33 +0,0 @@ -package com.tangem.core.navigation - -import android.net.Uri -import android.os.Bundle -import androidx.appcompat.app.AppCompatActivity -import org.rekotlin.Action -import java.lang.ref.WeakReference - -sealed class NavigationAction : Action { - - data class NavigateTo( - val screen: AppScreen, - val fragmentShareTransition: FragmentShareTransition? = null, - val addToBackstack: Boolean = true, - val bundle: Bundle? = null, - ) : NavigationAction() - - data class PopBackTo(val screen: AppScreen? = null, val inclusive: Boolean = false) : NavigationAction() - - data class OpenUrl(val url: String) : NavigationAction() - - data class OpenDocument(val url: Uri) : NavigationAction() - - object OpenBiometricsSettings : NavigationAction() - - data class OpenDialog(val stateDialog: StateDialog) : NavigationAction() - - data class Share(val data: String) : NavigationAction() - - data class ActivityCreated(val activity: WeakReference) : NavigationAction() - - data class ActivityDestroyed(val activity: WeakReference) : NavigationAction() -} \ No newline at end of file diff --git a/core/navigation/src/main/java/com/tangem/core/navigation/NavigationState.kt b/core/navigation/src/main/java/com/tangem/core/navigation/NavigationState.kt deleted file mode 100644 index a0a6d64f25..0000000000 --- a/core/navigation/src/main/java/com/tangem/core/navigation/NavigationState.kt +++ /dev/null @@ -1,38 +0,0 @@ -package com.tangem.core.navigation - -import androidx.appcompat.app.AppCompatActivity -import org.rekotlin.StateType -import java.lang.ref.WeakReference - -data class NavigationState( - val backStack: List = emptyList(), - val activity: WeakReference? = null, -) : StateType - -enum class AppScreen(val isDialogFragment: Boolean = false) { - Home, - Disclaimer, - OnboardingNote, - OnboardingWallet, - OnboardingTwins, - OnboardingOther, - Wallet, - WalletDetails, - Send(isDialogFragment = true), - Details, - DetailsSecurity, - CardSettings, - AppSettings, - ResetToFactory, - AccessCodeRecovery, - ManageTokens, - AddCustomToken, - WalletConnectSessions, - QrScanning, - ReferralProgram, - Swap, - Welcome, - SaveWallet(isDialogFragment = true), - AppCurrencySelector, - ModalNotification(isDialogFragment = true), -} \ No newline at end of file diff --git a/core/navigation/src/main/java/com/tangem/core/navigation/ReduxNavController.kt b/core/navigation/src/main/java/com/tangem/core/navigation/ReduxNavController.kt deleted file mode 100644 index 20e37f3958..0000000000 --- a/core/navigation/src/main/java/com/tangem/core/navigation/ReduxNavController.kt +++ /dev/null @@ -1,16 +0,0 @@ -package com.tangem.core.navigation - -/** - * Navigation controller that based on redux actions - * -[REDACTED_AUTHOR] - */ -interface ReduxNavController { - - /** Navigate by [action] */ - fun navigate(action: NavigationAction) - - fun popBackStack(screen: AppScreen? = null) - - fun getBackStack(): List -} \ No newline at end of file diff --git a/core/navigation/src/main/java/com/tangem/core/navigation/FragmentShareTransition.kt b/core/navigation/src/main/java/com/tangem/core/navigation/ShareElement.kt similarity index 74% rename from core/navigation/src/main/java/com/tangem/core/navigation/FragmentShareTransition.kt rename to core/navigation/src/main/java/com/tangem/core/navigation/ShareElement.kt index 2cb2132eec..b3fd049583 100644 --- a/core/navigation/src/main/java/com/tangem/core/navigation/FragmentShareTransition.kt +++ b/core/navigation/src/main/java/com/tangem/core/navigation/ShareElement.kt @@ -1,18 +1,8 @@ package com.tangem.core.navigation import android.view.View -import androidx.transition.TransitionSet import java.lang.ref.WeakReference -/** -[REDACTED_AUTHOR] - */ -data class FragmentShareTransition( - val shareElements: List, - val enterTransitionSet: TransitionSet, - val exitTransitionSet: TransitionSet, -) - /** * For ease of use, the name is used as transitionName\name into the FragmentTransaction.addSharedElement */ diff --git a/core/navigation/src/main/java/com/tangem/core/navigation/StateDialog.kt b/core/navigation/src/main/java/com/tangem/core/navigation/StateDialog.kt deleted file mode 100644 index 75aa1f0579..0000000000 --- a/core/navigation/src/main/java/com/tangem/core/navigation/StateDialog.kt +++ /dev/null @@ -1,10 +0,0 @@ -package com.tangem.core.navigation - -interface StateDialog { - - data class ScanFailsDialog(val source: ScanFailsSource) : StateDialog - - enum class ScanFailsSource { - MAIN, SIGN_IN, SETTINGS, INTRO; - } -} \ No newline at end of file diff --git a/core/navigation/src/main/java/com/tangem/core/navigation/finisher/AppFinisher.kt b/core/navigation/src/main/java/com/tangem/core/navigation/finisher/AppFinisher.kt new file mode 100644 index 0000000000..54785819e1 --- /dev/null +++ b/core/navigation/src/main/java/com/tangem/core/navigation/finisher/AppFinisher.kt @@ -0,0 +1,8 @@ +package com.tangem.core.navigation.finisher + +interface AppFinisher { + + fun finish() + + fun restart() +} \ No newline at end of file diff --git a/core/navigation/src/main/java/com/tangem/core/navigation/settings/DummySettingsManager.kt b/core/navigation/src/main/java/com/tangem/core/navigation/settings/DummySettingsManager.kt new file mode 100644 index 0000000000..25c4706fb9 --- /dev/null +++ b/core/navigation/src/main/java/com/tangem/core/navigation/settings/DummySettingsManager.kt @@ -0,0 +1,5 @@ +package com.tangem.core.navigation.settings + +class DummySettingsManager : SettingsManager { + override fun openSettings() { /* no-op */ } +} \ No newline at end of file diff --git a/core/navigation/src/main/java/com/tangem/core/navigation/settings/SettingsManager.kt b/core/navigation/src/main/java/com/tangem/core/navigation/settings/SettingsManager.kt new file mode 100644 index 0000000000..4be904c9cb --- /dev/null +++ b/core/navigation/src/main/java/com/tangem/core/navigation/settings/SettingsManager.kt @@ -0,0 +1,5 @@ +package com.tangem.core.navigation.settings + +interface SettingsManager { + fun openSettings() +} \ No newline at end of file diff --git a/core/navigation/src/main/java/com/tangem/core/navigation/share/DummyShareManager.kt b/core/navigation/src/main/java/com/tangem/core/navigation/share/DummyShareManager.kt new file mode 100644 index 0000000000..20769b6995 --- /dev/null +++ b/core/navigation/src/main/java/com/tangem/core/navigation/share/DummyShareManager.kt @@ -0,0 +1,8 @@ +package com.tangem.core.navigation.share + +class DummyShareManager : ShareManager { + + override fun shareText(text: String) { + /* no-op */ + } +} \ No newline at end of file diff --git a/core/navigation/src/main/java/com/tangem/core/navigation/share/ShareManager.kt b/core/navigation/src/main/java/com/tangem/core/navigation/share/ShareManager.kt new file mode 100644 index 0000000000..81146f78f4 --- /dev/null +++ b/core/navigation/src/main/java/com/tangem/core/navigation/share/ShareManager.kt @@ -0,0 +1,6 @@ +package com.tangem.core.navigation.share + +interface ShareManager { + + fun shareText(text: String) +} \ No newline at end of file diff --git a/core/navigation/src/main/java/com/tangem/core/navigation/url/DummyUrlOpener.kt b/core/navigation/src/main/java/com/tangem/core/navigation/url/DummyUrlOpener.kt new file mode 100644 index 0000000000..cff4946b40 --- /dev/null +++ b/core/navigation/src/main/java/com/tangem/core/navigation/url/DummyUrlOpener.kt @@ -0,0 +1,8 @@ +package com.tangem.core.navigation.url + +class DummyUrlOpener : UrlOpener { + + override fun openUrl(url: String) { + /* no-op */ + } +} \ No newline at end of file diff --git a/core/navigation/src/main/java/com/tangem/core/navigation/url/UrlOpener.kt b/core/navigation/src/main/java/com/tangem/core/navigation/url/UrlOpener.kt new file mode 100644 index 0000000000..d78ba1b1eb --- /dev/null +++ b/core/navigation/src/main/java/com/tangem/core/navigation/url/UrlOpener.kt @@ -0,0 +1,6 @@ +package com.tangem.core.navigation.url + +interface UrlOpener { + + fun openUrl(url: String) +} \ No newline at end of file diff --git a/core/pagination/.gitignore b/core/pagination/.gitignore new file mode 100644 index 0000000000..42afabfd2a --- /dev/null +++ b/core/pagination/.gitignore @@ -0,0 +1 @@ +/build \ No newline at end of file diff --git a/core/pagination/build.gradle.kts b/core/pagination/build.gradle.kts new file mode 100644 index 0000000000..c7b5d3d97a --- /dev/null +++ b/core/pagination/build.gradle.kts @@ -0,0 +1,10 @@ +plugins { + alias(deps.plugins.kotlin.jvm) + id("configuration") +} + +dependencies { + // region Coroutines + implementation(deps.kotlin.coroutines) + // endregion +} \ No newline at end of file diff --git a/core/pagination/src/main/java/com/tangem/pagination/Batch.kt b/core/pagination/src/main/java/com/tangem/pagination/Batch.kt new file mode 100644 index 0000000000..0e262776a2 --- /dev/null +++ b/core/pagination/src/main/java/com/tangem/pagination/Batch.kt @@ -0,0 +1,13 @@ +package com.tangem.pagination + +/** + * Represents a batch of data with a key. + * Used in [BatchListState]. + * + * @param TKey type of the key. + * @param TData type of the data. + */ +data class Batch( + val key: TKey, + val data: TData, +) \ No newline at end of file diff --git a/core/pagination/src/main/java/com/tangem/pagination/BatchAction.kt b/core/pagination/src/main/java/com/tangem/pagination/BatchAction.kt new file mode 100644 index 0000000000..fd013069eb --- /dev/null +++ b/core/pagination/src/main/java/com/tangem/pagination/BatchAction.kt @@ -0,0 +1,77 @@ +package com.tangem.pagination + +import java.util.UUID + +/** + * Action that can be dispatched to [BatchListSource]. + * + * @param TRequestParams type of the request params to load batches. + * @param TKey type of the key of the batch. + * @param TUpdate type of the update request. + */ +sealed class BatchAction { + + /** + * Action to load the first batch. + * + * @param requestParams request params to load the first batch. + */ + data class Reload( + val requestParams: TRequestParams, + ) : BatchAction() + + /** + * Action to load the next batch. + * + * @param requestParams request params to load the next batch with new request. + * If null, the last request will be used. + * Will be saved in the state and used for future LoadMore actions with request = null. + */ + data class LoadMore( + val requestParams: TRequestParams? = null, + ) : BatchAction() + + /** + * Action to update the batch. + * + * @param keys keys of the batches to update. + * @param updateRequest request to update the batches. + * @param async true if the request doesn't require to synchronize on specific batches in order to fetch update + * data, this request will be delegated to fetchAsync method in [BatchUpdateFetcher], + * false if request requires to hold the current batches data until fetch + update is completed + * @param operationId the unique identifier of the request. + * Only one request with the same hash can be executed at a time, + * the rest of the requests will be canceled as long as there is a request with this hash in progress. + */ + class UpdateBatches( + val keys: Set, + val updateRequest: TUpdate, + val async: Boolean = false, + val operationId: String = UUID.randomUUID().toString(), + ) : BatchAction() + + /** + * Action to cancel the current batch loading. + */ + data object CancelBatchLoading : BatchAction() + + /** + * Action to cancel all update requests. + */ + data object CancelAllUpdates : BatchAction() + + /** + * Action to cancel update requests that satisfy the predicate. + * + * @param predicate predicate to check if the update request should be cancelled. + */ + class CancelUpdates( + val predicate: (UpdateBatches) -> Boolean, + ) : BatchAction() + + /** + * Clears the state and stops all current batch loading and updates + * After this status becomes [PaginationStatus.None] + */ + data object Reset : BatchAction() +} \ No newline at end of file diff --git a/core/pagination/src/main/java/com/tangem/pagination/BatchFetchResult.kt b/core/pagination/src/main/java/com/tangem/pagination/BatchFetchResult.kt new file mode 100644 index 0000000000..f7b78b226f --- /dev/null +++ b/core/pagination/src/main/java/com/tangem/pagination/BatchFetchResult.kt @@ -0,0 +1,32 @@ +package com.tangem.pagination + +/** + * Represents a result of a batch fetch request. + * Used in [BatchListState]. + * + * @param TData type of the data. + */ +sealed class BatchFetchResult { + + /** + * Represents a successful result of a batch fetch request. + * + * @param data fetched data. + * @param empty indicates that data is empty and [BatchListSource] shouldn't create new batch for this result + * @param last indicates if this is the last batch for the request. + */ + data class Success( + val data: TData, + val empty: Boolean, + val last: Boolean, + ) : BatchFetchResult() + + /** + * Represents an error result of a batch fetch request. + * Also used for unexpected exceptions that occurred in fetch method in BatchFetcher. + * + * @param throwable throwable that occurred during the request. + * @see com.tangem.pagination.fetcher.BatchFetcher + */ + class Error(val throwable: Throwable) : BatchFetchResult() +} \ No newline at end of file diff --git a/core/pagination/src/main/java/com/tangem/pagination/BatchListSource.kt b/core/pagination/src/main/java/com/tangem/pagination/BatchListSource.kt new file mode 100644 index 0000000000..158de617e7 --- /dev/null +++ b/core/pagination/src/main/java/com/tangem/pagination/BatchListSource.kt @@ -0,0 +1,486 @@ +package com.tangem.pagination + +import com.tangem.pagination.exception.OperationWIthTheSameIdInProgress +import com.tangem.pagination.fetcher.BatchFetcher +import kotlinx.coroutines.* +import kotlinx.coroutines.channels.BufferOverflow +import kotlinx.coroutines.flow.* + +/** + * Source for paginated data. The starting point for pagination. + * + * @param TKey Type of the key that identifies a batch. + * @param TData Type of the data in the batch. Generally, it' a list of items. + * @param TUpdate Type of the update request. + * @property state State of the paginated data. + * @property updateResults Flow of results of update requests. + */ +interface BatchListSource { + val state: StateFlow> + val updateResults: SharedFlow>> +} + +/** + * Creates a new [BatchListSource] with the provided configuration. + * + * @param fetchDispatcher Dispatcher for fetch operations. + * @param context Context for batching. + * @param generateNewKey Function to generate a new key for a batch. + * @param batchFetcher Function to fetch a batch of data. + * + * @return New instance of [BatchListSource]. + */ +@Suppress("FunctionNaming") +fun BatchListSource( + fetchDispatcher: CoroutineDispatcher = Dispatchers.IO, + context: BatchingContext, + generateNewKey: suspend (List) -> TKey, + batchFetcher: BatchFetcher, +): BatchListSource = + DefaultBatchListSource(fetchDispatcher, context, generateNewKey, batchFetcher, null) + +/** + * Creates a new [BatchListSource] with the provided configuration. + * + * @param fetchDispatcher Dispatcher for fetch operations. + * @param context Context for batching. + * @param generateNewKey Function to generate a new key for a batch. + * @param batchFetcher Function to fetch a batch of data. + * @param updateFetcher Function to fetch updates for batches. + * + * @return New instance of [BatchListSource]. + */ +@Suppress("FunctionNaming") +fun BatchListSource( + fetchDispatcher: CoroutineDispatcher = Dispatchers.IO, + context: BatchingContext, + generateNewKey: suspend (List) -> TKey, + batchFetcher: BatchFetcher, + updateFetcher: BatchUpdateFetcher, +): BatchListSource = + DefaultBatchListSource(fetchDispatcher, context, generateNewKey, batchFetcher, updateFetcher) + +@Suppress("LargeClass") +private class DefaultBatchListSource( + private val fetchDispatcher: CoroutineDispatcher, + private val context: BatchingContext, + private val generateNewKey: suspend (List) -> TKey, + private val batchFetcher: BatchFetcher, + private val updateFetcher: BatchUpdateFetcher? = null, +) : BatchListSource { + + override val state = MutableStateFlow(BatchListState(emptyList(), PaginationStatus.None)) + override val updateResults = MutableSharedFlow>>( + extraBufferCapacity = 1, + onBufferOverflow = BufferOverflow.DROP_OLDEST, + ) + + private val scope = context.coroutineScope + private val updateJobs = MutableStateFlow, Job>>>(emptyList()) + private val updateAsyncJobs = + MutableStateFlow, Job>>>(emptyList()) + private val waitingUpdateJobs = + MutableStateFlow, Job>>>(emptyList()) + + private val lastRequestResult = MutableStateFlow?>(null) + private var reloadActionJob: Job? = null + private var loadMoreActionJob: Job? = null + + init { + scope.launch { + try { + awaitCancellation() + } finally { + withContext(NonCancellable) { + resetState() + } + } + } + + scope.launch { + context.actionsFlow + .conflate() + .collect { action -> + collectActions(action) + } + } + } + + @Suppress("CyclomaticComplexMethod") + private fun collectActions(action: BatchAction) { + when (action) { + is BatchAction.Reload -> { + // Stop all tasks + loadMoreActionJob?.cancel() + reloadActionJob?.cancel() + stopAllUpdates() + reloadActionJob = scope.launchFetch { + reloadTask(action) + } + } + is BatchAction.LoadMore -> { + if (loadMoreActionJob?.isActive == true) { + return + } + + loadMoreActionJob = scope.launchFetch { + reloadActionJob?.join() + loadMoreTask(action) + } + } + is BatchAction.UpdateBatches -> { + if (reloadActionJob?.isActive == true) { + return + } + + if (updateFetcher == null) return + // If the request with the same operationId is in progress, skip the request + if (updateInProgressExists(action.operationId)) { + updateResults.tryEmit( + action.updateRequest to BatchUpdateResult.Error( + OperationWIthTheSameIdInProgress(action.operationId), + ), + ) + } + + if (action.async) { + collectAsyncUpdateAction(action) + } else { + collectSyncUpdateAction(action) + } + } + BatchAction.CancelAllUpdates -> { + if (updateFetcher == null) return + + stopAllUpdates() + } + is BatchAction.CancelUpdates -> { + if (updateFetcher == null) return + stopUpdates(action.predicate) + } + BatchAction.CancelBatchLoading -> { + loadMoreActionJob?.cancel() + reloadActionJob?.cancel() + } + BatchAction.Reset -> { + resetState() + } + } + } + + private fun collectAsyncUpdateAction(action: BatchAction.UpdateBatches) { + val job = scope.launchFetch { + updateBatchesAsyncTask(action) + } + + val actionJob = action to job + + updateAsyncJobs.update { it + actionJob } + + job.invokeOnCompletion { cause -> + // If the job was cancelled it is up to a canceller to remove job from the updateJobs list + if (cause !is CancellationException) { + updateAsyncJobs.update { it - actionJob } + } + } + } + + private fun collectSyncUpdateAction(action: BatchAction.UpdateBatches) { + // Lazily start a job so we can avoid batch update collisions + // by waiting for other tasks with the same keys to complete + val job = scope.launchFetch(start = CoroutineStart.LAZY) { + updateBatchesTask(action) + } + + val actionJob = action to job + + waitingUpdateJobs.update { it + actionJob } + + scope.launchFetch { + // Wait for other update tasks that mutate batches with the same keys + updateJobs.first { workingJobs -> + action.keys.intersect(workingJobs.map { it.first.keys }.flatten().toSet()).isEmpty() + } + + waitingUpdateJobs.update { it - actionJob } + + // No other task are mutating batches with the same keys, so we can start a job + val started = job.start() + + if (started) { + updateJobs.update { it + actionJob } + + job.invokeOnCompletion { cause -> + // If the job was cancelled it is up to a canceller to remove job from the updateJobs list + if (cause !is CancellationException) { + updateJobs.update { it - actionJob } + } + } + } + } + } + + private suspend fun reloadTask(action: BatchAction.Reload) { + state.value = BatchListState( + data = emptyList(), + status = PaginationStatus.InitialLoading, + ) + + val res = runCatching { + batchFetcher.fetchFirst(action.requestParams) + }.getOrElse { + currentCoroutineContext().ensureActive() + BatchFetchResult.Error(it) + } + + currentCoroutineContext().ensureActive() + + state.value = when (res) { + is BatchFetchResult.Success -> { + val batch = if (res.empty.not()) { + Batch( + key = generateNewKey(listOf()), + data = res.data, + ) + } else { + null + } + + BatchListState( + data = batch?.let { listOf(it) } ?: emptyList(), + status = if (res.last) { + PaginationStatus.EndOfPagination + } else { + PaginationStatus.Paginating(res) + }, + ) + } + is BatchFetchResult.Error -> { + BatchListState( + data = emptyList(), + status = PaginationStatus.InitialLoadingError( + throwable = res.throwable, + ), + ) + } + } + + lastRequestResult.value = res + } + + private suspend fun loadMoreTask(action: BatchAction.LoadMore) { + val status = state.value.status + + // Skip the action if the state is not ready to continue pagination. + // Two options are acceptable: + // 1. The Source is ready to load next page with the same or different request params. + // 2. The Source has reached the end of pagination, but there is another request + // that can possibly load the next page and continue the pagination + + if (status !is PaginationStatus.Paginating && status !is PaginationStatus.EndOfPagination) return + if (status is PaginationStatus.EndOfPagination && action.requestParams == null) return + + val lastResult = lastRequestResult.value ?: return + + state.update { it.copy(status = PaginationStatus.NextBatchLoading) } + + val res = runCatching { + batchFetcher.fetchNext(action.requestParams, lastResult) + }.getOrElse { BatchFetchResult.Error(it) } + + lastRequestResult.value = lastResult + + state.update { currentState -> + when (res) { + is BatchFetchResult.Success -> { + val newBatch = if (res.empty.not()) { + Batch( + key = generateNewKey(currentState.data.map { it.key }), + data = res.data, + ) + } else { + null + } + + currentState.copy( + data = newBatch?.let { currentState.data + it } ?: currentState.data, + status = if (res.last) { + PaginationStatus.EndOfPagination + } else { + PaginationStatus.Paginating(res) + }, + ) + } + is BatchFetchResult.Error -> { + currentState.copy( + status = PaginationStatus.Paginating(res), + ) + } + } + } + } + + private suspend fun updateBatchesTask(action: BatchAction.UpdateBatches) { + if (updateFetcher == null) return + + val batches = state.value.data + val batchesToUpdate = batches.filter { action.keys.contains(it.key) } + + val result = try { + updateFetcher.fetchUpdate( + toUpdate = batchesToUpdate, + updateRequest = action.updateRequest, + ) + } catch (t: Throwable) { + BatchUpdateResult.Error(t) + } + + currentCoroutineContext().ensureActive() + + if (result is BatchUpdateResult.Success) { + state.update { currentState -> + val resMap = result.data.associateBy { it.key } + currentState.copy( + data = currentState.data.map { + resMap[it.key] ?: it + }, + ) + } + } + + updateResults.emit(action.updateRequest to result) + } + + private suspend fun updateBatchesAsyncTask(action: BatchAction.UpdateBatches) { + if (updateFetcher == null) return + + val batches = state.value.data + val batchesToUpdate = batches.filter { action.keys.contains(it.key) } + + val updateContext = UpdateContext(request = action.updateRequest, action.keys) + + with(updateFetcher) { + runCatching { + updateContext.fetchUpdateAsync(batchesToUpdate, action.updateRequest).also { + currentCoroutineContext().ensureActive() + } + }.getOrElse { + updateResults.emit(action.updateRequest to BatchUpdateResult.Error(it)) + } + } + } + + @Suppress("FunctionNaming") + private fun UpdateContext(request: TUpdate, keysToUpdate: Set) = + object : BatchUpdateFetcher.UpdateContext { + + override suspend fun update(update: List>.() -> BatchUpdateResult) { + currentCoroutineContext().ensureActive() + + val stateToFetchUpdateBasedOn = state.value.data.filter { + keysToUpdate.contains(it.key) + } + + val result = runCatching { + stateToFetchUpdateBasedOn.update() + }.getOrElse { + BatchUpdateResult.Error(it) + } + + if (result is BatchUpdateResult.Success) { + state.update { currentState -> + val resMap = result.data.associateBy { it.key } + currentState.copy( + data = currentState.data.map { + resMap[it.key] ?: it + }, + ) + } + } + + updateResults.emit(request to result) + } + } + + private fun updateInProgressExists(operationId: String): Boolean { + return updateAsyncJobs.value.any { it.first.operationId == operationId } || + updateJobs.value.any { it.first.operationId == operationId } || + waitingUpdateJobs.value.any { it.first.operationId == operationId } + } + + private fun resetState() { + if (updateFetcher != null) { + stopAllUpdates() + } + loadMoreActionJob?.cancel() + loadMoreActionJob = null + reloadActionJob?.cancel() + reloadActionJob = null + lastRequestResult.value = null + state.value = BatchListState(emptyList(), PaginationStatus.None) + } + + private fun stopAllUpdates() { + updateAsyncJobs.update { actionAsyncJobs -> + actionAsyncJobs.forEach { + it.second.cancel() + } + emptyList() + } + + updateJobs.update { actionJobs -> + waitingUpdateJobs.update { waitingActionJobs -> + waitingActionJobs.forEach { + it.second.cancel() + } + emptyList() + } + actionJobs.forEach { + it.second.cancel() + } + emptyList() + } + } + + private fun stopUpdates(predicate: (BatchAction.UpdateBatches) -> Boolean) { + updateAsyncJobs.update { actionAsyncJobs -> + actionAsyncJobs.mapNotNull { + if (predicate(it.first)) { + it.second.cancel() + null + } else { + it + } + } + emptyList() + } + + updateJobs.update { actionJobs -> + waitingUpdateJobs.update { waitingActionJobs -> + waitingActionJobs.mapNotNull { + if (predicate(it.first)) { + it.second.cancel() + null + } else { + it + } + } + } + actionJobs.mapNotNull { + if (predicate(it.first)) { + it.second.cancel() + null + } else { + it + } + } + } + } + + private fun CoroutineScope.launchFetch( + start: CoroutineStart = CoroutineStart.DEFAULT, + block: suspend CoroutineScope.() -> Unit, + ): Job { + return launch(context = fetchDispatcher + SupervisorJob(), start = start, block = block) + } +} \ No newline at end of file diff --git a/core/pagination/src/main/java/com/tangem/pagination/BatchListSourceFlow.kt b/core/pagination/src/main/java/com/tangem/pagination/BatchListSourceFlow.kt new file mode 100644 index 0000000000..258a20b8d0 --- /dev/null +++ b/core/pagination/src/main/java/com/tangem/pagination/BatchListSourceFlow.kt @@ -0,0 +1,17 @@ +package com.tangem.pagination + +import kotlinx.coroutines.flow.SharedFlow +import kotlinx.coroutines.flow.StateFlow + +fun BatchListSource.toBatchFlow() = + object : BatchFlow { + override val state: StateFlow> + get() = this@toBatchFlow.state + override val updateResults: SharedFlow>> + get() = this@toBatchFlow.updateResults + } + +interface BatchFlow { + val state: StateFlow> + val updateResults: SharedFlow>> +} \ No newline at end of file diff --git a/core/pagination/src/main/java/com/tangem/pagination/BatchListState.kt b/core/pagination/src/main/java/com/tangem/pagination/BatchListState.kt new file mode 100644 index 0000000000..b53ba23dc0 --- /dev/null +++ b/core/pagination/src/main/java/com/tangem/pagination/BatchListState.kt @@ -0,0 +1,17 @@ +package com.tangem.pagination + +/** + * State that is used for listening the current state of a pagination. + * + * @param TKey type of the key of the batch. + * @param TData type of the data. + * + * @property data list of loaded batches. + * @property status current status of the pagination. + * + * @see BatchListSource + */ +data class BatchListState( + val data: List>, + val status: PaginationStatus, +) \ No newline at end of file diff --git a/core/pagination/src/main/java/com/tangem/pagination/BatchUpdateFetcher.kt b/core/pagination/src/main/java/com/tangem/pagination/BatchUpdateFetcher.kt new file mode 100644 index 0000000000..f53deb4449 --- /dev/null +++ b/core/pagination/src/main/java/com/tangem/pagination/BatchUpdateFetcher.kt @@ -0,0 +1,63 @@ +package com.tangem.pagination + +/** + * Interface for fetching updates for a batch of data. + * Used in [BatchListState]. + * + * @param TKey type of the key. + * @param TData type of the data. + * @param TUpdate type of the update request. + */ +interface BatchUpdateFetcher { + + /** + * Fetches updates for a batch of data. + * Note that the result batch key as a result of executing the method must be presented in the [toUpdate] list, + * otherwise, updates will not be performed + * + * @param toUpdate list of batches to update. + * @param updateRequest request to update the data. + * @return result of the update operation. + */ + suspend fun fetchUpdate( + toUpdate: List>, + updateRequest: TUpdate, + ): BatchUpdateResult = BatchUpdateResult.Error(NotImplementedError()) + + /** + * Fetches updates for a batch of data asynchronously. + * To update the data, use the [UpdateContext.update] method. + * [UpdateContext.update] could be called as many times as you want. + * + * Note that the result batch key as a result of executing the method must be presented in the [toUpdate] list, + * otherwise, updates will not be performed. + * + * @param toUpdate list of batches to update. **Attention** Data may be outdated and should be used only to make + * a request for an update, not for the actual update operation. For the actual update operation, use the batches + * provided by [UpdateContext.update]. + * @param updateRequest request to update the data. + */ + suspend fun UpdateContext.fetchUpdateAsync( + toUpdate: List>, + updateRequest: TUpdate, + ) { + } + + /** + * Context for updating the data. + * Used by [BatchListSource] to provide a way to update batches by [fetchUpdateAsync] method. + */ + interface UpdateContext { + + /** + * Updates the data of the batch. + * Could be called as many times as you want. + * + * Input batches keys and the data could not always be the same as the keys of the [toUpdate] list in + * [fetchUpdateAsync] method, but the provided set of keys will always be a subset of the [toUpdate] list. + * + * @param update lambda to update the data. + */ + suspend fun update(update: List>.() -> BatchUpdateResult) + } +} \ No newline at end of file diff --git a/core/pagination/src/main/java/com/tangem/pagination/BatchUpdateResult.kt b/core/pagination/src/main/java/com/tangem/pagination/BatchUpdateResult.kt new file mode 100644 index 0000000000..c2e00fad9c --- /dev/null +++ b/core/pagination/src/main/java/com/tangem/pagination/BatchUpdateResult.kt @@ -0,0 +1,27 @@ +package com.tangem.pagination + +/** + * Represents the result of a batch fetch operation. + * Used in [BatchListState] and [BatchUpdateFetcher]. + * + * @param TKey type of the key. + * @param TData type of the data. + */ +sealed class BatchUpdateResult { + + /** + * Represents a successful result of a batch update operation. + * + * @param data fetched data. + */ + data class Success( + val data: List>, + ) : BatchUpdateResult() + + /** + * Represents an error result of a batch update operation. + * + * @param error error that occurred during the operation. + */ + class Error(val throwable: Throwable) : BatchUpdateResult() +} \ No newline at end of file diff --git a/core/pagination/src/main/java/com/tangem/pagination/BatchingContext.kt b/core/pagination/src/main/java/com/tangem/pagination/BatchingContext.kt new file mode 100644 index 0000000000..252d6f1680 --- /dev/null +++ b/core/pagination/src/main/java/com/tangem/pagination/BatchingContext.kt @@ -0,0 +1,22 @@ +package com.tangem.pagination + +import kotlinx.coroutines.CoroutineScope +import kotlinx.coroutines.flow.Flow + +/** + * Context for working with [BatchListSource]. + * + * @param TRequestParams type of the request. + * @param TKey type of the key. + * @param TUpdate type of the update request. + * + * @property actionsFlow flow of [BatchAction]s that would be dispatched to [BatchListSource]. + * @property coroutineScope scope for the [BatchListSource] to launch coroutines. When it is cancelled, + * all the operations and requests launched in the [BatchListSource] would be cancelled and all data would be cleared. + * + * @see BatchListSource + */ +class BatchingContext( + val actionsFlow: Flow>, + val coroutineScope: CoroutineScope, +) \ No newline at end of file diff --git a/core/pagination/src/main/java/com/tangem/pagination/PaginationStatus.kt b/core/pagination/src/main/java/com/tangem/pagination/PaginationStatus.kt new file mode 100644 index 0000000000..5e30875c6a --- /dev/null +++ b/core/pagination/src/main/java/com/tangem/pagination/PaginationStatus.kt @@ -0,0 +1,55 @@ +package com.tangem.pagination + +/** + * Status of the pagination. + * + * @param TData type of the data. + * + * @see BatchListState + */ +sealed class PaginationStatus { + + /** + * Represents that there is no data. Used when the list of batches is empty. + * The initial state of the pagination. + */ + data object None : PaginationStatus() + + /** + * Represents that the batch is loading for the first time. + * Used when the pagination is empty and the first batch is being loaded. + */ + data object InitialLoading : PaginationStatus() + + /** + * Represents that the first batch was loaded with an error. + * + * @param error error that occurred during the initial loading. + */ + data class InitialLoadingError( + val throwable: Throwable, + ) : PaginationStatus() + + /** + * Represents that the last batch was loaded and + * the source is ready to load the next one or reload previous if [lastResult] is an error. + * For the first batch, [lastResult] is always [BatchFetchResult.Success] + * + * @param lastResult result of the last batch fetch. + */ + data class Paginating( + val lastResult: BatchFetchResult, + ) : PaginationStatus() + + /** + * Represents that the next batch is loading. + * Used when the next batch is being loaded. + */ + data object NextBatchLoading : PaginationStatus() + + /** + * Represents that the source has no more batches to load. + * The next [BatchAction.LoadMore] with [BatchAction.LoadMore.requestParams] = null will be ignored. + */ + data object EndOfPagination : PaginationStatus() +} \ No newline at end of file diff --git a/core/pagination/src/main/java/com/tangem/pagination/exception/EndOfPaginationException.kt b/core/pagination/src/main/java/com/tangem/pagination/exception/EndOfPaginationException.kt new file mode 100644 index 0000000000..f2cc69767a --- /dev/null +++ b/core/pagination/src/main/java/com/tangem/pagination/exception/EndOfPaginationException.kt @@ -0,0 +1,6 @@ +package com.tangem.pagination.exception + +/** + * Exception that is thrown when there are no more items to fetch. + */ +class EndOfPaginationException : IllegalStateException() \ No newline at end of file diff --git a/core/pagination/src/main/java/com/tangem/pagination/exception/OperationWIthTheSameIdInProgress.kt b/core/pagination/src/main/java/com/tangem/pagination/exception/OperationWIthTheSameIdInProgress.kt new file mode 100644 index 0000000000..5cf81ea1cd --- /dev/null +++ b/core/pagination/src/main/java/com/tangem/pagination/exception/OperationWIthTheSameIdInProgress.kt @@ -0,0 +1,5 @@ +package com.tangem.pagination.exception + +class OperationWIthTheSameIdInProgress(operationId: String) : RuntimeException( + "Operation is already in progress - id:$operationId ", +) \ No newline at end of file diff --git a/core/pagination/src/main/java/com/tangem/pagination/fetcher/BatchFetcher.kt b/core/pagination/src/main/java/com/tangem/pagination/fetcher/BatchFetcher.kt new file mode 100644 index 0000000000..818620dab1 --- /dev/null +++ b/core/pagination/src/main/java/com/tangem/pagination/fetcher/BatchFetcher.kt @@ -0,0 +1,36 @@ +package com.tangem.pagination.fetcher + +import com.tangem.pagination.BatchFetchResult +import com.tangem.pagination.BatchListState + +/** + * Interface for fetching a batch of data. Used in [BatchListState]. + * + * @param TRequestParams type of the request. + * @param TData type of the data. + * + * @see BatchListState + */ +interface BatchFetcher { + + /** + * Fetches the first batch of data. + * + * @param requestParams initial request params. Will be saved to be used in [fetchNext] requests. + * @return result of the fetch operation. + */ + suspend fun fetchFirst(requestParams: TRequestParams): BatchFetchResult + + /** + * Fetches the next batch of data. + * + * @param overrideRequestParams overrides current remembered request, even if that fetch fails. + * If null, the last request should be used. + * @param lastResult result of the last fetch operation. + * @return result of the fetch operation. + */ + suspend fun fetchNext( + overrideRequestParams: TRequestParams?, + lastResult: BatchFetchResult, + ): BatchFetchResult +} \ No newline at end of file diff --git a/core/pagination/src/main/java/com/tangem/pagination/fetcher/LimitOffsetBatchFetcher.kt b/core/pagination/src/main/java/com/tangem/pagination/fetcher/LimitOffsetBatchFetcher.kt new file mode 100644 index 0000000000..73a2c5f0a7 --- /dev/null +++ b/core/pagination/src/main/java/com/tangem/pagination/fetcher/LimitOffsetBatchFetcher.kt @@ -0,0 +1,90 @@ +package com.tangem.pagination.fetcher + +import com.tangem.pagination.BatchFetchResult +import com.tangem.pagination.exception.EndOfPaginationException +import kotlinx.coroutines.currentCoroutineContext +import kotlinx.coroutines.ensureActive +import kotlinx.coroutines.flow.MutableStateFlow + +/** + * Fetcher that uses limit and offset to fetch data. + * + * @param TRequestParams type of the request params. + * @param TData type of the data. + * + * @property prefetchDistance number of items to fetch for the first batch. + * @property batchSize size of the batch. + * @property subFetcher function that fetches the data. + */ +class LimitOffsetBatchFetcher( + private val prefetchDistance: Int, + private val batchSize: Int, + private val subFetcher: SubFetcher, +) : BatchFetcher { + + data class Request( + val limit: Int, + val offset: Int, + val params: TRequestParams, + ) + + fun interface SubFetcher { + suspend fun fetch( + request: Request, + lastResult: BatchFetchResult?, + isFirstBatchFetching: Boolean, + ): BatchFetchResult + } + + private val lastRequest = MutableStateFlow?>(null) + + override suspend fun fetchFirst(requestParams: TRequestParams): BatchFetchResult { + val req = Request( + offset = 0, + limit = prefetchDistance, + params = requestParams, + ) + + val res = runCatching { + subFetcher.fetch(request = req, lastResult = null, isFirstBatchFetching = true) + }.getOrElse { + currentCoroutineContext().ensureActive() + BatchFetchResult.Error(it) + } + + lastRequest.value = req + return res + } + + override suspend fun fetchNext( + overrideRequestParams: TRequestParams?, + lastResult: BatchFetchResult, + ): BatchFetchResult { + val last = lastRequest.value + requireNotNull(last) + + val req = if (lastResult is BatchFetchResult.Success) { + if (lastResult.last && overrideRequestParams == null) { + return BatchFetchResult.Error(EndOfPaginationException()) + } + + Request( + offset = last.offset + last.limit, + limit = batchSize, + params = overrideRequestParams ?: last.params, + ) + } else { + last + } + + val res = runCatching { + subFetcher.fetch(request = req, lastResult = lastResult, isFirstBatchFetching = false) + }.getOrElse { + currentCoroutineContext().ensureActive() + BatchFetchResult.Error(it) + } + + lastRequest.value = req + return res + } +} \ No newline at end of file diff --git a/core/res/src/main/res/values-de/strings-blockchain.xml b/core/res/src/main/res/values-de/strings-blockchain.xml index 82986f8529..adea1fc8ea 100644 --- a/core/res/src/main/res/values-de/strings-blockchain.xml +++ b/core/res/src/main/res/values-de/strings-blockchain.xml @@ -1,10 +1,18 @@ + Standard + Altbestand Erhalt der Gebühr fehlgeschlagen - Senden Sie Geld an diese Andresse um ein Konto zu erstellen + Aufgrund der Beschränkungen von %1$s können nur %2$d UTXOs in eine einzige Transaktion passen. Das bedeutet, dass du nur %3$s oder weniger senden kannst. Du musst den Betrag reduzieren. + Nicht genug Geld für die Transaktion. Bitte lade dein Konto auf. + Es ist ein Fehler aufgetreten. Code: %s. + Um das %1$s -Netzwerk nutzen zu können, must du die Kontoreserve ( %2$s %3$s ) bezahlen, die diesen Betrag auf unbestimmte Zeit sperrt und verbirgt + Das Zielkonto ist nicht aktiv. Sende %s oder mehr, um das Konto zu aktivieren. + Senden Sie Geld an diese Andresse um ein Konto zu erstellen Minimaler Betrag ist %s - Restbestand zu klein + Die Veränderung ist zu gering Falsche Gebühr + Mindestguthaben ist %s Das Zielkonto ist nicht erstellt. Der abzusendende Betrag soll %s + Gebühr oder mehr sein Unbekannter Fehler Der Betrag geht über die Bilanz hinaus @@ -12,6 +20,6 @@ Die Gebühr geht über die Bilanz hinaus Der Gesamtbetrag geht über die Bilanz hinaus Nein, alles senden - Um %s XTZ reduzieren + Um %s XTZ reduziert Damit Sie beim nächsten Aufladen Ihrer Brieftasche keine erhöhte Provision zahlen, soll der Betrag um %s XTZ reduziert werden diff --git a/core/res/src/main/res/values-de/strings.xml b/core/res/src/main/res/values-de/strings.xml index 559c09d33c..0123a1dfdd 100644 --- a/core/res/src/main/res/values-de/strings.xml +++ b/core/res/src/main/res/values-de/strings.xml @@ -1,59 +1,896 @@ + Netzwerk wählen + Benutzerdef. Token hinzuf. + Token verwalten + Sende nur %1$s ( %2$s ) vom %3$s -Netzwerk an diese Adresse. Die Verwendung anderer Token und Netzwerke kann zum Verlust von Geldern führen. + So scannt man + Hilfe anfordern + Erneut versuchen + Diese Funktion ist im Demomodus deaktiviert + Ursache: %s + Transaktion kann nicht gesendet werden + Das gewählte unterstützt nicht das %1$s Netzwerk + Um die kryptografische Verschlüsselung der %1$s Blockchain zu aktivieren, musst Du die Wallet auf die Werkseinstellungen zurücksetzen. Bitte heb vorher dein Guthaben ab, um sicherzustellen, dass du nichts verlierst, und führe dann den Reset-Vorgang durch. Nach dem Zurücksetzen ist der Zugriff auf die aktuelle Wallet nicht mehr möglich. + Tokens im %1$s -Netzwerk werden von dieser Karte aufgrund einer Firmware-Einschränkung nicht unterstützt. + Hast du Probleme beim Scannen deiner Karte? Diese Karte ist für die Zusammenarbeit mit Tangem nicht geeignet + Standardgebühr + Aktiviere die Option Standardgebühr, um die Transaktionsgebühren automatisch festzulegen und die Gebührenseite beim Senden von Geldern zu überspringen. Du kannst bei Bedarf jederzeit zu dieser Seite zurückkehren. + Gehe zu den Einstellungen, um die biometrische Authentifizierung in der Tangem-App zu aktivieren + Biometrische Authentifizierung aktivieren + Dadurch werden alle gespeicherten Zugangscodes für die Wallet gelöscht. Jede weitere Operation mit der Wallet erfordert die Übermittlung des Zugangscodes. + Durch das Entfernen der gespeicherten Karte werden alle gespeicherten Wallets und deren Zugangscodes aus der App gelöscht. + Zugangscode speichern + Bei Interaktionen mit deiner Karte wird anstelle des Zugangscodes eine biometrische Authentifizierung abgefragt. + Behalte die Wallet in der App + Aktiviere die Verknüpfung aller Wallets mit der Tangem-App. Die biometrische Authentifizierung ist zum Entsperren der App erforderlich. Das Signieren von Transaktionen erfordert das Antippen deiner Tangem-Karte. + Dunkel + Hell + Systemstandard + Thema + App Einstellungen + Um deine Kontostände ein- oder auszublenden, flippe einfach das Display deines Geräts nach unten, oder schalte es in den Einstellungen aus. + Nicht mehr anzeigen + Verstanden + Guthaben sind ausgeblendet + Bitte Karte scannen + Bitte versuche es in 30 Sekunden erneut oder scanne die Karte + Zu viele Versuche + Du hast die biometrische Authentifizierung auf deinem Telefon deaktiviert und kannst keine Wallets in der App speichern. Um Wallets zu speichern, aktiviere bitte die biometrische Authentifizierung in deinen Telefoneinstellungen. + Backup-Prozess starten + Von deiner Fiat-Karte oder deinem Bankkonto + + %d Karte + %d Karten + + Deaktiviere diese Option, wenn du nicht möchtest, dass diese Karte zum Zurücksetzen von Zugangscodes auf anderen Karten in dieser Wallets verwendet wird. Bitte beachte, dass du dann auch den Zugangscode auf dieser Karte nicht zurücksetzen kannst. + Ermöglicht die Verwendung dieser Karte zum Zurücksetzen des Zugangscodes auf anderen Karten in dieser Brieftasche + Zugangscodes wiederherstellen + Zurücksetzen + Möchtest du das wirklich tun? + Zugangscode ändern + Der Zugangscode wird nur auf dieser Karte geändert + Alle Karten der ausgewählten Wallet wurden auf die Werkseinstellungen zurückgesetzt. Du kannst nun eine neue Wallet aufsetzen. + Komplett zurücksetzen + Möchtest du die nächste Karte in dieser Wallet zurücksetzen? + Karte zurücksetzen + Wir empfehlen dir, den Zurücksetzungsprozess für alle Karten in dieser Wallet abzuschließen + Du hast nicht alle deine Karten zurückgesetzt + Auf Werkseinstellungen zurücksetzen + Sicherheitsmodus + Karteneinstellungen + Zusätzlich zu den Netzwerkgebühren erhebt das Cardano-Netzwerk %1$s ADA bei Transaktionen mit dem Token %2$s + Cardano-Transaktionsanforderungen + Um eine %1$s Transaktion durchzuführen, musst du einen gewissen ADA-Betrag einzahlen, um die Netzwerkgebühr und den ADA-Mindestwert zu decken (5 ADA werden empfohlen). + Nicht genügend ADA für die Tokenübertrag + Du musst einige ADA verwalten, weil du einige Token auf der Cardano-Blockchain besitzt + Nicht genug ADA Akzeptieren + Zugang verweigert + Alle + Erlauben + Anwenden + Genehmigung + Genehmigen + Achtung Bilanz: %s - Sie haben keinen Zugang zur Kamera erteilt, bitte passen Sie Ihre Datenschutzeinstellungen an + Saldo + biometrische Authentifizierung + biometrische Daten + Kaufen + Gehe zu %1$s + D hast keinen Zugang zur Kamera erteilt, bitte passe deine Datenschutzeinstellungen an Abbrechen + Stakingbelohnungen beanstpruchen + Schließen + Weiter + Kopieren + Adresse kopieren + Erstellen + Benutzerdef. + + %d tag + %d tage + Entfernen + Deaktiviert Erledigt + Aktivieren + Aktiviert Fehler + Erkunden + Transaktionsverlauf einsehen + Explorer Gebühr + Netzwerkgebühren sind Gebühren, die Nutzer für die Verarbeitung und Bestätigung von Transaktionen zahlen. Die Höhe der Gebühren kann von der Überlastung des Netzes, der Größe der Transaktion und der Ausführungspriorität abhängen. %s + Schnell + Markt + Langsam + Gebühren + Adressen abrufen + Zum Anbieter gehen + Zum Token + Importieren + Später + Gesperrt + Hauptnetz Netzgebühr + Der überwiesene Betrag wird um %1$s (%2$s) gekürzt, um die gewählte Gebührenhöhe zu decken. + Weiter + Nein + Keine Adresse + Jetzt OK + Primär Karte + Passphrase + Einfügen + %1$s-%2$s + Weiterlesen + Empfangen + Ablehnen + Neu laden + Umbenennen + Speichern Änderungen speichern - Absenden - Erfolg + Suchen + Token suchen + Seed phrase + Aktion auswählen + Verkaufen + Senden + Der Server ist nicht verfügbar. Bitte versuche es später erneut. + Teilen + Signieren + Signieren und senden + Staken + Staking + Start + Einreichen + Erfolgt + Unterstützung + Tauschen + Allgemeine Geschäftsbedingungen + Heute + Transaktion fehlgeschlagen + Transaktionen + Überweisung + Ich verstehe + Es ist ein Fehler aufgetreten. Bitte versuche es erneut. + Nicht erreichbar + staking beenden + Ja + Vertragsadresse kopiert! + Verfügbare Netzwerke + Token hinzufügen + Vertragsadresse + Vertragsadresse ist ungültig + Bitte wähle das Netzwerk + Dezimalzahl muss eine gültige Ganzzahl sein, bis zu %li + Benutzerdefinierte Ableitung(derivation) + E. g. m/00\'/0000\'/0\'/0/0 + Benutzerdefinierte Ableitung (Derivation) eingeben + Dezimalstellen + Ableitungspfad (Derivation Path) + Standard + BIP44 Coin Type + Der von dir eingegebene Ableitungspfad(derivation path) ist ungültig + Z.B. USD-Coin + Name + Nicht ausgewählt + Netzwerk + Token-Netzwerk + Du kannst einen Token, der von Tangem nicht unterstützt wird, manuell hinzufügen + Z.B. USDC + Symbol + Token-Symbol + Dieses Token/Netzwerk wurde bereits zu deiner Liste hinzugefügt + Beachte, dass Token von jedem erstellt werden können. Achte darauf, keine Betrugstoken hinzuzufügen, diese können kostenlos sein. + Sei vorsichtig beim Hinzufügen von SCAM-Token, sie können nichts kosten + Beachten, dass Token von jedem erstellt werden können + Kaufe eine Tangem Wallet + Chat Zugangscode - Sie müssen den richtigen Zugangscode eingeben, bevor Sie die Karte scannen. + Du musst den richtigen Zugangscode eingeben, bevor du die Karte scannst. Langes Tippen Dieser Mechanismus schützt vor Annäherungsangriffen auf eine Karte. Es wird eine Verzögerung zwischen dem Empfang und der Ausführung eines Befehls erzwungen. Nach der ersten signierten Transaktion wird dieses Telefon mit der Karte verknüpft und die Transaktionen werden sofort signiert Passcode - Bevor Sie einen Befehl ausführen, der eine Änderung des Kartenstatus zur Folge hat, müssen Sie den Passcode eingeben. + Bevor du einen Befehl ausführst, der eine Änderung des Kartenstatus zur Folge hat, musst du den Passcode eingeben. + Empfehlungsprogramm + Flippe den Bildschirm deines Geräts nach unten, um Salden schnell ein- und auszublenden %s Hasch KartenID + Kontakt zum Support + Weitere Karten verknüpfen App Währung - Emittent + Flipp um Guthaben auszublenden + Aussteller Signiert + Gib uns eine Rückmeldung Details + Überprüfe deine Internetverbindung oder wechseln zu einem anderen Netzwerk Nutzungsbedingungen + Du hast eine Karte aus einer anderen Wallet verwendet. Tippe auf die Karte, die dieser Wallet zugeordnet ist. + Meine Token + Du hast noch keine Token hinzugefügt. Füge Token über den Markt zum Tausch hinzu + Kann nicht gegen %s ausgetauscht werden + Bereitgestellt von + Status + Tangem bietet Token-Swaps über Drittanbieter gemäß den jeweiligen Bedingungen des jeweiligen Anbieters an. + Anbieter wählen + Es ist ein Fehler aufgetreten. Code: %s + Huch! Der Tausch des ausgewählten Paares über den gewählten Anbieter ist vorübergehend nicht möglich. Bitte versuche es später erneut. (Code: %s) + Der gewählte Anbieter ist im Moment nicht verfügbar. Bitte versuche es später noch einmal. (Code: %s) + Swaps sind im Moment nicht verfügbar. Bitte versuche es später noch einmal. (Code: %s) + Geschätzter Betrag + Getauscht von %s + Besuche die Website des Anbieters, um dein Geld zurückzuerhalten + Fehler beim Vorgang durch Anbieter + Der Transaktionsbetrag wurde aufgrund von OKX- oder Bridge-Regeln in %1$s auf deine Wallet zurückerstattet. %2$s + Der Betrag wurde in %1$s (%2$s Netzwerk) zurückerstattet. + Besuche die Website des Anbieters zur Überprüfung + KYC-Überprüfung durch den Anbieter erforderlich + Abgebrochen + Bestätigt + Bestätigen + wird bestätigt... + Getauscht + Tauschen läuft + Austauschen... + Fehlgeschlagen + Einzahlung empfangen + Einzahlung wird erwartet + Warten auf Einzahlung... + Rückerstattet + An dich gesendet + wird an dich versendet... + Gesendet + Daten stammen vom Anbieter. Der geschätzte Betrag kann sich aufgrund der Marktbedingungen ändern. + Status des Tausches + Verifizierung erforderlich + Wartet auf Transaktions-Hash + Liste aller Token, die deiner Wallet hinzugefügt wurden + Beste Preise werden abgerufen … + Variabler Zinssatz + Durch die Nutzung der Swap-Funktion erklärst du dich mit den folgenden Bedingungen des Anbieters einverstanden %s + Durch die Nutzung der Swap-Funktionalität erklärst du dich mit des Anbieters %1$s und %2$s einverstanden + Weitere Anbieter werden bald folgen.\nBleib dabei! + Datenschutzbestimmungen + Anbieter + Bester Preis + Verfügbar bis zu %s + Erhältlich bei %s + Für dieses Paar nicht verfügbar + Erlaubnis erforderlich + Empfohlen + Nutzungsbedingungen + Keine Token gefunden. Bitte versuche eine andere Anfrage + ID: %s + Transaktions-ID kopiert + Aus einer anderen Währung in deiner Wallet + Die folgenden Angaben sind freiwillig. Du kannst diese löschen, wenn du sie nicht weitergeben möchtest. + Teile uns mit, welche Funktionen du vermisst, und wir werden versuchen, dir zu helfen. + Bitte sag uns, welche Karte du hast + Hallo Support-Team, + Bitte erzähle uns mehr über dein Problem. Jedes kleine Detail kann helfen. + Meine Vorschläge + Kann eine Karte nicht scannen + Rückmeldung + Feedback zu Tangem + Eine Transaktion kann nicht gesendet werden + Aktuelle Transaktion + Das Netzwerk erhebt eine Token-Genehmigungsgebühr, um zu überprüfen, ob Sie die Verwendung Ihres Tokens für den Swap genehmigen. + Gib das Genehmigungslimit für das ausgewählte Token an + Betrag %s + Die Genehmigungsfunktion ist erforderlich, um einer anderen Adresse die Berechtigung zur Verwendung einer bestimmten Menge Ihrer Token zu erteilen. Standardmäßig können Smart Contracts nicht auf deine Token zugreifen, es sei denn, du stimmen zu. Indem du deine Token \"freischaltest\", autorisierst du den StakeKit Smart Contract, sie zu verwenden. Die Miner des Netzwerks erhalten eine Gasgebühr (von dir bezahlt), um diese Aktion in der Blockchain aufzuzeichnen. Du kannst deine Token einsetzen, nachdem du die Genehmigung erteilt hast. + Um fortzufahren, musst du StakeKit Smart Contract erlauben, deine %s zu verwenden + Um fortzufahren, erteile %1s Smart Contracts die Berechtigung, dein zu %2s verwenden. + Erlaubnis erteilen + Unbegrenzt + Karte bestellen Karte scannen - Tippen Sie um den Zugangscode zu ändern - Tippen Sie um den Passcode zu ändern + Um den Zugangscode zu ändern, halte die Karte wie oben gezeigt an das Gerät und entferne sie erst am Ende des Vorgangs. + Um den Passcode zu ändern, halte die Karte wie oben gezeigt an das Gerät und entferne sie erst am Ende des Vorgangs. + Um die Wallet zu erstellen, halte die Karte wie oben gezeigt an das Gerät und entferne sie erst am Ende des Vorgangs. + Halte deine Karte Nr. %s des Sets an dein Smartphone Legen Sie die Karte zum Scannen an Tippen um zu signieren - Legen Sie die Karte an - Ein wallet erstellen + Lege die Karte an + Du hast deine biometrischen Daten aktualisiert, scanne deine Karte, um einzutreten + Dein Guthaben sollte höher sein als der Gebührenwert, um eine Überweisung zu tätigen + Unzureichende Mittel + Du hast nicht genug Mana für diese Transaktion. Bitte warte, bis das Mana wieder aufgefüllt ist. Dein Mana-Guthaben beträgt %1$s/%2$s + Nicht genug Mana + Du kannst nur %s übertragen, da das Koinos-Netzwerk ein Mana-Limit vorgibt. + Mana-Limit + Das Koinos-Netzwerk benötigt Mana als Netzwerkgebühr. Du hast %1$s/%2$s Mana + Mana-Level + Um mit der Verfolgung deiner Krypto-Assets und -Transaktionen zu beginnen, füge einen Token hinzu + Token verwalten + Um auf alle Netzwerke zugreifen zu können, musst du die Karte scannen + Scanne deine Karte + Genießen %1$s Servicegebühren auf Swaps über Changelly von Februar %2$s-%3$s + Swap mit Changelly, %s Gebühren + Token + Hinzufügen + Bearbeiten + \nCoinMarketCap + Blockchain, auf der die Kryptowährung ursprünglich erstellt wurde + Natives Netzwerk + Die Verwendung von nicht nativen Netzwerken für Token ermöglicht eine blockchainübergreifende Interoperabilität, sodass Vermögenswerte in verschiedenen dezentralen Anwendungen und Smart Contracts plattformübergreifend genutzt werden können. Dies erfordert jedoch häufig eine Verwahrstelle oder einen intelligenten Vertrag, um den ursprünglichen Vermögenswert sicher zu verwahren, was zu einer Zentralisierung und einem Kontrahentenrisiko führt. + Nicht die ursprüngliche oder primäre Blockchain, in der der Token gehostet wird + Nicht-native Netzwerke + Netzwerke auswählen + Wallet + Dieses Token konnte nicht gefunden werden. Du kannst ihn manuell hinzufügen. + + %1$d von %2$d Wallet + %1$d von %2$d Wallets + + Entfernen + z.B. BTC vertraue ich, hodl muss ich + Dein Portfolio wurde aktualisiert + Der ausgewählte Token ist derzeit nicht für Aktionen innerhalb der Krypto-Wallet verfügbar. Aber keine Sorge, du kannst dein Interesse bekunden, indem du den Token hochstufen. + Hochstimmen + Wallet auswählen + Das Wallet unterstützt nicht mehr als ein Netzwerk + Um mit dem Kauf, Tausch oder Erhalt dieses Vermögenswerts zu beginnen, füge diesen Token zu mindestens 1 Netzwerk hinzu + Dieses Asset ist nicht verfügbar + Zum Portfolio hinzufügen + Token hinzufügen + Verfügbare Netzwerke + Mein Portfolio + Markt + Um Adressen für ausgewählte Netzwerke zu generieren, musst du eine Tangem-Karte scannen/ einsetzen + Die Daten konnten nicht geladen werden... + Schnelle Aktionen + Ergebnis + Token unter 100k Marktkapitalisierung anzeigen + Token anzeigen + Kein Ergebnis + Netzwerk auswählen + Wallet auswählen + 1M + 1 Y + 24H + 3M + 6M + 7T + Alle + Erfahrene Käufer + Bewertung + Sortieren nach + Top-Gewinner + Top-Verlierer + Beliebt + Über %s + + Bewertung, basierend auf %d + Bewertungen, basierend auf %d + + Blockchain-Site + Kaufdruck + Die Differenz zwischen Käufer- und Verkäufervolumen + Umlaufmenge + Die Gesamtzahl der Coins, die für den Handel verfügbar sind und auf dem Markt zirkulieren + Erfahrene Käufer + Nettokäufer mit der zusätzlichen Anforderung, mindestens 100 ausgehende Transaktionen zu haben + Vollständig verwässerte Bewertung + Der theoretische Gesamtwert einer Kryptowährung, wenn alle Coins, die existieren könnten, im Umlauf sind, einschließlich derjenigen, die derzeit nicht im Umlauf sind + Entstehungsdatum + Leer + Hoch + Inhaber/ Halter + Die Änderung der Anzahl der Token-Inhaber innerhalb eines bestimmten Zeitraums + Einblicke + Links + Liquidität + Die Änderung der Liquidität, die dem Token während des angegebenen Zeitraums zur Verfügung steht + Liquiditätsindex + Leer + Niedrig + Marktkapitalisierung + Der Gesamtmarktwert einer Kryptowährung, berechnet durch Multiplikation des aktuellen Preises der Münze mit der Gesamtzahl der im Umlauf befindlichen Münzen + Marktbewertung + Position im Krypto-Rating zwischen allen Coins basierend auf der Marktkapitalisierung + Maximale Versorgung + Leer + Metriken + Offizielle Links + Preisleistung + Aufbewahrungsort + Sicherheitsbewertung + Leer + Soziales + Gesamtangebot + Die maximale Anzahl von Coins oder Tokens, die jemals für eine bestimmte Kryptowährung existieren können + Handelsvolumen (24h) + Der Gesamtbetrag einer Kryptowährung, der innerhalb der letzten 24 Stunden gehandelt wurde, wobei das Aktivitäts- und Liquiditätsniveau auf dem Markt angegeben wird + Du musst einen einzigen Zugangscode einrichten, um alle deine Karten zu schützen + Schützen + Du kannst später auf jeder Karte einen individuellen Zugangscode einrichten + Personalisieren + Der Zugangscode kann mit einer verbundenen Karte wiederhergestellt werden. Bewahre nicht alle Karten an einem Ort auf. + Wiederherstellen + Wähle ein beliebiges Wort, eine Phrase oder eine Zahl als Zugangscode + Zugangscode erstellen + Gib deinen Zugangscode ein weiteres Mal ein, um einen Fehler zu vermeiden + Gebe deinen Zugangscode erneut ein + Der Zugangscode muss mindestens 4 Zeichen lang sein + Der eingegebene Zugangscode stimmt nicht mit dem ursprünglichen Zugangscode überein + Bitte wiederhole den Vorgang. Die Karte wird auf Werkseinstellungen zurückgesetzt. + Aktivierungsfehler + Token hinzufügen + Du hast eine Backup-Karte hinzugefügt. Wenn der Backup-Prozess abgeschlossen ist, kannst du keine weiteren Backup-Karten hinzufügen. Wenn du noch eine Karte hast, füge diese zum Backup hinzu. Möchtest du den Backup-Prozess fortsetzen? + Der Sicherungsvorgang ist teilweise abgeschlossen. Du kannst ihn jetzt nicht beenden. + Die Passphrase ist eine fortschrittliche Sicherheitsfunktion, die von Krypto-Wallets verwendet wird. Sie fügt ein zusätzliches Wort oder eine Phrase deiner Wahl zu der bereits bestehenden Wiederherstellungsphrase hinzu, um einen brandneuen Satz von Adressen zu erzeugen. + Hinzufügen einer Sicherungskarte + Scanne die Karte Nr. %d + Jetzt sichern + Scannen der Hauptkarte + Weiter zu meiner Wallet + Backup abschließen + Krypto empfangen + Primärkarte scannen + Für später überspringen + Wie funktioniert es? + Lass uns alle Schlüssel auf deiner Karte generieren und eine sichere Wallet erstellen + Ein Wallet erstellen + Erstelle eine Wallet + Andere Optionen + Deine Schlüssel(private-keys) werden sicher im Inneren der Karte generiert. Es gibt keine Seed-Phrase, d. h. niemand kann sie exportieren oder stehlen. + Schlüssel anonym generieren + Deine Karte ist aktiviert und einsatzbereit + Erfolgreich! + In diesem Fall musst du ganz von vorne anfangen. + Möchtest du den Aktivierungsprozess abbrechen? + Erste Schritte + Für die Karte, die du hinzufügen möchtest, wurde bereits eine andere Wallets erstellt. Wenn du Guthaben auf dieser Wallets hast, hebe es bitte ab, setze diese Karte zurück und füge sie als Backup hinzu. + Erstellen eines Backups + Lese mehr über die Seed-Phrase + + leer + Schreibe diese %d-Wörter in der unten angegebenen Reihenfolge auf und bewahre sie an einem sicheren und geheimen Ort auf. + + Deine Seed-Phrase + + leer + %d Wörter + + Um deine Wallets zu importieren, gib bitte deine Seed-Phrase in das folgende Feld ein + Seed-Phrase generieren + Wallet importieren + Eine Seed-Phrase ist eine Reihe von Wörtern, mit denen du deine Wallet wiederherstellen kannst. Im Gegensatz zu den von der Karte generierten Schlüsseln sind Seed-Phrasen ungeschützt und können kopiert und gestohlen werden. Die Verwendung dieser Option erfolgt auf eigene Gefahr. + Seed-Phrase verwenden + Ungültige Seed-Phrase. Bitte überprüfe die Wortreihenfolge. + Ungültige Seed-Phrase. Bitte überprüfe die Rechtschreibung. + veralteter Standard + Um zu überprüfen, ob du deine Seed-Phrase richtig aufgeschrieben hast, gib bitte das 2., 7. und 11 Wort ein. + Eine letzte Prüfung! + Um den Sicherungsvorgang zu starten, füge bis zu zwei Sicherungskarten hinzu. + Du kannst eine weitere Karte hinzufügen oder den Sicherungsvorgang abschließen + Bereite die Sicherungskarte mit der Nummer %s vor. + Scanne die primär-Karte, um den Sicherungsvorgang zu starten. + Bereite die primäre Karte mit der Nummer %s vor. + Deine Tangem-Karte ist konfiguriert und einsatzbereit. + Maximale Anzahl an Karten hinzugefügt. Schließe den Sicherungsvorgang ab. + Karte aktivieren + Sicherungskarte Nr. %d + Keine Sicherungskarten + Benachrichtigungen + Eine Backup-Karte hinzugefügt + Bereite deine Karte vor + Zwei Backup-Karten hinzugefügt + Um zu beginnen, lade einfach die wallet mit einem beliebigen Betrag auf + Um zu beginnen, lade die Wallet einfach mit mehr als %1$s %2$s auf. + Krypto kaufen + Adresse der Wallet anzeigen + Aktivieren einer Wallet + Der Twinning-Prozess ist teilweise abgeschlossen. Du kannst ihn jetzt nicht mehr beenden. + Wenn der Prozess der Erstellung der Brieftasche in irgendeiner Weise unterbrochen wird, musst du diesen von vorne beginnen + Du kannst deine Schlüssel mit bis zu zwei weiteren leeren Tangem Wallet-Karten sichern. + Der Zugangscode kann mit einer der Ersatzkarten wiederhergestellt werden. + Alle Backup-Karten können als voll funktionsfähig mit den gleichen Schlüsseln verwendet werden. + Du kannst einen Zugangscode zum Schutz deiner wallet festlegen. + Wiederherstellungs-Wallet + Zugangscode wiederherstellen + Identische Karten + Zugangscode + Gruppe erstellen + Nach Guthaben + Token organisieren + Gruppierung aufh. + Wählen aus der Galerie aus + Einstellungen + Du hast keinen Zugriff auf deine Kamera gewährt + Kamerazugriff verweigert + %1$s ( %2$s ) im %3$s Netzwerk + Sende nur %s an diese Adresse. Der Versand einer anderen Währung führt zu ihrem unwiderruflichen Verlust. + QR-Code anzeigen oder Adresse teilen + Teilnehmen + Die Informationen zum Empfehlungsprogramm konnten nicht geladen werden. Bitte versuche es später noch einmal. + Die Informationen über das Empfehlungsprogramm konnten nicht geladen werden. Fehlercode: %s. Bitte versuche es später noch einmal. + Anstehende Zahlungen + Deine Freunde kauften + Weniger + Mehr + Keine anstehenden Zahlungen + + für %d Wallet + für %d Wallets + + Du bekommst ^^%1$s^^ für jede von einem Freund gekaufte Wallet auf deine %2$s Netzwerkadresse %3$s ^^30 Tage nach^^ dem + Du + Bekommt eine + beim Kauf einer Wallet auf tangem.com + %s Rabatt + Dein Freund + Persönlicher Code kopiert! + Dein persönlicher Code + Tangem Wallet mit Rabatt kaufen!\n%s + Empfehle Tangem deinen Freunden + Du hast akzeptiert + Durch Tippen auf diese Schaltfläche akzeptierst du + des Empfehlungsprogramms + + %d Wallet + %d Wallets + + Zurücksetzen der Karte + Mir ist bewusst, dass ich nach der Durchführung dieser Aktion keinen Zugriff mehr auf die aktuelle Wallet habe. + Mir ist klar, dass ich diese Karte nicht verwenden kann, um meinen Zugangscode auf den anderen Karten der aktuellen Wallet wiederherzustellen + Durch das Zurücksetzen auf Werkseinstellungen wird die Wallet vollständig von der ausgewählten Karte gelöscht. Du kannst die aktuelle Wallet nicht wiederherstellen oder die Karte verwenden, um den Zugangscode wiederherzustellen. + Beim Zurücksetzen auf die Werkseinstellungen wird die Wallet der ausgewählten Karte vollständig gelöscht und aus der App entfernt. Es ist nicht möglich, die aktuelle Wallet wiederherzustellen. + Besitzt du eine Bankkarte aus einem anderen Land und eine Aufenthaltserlaubnis oder Registrierung außerhalb der Russischen Föderation? + Russische Bankkarten werden derzeit nicht akzeptiert + Melde dich bei der App an und überprüfe dein Guthaben, ohne die Karte zu scannen + Zugriff auf die App + Nutzung biometrischer Daten zulassen + Bei Interaktionen mit deiner Wallet werden anstelle des Zugangscodes biometrische Daten abgefragt + Zugangscode + Es sieht so aus, als ob du die biometrische Authentifizierung deaktiviert hast. Diese ist notwendig, um Wallets zu speichern + Biometrische Autorisierung aktivieren + Möchtest du Biometrie nutzen? + Beachte, dass für Transaktionen mit deinem Guthaben weiterhin deine Karte erforderlich ist + Karte scannen + Scanne die Karte, um ihre Einstellungen zu ändern. Die Änderungen wirken sich nur auf die von dir gescannte Karte aus und haben keine Auswirkungen auf andere mit deiner Wallet verknüpften Karten. + Halte deine Karte bereit! + Bereits in der eingegebenen Adresse enthalten + Der Provisionsbetrag ist %s mal der empfohlene Betrag. Stelle sicher, dass die benutzerdefinierten Einstellungen korrekt sind. + Du hast eine Kommission angegeben, die unter dem empfohlenen Betrag liegt, was zu einer Verzögerung Ihrer Transaktion führen könnte. Weiter? + Grund: %1$s\nCode: %2$s + Die Transaktion ist nicht abgeschlossen Betrag + Du kannst deine Transaktionsgebühr festlegen, indem du den Wert im Feld Satoshi pro vByte anpasst. + Die Gebühr, die für deine Transaktion erhoben wird. Du kannst einen eigenen Wert festlegen. + Maximale Gebühr + Dies sind die Kosten, die du für jede Gaseinheit zu zahlen bereit bist. Je höher der Gaspreis ist, desto schneller wird deine Transaktion bearbeitet. (Vorzugsgebühr inbegriffen) + Prioritätsgebühr + Die Gebühr, die ein Nutzer an Miner oder Validierer zahlen kann, um die Aufnahme seiner Transaktion in einen Block zu beschleunigen. + Die Gebühr, die für die Nutzung jeder nicht ausgegebenen Transaktionsausgabe (UTXO) im Kaspa-Netzwerk erforderlich ist. Je mehr UTXOs du in einer Transaktion verwenden, desto höher ist die Gebühr. + KAS per UTXO + %1$s, %2$s Adresse + Ziel-Tag + Adresse eingeben Die Adresse stimmt mit der Adresse Ihrer Brieftasche überein + Ungültiges Tag. Es wird der Transaktion nicht hinzugefügt. + Ungültiges Memo. Sie wird der Transaktion nicht hinzugefügt. Tag Memo inkl. Gebühr Niedrig Normal Priorität + Überprüfe deine Netzwerkverbindung + Informationen zur Netzwerkgebühr nicht erreichbar + Von + Grenzwert Gasgebühr + Dies ist die maximale Gasgebühr, die für den Abschluss einer Transaktion oder eines Vertrags ausgegeben wird. Ein Gaslimit verhindert unerwartete oder unbegrenzte Gebühren bei der Ausführung einer Transaktion. + Gaspreis + Dies sind die Kosten, die du für jede Gaseinheit zu zahlen bereit sind. Je höher der Gaspreis ist, desto schneller wird Ihre Transaktion abgewickelt. + Max Höchstbetrag + Gebühr bis zu + Ungültiges Memo + Abdeckung der Netzgebühren + Unzureichende Mittel für die Überweisung, da die Summe aus Gebühr und Überweisungsbetrag das bestehende Guthaben übersteigt + Gesamtbetrag übersteigt den Saldo + Das Konto wird von der Blockchain gelöscht, wenn der Kontostand unter die Mindesteinlage fällt. Bitte belasse %s auf deinem Konto. + Mindesteinlage + Der Kommissionsbetrag ist %s mal der empfohlene Betrag. Stelle sicher, dass die benutzerdefinierten Einstellungen korrekt sind. + Die individuelle Gebühr ist hoch + Aufgrund der Besonderheiten des Netzes %1$s ist die Gebühr für die Überweisung des gesamten Guthabens höher. Um die Kommission zu reduzieren, Kannst du %2$s verlassen. + Die Gebühr ist höher + Die enthaltene Kommission übersteigt den Überweisungsbetrag, was zu einem negativen Wert führt + ungültige Menge + Der Mindestbetrag für den Versand beträgt %1$s. Bitte stell sicher, dass der Restbetrag nach dem Versand nicht unter %2$s liegt. + Das Zielkonto wurde nicht erstellt. Bitte änder den zu sendenden Betrag. + Der zu sendende Betrag muss mindestens %s betragen + Verlasse %s + Verringern um %s + Reduziere auf %s + Bitte beachte, dass es bei bestimmten Gebühreneinstellungen zu Verzögerungen bei deiner Transaktion kommen kann + Transaktionsverzögerungen sind möglich + Aufgrund der Beschränkungen von %1$s können nur %2$s UTXOs in eine einzige Transaktion passen. Das bedeutet, dass du nur %3$s oder weniger senden kannst. Du musst den Betrag reduzieren. + Begrenzung der Transaktionen + Optional + Bitte richte den QR-Code auf das Quadrat aus, um ihn zu scannen. Stell sicher, dass du die Netzwerkadresse %s scannen. + Jüngste + Empfänger + Keine gültige Adresse + Vergewisser dich, dass die empfangende Wallet-Adresse im %s Netzwerk ist, damit du deine Token nicht verlierst. + Senden an + Ein Memo/Destination Tag ist eine eindeutige ID zur Unterscheidung von Transaktionen, die an denselben Empfänger im selben Netzwerk gesendet werden. Vorsicht! Das Weglassen eines Vermerks kann dazu führen, dass Gelder für immer verloren sind! + Meine Wallet + Eine Möglichkeit, Bitcoin-Transaktionsgebühren zu messen. Du gibst die Anzahl der kleinsten Bitcoin-Einheiten (Satoshi) für jedes virtuelle Byte in einer Transaktion an. Je höher die Zahl, desto schneller wird die Transaktion von den Minern verarbeitet. + Satoshi / vByte + Senden... + Berühre an beliebiger Stelle für Änderungen + Versende %s + Du sendest **%1$s** inklusive der Netzwerkgebühr %2$s + Du sendest **%1$s** und %2$s + Senden %s Gesamt %1$s und %2$s werden gesendet ≈ %1$s (inkl. Gebühr: %2$s) %s wird gesendet Die Transaktion wurde erfolgreich signiert und an den Blockchain-Knoten gesendet. Die Walletbilanz wird aktualisiert + %1$s ist ein Vermögenswert im Tron-Netzwerk. Um die Gebühr zu berechnen und eine Transaktion durchzuführen, musst du etwas Tron (TRX) auf deinem Konto einzahlen. Ungültige Adresse + %1$s (%2$s) + Transaktion gesendet + Bereite das Scannen der Karte vor, die du einrichten möchtest. + Entferne diese Wallet + Hiermit wird die Wallet aus der Anwendung entfernt. Die Wallet selbst kann wieder hinzugefügt werden. + Name + Aktiv + Um deine Kryptos zu unstaken, klick hier. + Die Anzahl der zu stakenden Krypros muss mindesten %s betragen + nicht gestakte beanspruche + Jährliche prozentuale Rendite + Die jährliche prozentuale Rendite, die du durch die Teilnahme am Staking erzielen kannst. + Effektiver Jahreszins + Verfügbar + Durchschnittliche Belohnungsquote + %s geschätzter Profit + Marktbewertung + Metriken + Mindestanforderungen + Keine Belohnungen zu beanspruchen. + Belohnungen beanspruchen + Eine Möglichkeit, Staking-Belohnungen zu erhalten. Es kann automatisch oder manuell beansprucht werden. + Belohnungszeitplan + Dabei handelt es sich um einen Zeitplan, der festlegt, wann die Teilnehmer am Staking ihre Belohnungen erhalten. + Belohnungen, die du beanspruchen kannst: %s + Staking %s + Entbindungsdauer + Der Zeitraum, den du nach der Beantragung der Abhebung von Geldern aus dem Staking warten musst, bevor die Token verfügbar werden. + Aufwärmphase + Die zugewiesene Zeit für die Aktivierung der Teilnahme am Staking. + Stake %s + Migrieren + Natives Staking + Mit Staking kannst du %1s verdienen. Deine Staking-Belohnungen kommen alle ~%2s Tage. + Verdiene Staking-Belohnungen + Die Belohnungen werden sofort nach dem unstaken gestoppt. Der unstakingprozess dauert %s. + Erneut binden + Erneut staken + Belohnungen erneut staken + Widerrufen + Neuwahl + Belohnungen + Stake gesperrt + Mehr staken + gelocktes unlocken + Unstaken + Prüfe, was nicht eingesetzt wurde, um dein Vermögen zu beanspruchen + Staking beenden + Validator/ Prüfer + Abstimmung + Abstimmung gesperrt + Zurückziehen + Bewahre deine Krypto-Assets sicher auf, während die privaten Schlüssel auf deiner Karte bleiben + Revolutionäre Hardware-Wallet + Bis zu 3 physische Karten pro Wallet + Ultrasicheres Backup + Eine Hardware-Wallet für deine Bitcoins, Ethereum und viele weitere Währungen gleichzeitig – alles auf einer Karte + Tausende von Währungen + Verwende es unterwegs, überall und jederzeit. Keine Kabel oder Batterien. Tippe einfach mit der Karte auf dein Telefon, wenn du Kryptowährung benötigst. + Die Wallet für jeden + Lerne Tangem kennen + Tausche, kaufen Sie NFTs, vergebe Kredite und tätige Einlagen bei mehr als 100 verschiedenen dezentralen Diensten + Web 3.0-kompatibel + Tausche mehr Token zu besseren Kursen direkt in deiner Brieftasche. + Neuer Swap-Anbieter verfügbar! + Der Betrag umfasst:\n- Gebühr des Dienstanbieters\n- Netzgebühr für die Rücksendung von %s von der Vermittlungsstelle an die Adresse des Nutzers. + Der Betrag enthält die Gebühren des Dienstleisters. + Gebühren + Alle dezentralen Börsen benötigen Genehmigungen, um zu verhindern, dass intelligente Verträge ohne Ihre Erlaubnis auf Ihre Geldbörse zugreifen. Smart Contracts können nicht auf Ihre Token zugreifen, wenn Sie nicht zustimmen. Indem Sie Ihre Token \"freischalten\", ermächtigen Sie den 1-Zoll-Smart-Contract, sie auszugeben. Die Miner des Netzwerks erhalten eine (von Ihnen bezahlte) Gasgebühr, um diese Aktion in der Blockchain aufzuzeichnen. Sie können Ihre Token tauschen, nachdem Sie Ihre Zustimmung gegeben haben. + Genehmigen + Fehler bei der Gebührenschätzung. Bitte sende dein Feedback an den Support. + Du wechselst + Der Tausch dieser Menge ausgewählter Token hat erhebliche Auswirkungen auf den Preis und verringert dein Ergebnis. + Unzureichende Mittel + Erlaubnis erteilen + In Arbeit + Tauschen + Du erhältst + Token auswählen + Nicht verfügbar + Guthaben versteckt + Angezeigte Salden + Rückgängig machen + Dieser Vorgang ist derzeit nicht verfügbar. Bitte versuche es später noch einmal. + Der Kauf von %s ist im Moment nicht verfügbar. Bitte prüfe später ob es Updates gibt. + Du hast kein Guthaben um dies zu Verkaufen. Lade dein Konto auf, um Geld von dort zu verkaufen. + Du hast kein Guthaben zum Versenden. Lade dein Konto auf, um Geld von dort aus senden zu können. + Swappen %s ist im Moment nicht verfügbar. Bitte prüfe später ob es Updates gibt. + Das Geld für den Verkauf steht zur Verfügung, sobald die ausstehende(n) Transaktion(en) im Netzwerk %s abgeschlossen ist/sind. + Die Geldsendung wird verfügbar, sobald die ausstehende(n) Transaktion(en) im Netzwerk %s abgeschlossen ist/sind. + Der Verkauf von %s ist im Moment nicht verfügbar. Bitte prüfe später ob es Updates gibt. + Staking %s ist aktuell nicht verfügbar. Prüfe bitte ob es ein neues Update gibt. + Generiere XPUB + Ausblenden + Du bist dabei, dieses Token vom Hauptbildschirm auszublenden. Du kannst es jederzeit über die Seite „Token verwalten“ wieder hinzufügen. + Blende %s aus + Token ausblenden + Durch das Staking kannst du alle %2$s Tage %1$s verdienen und Belohnungen erhalten + Verdiene bis zu %s Stakingprämie pro Jahr + %1$s Token in %%image%% %2$s Netzwerk + Token in %%image%% %1$s Netzwerk + Der %1$s (%2$s) Token ist die Hauptwährung im %3$s Netzwerk und kann nicht versteckt werden, solange du andere Token dieses Netzwerks in der Liste aktiv hast. + %s kann nicht ausgeblendet werden + Tausche diesen Token gegen einen anderen zu %1$s Servicegebühren von Februar %2$s-%3$s. + Tausche mit Changelly, %s Gebühren + Jetzt tauschen + Vertrag: %s + Du hast noch keine Transaktionen + Der Transaktionsverlauf konnte nicht geladen werden.\nKlicke auf die Schaltfläche Neu laden, um die Informationen zu aktualisieren. + Mehrere Adressen + Die Transaktionshistorie wird für diese Blockchain derzeit nicht verfügbar. Aber keine Sorge, wir arbeiten daran! In der Zwischenzeit kannst du es im Explorer überprüfen. + Operation + von: %s + zu: %s + Versuche es erneut + Du hast dieselbe Karte gescannt. Um ein Zwillings-Wallet zu erstellen, musst du die Karte mit der Nummer %d scannen. + Du hast die falsche Doppelkarte gescannt. Bitte versuche eine andere Karte + Die, die du in den Hand hältst, und die andere mit der Nummer %s.\n\nBeide Karten können verwendet werden, um Geld aus dieser Wallet zu versenden. + Eine Wallet. Zwei Karten. + Scanne die Karte Nr. %s + Wallet erstellen + Scanne die Nr. %s Zwillingskarte + Karte vorbereiten Tangem Twin + Diese Aktion ist unumkehrbar. Du hast keinen Zugriff mehr auf die alte Wallet. + Tippe auf die Doppelkarte mit der Nummer %s und entferne sie erst am Ende des Vorgangs. + Verwende %s oder scanne eine Karte, um Zugriff auf deine Wallet zu erhalten. + Bleib auf dem Laufenden mit den neuesten Funktionen und Neuigkeiten + Sei der Erste, der von neuen Aktionen erfährt + Möchtest du Push-Benachrichtigungen verwenden? + Neues Wallet hinzufügen + Möchtest du diese Wallet wirklich löschen? + Es ist ein Fehler aufgetreten, bitte scanne deine Karte, um sich anzumelden + Dieses Wallet wurde bereits gespeichert, du kannst ein weiteres hinzufügen + Die Wallet mit dem Namen %s existiert bereits + Wallet-Name + Wallet umbenennen + Alle freischalten + Alle mit %s freischalten + Blockchain ist nicht erreichbar. Versuche es später nochmal + Karte scannen + Aufforderung zum Signieren einer Nachricht. \n\n %s + Dapp %1$s, mit der Bitte um\nBNB-Transaktion zu unterzeichnen.\n\n%2$s + Handelsauftrag für %1$s\n Preis: %2$s\n Zu erhaltender Betrag: %3$s\n Zu zahlender Betrag: %4$s + Details zur Transaktion:\nVon: %1$s\nZu: %2$s\nBetrag: %3$s + Zwischenablage enthält WalletConnect-Code. Kopierten Wert verwenden oder QR-Code scannen + Antrag auf Erstellung einer Transaktion für %1$s\n%2$s\n\nBetrag: %3$s\nGebühr: %4$s\nGesamt: %5$s\nSaldo: %6$s + Die Transaktion kann nicht gesendet werden. Nicht genügend Guthaben. + WalletConnect Sitzung konnte nicht aufgebaut werden. Bitte versuche es später noch einmal. + Nachricht konnte nicht signiert werden.\nBitte, versuche es erneut + WalletConnect-Sitzung konnte nicht aufgebaut werden: Timeout-Fehler. Bitte versuche es später noch einmal. + Sitzungsanfrage enthält nicht unterstützte Blockchains für WalletConnect-Verbindung. Nicht unterstützte Blockchains:\n + Aufgrund der technischen Implementierung kann keine Verbindung zu dieser Dapp hergestellt werden. + Es ist ein unbekannter Fehler aufgetreten. Fehlermeldung: %s. Wenn das Problem weiterhin besteht, wende dich bitte an unseren Support + Falsche Karte in der Tangem App ausgewählt + Transaktion aus Dapp-Daten konnte nicht erstellt werden. Code: %s + Es ist ein unbekannter Fehler aufgetreten. Fehlercode: %d. Wenn das Problem weiterhin besteht, wende dich bitte an unseren Support + Keine geöffneten WalletConnect-Sitzungen + Hoppla. Keine Sitzungen. + WalletConnect-Sitzung konnte nicht gekoppelt werden: %1$s + Einfügen aus der Zwischenablage + Nachricht für %1$s:\n%2$s + Anfrage zum Starten einer Sitzung für\n %1$s\n\n NETZWERK: %2$s \n\n URL: %3$s + Der Vorgang konnte nicht abgeschlossen werden. \n\nDu hast bereits eine WalletConnect-Sitzung mit diesen Parametern hergestellt. + Neuen Code scannen + Mit dieser Karte kann keine WalletConnect-Sitzung hergestellt werden + Dieses Netzwerk wird nicht unterstützt. Bitte wähle ein anderes Netzwerk. + Netzwerk auswählen + WalletConnect-Sitzungen + Mit dApps verbinden WalletConnect + Das Herstellen der Verbindung kann einige Sekunden dauern + %s Marktpreis + letzte 24h + %s Netzwerk Die Adresse wurde erfolgreich kopiert Keine Internetverbindung + Wallet-Einstellungen Tangem - OK, ich hab\'s! + Verwende %s oder scanne eine Karte, um den Zugriff auf deine Wallet freizuschalten. + Es scheint, dass die Aktivierung der Karte nicht korrekt abgeschlossen wurde. Dies kann an einem Problem mit dem NFC-Modul deines Gerätes oder an einem falschen Tippen der Karte auf dein Gerät liegen. Bitte wende dich an unser Support-Team, um Unterstützung zu erhalten. + Aktivierungsfehler + Laut den Entwicklern des BNB-Netzes wird die Unterstützung für den BEP-2-Standard im Juni 2024 enden. Um den Verlust von Vermögenswerten mit diesem Standard zu vermeiden, konvertiere bitte in den BEP-20 Standard. Nutze gerne unseren Swap-Service, um sie auf das BNB Smart Chain Netzwerk zu übertragen. + BNB Beacon Chain wird abgeschaltet + verbesserungswürdig + Gefällt mir + OK, habe ich verstanden! + Echt toll! + Aktualisieren + Du befindest sich derzeit im Demo-Modus + Demo-Modus aktiv + Die Karte, die du gescannt hast, ist eine Entwicklerkarte. Verwenden diese nicht zur Erstellung Ihrer Wallet. + Nicht für Benutzer! + %1$s Netzwerk erfordert eine Mindesteinlage. Wenn dein Konto unter %2$s fällt, wird es deaktiviert und alle verbleibenden Guthaben werden vernichtet. + Netzwerk erfordert eine Mindesteinzahlung + Der Swap wird nach Abschluss der Transaktion %s verfügbar sein. + Du hast aktive Transaktion + Die Genehmigung des Swaps ist im Gange und wird in Kürze abgeschlossen sein. + Genehmigung in Arbeit + Der Mindestbetrag für den Tausch beträgt %1$s. Bitte stelle sicher, dass der Restsaldo nach dem Swap nicht unter %2$s liegt. + Du hast keine %s Coins in deiner Liste + Keine Token zum Tauschen verfügbar + Um eine Transaktion durchzuführen, du etwas etwas einzahlen %1$s %2$s + Die Gebühr %s kann nicht gedeckt werden + Der zu erhaltende Betrag muss mindestens %s betragen + Service vorübergehend nicht verfügbar + Die Menge der zu tauschenden Token darf folgende Werte nicht überschreiten %s + Der zu tauschende Betrag muss mindestens %s betragen + Bitte änder den zu tauschenden Betrag + Bei dieser Karte kann es sich um ein Produktionsmuster oder eine Fälschung handeln + Echtheitsprüfung fehlgeschlagen + zuordnen + Dieser Token muss mit Ihrem Hedera-Konto verbunden sein, bevor du diesen erhalten kannst. Zuordnungsgebühr ~%1$s %2$s + Dieses Token muss mit deinem Hedera-Konto verknüpft sein, bevor du ihn erhalten kannst. + Verknüpfe deinen Token + Nicht genug %s. Lade dein Hedera-Konto auf, um dieses Token zuzuordnen + Auf dieser Karte sind nur noch %s Unterschriften übrig. Du musst dein gesamtes Guthaben abheben. + Geringe Anzahl von Unterschriften + Token in verschiedenen Netzwerken können unterschiedliche Adressen haben. Überprüfe bei der Überweisung noch einmal, ob deine Adresse mit der des Netzwerks übereinstimmt. + + Verwende deine Karte, um eine Adresse für das %d-Netz zu erhalten + Verwende deine Karte, um mehrere Adressen für die %d-Netzwerke zu erhalten + + Einige Adressen fehlen + Das Netzwerk ist derzeit nicht erreichbar. Bitte versuchen Sie es später erneut. + Netzwerk ist nicht erreichbar + Lade dein Guthaben auf + Deine Wallet wurde nicht gesichert. Führe diesen Vorgang durch, um dein Vermögen jetzt zu schützen. + Fehlende Sicherung + Diese Karte wurde bereits für Transaktionen verwendet. Wenn die Karte aus einer nicht vertrauenswürdigen Quelle stammt, solltest du den gesamten Betrag abheben. Wenn es sich um deine Karte handelt, sind keine Maßnahmen erforderlich. + Karte hat bereits Transaktionen unterzeichnet + Deine Bewertung motiviert uns, die Tangem Wallet noch besser zu machen. + Gefällt dir Tangem? + Du musst deinen Token zuordnen, bevor du Token erhalten kannst + Netzmietgebühr erforderlich + %1$s ist ein Vermögenswert im %2$s Netzwerk. Um eine %3$s Transaktion durchzuführen, musst du etwas %4$s (%5$s) einzahlen, um die Netzwerkgebühr zu decken. + Unzureichende %1$s zur Deckung der Netzgebühr + Das Solana-Netz ist überlastet. Wenn deine Transaktion nicht innerhalb von 2 Minuten bearbeitet wird, wiederhole bitte die Transaktion. + Solana Netzwerkalarm + Das Solana-Netzwerk erhebt alle 2 Tage eine Miete von %1$s. Konten, die sich die Miete nicht leisten können, werden aus dem Netzwerk gelöscht. Hinterlege deinem Konto mit mehr als %2$s, um es kostenlos zu nutzen. + Einige Netzwerke sind derzeit nicht erreichbar. Bitte versuche es später erneut. + Einige Netzwerke sind nicht erreichbar + Dies ist eine Testnet-Karte. Sie kann keine Transaktionen verarbeiten und sollte nur zu Test- und Entwicklungszwecken verwendet werden. + Nur für Testzwecke + Verwerfen + Du hast eine unterbrochene Sicherung. Möchtest du diese fortsetzen? + Ja, fortsetzen + Verwerfen + Wenn du das Backup jetzt abbrichst, musst du die Karten auf die Werkseinstellungen zurücksetzen, um von vorne zu beginnen + Sicherung fortsetzen + Dies ist eine unwiderrufliche Aktion + Anmelden mit %s + Karte scannen + Verwenden %s oder scanne eine Karte, um auf die App zuzugreifen + Willkommen zurück! diff --git a/core/res/src/main/res/values-fr/strings-blockchain.xml b/core/res/src/main/res/values-fr/strings-blockchain.xml index 97b9e7c7c7..8269ca16c6 100644 --- a/core/res/src/main/res/values-fr/strings-blockchain.xml +++ b/core/res/src/main/res/values-fr/strings-blockchain.xml @@ -1,17 +1,25 @@ - Échec de réception des commissions - Pour créer un compte, envoyez des fonds monétaires à cette adresse + Défaut + Héritage + Échec de réception des frais de commissions + En raison d\'une limitations sur les %1$s, seuls les %2$d UTXO peuvent s\'intégrer dans une seule transaction. Ce qui signifie vous ne pouvez envoyer que %3$s ou moins. Réduisez le montant. + Pas assez de fonds pour la transaction. Veuillez recharger votre compte. + Une erreur s\'est produite. Code:%s + Pour utiliser le réseau %1$s, vous devez payer la réserve de compte (%2$s%3$s), qui bloque et cache ce montant indéfiniment + Le compte de destination est inactif. Envoyez %s ou plus pour activer le compte. + Pour créer un compte, envoyez des fonds à cette adresse Le montant minimal est de %s - Le reste est trop petit - Commission non valide - Le compte cible n\'a pas été créé. Le montant à envoyer doit être de %s + commissions ou plus + Le montant est trop faible + Frais de commissions non valides + Le solde minimal est de %s + Le compte cible n\'a pas été créé. Le montant à envoyer doit être de %s + frais de commissions ou plus Erreur inconnue Le montant dépasse le solde - Somme incorrecte - Les commissions dépassent le solde + Montant invalide + Les frais de commissions dépassent le solde Le total dépasse le solde Non, envoyer toute la somme Réduire de %s XTZ - Pour ne pas payer une commission élevée la prochaine fois que vous rechargez votre portefeuille, veuillez réduire le montant de %s XTZ + Pour ne pas payer un fraid de commissions élevé la prochaine fois que vous rechargez votre portefeuille, veuillez réduire le montant de %s XTZ diff --git a/core/res/src/main/res/values-fr/strings.xml b/core/res/src/main/res/values-fr/strings.xml index e7454edeb7..071924cd18 100644 --- a/core/res/src/main/res/values-fr/strings.xml +++ b/core/res/src/main/res/values-fr/strings.xml @@ -1,59 +1,803 @@ + Choisissez le réseau + Ajouter un jeton personnalisé + Gérer les jetons + Envoyez uniquement %1$s (%2$s) depuis les réseaux %3$s à cette adresse. L\'utilisation d\'autres jetons et réseaux peut entraîner une perte de fonds. + Comment scanner + Demander de l\'aide + Réessayer + Cette fonctionnalité est désactivée en mode démo + Raison : %s + Impossible d\'envoyer une transaction + Le sélectionné ne prend pas en charge le réseau %1$s + Pour activer le cryptage de la blockchain %1$s, vous devrez réinitialiser le portefeuille aux paramètres d\'usine. Veuillez retirer vos fonds avant de le faire pour vous assurer de ne pas les perdre, puis terminez le processus de réinitialisation. L\'accès au portefeuille actuel ne sera pas possible après la réinitialisation. + Les jetons du réseau %1$s ne sont pas pris en charge par cette carte en raison d\'une limitation du micrologiciel. + Avez-vous des difficultés à scanner votre carte ? Cette carte n\'est pas conçue pour fonctionner avec Tangem + Frais par défaut + Activez les frais par défaut pour définir automatiquement les frais de transaction et ignorer la page Frais lors de l\'envoi de fonds. Vous pouvez toujours revenir sur cette page si nécessaire. + Allez dans les paramètres pour activer l\'authentification biométrique dans le Tangem App + Activer l\'authentification biométrique + Cela supprimera tous les codes d\'accès des portefeuilles enregistrés. Toute opération ultérieure avec le portefeuille nécessitera la soumission du code d\'accès. + La suppression de la carte enregistrée supprime de l\'application tous les portefeuilles enregistrés et leurs codes d\'accès. + Enregistrer le code d\'accès + L\'authentification biométrique sera demandée à la place du code d\'accès pour les interactions avec votre carte. + Conserver le portefeuille dans l\'application + Activez cette option pour lier tous les portefeuilles à l\'application Tangem. L\'authentification biométrique sera requise pour déverrouiller l\'application. La signature des transactions nécessite de taper sur votre carte Tangem. + Sombre + Clair + Par défaut du système + Thème + Paramètres de l\'application + Pour masquer ou afficher vos soldes, il suffit de retourner l\'écran de votre appareil vers le bas ou de le désactiver dans les paramètres + Ne plus afficher + Compris + Les soldes sont masqués + Veuillez scanner la carte + Veuillez réessayer dans 30 secondes ou scanner la carte + Trop de tentatives + Vous avez désactivé l\'authentification biométrique sur votre téléphone et ne pourrez pas enregistrer de portefeuilles dans l\'application. Pour enregistrer des portefeuilles, veuillez activer la fonction d\'authentification biométrique dans les paramètres de votre téléphone. + Démarrer le processus de sauvegarde + + %d carte + %d cartes + + Désactivez cette option si vous ne voulez pas que cette carte soit utilisée pour réinitialiser les codes d\'accès sur d\'autres cartes de ce portefeuille. Veuillez noter que cela vous empêchera également de réinitialiser le code d\'accès sur cette carte. + Vous permet d\'utiliser cette carte pour réinitialiser le code d\'accès sur d\'autres cartes de ce portefeuille + Récupération du code d\'accès + Réinitialiser + Êtes-vous sûr de vouloir faire cela ? + Modifier le code d\'accès + Le code d\'accès ne sera modifié que sur cette carte + Toutes les cartes du portefeuille sélectionné ont été réinitialisées aux paramètres d\'usine. Vous pouvez maintenant créer un nouveau portefeuille. + Réinitialisation terminée + Voulez-vous réinitialiser la prochaine carte de ce portefeuille ? + Carte réinitialisée + Nous vous recommandons de terminer le processus de réinitialisation pour toutes les cartes de ce portefeuille + Vous n\'avez pas réinitialisé toutes vos cartes + Réinitialiser aux paramètres d\'usine + Mode de sécurité + Paramètres de la carte + En plus des frais de réseau, le réseau Cardano facture %1$s de l\'ADA lors des transactions avec le jeton %2$s + Exigences pour les transactions Cardano + Pour effectuer une transaction %1$s, vous devez déposer de l\'ADA pour couvrir les frais de réseau et la valeur minimale en ADA (5 ADA recommandés) + ADA insuffisant pour le transfert de jetons + Vous devez conserver un peu d\'ADA car vous avez des jetons sur la blockchain Cardano + ADA insuffisant J\'accepte + Accès refusé + Tout + Permettre + Appliquer + Approbation + Approuver + Attention Solde : %s + Solde + authentification biométrique + biométrie + Acheter + Aller à %1$s Vous n\'avez pas octroyé l\'accès à votre caméra, veuillez modifier vos paramètres de confidentialité Annuler + Fermer + Continuer + Copier + Copier l\'adresse + Créer + Personnalisé + + %d jour + %d jours + Supprimer + Désactivé Exécuté + Activer + Activé Erreur + Explorer + Explorez l\'historique des transactions + Explorateur Commissions + Les frais de réseau sont des charges que les utilisateurs paient pour traiter et confirmer les transactions. Le montant des frais peut être affecté par la congestion du réseau, la taille de la transaction et la priorité d\'exécution. %s + Rapide + Marché + Lent + Vitesse et frais + Obtenir des adresses + Aller au fournisseur + Importez + Plus tard + Verrouillé + Réseau principal Commissions du réseau + Le montant envoyé sera réduit de %1$s(%2$s) pour couvrir le niveau de frais sélectionné + Suivant + Non + Aucune adresse + Maintenant OK + Carte principale + Passphrase + Coller + %1$s-%2$s + En savoir plus + Recevoir + Rejeter + Recharger + Renommer + Enregistrer Sauvegarder les modifications + Rechercher + Rechercher des jetons + Seed phrase + Sélectionner une action + Vendre Envoyer + Le serveur n\'est pas disponible, veuillez réessayer plus tard + Partager + Signer + Signer et envoyer + Enjeu + Staking + Démarrer + Soumettre Avec succès + Support + Échange + termes et conditions + Aujourd\'hui + La transaction a échoué + Transactions + Transfert + Je comprends + Il y avait une erreur. Veuillez réessayer. + Inaccessible + Oui + Adresse du contrat copiée ! + Réseaux disponibles + Ajouter un jeton + Adresse du contrat + L\'adresse du contrat n\'est pas valide + Veuillez sélectionner le réseau + Les décimales doivent être un entier valide, jusqu\'à %li + Dérivation personnalisée + Par exemple m/00\'/0000\'/0\'/0/0 + Entrez une dérivation personnalisée + Décimales + Chemin de dérivation + Par défaut + Coin de type BIP44 + Le chemin de dérivation entré est invalide + Par exemple USD coin + Nom + Non sélectionné + Réseau + Réseau de jetons + Vous pouvez ajouter manuellement un jeton qui n\'est pas nativement pris en charge par Tangem + Par exemple USDC + Symbole + Symbole du jeton + Ce jeton/réseau a déjà été ajouté à votre liste + Notez que les jetons peuvent être créés par n\'importe qui. Méfiez-vous de l\'ajout de jetons frauduleux, ils peuvent ne rien coûter. + Prenez garde de l\'ajout de jetons frauduleux, ils peuvent ne rien coûter + Notez que les jetons peuvent être créés par n\'importe qui + Acheter un Portefeuille Tangem + Chat Code d\'accès Vous devrez entrer le mot de passe correct avant de scanner la carte Tenez la carte fermement Ce mécanisme protège contre les attaques sans contact sur la carte. Il y a un délai entre la réception et l\'exécution de la commande. Après la première transaction signée, ce téléphone sera associé à la carte et les transactions seront signées immédiatement. Mot de passe Avant d\'exécuter une commande qui modifie l\'état de la carte, vous devrez entrer un mot de passe. + Programme de parrainage + Retournez l\'écran de votre appareil vers le bas pour masquer et afficher rapidement les soldes %s hashes ID de la carte + Contactez l\'équipe de support + Lier plus de cartes Monnaie de l\'application + Retourner pour masquer les soldes Emetteur Signé + Envoyer un commentaire Référénces + Vérifiez votre connexion Internet ou passez à un réseau différent Conditions d\'utilisation - Scannez la carte + Vous avez utilisé une carte d\'un autre portefeuille. Appuyez sur la carte associée à ce portefeuille + Mes jetons + Vous n\'avez pas encore ajouté de jetons. Ajoutez des jetons via Market pour effectuer une échange + Ne peut pas être échangé contre %s + Fourni par + Statut + Tangem propose des échanges de jetons via des fournisseurs tiers selon les conditions de chaque fournisseur + Choisissez un fournisseur + Une erreur s\'est produite. Code : %s + Oups! L\'échange de la paire sélectionnée via le fournisseur choisi est temporairement indisponible. Veuillez réessayer plus tard. (Code : %s) + Le fournisseur sélectionné n\'est pas disponible pour le moment. Veuillez réessayer plus tard. (Code : %s) + Les échanges ne sont pas disponibles pour le moment. Veuillez réessayer plus tard. (Code : %s) + Montant estimé + Échange par %s + Visitez le site Web du fournisseur pour obtenir un remboursement + Opération échouée par le fournisseur + Visitez le site Web du fournisseur pour la vérification + Vérification KYC requise par le fournisseur + Annulé + Confirmé + En attente de confirmation + En cours de confirmation + Échangé + En cours d\'échange + En cours d\'échange + Échoué + Dépôt reçu + En attente du dépôt + En attente du dépôt + Remboursé + Je vous envoie + En cours d\'envoi + Envoyé + Données fournies par le fournisseur. Le montant estimé est sujet à modification en raison des conditions du marché. + Statut de l\'échange + Verification requise + Liste de tous les jetons ajoutés à votre portefeuille + En cherche des meilleurs taux + Taux flottant + En utilisant la fonctionnalité d\'échange, vous acceptez les %s + En utilisant la fonctionnalité d\'échange, vous acceptez les conditions %1$s et %2$s du fournisseur. + D\'autres fournisseurs arriveront bientôt.\nRestez branchés ! + Politique de confidentialité + Fournisseur + Meilleur taux + Disponible jusqu\'à %s + Disponible à partir de %s + Indisponible pour cette paire + Permission requise + Conditions d\'utilisation + Aucun jeton trouvé. Veuillez essayer une autre demande + ID : %s + ID de transaction copié + Les informations suivantes sont facultatives. Vous pouvez les effacer si vous ne souhaitez pas les partager. + Dites-nous quelles fonctions vous manquent, et nous essaierons de vous aider. + Veuillez nous dire quelle carte vous avez + Chère équipe de support, + Veuillez nous en dire plus sur votre problème. Chaque petit détail peut nous aider. + Mes suggestions + Impossible de scanner une carte + Commentaires + Commentaires sur Tangem + Impossible d\'envoyer une transaction + Transaction en cours + Le réseau facturera des frais d\'approbation de jeton pour vérifier que vous autorisez l\'utilisation de votre jeton pour l\'échange. + Spécifiez la limite approuvée pour le jeton sélectionné + Montant %s + Pour continuer, accordez aux smart contracts de %1s l\'autorisation d\'utiliser votre %2s + Donner l\'autorisation + Illimité + Commandez + Scannez Touchez, pour modifier le code d\'accès Touchez, pour modifier le mot de passe + Pour créer le portefeuille, appuyez sur la carte comme indiqué ci-dessus et ne la retirez pas jusqu\'à la fin de l\'opération + Appuyez sur la carte n°%s du portefeuille Posez pour scanner Touchez pour signer Posez la carte + Vous avez mis à jour vos données biométriques, scannez votre carte pour entrer + Votre solde doit être supérieur à la valeur des frais pour effectuer un transfert + Solde insuffisant + Vous n\'avez pas assez de Mana pour cette transaction. Veuillez attendre que le Mana soit reconstitué. Votre solde de Mana est de %1$s/%2$s + Mana insuffisant + Vous ne pouvez transférer que %s en raison de la limite de Mana imposée par le réseau Koinos + Limite de Mana + Le réseau Koinos nécessite du Mana pour les frais de réseau. Vous avez %1$s/%2$s Mana + Quantité de Mana + Pour commencer à suivre vos actifs et transactions crypto, ajoutez des jetons + Gérer les jetons + Pour accéder à tous les réseaux, vous devez scanner la carte + Scannez votre carte + Bénéficiez de %1$s frais de service sur les échanges via Changelly du %2$s au %3$s février + Echangez avec Changelly, %s frais + Jetons + Ajouter + Modifier + Capitalisation boursière des crypto + Blockchain sur laquelle la crypto-monnaie a été initialement créée + Réseau natif + L\'utilisation de réseaux non natifs pour les jetons permet l\'interopérabilité entre les blockchains permettant aux actifs d\'être utilisés dans diverses applications décentralisées et smart contracts sur différentes plateformes. Cependant, cela implique souvent un custodial ou un smart contract pour détenir l\'actif original en toute sécurité introduisant une centralisation et un risque de contrepartie. + Blockchain non originale ou principale sur laquelle le jeton est hébergé + Réseaux non natifs + Choisissez les réseaux + Portefeuille + Impossible de trouver ce jeton, vous pouvez l\'ajouter manuellement + + %1$d du %2$d portefeuille + %1$d des %2$d portefeuilles + + Enlever + par exemple, BTC I trust, hodl I must + Votre portfolio a été mis à jour + Le jeton sélectionné n\'est actuellement pas disponible pour des actions dans le portefeuille crypto. Mais ne vous inquiétez pas, vous pouvez exprimer votre intérêt en votant positivement. + Vote positif + Choisissez un portefeuille + Le portefeuille ne prend pas en charge plus d\'un réseau + Pour commencer à acheter, échanger ou recevoir cet actif, ajoutez ce jeton à au moins 1 réseau + Cet actif n\'est pas disponible + Ajouter au portfolio + Mon portfolio + Marché + Pour générer des adresses pour les réseaux sélectionnés, vous devez scanner votre carte Tangem. + Sélectionnez un portefeuille + Trier par + Idées + Liens + Métriques + Performance des prix + Score de sécurité + Vous devez définir un seul code d\'accès pour protéger toutes vos cartes + Protéger + Vous pourrez définir un code d\'accès individuel sur chaque carte plus tard + Personnaliser + Le code d\'accès peut être restauré avec une carte liée. Ne gardez pas toutes les cartes au même endroit. + Restaurer + Choisissez n\'importe quel mot, phrase ou nombre que vous souhaitez comme code d\'accès + Créer un code d\'accès + Entrez à nouveau votre code d\'accès pour éviter une erreur + Saisissez à nouveau votre code d\'accès + Le code d\'accès doit comporter au moins 4 caractères + Le code d\'accès saisi ne correspond pas au code d\'accès initial + Veuillez répéter l\'opération. La carte sera réinitialisée aux paramètres d\'usine. + Erreur d\'activation + Ajouter des jetons + Vous avez ajouté une carte de sauvegarde. Une fois le processus de sauvegarde terminé, vous ne pourrez plus ajouter de cartes de sauvegarde. Si vous avez une autre carte, ajoutez-la à la sauvegarde. Souhaitez-vous poursuivre le processus de sauvegarde ? + Le processus de sauvegarde est partiellement terminé. Vous ne pouvez pas le quitter maintenant. + La phrase secrète est une fonctionnalité de sécurité avancée utilisée par les portefeuilles cryptographiques. Il ajoute un mot ou une phrase supplémentaire de votre choix à votre phrase de récupération déjà existante pour débloquer un tout nouvel ensemble d\'adresses. + Ajouter une carte de sauvegarde + Scannez la carte n°%d + Sauvegarder maintenant + Scannez la carte principale + Continuer vers mon portefeuille + Finaliser la sauvegarde + Recevoir des crypto-monnaies + Scannez la carte principale + Ignorer pour plus tard + Comment ça marche ? + Générons toutes les clés sur votre carte et créons un portefeuille sécurisé Créer un portefeuille + Créer un portefeuille + Autres options + Vos clés seront générées de manière sécurisée à l\'intérieur de la carte. Il n\'y a pas de seed phrase, ce qui signifie que personne ne peut l\'exporter ou la voler. + Générer des clés de manière privée + Votre carte est activée et prête à être utilisée + Succès ! + Dans ce cas, vous devrez recommencer depuis le début. + Voulez-vous quitter le processus d\'activation ? + Initialiser + Un autre portefeuille a déjà été créé sur la carte que vous essayez d\'ajouter. Si vous avez des fonds dans ce portefeuille, veuillez les retirer, puis réinitialiser cette carte et l\'ajouter comme sauvegarde. + Sauvegarde en cours + En savoir plus sur les seed phrases + + Empty + Écrivez ces %d mots dans l\'ordre indiqué ci-dessous et conservez-les dans un endroit sûr et secret. + + Votre seed phrase + + Empty + %d mots + + Pour importer votre portefeuille, entrez votre seed phrase dans le champ ci-dessous + Générer une seed phrase + Importez + Une seed phrase est une série de mots qui vous permet de récupérer votre portefeuille. Contrairement aux clés générées par la carte, les seed phrases ne sont pas protégées et peuvent être copiées et volées. Utilisez cette option à vos propres risques. + Utiliser une seed phrase + Seed phrase invalide. Veuillez vérifier l\'ordre des mots. + Seed phrase invalide. Veuillez vérifier votre orthographe. + Héritage + Pour vérifier si vous avez correctement noté votre seed phrase, veuillez entrer les 2ème, 7ème et 11ème mots + Alors, vérifions + Pour démarrer le processus de sauvegarde, ajoutez jusqu\'à deux cartes de sauvegarde. + Vous pouvez ajouter une carte supplémentaire ou finaliser le processus de sauvegarde + Préparez la carte de sauvegarde avec le numéro %s + Scannez la carte principale pour démarrer le processus de sauvegarde. + Préparez la carte principale avec le numéro %s + Votre carte de portefeuille est configurée et prête à l\'emploi. + Nombre maximum de cartes ajoutées. Finalisez le processus de sauvegarde. + Activation de la carte + Carte de sauvegarde n°%d + Aucune carte de sauvegarde + Une carte de sauvegarde ajoutée + Préparez votre carte + Deux cartes de sauvegarde ajoutées + Pour commencer, rechargez simplement le portefeuille avec n\'importe quel montant + Pour commencer, rechargez simplement le portefeuille avec plus de %1$s %2$s + Acheter des crypto-monnaies + Afficher l\'adresse du portefeuille + Activer un portefeuille + Le processus de jumelage est partiellement terminé. Vous ne pouvez pas le quitter maintenant. + Si le processus de création du portefeuille est interrompu de quelque manière que ce soit, vous devrez recommencer + Vous pouvez sauvegarder vos clés sur jusqu\'à deux autres cartes vierges du Portefeuille Tangem. + Le code d\'accès peut être restauré avec l\'une des cartes de sauvegarde. + Toutes les cartes de sauvegarde peuvent être utilisées comme des cartes entièrement fonctionnelles avec des clés identiques. + Vous pourrez définir un code d\'accès pour protéger vos portefeuilles. + Portefeuille de sauvegarde + Restauration du code d\'accès + Cartes identiques + Code d\'accès + Grouper + Par solde + Organiser les jetons + Dégrouper + Sélectionnez dans la galerie + Paramètres + Vous n\'avez pas donné accès à votre caméra + Accès à la caméra refusé + %1$s (%2$s) sur le réseau %3$s + Envoyez uniquement %s à cette adresse. L\'envoi de toute autre devise entraînera sa perte irréversible. + Participer + Échec du chargement des informations sur le programme de parrainage. Veuillez réessayer plus tard. + Échec du chargement des informations sur le programme de parrainage. Code d\'erreur : %s. Veuillez réessayer plus tard. + Paiements à venir + Vos amis ont acheté + Moins + Plus + Aucun paiement à venir + + pour le portefeuille %d + pour les portefeuilles %d + + Obtiendras ^^%1$s^^ pour chaque portefeuille acheté par votre ami sur votre adresse de réseau %2$s %3$s ^^30 jours après^^ + Vous + Obtiendrez + lors de l\'achat d\'un portefeuille sur tangem.com + %s réduction + Votre ami + Code personnel copié ! + Votre code personnel + Achetez le Portefeuille Tangem avec une remise !\n%s + Référez Tangem à vos amis + Vous avez accepté + En appuyant sur ce bouton, vous acceptez + du programme de parrainage + + %d portefeuille + %d portefeuilles + + Réinitialiser la carte + Je comprends qu\'après avoir effectué cette action, je n\'aurai plus accès au portefeuille actuel + Je comprends que je ne peux pas utiliser cette carte pour récupérer mon code d\'accès sur les autres cartes du portefeuille actuel + La réinitialisation aux paramètres d\'usine supprimera complètement le portefeuille de la carte sélectionnée. Vous ne pourrez pas restaurer le portefeuille actuel ni utiliser la carte pour récupérer le code d\'accès. + La réinitialisation aux paramètres d\'usine supprimera complètement le portefeuille de la carte sélectionnée et le supprimera de l\'application. Vous ne pourrez pas restaurer le portefeuille actuel. + Avez-vous une carte bancaire d\'un autre pays et un permis de séjour ou une inscription en dehors de la Fédération de Russie ? + Les cartes bancaires russes ne sont actuellement pas acceptées + Connectez-vous à l\'application et vérifiez votre solde sans scanner la carte + Accéder à l\'application + Autoriser l\'utilisation de la biométrie + La biométrie sera demandée à la place du code d\'accès pour les interactions avec votre portefeuille + Code d\'accès + Il semble que vous ayez désactivé l\'authentification biométrique, elle est nécessaire pour sauvegarder les portefeuilles + Activer l\'autorisation biométrique + Souhaitez-vous utiliser la biométrie ? + Notez qu\'effectuer une transaction avec vos fonds nécessitera toujours votre carte + Scannez votre carte + Scannez la carte pour modifier ses paramètres. Les modifications n\'affecteront que la carte que vous avez scannée et n\'affecteront pas les autres cartes liées à votre portefeuille. + Préparez votre carte ! + Déjà inclus dans l\'adresse saisie + Le montant de la commission est %s fois le montant recommandé. Assurez-vous que les paramètres personnalisés sont corrects. + Vous avez spécifié une commission inférieure au montant recommandé, ce qui pourrait entraîner un retard dans votre transaction. Continuer? + Raison : %1$s\nCode : %2$s + La transaction est incomplète Somme + Vous pouvez définir vos frais de transaction en ajustant la valeur dans le champ Satoshi par vByte. + Les frais qui seront facturés pour votre transaction. Vous pouvez définir votre propre valeur. + Frais maximum + Il s\'agit du coût que vous êtes prêt à payer pour chaque unité de gaz. Plus le prix du gaz est élevé, plus votre transaction sera traitée rapidement. (Frais de priorité inclus) + Frais de priorité + Les frais qu\'un utilisateur peut payer aux mineurs ou aux validateurs pour accélérer l\'inclusion de leur transaction dans un bloc. + Les frais requis pour l\'utilisation de chaque sortie de transaction non dépensée (UTXO) dans le réseau Kaspa. Plus vous utilisez d’UTXO dans une transaction, plus les frais seront élevés. + KAS pour UTXO + %1$s, %2$s Adresse + Destination Tag + Entrez l\'adresse L\'adresse est la même que celle de votre portefeuille + Tag invalide. Il ne sera pas ajouté à la transaction. + Mémo invalide. Il ne sera pas ajouté à la transaction. Tag Memo Inclure les commissions Bas Normal Priorité + Vérifiez votre connexion réseau + Informations sur les frais de réseau inaccessibles + De + Limite de gaz + Il s\'agit du montant maximal de gaz qui sera dépensé pour effectuer une transaction ou un contrat. Une limite de gaz empêche des frais imprévus ou illimités lors de l\'exécution d\'une transaction. + Prix ​​du gaz + Il s\'agit du coût que vous êtes prêt à payer pour chaque unité de gaz. Plus le prix du gaz est élevé, plus votre transaction sera traitée rapidement. + Max Somme maximale + Frais jusqu\'à + Memo invalide + Couverture des frais de réseau + Fonds insuffisants pour le transfert, car le total des frais et du montant du transfert dépasse le solde existant + Le total dépasse le solde + Le compte sera effacé de la blockchain si un solde descend en dessous du dépôt existentiel. Veuillez en laisser %s sur votre solde. + Dépôt existentiel + Le montant de la commission est %s fois le montant recommandé. Assurez-vous que les paramètres personnalisés sont corrects. + Les frais de douane sont élevés + En raison des particularités du réseau %1$s, les frais de transfert de la totalité du solde sont plus élevés. Pour réduire la commission, vous pouvez en laisser %2$s. + Les frais sont plus élevés + La commission incluse dépasse le montant du transfert, ce qui entraîne une valeur négative + Montant invalide + Le montant minimum d\'envoi est de %1$s. Veuillez vous assurer que le solde restant après l\'envoi ne sera pas inférieur à %2$s. + Le compte cible n\'est pas créé. Veuillez modifier le montant à envoyer. + Le montant à envoyer doit être d\'au moins %s + Quitter %s + Réduire de %s + Réduire à %s + Veuillez noter que votre transaction peut subir des retards dans certains paramètres de frais + Des retards de transaction sont possibles + En raison de %1$s limitations, seuls %2$s UTXO peuvent s\'intégrer dans une seule transaction. Cela signifie que vous ne pouvez en envoyer que %3$s ou moins. Vous devez réduire le montant. + Limitation des transactions + Facultatif + Veuillez aligner votre code QR avec le carré pour le scanner. Assurez-vous de scanner l\'adresse du réseau %s. + Récent + Destinataire + Adresse non valide + Assurez-vous que l\'adresse du portefeuille de réception est sur le réseau %s pour éviter de perdre vos jetons + Envoyer à + Un Memo/Destination Tag est un identifiant unique permettant de différencier les transactions envoyées au même destinataire sur le même réseau. Attention : L\'omission d\'un mémo peut entraîner des fonds mal placés + Mes portefeuilles + Un moyen de mesurer les frais de transaction Bitcoin. Il indique le nombre de la plus petite unité de Bitcoin (Satoshi) pour chaque octet virtuel dans une transaction. Plus le nombre est élevé, plus la transaction sera traitée rapidement par les mineurs. + Satoshi / vByte + En cours d\'envoi + Appuyez sur n\'importe quel champ pour le modifier + Envoyer %s + Vous envoyez **%1$s** incluant des frais de réseau de %2$s + Vous envoyez **%1$s** and %2$s + Envoi de %s Total Sera envoyé %1$s et %2$s ≈ %1$s (incl. les commissions : %2$s) Sera envoyé %s La transaction a été signée avec succès et envoyée au nœud de blockchain. Le solde du portefeuille sera mis à jour après un certain temps + %1$s est un actif du réseau Tron. Pour calculer les frais et effectuer une transaction, déposez du Tron (TRX) sur votre compte. Adresse incorrecte + %1$s (%2$s) + Transaction envoyée + Préparez-vous à numériser la carte que vous souhaitez configurer. + Oublier le portefeuille + Cela supprimera le portefeuille de l\'application. Le portefeuille lui-même peut être ajouté à nouveau. + Nom + Actif + Afin d\'unstaker vos actifs, cliquez ici. + Le pourcentage de rendement annuel que vous pouvez gagner en participant au staking. + APR + Disponible + Taux de récompense moyen + %s profit estimatif + Cote du marché + Métriques + Minimum requis + Aucune récompense à réclamer + Réclamation de récompense + Un moyen de recevoir des récompenses de staking. Il peut être réclamé automatiquement ou manuellement. + Calendrier de récompenses + Il s\'agit d\'un calendrier qui détermine le moment où les participants au staking reçoivent leurs récompenses. + Récompenses à réclamer: %s + Staking %s + Période de détachement + La période que vous devez attendre après avoir demandé le retrait des fonds du staking avant que les jetons ne soient disponibles. + Période d\'échauffement + Le temps imparti pour activer la participation au staking. + Native staking + Le staking vous permet d\'en gagner %1s. Vos récompenses de staking arrivent tous les ~%2s jours. + Gagnez des récompenses de staking + Récompenses + Staker plus + Non-staké + Vérifiez non-stakés pour réclamer vos actifs + Validateur + Stockez vos actifs crypto en toute sécurité tout en conservant les clés privées contenues dans votre carte + Portefeuille matériel révolutionnaire + Jusqu\'à 3 cartes physiques pour un portefeuille + Sauvegarde ultra sécurisée + Un portefeuille matériel pour vos Bitcoin, Ethereum et de nombreuses autres devises simultanément, le tout dans une seule carte + Des milliers de devises + Utilisez-la en déplacement, n\'importe où, n\'importe quand. Pas de fils ni de piles. Il suffit de taper la carte sur votre téléphone lorsque vous avez besoin de votre crypto. + Le portefeuille pour tous + Découvrez Tangem + Échangez, achetez des NFT, faites des prêts et des dépôts dans plus de 100 services décentralisés différents + Compatible Web 3.0 + Le montant comprend :\n• les frais du fournisseur de services\n• les frais de réseau pour l\'envoi de %s depuis l\'échange vers l\'adresse de l\'utilisateur. + Le montant comprend les frais du fournisseur de services. + Frais + Tous les échanges décentralisés nécessitent des approbations pour empêcher les smart contracts d\'accéder à votre portefeuille sans votre permission. Par conception, les smart contracts ne peuvent pas accéder à vos jetons sans votre approbation. En « déverrouillant » vos jetons, vous autorisez le smart contract 1-inch à les dépenser. Les mineurs du réseau reçoivent des frais de gaz (payés par vous) pour enregistrer cette action sur la blockchain. Vous pouvez échanger votre jeton après avoir donné votre approbation. + Approuver + Vous échangez + Échanger ce montant de jetons sélectionnés aura un impact significatif sur les prix et réduira votre résultat. + Fonds insuffisants + Donner l\'autorisation + En cours + Échanger + Vous recevez + Choisir le jeton + non disponible + Soldes masqués + Soldes affichés + Annuler + Cette opération est actuellement indisponible. Veuillez réessayer plus tard. + L\'achat de %s n\'est pas disponible pour le moment. Veuillez vérifier vos mises à jour. + Vous n\'avez pas de fonds à vendre. Renflouez votre compte pour pouvoir vendre des fonds à partir de celui-ci. + Vous n\'avez pas de fonds à envoyer. Renflouez votre compte pour pouvoir envoyer des fonds à partir de celui-ci. + Le service d\'échange %s n\'est pas disponible pour le moment. Veuillez consulter nos mises à jour. + La vente de fonds sera disponible une fois que la ou les transactions en attente dans le réseau %s seront terminées + L\'envoi de fonds sera disponible une fois la ou les transactions en attente dans le réseau %s terminées. + La vente de %s n\'est pas disponible pour le moment. Veuillez consulter nos mises à jour. + Le staking %s n’est pas disponible pour le moment. Veuillez consulter nos mises à jour. + Générer XPUB + Masquer + Vous êtes sur le point de masquer ce jeton de l\'écran principal. Vous pouvez le rajouter à tout moment via la page de gestion des jetons. + Masquer %s + Masquer le jeton + Le Staking vous permet d\'en gagner %1$s et d\'obtenir des récompenses tous les %2$s jours + Gagnez jusqu\'à %s récompense de mise par an + %1$s jeton dans %%image%% %2$s le réseau + Jeton dans le %%image%% %1$s réseau + Le jeton %1$s (%2$s) est la principale devise du réseau %3$s et ne peut pas être masqué tant que vous avez d\'autres jetons de ce réseau dans la liste + Impossible de masquer %s + Échangez ce jeton contre un autre moyennant des frais de service de %1$s du %2$s au %3$s février. + Échangez avec Changelly, %s frais + Échangez maintenant + contrat : %s + Vous n\'avez pas encore de transactions + Échec du chargement de l\'historique des transactions.\nCliquez sur le bouton de rechargement pour mettre à jour les informations. + Adresses multiples + L\'historique des transactions n\'est actuellement pas pris en charge pour cette blockchain. Mais ne vous inquiétez pas, nous y travaillons ! En attendant, vous pouvez le vérifier dans l\'explorateur. + Opération + de : %s + à : %s + Vous avez scanné la même carte. Pour créer un portefeuille jumeau, vous devez scanner la carte portant le numéro %d + Vous avez scanné une mauvaise carte jumelle. S\'il vous plaît, essayez-en un autre + Celle que vous tenez dans vos mains et l\'autre portant le numéro %s\n\nLes deux cartes peuvent être utilisées pour extraire des fonds de ce portefeuille. + Un portefeuille. Deux cartes. + Scannez la carte n°%s + Création du portefeuille + Scannez la carte jumelle n°%s + Préparation de la carte Tangem Twin + Cette action est irréversible. Vous n\'aurez plus accès à l\'ancien portefeuille. + Appuyez sur la carte jumelle avec le numéro %s et ne la retirez pas jusqu\'à la fin de l\'opération + Utilisez %s ou scannez une carte pour avoir accès à votre portefeuille + Restez à jour avec les dernières fonctionnalités et actualités + Soyez le premier informé des nouvelles promotions + Souhaitez-vous utiliser les notifications push? + Ajouter un nouveau portefeuille + Êtes-vous sûr de vouloir supprimer ce portefeuille ? + Une erreur s\'est produite, veuillez scanner votre carte pour vous connecter + Ce portefeuille a déjà été enregistré, vous pouvez en ajouter un autre + Le portefeuille portant le nom %s existe déjà + Nom du portefeuille + Renommer le portefeuille + Tout déverrouiller + Tout déverrouiller avec %s + La blockchain n\'est pas accessible. Réessayez plus tard + Scanner la carte + Demande de signature d\'un message.\n\n%s + Dapp %1$s, demandant de\nsigner la transaction BNB.\n\n%2$s + Ordre de trade pour %1$s\nPrix : %2$s\nMontant à recevoir : %3$s\nMontant à payer : %4$s + Détails de la transaction :\nDe : %1$s\nÀ : %2$s\nMontant : %3$s + Le presse-papiers contient un code WalletConnect. Utilisez la valeur copiée ou scannez le QR-code + Demande de création d\'une transaction pour %1$s\n%2$s\n\nMontant : %3$s\nFrais : %4$s\nTotal : %5$s\nSolde : %6$s + Impossible d\'envoyer la transaction. Fonds insuffisants. + Échec de l\'établissement de la session WalletConnect. Veuillez réessayer plus tard. + Échec de la signature du message. Veuillez réessayer + Échec de l\'établissement de la session WalletConnect : erreur de délai d\'attente. Veuillez réessayer plus tard. + La demande de session contient des blockchains non prises en charge pour la connexion WalletConnect. Blockchains non prises en charge :\n + La connexion avec cette dApp ne peut pas être établie en raison de son implémentation technique. + Nous avons rencontré une erreur inconnue. Message d\'erreur : %s. Si le problème persiste, n\'hésitez pas à contacter notre support + Mauvaise carte sélectionnée dans le Tangem App + Échec de la création de la transaction à partir des données de la Dapp. Code: %s + Nous avons rencontré une erreur inconnue. Code d\'erreur : %d. Si le problème persiste, n\'hésitez pas à contacter notre support + Aucune session WalletConnect ouverte + Oups. Aucune session. + Échec de l\'appairage de la session WalletConnect : %1$s + Coller depuis le presse-papiers + Message pour %1$s :\n%2$s + Demande de démarrage d\'une session pour\n%1$s\nRÉSEAU : %2$s\n\nURL : %3$s + L\'opération n\'a pas pu être effectuée.\n\nVous avez déjà établi une session WalletConnect avec ces paramètres. + Scanner un nouveau code + Cette carte ne peut pas être utilisée pour établir une session WalletConnect + Ce réseau n\'est pas pris en charge. Veuillez sélectionner un autre réseau. + Sélectionnez un réseau + Sessions WalletConnect + Se connecter aux dApps WalletConnect + La connexion peut prendre quelques secondes + %s Prix du marché + dernières 24h + %s réseau L\'adresse a été copiée avec succès Pas de connexion internet + Paramètres du portefeuille Tangem + Utilisez %s ou scannez une carte pour déverrouiller l\'accès à votre portefeuille + Il semble que l\'activation de la carte ne se soit pas déroulée correctement. Cela peut être dû à un problème avec le module NFC de votre appareil ou à une mauvaise connexion de la carte sur votre appareil. Veuillez contacter notre équipe de support pour obtenir de l’aide. + Erreur d\'activation + Selon les développeurs du réseau BNB, le support de la norme BEP-2\nprendra fin en juin 2024. Pour éviter de perdre des actifs avec cette norme, veuillez les convertir à la norme BEP-20. Utilisez notre service de d\'échange pour les transférer sur le réseau BNB Smart Chain. + BNB Beacon Chain va s\'arrêter de fonctionner + Pas terrible + J\'aime Ok, je l\'ai! + Vraiment cool ! + Rafraîchir + Vous êtes actuellement en mode démo + Mode démo actif + La carte que vous avez scannée est une carte de développeur. Ne l\'utilisez pas pour créer votre portefeuille. + Pas pour les utilisateurs ! + Le réseau %1$s nécessite un dépôt existentiel. Si votre compte descend en dessous de %2$s, il sera désactivé et les fonds restants seront détruits. + Le réseau nécessite un dépôt existentiel + L\'échange sera disponible une fois la %s transaction terminée. + Vous avez une transaction active + L\'approbation de l\'échange est en cours et sera achevée sous peu + Approbation en cours + Le montant minimum d\'échange est de %1$s. Veuillez vous assurer que le solde restant après l\'échange ne sera pas inférieur à %2$s. + Vous n\'avez pas de pièces échangeables %s dans votre liste + Aucun jeton disponible à échanger + Pour effectuer une transaction, vous devez déposer %1$s %2$s + Impossible de couvrir %s frais + Le montant à recevoir doit être d\'au moins %s + Service temporairement indisponible + Le nombre de jetons à échanger ne doit pas dépasser %s + Le montant à échanger doit être d\'au moins %s + Veuillez modifier le montant à échanger + Cette carte pourrait être un échantillon de production ou une contrefaçon + Échec de la vérification d\'authenticité + Associer + Ce jeton doit être associé à votre compte Hedera avant que vous puissiez le recevoir. Frais d\'association ~%1$s %2$s + Ce jeton doit être associé à votre compte Hedera avant que vous puissiez le recevoir + Associez votre jeton + %s insuffisant. Renflouez votre compte Hedera pour associer ce jeton + Il ne reste que %s signatures sur cette carte. Vous devez retirer tous vos fonds. + Faible nombre de signatures + Les jetons sur différents réseaux peuvent avoir des adresses différentes. Vérifiez bien que votre adresse correspond au réseau lorsque vous transférez des fonds. + + Utilisez votre carte pour obtenir une adresse pour le réseau %d + Utilisez votre carte pour obtenir des adresses pour les réseaux %d + + Certaines adresses sont manquantes + Le réseau est actuellement inaccessible. Veuillez réessayer plus tard. + Le réseau est inaccessible + Renflouez votre portefeuille + Votre portefeuille n\'a pas été sauvegardé. Effectuez cette procédure pour protéger vos actifs dès maintenant. + Sauvegarde manquante + Cette carte a déjà été utilisée pour des transactions. Si elle provient d\'une source non fiable, envisagez de retirer tous les fonds. S\'il s\'agit de votre carte, aucune action n\'est requise. + La carte a déjà signé des transactions + Votre avis nous motive à améliorer encore le Portefeuille Tangem + Vous appréciez Tangem ? + Vous devez associer votre jeton avant de recevoir des jetons + Frais de location de réseau requis + %1$s s\'agit d\'un actif du réseau %2$s. Pour effectuer une transaction %3$s, vous devez déposer une certaine quantité de %4$s (%5$s) pour couvrir les frais de réseau. + %1$s insuffisant pour couvrir les frais de réseau + Le réseau Solana est encombré. Si votre transaction n\'est pas traitée dans les 2 minutes, veuillez répéter la transaction. + Alerte réseau Solana + Le réseau Solana facture un loyer de %1$s tous les 2 jours. Les comptes qui ne peuvent pas se permettre le loyer sont purgés du réseau. Déposez sur votre compte plus de %2$s pour l\'utiliser gratuitement. + Certains réseaux sont actuellement inaccessibles. Veuillez réessayer plus tard. + Certains réseaux sont inaccessibles + Il s\'agit d\'une carte Testnet. Elle ne peut pas traiter les transactions et ne doit être utilisée qu\'à des fins de test et de développement. + À des fins de test uniquement + Ignorer + Vous avez une sauvegarde interrompue. Voulez-vous la reprendre ? + Oui, reprendre + Ignorer + Si vous ignorez la sauvegarde maintenant, vous devrez réinitialiser les cartes aux paramètres d\'usine pour recommencer + Reprendre la sauvegarde + C\'est une action irréversible + Se connecter avec %s + Scanner la carte + Utiliser %s ou scanner une carte pour accéder à l\'application + Bon retour ! diff --git a/core/res/src/main/res/values-it/strings.xml b/core/res/src/main/res/values-it/strings.xml index e7caa7829e..b8860bd7d8 100644 --- a/core/res/src/main/res/values-it/strings.xml +++ b/core/res/src/main/res/values-it/strings.xml @@ -14,6 +14,7 @@ Mantieni le modifiche Invia Con successo + Avviso Codice di accesso Prima di scansionare la carta sarà necessario inserire il codice di accesso corretto Mantenimento della carta diff --git a/core/res/src/main/res/values-ja/strings-blockchain.xml b/core/res/src/main/res/values-ja/strings-blockchain.xml new file mode 100644 index 0000000000..5c5a94491d --- /dev/null +++ b/core/res/src/main/res/values-ja/strings-blockchain.xml @@ -0,0 +1,25 @@ + + + デフォルト + レガシー + 手数料を取得できませんでした + %1$sの制限により、1つのトランザクションに収まるUTXOは%2$d個のみです。つまり、 %3$s以下しか送信できません。量を減らす必要があります。 + 取引に必要な資金が不足しています。アカウントに入金してください。 + エラーが発生しました。コード: %s 。 + %1$sネットワークを使用するには、アカウント準備金 ( %2$s %3$s ) を支払う必要があります。これにより、その金額はロックされ、無期限に非表示になります。 + 送信先アカウントが有効ではありません。%s 以上を送信してアカウントを有効にしてください。 + アカウントを作成するには、このアドレスに資金を送金してください + 最低額は%sです + 値が小さすぎます + 無効な手数料 + 最低残高は%sです + 対象アカウントは作成されていません。送信金額は、%s + 手数料またはそれ以上である必要があります。 + 不明なエラー + 金額が残高を超えています + 無効な金額 + 手数料が残高を超えています + 合計金額が残高を超えています + いいえ、すべて送信します + %s XTZを減らす + 次回ウォレットにチャージするときに手数料の増加を避けるには、金額を%s XTZ減らしてください。 + diff --git a/core/res/src/main/res/values-ja/strings.xml b/core/res/src/main/res/values-ja/strings.xml new file mode 100644 index 0000000000..d9c7168c7a --- /dev/null +++ b/core/res/src/main/res/values-ja/strings.xml @@ -0,0 +1,884 @@ + + + ネットワークを選択 + カスタムトークンの追加 + トークンの管理 + このアドレスには%3$s ネットワークから%1$s (%2$s) のみを送信してください。他のトークンやネットワークを使用すると、資金を失う可能性があります。 + スキャン方法 + サポートをリクエストする + もう一度やり直してください + この機能はデモモードでは無効です + 理由: %s + 取引を送信できません + 選択したものは%1$sネットワークをサポートしていません。 + %1$sブロックチェーンの暗号化を有効にするには、ウォレットを工場出荷時の設定にリセットする必要があります。リセットする前に出金して、資金が失われないようにしてから、リセット処理を完了してください。リセット後は、現在のウォレットにアクセスできなくなります。 + %1$s ネットワークのトークンは、ファームウェアの制限により、このカードではサポートされていません。 + カードのスキャンに問題がありますか? + このカードはこのアプリでは使用できません。 + デフォルト手数料 + デフォルト手数料を有効にすると、取引手数料が自動的に設定され、送金時に手数料ページを表示する必要がなくなります。必要に応じて、いつでもこのページに戻ることができます。 + 設定に移動して、Tangemアプリで生体認証を有効にします。 + 生体認証を有効にする + これにより、保存されているウォレットアクセスコードがすべて削除されます。ウォレットでの今後の操作には、アクセスコードの送信が必要になります。 + 保存したカードを削除すると、保存されているすべてのウォレットとそのアクセスコードがアプリから削除されます。 + アクセスコードを保存 + カードとのやり取りには、アクセスコードの代わりに生体認証が要求されます。 + ウォレットをアプリに保存する + すべてのウォレットをTangemアプリにリンクできるようにします。アプリのロックを解除するには、生体認証が必要になります。取引の署名には、Tangemカードをタップする必要があります。 + ダーク + ライト + システムのデフォルト + テーマ + アプリ設定 + 残高を表示または非表示にするには、デバイスの画面を下向きにするか、設定でオフにしてください。 + 今後表示しない + わかりました + 残高は非表示 + カードをスキャンしてください + 30秒後に再試行するか、カードをスキャンしてください。 + 試行回数が多すぎます + お使いの携帯電話で生体認証が無効になっているため、アプリにウォレットを保存できません。ウォレットを保存するには、携帯電話の設定で生体認証機能を有効にしてください。 + バックアップ処理を開始する + 法定通貨カードまたは銀行口座から + + %d カード + + このカードを使用して、このウォレット内の他のカードのアクセスコードをリセットしたくない場合は、このオプションを無効にしてください。これにより、このカードのアクセスコードもリセットできなくなりますのでご注意ください。 + このカードを使用して、このウォレット内の他のカードのアクセスコードをリセットできます。 + アクセスコードの復元 + リセット + 本当に実行しますか? + アクセスコードの変更 + アクセスコードは、このカードのみで変更されます + 選択したウォレットのすべてのカードが、工場出荷時の設定にリセットされました。これで、新しいウォレットを作成できます。 + リセット完了 + このウォレットの次のカードをリセットしますか? + カードのリセット + このウォレットのすべてのカードをリセットすることをお勧めします。 + すべてのカードのリセットが完了していません。 + 工場出荷時の設定にリセット + セキュリティ・モード + カード設定 + ネットワーク手数料に加えて、Cardanoネットワークは%2$sトークンで取引する際に%1$s ADAを請求します。 + Cardanoの取引要件 + %1$s 取引を行うには、いくらかのADAを入金し、ネットワーク手数料と最小ADA (5ADAを推奨) をカバーする必要があります。 + トークンを送るために必要なADAが不足しています。 + カルダノブロックチェーン上にトークンを持っているため、いくらかのADA残高を維持する必要があります。 + ADAが不足しています。 + 受け入れる + アクセスが拒否されました + すべて + 許可する + 適用する + 承認 + 承認 + 注意 + 残高: %s + 残高 + 生体認証 + 生体認証 + 買う + %1$sへ移動 + カメラへのアクセスを許可していません。プライバシー設定を調整してください。 + キャンセル + 報酬を受け取る + 閉じる + 続ける + コピー + アドレスをコピー + 作成 + 設定 + + %d 日 + + 削除 + 無効 + 完了 + 有効にする + 有効 + エラー + 移動する + 取引履歴を調べる + エクスプローラー + 手数料 + ネットワーク手数料は、取引の処理と確認のためにユーザーが支払う料金です。手数料の額は、ネットワークの混雑さ、取引のサイズ、実行の優先度によって左右されます。 %s + 速い + マーケット + 遅い + 速度と料金 + アドレスを取得する + プロバイダーへ移動 + トークンへ移動 + インポート + 後で + ロックされています + メインネットワーク + ネットワーク手数料 + 送金額は、選択された手数料レベルをカバーするため、%1$s (%2$s) 減額されます。 + + いいえ + アドレスがありません + + わかりました + プライマリーカード + パスフレーズ + ペースト + %1$s-%2$s + 続きを読む + 受け取る + 拒否 + リロード + 名前を変更 + 保存 + 変更内容を保存 + 検索 + トークンを検索 + シードフレーズ + アクションを選択 + 売る + 送る + サーバーが利用できません。しばらくしてからもう一度お試しください。 + 共有 + 署名 + 署名して送信 + ステーキング + ステーキング + 始める + 送信 + 成功 + サポート + スワップ + 利用規約 + 今日 + 取引が失敗しました + 取引 + 送金 + わかりました + エラーが発生しました。もう一度お試しください。 + アクセスできません + ステーキング解除 + はい + コントラクトアドレスをコピーしました! + 利用可能なネットワーク + トークンを追加 + コントラクトアドレス + コントラクトアドレスが無効です + ネットワークを選択してください + 小数は%liまでの有効な整数である必要があります + カスタム派生パス + 例:m/00\'/0000\'/0\'/0/0 + カスタム派生パスを入力 + 小数 + 派生パス + デフォルト + BIP44コインタイプ + 入力した派生パスは無効です + USD Coin + 名前 + 未選択 + ネットワーク + トークン・ネットワーク + Tangemでネイティブにサポートされていないトークンを手動で追加できます。 + 例: USDC + シンボル + トークン・シンボル + このトークン/ネットワークはすでにリストに追加されています + トークンは誰でも作成できることに注意してください。詐欺トークンの追加には注意が必要ですが、費用はかかりません。 + 詐欺トークンを追加することには注意してください。費用がかからない場合があります。 + トークンは誰でも作成できることに注意してください。 + Tangemウォレットを購入 + チャット + アクセスコード + カードをスキャンする前に、正しいアクセスコードを送信する必要があります。 + 長くタップ + このメカニズムは、カードに対する近接攻撃から保護します。コマンドの受信と実行の間に遅延を強制します。 + パスコード + カードの状態の変更を伴うコマンドを実行する前に、パスコードを入力する必要があります。 + 紹介プログラム + デバイスの画面を下に向けると、残高をすばやく非表示にしたり表示したりできます。 + %sハッシュ + カードID + サポートへのお問い合わせ + 他のカードをリンクする + アプリ通貨 + フリップして残高を非表示にする + 発行者 + 署名済み + フィードバックを送信 + 詳細 + インターネット接続を確認するか、別のネットワークに切り替えてください。 + 利用規約 + 別のウォレットのカードを使用しました。このウォレットに関連付けられているカードをタップしてください。 + マイトークン + まだトークンを追加していません。マーケットからトークンを追加して交換してください。 + %sとの交換はできません + 提供元 + ステータス + Tangemは、各プロバイダーの条件に従って、サードパーティプロバイダーを介してトークンスワップを提供します。 + プロバイダーを選択 + エラーが発生しました。コード: %s + おっと!このプロバイダーで選択したペアを交換することは一時的にできません。後でもう一度お試しください。(Code:%s) + 選択したプロバイダーは現在利用できません。しばらくしてからもう一度お試しください。(コード: %s ) + 現在、交換はご利用いただけません。しばらくしてからもう一度お試しください。(コード: %s ) + 推定金額 + %sによる交換 + 返金を受けるには、プロバイダーのウェブサイトにアクセスしてください。 + プロバイダーによる操作が失敗しました。 + OKXまたはブリッジのルールにより、取引金額は%1$sでウォレットに返金されました。%2$s + 金額は %1$s(%2$sネットワーク)で返金されました + 確認するには、プロバイダーのウェブサイトにアクセスしてください。 + プロバイダーによる本人確認手続きが必要です。 + キャンセルされました + 確認済み + 確認中 + 確認中... + 交換済み + 交換中 + 交換中... + 失敗しました + 入金済み + 入金待ち + 入金待ち... + 返金済み + あなたへ送金しています + 送金中... + 送金済み + プロバイダー提供のデータ。推定額は市場動向により変更される場合があります。 + 交換ステータス + 確認が必要です + 取引ハッシュを待機中 + ウォレットに追加されたすべてのトークンのリスト + 最良のレートを取得しています... + 変動レート + スワップ機能を使用すると、プロバイダーの%sに同意したことになります。 + スワップ機能を使用すると、プロバイダーの%1$sおよび%2$sに同意したことになります。 + さらに多くのプロバイダーを追加予定です。 \nお楽しみに。 + プライバシーポリシー + プロバイダー + ベストレート + 最大 %s まで使用可能 + %s 以上で利用可能 + このペアは利用できません + 許可が必要です + 推奨 + 利用規約 + トークンが見つかりません。別のリクエストをお試しください。 + ID: %s + 取引IDをコピーしました + ウォレット内の別の通貨から + 以下の情報はオプションです。共有したくない場合は消去できます。 + どのような機能が不足しているかを教えください。解決できるよう尽力致します。 + お持ちのカードについて教えてください + サポートチームの皆さん、こんにちは。 + 問題について詳しく教えてください。どんな些細なことでも役に立ちます。 + 私の提案 + カードをスキャンできません + フィードバック + Tangemへのフィードバック + 取引を送信できません + 現在の取引 + ネットワークは、あなたがトークンのスワップを承認していることを確認するために、トークン承認手数料を請求します。 + 選択したトークンの承認制限を指定します + 金額%s + 承認機能は、別のアドレスに特定の量のトークンを使用する許可を与えるために必要です。設計上スマートコントラクトは、承認しない限りトークンにアクセスできません。トークンを「ロック解除」すると、StakeKitスマート コントラクトがトークンを使用する権限が与えられます。ネットワークのマイナーは、このアクションをブロックチェーンに記録するためにガス料金(あなたが支払う)を受け取ります。承認後、トークンをステーキングできます。 + 続行するには、StakeKitスマートコントラクトが%sを使用することを許可する必要があります + 続行するには、%1sスマートコントラクトに%2sを使用する権限を付与してください + 許可を与える + 無制限 + カードを注文 + カードをスキャン + アクセスコードを変更するには、上図のようにカードをタップし、操作が終了するまで取り外さないでください。 + パスコードを変更するには、上記のようにカードをタップし、操作が終了するまで取り外さないでください。 + ウォレットを作成するには、上記のようにカードをタップし、操作が終了するまで取り外さないでください。 + ウォレットの%s番目のカードをタップします + タップしてスキャン + タップして署名 + カードをタップ + 生体認証を更新しました。カードをスキャンして入ってください。 + 送金するには、残高が手数料額より高くなければなりません。 + 残高不足 + この取引に必要なManaが不足しています。Manaが補充されるまでお待ちください。あなたのMana残高は%1$s/%2$sです。 + Manaが不足しています + KoinosネットワークによるMana制限のため、%s のみ送金できます。 + Mana上限 + Koinosネットワークでは、ネットワーク手数料としてManaが必要です。あなたは%1$s / %2$sManaを持っています。 + Manaレベル + 暗号資産および取引の追跡を開始するには、トークンを追加してください + トークンの管理 + すべてのネットワークにアクセスするには、カードをスキャンする必要があります。 + カードをスキャンする + 2月%2$s - %3$sの期間、Changelly経由のスワップは%1$sのサービス手数料となります。 + Changellyでスワップ、手数料%s + トークン + 追加 + 編集 + コインの時価総額 + この暗号資産が最初に生成されたブロックチェーン + ネイティブ・ネットワーク + 非ネイティブネットワークを使用すると、ブロックチェーン間の相互運用性が実現し、トークンをさまざまな分散型アプリケーションやプラットフォーム間のスマートコントラクトで利用できるようになります。ただし、これには多くの場合、元の資産を安全に保管するためのカストディアンまたはスマートコントラクトが必要となり、中央集権化とカウンターパーティリスクが生じます。 + トークンがホストされているオリジナルまたは主要なブロックチェーンではありません + 非ネイティブ・ネットワーク + ネットワークを選択 + ウォレット + トークンが見つかりませんでした。手動で追加できます。 + + %1$d の %2$d ウォレット\n%1$d の %2$d ウォレット + + 削除 + 例:私はBTCを信じる、HODLしなければならない + ポートフォリオが更新されました + 選択したトークンは現在、暗号資産ウォレット内でのアクションには利用できません。しかし、心配しないでください。賛成票を投じることで関心を表明できます。 + 賛成票を投じる + ウォレットを選択 + ウォレットは複数のネットワークをサポートしていません。 + このアセットの購入、交換、受け取りを開始するには、このトークンを少なくとも1つのネットワークに追加してください。 + このアセットは利用できません + ポートフォリオに追加 + トークンを追加 + 利用可能なネットワーク + 私のポートフォリオ + マーケット + 選択したネットワークのアドレスを生成するには、Tangemカードをスキャンする必要があります。 + データを読み込めません… + クイックアクション + 結果 + 時価総額10万ドル以下のトークンを見る + トークンを表示 + 検索結果はありません + ネットワークを選択 + ウォレットを選択 + 1ヶ月 + 1年 + 24時間 + 3ヶ月 + 6ヶ月 + 7日 + すべて + 経験豊富な買い手 + 格付け + 並べ替え + 上昇率上位 + 下落率上位 + トレンド + %sについて + + %d のレーティングに基づいて + + ブロックチェーンサイト + 買い圧力 + 買い手と売り手の取引量の差 + 循環供給量 + 取引可能で市場に流通しているコインの総数 + 経験豊富な買い手 + 少なくとも100の発信取引を持つネット・バイヤー + 完全希薄化後評価額 + 現在流通していないものも含め、存在する可能性のあるすべてのコインが流通している場合の暗号資産の理論上の合計価値 + ジェネシスの日付 + 高い + ホルダー + 特定の期間内のトークンホルダー数の変化 + インサイト + リンク + 流動性 + 指定された期間中のトークンに利用可能な流動性の変化 + 流動性指数 + 低い + 時価総額 + 暗号資産の市場価値の合計。コインの現在の価格と、流通しているコインの総数を掛けて計算されます。 + 市場格付け + 時価総額に基づくすべてのコイン間の暗号資産評価における位置 + 最大供給量 + 指標 + 公式リンク + 値動き + リポジトリ + セキュリティ・スコア + ソーシャル + 総供給量 + 特定の暗号資産に存在しうるコインまたはトークンの最大数 + 取引量(24時間) + 過去24時間以内に取引された暗号資産の合計額。市場の活発さと流動性を示します。 + すべてのカードを保護するには、単一のアクセスコードを設定する必要があります + 保護する + 後で各カードに個別のアクセスコードを設定できます + パーソナライズする + アクセスコードはリンクされたカード1枚で復元できます。すべてのカードを1か所に保管しないでください。 + 復元する + アクセスコードとして任意の単語、フレーズ、または数字を選択してください + アクセスコードの作成 + 間違いを避けるため、アクセスコードをもう一度入力してください。 + アクセスコードの再入力 + アクセスコードは4文字以上である必要があります + 入力したアクセスコードが、初期アクセスコードと一致しませんでした + 操作を繰り返してください。カードは工場出荷時の設定にリセットされます。 + アクティベーションに失敗しました + トークンを追加する + バックアップカードを1枚追加しました。バックアップ処理が終了すると、これ以上バックアップカードを追加することはできません。もう一枚カードがあれば、バックアップに追加してください。バックアップ処理を続けますか? + バックアップ手続きは部分的に完了しています。現在終了することはできません。 + パスフレーズは、暗号資産ウォレットが使用する高度なセキュリティ機能です。既存のリカバリフレーズに、自分で選択した単語またはフレーズを追加することで、まったく新しいアドレスのロック解除が可能になります。 + バックアップカードを追加する + カード #%d をスキャン + 今すぐバックアップ + プライマリカードをスキャン + ウォレットへ進む + バックアップを完了する + 暗号資産を受け取る + プライマリカードをスキャン + スキップする + どのように機能しますか? + すべての秘密鍵をカード内で生成し、安全なウォレットを作成しましょう + ウォレットを作成する + ウォレットを作成する + その他のオプション + 秘密鍵はカード内で安全に生成されます。シードフレーズは存在しないので、誰もエクスポートしたり盗んだりすることはできません。 + 秘密鍵を非公開で生成する + カードは有効化され、使用可能になりました + 成功! + この場合は、最初からやり直す必要があります。 + アクティベーション処理を途中で終了しますか? + スタート + 追加しようとしているカードには、すでに別のウォレットが作成されています。このウォレットに資金がある場合は、それを引き出してからこのカードをリセットし、バックアップとして追加してください。 + バックアップの作成 + シードフレーズについてもっと読む + + これらの %d 単語を以下の順番通りに書き留め、安全かつ秘密の場所に保管してください。 + + あなたのシードフレーズ + + %d 単語 + + ウォレットをインポートするには、下のフィールドにシードフレーズを入力してください。 + シードフレーズを生成する + ウォレットをインポート + シードフレーズは、ウォレットを復元できる一連の単語です。カードによって生成される秘密鍵とは異なり、シードフレーズは保護されていないため、コピーされて盗まれる可能性があります。このオプションは自己責任で使用してください。 + シードフレーズを使用する + 無効なシードフレーズです。語順を確認してください。 + 無効なシードフレーズです。スペルを確認してください。 + レガシー + シードフレーズを正しく書き込んだかどうかを確認するために、2番目、7番目、11番目の単語を入力してください。 + では、確認してみましょう + バックアップ処理を開始するには、最大2枚のバックアップカードを追加します。 + カードをもう1枚追加するか、バックアップ処理を完了します + 番号%sのバックアップカードを準備してください + プライマリカードをスキャンして、バックアップ処理を開始します。 + 番号%sのプライマリカードを準備してください + ウォレットカードが設定され、使用できるようになりました。 + 最大枚数のカードが追加されました。バックアップ処理を完了します。 + カードの有効化 + バックアップカード # %d + バックアップカードなし + 通知 + バックアップカードが1枚追加されました + カードを準備してください + バックアップカード2枚が追加されました + 始めるには、ウォレットに任意の金額を入金するだけです + 始めるには、ウォレットに%1$s %2$s以上入金するだけです + 暗号資産を購入する + ウォレットのアドレスを表示する + ウォレットを有効化する + ツイン化プロセスは部分的に完了しています。現在終了することはできません。 + ウォレットの作成プロセスが何らかの理由で中断された場合は、最初からやり直す必要があります。 + 秘密鍵のバックアップは、未使用のTangemウォレットカード2枚まで可能です。 + アクセスコードは、バックアップカード1枚を使用して復元できます。 + すべてのバックアップカードは同一の秘密鍵を使用しており、すべての機能を使用できます。 + ウォレットを保護するためにアクセスコードを設定できます。 + バックアップウォレット + アクセスコードの復元 + 同一のカード + アクセスコード + グループ + 残高順 + トークンを整理する + グループ解除 + ギャラリーから選択 + 設定 + カメラへのアクセスを許可していません。 + カメラへのアクセスが拒否されました + %3$sネットワーク上の%1$s ( %2$s ) + このアドレスには%sのみを送金してください。他のトークンを送信すると、取り返しのつかない損失が発生します。 + QRコードを表示するか、アドレスを共有します + 参加する + 紹介プログラムに関する情報を読み込めませんでした。しばらくしてからもう一度お試しください。 + 紹介プログラムに関する情報を読み込めませんでした。エラー コード: %s 。しばらくしてからもう一度お試しください。 + 今後のお支払い + あなたの友達が購入した + 少ない + 多い + お支払いの予定はありません + + %dのウォレット + + あなたの%2$sネットワークアドレス%3$sで友達が購入したウォレットごとに、^^30日後 ^^^^ %1$s ^^ をゲットできます + あなた + 以下を取得します。 + tangem.comでウォレットを購入するとき + %s割引 + あなたの友達 + パーソナルコードをコピーしました! + パーソナルコード + Tangemウォレットを割引価格で購入!\n%s + 友達にTangemを紹介 + 承諾しました + このボタンをタップすると、同意したことになります + 紹介プログラム + + %d ウォレット + + カードをリセットする + この操作を実行すると、現在のウォレットにアクセスできなくなることを理解しています。 + このカードを使用して、現在のウォレットの他のカードのアクセスコードを回復させられないことを認識しています。 + 工場出荷時設定にリセットすると、選択したカードからウォレットが完全に削除されます。現在のウォレットを復元したり、カードを使用してアクセスコードを回復したりすることはできません。 + 工場出荷時の状態にリセットすると、選択したカードからウォレットが完全に削除され、アプリから削除されます。現在のウォレットを復元することはできません。 + 他の国の銀行カードと、ロシア連邦外での居住許可証または登録をお持ちですか? + ロシアの銀行カードは現在ご利用いただけません + アプリにログインして、カードをスキャンせずに残高を確認できます + アプリにアクセスする + 生体認証の使用を許可する + ウォレットの操作には、アクセスコードの代わりに生体認証が要求されます。 + アクセスコード + 生体認証が無効になっているようです。ウォレットを保存する必要があります。 + 生体認証を有効にする + 生体認証を使用しますか? + 資金を使って取引を行うには、カードが必要になりますのでご注意ください。 + カードをスキャン + カードをスキャンして設定を変更します。変更はスキャンしたカードにのみ影響し、ウォレットに関連付けられている他のカードには影響しません。 + カードを準備してください! + 入力したアドレスにすでに含まれています + 手数料額が推奨額の%s倍となっています。カスタム設定が正しいことを再度確認してください。 + 推奨手数料を下回る手数料が指定されたため、取引に遅れが生じる可能性があります。続行しますか? + 理由: %1$s \nコード: %2$s + 取引は完了していません + 金額 + 取引手数料は、vByteフィールドのSatoshiの値を調整して設定できます。 + 取引にかかる手数料です。自由に設定できます。 + 最大手数料 + 各ガスに支払う最大コストです。ガス代が高いほど、トランザクションは早く処理されます。(優先手数料を含みます) + 優先手数料 + ブロックに自分の取引が含まれるのを早めるために、ユーザーがマイナーやバリデーターに支払う手数料です。 + Kaspaネットワークで未使用の取引出力(UTXO)を使用するために必要な手数料です。取引で使用するUTXOが多ければ多いほど、手数料は高くなります。 + UTXOあたりのKAS + %1$s 、 %2$s + アドレス + 宛先タグ + アドレスを入力 + アドレスはウォレットアドレスと同じです + 無効なタグです。取引には追加されません。 + 無効なメモです。取引には追加されません。 + タグ + メモ + 手数料込み + 低い + 普通 + 優先 + ネットワーク接続を確認してください + ネットワーク手数料についての情報にアクセスできません + より + ガス上限 + これは、取引または契約を完了するために使用されるガスの最大額です。ガス上限を設定することで、取引実行時に予期せぬ請求や無制限の請求を防ぐことができます。 + ガス代 + 各ガスに支払う最大コストです。ガス代が高いほど、取引は早く処理されます。 + 最大 + 最大金額 + 最大手数料 + 無効なメモ + ネットワーク手数料のカバー + 手数料と送金額の合計が残高を超えているため、送金に必要な資金が不足しています。 + 合計が残高を超えています + 残高が最低量を下回ると、当アカウントはブロックチェーンから消去されます。残高に%sを残しておいてください。 + アカウント維持に必要な最低残高 + 手数料額が推奨額の%s倍となっています。カスタム設定が正しいことを再度確認してください。 + カスタム手数料が高くなっています + %1$sネットワークの特殊性により、残高全体を転送する場合の手数料は高くなります。手数料を削減するには、 %2$sを残します。 + 手数料が高くなっています + 手数料が送金金額を超えており、マイナスの値になってしまいます。 + 無効な金額 + 最低送金金額は%1$sです。送金後の残高が%2$s未満にならないようにしてください。 + 対象口座が作成されていません。送金額を変更してください。 + 送金額は%s以上である必要があります。 + %s を残します + %sを減らす + %s に減らします。 + 手数料の設定によっては、取引に遅延が発生する場合があります。 + 取引遅延の可能性があります + %1$sの制限により、1つの取引に収まるUTXOは%2$s個のみです。つまり、 %3$s個以下しか送信できません。量を減らす必要があります。 + 取引制限 + オプション + QRコードを正方形に合わせてスキャンしてください。%s ネットワークアドレスをスキャンしてください。 + 最近の取引 + 受取人 + 有効なアドレスではありません + トークンを失わないように、受信ウォレットアドレスが%sネットワーク上にあることを確認してください。 + 送金先 + メモ/宛先タグは、同じネットワーク上の同じ受信者に送信された取引を区別するためのユニークなIDです。注意:メモを省略すると、資金の行き違いにつながる可能性があります。 + マイウォレット + Bitcoinの取引手数料を測定する方法。取引における各仮想バイトの最小Bitcoin単位(Satoshi)の数を示します。数値が高いほど、マイナーによる取引の処理速度が速くなります。 + Satoshi / vByte + 送金中... + 変更するには任意の箇所をタップしてください + %sを送金する + **%1$s** を送金する (ネットワーク手数料%2$sを含む) + **%1$s** と %2$s を送金しています。 + %sを送信しています + 合計 + %1$sと%2$sが送信されます + ≈ %1$s (%2$s: 手数料を含む) + %sが送信されます + 取引は正常に署名され、ブロックチェーンノードに送信されました。ウォレットの残高はしばらくして更新されます。 + %1$sはTronネットワークのアセットです。手数料を計算して取引を行うには、アカウントにTron(TRX)を入金する必要があります。 + 無効なアドレス + %1$s ( %2$s ) + 取引が送信されました + セットアップしたいカードをスキャンするために準備してください。 + ウォレット削除 + これにより、ウォレットがアプリから削除されます。ウォレットは再度追加できます。 + 名前 + アクティブ + 資産のステーキングを解除するには、ここをクリックしてください。 + ステーキング金額は %s 以上である必要があります + ステーキング解除分を請求する + APY + ステーキングに参加することで得られる年間収益率。 + APR + 利用可能 + 平均報酬率 + ステーキングとは? + %s 推定利益 + 市場評価 + 指標 + 最低要件 + 請求できる報酬はありません + 請求中の報酬 + ステーキング報酬を受け取る方法。自動または手動で請求できます。 + 報酬スケジュール + これは、ステーキングの参加者がいつ報酬を受け取るかを決定するスケジュールです。 + 受け取る報酬: %s + ステーキング%s + 解約完了までの期間 + ステーキングから資金の引き出しを要求した後、トークンが利用可能になるまでの待機期間。 + ウォームアップ期間 + ステーキングへの参加を有効にするために割り当てられた時間。 + %sをステーキングする + 移行 + ネイティブステーキング + ステーキングにより%1sを獲得できます。ステーキング報酬は ~ %2s日ごとに届きます。 + ステーキング報酬を獲得 + ステーキング解除後、報酬の獲得はすぐに停止します。ステーキング解除プロセスには%sかかります。 + 再結束 + 再度ステーキングする + 報酬をステーキングする + 取り消す + 再投票 + 報酬 + ステーキングはロックされています + もっとステーキングする + ステーキング解除はロックされています + スタックされていない + 資産を請求するために、unstakedを確認してください + ステーキング解除 + バリデーター + 投票する + 投票はロックされています + 引き出す + カード内に秘密鍵を保管しながら暗号資産を安全に保管します + 革新的なハードウェアウォレット + 1つのウォレットに最大3枚のカード + 安全なバックアップ + ビットコイン、イーサリアム、その他多くの暗号資産を同時に管理できるハードウェアウォレット – オールインワンカード + 数千の通貨 + 外出先でも、いつでもどこでも使用できます。コードや電池は不要です。暗号資産が必要なときに、カードをスマートフォンにタップするだけです。 + すべての人のためのウォレット + Tangemのご紹介 + 100種類以上の分散型サービスで、NFTの交換・購入や、借入・預金を行うことができます。 + Web3.0対応 + より多くのトークンをより良いレートで、ウォレット内にて直接交換します。 + 新しいスワッププロバイダーが利用可能になりました! + この金額には以下が含まれます:\n- サービスプロバイダーの手数料\n- 取引所からユーザーのアドレスに%s を送り返すためのネットワーク手数料。 + この金額には、サービスプロバイダーの手数料が含まれています。 + 手数料 + すべての分散型取引所は、スマートコントラクトがあなたの許可なくウォレットにアクセスするのを防ぐために承認を必要とします。設計上、スマートコントラクトは承認なしでトークンにアクセスできません。トークンを「ロック解除」することで、あなたは1-inchのスマートコントラクトがトークンを使うことを承認します。ネットワークのマイナーは、このアクションをブロックチェーンに記録するためのガス料金(あなたが支払う)を受け取ります。承認後、トークンを交換することができます。 + 承認 + 手数料見積りエラーです。サポートにフィードバックをお送りください。 + スワップする + 選択したトークンをこの量を交換すると、価格に大きな影響が生じ、結果が減少します。 + 残高不足 + 許可を与える + 進行中 + スワップ + 受け取る + トークンを選択 + 利用不可 + 残高非表示 + 残高表示 + 元に戻す + この操作は現在利用できません。しばらくしてからもう一度お試しください。 + 現在、 %sの買付はご利用いただけません。アップデート情報をご確認ください。 + 売却できる資金がありません。アカウントに入金して、売却できるようにしてください。 + 送金する資金がありません。アカウントに入金して、送金できるようにしてください。 + 現在、 %sの交換はご利用いただけません。アップデート情報を確認してください。 + ネットワーク%s内の保留中の取引が完了すると、資金の売却が可能になります。 + ネットワーク%s内の保留中の取引が完了すると、送金が可能になります。 + 現在、 %sの売却はご利用いただけません。アップデート情報をご確認ください。 + %s のステーキングは現在ご利用いただけません。最新情報をご確認ください。 + XPUBを生成する + 非表示 + このトークンをメイン画面から非表示にします。トークンの管理ページからいつでも再度追加できます。 + %sを非表示 + トークンを非表示 + ステーキングにより、 %1$sを獲得し、 %2$s日ごとに報酬を受け取ることができます。 + 年間最大%sのステーキング報酬を獲得 + %%image%% %2$s ネットワークの %1$s トークン + %%image%% %1$sネットワーク上のトークン + %1$s ( %2$s ) トークンは%3$sネットワークの主要通貨であり、このネットワーク上の他のトークンがリストにある限り、非表示にすることはできません。 + %sを非表示にできません + このトークンは、2月%2$s-%3$s の間、%1$s のサービス手数料で別のトークンと交換できます。 + Changellyでスワップ、手数料%s + 今すぐスワップ + コントラクト: %s + まだ取引はありません + 取引履歴の読み込みに失敗しました。\n情報を更新するには、リロードボタンをクリックしてください。 + 複数のアドレス + 現在、このブロックチェーンでは取引履歴はサポートされていません。しかしご心配なく!弊社で対応中です。その間、エクスプローラーで確認することができます。 + オペレーション + 送金元: %s + 送金先: %s + もう一度やり直してください + 同じカードをスキャンしました。ツインウォレットを作成するには、番号%dのカードをスキャンする必要があります。 + 間違ったツインカードをスキャンしました。別のカードをお試しください。 + あなたが今手にしているカード、そしてもうひとつが番号%s のカードです。\n\nどちらのカードも、このウォレットから資金を引き出すために使用できます。 + 1つのウォレット。2枚のカード。 + カード #%s をスキャン + ウォレットの作成 + # %sツインカードをスキャン + カードの準備 + Tangemツイン + この操作は元に戻せません。古いウォレットにはアクセスできなくなります。 + 番号%sのツインカードをタップし、操作が終了するまで取り外さないでください。 + %sを使用するか、カードをスキャンしてウォレットにアクセスしてください + 最新の機能とニュースをお届けします + 新しいプロモーション情報をいち早く入手しましょう + プッシュ通知を使用しますか? + 新しいウォレットを追加 + 本当にこのウォレットを削除してもよろしいですか? + エラーが発生しました。カードをスキャンしてログインしてください。 + このウォレットはすでに保存されています。別のウォレットを追加できます。 + %sという名前のウォレットはすでに存在します。 + ウォレット名 + ウォレット名の変更 + すべてのロックを解除 + %sですべてをロック解除 + ブロックチェーンにアクセスできません。後でもう一度お試しください。 + カードをスキャン + メッセージに署名することを要求しています。 \n\n %s + Dapp%1$s 、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 + クリップボードには WalletConnect コードが含まれています。コピーした値を使用するか、QRコードをスキャンしてください。 + %1$sの取引を作成するリクエスト\n%2$s\n\n金額: %3$s\n手数料: %4$s\n合計: %5$s\n残高: %6$s + 取引を送信できません。資金が足りません。 + WalletConnect セッションを確立できませんでした。しばらくしてからもう一度お試しください。 + メッセージの署名に失敗しました。\nもう一度お試しください。 + WalletConnectセッションの確立に失敗しました:タイムアウトエラー。しばらくしてもう一度お試しください。 + セッションリクエストには、WalletConnect接続でサポートされていないブロックチェーンが含まれています。サポートされていないブロックチェーン: \n + 技術的な実装のため、このDappとの接続は確立できません。 + 不明なエラーが発生しました。エラーメッセージ: %s 。問題が解決しない場合は、お気軽にサポートにお問い合わせください。 + Tangemアプリで間違ったカードが選択されました + Dappデータから取引を作成できませんでした。コード: %s + 不明なエラーが発生しました。エラーコード: %d 。問題が解決しない場合は、お気軽にサポートにお問い合わせください。 + WalletConnectセッションが開かれていません + おっと。セッションがありません。 + WalletConnectセッションのペアリングに失敗しました: %1$s + クリップボードから貼り付け + %1$sへのメッセージ:\n %2$s + セッション開始のリクエスト\n%1$s\n\nネットワーク: %2$s \n\n URL: %3$s + 操作を完了できませんでした。\n\nこのパラメータでWalletConnectセッションをすでに確立しています。 + 新しいコードをスキャンする + このカードは、WalletConnectセッションの確立には使用できません。 + このネットワークはサポートされていません。別のネットワークを選択してください。 + ネットワークを選択 + WalletConnectセッション + dAppsに接続する + WalletConnect + 接続には数秒かかる場合があります + %s市場価格 + 直近24時間 + %sネットワーク + アドレスがクリップボードにコピーされました + インターネット接続がありません + ウォレット設定 + Tangem + %sを使用するか、カードをスキャンしてウォレットにアクセスしてください + カードのアクティベーションが正しく完了しませんでした。デバイスの NFCモジュールに問題があるか、カードをデバイスに正しくタップしていないことが原因かもしれません。サポートチームにお問い合わせください。 + アクティベーションに失敗しました + BNBネットワーク開発者によると、BEP-2規格のサポートは2024年6月に終了します。この規格の資産を失わないために、BEP-20規格に変換してください。BNBスマートチェーンネットワークへ移行するには、Tangemのスワップサービスをご利用ください。 + BNBビーコンチェーンは閉鎖されます。 + もっと良くなるはず + 気に入った + はい、わかりました! + すごくクールだ! + リフレッシュ + 現在デモモードです + デモモードが有効になっています + スキャンしたカードは開発者カードです。ウォレットの作成には使用しないでください。 + ユーザー向けではありません! + %1$sネットワークには、最低預金残高が必要です。残高が%2$sを下回ると、アカウントは無効になり、残りの資金は破棄されます。 + ネットワークには最低残高が必要です + スワップは、%s の取引完了後に利用可能となります。 + アクティブな取引があります + スワップの承認は現在進行中で、まもなく完了する予定です。 + 承認が進行中 + 最低のスワップ金額は%1$s です。スワップ後の残金が%2$s を下回らないようにしてください。 + あなたのリストには、交換可能な %s トークンがありません。 + スワップ可能なトークンがありません + 取引を行うには、 %1$s %2$sを入金する必要があります。 + %s 手数料を支払えません + 受け取る金額は、 %s 以上である必要があります。 + サービスは一時的に利用できません + スワップするトークンの量は %s を超えないでください + スワップ金額は %s 以上である必要があります + スワップの金額を変更してください + このカードは、サンプル品または偽造品である可能性があります + 真正性チェックに失敗しました + 関連付ける + このトークンを受け取るには、Hederaアカウントに関連付ける必要があります。関連付け手数料 ~ %1$s %2$s + このトークンを受け取るには、Hederaアカウントに関連付ける必要があります。 + トークンを関連付ける + %sが不足しています。このトークンを関連付けるには、Hederaアカウントに資金を追加してください。 + このカードには%sの署名のみが残っています。資金をすべて引き出す必要があります。 + 署名数が少ないです + 異なるネットワーク上のトークンは、異なるアドレスを持つ場合があります。資金を送金する際には、アドレスがネットワークと一致していることを再確認してください。 + + %d ネットワークのアドレスを取得するために、カードを利用してください + + 一部のアドレスが見つかりません + 現在、ネットワークにアクセスできません。しばらくしてからもう一度お試しください。 + ネットワークにアクセスできません + ウォレットに入金 + ウォレットがバックアップされていません。アセットを保護するために今すぐこの手順を実行してください。 + バックアップがありません + このカードは以前取引に使用されたことがあります。信頼できない出所から受け取った場合は、全資金を引き出すことを検討してください。あなたのカードであれば、何もする必要はありません。 + カードはすでに取引に署名済みです + あなたのレビューは、Tangemウォレットをさらに良くするためのモチベーションになります + Tangemを楽しんでいますか? + トークンを受け取る前に、トークンを関連付ける必要があります。 + ネットワーク使用料が必要です + %1$s は %2$s ネットワーク内のアセットです。%3$s 取引を行うには、ネットワーク手数料のために %4$s (%5$s) を入金する必要があります。 + ネットワーク料金をカバーするための%1$sが足りません + Solanaネットワークが混雑しています。2分以内に取引が完了しない場合は、再度取引を繰り返してください。 + Solanaネットワークアラート + Solana ネットワークは 2 日ごとに%1$sのレンタル料を請求します。レンタル料を支払えないアカウントはネットワークから削除されます。アカウントに%2$s以上入金すると、無料で使用できます。 + 現在、一部のネットワークにアクセスできません。しばらくしてからもう一度お試しください。 + 一部のネットワークにアクセスできません + これはテストネットカードです。取引処理はできませんので、テストおよび開発目的でのみご利用ください。 + テスト目的のみ + 破棄 + バックアップが中断されました。再開しますか? + はい、再開します + 破棄 + バックアップを破棄する場合は、カードを工場出荷時の設定にリセットしてやり直す必要があります。 + バックアップを再開する + これはやり直しができないアクションです + %sでログイン + カードをスキャン + アプリにアクセスするには、 %sを使用するか、カードをスキャンしてください + お帰りなさい! + diff --git a/core/res/src/main/res/values-ru/strings.xml b/core/res/src/main/res/values-ru/strings.xml index 42a9605d17..f9f2f33750 100644 --- a/core/res/src/main/res/values-ru/strings.xml +++ b/core/res/src/main/res/values-ru/strings.xml @@ -1,753 +1,830 @@ - Добавить токен - Валюты - Отправляйте только %1$s (%2$s) в сети %3$s на этот адрес. Использование другой сети может привести к утрате средств. - Обратиться в поддержку - Эта функция недоступна в демонстрационном режиме - Причина: %s - Не могу отправить транзакцию - Выбранный кошелёк не поддерживает сеть %1$s - Для активации криптографии сети %1$s необходимо сбросить кошелек до заводских настроек. Пожалуйста, выведите свои средства, чтобы не потерять их, после сброса доступ к текущему кошельку будет невозможен. - Токены в сети %1$s не поддерживаются этой картой из-за ограничений прошивки. - У вас возникли трудности со сканированием карты? - Эта карта не предназначена для работы с этим приложением - Подключите функцию комиссии по умолчанию и при формировании транзакции на отправку средств комиссия будет выставлена автоматически, а экран комиссии пропущен. Вы всегда сможете на него вернуться. - Перейдите в настройки, чтобы включить биометрическую аутентификацию в приложении Tangem - Включите биометрическую аутентификацию - Все сохраненные коды доступа будут удалены. Вам потребуется вводить код доступа при работе с кошельком. - При отключении функции сохранения кошелька все ранее сохраненные кошельки будут удалены из приложения. - Сохранение кода доступа - Подключите функцию хранения кодов доступа от карт на телефоне в зашифрованном виде, и при работе с картой вместо кода доступа будет запрашиваться биометрическая аутентификация. - Cохранение кошелька - Подключите функцию привязки карты в приложении, а также возможность биометрической аутентификации. Подпись транзакции все так же потребует карту. - Тёмная - Светлая - Как в системе - Тема - Настройки приложения - Чтобы скрыть или показать баланс, просто поверните ваше устройство вниз или отключите опцию его в разделе \"Настройки\" - Больше не показывать - Понятно - Балансы скрыты - Пожалуйста, отсканируйте карту - Пожалуйста, попробуйте снова через 30 секунд или отсканируйте карту - Слишком много попыток - Вы отключили биометрическую аутентификацию на вашем телефоне и не сможете сохранять кошельки в приложении. Для сохранения кошельков, пожалуйста, включите функцию биометрической аутентификации в настройках телефона. - Начать резервное копирование - - %d карта - %d карты - %d карт - %d карт - - Отключите эту опцию, если не хотите, чтобы эта карта использовалась для сброса кодов доступа на другие карты этого кошелька. Обратите внимание, сброс кода также не будет доступен на этой карте. - Использовать эту карту для сброса кода доступа на других картах в этом кошельке - Восстановление кода доступа - Сбросить - Вы уверены, что хотите это сделать? - Смена кода доступа - Код доступа будет изменен только на данной карте - Все карты выбранного кошелька сброшены до заводских настроек, вы можете создать новый кошелек - Сброс завершён - Хотите сбросить следующую карту от этого кошелька? - Сброс карты - Рекомендуем завершить процесс сброса всех карт кошелька - Вы сбросили не все карты - Заводские настройки - Тип безопасности - Настройки карты - Помимо сетевой комиссий, сеть Cardano взимает %1$s ADA при транзакции с токеном %2$s - Требования к транзакции Cardano - Чтобы совершить транзакцию %1$s, внесите некоторую сумму ADA для покрытия сетевой комиссии и минимального значения ADA (рекомендуется 5 ADA) - Недостаточно ADA для транзакции - Вы должны поддерживать некоторое количество ADA, поскольку у вас на балансе есть токены в сети Cardano - Недостаточно ADA - Принять - Доступ запрещен - Применить - Одобрение - Внимание - Баланс: %s - Баланс - биометрическую аутентификацию - биометрией - Купить - Перейти на %1$s - Вы не предоставили доступ к камере, пожалуйста, измените настройки конфиденциальности. - Отмена - Закрыть - Продолжить - Копировать - Скопировать адрес - Создать - Удалить - Отключено - Готово - Включить - Включено - Ошибка - Обозреватель - Посмотреть историю транзакций - Обозреватель - Комиссия - Сетевые комиссии – это плата пользователя за обработку и подтверждение транзакций. Размер комиссии зависит от нагрузки на сеть, объема транзакции и приоритета исполнения. %s - Свое - Быстро - По рынку - Медленно - Скорость и комиссия - Получить адреса - К провайдеру - Перейти в токен - Импортировать - Позже - Заблокирован - Основная сеть - Сетевая комиссия - Сумма отправки будет уменьшена на %1$s (%2$s) для покрытия выбранного уровня комиссии - Далее - Нет - Нет адреса - OK - Основная карта - Парольная фраза - Вставить - Подробнее - Получить - Отклонить - Перезагрузить - Переименовать - Сохранить изменения - Искать - Поиск токенов - Seed-фраза - Выберите действие - Продать - Отправить - Сервер недоступен, повторите попытку позднее - Поделиться - Подписать - Подписать и отправить - Начать - Отправить - Успешно - Поддержка - Обмен - условия участия - Ошибка транзакции - Транзакции - Перевод - Я понял - Произошла ошибка. Пожалуйста, попробуйте снова. - Недоступно - Да - Адрес контракта скопирован! - Доступные сети - Добавить токен - Адрес контракта - Адрес контракта некорректен - Пожалуйста, выберите сеть - Десятичное число должно быть действительным целым числом, до %li - Своя деривация - Например m/00\'/0000\'/0\'/0/0 - Введите свою деривацию - Знаков после запятой - Путь деривации - По умолчанию - Деривация по BIP44 - Введенный путь деривации некорректен - Например, USD Coin - Название токена - Не выбрано - Сеть - Сеть - Вы можете добавить токен в ручную, если он не поддерживается Tangem - Например, USDC - Символ - Символ токена - Этот токен/сеть уже находится в вашем списке - Токены могут быть созданы кем угодно. Остерегайтесь мошеннических токенов, они могут ничего не стоить - Остерегайтесь мошеннических токенов, они могут ничего не стоить - Токены могут быть созданы кем угодно - Чат - Код доступа - Перед сканированием карты вам нужно будет ввести правильный код доступа. - Задержка сканирования - Этот механизм защищает карту от бесконтактных атак. Между сканированием карты и выполнением команды будет добавлена задержка. - Пароль - Перед выполнением любой команды, влекущей за собой изменение состояния карты, вам необходимо будет ввести пароль. - Реферальная программа - Переверните экран вашего устройства вниз, чтобы быстро скрыть и отобразить балансы - %s хэшей - Номер карты - Обратиться в поддержку - Добавить еще карты - Валюта приложения - Скрывать балансы жестом переворота - Эмитент - Подписано - Подробности - Проверьте подключение с интернетом или переключитесь на другую сеть - Условия использования - Вы использовали карту от другого кошелька. Приложите карту, связанную с этим кошельком. - Мои токены - У вас нет добавленных токенов. Добавьте токены для обмена - Недоступен для обмена с %s - Предоставлено - Статус - Tangem предоставляет доступ к обмену через сторонних поставщиков в соответствии с их правилами - Выберите провайдера - Произошла ошибка. Код: %s - К сожалению, обмен указанной пары через выбранного провайдера на данный момент невозможен. Попробуйте совершить обмен позже. (Код: %s) - Выбранный провайдер недоступен для обмена. Попробуйте позже. (Код: %s) - В данный момент обмен невозможен. Попробуйте позже. (Код: %s) - Курс обмена - Обмен через %s - Чтобы вернуть ваши деньги, посетите сайт провайдера - Операция не выполнена провайдером - Отправленные средства были возвращены в %1$s на ваш кошелек в соответствии с правилами OKX или моста обмена. %2$s - Сумма была возвращена в %1$s (%2$s сети) - Посетите сайт провайдера для проверки - Провайдер запрашивает прохождение верификации - Отменен - Подтверждено - Подтверждение - Подтверждение... - Обменяно - Обмен - Обмен... - Неудачно - Депозит получен - Ожидание депозита - Ожидаем пополнения... - Возвращено - Отправляем - Отправка средств... - Отправлено - Данные провайдера. Сумма к получению может измениться в зависимости от рыночных условий. - Статус обмена - Требуется верификация - Ожидание хеша транзакции - Список токенов в вашем кошельке - Получение наилучших курсов... - Плавающая ставка - Пользуясь сервисом, вы соглашаетесь с %s - Пользуясь сервисом, вы соглашаетесь с %1$s и %2$s - Больше провайдеров на подходе.\nСледите за обновлениями! - Политикой конфиденциальности - Провайдер - Лучший курс - Доступно до %s - Доступно с %s - Недоступно для этой пары - Требуется разрешение - Рекомендовано - Условиями использования - Токены не найдены. Пожалуйста, попробуйте другой запрос - ID: %s - ID транзакции скопирован - Информация ниже не является обязательной. Вы можете стереть её, если хотите. - Расскажите, каких функций вам не хватает, и мы постараемся вам помочь. - Скажите, пожалуйста, какая у вас карта? - Привет, команда поддержки, - Пожалуйста, расскажите нам больше о вашей проблеме. Каждая маленькая деталь может помочь. - Мои предложения - Не могу отсканировать карту - Обращение в поддержку - Обращение в поддержку Tangem - Не могу отправить транзакцию - Купить - Сканировать - Чтобы изменить код доступа, приложите карту как показано выше и не убирайте до окончания операции - Чтобы изменить пароль, приложите карту как показано выше и не убирайте до окончания операции - Чтобы создать кошелек, приложите карту как показано выше и не убирайте до окончания операции - Приложите карту #%s для сброса - Приложите, чтобы отсканировать - Приложите, чтобы подписать - Приложите карту - Вы обновили данные биометрии, отсканируйте свою карту для входа - Ваш баланс должен быть выше суммы комиссии для осуществления перевода - Недостаточно средств - У вас недостаточно Маны для этой транзакции. Пожалуйста, подождите, пока Мана восполнится. Ваш баланс маны равен %1$s/%2$s - Недостаточно Маны - Вы можете перевести только %s из-за ограничения Mana, установленного сетью Koinos - Лимит маны - Сеть Koinos использует Ману для оплаты комиссии сети. У вас есть %1$s/%2$s Mana - Уровень маны - Чтобы начать отслеживать свои криптоактивы и транзакции, добавьте токены - Управление токенами - Чтобы получить доступ ко всем сетям, вам необходимо отсканировать карту - Отсканируйте карту - Обменивайте свои токены с %1$s комиссии провайдера через Changelly с %2$s по %3$s февраля. - Обмен с Changelly, %s комиссии - Токены - Забронировать - Оплатите его криптой и сэкономьте **50 долларов** через нашего партнера Travala: **%1s - %2s** - Забронируйте отпуск с Tangem - Добавить - Изменить - Рыночная капитализация - Основная сеть - Не основной или основной блокчейн, на котором размещен токен - Не основные сети - Выберите сети - Кошелек - Не удалось найти этот токен, вы можете добавить его вручную. - - %1$d из %2$d кошелька - %1$d из %2$d кошельков - %1$d из %2$d кошельков - %1$d из %2$d кошельков - - например Bitcoin - Выбранный токен не доступен в кошельке на данный момент. Но не переживайте, вы можете выразить свой интерес проголосовав за его добавление. - Голосовать - Выберите кошелек - Кошелёк не поддерживает более одной сети - Вам необходимо установить единый код доступа для защиты всех ваших карт - Защита - Позже вы сможете установить индивидуальный код доступа для каждой карты - Персонализация - Код доступа можно восстановить с помощью привязанной карты. Не храните все карты в одном месте. - Восстановление - Выберите любое слово, фразу или число в качестве кода доступа - Создайте код доступа - Введите код доступа еще раз, чтобы избежать ошибки - Повторно введите код доступа - Код доступа должен состоять не менее чем из 4 символов. - Введенные коды доступа не совпадают - Необходимо повторить операцию, при этом карта будет сброшена к заводским настройкам - Ошибка активации - Добавление токенов - Вы добавили одну резервную карту. После того, как процесс будет завершен, Вы больше не сможете добавить карт. Если у Вас есть еще одна карта, добавьте ее в резервную копию. Хотите продолжить? - Процесс резервного копирования почти завершен. Вы не можете выйти из него сейчас. - Парольная фраза — это расширенная функция безопасности, которую используют криптокошельки. Она добавляет дополнительное слово или фразу по вашему выбору к уже существующей seed - фразе, чтобы разблокировать совершенно новый набор адресов. - Добавить резервную карту - Сканировать карту #%d - Создать резервную копию - Сканировать основную карту - Перейти к моему кошельку - Завершение бэкапа - Получить криптовалюту - Сканировать основную карту - Пропустить - Как это работает? - Давайте сгенерируем все ключи на вашей карте и создадим безопасный кошелек - Создать кошелек - Создать кошелек - Другие опции - Ваши ключи будут надежно сгенерированы внутри карты. Никакой seed-фразы, а это значит, что никто не может экспортировать или украсть ее. - Cоздавайте ключи приватно - Ваша карта активирована и готова к использованию - Успешно! - В этом случае вам будет необходимо начать процесс заново. - Вы хотите выйти из процесса активации? - Подготовка - Другой кошелек уже был создан на карте, которую вы пытаетесь добавить. Если на нем есть средства, пожалуйста сначала выведите их, а затем сделайте сброс до заводских настроек и используйте как резервную. - Резервная копия - Прочитать о seed-фразе - - - Запишите эти %d слова в порядке, указанном ниже, и сохраните их в надежном месте. - Запишите эти %d слов в порядке, указанном ниже, и сохраните их в надежном месте. - Запишите эти %d слов в порядке, указанном ниже, и сохраните их в надежном месте. - - Ваша seed-фраза - - - %d слова - %d слов - %d слов - - Чтобы импортировать кошелек, введите seed-фразу в поле ниже - Создать seed-фразу - Импорт кошелька - Seed-фраза — это набор слов, который дает возможность восстановить кошелек. В отличие от ключей, сгенерированных картой, seed-фраза не защищена и может быть скопирована и украдена. Используйте этот вариант на свой страх и риск. - Использовать seed-фразу - Неверная seed-фраза. Пожалуйста, проверьте порядок слов. - Неверная seed-фраза. Пожалуйста, проверьте орфографию. - Устаревший - Чтобы проверить, правильно ли вы записали seed-фразу, введите 2-е, 7-е и 11-е слова - Итак, проверим - Чтобы начать процесс резервного копирования, добавьте одну или две резервные карты. - Вы можете добавить еще одну карту или завершить процесс резервного копирования - Подготовьте резервную карту с номером %s - Отсканируйте основную карту, чтобы начать процесс резервного копирования. - Подготовьте основную карту с номером %s - Ваша карта настроена и готова к использованию. - Добавлено максимальное количество карт. Завершите процесс резервного копирования. - Активация карты - Резервная карта #%d - Нет резервных карт - Добавлена ​​одна резервная карта - Подготовьте свою карту - Добавлены две резервные карты - Пополните кошелек на любую сумму, чтобы начать пользоваться картой - Пополните кошелек более чем на %1$s %2$s, чтобы начать пользоваться картой - Купить криптовалюту - Показать адрес кошелька - Активация кошелька - Процесс связывания карт частично завершен. Вы не можете выйти из него сейчас. - Если процесc создания кошелька каким-либо образом прервется, вам придется начинать сначала - Вы можете сделать резервную копию своих ключей на одной или двух других пустых картах Wallet. - Код доступа можно восстановить с помощью одной из резервных карт. - Все резервные карты являются полнофункциональными и содержат одинаковые ключи. - Вы сможете установить код доступа для защиты своих кошельков. - Резервная копия карты - Восстановление кода доступа - Идентичные карты - Код доступа - Группы - По балансу - Сортировка токенов - Список - Выбрать из галереи - Настройки - Вы не предоставили доступ к вашей камере - Доступ к камере запрещен - %1$s (%2$s) в сети %3$s - Отправляйте только %s на этот адрес. Использование другой сети может привести к утрате средств. - Участвовать - Не удалось загрузить информацию по реферальной программе. Пожалуйста, попробуйте позже. - Не удалось загрузить информацию по реферальной программе. Код ошибки: %s. Пожалуйста, попробуйте позже. - Грядущие выплаты - Ваши друзья купили - Меньше - Больше - Нет грядущих выплат - - за %d кошелек - за %d кошелька - за %d кошельков - за %d кошельков - - Получите ^^%1$s^^ на ваш адрес в сети %2$s %3$s ^^спустя 30 дней^^ за каждый кошелек, который купит ваш друг - Вы - Получит - при покупке кошелька на сайте tangem.com - %s скидку - Ваш друг - Персональный код скопирован! - Ваш персональный код - Купи Tangem Wallet со скидкой!\n%s - Приведи друга в Tangem - Вы приняли - Нажимая на эту кнопку, вы принимаете - в реферальной программе - - %d кошелек - %d кошелька - %d кошельков - %d кошельков - - Сбросить карту - Я понимаю, что после выполнения этого действия у меня больше не будет доступа к текущему кошельку - Я понимаю, что не смогу этой картой восстановить пароль на остальных картах этого кошелька, если я его забуду - Сброс к заводским настройкам приведет к полному удалению кошелька с выбранной карты. Вы не сможете восстановить текущий кошелек или использовать данную карту для восстановления кода доступа. - Сброс к заводским настройкам приведет к полному удалению кошелька с выбранной карты. Вы не сможете восстановить текущий кошелек. - У вас есть карта банка другой страны, а также вид на жительство или регистрация вне РФ? - Карты банков РФ в данный момент не принимаются - Войдите в приложение и следите за своим балансом без сканирования карты - Доступ в приложение - Использовать биометрию - Для операций с вашим кошельком будет запрашиваться биометрия вместо кода доступа карты - Код доступа - Похоже, что у вас отключена биометрическая аутентификация, она необходима для сохранения кошельков - Включите биометрическую аутентификацию - Вы хотите использовать биометрию? - Обратите внимание, что для совершения транзакции с вашими средствами по-прежнему потребуется ваша карта - Сканировать - Отсканируйте карту, чтобы изменить ее настройки. Изменения затронут только ту карту, которую вы отсканировали, и не повлияют на другие карты, привязанные к вашему кошельку. - Приготовьте свою карту - Уже содержится во введенном адресе - Сумма комиссии в %s раз превышает рекомендованную. Убедитесь, что указанная комиссия верна. - Вы указали комиссию ниже рекомендуемой, это может привести к задержке исполнения вашей транзакции. Продолжить? - Причина: %1$s\nКод: %2$s - Транзакция не выполнена - Сумма - Вы можете установить комиссию за транзакцию, изменив значение в поле Satoshi per vByte. - Это стоимость, которую вы готовы заплатить за каждую единицу газа. Чем выше цена газа, тем быстрее ваша транзакция будет обработана. (Приоритетная комиссия включена) - Приоритетная комиссия - Комиссия, которую пользователь может заплатить майнерам или валидаторам за ускорение включения его транзакции в блок. - %1$s, %2$s - Адрес - Код назначения - Введите адрес - Адрес совпадает с адресом кошелька - Комиссия, которая будет взята за вашу транзакцию. Вы можете выставить своё собственное значение. - Недопустимый Tag. Он не будет добавлен в транзакцию. - Недопустимый Memo. Он не будет добавлен в транзакцию. - Tag - Memo - Включая комиссию - Низкая - Нормальная - Приоритетная - Проверьте своё интернет соединение - Информация о комиссии сети недоступна - Из - Лимит газа - Это максимальное количество газа, которое будет потрачено на выполнение транзакции или контракта. Лимит газа предотвращает неожиданные или неограниченные расходы при выполнении транзакции. - Цена газа - Это стоимость, которую вы готовы заплатить за каждую единицу газа. Чем выше цена газа, тем быстрее ваша транзакция будет обработана. - Всё - Максимальная сумма - Комиссия не превысит - Недопустимый Memo - Покрытие сетевой комиссии - Недостаточно средств для перевода, так как сумма комиссии и сумма перевода в совокупности больше имеющегося баланса - Недостаточно средств - Аккаунт будет удален из блокчейна, если баланс упадет ниже экзистенциального депозита. Пожалуйста, оставьте %s на балансе. - Экзистенциальный депозит - Сумма комиссии в %s раз превышает рекомендованную. Убедитесь, что указанная комиссия верна. - Установлена высокая комиссия - Ввиду особенности сети %1$s комиссия при переводе всего баланса выше. Для того, чтобы снизить комиссию Вы можете оставить %2$s. - Комиссия повышена - Включенная комиссия превышает сумму перевода, что приводит к отрицательному значению - Недопустимая сумма - Минимальная сумма отправки - %1$s. Пожалуйста, убедитесь, что остаток после отправки также не будет меньше %2$s. - Адрес получателя не активирован. \nПожалуйста, измените сумму отправки, чтобы продолжить. - Сумма отправки не может быть менее %s - Оставить %s - Уменьшить на %s - Уменьшить до %s - Обратите внимание, что при определенных параметрах комиссии возможны задержки по вашей транзакции - Возможны задержки по транзакции - Из-за ограничений %1$s в одну транзакцию может поместиться только %2$s UTXO. Это означает, что вы можете отправить только %3$s или меньше. Вам нужно уменьшить сумму. - Лимит транзакции - Опционально - Пожалуйста, совместите свой QR-код с квадратом, чтобы отсканировать его. Убедитесь, что вы сканируете адрес в сети %s. - Последние - Получатель - Неверный адрес - Убедитесь, что вы отправляете средства на адрес кошелька %s. Ошибки могут привести к потере ваших токенов. - Отправить - Мемо/ Код назначения - это код, разделяющий транзакции к общему получателю в сети криптовалют. Внимание: отсутствие мемо может привести к потере средств. - Мои кошельки - Способ измерения комиссии за биткоин-транзакцию. Он указывает на количество самой маленькой единицы биткоина (сатоши) за каждый виртуальный байт в транзакции. Чем выше число, тем быстрее будет обработана транзакция майнерами. - Сатоши / вбайт - Отправка - Нажмите на любое поле, чтобы изменить его - Отправка %s - Вы отправляете **%1$s**, включая комиссию сети %2$s - Вы отправляете **%1$s** и %2$s - Отправка %s - Всего - %1$s и %2$s будет отправлено - ≈ %1$s (вкл. комиссию: %2$s) - %s будет отправлено - Транзакция успешно подписана и отправлена в блокчейн. Баланс будет обновлен через некоторое время - Неверный адрес - Транзакция отправлена - Забыть кошелек - Это приведет к удалению кошелька из приложения. Сам кошелек можно добавить снова. - Имя - Держите свои криптосбережения в безопасности. Приватные ключи надежно хранятся на карте. - Революционный аппаратный кошелек - До трех карт с одним кошельком - Все ключи в безопасности - Аппаратный кошелек для ваших биткоинов, эфира и многих других валют одновременно — все в одной карте - Тысячи криптовалют - Используйте его на ходу, в любом месте, в любое время. Без проводов и батареек. Как только понадобится крипта, просто приложите карту к телефону. - Кошелек для каждого - Встречайте Tangem - Обменивайте, покупайте NFT, получайте займы и делайте вклады в более чем 100 различных децентрализованных сервисах - Поддержка Web 3.0 - Обменивайте больше токенов по лучшим курсам прямо в вашем кошельке. - Новый провайдер обмена! - В сумму включено: \n• комиссия провайдера сервиса\n• комиссия сети за отправку %s от биржи обратно на адрес пользователя - В сумму включена комиссия провайдера сервиса. - Комиссии - Подтверждения считаются отраслевым стандартом для всех децентрализованных бирж и защищают ваш кошелек от доступа со стороны смарт-контракта без вашего разрешения. По замыслу смарт-контракты не могут получить доступ к вашим токенам, если вы не одобрите доступ со своей стороны. «Разблокируя» свои токены, вы даете смарт-контракту 1inch разрешение тратить ваши активы. Майнеры сети получают компенсацию за газ (оплачиваемый вами) за запись этого действия в блокчейне. Как только разрешение будет предоставлено, вы сможете обменять свой токен. - Подтвердить - Вы отправляете - Дать разрешение - Обмен этой суммы выбранных токенов может вызвать значительные колебания цены и уменьшить получаемую сумму. - Недостаточно средств - Подтвердить - Текущая транзакция - Комиссия сети за одобрение токена будет взиматься за подтверждение того, что именно вы разрешаете использовать ваш токен для обмена. - Дать разрешение - Укажите лимит доступа к выбранному токену - Количество %s - Чтобы продолжить, вам нужно разрешить смарт-контракту %1$s использовать ваш %2$s - Безлимитно - В процессе - Обменять - Вы получите - Выберите токен - не доступен - Балансы скрыты - Балансы показаны - Отменить - Выбранная операция в данный момент недоступна. Попробуйте позже. - В данный момент покупка монеты %s недоступна. Следите за нашими обновлениями. - У вас нет средств для продажи. Пополните счет, чтобы иметь возможность продать с него средства. - У вас нет средств для отправки. Пополните счет, чтобы иметь возможность отправить с него средства. - В данный момент обмен монеты %s недоступен. Следите за нашими обновлениями. - Продажа средств станет доступной после завершения транзакции(-ий) в сети %s - Отправка средств станет доступной после завершения транзакции(-ий) в сети %s - В данный момент продажа %s недоступна. Следите за нашими обновлениями. - Сгенерировать XPUB - Скрыть - Вы скрываете токен с главного экрана, но в любой момент сможете добавить его обратно через страницу управления токенами. - Скрыть %s - Скрыть токен - Стейкинг позволяет вам зарабатывать %1$s и получать вознаграждения каждые %2$s дней - Зарабатывайте до %s вознаграждений за стейкинг ежегодно - %1$s токен в сети %%image%% %2$s - Токен в сети %%image%% %1$s - Токен %1$s (%2$s) является основной валютой в сети %3$s и не может быть скрыт до тех пор, пока у вас в списке есть другие токены этой сети - Невозможно скрыть %s - Обменивайте этот токен на другие с %1$s комиссии за обслуживание с %2$s по %3$s февраля. - Обмен с Changelly, %s комиссии - Обменять - контракт: %s - У вас еще нет транзакций - Не удалось загрузить историю транзакций.\nНажмите на кнопку перезагрузки, чтобы обновить информацию. - Несколько адресов - История транзакций в настоящее время не поддерживается для этого блокчейна. Но не волнуйтесь, мы работаем над этим! А пока вы можете проверить ее в обозревателе. - Операция - от: %s - на: %s - Вы отсканировали ту же карту. Для создания twin-кошелька вам необходимо отсканировать карту с номером %d - Вы отсканировали не ту twin-карту. Пожалуйста, попробуйте отсканировать другую - Это карта, которую вы держите в руках. У парной карты номер %s.\n\nОбе карты можно использовать для вывода средств из этого кошелька. - Один кошелек. Две карты. - Сканировать карту #%s - Создание кошелька - Отсканируйте twin-карту #%s - Подготовка карты - Tangem Twin - Это действие необратимо. У вас не будет доступа к старому кошельку. - Приложите twin-карту с номером %s и не убирайте до окончания операции - Используйте %s или отсканируйте карту, чтобы получить доступ к своему кошельку - Добавить новый кошелек - Вы уверены, что хотите удалить этот кошелек? - Произошла ошибка, пожалуйста, отсканируйте свою карту для входа - Этот кошелек уже был сохранен, вы можете добавить другой - Кошелек с именем %s уже существует - Имя кошелька - Переименование кошелька - Разблокировать все - Разблокировать все с %s - Блокчейн недоступен. Попробуйте позже. - Отсканируйте карту - Запрос на подпись сообщения.\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 - Буфер обмена содержит код 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 Попробуйте, пожалуйста, позже. Если проблема будет продолжать возникать - обратитесь в службу поддержки. - Нет открытых сессий WalletConnect - Упс. Нет сессий. - Не удалось создать пару WalletConnect: %1$s - Вставить из буфера обмена - Сообщение для %1$s:\n%2$s - Запрос на открытие сессии для\n%1$s\n\nСЕТЬ: %2$s\n\nURL: %3$s - Операция не может быть завершена.\n\nВы уже установили сеанс WalletConnect с этими параметрами. - Сканировать новый код - Эту карту нельзя использовать с WalletConnect. - Сеть не поддерживается. Пожалуйста, выберите другую сеть. - Выберите сеть - Сессии WalletConnect - Подключение к dApps - WalletConnect - Рыночная цена %s - за 24 часа - Сеть %s - Адрес скопирован в буфер обмена - Нет соединения с интернетом - Настройки кошелька - Tangem - Используйте %s или отсканируйте карту, чтобы разблокировать доступ к вашему кошельку - Похоже, что процесс активации карт не был завершен корректно. Это могло быть вызвано проблемой взаимодействия с модулем NFC либо некорректным прикладыванием карты к телефону. Пожалуйста, обратитесь в нашу службу поддержки для уточнения деталей. - Ошибка активации - По решению разработчиков сети BNB стандарт BEP-2 перестанет поддерживаться в июне 2024 года. Чтобы не потерять активы, их необходимо преобразовать в стандарт BEP-20. Используйте функцию обмена в приложении или сторонние сервисы, чтобы перевести средства в cеть BNB Smart Chain. - Отключение сети BNB Beacon Chain - Можно лучше - Нравится - Понятно! - Очень круто! - Обновить - Вы находитесь в режиме демо - Демо режим включен - Отсканированная вами карта является картой разработчика. Не используйте ее для создания своего кошелька. - Не для пользователя! - Cеть %1$s использует концепцию экзистенциального депозита. Если баланс вашего счета будет ниже %2$s, то он будет деактивирован, а средства на счете уничтожены. - Для работы с сетью необходим депозит - Обмен будет доступен после завершения %s транзакции - У вас есть активная транзакция - Разрешение обмена в процессе и будет скоро завершено - Разрешение в процессе - Минимальная сумма обмена - %1$s. Пожалуйста, убедитесь, что остаток после обмена также не будет меньше %2$s. - У вас в списке нет монет доступных для обмена с %s - Нет доступных для обмена токенов - Чтобы совершить транзакцию, вам необходимо внести немного %1$s %2$s - Невозможно покрыть комиссию %s - Сумма получения не может быть менее %s - Cервис временно недоступен - Сумма для обмена должна быть не более %s - Сумма для обмена должна быть не менее %s - Пожалуйста, измените сумму для обмена - Возможно, данная карта - образец или подделка - Ошибка проверки подлинности - Ассоциировать - Этот токен должен быть ассоциирован с вашей учетной записью Hedera, прежде чем вы сможете его принять. Стоимость ассоциации ~%1$s %2$s - Этот токен должен быть ассоциирован с вашей учетной записью Hedera, прежде чем вы сможете его принять - Ассоциируете свой токен - Недостаточно %s. Пополните ваш аккаунт Hedera для ассоциации этого токена - На этой карте осталось всего %s подписей. Вам следует вывести все ваши средства. - Малое количество подписей - Токены на разных сетях могут иметь разные адреса. Пожалуйста, убедитесь при переводе средств, что ваш адрес соответствует сети. - - Используйте вашу карту, чтобы получить адрес для %d сети - Используйте вашу карту, чтобы получить адреса для %d сетей - Используйте вашу карту, чтобы получить адреса для %d сетей - Используйте вашу карту, чтобы получить адреса для %d сетей - - Некоторые адреса отсутствуют - В данный момент сеть недоступна. Пожалуйста, попробуйте позже. - Сеть недоступна - Пополните ваш кошелек - Ваш кошелек не имеет резервной копии. Проведите эту процедуру сейчас, чтобы защитить ваши активы. - Резервная копия отсутствует - Эта карта ранее использовалась для подписи транзакций. Если она получена от ненадежного источника, рассмотрите возможность вывода своих средств. Если это ваша карта, дополнительных действий не требуется. - Карта уже подписывала транзакции - Ваш отзыв мотивирует нас сделать кошелек Tangem еще лучше - Нравится Tangem? - Вам необходимо провести ассоциацию токена для того, чтобы иметь возможность принимать его - Необходима плата за аренду сети - %1$s - это монета в сети %2$s. Для совершения транзакции %3$s, вам необходимо внести немного %4$s (%5$s), чтобы покрыть комиссию сети. - Недостаточно %1$s для оплаты комиссии сети - Сеть Солана испытывает высокую нагрузку. Если Ваша транзакция не прошла в течение 2 минут, повторите её отправку. - Оповещение сети Солана - Сеть Solana взимает арендную плату в размере %1$s каждые 2 дня. Аккаунты, которые не могут позволить себе арендную плату, удаляются из сети. Пополните свой счет более чем на %2$s, чтобы не платить арендную плату. - Некоторые сети в настоящее время недоступны. Пожалуйста, повторите попытку позже. - Некоторые сети недоступны - Это Testnet карта. Он не может обрабатывать транзакции и используется только в целях тестирования и разработки. - Только для целей тестирования - Отказаться - Вы не закончили резервное копирование. Хотите продолжить? - Да, возобновить - Отказаться - Если сейчас отказаться, то придётся сбрасывать карты до заводских настроек, чтобы начать заново - Возобновить резервное копирование - Это необратимое действие - Войти с %s - Сканировать карту - Используйте %s или отсканируйте карту для входа в приложение - C возвращением! + Выберите сеть + Добавить токен + Валюты + Отправляйте только %1$s (%2$s) в сети %3$s на этот адрес. Использование другой сети может привести к утрате средств. + Как сканировать + Обратиться в поддержку + Попробовать снова + Эта функция недоступна в демонстрационном режиме + Причина: %s + Не могу отправить транзакцию + Выбранный кошелёк не поддерживает сеть %1$s + Для активации криптографии сети %1$s необходимо сбросить кошелек до заводских настроек. Пожалуйста, выведите свои средства, чтобы не потерять их, после сброса доступ к текущему кошельку будет невозможен. + Токены в сети %1$s не поддерживаются этой картой из-за ограничений прошивки. + У вас возникли трудности со сканированием карты? + Эта карта не предназначена для работы с этим приложением + Подключите функцию комиссии по умолчанию и при формировании транзакции на отправку средств комиссия будет выставлена автоматически, а экран комиссии пропущен. Вы всегда сможете на него вернуться. + Перейдите в настройки, чтобы включить биометрическую аутентификацию в приложении Tangem + Включите биометрическую аутентификацию + Все сохраненные коды доступа будут удалены. Вам потребуется вводить код доступа при работе с кошельком. + При отключении функции сохранения кошелька все ранее сохраненные кошельки будут удалены из приложения. + Сохранение кода доступа + Подключите функцию хранения кодов доступа от карт на телефоне в зашифрованном виде, и при работе с картой вместо кода доступа будет запрашиваться биометрическая аутентификация. + Cохранение кошелька + Подключите функцию привязки карты в приложении, а также возможность биометрической аутентификации. Подпись транзакции все так же потребует карту. + Тёмная + Светлая + Как в системе + Тема + Настройки приложения + Чтобы скрыть или показать баланс, просто поверните ваше устройство вниз или отключите опцию его в разделе \"Настройки\" + Больше не показывать + Понятно + Балансы скрыты + Пожалуйста, отсканируйте карту + Пожалуйста, попробуйте снова через 30 секунд или отсканируйте карту + Слишком много попыток + Вы отключили биометрическую аутентификацию на вашем телефоне и не сможете сохранять кошельки в приложении. Для сохранения кошельков, пожалуйста, включите функцию биометрической аутентификации в настройках телефона. + Начать резервное копирование + + %d карта + %d карты + %d карт + %d карт + + Отключите эту опцию, если не хотите, чтобы эта карта использовалась для сброса кодов доступа на другие карты этого кошелька. Обратите внимание, сброс кода также не будет доступен на этой карте. + Использовать эту карту для сброса кода доступа на других картах в этом кошельке + Восстановление кода доступа + Сбросить + Вы уверены, что хотите это сделать? + Смена кода доступа + Код доступа будет изменен только на данной карте + Все карты выбранного кошелька сброшены до заводских настроек, вы можете создать новый кошелек + Сброс завершён + Хотите сбросить следующую карту от этого кошелька? + Сброс карты + Рекомендуем завершить процесс сброса всех карт кошелька + Вы сбросили не все карты + Заводские настройки + Тип безопасности + Настройки карты + Помимо сетевой комиссий, сеть Cardano взимает %1$s ADA при транзакции с токеном %2$s + Требования к транзакции Cardano + Чтобы совершить транзакцию %1$s, внесите некоторую сумму ADA для покрытия сетевой комиссии и минимального значения ADA (рекомендуется 5 ADA) + Недостаточно ADA для транзакции + Вы должны поддерживать некоторое количество ADA, поскольку у вас на балансе есть токены в сети Cardano + Недостаточно ADA + Принять + Доступ запрещен + Разрешить + Применить + Одобрение + Подтвердить + Внимание + Баланс: %s + Баланс + биометрическую аутентификацию + биометрией + Купить + Перейти на %1$s + Вы не предоставили доступ к камере, пожалуйста, измените настройки конфиденциальности. + Отмена + Вывести награду + Закрыть + Продолжить + Копировать + Скопировать адрес + Создать + Свое + + %d день + %d дня + %d дней + %d дней + + Удалить + Отключено + Готово + Включить + Включено + Ошибка + Обозреватель + Посмотреть историю транзакций + Обозреватель + Комиссия + Сетевые комиссии – это плата пользователя за обработку и подтверждение транзакций. Размер комиссии зависит от нагрузки на сеть, объема транзакции и приоритета исполнения. %s + Быстро + По рынку + Медленно + Скорость и комиссия + Получить адреса + К провайдеру + Перейти в токен + Импортировать + Позже + Заблокирован + Основная сеть + Сетевая комиссия + Сумма отправки будет уменьшена на %1$s (%2$s) для покрытия выбранного уровня комиссии + Далее + Нет + Нет адреса + Сейчас + OK + Основная карта + Парольная фраза + Вставить + %1$s-%2$s + Подробнее + Получить + Отклонить + Перезагрузить + Переименовать + Сохранить + Сохранить изменения + Искать + Поиск токенов + Seed-фраза + Выберите действие + Продать + Отправить + Сервер недоступен, повторите попытку позднее + Поделиться + Подписать + Подписать и отправить + Застейкать + Стейкинг + Начать + Отправить + Успешно + Поддержка + Обмен + условия участия + Сегодня + Ошибка транзакции + Транзакции + Перевод + Я понял + Произошла ошибка. Пожалуйста, попробуйте снова. + Недоступно + Завершить стейкинг + Да + Адрес контракта скопирован! + Доступные сети + Добавить токен + Адрес контракта + Адрес контракта некорректен + Пожалуйста, выберите сеть + Десятичное число должно быть действительным целым числом, до %li + Своя деривация + Например m/00\'/0000\'/0\'/0/0 + Введите свою деривацию + Знаков после запятой + Путь деривации + По умолчанию + Деривация по BIP44 + Введенный путь деривации некорректен + Например, USD Coin + Название токена + Не выбрано + Сеть + Сеть + Вы можете добавить токен в ручную, если он не поддерживается Tangem + Например, USDC + Символ + Символ токена + Этот токен/сеть уже находится в вашем списке + Токены могут быть созданы кем угодно. Остерегайтесь мошеннических токенов, они могут ничего не стоить + Остерегайтесь мошеннических токенов, они могут ничего не стоить + Токены могут быть созданы кем угодно + Купить кошелек Tangem + Чат + Код доступа + Перед сканированием карты вам нужно будет ввести правильный код доступа. + Задержка сканирования + Этот механизм защищает карту от бесконтактных атак. Между сканированием карты и выполнением команды будет добавлена задержка. + Пароль + Перед выполнением любой команды, влекущей за собой изменение состояния карты, вам необходимо будет ввести пароль. + Реферальная программа + Переверните экран вашего устройства вниз, чтобы быстро скрыть и отобразить балансы + %s хэшей + Номер карты + Обратиться в поддержку + Добавить еще карты + Валюта приложения + Скрывать балансы жестом переворота + Эмитент + Подписано + Отправить отзыв + Подробности + Проверьте подключение с интернетом или переключитесь на другую сеть + Условия использования + Вы использовали карту от другого кошелька. Приложите карту, связанную с этим кошельком. + Мои токены + У вас нет добавленных токенов. Добавьте токены для обмена + Недоступен для обмена с %s + Предоставлено + Статус + Tangem предоставляет доступ к обмену через сторонних поставщиков в соответствии с их правилами + Выберите провайдера + Произошла ошибка. Код: %s + К сожалению, обмен указанной пары через выбранного провайдера на данный момент невозможен. Попробуйте совершить обмен позже. (Код: %s) + Выбранный провайдер недоступен для обмена. Попробуйте позже. (Код: %s) + В данный момент обмен невозможен. Попробуйте позже. (Код: %s) + Курс обмена + Обмен через %s + Чтобы вернуть ваши деньги, посетите сайт провайдера + Операция не выполнена провайдером + Отправленные средства были возвращены в %1$s на ваш кошелек в соответствии с правилами OKX или моста обмена. %2$s + Сумма была возвращена в %1$s (%2$s сети) + Посетите сайт провайдера для проверки + Провайдер запрашивает прохождение верификации + Отменен + Подтверждено + Подтверждение + Подтверждение... + Обменяно + Обмен + Обмен... + Неудачно + Депозит получен + Ожидание депозита + Ожидаем пополнения... + Возвращено + Отправляем + Отправка средств... + Отправлено + Данные провайдера. Сумма к получению может измениться в зависимости от рыночных условий. + Статус обмена + Требуется верификация + Ожидание хеша транзакции + Список токенов в вашем кошельке + Получение наилучших курсов... + Плавающая ставка + Пользуясь сервисом, вы соглашаетесь с %s + Пользуясь сервисом, вы соглашаетесь с %1$s и %2$s + Больше провайдеров на подходе.\nСледите за обновлениями! + Политикой конфиденциальности + Провайдер + Лучший курс + Доступно до %s + Доступно с %s + Недоступно для этой пары + Требуется разрешение + Рекомендовано + Условиями использования + Токены не найдены. Пожалуйста, попробуйте другой запрос + ID: %s + ID транзакции скопирован + Информация ниже не является обязательной. Вы можете стереть её, если хотите. + Расскажите, каких функций вам не хватает, и мы постараемся вам помочь. + Скажите, пожалуйста, какая у вас карта? + Привет, команда поддержки, + Пожалуйста, расскажите нам больше о вашей проблеме. Каждая маленькая деталь может помочь. + Мои предложения + Не могу отсканировать карту + Обращение в поддержку + Обращение в поддержку Tangem + Не могу отправить транзакцию + Текущая транзакция + Комиссия сети за одобрение токена будет взиматься за подтверждение того, что именно вы разрешаете использовать ваш токен для обмена. + Укажите лимит доступа к выбранному токену + Количество %s + Функция подтверждения необходима для предоставления другому адресу разрешения на использование определенного количества ваших токенов.По замыслу смарт-контракты не могут получить доступ к вашим токенам, если вы не одобрите доступ со своей стороны. «Разблокируя» свои токены, вы даете смарт-контракту StakeKit разрешение использовать ваши активы. Майнеры сети получают компенсацию за газ (оплачиваемый вами) за запись этого действия в блокчейне. Как только разрешение будет предоставлено, вы сможете осуществить стейкинг токена. + Чтобы продолжить, вам необходимо разрешить смарт контракту StakeKit использовать ваш %s + Чтобы продолжить, вам нужно разрешить смарт-контракту %1s использовать ваш %2s + Дать разрешение + Безлимитно + Купить + Сканировать + Чтобы изменить код доступа, приложите карту как показано выше и не убирайте до окончания операции + Чтобы изменить пароль, приложите карту как показано выше и не убирайте до окончания операции + Чтобы создать кошелек, приложите карту как показано выше и не убирайте до окончания операции + Приложите карту #%s для сброса + Приложите, чтобы отсканировать + Приложите, чтобы подписать + Приложите карту + Вы обновили данные биометрии, отсканируйте свою карту для входа + Ваш баланс должен быть выше суммы комиссии для осуществления перевода + Недостаточно средств + У вас недостаточно Маны для этой транзакции. Пожалуйста, подождите, пока Мана восполнится. Ваш баланс маны равен %1$s/%2$s + Недостаточно Маны + Вы можете перевести только %s из-за ограничения Mana, установленного сетью Koinos + Лимит маны + Сеть Koinos использует Ману для оплаты комиссии сети. У вас есть %1$s/%2$s Mana + Уровень маны + Чтобы начать отслеживать свои криптоактивы и транзакции, добавьте токены + Управление токенами + Чтобы получить доступ ко всем сетям, вам необходимо отсканировать карту + Отсканируйте карту + Обменивайте свои токены с %1$s комиссии провайдера через Changelly с %2$s по %3$s февраля. + Обмен с Changelly, %s комиссии + Токены + Добавить + Изменить + Рыночная капитализация + Основная сеть + Не основной или основной блокчейн, на котором размещен токен + Не основные сети + Выберите сети + Кошелек + Не удалось найти этот токен, вы можете добавить его вручную. + + %1$d из %2$d кошелька + %1$d из %2$d кошельков + %1$d из %2$d кошельков + %1$d из %2$d кошельков + + Удалить + например Bitcoin + Ваш портфель был обновлен + Выбранный токен не доступен в кошельке на данный момент. Но не переживайте, вы можете выразить свой интерес проголосовав за его добавление. + Голосовать + Выберите кошелек + Кошелёк не поддерживает более одной сети + Чтобы создать адреса для выбранных сетей, необходимо отсканировать свой кошелек Tangem. + Ссылки + Метрики + Вам необходимо установить единый код доступа для защиты всех ваших карт + Защита + Позже вы сможете установить индивидуальный код доступа для каждой карты + Персонализация + Код доступа можно восстановить с помощью привязанной карты. Не храните все карты в одном месте. + Восстановление + Выберите любое слово, фразу или число в качестве кода доступа + Создайте код доступа + Введите код доступа еще раз, чтобы избежать ошибки + Повторно введите код доступа + Код доступа должен состоять не менее чем из 4 символов. + Введенные коды доступа не совпадают + Необходимо повторить операцию, при этом карта будет сброшена к заводским настройкам + Ошибка активации + Добавление токенов + Вы добавили одну резервную карту. После того, как процесс будет завершен, Вы больше не сможете добавить карт. Если у Вас есть еще одна карта, добавьте ее в резервную копию. Хотите продолжить? + Процесс резервного копирования почти завершен. Вы не можете выйти из него сейчас. + Парольная фраза — это расширенная функция безопасности, которую используют криптокошельки. Она добавляет дополнительное слово или фразу по вашему выбору к уже существующей seed - фразе, чтобы разблокировать совершенно новый набор адресов. + Добавить резервную карту + Сканировать карту #%d + Создать резервную копию + Сканировать основную карту + Перейти к моему кошельку + Завершение бэкапа + Получить криптовалюту + Сканировать основную карту + Пропустить + Как это работает? + Давайте сгенерируем все ключи на вашей карте и создадим безопасный кошелек + Создать кошелек + Создать кошелек + Другие опции + Ваши ключи будут надежно сгенерированы внутри карты. Никакой seed-фразы, а это значит, что никто не может экспортировать или украсть ее. + Cоздавайте ключи приватно + Ваша карта активирована и готова к использованию + Успешно! + В этом случае вам будет необходимо начать процесс заново. + Вы хотите выйти из процесса активации? + Подготовка + Другой кошелек уже был создан на карте, которую вы пытаетесь добавить. Если на нем есть средства, пожалуйста сначала выведите их, а затем сделайте сброс до заводских настроек и используйте как резервную. + Резервная копия + Прочитать о seed-фразе + + + Запишите эти %d слова в порядке, указанном ниже, и сохраните их в надежном месте. + Запишите эти %d слов в порядке, указанном ниже, и сохраните их в надежном месте. + Запишите эти %d слов в порядке, указанном ниже, и сохраните их в надежном месте. + + Ваша seed-фраза + + + %d слова + %d слов + %d слов + + Чтобы импортировать кошелек, введите seed-фразу в поле ниже + Создать seed-фразу + Импорт кошелька + Seed-фраза — это набор слов, который дает возможность восстановить кошелек. В отличие от ключей, сгенерированных картой, seed-фраза не защищена и может быть скопирована и украдена. Используйте этот вариант на свой страх и риск. + Использовать seed-фразу + Неверная seed-фраза. Пожалуйста, проверьте порядок слов. + Неверная seed-фраза. Пожалуйста, проверьте орфографию. + Устаревший + Чтобы проверить, правильно ли вы записали seed-фразу, введите 2-е, 7-е и 11-е слова + Итак, проверим + Чтобы начать процесс резервного копирования, добавьте одну или две резервные карты. + Вы можете добавить еще одну карту или завершить процесс резервного копирования + Подготовьте резервную карту с номером %s + Отсканируйте основную карту, чтобы начать процесс резервного копирования. + Подготовьте основную карту с номером %s + Ваша карта настроена и готова к использованию. + Добавлено максимальное количество карт. Завершите процесс резервного копирования. + Активация карты + Резервная карта #%d + Нет резервных карт + Уведомления + Добавлена ​​одна резервная карта + Подготовьте свою карту + Добавлены две резервные карты + Пополните кошелек на любую сумму, чтобы начать пользоваться картой + Пополните кошелек более чем на %1$s %2$s, чтобы начать пользоваться картой + Купить криптовалюту + Показать адрес кошелька + Активация кошелька + Процесс связывания карт частично завершен. Вы не можете выйти из него сейчас. + Если процесc создания кошелька каким-либо образом прервется, вам придется начинать сначала + Вы можете сделать резервную копию своих ключей на одной или двух других пустых картах Wallet. + Код доступа можно восстановить с помощью одной из резервных карт. + Все резервные карты являются полнофункциональными и содержат одинаковые ключи. + Вы сможете установить код доступа для защиты своих кошельков. + Резервная копия карты + Восстановление кода доступа + Идентичные карты + Код доступа + Группы + По балансу + Упорядочить токены + Список + Выбрать из галереи + Настройки + Вы не предоставили доступ к вашей камере + Доступ к камере запрещен + %1$s (%2$s) в сети %3$s + Отправляйте только %s на этот адрес. Использование другой сети может привести к утрате средств. + Участвовать + Не удалось загрузить информацию по реферальной программе. Пожалуйста, попробуйте позже. + Не удалось загрузить информацию по реферальной программе. Код ошибки: %s. Пожалуйста, попробуйте позже. + Грядущие выплаты + Ваши друзья купили + Меньше + Больше + Нет грядущих выплат + + за %d кошелек + за %d кошелька + за %d кошельков + за %d кошельков + + Получите ^^%1$s^^ на ваш адрес в сети %2$s %3$s ^^спустя 30 дней^^ за каждый кошелек, который купит ваш друг + Вы + Получит + при покупке кошелька на сайте tangem.com + %s скидку + Ваш друг + Персональный код скопирован! + Ваш персональный код + Купи Tangem Wallet со скидкой!\n%s + Приведи друга в Tangem + Вы приняли + Нажимая на эту кнопку, вы принимаете + в реферальной программе + + %d кошелек + %d кошелька + %d кошельков + %d кошельков + + Сбросить карту + Я понимаю, что после выполнения этого действия у меня больше не будет доступа к текущему кошельку + Я понимаю, что не смогу этой картой восстановить пароль на остальных картах этого кошелька, если я его забуду + Сброс к заводским настройкам приведет к полному удалению кошелька с выбранной карты. Вы не сможете восстановить текущий кошелек или использовать данную карту для восстановления кода доступа. + Сброс к заводским настройкам приведет к полному удалению кошелька с выбранной карты. Вы не сможете восстановить текущий кошелек. + У вас есть карта банка другой страны, а также вид на жительство или регистрация вне РФ? + Карты банков РФ в данный момент не принимаются + Войдите в приложение и следите за своим балансом без сканирования карты + Доступ в приложение + Использовать биометрию + Для операций с вашим кошельком будет запрашиваться биометрия вместо кода доступа карты + Код доступа + Похоже, что у вас отключена биометрическая аутентификация, она необходима для сохранения кошельков + Включите биометрическую аутентификацию + Вы хотите использовать биометрию? + Обратите внимание, что для совершения транзакции с вашими средствами по-прежнему потребуется ваша карта + Сканировать + Отсканируйте карту, чтобы изменить ее настройки. Изменения затронут только ту карту, которую вы отсканировали, и не повлияют на другие карты, привязанные к вашему кошельку. + Приготовьте свою карту + Уже содержится во введенном адресе + Сумма комиссии в %s раз превышает рекомендованную. Убедитесь, что указанная комиссия верна. + Вы указали комиссию ниже рекомендуемой, это может привести к задержке исполнения вашей транзакции. Продолжить? + Причина: %1$s\nКод: %2$s + Транзакция не выполнена + Сумма + Вы можете установить комиссию за транзакцию, изменив значение в поле Satoshi per vByte. + Комиссия, которая будет взята за вашу транзакцию. Вы можете выставить своё собственное значение. + Это стоимость, которую вы готовы заплатить за каждую единицу газа. Чем выше цена газа, тем быстрее ваша транзакция будет обработана. (Приоритетная комиссия включена) + Приоритетная комиссия + Комиссия, которую пользователь может заплатить майнерам или валидаторам за ускорение включения его транзакции в блок. + Комиссия, которую нужно заплатить за использование каждого неиспользованного выхода транзакции (UTXO) в сети Kaspa. Чем больше UTXO вы используете в транзакции, тем выше будет комиссия. + KAS за UTXO + %1$s, %2$s + Адрес + Код назначения + Введите адрес + Адрес совпадает с адресом кошелька + Недопустимый Tag. Он не будет добавлен в транзакцию. + Недопустимый Memo. Он не будет добавлен в транзакцию. + Tag + Memo + Включая комиссию + Низкая + Нормальная + Приоритетная + Проверьте своё интернет соединение + Информация о комиссии сети недоступна + Из + Лимит газа + Это максимальное количество газа, которое будет потрачено на выполнение транзакции или контракта. Лимит газа предотвращает неожиданные или неограниченные расходы при выполнении транзакции. + Цена газа + Это стоимость, которую вы готовы заплатить за каждую единицу газа. Чем выше цена газа, тем быстрее ваша транзакция будет обработана. + Всё + Максимальная сумма + Комиссия не превысит + Недопустимый Memo + Покрытие сетевой комиссии + Недостаточно средств для перевода, так как сумма комиссии и сумма перевода в совокупности больше имеющегося баланса + Недостаточно средств + Аккаунт будет удален из блокчейна, если баланс упадет ниже экзистенциального депозита. Пожалуйста, оставьте %s на балансе. + Экзистенциальный депозит + Сумма комиссии в %s раз превышает рекомендованную. Убедитесь, что указанная комиссия верна. + Установлена высокая комиссия + Ввиду особенности сети %1$s комиссия при переводе всего баланса выше. Для того, чтобы снизить комиссию Вы можете оставить %2$s. + Комиссия повышена + Включенная комиссия превышает сумму перевода, что приводит к отрицательному значению + Недопустимая сумма + Минимальная сумма отправки - %1$s. Пожалуйста, убедитесь, что остаток после отправки также не будет меньше %2$s. + Адрес получателя не активирован. \nПожалуйста, измените сумму отправки, чтобы продолжить. + Сумма отправки не может быть менее %s + Оставить %s + Уменьшить на %s + Уменьшить до %s + Обратите внимание, что при определенных параметрах комиссии возможны задержки по вашей транзакции + Возможны задержки по транзакции + Из-за ограничений %1$s в одну транзакцию может поместиться только %2$s UTXO. Это означает, что вы можете отправить только %3$s или меньше. Вам нужно уменьшить сумму. + Лимит транзакции + Опционально + Пожалуйста, совместите свой QR-код с квадратом, чтобы отсканировать его. Убедитесь, что вы сканируете адрес в сети %s. + Последние + Получатель + Неверный адрес + Убедитесь, что вы отправляете средства на адрес кошелька %s. Ошибки могут привести к потере ваших токенов. + Отправить + Мемо/ Код назначения - это код, разделяющий транзакции к общему получателю в сети криптовалют. Внимание: отсутствие мемо может привести к потере средств. + Мои кошельки + Способ измерения комиссии за биткоин-транзакцию. Он указывает на количество самой маленькой единицы биткоина (сатоши) за каждый виртуальный байт в транзакции. Чем выше число, тем быстрее будет обработана транзакция майнерами. + Сатоши / вбайт + Отправка + Нажмите на любое поле, чтобы изменить его + Отправка %s + Вы отправляете **%1$s**, включая комиссию сети %2$s + Вы отправляете **%1$s** и %2$s + Отправка %s + Всего + %1$s и %2$s будет отправлено + ≈ %1$s (вкл. комиссию: %2$s) + %s будет отправлено + Транзакция успешно подписана и отправлена в блокчейн. Баланс будет обновлен через некоторое время + %1$s — это монета в сети Tron. Чтобы рассчитать комиссию и совершить транзакцию, вам необходимо внести немного Tron (TRX) на свой адрес. + Неверный адрес + Транзакция отправлена + Подготовьтесь к сканированию карты, которую вы хотите настроить. + Забыть кошелек + Это приведет к удалению кошелька из приложения. Сам кошелек можно добавить снова. + Имя + Активно + Для завершения стейкинга нажмите сюда + Сумма для стейкинга должна быть не менее %s + Забрать средства + APY + Годовой процентный доход, который вы можете получить от участия в стейкинге. + APR + Доступно + Средння ставка вознаграждения + %s оценка доходности + Позиция в рынке + Метрики + Минимальное количество + Нет вознаграждений к получению + Способ возраграждения + Способ получения вознаграждений за стейкинг. Он может быть автоматическим, при котором вознаграждение само зачисляется вам на адрес или в ручную, когда вознаграждение нужно вывести, создав транзакцию на её получение. + Период возрагражения + Это период, определяющий, когда участники стейкинга получат свои вознаграждения. + Вознаграждение для получения: %s + Стейкинг %s + Период вывода + Период, который необходимо подождать после запроса на вывод средств из стейкинга, прежде чем токены станут доступны. + Период прогрева + Время, необходимое для начала процесса стейкинга и активации процесса начисления наград + Застейкать %s + Переместить + Нативный стейкинг + Стейкинг дает возможность вам получать %1s. Награда будет зачисляться каждый %2s + Получите награду за стейкинг + Награда перестанет начисляться сразу после завершения стейкинга. Процесс завершения длится %s. + Повторный стейкинг + Застейкать вознаграждения + Отозвать + Переголосовать + Вознаграждения + Застейкать еще + Разблокировать + Выведено из стейкинга + Проверьте процесс завершения стейкинга, чтобы вывести свои средства. + Завершение стейкинга + Валидатор + Проголосовать + Вывод + Держите свои криптосбережения в безопасности. Приватные ключи надежно хранятся на карте. + Революционный аппаратный кошелек + До трех карт с одним кошельком + Все ключи в безопасности + Аппаратный кошелек для ваших биткоинов, эфира и многих других валют одновременно — все в одной карте + Тысячи криптовалют + Используйте его на ходу, в любом месте, в любое время. Без проводов и батареек. Как только понадобится крипта, просто приложите карту к телефону. + Кошелек для каждого + Встречайте Tangem + Обменивайте, покупайте NFT, получайте займы и делайте вклады в более чем 100 различных децентрализованных сервисах + Поддержка Web 3.0 + Обменивайте больше токенов по лучшим курсам прямо в вашем кошельке. + Новый провайдер обмена! + В сумму включено: \n• комиссия провайдера сервиса\n• комиссия сети за отправку %s от биржи обратно на адрес пользователя + В сумму включена комиссия провайдера сервиса. + Комиссии + Подтверждения считаются отраслевым стандартом для всех децентрализованных бирж и защищают ваш кошелек от доступа со стороны смарт-контракта без вашего разрешения. По замыслу смарт-контракты не могут получить доступ к вашим токенам, если вы не одобрите доступ со своей стороны. «Разблокируя» свои токены, вы даете смарт-контракту 1inch разрешение тратить ваши активы. Майнеры сети получают компенсацию за газ (оплачиваемый вами) за запись этого действия в блокчейне. Как только разрешение будет предоставлено, вы сможете обменять свой токен. + Подтвердить + Вы отправляете + Обмен этой суммы выбранных токенов может вызвать значительные колебания цены и уменьшить получаемую сумму. + Недостаточно средств + Дать разрешение + В процессе + Обменять + Вы получите + Выберите токен + не доступен + Балансы скрыты + Балансы показаны + Отменить + Выбранная операция в данный момент недоступна. Попробуйте позже. + В данный момент покупка монеты %s недоступна. Следите за нашими обновлениями. + У вас нет средств для продажи. Пополните счет, чтобы иметь возможность продать с него средства. + У вас нет средств для отправки. Пополните счет, чтобы иметь возможность отправить с него средства. + В данный момент обмен монеты %s недоступен. Следите за нашими обновлениями. + Продажа средств станет доступной после завершения транзакции(-ий) в сети %s + Отправка средств станет доступной после завершения транзакции(-ий) в сети %s + В данный момент продажа %s недоступна. Следите за нашими обновлениями. + В данный момент стейкинг монеты %s недоступен. Следите за нашими обновлениями. + Сгенерировать XPUB + Скрыть + Вы скрываете токен с главного экрана, но в любой момент сможете добавить его обратно через страницу управления токенами. + Скрыть %s + Скрыть токен + Стейкинг позволяет вам зарабатывать %1$s и получать вознаграждения каждые %2$s дней + Зарабатывайте до %s вознаграждений за стейкинг ежегодно + %1$s токен в сети %%image%% %2$s + Токен в сети %%image%% %1$s + Токен %1$s (%2$s) является основной валютой в сети %3$s и не может быть скрыт до тех пор, пока у вас в списке есть другие токены этой сети + Невозможно скрыть %s + Обменивайте этот токен на другие с %1$s комиссии за обслуживание с %2$s по %3$s февраля. + Обмен с Changelly, %s комиссии + Обменять + контракт: %s + У вас еще нет транзакций + Не удалось загрузить историю транзакций.\nНажмите на кнопку перезагрузки, чтобы обновить информацию. + Несколько адресов + История транзакций в настоящее время не поддерживается для этого блокчейна. Но не волнуйтесь, мы работаем над этим! А пока вы можете проверить ее в обозревателе. + Операция + от: %s + на: %s + Вы отсканировали ту же карту. Для создания twin-кошелька вам необходимо отсканировать карту с номером %d + Вы отсканировали не ту twin-карту. Пожалуйста, попробуйте отсканировать другую + Это карта, которую вы держите в руках. У парной карты номер %s.\n\nОбе карты можно использовать для вывода средств из этого кошелька. + Один кошелек. Две карты. + Сканировать карту #%s + Создание кошелька + Отсканируйте twin-карту #%s + Подготовка карты + Tangem Twin + Это действие необратимо. У вас не будет доступа к старому кошельку. + Приложите twin-карту с номером %s и не убирайте до окончания операции + Используйте %s или отсканируйте карту, чтобы получить доступ к своему кошельку + Будьте в курсе новых функций и новостей + Узнавайте первым о новых акциях + Хотите использовать Push-уведомления? + Добавить новый кошелек + Вы уверены, что хотите удалить этот кошелек? + Произошла ошибка, пожалуйста, отсканируйте свою карту для входа + Этот кошелек уже был сохранен, вы можете добавить другой + Кошелек с именем %s уже существует + Имя кошелька + Переименование кошелька + Разблокировать все + Разблокировать все с %s + Блокчейн недоступен. Попробуйте позже. + Отсканируйте карту + Запрос на подпись сообщения.\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 + Буфер обмена содержит код 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 Попробуйте, пожалуйста, позже. Если проблема будет продолжать возникать - обратитесь в службу поддержки. + Нет открытых сессий WalletConnect + Упс. Нет сессий. + Не удалось создать пару WalletConnect: %1$s + Вставить из буфера обмена + Сообщение для %1$s:\n%2$s + Запрос на открытие сессии для\n%1$s\n\nСЕТЬ: %2$s\n\nURL: %3$s + Операция не может быть завершена.\n\nВы уже установили сеанс WalletConnect с этими параметрами. + Сканировать новый код + Эту карту нельзя использовать с WalletConnect. + Сеть не поддерживается. Пожалуйста, выберите другую сеть. + Выберите сеть + Сессии WalletConnect + Подключение к dApps + WalletConnect + Подключение может занять несколько секунд + Рыночная цена %s + за 24 часа + Сеть %s + Адрес скопирован в буфер обмена + Нет соединения с интернетом + Настройки кошелька + Tangem + Используйте %s или отсканируйте карту, чтобы разблокировать доступ к вашему кошельку + Похоже, что процесс активации карт не был завершен корректно. Это могло быть вызвано проблемой взаимодействия с модулем NFC либо некорректным прикладыванием карты к телефону. Пожалуйста, обратитесь в нашу службу поддержки для уточнения деталей. + Ошибка активации + По решению разработчиков сети BNB стандарт BEP-2 перестанет поддерживаться в июне 2024 года. Чтобы не потерять активы, их необходимо преобразовать в стандарт BEP-20. Используйте функцию обмена в приложении или сторонние сервисы, чтобы перевести средства в cеть BNB Smart Chain. + Отключение сети BNB Beacon Chain + Можно лучше + Нравится + Понятно! + Очень круто! + Обновить + Вы находитесь в режиме демо + Демо режим включен + Отсканированная вами карта является картой разработчика. Не используйте ее для создания своего кошелька. + Не для пользователя! + Cеть %1$s использует концепцию экзистенциального депозита. Если баланс вашего счета будет ниже %2$s, то он будет деактивирован, а средства на счете уничтожены. + Для работы с сетью необходим депозит + Обмен будет доступен после завершения %s транзакции + У вас есть активная транзакция + Разрешение обмена в процессе и будет скоро завершено + Разрешение в процессе + Минимальная сумма обмена - %1$s. Пожалуйста, убедитесь, что остаток после обмена также не будет меньше %2$s. + У вас в списке нет монет доступных для обмена с %s + Нет доступных для обмена токенов + Чтобы совершить транзакцию, вам необходимо внести немного %1$s %2$s + Невозможно покрыть комиссию %s + Сумма получения не может быть менее %s + Cервис временно недоступен + Сумма для обмена должна быть не более %s + Сумма для обмена должна быть не менее %s + Пожалуйста, измените сумму для обмена + Возможно, данная карта - образец или подделка + Ошибка проверки подлинности + Ассоциировать + Этот токен должен быть ассоциирован с вашей учетной записью Hedera, прежде чем вы сможете его принять. Стоимость ассоциации ~%1$s %2$s + Этот токен должен быть ассоциирован с вашей учетной записью Hedera, прежде чем вы сможете его принять + Ассоциируете свой токен + Недостаточно %s. Пополните ваш аккаунт Hedera для ассоциации этого токена + На этой карте осталось всего %s подписей. Вам следует вывести все ваши средства. + Малое количество подписей + Токены на разных сетях могут иметь разные адреса. Пожалуйста, убедитесь при переводе средств, что ваш адрес соответствует сети. + + Используйте вашу карту, чтобы получить адрес для %d сети + Используйте вашу карту, чтобы получить адреса для %d сетей + Используйте вашу карту, чтобы получить адреса для %d сетей + Используйте вашу карту, чтобы получить адреса для %d сетей + + Некоторые адреса отсутствуют + В данный момент сеть недоступна. Пожалуйста, попробуйте позже. + Сеть недоступна + Пополните ваш кошелек + Ваш кошелек не имеет резервной копии. Проведите эту процедуру сейчас, чтобы защитить ваши активы. + Резервная копия отсутствует + Эта карта ранее использовалась для подписи транзакций. Если она получена от ненадежного источника, рассмотрите возможность вывода своих средств. Если это ваша карта, дополнительных действий не требуется. + Карта уже подписывала транзакции + Ваш отзыв мотивирует нас сделать кошелек Tangem еще лучше + Нравится Tangem? + Вам необходимо провести ассоциацию токена для того, чтобы иметь возможность принимать его + Необходима плата за аренду сети + %1$s - это монета в сети %2$s. Для совершения транзакции %3$s, вам необходимо внести немного %4$s (%5$s), чтобы покрыть комиссию сети. + Недостаточно %1$s для оплаты комиссии сети + Сеть Солана испытывает высокую нагрузку. Если Ваша транзакция не прошла в течение 2 минут, повторите её отправку. + Оповещение сети Солана + Сеть Solana взимает арендную плату в размере %1$s каждые 2 дня. Аккаунты, которые не могут позволить себе арендную плату, удаляются из сети. Пополните свой счет более чем на %2$s, чтобы не платить арендную плату. + Некоторые сети в настоящее время недоступны. Пожалуйста, повторите попытку позже. + Некоторые сети недоступны + Это Testnet карта. Он не может обрабатывать транзакции и используется только в целях тестирования и разработки. + Только для целей тестирования + Отказаться + Вы не закончили резервное копирование. Хотите продолжить? + Да, возобновить + Отказаться + Если сейчас отказаться, то придётся сбрасывать карты до заводских настроек, чтобы начать заново + Возобновить резервное копирование + Это необратимое действие + Войти с %s + Сканировать карту + Используйте %s или отсканируйте карту для входа в приложение + C возвращением! diff --git a/core/res/src/main/res/values-uk-rUA/strings-blockchain.xml b/core/res/src/main/res/values-uk-rUA/strings-blockchain.xml new file mode 100644 index 0000000000..d2c3ed6cdf --- /dev/null +++ b/core/res/src/main/res/values-uk-rUA/strings-blockchain.xml @@ -0,0 +1,25 @@ + + + За замовчуванням + Застарілий + Не вдалося отримати комісію + Через обмеження %1$s в одну транзакцію може поміститися тільки %2$d UTXO. Це означає, що ви можете відправити тільки %3$s або менше. Вам потрібно зменшити суму. + Недостатньо коштів для здійснення транзакції. Будь ласка, поповніть свій акаунт. + Виникла помилка. Код: %s. + Щоб користуватися мережею %1$s, ви маєте оплатити резерв акаунта (%2$s %3$s), який блокується і не використовується у вашому балансі + Обліковий запис одержувача не активовано. Надішліть %s або більше, щоб активувати обліковий запис. + Для створення акаунту надішліть кошти на цю адресу + Мінімальна сума: %s + Решта занадто мала + Невірна комісія + Мінімальний баланс: %s + Обліковий запис одержувача не створено. Сума для переказу повинна бути %s + комісія або більше + Невідома помилка + Сума перевищує залишок + Недопустима сума + Комісія перевищує залишок + Сума, що відправляється, перевищує залишок + Ні, відправити все + Зменшити на %s XTZ + Щоб не платити підвищену комісію при наступному поповненні гаманця, зменште суму на %s XTZ + diff --git a/core/res/src/main/res/values-uk-rUA/strings.xml b/core/res/src/main/res/values-uk-rUA/strings.xml new file mode 100644 index 0000000000..14a8373849 --- /dev/null +++ b/core/res/src/main/res/values-uk-rUA/strings.xml @@ -0,0 +1,895 @@ + + + Оберіть мережу + Додати токен + Керування токенами + Надсилайте тільки %1$s (%2$s) в мережі %3$s на цю адресу. Використання іншої мережі може призвести до втрати коштів. + Як сканувати + Звернутися в підтримку + Спробуйте ще раз + Ця функція недоступна в демонстраційному режимі + Причина: %s + Не вдається відправити транзакцію + Обраний гаманець не підтримує мережу %1$s + Щоб активувати криптографічне шифрування блокчейну %1$s, вам потрібно скинути налаштування гаманця до заводських. Зніміть свої кошти перед цим, щоб переконатися, що ви їх не втратите, а потім завершіть процес скидання. Вхід до поточного гаманця буде неможливий після скидання. + Токени в мережі %1$s не підтримуються цією карткою через обмеження прошивки. + У вас виникли труднощі зі скануванням картки? + Ця картка не призначена для роботи з цим додатком + Комісія за замовчуванням + Увімкніть комісію за замовчуванням, щоб автоматично встановлювати комісію за транзакцію і пропускати сторінку комісій під час відправлення коштів. Ви завжди можете повернутися до цієї сторінки за необхідності. + Перейдіть до налаштувань, щоб увімкнути біометричну автентифікацію в додатку Tangem + Увімкнути біометричну автентифікацію + Усі збережені коди доступу будуть видалені. Вам доведеться вводити код доступу при роботі з гаманцем. + При відключенні функції збереження гаманця всі збережені до цього гаманці будуть видалені зі застосунку. + Зберегти код доступу + Підключіть функцію збереження кодів доступу від карток на телефоні у зашифрованому виді, і при роботі з карткою замість коду доступу буде запитуватися біометрична автентифікація. + Зберігати гаманець у додатку + Увімкніть функцію привʼязки карток у застосунку, а також можливість біометричної автентифікації. Підпис транзакції й надалі буде потребувати картку. + Темна + Світла + Системна + Тема + Налаштування застосунку + Щоб приховати або показати свій баланс, просто переверніть екран пристрою вниз або вимкніть його в налаштуваннях + Більше не показувати + Зрозуміло + Баланси приховані + Будь ласка, відскануйте картку + Будь ласка, повторіть спробу через 30 секунд або відскануйте картку + Забагато спроб + Ви вимкнули біометричну автентифікацію на своєму телефоні і не зможете зберігати гаманці в додатку. Щоб зберегти гаманці, будь ласка, увімкніть функцію біометричної автентифікації в налаштуваннях телефону. + Почніть процес резервного копіювання + З вашої фіатної картки або банківського рахунку + + %d картка + %d картки + %d карток + %d карток + + Вимкніть цю опцію, якщо ви не хочете, щоб ця картка використовувалася для скидання кодів доступу до інших карток у цьому гаманці. Зверніть увагу, що це також унеможливить скидання коду доступу на цій картці. + Дозволяє використовувати цю картку для скидання коду доступу на інших картках у цьому гаманці + Відновлення коду доступу + Скинути + Ви впевнені, що хочете це зробити? + Зміна коду доступу + Код доступу буде змінено лише на цій картці + Усі картки у вибраному гаманці було скинуто до заводських налаштувань. Тепер ви можете створити новий гаманець. + Скидання завершено + Ви хочете скинути наступну картку в цьому гаманці? + Скидання картки + Рекомендуємо завершити процес скидання для всіх карток у цьому гаманці + Ви скинули не всі картки + Скинути до заводських налаштувань + Тип безпеки + Налаштування картки + Крім мережевих комісій, мережа Cardano стягує %1$s ADA при транзакції з токеном %2$s + Вимоги до транзакції Cardano + Щоб здійснити транзакцію %1$s, внесіть певну суму ADA для покриття мережевої комісії та мінімальне значення ADA (рекомендовано 5 ADA) + Недостатньо ADA для транзакції + Ви повинні утримувати деяку кількість ADA, оскільки у вас на балансі є токени в мережі Cardano + Недостатньо ADA + Прийняти + Доступ заборонено + Усе + Дозволити + Застосовувати + Затвердження + Підтвердити + Увага + Баланс: %s + Баланс + біометрична автентифікація + біометрією + Купити + Перейдіть до %1$s + Ви не надали доступ до камери, будь ласка, змініть налаштування конфіденційності + Скасувати + Отримати винагороди + Закрити + Продовжити + Копіювати + Скопіювати адресу + Створити + Власна + + %d день + %d днів + %d днів + %d днів + + Видалити + Вимкнуто + Готово + Увімкнути + Увімкнено + Помилка + Оглядач + Переглянути історію транзакцій + Оглядач + Комісія + Мережеві комісії – це збори, які користувачі сплачують за обробку та підтвердження транзакцій. На розмір комісії може впливати перевантаження мережі, розмір транзакції та пріоритет виконання. %s + Швидко + За ринком + Повільно + Швидкість та комісія + Отримати адреси + Перейти до провайдера + Перейти до токену + Імпортувати + Пізніше + Заблокований + Основна мережа + Комісія мережі + Сума відправлення буде зменшена на %1$s (%2$s) для покриття обраного рівня комісії + Далі + Ні + Немає адреси + Зараз + ОК + Основна картка + Парольна фраза + Вставити + %1$s-%2$s + Детальніше + Отримати + Відхилити + Перезавантажити + Перейменувати + Зберегти + Зберегти зміни + Шукати + Пошук токенів + Seed-фраза + Оберіть дію + Продати + Надіслати + Сервер недоступний, спробуйте пізніше + Поширити + Підписати + Підписати та надіслати + Застейкати + Стейкінг + Почати + Надіслати + Успіх + Підтримка + Обмін + умови участі + Сьогодні + Помилка транзакції + Транзакції + Переказ + Я зрозумів + Виникла помилка. Будь ласка, спробуйте ще раз. + Недоступно + Скасувати стейкінг + Так + Адреса контракту скопійована! + Доступні мережі + Додати токен + Адреса контракту + Адреса контракту недійсна + Будь ласка, оберіть мережу + Десяткове число повинно бути дійсним цілим числом, до %li + Власна деривація + Наприклад, m/00\'/0000\'/0\'/0/0 + Введіть власну деривацію + Знаків після коми + Шлях деривації + За замовчуванням + Тип монети BIP44 + Введений шлях деривації недійсний + Наприклад, USD Coin + Назва токену + Не обрано + Мережа + Мережа + Ви можете вручну додати токен, який не підтримується Tangem + Наприклад, USDC + Символ + Символ токену + Цей токен/мережа вже знаходяться у вашому списку + Зауважте, що токени можуть бути створені ким завгодно. Остерігайтеся шахрайських токенів, вони можуть нічого не коштувати. + Остерігайтеся шахрайських токенів, вони можуть нічого не коштувати + Зауважте, що токени можуть бути створені ким завгодно + Купити гаманець Tangem + Чат + Код доступу + Перед скануванням картки вам потрібно буде ввести правильний код доступу + Затримка сканування + Цей механізм захищає картку від безконтактних атак. Між скануванням картки та виконанням команди буде додана затримка. + Пароль + Перед виконанням будь-якої команди, що тягне за собою зміну стану картки, вам необхідно буде ввести пароль. + Реферальна програма + Переверніть екран пристрою вниз, щоб швидко приховати та відобразити баланси + %s хешів + Номер картки + Звернутися у підтримку + Додати більше карток + Валюта застосунку + Приховувати баланси жестом перевороту + Емітент + Підписано + Надіслати відгук + Деталі + Перевірте підключення до інтернету або змініть мережу + Умови використання + Ви використали картку від іншого гаманця. Прикладіть картку, пов\'язану з цим гаманцем. + Мої токени + У вас немає доданих токенів. Додайте токени для обміну + Недоступний для обміну з %s + Послугу надає + Статус + Tangem пропонує обмін токенів через сторонніх провайдерів відповідно до умов кожного провайдера + Оберіть провайдера + Виникла помилка. Код: %s + На жаль, обмін вказаної пари через обраного провайдера тимчасово неможливий. Спробуйте здійснити обмін пізніше. (Код: %s) + Наразі обраний провайдер недоступний для обміну. Спробуй пізніше. (Код: %s) + Наразі обмін неможливий. Спробуй пізніше. (Код: %s) + Курс обміну + Обмін через %s + Щоб повернути ваші кошти, відвідайте сайт провайдера + Операція не виконана провайдером + Сума транзакції була повернута в %1$s на ваш гаманець відповідно до правил OKX або мосту обміну. %2$s + Сума була повернута в %1$s (%2$s мережі) + Відвідайте сайт провайдера для перевірки + Провайдер вимагає проходження KYC верифікації + Скасовано + Підтверджено + Підтвердження + Підтвердження... + Обміняно + Обмін + Обмін... + Не вдалося + Депозит отримано + Очікуємо на депозит + Очікуємо на депозит... + Повернено + Надсилаємо вам + Надсилаємо вам... + Надіслано + Дані провайдера. Орієнтовна сума може бути змінена через ринкові умови. + Статус обміну + Потрібна верифікація + Очікування хешу транзакції + Список токенів у вашому гаманцю + Шукаємо найвигідніший курс... + Плаваюча ставка + Використовуючи сервіс обміну, ви погоджуєтеся з його %s + Використовуючи сервіс обміну, ви погоджуєтеся з його %1$s та %2$s + Незабаром з\'являться нові провайдери.\nСлідкуйте за новинами! + Політикою конфіденційності + Провайдер + Найкращий курс + Доступно до %s + Доступно від %s + Недоступно для цієї пари + Потрібен дозвіл + Рекомендовано + Умовами використання + Токенів не знайдено. Будь ласка, спробуйте інший запит + ID: %s + ID транзакції скопійовано + З іншої валюти у вашому гаманці + Інформація нижче не є обов\'язковою. Ви можете стерти її, якщо бажаєте. + Розкажіть, яких функцій вам не вистачає, і ми спробуємо вам допомогти. + Розкажіть, будь ласка, яку картку ви маєте? + Привіт, команда підтримки, + Будь ласка, розкажіть нам більше про вашу проблему. Кожна дрібниця може допомогти. + Мої пропозиції + Не вдається відсканувати картку + Звернення в підтримку + Звернення в підтримку Tangem + Не вдається відправити транзакцію + Поточна транзакція + Мережа стягує комісію за схвалення токену за підтвердження, що саме ви дозволяєте використовувати ваш токен для обміну. + Вкажіть ліміт доступу для обраного токена + Кількість %s + Функція підтвердження необхідна для надання дозволу іншій адресі на використання певної кількості ваших токенів. За задумом, смарт-контракти не можуть отримати доступ до ваших токенів без вашого схвалення. \"Розблоковуючи\" свої токени, ви дозволяєте смарт-контракту StakeKit використовувати їх. Майнери мережі отримують плату за газ (сплачену вами), щоб зафіксувати цю дію в блокчейні. Ви зможете застейкати свій токен після того, як дасте дозвіл. + Щоб продовжити, вам потрібно дозволити смарт-контракту StakeKit використовувати ваш %s + Щоб продовжити, вам потрібно надати дозвіл смарт-контракту %1s використовувати ваш %2s + Надати дозвіл + Необмежено + Купити + Сканувати + Щоб змінити код доступу, прикладіть картку, як показано вище, і не прибирайте її до закінчення операції + Щоб змінити пароль, прикладіть картку, як показано вище, і не прибирайте її до закінчення операції + Щоб створити гаманець, прикладіть картку, як показано вище, і не прибирайте її до завершення операції + Прикладіть картку #%s для скидання + Прикладіть, щоб відсканувати + Прикладіть, щоб підписати + Прикладіть картку + Ви оновили біометричні дані, відскануйте свою картку для входу + Ваш баланс повинен перевищувати суму комісії для здійснення переказу + Недостатньо балансу + У вас недостатньо Mana для цієї транзакції. Будь ласка, зачекайте, поки Mana буде поповнена. Ваш баланс Mana становить %1$s/%2$s + Недостатньо Mana + Ви можете переказати тільки %s через обмеження Mana, встановлене мережею Koinos + Ліміт Mana + Мережа Koinos вимагає Mana для мережевої комісії. У вас є %1$s/%2$s Mana + Рівень Mana + Щоб почати відстежувати свої криптоактиви та транзакції, додайте токени + Керування токенами + Для доступу до всіх мереж необхідно відсканувати картку + Відскануйте картку + Насолоджуйтесь %1$s комісією за обслуговування на свопах через Changelly з %2$s по %3$s лютого. + Обмін із Changelly, %s комісії + Токени + Додати + Редагувати + Ринкова капіталізація + Спочатку був створений блокчейн криптовалюти + Основна мережа + Використання неосновних мереж для токенів дозволяє забезпечити крос-блокчейн інтероперабельність, що дає змогу використовувати активи в різноманітних децентралізованих додатках та смарт-контрактах на різних платформах. Однак це часто вимагає наявності кастодіана або смарт-контракту для безпечного зберігання оригінального активу, що вводить централізацію та ризик контрагента. + Не оригінальний або первинний блокчейн, на якому розміщено токен + Неосновні мережі + Оберіть мережі + Гаманець + Не вдалося знайти цей токен, ви можете додати його вручну + + %1$d із %2$d гаманця + %1$d із %2$d гаманців + %1$d із %2$d гаманців + %1$d із %2$d гаманців + + Видалити + наприклад Bitcoin + Ваше портфоліо оновлено + Обраний токен наразі недоступний для дій у криптогаманці. Але не хвилюйтеся, ви можете висловити свою зацікавленість, проголосувавши за його інтеграцію. + Проголосувати + Оберіть гаманець + Гаманець не підтримує більше однієї мережі + Щоб почати купувати, обмінювати або отримувати цей актив, додайте цей токен принаймні в 1 мережу + Цей актив недоступний + Додати в портфоліо + Додати токен + Доступні мережі + Моє портфоліо + Маркет + Щоб згенерувати адреси для обраних мереж, потрібно відсканувати свою картку Tangem. + Не вдалося завантажити дані... + Швидкі дії + Результат + Переглянути токени до 100к ринкової капіталізації + Показати токени + Жодного результату + Виберіть мережу + Оберіть гаманець + 1 міс. + 1 рік + 24 год. + 3 міс. + 6 міс. + 7 днів + Увесь + Досвідчені покупці + За рейтингом + Сортувати за + Лідери росту + Лідери падіння + В тренді + Про %s + + На основі %d оцінки + На основі %d оцінок + На основі %d оцінок + На основі %d оцінок + + Блокчейн сайт + Давлення покупця + Різниця між обсягом покупців та обсягом продавців + Циркуляційний запас + Загальна кількість монет, які доступні для торгівлі та перебувають в обігу на ринку + Досвідчені покупці + Мережеві покупці з додатковою вимогою мати не менше 100 вихідних транзакцій + Повністю розведена ринкова капіталізація + Загальна теоретична вартість криптовалюти, якщо всі монети, які могли б існувати, перебувають в обігу, включаючи ті, що не перебувають в обігу в даний час + Дата створення + Високий + Тримачі + Зміна кількості власників токенів протягом певного періоду часу + Інсайти + Посилання + Ліквідність + Зміна того, скільки ліквідності доступно для токена протягом зазначеного періоду часу + Індекс ліквідності + Низький + Ринкова капіталізація + Загальна ринкова вартість криптовалюти, що розраховується шляхом множення поточної ціни монети на загальну кількість монет в обігу + Рейтинг ринку + Позиція в крипторейтингу між усіма монетами на основі ринкової капіталізації + Максимальна пропозиція + Метрики + Офіційні посилання + Цінова ефективність + Репозиторій + Оцінка безпеки + Соцмережі + Загальна пропозиція + Максимальна кількість монет або токенів, яка може коли-небудь існувати для певної криптовалюти + Обсяг торгів (24г) + Загальна сума криптовалюти, якою торгували протягом останніх 24 годин, що вказує на рівень активності та ліквідності на ринку + Вам потрібно встановити єдиний код доступу для захисту всіх ваших карток + Захист + Пізніше ви зможете налаштувати індивідуальний код доступу до кожної картки + Персоналізація + Код доступу можна відновити за допомогою прив\'язаної картки. Не зберігайте всі картки в одному місці. + Відновлення + Оберіть будь-яке слово, фразу або число в якості коду доступу + Створити код доступу + Введіть код доступу ще раз, щоб уникнути помилки + Повторно введіть код доступу + Код доступу повинен містити не менше 4 символів + Введені коди доступу не збігаються + Необхідно повторити операцію. Карту буде скинуто до заводських налаштувань. + Помилка активації + Додати токени + Ви додали одну резервну картку. Після завершення процесу резервного копіювання ви не зможете додати більше резервних карток. Якщо у вас є ще одна картка, додайте її до резервної копії. Ви бажаєте продовжити? + Процес резервного копіювання частково завершено. Ви не можете вийти з нього зараз. + Парольна фраза – це розширена функція безпеки, яку використовують криптогаманці. Вона додає додаткове слово або фразу на ваш вибір до вже існуючої seed - фрази, щоб розблокувати абсолютно новий набір адрес. + Додати резервну картку + Відсканувати картку #%d + Створити резервну копію + Відсканувати основну картку + Перейти до мого гаманця + Завершення бекапу + Отримати криптовалюту + Сканувати основну картку + Пропустити + Як це працює? + Давайте згенеруємо всі ключі на вашій картці та створимо безпечний гаманець + Створити гаманець + Створити гаманець + Інші опції + Ваші ключі будуть надійно згенеровані всередині картки. Ніякої seed-фрази, а це означає, що ніхто не зможе її експортувати або вкрасти. + Генеруйте ключі приватно + Ваша картка активована та готова до використання + Успішно! + У цьому випадку вам доведеться почати наново. + Ви хочете вийти з процесу активації? + Підготовка + На картці, яку ви намагаєтеся додати, вже створено інший гаманець. Якщо у вас є кошти на цьому гаманці, будь ласка, виведіть їх, а потім скиньте цю картку до заводських налаштувань і додайте її як резервну. + Резервна копія + Дізнатися більше про seed-фразу + + Запишіть це %d слово у порядку, вказаному нижче, та збережіть його у надійному місці. + Запишіть ці %d слова у порядку, вказаному нижче, та збережіть їх у надійному місці. + Запишіть ці %d слів у порядку, вказаному нижче, та збережіть їх у надійному місці. + Запишіть ці %d слів у порядку, вказаному нижче, та збережіть їх у надійному місці. + + Ваша seed-фраза + + %d слово + %d слова + %d слів + %d слів + + Щоб імпортувати гаманець, введіть seed-фразу в поле нижче + Згенерувати seed-фразу + Імпорт гаманця + Seed-фраза — це набір слів, який дозволяє відновити ваш гаманець. На відміну від ключів, що генеруються карткою, seed-фраза не захищена і може бути скопійована та викрадена. Використовуйте цю опцію на свій власний ризик. + Використовувати seed-фразу + Невірна seed-фраза. Будь ласка, перевірте порядок слів. + Невірна seed-фраза. Будь ласка, перевірте правопис. + Застарілий + Щоб перевірити чи правильно ви записали seed-фразу, введіть 2-е, 7-е та 11-те слова + Отже, давайте перевіримо + Щоб почати процес резервного копіювання, додайте одну або дві резервні картки. + Ви можете додати ще одну картку або завершити процес резервного копіювання + Підготуйте резервну картку з номером %s + Відскануйте основну картку, щоб почати процес резервного копіювання. + Підготуйте основну картку з номером %s + Ваша картка налаштована та готова до використання. + Додано максимальну кількість карток. Завершіть процес резервного копіювання. + Активація картки + Резервна картка #%d + Немає резервних карток + Сповіщення + Додано одну резервну картку + Підготуйте свою картку + Додано дві резервні картки + Поповніть гаманець на будь-яку суму, щоб почати користуватися карткою + Щоб почати, просто поповніть гаманець більше, ніж на %1$s %2$s + Купити криптовалюту + Показати адресу гаманця + Активація гаманця + Процес поєднання карток частково завершено. Ви не можете вийти з нього зараз. + Якщо процес створення гаманця буде перервано будь-яким чином, вам доведеться почати все спочатку + Ви можете створити резервну копію ключів на одній або двох інших порожніх картках Tangem Wallet. + Код доступу можна відновити за допомогою однієї з резервних карток. + Всі резервні карти можна використовувати як повнофункціональні з ідентичними ключами. + Ви зможете встановити код доступу для захисту своїх гаманців. + Резервна копія картки + Відновлення коду доступу + Ідентичні картки + Код доступу + Групами + За балансом + Сортування токенів + Список + Виберіть з галереї + Налаштування + Ви не надали доступ до своєї камери + Доступ до камери заборонено + %1$s (%2$s) у мережі %3$s + Надсилайте лише %s на цю адресу. Надсилання будь-якої іншої валюти призведе до її незворотної втрати. + Покажіть QR-код або поділіться своєю адресою + Взяти участь + Не вдалося завантажити інформацію по реферальній програмі. Будь ласка, спробуйте пізніше. + Не вдалося завантажити інформацію по реферальній програмі. Код помилки: %s. Будь ласка, спробуйте пізніше. + Майбутні виплати + Ваші друзі купили + Менше + Більше + Немає майбутніх виплат + + за %d гаманець + за %d гаманця + за %d гаманців + за %d гаманців + + Отримайте ^^%1$s^^ на вашу адресу в мережі %2$s%3$s ^^через 30 днів^^ за кожен гаманець, який придбає ваш друг + Ви + Отримає + при купівлі гаманця на сайті tangem.com + %s знижку + Ваш друг + Персональний код скопійовано! + Ваш персональний код + Купити Tangem Wallet зі знижкою!\n%s + Приведи друга в Tangem + Ви прийняли + Натискаючи цю кнопку, ви приймаєте + в реферальній програмі + + %d гаманець + %d гаманця + %d гаманців + %d гаманців + + Скинути картку + Я розумію, що після виконання цієї дії у мене більше не буде доступу до поточного гаманця + Я розумію, що не можу використати цю картку для відновлення свого коду доступу на інших картках поточного гаманця + Скидання до заводських налаштувань призведе до повного видалення гаманця з обраної картки. Ви не зможете відновити поточний гаманець або використати картку для відновлення коду доступу. + Скидання до заводських налаштувань призведе до повного видалення гаманця з обраної картки. Ви не зможете відновити поточний гаманець. + У вас є банківська картка іншої країни та посвідка на проживання або реєстрація за межами Російської Федерації? + Російські банківські картки наразі не приймаються + Увійдіть у додаток та слідкуйте за своїм балансом без сканування картки + Доступ до додатку + Використовувати біометрію + Для взаємодії з гаманцем будуть запитуватися біометричні дані замість коду доступу + Код доступу + Схоже, що у вас відключена біометрична автентифікація, вона необхідна для збереження гаманців + Увімкніть біометричну автентифікацію + Бажаєте використовувати біометрію? + Зверніть увагу, що для здійснення транзакції з вашими коштами вам все одно знадобиться ваша картка + Сканувати + Відскануйте картку, щоб змінити її налаштування. Зміни торкнуться лише відсканованої картки і не вплинуть на інші картки, прив\'язані до вашого гаманця. + Підготуйте свою картку + Вже включено до введеної адреси + Сума комісії у %s разів перевищує рекомендовану. Переконайтеся, що користувацькі налаштування вірні. + Ви вказали комісію нижче рекомендованої, це може спричинити затримку вашої транзакції. Продовжити? + Причина: %1$s\nКод: %2$s + Транзакція не завершена + Сума + Ви можете встановити розмір комісії за транзакцію, налаштувавши значення в полі Satoshi per vByte. + Комісія, яка буде стягнута за вашу транзакцію. Ви можете встановити власне значення. + Максимальна комісія + Це вартість, яку ви готові платити за кожну одиницю газу. Чим вища ціна газу, тим швидше буде оброблено вашу транзакцію. (Пріоритетна плата входить у вартість) + Пріоритетна плата + Комісія, яку користувач може заплатити майнерам або валідаторам, щоб прискорити включення їхньої транзакції в блок. + Комісія, необхідна за використання кожної невитраченої транзакції (UTXO) у мережі Kaspa. Чим більше UTXO ви використовуєте в транзакції, тим вищою буде комісія. + KAS за UTXO + %1$s, %2$s + Адреса + Тег призначення + Введіть адресу + Адреса збігається з адресою гаманця + Недопустимий Tag. Він не буде доданий у транзакцію. + Недопустимий Memo. Він не буде доданий до транзакції. + Tag + Memo + Включаючи комісію + Низька + Нормальна + Пріоритетна + Перевірте підключення до мережі + Інформація щодо комісії в мережі недоступна + Із + Ліміт газу + Це максимальна кількість газу, яка буде витрачена на здійснення транзакції чи контракту. Ліміт газу запобігає несподіваним або необмеженим стягненням під час виконання транзакції. + Вартість газу + Це вартість, яку ви готові платити за кожну одиницю газу. Чим вища ціна газу, тим швидше буде оброблено вашу транзакцію. + Все + Максимальна сума + Комісія може сягати до + Недопустимий Memo + Покриття мережевої комісії + Недостатньо коштів для здійснення переказу, оскільки загальна сума комісії та переказу перевищує наявний баланс + Сума перевищує баланс + Рахунок буде видалено з блокчейну, якщо баланс стане нижчим за екзистенційний депозит. Будь ласка, залиште %s на своєму балансі. + Екзистенційний депозит + Сума комісії в %s разів перевищує рекомендовану. Переконайтеся, що користувацькі налаштування вірні. + Встановлена комісія завелика + Через особливості мережі %1$s комісія за переказ всього балансу вища. Щоб зменшити комісію, Ви можете залишити %2$s. + Підвищена комісія + Включена комісія перевищує суму переказу, що призводить до від’ємного значення + Недопустима сума + Мінімальна сума переказу - %1$s. Будь ласка, переконайтеся, що залишок після переказу не буде меншим ніж %2$s. + Цільовий рахунок не активований. Будь ласка, змініть суму переказу, щоб продовжити. + Сума переказу повинна бути не менше %s + Залишити %s + Зменшити на %s + Зменшити до %s + Зверніть увагу, що при певних налаштуваннях комісії можливі затримки по вашій транзакції + Можливі затримки транзакцій + Через обмеження %1$s одна транзакція може вмістити лише %2$s UTXO. Це означає, що ви можете надіслати лише %3$s або менше. Вам потрібно зменшити суму. + Ліміт транзакції + Опціонально + Будь ласка, сумістіть свій QR-код з квадратом, щоб відсканувати його. Переконайтеся, що ви скануєте адресу в мережі %s. + Останні + Одержувач + Недійсна адреса + Переконайтеся, що адреса гаманця одержувача знаходиться в мережі %s, щоб уникнути втрати ваших токенів + Надіслати до + Memo/ Тег призначення — це унікальний ідентифікатор для розрізнення транзакцій, надісланих тому самому одержувачу в тій самій мережі. Застереження: відсутність тегу може призвести до втрати коштів. + Мої гаманці + Спосіб виміру комісії за біткоїн-транзакцію. Він свідчить про кількість найменшої одиниці біткоїна (сатоші) за кожен віртуальний байт у транзакції. Чим вище число, тим швидше буде оброблено транзакцію майнерами. + Сатоші / вбайт + Надсилання... + Торкніться будь-якого поля, щоб змінити його + Надіслати %s + Ви надсилаєте **%1$s**, включно з комісію мережі %2$s + Ви надсилаєте **%1$s** і %2$s + Надсилання %s + Всього + %1$s та %2$s буде надіслано + ≈ %1$s (вкл. комісію: %2$s ) + %s буде надіслано + Транзакція успішно підписана і відправлена до блокчейну. Баланс гаманця буде оновлено через деякий час + %1$s — це монета у мережі Tron. Щоб розрахувати комісію та здійснити транзакцію, вам необхідно внести певну кількість Tron (TRX) на свій рахунок. + Недійсна адреса + %1$s (%2$s) + Трансакцію надіслано + Підготуйтеся до сканування картку, яку потрібно налаштувати. + Забути гаманець + Це призведе до видалення гаманця з застосунку. Сам гаманець можна додати знову. + Ім\'я + Активний + Щоб вивести активи зі стейкінгу, натисніть тут. + Сума для стейкінгу має бути не менше %s + Річний відсоток, який ви можете отримати, беручи участь у стейкінгу. + APR + Доступно + Середня ставка винагороди + ~ прибуток за %s + Рейтинг ринку + Метрики + Мінімальні вимоги + Немає винагород, щоб отримати + Отримати винагороду + Спосіб отримання винагороди за стейкінг. Його можна отримати автоматично або вручну. + Розклад винагород + Це графік, який визначає коли учасники стейкінгу отримують свої винагороди. + Нагороди для отримання: %s + Стейкінг %s + Період розблокування + Період, який ви повинні чекати після запиту на виведення коштів зі стейкінгу, перш ніж токени стануть доступними. + Період блокування + Відведений час для активації участі в стейкінгу. + Стейкінг %s + Нативний стейкінг + Стейкінг дозволяє заробляти %1s. Ваші винагороди за стейкінг надходять кожні ~%2s днів. + Отримуйте винагороду за стейкінг + Винагороди + Застейкати більше + Не застейканий + Перевірити незастейкані, щоб отримати свої активи + Валідатор + Тримайте свою криптовалюту в безпеці. Приватні ключі надійно зберігаються на картці. + Революційний апаратний гаманець + До трьох карток з одним гаманцем + Всі ключі у безпеці + Апаратний гаманець для ваших біткоїнів, ефіріуму та багатьох інших валют одночасно — і все це на одній картці + Тисячі криптовалют + Використовуйте його в дорозі, будь-де і будь-коли. Ніяких дротів чи батарейок. Просто прикладіть картку до телефону, коли вам потрібна криптовалюта. + Гаманець для кожного + Зустрічайте Tangem + Обмінюйте, купуйте NFT, отримуйте позики та робіть депозити у понад 100 різних децентралізованих сервісах + Web 3.0 сумісність + Обмінюйте більше токенів за вигіднішим курсом прямо у своєму гаманці. + З\'явився новий провайдер обмінів! + Сума включає: \n• комісію постачальника послуг\n• комісію мережі за відправлення %s з біржі назад на адресу користувача. + Сума включає комісію постачальника послуг. + Комісії + Всі децентралізовані біржі вимагають схвалення, щоб запобігти доступу смарт-контрактів до вашого гаманця без вашого дозволу. За задумом смарт-контракти не можуть отримати доступ до ваших токенів без вашого схвалення. \"Розблоковуючи\" свої токени, ви дозволяєте смарт-контракту 1inch витрачати ваші активи. Майнери мережі отримують плату за газ (сплачену вами), щоб зафіксувати цю дію в блокчейні. Ви можете обміняти свій токен після того, як дасте дозвіл. + Підтвердити + Помилка при розрахунку комісії. Будь ласка, надішліть відгук до служби підтримки. + Ви обмінюєте + Обмін цієї кількості обраних токенів призведе до значного впливу на ціну і зменшить вашу кінцеву суму. + Недостатньо коштів + Надати дозвіл + В процесі + Обміняти + Ви отримаєте + Оберіть токен + недоступно + Баланси приховано + Баланси показано + Скасувати + Обрана операція наразі недоступна. Спробуйте пізніше. + Наразі купівля монети %s недоступна. Слідкуйте за нашими оновленнями. + У вас немає коштів для продажу. Поповніть рахунок, щоб мати змогу продати з нього кошти. + У вас немає коштів для відправлення. Поповніть рахунок, щоб мати змогу надіслати з нього кошти. + Наразі обмін монети %s недоступний. Слідкуйте за нашими оновленнями. + Продаж коштів стане доступним після завершення транзакції(-ій) в мережі %s + Надсилання коштів стане доступним після завершення транзакції(-ій) в мережі %s + Наразі продаж %s недоступний. Слідкуйте за нашими оновленнями. + Стейкінг %s зараз недоступний. Будь ласка, слідкуйте за нашими оновленнями. + Згенерувати XPUB + Приховати + Ви збираєтеся приховати цей токен з головного екрану. Ви можете додати його назад будь-коли на сторінці керування токенами. + Приховати %s + Приховати токен + Стейкінг дозволяє заробляти %1$s і отримувати винагороду кожні %2$s днів + Заробляйте до %s винагород за стейкінг щороку + %1$s токен в мережі %%image%% %2$s + Токен у мережі %%image%% %1$s + Токен %1$s (%2$s) є основною валютою в мережі %3$s і не може бути прихований до тих пір, поки у вас в списку є інші токени цієї мережі + Неможливо приховати %s + Обмінюйте цей токен на інші з %1$s комісією за обслуговування з %2$s по %3$s лютого. + Обмін із Changelly, %s комісії + Обміняти + контракт: %s + У вас ще немає транзакцій + Не вдалося завантажити історію транзакцій.\nНатисніть кнопку перезавантаження, щоб оновити інформацію. + Кілька адрес + Історія транзакцій наразі не підтримується для цього блокчейну. Але не хвилюйтеся, ми працюємо над цим! А поки можете перевірити це в оглядачі. + Операція + від: %s + до: %s + Спробуйте знову + Ви відсканували одну й ту саму картку. Для створення twin-гаманця вам потрібно відсканувати картку з номером %d + Ви відсканували не ту twin-картку. Будь ласка, спробуйте відсканувати іншу + Це картка, яку ви тримаєте в руках. У парної картки номер %s.\n\nОбидві картки можна використовувати для зняття коштів з цього гаманця. + Один гаманець. Дві картки. + Відсканувати картку #%s + Створення гаманця + Відскануйте twin-картку # %s + Підготовка картки + Tangem Twin + Ця дія є незворотною. Ви не матимете доступу до старого гаманця. + Прикладіть twin-картку з номером %s та не прибирайте її до завершення операції + Використовуйте %s або відскануйте картку, щоб отримати доступ до свого гаманця + Будьте в курсі останніх функцій та новин + Дізнавайтеся першими про нові акції + Бажаєте використовувати Push-повідомлення? + Додати новий гаманець + Ви впевнені, що хочете видалити цей гаманець? + Сталася помилка, будь ласка, відскануйте свою картку, щоб увійти в систему + Цей гаманець вже збережено, ви можете додати інший + Гаманець з назвою %s вже існує + Назва гаманця + Перейменувати гаманець + Розблокувати все + Розблокувати все з %s + Блокчейн недоступний. Спробуйте пізніше + Відскануйте картку + Запит на підпис повідомлення.\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Дo: %2$s\nСума: %3$s + У буфері обміну міститься код WalletConnect. Використайте скопійоване значення або відскануйте QR-код + Запит на створення транзакції для %1$s\n%2$s\n\nСума: %3$s\nКомісія: %4$s\nВсього: %5$s\nБаланс: %6$s + Неможливо відправити транзакцію. Недостатньо коштів. + Не вдалося встановити сеанс WalletConnect. Будь ласка, спробуйте пізніше. + Не вдалося підписати повідомлення.\nБудь ласка, спробуйте ще раз + Не вдалося створити сеанс WalletConnect за відведений час. Будь ласка, спробуйте пізніше. + Запит на підключення сеансу WalletConnect містить непідтримувані блокчейни. Непідтримувані блокчейни:\n + Зв\'язок з цим Dapp сервісом не може бути встановлений через його технічну реалізацію. + Ми зіткнулися з невідомою помилкою. Повідомлення про помилку: %s. Якщо проблема не зникає — зверніться до нашої служби підтримки. + Невірна картка обрана в додатку Tangem + Не вдалося створити транзакцію з даних Dapp. Код: %s + Ми зіткнулися з невідомою помилкою. Код помилки: %d. Якщо проблема не зникає — зверніться до нашої служби підтримки. + Немає відкритих сеансів WalletConnect + Упс. Немає сеансів. + Не вдалося створити пару WalletConnect: %1$s + Вставити з буфера обміну + Повідомлення для %1$s:\n%2$s + Запит на відкриття сесії для\n%1$s\n\nМЕРЕЖА: %2$s\n\nURL: %3$s + Операція не може бути завершена.\n\nВи вже створили сеанс WalletConnect з цими параметрами. + Відсканувати новий код + Цю картку не можна використовувати з WalletConnect. + Ця мережа не підтримується. Будь ласка, виберіть іншу мережу. + Оберіть мережу + Сеанси WalletConnect + Підключення до dApps + WalletConnect + Підключення може зайняти кілька секунд + Ринкова ціна %s + за 24 години + Мережа %s + Адреса скопійована в буфер обміну + Немає підключення до інтернету + Налаштування гаманця + Tangem + Використовуйте %s або відскануйте картку, щоб розблокувати доступ до гаманця + Схоже, що активація картки була виконана неправильно. Це може бути пов\'язано з проблемою з модулем NFC вашого пристрою або неправильним прикладанням картки до пристрою. Зверніться за допомогою до нашої служби підтримки. + Помилка активації + За рішенням розробників мережі BNB стандарт BEP-2 перестане підтримуватись у червні 2024 року. Щоб не втратити свої активи, їх необхідно конвертувати у стандарт BEP-20. Використовуйте функцію обміну, щоб перевести їх у мережу BNB Smart Chain. + Відключення мережі BNB Beacon Chain + Можна краще + Вподобати + Зрозуміло! + Дуже круто! + Оновити + Ви перебуваєте в демонстраційному режимі + Демонстраційний режим активовано + Відсканована вами картка є карткою розробника. Не використовуйте її для створення гаманця. + Не для користувачів! + Мережа %1$s використовує концепцію екзистенціального депозиту. Якщо баланс вашого рахунку буде нижче %2$s, його буде деактивовано, а всі залишкові кошти знищено. + Для роботи з мережею вимагається депозит + Обмін буде доступний після завершення %s транзакції + У вас є активна транзакція + Затвердження обміну триває і незабаром буде завершено + Затвердження в процесі + Мінімальна сума обміну становить - %1$s. Будь ласка, переконайтеся, що залишок на рахунку після обміну буде не менше за %2$s. + У вашому списку немає доступних монет для обміну %s + Немає доступних токенів для обміну + Щоб здійснити транзакцію, вам потрібно внести трохи %1$s %2$s + Неможливо покрити комісію %s + Сума отримання не може бути меншою за %s + Сервіс тимчасово недоступний + Сума до обміну не повинна перевищувати %s + Сума для обміну має бути не менше %s + Будь ласка, змініть суму для обміну + Ця картка може бути виробничим зразком або підробкою + Перевірка автентичності не вдалася + Асоціювати + Цей токен повинен бути асоційований з вашим обліковим записом Hedera, перш ніж ви зможете його прийняти. Вартість асоціації ~ %1$s %2$s + Цей токен повинен бути асоційований з вашим обліковим записом Hedera, перш ніж ви зможете його прийняти + Асоціюйте свій токен + Недостатньо %s. Поповніть ваш обліковий запис Hedera для асоціації цього токена + На цій картці залишається лише %s підписів. Ви повинні вивести всі свої кошти. + Низька кількість підписів + Токени в різних мережах можуть мати різні адреси. Переконайтеся, що ваша адреса відповідає мережі, коли переказуєте кошти. + + Використовуйте вашу картку, щоб отримати адресу для %d мережі + Використовуйте вашу картку, щоб отримати адреси для %d мереж + Використовуйте вашу картку, щоб отримати адреси для %d мереж + Використовуйте вашу картку, щоб отримати адреси для %d мереж + + Деякі адреси відсутні + Мережа наразі недоступна. Будь ласка, спробуйте пізніше. + Мережа недоступна + Поповніть свій гаманець + Ваш гаманець не має резервної копії. Проведіть цю процедуру зараз, щоб захистити свої активи. + Резервна копія відсутня + Ця картка вже використовувалася для здійснення транзакцій. Якщо вона отримана з ненадійного джерела, подумайте про те, щоб зняти всі кошти. Якщо це ваша картка, ніяких додаткових дій не потрібно. + Картка вже підписувала транзакції + Ваш відгук мотивує нас робити гаманець Tangem Wallet ще кращим + Подобається Tangem? + Вам необхідно провести асоціацію токена, щоб мати можливість приймати його + Необхідна плата за оренду мережі + %1$s є активом у мережі %2$s. Щоб здійснити транзакцію %3$s, ви повинні внести певну суму %4$s (%5$s), щоб покрити комісію мережі. + Недостатньо %1$s для покриття комісії мережі + Мережа Солана зазнає високого навантаження. Якщо транзакція не пройшла протягом 2 хвилин, повторіть транзакцію. + Оповіщення мережі Солана + Мережа Solana стягує орендну плату у розмірі %1$s кожні 2 дні. Акаунти, які не можуть дозволити собі орендну плату, видаляються з мережі. Поповніть свій рахунок на суму понад %2$s, щоб не платити орендну плату. + Деякі мережі наразі недоступні. Будь ласка, спробуйте пізніше. + Деякі мережі недоступні + Це картка Testnet. Вона не може обробляти транзакції і повинна використовуватися лише для тестування та розробки. + Лише для цілей тестування + Відмовитися + Ви не завершили резервне копіювання. Бажаєте продовжити? + Так, поновити + Відмовитися + Якщо зараз відмовитися, то доведеться скинути картки до заводських налаштувань, щоб почати спочатку + Відновити резервне копіювання + Це незворотна дія + Увійдіть за допомогою %s + Сканувати картку + Використовуйте %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 2a44adee3c..b198f3eee7 100644 --- a/core/res/src/main/res/values-zh-rTW/strings.xml +++ b/core/res/src/main/res/values-zh-rTW/strings.xml @@ -4,10 +4,14 @@ 管理代幣 僅將 %1$s (%2$s) 從 %3$s 網絡發送到此地址。使用其他代幣和網絡可能會導致資金損失 請求支持 + 再試一次 此功能不在展示模式中提供 原因:%s 無法發送交易 此卡不支持%1$s網路上的代幣因為韌體限制 + 感謝您的反饋。我們會盡快回复 + 你的建議已送出 + 請嘗試完全按照動畫中顯示的方式點擊卡片或請求支持 有困難在掃描卡上嗎? 此卡不適用於此app 轉到設置以在 Tangem App 中啟用生物識別身份驗證 @@ -36,6 +40,7 @@ 安全模式 卡片設置 接受 + 允許 注意 餘額: %s 餘額 @@ -51,6 +56,7 @@ 創造 刪除 禁用 + 斷開連接 完成 允許 啟用 @@ -63,6 +69,7 @@ 主卡片 拒絕 重新命名 + 重試 保存設置 搜索 搜尋代幣 @@ -81,6 +88,7 @@ 交易 我了解 無法觸達 + 警告 已複製代幣地址 支持的網路 @@ -113,6 +121,7 @@ App Currency 發行人 簽署 + 如果您忘記密碼,您將無法使用您的資金。無法恢復代碼 更多 檢查您的網路連接或切換到其他網絡 服務條款 @@ -127,6 +136,9 @@ 反饋 Tangem反饋 無法發送交易 + 數量 %s + 要繼續,您需要允許 %1s 智能合約使用您的 %2s + 賦予權限 掃描卡片 要更改訪問密碼,請完全按照上圖所示連接手機和卡片 要更改密碼,請完全按照上圖所示連接手機和卡 @@ -171,7 +183,6 @@ 這此情況,您必須要重新開始 您想要離開啟用程序嗎? 開始 - 您要添加的卡上已經創建了另一個錢包。你想重置它並將卡用於新錢包嗎? 創建備份 閱讀更多關於助記詞的訊息 @@ -277,13 +288,9 @@ 兼容Web3.0 批准被視為所有去中心化交易所的行業標準,並保護您的錢包在未經您許可的情況下不被智能合約訪問。按照設計,智能合約無法訪問您的代幣,除非您從您的終端批准訪問。通過“解鎖”您的代幣,您將獲得 1inch 智能合約使用您的資產的權限。網絡的礦工將獲得Gas Fee(由您支付)作為補償,以在區塊鏈上記錄此操作。一旦獲得許可,您就可以交易您的代幣。 批准 - 賦予權限 在此代幣交換的數量將對價格產生重大影響,並降低您收到的數量 餘額不足 - 允許 賦予權限 - 數量 %s - 要繼續,您需要允許 %1$s 智能合約使用您的 %2$s 進行中 交易 選擇代幣 @@ -292,7 +299,7 @@ 您即將在主屏幕上隱藏此代幣。您可以隨時通過管理代幣頁面將其添加回來。 隱藏 %s 隱藏代幣 - %1$s 代幣是 %2$s 網絡上的主要貨幣,只要列表中還有該網絡上的其他代幣,它就無法被隱藏。 + %1$s (%2$s) 代幣是 %3$s 網絡上的主要貨幣,只要列表中還有該網絡上的其他代幣,它就無法被隱藏。 無法隱藏 %s 您還沒有任何交易 無法加載交易 diff --git a/core/res/src/main/res/values/strings.xml b/core/res/src/main/res/values/strings.xml index 22914442eb..b277ef22a8 100644 --- a/core/res/src/main/res/values/strings.xml +++ b/core/res/src/main/res/values/strings.xml @@ -1,744 +1,894 @@ - Add custom token - Manage tokens - Send only %1$s (%2$s) from %3$s network to this address. Using other tokens and networks may result in loss of funds. - Request support - This feature is disabled in Demo mode - Reason: %s - Can\'t send a transaction - The selected does not support the %1$s network - To activate the %1$s blockchain\'s cryptographic encryption, you\'ll need to reset the wallet to factory settings. Please withdraw your funds before doing so to ensure that you don\'t lose them, and then complete the reset process. Access to the current wallet will not be possible after the reset. - Tokens in %1$s network are not supported by this card due to firmware limitation. - Are you having difficulty scanning your card? - This card is not designed to work with this app - Default Fee - Enable Default Fee to set transaction fees automatically and skip the Fee page when sending funds. You can always go back to this page if necessary. - Go to settings to enable biometric authentication in the Tangem App - Enable biometric authentication - This will delete all the saved wallet access codes. Any further operation with the wallet will require submitting the access code. - Removing the saved card deletes all the saved wallets and their access codes from the app. - Save Access Code - Biometric authentication will be requested instead of the access code for interactions with your card. - Keep the wallet in the app - Enable to link all the wallets to Tangem app. Biometric authentication will be required for unlocking the app. Transaction signing requires tapping your Tangem card. - Dark - Light - System default - Theme - App settings - To hide or show your balances, simply flip your device screen down, or switch it off in Settings - Don\'t show again - Got it - Balances are hidden - Please scan the card - Please try again in 30 seconds or scan the card - Too many attempts - You have disabled biometric authentication on your phone and will not be able to save wallets in the app. To save wallets, please enable the biometric authentication function in your phone settings. - Start backup process - - %d card - %d cards - - Disable this option if you don\'t want this card to be used to reset access codes on other cards in this wallet. Please note that this will also prevent you from resetting the access code on this card. - Allows you to use this card to reset access code on other cards in this wallet - Access code recovery - Reset - Are you sure you want to do this? - Change Access Code - Access code will be changed on this card only - All cards in the selected wallet have been reset to factory settings. You can now create a new wallet. - Reset complete - Do you want to reset the next card in this wallet? - Card reset - We recommend completing the reset process for all cards in this wallet - You haven\'t reset all your cards - Reset to Factory Settings - Security Mode - Card settings - In addition to network fee, the Cardano network charges %1$s ADA when transacting with the %2$s token - Cardano transaction requirements - To make a %1$s transaction, you must deposit some ADA to cover the network fee and minimum ADA value (5 ADA recommended) - Insufficient ADA for token transfer - You must maintain some ADA because you have some tokens on the Cardano blockchain - Not enough ADA - Accept - Access denied - Apply - Approval - Attention - Balance: %s - Balance - biometric authentication - biometrics - Buy - Go to %1$s - You have not given access to your camera, please adjust your privacy settings - Cancel - Close - Continue - Copy - Copy address - Create - Delete - Disabled - Done - Enable - Enabled - Error - Explore - Explore transaction history - Explorer - Fee - Network fees are charges users pay to process and confirm transactions. The fee amount can be affected by network congestion, transaction size, and execution priority. %s - Custom - Fast - Market - Slow - Speed and fee - Get addresses - Go to provider - Go to token - Import - Later - Locked - Main network - Network fee - Amount sent will be reduced by %1$s (%2$s) to cover the selected fee level - Next - No - No address - OK - Primary Card - Passphrase - Paste - Read more - Receive - Reject - Reload - Rename - Save changes - Search - Search tokens - Seed phrase - Select action - Sell - Send - The server is not available, please try again later - Share - Sign - Sign and send - Start - Submit - Success - Support - Swap - terms and conditions - Transaction failed - Transactions - Transfer - I understand - There was an error. Please try again. - Unreachable - Yes - Contract address copied! - Available networks - Add token - Contract address - Contract address is invalid - Please select the network - Decimal must be a valid integer, up to %li - Custom derivation - E. g. m/00\'/0000\'/0\'/0/0 - Enter custom derivation - Decimals - Derivation Path - Default - BIP44 coin type - The derivation path you\'ve entered is not valid - E.g. USD Coin - Name - Not selected - Network - Token network - You can manually add a token that is not natively supported by Tangem - E.g. USDC - Symbol - Token symbol - This token/network has already been added to your list - Note that tokens can be created by anyone. Be aware of adding scam tokens, they can cost nothing. - Be aware of adding scam tokens, they can cost nothing - Note that tokens can be created by anyone - Chat - Access code - You will have to submit the correct access code before scanning the card - Long Tap - This mechanism protects against proximity attacks on a card. It will enforce a delay between reception and execution of a command. - Passcode - Before executing any command entailing a change of the card state, you will have to enter the passcode. - Referral program - Flip your device screen down to quickly hide and show balances - %s hashes - Card ID - Contact support - Link More Cards - App Currency - Flip-to-Hide Balances - Issuer - Signed - Details - Check your internet connection or switch to a different network - Terms of service - You have used a card from another wallet. Tap the card associated with this wallet - My tokens - You haven\'t added any tokens yet. Add tokens via Market to swap - Cannot be swapped for %s - Provided by - Status - Tangem offers token swaps via 3rd-party providers according to each provider\'s terms - Choose provider - An error occurred. Code: %s - Oops! Swapping the selected pair through the chosen provider is temporarily unavailable. Please try again later. (Code: %s) - Selected provider is unavailable at the moment. Please try again later. (Code: %s) - Swaps are unavailable at the moment. Please try again later. (Code: %s) - Estimated amount - Exchange by %s - Visit provider’s website to refund your money - Operation failed by provider - The transaction amount was refunded in %1$s to your wallet due to OKX or bridge rules. %2$s - The amount was refunded in %1$s (%2$s network) - Visit provider’s website for verification - KYC verification required by provider - Canceled - Confirmed - Confirming - Confirming... - Exchanged - Exchanging - Exchanging... - Failed - Deposit received - Awaiting deposit - Awaiting deposit... - Refunded - Sending to you - Sending to you... - Sent - Provider-sourced data. Estimated amount subject to change due to market conditions. - Exchange status - Verification required - Awaiting transaction hash - List of all tokens added to your wallet - Fetching best rates... - Floating rate - By using swap functionality, you agree with provider’s %s - By using swap functionality, you agree with provider’s %1$s and %2$s - More providers are coming soon.\nStay tuned! - Privacy Policy - Provider - Best rate - Available up to %s - Available from %s - Unavailable for this pair - Permission Required - Recommended - Terms of Use - No tokens found. Please try another request - ID: %s - Transaction ID copied - The following information is optional. You can erase it if you don\'t want to share it. - Tell us what functions you are missing, and we will try to help you. - Please tell us what card do you have - Hi support team, - Please tell us more about your issue. Every small detail can help. - My suggestions - Can\'t scan a card - Feedback - Tangem feedback - Can\'t send a transaction - Order card - Scan card - To change the access code tap the card as shown above and do not remove until the end of the operation - To change the passcode tap the card as shown above and do not remove until the end of the operation - To create the wallet tap the card as shown above and do not remove until the end of the operation - Tap the card #%s of the wallet - Tap to scan - Tap to sign - Tap the card - You have updated biometrics, scan your card to enter - Your balance should be higher than the fee value to make a transfer - Not enough balance - You don\'t have enough Mana for this transaction. Please wait until the Mana is refilled. Your Mana balance is %1$s/%2$s - Not enough Mana - You can transfer only %s due to the Mana limit imposed by the Koinos network - Mana limit - The Koinos network requires Mana for network fees. Your have %1$s/%2$s Mana - Mana level - To begin tracking your crypto assets and transactions, add tokens - Manage tokens - To access all the networks you need to scan the card - Scan your card - Enjoy %1$s service fees on swaps via Changelly from February %2$s-%3$s - Swap with Changelly, %s fees - Tokens - Book now - Save **$50** while booking via our partner Travala: **%1s - %2s** - Book your holidays with Tangem and pay in crypto - Add - Edit - Coin market cap - Blockchain the cryptocurrency was initially created - Native network - Using non-native networks for tokens enables cross-blockchain interoperability, allowing assets to be utilized in diverse decentralized applications and smart contracts across platforms. However, this often involves a custodian or smart contract to hold the original asset securely, introducing centralization and counterparty risk. - Not original or primary blockchain the token is hosted - Non-native networks - Choose networks - Wallet - Couldn’t find this token, you can add it manually - - %1$d of %2$d wallet - %1$d of %2$d wallets - - e.g. BTC I trust, hodl I must - The selected token is currently unavailable for actions within the crypto wallet. But worry not, you can express your interest by upvoting it. - Upvote - Choose wallet - The wallet doesn\'t support more than one network - You have to set up a single access code to protect all your cards - Protect - You can set up an individual access code on each card later - Personalize - The access code can be restored with a linked card. Don’t keep all cards at one place. - Restore - Choose any word, phrase, or number you want as your access code - Create Access Code - Enter your access code one more time to avoid a mistake - Re-enter your Access Code - Access code must be at least 4 characters long - Entered access code didn\'t match the initial access code - Please repeat the operation. The card will be reset to factory settings. - Activation error - Add tokens - You\'ve added one backup card. When backup process is finished you can\'t add more backup cards. If you have one more card, add it to backup. Do you like to continue the backup process? - The backup process is partly complete. You can\'t exit it now. - The passphrase is an advanced security feature that crypto wallets use. It adds an extra word or phrase of your own choosing to your already existing recovery phrase to unlock a brand-new set of addresses. - Add a backup card - Scan the card #%d - Backup now - Scan the primary card - Continue to my wallet - Finalize the backup - Receive crypto - Scan primary card - Skip for later - How does it work? - Let\'s generate all the keys on your card and create a secure wallet - Create wallet - Create a wallet - Other options - Your keys will be securely generated inside the card. There is no seed phrase, which means nobody can export or steal it. - Generate keys privately - Your card is activated and ready to be used - Success! - In this case, you will need to start from the beginning. - Do you want to exit the activation process? - Getting started - Another wallet has already been created on the card you\'re trying to add. If you have funds in this wallet, please withdraw it and then reset this card and add it as a backup. - Creating a backup - Read more about seed phrase - - - Write these %d words down in the order given below and store them in a safe and secret place. - - Your seed phrase - - - %d words - - To import your wallet, enter your seed phrase in the field below - Generate seed phrase - Import wallet - A seed phrase is a series of words that allows you to recover your wallet. Unlike the keys generated by the card, seed phrases are unprotected and can be copied and stolen. Use this option at your own risk. - Use seed phrase - Invalid seed phrase. Please check the word order. - Invalid seed phrase. Please check your spelling. - Legacy - To check whether you’ve written down your seed phrase correctly, please enter the 2nd, 7th and 11th words - So, let’s check - To start the backup process add up to two backup cards. - You can add one more card or finalize the backup process - Prepare the backup card with number %s - Scan the primary card to start the backup process. - Prepare the primary card with number %s - Your wallet card is configured and ready for use. - Max number of cards added. Finalize the backup process. - Activating card - Backup card #%d - No backup cards - One backup card added - Prepare your card - Two backup cards added - To get started, simply top up the wallet with any amount - To get started, simply top up the wallet with more than %1$s %2$s - Buy crypto - Show the wallet\'s address - Activate a wallet - The twinning process is partly complete. You can\'t exit it now. - If the process of creating the wallet gets interrupted in any way, you\'ll have to start over - You can backup your keys up to two other blank Tangem Wallet cards. - Access code can be restored with one of backup cards. - All the backup cards can be used as full-functional with the identical keys. - You will be able to set an access code to protect your wallets. - Backup wallet - Access code restore - Identical cards - Access code - Group - By balance - Organize tokens - Ungroup - Select from the gallery - Settings - You have not given access to your camera - Camera access denied - %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. - Upcoming payments - Your friends bought - Less - More - No upcoming payments - - for %d wallet - for %d wallets - - Will get ^^%1$s^^ for each wallet bought by your friend on your %2$s network address %3$s ^^30 days after^^ that - You - Will get a - when buying a wallet on tangem.com - %s discount - Your friend - Personal code copied! - Your personal code - Buy Tangem Wallet with discount!\n%s - Refer your friends to Tangem - You\'ve accepted - By tapping this button you accept - of the referral program - - %d wallet - %d wallets - - Reset the Card - I understand that after performing this action, I will no longer have access to the current wallet - I realize that I can\'t use this card to recover my access code on the other cards of the current wallet - Factory Reset will completely delete the wallet from the selected card. You will not be able to restore the current wallet or use the card to recover the access code. - 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 from another country and a residence permit or registration outside the Russian Federation? - Russian bank cards are not currently accepted - Log into the app and check your balance without scanning the card - Access the app - Allow to use biometrics - Biometrics will be requested instead of the access code for interactions with your wallet - Access code - It looks like you have biometric authentication disabled, it is necessary to save wallets - Enable biometric authorization - Would you like to use biometrics? - Note that making a transaction with your funds will still require your card - Scan Card - Scan the card to change its settings. The changes will impact only the card you\'ve scanned and will not affect other cards tied to your wallet. - Get your card ready! - Already included in the entered address - The commission amount is %s times the recommended amount. Make sure that the custom settings are correct. - You specified a commission below the recommended amount, which could cause a delay in your transaction. Continue? - Reason: %1$s\nCode: %2$s - The transaction is not completed - Amount - You can set your transaction fee by adjusting the value in the Satoshi per vByte field. - Max fee - This is the cost you are willing to pay for each unit of gas. The higher the gas price, the faster your transaction will be processed. (Priority fee included) - Priority fee - The fee that a user can pay to miners or validators to expedite the inclusion of their transaction in a block. - %1$s, %2$s - Address - Destination Tag - Enter address - Address is the same as wallet address - The fee that will be charged for your transaction. You can set your own value. - Invalid Tag. It won\'t be added to the transaction. - Invalid Memo. It won\'t be added to the transaction. - Tag - Memo - Include fee - Low - Normal - Priority - Check your network connection - Network fee info unreachable - From - Gas limit - This is the maximum amount of gas that will be spent to complete a transaction or contract. A gas limit prevents unexpected or unlimited charges when executing a transaction. - Gas price - This is the cost you are willing to pay for each unit of gas. The higher the gas price, the faster your transaction will be processed. - Max - Maximum amount - Fee up to - Invalid Memo - Network fee coverage - Insufficient funds for the transfer, as the total of the fee and transfer amount exceeds the existing balance - Total exceeds balance - The account will be wiped from the blockchain if a balance goes below the existential deposit. Please leave %s on your balance. - Existential deposit - The commission amount is %s times the recommended amount. Make sure that the custom settings are correct. - Custom fee is high - Due to the peculiarities of the %1$s network, the fee for transferring the entire balance is higher. To reduce the commission, you can leave %2$s. - The fee is higher - The included commission exceeds the transfer amount, leading to a negative value - Invalid amount - The minimum sending amount is %1$s. Please ensure that the remaining balance after sending will not be less than %2$s. - Target account is not created. Please change the amount to send. - The amount to send must be at least %s - Leave %s - Reduce by %s - Reduce to %s - Kindly be aware that your transaction may experience delays under specific fee settings - Transaction delays are possible - Due to %1$s limitations only %2$s UTXOs can fit in a single transaction. This means you can only send %3$s or less. You need to reduce the amount. - Transaction limitation - Optional - Please align your QR code with the square to scan it. Ensure you scan %s network address. - Recent - Recipient - Not a valid address - Ensure the receiving wallet address is on the %s network to avoid losing your tokens - Send to - A Memo/Destination Tag is a unique ID for differentiating transactions sent to the same recipient on the same network. Caution: Omitting a memo may lead to misplaced funds - My wallets - A way of measuring Bitcoin transaction fees. It indicates the number of the smallest Bitcoin unit (Satoshi) for each virtual byte in a transaction. The higher the number, the faster the transaction will be processed by miners. - Satoshi / vByte - Sending... - Tap any field to change it - Send %s - You are sending **%1$s** including a network fee of %2$s - You are sending **%1$s** and %2$s - Sending %s - Total - %1$s and %2$s will be sent - ≈ %1$s (inc. fee: %2$s) - %s will be sent - Transaction has been successfully signed and sent to the blockchain node. Wallet balance will be updated in a while - Invalid address - %1$s (%2$s) - Transaction sent - Forget wallet - This will remove the wallet from the application. The wallet itself can be added again. - Name - Store your crypto assets secure while keeping private keys contained in your card - Revolutionary Hardware Wallet - Up to 3 physical cards to one wallet - Ultra Secure Backup - A hardware wallet for your Bitcoin, Ethereum and many more currencies simultaneously – all in one card - 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 - Meet Tangem - Exchange, buy NFT\'s, make loans and deposits in more than 100 different decentralized services - Web 3.0 Compatible - Exchange more tokens at better rates directly in your wallet. - New Swap Provider Available! - The amount includes:\n• service provider\'s fee\n• network fee for sending %s from the exchange back to the user\'s address. - The amount includes the service provider\'s fee. - Fees - All decentralized exchanges require approvals to prevent smart contracts from accessing your wallet without your permission. By design, smart contracts can\'t access your tokens unless you approve. By \"unlocking\" your tokens, you authorize the 1-inch smart contract to spend them. The network\'s miners receive a gas fee (paid by you) to record this action on the blockchain. You can swap your token after giving approval. - Approve - You swap - Give Permission - Swapping this amount of selected tokens will cause a significant price impact and reduce your outcome. - Insufficient funds - Approve - Current transaction - The network will charge a token approval fee to verify that you are authorizing the use of your token for the swap. - Give Permission - Specify the approve limit for the selected token - Amount %s - To continue, grant %1$s smart contracts permission to use your %2$s - Unlimited - In progress - Swap - You receive - Choose token - not available - Balances hidden - Balances shown - Undo - This operation is currently unavailable. Please try again later. - Buying %s is not available at the moment. Please check our updates. - You do not have funds to sell. Top up your account to be able to sell funds from it. - You do not have funds to send. Top up your account to be able to send funds from it. - Swapping %s is not available at the moment. Please check our updates. - Selling funds will be available once the pending transaction(s) in network %s is complete - Sending funds will be available once the pending transaction(s) in network %s is complete - Selling %s is not available at the moment. Please check our updates. - Generate XPUB - Hide - You are about to hide this token from the main screen. You can add it back anytime through the manage tokens page. - Hide %s - Hide token - Staking allows you to earn %1$s and get rewards every %2$s days - Earn up to %s staking rewards yearly - %1$s token in %%image%% %2$s network - Token in %%image%% %1$s network - The %1$s (%2$s) token is the main currency on the %3$s network and cannot be hidden as long as you have other tokens on this network in the list - Unable to hide %s - Exchange this token for another at %1$s service fees from February %2$s-%3$s. - Swap with Changelly, %s fees - Swap now - contract: %s - You don\'t have any transactions yet - Failed to load transaction history.\nClick on reload button to update the information. - Multiple addresses - Transaction history is currently not supported for this blockchain. But don\'t worry, we\'re working on it! In the meantime you can check it in the explorer. - Operation - from: %s - to: %s - You\'ve scanned the same card. To create a twin wallet you need to scan the card with number %d - You\'ve scanned wrong twin card. Please try another one - This one that you are holding in your hands and the other one with number %s.\n\nBoth cards can be used to extract funds from this wallet. - One wallet. Two cards. - Scan the card #%s - Creating wallet - Scan the #%s twin card - Preparing card - Tangem Twin - This action is irreversible. You will not have access to the old wallet. - Tap the twin card with number %s and do not remove until the end of the operation - Use %s or scan a card to have an access to your wallet - Add new wallet - Are you sure you want to delete this wallet? - An error has occurred, please scan your card to log in - This wallet has already been saved, you can add another one - The wallet with name %s already exists - Wallet name - Rename Wallet - Unlock all - Unlock all with %s - Blockchain is unreachable. Try later - Scan the card - 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 - 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 - No opened WalletConnect sessions - Ooops. No Sessions. - Failed to pairing WalletConnect session: %1$s - Paste from clipboard - Message for %1$s:\n%2$s - Request to start a session for\n%1$s\n\nNETWORK: %2$s\n\nURL: %3$s - The operation couldn\'t be completed.\n\nYou have already established a WalletConnect session with this parameters. - Scan new code - This card can\'t be used to establish WalletConnect session - This network is not supported. Please select another network. - Select network - WalletConnect Sessions - Connect to dApps - WalletConnect - %s Market Price - last 24h - %s network - Address was copied to clipboard - No internet connection - Wallet settings - Tangem - Use %s or scan a card to unlock access to your wallet - It seems that the card activation was not completed correctly. This could be due to an issue with your device\'s NFC module or incorrect tapping of the card to your device. Please contact our Support team for assistance. - Activation error - According to BNB network developers, support for the BEP-2 standard will end in June 2024. To avoid losing assets with this standard, please convert them to the BEP-20 standard. Use our swap service or third-party services to transfer funds to the BNB Smart Chain network. - BNB Beacon Chain will shut down - Could be better - Like it - Ok, Got it! - Really cool! - Refresh - You are currently in the Demo mode - Demo mode active - The card you scanned is a developer card. Do not use it to create your wallet. - Not for users! - %1$s network requires an Existential Deposit. If your account drops below %2$s, it will be deactivated, and any remaining funds will be destroyed. - Network requires Existential Deposit - Swap will be available after the %s transaction is complete - You have active transaction - Swap approval is underway and will be completed shortly - Approval in progress - The minimum swapping amount is %1$s. Please ensure that the remaining balance after the swap will not be less than %2$s. - You do not have any %s exchangeable coins in your list - No available tokens to swap - To make a transaction you need to deposit some %1$s %2$s - Unable to cover %s fee - The amount to receive must be at least %s - Service temporarily unavailable - The amount of tokens to be swapped must not exceed %s - The amount to swap must be at least %s - Please change the amount to swap - This card might be a production sample or counterfeit - Authenticity check failed - Associate - This token must be associated with your Hedera account before you can receive it. Association fee ~%1$s %2$s - This token must be associated with your Hedera account before you can receive it - Associate your token - Not enough %s. Top up your Hedera account to associate this token - Only %s signatures are left on this card. You must withdraw all of your funds. - Low signature count - Tokens on different networks can have different addresses. Double-check that your address matches the network when you transfer funds. - - Use your card to get an address for %d network - Use your card to get an addresses for %d networks - - Some addresses are missing - The network is currently unreachable. Please try again later. - Network is unreachable - Top up your wallet - Your wallet hasn\'t been backed up. Carry out this procedure to protect your assets now. - Missing backup - This card has been previously used for transactions. If received from an untrusted source, consider withdrawing all funds. If it\'s your card, no action is required. - Card has already signed transactions - Your review keeps us motivated to make Tangem Wallet even better - Enjoying Tangem? - You must associate your token before receiving tokens - Network rent fee required - %1$s is an asset in the %2$s network. To make a %3$s transaction, you must deposit some %4$s (%5$s) to cover the network fee. - Insufficient %1$s to cover network fee - The Solana network is congested. If your transaction is not processed within 2 minutes, please repeat the transaction. - Solana Network Alert - 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. - Some networks currently are unreachable. Please try again later. - Some networks are unreachable - This is a Testnet card. It cannot process transactions and should only be used for testing and development purposes. - For testing purposes only - Discard - You have an interrupted backup. Do you want to resume? - Yes, resume - Discard - If you will discard the backup now, then you will have to reset the cards to factory settings to start over again - Resume backup - This is an irreversible action - Log in with %s - Scan card - Use %s or scan a card to access the app - Welcome back! + Choose network + Add custom token + Manage tokens + Send only %1$s (%2$s) from %3$s network to this address. Using other tokens and networks may result in loss of funds. + How to scan + Request support + Try again + This feature is disabled in Demo mode + Reason: %s + Can\'t send a transaction + The selected does not support the %1$s network + To activate the %1$s blockchain\'s cryptographic encryption, you\'ll need to reset the wallet to factory settings. Please withdraw your funds before doing so to ensure that you don\'t lose them, and then complete the reset process. Access to the current wallet will not be possible after the reset. + Tokens in %1$s network are not supported by this card due to firmware limitation. + Are you having difficulty scanning your card? + This card is not designed to work with this app + Default Fee + Enable Default Fee to set transaction fees automatically and skip the Fee page when sending funds. You can always go back to this page if necessary. + Go to settings to enable biometric authentication in the Tangem App + Enable biometric authentication + This will delete all the saved wallet access codes. Any further operation with the wallet will require submitting the access code. + Removing the saved card deletes all the saved wallets and their access codes from the app. + Save Access Code + Biometric authentication will be requested instead of the access code for interactions with your card. + Keep the wallet in the app + Enable to link all the wallets to Tangem app. Biometric authentication will be required for unlocking the app. Transaction signing requires tapping your Tangem card. + Dark + Light + System default + Theme + App settings + To hide or show your balances, simply flip your device screen down, or switch it off in Settings + Don\'t show again + Got it + Balances are hidden + Please scan the card + Please try again in 30 seconds or scan the card + Too many attempts + You have disabled biometric authentication on your phone and will not be able to save wallets in the app. To save wallets, please enable the biometric authentication function in your phone settings. + Start backup process + With your bank card or bank account + + %d card + %d cards + + Disable this option if you don\'t want this card to be used to reset access codes on other cards in this wallet. Please note that this will also prevent you from resetting the access code on this card. + Allows you to use this card to reset access code on other cards in this wallet + Access code recovery + Reset + Are you sure you want to do this? + Change Access Code + Access code will be changed on this card only + All cards in the selected wallet have been reset to factory settings. You can now create a new wallet. + Reset complete + Do you want to reset the next card in this wallet? + Card reset + We recommend completing the reset process for all cards in this wallet + You haven\'t reset all your cards + Reset to Factory Settings + Security Mode + Card settings + In addition to network fee, the Cardano network charges %1$s ADA when transacting with the %2$s token + Cardano transaction requirements + To make a %1$s transaction, you must deposit some ADA to cover the network fee and minimum ADA value (5 ADA recommended) + Insufficient ADA for token transfer + You must maintain some ADA because you have some tokens on the Cardano blockchain + Not enough ADA + Accept + Access denied + All + Allow + Apply + Approval + Approve + Attention + Balance: %s + Balance + biometric authentication + biometrics + Buy + Go to %1$s + You have not given access to your camera, please adjust your privacy settings + Cancel + Claim rewards + Close + Continue + Copy + Copy address + Create + Custom + + %d day + %d days + + Delete + Disabled + Done + Enable + Enabled + Error + Explore + Explore transaction history + Explorer + Fee + Network fees are charges users pay to process and confirm transactions. The fee amount can be affected by network congestion, transaction size, and execution priority. %s + Fast + Market + Slow + Speed and fee + Get addresses + Go to provider + Go to token + Import + Later + Locked + Main network + Network fee + Amount sent will be reduced by %1$s (%2$s) to cover the selected fee level + Next + No + No address + Now + OK + Primary Card + Passphrase + Paste + %1$s-%2$s + Read more + Receive + Reject + Reload + Rename + Save + Save changes + Search + Search tokens + Seed phrase + Select action + Sell + Send + The server is not available, please try again later + Share + Sign + Sign and send + Stake + Staking + Start + Submit + Success + Support + Swap + terms and conditions + Today + Transaction failed + Transactions + Transfer + I understand + There was an error. Please try again. + Unreachable + Unstake + Yes + Contract address copied! + Available networks + Add token + Contract address + Contract address is invalid + Please select the network + Decimal must be a valid integer, up to %li + Custom derivation + E. g. m/00\'/0000\'/0\'/0/0 + Enter custom derivation + Decimals + Derivation Path + Default + BIP44 coin type + The derivation path you\'ve entered is not valid + E.g. USD Coin + Name + Not selected + Network + Token network + You can manually add a token that is not natively supported by Tangem + E.g. USDC + Symbol + Token symbol + This token/network has already been added to your list + Note that tokens can be created by anyone. Be aware of adding scam tokens, they can cost nothing. + Be aware of adding scam tokens, they can cost nothing + Note that tokens can be created by anyone + Buy Tangem Wallet + Chat + Access code + You will have to submit the correct access code before scanning the card + Long Tap + This mechanism protects against proximity attacks on a card. It will enforce a delay between reception and execution of a command. + Passcode + Before executing any command entailing a change of the card state, you will have to enter the passcode. + Referral program + Flip your device screen down to quickly hide and show balances + %s hashes + Card ID + Contact support + Link More Cards + App Currency + Flip-to-Hide Balances + Issuer + Signed + Send feedback + Details + Check your internet connection or switch to a different network + Terms of service + You have used a card from another wallet. Tap the card associated with this wallet + My tokens + You haven\'t added any tokens yet. Add tokens via Market to swap + Cannot be swapped for %s + Provided by + Status + Tangem offers token swaps via 3rd-party providers according to each provider\'s terms + Choose provider + An error occurred. Code: %s + Oops! Swapping the selected pair through the chosen provider is temporarily unavailable. Please try again later. (Code: %s) + Selected provider is unavailable at the moment. Please try again later. (Code: %s) + Swaps are unavailable at the moment. Please try again later. (Code: %s) + Estimated amount + Exchange by %s + Visit provider’s website to refund your money + Operation failed by provider + The transaction amount was refunded in %1$s to your wallet due to OKX or bridge rules. %2$s + The amount was refunded in %1$s (%2$s network) + Visit provider’s website for verification + KYC verification required by provider + Canceled + Confirmed + Confirming + Confirming... + Exchanged + Exchanging + Exchanging... + Failed + Deposit received + Awaiting deposit + Awaiting deposit... + Refunded + Sending to you + Sending to you... + Sent + Provider-sourced data. Estimated amount subject to change due to market conditions. + Exchange status + Verification required + Awaiting transaction hash + List of all tokens added to your wallet + Fetching best rates... + Floating rate + By using swap functionality, you agree with provider’s %s + By using swap functionality, you agree with provider’s %1$s and %2$s + More providers are coming soon.\nStay tuned! + Privacy Policy + Provider + Best rate + Available up to %s + Available from %s + Unavailable for this pair + Permission Required + Recommended + Terms of Use + No tokens found. Please try another request + ID: %s + Transaction ID copied + With another currency in your wallet + The following information is optional. You can erase it if you don\'t want to share it. + Tell us what functions you are missing, and we will try to help you. + Please tell us what card do you have + Hi support team, + Please tell us more about your issue. Every small detail can help. + My suggestions + Can\'t scan a card + Feedback + Tangem feedback + Can\'t send a transaction + Current transaction + The network will charge a token approval fee to verify that you are authorizing the use of your token for the swap. + Specify the approve limit for the selected token + Amount %s + The Approve function is needed to grant permission to another address to use a specific amount of your tokens. By design, smart contracts can\'t access your tokens unless you approve. By \"unlocking\" your tokens, you authorize the StakeKit smart contract to use them. The network\'s miners receive a gas fee (paid by you) to record this action on the blockchain. You can stake your token after giving approval. + To continue you need to allow StakeKit smart contract to use your %s + To continue, grant %1s smart contracts permission to use your %2s + Give Permission + Unlimited + Order card + Scan card + To change the access code tap the card as shown above and do not remove until the end of the operation + To change the passcode tap the card as shown above and do not remove until the end of the operation + To create the wallet tap the card as shown above and do not remove until the end of the operation + Tap the card #%s of the wallet + Tap to scan + Tap to sign + Tap the card + You have updated biometrics, scan your card to enter + Your balance should be higher than the fee value to make a transfer + Not enough balance + You don\'t have enough Mana for this transaction. Please wait until the Mana is refilled. Your Mana balance is %1$s/%2$s + Not enough Mana + You can transfer only %s due to the Mana limit imposed by the Koinos network + Mana limit + The Koinos network requires Mana for network fees. Your have %1$s/%2$s Mana + Mana level + To begin tracking your crypto assets and transactions, add tokens + Manage tokens + To access all the networks you need to scan the card + Scan your card + Enjoy %1$s service fees on swaps via Changelly from February %2$s-%3$s + Swap with Changelly, %s fees + Tokens + Add + Edit + Coin market cap + Blockchain the cryptocurrency was initially created + Native network + Using non-native networks for tokens enables cross-blockchain interoperability, allowing assets to be utilized in diverse decentralized applications and smart contracts across platforms. However, this often involves a custodian or smart contract to hold the original asset securely, introducing centralization and counterparty risk. + Not original or primary blockchain the token is hosted + Non-native networks + Choose networks + Wallet + Couldn’t find this token, you can add it manually + + %1$d of %2$d wallet + %1$d of %2$d wallets + + Remove + e.g. BTC I trust, hodl I must + Your portfolio has been updated + The selected token is currently unavailable for actions within the crypto wallet. But worry not, you can express your interest by upvoting it. + Upvote + Choose wallet + The wallet doesn\'t support more than one network + To start buying, exchanging or receiving this asset, add this token to at least 1 network + This asset is not available + Add to portfolio + Add token + Available networks + My portfolio + Market + To generate addresses for selected networks, you must scan your Tangem Wallet card. + Unable to load the data… + Quick actions + Result + See tokens under 100k market cap + Show tokens + No result + Select network + Select wallet + 1m + 1y + 24h + 3m + 6m + 7d + All + Experienced buyers + Rating + Sort By + Top Gainers + Top losers + Trending + About %s + + Based on %d rating + Based on %d ratings + + Blockchain site + Buy pressure + The difference between buyers volume and sellers volume + Circulating supply + The total number of coins that are available for trading and are circulating in the market + Experienced buyers + Net buyers with the additional requirement of having at least 100 outgoing transactions + Fully diluted valuation + The total theoretical value of a cryptocurrency if all coins that could exist are in circulation, including those not currently circulating + Genesis date + High + Holders + The change in the number of token holders within a specific timeframe + Insights + Links + Liquidity + The change in how much liquidity is available for the token during the specified timeframe + Liquidity index + Low + Market capitalization + The total market value of a cryptocurrency, calculated by multiplying the current price of the coin by the total number of coins in circulation + Market rating + Position in crypto rating between all coins based on market capitalization + Max supply + Metrics + Official links + Price performance + Repository + Security score + Social + Total supply + The maximum number of coins or tokens that can ever exist for a particular cryptocurrency + Trading volume (24h) + The total amount of a cryptocurrency that has been traded within the last 24 hours, indicating the level of activity and liquidity in the market + You have to set up a single access code to protect all your cards + Protect + You can set up an individual access code on each card later + Personalize + The access code can be restored with a linked card. Don’t keep all cards at one place. + Restore + Choose any word, phrase, or number you want as your access code + Create Access Code + Enter your access code one more time to avoid a mistake + Re-enter your Access Code + Access code must be at least 4 characters long + Entered access code didn\'t match the initial access code + Please repeat the operation. The card will be reset to factory settings. + Activation error + Add tokens + You\'ve added one backup card. When backup process is finished you can\'t add more backup cards. If you have one more card, add it to backup. Do you like to continue the backup process? + The backup process is partly complete. You can\'t exit it now. + The passphrase is an advanced security feature that crypto wallets use. It adds an extra word or phrase of your own choosing to your already existing recovery phrase to unlock a brand-new set of addresses. + Add a backup card + Scan the card #%d + Backup now + Scan the primary card + Continue to my wallet + Finalize the backup + Receive crypto + Scan primary card + Skip for later + How does it work? + Let\'s generate all the keys on your card and create a secure wallet + Create wallet + Create a wallet + Other options + Your keys will be securely generated inside the card. There is no seed phrase, which means nobody can export or steal it. + Generate keys privately + Your card is activated and ready to be used + Success! + In this case, you will need to start from the beginning. + Do you want to exit the activation process? + Getting started + Another wallet has already been created on the card you\'re trying to add. If you have funds in this wallet, please withdraw it and then reset this card and add it as a backup. + Creating a backup + Read more about seed phrase + + + Write these %d words down in the order given below and store them in a safe and secret place. + + Your seed phrase + + + %d words + + To import your wallet, enter your seed phrase in the field below + Generate seed phrase + Import wallet + A seed phrase is a series of words that allows you to recover your wallet. Unlike the keys generated by the card, seed phrases are unprotected and can be copied and stolen. Use this option at your own risk. + Use seed phrase + Invalid seed phrase. Please check the word order. + Invalid seed phrase. Please check your spelling. + Legacy + To check whether you’ve written down your seed phrase correctly, please enter the 2nd, 7th and 11th words + So, let’s check + To start the backup process add up to two backup cards. + You can add one more card or finalize the backup process + Prepare the backup card with number %s + Scan the primary card to start the backup process. + Prepare the primary card with number %s + Your wallet card is configured and ready for use. + Max number of cards added. Finalize the backup process. + Activating card + Backup card #%d + No backup cards + Notifications + One backup card added + Prepare your card + Two backup cards added + To get started, simply top up the wallet with any amount + To get started, simply top up the wallet with more than %1$s %2$s + Buy crypto + Show the wallet\'s address + Activate a wallet + The twinning process is partly complete. You can\'t exit it now. + If the process of creating the wallet gets interrupted in any way, you\'ll have to start over + You can backup your keys up to two other blank Tangem Wallet cards. + Access code can be restored with one of backup cards. + All the backup cards can be used as full-functional with the identical keys. + You will be able to set an access code to protect your wallets. + Backup wallet + Access code restore + Identical cards + Access code + Group + By balance + Organize tokens + Ungroup + Select from the gallery + Settings + You have not given access to your camera + Camera access denied + %1$s (%2$s) on %3$s network + Send only %s to this address. Sending any other currency will result in its irreversible loss. + Show a QR-code or share your address + 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. + Upcoming payments + Your friends bought + Less + More + No upcoming payments + + for %d wallet + for %d wallets + + Will get ^^%1$s^^ for each wallet bought by your friend on your %2$s network address %3$s ^^30 days after^^ that + You + Will get a + when buying a wallet on tangem.com + %s discount + Your friend + Personal code copied! + Your personal code + Buy Tangem Wallet with discount!\n%s + Refer your friends to Tangem + You\'ve accepted + By tapping this button you accept + of the referral program + + %d wallet + %d wallets + + Reset the Card + I understand that after performing this action, I will no longer have access to the current wallet + I realize that I can\'t use this card to recover my access code on the other cards of the current wallet + Factory Reset will completely delete the wallet from the selected card. You will not be able to restore the current wallet or use the card to recover the access code. + 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 from another country and a residence permit or registration outside the Russian Federation? + Russian bank cards are not currently accepted + Log into the app and check your balance without scanning the card + Access the app + Allow to use biometrics + Biometrics will be requested instead of the access code for interactions with your wallet + Access code + It looks like you have biometric authentication disabled, it is necessary to save wallets + Enable biometric authorization + Would you like to use biometrics? + Note that making a transaction with your funds will still require your card + Scan Card + Scan the card to change its settings. The changes will impact only the card you\'ve scanned and will not affect other cards tied to your wallet. + Get your card ready! + Already included in the entered address + The commission amount is %s times the recommended amount. Make sure that the custom settings are correct. + You specified a commission below the recommended amount, which could cause a delay in your transaction. Continue? + Reason: %1$s\nCode: %2$s + The transaction is not completed + Amount + You can set your transaction fee by adjusting the value in the Satoshi per vByte field. + The fee that will be charged for your transaction. You can set your own value. + Max fee + This is the cost you are willing to pay for each unit of gas. The higher the gas price, the faster your transaction will be processed. (Priority fee included) + Priority fee + The fee that a user can pay to miners or validators to expedite the inclusion of their transaction in a block. + The fee required for using each unspent transaction output (UTXO) in the Kaspa network. The more UTXOs you use in a transaction, the higher the fee will be. + KAS per UTXO + %1$s, %2$s + Address + Destination Tag + Enter address + Address is the same as wallet address + Invalid Tag. It won\'t be added to the transaction. + Invalid Memo. It won\'t be added to the transaction. + Tag + Memo + Include fee + Low + Normal + Priority + Check your network connection + Network fee info unreachable + From + Gas limit + This is the maximum amount of gas that will be spent to complete a transaction or contract. A gas limit prevents unexpected or unlimited charges when executing a transaction. + Gas price + This is the cost you are willing to pay for each unit of gas. The higher the gas price, the faster your transaction will be processed. + Max + Maximum amount + Fee up to + Invalid Memo + Network fee coverage + Insufficient funds for the transfer, as the total of the fee and transfer amount exceeds the existing balance + Total exceeds balance + The account will be wiped from the blockchain if a balance goes below the existential deposit. Please leave %s on your balance. + Existential deposit + The commission amount is %s times the recommended amount. Make sure that the custom settings are correct. + Custom fee is high + Due to the peculiarities of the %1$s network, the fee for transferring the entire balance is higher. To reduce the commission, you can leave %2$s. + The fee is higher + The included commission exceeds the transfer amount, leading to a negative value + Invalid amount + The minimum sending amount is %1$s. Please ensure that the remaining balance after sending will not be less than %2$s. + Target account is not created. Please change the amount to send. + The amount to send must be at least %s + Leave %s + Reduce by %s + Reduce to %s + Kindly be aware that your transaction may experience delays under specific fee settings + Transaction delays are possible + Due to %1$s limitations only %2$s UTXOs can fit in a single transaction. This means you can only send %3$s or less. You need to reduce the amount. + Transaction limitation + Optional + Please align your QR code with the square to scan it. Ensure you scan %s network address. + Recent + Recipient + Not a valid address + Ensure the receiving wallet address is on the %s network to avoid losing your tokens + Send to + A Memo/Destination Tag is a unique ID for differentiating transactions sent to the same recipient on the same network. Caution: Omitting a memo may lead to misplaced funds + My wallets + A way of measuring Bitcoin transaction fees. It indicates the number of the smallest Bitcoin unit (Satoshi) for each virtual byte in a transaction. The higher the number, the faster the transaction will be processed by miners. + Satoshi / vByte + Sending... + Tap any field to change it + Send %s + You are sending **%1$s** including a network fee of %2$s + You are sending **%1$s** and %2$s + Sending %s + Total + %1$s and %2$s will be sent + ≈ %1$s (inc. fee: %2$s) + %s will be sent + Transaction has been successfully signed and sent to the blockchain node. Wallet balance will be updated in a while + %1$s is an asset in the Tron network. To calculate the fee and make a transaction you need to deposit some Tron (TRX) in your account. + Invalid address + %1$s (%2$s) + Transaction sent + Prepare to scan card you want to setup. + Forget wallet + This will remove the wallet from the application. The wallet itself can be added again. + Name + Active + To unstake your assets, click here. + The amount to stake must be at least %s + Claim unstaked + Annual percentage rate + The annual percentage return you can earn from participating in staking. + APR + Available + Average Reward Rate + What is Staking? + %s est. profit + Market rating + Metrics + Minimum Requirement + No rewards to claim + Reward claiming + A way to receive staking rewards. It can be claimed automatically or manually. + Reward schedule + This is a schedule that determines when participants in staking receive their rewards. + Rewards to claim: %s + Staking %s + Unbonding Period + The period you must wait after requesting to withdraw funds from staking before the tokens become available. + Warmup period + The allocated time for activating participation in staking. + Stake %s + Migrate + Native staking + Staking allow you to earn %1s. Your staking rewards arrive every ~%2s days. + Earn staking rewards + Rewards stop accruing immediately after you unstake. The unstaking process takes %s. + Rebond + Restake + Restake rewards + Revoke + Revote + Rewards + Stake locked + Stake more + Unlock locked + Unstaked + Check unstaked to claim your assets + Unstaking + Validator + Vote + Vote locked + Withdraw + Store your crypto assets secure while keeping private keys contained in your card + Revolutionary Hardware Wallet + Up to 3 physical cards to one wallet + Ultra Secure Backup + A hardware wallet for your Bitcoin, Ethereum and many more currencies simultaneously – all in one card + 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 + Meet Tangem + Exchange, buy NFT\'s, make loans and deposits in more than 100 different decentralized services + Web 3.0 Compatible + Exchange more tokens at better rates directly in your wallet. + New Swap Provider Available! + The amount includes:\n• service provider\'s fee\n• network fee for sending %s from the exchange back to the user\'s address. + The amount includes the service provider\'s fee. + Fees + All decentralized exchanges require approvals to prevent smart contracts from accessing your wallet without your permission. By design, smart contracts can\'t access your tokens unless you approve. By \"unlocking\" your tokens, you authorize the 1-inch smart contract to spend them. The network\'s miners receive a gas fee (paid by you) to record this action on the blockchain. You can swap your token after giving approval. + Approve + Fee estimation error. Please send feedback to support. + You swap + Swapping this amount of selected tokens will cause a significant price impact and reduce your outcome. + Insufficient funds + Give Permission + In progress + Swap + You receive + Choose token + not available + Balances hidden + Balances shown + Undo + This operation is currently unavailable. Please try again later. + Buying %s is not available at the moment. Please check our updates. + You do not have funds to sell. Top up your account to be able to sell funds from it. + You do not have funds to send. Top up your account to be able to send funds from it. + Swapping %s is not available at the moment. Please check our updates. + Selling funds will be available once the pending transaction(s) in network %s is complete + Sending funds will be available once the pending transaction(s) in network %s is complete + Selling %s is not available at the moment. Please check our updates. + Staking %s is not available at the moment. Please check our updates. + Generate XPUB + Hide + You are about to hide this token from the main screen. You can add it back anytime through the manage tokens page. + Hide %s + Hide token + Staking allows you to earn %1$s and get rewards every %2$s days + Earn up to %s staking rewards yearly + %1$s token in %%image%% %2$s network + Token in %%image%% %1$s network + The %1$s (%2$s) token is the main currency on the %3$s network and cannot be hidden as long as you have other tokens on this network in the list + Unable to hide %s + Exchange this token for another at %1$s service fees from February %2$s-%3$s. + Swap with Changelly, %s fees + Swap now + contract: %s + You don\'t have any transactions yet + Failed to load transaction history.\nClick on reload button to update the information. + Multiple addresses + Transaction history is currently not supported for this blockchain. But don\'t worry, we\'re working on it! In the meantime you can check it in the explorer. + Operation + from: %s + to: %s + Try again + You\'ve scanned the same card. To create a twin wallet you need to scan the card with number %d + You\'ve scanned wrong twin card. Please try another one + This one that you are holding in your hands and the other one with number %s.\n\nBoth cards can be used to extract funds from this wallet. + One wallet. Two cards. + Scan the card #%s + Creating wallet + Scan the #%s twin card + Preparing card + Tangem Twin + This action is irreversible. You will not have access to the old wallet. + Tap the twin card with number %s and do not remove until the end of the operation + Use %s or scan a card to have an access to your wallet + Stay up to date with the latest features and news + Be the first to know about new promotions + Would you like to use\nPush-notifications? + Add new wallet + Are you sure you want to delete this wallet? + An error has occurred, please scan your card to log in + This wallet has already been saved, you can add another one + The wallet with name %s already exists + Wallet name + Rename Wallet + Unlock all + Unlock all with %s + Blockchain is unreachable. Try later + Scan the card + 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 + 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 + No opened WalletConnect sessions + Ooops. No Sessions. + Failed to pairing WalletConnect session: %1$s + Paste from clipboard + Message for %1$s:\n%2$s + Request to start a session for\n%1$s\n\nNETWORK: %2$s\n\nURL: %3$s + The operation couldn\'t be completed.\n\nYou have already established a WalletConnect session with this parameters. + Scan new code + This card can\'t be used to establish WalletConnect session + This network is not supported. Please select another network. + Select network + WalletConnect Sessions + Connect to dApps + WalletConnect + Connecting may take a few seconds + %s Market Price + last 24h + %s network + Address was copied to clipboard + No internet connection + Wallet settings + Tangem + Use %s or scan a card to unlock access to your wallet + It seems that the card activation was not completed correctly. This could be due to an issue with your device\'s NFC module or incorrect tapping of the card to your device. Please contact our Support team for assistance. + Activation error + According to BNB network developers, support for the BEP-2 standard will end in June 2024. To avoid losing assets with this standard, please convert them to the BEP-20 standard. Use our swap service or third-party services to transfer funds to the BNB Smart Chain network. + BNB Beacon Chain will shut down + Could be better + Like it + Ok, Got it! + Really cool! + Refresh + You are currently in the Demo mode + Demo mode active + The card you scanned is a developer card. Do not use it to create your wallet. + Not for users! + %1$s network requires an Existential Deposit. If your account drops below %2$s, it will be deactivated, and any remaining funds will be destroyed. + Network requires Existential Deposit + Swap will be available after the %s transaction is complete + You have active transaction + Swap approval is underway and will be completed shortly + Approval in progress + The minimum swapping amount is %1$s. Please ensure that the remaining balance after the swap will not be less than %2$s. + You do not have any %s exchangeable coins in your list + No available tokens to swap + To make a transaction you need to deposit some %1$s %2$s + Unable to cover %s fee + The amount to receive must be at least %s + Service temporarily unavailable + The amount of tokens to be swapped must not exceed %s + The amount to swap must be at least %s + Please change the amount to swap + This card might be a production sample or counterfeit + Authenticity check failed + Associate + This token must be associated with your Hedera account before you can receive it. Association fee ~%1$s %2$s + This token must be associated with your Hedera account before you can receive it + Associate your token + Not enough %s. Top up your Hedera account to associate this token + Only %s signatures are left on this card. You must withdraw all of your funds. + Low signature count + Tokens on different networks can have different addresses. Double-check that your address matches the network when you transfer funds. + + Use your card to get an address for %d network + Use your card to get an addresses for %d networks + + Some addresses are missing + The network is currently unreachable. Please try again later. + Network is unreachable + Top up your wallet + Your wallet hasn\'t been backed up. Carry out this procedure to protect your assets now. + Missing backup + This card has been previously used for transactions. If received from an untrusted source, consider withdrawing all funds. If it\'s your card, no action is required. + Card has already signed transactions + Your review keeps us motivated to make Tangem Wallet even better + Enjoying Tangem? + You must associate your token before receiving tokens + Network rent fee required + %1$s is an asset in the %2$s network. To make a %3$s transaction, you must deposit some %4$s (%5$s) to cover the network fee. + Insufficient %1$s to cover network fee + The Solana network is congested. If your transaction is not processed within 2 minutes, please repeat the transaction. + Solana Network Alert + 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. + Some networks currently are unreachable. Please try again later. + Some networks are unreachable + This is a Testnet card. It cannot process transactions and should only be used for testing and development purposes. + For testing purposes only + Discard + You have an interrupted backup. Do you want to resume? + Yes, resume + Discard + If you will discard the backup now, then you will have to reset the cards to factory settings to start over again + Resume backup + This is an irreversible action + Log in with %s + Scan card + Use %s or scan a card to access the app + Welcome back! diff --git a/core/ui/build.gradle.kts b/core/ui/build.gradle.kts index e7c5bfc4e7..cb8f7f15ee 100644 --- a/core/ui/build.gradle.kts +++ b/core/ui/build.gradle.kts @@ -9,9 +9,6 @@ android { } dependencies { - /** Project - Common */ - implementation(projects.common) - /** Project - Domain */ implementation(projects.domain.tokens.models) implementation(projects.domain.appTheme.models) @@ -25,6 +22,12 @@ dependencies { implementation(deps.androidx.fragment.ktx) implementation(deps.androidx.paging.runtime) implementation(deps.androidx.palette) + implementation(deps.androidx.windowManager) { + exclude( + deps.kotlin.coroutines.android.get().module.group, + deps.kotlin.coroutines.android.get().module.name + ) + } /** Compose */ implementation(deps.compose.constraintLayout) @@ -40,11 +43,12 @@ dependencies { /** Other libraries */ implementation(deps.compose.accompanist.systemUiController) + implementation(deps.compose.accompanist.permission) implementation(deps.material) implementation(deps.compose.shimmer) implementation(deps.kotlin.immutable.collections) implementation(deps.zxing.qrCore) - implementation(deps.jodatime) + api(deps.jodatime) implementation(deps.timber) implementation(deps.markdown) } \ No newline at end of file diff --git a/core/ui/src/main/java/com/tangem/core/ui/UiDependencies.kt b/core/ui/src/main/java/com/tangem/core/ui/UiDependencies.kt index 62e19d4af6..49a90c5af6 100644 --- a/core/ui/src/main/java/com/tangem/core/ui/UiDependencies.kt +++ b/core/ui/src/main/java/com/tangem/core/ui/UiDependencies.kt @@ -1,11 +1,19 @@ package com.tangem.core.ui +import androidx.compose.material3.SnackbarHostState +import androidx.compose.runtime.Stable import com.tangem.core.ui.haptic.HapticManager +import com.tangem.core.ui.message.EventMessageHandler import com.tangem.core.ui.theme.AppThemeModeHolder +@Stable interface UiDependencies { val hapticManager: HapticManager val appThemeModeHolder: AppThemeModeHolder + + val globalSnackbarHostState: SnackbarHostState + + val eventMessageHandler: EventMessageHandler } \ No newline at end of file diff --git a/core/ui/src/main/java/com/tangem/core/ui/components/BottomFade.kt b/core/ui/src/main/java/com/tangem/core/ui/components/BottomFade.kt new file mode 100644 index 0000000000..fbb4ae896b --- /dev/null +++ b/core/ui/src/main/java/com/tangem/core/ui/components/BottomFade.kt @@ -0,0 +1,33 @@ +package com.tangem.core.ui.components + +import androidx.compose.foundation.background +import androidx.compose.foundation.layout.* +import androidx.compose.runtime.Composable +import androidx.compose.ui.Modifier +import androidx.compose.ui.graphics.Brush +import androidx.compose.ui.graphics.Color +import androidx.compose.ui.platform.LocalDensity +import com.tangem.core.ui.res.TangemTheme + +/** + * A composable that draws a fade effect at the bottom of the screen. Used on screens with a list of repeating + * elements and floating button at the bottom of the screen. + */ +@Composable +fun BottomFade(modifier: Modifier = Modifier, backgroundColor: Color = TangemTheme.colors.background.secondary) { + val bottomBarHeight = with(LocalDensity.current) { WindowInsets.systemBars.getBottom(this).toDp() } + + Box( + modifier = modifier + .fillMaxWidth() + .height(TangemTheme.dimens.size100 + bottomBarHeight) + .background( + brush = Brush.verticalGradient( + colors = listOf( + Color.Transparent, + backgroundColor, + ), + ), + ), + ) +} \ No newline at end of file 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 bb17fcf7b6..7ef56f015e 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 @@ -86,6 +86,7 @@ fun PrimaryButton( onClick: () -> Unit, modifier: Modifier = Modifier, size: TangemButtonSize = TangemButtonSize.Default, + colors: ButtonColors = TangemButtonsDefaults.primaryButtonColors, showProgress: Boolean = false, enabled: Boolean = true, ) { @@ -94,7 +95,7 @@ fun PrimaryButton( text = text, icon = TangemButtonIconPosition.None, onClick = onClick, - colors = TangemButtonsDefaults.primaryButtonColors, + colors = colors, enabled = enabled, showProgress = showProgress, size = size, diff --git a/core/ui/src/main/java/com/tangem/core/ui/components/Dialogs.kt b/core/ui/src/main/java/com/tangem/core/ui/components/Dialogs.kt index 18ca78091a..97a3b692cc 100644 --- a/core/ui/src/main/java/com/tangem/core/ui/components/Dialogs.kt +++ b/core/ui/src/main/java/com/tangem/core/ui/components/Dialogs.kt @@ -27,8 +27,8 @@ import com.tangem.core.ui.R import com.tangem.core.ui.components.SelctorDialogParamsProvider.SelectorDialogParams import com.tangem.core.ui.components.buttons.common.TangemButtonsDefaults import com.tangem.core.ui.components.fields.SimpleDialogTextField -import com.tangem.core.ui.res.TangemThemePreview import com.tangem.core.ui.res.TangemTheme +import com.tangem.core.ui.res.TangemThemePreview import kotlinx.collections.immutable.ImmutableList import kotlinx.collections.immutable.persistentListOf import kotlinx.collections.immutable.toImmutableList @@ -100,7 +100,7 @@ fun TextInputDialog( confirmButton: DialogButton, onDismissDialog: () -> Unit, onValueChange: (TextFieldValue) -> Unit, - textFieldParams: AdditionalTextInputDialogParams, + textFieldParams: AdditionalTextInputDialogParams = remember { AdditionalTextInputDialogParams() }, title: String? = null, dismissButton: DialogButton? = null, isDismissable: Boolean = true, @@ -128,7 +128,7 @@ fun TextInputDialog( confirmButton: DialogButton, onDismissDialog: () -> Unit, onValueChange: (String) -> Unit, - textFieldParams: AdditionalTextInputDialogParams, + textFieldParams: AdditionalTextInputDialogParams = remember { AdditionalTextInputDialogParams() }, title: String? = null, dismissButton: DialogButton? = null, isDismissable: Boolean = true, diff --git a/core/ui/src/main/java/com/tangem/core/ui/components/Shimmers.kt b/core/ui/src/main/java/com/tangem/core/ui/components/Shimmers.kt index ddb5122ee1..2e5b4ee1c2 100644 --- a/core/ui/src/main/java/com/tangem/core/ui/components/Shimmers.kt +++ b/core/ui/src/main/java/com/tangem/core/ui/components/Shimmers.kt @@ -17,10 +17,7 @@ import androidx.compose.ui.graphics.BlendMode import androidx.compose.ui.graphics.Color import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.unit.Dp -import com.tangem.core.ui.res.LocalIsInDarkTheme -import com.tangem.core.ui.res.TangemColorPalette -import com.tangem.core.ui.res.TangemThemePreview -import com.tangem.core.ui.res.TangemTheme +import com.tangem.core.ui.res.* import com.valentinilk.shimmer.* /** @@ -31,7 +28,7 @@ fun RectangleShimmer(modifier: Modifier = Modifier, radius: Dp = TangemTheme.dim Box( modifier = modifier .clip(RoundedCornerShape(size = radius)) - .shimmer(TangemShimmer), + .shimmer(LocalTangemShimmer.current), ) } @@ -44,11 +41,11 @@ fun CircleShimmer(modifier: Modifier = Modifier) { Box( modifier = modifier .clip(CircleShape) - .shimmer(TangemShimmer), + .shimmer(LocalTangemShimmer.current), ) } -private val TangemShimmer: Shimmer +internal val TangemShimmer: Shimmer @Composable get() = rememberShimmer( shimmerBounds = ShimmerBounds.View, diff --git a/core/ui/src/main/java/com/tangem/core/ui/components/SystemBarsEffect.kt b/core/ui/src/main/java/com/tangem/core/ui/components/SystemBarsEffect.kt deleted file mode 100644 index ea843b7a7a..0000000000 --- a/core/ui/src/main/java/com/tangem/core/ui/components/SystemBarsEffect.kt +++ /dev/null @@ -1,12 +0,0 @@ -package com.tangem.core.ui.components - -import androidx.compose.runtime.Composable -import androidx.compose.runtime.SideEffect -import com.google.accompanist.systemuicontroller.SystemUiController -import com.google.accompanist.systemuicontroller.rememberSystemUiController - -@Composable -fun SystemBarsEffect(block: SystemUiController.() -> Unit) { - val systemUiController = rememberSystemUiController() - SideEffect { block(systemUiController) } -} \ No newline at end of file diff --git a/core/ui/src/main/java/com/tangem/core/ui/components/SystemBarsUtils.kt b/core/ui/src/main/java/com/tangem/core/ui/components/SystemBarsUtils.kt new file mode 100644 index 0000000000..0e40554581 --- /dev/null +++ b/core/ui/src/main/java/com/tangem/core/ui/components/SystemBarsUtils.kt @@ -0,0 +1,61 @@ +package com.tangem.core.ui.components + +import androidx.compose.runtime.Composable +import androidx.compose.runtime.DisposableEffect +import androidx.compose.runtime.LaunchedEffect +import androidx.compose.runtime.SideEffect +import com.google.accompanist.systemuicontroller.rememberSystemUiController +import com.tangem.core.ui.res.LocalIsInDarkTheme + +/** + * Provides the ability to set a scrim for 3-button navigation + * + * Automatically makes navigation bar transparent when the composable is disposed. + * + * Usage example: [com.tangem.feature.tokendetails.presentation.TokenDetailsFragment] + */ +@Composable +fun NavigationBar3ButtonsScrim() { + val systemUiController = rememberSystemUiController() + val isDarkTheme = LocalIsInDarkTheme.current + SideEffect { + systemUiController.isNavigationBarContrastEnforced = true + } + LaunchedEffect(systemUiController.isNavigationBarContrastEnforced) { + if (systemUiController.isNavigationBarContrastEnforced.not()) { + systemUiController.isNavigationBarContrastEnforced = true + } + } + DisposableEffect(isDarkTheme) { + onDispose { + systemUiController.isNavigationBarContrastEnforced = false + } + } +} + +/** + * Provides the ability to set dark/light icons in cases where the darkness of the screen differs from that + * provided in [TangemTheme]. + * + * Automatically returns the icon colors to their original state when the composable is disposed. + * + * Usage example: [com.tangem.feature.qrscanning.QrScanningFragment] + */ +@Composable +fun SystemBarsIconsDisposable(darkIcons: Boolean, isNavigationBarContrastEnforced: Boolean = false) { + val systemUiController = rememberSystemUiController() + + SideEffect { + systemUiController.systemBarsDarkContentEnabled = darkIcons + systemUiController.isNavigationBarContrastEnforced = isNavigationBarContrastEnforced + } + + val isDarkTheme = LocalIsInDarkTheme.current + + DisposableEffect(isDarkTheme) { + onDispose { + systemUiController.systemBarsDarkContentEnabled = !isDarkTheme + systemUiController.isNavigationBarContrastEnforced = false + } + } +} \ No newline at end of file diff --git a/core/ui/src/main/java/com/tangem/core/ui/components/TangemSwitch.kt b/core/ui/src/main/java/com/tangem/core/ui/components/TangemSwitch.kt index 8e0081a633..7b3c924e95 100644 --- a/core/ui/src/main/java/com/tangem/core/ui/components/TangemSwitch.kt +++ b/core/ui/src/main/java/com/tangem/core/ui/components/TangemSwitch.kt @@ -15,6 +15,7 @@ import androidx.compose.runtime.remember import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.Color +import androidx.compose.ui.semantics.Role import androidx.compose.ui.unit.Dp import androidx.compose.ui.unit.dp import com.tangem.core.ui.res.TangemTheme @@ -23,6 +24,8 @@ import com.tangem.core.ui.res.TangemTheme @Composable fun TangemSwitch( onCheckedChange: (Boolean) -> Unit, + modifier: Modifier = Modifier, + interactionSource: MutableInteractionSource = remember { MutableInteractionSource() }, checkedColor: Color = TangemTheme.colors.control.checked, uncheckedColor: Color = TangemTheme.colors.icon.informative, size: Dp = 48.dp, @@ -39,23 +42,20 @@ fun TangemSwitch( (if (isChecked) checkedColor else uncheckedColor) .copy(alpha = if (enabled) 1f else .4f) } - val interactionSource = remember { MutableInteractionSource() } Box( - modifier = Modifier + modifier = modifier .clickable( - interactionSource = interactionSource, - indication = null, - enabled = enabled, - ) { - onCheckedChange(!checked) - } - .indication( interactionSource = interactionSource, indication = rememberRipple( bounded = false, color = Color.Transparent, ), + enabled = enabled, + role = Role.Switch, + onClick = { + onCheckedChange(!checked) + }, ), ) { BoxWithConstraints( diff --git a/core/ui/src/main/java/com/tangem/core/ui/components/TextFields.kt b/core/ui/src/main/java/com/tangem/core/ui/components/TextFields.kt index 055eaab6f7..da346fafa1 100644 --- a/core/ui/src/main/java/com/tangem/core/ui/components/TextFields.kt +++ b/core/ui/src/main/java/com/tangem/core/ui/components/TextFields.kt @@ -26,8 +26,8 @@ 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.res.TangemThemePreview import com.tangem.core.ui.res.TangemTheme +import com.tangem.core.ui.res.TangemThemePreview /** * [Show in Figma](https://www.figma.com/file/14ISV23YB1yVW1uNVwqrKv/Android?node-id=213%3A218&t=TmfD6UBHPg9uYfev-4) @@ -392,7 +392,11 @@ data class TangemTextFieldColors( else -> unfocusedIndicatorColor } return if (enabled) { - animateColorAsState(targetValue, tween(durationMillis = 120)) + animateColorAsState( + targetValue = targetValue, + animationSpec = tween(durationMillis = 120), + label = "IndicatorColor", + ) } else { rememberUpdatedState(targetValue) } diff --git a/core/ui/src/main/java/com/tangem/core/ui/components/appbar/AppBarWithAdditionalButtons.kt b/core/ui/src/main/java/com/tangem/core/ui/components/appbar/AppBarWithAdditionalButtons.kt deleted file mode 100644 index 685358db13..0000000000 --- a/core/ui/src/main/java/com/tangem/core/ui/components/appbar/AppBarWithAdditionalButtons.kt +++ /dev/null @@ -1,122 +0,0 @@ -package com.tangem.core.ui.components.appbar - -import android.content.res.Configuration -import androidx.compose.foundation.layout.Box -import androidx.compose.foundation.layout.fillMaxWidth -import androidx.compose.foundation.layout.heightIn -import androidx.compose.foundation.layout.padding -import androidx.compose.foundation.layout.size -import androidx.compose.material.Icon -import androidx.compose.material.IconButton -import androidx.compose.material.Text -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.tooling.preview.Preview -import com.tangem.core.ui.R -import com.tangem.core.ui.components.appbar.models.AdditionalButton -import com.tangem.core.ui.res.TangemThemePreview -import com.tangem.core.ui.res.TangemTheme - -/** - * App bar with title and two additional buttons - * - * @param startButton button information attached to the left edge - * @param endButton button information attached to the right edge - * - * @see - * Figma Component - */ -@Composable -fun AppBarWithAdditionalButtons( - text: String, - startButton: AdditionalButton? = null, - endButton: AdditionalButton? = null, -) { - Box( - modifier = Modifier - .fillMaxWidth() - .heightIn(TangemTheme.dimens.size56) - .padding(all = TangemTheme.dimens.spacing16), - ) { - if (startButton != null) { - IconButton(modifier = Modifier.align(Alignment.CenterStart), onClick = startButton.onIconClicked) { - Icon( - painter = painterResource(id = startButton.iconRes), - contentDescription = null, - modifier = Modifier.size(TangemTheme.dimens.size24), - tint = TangemTheme.colors.icon.primary1, - ) - } - } - - Text( - text = text, - modifier = Modifier.align(Alignment.Center), - color = TangemTheme.colors.text.primary1, - maxLines = 1, - style = TangemTheme.typography.subtitle1, - ) - - if (endButton != null) { - IconButton(modifier = Modifier.align(Alignment.CenterEnd), onClick = endButton.onIconClicked) { - Icon( - painter = painterResource(id = endButton.iconRes), - contentDescription = null, - modifier = Modifier.size(TangemTheme.dimens.size24), - tint = TangemTheme.colors.icon.primary1, - ) - } - } - } -} - -@Preview(widthDp = 360, heightDp = 56, showBackground = true) -@Preview(widthDp = 360, heightDp = 56, showBackground = true, uiMode = Configuration.UI_MODE_NIGHT_YES) -@Composable -private fun Preview_AppBarWithAdditionalButtons() { - TangemThemePreview { - AppBarWithAdditionalButtons( - text = "Tangem", - startButton = AdditionalButton( - iconRes = R.drawable.ic_scan_24, - onIconClicked = {}, - ), - endButton = AdditionalButton( - iconRes = R.drawable.ic_more_vertical_24, - onIconClicked = {}, - ), - ) - } -} - -@Preview(widthDp = 360, heightDp = 56, showBackground = true) -@Preview(widthDp = 360, heightDp = 56, showBackground = true, uiMode = Configuration.UI_MODE_NIGHT_YES) -@Composable -private fun Preview_AppBarWithOnlyStartButtons() { - TangemThemePreview { - AppBarWithAdditionalButtons( - text = "Tangem", - startButton = AdditionalButton( - iconRes = R.drawable.ic_scan_24, - onIconClicked = {}, - ), - ) - } -} - -@Preview(widthDp = 360, heightDp = 56, showBackground = true) -@Preview(widthDp = 360, heightDp = 56, showBackground = true, uiMode = Configuration.UI_MODE_NIGHT_YES) -@Composable -private fun Preview_AppBarWithOnlyEndButtons() { - TangemThemePreview { - AppBarWithAdditionalButtons( - text = "Tangem", - endButton = AdditionalButton( - iconRes = R.drawable.ic_more_vertical_24, - onIconClicked = {}, - ), - ) - } -} \ No newline at end of file diff --git a/core/ui/src/main/java/com/tangem/core/ui/components/appbar/AppBarWithBackButton.kt b/core/ui/src/main/java/com/tangem/core/ui/components/appbar/AppBarWithBackButton.kt index 80d3014615..65304bcf57 100644 --- a/core/ui/src/main/java/com/tangem/core/ui/components/appbar/AppBarWithBackButton.kt +++ b/core/ui/src/main/java/com/tangem/core/ui/components/appbar/AppBarWithBackButton.kt @@ -2,22 +2,12 @@ package com.tangem.core.ui.components.appbar import android.content.res.Configuration import androidx.annotation.DrawableRes -import androidx.compose.foundation.background -import androidx.compose.foundation.clickable -import androidx.compose.foundation.interaction.MutableInteractionSource -import androidx.compose.foundation.layout.* -import androidx.compose.material.Icon -import androidx.compose.material.Text -import androidx.compose.material.ripple.rememberRipple import androidx.compose.runtime.Composable -import androidx.compose.runtime.remember -import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier -import androidx.compose.ui.res.painterResource import androidx.compose.ui.tooling.preview.Preview import com.tangem.core.ui.R +import com.tangem.core.ui.components.appbar.models.TopAppBarButtonUM import com.tangem.core.ui.res.TangemThemePreview -import com.tangem.core.ui.res.TangemTheme /** * App bar with back button and optional title @@ -37,37 +27,17 @@ fun AppBarWithBackButton( text: String? = null, @DrawableRes iconRes: Int? = null, ) { - Row( - modifier = modifier - .background(color = TangemTheme.colors.background.secondary) - .fillMaxWidth() - .padding(all = TangemTheme.dimens.spacing16), - horizontalArrangement = Arrangement.spacedBy(TangemTheme.dimens.spacing16), - verticalAlignment = Alignment.CenterVertically, - ) { - Icon( - painter = painterResource(iconRes ?: R.drawable.ic_back_24), - contentDescription = null, - modifier = Modifier - .size(size = TangemTheme.dimens.size24) - .clickable( - indication = rememberRipple(bounded = false), - interactionSource = remember { MutableInteractionSource() }, - onClick = onBackClick, - ), - tint = TangemTheme.colors.icon.primary1, - ) - if (!text.isNullOrBlank()) { - Text( - text = text, - color = TangemTheme.colors.text.primary1, - maxLines = 1, - style = TangemTheme.typography.subtitle1, - ) - } - } + TangemTopAppBar( + modifier = modifier, + title = text, + startButton = TopAppBarButtonUM( + iconRes = iconRes ?: R.drawable.ic_back_24, + onIconClicked = onBackClick, + ), + ) } +// region Preview @Preview(widthDp = 360, heightDp = 56, showBackground = true) @Preview(widthDp = 360, heightDp = 56, showBackground = true, uiMode = Configuration.UI_MODE_NIGHT_YES) @Composable @@ -75,4 +45,5 @@ private fun PreviewAppBarWithBackButton() { TangemThemePreview { AppBarWithBackButton(text = "Title", onBackClick = {}) } -} \ No newline at end of file +} +// endregion \ No newline at end of file diff --git a/core/ui/src/main/java/com/tangem/core/ui/components/appbar/AppBarWithBackButtonAndIcon.kt b/core/ui/src/main/java/com/tangem/core/ui/components/appbar/AppBarWithBackButtonAndIcon.kt index 0006bdad9d..aaa6fcf804 100644 --- a/core/ui/src/main/java/com/tangem/core/ui/components/appbar/AppBarWithBackButtonAndIcon.kt +++ b/core/ui/src/main/java/com/tangem/core/ui/components/appbar/AppBarWithBackButtonAndIcon.kt @@ -2,18 +2,14 @@ package com.tangem.core.ui.components.appbar import android.content.res.Configuration import androidx.annotation.DrawableRes -import androidx.compose.animation.* -import androidx.compose.foundation.clickable -import androidx.compose.foundation.layout.size -import androidx.compose.material.Icon import androidx.compose.runtime.Composable 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.TangemThemePreview +import com.tangem.core.ui.components.appbar.models.TopAppBarButtonUM import com.tangem.core.ui.res.TangemTheme +import com.tangem.core.ui.res.TangemThemePreview @Composable fun AppBarWithBackButtonAndIcon( @@ -26,30 +22,22 @@ fun AppBarWithBackButtonAndIcon( onIconClick: (() -> Unit)? = null, backgroundColor: Color = TangemTheme.colors.background.secondary, ) { - AppBarWithBackButtonAndIconContent( - onBackClick = onBackClick, + TangemTopAppBar( modifier = modifier, - text = text, + title = text, subtitle = subtitle, - backIconRes = backIconRes, - backgroundColor = backgroundColor, - iconContent = { - AnimatedContent( - targetState = iconRes, - transitionSpec = { (fadeIn() + scaleIn()).togetherWith(fadeOut() + scaleOut()) }, - label = "Toolbar icon change", - ) { - if (onIconClick != null && it != null) { - Icon( - painter = painterResource(it), - contentDescription = null, - modifier = Modifier - .size(size = TangemTheme.dimens.size24) - .clickable { onIconClick() }, - tint = TangemTheme.colors.icon.primary1, - ) - } - } + containerColor = backgroundColor, + startButton = TopAppBarButtonUM( + iconRes = backIconRes ?: R.drawable.ic_back_24, + onIconClicked = onBackClick, + ), + endButton = if (iconRes != null && onIconClick != null) { + TopAppBarButtonUM( + iconRes = iconRes, + onIconClicked = onIconClick, + ) + } else { + null }, ) } diff --git a/core/ui/src/main/java/com/tangem/core/ui/components/appbar/AppBarWithBackButtonAndIconContent.kt b/core/ui/src/main/java/com/tangem/core/ui/components/appbar/AppBarWithBackButtonAndIconContent.kt deleted file mode 100644 index fae3598a38..0000000000 --- a/core/ui/src/main/java/com/tangem/core/ui/components/appbar/AppBarWithBackButtonAndIconContent.kt +++ /dev/null @@ -1,127 +0,0 @@ -package com.tangem.core.ui.components.appbar - -import android.content.res.Configuration -import androidx.annotation.DrawableRes -import androidx.compose.animation.* -import androidx.compose.foundation.background -import androidx.compose.foundation.clickable -import androidx.compose.foundation.interaction.MutableInteractionSource -import androidx.compose.foundation.layout.* -import androidx.compose.material.Icon -import androidx.compose.material.Text -import androidx.compose.material.ripple.rememberRipple -import androidx.compose.runtime.Composable -import androidx.compose.runtime.remember -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.TangemThemePreview -import com.tangem.core.ui.res.TangemTheme - -/** - * App bar with back button and icon content for any possible number/style of icons - * - * @param onBackClick callback for back button - * @param modifier modifier - * @param text appbar title - * @param backIconRes icon for back button - * @param backgroundColor background color - * @param iconContent icon content - */ -@Composable -fun AppBarWithBackButtonAndIconContent( - onBackClick: () -> Unit, - modifier: Modifier = Modifier, - text: String? = null, - subtitle: String? = null, - @DrawableRes backIconRes: Int? = null, - backIconTint: Color = TangemTheme.colors.icon.primary1, - backgroundColor: Color = TangemTheme.colors.background.secondary, - iconContent: @Composable () -> Unit, -) { - Row( - modifier = modifier - .height(TangemTheme.dimens.size56) - .background(color = backgroundColor) - .fillMaxWidth() - .padding(horizontal = TangemTheme.dimens.spacing16), - horizontalArrangement = Arrangement.spacedBy(TangemTheme.dimens.spacing16), - verticalAlignment = Alignment.CenterVertically, - ) { - Icon( - painter = painterResource(backIconRes ?: R.drawable.ic_back_24), - contentDescription = null, - modifier = Modifier - .padding(vertical = TangemTheme.dimens.spacing16) - .size(size = TangemTheme.dimens.size24) - .clickable( - interactionSource = remember { MutableInteractionSource() }, - indication = rememberRipple(bounded = false), - ) { onBackClick() }, - tint = backIconTint, - ) - Column( - verticalArrangement = Arrangement.Center, - modifier = Modifier.weight(1f) - .animateContentSize(), - ) { - AnimatedVisibility( - visible = !text.isNullOrBlank(), - enter = fadeIn(), - exit = fadeOut(), - label = "Toolbar title change", - ) { - Text( - text = text.orEmpty(), - color = TangemTheme.colors.text.primary1, - maxLines = 1, - style = TangemTheme.typography.subtitle1, - ) - } - AnimatedVisibility( - visible = !subtitle.isNullOrBlank(), - enter = fadeIn().plus(expandVertically()), - exit = fadeOut().plus(shrinkVertically()), - label = "Toolbar subtitle change", - ) { - Text( - text = subtitle.orEmpty(), - color = TangemTheme.colors.text.secondary, - maxLines = 1, - style = TangemTheme.typography.caption2, - ) - } - } - iconContent() - } -} - -@Preview(widthDp = 360, heightDp = 56, showBackground = true) -@Preview(widthDp = 360, heightDp = 56, showBackground = true, uiMode = Configuration.UI_MODE_NIGHT_YES) -@Composable -private fun PreviewAppBarWithBackButtonAndIcon() { - TangemThemePreview { - AppBarWithBackButtonAndIconContent( - text = "Title", - subtitle = "Subtitle", - onBackClick = {}, - iconContent = { - Row { - Icon( - painter = painterResource(id = R.drawable.ic_qrcode_scan_24), - tint = TangemTheme.colors.icon.primary1, - contentDescription = null, - ) - Icon( - painter = painterResource(id = R.drawable.ic_flash_on_24), - tint = TangemTheme.colors.icon.primary1, - contentDescription = null, - ) - } - }, - ) - } -} \ No newline at end of file diff --git a/core/ui/src/main/java/com/tangem/core/ui/components/appbar/TangemTopAppBar.kt b/core/ui/src/main/java/com/tangem/core/ui/components/appbar/TangemTopAppBar.kt new file mode 100644 index 0000000000..716d79978f --- /dev/null +++ b/core/ui/src/main/java/com/tangem/core/ui/components/appbar/TangemTopAppBar.kt @@ -0,0 +1,336 @@ +package com.tangem.core.ui.components.appbar + +import android.content.res.Configuration +import androidx.compose.animation.* +import androidx.compose.foundation.background +import androidx.compose.foundation.layout.* +import androidx.compose.material3.Text +import androidx.compose.runtime.Composable +import androidx.compose.runtime.ReadOnlyComposable +import androidx.compose.ui.Alignment +import androidx.compose.ui.Modifier +import androidx.compose.ui.graphics.Color +import androidx.compose.ui.text.style.TextOverflow +import androidx.compose.ui.tooling.preview.Preview +import androidx.compose.ui.tooling.preview.PreviewParameter +import androidx.compose.ui.tooling.preview.PreviewParameterProvider +import com.tangem.core.ui.R +import com.tangem.core.ui.components.appbar.models.TopAppBarButtonUM +import com.tangem.core.ui.extensions.TextReference +import com.tangem.core.ui.extensions.resolveReference +import com.tangem.core.ui.res.TangemTheme +import com.tangem.core.ui.res.TangemThemePreview + +/** + * [TangemTopAppBar] height options. + * */ +enum class TangemTopAppBarHeight { + BOTTOM_SHEET, DEFAULT, +} + +/** + * Top app bar with two optional buttons: [startButton] and [endButton]. + * + * @see + * Figma Component + */ +@Composable +fun TangemTopAppBar( + modifier: Modifier = Modifier, + startButton: TopAppBarButtonUM? = null, + endButton: TopAppBarButtonUM? = null, + textColor: Color = TangemTheme.colors.text.primary1, + iconTint: Color = TangemTheme.colors.icon.primary1, + containerColor: Color = Color.Transparent, + height: TangemTopAppBarHeight = TangemTopAppBarHeight.DEFAULT, +) { + TangemTopAppBar( + modifier = modifier, + title = null, + startButton = startButton, + endButton = endButton, + textColor = textColor, + iconTint = iconTint, + containerColor = containerColor, + height = height, + ) +} + +/** + * Top app bar with [title], optional [subtitle] and two optional buttons: [startButton] and [endButton]. + * + * Where [title] and [subtitle] are [TextReference]. + * + * @see + * Figma Component + */ +@Composable +fun TangemTopAppBar( + title: TextReference, + modifier: Modifier = Modifier, + subtitle: TextReference? = null, + startButton: TopAppBarButtonUM? = null, + endButton: TopAppBarButtonUM? = null, + textColor: Color = TangemTheme.colors.text.primary1, + iconTint: Color = TangemTheme.colors.icon.primary1, + titleAlignment: Alignment.Horizontal = Alignment.Start, + containerColor: Color = Color.Transparent, + height: TangemTopAppBarHeight = TangemTopAppBarHeight.DEFAULT, +) { + TangemTopAppBar( + modifier = modifier, + title = title.resolveReference(), + subtitle = subtitle?.resolveReference(), + startButton = startButton, + endButton = endButton, + textColor = textColor, + iconTint = iconTint, + titleAlignment = titleAlignment, + containerColor = containerColor, + height = height, + ) +} + +/** + * Top app bar with [title], optional [subtitle] and two optional buttons: [startButton] and [endButton]. + * + * Where [title] and [subtitle] are [String]. + * + * @see + * Figma Component + */ +@Composable +fun TangemTopAppBar( + title: String?, + modifier: Modifier = Modifier, + subtitle: String? = null, + startButton: TopAppBarButtonUM? = null, + endButton: TopAppBarButtonUM? = null, + textColor: Color = TangemTheme.colors.text.primary1, + iconTint: Color = TangemTheme.colors.icon.primary1, + titleAlignment: Alignment.Horizontal = Alignment.Start, + containerColor: Color = Color.Transparent, + height: TangemTopAppBarHeight = TangemTopAppBarHeight.DEFAULT, +) { + TangemTopAppBar( + title = title, + modifier = modifier, + subtitle = subtitle, + startButton = startButton, + textColor = textColor, + iconTint = iconTint, + titleAlignment = titleAlignment, + containerColor = containerColor, + height = height, + endContent = { + if (endButton != null) { + TopAppBarButton( + button = endButton, + tint = iconTint, + ) + } + }, + ) +} + +/** + * Top app bar with [title], optional [subtitle], optional [startButton] and [endContent]. + * + * Where [title] and [subtitle] are [String] and [endContent] is a lambda that provides a [RowScope] to build + * the end content. + * + * @see + * Figma Component + */ +@Composable +fun TangemTopAppBar( + title: String?, + modifier: Modifier = Modifier, + subtitle: String? = null, + startButton: TopAppBarButtonUM? = null, + textColor: Color = TangemTheme.colors.text.primary1, + iconTint: Color = TangemTheme.colors.icon.primary1, + titleAlignment: Alignment.Horizontal = Alignment.Start, + containerColor: Color = Color.Transparent, + height: TangemTopAppBarHeight = TangemTopAppBarHeight.DEFAULT, + endContent: @Composable RowScope.() -> Unit, +) { + Row( + modifier = modifier + .background(color = containerColor) + .fillMaxWidth() + .heightIn(min = height.dp), + verticalAlignment = Alignment.CenterVertically, + ) { + Box( + modifier = Modifier + .padding(horizontal = TangemTheme.dimens.spacing12) + .size(TangemTheme.dimens.size32), + contentAlignment = Alignment.Center, + ) { + if (startButton != null) { + TopAppBarButton( + button = startButton, + tint = iconTint, + ) + } + } + + TopAppBarTitle( + modifier = Modifier.weight(1f), + title = title, + subtitle = subtitle, + textColor = textColor, + titleAlignment = titleAlignment, + ) + + Row( + modifier = Modifier + .padding(horizontal = TangemTheme.dimens.spacing12) + .widthIn(min = TangemTheme.dimens.size32) + .height(TangemTheme.dimens.size32), + verticalAlignment = Alignment.CenterVertically, + horizontalArrangement = Arrangement.spacedBy(TangemTheme.dimens.spacing12, Alignment.End), + content = endContent, + ) + } +} + +@Composable +private fun TopAppBarTitle( + title: String?, + subtitle: String?, + textColor: Color, + titleAlignment: Alignment.Horizontal, + modifier: Modifier = Modifier, +) { + Box(modifier = modifier) { + AnimatedVisibility( + modifier = Modifier.fillMaxWidth(), + visible = !title.isNullOrBlank(), + enter = fadeIn() + expandVertically(), + exit = fadeOut() + shrinkVertically(), + ) { + Column( + modifier = Modifier.fillMaxWidth(), + verticalArrangement = Arrangement.Center, + horizontalAlignment = titleAlignment, + ) { + Text( + text = title.orEmpty(), + style = TangemTheme.typography.subtitle1, + color = textColor, + maxLines = 1, + overflow = TextOverflow.Ellipsis, + ) + + AnimatedVisibility( + visible = !subtitle.isNullOrBlank(), + enter = fadeIn() + expandVertically(), + exit = fadeOut() + shrinkVertically(), + label = "Toolbar subtitle visibility", + ) { + Text( + text = subtitle.orEmpty(), + style = TangemTheme.typography.caption2, + color = TangemTheme.colors.text.secondary, + maxLines = 1, + overflow = TextOverflow.Ellipsis, + ) + } + } + } + } +} + +private val TangemTopAppBarHeight.dp + @Composable + @ReadOnlyComposable + get() = when (this) { + TangemTopAppBarHeight.BOTTOM_SHEET -> TangemTheme.dimens.size44 + TangemTopAppBarHeight.DEFAULT -> TangemTheme.dimens.size56 + } + +// region Preview +@Composable +@Preview(showBackground = true, widthDp = 360) +@Preview(showBackground = true, widthDp = 360, uiMode = Configuration.UI_MODE_NIGHT_YES) +private fun Preview_BasicTopAppBar( + @PreviewParameter(BasicTopAppBarPMPreviewProvider::class) params: BasicTopAppBarPM, +) { + TangemThemePreview { + TangemTopAppBar( + title = params.title, + subtitle = params.subtitle, + startButton = params.startButton, + endButton = params.endButton, + titleAlignment = params.titleAlignment, + containerColor = TangemTheme.colors.background.secondary, + height = params.height, + ) + } +} + +private data class BasicTopAppBarPM( + val title: String? = "Tangem", + val subtitle: String? = null, + val startButton: TopAppBarButtonUM? = null, + val endButton: TopAppBarButtonUM? = null, + val titleAlignment: Alignment.Horizontal = Alignment.CenterHorizontally, + val height: TangemTopAppBarHeight = TangemTopAppBarHeight.DEFAULT, +) + +private class BasicTopAppBarPMPreviewProvider : PreviewParameterProvider { + override val values: Sequence + get() = sequenceOf( + BasicTopAppBarPM( + subtitle = "Subtitle", + titleAlignment = Alignment.Start, + startButton = TopAppBarButtonUM.Back { }, + ), + BasicTopAppBarPM( + title = null, + startButton = TopAppBarButtonUM.Back { }, + ), + BasicTopAppBarPM( + height = TangemTopAppBarHeight.BOTTOM_SHEET, + ), + BasicTopAppBarPM( + startButton = TopAppBarButtonUM( + iconRes = R.drawable.ic_scan_24, + onIconClicked = {}, + ), + endButton = TopAppBarButtonUM( + iconRes = R.drawable.ic_more_vertical_24, + onIconClicked = {}, + ), + ), + BasicTopAppBarPM( + startButton = TopAppBarButtonUM( + iconRes = R.drawable.ic_scan_24, + onIconClicked = {}, + ), + ), + BasicTopAppBarPM( + endButton = TopAppBarButtonUM( + iconRes = R.drawable.ic_more_vertical_24, + onIconClicked = {}, + ), + height = TangemTopAppBarHeight.BOTTOM_SHEET, + ), + BasicTopAppBarPM( + title = "1234567891011121314151617181920", + subtitle = "12345678910111213141516171819202122232425", + titleAlignment = Alignment.Start, + startButton = TopAppBarButtonUM( + iconRes = R.drawable.ic_scan_24, + onIconClicked = {}, + ), + endButton = TopAppBarButtonUM( + iconRes = R.drawable.ic_more_vertical_24, + onIconClicked = {}, + ), + ), + ) +} +// endregion Preview \ No newline at end of file diff --git a/core/ui/src/main/java/com/tangem/core/ui/components/appbar/TopAppBarButton.kt b/core/ui/src/main/java/com/tangem/core/ui/components/appbar/TopAppBarButton.kt new file mode 100644 index 0000000000..160e0148da --- /dev/null +++ b/core/ui/src/main/java/com/tangem/core/ui/components/appbar/TopAppBarButton.kt @@ -0,0 +1,26 @@ +package com.tangem.core.ui.components.appbar + +import androidx.compose.foundation.layout.size +import androidx.compose.material3.Icon +import androidx.compose.material3.IconButton +import androidx.compose.runtime.Composable +import androidx.compose.ui.Modifier +import androidx.compose.ui.graphics.Color +import androidx.compose.ui.res.painterResource +import com.tangem.core.ui.components.appbar.models.TopAppBarButtonUM +import com.tangem.core.ui.res.TangemTheme + +@Composable +fun TopAppBarButton(button: TopAppBarButtonUM, tint: Color, modifier: Modifier = Modifier) { + IconButton( + modifier = modifier.size(TangemTheme.dimens.size32), + onClick = button.onIconClicked, + ) { + Icon( + modifier = Modifier.size(TangemTheme.dimens.size24), + painter = painterResource(id = button.iconRes), + tint = tint, + contentDescription = null, + ) + } +} \ No newline at end of file diff --git a/core/ui/src/main/java/com/tangem/core/ui/components/appbar/models/AdditionalButton.kt b/core/ui/src/main/java/com/tangem/core/ui/components/appbar/models/AdditionalButton.kt deleted file mode 100644 index 2517f5ef41..0000000000 --- a/core/ui/src/main/java/com/tangem/core/ui/components/appbar/models/AdditionalButton.kt +++ /dev/null @@ -1,8 +0,0 @@ -package com.tangem.core.ui.components.appbar.models - -import androidx.annotation.DrawableRes - -data class AdditionalButton( - @DrawableRes val iconRes: Int, - val onIconClicked: () -> Unit, -) \ No newline at end of file diff --git a/core/ui/src/main/java/com/tangem/core/ui/components/appbar/models/TopAppBarButtonUM.kt b/core/ui/src/main/java/com/tangem/core/ui/components/appbar/models/TopAppBarButtonUM.kt new file mode 100644 index 0000000000..61e3f25d39 --- /dev/null +++ b/core/ui/src/main/java/com/tangem/core/ui/components/appbar/models/TopAppBarButtonUM.kt @@ -0,0 +1,19 @@ +package com.tangem.core.ui.components.appbar.models + +import androidx.annotation.DrawableRes +import com.tangem.core.ui.R + +data class TopAppBarButtonUM( + @DrawableRes val iconRes: Int, + val onIconClicked: () -> Unit, +) { + + @Suppress("FunctionName") + companion object { + + fun Back(onBackClicked: () -> Unit) = TopAppBarButtonUM( + iconRes = R.drawable.ic_back_24, + onIconClicked = onBackClicked, + ) + } +} \ No newline at end of file diff --git a/core/ui/src/main/java/com/tangem/core/ui/components/atoms/radiobutton/TangemRadioButton.kt b/core/ui/src/main/java/com/tangem/core/ui/components/atoms/radiobutton/TangemRadioButton.kt new file mode 100644 index 0000000000..777062e8bd --- /dev/null +++ b/core/ui/src/main/java/com/tangem/core/ui/components/atoms/radiobutton/TangemRadioButton.kt @@ -0,0 +1,85 @@ +package com.tangem.core.ui.components.atoms.radiobutton + +import android.content.res.Configuration +import androidx.compose.animation.AnimatedVisibility +import androidx.compose.foundation.Canvas +import androidx.compose.foundation.clickable +import androidx.compose.foundation.interaction.MutableInteractionSource +import androidx.compose.foundation.layout.Box +import androidx.compose.foundation.layout.padding +import androidx.compose.foundation.layout.size +import androidx.compose.material.ripple.rememberRipple +import androidx.compose.material3.Icon +import androidx.compose.runtime.* +import androidx.compose.ui.Modifier +import androidx.compose.ui.graphics.drawscope.Stroke +import androidx.compose.ui.platform.LocalDensity +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 +import com.tangem.core.ui.res.TangemThemePreview + +/** + * [Radio button](https://www.figma.com/design/14ISV23YB1yVW1uNVwqrKv/Android?node-id=101-119&t=FH84ljLBk1vmGAei-4) + * + * @param isSelected Whether the radio button is selected + * @param onClick Called when the user clicks the button + * @param modifier Modifier to be applied to the button + * @param isEnabled Whether the button click is enabled + */ +@Composable +fun TangemRadioButton( + isSelected: Boolean, + onClick: () -> Unit, + modifier: Modifier = Modifier, + isEnabled: Boolean = true, +) { + Box( + modifier = modifier.clickable( + enabled = isEnabled, + interactionSource = remember { MutableInteractionSource() }, + indication = rememberRipple(bounded = false, radius = TangemTheme.dimens.size16), + onClick = onClick, + ), + ) { + val color = TangemTheme.colors.stroke.secondary + val radius = with(LocalDensity.current) { TangemTheme.dimens.size9.toPx() } + val width = with(LocalDensity.current) { TangemTheme.dimens.size2.toPx() } + Canvas( + modifier = Modifier + .size(TangemTheme.dimens.size24) + .padding(TangemTheme.dimens.spacing2), + ) { + drawCircle( + color = color, + radius = radius, + style = Stroke(width), + ) + } + AnimatedVisibility( + visible = isSelected, + label = "Radio button animation", + modifier = modifier + .size(TangemTheme.dimens.size24), + ) { + Icon( + painter = painterResource(id = R.drawable.ic_check_circle_24), + contentDescription = null, + tint = TangemTheme.colors.control.checked, + ) + } + } +} + +// region Preview +@Preview(showBackground = true) +@Preview(showBackground = true, uiMode = Configuration.UI_MODE_NIGHT_YES) +@Composable +private fun TangemRadioButton_Preview() { + var isSelected by remember { mutableStateOf(false) } + TangemThemePreview { + TangemRadioButton(isSelected, onClick = { isSelected = !isSelected }) + } +} +// endregion \ No newline at end of file diff --git a/features/details/impl/src/main/kotlin/com/tangem/features/details/ui/BlockCard.kt b/core/ui/src/main/java/com/tangem/core/ui/components/block/BlockCard.kt similarity index 73% rename from features/details/impl/src/main/kotlin/com/tangem/features/details/ui/BlockCard.kt rename to core/ui/src/main/java/com/tangem/core/ui/components/block/BlockCard.kt index e11a41c41e..49752f2700 100644 --- a/features/details/impl/src/main/kotlin/com/tangem/features/details/ui/BlockCard.kt +++ b/core/ui/src/main/java/com/tangem/core/ui/components/block/BlockCard.kt @@ -1,4 +1,4 @@ -package com.tangem.features.details.ui +package com.tangem.core.ui.components.block import androidx.compose.foundation.layout.ColumnScope import androidx.compose.material3.Card @@ -9,9 +9,10 @@ import androidx.compose.ui.Modifier import com.tangem.core.ui.res.TangemTheme @Composable -internal fun BlockCard( +fun BlockCard( modifier: Modifier = Modifier, enabled: Boolean = true, + colors: CardColors = TangemBlockCardColors, onClick: () -> Unit = {}, content: @Composable ColumnScope.() -> Unit = {}, ) { @@ -19,18 +20,18 @@ internal fun BlockCard( modifier = modifier, onClick = onClick, shape = TangemTheme.shapes.roundedCornersXMedium, - colors = BlockColors, + colors = colors, enabled = enabled, content = content, ) } -private val BlockColors: CardColors +val TangemBlockCardColors: CardColors @Composable @ReadOnlyComposable get() = CardColors( containerColor = TangemTheme.colors.background.primary, contentColor = TangemTheme.colors.text.primary1, - disabledContainerColor = TangemTheme.colors.button.disabled, - disabledContentColor = TangemTheme.colors.text.disabled, + disabledContainerColor = TangemTheme.colors.background.primary, + disabledContentColor = TangemTheme.colors.text.primary1, ) \ No newline at end of file diff --git a/features/details/impl/src/main/kotlin/com/tangem/features/details/ui/BlockItem.kt b/core/ui/src/main/java/com/tangem/core/ui/components/block/BlockItem.kt similarity index 61% rename from features/details/impl/src/main/kotlin/com/tangem/features/details/ui/BlockItem.kt rename to core/ui/src/main/java/com/tangem/core/ui/components/block/BlockItem.kt index 80d99b3b20..d729408a97 100644 --- a/features/details/impl/src/main/kotlin/com/tangem/features/details/ui/BlockItem.kt +++ b/core/ui/src/main/java/com/tangem/core/ui/components/block/BlockItem.kt @@ -1,4 +1,4 @@ -package com.tangem.features.details.ui +package com.tangem.core.ui.components.block import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Row @@ -11,12 +11,12 @@ import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.res.painterResource import androidx.compose.ui.text.style.TextOverflow +import com.tangem.core.ui.components.block.model.BlockUM import com.tangem.core.ui.extensions.resolveReference import com.tangem.core.ui.res.TangemTheme -import com.tangem.features.details.entity.DetailsItemUM @Composable -internal fun BlockItem(model: DetailsItemUM.Basic.Item, modifier: Modifier = Modifier) { +fun BlockItem(model: BlockUM, modifier: Modifier = Modifier) { BlockCard( modifier = modifier, onClick = model.onClick, @@ -29,14 +29,22 @@ internal fun BlockItem(model: DetailsItemUM.Basic.Item, modifier: Modifier = Mod Icon( modifier = Modifier.size(TangemTheme.dimens.size24), painter = painterResource(id = model.iconRes), - tint = TangemTheme.colors.icon.secondary, + tint = when (model.accentType) { + BlockUM.AccentType.NONE -> TangemTheme.colors.icon.secondary + BlockUM.AccentType.ACCENT -> TangemTheme.colors.text.accent + BlockUM.AccentType.WARNING -> TangemTheme.colors.text.warning + }, contentDescription = null, ) Text( - text = model.title.resolveReference(), + text = model.text.resolveReference(), style = TangemTheme.typography.subtitle1, - color = TangemTheme.colors.text.primary1, + color = when (model.accentType) { + BlockUM.AccentType.NONE -> TangemTheme.colors.text.primary1 + BlockUM.AccentType.ACCENT -> TangemTheme.colors.text.accent + BlockUM.AccentType.WARNING -> TangemTheme.colors.text.warning + }, maxLines = 1, overflow = TextOverflow.Ellipsis, ) diff --git a/core/ui/src/main/java/com/tangem/core/ui/components/block/information/InformationBlock.kt b/core/ui/src/main/java/com/tangem/core/ui/components/block/information/InformationBlock.kt new file mode 100644 index 0000000000..027109f071 --- /dev/null +++ b/core/ui/src/main/java/com/tangem/core/ui/components/block/information/InformationBlock.kt @@ -0,0 +1,228 @@ +package com.tangem.core.ui.components.block.information + +import android.content.res.Configuration +import androidx.compose.foundation.background +import androidx.compose.foundation.layout.* +import androidx.compose.material3.Text +import androidx.compose.runtime.Composable +import androidx.compose.runtime.Immutable +import androidx.compose.ui.Alignment +import androidx.compose.ui.Modifier +import androidx.compose.ui.draw.clip +import androidx.compose.ui.tooling.preview.Preview +import com.tangem.core.ui.R +import com.tangem.core.ui.components.buttons.SecondarySmallButton +import com.tangem.core.ui.components.buttons.SmallButtonConfig +import com.tangem.core.ui.components.buttons.common.TangemButtonIconPosition +import com.tangem.core.ui.components.text.TooltipText +import com.tangem.core.ui.extensions.TextReference +import com.tangem.core.ui.extensions.resolveReference +import com.tangem.core.ui.extensions.stringReference +import com.tangem.core.ui.res.TangemTheme +import com.tangem.core.ui.res.TangemThemePreview +import kotlinx.collections.immutable.persistentListOf + +@Immutable +class InformationBlockContentScope(val scope: BoxScope) : BoxScope by scope + +@Composable +fun InformationBlock( + title: @Composable BoxScope.() -> Unit, + modifier: Modifier = Modifier, + action: (@Composable BoxScope.() -> Unit)? = null, + content: (@Composable InformationBlockContentScope.() -> Unit)? = null, +) { + Column( + modifier = modifier + .clip(TangemTheme.shapes.roundedCornersXMedium) + .background(color = TangemTheme.colors.background.action), + horizontalAlignment = Alignment.Start, + ) { + Row( + modifier = Modifier + .fillMaxWidth() + .heightIn(min = TangemTheme.dimens.size40) + .padding( + top = TangemTheme.dimens.spacing12, + bottom = TangemTheme.dimens.spacing6, + ) + .padding(horizontal = TangemTheme.dimens.spacing12), + horizontalArrangement = Arrangement.SpaceBetween, + verticalAlignment = Alignment.CenterVertically, + ) { + Box( + modifier = Modifier + .weight(weight = 1f) + .heightIn(min = TangemTheme.dimens.size20), + contentAlignment = Alignment.CenterStart, + content = title, + ) + if (action != null) { + Spacer(modifier = Modifier.size(TangemTheme.dimens.spacing8)) + Box( + modifier = Modifier + .weight(weight = 1f) + .heightIn(min = TangemTheme.dimens.size24), + contentAlignment = Alignment.CenterEnd, + content = action, + ) + } + } + + if (content != null) { + Box( + modifier = Modifier + .padding(horizontal = TangemTheme.dimens.spacing12) + .fillMaxWidth(), + ) { + val scope = InformationBlockContentScope(scope = this) + content(scope) + } + } + } +} + +// region Previews +@Composable +@Preview(showBackground = true, widthDp = 328) +@Preview(showBackground = true, widthDp = 328, uiMode = Configuration.UI_MODE_NIGHT_YES) +private fun Preview_Grid() { + TangemThemePreview { + InformationBlock( + title = { + TooltipText( + text = stringReference("Grid title"), + onInfoClick = { }, + ) + }, + content = { + GridItems( + itemPadding = PaddingValues(horizontal = TangemTheme.dimens.spacing4), + items = persistentListOf( + stringReference("Fist item"), + stringReference("Second item"), + ), + itemContent = { + PreviewItem(text = it) + }, + horizontalArragement = Arrangement.spacedBy(TangemTheme.dimens.spacing12), + ) + }, + ) + } +} + +@Composable +@Preview(showBackground = true, widthDp = 328) +@Preview(showBackground = true, widthDp = 328, uiMode = Configuration.UI_MODE_NIGHT_YES) +private fun Preview_List() { + TangemThemePreview { + InformationBlock( + title = { + Text( + text = "List", + style = TangemTheme.typography.subtitle2, + color = TangemTheme.colors.text.tertiary, + ) + }, + action = { + SecondarySmallButton( + config = SmallButtonConfig( + text = stringReference("Add token"), + icon = TangemButtonIconPosition.Start(R.drawable.ic_plus_24), + onClick = {}, + ), + ) + }, + content = { + ListItems( + items = persistentListOf( + stringReference("Fist item"), + stringReference("Second item"), + ), + itemContent = { + PreviewItem(it) + }, + verticalArragement = Arrangement.spacedBy(TangemTheme.dimens.spacing8), + ) + }, + ) + } +} + +@Composable +@Preview(showBackground = true, widthDp = 328) +@Preview(showBackground = true, widthDp = 328, uiMode = Configuration.UI_MODE_NIGHT_YES) +private fun Preview_Plain() { + TangemThemePreview { + InformationBlock( + title = { + Column( + verticalArrangement = Arrangement.spacedBy(TangemTheme.dimens.spacing4), + ) { + TooltipText( + text = stringReference("Title"), + onInfoClick = { }, + ) + + Text( + text = "Subtitle", + style = TangemTheme.typography.body2, + color = TangemTheme.colors.text.tertiary, + ) + } + }, + action = { + PreviewItem(text = stringReference("Action")) + }, + ) + } +} + +@Composable +@Preview(showBackground = true, widthDp = 328) +@Preview(showBackground = true, widthDp = 328, uiMode = Configuration.UI_MODE_NIGHT_YES) +private fun Preview_Tree() { + TangemThemePreview { + InformationBlock( + title = { + TooltipText( + text = stringReference("Tree title"), + onInfoClick = { }, + ) + }, + content = { + ArrowRowItems( + itemPadding = PaddingValues(vertical = TangemTheme.dimens.spacing4), + items = persistentListOf( + stringReference("Fist item"), + stringReference("Second item"), + stringReference("Third item"), + ), + rootContent = { + PreviewItem(stringReference("Root")) + }, + itemContent = { + PreviewItem(it) + }, + ) + }, + ) + } +} + +@Composable +private fun PreviewItem(text: TextReference) { + Box( + modifier = Modifier + .fillMaxWidth() + .background(TangemTheme.colors.background.secondary) + .padding(all = TangemTheme.dimens.spacing12), + ) { + Text( + text = text.resolveReference(), + color = TangemTheme.colors.text.primary1, + ) + } +} +// endregion \ No newline at end of file diff --git a/core/ui/src/main/java/com/tangem/core/ui/components/block/information/InformationBlockContent.kt b/core/ui/src/main/java/com/tangem/core/ui/components/block/information/InformationBlockContent.kt new file mode 100644 index 0000000000..1a40b55863 --- /dev/null +++ b/core/ui/src/main/java/com/tangem/core/ui/components/block/information/InformationBlockContent.kt @@ -0,0 +1,113 @@ +package com.tangem.core.ui.components.block.information + +import androidx.compose.foundation.layout.* +import androidx.compose.runtime.Composable +import androidx.compose.runtime.derivedStateOf +import androidx.compose.runtime.getValue +import androidx.compose.runtime.remember +import androidx.compose.ui.Alignment +import androidx.compose.ui.Modifier +import androidx.compose.ui.util.fastForEach +import com.tangem.core.ui.components.rows.ArrowRow +import com.tangem.core.ui.res.TangemTheme +import kotlinx.collections.immutable.ImmutableList +import kotlinx.collections.immutable.toImmutableList + +@Composable +inline fun InformationBlockContentScope.ListItems( + items: ImmutableList, + itemContent: @Composable BoxScope.(T) -> Unit, + modifier: Modifier = Modifier, + itemPadding: PaddingValues = PaddingValues(all = TangemTheme.dimens.spacing0), + horizontalAlignment: Alignment.Horizontal = Alignment.CenterHorizontally, + verticalArragement: Arrangement.Vertical = Arrangement.Top, +) { + Column( + modifier = modifier.fillMaxWidth(), + horizontalAlignment = horizontalAlignment, + verticalArrangement = verticalArragement, + ) { + items.fastForEach { item -> + Box( + modifier = Modifier + .padding(itemPadding) + .fillMaxWidth(), + ) { + itemContent(item) + } + } + } +} + +@Composable +inline fun InformationBlockContentScope.GridItems( + items: ImmutableList, + itemContent: @Composable BoxScope.(T) -> Unit, + modifier: Modifier = Modifier, + itemPadding: PaddingValues = PaddingValues(all = TangemTheme.dimens.spacing0), + verticalAlignment: Alignment.Vertical = Alignment.Top, + horizontalArragement: Arrangement.Horizontal = Arrangement.Start, +) { + val rowItems by remember(items) { + derivedStateOf { + items.asSequence() + .windowed(size = 2, step = 2, partialWindows = true) + .map { it.toImmutableList() } + .toImmutableList() + } + } + + Column( + modifier = modifier.fillMaxWidth(), + horizontalAlignment = Alignment.CenterHorizontally, + verticalArrangement = Arrangement.Top, + ) { + rowItems.fastForEach { row -> + Row( + modifier = Modifier.fillMaxWidth(), + verticalAlignment = verticalAlignment, + horizontalArrangement = horizontalArragement, + ) { + row.fastForEach { item -> + Box( + modifier = Modifier + .padding(itemPadding) + .weight(1f), + contentAlignment = Alignment.Center, + ) { + itemContent(item) + } + } + } + } + } +} + +@Composable +inline fun InformationBlockContentScope.ArrowRowItems( + items: ImmutableList, + rootContent: @Composable BoxScope.() -> Unit, + itemContent: @Composable BoxScope.(T) -> Unit, + modifier: Modifier = Modifier, + itemPadding: PaddingValues = PaddingValues(all = TangemTheme.dimens.spacing0), +) { + Column( + modifier = modifier.fillMaxWidth(), + horizontalAlignment = Alignment.CenterHorizontally, + ) { + Box( + modifier = Modifier.fillMaxWidth(), + contentAlignment = Alignment.CenterStart, + content = rootContent, + ) + + items.forEachIndexed { index, item -> + ArrowRow( + modifier = Modifier.fillMaxWidth(), + content = { itemContent(item) }, + contentPadding = itemPadding, + isLastItem = index == items.size - 1, + ) + } + } +} \ No newline at end of file diff --git a/core/ui/src/main/java/com/tangem/core/ui/components/block/model/BlockUM.kt b/core/ui/src/main/java/com/tangem/core/ui/components/block/model/BlockUM.kt new file mode 100644 index 0000000000..df7e04af33 --- /dev/null +++ b/core/ui/src/main/java/com/tangem/core/ui/components/block/model/BlockUM.kt @@ -0,0 +1,16 @@ +package com.tangem.core.ui.components.block.model + +import androidx.annotation.DrawableRes +import com.tangem.core.ui.extensions.TextReference + +data class BlockUM( + val text: TextReference, + @DrawableRes val iconRes: Int, + val onClick: () -> Unit, + val accentType: AccentType = AccentType.NONE, +) { + + enum class AccentType { + NONE, ACCENT, WARNING, + } +} \ No newline at end of file diff --git a/core/ui/src/main/java/com/tangem/core/ui/components/bottomsheets/TangemBottomSheet.kt b/core/ui/src/main/java/com/tangem/core/ui/components/bottomsheets/TangemBottomSheet.kt index 3f934a0f9b..67466771ba 100644 --- a/core/ui/src/main/java/com/tangem/core/ui/components/bottomsheets/TangemBottomSheet.kt +++ b/core/ui/src/main/java/com/tangem/core/ui/components/bottomsheets/TangemBottomSheet.kt @@ -1,42 +1,98 @@ package com.tangem.core.ui.components.bottomsheets -import androidx.compose.foundation.layout.ColumnScope +import androidx.compose.foundation.layout.* import androidx.compose.material3.ExperimentalMaterial3Api import androidx.compose.material3.ModalBottomSheet import androidx.compose.material3.SheetState +import androidx.compose.material3.SheetValue.Expanded import androidx.compose.material3.rememberModalBottomSheetState import androidx.compose.runtime.* +import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.Color +import androidx.compose.ui.platform.LocalDensity +import com.tangem.core.ui.components.appbar.models.TopAppBarButtonUM +import com.tangem.core.ui.extensions.TextReference +import com.tangem.core.ui.res.LocalBottomSheetAlwaysVisible +import com.tangem.core.ui.res.LocalWindowSize import com.tangem.core.ui.res.TangemTheme +import com.tangem.core.ui.utils.WindowInsetsZero import kotlinx.coroutines.coroutineScope import kotlinx.coroutines.launch /** - * Tangem bottom sheet with custom draggable header and config - * - * @param config data model containing logic and ui models - * @param content custom bottom sheet content + * Bottom sheet with [content], [titleText] and optional [titleAction]. + * */ +@Composable +inline fun TangemBottomSheet( + config: TangemBottomSheetConfig, + titleText: TextReference, + titleAction: TopAppBarButtonUM? = null, + containerColor: Color = TangemTheme.colors.background.primary, + addBottomInsets: Boolean = true, + crossinline content: @Composable ColumnScope.(T) -> Unit, +) { + TangemBottomSheet( + config = config, + containerColor = containerColor, + addBottomInsets = addBottomInsets, + title = { TangemBottomSheetTitle(title = titleText, endButton = titleAction) }, + content = content, + ) +} + +/** + * Bottom sheet with [content] and optional [title]. */ -@OptIn(ExperimentalMaterial3Api::class) @Composable inline fun TangemBottomSheet( config: TangemBottomSheetConfig, containerColor: Color = TangemTheme.colors.background.primary, + addBottomInsets: Boolean = true, + crossinline title: @Composable BoxScope.(T) -> Unit = {}, crossinline content: @Composable ColumnScope.(T) -> Unit, ) { - var isVisible by remember { mutableStateOf(value = config.isShow) } + val isAlwaysVisible = LocalBottomSheetAlwaysVisible.current + if (isAlwaysVisible) { + PreviewBottomSheet( + config = config, + containerColor = containerColor, + addBottomInsets = addBottomInsets, + title = title, + content = content, + ) + } else { + DefaultBottomSheet( + config = config, + containerColor = containerColor, + addBottomInsets = addBottomInsets, + title = title, + content = content, + ) + } +} + +@Composable +@OptIn(ExperimentalMaterial3Api::class) +inline fun DefaultBottomSheet( + config: TangemBottomSheetConfig, + containerColor: Color, + addBottomInsets: Boolean, + crossinline title: @Composable (BoxScope.(T) -> Unit), + crossinline content: @Composable (ColumnScope.(T) -> Unit), +) { + var isVisible by remember { mutableStateOf(value = config.isShow) } val sheetState = rememberModalBottomSheetState(skipPartiallyExpanded = true) + if (isVisible && config.content is T) { - ModalBottomSheet( - onDismissRequest = config.onDismissRequest, + BasicBottomSheet( + config = config, sheetState = sheetState, containerColor = containerColor, - shape = TangemTheme.shapes.bottomSheetLarge, - dragHandle = { TangemBottomSheetDraggableHeader(color = containerColor) }, - ) { - content(config.content) - } + addBottomInsets = addBottomInsets, + title = title, + content = content, + ) } LaunchedEffect(key1 = config.isShow) { @@ -48,6 +104,75 @@ inline fun TangemBottomSheet( } } +@Composable +@OptIn(ExperimentalMaterial3Api::class) +inline fun PreviewBottomSheet( + config: TangemBottomSheetConfig, + containerColor: Color, + addBottomInsets: Boolean, + crossinline title: @Composable (BoxScope.(T) -> Unit), + crossinline content: @Composable (ColumnScope.(T) -> Unit), +) { + BasicBottomSheet( + config = config, + sheetState = SheetState( + skipPartiallyExpanded = true, + initialValue = Expanded, + density = LocalDensity.current, + ), + containerColor = containerColor, + addBottomInsets = addBottomInsets, + title = title, + content = content, + ) +} + +@Suppress("LongParameterList") +@OptIn(ExperimentalMaterial3Api::class) +@Composable +inline fun BasicBottomSheet( + config: TangemBottomSheetConfig, + sheetState: SheetState, + containerColor: Color, + addBottomInsets: Boolean, + crossinline title: @Composable (BoxScope.(T) -> Unit), + crossinline content: @Composable (ColumnScope.(T) -> Unit), +) { + val model = config.content as? T ?: return + + val statusBarHeight = with(LocalDensity.current) { WindowInsets.statusBars.getTop(this).toDp() } + val bottomBarHeight = with(LocalDensity.current) { WindowInsets.systemBars.getBottom(this).toDp() } + + ModalBottomSheet( + // FIXME temporary solution to fix height of the bottom sheet + modifier = Modifier.sizeIn(maxHeight = LocalWindowSize.current.height - statusBarHeight), + onDismissRequest = config.onDismissRequest, + sheetState = sheetState, + containerColor = containerColor, + shape = TangemTheme.shapes.bottomSheetLarge, + windowInsets = WindowInsetsZero, + dragHandle = { TangemBottomSheetDraggableHeader(color = containerColor) }, + ) { + Column( + modifier = Modifier.let { + if (addBottomInsets) { + it.padding(bottom = bottomBarHeight) + } else { + it + } + }, + ) { + Box( + modifier = Modifier.fillMaxWidth(), + ) { + title(model) + } + + content(model) + } + } +} + @OptIn(ExperimentalMaterial3Api::class) suspend fun SheetState.collapse(onCollapsed: () -> Unit) { coroutineScope { diff --git a/core/ui/src/main/java/com/tangem/core/ui/components/bottomsheets/TangemBottomSheetDraggableHeader.kt b/core/ui/src/main/java/com/tangem/core/ui/components/bottomsheets/TangemBottomSheetDraggableHeader.kt index 0d2cbe9d4e..37bff1013a 100644 --- a/core/ui/src/main/java/com/tangem/core/ui/components/bottomsheets/TangemBottomSheetDraggableHeader.kt +++ b/core/ui/src/main/java/com/tangem/core/ui/components/bottomsheets/TangemBottomSheetDraggableHeader.kt @@ -5,7 +5,7 @@ import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.height import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.size -import androidx.compose.material.Surface +import androidx.compose.material3.Surface import androidx.compose.runtime.Composable import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.Color @@ -14,8 +14,7 @@ import com.tangem.core.ui.res.TangemTheme @Composable fun TangemBottomSheetDraggableHeader(color: Color = TangemTheme.colors.background.primary) { Surface( - modifier = Modifier - .height(TangemTheme.dimens.size20), + modifier = Modifier.height(TangemTheme.dimens.size20), color = color, ) { Box( diff --git a/core/ui/src/main/java/com/tangem/core/ui/components/bottomsheets/TangemBottomSheetTitle.kt b/core/ui/src/main/java/com/tangem/core/ui/components/bottomsheets/TangemBottomSheetTitle.kt new file mode 100644 index 0000000000..65e7c87924 --- /dev/null +++ b/core/ui/src/main/java/com/tangem/core/ui/components/bottomsheets/TangemBottomSheetTitle.kt @@ -0,0 +1,68 @@ +package com.tangem.core.ui.components.bottomsheets + +import android.content.res.Configuration +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.tooling.preview.Preview +import com.tangem.core.ui.R +import com.tangem.core.ui.components.appbar.TangemTopAppBar +import com.tangem.core.ui.components.appbar.TangemTopAppBarHeight +import com.tangem.core.ui.components.appbar.models.TopAppBarButtonUM +import com.tangem.core.ui.extensions.TextReference +import com.tangem.core.ui.extensions.resolveReference +import com.tangem.core.ui.res.TangemTheme +import com.tangem.core.ui.res.TangemThemePreview + +@Composable +fun TangemBottomSheetTitle( + title: TextReference?, + modifier: Modifier = Modifier, + endButton: TopAppBarButtonUM? = null, + containerColor: Color = Color.Transparent, +) { + TangemBottomSheetTitle( + modifier = modifier, + title = title?.resolveReference(), + endButton = endButton, + containerColor = containerColor, + ) +} + +@Composable +fun TangemBottomSheetTitle( + title: String?, + modifier: Modifier = Modifier, + endButton: TopAppBarButtonUM? = null, + containerColor: Color = Color.Transparent, +) { + TangemTopAppBar( + modifier = modifier, + title = title, + endButton = endButton, + textColor = TangemTheme.colors.text.primary1, + iconTint = TangemTheme.colors.icon.informative, + titleAlignment = Alignment.CenterHorizontally, + containerColor = containerColor, + height = TangemTopAppBarHeight.BOTTOM_SHEET, + ) +} + +// region Preview +@Composable +@Preview(showBackground = true, widthDp = 360) +@Preview(showBackground = true, widthDp = 360, uiMode = Configuration.UI_MODE_NIGHT_YES) +private fun Preview_TangemBottomSheetTitle() { + TangemThemePreview { + TangemBottomSheetTitle( + title = "Title", + endButton = TopAppBarButtonUM( + iconRes = R.drawable.ic_information_24, + onIconClicked = {}, + ), + containerColor = TangemTheme.colors.background.secondary, + ) + } +} +// endregion Preview \ No newline at end of file diff --git a/core/ui/src/main/java/com/tangem/core/ui/components/buttons/SmallButton.kt b/core/ui/src/main/java/com/tangem/core/ui/components/buttons/SmallButton.kt index 15f640bdbf..e02ae97109 100644 --- a/core/ui/src/main/java/com/tangem/core/ui/components/buttons/SmallButton.kt +++ b/core/ui/src/main/java/com/tangem/core/ui/components/buttons/SmallButton.kt @@ -6,17 +6,21 @@ import androidx.compose.foundation.background import androidx.compose.foundation.clickable import androidx.compose.foundation.layout.* import androidx.compose.foundation.shape.RoundedCornerShape -import androidx.compose.material.Text +import androidx.compose.material3.Icon +import androidx.compose.material3.Text import androidx.compose.runtime.Composable import androidx.compose.runtime.getValue import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.draw.clip +import androidx.compose.ui.res.painterResource import androidx.compose.ui.tooling.preview.Preview +import com.tangem.core.ui.R +import com.tangem.core.ui.components.buttons.common.TangemButtonIconPosition import com.tangem.core.ui.extensions.TextReference import com.tangem.core.ui.extensions.resolveReference -import com.tangem.core.ui.res.TangemThemePreview import com.tangem.core.ui.res.TangemTheme +import com.tangem.core.ui.res.TangemThemePreview /** * Small button config @@ -28,6 +32,7 @@ import com.tangem.core.ui.res.TangemTheme data class SmallButtonConfig( val text: TextReference, val onClick: () -> Unit, + val icon: TangemButtonIconPosition = TangemButtonIconPosition.None, ) /** @@ -61,13 +66,12 @@ private fun SmallButton(config: SmallButtonConfig, isPrimary: Boolean, modifier: label = "Update background color", ) - val textColor by animateColorAsState( - targetValue = if (isPrimary) TangemTheme.colors.text.primary2 else TangemTheme.colors.text.primary1, - label = "Update text color", - ) - Box( + Row( modifier = modifier - .defaultMinSize(minWidth = TangemTheme.dimens.size46, minHeight = TangemTheme.dimens.size24) + .defaultMinSize( + minWidth = TangemTheme.dimens.size46, + minHeight = TangemTheme.dimens.size24, + ) .clip(shape) .background( color = backgroundColor, @@ -75,22 +79,68 @@ private fun SmallButton(config: SmallButtonConfig, isPrimary: Boolean, modifier: ) .clickable(enabled = true, onClick = config.onClick) .padding( - vertical = TangemTheme.dimens.spacing2, + paddingValues = when (config.icon) { + is TangemButtonIconPosition.None -> PaddingValues( + horizontal = TangemTheme.dimens.spacing12, + ) + is TangemButtonIconPosition.End -> PaddingValues( + start = TangemTheme.dimens.spacing12, + end = TangemTheme.dimens.spacing8, + ) + is TangemButtonIconPosition.Start -> PaddingValues( + start = TangemTheme.dimens.spacing8, + end = TangemTheme.dimens.spacing12, + ) + }, ), - contentAlignment = Alignment.Center, + verticalAlignment = Alignment.CenterVertically, + horizontalArrangement = Arrangement.Center, ) { - Text( - modifier = Modifier.padding( - horizontal = TangemTheme.dimens.spacing10, - ), - text = config.text.resolveReference(), - color = textColor, - maxLines = 1, - style = TangemTheme.typography.button, + ContentContainer( + iconPosition = config.icon, + text = { + val textColor by animateColorAsState( + targetValue = if (isPrimary) TangemTheme.colors.text.primary2 else TangemTheme.colors.text.primary1, + label = "Update text color", + ) + + Text( + modifier = Modifier.padding(vertical = TangemTheme.dimens.spacing4), + text = config.text.resolveReference(), + color = textColor, + maxLines = 1, + style = TangemTheme.typography.button, + ) + }, + icon = { iconResId -> + Icon( + modifier = Modifier.size(TangemTheme.dimens.size16), + painter = painterResource(id = iconResId), + tint = TangemTheme.colors.icon.secondary, + contentDescription = null, + ) + }, ) } } +@Composable +private fun RowScope.ContentContainer( + iconPosition: TangemButtonIconPosition, + text: @Composable RowScope.() -> Unit, + icon: @Composable RowScope.(Int) -> Unit, +) { + if (iconPosition is TangemButtonIconPosition.Start) { + icon(iconPosition.iconResId) + Spacer(modifier = Modifier.requiredWidth(TangemTheme.dimens.spacing4)) + } + text() + if (iconPosition is TangemButtonIconPosition.End) { + Spacer(modifier = Modifier.requiredWidth(TangemTheme.dimens.spacing4)) + icon(iconPosition.iconResId) + } +} + @Preview(showBackground = true) @Preview(showBackground = true, uiMode = Configuration.UI_MODE_NIGHT_YES) @Composable @@ -112,5 +162,17 @@ private fun ButtonsSample() { ) PrimarySmallButton(config = config) SecondarySmallButton(config = config.copy(text = TextReference.Str(value = "Add"))) + SecondarySmallButton( + config = config.copy( + text = TextReference.Str(value = "Rating"), + icon = TangemButtonIconPosition.End(iconResId = R.drawable.ic_chevron_24), + ), + ) + SecondarySmallButton( + config = config.copy( + text = TextReference.Str(value = "Add token"), + icon = TangemButtonIconPosition.Start(iconResId = R.drawable.ic_plus_24), + ), + ) } } \ 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 index 344811dac2..f4235c7619 100644 --- 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 @@ -6,7 +6,7 @@ import androidx.compose.runtime.State import androidx.compose.runtime.rememberUpdatedState import androidx.compose.ui.graphics.Color -class TangemButtonColors( +data class TangemButtonColors( private val backgroundColor: Color, private val contentColor: Color, private val disabledBackgroundColor: Color, diff --git a/core/ui/src/main/java/com/tangem/core/ui/components/buttons/segmentedbutton/SegmentedButton.kt b/core/ui/src/main/java/com/tangem/core/ui/components/buttons/segmentedbutton/SegmentedButton.kt index 0bfeb822a6..c4be2dacd0 100644 --- a/core/ui/src/main/java/com/tangem/core/ui/components/buttons/segmentedbutton/SegmentedButton.kt +++ b/core/ui/src/main/java/com/tangem/core/ui/components/buttons/segmentedbutton/SegmentedButton.kt @@ -4,14 +4,9 @@ import android.content.res.Configuration import androidx.compose.animation.animateColorAsState import androidx.compose.animation.core.Spring import androidx.compose.animation.core.spring -import androidx.compose.foundation.LocalIndication -import androidx.compose.foundation.background -import androidx.compose.foundation.clickable +import androidx.compose.foundation.* import androidx.compose.foundation.interaction.MutableInteractionSource -import androidx.compose.foundation.layout.Arrangement -import androidx.compose.foundation.layout.Box -import androidx.compose.foundation.layout.Row -import androidx.compose.foundation.layout.padding +import androidx.compose.foundation.layout.* import androidx.compose.foundation.shape.RoundedCornerShape import androidx.compose.material3.Text import androidx.compose.runtime.* @@ -21,8 +16,10 @@ import androidx.compose.ui.graphics.Color 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.res.TangemThemePreview +import androidx.compose.ui.unit.dp import com.tangem.core.ui.res.TangemTheme +import com.tangem.core.ui.res.TangemThemePreview +import kotlinx.collections.immutable.ImmutableList import kotlinx.collections.immutable.PersistentList import kotlinx.collections.immutable.persistentListOf @@ -42,7 +39,7 @@ import kotlinx.collections.immutable.persistentListOf */ @Composable inline fun SegmentedButtons( - config: PersistentList, + config: ImmutableList, crossinline onClick: (T) -> Unit, modifier: Modifier = Modifier, color: Color = TangemTheme.colors.background.tertiary, @@ -51,7 +48,7 @@ inline fun SegmentedButtons( showIndication: Boolean = true, initialSelectedItem: T? = null, isEnabled: Boolean = true, - crossinline buttonContent: @Composable (T) -> Unit, + crossinline buttonContent: @Composable BoxScope.(T) -> Unit, ) { if (config.isEmpty() || config.size == 1) return @@ -59,12 +56,14 @@ inline fun SegmentedButtons( val index = if (initialSelectedItem == null) 0 else config.indexOf(initialSelectedItem) mutableIntStateOf(index) } + val shape = RoundedCornerShape(TangemTheme.dimens.radius26) Row( modifier = modifier - .clip(RoundedCornerShape(TangemTheme.dimens.radius26)) + .clip(shape) .background(dividerColor) - .padding(TangemTheme.dimens.spacing1), + .border(BorderStroke(1.dp, dividerColor), shape = shape) + .height(IntrinsicSize.Max), horizontalArrangement = Arrangement.spacedBy(TangemTheme.dimens.spacing1), ) { repeat(config.size) { index -> @@ -97,7 +96,7 @@ inline fun SegmentedButtons( onClick(config[index]) }, ) { - buttonContent.invoke(config[index]) + buttonContent.invoke(this, config[index]) } } } diff --git a/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/ui/common/FooterContainer.kt b/core/ui/src/main/java/com/tangem/core/ui/components/containers/FooterContainer.kt similarity index 92% rename from features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/ui/common/FooterContainer.kt rename to core/ui/src/main/java/com/tangem/core/ui/components/containers/FooterContainer.kt index 26b442e62a..5296313d28 100644 --- a/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/ui/common/FooterContainer.kt +++ b/core/ui/src/main/java/com/tangem/core/ui/components/containers/FooterContainer.kt @@ -1,4 +1,4 @@ -package com.tangem.features.send.impl.presentation.ui.common +package com.tangem.core.ui.components.containers import androidx.compose.animation.AnimatedVisibility import androidx.compose.foundation.layout.Column @@ -18,7 +18,7 @@ import com.tangem.core.ui.res.TangemTheme * @param content field content */ @Composable -internal fun FooterContainer( +fun FooterContainer( modifier: Modifier = Modifier, footer: String? = null, footerTopPadding: Dp = TangemTheme.dimens.spacing8, diff --git a/core/ui/src/main/java/com/tangem/core/ui/components/currency/DefaultCurrencyIcon.kt b/core/ui/src/main/java/com/tangem/core/ui/components/currency/DefaultCurrencyIcon.kt index 005053e2c8..bc9b5f2707 100644 --- a/core/ui/src/main/java/com/tangem/core/ui/components/currency/DefaultCurrencyIcon.kt +++ b/core/ui/src/main/java/com/tangem/core/ui/components/currency/DefaultCurrencyIcon.kt @@ -13,7 +13,7 @@ import androidx.compose.ui.platform.LocalDensity import androidx.compose.ui.unit.Dp import coil.compose.SubcomposeAsyncImage import coil.request.ImageRequest -import com.tangem.core.ui.components.currency.tokenicon.LoadingIcon +import com.tangem.core.ui.components.currency.icon.LoadingIcon import com.tangem.core.ui.res.TangemTheme import com.tangem.core.ui.utils.ImageBackgroundContrastChecker import kotlinx.coroutines.launch diff --git a/core/ui/src/main/java/com/tangem/core/ui/components/currency/tokenicon/ContentIcon.kt b/core/ui/src/main/java/com/tangem/core/ui/components/currency/icon/ContentIcon.kt similarity index 90% rename from core/ui/src/main/java/com/tangem/core/ui/components/currency/tokenicon/ContentIcon.kt rename to core/ui/src/main/java/com/tangem/core/ui/components/currency/icon/ContentIcon.kt index cdf96d7b53..089d050c7d 100644 --- a/core/ui/src/main/java/com/tangem/core/ui/components/currency/tokenicon/ContentIcon.kt +++ b/core/ui/src/main/java/com/tangem/core/ui/components/currency/icon/ContentIcon.kt @@ -1,4 +1,4 @@ -package com.tangem.core.ui.components.currency.tokenicon +package com.tangem.core.ui.components.currency.icon import androidx.annotation.DrawableRes import androidx.compose.foundation.Image @@ -18,20 +18,20 @@ import com.tangem.core.ui.res.TangemTheme @Composable internal fun ContentIcon( - icon: TokenIconState, + icon: CurrencyIconState, alpha: Float, colorFilter: ColorFilter?, modifier: Modifier = Modifier, ) { when (icon) { - is TokenIconState.CoinIcon -> CoinIcon( + is CurrencyIconState.CoinIcon -> CoinIcon( modifier = modifier, url = icon.url, fallbackResId = icon.fallbackResId, alpha = alpha, colorFilter = colorFilter, ) - is TokenIconState.TokenIcon -> TokenIcon( + is CurrencyIconState.TokenIcon -> TokenIcon( modifier = modifier, url = icon.url, alpha = alpha, @@ -45,20 +45,20 @@ internal fun ContentIcon( ) }, ) - is TokenIconState.CustomTokenIcon -> CustomTokenIcon( + is CurrencyIconState.CustomTokenIcon -> CustomTokenIcon( modifier = modifier, tint = icon.tint, background = icon.background, alpha = alpha, ) - TokenIconState.Loading, - TokenIconState.Locked, + CurrencyIconState.Loading, + CurrencyIconState.Locked, -> Unit } } @Composable -private fun CoinIcon( +fun CoinIcon( url: String?, @DrawableRes fallbackResId: Int, alpha: Float, diff --git a/core/ui/src/main/java/com/tangem/core/ui/components/currency/tokenicon/TokenIcon.kt b/core/ui/src/main/java/com/tangem/core/ui/components/currency/icon/CurrencyIcon.kt similarity index 69% rename from core/ui/src/main/java/com/tangem/core/ui/components/currency/tokenicon/TokenIcon.kt rename to core/ui/src/main/java/com/tangem/core/ui/components/currency/icon/CurrencyIcon.kt index 559bc7bde8..d06e59fc30 100644 --- a/core/ui/src/main/java/com/tangem/core/ui/components/currency/tokenicon/TokenIcon.kt +++ b/core/ui/src/main/java/com/tangem/core/ui/components/currency/icon/CurrencyIcon.kt @@ -1,4 +1,4 @@ -package com.tangem.core.ui.components.currency.tokenicon +package com.tangem.core.ui.components.currency.icon import androidx.compose.foundation.background import androidx.compose.foundation.layout.Box @@ -12,9 +12,7 @@ import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import com.tangem.core.ui.components.CircleShimmer import com.tangem.core.ui.res.TangemTheme -import com.tangem.core.ui.utils.GRAY_SCALE_ALPHA -import com.tangem.core.ui.utils.GrayscaleColorFilter -import com.tangem.core.ui.utils.NORMAL_ALPHA +import com.tangem.core.ui.utils.getGreyScaleColorFilter /** * Cryptocurrency icon with network badge @@ -26,23 +24,23 @@ import com.tangem.core.ui.utils.NORMAL_ALPHA * @param shouldDisplayNetwork specifies whether to display network badge */ @Composable -fun TokenIcon(state: TokenIconState, modifier: Modifier = Modifier, shouldDisplayNetwork: Boolean = true) { +fun CurrencyIcon(state: CurrencyIconState, modifier: Modifier = Modifier, shouldDisplayNetwork: Boolean = true) { BaseContainer(modifier = modifier) { val iconModifier = Modifier .align(Alignment.Center) .size(TangemTheme.dimens.size36) when (state) { - is TokenIconState.Loading -> LoadingIcon(modifier = iconModifier) - is TokenIconState.Locked -> LockedIcon(modifier = iconModifier) - is TokenIconState.CoinIcon, - is TokenIconState.CustomTokenIcon, - is TokenIconState.TokenIcon, + is CurrencyIconState.Loading -> LoadingIcon(modifier = iconModifier) + is CurrencyIconState.Locked -> LockedIcon(modifier = iconModifier) + is CurrencyIconState.CoinIcon, + is CurrencyIconState.CustomTokenIcon, + is CurrencyIconState.TokenIcon, -> { ContentIconContainer( icon = state, modifier = iconModifier, - shouldDisplayNetwork = shouldDisplayNetwork, + shouldShowTopBadge = shouldDisplayNetwork, ) } } @@ -70,17 +68,13 @@ private fun LockedIcon(modifier: Modifier = Modifier) { @Composable private fun BoxScope.ContentIconContainer( - icon: TokenIconState, + icon: CurrencyIconState, + shouldShowTopBadge: Boolean, modifier: Modifier = Modifier, - shouldDisplayNetwork: Boolean = true, ) { val networkBadgeOffset = TangemTheme.dimens.spacing4 val (alpha, colorFilter) = remember(icon.isGrayscale) { - if (icon.isGrayscale) { - GRAY_SCALE_ALPHA to GrayscaleColorFilter - } else { - NORMAL_ALPHA to null - } + getGreyScaleColorFilter(icon.isGrayscale) } ContentIcon( @@ -90,19 +84,21 @@ private fun BoxScope.ContentIconContainer( colorFilter = colorFilter, ) - if (icon.networkBadgeIconResId != null && shouldDisplayNetwork) { - NetworkBadge( + if (icon.topBadgeIconResId != null && shouldShowTopBadge) { + TopBadge( modifier = Modifier .offset(x = networkBadgeOffset, y = -networkBadgeOffset) .align(Alignment.TopEnd), - iconResId = requireNotNull(icon.networkBadgeIconResId), + iconResId = requireNotNull(icon.topBadgeIconResId), alpha = alpha, colorFilter = colorFilter, ) } if (icon.showCustomBadge) { - CustomBadge(modifier = Modifier.align(Alignment.BottomEnd)) + BottomBadge( + modifier = Modifier.align(Alignment.BottomEnd), + ) } } diff --git a/core/ui/src/main/java/com/tangem/core/ui/components/currency/tokenicon/TokenIconState.kt b/core/ui/src/main/java/com/tangem/core/ui/components/currency/icon/CurrencyIconState.kt similarity index 75% rename from core/ui/src/main/java/com/tangem/core/ui/components/currency/tokenicon/TokenIconState.kt rename to core/ui/src/main/java/com/tangem/core/ui/components/currency/icon/CurrencyIconState.kt index 0f7ff350de..85e49532fc 100644 --- a/core/ui/src/main/java/com/tangem/core/ui/components/currency/tokenicon/TokenIconState.kt +++ b/core/ui/src/main/java/com/tangem/core/ui/components/currency/icon/CurrencyIconState.kt @@ -1,4 +1,4 @@ -package com.tangem.core.ui.components.currency.tokenicon +package com.tangem.core.ui.components.currency.icon import androidx.annotation.DrawableRes import androidx.compose.runtime.Immutable @@ -10,11 +10,11 @@ import androidx.compose.ui.graphics.Color * [REDACTED_TODO_COMMENT] */ @Immutable -sealed class TokenIconState { +sealed class CurrencyIconState { abstract val isGrayscale: Boolean abstract val showCustomBadge: Boolean - abstract val networkBadgeIconResId: Int? + abstract val topBadgeIconResId: Int? /** * Represents a coin icon. @@ -29,16 +29,16 @@ sealed class TokenIconState { @DrawableRes val fallbackResId: Int, override val isGrayscale: Boolean, override val showCustomBadge: Boolean, - ) : TokenIconState() { + ) : CurrencyIconState() { - override val networkBadgeIconResId: Int? = null + override val topBadgeIconResId: Int? = null } /** * Represents a token icon. * * @property url The URL where the token icon can be fetched from. May be `null` if not found. - * @property networkBadgeIconResId The drawable resource ID for the network badge. + * @property topBadgeIconResId The drawable resource ID for the network badge. * @property isGrayscale Specifies whether to show the icon in grayscale. * @property showCustomBadge Specifies whether to show the custom token badge. * @property fallbackTint The color to be used for tinting the fallback icon. @@ -46,39 +46,39 @@ sealed class TokenIconState { */ data class TokenIcon( val url: String?, - @DrawableRes override val networkBadgeIconResId: Int, + @DrawableRes override val topBadgeIconResId: Int, override val isGrayscale: Boolean, override val showCustomBadge: Boolean, val fallbackTint: Color, val fallbackBackground: Color, - ) : TokenIconState() + ) : CurrencyIconState() /** * Represents a custom token icon. * * @property tint The color to be used for tinting the icon. * @property background The background color to be used for the icon. - * @property networkBadgeIconResId The drawable resource ID for the network badge. + * @property topBadgeIconResId The drawable resource ID for the network badge. * @property isGrayscale Specifies whether to show the icon in grayscale. * @property showCustomBadge Specifies whether to show the custom token badge. */ data class CustomTokenIcon( val tint: Color, val background: Color, - @DrawableRes override val networkBadgeIconResId: Int, + @DrawableRes override val topBadgeIconResId: Int, override val isGrayscale: Boolean, override val showCustomBadge: Boolean = true, - ) : TokenIconState() + ) : CurrencyIconState() - data object Loading : TokenIconState() { + data object Loading : CurrencyIconState() { override val isGrayscale: Boolean = false override val showCustomBadge: Boolean = false - override val networkBadgeIconResId: Int? = null + override val topBadgeIconResId: Int? = null } - data object Locked : TokenIconState() { + data object Locked : CurrencyIconState() { override val isGrayscale: Boolean = false override val showCustomBadge: Boolean = false - override val networkBadgeIconResId: Int? = null + override val topBadgeIconResId: Int? = null } } \ No newline at end of file diff --git a/core/ui/src/main/java/com/tangem/core/ui/components/currency/tokenicon/IconBadge.kt b/core/ui/src/main/java/com/tangem/core/ui/components/currency/icon/IconBadge.kt similarity index 92% rename from core/ui/src/main/java/com/tangem/core/ui/components/currency/tokenicon/IconBadge.kt rename to core/ui/src/main/java/com/tangem/core/ui/components/currency/icon/IconBadge.kt index e21ce3274c..09e597f7a6 100644 --- a/core/ui/src/main/java/com/tangem/core/ui/components/currency/tokenicon/IconBadge.kt +++ b/core/ui/src/main/java/com/tangem/core/ui/components/currency/icon/IconBadge.kt @@ -1,4 +1,4 @@ -package com.tangem.core.ui.components.currency.tokenicon +package com.tangem.core.ui.components.currency.icon import androidx.annotation.DrawableRes import androidx.compose.foundation.Image @@ -14,7 +14,7 @@ import androidx.compose.ui.res.painterResource import com.tangem.core.ui.res.TangemTheme @Composable -internal fun NetworkBadge( +internal fun TopBadge( @DrawableRes iconResId: Int, alpha: Float, colorFilter: ColorFilter?, @@ -41,7 +41,7 @@ internal fun NetworkBadge( } @Composable -internal fun CustomBadge(modifier: Modifier = Modifier) { +internal fun BottomBadge(modifier: Modifier = Modifier) { Box( modifier = modifier .size(TangemTheme.dimens.size12) diff --git a/core/ui/src/main/java/com/tangem/core/ui/components/currency/tokenicon/converter/CryptoCurrencyToIconStateConverter.kt b/core/ui/src/main/java/com/tangem/core/ui/components/currency/icon/converter/CryptoCurrencyToIconStateConverter.kt similarity index 81% rename from core/ui/src/main/java/com/tangem/core/ui/components/currency/tokenicon/converter/CryptoCurrencyToIconStateConverter.kt rename to core/ui/src/main/java/com/tangem/core/ui/components/currency/icon/converter/CryptoCurrencyToIconStateConverter.kt index 3e62e98992..c331fc8a1d 100644 --- a/core/ui/src/main/java/com/tangem/core/ui/components/currency/tokenicon/converter/CryptoCurrencyToIconStateConverter.kt +++ b/core/ui/src/main/java/com/tangem/core/ui/components/currency/icon/converter/CryptoCurrencyToIconStateConverter.kt @@ -1,6 +1,6 @@ -package com.tangem.core.ui.components.currency.tokenicon.converter +package com.tangem.core.ui.components.currency.icon.converter -import com.tangem.core.ui.components.currency.tokenicon.TokenIconState +import com.tangem.core.ui.components.currency.icon.CurrencyIconState import com.tangem.core.ui.extensions.getTintForTokenIcon import com.tangem.core.ui.extensions.networkIconResId import com.tangem.core.ui.extensions.tryGetBackgroundForTokenIcon @@ -9,11 +9,11 @@ import com.tangem.domain.tokens.model.CryptoCurrencyStatus import com.tangem.utils.converter.Converter /** - * Converts [CryptoCurrencyStatus] to [TokenIconState] + * Converts [CryptoCurrencyStatus] to [CurrencyIconState] */ -class CryptoCurrencyToIconStateConverter : Converter { +class CryptoCurrencyToIconStateConverter : Converter { - override fun convert(value: CryptoCurrencyStatus): TokenIconState { + override fun convert(value: CryptoCurrencyStatus): CurrencyIconState { return when (val currency = value.currency) { is CryptoCurrency.Coin -> getIconStateForCoin(currency, value.value.isError) is CryptoCurrency.Token -> getIconStateForToken(currency, value.value.isError) @@ -24,7 +24,7 @@ class CryptoCurrencyToIconStateConverter : Converter getIconStateForCoin( coin = currency, @@ -41,7 +41,7 @@ class CryptoCurrencyToIconStateConverter : Converter getIconStateForCoin(currency, isUnreachable = false) is CryptoCurrency.Token -> getIconStateForToken(currency, isErrorStatus = false) @@ -53,8 +53,8 @@ class CryptoCurrencyToIconStateConverter : Converter + DecorationBox( + state = state, + innerTextField = innerTextField, + interactionSource = interactionSource, + colors = colors, + focusManager = focusManager, + keyboardController = keyboardController, + ) + }, + ) +} + +@Suppress("LongParameterList") +@Composable +@OptIn(ExperimentalMaterial3Api::class) +private fun DecorationBox( + state: SearchBarUM, + innerTextField: @Composable () -> Unit, + interactionSource: MutableInteractionSource, + colors: TextFieldColors, + focusManager: FocusManager, + keyboardController: SoftwareKeyboardController?, +) { + TextFieldDefaults.DecorationBox( + value = state.query, + innerTextField = innerTextField, + enabled = true, + singleLine = true, + visualTransformation = VisualTransformation.None, + interactionSource = interactionSource, + shape = TangemTheme.shapes.roundedCornersXLarge, + colors = colors, + contentPadding = PaddingValues(all = TangemTheme.dimens.spacing12), + leadingIcon = { + Icon( + modifier = Modifier.size(TangemTheme.dimens.size20), + painter = painterResource(id = R.drawable.ic_search_24), + tint = TangemTheme.colors.icon.informative, + contentDescription = null, + ) + }, + trailingIcon = { + ClearButton( + state = state, + focusManager = focusManager, + keyboardController = keyboardController, + ) + }, + placeholder = { + Text( + text = state.placeholderText.resolveReference(), + color = TangemTheme.colors.text.tertiary, + style = TangemTheme.typography.body2, + maxLines = 1, + overflow = TextOverflow.Ellipsis, + ) + }, + ) +} + +@Composable +private fun ClearButton( + state: SearchBarUM, + focusManager: FocusManager, + keyboardController: SoftwareKeyboardController?, + modifier: Modifier = Modifier, +) { + if (state.query.isNotEmpty() || state.isActive) { + IconButton( + modifier = modifier, + onClick = { + if (state.query.isNotEmpty()) { + state.onQueryChange("") + } + focusManager.clearFocus() + keyboardController?.hide() + state.onActiveChange(false) + }, + ) { + Icon( + modifier = Modifier.size(TangemTheme.dimens.size20), + painter = painterResource(id = R.drawable.ic_close_24), + tint = TangemTheme.colors.icon.informative, + contentDescription = null, + ) + } + } +} + +private val TangemSearchBarColors: TextFieldColors + @Composable + get() = TextFieldDefaults.colors().copy( + focusedContainerColor = TangemTheme.colors.field.primary, + unfocusedContainerColor = TangemTheme.colors.field.primary, + focusedTextColor = TangemTheme.colors.text.primary1, + unfocusedTextColor = TangemTheme.colors.text.primary1, + cursorColor = TangemTheme.colors.icon.primary1, + focusedIndicatorColor = Color.Transparent, + unfocusedIndicatorColor = Color.Transparent, + disabledIndicatorColor = Color.Transparent, + ) + +// region Previews +@Preview(widthDp = 328) +@Preview(widthDp = 328, uiMode = Configuration.UI_MODE_NIGHT_YES) +@Composable +private fun Preview_TokensSearchBar(@PreviewParameter(SearchBarkConfigProvider::class) state: SearchBarUM) { + TangemThemePreview { + SearchBar(state) + } +} + +private class SearchBarkConfigProvider : CollectionPreviewParameterProvider( + collection = listOf( + SearchBarUM( + placeholderText = resourceReference(R.string.manage_tokens_search_placeholder), + query = "BTC", + onQueryChange = {}, + isActive = true, + onActiveChange = {}, + ), + SearchBarUM( + placeholderText = resourceReference(R.string.manage_tokens_search_placeholder), + query = "", + onQueryChange = {}, + isActive = false, + onActiveChange = {}, + ), + ), +) +// endregion \ No newline at end of file diff --git a/core/ui/src/main/java/com/tangem/core/ui/components/fields/entity/SearchBarUM.kt b/core/ui/src/main/java/com/tangem/core/ui/components/fields/entity/SearchBarUM.kt new file mode 100644 index 0000000000..d2ac8fcc8b --- /dev/null +++ b/core/ui/src/main/java/com/tangem/core/ui/components/fields/entity/SearchBarUM.kt @@ -0,0 +1,11 @@ +package com.tangem.core.ui.components.fields.entity + +import com.tangem.core.ui.extensions.TextReference + +data class SearchBarUM( + val placeholderText: TextReference, + val query: String, + val onQueryChange: (String) -> Unit, + val isActive: Boolean, + val onActiveChange: (Boolean) -> Unit, +) \ No newline at end of file diff --git a/core/ui/src/main/java/com/tangem/core/ui/components/inputrow/InputRowApprox.kt b/core/ui/src/main/java/com/tangem/core/ui/components/inputrow/InputRowApprox.kt index 2bd8311866..4a2a746428 100644 --- a/core/ui/src/main/java/com/tangem/core/ui/components/inputrow/InputRowApprox.kt +++ b/core/ui/src/main/java/com/tangem/core/ui/components/inputrow/InputRowApprox.kt @@ -12,13 +12,13 @@ import androidx.compose.ui.tooling.preview.Preview import com.tangem.core.ui.R import com.tangem.core.ui.components.atoms.text.EllipsisText import com.tangem.core.ui.components.atoms.text.TextEllipsis -import com.tangem.core.ui.components.currency.tokenicon.TokenIcon -import com.tangem.core.ui.components.currency.tokenicon.TokenIconState +import com.tangem.core.ui.components.currency.icon.CurrencyIcon +import com.tangem.core.ui.components.currency.icon.CurrencyIconState import com.tangem.core.ui.components.inputrow.inner.DividerContainer import com.tangem.core.ui.extensions.TextReference import com.tangem.core.ui.extensions.resolveReference -import com.tangem.core.ui.res.TangemThemePreview import com.tangem.core.ui.res.TangemTheme +import com.tangem.core.ui.res.TangemThemePreview /** * [Input Row Approx](https://www.figma.com/file/14ISV23YB1yVW1uNVwqrKv/Android?type=design&node-id=2207-810&mode=design&t=fM1ZU6zQF6g3CaTv-4) @@ -35,10 +35,10 @@ import com.tangem.core.ui.res.TangemTheme @Suppress("LongParameterList") @Composable fun InputRowApprox( - leftIcon: TokenIconState, + leftIcon: CurrencyIconState, leftTitle: TextReference, leftSubtitle: TextReference, - rightIcon: TokenIconState, + rightIcon: CurrencyIconState, rightTitle: TextReference, rightSubtitle: TextReference, modifier: Modifier = Modifier, @@ -86,7 +86,7 @@ fun InputRowApprox( @Composable private fun InputRowApproxItem( - iconState: TokenIconState, + iconState: CurrencyIconState, title: TextReference, subtitle: TextReference, modifier: Modifier = Modifier, @@ -95,7 +95,7 @@ private fun InputRowApproxItem( Row( modifier = modifier, ) { - TokenIcon( + CurrencyIcon( state = iconState, modifier = Modifier .size(TangemTheme.dimens.size36), @@ -131,11 +131,11 @@ private fun InputRowApproxPreview() { TangemThemePreview { Column { InputRowApprox( - leftIcon = TokenIconState.Loading, + leftIcon = CurrencyIconState.Loading, leftTitle = TextReference.Str("Left title USD"), leftSubtitle = TextReference.Str("Left subtitle USD"), leftTitleEllipsisOffset = 3, - rightIcon = TokenIconState.Loading, + rightIcon = CurrencyIconState.Loading, rightTitle = TextReference.Str("Right title Right title Right title Right title Right title USD"), rightSubtitle = TextReference.Str("Right subtitle Right subtitle Right subtitle USD"), rightTitleEllipsisOffset = 3, @@ -143,11 +143,11 @@ private fun InputRowApproxPreview() { .background(TangemTheme.colors.background.action), ) InputRowApprox( - leftIcon = TokenIconState.Loading, + leftIcon = CurrencyIconState.Loading, leftTitle = TextReference.Str("Left title Left title Left title Left title Left title USD"), leftSubtitle = TextReference.Str("Left subtitle Left subtitle Left subtitle USD"), leftTitleEllipsisOffset = 3, - rightIcon = TokenIconState.Loading, + rightIcon = CurrencyIconState.Loading, rightTitle = TextReference.Str("Right title USD"), rightSubtitle = TextReference.Str("Right subtitle USD"), rightTitleEllipsisOffset = 3, diff --git a/core/ui/src/main/java/com/tangem/core/ui/components/inputrow/InputRowBestRate.kt b/core/ui/src/main/java/com/tangem/core/ui/components/inputrow/InputRowBestRate.kt index 3f711de362..0a17c85b13 100644 --- a/core/ui/src/main/java/com/tangem/core/ui/components/inputrow/InputRowBestRate.kt +++ b/core/ui/src/main/java/com/tangem/core/ui/components/inputrow/InputRowBestRate.kt @@ -5,7 +5,6 @@ import androidx.compose.foundation.background import androidx.compose.foundation.clickable import androidx.compose.foundation.interaction.MutableInteractionSource import androidx.compose.foundation.layout.* -import androidx.compose.foundation.shape.CircleShape import androidx.compose.foundation.shape.RoundedCornerShape import androidx.compose.material.ripple.rememberRipple import androidx.compose.material3.Icon @@ -14,18 +13,15 @@ import androidx.compose.runtime.Composable import androidx.compose.runtime.remember import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier -import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.res.painterResource import androidx.compose.ui.res.stringResource import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.tooling.preview.PreviewParameter import androidx.compose.ui.tooling.preview.PreviewParameterProvider -import coil.compose.SubcomposeAsyncImage -import coil.request.ImageRequest import com.tangem.core.ui.R import com.tangem.core.ui.components.SpacerWMax -import com.tangem.core.ui.components.currency.tokenicon.LoadingIcon import com.tangem.core.ui.components.inputrow.inner.DividerContainer +import com.tangem.core.ui.components.inputrow.inner.InputRowAsyncImage import com.tangem.core.ui.extensions.TextReference import com.tangem.core.ui.extensions.resolveReference import com.tangem.core.ui.res.TangemThemePreview @@ -63,7 +59,7 @@ fun InputRowBestRate( modifier = Modifier .padding(TangemTheme.dimens.spacing12), ) { - InnerIcon(imageUrl = imageUrl) + InputRowAsyncImage(imageUrl = imageUrl, modifier = Modifier.size(TangemTheme.dimens.spacing40)) Column( modifier = Modifier .padding(start = TangemTheme.dimens.spacing12), @@ -131,29 +127,6 @@ private fun InnerTitle(title: TextReference, titleExtra: TextReference, showTag: } } -@Composable -private fun InnerIcon(imageUrl: String) { - SubcomposeAsyncImage( - modifier = Modifier.size(TangemTheme.dimens.size40), - model = ImageRequest.Builder(context = LocalContext.current) - .data(imageUrl) - .crossfade(enable = true) - .allowHardware(enable = false) - .build(), - loading = { LoadingIcon() }, - error = { - Box( - modifier = Modifier - .background( - color = TangemTheme.colors.background.tertiary, - shape = CircleShape, - ), - ) - }, - contentDescription = null, - ) -} - //region preview @Preview @Preview(uiMode = Configuration.UI_MODE_NIGHT_YES) diff --git a/core/ui/src/main/java/com/tangem/core/ui/components/inputrow/InputRowChecked.kt b/core/ui/src/main/java/com/tangem/core/ui/components/inputrow/InputRowChecked.kt new file mode 100644 index 0000000000..ca8da83f36 --- /dev/null +++ b/core/ui/src/main/java/com/tangem/core/ui/components/inputrow/InputRowChecked.kt @@ -0,0 +1,74 @@ +package com.tangem.core.ui.components.inputrow + +import android.content.res.Configuration +import androidx.compose.animation.AnimatedVisibility +import androidx.compose.foundation.background +import androidx.compose.foundation.layout.* +import androidx.compose.material3.Icon +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.vector.ImageVector +import androidx.compose.ui.graphics.vector.rememberVectorPainter +import androidx.compose.ui.res.vectorResource +import androidx.compose.ui.text.style.TextOverflow +import androidx.compose.ui.tooling.preview.Preview +import androidx.compose.ui.unit.dp +import com.tangem.core.ui.R +import com.tangem.core.ui.extensions.TextReference +import com.tangem.core.ui.extensions.resolveReference +import com.tangem.core.ui.extensions.stringReference +import com.tangem.core.ui.res.TangemTheme +import com.tangem.core.ui.res.TangemThemePreview + +@Composable +fun InputRowChecked(text: TextReference, checked: Boolean, modifier: Modifier = Modifier) { + Row( + modifier = modifier.padding(TangemTheme.dimens.spacing12), + horizontalArrangement = Arrangement.SpaceBetween, + verticalAlignment = Alignment.CenterVertically, + ) { + Text( + modifier = Modifier.weight(1f), + text = text.resolveReference(), + style = TangemTheme.typography.body2, + color = TangemTheme.colors.text.primary1, + maxLines = 1, + overflow = TextOverflow.Ellipsis, + ) + AnimatedVisibility( + modifier = Modifier, + visible = checked, + ) { + Icon( + painter = rememberVectorPainter(image = ImageVector.vectorResource(id = R.drawable.ic_check_24)), + tint = TangemTheme.colors.icon.accent, + contentDescription = null, + ) + } + if (checked.not()) { + Box(Modifier.height(TangemTheme.dimens.size24)) + } + } +} + +@Preview +@Preview(uiMode = Configuration.UI_MODE_NIGHT_YES) +@Composable +private fun Preview() { + TangemThemePreview { + Column(Modifier.background(TangemTheme.colors.background.primary)) { + InputRowChecked( + text = stringReference("Title Title Title Title Title Title Title Title Title"), + checked = false, + modifier = Modifier.width(300.dp), + ) + InputRowChecked( + text = stringReference("Title Title Title Title Title Title Title Title Title"), + checked = true, + modifier = Modifier.width(300.dp), + ) + } + } +} \ No newline at end of file diff --git a/core/ui/src/main/java/com/tangem/core/ui/components/inputrow/InputRowDefault.kt b/core/ui/src/main/java/com/tangem/core/ui/components/inputrow/InputRowDefault.kt index 4222d238c0..1eff068d9f 100644 --- a/core/ui/src/main/java/com/tangem/core/ui/components/inputrow/InputRowDefault.kt +++ b/core/ui/src/main/java/com/tangem/core/ui/components/inputrow/InputRowDefault.kt @@ -4,12 +4,16 @@ import android.content.res.Configuration import androidx.compose.foundation.background import androidx.compose.foundation.clickable import androidx.compose.foundation.interaction.MutableInteractionSource -import androidx.compose.foundation.layout.* +import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.Row +import androidx.compose.foundation.layout.fillMaxWidth +import androidx.compose.foundation.layout.padding import androidx.compose.material.ripple.rememberRipple import androidx.compose.material3.Icon import androidx.compose.material3.Text import androidx.compose.runtime.Composable import androidx.compose.runtime.remember +import androidx.compose.ui.Alignment.Companion.CenterVertically import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.Color import androidx.compose.ui.res.painterResource @@ -20,8 +24,8 @@ import com.tangem.core.ui.R import com.tangem.core.ui.components.inputrow.inner.DividerContainer import com.tangem.core.ui.extensions.TextReference import com.tangem.core.ui.extensions.resolveReference -import com.tangem.core.ui.res.TangemThemePreview import com.tangem.core.ui.res.TangemTheme +import com.tangem.core.ui.res.TangemThemePreview /** * [InputRowDefault](https://www.figma.com/file/14ISV23YB1yVW1uNVwqrKv/Android?type=design&node-id=2100-807&mode=design&t=86eKp9izWxUvmoCq-4) @@ -64,7 +68,7 @@ fun InputRowDefault( ) { Text( text = title.resolveReference(), - style = TangemTheme.typography.caption2, + style = TangemTheme.typography.subtitle2, color = titleColor, ) Text( @@ -80,11 +84,13 @@ fun InputRowDefault( contentDescription = null, tint = iconTint, modifier = Modifier + .align(CenterVertically) .padding( top = TangemTheme.dimens.spacing10, bottom = TangemTheme.dimens.spacing10, ) .clickable( + enabled = onIconClick != null, interactionSource = remember { MutableInteractionSource() }, indication = rememberRipple(bounded = false), ) { onIconClick?.invoke() }, diff --git a/core/ui/src/main/java/com/tangem/core/ui/components/inputrow/InputRowImage.kt b/core/ui/src/main/java/com/tangem/core/ui/components/inputrow/InputRowImage.kt index 35ba18ad8a..58a61bb00e 100644 --- a/core/ui/src/main/java/com/tangem/core/ui/components/inputrow/InputRowImage.kt +++ b/core/ui/src/main/java/com/tangem/core/ui/components/inputrow/InputRowImage.kt @@ -18,13 +18,13 @@ import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.tooling.preview.PreviewParameter import androidx.compose.ui.tooling.preview.PreviewParameterProvider import com.tangem.core.ui.R +import com.tangem.core.ui.components.currency.icon.CurrencyIcon +import com.tangem.core.ui.components.currency.icon.CurrencyIconState import com.tangem.core.ui.components.inputrow.inner.DividerContainer -import com.tangem.core.ui.components.currency.tokenicon.TokenIcon -import com.tangem.core.ui.components.currency.tokenicon.TokenIconState import com.tangem.core.ui.extensions.TextReference import com.tangem.core.ui.extensions.resolveReference -import com.tangem.core.ui.res.TangemThemePreview import com.tangem.core.ui.res.TangemTheme +import com.tangem.core.ui.res.TangemThemePreview /** * [Input Row Image](https://www.figma.com/file/14ISV23YB1yVW1uNVwqrKv/Android?type=design&node-id=2100-813&mode=design&t=IQ5lBJEkFGU4WSvi-4) @@ -32,7 +32,7 @@ import com.tangem.core.ui.res.TangemTheme * @param title title reference * @param subtitle subtitle reference * @param caption caption reference - * @param tokenIconState token icon state [TokenIconState] + * @param tokenIconState token icon state [CurrencyIconState] * @param modifier modifier * @param titleColor title color * @param subtitleColor subtitle color @@ -48,7 +48,7 @@ fun InputRowImage( title: TextReference, subtitle: TextReference, caption: TextReference, - tokenIconState: TokenIconState, + tokenIconState: CurrencyIconState, modifier: Modifier = Modifier, titleColor: Color = TangemTheme.colors.text.secondary, subtitleColor: Color = TangemTheme.colors.text.primary1, @@ -79,7 +79,7 @@ fun InputRowImage( top = TangemTheme.dimens.spacing6, ), ) { - TokenIcon( + CurrencyIcon( state = tokenIconState, shouldDisplayNetwork = showNetworkIcon, modifier = Modifier @@ -146,7 +146,7 @@ private data class InputRowImagePreviewData( val title: TextReference, val subtitle: TextReference, val caption: TextReference, - val iconState: TokenIconState, + val iconState: CurrencyIconState, val showDivider: Boolean, val actionIconRes: Int?, val showNetworkIcon: Boolean = false, @@ -160,7 +160,7 @@ private class InputRowImagePreviewDataProvider : title = TextReference.Str("title"), subtitle = TextReference.Str("subtitle"), caption = TextReference.Str("caption"), - iconState = TokenIconState.Locked, + iconState = CurrencyIconState.Locked, actionIconRes = null, showDivider = false, showNetworkIcon = false, @@ -169,7 +169,7 @@ private class InputRowImagePreviewDataProvider : title = TextReference.Str("title"), subtitle = TextReference.Str("subtitle"), caption = TextReference.Str("caption"), - iconState = TokenIconState.Locked, + iconState = CurrencyIconState.Locked, actionIconRes = R.drawable.ic_chevron_right_24, showDivider = true, showNetworkIcon = true, diff --git a/core/ui/src/main/java/com/tangem/core/ui/components/inputrow/InputRowImageBase.kt b/core/ui/src/main/java/com/tangem/core/ui/components/inputrow/InputRowImageBase.kt new file mode 100644 index 0000000000..417a7edbec --- /dev/null +++ b/core/ui/src/main/java/com/tangem/core/ui/components/inputrow/InputRowImageBase.kt @@ -0,0 +1,52 @@ +package com.tangem.core.ui.components.inputrow + +import androidx.compose.foundation.layout.* +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 com.tangem.core.ui.components.inputrow.inner.InputRowAsyncImage +import com.tangem.core.ui.extensions.TextReference +import com.tangem.core.ui.extensions.resolveAnnotatedReference +import com.tangem.core.ui.extensions.resolveReference +import com.tangem.core.ui.res.TangemTheme + +@Composable +internal fun InputRowImageBase( + subtitle: TextReference, + caption: TextReference, + imageUrl: String, + modifier: Modifier = Modifier, + subtitleColor: Color = TangemTheme.colors.text.primary1, + captionColor: Color = TangemTheme.colors.text.tertiary, + isGrayscaleImage: Boolean = false, + extraContent: @Composable RowScope.() -> Unit = {}, +) { + Row( + verticalAlignment = Alignment.CenterVertically, + horizontalArrangement = Arrangement.spacedBy(TangemTheme.dimens.spacing12), + modifier = modifier, + ) { + InputRowAsyncImage( + imageUrl = imageUrl, + isGrayscale = isGrayscaleImage, + modifier = Modifier + .size(TangemTheme.dimens.spacing36), + ) + Column { + Text( + text = subtitle.resolveReference(), + style = TangemTheme.typography.subtitle2, + color = subtitleColor, + ) + Text( + text = caption.resolveAnnotatedReference(), + style = TangemTheme.typography.caption2, + color = captionColor, + modifier = Modifier.padding(top = TangemTheme.dimens.spacing2), + ) + } + extraContent() + } +} \ No newline at end of file diff --git a/core/ui/src/main/java/com/tangem/core/ui/components/inputrow/InputRowImageChevron.kt b/core/ui/src/main/java/com/tangem/core/ui/components/inputrow/InputRowImageChevron.kt new file mode 100644 index 0000000000..c341f3ceac --- /dev/null +++ b/core/ui/src/main/java/com/tangem/core/ui/components/inputrow/InputRowImageChevron.kt @@ -0,0 +1,82 @@ +package com.tangem.core.ui.components.inputrow + +import android.content.res.Configuration +import androidx.compose.material3.Icon +import androidx.compose.runtime.Composable +import androidx.compose.ui.Modifier +import androidx.compose.ui.graphics.Color +import androidx.compose.ui.res.painterResource +import androidx.compose.ui.text.SpanStyle +import androidx.compose.ui.text.buildAnnotatedString +import androidx.compose.ui.text.withStyle +import androidx.compose.ui.tooling.preview.Preview +import com.tangem.core.ui.R +import com.tangem.core.ui.components.SpacerWMax +import com.tangem.core.ui.extensions.* +import com.tangem.core.ui.res.TangemTheme +import com.tangem.core.ui.res.TangemThemePreview + +/** + * Input row component with selector + * [Input Row Image](https://www.figma.com/design/14ISV23YB1yVW1uNVwqrKv/Android?node-id=2100-842&t=hoBXmDX8NeLrp4p6-4) + * + * @param subtitle subtitle text + * @param caption caption text + * @param imageUrl icon to load + * @param modifier modifier + * @param subtitleColor subtitle text color + * @param captionColor caption text color + */ +@Composable +fun InputRowImageChevron( + subtitle: TextReference, + caption: TextReference, + imageUrl: String, + modifier: Modifier = Modifier, + subtitleColor: Color = TangemTheme.colors.text.primary1, + captionColor: Color = TangemTheme.colors.text.tertiary, + showChevron: Boolean = true, +) { + InputRowImageBase( + subtitle = subtitle, + caption = caption, + imageUrl = imageUrl, + modifier = modifier, + subtitleColor = subtitleColor, + captionColor = captionColor, + ) { + SpacerWMax() + if (showChevron) { + Icon( + painter = painterResource(id = R.drawable.ic_chevron_right_24), + tint = TangemTheme.colors.icon.informative, + contentDescription = null, + ) + } + } +} + +// region Preview +@Preview(showBackground = true, widthDp = 360) +@Preview(showBackground = true, widthDp = 360, uiMode = Configuration.UI_MODE_NIGHT_YES) +@Composable +private fun InputRowImageChevron_Preview() { + TangemThemePreview { + InputRowImageChevron( + subtitle = stringReference("Binance"), + caption = combinedReference( + resourceReference(R.string.staking_details_apr), + annotatedReference( + buildAnnotatedString { + append(" ") + withStyle(SpanStyle(TangemTheme.colors.text.accent)) { + stringReference("3,54%") + } + }, + ), + ), + imageUrl = "", + ) + } +} +// endregion \ No newline at end of file diff --git a/core/ui/src/main/java/com/tangem/core/ui/components/inputrow/InputRowImageInfo.kt b/core/ui/src/main/java/com/tangem/core/ui/components/inputrow/InputRowImageInfo.kt new file mode 100644 index 0000000000..f9811bbe1a --- /dev/null +++ b/core/ui/src/main/java/com/tangem/core/ui/components/inputrow/InputRowImageInfo.kt @@ -0,0 +1,117 @@ +package com.tangem.core.ui.components.inputrow + +import android.content.res.Configuration +import androidx.compose.foundation.layout.Arrangement +import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.padding +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.text.SpanStyle +import androidx.compose.ui.text.buildAnnotatedString +import androidx.compose.ui.text.withStyle +import androidx.compose.ui.tooling.preview.Preview +import com.tangem.core.ui.R +import com.tangem.core.ui.components.atoms.text.EllipsisText +import com.tangem.core.ui.extensions.* +import com.tangem.core.ui.res.TangemTheme +import com.tangem.core.ui.res.TangemThemePreview + +/** + * Input row component with selector + * [Input Row Image](https://www.figma.com/design/14ISV23YB1yVW1uNVwqrKv/Android?node-id=2841-1589&t=u6pOF6lsdpvWLELb-4) + * + * @param title title text + * @param subtitle subtitle text + * @param caption caption text + * @param infoTitle info title text + * @param infoSubtitle info subtitle text + * @param modifier modifier + * @param imageUrl icon to load + * @param subtitleColor subtitle text color + * @param captionColor caption text color + * @param isGrayscaleImage whether to display grayscale image + */ +@Suppress("LongParameterList") +@Composable +fun InputRowImageInfo( + subtitle: TextReference, + caption: TextReference, + infoTitle: TextReference, + infoSubtitle: TextReference, + imageUrl: String, + modifier: Modifier = Modifier, + title: TextReference? = null, + subtitleColor: Color = TangemTheme.colors.text.primary1, + captionColor: Color = TangemTheme.colors.text.tertiary, + isGrayscaleImage: Boolean = false, +) { + Column( + verticalArrangement = Arrangement.spacedBy(TangemTheme.dimens.spacing6), + modifier = modifier + .padding(TangemTheme.dimens.spacing12), + ) { + if (title != null) { + Text( + text = title.resolveReference(), + style = TangemTheme.typography.subtitle2, + color = TangemTheme.colors.text.tertiary, + ) + } + InputRowImageBase( + subtitle = subtitle, + caption = caption, + imageUrl = imageUrl, + subtitleColor = subtitleColor, + captionColor = captionColor, + isGrayscaleImage = isGrayscaleImage, + ) { + Column( + verticalArrangement = Arrangement.spacedBy(TangemTheme.dimens.spacing2), + horizontalAlignment = Alignment.End, + modifier = Modifier.weight(1f), + ) { + EllipsisText( + text = infoTitle.resolveReference(), + style = TangemTheme.typography.body2, + color = TangemTheme.colors.text.primary1, + ) + EllipsisText( + text = infoSubtitle.resolveReference(), + style = TangemTheme.typography.caption2, + color = TangemTheme.colors.text.tertiary, + ) + } + } + } +} + +// region Preview +@Preview(showBackground = true, widthDp = 360) +@Preview(showBackground = true, widthDp = 360, uiMode = Configuration.UI_MODE_NIGHT_YES) +@Composable +private fun InputRowImageInfo_Preview() { + TangemThemePreview { + InputRowImageInfo( + title = stringReference("Active"), + subtitle = stringReference("Binance"), + caption = combinedReference( + resourceReference(R.string.staking_details_apr), + annotatedReference( + buildAnnotatedString { + append(" ") + withStyle(SpanStyle(TangemTheme.colors.text.accent)) { + stringReference("3,54%") + } + }, + ), + ), + infoTitle = stringReference("5431231231231231231231232 USD"), + infoSubtitle = stringReference("5 SOL"), + imageUrl = "", + ) + } +} +// endregion \ No newline at end of file diff --git a/core/ui/src/main/java/com/tangem/core/ui/components/inputrow/InputRowImageSelector.kt b/core/ui/src/main/java/com/tangem/core/ui/components/inputrow/InputRowImageSelector.kt new file mode 100644 index 0000000000..5231d7f896 --- /dev/null +++ b/core/ui/src/main/java/com/tangem/core/ui/components/inputrow/InputRowImageSelector.kt @@ -0,0 +1,133 @@ +package com.tangem.core.ui.components.inputrow + +import android.content.res.Configuration +import androidx.compose.foundation.background +import androidx.compose.foundation.clickable +import androidx.compose.foundation.interaction.MutableInteractionSource +import androidx.compose.foundation.layout.padding +import androidx.compose.material.ripple.rememberRipple +import androidx.compose.runtime.Composable +import androidx.compose.runtime.remember +import androidx.compose.ui.Modifier +import androidx.compose.ui.graphics.Color +import androidx.compose.ui.text.SpanStyle +import androidx.compose.ui.text.buildAnnotatedString +import androidx.compose.ui.text.withStyle +import androidx.compose.ui.tooling.preview.Preview +import androidx.compose.ui.tooling.preview.PreviewParameter +import androidx.compose.ui.tooling.preview.PreviewParameterProvider +import com.tangem.core.ui.R +import com.tangem.core.ui.components.SpacerWMax +import com.tangem.core.ui.components.atoms.radiobutton.TangemRadioButton +import com.tangem.core.ui.extensions.TextReference +import com.tangem.core.ui.extensions.annotatedReference +import com.tangem.core.ui.extensions.combinedReference +import com.tangem.core.ui.extensions.resourceReference +import com.tangem.core.ui.res.TangemTheme +import com.tangem.core.ui.res.TangemThemePreview +import com.tangem.core.ui.utils.BigDecimalFormatter +import java.math.BigDecimal + +/** + * Input row component with selector + * [Input Row Image](https://www.figma.com/design/14ISV23YB1yVW1uNVwqrKv/Android?node-id=2772-905&t=FH84ljLBk1vmGAei-4) + * + * @param subtitle subtitle text + * @param caption caption text + * @param imageUrl icon to load + * @param onSelect callback when selected + * @param modifier modifier + * @param subtitleColor subtitle text color + * @param captionColor caption text color + * @param isSelected true if selected + */ +@Composable +fun InputRowImageSelector( + subtitle: TextReference, + caption: TextReference, + imageUrl: String, + onSelect: () -> Unit, + modifier: Modifier = Modifier, + subtitleColor: Color = TangemTheme.colors.text.primary1, + captionColor: Color = TangemTheme.colors.text.tertiary, + isSelected: Boolean = false, +) { + InputRowImageBase( + subtitle = subtitle, + caption = caption, + imageUrl = imageUrl, + subtitleColor = subtitleColor, + captionColor = captionColor, + modifier = modifier + .clickable( + onClick = onSelect, + interactionSource = remember { MutableInteractionSource() }, + indication = rememberRipple(), + ) + .padding(TangemTheme.dimens.spacing12), + ) { + SpacerWMax() + TangemRadioButton(isSelected = isSelected, isEnabled = false, onClick = onSelect) + } +} + +//region preview +@Preview(widthDp = 328) +@Preview(widthDp = 328, uiMode = Configuration.UI_MODE_NIGHT_YES) +@Composable +private fun InputRowImageSelectorPreview( + @PreviewParameter(InputRowImageSelectorPreviewDataProvider::class) data: InputRowImageSelectorPreviewData, +) { + TangemThemePreview { + InputRowImageSelector( + modifier = Modifier.background(TangemTheme.colors.background.action), + subtitle = data.subtitle, + caption = combinedReference( + resourceReference(R.string.staking_details_apr), + annotatedReference( + buildAnnotatedString { + append(" ") + withStyle(style = SpanStyle(color = TangemTheme.colors.text.accent)) { + append( + BigDecimalFormatter.formatPercent(BigDecimal.ZERO, true), + ) + } + }, + ), + ), + imageUrl = "", + isSelected = false, + onSelect = {}, + ) + } +} + +private data class InputRowImageSelectorPreviewData( + val subtitle: TextReference, + val caption: TextReference, + val showDivider: Boolean, + val actionIconRes: Int?, + val isSelected: Boolean, +) + +private class InputRowImageSelectorPreviewDataProvider : + PreviewParameterProvider { + override val values: Sequence + get() = sequenceOf( + InputRowImageSelectorPreviewData( + subtitle = TextReference.Str("subtitle"), + caption = TextReference.Str("caption"), + actionIconRes = null, + showDivider = false, + isSelected = false, + ), + InputRowImageSelectorPreviewData( + subtitle = TextReference.Str("subtitle"), + caption = TextReference.Str("caption"), + actionIconRes = R.drawable.ic_chevron_right_24, + showDivider = true, + isSelected = true, + ), + ) +} +//endregion \ No newline at end of file diff --git a/core/ui/src/main/java/com/tangem/core/ui/components/inputrow/inner/DividerContainer.kt b/core/ui/src/main/java/com/tangem/core/ui/components/inputrow/inner/DividerContainer.kt index a5510a378d..434b7751e7 100644 --- a/core/ui/src/main/java/com/tangem/core/ui/components/inputrow/inner/DividerContainer.kt +++ b/core/ui/src/main/java/com/tangem/core/ui/components/inputrow/inner/DividerContainer.kt @@ -3,7 +3,7 @@ package com.tangem.core.ui.components.inputrow.inner import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.PaddingValues import androidx.compose.foundation.layout.padding -import androidx.compose.material3.Divider +import androidx.compose.material3.HorizontalDivider import androidx.compose.runtime.Composable import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier @@ -19,7 +19,7 @@ fun DividerContainer( Box(modifier = modifier) { content() if (showDivider) { - Divider( + HorizontalDivider( modifier = Modifier .align(Alignment.BottomCenter) .padding(paddingValues), diff --git a/core/ui/src/main/java/com/tangem/core/ui/components/inputrow/inner/InputRowAsyncImage.kt b/core/ui/src/main/java/com/tangem/core/ui/components/inputrow/inner/InputRowAsyncImage.kt new file mode 100644 index 0000000000..b85e91ba30 --- /dev/null +++ b/core/ui/src/main/java/com/tangem/core/ui/components/inputrow/inner/InputRowAsyncImage.kt @@ -0,0 +1,46 @@ +package com.tangem.core.ui.components.inputrow.inner + +import androidx.compose.foundation.background +import androidx.compose.foundation.layout.Box +import androidx.compose.foundation.shape.CircleShape +import androidx.compose.runtime.Composable +import androidx.compose.ui.Modifier +import androidx.compose.ui.platform.LocalContext +import coil.compose.SubcomposeAsyncImage +import coil.request.ImageRequest +import com.tangem.core.ui.components.currency.icon.LoadingIcon +import com.tangem.core.ui.res.TangemTheme +import com.tangem.core.ui.utils.getGreyScaleColorFilter + +/** + * Loads image by url for icon in the input row + * + * @param imageUrl url of the image + * @param modifier modifier + * @param isGrayscale whether to apply grayscale filter + */ +@Composable +internal fun InputRowAsyncImage(imageUrl: String, modifier: Modifier = Modifier, isGrayscale: Boolean = false) { + val (alpha, colorFilter) = getGreyScaleColorFilter(isGrayscale = isGrayscale) + SubcomposeAsyncImage( + modifier = modifier, + colorFilter = colorFilter, + alpha = alpha, + model = ImageRequest.Builder(context = LocalContext.current) + .data(imageUrl) + .crossfade(enable = true) + .allowHardware(enable = false) + .build(), + loading = { LoadingIcon() }, + error = { + Box( + modifier = Modifier + .background( + color = TangemTheme.colors.background.tertiary, + shape = CircleShape, + ), + ) + }, + contentDescription = null, + ) +} \ No newline at end of file diff --git a/core/ui/src/main/java/com/tangem/core/ui/components/list/RoundedListWithDividers.kt b/core/ui/src/main/java/com/tangem/core/ui/components/list/RoundedListWithDividers.kt new file mode 100644 index 0000000000..8161f2ff69 --- /dev/null +++ b/core/ui/src/main/java/com/tangem/core/ui/components/list/RoundedListWithDividers.kt @@ -0,0 +1,123 @@ +package com.tangem.core.ui.components.list + +import android.content.res.Configuration +import androidx.compose.foundation.background +import androidx.compose.foundation.layout.* +import androidx.compose.foundation.lazy.LazyColumn +import androidx.compose.foundation.lazy.itemsIndexed +import androidx.compose.runtime.Composable +import androidx.compose.ui.Modifier +import androidx.compose.ui.tooling.preview.Preview +import com.tangem.core.ui.R +import com.tangem.core.ui.components.rows.CornersToRound +import com.tangem.core.ui.components.rows.RoundableCornersRow +import com.tangem.core.ui.extensions.TextReference +import com.tangem.core.ui.extensions.resolveReference +import com.tangem.core.ui.res.TangemTheme +import com.tangem.core.ui.res.TangemThemePreview +import kotlinx.collections.immutable.persistentListOf + +@Composable +fun RoundedListWithDividers(rows: List, modifier: Modifier = Modifier) { + LazyColumn(modifier = modifier) { + itemsIndexed( + items = rows, + key = { _, item -> item.id }, + ) { index, row -> + InitialInfoContentRow( + startText = row.startText.resolveReference(), + endText = row.endText.resolveReference(), + cornersToRound = getCornersToRound(index, rows.size), + iconClick = row.iconClick, + ) + if (index < rows.lastIndex) { + RoundedListDivider() + } + } + } +} + +@Composable +private fun InitialInfoContentRow( + startText: String, + endText: String, + cornersToRound: CornersToRound, + iconClick: (() -> Unit)? = null, +) { + RoundableCornersRow( + startText = startText, + startTextColor = TangemTheme.colors.text.primary1, + startTextStyle = TangemTheme.typography.body2, + endText = endText, + endTextColor = TangemTheme.colors.text.tertiary, + endTextStyle = TangemTheme.typography.body2, + cornersToRound = cornersToRound, + iconResId = R.drawable.ic_information_24, + iconClick = iconClick, + ) +} + +@Composable +fun RoundedListDivider() { + Row( + modifier = Modifier + .fillMaxWidth() + .height(TangemTheme.dimens.size0_5), + ) { + Box( + modifier = Modifier + .width(TangemTheme.dimens.size16) + .height(TangemTheme.dimens.size0_5) + .background(TangemTheme.colors.background.primary), + ) + Box( + modifier = Modifier + .weight(1f) + .height(TangemTheme.dimens.size0_5) + .background(TangemTheme.colors.background.tertiary), + ) + } +} + +private fun getCornersToRound(currentIndex: Int, listSize: Int): CornersToRound { + return when (currentIndex) { + 0 -> CornersToRound.TOP_2 + listSize - 1 -> CornersToRound.BOTTOM_2 + else -> CornersToRound.ZERO + } +} + +data class RoundedListWithDividersItemData( + val id: Int, + val startText: TextReference, + val endText: TextReference, + val iconClick: (() -> Unit)? = null, +) + +@Composable +@Preview(showBackground = true) +@Preview(showBackground = true, uiMode = Configuration.UI_MODE_NIGHT_YES) +private fun Preview_StakingInfoBottomSheet() { + TangemThemePreview { + RoundedListWithDividers( + rows = persistentListOf( + RoundedListWithDividersItemData( + id = 1, + startText = TextReference.Str("Key 1"), + endText = TextReference.Str("Value 1"), + ), + RoundedListWithDividersItemData( + id = 2, + startText = TextReference.Str("Key 2"), + endText = TextReference.Str("Value 2"), + ), + RoundedListWithDividersItemData( + id = 3, + startText = TextReference.Str("Key 3"), + endText = TextReference.Str("Value 3"), + iconClick = {}, + ), + ), + ) + } +} \ No newline at end of file diff --git a/core/ui/src/main/java/com/tangem/core/ui/components/marketprice/MarketPriceBlock.kt b/core/ui/src/main/java/com/tangem/core/ui/components/marketprice/MarketPriceBlock.kt index 606416093a..8ef37d1f7c 100644 --- a/core/ui/src/main/java/com/tangem/core/ui/components/marketprice/MarketPriceBlock.kt +++ b/core/ui/src/main/java/com/tangem/core/ui/components/marketprice/MarketPriceBlock.kt @@ -4,14 +4,12 @@ import android.content.res.Configuration import androidx.compose.animation.AnimatedContent import androidx.compose.foundation.background import androidx.compose.foundation.layout.* -import androidx.compose.material.Icon -import androidx.compose.material.Text +import androidx.compose.material3.Text import androidx.compose.runtime.* import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.layout.onSizeChanged import androidx.compose.ui.platform.LocalDensity -import androidx.compose.ui.res.painterResource import androidx.compose.ui.res.stringResource import androidx.compose.ui.text.style.TextOverflow import androidx.compose.ui.tooling.preview.Preview @@ -20,8 +18,8 @@ import androidx.compose.ui.tooling.preview.datasource.CollectionPreviewParameter import androidx.compose.ui.unit.Dp import com.tangem.core.ui.R import com.tangem.core.ui.components.RectangleShimmer -import com.tangem.core.ui.res.TangemThemePreview import com.tangem.core.ui.res.TangemTheme +import com.tangem.core.ui.res.TangemThemePreview import com.tangem.core.ui.utils.BigDecimalFormatter /** @@ -116,7 +114,10 @@ private fun PriceBlock(state: MarketPriceBlockState, priceWidthDp: Dp) { ) { Price(price = marketPriceBlockState.price, modifier = priceModifier) - PriceChangeInPercent(marketPriceBlockState.priceChangeConfig) + PriceChangeInPercent( + valueInPercent = marketPriceBlockState.priceChangeConfig.valueInPercent, + type = marketPriceBlockState.priceChangeConfig.type, + ) } } else { Price(price = BigDecimalFormatter.EMPTY_BALANCE_SIGN, modifier = priceModifier) @@ -136,47 +137,6 @@ private fun Price(price: String, modifier: Modifier = Modifier) { ) } -@Composable -private fun PriceChangeInPercent(config: PriceChangeState.Content) { - AnimatedContent( - targetState = config.type, - contentAlignment = Alignment.CenterStart, - label = "Update price change", - ) { type -> - Row( - verticalAlignment = Alignment.CenterVertically, - horizontalArrangement = Arrangement.spacedBy(space = TangemTheme.dimens.spacing2), - ) { - Icon( - modifier = Modifier.size(TangemTheme.dimens.size8), - painter = painterResource( - id = when (type) { - PriceChangeType.UP -> R.drawable.ic_arrow_up_8 - PriceChangeType.DOWN -> R.drawable.ic_arrow_down_8 - PriceChangeType.NEUTRAL -> R.drawable.ic_elipse_8 - }, - ), - tint = when (type) { - PriceChangeType.UP -> TangemTheme.colors.icon.accent - PriceChangeType.DOWN -> TangemTheme.colors.icon.warning - PriceChangeType.NEUTRAL -> TangemTheme.colors.icon.inactive - }, - contentDescription = null, - ) - - Text( - text = config.valueInPercent, - color = when (type) { - PriceChangeType.UP -> TangemTheme.colors.text.accent - PriceChangeType.DOWN -> TangemTheme.colors.text.warning - PriceChangeType.NEUTRAL -> TangemTheme.colors.text.disabled - }, - style = TangemTheme.typography.body2, - ) - } - } -} - @Composable private fun LoadingContent() { Row( diff --git a/core/ui/src/main/java/com/tangem/core/ui/components/marketprice/PriceChangeInPercent.kt b/core/ui/src/main/java/com/tangem/core/ui/components/marketprice/PriceChangeInPercent.kt new file mode 100644 index 0000000000..d2c55ed576 --- /dev/null +++ b/core/ui/src/main/java/com/tangem/core/ui/components/marketprice/PriceChangeInPercent.kt @@ -0,0 +1,96 @@ +package com.tangem.core.ui.components.marketprice + +import android.content.res.Configuration +import androidx.compose.foundation.layout.Arrangement +import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.Row +import androidx.compose.foundation.layout.size +import androidx.compose.material3.Icon +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.vector.ImageVector +import androidx.compose.ui.res.vectorResource +import androidx.compose.ui.text.TextStyle +import androidx.compose.ui.text.style.TextOverflow +import androidx.compose.ui.tooling.preview.Preview +import com.tangem.core.ui.R +import com.tangem.core.ui.res.TangemTheme +import com.tangem.core.ui.res.TangemThemePreview + +@Composable +fun PriceChangeInPercent( + valueInPercent: String, + type: PriceChangeType, + modifier: Modifier = Modifier, + textStyle: TextStyle = TangemTheme.typography.body2, +) { + Row( + modifier = modifier, + verticalAlignment = Alignment.CenterVertically, + horizontalArrangement = Arrangement.spacedBy(space = TangemTheme.dimens.spacing2), + ) { + Icon( + modifier = Modifier + .size(TangemTheme.dimens.size8) + .align(Alignment.CenterVertically), + imageVector = ImageVector.vectorResource( + id = when (type) { + PriceChangeType.UP -> R.drawable.ic_arrow_up_8 + PriceChangeType.DOWN -> R.drawable.ic_arrow_down_8 + PriceChangeType.NEUTRAL -> R.drawable.ic_elipse_8 + }, + ), + tint = when (type) { + PriceChangeType.UP -> TangemTheme.colors.icon.accent + PriceChangeType.DOWN -> TangemTheme.colors.icon.warning + PriceChangeType.NEUTRAL -> TangemTheme.colors.icon.inactive + }, + contentDescription = null, + ) + + Text( + text = valueInPercent, + color = when (type) { + PriceChangeType.UP -> TangemTheme.colors.text.accent + PriceChangeType.DOWN -> TangemTheme.colors.text.warning + PriceChangeType.NEUTRAL -> TangemTheme.colors.text.disabled + }, + style = textStyle, + overflow = TextOverflow.Visible, + maxLines = 1, + ) + } +} + +//region Preview + +@Preview +@Preview(uiMode = Configuration.UI_MODE_NIGHT_YES) +@Composable +private fun Preview() { + TangemThemePreview { + Column { + PriceChangeInPercent( + valueInPercent = "52.00%", + type = PriceChangeType.NEUTRAL, + ) + PriceChangeInPercent( + valueInPercent = "52.00%", + type = PriceChangeType.UP, + ) + PriceChangeInPercent( + valueInPercent = "52.00%", + type = PriceChangeType.DOWN, + ) + PriceChangeInPercent( + valueInPercent = "52.00%", + type = PriceChangeType.DOWN, + textStyle = TangemTheme.typography.caption2, + ) + } + } +} + +//endregion Preview \ No newline at end of file diff --git a/core/ui/src/main/java/com/tangem/core/ui/components/notifications/CurrencyNotification.kt b/core/ui/src/main/java/com/tangem/core/ui/components/notifications/CurrencyNotification.kt index 7c646add3d..e1b4cc4b24 100644 --- a/core/ui/src/main/java/com/tangem/core/ui/components/notifications/CurrencyNotification.kt +++ b/core/ui/src/main/java/com/tangem/core/ui/components/notifications/CurrencyNotification.kt @@ -15,8 +15,8 @@ import androidx.compose.ui.text.buildAnnotatedString import androidx.compose.ui.tooling.preview.Preview import com.tangem.core.ui.R import com.tangem.core.ui.components.SpacerW -import com.tangem.core.ui.components.currency.tokenicon.TokenIcon -import com.tangem.core.ui.components.currency.tokenicon.TokenIconState +import com.tangem.core.ui.components.currency.icon.CurrencyIcon +import com.tangem.core.ui.components.currency.icon.CurrencyIconState import com.tangem.core.ui.extensions.* import com.tangem.core.ui.res.TangemTheme import com.tangem.core.ui.res.TangemThemePreview @@ -54,12 +54,12 @@ fun CurrencyNotification( @Composable private fun MainContent( - tokenIconState: TokenIconState, + tokenIconState: CurrencyIconState, title: TextReference, subtitle: CurrencyNotificationConfig.AnnotatedSubtitle, ) { Row { - TokenIcon( + CurrencyIcon( state = tokenIconState, modifier = Modifier.align(alignment = Alignment.CenterVertically), ) @@ -107,9 +107,9 @@ private fun Preview_Notification() { }, onClick = { _, _ -> }, ), - tokenIconState = TokenIconState.TokenIcon( + tokenIconState = CurrencyIconState.TokenIcon( url = "https://s3.eu-central-1.amazonaws.com/tangem.api/coins/large/usd-coin.png", - networkBadgeIconResId = R.drawable.ic_polygon_22, + topBadgeIconResId = R.drawable.ic_polygon_22, isGrayscale = false, showCustomBadge = false, fallbackTint = Color(1.0f, 1.0f, 1.0f, 1.0f, ColorSpaces.Srgb), diff --git a/core/ui/src/main/java/com/tangem/core/ui/components/notifications/CurrencyNotificationConfig.kt b/core/ui/src/main/java/com/tangem/core/ui/components/notifications/CurrencyNotificationConfig.kt index 0fa3aadd26..74962546e7 100644 --- a/core/ui/src/main/java/com/tangem/core/ui/components/notifications/CurrencyNotificationConfig.kt +++ b/core/ui/src/main/java/com/tangem/core/ui/components/notifications/CurrencyNotificationConfig.kt @@ -2,7 +2,7 @@ package com.tangem.core.ui.components.notifications import androidx.compose.runtime.Composable import androidx.compose.ui.text.AnnotatedString -import com.tangem.core.ui.components.currency.tokenicon.TokenIconState +import com.tangem.core.ui.components.currency.icon.CurrencyIconState import com.tangem.core.ui.extensions.TextReference /** @@ -18,7 +18,7 @@ import com.tangem.core.ui.extensions.TextReference data class CurrencyNotificationConfig( val title: TextReference, val subtitle: AnnotatedSubtitle, - val tokenIconState: TokenIconState, + val tokenIconState: CurrencyIconState, val buttonsState: NotificationConfig.ButtonsState, ) { diff --git a/core/ui/src/main/java/com/tangem/core/ui/components/notifications/TravalaNotificationWithBackground.kt b/core/ui/src/main/java/com/tangem/core/ui/components/notifications/TravalaNotificationWithBackground.kt deleted file mode 100644 index 9e6ba3db1d..0000000000 --- a/core/ui/src/main/java/com/tangem/core/ui/components/notifications/TravalaNotificationWithBackground.kt +++ /dev/null @@ -1,215 +0,0 @@ -package com.tangem.core.ui.components.notifications - -import androidx.compose.foundation.Image -import androidx.compose.foundation.background -import androidx.compose.foundation.clickable -import androidx.compose.foundation.interaction.MutableInteractionSource -import androidx.compose.foundation.layout.* -import androidx.compose.material.Icon -import androidx.compose.material.Text -import androidx.compose.material.ripple.rememberRipple -import androidx.compose.runtime.* -import androidx.compose.ui.Alignment -import androidx.compose.ui.Modifier -import androidx.compose.ui.draw.clip -import androidx.compose.ui.geometry.Size -import androidx.compose.ui.graphics.Color -import androidx.compose.ui.layout.ContentScale -import androidx.compose.ui.layout.ScaleFactor -import androidx.compose.ui.platform.LocalDensity -import androidx.compose.ui.res.painterResource -import androidx.compose.ui.text.AnnotatedString -import androidx.compose.ui.text.SpanStyle -import androidx.compose.ui.text.buildAnnotatedString -import androidx.compose.ui.text.style.LineBreak -import androidx.compose.ui.text.withStyle -import androidx.compose.ui.tooling.preview.Preview -import androidx.compose.ui.unit.Density -import androidx.compose.ui.unit.dp -import com.tangem.core.ui.R -import com.tangem.core.ui.components.SpacerH8 -import com.tangem.core.ui.components.buttons.common.TangemButton -import com.tangem.core.ui.components.buttons.common.TangemButtonColors -import com.tangem.core.ui.components.buttons.common.TangemButtonIconPosition -import com.tangem.core.ui.extensions.resolveReference -import com.tangem.core.ui.extensions.resourceReference -import com.tangem.core.ui.extensions.wrappedList -import com.tangem.core.ui.res.TangemColorPalette.White -import com.tangem.core.ui.res.TangemTheme - -/** - * Travala notification with image background - * @see Travala Promo - */ -@Suppress("LongMethod", "DestructuringDeclarationWithTooManyEntries") -@Composable -fun TravalaNotificationWithBackground(config: NotificationConfig, modifier: Modifier = Modifier) { - val button = config.buttonsState as? NotificationConfig.ButtonsState.SecondaryButtonConfig - - Box( - modifier = modifier - .defaultMinSize(minHeight = TangemTheme.dimens.size62) - .fillMaxWidth() - .clip(TangemTheme.shapes.roundedCornersXMedium) - .background(Color.Black) - .clickable( - enabled = config.onClick != null, - onClick = config.onClick ?: {}, - ), - propagateMinConstraints = true, - contentAlignment = Alignment.TopStart, - ) { - val density = LocalDensity.current - Image( - painter = painterResource(R.drawable.img_travala_banner_promo_background), - contentDescription = null, - contentScale = TravalaBackgroundScale(density), - alignment = Alignment.TopStart, - modifier = Modifier - .matchParentSize() - .wrapContentSize(unbounded = true, align = Alignment.TopStart) - .align(Alignment.TopStart), - ) - Image( - painter = painterResource(R.drawable.img_travala_banner_promo_background_2), - contentDescription = null, - contentScale = TravalaBackgroundScale(density), - alignment = Alignment.TopStart, - modifier = Modifier - .matchParentSize() - .wrapContentSize(unbounded = true, align = Alignment.TopEnd) - .align(Alignment.TopEnd), - ) - Column { - Row { - Box(modifier = Modifier.size(87.dp)) - Column( - Modifier - .weight(1f) - .padding(top = TangemTheme.dimens.spacing12), - ) { - Text( - text = config.title.resolveReference(), - style = TangemTheme.typography.button.copy( - lineBreak = LineBreak.Heading, - ), - color = TangemTheme.colors.text.constantWhite, - ) - SpacerH8() - Text( - text = formatSubtitle(config.subtitle.resolveReference()), - style = TangemTheme.typography.caption2.copy( - lineBreak = LineBreak.Heading, - ), - color = TangemTheme.colors.text.constantWhite, - ) - } - Icon( - painter = painterResource(id = R.drawable.ic_close_24), - contentDescription = null, - tint = TangemTheme.colors.text.constantWhite, - modifier = Modifier - .padding( - top = TangemTheme.dimens.spacing12, - end = TangemTheme.dimens.spacing12, - start = TangemTheme.dimens.spacing2, - ) - .size(TangemTheme.dimens.size16) - .clickable( - interactionSource = remember { MutableInteractionSource() }, - indication = rememberRipple(bounded = false), - ) { - config.onCloseClick?.invoke() - }, - ) - } - - TangemButton( - text = button?.text?.resolveReference().orEmpty(), - icon = TangemButtonIconPosition.None, - onClick = button?.onClick ?: {}, - colors = TangemButtonColors( - backgroundColor = White.copy(alpha = 0.3f), - contentColor = White, - disabledBackgroundColor = TangemTheme.colors.button.disabled, - disabledContentColor = TangemTheme.colors.text.disabled, - ), - enabled = true, - showProgress = false, - modifier = Modifier - .padding(TangemTheme.dimens.spacing12) - .fillMaxWidth(), - ) - } - } -} - -private const val TRAVALA_BACKGROUND_SRC_IMG_SCALE = 4 - -private class TravalaBackgroundScale( - val density: Density, -) : ContentScale { - override fun computeScaleFactor(srcSize: Size, dstSize: Size): ScaleFactor { - with(density) { - val originalWidth = (srcSize.width / TRAVALA_BACKGROUND_SRC_IMG_SCALE).dp.toPx() - val widthScale = originalWidth / srcSize.width - val originalHeight = (srcSize.height / TRAVALA_BACKGROUND_SRC_IMG_SCALE).dp.toPx() - val heightScale = originalHeight / srcSize.height - return ScaleFactor(widthScale, heightScale) - } - } -} - -@Composable -private fun formatSubtitle(subtitle: String): AnnotatedString { - val pattern = Regex("\\*\\*(.*?)\\*\\*") - var startIndex = 0 - val annotatedString = buildAnnotatedString { - pattern.findAll(subtitle).forEach { matchResult -> - val index = matchResult.range.first - val matchedValue = matchResult.groups[1]?.value ?: "" - - // appends unformatted part - append(subtitle.substring(startIndex, index)) - - // applies style on ^^-wrapped parts - withStyle(SpanStyle(fontWeight = TangemTheme.typography.caption1.fontWeight)) { - append(matchedValue) - } - - // goes to next part - startIndex = matchResult.range.last + 1 - } - - // appends remaining ending if exists - append(subtitle.substring(startIndex)) - } - - return annotatedString -} - -//region preview -@Preview -@Composable -private fun TravalaNotificationWithBackgroundPreview() { - TangemTheme { - TravalaNotificationWithBackground( - config = NotificationConfig( - title = resourceReference( - id = R.string.main_travala_promotion_title, - ), - subtitle = resourceReference( - id = R.string.main_travala_promotion_description, - formatArgs = wrappedList("May 13", "June 12"), - ), - iconResId = R.drawable.img_swap_promo, - backgroundResId = R.drawable.img_travala_banner_promo_background, - buttonsState = NotificationConfig.ButtonsState.SecondaryButtonConfig( - text = resourceReference(id = R.string.token_swap_promotion_button), - onClick = {}, - ), - ), - ) - } -} -//endregion \ No newline at end of file diff --git a/core/ui/src/main/java/com/tangem/core/ui/components/rows/ArrowRow.kt b/core/ui/src/main/java/com/tangem/core/ui/components/rows/ArrowRow.kt new file mode 100644 index 0000000000..0e594fbd91 --- /dev/null +++ b/core/ui/src/main/java/com/tangem/core/ui/components/rows/ArrowRow.kt @@ -0,0 +1,168 @@ +package com.tangem.core.ui.components.rows + +import androidx.compose.foundation.Canvas +import androidx.compose.foundation.layout.* +import androidx.compose.runtime.* +import androidx.compose.ui.Alignment +import androidx.compose.ui.Modifier +import androidx.compose.ui.geometry.Offset +import androidx.compose.ui.geometry.Rect +import androidx.compose.ui.graphics.* +import androidx.compose.ui.graphics.drawscope.DrawScope +import androidx.compose.ui.graphics.drawscope.Stroke +import androidx.compose.ui.graphics.drawscope.drawIntoCanvas +import androidx.compose.ui.layout.onSizeChanged +import androidx.compose.ui.platform.LocalDensity +import androidx.compose.ui.unit.* +import com.tangem.core.ui.res.TangemTheme +import com.tangem.core.ui.utils.* + +@Composable +inline fun ArrowRow( + isLastItem: Boolean, + content: @Composable() (BoxScope.() -> Unit), + modifier: Modifier = Modifier, + contentPadding: PaddingValues = PaddingValues(all = TangemTheme.dimens.spacing0), +) { + val density = LocalDensity.current.density + val defaultRowHeight = TangemTheme.dimens.size0 + var itemHeight by remember { mutableStateOf(defaultRowHeight) } + + Row( + modifier = modifier.onSizeChanged { size -> + val height = size.height.toFloat() + if (height != itemHeight.toPx(density)) { + itemHeight = convertPxToDp(px = height, density = density) + } + }, + verticalAlignment = Alignment.CenterVertically, + horizontalArrangement = Arrangement.Start, + ) { + ChildArrow( + childHeight = itemHeight, + isLastChild = isLastItem, + ) + + Box( + modifier = Modifier + .padding(contentPadding) + .fillMaxWidth(), + contentAlignment = Alignment.CenterStart, + ) { + content() + } + } +} + +@Suppress("LongParameterList") +@Immutable +private class ChildArrowScope( + val figureRect: Rect, + val arrowHeadRect: Rect, + val curvedArrowRect: Rect, + val arrowStrokeWidth: Float, + val arrowHeadRadius: Float, + val strokeColor: Color, + drawScope: DrawScope, +) : DrawScope by drawScope + +@Composable +fun ChildArrow(childHeight: Dp, isLastChild: Boolean) { + val figureWidth = TangemTheme.dimens.size40 + + val strokeColor = TangemTheme.colors.stroke.secondary + val arrowStrokeWidthDp = TangemTheme.dimens.size1 + + val arrowHeadRadiusDp = TangemTheme.dimens.size1 + + val figureRectDp = DpRect( + origin = DpOffset.Zero, + size = DpSize(width = TangemTheme.dimens.size40, height = childHeight), + ) + + val arrowHeadSize = DpSize( + width = TangemTheme.dimens.size6, + height = TangemTheme.dimens.size6, + ) + val arrowHeadRectDp = DpRect( + origin = DpOffset( + x = figureWidth - arrowHeadSize.width, + y = figureRectDp.size.center.y - arrowHeadSize.center.y, + ), + size = arrowHeadSize, + ) + + val curvedArrowRectDp = DpRect( + top = figureRectDp.top, + left = TangemTheme.dimens.size18, + right = figureRectDp.right - arrowHeadRectDp.width, + bottom = figureRectDp.size.center.y, + ) + + Canvas( + modifier = Modifier + .width(figureWidth) + .height(childHeight), + ) { + val scope = ChildArrowScope( + figureRect = figureRectDp.toRect(), + arrowHeadRect = arrowHeadRectDp.toRect(), + curvedArrowRect = curvedArrowRectDp.toRect(), + arrowStrokeWidth = arrowStrokeWidthDp.toPx(), + arrowHeadRadius = arrowHeadRadiusDp.toPx(), + strokeColor = strokeColor, + drawScope = this, + ) + + scope.drawCurveArrow() + scope.drawArrowHead() + + if (!isLastChild) { + scope.drawArrowLine() + } + } +} + +private fun ChildArrowScope.drawArrowHead() { + val arrowHeadPath = Path().apply { + moveTo(arrowHeadRect.centerRight) + lineTo(arrowHeadRect.topLeft) + lineTo(arrowHeadRect.bottomLeft) + close() + } + val paint = Paint().apply { + color = strokeColor + style = PaintingStyle.Fill + pathEffect = PathEffect.cornerPathEffect(arrowHeadRadius) + } + drawIntoCanvas { canvas -> + canvas.drawOutline( + outline = Outline.Generic(arrowHeadPath), + paint = paint, + ) + } +} + +private fun ChildArrowScope.drawCurveArrow() { + val curveArrowPath = Path().apply { + moveTo(curvedArrowRect.topLeft) + quadraticBezierTo( + control = curvedArrowRect.bottomLeft, + end = curvedArrowRect.bottomRight, + ) + } + drawPath( + path = curveArrowPath, + color = strokeColor, + style = Stroke(width = arrowStrokeWidth), + ) +} + +private fun ChildArrowScope.drawArrowLine() { + drawLine( + color = strokeColor, + start = curvedArrowRect.topLeft, + end = Offset(curvedArrowRect.left, figureRect.bottom), + strokeWidth = arrowStrokeWidth, + ) +} \ No newline at end of file diff --git a/core/ui/src/main/java/com/tangem/core/ui/components/rows/BlockchainRow.kt b/core/ui/src/main/java/com/tangem/core/ui/components/rows/BlockchainRow.kt new file mode 100644 index 0000000000..4f8edf75c4 --- /dev/null +++ b/core/ui/src/main/java/com/tangem/core/ui/components/rows/BlockchainRow.kt @@ -0,0 +1,161 @@ +package com.tangem.core.ui.components.rows + +import android.content.res.Configuration +import androidx.annotation.DrawableRes +import androidx.compose.foundation.Image +import androidx.compose.foundation.background +import androidx.compose.foundation.layout.* +import androidx.compose.foundation.shape.CircleShape +import androidx.compose.material3.Icon +import androidx.compose.runtime.Composable +import androidx.compose.ui.Alignment +import androidx.compose.ui.Modifier +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.TangemSwitch +import com.tangem.core.ui.components.rows.model.BlockchainRowUM +import com.tangem.core.ui.res.TangemTheme +import com.tangem.core.ui.res.TangemThemePreview + +/** + * [Figma Component](https://www.figma.com/design/14ISV23YB1yVW1uNVwqrKv/Android?node-id=2737-2800&t=ewlXfWwbDnRhjw4B-4) + * */ +@Composable +fun BlockchainRow(model: BlockchainRowUM, action: @Composable BoxScope.() -> Unit, modifier: Modifier = Modifier) { + RowContentContainer( + modifier = modifier + .heightIn(min = TangemTheme.dimens.size52) + .padding( + vertical = TangemTheme.dimens.spacing8, + horizontal = TangemTheme.dimens.spacing8, + ), + icon = { + RowIcon( + resId = model.iconResId, + isColored = model.isSelected, + showAccentBadge = model.isMainNetwork, + ) + }, + text = { + RowText( + mainText = model.name, + secondText = model.type, + accentMainText = model.isSelected, + accentSecondText = model.isMainNetwork, + ) + }, + action = action, + ) +} + +@Composable +private fun RowIcon( + @DrawableRes resId: Int, + isColored: Boolean, + showAccentBadge: Boolean, + modifier: Modifier = Modifier, +) { + Box( + modifier = modifier.size(TangemTheme.dimens.size24), + ) { + if (isColored) { + Image( + modifier = Modifier + .align(Alignment.Center) + .size(TangemTheme.dimens.size22), + painter = painterResource(id = resId), + contentDescription = null, + ) + } else { + Icon( + modifier = Modifier + .align(Alignment.Center) + .background( + color = TangemTheme.colors.button.secondary, + shape = CircleShape, + ) + .size(TangemTheme.dimens.size22), + painter = painterResource(id = resId), + tint = TangemTheme.colors.icon.informative, + contentDescription = null, + ) + } + + if (showAccentBadge) { + Badge(modifier = Modifier.align(Alignment.TopEnd)) + } + } +} + +@Composable +private fun Badge(modifier: Modifier = Modifier) { + Box( + modifier = modifier + .size(TangemTheme.dimens.size8) + .background( + color = TangemTheme.colors.background.primary, + shape = CircleShape, + ), + contentAlignment = Alignment.Center, + ) { + Box( + modifier = Modifier + .size(TangemTheme.dimens.size5) + .background( + color = TangemTheme.colors.icon.accent, + shape = CircleShape, + ), + ) + } +} + +// region Preview +@Preview(showBackground = true, widthDp = 360) +@Preview(showBackground = true, widthDp = 360, uiMode = Configuration.UI_MODE_NIGHT_YES) +@Composable +private fun Preview_BlockchainRow(@PreviewParameter(BlockchainRowParameterProvider::class) state: BlockchainRowUM) { + TangemThemePreview { + ArrowRow( + modifier = Modifier.background(TangemTheme.colors.background.primary), + isLastItem = false, + content = { + BlockchainRow( + model = state, + action = { + TangemSwitch(onCheckedChange = { /* [REDACTED_TODO_COMMENT]*/ }, checked = true) + }, + ) + }, + ) + } +} + +private class BlockchainRowParameterProvider : CollectionPreviewParameterProvider( + collection = listOf( + BlockchainRowUM( + name = "BNB BEACON CHAIN", + type = "BEP20", + iconResId = R.drawable.img_bsc_22, + isMainNetwork = true, + isSelected = true, + ), + BlockchainRowUM( + name = "1234567890111213141516171819", + type = "BEP20", + iconResId = R.drawable.ic_bsc_16, + isMainNetwork = true, + isSelected = false, + ), + BlockchainRowUM( + name = "BNB BEACON CHAIN", + type = "1234567890111213141516171819", + iconResId = R.drawable.ic_bsc_16, + isMainNetwork = false, + isSelected = false, + ), + ), +) +// endregion Preview \ No newline at end of file diff --git a/core/ui/src/main/java/com/tangem/core/ui/components/rows/ChainRow.kt b/core/ui/src/main/java/com/tangem/core/ui/components/rows/ChainRow.kt new file mode 100644 index 0000000000..c57b6ebc1a --- /dev/null +++ b/core/ui/src/main/java/com/tangem/core/ui/components/rows/ChainRow.kt @@ -0,0 +1,104 @@ +package com.tangem.core.ui.components.rows + +import android.content.res.Configuration +import androidx.compose.foundation.background +import androidx.compose.foundation.layout.Arrangement +import androidx.compose.foundation.layout.BoxScope +import androidx.compose.foundation.layout.heightIn +import androidx.compose.foundation.layout.padding +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.TangemSwitch +import com.tangem.core.ui.components.currency.icon.CurrencyIcon +import com.tangem.core.ui.components.currency.icon.CurrencyIconState +import com.tangem.core.ui.components.rows.model.ChainRowUM +import com.tangem.core.ui.extensions.resourceReference +import com.tangem.core.ui.res.TangemTheme +import com.tangem.core.ui.res.TangemThemePreview + +/** + * [Figma Component](https://www.figma.com/design/14ISV23YB1yVW1uNVwqrKv/Android?node-id=1608-1147&t=ewlXfWwbDnRhjw4B-4) + * */ +@Composable +fun ChainRow(model: ChainRowUM, modifier: Modifier = Modifier, action: @Composable BoxScope.() -> Unit = {}) { + RowContentContainer( + modifier = modifier + .heightIn(min = TangemTheme.dimens.size68) + .padding(vertical = TangemTheme.dimens.spacing8) + .padding( + start = TangemTheme.dimens.spacing8, + end = TangemTheme.dimens.spacing12, + ), + horizontalArrangement = Arrangement.spacedBy(TangemTheme.dimens.spacing12), + icon = { + CurrencyIcon( + state = model.icon, + shouldDisplayNetwork = true, + ) + }, + text = { + RowText( + mainText = model.name, + secondText = model.type, + subtitle = if (model.showCustom) { + resourceReference(R.string.common_custom) + } else { + null + }, + accentMainText = true, + accentSecondText = false, + ) + }, + action = action, + ) +} + +// region Preview +@Preview(showBackground = true, widthDp = 360) +@Preview(showBackground = true, widthDp = 360, uiMode = Configuration.UI_MODE_NIGHT_YES) +@Composable +private fun Preview_ChainRow(@PreviewParameter(ChainRowParameterProvider::class) state: ChainRowUM) { + TangemThemePreview { + ChainRow( + modifier = Modifier.background(TangemTheme.colors.background.primary), + model = state, + action = { + TangemSwitch(onCheckedChange = {}, checked = false) + }, + ) + } +} + +private class ChainRowParameterProvider : CollectionPreviewParameterProvider( + collection = listOf( + ChainRowUM( + name = "Cardano", + type = "ADA", + icon = CurrencyIconState.Locked, + showCustom = true, + ), + ChainRowUM( + name = "Binance", + type = "BNB", + icon = CurrencyIconState.Locked, + showCustom = false, + ), + ChainRowUM( + name = "123456789010111213141516", + type = "BNB", + icon = CurrencyIconState.Locked, + showCustom = true, + ), + ChainRowUM( + name = "123456789010111213141516", + type = "123456789010111213141516", + icon = CurrencyIconState.Locked, + showCustom = false, + ), + ), +) +// endregion Preview \ No newline at end of file diff --git a/core/ui/src/main/java/com/tangem/core/ui/components/rows/RoundableCornersRow.kt b/core/ui/src/main/java/com/tangem/core/ui/components/rows/RoundableCornersRow.kt new file mode 100644 index 0000000000..c2b1e97286 --- /dev/null +++ b/core/ui/src/main/java/com/tangem/core/ui/components/rows/RoundableCornersRow.kt @@ -0,0 +1,157 @@ +package com.tangem.core.ui.components.rows + +import android.content.res.Configuration +import androidx.compose.foundation.background +import androidx.compose.foundation.clickable +import androidx.compose.foundation.interaction.MutableInteractionSource +import androidx.compose.foundation.layout.* +import androidx.compose.foundation.shape.RoundedCornerShape +import androidx.compose.material.ripple.rememberRipple +import androidx.compose.material3.Icon +import androidx.compose.material3.Surface +import androidx.compose.material3.Text +import androidx.compose.runtime.Composable +import androidx.compose.runtime.remember +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.text.TextStyle +import androidx.compose.ui.tooling.preview.Preview +import androidx.compose.ui.tooling.preview.PreviewParameter +import androidx.compose.ui.tooling.preview.PreviewParameterProvider +import androidx.compose.ui.unit.dp +import com.tangem.core.ui.R +import com.tangem.core.ui.res.TangemTheme +import com.tangem.core.ui.res.TangemThemePreview + +@Suppress("LongParameterList") +@Composable +fun RoundableCornersRow( + startText: String, + startTextColor: Color, + startTextStyle: TextStyle, + endText: String, + endTextColor: Color, + endTextStyle: TextStyle, + cornersToRound: CornersToRound, + iconResId: Int? = null, + iconClick: (() -> Unit)? = null, +) { + Surface( + shape = cornersToRound.getShape(), + color = TangemTheme.colors.background.primary, + ) { + Row( + modifier = Modifier + .fillMaxWidth() + .heightIn(TangemTheme.dimens.size48) + .padding( + horizontal = TangemTheme.dimens.spacing16, + vertical = TangemTheme.dimens.spacing12, + ), + horizontalArrangement = Arrangement.Start, + verticalAlignment = Alignment.CenterVertically, + ) { + Text( + text = startText, + color = startTextColor, + maxLines = 1, + style = startTextStyle, + ) + if (iconResId != null && iconClick != null) { + Icon( + modifier = Modifier + .padding(TangemTheme.dimens.spacing4) + .size(TangemTheme.dimens.size16) + .clickable( + interactionSource = remember { MutableInteractionSource() }, + indication = rememberRipple(bounded = false, radius = TangemTheme.dimens.radius10), + onClick = iconClick, + ), + painter = painterResource(id = R.drawable.ic_alert_24), + contentDescription = null, + tint = TangemTheme.colors.text.tertiary, + ) + } + Spacer(modifier = Modifier.weight(1f)) + Text( + text = endText, + color = endTextColor, + maxLines = 1, + style = endTextStyle, + ) + } + } +} + +enum class CornersToRound { + + ALL_4, + TOP_2, + BOTTOM_2, + ZERO, + ; + + @Suppress("TopLevelComposableFunctions") + @Composable + fun getShape(): RoundedCornerShape { + val radius = TangemTheme.dimens.radius12 + return when (this) { + ALL_4 -> RoundedCornerShape(radius) + TOP_2 -> RoundedCornerShape(topStart = radius, topEnd = radius) + BOTTOM_2 -> RoundedCornerShape(bottomStart = radius, bottomEnd = radius) + ZERO -> RoundedCornerShape(0.dp) + } + } +} + +@Preview(widthDp = 360, showBackground = true) +@Preview(widthDp = 360, showBackground = true, uiMode = Configuration.UI_MODE_NIGHT_YES) +@Composable +private fun Preview_RoundableCornersRow( + @PreviewParameter(RoundableCornersRowDataProvider::class) previewData: RoundableCornersRowPreviewData, +) { + TangemThemePreview { + Box(modifier = Modifier.background(color = TangemTheme.colors.icon.attention)) { + RoundableCornersRow( + startText = previewData.startText, + startTextColor = TangemTheme.colors.text.tertiary, + startTextStyle = TangemTheme.typography.subtitle2, + endText = previewData.endText, + endTextColor = TangemTheme.colors.text.primary1, + endTextStyle = TangemTheme.typography.subtitle2, + cornersToRound = previewData.cornersToRound, + iconResId = previewData.iconResId, + ) + } + } +} + +private data class RoundableCornersRowPreviewData( + val startText: String, + val endText: String, + val cornersToRound: CornersToRound, + val iconResId: Int? = null, +) + +private class RoundableCornersRowDataProvider : + PreviewParameterProvider { + + override val values: Sequence + get() = sequenceOf( + getPreviewData(cornersToRound = CornersToRound.ZERO), + getPreviewData(cornersToRound = CornersToRound.TOP_2), + getPreviewData(cornersToRound = CornersToRound.BOTTOM_2), + getPreviewData(cornersToRound = CornersToRound.ZERO, iconResId = R.drawable.ic_alert_24), + getPreviewData(cornersToRound = CornersToRound.TOP_2, iconResId = R.drawable.ic_alert_24), + getPreviewData(cornersToRound = CornersToRound.BOTTOM_2, iconResId = R.drawable.ic_alert_24), + ) + + private fun getPreviewData(cornersToRound: CornersToRound, iconResId: Int? = null) = RoundableCornersRowPreviewData( + startText = "startText", + endText = "endText", + cornersToRound = cornersToRound, + iconResId = iconResId, + ) +} \ No newline at end of file diff --git a/core/ui/src/main/java/com/tangem/core/ui/components/rows/RowComponents.kt b/core/ui/src/main/java/com/tangem/core/ui/components/rows/RowComponents.kt new file mode 100644 index 0000000000..f93f42b41d --- /dev/null +++ b/core/ui/src/main/java/com/tangem/core/ui/components/rows/RowComponents.kt @@ -0,0 +1,95 @@ +package com.tangem.core.ui.components.rows + +import androidx.compose.foundation.layout.* +import androidx.compose.material3.Text +import androidx.compose.runtime.Composable +import androidx.compose.ui.Alignment +import androidx.compose.ui.Modifier +import androidx.compose.ui.text.style.TextOverflow +import com.tangem.core.ui.extensions.TextReference +import com.tangem.core.ui.extensions.isNullOrEmpty +import com.tangem.core.ui.extensions.resolveReference +import com.tangem.core.ui.res.TangemTheme + +@Composable +internal inline fun RowContentContainer( + icon: @Composable BoxScope.() -> Unit, + text: @Composable BoxScope.() -> Unit, + action: @Composable BoxScope.() -> Unit, + modifier: Modifier = Modifier, + horizontalArrangement: Arrangement.Horizontal = Arrangement.spacedBy(TangemTheme.dimens.spacing8), +) { + Row( + modifier = modifier.fillMaxWidth(), + verticalAlignment = Alignment.CenterVertically, + horizontalArrangement = horizontalArrangement, + ) { + Box( + contentAlignment = Alignment.Center, + content = icon, + ) + Box( + modifier = Modifier + .weight(1f) + .heightIn(min = TangemTheme.dimens.size22), + contentAlignment = Alignment.CenterStart, + content = text, + ) + Box( + modifier = Modifier + .requiredWidthIn(max = TangemTheme.dimens.size80) + .heightIn(min = TangemTheme.dimens.size24), + contentAlignment = Alignment.CenterEnd, + content = action, + ) + } +} + +@Composable +internal fun RowText( + mainText: String, + secondText: String, + accentMainText: Boolean, + accentSecondText: Boolean, + modifier: Modifier = Modifier, + subtitle: TextReference? = null, +) { + Column( + modifier = modifier, + horizontalAlignment = Alignment.Start, + verticalArrangement = Arrangement.spacedBy(TangemTheme.dimens.spacing2), + ) { + Row( + verticalAlignment = Alignment.CenterVertically, + horizontalArrangement = Arrangement.spacedBy(TangemTheme.dimens.spacing4), + ) { + Text( + modifier = Modifier.weight(weight = 10f, fill = false), + text = mainText, + style = TangemTheme.typography.subtitle2, + color = if (accentMainText) TangemTheme.colors.text.primary1 else TangemTheme.colors.text.secondary, + maxLines = 1, + overflow = TextOverflow.Ellipsis, + ) + + Text( + modifier = Modifier.weight(weight = 4f, fill = false), + text = secondText, + style = TangemTheme.typography.body2, + color = if (accentSecondText) TangemTheme.colors.text.accent else TangemTheme.colors.text.secondary, + maxLines = 1, + overflow = TextOverflow.Ellipsis, + ) + } + + if (!subtitle.isNullOrEmpty()) { + Text( + text = subtitle.resolveReference(), + style = TangemTheme.typography.caption2, + color = TangemTheme.colors.text.tertiary, + maxLines = 1, + overflow = TextOverflow.Ellipsis, + ) + } + } +} \ No newline at end of file diff --git a/core/ui/src/main/java/com/tangem/core/ui/components/rows/SelectorRowItem.kt b/core/ui/src/main/java/com/tangem/core/ui/components/rows/SelectorRowItem.kt index c1e06e7270..c6dd8c39f9 100644 --- a/core/ui/src/main/java/com/tangem/core/ui/components/rows/SelectorRowItem.kt +++ b/core/ui/src/main/java/com/tangem/core/ui/components/rows/SelectorRowItem.kt @@ -25,6 +25,7 @@ import com.tangem.core.ui.extensions.TextReference import com.tangem.core.ui.extensions.resolveReference import com.tangem.core.ui.res.TangemThemePreview import com.tangem.core.ui.res.TangemTheme +import com.tangem.utils.StringsSigns @Composable fun SelectorRowItem( @@ -127,7 +128,7 @@ private fun RowScope.SelectorValueContent( ) if (postDot != null) { Text( - text = "•", + text = StringsSigns.DOT, style = TangemTheme.typography.caption2, color = TangemTheme.colors.text.primary1, textAlign = TextAlign.Center, diff --git a/core/ui/src/main/java/com/tangem/core/ui/components/rows/model/BlockchainRowUM.kt b/core/ui/src/main/java/com/tangem/core/ui/components/rows/model/BlockchainRowUM.kt new file mode 100644 index 0000000000..f8e756a9ae --- /dev/null +++ b/core/ui/src/main/java/com/tangem/core/ui/components/rows/model/BlockchainRowUM.kt @@ -0,0 +1,12 @@ +package com.tangem.core.ui.components.rows.model + +import androidx.compose.runtime.Immutable + +@Immutable +data class BlockchainRowUM( + val name: String, + val type: String, + val iconResId: Int, + val isMainNetwork: Boolean, + val isSelected: Boolean, +) \ No newline at end of file diff --git a/core/ui/src/main/java/com/tangem/core/ui/components/rows/model/ChainRowUM.kt b/core/ui/src/main/java/com/tangem/core/ui/components/rows/model/ChainRowUM.kt new file mode 100644 index 0000000000..c0c3764c5e --- /dev/null +++ b/core/ui/src/main/java/com/tangem/core/ui/components/rows/model/ChainRowUM.kt @@ -0,0 +1,12 @@ +package com.tangem.core.ui.components.rows.model + +import androidx.compose.runtime.Immutable +import com.tangem.core.ui.components.currency.icon.CurrencyIconState + +@Immutable +data class ChainRowUM( + val name: String, + val type: String, + val icon: CurrencyIconState, + val showCustom: Boolean, +) \ No newline at end of file diff --git a/core/ui/src/main/java/com/tangem/core/ui/components/showcase/Showcase.kt b/core/ui/src/main/java/com/tangem/core/ui/components/showcase/Showcase.kt new file mode 100644 index 0000000000..8112024b54 --- /dev/null +++ b/core/ui/src/main/java/com/tangem/core/ui/components/showcase/Showcase.kt @@ -0,0 +1,143 @@ +package com.tangem.core.ui.components.showcase + +import android.content.res.Configuration +import androidx.annotation.DrawableRes +import androidx.compose.foundation.background +import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.fillMaxSize +import androidx.compose.foundation.layout.fillMaxWidth +import androidx.compose.foundation.layout.padding +import androidx.compose.material3.Text +import androidx.compose.runtime.Composable +import androidx.compose.ui.Alignment +import androidx.compose.ui.Modifier +import androidx.compose.ui.tooling.preview.Preview +import com.tangem.core.ui.R +import com.tangem.core.ui.components.PrimaryButton +import com.tangem.core.ui.components.SecondaryButton +import com.tangem.core.ui.components.showcase.model.ShowcaseButtonModel +import com.tangem.core.ui.components.showcase.model.ShowcaseItemModel +import com.tangem.core.ui.extensions.TextReference +import com.tangem.core.ui.extensions.resolveReference +import com.tangem.core.ui.extensions.resourceReference +import com.tangem.core.ui.res.TangemTheme +import com.tangem.core.ui.res.TangemThemePreview +import kotlinx.collections.immutable.ImmutableList +import kotlinx.collections.immutable.persistentListOf + +/** + * @param headerIconRes big header icon + * @param headerText header text + * @param showcaseItems list of bullet points + * @param primaryButton primary button + * @param secondaryButton secondary button + * @param modifier compose modifier + * + * @see Figma component + */ +@Composable +fun Showcase( + @DrawableRes headerIconRes: Int, + headerText: TextReference, + showcaseItems: ImmutableList, + primaryButton: ShowcaseButtonModel, + secondaryButton: ShowcaseButtonModel, + modifier: Modifier = Modifier, +) { + Column( + modifier = modifier.fillMaxSize(), + ) { + ShowcaseContent( + headerIconRes = headerIconRes, + headerText = headerText, + showcaseItems = showcaseItems, + modifier = Modifier + .weight(1f) + .align(Alignment.CenterHorizontally), + ) + ShowcaseButtons( + primaryButtonText = primaryButton.buttonText, + onPrimaryClick = primaryButton.onClick, + secondaryButtonText = secondaryButton.buttonText, + onSecondaryClick = secondaryButton.onClick, + ) + } +} + +@Composable +private fun ShowcaseButtons( + primaryButtonText: TextReference, + secondaryButtonText: TextReference, + onPrimaryClick: () -> Unit, + onSecondaryClick: () -> Unit, + hint: TextReference? = null, +) { + Column( + horizontalAlignment = Alignment.CenterHorizontally, + ) { + PrimaryButton( + text = primaryButtonText.resolveReference(), + onClick = onPrimaryClick, + modifier = Modifier + .fillMaxWidth() + .padding( + start = TangemTheme.dimens.spacing16, + end = TangemTheme.dimens.spacing16, + ), + ) + SecondaryButton( + text = secondaryButtonText.resolveReference(), + onClick = onSecondaryClick, + modifier = Modifier + .fillMaxWidth() + .padding( + start = TangemTheme.dimens.spacing16, + end = TangemTheme.dimens.spacing16, + top = TangemTheme.dimens.spacing12, + bottom = TangemTheme.dimens.spacing16, + ), + ) + hint?.let { + Text( + text = it.resolveReference(), + style = TangemTheme.typography.body2, + color = TangemTheme.colors.text.secondary, + modifier = Modifier + .fillMaxWidth() + .padding( + start = TangemTheme.dimens.spacing16, + end = TangemTheme.dimens.spacing16, + bottom = TangemTheme.dimens.spacing12, + ), + ) + } + } +} + +// region Preview +@Preview(showBackground = true, widthDp = 360, heightDp = 720) +@Preview(showBackground = true, widthDp = 360, heightDp = 720, uiMode = Configuration.UI_MODE_NIGHT_YES) +@Composable +private fun Showcase_Preview() { + TangemThemePreview { + Showcase( + headerIconRes = R.drawable.ic_notifications_unread_24, + headerText = resourceReference(R.string.user_push_notification_agreement_header), + showcaseItems = persistentListOf( + ShowcaseItemModel( + R.drawable.ic_rocket_launch_24, + resourceReference(R.string.user_push_notification_agreement_argument_one), + ), + ShowcaseItemModel( + R.drawable.ic_storefront_24, + resourceReference(R.string.user_push_notification_agreement_argument_two), + ), + ), + primaryButton = ShowcaseButtonModel(resourceReference(R.string.common_allow), {}), + secondaryButton = ShowcaseButtonModel(resourceReference(R.string.common_later), {}), + modifier = Modifier.background(TangemTheme.colors.background.primary), + ) + } +} +// endregion \ No newline at end of file diff --git a/core/ui/src/main/java/com/tangem/core/ui/components/showcase/ShowcaseContent.kt b/core/ui/src/main/java/com/tangem/core/ui/components/showcase/ShowcaseContent.kt new file mode 100644 index 0000000000..336172a208 --- /dev/null +++ b/core/ui/src/main/java/com/tangem/core/ui/components/showcase/ShowcaseContent.kt @@ -0,0 +1,71 @@ +package com.tangem.core.ui.components.showcase + +import androidx.annotation.DrawableRes +import androidx.compose.foundation.layout.Arrangement +import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.padding +import androidx.compose.foundation.layout.size +import androidx.compose.material3.Icon +import androidx.compose.material3.Text +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.style.TextAlign +import com.tangem.core.ui.components.showcase.model.ShowcaseItemModel +import com.tangem.core.ui.extensions.TextReference +import com.tangem.core.ui.extensions.resolveReference +import com.tangem.core.ui.res.TangemTheme +import kotlinx.collections.immutable.ImmutableList + +@Composable +fun ShowcaseContent( + @DrawableRes headerIconRes: Int, + headerText: TextReference, + showcaseItems: ImmutableList, + modifier: Modifier = Modifier, +) { + Column( + verticalArrangement = Arrangement.Center, + modifier = modifier, + ) { + Icon( + painter = painterResource(id = headerIconRes), + contentDescription = null, + tint = TangemTheme.colors.icon.primary1, + modifier = Modifier + .align(Alignment.CenterHorizontally) + .size(TangemTheme.dimens.size56), + ) + Text( + text = headerText.resolveReference(), + style = TangemTheme.typography.h2, + color = TangemTheme.colors.text.primary1, + textAlign = TextAlign.Center, + modifier = Modifier + .align(Alignment.CenterHorizontally) + .padding( + start = TangemTheme.dimens.spacing34, + end = TangemTheme.dimens.spacing34, + top = TangemTheme.dimens.spacing28, + ), + ) + Column( + modifier = Modifier + .padding( + start = TangemTheme.dimens.spacing34, + end = TangemTheme.dimens.spacing34, + top = TangemTheme.dimens.spacing28, + ), + verticalArrangement = Arrangement.spacedBy(TangemTheme.dimens.spacing24), + horizontalAlignment = Alignment.CenterHorizontally, + ) { + repeat(showcaseItems.size) { index -> + ShowcaseItem( + iconRes = showcaseItems[index].iconRes, + text = showcaseItems[index].text, + ) + } + } + } +} \ No newline at end of file diff --git a/core/ui/src/main/java/com/tangem/core/ui/components/showcase/ShowcaseItem.kt b/core/ui/src/main/java/com/tangem/core/ui/components/showcase/ShowcaseItem.kt new file mode 100644 index 0000000000..2f098c6720 --- /dev/null +++ b/core/ui/src/main/java/com/tangem/core/ui/components/showcase/ShowcaseItem.kt @@ -0,0 +1,33 @@ +package com.tangem.core.ui.components.showcase + +import androidx.annotation.DrawableRes +import androidx.compose.foundation.layout.Row +import androidx.compose.foundation.layout.fillMaxWidth +import androidx.compose.foundation.layout.padding +import androidx.compose.material3.Icon +import androidx.compose.material3.Text +import androidx.compose.runtime.Composable +import androidx.compose.ui.Modifier +import androidx.compose.ui.res.painterResource +import com.tangem.core.ui.extensions.TextReference +import com.tangem.core.ui.extensions.resolveReference +import com.tangem.core.ui.res.TangemTheme + +@Composable +internal fun ShowcaseItem(@DrawableRes iconRes: Int, text: TextReference) { + Row { + Icon( + painter = painterResource(id = iconRes), + contentDescription = null, + tint = TangemTheme.colors.icon.primary1, + ) + Text( + text = text.resolveReference(), + style = TangemTheme.typography.body2, + color = TangemTheme.colors.text.secondary, + modifier = Modifier + .fillMaxWidth() + .padding(start = TangemTheme.dimens.spacing20), + ) + } +} \ No newline at end of file diff --git a/core/ui/src/main/java/com/tangem/core/ui/components/showcase/model/ShowcaseButtonModel.kt b/core/ui/src/main/java/com/tangem/core/ui/components/showcase/model/ShowcaseButtonModel.kt new file mode 100644 index 0000000000..602465c864 --- /dev/null +++ b/core/ui/src/main/java/com/tangem/core/ui/components/showcase/model/ShowcaseButtonModel.kt @@ -0,0 +1,8 @@ +package com.tangem.core.ui.components.showcase.model + +import com.tangem.core.ui.extensions.TextReference + +data class ShowcaseButtonModel( + val buttonText: TextReference, + val onClick: () -> Unit, +) \ No newline at end of file diff --git a/core/ui/src/main/java/com/tangem/core/ui/components/showcase/model/ShowcaseItemModel.kt b/core/ui/src/main/java/com/tangem/core/ui/components/showcase/model/ShowcaseItemModel.kt new file mode 100644 index 0000000000..f9865aab9e --- /dev/null +++ b/core/ui/src/main/java/com/tangem/core/ui/components/showcase/model/ShowcaseItemModel.kt @@ -0,0 +1,9 @@ +package com.tangem.core.ui.components.showcase.model + +import androidx.annotation.DrawableRes +import com.tangem.core.ui.extensions.TextReference + +data class ShowcaseItemModel( + @DrawableRes val iconRes: Int, + val text: TextReference, +) \ No newline at end of file diff --git a/core/ui/src/main/java/com/tangem/core/ui/components/snackbar/CopiedTextSnackbar.kt b/core/ui/src/main/java/com/tangem/core/ui/components/snackbar/CopiedTextSnackbar.kt index 35cc8f6903..eea8a09bae 100644 --- a/core/ui/src/main/java/com/tangem/core/ui/components/snackbar/CopiedTextSnackbar.kt +++ b/core/ui/src/main/java/com/tangem/core/ui/components/snackbar/CopiedTextSnackbar.kt @@ -19,6 +19,7 @@ import com.tangem.core.ui.extensions.TextReference import com.tangem.core.ui.extensions.resolveReference import com.tangem.core.ui.extensions.stringReference import com.tangem.core.ui.res.TangemTheme +import com.tangem.core.ui.res.TangemThemePreview /** * Snackbar to inform the user about copying text to the clipboard @@ -100,7 +101,7 @@ private fun MessageText(text: TextReference, modifier: Modifier = Modifier) { private fun Preview_CopiedTextSnackbar( @PreviewParameter(CopiedTextSnackbarDataProvider::class) message: TextReference, ) { - TangemTheme(isDark = false) { + TangemThemePreview { CopiedTextSnackbar(message = message) } } diff --git a/core/ui/src/main/java/com/tangem/core/ui/components/text/TooltipText.kt b/core/ui/src/main/java/com/tangem/core/ui/components/text/TooltipText.kt new file mode 100644 index 0000000000..110080210d --- /dev/null +++ b/core/ui/src/main/java/com/tangem/core/ui/components/text/TooltipText.kt @@ -0,0 +1,91 @@ +package com.tangem.core.ui.components.text + +import android.content.res.Configuration +import androidx.compose.foundation.background +import androidx.compose.foundation.clickable +import androidx.compose.foundation.interaction.MutableInteractionSource +import androidx.compose.foundation.layout.* +import androidx.compose.material3.Icon +import androidx.compose.material3.IconButton +import androidx.compose.material3.Text +import androidx.compose.runtime.Composable +import androidx.compose.runtime.remember +import androidx.compose.ui.Alignment +import androidx.compose.ui.Modifier +import androidx.compose.ui.res.painterResource +import androidx.compose.ui.text.style.TextOverflow +import androidx.compose.ui.tooling.preview.Preview +import androidx.compose.ui.unit.dp +import com.tangem.core.ui.R +import com.tangem.core.ui.extensions.TextReference +import com.tangem.core.ui.extensions.resolveReference +import com.tangem.core.ui.extensions.stringReference +import com.tangem.core.ui.res.TangemTheme +import com.tangem.core.ui.res.TangemThemePreview + +@Composable +fun TooltipText( + text: TextReference, + onInfoClick: () -> Unit, + modifier: Modifier = Modifier, + useSmallerText: Boolean = false, +) { + val interactionSource = remember { MutableInteractionSource() } + + Row( + modifier = modifier + .clickable( + interactionSource = interactionSource, + indication = null, + onClick = onInfoClick, + ), + verticalAlignment = Alignment.CenterVertically, + horizontalArrangement = Arrangement.SpaceAround, + ) { + Text( + modifier = Modifier.weight(1f, fill = false), + text = text.resolveReference(), + style = if (useSmallerText) { + TangemTheme.typography.caption2 + } else { + TangemTheme.typography.subtitle2 + }, + color = TangemTheme.colors.text.tertiary, + maxLines = 1, + overflow = TextOverflow.Ellipsis, + ) + + IconButton( + modifier = Modifier.requiredSize(TangemTheme.dimens.size24), + interactionSource = interactionSource, + onClick = onInfoClick, + ) { + Icon( + modifier = Modifier.size(TangemTheme.dimens.size16), + painter = painterResource(id = R.drawable.ic_information_24), + tint = TangemTheme.colors.icon.informative, + contentDescription = null, + ) + } + } +} + +// region Preview +@Preview(showBackground = true, widthDp = 360) +@Preview(showBackground = true, widthDp = 360, uiMode = Configuration.UI_MODE_NIGHT_YES) +@Composable +private fun Preview_TooltipText() { + TangemThemePreview { + Box( + modifier = Modifier + .width(width = 90.dp) + .background(color = TangemTheme.colors.background.primary), + ) { + TooltipText( + text = stringReference("Text"), + onInfoClick = { /* [REDACTED_TODO_COMMENT]*/ }, + ) + } + } +} +// endregion Preview \ No newline at end of file diff --git a/core/ui/src/main/java/com/tangem/core/ui/components/transactions/Transaction.kt b/core/ui/src/main/java/com/tangem/core/ui/components/transactions/Transaction.kt index e43769432c..6a906295de 100644 --- a/core/ui/src/main/java/com/tangem/core/ui/components/transactions/Transaction.kt +++ b/core/ui/src/main/java/com/tangem/core/ui/components/transactions/Transaction.kt @@ -22,7 +22,6 @@ import androidx.compose.ui.tooling.preview.PreviewParameter import androidx.compose.ui.tooling.preview.datasource.CollectionPreviewParameterProvider import androidx.constraintlayout.compose.ConstraintLayout import androidx.constraintlayout.compose.Dimension -import com.tangem.common.Strings import com.tangem.core.ui.R import com.tangem.core.ui.components.CircleShimmer import com.tangem.core.ui.components.RectangleShimmer @@ -35,6 +34,7 @@ import com.tangem.core.ui.extensions.resourceReference import com.tangem.core.ui.extensions.stringReference import com.tangem.core.ui.res.TangemTheme import com.tangem.core.ui.res.TangemThemePreview +import com.tangem.utils.StringsSigns import java.util.UUID /** @@ -258,7 +258,7 @@ private fun Amount(state: TransactionState, isBalanceHidden: Boolean, modifier: when (state) { is TransactionState.Content -> { Text( - text = if (isBalanceHidden) Strings.STARS else state.amount, + text = if (isBalanceHidden) StringsSigns.STARS else state.amount, modifier = modifier, textAlign = TextAlign.End, color = when (state.status) { diff --git a/core/ui/src/main/java/com/tangem/core/ui/decompose/ComposableContentComponent.kt b/core/ui/src/main/java/com/tangem/core/ui/decompose/ComposableContentComponent.kt new file mode 100644 index 0000000000..c44405f037 --- /dev/null +++ b/core/ui/src/main/java/com/tangem/core/ui/decompose/ComposableContentComponent.kt @@ -0,0 +1,12 @@ +package com.tangem.core.ui.decompose + +import androidx.compose.runtime.Composable +import androidx.compose.runtime.Stable +import androidx.compose.ui.Modifier + +@Stable +fun interface ComposableContentComponent { + + @Composable + fun Content(modifier: Modifier) +} \ No newline at end of file diff --git a/core/ui/src/main/java/com/tangem/core/ui/decompose/ComposableDialogComponent.kt b/core/ui/src/main/java/com/tangem/core/ui/decompose/ComposableDialogComponent.kt new file mode 100644 index 0000000000..f87116ef80 --- /dev/null +++ b/core/ui/src/main/java/com/tangem/core/ui/decompose/ComposableDialogComponent.kt @@ -0,0 +1,13 @@ +package com.tangem.core.ui.decompose + +import androidx.compose.runtime.Composable +import androidx.compose.runtime.Stable + +@Stable +interface ComposableDialogComponent { + + fun dismiss() + + @Composable + fun Dialog() +} \ No newline at end of file diff --git a/core/ui/src/main/java/com/tangem/core/ui/extensions/MarkdownExtension.kt b/core/ui/src/main/java/com/tangem/core/ui/extensions/MarkdownExtension.kt index 408e9130ee..c510835242 100644 --- a/core/ui/src/main/java/com/tangem/core/ui/extensions/MarkdownExtension.kt +++ b/core/ui/src/main/java/com/tangem/core/ui/extensions/MarkdownExtension.kt @@ -2,6 +2,7 @@ package com.tangem.core.ui.extensions import androidx.compose.runtime.Composable import androidx.compose.runtime.remember +import androidx.compose.ui.graphics.Color import androidx.compose.ui.text.AnnotatedString import androidx.compose.ui.text.SpanStyle import androidx.compose.ui.text.font.FontWeight @@ -53,4 +54,10 @@ fun AnnotatedString.Builder.appendMarkdown(markdownText: String, node: ASTNode): } } return this +} + +fun AnnotatedString.Builder.appendSpace() = append(" ") + +fun AnnotatedString.Builder.appendColored(text: String, color: Color) = withStyle(SpanStyle(color = color)) { + append(text) } \ 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 2f22994f64..4aab281036 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 @@ -9,8 +9,11 @@ import androidx.compose.runtime.ReadOnlyComposable import androidx.compose.ui.res.pluralStringResource import androidx.compose.ui.res.stringResource import androidx.compose.ui.text.AnnotatedString +import androidx.compose.ui.text.AnnotatedString.Builder import androidx.compose.ui.text.buildAnnotatedString import org.intellij.markdown.MarkdownElementTypes +import kotlin.contracts.ExperimentalContracts +import kotlin.contracts.contract /** * Utility class for creating text as [String] or [StringRes]. @@ -46,6 +49,13 @@ sealed interface TextReference { */ data class Str(val value: String) : TextReference + /** + * Annotated text + * + * @property value annotated string + */ + data class Annotated(val value: AnnotatedString) : TextReference + /** * Combined reference. It concatenates all [refs]. * @@ -81,6 +91,27 @@ fun stringReference(value: String): TextReference { return TextReference.Str(value) } +/** + * Creates a [TextReference] using an annotated string value. + * + * @param value The annotated string value. + * @return A [TextReference] representing the provided annotated string value. + */ +fun annotatedReference(value: AnnotatedString): TextReference { + return TextReference.Annotated(value) +} + +/** + * Creates a [TextReference] using an annotated string value. + * + * @param onAnnotated The annotated string builder. + * @return A [TextReference] representing the provided annotated string value. + */ +@Composable +inline fun annotatedReference(onAnnotated: Builder.() -> Unit): TextReference { + return TextReference.Annotated(buildAnnotatedString { onAnnotated() }) +} + /** * Creates a [TextReference] using a plural string resource ID with count and optional format arguments. * @@ -131,6 +162,7 @@ fun TextReference.resolveReference(): String { } is TextReference.PluralRes -> pluralStringResource(id, count, *formatArgs.toTypedArray()) is TextReference.Str -> value + is TextReference.Annotated -> value.text is TextReference.Combined -> { buildString { refs.forEach { @@ -153,6 +185,7 @@ fun TextReference.resolveReference(resources: Resources): String { } is TextReference.PluralRes -> resources.getQuantityString(id, count, *formatArgs.toTypedArray()) is TextReference.Str -> value + is TextReference.Annotated -> value.text is TextReference.Combined -> { buildString { refs.forEach { @@ -178,9 +211,10 @@ fun TextReference.resolveAnnotatedReference(): AnnotatedString { pluralStringResource(id, count, *formatArgs.toTypedArray()), ) is TextReference.Str -> formatAnnotated(value) + is TextReference.Annotated -> value is TextReference.Combined -> buildAnnotatedString { refs.forEach { - append(formatAnnotated(it.resolveReference())) + append(it.resolveAnnotatedReference()) } } } @@ -193,10 +227,21 @@ operator fun TextReference.plus(ref: TextReference): TextReference { is TextReference.PluralRes, is TextReference.Res, is TextReference.Str, + is TextReference.Annotated, -> TextReference.Combined(refs = wrappedList(this, ref)) } } +@Suppress("NOTHING_TO_INLINE") +@OptIn(ExperimentalContracts::class) +inline fun TextReference?.isNullOrEmpty(): Boolean { + contract { + returns(false) implies (this@isNullOrEmpty != null) + } + + return this == null || this == TextReference.EMPTY +} + @Composable private fun formatAnnotated(rawString: String): AnnotatedString { val markdownDescriptor = rememberMarkdownParser() diff --git a/core/ui/src/main/java/com/tangem/core/ui/haptic/MockHapticManager.kt b/core/ui/src/main/java/com/tangem/core/ui/haptic/MockHapticManager.kt index 876ee7a05d..ad74ee1bd1 100644 --- a/core/ui/src/main/java/com/tangem/core/ui/haptic/MockHapticManager.kt +++ b/core/ui/src/main/java/com/tangem/core/ui/haptic/MockHapticManager.kt @@ -1,16 +1,30 @@ package com.tangem.core.ui.haptic -object MockHapticManager : HapticManager { +import androidx.compose.ui.hapticfeedback.HapticFeedback +import androidx.compose.ui.hapticfeedback.HapticFeedbackType + +@Suppress("FunctionName") +fun MockHapticManager(mockHapticFeedback: HapticFeedback? = null): HapticManager = + if (mockHapticFeedback == null) MockHapticManager else MockHapticManagerImpl(mockHapticFeedback) + +val MockHapticManager: HapticManager = MockHapticManagerImpl() + +private class MockHapticManagerImpl( + private val mockHapticFeedback: HapticFeedback? = null, +) : HapticManager { override fun vibrateShort() { - /** Intentionnaly do nothing */ + mockHapticFeedback?.performHapticFeedback(HapticFeedbackType.TextHandleMove) + /** Intentionally do nothing */ } override fun vibrateMeduim() { - /** Intentionnaly do nothing */ + mockHapticFeedback?.performHapticFeedback(HapticFeedbackType.TextHandleMove) + /** Intentionally do nothing */ } override fun vibrateLong() { - /** Intentionnaly do nothing */ + mockHapticFeedback?.performHapticFeedback(HapticFeedbackType.LongPress) + /** Intentionally do nothing */ } } \ No newline at end of file diff --git a/core/ui/src/main/java/com/tangem/core/ui/message/EventMessageHandler.kt b/core/ui/src/main/java/com/tangem/core/ui/message/EventMessageHandler.kt index 0f4d117dab..782cd2a84f 100644 --- a/core/ui/src/main/java/com/tangem/core/ui/message/EventMessageHandler.kt +++ b/core/ui/src/main/java/com/tangem/core/ui/message/EventMessageHandler.kt @@ -1,5 +1,6 @@ package com.tangem.core.ui.message +import androidx.compose.runtime.Stable import com.tangem.core.decompose.ui.UiMessage import com.tangem.core.decompose.ui.UiMessageHandler import com.tangem.core.ui.event.StateEvent @@ -11,6 +12,7 @@ import kotlinx.coroutines.flow.StateFlow /** * Message handler that is used to show or remove an [EventMessage] in the UI. */ +@Stable class EventMessageHandler( private val events: MutableStateFlow> = MutableStateFlow(consumedEvent()), ) : UiMessageHandler, StateFlow> by events { 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 55321fa0b2..9b00a821e5 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 @@ -45,8 +45,10 @@ data class TangemDimens internal constructor( val size2: Dp = 2.dp, val size4: Dp = 4.dp, val size5: Dp = 5.dp, + val size6: Dp = 6.dp, val size7: Dp = 7.dp, val size8: Dp = 8.dp, + val size9: Dp = 9.dp, val size10: Dp = 10.dp, val size11: Dp = 11.dp, val size12: Dp = 12.dp, @@ -55,6 +57,7 @@ data class TangemDimens internal constructor( val size16: Dp = 16.dp, val size18: Dp = 18.dp, val size20: Dp = 20.dp, + val size22: Dp = 22.dp, val size24: Dp = 24.dp, val size28: Dp = 28.dp, val size30: Dp = 30.dp, @@ -81,8 +84,10 @@ data class TangemDimens internal constructor( val size90: Dp = 90.dp, val size93: Dp = 93.dp, val size96: Dp = 96.dp, + val size100: Dp = 100.dp, val size102: Dp = 102.dp, val size108: Dp = 108.dp, + val size110: Dp = 110.dp, val size116: Dp = 116.dp, val size120: Dp = 120.dp, val size142: Dp = 142.dp, @@ -99,9 +104,11 @@ data class TangemDimens internal constructor( val spacing2: Dp = 2.dp, val spacing3: Dp = 3.dp, val spacing4: Dp = 4.dp, + val spacing5: Dp = 5.dp, val spacing6: Dp = 6.dp, val spacing8: Dp = 8.dp, val spacing10: Dp = 10.dp, + val spacing11: Dp = 11.dp, val spacing12: Dp = 12.dp, val spacing14: Dp = 14.dp, val spacing15: Dp = 15.dp, @@ -115,7 +122,7 @@ data class TangemDimens internal constructor( val spacing30: Dp = 30.dp, val spacing32: Dp = 32.dp, val spacing34: Dp = 34.dp, - val spacing36: Dp = 34.dp, + val spacing36: Dp = 36.dp, val spacing38: Dp = 38.dp, val spacing40: Dp = 40.dp, val spacing44: Dp = 44.dp, diff --git a/core/ui/src/main/java/com/tangem/core/ui/res/TangemShapes.kt b/core/ui/src/main/java/com/tangem/core/ui/res/TangemShapes.kt index 8bf99452ed..5da8defa94 100644 --- a/core/ui/src/main/java/com/tangem/core/ui/res/TangemShapes.kt +++ b/core/ui/src/main/java/com/tangem/core/ui/res/TangemShapes.kt @@ -12,6 +12,7 @@ data class TangemShapes internal constructor( val roundedCornersMedium: Shape, val roundedCornersXMedium: Shape, val roundedCornersLarge: Shape, + val roundedCornersXLarge: Shape, val bottomSheet: Shape, val bottomSheetLarge: Shape, ) { @@ -22,6 +23,7 @@ data class TangemShapes internal constructor( roundedCornersMedium = RoundedCornerShape(size = dimens.radius12), roundedCornersXMedium = RoundedCornerShape(size = dimens.radius16), roundedCornersLarge = RoundedCornerShape(size = dimens.radius28), + roundedCornersXLarge = RoundedCornerShape(size = dimens.radius36), bottomSheet = RoundedCornerShape( topStart = dimens.radius16, topEnd = dimens.radius16, diff --git a/core/ui/src/main/java/com/tangem/core/ui/res/TangemTheme.kt b/core/ui/src/main/java/com/tangem/core/ui/res/TangemTheme.kt index 4f3287a86d..300231f9c3 100644 --- a/core/ui/src/main/java/com/tangem/core/ui/res/TangemTheme.kt +++ b/core/ui/src/main/java/com/tangem/core/ui/res/TangemTheme.kt @@ -1,21 +1,28 @@ package com.tangem.core.ui.res +import androidx.compose.foundation.text.selection.LocalTextSelectionColors +import androidx.compose.foundation.text.selection.TextSelectionColors import androidx.compose.material.Colors import androidx.compose.material.MaterialTheme import androidx.compose.material.ProvideTextStyle +import androidx.compose.material3.SnackbarHostState import androidx.compose.runtime.* +import androidx.compose.ui.graphics.Color +import com.google.accompanist.systemuicontroller.rememberSystemUiController +import com.tangem.core.ui.components.TangemShimmer import com.tangem.core.ui.haptic.HapticManager import com.tangem.core.ui.haptic.MockHapticManager - -// TODO: use isSystemInDarkTheme() for automatic color detection -internal const val IS_SYSTEM_IN_DARK_THEME: Boolean = false +import com.tangem.core.ui.windowsize.WindowSize +import com.valentinilk.shimmer.Shimmer @Composable fun TangemTheme( isDark: Boolean = false, + windowSize: WindowSize, typography: TangemTypography = TangemTheme.typography, dimens: TangemDimens = TangemTheme.dimens, hapticManager: HapticManager = MockHapticManager, + snackbarHostState: SnackbarHostState = remember { SnackbarHostState() }, content: @Composable () -> Unit, ) { val themeColors = if (isDark) darkThemeColors() else lightThemeColors() @@ -23,6 +30,16 @@ fun TangemTheme( .also { it.update(themeColors) } val shapes = remember { TangemShapes(dimens) } + val systemUiController = rememberSystemUiController() + + SideEffect { + systemUiController.setSystemBarsColor( + color = Color.Transparent, + darkIcons = !isDark, + isNavigationBarContrastEnforced = false, + ) + } + MaterialTheme( colors = materialThemeColors(colors = themeColors, isDark = isDark), ) { @@ -33,11 +50,18 @@ fun TangemTheme( LocalTangemShapes provides shapes, LocalIsInDarkTheme provides isDark, LocalHapticManager provides hapticManager, + LocalSnackbarHostState provides snackbarHostState, + LocalWindowSize provides windowSize, + LocalTextSelectionColors provides TangemTextSelectionColors, ) { - ProvideTextStyle( - value = TangemTheme.typography.body1, - content = content, - ) + CompositionLocalProvider( + LocalTangemShimmer provides TangemShimmer, + ) { + ProvideTextStyle( + value = TangemTheme.typography.body1, + content = content, + ) + } } } } @@ -124,7 +148,7 @@ private fun lightThemeColors(): TangemColors { ), stroke = TangemColors.Stroke( primary = TangemColorPalette.Light2, - secondary = TangemColorPalette.Dark5, + secondary = TangemColorPalette.Light5, transparency = TangemColorPalette.White, ), field = TangemColors.Field( @@ -184,6 +208,12 @@ private fun darkThemeColors(): TangemColors { ) } +@Stable +private val TangemTextSelectionColors = TextSelectionColors( + handleColor = TangemColorPalette.Azure, + backgroundColor = TangemColorPalette.Azure.copy(alpha = 0.4f), +) + private val LocalTangemColors = staticCompositionLocalOf { error("No TangemColors provided") } @@ -204,4 +234,16 @@ val LocalIsInDarkTheme = staticCompositionLocalOf { false } val LocalHapticManager = staticCompositionLocalOf { error("No HapticManager provided") +} + +val LocalSnackbarHostState = staticCompositionLocalOf { + error("No SnackbarHostState provided") +} + +val LocalWindowSize = staticCompositionLocalOf { + error("No WindowSize provided") +} + +val LocalTangemShimmer = staticCompositionLocalOf { + error("No TangemShimmer provided") } \ No newline at end of file diff --git a/core/ui/src/main/java/com/tangem/core/ui/res/TangemThemePreview.kt b/core/ui/src/main/java/com/tangem/core/ui/res/TangemThemePreview.kt index 2a9e0caf65..c3ed096dce 100644 --- a/core/ui/src/main/java/com/tangem/core/ui/res/TangemThemePreview.kt +++ b/core/ui/src/main/java/com/tangem/core/ui/res/TangemThemePreview.kt @@ -1,21 +1,44 @@ package com.tangem.core.ui.res import androidx.compose.foundation.isSystemInDarkTheme +import androidx.compose.foundation.layout.BoxWithConstraints import androidx.compose.runtime.Composable +import androidx.compose.runtime.CompositionLocalProvider +import androidx.compose.runtime.ProvidableCompositionLocal +import androidx.compose.runtime.compositionLocalOf +import androidx.compose.ui.platform.LocalHapticFeedback +import com.tangem.core.ui.haptic.MockHapticManager +import com.tangem.core.ui.windowsize.rememberWindowSizePreview @Composable fun TangemThemePreview( isDark: Boolean? = null, typography: TangemTypography = TangemTheme.typography, dimens: TangemDimens = TangemTheme.dimens, + alwaysShowBottomSheets: Boolean = true, content: @Composable () -> Unit, ) { val isDarkTheme = isDark ?: isSystemInDarkTheme() - TangemTheme( - isDark = isDarkTheme, - typography = typography, - dimens = dimens, - content = content, - ) + CompositionLocalProvider( + LocalBottomSheetAlwaysVisible provides alwaysShowBottomSheets, + ) { + BoxWithConstraints { + TangemTheme( + isDark = isDarkTheme, + typography = typography, + dimens = dimens, + windowSize = rememberWindowSizePreview(maxWidth, maxHeight), + hapticManager = MockHapticManager(LocalHapticFeedback.current), + content = content, + ) + } + } +} + +/** + * This is used to make the bottom sheet always visible in the Preview and should be `true` only in the Preview. + * */ +val LocalBottomSheetAlwaysVisible: ProvidableCompositionLocal = compositionLocalOf { + false } \ No newline at end of file diff --git a/core/ui/src/main/java/com/tangem/core/ui/screen/ComposeActivity.kt b/core/ui/src/main/java/com/tangem/core/ui/screen/ComposeActivity.kt index fe4f115dcd..9d4acd5fc0 100644 --- a/core/ui/src/main/java/com/tangem/core/ui/screen/ComposeActivity.kt +++ b/core/ui/src/main/java/com/tangem/core/ui/screen/ComposeActivity.kt @@ -12,6 +12,6 @@ abstract class ComposeActivity : ComponentActivity(), ComposeScreen { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) - setContentView(createComposeView(context = this)) + setContentView(createComposeView(context = this, activity = this)) } } \ No newline at end of file diff --git a/core/ui/src/main/java/com/tangem/core/ui/screen/ComposeBottomSheetFragment.kt b/core/ui/src/main/java/com/tangem/core/ui/screen/ComposeBottomSheetFragment.kt index b437a39cd5..75dc4e8a98 100644 --- a/core/ui/src/main/java/com/tangem/core/ui/screen/ComposeBottomSheetFragment.kt +++ b/core/ui/src/main/java/com/tangem/core/ui/screen/ComposeBottomSheetFragment.kt @@ -52,7 +52,7 @@ abstract class ComposeBottomSheetFragment : BottomSheetDialogFragment(), Compose override fun getTheme(): Int = R.style.AppTheme_TransparentBottomSheetDialog override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View { - return createComposeView(inflater.context) + return createComposeView(inflater.context, requireActivity()) } override fun onCreateDialog(savedInstanceState: Bundle?): Dialog { diff --git a/core/ui/src/main/java/com/tangem/core/ui/screen/ComposeFragment.kt b/core/ui/src/main/java/com/tangem/core/ui/screen/ComposeFragment.kt index c60bf1ba7b..48565c82d7 100644 --- a/core/ui/src/main/java/com/tangem/core/ui/screen/ComposeFragment.kt +++ b/core/ui/src/main/java/com/tangem/core/ui/screen/ComposeFragment.kt @@ -18,7 +18,7 @@ abstract class ComposeFragment : Fragment(), ComposeScreen { override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View { val isTransitionsInflated = TransitionInflater.from(requireContext()).inflateTransitions() - return createComposeView(inflater.context).also { + return createComposeView(inflater.context, requireActivity()).also { it.isTransitionGroup = isTransitionsInflated } } diff --git a/core/ui/src/main/java/com/tangem/core/ui/screen/ComposeScreen.kt b/core/ui/src/main/java/com/tangem/core/ui/screen/ComposeScreen.kt index 4c2faae280..d6b1869ec5 100644 --- a/core/ui/src/main/java/com/tangem/core/ui/screen/ComposeScreen.kt +++ b/core/ui/src/main/java/com/tangem/core/ui/screen/ComposeScreen.kt @@ -1,5 +1,6 @@ package com.tangem.core.ui.screen +import android.app.Activity import android.content.Context import androidx.compose.foundation.isSystemInDarkTheme import androidx.compose.foundation.layout.fillMaxSize @@ -10,6 +11,7 @@ import androidx.compose.ui.Modifier import androidx.compose.ui.platform.ComposeView import com.tangem.core.ui.UiDependencies import com.tangem.core.ui.res.TangemTheme +import com.tangem.core.ui.windowsize.rememberWindowSize import com.tangem.domain.apptheme.model.AppThemeMode /** @@ -50,14 +52,17 @@ internal interface ComposeScreen { * @param context The context. * @return A [ComposeView] instance with the defined screen content. */ -internal fun ComposeScreen.createComposeView(context: Context): ComposeView { +internal fun ComposeScreen.createComposeView(context: Context, activity: Activity): ComposeView { return ComposeView(context).apply { setContent { val appThemeMode by uiDependencies.appThemeModeHolder.appThemeMode + val windowSize = rememberWindowSize(activity = activity) TangemTheme( isDark = shouldUseDarkTheme(appThemeMode), + windowSize = windowSize, hapticManager = uiDependencies.hapticManager, + snackbarHostState = uiDependencies.globalSnackbarHostState, ) { ScreenContent(modifier = screenModifier) } diff --git a/core/ui/src/main/java/com/tangem/core/ui/utils/BigDecimalFormatter.kt b/core/ui/src/main/java/com/tangem/core/ui/utils/BigDecimalFormatter.kt index 0dbdded548..e5d94f85b7 100644 --- a/core/ui/src/main/java/com/tangem/core/ui/utils/BigDecimalFormatter.kt +++ b/core/ui/src/main/java/com/tangem/core/ui/utils/BigDecimalFormatter.kt @@ -1,6 +1,10 @@ package com.tangem.core.ui.utils +import android.icu.text.CompactDecimalFormat +import android.os.Build import com.tangem.domain.tokens.model.CryptoCurrency +import com.tangem.utils.StringsSigns.DASH_SIGN +import com.tangem.utils.StringsSigns.LOWER_SIGN import timber.log.Timber import java.math.BigDecimal import java.math.RoundingMode @@ -11,8 +15,8 @@ import java.util.Locale object BigDecimalFormatter { - const val EMPTY_BALANCE_SIGN = "—" - const val CAN_BE_LOWER_SIGN = "<" + const val EMPTY_BALANCE_SIGN = DASH_SIGN + const val CAN_BE_LOWER_SIGN = LOWER_SIGN private val FORMAT_THRESHOLD = BigDecimal("0.01") private const val TEMP_CURRENCY_CODE = "USD" @@ -33,7 +37,7 @@ object BigDecimalFormatter { maximumFractionDigits = decimals.coerceAtMost(maximumValue = 8) minimumFractionDigits = 2 isGroupingUsed = true - roundingMode = RoundingMode.DOWN + roundingMode = RoundingMode.HALF_UP } return formatter.format(cryptoAmount).let { @@ -89,7 +93,7 @@ object BigDecimalFormatter { maximumFractionDigits = cryptoCurrency.decimals minimumFractionDigits = 2 isGroupingUsed = true - roundingMode = RoundingMode.DOWN + roundingMode = RoundingMode.HALF_UP } return formatter.format(cryptoAmount).let { @@ -217,5 +221,77 @@ object BigDecimalFormatter { } } + /** + * Adds a proper currency sign for the provided formatted [amount] + * ex. '10.0k" -> "$10.0k", "string" -> "$string" + */ + fun addCurrencySymbolToStringAmount( + amount: String, + fiatCurrencyCode: String, + fiatCurrencySymbol: String, + locale: Locale = Locale.getDefault(), + ): String { + val sampleAmount = BigDecimal.TEN + val currency = getCurrency(fiatCurrencyCode) + + val formatter = NumberFormat.getCurrencyInstance(locale).apply { + maximumFractionDigits = 0 + minimumFractionDigits = 0 + this.currency = currency + } + + val formatted = formatter.format(sampleAmount) + .replace(currency.getSymbol(locale), fiatCurrencySymbol) + .replace(sampleAmount.toString(), amount) + + return formatted + } + + /** + * "123456.6" -> "$123.457K" + * "12345.6" -> "$123.046K" + */ + @Suppress("MagicNumber") + fun formatCompactAmount( + amount: BigDecimal, + fiatCurrencyCode: String, + fiatCurrencySymbol: String, + locale: Locale = Locale.getDefault(), + ): String { + if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N) { + return BigDecimalFormatterCompat.formatCompactAmountNoLocaleContext( + amount = amount, + fiatCurrencyCode = fiatCurrencyCode, + fiatCurrencySymbol = fiatCurrencySymbol, + locale = locale, + ) + } + + val scaledAmount = amount.setScale(0, RoundingMode.HALF_UP) + val digitsCount = scaledAmount.longValueExact().toString().count() + val digitsToFormat = 6 - when (digitsCount % 3) { + 0 -> 0 + 1 -> 2 + else -> 1 + } + + val formatter = CompactDecimalFormat.getInstance( + locale, + CompactDecimalFormat.CompactStyle.SHORT, + ).apply { + minimumSignificantDigits = 4 + maximumSignificantDigits = digitsToFormat + } + + val rawAmount = formatter.format(amount.setScale(0, RoundingMode.HALF_UP)) + + return addCurrencySymbolToStringAmount( + amount = rawAmount, + fiatCurrencyCode = fiatCurrencyCode, + fiatCurrencySymbol = fiatCurrencySymbol, + locale = locale, + ) + } + private fun BigDecimal.isLessThanThreshold() = this > BigDecimal.ZERO && this < FIAT_FORMAT_THRESHOLD } \ No newline at end of file diff --git a/core/ui/src/main/java/com/tangem/core/ui/utils/BigDecimalFormatterCompat.kt b/core/ui/src/main/java/com/tangem/core/ui/utils/BigDecimalFormatterCompat.kt new file mode 100644 index 0000000000..82aab46559 --- /dev/null +++ b/core/ui/src/main/java/com/tangem/core/ui/utils/BigDecimalFormatterCompat.kt @@ -0,0 +1,52 @@ +package com.tangem.core.ui.utils + +import java.math.BigDecimal +import java.math.RoundingMode +import java.util.Locale + +internal object BigDecimalFormatterCompat { + + /** + * Formats value as [BigDecimalFormatter.formatCompactAmount] does using only "T","B","M","K" suffixes + * Used for < API24 compatibility + */ + @Suppress("MagicNumber", "UnnecessaryParentheses") + fun formatCompactAmountNoLocaleContext( + amount: BigDecimal, + fiatCurrencyCode: String, + fiatCurrencySymbol: String, + locale: Locale = Locale.getDefault(), + ): String { + val value = amount.setScale(0, RoundingMode.HALF_UP).longValueExact() + + val formatted = when { + value > 1_000_000_000_000L -> { + val trillion = value / 1_000_000_000_000 + val billion = (value % 1_000_000_000_000) / 1_000_000_000 + "$trillion.${billion}T" + } + value > 1_000_000_000L -> { + val billion = value / 1_000_000_000 + val million = (value % 1_000_000_000) / 1_000_000 + "$billion.${million}B" + } + value > 1_000_000L -> { + val million = value / 1_000_000 + val thousand = (value % 1_000_000) / 1_000 + "$million.${thousand}M" + } + value > 1_000L -> { + val thousand = value / 1_000 + "${thousand}K" + } + else -> return value.toString() + } + + return BigDecimalFormatter.addCurrencySymbolToStringAmount( + amount = formatted, + fiatCurrencyCode = fiatCurrencyCode, + fiatCurrencySymbol = fiatCurrencySymbol, + locale = locale, + ) + } +} \ No newline at end of file diff --git a/core/ui/src/main/java/com/tangem/core/ui/utils/DensityUtils.kt b/core/ui/src/main/java/com/tangem/core/ui/utils/DensityUtils.kt new file mode 100644 index 0000000000..105d2416d3 --- /dev/null +++ b/core/ui/src/main/java/com/tangem/core/ui/utils/DensityUtils.kt @@ -0,0 +1,18 @@ +package com.tangem.core.ui.utils + +import androidx.compose.runtime.Composable +import androidx.compose.runtime.Stable +import androidx.compose.ui.platform.LocalDensity +import androidx.compose.ui.unit.Dp + +@Stable +@Composable +fun Dp.toPx(): Float = toPx(density = LocalDensity.current.density) + +@Stable +@Composable +fun convertPxToDp(px: Float): Dp = convertPxToDp(px, density = LocalDensity.current.density) + +fun Dp.toPx(density: Float): Float = this.value * density + +fun convertPxToDp(px: Float, density: Float): Dp = Dp(value = px / density) \ No newline at end of file diff --git a/core/ui/src/main/java/com/tangem/core/ui/utils/GrayscaleUtils.kt b/core/ui/src/main/java/com/tangem/core/ui/utils/GrayscaleUtils.kt index f3edb75b60..a71cf3875a 100644 --- a/core/ui/src/main/java/com/tangem/core/ui/utils/GrayscaleUtils.kt +++ b/core/ui/src/main/java/com/tangem/core/ui/utils/GrayscaleUtils.kt @@ -8,4 +8,13 @@ const val GRAY_SCALE_ALPHA = 0.4f const val NORMAL_ALPHA = 1f val GrayscaleColorFilter: ColorFilter - get() = ColorFilter.colorMatrix(ColorMatrix().apply { setToSaturation(GRAY_SCALE_SATURATION) }) \ No newline at end of file + get() = ColorFilter.colorMatrix(ColorMatrix().apply { setToSaturation(GRAY_SCALE_SATURATION) }) + +/** + * Returns alpha and color filter for grayscale if [isGrayscale] is true + */ +fun getGreyScaleColorFilter(isGrayscale: Boolean): Pair = if (isGrayscale) { + GRAY_SCALE_ALPHA to GrayscaleColorFilter +} else { + NORMAL_ALPHA to null +} \ No newline at end of file diff --git a/core/ui/src/main/java/com/tangem/core/ui/utils/ImageBackgroundContrastChecker.kt b/core/ui/src/main/java/com/tangem/core/ui/utils/ImageBackgroundContrastChecker.kt index ed6cab9758..7c9071598f 100644 --- a/core/ui/src/main/java/com/tangem/core/ui/utils/ImageBackgroundContrastChecker.kt +++ b/core/ui/src/main/java/com/tangem/core/ui/utils/ImageBackgroundContrastChecker.kt @@ -39,6 +39,6 @@ class ImageBackgroundContrastChecker( private companion object { // https://www.w3.org/TR/2008/REC-WCAG20-20081211/#contrast-ratiodef - private const val LOW_CONTRAST_RATIO = 1.5f + private const val LOW_CONTRAST_RATIO = 1.1f } } \ No newline at end of file diff --git a/core/ui/src/main/java/com/tangem/core/ui/utils/PathUtils.kt b/core/ui/src/main/java/com/tangem/core/ui/utils/PathUtils.kt new file mode 100644 index 0000000000..8ab1fe470b --- /dev/null +++ b/core/ui/src/main/java/com/tangem/core/ui/utils/PathUtils.kt @@ -0,0 +1,10 @@ +package com.tangem.core.ui.utils + +import androidx.compose.ui.geometry.Offset +import androidx.compose.ui.graphics.Path + +fun Path.lineTo(offset: Offset) = lineTo(offset.x, offset.y) + +fun Path.moveTo(offset: Offset) = moveTo(offset.x, offset.y) + +fun Path.quadraticBezierTo(control: Offset, end: Offset) = quadraticBezierTo(control.x, control.y, end.x, end.y) \ No newline at end of file diff --git a/core/ui/src/main/java/com/tangem/core/ui/utils/RequestPushPermission.kt b/core/ui/src/main/java/com/tangem/core/ui/utils/RequestPushPermission.kt new file mode 100644 index 0000000000..1b21fff1ef --- /dev/null +++ b/core/ui/src/main/java/com/tangem/core/ui/utils/RequestPushPermission.kt @@ -0,0 +1,42 @@ +package com.tangem.core.ui.utils + +import androidx.compose.runtime.Composable +import androidx.compose.runtime.LaunchedEffect +import androidx.compose.runtime.MutableState +import com.google.accompanist.permissions.ExperimentalPermissionsApi +import com.google.accompanist.permissions.isGranted +import com.google.accompanist.permissions.rememberPermissionState + +/** + * Returns push permission requester. + * Handles granting permission from app settings. + */ +@Suppress("LongParameterList") +@OptIn(ExperimentalPermissionsApi::class) +@Composable +fun requestPushPermission( + pushPermission: String?, + isClicked: MutableState, + onAllow: () -> Unit, + onDeny: () -> Unit, +): () -> Unit { + val permissionState = pushPermission?.let { permission -> + rememberPermissionState(permission = permission) + } + + // Check if user granted permission and close bottom sheet + LaunchedEffect(key1 = permissionState?.status, isClicked) { + if (!isClicked.value) return@LaunchedEffect + if (permissionState?.status?.isGranted == true) { + onAllow() + } else { + onDeny() + } + } + + return if (permissionState == null) { + {} + } else { + permissionState::launchPermissionRequest + } +} \ No newline at end of file diff --git a/core/ui/src/main/java/com/tangem/core/ui/utils/WindowInsetsZero.kt b/core/ui/src/main/java/com/tangem/core/ui/utils/WindowInsetsZero.kt new file mode 100644 index 0000000000..a17ac5f1ef --- /dev/null +++ b/core/ui/src/main/java/com/tangem/core/ui/utils/WindowInsetsZero.kt @@ -0,0 +1,12 @@ +package com.tangem.core.ui.utils + +import androidx.compose.foundation.layout.WindowInsets +import androidx.compose.ui.unit.Density +import androidx.compose.ui.unit.LayoutDirection + +object WindowInsetsZero : WindowInsets { + override fun getBottom(density: Density): Int = 0 + override fun getLeft(density: Density, layoutDirection: LayoutDirection): Int = 0 + override fun getRight(density: Density, layoutDirection: LayoutDirection): Int = 0 + override fun getTop(density: Density): Int = 0 +} \ No newline at end of file diff --git a/core/ui/src/main/java/com/tangem/core/ui/windowsize/WindowSize.kt b/core/ui/src/main/java/com/tangem/core/ui/windowsize/WindowSize.kt new file mode 100644 index 0000000000..ed47c74673 --- /dev/null +++ b/core/ui/src/main/java/com/tangem/core/ui/windowsize/WindowSize.kt @@ -0,0 +1,99 @@ +package com.tangem.core.ui.windowsize + +import android.app.Activity +import androidx.compose.runtime.Composable +import androidx.compose.runtime.remember +import androidx.compose.ui.geometry.Size +import androidx.compose.ui.graphics.toComposeRect +import androidx.compose.ui.platform.LocalConfiguration +import androidx.compose.ui.platform.LocalDensity +import androidx.compose.ui.unit.Dp +import androidx.compose.ui.unit.dp +import androidx.window.layout.WindowMetricsCalculator + +/** + * The preferred way to determine the window size is because it provides the actual size of the window as opposed to + * [LocalConfiguration.current.screenHeightDp] + * + * @property width actual window width + * @property height actual window height + * @property widthSizeType window size type based on width + * @property heightSizeType window size type based on height + * @property smallestSize smallest size of width and height + */ +data class WindowSize( + val width: Dp, + val height: Dp, +) { + val widthSizeType: WindowSizeType = getWidthWindowSizeType(width) + val heightSizeType: WindowSizeType = getHeightWindowSizeType(height) + val smallestSize: Dp = minOf(width, height) + + fun widthAtLeast(type: WindowSizeType): Boolean = this.widthSizeType.ordinal >= type.ordinal + + fun widthAtLeast(value: Dp): Boolean = this.width >= value + + fun heightAtLeast(type: WindowSizeType): Boolean = this.heightSizeType.ordinal >= type.ordinal + + fun heightAtLeast(value: Dp): Boolean = this.height >= value + + fun widthAtMost(type: WindowSizeType): Boolean = this.widthSizeType.ordinal <= type.ordinal + + fun widthAtMost(value: Dp): Boolean = this.width <= value + + fun heightAtMost(type: WindowSizeType): Boolean = this.heightSizeType.ordinal <= type.ordinal + + fun heightAtMost(value: Dp): Boolean = this.height <= value + + private fun getWidthWindowSizeType(windowDp: Dp): WindowSizeType = when { + windowDp <= 320.dp -> WindowSizeType.ExtraSmall + windowDp <= 360.dp -> WindowSizeType.Small + windowDp <= 540.dp -> WindowSizeType.Normal + windowDp <= 700.dp -> WindowSizeType.Large + else -> WindowSizeType.ExtraLarge + } + + private fun getHeightWindowSizeType(heightDp: Dp): WindowSizeType = when { + heightDp <= 480.dp -> WindowSizeType.ExtraSmall + heightDp <= 640.dp -> WindowSizeType.Small + heightDp <= 860.dp -> WindowSizeType.Normal + heightDp <= 1100.dp -> WindowSizeType.Large + else -> WindowSizeType.ExtraLarge + } +} + +enum class WindowSizeType { + ExtraSmall, Small, Normal, Large, ExtraLarge +} + +@Composable +fun rememberWindowSize(activity: Activity): WindowSize { + val windowBoundsSize = rememberWindowBoundsSize(activity) + val windowDpSize = with(LocalDensity.current) { + windowBoundsSize.toDpSize() + } + + return WindowSize( + width = windowDpSize.width, + height = windowDpSize.height, + ) +} + +@Composable +internal fun rememberWindowSizePreview(width: Dp, height: Dp): WindowSize { + return remember(width, height) { + WindowSize( + width = width, + height = height, + ) + } +} + +@Composable +private fun rememberWindowBoundsSize(activity: Activity): Size { + val configuration = LocalConfiguration.current + val windowMetrics = remember(configuration) { + WindowMetricsCalculator.getOrCreate().computeCurrentWindowMetrics(activity) + } + return windowMetrics.bounds.toComposeRect().size +} \ No newline at end of file diff --git a/app/src/main/res/drawable/ic_add_friends.xml b/core/ui/src/main/res/drawable/ic_add_friends_24.xml similarity index 100% rename from app/src/main/res/drawable/ic_add_friends.xml rename to core/ui/src/main/res/drawable/ic_add_friends_24.xml diff --git a/core/ui/src/main/res/drawable/ic_card_foget_24.xml b/core/ui/src/main/res/drawable/ic_card_foget_24.xml new file mode 100644 index 0000000000..77d2117ba5 --- /dev/null +++ b/core/ui/src/main/res/drawable/ic_card_foget_24.xml @@ -0,0 +1,10 @@ + + + diff --git a/app/src/main/res/drawable/ic_card_settings.xml b/core/ui/src/main/res/drawable/ic_card_settings_24.xml similarity index 100% rename from app/src/main/res/drawable/ic_card_settings.xml rename to core/ui/src/main/res/drawable/ic_card_settings_24.xml diff --git a/core/ui/src/main/res/drawable/ic_check_circle_24.xml b/core/ui/src/main/res/drawable/ic_check_circle_24.xml new file mode 100644 index 0000000000..21b193accf --- /dev/null +++ b/core/ui/src/main/res/drawable/ic_check_circle_24.xml @@ -0,0 +1,5 @@ + + + + + diff --git a/core/ui/src/main/res/drawable/ic_infinity_24.xml b/core/ui/src/main/res/drawable/ic_infinity_24.xml new file mode 100644 index 0000000000..cf0d1b2c54 --- /dev/null +++ b/core/ui/src/main/res/drawable/ic_infinity_24.xml @@ -0,0 +1,5 @@ + + + + + diff --git a/core/ui/src/main/res/drawable/ic_more_cards_24.xml b/core/ui/src/main/res/drawable/ic_more_cards_24.xml new file mode 100644 index 0000000000..1fd80fa554 --- /dev/null +++ b/core/ui/src/main/res/drawable/ic_more_cards_24.xml @@ -0,0 +1,11 @@ + + + diff --git a/core/ui/src/main/res/drawable/ic_notifications_unread_24.xml b/core/ui/src/main/res/drawable/ic_notifications_unread_24.xml new file mode 100644 index 0000000000..c50e451c69 --- /dev/null +++ b/core/ui/src/main/res/drawable/ic_notifications_unread_24.xml @@ -0,0 +1,11 @@ + + + + + + + + + + + diff --git a/core/ui/src/main/res/drawable/ic_plus_mini_28.xml b/core/ui/src/main/res/drawable/ic_plus_mini_28.xml new file mode 100644 index 0000000000..e6e483128c --- /dev/null +++ b/core/ui/src/main/res/drawable/ic_plus_mini_28.xml @@ -0,0 +1,10 @@ + + + diff --git a/core/ui/src/main/res/drawable/ic_rocket_launch_24.xml b/core/ui/src/main/res/drawable/ic_rocket_launch_24.xml new file mode 100644 index 0000000000..a7b572f5f0 --- /dev/null +++ b/core/ui/src/main/res/drawable/ic_rocket_launch_24.xml @@ -0,0 +1,11 @@ + + + + + + + + + + + diff --git a/core/ui/src/main/res/drawable/ic_staking_24.xml b/core/ui/src/main/res/drawable/ic_staking_24.xml new file mode 100644 index 0000000000..9a74909897 --- /dev/null +++ b/core/ui/src/main/res/drawable/ic_staking_24.xml @@ -0,0 +1,5 @@ + + + + + diff --git a/core/ui/src/main/res/drawable/ic_storefront_24.xml b/core/ui/src/main/res/drawable/ic_storefront_24.xml new file mode 100644 index 0000000000..7f17e6c496 --- /dev/null +++ b/core/ui/src/main/res/drawable/ic_storefront_24.xml @@ -0,0 +1,11 @@ + + + + + + + + + + + diff --git a/core/utils/src/main/java/com/tangem/utils/StringsSigns.kt b/core/utils/src/main/java/com/tangem/utils/StringsSigns.kt new file mode 100644 index 0000000000..15d69db683 --- /dev/null +++ b/core/utils/src/main/java/com/tangem/utils/StringsSigns.kt @@ -0,0 +1,12 @@ +package com.tangem.utils + +object StringsSigns { + + const val STARS = "\u2217\u2217\u2217" + const val DOT = "•" + const val PLUS = "+" + const val MINUS = "-" + const val DASH_SIGN = "—" + const val LOWER_SIGN = "<" + const val TILDE_SIGN = "~" +} \ No newline at end of file diff --git a/core/utils/src/main/java/com/tangem/utils/extensions/BigDecimalExt.kt b/core/utils/src/main/java/com/tangem/utils/extensions/BigDecimalExt.kt new file mode 100644 index 0000000000..d09f3f6a6d --- /dev/null +++ b/core/utils/src/main/java/com/tangem/utils/extensions/BigDecimalExt.kt @@ -0,0 +1,10 @@ +package com.tangem.utils.extensions + +import java.math.BigDecimal + +/** + * Converts `BigDecimal?` to `BigDecimal` + * + * If `BigDecimal?` is `null`, returns `BigDecimal.ZERO` + */ +fun BigDecimal?.orZero(): BigDecimal = this ?: BigDecimal.ZERO \ No newline at end of file diff --git a/core/utils/src/main/java/com/tangem/utils/transformer/Transformer.kt b/core/utils/src/main/java/com/tangem/utils/transformer/Transformer.kt new file mode 100644 index 0000000000..9c271d0920 --- /dev/null +++ b/core/utils/src/main/java/com/tangem/utils/transformer/Transformer.kt @@ -0,0 +1,8 @@ +package com.tangem.utils.transformer + +/** + * Transforms state to updated state. + */ +interface Transformer { + fun transform(prevState: S): S +} \ No newline at end of file diff --git a/data/card/src/main/java/com/tangem/data/card/DefaultCardRepository.kt b/data/card/src/main/java/com/tangem/data/card/DefaultCardRepository.kt index d0250fd7c3..5241c8562b 100644 --- a/data/card/src/main/java/com/tangem/data/card/DefaultCardRepository.kt +++ b/data/card/src/main/java/com/tangem/data/card/DefaultCardRepository.kt @@ -80,24 +80,10 @@ internal class DefaultCardRepository( return appPreferencesStore.getSyncOrDefault(key = PreferencesKeys.IS_TANGEM_TOS_ACCEPTED_KEY, default = false) } - override suspend fun isStart2CoinTOSAccepted(cardId: String): Boolean { - return appPreferencesStore.getSyncOrDefault( - key = PreferencesKeys.getStart2CoinTOSAcceptedKey(region = getRegion(cardId)), - default = false, - ) - } - override suspend fun acceptTangemTOS() { return appPreferencesStore.store(key = PreferencesKeys.IS_TANGEM_TOS_ACCEPTED_KEY, true) } - override suspend fun acceptStart2CoinTOS(cardId: String) { - appPreferencesStore.store( - key = PreferencesKeys.getStart2CoinTOSAcceptedKey(region = getRegion(cardId)), - value = true, - ) - } - private suspend fun AppPreferencesStore.editUsedCards(cardId: String, update: (UsedCardInfo) -> UsedCardInfo) { editData { mutablePreferences -> val usedCards = mutablePreferences.getUsedCards() @@ -127,16 +113,5 @@ internal class DefaultCardRepository( .firstOrNull { it.cardId == cardId } } - private fun getRegion(cardId: String): String? { - if (cardId.isEmpty()) return null - - return when (cardId[1]) { - '0' -> "fr" - '1' -> "ch" - '2' -> "at" - else -> null - } - } - private fun createDefaultUsedCardInfo(cardId: String) = UsedCardInfo(cardId = cardId) } \ No newline at end of file diff --git a/data/feedback/build.gradle.kts b/data/feedback/build.gradle.kts index 4847e15ddd..e936310c64 100644 --- a/data/feedback/build.gradle.kts +++ b/data/feedback/build.gradle.kts @@ -37,7 +37,9 @@ dependencies { implementation(projects.domain.feedback) implementation(projects.domain.legacy) - implementation(projects.libs.blockchainSdk) implementation(projects.domain.models) + implementation(projects.domain.wallets) implementation(projects.domain.wallets.models) + + implementation(projects.libs.blockchainSdk) } \ No newline at end of file diff --git a/data/feedback/src/main/java/com/tangem/data/feedback/DefaultFeedbackRepository.kt b/data/feedback/src/main/java/com/tangem/data/feedback/DefaultFeedbackRepository.kt index 4bf2f7eb2a..b5313ac608 100644 --- a/data/feedback/src/main/java/com/tangem/data/feedback/DefaultFeedbackRepository.kt +++ b/data/feedback/src/main/java/com/tangem/data/feedback/DefaultFeedbackRepository.kt @@ -9,12 +9,14 @@ import com.tangem.data.feedback.converters.CardInfoConverter import com.tangem.datasource.local.preferences.AppPreferencesStore import com.tangem.datasource.local.preferences.PreferencesKeys import com.tangem.datasource.local.preferences.utils.getObjectMap -import com.tangem.datasource.local.userwallet.UserWalletsStore import com.tangem.datasource.local.walletmanager.WalletManagersStore import com.tangem.domain.feedback.models.* import com.tangem.domain.feedback.repository.FeedbackRepository -import com.tangem.domain.wallets.models.UserWallet +import com.tangem.domain.models.scan.ScanResponse +import com.tangem.domain.wallets.legacy.UserWalletsListManager import com.tangem.domain.wallets.models.UserWalletId +import com.tangem.utils.coroutines.CoroutineDispatcherProvider +import com.tangem.utils.coroutines.runCatching import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.update import timber.log.Timber @@ -25,43 +27,47 @@ import java.io.StringWriter /** * Implementation of [FeedbackRepository] * - * @property appPreferencesStore application preferences store - * @property userWalletsStore user wallets store - * @property walletManagersStore wallet managers store - * @property context context for getting app version + * @property appPreferencesStore application preferences store + * @property userWalletsListManager user wallets list manager + * @property walletManagersStore wallet managers store + * @property context context for getting app version + * @property dispatchers coroutine dispatchers provider * [REDACTED_AUTHOR] */ internal class DefaultFeedbackRepository( private val appPreferencesStore: AppPreferencesStore, - private val userWalletsStore: UserWalletsStore, + private val userWalletsListManager: UserWalletsListManager, private val walletManagersStore: WalletManagersStore, private val context: Context, + private val dispatchers: CoroutineDispatcherProvider, ) : FeedbackRepository { private val blockchainsErrors = MutableStateFlow>(emptyMap()) - override suspend fun getUserWalletsInfo(): UserWalletsInfo { + override suspend fun getCardInfo(scanResponse: ScanResponse) = CardInfoConverter.convert(value = scanResponse) + + override suspend fun getUserWalletsInfo(userWalletId: UserWalletId?): UserWalletsInfo { return UserWalletsInfo( - selectedUserWalletId = getSelectedUserWallet().walletId.stringValue, - totalUserWallets = userWalletsStore.getAllSyncOrNull()?.size ?: error("No user wallets found"), + selectedUserWalletId = userWalletId?.stringValue ?: "card isn't activated", + totalUserWallets = userWalletsListManager.walletsCount, ) } - override suspend fun getCardInfo(): CardInfo { - return CardInfoConverter.convert(value = getSelectedUserWallet()) - } - - override suspend fun getBlockchainInfoList(): List { + override suspend fun getBlockchainInfoList(userWalletId: UserWalletId): List { return walletManagersStore - .getAllSync(userWalletId = getSelectedUserWallet().walletId) + .getAllSync(userWalletId = userWalletId) .map(BlockchainInfoConverter::convert) } - override suspend fun getBlockchainInfo(blockchainId: String, derivationPath: String?): BlockchainInfo? { + override suspend fun getBlockchainInfo( + userWalletId: UserWalletId, + blockchainId: String, + derivationPath: String?, + ): BlockchainInfo? { return walletManagersStore .getSyncOrNull( - userWalletId = getSelectedUserWallet().walletId, + userWalletId = userWalletId, blockchain = Blockchain.fromId(blockchainId), derivationPath = derivationPath, ) @@ -77,18 +83,18 @@ internal class DefaultFeedbackRepository( } override fun saveBlockchainErrorInfo(error: BlockchainErrorInfo) { + val userWallet = userWalletsListManager.selectedUserWalletSync ?: error("UserWallet is not selected") + blockchainsErrors.update { it.toMutableMap().apply { - put(getSelectedUserWallet().walletId, error) + put(userWallet.walletId, error) } } } - override suspend fun getBlockchainErrorInfo(): BlockchainErrorInfo? { - return blockchainsErrors.value[getSelectedUserWallet().walletId].also { - if (it == null) { - Timber.e("Blockchain error info is null for ${getSelectedUserWallet().walletId}") - } + override suspend fun getBlockchainErrorInfo(userWalletId: UserWalletId): BlockchainErrorInfo? { + return blockchainsErrors.value[userWalletId].also { + if (it == null) Timber.e("Blockchain error info is null for $userWalletId") } } @@ -99,7 +105,7 @@ internal class DefaultFeedbackRepository( } override suspend fun createLogFile(logs: String): File? { - return try { + return runCatching(dispatchers.io) { val file = File(context.filesDir, LOGS_FILE) file.delete() file.createNewFile() @@ -113,8 +119,8 @@ internal class DefaultFeedbackRepository( fileWriter.close() file - } catch (ex: Exception) { - Timber.e(ex, "Logs file isn't created") + }.getOrElse { + Timber.e(it, "Logs file isn't created") null } } @@ -130,11 +136,6 @@ internal class DefaultFeedbackRepository( ) } - private fun getSelectedUserWallet(): UserWallet { - return userWalletsStore.selectedUserWalletOrNull - ?: error("UserWallet is not selected") - } - private companion object { const val LOGS_FILE = "logs.txt" } diff --git a/data/feedback/src/main/java/com/tangem/data/feedback/converters/CardInfoConverter.kt b/data/feedback/src/main/java/com/tangem/data/feedback/converters/CardInfoConverter.kt index 7d16454467..c4aafd2bf2 100644 --- a/data/feedback/src/main/java/com/tangem/data/feedback/converters/CardInfoConverter.kt +++ b/data/feedback/src/main/java/com/tangem/data/feedback/converters/CardInfoConverter.kt @@ -2,28 +2,36 @@ package com.tangem.data.feedback.converters import com.tangem.domain.common.TapWorkarounds.isStart2Coin import com.tangem.domain.feedback.models.CardInfo -import com.tangem.domain.wallets.models.UserWallet +import com.tangem.domain.models.scan.CardDTO +import com.tangem.domain.models.scan.ScanResponse +import com.tangem.domain.wallets.builder.UserWalletIdBuilder +import com.tangem.domain.wallets.models.UserWalletId import com.tangem.utils.converter.Converter /** - * Converter from [UserWallet] to [CardInfo] + * Converter from [ScanResponse] to [CardInfo] * [REDACTED_AUTHOR] */ -internal object CardInfoConverter : Converter { +internal object CardInfoConverter : Converter { - override fun convert(value: UserWallet): CardInfo { - return with(value.scanResponse) { + override fun convert(value: ScanResponse): CardInfo { + return with(value) { CardInfo( + userWalletId = createUserWalletId(scanResponse = value), cardId = card.cardId, firmwareVersion = card.firmwareVersion.stringValue, cardBlockchain = walletData?.blockchain, signedHashesList = card.wallets.map { CardInfo.SignedHashes(curve = it.curve.curve, total = it.totalSignedHashes?.toString()) }, - isImported = value.isImported, - isStart2Coin = value.scanResponse.card.isStart2Coin, + isImported = value.card.wallets.any(CardDTO.Wallet::isImported), + isStart2Coin = value.card.isStart2Coin, ) } } + + private fun createUserWalletId(scanResponse: ScanResponse): UserWalletId? { + return UserWalletIdBuilder.scanResponse(scanResponse = scanResponse).build() + } } \ No newline at end of file diff --git a/data/feedback/src/main/java/com/tangem/data/feedback/di/FeedbackRepositoryModule.kt b/data/feedback/src/main/java/com/tangem/data/feedback/di/FeedbackRepositoryModule.kt index 5a00938959..393a30cf25 100644 --- a/data/feedback/src/main/java/com/tangem/data/feedback/di/FeedbackRepositoryModule.kt +++ b/data/feedback/src/main/java/com/tangem/data/feedback/di/FeedbackRepositoryModule.kt @@ -3,9 +3,10 @@ package com.tangem.data.feedback.di import android.content.Context import com.tangem.data.feedback.DefaultFeedbackRepository import com.tangem.datasource.local.preferences.AppPreferencesStore -import com.tangem.datasource.local.userwallet.UserWalletsStore import com.tangem.datasource.local.walletmanager.WalletManagersStore import com.tangem.domain.feedback.repository.FeedbackRepository +import com.tangem.domain.wallets.legacy.UserWalletsListManager +import com.tangem.utils.coroutines.CoroutineDispatcherProvider import dagger.Module import dagger.Provides import dagger.hilt.InstallIn @@ -21,10 +22,17 @@ internal object FeedbackRepositoryModule { @Singleton fun provideFeedbackRepository( appPreferencesStore: AppPreferencesStore, - userWalletsStore: UserWalletsStore, + userWalletsListManager: UserWalletsListManager, walletManagersStore: WalletManagersStore, @ApplicationContext context: Context, + dispatchers: CoroutineDispatcherProvider, ): FeedbackRepository { - return DefaultFeedbackRepository(appPreferencesStore, userWalletsStore, walletManagersStore, context) + return DefaultFeedbackRepository( + appPreferencesStore = appPreferencesStore, + userWalletsListManager = userWalletsListManager, + walletManagersStore = walletManagersStore, + context = context, + dispatchers = dispatchers, + ) } } \ No newline at end of file diff --git a/data/markets/.gitignore b/data/markets/.gitignore new file mode 100644 index 0000000000..42afabfd2a --- /dev/null +++ b/data/markets/.gitignore @@ -0,0 +1 @@ +/build \ No newline at end of file diff --git a/data/markets/build.gradle.kts b/data/markets/build.gradle.kts new file mode 100644 index 0000000000..98b32e7c97 --- /dev/null +++ b/data/markets/build.gradle.kts @@ -0,0 +1,34 @@ +plugins { + alias(deps.plugins.android.library) + alias(deps.plugins.kotlin.android) + alias(deps.plugins.kotlin.kapt) + alias(deps.plugins.hilt.android) + id("configuration") +} + +android { + namespace = "com.tangem.data.markets" +} + +dependencies { + implementation(projects.core.datasource) + implementation(projects.core.utils) + implementation(projects.core.pagination) + implementation(projects.domain.tokens.models) + implementation(projects.domain.markets) + implementation(projects.data.common) + + // region DI + implementation(deps.hilt.android) + kapt(deps.hilt.kapt) + // endregion + + // region Others dependencies + implementation(deps.kotlin.coroutines) + implementation(deps.moshi) + implementation(deps.moshi.kotlin) + implementation(deps.timber) + + implementation(projects.libs.blockchainSdk) + // endregion +} diff --git a/data/markets/src/main/java/com/tangem/data/markets/DefaultMarketsTokenRepository.kt b/data/markets/src/main/java/com/tangem/data/markets/DefaultMarketsTokenRepository.kt new file mode 100644 index 0000000000..be83e51fa2 --- /dev/null +++ b/data/markets/src/main/java/com/tangem/data/markets/DefaultMarketsTokenRepository.kt @@ -0,0 +1,92 @@ +package com.tangem.data.markets + +import com.tangem.data.markets.converters.* +import com.tangem.data.markets.utils.retryOnError +import com.tangem.datasource.api.common.response.getOrThrow +import com.tangem.datasource.api.markets.TangemTechMarketsApi +import com.tangem.datasource.api.tangemTech.TangemTechApi +import com.tangem.domain.markets.* +import com.tangem.domain.markets.repositories.MarketsTokenRepository +import com.tangem.pagination.* +import com.tangem.pagination.fetcher.LimitOffsetBatchFetcher +import com.tangem.utils.coroutines.CoroutineDispatcherProvider +import java.util.concurrent.atomic.AtomicLong + +internal class DefaultMarketsTokenRepository( + private val marketsApi: TangemTechMarketsApi, + private val tangemTechApi: TangemTechApi, + private val dispatcherProvider: CoroutineDispatcherProvider, +) : MarketsTokenRepository { + + private val tokenListConverter = TokenMarketListConverter() + + private fun createTokenMarketsFetcher(firstBatchSize: Int, nextBatchSize: Int) = LimitOffsetBatchFetcher( + prefetchDistance = firstBatchSize, + batchSize = nextBatchSize, + subFetcher = object : LimitOffsetBatchFetcher.SubFetcher> { + + val requestTimeStamp = AtomicLong(0) + + override suspend fun fetch( + request: LimitOffsetBatchFetcher.Request, + lastResult: BatchFetchResult>?, + isFirstBatchFetching: Boolean, + ): BatchFetchResult> { + val searchText = + if (request.params.searchText.isNullOrBlank()) null else request.params.searchText + + val requestCall = suspend { + marketsApi.getCoinsList( + currency = request.params.fiatPriceCurrency, + interval = request.params.priceChangeInterval.toRequestParam(), + order = request.params.order.toRequestParam(), + search = searchText, + generalCoins = request.params.showUnder100kMarketCapTokens.not(), + offset = request.offset, + limit = request.limit, + ).getOrThrow() + } + + // we shouldn't infinitely retry on the first batch request + val res = if (isFirstBatchFetching) { + requestCall() + } else { + retryOnError(priority = true) { + requestCall() + } + } + + if (isFirstBatchFetching) { + requestTimeStamp.set(0) // TODO when backend is ready + } + + val last = res.tokens.size < request.limit + + return BatchFetchResult.Success( + data = tokenListConverter.convert(res), + last = last, + empty = res.tokens.isEmpty(), + ) + } + }, + ) + + override fun getTokenListFlow( + batchingContext: BatchingContext, + firstBatchSize: Int, + nextBatchSize: Int, + ): BatchFlow, TokenMarketUpdateRequest> { + val tokenMarketsUpdateFetcher = MarketsBatchUpdateFetcher( + tangemTechApi = tangemTechApi, + marketsApi = marketsApi, + ) + + return BatchListSource( + fetchDispatcher = dispatcherProvider.io, + context = batchingContext, + generateNewKey = { it.size }, + batchFetcher = createTokenMarketsFetcher(firstBatchSize = firstBatchSize, nextBatchSize = nextBatchSize), + updateFetcher = tokenMarketsUpdateFetcher, + ).toBatchFlow() + } +} \ No newline at end of file diff --git a/data/markets/src/main/java/com/tangem/data/markets/MarketsBatchUpdateFetcher.kt b/data/markets/src/main/java/com/tangem/data/markets/MarketsBatchUpdateFetcher.kt new file mode 100644 index 0000000000..625f90797d --- /dev/null +++ b/data/markets/src/main/java/com/tangem/data/markets/MarketsBatchUpdateFetcher.kt @@ -0,0 +1,119 @@ +package com.tangem.data.markets + +import com.tangem.data.markets.converters.TokenListChartConverter +import com.tangem.data.markets.converters.TokenMarketChartsConverter +import com.tangem.data.markets.converters.TokenQuotesConverter +import com.tangem.data.markets.converters.toRequestParam +import com.tangem.data.markets.utils.retryOnError +import com.tangem.datasource.api.common.response.getOrThrow +import com.tangem.datasource.api.markets.TangemTechMarketsApi +import com.tangem.datasource.api.markets.models.response.TokenMarketChartListResponse +import com.tangem.datasource.api.tangemTech.TangemTechApi +import com.tangem.domain.markets.TokenMarket +import com.tangem.domain.markets.TokenMarketUpdateRequest +import com.tangem.pagination.Batch +import com.tangem.pagination.BatchUpdateFetcher +import com.tangem.pagination.BatchUpdateResult +import kotlinx.coroutines.* + +internal class MarketsBatchUpdateFetcher( + private val marketsApi: TangemTechMarketsApi, + private val tangemTechApi: TangemTechApi, +) : BatchUpdateFetcher, TokenMarketUpdateRequest> { + + private val tokenListChartsConverter = TokenMarketChartsConverter(TokenListChartConverter()) + private val tokenQuotesConverter = TokenQuotesConverter() + + override suspend fun BatchUpdateFetcher.UpdateContext>.fetchUpdateAsync( + toUpdate: List>>, + updateRequest: TokenMarketUpdateRequest, + ) { + val idsToUpdate = toUpdate.map { batch -> + batch.key to batch.data.map { it.id } + } + + when (updateRequest) { + is TokenMarketUpdateRequest.UpdateChart -> coroutineScope { + val updateTasks = idsToUpdate.map { batchIds -> + async { + retryOnError { + marketsApi.getCoinsListCharts( + coinIds = batchIds.second.joinToString(separator = ","), + interval = updateRequest.interval.toRequestParam(), + currency = updateRequest.currency, + ).getOrThrow() + } + } + } + + updateTasks.forEachIndexed { index, deferred -> + launch { + val res = deferred.await() + val batchToUpdate = toUpdate[index] + + update { + val resBatch = changeChartsInBatches( + updateRequest = updateRequest, + batchToUpdate = batchToUpdate, + update = res, + ) + BatchUpdateResult.Success(resBatch) + } + } + } + } + is TokenMarketUpdateRequest.UpdateQuotes -> { + val quotesRes = retryOnError { + tangemTechApi.getQuotes( + currencyId = updateRequest.currencyId, + coinIds = idsToUpdate.map { it.second }.flatten().joinToString(separator = ","), + fields = quoteFields.joinToString(separator = ","), + ).getOrThrow() + } + + update { + val res = toUpdate.map { batch -> + batch.copy( + data = batch.data.map { + it.copy(tokenQuotes = tokenQuotesConverter.convert(it.id, quotesRes)) + }, + ) + } + + BatchUpdateResult.Success(res) + } + } + } + } + + private fun List>>.changeChartsInBatches( + updateRequest: TokenMarketUpdateRequest.UpdateChart, + batchToUpdate: Batch>, + update: TokenMarketChartListResponse, + ): List>> = mapNotNull { resultBatch -> + if (batchToUpdate.key != resultBatch.key) return@mapNotNull null + + Batch( + key = batchToUpdate.key, + data = batchToUpdate.data.map { + it.copy( + tokenCharts = tokenListChartsConverter.convert( + chartsToCopy = it.tokenCharts, + tokenId = it.id, + interval = updateRequest.interval, + value = update, + ), + ) + }, + ) + } + + companion object { + private val quoteFields = listOf( + "price", + "priceChange24h", + "priceChange1w", + "priceChange30d", + ) + } +} \ No newline at end of file diff --git a/data/markets/src/main/java/com/tangem/data/markets/converters/TokenListChartConverter.kt b/data/markets/src/main/java/com/tangem/data/markets/converters/TokenListChartConverter.kt new file mode 100644 index 0000000000..0b4cf678c6 --- /dev/null +++ b/data/markets/src/main/java/com/tangem/data/markets/converters/TokenListChartConverter.kt @@ -0,0 +1,16 @@ +package com.tangem.data.markets.converters + +import com.tangem.datasource.api.markets.models.response.TokenMarketChartResponse +import com.tangem.domain.markets.PriceChangeInterval +import com.tangem.domain.markets.TokenChart + +class TokenListChartConverter { + + fun convert(interval: PriceChangeInterval, value: TokenMarketChartResponse): TokenChart { + return TokenChart( + interval = interval, + priceY = value.prices.values.toList(), + timeStamp = value.prices.keys.toList(), + ) + } +} \ No newline at end of file diff --git a/data/markets/src/main/java/com/tangem/data/markets/converters/TokenListConfigConverters.kt b/data/markets/src/main/java/com/tangem/data/markets/converters/TokenListConfigConverters.kt new file mode 100644 index 0000000000..f47c0ff170 --- /dev/null +++ b/data/markets/src/main/java/com/tangem/data/markets/converters/TokenListConfigConverters.kt @@ -0,0 +1,28 @@ +package com.tangem.data.markets.converters + +import com.tangem.domain.markets.PriceChangeInterval +import com.tangem.domain.markets.TokenMarketListConfig + +fun TokenMarketListConfig.Interval.toRequestParam(): String = when (this) { + TokenMarketListConfig.Interval.H24 -> "24h" + TokenMarketListConfig.Interval.WEEK -> "1w" + TokenMarketListConfig.Interval.MONTH -> "30d" +} + +fun TokenMarketListConfig.Order.toRequestParam(): String = when (this) { + TokenMarketListConfig.Order.ByRating -> "rating" + TokenMarketListConfig.Order.Trending -> "trending" + TokenMarketListConfig.Order.Buyers -> "buyers" + TokenMarketListConfig.Order.TopGainers -> "gainers" + TokenMarketListConfig.Order.TopLosers -> "losers" +} + +fun PriceChangeInterval.toRequestParam(): String = when (this) { + PriceChangeInterval.H24 -> "24h" + PriceChangeInterval.WEEK -> "1w" + PriceChangeInterval.MONTH -> "30d" + PriceChangeInterval.MONTH3 -> "3m" + PriceChangeInterval.MONTH6 -> "6m" + PriceChangeInterval.YEAR -> "1y" + PriceChangeInterval.ALL_TIME -> "all" +} \ No newline at end of file diff --git a/data/markets/src/main/java/com/tangem/data/markets/converters/TokenMarketChartsConverter.kt b/data/markets/src/main/java/com/tangem/data/markets/converters/TokenMarketChartsConverter.kt new file mode 100644 index 0000000000..dcfdee4638 --- /dev/null +++ b/data/markets/src/main/java/com/tangem/data/markets/converters/TokenMarketChartsConverter.kt @@ -0,0 +1,33 @@ +package com.tangem.data.markets.converters + +import com.tangem.datasource.api.markets.models.response.TokenMarketChartListResponse +import com.tangem.domain.markets.PriceChangeInterval +import com.tangem.domain.markets.TokenMarket + +class TokenMarketChartsConverter( + private val tokenListChartConverter: TokenListChartConverter, +) { + + fun convert( + chartsToCopy: TokenMarket.Charts, + tokenId: String, + interval: PriceChangeInterval, + value: TokenMarketChartListResponse, + ): TokenMarket.Charts { + val prices = requireNotNull(value[tokenId]) { + "$tokenId is not found in the response. This shouldn't have happened." + } + return when (interval) { + PriceChangeInterval.H24 -> chartsToCopy.copy( + h24 = tokenListChartConverter.convert(interval, prices), + ) + PriceChangeInterval.WEEK -> chartsToCopy.copy( + week = tokenListChartConverter.convert(interval, prices), + ) + PriceChangeInterval.MONTH -> chartsToCopy.copy( + month = tokenListChartConverter.convert(interval, prices), + ) + else -> error("unsupported interval=$interval. This shouldn't have happened.") + } + } +} \ No newline at end of file diff --git a/data/markets/src/main/java/com/tangem/data/markets/converters/TokenMarketListConverter.kt b/data/markets/src/main/java/com/tangem/data/markets/converters/TokenMarketListConverter.kt new file mode 100644 index 0000000000..96f7e01ebf --- /dev/null +++ b/data/markets/src/main/java/com/tangem/data/markets/converters/TokenMarketListConverter.kt @@ -0,0 +1,40 @@ +package com.tangem.data.markets.converters + +import com.tangem.datasource.api.markets.models.response.TokenMarketListResponse +import com.tangem.domain.markets.PriceChangeInterval +import com.tangem.domain.markets.TokenMarket +import com.tangem.domain.markets.TokenQuotes +import com.tangem.utils.converter.Converter + +class TokenMarketListConverter : Converter> { + + override fun convert(value: TokenMarketListResponse): List { + val imageHost = value.imageHost ?: run { + if (value.tokens.isEmpty()) { + return emptyList() + } else { + error("imageHost cannot be null") + } + } + + return value.tokens.map { token -> + TokenMarket( + id = token.id, + name = token.name, + symbol = token.symbol, + marketRating = token.marketRating, + marketCap = token.marketCap, + imageHost = imageHost, + tokenQuotes = TokenQuotes( + currentPrice = token.currentPrice, + priceChanges = mapOf( + PriceChangeInterval.H24 to token.priceChangePercentage.h24.movePointLeft(2), + PriceChangeInterval.WEEK to token.priceChangePercentage.week1.movePointLeft(2), + PriceChangeInterval.MONTH to token.priceChangePercentage.day30.movePointLeft(2), + ), + ), + tokenCharts = TokenMarket.Charts(null, null, null), + ) + } + } +} \ No newline at end of file diff --git a/data/markets/src/main/java/com/tangem/data/markets/converters/TokenQuotesConverter.kt b/data/markets/src/main/java/com/tangem/data/markets/converters/TokenQuotesConverter.kt new file mode 100644 index 0000000000..205c469eb5 --- /dev/null +++ b/data/markets/src/main/java/com/tangem/data/markets/converters/TokenQuotesConverter.kt @@ -0,0 +1,25 @@ +package com.tangem.data.markets.converters + +import com.tangem.datasource.api.tangemTech.models.QuotesResponse +import com.tangem.domain.markets.PriceChangeInterval +import com.tangem.domain.markets.TokenQuotes +import java.math.BigDecimal + +class TokenQuotesConverter { + + fun convert(tokenId: String, value: QuotesResponse): TokenQuotes { + val quote = requireNotNull(value.quotes[tokenId]) { + "$tokenId is not found in the response. This shouldn't have happened." + } + return TokenQuotes( + currentPrice = requireNotNull(quote.price) { + "Price is not found in the QuotesResponse. This shouldn't have happened." + }, + priceChanges = mapOf( + PriceChangeInterval.H24 to (quote.priceChange24h ?: BigDecimal.ZERO).movePointLeft(2), + PriceChangeInterval.WEEK to (quote.priceChange1w ?: BigDecimal.ZERO).movePointLeft(2), + PriceChangeInterval.MONTH to (quote.priceChange30d ?: BigDecimal.ZERO).movePointLeft(2), + ), + ) + } +} \ No newline at end of file diff --git a/data/markets/src/main/java/com/tangem/data/markets/di/MarketsDataModule.kt b/data/markets/src/main/java/com/tangem/data/markets/di/MarketsDataModule.kt new file mode 100644 index 0000000000..22356c0dfd --- /dev/null +++ b/data/markets/src/main/java/com/tangem/data/markets/di/MarketsDataModule.kt @@ -0,0 +1,32 @@ +package com.tangem.data.markets.di + +import com.tangem.data.markets.DefaultMarketsTokenRepository +import com.tangem.datasource.api.markets.TangemTechMarketsApi +import com.tangem.datasource.api.tangemTech.TangemTechApi +import com.tangem.datasource.di.DevTangemApi +import com.tangem.domain.markets.repositories.MarketsTokenRepository +import com.tangem.utils.coroutines.CoroutineDispatcherProvider +import dagger.Module +import dagger.Provides +import dagger.hilt.InstallIn +import dagger.hilt.components.SingletonComponent +import javax.inject.Singleton + +@Module +@InstallIn(SingletonComponent::class) +internal object MarketsDataModule { + + @Provides + @Singleton + fun provideMarketsRepository( + @DevTangemApi marketsApi: TangemTechMarketsApi, + @DevTangemApi tangemTechApi: TangemTechApi, + dispatchers: CoroutineDispatcherProvider, + ): MarketsTokenRepository { + return DefaultMarketsTokenRepository( + marketsApi = marketsApi, + tangemTechApi = tangemTechApi, + dispatcherProvider = dispatchers, + ) + } +} \ No newline at end of file diff --git a/data/markets/src/main/java/com/tangem/data/markets/utils/RequestUtils.kt b/data/markets/src/main/java/com/tangem/data/markets/utils/RequestUtils.kt new file mode 100644 index 0000000000..18f4e1fda0 --- /dev/null +++ b/data/markets/src/main/java/com/tangem/data/markets/utils/RequestUtils.kt @@ -0,0 +1,27 @@ +package com.tangem.data.markets.utils + +import kotlinx.coroutines.currentCoroutineContext +import kotlinx.coroutines.delay +import kotlinx.coroutines.ensureActive +import kotlinx.coroutines.yield +import timber.log.Timber +import kotlin.coroutines.cancellation.CancellationException + +@Suppress("UnconditionalJumpStatementInLoop") +internal suspend fun retryOnError(priority: Boolean = false, call: suspend () -> T): T { + while (true) { + return try { + call() + } catch (e: Exception) { + if (e is CancellationException) { + currentCoroutineContext().ensureActive() + } + Timber.e(e) + if (priority.not()) { + yield() + delay(timeMillis = 500) + } + continue + } + } +} \ No newline at end of file diff --git a/data/settings/src/main/java/com/tangem/data/settings/DefaultPermissionRepository.kt b/data/settings/src/main/java/com/tangem/data/settings/DefaultPermissionRepository.kt new file mode 100644 index 0000000000..e2528964fe --- /dev/null +++ b/data/settings/src/main/java/com/tangem/data/settings/DefaultPermissionRepository.kt @@ -0,0 +1,35 @@ +package com.tangem.data.settings + +import com.tangem.datasource.local.preferences.AppPreferencesStore +import com.tangem.datasource.local.preferences.PreferencesKeys.getShouldShowInitialPermissionScreen +import com.tangem.datasource.local.preferences.PreferencesKeys.getShouldShowPermission +import com.tangem.datasource.local.preferences.utils.getSyncOrDefault +import com.tangem.datasource.local.preferences.utils.store +import com.tangem.domain.settings.repositories.PermissionRepository + +internal class DefaultPermissionRepository( + private val appPreferencesStore: AppPreferencesStore, +) : PermissionRepository { + + override suspend fun shouldInitiallyShowPermissionScreen(permission: String): Boolean { + return appPreferencesStore.getSyncOrDefault( + key = getShouldShowInitialPermissionScreen(permission), + default = true, + ) + } + + override suspend fun neverInitiallyShowPermissionScreen(permission: String) { + appPreferencesStore.store( + key = getShouldShowInitialPermissionScreen(permission), + value = false, + ) + } + + override suspend fun shouldAskPermission(permission: String): Boolean { + return appPreferencesStore.getSyncOrDefault(getShouldShowPermission(permission), true) + } + + override suspend fun neverAskPermission(permission: String) { + appPreferencesStore.store(key = getShouldShowPermission(permission), value = false) + } +} \ No newline at end of file diff --git a/data/settings/src/main/java/com/tangem/data/settings/di/SettingsDataModule.kt b/data/settings/src/main/java/com/tangem/data/settings/di/SettingsDataModule.kt index 4f6bf8e17b..d1daa5b8a0 100644 --- a/data/settings/src/main/java/com/tangem/data/settings/di/SettingsDataModule.kt +++ b/data/settings/src/main/java/com/tangem/data/settings/di/SettingsDataModule.kt @@ -1,12 +1,14 @@ package com.tangem.data.settings.di import com.tangem.data.settings.DefaultAppRatingRepository -import com.tangem.data.settings.DefaultSettingsRepository +import com.tangem.data.settings.DefaultPermissionRepository import com.tangem.data.settings.DefaultPromoSettingsRepository +import com.tangem.data.settings.DefaultSettingsRepository import com.tangem.datasource.local.preferences.AppPreferencesStore import com.tangem.domain.settings.repositories.AppRatingRepository -import com.tangem.domain.settings.repositories.SettingsRepository +import com.tangem.domain.settings.repositories.PermissionRepository import com.tangem.domain.settings.repositories.PromoSettingsRepository +import com.tangem.domain.settings.repositories.SettingsRepository import dagger.Module import dagger.Provides import dagger.hilt.InstallIn @@ -34,4 +36,10 @@ internal object SettingsDataModule { fun providePromoSettingsSettingsRepository(appPreferencesStore: AppPreferencesStore): PromoSettingsRepository { return DefaultPromoSettingsRepository(appPreferencesStore = appPreferencesStore) } + + @Provides + @Singleton + fun providePushPermissionRepository(appPreferencesStore: AppPreferencesStore): PermissionRepository { + return DefaultPermissionRepository(appPreferencesStore = appPreferencesStore) + } } \ No newline at end of file diff --git a/data/staking/build.gradle.kts b/data/staking/build.gradle.kts index 83a8cccc87..0a1688dee1 100644 --- a/data/staking/build.gradle.kts +++ b/data/staking/build.gradle.kts @@ -11,12 +11,20 @@ android { } dependencies { - + /** Core modules */ implementation(projects.core.datasource) implementation(projects.core.utils) - implementation(projects.domain.staking) - implementation(projects.features.staking.api) + /** Common modules */ + implementation(projects.data.common) + + /** Domain modules */ + implementation(projects.domain.tokens.models) + implementation(projects.domain.staking) + implementation(projects.domain.wallets.models) + + /** Feature Api modules */ + implementation(projects.features.staking.api) // region DI implementation(deps.hilt.android) @@ -24,13 +32,17 @@ dependencies { // endregion // region Others dependencies + implementation(deps.androidx.datastore) implementation(deps.jodatime) implementation(deps.kotlin.coroutines) implementation(deps.moshi) implementation(deps.moshi.kotlin) + + implementation(projects.libs.blockchainSdk) implementation(deps.tangem.blockchain) { exclude(module = "joda-time") } + // endregion } diff --git a/data/staking/src/main/java/com/tangem/data/staking/DefaultStakingErrorResolver.kt b/data/staking/src/main/java/com/tangem/data/staking/DefaultStakingErrorResolver.kt new file mode 100644 index 0000000000..a991a4e1f6 --- /dev/null +++ b/data/staking/src/main/java/com/tangem/data/staking/DefaultStakingErrorResolver.kt @@ -0,0 +1,19 @@ +package com.tangem.data.staking + +import com.tangem.data.staking.converters.error.StakeKitErrorConverter +import com.tangem.datasource.api.common.response.ApiResponseError +import com.tangem.domain.staking.model.stakekit.StakingError +import com.tangem.domain.staking.repositories.StakingErrorResolver + +internal class DefaultStakingErrorResolver( + private val stakeKitErrorConverter: StakeKitErrorConverter, +) : StakingErrorResolver { + + override fun resolve(throwable: Throwable): StakingError { + return if (throwable is ApiResponseError.HttpException) { + stakeKitErrorConverter.convert(throwable.errorBody.orEmpty()) + } else { + StakingError.UnknownError + } + } +} \ No newline at end of file diff --git a/data/staking/src/main/java/com/tangem/data/staking/DefaultStakingRepository.kt b/data/staking/src/main/java/com/tangem/data/staking/DefaultStakingRepository.kt index a60a8c5141..bc015d17b5 100644 --- a/data/staking/src/main/java/com/tangem/data/staking/DefaultStakingRepository.kt +++ b/data/staking/src/main/java/com/tangem/data/staking/DefaultStakingRepository.kt @@ -1,34 +1,132 @@ package com.tangem.data.staking +import arrow.core.raise.catch import com.tangem.blockchain.common.Blockchain +import com.tangem.blockchainsdk.utils.toCoinId +import com.tangem.data.common.cache.CacheRegistry +import com.tangem.data.staking.converters.* +import com.tangem.data.staking.converters.action.ActionStatusConverter +import com.tangem.data.staking.converters.action.EnterActionResponseConverter +import com.tangem.data.staking.converters.action.StakingActionTypeConverter +import com.tangem.data.staking.converters.transaction.GasEstimateConverter +import com.tangem.data.staking.converters.transaction.StakingTransactionConverter +import com.tangem.data.staking.converters.transaction.StakingTransactionStatusConverter +import com.tangem.data.staking.converters.transaction.StakingTransactionTypeConverter import com.tangem.datasource.api.common.response.getOrThrow import com.tangem.datasource.api.stakekit.StakeKitApi -import com.tangem.domain.staking.model.StakingAvailability -import com.tangem.domain.staking.model.StakingEntryInfo +import com.tangem.datasource.api.stakekit.models.request.* +import com.tangem.datasource.api.stakekit.models.response.model.YieldBalanceWrapperDTO +import com.tangem.datasource.local.preferences.AppPreferencesStore +import com.tangem.datasource.local.preferences.PreferencesKeys +import com.tangem.datasource.local.preferences.utils.getObjectListSync +import com.tangem.datasource.local.token.StakingBalanceStore +import com.tangem.datasource.local.token.StakingYieldsStore +import com.tangem.domain.core.lce.LceFlow +import com.tangem.domain.core.lce.lceFlow +import com.tangem.domain.staking.model.* +import com.tangem.domain.staking.model.stakekit.Yield +import com.tangem.domain.staking.model.stakekit.YieldBalance +import com.tangem.domain.staking.model.stakekit.YieldBalanceList +import com.tangem.domain.staking.model.stakekit.action.StakingAction +import com.tangem.domain.staking.model.stakekit.action.StakingActionCommonType +import com.tangem.domain.staking.model.stakekit.action.StakingActionType +import com.tangem.domain.staking.model.stakekit.transaction.ActionParams +import com.tangem.domain.staking.model.stakekit.transaction.StakingGasEstimate +import com.tangem.domain.staking.model.stakekit.transaction.StakingTransaction import com.tangem.domain.staking.repositories.StakingRepository +import com.tangem.domain.tokens.model.CryptoCurrency +import com.tangem.domain.tokens.model.CryptoCurrencyAddress +import com.tangem.domain.tokens.model.Network +import com.tangem.domain.wallets.models.UserWalletId import com.tangem.features.staking.api.featuretoggles.StakingFeatureToggles import com.tangem.utils.coroutines.CoroutineDispatcherProvider +import com.tangem.utils.toFormattedString +import kotlinx.coroutines.NonCancellable +import kotlinx.coroutines.flow.* +import kotlinx.coroutines.launch import kotlinx.coroutines.withContext +@Suppress("LargeClass", "LongParameterList") internal class DefaultStakingRepository( private val stakeKitApi: StakeKitApi, - private val stakingFeatureToggles: StakingFeatureToggles, + private val appPreferencesStore: AppPreferencesStore, + private val stakingYieldsStore: StakingYieldsStore, + private val stakingBalanceStore: StakingBalanceStore, + private val cacheRegistry: CacheRegistry, private val dispatchers: CoroutineDispatcherProvider, + private val stakingFeatureToggle: StakingFeatureToggles, ) : StakingRepository { - override fun getStakingAvailability(blockchainId: String): StakingAvailability { - if (!stakingFeatureToggles.isStakingEnabled) { - return StakingAvailability.Unavailable - } + private val stakingNetworkTypeConverter = StakingNetworkTypeConverter() + private val networkTypeConverter = StakingNetworkTypeConverter() + private val transactionStatusConverter = StakingTransactionStatusConverter() + private val transactionTypeConverter = StakingTransactionTypeConverter() + private val actionStatusConverter = ActionStatusConverter() + private val stakingActionTypeConverter = StakingActionTypeConverter() + private val tokenConverter = TokenConverter( + stakingNetworkTypeConverter = stakingNetworkTypeConverter, + ) + private val yieldConverter = YieldConverter( + tokenConverter = tokenConverter, + ) + private val gasEstimateConverter = GasEstimateConverter( + tokenConverter = tokenConverter, + ) + private val transactionConverter = StakingTransactionConverter( + networkTypeConverter = networkTypeConverter, + transactionStatusConverter = transactionStatusConverter, + transactionTypeConverter = transactionTypeConverter, + gasEstimateConverter = gasEstimateConverter, + ) + private val enterActionResponseConverter = EnterActionResponseConverter( + actionStatusConverter = actionStatusConverter, + stakingActionTypeConverter = stakingActionTypeConverter, + transactionConverter = transactionConverter, + ) - return integrationIdMap[Blockchain.fromId(blockchainId)]?.let { - StakingAvailability.Available(it) - } ?: StakingAvailability.Unavailable + private val yieldBalanceConverter = YieldBalanceConverter() + + private val yieldBalanceListConverter = YieldBalanceListConverter() + + private val isYieldBalanceFetching = MutableStateFlow( + value = emptyMap(), + ) + + override fun isStakingSupported(currencyId: String): Boolean { + return integrationIdMap.containsKey(currencyId) } - override suspend fun getEntryInfo(integrationId: String): StakingEntryInfo { + override suspend fun fetchEnabledYields(refresh: Boolean) { + withContext(dispatchers.io) { + cacheRegistry.invokeOnExpire( + key = YIELDS_STORE_KEY, + skipCache = refresh, + block = { + val stakingTokensWithYields = stakeKitApi.getMultipleYields().getOrThrow() + stakingYieldsStore.store(stakingTokensWithYields.data) + }, + ) + } + } + + override suspend fun getYield(cryptoCurrencyId: CryptoCurrency.ID, symbol: String): Yield { return withContext(dispatchers.io) { - val yield = stakeKitApi.getSingleYield(integrationId).getOrThrow() + val yields = getEnabledYields() ?: error("No yields found") + val rawCurrencyId = cryptoCurrencyId.rawCurrencyId ?: error("Staking custom tokens is not available") + + val prefetchedYield = findPrefetchedYield( + yields = yields, + currencyId = rawCurrencyId, + symbol = symbol, + ) + + prefetchedYield ?: error("Staking is unavailable") + } + } + + override suspend fun getEntryInfo(cryptoCurrencyId: CryptoCurrency.ID, symbol: String): StakingEntryInfo { + return withContext(dispatchers.io) { + val yield = getYield(cryptoCurrencyId, symbol) StakingEntryInfo( interestRate = yield.apy, @@ -38,31 +136,389 @@ internal class DefaultStakingRepository( } } - companion object { - private const val SOLANA_INTEGRATION_ID = "solana-sol-native-multivalidator-staking" - private const val COSMOS_INTEGRATION_ID = "cosmos-atom-native-staking" - private const val POLKADOT_INTEGRATION_ID = "polkadot-dot-validator-staking" - private const val ETHEREUM_INTEGRATION_ID = "ethereum-matic-native-staking" - private const val AVALANCHE_INTEGRATION_ID = "avalanche-avax-native-staking" - private const val TRON_INTEGRATION_ID = "tron-trx-native-staking" - private const val CRONOS_INTEGRATION_ID = "cronos-cro-native-staking" - private const val BINANCE_INTEGRATION_ID = "binance-bnb-native-staking" - private const val KAVA_INTEGRATION_ID = "kava-kava-native-staking" - private const val NEAR_INTEGRATION_ID = "near-near-native-staking" - private const val TEZOS_INTEGRATION_ID = "tezos-xtz-native-staking" + override suspend fun getStakingAvailabilityForActions( + cryptoCurrencyId: CryptoCurrency.ID, + symbol: String, + ): StakingAvailability { + val rawCurrencyId = cryptoCurrencyId.rawCurrencyId ?: return StakingAvailability.Unavailable - private val integrationIdMap = mapOf( - Blockchain.Solana to SOLANA_INTEGRATION_ID, - Blockchain.Cosmos to COSMOS_INTEGRATION_ID, - Blockchain.Polkadot to POLKADOT_INTEGRATION_ID, - Blockchain.Polygon to ETHEREUM_INTEGRATION_ID, - Blockchain.Avalanche to AVALANCHE_INTEGRATION_ID, - Blockchain.Tron to TRON_INTEGRATION_ID, - Blockchain.Cronos to CRONOS_INTEGRATION_ID, - Blockchain.Binance to BINANCE_INTEGRATION_ID, - Blockchain.Kava to KAVA_INTEGRATION_ID, - Blockchain.Near to NEAR_INTEGRATION_ID, - Blockchain.Tezos to TEZOS_INTEGRATION_ID, + return withContext(dispatchers.io) { + val yields = getEnabledYields() ?: return@withContext StakingAvailability.Unavailable + + val prefetchedYield = findPrefetchedYield(yields, rawCurrencyId, symbol) + val isSupported = isStakingSupported(rawCurrencyId) + + when { + prefetchedYield != null && isSupported -> { + StakingAvailability.Available(prefetchedYield.id) + } + prefetchedYield == null && isSupported -> { + StakingAvailability.TemporaryDisabled + } + else -> StakingAvailability.Unavailable + } + } + } + + override suspend fun createAction(params: ActionParams): StakingAction { + return withContext(dispatchers.io) { + val response = when (params.actionCommonType) { + StakingActionCommonType.ENTER -> stakeKitApi.createEnterAction(createActionRequestBody(params)) + StakingActionCommonType.EXIT -> stakeKitApi.createExitAction(createActionRequestBody(params)) + StakingActionCommonType.PENDING -> stakeKitApi.createPendingAction( + createPendingActionRequestBody(params), + ) + } + + enterActionResponseConverter.convert(response.getOrThrow()) + } + } + + override suspend fun estimateGas(params: ActionParams): StakingGasEstimate { + return withContext(dispatchers.io) { + val gasEstimateDTO = when (params.actionCommonType) { + StakingActionCommonType.ENTER -> stakeKitApi.estimateGasOnEnter(createActionRequestBody(params)) + StakingActionCommonType.EXIT -> stakeKitApi.estimateGasOnExit(createActionRequestBody(params)) + StakingActionCommonType.PENDING -> stakeKitApi.estimateGasOnPending( + createPendingActionRequestBody(params), + ) + } + + gasEstimateConverter.convert(gasEstimateDTO.getOrThrow()) + } + } + + override suspend fun constructTransaction(transactionId: String): StakingTransaction { + return withContext(dispatchers.io) { + val transactionResponse = stakeKitApi.constructTransaction( + transactionId = transactionId, + body = ConstructTransactionRequestBody(), + ) + + transactionConverter.convert(transactionResponse.getOrThrow()) + } + } + + override suspend fun fetchSingleYieldBalance( + userWalletId: UserWalletId, + address: CryptoCurrencyAddress, + refresh: Boolean, + ) = withContext(dispatchers.io) { + if (!stakingFeatureToggle.isStakingEnabled) return@withContext + + val cryptoCurrency = address.cryptoCurrency + val rawCurrencyId = + cryptoCurrency.id.rawCurrencyId ?: error("Staking custom tokens is not available") + + val integrationId = integrationIdMap[rawCurrencyId] ?: return@withContext + + cacheRegistry.invokeOnExpire( + key = getYieldBalancesKey(userWalletId), + skipCache = refresh, + block = { + val requestBody = getBalanceRequestData(address.address, integrationId) + val result = stakeKitApi.getSingleYieldBalance( + integrationId = requestBody.integrationId, + body = requestBody, + ).getOrThrow() + + stakingBalanceStore.store( + requestBody.integrationId, + YieldBalanceWrapperDTO( + balances = result, + integrationId = requestBody.integrationId, + ), + ) + }, + ) + } + + override fun getSingleYieldBalanceFlow( + userWalletId: UserWalletId, + address: CryptoCurrencyAddress, + ): Flow = channelFlow { + if (!stakingFeatureToggle.isStakingEnabled) { + send(YieldBalance.Empty) + } else { + launch(dispatchers.io) { + val integrationId = integrationIdMap[address.cryptoCurrency.id.rawCurrencyId] + ?: error("Could not get integrationId") + stakingBalanceStore.get(integrationId) + .collectLatest { + send( + yieldBalanceConverter.convert( + YieldBalanceConverter.Data( + balance = it, + integrationId = integrationId, + ), + ), + ) + } + } + + withContext(dispatchers.io) { + fetchSingleYieldBalance( + userWalletId, + address, + ) + } + } + }.cancellable() + + override suspend fun getSingleYieldBalanceSync( + userWalletId: UserWalletId, + address: CryptoCurrencyAddress, + ): YieldBalance = withContext(dispatchers.io) { + if (!stakingFeatureToggle.isStakingEnabled) { + YieldBalance.Empty + } else { + fetchSingleYieldBalance(userWalletId, address) + + val integrationId = integrationIdMap[address.cryptoCurrency.id.rawCurrencyId] + ?: error("Could not get integrationId") + val result = stakingBalanceStore.getSyncOrNull(integrationId) ?: return@withContext YieldBalance.Error + yieldBalanceConverter.convert( + YieldBalanceConverter.Data( + balance = result, + integrationId = integrationId, + ), + ) + } + } + + override suspend fun fetchMultiYieldBalance( + userWalletId: UserWalletId, + addresses: List, + refresh: Boolean, + ) = withContext(dispatchers.io) { + if (!stakingFeatureToggle.isStakingEnabled) return@withContext + try { + isYieldBalanceFetching.update { + it + (userWalletId to true) + } + cacheRegistry.invokeOnExpire( + key = getYieldBalancesKey(userWalletId), + skipCache = refresh, + block = { + val result = stakeKitApi.getMultipleYieldBalances( + addresses + .mapNotNull { networkAddress -> + val cryptoCurrency = networkAddress.cryptoCurrency + val rawCurrencyId = cryptoCurrency.id.rawCurrencyId ?: error("Currency raw id is null") + val integrationId = integrationIdMap[rawCurrencyId] + + if (integrationId != null) { + networkAddress.address to integrationId + } else { + null + } + } + .distinct() + .map { getBalanceRequestData(it.first, it.second) }, + ).getOrThrow() + + stakingBalanceStore.store(result) + }, + ) + } finally { + isYieldBalanceFetching.update { + it - userWalletId + } + } + } + + override fun getMultiYieldBalanceFlow( + userWalletId: UserWalletId, + addresses: List, + ): Flow = channelFlow { + if (!stakingFeatureToggle.isStakingEnabled) { + send(YieldBalanceList.Empty) + } else { + launch(dispatchers.io) { + stakingBalanceStore.get() + .collectLatest { send(yieldBalanceListConverter.convert(it)) } + } + + withContext(dispatchers.io) { + fetchMultiYieldBalance( + userWalletId, + addresses, + ) + } + } + }.cancellable() + + override fun getMultiYieldBalanceLce( + userWalletId: UserWalletId, + addresses: List, + ): LceFlow = lceFlow { + if (!stakingFeatureToggle.isStakingEnabled) { + send(YieldBalanceList.Empty) + } else { + launch(dispatchers.io) { + combine( + stakingBalanceStore.get(), + isYieldBalanceFetching.map { it.getOrElse(userWalletId) { false } }, + ) { result, isFetching -> + val balances = yieldBalanceListConverter.convert(result) + send(balances, isStillLoading = isFetching) + }.collect() + } + withContext(dispatchers.io) { + catch( + block = { fetchMultiYieldBalance(userWalletId, addresses, refresh = false) }, + catch = { raise(it) }, + ) + } + } + } + + override suspend fun getMultiYieldBalanceSync( + userWalletId: UserWalletId, + addresses: List, + ): YieldBalanceList = withContext(dispatchers.io) { + if (!stakingFeatureToggle.isStakingEnabled) { + YieldBalanceList.Empty + } else { + fetchMultiYieldBalance(userWalletId, addresses) + val result = stakingBalanceStore.getSyncOrNull() ?: return@withContext YieldBalanceList.Error + yieldBalanceListConverter.convert(result) + } + } + + override suspend fun submitHash(transactionId: String, transactionHash: String) { + withContext(dispatchers.io) { + stakeKitApi.submitTransactionHash( + transactionId = transactionId, + body = SubmitTransactionHashRequestBody( + hash = transactionHash, + ), + ) + } + } + + override suspend fun storeUnsubmittedHash(unsubmittedTransactionMetadata: UnsubmittedTransactionMetadata) { + withContext(dispatchers.io) { + appPreferencesStore.editData { preferences -> + val savedTransactions = preferences.getObjectListOrDefault( + key = PreferencesKeys.UNSUBMITTED_TRANSACTIONS_KEY, + default = emptyList(), + ) + + preferences.setObjectList( + key = PreferencesKeys.UNSUBMITTED_TRANSACTIONS_KEY, + value = savedTransactions + unsubmittedTransactionMetadata, + ) + } + } + } + + override suspend fun sendUnsubmittedHashes() { + withContext(NonCancellable) { + val savedTransactions = appPreferencesStore.getObjectListSync( + key = PreferencesKeys.UNSUBMITTED_TRANSACTIONS_KEY, + ) + + savedTransactions.forEach { + stakeKitApi.submitTransactionHash( + transactionId = it.transactionId, + body = SubmitTransactionHashRequestBody(hash = it.transactionHash), + ) + } + + appPreferencesStore.editData { mutablePreferences -> + mutablePreferences.setObjectList( + key = PreferencesKeys.UNSUBMITTED_TRANSACTIONS_KEY, + value = emptyList(), + ) + } + } + } + + private fun createActionRequestBody(params: ActionParams): ActionRequestBody { + return ActionRequestBody( + integrationId = params.integrationId, + addresses = Address(params.address), + args = ActionRequestBodyArgs( + amount = params.amount.toFormattedString(params.token.decimals), + inputToken = tokenConverter.convertBack(params.token), + validatorAddress = params.validatorAddress, + ), + ) + } + + private fun createPendingActionRequestBody(params: ActionParams): PendingActionRequestBody { + return PendingActionRequestBody( + integrationId = params.integrationId, + type = params.type ?: StakingActionType.UNKNOWN, + passthrough = params.passthrough.orEmpty(), + args = ActionRequestBodyArgs( + amount = params.amount.toFormattedString(params.token.decimals), + validatorAddress = params.validatorAddress, + ), + ) + } + + override fun isStakeMoreAvailable(networkId: Network.ID): Boolean { + val blockchain = Blockchain.fromId(networkId.value) + return when (blockchain) { + Blockchain.Solana -> false + else -> true + } + } + + private fun findPrefetchedYield(yields: List, currencyId: String, symbol: String): Yield? { + return yields.find { it.token.coinGeckoId == currencyId && it.token.symbol == symbol } + } + + private suspend fun getEnabledYields(): List? { + val yields = stakingYieldsStore.getSyncOrNull() ?: return null + return yields.map { yieldConverter.convert(it) } + } + + private fun getBalanceRequestData(address: String, integrationId: String): YieldBalanceRequestBody { + return YieldBalanceRequestBody( + addresses = Address( + address = address, + additionalAddresses = null, // todo fill additional addresses metadata if needed + explorerUrl = "", // todo fill exporer url [REDACTED_JIRA] + ), + args = YieldBalanceRequestBody.YieldBalanceRequestArgs( + validatorAddresses = listOf(), // todo add validators [REDACTED_JIRA] + ), + integrationId = integrationId, + ) + } + + private fun getYieldBalancesKey(userWalletId: UserWalletId) = "yield_balance_${userWalletId.stringValue}" + + private companion object { + const val YIELDS_STORE_KEY = "yields" + + const val SOLANA_INTEGRATION_ID = "solana-sol-native-multivalidator-staking" + const val COSMOS_INTEGRATION_ID = "cosmos-atom-native-staking" + const val POLKADOT_INTEGRATION_ID = "polkadot-dot-validator-staking" + const val ETHEREUM_INTEGRATION_ID = "ethereum-matic-native-staking" + const val AVALANCHE_INTEGRATION_ID = "avalanche-avax-native-staking" + const val TRON_INTEGRATION_ID = "tron-trx-native-staking" + const val CRONOS_INTEGRATION_ID = "cronos-cro-native-staking" + const val BINANCE_INTEGRATION_ID = "binance-bnb-native-staking" + const val KAVA_INTEGRATION_ID = "kava-kava-native-staking" + const val NEAR_INTEGRATION_ID = "near-near-native-staking" + const val TEZOS_INTEGRATION_ID = "tezos-xtz-native-staking" + + val integrationIdMap = mapOf( + Blockchain.Solana.toCoinId() to SOLANA_INTEGRATION_ID, + Blockchain.Cosmos.toCoinId() to COSMOS_INTEGRATION_ID, + Blockchain.Polkadot.toCoinId() to POLKADOT_INTEGRATION_ID, + Blockchain.Polygon.toCoinId() to ETHEREUM_INTEGRATION_ID, + Blockchain.Avalanche.toCoinId() to AVALANCHE_INTEGRATION_ID, + Blockchain.Tron.toCoinId() to TRON_INTEGRATION_ID, + Blockchain.Cronos.toCoinId() to CRONOS_INTEGRATION_ID, + Blockchain.Binance.toCoinId() to BINANCE_INTEGRATION_ID, + Blockchain.Kava.toCoinId() to KAVA_INTEGRATION_ID, + Blockchain.Near.toCoinId() to NEAR_INTEGRATION_ID, + Blockchain.Tezos.toCoinId() to TEZOS_INTEGRATION_ID, ) } } \ No newline at end of file diff --git a/data/staking/src/main/java/com/tangem/data/staking/converters/StakingNetworkTypeConverter.kt b/data/staking/src/main/java/com/tangem/data/staking/converters/StakingNetworkTypeConverter.kt new file mode 100644 index 0000000000..e3b284f5fc --- /dev/null +++ b/data/staking/src/main/java/com/tangem/data/staking/converters/StakingNetworkTypeConverter.kt @@ -0,0 +1,153 @@ +package com.tangem.data.staking.converters + +import com.tangem.datasource.api.stakekit.models.response.model.NetworkTypeDTO +import com.tangem.domain.staking.model.stakekit.NetworkType +import com.tangem.utils.converter.TwoWayConverter + +@Suppress("CyclomaticComplexMethod", "LongMethod") +class StakingNetworkTypeConverter : TwoWayConverter { + + override fun convert(value: NetworkTypeDTO): NetworkType { + return when (value) { + NetworkTypeDTO.AVALANCHE_C -> NetworkType.AVALANCHE_C + NetworkTypeDTO.AVALANCHE_ATOMIC -> NetworkType.AVALANCHE_ATOMIC + NetworkTypeDTO.AVALANCHE_P -> NetworkType.AVALANCHE_P + NetworkTypeDTO.ARBITRUM -> NetworkType.ARBITRUM + NetworkTypeDTO.BINANCE -> NetworkType.BINANCE + NetworkTypeDTO.CELO -> NetworkType.CELO + NetworkTypeDTO.ETHEREUM -> NetworkType.ETHEREUM + NetworkTypeDTO.ETHEREUM_GOERLI -> NetworkType.ETHEREUM_GOERLI + NetworkTypeDTO.ETHEREUM_HOLESKY -> NetworkType.ETHEREUM_HOLESKY + NetworkTypeDTO.FANTOM -> NetworkType.FANTOM + NetworkTypeDTO.HARMONY -> NetworkType.HARMONY + NetworkTypeDTO.OPTIMISM -> NetworkType.OPTIMISM + NetworkTypeDTO.POLYGON -> NetworkType.POLYGON + NetworkTypeDTO.GNOSIS -> NetworkType.GNOSIS + NetworkTypeDTO.MOONRIVER -> NetworkType.MOONRIVER + NetworkTypeDTO.OKC -> NetworkType.OKC + NetworkTypeDTO.ZKSYNC -> NetworkType.ZKSYNC + NetworkTypeDTO.VICTION -> NetworkType.VICTION + NetworkTypeDTO.AGORIC -> NetworkType.AGORIC + NetworkTypeDTO.AKASH -> NetworkType.AKASH + NetworkTypeDTO.AXELAR -> NetworkType.AXELAR + NetworkTypeDTO.BAND_PROTOCOL -> NetworkType.BAND_PROTOCOL + NetworkTypeDTO.BITSONG -> NetworkType.BITSONG + NetworkTypeDTO.CANTO -> NetworkType.CANTO + NetworkTypeDTO.CHIHUAHUA -> NetworkType.CHIHUAHUA + NetworkTypeDTO.COMDEX -> NetworkType.COMDEX + NetworkTypeDTO.COREUM -> NetworkType.COREUM + NetworkTypeDTO.COSMOS -> NetworkType.COSMOS + NetworkTypeDTO.CRESCENT -> NetworkType.CRESCENT + NetworkTypeDTO.CRONOS -> NetworkType.CRONOS + NetworkTypeDTO.CUDOS -> NetworkType.CUDOS + NetworkTypeDTO.DESMOS -> NetworkType.DESMOS + NetworkTypeDTO.DYDX -> NetworkType.DYDX + NetworkTypeDTO.EVMOS -> NetworkType.EVMOS + NetworkTypeDTO.FETCH_AI -> NetworkType.FETCH_AI + NetworkTypeDTO.GRAVITY_BRIDGE -> NetworkType.GRAVITY_BRIDGE + NetworkTypeDTO.INJECTIVE -> NetworkType.INJECTIVE + NetworkTypeDTO.IRISNET -> NetworkType.IRISNET + NetworkTypeDTO.JUNO -> NetworkType.JUNO + NetworkTypeDTO.KAVA -> NetworkType.KAVA + NetworkTypeDTO.KI_NETWORK -> NetworkType.KI_NETWORK + NetworkTypeDTO.MARS_PROTOCOL -> NetworkType.MARS_PROTOCOL + NetworkTypeDTO.NYM -> NetworkType.NYM + NetworkTypeDTO.OKEX_CHAIN -> NetworkType.OKEX_CHAIN + NetworkTypeDTO.ONOMY -> NetworkType.ONOMY + NetworkTypeDTO.OSMOSIS -> NetworkType.OSMOSIS + NetworkTypeDTO.PERSISTENCE -> NetworkType.PERSISTENCE + NetworkTypeDTO.QUICKSILVER -> NetworkType.QUICKSILVER + NetworkTypeDTO.REGEN -> NetworkType.REGEN + NetworkTypeDTO.SECRET -> NetworkType.SECRET + NetworkTypeDTO.SENTINEL -> NetworkType.SENTINEL + NetworkTypeDTO.SOMMELIER -> NetworkType.SOMMELIER + NetworkTypeDTO.STAFI -> NetworkType.STAFI + NetworkTypeDTO.STARGAZE -> NetworkType.STARGAZE + NetworkTypeDTO.STRIDE -> NetworkType.STRIDE + NetworkTypeDTO.TERITORI -> NetworkType.TERITORI + NetworkTypeDTO.TGRADE -> NetworkType.TGRADE + NetworkTypeDTO.UMEE -> NetworkType.UMEE + NetworkTypeDTO.POLKADOT -> NetworkType.POLKADOT + NetworkTypeDTO.KUSAMA -> NetworkType.KUSAMA + NetworkTypeDTO.WESTEND -> NetworkType.WESTEND + NetworkTypeDTO.BINANCEBEACON -> NetworkType.BINANCEBEACON + NetworkTypeDTO.NEAR -> NetworkType.NEAR + NetworkTypeDTO.SOLANA -> NetworkType.SOLANA + NetworkTypeDTO.TEZOS -> NetworkType.TEZOS + NetworkTypeDTO.TRON -> NetworkType.TRON + else -> NetworkType.UNKNOWN + } + } + + override fun convertBack(value: NetworkType): NetworkTypeDTO { + return when (value) { + NetworkType.AVALANCHE_C -> NetworkTypeDTO.AVALANCHE_C + NetworkType.AVALANCHE_ATOMIC -> NetworkTypeDTO.AVALANCHE_ATOMIC + NetworkType.AVALANCHE_P -> NetworkTypeDTO.AVALANCHE_P + NetworkType.ARBITRUM -> NetworkTypeDTO.ARBITRUM + NetworkType.BINANCE -> NetworkTypeDTO.BINANCE + NetworkType.CELO -> NetworkTypeDTO.CELO + NetworkType.ETHEREUM -> NetworkTypeDTO.ETHEREUM + NetworkType.ETHEREUM_GOERLI -> NetworkTypeDTO.ETHEREUM_GOERLI + NetworkType.ETHEREUM_HOLESKY -> NetworkTypeDTO.ETHEREUM_HOLESKY + NetworkType.FANTOM -> NetworkTypeDTO.FANTOM + NetworkType.HARMONY -> NetworkTypeDTO.HARMONY + NetworkType.OPTIMISM -> NetworkTypeDTO.OPTIMISM + NetworkType.POLYGON -> NetworkTypeDTO.POLYGON + NetworkType.GNOSIS -> NetworkTypeDTO.GNOSIS + NetworkType.MOONRIVER -> NetworkTypeDTO.MOONRIVER + NetworkType.OKC -> NetworkTypeDTO.OKC + NetworkType.ZKSYNC -> NetworkTypeDTO.ZKSYNC + NetworkType.VICTION -> NetworkTypeDTO.VICTION + NetworkType.AGORIC -> NetworkTypeDTO.AGORIC + NetworkType.AKASH -> NetworkTypeDTO.AKASH + NetworkType.AXELAR -> NetworkTypeDTO.AXELAR + NetworkType.BAND_PROTOCOL -> NetworkTypeDTO.BAND_PROTOCOL + NetworkType.BITSONG -> NetworkTypeDTO.BITSONG + NetworkType.CANTO -> NetworkTypeDTO.CANTO + NetworkType.CHIHUAHUA -> NetworkTypeDTO.CHIHUAHUA + NetworkType.COMDEX -> NetworkTypeDTO.COMDEX + NetworkType.COREUM -> NetworkTypeDTO.COREUM + NetworkType.COSMOS -> NetworkTypeDTO.COSMOS + NetworkType.CRESCENT -> NetworkTypeDTO.CRESCENT + NetworkType.CRONOS -> NetworkTypeDTO.CRONOS + NetworkType.CUDOS -> NetworkTypeDTO.CUDOS + NetworkType.DESMOS -> NetworkTypeDTO.DESMOS + NetworkType.DYDX -> NetworkTypeDTO.DYDX + NetworkType.EVMOS -> NetworkTypeDTO.EVMOS + NetworkType.FETCH_AI -> NetworkTypeDTO.FETCH_AI + NetworkType.GRAVITY_BRIDGE -> NetworkTypeDTO.GRAVITY_BRIDGE + NetworkType.INJECTIVE -> NetworkTypeDTO.INJECTIVE + NetworkType.IRISNET -> NetworkTypeDTO.IRISNET + NetworkType.JUNO -> NetworkTypeDTO.JUNO + NetworkType.KAVA -> NetworkTypeDTO.KAVA + NetworkType.KI_NETWORK -> NetworkTypeDTO.KI_NETWORK + NetworkType.MARS_PROTOCOL -> NetworkTypeDTO.MARS_PROTOCOL + NetworkType.NYM -> NetworkTypeDTO.NYM + NetworkType.OKEX_CHAIN -> NetworkTypeDTO.OKEX_CHAIN + NetworkType.ONOMY -> NetworkTypeDTO.ONOMY + NetworkType.OSMOSIS -> NetworkTypeDTO.OSMOSIS + NetworkType.PERSISTENCE -> NetworkTypeDTO.PERSISTENCE + NetworkType.QUICKSILVER -> NetworkTypeDTO.QUICKSILVER + NetworkType.REGEN -> NetworkTypeDTO.REGEN + NetworkType.SECRET -> NetworkTypeDTO.SECRET + NetworkType.SENTINEL -> NetworkTypeDTO.SENTINEL + NetworkType.SOMMELIER -> NetworkTypeDTO.SOMMELIER + NetworkType.STAFI -> NetworkTypeDTO.STAFI + NetworkType.STARGAZE -> NetworkTypeDTO.STARGAZE + NetworkType.STRIDE -> NetworkTypeDTO.STRIDE + NetworkType.TERITORI -> NetworkTypeDTO.TERITORI + NetworkType.TGRADE -> NetworkTypeDTO.TGRADE + NetworkType.UMEE -> NetworkTypeDTO.UMEE + NetworkType.POLKADOT -> NetworkTypeDTO.POLKADOT + NetworkType.KUSAMA -> NetworkTypeDTO.KUSAMA + NetworkType.WESTEND -> NetworkTypeDTO.WESTEND + NetworkType.BINANCEBEACON -> NetworkTypeDTO.BINANCEBEACON + NetworkType.NEAR -> NetworkTypeDTO.NEAR + NetworkType.SOLANA -> NetworkTypeDTO.SOLANA + NetworkType.TEZOS -> NetworkTypeDTO.TEZOS + NetworkType.TRON -> NetworkTypeDTO.TRON + else -> NetworkTypeDTO.UNKNOWN + } + } +} \ No newline at end of file diff --git a/data/staking/src/main/java/com/tangem/data/staking/converters/StakingTokenConverter.kt b/data/staking/src/main/java/com/tangem/data/staking/converters/StakingTokenConverter.kt new file mode 100644 index 0000000000..06cbb55869 --- /dev/null +++ b/data/staking/src/main/java/com/tangem/data/staking/converters/StakingTokenConverter.kt @@ -0,0 +1,22 @@ +package com.tangem.data.staking.converters + +import com.tangem.datasource.api.stakekit.models.response.model.TokenWithYieldDTO +import com.tangem.domain.staking.model.StakingToken +import com.tangem.domain.staking.model.StakingTokenWithYield +import com.tangem.utils.converter.Converter + +class StakingTokenConverter : Converter { + + override fun convert(value: TokenWithYieldDTO): StakingTokenWithYield { + return StakingTokenWithYield( + token = StakingToken( + name = value.token.name, + symbol = value.token.symbol, + decimals = value.token.decimals, + contractAddress = value.token.address, + coinGeckoId = value.token.coinGeckoId, + ), + availableYieldIds = value.availableYieldIds, + ) + } +} \ No newline at end of file diff --git a/data/staking/src/main/java/com/tangem/data/staking/converters/TokenConverter.kt b/data/staking/src/main/java/com/tangem/data/staking/converters/TokenConverter.kt new file mode 100644 index 0000000000..2f67326a0c --- /dev/null +++ b/data/staking/src/main/java/com/tangem/data/staking/converters/TokenConverter.kt @@ -0,0 +1,36 @@ +package com.tangem.data.staking.converters + +import com.tangem.datasource.api.stakekit.models.response.model.TokenDTO +import com.tangem.domain.staking.model.stakekit.Token +import com.tangem.utils.converter.TwoWayConverter + +class TokenConverter( + private val stakingNetworkTypeConverter: StakingNetworkTypeConverter, +) : TwoWayConverter { + + override fun convert(value: TokenDTO): Token { + return Token( + name = value.name, + network = stakingNetworkTypeConverter.convert(value.network), + symbol = value.symbol, + decimals = value.decimals, + address = value.address, + coinGeckoId = value.coinGeckoId, + logoURI = value.logoURI, + isPoints = value.isPoints, + ) + } + + override fun convertBack(value: Token): TokenDTO { + return TokenDTO( + name = value.name, + network = stakingNetworkTypeConverter.convertBack(value.network), + symbol = value.symbol, + decimals = value.decimals, + address = value.address, + coinGeckoId = value.coinGeckoId, + logoURI = value.logoURI, + isPoints = value.isPoints, + ) + } +} \ No newline at end of file diff --git a/data/staking/src/main/java/com/tangem/data/staking/converters/YieldBalanceConverter.kt b/data/staking/src/main/java/com/tangem/data/staking/converters/YieldBalanceConverter.kt new file mode 100644 index 0000000000..c46a15f279 --- /dev/null +++ b/data/staking/src/main/java/com/tangem/data/staking/converters/YieldBalanceConverter.kt @@ -0,0 +1,41 @@ +package com.tangem.data.staking.converters + +import com.tangem.data.staking.converters.action.PendingActionConverter +import com.tangem.datasource.api.stakekit.models.response.model.BalanceDTO +import com.tangem.domain.staking.model.stakekit.BalanceItem +import com.tangem.domain.staking.model.stakekit.BalanceType +import com.tangem.domain.staking.model.stakekit.YieldBalance +import com.tangem.domain.staking.model.stakekit.YieldBalanceItem +import com.tangem.utils.converter.Converter + +internal class YieldBalanceConverter : Converter { + + private val pendingActionConverter by lazy(LazyThreadSafetyMode.NONE) { PendingActionConverter() } + + override fun convert(value: Data): YieldBalance { + return if (value.balance.isEmpty()) { + YieldBalance.Empty + } else { + YieldBalance.Data( + balance = YieldBalanceItem( + items = value.balance.map { item -> + BalanceItem( + type = BalanceType.valueOf(item.type.name), + amount = item.amount, + pricePerShare = item.pricePerShare, + rawCurrencyId = item.tokenDTO.coinGeckoId, + validatorAddress = item.validatorAddress, + pendingActions = pendingActionConverter.convertList(item.pendingActions), + ) + }, + integrationId = value.integrationId, + ), + ) + } + } + + data class Data( + val balance: List, + val integrationId: String?, + ) +} \ No newline at end of file diff --git a/data/staking/src/main/java/com/tangem/data/staking/converters/YieldBalanceListConverter.kt b/data/staking/src/main/java/com/tangem/data/staking/converters/YieldBalanceListConverter.kt new file mode 100644 index 0000000000..0476368b30 --- /dev/null +++ b/data/staking/src/main/java/com/tangem/data/staking/converters/YieldBalanceListConverter.kt @@ -0,0 +1,29 @@ +package com.tangem.data.staking.converters + +import com.tangem.datasource.api.stakekit.models.response.model.YieldBalanceWrapperDTO +import com.tangem.domain.staking.model.stakekit.YieldBalanceList +import com.tangem.utils.converter.Converter + +internal class YieldBalanceListConverter : Converter, YieldBalanceList> { + + internal val converter by lazy(LazyThreadSafetyMode.NONE) { + YieldBalanceConverter() + } + + override fun convert(value: List): YieldBalanceList { + return if (value.isEmpty()) { + YieldBalanceList.Empty + } else { + YieldBalanceList.Data( + balances = value.map { + converter.convert( + YieldBalanceConverter.Data( + balance = it.balances, + integrationId = it.integrationId, + ), + ) + }, + ) + } + } +} \ No newline at end of file diff --git a/data/staking/src/main/java/com/tangem/data/staking/converters/YieldConverter.kt b/data/staking/src/main/java/com/tangem/data/staking/converters/YieldConverter.kt new file mode 100644 index 0000000000..ddf093c628 --- /dev/null +++ b/data/staking/src/main/java/com/tangem/data/staking/converters/YieldConverter.kt @@ -0,0 +1,125 @@ +package com.tangem.data.staking.converters + +import com.tangem.datasource.api.stakekit.models.response.model.AddressArgumentDTO +import com.tangem.datasource.api.stakekit.models.response.model.YieldDTO +import com.tangem.domain.staking.model.stakekit.AddressArgument +import com.tangem.domain.staking.model.stakekit.Yield +import com.tangem.utils.converter.Converter + +class YieldConverter( + private val tokenConverter: TokenConverter, +) : Converter { + + override fun convert(value: YieldDTO): Yield { + return Yield( + id = value.id, + token = tokenConverter.convert(value.token), + tokens = value.tokens.map { tokenConverter.convert(it) }, + args = convertArgs(value.args), + status = convertStatus(value.status), + apy = value.apy, + rewardRate = value.rewardRate, + rewardType = convertRewardType(value.rewardType), + metadata = convertMetadata(value.metadata), + validators = value.validators + .filter { it.preferred } + .map { convertValidator(it) } + .sortedByDescending { it.apr }, + isAvailable = value.isAvailable, + ) + } + + private fun convertArgs(argsDTO: YieldDTO.ArgsDTO): Yield.Args { + return Yield.Args( + enter = convertEnter(argsDTO.enter), + exit = argsDTO.exit?.let { convertEnter(it) }, + ) + } + + private fun convertEnter(enterDTO: YieldDTO.ArgsDTO.Enter): Yield.Args.Enter { + return Yield.Args.Enter( + addresses = convertAddresses(enterDTO.addresses), + args = enterDTO.args.mapValues { convertAddressArgument(it.value) }, + ) + } + + private fun convertAddresses(addressesDTO: YieldDTO.ArgsDTO.Enter.Addresses): Yield.Args.Enter.Addresses { + return Yield.Args.Enter.Addresses( + address = convertAddressArgument(addressesDTO.address), + additionalAddresses = addressesDTO.additionalAddresses?.mapValues { convertAddressArgument(it.value) }, + ) + } + + private fun convertAddressArgument(addressArgumentDTO: AddressArgumentDTO): AddressArgument { + return AddressArgument( + required = addressArgumentDTO.required, + network = addressArgumentDTO.network, + minimum = addressArgumentDTO.minimum, + maximum = addressArgumentDTO.maximum, + ) + } + + private fun convertStatus(statusDTO: YieldDTO.StatusDTO): Yield.Status { + return Yield.Status( + enter = statusDTO.enter, + exit = statusDTO.exit, + ) + } + + private fun convertMetadata(metadataDTO: YieldDTO.MetadataDTO): Yield.Metadata { + return Yield.Metadata( + name = metadataDTO.name, + logoUri = metadataDTO.logoUri, + description = metadataDTO.description, + documentation = metadataDTO.documentation, + gasFeeToken = tokenConverter.convert(metadataDTO.gasFeeTokenDTO), + token = tokenConverter.convert(metadataDTO.tokenDTO), + tokens = metadataDTO.tokensDTO.map { tokenConverter.convert(it) }, + type = metadataDTO.type, + rewardSchedule = metadataDTO.rewardSchedule, + cooldownPeriod = convertPeriod(metadataDTO.cooldownPeriod), + warmupPeriod = convertPeriod(metadataDTO.warmupPeriod), + rewardClaiming = metadataDTO.rewardClaiming, + defaultValidator = metadataDTO.defaultValidator, + minimumStake = metadataDTO.minimumStake, + supportsMultipleValidators = metadataDTO.supportsMultipleValidators, + revshare = convertEnabled(metadataDTO.revshare), + fee = convertEnabled(metadataDTO.fee), + ) + } + + private fun convertPeriod(periodDTO: YieldDTO.MetadataDTO.PeriodDTO): Yield.Metadata.Period { + return Yield.Metadata.Period( + days = periodDTO.days, + ) + } + + private fun convertEnabled(enabledDTO: YieldDTO.MetadataDTO.EnabledDTO): Yield.Metadata.Enabled { + return Yield.Metadata.Enabled( + enabled = enabledDTO.enabled, + ) + } + + private fun convertValidator(validatorDTO: YieldDTO.ValidatorDTO): Yield.Validator { + return Yield.Validator( + address = validatorDTO.address, + status = validatorDTO.status, + name = validatorDTO.name, + image = validatorDTO.image, + website = validatorDTO.website, + apr = validatorDTO.apr, + commission = validatorDTO.commission, + stakedBalance = validatorDTO.stakedBalance, + votingPower = validatorDTO.votingPower, + preferred = validatorDTO.preferred, + ) + } + + private fun convertRewardType(rewardTypeDTO: YieldDTO.RewardTypeDTO): Yield.RewardType { + return when (rewardTypeDTO) { + YieldDTO.RewardTypeDTO.APY -> Yield.RewardType.APY + YieldDTO.RewardTypeDTO.APR -> Yield.RewardType.APR + else -> Yield.RewardType.UNKNOWN + } + } +} \ No newline at end of file diff --git a/data/staking/src/main/java/com/tangem/data/staking/converters/action/ActionStatusConverter.kt b/data/staking/src/main/java/com/tangem/data/staking/converters/action/ActionStatusConverter.kt new file mode 100644 index 0000000000..4bc04836a3 --- /dev/null +++ b/data/staking/src/main/java/com/tangem/data/staking/converters/action/ActionStatusConverter.kt @@ -0,0 +1,19 @@ +package com.tangem.data.staking.converters.action + +import com.tangem.datasource.api.stakekit.models.response.model.action.StakingActionStatusDTO +import com.tangem.domain.staking.model.stakekit.action.StakingActionStatus +import com.tangem.utils.converter.Converter + +class ActionStatusConverter : Converter { + override fun convert(value: StakingActionStatusDTO): StakingActionStatus { + return when (value) { + StakingActionStatusDTO.CANCELED -> StakingActionStatus.CANCELED + StakingActionStatusDTO.CREATED -> StakingActionStatus.CREATED + StakingActionStatusDTO.WAITING_FOR_NEXT -> StakingActionStatus.WAITING_FOR_NEXT + StakingActionStatusDTO.PROCESSING -> StakingActionStatus.PROCESSING + StakingActionStatusDTO.FAILED -> StakingActionStatus.FAILED + StakingActionStatusDTO.SUCCESS -> StakingActionStatus.SUCCESS + else -> StakingActionStatus.UNKNOWN + } + } +} \ No newline at end of file diff --git a/data/staking/src/main/java/com/tangem/data/staking/converters/action/EnterActionResponseConverter.kt b/data/staking/src/main/java/com/tangem/data/staking/converters/action/EnterActionResponseConverter.kt new file mode 100644 index 0000000000..d06ab798d2 --- /dev/null +++ b/data/staking/src/main/java/com/tangem/data/staking/converters/action/EnterActionResponseConverter.kt @@ -0,0 +1,28 @@ +package com.tangem.data.staking.converters.action + +import com.tangem.data.staking.converters.transaction.StakingTransactionConverter +import com.tangem.datasource.api.stakekit.models.response.EnterActionResponse +import com.tangem.domain.staking.model.stakekit.action.StakingAction +import com.tangem.utils.converter.Converter + +class EnterActionResponseConverter( + private val actionStatusConverter: ActionStatusConverter, + private val stakingActionTypeConverter: StakingActionTypeConverter, + private val transactionConverter: StakingTransactionConverter, +) : Converter { + + override fun convert(value: EnterActionResponse): StakingAction { + return StakingAction( + id = value.id, + integrationId = value.integrationId, + status = actionStatusConverter.convert(value.status), + type = stakingActionTypeConverter.convert(value.type), + currentStepIndex = value.currentStepIndex, + amount = value.amount, + validatorAddress = value.validatorAddress, + validatorAddresses = value.validatorAddresses, + transactions = value.transactions?.map(transactionConverter::convert), + createdAt = value.createdAt, + ) + } +} \ No newline at end of file diff --git a/data/staking/src/main/java/com/tangem/data/staking/converters/action/PendingActionConverter.kt b/data/staking/src/main/java/com/tangem/data/staking/converters/action/PendingActionConverter.kt new file mode 100644 index 0000000000..c9ddee7f77 --- /dev/null +++ b/data/staking/src/main/java/com/tangem/data/staking/converters/action/PendingActionConverter.kt @@ -0,0 +1,44 @@ +package com.tangem.data.staking.converters.action + +import com.tangem.datasource.api.stakekit.models.response.model.BalanceDTO +import com.tangem.domain.staking.model.stakekit.PendingAction +import com.tangem.utils.converter.Converter + +internal class PendingActionConverter : Converter { + + private val stakingActionTypeConverter by lazy(LazyThreadSafetyMode.NONE) { StakingActionTypeConverter() } + + override fun convert(value: BalanceDTO.PendingAction): PendingAction { + return PendingAction( + type = stakingActionTypeConverter.convert(value.type), + passthrough = value.passthrough, + args = with(value.args) { + PendingAction.PendingActionArgs( + amount = this?.amount?.let { + PendingAction.PendingActionArgs.Amount( + required = it.required, + minimum = it.minimum, + maximum = it.maximum, + ) + }, + duration = this?.duration?.let { + PendingAction.PendingActionArgs.Duration( + required = it.required, + minimum = it.minimum, + maximum = it.maximum, + ) + }, + validatorAddress = this?.validatorAddress?.required, + validatorAddresses = this?.validatorAddresses?.required, + tronResource = this?.tronResource?.let { + PendingAction.PendingActionArgs.TronResource( + required = it.required, + options = it.options, + ) + }, + signatureVerification = this?.signatureVerification?.required, + ) + }, + ) + } +} \ No newline at end of file diff --git a/data/staking/src/main/java/com/tangem/data/staking/converters/action/StakingActionTypeConverter.kt b/data/staking/src/main/java/com/tangem/data/staking/converters/action/StakingActionTypeConverter.kt new file mode 100644 index 0000000000..95829958e7 --- /dev/null +++ b/data/staking/src/main/java/com/tangem/data/staking/converters/action/StakingActionTypeConverter.kt @@ -0,0 +1,30 @@ +package com.tangem.data.staking.converters.action + +import com.tangem.datasource.api.stakekit.models.response.model.action.StakingActionTypeDTO +import com.tangem.domain.staking.model.stakekit.action.StakingActionType +import com.tangem.utils.converter.Converter + +@Suppress("CyclomaticComplexMethod") +class StakingActionTypeConverter : Converter { + + override fun convert(value: StakingActionTypeDTO): StakingActionType { + return when (value) { + StakingActionTypeDTO.STAKE -> StakingActionType.STAKE + StakingActionTypeDTO.UNSTAKE -> StakingActionType.UNSTAKE + StakingActionTypeDTO.CLAIM_REWARDS -> StakingActionType.CLAIM_REWARDS + StakingActionTypeDTO.RESTAKE_REWARDS -> StakingActionType.RESTAKE_REWARDS + StakingActionTypeDTO.WITHDRAW -> StakingActionType.WITHDRAW + StakingActionTypeDTO.RESTAKE -> StakingActionType.RESTAKE + StakingActionTypeDTO.CLAIM_UNSTAKED -> StakingActionType.CLAIM_UNSTAKED + StakingActionTypeDTO.UNLOCK_LOCKED -> StakingActionType.UNLOCK_LOCKED + StakingActionTypeDTO.STAKE_LOCKED -> StakingActionType.STAKE_LOCKED + StakingActionTypeDTO.VOTE -> StakingActionType.VOTE + StakingActionTypeDTO.REVOKE -> StakingActionType.REVOKE + StakingActionTypeDTO.VOTE_LOCKED -> StakingActionType.VOTE_LOCKED + StakingActionTypeDTO.REVOTE -> StakingActionType.REVOTE + StakingActionTypeDTO.REBOND -> StakingActionType.REBOND + StakingActionTypeDTO.MIGRATE -> StakingActionType.MIGRATE + StakingActionTypeDTO.UNKNOWN -> StakingActionType.UNKNOWN + } + } +} \ No newline at end of file diff --git a/data/staking/src/main/java/com/tangem/data/staking/converters/error/StakeKitErrorConverter.kt b/data/staking/src/main/java/com/tangem/data/staking/converters/error/StakeKitErrorConverter.kt new file mode 100644 index 0000000000..39aef18e1b --- /dev/null +++ b/data/staking/src/main/java/com/tangem/data/staking/converters/error/StakeKitErrorConverter.kt @@ -0,0 +1,115 @@ +package com.tangem.data.staking.converters.error + +import com.squareup.moshi.JsonAdapter +import com.tangem.datasource.api.stakekit.models.response.model.error.AccessDeniedErrorTypeDTO +import com.tangem.datasource.api.stakekit.models.response.model.error.StakeKitErrorMessageDTO +import com.tangem.datasource.api.stakekit.models.response.model.error.StakeKitErrorResponse +import com.tangem.domain.staking.model.stakekit.StakingError +import com.tangem.utils.converter.Converter + +internal class StakeKitErrorConverter( + private val jsonAdapter: JsonAdapter, +) : Converter { + + @Suppress("CyclomaticComplexMethod", "LongMethod") + override fun convert(value: String): StakingError { + return try { + val stakeKitErrorResponse = jsonAdapter.fromJson(value) ?: return StakingError.UnknownError + + if (stakeKitErrorResponse.type == AccessDeniedErrorTypeDTO.GEO_LOCATION) { + StakingError.UnavailableDueToGeolocationError( + tags = stakeKitErrorResponse.tags ?: emptyList(), + ) + } + + when (stakeKitErrorResponse.message) { + StakeKitErrorMessageDTO.MINIMUM_AMOUNT_NOT_REACHED -> StakingError.MinimumAmountNotReachedError( + amount = stakeKitErrorResponse.details?.amount ?: "", + ) + StakeKitErrorMessageDTO.MISSING_ARGUMENTS_ERROR -> StakingError.MissingArgumentsError( + arguments = stakeKitErrorResponse.details?.arguments ?: "", + ) + StakeKitErrorMessageDTO.YIELD_UNDER_MAINTENANCE_ERROR -> StakingError.YieldUnderMaintenanceError( + yieldId = stakeKitErrorResponse.details?.yieldId ?: "", + ) + StakeKitErrorMessageDTO.INSUFFICIENT_FUNDS_ERROR -> + StakingError.InsufficientFundsError + StakeKitErrorMessageDTO.STAKED_POSITION_NOT_FOUND_ERROR -> + StakingError.StakedPositionNotFoundError + StakeKitErrorMessageDTO.INVALID_AMOUNT_SUBMITTED_ERROR -> + StakingError.InvalidAmountSubmittedError + StakeKitErrorMessageDTO.BALANCE_UNAVAILABLE_ERROR -> + StakingError.BalanceUnavailableError + StakeKitErrorMessageDTO.GAS_PRICE_UNAVAILABLE_ERROR -> + StakingError.GasPriceUnavailableError + StakeKitErrorMessageDTO.NOT_IMPLEMENTED_ERROR -> + StakingError.NotImplementedError + StakeKitErrorMessageDTO.TOKEN_NOT_FOUND_ERROR -> + StakingError.TokenNotFoundError + StakeKitErrorMessageDTO.BROADCAST_TRANSACTION_ERROR -> + StakingError.BroadcastTransactionError + StakeKitErrorMessageDTO.MISSING_GAS_PRICE_STRATEGY_ERROR -> + StakingError.MissingGasPriceStrategyError + StakeKitErrorMessageDTO.SUBSTRATE_MALFORMED_TRANSACTION_HASH_ERROR -> + StakingError.SubstrateMalformedTransactionHashError + StakeKitErrorMessageDTO.TRON_MAXIMUM_AMOUNT_OF_VALIDATORS_EXCEEDED_ERROR -> + StakingError.TronMaximumAmountOfValidatorsExceededError + StakeKitErrorMessageDTO.SUBSTRATE_POOL_NOT_FOUND_ERROR -> + StakingError.SubstratePoolNotFoundError + StakeKitErrorMessageDTO.SUBSTRATE_BONDED_AMOUNT_TOO_LOW_ERROR -> + StakingError.SubstrateBondedAmountTooLowError + StakeKitErrorMessageDTO.TRON_MISSING_RESOURCE_TYPE_ARGUMENT_ERROR -> + StakingError.TronMissingResourceTypeArgumentError + StakeKitErrorMessageDTO.AAVE_V3_POOL_FROZEN_ERROR -> + StakingError.AaveV3PoolFrozenError + StakeKitErrorMessageDTO.AAVE_V3_TOKEN_PAIR_NOT_FOUND_ERROR -> + StakingError.AaveV3TokenPairNotFoundError + StakeKitErrorMessageDTO.YEARN_VAULT_AT_MAX_CAPACITY_ERROR -> + StakingError.YearnVaultAtMaxCapacityError + StakeKitErrorMessageDTO.STETH_NO_WITHDRAWAL_REQUESTS_FOUND_ERROR -> + StakingError.StETHNoWithdrawalRequestsFoundError + StakeKitErrorMessageDTO.MORPHO_LENDING_POOL_PAUSED_ERROR -> + StakingError.MorphoLendingPoolPausedError + StakeKitErrorMessageDTO.NONCE_UNAVAILABLE_ERROR -> + StakingError.NonceUnavailableError + StakeKitErrorMessageDTO.COSMOS_ACCOUNT_NOT_FOUND_ERROR -> + StakingError.CosmosAcccountNotFoundError + StakeKitErrorMessageDTO.AVALANCHE_MISSING_ADDITIONAL_ADDRESSES_ARGUMENT_ERROR -> + StakingError.AvalancheMissingAdditionalAddressesArgumentError + StakeKitErrorMessageDTO.AVALANCHE_VALIDATOR_INFO_NOT_FOUND_ERROR -> + StakingError.AvalancheValidatorInfoNotFoundError + StakeKitErrorMessageDTO.SOLANA_TRANSACTION_SIGNATURE_VERIFICATION_FAILURE_ERROR -> + StakingError.SolanaTransactionSignatureVerificationFailureError + StakeKitErrorMessageDTO.SOLANA_UNABLE_TO_CREATE_STAKE_ACCOUNT_ERROR -> + StakingError.SolanaUnableTocreateStakeAccountError + StakeKitErrorMessageDTO.SOLANA_STAKE_AMOUNT_TOO_LOW_ERROR -> + StakingError.SolanaStakeAmountTooLowError + StakeKitErrorMessageDTO.SOLANA_UNSTAKE_AMOUNT_TOO_LOW_ERROR -> + StakingError.SolanaUnstakeAmountTooLowError + StakeKitErrorMessageDTO.SOLANA_STAKE_ACCOUNTS_NOT_FOUND_ERROR -> + StakingError.SolanaStakeAccountsNotFoundError + StakeKitErrorMessageDTO.SOLANA_ELIGIBLE_STAKE_ACCOUNTS_NOT_FOUND_ERROR -> + StakingError.SolanaEligibleStakeAccountsNotFoundError + StakeKitErrorMessageDTO.TEZOS_NO_BALANCE_DELEGATED_ERROR -> + StakingError.TezosNoBalanceDelegatedError + StakeKitErrorMessageDTO.TEZOS_MISSING_PUBKEY_ARGUMENT_ERROR -> + StakingError.TezosMissingPubkeyArgumentError + StakeKitErrorMessageDTO.TEZOS_ESTIMATE_REVEAL_GAS_LIMIT_ERROR -> + StakingError.TezosEstimateRevealGasLimitError + StakeKitErrorMessageDTO.TEZOS_BALANCE_ALREADY_DELEGATED_ERROR -> + StakingError.TezosBalanceAlreadyDelegatedError + StakeKitErrorMessageDTO.BINANCE_ACCOUNT_NOT_FOUND_ERROR -> + StakingError.BinanceAccountNotFoundError + StakeKitErrorMessageDTO.BINANCE_MISSING_ACCOUNT_NUMBER_OR_SEQUENCE_ERROR -> + StakingError.BinanceMissingAccountNumberOrSequenceError + StakeKitErrorMessageDTO.GRT_STAKING_DISABLED_ERROR -> + StakingError.GRTStakingDisabledError + StakeKitErrorMessageDTO.GRT_STAKING_DISABLED_LEDGER_LIVE_ERROR -> + StakingError.GRTStakingDisabledLedgerLiveError + else -> StakingError.UnknownError + } + } catch (e: Exception) { + StakingError.UnknownError + } + } +} \ No newline at end of file diff --git a/data/staking/src/main/java/com/tangem/data/staking/converters/transaction/GasEstimateConverter.kt b/data/staking/src/main/java/com/tangem/data/staking/converters/transaction/GasEstimateConverter.kt new file mode 100644 index 0000000000..6220823faf --- /dev/null +++ b/data/staking/src/main/java/com/tangem/data/staking/converters/transaction/GasEstimateConverter.kt @@ -0,0 +1,19 @@ +package com.tangem.data.staking.converters.transaction + +import com.tangem.data.staking.converters.TokenConverter +import com.tangem.datasource.api.stakekit.models.response.model.transaction.StakingGasEstimateDTO +import com.tangem.domain.staking.model.stakekit.transaction.StakingGasEstimate +import com.tangem.utils.converter.Converter + +class GasEstimateConverter( + private val tokenConverter: TokenConverter, +) : Converter { + + override fun convert(value: StakingGasEstimateDTO): StakingGasEstimate { + return StakingGasEstimate( + amount = value.amount, + token = tokenConverter.convert(value.token), + gasLimit = value.gasLimit, + ) + } +} \ No newline at end of file diff --git a/data/staking/src/main/java/com/tangem/data/staking/converters/transaction/StakingTransactionConverter.kt b/data/staking/src/main/java/com/tangem/data/staking/converters/transaction/StakingTransactionConverter.kt new file mode 100644 index 0000000000..ef86c8ef8b --- /dev/null +++ b/data/staking/src/main/java/com/tangem/data/staking/converters/transaction/StakingTransactionConverter.kt @@ -0,0 +1,33 @@ +package com.tangem.data.staking.converters.transaction + +import com.tangem.data.staking.converters.StakingNetworkTypeConverter +import com.tangem.datasource.api.stakekit.models.response.model.transaction.StakingTransactionDTO +import com.tangem.domain.staking.model.stakekit.transaction.StakingTransaction +import com.tangem.utils.converter.Converter + +class StakingTransactionConverter( + private val networkTypeConverter: StakingNetworkTypeConverter, + private val transactionStatusConverter: StakingTransactionStatusConverter, + private val transactionTypeConverter: StakingTransactionTypeConverter, + private val gasEstimateConverter: GasEstimateConverter, +) : Converter { + + override fun convert(value: StakingTransactionDTO): StakingTransaction { + return StakingTransaction( + id = value.id, + network = networkTypeConverter.convert(value.network), + status = transactionStatusConverter.convert(value.status), + type = transactionTypeConverter.convert(value.type), + hash = value.hash, + signedTransaction = value.signedTransaction, + unsignedTransaction = value.unsignedTransaction, + stepIndex = value.stepIndex, + error = value.error, + gasEstimate = value.gasEstimate?.let { gasEstimateConverter.convert(it) }, + stakeId = value.stakeId, + explorerUrl = value.explorerUrl, + ledgerHwAppId = value.ledgerHwAppId, + isMessage = value.isMessage, + ) + } +} \ No newline at end of file diff --git a/data/staking/src/main/java/com/tangem/data/staking/converters/transaction/StakingTransactionStatusConverter.kt b/data/staking/src/main/java/com/tangem/data/staking/converters/transaction/StakingTransactionStatusConverter.kt new file mode 100644 index 0000000000..236c6e53cb --- /dev/null +++ b/data/staking/src/main/java/com/tangem/data/staking/converters/transaction/StakingTransactionStatusConverter.kt @@ -0,0 +1,24 @@ +package com.tangem.data.staking.converters.transaction + +import com.tangem.datasource.api.stakekit.models.response.model.transaction.StakingTransactionStatusDTO +import com.tangem.domain.staking.model.stakekit.transaction.StakingTransactionStatus +import com.tangem.utils.converter.Converter + +class StakingTransactionStatusConverter : Converter { + + override fun convert(value: StakingTransactionStatusDTO): StakingTransactionStatus { + return when (value) { + StakingTransactionStatusDTO.NOT_FOUND -> StakingTransactionStatus.NOT_FOUND + StakingTransactionStatusDTO.CREATED -> StakingTransactionStatus.CREATED + StakingTransactionStatusDTO.BLOCKED -> StakingTransactionStatus.BLOCKED + StakingTransactionStatusDTO.WAITING_FOR_SIGNATURE -> StakingTransactionStatus.WAITING_FOR_SIGNATURE + StakingTransactionStatusDTO.SIGNED -> StakingTransactionStatus.SIGNED + StakingTransactionStatusDTO.BROADCASTED -> StakingTransactionStatus.BROADCASTED + StakingTransactionStatusDTO.PENDING -> StakingTransactionStatus.PENDING + StakingTransactionStatusDTO.CONFIRMED -> StakingTransactionStatus.CONFIRMED + StakingTransactionStatusDTO.FAILED -> StakingTransactionStatus.FAILED + StakingTransactionStatusDTO.SKIPPED -> StakingTransactionStatus.SKIPPED + StakingTransactionStatusDTO.UNKNOWN -> StakingTransactionStatus.UNKNOWN + } + } +} \ No newline at end of file diff --git a/data/staking/src/main/java/com/tangem/data/staking/converters/transaction/StakingTransactionTypeConverter.kt b/data/staking/src/main/java/com/tangem/data/staking/converters/transaction/StakingTransactionTypeConverter.kt new file mode 100644 index 0000000000..8466b36a37 --- /dev/null +++ b/data/staking/src/main/java/com/tangem/data/staking/converters/transaction/StakingTransactionTypeConverter.kt @@ -0,0 +1,54 @@ +package com.tangem.data.staking.converters.transaction + +import com.tangem.datasource.api.stakekit.models.response.model.transaction.StakingTransactionTypeDTO +import com.tangem.domain.staking.model.stakekit.transaction.StakingTransactionType +import com.tangem.utils.converter.Converter + +@Suppress("CyclomaticComplexMethod") +class StakingTransactionTypeConverter : Converter { + + override fun convert(value: StakingTransactionTypeDTO): StakingTransactionType { + return when (value) { + StakingTransactionTypeDTO.SWAP -> StakingTransactionType.SWAP + StakingTransactionTypeDTO.DEPOSIT -> StakingTransactionType.DEPOSIT + StakingTransactionTypeDTO.APPROVAL -> StakingTransactionType.APPROVAL + StakingTransactionTypeDTO.STAKE -> StakingTransactionType.STAKE + StakingTransactionTypeDTO.CLAIM_UNSTAKED -> StakingTransactionType.CLAIM_UNSTAKED + StakingTransactionTypeDTO.CLAIM_REWARDS -> StakingTransactionType.CLAIM_REWARDS + StakingTransactionTypeDTO.RESTAKE_REWARDS -> StakingTransactionType.RESTAKE_REWARDS + StakingTransactionTypeDTO.UNSTAKE -> StakingTransactionType.UNSTAKE + StakingTransactionTypeDTO.SPLIT -> StakingTransactionType.SPLIT + StakingTransactionTypeDTO.MERGE -> StakingTransactionType.MERGE + StakingTransactionTypeDTO.LOCK -> StakingTransactionType.LOCK + StakingTransactionTypeDTO.UNLOCK -> StakingTransactionType.UNLOCK + StakingTransactionTypeDTO.SUPPLY -> StakingTransactionType.SUPPLY + StakingTransactionTypeDTO.BRIDGE -> StakingTransactionType.BRIDGE + StakingTransactionTypeDTO.VOTE -> StakingTransactionType.VOTE + StakingTransactionTypeDTO.REVOKE -> StakingTransactionType.REVOKE + StakingTransactionTypeDTO.RESTAKE -> StakingTransactionType.RESTAKE + StakingTransactionTypeDTO.REBOND -> StakingTransactionType.REBOND + StakingTransactionTypeDTO.WITHDRAW -> StakingTransactionType.WITHDRAW + StakingTransactionTypeDTO.CREATE_ACCOUNT -> StakingTransactionType.CREATE_ACCOUNT + StakingTransactionTypeDTO.REVEAL -> StakingTransactionType.REVEAL + StakingTransactionTypeDTO.MIGRATE -> StakingTransactionType.MIGRATE + StakingTransactionTypeDTO.UTXO_P_TO_C_IMPORT -> StakingTransactionType.UTXO_P_TO_C_IMPORT + StakingTransactionTypeDTO.UTXO_C_TO_P_IMPORT -> StakingTransactionType.UTXO_C_TO_P_IMPORT + StakingTransactionTypeDTO.UNFREEZE_LEGACY -> StakingTransactionType.UNFREEZE_LEGACY + StakingTransactionTypeDTO.UNFREEZE_LEGACY_BANDWIDTH -> StakingTransactionType.UNFREEZE_LEGACY_BANDWIDTH + StakingTransactionTypeDTO.UNFREEZE_LEGACY_ENERGY -> StakingTransactionType.UNFREEZE_LEGACY_ENERGY + StakingTransactionTypeDTO.UNFREEZE_BANDWIDTH -> StakingTransactionType.UNFREEZE_BANDWIDTH + StakingTransactionTypeDTO.UNFREEZE_ENERGY -> StakingTransactionType.UNFREEZE_ENERGY + StakingTransactionTypeDTO.FREEZE_BANDWIDTH -> StakingTransactionType.FREEZE_BANDWIDTH + StakingTransactionTypeDTO.FREEZE_ENERGY -> StakingTransactionType.FREEZE_ENERGY + StakingTransactionTypeDTO.UNDELEGATE_BANDWIDTH -> StakingTransactionType.UNDELEGATE_BANDWIDTH + StakingTransactionTypeDTO.UNDELEGATE_ENERGY -> StakingTransactionType.UNDELEGATE_ENERGY + StakingTransactionTypeDTO.P2P_NODE_REQUEST -> StakingTransactionType.P2P_NODE_REQUEST + StakingTransactionTypeDTO.LUGANODES_PROVISION -> StakingTransactionType.LUGANODES_PROVISION + StakingTransactionTypeDTO.LUGANODES_EXIT_REQUEST -> StakingTransactionType.LUGANODES_EXIT_REQUEST + StakingTransactionTypeDTO.INFSTONES_PROVISION -> StakingTransactionType.INFSTONES_PROVISION + StakingTransactionTypeDTO.INFSTONES_EXIT_REQUEST -> StakingTransactionType.INFSTONES_EXIT_REQUEST + StakingTransactionTypeDTO.INFSTONES_CLAIM_REQUEST -> StakingTransactionType.INFSTONES_CLAIM_REQUEST + StakingTransactionTypeDTO.UNKNOWN -> StakingTransactionType.UNKNOWN + } + } +} \ No newline at end of file diff --git a/data/staking/src/main/java/com/tangem/data/staking/di/StakingDataModule.kt b/data/staking/src/main/java/com/tangem/data/staking/di/StakingDataModule.kt index 0f5076bb01..f0562851c1 100644 --- a/data/staking/src/main/java/com/tangem/data/staking/di/StakingDataModule.kt +++ b/data/staking/src/main/java/com/tangem/data/staking/di/StakingDataModule.kt @@ -1,7 +1,17 @@ package com.tangem.data.staking.di +import com.squareup.moshi.Moshi +import com.tangem.data.common.cache.CacheRegistry +import com.tangem.data.staking.DefaultStakingErrorResolver import com.tangem.data.staking.DefaultStakingRepository +import com.tangem.data.staking.converters.error.StakeKitErrorConverter import com.tangem.datasource.api.stakekit.StakeKitApi +import com.tangem.datasource.api.stakekit.models.response.model.error.StakeKitErrorResponse +import com.tangem.datasource.di.NetworkMoshi +import com.tangem.datasource.local.preferences.AppPreferencesStore +import com.tangem.datasource.local.token.StakingBalanceStore +import com.tangem.datasource.local.token.StakingYieldsStore +import com.tangem.domain.staking.repositories.StakingErrorResolver import com.tangem.domain.staking.repositories.StakingRepository import com.tangem.features.staking.api.featuretoggles.StakingFeatureToggles import com.tangem.utils.coroutines.CoroutineDispatcherProvider @@ -19,13 +29,30 @@ internal object StakingDataModule { @Singleton fun provideStakingRepository( stakeKitApi: StakeKitApi, - stakingFeatureToggles: StakingFeatureToggles, - coroutineDispatcherProvider: CoroutineDispatcherProvider, + appPreferencesStore: AppPreferencesStore, + stakingTokenStore: StakingYieldsStore, + stakingBalanceStore: StakingBalanceStore, + dispatchers: CoroutineDispatcherProvider, + stakingFeatureToggle: StakingFeatureToggles, + cacheRegistry: CacheRegistry, ): StakingRepository { return DefaultStakingRepository( stakeKitApi = stakeKitApi, - stakingFeatureToggles = stakingFeatureToggles, - dispatchers = coroutineDispatcherProvider, + appPreferencesStore = appPreferencesStore, + stakingYieldsStore = stakingTokenStore, + stakingBalanceStore = stakingBalanceStore, + dispatchers = dispatchers, + cacheRegistry = cacheRegistry, + stakingFeatureToggle = stakingFeatureToggle, + ) + } + + @Provides + @Singleton + internal fun provideStakingErrorResolver(@NetworkMoshi moshi: Moshi): StakingErrorResolver { + val jsonAdapter = moshi.adapter(StakeKitErrorResponse::class.java) + return DefaultStakingErrorResolver( + stakeKitErrorConverter = StakeKitErrorConverter(jsonAdapter), ) } } \ No newline at end of file diff --git a/data/tokens/src/main/kotlin/com/tangem/data/tokens/di/TokensDataModule.kt b/data/tokens/src/main/kotlin/com/tangem/data/tokens/di/TokensDataModule.kt index f31d0e4b5f..59ddeeb01d 100644 --- a/data/tokens/src/main/kotlin/com/tangem/data/tokens/di/TokensDataModule.kt +++ b/data/tokens/src/main/kotlin/com/tangem/data/tokens/di/TokensDataModule.kt @@ -7,7 +7,7 @@ import com.tangem.datasource.api.tangemTech.TangemTechApi import com.tangem.datasource.local.network.NetworksStatusesStore import com.tangem.datasource.local.preferences.AppPreferencesStore import com.tangem.datasource.local.quote.QuotesStore -import com.tangem.datasource.local.token.AssetsStore +import com.tangem.datasource.local.token.ExpressAssetsStore import com.tangem.datasource.local.token.UserTokensStore import com.tangem.datasource.local.userwallet.UserWalletsStore import com.tangem.domain.tokens.repository.* @@ -31,7 +31,7 @@ internal object TokensDataModule { userTokensStore: UserTokensStore, userWalletsStore: UserWalletsStore, walletManagersFacade: WalletManagersFacade, - assetsStore: AssetsStore, + expressAssetsStore: ExpressAssetsStore, cacheRegistry: CacheRegistry, dispatchers: CoroutineDispatcherProvider, ): CurrenciesRepository { @@ -41,7 +41,7 @@ internal object TokensDataModule { userTokensStore = userTokensStore, walletManagersFacade = walletManagersFacade, userWalletsStore = userWalletsStore, - assetsStore = assetsStore, + expressAssetsStore = expressAssetsStore, cacheRegistry = cacheRegistry, dispatchers = dispatchers, ) @@ -88,10 +88,10 @@ internal object TokensDataModule { @Provides @Singleton fun provideDefaultMarketCoinsRepository( - assetsStore: AssetsStore, + expressAssetsStore: ExpressAssetsStore, coroutineDispatcherProvider: CoroutineDispatcherProvider, ): MarketCryptoCurrencyRepository { - return DefaultMarketCryptoCurrencyRepository(assetsStore, coroutineDispatcherProvider) + return DefaultMarketCryptoCurrencyRepository(expressAssetsStore, coroutineDispatcherProvider) } @Provides diff --git a/data/tokens/src/main/kotlin/com/tangem/data/tokens/repository/DefaultCurrenciesRepository.kt b/data/tokens/src/main/kotlin/com/tangem/data/tokens/repository/DefaultCurrenciesRepository.kt index 653b731d38..b24c5226bc 100644 --- a/data/tokens/src/main/kotlin/com/tangem/data/tokens/repository/DefaultCurrenciesRepository.kt +++ b/data/tokens/src/main/kotlin/com/tangem/data/tokens/repository/DefaultCurrenciesRepository.kt @@ -15,7 +15,7 @@ import com.tangem.datasource.api.express.models.request.AssetsRequestBody import com.tangem.datasource.api.express.models.request.LeastTokenInfo import com.tangem.datasource.api.tangemTech.TangemTechApi import com.tangem.datasource.api.tangemTech.models.UserTokensResponse -import com.tangem.datasource.local.token.AssetsStore +import com.tangem.datasource.local.token.ExpressAssetsStore import com.tangem.datasource.local.token.UserTokensStore import com.tangem.datasource.local.userwallet.UserWalletsStore import com.tangem.domain.common.util.derivationStyleProvider @@ -46,7 +46,7 @@ internal class DefaultCurrenciesRepository( private val userTokensStore: UserTokensStore, private val userWalletsStore: UserWalletsStore, private val walletManagersFacade: WalletManagersFacade, - private val assetsStore: AssetsStore, + private val expressAssetsStore: ExpressAssetsStore, private val cacheRegistry: CacheRegistry, private val dispatchers: CoroutineDispatcherProvider, ) : CurrenciesRepository { @@ -250,7 +250,7 @@ internal class DefaultCurrenciesRepository( launch(dispatchers.io) { combine( - getMultiCurrencyWalletCurrencies(userWallet).distinctUntilChanged(), + getMultiCurrencyWalletCurrencies(userWallet), isMultiCurrencyWalletCurrenciesFetching.map { it.getOrElse(userWallet.walletId) { false } }, ) { currencies, isFetching -> send(currencies, isStillLoading = isFetching) @@ -369,18 +369,20 @@ internal class DefaultCurrenciesRepository( } } - override fun hasPendingTransactions( + override fun isSendBlockedByPendingTransactions( cryptoCurrencyStatus: CryptoCurrencyStatus, coinStatus: CryptoCurrencyStatus?, ): Boolean { val blockchain = Blockchain.fromId(cryptoCurrencyStatus.currency.network.id.value) val isBitcoinBlockchain = blockchain == Blockchain.Bitcoin || blockchain == Blockchain.BitcoinTestnet - - return if (cryptoCurrencyStatus.currency is CryptoCurrency.Coin && isBitcoinBlockchain) { - val outgoingTransactions = cryptoCurrencyStatus.value.pendingTransactions.filter { it.isOutgoing } - outgoingTransactions.isNotEmpty() - } else { - coinStatus?.value?.hasCurrentNetworkTransactions == true + return when { + cryptoCurrencyStatus.currency is CryptoCurrency.Coin && isBitcoinBlockchain -> { + val outgoingTransactions = cryptoCurrencyStatus.value.pendingTransactions.filter { it.isOutgoing } + outgoingTransactions.isNotEmpty() + } + blockchain.isEvm() -> false + blockchain == Blockchain.Tron || blockchain == Blockchain.TronTestnet -> false + else -> coinStatus?.value?.hasCurrentNetworkTransactions == true } } @@ -462,21 +464,23 @@ internal class DefaultCurrenciesRepository( } private suspend fun fetchTokensIfCacheExpired(userWallet: UserWallet, refresh: Boolean) { - try { - isMultiCurrencyWalletCurrenciesFetching.update { - it + (userWallet.walletId to true) - } + cacheRegistry.invokeOnExpire( + key = getTokensCacheKey(userWallet.walletId), + skipCache = refresh, + block = { + isMultiCurrencyWalletCurrenciesFetching.update { + it + (userWallet.walletId to true) + } - cacheRegistry.invokeOnExpire( - key = getTokensCacheKey(userWallet.walletId), - skipCache = refresh, - block = { fetchTokens(userWallet) }, - ) - } finally { - isMultiCurrencyWalletCurrenciesFetching.update { - it - userWallet.walletId - } - } + try { + fetchTokens(userWallet) + } finally { + isMultiCurrencyWalletCurrenciesFetching.update { + it - userWallet.walletId + } + } + }, + ) } private suspend fun fetchTokens(userWallet: UserWallet) { @@ -530,7 +534,7 @@ internal class DefaultCurrenciesRepository( ), ) - assetsStore.store(userWalletId, response.getOrThrow()) + expressAssetsStore.store(userWalletId, response.getOrThrow()) } } catch (e: Throwable) { Timber.e(e, "Unable to fetch assets for: ${userWalletId.stringValue}") diff --git a/data/tokens/src/main/kotlin/com/tangem/data/tokens/repository/DefaultMarketCryptoCurrencyRepository.kt b/data/tokens/src/main/kotlin/com/tangem/data/tokens/repository/DefaultMarketCryptoCurrencyRepository.kt index d4a0f8fd29..83f30079f3 100644 --- a/data/tokens/src/main/kotlin/com/tangem/data/tokens/repository/DefaultMarketCryptoCurrencyRepository.kt +++ b/data/tokens/src/main/kotlin/com/tangem/data/tokens/repository/DefaultMarketCryptoCurrencyRepository.kt @@ -1,7 +1,7 @@ package com.tangem.data.tokens.repository import com.tangem.datasource.api.express.models.TangemExpressValues.EMPTY_CONTRACT_ADDRESS_VALUE -import com.tangem.datasource.local.token.AssetsStore +import com.tangem.datasource.local.token.ExpressAssetsStore import com.tangem.domain.tokens.model.CryptoCurrency import com.tangem.domain.tokens.repository.MarketCryptoCurrencyRepository import com.tangem.domain.wallets.models.UserWalletId @@ -9,7 +9,7 @@ import com.tangem.utils.coroutines.CoroutineDispatcherProvider import kotlinx.coroutines.withContext class DefaultMarketCryptoCurrencyRepository( - private val assetsStore: AssetsStore, + private val expressAssetsStore: ExpressAssetsStore, private val dispatchers: CoroutineDispatcherProvider, ) : MarketCryptoCurrencyRepository { @@ -22,7 +22,7 @@ class DefaultMarketCryptoCurrencyRepository( val contractAddress = (cryptoCurrency as? CryptoCurrency.Token)?.contractAddress ?: EMPTY_CONTRACT_ADDRESS_VALUE - val asset = assetsStore.getSyncOrNull(userWalletId)?.find { + val asset = expressAssetsStore.getSyncOrNull(userWalletId)?.find { it.network == cryptoCurrency.network.backendId && it.contractAddress.equals(contractAddress, ignoreCase = true) } diff --git a/data/tokens/src/main/kotlin/com/tangem/data/tokens/repository/DefaultNetworksRepository.kt b/data/tokens/src/main/kotlin/com/tangem/data/tokens/repository/DefaultNetworksRepository.kt index c4a12be730..bcc65da983 100644 --- a/data/tokens/src/main/kotlin/com/tangem/data/tokens/repository/DefaultNetworksRepository.kt +++ b/data/tokens/src/main/kotlin/com/tangem/data/tokens/repository/DefaultNetworksRepository.kt @@ -124,29 +124,81 @@ internal class DefaultNetworksRepository( } } + override suspend fun getNetworkAddress( + userWalletId: UserWalletId, + currency: CryptoCurrency, + ): CryptoCurrencyAddress = withContext(dispatchers.io) { + CryptoCurrencyAddress( + cryptoCurrency = currency, + address = walletManagersFacade.getAddresses(userWalletId, currency.network) + .firstOrNull { it.type == AddressType.Default } + ?.value.orEmpty(), + ) + } + + override fun getNetworkAddressFlow( + userWalletId: UserWalletId, + currency: CryptoCurrency, + ): Flow = channelFlow { + launch(dispatchers.io) { + send(getNetworkAddress(userWalletId, currency)) + } + } + + override suspend fun getNetworkAddresses(userWalletId: UserWalletId): List = + withContext(dispatchers.io) { + // Get list of currencies matching [network] + val currencies = getCurrencies(userWalletId) + + // There is no currencies matching given [networks] in [userWalletId] + if (currencies.toList().isEmpty()) return@withContext emptyList() + + currencies.toList().map { currency -> + CryptoCurrencyAddress( + cryptoCurrency = currency, + address = walletManagersFacade.getAddresses(userWalletId, currency.network) + .firstOrNull { it.type == AddressType.Default } + ?.value.orEmpty(), + ) + } + } + + override fun getNetworkAddressesFlow( + userWalletId: UserWalletId, + network: Network, + ): Flow> = channelFlow { + launch(dispatchers.io) { + send(getNetworkAddresses(userWalletId, network)) + } + } + + override fun getNetworkAddressesFlow(userWalletId: UserWalletId): Flow> = channelFlow { + launch(dispatchers.io) { + send(getNetworkAddresses(userWalletId)) + } + } + private suspend fun fetchNetworksStatusesIfCacheExpired( userWalletId: UserWalletId, networks: Set, refresh: Boolean, ) { - try { - isNetworkStatusesFetching.update { - it + (userWalletId to true) - } + val currencies = getCurrencies(userWalletId, networks) + val networksDeferred = networks.mapNotNull { network -> + fetchNetworkStatusIfCacheExpired(userWalletId, network, currencies, refresh) + } - val currencies = getCurrencies(userWalletId, networks) - coroutineScope { - networks - .map { network -> - async { - fetchNetworkStatusIfCacheExpired(userWalletId, network, currencies, refresh) - } - } - .awaitAll() - } - } finally { - isNetworkStatusesFetching.update { - it - userWalletId + if (networksDeferred.isNotEmpty()) { + try { + isNetworkStatusesFetching.update { + it + (userWalletId to true) + } + + networksDeferred.awaitAll() + } finally { + isNetworkStatusesFetching.update { + it - userWalletId + } } } } @@ -172,12 +224,19 @@ internal class DefaultNetworksRepository( network: Network, currencies: Sequence, refresh: Boolean, - ) { - cacheRegistry.invokeOnExpire( - key = getNetworksStatusesCacheKey(userWalletId, network), - skipCache = refresh, - block = { fetchNetworkStatus(userWalletId, network, currencies) }, - ) + ): Deferred? = coroutineScope { + val key = getNetworksStatusesCacheKey(userWalletId, network) + if (refresh || cacheRegistry.isExpired(key)) { + async { + cacheRegistry.invokeOnExpire( + key = key, + skipCache = refresh, + block = { fetchNetworkStatus(userWalletId, network, currencies) }, + ) + } + } else { + null + } } private suspend fun fetchNetworkStatus( diff --git a/data/tokens/src/main/kotlin/com/tangem/data/tokens/utils/QuotesConverter.kt b/data/tokens/src/main/kotlin/com/tangem/data/tokens/utils/QuotesConverter.kt index d76681efa4..85c903ceec 100644 --- a/data/tokens/src/main/kotlin/com/tangem/data/tokens/utils/QuotesConverter.kt +++ b/data/tokens/src/main/kotlin/com/tangem/data/tokens/utils/QuotesConverter.kt @@ -13,7 +13,7 @@ internal class QuotesConverter : Converter { return Quote( rawCurrencyId = rawCurrencyId, fiatRate = responseQuote.price ?: BigDecimal.ZERO, - priceChange = (responseQuote.priceChange ?: BigDecimal.ZERO).movePointLeft(2), + priceChange = (responseQuote.priceChange24h ?: BigDecimal.ZERO).movePointLeft(2), ) } } \ No newline at end of file diff --git a/data/transaction/build.gradle.kts b/data/transaction/build.gradle.kts index 615758dcf6..41baa4a4ba 100644 --- a/data/transaction/build.gradle.kts +++ b/data/transaction/build.gradle.kts @@ -14,6 +14,7 @@ dependencies { /** Tangem SDKs */ implementation(deps.tangem.blockchain) + implementation(deps.tangem.card.core) /** Core */ implementation(projects.core.datasource) @@ -25,6 +26,7 @@ dependencies { implementation(projects.libs.blockchainSdk) implementation(projects.domain.wallets.models) implementation(projects.domain.tokens.models) + implementation(projects.domain.transaction.models) /** DI */ implementation(deps.hilt.android) diff --git a/data/transaction/src/main/java/com/tangem/data/transaction/DefaultTransactionRepository.kt b/data/transaction/src/main/java/com/tangem/data/transaction/DefaultTransactionRepository.kt index 3f3d8aaa68..56922c5bf0 100644 --- a/data/transaction/src/main/java/com/tangem/data/transaction/DefaultTransactionRepository.kt +++ b/data/transaction/src/main/java/com/tangem/data/transaction/DefaultTransactionRepository.kt @@ -4,21 +4,28 @@ import androidx.core.text.isDigitsOnly import com.tangem.blockchain.blockchains.algorand.AlgorandTransactionExtras import com.tangem.blockchain.blockchains.binance.BinanceTransactionExtras import com.tangem.blockchain.blockchains.cosmos.CosmosTransactionExtras +import com.tangem.blockchain.blockchains.ethereum.EthereumTransactionExtras import com.tangem.blockchain.blockchains.hedera.HederaTransactionExtras import com.tangem.blockchain.blockchains.stellar.StellarMemo import com.tangem.blockchain.blockchains.stellar.StellarTransactionExtras import com.tangem.blockchain.blockchains.ton.TonTransactionExtras +import com.tangem.blockchain.blockchains.tron.TronTransactionExtras import com.tangem.blockchain.blockchains.xrp.XrpTransactionBuilder import com.tangem.blockchain.common.* import com.tangem.blockchain.common.transaction.Fee +import com.tangem.blockchainsdk.utils.fromNetworkId +import com.tangem.common.extensions.hexToBytes import com.tangem.datasource.local.walletmanager.WalletManagersStore import com.tangem.domain.tokens.model.Network import com.tangem.domain.transaction.TransactionRepository +import com.tangem.domain.transaction.models.TransactionType import com.tangem.domain.walletmanager.WalletManagersFacade import com.tangem.domain.wallets.models.UserWalletId import com.tangem.utils.coroutines.CoroutineDispatcherProvider import kotlinx.coroutines.withContext import timber.log.Timber +import java.math.BigInteger +import com.tangem.blockchain.blockchains.tron.TransactionType as SdkTransactionType internal class DefaultTransactionRepository( private val walletManagersFacade: WalletManagersFacade, @@ -35,7 +42,7 @@ internal class DefaultTransactionRepository( network: Network, txExtras: TransactionExtras?, hash: String?, - ): TransactionData? = withContext(coroutineDispatcherProvider.io) { + ): TransactionData.Uncompiled? = withContext(coroutineDispatcherProvider.io) { val blockchain = Blockchain.fromId(network.id.value) val walletManager = walletManagersFacade.getOrCreateWalletManager( userWalletId = userWalletId, @@ -43,7 +50,7 @@ internal class DefaultTransactionRepository( derivationPath = network.derivationPath.value, ) - return@withContext walletManager?.createTransactionInternal( + return@withContext walletManager?.createTransactionDataInternal( amount = amount, fee = fee, memo = memo, @@ -75,7 +82,7 @@ internal class DefaultTransactionRepository( val validator = walletManager as? TransactionValidator if (validator != null) { - val transaction = walletManager.createTransactionInternal( + val transactionData = walletManager.createTransactionDataInternal( amount = amount, fee = fee ?: Fee.Common(amount = amount), memo = memo, @@ -85,7 +92,7 @@ internal class DefaultTransactionRepository( hash = hash, ) - validator.validate(transaction = transaction) + validator.validate(transactionData = transactionData) } else { Timber.e("${walletManager?.wallet?.blockchain} does not support transaction validation") Result.success(Unit) @@ -107,8 +114,41 @@ internal class DefaultTransactionRepository( (walletManager as TransactionSender).send(txData, signer) } + override fun createTransactionDataExtras( + data: String, + network: Network, + transactionType: TransactionType, + nonce: BigInteger?, + gasLimit: BigInteger?, + ): TransactionExtras { + val blockchain = Blockchain.fromNetworkId(networkId = network.backendId) + ?: error("Blockchain not found") + return when { + blockchain.isEvm() -> { + EthereumTransactionExtras( + data = data.hexToBytes(), + gasLimit = gasLimit, + nonce = nonce, + ) + } + blockchain == Blockchain.Tron -> { + TronTransactionExtras( + data = data.hexToBytes(), + txType = convertToSdkTransactionType(transactionType), + ) + } + else -> error("Data extras not supported for $blockchain") + } + } + + private fun convertToSdkTransactionType(transactionType: TransactionType): SdkTransactionType { + return when (transactionType) { + TransactionType.APPROVE -> SdkTransactionType.APPROVE + } + } + @Suppress("LongParameterList") - private fun WalletManager.createTransactionInternal( + private fun WalletManager.createTransactionDataInternal( amount: Amount, fee: Fee, memo: String?, @@ -116,7 +156,7 @@ internal class DefaultTransactionRepository( network: Network, txExtras: TransactionExtras?, hash: String?, - ): TransactionData { + ): TransactionData.Uncompiled { if (txExtras != null && memo != null) { // throw error for now to avoid programmers errors when use extras error("Both txExtras and memo provided, use only one of them") diff --git a/data/txhistory/src/main/kotlin/com/tangem/data/txhistory/repository/paging/TxHistoryPagingSource.kt b/data/txhistory/src/main/kotlin/com/tangem/data/txhistory/repository/paging/TxHistoryPagingSource.kt index d534e238ec..87d2138b87 100644 --- a/data/txhistory/src/main/kotlin/com/tangem/data/txhistory/repository/paging/TxHistoryPagingSource.kt +++ b/data/txhistory/src/main/kotlin/com/tangem/data/txhistory/repository/paging/TxHistoryPagingSource.kt @@ -85,6 +85,7 @@ internal class TxHistoryPagingSource( currency = sourceParams.currency, ) .filterUnconfirmedTransaction() + .sortedByDescending { it.timestampInMillis } .filterIfTxAlreadyAdded(apiItems = items) return if (recentItems.isEmpty()) { diff --git a/data/visa/src/debug/kotlin/com/tangem/data/visa/DefaultVisaRepository.kt b/data/visa/src/debug/kotlin/com/tangem/data/visa/DefaultVisaRepository.kt index a817781b53..e558b2def0 100644 --- a/data/visa/src/debug/kotlin/com/tangem/data/visa/DefaultVisaRepository.kt +++ b/data/visa/src/debug/kotlin/com/tangem/data/visa/DefaultVisaRepository.kt @@ -10,10 +10,8 @@ import com.tangem.common.card.EllipticCurve import com.tangem.common.extensions.hexToBytes import com.tangem.common.extensions.toHexString import com.tangem.data.common.cache.CacheRegistry -import com.tangem.data.visa.utils.VisaConfig -import com.tangem.data.visa.utils.VisaCurrencyFactory -import com.tangem.data.visa.utils.VisaTxDetailsFactory -import com.tangem.data.visa.utils.VisaTxHistoryPagingSource +import com.tangem.data.visa.config.VisaLibLoader +import com.tangem.data.visa.utils.* import com.tangem.datasource.api.common.response.getOrThrow import com.tangem.datasource.api.tangemTech.TangemTechApi import com.tangem.datasource.local.userwallet.UserWalletsStore @@ -24,8 +22,6 @@ import com.tangem.domain.visa.model.VisaTxHistoryItem import com.tangem.domain.visa.repository.VisaRepository import com.tangem.domain.wallets.models.UserWallet import com.tangem.domain.wallets.models.UserWalletId -import com.tangem.lib.visa.VisaContractInfoProvider -import com.tangem.lib.visa.api.VisaApi import com.tangem.lib.visa.model.VisaTxHistoryResponse import com.tangem.utils.coroutines.CoroutineDispatcherProvider import kotlinx.coroutines.flow.Flow @@ -35,9 +31,8 @@ import kotlinx.coroutines.withContext import java.math.BigDecimal internal class DefaultVisaRepository( - private val visaContractInfoProvider: VisaContractInfoProvider, + private val visaLibLoader: VisaLibLoader, private val tangemTechApi: TangemTechApi, - private val visaApi: VisaApi, private val cacheRegistry: CacheRegistry, private val userWalletsStore: UserWalletsStore, private val dispatchers: CoroutineDispatcherProvider, @@ -76,9 +71,11 @@ internal class DefaultVisaRepository( } private suspend fun fetchVisaCurrency(address: String) { + val contractInfoProvider = visaLibLoader.getOrCreateProvider() + parZip( dispatchers.io, - { visaContractInfoProvider.getContractInfo(address) }, + { contractInfoProvider.getContractInfo(address) }, { getFiatRate() }, { contractInfo, fiatRate -> fetchedCurrencies.update { value -> @@ -97,6 +94,7 @@ internal class DefaultVisaRepository( ): Flow> { val userWallet = findVisaUserWallet(userWalletId) val cardPubKey = getCardPubKey(userWallet) + val api = visaLibLoader.getOrCreateApi() val pager = Pager( config = PagingConfig( pageSize = pageSize, @@ -110,7 +108,7 @@ internal class DefaultVisaRepository( isRefresh = isRefresh, ), cacheRegistry = cacheRegistry, - visaApi = visaApi, + visaApi = api, fetchedItems = fetchedHistoryItems, dispatchers = dispatchers, ) @@ -137,7 +135,7 @@ internal class DefaultVisaRepository( } private suspend fun makeAddress(userWalletId: UserWalletId): String { - if (IS_DEMO_MODE_ENABLED) return DEMO_ADDRESS + if (VisaConstants.IS_DEMO_MODE_ENABLED) return getDemoAddress() val userWallet = findVisaUserWallet(userWalletId) val walletAddresses = makeWalletAddresses(userWallet) @@ -149,13 +147,13 @@ internal class DefaultVisaRepository( } private suspend fun getFiatRate(): BigDecimal? { - val fiatCurrencyId = VisaConfig.fiatCurrency.code.lowercase() + val fiatCurrencyId = VisaConstants.fiatCurrency.code.lowercase() val quotes = tangemTechApi.getQuotes( currencyId = fiatCurrencyId, - coinIds = VisaConfig.TOKEN_ID, + coinIds = VisaConstants.TOKEN_ID, ).getOrThrow() - return quotes.quotes[VisaConfig.TOKEN_ID]?.price + return quotes.quotes[VisaConstants.TOKEN_ID]?.price } private fun makeWalletAddresses(userWallet: UserWallet): Set

{ @@ -165,7 +163,7 @@ internal class DefaultVisaRepository( } private fun getCardPubKey(userWallet: UserWallet): String { - if (IS_DEMO_MODE_ENABLED) return DEMO_PUBLIC_KEY + if (VisaConstants.IS_DEMO_MODE_ENABLED) return getDemoPublicKey() val cardWallet = userWallet.scanResponse.card.wallets.firstOrNull { it.curve == EllipticCurve.Secp256k1 @@ -189,12 +187,4 @@ internal class DefaultVisaRepository( private fun getVisaCurrencyKey(address: String): String { return "visa_currency_$address" } - - private companion object { - // Must be `false` in production - const val IS_DEMO_MODE_ENABLED = false - - const val DEMO_ADDRESS = "0x40d8194b7168723ece51fa34d16825c60ba03dfa" - const val DEMO_PUBLIC_KEY = "02C2BBA0DA1E066EA968C1EB129499F6DEBC5FD82D70D61DCAF691CDB69AF5D8B9" - } } \ No newline at end of file diff --git a/data/visa/src/debug/kotlin/com/tangem/data/visa/config/VisaConfig.kt b/data/visa/src/debug/kotlin/com/tangem/data/visa/config/VisaConfig.kt new file mode 100644 index 0000000000..8c5dba275a --- /dev/null +++ b/data/visa/src/debug/kotlin/com/tangem/data/visa/config/VisaConfig.kt @@ -0,0 +1,25 @@ +package com.tangem.data.visa.config + +import com.squareup.moshi.Json + +internal data class VisaConfig( + @Json(name = "testnet") + val testnet: Addresses, + @Json(name = "mainnet") + val mainnet: Addresses, + @Json(name = "txHistoryAPIAdditionalHeaders") + val header: Header, +) { + + data class Addresses( + @Json(name = "paymentAccountRegistry") + val paymentAccountRegistry: String, + @Json(name = "bridgeProcessor") + val bridgeProcessor: String, + ) + + data class Header( + @Json(name = "x-asn") + val xAsn: String, + ) +} \ No newline at end of file diff --git a/data/visa/src/debug/kotlin/com/tangem/data/visa/config/VisaLibLoader.kt b/data/visa/src/debug/kotlin/com/tangem/data/visa/config/VisaLibLoader.kt new file mode 100644 index 0000000000..e5062cf662 --- /dev/null +++ b/data/visa/src/debug/kotlin/com/tangem/data/visa/config/VisaLibLoader.kt @@ -0,0 +1,86 @@ +package com.tangem.data.visa.config + +import com.squareup.moshi.Moshi +import com.tangem.data.visa.BuildConfig +import com.tangem.data.visa.utils.VisaConstants +import com.tangem.datasource.asset.loader.AssetLoader +import com.tangem.datasource.di.NetworkMoshi +import com.tangem.lib.visa.VisaContractInfoProvider +import com.tangem.lib.visa.api.VisaApi +import com.tangem.lib.visa.api.VisaApiBuilder +import com.tangem.utils.coroutines.CoroutineDispatcherProvider +import kotlinx.coroutines.sync.Mutex +import kotlinx.coroutines.sync.withLock +import javax.inject.Inject + +internal class VisaLibLoader @Inject constructor( + private val assetLoader: AssetLoader, + @NetworkMoshi private val moshi: Moshi, + private val dispatchers: CoroutineDispatcherProvider, +) { + + private val createMutex = Mutex() + + private var config: VisaConfig? = null + + private var provider: VisaContractInfoProvider? = null + private var api: VisaApi? = null + + suspend fun getOrCreateProvider(): VisaContractInfoProvider = provider ?: createProvider() + + suspend fun getOrCreateApi(): VisaApi = api ?: createApi() + + private suspend fun createProvider(): VisaContractInfoProvider = createMutex.withLock { + val config = getOrLoadConfig() + + provider = VisaContractInfoProvider.Builder( + useTestnetRpc = VisaConstants.USE_TEST_ENV, + bridgeProcessorAddress = if (VisaConstants.USE_TEST_ENV) { + config.testnet.bridgeProcessor + } else { + config.mainnet.bridgeProcessor + }, + paymentAccountRegistryAddress = if (VisaConstants.USE_TEST_ENV) { + config.testnet.paymentAccountRegistry + } else { + config.mainnet.paymentAccountRegistry + }, + isNetworkLoggingEnabled = BuildConfig.LOG_ENABLED, + dispatchers = dispatchers, + ).build() + + return requireNotNull(provider) { + "Visa provider is not created" + } + } + + private suspend fun createApi(): VisaApi = createMutex.withLock { + val config = getOrLoadConfig() + + api = VisaApiBuilder( + useDevApi = VisaConstants.USE_TEST_ENV, + isNetworkLoggingEnabled = BuildConfig.LOG_ENABLED, + moshi = moshi, + headers = mapOf( + X_ASN_HEADER_NAME to config.header.xAsn, + ), + ).build() + + return requireNotNull(api) { + "Visa API is not created" + } + } + + private suspend fun getOrLoadConfig(): VisaConfig { + config = assetLoader.load(VISA_CONFIG_FILE_NAME) + + return requireNotNull(config) { + "Visa config is not found" + } + } + + companion object { + private const val VISA_CONFIG_FILE_NAME = "tangem-app-config/visa_config" + private const val X_ASN_HEADER_NAME = "x-asn" + } +} \ No newline at end of file diff --git a/data/visa/src/debug/kotlin/com/tangem/data/visa/di/ImplementedVisaDataModule.kt b/data/visa/src/debug/kotlin/com/tangem/data/visa/di/ImplementedVisaDataModule.kt index a3022a444a..60d487838e 100644 --- a/data/visa/src/debug/kotlin/com/tangem/data/visa/di/ImplementedVisaDataModule.kt +++ b/data/visa/src/debug/kotlin/com/tangem/data/visa/di/ImplementedVisaDataModule.kt @@ -1,15 +1,11 @@ package com.tangem.data.visa.di -import com.squareup.moshi.Moshi import com.tangem.data.common.cache.CacheRegistry -import com.tangem.data.visa.BuildConfig import com.tangem.data.visa.DefaultVisaRepository +import com.tangem.data.visa.config.VisaLibLoader import com.tangem.datasource.api.tangemTech.TangemTechApi -import com.tangem.datasource.di.NetworkMoshi import com.tangem.datasource.local.userwallet.UserWalletsStore import com.tangem.domain.visa.repository.VisaRepository -import com.tangem.lib.visa.VisaContractInfoProvider -import com.tangem.lib.visa.api.VisaApiBuilder import com.tangem.utils.coroutines.CoroutineDispatcherProvider import dagger.Module import dagger.Provides @@ -25,29 +21,16 @@ internal object ImplementedVisaDataModule { @Singleton @ImplementedVisaRepository fun provideVisaRepository( - @NetworkMoshi moshi: Moshi, + visaLibLoader: VisaLibLoader, tangemTechApi: TangemTechApi, cacheRegistry: CacheRegistry, userWalletsStore: UserWalletsStore, dispatchers: CoroutineDispatcherProvider, - ): VisaRepository { - val contractInfoProvider = VisaContractInfoProvider.Builder( - isNetworkLoggingEnabled = BuildConfig.LOG_ENABLED, - dispatchers = dispatchers, - ).build() - val visaApi = VisaApiBuilder( - useDevApi = true, - isNetworkLoggingEnabled = BuildConfig.LOG_ENABLED, - moshi = moshi, - ).build() - - return DefaultVisaRepository( - contractInfoProvider, - tangemTechApi, - visaApi, - cacheRegistry, - userWalletsStore, - dispatchers, - ) - } + ): VisaRepository = DefaultVisaRepository( + visaLibLoader, + tangemTechApi, + cacheRegistry, + userWalletsStore, + dispatchers, + ) } \ No newline at end of file diff --git a/data/visa/src/debug/kotlin/com/tangem/data/visa/utils/CurrencyUtils.kt b/data/visa/src/debug/kotlin/com/tangem/data/visa/utils/CurrencyUtils.kt index b664ad4320..bcc9aeb311 100644 --- a/data/visa/src/debug/kotlin/com/tangem/data/visa/utils/CurrencyUtils.kt +++ b/data/visa/src/debug/kotlin/com/tangem/data/visa/utils/CurrencyUtils.kt @@ -7,9 +7,9 @@ import java.util.Currency internal fun findCurrencyByNumericCode(code: Int): Currency { return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { Currency.getAvailableCurrencies().firstOrNull { it.numericCode == code } - ?: Currency.getInstance(VisaConfig.fiatCurrency.code) + ?: Currency.getInstance(VisaConstants.fiatCurrency.code) } else { Timber.w("Unable to get currency by numeric code on API level ${Build.VERSION.SDK_INT}") - Currency.getInstance(VisaConfig.fiatCurrency.code) + Currency.getInstance(VisaConstants.fiatCurrency.code) } } \ No newline at end of file diff --git a/data/visa/src/debug/kotlin/com/tangem/data/visa/utils/VisaConfig.kt b/data/visa/src/debug/kotlin/com/tangem/data/visa/utils/VisaConfig.kt deleted file mode 100644 index 6b3e3f3f8b..0000000000 --- a/data/visa/src/debug/kotlin/com/tangem/data/visa/utils/VisaConfig.kt +++ /dev/null @@ -1,16 +0,0 @@ -package com.tangem.data.visa.utils - -import com.tangem.domain.appcurrency.model.AppCurrency - -internal object VisaConfig { - - const val NETWORK_NAME = "Polygon PoS" - - const val TOKEN_ID = "tether" - - val fiatCurrency = AppCurrency( - code = "EUR", - name = "Euro", - symbol = "€", - ) -} \ No newline at end of file diff --git a/data/visa/src/debug/kotlin/com/tangem/data/visa/utils/VisaConstants.kt b/data/visa/src/debug/kotlin/com/tangem/data/visa/utils/VisaConstants.kt new file mode 100644 index 0000000000..27cd336588 --- /dev/null +++ b/data/visa/src/debug/kotlin/com/tangem/data/visa/utils/VisaConstants.kt @@ -0,0 +1,44 @@ +package com.tangem.data.visa.utils + +import com.tangem.domain.appcurrency.model.AppCurrency + +internal object VisaConstants { + + const val NETWORK_NAME = "Polygon PoS" + + const val TOKEN_ID = "tether" + + val fiatCurrency = AppCurrency( + code = "EUR", + name = "Euro", + symbol = "€", + ) + + /* + * Must be `false` in production + * Don't forget to change CardTypesResolver.isVisaWallet + * */ + const val IS_DEMO_MODE_ENABLED = false + + const val USE_TEST_ENV = true + + const val DEMO_TESTNET_ADDRESS = "0x51d034eb1563d0d2e66379ef37756d3c14936c44" + const val DEMO_TESTNET_PUBLIC_KEY = "03FA1122B809079F79C4E0F657FE11337FEC88C3FB3C6341B2CE2E4F5D9241DD86" + + const val DEMO_MAINNET_ADDRESS = "0x927e3ef2b3d85bacf9e520379f64f6627d323fcd" + const val DEMO_MAINNET_PUBLIC_KEY = "02AC61CD57B8011BEE8BB489FB744845CC113AD379132C56015EE70528B6A88E92" +} + +internal fun getDemoAddress(): String { + return if (VisaConstants.USE_TEST_ENV) { + VisaConstants.DEMO_TESTNET_ADDRESS + } else { + VisaConstants.DEMO_MAINNET_ADDRESS + } +} + +internal fun getDemoPublicKey(): String { + return if (VisaConstants.USE_TEST_ENV) { + VisaConstants.DEMO_TESTNET_PUBLIC_KEY + } else VisaConstants.DEMO_MAINNET_PUBLIC_KEY +} \ No newline at end of file diff --git a/data/visa/src/debug/kotlin/com/tangem/data/visa/utils/VisaCurrencyFactory.kt b/data/visa/src/debug/kotlin/com/tangem/data/visa/utils/VisaCurrencyFactory.kt index 3c9f55e37f..6398dcec84 100644 --- a/data/visa/src/debug/kotlin/com/tangem/data/visa/utils/VisaCurrencyFactory.kt +++ b/data/visa/src/debug/kotlin/com/tangem/data/visa/utils/VisaCurrencyFactory.kt @@ -21,10 +21,10 @@ internal class VisaCurrencyFactory { return VisaCurrency( symbol = contractInfo.token.symbol, - networkName = VisaConfig.NETWORK_NAME, + networkName = VisaConstants.NETWORK_NAME, decimals = contractInfo.token.decimals, fiatRate = fiatRate, - fiatCurrency = VisaConfig.fiatCurrency, + fiatCurrency = VisaConstants.fiatCurrency, balances = with(contractInfo) { VisaCurrency.Balances( total = balances.total, diff --git a/domain/balance-hiding/src/main/kotlin/com/tangem/domain/balancehiding/error/HideBalancesError.kt b/domain/balance-hiding/src/main/kotlin/com/tangem/domain/balancehiding/error/HideBalancesError.kt index 7438c20918..fb0e72e862 100644 --- a/domain/balance-hiding/src/main/kotlin/com/tangem/domain/balancehiding/error/HideBalancesError.kt +++ b/domain/balance-hiding/src/main/kotlin/com/tangem/domain/balancehiding/error/HideBalancesError.kt @@ -2,7 +2,7 @@ package com.tangem.domain.balancehiding.error sealed class HideBalancesError { - object HidingDisabled : HideBalancesError() + data object HidingDisabled : HideBalancesError() data class DataError(val cause: Throwable) : HideBalancesError() } \ No newline at end of file diff --git a/domain/card/src/main/kotlin/com/tangem/domain/card/NetworkHasDerivationUseCase.kt b/domain/card/src/main/kotlin/com/tangem/domain/card/NetworkHasDerivationUseCase.kt new file mode 100644 index 0000000000..7bc68e0d66 --- /dev/null +++ b/domain/card/src/main/kotlin/com/tangem/domain/card/NetworkHasDerivationUseCase.kt @@ -0,0 +1,16 @@ +package com.tangem.domain.card + +import arrow.core.Either +import com.tangem.blockchain.common.Blockchain +import com.tangem.domain.common.util.hasDerivation +import com.tangem.domain.models.scan.ScanResponse +import com.tangem.domain.tokens.model.Network + +class NetworkHasDerivationUseCase { + + operator fun invoke(scanResponse: ScanResponse, network: Network): Either { + val blockchain = Blockchain.fromId(network.id.value) + val derivationPath = network.derivationPath.value + return Either.catch { derivationPath != null && scanResponse.hasDerivation(blockchain, derivationPath) } + } +} \ No newline at end of file diff --git a/domain/card/src/main/kotlin/com/tangem/domain/card/ResetCardUseCase.kt b/domain/card/src/main/kotlin/com/tangem/domain/card/ResetCardUseCase.kt index 7bdd4f2293..7a71009602 100644 --- a/domain/card/src/main/kotlin/com/tangem/domain/card/ResetCardUseCase.kt +++ b/domain/card/src/main/kotlin/com/tangem/domain/card/ResetCardUseCase.kt @@ -2,7 +2,6 @@ package com.tangem.domain.card import arrow.core.Either import com.tangem.domain.card.models.ResetCardError -import com.tangem.domain.models.scan.CardDTO import com.tangem.domain.wallets.models.UserWalletId /** @@ -12,13 +11,18 @@ import com.tangem.domain.wallets.models.UserWalletId */ interface ResetCardUseCase { - /** Reset card [card] to factory settings */ - suspend operator fun invoke(card: CardDTO): Either + /** Reset card [cardId] to factory settings */ + suspend operator fun invoke(cardId: String, params: ResetCardUserCodeParams): Either - /** Reset backup card [cardNumber] with expected [UserWalletId] using [card] of reset card */ + /** Reset backup card [cardNumber] with expected [UserWalletId] using [params] of reset card */ suspend operator fun invoke( cardNumber: Int, - card: CardDTO, + params: ResetCardUserCodeParams, userWalletId: UserWalletId, - ): Either -} \ No newline at end of file + ): Either +} + +data class ResetCardUserCodeParams( + val isAccessCodeSet: Boolean, + val isPasscodeSet: Boolean?, +) \ No newline at end of file diff --git a/domain/card/src/main/kotlin/com/tangem/domain/card/repository/CardRepository.kt b/domain/card/src/main/kotlin/com/tangem/domain/card/repository/CardRepository.kt index 68e476443e..5e01929fa1 100644 --- a/domain/card/src/main/kotlin/com/tangem/domain/card/repository/CardRepository.kt +++ b/domain/card/src/main/kotlin/com/tangem/domain/card/repository/CardRepository.kt @@ -26,10 +26,5 @@ interface CardRepository { @Throws suspend fun isTangemTOSAccepted(): Boolean - @Throws - suspend fun isStart2CoinTOSAccepted(cardId: String): Boolean - suspend fun acceptTangemTOS() - - suspend fun acceptStart2CoinTOS(cardId: String) } \ No newline at end of file diff --git a/domain/core/build.gradle.kts b/domain/core/build.gradle.kts index 63325166f7..46d2670d68 100644 --- a/domain/core/build.gradle.kts +++ b/domain/core/build.gradle.kts @@ -1,5 +1,6 @@ plugins { alias(deps.plugins.kotlin.jvm) + alias(deps.plugins.kotlin.serialization) id("configuration") } @@ -7,4 +8,6 @@ dependencies { api(deps.kotlin.coroutines) api(deps.arrow.core) api(deps.arrow.fx) + + implementation(deps.kotlin.serialization) } \ No newline at end of file diff --git a/domain/core/src/main/kotlin/com/tangem/domain/core/lce/Lce.kt b/domain/core/src/main/kotlin/com/tangem/domain/core/lce/Lce.kt index 25029586ad..2d6902a58a 100644 --- a/domain/core/src/main/kotlin/com/tangem/domain/core/lce/Lce.kt +++ b/domain/core/src/main/kotlin/com/tangem/domain/core/lce/Lce.kt @@ -96,4 +96,54 @@ sealed class Lce { ifContent = ::identity, ifError = { null }, ) + + /** + * Returns the error of this [Lce] if it's a [Lce.Error], `null` otherwise. + * + * @return The error of this [Lce] or `null`. + */ + fun errorOrNull(): E? = fold( + ifLoading = { null }, + ifContent = { null }, + ifError = ::identity, + ) + + /** + * Returns `true` if this [Lce] is a [Lce.Loading] state and the given predicate is `true`. + * + * @param predicate The predicate to apply to the partial content. + * By default, the predicate is `true` for any partial content. + * @return `true` if this [Lce] is a [Lce.Loading] state and the given predicate is `true`, `false` otherwise. + */ + fun isLoading(predicate: (maybeContent: C?) -> Boolean = { true }): Boolean = fold( + ifLoading = { predicate(it) }, + ifContent = { false }, + ifError = { false }, + ) + + /** + * Returns `true` if this [Lce] is a [Lce.Error] state and the given predicate is `true`. + * + * @param predicate The predicate to apply to the error. + * By default, the predicate is `true` for any error. + * @return `true` if this [Lce] is a [Lce.Error] state and the given predicate is `true`, `false` otherwise. + */ + fun isError(predicate: (error: E) -> Boolean = { true }): Boolean = fold( + ifLoading = { false }, + ifContent = { false }, + ifError = { predicate(it) }, + ) + + /** + * Returns `true` if this [Lce] is a [Lce.Content] state and the given predicate is `true`. + * + * @param predicate The predicate to apply to the content. + * By default, the predicate is `true` for any content. + * @return `true` if this [Lce] is a [Lce.Content] state and the given predicate is `true`, `false` otherwise. + */ + fun isContent(predicate: (content: C) -> Boolean = { true }): Boolean = fold( + ifLoading = { false }, + ifContent = { predicate(it) }, + ifError = { false }, + ) } \ No newline at end of file diff --git a/domain/core/src/main/kotlin/com/tangem/domain/core/lce/LceRaise.kt b/domain/core/src/main/kotlin/com/tangem/domain/core/lce/LceRaise.kt index 90dbc6d172..1484205426 100644 --- a/domain/core/src/main/kotlin/com/tangem/domain/core/lce/LceRaise.kt +++ b/domain/core/src/main/kotlin/com/tangem/domain/core/lce/LceRaise.kt @@ -2,8 +2,10 @@ package com.tangem.domain.core.lce import arrow.atomic.Atomic import arrow.core.raise.Raise +import arrow.core.raise.RaiseDSL import arrow.core.raise.recover import com.tangem.domain.core.utils.lceContent +import com.tangem.domain.core.utils.lceError import com.tangem.domain.core.utils.lceLoading import kotlin.experimental.ExperimentalTypeInference @@ -18,18 +20,55 @@ class LceRaise @PublishedApi internal constructor( private val raise: Raise>, ) : Raise> by raise { + /** + * An [Atomic] boolean flag indicating whether a loading operation is in progress. + */ val isLoading: Atomic = Atomic(false) + /** + * Helper function to raise an [Lce.Error] state with the given error object. + * */ + @RaiseDSL + @JvmName(name = "raiseError") + fun raise(r: E): Nothing = raise(r = r.lceError()) + + /** + * Helper function to raise an [Lce.Loading] state. + */ + @RaiseDSL + fun raiseLoading(): Nothing = raise(r = lceLoading()) + + /** + * Execute the [Raise] context function resulting in [C] or any _logical error_ of type [OtherError], + * and transform any raised [OtherError] into [E], which is raised to the outer [Raise]. + * + * @see arrow.core.raise.withError + * */ + @RaiseDSL + @OptIn(ExperimentalTypeInference::class) + inline fun withError( + transform: (OtherError) -> E, + @BuilderInference block: LceRaise.() -> C, + ): C = recover( + block = { block(LceRaise(raise = this@recover)) }, + recover = { error -> + error.fold( + ifLoading = { raiseLoading() }, + ifError = { raise(transform(it)) }, + ifContent = { it }, + ) + }, + ) + /** * Binds the content of this [Lce] instance and handles its state. * If this is a [Lce.Loading] state, sets the [isLoading] flag to true and calls the [ifLoading] function. * If this is a [Lce.Content] state, returns the content. * If this is a [Lce.Error] state, raises the error. * - * @param ifLoading The function to call if this is a [Lce.Loading] state. - * By default, it raises a new [Lce.Loading] state. * @return The content of this [Lce] instance. */ + @RaiseDSL fun Lce.bind(): C = when (this) { is Lce.Loading -> { isLoading.set(true) @@ -48,6 +87,7 @@ class LceRaise @PublishedApi internal constructor( * * @return The content of this [Lce] instance. */ + @RaiseDSL fun Lce.bindOrNull(): C? = when (this) { is Lce.Loading -> { isLoading.set(true) diff --git a/domain/core/src/main/kotlin/com/tangem/domain/core/serialization/BigDecimalSerializer.kt b/domain/core/src/main/kotlin/com/tangem/domain/core/serialization/BigDecimalSerializer.kt new file mode 100644 index 0000000000..ea7727681f --- /dev/null +++ b/domain/core/src/main/kotlin/com/tangem/domain/core/serialization/BigDecimalSerializer.kt @@ -0,0 +1,21 @@ +package com.tangem.domain.core.serialization + +import kotlinx.serialization.KSerializer +import kotlinx.serialization.descriptors.PrimitiveKind +import kotlinx.serialization.descriptors.PrimitiveSerialDescriptor +import kotlinx.serialization.encoding.Decoder +import kotlinx.serialization.encoding.Encoder +import java.math.BigDecimal + +internal object BigDecimalSerializer : KSerializer { + + override val descriptor = PrimitiveSerialDescriptor(serialName = "BigDecimal", PrimitiveKind.STRING) + + override fun serialize(encoder: Encoder, value: BigDecimal) { + encoder.encodeString(value.toString()) + } + + override fun deserialize(decoder: Decoder): BigDecimal { + return BigDecimal(decoder.decodeString()) + } +} \ No newline at end of file diff --git a/domain/core/src/main/kotlin/com/tangem/domain/core/serialization/SerializedBigDecimal.kt b/domain/core/src/main/kotlin/com/tangem/domain/core/serialization/SerializedBigDecimal.kt new file mode 100644 index 0000000000..3243892b18 --- /dev/null +++ b/domain/core/src/main/kotlin/com/tangem/domain/core/serialization/SerializedBigDecimal.kt @@ -0,0 +1,6 @@ +package com.tangem.domain.core.serialization + +import kotlinx.serialization.Serializable +import java.math.BigDecimal + +typealias SerializedBigDecimal = @Serializable(with = BigDecimalSerializer::class) BigDecimal \ No newline at end of file diff --git a/domain/feedback/build.gradle.kts b/domain/feedback/build.gradle.kts index 6a21560035..28fe483e00 100644 --- a/domain/feedback/build.gradle.kts +++ b/domain/feedback/build.gradle.kts @@ -13,5 +13,6 @@ dependencies { implementation(deps.jodatime) implementation(projects.core.res) + implementation(projects.domain.models) implementation(projects.domain.wallets.models) } \ No newline at end of file diff --git a/domain/feedback/src/main/java/com/tangem/domain/feedback/FeedbackManager.kt b/domain/feedback/src/main/java/com/tangem/domain/feedback/FeedbackManager.kt new file mode 100644 index 0000000000..bc18ec66ec --- /dev/null +++ b/domain/feedback/src/main/java/com/tangem/domain/feedback/FeedbackManager.kt @@ -0,0 +1,8 @@ +package com.tangem.domain.feedback + +import com.tangem.domain.feedback.models.FeedbackEmailType + +interface FeedbackManager { + + fun sendEmail(type: FeedbackEmailType) +} \ No newline at end of file diff --git a/domain/feedback/src/main/java/com/tangem/domain/feedback/GetCardInfoUseCase.kt b/domain/feedback/src/main/java/com/tangem/domain/feedback/GetCardInfoUseCase.kt new file mode 100644 index 0000000000..9d9fc6995c --- /dev/null +++ b/domain/feedback/src/main/java/com/tangem/domain/feedback/GetCardInfoUseCase.kt @@ -0,0 +1,23 @@ +package com.tangem.domain.feedback + +import arrow.core.Either +import arrow.core.Either.Companion.catch +import com.tangem.domain.feedback.models.CardInfo +import com.tangem.domain.feedback.repository.FeedbackRepository +import com.tangem.domain.models.scan.ScanResponse + +/** + * UseCase for creating 'CardInfo' + * + * @property feedbackRepository feedback repository + * +[REDACTED_AUTHOR] + */ +class GetCardInfoUseCase( + private val feedbackRepository: FeedbackRepository, +) { + + suspend operator fun invoke(scanResponse: ScanResponse): Either { + return catch { feedbackRepository.getCardInfo(scanResponse) } + } +} \ No newline at end of file diff --git a/domain/feedback/src/main/java/com/tangem/domain/feedback/GetFeedbackEmailUseCase.kt b/domain/feedback/src/main/java/com/tangem/domain/feedback/GetFeedbackEmailUseCase.kt index 50998a4ed8..acdcc492b7 100644 --- a/domain/feedback/src/main/java/com/tangem/domain/feedback/GetFeedbackEmailUseCase.kt +++ b/domain/feedback/src/main/java/com/tangem/domain/feedback/GetFeedbackEmailUseCase.kt @@ -25,23 +25,21 @@ class GetFeedbackEmailUseCase( private val emailMessageBodyResolver = EmailMessageBodyResolver(feedbackRepository) suspend operator fun invoke(type: FeedbackEmailType): FeedbackEmail { - val cardInfo = feedbackRepository.getCardInfo() - val formattedLogs = AppLogsFormatter().format(appLogs = feedbackRepository.getAppLogs()) return FeedbackEmail( - address = getAddress(cardInfo), - subject = emailSubjectResolver.resolve(type, cardInfo), - message = createMessage(type, cardInfo), + address = getAddress(type.cardInfo), + subject = emailSubjectResolver.resolve(type), + message = createMessage(type), file = feedbackRepository.createLogFile(logs = formattedLogs), ) } - private fun getAddress(cardInfo: CardInfo): String { - return if (cardInfo.isStart2Coin) START2COIN_SUPPORT_EMAIL else TANGEM_SUPPORT_EMAIL + private fun getAddress(cardInfo: CardInfo?): String { + return if (cardInfo?.isStart2Coin == true) START2COIN_SUPPORT_EMAIL else TANGEM_SUPPORT_EMAIL } - private suspend fun createMessage(type: FeedbackEmailType, cardInfo: CardInfo): String { + private suspend fun createMessage(type: FeedbackEmailType): String { return StringBuilder().apply { val title = emailMessageTitleResolver.resolve(type) append(title) @@ -50,9 +48,7 @@ class GetFeedbackEmailUseCase( appendDisclaimerIfNeeded(type) - skipLine() - - val body = emailMessageBodyResolver.resolve(type, cardInfo) + val body = emailMessageBodyResolver.resolve(type) append(body) }.toString() } @@ -62,6 +58,7 @@ class GetFeedbackEmailUseCase( this } else { append(resources.getString(R.string.feedback_data_collection_message)) + skipLine() } } } \ No newline at end of file diff --git a/domain/feedback/src/main/java/com/tangem/domain/feedback/models/CardInfo.kt b/domain/feedback/src/main/java/com/tangem/domain/feedback/models/CardInfo.kt index 7ae84ac608..2e7e710cc1 100644 --- a/domain/feedback/src/main/java/com/tangem/domain/feedback/models/CardInfo.kt +++ b/domain/feedback/src/main/java/com/tangem/domain/feedback/models/CardInfo.kt @@ -1,6 +1,9 @@ package com.tangem.domain.feedback.models +import com.tangem.domain.wallets.models.UserWalletId + data class CardInfo( + val userWalletId: UserWalletId?, val cardId: String, val firmwareVersion: String, val cardBlockchain: String?, diff --git a/domain/feedback/src/main/java/com/tangem/domain/feedback/models/FeedbackEmailType.kt b/domain/feedback/src/main/java/com/tangem/domain/feedback/models/FeedbackEmailType.kt index 6bbd5a9670..1e4971e4cf 100644 --- a/domain/feedback/src/main/java/com/tangem/domain/feedback/models/FeedbackEmailType.kt +++ b/domain/feedback/src/main/java/com/tangem/domain/feedback/models/FeedbackEmailType.kt @@ -7,15 +7,19 @@ package com.tangem.domain.feedback.models */ sealed interface FeedbackEmailType { + val cardInfo: CardInfo? + /** User initiate request yourself. Example, button on DetailsScreen or OnboardingScreen */ - data object DirectUserRequest : FeedbackEmailType + data class DirectUserRequest(override val cardInfo: CardInfo) : FeedbackEmailType /** User rate the app as "can be better" */ - data object RateCanBeBetter : FeedbackEmailType + data class RateCanBeBetter(override val cardInfo: CardInfo) : FeedbackEmailType /** User has problem with scanning */ - data object ScanningProblem : FeedbackEmailType + data object ScanningProblem : FeedbackEmailType { + override val cardInfo: CardInfo? = null + } /** User has problem with sending transaction */ - data object TransactionSendingProblem : FeedbackEmailType + data class TransactionSendingProblem(override val cardInfo: CardInfo) : FeedbackEmailType } \ No newline at end of file diff --git a/domain/feedback/src/main/java/com/tangem/domain/feedback/repository/FeedbackRepository.kt b/domain/feedback/src/main/java/com/tangem/domain/feedback/repository/FeedbackRepository.kt index c9d6806eea..1b5de9c70c 100644 --- a/domain/feedback/src/main/java/com/tangem/domain/feedback/repository/FeedbackRepository.kt +++ b/domain/feedback/src/main/java/com/tangem/domain/feedback/repository/FeedbackRepository.kt @@ -1,23 +1,29 @@ package com.tangem.domain.feedback.repository import com.tangem.domain.feedback.models.* +import com.tangem.domain.models.scan.ScanResponse +import com.tangem.domain.wallets.models.UserWalletId import java.io.File interface FeedbackRepository { - suspend fun getUserWalletsInfo(): UserWalletsInfo + suspend fun getCardInfo(scanResponse: ScanResponse): CardInfo - suspend fun getCardInfo(): CardInfo + suspend fun getUserWalletsInfo(userWalletId: UserWalletId?): UserWalletsInfo - suspend fun getBlockchainInfoList(): List - - suspend fun getBlockchainInfo(blockchainId: String, derivationPath: String?): BlockchainInfo? + suspend fun getBlockchainInfoList(userWalletId: UserWalletId): List fun getPhoneInfo(): PhoneInfo + suspend fun getBlockchainInfo( + userWalletId: UserWalletId, + blockchainId: String, + derivationPath: String?, + ): BlockchainInfo? + fun saveBlockchainErrorInfo(error: BlockchainErrorInfo) - suspend fun getBlockchainErrorInfo(): BlockchainErrorInfo? + suspend fun getBlockchainErrorInfo(userWalletId: UserWalletId): BlockchainErrorInfo? suspend fun getAppLogs(): List diff --git a/domain/feedback/src/main/java/com/tangem/domain/feedback/utils/EmailMessageBodyResolver.kt b/domain/feedback/src/main/java/com/tangem/domain/feedback/utils/EmailMessageBodyResolver.kt index 8574fb1010..a9bb1a64dd 100644 --- a/domain/feedback/src/main/java/com/tangem/domain/feedback/utils/EmailMessageBodyResolver.kt +++ b/domain/feedback/src/main/java/com/tangem/domain/feedback/utils/EmailMessageBodyResolver.kt @@ -16,25 +16,33 @@ internal class EmailMessageBodyResolver( private val feedbackRepository: FeedbackRepository, ) { - /** Resolve email message body by [type] using [cardInfo] */ - suspend fun resolve(type: FeedbackEmailType, cardInfo: CardInfo): String = with(FeedbackDataBuilder()) { + /** Resolve email message body by [type] */ + suspend fun resolve(type: FeedbackEmailType): String = with(FeedbackDataBuilder()) { when (type) { - FeedbackEmailType.DirectUserRequest -> addUserRequestBody(cardInfo) - FeedbackEmailType.RateCanBeBetter -> addCardAndPhoneInfo(cardInfo) - FeedbackEmailType.ScanningProblem -> addScanningProblemBody() - FeedbackEmailType.TransactionSendingProblem -> addTransactionSendingProblemBody(cardInfo) + is FeedbackEmailType.DirectUserRequest -> addUserRequestBody(type.cardInfo) + is FeedbackEmailType.RateCanBeBetter -> addCardAndPhoneInfo(type.cardInfo) + is FeedbackEmailType.ScanningProblem -> addScanningProblemBody() + is FeedbackEmailType.TransactionSendingProblem -> addTransactionSendingProblemBody(type.cardInfo) } return build() } private suspend fun FeedbackDataBuilder.addUserRequestBody(cardInfo: CardInfo) { - addUserWalletsInfo(userWalletsInfo = feedbackRepository.getUserWalletsInfo()) + addUserWalletsInfo(userWalletsInfo = feedbackRepository.getUserWalletsInfo(cardInfo.userWalletId)) addDelimiter() addCardInfo(cardInfo) addDelimiter() - addBlockchainInfoList(blockchainInfoList = feedbackRepository.getBlockchainInfoList()) - addDelimiter() + + if (cardInfo.userWalletId != null) { + val blockchainInfoList = feedbackRepository.getBlockchainInfoList(cardInfo.userWalletId) + + if (blockchainInfoList.isNotEmpty()) { + addBlockchainInfoList(blockchainInfoList = blockchainInfoList) + addDelimiter() + } + } + addPhoneInfo(phoneInfo = feedbackRepository.getPhoneInfo()) } @@ -46,9 +54,11 @@ internal class EmailMessageBodyResolver( addCardInfo(cardInfo) addDelimiter() - val blockchainError = feedbackRepository.getBlockchainErrorInfo() + val userWalletId = requireNotNull(cardInfo.userWalletId) { "UserWalletId must be not null" } + val blockchainError = feedbackRepository.getBlockchainErrorInfo(userWalletId = userWalletId) val blockchainInfo = blockchainError?.let { feedbackRepository.getBlockchainInfo( + userWalletId = userWalletId, blockchainId = blockchainError.blockchainId, derivationPath = blockchainError.derivationPath, ) diff --git a/domain/feedback/src/main/java/com/tangem/domain/feedback/utils/EmailMessageTitleResolver.kt b/domain/feedback/src/main/java/com/tangem/domain/feedback/utils/EmailMessageTitleResolver.kt index 38c983c617..6ab001b775 100644 --- a/domain/feedback/src/main/java/com/tangem/domain/feedback/utils/EmailMessageTitleResolver.kt +++ b/domain/feedback/src/main/java/com/tangem/domain/feedback/utils/EmailMessageTitleResolver.kt @@ -16,10 +16,10 @@ internal class EmailMessageTitleResolver(private val resources: Resources) { /** Resolve email message title by [type] */ fun resolve(type: FeedbackEmailType): String { return when (type) { - FeedbackEmailType.DirectUserRequest -> R.string.feedback_preface_support - FeedbackEmailType.RateCanBeBetter -> R.string.feedback_preface_rate_negative - FeedbackEmailType.ScanningProblem -> R.string.feedback_preface_scan_failed - FeedbackEmailType.TransactionSendingProblem -> R.string.feedback_preface_tx_failed + is FeedbackEmailType.DirectUserRequest -> R.string.feedback_preface_support + is FeedbackEmailType.RateCanBeBetter -> R.string.feedback_preface_rate_negative + is FeedbackEmailType.ScanningProblem -> R.string.feedback_preface_scan_failed + is FeedbackEmailType.TransactionSendingProblem -> R.string.feedback_preface_tx_failed } .let(resources::getString) } diff --git a/domain/feedback/src/main/java/com/tangem/domain/feedback/utils/EmailSubjectResolver.kt b/domain/feedback/src/main/java/com/tangem/domain/feedback/utils/EmailSubjectResolver.kt index 392fa7d2f4..beb89739bd 100644 --- a/domain/feedback/src/main/java/com/tangem/domain/feedback/utils/EmailSubjectResolver.kt +++ b/domain/feedback/src/main/java/com/tangem/domain/feedback/utils/EmailSubjectResolver.kt @@ -2,7 +2,6 @@ package com.tangem.domain.feedback.utils import android.content.res.Resources import com.tangem.domain.feedback.R -import com.tangem.domain.feedback.models.CardInfo import com.tangem.domain.feedback.models.FeedbackEmailType /** @@ -14,19 +13,19 @@ import com.tangem.domain.feedback.models.FeedbackEmailType */ internal class EmailSubjectResolver(private val resources: Resources) { - /** Resolve email message body by [type] using [cardInfo] */ - fun resolve(type: FeedbackEmailType, cardInfo: CardInfo): String { + /** Resolve email message body by [type] */ + fun resolve(type: FeedbackEmailType): String { return when (type) { - FeedbackEmailType.DirectUserRequest -> { - if (cardInfo.isStart2Coin) { + is FeedbackEmailType.DirectUserRequest -> { + if (type.cardInfo.isStart2Coin) { R.string.feedback_subject_support } else { R.string.feedback_subject_support_tangem } } - FeedbackEmailType.RateCanBeBetter -> R.string.feedback_subject_rate_negative - FeedbackEmailType.ScanningProblem -> R.string.feedback_subject_scan_failed - FeedbackEmailType.TransactionSendingProblem -> R.string.feedback_subject_tx_failed + is FeedbackEmailType.RateCanBeBetter -> R.string.feedback_subject_rate_negative + is FeedbackEmailType.ScanningProblem -> R.string.feedback_subject_scan_failed + is FeedbackEmailType.TransactionSendingProblem -> R.string.feedback_subject_tx_failed } .let(resources::getString) } diff --git a/domain/legacy/src/main/java/com/tangem/domain/common/LogConfig.kt b/domain/legacy/src/main/java/com/tangem/domain/common/LogConfig.kt index 9373ae2a5b..9dbf3c435b 100644 --- a/domain/legacy/src/main/java/com/tangem/domain/common/LogConfig.kt +++ b/domain/legacy/src/main/java/com/tangem/domain/common/LogConfig.kt @@ -19,6 +19,6 @@ object NetworkLogConfig { } object AnalyticsHandlersLogConfig { - const val firebase: Boolean = false + val firebase: Boolean = BuildConfig.LOG_ENABLED val amplitude: Boolean = BuildConfig.LOG_ENABLED } \ No newline at end of file diff --git a/domain/legacy/src/main/java/com/tangem/domain/common/TangemCardTypesResolver.kt b/domain/legacy/src/main/java/com/tangem/domain/common/TangemCardTypesResolver.kt index 82208040e8..6a4afdcfd9 100644 --- a/domain/legacy/src/main/java/com/tangem/domain/common/TangemCardTypesResolver.kt +++ b/domain/legacy/src/main/java/com/tangem/domain/common/TangemCardTypesResolver.kt @@ -143,7 +143,13 @@ internal class TangemCardTypesResolver( override fun getRemainingSignatures(): Int? = card.wallets.firstOrNull()?.remainingSignatures - override fun getCardId(): String = card.cardId + override fun getCardId(): String { + return if (isTangemTwins()) { + card.getTwinCardIdForUser() + } else { + card.cardId + } + } override fun isTestCard(): Boolean = card.isTestCard diff --git a/domain/legacy/src/main/java/com/tangem/domain/common/util/ScanResponseExtensions.kt b/domain/legacy/src/main/java/com/tangem/domain/common/util/ScanResponseExtensions.kt index 61ec0cc72e..1c3519f606 100644 --- a/domain/legacy/src/main/java/com/tangem/domain/common/util/ScanResponseExtensions.kt +++ b/domain/legacy/src/main/java/com/tangem/domain/common/util/ScanResponseExtensions.kt @@ -13,6 +13,7 @@ import com.tangem.domain.common.TapWorkarounds.isTestCard import com.tangem.domain.common.configs.CardConfig import com.tangem.domain.common.configs.Wallet2CardConfig import com.tangem.domain.models.scan.ScanResponse +import com.tangem.domain.wallets.models.UserWallet val ScanResponse.cardTypesResolver: CardTypesResolver get() = TangemCardTypesResolver( @@ -27,6 +28,9 @@ val ScanResponse.derivationStyleProvider: DerivationStyleProvider card, ) +val UserWallet.cardTypesResolver: CardTypesResolver + get() = scanResponse.cardTypesResolver + fun ScanResponse.twinsIsTwinned(): Boolean = card.isTangemTwins && walletData != null && secondTwinPublicKey != null fun ScanResponse.supportsHdWallet(): Boolean = card.settings.isHDWalletAllowed fun ScanResponse.supportsBackup(): Boolean = card.settings.isBackupAllowed diff --git a/domain/legacy/src/main/java/com/tangem/domain/exchange/RampStateManager.kt b/domain/legacy/src/main/java/com/tangem/domain/exchange/RampStateManager.kt index ac9b4fa892..2536d78ea9 100644 --- a/domain/legacy/src/main/java/com/tangem/domain/exchange/RampStateManager.kt +++ b/domain/legacy/src/main/java/com/tangem/domain/exchange/RampStateManager.kt @@ -1,5 +1,6 @@ package com.tangem.domain.exchange +import com.tangem.domain.models.scan.ScanResponse import com.tangem.domain.tokens.model.CryptoCurrency /** @@ -7,7 +8,7 @@ import com.tangem.domain.tokens.model.CryptoCurrency */ interface RampStateManager { - fun availableForBuy(cryptoCurrency: CryptoCurrency): Boolean + fun availableForBuy(scanResponse: ScanResponse, cryptoCurrency: CryptoCurrency): Boolean fun availableForSell(cryptoCurrency: CryptoCurrency): Boolean } \ No newline at end of file diff --git a/domain/legacy/src/main/java/com/tangem/domain/redux/LegacyAction.kt b/domain/legacy/src/main/java/com/tangem/domain/redux/LegacyAction.kt index eb116384ba..ab0183d09e 100644 --- a/domain/legacy/src/main/java/com/tangem/domain/redux/LegacyAction.kt +++ b/domain/legacy/src/main/java/com/tangem/domain/redux/LegacyAction.kt @@ -8,9 +8,9 @@ import java.math.BigDecimal sealed interface LegacyAction : Action { - data object SendEmailSupport : LegacyAction + data class SendEmailSupport(val scanResponse: ScanResponse) : LegacyAction - data object SendEmailRateCanBeBetter : LegacyAction + data class SendEmailRateCanBeBetter(val scanResponse: ScanResponse) : LegacyAction /** * Initiate an onboarding process. @@ -36,5 +36,6 @@ sealed interface LegacyAction : Action { val fee: BigDecimal?, val destinationAddress: String?, val errorMessage: String, + val scanResponse: ScanResponse, ) : LegacyAction } \ No newline at end of file diff --git a/domain/legacy/src/main/java/com/tangem/domain/redux/ReduxStateHolder.kt b/domain/legacy/src/main/java/com/tangem/domain/redux/ReduxStateHolder.kt index 80e03d9347..afa5e3bf04 100644 --- a/domain/legacy/src/main/java/com/tangem/domain/redux/ReduxStateHolder.kt +++ b/domain/legacy/src/main/java/com/tangem/domain/redux/ReduxStateHolder.kt @@ -11,5 +11,5 @@ interface ReduxStateHolder { suspend fun onUserWalletSelected(userWallet: UserWallet) - fun sendFeedbackEmail() + fun dispatchDialogShow(dialog: StateDialog) } \ No newline at end of file diff --git a/domain/legacy/src/main/java/com/tangem/domain/redux/StateDialog.kt b/domain/legacy/src/main/java/com/tangem/domain/redux/StateDialog.kt new file mode 100644 index 0000000000..e4beb677bd --- /dev/null +++ b/domain/legacy/src/main/java/com/tangem/domain/redux/StateDialog.kt @@ -0,0 +1,10 @@ +package com.tangem.domain.redux + +interface StateDialog { + + data class ScanFailsDialog(val source: ScanFailsSource, val onTryAgain: (() -> Unit)? = null) : StateDialog + + enum class ScanFailsSource { + MAIN, SIGN_IN, SETTINGS, INTRO; + } +} \ No newline at end of file diff --git a/domain/legacy/src/main/java/com/tangem/domain/walletmanager/DefaultWalletManagersFacade.kt b/domain/legacy/src/main/java/com/tangem/domain/walletmanager/DefaultWalletManagersFacade.kt index 25dae1f2dd..68f4060640 100644 --- a/domain/legacy/src/main/java/com/tangem/domain/walletmanager/DefaultWalletManagersFacade.kt +++ b/domain/legacy/src/main/java/com/tangem/domain/walletmanager/DefaultWalletManagersFacade.kt @@ -45,7 +45,7 @@ import timber.log.Timber import java.math.BigDecimal import java.util.EnumSet -@Suppress("LargeClass", "TooManyFunctions", "LongParameterList") +@Suppress("LargeClass", "TooManyFunctions") // FIXME: Move to its own module and make internal @Deprecated("Inject the WalletManagerFacade interface using DI instead") class DefaultWalletManagersFacade( @@ -474,7 +474,7 @@ class DefaultWalletManagersFacade( amount: Amount, userWalletId: UserWalletId, network: Network, - ): Result? { + ): Result? = withContext(dispatchers.io) { val blockchain = Blockchain.fromId(network.id.value) val walletManager = getOrCreateWalletManager( userWalletId = userWalletId, @@ -484,7 +484,7 @@ class DefaultWalletManagersFacade( val destination = estimationFeeAddressFactory.makeAddress(blockchain) - return (walletManager as? TransactionSender)?.estimateFee( + (walletManager as? TransactionSender)?.estimateFee( amount = amount, destination = destination, ) diff --git a/domain/legacy/src/main/java/com/tangem/domain/walletmanager/utils/TransactionDataToTxHistoryItemConverter.kt b/domain/legacy/src/main/java/com/tangem/domain/walletmanager/utils/TransactionDataToTxHistoryItemConverter.kt index cd756efd3c..22ae5adecc 100644 --- a/domain/legacy/src/main/java/com/tangem/domain/walletmanager/utils/TransactionDataToTxHistoryItemConverter.kt +++ b/domain/legacy/src/main/java/com/tangem/domain/walletmanager/utils/TransactionDataToTxHistoryItemConverter.kt @@ -17,9 +17,9 @@ import java.math.BigDecimal internal class TransactionDataToTxHistoryItemConverter( private val walletAddresses: Set
, private val feePaidCurrency: FeePaidCurrency, -) : Converter { +) : Converter { - override fun convert(value: TransactionData): TxHistoryItem? { + override fun convert(value: TransactionData.Uncompiled): TxHistoryItem? { val hash = value.hash ?: return null val millis = value.date?.timeInMillis ?: return null val amount = getTransactionAmountValue(value.amount, value.fee?.amount) ?: return null diff --git a/domain/legacy/src/main/java/com/tangem/domain/walletmanager/utils/UpdateWalletManagerResultFactory.kt b/domain/legacy/src/main/java/com/tangem/domain/walletmanager/utils/UpdateWalletManagerResultFactory.kt index 84b194166b..df5aa57530 100644 --- a/domain/legacy/src/main/java/com/tangem/domain/walletmanager/utils/UpdateWalletManagerResultFactory.kt +++ b/domain/legacy/src/main/java/com/tangem/domain/walletmanager/utils/UpdateWalletManagerResultFactory.kt @@ -90,7 +90,7 @@ internal class UpdateWalletManagerResultFactory { private fun getCurrentTransactions( txHistoryItemConverter: TransactionDataToTxHistoryItemConverter, - recentTransactions: Set, + recentTransactions: Set, ): Set { val unconfirmedTransactions = recentTransactions.filter { it.status == TransactionStatus.Unconfirmed @@ -122,7 +122,7 @@ internal class UpdateWalletManagerResultFactory { private fun createCurrencyTransaction( txHistoryItemConverter: TransactionDataToTxHistoryItemConverter, - data: TransactionData, + data: TransactionData.Uncompiled, ): CryptoCurrencyTransaction? { return when (val type = data.amount.type) { is AmountType.Coin -> { diff --git a/domain/markets/.gitignore b/domain/markets/.gitignore new file mode 100644 index 0000000000..42afabfd2a --- /dev/null +++ b/domain/markets/.gitignore @@ -0,0 +1 @@ +/build \ No newline at end of file diff --git a/domain/markets/build.gradle.kts b/domain/markets/build.gradle.kts new file mode 100644 index 0000000000..5529922be2 --- /dev/null +++ b/domain/markets/build.gradle.kts @@ -0,0 +1,20 @@ +plugins { + alias(deps.plugins.android.library) + alias(deps.plugins.kotlin.android) + alias(deps.plugins.kotlin.serialization) + id("configuration") +} + +android { + namespace = "com.tangem.domain.markets" +} + + +dependencies { + api(projects.domain.markets.models) + api(projects.domain.core) + api(projects.core.pagination) + + implementation(deps.kotlin.serialization) + implementation(projects.domain.tokens.models) +} \ No newline at end of file diff --git a/domain/markets/models/.gitignore b/domain/markets/models/.gitignore new file mode 100644 index 0000000000..42afabfd2a --- /dev/null +++ b/domain/markets/models/.gitignore @@ -0,0 +1 @@ +/build \ No newline at end of file diff --git a/domain/markets/models/build.gradle.kts b/domain/markets/models/build.gradle.kts new file mode 100644 index 0000000000..7558c5ca61 --- /dev/null +++ b/domain/markets/models/build.gradle.kts @@ -0,0 +1,12 @@ +plugins { + alias(deps.plugins.kotlin.jvm) + alias(deps.plugins.kotlin.serialization) + id("configuration") +} + +dependencies { + implementation(projects.domain.core) + + implementation(deps.kotlin.serialization) + implementation(deps.jodatime) +} \ No newline at end of file diff --git a/domain/markets/models/src/main/kotlin/com/tangem/domain/markets/PriceChangeInterval.kt b/domain/markets/models/src/main/kotlin/com/tangem/domain/markets/PriceChangeInterval.kt new file mode 100644 index 0000000000..ff9b0ba89a --- /dev/null +++ b/domain/markets/models/src/main/kotlin/com/tangem/domain/markets/PriceChangeInterval.kt @@ -0,0 +1,5 @@ +package com.tangem.domain.markets + +enum class PriceChangeInterval { + H24, WEEK, MONTH, MONTH3, MONTH6, YEAR, ALL_TIME +} \ No newline at end of file diff --git a/domain/markets/models/src/main/kotlin/com/tangem/domain/markets/TokenChart.kt b/domain/markets/models/src/main/kotlin/com/tangem/domain/markets/TokenChart.kt new file mode 100644 index 0000000000..d239ae395a --- /dev/null +++ b/domain/markets/models/src/main/kotlin/com/tangem/domain/markets/TokenChart.kt @@ -0,0 +1,13 @@ +package com.tangem.domain.markets + +import java.math.BigDecimal + +data class TokenChart( + val interval: PriceChangeInterval, + val priceY: List, + val timeStamp: List, +) { + init { + require(priceY.size == timeStamp.size) + } +} \ No newline at end of file diff --git a/domain/markets/models/src/main/kotlin/com/tangem/domain/markets/TokenMarket.kt b/domain/markets/models/src/main/kotlin/com/tangem/domain/markets/TokenMarket.kt new file mode 100644 index 0000000000..b7316cf79a --- /dev/null +++ b/domain/markets/models/src/main/kotlin/com/tangem/domain/markets/TokenMarket.kt @@ -0,0 +1,33 @@ +package com.tangem.domain.markets + +import java.math.BigDecimal + +data class TokenMarket( + val id: String, + val name: String, + val symbol: String, + val marketRating: Int?, + val marketCap: BigDecimal?, + val tokenQuotes: TokenQuotes, + val tokenCharts: Charts, + private val imageHost: String, +) { + + data class Charts( + val h24: TokenChart?, + val week: TokenChart?, + val month: TokenChart?, + ) + + // 25x25 + val imageUrlThumb = + "${imageHost}thumb/$id.png" + + // 50x50 + val imageUrlSmall = + "${imageHost}small/$id.png" + + // 250x250 + val imageUrlLarge = + "${imageHost}large/$id.png" +} \ No newline at end of file diff --git a/domain/markets/models/src/main/kotlin/com/tangem/domain/markets/TokenMarketListConfig.kt b/domain/markets/models/src/main/kotlin/com/tangem/domain/markets/TokenMarketListConfig.kt new file mode 100644 index 0000000000..ad952091b6 --- /dev/null +++ b/domain/markets/models/src/main/kotlin/com/tangem/domain/markets/TokenMarketListConfig.kt @@ -0,0 +1,18 @@ +package com.tangem.domain.markets + +data class TokenMarketListConfig( + val fiatPriceCurrency: String, + val searchText: String?, + val showUnder100kMarketCapTokens: Boolean, + val priceChangeInterval: Interval, + val order: Order, +) { + + enum class Order { + ByRating, Trending, Buyers, TopGainers, TopLosers + } + + enum class Interval { + H24, WEEK, MONTH, + } +} \ No newline at end of file diff --git a/domain/markets/models/src/main/kotlin/com/tangem/domain/markets/TokenMarketUpdateRequest.kt b/domain/markets/models/src/main/kotlin/com/tangem/domain/markets/TokenMarketUpdateRequest.kt new file mode 100644 index 0000000000..bcac52fddb --- /dev/null +++ b/domain/markets/models/src/main/kotlin/com/tangem/domain/markets/TokenMarketUpdateRequest.kt @@ -0,0 +1,13 @@ +package com.tangem.domain.markets + +sealed class TokenMarketUpdateRequest { + + data class UpdateQuotes( + val currencyId: String, + ) : TokenMarketUpdateRequest() + + data class UpdateChart( + val interval: PriceChangeInterval, + val currency: String, + ) : TokenMarketUpdateRequest() +} \ No newline at end of file diff --git a/domain/markets/models/src/main/kotlin/com/tangem/domain/markets/TokenQuotes.kt b/domain/markets/models/src/main/kotlin/com/tangem/domain/markets/TokenQuotes.kt new file mode 100644 index 0000000000..7a162c9aac --- /dev/null +++ b/domain/markets/models/src/main/kotlin/com/tangem/domain/markets/TokenQuotes.kt @@ -0,0 +1,18 @@ +package com.tangem.domain.markets + +import java.math.BigDecimal + +data class TokenQuotes( + val currentPrice: BigDecimal, + private val priceChanges: Map, +) { + init { + require(priceChanges.containsKey(PriceChangeInterval.H24)) + require(priceChanges.containsKey(PriceChangeInterval.WEEK)) + require(priceChanges.containsKey(PriceChangeInterval.MONTH)) + } + + fun h24Percent() = priceChanges[PriceChangeInterval.H24]!! + fun weekPercent() = priceChanges[PriceChangeInterval.WEEK]!! + fun monthPercent() = priceChanges[PriceChangeInterval.MONTH]!! +} \ No newline at end of file diff --git a/domain/markets/src/main/java/com/tangem/domain/markets/GetMarketsTokenListFlowUseCase.kt b/domain/markets/src/main/java/com/tangem/domain/markets/GetMarketsTokenListFlowUseCase.kt new file mode 100644 index 0000000000..8ba13797a3 --- /dev/null +++ b/domain/markets/src/main/java/com/tangem/domain/markets/GetMarketsTokenListFlowUseCase.kt @@ -0,0 +1,28 @@ +package com.tangem.domain.markets + +import com.tangem.domain.markets.repositories.MarketsTokenRepository +import com.tangem.pagination.BatchFlow +import com.tangem.pagination.BatchingContext + +typealias TokenListBatchingContext = BatchingContext +typealias TokenListBatchFlow = BatchFlow, TokenMarketUpdateRequest> + +class GetMarketsTokenListFlowUseCase( + private val marketsTokenRepository: MarketsTokenRepository, +) { + operator fun invoke(batchingContext: TokenListBatchingContext, batchFlowType: BatchFlowType): TokenListBatchFlow { + return marketsTokenRepository.getTokenListFlow( + batchingContext = batchingContext, + firstBatchSize = batchFlowType.firstBatchSize, + nextBatchSize = batchFlowType.nextBatchSize, + ) + } + + enum class BatchFlowType( + val firstBatchSize: Int, + val nextBatchSize: Int, + ) { + Main(firstBatchSize = 150, nextBatchSize = 100), + Search(firstBatchSize = 50, nextBatchSize = 50), + } +} \ No newline at end of file diff --git a/domain/markets/src/main/java/com/tangem/domain/markets/repositories/MarketsTokenRepository.kt b/domain/markets/src/main/java/com/tangem/domain/markets/repositories/MarketsTokenRepository.kt new file mode 100644 index 0000000000..31693705dc --- /dev/null +++ b/domain/markets/src/main/java/com/tangem/domain/markets/repositories/MarketsTokenRepository.kt @@ -0,0 +1,12 @@ +package com.tangem.domain.markets.repositories + +import com.tangem.domain.markets.* + +interface MarketsTokenRepository { + + fun getTokenListFlow( + batchingContext: TokenListBatchingContext, + firstBatchSize: Int, + nextBatchSize: Int, + ): TokenListBatchFlow +} \ No newline at end of file diff --git a/domain/models/build.gradle.kts b/domain/models/build.gradle.kts index fbccb4120d..bf25c0f8b6 100644 --- a/domain/models/build.gradle.kts +++ b/domain/models/build.gradle.kts @@ -1,9 +1,11 @@ plugins { alias(deps.plugins.kotlin.jvm) + alias(deps.plugins.kotlin.serialization) id("configuration") } dependencies { implementation(deps.tangem.card.core) implementation(deps.moshi.kotlin) + implementation(deps.kotlin.serialization) } \ No newline at end of file diff --git a/domain/models/src/main/kotlin/com/tangem/domain/models/scan/CardDTO.kt b/domain/models/src/main/kotlin/com/tangem/domain/models/scan/CardDTO.kt index ff2b5be1d0..fcce746f21 100644 --- a/domain/models/src/main/kotlin/com/tangem/domain/models/scan/CardDTO.kt +++ b/domain/models/src/main/kotlin/com/tangem/domain/models/scan/CardDTO.kt @@ -299,6 +299,7 @@ data class CardDTO( } sealed class BackupStatus { + data class CardLinked(val cardCount: Int) : BackupStatus() data class Active(val cardCount: Int) : BackupStatus() diff --git a/domain/settings/src/main/java/com/tangem/domain/settings/NeverRequestPermissionUseCase.kt b/domain/settings/src/main/java/com/tangem/domain/settings/NeverRequestPermissionUseCase.kt new file mode 100644 index 0000000000..84d654dc42 --- /dev/null +++ b/domain/settings/src/main/java/com/tangem/domain/settings/NeverRequestPermissionUseCase.kt @@ -0,0 +1,13 @@ +package com.tangem.domain.settings + +import arrow.core.Either +import com.tangem.domain.settings.repositories.PermissionRepository + +class NeverRequestPermissionUseCase( + private val repository: PermissionRepository, +) { + + suspend operator fun invoke(permission: String): Either = Either.catch { + repository.neverAskPermission(permission) + } +} \ No newline at end of file diff --git a/domain/settings/src/main/java/com/tangem/domain/settings/NeverToInitiallyAskPermissionUseCase.kt b/domain/settings/src/main/java/com/tangem/domain/settings/NeverToInitiallyAskPermissionUseCase.kt new file mode 100644 index 0000000000..02baad3a02 --- /dev/null +++ b/domain/settings/src/main/java/com/tangem/domain/settings/NeverToInitiallyAskPermissionUseCase.kt @@ -0,0 +1,12 @@ +package com.tangem.domain.settings + +import com.tangem.domain.settings.repositories.PermissionRepository + +class NeverToInitiallyAskPermissionUseCase( + private val repository: PermissionRepository, +) { + + suspend operator fun invoke(permission: String) { + repository.neverInitiallyShowPermissionScreen(permission) + } +} \ No newline at end of file diff --git a/domain/settings/src/main/java/com/tangem/domain/settings/ShouldAskPermissionUseCase.kt b/domain/settings/src/main/java/com/tangem/domain/settings/ShouldAskPermissionUseCase.kt new file mode 100644 index 0000000000..44f063119a --- /dev/null +++ b/domain/settings/src/main/java/com/tangem/domain/settings/ShouldAskPermissionUseCase.kt @@ -0,0 +1,10 @@ +package com.tangem.domain.settings + +import com.tangem.domain.settings.repositories.PermissionRepository + +class ShouldAskPermissionUseCase( + private val repository: PermissionRepository, +) { + + suspend operator fun invoke(permission: String): Boolean = repository.shouldAskPermission(permission) +} \ No newline at end of file diff --git a/domain/settings/src/main/java/com/tangem/domain/settings/ShouldInitiallyAskPermissionUseCase.kt b/domain/settings/src/main/java/com/tangem/domain/settings/ShouldInitiallyAskPermissionUseCase.kt new file mode 100644 index 0000000000..b7d5a6f1ca --- /dev/null +++ b/domain/settings/src/main/java/com/tangem/domain/settings/ShouldInitiallyAskPermissionUseCase.kt @@ -0,0 +1,11 @@ +package com.tangem.domain.settings + +import arrow.core.Either +import com.tangem.domain.settings.repositories.PermissionRepository + +class ShouldInitiallyAskPermissionUseCase(private val repository: PermissionRepository) { + + suspend operator fun invoke(permission: String): Either = Either.catch { + repository.shouldInitiallyShowPermissionScreen(permission) + } +} \ No newline at end of file diff --git a/domain/settings/src/main/java/com/tangem/domain/settings/repositories/PermissionRepository.kt b/domain/settings/src/main/java/com/tangem/domain/settings/repositories/PermissionRepository.kt new file mode 100644 index 0000000000..21b476b233 --- /dev/null +++ b/domain/settings/src/main/java/com/tangem/domain/settings/repositories/PermissionRepository.kt @@ -0,0 +1,27 @@ +package com.tangem.domain.settings.repositories + +interface PermissionRepository { + + /** + * Return true if should display screen ONCE asking to allow [permission]. + * False otherwise or screen already was displayed + */ + suspend fun shouldInitiallyShowPermissionScreen(permission: String): Boolean + + /** + * Sets value indicating that screen for [permission] was shown in initial app launch + */ + suspend fun neverInitiallyShowPermissionScreen(permission: String) + + /** + * Is clear to ask [permission]. + * User could already granted or permanently denied permission + * Or there is an active delay before next request + */ + suspend fun shouldAskPermission(permission: String): Boolean + + /** + * Permanently deny [permission] and never request again + */ + suspend fun neverAskPermission(permission: String) +} \ No newline at end of file diff --git a/domain/staking/build.gradle.kts b/domain/staking/build.gradle.kts index f6a93898bb..e92bc23b4c 100644 --- a/domain/staking/build.gradle.kts +++ b/domain/staking/build.gradle.kts @@ -1,9 +1,23 @@ plugins { - alias(deps.plugins.kotlin.jvm) + alias(deps.plugins.android.library) + alias(deps.plugins.kotlin.android) + alias(deps.plugins.kotlin.serialization) id("configuration") } +android { + namespace = "com.tangem.domain.staking" +} + + dependencies { - implementation(deps.kotlin.coroutines) - implementation(deps.arrow.core) + api(projects.domain.staking.models) + + api(projects.domain.core) + implementation(deps.kotlin.serialization) + + implementation(projects.domain.tokens.models) + implementation(projects.domain.wallets.models) + + implementation(projects.features.staking.api) } \ No newline at end of file diff --git a/domain/staking/models/.gitignore b/domain/staking/models/.gitignore new file mode 100644 index 0000000000..796b96d1c4 --- /dev/null +++ b/domain/staking/models/.gitignore @@ -0,0 +1 @@ +/build diff --git a/domain/staking/models/build.gradle.kts b/domain/staking/models/build.gradle.kts new file mode 100644 index 0000000000..7558c5ca61 --- /dev/null +++ b/domain/staking/models/build.gradle.kts @@ -0,0 +1,12 @@ +plugins { + alias(deps.plugins.kotlin.jvm) + alias(deps.plugins.kotlin.serialization) + id("configuration") +} + +dependencies { + implementation(projects.domain.core) + + implementation(deps.kotlin.serialization) + implementation(deps.jodatime) +} \ No newline at end of file diff --git a/domain/staking/src/main/java/com/tangem/domain/staking/model/StakingAvailability.kt b/domain/staking/models/src/main/kotlin/com/tangem/domain/staking/model/StakingAvailability.kt similarity index 77% rename from domain/staking/src/main/java/com/tangem/domain/staking/model/StakingAvailability.kt rename to domain/staking/models/src/main/kotlin/com/tangem/domain/staking/model/StakingAvailability.kt index bf40ee3b58..d7eaa306e0 100644 --- a/domain/staking/src/main/java/com/tangem/domain/staking/model/StakingAvailability.kt +++ b/domain/staking/models/src/main/kotlin/com/tangem/domain/staking/model/StakingAvailability.kt @@ -5,4 +5,6 @@ sealed class StakingAvailability { data class Available(val integrationId: String) : StakingAvailability() data object Unavailable : StakingAvailability() + + data object TemporaryDisabled : StakingAvailability() } \ No newline at end of file diff --git a/domain/staking/src/main/java/com/tangem/domain/staking/model/StakingEntryInfo.kt b/domain/staking/models/src/main/kotlin/com/tangem/domain/staking/model/StakingEntryInfo.kt similarity index 100% rename from domain/staking/src/main/java/com/tangem/domain/staking/model/StakingEntryInfo.kt rename to domain/staking/models/src/main/kotlin/com/tangem/domain/staking/model/StakingEntryInfo.kt diff --git a/domain/staking/models/src/main/kotlin/com/tangem/domain/staking/model/StakingToken.kt b/domain/staking/models/src/main/kotlin/com/tangem/domain/staking/model/StakingToken.kt new file mode 100644 index 0000000000..5da29043d1 --- /dev/null +++ b/domain/staking/models/src/main/kotlin/com/tangem/domain/staking/model/StakingToken.kt @@ -0,0 +1,9 @@ +package com.tangem.domain.staking.model + +data class StakingToken( + val name: String, + val symbol: String, + val decimals: Int, + val contractAddress: String?, + val coinGeckoId: String?, +) \ No newline at end of file diff --git a/domain/staking/models/src/main/kotlin/com/tangem/domain/staking/model/StakingTokenWithYield.kt b/domain/staking/models/src/main/kotlin/com/tangem/domain/staking/model/StakingTokenWithYield.kt new file mode 100644 index 0000000000..833cb6ae49 --- /dev/null +++ b/domain/staking/models/src/main/kotlin/com/tangem/domain/staking/model/StakingTokenWithYield.kt @@ -0,0 +1,6 @@ +package com.tangem.domain.staking.model + +data class StakingTokenWithYield( + val token: StakingToken, + val availableYieldIds: List, +) \ No newline at end of file diff --git a/domain/staking/models/src/main/kotlin/com/tangem/domain/staking/model/UnsubmittedTransactionMetadata.kt b/domain/staking/models/src/main/kotlin/com/tangem/domain/staking/model/UnsubmittedTransactionMetadata.kt new file mode 100644 index 0000000000..e57067b382 --- /dev/null +++ b/domain/staking/models/src/main/kotlin/com/tangem/domain/staking/model/UnsubmittedTransactionMetadata.kt @@ -0,0 +1,6 @@ +package com.tangem.domain.staking.model + +data class UnsubmittedTransactionMetadata( + val transactionHash: String, + val transactionId: String, +) \ No newline at end of file diff --git a/domain/staking/models/src/main/kotlin/com/tangem/domain/staking/model/stakekit/NetworkType.kt b/domain/staking/models/src/main/kotlin/com/tangem/domain/staking/model/stakekit/NetworkType.kt new file mode 100644 index 0000000000..1d429683bc --- /dev/null +++ b/domain/staking/models/src/main/kotlin/com/tangem/domain/staking/model/stakekit/NetworkType.kt @@ -0,0 +1,71 @@ +package com.tangem.domain.staking.model.stakekit + +enum class NetworkType { + AVALANCHE_C, + AVALANCHE_ATOMIC, + AVALANCHE_P, + ARBITRUM, + BINANCE, + CELO, + ETHEREUM, + ETHEREUM_GOERLI, + ETHEREUM_HOLESKY, + FANTOM, + HARMONY, + OPTIMISM, + POLYGON, + GNOSIS, + MOONRIVER, + OKC, + ZKSYNC, + VICTION, + AGORIC, + AKASH, + AXELAR, + BAND_PROTOCOL, + BITSONG, + CANTO, + CHIHUAHUA, + COMDEX, + COREUM, + COSMOS, + CRESCENT, + CRONOS, + CUDOS, + DESMOS, + DYDX, + EVMOS, + FETCH_AI, + GRAVITY_BRIDGE, + INJECTIVE, + IRISNET, + JUNO, + KAVA, + KI_NETWORK, + MARS_PROTOCOL, + NYM, + OKEX_CHAIN, + ONOMY, + OSMOSIS, + PERSISTENCE, + QUICKSILVER, + REGEN, + SECRET, + SENTINEL, + SOMMELIER, + STAFI, + STARGAZE, + STRIDE, + TERITORI, + TGRADE, + UMEE, + POLKADOT, + KUSAMA, + WESTEND, + BINANCEBEACON, + NEAR, + SOLANA, + TEZOS, + TRON, + UNKNOWN, +} \ No newline at end of file diff --git a/domain/staking/models/src/main/kotlin/com/tangem/domain/staking/model/stakekit/StakingError.kt b/domain/staking/models/src/main/kotlin/com/tangem/domain/staking/model/stakekit/StakingError.kt new file mode 100644 index 0000000000..9fc68971f3 --- /dev/null +++ b/domain/staking/models/src/main/kotlin/com/tangem/domain/staking/model/stakekit/StakingError.kt @@ -0,0 +1,96 @@ +package com.tangem.domain.staking.model.stakekit + +sealed class StakingError { + + // region stakekit errors + + data class MinimumAmountNotReachedError(val amount: String) : StakingError() + + data class MissingArgumentsError(val arguments: String) : StakingError() + + data class YieldUnderMaintenanceError(val yieldId: String) : StakingError() + + data object InsufficientFundsError : StakingError() + + data object StakedPositionNotFoundError : StakingError() + + data object InvalidAmountSubmittedError : StakingError() + + data object BalanceUnavailableError : StakingError() + + data object GasPriceUnavailableError : StakingError() + + data object NotImplementedError : StakingError() + + data object TokenNotFoundError : StakingError() + + data object BroadcastTransactionError : StakingError() + + data object MissingGasPriceStrategyError : StakingError() + + data object SubstrateMalformedTransactionHashError : StakingError() + + data object TronMaximumAmountOfValidatorsExceededError : StakingError() + + data object SubstratePoolNotFoundError : StakingError() + + data object SubstrateBondedAmountTooLowError : StakingError() + + data object TronMissingResourceTypeArgumentError : StakingError() + + data object AaveV3PoolFrozenError : StakingError() + + data object AaveV3TokenPairNotFoundError : StakingError() + + data object YearnVaultAtMaxCapacityError : StakingError() + + data object StETHNoWithdrawalRequestsFoundError : StakingError() + + data object MorphoLendingPoolPausedError : StakingError() + + data object NonceUnavailableError : StakingError() + + data object CosmosAcccountNotFoundError : StakingError() + + data object AvalancheMissingAdditionalAddressesArgumentError : StakingError() + + data object AvalancheValidatorInfoNotFoundError : StakingError() + + data object SolanaTransactionSignatureVerificationFailureError : StakingError() + + data object SolanaUnableTocreateStakeAccountError : StakingError() + + data object SolanaStakeAmountTooLowError : StakingError() + + data object SolanaUnstakeAmountTooLowError : StakingError() + + data object SolanaStakeAccountsNotFoundError : StakingError() + + data object SolanaEligibleStakeAccountsNotFoundError : StakingError() + + data object TezosNoBalanceDelegatedError : StakingError() + + data object TezosMissingPubkeyArgumentError : StakingError() + + data object TezosEstimateRevealGasLimitError : StakingError() + + data object TezosBalanceAlreadyDelegatedError : StakingError() + + data object BinanceAccountNotFoundError : StakingError() + + data object BinanceMissingAccountNumberOrSequenceError : StakingError() + + data object GRTStakingDisabledError : StakingError() + + data object GRTStakingDisabledLedgerLiveError : StakingError() + + data class UnavailableDueToGeolocationError( + val tags: List, + ) : StakingError() + + // endregion + + data class DataError(val cause: Throwable) : StakingError() + + data object UnknownError : StakingError() +} \ No newline at end of file diff --git a/domain/staking/models/src/main/kotlin/com/tangem/domain/staking/model/stakekit/Yield.kt b/domain/staking/models/src/main/kotlin/com/tangem/domain/staking/model/stakekit/Yield.kt new file mode 100644 index 0000000000..e173689c6f --- /dev/null +++ b/domain/staking/models/src/main/kotlin/com/tangem/domain/staking/model/stakekit/Yield.kt @@ -0,0 +1,118 @@ +package com.tangem.domain.staking.model.stakekit + +import com.tangem.domain.core.serialization.SerializedBigDecimal +import kotlinx.serialization.Serializable + +@Serializable +data class Yield( + val id: String, + val token: Token, + val tokens: List, + val args: Args, + val status: Status, + val apy: SerializedBigDecimal, + val rewardRate: Double, + val rewardType: RewardType, + val metadata: Metadata, + val validators: List, + val isAvailable: Boolean, +) { + + @Serializable + data class Status( + val enter: Boolean, + val exit: Boolean?, + ) + + @Serializable + data class Args( + val enter: Enter, + val exit: Enter?, + ) { + + @Serializable + data class Enter( + val addresses: Addresses, + val args: Map, + ) { + + @Serializable + data class Addresses( + val address: AddressArgument, + val additionalAddresses: Map? = null, + ) + } + } + + @Serializable + data class Validator( + val address: String, + val status: String, + val name: String, + val image: String?, + val website: String?, + val apr: SerializedBigDecimal?, + val commission: Double?, + val stakedBalance: String?, + val votingPower: Double?, + val preferred: Boolean, + ) + + @Serializable + data class Metadata( + val name: String, + val logoUri: String, + val description: String, + val documentation: String?, + val gasFeeToken: Token, + val token: Token, + val tokens: List, + val type: String, + val rewardSchedule: String, + val cooldownPeriod: Period, + val warmupPeriod: Period, + val rewardClaiming: String, + val defaultValidator: String?, + val minimumStake: Int?, + val supportsMultipleValidators: Boolean, + val revshare: Enabled, + val fee: Enabled, + ) { + + @Serializable + data class Period( + val days: Int, + ) + + @Serializable + data class Enabled( + val enabled: Boolean, + ) + } + + enum class RewardType { + APY, // compound rate + APR, // simple rate + UNKNOWN, + } +} + +@Serializable +data class Token( + val name: String, + val network: NetworkType, + val symbol: String, + val decimals: Int, + val address: String?, + val coinGeckoId: String?, + val logoURI: String?, + val isPoints: Boolean?, +) + +@Serializable +data class AddressArgument( + val required: Boolean, + val network: String? = null, + val minimum: Double? = null, + val maximum: Double? = null, +) \ No newline at end of file diff --git a/domain/staking/models/src/main/kotlin/com/tangem/domain/staking/model/stakekit/YieldBalance.kt b/domain/staking/models/src/main/kotlin/com/tangem/domain/staking/model/stakekit/YieldBalance.kt new file mode 100644 index 0000000000..1c521e2ab3 --- /dev/null +++ b/domain/staking/models/src/main/kotlin/com/tangem/domain/staking/model/stakekit/YieldBalance.kt @@ -0,0 +1,85 @@ +package com.tangem.domain.staking.model.stakekit + +import com.tangem.domain.staking.model.stakekit.action.StakingActionType +import java.math.BigDecimal + +sealed class YieldBalance { + + data class Data( + val balance: YieldBalanceItem, + ) : YieldBalance() { + fun getTotalStakingBalance(): BigDecimal { + return balance.items + .filterNot { it.type == BalanceType.REWARDS } + .sumOf { it.amount * it.pricePerShare } + } + + fun getRewardStakingBalance(): BigDecimal { + return balance.items + .filter { it.type == BalanceType.REWARDS } + .sumOf { it.amount * it.pricePerShare } + } + } + + data object Empty : YieldBalance() + + data object Error : YieldBalance() +} + +data class YieldBalanceItem( + val items: List, + val integrationId: String?, +) + +data class BalanceItem( + val type: BalanceType, + val amount: BigDecimal, + val pricePerShare: BigDecimal, + val rawCurrencyId: String?, + val validatorAddress: String?, + val pendingActions: List, +) + +data class PendingAction( + val type: StakingActionType, + val passthrough: String, + val args: PendingActionArgs?, +) { + data class PendingActionArgs( + val amount: Amount?, + val duration: Duration?, + val validatorAddress: Boolean?, + val validatorAddresses: Boolean?, + val tronResource: TronResource?, + val signatureVerification: Boolean?, + ) { + data class Amount( + val required: Boolean, + val minimum: BigDecimal?, + val maximum: BigDecimal?, + ) + + data class Duration( + val required: Boolean, + val minimum: Int?, + val maximum: Int?, + ) + + data class TronResource( + val required: Boolean, + val options: List, + ) + } +} + +enum class BalanceType { + AVAILABLE, + STAKED, + UNSTAKING, + UNSTAKED, + PREPARING, + REWARDS, + LOCKED, + UNLOCKING, + UNKNOWN, +} \ No newline at end of file diff --git a/domain/staking/models/src/main/kotlin/com/tangem/domain/staking/model/stakekit/YieldBalanceList.kt b/domain/staking/models/src/main/kotlin/com/tangem/domain/staking/model/stakekit/YieldBalanceList.kt new file mode 100644 index 0000000000..3d3ae126da --- /dev/null +++ b/domain/staking/models/src/main/kotlin/com/tangem/domain/staking/model/stakekit/YieldBalanceList.kt @@ -0,0 +1,19 @@ +package com.tangem.domain.staking.model.stakekit + +sealed class YieldBalanceList { + + data class Data( + val balances: List, + ) : YieldBalanceList() { + fun getBalance(rawCurrencyId: String?): YieldBalance { + return balances.firstOrNull { yield -> + (yield as? YieldBalance.Data)?.balance?.items + ?.any { it.rawCurrencyId == rawCurrencyId } == true + } ?: YieldBalance.Error + } + } + + data object Empty : YieldBalanceList() + + data object Error : YieldBalanceList() +} \ No newline at end of file diff --git a/domain/staking/models/src/main/kotlin/com/tangem/domain/staking/model/stakekit/action/StakingAction.kt b/domain/staking/models/src/main/kotlin/com/tangem/domain/staking/model/stakekit/action/StakingAction.kt new file mode 100644 index 0000000000..be1545d6da --- /dev/null +++ b/domain/staking/models/src/main/kotlin/com/tangem/domain/staking/model/stakekit/action/StakingAction.kt @@ -0,0 +1,18 @@ +package com.tangem.domain.staking.model.stakekit.action + +import com.tangem.domain.staking.model.stakekit.transaction.StakingTransaction +import org.joda.time.DateTime +import java.math.BigDecimal + +data class StakingAction( + val id: String, + val integrationId: String, + val status: StakingActionStatus, + val type: StakingActionType, + val currentStepIndex: Int, + val amount: BigDecimal, + val validatorAddress: String?, + val validatorAddresses: List?, + val transactions: List?, + val createdAt: DateTime, +) \ No newline at end of file diff --git a/domain/staking/models/src/main/kotlin/com/tangem/domain/staking/model/stakekit/action/StakingActionCommonType.kt b/domain/staking/models/src/main/kotlin/com/tangem/domain/staking/model/stakekit/action/StakingActionCommonType.kt new file mode 100644 index 0000000000..1caf4b8942 --- /dev/null +++ b/domain/staking/models/src/main/kotlin/com/tangem/domain/staking/model/stakekit/action/StakingActionCommonType.kt @@ -0,0 +1,7 @@ +package com.tangem.domain.staking.model.stakekit.action + +enum class StakingActionCommonType { + ENTER, + EXIT, + PENDING, +} \ No newline at end of file diff --git a/domain/staking/models/src/main/kotlin/com/tangem/domain/staking/model/stakekit/action/StakingActionStatus.kt b/domain/staking/models/src/main/kotlin/com/tangem/domain/staking/model/stakekit/action/StakingActionStatus.kt new file mode 100644 index 0000000000..33e1750e27 --- /dev/null +++ b/domain/staking/models/src/main/kotlin/com/tangem/domain/staking/model/stakekit/action/StakingActionStatus.kt @@ -0,0 +1,11 @@ +package com.tangem.domain.staking.model.stakekit.action + +enum class StakingActionStatus { + CANCELED, + CREATED, + WAITING_FOR_NEXT, + PROCESSING, + FAILED, + SUCCESS, + UNKNOWN, +} \ No newline at end of file diff --git a/domain/staking/models/src/main/kotlin/com/tangem/domain/staking/model/stakekit/action/StakingActionType.kt b/domain/staking/models/src/main/kotlin/com/tangem/domain/staking/model/stakekit/action/StakingActionType.kt new file mode 100644 index 0000000000..5098ec0ce1 --- /dev/null +++ b/domain/staking/models/src/main/kotlin/com/tangem/domain/staking/model/stakekit/action/StakingActionType.kt @@ -0,0 +1,20 @@ +package com.tangem.domain.staking.model.stakekit.action + +enum class StakingActionType { + STAKE, + UNSTAKE, + CLAIM_REWARDS, + RESTAKE_REWARDS, + WITHDRAW, + RESTAKE, + CLAIM_UNSTAKED, + UNLOCK_LOCKED, + STAKE_LOCKED, + VOTE, + REVOKE, + VOTE_LOCKED, + REVOTE, + REBOND, + MIGRATE, + UNKNOWN, +} \ No newline at end of file diff --git a/domain/staking/models/src/main/kotlin/com/tangem/domain/staking/model/stakekit/transaction/ActionParams.kt b/domain/staking/models/src/main/kotlin/com/tangem/domain/staking/model/stakekit/transaction/ActionParams.kt new file mode 100644 index 0000000000..2adfaed13b --- /dev/null +++ b/domain/staking/models/src/main/kotlin/com/tangem/domain/staking/model/stakekit/transaction/ActionParams.kt @@ -0,0 +1,17 @@ +package com.tangem.domain.staking.model.stakekit.transaction + +import com.tangem.domain.staking.model.stakekit.Token +import com.tangem.domain.staking.model.stakekit.action.StakingActionCommonType +import com.tangem.domain.staking.model.stakekit.action.StakingActionType +import java.math.BigDecimal + +data class ActionParams( + val actionCommonType: StakingActionCommonType, + val integrationId: String, + val amount: BigDecimal, + val address: String, + val validatorAddress: String, + val token: Token, + val passthrough: String? = null, + val type: StakingActionType? = null, +) \ No newline at end of file diff --git a/domain/staking/models/src/main/kotlin/com/tangem/domain/staking/model/stakekit/transaction/StakingGasEstimate.kt b/domain/staking/models/src/main/kotlin/com/tangem/domain/staking/model/stakekit/transaction/StakingGasEstimate.kt new file mode 100644 index 0000000000..585ae1edb5 --- /dev/null +++ b/domain/staking/models/src/main/kotlin/com/tangem/domain/staking/model/stakekit/transaction/StakingGasEstimate.kt @@ -0,0 +1,10 @@ +package com.tangem.domain.staking.model.stakekit.transaction + +import com.tangem.domain.staking.model.stakekit.Token +import java.math.BigDecimal + +data class StakingGasEstimate( + val amount: BigDecimal, + val token: Token, + val gasLimit: String?, +) \ No newline at end of file diff --git a/domain/staking/models/src/main/kotlin/com/tangem/domain/staking/model/stakekit/transaction/StakingTransaction.kt b/domain/staking/models/src/main/kotlin/com/tangem/domain/staking/model/stakekit/transaction/StakingTransaction.kt new file mode 100644 index 0000000000..4222203a21 --- /dev/null +++ b/domain/staking/models/src/main/kotlin/com/tangem/domain/staking/model/stakekit/transaction/StakingTransaction.kt @@ -0,0 +1,20 @@ +package com.tangem.domain.staking.model.stakekit.transaction + +import com.tangem.domain.staking.model.stakekit.NetworkType + +data class StakingTransaction( + val id: String, + val network: NetworkType, + val status: StakingTransactionStatus, + val type: StakingTransactionType, + val hash: String?, + val signedTransaction: String?, + val unsignedTransaction: String?, + val stepIndex: Int, + val error: String?, + val gasEstimate: StakingGasEstimate?, + val stakeId: String?, + val explorerUrl: String?, + val ledgerHwAppId: String?, + val isMessage: Boolean, +) \ No newline at end of file diff --git a/domain/staking/models/src/main/kotlin/com/tangem/domain/staking/model/stakekit/transaction/StakingTransactionStatus.kt b/domain/staking/models/src/main/kotlin/com/tangem/domain/staking/model/stakekit/transaction/StakingTransactionStatus.kt new file mode 100644 index 0000000000..642276c7ca --- /dev/null +++ b/domain/staking/models/src/main/kotlin/com/tangem/domain/staking/model/stakekit/transaction/StakingTransactionStatus.kt @@ -0,0 +1,15 @@ +package com.tangem.domain.staking.model.stakekit.transaction + +enum class StakingTransactionStatus { + NOT_FOUND, + CREATED, + BLOCKED, + WAITING_FOR_SIGNATURE, + SIGNED, + BROADCASTED, + PENDING, + CONFIRMED, + FAILED, + SKIPPED, + UNKNOWN, +} \ No newline at end of file diff --git a/domain/staking/models/src/main/kotlin/com/tangem/domain/staking/model/stakekit/transaction/StakingTransactionType.kt b/domain/staking/models/src/main/kotlin/com/tangem/domain/staking/model/stakekit/transaction/StakingTransactionType.kt new file mode 100644 index 0000000000..34caa67d0f --- /dev/null +++ b/domain/staking/models/src/main/kotlin/com/tangem/domain/staking/model/stakekit/transaction/StakingTransactionType.kt @@ -0,0 +1,44 @@ +package com.tangem.domain.staking.model.stakekit.transaction + +enum class StakingTransactionType { + SWAP, + DEPOSIT, + APPROVAL, + STAKE, + CLAIM_UNSTAKED, + CLAIM_REWARDS, + RESTAKE_REWARDS, + UNSTAKE, + SPLIT, + MERGE, + LOCK, + UNLOCK, + SUPPLY, + BRIDGE, + VOTE, + REVOKE, + RESTAKE, + REBOND, + WITHDRAW, + CREATE_ACCOUNT, + REVEAL, + MIGRATE, + UTXO_P_TO_C_IMPORT, + UTXO_C_TO_P_IMPORT, + UNFREEZE_LEGACY, + UNFREEZE_LEGACY_BANDWIDTH, + UNFREEZE_LEGACY_ENERGY, + UNFREEZE_BANDWIDTH, + UNFREEZE_ENERGY, + FREEZE_BANDWIDTH, + FREEZE_ENERGY, + UNDELEGATE_BANDWIDTH, + UNDELEGATE_ENERGY, + P2P_NODE_REQUEST, + LUGANODES_PROVISION, + LUGANODES_EXIT_REQUEST, + INFSTONES_PROVISION, + INFSTONES_EXIT_REQUEST, + INFSTONES_CLAIM_REQUEST, + UNKNOWN, +} \ No newline at end of file diff --git a/domain/staking/src/main/java/com/tangem/domain/staking/EstimateGasUseCase.kt b/domain/staking/src/main/java/com/tangem/domain/staking/EstimateGasUseCase.kt new file mode 100644 index 0000000000..381308b7a7 --- /dev/null +++ b/domain/staking/src/main/java/com/tangem/domain/staking/EstimateGasUseCase.kt @@ -0,0 +1,25 @@ +package com.tangem.domain.staking + +import arrow.core.Either +import com.tangem.domain.staking.model.stakekit.StakingError +import com.tangem.domain.staking.model.stakekit.transaction.ActionParams +import com.tangem.domain.staking.model.stakekit.transaction.StakingGasEstimate +import com.tangem.domain.staking.repositories.StakingErrorResolver +import com.tangem.domain.staking.repositories.StakingRepository + +/** + * Use case for staking gas estimation. + */ +class EstimateGasUseCase( + private val stakingRepository: StakingRepository, + private val stakingErrorResolver: StakingErrorResolver, +) { + + suspend operator fun invoke(params: ActionParams): Either { + return Either.catch { + stakingRepository.estimateGas(params) + }.mapLeft { + stakingErrorResolver.resolve(it) + } + } +} \ No newline at end of file diff --git a/domain/staking/src/main/java/com/tangem/domain/staking/FetchStakingTokensUseCase.kt b/domain/staking/src/main/java/com/tangem/domain/staking/FetchStakingTokensUseCase.kt new file mode 100644 index 0000000000..c591ae2bc2 --- /dev/null +++ b/domain/staking/src/main/java/com/tangem/domain/staking/FetchStakingTokensUseCase.kt @@ -0,0 +1,25 @@ +package com.tangem.domain.staking + +import arrow.core.Either +import arrow.core.raise.catch +import arrow.core.raise.either +import com.tangem.domain.staking.model.stakekit.StakingError +import com.tangem.domain.staking.repositories.StakingErrorResolver +import com.tangem.domain.staking.repositories.StakingRepository + +/** + * Use case for getting enabled tokens + */ +class FetchStakingTokensUseCase( + private val stakingRepository: StakingRepository, + private val stakingErrorResolver: StakingErrorResolver, +) { + suspend operator fun invoke(isRefresh: Boolean = false): Either { + return either { + catch( + block = { stakingRepository.fetchEnabledYields(isRefresh) }, + catch = { stakingErrorResolver.resolve(it) }, + ) + } + } +} \ No newline at end of file diff --git a/domain/staking/src/main/java/com/tangem/domain/staking/FetchStakingYieldBalanceUseCase.kt b/domain/staking/src/main/java/com/tangem/domain/staking/FetchStakingYieldBalanceUseCase.kt new file mode 100644 index 0000000000..333762d0e1 --- /dev/null +++ b/domain/staking/src/main/java/com/tangem/domain/staking/FetchStakingYieldBalanceUseCase.kt @@ -0,0 +1,35 @@ +package com.tangem.domain.staking + +import arrow.core.Either +import arrow.core.raise.catch +import arrow.core.raise.either +import com.tangem.domain.staking.model.stakekit.StakingError +import com.tangem.domain.staking.repositories.StakingErrorResolver +import com.tangem.domain.staking.repositories.StakingRepository +import com.tangem.domain.tokens.model.CryptoCurrencyAddress +import com.tangem.domain.wallets.models.UserWalletId + +class FetchStakingYieldBalanceUseCase( + private val stakingRepository: StakingRepository, + private val stakingErrorResolver: StakingErrorResolver, +) { + + suspend operator fun invoke( + userWalletId: UserWalletId, + address: CryptoCurrencyAddress, + refresh: Boolean = false, + ): Either { + return either { + catch( + block = { + stakingRepository.fetchSingleYieldBalance( + userWalletId = userWalletId, + address = address, + refresh = refresh, + ) + }, + catch = { stakingErrorResolver.resolve(it) }, + ) + } + } +} \ No newline at end of file diff --git a/domain/staking/src/main/java/com/tangem/domain/staking/GetStakingAvailabilityUseCase.kt b/domain/staking/src/main/java/com/tangem/domain/staking/GetStakingAvailabilityUseCase.kt index 18717a31f7..46a2f010be 100644 --- a/domain/staking/src/main/java/com/tangem/domain/staking/GetStakingAvailabilityUseCase.kt +++ b/domain/staking/src/main/java/com/tangem/domain/staking/GetStakingAvailabilityUseCase.kt @@ -1,16 +1,26 @@ package com.tangem.domain.staking +import arrow.core.Either import com.tangem.domain.staking.model.StakingAvailability +import com.tangem.domain.staking.model.stakekit.StakingError +import com.tangem.domain.staking.repositories.StakingErrorResolver import com.tangem.domain.staking.repositories.StakingRepository +import com.tangem.domain.tokens.model.CryptoCurrency /** - * Use case for getting info about staking availability for certain blockchain. + * Use case for getting info about staking capability in tangem app. */ class GetStakingAvailabilityUseCase( private val stakingRepository: StakingRepository, + private val stakingErrorResolver: StakingErrorResolver, ) { - operator fun invoke(blockchainNetworkId: String): StakingAvailability { - return stakingRepository.getStakingAvailability(blockchainNetworkId) + suspend operator fun invoke( + cryptoCurrencyId: CryptoCurrency.ID, + symbol: String, + ): Either { + return Either + .catch { stakingRepository.getStakingAvailabilityForActions(cryptoCurrencyId, symbol) } + .mapLeft { stakingErrorResolver.resolve(it) } } } \ No newline at end of file diff --git a/domain/staking/src/main/java/com/tangem/domain/staking/GetStakingEntryInfoUseCase.kt b/domain/staking/src/main/java/com/tangem/domain/staking/GetStakingEntryInfoUseCase.kt index 02a505aa03..ffa3cbb0a3 100644 --- a/domain/staking/src/main/java/com/tangem/domain/staking/GetStakingEntryInfoUseCase.kt +++ b/domain/staking/src/main/java/com/tangem/domain/staking/GetStakingEntryInfoUseCase.kt @@ -2,14 +2,30 @@ package com.tangem.domain.staking import arrow.core.Either import com.tangem.domain.staking.model.StakingEntryInfo +import com.tangem.domain.staking.model.stakekit.StakingError +import com.tangem.domain.staking.repositories.StakingErrorResolver import com.tangem.domain.staking.repositories.StakingRepository +import com.tangem.domain.tokens.model.CryptoCurrency /** * Use case for getting entry info about staking on token screen. */ -class GetStakingEntryInfoUseCase(private val stakingRepository: StakingRepository) { +class GetStakingEntryInfoUseCase( + private val stakingRepository: StakingRepository, + private val stakingErrorResolver: StakingErrorResolver, +) { - suspend operator fun invoke(integrationId: String): Either { - return Either.catch { stakingRepository.getEntryInfo(integrationId) } + suspend operator fun invoke( + cryptoCurrencyId: CryptoCurrency.ID, + symbol: String, + ): Either { + return Either + .catch { + stakingRepository.getEntryInfo( + cryptoCurrencyId = cryptoCurrencyId, + symbol = symbol, + ) + } + .mapLeft { stakingErrorResolver.resolve(it) } } } \ No newline at end of file diff --git a/domain/staking/src/main/java/com/tangem/domain/staking/GetStakingTransactionUseCase.kt b/domain/staking/src/main/java/com/tangem/domain/staking/GetStakingTransactionUseCase.kt new file mode 100644 index 0000000000..02abd643a4 --- /dev/null +++ b/domain/staking/src/main/java/com/tangem/domain/staking/GetStakingTransactionUseCase.kt @@ -0,0 +1,38 @@ +package com.tangem.domain.staking + +import arrow.core.Either +import com.tangem.domain.staking.model.stakekit.StakingError +import com.tangem.domain.staking.model.stakekit.transaction.ActionParams +import com.tangem.domain.staking.model.stakekit.transaction.StakingTransaction +import com.tangem.domain.staking.repositories.StakingErrorResolver +import com.tangem.domain.staking.repositories.StakingRepository +import kotlinx.coroutines.delay + +/** + * Use case for creating enter action + */ +class GetStakingTransactionUseCase( + private val stakingRepository: StakingRepository, + private val stakingErrorResolver: StakingErrorResolver, +) { + + suspend operator fun invoke(params: ActionParams): Either { + return Either.catch { + val createAction = stakingRepository.createAction(params) + + // workaround, sometimes transaction is not created immediately after actions/enter + delay(PATCH_TRANSACTION_REQUEST_DELAY) + + val createdTransaction = createAction.transactions?.get(0) ?: error("No available transaction to patch") + val patchedTransaction = stakingRepository.constructTransaction(createdTransaction.id) + + patchedTransaction + }.mapLeft { + stakingErrorResolver.resolve(it) + } + } + + companion object { + private const val PATCH_TRANSACTION_REQUEST_DELAY = 1000L + } +} \ No newline at end of file diff --git a/domain/staking/src/main/java/com/tangem/domain/staking/GetStakingYieldBalanceUseCase.kt b/domain/staking/src/main/java/com/tangem/domain/staking/GetStakingYieldBalanceUseCase.kt new file mode 100644 index 0000000000..5c5528b931 --- /dev/null +++ b/domain/staking/src/main/java/com/tangem/domain/staking/GetStakingYieldBalanceUseCase.kt @@ -0,0 +1,31 @@ +package com.tangem.domain.staking + +import arrow.core.Either +import arrow.core.left +import arrow.core.right +import com.tangem.domain.core.utils.EitherFlow +import com.tangem.domain.staking.model.stakekit.StakingError +import com.tangem.domain.staking.model.stakekit.YieldBalance +import com.tangem.domain.staking.repositories.StakingErrorResolver +import com.tangem.domain.staking.repositories.StakingRepository +import com.tangem.domain.tokens.model.CryptoCurrencyAddress +import com.tangem.domain.wallets.models.UserWalletId +import kotlinx.coroutines.flow.catch +import kotlinx.coroutines.flow.map + +class GetStakingYieldBalanceUseCase( + private val stakingRepository: StakingRepository, + private val stakingErrorResolver: StakingErrorResolver, +) { + + operator fun invoke( + userWalletId: UserWalletId, + address: CryptoCurrencyAddress, + ): EitherFlow { + return stakingRepository.getSingleYieldBalanceFlow( + userWalletId = userWalletId, + address = address, + ).map> { it.right() } + .catch { emit(stakingErrorResolver.resolve(it).left()) } + } +} \ No newline at end of file diff --git a/domain/staking/src/main/java/com/tangem/domain/staking/GetYieldUseCase.kt b/domain/staking/src/main/java/com/tangem/domain/staking/GetYieldUseCase.kt new file mode 100644 index 0000000000..3bf59574a6 --- /dev/null +++ b/domain/staking/src/main/java/com/tangem/domain/staking/GetYieldUseCase.kt @@ -0,0 +1,23 @@ +package com.tangem.domain.staking + +import arrow.core.Either +import com.tangem.domain.staking.model.stakekit.StakingError +import com.tangem.domain.staking.model.stakekit.Yield +import com.tangem.domain.staking.repositories.StakingErrorResolver +import com.tangem.domain.staking.repositories.StakingRepository +import com.tangem.domain.tokens.model.CryptoCurrency + +/** + * Use case for getting staking yield for staking scenario start. + */ +class GetYieldUseCase( + private val stakingRepository: StakingRepository, + private val stakingErrorResolver: StakingErrorResolver, +) { + + suspend operator fun invoke(cryptoCurrencyId: CryptoCurrency.ID, symbol: String): Either { + return Either + .catch { stakingRepository.getYield(cryptoCurrencyId, symbol) } + .mapLeft { stakingErrorResolver.resolve(it) } + } +} \ No newline at end of file diff --git a/domain/staking/src/main/java/com/tangem/domain/staking/IsStakeMoreAvailableUseCase.kt b/domain/staking/src/main/java/com/tangem/domain/staking/IsStakeMoreAvailableUseCase.kt new file mode 100644 index 0000000000..4dd7fc8f38 --- /dev/null +++ b/domain/staking/src/main/java/com/tangem/domain/staking/IsStakeMoreAvailableUseCase.kt @@ -0,0 +1,19 @@ +package com.tangem.domain.staking + +import arrow.core.Either +import com.tangem.domain.staking.model.stakekit.StakingError +import com.tangem.domain.staking.repositories.StakingErrorResolver +import com.tangem.domain.staking.repositories.StakingRepository +import com.tangem.domain.tokens.model.Network + +class IsStakeMoreAvailableUseCase( + private val stakingRepository: StakingRepository, + private val stakingErrorResolver: StakingErrorResolver, +) { + + operator fun invoke(networkId: Network.ID): Either { + return Either + .catch { stakingRepository.isStakeMoreAvailable(networkId) } + .mapLeft { stakingErrorResolver.resolve(it) } + } +} \ No newline at end of file diff --git a/domain/staking/src/main/java/com/tangem/domain/staking/SaveUnsubmittedHashUseCase.kt b/domain/staking/src/main/java/com/tangem/domain/staking/SaveUnsubmittedHashUseCase.kt new file mode 100644 index 0000000000..0a83c395cb --- /dev/null +++ b/domain/staking/src/main/java/com/tangem/domain/staking/SaveUnsubmittedHashUseCase.kt @@ -0,0 +1,29 @@ +package com.tangem.domain.staking + +import arrow.core.Either +import com.tangem.domain.staking.model.stakekit.StakingError +import com.tangem.domain.staking.model.UnsubmittedTransactionMetadata +import com.tangem.domain.staking.repositories.StakingErrorResolver +import com.tangem.domain.staking.repositories.StakingRepository + +/** + * Use case for saving hash that failed to submit during staking confirmation + */ +class SaveUnsubmittedHashUseCase( + private val stakingRepository: StakingRepository, + private val stakingErrorResolver: StakingErrorResolver, +) { + + suspend operator fun invoke(transactionId: String, transactionHash: String): Either { + return Either.catch { + stakingRepository.storeUnsubmittedHash( + unsubmittedTransactionMetadata = UnsubmittedTransactionMetadata( + transactionId = transactionId, + transactionHash = transactionHash, + ), + ) + }.mapLeft { + stakingErrorResolver.resolve(it) + } + } +} \ No newline at end of file diff --git a/domain/staking/src/main/java/com/tangem/domain/staking/SendUnsubmittedHashesUseCase.kt b/domain/staking/src/main/java/com/tangem/domain/staking/SendUnsubmittedHashesUseCase.kt new file mode 100644 index 0000000000..95f3ad9eea --- /dev/null +++ b/domain/staking/src/main/java/com/tangem/domain/staking/SendUnsubmittedHashesUseCase.kt @@ -0,0 +1,21 @@ +package com.tangem.domain.staking + +import arrow.core.Either +import com.tangem.domain.staking.model.stakekit.StakingError +import com.tangem.domain.staking.repositories.StakingErrorResolver +import com.tangem.domain.staking.repositories.StakingRepository + +/** + * Use case for commiting hashes that failed to submit during staking confirmation + */ +class SendUnsubmittedHashesUseCase( + private val stakingRepository: StakingRepository, + private val stakingErrorResolver: StakingErrorResolver, +) { + + suspend operator fun invoke(): Either { + return Either + .catch { stakingRepository.sendUnsubmittedHashes() } + .mapLeft { stakingErrorResolver.resolve(it) } + } +} \ No newline at end of file diff --git a/domain/staking/src/main/java/com/tangem/domain/staking/SubmitHashUseCase.kt b/domain/staking/src/main/java/com/tangem/domain/staking/SubmitHashUseCase.kt new file mode 100644 index 0000000000..d810cfac8c --- /dev/null +++ b/domain/staking/src/main/java/com/tangem/domain/staking/SubmitHashUseCase.kt @@ -0,0 +1,27 @@ +package com.tangem.domain.staking + +import arrow.core.Either +import com.tangem.domain.staking.model.stakekit.StakingError +import com.tangem.domain.staking.repositories.StakingErrorResolver +import com.tangem.domain.staking.repositories.StakingRepository + +/** + * Use case for submitting transaction hash to stakekit + */ +class SubmitHashUseCase( + private val stakingRepository: StakingRepository, + private val stakingErrorResolver: StakingErrorResolver, +) { + + suspend fun submitHash(transactionId: String, transactionHash: String): Either { + return Either + .catch { + stakingRepository.submitHash( + transactionId = transactionId, + transactionHash = transactionHash, + ) + }.mapLeft { + stakingErrorResolver.resolve(it) + } + } +} \ No newline at end of file diff --git a/domain/staking/src/main/java/com/tangem/domain/staking/repositories/StakingErrorResolver.kt b/domain/staking/src/main/java/com/tangem/domain/staking/repositories/StakingErrorResolver.kt new file mode 100644 index 0000000000..f45ad158d8 --- /dev/null +++ b/domain/staking/src/main/java/com/tangem/domain/staking/repositories/StakingErrorResolver.kt @@ -0,0 +1,8 @@ +package com.tangem.domain.staking.repositories + +import com.tangem.domain.staking.model.stakekit.StakingError + +interface StakingErrorResolver { + + fun resolve(throwable: Throwable): StakingError +} \ No newline at end of file diff --git a/domain/staking/src/main/java/com/tangem/domain/staking/repositories/StakingRepository.kt b/domain/staking/src/main/java/com/tangem/domain/staking/repositories/StakingRepository.kt index 763377ac5e..a9ff51285e 100644 --- a/domain/staking/src/main/java/com/tangem/domain/staking/repositories/StakingRepository.kt +++ b/domain/staking/src/main/java/com/tangem/domain/staking/repositories/StakingRepository.kt @@ -1,11 +1,78 @@ package com.tangem.domain.staking.repositories -import com.tangem.domain.staking.model.StakingAvailability -import com.tangem.domain.staking.model.StakingEntryInfo +import com.tangem.domain.core.lce.LceFlow +import com.tangem.domain.staking.model.* +import com.tangem.domain.staking.model.stakekit.Yield +import com.tangem.domain.staking.model.stakekit.YieldBalance +import com.tangem.domain.staking.model.stakekit.YieldBalanceList +import com.tangem.domain.staking.model.stakekit.action.StakingAction +import com.tangem.domain.staking.model.stakekit.transaction.ActionParams +import com.tangem.domain.staking.model.stakekit.transaction.StakingGasEstimate +import com.tangem.domain.staking.model.stakekit.transaction.StakingTransaction +import com.tangem.domain.tokens.model.CryptoCurrency +import com.tangem.domain.tokens.model.CryptoCurrencyAddress +import com.tangem.domain.tokens.model.Network +import com.tangem.domain.wallets.models.UserWalletId +import kotlinx.coroutines.flow.Flow interface StakingRepository { - fun getStakingAvailability(blockchainId: String): StakingAvailability + fun isStakingSupported(currencyId: String): Boolean - suspend fun getEntryInfo(integrationId: String): StakingEntryInfo + suspend fun fetchEnabledYields(refresh: Boolean) + + suspend fun getEntryInfo(cryptoCurrencyId: CryptoCurrency.ID, symbol: String): StakingEntryInfo + + suspend fun getYield(cryptoCurrencyId: CryptoCurrency.ID, symbol: String): Yield + + suspend fun getStakingAvailabilityForActions( + cryptoCurrencyId: CryptoCurrency.ID, + symbol: String, + ): StakingAvailability + + suspend fun fetchSingleYieldBalance( + userWalletId: UserWalletId, + address: CryptoCurrencyAddress, + refresh: Boolean = false, + ) + + fun getSingleYieldBalanceFlow(userWalletId: UserWalletId, address: CryptoCurrencyAddress): Flow + + suspend fun getSingleYieldBalanceSync(userWalletId: UserWalletId, address: CryptoCurrencyAddress): YieldBalance + + suspend fun fetchMultiYieldBalance( + userWalletId: UserWalletId, + addresses: List, + refresh: Boolean = false, + ) + + fun getMultiYieldBalanceFlow( + userWalletId: UserWalletId, + addresses: List, + ): Flow + + fun getMultiYieldBalanceLce( + userWalletId: UserWalletId, + addresses: List, + ): LceFlow + + suspend fun getMultiYieldBalanceSync( + userWalletId: UserWalletId, + addresses: List, + ): YieldBalanceList + + suspend fun createAction(params: ActionParams): StakingAction + + suspend fun estimateGas(params: ActionParams): StakingGasEstimate + + suspend fun constructTransaction(transactionId: String): StakingTransaction + + suspend fun submitHash(transactionId: String, transactionHash: String) + + suspend fun storeUnsubmittedHash(unsubmittedTransactionMetadata: UnsubmittedTransactionMetadata) + + suspend fun sendUnsubmittedHashes() + + /** Returns whether additional staking is possible if there is already active staking */ + fun isStakeMoreAvailable(networkId: Network.ID): Boolean } \ No newline at end of file diff --git a/domain/tokens/build.gradle.kts b/domain/tokens/build.gradle.kts index de3ef835c5..989a7e9c5d 100644 --- a/domain/tokens/build.gradle.kts +++ b/domain/tokens/build.gradle.kts @@ -14,6 +14,7 @@ dependencies { api(projects.domain.core) implementation(projects.domain.models) implementation(projects.domain.legacy) + implementation(projects.domain.staking) implementation(projects.libs.blockchainSdk) implementation(projects.domain.tokens.models) implementation(projects.domain.txhistory.models) @@ -23,7 +24,10 @@ dependencies { implementation(projects.domain.settings) implementation(projects.features.swap.domain.api) implementation(projects.features.swap.domain.models) + + /** Project - Api */ implementation(projects.features.send.api) + implementation(projects.features.staking.api) /** Project - Other */ implementation(projects.core.utils) diff --git a/domain/tokens/models/build.gradle.kts b/domain/tokens/models/build.gradle.kts index 948bad320b..c51f155acf 100644 --- a/domain/tokens/models/build.gradle.kts +++ b/domain/tokens/models/build.gradle.kts @@ -1,7 +1,7 @@ plugins { alias(deps.plugins.android.library) alias(deps.plugins.kotlin.android) - id("kotlin-parcelize") + alias(deps.plugins.kotlin.serialization) id("configuration") } @@ -10,11 +10,20 @@ android { } dependencies { - implementation(projects.domain.txhistory.models) + /** Project - Core */ implementation(projects.core.analytics.models) + + /** Project - Domain */ + implementation(projects.domain.txhistory.models) + implementation(projects.domain.staking.models) + + /** SDK dependencies */ implementation(deps.tangem.blockchain) { exclude(module = "joda-time") } + + /** Other dependencies */ + implementation(deps.kotlin.serialization) implementation(deps.jodatime) implementation(deps.timber) } \ No newline at end of file diff --git a/domain/tokens/models/src/main/java/com/tangem/domain/tokens/model/CryptoCurrency.kt b/domain/tokens/models/src/main/java/com/tangem/domain/tokens/model/CryptoCurrency.kt index db909d08f3..a0468f3100 100644 --- a/domain/tokens/models/src/main/java/com/tangem/domain/tokens/model/CryptoCurrency.kt +++ b/domain/tokens/models/src/main/java/com/tangem/domain/tokens/model/CryptoCurrency.kt @@ -1,7 +1,6 @@ package com.tangem.domain.tokens.model -import android.os.Parcelable -import kotlinx.parcelize.Parcelize +import kotlinx.serialization.Serializable /** * Represents a generic cryptocurrency. @@ -14,8 +13,8 @@ import kotlinx.parcelize.Parcelize * @property iconUrl Optional URL of the cryptocurrency icon. `null` if not found. * @property isCustom Indicates whether the currency is a custom user-added currency or not. */ -@Parcelize -sealed class CryptoCurrency : Parcelable { +@Serializable +sealed class CryptoCurrency { abstract val id: ID abstract val network: Network @@ -28,6 +27,7 @@ sealed class CryptoCurrency : Parcelable { /** * Represents a native coin in the blockchain network. */ + @Serializable data class Coin( override val id: ID, override val network: Network, @@ -48,6 +48,7 @@ sealed class CryptoCurrency : Parcelable { * * @property contractAddress Address of the contract managing the token. */ + @Serializable data class Token( override val id: ID, override val network: Network, @@ -75,12 +76,12 @@ sealed class CryptoCurrency : Parcelable { * @property rawCurrencyId Represents not unique currency ID from the blockchain network. `null` if * its ID of the custom token. */ - @Parcelize + @Serializable data class ID( private val prefix: Prefix, private val body: Body, private val suffix: Suffix, - ) : Parcelable { + ) { val value: String get() = buildString { @@ -121,12 +122,13 @@ sealed class CryptoCurrency : Parcelable { * * The body can be either a raw network ID or a raw network ID with a network derivation path. */ - @Parcelize - sealed class Body : Parcelable { + @Serializable + sealed class Body { /** The value of the body. */ abstract val value: String + @Serializable /** Represents a raw network ID. */ data class NetworkId(val rawId: String) : Body() { override val value: String get() = rawId @@ -137,6 +139,7 @@ sealed class CryptoCurrency : Parcelable { * * Should be used for a cryptocurrencies with custom derivation path. * */ + @Serializable data class NetworkIdWithDerivationPath( val rawId: String, val derivationPath: String, @@ -155,13 +158,14 @@ sealed class CryptoCurrency : Parcelable { * * The suffix can either be a raw ID or a contract address. */ - @Parcelize - sealed class Suffix : Parcelable { + @Serializable + sealed class Suffix { /** The value of the suffix, which could be either a raw ID or a contract address. */ abstract val value: String /** Represents a raw ID suffix. */ + @Serializable data class RawID(val rawId: String, val contractAddress: String? = null) : Suffix() { override val value: String get() = buildString { @@ -174,6 +178,7 @@ sealed class CryptoCurrency : Parcelable { } /** Represents a contract address suffix. */ + @Serializable data class ContractAddress(val contractAddress: String) : Suffix() { override val value: String get() = contractAddress } @@ -183,11 +188,11 @@ sealed class CryptoCurrency : Parcelable { return "ID(value='$value')" } - private companion object { + companion object { // should use delimiters that could be used in URL not like path or query delimiters - const val PREFIX_DELIMITER = '_' - const val SUFFIX_DELIMITER = ';' - const val DERIVATION_PATH_DELIMITER = 'd' + private const val PREFIX_DELIMITER = '_' + private const val SUFFIX_DELIMITER = ';' + private const val DERIVATION_PATH_DELIMITER = 'd' } } diff --git a/domain/tokens/models/src/main/java/com/tangem/domain/tokens/model/CryptoCurrencyStatus.kt b/domain/tokens/models/src/main/java/com/tangem/domain/tokens/model/CryptoCurrencyStatus.kt index 6b098d5be3..d6db9ae7e0 100644 --- a/domain/tokens/models/src/main/java/com/tangem/domain/tokens/model/CryptoCurrencyStatus.kt +++ b/domain/tokens/models/src/main/java/com/tangem/domain/tokens/model/CryptoCurrencyStatus.kt @@ -1,5 +1,6 @@ package com.tangem.domain.tokens.model +import com.tangem.domain.staking.model.stakekit.YieldBalance import com.tangem.domain.txhistory.models.TxHistoryItem import java.math.BigDecimal @@ -45,6 +46,9 @@ data class CryptoCurrencyStatus( /** The network address */ open val networkAddress: NetworkAddress? = null + + /** Staking yield balance */ + open val yieldBalance: YieldBalance? = null } /** Represents the Loading state of a cryptocurrency, typically while fetching its details. */ @@ -107,6 +111,7 @@ data class CryptoCurrencyStatus( override val fiatAmount: BigDecimal, override val fiatRate: BigDecimal, override val priceChange: BigDecimal, + override val yieldBalance: YieldBalance?, override val hasCurrentNetworkTransactions: Boolean, override val pendingTransactions: Set, override val networkAddress: NetworkAddress, @@ -128,6 +133,7 @@ data class CryptoCurrencyStatus( override val fiatAmount: BigDecimal?, override val fiatRate: BigDecimal?, override val priceChange: BigDecimal?, + override val yieldBalance: YieldBalance?, override val hasCurrentNetworkTransactions: Boolean, override val pendingTransactions: Set, override val networkAddress: NetworkAddress, @@ -143,6 +149,7 @@ data class CryptoCurrencyStatus( */ data class NoQuote( override val amount: BigDecimal, + override val yieldBalance: YieldBalance?, override val hasCurrentNetworkTransactions: Boolean, override val pendingTransactions: Set, override val networkAddress: NetworkAddress, diff --git a/domain/tokens/models/src/main/java/com/tangem/domain/tokens/model/Network.kt b/domain/tokens/models/src/main/java/com/tangem/domain/tokens/model/Network.kt index 5dcdb275ef..59d8d3a517 100644 --- a/domain/tokens/models/src/main/java/com/tangem/domain/tokens/model/Network.kt +++ b/domain/tokens/models/src/main/java/com/tangem/domain/tokens/model/Network.kt @@ -1,7 +1,6 @@ package com.tangem.domain.tokens.model -import android.os.Parcelable -import kotlinx.parcelize.Parcelize +import kotlinx.serialization.Serializable /** * Represents a blockchain network, identified by a unique ID, a human-readable name, and its standard type. @@ -20,7 +19,7 @@ import kotlinx.parcelize.Parcelize * that cannot be represented in a fiat currency. * (For those blockchains that have FeeResource instead of a standard type of fee) */ -@Parcelize +@Serializable data class Network( val id: ID, val backendId: String, @@ -30,7 +29,7 @@ data class Network( val isTestnet: Boolean, val standardType: StandardType, val hasFiatFeeRate: Boolean, -) : Parcelable { +) { init { require(name.isNotBlank()) { "Network name must not be blank" } @@ -42,8 +41,8 @@ data class Network( * @property value The string representation of the network ID. */ @JvmInline - @Parcelize - value class ID(val value: String) : Parcelable { + @Serializable + value class ID(val value: String) { init { require(value.isNotBlank()) { "Network ID must not be blank" } @@ -56,8 +55,8 @@ data class Network( * This class represents such paths in a generic manner, allowing for predefined card-based paths, * custom paths, or even no derivation path at all. */ - @Parcelize - sealed class DerivationPath : Parcelable { + @Serializable + sealed class DerivationPath { /** The actual derivation path value, if any. */ abstract val value: String? @@ -67,6 +66,7 @@ data class Network( * * @property value The derivation path string. */ + @Serializable data class Card(override val value: String) : DerivationPath() /** @@ -74,12 +74,14 @@ data class Network( * * @property value The derivation path string. */ + @Serializable data class Custom(override val value: String) : DerivationPath() /** * Represents a lack of derivation path. */ - object None : DerivationPath() { + @Serializable + data object None : DerivationPath() { override val value: String? get() = null } } @@ -93,31 +95,36 @@ data class Network( * * @property name The human-readable name of the standard type. */ - @Parcelize - sealed class StandardType : Parcelable { + @Serializable + sealed class StandardType { abstract val name: String /** Represents the ERC20 token standard, common on the Ethereum network. */ - object ERC20 : StandardType() { + @Serializable + data object ERC20 : StandardType() { override val name: String get() = "ERC20" } /** Represents the TRC20 token standard, common on the TRON network. */ - object TRC20 : StandardType() { + @Serializable + data object TRC20 : StandardType() { override val name: String get() = "TRC20" } /** Represents the BEP20 token standard, common on the Binance Smart Chain network. */ - object BEP20 : StandardType() { + @Serializable + data object BEP20 : StandardType() { override val name: String get() = "BEP20" } /** Represents the BEP2 token standard, common on the Binance Chain network. */ - object BEP2 : StandardType() { + @Serializable + data object BEP2 : StandardType() { override val name: String get() = "BEP2" } /** Represents a network that does not adhere to a predefined standard type. */ + @Serializable data class Unspecified(override val name: String) : StandardType() } } \ No newline at end of file diff --git a/domain/tokens/models/src/main/java/com/tangem/domain/tokens/model/Quote.kt b/domain/tokens/models/src/main/java/com/tangem/domain/tokens/model/Quote.kt index 9f5dfbe387..3db9280b76 100644 --- a/domain/tokens/models/src/main/java/com/tangem/domain/tokens/model/Quote.kt +++ b/domain/tokens/models/src/main/java/com/tangem/domain/tokens/model/Quote.kt @@ -8,12 +8,9 @@ import java.math.BigDecimal * @property rawCurrencyId The unique identifier of the cryptocurrency for which the financial information is provided. * @property fiatRate The current fiat exchange rate for the cryptocurrency. * @property priceChange The price change for the cryptocurrency. - * @property values The values representing the cryptocurrency's price changes over a 24-hour period, - * suitable for chart plotting. */ data class Quote( val rawCurrencyId: String, val fiatRate: BigDecimal, val priceChange: BigDecimal, - val values: List? = null, ) \ No newline at end of file diff --git a/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/FetchCardTokenListUseCase.kt b/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/FetchCardTokenListUseCase.kt index 7448714472..ca9266b2d1 100644 --- a/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/FetchCardTokenListUseCase.kt +++ b/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/FetchCardTokenListUseCase.kt @@ -4,6 +4,7 @@ import arrow.core.Either import arrow.core.raise.Raise import arrow.core.raise.catch import arrow.core.raise.either +import com.tangem.domain.staking.repositories.StakingRepository import com.tangem.domain.tokens.error.TokenListError import com.tangem.domain.tokens.model.CryptoCurrency import com.tangem.domain.tokens.model.Network @@ -19,6 +20,7 @@ class FetchCardTokenListUseCase( private val currenciesRepository: CurrenciesRepository, private val networksRepository: NetworksRepository, private val quotesRepository: QuotesRepository, + private val stakingRepository: StakingRepository, ) { suspend operator fun invoke(userWalletId: UserWalletId, refresh: Boolean = false): Either { @@ -39,8 +41,13 @@ class FetchCardTokenListUseCase( refresh = refresh, ) } - - awaitAll(fetchStatuses, fetchQuotes) + val yieldBalances = async { + fetchYieldBalances( + userWalletId = userWalletId, + refresh = refresh, + ) + } + awaitAll(fetchStatuses, fetchQuotes, yieldBalances) } } } @@ -69,4 +76,12 @@ class FetchCardTokenListUseCase( catch = { /* Ignore error */ }, ) } + + private suspend fun fetchYieldBalances(userWalletId: UserWalletId, refresh: Boolean) { + val networkAddresses = networksRepository.getNetworkAddresses(userWalletId) + catch( + block = { stakingRepository.fetchMultiYieldBalance(userWalletId, networkAddresses, refresh) }, + catch = { /* Ignore error */ }, + ) + } } \ No newline at end of file diff --git a/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/GetCardTokensListUseCase.kt b/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/GetCardTokensListUseCase.kt index 31b6ccc631..698c3be4f5 100644 --- a/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/GetCardTokensListUseCase.kt +++ b/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/GetCardTokensListUseCase.kt @@ -2,6 +2,7 @@ package com.tangem.domain.tokens import arrow.core.left import com.tangem.domain.core.utils.EitherFlow +import com.tangem.domain.staking.repositories.StakingRepository import com.tangem.domain.tokens.error.TokenListError import com.tangem.domain.tokens.error.mapper.mapToTokenListError import com.tangem.domain.tokens.model.CryptoCurrencyStatus @@ -21,6 +22,7 @@ class GetCardTokensListUseCase( private val currenciesRepository: CurrenciesRepository, private val quotesRepository: QuotesRepository, private val networksRepository: NetworksRepository, + private val stakingRepository: StakingRepository, ) { @OptIn(ExperimentalCoroutinesApi::class) @@ -43,6 +45,7 @@ class GetCardTokensListUseCase( currenciesRepository = currenciesRepository, quotesRepository = quotesRepository, networksRepository = networksRepository, + stakingRepository = stakingRepository, ) return operations.getCardCurrenciesStatusesFlow() diff --git a/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/GetCryptoCurrencyActionsUseCase.kt b/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/GetCryptoCurrencyActionsUseCase.kt index e521d035af..c83af879ba 100644 --- a/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/GetCryptoCurrencyActionsUseCase.kt +++ b/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/GetCryptoCurrencyActionsUseCase.kt @@ -2,6 +2,8 @@ package com.tangem.domain.tokens import com.tangem.domain.common.util.cardTypesResolver import com.tangem.domain.exchange.RampStateManager +import com.tangem.domain.staking.model.StakingAvailability +import com.tangem.domain.staking.repositories.StakingRepository import com.tangem.domain.tokens.model.* import com.tangem.domain.tokens.operations.CurrenciesStatusesOperations import com.tangem.domain.tokens.repository.CurrenciesRepository @@ -10,6 +12,7 @@ import com.tangem.domain.tokens.repository.NetworksRepository import com.tangem.domain.tokens.repository.QuotesRepository import com.tangem.domain.walletmanager.WalletManagersFacade import com.tangem.domain.wallets.models.UserWallet +import com.tangem.features.staking.api.featuretoggles.StakingFeatureToggles import com.tangem.utils.coroutines.CoroutineDispatcherProvider import com.tangem.utils.isNullOrZero import kotlinx.coroutines.ExperimentalCoroutinesApi @@ -28,6 +31,8 @@ class GetCryptoCurrencyActionsUseCase( private val currenciesRepository: CurrenciesRepository, private val quotesRepository: QuotesRepository, private val networksRepository: NetworksRepository, + private val stakingRepository: StakingRepository, + private val stakingFeatureToggles: StakingFeatureToggles, private val dispatchers: CoroutineDispatcherProvider, ) { @@ -40,6 +45,7 @@ class GetCryptoCurrencyActionsUseCase( currenciesRepository = currenciesRepository, quotesRepository = quotesRepository, networksRepository = networksRepository, + stakingRepository = stakingRepository, userWalletId = userWallet.walletId, ) val networkId = cryptoCurrencyStatus.currency.network.id @@ -100,7 +106,7 @@ class GetCryptoCurrencyActionsUseCase( return listOf(TokenActionsState.ActionState.HideToken(ScenarioUnavailabilityReason.None)) } if (cryptoCurrencyStatus.value is CryptoCurrencyStatus.Unreachable) { - return getActionsForUnreachableCurrency(cryptoCurrencyStatus, needAssociateAsset) + return getActionsForUnreachableCurrency(userWallet, cryptoCurrencyStatus, needAssociateAsset) } val activeList = mutableListOf() @@ -121,6 +127,19 @@ class GetCryptoCurrencyActionsUseCase( activeList.add(TokenActionsState.ActionState.Receive(scenario)) } + // staking + if (stakingFeatureToggles.isStakingEnabled) { + if (isStakingAvailable(cryptoCurrency)) { + activeList.add(TokenActionsState.ActionState.Stake(ScenarioUnavailabilityReason.None)) + } else { + disabledList.add( + TokenActionsState.ActionState.Stake( + unavailabilityReason = ScenarioUnavailabilityReason.StakingUnavailable(cryptoCurrency.name), + ), + ) + } + } + // send val sendUnavailabilityReason = getSendUnavailabilityReason( cryptoCurrencyStatus = cryptoCurrencyStatus, @@ -149,7 +168,7 @@ class GetCryptoCurrencyActionsUseCase( } // buy - if (rampManager.availableForBuy(cryptoCurrency)) { + if (rampManager.availableForBuy(userWallet.scanResponse, cryptoCurrency)) { activeList.add(TokenActionsState.ActionState.Buy(ScenarioUnavailabilityReason.None)) } else { disabledList.add( @@ -203,6 +222,7 @@ class GetCryptoCurrencyActionsUseCase( } private fun getActionsForUnreachableCurrency( + userWallet: UserWallet, cryptoCurrencyStatus: CryptoCurrencyStatus, needAssociateAsset: Boolean, ): List { @@ -211,7 +231,7 @@ class GetCryptoCurrencyActionsUseCase( if (isAddressAvailable(cryptoCurrencyStatus.value.networkAddress)) { actionsList.add(TokenActionsState.ActionState.CopyAddress(ScenarioUnavailabilityReason.None)) } - if (rampManager.availableForBuy(cryptoCurrencyStatus.currency)) { + if (rampManager.availableForBuy(userWallet.scanResponse, cryptoCurrencyStatus.currency)) { actionsList.add(TokenActionsState.ActionState.Buy(ScenarioUnavailabilityReason.None)) } else { actionsList.add( @@ -225,7 +245,6 @@ class GetCryptoCurrencyActionsUseCase( actionsList.add(TokenActionsState.ActionState.Send(ScenarioUnavailabilityReason.Unreachable)) actionsList.add(TokenActionsState.ActionState.Swap(ScenarioUnavailabilityReason.Unreachable)) actionsList.add(TokenActionsState.ActionState.Sell(ScenarioUnavailabilityReason.Unreachable)) - if (isAddressAvailable(cryptoCurrencyStatus.value.networkAddress)) { val scenario = if (needAssociateAsset) { ScenarioUnavailabilityReason.UnassociatedAsset @@ -234,7 +253,11 @@ class GetCryptoCurrencyActionsUseCase( } actionsList.add(TokenActionsState.ActionState.Receive(scenario)) } + if (stakingFeatureToggles.isStakingEnabled) { + actionsList.add(TokenActionsState.ActionState.Stake(ScenarioUnavailabilityReason.Unreachable)) + } actionsList.add(TokenActionsState.ActionState.HideToken(ScenarioUnavailabilityReason.None)) + return actionsList } @@ -246,7 +269,7 @@ class GetCryptoCurrencyActionsUseCase( cryptoCurrencyStatus.value.amount.isNullOrZero() -> { ScenarioUnavailabilityReason.EmptyBalance(ScenarioUnavailabilityReason.WithdrawalScenario.SEND) } - currenciesRepository.hasPendingTransactions( + currenciesRepository.isSendBlockedByPendingTransactions( cryptoCurrencyStatus = cryptoCurrencyStatus, coinStatus = coinStatus, ) -> { @@ -264,4 +287,11 @@ class GetCryptoCurrencyActionsUseCase( private fun isAddressAvailable(networkAddress: NetworkAddress?): Boolean { return networkAddress != null && networkAddress.defaultAddress.value.isNotEmpty() } + + private suspend fun isStakingAvailable(cryptoCurrency: CryptoCurrency): Boolean { + return stakingRepository.getStakingAvailabilityForActions( + cryptoCurrencyId = cryptoCurrency.id, + symbol = cryptoCurrency.symbol, + ) is StakingAvailability.Available + } } \ No newline at end of file diff --git a/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/GetCryptoCurrencyStatusSyncUseCase.kt b/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/GetCryptoCurrencyStatusSyncUseCase.kt index 8150cfc734..9c87e00297 100644 --- a/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/GetCryptoCurrencyStatusSyncUseCase.kt +++ b/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/GetCryptoCurrencyStatusSyncUseCase.kt @@ -1,6 +1,7 @@ package com.tangem.domain.tokens import arrow.core.Either +import com.tangem.domain.staking.repositories.StakingRepository import com.tangem.domain.tokens.error.CurrencyStatusError import com.tangem.domain.tokens.error.mapper.mapToCurrencyError import com.tangem.domain.tokens.model.CryptoCurrency @@ -16,6 +17,7 @@ class GetCryptoCurrencyStatusSyncUseCase( internal val currenciesRepository: CurrenciesRepository, internal val quotesRepository: QuotesRepository, internal val networksRepository: NetworksRepository, + internal val stakingRepository: StakingRepository, internal val dispatchers: CoroutineDispatcherProvider, ) { @@ -29,6 +31,7 @@ class GetCryptoCurrencyStatusSyncUseCase( currenciesRepository = currenciesRepository, quotesRepository = quotesRepository, networksRepository = networksRepository, + stakingRepository = stakingRepository, ) return operations.getCurrencyStatusSync(cryptoCurrencyId, isSingleWalletWithTokens) @@ -41,6 +44,7 @@ class GetCryptoCurrencyStatusSyncUseCase( currenciesRepository = currenciesRepository, quotesRepository = quotesRepository, networksRepository = networksRepository, + stakingRepository = stakingRepository, ) return operations.getPrimaryCurrencyStatusSync() diff --git a/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/GetCryptoCurrencyStatusesSyncUseCase.kt b/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/GetCryptoCurrencyStatusesSyncUseCase.kt index cdf58b3080..4c3e6b1b71 100644 --- a/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/GetCryptoCurrencyStatusesSyncUseCase.kt +++ b/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/GetCryptoCurrencyStatusesSyncUseCase.kt @@ -1,6 +1,7 @@ package com.tangem.domain.tokens import arrow.core.Either +import com.tangem.domain.staking.repositories.StakingRepository import com.tangem.domain.tokens.error.TokenListError import com.tangem.domain.tokens.error.mapper.mapToTokenListError import com.tangem.domain.tokens.model.CryptoCurrencyStatus @@ -15,6 +16,7 @@ class GetCryptoCurrencyStatusesSyncUseCase( internal val currenciesRepository: CurrenciesRepository, internal val quotesRepository: QuotesRepository, internal val networksRepository: NetworksRepository, + internal val stakingRepository: StakingRepository, internal val dispatchers: CoroutineDispatcherProvider, ) { @@ -24,6 +26,7 @@ class GetCryptoCurrencyStatusesSyncUseCase( currenciesRepository = currenciesRepository, quotesRepository = quotesRepository, networksRepository = networksRepository, + stakingRepository = stakingRepository, ) return operations.getCurrenciesStatusesSync() diff --git a/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/GetCurrencyStatusUpdatesUseCase.kt b/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/GetCurrencyStatusUpdatesUseCase.kt index 92e660af07..dceb8551cf 100644 --- a/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/GetCurrencyStatusUpdatesUseCase.kt +++ b/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/GetCurrencyStatusUpdatesUseCase.kt @@ -1,6 +1,7 @@ package com.tangem.domain.tokens import arrow.core.Either +import com.tangem.domain.staking.repositories.StakingRepository import com.tangem.domain.tokens.error.CurrencyStatusError import com.tangem.domain.tokens.error.mapper.mapToCurrencyError import com.tangem.domain.tokens.model.CryptoCurrency @@ -24,6 +25,7 @@ class GetCurrencyStatusUpdatesUseCase( private val currenciesRepository: CurrenciesRepository, private val quotesRepository: QuotesRepository, private val networksRepository: NetworksRepository, + private val stakingRepository: StakingRepository, private val dispatchers: CoroutineDispatcherProvider, ) { @@ -60,6 +62,7 @@ class GetCurrencyStatusUpdatesUseCase( currenciesRepository = currenciesRepository, quotesRepository = quotesRepository, networksRepository = networksRepository, + stakingRepository = stakingRepository, userWalletId = userWalletId, ) diff --git a/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/GetCurrencyWarningsUseCase.kt b/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/GetCurrencyWarningsUseCase.kt index 93ff397011..29592489a4 100644 --- a/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/GetCurrencyWarningsUseCase.kt +++ b/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/GetCurrencyWarningsUseCase.kt @@ -1,6 +1,7 @@ package com.tangem.domain.tokens import com.tangem.domain.settings.ShouldShowSwapPromoTokenUseCase +import com.tangem.domain.staking.repositories.StakingRepository import com.tangem.domain.tokens.model.* import com.tangem.domain.tokens.model.warnings.CryptoCurrencyWarning import com.tangem.domain.tokens.model.warnings.HederaWarnings @@ -26,6 +27,7 @@ class GetCurrencyWarningsUseCase( private val networksRepository: NetworksRepository, private val swapRepository: SwapRepository, private val marketCryptoCurrencyRepository: MarketCryptoCurrencyRepository, + private val stakingRepository: StakingRepository, private val promoRepository: PromoRepository, private val showSwapPromoTokenUseCase: ShouldShowSwapPromoTokenUseCase, private val dispatchers: CoroutineDispatcherProvider, @@ -43,6 +45,7 @@ class GetCurrencyWarningsUseCase( currenciesRepository = currenciesRepository, quotesRepository = quotesRepository, networksRepository = networksRepository, + stakingRepository = stakingRepository, userWalletId = userWalletId, ) return combine( diff --git a/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/GetFeePaidCryptoCurrencyStatusSyncUseCase.kt b/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/GetFeePaidCryptoCurrencyStatusSyncUseCase.kt index d38fa6a951..473b7c10b9 100644 --- a/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/GetFeePaidCryptoCurrencyStatusSyncUseCase.kt +++ b/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/GetFeePaidCryptoCurrencyStatusSyncUseCase.kt @@ -2,6 +2,7 @@ package com.tangem.domain.tokens import arrow.core.Either import arrow.core.raise.either +import com.tangem.domain.staking.repositories.StakingRepository import com.tangem.domain.tokens.error.TokenListError import com.tangem.domain.tokens.model.CryptoCurrencyStatus import com.tangem.domain.tokens.model.FeePaidCurrency @@ -16,6 +17,7 @@ class GetFeePaidCryptoCurrencyStatusSyncUseCase( internal val currenciesRepository: CurrenciesRepository, internal val quotesRepository: QuotesRepository, internal val networksRepository: NetworksRepository, + internal val stakingRepository: StakingRepository, internal val dispatchers: CoroutineDispatcherProvider, ) { @@ -30,6 +32,7 @@ class GetFeePaidCryptoCurrencyStatusSyncUseCase( currenciesRepository = currenciesRepository, quotesRepository = quotesRepository, networksRepository = networksRepository, + stakingRepository = stakingRepository, ) return either { diff --git a/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/GetNetworkCoinStatusUseCase.kt b/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/GetNetworkCoinStatusUseCase.kt index 8b03aef79d..bd77e54e3b 100644 --- a/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/GetNetworkCoinStatusUseCase.kt +++ b/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/GetNetworkCoinStatusUseCase.kt @@ -1,6 +1,7 @@ package com.tangem.domain.tokens import arrow.core.Either +import com.tangem.domain.staking.repositories.StakingRepository import com.tangem.domain.tokens.error.CurrencyStatusError import com.tangem.domain.tokens.error.mapper.mapToCurrencyError import com.tangem.domain.tokens.model.CryptoCurrencyStatus @@ -17,6 +18,7 @@ class GetNetworkCoinStatusUseCase( private val currenciesRepository: CurrenciesRepository, private val quotesRepository: QuotesRepository, private val networksRepository: NetworksRepository, + private val stakingRepository: StakingRepository, private val dispatchers: CoroutineDispatcherProvider, ) { @@ -49,6 +51,7 @@ class GetNetworkCoinStatusUseCase( currenciesRepository = currenciesRepository, quotesRepository = quotesRepository, networksRepository = networksRepository, + stakingRepository = stakingRepository, userWalletId = userWalletId, ) val maybeCurrency = if (isSingleWalletWithTokens) { @@ -69,6 +72,7 @@ class GetNetworkCoinStatusUseCase( currenciesRepository = currenciesRepository, quotesRepository = quotesRepository, networksRepository = networksRepository, + stakingRepository = stakingRepository, userWalletId = userWalletId, ) val networkFlow = if (isSingleWalletWithTokens) { diff --git a/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/GetPrimaryCurrencyStatusUpdatesUseCase.kt b/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/GetPrimaryCurrencyStatusUpdatesUseCase.kt index f1216be10f..fdc6dfaf8a 100644 --- a/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/GetPrimaryCurrencyStatusUpdatesUseCase.kt +++ b/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/GetPrimaryCurrencyStatusUpdatesUseCase.kt @@ -1,6 +1,7 @@ package com.tangem.domain.tokens import arrow.core.Either +import com.tangem.domain.staking.repositories.StakingRepository import com.tangem.domain.tokens.error.CurrencyStatusError import com.tangem.domain.tokens.error.mapper.mapToCurrencyError import com.tangem.domain.tokens.model.CryptoCurrencyStatus @@ -24,6 +25,7 @@ class GetPrimaryCurrencyStatusUpdatesUseCase( private val currenciesRepository: CurrenciesRepository, private val quotesRepository: QuotesRepository, private val networksRepository: NetworksRepository, + private val stakingRepository: StakingRepository, private val dispatchers: CoroutineDispatcherProvider, ) { @@ -46,6 +48,7 @@ class GetPrimaryCurrencyStatusUpdatesUseCase( currenciesRepository = currenciesRepository, quotesRepository = quotesRepository, networksRepository = networksRepository, + stakingRepository = stakingRepository, userWalletId = userWalletId, ) diff --git a/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/GetTokenListUseCase.kt b/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/GetTokenListUseCase.kt index afb4450d1c..9cd14a845c 100644 --- a/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/GetTokenListUseCase.kt +++ b/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/GetTokenListUseCase.kt @@ -1,17 +1,15 @@ package com.tangem.domain.tokens -import arrow.core.left import com.tangem.domain.core.lce.LceFlow -import com.tangem.domain.core.utils.EitherFlow import com.tangem.domain.core.utils.lceError import com.tangem.domain.core.utils.lceLoading import com.tangem.domain.core.utils.toLce +import com.tangem.domain.staking.repositories.StakingRepository import com.tangem.domain.tokens.error.TokenListError import com.tangem.domain.tokens.error.mapper.mapToTokenListError import com.tangem.domain.tokens.model.CryptoCurrencyStatus import com.tangem.domain.tokens.model.TokenList import com.tangem.domain.tokens.operations.CurrenciesStatusesLceOperations -import com.tangem.domain.tokens.operations.CurrenciesStatusesOperations import com.tangem.domain.tokens.operations.TokenListOperations import com.tangem.domain.tokens.repository.CurrenciesRepository import com.tangem.domain.tokens.repository.NetworksRepository @@ -26,35 +24,16 @@ class GetTokenListUseCase( private val currenciesRepository: CurrenciesRepository, private val quotesRepository: QuotesRepository, private val networksRepository: NetworksRepository, + private val stakingRepository: StakingRepository, ) { @OptIn(ExperimentalCoroutinesApi::class) - fun launch(userWalletId: UserWalletId): EitherFlow { - val operations = CurrenciesStatusesOperations( - userWalletId = userWalletId, - currenciesRepository = currenciesRepository, - quotesRepository = quotesRepository, - networksRepository = networksRepository, - ) - - return operations.getCurrenciesStatusesFlow().transformLatest { maybeTokens -> - maybeTokens.fold( - ifLeft = { error -> - emit(error.mapToTokenListError().left()) - }, - ifRight = { tokens -> - emitAll(createTokenList(userWalletId, tokens)) - }, - ) - } - } - - @OptIn(ExperimentalCoroutinesApi::class) - fun launchLce(userWalletId: UserWalletId): LceFlow { + fun launch(userWalletId: UserWalletId): LceFlow { val operations = CurrenciesStatusesLceOperations( currenciesRepository = currenciesRepository, quotesRepository = quotesRepository, networksRepository = networksRepository, + stakingRepository = stakingRepository, ) return operations.getCurrenciesStatuses(userWalletId).transformLatest { maybeCurrencies -> @@ -74,21 +53,6 @@ class GetTokenListUseCase( } } - private fun createTokenList( - userWalletId: UserWalletId, - tokens: List, - ): EitherFlow { - val operations = TokenListOperations( - userWalletId = userWalletId, - tokens = tokens, - currenciesRepository = currenciesRepository, - ) - - return operations.getTokenListFlow().map { maybeTokenList -> - maybeTokenList.mapLeft(TokenListOperations.Error::mapToTokenListError) - } - } - private fun createTokenListLce( userWalletId: UserWalletId, currencies: List, diff --git a/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/GetWalletTotalBalanceUseCase.kt b/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/GetWalletTotalBalanceUseCase.kt index 36da5cae5c..0f4d3477da 100644 --- a/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/GetWalletTotalBalanceUseCase.kt +++ b/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/GetWalletTotalBalanceUseCase.kt @@ -1,11 +1,13 @@ package com.tangem.domain.tokens +import arrow.atomic.update import arrow.core.raise.ensureNotNull import arrow.core.toNonEmptyListOrNull import com.tangem.domain.core.lce.Lce import com.tangem.domain.core.lce.LceFlow import com.tangem.domain.core.lce.lce import com.tangem.domain.core.utils.lceLoading +import com.tangem.domain.staking.repositories.StakingRepository import com.tangem.domain.tokens.error.TokenListError import com.tangem.domain.tokens.model.CryptoCurrencyStatus import com.tangem.domain.tokens.model.TotalFiatBalance @@ -15,20 +17,22 @@ import com.tangem.domain.tokens.repository.CurrenciesRepository import com.tangem.domain.tokens.repository.NetworksRepository import com.tangem.domain.tokens.repository.QuotesRepository import com.tangem.domain.wallets.models.UserWalletId +import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.flow.combine import kotlinx.coroutines.flow.map -import kotlinx.coroutines.flow.transform +import kotlinx.coroutines.flow.transformLatest class GetWalletTotalBalanceUseCase( private val currenciesRepository: CurrenciesRepository, private val quotesRepository: QuotesRepository, private val networksRepository: NetworksRepository, + private val stakingRepository: StakingRepository, ) { suspend operator fun invoke( - userWallestIds: Collection, + userTallestIds: Collection, ): LceFlow> { - val flows = userWallestIds.distinct() + val flows = userTallestIds.distinct() .map { userWalletId -> invoke(userWalletId).map { maybeBalance -> userWalletId to maybeBalance @@ -37,17 +41,23 @@ class GetWalletTotalBalanceUseCase( return combine(flows) { balances -> lce { - balances.associate { (userWalletId, maybeBalance) -> - userWalletId to maybeBalance.bind() + balances.fold(mutableMapOf()) { acc, (userWalletId, maybeBalance) -> + val balance = maybeBalance.bindOrNull() ?: TotalFiatBalance.Loading + + isLoading.update { it || balance is TotalFiatBalance.Loading } + + acc[userWalletId] = balance + acc } } } } + @OptIn(ExperimentalCoroutinesApi::class) suspend operator fun invoke(userWalletId: UserWalletId): LceFlow { val currenciesStatuses = getStatuses(userWalletId) - return currenciesStatuses.transform { maybeStatuses -> + return currenciesStatuses.transformLatest { maybeStatuses -> val balance = createBalance(maybeStatuses) emit(balance) @@ -72,6 +82,7 @@ class GetWalletTotalBalanceUseCase( currenciesRepository = currenciesRepository, quotesRepository = quotesRepository, networksRepository = networksRepository, + stakingRepository = stakingRepository, ) return operations.getCurrenciesStatuses( diff --git a/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/error/mapper/CurrencyStatusErrorMappers.kt b/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/error/mapper/CurrencyStatusErrorMappers.kt index 6b5e9429d8..000588f24b 100644 --- a/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/error/mapper/CurrencyStatusErrorMappers.kt +++ b/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/error/mapper/CurrencyStatusErrorMappers.kt @@ -6,6 +6,7 @@ import com.tangem.domain.tokens.operations.CurrenciesStatusesOperations internal fun CurrenciesStatusesOperations.Error.mapToCurrencyError(): CurrencyStatusError { return when (this) { is CurrenciesStatusesOperations.Error.DataError -> CurrencyStatusError.DataError(this.cause) + is CurrenciesStatusesOperations.Error.EmptyYieldBalances, is CurrenciesStatusesOperations.Error.EmptyNetworksStatuses, is CurrenciesStatusesOperations.Error.EmptyQuotes, is CurrenciesStatusesOperations.Error.EmptyCurrencies, diff --git a/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/error/mapper/TokenListErrorMappers.kt b/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/error/mapper/TokenListErrorMappers.kt index 27b4e3956f..4f918d6a79 100644 --- a/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/error/mapper/TokenListErrorMappers.kt +++ b/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/error/mapper/TokenListErrorMappers.kt @@ -11,6 +11,7 @@ internal fun CurrenciesStatusesOperations.Error.mapToTokenListError(): TokenList is CurrenciesStatusesOperations.Error.EmptyQuotes, is CurrenciesStatusesOperations.Error.EmptyCurrencies, is CurrenciesStatusesOperations.Error.UnableToCreateCurrencyStatus, + is CurrenciesStatusesOperations.Error.EmptyYieldBalances, -> TokenListError.EmptyTokens } } diff --git a/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/legacy/TradeCryptoAction.kt b/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/legacy/TradeCryptoAction.kt index 092ad6d3ba..0b04bf321b 100644 --- a/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/legacy/TradeCryptoAction.kt +++ b/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/legacy/TradeCryptoAction.kt @@ -1,8 +1,10 @@ package com.tangem.domain.tokens.legacy +import com.tangem.domain.staking.model.stakekit.Yield import com.tangem.domain.tokens.model.CryptoCurrency import com.tangem.domain.tokens.model.CryptoCurrencyStatus import com.tangem.domain.wallets.models.UserWallet +import com.tangem.domain.wallets.models.UserWalletId import org.rekotlin.Action import java.math.BigDecimal @@ -40,6 +42,12 @@ sealed class TradeCryptoAction : Action { data class Swap(val cryptoCurrency: CryptoCurrency) : TradeCryptoAction() + data class Stake( + val userWalletId: UserWalletId, + val cryptoCurrencyId: CryptoCurrency.ID, + val yield: Yield, + ) : TradeCryptoAction() + data class TransactionInfo( val transactionId: String, val destinationAddress: String, diff --git a/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/model/ScenarioUnavailabilityReason.kt b/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/model/ScenarioUnavailabilityReason.kt index 54db16bf92..340ca7d60d 100644 --- a/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/model/ScenarioUnavailabilityReason.kt +++ b/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/model/ScenarioUnavailabilityReason.kt @@ -3,6 +3,9 @@ package com.tangem.domain.tokens.model sealed class ScenarioUnavailabilityReason { data object None : ScenarioUnavailabilityReason() + // staking-specific + data class StakingUnavailable(val cryptoCurrencyName: String) : ScenarioUnavailabilityReason() + // send&sell-specific data class PendingTransaction( val withdrawalScenario: WithdrawalScenario, @@ -24,6 +27,6 @@ sealed class ScenarioUnavailabilityReason { data object UnassociatedAsset : ScenarioUnavailabilityReason() enum class WithdrawalScenario { - SELL, SEND + SELL, SEND // TODO staking create&process STAKING } } \ No newline at end of file diff --git a/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/model/TokenActionsState.kt b/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/model/TokenActionsState.kt index 372f1e51d5..a3dbea0959 100644 --- a/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/model/TokenActionsState.kt +++ b/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/model/TokenActionsState.kt @@ -20,6 +20,8 @@ data class TokenActionsState( data class Receive(override val unavailabilityReason: ScenarioUnavailabilityReason) : ActionState() + data class Stake(override val unavailabilityReason: ScenarioUnavailabilityReason) : ActionState() + data class Swap(override val unavailabilityReason: ScenarioUnavailabilityReason) : ActionState() data class Send(override val unavailabilityReason: ScenarioUnavailabilityReason) : ActionState() diff --git a/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/operations/CurrenciesStatusesLceOperations.kt b/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/operations/CurrenciesStatusesLceOperations.kt index 3dd2b0582b..8dee89d0e6 100644 --- a/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/operations/CurrenciesStatusesLceOperations.kt +++ b/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/operations/CurrenciesStatusesLceOperations.kt @@ -7,6 +7,9 @@ import com.tangem.domain.core.lce.LceFlow import com.tangem.domain.core.lce.lce import com.tangem.domain.core.utils.lceError import com.tangem.domain.core.utils.lceLoading +import com.tangem.domain.staking.model.stakekit.YieldBalance +import com.tangem.domain.staking.model.stakekit.YieldBalanceList +import com.tangem.domain.staking.repositories.StakingRepository import com.tangem.domain.tokens.error.TokenListError import com.tangem.domain.tokens.model.* import com.tangem.domain.tokens.repository.CurrenciesRepository @@ -20,6 +23,7 @@ internal class CurrenciesStatusesLceOperations( private val currenciesRepository: CurrenciesRepository, private val quotesRepository: QuotesRepository, private val networksRepository: NetworksRepository, + private val stakingRepository: StakingRepository, ) { fun getCurrenciesStatuses( @@ -29,7 +33,7 @@ internal class CurrenciesStatusesLceOperations( return transformToCurrenciesStatuses( userWalletId = userWalletId, flow = if (isSingleCurrencyWalletsAllowed) { - getWalletCurrenies(userWalletId) + getWalletCurrencies(userWalletId) } else { getMultiCurrencyWalletCurrencies(userWalletId) }, @@ -65,11 +69,18 @@ internal class CurrenciesStatusesLceOperations( val (networks, currenciesIds) = getIds(nonEmptyCurrencies) + val addresses = networksRepository.getNetworkAddresses(userWalletId) combine( getQuotes(currenciesIds), getNetworksStatuses(userWalletId, networks), - ) { maybeQuotes, maybeNetworksStatuses -> - val statuses = createCurrenciesStatuses(nonEmptyCurrencies, maybeQuotes, maybeNetworksStatuses) + getYieldBalances(userWalletId, addresses), + ) { maybeQuotes, maybeNetworksStatuses, maybeYieldBalances -> + val statuses = createCurrenciesStatuses( + currencies = nonEmptyCurrencies, + maybeQuotes = maybeQuotes, + maybeNetworkStatuses = maybeNetworksStatuses, + maybeYieldBalances = maybeYieldBalances, + ) emit(statuses) }.collect() } @@ -84,16 +95,17 @@ internal class CurrenciesStatusesLceOperations( lceLoading() } else { createCurrenciesStatuses( - nonEmptyCurrencies, + currencies = nonEmptyCurrencies, maybeNetworkStatuses = null, maybeQuotes = null, + maybeYieldBalances = null, ) } return statuses } - private fun getWalletCurrenies(userWalletId: UserWalletId): LceFlow> { + private fun getWalletCurrencies(userWalletId: UserWalletId): LceFlow> { return currenciesRepository.getWalletCurrenciesUpdates(userWalletId) .map { maybeCurrencies -> maybeCurrencies.mapError { TokenListError.DataError(it) } @@ -113,6 +125,7 @@ internal class CurrenciesStatusesLceOperations( currencies: NonEmptyList, maybeQuotes: Either>?, maybeNetworkStatuses: Lce>?, + maybeYieldBalances: Lce?, ): Lce> = lce { isLoading.set(maybeNetworkStatuses == null) @@ -127,11 +140,20 @@ internal class CurrenciesStatusesLceOperations( null } + val yieldBalances = maybeYieldBalances?.getOrNull() + currencies.map { currency -> val quote = quotes?.firstOrNull { it.rawCurrencyId == currency.id.rawCurrencyId } val networkStatus = networksStatuses?.firstOrNull { it.network == currency.network } + val yieldBalance = (yieldBalances as? YieldBalanceList.Data)?.getBalance(currency.id.rawCurrencyId) - createCurrencyStatus(currency, quote, networkStatus, ignoreQuote = quotesRetrievingFailed) + createCurrencyStatus( + currency = currency, + quote = quote, + networkStatus = networkStatus, + yieldBalance = yieldBalance, + ignoreQuote = quotesRetrievingFailed, + ) } } @@ -139,12 +161,14 @@ internal class CurrenciesStatusesLceOperations( currency: CryptoCurrency, quote: Quote?, networkStatus: NetworkStatus?, + yieldBalance: YieldBalance?, ignoreQuote: Boolean, ): CryptoCurrencyStatus { val currencyStatusOperations = CurrencyStatusOperations( currency = currency, quote = quote, networkStatus = networkStatus, + yieldBalance = yieldBalance, ignoreQuote = ignoreQuote, ) @@ -167,6 +191,18 @@ internal class CurrenciesStatusesLceOperations( } } + private fun getYieldBalances( + userWalletId: UserWalletId, + addresses: List, + ): LceFlow { + return stakingRepository.getMultiYieldBalanceLce( + userWalletId = userWalletId, + addresses = addresses, + ).map { maybeBalances -> + maybeBalances.mapError { TokenListError.DataError(it) } + } + } + private fun getIds(currencies: List): Pair, NonEmptySet> { val currencyIdToNetworkId = currencies.associate { currency -> currency.id to currency.network diff --git a/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/operations/CurrenciesStatusesOperations.kt b/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/operations/CurrenciesStatusesOperations.kt index de1768de08..34e8a290cb 100644 --- a/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/operations/CurrenciesStatusesOperations.kt +++ b/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/operations/CurrenciesStatusesOperations.kt @@ -3,6 +3,9 @@ package com.tangem.domain.tokens.operations import arrow.core.* import arrow.core.raise.* import com.tangem.domain.core.utils.EitherFlow +import com.tangem.domain.staking.model.stakekit.YieldBalance +import com.tangem.domain.staking.model.stakekit.YieldBalanceList +import com.tangem.domain.staking.repositories.StakingRepository import com.tangem.domain.tokens.model.* import com.tangem.domain.tokens.repository.CurrenciesRepository import com.tangem.domain.tokens.repository.NetworksRepository @@ -17,48 +20,10 @@ internal class CurrenciesStatusesOperations( private val currenciesRepository: CurrenciesRepository, private val quotesRepository: QuotesRepository, private val networksRepository: NetworksRepository, + private val stakingRepository: StakingRepository, private val userWalletId: UserWalletId, ) { - @OptIn(ExperimentalCoroutinesApi::class) - fun getCurrenciesStatusesFlow(): EitherFlow> { - return getMultiCurrencyWalletCurrencies().transformLatest { maybeCurrencies -> - val nonEmptyCurrencies = maybeCurrencies.fold( - ifLeft = { error -> - emit(error.left()) - return@transformLatest - }, - ifRight = List::toNonEmptyListOrNull, - ) - - if (nonEmptyCurrencies == null) { - val emptyCurrenciesStatuses = emptyList() - - emit(emptyCurrenciesStatuses.right()) - return@transformLatest - } - - val maybeLoadingCurrenciesStatuses = createCurrenciesStatuses( - currencies = nonEmptyCurrencies, - maybeNetworkStatuses = null, - maybeQuotes = null, - ) - - emit(maybeLoadingCurrenciesStatuses) - - val (networks, currenciesIds) = getIds(nonEmptyCurrencies) - - val currenciesFlow = combine( - getQuotes(currenciesIds), - getNetworksStatuses(networks), - ) { maybeQuotes, maybeNetworksStatuses -> - createCurrenciesStatuses(nonEmptyCurrencies, maybeQuotes, maybeNetworksStatuses) - } - - emitAll(currenciesFlow) - } - } - suspend fun getCurrenciesStatusesSync(): Either> { return either { catch( @@ -70,7 +35,9 @@ internal class CurrenciesStatusesOperations( val quotes = quotesRepository.getQuotesSync(currenciesIds, false).right() val networkStatuses = networksRepository.getNetworkStatusesSync(userWalletId, networks, false).right() - return createCurrenciesStatuses(nonEmptyCurrencies, quotes, networkStatuses) + val yieldBalances = getYieldBalancesSync() + + return createCurrenciesStatuses(nonEmptyCurrencies, quotes, networkStatuses, yieldBalances) }, catch = { raise(Error.DataError(it)) }, ) @@ -98,7 +65,9 @@ internal class CurrenciesStatusesOperations( ).firstOrNull { it.network == currency.network }.right() - return createCurrencyStatus(currency, quotes, networkStatuses) + val yieldBalances = getYieldBalanceSync(currency) + + return createCurrencyStatus(currency, quotes, networkStatuses, yieldBalances) }, catch = { raise(Error.DataError(it)) }, ) @@ -142,8 +111,9 @@ internal class CurrenciesStatusesOperations( }, catch = { Error.DataError(it).left() }, ) + val yieldBalances = getYieldBalanceSync(currency) - return createCurrencyStatus(currency, quotes, networkStatus) + return createCurrencyStatus(currency, quotes, networkStatus, yieldBalances) } fun getCardCurrenciesStatusesFlow(): Flow>> { @@ -167,6 +137,7 @@ internal class CurrenciesStatusesOperations( currencies = nonEmptyCurrencies, maybeNetworkStatuses = null, maybeQuotes = null, + maybeYieldBalances = null, ) emit(maybeLoadingCurrenciesStatuses) @@ -176,8 +147,9 @@ internal class CurrenciesStatusesOperations( val currenciesFlow = combine( getQuotes(currenciesIds), getNetworksStatuses(networks), - ) { maybeQuotes, maybeNetworksStatuses -> - createCurrenciesStatuses(nonEmptyCurrencies, maybeQuotes, maybeNetworksStatuses) + getYieldBalances(), + ) { maybeQuotes, maybeNetworksStatuses, maybeYieldBalances -> + createCurrenciesStatuses(nonEmptyCurrencies, maybeQuotes, maybeNetworksStatuses, maybeYieldBalances) } emitAll(currenciesFlow) @@ -255,8 +227,10 @@ internal class CurrenciesStatusesOperations( } } - return combine(quoteFlow, statusFlow) { maybeQuote, maybeNetworkStatus -> - createCurrencyStatus(currency, maybeQuote, maybeNetworkStatus) + val yieldBalanceFlow = getYieldBalance(currency) + + return combine(quoteFlow, statusFlow, yieldBalanceFlow) { maybeQuote, maybeNetworkStatus, maybeYieldBalance -> + createCurrencyStatus(currency, maybeQuote, maybeNetworkStatus, maybeYieldBalance) } } @@ -264,6 +238,7 @@ internal class CurrenciesStatusesOperations( currencies: NonEmptyList, maybeQuotes: Either>?, maybeNetworkStatuses: Either>?, + maybeYieldBalances: Either?, ): Either> = either { var quotesRetrievingFailed = false @@ -281,11 +256,19 @@ internal class CurrenciesStatusesOperations( }, ) + val yieldBalances = maybeYieldBalances?.getOrNull() + currencies.map { currency -> val quote = quotes?.firstOrNull { it.rawCurrencyId == currency.id.rawCurrencyId } val networkStatus = networksStatuses?.firstOrNull { it.network == currency.network } - - createCurrencyStatus(currency, quote, networkStatus, ignoreQuote = quotesRetrievingFailed) + val yieldBalance = (yieldBalances as? YieldBalanceList.Data)?.getBalance(currency.id.rawCurrencyId) + createCurrencyStatus( + currency = currency, + quote = quote, + networkStatus = networkStatus, + ignoreQuote = quotesRetrievingFailed, + yieldBalance = yieldBalance, + ) } } @@ -293,6 +276,7 @@ internal class CurrenciesStatusesOperations( currency: CryptoCurrency, maybeQuote: Either, maybeNetworkStatus: Either, + maybeYieldBalance: Either?, ): Either = either { var quoteRetrievingFailed = false @@ -301,8 +285,15 @@ internal class CurrenciesStatusesOperations( quoteRetrievingFailed = true null } + val yieldBalance = maybeYieldBalance?.getOrNull() - createCurrencyStatus(currency, quote, networkStatus, ignoreQuote = quoteRetrievingFailed) + createCurrencyStatus( + currency = currency, + quote = quote, + networkStatus = networkStatus, + ignoreQuote = quoteRetrievingFailed, + yieldBalance = yieldBalance, + ) } private fun createCurrencyStatus( @@ -310,24 +301,19 @@ internal class CurrenciesStatusesOperations( quote: Quote?, networkStatus: NetworkStatus?, ignoreQuote: Boolean, + yieldBalance: YieldBalance?, ): CryptoCurrencyStatus { val currencyStatusOperations = CurrencyStatusOperations( currency = currency, quote = quote, networkStatus = networkStatus, ignoreQuote = ignoreQuote, + yieldBalance = yieldBalance, ) return currencyStatusOperations.createTokenStatus() } - private fun getMultiCurrencyWalletCurrencies(): Flow>> { - return currenciesRepository.getMultiCurrencyWalletCurrenciesUpdates(userWalletId) - .map, Either>> { it.right() } - .catch { emit(Error.DataError(it).left()) } - .onEmpty { emit(Error.EmptyCurrencies.left()) } - } - private suspend fun Raise.getMultiCurrencyWalletCurrency(currencyId: CryptoCurrency.ID): CryptoCurrency { return Either.catch { currenciesRepository.getMultiCurrencyWalletCurrency( @@ -396,6 +382,65 @@ internal class CurrenciesStatusesOperations( .onEmpty { emit(Error.EmptyNetworksStatuses.left()) } } + @OptIn(ExperimentalCoroutinesApi::class) + private fun getYieldBalances(): EitherFlow { + return networksRepository.getNetworkAddressesFlow(userWalletId).flatMapLatest { addresses -> + stakingRepository.getMultiYieldBalanceFlow( + userWalletId = userWalletId, + addresses = addresses, + ).map> { it.right() } + .catch { emit(Error.DataError(it).left()) } + .onEmpty { emit(Error.EmptyYieldBalances.left()) } + } + } + + private suspend fun getYieldBalancesSync(): Either { + return catch( + block = { + val networkAddresses = networksRepository.getNetworkAddresses(userWalletId) + stakingRepository.getMultiYieldBalanceSync( + userWalletId, + networkAddresses, + ).right() + }, + catch = { + Error.EmptyYieldBalances.left() + }, + ) + } + + private suspend fun getYieldBalanceSync( + cryptoCurrency: CryptoCurrency, + ): Either { + return catch( + block = { + val address = networksRepository.getNetworkAddress(userWalletId, cryptoCurrency) + stakingRepository.getSingleYieldBalanceSync( + userWalletId, + address, + ).right() + }, + catch = { + Error.EmptyYieldBalances.left() + }, + ) + } + + @OptIn(ExperimentalCoroutinesApi::class) + private fun getYieldBalance(cryptoCurrency: CryptoCurrency): EitherFlow { + return networksRepository.getNetworkAddressFlow( + userWalletId, + cryptoCurrency, + ).flatMapLatest { address -> + stakingRepository.getSingleYieldBalanceFlow( + userWalletId = userWalletId, + address = address, + ).map> { it.right() } + .catch { emit(Error.DataError(it).left()) } + .onEmpty { emit(Error.EmptyYieldBalances.left()) } + } + } + private fun getIds( currencies: NonEmptyList, ): Pair, NonEmptySet> { @@ -413,14 +458,16 @@ internal class CurrenciesStatusesOperations( sealed class Error { - object EmptyCurrencies : Error() + data object EmptyCurrencies : Error() - object EmptyQuotes : Error() + data object EmptyQuotes : Error() - object EmptyNetworksStatuses : Error() + data object EmptyNetworksStatuses : Error() - object UnableToCreateCurrencyStatus : Error() + data object UnableToCreateCurrencyStatus : Error() data class DataError(val cause: Throwable) : Error() + + data object EmptyYieldBalances : Error() } } \ No newline at end of file diff --git a/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/operations/CurrencyStatusOperations.kt b/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/operations/CurrencyStatusOperations.kt index 8284d1667e..380f77dc4f 100644 --- a/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/operations/CurrencyStatusOperations.kt +++ b/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/operations/CurrencyStatusOperations.kt @@ -1,5 +1,6 @@ package com.tangem.domain.tokens.operations +import com.tangem.domain.staking.model.stakekit.YieldBalance import com.tangem.domain.tokens.model.* import java.math.BigDecimal @@ -7,6 +8,7 @@ internal class CurrencyStatusOperations( private val currency: CryptoCurrency, private val quote: Quote?, private val networkStatus: NetworkStatus?, + private val yieldBalance: YieldBalance?, private val ignoreQuote: Boolean, ) { @@ -18,7 +20,7 @@ internal class CurrencyStatusOperations( is NetworkStatus.MissedDerivation -> createMissedDerivationStatus() is NetworkStatus.Unreachable -> createUnreachableStatus(status) is NetworkStatus.NoAccount -> createNoAccountStatus(status) - is NetworkStatus.Verified -> createStatus(status) + is NetworkStatus.Verified -> createStatus(status, yieldBalance) } } @@ -42,7 +44,7 @@ internal class CurrencyStatusOperations( networkAddress = status.address, ) - private fun createStatus(status: NetworkStatus.Verified): CryptoCurrencyStatus.Value { + private fun createStatus(status: NetworkStatus.Verified, yieldBalance: YieldBalance?): CryptoCurrencyStatus.Value { val amount = when (val amount = status.amounts[currency.id]) { null -> { return CryptoCurrencyStatus.Loading @@ -62,6 +64,7 @@ internal class CurrencyStatusOperations( hasCurrentNetworkTransactions = hasCurrentNetworkTransactions, pendingTransactions = currentTransactions, networkAddress = status.address, + yieldBalance = yieldBalance, ) currency is CryptoCurrency.Token && currency.isCustom -> CryptoCurrencyStatus.Custom( amount = amount, @@ -71,6 +74,7 @@ internal class CurrencyStatusOperations( hasCurrentNetworkTransactions = hasCurrentNetworkTransactions, pendingTransactions = currentTransactions, networkAddress = status.address, + yieldBalance = yieldBalance, ) quote == null -> CryptoCurrencyStatus.Loading else -> CryptoCurrencyStatus.Loaded( @@ -81,6 +85,7 @@ internal class CurrencyStatusOperations( hasCurrentNetworkTransactions = hasCurrentNetworkTransactions, pendingTransactions = currentTransactions, networkAddress = status.address, + yieldBalance = yieldBalance, ) } } diff --git a/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/operations/TokenListFiatBalanceOperations.kt b/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/operations/TokenListFiatBalanceOperations.kt index 2ff01885c9..e446ca55aa 100644 --- a/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/operations/TokenListFiatBalanceOperations.kt +++ b/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/operations/TokenListFiatBalanceOperations.kt @@ -1,8 +1,10 @@ package com.tangem.domain.tokens.operations import arrow.core.NonEmptyList +import com.tangem.domain.staking.model.stakekit.YieldBalance import com.tangem.domain.tokens.model.CryptoCurrencyStatus import com.tangem.domain.tokens.model.TotalFiatBalance +import com.tangem.utils.extensions.orZero import java.math.BigDecimal internal class TokenListFiatBalanceOperations( @@ -56,10 +58,13 @@ internal class TokenListFiatBalanceOperations( currentBalance: TotalFiatBalance, ): TotalFiatBalance { return with(currentBalance) { + val stakingBalance = (status.yieldBalance as? YieldBalance.Data)?.getTotalStakingBalance().orZero() + val fiatStakingBalance = status.fiatRate.times(stakingBalance) + (this as? TotalFiatBalance.Loaded)?.copy( - amount = this.amount + status.fiatAmount, + amount = this.amount + status.fiatAmount + fiatStakingBalance, ) ?: TotalFiatBalance.Loaded( - amount = status.fiatAmount, + amount = status.fiatAmount + fiatStakingBalance, isAllAmountsSummarized = true, ) } @@ -71,12 +76,13 @@ internal class TokenListFiatBalanceOperations( ): TotalFiatBalance { return with(currentBalance) { val isTokenAmountCanBeSummarized = status.fiatAmount != null - + val yieldBalance = (status.yieldBalance as? YieldBalance.Data)?.getTotalStakingBalance().orZero() + val fiatYieldBalance = status.fiatRate?.times(yieldBalance).orZero() (this as? TotalFiatBalance.Loaded)?.copy( - amount = this.amount + (status.fiatAmount ?: BigDecimal.ZERO), + amount = this.amount + status.fiatAmount.orZero() + fiatYieldBalance, isAllAmountsSummarized = isTokenAmountCanBeSummarized, ) ?: TotalFiatBalance.Loaded( - amount = status.fiatAmount ?: BigDecimal.ZERO, + amount = status.fiatAmount.orZero() + fiatYieldBalance, isAllAmountsSummarized = isTokenAmountCanBeSummarized, ) } diff --git a/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/repository/CurrenciesRepository.kt b/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/repository/CurrenciesRepository.kt index d5daebcd8e..4d8d4f0522 100644 --- a/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/repository/CurrenciesRepository.kt +++ b/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/repository/CurrenciesRepository.kt @@ -195,12 +195,15 @@ interface CurrenciesRepository { fun getMissedAddressesCryptoCurrencies(userWalletId: UserWalletId): Flow> /** - * Determines whether the currency has pending transaction or currency network has pending transaction + * Determines whether the currency sending is blocked by network pending transaction * * @param cryptoCurrencyStatus currency status * @param coinStatus main currency status in [cryptoCurrencyStatus] network */ - fun hasPendingTransactions(cryptoCurrencyStatus: CryptoCurrencyStatus, coinStatus: CryptoCurrencyStatus?): Boolean + fun isSendBlockedByPendingTransactions( + cryptoCurrencyStatus: CryptoCurrencyStatus, + coinStatus: CryptoCurrencyStatus?, + ): Boolean /** * Retrieves fee paid currency for specific [currency]. diff --git a/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/repository/NetworksRepository.kt b/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/repository/NetworksRepository.kt index a2033bb707..a2a99ddea2 100644 --- a/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/repository/NetworksRepository.kt +++ b/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/repository/NetworksRepository.kt @@ -1,6 +1,7 @@ package com.tangem.domain.tokens.repository import com.tangem.domain.core.lce.LceFlow +import com.tangem.domain.tokens.model.CryptoCurrency import com.tangem.domain.tokens.model.CryptoCurrencyAddress import com.tangem.domain.tokens.model.Network import com.tangem.domain.tokens.model.NetworkStatus @@ -62,8 +63,33 @@ interface NetworksRepository { fun isNeedToCreateAccountWithoutReserve(network: Network): Boolean + /** + * Returns list of addresses and crypto currency info of added currencies of [network] in selected wallet [userWalletId] + */ + fun getNetworkAddressesFlow(userWalletId: UserWalletId, network: Network): Flow> + /** * Returns list of addresses and crypto currency info of added currencies of [network] in selected wallet [userWalletId] */ suspend fun getNetworkAddresses(userWalletId: UserWalletId, network: Network): List + + /** + * Returns address of [cryptoCurrency] in selected wallet [userWalletId] + */ + suspend fun getNetworkAddress(userWalletId: UserWalletId, currency: CryptoCurrency): CryptoCurrencyAddress + + /** + * Returns address of [cryptoCurrency] in selected wallet [userWalletId] + */ + fun getNetworkAddressFlow(userWalletId: UserWalletId, currency: CryptoCurrency): Flow + + /** + * Returns list of addresses and crypto currency info in selected wallet [userWalletId] + */ + fun getNetworkAddressesFlow(userWalletId: UserWalletId): Flow> + + /** + * Returns list of addresses and crypto currency info in selected wallet [userWalletId] + */ + suspend fun getNetworkAddresses(userWalletId: UserWalletId): List } \ No newline at end of file diff --git a/domain/tokens/src/test/kotlin/com/tangem/domain/tokens/GetPrimaryCurrencyStatusUpdatesUseCaseTest.kt b/domain/tokens/src/test/kotlin/com/tangem/domain/tokens/GetPrimaryCurrencyStatusUpdatesUseCaseTest.kt index b5c027ac68..824a8e89c2 100644 --- a/domain/tokens/src/test/kotlin/com/tangem/domain/tokens/GetPrimaryCurrencyStatusUpdatesUseCaseTest.kt +++ b/domain/tokens/src/test/kotlin/com/tangem/domain/tokens/GetPrimaryCurrencyStatusUpdatesUseCaseTest.kt @@ -4,6 +4,7 @@ import arrow.core.Either import arrow.core.left import arrow.core.right import com.tangem.domain.core.error.DataError +import com.tangem.domain.staking.model.stakekit.YieldBalance import com.tangem.domain.tokens.error.CurrencyStatusError import com.tangem.domain.tokens.mock.MockNetworks import com.tangem.domain.tokens.mock.MockQuotes @@ -13,6 +14,7 @@ import com.tangem.domain.tokens.model.* import com.tangem.domain.tokens.repository.MockCurrenciesRepository import com.tangem.domain.tokens.repository.MockNetworksRepository import com.tangem.domain.tokens.repository.MockQuotesRepository +import com.tangem.domain.tokens.repository.MockStakingRepository import com.tangem.domain.wallets.models.UserWalletId import com.tangem.utils.coroutines.TestingCoroutineDispatcherProvider import junit.framework.TestCase.assertEquals @@ -121,6 +123,7 @@ internal class GetPrimaryCurrencyStatusUpdatesUseCaseTest { networkAddress = NetworkAddress.Single( defaultAddress = NetworkAddress.Address(value = "mock", NetworkAddress.Address.Type.Primary), ), + yieldBalance = YieldBalance.Error, ), ) } @@ -171,5 +174,6 @@ internal class GetPrimaryCurrencyStatusUpdatesUseCaseTest { ), quotesRepository = MockQuotesRepository(quotes), networksRepository = MockNetworksRepository(statuses), + stakingRepository = MockStakingRepository(), ) } \ No newline at end of file diff --git a/domain/tokens/src/test/kotlin/com/tangem/domain/tokens/GetTokenListUseCaseTest.kt b/domain/tokens/src/test/kotlin/com/tangem/domain/tokens/GetTokenListUseCaseTest.kt deleted file mode 100644 index 613246a85c..0000000000 --- a/domain/tokens/src/test/kotlin/com/tangem/domain/tokens/GetTokenListUseCaseTest.kt +++ /dev/null @@ -1,320 +0,0 @@ -package com.tangem.domain.tokens - -import arrow.core.Either -import arrow.core.left -import arrow.core.right -import com.tangem.domain.core.error.DataError -import com.tangem.domain.tokens.error.TokenListError -import com.tangem.domain.tokens.mock.MockNetworks -import com.tangem.domain.tokens.mock.MockQuotes -import com.tangem.domain.tokens.mock.MockTokenLists -import com.tangem.domain.tokens.mock.MockTokens -import com.tangem.domain.tokens.model.CryptoCurrency -import com.tangem.domain.tokens.model.NetworkStatus -import com.tangem.domain.tokens.model.Quote -import com.tangem.domain.tokens.model.TokenList -import com.tangem.domain.tokens.repository.MockCurrenciesRepository -import com.tangem.domain.tokens.repository.MockNetworksRepository -import com.tangem.domain.tokens.repository.MockQuotesRepository -import com.tangem.domain.wallets.models.UserWalletId -import junit.framework.TestCase.assertEquals -import kotlinx.coroutines.delay -import kotlinx.coroutines.flow.* -import kotlinx.coroutines.test.runTest -import org.junit.Ignore -import org.junit.Test - -internal class GetTokenListUseCaseTest { - - private val userWalletId = UserWalletId(value = null) - - @Ignore - @Test - fun `when list ungrouped and unsorted then correct token list should be returned`() = runTest { - // Given - val expectedResult = listOf( - MockTokenLists.loadingUngroupedTokenList.right(), - MockTokenLists.failedUngroupedTokenList.right(), - ) - - val useCase = getUseCase( - isGrouped = flowOf(false.right()), - isSortedByBalance = flowOf(false.right()), - ) - - // When - val result = useCase.launch(userWalletId) - .take(count = 2) - .toList() - - // Then - assertEquals(expectedResult, result) - } - - @Test - fun `when tokens getting failed then error should be received`() = runTest { - // Given - val expectedResult = TokenListError.DataError(DataError.NetworkError.NoInternetConnection).left() - - val useCase = getUseCase(tokens = flowOf(DataError.NetworkError.NoInternetConnection.left())) - - // When - val result = useCase.launch(userWalletId).first() - - // Then - assertEquals(expectedResult, result) - } - - @Test - fun `when quotes getting failed then token list without quotes should be received`() = runTest { - // Given - val expectedResult = listOf( - MockTokenLists.loadingUngroupedTokenList.right(), - MockTokenLists.noQuotesUngroupedTokenList.right(), - ) - - val useCase = getUseCase( - quotes = flowOf(DataError.NetworkError.NoInternetConnection.left()), - statuses = flowOf(MockNetworks.verifiedNetworksStatuses.right()), - ) - - // When - val result = useCase.launch(userWalletId) - .take(count = 2) - .toList() - - // Then - assertEquals(expectedResult, result) - } - - @Test - fun `when grouping type getting failed then error should be received`() = runTest { - // Given - val expectedResult = TokenListError.DataError(DataError.NetworkError.NoInternetConnection).left() - - val useCase = getUseCase(isGrouped = flowOf(DataError.NetworkError.NoInternetConnection.left())) - - // When - val result = useCase.launch(userWalletId).first() - - // Then - assertEquals(expectedResult, result) - } - - @Test - fun `when sorting type getting failed then error should be received`() = runTest { - // Given - val expectedResult = TokenListError.DataError(DataError.NetworkError.NoInternetConnection).left() - - val useCase = getUseCase(isSortedByBalance = flowOf(DataError.NetworkError.NoInternetConnection.left())) - - // When - val result = useCase.launch(userWalletId).first() - - // Then - assertEquals(expectedResult, result) - } - - @Ignore - @Test - fun `when tokens getting failed on second emit then error should be received`() = runTest { - // Given - val error = DataError.NetworkError.NoInternetConnection.left() - val expectedResult = listOf( - MockTokenLists.loadingUngroupedTokenList.right(), - MockTokenLists.failedUngroupedTokenList.right(), - TokenListError.DataError(DataError.NetworkError.NoInternetConnection).left(), - ) - - val useCase = getUseCase( - tokens = flowOf( - MockTokens.tokens.right(), - error, - ).map { delay(timeMillis = 1_000); it }, - ) - - // When - val result = useCase.launch(userWalletId) - .take(count = 3) - .toList() - - // Then - assertEquals(expectedResult, result) - } - - @Ignore - @Test - fun `when list grouped then correct token list should be received`() = runTest { - val expectedResult = listOf( - MockTokenLists.loadingGroupedTokenList.right(), - MockTokenLists.failedGroupedTokenList.right(), - ) - - val useCase = getUseCase(isGrouped = flowOf(true.right())) - - // When - val result = useCase.launch(userWalletId) - .take(count = 2) - .toList() - - // Then - assertEquals(expectedResult, result) - } - - @Test - fun `when list is sorted and ungrouped then correct token list should be received`() = runTest { - val expectedResult = listOf( - MockTokenLists.loadingUngroupedTokenList.copy(sortedBy = TokenList.SortType.BALANCE).right(), - MockTokenLists.sortedUngroupedTokenList.right(), - ) - - val useCase = getUseCase( - statuses = flowOf(MockNetworks.verifiedNetworksStatuses.right()), - isGrouped = flowOf(false.right()), - isSortedByBalance = flowOf(true.right()), - ) - - // When - val result = useCase.launch(userWalletId) - .take(count = 2) - .toList() - - // Then - assertEquals(expectedResult, result) - } - - @Test - fun `when list is sorted and grouped then correct token list should be received`() = runTest { - val expectedResult = listOf( - MockTokenLists.loadingGroupedTokenList.copy(sortedBy = TokenList.SortType.BALANCE).right(), - MockTokenLists.sortedGroupedTokenList.right(), - ) - - val useCase = getUseCase( - statuses = flowOf(MockNetworks.verifiedNetworksStatuses.right()), - isGrouped = flowOf(true.right()), - isSortedByBalance = flowOf(true.right()), - ) - - // When - val result = useCase.launch(userWalletId) - .take(count = 2) - .toList() - - // Then - assertEquals(expectedResult, result) - } - - @Test - fun `when tokens is empty then not initialized token list should be received`() = runTest { - val expectedResult = MockTokenLists.emptyTokenList.right() - - val useCase = getUseCase(tokens = flowOf(emptyList().right())) - - // When - val result = useCase.launch(userWalletId).first() - - // Then - assertEquals(expectedResult, result) - } - - @Test - fun `when tokens flow is empty then error should be received`() = runTest { - val expectedResult = TokenListError.EmptyTokens.left() - - val useCase = getUseCase(tokens = flowOf()) - - // When - val result = useCase.launch(userWalletId).first() - - // Then - assertEquals(expectedResult, result) - } - - @Test - fun `when networks statuses flow is empty then error should be received`() = runTest { - val expectedResult = listOf( - MockTokenLists.loadingUngroupedTokenList.right(), - TokenListError.EmptyTokens.left(), - ) - - val useCase = getUseCase(statuses = flowOf()) - - // When - val result = useCase.launch(userWalletId) - .take(count = 2) - .toList() - - // Then - assertEquals(expectedResult, result) - } - - @Test - fun `when networks statuses is empty then loading token list should be received`() = runTest { - val expectedResult = MockTokenLists.loadingUngroupedTokenList.right() - - val useCase = getUseCase(statuses = flowOf(emptySet().right())) - - // When - val result = useCase.launch(userWalletId).first() - - // Then - assertEquals(expectedResult, result) - } - - @Test - fun `when quotes flow is empty then list without quotes should be received`() = runTest { - val expectedResult = listOf( - MockTokenLists.loadingUngroupedTokenList.right(), - MockTokenLists.noQuotesUngroupedTokenList.right(), - ) - - val useCase = getUseCase( - statuses = flowOf(MockNetworks.verifiedNetworksStatuses.right()), - quotes = flowOf(emptySet().right()), - ) - - // When - val result = useCase.launch(userWalletId) - .take(count = 2) - .toList() - - // Then - assertEquals(expectedResult, result) - } - - @Test - fun `when quotes is empty and statuses verified then loading token list should be received`() = runTest { - val expectedResult = MockTokenLists.loadingUngroupedTokenList.right() - - val useCase = getUseCase( - statuses = flowOf(MockNetworks.verifiedNetworksStatuses.right()), - quotes = flowOf(emptySet().right()), - ) - - // When - val result = useCase.launch(userWalletId).first() - - // Then - assertEquals(expectedResult, result) - } - - private fun getUseCase( - tokens: Flow>> = flowOf(MockTokens.tokens.right()), - quotes: Flow>> = flowOf(MockQuotes.quotes.right()), - statuses: Flow>> = flowOf(MockNetworks.errorNetworksStatuses.right()), - isGrouped: Flow> = flowOf(MockTokenLists.isGrouped.right()), - isSortedByBalance: Flow> = flowOf(MockTokenLists.isSortedByBalance.right()), - ) = GetTokenListUseCase( - currenciesRepository = MockCurrenciesRepository( - sortTokensResult = Unit.right(), - removeCurrencyResult = Unit.right(), - token = MockTokens.token1.right(), - tokens = tokens, - isGrouped = isGrouped, - isSortedByBalance = isSortedByBalance, - ), - quotesRepository = MockQuotesRepository(quotes), - networksRepository = MockNetworksRepository(statuses), - ) -} \ No newline at end of file diff --git a/domain/tokens/src/test/kotlin/com/tangem/domain/tokens/mock/MockTokenLists.kt b/domain/tokens/src/test/kotlin/com/tangem/domain/tokens/mock/MockTokenLists.kt index e08a5348dd..3f15752baf 100644 --- a/domain/tokens/src/test/kotlin/com/tangem/domain/tokens/mock/MockTokenLists.kt +++ b/domain/tokens/src/test/kotlin/com/tangem/domain/tokens/mock/MockTokenLists.kt @@ -49,7 +49,8 @@ internal object MockTokenLists { val loadingUngroupedTokenList = with(failedUngroupedTokenList) { copy( - currencies = currencies.map { it.copy(value = CryptoCurrencyStatus.Loading) }.toNonEmptyListOrNull() ?: emptyList(), + currencies = currencies.map { it.copy(value = CryptoCurrencyStatus.Loading) }.toNonEmptyListOrNull() + ?: emptyList(), totalFiatBalance = TotalFiatBalance.Loading, ) } @@ -60,7 +61,9 @@ internal object MockTokenLists { groups = groups.map { group -> group.copy( currencies = group.currencies - .map { it.copy(value = CryptoCurrencyStatus.Loading) }, + .map { it.copy(value = CryptoCurrencyStatus.Loading) } + .toNonEmptyListOrNull() + ?: emptyList(), ) }.toNonEmptyListOrNull()!!, ) @@ -109,7 +112,7 @@ internal object MockTokenLists { val sortedGroupedTokenList: TokenList.GroupedByNetwork get() { - val groups = sortedNetworksGroups + val groups = sortedNetworksGroups.toNonEmptyList() return unsortedGroupedTokenList.copy( groups = groups, diff --git a/domain/tokens/src/test/kotlin/com/tangem/domain/tokens/mock/MockTokensStates.kt b/domain/tokens/src/test/kotlin/com/tangem/domain/tokens/mock/MockTokensStates.kt index 7490827a6c..78858d98c1 100644 --- a/domain/tokens/src/test/kotlin/com/tangem/domain/tokens/mock/MockTokensStates.kt +++ b/domain/tokens/src/test/kotlin/com/tangem/domain/tokens/mock/MockTokensStates.kt @@ -1,6 +1,7 @@ package com.tangem.domain.tokens.mock import arrow.core.nonEmptyListOf +import com.tangem.domain.staking.model.stakekit.YieldBalance import com.tangem.domain.tokens.model.CryptoCurrencyAmountStatus import com.tangem.domain.tokens.model.CryptoCurrencyStatus import com.tangem.domain.tokens.model.NetworkAddress @@ -151,6 +152,7 @@ internal object MockTokensStates { pendingTransactions = emptySet(), hasCurrentNetworkTransactions = false, networkAddress = requireNotNull(networkStatus.value as? NetworkStatus.Verified).address, + yieldBalance = YieldBalance.Error, ), ) } @@ -166,6 +168,7 @@ internal object MockTokensStates { .first { it.network == status.currency.network } .value as? NetworkStatus.Verified, ).address, + yieldBalance = YieldBalance.Error, ), ) } diff --git a/domain/tokens/src/test/kotlin/com/tangem/domain/tokens/repository/MockCurrenciesRepository.kt b/domain/tokens/src/test/kotlin/com/tangem/domain/tokens/repository/MockCurrenciesRepository.kt index ff73d40462..c1c3aa5e5a 100644 --- a/domain/tokens/src/test/kotlin/com/tangem/domain/tokens/repository/MockCurrenciesRepository.kt +++ b/domain/tokens/src/test/kotlin/com/tangem/domain/tokens/repository/MockCurrenciesRepository.kt @@ -122,7 +122,7 @@ internal class MockCurrenciesRepository( return isSortedByBalance.map { it.getOrElse { e -> throw e } } } - override fun hasPendingTransactions( + override fun isSendBlockedByPendingTransactions( cryptoCurrencyStatus: CryptoCurrencyStatus, coinStatus: CryptoCurrencyStatus?, ): Boolean { diff --git a/domain/tokens/src/test/kotlin/com/tangem/domain/tokens/repository/MockNetworksRepository.kt b/domain/tokens/src/test/kotlin/com/tangem/domain/tokens/repository/MockNetworksRepository.kt index 78e06e7087..5b5019dfd6 100644 --- a/domain/tokens/src/test/kotlin/com/tangem/domain/tokens/repository/MockNetworksRepository.kt +++ b/domain/tokens/src/test/kotlin/com/tangem/domain/tokens/repository/MockNetworksRepository.kt @@ -3,13 +3,15 @@ package com.tangem.domain.tokens.repository import arrow.core.Either import arrow.core.getOrElse import com.tangem.domain.core.error.DataError -import com.tangem.domain.tokens.model.CryptoCurrencyAddress import com.tangem.domain.core.lce.LceFlow import com.tangem.domain.core.utils.toLce +import com.tangem.domain.tokens.model.CryptoCurrency +import com.tangem.domain.tokens.model.CryptoCurrencyAddress import com.tangem.domain.tokens.model.Network import com.tangem.domain.tokens.model.NetworkStatus import com.tangem.domain.wallets.models.UserWalletId import kotlinx.coroutines.flow.Flow +import kotlinx.coroutines.flow.channelFlow import kotlinx.coroutines.flow.first import kotlinx.coroutines.flow.map @@ -44,10 +46,38 @@ internal class MockNetworksRepository( } override fun isNeedToCreateAccountWithoutReserve(network: Network) = false + + override fun getNetworkAddressesFlow( + userWalletId: UserWalletId, + network: Network, + ): Flow> = channelFlow { + send(emptyList()) + } + + override fun getNetworkAddressesFlow(userWalletId: UserWalletId): Flow> = channelFlow { + send(emptyList()) + } + override suspend fun getNetworkAddresses( userWalletId: UserWalletId, network: Network, ): List { return emptyList() } + + override suspend fun getNetworkAddresses(userWalletId: UserWalletId): List { + return emptyList() + } + + override suspend fun getNetworkAddress( + userWalletId: UserWalletId, + currency: CryptoCurrency, + ): CryptoCurrencyAddress = CryptoCurrencyAddress(currency, "") + + override fun getNetworkAddressFlow( + userWalletId: UserWalletId, + currency: CryptoCurrency, + ): Flow = channelFlow { + send(CryptoCurrencyAddress(currency, "")) + } } \ No newline at end of file diff --git a/domain/tokens/src/test/kotlin/com/tangem/domain/tokens/repository/MockStakingRepository.kt b/domain/tokens/src/test/kotlin/com/tangem/domain/tokens/repository/MockStakingRepository.kt new file mode 100644 index 0000000000..ad8a88a0fd --- /dev/null +++ b/domain/tokens/src/test/kotlin/com/tangem/domain/tokens/repository/MockStakingRepository.kt @@ -0,0 +1,232 @@ +package com.tangem.domain.tokens.repository + +import com.tangem.domain.core.lce.LceFlow +import com.tangem.domain.core.lce.lceFlow +import com.tangem.domain.staking.model.* +import com.tangem.domain.staking.model.stakekit.action.StakingAction +import com.tangem.domain.staking.model.stakekit.action.StakingActionStatus +import com.tangem.domain.staking.model.stakekit.action.StakingActionType +import com.tangem.domain.staking.model.stakekit.* +import com.tangem.domain.staking.model.stakekit.transaction.* +import com.tangem.domain.staking.repositories.StakingRepository +import com.tangem.domain.tokens.model.CryptoCurrency +import com.tangem.domain.tokens.model.CryptoCurrencyAddress +import com.tangem.domain.tokens.model.Network +import com.tangem.domain.wallets.models.UserWalletId +import kotlinx.coroutines.flow.Flow +import kotlinx.coroutines.flow.channelFlow +import org.joda.time.DateTime +import java.math.BigDecimal + +class MockStakingRepository : StakingRepository { + override fun isStakingSupported(currencyId: String): Boolean = true + + override suspend fun fetchEnabledYields(refresh: Boolean) { + /* no-op */ + } + + override suspend fun getEntryInfo(cryptoCurrencyId: CryptoCurrency.ID, symbol: String): StakingEntryInfo = + StakingEntryInfo( + interestRate = 1.toBigDecimal(), + periodInDays = 2, + tokenSymbol = "SOL", + ) + + override suspend fun getYield(cryptoCurrencyId: CryptoCurrency.ID, symbol: String): Yield = Yield( + id = "1", + token = Token( + name = "Solana", + network = NetworkType.SOLANA, + symbol = "SOL", + decimals = 18, + address = null, + coinGeckoId = "solana", + logoURI = null, + isPoints = null, + ), + tokens = listOf(), + args = Yield.Args( + enter = Yield.Args.Enter( + addresses = Yield.Args.Enter.Addresses( + address = AddressArgument( + required = false, + network = null, + minimum = null, + maximum = null, + ), + additionalAddresses = mapOf(), + ), + args = mapOf(), + ), + exit = null, + ), + status = Yield.Status(enter = false, exit = null), + apy = 1.toBigDecimal(), + rewardRate = 2.3, + rewardType = Yield.RewardType.APR, + metadata = Yield.Metadata( + name = "Yield", + logoUri = "", + description = "", + documentation = null, + gasFeeToken = Token( + name = "Solana", + network = NetworkType.SOLANA, + symbol = "SOL", + decimals = 18, + address = null, + coinGeckoId = null, + logoURI = null, + isPoints = null, + ), + token = Token( + name = "Solana", + network = NetworkType.SOLANA, + symbol = "SOL", + decimals = 18, + address = null, + coinGeckoId = null, + logoURI = null, + isPoints = null, + ), + tokens = listOf(), + type = "auto", + rewardSchedule = "1", + cooldownPeriod = Yield.Metadata.Period(days = 1), + warmupPeriod = Yield.Metadata.Period(days = 1), + rewardClaiming = "1", + defaultValidator = null, + minimumStake = null, + supportsMultipleValidators = false, + revshare = Yield.Metadata.Enabled(enabled = false), + fee = Yield.Metadata.Enabled(enabled = false), + ), + validators = listOf(), + isAvailable = false, + ) + + override suspend fun getStakingAvailabilityForActions( + cryptoCurrencyId: CryptoCurrency.ID, + symbol: String, + ): StakingAvailability = StakingAvailability.Unavailable + + override suspend fun fetchSingleYieldBalance( + userWalletId: UserWalletId, + address: CryptoCurrencyAddress, + refresh: Boolean, + ) { + /* no-op */ + } + + override fun getSingleYieldBalanceFlow( + userWalletId: UserWalletId, + address: CryptoCurrencyAddress, + ): Flow = channelFlow { + send(YieldBalance.Error) + } + + override suspend fun getSingleYieldBalanceSync( + userWalletId: UserWalletId, + address: CryptoCurrencyAddress, + ): YieldBalance = YieldBalance.Error + + override suspend fun fetchMultiYieldBalance( + userWalletId: UserWalletId, + addresses: List, + refresh: Boolean, + ) { + /* no-op */ + } + + override fun getMultiYieldBalanceFlow( + userWalletId: UserWalletId, + addresses: List, + ): Flow = channelFlow { + send( + YieldBalanceList.Data( + balances = listOf(YieldBalance.Error), + ), + ) + } + + override fun getMultiYieldBalanceLce( + userWalletId: UserWalletId, + addresses: List, + ): LceFlow = lceFlow { + send( + YieldBalanceList.Data( + balances = listOf(YieldBalance.Error), + ), + ) + } + + override suspend fun getMultiYieldBalanceSync( + userWalletId: UserWalletId, + addresses: List, + ): YieldBalanceList = YieldBalanceList.Data( + balances = listOf(YieldBalance.Error), + ) + + override suspend fun createAction(params: ActionParams): StakingAction { + return StakingAction( + id = "quis", + integrationId = "persequeris", + status = StakingActionStatus.PROCESSING, + type = StakingActionType.CLAIM_REWARDS, + currentStepIndex = 8701, + amount = BigDecimal.ZERO, + validatorAddress = null, + validatorAddresses = listOf(), + transactions = listOf(), + createdAt = DateTime.now(), + ) + } + + override suspend fun estimateGas(params: ActionParams): StakingGasEstimate { + return StakingGasEstimate( + amount = BigDecimal(0.0001), + token = Token( + name = "Solana", + network = NetworkType.SOLANA, + symbol = "SOL", + decimals = 18, + address = null, + coinGeckoId = "solana", + logoURI = null, + isPoints = null, + ), + gasLimit = null, + ) + } + + override suspend fun constructTransaction(transactionId: String): StakingTransaction = StakingTransaction( + id = "id", + network = NetworkType.SOLANA, + status = StakingTransactionStatus.SIGNED, + type = StakingTransactionType.FREEZE_ENERGY, + hash = null, + signedTransaction = null, + unsignedTransaction = null, + stepIndex = 9368, + error = null, + gasEstimate = null, + stakeId = null, + explorerUrl = null, + ledgerHwAppId = null, + isMessage = false, + ) + + override suspend fun submitHash(transactionId: String, transactionHash: String) { + /* no-op */ + } + + override suspend fun storeUnsubmittedHash(unsubmittedTransactionMetadata: UnsubmittedTransactionMetadata) { + /* no-op */ + } + + override suspend fun sendUnsubmittedHashes() { + /* no-op */ + } + + override fun isStakeMoreAvailable(networkId: Network.ID): Boolean = true +} \ No newline at end of file diff --git a/domain/transaction/build.gradle.kts b/domain/transaction/build.gradle.kts index d4014c6f47..b54aeca082 100644 --- a/domain/transaction/build.gradle.kts +++ b/domain/transaction/build.gradle.kts @@ -28,6 +28,7 @@ dependencies { implementation(projects.domain.wallets.models) implementation(projects.domain.tokens) implementation(projects.domain.tokens.models) + implementation(projects.domain.transaction.models) implementation(projects.domain.demo) implementation(projects.domain.card) } \ No newline at end of file diff --git a/domain/transaction/models/src/main/kotlin/com/tangem/domain/transaction/models/TransactionType.kt b/domain/transaction/models/src/main/kotlin/com/tangem/domain/transaction/models/TransactionType.kt new file mode 100644 index 0000000000..fdd9a7ec17 --- /dev/null +++ b/domain/transaction/models/src/main/kotlin/com/tangem/domain/transaction/models/TransactionType.kt @@ -0,0 +1,5 @@ +package com.tangem.domain.transaction.models + +enum class TransactionType { + APPROVE, +} \ No newline at end of file diff --git a/domain/transaction/src/main/java/com/tangem/domain/transaction/TransactionRepository.kt b/domain/transaction/src/main/java/com/tangem/domain/transaction/TransactionRepository.kt index 181ce66767..3fb7cbf0b5 100644 --- a/domain/transaction/src/main/java/com/tangem/domain/transaction/TransactionRepository.kt +++ b/domain/transaction/src/main/java/com/tangem/domain/transaction/TransactionRepository.kt @@ -4,7 +4,9 @@ import com.tangem.blockchain.common.* import com.tangem.blockchain.common.transaction.Fee import com.tangem.blockchain.common.transaction.TransactionSendResult import com.tangem.domain.tokens.model.Network +import com.tangem.domain.transaction.models.TransactionType import com.tangem.domain.wallets.models.UserWalletId +import java.math.BigInteger interface TransactionRepository { @@ -18,7 +20,7 @@ interface TransactionRepository { network: Network, txExtras: TransactionExtras?, hash: String?, - ): TransactionData? + ): TransactionData.Uncompiled? @Suppress("LongParameterList") suspend fun validateTransaction( @@ -39,4 +41,12 @@ interface TransactionRepository { userWalletId: UserWalletId, network: Network, ): com.tangem.blockchain.extensions.Result + + fun createTransactionDataExtras( + data: String, + network: Network, + transactionType: TransactionType, + nonce: BigInteger?, + gasLimit: BigInteger?, + ): TransactionExtras } \ No newline at end of file diff --git a/domain/transaction/src/main/java/com/tangem/domain/transaction/error/FeeErrorsMapper.kt b/domain/transaction/src/main/java/com/tangem/domain/transaction/error/FeeErrorsMapper.kt new file mode 100644 index 0000000000..718ccb6f9b --- /dev/null +++ b/domain/transaction/src/main/java/com/tangem/domain/transaction/error/FeeErrorsMapper.kt @@ -0,0 +1,13 @@ +package com.tangem.domain.transaction.error + +import com.tangem.blockchain.common.BlockchainSdkError +import com.tangem.blockchain.extensions.Result + +fun Result.Failure.mapToFeeError(): GetFeeError { + return when (this.error) { + is BlockchainSdkError.Tron.AccountActivationError -> { + GetFeeError.BlockchainErrors.TronActivationError + } + else -> GetFeeError.DataError(this.error) + } +} \ No newline at end of file diff --git a/domain/transaction/src/main/java/com/tangem/domain/transaction/error/GetFeeError.kt b/domain/transaction/src/main/java/com/tangem/domain/transaction/error/GetFeeError.kt index f2e3f7f60f..bc57770c0f 100644 --- a/domain/transaction/src/main/java/com/tangem/domain/transaction/error/GetFeeError.kt +++ b/domain/transaction/src/main/java/com/tangem/domain/transaction/error/GetFeeError.kt @@ -2,5 +2,9 @@ package com.tangem.domain.transaction.error sealed class GetFeeError { data class DataError(val cause: Throwable?) : GetFeeError() - object UnknownError : GetFeeError() + data object UnknownError : GetFeeError() + + sealed class BlockchainErrors : GetFeeError() { + data object TronActivationError : BlockchainErrors() + } } \ No newline at end of file diff --git a/domain/transaction/src/main/java/com/tangem/domain/transaction/usecase/CreateTransactionDataExtrasUseCase.kt b/domain/transaction/src/main/java/com/tangem/domain/transaction/usecase/CreateTransactionDataExtrasUseCase.kt new file mode 100644 index 0000000000..52d686e403 --- /dev/null +++ b/domain/transaction/src/main/java/com/tangem/domain/transaction/usecase/CreateTransactionDataExtrasUseCase.kt @@ -0,0 +1,30 @@ +package com.tangem.domain.transaction.usecase + +import arrow.core.Either +import com.tangem.domain.tokens.model.Network +import com.tangem.domain.transaction.TransactionRepository +import com.tangem.domain.transaction.models.TransactionType +import java.math.BigInteger + +class CreateTransactionDataExtrasUseCase( + private val transactionRepository: TransactionRepository, +) { + + operator fun invoke( + data: String, + network: Network, + transactionType: TransactionType, + gasLimit: BigInteger? = null, + nonce: BigInteger? = null, + ) = Either.catch { + requireNotNull( + transactionRepository.createTransactionDataExtras( + data = data, + network = network, + transactionType = transactionType, + nonce = nonce, + gasLimit = gasLimit, + ), + ) { "Failed to create transaction" } + } +} \ No newline at end of file diff --git a/domain/transaction/src/main/java/com/tangem/domain/transaction/usecase/EstimateFeeUseCase.kt b/domain/transaction/src/main/java/com/tangem/domain/transaction/usecase/EstimateFeeUseCase.kt index a33088d612..134cb9f3f5 100644 --- a/domain/transaction/src/main/java/com/tangem/domain/transaction/usecase/EstimateFeeUseCase.kt +++ b/domain/transaction/src/main/java/com/tangem/domain/transaction/usecase/EstimateFeeUseCase.kt @@ -8,14 +8,15 @@ import com.tangem.blockchain.common.AmountType import com.tangem.blockchain.common.Token import com.tangem.blockchain.common.transaction.TransactionFee import com.tangem.blockchain.extensions.Result +import com.tangem.domain.demo.DemoConfig +import com.tangem.domain.demo.DemoTransactionSender import com.tangem.domain.tokens.model.CryptoCurrency import com.tangem.domain.transaction.error.GetFeeError +import com.tangem.domain.transaction.error.mapToFeeError import com.tangem.domain.walletmanager.WalletManagersFacade -import com.tangem.domain.wallets.models.UserWalletId -import com.tangem.utils.coroutines.CoroutineDispatcherProvider +import com.tangem.domain.wallets.models.UserWallet import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.flow -import kotlinx.coroutines.flow.flowOn import java.math.BigDecimal /** @@ -23,27 +24,46 @@ import java.math.BigDecimal */ class EstimateFeeUseCase( private val walletManagersFacade: WalletManagersFacade, - private val dispatcher: CoroutineDispatcherProvider, + private val demoConfig: DemoConfig, ) { suspend operator fun invoke( amount: BigDecimal, - userWalletId: UserWalletId, + userWallet: UserWallet, cryptoCurrency: CryptoCurrency, ): Flow> { return flow { - val result = walletManagersFacade.estimateFee( - amount = convertCryptoCurrencyToAmount(cryptoCurrency, amount), - userWalletId = userWalletId, - network = cryptoCurrency.network, - ) + val amountData = convertCryptoCurrencyToAmount(cryptoCurrency, amount) + val result = if (demoConfig.isDemoCardId(userWallet.scanResponse.card.cardId)) { + demoTransactionSender(userWallet, cryptoCurrency).estimateFee( + amount = amountData, + destination = "", + ) + } else { + walletManagersFacade.estimateFee( + amount = amountData, + userWalletId = userWallet.walletId, + network = cryptoCurrency.network, + ) + } val maybeFee = when (result) { is Result.Success -> result.data.right() - is Result.Failure -> GetFeeError.DataError(result.error).left() + is Result.Failure -> result.mapToFeeError().left() null -> GetFeeError.UnknownError.left() } emit(maybeFee) - }.flowOn(dispatcher.io) + } + } + + private suspend fun demoTransactionSender( + userWallet: UserWallet, + cryptoCurrency: CryptoCurrency, + ): DemoTransactionSender { + return DemoTransactionSender( + walletManagersFacade + .getOrCreateWalletManager(userWallet.walletId, cryptoCurrency.network) + ?: error("WalletManager is null"), + ) } private fun convertCryptoCurrencyToAmount(cryptoCurrency: CryptoCurrency, amount: BigDecimal) = Amount( diff --git a/domain/transaction/src/main/java/com/tangem/domain/transaction/usecase/GetFeeUseCase.kt b/domain/transaction/src/main/java/com/tangem/domain/transaction/usecase/GetFeeUseCase.kt index 2f113a02a0..548a43ab6c 100644 --- a/domain/transaction/src/main/java/com/tangem/domain/transaction/usecase/GetFeeUseCase.kt +++ b/domain/transaction/src/main/java/com/tangem/domain/transaction/usecase/GetFeeUseCase.kt @@ -10,6 +10,7 @@ import com.tangem.domain.demo.DemoConfig import com.tangem.domain.demo.DemoTransactionSender import com.tangem.domain.tokens.model.CryptoCurrency import com.tangem.domain.transaction.error.GetFeeError +import com.tangem.domain.transaction.error.mapToFeeError import com.tangem.domain.walletmanager.WalletManagersFacade import com.tangem.domain.wallets.models.UserWallet import java.math.BigDecimal @@ -47,7 +48,7 @@ class GetFeeUseCase( val maybeFee = when (result) { is Result.Success -> result.data - is Result.Failure -> raise(GetFeeError.DataError(result.error)) + is Result.Failure -> raise(result.mapToFeeError()) } maybeFee }, diff --git a/domain/transaction/src/main/java/com/tangem/domain/transaction/usecase/SendTransactionUseCase.kt b/domain/transaction/src/main/java/com/tangem/domain/transaction/usecase/SendTransactionUseCase.kt index faccbea7e4..96b5db01fa 100644 --- a/domain/transaction/src/main/java/com/tangem/domain/transaction/usecase/SendTransactionUseCase.kt +++ b/domain/transaction/src/main/java/com/tangem/domain/transaction/usecase/SendTransactionUseCase.kt @@ -14,6 +14,7 @@ import com.tangem.core.ui.extensions.resourceReference import com.tangem.core.ui.extensions.wrappedList import com.tangem.domain.card.repository.CardSdkConfigRepository import com.tangem.domain.common.TapWorkarounds.isStart2Coin +import com.tangem.domain.common.TapWorkarounds.isTangemTwins import com.tangem.domain.demo.DemoConfig import com.tangem.domain.demo.DemoTransactionSender import com.tangem.domain.tokens.model.Network @@ -37,7 +38,10 @@ class SendTransactionUseCase( userWallet: UserWallet, network: Network, ): Either { - val signer = cardSdkConfigRepository.getCommonSigner(cardId = null) + val card = userWallet.scanResponse.card + val isCardNotBackedUp = card.backupStatus?.isActive != true && !card.isTangemTwins + + val signer = cardSdkConfigRepository.getCommonSigner(cardId = card.cardId.takeIf { isCardNotBackedUp }) val linkedTerminal = cardSdkConfigRepository.isLinkedTerminal() if (userWallet.scanResponse.card.isStart2Coin) { @@ -105,22 +109,7 @@ class SendTransactionUseCase( } val error = result.error as? BlockchainSdkError ?: return SendTransactionError.UnknownError() return when (error) { - is BlockchainSdkError.WrappedTangemError -> { - if (error.code == USER_CANCELLED_ERROR_CODE) { - SendTransactionError.UserCancelledError - } else { - val tangemError = error.tangemError - if (tangemError is TangemSdkError) { - val resource = tangemError.localizedDescriptionRes() - val resId = resource.resId ?: R.string.common_unknown_error - val resArgs = resource.args.map { it.value } - val textReference = resourceReference(resId, wrappedList(resArgs)) - SendTransactionError.TangemSdkError(tangemError.code, textReference) - } else { - SendTransactionError.BlockchainSdkError(error.code, tangemError.customMessage) - } - } - } + is BlockchainSdkError.WrappedTangemError -> parseWrappedError(error) is BlockchainSdkError.CreateAccountUnderfunded -> { val minAmount = error.minReserve val minValue = minAmount.value?.toFormattedString(minAmount.decimals).orEmpty() @@ -134,4 +123,26 @@ class SendTransactionUseCase( } } } + + private fun parseWrappedError(error: BlockchainSdkError.WrappedTangemError): SendTransactionError { + return if (error.code == USER_CANCELLED_ERROR_CODE) { + SendTransactionError.UserCancelledError + } else { + when (val tangemError = error.tangemError) { + is TangemSdkError -> { + val resource = tangemError.localizedDescriptionRes() + val resId = resource.resId ?: R.string.common_unknown_error + val resArgs = resource.args.map { it.value } + val textReference = resourceReference(resId, wrappedList(resArgs)) + SendTransactionError.TangemSdkError(tangemError.code, textReference) + } + is BlockchainSdkError.WrappedTangemError -> { + parseWrappedError(tangemError) // todo remove when sdk errors are revised + } + else -> { + SendTransactionError.BlockchainSdkError(error.code, tangemError.customMessage) + } + } + } + } } \ No newline at end of file diff --git a/domain/transaction/src/main/java/com/tangem/domain/transaction/usecase/ValidateTransactionUseCase.kt b/domain/transaction/src/main/java/com/tangem/domain/transaction/usecase/ValidateTransactionUseCase.kt index 8be00045ba..61b2f26817 100644 --- a/domain/transaction/src/main/java/com/tangem/domain/transaction/usecase/ValidateTransactionUseCase.kt +++ b/domain/transaction/src/main/java/com/tangem/domain/transaction/usecase/ValidateTransactionUseCase.kt @@ -16,7 +16,7 @@ class ValidateTransactionUseCase( @Suppress("LongParameterList") suspend operator fun invoke( amount: Amount, - fee: Fee, + fee: Fee?, memo: String?, destination: String, userWalletId: UserWalletId, diff --git a/domain/txhistory/src/main/kotlin/com/tangem/domain/txhistory/usecase/GetExplorerTransactionUrlUseCase.kt b/domain/txhistory/src/main/kotlin/com/tangem/domain/txhistory/usecase/GetExplorerTransactionUrlUseCase.kt index cedb309901..991475bef2 100644 --- a/domain/txhistory/src/main/kotlin/com/tangem/domain/txhistory/usecase/GetExplorerTransactionUrlUseCase.kt +++ b/domain/txhistory/src/main/kotlin/com/tangem/domain/txhistory/usecase/GetExplorerTransactionUrlUseCase.kt @@ -11,7 +11,6 @@ import com.tangem.domain.wallets.models.UserWalletId class GetExplorerTransactionUrlUseCase( private val repository: TxHistoryRepository, ) { - @Deprecated("Replace with invoke [UserWalletId, Network]") operator fun invoke(txHash: String, networkId: Network.ID): Either { return either { catch( diff --git a/domain/wallets/build.gradle.kts b/domain/wallets/build.gradle.kts index bd175a01fa..9972fdc9c7 100644 --- a/domain/wallets/build.gradle.kts +++ b/domain/wallets/build.gradle.kts @@ -16,6 +16,7 @@ dependencies { // endregion // region Domain modules + api(projects.domain.core) implementation(projects.domain.legacy) implementation(projects.libs.blockchainSdk) implementation(projects.domain.models) @@ -28,9 +29,4 @@ dependencies { implementation(deps.tangem.blockchain) // android-library implementation(deps.tangem.card.core) // endregion - - // region Other libraries - implementation(deps.arrow.core) - implementation(deps.kotlin.coroutines) - // endregion } \ No newline at end of file diff --git a/domain/wallets/models/build.gradle.kts b/domain/wallets/models/build.gradle.kts index 537d724d84..1b3ce4dfaf 100644 --- a/domain/wallets/models/build.gradle.kts +++ b/domain/wallets/models/build.gradle.kts @@ -1,5 +1,6 @@ plugins { alias(deps.plugins.kotlin.jvm) + alias(deps.plugins.kotlin.serialization) id("configuration") } @@ -11,4 +12,8 @@ dependencies { // region Domain modules implementation(project(":domain:models")) // endregion + + // region Other libraries + implementation(deps.kotlin.serialization) + // endregion } \ No newline at end of file diff --git a/domain/wallets/models/src/main/java/com/tangem/domain/wallets/models/UserWalletId.kt b/domain/wallets/models/src/main/java/com/tangem/domain/wallets/models/UserWalletId.kt index 970ee3ad9f..4ea8ab824c 100644 --- a/domain/wallets/models/src/main/java/com/tangem/domain/wallets/models/UserWalletId.kt +++ b/domain/wallets/models/src/main/java/com/tangem/domain/wallets/models/UserWalletId.kt @@ -2,9 +2,10 @@ package com.tangem.domain.wallets.models import com.tangem.common.extensions.hexToBytes import com.tangem.common.extensions.toHexString -import java.io.Serializable +import kotlinx.serialization.Serializable -data class UserWalletId(val stringValue: String) : Serializable { +@Serializable +data class UserWalletId(val stringValue: String) { val value = stringValue.hexToBytes() diff --git a/domain/wallets/src/main/java/com/tangem/domain/wallets/legacy/UserWalletsListManager.kt b/domain/wallets/src/main/java/com/tangem/domain/wallets/legacy/UserWalletsListManager.kt index 9b63847e73..bd117a8c8e 100644 --- a/domain/wallets/src/main/java/com/tangem/domain/wallets/legacy/UserWalletsListManager.kt +++ b/domain/wallets/src/main/java/com/tangem/domain/wallets/legacy/UserWalletsListManager.kt @@ -16,12 +16,14 @@ interface UserWalletsListManager { val userWallets: Flow> /** [Flow] with selected [UserWallet] updates */ + @Deprecated("You should provide the selected wallet via routing parameters due to the scalability of the features") val selectedUserWallet: Flow /** [List] with all saved [UserWallet]s updates */ val userWalletsSync: List /** Selected [UserWallet] */ + @Deprecated("You should provide the selected wallet via routing parameters due to the scalability of the features") val selectedUserWalletSync: UserWallet? /** Indicates that the [UserWalletsListManager] contains at least one saved [UserWallet] */ diff --git a/domain/wallets/src/main/java/com/tangem/domain/wallets/models/UpdateWalletError.kt b/domain/wallets/src/main/java/com/tangem/domain/wallets/models/UpdateWalletError.kt index b15ec332d1..ae3c5bba65 100644 --- a/domain/wallets/src/main/java/com/tangem/domain/wallets/models/UpdateWalletError.kt +++ b/domain/wallets/src/main/java/com/tangem/domain/wallets/models/UpdateWalletError.kt @@ -2,7 +2,7 @@ package com.tangem.domain.wallets.models sealed interface UpdateWalletError { - data object DataError : UpdateWalletError - data object NameAlreadyExists : UpdateWalletError + + data class DataError(val cause: Throwable) : UpdateWalletError } \ No newline at end of file diff --git a/domain/wallets/src/main/java/com/tangem/domain/wallets/usecase/GetSelectedWalletSyncUseCase.kt b/domain/wallets/src/main/java/com/tangem/domain/wallets/usecase/GetSelectedWalletSyncUseCase.kt index e9f51327a6..ebcd1378d7 100644 --- a/domain/wallets/src/main/java/com/tangem/domain/wallets/usecase/GetSelectedWalletSyncUseCase.kt +++ b/domain/wallets/src/main/java/com/tangem/domain/wallets/usecase/GetSelectedWalletSyncUseCase.kt @@ -17,6 +17,7 @@ import com.tangem.domain.wallets.models.UserWallet */ class GetSelectedWalletSyncUseCase(private val userWalletsListManager: UserWalletsListManager) { + @Deprecated("You should provide the selected wallet via routing parameters due to the scalability of the features") operator fun invoke(): Either { return either { ensureNotNull( diff --git a/domain/wallets/src/main/java/com/tangem/domain/wallets/usecase/GetSelectedWalletUseCase.kt b/domain/wallets/src/main/java/com/tangem/domain/wallets/usecase/GetSelectedWalletUseCase.kt index bda3c953ee..4751238a0f 100644 --- a/domain/wallets/src/main/java/com/tangem/domain/wallets/usecase/GetSelectedWalletUseCase.kt +++ b/domain/wallets/src/main/java/com/tangem/domain/wallets/usecase/GetSelectedWalletUseCase.kt @@ -16,6 +16,7 @@ import kotlinx.coroutines.flow.Flow */ class GetSelectedWalletUseCase(private val userWalletsListManager: UserWalletsListManager) { + @Deprecated("You should provide the selected wallet via routing parameters due to the scalability of the features") operator fun invoke(): Either> { return either { userWalletsListManager.selectedUserWallet diff --git a/domain/wallets/src/main/java/com/tangem/domain/wallets/usecase/GetUserWalletUseCase.kt b/domain/wallets/src/main/java/com/tangem/domain/wallets/usecase/GetUserWalletUseCase.kt index 9323fd5423..a8b14fe269 100644 --- a/domain/wallets/src/main/java/com/tangem/domain/wallets/usecase/GetUserWalletUseCase.kt +++ b/domain/wallets/src/main/java/com/tangem/domain/wallets/usecase/GetUserWalletUseCase.kt @@ -1,12 +1,17 @@ package com.tangem.domain.wallets.usecase import arrow.core.Either +import arrow.core.left import arrow.core.raise.either import arrow.core.raise.ensureNotNull +import arrow.core.right +import com.tangem.domain.core.utils.EitherFlow import com.tangem.domain.wallets.legacy.UserWalletsListManager import com.tangem.domain.wallets.models.GetUserWalletError import com.tangem.domain.wallets.models.UserWallet import com.tangem.domain.wallets.models.UserWalletId +import kotlinx.coroutines.ExperimentalCoroutinesApi +import kotlinx.coroutines.flow.transformLatest class GetUserWalletUseCase(private val userWalletsListManager: UserWalletsListManager) { @@ -17,4 +22,13 @@ class GetUserWalletUseCase(private val userWalletsListManager: UserWalletsListMa raise(GetUserWalletError.UserWalletNotFound) } } + + @OptIn(ExperimentalCoroutinesApi::class) + fun invokeFlow(userWalletId: UserWalletId): EitherFlow { + return userWalletsListManager.userWallets.transformLatest { userWallets -> + userWallets.firstOrNull { it.walletId == userWalletId } + ?.let { emit(it.right()) } + ?: emit(GetUserWalletError.UserWalletNotFound.left()) + } + } } \ No newline at end of file diff --git a/domain/wallets/src/main/java/com/tangem/domain/wallets/usecase/RenameWalletUseCase.kt b/domain/wallets/src/main/java/com/tangem/domain/wallets/usecase/RenameWalletUseCase.kt index e03da26f6b..ff568c6794 100644 --- a/domain/wallets/src/main/java/com/tangem/domain/wallets/usecase/RenameWalletUseCase.kt +++ b/domain/wallets/src/main/java/com/tangem/domain/wallets/usecase/RenameWalletUseCase.kt @@ -1,36 +1,39 @@ package com.tangem.domain.wallets.usecase import arrow.core.Either -import arrow.core.left import arrow.core.raise.either -import arrow.core.right -import com.tangem.common.doOnFailure -import com.tangem.common.doOnSuccess +import arrow.core.raise.ensure +import com.tangem.common.CompletionResult import com.tangem.domain.wallets.legacy.UserWalletsListManager import com.tangem.domain.wallets.models.UpdateWalletError import com.tangem.domain.wallets.models.UserWallet import com.tangem.domain.wallets.models.UserWalletId +import com.tangem.utils.coroutines.CoroutineDispatcherProvider +import kotlinx.coroutines.withContext /** * Use case for rename user wallet * * @property userWalletsListManager user wallets list manager */ -class RenameWalletUseCase(private val userWalletsListManager: UserWalletsListManager) { +class RenameWalletUseCase( + private val userWalletsListManager: UserWalletsListManager, + private val dispatchers: CoroutineDispatcherProvider, +) { - suspend operator fun invoke(userWalletId: UserWalletId, name: String): Either { - val existingNames = userWalletsListManager.userWalletsSync + suspend operator fun invoke(userWalletId: UserWalletId, name: String): Either = + withContext(dispatchers.io) { + either { + val existingNames = userWalletsListManager.userWalletsSync - if (existingNames.any { it.name == name && it.walletId != userWalletId }) { - return UpdateWalletError.NameAlreadyExists.left() + ensure(existingNames.none { it.name == name && it.walletId != userWalletId }) { + UpdateWalletError.NameAlreadyExists + } + + when (val result = userWalletsListManager.update(userWalletId) { it.copy(name = name) }) { + is CompletionResult.Failure -> raise(UpdateWalletError.DataError(result.error)) + is CompletionResult.Success -> result.data + } + } } - - return either { - userWalletsListManager.update(userWalletId) { it.copy(name = name) } - .doOnSuccess { return it.right() } - .doOnFailure { return UpdateWalletError.DataError.left() } - - return UpdateWalletError.DataError.left() - } - } } \ No newline at end of file diff --git a/domain/wallets/src/main/java/com/tangem/domain/wallets/usecase/UpdateWalletUseCase.kt b/domain/wallets/src/main/java/com/tangem/domain/wallets/usecase/UpdateWalletUseCase.kt index b060418b2e..5e9f4eb656 100644 --- a/domain/wallets/src/main/java/com/tangem/domain/wallets/usecase/UpdateWalletUseCase.kt +++ b/domain/wallets/src/main/java/com/tangem/domain/wallets/usecase/UpdateWalletUseCase.kt @@ -1,11 +1,8 @@ package com.tangem.domain.wallets.usecase import arrow.core.Either -import arrow.core.left import arrow.core.raise.either -import arrow.core.right -import com.tangem.common.doOnFailure -import com.tangem.common.doOnSuccess +import com.tangem.common.CompletionResult import com.tangem.domain.wallets.legacy.UserWalletsListManager import com.tangem.domain.wallets.models.UpdateWalletError import com.tangem.domain.wallets.models.UserWallet @@ -23,13 +20,10 @@ class UpdateWalletUseCase(private val userWalletsListManager: UserWalletsListMan suspend operator fun invoke( userWalletId: UserWalletId, update: suspend (UserWallet) -> UserWallet, - ): Either { - return either { - userWalletsListManager.update(userWalletId, update) - .doOnSuccess { return it.right() } - .doOnFailure { return UpdateWalletError.DataError.left() } - - return UpdateWalletError.DataError.left() + ): Either = either { + when (val result = userWalletsListManager.update(userWalletId, update)) { + is CompletionResult.Failure -> raise(UpdateWalletError.DataError(result.error)) + is CompletionResult.Success -> result.data } } } \ No newline at end of file diff --git a/fastlane/Fastfile b/fastlane/Fastfile index f18a200057..d1cfaf3f7e 100644 --- a/fastlane/Fastfile +++ b/fastlane/Fastfile @@ -59,18 +59,20 @@ platform :android do "android.injected.signing.store.password" => options[:store_password], "android.injected.signing.key.alias" => options[:key_alias], "android.injected.signing.key.password" => options[:key_password], - }) - gradle( - task: "assemble", - build_type: "Release", - properties: { - 'versionCode' => options[:versionCode], - 'versionName' => options[:versionName], - "android.injected.signing.store.file" => options[:keystore], - "android.injected.signing.store.password" => options[:store_password], - "android.injected.signing.key.alias" => options[:key_alias], - "android.injected.signing.key.password" => options[:key_password], - }) + } + ) + gradle( + task: "assemble", + build_type: "Release", + properties: { + 'versionCode' => options[:versionCode], + 'versionName' => options[:versionName], + "android.injected.signing.store.file" => options[:keystore], + "android.injected.signing.store.password" => options[:store_password], + "android.injected.signing.key.alias" => options[:key_alias], + "android.injected.signing.key.password" => options[:key_password], + } + ) end desc "Submit a new Beta Build to Firebase App Distribution" @@ -81,4 +83,20 @@ platform :android do groups: options[:groups]) end + desc "Publish internal and external builds to Firebase App Distribution" + lane :publishToFirebase do |options| + gradle( + task: "clean assemble", + build_type: "Internal", + properties: { + 'versionCode' => ENV['versionCode'], + 'versionName' => ENV['versionName'], + } + ) + firebase_app_distribution( + app: ENV['app_id_internal'], + apk_path: ENV['apk_path_internal'], + groups: ENV['groups'] + ) + end end diff --git a/fastlane/README.md b/fastlane/README.md index 9df376cd1d..44d6ef904a 100644 --- a/fastlane/README.md +++ b/fastlane/README.md @@ -37,7 +37,7 @@ Build a signed release APK [bundle exec] fastlane android build ``` -Build internal and release APKs +Build external and release APKs ### android beta @@ -47,6 +47,16 @@ Build internal and release APKs Submit a new Beta Build to Firebase App Distribution +### android publishToFirebase + +```sh +[bundle exec] fastlane android publishToFirebase +``` + +Publish internal and external builds to Firebase App Distribution + + + ---- This README.md is auto-generated and will be re-generated every time [_fastlane_](https://fastlane.tools) is run. diff --git a/features/details/api/build.gradle.kts b/features/details/api/build.gradle.kts index 5010f64d85..ce267fe5d1 100644 --- a/features/details/api/build.gradle.kts +++ b/features/details/api/build.gradle.kts @@ -15,7 +15,5 @@ dependencies { /* Project - Core */ implementation(projects.core.decompose) - - /* AndroidX */ - implementation(deps.androidx.fragment.ktx) + implementation(projects.core.ui) } \ No newline at end of file diff --git a/features/details/api/src/main/kotlin/com/tangem/features/details/DetailsEntryPoint.kt b/features/details/api/src/main/kotlin/com/tangem/features/details/DetailsEntryPoint.kt deleted file mode 100644 index d3ac9fe6f7..0000000000 --- a/features/details/api/src/main/kotlin/com/tangem/features/details/DetailsEntryPoint.kt +++ /dev/null @@ -1,13 +0,0 @@ -package com.tangem.features.details - -import androidx.fragment.app.Fragment - -interface DetailsEntryPoint { - - fun entryFragment(): Fragment - - companion object { - - const val USER_WALLET_ID_KEY = "user_wallet_id" - } -} \ No newline at end of file diff --git a/features/details/api/src/main/kotlin/com/tangem/features/details/component/DetailsComponent.kt b/features/details/api/src/main/kotlin/com/tangem/features/details/component/DetailsComponent.kt new file mode 100644 index 0000000000..f2546ffc26 --- /dev/null +++ b/features/details/api/src/main/kotlin/com/tangem/features/details/component/DetailsComponent.kt @@ -0,0 +1,14 @@ +package com.tangem.features.details.component + +import com.tangem.core.decompose.factory.ComponentFactory +import com.tangem.core.ui.decompose.ComposableContentComponent +import com.tangem.domain.wallets.models.UserWalletId + +interface DetailsComponent : ComposableContentComponent { + + interface Factory : ComponentFactory + + data class Params( + val userWalletId: UserWalletId, + ) +} \ No newline at end of file diff --git a/features/details/api/src/main/kotlin/com/tangem/features/details/component/UserWalletListComponent.kt b/features/details/api/src/main/kotlin/com/tangem/features/details/component/UserWalletListComponent.kt new file mode 100644 index 0000000000..7908aa5ede --- /dev/null +++ b/features/details/api/src/main/kotlin/com/tangem/features/details/component/UserWalletListComponent.kt @@ -0,0 +1,11 @@ +package com.tangem.features.details.component + +import com.tangem.core.decompose.context.AppComponentContext +import com.tangem.core.ui.decompose.ComposableContentComponent + +interface UserWalletListComponent : ComposableContentComponent { + + interface Factory { + fun create(context: AppComponentContext): UserWalletListComponent + } +} \ No newline at end of file diff --git a/features/details/impl/build.gradle.kts b/features/details/impl/build.gradle.kts index 5060249621..82ca657a96 100644 --- a/features/details/impl/build.gradle.kts +++ b/features/details/impl/build.gradle.kts @@ -15,6 +15,7 @@ dependencies { /* Project - API */ implementation(projects.features.details.api) + implementation(projects.features.disclaimer.api) implementation(projects.features.tester.api) /* Project - Core */ @@ -23,13 +24,30 @@ dependencies { implementation(projects.core.featuretoggles) implementation(projects.core.navigation) implementation(projects.core.analytics.models) + implementation(projects.common.routing) /* Project - Domain */ + implementation(projects.domain.models) + implementation(projects.domain.feedback) + implementation(projects.domain.wallets) implementation(projects.domain.wallets.models) + implementation(projects.domain.card) + implementation(projects.domain.tokens) + implementation(projects.domain.tokens.models) + implementation(projects.domain.appCurrency) + implementation(projects.domain.appCurrency.models) + implementation(projects.domain.walletConnect) + implementation(projects.domain.balanceHiding) + implementation(projects.domain.balanceHiding.models) implementation(projects.domain.legacy) + /* SDK */ + // TODO: For TangemError model, should be removed after card domain scanning refactoring + implementation(deps.tangem.card.core) + // For image resolving + implementation(deps.tangem.blockchain) + /* AndroidX */ - implementation(deps.androidx.fragment.ktx) implementation(deps.androidx.activity.compose) implementation(deps.lifecycle.compose) @@ -40,6 +58,7 @@ dependencies { implementation(deps.compose.foundation) implementation(deps.compose.material3) implementation(deps.compose.shimmer) + implementation(deps.compose.coil) /* DI */ implementation(deps.hilt.android) @@ -47,4 +66,5 @@ dependencies { /* Other */ implementation(deps.kotlin.immutable.collections) + implementation(deps.timber) } \ No newline at end of file diff --git a/features/details/impl/src/main/kotlin/com/tangem/features/details/DetailsFragment.kt b/features/details/impl/src/main/kotlin/com/tangem/features/details/DetailsFragment.kt deleted file mode 100644 index 28db59fc3d..0000000000 --- a/features/details/impl/src/main/kotlin/com/tangem/features/details/DetailsFragment.kt +++ /dev/null @@ -1,76 +0,0 @@ -package com.tangem.features.details - -import androidx.compose.runtime.Composable -import androidx.compose.ui.Modifier -import androidx.fragment.app.Fragment -import com.tangem.core.decompose.context.AppComponentContext -import com.tangem.core.decompose.di.RootAppComponentContext -import com.tangem.core.ui.UiDependencies -import com.tangem.core.ui.message.EventMessageEffect -import com.tangem.core.ui.message.EventMessageHandler -import com.tangem.core.ui.screen.ComposeFragment -import com.tangem.features.details.component.DetailsComponent -import com.tangem.features.details.component.preview.PreviewDetailsComponent -import dagger.hilt.android.AndroidEntryPoint -import javax.inject.Inject - -// TODO: Remove after [REDACTED_JIRA] -@AndroidEntryPoint -internal class DetailsFragment : ComposeFragment() { - - @Inject - override lateinit var uiDependencies: UiDependencies - - // @Inject - // internal lateinit var componentFactory: DetailsComponent.Factory - - @Inject - internal lateinit var detailsRouter: DetailsRouter - - @Inject - @RootAppComponentContext - internal lateinit var rootContext: AppComponentContext - - private val component: DetailsComponent by lazy { initComponent() } - - private val messageHandler = EventMessageHandler() - - @Composable - override fun ScreenContent(modifier: Modifier) { - component.View(modifier = modifier) - - EventMessageEffect( - messageHandler = messageHandler, - snackbarHostState = component.snackbarHostState, - ) - } - - private fun initComponent(): DetailsComponent { - // TODO: Uncomment in [REDACTED_JIRA] - // val selectedUserWalletId = arguments?.getString(DetailsEntryPoint.USER_WALLET_ID_KEY) - // ?.let(::UserWalletId) - // - // - // requireNotNull(selectedUserWalletId) { "UserWalletId must be provided" } - // - // val context = rootContext.childByContext( - // componentContext = defaultComponentContext(requireActivity().onBackPressedDispatcher), - // messageHandler = messageHandler, - // router = detailsRouter, - // ) - // - // return componentFactory.create( - // context = context, - // params = DetailsComponent.Params( - // selectedUserWalletId = selectedUserWalletId, - // ), - // ) - - return PreviewDetailsComponent() - } - - companion object : DetailsEntryPoint { - - override fun entryFragment(): Fragment = DetailsFragment() - } -} \ No newline at end of file diff --git a/features/details/impl/src/main/kotlin/com/tangem/features/details/DetailsRouter.kt b/features/details/impl/src/main/kotlin/com/tangem/features/details/DetailsRouter.kt deleted file mode 100644 index fbd703a49a..0000000000 --- a/features/details/impl/src/main/kotlin/com/tangem/features/details/DetailsRouter.kt +++ /dev/null @@ -1,55 +0,0 @@ -package com.tangem.features.details - -import com.tangem.core.decompose.navigation.Route -import com.tangem.core.decompose.navigation.Router -import com.tangem.core.navigation.NavigationAction -import com.tangem.core.navigation.ReduxNavController -import com.tangem.domain.redux.ReduxStateHolder -import com.tangem.features.details.routing.DetailsRoute -import com.tangem.features.tester.api.TesterRouter -import javax.inject.Inject - -// TODO: Remove after [REDACTED_JIRA] -internal class DetailsRouter @Inject constructor( - private val reduxNavController: ReduxNavController, - private val reduxStateHolder: ReduxStateHolder, - private val testerRouter: TesterRouter, -) : Router { - - override fun push(route: Route, onComplete: (isSuccess: Boolean) -> Unit) { - if (route is DetailsRoute) { - when (route) { - is DetailsRoute.Screen -> { - reduxNavController.navigate(NavigationAction.NavigateTo(route.screen, bundle = route.params)) - } - is DetailsRoute.Feedback -> { - reduxStateHolder.sendFeedbackEmail() - } - is DetailsRoute.TesterMenu -> { - testerRouter.startTesterScreen() - } - is DetailsRoute.Url -> { - reduxNavController.navigate(NavigationAction.OpenUrl(route.url)) - } - } - onComplete(true) - } else { - onComplete(false) - } - } - - override fun pop(onComplete: (isSuccess: Boolean) -> Unit) { - reduxNavController.popBackStack() - onComplete(true) - } - - override fun popTo(route: Route, onComplete: (isSuccess: Boolean) -> Unit) { - if (route is DetailsRoute.Screen) { - reduxNavController.popBackStack(route.screen) - onComplete(true) - } else { - reduxNavController.getBackStack() - onComplete(false) - } - } -} \ No newline at end of file diff --git a/features/details/impl/src/main/kotlin/com/tangem/features/details/component/DetailsComponent.kt b/features/details/impl/src/main/kotlin/com/tangem/features/details/component/DetailsComponent.kt deleted file mode 100644 index 9731597b9b..0000000000 --- a/features/details/impl/src/main/kotlin/com/tangem/features/details/component/DetailsComponent.kt +++ /dev/null @@ -1,25 +0,0 @@ -package com.tangem.features.details.component - -import androidx.compose.material3.SnackbarHostState -import androidx.compose.runtime.Composable -import androidx.compose.ui.Modifier -import com.tangem.core.decompose.context.AppComponentContext -import com.tangem.domain.wallets.models.UserWalletId - -interface DetailsComponent { - - val snackbarHostState: SnackbarHostState - - @Composable - @Suppress("TopLevelComposableFunctions") // TODO: Remove this check - fun View(modifier: Modifier) - - interface Factory { - - fun create(context: AppComponentContext, params: Params): DetailsComponent - } - - data class Params( - val selectedUserWalletId: UserWalletId, - ) -} \ No newline at end of file diff --git a/features/details/impl/src/main/kotlin/com/tangem/features/details/component/UserWalletListComponent.kt b/features/details/impl/src/main/kotlin/com/tangem/features/details/component/UserWalletListComponent.kt deleted file mode 100644 index 0a76b5fcd1..0000000000 --- a/features/details/impl/src/main/kotlin/com/tangem/features/details/component/UserWalletListComponent.kt +++ /dev/null @@ -1,16 +0,0 @@ -package com.tangem.features.details.component - -import androidx.compose.runtime.Composable -import androidx.compose.ui.Modifier -import com.tangem.core.decompose.context.AppComponentContext - -interface UserWalletListComponent { - - @Composable - @Suppress("TopLevelComposableFunctions") // TODO: Remove this check - fun View(modifier: Modifier) - - interface Factory { - fun create(context: AppComponentContext): UserWalletListComponent - } -} \ No newline at end of file diff --git a/features/details/impl/src/main/kotlin/com/tangem/features/details/component/WalletConnectComponent.kt b/features/details/impl/src/main/kotlin/com/tangem/features/details/component/WalletConnectComponent.kt deleted file mode 100644 index c8a317814b..0000000000 --- a/features/details/impl/src/main/kotlin/com/tangem/features/details/component/WalletConnectComponent.kt +++ /dev/null @@ -1,23 +0,0 @@ -package com.tangem.features.details.component - -import androidx.compose.runtime.Composable -import androidx.compose.ui.Modifier -import com.tangem.core.decompose.context.AppComponentContext -import com.tangem.domain.wallets.models.UserWalletId - -interface WalletConnectComponent { - - suspend fun checkIsAvailable(): Boolean - - @Composable - @Suppress("TopLevelComposableFunctions") // TODO: Remove this check - fun View(modifier: Modifier) - - interface Factory { - fun create(context: AppComponentContext, params: Params): WalletConnectComponent - } - - data class Params( - val userWalletId: UserWalletId, - ) -} \ No newline at end of file diff --git a/features/details/impl/src/main/kotlin/com/tangem/features/details/component/impl/DefaultDetailsComponent.kt b/features/details/impl/src/main/kotlin/com/tangem/features/details/component/impl/DefaultDetailsComponent.kt new file mode 100644 index 0000000000..ec33cbbaaf --- /dev/null +++ b/features/details/impl/src/main/kotlin/com/tangem/features/details/component/impl/DefaultDetailsComponent.kt @@ -0,0 +1,45 @@ +package com.tangem.features.details.component.impl + +import androidx.compose.runtime.Composable +import androidx.compose.runtime.getValue +import androidx.compose.ui.Modifier +import androidx.lifecycle.compose.collectAsStateWithLifecycle +import com.tangem.core.decompose.context.AppComponentContext +import com.tangem.core.decompose.context.child +import com.tangem.core.decompose.model.getOrCreateModel +import com.tangem.features.details.component.DetailsComponent +import com.tangem.features.details.component.UserWalletListComponent +import com.tangem.features.details.model.DetailsModel +import com.tangem.features.details.ui.DetailsScreen +import dagger.assisted.Assisted +import dagger.assisted.AssistedFactory +import dagger.assisted.AssistedInject + +internal class DefaultDetailsComponent @AssistedInject constructor( + @Assisted context: AppComponentContext, + @Assisted params: DetailsComponent.Params, + userWalletListComponentFactory: UserWalletListComponent.Factory, +) : DetailsComponent, AppComponentContext by context { + + private val model: DetailsModel = getOrCreateModel(params) + + private val userWalletListComponent = userWalletListComponentFactory.create( + context = child(key = "user_wallet_list_component"), + ) + + @Composable + override fun Content(modifier: Modifier) { + val state by model.state.collectAsStateWithLifecycle() + + DetailsScreen( + modifier = modifier, + state = state, + userWalletListBlockContent = userWalletListComponent, + ) + } + + @AssistedFactory + interface Factory : DetailsComponent.Factory { + override fun create(context: AppComponentContext, params: DetailsComponent.Params): DefaultDetailsComponent + } +} \ No newline at end of file diff --git a/features/details/impl/src/main/kotlin/com/tangem/features/details/component/impl/DefaultUserWalletListComponent.kt b/features/details/impl/src/main/kotlin/com/tangem/features/details/component/impl/DefaultUserWalletListComponent.kt new file mode 100644 index 0000000000..53279cde55 --- /dev/null +++ b/features/details/impl/src/main/kotlin/com/tangem/features/details/component/impl/DefaultUserWalletListComponent.kt @@ -0,0 +1,37 @@ +package com.tangem.features.details.component.impl + +import androidx.compose.runtime.Composable +import androidx.compose.runtime.getValue +import androidx.compose.ui.Modifier +import androidx.lifecycle.compose.collectAsStateWithLifecycle +import com.tangem.core.decompose.context.AppComponentContext +import com.tangem.core.decompose.model.getOrCreateModel +import com.tangem.features.details.component.UserWalletListComponent +import com.tangem.features.details.model.UserWalletListModel +import com.tangem.features.details.ui.UserWalletListBlock +import dagger.assisted.Assisted +import dagger.assisted.AssistedFactory +import dagger.assisted.AssistedInject + +internal class DefaultUserWalletListComponent @AssistedInject constructor( + @Assisted context: AppComponentContext, +) : UserWalletListComponent, AppComponentContext by context { + + private val model: UserWalletListModel = getOrCreateModel() + + @Composable + override fun Content(modifier: Modifier) { + val state by model.state.collectAsStateWithLifecycle() + + UserWalletListBlock( + modifier = modifier, + state = state, + ) + } + + @AssistedFactory + interface Factory : UserWalletListComponent.Factory { + + override fun create(context: AppComponentContext): DefaultUserWalletListComponent + } +} \ No newline at end of file diff --git a/features/details/impl/src/main/kotlin/com/tangem/features/details/component/preview/PreviewDetailsComponent.kt b/features/details/impl/src/main/kotlin/com/tangem/features/details/component/preview/PreviewDetailsComponent.kt index 9c6aff4521..209cad1288 100644 --- a/features/details/impl/src/main/kotlin/com/tangem/features/details/component/preview/PreviewDetailsComponent.kt +++ b/features/details/impl/src/main/kotlin/com/tangem/features/details/component/preview/PreviewDetailsComponent.kt @@ -1,8 +1,9 @@ package com.tangem.features.details.component.preview -import androidx.compose.material3.SnackbarHostState import androidx.compose.runtime.Composable import androidx.compose.ui.Modifier +import com.tangem.core.decompose.navigation.DummyRouter +import com.tangem.core.navigation.url.DummyUrlOpener import com.tangem.features.details.component.DetailsComponent import com.tangem.features.details.entity.DetailsFooterUM import com.tangem.features.details.entity.DetailsUM @@ -13,18 +14,15 @@ import kotlinx.coroutines.runBlocking internal class PreviewDetailsComponent : DetailsComponent { - override val snackbarHostState: SnackbarHostState = SnackbarHostState() - private val previewBlocks = runBlocking { ItemsBuilder( - walletConnectComponent = PreviewWalletConnectComponent(), - userWalletListComponent = PreviewUserWalletListComponent(), - router = PreviewRouter(), - ).buldAll() + router = DummyRouter(), + urlOpener = DummyUrlOpener(), + ).buildAll(isWalletConnectAvailable = true, onSupportClick = {}) } private val previewFooter = DetailsFooterUM( - socials = SocialsBuilder(PreviewRouter()).buildAll(), + socials = SocialsBuilder(DummyUrlOpener()).buildAll(), appVersion = "1.0.0-preview", ) @@ -35,12 +33,11 @@ internal class PreviewDetailsComponent : DetailsComponent { ) @Composable - @Suppress("TopLevelComposableFunctions") // TODO: Remove this check - override fun View(modifier: Modifier) { + override fun Content(modifier: Modifier) { DetailsScreen( modifier = modifier, state = previewState, - snackbarHostState = snackbarHostState, + userWalletListBlockContent = PreviewUserWalletListComponent(), ) } } \ No newline at end of file diff --git a/features/details/impl/src/main/kotlin/com/tangem/features/details/component/preview/PreviewRouter.kt b/features/details/impl/src/main/kotlin/com/tangem/features/details/component/preview/PreviewRouter.kt deleted file mode 100644 index 49366db923..0000000000 --- a/features/details/impl/src/main/kotlin/com/tangem/features/details/component/preview/PreviewRouter.kt +++ /dev/null @@ -1,18 +0,0 @@ -package com.tangem.features.details.component.preview - -import com.tangem.core.decompose.navigation.Route -import com.tangem.core.decompose.navigation.Router - -internal class PreviewRouter : Router { - override fun push(route: Route, onComplete: (isSuccess: Boolean) -> Unit) { - /* no-op */ - } - - override fun pop(onComplete: (isSuccess: Boolean) -> Unit) { - /* no-op */ - } - - override fun popTo(route: Route, onComplete: (isSuccess: Boolean) -> Unit) { - /* no-op */ - } -} \ No newline at end of file diff --git a/features/details/impl/src/main/kotlin/com/tangem/features/details/component/preview/PreviewUserWalletListComponent.kt b/features/details/impl/src/main/kotlin/com/tangem/features/details/component/preview/PreviewUserWalletListComponent.kt index c7628c2619..92b6f46de3 100644 --- a/features/details/impl/src/main/kotlin/com/tangem/features/details/component/preview/PreviewUserWalletListComponent.kt +++ b/features/details/impl/src/main/kotlin/com/tangem/features/details/component/preview/PreviewUserWalletListComponent.kt @@ -19,23 +19,26 @@ internal class PreviewUserWalletListComponent : UserWalletListComponent { userWallets = persistentListOf( UserWalletListUM.UserWalletUM( id = UserWalletId("user_wallet_1".encodeToByteArray()), - name = "My Wallet", + name = stringReference("My Wallet"), information = getInformation(3, "4 496,75 $"), - imageResId = R.drawable.ill_card_wallet_2_211_343, + imageUrl = "", + isEnabled = true, onClick = {}, ), UserWalletListUM.UserWalletUM( id = UserWalletId("user_wallet_2".encodeToByteArray()), - name = "Old wallet", + name = stringReference("Old wallet"), information = getInformation(3, "4 496,75 $"), - imageResId = R.drawable.ill_card_note_eth_211_343, + imageUrl = "", + isEnabled = true, onClick = {}, ), UserWalletListUM.UserWalletUM( id = UserWalletId("user_wallet_3".encodeToByteArray()), - name = "Multi Card", + name = stringReference("Multi Card"), information = getInformation(3, "4 496,75 $"), - imageResId = R.drawable.ill_card_note_bnb_211_343, + imageUrl = "", + isEnabled = false, onClick = {}, ), ), @@ -45,8 +48,7 @@ internal class PreviewUserWalletListComponent : UserWalletListComponent { ) @Composable - @Suppress("TopLevelComposableFunctions") // TODO: Remove this check - override fun View(modifier: Modifier) { + override fun Content(modifier: Modifier) { UserWalletListBlock(state = previewState, modifier = modifier) } diff --git a/features/details/impl/src/main/kotlin/com/tangem/features/details/component/preview/PreviewWalletConnectComponent.kt b/features/details/impl/src/main/kotlin/com/tangem/features/details/component/preview/PreviewWalletConnectComponent.kt deleted file mode 100644 index 4f94585d78..0000000000 --- a/features/details/impl/src/main/kotlin/com/tangem/features/details/component/preview/PreviewWalletConnectComponent.kt +++ /dev/null @@ -1,17 +0,0 @@ -package com.tangem.features.details.component.preview - -import androidx.compose.runtime.Composable -import androidx.compose.ui.Modifier -import com.tangem.features.details.component.WalletConnectComponent -import com.tangem.features.details.ui.WalletConnectBlock - -internal class PreviewWalletConnectComponent : WalletConnectComponent { - - override suspend fun checkIsAvailable(): Boolean = true - - @Composable - @Suppress("TopLevelComposableFunctions") // TODO: Remove this check - override fun View(modifier: Modifier) { - WalletConnectBlock(onClick = { /* no-op */ }, modifier = modifier) - } -} \ No newline at end of file diff --git a/features/details/impl/src/main/kotlin/com/tangem/features/details/di/ComponentModule.kt b/features/details/impl/src/main/kotlin/com/tangem/features/details/di/ComponentModule.kt new file mode 100644 index 0000000000..27fd842ab3 --- /dev/null +++ b/features/details/impl/src/main/kotlin/com/tangem/features/details/di/ComponentModule.kt @@ -0,0 +1,26 @@ +package com.tangem.features.details.di + +import com.tangem.features.details.component.DetailsComponent +import com.tangem.features.details.component.UserWalletListComponent +import com.tangem.features.details.component.impl.DefaultDetailsComponent +import com.tangem.features.details.component.impl.DefaultUserWalletListComponent +import dagger.Binds +import dagger.Module +import dagger.hilt.InstallIn +import dagger.hilt.components.SingletonComponent +import javax.inject.Singleton + +@Module +@InstallIn(SingletonComponent::class) +internal interface ComponentModule { + + @Binds + @Singleton + fun bindDetailsComponentFactory(factory: DefaultDetailsComponent.Factory): DetailsComponent.Factory + + @Binds + @Singleton + fun bindUserWalletListComponentFactory( + factory: DefaultUserWalletListComponent.Factory, + ): UserWalletListComponent.Factory +} \ No newline at end of file diff --git a/features/details/impl/src/main/kotlin/com/tangem/features/details/di/FeatureModule.kt b/features/details/impl/src/main/kotlin/com/tangem/features/details/di/FeatureModule.kt index f9a437ee25..44a655a33f 100644 --- a/features/details/impl/src/main/kotlin/com/tangem/features/details/di/FeatureModule.kt +++ b/features/details/impl/src/main/kotlin/com/tangem/features/details/di/FeatureModule.kt @@ -2,9 +2,7 @@ package com.tangem.features.details.di import com.tangem.core.featuretoggle.manager.FeatureTogglesManager import com.tangem.features.details.DefaultDetailsFeatureToggles -import com.tangem.features.details.DetailsEntryPoint import com.tangem.features.details.DetailsFeatureToggles -import com.tangem.features.details.DetailsFragment import dagger.Module import dagger.Provides import dagger.hilt.InstallIn @@ -20,10 +18,4 @@ internal object FeatureModule { fun provideFeatureToggles(featureTogglesManager: FeatureTogglesManager): DetailsFeatureToggles { return DefaultDetailsFeatureToggles(featureTogglesManager) } - - @Provides - @Singleton - fun provideEntryPoint(): DetailsEntryPoint { - return DetailsFragment.Companion - } } \ No newline at end of file diff --git a/features/details/impl/src/main/kotlin/com/tangem/features/details/di/ModelModule.kt b/features/details/impl/src/main/kotlin/com/tangem/features/details/di/ModelModule.kt index 8b429e0438..63481527c2 100644 --- a/features/details/impl/src/main/kotlin/com/tangem/features/details/di/ModelModule.kt +++ b/features/details/impl/src/main/kotlin/com/tangem/features/details/di/ModelModule.kt @@ -3,6 +3,7 @@ package com.tangem.features.details.di import com.tangem.core.decompose.di.DecomposeComponent import com.tangem.core.decompose.model.Model import com.tangem.features.details.model.DetailsModel +import com.tangem.features.details.model.UserWalletListModel import dagger.Binds import dagger.Module import dagger.hilt.InstallIn @@ -17,4 +18,9 @@ internal interface ModelModule { @IntoMap @ClassKey(DetailsModel::class) fun provideDetailsModel(model: DetailsModel): Model + + @Binds + @IntoMap + @ClassKey(UserWalletListModel::class) + fun provideUserWalletListModel(model: UserWalletListModel): Model } \ No newline at end of file diff --git a/features/details/impl/src/main/kotlin/com/tangem/features/details/entity/DetailsFooterUM.kt b/features/details/impl/src/main/kotlin/com/tangem/features/details/entity/DetailsFooterUM.kt index 267acbe9d0..c614a5af8d 100644 --- a/features/details/impl/src/main/kotlin/com/tangem/features/details/entity/DetailsFooterUM.kt +++ b/features/details/impl/src/main/kotlin/com/tangem/features/details/entity/DetailsFooterUM.kt @@ -1,8 +1,10 @@ package com.tangem.features.details.entity import androidx.annotation.DrawableRes +import androidx.compose.runtime.Immutable import kotlinx.collections.immutable.ImmutableList +@Immutable internal data class DetailsFooterUM( val appVersion: String, val socials: ImmutableList, diff --git a/features/details/impl/src/main/kotlin/com/tangem/features/details/entity/DetailsItemUM.kt b/features/details/impl/src/main/kotlin/com/tangem/features/details/entity/DetailsItemUM.kt index 1aa5a52ab5..99c416a63a 100644 --- a/features/details/impl/src/main/kotlin/com/tangem/features/details/entity/DetailsItemUM.kt +++ b/features/details/impl/src/main/kotlin/com/tangem/features/details/entity/DetailsItemUM.kt @@ -1,10 +1,7 @@ package com.tangem.features.details.entity -import androidx.annotation.DrawableRes -import androidx.compose.runtime.Composable import androidx.compose.runtime.Immutable -import androidx.compose.ui.Modifier -import com.tangem.core.ui.extensions.TextReference +import com.tangem.core.ui.components.block.model.BlockUM import kotlinx.collections.immutable.ImmutableList @Immutable @@ -19,23 +16,15 @@ internal sealed class DetailsItemUM { data class Item( val id: String, - val title: TextReference, - @DrawableRes - val iconRes: Int, - val onClick: () -> Unit, + val block: BlockUM, ) } - data class Component( - override val id: String, - val content: Content, - ) : DetailsItemUM() { + data class WalletConnect(val onClick: () -> Unit) : DetailsItemUM() { + override val id: String = "wallet_connect" + } - fun interface Content { - - @Composable - @Suppress("TopLevelComposableFunctions", "ComposableFunctionName") - operator fun invoke(modifier: Modifier) - } + data object UserWalletList : DetailsItemUM() { + override val id: String = "user_wallet_list" } } \ No newline at end of file diff --git a/features/details/impl/src/main/kotlin/com/tangem/features/details/entity/UserWalletListUM.kt b/features/details/impl/src/main/kotlin/com/tangem/features/details/entity/UserWalletListUM.kt index d6f947b063..1569f48efb 100644 --- a/features/details/impl/src/main/kotlin/com/tangem/features/details/entity/UserWalletListUM.kt +++ b/features/details/impl/src/main/kotlin/com/tangem/features/details/entity/UserWalletListUM.kt @@ -1,10 +1,11 @@ package com.tangem.features.details.entity -import androidx.annotation.DrawableRes +import androidx.compose.runtime.Immutable import com.tangem.core.ui.extensions.TextReference import com.tangem.domain.wallets.models.UserWalletId import kotlinx.collections.immutable.ImmutableList +@Immutable internal data class UserWalletListUM( val userWallets: ImmutableList, val isWalletSavingInProgress: Boolean, @@ -12,12 +13,13 @@ internal data class UserWalletListUM( val onAddNewWalletClick: () -> Unit, ) { + @Immutable data class UserWalletUM( val id: UserWalletId, - val name: String, + val name: TextReference, val information: TextReference, - @DrawableRes - val imageResId: Int, + val imageUrl: String, + val isEnabled: Boolean, val onClick: () -> Unit, ) } \ No newline at end of file diff --git a/features/details/impl/src/main/kotlin/com/tangem/features/details/model/DetailsModel.kt b/features/details/impl/src/main/kotlin/com/tangem/features/details/model/DetailsModel.kt index 918c27eb97..8bd54c48e9 100644 --- a/features/details/impl/src/main/kotlin/com/tangem/features/details/model/DetailsModel.kt +++ b/features/details/impl/src/main/kotlin/com/tangem/features/details/model/DetailsModel.kt @@ -1,10 +1,103 @@ package com.tangem.features.details.model +import arrow.core.getOrElse +import com.tangem.core.decompose.di.ComponentScoped import com.tangem.core.decompose.model.Model +import com.tangem.core.decompose.model.ParamsContainer +import com.tangem.core.decompose.navigation.Router +import com.tangem.domain.feedback.FeedbackManager +import com.tangem.domain.feedback.GetCardInfoUseCase +import com.tangem.domain.feedback.models.FeedbackEmailType +import com.tangem.domain.walletconnect.CheckIsWalletConnectAvailableUseCase +import com.tangem.domain.wallets.usecase.GetSelectedWalletSyncUseCase +import com.tangem.features.details.component.DetailsComponent +import com.tangem.features.details.entity.DetailsFooterUM +import com.tangem.features.details.entity.DetailsItemUM +import com.tangem.features.details.entity.DetailsUM +import com.tangem.features.details.utils.ItemsBuilder +import com.tangem.features.details.utils.SocialsBuilder import com.tangem.utils.coroutines.CoroutineDispatcherProvider +import com.tangem.utils.version.AppVersionProvider +import kotlinx.collections.immutable.ImmutableList +import kotlinx.collections.immutable.persistentListOf +import kotlinx.coroutines.flow.MutableStateFlow +import kotlinx.coroutines.flow.launchIn +import kotlinx.coroutines.flow.onEach +import kotlinx.coroutines.flow.update +import kotlinx.coroutines.launch +import timber.log.Timber import javax.inject.Inject -// TODO: Will be implemented later +@ComponentScoped +@Suppress("LongParameterList") internal class DetailsModel @Inject constructor( + private val socialsBuilder: SocialsBuilder, + private val itemsBuilder: ItemsBuilder, + private val appVersionProvider: AppVersionProvider, + private val checkIsWalletConnectAvailableUseCase: CheckIsWalletConnectAvailableUseCase, + private val router: Router, + private val paramsContainer: ParamsContainer, + private val getSelectedWalletSyncUseCase: GetSelectedWalletSyncUseCase, + private val getCardInfoUseCase: GetCardInfoUseCase, + private val feedbackManager: FeedbackManager, override val dispatchers: CoroutineDispatcherProvider, -) : Model() \ No newline at end of file +) : Model() { + + private val params: DetailsComponent.Params = paramsContainer.require() + + private val items: MutableStateFlow> = MutableStateFlow(value = persistentListOf()) + + val state: MutableStateFlow = MutableStateFlow( + value = DetailsUM( + items = items.value, + footer = DetailsFooterUM( + socials = socialsBuilder.buildAll(), + appVersion = getAppVersion(), + ), + popBack = router::pop, + ), + ) + + init { + items + .onEach(::updateState) + .launchIn(modelScope) + + checkWalletConnectAvailability() + } + + private fun checkWalletConnectAvailability() = modelScope.launch { + val isWalletConnectAvailable = checkIsWalletConnectAvailableUseCase(params.userWalletId).getOrElse { + Timber.w("Unable to check WalletConnect availability: $it") + + false + } + + items.value = itemsBuilder.buildAll( + isWalletConnectAvailable = isWalletConnectAvailable, + onSupportClick = ::sendFeedback, + ) + } + + private fun sendFeedback() { + modelScope.launch { + val scanResponse = getSelectedWalletSyncUseCase().getOrNull()?.scanResponse + ?: error("Selected wallet is null") + + val cardInfo = getCardInfoUseCase(scanResponse = scanResponse).getOrNull() + ?: error("CardInfo must be not null") + + feedbackManager.sendEmail(type = FeedbackEmailType.DirectUserRequest(cardInfo)) + } + } + + private suspend fun updateState(items: ImmutableList) { + state.update { prevState -> + prevState.copy( + items = items, + ) + } + } + + private fun getAppVersion(): String = "${appVersionProvider.versionName} (${appVersionProvider.versionCode})" +} \ No newline at end of file diff --git a/features/details/impl/src/main/kotlin/com/tangem/features/details/model/UserWalletListModel.kt b/features/details/impl/src/main/kotlin/com/tangem/features/details/model/UserWalletListModel.kt new file mode 100644 index 0000000000..12f18cc1f4 --- /dev/null +++ b/features/details/impl/src/main/kotlin/com/tangem/features/details/model/UserWalletListModel.kt @@ -0,0 +1,69 @@ +package com.tangem.features.details.model + +import com.tangem.core.decompose.di.ComponentScoped +import com.tangem.core.decompose.model.Model +import com.tangem.core.ui.extensions.TextReference +import com.tangem.core.ui.extensions.resourceReference +import com.tangem.domain.wallets.usecase.ShouldSaveUserWalletsUseCase +import com.tangem.features.details.entity.UserWalletListUM +import com.tangem.features.details.entity.UserWalletListUM.UserWalletUM +import com.tangem.features.details.impl.R +import com.tangem.features.details.utils.UserWalletSaver +import com.tangem.features.details.utils.UserWalletsFetcher +import com.tangem.utils.coroutines.CoroutineDispatcherProvider +import kotlinx.collections.immutable.ImmutableList +import kotlinx.collections.immutable.persistentListOf +import kotlinx.coroutines.flow.MutableStateFlow +import kotlinx.coroutines.flow.combine +import kotlinx.coroutines.flow.launchIn +import kotlinx.coroutines.flow.update +import javax.inject.Inject + +@ComponentScoped +internal class UserWalletListModel @Inject constructor( + userWalletsFetcher: UserWalletsFetcher, + shouldSaveUserWalletsUseCase: ShouldSaveUserWalletsUseCase, + private val userWalletSaver: UserWalletSaver, + override val dispatchers: CoroutineDispatcherProvider, +) : Model() { + + private val isWalletSavingInProgress: MutableStateFlow = MutableStateFlow(value = false) + + val state: MutableStateFlow = MutableStateFlow( + value = UserWalletListUM( + userWallets = persistentListOf(), + isWalletSavingInProgress = false, + addNewWalletText = TextReference.EMPTY, + onAddNewWalletClick = ::addUserWallet, + ), + ) + + init { + combine( + userWalletsFetcher.userWallets, + shouldSaveUserWalletsUseCase(), + isWalletSavingInProgress, + transform = ::updateState, + ).launchIn(modelScope) + } + + private fun updateState( + userWallets: ImmutableList, + shouldSaveUserWallets: Boolean, + isWalletSavingInProgress: Boolean, + ) = state.update { value -> + value.copy( + userWallets = userWallets, + isWalletSavingInProgress = isWalletSavingInProgress, + addNewWalletText = if (shouldSaveUserWallets) { + resourceReference(R.string.user_wallet_list_add_button) + } else { + resourceReference(R.string.scan_card_settings_button) + }, + ) + } + + private fun addUserWallet() = withProgress(isWalletSavingInProgress) { + userWalletSaver.scanAndSaveUserWallet() + } +} \ No newline at end of file diff --git a/features/details/impl/src/main/kotlin/com/tangem/features/details/routing/DetailsRoute.kt b/features/details/impl/src/main/kotlin/com/tangem/features/details/routing/DetailsRoute.kt deleted file mode 100644 index 878987aca5..0000000000 --- a/features/details/impl/src/main/kotlin/com/tangem/features/details/routing/DetailsRoute.kt +++ /dev/null @@ -1,20 +0,0 @@ -package com.tangem.features.details.routing - -import android.os.Bundle -import com.tangem.core.decompose.navigation.Route -import com.tangem.core.navigation.AppScreen - -// TODO: Remove after [REDACTED_JIRA] -internal sealed class DetailsRoute : Route { - - data class Screen( - val screen: AppScreen, - val params: Bundle? = null, - ) : DetailsRoute() - - data class Url(val url: String) : DetailsRoute() - - data object Feedback : DetailsRoute() - - data object TesterMenu : DetailsRoute() -} \ No newline at end of file diff --git a/features/details/impl/src/main/kotlin/com/tangem/features/details/ui/DetailsScreen.kt b/features/details/impl/src/main/kotlin/com/tangem/features/details/ui/DetailsScreen.kt index 0b03305816..9132fff08b 100644 --- a/features/details/impl/src/main/kotlin/com/tangem/features/details/ui/DetailsScreen.kt +++ b/features/details/impl/src/main/kotlin/com/tangem/features/details/ui/DetailsScreen.kt @@ -9,17 +9,22 @@ import androidx.compose.foundation.layout.* import androidx.compose.foundation.lazy.LazyColumn import androidx.compose.foundation.lazy.items import androidx.compose.foundation.rememberScrollState -import androidx.compose.material3.* +import androidx.compose.material3.Icon +import androidx.compose.material3.IconButton +import androidx.compose.material3.Scaffold +import androidx.compose.material3.Text import androidx.compose.runtime.* import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier -import androidx.compose.ui.input.nestedscroll.nestedScroll import androidx.compose.ui.res.painterResource import androidx.compose.ui.res.stringResource -import androidx.compose.ui.text.style.TextOverflow import androidx.compose.ui.tooling.preview.Preview -import com.tangem.core.ui.components.SystemBarsEffect +import com.tangem.core.ui.components.appbar.TangemTopAppBar +import com.tangem.core.ui.components.appbar.models.TopAppBarButtonUM +import com.tangem.core.ui.components.block.BlockItem import com.tangem.core.ui.components.snackbar.TangemSnackbarHost +import com.tangem.core.ui.decompose.ComposableContentComponent +import com.tangem.core.ui.res.LocalSnackbarHostState import com.tangem.core.ui.res.TangemTheme import com.tangem.core.ui.res.TangemThemePreview import com.tangem.features.details.component.preview.PreviewDetailsComponent @@ -28,96 +33,62 @@ import com.tangem.features.details.entity.DetailsItemUM import com.tangem.features.details.entity.DetailsUM import com.tangem.features.details.impl.R -private const val COLLAPSED_APP_BAR_THRESHOLD = 0.4f - -@OptIn(ExperimentalMaterial3Api::class) @Composable -internal fun DetailsScreen(state: DetailsUM, snackbarHostState: SnackbarHostState, modifier: Modifier = Modifier) { +internal fun DetailsScreen( + state: DetailsUM, + userWalletListBlockContent: ComposableContentComponent, + modifier: Modifier = Modifier, +) { val backgroundColor = TangemTheme.colors.background.secondary - val scrollBehavior = TopAppBarDefaults.exitUntilCollapsedScrollBehavior() - - SystemBarsEffect { - setSystemBarsColor(backgroundColor) - } BackHandler(onBack = state.popBack) Scaffold( - modifier = modifier.nestedScroll(scrollBehavior.nestedScrollConnection), + modifier = modifier, containerColor = backgroundColor, snackbarHost = { TangemSnackbarHost( modifier = Modifier.padding(all = TangemTheme.dimens.spacing16), - hostState = snackbarHostState, + hostState = LocalSnackbarHostState.current, + ) + }, + topBar = { + TangemTopAppBar( + modifier = Modifier.statusBarsPadding(), + startButton = TopAppBarButtonUM.Back(state.popBack), ) }, - topBar = { TopBar(state, scrollBehavior) }, ) { paddingValues -> Content( modifier = Modifier.padding(paddingValues), state = state, + userWalletListBlockContent = userWalletListBlockContent, ) } } -@OptIn(ExperimentalMaterial3Api::class) @Composable -private fun TopBar(state: DetailsUM, scrollBehavior: TopAppBarScrollBehavior, modifier: Modifier = Modifier) { - MediumTopAppBar( - modifier = modifier, - scrollBehavior = scrollBehavior, - colors = TopAppBarColors( - containerColor = TangemTheme.colors.background.secondary, - scrolledContainerColor = TangemTheme.colors.background.secondary, - navigationIconContentColor = TangemTheme.colors.icon.primary1, - titleContentColor = TangemTheme.colors.text.primary1, - actionIconContentColor = TangemTheme.colors.icon.primary1, - ), - title = { - val collapsedStyle = TangemTheme.typography.subtitle1 - val expandedStyle = TangemTheme.typography.h1 - val style by remember(scrollBehavior.state.collapsedFraction) { - derivedStateOf { - if (scrollBehavior.state.collapsedFraction >= COLLAPSED_APP_BAR_THRESHOLD) { - collapsedStyle - } else { - expandedStyle - } - } - } - - Text( - text = stringResource(id = R.string.details_title), - style = style, - maxLines = 1, - overflow = TextOverflow.Ellipsis, - ) - }, - navigationIcon = { - IconButton( - modifier = Modifier.size(TangemTheme.dimens.size32), - onClick = state.popBack, - ) { - Icon( - modifier = Modifier.size(TangemTheme.dimens.size24), - painter = painterResource(id = R.drawable.ic_back_24), - contentDescription = null, - ) - } - }, - ) -} - -@Composable -private fun Content(state: DetailsUM, modifier: Modifier = Modifier) { +private fun Content( + state: DetailsUM, + userWalletListBlockContent: ComposableContentComponent, + modifier: Modifier = Modifier, +) { LazyColumn( modifier = modifier, verticalArrangement = Arrangement.spacedBy(TangemTheme.dimens.spacing16), contentPadding = PaddingValues( - top = TangemTheme.dimens.spacing16, + top = TangemTheme.dimens.spacing12, bottom = TangemTheme.dimens.spacing16, ), ) { + item { + Text( + modifier = Modifier.padding(horizontal = TangemTheme.dimens.spacing16), + text = stringResource(R.string.details_title), + style = TangemTheme.typography.h1, + color = TangemTheme.colors.text.primary1, + ) + } items( items = state.items, key = DetailsItemUM::id, @@ -125,6 +96,7 @@ private fun Content(state: DetailsUM, modifier: Modifier = Modifier) { Block( modifier = Modifier.padding(horizontal = TangemTheme.dimens.spacing16), model = block, + userWalletListBlockContent = userWalletListBlockContent, ) } @@ -138,7 +110,11 @@ private fun Content(state: DetailsUM, modifier: Modifier = Modifier) { } @Composable -private fun Block(model: DetailsItemUM, modifier: Modifier = Modifier) { +private fun Block( + model: DetailsItemUM, + userWalletListBlockContent: ComposableContentComponent, + modifier: Modifier = Modifier, +) { Column( modifier = modifier .fillMaxWidth() @@ -149,22 +125,28 @@ private fun Block(model: DetailsItemUM, modifier: Modifier = Modifier) { horizontalAlignment = Alignment.Start, verticalArrangement = Arrangement.Top, ) { + val itemModifier = Modifier.fillMaxWidth() + when (model) { is DetailsItemUM.Basic -> { model.items.forEach { item -> key(item.id) { BlockItem( - modifier = Modifier.fillMaxWidth(), - model = item, + modifier = itemModifier, + model = item.block, ) } } } - is DetailsItemUM.Component -> { - model.content( - modifier = Modifier.fillMaxWidth(), + is DetailsItemUM.WalletConnect -> { + WalletConnectBlock( + modifier = itemModifier, + onClick = model.onClick, ) } + is DetailsItemUM.UserWalletList -> { + userWalletListBlockContent.Content(modifier = itemModifier) + } } } } @@ -222,7 +204,7 @@ private fun Footer(model: DetailsFooterUM, modifier: Modifier = Modifier) { @Preview(showBackground = true, widthDp = 360, uiMode = Configuration.UI_MODE_NIGHT_YES) private fun Preview_DetailsScreen() { TangemThemePreview { - PreviewDetailsComponent().View(modifier = Modifier.fillMaxSize()) + PreviewDetailsComponent().Content(modifier = Modifier.fillMaxSize()) } } // endregion Preview \ No newline at end of file diff --git a/features/details/impl/src/main/kotlin/com/tangem/features/details/ui/UserWalletListBlock.kt b/features/details/impl/src/main/kotlin/com/tangem/features/details/ui/UserWalletListBlock.kt index 254c434047..794ef632c3 100644 --- a/features/details/impl/src/main/kotlin/com/tangem/features/details/ui/UserWalletListBlock.kt +++ b/features/details/impl/src/main/kotlin/com/tangem/features/details/ui/UserWalletListBlock.kt @@ -1,21 +1,30 @@ package com.tangem.features.details.ui +import androidx.compose.animation.AnimatedContent import androidx.compose.foundation.Image import androidx.compose.foundation.layout.* +import androidx.compose.material3.CircularProgressIndicator import androidx.compose.material3.Icon import androidx.compose.material3.Text import androidx.compose.runtime.Composable import androidx.compose.runtime.key import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier -import androidx.compose.ui.layout.ContentScale +import androidx.compose.ui.draw.clip +import androidx.compose.ui.platform.LocalContext +import androidx.compose.ui.platform.LocalDensity import androidx.compose.ui.res.painterResource import androidx.compose.ui.text.style.TextOverflow +import coil.compose.SubcomposeAsyncImage +import coil.request.ImageRequest +import com.tangem.core.ui.components.RectangleShimmer +import com.tangem.core.ui.components.block.BlockCard import com.tangem.core.ui.extensions.TextReference import com.tangem.core.ui.extensions.resolveReference import com.tangem.core.ui.res.TangemTheme import com.tangem.features.details.entity.UserWalletListUM import com.tangem.features.details.impl.R +import com.tangem.features.details.ui.coil.RotationTransformation @Composable internal fun UserWalletListBlock(state: UserWalletListUM, modifier: Modifier = Modifier) { @@ -43,6 +52,7 @@ private fun UserWalletItem(model: UserWalletListUM.UserWalletUM, modifier: Modif BlockCard( modifier = modifier, onClick = model.onClick, + enabled = model.isEnabled, ) { Row( modifier = Modifier @@ -52,39 +62,81 @@ private fun UserWalletItem(model: UserWalletListUM.UserWalletUM, modifier: Modif verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.spacedBy(TangemTheme.dimens.spacing12), ) { - Image( - modifier = Modifier - .width(TangemTheme.dimens.size24) - .height(TangemTheme.dimens.size36), - painter = painterResource(id = model.imageResId), - contentScale = ContentScale.FillBounds, - contentDescription = null, + Image(imageUrl = model.imageUrl) + NameAndInfo( + name = model.name, + information = model.information, ) - - Column( - modifier = Modifier.heightIn(min = TangemTheme.dimens.size40), - horizontalAlignment = Alignment.Start, - verticalArrangement = Arrangement.SpaceEvenly, - ) { - Text( - text = model.name, - style = TangemTheme.typography.subtitle1, - color = TangemTheme.colors.text.primary1, - maxLines = 1, - overflow = TextOverflow.Ellipsis, - ) - Text( - text = model.information.resolveReference(), - style = TangemTheme.typography.caption2, - color = TangemTheme.colors.text.tertiary, - maxLines = 1, - overflow = TextOverflow.Ellipsis, - ) - } } } } +@Composable +private fun NameAndInfo(name: TextReference, information: TextReference, modifier: Modifier = Modifier) { + Column( + modifier = modifier.heightIn(min = TangemTheme.dimens.size40), + horizontalAlignment = Alignment.Start, + verticalArrangement = Arrangement.SpaceEvenly, + ) { + Text( + text = name.resolveReference(), + style = TangemTheme.typography.subtitle1, + color = TangemTheme.colors.text.primary1, + maxLines = 1, + overflow = TextOverflow.Ellipsis, + ) + + AnimatedContent( + targetState = information.resolveReference(), + label = "User wallet information", + ) { information -> + Text( + text = information, + style = TangemTheme.typography.caption2, + color = TangemTheme.colors.text.tertiary, + maxLines = 1, + overflow = TextOverflow.Ellipsis, + ) + } + } +} + +@Composable +private fun Image(imageUrl: String, modifier: Modifier = Modifier) { + val imageModifier = modifier + .width(TangemTheme.dimens.size24) + .height(TangemTheme.dimens.size36) + .clip(TangemTheme.shapes.roundedCornersSmall) + + SubcomposeAsyncImage( + modifier = imageModifier, + model = ImageRequest.Builder(LocalContext.current) + .transformations(RotationTransformation(angle = 90f)) + .size( + width = with(LocalDensity.current) { TangemTheme.dimens.size36.roundToPx() }, + height = with(LocalDensity.current) { TangemTheme.dimens.size24.roundToPx() }, + ) + .data(imageUrl) + .crossfade(enable = true) + .allowHardware(enable = false) + .build(), + loading = { + RectangleShimmer( + modifier = imageModifier, + radius = TangemTheme.dimens.size2, + ) + }, + error = { + Image( + modifier = imageModifier, + painter = painterResource(id = R.drawable.img_card_wallet_2_gray_22_36), + contentDescription = null, + ) + }, + contentDescription = null, + ) +} + @Composable private fun AddWalletButton( text: TextReference, @@ -104,12 +156,25 @@ private fun AddWalletButton( verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.spacedBy(TangemTheme.dimens.spacing12), ) { - Icon( + AnimatedContent( modifier = Modifier.size(TangemTheme.dimens.size24), - painter = painterResource(id = R.drawable.ic_plus_24), - tint = TangemTheme.colors.icon.accent, - contentDescription = null, - ) + targetState = isInProgress, + label = "Add wallet progress", + ) { isInProgress -> + if (isInProgress) { + CircularProgressIndicator( + modifier = Modifier.size(TangemTheme.dimens.size24), + color = TangemTheme.colors.icon.accent, + ) + } else { + Icon( + modifier = Modifier.size(TangemTheme.dimens.size24), + painter = painterResource(id = R.drawable.ic_plus_24), + tint = TangemTheme.colors.icon.accent, + contentDescription = null, + ) + } + } Text( text = text.resolveReference(), diff --git a/features/details/impl/src/main/kotlin/com/tangem/features/details/ui/WalletConnectBlock.kt b/features/details/impl/src/main/kotlin/com/tangem/features/details/ui/WalletConnectBlock.kt index 11a28b3a75..b2e05c0504 100644 --- a/features/details/impl/src/main/kotlin/com/tangem/features/details/ui/WalletConnectBlock.kt +++ b/features/details/impl/src/main/kotlin/com/tangem/features/details/ui/WalletConnectBlock.kt @@ -8,6 +8,7 @@ import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.res.painterResource import androidx.compose.ui.res.stringResource +import com.tangem.core.ui.components.block.BlockCard import com.tangem.core.ui.res.TangemColorPalette import com.tangem.core.ui.res.TangemTheme import com.tangem.features.details.impl.R diff --git a/features/details/impl/src/main/kotlin/com/tangem/features/details/ui/coil/RotationTransformation.kt b/features/details/impl/src/main/kotlin/com/tangem/features/details/ui/coil/RotationTransformation.kt new file mode 100644 index 0000000000..ca7f0929d0 --- /dev/null +++ b/features/details/impl/src/main/kotlin/com/tangem/features/details/ui/coil/RotationTransformation.kt @@ -0,0 +1,22 @@ +package com.tangem.features.details.ui.coil + +import android.graphics.Bitmap +import android.graphics.Matrix +import coil.size.Size +import coil.transform.Transformation + +internal class RotationTransformation(private val angle: Float) : Transformation { + + override val cacheKey: String = "rotate:$angle" + + override suspend fun transform(input: Bitmap, size: Size): Bitmap { + val matrix = Matrix().apply { + val centerX = input.width / 2f + val centerY = input.height / 2f + + postRotate(angle, centerX, centerY) + } + + return Bitmap.createBitmap(input, 0, 0, input.width, input.height, matrix, true) + } +} \ No newline at end of file diff --git a/features/details/impl/src/main/kotlin/com/tangem/features/details/utils/ItemsBuilder.kt b/features/details/impl/src/main/kotlin/com/tangem/features/details/utils/ItemsBuilder.kt index aa18331772..f14c204327 100644 --- a/features/details/impl/src/main/kotlin/com/tangem/features/details/utils/ItemsBuilder.kt +++ b/features/details/impl/src/main/kotlin/com/tangem/features/details/utils/ItemsBuilder.kt @@ -1,61 +1,57 @@ package com.tangem.features.details.utils +import com.tangem.common.routing.AppRoute +import com.tangem.core.decompose.di.ComponentScoped import com.tangem.core.decompose.navigation.Router -import com.tangem.core.navigation.AppScreen +import com.tangem.core.navigation.url.UrlOpener +import com.tangem.core.ui.components.block.model.BlockUM import com.tangem.core.ui.extensions.resourceReference import com.tangem.core.ui.extensions.stringReference -import com.tangem.features.details.component.UserWalletListComponent -import com.tangem.features.details.component.WalletConnectComponent import com.tangem.features.details.entity.DetailsItemUM import com.tangem.features.details.impl.BuildConfig import com.tangem.features.details.impl.R -import com.tangem.features.details.routing.DetailsRoute import kotlinx.collections.immutable.ImmutableList import kotlinx.collections.immutable.persistentListOf import kotlinx.collections.immutable.toImmutableList +import javax.inject.Inject -internal class ItemsBuilder( - private val walletConnectComponent: WalletConnectComponent, - private val userWalletListComponent: UserWalletListComponent, +@ComponentScoped +internal class ItemsBuilder @Inject constructor( private val router: Router, + private val urlOpener: UrlOpener, ) { - suspend fun buldAll(): ImmutableList = buildList { - buildWalletConnectBlock()?.let(::add) - buildUserWalletListBlock().let(::add) - buildShopBlock().let(::add) - buildSettingsBlock().let(::add) - buildSupportBlock().let(::add) - }.toImmutableList() + fun buildAll(isWalletConnectAvailable: Boolean, onSupportClick: () -> Unit): ImmutableList = + buildList { + buildWalletConnectBlock(isWalletConnectAvailable)?.let(::add) + buildUserWalletListBlock().let(::add) + buildShopBlock().let(::add) + buildSettingsBlock().let(::add) + buildSupportBlock(onSupportClick).let(::add) + }.toImmutableList() - private suspend fun buildWalletConnectBlock(): DetailsItemUM? { - return if (walletConnectComponent.checkIsAvailable()) { - DetailsItemUM.Component( - id = "wallet_connect", - content = { - walletConnectComponent.View(modifier = it) - }, + private fun buildWalletConnectBlock(isWalletConnectAvailable: Boolean): DetailsItemUM? { + return if (isWalletConnectAvailable) { + DetailsItemUM.WalletConnect( + onClick = { router.push(AppRoute.WalletConnectSessions) }, ) } else { null } } - private fun buildUserWalletListBlock(): DetailsItemUM = DetailsItemUM.Component( - id = "user_wallet_list", - content = { - userWalletListComponent.View(modifier = it) - }, - ) + private fun buildUserWalletListBlock(): DetailsItemUM = DetailsItemUM.UserWalletList private fun buildShopBlock(): DetailsItemUM = DetailsItemUM.Basic( id = "shop", items = persistentListOf( DetailsItemUM.Basic.Item( id = "buy_tangem_wallet", - title = stringReference("Buy Tangem Wallet"), // TODO: Move to resources in [REDACTED_TASK_KEY] - iconRes = R.drawable.ic_tangem_24, - onClick = { router.push(DetailsRoute.Url(BUY_TANGEM_URL)) }, + block = BlockUM( + text = resourceReference(R.string.details_buy_wallet), + iconRes = R.drawable.ic_tangem_24, + onClick = { urlOpener.openUrl(BUY_TANGEM_URL) }, + ), ), ), ) @@ -65,36 +61,44 @@ internal class ItemsBuilder( items = buildList { DetailsItemUM.Basic.Item( id = "app_settings", - title = resourceReference(R.string.app_settings_title), - iconRes = R.drawable.ic_settings_24, - onClick = { router.push(DetailsRoute.Screen(AppScreen.AppSettings)) }, + block = BlockUM( + text = resourceReference(R.string.app_settings_title), + iconRes = R.drawable.ic_settings_24, + onClick = { router.push(AppRoute.AppSettings) }, + ), ).let(::add) if (BuildConfig.TESTER_MENU_ENABLED) { DetailsItemUM.Basic.Item( id = "tester_menu", - title = stringReference(value = "Tester menu"), - iconRes = R.drawable.ic_alert_24, - onClick = { router.push(DetailsRoute.TesterMenu) }, + block = BlockUM( + text = stringReference(value = "Tester menu"), + iconRes = R.drawable.ic_alert_24, + onClick = { router.push(AppRoute.TesterMenu) }, + ), ).let(::add) } }.toImmutableList(), ) - private fun buildSupportBlock(): DetailsItemUM = DetailsItemUM.Basic( + private fun buildSupportBlock(onClick: () -> Unit): DetailsItemUM = DetailsItemUM.Basic( id = "support", items = persistentListOf( DetailsItemUM.Basic.Item( id = "send_feedback", - title = stringReference("Send feedback"), // TODO: Move to resources in [REDACTED_TASK_KEY] - iconRes = R.drawable.ic_comment_24, - onClick = { router.push(DetailsRoute.Feedback) }, + block = BlockUM( + text = resourceReference(R.string.details_row_title_contact_to_support), + iconRes = R.drawable.ic_comment_24, + onClick = onClick, + ), ), DetailsItemUM.Basic.Item( id = "disclaimer", - title = resourceReference(R.string.disclaimer_title), - iconRes = R.drawable.ic_text_24, - onClick = { router.push(DetailsRoute.Screen(AppScreen.Disclaimer)) }, + block = BlockUM( + text = resourceReference(R.string.disclaimer_title), + iconRes = R.drawable.ic_text_24, + onClick = { router.push(AppRoute.Disclaimer(isTosAccepted = true)) }, + ), ), ), ) diff --git a/features/details/impl/src/main/kotlin/com/tangem/features/details/utils/SocialsBuilder.kt b/features/details/impl/src/main/kotlin/com/tangem/features/details/utils/SocialsBuilder.kt index 6896f1e7d0..8282bbd41c 100644 --- a/features/details/impl/src/main/kotlin/com/tangem/features/details/utils/SocialsBuilder.kt +++ b/features/details/impl/src/main/kotlin/com/tangem/features/details/utils/SocialsBuilder.kt @@ -1,15 +1,17 @@ package com.tangem.features.details.utils import androidx.compose.ui.text.intl.Locale -import com.tangem.core.decompose.navigation.Router +import com.tangem.core.decompose.di.ComponentScoped +import com.tangem.core.navigation.url.UrlOpener import com.tangem.features.details.entity.DetailsFooterUM import com.tangem.features.details.impl.R -import com.tangem.features.details.routing.DetailsRoute import kotlinx.collections.immutable.ImmutableList import kotlinx.collections.immutable.toImmutableList +import javax.inject.Inject -internal class SocialsBuilder( - private val router: Router, +@ComponentScoped +internal class SocialsBuilder @Inject constructor( + private val urlOpener: UrlOpener, ) { fun buildAll(): ImmutableList = Social.all.map { social -> @@ -29,7 +31,7 @@ internal class SocialsBuilder( social.url } - router.push(DetailsRoute.Url(url)) + urlOpener.openUrl(url) } private enum class Social( diff --git a/features/details/impl/src/main/kotlin/com/tangem/features/details/utils/UserWalletMappers.kt b/features/details/impl/src/main/kotlin/com/tangem/features/details/utils/UserWalletMappers.kt new file mode 100644 index 0000000000..a9782fc1d9 --- /dev/null +++ b/features/details/impl/src/main/kotlin/com/tangem/features/details/utils/UserWalletMappers.kt @@ -0,0 +1,110 @@ +package com.tangem.features.details.utils + +import com.tangem.core.ui.extensions.* +import com.tangem.core.ui.utils.BigDecimalFormatter +import com.tangem.domain.appcurrency.model.AppCurrency +import com.tangem.domain.models.scan.CardDTO +import com.tangem.domain.tokens.model.TotalFiatBalance +import com.tangem.domain.wallets.models.UserWallet +import com.tangem.domain.wallets.models.UserWalletId +import com.tangem.features.details.entity.UserWalletListUM.UserWalletUM +import com.tangem.features.details.impl.R +import com.tangem.utils.StringsSigns.STARS +import kotlinx.collections.immutable.ImmutableList +import kotlinx.collections.immutable.toImmutableList + +internal fun List.toUiModels( + onClick: (UserWalletId) -> Unit, + appCurrency: AppCurrency? = null, + balances: Map = emptyMap(), + isLoading: Boolean = true, + isBalancesHidden: Boolean = false, +): ImmutableList = this.map { model -> + val balance = balances[model.walletId] + + model.toUiModel( + balance = balance, + appCurrency = appCurrency, + isLoading = isLoading, + isBalanceHidden = isBalancesHidden, + onClick = { onClick(model.walletId) }, + ) +}.toImmutableList() + +private fun UserWallet.toUiModel( + balance: TotalFiatBalance?, + appCurrency: AppCurrency?, + isLoading: Boolean, + isBalanceHidden: Boolean, + onClick: () -> Unit, +): UserWalletUM = UserWalletUM( + id = walletId, + name = stringReference(name), + information = getInfo( + appCurrency = appCurrency, + balance = balance, + isBalanceHidden = isBalanceHidden, + isLoading = isLoading, + ), + imageUrl = artworkUrl, + isEnabled = !isLocked, + onClick = onClick, +) + +private fun UserWallet.getInfo( + appCurrency: AppCurrency?, + balance: TotalFiatBalance?, + isBalanceHidden: Boolean, + isLoading: Boolean, +): TextReference { + val dividerRef = stringReference(value = " • ") + + val cardCount = getCardCount() + val cardCountRef = TextReference.PluralRes( + id = R.plurals.card_label_card_count, + count = cardCount, + formatArgs = wrappedList(cardCount), + ) + + return when { + isBalanceHidden -> combinedReference(cardCountRef, dividerRef, stringReference(STARS)) + isLocked -> combinedReference(cardCountRef, dividerRef, resourceReference(R.string.common_locked)) + isLoading -> cardCountRef + else -> getBalanceInfo(balance, appCurrency, cardCountRef, dividerRef) + } +} + +private fun getBalanceInfo( + balance: TotalFiatBalance?, + appCurrency: AppCurrency?, + cardCountRef: TextReference, + dividerRef: TextReference, +): TextReference { + val amount = when (balance) { + is TotalFiatBalance.Loaded -> balance.amount + is TotalFiatBalance.Failed, + is TotalFiatBalance.Loading, + null, + -> null + } + + return if (amount != null && appCurrency != null) { + val formattedAmount = BigDecimalFormatter.formatFiatAmount( + fiatAmount = amount, + fiatCurrencyCode = appCurrency.code, + fiatCurrencySymbol = appCurrency.symbol, + ) + val amountRef = stringReference(formattedAmount) + combinedReference(cardCountRef, dividerRef, amountRef) + } else { + combinedReference(cardCountRef, dividerRef, stringReference(BigDecimalFormatter.EMPTY_BALANCE_SIGN)) + } +} + +private fun UserWallet.getCardCount() = when (val status = scanResponse.card.backupStatus) { + is CardDTO.BackupStatus.Active -> status.cardCount.inc() + is CardDTO.BackupStatus.CardLinked -> status.cardCount.inc() + is CardDTO.BackupStatus.NoBackup, + null, + -> 1 +} \ No newline at end of file diff --git a/features/details/impl/src/main/kotlin/com/tangem/features/details/utils/UserWalletSaver.kt b/features/details/impl/src/main/kotlin/com/tangem/features/details/utils/UserWalletSaver.kt new file mode 100644 index 0000000000..80a7f98ce1 --- /dev/null +++ b/features/details/impl/src/main/kotlin/com/tangem/features/details/utils/UserWalletSaver.kt @@ -0,0 +1,153 @@ +package com.tangem.features.details.utils + +import androidx.compose.ui.res.stringResource +import arrow.core.raise.Raise +import arrow.core.raise.ensureNotNull +import arrow.core.raise.fold +import arrow.core.raise.recover +import com.tangem.common.routing.AppRoute +import com.tangem.core.analytics.models.AnalyticsParam +import com.tangem.core.decompose.di.ComponentScoped +import com.tangem.core.decompose.navigation.Router +import com.tangem.core.decompose.navigation.popTo +import com.tangem.core.decompose.ui.UiMessageSender +import com.tangem.core.ui.components.SimpleOkDialog +import com.tangem.core.ui.extensions.TextReference +import com.tangem.core.ui.extensions.isNullOrEmpty +import com.tangem.core.ui.extensions.resourceReference +import com.tangem.core.ui.extensions.stringReference +import com.tangem.core.ui.message.ContentMessage +import com.tangem.core.ui.message.SnackbarMessage +import com.tangem.domain.card.ScanCardProcessor +import com.tangem.domain.models.scan.ScanResponse +import com.tangem.domain.redux.ReduxStateHolder +import com.tangem.domain.wallets.builder.UserWalletBuilder +import com.tangem.domain.wallets.models.SaveWalletError +import com.tangem.domain.wallets.models.UserWallet +import com.tangem.domain.wallets.usecase.GenerateWalletNameUseCase +import com.tangem.domain.wallets.usecase.SaveWalletUseCase +import com.tangem.domain.wallets.usecase.ShouldSaveUserWalletsSyncUseCase +import com.tangem.features.details.impl.R +import javax.inject.Inject + +@ComponentScoped +@Suppress("LongParameterList") +internal class UserWalletSaver @Inject constructor( + private val scanCardProcessor: ScanCardProcessor, + private val saveWalletUseCase: SaveWalletUseCase, + private val generateWalletNameUseCase: GenerateWalletNameUseCase, + private val shouldSaveUserWalletsSyncUseCase: ShouldSaveUserWalletsSyncUseCase, + private val reduxStateHolder: ReduxStateHolder, + private val messageSender: UiMessageSender, + private val router: Router, +) { + + suspend fun scanAndSaveUserWallet() = recover( + block = { + val response = scanCard() ?: return@recover + val userWallet = createUserWallet(response) + + saveWallet(userWallet) + }, + recover = { error -> + val message = error.message + + if (!message.isNullOrEmpty()) { + messageSender.send(SnackbarMessage(message)) + } + }, + ) + + private suspend fun Raise.saveWallet(userWallet: UserWallet) { + fold( + block = { saveWalletUseCase(userWallet).bind() }, + recover = { error -> + when (error) { + is SaveWalletError.WalletAlreadySaved -> { + if (shouldSaveUserWalletsSyncUseCase()) { + selectUserWallet() + } else { + router.popTo() + } + } + is SaveWalletError.DataError -> { + val messageRef = ensureNotNull(error.messageId?.let(::resourceReference)) { + Error.Unknown + } + + raise(Error.Message(messageRef)) + } + } + }, + transform = { + // call only if wallet is successfully saved + reduxStateHolder.onUserWalletSelected(userWallet) + + router.popTo() + }, + ) + } + + private fun selectUserWallet() { + messageSender.send( + message = ContentMessage { onDismiss -> + SimpleOkDialog( + message = stringResource(id = R.string.user_wallet_list_error_wallet_already_saved), + onDismissDialog = onDismiss, + ) + }, + ) + } + + private suspend fun Raise.createUserWallet(response: ScanResponse): UserWallet { + val userWallet = UserWalletBuilder(response, generateWalletNameUseCase).build() + + return ensureNotNull(userWallet) { Error.Unknown } + } + + private suspend fun Raise.scanCard(): ScanResponse? { + var response: ScanResponse? = null + + scanCardProcessor.scan( + analyticsSource = AnalyticsParam.ScreensSources.Settings, + onWalletNotCreated = { + /* no-op */ + }, + disclaimerWillShow = { + router.pop() + }, + onSuccess = { + response = it + }, + onFailure = { tangemError -> + val error = if (!tangemError.silent) { + val message = tangemError.messageResId + ?.let(::resourceReference) + ?: stringReference(tangemError.customMessage) + + Error.Message(message) + } else { + Error.Silent + } + + raise(error) + }, + ) + + return response + } + + sealed class Error { + + open val message: TextReference? = null + + data object Silent : Error() + + data class Message(override val message: TextReference) : Error() + + data object Unknown : Error() { + + override val message: TextReference = resourceReference(R.string.common_unknown_error) + } + } +} \ No newline at end of file diff --git a/features/details/impl/src/main/kotlin/com/tangem/features/details/utils/UserWalletsFetcher.kt b/features/details/impl/src/main/kotlin/com/tangem/features/details/utils/UserWalletsFetcher.kt new file mode 100644 index 0000000000..e141c4034e --- /dev/null +++ b/features/details/impl/src/main/kotlin/com/tangem/features/details/utils/UserWalletsFetcher.kt @@ -0,0 +1,104 @@ +package com.tangem.features.details.utils + +import arrow.core.Either +import com.tangem.common.routing.AppRoute +import com.tangem.core.decompose.di.ComponentScoped +import com.tangem.core.decompose.navigation.Router +import com.tangem.core.decompose.ui.UiMessageSender +import com.tangem.core.ui.extensions.resourceReference +import com.tangem.core.ui.message.SnackbarMessage +import com.tangem.domain.appcurrency.GetSelectedAppCurrencyUseCase +import com.tangem.domain.appcurrency.error.SelectedAppCurrencyError +import com.tangem.domain.appcurrency.model.AppCurrency +import com.tangem.domain.balancehiding.BalanceHidingSettings +import com.tangem.domain.balancehiding.GetBalanceHidingSettingsUseCase +import com.tangem.domain.core.lce.Lce +import com.tangem.domain.core.lce.lce +import com.tangem.domain.core.utils.getOrElse +import com.tangem.domain.core.utils.toLce +import com.tangem.domain.tokens.GetWalletTotalBalanceUseCase +import com.tangem.domain.tokens.error.TokenListError +import com.tangem.domain.tokens.model.TotalFiatBalance +import com.tangem.domain.wallets.models.UserWallet +import com.tangem.domain.wallets.models.UserWalletId +import com.tangem.domain.wallets.usecase.GetWalletsUseCase +import com.tangem.features.details.entity.UserWalletListUM.UserWalletUM +import com.tangem.features.details.impl.R +import kotlinx.collections.immutable.ImmutableList +import kotlinx.coroutines.ExperimentalCoroutinesApi +import kotlinx.coroutines.flow.* +import javax.inject.Inject + +@ComponentScoped +internal class UserWalletsFetcher @Inject constructor( + getWalletsUseCase: GetWalletsUseCase, + private val getWalletTotalBalanceUseCase: GetWalletTotalBalanceUseCase, + private val getSelectedAppCurrencyUseCase: GetSelectedAppCurrencyUseCase, + private val getBalanceHidingSettingsUseCase: GetBalanceHidingSettingsUseCase, + private val router: Router, + private val messageSender: UiMessageSender, +) { + + @OptIn(ExperimentalCoroutinesApi::class) + val userWallets: Flow> = getWalletsUseCase().transformLatest { wallets -> + emit(wallets.toUiModels(onClick = ::navigateToWalletSettings)) + + combine( + getSelectedAppCurrencyUseCase().distinctUntilChanged(), + getBalanceHidingSettingsUseCase().distinctUntilChanged(), + getWalletTotalBalanceUseCase(wallets.map(UserWallet::walletId)).distinctUntilChanged(), + ) { maybeAppCurrency, balanceHidingSettings, maybeBalances -> + val models = createUiModels( + wallets = wallets, + maybeAppCurrency = maybeAppCurrency, + maybeBalances = maybeBalances, + balanceHidingSettings = balanceHidingSettings, + ).getOrElse( + ifLoading = { return@combine }, + ifError = { + val message = resourceReference(R.string.common_unknown_error) + messageSender.send(SnackbarMessage(message)) + + return@combine + }, + ) + + emit(models) + }.collect() + } + + private fun createUiModels( + wallets: List, + maybeAppCurrency: Either, + maybeBalances: Lce>, + balanceHidingSettings: BalanceHidingSettings, + ): Lce> = lce { + val balances = withError( + transform = { Error.UnableToGetBalances }, + block = { maybeBalances.bindOrNull().orEmpty() }, + ) + val appCurrency = withError( + transform = { Error.UnableToGetAppCurrency }, + block = { maybeAppCurrency.toLce().bind() }, + ) + + wallets.toUiModels( + appCurrency = appCurrency, + balances = balances, + onClick = ::navigateToWalletSettings, + isBalancesHidden = balanceHidingSettings.isBalanceHidden, + isLoading = maybeBalances.isLoading(), + ) + } + + private fun navigateToWalletSettings(userWalletId: UserWalletId) { + router.push(AppRoute.WalletSettings(userWalletId)) + } + + sealed class Error { + + data object UnableToGetAppCurrency : Error() + + data object UnableToGetBalances : Error() + } +} \ No newline at end of file diff --git a/features/details/impl/src/main/res/drawable/ill_card_note_bnb_211_343.png b/features/details/impl/src/main/res/drawable/ill_card_note_bnb_211_343.png deleted file mode 100644 index 033efd2699..0000000000 Binary files a/features/details/impl/src/main/res/drawable/ill_card_note_bnb_211_343.png and /dev/null differ diff --git a/features/details/impl/src/main/res/drawable/ill_card_note_eth_211_343.png b/features/details/impl/src/main/res/drawable/ill_card_note_eth_211_343.png deleted file mode 100644 index b338ee1eb5..0000000000 Binary files a/features/details/impl/src/main/res/drawable/ill_card_note_eth_211_343.png and /dev/null differ diff --git a/features/details/impl/src/main/res/drawable/ill_card_wallet_2_211_343.png b/features/details/impl/src/main/res/drawable/ill_card_wallet_2_211_343.png deleted file mode 100644 index 9625b941a1..0000000000 Binary files a/features/details/impl/src/main/res/drawable/ill_card_wallet_2_211_343.png and /dev/null differ diff --git a/features/details/impl/src/main/res/drawable/img_card_wallet_2_gray_22_36.xml b/features/details/impl/src/main/res/drawable/img_card_wallet_2_gray_22_36.xml new file mode 100644 index 0000000000..977d693e60 --- /dev/null +++ b/features/details/impl/src/main/res/drawable/img_card_wallet_2_gray_22_36.xml @@ -0,0 +1,13 @@ + + + + + diff --git a/features/disclaimer/api/.gitignore b/features/disclaimer/api/.gitignore new file mode 100644 index 0000000000..42afabfd2a --- /dev/null +++ b/features/disclaimer/api/.gitignore @@ -0,0 +1 @@ +/build \ No newline at end of file diff --git a/features/disclaimer/api/build.gradle.kts b/features/disclaimer/api/build.gradle.kts new file mode 100644 index 0000000000..7b97fa25c1 --- /dev/null +++ b/features/disclaimer/api/build.gradle.kts @@ -0,0 +1,16 @@ +plugins { + alias(deps.plugins.android.library) + alias(deps.plugins.kotlin.android) + id("configuration") +} + +android { + namespace = "com.tangem.features.disclaimer.api" +} + +dependencies { + + /* Project - Core */ + implementation(projects.core.decompose) + implementation(projects.core.ui) +} \ No newline at end of file diff --git a/features/disclaimer/api/src/main/java/com/tangem/features/disclaimer/api/components/DisclaimerComponent.kt b/features/disclaimer/api/src/main/java/com/tangem/features/disclaimer/api/components/DisclaimerComponent.kt new file mode 100644 index 0000000000..df556bb776 --- /dev/null +++ b/features/disclaimer/api/src/main/java/com/tangem/features/disclaimer/api/components/DisclaimerComponent.kt @@ -0,0 +1,12 @@ +package com.tangem.features.disclaimer.api.components + +import com.tangem.core.decompose.factory.ComponentFactory +import com.tangem.core.ui.decompose.ComposableContentComponent + +interface DisclaimerComponent : ComposableContentComponent { + interface Factory : ComponentFactory + + data class Params( + val isTosAccepted: Boolean, + ) +} \ No newline at end of file diff --git a/features/disclaimer/impl/.gitignore b/features/disclaimer/impl/.gitignore new file mode 100644 index 0000000000..42afabfd2a --- /dev/null +++ b/features/disclaimer/impl/.gitignore @@ -0,0 +1 @@ +/build \ No newline at end of file diff --git a/features/disclaimer/impl/build.gradle.kts b/features/disclaimer/impl/build.gradle.kts new file mode 100644 index 0000000000..d60dcd1885 --- /dev/null +++ b/features/disclaimer/impl/build.gradle.kts @@ -0,0 +1,51 @@ +plugins { + alias(deps.plugins.android.library) + alias(deps.plugins.kotlin.android) + alias(deps.plugins.kotlin.kapt) + alias(deps.plugins.hilt.android) + id("configuration") +} + +android { + namespace = "com.tangem.features.disclaimer.impl" +} + +dependencies { + /* AndroidX */ + implementation(deps.lifecycle.compose) + implementation(deps.androidx.activity.compose) + + /** Compose */ + implementation(deps.compose.foundation) + implementation(deps.compose.ui) + implementation(deps.compose.ui.tooling) + implementation(deps.compose.accompanist.systemUiController) + implementation(deps.compose.accompanist.permission) + implementation(deps.compose.accompanist.webView) + implementation(deps.compose.material3) + implementation(deps.compose.material) + + /** Core modules */ + implementation(projects.core.ui) + implementation(projects.core.utils) + implementation(projects.core.featuretoggles) + implementation(projects.core.navigation) + implementation(projects.core.decompose) + implementation(projects.common.routing) + + /** Domain modules */ + implementation(projects.domain.models) + implementation(projects.domain.card) + implementation(projects.domain.settings) + + /** Feature modules */ + implementation(projects.features.disclaimer.api) + implementation(projects.features.pushNotifications.api) + + /** Other dependencies */ + implementation(deps.arrow.core) + + /** DI */ + implementation(deps.hilt.android) + kapt(deps.hilt.kapt) +} \ No newline at end of file diff --git a/features/disclaimer/impl/src/main/java/com/tangem/features/disclaimer/impl/component/impl/DefaultDisclaimerComponent.kt b/features/disclaimer/impl/src/main/java/com/tangem/features/disclaimer/impl/component/impl/DefaultDisclaimerComponent.kt new file mode 100644 index 0000000000..5fbd86f488 --- /dev/null +++ b/features/disclaimer/impl/src/main/java/com/tangem/features/disclaimer/impl/component/impl/DefaultDisclaimerComponent.kt @@ -0,0 +1,40 @@ +package com.tangem.features.disclaimer.impl.component.impl + +import androidx.activity.compose.BackHandler +import androidx.compose.runtime.Composable +import androidx.compose.runtime.getValue +import androidx.compose.ui.Modifier +import androidx.lifecycle.compose.collectAsStateWithLifecycle +import com.tangem.core.decompose.context.AppComponentContext +import com.tangem.core.decompose.model.getOrCreateModel +import com.tangem.features.disclaimer.api.components.DisclaimerComponent +import com.tangem.features.disclaimer.impl.model.DisclaimerModel +import com.tangem.features.disclaimer.impl.ui.DisclaimerScreen +import dagger.assisted.Assisted +import dagger.assisted.AssistedFactory +import dagger.assisted.AssistedInject + +internal class DefaultDisclaimerComponent @AssistedInject constructor( + @Assisted context: AppComponentContext, + @Assisted private val params: DisclaimerComponent.Params, +) : DisclaimerComponent, AppComponentContext by context { + + private val model: DisclaimerModel = getOrCreateModel(params) + + @Composable + override fun Content(modifier: Modifier) { + val state by model.state.collectAsStateWithLifecycle() + + BackHandler(onBack = state.popBack) + DisclaimerScreen(state = state) + } + + @AssistedFactory + interface Factory : DisclaimerComponent.Factory { + + override fun create( + context: AppComponentContext, + params: DisclaimerComponent.Params, + ): DefaultDisclaimerComponent + } +} \ No newline at end of file diff --git a/features/disclaimer/impl/src/main/java/com/tangem/features/disclaimer/impl/di/ComponentModule.kt b/features/disclaimer/impl/src/main/java/com/tangem/features/disclaimer/impl/di/ComponentModule.kt new file mode 100644 index 0000000000..1605d6bbd6 --- /dev/null +++ b/features/disclaimer/impl/src/main/java/com/tangem/features/disclaimer/impl/di/ComponentModule.kt @@ -0,0 +1,18 @@ +package com.tangem.features.disclaimer.impl.di + +import com.tangem.features.disclaimer.api.components.DisclaimerComponent +import com.tangem.features.disclaimer.impl.component.impl.DefaultDisclaimerComponent +import dagger.Binds +import dagger.Module +import dagger.hilt.InstallIn +import dagger.hilt.components.SingletonComponent +import javax.inject.Singleton + +@Module +@InstallIn(SingletonComponent::class) +internal interface ComponentModule { + + @Binds + @Singleton + fun bindDisclaimerComponentFactory(factory: DefaultDisclaimerComponent.Factory): DisclaimerComponent.Factory +} \ No newline at end of file diff --git a/features/disclaimer/impl/src/main/java/com/tangem/features/disclaimer/impl/di/ModelModule.kt b/features/disclaimer/impl/src/main/java/com/tangem/features/disclaimer/impl/di/ModelModule.kt new file mode 100644 index 0000000000..a589336c78 --- /dev/null +++ b/features/disclaimer/impl/src/main/java/com/tangem/features/disclaimer/impl/di/ModelModule.kt @@ -0,0 +1,20 @@ +package com.tangem.features.disclaimer.impl.di + +import com.tangem.core.decompose.di.DecomposeComponent +import com.tangem.core.decompose.model.Model +import com.tangem.features.disclaimer.impl.model.DisclaimerModel +import dagger.Binds +import dagger.Module +import dagger.hilt.InstallIn +import dagger.multibindings.ClassKey +import dagger.multibindings.IntoMap + +@Module +@InstallIn(DecomposeComponent::class) +internal interface ModelModule { + + @Binds + @IntoMap + @ClassKey(DisclaimerModel::class) + fun provideDisclaimerModel(model: DisclaimerModel): Model +} \ No newline at end of file diff --git a/features/disclaimer/impl/src/main/java/com/tangem/features/disclaimer/impl/entity/DisclaimerUM.kt b/features/disclaimer/impl/src/main/java/com/tangem/features/disclaimer/impl/entity/DisclaimerUM.kt new file mode 100644 index 0000000000..155a91269b --- /dev/null +++ b/features/disclaimer/impl/src/main/java/com/tangem/features/disclaimer/impl/entity/DisclaimerUM.kt @@ -0,0 +1,18 @@ +package com.tangem.features.disclaimer.impl.entity + +internal data class DisclaimerUM( + val url: String, + val isTosAccepted: Boolean, + val onAccept: (Boolean) -> Unit, + val popBack: () -> Unit, +) + +internal object DummyDisclaimer { + + val state = DisclaimerUM( + url = "https://tangem.com/tangem_tos.html", + isTosAccepted = false, + onAccept = {}, + popBack = {}, + ) +} \ No newline at end of file diff --git a/features/disclaimer/impl/src/main/java/com/tangem/features/disclaimer/impl/local/LocalTermOfServices.kt b/features/disclaimer/impl/src/main/java/com/tangem/features/disclaimer/impl/local/LocalTermOfServices.kt new file mode 100644 index 0000000000..1d60540d5e --- /dev/null +++ b/features/disclaimer/impl/src/main/java/com/tangem/features/disclaimer/impl/local/LocalTermOfServices.kt @@ -0,0 +1,233 @@ +package com.tangem.features.disclaimer.impl.local + +internal val localTermsOfServices = """ + + + + + + + + Legal Disclaimer + + + + +

TANGEM WALLET AND TANGEM MOBILE APPLICATION

+

Terms of Service

+ +

PLEASE READ THESE TERMS OF SERVICE CAREFULLY. BY CLICKING TO ACCEPT, OR BY ACCESSING OR USING OUR SERVICES, YOU AGREE THAT YOU HAVE READ, UNDERSTOOD, AND ACCEPT ALL OF THE TERMS AND CONDITIONS CONTAINED HEREIN. BY PURCHASE OF TANGEM WALLET (CARD) OR BY USING TANGEM WALLET (CARD) OR BY USING TANGEM MOBILE APPLICATION, YOU DEMONSTRATE YOUR AGREEMENT TO THESE TERMS AND CONDITIONS CONTAINED HEREIN.

+ +

1. DEFINITIONS

+

“Cardholder” refers to an individual who owns a Tangem Card that is used to access the Tangem Wallet and Tangem Mobile Application.

+

“Blockchain Asset” refers to digital assets, including but not limited to cryptocurrencies, that can be managed through the Tangem Wallet.

+

“Blockchain Address” means a unique identifier that serves as a virtual location of the Blockchain Asset in the blockchain.

+

“Card Transaction” means transfer of Blockchain Asset from the Blockchain Address associated with the Public Key stored on the Tangem Wallet (Card).

+

“Official Mobile Application” means an application developed and distributed by Tangem, providing interoperability between Tangem Wallet (Card) and blockchain, and working on NFC-capable smartphones and tablets using Google Android and Apple iOS operation systems.

+

“Private Key” means a secret cryptographic key which provides full control over a Blockchain Asset.

+

“Tangem” means Tangem AG, a company incorporated under the laws of Switzerland (CHE-390.112.525), with a registered address at Baarerstrasse 10, CH-6300 Zug.

+

“Public Key” means a cryptographic key, which provides access to information about a Blockchain Asset, including but not limited to Blockchain Address

+

“Services” means the purchase and/or use of Tangem Wallet (Card) and the services or any other features, technologies or functionalities linked to the Tangem Wallet (Card) provided or operated by Tangem via the website or Official Mobile Applications.

+

“Tangem Wallet (Card) / Tangem Card / Card” means physical card which stores Private Key and Public Key and is used as a backup card.

+ +

2. DISCLAIMER

+

2.1. Bitcoin and other cryptocurrencies are virtual currencies, digital representations of value that are neither issued by a central bank of any state or public authority attached to a conventional currency, but may be used by any natural or legal persons as a means of exchange and can be transferred, stored or traded electronically.

+

2.2. Blockchain technologies and related services are subject to continuous regulatory changes and scrutiny around the world, including but not limited to anti-money laundering and financial regulations. You acknowledge that certain Services, including their availability, could be impacted by one or more regulatory requirements.

+

2.3. No advice. No part of the information herein should be considered to be business, legal, financial or tax advice regarding the Products or Services. You should consult your own legal, financial, tax or other professional advisor regarding the matter. By using the Services, you represent that Tangem is responsible neither for obtaining the information about tax or similar obligations arising in relation to usage of the Services nor for fulfillment of such tax (or similar) obligations.

+ +

3. GENERAL PROVISIONS

+

3.1. These Terms of Service (the “Terms”) govern the use of Tangem Wallet and/or Official Mobile Application provided by Tangem (referred to as "Tangem", "we" or "us" in this document) and the related services or any other features, technologies or functionalities linked to Tangem Wallet (Card). Tangem is a company incorporated under the laws of Switzerland (CHE-390.112.525), with a registered address at Baarerstrasse 10, CH-6300 Zug.

+

3.2. Tangem Cards may be used for storage of Private Key and Public Key to Cardholder’s Blockchain Assets and authentication of Card Transactions with the purpose of “person-to-person” transfer of Blockchain Assets to another blockchain address.

+

3.3. Official Mobile Application is intended for usage only with Tangem Wallet (Card), providing interoperability between the cards and blockchain via NFC interface. Official Mobile Application DOES NOT:

+

3.3.1. Generate, store, transmit, or have access to private (secret) cryptographic keys to blockchain wallets holding Blockchain assets.

+

3.3.2. Generate, store, transmit, or have access to secret keys, passwords, passphrases, recovery phrases that can be used to restore or to copy private (secret) keys to blockchain wallets holding Blockchain assets.

+

3.3.3 Provide exchange, trading, investment services on behalf of Tangem.

+ +

4. RIGHTS AND OBLIGATIONS

+

4.1. Cardholder agrees that these Terms are binding.

+

4.2. Cardholder shall be the only person having physical access to Tangem Wallet.

+

4.3. Cardholder acknowledges and agrees that Tangem does not provide backup or recovery of Private Key and Public Key stored by Tangem Wallet (Card).

+

4.4. Tangem does not keep records of Cardholder’s personal data, the amount of Blockchain Asset stored on the Card, the Private Key, or personalized history of Card usage.

+ +

5. COSTS

+

5.1. Costs, fees and commission (the “Costs”) may be charged in connection with the use of Card. These Costs are disclosed in Official Mobile Applications to Cardholder.

+

5.2. Amendments to Costs due to changing expenses or market conditions may be made at any time via adjustments to the fee schedules. Such amendments shall be communicated to Cardholder in an appropriate manner. Upon notification and in the event of the objection, Cardholder may cancel the Card with immediate effect.

+ +

6. CARDHOLDER’S DUTIES OF CARE

+

6.1. In particular, Cardholder shall exercise the following duties of care:

+

6.1.1. Upon receiving the Card, Cardholder should download Official Mobile Applications in order to create the backup and if applicable determine the amount of Blockchain Asset stored through Official Mobile Applications.

+

6.1.2. Cardholder shall keep the means of access and Tangem Wallet (Card) with care and all Cards separate from each other.

+

6.1.3. Cardholder must always know where Tangem Wallet (Card) is and regularly ensure that it is still in his/her possession. He/she shall avoid even temporary possession of Tangem Wallet (Card) by any other person.

+

6.1.4. Cardholder shall treat Tangem Wallet in the same manner as physical money (cash) and keep it safe. If any of the Card is lost, stolen or destroyed, control over the corresponding Blockchain Asset may be permanently lost.

+

6.1.5. Before using the Card with Official Mobile Applications, Cardholder shall locate Official Mobile Applications in Google Play or Apple app store and install it as instructed in the Card box.

+

6.1.6. Card shall be used only with Official Mobile Applications and as instructed in the Card box.

+

6.1.7. Official Mobile Application shall be the only source of information about the Blockchain Address of the Blockchain Asset and corresponding Public Key stored on Tangem Wallet (Card).

+

6.1.8. Cardholder shall only use Near-Field Devices (the “NFC”) devices that are capable of running Official Mobile Applications. He/she shall avoid leaving Tangem Wallet (Card) in the proximity of the NFC devices of other persons.

+

6.1.9. Tangem Wallet (Card) shall be used only for physically tapping and holding near Cardholder’s NFC device when Official Mobile Application requests it.

+

6.1.10. Cardholder shall keep Tangem Wallet (Card) with care and protect Tangem Wallet (Card) from mechanical damage, high temperatures, strong electromagnetic fields, and other harmful factors.

+

6.2. No retrieval of Private Keys. Tangem operates non-custodial services, which means that we do not store, nor do we have access to your Blockchain Assets nor your Private Keys. Tangem does not have access to or store passwords, 24-word Recovery Phrase, Private Keys, passphrases, transaction history, PIN, or other credentials associated with your use of the Services. You are solely responsible for remembering, storing, and keeping your credentials in a secure location, away from prying eyes. Any third party with knowledge of one or more of your 24-word Recovery Phrase can gain control of the Private Keys associated with your Tangem Wallet (Card) or of the 24-word Recovery Phrase, and therefore steal your Blockchain Assets, without any possibility for you or Tangem to retrieve them.

+ +

7. RIGHTS AND RESPONSIBILITIES OF CARDHOLDER

+

7.1. Cardholder is liable for all liabilities arising from the use of Tangem Wallet (Card) and/or Tangem Official Mobile Application. Any disputes in relation to discrepancies and complaints about goods or services and any resulting claims must be settled directly by Cardholder with the respective Reseller.

+

7.2. As a matter of principle, Cardholder is liable for any risks resulting from the misuse of Tangem Wallet (Card) and/or Official Mobile Application. In any case, Cardholder is solely liable for all transactions authorized using a means of access.

+

7.3. Any loss or damage resulting from the forwarding of Tangem Wallet (Card) and/or means of access shall be borne by Cardholder.

+

7.4. Loss or damage incurred by Cardholder in connection with the possession or use of Tangem Wallet (Card) and/or Official Mobile Application shall be borne solely by Cardholder. Tangem assumes no liability if Tangem Wallet (Card) and/or Official Mobile Application cannot be used due to a technical defect or because it has been canceled, blocked or the spending limit has been adjusted.

+

7.5. Cardholder is only permitted to use Tangem Wallet (Card) and Official Mobile Application for his personal, non-commercial use. Cardholder is not allowed to resell Tangem Wallet (Card).

+

7.6. Cardholder is solely responsible to determinate what, if any, taxes apply to Card Transactions. Tangem or contributors to Official Mobile Applications are NOT responsible for determining the taxes that apply to Card Transactions.

+

7.7. Before Cardholder engages in transactions using an electronic system, Cardholder should carefully review the rules and regulations of the exchanges offering the system and/or listing the instruments Cardholder intends to trade. Online trading has inherent risk due to system response and access times that may vary due to market conditions, system performance, and other factors. Cardholder should understand, fully accept and take on these and additional risks before trading.

+

7.8. There is considerable exposure to risk in the Blockchain Asset exchange transaction. Any transaction involving the Blockchain Asset involves risks including, but not limited to, the potential for changing economic conditions that may substantially affect the price or liquidity of the Blockchain Asset. Investments in the Blockchain Asset exchange speculation may also be susceptible to sharp rises and falls as the relevant market values fluctuate. It is for this reason that when speculating in such markets it is advisable to use only risk capital.

+

7.9. Before initiating any transactions through third-party resources via widgets or links within the application, Cardholder is expressly advised to meticulously review and comprehend the terms, rules, and regulations governing such resources. It is imperative for Cardholder to be cognizant of the inherent risks associated with online trading, including variations in system response times, access delays influenced by market conditions, system performance, and other pertinent factors.

+

7.10. Cardholder unequivocally assumes sole responsibility for all actions undertaken, encompassing but not limited to swap transactions, on-ramp, and off-ramp activities, when transitioning to third-party resources through widgets or links within the application. This responsibility extends to compliance with the terms and conditions of the relevant third-party resources and adherence to applicable laws and regulations.

+

7.11. Cardholder acknowledges and accepts that the use of third-party resources involves inherent risks, and Tangem shall bear no liability for the consequences arising from Cardholder's independent actions on these external platforms.

+

7.12. Cardholder is responsible for implementing adequate security measures and precautions when interacting with third-party resources to safeguard personal information, financial assets, and to mitigate potential risks associated with such engagements.

+

7.13. Cardholder agrees to indemnify and hold Tangem, its affiliates, and service providers harmless from any claims, losses, or damages incurred as a result of their actions on third-party platforms, as outlined in the Terms of Services.

+

7.14. Tangem explicitly disclaims any affiliation, endorsement, or responsibility for the content, policies, or transactions on third-party resources, and Cardholder interactions with such resources are entirely at their own risk.

+ +

8. THIRD-PARTY SERVICES

+

8.1. We may incorporate, reference and/or provide access to Third Party Services. For instance, buy, sell and crypto to crypto exchange (“swap”) services are Third Party Services. You agree that your use of Third-Party Services is subject to separate terms and conditions between you and the third-party identified in Tangem.

+

8.2. Tangem is not responsible for the content, accuracy, security, availability, any performance, or failure to perform of the Third-Party Services or any issue in relation with the use of Third-Party Services. Tangem does not provide any guarantees that access to Third-Party Services will not be interrupted or that there will be no delays, failures, errors, omissions, corruption or loss of transmitted information, data or funds, and Tangem shall not be liable for any such Third-Party Services. You agree to use the Third-Party Services at your own risk. It is your responsibility to review the third party’s terms and policies before using a Third-Party Service. Third-Party Services may not be available in all languages and may not be appropriate or available for use in any particular location. To the extent you choose to use such Third-Party Services, you are solely responsible for compliance with any applicable laws in relation to such use. In addition, Tangem reserves the right to block access to these Third-Party Services through Tangem Live in particular, but not exclusively, in the event of non-compliance with the applicable regulations by the Third-Party partner. We retain the exclusive right to suspend, remove, or cancel the availability of any such Third-Party Service for any reason and without prior notice.

+ +

9. RESPONSIBILITIES AND LIABILITIES OF TANGEM

+

9.1. Tangem does not warrant or make any representations regarding the use, the inability to use or operate, or the results of the use or operation of Tangem Wallet (Card) and/or Official Mobile Application.

+

9.2. Tangem does not keep any records of Cardholder information, the amount of Blockchain Asset stored on Tangem Wallet (Card), the Private Key, or personalized history of cards usage.

+

9.3. Tangem does not provide any backup or recovery of Private Key and Public Key stored on Tangem Wallet (Card).

+

9.4. Tangem shall not be held liable for any failure to be able to use Tangem Wallet (Card) and/or Official Mobile Application, for any reason whatsoever, nor will Tangem be held liable for the loss of the Blockchain Asset resulting from a malfunction or inoperability of the blockchain network hosting Blockchain Asset, as well as the inaccessibility of its public servers and services.

+

9.5. Tangem does not guarantee that the operation of Tangem Wallet (Card) and/or Official Mobile Application will be secure, accurate, complete, uninterrupted, without error or free of viruses, worms, other harmful components or other program limitations. Tangem may, at its sole discretion and without obligation to do so, correct, modify, amend, enhance, improve and make any other changes to Tangem Wallet and/or Official Mobile Application, change, update or suspend the Services, temporarily or indefinitely, so as to carry out works including, but not limited to: firmware and software updates, maintenance operations, amendments to the servers, bug fixes, etc. We will make reasonable efforts to give you prior notice of any significant disruption of the Services. Tangem does not guarantee the correct functioning of the Services in the event of the installation or use of programs or applications that do not conform to Service specifications and technical standards.

+

9.6. Tangem shall not be held liable for the loss of profits, income, value or any indirect, extraordinary, consequential, exemplary or punitive damages.

+

9.7. Tangem shall not be held liable for loss or breakdown of Tangem Wallet (Card).

+

9.8. Tangem shall not be held liable for any loss of Blockchain Asset in the event of loss or total breakdown of Tangem Wallet (Card).

+ +

10. GUARANTEES

+

10.1. Under the condition that Cardholder exercises the duties of care as stated in Clause 5, Tangem guarantees that Tangem Wallet (Card) will function properly and without restriction for a period of 2 (two) years. In the event of a breakdown of Tangem Wallet (Card) without it being the fault of Cardholder due to reasons mentioned in Clause 5 of these Terms, Tangem will replace Tangem Wallet with a new one. Cardholder shall inform Tangem on the event of a breakdown by sending an e-mail to support@tangem.com. If failed to resolve with support team of Tangem, Cardholder shall wait for instructions on safe shipping of Tangem Wallet (Card).

+

10.2. Tangem guarantees that Tangem Wallet (Card) prevents duplication of the Private Key and that Cardholder has exclusive control over the Blockchain Asset unless the contrary is imposed by specific blockchain network rules, e.g. two or more private keys can be used to control the same Blockchain Asset.

+ +

11. LIMITATION OF LIABILITY

+

11.1. Tangem Wallet (Card), including without limitation any content, data and information related thereto, is provided on an “as is” basis and “as available” basis, without any warranties of any kind, express or implied warranties of use, merchantability or suitability for a certain purpose or use, including without limitation, the quality of products and services provided by users, third-party services, and/or exchanges (except for the guarantees set forth in Section 9).

+

11.2. Official Mobile Application is provided on an “as is” basis and “as available” basis without any warranties of any kind regarding Official Mobile Application and/or any content, data, materials and/or services provided on Official Mobile Application.

+

11.3. Tangem and its affiliates, including any of their officers, directors, shareholders, employees, sub-contractors, agents, parent companies, subsidiaries and other affiliates (collectively, the “Tangem Affiliates”), jointly and severally, disclaim and make no representations or warranties as to the usability, accuracy, quality, availability, reliability, suitability, completeness, truthfulness, usefulness or effectiveness of any content, data, results or other information obtained or generated by Tangem and/or any user related to you or any other user of Tangem Wallet (Card), and Official Mobile Applications.

+

11.4. In no event shall Tangem and/or any of Tangem Affiliates be liable for any damages whatsoever, including direct, indirect, extraordinary, incidental or consequential damages of any kind, but not limited to, resulting from or arising out of the use of Tangem Wallet (Card) and/or Official Mobile Applications or inability to use Tangem Wallet (Card) and/or Official Mobile Applications, failure of Tangem Wallet (Card) and/or Official Mobile Applications to perform as represented or expected, loss of goodwill or profits, or loss of data arising out of or in any way connected with the use of Tangem Wallet (Card) and/or Official Mobile Applications. In no event shall Tangem and/or any of Tangem Affiliates be liable for the performance or failure of Tangem Wallet (Card) and/ or Official Mobile Applications to perform under these Terms of Use and any other act or omission by Tangem by any cause whatsoever including without limitation damages arising from the conduct of any users, third party services and/or exchanges. In no way Tangem or contributors to Official Mobile Application are responsible for the actions, decisions, or other behavior taken or not taken by Cardholder in reliance upon Tangem Official Mobile Application.

+

11.5. You hereby acknowledge and agree that these limitations of liability are agreed allocations of risk constituting in part the consideration for using Tangem Wallet (Card) and Official Mobile Applications and such limitations will apply notwithstanding the failure of essential purpose of any limited remedy, and even if Tangem and/or any Tangem Affiliates has been advised of the possibility of such liabilities and/or damages.

+

11.6. Tangem will not be responsible for any losses, damages or claims arising from events falling within the scope of the following five categories:

+

11.6.1. Mistakes made by Cardholder, e.g., forgotten passwords, payments sent to wrong addresses, and accidental deletion of blockchain wallets on Tangem Wallet (Card).

+

11.6.2. Problems of Official Mobile Application and/or any blockchain- or cryptocurrency- related software or service, e.g., corrupted files, incorrectly constructed transactions, unsafe cryptographic libraries, malware.

+

11.6.3. Technical failures in the hardware of Cardholder, including cards, of any blockchain- or cryptocurrency- related software or service, e.g., data loss due to a faulty or damaged storage device.

+

11.6.4. Security problems experienced by Cardholder, e.g., unauthorized access to Cardholders' wallets and/or accounts.

+

11.6.5. Actions or inactions of third parties and/or events experienced by third parties, e.g., bankruptcy of service providers, information security attacks on service providers, and fraud conducted by third parties.

+ +

12. GOVERNING LAW AND DISPUTE RESOLUTION

+

12.1. Unless otherwise required by a mandatory law of a member state of the European Union or any other jurisdiction these Terms of Service and any separate agreements whereby we provide you Services shall be governed by the laws of Switzerland without regard to its conflict of laws principles.

+

12.2. You can submit a claim in written form regarding the operation of the Services to us via email at store@tangem.com. You may also reach us in writing at the following address: Tangem AG, Baarerstrasse 10, Zug, CH-6300 Switzerland. In case of failure to resolve disputes and disagreements by way of negotiations the settlement shall be in accordance with claim procedure. Claims shall be reviewed within 30 calendar days.

+

12.3. Subject to compulsory legal provisions, any use of the Services and all legal disputes arising out of or in connection therewith shall be submitted to the exclusive jurisdiction of the courts of the Canton of Zug.

+ +

13. COMMUNICATION

+

13.1. In the event when under the Terms Tangem provides the User with any information that relates to the Services provided hereunder, this information may be given to the Client through the Website without sending said information directly to the User’s address and / or using other secure means.

+

13.2. Tangem shall respond to requests from the User promptly and within 7 calendar days following the date of receipt of the request. The response time may in some cases may exceed 7 calendar days.

+ +

14. MISCELLANEOUS

+

14.1. Entire agreement. These Terms and any policies or operating rules posted by us on the Website or in respect to the Services constitutes the entire agreement and understanding between you and us and govern your use of the Services, superseding any prior or contemporaneous agreements, communications and proposals, whether oral or written, between you and us (including, but not limited to, any prior versions of the Terms).

+

14.2. Severability. In the event that any provision of these Terms is determined to be unlawful, void or unenforceable, such provision will nonetheless be enforceable to the fullest extent permitted by applicable law, and the unenforceable portion will be deemed to be severed from these Terms of Service, such determination will not affect the validity and enforceability of any other remaining provisions.

+

14.3. Assignment. You may not assign your rights or obligations under these Terms in whole or in part to any third party. You acknowledge and agree that Tangem may assign its rights and obligations under these Terms, including rights and obligations concerning insurance, and, in such context, share or transfer information provided by you while using the Services to a third party.

+

14.4. No waiver. The failure of us to exercise or enforce any right or provision of these Terms will not constitute a waiver of such right or provision.

+

14.5. Any ambiguities in the interpretation of these Terms will not be construed against the drafting party.

+

14.6. Errors, Inaccuracies, And Omissions. Occasionally there may be information in the Services that contains typographical errors, inaccuracies or omissions that may relate to product descriptions, pricing, promotions, offers, product shipping charges, transit times and availability. We reserve the right to correct any errors, inaccuracies or omissions, and to change or update information or cancel orders if any information in the Services or on any related website is inaccurate at any time without prior notice (including after you have submitted your order).

+

14.7. Terms concerning Recovery Phrase apply to Tangem Wallet (Card) supporting this feature.

+

14.8. We undertake no obligation to update, amend or clarify information in the Services, including without limitation, pricing information, except as required by law. No specified update or refresh date applied in the Services or on any related website, should be taken to indicate that all information in the Services has been modified or updated.

+

14.9. These Terms may be drawn up in different languages. In case of any inconsistency the English version of the Terms shall prevail.

+ +

Last amended on: March 1st, 2024

+ + + +""".trimIndent() \ No newline at end of file diff --git a/features/disclaimer/impl/src/main/java/com/tangem/features/disclaimer/impl/model/DisclaimerModel.kt b/features/disclaimer/impl/src/main/java/com/tangem/features/disclaimer/impl/model/DisclaimerModel.kt new file mode 100644 index 0000000000..e2dffb37f3 --- /dev/null +++ b/features/disclaimer/impl/src/main/java/com/tangem/features/disclaimer/impl/model/DisclaimerModel.kt @@ -0,0 +1,70 @@ +package com.tangem.features.disclaimer.impl.model + +import com.tangem.common.routing.AppRoute +import com.tangem.core.decompose.di.ComponentScoped +import com.tangem.core.decompose.model.Model +import com.tangem.core.decompose.model.ParamsContainer +import com.tangem.core.decompose.navigation.Router +import com.tangem.core.navigation.finisher.AppFinisher +import com.tangem.domain.card.repository.CardRepository +import com.tangem.domain.settings.NeverRequestPermissionUseCase +import com.tangem.domain.settings.NeverToInitiallyAskPermissionUseCase +import com.tangem.features.disclaimer.api.components.DisclaimerComponent +import com.tangem.features.disclaimer.impl.entity.DisclaimerUM +import com.tangem.features.pushnotifications.api.utils.PUSH_PERMISSION +import com.tangem.utils.coroutines.CoroutineDispatcherProvider +import kotlinx.coroutines.flow.MutableStateFlow +import kotlinx.coroutines.launch +import javax.inject.Inject + +@ComponentScoped +@Suppress("LongParameterList") +internal class DisclaimerModel @Inject constructor( + override val dispatchers: CoroutineDispatcherProvider, + private val cardRepository: CardRepository, + private val router: Router, + private val neverToInitiallyAskPermissionUseCase: NeverToInitiallyAskPermissionUseCase, + private val neverRequestPermissionUseCase: NeverRequestPermissionUseCase, + private val appFinisher: AppFinisher, + paramsContainer: ParamsContainer, +) : Model() { + + private val params: DisclaimerComponent.Params = paramsContainer.require() + + val state: MutableStateFlow = MutableStateFlow( + DisclaimerUM( + onAccept = ::onAccept, + url = DISCLAIMER_URL, + isTosAccepted = params.isTosAccepted, + popBack = ::popBack, + ), + ) + + private fun onAccept(shouldAskPushPermission: Boolean) = modelScope.launch { + if (params.isTosAccepted) { + router.pop() + } else { + cardRepository.acceptTangemTOS() + + if (shouldAskPushPermission) { + router.push(AppRoute.PushNotification) + } else { + neverToInitiallyAskPermissionUseCase(PUSH_PERMISSION) + neverRequestPermissionUseCase(PUSH_PERMISSION) + router.replaceAll(AppRoute.Home) + } + } + } + + private fun popBack() { + if (params.isTosAccepted) { + router.pop() + } else { + appFinisher.finish() + } + } + + private companion object { + const val DISCLAIMER_URL = "https://tangem.com/tangem_tos.html" + } +} \ No newline at end of file diff --git a/features/disclaimer/impl/src/main/java/com/tangem/features/disclaimer/impl/ui/DisclaimerScreen.kt b/features/disclaimer/impl/src/main/java/com/tangem/features/disclaimer/impl/ui/DisclaimerScreen.kt new file mode 100644 index 0000000000..208feec00e --- /dev/null +++ b/features/disclaimer/impl/src/main/java/com/tangem/features/disclaimer/impl/ui/DisclaimerScreen.kt @@ -0,0 +1,181 @@ +package com.tangem.features.disclaimer.impl.ui + +import android.annotation.SuppressLint +import android.content.res.Configuration +import androidx.compose.animation.AnimatedVisibility +import androidx.compose.animation.fadeIn +import androidx.compose.animation.fadeOut +import androidx.compose.foundation.background +import androidx.compose.foundation.layout.* +import androidx.compose.material3.CircularProgressIndicator +import androidx.compose.runtime.Composable +import androidx.compose.runtime.derivedStateOf +import androidx.compose.runtime.getValue +import androidx.compose.runtime.remember +import androidx.compose.ui.Alignment +import androidx.compose.ui.Modifier +import androidx.compose.ui.graphics.toArgb +import androidx.compose.ui.platform.LocalDensity +import androidx.compose.ui.res.stringResource +import androidx.compose.ui.tooling.preview.Preview +import com.google.accompanist.permissions.ExperimentalPermissionsApi +import com.google.accompanist.permissions.isGranted +import com.google.accompanist.permissions.rememberPermissionState +import com.google.accompanist.web.WebView +import com.google.accompanist.web.rememberWebViewState +import com.google.accompanist.web.rememberWebViewStateWithHTMLData +import com.tangem.core.ui.components.BottomFade +import com.tangem.core.ui.components.NavigationBar3ButtonsScrim +import com.tangem.core.ui.components.PrimaryButton +import com.tangem.core.ui.components.appbar.TangemTopAppBar +import com.tangem.core.ui.components.appbar.models.TopAppBarButtonUM +import com.tangem.core.ui.components.buttons.common.TangemButtonColors +import com.tangem.core.ui.extensions.resourceReference +import com.tangem.core.ui.res.TangemColorPalette +import com.tangem.core.ui.res.TangemTheme +import com.tangem.core.ui.res.TangemThemePreview +import com.tangem.features.disclaimer.impl.R +import com.tangem.features.disclaimer.impl.entity.DisclaimerUM +import com.tangem.features.disclaimer.impl.entity.DummyDisclaimer +import com.tangem.features.disclaimer.impl.local.localTermsOfServices +import com.tangem.features.pushnotifications.api.utils.getPushPermissionOrNull + +@Composable +internal fun DisclaimerScreen(state: DisclaimerUM) { + val bottomBarHeight = with(LocalDensity.current) { WindowInsets.systemBars.getBottom(this).toDp() } + val bottomPadding = if (state.isTosAccepted) { + bottomBarHeight + TangemTheme.dimens.size16 + } else { + bottomBarHeight + TangemTheme.dimens.size64 + } + val backgroundColor = if (state.isTosAccepted) TangemTheme.colors.background.primary else TangemColorPalette.Dark6 + val (textColor, iconColor) = if (state.isTosAccepted) { + TangemTheme.colors.text.primary1 to TangemTheme.colors.icon.primary1 + } else { + TangemColorPalette.Light4 to TangemColorPalette.Light4 + } + Box( + modifier = Modifier + .background(backgroundColor) + .statusBarsPadding(), + ) { + Column( + modifier = Modifier + .padding(bottom = bottomPadding) + .fillMaxSize(), + ) { + TangemTopAppBar( + title = resourceReference(R.string.disclaimer_title), + startButton = TopAppBarButtonUM( + iconRes = R.drawable.ic_back_24, + onIconClicked = state.popBack, + ).takeIf { state.isTosAccepted }, + titleAlignment = Alignment.CenterHorizontally, + textColor = textColor, + iconTint = iconColor, + ) + DisclaimerContent(state.url, state.isTosAccepted) + } + + if (!state.isTosAccepted) { + BottomFade(Modifier.align(Alignment.BottomCenter), backgroundColor = backgroundColor) + DisclaimerButton(state.onAccept) + } else { + NavigationBar3ButtonsScrim() + } + } +} + +@SuppressLint("SetJavaScriptEnabled") +@Composable +private fun DisclaimerContent(url: String, isTosAccepted: Boolean) { + val backgroundColor = if (isTosAccepted) TangemTheme.colors.background.primary else TangemColorPalette.Dark6 + + val webViewStateUrl = rememberWebViewState(url) + val webViewStateData = + rememberWebViewStateWithHTMLData(data = localTermsOfServices, mimeType = "text/html", encoding = "UTF-8") + + val webViewState by remember { + derivedStateOf { + if (webViewStateUrl.errorsForCurrentRequest.isNotEmpty()) { + webViewStateData + } else { + webViewStateUrl + } + } + } + + Box { + WebView( + state = webViewState, + captureBackPresses = false, + onCreated = { + it.settings.javaScriptEnabled = !isTosAccepted + it.setBackgroundColor(backgroundColor.toArgb()) + }, + client = remember { DisclaimerWebViewClient() }, + modifier = Modifier.fillMaxSize(), + ) + + AnimatedVisibility( + visible = webViewState.isLoading, + label = "Loading state change animation", + enter = fadeIn(), + exit = fadeOut(), + modifier = Modifier + .fillMaxSize() + .background(backgroundColor), + ) { + Box( + modifier = Modifier + .fillMaxSize() + .background(backgroundColor), + ) { + CircularProgressIndicator( + color = TangemTheme.colors.icon.informative, + modifier = Modifier + .align(Alignment.Center) + .padding(TangemTheme.dimens.spacing8), + ) + } + } + } +} + +@OptIn(ExperimentalPermissionsApi::class) +@Composable +private fun BoxScope.DisclaimerButton(onAccept: (Boolean) -> Unit) { + val isPermissionGranted = getPushPermissionOrNull()?.let { permission -> + rememberPermissionState(permission = permission).status.isGranted + } ?: true + PrimaryButton( + text = stringResource(id = R.string.common_accept), + onClick = { onAccept(!isPermissionGranted) }, + colors = TangemButtonColors( + backgroundColor = TangemColorPalette.Light4, + contentColor = TangemColorPalette.Dark6, + disabledBackgroundColor = TangemColorPalette.Light4, + disabledContentColor = TangemColorPalette.Dark6, + ), + modifier = Modifier + .align(Alignment.BottomCenter) + .navigationBarsPadding() + .padding( + start = TangemTheme.dimens.spacing16, + end = TangemTheme.dimens.spacing16, + bottom = TangemTheme.dimens.spacing16, + ) + .fillMaxWidth(), + ) +} + +// region Preview +@Preview(showBackground = true, widthDp = 360, heightDp = 800) +@Preview(showBackground = true, widthDp = 360, heightDp = 800, uiMode = Configuration.UI_MODE_NIGHT_YES) +@Composable +private fun DisclaimerScreen_Preview() { + TangemThemePreview { + DisclaimerScreen(state = DummyDisclaimer.state) + } +} +// endregion \ No newline at end of file diff --git a/features/disclaimer/impl/src/main/java/com/tangem/features/disclaimer/impl/ui/DisclaimerWebViewClient.kt b/features/disclaimer/impl/src/main/java/com/tangem/features/disclaimer/impl/ui/DisclaimerWebViewClient.kt new file mode 100644 index 0000000000..c3046d0855 --- /dev/null +++ b/features/disclaimer/impl/src/main/java/com/tangem/features/disclaimer/impl/ui/DisclaimerWebViewClient.kt @@ -0,0 +1,45 @@ +package com.tangem.features.disclaimer.impl.ui + +import android.graphics.Bitmap +import android.webkit.WebView +import com.google.accompanist.web.AccompanistWebViewClient + +internal enum class ProgressState { + Loading, + Done, + Error, +} + +/** + * Workaround to display web view with ToS only in dark theme + */ +private fun WebView.injectCSS() { + val code = "javascript:(function() {" + + "var node = document.createElement('style');" + + "node.type = 'text/css';" + + " node.innerHTML = 'body, label,th,p,a, td, tr,li,ul,span,table,h1,h2,h3,h4,h5,h6,h7,div,small {" + + " color: #C9C9C9;" + + "background-color: #1E1E1E;" + + " } ';" + + " document.head.appendChild(node);})();" + + evaluateJavascript(code, null) +} + +internal class DisclaimerWebViewClient : AccompanistWebViewClient() { + + override fun onPageStarted(view: WebView?, url: String?, favicon: Bitmap?) { + view?.injectCSS() + super.onPageStarted(view, url, favicon) + } + + override fun onPageCommitVisible(view: WebView?, url: String?) { + view?.injectCSS() + super.onPageCommitVisible(view, url) + } + + override fun onPageFinished(view: WebView?, url: String?) { + view?.injectCSS() + super.onPageFinished(view, url) + } +} \ No newline at end of file diff --git a/features/manage-tokens/api/build.gradle.kts b/features/manage-tokens/api/build.gradle.kts index cbfb3f7b1f..0cf94d3840 100644 --- a/features/manage-tokens/api/build.gradle.kts +++ b/features/manage-tokens/api/build.gradle.kts @@ -9,5 +9,10 @@ android { } dependencies { - implementation(deps.compose.foundation) + /* Project - Domain */ + implementation(projects.domain.wallets.models) + + /* Project - Core */ + implementation(projects.core.ui) + implementation(projects.core.decompose) } \ No newline at end of file diff --git a/features/manage-tokens/api/src/main/kotlin/com/tangem/features/managetokens/component/ManageTokensComponent.kt b/features/manage-tokens/api/src/main/kotlin/com/tangem/features/managetokens/component/ManageTokensComponent.kt new file mode 100644 index 0000000000..54cb358614 --- /dev/null +++ b/features/manage-tokens/api/src/main/kotlin/com/tangem/features/managetokens/component/ManageTokensComponent.kt @@ -0,0 +1,14 @@ +package com.tangem.features.managetokens.component + +import com.tangem.core.decompose.factory.ComponentFactory +import com.tangem.core.ui.decompose.ComposableContentComponent +import com.tangem.domain.wallets.models.UserWalletId + +interface ManageTokensComponent : ComposableContentComponent { + + data class Params( + val userWalletId: UserWalletId, + ) + + interface Factory : ComponentFactory +} \ No newline at end of file diff --git a/features/manage-tokens/api/src/main/kotlin/com/tangem/features/managetokens/featuretoggles/ManageTokensFeatureToggles.kt b/features/manage-tokens/api/src/main/kotlin/com/tangem/features/managetokens/featuretoggles/ManageTokensFeatureToggles.kt deleted file mode 100644 index e29173b5fc..0000000000 --- a/features/manage-tokens/api/src/main/kotlin/com/tangem/features/managetokens/featuretoggles/ManageTokensFeatureToggles.kt +++ /dev/null @@ -1,5 +0,0 @@ -package com.tangem.features.managetokens.featuretoggles - -interface ManageTokensFeatureToggles { - val isRedesignedScreenEnabled: Boolean -} \ No newline at end of file diff --git a/features/manage-tokens/api/src/main/kotlin/com/tangem/features/managetokens/navigation/ExpandableState.kt b/features/manage-tokens/api/src/main/kotlin/com/tangem/features/managetokens/navigation/ExpandableState.kt deleted file mode 100644 index 34048e6f11..0000000000 --- a/features/manage-tokens/api/src/main/kotlin/com/tangem/features/managetokens/navigation/ExpandableState.kt +++ /dev/null @@ -1,6 +0,0 @@ -package com.tangem.features.managetokens.navigation - -enum class ExpandableState { - EXPANDED, - COLLAPSED, -} \ No newline at end of file diff --git a/features/manage-tokens/api/src/main/kotlin/com/tangem/features/managetokens/navigation/ManageTokensUi.kt b/features/manage-tokens/api/src/main/kotlin/com/tangem/features/managetokens/navigation/ManageTokensUi.kt deleted file mode 100644 index f200ab6a3c..0000000000 --- a/features/manage-tokens/api/src/main/kotlin/com/tangem/features/managetokens/navigation/ManageTokensUi.kt +++ /dev/null @@ -1,12 +0,0 @@ -package com.tangem.features.managetokens.navigation - -import androidx.compose.runtime.Composable -import androidx.compose.runtime.State -import androidx.compose.ui.unit.Dp - -interface ManageTokensUi { - - @Suppress("TopLevelComposableFunctions") - @Composable - fun Content(onHeaderSizeChange: (Dp) -> Unit, state: State) -} \ No newline at end of file diff --git a/features/manage-tokens/impl/build.gradle.kts b/features/manage-tokens/impl/build.gradle.kts index 88d462b52c..8e3cc2bddb 100644 --- a/features/manage-tokens/impl/build.gradle.kts +++ b/features/manage-tokens/impl/build.gradle.kts @@ -1,6 +1,7 @@ plugins { alias(deps.plugins.android.library) alias(deps.plugins.kotlin.android) + alias(deps.plugins.kotlin.serialization) alias(deps.plugins.kotlin.kapt) alias(deps.plugins.hilt.android) id("configuration") @@ -11,61 +12,30 @@ android { } dependencies { - /** AndroidX */ - implementation(deps.androidx.activity.compose) - implementation(deps.material) + /* Project - API */ + implementation(projects.features.manageTokens.api) - /** Compose */ - implementation(deps.compose.accompanist.systemUiController) - implementation(deps.compose.coil) - implementation(deps.compose.constraintLayout) - implementation(deps.compose.foundation) - implementation(deps.compose.material) - implementation(deps.compose.material3) - implementation(deps.compose.navigation) - implementation(deps.compose.navigation.hilt) - implementation(deps.compose.paging) - implementation(deps.compose.reorderable) - implementation(deps.compose.shimmer) + /* Project - Core */ + implementation(projects.core.decompose) + implementation(projects.core.ui) + implementation(projects.common.routing) + + /* AndroidX */ + implementation(deps.androidx.activity.compose) + implementation(deps.lifecycle.compose) + + /* Compose */ implementation(deps.compose.ui) implementation(deps.compose.ui.tooling) + implementation(deps.compose.foundation) + implementation(deps.compose.material3) + implementation(deps.compose.shimmer) - /** Other libraries */ - implementation(deps.arrow.core) - implementation(deps.jodatime) - implementation(deps.kotlin.immutable.collections) - implementation(deps.tangem.card.core) - implementation(deps.timber) - - /** DI */ + /* DI */ implementation(deps.hilt.android) kapt(deps.hilt.kapt) - /** Core modules */ - implementation(projects.core.analytics) - implementation(projects.core.analytics.models) - implementation(projects.core.featuretoggles) - implementation(projects.core.navigation) - implementation(projects.core.ui) - implementation(projects.core.utils) - - /** Project - Data */ - implementation(projects.data.tokens) - - /** Domain modules */ - implementation(projects.domain.card) - implementation(projects.domain.demo) - implementation(projects.domain.legacy) - implementation(projects.libs.blockchainSdk) - implementation(projects.domain.models) - implementation(projects.domain.settings) - implementation(projects.domain.tokens) - implementation(projects.domain.tokens.models) - implementation(projects.domain.wallets) - implementation(projects.domain.wallets.models) - implementation(projects.domain.appCurrency) - implementation(projects.domain.appCurrency.models) - - /** Feature Apis */ - implementation(projects.features.manageTokens.api) + /* Other */ + implementation(deps.kotlin.immutable.collections) + implementation(deps.timber) } \ No newline at end of file diff --git a/features/manage-tokens/impl/src/main/java/com/tangem/managetokens/di/ManageTokensFeatureTogglesModule.kt b/features/manage-tokens/impl/src/main/java/com/tangem/managetokens/di/ManageTokensFeatureTogglesModule.kt deleted file mode 100644 index 7552eb21df..0000000000 --- a/features/manage-tokens/impl/src/main/java/com/tangem/managetokens/di/ManageTokensFeatureTogglesModule.kt +++ /dev/null @@ -1,21 +0,0 @@ -package com.tangem.managetokens.di - -import com.tangem.core.featuretoggle.manager.FeatureTogglesManager -import com.tangem.features.managetokens.featuretoggles.ManageTokensFeatureToggles -import com.tangem.managetokens.featuretoggles.DefaultManageTokensFeatureToggles -import dagger.Module -import dagger.Provides -import dagger.hilt.InstallIn -import dagger.hilt.components.SingletonComponent -import javax.inject.Singleton - -@Module -@InstallIn(SingletonComponent::class) -internal object ManageTokensFeatureTogglesModule { - - @Provides - @Singleton - fun provideWalletFeatureToggles(featureTogglesManager: FeatureTogglesManager): ManageTokensFeatureToggles { - return DefaultManageTokensFeatureToggles(featureTogglesManager = featureTogglesManager) - } -} \ No newline at end of file diff --git a/features/manage-tokens/impl/src/main/java/com/tangem/managetokens/di/ManageTokensRouterModule.kt b/features/manage-tokens/impl/src/main/java/com/tangem/managetokens/di/ManageTokensRouterModule.kt deleted file mode 100644 index e0ca63c3b2..0000000000 --- a/features/manage-tokens/impl/src/main/java/com/tangem/managetokens/di/ManageTokensRouterModule.kt +++ /dev/null @@ -1,18 +0,0 @@ -package com.tangem.managetokens.di - -import com.tangem.features.managetokens.navigation.ManageTokensUi -import com.tangem.managetokens.presentation.router.ManageTokensUiImpl -import dagger.Binds -import dagger.Module -import dagger.hilt.InstallIn -import dagger.hilt.components.SingletonComponent -import javax.inject.Singleton - -@Module -@InstallIn(SingletonComponent::class) -internal interface ManageTokensRouterModule { - - @Binds - @Singleton - fun provideManageTokensRouter(manageTokensUiImpl: ManageTokensUiImpl): ManageTokensUi -} \ No newline at end of file diff --git a/features/manage-tokens/impl/src/main/java/com/tangem/managetokens/featuretoggles/DefaultManageTokensFeatureToggles.kt b/features/manage-tokens/impl/src/main/java/com/tangem/managetokens/featuretoggles/DefaultManageTokensFeatureToggles.kt deleted file mode 100644 index 967a54e950..0000000000 --- a/features/manage-tokens/impl/src/main/java/com/tangem/managetokens/featuretoggles/DefaultManageTokensFeatureToggles.kt +++ /dev/null @@ -1,11 +0,0 @@ -package com.tangem.managetokens.featuretoggles - -import com.tangem.core.featuretoggle.manager.FeatureTogglesManager -import com.tangem.features.managetokens.featuretoggles.ManageTokensFeatureToggles - -internal class DefaultManageTokensFeatureToggles( - private val featureTogglesManager: FeatureTogglesManager, -) : ManageTokensFeatureToggles { - override val isRedesignedScreenEnabled: Boolean - get() = featureTogglesManager.isFeatureEnabled(name = "REDESIGNED_MANAGE_TOKENS_SCREEN_ENABLED") -} \ No newline at end of file diff --git a/features/manage-tokens/impl/src/main/java/com/tangem/managetokens/presentation/addcustomtoken/router/AddCustomTokenRoute.kt b/features/manage-tokens/impl/src/main/java/com/tangem/managetokens/presentation/addcustomtoken/router/AddCustomTokenRoute.kt deleted file mode 100644 index fad644416a..0000000000 --- a/features/manage-tokens/impl/src/main/java/com/tangem/managetokens/presentation/addcustomtoken/router/AddCustomTokenRoute.kt +++ /dev/null @@ -1,14 +0,0 @@ -package com.tangem.managetokens.presentation.addcustomtoken.router - -/** - * Add Custom Tokens screens - * @property route route string representation - */ -internal sealed class AddCustomTokenRoute(val route: String) { - object Main : AddCustomTokenRoute("$BASE_ROUTE/main") - object ChooseNetwork : AddCustomTokenRoute("$BASE_ROUTE/choose_network") - object ChooseWallet : AddCustomTokenRoute("$BASE_ROUTE/choose_wallet") - object ChooseDerivation : AddCustomTokenRoute("$BASE_ROUTE/choose_derivation") -} - -private const val BASE_ROUTE = "manage_tokens/add_custom_token" \ No newline at end of file diff --git a/features/manage-tokens/impl/src/main/java/com/tangem/managetokens/presentation/addcustomtoken/router/AddCustomTokenRouter.kt b/features/manage-tokens/impl/src/main/java/com/tangem/managetokens/presentation/addcustomtoken/router/AddCustomTokenRouter.kt deleted file mode 100644 index 4185ccddd4..0000000000 --- a/features/manage-tokens/impl/src/main/java/com/tangem/managetokens/presentation/addcustomtoken/router/AddCustomTokenRouter.kt +++ /dev/null @@ -1,29 +0,0 @@ -package com.tangem.managetokens.presentation.addcustomtoken.router - -import androidx.compose.runtime.Stable -import androidx.navigation.NavController - -@Stable -internal class AddCustomTokenRouter( - private val navController: NavController, -) { - /** Pop back stack */ - fun popBackStack() { - navController.popBackStack() - } - - /** Open custom token choose network screen */ - fun openCustomTokenChooseNetwork() { - navController.navigate(AddCustomTokenRoute.ChooseNetwork.route) - } - - /** Open custom token choose derivation screen */ - fun openCustomTokenChooseDerivation() { - navController.navigate(AddCustomTokenRoute.ChooseDerivation.route) - } - - /** Open custom token choose wallet screen */ - fun openCustomTokenChooseWallet() { - navController.navigate(AddCustomTokenRoute.ChooseWallet.route) - } -} \ No newline at end of file diff --git a/features/manage-tokens/impl/src/main/java/com/tangem/managetokens/presentation/addcustomtoken/state/AddCustomTokenState.kt b/features/manage-tokens/impl/src/main/java/com/tangem/managetokens/presentation/addcustomtoken/state/AddCustomTokenState.kt deleted file mode 100644 index 0eafc00654..0000000000 --- a/features/manage-tokens/impl/src/main/java/com/tangem/managetokens/presentation/addcustomtoken/state/AddCustomTokenState.kt +++ /dev/null @@ -1,18 +0,0 @@ -package com.tangem.managetokens.presentation.addcustomtoken.state - -import com.tangem.core.ui.event.StateEvent -import com.tangem.core.ui.event.consumedEvent -import com.tangem.managetokens.presentation.common.state.ChooseWalletState -import com.tangem.managetokens.presentation.common.state.Event -import kotlinx.collections.immutable.ImmutableSet - -internal data class AddCustomTokenState( - val chooseWalletState: ChooseWalletState, - val chooseNetworkState: ChooseNetworkState, - val chooseDerivationState: ChooseDerivationState?, - val tokenData: CustomTokenData?, - val warnings: ImmutableSet, - val addTokenButton: ButtonState, - val showChooseWalletScreen: Boolean = false, - val event: StateEvent = consumedEvent(), -) \ No newline at end of file diff --git a/features/manage-tokens/impl/src/main/java/com/tangem/managetokens/presentation/addcustomtoken/state/AddCustomTokenWarning.kt b/features/manage-tokens/impl/src/main/java/com/tangem/managetokens/presentation/addcustomtoken/state/AddCustomTokenWarning.kt deleted file mode 100644 index 690178c20d..0000000000 --- a/features/manage-tokens/impl/src/main/java/com/tangem/managetokens/presentation/addcustomtoken/state/AddCustomTokenWarning.kt +++ /dev/null @@ -1,32 +0,0 @@ -package com.tangem.managetokens.presentation.addcustomtoken.state - -import com.tangem.core.ui.extensions.TextReference -import com.tangem.core.ui.extensions.resourceReference -import com.tangem.core.ui.extensions.wrappedList -import com.tangem.features.managetokens.impl.R - -/** - * Warning model of add custom token screen - * - * @property title warning description - */ -internal sealed class AddCustomTokenWarning(val title: TextReference, val subtitle: TextReference? = null) { - - object PotentialScamToken : AddCustomTokenWarning( - title = resourceReference(R.string.custom_token_validation_error_not_found_title), - subtitle = resourceReference(R.string.custom_token_validation_error_not_found_description), - ) - - object InvalidContractAddress : AddCustomTokenWarning( - title = resourceReference(R.string.custom_token_creation_error_invalid_contract_address), - ) - - object WrongDecimals : AddCustomTokenWarning( - title = - resourceReference(R.string.custom_token_creation_error_wrong_decimals, wrappedList(MAXIMUM_DECIMAL_NUMBER)), - ) - - private companion object { - const val MAXIMUM_DECIMAL_NUMBER = 30 - } -} \ No newline at end of file diff --git a/features/manage-tokens/impl/src/main/java/com/tangem/managetokens/presentation/addcustomtoken/state/ButtonState.kt b/features/manage-tokens/impl/src/main/java/com/tangem/managetokens/presentation/addcustomtoken/state/ButtonState.kt deleted file mode 100644 index 42b515ea20..0000000000 --- a/features/manage-tokens/impl/src/main/java/com/tangem/managetokens/presentation/addcustomtoken/state/ButtonState.kt +++ /dev/null @@ -1,6 +0,0 @@ -package com.tangem.managetokens.presentation.addcustomtoken.state - -internal data class ButtonState( - val isEnabled: Boolean, - val onClick: () -> Unit, -) \ No newline at end of file diff --git a/features/manage-tokens/impl/src/main/java/com/tangem/managetokens/presentation/addcustomtoken/state/ChooseDerivationState.kt b/features/manage-tokens/impl/src/main/java/com/tangem/managetokens/presentation/addcustomtoken/state/ChooseDerivationState.kt deleted file mode 100644 index 047fae161d..0000000000 --- a/features/manage-tokens/impl/src/main/java/com/tangem/managetokens/presentation/addcustomtoken/state/ChooseDerivationState.kt +++ /dev/null @@ -1,13 +0,0 @@ -package com.tangem.managetokens.presentation.addcustomtoken.state - -import kotlinx.collections.immutable.ImmutableList - -internal data class ChooseDerivationState( - val derivations: ImmutableList, - val selectedDerivation: Derivation?, - val enterCustomDerivationState: EnterCustomDerivationState?, - val onChooseDerivationClick: () -> Unit, - val onCloseChoosingDerivationClick: () -> Unit, - val onEnterCustomDerivation: () -> Unit, - val show: Boolean = false, -) \ No newline at end of file diff --git a/features/manage-tokens/impl/src/main/java/com/tangem/managetokens/presentation/addcustomtoken/state/ChooseNetworkState.kt b/features/manage-tokens/impl/src/main/java/com/tangem/managetokens/presentation/addcustomtoken/state/ChooseNetworkState.kt deleted file mode 100644 index 56b993010b..0000000000 --- a/features/manage-tokens/impl/src/main/java/com/tangem/managetokens/presentation/addcustomtoken/state/ChooseNetworkState.kt +++ /dev/null @@ -1,12 +0,0 @@ -package com.tangem.managetokens.presentation.addcustomtoken.state - -import com.tangem.managetokens.presentation.common.state.NetworkItemState -import kotlinx.collections.immutable.ImmutableList - -internal data class ChooseNetworkState( - val networks: ImmutableList, - val selectedNetwork: NetworkItemState?, - val onChooseNetworkClick: () -> Unit, - val onCloseChoosingNetworkClick: () -> Unit, - val show: Boolean = false, -) \ No newline at end of file diff --git a/features/manage-tokens/impl/src/main/java/com/tangem/managetokens/presentation/addcustomtoken/state/CustomTokenData.kt b/features/manage-tokens/impl/src/main/java/com/tangem/managetokens/presentation/addcustomtoken/state/CustomTokenData.kt deleted file mode 100644 index b481d6767a..0000000000 --- a/features/manage-tokens/impl/src/main/java/com/tangem/managetokens/presentation/addcustomtoken/state/CustomTokenData.kt +++ /dev/null @@ -1,18 +0,0 @@ -package com.tangem.managetokens.presentation.addcustomtoken.state - -internal data class CustomTokenData( - val contractAddressTextField: TextFieldState, - val nameTextField: TextFieldState, - val symbolTextField: TextFieldState, - val decimalsTextField: TextFieldState, -) { - - fun isRequiredInformationProvided(): Boolean { - return contractAddressTextField.isInputValid() && nameTextField.isInputValid() && - symbolTextField.isInputValid() && decimalsTextField.isInputValid() - } - - fun isNameSymbolDecimalsDisabled(): Boolean { - return nameTextField.isDisabled() && symbolTextField.isDisabled() && decimalsTextField.isDisabled() - } -} \ No newline at end of file diff --git a/features/manage-tokens/impl/src/main/java/com/tangem/managetokens/presentation/addcustomtoken/state/Derivation.kt b/features/manage-tokens/impl/src/main/java/com/tangem/managetokens/presentation/addcustomtoken/state/Derivation.kt deleted file mode 100644 index 69f41a5f08..0000000000 --- a/features/manage-tokens/impl/src/main/java/com/tangem/managetokens/presentation/addcustomtoken/state/Derivation.kt +++ /dev/null @@ -1,9 +0,0 @@ -package com.tangem.managetokens.presentation.addcustomtoken.state - -internal data class Derivation( - val networkName: String, - val standardType: String?, - val path: String, - val networkId: String?, - val onDerivationSelected: (Derivation) -> Unit, -) \ No newline at end of file diff --git a/features/manage-tokens/impl/src/main/java/com/tangem/managetokens/presentation/addcustomtoken/state/EnterCustomDerivationState.kt b/features/manage-tokens/impl/src/main/java/com/tangem/managetokens/presentation/addcustomtoken/state/EnterCustomDerivationState.kt deleted file mode 100644 index 3b6ca1c57a..0000000000 --- a/features/manage-tokens/impl/src/main/java/com/tangem/managetokens/presentation/addcustomtoken/state/EnterCustomDerivationState.kt +++ /dev/null @@ -1,10 +0,0 @@ -package com.tangem.managetokens.presentation.addcustomtoken.state - -internal data class EnterCustomDerivationState( - val value: String, - val onValueChange: (String) -> Unit, - val confirmButtonEnabled: Boolean, - val derivationIncorrect: Boolean, - val onConfirmButtonClick: () -> Unit, - val onDismiss: () -> Unit, -) \ No newline at end of file diff --git a/features/manage-tokens/impl/src/main/java/com/tangem/managetokens/presentation/addcustomtoken/state/TextFieldState.kt b/features/manage-tokens/impl/src/main/java/com/tangem/managetokens/presentation/addcustomtoken/state/TextFieldState.kt deleted file mode 100644 index 3068a0b6e9..0000000000 --- a/features/manage-tokens/impl/src/main/java/com/tangem/managetokens/presentation/addcustomtoken/state/TextFieldState.kt +++ /dev/null @@ -1,34 +0,0 @@ -package com.tangem.managetokens.presentation.addcustomtoken.state - -internal sealed class TextFieldState { - object Loading : TextFieldState() - - data class Editable( - val value: String, - val isEnabled: Boolean, - val error: AddCustomTokenWarning? = null, - val onValueChange: (String) -> Unit, - val onFocusExit: () -> Unit, - ) : TextFieldState() - - fun isInputValid(): Boolean = this is Editable && value.isNotBlank() && error == null - - fun isDisabled() = this is Editable && !this.isEnabled - - fun copySealed( - value: String = (this as? Editable)?.value ?: "", - isEnabled: Boolean = (this as? Editable)?.isEnabled ?: true, - error: AddCustomTokenWarning? = (this as? Editable)?.error, - onValueChange: (String) -> Unit = (this as? Editable)?.onValueChange ?: {}, - ): TextFieldState { - return when (this) { - is Editable -> this.copy( - value = value, - isEnabled = isEnabled, - error = error, - onValueChange = onValueChange, - ) - is Loading -> this - } - } -} \ No newline at end of file diff --git a/features/manage-tokens/impl/src/main/java/com/tangem/managetokens/presentation/addcustomtoken/state/factory/AddCustomTokenStateFactory.kt b/features/manage-tokens/impl/src/main/java/com/tangem/managetokens/presentation/addcustomtoken/state/factory/AddCustomTokenStateFactory.kt deleted file mode 100644 index 6ad1ac8e68..0000000000 --- a/features/manage-tokens/impl/src/main/java/com/tangem/managetokens/presentation/addcustomtoken/state/factory/AddCustomTokenStateFactory.kt +++ /dev/null @@ -1,395 +0,0 @@ -package com.tangem.managetokens.presentation.addcustomtoken.state.factory - -import com.tangem.core.ui.event.consumedEvent -import com.tangem.core.ui.event.triggeredEvent -import com.tangem.crypto.hdWallet.DerivationPath -import com.tangem.domain.tokens.error.AddCustomTokenError -import com.tangem.domain.tokens.model.Network -import com.tangem.domain.wallets.models.UserWallet -import com.tangem.domain.wallets.models.UserWalletId -import com.tangem.managetokens.presentation.common.state.* -import com.tangem.managetokens.presentation.addcustomtoken.state.* -import com.tangem.managetokens.presentation.addcustomtoken.viewmodels.AddCustomTokenClickIntents -import com.tangem.utils.Provider -import kotlinx.collections.immutable.persistentListOf -import kotlinx.collections.immutable.persistentSetOf -import kotlinx.collections.immutable.toPersistentList -import kotlinx.collections.immutable.toPersistentSet - -@Suppress("LargeClass") -internal class AddCustomTokenStateFactory( - private val currentStateProvider: Provider, - private val clickIntents: AddCustomTokenClickIntents, -) { - - fun getInitialState(): AddCustomTokenState { - return AddCustomTokenState( - chooseWalletState = ChooseWalletState.NoSelection, - chooseNetworkState = ChooseNetworkState( - networks = persistentListOf(), - selectedNetwork = null, - onChooseNetworkClick = clickIntents::onChooseNetworkClick, - onCloseChoosingNetworkClick = clickIntents::onCloseChoosingNetworkClick, - ), - chooseDerivationState = ChooseDerivationState( - derivations = persistentListOf(), - selectedDerivation = null, - enterCustomDerivationState = null, - onChooseDerivationClick = clickIntents::onChooseDerivationClick, - onCloseChoosingDerivationClick = clickIntents::onCloseChoosingDerivationClick, - onEnterCustomDerivation = clickIntents::onEnterCustomDerivation, - ), - tokenData = null, - warnings = persistentSetOf(), - addTokenButton = ButtonState(isEnabled = false, onClick = clickIntents::onAddCustomButtonClick), - ) - } - - fun getFullState( - suitableUserWallets: List, - allUserWallets: List, - selectedWalletId: UserWalletId?, - supportedNetworks: List, - ): AddCustomTokenState { - val derivations = getListOfDerivations(supportedNetworks) - - val chooseDerivationState = createChooseDerivationState(derivations) - val networkConverter = NetworkToNetworkItemStateConverter(clickIntents::onNetworkSelected) - val networks = supportedNetworks.map { networkConverter.convert(it) } - - val chooseWalletState = getNewChooseWalletState(allUserWallets, suitableUserWallets, selectedWalletId) - - return AddCustomTokenState( - chooseWalletState = chooseWalletState, - chooseNetworkState = ChooseNetworkState( - networks = networks.toPersistentList(), - selectedNetwork = null, - onChooseNetworkClick = clickIntents::onChooseNetworkClick, - onCloseChoosingNetworkClick = clickIntents::onBack, - ), - chooseDerivationState = chooseDerivationState, - tokenData = null, - warnings = persistentSetOf(), - addTokenButton = ButtonState(isEnabled = false, onClick = clickIntents::onAddCustomButtonClick), - ) - } - - private fun getListOfDerivations( - networksListToGenerateDerivations: List, - filterOnlyHardenedDerivations: Boolean = false, - ): List { - return networksListToGenerateDerivations.mapNotNull { network -> - network.derivationPath.value?.let { rawPath -> - Derivation( - networkName = network.name, - standardType = network.standardType.name, - path = rawPath, - networkId = network.backendId, - onDerivationSelected = clickIntents::onDerivationSelected, - ) - }.takeIf { derivation -> - if (filterOnlyHardenedDerivations) { - derivation?.let { allNodesHardened(createDerivationPathOrNull(it.path)) } ?: false - } else { - true - } - } - } - } - - private fun createChooseDerivationState(derivations: List): ChooseDerivationState? { - return if (derivations.isNotEmpty()) { - ChooseDerivationState( - derivations = derivations.toPersistentList(), - selectedDerivation = null, - enterCustomDerivationState = null, - onChooseDerivationClick = clickIntents::onChooseDerivationClick, - onCloseChoosingDerivationClick = clickIntents::onBack, - onEnterCustomDerivation = clickIntents::onEnterCustomDerivation, - ) - } else { - null - } - } - - fun updateWithNewWalletSelected( - selectedWalletId: UserWalletId, - supportedNetworks: List, - ): AddCustomTokenState { - val derivations = getListOfDerivations(supportedNetworks) - - val chooseDerivationState = createChooseDerivationState(derivations) - val networkConverter = NetworkToNetworkItemStateConverter(clickIntents::onNetworkSelected) - val networks = supportedNetworks.map { networkConverter.convert(it) } - - val currentWalletState = requireNotNull( - currentStateProvider().chooseWalletState as? ChooseWalletState.Choose, - ) { - "If user wallet was chosen, ChooseWalletState type must be Choose" - } - val selectedWalletState = currentWalletState.wallets.find { it.walletId == selectedWalletId.stringValue } - val chooseWalletState = currentWalletState.copy(selectedWallet = selectedWalletState) - - return AddCustomTokenState( - chooseWalletState = chooseWalletState, - chooseNetworkState = ChooseNetworkState( - networks = networks.toPersistentList(), - selectedNetwork = null, - onChooseNetworkClick = clickIntents::onChooseNetworkClick, - onCloseChoosingNetworkClick = clickIntents::onBack, - ), - chooseDerivationState = chooseDerivationState, - tokenData = null, - warnings = persistentSetOf(), - addTokenButton = ButtonState(isEnabled = false, onClick = clickIntents::onAddCustomButtonClick), - ) - } - - private fun getNewChooseWalletState( - suitableUserWallets: List, - allUserWallets: List, - selectedWalletId: UserWalletId?, - ): ChooseWalletState { - val chooseWalletState = if (suitableUserWallets.size == 1) { - ChooseWalletState.NoSelection - } else if (suitableUserWallets.isEmpty() && allUserWallets.all { !it.isMultiCurrency }) { - ChooseWalletState.Warning(ChooseWalletWarning.SINGLE_CURRENCY) - } else { - var selectedWalletState: WalletState? = null - ChooseWalletState.Choose( - wallets = suitableUserWallets.map { wallet -> - val walletState = WalletState( - walletId = wallet.walletId.stringValue, - artworkUrl = wallet.artworkUrl, - onSelected = clickIntents::onWalletSelected, - walletName = wallet.name, - ) - if (wallet.walletId.stringValue == selectedWalletId?.stringValue) { - selectedWalletState = walletState - } - walletState - }.toPersistentList(), - selectedWallet = requireNotNull(selectedWalletState), - onChooseWalletClick = clickIntents::onChooseWalletClick, - onCloseChoosingWalletClick = clickIntents::onCloseChoosingWalletClick, - ) - } - return chooseWalletState - } - - fun removeTokenAddressError(): AddCustomTokenState { - return addTokenAddressFieldError(null) - } - - private fun addTokenAddressFieldError(error: AddCustomTokenWarning?): AddCustomTokenState { - val tokenData = currentStateProvider().tokenData ?: return currentStateProvider() - val contractAddressField = tokenData.contractAddressTextField.copySealed(error = error) - return currentStateProvider().copy(tokenData = tokenData.copy(contractAddressTextField = contractAddressField)) - } - - private fun unlockAndClearNameSymbolAndDecimals(state: AddCustomTokenState): AddCustomTokenState { - val currentTokenData = state.tokenData - return state.copy( - tokenData = currentTokenData?.copy( - nameTextField = TextFieldState.Editable( - value = "", - isEnabled = true, - onValueChange = clickIntents::onTokenNameChange, - onFocusExit = clickIntents::onTokenNameFocusExit, - ), - symbolTextField = TextFieldState.Editable( - value = "", - isEnabled = true, - onValueChange = clickIntents::onSymbolChange, - onFocusExit = clickIntents::onSymbolFocusExit, - ), - decimalsTextField = TextFieldState.Editable( - value = "", - isEnabled = true, - onValueChange = clickIntents::onDecimalsChange, - onFocusExit = clickIntents::onDecimalsFocusExit, - ), - ), - ) - } - - fun getStateAndTriggerEvent( - state: AddCustomTokenState, - event: Event, - setUiState: (AddCustomTokenState) -> Unit, - ): AddCustomTokenState { - return state.copy( - event = triggeredEvent( - data = event, - onConsume = { - val currentState = currentStateProvider() - setUiState(currentState.copy(event = consumedEvent())) - }, - ), - ) - } - - fun updateStateOnNetworkSelected( - networkItemState: NetworkItemState, - supportsTokens: Boolean, - networks: List, - requiresHardenedDerivationOnly: Boolean, - ): AddCustomTokenState { - val uiState = currentStateProvider() - val tokenData = if (supportsTokens) { - uiState.tokenData ?: CustomTokenData( - contractAddressTextField = TextFieldState.Editable( - value = "", - isEnabled = true, - onValueChange = clickIntents::onContractAddressChange, - onFocusExit = clickIntents::onContractAddressFocusExit, - ), - nameTextField = TextFieldState.Editable( - value = "", - isEnabled = false, - onValueChange = clickIntents::onTokenNameChange, - onFocusExit = clickIntents::onTokenNameFocusExit, - ), - symbolTextField = TextFieldState.Editable( - value = "", - isEnabled = false, - onValueChange = clickIntents::onSymbolChange, - onFocusExit = clickIntents::onSymbolFocusExit, - ), - decimalsTextField = TextFieldState.Editable( - value = "", - isEnabled = false, - onValueChange = clickIntents::onDecimalsChange, - onFocusExit = clickIntents::onDecimalsFocusExit, - ), - ) - } else { - null - } - - val derivations = getListOfDerivations(networks, requiresHardenedDerivationOnly) - val chooseDerivationState = createChooseDerivationState(derivations) - - return uiState.copy( - chooseNetworkState = uiState.chooseNetworkState.copy( - selectedNetwork = networkItemState, - ), - chooseDerivationState = chooseDerivationState, - tokenData = tokenData, - addTokenButton = uiState.addTokenButton.copy(isEnabled = true), - ) - } - - fun updateOnCustomDerivationSelected(): AddCustomTokenState { - val uiState = currentStateProvider() - return uiState.copy( - chooseDerivationState = uiState.chooseDerivationState?.copy( - enterCustomDerivationState = null, - selectedDerivation = Derivation( - networkName = "", - path = uiState.chooseDerivationState.enterCustomDerivationState?.value ?: "", - networkId = null, - standardType = null, - onDerivationSelected = clickIntents::onDerivationSelected, - ), - ), - ) - } - - fun updateStateOnEnterCustomDerivation(): AddCustomTokenState { - val customDerivationState = EnterCustomDerivationState( - value = "", - onValueChange = clickIntents::onCustomDerivationChange, - confirmButtonEnabled = false, - derivationIncorrect = false, - onConfirmButtonClick = clickIntents::onCustomDerivationSelected, - onDismiss = clickIntents::onCustomDerivationDialogDismissed, - ) - val uiState = currentStateProvider() - return uiState.copy( - chooseDerivationState = uiState.chooseDerivationState?.copy( - enterCustomDerivationState = customDerivationState, - ), - ) - } - - fun updateOnCustomDerivationEntered(input: String, requiresHardenedDerivationOnly: Boolean): AddCustomTokenState { - val uiState = currentStateProvider() - val path = createDerivationPathOrNull(input) - val isWrongDerivationForWallet2 = isWrongDerivationForWallet2( - requiresHardenedDerivationOnly = requiresHardenedDerivationOnly, - derivationPath = path, - ) - val enterDerivationState = uiState.chooseDerivationState?.enterCustomDerivationState?.copy( - confirmButtonEnabled = path != null && !isWrongDerivationForWallet2, - derivationIncorrect = input.isNotBlank() && path == null || isWrongDerivationForWallet2, - ) - return uiState.copy( - chooseDerivationState = uiState.chooseDerivationState?.copy( - enterCustomDerivationState = enterDerivationState, - ), - ) - } - - private fun isWrongDerivationForWallet2( - requiresHardenedDerivationOnly: Boolean, - derivationPath: DerivationPath?, - ): Boolean { - return if (requiresHardenedDerivationOnly) { - !allNodesHardened(derivationPath) - } else { - false - } - } - - private fun allNodesHardened(derivationPath: DerivationPath?): Boolean { - return derivationPath?.nodes?.all { it.isHardened } ?: false - } - - private fun createDerivationPathOrNull(rawPath: String): DerivationPath? { - return try { - DerivationPath(rawPath) - } catch (error: Throwable) { - null - } - } - - fun updateStateOnLoadingTokenInfo(contractAddress: String): AddCustomTokenState { - return currentStateProvider().copy( - tokenData = CustomTokenData( - contractAddressTextField = TextFieldState.Editable( - value = contractAddress, - isEnabled = true, - onValueChange = clickIntents::onContractAddressChange, - onFocusExit = clickIntents::onContractAddressFocusExit, - - ), - nameTextField = TextFieldState.Loading, - symbolTextField = TextFieldState.Loading, - decimalsTextField = TextFieldState.Loading, - ), - ) - } - - fun handleAddressError(error: AddCustomTokenError): AddCustomTokenState { - val uiState = currentStateProvider() - return when (error) { - AddCustomTokenError.INVALID_CONTRACT_ADDRESS -> { - removeTokenAddressError().also { unlockAndClearNameSymbolAndDecimals(it) } - .copy( - addTokenButton = uiState.addTokenButton.copy(isEnabled = false), - warnings = uiState.warnings - .filterNot { it is AddCustomTokenWarning.PotentialScamToken } - .toPersistentSet(), - ) - } - AddCustomTokenError.FIELD_IS_EMPTY -> - removeTokenAddressError().also { unlockAndClearNameSymbolAndDecimals(it) } - .copy( - addTokenButton = uiState.addTokenButton.copy( - isEnabled = uiState.tokenData?.isRequiredInformationProvided() == true, - ), - ) - } - } -} \ No newline at end of file diff --git a/features/manage-tokens/impl/src/main/java/com/tangem/managetokens/presentation/addcustomtoken/state/factory/AddCustomTokenStateToCryptoCurrencyConverter.kt b/features/manage-tokens/impl/src/main/java/com/tangem/managetokens/presentation/addcustomtoken/state/factory/AddCustomTokenStateToCryptoCurrencyConverter.kt deleted file mode 100644 index e6e1b2f84e..0000000000 --- a/features/manage-tokens/impl/src/main/java/com/tangem/managetokens/presentation/addcustomtoken/state/factory/AddCustomTokenStateToCryptoCurrencyConverter.kt +++ /dev/null @@ -1,58 +0,0 @@ -package com.tangem.managetokens.presentation.addcustomtoken.state.factory - -import com.tangem.data.tokens.utils.CryptoCurrencyFactory -import com.tangem.domain.common.DerivationStyleProvider -import com.tangem.domain.tokens.model.CryptoCurrency -import com.tangem.managetokens.presentation.addcustomtoken.state.AddCustomTokenState -import com.tangem.managetokens.presentation.addcustomtoken.state.CustomTokenData -import com.tangem.managetokens.presentation.addcustomtoken.state.TextFieldState -import com.tangem.utils.converter.Converter - -internal class AddCustomTokenStateToCryptoCurrencyConverter( - private val derivationStyleProvider: DerivationStyleProvider, -) : Converter { - - override fun convert(value: AddCustomTokenState): CryptoCurrency { - val derivationPath = value.chooseDerivationState?.selectedDerivation?.path - val token = parseTokenOrNull(value.tokenData) - - val cryptoCurrency = if (token != null) { - CryptoCurrencyFactory().createToken( - token = token, - networkId = value.chooseNetworkState.selectedNetwork?.id ?: "", - derivationStyleProvider = derivationStyleProvider, - extraDerivationPath = derivationPath, - ) - } else { - CryptoCurrencyFactory().createCoin( - networkId = value.chooseNetworkState.selectedNetwork?.id ?: "", - derivationStyleProvider = derivationStyleProvider, - extraDerivationPath = derivationPath, - ) - } - return requireNotNull(cryptoCurrency) { - "Unless network is not Unknown blockchain, CryptoCurrency cannot be null" - } - } - - @Suppress("ComplexCondition") - private fun parseTokenOrNull(tokenData: CustomTokenData?): CryptoCurrencyFactory.Token? { - val contractAddress = (tokenData?.contractAddressTextField as? TextFieldState.Editable)?.value - val symbol = (tokenData?.symbolTextField as? TextFieldState.Editable)?.value - val name = (tokenData?.nameTextField as? TextFieldState.Editable)?.value - val decimals = (tokenData?.decimalsTextField as? TextFieldState.Editable)?.value?.toIntOrNull() - return if ( - !contractAddress.isNullOrBlank() && !symbol.isNullOrBlank() && !name.isNullOrBlank() && decimals != null - ) { - CryptoCurrencyFactory.Token( - symbol = symbol, - name = name, - contractAddress = contractAddress, - decimals = decimals, - id = null, - ) - } else { - null - } - } -} \ No newline at end of file diff --git a/features/manage-tokens/impl/src/main/java/com/tangem/managetokens/presentation/addcustomtoken/state/factory/ContractAddressToCustomTokenDataConverter.kt b/features/manage-tokens/impl/src/main/java/com/tangem/managetokens/presentation/addcustomtoken/state/factory/ContractAddressToCustomTokenDataConverter.kt deleted file mode 100644 index eb0897d370..0000000000 --- a/features/manage-tokens/impl/src/main/java/com/tangem/managetokens/presentation/addcustomtoken/state/factory/ContractAddressToCustomTokenDataConverter.kt +++ /dev/null @@ -1,39 +0,0 @@ -package com.tangem.managetokens.presentation.addcustomtoken.state.factory - -import com.tangem.managetokens.presentation.addcustomtoken.state.CustomTokenData -import com.tangem.managetokens.presentation.addcustomtoken.state.TextFieldState -import com.tangem.managetokens.presentation.addcustomtoken.viewmodels.AddCustomTokenClickIntents -import com.tangem.utils.converter.Converter - -internal class ContractAddressToCustomTokenDataConverter( - private val clickIntents: AddCustomTokenClickIntents, -) : Converter { - override fun convert(value: String): CustomTokenData { - return CustomTokenData( - contractAddressTextField = TextFieldState.Editable( - value = value, - isEnabled = true, - onValueChange = clickIntents::onContractAddressChange, - onFocusExit = clickIntents::onContractAddressFocusExit, - ), - nameTextField = TextFieldState.Editable( - value = "", - isEnabled = true, - onValueChange = clickIntents::onTokenNameChange, - onFocusExit = clickIntents::onTokenNameFocusExit, - ), - symbolTextField = TextFieldState.Editable( - value = "", - isEnabled = true, - onValueChange = clickIntents::onSymbolChange, - onFocusExit = clickIntents::onSymbolFocusExit, - ), - decimalsTextField = TextFieldState.Editable( - value = "", - isEnabled = true, - onValueChange = clickIntents::onDecimalsChange, - onFocusExit = clickIntents::onDecimalsFocusExit, - ), - ) - } -} \ No newline at end of file diff --git a/features/manage-tokens/impl/src/main/java/com/tangem/managetokens/presentation/addcustomtoken/state/factory/FoundTokenToCustomTokenDataConverter.kt b/features/manage-tokens/impl/src/main/java/com/tangem/managetokens/presentation/addcustomtoken/state/factory/FoundTokenToCustomTokenDataConverter.kt deleted file mode 100644 index 65921700dc..0000000000 --- a/features/manage-tokens/impl/src/main/java/com/tangem/managetokens/presentation/addcustomtoken/state/factory/FoundTokenToCustomTokenDataConverter.kt +++ /dev/null @@ -1,40 +0,0 @@ -package com.tangem.managetokens.presentation.addcustomtoken.state.factory - -import com.tangem.domain.tokens.model.FoundToken -import com.tangem.managetokens.presentation.addcustomtoken.state.CustomTokenData -import com.tangem.managetokens.presentation.addcustomtoken.state.TextFieldState -import com.tangem.managetokens.presentation.addcustomtoken.viewmodels.AddCustomTokenClickIntents -import com.tangem.utils.converter.Converter - -internal class FoundTokenToCustomTokenDataConverter( - private val clickIntents: AddCustomTokenClickIntents, -) : Converter { - override fun convert(value: FoundToken): CustomTokenData { - return CustomTokenData( - contractAddressTextField = TextFieldState.Editable( - value = value.contractAddress, - isEnabled = true, - onValueChange = clickIntents::onContractAddressChange, - onFocusExit = clickIntents::onContractAddressFocusExit, - ), - nameTextField = TextFieldState.Editable( - value = value.name, - isEnabled = false, - onValueChange = clickIntents::onTokenNameChange, - onFocusExit = clickIntents::onTokenNameFocusExit, - ), - symbolTextField = TextFieldState.Editable( - value = value.symbol, - isEnabled = false, - onValueChange = clickIntents::onSymbolChange, - onFocusExit = clickIntents::onSymbolFocusExit, - ), - decimalsTextField = TextFieldState.Editable( - value = value.decimals.toString(), - isEnabled = false, - onValueChange = clickIntents::onDecimalsChange, - onFocusExit = clickIntents::onDecimalsFocusExit, - ), - ) - } -} \ No newline at end of file diff --git a/features/manage-tokens/impl/src/main/java/com/tangem/managetokens/presentation/addcustomtoken/state/factory/NetworkToNetworkItemStateConverter.kt b/features/manage-tokens/impl/src/main/java/com/tangem/managetokens/presentation/addcustomtoken/state/factory/NetworkToNetworkItemStateConverter.kt deleted file mode 100644 index 74b4eda971..0000000000 --- a/features/manage-tokens/impl/src/main/java/com/tangem/managetokens/presentation/addcustomtoken/state/factory/NetworkToNetworkItemStateConverter.kt +++ /dev/null @@ -1,20 +0,0 @@ -package com.tangem.managetokens.presentation.addcustomtoken.state.factory - -import com.tangem.core.ui.extensions.getActiveIconResByNetworkId -import com.tangem.domain.tokens.model.Network -import com.tangem.managetokens.presentation.common.state.NetworkItemState -import com.tangem.utils.converter.Converter - -internal class NetworkToNetworkItemStateConverter( - private val onNetworkItemSelected: (NetworkItemState) -> Unit, -) : Converter { - override fun convert(value: Network): NetworkItemState { - return NetworkItemState.Selectable( - name = value.name, - protocolName = value.standardType.name, - iconResId = getActiveIconResByNetworkId(value.backendId), - id = value.backendId, - onNetworkClick = onNetworkItemSelected, - ) - } -} \ No newline at end of file diff --git a/features/manage-tokens/impl/src/main/java/com/tangem/managetokens/presentation/addcustomtoken/state/previewdata/AddCustomTokenPreviewData.kt b/features/manage-tokens/impl/src/main/java/com/tangem/managetokens/presentation/addcustomtoken/state/previewdata/AddCustomTokenPreviewData.kt deleted file mode 100644 index 96e7bf7379..0000000000 --- a/features/manage-tokens/impl/src/main/java/com/tangem/managetokens/presentation/addcustomtoken/state/previewdata/AddCustomTokenPreviewData.kt +++ /dev/null @@ -1,50 +0,0 @@ -package com.tangem.managetokens.presentation.addcustomtoken.state.previewdata - -import com.tangem.managetokens.presentation.common.state.ChooseWalletState -import com.tangem.managetokens.presentation.common.state.WalletState -import com.tangem.managetokens.presentation.addcustomtoken.state.* -import kotlinx.collections.immutable.persistentListOf -import kotlinx.collections.immutable.persistentSetOf - -internal object AddCustomTokenPreviewData { - val state = AddCustomTokenState( - chooseWalletState = ChooseWalletState.Choose( - wallets = persistentListOf(), - selectedWallet = WalletState( - "", - "", - "My Wallet", - {}, - ), - onChooseWalletClick = { }, - onCloseChoosingWalletClick = { }, - ), - chooseNetworkState = ChooseNetworkState( - networks = persistentListOf(), - selectedNetwork = null, - onChooseNetworkClick = { }, - onCloseChoosingNetworkClick = {}, - ), - chooseDerivationState = ChooseDerivationState( - derivations = persistentListOf(), - selectedDerivation = null, - enterCustomDerivationState = null, - onChooseDerivationClick = { }, - onCloseChoosingDerivationClick = {}, - onEnterCustomDerivation = {}, - ), - tokenData = CustomTokenData( - contractAddressTextField = TextFieldState.Editable( - value = "0x4ace7262705b68bcba5b91de96889349394", - isEnabled = false, - onValueChange = {}, - onFocusExit = {}, - ), - nameTextField = TextFieldState.Loading, - symbolTextField = TextFieldState.Loading, - decimalsTextField = TextFieldState.Loading, - ), - warnings = persistentSetOf(), - addTokenButton = ButtonState(isEnabled = true, onClick = {}), - ) -} \ No newline at end of file diff --git a/features/manage-tokens/impl/src/main/java/com/tangem/managetokens/presentation/addcustomtoken/state/previewdata/ChooseDerivationPreviewData.kt b/features/manage-tokens/impl/src/main/java/com/tangem/managetokens/presentation/addcustomtoken/state/previewdata/ChooseDerivationPreviewData.kt deleted file mode 100644 index c4cfd15483..0000000000 --- a/features/manage-tokens/impl/src/main/java/com/tangem/managetokens/presentation/addcustomtoken/state/previewdata/ChooseDerivationPreviewData.kt +++ /dev/null @@ -1,42 +0,0 @@ -package com.tangem.managetokens.presentation.addcustomtoken.state.previewdata - -import com.tangem.managetokens.presentation.addcustomtoken.state.ChooseDerivationState -import com.tangem.managetokens.presentation.addcustomtoken.state.Derivation -import kotlinx.collections.immutable.ImmutableList -import kotlinx.collections.immutable.persistentListOf - -internal object ChooseDerivationPreviewData { - private val derivations: ImmutableList = persistentListOf( - Derivation( - networkName = "Ethereum", - path = "m/44’/9001’/0’/0/0", - networkId = "ethereum", - standardType = "ERC", - onDerivationSelected = {}, - ), - Derivation( - networkName = "Polygon", - path = "m/44’/9001’/0’/0/0", - networkId = "polygon", - standardType = "ERC", - onDerivationSelected = {}, - ), - Derivation( - networkName = "Avalanche", - path = "m/44’/9001’/0’/0/0", - networkId = "avalanche", - standardType = "ERC", - onDerivationSelected = {}, - ), - ) - - val state = ChooseDerivationState( - derivations = derivations, - selectedDerivation = derivations.first(), - enterCustomDerivationState = null, - onEnterCustomDerivation = {}, - onCloseChoosingDerivationClick = {}, - onChooseDerivationClick = {}, - show = true, - ) -} \ No newline at end of file diff --git a/features/manage-tokens/impl/src/main/java/com/tangem/managetokens/presentation/addcustomtoken/state/previewdata/ChooseNetworkCustomPreviewData.kt b/features/manage-tokens/impl/src/main/java/com/tangem/managetokens/presentation/addcustomtoken/state/previewdata/ChooseNetworkCustomPreviewData.kt deleted file mode 100644 index 08987dbadf..0000000000 --- a/features/manage-tokens/impl/src/main/java/com/tangem/managetokens/presentation/addcustomtoken/state/previewdata/ChooseNetworkCustomPreviewData.kt +++ /dev/null @@ -1,32 +0,0 @@ -package com.tangem.managetokens.presentation.addcustomtoken.state.previewdata - -import com.tangem.features.managetokens.impl.R -import com.tangem.managetokens.presentation.common.state.NetworkItemState -import com.tangem.managetokens.presentation.addcustomtoken.state.ChooseNetworkState -import kotlinx.collections.immutable.persistentListOf - -internal object ChooseNetworkCustomPreviewData { - val networks = persistentListOf( - NetworkItemState.Selectable( - name = "Ethereum", - protocolName = "ETH", - iconResId = R.drawable.img_kusama_22, - id = "ethereum", - onNetworkClick = { }, - ), - NetworkItemState.Selectable( - name = "BNB SMART CHAIN", - protocolName = "BEP20", - iconResId = R.drawable.ic_bsc_16, - id = "binance smart chain", - onNetworkClick = { }, - ), - ) - val state = ChooseNetworkState( - networks, - selectedNetwork = networks.first(), - onCloseChoosingNetworkClick = {}, - onChooseNetworkClick = {}, - show = true, - ) -} \ No newline at end of file diff --git a/features/manage-tokens/impl/src/main/java/com/tangem/managetokens/presentation/addcustomtoken/ui/AddCustomTokenBottomSheet.kt b/features/manage-tokens/impl/src/main/java/com/tangem/managetokens/presentation/addcustomtoken/ui/AddCustomTokenBottomSheet.kt deleted file mode 100644 index 69fe567327..0000000000 --- a/features/manage-tokens/impl/src/main/java/com/tangem/managetokens/presentation/addcustomtoken/ui/AddCustomTokenBottomSheet.kt +++ /dev/null @@ -1,201 +0,0 @@ -package com.tangem.managetokens.presentation.addcustomtoken.ui - -import android.annotation.SuppressLint -import androidx.activity.compose.BackHandler -import androidx.activity.compose.LocalOnBackPressedDispatcherOwner -import androidx.compose.foundation.focusable -import androidx.compose.foundation.layout.ColumnScope -import androidx.compose.foundation.layout.WindowInsets -import androidx.compose.foundation.layout.WindowInsetsSides -import androidx.compose.foundation.layout.fillMaxSize -import androidx.compose.foundation.layout.only -import androidx.compose.foundation.layout.systemBars -import androidx.compose.material3.BottomSheetDefaults -import androidx.compose.material3.ExperimentalMaterial3Api -import androidx.compose.material3.ModalBottomSheet -import androidx.compose.material3.ModalBottomSheetDefaults -import androidx.compose.material3.ModalBottomSheetProperties -import androidx.compose.material3.SheetState -import androidx.compose.material3.SheetValue -import androidx.compose.material3.rememberModalBottomSheetState -import androidx.compose.runtime.Composable -import androidx.compose.runtime.DisposableEffect -import androidx.compose.runtime.LaunchedEffect -import androidx.compose.runtime.getValue -import androidx.compose.runtime.mutableStateOf -import androidx.compose.runtime.remember -import androidx.compose.runtime.rememberCoroutineScope -import androidx.compose.runtime.setValue -import androidx.compose.ui.Modifier -import androidx.compose.ui.focus.FocusRequester -import androidx.compose.ui.focus.focusRequester -import androidx.compose.ui.graphics.Color -import androidx.compose.ui.graphics.Shape -import androidx.compose.ui.input.key.Key -import androidx.compose.ui.input.key.KeyEventType -import androidx.compose.ui.input.key.key -import androidx.compose.ui.input.key.onPreviewKeyEvent -import androidx.compose.ui.input.key.type -import androidx.hilt.navigation.compose.hiltViewModel -import androidx.navigation.compose.NavHost -import androidx.navigation.compose.composable -import androidx.navigation.compose.rememberNavController -import com.tangem.core.ui.components.bottomsheets.TangemBottomSheetConfig -import com.tangem.core.ui.components.bottomsheets.TangemBottomSheetDraggableHeader -import com.tangem.core.ui.components.bottomsheets.collapse -import com.tangem.core.ui.res.TangemTheme -import com.tangem.managetokens.presentation.addcustomtoken.router.AddCustomTokenRoute -import com.tangem.managetokens.presentation.addcustomtoken.router.AddCustomTokenRouter -import com.tangem.managetokens.presentation.addcustomtoken.viewmodels.AddCustomTokenViewModel -import com.tangem.managetokens.presentation.common.state.ChooseWalletState -import kotlinx.coroutines.launch - -@OptIn(ExperimentalMaterial3Api::class) -@Composable -fun AddCustomTokenBottomSheet(config: TangemBottomSheetConfig) { - val viewModel = hiltViewModel() - - var isVisible by remember { mutableStateOf(value = config.isShow) } - val sheetState = rememberModalBottomSheetState(skipPartiallyExpanded = true) - - if (isVisible) { - // ViewModel cannot be scoped to ModalBottomSheet's lifecycle, - // so we have to manually initialize and dispose its state when bottom sheet enters and leaves a composition - DisposableEffect(viewModel) { - viewModel.onInitialize() - onDispose { viewModel.onDispose() } - } - - ModalBottomSheetWithBackHandling( - onDismissRequest = config.onDismissRequest, - sheetState = sheetState, - containerColor = TangemTheme.colors.background.tertiary, - shape = TangemTheme.shapes.bottomSheetLarge, - windowInsets = WindowInsets.systemBars.only(WindowInsetsSides.Top), - dragHandle = { TangemBottomSheetDraggableHeader(color = TangemTheme.colors.background.tertiary) }, - properties = ModalBottomSheetDefaults.properties(shouldDismissOnBackPress = false), - ) { - Content(onDismissRequest = config.onDismissRequest, viewModel = viewModel) - } - } - - LaunchedEffect(key1 = config.isShow) { - if (config.isShow) { - isVisible = true - } else { - sheetState.collapse { isVisible = false } - } - } -} - -@OptIn(ExperimentalMaterial3Api::class) -@Composable -private fun ModalBottomSheetWithBackHandling( - onDismissRequest: () -> Unit, - modifier: Modifier = Modifier, - containerColor: Color = BottomSheetDefaults.ContainerColor, - shape: Shape = BottomSheetDefaults.ExpandedShape, - windowInsets: WindowInsets = BottomSheetDefaults.windowInsets, - dragHandle: @Composable (() -> Unit)? = { BottomSheetDefaults.DragHandle() }, - sheetState: SheetState = rememberModalBottomSheetState(), - properties: ModalBottomSheetProperties = ModalBottomSheetDefaults.properties(), - content: @Composable ColumnScope.() -> Unit, -) { - val scope = rememberCoroutineScope() - - BackHandler(enabled = sheetState.targetValue != SheetValue.Hidden) { - // Always catch back here, but only let it dismiss if shouldDismissOnBackPress. - // If not, it will have no effect. - if (properties.shouldDismissOnBackPress) { - scope.launch { sheetState.hide() }.invokeOnCompletion { - if (!sheetState.isVisible) { - onDismissRequest() - } - } - } - } - - val requester = remember { FocusRequester() } - val backPressedDispatcherOwner = LocalOnBackPressedDispatcherOwner.current - - ModalBottomSheet( - onDismissRequest = onDismissRequest, - containerColor = containerColor, - shape = shape, - windowInsets = windowInsets, - dragHandle = dragHandle, - sheetState = sheetState, - modifier = modifier - .focusRequester(requester) - .focusable() - .onPreviewKeyEvent { - if (it.key == Key.Back && it.type == KeyEventType.KeyUp && !it.nativeKeyEvent.isCanceled) { - backPressedDispatcherOwner?.onBackPressedDispatcher?.onBackPressed() - return@onPreviewKeyEvent true - } - return@onPreviewKeyEvent false - }, - properties = ModalBottomSheetDefaults.properties( - securePolicy = properties.securePolicy, - isFocusable = properties.isFocusable, - // Set false otherwise the onPreviewKeyEvent doesn't work at all. - // The functionality of shouldDismissOnBackPress is achieved by the BackHandler. - shouldDismissOnBackPress = false, - ), - content = content, - ) - - LaunchedEffect(Unit) { - requester.requestFocus() - } -} - -@SuppressLint("RestrictedApi") -@Composable -private fun Content(viewModel: AddCustomTokenViewModel, onDismissRequest: () -> Unit) { - val navController = rememberNavController() - - LaunchedEffect(navController) { - navController.currentBackStack - .collect { - if (it.isEmpty()) { - onDismissRequest() - } - } - } - - BackHandler(true) { - navController.popBackStack() - } - - val router = remember(navController) { AddCustomTokenRouter(navController) } - - viewModel.router = router - - NavHost( - modifier = Modifier.fillMaxSize(), - navController = navController, - startDestination = AddCustomTokenRoute.Main.route, - ) { - composable( - route = AddCustomTokenRoute.Main.route, - ) { - AddCustomTokenScreen(state = viewModel.uiState) - } - composable( - route = AddCustomTokenRoute.ChooseNetwork.route, - ) { - ChooseNetworkCustomScreen(state = viewModel.uiState.chooseNetworkState) - } - composable( - route = AddCustomTokenRoute.ChooseDerivation.route, - ) { - ChooseDerivationScreen(state = requireNotNull(viewModel.uiState.chooseDerivationState)) - } - composable( - route = AddCustomTokenRoute.ChooseWallet.route, - ) { - CustomTokensChooseWalletScreen(state = viewModel.uiState.chooseWalletState as ChooseWalletState.Choose) - } - } -} \ No newline at end of file diff --git a/features/manage-tokens/impl/src/main/java/com/tangem/managetokens/presentation/addcustomtoken/ui/AddCustomTokenScreen.kt b/features/manage-tokens/impl/src/main/java/com/tangem/managetokens/presentation/addcustomtoken/ui/AddCustomTokenScreen.kt deleted file mode 100644 index d5691e9017..0000000000 --- a/features/manage-tokens/impl/src/main/java/com/tangem/managetokens/presentation/addcustomtoken/ui/AddCustomTokenScreen.kt +++ /dev/null @@ -1,298 +0,0 @@ -package com.tangem.managetokens.presentation.addcustomtoken.ui - -import android.content.res.Configuration -import androidx.compose.foundation.background -import androidx.compose.foundation.layout.* -import androidx.compose.foundation.lazy.LazyColumn -import androidx.compose.foundation.shape.RoundedCornerShape -import androidx.compose.foundation.text.KeyboardOptions -import androidx.compose.material3.Text -import androidx.compose.runtime.* -import androidx.compose.ui.ExperimentalComposeUiApi -import androidx.compose.ui.Modifier -import androidx.compose.ui.draw.clip -import androidx.compose.ui.focus.FocusDirection -import androidx.compose.ui.platform.LocalFocusManager -import androidx.compose.ui.res.stringResource -import androidx.compose.ui.text.input.ImeAction -import androidx.compose.ui.text.input.KeyboardType -import androidx.compose.ui.text.style.TextAlign -import androidx.compose.ui.tooling.preview.Preview -import com.tangem.core.ui.components.Keyboard -import com.tangem.core.ui.components.PrimaryButton -import com.tangem.core.ui.components.RectangleShimmer -import com.tangem.core.ui.components.bottomsheets.TangemBottomSheetConfig -import com.tangem.core.ui.components.keyboardAsState -import com.tangem.core.ui.extensions.resolveReference -import com.tangem.core.ui.res.TangemTheme -import com.tangem.core.ui.res.TangemThemePreview -import com.tangem.features.managetokens.impl.R -import com.tangem.managetokens.presentation.common.state.AlertState -import com.tangem.managetokens.presentation.common.state.ChooseWalletState -import com.tangem.managetokens.presentation.common.ui.ChooseWalletBottomSheet -import com.tangem.managetokens.presentation.common.ui.ChooseWalletBottomSheetConfig -import com.tangem.managetokens.presentation.common.ui.EventEffect -import com.tangem.managetokens.presentation.common.ui.components.Alert -import com.tangem.managetokens.presentation.common.ui.components.SimpleSelectionBlock -import com.tangem.managetokens.presentation.addcustomtoken.state.AddCustomTokenState -import com.tangem.managetokens.presentation.addcustomtoken.state.CustomTokenData -import com.tangem.managetokens.presentation.addcustomtoken.state.TextFieldState -import com.tangem.managetokens.presentation.addcustomtoken.state.previewdata.AddCustomTokenPreviewData - -@Composable -internal fun AddCustomTokenScreen(state: AddCustomTokenState, modifier: Modifier = Modifier) { - var alertState by remember { mutableStateOf(value = null) } - - EventEffect( - event = state.event, - onAlertStateSet = { alertState = it }, - ) - alertState?.let { - Alert(state = it, onDismiss = { alertState = null }) - } - Content(state = state, modifier = modifier) -} - -@Composable -private fun Content(state: AddCustomTokenState, modifier: Modifier = Modifier) { - val keyboard by keyboardAsState() - - Column( - modifier = modifier - .background(color = TangemTheme.colors.background.tertiary) - .statusBarsPadding() - .navigationBarsPadding() - .imePadding() - .padding( - top = TangemTheme.dimens.spacing10, - start = TangemTheme.dimens.spacing16, - end = TangemTheme.dimens.spacing16, - bottom = TangemTheme.dimens.spacing18, - ) - .fillMaxWidth(), - ) { - Text( - text = stringResource(id = R.string.manage_tokens_network_selector_title), - color = TangemTheme.colors.text.primary1, - style = TangemTheme.typography.subtitle1, - textAlign = TextAlign.Center, - modifier = Modifier - .fillMaxWidth() - .padding(bottom = TangemTheme.dimens.spacing10), - ) - Text( - text = stringResource(id = R.string.custom_token_subtitle), - color = TangemTheme.colors.text.secondary, - style = TangemTheme.typography.caption2, - textAlign = TextAlign.Center, - modifier = Modifier - .fillMaxWidth() - .padding(bottom = TangemTheme.dimens.spacing16), - ) - CustomTokenItemsList(state = state) - if (keyboard is Keyboard.Closed) { - PrimaryButton( - text = stringResource(id = R.string.custom_token_add_token), - onClick = state.addTokenButton.onClick, - enabled = state.addTokenButton.isEnabled, - modifier = Modifier.fillMaxWidth(), - ) - } - } - - if (state.chooseWalletState is ChooseWalletState.Choose && state.chooseWalletState.show) { - val config = TangemBottomSheetConfig( - isShow = true, - content = ChooseWalletBottomSheetConfig(state.chooseWalletState), - onDismissRequest = state.chooseWalletState.onCloseChoosingWalletClick, - ) - ChooseWalletBottomSheet(config) - } -} - -@Composable -private fun ColumnScope.CustomTokenItemsList(state: AddCustomTokenState, modifier: Modifier = Modifier) { - LazyColumn( - modifier - .fillMaxWidth() - .weight(1f), - ) { - if (state.chooseWalletState is ChooseWalletState.Choose) { - item { - SimpleSelectionBlock( - title = stringResource(id = R.string.manage_tokens_network_selector_wallet), - subtitle = state.chooseWalletState.selectedWallet?.walletName ?: "", - onClick = state.chooseWalletState.onChooseWalletClick, - modifier = Modifier - .padding(bottom = TangemTheme.dimens.spacing12), - ) - } - } - item { - SimpleSelectionBlock( - title = stringResource(id = R.string.custom_token_network_input_title), - subtitle = state.chooseNetworkState.selectedNetwork?.name - ?: stringResource(id = R.string.manage_tokens_network_selector_title), - onClick = state.chooseNetworkState.onChooseNetworkClick, - modifier = Modifier - .padding(bottom = TangemTheme.dimens.spacing12), - ) - } - if (state.tokenData != null) { - item { - TokenFields( - state = state.tokenData, - modifier = Modifier - .padding(bottom = TangemTheme.dimens.spacing12), - ) - } - } - if (state.chooseDerivationState != null) { - item { - SimpleSelectionBlock( - title = stringResource(id = R.string.custom_token_derivation_path), - subtitle = state.chooseDerivationState.selectedDerivation?.path - ?: stringResource(id = R.string.custom_token_derivation_path_default), - onClick = state.chooseDerivationState.onChooseDerivationClick, - modifier = Modifier.padding(bottom = TangemTheme.dimens.spacing12), - ) - } - } - } -} - -@OptIn(ExperimentalComposeUiApi::class) -@Composable -private fun TokenFields(state: CustomTokenData, modifier: Modifier = Modifier) { - val focusManager = LocalFocusManager.current - - Column( - modifier = modifier - .fillMaxWidth() - .clip(shape = RoundedCornerShape(TangemTheme.dimens.radius16)) - .background(color = TangemTheme.colors.background.action), - ) { - TokenField( - textFieldState = state.contractAddressTextField, - placeholder = "0x0000000000000000000000000000000", - title = R.string.custom_token_contract_address_input_title, - keyboardOptions = KeyboardOptions( - keyboardType = KeyboardType.Text, - imeAction = if (state.isNameSymbolDecimalsDisabled()) { - ImeAction.Done - } else { - ImeAction.Next - }, - ), - onImeAction = { - if (state.isNameSymbolDecimalsDisabled()) { - focusManager.moveFocus(FocusDirection.Exit) - } else { - focusManager.moveFocus(FocusDirection.Down) - } - }, - ) - TokenField( - textFieldState = state.nameTextField, - placeholder = stringResource(id = R.string.custom_token_name_input_placeholder), - title = R.string.custom_token_name_input_title, - keyboardOptions = KeyboardOptions( - keyboardType = KeyboardType.Text, - imeAction = ImeAction.Next, - ), - onImeAction = { focusManager.moveFocus(FocusDirection.Down) }, - ) - TokenField( - textFieldState = state.symbolTextField, - placeholder = stringResource(id = R.string.custom_token_token_symbol_input_placeholder), - title = R.string.custom_token_token_symbol_input_title, - keyboardOptions = KeyboardOptions( - keyboardType = KeyboardType.Text, - imeAction = ImeAction.Next, - ), - onImeAction = { focusManager.moveFocus(FocusDirection.Down) }, - ) - TokenField( - textFieldState = state.decimalsTextField, - placeholder = "0", - title = R.string.custom_token_decimals_input_title, - keyboardOptions = KeyboardOptions( - keyboardType = KeyboardType.Number, - imeAction = ImeAction.Done, - ), - onImeAction = { focusManager.moveFocus(FocusDirection.Exit) }, - ) - } -} - -@Composable -private fun TokenField( - textFieldState: TextFieldState, - placeholder: String, - title: Int, - onImeAction: () -> Unit, - keyboardOptions: KeyboardOptions, -) { - Column( - modifier = Modifier - .background(color = TangemTheme.colors.background.action) - .padding(TangemTheme.dimens.spacing16), - ) { - TokenTextFieldTitle( - state = textFieldState, - title = stringResource(id = title), - ) - when (textFieldState) { - is TextFieldState.Editable -> TokenTextField( - state = textFieldState, - placeholder = placeholder, - onImeAction = onImeAction, - keyboardOptions = keyboardOptions, - ) - is TextFieldState.Loading -> TokenShimmer() - } - } -} - -@Composable -private fun TokenShimmer() { - RectangleShimmer( - radius = TangemTheme.dimens.radius3, - modifier = Modifier - .padding(vertical = TangemTheme.dimens.spacing4) - .size( - height = TangemTheme.dimens.size12, - width = TangemTheme.dimens.size90, - ), - ) -} - -@Composable -private fun TokenTextFieldTitle(state: TextFieldState?, title: String) { - val modifier = Modifier.padding(bottom = TangemTheme.dimens.spacing4) - val error = (state as? TextFieldState.Editable)?.error - if (error == null) { - Text( - text = title, - color = TangemTheme.colors.text.secondary, - style = TangemTheme.typography.subtitle1, - modifier = modifier, - ) - } else { - Text( - text = error.title.resolveReference(), - color = TangemTheme.colors.text.warning, - style = TangemTheme.typography.subtitle1, - modifier = modifier, - ) - } -} - -@Preview -@Preview(uiMode = Configuration.UI_MODE_NIGHT_YES) -@Composable -private fun Preview_ChooseDerivationScreen() { - TangemThemePreview { - AddCustomTokenScreen(state = AddCustomTokenPreviewData.state) - } -} \ No newline at end of file diff --git a/features/manage-tokens/impl/src/main/java/com/tangem/managetokens/presentation/addcustomtoken/ui/ChooseDerivationScreen.kt b/features/manage-tokens/impl/src/main/java/com/tangem/managetokens/presentation/addcustomtoken/ui/ChooseDerivationScreen.kt deleted file mode 100644 index a7805cbb96..0000000000 --- a/features/manage-tokens/impl/src/main/java/com/tangem/managetokens/presentation/addcustomtoken/ui/ChooseDerivationScreen.kt +++ /dev/null @@ -1,109 +0,0 @@ -package com.tangem.managetokens.presentation.addcustomtoken.ui - -import android.content.res.Configuration -import androidx.compose.foundation.background -import androidx.compose.foundation.clickable -import androidx.compose.foundation.layout.* -import androidx.compose.foundation.lazy.LazyColumn -import androidx.compose.material.Icon -import androidx.compose.material3.Text -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.res.stringResource -import androidx.compose.ui.tooling.preview.Preview -import com.tangem.core.ui.decorations.roundedShapeItemDecoration -import com.tangem.core.ui.res.TangemThemePreview -import com.tangem.core.ui.res.TangemTheme -import com.tangem.features.managetokens.impl.R -import com.tangem.managetokens.presentation.common.ui.components.SimpleSelectionBlock -import com.tangem.managetokens.presentation.addcustomtoken.state.ChooseDerivationState -import com.tangem.managetokens.presentation.addcustomtoken.state.previewdata.ChooseDerivationPreviewData - -@Composable -internal fun ChooseDerivationScreen(state: ChooseDerivationState, modifier: Modifier = Modifier) { - if (state.enterCustomDerivationState != null) { - CustomDerivationDialog(state.enterCustomDerivationState) - } - - Column( - modifier = modifier - .fillMaxSize() - .background(color = TangemTheme.colors.background.tertiary) - .statusBarsPadding() - .navigationBarsPadding() - .padding( - top = TangemTheme.dimens.spacing10, - start = TangemTheme.dimens.spacing16, - end = TangemTheme.dimens.spacing16, - bottom = TangemTheme.dimens.spacing18, - ), - ) { - Box( - modifier = Modifier - .fillMaxWidth() - .defaultMinSize(minHeight = TangemTheme.dimens.size44) - .padding(bottom = TangemTheme.dimens.spacing12), - contentAlignment = Alignment.CenterStart, - ) { - Icon( - painter = painterResource(id = R.drawable.ic_back_24), - contentDescription = null, - tint = TangemTheme.colors.icon.primary1, - modifier = Modifier - .clickable { state.onCloseChoosingDerivationClick() }, - ) - Text( - text = stringResource(id = R.string.custom_token_derivation_path), - color = TangemTheme.colors.text.primary1, - style = TangemTheme.typography.subtitle1, - modifier = Modifier - .padding(horizontal = TangemTheme.dimens.spacing24) - .align(Alignment.Center), - ) - } - DerivationsList(state) - } -} - -@Composable -private fun DerivationsList(state: ChooseDerivationState) { - LazyColumn( - modifier = Modifier - .padding(horizontal = TangemTheme.dimens.spacing16), - contentPadding = PaddingValues(vertical = TangemTheme.dimens.spacing12), - ) { - item { - SimpleSelectionBlock( - title = stringResource(id = R.string.custom_token_custom_derivation), - subtitle = stringResource(id = R.string.custom_token_custom_derivation), - onClick = state.onEnterCustomDerivation, - modifier = Modifier.padding(bottom = TangemTheme.dimens.spacing12), - ) - } - items(state.derivations.count()) { index -> - val derivationItem = state.derivations[index] - SimpleSelectionBlock( - title = derivationItem.networkName, - subtitle = derivationItem.path, - onClick = { derivationItem.onDerivationSelected(derivationItem) }, - modifier = Modifier.roundedShapeItemDecoration( - currentIndex = index, - lastIndex = state.derivations.lastIndex, - addDefaultPadding = false, - ), - roundedCorners = false, - ) - } - } -} - -@Preview -@Preview(uiMode = Configuration.UI_MODE_NIGHT_YES) -@Composable -private fun Preview_ChooseDerivationScreen() { - TangemThemePreview { - ChooseDerivationScreen(state = ChooseDerivationPreviewData.state) - } -} \ No newline at end of file diff --git a/features/manage-tokens/impl/src/main/java/com/tangem/managetokens/presentation/addcustomtoken/ui/ChooseNetworkCustomScreen.kt b/features/manage-tokens/impl/src/main/java/com/tangem/managetokens/presentation/addcustomtoken/ui/ChooseNetworkCustomScreen.kt deleted file mode 100644 index 6777fc4fbc..0000000000 --- a/features/manage-tokens/impl/src/main/java/com/tangem/managetokens/presentation/addcustomtoken/ui/ChooseNetworkCustomScreen.kt +++ /dev/null @@ -1,89 +0,0 @@ -package com.tangem.managetokens.presentation.addcustomtoken.ui - -import android.content.res.Configuration -import androidx.compose.foundation.background -import androidx.compose.foundation.clickable -import androidx.compose.foundation.layout.* -import androidx.compose.foundation.lazy.LazyColumn -import androidx.compose.material.Icon -import androidx.compose.material3.Text -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.res.stringResource -import androidx.compose.ui.tooling.preview.Preview -import com.tangem.core.ui.decorations.roundedShapeItemDecoration -import com.tangem.core.ui.res.TangemThemePreview -import com.tangem.core.ui.res.TangemTheme -import com.tangem.features.managetokens.impl.R -import com.tangem.managetokens.presentation.common.ui.components.NetworkItem -import com.tangem.managetokens.presentation.addcustomtoken.state.ChooseNetworkState -import com.tangem.managetokens.presentation.addcustomtoken.state.previewdata.ChooseNetworkCustomPreviewData - -@Composable -internal fun ChooseNetworkCustomScreen(state: ChooseNetworkState, modifier: Modifier = Modifier) { - Column( - modifier = modifier - .fillMaxSize() - .background(color = TangemTheme.colors.background.tertiary) - .statusBarsPadding() - .navigationBarsPadding() - .padding( - top = TangemTheme.dimens.spacing10, - start = TangemTheme.dimens.spacing16, - end = TangemTheme.dimens.spacing16, - bottom = TangemTheme.dimens.spacing18, - ), - ) { - Box( - modifier = Modifier - .fillMaxWidth() - .defaultMinSize(minHeight = TangemTheme.dimens.size44) - .padding(bottom = TangemTheme.dimens.spacing12), - contentAlignment = Alignment.CenterStart, - ) { - Icon( - painter = painterResource(id = R.drawable.ic_back_24), - contentDescription = null, - tint = TangemTheme.colors.icon.primary1, - modifier = Modifier - .clickable { state.onCloseChoosingNetworkClick() }, - ) - Text( - text = stringResource(id = R.string.custom_token_network_selector_title), - color = TangemTheme.colors.text.primary1, - style = TangemTheme.typography.subtitle1, - modifier = Modifier - .padding(horizontal = TangemTheme.dimens.spacing24) - .align(Alignment.Center), - ) - } - LazyColumn( - contentPadding = PaddingValues(vertical = TangemTheme.dimens.spacing12), - ) { - items(state.networks.count()) { index -> - NetworkItem( - state = state.networks[index], - tokenState = null, - isSelected = state.selectedNetwork == state.networks[index], - modifier = Modifier - .roundedShapeItemDecoration( - currentIndex = index, - lastIndex = state.networks.lastIndex, - addDefaultPadding = false, - ), - ) - } - } - } -} - -@Preview -@Preview(uiMode = Configuration.UI_MODE_NIGHT_YES) -@Composable -private fun Preview_ChooseNetworkScreen() { - TangemThemePreview { - ChooseNetworkCustomScreen(ChooseNetworkCustomPreviewData.state) - } -} \ No newline at end of file diff --git a/features/manage-tokens/impl/src/main/java/com/tangem/managetokens/presentation/addcustomtoken/ui/CustomDerivationDialog.kt b/features/manage-tokens/impl/src/main/java/com/tangem/managetokens/presentation/addcustomtoken/ui/CustomDerivationDialog.kt deleted file mode 100644 index 969d7f61fb..0000000000 --- a/features/manage-tokens/impl/src/main/java/com/tangem/managetokens/presentation/addcustomtoken/ui/CustomDerivationDialog.kt +++ /dev/null @@ -1,43 +0,0 @@ -package com.tangem.managetokens.presentation.addcustomtoken.ui - -import androidx.compose.runtime.Composable -import androidx.compose.ui.res.stringResource -import com.tangem.core.ui.components.AdditionalTextInputDialogParams -import com.tangem.core.ui.components.DialogButton -import com.tangem.core.ui.components.TextInputDialog -import com.tangem.features.managetokens.impl.R -import com.tangem.managetokens.presentation.addcustomtoken.state.EnterCustomDerivationState - -@Composable -internal fun CustomDerivationDialog(state: EnterCustomDerivationState) { - val confirmButton = DialogButton( - title = stringResource(id = R.string.common_ok), - enabled = state.confirmButtonEnabled, - onClick = state.onConfirmButtonClick, - ) - - val dismissButton = DialogButton( - title = stringResource(id = R.string.common_cancel), - onClick = state.onDismiss, - ) - - val params = AdditionalTextInputDialogParams( - placeholder = stringResource(id = R.string.custom_token_custom_derivation_placeholder), - isError = state.derivationIncorrect, - errorText = if (state.derivationIncorrect) { - stringResource(R.string.custom_token_invalid_derivation_path) - } else { - null - }, - ) - - TextInputDialog( - fieldValue = state.value, - confirmButton = confirmButton, - onDismissDialog = state.onDismiss, - onValueChange = state.onValueChange, - textFieldParams = params, - title = stringResource(id = R.string.custom_token_custom_derivation_title), - dismissButton = dismissButton, - ) -} \ No newline at end of file diff --git a/features/manage-tokens/impl/src/main/java/com/tangem/managetokens/presentation/addcustomtoken/ui/CustomTokenChooseWalletScreen.kt b/features/manage-tokens/impl/src/main/java/com/tangem/managetokens/presentation/addcustomtoken/ui/CustomTokenChooseWalletScreen.kt deleted file mode 100644 index 3b8eb7c2af..0000000000 --- a/features/manage-tokens/impl/src/main/java/com/tangem/managetokens/presentation/addcustomtoken/ui/CustomTokenChooseWalletScreen.kt +++ /dev/null @@ -1,20 +0,0 @@ -package com.tangem.managetokens.presentation.addcustomtoken.ui - -import androidx.compose.foundation.layout.fillMaxSize -import androidx.compose.foundation.layout.navigationBarsPadding -import androidx.compose.foundation.layout.statusBarsPadding -import androidx.compose.runtime.Composable -import androidx.compose.ui.Modifier -import com.tangem.managetokens.presentation.common.state.ChooseWalletState -import com.tangem.managetokens.presentation.common.ui.ChooseWalletScreen - -@Composable -internal fun CustomTokensChooseWalletScreen(state: ChooseWalletState.Choose) { - ChooseWalletScreen( - state = state, - modifier = Modifier - .fillMaxSize() - .statusBarsPadding() - .navigationBarsPadding(), - ) -} \ No newline at end of file diff --git a/features/manage-tokens/impl/src/main/java/com/tangem/managetokens/presentation/addcustomtoken/ui/TokenTextField.kt b/features/manage-tokens/impl/src/main/java/com/tangem/managetokens/presentation/addcustomtoken/ui/TokenTextField.kt deleted file mode 100644 index 63521c6775..0000000000 --- a/features/manage-tokens/impl/src/main/java/com/tangem/managetokens/presentation/addcustomtoken/ui/TokenTextField.kt +++ /dev/null @@ -1,81 +0,0 @@ -package com.tangem.managetokens.presentation.addcustomtoken.ui - -import androidx.compose.foundation.layout.Row -import androidx.compose.foundation.layout.fillMaxWidth -import androidx.compose.foundation.text.BasicTextField -import androidx.compose.foundation.text.KeyboardOptions -import androidx.compose.material3.Text -import androidx.compose.runtime.Composable -import androidx.compose.runtime.LaunchedEffect -import androidx.compose.runtime.mutableStateOf -import androidx.compose.runtime.remember -import androidx.compose.ui.Modifier -import androidx.compose.ui.focus.onFocusChanged -import androidx.compose.ui.graphics.SolidColor -import androidx.compose.ui.input.key.* -import androidx.compose.ui.text.font.FontWeight -import androidx.compose.ui.text.input.ImeAction -import androidx.compose.ui.text.input.KeyboardType -import com.tangem.core.ui.res.TangemTheme -import com.tangem.managetokens.presentation.addcustomtoken.state.TextFieldState - -@Composable -internal fun TokenTextField( - state: TextFieldState.Editable, - placeholder: String, - onImeAction: () -> Unit, - keyboardOptions: KeyboardOptions = KeyboardOptions( - keyboardType = KeyboardType.Text, - imeAction = ImeAction.Default, - ), -) { - val isInitiallyComposed = remember { mutableStateOf(false) } - LaunchedEffect(key1 = true) { - isInitiallyComposed.value = true - } - - BasicTextField( - value = state.value, - onValueChange = state.onValueChange, - keyboardOptions = keyboardOptions, - singleLine = true, - maxLines = 1, - textStyle = TangemTheme.typography.subtitle1.copy( - fontWeight = FontWeight.Normal, - color = if (state.isEnabled) TangemTheme.colors.text.primary1 else TangemTheme.colors.text.disabled, - ), - cursorBrush = SolidColor(TangemTheme.colors.icon.primary1), - modifier = Modifier - .fillMaxWidth() - .onKeyEvent { keyEvent -> - if (keyEvent.type == KeyEventType.KeyUp && keyEvent.key == Key.Enter) { - onImeAction() - true - } else { - false - } - } - .onFocusChanged { - if (!it.isFocused && isInitiallyComposed.value) { - state.onFocusExit() - } - }, - decorationBox = { innerTextField -> - Row(modifier = Modifier.fillMaxWidth()) { - if (state.value.isEmpty()) { - Text( - text = placeholder, - color = if (state.isEnabled) { - TangemTheme.colors.text.tertiary - } else { - TangemTheme.colors.text.disabled - }, - style = TangemTheme.typography.body2, - ) - } - } - innerTextField() - }, - enabled = state.isEnabled, - ) -} \ No newline at end of file diff --git a/features/manage-tokens/impl/src/main/java/com/tangem/managetokens/presentation/addcustomtoken/viewmodels/AddCustomTokenClickIntents.kt b/features/manage-tokens/impl/src/main/java/com/tangem/managetokens/presentation/addcustomtoken/viewmodels/AddCustomTokenClickIntents.kt deleted file mode 100644 index 5a2e8e299b..0000000000 --- a/features/manage-tokens/impl/src/main/java/com/tangem/managetokens/presentation/addcustomtoken/viewmodels/AddCustomTokenClickIntents.kt +++ /dev/null @@ -1,54 +0,0 @@ -package com.tangem.managetokens.presentation.addcustomtoken.viewmodels - -import com.tangem.managetokens.presentation.common.state.NetworkItemState -import com.tangem.managetokens.presentation.addcustomtoken.state.Derivation - -@Suppress("TooManyFunctions") -internal interface AddCustomTokenClickIntents { - - fun onNetworkSelected(networkItemState: NetworkItemState) - - fun onChooseNetworkClick() - - fun onCloseChoosingNetworkClick() - - fun onWalletSelected(walletId: String) - - fun onChooseWalletClick() - - fun onCloseChoosingWalletClick() - - fun onContractAddressChange(input: String) - - fun onTokenNameChange(input: String) - - fun onSymbolChange(input: String) - - fun onDecimalsChange(input: String) - - fun onContractAddressFocusExit() - - fun onTokenNameFocusExit() - - fun onSymbolFocusExit() - - fun onDecimalsFocusExit() - - fun onDerivationSelected(derivation: Derivation) - - fun onChooseDerivationClick() - - fun onCloseChoosingDerivationClick() - - fun onEnterCustomDerivation() - - fun onCustomDerivationChange(input: String) - - fun onCustomDerivationSelected() - - fun onCustomDerivationDialogDismissed() - - fun onAddCustomButtonClick() - - fun onBack() -} \ No newline at end of file diff --git a/features/manage-tokens/impl/src/main/java/com/tangem/managetokens/presentation/addcustomtoken/viewmodels/AddCustomTokenViewModel.kt b/features/manage-tokens/impl/src/main/java/com/tangem/managetokens/presentation/addcustomtoken/viewmodels/AddCustomTokenViewModel.kt deleted file mode 100644 index 44e55b947d..0000000000 --- a/features/manage-tokens/impl/src/main/java/com/tangem/managetokens/presentation/addcustomtoken/viewmodels/AddCustomTokenViewModel.kt +++ /dev/null @@ -1,484 +0,0 @@ -package com.tangem.managetokens.presentation.addcustomtoken.viewmodels - -import androidx.compose.runtime.Stable -import androidx.compose.runtime.getValue -import androidx.compose.runtime.mutableStateOf -import androidx.compose.runtime.setValue -import androidx.lifecycle.DefaultLifecycleObserver -import androidx.lifecycle.ViewModel -import androidx.lifecycle.viewModelScope -import arrow.core.getOrElse -import com.tangem.core.analytics.api.AnalyticsEventHandler -import com.tangem.domain.common.util.derivationStyleProvider -import com.tangem.domain.tokens.* -import com.tangem.domain.tokens.model.CryptoCurrency -import com.tangem.domain.tokens.model.Network -import com.tangem.domain.wallets.models.UserWallet -import com.tangem.domain.wallets.models.UserWalletId -import com.tangem.domain.wallets.usecase.GetSelectedWalletSyncUseCase -import com.tangem.domain.wallets.usecase.GetWalletsUseCase -import com.tangem.domain.wallets.usecase.SelectWalletUseCase -import com.tangem.managetokens.presentation.addcustomtoken.router.AddCustomTokenRouter -import com.tangem.managetokens.presentation.common.analytics.ManageTokens -import com.tangem.managetokens.presentation.common.state.AlertState -import com.tangem.managetokens.presentation.common.state.Event -import com.tangem.managetokens.presentation.common.state.NetworkItemState -import com.tangem.managetokens.presentation.addcustomtoken.state.* -import com.tangem.managetokens.presentation.addcustomtoken.state.factory.AddCustomTokenStateToCryptoCurrencyConverter -import com.tangem.managetokens.presentation.addcustomtoken.state.factory.ContractAddressToCustomTokenDataConverter -import com.tangem.managetokens.presentation.addcustomtoken.state.factory.AddCustomTokenStateFactory -import com.tangem.managetokens.presentation.addcustomtoken.state.factory.FoundTokenToCustomTokenDataConverter -import com.tangem.utils.Provider -import com.tangem.utils.coroutines.CoroutineDispatcherProvider -import com.tangem.utils.coroutines.Debouncer -import com.tangem.utils.coroutines.Debouncer.Companion.DEFAULT_WAIT_TIME_MS -import dagger.hilt.android.lifecycle.HiltViewModel -import kotlinx.collections.immutable.toPersistentSet -import kotlinx.coroutines.* -import kotlinx.coroutines.flow.collectLatest -import kotlinx.coroutines.flow.distinctUntilChanged -import javax.inject.Inject -import kotlin.properties.Delegates - -@Suppress("LongParameterList", "TooManyFunctions", "LargeClass") -@Stable -@HiltViewModel -internal class AddCustomTokenViewModel @Inject constructor( - private val dispatchers: CoroutineDispatcherProvider, - private val getWalletsUseCase: GetWalletsUseCase, - private val getSelectedWalletSyncUseCase: GetSelectedWalletSyncUseCase, - private val addCryptoCurrenciesUseCase: AddCryptoCurrenciesUseCase, - private val selectWalletUseCase: SelectWalletUseCase, - private val getCurrenciesUseCase: GetCryptoCurrenciesUseCase, - private val findTokenByContractAddressUseCase: FindTokenByContractAddressUseCase, - private val validateContractAddressUseCase: ValidateContractAddressUseCase, - private val getNetworksSupportedByWallet: GetNetworksSupportedByWallet, - private val areTokensSupportedByNetworkUseCase: AreTokensSupportedByNetworkUseCase, - private val requiresHardenedDerivationOnlyUseCase: RequiresHardenedDerivationOnlyUseCase, - private val analyticsEventHandler: AnalyticsEventHandler, -) : ViewModel(), AddCustomTokenClickIntents, DefaultLifecycleObserver { - - private val debouncer = Debouncer() - - private val stateFactory = AddCustomTokenStateFactory( - currentStateProvider = Provider { uiState }, - clickIntents = this, - ) - - var router: AddCustomTokenRouter by Delegates.notNull() - - var uiState: AddCustomTokenState by mutableStateOf(stateFactory.getInitialState()) - private set - - /** - * Called when the bottom sheet was opened - */ - fun onInitialize() { - viewModelScope.launch(dispatchers.io) { - getWalletsUseCase() - .distinctUntilChanged() - .collectLatest { userWallets -> - val suitableUserWallets = userWallets.filter { it.isMultiCurrency && !it.isLocked } - val selectedWalletId = selectSuitableWallet(suitableUserWallets) - val networks = selectedWalletId?.let { getSupportedNetworks(selectedWalletId) } ?: emptyList() - withContext(dispatchers.main) { - uiState = stateFactory.getFullState( - allUserWallets = suitableUserWallets, - suitableUserWallets = userWallets, - selectedWalletId = selectedWalletId, - supportedNetworks = networks, - ) - } - } - } - } - - /** - * Called after the bottom sheet is closed - */ - fun onDispose() { - // We have to manually cancel viewModelScope's child jobs when bottom sheet is closed - viewModelScope.coroutineContext.cancelChildren() - // and reset state - uiState = stateFactory.getInitialState() - } - - private suspend fun selectSuitableWallet(suitableUserWallets: List): UserWalletId? { - val selectedWallet = getSelectedWalletSyncUseCase().getOrNull() - val selectedWalletId = if (walletSupportsAddingTokens(selectedWallet) && suitableUserWallets.isNotEmpty()) { - val walletId = suitableUserWallets.first().walletId - selectWalletUseCase(walletId) - walletId - } else { - selectedWallet?.walletId - } - return selectedWalletId - } - - private fun walletSupportsAddingTokens(userWallet: UserWallet?): Boolean { - return userWallet != null && userWallet.isMultiCurrency && !userWallet.isLocked - } - - private suspend fun getSupportedNetworks(userWalletId: UserWalletId): List { - return getNetworksSupportedByWallet(userWalletId).fold( - ifLeft = { emptyList() }, - ifRight = { it }, - ) - } - - override fun onNetworkSelected(networkItemState: NetworkItemState) { - analyticsEventHandler.send(ManageTokens.CustomTokenNetworkSelected(networkItemState.name)) - selectNetwork(networkItemState) - router.popBackStack() - } - - private fun selectNetwork(networkItemState: NetworkItemState) { - viewModelScope.launch(dispatchers.io) { - // TODO [REDACTED_TASK_KEY] - val selectedWalletId = getSelectedWalletSyncUseCase().getOrNull()?.walletId ?: return@launch - val supportsTokens = areTokensSupportedByNetworkUseCase( - networkId = networkItemState.id, - userWalletId = selectedWalletId, - ).getOrNull() ?: false - - val networksForDerivations = getSupportedNetworks(selectedWalletId) - - withContext(dispatchers.main) { - uiState = stateFactory.updateStateOnNetworkSelected( - networkItemState = networkItemState, - supportsTokens = supportsTokens, - networks = networksForDerivations, - requiresHardenedDerivationOnly = requiresHardenedDerivationOnly( - networkId = networkItemState.id, - userWalletId = selectedWalletId, - ), - ) - } - } - } - - override fun onChooseNetworkClick() { - router.openCustomTokenChooseNetwork() - } - - override fun onCloseChoosingNetworkClick() { - router.popBackStack() - } - - override fun onWalletSelected(walletId: String) { - analyticsEventHandler.send(ManageTokens.WalletSelected(ManageTokens.WalletSelected.Source.CustomToken)) - viewModelScope.launch(dispatchers.io) { - val userWalletId = UserWalletId(walletId) - selectWalletUseCase(userWalletId) - val supportedNetworks = getSupportedNetworks(UserWalletId(walletId)) - - withContext(dispatchers.main) { - uiState = stateFactory.updateWithNewWalletSelected( - selectedWalletId = userWalletId, - supportedNetworks = supportedNetworks, - ) - router.popBackStack() - } - } - } - - override fun onChooseWalletClick() { - router.openCustomTokenChooseWallet() - } - - override fun onCloseChoosingWalletClick() { - router.popBackStack() - } - - override fun onContractAddressChange(input: String) { - uiState = uiState.copy( - tokenData = uiState.tokenData?.copy( - contractAddressTextField = TextFieldState.Editable( - value = input, - isEnabled = true, - onValueChange = this::onContractAddressChange, - onFocusExit = this::onContractAddressFocusExit, - ), - ), - ) - debouncer.debounce(waitMs = DEFAULT_WAIT_TIME_MS, coroutineScope = viewModelScope + dispatchers.io) { - uiState.chooseNetworkState.selectedNetwork?.let { networkItemState -> - validateContractAddressUseCase(input, networkItemState.id).fold( - ifRight = { - uiState = stateFactory.removeTokenAddressError() - .copy( - addTokenButton = uiState.addTokenButton.copy( - isEnabled = uiState.tokenData?.isRequiredInformationProvided() == true, - ), - warnings = uiState.warnings - .filterNot { it is AddCustomTokenWarning.PotentialScamToken }.toPersistentSet(), - ) - fetchTokenInformation(contractAddress = input, networkId = networkItemState.id) - }, - ifLeft = { error -> - uiState = stateFactory.handleAddressError(error) - }, - ) - } - } - } - - private fun fetchTokenInformation(contractAddress: String, networkId: String) { - viewModelScope.launch(dispatchers.main) { - uiState = stateFactory.updateStateOnLoadingTokenInfo(contractAddress) - withContext(dispatchers.io) { - findTokenByContractAddressUseCase( - contractAddress = contractAddress, - networkId = networkId, - ).fold( - ifLeft = { - val tokenData = ContractAddressToCustomTokenDataConverter(this@AddCustomTokenViewModel) - .convert(contractAddress) - - val isButtonEnabled = tokenData.isRequiredInformationProvided() - uiState = uiState.copy( - tokenData = tokenData, - warnings = (uiState.warnings + AddCustomTokenWarning.PotentialScamToken).toPersistentSet(), - addTokenButton = uiState.addTokenButton.copy( - isEnabled = isButtonEnabled, - ), - ) - }, - ifRight = { token -> - val tokenData = if (token != null) { - FoundTokenToCustomTokenDataConverter(this@AddCustomTokenViewModel).convert(token) - } else { - ContractAddressToCustomTokenDataConverter(this@AddCustomTokenViewModel).convert( - contractAddress, - ) - } - - val isButtonEnabled = tokenData.isRequiredInformationProvided() - uiState = uiState.copy( - tokenData = tokenData, - addTokenButton = uiState.addTokenButton.copy( - isEnabled = isButtonEnabled, - ), - ) - }, - ) - } - } - } - - override fun onTokenNameChange(input: String) { - uiState = uiState.copy( - tokenData = uiState.tokenData?.copy( - nameTextField = TextFieldState.Editable( - value = input, - isEnabled = true, - onValueChange = this::onTokenNameChange, - onFocusExit = this::onTokenNameFocusExit, - ), - ), - addTokenButton = uiState.addTokenButton.copy( - isEnabled = uiState.tokenData?.isRequiredInformationProvided() == true, - ), - ) - } - - override fun onSymbolChange(input: String) { - uiState = uiState.copy( - tokenData = uiState.tokenData?.copy( - symbolTextField = TextFieldState.Editable( - value = input, - isEnabled = true, - onValueChange = this::onSymbolChange, - onFocusExit = this::onSymbolFocusExit, - ), - ), - addTokenButton = uiState.addTokenButton.copy( - isEnabled = uiState.tokenData?.isRequiredInformationProvided() == true, - ), - ) - } - - override fun onDecimalsChange(input: String) { - val correctInput = input.toIntOrNull() - val error = if (input.isNotBlank() && correctInput == null) { - AddCustomTokenWarning.WrongDecimals - } else { - null - } - uiState = uiState.copy( - tokenData = uiState.tokenData?.copy( - decimalsTextField = TextFieldState.Editable( - value = input, - isEnabled = true, - onValueChange = this::onDecimalsChange, - error = error, - onFocusExit = this::onDecimalsFocusExit, - ), - ), - addTokenButton = uiState.addTokenButton.copy( - isEnabled = uiState.tokenData?.isRequiredInformationProvided() == true, - ), - ) - } - - override fun onContractAddressFocusExit() { - val error = (uiState.tokenData?.contractAddressTextField as? TextFieldState.Editable)?.error - val validated = error !is AddCustomTokenWarning.InvalidContractAddress - analyticsEventHandler.send(ManageTokens.CustomTokenAddress(validated = validated)) - } - - override fun onTokenNameFocusExit() { - analyticsEventHandler.send(ManageTokens.CustomTokenName) - } - - override fun onSymbolFocusExit() { - analyticsEventHandler.send(ManageTokens.CustomTokenSymbol) - } - - override fun onDecimalsFocusExit() { - analyticsEventHandler.send(ManageTokens.CustomTokenDecimals) - } - - override fun onDerivationSelected(derivation: Derivation) { - derivation.standardType?.let { - analyticsEventHandler.send(ManageTokens.CustomTokenDerivationSelected(derivation.networkName)) - } - uiState = uiState.copy( - chooseDerivationState = uiState.chooseDerivationState?.copy(selectedDerivation = derivation), - ) - router.popBackStack() - } - - override fun onChooseDerivationClick() { - router.openCustomTokenChooseDerivation() - } - - override fun onCloseChoosingDerivationClick() { - router.popBackStack() - } - - override fun onCustomDerivationChange(input: String) { - val selectedWallet = getSelectedWalletSyncUseCase().getOrNull() ?: return - - analyticsEventHandler.send(ManageTokens.CustomTokenDerivationSelected(ManageTokens.Derivation.CUSTOM.value)) - uiState = uiState.copy( - chooseDerivationState = uiState.chooseDerivationState?.copy( - enterCustomDerivationState = uiState.chooseDerivationState?.enterCustomDerivationState?.copy( - value = input, - ), - ), - ) - debouncer.debounce(waitMs = DEFAULT_WAIT_TIME_MS, coroutineScope = viewModelScope + dispatchers.io) { - val networkId = uiState.chooseNetworkState.selectedNetwork?.id ?: return@debounce - uiState = stateFactory.updateOnCustomDerivationEntered( - input = input, - requiresHardenedDerivationOnly = requiresHardenedDerivationOnly(networkId, selectedWallet.walletId), - ) - } - } - - private suspend fun requiresHardenedDerivationOnly(networkId: String, userWalletId: UserWalletId): Boolean { - return requiresHardenedDerivationOnlyUseCase.invoke( - networkId = networkId, - userWalletId = userWalletId, - ).getOrElse { false } - } - - override fun onCustomDerivationSelected() { - uiState = stateFactory.updateOnCustomDerivationSelected() - router.popBackStack() - } - - override fun onEnterCustomDerivation() { - uiState = stateFactory.updateStateOnEnterCustomDerivation() - } - - override fun onCustomDerivationDialogDismissed() { - uiState = uiState.copy( - chooseDerivationState = uiState.chooseDerivationState?.copy( - enterCustomDerivationState = null, - ), - ) - } - - override fun onAddCustomButtonClick() { - viewModelScope.launch(dispatchers.io) { - val selectedWallet = getSelectedWalletSyncUseCase().getOrNull() ?: return@launch - val cryptoCurrency = AddCustomTokenStateToCryptoCurrencyConverter( - selectedWallet.scanResponse.derivationStyleProvider, - ).convert(uiState) - val alreadyAdded = isCryptoCurrencyAlreadyAdded(selectedWallet, cryptoCurrency) - if (alreadyAdded) { - uiState = stateFactory.getStateAndTriggerEvent( - state = uiState, - event = Event.ShowAlert(AlertState.TokenAlreadyAdded), - setUiState = { uiState = it }, - ) - } else { - sendTokenAddedEvent(cryptoCurrency) - addCryptoCurrenciesUseCase(selectedWallet.walletId, currency = cryptoCurrency) - withContext(dispatchers.main) { router.popBackStack() } - } - } - } - - private suspend fun isCryptoCurrencyAlreadyAdded( - selectedWallet: UserWallet, - cryptoCurrency: CryptoCurrency, - ): Boolean { - val currenciesList = getCurrenciesUseCase.getSync(selectedWallet.walletId).getOrElse { emptyList() } - return when (cryptoCurrency) { - is CryptoCurrency.Coin -> { - currenciesList.any { - it is CryptoCurrency.Coin && - it.id == cryptoCurrency.id && - it.network.derivationPath == cryptoCurrency.network.derivationPath - } - } - is CryptoCurrency.Token -> { - currenciesList.any { - (it as? CryptoCurrency.Token)?.let { - it.id == cryptoCurrency.id && - it.contractAddress == cryptoCurrency.contractAddress && - it.network.id == cryptoCurrency.network.id && - it.network.derivationPath == cryptoCurrency.network.derivationPath - } ?: false - } - } - } - } - - private fun sendTokenAddedEvent(cryptoCurrency: CryptoCurrency) { - val selectedDerivation = uiState.chooseDerivationState?.selectedDerivation - - val derivation = when { - selectedDerivation == null -> ManageTokens.Derivation.DEFAULT.value - selectedDerivation.networkName.isNotEmpty() -> selectedDerivation.networkName - else -> ManageTokens.Derivation.CUSTOM.value - } - when (cryptoCurrency) { - is CryptoCurrency.Token -> { - analyticsEventHandler.send( - ManageTokens.CustomTokenWasAdded( - derivation = derivation, - networkId = cryptoCurrency.network.name, - contractAddress = cryptoCurrency.contractAddress, - token = cryptoCurrency.symbol, - ), - ) - } - is CryptoCurrency.Coin -> { - analyticsEventHandler.send( - ManageTokens.CustomTokenWasAdded( - derivation = derivation, - networkId = cryptoCurrency.network.name, - ), - ) - } - } - } - - override fun onBack() { - router.popBackStack() - } -} \ No newline at end of file diff --git a/features/manage-tokens/impl/src/main/java/com/tangem/managetokens/presentation/common/analytics/ManageTokens.kt b/features/manage-tokens/impl/src/main/java/com/tangem/managetokens/presentation/common/analytics/ManageTokens.kt deleted file mode 100644 index 3a527de7f2..0000000000 --- a/features/manage-tokens/impl/src/main/java/com/tangem/managetokens/presentation/common/analytics/ManageTokens.kt +++ /dev/null @@ -1,102 +0,0 @@ -package com.tangem.managetokens.presentation.common.analytics - -import com.tangem.core.analytics.models.AnalyticsEvent -import com.tangem.core.analytics.models.AnalyticsParam - -sealed class ManageTokens( - event: String, - params: Map = emptyMap(), -) : AnalyticsEvent("Manage Tokens", event, params) { - - class ScreenOpened : ManageTokens("Manage Tokens Screen Opened") - - class TokenIsNotFound(userInput: String) : ManageTokens( - event = "Token Is Not Found", - params = mapOf("Input" to userInput), - ) - - class TokenSwitcherChanged( - token: String, - state: AnalyticsParam.OnOffState, - ) : ManageTokens( - event = "Token Switcher Changed", - params = mapOf( - "Token" to token, - "State" to state.value, - ), - ) - - class ButtonAdd(token: String) : ManageTokens( - event = "Button - Add", - params = mapOf("Token" to token), - ) - - class ButtonEdit(token: String) : ManageTokens( - event = "Button - Edit", - params = mapOf("Token" to token), - ) - - object ButtonChooseWallet : ManageTokens(event = "Button - Choose Wallet") - - class WalletSelected(source: Source) : ManageTokens( - event = "Wallet Selected", - params = mapOf("Source" to source.name), - ) { - - enum class Source(name: String) { - MainToken("Main Token"), - CustomToken("Custom Token"), - } - } - - object NoticeNonNativeNetworkClicked : ManageTokens(event = "Notice - Non Native Network Clicked") - - class ButtonGenerateAddresses(cardCount: Int) : ManageTokens( - event = "Button - Get Addresses", - params = mapOf("CardCount" to cardCount.toString()), - ) - - object ButtonCustomToken : ManageTokens("Button - Custom Token") - - class CustomTokenWasAdded( - val derivation: String, - val networkId: String, - val token: String? = null, - val contractAddress: String? = null, - ) : ManageTokens( - event = "Custom Token Was Added", - params = mutableMapOf( - "Derivation" to derivation, - "Network Id" to networkId, - ).apply { - token?.let { put("Token", it) } - contractAddress?.let { put("Contract Address", it) } - }, - ) - - class CustomTokenNetworkSelected(blockchain: String) : ManageTokens( - event = "Custom Token Network Selected", - params = mapOf("blockchain" to blockchain), - ) - - class CustomTokenDerivationSelected(derivation: String) : ManageTokens( - event = "Custom Token Derivation Selected", - params = mapOf("Derivation" to derivation), - ) - - class CustomTokenAddress(validated: Boolean) : ManageTokens( - "Custom Token Address", - params = mapOf("Validation" to if (validated) "Ok" else "Error"), - ) - - object CustomTokenName : ManageTokens("Custom Token Name") - - object CustomTokenSymbol : ManageTokens("Custom Token Symbol") - - object CustomTokenDecimals : ManageTokens("Custom Token Decimals") - - enum class Derivation(val value: String) { - DEFAULT("Default"), - CUSTOM("Custom"), - } -} \ No newline at end of file diff --git a/features/manage-tokens/impl/src/main/java/com/tangem/managetokens/presentation/common/state/AlertState.kt b/features/manage-tokens/impl/src/main/java/com/tangem/managetokens/presentation/common/state/AlertState.kt deleted file mode 100644 index 82ba359079..0000000000 --- a/features/manage-tokens/impl/src/main/java/com/tangem/managetokens/presentation/common/state/AlertState.kt +++ /dev/null @@ -1,56 +0,0 @@ -package com.tangem.managetokens.presentation.common.state - -import com.tangem.core.ui.extensions.TextReference -import com.tangem.core.ui.extensions.resourceReference -import com.tangem.core.ui.extensions.wrappedList -import com.tangem.features.managetokens.impl.R - -internal sealed class AlertState { - - abstract val message: TextReference - - class DefaultAlert( - override val message: TextReference, - ) : AlertState() - - class TokenUnavailable( - val onUpvoteClick: () -> Unit, - ) : AlertState() { - override val message: TextReference = resourceReference(R.string.manage_tokens_unavailable_description) - val confirmButtonText: TextReference = resourceReference(R.string.common_close) - val dismissButtonText: TextReference = resourceReference(R.string.manage_tokens_unavailable_vote) - } - - object NonNative : AlertState() { - override val message: TextReference = resourceReference(R.string.manage_tokens_network_selector_non_native_info) - } - - class TokensUnsupported(networkName: String) : AlertState() { - override val message: TextReference = resourceReference( - id = R.string.alert_manage_tokens_unsupported_message, - formatArgs = wrappedList(networkName), - ) - } - - object TokensUnsupportedCurve : AlertState() { - override val message: TextReference = resourceReference(R.string.alert_manage_tokens_unsupported_curve_message) - } - - class TokensUnsupportedBlockchainByCard(networkName: String) : AlertState() { - override val message: TextReference = resourceReference( - id = R.string.alert_manage_tokens_unsupported_blockchain_by_card_message, - formatArgs = wrappedList(networkName), - ) - } - - class CannotHideNetworkWithTokens(tokenName: String, currencySymbol: String, networkName: String) : AlertState() { - override val message: TextReference = resourceReference( - id = R.string.token_details_unable_hide_alert_message, - formatArgs = wrappedList(tokenName, currencySymbol, networkName), - ) - } - - object TokenAlreadyAdded : AlertState() { - override val message: TextReference = resourceReference(R.string.custom_token_validation_error_already_added) - } -} \ No newline at end of file diff --git a/features/manage-tokens/impl/src/main/java/com/tangem/managetokens/presentation/common/state/ChooseWalletState.kt b/features/manage-tokens/impl/src/main/java/com/tangem/managetokens/presentation/common/state/ChooseWalletState.kt deleted file mode 100644 index 6a585d7148..0000000000 --- a/features/manage-tokens/impl/src/main/java/com/tangem/managetokens/presentation/common/state/ChooseWalletState.kt +++ /dev/null @@ -1,29 +0,0 @@ -package com.tangem.managetokens.presentation.common.state - -import com.tangem.core.ui.extensions.TextReference -import com.tangem.features.managetokens.impl.R -import kotlinx.collections.immutable.ImmutableList - -internal sealed class ChooseWalletState { - data class Choose( - val wallets: ImmutableList, - val selectedWallet: WalletState?, - val onChooseWalletClick: () -> Unit, - val onCloseChoosingWalletClick: () -> Unit, - val show: Boolean = false, - ) : ChooseWalletState() - - object NoSelection : ChooseWalletState() - - class Warning(val type: ChooseWalletWarning) : ChooseWalletState() { - val message: TextReference - get() = when (type) { - ChooseWalletWarning.SINGLE_CURRENCY -> - TextReference.Res(R.string.manage_tokens_wallet_support_only_one_network_title) - } - } -} - -enum class ChooseWalletWarning { - SINGLE_CURRENCY, -} \ No newline at end of file diff --git a/features/manage-tokens/impl/src/main/java/com/tangem/managetokens/presentation/common/state/Event.kt b/features/manage-tokens/impl/src/main/java/com/tangem/managetokens/presentation/common/state/Event.kt deleted file mode 100644 index 4024d7a4d8..0000000000 --- a/features/manage-tokens/impl/src/main/java/com/tangem/managetokens/presentation/common/state/Event.kt +++ /dev/null @@ -1,8 +0,0 @@ -package com.tangem.managetokens.presentation.common.state - -import androidx.compose.runtime.Immutable - -@Immutable -internal sealed interface Event { - data class ShowAlert(val state: AlertState) : Event -} \ No newline at end of file diff --git a/features/manage-tokens/impl/src/main/java/com/tangem/managetokens/presentation/common/state/NetworkItemState.kt b/features/manage-tokens/impl/src/main/java/com/tangem/managetokens/presentation/common/state/NetworkItemState.kt deleted file mode 100644 index 6255c750f9..0000000000 --- a/features/manage-tokens/impl/src/main/java/com/tangem/managetokens/presentation/common/state/NetworkItemState.kt +++ /dev/null @@ -1,82 +0,0 @@ -package com.tangem.managetokens.presentation.common.state - -import androidx.compose.runtime.MutableState -import com.tangem.core.ui.extensions.* -import com.tangem.managetokens.presentation.managetokens.state.TokenItemState - -/** - * Network item state - * - * @property name network name - * @property protocolName network protocol name - * @property id network id - * @property iconRes network icon id from resources - */ -internal sealed interface NetworkItemState { - - val name: String - val protocolName: String - val id: String - - val iconRes: Int - get() = when (this) { - is Selectable -> this.iconResId - is Toggleable -> this.iconResId.value - } - - /** - * Network item state that can be added and deleted - * - * @property name network name - * @property protocolName network protocol name - * @property id network id - * @property iconResId network icon id from resources - * @property isMainNetwork flag that determines if the network is the main network for the token - * @property isAdded flag that determines if the user has saved the network - * @property address contract address - * @property decimals decimal count - * @property onToggleClick lambda be invoked when switch is been toggled - */ - @Suppress("LongParameterList") - data class Toggleable( - override val name: String, - override val protocolName: String, - override val id: String, - val iconResId: MutableState, - val isMainNetwork: Boolean, - val isAdded: MutableState, - val address: String?, - val decimals: Int?, - val onToggleClick: (TokenItemState.Loaded, Toggleable) -> Unit, - ) : NetworkItemState { - - /** - * Change toggle state [isAdded]. - * - * It is a hack that helps us to change element of flow - */ - fun changeToggleState() { - val reverseState = !isAdded.value - isAdded.value = reverseState - iconResId.value = if (reverseState) getActiveIconResByNetworkId(id) else getGreyedOutIconResByNetworkId(id) - } - } - - /** - * Network item state that can be selected - * - * @property name network name - * @property protocolName network protocol name - * @property iconResId network icon id from resources - * @property id network id - * @property onNetworkClick lambda be invoked when network item is been clicked - * - */ - data class Selectable( - override val name: String, - override val protocolName: String, - val iconResId: Int, - override val id: String, - val onNetworkClick: (NetworkItemState) -> Unit, - ) : NetworkItemState -} \ No newline at end of file diff --git a/features/manage-tokens/impl/src/main/java/com/tangem/managetokens/presentation/common/state/WalletState.kt b/features/manage-tokens/impl/src/main/java/com/tangem/managetokens/presentation/common/state/WalletState.kt deleted file mode 100644 index 6af48736a4..0000000000 --- a/features/manage-tokens/impl/src/main/java/com/tangem/managetokens/presentation/common/state/WalletState.kt +++ /dev/null @@ -1,8 +0,0 @@ -package com.tangem.managetokens.presentation.common.state - -internal data class WalletState( - val walletId: String, - val artworkUrl: String?, - val walletName: String, - val onSelected: (String) -> Unit, -) \ No newline at end of file diff --git a/features/manage-tokens/impl/src/main/java/com/tangem/managetokens/presentation/common/state/previewdata/ChooseWalletStatePreviewData.kt b/features/manage-tokens/impl/src/main/java/com/tangem/managetokens/presentation/common/state/previewdata/ChooseWalletStatePreviewData.kt deleted file mode 100644 index f231654b96..0000000000 --- a/features/manage-tokens/impl/src/main/java/com/tangem/managetokens/presentation/common/state/previewdata/ChooseWalletStatePreviewData.kt +++ /dev/null @@ -1,27 +0,0 @@ -package com.tangem.managetokens.presentation.common.state.previewdata - -import com.tangem.managetokens.presentation.common.state.ChooseWalletState -import com.tangem.managetokens.presentation.common.state.WalletState -import kotlinx.collections.immutable.persistentListOf - -internal object ChooseWalletStatePreviewData { - - val state: ChooseWalletState.Choose - get() = ChooseWalletState.Choose( - wallets = persistentListOf( - walletState, - walletState.copy(walletId = "2"), - ), - selectedWallet = walletState, - onChooseWalletClick = {}, - onCloseChoosingWalletClick = {}, - ) - - private val walletState: WalletState - get() = WalletState( - walletName = "My wallet", - walletId = "1", - artworkUrl = "", - onSelected = {}, - ) -} \ No newline at end of file diff --git a/features/manage-tokens/impl/src/main/java/com/tangem/managetokens/presentation/common/ui/ChooseWalletBottomSheet.kt b/features/manage-tokens/impl/src/main/java/com/tangem/managetokens/presentation/common/ui/ChooseWalletBottomSheet.kt deleted file mode 100644 index 9bf85280d4..0000000000 --- a/features/manage-tokens/impl/src/main/java/com/tangem/managetokens/presentation/common/ui/ChooseWalletBottomSheet.kt +++ /dev/null @@ -1,22 +0,0 @@ -package com.tangem.managetokens.presentation.common.ui - -import androidx.compose.runtime.Composable -import com.tangem.core.ui.components.bottomsheets.TangemBottomSheet -import com.tangem.core.ui.components.bottomsheets.TangemBottomSheetConfig -import com.tangem.core.ui.components.bottomsheets.TangemBottomSheetConfigContent -import com.tangem.core.ui.res.TangemTheme -import com.tangem.managetokens.presentation.common.state.ChooseWalletState - -@Composable -internal fun ChooseWalletBottomSheet(config: TangemBottomSheetConfig) { - TangemBottomSheet( - config = config, - containerColor = TangemTheme.colors.background.tertiary, - ) { - ChooseWalletScreen(state = it.chooseWalletState) - } -} - -internal class ChooseWalletBottomSheetConfig( - val chooseWalletState: ChooseWalletState.Choose, -) : TangemBottomSheetConfigContent \ No newline at end of file diff --git a/features/manage-tokens/impl/src/main/java/com/tangem/managetokens/presentation/common/ui/ChooseWalletScreen.kt b/features/manage-tokens/impl/src/main/java/com/tangem/managetokens/presentation/common/ui/ChooseWalletScreen.kt deleted file mode 100644 index 121faaba26..0000000000 --- a/features/manage-tokens/impl/src/main/java/com/tangem/managetokens/presentation/common/ui/ChooseWalletScreen.kt +++ /dev/null @@ -1,150 +0,0 @@ -package com.tangem.managetokens.presentation.common.ui - -import android.content.res.Configuration -import androidx.compose.foundation.Image -import androidx.compose.foundation.background -import androidx.compose.foundation.clickable -import androidx.compose.foundation.layout.* -import androidx.compose.foundation.lazy.LazyColumn -import androidx.compose.material.Icon -import androidx.compose.material.IconButton -import androidx.compose.material3.Text -import androidx.compose.runtime.Composable -import androidx.compose.ui.Alignment -import androidx.compose.ui.Modifier -import androidx.compose.ui.platform.LocalContext -import androidx.compose.ui.res.painterResource -import androidx.compose.ui.res.stringResource -import androidx.compose.ui.text.style.TextAlign -import androidx.compose.ui.tooling.preview.Preview -import coil.compose.SubcomposeAsyncImage -import coil.request.ImageRequest -import com.tangem.core.ui.components.SpacerH -import com.tangem.core.ui.components.SpacerW12 -import com.tangem.core.ui.components.SpacerWMax -import com.tangem.core.ui.decorations.roundedShapeItemDecoration -import com.tangem.core.ui.res.TangemTheme -import com.tangem.core.ui.res.TangemThemePreview -import com.tangem.features.managetokens.impl.R -import com.tangem.managetokens.presentation.common.state.ChooseWalletState -import com.tangem.managetokens.presentation.common.state.WalletState -import com.tangem.managetokens.presentation.common.state.previewdata.ChooseWalletStatePreviewData - -@Composable -internal fun ChooseWalletScreen(state: ChooseWalletState.Choose, modifier: Modifier = Modifier) { - LazyColumn( - modifier = modifier - .background(TangemTheme.colors.background.tertiary) - .padding( - start = TangemTheme.dimens.spacing16, - end = TangemTheme.dimens.spacing16, - bottom = TangemTheme.dimens.spacing16, - ), - ) { - item { - Box( - modifier = Modifier.defaultMinSize(minHeight = TangemTheme.dimens.size44), - ) { - IconButton( - onClick = state.onCloseChoosingWalletClick, - modifier = Modifier - .align(Alignment.CenterStart) - .clickable { state.onCloseChoosingWalletClick() }, - ) { - Icon( - painterResource(id = R.drawable.ic_back_24), - contentDescription = null, - tint = TangemTheme.colors.icon.primary1, - ) - } - Text( - text = stringResource(id = R.string.manage_tokens_wallet_selector_title), - color = TangemTheme.colors.text.primary1, - style = TangemTheme.typography.subtitle1, - textAlign = TextAlign.Center, - maxLines = 1, - modifier = Modifier - .fillMaxWidth() - .align(Alignment.Center), - ) - } - } - items( - count = state.wallets.count(), - key = { index -> state.wallets[index].walletId }, - ) { index -> - WalletItem( - wallet = state.wallets[index], - selectedWallet = state.selectedWallet, - modifier = Modifier - .roundedShapeItemDecoration( - currentIndex = index, - lastIndex = state.wallets.lastIndex, - addDefaultPadding = false, - ), - ) - } - item { - SpacerH(height = TangemTheme.dimens.spacing16) - } - } -} - -@Composable -private fun WalletItem(wallet: WalletState, selectedWallet: WalletState?, modifier: Modifier = Modifier) { - Row( - modifier = modifier - .clickable { wallet.onSelected(wallet.walletId) } - .background(TangemTheme.colors.background.action) - .defaultMinSize(minHeight = TangemTheme.dimens.size72) - .padding(horizontal = TangemTheme.dimens.spacing16), - verticalAlignment = Alignment.CenterVertically, - ) { - SubcomposeAsyncImage( - modifier = Modifier.size(height = TangemTheme.dimens.size30, width = TangemTheme.dimens.size50), - - model = ImageRequest.Builder(context = LocalContext.current) - .data(wallet.artworkUrl) - .crossfade(enable = true) - .build(), - loading = { - Image( - painter = painterResource(R.drawable.card_placeholder_black), - contentDescription = null, - ) - }, - error = { - Image( - painter = painterResource(R.drawable.card_placeholder_black), - contentDescription = null, - ) - }, - contentDescription = null, - ) - SpacerW12() - Text( - text = wallet.walletName, - style = TangemTheme.typography.subtitle1, - color = TangemTheme.colors.text.primary1, - ) - SpacerWMax() - if (selectedWallet == wallet) { - Icon( - painter = painterResource(id = R.drawable.ic_check_24), - contentDescription = null, - tint = TangemTheme.colors.icon.accent, - ) - } - } -} - -@Preview -@Preview(uiMode = Configuration.UI_MODE_NIGHT_YES) -@Composable -private fun Preview_ChooseWalletScreen() { - TangemThemePreview { - ChooseWalletScreen( - state = ChooseWalletStatePreviewData.state, - ) - } -} \ No newline at end of file diff --git a/features/manage-tokens/impl/src/main/java/com/tangem/managetokens/presentation/common/ui/EventEffect.kt b/features/manage-tokens/impl/src/main/java/com/tangem/managetokens/presentation/common/ui/EventEffect.kt deleted file mode 100644 index 0bfc404f35..0000000000 --- a/features/manage-tokens/impl/src/main/java/com/tangem/managetokens/presentation/common/ui/EventEffect.kt +++ /dev/null @@ -1,18 +0,0 @@ -package com.tangem.managetokens.presentation.common.ui - -import androidx.compose.runtime.Composable -import com.tangem.core.ui.event.StateEvent -import com.tangem.managetokens.presentation.common.state.AlertState -import com.tangem.managetokens.presentation.common.state.Event - -@Composable -internal fun EventEffect(event: StateEvent, onAlertStateSet: (AlertState) -> Unit) { - com.tangem.core.ui.event.EventEffect( - event = event, - onTrigger = { value -> - when (value) { - is Event.ShowAlert -> onAlertStateSet(value.state) - } - }, - ) -} \ No newline at end of file diff --git a/features/manage-tokens/impl/src/main/java/com/tangem/managetokens/presentation/common/ui/components/Alert.kt b/features/manage-tokens/impl/src/main/java/com/tangem/managetokens/presentation/common/ui/components/Alert.kt deleted file mode 100644 index 14e49a02b6..0000000000 --- a/features/manage-tokens/impl/src/main/java/com/tangem/managetokens/presentation/common/ui/components/Alert.kt +++ /dev/null @@ -1,52 +0,0 @@ -package com.tangem.managetokens.presentation.common.ui.components - -import androidx.compose.runtime.Composable -import androidx.compose.ui.res.stringResource -import com.tangem.core.ui.components.BasicDialog -import com.tangem.core.ui.components.DialogButton -import com.tangem.core.ui.extensions.resolveReference -import com.tangem.features.managetokens.impl.R -import com.tangem.managetokens.presentation.common.state.AlertState - -@Composable -internal fun Alert(state: AlertState, onDismiss: () -> Unit) { - when (state) { - is AlertState.DefaultAlert, - is AlertState.NonNative, - AlertState.TokensUnsupportedCurve, - is AlertState.TokensUnsupported, - is AlertState.TokensUnsupportedBlockchainByCard, - is AlertState.CannotHideNetworkWithTokens, - is AlertState.TokenAlreadyAdded, - -> DefaultAlert(state, onDismiss) - is AlertState.TokenUnavailable -> TokenUnavailableAlert(state, onDismiss) - } -} - -@Composable -private fun DefaultAlert(state: AlertState, onDismiss: () -> Unit) { - BasicDialog( - message = state.message.resolveReference(), - confirmButton = DialogButton( - title = stringResource(id = R.string.common_ok), - onClick = onDismiss, - ), - onDismissDialog = onDismiss, - ) -} - -@Composable -private fun TokenUnavailableAlert(state: AlertState.TokenUnavailable, onDismiss: () -> Unit) { - BasicDialog( - message = state.message.resolveReference(), - confirmButton = DialogButton( - title = state.confirmButtonText.resolveReference(), - onClick = onDismiss, - ), - dismissButton = DialogButton( - title = state.dismissButtonText.resolveReference(), - onClick = { state.onUpvoteClick() }, - ), - onDismissDialog = onDismiss, - ) -} \ No newline at end of file diff --git a/features/manage-tokens/impl/src/main/java/com/tangem/managetokens/presentation/common/ui/components/NetworkItem.kt b/features/manage-tokens/impl/src/main/java/com/tangem/managetokens/presentation/common/ui/components/NetworkItem.kt deleted file mode 100644 index 553a6bd999..0000000000 --- a/features/manage-tokens/impl/src/main/java/com/tangem/managetokens/presentation/common/ui/components/NetworkItem.kt +++ /dev/null @@ -1,167 +0,0 @@ -package com.tangem.managetokens.presentation.common.ui.components - -import android.content.res.Configuration -import androidx.compose.foundation.background -import androidx.compose.foundation.clickable -import androidx.compose.foundation.layout.* -import androidx.compose.foundation.shape.CircleShape -import androidx.compose.material.Icon -import androidx.compose.material3.Text -import androidx.compose.runtime.Composable -import androidx.compose.runtime.mutableStateOf -import androidx.compose.ui.Alignment -import androidx.compose.ui.Modifier -import androidx.compose.ui.draw.clip -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.components.SpacerW -import com.tangem.core.ui.components.TangemSwitch -import com.tangem.core.ui.res.TangemThemePreview -import com.tangem.core.ui.res.TangemTheme -import com.tangem.features.managetokens.impl.R -import com.tangem.managetokens.presentation.common.state.NetworkItemState -import com.tangem.managetokens.presentation.managetokens.state.TokenItemState -import com.tangem.managetokens.presentation.managetokens.state.previewdata.TokenItemStatePreviewData - -@Composable -internal fun NetworkItem( - state: NetworkItemState, - tokenState: TokenItemState.Loaded?, - modifier: Modifier = Modifier, - isSelected: Boolean = false, -) { - Row( - modifier = modifier - .background(TangemTheme.colors.background.action) - .defaultMinSize(minHeight = TangemTheme.dimens.size68) - .then( - if (state is NetworkItemState.Selectable) { - Modifier.clickable { state.onNetworkClick(state) } - } else { - Modifier - }, - ) - .padding(horizontal = TangemTheme.dimens.spacing16) - .fillMaxWidth(), - verticalAlignment = Alignment.CenterVertically, - ) { - NetworkIcon(model = state) - SpacerW(width = TangemTheme.dimens.spacing12) - Text( - text = state.name, - color = TangemTheme.colors.text.primary1, - style = TangemTheme.typography.subtitle2, - ) - SpacerW(width = TangemTheme.dimens.spacing6) - Text( - text = state.protocolName, - color = TangemTheme.colors.text.tertiary, - style = TangemTheme.typography.body2, - modifier = Modifier - .weight(1f), - ) - if (state is NetworkItemState.Toggleable) { - TangemSwitch( - onCheckedChange = { - state.onToggleClick(tokenState!!, state) - }, - checked = state.isAdded.value, - ) - } else if (state is NetworkItemState.Selectable && isSelected) { - Icon( - painter = painterResource(id = R.drawable.ic_check_24), - contentDescription = null, - tint = TangemTheme.colors.icon.accent, - ) - } - } -} - -@Composable -internal fun NetworkIcon(model: NetworkItemState, modifier: Modifier = Modifier) { - Box(modifier = modifier.size(size = TangemTheme.dimens.size36)) { - val isAdded = when (model) { - is NetworkItemState.Selectable -> true - is NetworkItemState.Toggleable -> model.isAdded.value - } - - if (!isAdded) { - Box( - modifier = Modifier - .size(TangemTheme.dimens.size36) - .clip(CircleShape) - .background(TangemTheme.colors.control.unchecked), - ) - } - Icon( - painter = painterResource(id = model.iconRes), - contentDescription = null, - modifier = Modifier.size(size = TangemTheme.dimens.size36), - tint = if (isAdded) Color.Unspecified else TangemTheme.colors.text.tertiary, - ) - - if (model is NetworkItemState.Toggleable && model.isMainNetwork) { - Box( - modifier = Modifier - .align(Alignment.TopEnd) - .size(TangemTheme.dimens.size10) - .clip(CircleShape) - .background(TangemTheme.colors.stroke.transparency), - contentAlignment = Alignment.Center, - ) { - Box( - modifier = Modifier - .size(TangemTheme.dimens.size8) - .clip(CircleShape) - .background(TangemTheme.colors.icon.accent), - ) - } - } - } -} - -@Preview -@Preview(uiMode = Configuration.UI_MODE_NIGHT_YES) -@Composable -private fun Preview_NetworkItem(@PreviewParameter(NetworkItemStateProvider::class) state: NetworkItemState) { - TangemThemePreview { - NetworkItem(state, tokenState = TokenItemStatePreviewData.loadedPriceDown as TokenItemState.Loaded) - } -} - -private class NetworkItemStateProvider : CollectionPreviewParameterProvider( - collection = listOf( - NetworkItemState.Toggleable( - name = "Ethereum", - protocolName = "ETH", - iconResId = mutableStateOf(R.drawable.img_polygon_22), - isMainNetwork = true, - isAdded = mutableStateOf(true), - id = "", - address = "", - onToggleClick = { _, _ -> }, - decimals = 0, - ), - NetworkItemState.Toggleable( - name = "BNB SMART CHAIN", - protocolName = "BEP20", - iconResId = mutableStateOf(R.drawable.ic_bsc_16), - isMainNetwork = false, - isAdded = mutableStateOf(false), - id = "", - address = "", - onToggleClick = { _, _ -> }, - decimals = 0, - ), - NetworkItemState.Selectable( - name = "Ethereum", - protocolName = "ETH", - iconResId = R.drawable.img_polygon_22, - id = "", - onNetworkClick = { }, - ), - ), -) \ No newline at end of file diff --git a/features/manage-tokens/impl/src/main/java/com/tangem/managetokens/presentation/common/ui/components/SimpleSelectionBlock.kt b/features/manage-tokens/impl/src/main/java/com/tangem/managetokens/presentation/common/ui/components/SimpleSelectionBlock.kt deleted file mode 100644 index e7ad5cf31b..0000000000 --- a/features/manage-tokens/impl/src/main/java/com/tangem/managetokens/presentation/common/ui/components/SimpleSelectionBlock.kt +++ /dev/null @@ -1,65 +0,0 @@ -package com.tangem.managetokens.presentation.common.ui.components - -import android.content.res.Configuration -import androidx.compose.foundation.background -import androidx.compose.foundation.clickable -import androidx.compose.foundation.layout.Column -import androidx.compose.foundation.layout.fillMaxWidth -import androidx.compose.foundation.layout.padding -import androidx.compose.foundation.shape.RoundedCornerShape -import androidx.compose.material3.Text -import androidx.compose.runtime.Composable -import androidx.compose.ui.Modifier -import androidx.compose.ui.draw.clip -import androidx.compose.ui.tooling.preview.Preview -import com.tangem.core.ui.components.SpacerH -import com.tangem.core.ui.res.TangemThemePreview -import com.tangem.core.ui.res.TangemTheme - -@Composable -fun SimpleSelectionBlock( - title: String, - subtitle: String, - onClick: () -> Unit, - modifier: Modifier = Modifier, - roundedCorners: Boolean = true, -) { - Column( - modifier = modifier - .then( - if (roundedCorners) { - Modifier.clip(shape = RoundedCornerShape(TangemTheme.dimens.radius16)) - } else { - Modifier - }, - ) - .background(color = TangemTheme.colors.background.action) - .clickable { onClick() } - .padding( - horizontal = TangemTheme.dimens.spacing20, - vertical = TangemTheme.dimens.spacing16, - ) - .fillMaxWidth(), - ) { - Text( - text = title, - color = TangemTheme.colors.text.primary1, - style = TangemTheme.typography.subtitle1, - ) - SpacerH(height = TangemTheme.dimens.spacing4) - Text( - text = subtitle, - color = TangemTheme.colors.text.secondary, - style = TangemTheme.typography.body2, - ) - } -} - -@Preview -@Preview(uiMode = Configuration.UI_MODE_NIGHT_YES) -@Composable -private fun Preview_SimpleSelectionBlock() { - TangemThemePreview { - SimpleSelectionBlock(title = "Wallet", subtitle = "Family Wallet", onClick = { }) - } -} \ No newline at end of file diff --git a/features/manage-tokens/impl/src/main/java/com/tangem/managetokens/presentation/common/utils/CurrencyUtils.kt b/features/manage-tokens/impl/src/main/java/com/tangem/managetokens/presentation/common/utils/CurrencyUtils.kt deleted file mode 100644 index b005f36dee..0000000000 --- a/features/manage-tokens/impl/src/main/java/com/tangem/managetokens/presentation/common/utils/CurrencyUtils.kt +++ /dev/null @@ -1,18 +0,0 @@ -package com.tangem.managetokens.presentation.common.utils - -import com.tangem.domain.tokens.model.CryptoCurrency - -internal object CurrencyUtils { - fun isAdded(address: String?, networkId: String, currencies: Collection): Boolean { - return if (address != null) { - currencies.any { - !it.isCustom && it is CryptoCurrency.Token && it.contractAddress == address && - it.network.backendId == networkId - } - } else { - currencies.any { - !it.isCustom && it is CryptoCurrency.Coin && it.network.backendId == networkId - } - } - } -} \ No newline at end of file diff --git a/features/manage-tokens/impl/src/main/java/com/tangem/managetokens/presentation/managetokens/state/ChooseNetworkState.kt b/features/manage-tokens/impl/src/main/java/com/tangem/managetokens/presentation/managetokens/state/ChooseNetworkState.kt deleted file mode 100644 index df2a7f015f..0000000000 --- a/features/manage-tokens/impl/src/main/java/com/tangem/managetokens/presentation/managetokens/state/ChooseNetworkState.kt +++ /dev/null @@ -1,11 +0,0 @@ -package com.tangem.managetokens.presentation.managetokens.state - -import com.tangem.managetokens.presentation.common.state.NetworkItemState -import kotlinx.collections.immutable.ImmutableList - -internal data class ChooseNetworkState( - val nativeNetworks: ImmutableList, - val nonNativeNetworks: ImmutableList, - val onNonNativeNetworkHintClick: () -> Unit, - val onCloseChooseNetworkScreen: () -> Unit, -) \ No newline at end of file diff --git a/features/manage-tokens/impl/src/main/java/com/tangem/managetokens/presentation/managetokens/state/DerivationNotificationState.kt b/features/manage-tokens/impl/src/main/java/com/tangem/managetokens/presentation/managetokens/state/DerivationNotificationState.kt deleted file mode 100644 index 0cfdfa16d1..0000000000 --- a/features/manage-tokens/impl/src/main/java/com/tangem/managetokens/presentation/managetokens/state/DerivationNotificationState.kt +++ /dev/null @@ -1,34 +0,0 @@ -package com.tangem.managetokens.presentation.managetokens.state - -import com.tangem.core.ui.components.notifications.NotificationConfig -import com.tangem.core.ui.extensions.pluralReference -import com.tangem.core.ui.extensions.resourceReference -import com.tangem.core.ui.extensions.wrappedList -import com.tangem.features.managetokens.impl.R - -data class DerivationNotificationState( - val totalNeeded: Int, - val totalWallets: Int, - val walletsToDerive: Int, - val onGenerateClick: () -> Unit, -) { - val config = NotificationConfig( - title = resourceReference(id = R.string.warning_missing_derivation_title), - subtitle = pluralReference( - id = R.plurals.warning_missing_derivation_message, - count = totalNeeded, - formatArgs = wrappedList(totalNeeded), - ), - iconResId = R.drawable.ic_alert_circle_24, - buttonsState = NotificationConfig.ButtonsState.PrimaryButtonConfig( - text = resourceReference(id = R.string.common_generate_addresses), - iconResId = R.drawable.ic_tangem_24, - onClick = onGenerateClick, - additionalText = pluralReference( - id = R.plurals.manage_tokens_number_of_wallets_android, - count = totalWallets, - formatArgs = wrappedList(walletsToDerive, totalWallets), - ), - ), - ) -} \ No newline at end of file diff --git a/features/manage-tokens/impl/src/main/java/com/tangem/managetokens/presentation/managetokens/state/ManageTokensState.kt b/features/manage-tokens/impl/src/main/java/com/tangem/managetokens/presentation/managetokens/state/ManageTokensState.kt deleted file mode 100644 index 6738d56d3f..0000000000 --- a/features/manage-tokens/impl/src/main/java/com/tangem/managetokens/presentation/managetokens/state/ManageTokensState.kt +++ /dev/null @@ -1,27 +0,0 @@ -package com.tangem.managetokens.presentation.managetokens.state - -import androidx.paging.PagingData -import com.tangem.core.ui.components.bottomsheets.TangemBottomSheetConfig -import com.tangem.core.ui.event.StateEvent -import com.tangem.managetokens.presentation.common.state.ChooseWalletState -import com.tangem.managetokens.presentation.common.state.Event -import kotlinx.coroutines.flow.Flow - -internal data class ManageTokensState( - val searchBarState: SearchBarState, - val tokens: Flow>, - val isLoading: Boolean, - val addCustomTokenButton: AddCustomTokenButton, - val chooseWalletState: ChooseWalletState, - val derivationNotification: DerivationNotificationState? = null, - val selectedToken: TokenItemState.Loaded? = null, - val showChooseWalletScreen: Boolean = false, - val customTokenBottomSheetConfig: TangemBottomSheetConfig, - val event: StateEvent, - val onEmptySearchResult: (String) -> Unit, -) - -data class AddCustomTokenButton( - val isVisible: Boolean, - val onClick: () -> Unit, -) \ No newline at end of file diff --git a/features/manage-tokens/impl/src/main/java/com/tangem/managetokens/presentation/managetokens/state/QuotesState.kt b/features/manage-tokens/impl/src/main/java/com/tangem/managetokens/presentation/managetokens/state/QuotesState.kt deleted file mode 100644 index 3518626707..0000000000 --- a/features/manage-tokens/impl/src/main/java/com/tangem/managetokens/presentation/managetokens/state/QuotesState.kt +++ /dev/null @@ -1,14 +0,0 @@ -package com.tangem.managetokens.presentation.managetokens.state - -import com.tangem.core.ui.components.marketprice.PriceChangeType -import kotlinx.collections.immutable.ImmutableList - -internal sealed class QuotesState { - object Unknown : QuotesState() - - data class Content( - val priceChange: String, - val changeType: PriceChangeType, - val chartData: ImmutableList, - ) : QuotesState() -} \ No newline at end of file diff --git a/features/manage-tokens/impl/src/main/java/com/tangem/managetokens/presentation/managetokens/state/SearchBarState.kt b/features/manage-tokens/impl/src/main/java/com/tangem/managetokens/presentation/managetokens/state/SearchBarState.kt deleted file mode 100644 index d64808239e..0000000000 --- a/features/manage-tokens/impl/src/main/java/com/tangem/managetokens/presentation/managetokens/state/SearchBarState.kt +++ /dev/null @@ -1,11 +0,0 @@ -package com.tangem.managetokens.presentation.managetokens.state - -/** - * SearchBar state. - */ -internal data class SearchBarState( - val query: String, - val onQueryChange: (String) -> Unit, - val active: Boolean, - val onActiveChange: (Boolean) -> Unit, -) \ No newline at end of file diff --git a/features/manage-tokens/impl/src/main/java/com/tangem/managetokens/presentation/managetokens/state/TokenButtonType.kt b/features/manage-tokens/impl/src/main/java/com/tangem/managetokens/presentation/managetokens/state/TokenButtonType.kt deleted file mode 100644 index 6c47a870ec..0000000000 --- a/features/manage-tokens/impl/src/main/java/com/tangem/managetokens/presentation/managetokens/state/TokenButtonType.kt +++ /dev/null @@ -1,5 +0,0 @@ -package com.tangem.managetokens.presentation.managetokens.state - -internal enum class TokenButtonType { - ADD, EDIT, NOT_AVAILABLE -} \ No newline at end of file diff --git a/features/manage-tokens/impl/src/main/java/com/tangem/managetokens/presentation/managetokens/state/TokenIconState.kt b/features/manage-tokens/impl/src/main/java/com/tangem/managetokens/presentation/managetokens/state/TokenIconState.kt deleted file mode 100644 index 0bd0c0d25d..0000000000 --- a/features/manage-tokens/impl/src/main/java/com/tangem/managetokens/presentation/managetokens/state/TokenIconState.kt +++ /dev/null @@ -1,10 +0,0 @@ -package com.tangem.managetokens.presentation.managetokens.state - -import androidx.compose.ui.graphics.Color -import com.tangem.core.ui.extensions.ImageReference - -internal data class TokenIconState( - val iconReference: ImageReference?, - val placeholderTint: Color, - val placeholderBackground: Color, -) \ No newline at end of file diff --git a/features/manage-tokens/impl/src/main/java/com/tangem/managetokens/presentation/managetokens/state/TokenItemState.kt b/features/manage-tokens/impl/src/main/java/com/tangem/managetokens/presentation/managetokens/state/TokenItemState.kt deleted file mode 100644 index 7262bbe337..0000000000 --- a/features/manage-tokens/impl/src/main/java/com/tangem/managetokens/presentation/managetokens/state/TokenItemState.kt +++ /dev/null @@ -1,23 +0,0 @@ -package com.tangem.managetokens.presentation.managetokens.state - -import androidx.compose.runtime.MutableState - -internal sealed class TokenItemState { - - abstract val id: String - - data class Loading(override val id: String) : TokenItemState() - - data class Loaded( - override val id: String, - val name: String, - val currencySymbol: String, - val tokenId: String, - val tokenIcon: TokenIconState, - val quotes: QuotesState, - val rate: String?, - val availableAction: MutableState, - val chooseNetworkState: ChooseNetworkState, - val onButtonClick: (Loaded) -> Unit, - ) : TokenItemState() -} \ No newline at end of file diff --git a/features/manage-tokens/impl/src/main/java/com/tangem/managetokens/presentation/managetokens/state/factory/ManageTokensStateFactory.kt b/features/manage-tokens/impl/src/main/java/com/tangem/managetokens/presentation/managetokens/state/factory/ManageTokensStateFactory.kt deleted file mode 100644 index d7531b2e85..0000000000 --- a/features/manage-tokens/impl/src/main/java/com/tangem/managetokens/presentation/managetokens/state/factory/ManageTokensStateFactory.kt +++ /dev/null @@ -1,194 +0,0 @@ -package com.tangem.managetokens.presentation.managetokens.state.factory - -import androidx.paging.PagingData -import com.tangem.core.ui.components.bottomsheets.TangemBottomSheetConfig -import com.tangem.core.ui.components.bottomsheets.TangemBottomSheetConfigContent -import com.tangem.core.ui.event.consumedEvent -import com.tangem.core.ui.event.triggeredEvent -import com.tangem.domain.tokens.CurrencyCompatibilityError -import com.tangem.domain.tokens.model.CryptoCurrency -import com.tangem.domain.wallets.models.UserWallet -import com.tangem.managetokens.presentation.common.state.* -import com.tangem.managetokens.presentation.common.utils.CurrencyUtils -import com.tangem.managetokens.presentation.managetokens.state.* -import com.tangem.managetokens.presentation.managetokens.viewmodels.ManageTokensClickIntents -import com.tangem.managetokens.presentation.managetokens.viewmodels.ManageTokensUiEvents -import com.tangem.utils.Provider -import kotlinx.collections.immutable.toPersistentList -import kotlinx.coroutines.flow.Flow - -internal class ManageTokensStateFactory( - private val currentStateProvider: Provider, - private val clickIntents: ManageTokensClickIntents, - private val uiIntents: ManageTokensUiEvents, -) { - - fun getInitialState(tokens: Flow>): ManageTokensState { - return ManageTokensState( - searchBarState = SearchBarState( - query = "", - onQueryChange = clickIntents::onSearchQueryChange, - active = false, - onActiveChange = clickIntents::onSearchActiveChange, - ), - tokens = tokens, - addCustomTokenButton = AddCustomTokenButton( - isVisible = false, - onClick = clickIntents::onAddCustomTokensButtonClick, - ), - derivationNotification = null, - isLoading = false, - event = consumedEvent(), - chooseWalletState = ChooseWalletState.NoSelection, - onEmptySearchResult = uiIntents::onEmptySearchResult, - customTokenBottomSheetConfig = TangemBottomSheetConfig( - isShow = false, - onDismissRequest = uiIntents::onAddCustomTokenSheetDismissed, - content = TangemBottomSheetConfigContent.Empty, - ), - ) - } - - fun updateChooseWalletState( - wallets: List, - userWallets: List, - selectedWallet: UserWallet?, - ): ManageTokensState { - val chooseWalletState = when { - wallets.size == 1 -> { - ChooseWalletState.NoSelection - } - wallets.isEmpty() && userWallets.all { !it.isMultiCurrency } -> { - ChooseWalletState.Warning(ChooseWalletWarning.SINGLE_CURRENCY) - } - else -> { - var selectedWalletState: WalletState? = null - ChooseWalletState.Choose( - wallets = wallets.map { wallet -> - val walletState = WalletState( - walletId = wallet.walletId.stringValue, - artworkUrl = wallet.artworkUrl, - onSelected = clickIntents::onWalletSelected, - walletName = wallet.name, - ) - if (wallet.walletId.stringValue == selectedWallet?.walletId?.stringValue) { - selectedWalletState = walletState - } - walletState - }.toPersistentList(), - selectedWallet = selectedWalletState, - onChooseWalletClick = clickIntents::onChooseWalletClick, - onCloseChoosingWalletClick = clickIntents::onCloseChoosingWalletClick, - ) - } - } - return currentStateProvider().copy(chooseWalletState = chooseWalletState) - } - - fun showAddCustomTokensButton(show: Boolean): ManageTokensState { - return currentStateProvider().copy( - addCustomTokenButton = currentStateProvider().addCustomTokenButton.copy(isVisible = show), - ) - } - - fun updateSelectedWallet(selectedWalletId: String?): ManageTokensState { - val chooseWalletState = currentStateProvider().chooseWalletState - return currentStateProvider().copy( - showChooseWalletScreen = false, - chooseWalletState = if (chooseWalletState is ChooseWalletState.Choose) { - chooseWalletState.copy( - selectedWallet = chooseWalletState.wallets.find { - it.walletId == selectedWalletId - } ?: chooseWalletState.wallets.first(), - ) - } else { - chooseWalletState - }, - ) - } - - fun getStateAndTriggerEvent( - state: ManageTokensState, - event: Event, - setUiState: (ManageTokensState) -> Unit, - ): ManageTokensState { - return state.copy( - event = triggeredEvent( - data = event, - onConsume = { - val currentState = currentStateProvider() - setUiState(currentState.copy(event = consumedEvent())) - }, - ), - ) - } - - fun transformAddTokenErrorToAlert(error: CurrencyCompatibilityError, networkName: String): AlertState { - return when (error) { - CurrencyCompatibilityError.SolanaTokensUnsupported -> AlertState.TokensUnsupported(networkName) - CurrencyCompatibilityError.UnsupportedBlockchain -> AlertState.TokensUnsupportedBlockchainByCard( - networkName, - ) - CurrencyCompatibilityError.UnsupportedCurve -> AlertState.TokensUnsupportedCurve - } - } - - fun toggleNetworkState( - token: TokenItemState.Loaded, - network: NetworkItemState.Toggleable, - allAddedCurrencies: Collection, - ) { - network.changeToggleState() - val anyNetworkAdded = isAnyNetworkAdded( - networks = token.chooseNetworkState.nativeNetworks + token.chooseNetworkState.nonNativeNetworks, - allAddedCurrencies = allAddedCurrencies, - ) - val buttonType = if (anyNetworkAdded) TokenButtonType.EDIT else TokenButtonType.ADD - token.availableAction.value = buttonType - } - - private fun isAnyNetworkAdded( - networks: List, - allAddedCurrencies: Collection, - ): Boolean { - return networks.any { - it is NetworkItemState.Toggleable && CurrencyUtils.isAdded( - address = it.address, - networkId = it.id, - currencies = allAddedCurrencies, - ) - } - } - - fun updateTokenNetworksOnTokenSelection( - token: TokenItemState.Loaded, - addedCurrenciesOnWallet: Collection, - ) { - token.chooseNetworkState.nativeNetworks.forEach { - if (it is NetworkItemState.Toggleable) { - val isAdded = CurrencyUtils.isAdded(it.address, it.id, addedCurrenciesOnWallet) - if (isAdded != it.isAdded.value) (it as? NetworkItemState.Toggleable)?.changeToggleState() - } - } - token.chooseNetworkState.nonNativeNetworks.forEach { - if (it is NetworkItemState.Toggleable) { - val isAdded = CurrencyUtils.isAdded(it.address, it.id, addedCurrenciesOnWallet) - if (isAdded != it.isAdded.value) (it as? NetworkItemState.Toggleable)?.changeToggleState() - } - } - } - - fun updateDerivationNotification(totalNeeded: Int, totalWallets: Int, walletsToDerive: Int): ManageTokensState { - val derivationNotificationState = if (totalNeeded == 0) { - null - } else { - DerivationNotificationState( - totalNeeded = totalNeeded, - totalWallets = totalWallets, - walletsToDerive = walletsToDerive, - onGenerateClick = clickIntents::onGetAddressesClick, - ) - } - return currentStateProvider().copy(derivationNotification = derivationNotificationState) - } -} \ No newline at end of file diff --git a/features/manage-tokens/impl/src/main/java/com/tangem/managetokens/presentation/managetokens/state/factory/NetworkToNetworkItemStateConverter.kt b/features/manage-tokens/impl/src/main/java/com/tangem/managetokens/presentation/managetokens/state/factory/NetworkToNetworkItemStateConverter.kt deleted file mode 100644 index 01af86d1f2..0000000000 --- a/features/manage-tokens/impl/src/main/java/com/tangem/managetokens/presentation/managetokens/state/factory/NetworkToNetworkItemStateConverter.kt +++ /dev/null @@ -1,57 +0,0 @@ -package com.tangem.managetokens.presentation.managetokens.state.factory - -import androidx.compose.runtime.mutableIntStateOf -import androidx.compose.runtime.mutableStateOf -import com.tangem.core.ui.extensions.getActiveIconResByNetworkId -import com.tangem.core.ui.extensions.getGreyedOutIconResByNetworkId -import com.tangem.domain.tokens.model.CryptoCurrency -import com.tangem.domain.tokens.model.Token -import com.tangem.domain.wallets.models.UserWallet -import com.tangem.managetokens.presentation.common.state.NetworkItemState -import com.tangem.managetokens.presentation.common.utils.CurrencyUtils -import com.tangem.managetokens.presentation.managetokens.state.TokenItemState -import com.tangem.utils.Provider -import com.tangem.utils.converter.Converter - -internal class NetworkToNetworkItemStateConverter( - private val addedCurrenciesByWalletProvider: Provider>>, - private val selectedWalletProvider: Provider, - private val onNetworkToggleClick: (token: TokenItemState.Loaded, network: NetworkItemState.Toggleable) -> Unit, -) : Converter { - - override fun convert(value: Token.Network): NetworkItemState { - return createManageNetworkContent(value) - } - - private fun createManageNetworkContent(network: Token.Network): NetworkItemState { - val addedCurrencies = addedCurrenciesByWalletProvider()[selectedWalletProvider()] ?: emptyList() - val isAdded = CurrencyUtils.isAdded( - address = network.address, - networkId = network.networkId, - currencies = addedCurrencies, - ) - return NetworkItemState.Toggleable( - name = network.name, - iconResId = mutableIntStateOf( - getNetworkIconResId(isAdded, network.networkId), // todo - ), - isMainNetwork = isMainNetwork(network), - isAdded = mutableStateOf(isAdded), - id = network.networkId, - protocolName = network.standardType, - address = network.address, - decimals = network.decimalCount, - onToggleClick = onNetworkToggleClick, - ) - } - - private fun getNetworkIconResId(isAdded: Boolean, networkId: String): Int { - return if (isAdded) { - getActiveIconResByNetworkId(networkId) - } else { - getGreyedOutIconResByNetworkId(networkId) - } - } - - private fun isMainNetwork(network: Token.Network) = network.address == null -} \ No newline at end of file diff --git a/features/manage-tokens/impl/src/main/java/com/tangem/managetokens/presentation/managetokens/state/factory/NetworksToChooseNetworkStateConverter.kt b/features/manage-tokens/impl/src/main/java/com/tangem/managetokens/presentation/managetokens/state/factory/NetworksToChooseNetworkStateConverter.kt deleted file mode 100644 index 99509e85ea..0000000000 --- a/features/manage-tokens/impl/src/main/java/com/tangem/managetokens/presentation/managetokens/state/factory/NetworksToChooseNetworkStateConverter.kt +++ /dev/null @@ -1,36 +0,0 @@ -package com.tangem.managetokens.presentation.managetokens.state.factory - -import com.tangem.domain.tokens.model.Token -import com.tangem.managetokens.presentation.common.state.NetworkItemState -import com.tangem.managetokens.presentation.managetokens.state.ChooseNetworkState -import com.tangem.utils.converter.Converter -import kotlinx.collections.immutable.toPersistentList - -internal class NetworksToChooseNetworkStateConverter( - private val networkToNetworkItemStateConverter: NetworkToNetworkItemStateConverter, - private val onNonNativeNetworkHintClick: () -> Unit, - private val onCloseChooseNetworkScreen: () -> Unit, -) : Converter, ChooseNetworkState> { - - override fun convert(value: List): ChooseNetworkState { - return createChooseNetworksState(value) - } - - private fun createChooseNetworksState(networks: List): ChooseNetworkState { - val nativeNetworks = mutableListOf() - val nonNativeNetworks = mutableListOf() - networks.map { networkToNetworkItemStateConverter.convert(it) }.forEach { - if (it is NetworkItemState.Toggleable && it.isMainNetwork) { - nativeNetworks.add(it) - } else { - nonNativeNetworks.add(it) - } - } - return ChooseNetworkState( - nativeNetworks = nativeNetworks.toPersistentList(), - nonNativeNetworks = nonNativeNetworks.toPersistentList(), - onNonNativeNetworkHintClick = onNonNativeNetworkHintClick, - onCloseChooseNetworkScreen = onCloseChooseNetworkScreen, - ) - } -} \ No newline at end of file diff --git a/features/manage-tokens/impl/src/main/java/com/tangem/managetokens/presentation/managetokens/state/factory/QuotesToQuotesStateConverter.kt b/features/manage-tokens/impl/src/main/java/com/tangem/managetokens/presentation/managetokens/state/factory/QuotesToQuotesStateConverter.kt deleted file mode 100644 index 972c004779..0000000000 --- a/features/manage-tokens/impl/src/main/java/com/tangem/managetokens/presentation/managetokens/state/factory/QuotesToQuotesStateConverter.kt +++ /dev/null @@ -1,34 +0,0 @@ -package com.tangem.managetokens.presentation.managetokens.state.factory - -import com.tangem.core.ui.components.marketprice.PriceChangeType -import com.tangem.core.ui.components.marketprice.utils.PriceChangeConverter -import com.tangem.core.ui.utils.BigDecimalFormatter -import com.tangem.domain.tokens.model.Quote -import com.tangem.managetokens.presentation.managetokens.state.QuotesState -import com.tangem.utils.converter.Converter -import kotlinx.collections.immutable.persistentListOf -import java.math.BigDecimal - -@Suppress("MagicNumber") // TODO: remove when chart data is added (in [REDACTED_TASK_KEY] when endpoint is ready) -internal class QuotesToQuotesStateConverter : Converter { - override fun convert(value: Quote): QuotesState { - val priceChange = value.priceChange - return QuotesState.Content( - priceChange = BigDecimalFormatter.formatPercent( - percent = priceChange.movePointLeft(2), - useAbsoluteValue = true, - ), - changeType = priceChange.getPriceChangeType(), - chartData = // TODO (in [REDACTED_TASK_KEY] when endpoint is ready) - when (priceChange.getPriceChangeType()) { - PriceChangeType.UP -> persistentListOf(0f, 5f, 10f, 30f) - PriceChangeType.DOWN -> persistentListOf(15f, 12f, 13f, 18f, 10f, 3f) - PriceChangeType.NEUTRAL -> persistentListOf(0f, 0f, 0f, 0f) - }, - ) - } - - private fun BigDecimal.getPriceChangeType(): PriceChangeType { - return PriceChangeConverter.fromBigDecimal(value = this) - } -} \ No newline at end of file diff --git a/features/manage-tokens/impl/src/main/java/com/tangem/managetokens/presentation/managetokens/state/factory/TokenConverter.kt b/features/manage-tokens/impl/src/main/java/com/tangem/managetokens/presentation/managetokens/state/factory/TokenConverter.kt deleted file mode 100644 index 156c65d70d..0000000000 --- a/features/manage-tokens/impl/src/main/java/com/tangem/managetokens/presentation/managetokens/state/factory/TokenConverter.kt +++ /dev/null @@ -1,67 +0,0 @@ -package com.tangem.managetokens.presentation.managetokens.state.factory - -import androidx.compose.runtime.mutableStateOf -import com.tangem.core.ui.extensions.ImageReference -import com.tangem.core.ui.extensions.getTintForTokenIcon -import com.tangem.core.ui.extensions.tryGetBackgroundForTokenIcon -import com.tangem.core.ui.utils.BigDecimalFormatter -import com.tangem.domain.appcurrency.model.AppCurrency -import com.tangem.domain.tokens.model.CryptoCurrency -import com.tangem.domain.tokens.model.Token -import com.tangem.managetokens.presentation.common.utils.CurrencyUtils -import com.tangem.managetokens.presentation.managetokens.state.QuotesState -import com.tangem.managetokens.presentation.managetokens.state.TokenButtonType -import com.tangem.managetokens.presentation.managetokens.state.TokenIconState -import com.tangem.managetokens.presentation.managetokens.state.TokenItemState -import com.tangem.utils.Provider -import com.tangem.utils.converter.Converter - -internal class TokenConverter( - private val quotesStateConverter: QuotesToQuotesStateConverter, - private val networksToChooseNetworkStateConverter: NetworksToChooseNetworkStateConverter, - private val allAddedCurrencies: Provider>, - private val selectedAppCurrency: Provider, - private val onTokenItemButtonClick: (TokenItemState.Loaded) -> Unit, -) : Converter { - - override fun convert(value: Token): TokenItemState.Loaded { - val isAnyAdded = value.networks.any { network -> - CurrencyUtils.isAdded( - address = network.address, - networkId = network.networkId, - currencies = allAddedCurrencies(), - ) - } - val buttonType = when { - value.isAvailable && isAnyAdded -> TokenButtonType.EDIT - value.isAvailable && !isAnyAdded -> TokenButtonType.ADD - else -> TokenButtonType.NOT_AVAILABLE - } - - val background = tryGetBackgroundForTokenIcon(value.networks.firstOrNull()?.address ?: "") - val tint = getTintForTokenIcon(background) - - return TokenItemState.Loaded( - id = value.id, - name = value.name, - currencySymbol = value.symbol, - tokenId = value.id, - tokenIcon = TokenIconState( - ImageReference.Url(value.iconUrl), - placeholderBackground = background, - placeholderTint = tint, - ), - quotes = value.quote?.let { quotesStateConverter.convert(it) } ?: QuotesState.Unknown, - rate = value.quote?.fiatRate?.let { rate -> - BigDecimalFormatter.formatFiatAmount( - fiatAmount = rate, - fiatCurrencyCode = selectedAppCurrency().code, - fiatCurrencySymbol = selectedAppCurrency().symbol, - ) - }, - availableAction = mutableStateOf(buttonType), - chooseNetworkState = networksToChooseNetworkStateConverter.convert(value.networks), - onButtonClick = onTokenItemButtonClick, - ) - } -} \ No newline at end of file diff --git a/features/manage-tokens/impl/src/main/java/com/tangem/managetokens/presentation/managetokens/state/factory/TokenToCryptoCurrencyConverter.kt b/features/manage-tokens/impl/src/main/java/com/tangem/managetokens/presentation/managetokens/state/factory/TokenToCryptoCurrencyConverter.kt deleted file mode 100644 index a7a6832cc6..0000000000 --- a/features/manage-tokens/impl/src/main/java/com/tangem/managetokens/presentation/managetokens/state/factory/TokenToCryptoCurrencyConverter.kt +++ /dev/null @@ -1,37 +0,0 @@ -package com.tangem.managetokens.presentation.managetokens.state.factory - -import com.tangem.data.tokens.utils.CryptoCurrencyFactory -import com.tangem.domain.common.DerivationStyleProvider -import com.tangem.domain.tokens.model.CryptoCurrency -import com.tangem.managetokens.presentation.common.state.NetworkItemState -import com.tangem.managetokens.presentation.managetokens.state.TokenItemState -import com.tangem.utils.converter.Converter - -internal class TokenToCryptoCurrencyConverter( - private val network: NetworkItemState, - private val derivationStyleProvider: DerivationStyleProvider, -) : Converter { - - override fun convert(value: TokenItemState.Loaded): CryptoCurrency? { - return if (network is NetworkItemState.Toggleable && network.address != null) { - CryptoCurrencyFactory().createToken( - CryptoCurrencyFactory.Token( - symbol = value.currencySymbol, - name = value.name, - id = value.tokenId, - contractAddress = network.address, - decimals = requireNotNull(network.decimals), - ), - networkId = network.id, - derivationStyleProvider = derivationStyleProvider, - extraDerivationPath = null, - ) - } else { - CryptoCurrencyFactory().createCoin( - networkId = network.id, - derivationStyleProvider = derivationStyleProvider, - extraDerivationPath = null, - ) - } - } -} \ No newline at end of file diff --git a/features/manage-tokens/impl/src/main/java/com/tangem/managetokens/presentation/managetokens/state/previewdata/ChooseNetworkStatePreviewData.kt b/features/manage-tokens/impl/src/main/java/com/tangem/managetokens/presentation/managetokens/state/previewdata/ChooseNetworkStatePreviewData.kt deleted file mode 100644 index f66b65bc1b..0000000000 --- a/features/manage-tokens/impl/src/main/java/com/tangem/managetokens/presentation/managetokens/state/previewdata/ChooseNetworkStatePreviewData.kt +++ /dev/null @@ -1,56 +0,0 @@ -package com.tangem.managetokens.presentation.managetokens.state.previewdata - -import androidx.compose.runtime.mutableStateOf -import com.tangem.features.managetokens.impl.R -import com.tangem.managetokens.presentation.common.state.NetworkItemState -import com.tangem.managetokens.presentation.managetokens.state.ChooseNetworkState -import kotlinx.collections.immutable.toImmutableList - -internal object ChooseNetworkStatePreviewData { - - val state = ChooseNetworkState( - nativeNetworks = nativeNetworks.toImmutableList(), - nonNativeNetworks = nonNativeNetworks.toImmutableList(), - onNonNativeNetworkHintClick = {}, - onCloseChooseNetworkScreen = {}, - ) -} - -internal val nativeNetworks = listOf( - NetworkItemState.Toggleable( - name = "Ethereum", - protocolName = "ETH", - iconResId = mutableStateOf(R.drawable.img_polygon_22), - isMainNetwork = true, - isAdded = mutableStateOf(true), - id = "", - onToggleClick = { _, _ -> }, - address = "", - decimals = 0, - ), -) - -internal val nonNativeNetworks = listOf( - NetworkItemState.Toggleable( - name = "Ethereum", - protocolName = "ETH", - iconResId = mutableStateOf(R.drawable.img_kusama_22), - isMainNetwork = false, - isAdded = mutableStateOf(true), - id = "1", - onToggleClick = { _, _ -> }, - address = "", - decimals = 0, - ), - NetworkItemState.Toggleable( - name = "BNB SMART CHAIN", - protocolName = "BEP20", - iconResId = mutableStateOf(R.drawable.ic_bsc_16), - isMainNetwork = false, - isAdded = mutableStateOf(false), - id = "2", - onToggleClick = { _, _ -> }, - address = "", - decimals = 0, - ), -) \ No newline at end of file diff --git a/features/manage-tokens/impl/src/main/java/com/tangem/managetokens/presentation/managetokens/state/previewdata/DerivationNotificationStatePreviewData.kt b/features/manage-tokens/impl/src/main/java/com/tangem/managetokens/presentation/managetokens/state/previewdata/DerivationNotificationStatePreviewData.kt deleted file mode 100644 index b5d88b814a..0000000000 --- a/features/manage-tokens/impl/src/main/java/com/tangem/managetokens/presentation/managetokens/state/previewdata/DerivationNotificationStatePreviewData.kt +++ /dev/null @@ -1,12 +0,0 @@ -package com.tangem.managetokens.presentation.managetokens.state.previewdata - -import com.tangem.managetokens.presentation.managetokens.state.DerivationNotificationState - -object DerivationNotificationStatePreviewData { - val state = DerivationNotificationState( - totalNeeded = 5, - totalWallets = 3, - walletsToDerive = 2, - onGenerateClick = {}, - ) -} \ No newline at end of file diff --git a/features/manage-tokens/impl/src/main/java/com/tangem/managetokens/presentation/managetokens/state/previewdata/ManageTokensStatePreviewData.kt b/features/manage-tokens/impl/src/main/java/com/tangem/managetokens/presentation/managetokens/state/previewdata/ManageTokensStatePreviewData.kt deleted file mode 100644 index eab841b41f..0000000000 --- a/features/manage-tokens/impl/src/main/java/com/tangem/managetokens/presentation/managetokens/state/previewdata/ManageTokensStatePreviewData.kt +++ /dev/null @@ -1,45 +0,0 @@ -package com.tangem.managetokens.presentation.managetokens.state.previewdata - -import androidx.paging.PagingData -import com.tangem.core.ui.components.bottomsheets.TangemBottomSheetConfig -import com.tangem.core.ui.components.bottomsheets.TangemBottomSheetConfigContent -import com.tangem.core.ui.event.consumedEvent -import com.tangem.managetokens.presentation.common.state.previewdata.ChooseWalletStatePreviewData -import com.tangem.managetokens.presentation.managetokens.state.* -import com.tangem.managetokens.presentation.managetokens.state.ManageTokensState -import com.tangem.managetokens.presentation.managetokens.state.SearchBarState -import com.tangem.managetokens.presentation.managetokens.state.TokenItemState -import kotlinx.coroutines.flow.flowOf - -internal object ManageTokensStatePreviewData { - val loadedState: ManageTokensState - get() = ManageTokensState( - searchBarState = searchState, - tokens = flowOf(PagingData.from(tokens)), - isLoading = false, - addCustomTokenButton = AddCustomTokenButton(true, {}), - derivationNotification = DerivationNotificationStatePreviewData.state, - event = consumedEvent(), - chooseWalletState = ChooseWalletStatePreviewData.state, - onEmptySearchResult = {}, - customTokenBottomSheetConfig = TangemBottomSheetConfig(false, {}, TangemBottomSheetConfigContent.Empty), - ) - - val loadingState: ManageTokensState - get() = loadedState.copy(isLoading = true) - - private val tokens: List - get() = listOf( - TokenItemStatePreviewData.loadedPriceDown, - TokenItemStatePreviewData.loadedPriceUp, - TokenItemStatePreviewData.loadedPriceNeutral, - ) - - private val searchState: SearchBarState - get() = SearchBarState( - query = "", - onQueryChange = {}, - active = false, - onActiveChange = {}, - ) -} \ No newline at end of file diff --git a/features/manage-tokens/impl/src/main/java/com/tangem/managetokens/presentation/managetokens/state/previewdata/TokenItemStatePreviewData.kt b/features/manage-tokens/impl/src/main/java/com/tangem/managetokens/presentation/managetokens/state/previewdata/TokenItemStatePreviewData.kt deleted file mode 100644 index 1ba8f760e6..0000000000 --- a/features/manage-tokens/impl/src/main/java/com/tangem/managetokens/presentation/managetokens/state/previewdata/TokenItemStatePreviewData.kt +++ /dev/null @@ -1,77 +0,0 @@ -package com.tangem.managetokens.presentation.managetokens.state.previewdata - -import androidx.compose.runtime.mutableStateOf -import androidx.compose.ui.graphics.Color -import com.tangem.core.ui.components.marketprice.PriceChangeType -import com.tangem.managetokens.presentation.managetokens.state.QuotesState -import com.tangem.managetokens.presentation.managetokens.state.TokenButtonType -import com.tangem.managetokens.presentation.managetokens.state.TokenIconState -import com.tangem.managetokens.presentation.managetokens.state.TokenItemState -import kotlinx.collections.immutable.persistentListOf - -internal object TokenItemStatePreviewData { - - val tokenLoading: TokenItemState - get() = TokenItemState.Loading("id") - - val loadedPriceDown: TokenItemState - get() = TokenItemState.Loaded( - id = "BTC", - name = "Bitcoin Bitcoin Bitcoin Bitcoin Bitcoin Bitcoin Bitcoin Bitcoin", - tokenId = "BTC", - currencySymbol = "BTC", - tokenIcon = tokenIconState, - quotes = QuotesState.Content( - priceChange = "0.43%", - changeType = PriceChangeType.DOWN, - chartData = persistentListOf(10f, 2f, 5f, 3f, 4f, 8f, 9f, 7f, 4f), - ), - rate = "31 285.72$", - availableAction = mutableStateOf(TokenButtonType.ADD), - onButtonClick = {}, - chooseNetworkState = ChooseNetworkStatePreviewData.state, - ) - - val loadedPriceUp: TokenItemState - get() = TokenItemState.Loaded( - id = "BTC", - name = "Bitcoin", - tokenId = "BTC", - currencySymbol = "BTC", - tokenIcon = tokenIconState, - quotes = QuotesState.Content( - priceChange = "0.43%", - changeType = PriceChangeType.UP, - chartData = persistentListOf(1f, 3f, 4f, 8f, 12f, 10f, 8f, 3f, 5f, 7f), - ), - rate = "31 285.72$", - availableAction = mutableStateOf(TokenButtonType.NOT_AVAILABLE), - onButtonClick = {}, - chooseNetworkState = ChooseNetworkStatePreviewData.state, - ) - - val loadedPriceNeutral: TokenItemState - get() = TokenItemState.Loaded( - id = "BTC", - name = "Bitcoin Bitcoin Bitcoin Bitcoin Bitcoin Bitcoin Bitcoin Bitcoin", - tokenId = "BTC", - currencySymbol = "BTC", - tokenIcon = tokenIconState, - quotes = QuotesState.Content( - priceChange = "0.00%", - changeType = PriceChangeType.NEUTRAL, - chartData = persistentListOf(10f, 2f, 5f, 3f, 4f, 8f, 9f, 7f, 10f), - ), - rate = "31 285.72$", - availableAction = mutableStateOf(TokenButtonType.ADD), - onButtonClick = {}, - chooseNetworkState = ChooseNetworkStatePreviewData.state, - ) - - private val tokenIconState: TokenIconState - get() = TokenIconState( - iconReference = null, - placeholderTint = Color.White, - placeholderBackground = Color.Black, - ) -} \ No newline at end of file diff --git a/features/manage-tokens/impl/src/main/java/com/tangem/managetokens/presentation/managetokens/ui/ChooseNetworkBottomSheet.kt b/features/manage-tokens/impl/src/main/java/com/tangem/managetokens/presentation/managetokens/ui/ChooseNetworkBottomSheet.kt deleted file mode 100644 index 5cbdc20a93..0000000000 --- a/features/manage-tokens/impl/src/main/java/com/tangem/managetokens/presentation/managetokens/ui/ChooseNetworkBottomSheet.kt +++ /dev/null @@ -1,24 +0,0 @@ -package com.tangem.managetokens.presentation.managetokens.ui - -import androidx.compose.runtime.Composable -import com.tangem.core.ui.components.bottomsheets.TangemBottomSheet -import com.tangem.core.ui.components.bottomsheets.TangemBottomSheetConfig -import com.tangem.core.ui.components.bottomsheets.TangemBottomSheetConfigContent -import com.tangem.core.ui.res.TangemTheme -import com.tangem.managetokens.presentation.common.state.ChooseWalletState -import com.tangem.managetokens.presentation.managetokens.state.TokenItemState - -@Composable -internal fun ChooseNetworkBottomSheet(config: TangemBottomSheetConfig) { - TangemBottomSheet( - config = config, - containerColor = TangemTheme.colors.background.tertiary, - ) { - ChooseNetworkScreen(state = it.selectedToken, walletState = it.chooseWalletState) - } -} - -internal class ChooseNetworkBottomSheetConfig( - val selectedToken: TokenItemState.Loaded, - val chooseWalletState: ChooseWalletState, -) : TangemBottomSheetConfigContent \ No newline at end of file diff --git a/features/manage-tokens/impl/src/main/java/com/tangem/managetokens/presentation/managetokens/ui/ChooseNetworkScreen.kt b/features/manage-tokens/impl/src/main/java/com/tangem/managetokens/presentation/managetokens/ui/ChooseNetworkScreen.kt deleted file mode 100644 index 2f5d51df8a..0000000000 --- a/features/manage-tokens/impl/src/main/java/com/tangem/managetokens/presentation/managetokens/ui/ChooseNetworkScreen.kt +++ /dev/null @@ -1,201 +0,0 @@ -package com.tangem.managetokens.presentation.managetokens.ui - -import android.content.res.Configuration -import androidx.compose.foundation.background -import androidx.compose.foundation.clickable -import androidx.compose.foundation.layout.* -import androidx.compose.foundation.lazy.LazyColumn -import androidx.compose.foundation.lazy.LazyListScope -import androidx.compose.material.Icon -import androidx.compose.material3.Text -import androidx.compose.runtime.Composable -import androidx.compose.ui.Modifier -import androidx.compose.ui.res.painterResource -import androidx.compose.ui.res.stringResource -import androidx.compose.ui.text.style.TextAlign -import androidx.compose.ui.tooling.preview.Preview -import com.tangem.core.ui.components.SpacerH -import com.tangem.core.ui.components.SpacerW -import com.tangem.core.ui.components.WarningCardTitleOnly -import com.tangem.core.ui.decorations.roundedShapeItemDecoration -import com.tangem.core.ui.res.TangemThemePreview -import com.tangem.core.ui.res.TangemTheme -import com.tangem.features.managetokens.impl.R -import com.tangem.managetokens.presentation.common.state.ChooseWalletState -import com.tangem.managetokens.presentation.common.state.previewdata.ChooseWalletStatePreviewData -import com.tangem.managetokens.presentation.common.ui.components.NetworkItem -import com.tangem.managetokens.presentation.common.ui.components.SimpleSelectionBlock -import com.tangem.managetokens.presentation.managetokens.state.ChooseNetworkState -import com.tangem.managetokens.presentation.managetokens.state.TokenItemState -import com.tangem.managetokens.presentation.managetokens.state.previewdata.TokenItemStatePreviewData - -@Composable -internal fun ChooseNetworkScreen( - state: TokenItemState.Loaded, - walletState: ChooseWalletState, - modifier: Modifier = Modifier, -) { - val networkState = state.chooseNetworkState - LazyColumn( - contentPadding = PaddingValues( - start = TangemTheme.dimens.spacing16, - end = TangemTheme.dimens.spacing16, - bottom = TangemTheme.dimens.spacing16, - ), - modifier = modifier - .background(TangemTheme.colors.background.tertiary), - ) { - item { - Text( - text = stringResource(id = R.string.manage_tokens_network_selector_title), - color = TangemTheme.colors.text.primary1, - style = TangemTheme.typography.subtitle1, - textAlign = TextAlign.Center, - modifier = Modifier - .fillMaxWidth(), - ) - } - - when (walletState) { - is ChooseWalletState.Choose -> { - item { - SpacerH(height = TangemTheme.dimens.spacing10) - } - item { - SimpleSelectionBlock( - title = stringResource(id = R.string.manage_tokens_network_selector_wallet), - subtitle = walletState.selectedWallet?.walletName ?: "", - onClick = walletState.onChooseWalletClick, - ) - } - } - ChooseWalletState.NoSelection -> Unit - is ChooseWalletState.Warning -> { - item { - SpacerH(height = TangemTheme.dimens.spacing10) - } - item { - WarningCardTitleOnly( - title = stringResource(id = R.string.manage_tokens_wallet_support_only_one_network_title), - ) - } - } - } - - item { - SpacerH(height = TangemTheme.dimens.spacing16) - } - - if (networkState.nativeNetworks.isNotEmpty()) { - this@LazyColumn.nativeNetworks(networkState = networkState, tokenState = state) - } - - if (networkState.nonNativeNetworks.isNotEmpty()) { - this@LazyColumn.nonNativeNetworks(networkState = networkState, tokenState = state) - } - } -} - -private fun LazyListScope.nativeNetworks(networkState: ChooseNetworkState, tokenState: TokenItemState.Loaded) { - item { - Text( - text = stringResource(id = R.string.manage_tokens_network_selector_native_title), - color = TangemTheme.colors.text.tertiary, - style = TangemTheme.typography.caption1, - ) - SpacerH(height = TangemTheme.dimens.spacing2) - Text( - text = stringResource(id = R.string.manage_tokens_network_selector_native_subtitle), - color = TangemTheme.colors.text.tertiary, - style = TangemTheme.typography.caption2, - ) - SpacerH(height = TangemTheme.dimens.spacing8) - } - - items( - count = networkState.nativeNetworks.count(), - key = { index -> networkState.nativeNetworks[index].id }, - ) { index -> - NetworkItem( - state = networkState.nativeNetworks[index], - tokenState = tokenState, - modifier = Modifier - .roundedShapeItemDecoration( - currentIndex = index, - lastIndex = networkState.nativeNetworks.lastIndex, - addDefaultPadding = false, - ), - ) - } - - item { - SpacerH(height = TangemTheme.dimens.spacing16) - } -} - -private fun LazyListScope.nonNativeNetworks(networkState: ChooseNetworkState, tokenState: TokenItemState.Loaded) { - item { - NonNativeNetworksHeader(networkState.onNonNativeNetworkHintClick) - SpacerH(height = TangemTheme.dimens.spacing8) - } - - items( - count = networkState.nonNativeNetworks.count(), - key = { index -> networkState.nonNativeNetworks[index].id }, - ) { index -> - NetworkItem( - state = networkState.nonNativeNetworks[index], - tokenState = tokenState, - modifier = Modifier - .roundedShapeItemDecoration( - currentIndex = index, - lastIndex = networkState.nonNativeNetworks.lastIndex, - addDefaultPadding = false, - ), - ) - } - - item { - SpacerH(height = TangemTheme.dimens.spacing16) - } -} - -@Composable -private fun NonNativeNetworksHeader(onNonNativeNetworkHintClick: () -> Unit) { - Column { - Row { - Text( - text = stringResource(id = R.string.manage_tokens_network_selector_non_native_title), - color = TangemTheme.colors.text.tertiary, - style = TangemTheme.typography.caption1, - ) - SpacerW(width = TangemTheme.dimens.spacing2) - Icon( - painter = painterResource(id = R.drawable.ic_information_24), - tint = TangemTheme.colors.icon.inactive, - contentDescription = null, - modifier = Modifier - .size(TangemTheme.dimens.size16) - .clickable { onNonNativeNetworkHintClick() }, - ) - } - SpacerH(height = TangemTheme.dimens.spacing2) - Text( - text = stringResource(id = R.string.manage_tokens_network_selector_non_native_subtitle), - color = TangemTheme.colors.text.tertiary, - style = TangemTheme.typography.caption2, - ) - } -} - -@Preview -@Preview(uiMode = Configuration.UI_MODE_NIGHT_YES) -@Composable -private fun Preview_ChooseNetworkScreen() { - TangemThemePreview { - ChooseNetworkScreen( - state = TokenItemStatePreviewData.loadedPriceDown as TokenItemState.Loaded, - walletState = ChooseWalletStatePreviewData.state, - ) - } -} \ No newline at end of file diff --git a/features/manage-tokens/impl/src/main/java/com/tangem/managetokens/presentation/managetokens/ui/ManageTokensScreen.kt b/features/manage-tokens/impl/src/main/java/com/tangem/managetokens/presentation/managetokens/ui/ManageTokensScreen.kt deleted file mode 100644 index 15197a8e4a..0000000000 --- a/features/manage-tokens/impl/src/main/java/com/tangem/managetokens/presentation/managetokens/ui/ManageTokensScreen.kt +++ /dev/null @@ -1,198 +0,0 @@ -package com.tangem.managetokens.presentation.managetokens.ui - -import android.content.res.Configuration -import androidx.compose.animation.core.animateDpAsState -import androidx.compose.foundation.background -import androidx.compose.foundation.layout.* -import androidx.compose.foundation.lazy.rememberLazyListState -import androidx.compose.material.Surface -import androidx.compose.runtime.* -import androidx.compose.ui.Alignment -import androidx.compose.ui.Modifier -import androidx.compose.ui.layout.onGloballyPositioned -import androidx.compose.ui.platform.LocalDensity -import androidx.compose.ui.tooling.preview.Preview -import androidx.compose.ui.tooling.preview.PreviewParameter -import androidx.compose.ui.tooling.preview.datasource.CollectionPreviewParameterProvider -import androidx.compose.ui.unit.Dp -import androidx.compose.ui.unit.dp -import androidx.paging.LoadState -import androidx.paging.compose.LazyPagingItems -import androidx.paging.compose.collectAsLazyPagingItems -import com.tangem.core.ui.components.Keyboard -import com.tangem.core.ui.components.SpacerH18 -import com.tangem.core.ui.components.bottomsheets.TangemBottomSheetConfig -import com.tangem.core.ui.components.keyboardAsState -import com.tangem.core.ui.res.TangemThemePreview -import com.tangem.core.ui.res.TangemTheme -import com.tangem.managetokens.presentation.addcustomtoken.ui.AddCustomTokenBottomSheet -import com.tangem.managetokens.presentation.common.state.AlertState -import com.tangem.managetokens.presentation.common.state.ChooseWalletState -import com.tangem.managetokens.presentation.common.ui.ChooseWalletBottomSheet -import com.tangem.managetokens.presentation.common.ui.ChooseWalletBottomSheetConfig -import com.tangem.managetokens.presentation.common.ui.EventEffect -import com.tangem.managetokens.presentation.common.ui.components.Alert -import com.tangem.managetokens.presentation.managetokens.state.ManageTokensState -import com.tangem.managetokens.presentation.managetokens.state.TokenItemState -import com.tangem.managetokens.presentation.managetokens.state.previewdata.ManageTokensStatePreviewData -import com.tangem.managetokens.presentation.managetokens.ui.components.DerivationNotification -import com.tangem.managetokens.presentation.managetokens.ui.components.TokensList -import com.tangem.managetokens.presentation.managetokens.ui.components.TokensSearchBar - -@Composable -internal fun ManageTokensScreen(state: ManageTokensState, onHeaderSizeChange: (Dp) -> Unit) { - var alertState by remember { mutableStateOf(value = null) } - - EventEffect( - event = state.event, - onAlertStateSet = { alertState = it }, - ) - alertState?.let { - Alert(state = it, onDismiss = { alertState = null }) - } - - Content(state = state, onHeaderSizeChange = onHeaderSizeChange) - - AddCustomTokenBottomSheet(state.customTokenBottomSheetConfig) -} - -@Composable -private fun Content(state: ManageTokensState, onHeaderSizeChange: (Dp) -> Unit) { - val keyboard by keyboardAsState() - val density = LocalDensity.current - var tokenListAlertBottomPadding by remember(keyboard is Keyboard.Opened) { mutableStateOf(0.dp) } - - Box( - modifier = Modifier - .fillMaxSize() - .navigationBarsPadding() - .imePadding() - .background(color = TangemTheme.colors.background.primary), - ) { - Column { - val listState = rememberLazyListState() - val raiseSearchBar by remember { derivedStateOf { listState.firstVisibleItemIndex > 0 } } - val elevation by animateDpAsState( - targetValue = if (raiseSearchBar) TangemTheme.dimens.elevation8 else TangemTheme.dimens.elevation0, - label = "top_bar_elevation", - ) - - Surface( - elevation = elevation, - modifier = Modifier.onGloballyPositioned { - with(density) { onHeaderSizeChange(it.size.height.toDp()) } - }, - ) { - TokensSearchBar( - state = state.searchBarState, - modifier = Modifier - .background(color = TangemTheme.colors.background.primary) - .padding( - start = TangemTheme.dimens.spacing16, - end = TangemTheme.dimens.spacing16, - bottom = TangemTheme.dimens.spacing4, - ), - ) - } - - SpacerH18() - - val tokens = state.tokens.collectAsLazyPagingItems() - val query = state.searchBarState.query - - TrackPossibleEmptySearchResult( - tokens = tokens, - query = query, - onEmptySearchResult = state.onEmptySearchResult, - ) - - TokensList( - modifier = Modifier.padding(bottom = tokenListAlertBottomPadding), - tokens = tokens, - addCustomTokenButton = state.addCustomTokenButton, - ) - } - - state.selectedToken?.let { selectedToken -> - ManageTokensBottomSheet(selectedToken = selectedToken, state = state) - } - - state.derivationNotification?.let { - if (keyboard is Keyboard.Closed) { - DerivationNotification( - config = it.config, - modifier = Modifier - .align(Alignment.BottomCenter) - .onGloballyPositioned { - with(density) { tokenListAlertBottomPadding = it.size.height.toDp() } - }, - ) - DisposableEffect(Unit) { - onDispose { tokenListAlertBottomPadding = 0.dp } - } - } - } - } -} - -@Composable -private fun TrackPossibleEmptySearchResult( - tokens: LazyPagingItems, - query: String, - onEmptySearchResult: (String) -> Unit, -) { - val wasLoading = remember { mutableStateOf(false) } - - LaunchedEffect(tokens.loadState) { - val isLoading = tokens.loadState.refresh == LoadState.Loading - val stoppedLoading = wasLoading.value && !isLoading - val queryAndTokensCondition = query.isNotEmpty() && tokens.itemSnapshotList.isEmpty() - - if (stoppedLoading && queryAndTokensCondition) { - onEmptySearchResult(query) - } - - wasLoading.value = isLoading - } -} - -@Composable -private fun ManageTokensBottomSheet(selectedToken: TokenItemState.Loaded, state: ManageTokensState) { - if (state.showChooseWalletScreen && state.chooseWalletState is ChooseWalletState.Choose) { - val config = TangemBottomSheetConfig( - isShow = true, - content = ChooseWalletBottomSheetConfig(state.chooseWalletState), - onDismissRequest = state.chooseWalletState.onCloseChoosingWalletClick, - ) - ChooseWalletBottomSheet(config) - } else { - val config = TangemBottomSheetConfig( - isShow = true, - content = ChooseNetworkBottomSheetConfig( - selectedToken = selectedToken, - chooseWalletState = state.chooseWalletState, - ), - onDismissRequest = selectedToken.chooseNetworkState.onCloseChooseNetworkScreen, - ) - ChooseNetworkBottomSheet(config) - } -} - -@Preview -@Preview(uiMode = Configuration.UI_MODE_NIGHT_YES) -@Composable -private fun Preview_ManageTokensScreen( - @PreviewParameter(ManageTokensConfigProvider::class) - state: ManageTokensState, -) { - TangemThemePreview { - ManageTokensScreen(state) {} - } -} - -private class ManageTokensConfigProvider : CollectionPreviewParameterProvider( - collection = listOf( - ManageTokensStatePreviewData.loadingState, - ManageTokensStatePreviewData.loadedState, - ), -) \ No newline at end of file diff --git a/features/manage-tokens/impl/src/main/java/com/tangem/managetokens/presentation/managetokens/ui/components/AddCustomTokenButton.kt b/features/manage-tokens/impl/src/main/java/com/tangem/managetokens/presentation/managetokens/ui/components/AddCustomTokenButton.kt deleted file mode 100644 index 32962c70db..0000000000 --- a/features/manage-tokens/impl/src/main/java/com/tangem/managetokens/presentation/managetokens/ui/components/AddCustomTokenButton.kt +++ /dev/null @@ -1,60 +0,0 @@ -package com.tangem.managetokens.presentation.managetokens.ui.components - -import android.content.res.Configuration -import androidx.compose.foundation.background -import androidx.compose.foundation.clickable -import androidx.compose.foundation.layout.* -import androidx.compose.foundation.shape.CircleShape -import androidx.compose.material.Icon -import androidx.compose.material3.Text -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.res.stringResource -import androidx.compose.ui.tooling.preview.Preview -import com.tangem.core.ui.components.SpacerW -import com.tangem.core.ui.res.TangemTheme -import com.tangem.core.ui.res.TangemThemePreview -import com.tangem.features.managetokens.impl.R - -@Composable -internal fun AddCustomTokenButton(onButtonClick: () -> Unit, modifier: Modifier = Modifier) { - Row( - horizontalArrangement = Arrangement.Start, - verticalAlignment = Alignment.CenterVertically, - modifier = modifier - .defaultMinSize(minHeight = TangemTheme.dimens.size68) - .fillMaxWidth() - .clickable { onButtonClick() } - .padding(horizontal = TangemTheme.dimens.spacing16), - ) { - Box( - modifier = Modifier - .size(TangemTheme.dimens.size36) - .background(color = TangemTheme.colors.button.secondary, shape = CircleShape), - contentAlignment = Alignment.Center, - ) { - Icon( - painter = painterResource(id = R.drawable.ic_plus_24), - contentDescription = null, - tint = TangemTheme.colors.icon.informative, - ) - } - SpacerW(width = TangemTheme.dimens.spacing12) - Text( - text = stringResource(id = R.string.add_custom_token_title), - style = TangemTheme.typography.subtitle2, - color = TangemTheme.colors.text.tertiary, - ) - } -} - -@Preview -@Preview(uiMode = Configuration.UI_MODE_NIGHT_YES) -@Composable -private fun AddCustomTokenButton_Preview() { - TangemThemePreview { - AddCustomTokenButton(onButtonClick = { }) - } -} \ No newline at end of file diff --git a/features/manage-tokens/impl/src/main/java/com/tangem/managetokens/presentation/managetokens/ui/components/DerivationNotification.kt b/features/manage-tokens/impl/src/main/java/com/tangem/managetokens/presentation/managetokens/ui/components/DerivationNotification.kt deleted file mode 100644 index d1f3822c9b..0000000000 --- a/features/manage-tokens/impl/src/main/java/com/tangem/managetokens/presentation/managetokens/ui/components/DerivationNotification.kt +++ /dev/null @@ -1,138 +0,0 @@ -package com.tangem.managetokens.presentation.managetokens.ui.components - -import android.content.res.Configuration -import androidx.compose.foundation.background -import androidx.compose.foundation.layout.* -import androidx.compose.foundation.shape.CircleShape -import androidx.compose.foundation.shape.RoundedCornerShape -import androidx.compose.material.Card -import androidx.compose.material.Icon -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 com.tangem.core.ui.components.PrimaryButtonIconEndTwoLines -import com.tangem.core.ui.components.SpacerW -import com.tangem.core.ui.components.notifications.NotificationConfig -import com.tangem.core.ui.extensions.TextReference -import com.tangem.core.ui.extensions.resolveReference -import com.tangem.core.ui.res.TangemThemePreview -import com.tangem.core.ui.res.TangemTheme -import com.tangem.features.managetokens.impl.R -import com.tangem.managetokens.presentation.managetokens.state.previewdata.DerivationNotificationStatePreviewData - -@Composable -internal fun DerivationNotification(config: NotificationConfig, modifier: Modifier = Modifier) { - BaseContainer( - modifier = modifier, - ) { - Column( - modifier = Modifier.padding(all = TangemTheme.dimens.spacing16), - verticalArrangement = Arrangement.spacedBy(space = TangemTheme.dimens.spacing16), - ) { - MainContent( - iconResId = config.iconResId, - iconTint = TangemTheme.colors.icon.accent, - title = config.title, - subtitle = config.subtitle, - ) - val buttonConfig = config.buttonsState - if (buttonConfig is NotificationConfig.ButtonsState.PrimaryButtonConfig) { - PrimaryButtonIconEndTwoLines( - text = buttonConfig.text.resolveReference(), - iconResId = buttonConfig.iconResId ?: R.drawable.ic_tangem_24, - onClick = buttonConfig.onClick, - modifier = Modifier - .fillMaxWidth(), - additionalText = buttonConfig.additionalText?.resolveReference(), - ) - } - } - } -} - -@Composable -private fun BaseContainer(modifier: Modifier = Modifier, content: @Composable BoxScope.() -> Unit) { - Card( - modifier = modifier - .defaultMinSize(minHeight = TangemTheme.dimens.size62) - .fillMaxWidth(), - shape = RoundedCornerShape( - topStart = TangemTheme.dimens.radius16, - topEnd = TangemTheme.dimens.radius16, - ), - elevation = TangemTheme.dimens.elevation12, - backgroundColor = TangemTheme.colors.background.action, - ) { - Box(content = content) - } -} - -@Composable -private fun MainContent(iconResId: Int, iconTint: Color, title: TextReference, subtitle: TextReference) { - Row { - NotificationIcon(iconResId = iconResId, iconTint = iconTint) - SpacerW(width = TangemTheme.dimens.spacing10) - TextsBlock(title = title, subtitle = subtitle) - } -} - -@Composable -private fun RowScope.NotificationIcon(iconResId: Int, iconTint: Color) { - Box( - contentAlignment = Alignment.Center, - modifier = Modifier - .align(alignment = Alignment.CenterVertically), - ) { - Box( - modifier = Modifier - .size(TangemTheme.dimens.size36) - .background( - color = iconTint.copy(alpha = 0.12f), - shape = CircleShape, - ), - ) - Box( - modifier = Modifier - .size(TangemTheme.dimens.size16) - .background( - color = TangemTheme.colors.background.action, - shape = CircleShape, - ), - ) - Icon( - painter = painterResource(id = iconResId), - contentDescription = null, - tint = iconTint, - ) - } -} - -@Composable -private fun TextsBlock(title: TextReference, subtitle: TextReference) { - Column(verticalArrangement = Arrangement.spacedBy(space = TangemTheme.dimens.spacing2)) { - Text( - text = title.resolveReference(), - color = TangemTheme.colors.text.primary1, - style = TangemTheme.typography.button, - ) - - Text( - text = subtitle.resolveReference(), - color = TangemTheme.colors.text.tertiary, - style = TangemTheme.typography.caption2, - ) - } -} - -@Preview -@Preview(uiMode = Configuration.UI_MODE_NIGHT_YES) -@Composable -private fun Preview_ManageTokensScreen() { - TangemThemePreview { - DerivationNotification(DerivationNotificationStatePreviewData.state.config) - } -} \ No newline at end of file diff --git a/features/manage-tokens/impl/src/main/java/com/tangem/managetokens/presentation/managetokens/ui/components/PriceChangesChart.kt b/features/manage-tokens/impl/src/main/java/com/tangem/managetokens/presentation/managetokens/ui/components/PriceChangesChart.kt deleted file mode 100644 index 1a18c5ee93..0000000000 --- a/features/manage-tokens/impl/src/main/java/com/tangem/managetokens/presentation/managetokens/ui/components/PriceChangesChart.kt +++ /dev/null @@ -1,134 +0,0 @@ -package com.tangem.managetokens.presentation.managetokens.ui.components - -import androidx.compose.foundation.Canvas -import androidx.compose.foundation.layout.Row -import androidx.compose.foundation.layout.fillMaxHeight -import androidx.compose.runtime.Composable -import androidx.compose.ui.Modifier -import androidx.compose.ui.geometry.Offset -import androidx.compose.ui.geometry.Size -import androidx.compose.ui.graphics.Brush -import androidx.compose.ui.graphics.Color -import androidx.compose.ui.graphics.Path -import androidx.compose.ui.graphics.drawscope.DrawScope -import androidx.compose.ui.graphics.drawscope.Stroke -import androidx.compose.ui.tooling.preview.Preview -import com.tangem.core.ui.res.TangemTheme -import com.tangem.core.ui.res.TangemThemePreview -import kotlinx.collections.immutable.ImmutableList -import kotlinx.collections.immutable.persistentListOf - -/** - * A chart with a solid line and gradient underneath. It can accept values of any range and number. - * If the last value is bigger or equal to the first, the chart is of accent color, otherwise it's warning color. - * - * @param values a list of float values for a chart. - **/ -@Composable -fun PriceChangesChart(values: ImmutableList, modifier: Modifier = Modifier) { - Row(modifier = modifier) { - if (values.size < 2) return // escape without drawing when there are not enough points - - val lineColor = if (values.last() >= values.first()) { - TangemTheme.colors.icon.accent - } else { - TangemTheme.colors.icon.warning - } - val gradient = Brush.verticalGradient( - colors = listOf(lineColor.copy(alpha = 0.21f), lineColor.copy(alpha = 0.0f)), - ) - Chart(list = values, lineColor = lineColor, gradient = gradient, modifier = Modifier.weight(1f)) - } -} - -@Composable -private fun Chart(list: ImmutableList, lineColor: Color, gradient: Brush, modifier: Modifier = Modifier) { - val max = list.max() - val min = list.min() - val zipList: List> = list.zipWithNext() - - for (pair in zipList) { - val fromValuePercentage = getValuePercentageForRange(pair.first, max, min) - val toValuePercentage = getValuePercentageForRange(pair.second, max, min) - - Canvas( - modifier = modifier.fillMaxHeight(), - onDraw = { - val fromPoint = Offset(x = 0f, y = size.height.times(1 - fromValuePercentage)) - val toPoint = Offset(x = size.width, y = size.height.times(1 - toValuePercentage)) - - val path = drawChartLineAndCreatePath(fromPoint = fromPoint, toPoint = toPoint, lineColor = lineColor) - - fillChart( - path = path, - fromPoint = fromPoint, - toPoint = toPoint, - size = size, - gradient = gradient, - ) - }, - ) - } -} - -private fun DrawScope.drawChartLineAndCreatePath(fromPoint: Offset, toPoint: Offset, lineColor: Color): Path { - val path = Path() - path.moveTo(fromPoint.x, fromPoint.y) - path.lineTo(toPoint.x, toPoint.y) - drawPath( - path = path, - color = lineColor, - style = Stroke(width = 1f), - ) - return path -} - -private fun DrawScope.fillChart(path: Path, fromPoint: Offset, toPoint: Offset, size: Size, gradient: Brush) { - path.lineTo(toPoint.x, size.height) - path.lineTo(fromPoint.x, size.height) - path.lineTo(0f, fromPoint.y) - drawPath( - path = path, - brush = gradient, - ) -} - -private fun getValuePercentageForRange(value: Float, max: Float, min: Float): Float { - return if (max == min) { // to draw a straight line when all values are the same - val modifiedMax = max + 1 - val modifiedMin = min - 1 - (value - modifiedMin) / (modifiedMax - modifiedMin) - } else { - (value - min) / (max - min) - } -} - -@Preview(widthDp = 150, heightDp = 150, showBackground = true) -@Composable -private fun Chart_Positive_Preview() { - TangemThemePreview(isDark = true) { - PriceChangesChart( - persistentListOf(1f, 2f, 4f, 1f, 5f), - ) - } -} - -@Preview(widthDp = 150, heightDp = 150, showBackground = true) -@Composable -private fun Chart_Negative_Preview() { - TangemThemePreview(isDark = true) { - PriceChangesChart( - persistentListOf(10f, 2f, 4f, 1f, 5f), - ) - } -} - -@Preview(widthDp = 150, heightDp = 150, showBackground = true) -@Composable -private fun Chart_Neutral_Preview() { - TangemThemePreview(isDark = true) { - PriceChangesChart( - persistentListOf(5f, 2f, 4f, 1f, 5f), - ) - } -} \ No newline at end of file diff --git a/features/manage-tokens/impl/src/main/java/com/tangem/managetokens/presentation/managetokens/ui/components/SearchBar.kt b/features/manage-tokens/impl/src/main/java/com/tangem/managetokens/presentation/managetokens/ui/components/SearchBar.kt deleted file mode 100644 index 8faf911ebb..0000000000 --- a/features/manage-tokens/impl/src/main/java/com/tangem/managetokens/presentation/managetokens/ui/components/SearchBar.kt +++ /dev/null @@ -1,138 +0,0 @@ -package com.tangem.managetokens.presentation.managetokens.ui.components - -import android.content.res.Configuration -import androidx.compose.foundation.clickable -import androidx.compose.foundation.layout.fillMaxWidth -import androidx.compose.foundation.shape.RoundedCornerShape -import androidx.compose.foundation.text.KeyboardActions -import androidx.compose.foundation.text.KeyboardOptions -import androidx.compose.material.* -import androidx.compose.runtime.* -import androidx.compose.ui.ExperimentalComposeUiApi -import androidx.compose.ui.Modifier -import androidx.compose.ui.focus.onFocusChanged -import androidx.compose.ui.graphics.Color -import androidx.compose.ui.platform.LocalFocusManager -import androidx.compose.ui.platform.LocalSoftwareKeyboardController -import androidx.compose.ui.res.painterResource -import androidx.compose.ui.res.stringResource -import androidx.compose.ui.text.input.ImeAction -import androidx.compose.ui.text.input.KeyboardType -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.res.TangemThemePreview -import com.tangem.core.ui.res.TangemTheme -import com.tangem.features.managetokens.impl.R -import com.tangem.managetokens.presentation.managetokens.state.SearchBarState - -@OptIn(ExperimentalComposeUiApi::class) -@Composable -internal fun TokensSearchBar(state: SearchBarState, modifier: Modifier = Modifier) { - val keyboardController = LocalSoftwareKeyboardController.current - val focusManager = LocalFocusManager.current - - TextField( - value = state.query, - onValueChange = state.onQueryChange, - keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.Text, imeAction = ImeAction.Search), - keyboardActions = KeyboardActions( - onSearch = { - keyboardController?.hide() - focusManager.clearFocus() - }, - ), - singleLine = true, - maxLines = 1, - textStyle = TangemTheme.typography.body2.copy( - color = TangemTheme.colors.text.primary1, - ), - leadingIcon = { - Icon( - painter = painterResource(id = R.drawable.ic_search_24), - tint = TangemTheme.colors.icon.informative, - contentDescription = null, - modifier = Modifier.clickable { state.onActiveChange(true) }, - ) - }, - trailingIcon = { - if (state.query.isNotEmpty() || state.active) { - IconButton( - onClick = { - if (state.query.isNotEmpty()) { - state.onQueryChange("") - } - focusManager.clearFocus() - keyboardController?.hide() - state.onActiveChange(false) - }, - ) { - Icon( - painter = painterResource(id = R.drawable.ic_close), - tint = TangemTheme.colors.icon.informative, - contentDescription = null, - ) - } - } - }, - placeholder = { - Text( - text = stringResource(R.string.manage_tokens_search_placeholder), - color = TangemTheme.colors.text.tertiary, - style = TangemTheme.typography.body2, - ) - }, - shape = RoundedCornerShape(TangemTheme.dimens.radius36), - colors = searchbarTextFieldColors(), - modifier = modifier - .fillMaxWidth() - .onFocusChanged { - if (it.isFocused) { - state.onActiveChange(true) - } else { - state.onActiveChange(false) - } - }, - ) -} - -@Composable -private fun searchbarTextFieldColors(): TextFieldColors { - return TextFieldDefaults.textFieldColors( - backgroundColor = TangemTheme.colors.field.primary, - textColor = TangemTheme.colors.text.primary1, - cursorColor = TangemTheme.colors.icon.primary1, - focusedIndicatorColor = Color.Transparent, - unfocusedIndicatorColor = Color.Transparent, - disabledIndicatorColor = Color.Transparent, - ) -} - -@Preview -@Preview(uiMode = Configuration.UI_MODE_NIGHT_YES) -@Composable -private fun Preview_TokensSearchBar( - @PreviewParameter(SearchBarkConfigProvider::class) - state: SearchBarState, -) { - TangemThemePreview { - TokensSearchBar(state) - } -} - -private class SearchBarkConfigProvider : CollectionPreviewParameterProvider( - collection = listOf( - SearchBarState( - query = "BTC", - onQueryChange = {}, - active = true, - onActiveChange = {}, - ), - SearchBarState( - query = "", - onQueryChange = {}, - active = false, - onActiveChange = {}, - ), - ), -) \ No newline at end of file diff --git a/features/manage-tokens/impl/src/main/java/com/tangem/managetokens/presentation/managetokens/ui/components/TokenButton.kt b/features/manage-tokens/impl/src/main/java/com/tangem/managetokens/presentation/managetokens/ui/components/TokenButton.kt deleted file mode 100644 index 3829ec91db..0000000000 --- a/features/manage-tokens/impl/src/main/java/com/tangem/managetokens/presentation/managetokens/ui/components/TokenButton.kt +++ /dev/null @@ -1,85 +0,0 @@ -package com.tangem.managetokens.presentation.managetokens.ui.components - -import android.content.res.Configuration -import androidx.compose.foundation.clickable -import androidx.compose.foundation.interaction.MutableInteractionSource -import androidx.compose.foundation.layout.Box -import androidx.compose.foundation.layout.size -import androidx.compose.material.Icon -import androidx.compose.material.ripple.rememberRipple -import androidx.compose.runtime.Composable -import androidx.compose.runtime.remember -import androidx.compose.ui.Alignment -import androidx.compose.ui.Modifier -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.PreviewParameterProvider -import com.tangem.core.ui.components.buttons.PrimarySmallButton -import com.tangem.core.ui.components.buttons.SecondarySmallButton -import com.tangem.core.ui.components.buttons.SmallButtonConfig -import com.tangem.core.ui.extensions.resourceReference -import com.tangem.core.ui.res.TangemThemePreview -import com.tangem.core.ui.res.TangemTheme -import com.tangem.features.managetokens.impl.R -import com.tangem.managetokens.presentation.managetokens.state.TokenButtonType - -@Composable -internal fun TokenButton(type: TokenButtonType, onClick: () -> Unit, modifier: Modifier = Modifier) { - when (type) { - TokenButtonType.ADD -> PrimarySmallButton( - config = SmallButtonConfig( - text = resourceReference(R.string.manage_tokens_add), - onClick = onClick, - ), - modifier = modifier, - ) - TokenButtonType.EDIT -> SecondarySmallButton( - config = SmallButtonConfig( - text = resourceReference(R.string.manage_tokens_edit), - onClick = onClick, - ), - modifier = modifier, - ) - TokenButtonType.NOT_AVAILABLE -> { - Box( - modifier = modifier - .size(height = TangemTheme.dimens.size24, width = TangemTheme.dimens.size46) - .clickable( - interactionSource = remember { MutableInteractionSource() }, - indication = rememberRipple( - bounded = false, - radius = TangemTheme.dimens.size20, - ), - onClick = onClick, - ), - contentAlignment = Alignment.Center, - ) { - Icon( - modifier = Modifier - .size(TangemTheme.dimens.size20), - painter = painterResource(id = R.drawable.ic_information_24), - tint = TangemTheme.colors.icon.informative, - contentDescription = null, - ) - } - } - } -} - -@Preview(backgroundColor = 0xffffff, showBackground = true) -@Preview(showBackground = true, uiMode = Configuration.UI_MODE_NIGHT_YES) -@Composable -private fun TokenButton_Preview(@PreviewParameter(TokenButtonTypeProvider::class) type: TokenButtonType) { - TangemThemePreview { - TokenButton(type = type, {}) - } -} - -private class TokenButtonTypeProvider : PreviewParameterProvider { - override val values = sequenceOf( - TokenButtonType.ADD, - TokenButtonType.EDIT, - TokenButtonType.NOT_AVAILABLE, - ) -} \ No newline at end of file diff --git a/features/manage-tokens/impl/src/main/java/com/tangem/managetokens/presentation/managetokens/ui/components/TokenIcon.kt b/features/manage-tokens/impl/src/main/java/com/tangem/managetokens/presentation/managetokens/ui/components/TokenIcon.kt deleted file mode 100644 index 262ebcf808..0000000000 --- a/features/manage-tokens/impl/src/main/java/com/tangem/managetokens/presentation/managetokens/ui/components/TokenIcon.kt +++ /dev/null @@ -1,121 +0,0 @@ -package com.tangem.managetokens.presentation.managetokens.ui.components - -import androidx.compose.foundation.background -import androidx.compose.foundation.isSystemInDarkTheme -import androidx.compose.foundation.layout.Box -import androidx.compose.foundation.layout.size -import androidx.compose.foundation.shape.CircleShape -import androidx.compose.material3.Icon -import androidx.compose.runtime.* -import androidx.compose.ui.Alignment -import androidx.compose.ui.Modifier -import androidx.compose.ui.graphics.Color -import androidx.compose.ui.graphics.toArgb -import androidx.compose.ui.platform.LocalContext -import androidx.compose.ui.platform.LocalDensity -import androidx.compose.ui.res.painterResource -import coil.compose.SubcomposeAsyncImage -import coil.request.ImageRequest -import com.tangem.core.ui.components.CircleShimmer -import com.tangem.core.ui.extensions.ImageReference -import com.tangem.core.ui.res.TangemTheme -import com.tangem.core.ui.utils.ImageBackgroundContrastChecker -import com.tangem.features.managetokens.impl.R -import com.tangem.managetokens.presentation.managetokens.state.TokenIconState -import kotlinx.coroutines.launch - -@Composable -internal fun TokenIcon(state: TokenIconState, modifier: Modifier = Modifier) { - val iconModifier = modifier.size(TangemTheme.dimens.size36) - if (state.iconReference != null) { - DefaultCurrencyIcon( - modifier = iconModifier, - iconReference = state.iconReference, - errorIcon = { - PlaceholderIcon( - modifier = iconModifier, - tint = state.placeholderTint, - background = state.placeholderBackground, - ) - }, - ) - } else { - PlaceholderIcon( - modifier = iconModifier, - tint = state.placeholderTint, - background = state.placeholderBackground, - ) - } -} - -@Composable -private fun PlaceholderIcon(tint: Color, background: Color, modifier: Modifier = Modifier) { - Box( - modifier = modifier - .background( - color = background, - shape = CircleShape, - ), - contentAlignment = Alignment.Center, - ) { - Icon( - modifier = Modifier.matchParentSize(), - painter = painterResource(id = R.drawable.ic_custom_token_44), - tint = tint, - contentDescription = null, - ) - } -} - -@Composable -private inline fun DefaultCurrencyIcon( - iconReference: ImageReference, - crossinline errorIcon: @Composable () -> Unit, - modifier: Modifier = Modifier, -) { - var iconBackgroundColor by remember { mutableStateOf(Color.Transparent) } - var isBackgroundColorDefined by remember { mutableStateOf(false) } - val itemBackgroundColor = TangemTheme.colors.background.primary.toArgb() - val isDarkTheme = isSystemInDarkTheme() - val coroutineScope = rememberCoroutineScope() - - val pixelsSize = with(LocalDensity.current) { TangemTheme.dimens.size36.roundToPx() } - - SubcomposeAsyncImage( - modifier = modifier - .background( - color = iconBackgroundColor, - shape = TangemTheme.shapes.roundedCorners8, - ), - model = ImageRequest.Builder(context = LocalContext.current) - .data(iconReference.getReference()) - .size(size = pixelsSize) - .memoryCacheKey(key = iconReference.getReference().toString() + pixelsSize) - .crossfade(enable = true) - .allowHardware(false) - .listener( - onSuccess = { _, result -> - if (!isBackgroundColorDefined && isDarkTheme) { - coroutineScope.launch { - val color = ImageBackgroundContrastChecker( - drawable = result.drawable, - backgroundColor = itemBackgroundColor, - size = pixelsSize, - ).getContrastColor(isDarkTheme = true) - iconBackgroundColor = color - isBackgroundColorDefined = true - } - } - }, - ) - .build(), - loading = { LoadingIcon() }, - error = { errorIcon() }, - contentDescription = null, - ) -} - -@Composable -internal fun LoadingIcon(modifier: Modifier = Modifier) { - CircleShimmer(modifier = modifier) -} \ No newline at end of file diff --git a/features/manage-tokens/impl/src/main/java/com/tangem/managetokens/presentation/managetokens/ui/components/TokenPriceChange.kt b/features/manage-tokens/impl/src/main/java/com/tangem/managetokens/presentation/managetokens/ui/components/TokenPriceChange.kt deleted file mode 100644 index 28b7691794..0000000000 --- a/features/manage-tokens/impl/src/main/java/com/tangem/managetokens/presentation/managetokens/ui/components/TokenPriceChange.kt +++ /dev/null @@ -1,82 +0,0 @@ -package com.tangem.managetokens.presentation.managetokens.ui.components - -import androidx.compose.animation.AnimatedContent -import androidx.compose.foundation.layout.Arrangement -import androidx.compose.foundation.layout.Row -import androidx.compose.material3.Icon -import androidx.compose.material3.Text -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.style.TextOverflow -import com.tangem.core.ui.components.SpacerW4 -import com.tangem.core.ui.components.marketprice.PriceChangeType -import com.tangem.core.ui.res.TangemTheme -import com.tangem.features.managetokens.impl.R -import com.tangem.managetokens.presentation.managetokens.state.QuotesState - -@Composable -internal fun TokenPriceChange(state: QuotesState, modifier: Modifier = Modifier) { - when (state) { - is QuotesState.Content -> - PriceChangeBlock(modifier = modifier, type = state.changeType, text = state.priceChange) - QuotesState.Unknown -> PriceChangeBlock(modifier = modifier) - } -} - -@Composable -private fun PriceChangeBlock(modifier: Modifier = Modifier, type: PriceChangeType? = null, text: String? = null) { - Row( - modifier = modifier, - horizontalArrangement = Arrangement.End, - verticalAlignment = Alignment.CenterVertically, - ) { - PriceChangeIcon(type = type) - SpacerW4() - PriceChangeText(type = type, text = text) - } -} - -@Composable -private fun PriceChangeIcon(type: PriceChangeType?) { - AnimatedContent(targetState = type, label = "Update the price change's arrow") { animatedType -> - animatedType ?: return@AnimatedContent - - Icon( - painter = painterResource( - id = when (animatedType) { - PriceChangeType.UP -> R.drawable.ic_arrow_up_8 - PriceChangeType.DOWN -> R.drawable.ic_arrow_down_8 - PriceChangeType.NEUTRAL -> R.drawable.ic_elipse_8 - }, - ), - tint = when (animatedType) { - PriceChangeType.UP -> TangemTheme.colors.icon.accent - PriceChangeType.DOWN -> TangemTheme.colors.icon.warning - PriceChangeType.NEUTRAL -> TangemTheme.colors.icon.inactive - }, - contentDescription = null, - ) - } -} - -@Composable -private fun PriceChangeText(type: PriceChangeType?, text: String?) { - AnimatedContent(targetState = text, label = "Update the price change's text") { animatedText -> - animatedText ?: return@AnimatedContent - - Text( - text = animatedText, - color = when (type) { - PriceChangeType.UP -> TangemTheme.colors.text.accent - PriceChangeType.DOWN -> TangemTheme.colors.text.warning - PriceChangeType.NEUTRAL -> TangemTheme.colors.text.disabled - null -> TangemTheme.colors.text.primary1 - }, - overflow = TextOverflow.Ellipsis, - maxLines = 1, - style = TangemTheme.typography.body2, - ) - } -} \ No newline at end of file diff --git a/features/manage-tokens/impl/src/main/java/com/tangem/managetokens/presentation/managetokens/ui/components/TokenRowItem.kt b/features/manage-tokens/impl/src/main/java/com/tangem/managetokens/presentation/managetokens/ui/components/TokenRowItem.kt deleted file mode 100644 index 50cf504643..0000000000 --- a/features/manage-tokens/impl/src/main/java/com/tangem/managetokens/presentation/managetokens/ui/components/TokenRowItem.kt +++ /dev/null @@ -1,203 +0,0 @@ -package com.tangem.managetokens.presentation.managetokens.ui.components - -import android.content.res.Configuration -import androidx.compose.foundation.background -import androidx.compose.foundation.layout.* -import androidx.compose.material3.Surface -import androidx.compose.material3.Text -import androidx.compose.runtime.Composable -import androidx.compose.runtime.ReadOnlyComposable -import androidx.compose.ui.Alignment -import androidx.compose.ui.Modifier -import androidx.compose.ui.text.style.TextOverflow -import androidx.compose.ui.tooling.preview.Preview -import androidx.compose.ui.tooling.preview.PreviewParameter -import androidx.compose.ui.tooling.preview.datasource.CollectionPreviewParameterProvider -import androidx.compose.ui.unit.Dp -import com.tangem.core.ui.components.* -import com.tangem.core.ui.res.TangemThemePreview -import com.tangem.core.ui.res.TangemTheme -import com.tangem.managetokens.presentation.managetokens.state.QuotesState -import com.tangem.managetokens.presentation.managetokens.state.TokenItemState -import com.tangem.managetokens.presentation.managetokens.state.previewdata.TokenItemStatePreviewData - -private val TOKEN_ITEM_HEIGHT: Dp - @Composable - @ReadOnlyComposable - get() = TangemTheme.dimens.size68 - -@Composable -internal fun TokenRowItem(state: TokenItemState, modifier: Modifier = Modifier) { - when (state) { - is TokenItemState.Loading -> LoadingTokenItem(modifier) - is TokenItemState.Loaded -> LoadedTokenItem(state, modifier) - } -} - -@Composable -private fun LoadedTokenItem(state: TokenItemState.Loaded, modifier: Modifier = Modifier) { - BoxWithConstraints( - modifier = modifier - .fillMaxWidth() - .defaultMinSize(minHeight = TOKEN_ITEM_HEIGHT) - .background(TangemTheme.colors.background.primary), - contentAlignment = Alignment.CenterStart, - ) { - val width = maxWidth - - Row( - verticalAlignment = Alignment.CenterVertically, - modifier = Modifier.padding(horizontal = TangemTheme.dimens.spacing16), - ) { - TokenIcon(state = state.tokenIcon) - SpacerW12() - - Column( - modifier = Modifier - .weight(weight = 1f), - ) { - TokenName(name = state.name, currencyId = state.currencySymbol) - TokenPriceData(price = state.rate, quotesState = state.quotes) - } - SpacerW24() - - if (width > TangemTheme.dimens.size350 && // hide chart for small screens - state.quotes is QuotesState.Content - ) { - Chart(quotes = state.quotes) - SpacerW24() - } - - TokenButton( - type = state.availableAction.value, - onClick = { state.onButtonClick(state) }, - ) - } - } -} - -@Composable -private fun TokenName(name: String, currencyId: String) { - Row { - Text( - text = name, - color = TangemTheme.colors.text.primary1, - style = TangemTheme.typography.subtitle2, - maxLines = 1, - overflow = TextOverflow.Ellipsis, - modifier = Modifier - .weight(weight = 1f, fill = false), - ) - SpacerW(width = TangemTheme.dimens.spacing6) - Text( - text = currencyId, - color = TangemTheme.colors.text.tertiary, - style = TangemTheme.typography.body2, - maxLines = 1, - overflow = TextOverflow.Ellipsis, - ) - } -} - -@Composable -private fun TokenPriceData(price: String?, quotesState: QuotesState) { - if (price != null) { - Row { - Text( - text = price, - color = TangemTheme.colors.text.tertiary, - style = TangemTheme.typography.body2, - maxLines = 1, - overflow = TextOverflow.Ellipsis, - modifier = Modifier - .weight(weight = 1f, fill = false), - ) - SpacerW(width = TangemTheme.dimens.spacing6) - TokenPriceChange(state = quotesState) - } - } -} - -@Composable -private fun Chart(quotes: QuotesState.Content) { - Box( - modifier = Modifier - .size(width = TangemTheme.dimens.size50, height = TangemTheme.dimens.size28), - ) { - PriceChangesChart(values = quotes.chartData) - } -} - -@Composable -private fun LoadingTokenItem(modifier: Modifier = Modifier) { - BaseSurface(modifier) { - Row( - modifier = Modifier - .fillMaxWidth() - .padding( - horizontal = TangemTheme.dimens.spacing16, - vertical = TangemTheme.dimens.spacing4, - ), - verticalAlignment = Alignment.CenterVertically, - horizontalArrangement = Arrangement.spacedBy(TangemTheme.dimens.spacing12), - ) { - CircleShimmer(modifier = Modifier.size(size = TangemTheme.dimens.size36)) - Row( - modifier = Modifier.fillMaxWidth(), - verticalAlignment = Alignment.CenterVertically, - horizontalArrangement = Arrangement.SpaceBetween, - ) { - Column(verticalArrangement = Arrangement.spacedBy(TangemTheme.dimens.spacing10)) { - RectangleShimmer( - modifier = Modifier.size( - width = TangemTheme.dimens.size70, - height = TangemTheme.dimens.size12, - ), - ) - RectangleShimmer( - modifier = Modifier.size( - width = TangemTheme.dimens.size52, - height = TangemTheme.dimens.size12, - ), - ) - } - RectangleShimmer( - modifier = Modifier.size( - width = TangemTheme.dimens.size46, - height = TangemTheme.dimens.size12, - ), - ) - } - } - } -} - -@Composable -private fun BaseSurface(modifier: Modifier = Modifier, content: @Composable () -> Unit) { - Surface( - modifier = modifier.defaultMinSize(minHeight = TOKEN_ITEM_HEIGHT), - color = TangemTheme.colors.background.primary, - ) { - content() - } -} - -// region Preview -@Preview(showBackground = true, widthDp = 360) -@Preview(showBackground = true, widthDp = 360, uiMode = Configuration.UI_MODE_NIGHT_YES) -@Composable -private fun Preview_Tokens(@PreviewParameter(TokenConfigProvider::class) state: TokenItemState) { - TangemThemePreview { - TokenRowItem(state) - } -} - -private class TokenConfigProvider : CollectionPreviewParameterProvider( - collection = listOf( - TokenItemStatePreviewData.tokenLoading, - TokenItemStatePreviewData.loadedPriceDown, - TokenItemStatePreviewData.loadedPriceUp, - TokenItemStatePreviewData.loadedPriceNeutral, - ), -) -// endregion Preview \ No newline at end of file diff --git a/features/manage-tokens/impl/src/main/java/com/tangem/managetokens/presentation/managetokens/ui/components/TokensList.kt b/features/manage-tokens/impl/src/main/java/com/tangem/managetokens/presentation/managetokens/ui/components/TokensList.kt deleted file mode 100644 index ca26ef0621..0000000000 --- a/features/manage-tokens/impl/src/main/java/com/tangem/managetokens/presentation/managetokens/ui/components/TokensList.kt +++ /dev/null @@ -1,67 +0,0 @@ -package com.tangem.managetokens.presentation.managetokens.ui.components - -import androidx.compose.foundation.layout.padding -import androidx.compose.foundation.lazy.LazyColumn -import androidx.compose.foundation.lazy.items -import androidx.compose.material3.Text -import androidx.compose.runtime.Composable -import androidx.compose.ui.Modifier -import androidx.compose.ui.res.stringResource -import androidx.paging.LoadState -import androidx.paging.compose.LazyPagingItems -import com.tangem.core.ui.res.TangemTheme -import com.tangem.features.managetokens.impl.R -import com.tangem.managetokens.presentation.managetokens.state.AddCustomTokenButton -import com.tangem.managetokens.presentation.managetokens.state.TokenItemState - -private const val PLACEHOLDER_ITEMS_COUNT = 50 - -@Composable -internal fun TokensList( - tokens: LazyPagingItems, - addCustomTokenButton: AddCustomTokenButton, - modifier: Modifier = Modifier, -) { - LazyColumn(modifier = modifier) { - item { - Text( - text = stringResource(id = R.string.manage_tokens_list_header_title), - style = TangemTheme.typography.h3, - color = TangemTheme.colors.text.primary1, - modifier = Modifier.padding(horizontal = TangemTheme.dimens.spacing16), - ) - } - - if (tokens.loadState.refresh is LoadState.Loading) { - items(PLACEHOLDER_ITEMS_COUNT) { - TokenRowItem(state = TokenItemState.Loading(it.toString())) - } - } else { - val tokensList = tokens.itemSnapshotList - if (tokensList.isEmpty()) { - item { - Text( - text = stringResource(id = R.string.manage_tokens_nothing_found), - style = TangemTheme.typography.caption2, - color = TangemTheme.colors.text.tertiary, - modifier = Modifier.padding( - top = TangemTheme.dimens.spacing8, - start = TangemTheme.dimens.spacing16, - end = TangemTheme.dimens.spacing16, - ), - ) - } - } - - items(items = tokensList.items, key = TokenItemState::id) { token -> - TokenRowItem(state = token) - } - - if (addCustomTokenButton.isVisible) { - item { - AddCustomTokenButton(onButtonClick = addCustomTokenButton.onClick) - } - } - } - } -} \ No newline at end of file diff --git a/features/manage-tokens/impl/src/main/java/com/tangem/managetokens/presentation/managetokens/viewmodels/ManageTokensClickIntents.kt b/features/manage-tokens/impl/src/main/java/com/tangem/managetokens/presentation/managetokens/viewmodels/ManageTokensClickIntents.kt deleted file mode 100644 index 2b6ba5b3bd..0000000000 --- a/features/manage-tokens/impl/src/main/java/com/tangem/managetokens/presentation/managetokens/viewmodels/ManageTokensClickIntents.kt +++ /dev/null @@ -1,31 +0,0 @@ -package com.tangem.managetokens.presentation.managetokens.viewmodels - -import com.tangem.managetokens.presentation.common.state.NetworkItemState -import com.tangem.managetokens.presentation.managetokens.state.TokenItemState - -internal interface ManageTokensClickIntents { - - fun onAddCustomTokensButtonClick() - - fun onSearchQueryChange(query: String) - - fun onSearchActiveChange(active: Boolean) - - fun onTokenItemButtonClick(token: TokenItemState.Loaded) - - fun onGetAddressesClick() - - fun onBackClick() - - fun onCloseChooseNetworkScreen() - - fun onNetworkToggleClick(token: TokenItemState.Loaded, network: NetworkItemState.Toggleable) - - fun onNonNativeNetworkHintClick() - - fun onChooseWalletClick() - - fun onCloseChoosingWalletClick() - - fun onWalletSelected(walletId: String) -} \ No newline at end of file diff --git a/features/manage-tokens/impl/src/main/java/com/tangem/managetokens/presentation/managetokens/viewmodels/ManageTokensUiEvents.kt b/features/manage-tokens/impl/src/main/java/com/tangem/managetokens/presentation/managetokens/viewmodels/ManageTokensUiEvents.kt deleted file mode 100644 index 663871cf2a..0000000000 --- a/features/manage-tokens/impl/src/main/java/com/tangem/managetokens/presentation/managetokens/viewmodels/ManageTokensUiEvents.kt +++ /dev/null @@ -1,8 +0,0 @@ -package com.tangem.managetokens.presentation.managetokens.viewmodels - -internal interface ManageTokensUiEvents { - - fun onEmptySearchResult(query: String) - - fun onAddCustomTokenSheetDismissed() -} \ No newline at end of file diff --git a/features/manage-tokens/impl/src/main/java/com/tangem/managetokens/presentation/managetokens/viewmodels/ManageTokensViewModel.kt b/features/manage-tokens/impl/src/main/java/com/tangem/managetokens/presentation/managetokens/viewmodels/ManageTokensViewModel.kt deleted file mode 100644 index caa5ca105b..0000000000 --- a/features/manage-tokens/impl/src/main/java/com/tangem/managetokens/presentation/managetokens/viewmodels/ManageTokensViewModel.kt +++ /dev/null @@ -1,445 +0,0 @@ -package com.tangem.managetokens.presentation.managetokens.viewmodels - -import androidx.compose.runtime.* -import androidx.lifecycle.ViewModel -import androidx.lifecycle.viewModelScope -import androidx.paging.PagingData -import androidx.paging.map -import arrow.core.getOrElse -import com.tangem.core.analytics.api.AnalyticsEventHandler -import com.tangem.core.analytics.models.AnalyticsParam -import com.tangem.domain.appcurrency.GetSelectedAppCurrencyUseCase -import com.tangem.domain.appcurrency.model.AppCurrency -import com.tangem.domain.card.DerivePublicKeysUseCase -import com.tangem.domain.common.util.derivationStyleProvider -import com.tangem.domain.tokens.* -import com.tangem.domain.tokens.model.CryptoCurrency -import com.tangem.domain.wallets.models.UserWallet -import com.tangem.domain.wallets.models.UserWalletId -import com.tangem.domain.wallets.usecase.GetSelectedWalletSyncUseCase -import com.tangem.domain.wallets.usecase.GetWalletsUseCase -import com.tangem.domain.wallets.usecase.SelectWalletUseCase -import com.tangem.features.managetokens.navigation.ExpandableState -import com.tangem.managetokens.presentation.common.analytics.ManageTokens -import com.tangem.managetokens.presentation.common.state.AlertState -import com.tangem.managetokens.presentation.common.state.Event -import com.tangem.managetokens.presentation.common.state.NetworkItemState -import com.tangem.managetokens.presentation.managetokens.state.ManageTokensState -import com.tangem.managetokens.presentation.managetokens.state.TokenButtonType -import com.tangem.managetokens.presentation.managetokens.state.TokenItemState -import com.tangem.managetokens.presentation.managetokens.state.factory.* -import com.tangem.utils.Provider -import com.tangem.utils.coroutines.CoroutineDispatcherProvider -import com.tangem.utils.coroutines.Debouncer -import com.tangem.utils.coroutines.Debouncer.Companion.DEFAULT_WAIT_TIME_MS -import com.tangem.utils.coroutines.JobHolder -import com.tangem.utils.coroutines.saveIn -import dagger.hilt.android.lifecycle.HiltViewModel -import kotlinx.coroutines.* -import kotlinx.coroutines.flow.* -import timber.log.Timber -import java.util.Collections -import java.util.concurrent.ConcurrentHashMap -import java.util.concurrent.CopyOnWriteArrayList -import javax.inject.Inject -import kotlin.collections.set -import kotlin.properties.Delegates - -@Suppress("LongParameterList", "LargeClass") -@HiltViewModel -internal class ManageTokensViewModel @Inject constructor( - private val dispatchers: CoroutineDispatcherProvider, - private val getGlobalTokenListUseCase: GetGlobalTokenListUseCase, - private val getWalletsUseCase: GetWalletsUseCase, - private val getSelectedWalletSyncUseCase: GetSelectedWalletSyncUseCase, - private val removeCurrencyUseCase: RemoveCurrencyUseCase, - private val addCryptoCurrenciesUseCase: AddCryptoCurrenciesUseCase, - private val selectWalletUseCase: SelectWalletUseCase, - private val getCurrenciesUseCase: GetCryptoCurrenciesUseCase, - private val derivePublicKeysUseCase: DerivePublicKeysUseCase, - private val getMissedAddressesCryptoCurrenciesUseCase: GetMissedAddressesCryptoCurrenciesUseCase, - private val fetchTokenListUseCase: FetchTokenListUseCase, - private val getSelectedAppCurrencyUseCase: GetSelectedAppCurrencyUseCase, - private val checkCurrencyCompatibilityUseCase: CheckCurrencyCompatibilityUseCase, - private val isCryptoCurrencyCoinCouldHide: IsCryptoCurrencyCoinCouldHideUseCase, - private val analyticsEventHandler: AnalyticsEventHandler, -) : ViewModel(), ManageTokensClickIntents, ManageTokensUiEvents { - - private val stateFactory = ManageTokensStateFactory( - currentStateProvider = Provider { uiState }, - clickIntents = this, - uiIntents = this, - ) - - var uiState: ManageTokensState by mutableStateOf(stateFactory.getInitialState(flowOf(PagingData.from(emptyList())))) - private set - - private var expandableState: ExpandableState = ExpandableState.COLLAPSED - - private val currenciesListJobHolder: JobHolder = JobHolder() - - private val debouncer = Debouncer() - - private var allAddedCurrencies: MutableList = Collections.synchronizedList( - mutableListOf(), - ) - - private var wallets: CopyOnWriteArrayList by Delegates.notNull() - - private var addedCurrenciesByWallet: MutableMap> = ConcurrentHashMap() - - private var selectedWallet: UserWallet? = null - - private var currenciesToGenerateAddresses: Map> = emptyMap() - - private val selectedAppCurrencyFlow: StateFlow = createSelectedAppCurrencyFlow() - - private val quotesStateConverter = QuotesToQuotesStateConverter() - - private val networkToNetworkItemStateConverter = NetworkToNetworkItemStateConverter( - addedCurrenciesByWalletProvider = Provider { addedCurrenciesByWallet }, - selectedWalletProvider = Provider { selectedWallet }, - onNetworkToggleClick = this::onNetworkToggleClick, - ) - - private val networksToChooseNetworkStateConverter = NetworksToChooseNetworkStateConverter( - networkToNetworkItemStateConverter = networkToNetworkItemStateConverter, - onNonNativeNetworkHintClick = this::onNonNativeNetworkHintClick, - onCloseChooseNetworkScreen = this::onCloseChooseNetworkScreen, - ) - - private val tokenConverter = TokenConverter( - quotesStateConverter = quotesStateConverter, - networksToChooseNetworkStateConverter = networksToChooseNetworkStateConverter, - allAddedCurrencies = Provider { allAddedCurrencies }, - selectedAppCurrency = Provider { selectedAppCurrencyFlow.value }, - onTokenItemButtonClick = this::onTokenItemButtonClick, - ) - - init { - analyticsEventHandler.send(ManageTokens.ScreenOpened()) - - viewModelScope.launch(dispatchers.io) { - getWalletsUseCase() - .distinctUntilChanged() - .collectLatest { userWallets -> - launch { - subscribeToCurrencies(userWallets) - }.saveIn(currenciesListJobHolder) - } - } - } - - fun setExpandableState(state: State) { - expandableState = state.value - } - - private suspend fun subscribeToCurrencies(userWallets: List) { - wallets = CopyOnWriteArrayList(userWallets.filter { it.isMultiCurrency && !it.isLocked }) - - combine(wallets.map { getCurrenciesUseCase.invoke(it.walletId).distinctUntilChanged() }) { - if (expandableState == ExpandableState.EXPANDED) return@combine - - allAddedCurrencies.clear() - addedCurrenciesByWallet.clear() - - val walletsWithCurrencies = wallets.zip( - it.map { currencyList -> - currencyList.getOrElse { - Timber.e("Couldn't retrieve currency list") - emptyList() - } - }, - ) - - allAddedCurrencies = walletsWithCurrencies.flatMap { it.second }.toMutableList() - - walletsWithCurrencies.forEach { (wallet, currencies) -> - addedCurrenciesByWallet[wallet] = currencies.toMutableList() - } - - withContext(dispatchers.main) { - uiState = uiState.copy(tokens = getInitialTokensList()) - } - selectedWallet = getSelectedWalletSyncUseCase().fold( - ifLeft = { null }, - ifRight = { if (!it.isMultiCurrency || it.isLocked) null else it }, - ) - if (selectedWallet == null && wallets.isNotEmpty()) { - selectWalletUseCase(wallets.first().walletId) - selectedWallet = wallets.first() - } - updateDerivationNotificationState() - withContext(dispatchers.main) { - uiState = stateFactory.updateChooseWalletState(wallets, userWallets, selectedWallet) - } - }.collect() - } - - private fun getInitialTokensList(searchText: String = ""): Flow> { - return getGlobalTokenListUseCase(searchText = searchText).map { - it.map { token -> tokenConverter.convert(token) } - } - } - - private fun updateDerivationNotificationState() { - viewModelScope.launch(dispatchers.io) { - getMissedAddressesCryptoCurrenciesUseCase(wallets.map { it.walletId }) - .distinctUntilChanged() - .collectLatest { - it.onRight { mapOfMissingDerivations -> - currenciesToGenerateAddresses = mapOfMissingDerivations - withContext(dispatchers.main) { updateDerivation() } - } - } - } - } - - private fun updateDerivation() { - val totalNeeded = currenciesToGenerateAddresses.values.sumOf { derivations -> derivations.size } - val walletsToDerive = currenciesToGenerateAddresses.values - .filter { derivations -> derivations.isNotEmpty() }.size - uiState = stateFactory.updateDerivationNotification( - totalNeeded = totalNeeded, - totalWallets = wallets.size, - walletsToDerive = walletsToDerive, - ) - } - - private fun createSelectedAppCurrencyFlow(): StateFlow { - return getSelectedAppCurrencyUseCase() - .map { maybeAppCurrency -> - maybeAppCurrency.getOrElse { AppCurrency.Default } - } - .stateIn( - scope = viewModelScope, - started = SharingStarted.Eagerly, - initialValue = AppCurrency.Default, - ) - } - - override fun onAddCustomTokensButtonClick() { - analyticsEventHandler.send(ManageTokens.ButtonCustomToken) - uiState = uiState.copy(customTokenBottomSheetConfig = uiState.customTokenBottomSheetConfig.copy(isShow = true)) - } - - override fun onSearchQueryChange(query: String) { - uiState = uiState.copy(searchBarState = uiState.searchBarState.copy(query = query)) - - debouncer.debounce(waitMs = DEFAULT_WAIT_TIME_MS, coroutineScope = viewModelScope + dispatchers.io) { - val state = stateFactory.showAddCustomTokensButton(query.isNotBlank()) - uiState = state.copy(tokens = getInitialTokensList(query)) - } - } - - override fun onSearchActiveChange(active: Boolean) { - uiState = uiState.copy(searchBarState = uiState.searchBarState.copy(active = active)) - } - - override fun onTokenItemButtonClick(token: TokenItemState.Loaded) { - when (token.availableAction.value) { - TokenButtonType.ADD, TokenButtonType.EDIT -> { - if (token.availableAction.value == TokenButtonType.ADD) { - analyticsEventHandler.send(ManageTokens.ButtonAdd(token.currencySymbol)) - } - if (token.availableAction.value == TokenButtonType.EDIT) { - analyticsEventHandler.send(ManageTokens.ButtonEdit(token.currencySymbol)) - } - - uiState = uiState.copy(selectedToken = token) - val addedCurrenciesOnWallet = addedCurrenciesByWallet[selectedWallet] ?: listOf() - stateFactory.updateTokenNetworksOnTokenSelection(token, addedCurrenciesOnWallet) - } - TokenButtonType.NOT_AVAILABLE -> { - uiState = stateFactory.getStateAndTriggerEvent( - state = uiState, - event = Event.ShowAlert( - AlertState.TokenUnavailable( - onUpvoteClick = {}, // TODO later, when endpoint is available - ), - ), - setUiState = { uiState = it }, - ) - } - } - } - - override fun onGetAddressesClick() { - if (currenciesToGenerateAddresses.isNotEmpty()) { - viewModelScope.launch(dispatchers.io) { - val cardCount = currenciesToGenerateAddresses.count { it.value.isNotEmpty() } - analyticsEventHandler.send(ManageTokens.ButtonGenerateAddresses(cardCount)) - - currenciesToGenerateAddresses.forEach { (walletId, currenciesToDerive) -> - if (currenciesToDerive.isNotEmpty()) { - derivePublicKeysUseCase(walletId, currenciesToDerive) - .onRight { - updateDerivationNotificationState() - fetchTokenListUseCase(userWalletId = walletId) - } - } - } - } - } - } - - override fun onBackClick() { - TODO("Not yet implemented") // TODO: implement if needed when custom tokens and bottom sheet is complete - } - - override fun onCloseChooseNetworkScreen() { - uiState = uiState.copy(selectedToken = null) - } - - override fun onNetworkToggleClick(token: TokenItemState.Loaded, network: NetworkItemState.Toggleable) { - val selectedWallet = selectedWallet ?: return - if (!selectedWallet.isMultiCurrency || selectedWallet.isLocked) return - - if (network.isAdded.value) { - analyticsEventHandler.send( - ManageTokens.TokenSwitcherChanged(token = token.currencySymbol, AnalyticsParam.OnOffState.Off), - ) - toggleToken(token, network, selectedWallet) - } else { - analyticsEventHandler.send( - ManageTokens.TokenSwitcherChanged(token = token.currencySymbol, AnalyticsParam.OnOffState.On), - ) - viewModelScope.launch(dispatchers.io) { - checkCompatibilityAndToggleToken(token, network, selectedWallet) - } - } - } - - private suspend fun checkCompatibilityAndToggleToken( - token: TokenItemState.Loaded, - network: NetworkItemState.Toggleable, - selectedWallet: UserWallet, - ) { - checkCurrencyCompatibilityUseCase( - networkId = network.id, - isMainNetwork = network.address == null, - userWalletId = selectedWallet.walletId, - ) - .fold( - ifLeft = { error -> - uiState = stateFactory.getStateAndTriggerEvent( - state = uiState, - event = Event.ShowAlert( - stateFactory.transformAddTokenErrorToAlert( - error, - network.name, - ), - ), - setUiState = { uiState = it }, - ) - }, - ifRight = { - withContext(dispatchers.main) { toggleToken(token, network, selectedWallet) } - }, - ) - } - - private fun toggleToken( - token: TokenItemState.Loaded, - network: NetworkItemState.Toggleable, - selectedWallet: UserWallet, - ) { - val cryptoCurrency = requireNotNull( - TokenToCryptoCurrencyConverter( - network = network, - derivationStyleProvider = selectedWallet.scanResponse.derivationStyleProvider, - ).convert(token), - ) { - "It is only null if Blockchain is Unknown, which mustn't happen here" - } - if (!network.isAdded.value) { - addedCurrenciesByWallet[selectedWallet]?.add(cryptoCurrency) - allAddedCurrencies.add(cryptoCurrency) - viewModelScope.launch(dispatchers.io) { - addCryptoCurrenciesUseCase( - userWalletId = selectedWallet.walletId, - currency = cryptoCurrency, - ) - } - updateUi(token, network) - } else { - viewModelScope.launch(dispatchers.io) { - if (canBeRemovedAndShowAlertIfNot(selectedWallet.walletId, cryptoCurrency)) { - addedCurrenciesByWallet[selectedWallet]?.remove(cryptoCurrency) - allAddedCurrencies.remove(cryptoCurrency) - removeCurrencyUseCase(selectedWallet.walletId, cryptoCurrency) - withContext(dispatchers.main) { updateUi(token, network) } - } - } - } - } - - private fun updateUi(token: TokenItemState.Loaded, network: NetworkItemState.Toggleable) { - stateFactory.toggleNetworkState(token, network, allAddedCurrencies) - updateDerivationNotificationState() - } - - private suspend fun canBeRemovedAndShowAlertIfNot( - walletId: UserWalletId, - cryptoCurrency: CryptoCurrency, - ): Boolean { - return if (cryptoCurrency is CryptoCurrency.Coin && - !isCryptoCurrencyCoinCouldHide(walletId, cryptoCurrency) - ) { - uiState = stateFactory.getStateAndTriggerEvent( - state = uiState, - event = Event.ShowAlert( - AlertState.CannotHideNetworkWithTokens( - tokenName = cryptoCurrency.name, - currencySymbol = cryptoCurrency.symbol, - networkName = cryptoCurrency.network.name, - ), - ), - setUiState = { uiState = it }, - ) - false - } else { - true - } - } - - override fun onNonNativeNetworkHintClick() { - analyticsEventHandler.send(ManageTokens.NoticeNonNativeNetworkClicked) - uiState = stateFactory.getStateAndTriggerEvent( - state = uiState, - event = Event.ShowAlert(AlertState.NonNative), - setUiState = { uiState = it }, - ) - } - - override fun onChooseWalletClick() { - analyticsEventHandler.send(ManageTokens.ButtonChooseWallet) - uiState = uiState.copy( - showChooseWalletScreen = true, - ) - } - - override fun onCloseChoosingWalletClick() { - uiState = uiState.copy( - showChooseWalletScreen = false, - ) - } - - override fun onWalletSelected(walletId: String) { - analyticsEventHandler.send(ManageTokens.WalletSelected(ManageTokens.WalletSelected.Source.MainToken)) - viewModelScope.launch(dispatchers.io) { - selectWalletUseCase(UserWalletId(walletId)) - } - selectedWallet = wallets.find { it.walletId.stringValue == walletId } - uiState.selectedToken?.let { onTokenItemButtonClick(it) } - uiState = stateFactory.updateSelectedWallet(selectedWalletId = selectedWallet?.walletId?.stringValue) - } - - override fun onEmptySearchResult(query: String) { - analyticsEventHandler.send(ManageTokens.TokenIsNotFound(query)) - } - - override fun onAddCustomTokenSheetDismissed() { - uiState = uiState.copy(customTokenBottomSheetConfig = uiState.customTokenBottomSheetConfig.copy(isShow = false)) - } -} \ No newline at end of file diff --git a/features/manage-tokens/impl/src/main/java/com/tangem/managetokens/presentation/router/ManageTokensUiImpl.kt b/features/manage-tokens/impl/src/main/java/com/tangem/managetokens/presentation/router/ManageTokensUiImpl.kt deleted file mode 100644 index 9bcf70872f..0000000000 --- a/features/manage-tokens/impl/src/main/java/com/tangem/managetokens/presentation/router/ManageTokensUiImpl.kt +++ /dev/null @@ -1,25 +0,0 @@ -package com.tangem.managetokens.presentation.router - -import androidx.compose.runtime.Composable -import androidx.compose.runtime.State -import androidx.compose.ui.unit.Dp -import androidx.hilt.navigation.compose.hiltViewModel -import com.tangem.features.managetokens.navigation.ExpandableState -import com.tangem.features.managetokens.navigation.ManageTokensUi -import com.tangem.managetokens.presentation.managetokens.ui.ManageTokensScreen -import com.tangem.managetokens.presentation.managetokens.viewmodels.ManageTokensViewModel -import javax.inject.Inject - -internal class ManageTokensUiImpl @Inject constructor() : ManageTokensUi { - - @Composable - override fun Content(onHeaderSizeChange: (Dp) -> Unit, state: State) { - val viewModel = hiltViewModel() - viewModel.setExpandableState(state) - - ManageTokensScreen( - state = viewModel.uiState, - onHeaderSizeChange = onHeaderSizeChange, - ) - } -} \ No newline at end of file diff --git a/features/manage-tokens/impl/src/main/kotlin/com/tangem/features/managetokens/component/preview/PreviewManageTokensComponent.kt b/features/manage-tokens/impl/src/main/kotlin/com/tangem/features/managetokens/component/preview/PreviewManageTokensComponent.kt new file mode 100644 index 0000000000..8fabf7cfd4 --- /dev/null +++ b/features/manage-tokens/impl/src/main/kotlin/com/tangem/features/managetokens/component/preview/PreviewManageTokensComponent.kt @@ -0,0 +1,212 @@ +package com.tangem.features.managetokens.component.preview + +import androidx.compose.runtime.Composable +import androidx.compose.runtime.collectAsState +import androidx.compose.runtime.getValue +import androidx.compose.ui.Modifier +import androidx.compose.ui.graphics.Color +import androidx.compose.ui.util.fastForEachIndexed +import com.tangem.core.ui.components.currency.icon.CurrencyIconState +import com.tangem.core.ui.components.fields.entity.SearchBarUM +import com.tangem.core.ui.components.rows.model.BlockchainRowUM +import com.tangem.core.ui.components.rows.model.ChainRowUM +import com.tangem.core.ui.extensions.resourceReference +import com.tangem.features.managetokens.component.ManageTokensComponent +import com.tangem.features.managetokens.entity.CurrencyItemUM +import com.tangem.features.managetokens.entity.CurrencyNetworkUM +import com.tangem.features.managetokens.entity.ManageTokensUM +import com.tangem.features.managetokens.impl.R +import com.tangem.features.managetokens.ui.ManageTokensScreen +import kotlinx.collections.immutable.mutate +import kotlinx.collections.immutable.toImmutableList +import kotlinx.collections.immutable.toPersistentList +import kotlinx.coroutines.flow.MutableStateFlow +import kotlinx.coroutines.flow.update + +internal class PreviewManageTokensComponent : ManageTokensComponent { + + private val changedItemsIds: MutableSet = mutableSetOf() + + private var items = initItems() + + private val previewState = MutableStateFlow( + value = ManageTokensUM( + popBack = {}, + items = items, + search = SearchBarUM( + placeholderText = resourceReference(R.string.manage_tokens_search_placeholder), + query = "", + onQueryChange = ::searchCurrencies, + isActive = false, + onActiveChange = ::toggleSearchBar, + ), + hasChanges = false, + onSaveClick = {}, + onAddCustomToken = {}, + ), + ) + + private fun searchCurrencies(query: String) { + previewState.update { state -> + items = if (query.isBlank()) { + initItems() + } else { + items.filter { currency -> + currency.model.name.contains(query, ignoreCase = true) + }.toPersistentList() + } + + state.copy( + search = state.search.copy(query = query), + items = items, + ) + } + } + + private fun toggleSearchBar(isActive: Boolean) { + previewState.update { state -> + state.copy( + search = state.search.copy(isActive = isActive), + ) + } + } + + @Composable + override fun Content(modifier: Modifier) { + val state by previewState.collectAsState() + + ManageTokensScreen( + modifier = modifier, + state = state, + ) + } + + private fun initItems() = List(size = 30) { index -> + if (index < 2) { + getCustomItem(index) + } else { + getBasicItem(index) + } + }.toPersistentList() + + private fun getCustomItem(index: Int) = CurrencyItemUM.Custom( + id = index.toString(), + model = ChainRowUM( + name = "Custom token $index", + type = "CT$index", + icon = CurrencyIconState.CustomTokenIcon( + tint = Color.White, + background = Color.Black, + topBadgeIconResId = R.drawable.img_eth_22, + isGrayscale = false, + showCustomBadge = true, + ), + showCustom = true, + ), + onRemoveClick = {}, + ) + + private fun getBasicItem(index: Int) = CurrencyItemUM.Basic( + id = index.toString(), + model = ChainRowUM( + name = "Currency $index", + type = "C$index", + icon = CurrencyIconState.CoinIcon( + url = null, + fallbackResId = R.drawable.img_btc_22, + isGrayscale = false, + showCustomBadge = false, + ), + showCustom = false, + ), + networks = if (index == 2) { + CurrencyItemUM.Basic.NetworksUM.Expanded(getCurrencyNetworks(index)) + } else { + CurrencyItemUM.Basic.NetworksUM.Collapsed + }, + onExpandClick = { toggleCurrency(index) }, + ) + + private fun getCurrencyNetworks(currencyIndex: Int) = List(size = 3) { networkIndex -> + CurrencyNetworkUM( + id = networkIndex.toString(), + model = BlockchainRowUM( + name = "NETWORK$networkIndex", + type = "N$networkIndex", + iconResId = R.drawable.ic_eth_16, + isMainNetwork = networkIndex == 0, + isSelected = false, + ), + isSelected = false, + onSelectedStateChange = { toggleNetwork(currencyIndex, networkIndex, isSelected = it) }, + ) + }.toImmutableList() + + private fun toggleCurrency(index: Int) { + val updatedItem = when (val item = items[index]) { + is CurrencyItemUM.Basic -> item.copy( + networks = if (item.networks is CurrencyItemUM.Basic.NetworksUM.Collapsed) { + CurrencyItemUM.Basic.NetworksUM.Expanded(getCurrencyNetworks(index)) + } else { + CurrencyItemUM.Basic.NetworksUM.Collapsed + }, + ) + is CurrencyItemUM.Custom -> return + } + + previewState.update { state -> + items = items.mutate { + it[index] = updatedItem + } + state.copy(items = items) + } + } + + private fun toggleNetwork(currencyIndex: Int, networkIndex: Int, isSelected: Boolean) { + val updatedItem = when (val item = items[currencyIndex]) { + is CurrencyItemUM.Basic -> { + val updatedNetworks = (item.networks as? CurrencyItemUM.Basic.NetworksUM.Expanded) + ?.copy( + networks = item.networks.networks.toPersistentList().mutate { + it.fastForEachIndexed { index, network -> + if (index == networkIndex) { + it[index] = network.copy( + model = network.model.copy( + iconResId = if (isSelected) { + R.drawable.img_eth_22 + } else { + R.drawable.ic_eth_16 + }, + isSelected = isSelected, + ), + isSelected = isSelected, + ) + } + } + }, + ) + ?: return + + item.copy(networks = updatedNetworks) + } + is CurrencyItemUM.Custom -> return + } + + val id = "${currencyIndex}_$networkIndex" + if (changedItemsIds.contains(id)) { + changedItemsIds.remove(id) + } else { + changedItemsIds.add(id) + } + + previewState.update { state -> + items = items.mutate { + it[currencyIndex] = updatedItem + } + state.copy( + items = items, + hasChanges = changedItemsIds.isNotEmpty(), + ) + } + } +} \ No newline at end of file diff --git a/features/manage-tokens/impl/src/main/kotlin/com/tangem/features/managetokens/entity/CurrencyItemUM.kt b/features/manage-tokens/impl/src/main/kotlin/com/tangem/features/managetokens/entity/CurrencyItemUM.kt new file mode 100644 index 0000000000..0cfc505545 --- /dev/null +++ b/features/manage-tokens/impl/src/main/kotlin/com/tangem/features/managetokens/entity/CurrencyItemUM.kt @@ -0,0 +1,36 @@ +package com.tangem.features.managetokens.entity + +import androidx.compose.runtime.Immutable +import com.tangem.core.ui.components.rows.model.ChainRowUM +import kotlinx.collections.immutable.ImmutableList + +@Immutable +internal sealed class CurrencyItemUM { + + abstract val id: String + abstract val model: ChainRowUM + + data class Basic( + override val id: String, + override val model: ChainRowUM, + val networks: NetworksUM, + val onExpandClick: () -> Unit, + ) : CurrencyItemUM() { + + @Immutable + sealed class NetworksUM { + + data object Collapsed : NetworksUM() + + data class Expanded( + val networks: ImmutableList, + ) : NetworksUM() + } + } + + data class Custom( + override val id: String, + override val model: ChainRowUM, + val onRemoveClick: () -> Unit, + ) : CurrencyItemUM() +} \ No newline at end of file diff --git a/features/manage-tokens/impl/src/main/kotlin/com/tangem/features/managetokens/entity/CurrencyNetworkUM.kt b/features/manage-tokens/impl/src/main/kotlin/com/tangem/features/managetokens/entity/CurrencyNetworkUM.kt new file mode 100644 index 0000000000..8ed8dc5f9d --- /dev/null +++ b/features/manage-tokens/impl/src/main/kotlin/com/tangem/features/managetokens/entity/CurrencyNetworkUM.kt @@ -0,0 +1,12 @@ +package com.tangem.features.managetokens.entity + +import androidx.compose.runtime.Immutable +import com.tangem.core.ui.components.rows.model.BlockchainRowUM + +@Immutable +internal data class CurrencyNetworkUM( + val id: String, + val model: BlockchainRowUM, + val isSelected: Boolean, + val onSelectedStateChange: (Boolean) -> Unit, +) \ No newline at end of file diff --git a/features/manage-tokens/impl/src/main/kotlin/com/tangem/features/managetokens/entity/ManageTokensUM.kt b/features/manage-tokens/impl/src/main/kotlin/com/tangem/features/managetokens/entity/ManageTokensUM.kt new file mode 100644 index 0000000000..c8678bdd38 --- /dev/null +++ b/features/manage-tokens/impl/src/main/kotlin/com/tangem/features/managetokens/entity/ManageTokensUM.kt @@ -0,0 +1,15 @@ +package com.tangem.features.managetokens.entity + +import androidx.compose.runtime.Immutable +import com.tangem.core.ui.components.fields.entity.SearchBarUM +import kotlinx.collections.immutable.ImmutableList + +@Immutable +internal data class ManageTokensUM( + val popBack: () -> Unit, + val items: ImmutableList, + val search: SearchBarUM, + val hasChanges: Boolean, + val onAddCustomToken: () -> Unit, + val onSaveClick: () -> Unit, +) \ No newline at end of file diff --git a/features/manage-tokens/impl/src/main/kotlin/com/tangem/features/managetokens/ui/ManageTokensScreen.kt b/features/manage-tokens/impl/src/main/kotlin/com/tangem/features/managetokens/ui/ManageTokensScreen.kt new file mode 100644 index 0000000000..63a14af8d4 --- /dev/null +++ b/features/manage-tokens/impl/src/main/kotlin/com/tangem/features/managetokens/ui/ManageTokensScreen.kt @@ -0,0 +1,272 @@ +package com.tangem.features.managetokens.ui + +import android.content.res.Configuration +import androidx.activity.compose.BackHandler +import androidx.compose.animation.* +import androidx.compose.animation.core.animateFloatAsState +import androidx.compose.foundation.ExperimentalFoundationApi +import androidx.compose.foundation.background +import androidx.compose.foundation.clickable +import androidx.compose.foundation.layout.* +import androidx.compose.foundation.lazy.LazyColumn +import androidx.compose.foundation.lazy.items +import androidx.compose.material3.FabPosition +import androidx.compose.material3.Icon +import androidx.compose.material3.Scaffold +import androidx.compose.runtime.Composable +import androidx.compose.runtime.getValue +import androidx.compose.runtime.remember +import androidx.compose.ui.Alignment +import androidx.compose.ui.Modifier +import androidx.compose.ui.draw.rotate +import androidx.compose.ui.res.painterResource +import androidx.compose.ui.res.stringResource +import androidx.compose.ui.tooling.preview.Preview +import androidx.compose.ui.util.fastForEachIndexed +import com.tangem.core.ui.components.BottomFade +import com.tangem.core.ui.components.PrimaryButtonIconEnd +import com.tangem.core.ui.components.TangemSwitch +import com.tangem.core.ui.components.appbar.TangemTopAppBar +import com.tangem.core.ui.components.appbar.models.TopAppBarButtonUM +import com.tangem.core.ui.components.buttons.SecondarySmallButton +import com.tangem.core.ui.components.buttons.SmallButtonConfig +import com.tangem.core.ui.components.fields.SearchBar +import com.tangem.core.ui.components.fields.entity.SearchBarUM +import com.tangem.core.ui.components.rows.ArrowRow +import com.tangem.core.ui.components.rows.BlockchainRow +import com.tangem.core.ui.components.rows.ChainRow +import com.tangem.core.ui.extensions.resourceReference +import com.tangem.core.ui.res.TangemTheme +import com.tangem.core.ui.res.TangemThemePreview +import com.tangem.features.managetokens.component.preview.PreviewManageTokensComponent +import com.tangem.features.managetokens.entity.CurrencyItemUM +import com.tangem.features.managetokens.entity.CurrencyItemUM.Basic.NetworksUM +import com.tangem.features.managetokens.entity.ManageTokensUM +import com.tangem.features.managetokens.impl.R +import kotlinx.collections.immutable.ImmutableList + +private const val CHEVRON_ROTATION_EXPANDED = 180f +private const val CHEVRON_ROTATION_COLLAPSED = 0f + +@Composable +internal fun ManageTokensScreen(state: ManageTokensUM, modifier: Modifier = Modifier) { + BackHandler(onBack = state.popBack) + + Scaffold( + modifier = modifier, + containerColor = TangemTheme.colors.background.primary, + topBar = { + TangemTopAppBar( + modifier = Modifier.statusBarsPadding(), + title = stringResource(id = R.string.main_manage_tokens), + startButton = TopAppBarButtonUM.Back(state.popBack), + endButton = TopAppBarButtonUM( + iconRes = R.drawable.ic_plus_24, + onIconClicked = state.onAddCustomToken, + ), + ) + }, + content = { innerPadding -> + Content( + modifier = Modifier + .padding(innerPadding) + .fillMaxSize(), + state = state, + ) + }, + floatingActionButtonPosition = FabPosition.Center, + floatingActionButton = { + SaveChangesButton( + modifier = Modifier + .padding(horizontal = TangemTheme.dimens.spacing16) + .fillMaxWidth(), + isVisible = state.hasChanges, + onClick = state.onSaveClick, + ) + }, + ) +} + +@Composable +private fun SaveChangesButton(isVisible: Boolean, onClick: () -> Unit, modifier: Modifier = Modifier) { + AnimatedVisibility( + modifier = modifier, + visible = isVisible, + enter = fadeIn(), + exit = fadeOut(), + label = "save_button_visibility", + ) { + PrimaryButtonIconEnd( + text = stringResource(id = R.string.common_save), + iconResId = R.drawable.ic_tangem_24, + onClick = onClick, + ) + } +} + +@Composable +private fun Content(state: ManageTokensUM, modifier: Modifier = Modifier) { + Box(modifier = modifier) { + Currencies( + modifier = Modifier.fillMaxSize(), + items = state.items, + search = state.search, + ) + + AnimatedVisibility( + modifier = Modifier + .align(Alignment.BottomCenter) + .fillMaxWidth(), + visible = state.hasChanges, + label = "bottom_fade_visibility", + ) { + BottomFade() + } + } +} + +@OptIn(ExperimentalFoundationApi::class) +@Composable +private fun Currencies(items: ImmutableList, search: SearchBarUM, modifier: Modifier = Modifier) { + LazyColumn( + modifier = modifier, + ) { + stickyHeader(key = "search") { + Column( + modifier = Modifier + .background(TangemTheme.colors.background.primary) + .padding( + top = TangemTheme.dimens.spacing16, + bottom = TangemTheme.dimens.spacing12, + ) + .padding(horizontal = TangemTheme.dimens.spacing16) + .fillMaxWidth(), + ) { + SearchBar(state = search) + } + } + + items( + items = items, + key = CurrencyItemUM::id, + ) { item -> + when (item) { + is CurrencyItemUM.Basic -> { + BasicCurrencyItem( + modifier = Modifier.fillMaxWidth(), + item = item, + ) + } + is CurrencyItemUM.Custom -> { + CustomCurrencyItem( + modifier = Modifier.fillMaxWidth(), + item = item, + ) + } + } + } + } +} + +@Composable +private fun CustomCurrencyItem(item: CurrencyItemUM.Custom, modifier: Modifier = Modifier) { + ChainRow( + modifier = modifier, + model = item.model, + action = { + SecondarySmallButton( + config = SmallButtonConfig( + text = resourceReference(R.string.manage_tokens_remove), + onClick = item.onRemoveClick, + ), + ) + }, + ) +} + +@Composable +private fun BasicCurrencyItem(item: CurrencyItemUM.Basic, modifier: Modifier = Modifier) { + val isExpanded = item.networks is NetworksUM.Expanded + + Column(modifier = modifier) { + ChainRow( + modifier = Modifier.clickable(onClick = item.onExpandClick), + model = item.model, + action = { + val rotation by animateFloatAsState( + targetValue = if (isExpanded) { + CHEVRON_ROTATION_EXPANDED + } else { + CHEVRON_ROTATION_COLLAPSED + }, + label = "chevron_rotation", + ) + + Icon( + modifier = Modifier + .rotate(rotation) + .size(TangemTheme.dimens.size24), + painter = painterResource(id = R.drawable.ic_chevron_24), + tint = TangemTheme.colors.icon.informative, + contentDescription = null, + ) + }, + ) + + NetworksList( + modifier = Modifier.padding( + start = TangemTheme.dimens.spacing10, + end = TangemTheme.dimens.spacing8, + ), + networks = item.networks, + currencyId = item.id, + ) + } +} + +@Composable +private fun NetworksList(networks: NetworksUM, currencyId: String, modifier: Modifier = Modifier) { + AnimatedVisibility( + modifier = modifier, + visible = networks is NetworksUM.Expanded, + enter = fadeIn() + expandVertically(), + exit = fadeOut() + shrinkVertically(), + label = "networks_visibility", + ) { + Column { + val items = (networks as? NetworksUM.Expanded)?.networks + + // To keep items on collapse and avoid animation cancellation + val rememberedItems = remember(key1 = currencyId) { items } + val currentItems = items ?: rememberedItems + + currentItems?.fastForEachIndexed { index, network -> + ArrowRow( + isLastItem = index == currentItems.lastIndex, + content = { + BlockchainRow( + model = network.model, + action = { + TangemSwitch( + checked = network.isSelected, + onCheckedChange = network.onSelectedStateChange, + ) + }, + ) + }, + ) + } + } + } +} + +// region Preview +@Preview(showBackground = true, widthDp = 360, heightDp = 800) +@Preview(showBackground = true, widthDp = 360, heightDp = 800, uiMode = Configuration.UI_MODE_NIGHT_YES) +@Composable +private fun Preview_ManageTokens() { + TangemThemePreview { + PreviewManageTokensComponent().Content(Modifier.fillMaxWidth()) + } +} +// endregion Preview \ No newline at end of file diff --git a/features/markets/api/.gitignore b/features/markets/api/.gitignore new file mode 100644 index 0000000000..796b96d1c4 --- /dev/null +++ b/features/markets/api/.gitignore @@ -0,0 +1 @@ +/build diff --git a/features/markets/api/build.gradle.kts b/features/markets/api/build.gradle.kts new file mode 100644 index 0000000000..0248feb86d --- /dev/null +++ b/features/markets/api/build.gradle.kts @@ -0,0 +1,18 @@ +plugins { + alias(deps.plugins.android.library) + alias(deps.plugins.kotlin.android) + id("kotlin-parcelize") + id("configuration") +} + +android { + namespace = "com.tangem.features.markets.api" +} + +dependencies { + implementation(deps.compose.foundation) + + /* Project - Core */ + implementation(projects.core.decompose) + implementation(projects.core.ui) +} \ No newline at end of file diff --git a/features/markets/api/src/main/kotlin/com/tangem/features/markets/MarketsFeatureToggles.kt b/features/markets/api/src/main/kotlin/com/tangem/features/markets/MarketsFeatureToggles.kt new file mode 100644 index 0000000000..34758a7b41 --- /dev/null +++ b/features/markets/api/src/main/kotlin/com/tangem/features/markets/MarketsFeatureToggles.kt @@ -0,0 +1,5 @@ +package com.tangem.features.markets + +interface MarketsFeatureToggles { + val isFeatureEnabled: Boolean +} \ No newline at end of file diff --git a/features/markets/api/src/main/kotlin/com/tangem/features/markets/component/BottomSheetState.kt b/features/markets/api/src/main/kotlin/com/tangem/features/markets/component/BottomSheetState.kt new file mode 100644 index 0000000000..5c8cc47920 --- /dev/null +++ b/features/markets/api/src/main/kotlin/com/tangem/features/markets/component/BottomSheetState.kt @@ -0,0 +1,6 @@ +package com.tangem.features.markets.component + +enum class BottomSheetState { + EXPANDED, + COLLAPSED, +} \ No newline at end of file diff --git a/features/markets/api/src/main/kotlin/com/tangem/features/markets/component/MarketsListComponent.kt b/features/markets/api/src/main/kotlin/com/tangem/features/markets/component/MarketsListComponent.kt new file mode 100644 index 0000000000..c0d14dbea5 --- /dev/null +++ b/features/markets/api/src/main/kotlin/com/tangem/features/markets/component/MarketsListComponent.kt @@ -0,0 +1,23 @@ +package com.tangem.features.markets.component + +import androidx.compose.runtime.Composable +import androidx.compose.runtime.Stable +import androidx.compose.runtime.State +import androidx.compose.ui.Modifier +import androidx.compose.ui.unit.Dp +import com.tangem.core.decompose.context.AppComponentContext + +@Stable +interface MarketsListComponent { + + @Composable + fun BottomSheetContent( + bottomSheetState: State, + onHeaderSizeChange: (Dp) -> Unit, + modifier: Modifier, + ) + + interface Factory { + fun create(context: AppComponentContext): MarketsListComponent + } +} \ No newline at end of file diff --git a/features/markets/impl/.gitignore b/features/markets/impl/.gitignore new file mode 100644 index 0000000000..796b96d1c4 --- /dev/null +++ b/features/markets/impl/.gitignore @@ -0,0 +1 @@ +/build diff --git a/features/markets/impl/build.gradle.kts b/features/markets/impl/build.gradle.kts new file mode 100644 index 0000000000..46bc8c674a --- /dev/null +++ b/features/markets/impl/build.gradle.kts @@ -0,0 +1,48 @@ +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") +} + +android { + namespace = "com.tangem.features.markets.impl" +} + +dependencies { + /* Project - API */ + api(projects.features.markets.api) + + /* Domain */ + implementation(projects.domain.markets) + implementation(projects.domain.appCurrency) + implementation(projects.domain.appCurrency.models) + + /* Compose */ + implementation(deps.compose.coil) + implementation(deps.compose.foundation) + implementation(deps.compose.material3) + implementation(deps.compose.ui) + implementation(deps.compose.ui.tooling) + implementation(deps.compose.ui.utils) + implementation(deps.lifecycle.compose) + implementation(deps.androidx.activity.compose) + + /* DI */ + implementation(deps.hilt.android) + kapt(deps.hilt.kapt) + + /* Other */ + implementation(deps.kotlin.immutable.collections) + implementation(deps.timber) + + /* Core */ + implementation(projects.core.decompose) + implementation(projects.core.ui) + implementation(projects.core.featuretoggles) + + implementation(projects.common.ui) + implementation(projects.common.uiCharts) +} \ No newline at end of file diff --git a/features/markets/impl/src/main/kotlin/com/tangem/features/markets/DefaultMarketsFeatureToggles.kt b/features/markets/impl/src/main/kotlin/com/tangem/features/markets/DefaultMarketsFeatureToggles.kt new file mode 100644 index 0000000000..75062eddef --- /dev/null +++ b/features/markets/impl/src/main/kotlin/com/tangem/features/markets/DefaultMarketsFeatureToggles.kt @@ -0,0 +1,11 @@ +package com.tangem.features.markets + +import com.tangem.core.featuretoggle.manager.FeatureTogglesManager + +internal class DefaultMarketsFeatureToggles( + private val featureTogglesManager: FeatureTogglesManager, +) : MarketsFeatureToggles { + + override val isFeatureEnabled: Boolean + get() = featureTogglesManager.isFeatureEnabled("MARKETS_ENABLED") +} \ No newline at end of file diff --git a/features/markets/impl/src/main/kotlin/com/tangem/features/markets/component/impl/DefaultMarketsListComponent.kt b/features/markets/impl/src/main/kotlin/com/tangem/features/markets/component/impl/DefaultMarketsListComponent.kt new file mode 100644 index 0000000000..c5329d71a3 --- /dev/null +++ b/features/markets/impl/src/main/kotlin/com/tangem/features/markets/component/impl/DefaultMarketsListComponent.kt @@ -0,0 +1,51 @@ +package com.tangem.features.markets.component.impl + +import androidx.compose.runtime.Composable +import androidx.compose.runtime.LaunchedEffect +import androidx.compose.runtime.State +import androidx.compose.runtime.getValue +import androidx.compose.ui.Modifier +import androidx.compose.ui.unit.Dp +import androidx.lifecycle.compose.collectAsStateWithLifecycle +import com.tangem.core.decompose.context.AppComponentContext +import com.tangem.core.decompose.model.getOrCreateModel +import com.tangem.features.markets.component.BottomSheetState +import com.tangem.features.markets.component.MarketsListComponent +import com.tangem.features.markets.model.MarketsListModel +import com.tangem.features.markets.ui.MarketsList +import dagger.assisted.Assisted +import dagger.assisted.AssistedFactory +import dagger.assisted.AssistedInject + +internal class DefaultMarketsListComponent @AssistedInject constructor( + @Assisted context: AppComponentContext, +) : MarketsListComponent, AppComponentContext by context { + + private val model: MarketsListModel = getOrCreateModel() + + @Composable + override fun BottomSheetContent( + bottomSheetState: State, + onHeaderSizeChange: (Dp) -> Unit, + modifier: Modifier, + ) { + val state by model.state.collectAsStateWithLifecycle() + val bsState by bottomSheetState + + LaunchedEffect(bsState) { + model.containerBottomSheetState.value = bsState + } + + MarketsList( + modifier = modifier, + state = state, + onHeaderSizeChange = onHeaderSizeChange, + bottomSheetState = bsState, + ) + } + + @AssistedFactory + interface Factory : MarketsListComponent.Factory { + override fun create(context: AppComponentContext): DefaultMarketsListComponent + } +} \ No newline at end of file diff --git a/features/markets/impl/src/main/kotlin/com/tangem/features/markets/di/ComponentModule.kt b/features/markets/impl/src/main/kotlin/com/tangem/features/markets/di/ComponentModule.kt new file mode 100644 index 0000000000..f88b0b5ad0 --- /dev/null +++ b/features/markets/impl/src/main/kotlin/com/tangem/features/markets/di/ComponentModule.kt @@ -0,0 +1,18 @@ +package com.tangem.features.markets.di + +import com.tangem.features.markets.component.MarketsListComponent +import com.tangem.features.markets.component.impl.DefaultMarketsListComponent +import dagger.Binds +import dagger.Module +import dagger.hilt.InstallIn +import dagger.hilt.components.SingletonComponent +import javax.inject.Singleton + +@Module +@InstallIn(SingletonComponent::class) +internal interface ComponentModule { + + @Binds + @Singleton + fun bindMarketsListComponent(factory: DefaultMarketsListComponent.Factory): MarketsListComponent.Factory +} \ No newline at end of file diff --git a/features/markets/impl/src/main/kotlin/com/tangem/features/markets/di/FeatureModule.kt b/features/markets/impl/src/main/kotlin/com/tangem/features/markets/di/FeatureModule.kt new file mode 100644 index 0000000000..a2085dfe77 --- /dev/null +++ b/features/markets/impl/src/main/kotlin/com/tangem/features/markets/di/FeatureModule.kt @@ -0,0 +1,20 @@ +package com.tangem.features.markets.di + +import com.tangem.core.featuretoggle.manager.FeatureTogglesManager +import com.tangem.features.markets.DefaultMarketsFeatureToggles +import com.tangem.features.markets.MarketsFeatureToggles +import dagger.Module +import dagger.Provides +import dagger.hilt.InstallIn +import dagger.hilt.components.SingletonComponent +import javax.inject.Singleton + +@Module +@InstallIn(SingletonComponent::class) +internal object FeatureModule { + + @Provides + @Singleton + fun provideFeatureToggles(featureTogglesManager: FeatureTogglesManager): MarketsFeatureToggles = + DefaultMarketsFeatureToggles(featureTogglesManager = featureTogglesManager) +} \ No newline at end of file diff --git a/features/markets/impl/src/main/kotlin/com/tangem/features/markets/di/ModelModule.kt b/features/markets/impl/src/main/kotlin/com/tangem/features/markets/di/ModelModule.kt new file mode 100644 index 0000000000..9ee24735da --- /dev/null +++ b/features/markets/impl/src/main/kotlin/com/tangem/features/markets/di/ModelModule.kt @@ -0,0 +1,20 @@ +package com.tangem.features.markets.di + +import com.tangem.core.decompose.di.DecomposeComponent +import com.tangem.core.decompose.model.Model +import com.tangem.features.markets.model.MarketsListModel +import dagger.Binds +import dagger.Module +import dagger.hilt.InstallIn +import dagger.multibindings.ClassKey +import dagger.multibindings.IntoMap + +@Module +@InstallIn(DecomposeComponent::class) +internal interface ModelModule { + + @Binds + @IntoMap + @ClassKey(MarketsListModel::class) + fun provideMarketsListModel(model: MarketsListModel): Model +} \ No newline at end of file diff --git a/features/markets/impl/src/main/kotlin/com/tangem/features/markets/model/MarketsListModel.kt b/features/markets/impl/src/main/kotlin/com/tangem/features/markets/model/MarketsListModel.kt new file mode 100644 index 0000000000..97fc37c161 --- /dev/null +++ b/features/markets/impl/src/main/kotlin/com/tangem/features/markets/model/MarketsListModel.kt @@ -0,0 +1,224 @@ +package com.tangem.features.markets.model + +import androidx.compose.runtime.Stable +import arrow.core.getOrElse +import com.tangem.core.decompose.di.ComponentScoped +import com.tangem.core.decompose.model.Model +import com.tangem.domain.appcurrency.GetSelectedAppCurrencyUseCase +import com.tangem.domain.appcurrency.model.AppCurrency +import com.tangem.domain.markets.GetMarketsTokenListFlowUseCase +import com.tangem.features.markets.component.BottomSheetState +import com.tangem.features.markets.model.statemanager.MarketsListUMStateManager +import com.tangem.features.markets.model.statemanager.MarketsListBatchFlowManager +import com.tangem.features.markets.ui.entity.ListUM +import com.tangem.features.markets.ui.entity.SortByTypeUM +import com.tangem.utils.Provider +import com.tangem.utils.coroutines.CoroutineDispatcherProvider +import com.tangem.utils.coroutines.JobHolder +import com.tangem.utils.coroutines.saveIn +import kotlinx.coroutines.* +import kotlinx.coroutines.flow.* +import javax.inject.Inject + +private const val UPDATE_QUOTES_TIMER_MILLIS = 60000L +private const val SEARCH_QUERY_DEBOUNCE_MILLIS = 800L + +@OptIn(FlowPreview::class, ExperimentalCoroutinesApi::class) +@ComponentScoped +@Stable +internal class MarketsListModel @Inject constructor( + override val dispatchers: CoroutineDispatcherProvider, + getMarketsTokenListFlowUseCase: GetMarketsTokenListFlowUseCase, + getSelectedAppCurrencyUseCase: GetSelectedAppCurrencyUseCase, +) : Model() { + + private val currentAppCurrency = getSelectedAppCurrencyUseCase() + .map { maybeAppCurrency -> + maybeAppCurrency.getOrElse { AppCurrency.Default } + }.stateIn( + scope = modelScope, + started = SharingStarted.Eagerly, + initialValue = AppCurrency.Default, + ) + + private val visibleItemIds = MutableStateFlow>(emptyList()) + + private val marketsListUMStateManager = MarketsListUMStateManager( + onLoadMoreUiItems = { activeListManager.loadMore() }, + visibleItemsChanged = { visibleItemIds.value = it }, + onRetryButtonClicked = { activeListManager.reload() }, + ) + + private val mainMarketsListManager = MarketsListBatchFlowManager( + getMarketsTokenListFlowUseCase = getMarketsTokenListFlowUseCase, + batchFlowType = GetMarketsTokenListFlowUseCase.BatchFlowType.Main, + currentAppCurrency = Provider { currentAppCurrency.value }, + currentTrendInterval = Provider { marketsListUMStateManager.selectedInterval }, + currentSortByType = Provider { marketsListUMStateManager.selectedSortByType }, + currentSearchText = Provider { null }, + modelScope = modelScope, + dispatchers = dispatchers, + ) + private val searchMarketsListManager = MarketsListBatchFlowManager( + getMarketsTokenListFlowUseCase = getMarketsTokenListFlowUseCase, + batchFlowType = GetMarketsTokenListFlowUseCase.BatchFlowType.Search, + currentAppCurrency = Provider { currentAppCurrency.value }, + currentTrendInterval = Provider { marketsListUMStateManager.selectedInterval }, // FIXME fix on backend + currentSortByType = Provider { SortByTypeUM.Rating }, // FIXME maybe fix on backend + currentSearchText = Provider { marketsListUMStateManager.searchQuery }, + modelScope = modelScope, + dispatchers = dispatchers, + ) + + private var activeListManager: MarketsListBatchFlowManager = mainMarketsListManager + + val containerBottomSheetState = MutableStateFlow(BottomSheetState.COLLAPSED) + + val state = marketsListUMStateManager.state.asStateFlow() + + init { + @Suppress("UnnecessaryParentheses") + modelScope.launch { + marketsListUMStateManager.isInSearchStateFlow + .flatMapLatest { isInSearchMode -> + if (isInSearchMode) { + combine( + searchMarketsListManager.uiItems, + searchMarketsListManager.isInInitialLoadingErrorState, + searchMarketsListManager.isSearchNotFoundState, + ) { items, isError, notFound -> + (items to isError) to notFound + } + } else { + combine( + mainMarketsListManager.uiItems, + mainMarketsListManager.isInInitialLoadingErrorState, + ) { items, isError -> (items to isError) to false } + } + }.collect { + marketsListUMStateManager.onUiItemsChanged( + uiItems = it.first.first, + isInErrorState = it.first.second, + isSearchNotFound = it.second, + ) + } + } + + state.onEach { + if (it.list !is ListUM.Content) { + visibleItemIds.value = emptyList() + } + }.launchIn(modelScope) + + // update all lists when user's currency has changed + currentAppCurrency + .drop(1) + .onEach { + mainMarketsListManager.reload() + if (marketsListUMStateManager.isInSearchState) { + searchMarketsListManager.reload() + } + }.launchIn(modelScope) + + // load charts when new batch is being loaded + mainMarketsListManager.onLastBatchLoadedSuccess + .onEach { + mainMarketsListManager.loadCharts(setOf(it), marketsListUMStateManager.selectedInterval) + modelScope.loadQuotesWithTimer(timeMillis = UPDATE_QUOTES_TIMER_MILLIS) + } + .launchIn(modelScope) + + // listen currently selected interval, update charts if sorting=rating, or reload all list + modelScope.launch(dispatchers.default) { + marketsListUMStateManager.state + .map { it.selectedInterval } + .distinctUntilChanged() + .drop(1) + .collectLatest { interval -> + when (marketsListUMStateManager.selectedSortByType) { + SortByTypeUM.Rating -> { + mainMarketsListManager.updateUIWithSameState() + val batchKeys = mainMarketsListManager.getBatchKeysByItemIds(visibleItemIds.value) + mainMarketsListManager.loadCharts(batchKeys, interval) + } + else -> mainMarketsListManager.reload() + } + } + } + + // reload list when sorting type has changed + modelScope.launch { + marketsListUMStateManager.state + .map { it.selectedSortBy } + .distinctUntilChanged() + .drop(1) + .collectLatest { + mainMarketsListManager.reload() + } + } + + // listen current visible batch and update charts + modelScope.launch { + visibleItemIds + .mapNotNull { + if (it.isNotEmpty()) { + activeListManager.getBatchKeysByItemIds(visibleItemIds.value) + } else { + null + } + } + .distinctUntilChanged() + .collectLatest { visibleBatchKeys -> + activeListManager.loadCharts(visibleBatchKeys, marketsListUMStateManager.selectedInterval) + } + } + + // ===Search=== + + modelScope.launch { + marketsListUMStateManager.isInSearchStateFlow + .collectLatest { isInSearchMode -> + activeListManager = if (isInSearchMode) { + searchMarketsListManager + } else { + searchMarketsListManager.clearStateAndStopAllActions() + mainMarketsListManager + } + } + } + + modelScope.launch { + marketsListUMStateManager.searchQueryFlow + .filter { it.isNotEmpty() } + .debounce(timeoutMillis = SEARCH_QUERY_DEBOUNCE_MILLIS) + .filter { activeListManager == searchMarketsListManager } + .collectLatest { + searchMarketsListManager.reload(searchText = it) + } + } + + modelScope.launch { + searchMarketsListManager + .onLastBatchLoadedSuccess + .collectLatest { + searchMarketsListManager.loadCharts(setOf(it), marketsListUMStateManager.selectedInterval) + modelScope.loadQuotesWithTimer(timeMillis = UPDATE_QUOTES_TIMER_MILLIS) + } + } + + // initial loading + mainMarketsListManager.reload() + } + + private var updateQuotesJob = JobHolder() + private fun CoroutineScope.loadQuotesWithTimer(timeMillis: Long) { + launch { + while (true) { + delay(timeMillis) + // Update quotes only when the container bottom sheet is in the expanded state + containerBottomSheetState.first { it == BottomSheetState.EXPANDED } + activeListManager.updateQuotes() // TODO update a batch that is currently on screen + } + }.saveIn(updateQuotesJob) + } +} \ No newline at end of file diff --git a/features/markets/impl/src/main/kotlin/com/tangem/features/markets/model/converters/MarketsTokenItemConverter.kt b/features/markets/impl/src/main/kotlin/com/tangem/features/markets/model/converters/MarketsTokenItemConverter.kt new file mode 100644 index 0000000000..c2badcd569 --- /dev/null +++ b/features/markets/impl/src/main/kotlin/com/tangem/features/markets/model/converters/MarketsTokenItemConverter.kt @@ -0,0 +1,153 @@ +package com.tangem.features.markets.model.converters + +import com.tangem.common.ui.charts.state.DefaultPointValuesConverter +import com.tangem.common.ui.charts.state.MarketChartData +import com.tangem.common.ui.charts.state.MarketChartRawData +import com.tangem.core.ui.components.marketprice.PriceChangeType +import com.tangem.core.ui.utils.BigDecimalFormatter +import com.tangem.domain.appcurrency.model.AppCurrency +import com.tangem.domain.markets.TokenMarket +import com.tangem.features.markets.ui.entity.MarketsListItemUM +import com.tangem.features.markets.ui.entity.MarketsListUM.TrendInterval +import com.tangem.utils.converter.Converter +import java.math.BigDecimal +import java.math.RoundingMode + +internal class MarketsTokenItemConverter( + private val currentTrendInterval: TrendInterval, + private val appCurrency: AppCurrency, +) : Converter { + + override fun convert(value: TokenMarket): MarketsListItemUM { + return MarketsListItemUM( + id = value.id, + name = value.name, + currencySymbol = value.symbol, + ratingPosition = value.marketRating?.toString(), + marketCap = value.getMarketCap(), + iconUrl = value.imageUrlLarge, + price = value.getCurrentPrice(), + trendPercentText = value.getTrendPercent(), + trendType = value.getTrendType(), + chardData = value.getChartData(), + showUnder100kMarketCap = value.isUnder100kMarketCap(), + ) + } + + fun update(prev: TokenMarket, prevUI: MarketsListItemUM, new: TokenMarket): MarketsListItemUM { + require(prev.id == new.id) { + "Ids is not the same during update TokenMarket item: previousItem[${prev.id}] != newItem[${new.id}]" + } + + return prevUI.copy( + name = new.name, + currencySymbol = new.symbol, + ratingPosition = new.marketRating?.toString(), + marketCap = ifChanged(prev.marketCap, new.marketCap, prevUI.marketCap) { new.getMarketCap() }, + iconUrl = new.imageUrlLarge, + price = ifChanged(prev = prev.tokenQuotes, new = new.tokenQuotes, prevR = prevUI.price) { + new.getCurrentPrice( + prev = prev, + ) + }, + trendPercentText = ifChanged( + prev.tokenQuotes, + new.tokenQuotes, + prevUI.trendPercentText, + ) { new.getTrendPercent() }, + trendType = ifChanged(prev.tokenQuotes, new.tokenQuotes, prevUI.trendType) { new.getTrendType() }, + chardData = ifChanged(prev.tokenCharts, new.tokenCharts, prevUI.chardData) { new.getChartData() }, + ) + } + + private inline fun ifChanged(prev: T, new: T, prevR: R, force: Boolean = false, change: (T) -> R): R { + return if (force || prev != new) change(new) else prevR + } + + private fun TokenMarket.getMarketCap(): String? { + val value = marketCap?.takeIf { marketCap != BigDecimal.ZERO } ?: return null + + return BigDecimalFormatter.formatCompactAmount( + value, + fiatCurrencyCode = appCurrency.code, + fiatCurrencySymbol = appCurrency.symbol, + ) + } + + private fun TokenMarket.getCurrentPrice(prev: TokenMarket? = null): MarketsListItemUM.Price { + val prevPrice = prev?.tokenQuotes?.currentPrice + + val priceText = BigDecimalFormatter.formatFiatAmountUncapped( + fiatAmount = tokenQuotes.currentPrice, + fiatCurrencyCode = appCurrency.code, + fiatCurrencySymbol = appCurrency.symbol, + ) + + val changeType = if (prevPrice != null) { + if (tokenQuotes.currentPrice > prevPrice) { + PriceChangeType.UP + } else { + PriceChangeType.DOWN + } + } else { + null + } + + return MarketsListItemUM.Price( + text = priceText, + changeType = changeType, + ) + } + + private fun TokenMarket.getChartData(): MarketChartRawData? { + val chart = when (currentTrendInterval) { + TrendInterval.H24 -> tokenCharts.h24 + TrendInterval.D7 -> tokenCharts.week + TrendInterval.M1 -> tokenCharts.month + } + + return chart?.let { ct -> + DefaultPointValuesConverter.convert( + MarketChartData.Data( + y = ct.priceY, + x = ct.timeStamp.map { it.toBigDecimal() }, + ), + ) + } + } + + private fun TokenMarket.getTrendType(): PriceChangeType { + val percent = when (currentTrendInterval) { + TrendInterval.H24 -> tokenQuotes.h24Percent() + TrendInterval.D7 -> tokenQuotes.weekPercent() + TrendInterval.M1 -> tokenQuotes.monthPercent() + }.setScale(2, RoundingMode.UP) + + return when (percent.compareTo(BigDecimal.ZERO)) { + 1 -> PriceChangeType.UP + -1 -> PriceChangeType.DOWN + else -> PriceChangeType.NEUTRAL + } + } + + private fun TokenMarket.getTrendPercent(): String { + val percent = when (currentTrendInterval) { + TrendInterval.H24 -> tokenQuotes.h24Percent() + TrendInterval.D7 -> tokenQuotes.weekPercent() + TrendInterval.M1 -> tokenQuotes.monthPercent() + } + + return BigDecimalFormatter.formatPercent( + percent = percent, + useAbsoluteValue = true, + ) + } + + private fun TokenMarket.isUnder100kMarketCap(): Boolean { + return tokenQuotes.currentPrice.compareTo(decimal100k) == -1 + } + + private companion object { + val decimal100k: BigDecimal = BigDecimal.valueOf(100_000) + } +} \ No newline at end of file diff --git a/features/markets/impl/src/main/kotlin/com/tangem/features/markets/model/statemanager/MarketsListBatchFlowManager.kt b/features/markets/impl/src/main/kotlin/com/tangem/features/markets/model/statemanager/MarketsListBatchFlowManager.kt new file mode 100644 index 0000000000..ae897a5b9a --- /dev/null +++ b/features/markets/impl/src/main/kotlin/com/tangem/features/markets/model/statemanager/MarketsListBatchFlowManager.kt @@ -0,0 +1,318 @@ +package com.tangem.features.markets.model.statemanager + +import com.tangem.domain.appcurrency.model.AppCurrency +import com.tangem.domain.markets.* +import com.tangem.features.markets.model.converters.MarketsTokenItemConverter +import com.tangem.features.markets.model.utils.logAction +import com.tangem.features.markets.model.utils.logStatus +import com.tangem.features.markets.model.utils.logUpdateResults +import com.tangem.features.markets.ui.entity.MarketsListItemUM +import com.tangem.features.markets.ui.entity.MarketsListUM.TrendInterval +import com.tangem.features.markets.ui.entity.SortByTypeUM +import com.tangem.pagination.* +import com.tangem.utils.Provider +import com.tangem.utils.coroutines.CoroutineDispatcherProvider +import kotlinx.collections.immutable.ImmutableList +import kotlinx.collections.immutable.persistentListOf +import kotlinx.collections.immutable.toImmutableList +import kotlinx.coroutines.CoroutineScope +import kotlinx.coroutines.flow.* +import kotlinx.coroutines.launch + +private const val LOG_EVENTS = true + +@Suppress("LongParameterList") +internal class MarketsListBatchFlowManager( + getMarketsTokenListFlowUseCase: GetMarketsTokenListFlowUseCase, + private val batchFlowType: GetMarketsTokenListFlowUseCase.BatchFlowType, + private val currentTrendInterval: Provider, + private val currentAppCurrency: Provider, + private val currentSearchText: Provider, + private val currentSortByType: Provider, + private val modelScope: CoroutineScope, + private val dispatchers: CoroutineDispatcherProvider, +) { + private val actionsFlow = MutableSharedFlow>() + + private val batchFlow = getMarketsTokenListFlowUseCase( + batchingContext = TokenListBatchingContext( + actionsFlow = actionsFlow, + coroutineScope = modelScope, + ), + batchFlowType = batchFlowType, + ) + + val uiItems: StateFlow> + get() = uiBatches + .map { batches -> + batches.asSequence() + .map { it.data } + .flatten() + .toImmutableList() + } + .distinctUntilChanged() + .stateIn( + scope = modelScope, + started = SharingStarted.Eagerly, + initialValue = persistentListOf(), + ) + + val onLastBatchLoadedSuccess = batchFlow.state + .distinctUntilChanged { old, new -> old.status == new.status && old.data.size == new.data.size } + .mapNotNull { + when (val status = it.status) { + is PaginationStatus.Paginating -> { + if (status.lastResult is BatchFetchResult.Success) { + it.data.lastOrNull()?.key + } else { + null + } + } + is PaginationStatus.EndOfPagination -> { + it.data.lastOrNull()?.key + } + else -> null + } + } + + val isInInitialLoadingErrorState = batchFlow.state + .map { it.status is PaginationStatus.InitialLoadingError } + .distinctUntilChanged() + .stateIn( + scope = modelScope, + started = SharingStarted.Eagerly, + initialValue = false, + ) + + val isSearchNotFoundState = batchFlow.state + .map { + currentSearchText().isNullOrEmpty().not() && + it.status is PaginationStatus.EndOfPagination && + it.data.isEmpty() + } + .distinctUntilChanged() + .stateIn( + scope = modelScope, + started = SharingStarted.Eagerly, + initialValue = false, + ) + + private val uiBatches = MutableStateFlow>>>(emptyList()) + + init { + batchFlow.state + .map { it.data } + .distinctUntilChanged { a, b -> + a.size == b.size && a.map { it.data }.flatten() == b.map { it.data }.flatten() + } + .onEachWithPrevious { prev, list -> + updateState(prev, list) + } + .flowOn(dispatchers.default) + .launchIn(modelScope) + + if (LOG_EVENTS) { + batchFlow.updateResults + .onEach { logUpdateResults(batchFlowType.name, it) } + .launchIn(modelScope) + + batchFlow.state + .map { it.status } + .onEach { logStatus(batchFlowType.name, it) } + .launchIn(modelScope) + + actionsFlow + .onEach { logAction(batchFlowType.name, it) } + .launchIn(modelScope) + } + } + + private fun updateState( + previousList: List>>?, + list: List>>, + forceUpdate: Boolean = false, + ) = uiBatches.update { items -> + val converter = MarketsTokenItemConverter(currentTrendInterval(), appCurrency = currentAppCurrency()) + + if (previousList == null || list.size < previousList.size || forceUpdate) { + list.map { + Batch( + key = it.key, + data = converter.convertList(it.data), + ) + } + } else { + if (previousList.size != list.size) { + val keysToAdd = list.map { it.key }.subtract(previousList.map { it.key }.toSet()) + val newBatches = list.filter { keysToAdd.contains(it.key) } + + items + newBatches.map { + Batch( + key = it.key, + data = converter.convertList(it.data), + ) + } + } else { + items.mapIndexed { batchIndex, batch -> + val prevBatch = previousList[batchIndex] + val newBatch = list[batchIndex] + if (previousList == newBatch) return@mapIndexed batch + + Batch( + key = batch.key, + data = batch.data.mapIndexed { index, marketsListItemUM -> + val prevItem = prevBatch.data[index] + val newItem = newBatch.data[index] + + converter.update( + prevItem, + marketsListItemUM, + newItem, + ) + }, + ) + } + } + } + } + + fun reload(searchText: String? = null) { + modelScope.launch { + uiBatches.value = emptyList() + actionsFlow.emit( + BatchAction.Reload( + requestParams = TokenMarketListConfig( + fiatPriceCurrency = currentAppCurrency().code, + searchText = if (currentSearchText() == null) { + null + } else { + searchText ?: currentSearchText() + }, + showUnder100kMarketCapTokens = false, // TODO + priceChangeInterval = currentTrendInterval().toBatchRequestInterval(), + order = currentSortByType().toRequestOrder(), + ), + ), + ) + } + } + + fun loadMore() { + modelScope.launch { + actionsFlow.emit(BatchAction.LoadMore()) + } + } + + fun updateUIWithSameState() { + modelScope.launch(dispatchers.default) { + val current = batchFlow.state.value.data + updateState(current, current, forceUpdate = true) + } + } + + fun loadCharts(batchKeys: Set, interval: TrendInterval) { + modelScope.launch(dispatchers.default) { + val currentData = batchFlow.state.value.data + val alreadyLoadedChartsBatchKeys = currentData + .filter { + val first = it.data.firstOrNull() ?: return@filter false + val chartByInterval = when (interval) { + TrendInterval.H24 -> first.tokenCharts.h24 + TrendInterval.D7 -> first.tokenCharts.week + TrendInterval.M1 -> first.tokenCharts.month + } + chartByInterval != null + } + .map { it.key } + .toSet() + + val batchesKeysToLoad = batchKeys.minus(alreadyLoadedChartsBatchKeys) + + if (batchesKeysToLoad.isNotEmpty()) { + actionsFlow.emit( + BatchAction.UpdateBatches( + keys = batchesKeysToLoad, + updateRequest = TokenMarketUpdateRequest.UpdateChart( + interval = interval.toRequestInterval(), + currency = currentAppCurrency().code, + ), + async = true, + operationId = batchesKeysToLoad.toString() + interval.toString(), + ), + ) + } + } + } + + fun updateQuotes() { + modelScope.launch { + actionsFlow.emit( + BatchAction.CancelUpdates { + it.updateRequest is TokenMarketUpdateRequest.UpdateQuotes + }, + ) + + actionsFlow.emit( + BatchAction.UpdateBatches( + keys = batchFlow.state.value.data.map { it.key }.toSet(), + updateRequest = TokenMarketUpdateRequest.UpdateQuotes( + currencyId = currentAppCurrency().code, + ), + async = true, + operationId = "update quotes", + ), + ) + } + } + + fun clearStateAndStopAllActions() { + uiBatches.value = emptyList() + modelScope.launch { + actionsFlow.emit(BatchAction.Reset) + } + } + + fun getBatchKeysByItemIds(ids: List): Set { + val currentData = batchFlow.state.value.data + + return currentData + .filter { d -> d.data.any { ids.contains(it.id) } } + .map { it.key } + .toSet() + } + + private fun SortByTypeUM.toRequestOrder(): TokenMarketListConfig.Order { + return when (this) { + SortByTypeUM.Rating -> TokenMarketListConfig.Order.ByRating + SortByTypeUM.Trending -> TokenMarketListConfig.Order.Trending + SortByTypeUM.ExperiencedBuyers -> TokenMarketListConfig.Order.Buyers + SortByTypeUM.TopGainers -> TokenMarketListConfig.Order.TopGainers + SortByTypeUM.TopLosers -> TokenMarketListConfig.Order.TopLosers + } + } + + private fun TrendInterval.toBatchRequestInterval(): TokenMarketListConfig.Interval { + return when (this) { + TrendInterval.H24 -> TokenMarketListConfig.Interval.H24 + TrendInterval.D7 -> TokenMarketListConfig.Interval.WEEK + TrendInterval.M1 -> TokenMarketListConfig.Interval.MONTH + } + } + + private fun TrendInterval.toRequestInterval(): PriceChangeInterval { + return when (this) { + TrendInterval.H24 -> PriceChangeInterval.H24 + TrendInterval.D7 -> PriceChangeInterval.WEEK + TrendInterval.M1 -> PriceChangeInterval.MONTH + } + } + + private fun Flow.onEachWithPrevious(operation: suspend (prev: T?, value: T) -> Unit): Flow = flow { + var prev: T? = null + collect { value -> + operation(prev, value) + prev = value + emit(value) + } + } +} \ No newline at end of file diff --git a/features/markets/impl/src/main/kotlin/com/tangem/features/markets/model/statemanager/MarketsListUMStateManager.kt b/features/markets/impl/src/main/kotlin/com/tangem/features/markets/model/statemanager/MarketsListUMStateManager.kt new file mode 100644 index 0000000000..d845850f44 --- /dev/null +++ b/features/markets/impl/src/main/kotlin/com/tangem/features/markets/model/statemanager/MarketsListUMStateManager.kt @@ -0,0 +1,166 @@ +package com.tangem.features.markets.model.statemanager + +import androidx.compose.runtime.Stable +import com.tangem.core.ui.components.bottomsheets.TangemBottomSheetConfig +import com.tangem.core.ui.components.fields.entity.SearchBarUM +import com.tangem.core.ui.event.consumedEvent +import com.tangem.core.ui.event.triggeredEvent +import com.tangem.core.ui.extensions.resourceReference +import com.tangem.features.markets.impl.R +import com.tangem.features.markets.ui.entity.SortByBottomSheetContentUM +import com.tangem.features.markets.ui.entity.ListUM +import com.tangem.features.markets.ui.entity.MarketsListItemUM +import com.tangem.features.markets.ui.entity.MarketsListUM +import com.tangem.features.markets.ui.entity.SortByTypeUM +import kotlinx.collections.immutable.ImmutableList +import kotlinx.coroutines.flow.* + +@Stable +internal class MarketsListUMStateManager( + private val onLoadMoreUiItems: () -> Unit, + private val visibleItemsChanged: (itemsKeys: List) -> Unit, + private val onRetryButtonClicked: () -> Unit, +) { + + private var sortByBottomSheetIsShown + get() = state.value.sortByBottomSheet.isShow + set(value) = state.update { it.copy(sortByBottomSheet = it.sortByBottomSheet.copy(isShow = value)) } + + var searchQuery + get() = state.value.searchBar.query + private set(value) = state.update { + it.copy( + searchBar = it.searchBar.copy( + query = value, + isActive = value.isNotEmpty(), + ), + ) + } + + var isInSearchState + get() = state.value.searchBar.isActive + private set(value) = state.update { it.copy(searchBar = it.searchBar.copy(isActive = value)) } + + var selectedSortByType + get() = state.value.selectedSortBy + set(value) = state.update { + it.copy( + selectedSortBy = value, + sortByBottomSheet = it.sortByBottomSheet.copy( + content = (it.sortByBottomSheet.content as SortByBottomSheetContentUM).copy( + selectedOption = value, + ), + ), + list = if (it.list is ListUM.Content && it.selectedSortBy != value) { + it.list.copy(triggerScrollReset = triggeredEvent(Unit) { consumeTriggerResetScrollEvent() }) + } else { + it.list + }, + ) + } + + var selectedInterval + get() = state.value.selectedInterval + set(value) = state.update { + it.copy( + selectedInterval = value, + list = if (it.list is ListUM.Content && + it.selectedSortBy != SortByTypeUM.Rating && + it.selectedInterval != value + ) { + it.list.copy(triggerScrollReset = triggeredEvent(Unit) { consumeTriggerResetScrollEvent() }) + } else { + it.list + }, + ) + } + + val state = MutableStateFlow(state()) + val isInSearchStateFlow = state.map { it.searchBar.isActive }.distinctUntilChanged() + val searchQueryFlow = state.map { it.searchBar.query }.distinctUntilChanged() + + fun onUiItemsChanged( + isInErrorState: Boolean, + isSearchNotFound: Boolean, + uiItems: ImmutableList, + ) { + state.update { + when { + isInErrorState -> { + it.copy( + list = ListUM.LoadingError(onRetryClicked = onRetryButtonClicked), + ) + } + isSearchNotFound -> { + it.copy(list = ListUM.SearchNothingFound) + } + uiItems.isEmpty() -> { + it.copy(list = ListUM.Loading) + } + else -> { + it.copy( + list = ListUM.Content( + items = uiItems, + loadMore = onLoadMoreUiItems, + visibleIdsChanged = visibleItemsChanged, + showUnder100kTokens = true, + onShowTokensUnder100kClicked = { }, + triggerScrollReset = consumedEvent(), + ), + ) + } + } + } + } + + private fun state(): MarketsListUM = MarketsListUM( + list = ListUM.Loading, + searchBar = SearchBarUM( + placeholderText = resourceReference(R.string.manage_tokens_search_placeholder), + query = "", + onQueryChange = { searchQuery = it }, + isActive = false, + onActiveChange = { }, + ), + selectedSortBy = SortByTypeUM.Rating, + selectedInterval = MarketsListUM.TrendInterval.H24, + onIntervalClick = { selectedInterval = it }, + onSortByButtonClick = { sortByBottomSheetIsShown = true }, + sortByBottomSheet = TangemBottomSheetConfig( + isShow = false, + onDismissRequest = { sortByBottomSheetIsShown = false }, + content = SortByBottomSheetContentUM( + selectedOption = SortByTypeUM.Rating, + onOptionClicked = ::onBottomSheetOptionClicked, + ), + ), + ) + + private fun onBottomSheetOptionClicked(sortByTypeUM: SortByTypeUM) { + state.update { + it.copy( + selectedSortBy = sortByTypeUM, + sortByBottomSheet = it.sortByBottomSheet.copy( + isShow = false, + content = (it.sortByBottomSheet.content as SortByBottomSheetContentUM).copy( + selectedOption = sortByTypeUM, + ), + ), + ) + } + } + + private fun consumeTriggerResetScrollEvent() { + state.update { + it.copy( + list = if (it.list is ListUM.Content) { + it.list.copy( + triggerScrollReset = consumedEvent(), + ) + } else { + it.list + }, + ) + } + } +} \ No newline at end of file diff --git a/features/markets/impl/src/main/kotlin/com/tangem/features/markets/model/utils/LoggingUtils.kt b/features/markets/impl/src/main/kotlin/com/tangem/features/markets/model/utils/LoggingUtils.kt new file mode 100644 index 0000000000..e9cc0e8b31 --- /dev/null +++ b/features/markets/impl/src/main/kotlin/com/tangem/features/markets/model/utils/LoggingUtils.kt @@ -0,0 +1,58 @@ +package com.tangem.features.markets.model.utils + +import com.tangem.domain.markets.TokenMarket +import com.tangem.domain.markets.TokenMarketListConfig +import com.tangem.domain.markets.TokenMarketUpdateRequest +import com.tangem.pagination.BatchAction +import com.tangem.pagination.BatchUpdateResult +import com.tangem.pagination.PaginationStatus +import timber.log.Timber + +internal fun logStatus(tag: String, status: PaginationStatus>) { + Timber.tag(tag).d( + """ + Status + $status + """.trimIndent(), + ) +} + +internal fun logAction(tag: String, action: BatchAction) { + when (action) { + is BatchAction.Reload -> Timber.tag(tag).d( + """ + Reload = ${action.requestParams} + """.trimIndent(), + ) + is BatchAction.UpdateBatches -> Timber.tag(tag).d( + """ + To update: + keys: ${action.keys.toList()} + updateType: ${action.updateRequest.javaClass.simpleName} + """.trimIndent(), + ) + else -> Timber.tag(tag).d( + """ + $action + """.trimIndent(), + ) + } +} + +internal fun logUpdateResults( + tag: String, + updateResult: Pair>>, +) { + val sec = when (val s = updateResult.second) { + is BatchUpdateResult.Success -> "Success" + is BatchUpdateResult.Error -> s.throwable.toString() + } + + Timber.tag(tag).d( + """ + updateResults + request: ${updateResult.first} + result: $sec + """.trimIndent(), + ) +} \ No newline at end of file diff --git a/features/markets/impl/src/main/kotlin/com/tangem/features/markets/ui/MarketsList.kt b/features/markets/impl/src/main/kotlin/com/tangem/features/markets/ui/MarketsList.kt new file mode 100644 index 0000000000..3ff1f1d4e7 --- /dev/null +++ b/features/markets/impl/src/main/kotlin/com/tangem/features/markets/ui/MarketsList.kt @@ -0,0 +1,269 @@ +package com.tangem.features.markets.ui + +import androidx.activity.compose.BackHandler +import androidx.compose.animation.AnimatedVisibility +import androidx.compose.foundation.background +import androidx.compose.foundation.layout.* +import androidx.compose.foundation.lazy.rememberLazyListState +import androidx.compose.material3.Text +import androidx.compose.runtime.Composable +import androidx.compose.runtime.LaunchedEffect +import androidx.compose.runtime.getValue +import androidx.compose.ui.Alignment +import androidx.compose.ui.Modifier +import androidx.compose.ui.layout.onGloballyPositioned +import androidx.compose.ui.platform.LocalDensity +import androidx.compose.ui.platform.LocalFocusManager +import androidx.compose.ui.platform.LocalSoftwareKeyboardController +import androidx.compose.ui.res.stringResource +import androidx.compose.ui.tooling.preview.Preview +import androidx.compose.ui.unit.Dp +import androidx.compose.ui.unit.dp +import com.tangem.core.ui.components.Keyboard +import com.tangem.core.ui.components.SpacerH12 +import com.tangem.core.ui.components.bottomsheets.TangemBottomSheetConfig +import com.tangem.core.ui.components.buttons.SecondarySmallButton +import com.tangem.core.ui.components.buttons.SmallButtonConfig +import com.tangem.core.ui.components.buttons.common.TangemButtonIconPosition +import com.tangem.core.ui.components.buttons.segmentedbutton.SegmentedButtons +import com.tangem.core.ui.components.fields.SearchBar +import com.tangem.core.ui.components.fields.entity.SearchBarUM +import com.tangem.core.ui.components.keyboardAsState +import com.tangem.core.ui.event.consumedEvent +import com.tangem.core.ui.extensions.resolveReference +import com.tangem.core.ui.extensions.resourceReference +import com.tangem.core.ui.res.TangemTheme +import com.tangem.core.ui.res.TangemThemePreview +import com.tangem.features.markets.component.BottomSheetState +import com.tangem.features.markets.impl.R +import com.tangem.features.markets.ui.components.MarketsListLazyColumn +import com.tangem.features.markets.ui.components.MarketsListSortByBottomSheet +import com.tangem.features.markets.ui.entity.ListUM +import com.tangem.features.markets.ui.entity.MarketsListUM +import com.tangem.features.markets.ui.entity.SortByBottomSheetContentUM +import com.tangem.features.markets.ui.entity.SortByTypeUM +import com.tangem.features.markets.ui.preview.MarketChartListItemPreviewDataProvider +import kotlinx.collections.immutable.persistentListOf +import kotlinx.collections.immutable.toImmutableList + +@Composable +internal fun MarketsList( + state: MarketsListUM, + onHeaderSizeChange: (Dp) -> Unit, + bottomSheetState: BottomSheetState, + modifier: Modifier = Modifier, +) { + Content( + modifier = modifier, + state = state, + onHeaderSizeChange = onHeaderSizeChange, + ) + MarketsListSortByBottomSheet(config = state.sortByBottomSheet) + KeyboardEvents( + isSortByBottomSheetShown = state.sortByBottomSheet.isShow, + bottomSheetState = bottomSheetState, + ) +} + +@Composable +private fun Content(state: MarketsListUM, onHeaderSizeChange: (Dp) -> Unit, modifier: Modifier = Modifier) { + val density = LocalDensity.current + + Column( + modifier = modifier + .fillMaxSize() + .imePadding() + .background(color = TangemTheme.colors.background.primary), + ) { + SearchBar( + modifier = Modifier + .background(color = TangemTheme.colors.background.primary) + .padding( + start = TangemTheme.dimens.spacing16, + end = TangemTheme.dimens.spacing16, + bottom = TangemTheme.dimens.spacing4, + ) + .onGloballyPositioned { + with(density) { onHeaderSizeChange(it.size.height.toDp()) } + }, + state = state.searchBar, + ) + Spacer(Modifier.height(TangemTheme.dimens.spacing20)) + Column(Modifier.padding(horizontal = TangemTheme.dimens.size16)) { + Title(isInSearchMode = state.isInSearchMode) + AnimatedVisibility(state.isInSearchMode.not()) { + Column { + SpacerH12() + Options( + sortByTypeUM = state.selectedSortBy, + trendInterval = state.selectedInterval, + onIntervalClick = state.onIntervalClick, + onSortByClick = state.onSortByButtonClick, + ) + } + } + } + SpacerH12() + ItemsList( + isInSearchMode = state.isInSearchMode, + state = state.list, + ) + } +} + +@Composable +private fun Title(isInSearchMode: Boolean, modifier: Modifier = Modifier) { + Text( + modifier = modifier, + text = if (isInSearchMode) { + stringResource(id = R.string.markets_search_result_title) + } else { + stringResource(id = R.string.markets_common_title) + }, + style = TangemTheme.typography.h3, + color = TangemTheme.colors.text.primary1, + ) +} + +@Composable +private fun Options( + sortByTypeUM: SortByTypeUM, + trendInterval: MarketsListUM.TrendInterval, + onSortByClick: () -> Unit, + onIntervalClick: (MarketsListUM.TrendInterval) -> Unit, + modifier: Modifier = Modifier, +) { + Row( + modifier = modifier + .height(IntrinsicSize.Max) + .fillMaxWidth(), + horizontalArrangement = Arrangement.SpaceBetween, + ) { + SecondarySmallButton( + config = SmallButtonConfig( + text = sortByTypeUM.text, + onClick = onSortByClick, + icon = TangemButtonIconPosition.End(iconResId = R.drawable.ic_chevron_24), + ), + ) + SegmentedButtons( + config = persistentListOf( + MarketsListUM.TrendInterval.H24, + MarketsListUM.TrendInterval.D7, + MarketsListUM.TrendInterval.M1, + ), + color = TangemTheme.colors.button.secondary, + initialSelectedItem = trendInterval, + onClick = onIntervalClick, + modifier = Modifier + .width(160.dp) + .fillMaxHeight(), + ) { + Box( + Modifier + .fillMaxSize() + .align(Alignment.Center) + .padding( + vertical = TangemTheme.dimens.spacing4, + ), + ) { + Text( + modifier = Modifier.align(Alignment.Center), + text = it.text.resolveReference(), + style = TangemTheme.typography.caption1, + color = TangemTheme.colors.text.primary1, + ) + } + } + } +} + +@Composable +private fun ItemsList(isInSearchMode: Boolean, state: ListUM, modifier: Modifier = Modifier) { + val searchLazyListState = rememberLazyListState() + val mainLazyListState = rememberLazyListState() + + MarketsListLazyColumn( + modifier = modifier, + state = state, + isInSearchMode = isInSearchMode, + lazyListState = if (isInSearchMode) { + searchLazyListState + } else { + mainLazyListState + }, + ) +} + +@Composable +private fun KeyboardEvents(isSortByBottomSheetShown: Boolean, bottomSheetState: BottomSheetState) { + val keyboardController = LocalSoftwareKeyboardController.current + val keyboard by keyboardAsState() + val focusManager = LocalFocusManager.current + + BackHandler(enabled = keyboard is Keyboard.Opened) { + keyboardController?.hide() + } + + LaunchedEffect(keyboard) { + if (keyboard is Keyboard.Closed) { + focusManager.clearFocus() + } + } + + LaunchedEffect(isSortByBottomSheetShown) { + keyboardController?.hide() + } + + LaunchedEffect(bottomSheetState) { + if (bottomSheetState == BottomSheetState.COLLAPSED) { + focusManager.clearFocus() + } + } +} + +//region: Preview + +@Preview +@Composable +private fun Preview() { + TangemThemePreview { + MarketsList( + state = MarketsListUM( + list = ListUM.Content( + items = MarketChartListItemPreviewDataProvider().values + .flatMap { item -> List(size = 10) { item } } + .mapIndexed { index, item -> + item.copy(id = index.toString()) + } + .toImmutableList(), + showUnder100kTokens = false, + loadMore = {}, + visibleIdsChanged = {}, + onShowTokensUnder100kClicked = {}, + triggerScrollReset = consumedEvent(), + ), + searchBar = SearchBarUM( + placeholderText = resourceReference(R.string.manage_tokens_search_placeholder), + query = "", + onQueryChange = {}, + isActive = false, + onActiveChange = { }, + ), + selectedSortBy = SortByTypeUM.Rating, + selectedInterval = MarketsListUM.TrendInterval.H24, + onIntervalClick = {}, + onSortByButtonClick = {}, + sortByBottomSheet = TangemBottomSheetConfig( + isShow = false, + onDismissRequest = {}, + content = SortByBottomSheetContentUM(selectedOption = SortByTypeUM.Rating) {}, + ), + ), + onHeaderSizeChange = {}, + bottomSheetState = BottomSheetState.EXPANDED, + ) + } +} + +//endregion: Preview \ No newline at end of file diff --git a/features/markets/impl/src/main/kotlin/com/tangem/features/markets/ui/components/MarketsListItem.kt b/features/markets/impl/src/main/kotlin/com/tangem/features/markets/ui/components/MarketsListItem.kt new file mode 100644 index 0000000000..847f063309 --- /dev/null +++ b/features/markets/impl/src/main/kotlin/com/tangem/features/markets/ui/components/MarketsListItem.kt @@ -0,0 +1,451 @@ +package com.tangem.features.markets.ui.components + +import android.content.res.Configuration +import androidx.compose.animation.Animatable +import androidx.compose.animation.core.FastOutSlowInEasing +import androidx.compose.animation.core.snap +import androidx.compose.animation.core.tween +import androidx.compose.foundation.ExperimentalFoundationApi +import androidx.compose.foundation.Image +import androidx.compose.foundation.background +import androidx.compose.foundation.clickable +import androidx.compose.foundation.gestures.AnchoredDraggableState +import androidx.compose.foundation.gestures.DraggableAnchors +import androidx.compose.foundation.gestures.Orientation +import androidx.compose.foundation.gestures.anchoredDraggable +import androidx.compose.foundation.interaction.MutableInteractionSource +import androidx.compose.foundation.interaction.collectIsDraggedAsState +import androidx.compose.foundation.layout.* +import androidx.compose.material.ripple.rememberRipple +import androidx.compose.material3.Button +import androidx.compose.material3.Text +import androidx.compose.runtime.* +import androidx.compose.ui.Alignment +import androidx.compose.ui.Modifier +import androidx.compose.ui.draw.clip +import androidx.compose.ui.graphics.ColorFilter +import androidx.compose.ui.graphics.RectangleShape +import androidx.compose.ui.graphics.vector.ImageVector +import androidx.compose.ui.platform.LocalDensity +import androidx.compose.ui.res.vectorResource +import androidx.compose.ui.text.style.TextOverflow +import androidx.compose.ui.tooling.preview.Preview +import androidx.compose.ui.tooling.preview.PreviewParameter +import androidx.compose.ui.unit.IntOffset +import com.tangem.common.ui.charts.MarketChartMini +import com.tangem.common.ui.charts.state.MarketChartLook +import com.tangem.common.ui.charts.state.MarketChartRawData +import com.tangem.core.ui.components.* +import com.tangem.core.ui.components.currency.icon.CoinIcon +import com.tangem.core.ui.components.marketprice.PriceChangeInPercent +import com.tangem.core.ui.components.marketprice.PriceChangeType +import com.tangem.core.ui.res.LocalHapticManager +import com.tangem.core.ui.res.LocalWindowSize +import com.tangem.core.ui.res.TangemTheme +import com.tangem.core.ui.res.TangemThemePreview +import com.tangem.core.ui.windowsize.WindowSizeType +import com.tangem.features.markets.impl.R +import com.tangem.features.markets.ui.entity.MarketsListItemUM +import com.tangem.features.markets.ui.preview.MarketChartListItemPreviewDataProvider +import com.tangem.utils.StringsSigns.MINUS +import kotlinx.coroutines.launch +import kotlin.math.roundToInt +import kotlin.random.Random + +internal enum class DragValue { Start, End } + +const val SWIPE_THRESHOLD_PERCENT = 0.8f +const val SWIPE_VELOCITY_THRESHOLD = 20f + +@Suppress("LongMethod") +@OptIn(ExperimentalFoundationApi::class) +@Composable +fun MarketsListItem( + model: MarketsListItemUM, + modifier: Modifier = Modifier, + onClick: () -> Unit = {}, + onSwipeToAction: () -> Unit = {}, +) { + val actionWidth = TangemTheme.dimens.size68 + val actionWidthPx = with(LocalDensity.current) { actionWidth.toPx() } + + val hapticManager = LocalHapticManager.current + + val anchors = DraggableAnchors { + DragValue.Start at 0f + DragValue.End at -actionWidthPx + } + val state = remember { + AnchoredDraggableState( + initialValue = DragValue.Start, + anchors = anchors, + positionalThreshold = { it * (1 - SWIPE_THRESHOLD_PERCENT) }, + velocityThreshold = { SWIPE_VELOCITY_THRESHOLD }, + animationSpec = tween(easing = FastOutSlowInEasing), + confirmValueChange = { it == DragValue.Start }, + ) + } + val dragInteractionSource = remember { MutableInteractionSource() } + val clickInteractionSource = remember { MutableInteractionSource() } + val isInDraggedState by dragInteractionSource.collectIsDraggedAsState() + + LaunchedEffect(Unit) { + var actionPerformed = false + var releasePerformed = true + launch { + snapshotFlow { state.offset } + .collect { + val border = -actionWidthPx * SWIPE_THRESHOLD_PERCENT + if (it < border && actionPerformed.not()) { + hapticManager.vibrateLong() + actionPerformed = true + releasePerformed = false + } + + if (it > border) { + if (releasePerformed.not()) { + hapticManager.vibrateShort() + releasePerformed = true + } + actionPerformed = false + } + } + } + launch { + snapshotFlow { isInDraggedState } + .collect { + if (it.not() && actionPerformed) { + releasePerformed = true + onSwipeToAction() + } + } + } + } + + Box( + modifier = Modifier + .height(intrinsicSize = IntrinsicSize.Min) + .fillMaxWidth(), + ) { + Box( + modifier = Modifier + .align(Alignment.TopEnd) + .fillMaxHeight() + .offset { + IntOffset( + x = actionWidthPx.roundToInt() + + state + .requireOffset() + .toInt(), + y = 0, + ) + } + .width(actionWidth) + .background(TangemTheme.colors.control.checked), + contentAlignment = Alignment.Center, + ) { + Image( + modifier = Modifier.size(TangemTheme.dimens.size28), + imageVector = ImageVector.vectorResource(id = R.drawable.ic_plus_mini_28), + colorFilter = ColorFilter.tint(TangemTheme.colors.icon.primary2), + contentDescription = null, + ) + } + + Box( + modifier = modifier + .align(Alignment.CenterStart) + .clip(RectangleShape) + .offset { + IntOffset( + x = state + .requireOffset() + .toInt(), + y = 0, + ) + } + .anchoredDraggable( + state = state, + orientation = Orientation.Horizontal, + interactionSource = dragInteractionSource, + ) + .clickable( + enabled = true, + interactionSource = clickInteractionSource, + indication = rememberRipple(), + onClick = onClick, + ), + ) { + MarketsListItemContent(model = model) + } + } +} + +@Composable +private fun MarketsListItemContent(model: MarketsListItemUM, modifier: Modifier = Modifier) { + val windowSize = LocalWindowSize.current + + Row( + modifier = modifier.padding( + horizontal = TangemTheme.dimens.spacing16, + vertical = TangemTheme.dimens.spacing15, + ), + verticalAlignment = Alignment.CenterVertically, + ) { + CoinIcon( + modifier = Modifier.size(TangemTheme.dimens.size36), + url = model.iconUrl, + alpha = 1f, + colorFilter = null, + fallbackResId = R.drawable.ic_custom_token_44, + ) + + SpacerW12() + + Column(modifier = Modifier.weight(1f)) { + Row( + modifier = Modifier.fillMaxWidth(), + horizontalArrangement = Arrangement.SpaceBetween, + ) { + TokenTitle( + modifier = Modifier.weight(1f, fill = false), + name = model.name, + currencySymbol = model.currencySymbol, + ) + SpacerW8() + TokenPriceText( + modifier = Modifier.alignByBaseline(), + price = model.price.text, + priceChangeType = model.price.changeType, + ) + } + + SpacerH(height = TangemTheme.dimens.spacing2) + + Row( + modifier = Modifier.fillMaxWidth(), + horizontalArrangement = Arrangement.SpaceBetween, + verticalAlignment = Alignment.Bottom, + ) { + TokenSubtitle( + modifier = Modifier + .weight(1f, fill = false) + .alignByBaseline(), + ratingPosition = model.ratingPosition, + marketCap = model.marketCap, + ) + PriceChangeInPercent( + modifier = Modifier.alignByBaseline(), + textStyle = TangemTheme.typography.caption2, + type = model.trendType, + valueInPercent = model.trendPercentText, + ) + } + } + + if (windowSize.widthAtLeast(WindowSizeType.Small)) { + Spacer(Modifier.width(TangemTheme.dimens.spacing10)) + + Chart( + chartType = model.chartType, + chartRawData = model.chardData, + ) + } + } +} + +@Composable +private fun TokenTitle(name: String, currencySymbol: String, modifier: Modifier = Modifier) { + Row(modifier = modifier) { + Text( + modifier = Modifier + .weight(1f, fill = false) + .alignByBaseline(), + text = name, + color = TangemTheme.colors.text.primary1, + style = TangemTheme.typography.subtitle2, + maxLines = 1, + overflow = TextOverflow.Ellipsis, + ) + SpacerW4() + Text( + modifier = Modifier.alignByBaseline(), + text = currencySymbol, + color = TangemTheme.colors.text.tertiary, + style = TangemTheme.typography.caption1, + maxLines = 1, + overflow = TextOverflow.Visible, + ) + } +} + +@Composable +private fun TokenSubtitle(ratingPosition: String?, marketCap: String?, modifier: Modifier = Modifier) { + Row( + modifier = modifier, + verticalAlignment = Alignment.CenterVertically, + ) { + TokenRatingPlace(ratingPosition = ratingPosition) + SpacerW4() + TokenMarketCapText(text = marketCap ?: "") + } +} + +@Composable +private fun RowScope.TokenRatingPlace(ratingPosition: String?) { + Box( + modifier = Modifier + .alignByBaseline() + .heightIn(min = TangemTheme.dimens.size16) + .background( + color = TangemTheme.colors.field.primary, + shape = TangemTheme.shapes.roundedCornersSmall2, + ) + .padding(horizontal = TangemTheme.dimens.spacing5), + ) { + Text( + text = ratingPosition ?: MINUS, + color = TangemTheme.colors.text.tertiary, + style = TangemTheme.typography.caption1, + maxLines = 1, + ) + } +} + +@Composable +private fun RowScope.TokenMarketCapText(text: String) { + Text( + modifier = Modifier.alignByBaseline(), + text = text, + color = TangemTheme.colors.text.tertiary, + style = TangemTheme.typography.caption2, + maxLines = 1, + overflow = TextOverflow.Ellipsis, + ) +} + +@Composable +private fun TokenPriceText(price: String, modifier: Modifier = Modifier, priceChangeType: PriceChangeType? = null) { + val growColor = TangemTheme.colors.text.accent + val fallColor = TangemTheme.colors.text.warning + val generalColor = TangemTheme.colors.text.primary1 + + val color = remember { Animatable(generalColor) } + + LaunchedEffect(price) { + if (priceChangeType != null) { + val nextColor = when (priceChangeType) { + PriceChangeType.UP, + -> growColor + PriceChangeType.DOWN -> fallColor + PriceChangeType.NEUTRAL -> return@LaunchedEffect + } + + color.animateTo(nextColor, snap()) + color.animateTo(generalColor, tween(durationMillis = 500)) + } + } + + Text( + modifier = modifier, + text = price, + color = color.value, + maxLines = 1, + style = TangemTheme.typography.body2, + overflow = TextOverflow.Visible, + ) +} + +@Composable +private fun Chart(chartType: MarketChartLook.Type, chartRawData: MarketChartRawData?) { + val chartWidth = TangemTheme.dimens.size56 + Box( + modifier = Modifier + .padding(vertical = TangemTheme.dimens.spacing2) + .size(height = TangemTheme.dimens.size24, width = chartWidth), + ) { + if (chartRawData != null) { + MarketChartMini( + rawData = chartRawData, + type = chartType, + ) + } else { + RectangleShimmer( + modifier = Modifier + .fillMaxWidth() + .height(TangemTheme.dimens.size12) + .align(Alignment.Center), + radius = TangemTheme.dimens.radius3, + ) + } + } +} + +// region preview +@Preview(showBackground = true, widthDp = 360, name = "normal") +@Preview(showBackground = true, widthDp = 360, name = "normal night", uiMode = Configuration.UI_MODE_NIGHT_YES) +@Preview(showBackground = true, widthDp = 320, name = "small width") +@Composable +private fun Preview(@PreviewParameter(MarketChartListItemPreviewDataProvider::class) state: MarketsListItemUM) { + TangemThemePreview { + var state1 by remember { mutableStateOf(state) } + var state2 by remember { mutableStateOf(state) } + var prices by remember { + mutableStateOf( + listOf( + 100 to PriceChangeType.NEUTRAL, + 200 to PriceChangeType.NEUTRAL, + ), + ) + } + + Column(modifier = Modifier.background(TangemTheme.colors.background.primary)) { + MarketsListItem( + modifier = Modifier, + model = state1, + ) + MarketsListItem( + modifier = Modifier, + model = state2, + ) + Row { + Button( + onClick = { + state1 = state1.copy( + trendType = PriceChangeType.entries.random(), + ) + state2 = state2.copy( + trendType = PriceChangeType.entries.random(), + ) + }, + ) { Text(text = "trend") } + + Button( + onClick = { + prices = prices.map { + if (Random.nextBoolean()) { + it.first.inc() to PriceChangeType.UP + } else { + it.first.dec() to PriceChangeType.DOWN + } + } + state1 = state1.copy( + price = MarketsListItemUM.Price( + text = "0.${prices[0].first}023 $", + changeType = prices[0].second, + ), + ) + state2 = state2.copy( + price = MarketsListItemUM.Price( + text = "0.${prices[1].first}023 $", + changeType = prices[1].second, + ), + ) + }, + ) { Text(text = "price") } + } + } + } +} + +// endregion preview \ No newline at end of file diff --git a/features/markets/impl/src/main/kotlin/com/tangem/features/markets/ui/components/MarketsListItemPlaceholder.kt b/features/markets/impl/src/main/kotlin/com/tangem/features/markets/ui/components/MarketsListItemPlaceholder.kt new file mode 100644 index 0000000000..251844c2d6 --- /dev/null +++ b/features/markets/impl/src/main/kotlin/com/tangem/features/markets/ui/components/MarketsListItemPlaceholder.kt @@ -0,0 +1,110 @@ +package com.tangem.features.markets.ui.components + +import android.content.res.Configuration +import androidx.compose.foundation.background +import androidx.compose.foundation.layout.* +import androidx.compose.runtime.Composable +import androidx.compose.ui.Alignment +import androidx.compose.ui.Modifier +import androidx.compose.ui.platform.LocalDensity +import androidx.compose.ui.tooling.preview.Preview +import androidx.compose.ui.unit.sp +import com.tangem.core.ui.components.* +import com.tangem.core.ui.res.LocalWindowSize +import com.tangem.core.ui.res.TangemTheme +import com.tangem.core.ui.res.TangemThemePreview +import com.tangem.core.ui.windowsize.WindowSizeType + +@Suppress("LongMethod") +@Composable +fun MarketsListItemPlaceholder() { + val density = LocalDensity.current + val windowSize = LocalWindowSize.current + val sp12 = with(density) { 12.sp.toDp() } + + Row( + modifier = Modifier.padding( + horizontal = TangemTheme.dimens.spacing16, + vertical = TangemTheme.dimens.spacing15, + ), + verticalAlignment = Alignment.CenterVertically, + ) { + CircleShimmer(Modifier.size(TangemTheme.dimens.size36)) + + SpacerW12() + + Column(modifier = Modifier.weight(1f)) { + Row( + modifier = Modifier + .fillMaxWidth() + .padding(vertical = TangemTheme.dimens.spacing4), + horizontalArrangement = Arrangement.SpaceBetween, + ) { + RectangleShimmer( + modifier = Modifier + .width(TangemTheme.dimens.size70) + .height(sp12), + radius = TangemTheme.dimens.radius3, + ) + SpacerW8() + RectangleShimmer( + modifier = Modifier + .width(TangemTheme.dimens.size70) + .height(sp12), + radius = TangemTheme.dimens.radius3, + ) + } + + SpacerH(height = TangemTheme.dimens.spacing2) + + Row( + modifier = Modifier + .fillMaxWidth() + .padding(vertical = TangemTheme.dimens.spacing2), + horizontalArrangement = Arrangement.SpaceBetween, + verticalAlignment = Alignment.Bottom, + ) { + RectangleShimmer( + modifier = Modifier + .width(TangemTheme.dimens.size52) + .height(sp12), + radius = TangemTheme.dimens.radius3, + ) + RectangleShimmer( + modifier = Modifier + .width(TangemTheme.dimens.size52) + .height(sp12), + radius = TangemTheme.dimens.radius3, + ) + } + } + + if (windowSize.widthAtLeast(WindowSizeType.Small)) { + Spacer(Modifier.width(TangemTheme.dimens.spacing10)) + + Box { + RectangleShimmer( + modifier = Modifier + .align(Alignment.Center) + .width(TangemTheme.dimens.size56) + .height(TangemTheme.dimens.size12), + radius = TangemTheme.dimens.radius3, + ) + } + } + } +} + +@Preview(showBackground = true, widthDp = 360, name = "normal") +@Preview(showBackground = true, widthDp = 360, name = "normal night", uiMode = Configuration.UI_MODE_NIGHT_YES) +@Preview(showBackground = true, widthDp = 320, name = "small width") +@Composable +private fun Preview() { + TangemThemePreview { + Column(Modifier.background(TangemTheme.colors.background.tertiary)) { + repeat(20) { + MarketsListItemPlaceholder() + } + } + } +} \ No newline at end of file diff --git a/features/markets/impl/src/main/kotlin/com/tangem/features/markets/ui/components/MarketsListLazyColumn.kt b/features/markets/impl/src/main/kotlin/com/tangem/features/markets/ui/components/MarketsListLazyColumn.kt new file mode 100644 index 0000000000..dd7753fb72 --- /dev/null +++ b/features/markets/impl/src/main/kotlin/com/tangem/features/markets/ui/components/MarketsListLazyColumn.kt @@ -0,0 +1,222 @@ +package com.tangem.features.markets.ui.components + +import androidx.compose.foundation.layout.* +import androidx.compose.foundation.lazy.LazyColumn +import androidx.compose.foundation.lazy.LazyListState +import androidx.compose.foundation.lazy.items +import androidx.compose.foundation.lazy.rememberLazyListState +import androidx.compose.material3.Text +import androidx.compose.runtime.* +import androidx.compose.ui.Alignment +import androidx.compose.ui.Modifier +import androidx.compose.ui.geometry.Offset +import androidx.compose.ui.input.nestedscroll.NestedScrollConnection +import androidx.compose.ui.input.nestedscroll.NestedScrollSource +import androidx.compose.ui.input.nestedscroll.nestedScroll +import androidx.compose.ui.platform.LocalDensity +import androidx.compose.ui.res.stringResource +import com.tangem.core.ui.components.buttons.SecondarySmallButton +import com.tangem.core.ui.components.buttons.SmallButtonConfig +import com.tangem.core.ui.event.EventEffect +import com.tangem.core.ui.extensions.resourceReference +import com.tangem.core.ui.res.TangemTheme +import com.tangem.features.markets.impl.R +import com.tangem.features.markets.ui.entity.ListUM +import kotlinx.coroutines.launch + +private const val LOAD_NEXT_PAGE_ON_END_INDEX = 50 + +@Composable +@Suppress("LongMethod") +internal fun MarketsListLazyColumn( + state: ListUM, + isInSearchMode: Boolean, + lazyListState: LazyListState, + modifier: Modifier = Modifier, +) { + val bottomBarHeight = with(LocalDensity.current) { WindowInsets.systemBars.getBottom(this).toDp() } + val coroutineScope = rememberCoroutineScope() + + SideEffect { + if (state is ListUM.Loading) { + coroutineScope.launch { + lazyListState.scrollToItem(0) + } + } + } + + if (state is ListUM.Content) { + EventEffect(state.triggerScrollReset) { + lazyListState.scrollToItem(0) + } + } + + if (state is ListUM.Loading) { + LazyColumn( + modifier = Modifier.nestedScroll(DisableParentConnection), + state = rememberLazyListState(), + contentPadding = PaddingValues(bottom = bottomBarHeight), + userScrollEnabled = false, + ) { + items(count = 100, key = { it }) { + MarketsListItemPlaceholder() + } + } + } else { + LazyColumn( + modifier = modifier.nestedScroll(DisableParentConnection), + state = lazyListState, + contentPadding = PaddingValues(bottom = bottomBarHeight), + userScrollEnabled = true, + ) { + // ATTENTION! There should be no elements with a string key value except MarketsListItem! + when (state) { + is ListUM.LoadingError -> { + item(key = "loading error".hashCode()) { + LoadingErrorItem( + modifier = Modifier.fillParentMaxSize(), + onTryAgain = state.onRetryClicked, + ) + } + } + ListUM.SearchNothingFound -> { + item(key = "not found text".hashCode()) { + SearchNothingFoundText( + modifier = Modifier.fillParentMaxSize(), + ) + } + } + is ListUM.Content -> { + items( + items = state.items, + key = { it.id }, + ) { item -> + MarketsListItem(model = item) + } + + if (isInSearchMode && state.showUnder100kTokens.not()) { + item(key = "show tokens under 100k".hashCode()) { + ShowTokensUnder100kItem( + onShowTokensClick = state.onShowTokensUnder100kClicked, + ) + } + } + } + else -> {} + } + } + } + + VisibleItemsTracker(lazyListState, state) + + InfiniteListHandler( + listState = lazyListState, + buffer = LOAD_NEXT_PAGE_ON_END_INDEX, + onLoadMore = remember(state) { + { + if (state is ListUM.Content) { + state.loadMore() + } + } + }, + ) +} + +@Composable +private fun LoadingErrorItem(onTryAgain: () -> Unit, modifier: Modifier = Modifier) { + Box( + modifier + .padding( + horizontal = TangemTheme.dimens.spacing16, + vertical = TangemTheme.dimens.spacing12, + ) + .fillMaxWidth(), + contentAlignment = Alignment.Center, + ) { + UnableToLoadData(onRetryClick = onTryAgain) + } +} + +@Composable +private fun ShowTokensUnder100kItem(onShowTokensClick: () -> Unit, modifier: Modifier = Modifier) { + Column( + modifier = modifier + .padding( + horizontal = TangemTheme.dimens.spacing16, + vertical = TangemTheme.dimens.spacing12, + ) + .fillMaxWidth(), + verticalArrangement = Arrangement.spacedBy(TangemTheme.dimens.spacing12), + horizontalAlignment = Alignment.CenterHorizontally, + ) { + Text( + text = stringResource(R.string.markets_search_see_tokens_under_100k), + style = TangemTheme.typography.caption1, + color = TangemTheme.colors.text.tertiary, + ) + SecondarySmallButton( + config = SmallButtonConfig( + text = resourceReference(R.string.markets_search_show_tokens), + onClick = onShowTokensClick, + ), + ) + } +} + +@Composable +private fun SearchNothingFoundText(modifier: Modifier = Modifier) { + Box( + modifier = modifier, + contentAlignment = Alignment.Center, + ) { + Text( + text = stringResource(R.string.markets_search_token_no_result_title), + style = TangemTheme.typography.caption1, + color = TangemTheme.colors.text.tertiary, + ) + } +} + +@Composable +private fun VisibleItemsTracker(listState: LazyListState, state: ListUM) { + val visibleItems by remember { + derivedStateOf { + listState.layoutInfo.visibleItemsInfo.mapNotNull { it.key as? String } + } + } + + LaunchedEffect(listState.isScrollInProgress, visibleItems) { + if (state is ListUM.Content && listState.isScrollInProgress.not()) { + state.visibleIdsChanged(visibleItems) + } + } +} + +@Composable +fun InfiniteListHandler(listState: LazyListState, onLoadMore: () -> Unit, buffer: Int = 2) { + val loadMore by remember { + derivedStateOf { + val layoutInfo = listState.layoutInfo + val totalItemsNumber = layoutInfo.totalItemsCount + val lastVisibleItemIndex = (layoutInfo.visibleItemsInfo.lastOrNull()?.index ?: 0) + 1 + + lastVisibleItemIndex > totalItemsNumber - buffer + } + } + + val totalItemsCount by remember { derivedStateOf { listState.layoutInfo.totalItemsCount } } + var emitted by remember(totalItemsCount) { mutableStateOf(false) } + + LaunchedEffect(loadMore) { + if (loadMore && !emitted) { + emitted = true + onLoadMore() + } + } +} + +private object DisableParentConnection : NestedScrollConnection { + override fun onPostScroll(consumed: Offset, available: Offset, source: NestedScrollSource): Offset { + return available.copy(x = 0f) + } +} \ No newline at end of file diff --git a/features/markets/impl/src/main/kotlin/com/tangem/features/markets/ui/components/MarketsListSortByBottomSheet.kt b/features/markets/impl/src/main/kotlin/com/tangem/features/markets/ui/components/MarketsListSortByBottomSheet.kt new file mode 100644 index 0000000000..4ee563d08c --- /dev/null +++ b/features/markets/impl/src/main/kotlin/com/tangem/features/markets/ui/components/MarketsListSortByBottomSheet.kt @@ -0,0 +1,88 @@ +package com.tangem.features.markets.ui.components + +import android.content.res.Configuration +import androidx.compose.foundation.background +import androidx.compose.foundation.clickable +import androidx.compose.foundation.layout.Box +import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.padding +import androidx.compose.runtime.Composable +import androidx.compose.ui.Modifier +import androidx.compose.ui.draw.clip +import androidx.compose.ui.tooling.preview.Preview +import com.tangem.core.ui.components.bottomsheets.TangemBottomSheet +import com.tangem.core.ui.components.bottomsheets.TangemBottomSheetConfig +import com.tangem.core.ui.components.inputrow.InputRowChecked +import com.tangem.core.ui.components.inputrow.inner.DividerContainer +import com.tangem.core.ui.components.rows.CornersToRound +import com.tangem.core.ui.extensions.resourceReference +import com.tangem.core.ui.res.TangemTheme +import com.tangem.core.ui.res.TangemThemePreview +import com.tangem.features.markets.impl.R +import com.tangem.features.markets.ui.entity.SortByBottomSheetContentUM +import com.tangem.features.markets.ui.entity.SortByTypeUM + +@Composable +fun MarketsListSortByBottomSheet(config: TangemBottomSheetConfig) { + TangemBottomSheet( + config = config, + titleText = resourceReference(R.string.markets_sort_by_title), + containerColor = TangemTheme.colors.background.tertiary, + content = { Content(it) }, + ) +} + +@Composable +private fun Content(content: SortByBottomSheetContentUM) { + Column( + modifier = Modifier + .padding( + start = TangemTheme.dimens.spacing16, + end = TangemTheme.dimens.spacing16, + bottom = TangemTheme.dimens.spacing16, + ), + ) { + SortByTypeUM.entries.forEachIndexed { index, type -> + val cornersToRound = when (index) { + 0 -> CornersToRound.TOP_2 + SortByTypeUM.entries.lastIndex -> CornersToRound.BOTTOM_2 + else -> CornersToRound.ZERO + } + + DividerContainer( + modifier = Modifier + .clip(cornersToRound.getShape()) + .background(TangemTheme.colors.background.action) + .clickable { content.onOptionClicked(type) }, + showDivider = index != SortByTypeUM.entries.lastIndex, + ) { + InputRowChecked( + text = type.text, + checked = type == content.selectedOption, + ) + } + } + } +} + +@Preview(widthDp = 360, heightDp = 640) +@Preview(widthDp = 360, heightDp = 640, uiMode = Configuration.UI_MODE_NIGHT_YES) +@Composable +private fun Preview() { + TangemThemePreview( + alwaysShowBottomSheets = true, + ) { + Box(Modifier.background(TangemTheme.colors.background.secondary)) { + MarketsListSortByBottomSheet( + TangemBottomSheetConfig( + isShow = true, + onDismissRequest = {}, + content = SortByBottomSheetContentUM( + selectedOption = SortByTypeUM.Trending, + onOptionClicked = {}, + ), + ), + ) + } + } +} \ No newline at end of file diff --git a/features/markets/impl/src/main/kotlin/com/tangem/features/markets/ui/components/UnableToLoadData.kt b/features/markets/impl/src/main/kotlin/com/tangem/features/markets/ui/components/UnableToLoadData.kt new file mode 100644 index 0000000000..cf58422fb5 --- /dev/null +++ b/features/markets/impl/src/main/kotlin/com/tangem/features/markets/ui/components/UnableToLoadData.kt @@ -0,0 +1,47 @@ +package com.tangem.features.markets.ui.components + +import android.content.res.Configuration +import androidx.compose.foundation.layout.Arrangement +import androidx.compose.foundation.layout.Column +import androidx.compose.material3.Text +import androidx.compose.runtime.Composable +import androidx.compose.ui.Alignment +import androidx.compose.ui.Modifier +import androidx.compose.ui.res.stringResource +import androidx.compose.ui.tooling.preview.Preview +import com.tangem.core.ui.components.buttons.SecondarySmallButton +import com.tangem.core.ui.components.buttons.SmallButtonConfig +import com.tangem.core.ui.extensions.resourceReference +import com.tangem.core.ui.res.TangemTheme +import com.tangem.core.ui.res.TangemThemePreview +import com.tangem.features.markets.impl.R + +@Composable +internal fun UnableToLoadData(onRetryClick: () -> Unit, modifier: Modifier = Modifier) { + Column( + modifier = modifier, + verticalArrangement = Arrangement.spacedBy(TangemTheme.dimens.spacing12), + horizontalAlignment = Alignment.CenterHorizontally, + ) { + Text( + text = stringResource(R.string.markets_loading_error_title), + style = TangemTheme.typography.caption1, + color = TangemTheme.colors.text.tertiary, + ) + SecondarySmallButton( + config = SmallButtonConfig( + text = resourceReference(R.string.try_to_load_data_again_button_title), + onClick = onRetryClick, + ), + ) + } +} + +@Preview +@Preview(uiMode = Configuration.UI_MODE_NIGHT_YES) +@Composable +private fun Preview() { + TangemThemePreview { + UnableToLoadData(onRetryClick = {}) + } +} \ No newline at end of file diff --git a/features/markets/impl/src/main/kotlin/com/tangem/features/markets/ui/entity/MarketsListItemUM.kt b/features/markets/impl/src/main/kotlin/com/tangem/features/markets/ui/entity/MarketsListItemUM.kt new file mode 100644 index 0000000000..a561cf8517 --- /dev/null +++ b/features/markets/impl/src/main/kotlin/com/tangem/features/markets/ui/entity/MarketsListItemUM.kt @@ -0,0 +1,34 @@ +package com.tangem.features.markets.ui.entity + +import androidx.compose.runtime.Immutable +import com.tangem.common.ui.charts.state.MarketChartLook +import com.tangem.common.ui.charts.state.MarketChartRawData +import com.tangem.core.ui.components.marketprice.PriceChangeType + +@Immutable +data class MarketsListItemUM( + val id: String, + val name: String, + val currencySymbol: String, + val iconUrl: String?, + val ratingPosition: String?, + val marketCap: String?, + val price: Price, + val trendPercentText: String, + val trendType: PriceChangeType, + val chardData: MarketChartRawData?, + val showUnder100kMarketCap: Boolean = false, +) { + val chartType: MarketChartLook.Type = when (trendType) { + PriceChangeType.UP, + PriceChangeType.NEUTRAL, + -> MarketChartLook.Type.Growing + PriceChangeType.DOWN -> MarketChartLook.Type.Falling + } + + @Immutable + data class Price( + val text: String, + val changeType: PriceChangeType? = null, + ) +} \ No newline at end of file diff --git a/features/markets/impl/src/main/kotlin/com/tangem/features/markets/ui/entity/MarketsListUM.kt b/features/markets/impl/src/main/kotlin/com/tangem/features/markets/ui/entity/MarketsListUM.kt new file mode 100644 index 0000000000..9167060698 --- /dev/null +++ b/features/markets/impl/src/main/kotlin/com/tangem/features/markets/ui/entity/MarketsListUM.kt @@ -0,0 +1,58 @@ +package com.tangem.features.markets.ui.entity + +import androidx.compose.runtime.Immutable +import com.tangem.core.ui.components.bottomsheets.TangemBottomSheetConfig +import com.tangem.core.ui.components.fields.entity.SearchBarUM +import com.tangem.core.ui.event.StateEvent +import com.tangem.core.ui.extensions.TextReference +import com.tangem.core.ui.extensions.resourceReference +import com.tangem.features.markets.impl.R +import kotlinx.collections.immutable.ImmutableList + +internal data class MarketsListUM( + val list: ListUM, + val searchBar: SearchBarUM, + val selectedSortBy: SortByTypeUM, + val sortByBottomSheet: TangemBottomSheetConfig, + val selectedInterval: TrendInterval, + val onIntervalClick: (TrendInterval) -> Unit, + val onSortByButtonClick: () -> Unit, +) { + val isInSearchMode + get() = searchBar.isActive + + enum class TrendInterval(val text: TextReference) { + H24(resourceReference(R.string.markets_selector_interval_24h_title)), + D7(resourceReference(R.string.markets_selector_interval_7d_title)), + M1(resourceReference(R.string.markets_selector_interval_1m_title)), + } +} + +enum class SortByTypeUM(val text: TextReference) { + Rating(resourceReference(R.string.markets_sort_by_rating_title)), + Trending(resourceReference(R.string.markets_sort_by_trending_title)), + ExperiencedBuyers(resourceReference(R.string.markets_sort_by_experienced_buyers_title)), + TopGainers(resourceReference(R.string.markets_sort_by_top_gainers_title)), + TopLosers(resourceReference(R.string.markets_sort_by_top_losers_title)), +} + +@Immutable +sealed class ListUM { + + data class Content( + val items: ImmutableList, + val showUnder100kTokens: Boolean, + val loadMore: () -> Unit, + val visibleIdsChanged: (List) -> Unit, + val onShowTokensUnder100kClicked: () -> Unit, + val triggerScrollReset: StateEvent, + ) : ListUM() + + data object Loading : ListUM() + + data class LoadingError( + val onRetryClicked: () -> Unit, + ) : ListUM() + + data object SearchNothingFound : ListUM() +} \ No newline at end of file diff --git a/features/markets/impl/src/main/kotlin/com/tangem/features/markets/ui/entity/SortByBottomSheetContentUM.kt b/features/markets/impl/src/main/kotlin/com/tangem/features/markets/ui/entity/SortByBottomSheetContentUM.kt new file mode 100644 index 0000000000..af420055f5 --- /dev/null +++ b/features/markets/impl/src/main/kotlin/com/tangem/features/markets/ui/entity/SortByBottomSheetContentUM.kt @@ -0,0 +1,8 @@ +package com.tangem.features.markets.ui.entity + +import com.tangem.core.ui.components.bottomsheets.TangemBottomSheetConfigContent + +data class SortByBottomSheetContentUM( + val selectedOption: SortByTypeUM, + val onOptionClicked: (SortByTypeUM) -> Unit, +) : TangemBottomSheetConfigContent \ No newline at end of file diff --git a/features/markets/impl/src/main/kotlin/com/tangem/features/markets/ui/preview/MarketChartListItemPreviewDataProvider.kt b/features/markets/impl/src/main/kotlin/com/tangem/features/markets/ui/preview/MarketChartListItemPreviewDataProvider.kt new file mode 100644 index 0000000000..782d4bfbc8 --- /dev/null +++ b/features/markets/impl/src/main/kotlin/com/tangem/features/markets/ui/preview/MarketChartListItemPreviewDataProvider.kt @@ -0,0 +1,94 @@ +@file:Suppress("MagicNumber") +package com.tangem.features.markets.ui.preview + +import androidx.compose.ui.tooling.preview.datasource.CollectionPreviewParameterProvider +import com.tangem.common.ui.charts.state.MarketChartRawData +import com.tangem.core.ui.components.marketprice.PriceChangeType +import com.tangem.features.markets.ui.entity.MarketsListItemUM + +internal class MarketChartListItemPreviewDataProvider : CollectionPreviewParameterProvider( + collection = listOf( + MarketsListItemUM( + id = "1", + name = "Bitcoin", + currencySymbol = "BTC", + iconUrl = "", + ratingPosition = "10", + marketCap = "$6.233 B", + price = MarketsListItemUM.Price(text = "31 285.72$"), + trendPercentText = "12.43%", + trendType = PriceChangeType.UP, + chardData = MarketChartRawData( + y = listOf(0.4f, 0.2f, 0.4f, 0.1f, 0.4f, 2f, 5f, 0.1f, 2f, 2f, 3f), + ), + ), + MarketsListItemUM( + id = "1", + name = "Bitcoin", + currencySymbol = "BTC", + iconUrl = null, + ratingPosition = "10", + marketCap = "$6.233 B", + price = MarketsListItemUM.Price(text = "31 285.72$"), + trendPercentText = "12.43%", + trendType = PriceChangeType.NEUTRAL, + chardData = null, + ), + MarketsListItemUM( + id = "1", + name = "Bitcoin Bitcoin Bitcoin Bitcoin Bitcoin Bitcoin Bitcoin", + currencySymbol = "BTC", + iconUrl = null, + ratingPosition = "10", + marketCap = "$6.23348172384781234 B", + price = MarketsListItemUM.Price(text = "31 285.72$"), + trendPercentText = "12.43%", + trendType = PriceChangeType.DOWN, + chardData = MarketChartRawData( + y = listOf(0.4f, 0.2f, 0.4f, 0.1f, 0.4f, 2f, 5f, 0.1f, 2f, 2f, 3f), + ), + ), + MarketsListItemUM( + id = "1", + name = "Bitcoin", + currencySymbol = "BTC", + iconUrl = null, + ratingPosition = "10", + marketCap = null, + price = MarketsListItemUM.Price(text = "31 285.72$"), + trendPercentText = "12.43%", + trendType = PriceChangeType.UP, + chardData = MarketChartRawData( + y = listOf(0.4f, 0.2f, 0.4f, 0.1f, 0.4f, 2f, 5f, 0.1f, 2f, 2f, 3f), + ), + ), + MarketsListItemUM( + id = "1", + name = "Bitcoin", + currencySymbol = "BTC", + iconUrl = null, + ratingPosition = null, + marketCap = "$6.233 B", + price = MarketsListItemUM.Price(text = "31 285.72$"), + trendPercentText = "12.43%", + trendType = PriceChangeType.UP, + chardData = MarketChartRawData( + y = listOf(0.4f, 0.2f, 0.4f, 0.1f, 0.4f, 2f, 5f, 0.1f, 2f, 2f, 3f), + ), + ), + MarketsListItemUM( + id = "1", + name = "Bitcoin", + currencySymbol = "BTC", + iconUrl = null, + ratingPosition = null, + marketCap = null, + price = MarketsListItemUM.Price(text = "31 285.72$"), + trendPercentText = "12.43%", + trendType = PriceChangeType.UP, + chardData = MarketChartRawData( + y = listOf(0.4f, 0.2f, 0.4f, 0.1f, 0.4f, 2f, 5f, 0.1f, 2f, 2f, 3f), + ), + ), + ), +) \ No newline at end of file diff --git a/features/onboarding/build.gradle.kts b/features/onboarding/build.gradle.kts index 6629611e63..9f081a463f 100644 --- a/features/onboarding/build.gradle.kts +++ b/features/onboarding/build.gradle.kts @@ -42,6 +42,7 @@ dependencies { /** Compose libraries */ implementation(deps.compose.material) + implementation(deps.compose.material3) implementation(deps.compose.animation) implementation(deps.compose.foundation) implementation(deps.compose.ui) diff --git a/features/onboarding/src/main/java/com/tangem/feature/onboarding/api/OnboardingSeedPhraseScreen.kt b/features/onboarding/src/main/java/com/tangem/feature/onboarding/api/OnboardingSeedPhraseScreen.kt index 978f1ea01e..6db1217109 100644 --- a/features/onboarding/src/main/java/com/tangem/feature/onboarding/api/OnboardingSeedPhraseScreen.kt +++ b/features/onboarding/src/main/java/com/tangem/feature/onboarding/api/OnboardingSeedPhraseScreen.kt @@ -1,7 +1,6 @@ package com.tangem.feature.onboarding.api import androidx.activity.compose.BackHandler -import androidx.compose.foundation.isSystemInDarkTheme import androidx.compose.foundation.layout.* import androidx.compose.material.LinearProgressIndicator import androidx.compose.runtime.Composable @@ -19,11 +18,9 @@ class OnboardingSeedPhraseScreen : OnboardingSeedPhraseApi { @Composable override fun ScreenContent(uiState: OnboardingSeedPhraseState, subScreen: SeedPhraseScreen, progress: Float) { BackHandler(onBack = uiState.onBackClick) - TangemTheme(isDark = isSystemInDarkTheme()) { - Column { - ProgressIndicator(progress) - Content(subScreen, uiState) - } + Column { + ProgressIndicator(progress) + Content(subScreen, uiState) } } } diff --git a/features/onboarding/src/main/java/com/tangem/feature/onboarding/navigation/OnboardingRouter.kt b/features/onboarding/src/main/java/com/tangem/feature/onboarding/navigation/OnboardingRouter.kt index 5704da9b7f..b6bf1b0f60 100644 --- a/features/onboarding/src/main/java/com/tangem/feature/onboarding/navigation/OnboardingRouter.kt +++ b/features/onboarding/src/main/java/com/tangem/feature/onboarding/navigation/OnboardingRouter.kt @@ -4,9 +4,4 @@ package com.tangem.feature.onboarding.navigation * Onboarding router */ // TODO: Move to onboarding api module [REDACTED_JIRA] -interface OnboardingRouter { - - companion object { - const val CAN_SKIP_BACKUP = "onboarding_wallet_can_skip_backup" - } -} \ No newline at end of file +interface OnboardingRouter \ No newline at end of file diff --git a/features/push-notifications/api/.gitignore b/features/push-notifications/api/.gitignore new file mode 100644 index 0000000000..42afabfd2a --- /dev/null +++ b/features/push-notifications/api/.gitignore @@ -0,0 +1 @@ +/build \ No newline at end of file diff --git a/features/push-notifications/api/build.gradle.kts b/features/push-notifications/api/build.gradle.kts new file mode 100644 index 0000000000..8fd2b5a11b --- /dev/null +++ b/features/push-notifications/api/build.gradle.kts @@ -0,0 +1,18 @@ +plugins { + alias(deps.plugins.android.library) + alias(deps.plugins.kotlin.android) + id("configuration") +} + +android { + namespace = "com.tangem.features.pushnotifications.api" +} + +dependencies { + + /** AndroidX */ + implementation(deps.androidx.fragment.ktx) + + /** Core */ + implementation(projects.core.analytics.models) +} \ No newline at end of file diff --git a/features/push-notifications/api/src/main/java/com/tangem/features/pushnotifications/api/analytics/PushNotificationAnalyticEvents.kt b/features/push-notifications/api/src/main/java/com/tangem/features/pushnotifications/api/analytics/PushNotificationAnalyticEvents.kt new file mode 100644 index 0000000000..ae6f90b7a1 --- /dev/null +++ b/features/push-notifications/api/src/main/java/com/tangem/features/pushnotifications/api/analytics/PushNotificationAnalyticEvents.kt @@ -0,0 +1,37 @@ +package com.tangem.features.pushnotifications.api.analytics + +import com.tangem.core.analytics.models.AnalyticsEvent +import com.tangem.core.analytics.models.AnalyticsParam + +sealed class PushNotificationAnalyticEvents( + event: String, + params: Map = mapOf(), +) : AnalyticsEvent(category = "Push", event = event, params = params) { + + data class ButtonAllow( + val source: AnalyticsParam.ScreensSources, + ) : PushNotificationAnalyticEvents( + event = "Button - Allow", + params = mapOf( + AnalyticsParam.SOURCE to source.value, + ), + ) + + data class ButtonCancel( + val source: AnalyticsParam.ScreensSources, + ) : PushNotificationAnalyticEvents( + event = "Button - Cancel", + params = mapOf( + AnalyticsParam.SOURCE to source.value, + ), + ) + + data class PermissionStatus( + val isAllowed: Boolean, + ) : PushNotificationAnalyticEvents( + event = "Permission Status", + params = mapOf( + AnalyticsParam.STATE to if (isAllowed) "Allow" else "Cancel", + ), + ) +} \ No newline at end of file diff --git a/features/push-notifications/api/src/main/java/com/tangem/features/pushnotifications/api/featuretoggles/PushNotificationsFeatureToggles.kt b/features/push-notifications/api/src/main/java/com/tangem/features/pushnotifications/api/featuretoggles/PushNotificationsFeatureToggles.kt new file mode 100644 index 0000000000..18024f464f --- /dev/null +++ b/features/push-notifications/api/src/main/java/com/tangem/features/pushnotifications/api/featuretoggles/PushNotificationsFeatureToggles.kt @@ -0,0 +1,9 @@ +package com.tangem.features.pushnotifications.api.featuretoggles + +/** + * Push notifications feature toggles + */ +interface PushNotificationsFeatureToggles { + /** Availability of push notifications */ + val isPushNotificationsEnabled: Boolean +} \ No newline at end of file diff --git a/features/push-notifications/api/src/main/java/com/tangem/features/pushnotifications/api/navigation/PushNotificationsRouter.kt b/features/push-notifications/api/src/main/java/com/tangem/features/pushnotifications/api/navigation/PushNotificationsRouter.kt new file mode 100644 index 0000000000..6881437671 --- /dev/null +++ b/features/push-notifications/api/src/main/java/com/tangem/features/pushnotifications/api/navigation/PushNotificationsRouter.kt @@ -0,0 +1,8 @@ +package com.tangem.features.pushnotifications.api.navigation + +import androidx.fragment.app.Fragment + +interface PushNotificationsRouter { + + fun entryFragment(): Fragment +} \ No newline at end of file diff --git a/features/push-notifications/api/src/main/java/com/tangem/features/pushnotifications/api/utils/PermissionUtils.kt b/features/push-notifications/api/src/main/java/com/tangem/features/pushnotifications/api/utils/PermissionUtils.kt new file mode 100644 index 0000000000..c3d27e3ef5 --- /dev/null +++ b/features/push-notifications/api/src/main/java/com/tangem/features/pushnotifications/api/utils/PermissionUtils.kt @@ -0,0 +1,20 @@ +package com.tangem.features.pushnotifications.api.utils + +import android.Manifest +import android.os.Build +import androidx.annotation.ChecksSdkIntAtLeast + +@ChecksSdkIntAtLeast(api = Build.VERSION_CODES.TIRAMISU) +private val isRequirePushPermission = Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU + +val PUSH_PERMISSION = if (isRequirePushPermission) { + Manifest.permission.POST_NOTIFICATIONS +} else { + "android.permission.POST_NOTIFICATIONS" +} + +fun getPushPermissionOrNull() = if (isRequirePushPermission) { + Manifest.permission.POST_NOTIFICATIONS +} else { + null +} \ No newline at end of file diff --git a/features/push-notifications/impl/.gitignore b/features/push-notifications/impl/.gitignore new file mode 100644 index 0000000000..42afabfd2a --- /dev/null +++ b/features/push-notifications/impl/.gitignore @@ -0,0 +1 @@ +/build \ No newline at end of file diff --git a/features/push-notifications/impl/build.gradle.kts b/features/push-notifications/impl/build.gradle.kts new file mode 100644 index 0000000000..a9965b5681 --- /dev/null +++ b/features/push-notifications/impl/build.gradle.kts @@ -0,0 +1,47 @@ +plugins { + alias(deps.plugins.android.library) + alias(deps.plugins.kotlin.android) + alias(deps.plugins.kotlin.kapt) + alias(deps.plugins.hilt.android) + id("configuration") +} + +android { + namespace = "com.tangem.feature.pushnotifications.impl" +} + +dependencies { + /** AndroidX */ + implementation(deps.androidx.fragment.ktx) + implementation(deps.androidx.activity.compose) + + /** Compose */ + implementation(deps.compose.foundation) + implementation(deps.compose.accompanist.systemUiController) + implementation(deps.compose.accompanist.permission) + + /** Other dependencies */ + implementation(deps.timber) + implementation(deps.arrow.core) + implementation(deps.kotlin.immutable.collections) + + /** Core modules */ + implementation(projects.core.ui) + implementation(projects.core.featuretoggles) + implementation(projects.core.navigation) + implementation(projects.core.analytics) + implementation(projects.core.analytics.models) + + /** Common modules */ + implementation(projects.common.routing) + + /** Domain module */ + implementation(projects.domain.settings) + + /** Feature modules */ + implementation(projects.features.pushNotifications.api) + + /** DI */ + implementation(deps.hilt.android) + kapt(deps.hilt.kapt) +} \ No newline at end of file diff --git a/features/push-notifications/impl/src/main/java/com/tangem/features/pushnotifications/impl/PushNotificationsFragment.kt b/features/push-notifications/impl/src/main/java/com/tangem/features/pushnotifications/impl/PushNotificationsFragment.kt new file mode 100644 index 0000000000..c7110e411f --- /dev/null +++ b/features/push-notifications/impl/src/main/java/com/tangem/features/pushnotifications/impl/PushNotificationsFragment.kt @@ -0,0 +1,39 @@ +package com.tangem.features.pushnotifications.impl + +import androidx.activity.compose.BackHandler +import androidx.compose.runtime.Composable +import androidx.compose.ui.Modifier +import androidx.fragment.app.viewModels +import com.tangem.core.ui.UiDependencies +import com.tangem.core.ui.components.NavigationBar3ButtonsScrim +import com.tangem.core.ui.screen.ComposeFragment +import com.tangem.features.pushnotifications.impl.presentation.ui.PushNotificationsScreen +import com.tangem.features.pushnotifications.impl.presentation.viewmodel.PushNotificationViewModel +import dagger.hilt.android.AndroidEntryPoint +import javax.inject.Inject + +@AndroidEntryPoint +internal class PushNotificationsFragment : ComposeFragment() { + + @Inject + override lateinit var uiDependencies: UiDependencies + + private val viewModel by viewModels() + + @Composable + override fun ScreenContent(modifier: Modifier) { + BackHandler(onBack = requireActivity()::finish) + NavigationBar3ButtonsScrim() + PushNotificationsScreen( + onRequest = viewModel::onRequest, + onNeverRequest = viewModel::onNeverRequest, + onAllowPermission = viewModel::onAllowPermission, + onDenyPermission = viewModel::onDenyPermission, + ) + } + + companion object { + /** Create push notifications fragment instance */ + fun create(): PushNotificationsFragment = PushNotificationsFragment() + } +} \ No newline at end of file diff --git a/features/push-notifications/impl/src/main/java/com/tangem/features/pushnotifications/impl/di/PushNotificationsFeatureTogglesModule.kt b/features/push-notifications/impl/src/main/java/com/tangem/features/pushnotifications/impl/di/PushNotificationsFeatureTogglesModule.kt new file mode 100644 index 0000000000..0df7b0a222 --- /dev/null +++ b/features/push-notifications/impl/src/main/java/com/tangem/features/pushnotifications/impl/di/PushNotificationsFeatureTogglesModule.kt @@ -0,0 +1,24 @@ +package com.tangem.features.pushnotifications.impl.di + +import com.tangem.core.featuretoggle.manager.FeatureTogglesManager +import com.tangem.features.pushnotifications.api.featuretoggles.PushNotificationsFeatureToggles +import com.tangem.features.pushnotifications.impl.featuretoggles.DefaultPushNotificationsFeatureToggles +import dagger.Module +import dagger.Provides +import dagger.hilt.InstallIn +import dagger.hilt.components.SingletonComponent +import javax.inject.Singleton + +/** + * DI module provides implementation of [PushNotificationsFeatureToggles] + */ +@Module +@InstallIn(SingletonComponent::class) +internal object PushNotificationsFeatureTogglesModule { + + @Provides + @Singleton + fun provideSendFeatureToggles(featureTogglesManager: FeatureTogglesManager): PushNotificationsFeatureToggles { + return DefaultPushNotificationsFeatureToggles(featureTogglesManager = featureTogglesManager) + } +} \ No newline at end of file diff --git a/features/push-notifications/impl/src/main/java/com/tangem/features/pushnotifications/impl/di/PushNotificationsModule.kt b/features/push-notifications/impl/src/main/java/com/tangem/features/pushnotifications/impl/di/PushNotificationsModule.kt new file mode 100644 index 0000000000..b568880483 --- /dev/null +++ b/features/push-notifications/impl/src/main/java/com/tangem/features/pushnotifications/impl/di/PushNotificationsModule.kt @@ -0,0 +1,24 @@ +package com.tangem.features.pushnotifications.impl.di + +import com.tangem.common.routing.AppRouter +import com.tangem.features.pushnotifications.api.navigation.PushNotificationsRouter +import com.tangem.features.pushnotifications.impl.navigation.DefaultPushNotificationsRouter +import dagger.Module +import dagger.Provides +import dagger.hilt.InstallIn +import dagger.hilt.android.components.ActivityComponent +import dagger.hilt.android.scopes.ActivityScoped + +/** + * DI module provides implementation of [PushNotificationsRouter] + */ +@Module +@InstallIn(ActivityComponent::class) +object PushNotificationsModule { + + @Provides + @ActivityScoped + fun provideDisclaimerRouter(appRouter: AppRouter): PushNotificationsRouter { + return DefaultPushNotificationsRouter(appRouter) + } +} \ No newline at end of file diff --git a/features/push-notifications/impl/src/main/java/com/tangem/features/pushnotifications/impl/featuretoggles/DefaultPushNotificationsFeatureToggles.kt b/features/push-notifications/impl/src/main/java/com/tangem/features/pushnotifications/impl/featuretoggles/DefaultPushNotificationsFeatureToggles.kt new file mode 100644 index 0000000000..296ae7ca81 --- /dev/null +++ b/features/push-notifications/impl/src/main/java/com/tangem/features/pushnotifications/impl/featuretoggles/DefaultPushNotificationsFeatureToggles.kt @@ -0,0 +1,11 @@ +package com.tangem.features.pushnotifications.impl.featuretoggles + +import com.tangem.core.featuretoggle.manager.FeatureTogglesManager +import com.tangem.features.pushnotifications.api.featuretoggles.PushNotificationsFeatureToggles + +internal class DefaultPushNotificationsFeatureToggles( + private val featureTogglesManager: FeatureTogglesManager, +) : PushNotificationsFeatureToggles { + override val isPushNotificationsEnabled: Boolean + get() = featureTogglesManager.isFeatureEnabled("PUSH_NOTIFICATIONS_ENABLED") +} \ No newline at end of file diff --git a/features/push-notifications/impl/src/main/java/com/tangem/features/pushnotifications/impl/navigation/DefaultPushNotificationsRouter.kt b/features/push-notifications/impl/src/main/java/com/tangem/features/pushnotifications/impl/navigation/DefaultPushNotificationsRouter.kt new file mode 100644 index 0000000000..b2536cfe47 --- /dev/null +++ b/features/push-notifications/impl/src/main/java/com/tangem/features/pushnotifications/impl/navigation/DefaultPushNotificationsRouter.kt @@ -0,0 +1,18 @@ +package com.tangem.features.pushnotifications.impl.navigation + +import androidx.fragment.app.Fragment +import com.tangem.common.routing.AppRoute +import com.tangem.common.routing.AppRouter +import com.tangem.features.pushnotifications.impl.PushNotificationsFragment +import javax.inject.Inject + +internal class DefaultPushNotificationsRouter @Inject constructor( + private val appRouter: AppRouter, +) : InnerPushNotificationsRouter { + + override fun entryFragment(): Fragment = PushNotificationsFragment.create() + + override fun openHome() { + appRouter.push(AppRoute.Home) + } +} \ No newline at end of file diff --git a/features/push-notifications/impl/src/main/java/com/tangem/features/pushnotifications/impl/navigation/InnerPushNotificationsRouter.kt b/features/push-notifications/impl/src/main/java/com/tangem/features/pushnotifications/impl/navigation/InnerPushNotificationsRouter.kt new file mode 100644 index 0000000000..20050eca1e --- /dev/null +++ b/features/push-notifications/impl/src/main/java/com/tangem/features/pushnotifications/impl/navigation/InnerPushNotificationsRouter.kt @@ -0,0 +1,8 @@ +package com.tangem.features.pushnotifications.impl.navigation + +import com.tangem.features.pushnotifications.api.navigation.PushNotificationsRouter + +interface InnerPushNotificationsRouter : PushNotificationsRouter { + + fun openHome() +} \ No newline at end of file diff --git a/features/push-notifications/impl/src/main/java/com/tangem/features/pushnotifications/impl/presentation/ui/PushNotificationsScreen.kt b/features/push-notifications/impl/src/main/java/com/tangem/features/pushnotifications/impl/presentation/ui/PushNotificationsScreen.kt new file mode 100644 index 0000000000..a73e852c64 --- /dev/null +++ b/features/push-notifications/impl/src/main/java/com/tangem/features/pushnotifications/impl/presentation/ui/PushNotificationsScreen.kt @@ -0,0 +1,59 @@ +package com.tangem.features.pushnotifications.impl.presentation.ui + +import androidx.compose.foundation.layout.systemBarsPadding +import androidx.compose.runtime.Composable +import androidx.compose.runtime.mutableStateOf +import androidx.compose.runtime.remember +import androidx.compose.ui.Modifier +import com.tangem.core.ui.components.showcase.Showcase +import com.tangem.core.ui.components.showcase.model.ShowcaseButtonModel +import com.tangem.core.ui.components.showcase.model.ShowcaseItemModel +import com.tangem.core.ui.extensions.resourceReference +import com.tangem.core.ui.utils.requestPushPermission +import com.tangem.feature.pushnotifications.impl.R +import com.tangem.features.pushnotifications.api.utils.getPushPermissionOrNull +import kotlinx.collections.immutable.persistentListOf + +@Composable +internal fun PushNotificationsScreen( + onRequest: () -> Unit, + onNeverRequest: () -> Unit, + onAllowPermission: () -> Unit, + onDenyPermission: () -> Unit, +) { + val isClicked = remember { mutableStateOf(false) } + val requestPushPermission = requestPushPermission( + isClicked = isClicked, + onAllow = onAllowPermission, + onDeny = onDenyPermission, + pushPermission = getPushPermissionOrNull(), + ) + + Showcase( + headerIconRes = R.drawable.ic_notifications_unread_24, + headerText = resourceReference(R.string.user_push_notification_agreement_header), + showcaseItems = persistentListOf( + ShowcaseItemModel( + R.drawable.ic_rocket_launch_24, + resourceReference(R.string.user_push_notification_agreement_argument_one), + ), + ShowcaseItemModel( + R.drawable.ic_storefront_24, + resourceReference(R.string.user_push_notification_agreement_argument_two), + ), + ), + primaryButton = ShowcaseButtonModel( + buttonText = resourceReference(R.string.common_allow), + onClick = { + isClicked.value = true + onRequest() + requestPushPermission() + }, + ), + secondaryButton = ShowcaseButtonModel( + buttonText = resourceReference(R.string.common_cancel), + onClick = onNeverRequest, + ), + modifier = Modifier.systemBarsPadding(), + ) +} \ No newline at end of file diff --git a/features/push-notifications/impl/src/main/java/com/tangem/features/pushnotifications/impl/presentation/viewmodel/PushNotificationViewModel.kt b/features/push-notifications/impl/src/main/java/com/tangem/features/pushnotifications/impl/presentation/viewmodel/PushNotificationViewModel.kt new file mode 100644 index 0000000000..5b62923bbb --- /dev/null +++ b/features/push-notifications/impl/src/main/java/com/tangem/features/pushnotifications/impl/presentation/viewmodel/PushNotificationViewModel.kt @@ -0,0 +1,63 @@ +package com.tangem.features.pushnotifications.impl.presentation.viewmodel + +import androidx.lifecycle.ViewModel +import androidx.lifecycle.viewModelScope +import com.tangem.core.analytics.api.AnalyticsEventHandler +import com.tangem.core.analytics.models.AnalyticsParam +import com.tangem.domain.settings.NeverRequestPermissionUseCase +import com.tangem.domain.settings.NeverToInitiallyAskPermissionUseCase +import com.tangem.features.pushnotifications.api.analytics.PushNotificationAnalyticEvents +import com.tangem.features.pushnotifications.api.utils.PUSH_PERMISSION +import com.tangem.features.pushnotifications.impl.navigation.DefaultPushNotificationsRouter +import dagger.hilt.android.lifecycle.HiltViewModel +import kotlinx.coroutines.launch +import javax.inject.Inject + +@Suppress("LongParameterList") +@HiltViewModel +internal class PushNotificationViewModel @Inject constructor( + private val neverRequestPermissionUseCase: NeverRequestPermissionUseCase, + private val neverToInitiallyAskPermissionUseCase: NeverToInitiallyAskPermissionUseCase, + private val router: DefaultPushNotificationsRouter, + private val analyticHandler: AnalyticsEventHandler, +) : ViewModel(), PushNotificationsClickIntents { + + override fun onRequest() { + analyticHandler.send( + PushNotificationAnalyticEvents.ButtonAllow(AnalyticsParam.ScreensSources.Stories), + ) + } + + override fun onNeverRequest() { + analyticHandler.send( + PushNotificationAnalyticEvents.ButtonCancel(AnalyticsParam.ScreensSources.Stories), + ) + viewModelScope.launch { + neverRequestPermissionUseCase(PUSH_PERMISSION) + neverToInitiallyAskPermissionUseCase(PUSH_PERMISSION) + router.openHome() + } + } + + override fun onAllowPermission() { + analyticHandler.send( + PushNotificationAnalyticEvents.PermissionStatus(isAllowed = true), + ) + viewModelScope.launch { + neverRequestPermissionUseCase(PUSH_PERMISSION) + neverToInitiallyAskPermissionUseCase(PUSH_PERMISSION) + router.openHome() + } + } + + override fun onDenyPermission() { + analyticHandler.send( + PushNotificationAnalyticEvents.PermissionStatus(isAllowed = false), + ) + viewModelScope.launch { + neverRequestPermissionUseCase(PUSH_PERMISSION) + neverToInitiallyAskPermissionUseCase(PUSH_PERMISSION) + router.openHome() + } + } +} \ No newline at end of file diff --git a/features/push-notifications/impl/src/main/java/com/tangem/features/pushnotifications/impl/presentation/viewmodel/PushNotificationsClickIntents.kt b/features/push-notifications/impl/src/main/java/com/tangem/features/pushnotifications/impl/presentation/viewmodel/PushNotificationsClickIntents.kt new file mode 100644 index 0000000000..63100190b7 --- /dev/null +++ b/features/push-notifications/impl/src/main/java/com/tangem/features/pushnotifications/impl/presentation/viewmodel/PushNotificationsClickIntents.kt @@ -0,0 +1,11 @@ +package com.tangem.features.pushnotifications.impl.presentation.viewmodel + +internal interface PushNotificationsClickIntents { + fun onRequest() + + fun onNeverRequest() + + fun onAllowPermission() + + fun onDenyPermission() +} \ No newline at end of file diff --git a/features/qr-scanning/api/src/main/java/com/tangem/feature/qrscanning/QrScanningRouter.kt b/features/qr-scanning/api/src/main/java/com/tangem/feature/qrscanning/QrScanningRouter.kt index 7f5f0352b7..049e039209 100644 --- a/features/qr-scanning/api/src/main/java/com/tangem/feature/qrscanning/QrScanningRouter.kt +++ b/features/qr-scanning/api/src/main/java/com/tangem/feature/qrscanning/QrScanningRouter.kt @@ -5,9 +5,4 @@ import androidx.fragment.app.Fragment interface QrScanningRouter { fun getEntryFragment(): Fragment - - companion object { - const val SOURCE_KEY = "source" - const val NETWORK_KEY = "network" - } } \ No newline at end of file diff --git a/features/qr-scanning/impl/build.gradle.kts b/features/qr-scanning/impl/build.gradle.kts index 5ad7d8346d..f2dfb02aa4 100644 --- a/features/qr-scanning/impl/build.gradle.kts +++ b/features/qr-scanning/impl/build.gradle.kts @@ -16,6 +16,7 @@ dependencies { implementation(projects.core.ui) implementation(projects.core.utils) implementation(projects.core.navigation) + implementation(projects.common.routing) implementation(deps.androidx.fragment.ktx) implementation(deps.androidx.activity.compose) diff --git a/features/qr-scanning/impl/src/main/java/com/tangem/feature/qrscanning/QrScanningFragment.kt b/features/qr-scanning/impl/src/main/java/com/tangem/feature/qrscanning/QrScanningFragment.kt index 72d725c460..5118630639 100644 --- a/features/qr-scanning/impl/src/main/java/com/tangem/feature/qrscanning/QrScanningFragment.kt +++ b/features/qr-scanning/impl/src/main/java/com/tangem/feature/qrscanning/QrScanningFragment.kt @@ -7,21 +7,16 @@ import android.os.Bundle import android.view.View import androidx.activity.result.contract.ActivityResultContracts import androidx.compose.runtime.Composable -import androidx.compose.runtime.DisposableEffect import androidx.compose.ui.Modifier -import androidx.compose.ui.graphics.Color -import androidx.compose.ui.platform.LocalLifecycleOwner import androidx.core.content.ContextCompat import androidx.fragment.app.viewModels import androidx.lifecycle.Lifecycle -import androidx.lifecycle.LifecycleEventObserver import androidx.lifecycle.compose.collectAsStateWithLifecycle import androidx.lifecycle.lifecycleScope import androidx.lifecycle.repeatOnLifecycle -import com.google.accompanist.systemuicontroller.rememberSystemUiController import com.google.mlkit.vision.common.InputImage import com.tangem.core.ui.UiDependencies -import com.tangem.core.ui.res.TangemTheme +import com.tangem.core.ui.components.SystemBarsIconsDisposable import com.tangem.core.ui.screen.ComposeFragment import com.tangem.feature.qrscanning.inner.MLKitBarcodeAnalyzer import com.tangem.feature.qrscanning.navigation.QrScanningInnerRouter @@ -105,7 +100,8 @@ internal class QrScanningFragment : ComposeFragment() { @Composable override fun ScreenContent(modifier: Modifier) { - StatusBarTransparencyDisposable() + SystemBarsIconsDisposable(darkIcons = false) + QrScanningContent( executor = { cameraExecutor }, analyzer = { cameraAnalyzer }, @@ -145,29 +141,4 @@ internal class QrScanningFragment : ComposeFragment() { fun create() = QrScanningFragment() } -} - -@Composable -private fun StatusBarTransparencyDisposable() { - val systemUiController = rememberSystemUiController() - val systemBarsColor = TangemTheme.colors.background.secondary - val lifecycleOwner = LocalLifecycleOwner.current - DisposableEffect(Unit) { - val observer = LifecycleEventObserver { _, event -> - if (event == Lifecycle.Event.ON_START) { - systemUiController.setSystemBarsColor( - color = Color.Transparent, - darkIcons = false, - ) - } - if (event == Lifecycle.Event.ON_STOP) { - systemUiController.setSystemBarsColor(systemBarsColor) - } - } - lifecycleOwner.lifecycle.addObserver(observer) - - onDispose { - lifecycleOwner.lifecycle.removeObserver(observer) - } - } } \ No newline at end of file diff --git a/features/qr-scanning/impl/src/main/java/com/tangem/feature/qrscanning/di/QrScanningRouterModule.kt b/features/qr-scanning/impl/src/main/java/com/tangem/feature/qrscanning/di/QrScanningRouterModule.kt index 5bf6beee3f..b22a6c713f 100644 --- a/features/qr-scanning/impl/src/main/java/com/tangem/feature/qrscanning/di/QrScanningRouterModule.kt +++ b/features/qr-scanning/impl/src/main/java/com/tangem/feature/qrscanning/di/QrScanningRouterModule.kt @@ -1,6 +1,6 @@ package com.tangem.feature.qrscanning.di -import com.tangem.core.navigation.ReduxNavController +import com.tangem.common.routing.AppRouter import com.tangem.feature.qrscanning.QrScanningRouter import com.tangem.feature.qrscanning.navigation.DefaultQrScanningRouter import dagger.Module @@ -15,7 +15,7 @@ internal object QrScanningRouterModule { @Provides @ActivityScoped - fun provideQrScanRouter(reduxNavController: ReduxNavController): QrScanningRouter { - return DefaultQrScanningRouter(reduxNavController) + fun provideQrScanRouter(appRouter: AppRouter): QrScanningRouter { + return DefaultQrScanningRouter(appRouter) } } \ No newline at end of file diff --git a/features/qr-scanning/impl/src/main/java/com/tangem/feature/qrscanning/navigation/DefaultQrScanningRouter.kt b/features/qr-scanning/impl/src/main/java/com/tangem/feature/qrscanning/navigation/DefaultQrScanningRouter.kt index 17de053b79..3813274b68 100644 --- a/features/qr-scanning/impl/src/main/java/com/tangem/feature/qrscanning/navigation/DefaultQrScanningRouter.kt +++ b/features/qr-scanning/impl/src/main/java/com/tangem/feature/qrscanning/navigation/DefaultQrScanningRouter.kt @@ -1,15 +1,16 @@ package com.tangem.feature.qrscanning.navigation import androidx.fragment.app.Fragment -import com.tangem.core.navigation.ReduxNavController +import com.tangem.common.routing.AppRouter + import com.tangem.feature.qrscanning.QrScanningFragment class DefaultQrScanningRouter( - private val reduxNavController: ReduxNavController, + private val router: AppRouter, ) : QrScanningInnerRouter { override fun getEntryFragment(): Fragment = QrScanningFragment.create() override fun popBackStack() { - reduxNavController.popBackStack() + router.pop() } } \ No newline at end of file diff --git a/features/qr-scanning/impl/src/main/java/com/tangem/feature/qrscanning/presentation/QrScanningCameraDeniedBottomSheet.kt b/features/qr-scanning/impl/src/main/java/com/tangem/feature/qrscanning/presentation/QrScanningCameraDeniedBottomSheet.kt index 31f79da70e..cb06aa540c 100644 --- a/features/qr-scanning/impl/src/main/java/com/tangem/feature/qrscanning/presentation/QrScanningCameraDeniedBottomSheet.kt +++ b/features/qr-scanning/impl/src/main/java/com/tangem/feature/qrscanning/presentation/QrScanningCameraDeniedBottomSheet.kt @@ -1,25 +1,35 @@ package com.tangem.feature.qrscanning.presentation import android.content.Intent +import android.content.res.Configuration import android.net.Uri import android.provider.Settings +import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.padding import androidx.compose.material3.Text import androidx.compose.runtime.Composable +import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.res.stringResource +import androidx.compose.ui.tooling.preview.Preview import androidx.core.content.ContextCompat import com.tangem.core.ui.components.SimpleSettingsRow import com.tangem.core.ui.components.bottomsheets.TangemBottomSheet import com.tangem.core.ui.components.bottomsheets.TangemBottomSheetConfig import com.tangem.core.ui.res.TangemTheme +import com.tangem.core.ui.res.TangemThemePreview import com.tangem.feature.qrscanning.impl.R @Composable fun CameraDeniedBottomSheet(config: TangemBottomSheetConfig) { - TangemBottomSheet(config) { content: CameraDeniedBottomSheetConfig -> + TangemBottomSheet( + config = config, + title = { + CameraDeniedBottomSheetHeader() + }, + ) { content: CameraDeniedBottomSheetConfig -> CameraDeniedBottomSheet(content = content) } } @@ -28,7 +38,6 @@ fun CameraDeniedBottomSheet(config: TangemBottomSheetConfig) { private fun CameraDeniedBottomSheet(content: CameraDeniedBottomSheetConfig) { val context = LocalContext.current Column { - CameraDeniedBottomSheetHeader() SimpleSettingsRow( title = stringResource(id = R.string.qr_scanner_camera_denied_settings_button), icon = R.drawable.ic_settings_24, @@ -55,28 +64,45 @@ private fun CameraDeniedBottomSheet(content: CameraDeniedBottomSheetConfig) { } @Composable -private fun CameraDeniedBottomSheetHeader() { - Text( - text = stringResource(id = R.string.qr_scanner_camera_denied_title), - style = TangemTheme.typography.subtitle1, - color = TangemTheme.colors.text.primary1, - modifier = Modifier +private fun CameraDeniedBottomSheetHeader(modifier: Modifier = Modifier) { + Column( + modifier = modifier .padding( - start = TangemTheme.dimens.spacing20, - end = TangemTheme.dimens.spacing20, - top = TangemTheme.dimens.spacing16, + vertical = TangemTheme.dimens.spacing16, + horizontal = TangemTheme.dimens.spacing20, ), - ) - Text( - text = stringResource(id = R.string.qr_scanner_camera_denied_text), - style = TangemTheme.typography.body2, - color = TangemTheme.colors.text.secondary, - modifier = Modifier - .padding( - start = TangemTheme.dimens.spacing20, - end = TangemTheme.dimens.spacing20, - top = TangemTheme.dimens.spacing3, - bottom = TangemTheme.dimens.spacing16, + horizontalAlignment = Alignment.Start, + verticalArrangement = Arrangement.spacedBy(TangemTheme.dimens.spacing4), + ) { + Text( + text = stringResource(id = R.string.qr_scanner_camera_denied_title), + style = TangemTheme.typography.subtitle1, + color = TangemTheme.colors.text.primary1, + ) + Text( + text = stringResource(id = R.string.qr_scanner_camera_denied_text), + style = TangemTheme.typography.body2, + color = TangemTheme.colors.text.secondary, + ) + } +} + +// region Preview +@Composable +@Preview(showBackground = true) +@Preview(showBackground = true, uiMode = Configuration.UI_MODE_NIGHT_YES) +private fun Preview_CameraDeniedBottomSheet() { + TangemThemePreview { + CameraDeniedBottomSheet( + config = TangemBottomSheetConfig( + isShow = true, + onDismissRequest = {}, + content = CameraDeniedBottomSheetConfig( + onCancelClick = {}, + onGalleryClick = {}, + ), ), - ) -} \ No newline at end of file + ) + } +} +// endregion Preview \ No newline at end of file diff --git a/features/qr-scanning/impl/src/main/java/com/tangem/feature/qrscanning/presentation/QrScanningContent.kt b/features/qr-scanning/impl/src/main/java/com/tangem/feature/qrscanning/presentation/QrScanningContent.kt index 6dc9d3592b..019b7b6134 100644 --- a/features/qr-scanning/impl/src/main/java/com/tangem/feature/qrscanning/presentation/QrScanningContent.kt +++ b/features/qr-scanning/impl/src/main/java/com/tangem/feature/qrscanning/presentation/QrScanningContent.kt @@ -6,11 +6,9 @@ import androidx.compose.animation.fadeIn import androidx.compose.animation.fadeOut import androidx.compose.animation.togetherWith import androidx.compose.foundation.Canvas -import androidx.compose.foundation.clickable -import androidx.compose.foundation.interaction.MutableInteractionSource -import androidx.compose.foundation.layout.* -import androidx.compose.material.ripple.rememberRipple -import androidx.compose.material3.Icon +import androidx.compose.foundation.layout.Box +import androidx.compose.foundation.layout.fillMaxSize +import androidx.compose.foundation.layout.statusBarsPadding import androidx.compose.runtime.* import androidx.compose.ui.Modifier import androidx.compose.ui.geometry.Offset @@ -20,12 +18,13 @@ import androidx.compose.ui.graphics.PathEffect import androidx.compose.ui.graphics.StrokeJoin import androidx.compose.ui.graphics.drawscope.Stroke import androidx.compose.ui.platform.LocalDensity -import androidx.compose.ui.res.painterResource import androidx.compose.ui.text.drawText import androidx.compose.ui.text.rememberTextMeasurer import androidx.compose.ui.text.style.TextAlign import androidx.compose.ui.unit.Constraints -import com.tangem.core.ui.components.appbar.AppBarWithBackButtonAndIconContent +import com.tangem.core.ui.components.appbar.TangemTopAppBar +import com.tangem.core.ui.components.appbar.TopAppBarButton +import com.tangem.core.ui.components.appbar.models.TopAppBarButtonUM import com.tangem.core.ui.extensions.TextReference import com.tangem.core.ui.extensions.resolveReference import com.tangem.core.ui.res.TangemColorPalette @@ -59,46 +58,37 @@ internal fun QrScanningContent( Overlay( message = uiState.message, ) - AppBarWithBackButtonAndIconContent( - onBackClick = uiState.onBackClick, + + TangemTopAppBar( modifier = Modifier.statusBarsPadding(), - backgroundColor = Color.Transparent, - backIconTint = TangemColorPalette.White, - iconContent = { - Row { - AnimatedContent( - targetState = isFlash, - transitionSpec = { fadeIn().togetherWith(fadeOut()) }, - label = "Flash Change", - ) { - val flashIconRes = if (it) R.drawable.ic_flash_on_24 else R.drawable.ic_flash_off_24 - Icon( - painter = painterResource(flashIconRes), - contentDescription = null, - modifier = Modifier - .padding(end = TangemTheme.dimens.spacing20) - .size(size = TangemTheme.dimens.size24) - .clickable( - interactionSource = remember { MutableInteractionSource() }, - indication = rememberRipple(bounded = false), - onClick = { isFlash = !isFlash }, - ), - tint = TangemColorPalette.White, - ) - } - Icon( - painter = painterResource(R.drawable.ic_gallery_24), - contentDescription = null, - modifier = Modifier - .size(size = TangemTheme.dimens.size24) - .clickable( - interactionSource = remember { MutableInteractionSource() }, - indication = rememberRipple(bounded = false), - onClick = uiState.onGalleryClick, - ), + title = null, + startButton = TopAppBarButtonUM.Back(uiState.onBackClick), + iconTint = TangemColorPalette.White, + containerColor = Color.Transparent, + endContent = { + AnimatedContent( + targetState = isFlash, + transitionSpec = { fadeIn().togetherWith(fadeOut()) }, + label = "Flash Change", + ) { + TopAppBarButton( + button = TopAppBarButtonUM( + iconRes = if (it) R.drawable.ic_flash_on_24 else R.drawable.ic_flash_off_24, + onIconClicked = { + isFlash = !isFlash + }, + ), tint = TangemColorPalette.White, ) } + + TopAppBarButton( + button = TopAppBarButtonUM( + iconRes = R.drawable.ic_gallery_24, + onIconClicked = uiState.onGalleryClick, + ), + tint = TangemColorPalette.White, + ) }, ) if (uiState.bottomSheetConfig != null) { diff --git a/features/qr-scanning/impl/src/main/java/com/tangem/feature/qrscanning/viewmodel/QrScanningClickIntents.kt b/features/qr-scanning/impl/src/main/java/com/tangem/feature/qrscanning/viewmodel/QrScanningClickIntents.kt index 075894e1c6..5c2ab95304 100644 --- a/features/qr-scanning/impl/src/main/java/com/tangem/feature/qrscanning/viewmodel/QrScanningClickIntents.kt +++ b/features/qr-scanning/impl/src/main/java/com/tangem/feature/qrscanning/viewmodel/QrScanningClickIntents.kt @@ -45,13 +45,13 @@ internal class QrScanningClickIntentsImplementor @Inject constructor( override fun onQrScanned(qrCode: String) { if (qrCode.isNotBlank()) { + viewModelScope.launch(dispatcher.mainImmediate) { + emitQrScannedEventUseCase.invoke(source, qrCode) + } if (!isScanned) { router.popBackStack() isScanned = true } - viewModelScope.launch(dispatcher.main) { - emitQrScannedEventUseCase.invoke(source, qrCode) - } } } diff --git a/features/qr-scanning/impl/src/main/java/com/tangem/feature/qrscanning/viewmodel/QrScanningViewModel.kt b/features/qr-scanning/impl/src/main/java/com/tangem/feature/qrscanning/viewmodel/QrScanningViewModel.kt index cca4825f93..49b23ff8cd 100644 --- a/features/qr-scanning/impl/src/main/java/com/tangem/feature/qrscanning/viewmodel/QrScanningViewModel.kt +++ b/features/qr-scanning/impl/src/main/java/com/tangem/feature/qrscanning/viewmodel/QrScanningViewModel.kt @@ -3,8 +3,7 @@ package com.tangem.feature.qrscanning.viewmodel import androidx.lifecycle.SavedStateHandle import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope -import com.tangem.feature.qrscanning.QrScanningRouter.Companion.NETWORK_KEY -import com.tangem.feature.qrscanning.QrScanningRouter.Companion.SOURCE_KEY +import com.tangem.common.routing.AppRoute import com.tangem.domain.qrscanning.models.SourceType import com.tangem.feature.qrscanning.navigation.QrScanningInnerRouter import com.tangem.feature.qrscanning.presentation.QrScanningState @@ -24,8 +23,10 @@ internal class QrScanningViewModel @Inject constructor( savedStateHandle: SavedStateHandle, ) : ViewModel() { - private val source: SourceType = savedStateHandle[SOURCE_KEY] ?: error("Source is mandatory") - private val network: String? = savedStateHandle[NETWORK_KEY] + private val source: SourceType = savedStateHandle.get(AppRoute.QrScanning.SOURCE_KEY) + ?.let { SourceType.entries[it] } + ?: error("Source is mandatory") + private val network: String? = savedStateHandle[AppRoute.QrScanning.NETWORK_KEY] val uiState: StateFlow = stateHolder.uiState val launchGalleryEvent: SharedFlow = clickIntents.launchGallery diff --git a/features/referral/domain/build.gradle.kts b/features/referral/domain/build.gradle.kts index 0ae67f2d5f..4206513db7 100644 --- a/features/referral/domain/build.gradle.kts +++ b/features/referral/domain/build.gradle.kts @@ -32,6 +32,7 @@ dependencies { implementation(deps.arrow.core) implementation(deps.jodatime) implementation(deps.timber) + implementation(deps.tangem.card.core) /** DI */ implementation(deps.hilt.android) diff --git a/features/referral/domain/src/main/java/com/tangem/feature/referral/domain/ReferralInteractor.kt b/features/referral/domain/src/main/java/com/tangem/feature/referral/domain/ReferralInteractor.kt index 8024d1cc67..2bf7174f00 100644 --- a/features/referral/domain/src/main/java/com/tangem/feature/referral/domain/ReferralInteractor.kt +++ b/features/referral/domain/src/main/java/com/tangem/feature/referral/domain/ReferralInteractor.kt @@ -1,12 +1,13 @@ package com.tangem.feature.referral.domain +import com.tangem.domain.wallets.models.UserWalletId import com.tangem.feature.referral.domain.models.ReferralData interface ReferralInteractor { val isDemoMode: Boolean - suspend fun getReferralStatus(): ReferralData + suspend fun getReferralStatus(userWalletId: UserWalletId): ReferralData - suspend fun startReferral(): ReferralData + suspend fun startReferral(userWalletId: UserWalletId): ReferralData } \ No newline at end of file diff --git a/features/referral/domain/src/main/java/com/tangem/feature/referral/domain/ReferralInteractorImpl.kt b/features/referral/domain/src/main/java/com/tangem/feature/referral/domain/ReferralInteractorImpl.kt index 154764b162..04e3bb3028 100644 --- a/features/referral/domain/src/main/java/com/tangem/feature/referral/domain/ReferralInteractorImpl.kt +++ b/features/referral/domain/src/main/java/com/tangem/feature/referral/domain/ReferralInteractorImpl.kt @@ -1,9 +1,12 @@ package com.tangem.feature.referral.domain import arrow.core.getOrElse +import com.tangem.common.core.TangemSdkError import com.tangem.domain.card.DerivePublicKeysUseCase import com.tangem.domain.tokens.AddCryptoCurrenciesUseCase -import com.tangem.domain.wallets.usecase.GetSelectedWalletSyncUseCase +import com.tangem.domain.wallets.models.UserWalletId +import com.tangem.domain.wallets.usecase.GetUserWalletUseCase +import com.tangem.feature.referral.domain.errors.ReferralError import com.tangem.feature.referral.domain.models.ReferralData import com.tangem.feature.referral.domain.models.TokenData import com.tangem.lib.crypto.UserWalletManager @@ -14,7 +17,7 @@ internal class ReferralInteractorImpl( private val repository: ReferralRepository, private val userWalletManager: UserWalletManager, private val derivePublicKeysUseCase: DerivePublicKeysUseCase, - private val getSelectedWalletSyncUseCase: GetSelectedWalletSyncUseCase, + private val getUserWalletUseCase: GetUserWalletUseCase, private val addCryptoCurrenciesUseCase: AddCryptoCurrenciesUseCase, ) : ReferralInteractor { @@ -22,26 +25,26 @@ internal class ReferralInteractorImpl( override val isDemoMode: Boolean get() = repository.isDemoMode - override suspend fun getReferralStatus(): ReferralData { - val referralData = repository.getReferralData(userWalletManager.getWalletId()) + override suspend fun getReferralStatus(userWalletId: UserWalletId): ReferralData { + val referralData = repository.getReferralData(userWalletId.stringValue) saveReferralTokens(referralData.tokens) return referralData } - override suspend fun startReferral(): ReferralData { + override suspend fun startReferral(userWalletId: UserWalletId): ReferralData { if (tokensForReferral.isEmpty()) error("Tokens for ref is empty") val tokenData = tokensForReferral.first() - val userWallet = getSelectedWalletSyncUseCase().getOrElse { - error("Failed to get selected wallet: $it") + val userWallet = getUserWalletUseCase(userWalletId).getOrElse { + error("Failed to get user wallet $userWalletId: $it") } val cryptoCurrency = repository.getCryptoCurrency(userWalletId = userWallet.walletId, tokenData = tokenData) derivePublicKeysUseCase(userWallet.walletId, listOfNotNull(cryptoCurrency)).getOrElse { Timber.e("Failed to derive public keys: $it") - throw it + throw it.mapToDomainError() } addCryptoCurrenciesUseCase( @@ -66,4 +69,13 @@ internal class ReferralInteractorImpl( tokensForReferral.clear() tokensForReferral.addAll(tokens) } + + private fun Throwable.mapToDomainError(): ReferralError { + if (this !is TangemSdkError) return ReferralError.DataError(this) + return if (this is TangemSdkError.UserCancelled) { + ReferralError.UserCancelledException + } else { + ReferralError.SdkError + } + } } \ No newline at end of file diff --git a/features/referral/domain/src/main/java/com/tangem/feature/referral/domain/di/ReferralDomainModule.kt b/features/referral/domain/src/main/java/com/tangem/feature/referral/domain/di/ReferralDomainModule.kt index 0cd466fed7..172c41b27d 100644 --- a/features/referral/domain/src/main/java/com/tangem/feature/referral/domain/di/ReferralDomainModule.kt +++ b/features/referral/domain/src/main/java/com/tangem/feature/referral/domain/di/ReferralDomainModule.kt @@ -2,7 +2,7 @@ package com.tangem.feature.referral.domain.di import com.tangem.domain.card.DerivePublicKeysUseCase import com.tangem.domain.tokens.AddCryptoCurrenciesUseCase -import com.tangem.domain.wallets.usecase.GetSelectedWalletSyncUseCase +import com.tangem.domain.wallets.usecase.GetUserWalletUseCase import com.tangem.feature.referral.domain.ReferralInteractor import com.tangem.feature.referral.domain.ReferralInteractorImpl import com.tangem.feature.referral.domain.ReferralRepository @@ -23,14 +23,14 @@ class ReferralDomainModule { referralRepository: ReferralRepository, userWalletManager: UserWalletManager, derivePublicKeysUseCase: DerivePublicKeysUseCase, - getSelectedWalletSyncUseCase: GetSelectedWalletSyncUseCase, + getUserWalletUseCase: GetUserWalletUseCase, addCryptoCurrenciesUseCase: AddCryptoCurrenciesUseCase, ): ReferralInteractor { return ReferralInteractorImpl( repository = referralRepository, userWalletManager = userWalletManager, derivePublicKeysUseCase = derivePublicKeysUseCase, - getSelectedWalletSyncUseCase = getSelectedWalletSyncUseCase, + getUserWalletUseCase = getUserWalletUseCase, addCryptoCurrenciesUseCase = addCryptoCurrenciesUseCase, ) } diff --git a/features/referral/domain/src/main/java/com/tangem/feature/referral/domain/errors/ReferralError.kt b/features/referral/domain/src/main/java/com/tangem/feature/referral/domain/errors/ReferralError.kt new file mode 100644 index 0000000000..8d78d31fdd --- /dev/null +++ b/features/referral/domain/src/main/java/com/tangem/feature/referral/domain/errors/ReferralError.kt @@ -0,0 +1,8 @@ +package com.tangem.feature.referral.domain.errors + +sealed class ReferralError : Exception() { + data object UserCancelledException : ReferralError() + data object SdkError : ReferralError() + + data class DataError(val throwable: Throwable) : ReferralError() +} \ No newline at end of file diff --git a/features/referral/presentation/build.gradle.kts b/features/referral/presentation/build.gradle.kts index 0a90fdc329..ef6062abd5 100644 --- a/features/referral/presentation/build.gradle.kts +++ b/features/referral/presentation/build.gradle.kts @@ -12,12 +12,13 @@ android { dependencies { /** Core modules */ - implementation(project(":core:analytics")) + implementation(projects.core.analytics) implementation(projects.core.analytics.models) - implementation(project(":core:res")) - implementation(project(":core:utils")) - implementation(project(":core:ui")) - implementation(project(":libs:crypto")) + implementation(projects.core.res) + implementation(projects.core.utils) + implementation(projects.core.ui) + implementation(projects.libs.crypto) + implementation(projects.common.routing) /** AndroidX */ implementation(deps.androidx.appCompat) @@ -30,7 +31,8 @@ dependencies { implementation(deps.compose.ui.tooling) /** Domain */ - implementation(project(":features:referral:domain")) + implementation(projects.domain.wallets.models) + implementation(projects.features.referral.domain) /** Other libraries */ implementation(deps.compose.shimmer) diff --git a/features/referral/presentation/src/main/java/com/tangem/feature/referral/ReferralFragment.kt b/features/referral/presentation/src/main/java/com/tangem/feature/referral/ReferralFragment.kt index 2ccd4b74fc..cec296cc80 100644 --- a/features/referral/presentation/src/main/java/com/tangem/feature/referral/ReferralFragment.kt +++ b/features/referral/presentation/src/main/java/com/tangem/feature/referral/ReferralFragment.kt @@ -1,19 +1,16 @@ package com.tangem.feature.referral import android.os.Bundle -import androidx.compose.foundation.layout.systemBarsPadding import androidx.compose.runtime.Composable import androidx.compose.ui.Modifier import androidx.fragment.app.viewModels +import com.tangem.common.routing.AppRouter import com.tangem.core.ui.UiDependencies -import com.tangem.core.ui.components.SystemBarsEffect -import com.tangem.core.ui.res.TangemTheme import com.tangem.core.ui.screen.ComposeFragment import com.tangem.feature.referral.router.ReferralRouter import com.tangem.feature.referral.ui.ReferralScreen import com.tangem.feature.referral.viewmodels.ReferralViewModel import dagger.hilt.android.AndroidEntryPoint -import java.lang.ref.WeakReference import javax.inject.Inject @AndroidEntryPoint @@ -22,22 +19,19 @@ class ReferralFragment : ComposeFragment() { @Inject override lateinit var uiDependencies: UiDependencies + @Inject + internal lateinit var appRouter: AppRouter + private val viewModel by viewModels() override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) viewModel.onScreenOpened() - viewModel.setRouter(ReferralRouter(fragmentManager = WeakReference(parentFragmentManager))) + viewModel.setRouter(ReferralRouter(appRouter)) } @Composable override fun ScreenContent(modifier: Modifier) { - val backgroundColor = TangemTheme.colors.background.secondary - SystemBarsEffect { setSystemBarsColor(backgroundColor) } - - ReferralScreen( - modifier = Modifier.systemBarsPadding(), - stateHolder = viewModel.uiState, - ) + ReferralScreen(stateHolder = viewModel.uiState) } } \ No newline at end of file diff --git a/features/referral/presentation/src/main/java/com/tangem/feature/referral/router/ReferralRouter.kt b/features/referral/presentation/src/main/java/com/tangem/feature/referral/router/ReferralRouter.kt index ecd73795bf..a8ac11e54b 100644 --- a/features/referral/presentation/src/main/java/com/tangem/feature/referral/router/ReferralRouter.kt +++ b/features/referral/presentation/src/main/java/com/tangem/feature/referral/router/ReferralRouter.kt @@ -1,11 +1,12 @@ package com.tangem.feature.referral.router -import androidx.fragment.app.FragmentManager -import java.lang.ref.WeakReference +import com.tangem.common.routing.AppRouter -internal class ReferralRouter(private val fragmentManager: WeakReference) { +internal class ReferralRouter( + private val appRouter: AppRouter, +) { fun back() { - fragmentManager.get()?.popBackStack() + appRouter.pop() } } \ No newline at end of file diff --git a/features/referral/presentation/src/main/java/com/tangem/feature/referral/ui/AgreementBottomSheetContent.kt b/features/referral/presentation/src/main/java/com/tangem/feature/referral/ui/AgreementBottomSheetContent.kt index e44e192d0d..66be1782f1 100644 --- a/features/referral/presentation/src/main/java/com/tangem/feature/referral/ui/AgreementBottomSheetContent.kt +++ b/features/referral/presentation/src/main/java/com/tangem/feature/referral/ui/AgreementBottomSheetContent.kt @@ -3,40 +3,41 @@ package com.tangem.feature.referral.ui import android.content.res.Configuration import androidx.compose.foundation.background import androidx.compose.foundation.layout.Column -import androidx.compose.foundation.layout.fillMaxWidth +import androidx.compose.foundation.layout.Spacer +import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.height import androidx.compose.foundation.rememberScrollState import androidx.compose.foundation.verticalScroll import androidx.compose.runtime.Composable import androidx.compose.ui.Modifier -import androidx.compose.ui.platform.LocalConfiguration import androidx.compose.ui.platform.LocalInspectionMode import androidx.compose.ui.res.stringResource import androidx.compose.ui.tooling.preview.Preview +import androidx.compose.ui.unit.Dp import androidx.compose.ui.unit.dp import com.google.accompanist.web.WebView import com.google.accompanist.web.rememberWebViewState -import com.tangem.core.ui.components.appbar.AppBarWithAdditionalButtons -import com.tangem.core.ui.res.TangemThemePreview +import com.tangem.core.ui.components.appbar.TangemTopAppBar import com.tangem.core.ui.res.TangemTheme +import com.tangem.core.ui.res.TangemThemePreview import com.tangem.feature.referral.presentation.R /** * Bottom sheet content with referral program terms of use * * @param url link to the html page + * @param bottomBarHeight bottom insets */ @Composable -internal fun AgreementBottomSheetContent(url: String) { +internal fun AgreementBottomSheetContent(url: String, bottomBarHeight: Dp) { Column( modifier = Modifier - .fillMaxWidth() - .height(LocalConfiguration.current.screenHeightDp.dp - TangemTheme.dimens.spacing16), + .fillMaxSize() + .verticalScroll(rememberScrollState()), ) { - Column(modifier = Modifier.verticalScroll(rememberScrollState())) { - AppBarWithAdditionalButtons(text = stringResource(id = R.string.details_referral_title)) - AgreementHtmlView(url = url) - } + TangemTopAppBar(title = stringResource(id = R.string.details_referral_title)) + AgreementHtmlView(url = url) + Spacer(modifier = Modifier.height(bottomBarHeight)) } } @@ -46,7 +47,7 @@ private fun AgreementHtmlView(url: String) { val isInPreviewMode = LocalInspectionMode.current WebView( state = state, - modifier = Modifier.background(TangemTheme.colors.background.secondary), + modifier = Modifier.background(TangemTheme.colors.background.primary), captureBackPresses = false, onCreated = { if (!isInPreviewMode) { @@ -64,6 +65,6 @@ private fun AgreementHtmlView(url: String) { @Composable private fun Preview_AgreementBottomSheet() { TangemThemePreview { - AgreementBottomSheetContent(url = "https://tangem.com/en/") + AgreementBottomSheetContent(url = "https://tangem.com/en/", 50.dp) } } \ No newline at end of file diff --git a/features/referral/presentation/src/main/java/com/tangem/feature/referral/ui/AwardItems.kt b/features/referral/presentation/src/main/java/com/tangem/feature/referral/ui/AwardItems.kt deleted file mode 100644 index 5f11c074e1..0000000000 --- a/features/referral/presentation/src/main/java/com/tangem/feature/referral/ui/AwardItems.kt +++ /dev/null @@ -1,72 +0,0 @@ -package com.tangem.feature.referral.ui - -import androidx.compose.foundation.layout.* -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.text.TextStyle -import androidx.compose.ui.tooling.preview.Preview -import com.tangem.core.ui.res.TangemTheme -import com.tangem.core.ui.res.TangemThemePreview - -@Suppress("LongParameterList") -@Composable -internal fun AwardText( - startText: String, - startTextColor: Color, - startTextStyle: TextStyle, - endText: String, - endTextColor: Color, - endTextStyle: TextStyle, - cornersToRound: CornersToRound, -) { - Surface( - shape = cornersToRound.getShape(), - color = TangemTheme.colors.background.primary, - ) { - Row( - modifier = Modifier - .fillMaxWidth() - .heightIn(TangemTheme.dimens.size48) - .padding( - horizontal = TangemTheme.dimens.spacing16, - vertical = TangemTheme.dimens.spacing12, - ), - horizontalArrangement = Arrangement.SpaceBetween, - verticalAlignment = Alignment.CenterVertically, - ) { - Text( - text = startText, - color = startTextColor, - maxLines = 1, - style = startTextStyle, - ) - - Text( - text = endText, - color = endTextColor, - maxLines = 1, - style = endTextStyle, - ) - } - } -} - -@Preview(widthDp = 360, showBackground = true) -@Composable -private fun Preview_AwardItem() { - TangemThemePreview { - AwardText( - startText = "startText", - startTextColor = TangemTheme.colors.text.tertiary, - startTextStyle = TangemTheme.typography.subtitle2, - endText = "endText", - endTextColor = TangemTheme.colors.text.primary1, - endTextStyle = TangemTheme.typography.subtitle2, - cornersToRound = CornersToRound.TOP_2, - ) - } -} \ No newline at end of file diff --git a/features/referral/presentation/src/main/java/com/tangem/feature/referral/ui/CornersToRound.kt b/features/referral/presentation/src/main/java/com/tangem/feature/referral/ui/CornersToRound.kt deleted file mode 100644 index b5070cdb28..0000000000 --- a/features/referral/presentation/src/main/java/com/tangem/feature/referral/ui/CornersToRound.kt +++ /dev/null @@ -1,27 +0,0 @@ -package com.tangem.feature.referral.ui - -import androidx.compose.foundation.shape.RoundedCornerShape -import androidx.compose.runtime.Composable -import androidx.compose.ui.unit.dp -import com.tangem.core.ui.res.TangemTheme - -internal enum class CornersToRound { - - ALL_4, - TOP_2, - BOTTOM_2, - ZERO, - ; - - @Suppress("TopLevelComposableFunctions") - @Composable - fun getShape(): RoundedCornerShape { - val radius = TangemTheme.dimens.radius12 - return when (this) { - ALL_4 -> RoundedCornerShape(radius) - TOP_2 -> RoundedCornerShape(topStart = radius, topEnd = radius) - BOTTOM_2 -> RoundedCornerShape(bottomStart = radius, bottomEnd = radius) - ZERO -> RoundedCornerShape(0.dp) - } - } -} \ No newline at end of file diff --git a/features/referral/presentation/src/main/java/com/tangem/feature/referral/ui/ParticipateBottomBlock.kt b/features/referral/presentation/src/main/java/com/tangem/feature/referral/ui/ParticipateBottomBlock.kt index cd403043df..01e2c4b3d1 100644 --- a/features/referral/presentation/src/main/java/com/tangem/feature/referral/ui/ParticipateBottomBlock.kt +++ b/features/referral/presentation/src/main/java/com/tangem/feature/referral/ui/ParticipateBottomBlock.kt @@ -26,6 +26,8 @@ import androidx.compose.ui.tooling.preview.PreviewParameter import androidx.compose.ui.tooling.preview.datasource.CollectionPreviewParameterProvider import androidx.core.content.ContextCompat.startActivity import com.tangem.core.ui.components.PrimaryButtonIconStart +import com.tangem.core.ui.components.rows.CornersToRound +import com.tangem.core.ui.components.rows.RoundableCornersRow import com.tangem.core.ui.res.TangemTheme import com.tangem.core.ui.res.TangemThemePreview import com.tangem.feature.referral.domain.models.ExpectedAward @@ -82,7 +84,7 @@ private fun CounterAndAwards(purchasedWalletCount: Int, expectedAwards: Expected private fun Counter(purchasedWalletCount: Int, expectedAwards: ExpectedAwards?) { val isExpectedAwardsPresent = expectedAwards != null - AwardText( + RoundableCornersRow( startText = stringResource(id = R.string.referral_friends_bought_title), startTextColor = TangemTheme.colors.text.tertiary, startTextStyle = TangemTheme.typography.subtitle2, @@ -111,7 +113,7 @@ private fun Awards(expectedAwards: ExpectedAwards) { thickness = TangemTheme.dimens.size0_5, color = TangemTheme.colors.stroke.primary, ) - AwardText( + RoundableCornersRow( startText = if (expectedAwards.expectedAwards.isNotEmpty()) { stringResource(id = R.string.referral_expected_awards) } else { @@ -137,7 +139,7 @@ private fun Awards(expectedAwards: ExpectedAwards) { val extraItems = expectedAwards.expectedAwards.drop(elementsCountToShowInLessMode) initialItems.forEachIndexed { index, expectedAward -> - AwardText( + RoundableCornersRow( startText = expectedAward.paymentDate, startTextColor = TangemTheme.colors.text.primary1, startTextStyle = TangemTheme.typography.subtitle2, @@ -218,7 +220,7 @@ private fun LessMoreButton(isExpanded: MutableState) { private fun ExtraItems(extraItems: List) { Column { extraItems.forEach { expectedAward -> - AwardText( + RoundableCornersRow( startText = expectedAward.paymentDate, startTextColor = TangemTheme.colors.text.primary1, startTextStyle = TangemTheme.typography.subtitle2, diff --git a/features/referral/presentation/src/main/java/com/tangem/feature/referral/ui/ReferralBottomSheet.kt b/features/referral/presentation/src/main/java/com/tangem/feature/referral/ui/ReferralBottomSheet.kt index 2d70513c8a..678775213a 100644 --- a/features/referral/presentation/src/main/java/com/tangem/feature/referral/ui/ReferralBottomSheet.kt +++ b/features/referral/presentation/src/main/java/com/tangem/feature/referral/ui/ReferralBottomSheet.kt @@ -1,11 +1,19 @@ package com.tangem.feature.referral.ui +import androidx.compose.foundation.layout.WindowInsets +import androidx.compose.foundation.layout.height +import androidx.compose.foundation.layout.statusBars +import androidx.compose.foundation.layout.systemBars import androidx.compose.foundation.shape.RoundedCornerShape import androidx.compose.material3.ExperimentalMaterial3Api import androidx.compose.material3.ModalBottomSheet import androidx.compose.material3.SheetState import androidx.compose.runtime.Composable +import androidx.compose.ui.Modifier +import androidx.compose.ui.platform.LocalDensity +import com.tangem.core.ui.res.LocalWindowSize import com.tangem.core.ui.res.TangemTheme +import com.tangem.core.ui.utils.WindowInsetsZero import com.tangem.feature.referral.models.ReferralStateHolder @OptIn(ExperimentalMaterial3Api::class) @@ -16,14 +24,19 @@ internal fun ReferralBottomSheet( onDismissRequest: () -> Unit, config: ReferralStateHolder.ReferralInfoState, ) { + val statusBarHeight = with(LocalDensity.current) { WindowInsets.statusBars.getTop(this).toDp() } + val bottomBarHeight = with(LocalDensity.current) { WindowInsets.systemBars.getBottom(this).toDp() } + if (isVisible) { ModalBottomSheet( + modifier = Modifier.height(LocalWindowSize.current.height - statusBarHeight), onDismissRequest = onDismissRequest, sheetState = sheetState, shape = RoundedCornerShape( topStart = TangemTheme.dimens.radius16, topEnd = TangemTheme.dimens.radius16, ), + windowInsets = WindowInsetsZero, containerColor = TangemTheme.colors.background.primary, ) { AgreementBottomSheetContent( @@ -32,6 +45,7 @@ internal fun ReferralBottomSheet( is ReferralStateHolder.ReferralInfoState.ParticipantContent -> config.url is ReferralStateHolder.ReferralInfoState.Loading -> "" }, + bottomBarHeight = bottomBarHeight, ) } } diff --git a/features/referral/presentation/src/main/java/com/tangem/feature/referral/ui/ReferralScreen.kt b/features/referral/presentation/src/main/java/com/tangem/feature/referral/ui/ReferralScreen.kt index 39b216fb16..7d6614a7aa 100644 --- a/features/referral/presentation/src/main/java/com/tangem/feature/referral/ui/ReferralScreen.kt +++ b/features/referral/presentation/src/main/java/com/tangem/feature/referral/ui/ReferralScreen.kt @@ -46,16 +46,16 @@ import kotlinx.coroutines.launch */ @OptIn(ExperimentalMaterial3Api::class) @Composable -internal fun ReferralScreen(stateHolder: ReferralStateHolder, modifier: Modifier = Modifier) { +internal fun ReferralScreen(stateHolder: ReferralStateHolder) { var isBottomSheetVisible by remember { mutableStateOf(value = false) } val sheetState = rememberModalBottomSheetState(skipPartiallyExpanded = true) val snackbarHostState = remember(::SnackbarHostState) Scaffold( - modifier = modifier, topBar = { AppBarWithBackButton( + modifier = Modifier.statusBarsPadding(), text = stringResource(R.string.details_referral_title), onBackClick = stateHolder.headerState.onBackClicked, ) diff --git a/features/referral/presentation/src/main/java/com/tangem/feature/referral/viewmodels/ReferralViewModel.kt b/features/referral/presentation/src/main/java/com/tangem/feature/referral/viewmodels/ReferralViewModel.kt index 82c0d08bb8..236d0c93db 100644 --- a/features/referral/presentation/src/main/java/com/tangem/feature/referral/viewmodels/ReferralViewModel.kt +++ b/features/referral/presentation/src/main/java/com/tangem/feature/referral/viewmodels/ReferralViewModel.kt @@ -1,13 +1,19 @@ package com.tangem.feature.referral.viewmodels +import android.os.Bundle import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.setValue +import androidx.lifecycle.SavedStateHandle import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope +import com.tangem.common.routing.AppRoute +import com.tangem.common.routing.bundle.unbundle import com.tangem.core.analytics.api.AnalyticsEventHandler +import com.tangem.domain.wallets.models.UserWalletId import com.tangem.feature.referral.analytics.ReferralEvents import com.tangem.feature.referral.domain.ReferralInteractor +import com.tangem.feature.referral.domain.errors.ReferralError import com.tangem.feature.referral.domain.models.DiscountType import com.tangem.feature.referral.domain.models.ReferralData import com.tangem.feature.referral.domain.models.ReferralInfo @@ -16,7 +22,6 @@ import com.tangem.feature.referral.models.ReferralStateHolder import com.tangem.feature.referral.models.ReferralStateHolder.ErrorSnackbar import com.tangem.feature.referral.models.ReferralStateHolder.ReferralInfoState import com.tangem.feature.referral.router.ReferralRouter -import com.tangem.lib.crypto.models.errors.UserCancelledException import com.tangem.utils.coroutines.CoroutineDispatcherProvider import com.tangem.utils.coroutines.runCatching import dagger.hilt.android.lifecycle.HiltViewModel @@ -29,15 +34,20 @@ internal class ReferralViewModel @Inject constructor( private val referralInteractor: ReferralInteractor, private val dispatchers: CoroutineDispatcherProvider, private val analyticsEventHandler: AnalyticsEventHandler, + savedStateHandle: SavedStateHandle, ) : ViewModel() { - var uiState: ReferralStateHolder by mutableStateOf(createInitiallyUiState()) - private set + private val userWalletId = savedStateHandle.get(AppRoute.ReferralProgram.USER_WALLET_ID_KEY) + ?.unbundle(UserWalletId.serializer()) + ?: error("User wallet ID is required for Referral screen") private var referralRouter: ReferralRouter by Delegates.notNull() private var lastReferralData: ReferralData? = null + var uiState: ReferralStateHolder by mutableStateOf(createInitiallyUiState()) + private set + init { loadReferralData() } @@ -66,7 +76,7 @@ internal class ReferralViewModel @Inject constructor( uiState = uiState.copy(referralInfoState = ReferralInfoState.Loading) viewModelScope.launch(dispatchers.main) { runCatching(dispatchers.io) { - referralInteractor.getReferralStatus().apply { + referralInteractor.getReferralStatus(userWalletId).apply { lastReferralData = this } } @@ -82,10 +92,10 @@ internal class ReferralViewModel @Inject constructor( analyticsEventHandler.send(ReferralEvents.ClickParticipate) uiState = uiState.copy(referralInfoState = ReferralInfoState.Loading) viewModelScope.launch(dispatchers.main) { - runCatching(dispatchers.io) { referralInteractor.startReferral() } + runCatching(dispatchers.io) { referralInteractor.startReferral(userWalletId) } .onSuccess(::showContent) .onFailure { throwable -> - if (throwable is UserCancelledException) { + if (throwable is ReferralError.UserCancelledException) { lastReferralData?.let { referralData -> showContent(referralData) } diff --git a/features/send/api/src/main/kotlin/com/tangem/features/send/api/navigation/SendRouter.kt b/features/send/api/src/main/kotlin/com/tangem/features/send/api/navigation/SendRouter.kt index 4a2940f972..286f908ad8 100644 --- a/features/send/api/src/main/kotlin/com/tangem/features/send/api/navigation/SendRouter.kt +++ b/features/send/api/src/main/kotlin/com/tangem/features/send/api/navigation/SendRouter.kt @@ -5,13 +5,4 @@ import androidx.fragment.app.Fragment interface SendRouter { fun getEntryFragment(): Fragment - - companion object { - const val CRYPTO_CURRENCY_KEY = "send_crypto_currency" - const val USER_WALLET_ID_KEY = "send_user_wallet_id" - const val TRANSACTION_ID_KEY = "send_transaction_id" - const val AMOUNT_KEY = "send_amount" - const val TAG_KEY = "send_tag" - const val DESTINATION_ADDRESS_KEY = "send_destination_address" - } } \ No newline at end of file diff --git a/features/send/impl/build.gradle.kts b/features/send/impl/build.gradle.kts index 66e103efad..9a3de6d8cb 100644 --- a/features/send/impl/build.gradle.kts +++ b/features/send/impl/build.gradle.kts @@ -24,6 +24,7 @@ dependencies { implementation(deps.jodatime) implementation(deps.timber) implementation(deps.reKotlin) + implementation(deps.kotlin.serialization) /** Compose */ implementation(deps.compose.accompanist.systemUiController) @@ -51,7 +52,8 @@ dependencies { implementation(projects.core.datasource) /** Common */ - implementation(projects.common) + implementation(projects.common.ui) + implementation(projects.common.routing) /** Libs */ implementation(projects.libs.crypto) @@ -72,6 +74,7 @@ dependencies { implementation(projects.domain.card) implementation(projects.domain.balanceHiding) implementation(projects.domain.balanceHiding.models) + implementation(projects.domain.feedback) implementation(projects.domain.qrScanning) implementation(projects.domain.qrScanning.models) implementation(projects.domain.settings) diff --git a/features/send/impl/src/main/java/com/tangem/features/send/impl/di/SendRouterModule.kt b/features/send/impl/src/main/java/com/tangem/features/send/impl/di/SendRouterModule.kt index 7f38cacd35..b99742c742 100644 --- a/features/send/impl/src/main/java/com/tangem/features/send/impl/di/SendRouterModule.kt +++ b/features/send/impl/src/main/java/com/tangem/features/send/impl/di/SendRouterModule.kt @@ -1,6 +1,7 @@ package com.tangem.features.send.impl.di -import com.tangem.core.navigation.ReduxNavController +import com.tangem.common.routing.AppRouter +import com.tangem.core.navigation.url.UrlOpener import com.tangem.features.send.api.navigation.SendRouter import com.tangem.features.send.impl.navigation.DefaultSendRouter import dagger.Module @@ -18,7 +19,7 @@ internal object SendRouterModule { @Provides @ActivityScoped - fun provideSendRouter(reduxNavController: ReduxNavController): SendRouter { - return DefaultSendRouter(reduxNavController) + fun provideSendRouter(appRouter: AppRouter, urlOpener: UrlOpener): SendRouter { + return DefaultSendRouter(appRouter, urlOpener) } } \ No newline at end of file diff --git a/features/send/impl/src/main/java/com/tangem/features/send/impl/navigation/DefaultSendRouter.kt b/features/send/impl/src/main/java/com/tangem/features/send/impl/navigation/DefaultSendRouter.kt index 0629979fd1..ed9f1f7b14 100644 --- a/features/send/impl/src/main/java/com/tangem/features/send/impl/navigation/DefaultSendRouter.kt +++ b/features/send/impl/src/main/java/com/tangem/features/send/impl/navigation/DefaultSendRouter.kt @@ -1,48 +1,43 @@ package com.tangem.features.send.impl.navigation -import androidx.core.os.bundleOf import androidx.fragment.app.Fragment -import com.tangem.core.navigation.AppScreen -import com.tangem.core.navigation.NavigationAction -import com.tangem.core.navigation.ReduxNavController +import com.tangem.common.routing.AppRoute +import com.tangem.common.routing.AppRouter +import com.tangem.core.navigation.url.UrlOpener import com.tangem.domain.qrscanning.models.SourceType import com.tangem.domain.tokens.model.CryptoCurrency import com.tangem.domain.wallets.models.UserWalletId -import com.tangem.feature.qrscanning.QrScanningRouter import com.tangem.features.send.impl.presentation.SendFragment -import com.tangem.features.tokendetails.navigation.TokenDetailsRouter internal class DefaultSendRouter( - private val reduxNavController: ReduxNavController, + private val router: AppRouter, + private val urlOpener: UrlOpener, ) : InnerSendRouter { override fun getEntryFragment(): Fragment = SendFragment.create() override fun openUrl(url: String) { - reduxNavController.navigate(NavigationAction.OpenUrl(url = url)) + urlOpener.openUrl(url) } override fun openTokenDetails(userWalletId: UserWalletId, currency: CryptoCurrency) { - reduxNavController.popBackStack() - reduxNavController.navigate( - action = NavigationAction.NavigateTo( - screen = AppScreen.WalletDetails, - bundle = bundleOf( - TokenDetailsRouter.USER_WALLET_ID_KEY to userWalletId.stringValue, - TokenDetailsRouter.CRYPTO_CURRENCY_KEY to currency, - ), - ), - ) + router.pop { isSuccess -> + if (isSuccess) { + router.push( + AppRoute.CurrencyDetails( + userWalletId = userWalletId, + currency = currency, + ), + ) + } + } } override fun openQrCodeScanner(network: String) { - reduxNavController.navigate( - action = NavigationAction.NavigateTo( - screen = AppScreen.QrScanning, - bundle = bundleOf( - QrScanningRouter.SOURCE_KEY to SourceType.SEND, - QrScanningRouter.NETWORK_KEY to network, - ), + router.push( + AppRoute.QrScanning( + source = SourceType.SEND, + networkName = network, ), ) } diff --git a/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/SendFragment.kt b/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/SendFragment.kt index 4eb34fce88..48899c5eb3 100644 --- a/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/SendFragment.kt +++ b/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/SendFragment.kt @@ -6,10 +6,10 @@ import androidx.compose.runtime.getValue import androidx.compose.ui.Modifier import androidx.fragment.app.viewModels import androidx.lifecycle.compose.collectAsStateWithLifecycle +import com.tangem.common.routing.AppRoute +import com.tangem.common.routing.AppRouter import com.tangem.core.analytics.api.AnalyticsEventHandler import com.tangem.core.ui.UiDependencies -import com.tangem.core.ui.components.SystemBarsEffect -import com.tangem.core.ui.res.TangemTheme import com.tangem.core.ui.screen.ComposeFragment import com.tangem.features.send.api.navigation.SendRouter import com.tangem.features.send.impl.navigation.InnerSendRouter @@ -17,7 +17,6 @@ import com.tangem.features.send.impl.presentation.state.StateRouter import com.tangem.features.send.impl.presentation.ui.SendScreen import com.tangem.features.send.impl.presentation.viewmodel.SendViewModel import dagger.hilt.android.AndroidEntryPoint -import java.lang.ref.WeakReference import javax.inject.Inject /** @@ -32,6 +31,9 @@ internal class SendFragment : ComposeFragment() { @Inject lateinit var router: SendRouter + @Inject + lateinit var appRouter: AppRouter + @Inject lateinit var analyticsEventsHandler: AnalyticsEventHandler @@ -45,11 +47,11 @@ internal class SendFragment : ComposeFragment() { super.onCreate(savedInstanceState) lifecycle.addObserver(viewModel) - val isEditingDisabled = arguments?.getString(SendRouter.TRANSACTION_ID_KEY) != null + val isEditingDisabled = arguments?.getString(AppRoute.Send.TRANSACTION_ID_KEY) != null viewModel.setRouter( innerSendRouter, StateRouter( - fragmentManager = WeakReference(parentFragmentManager), + appRouter = appRouter, isEditingDisabled = isEditingDisabled, analyticsEventsHandler = analyticsEventsHandler, ), @@ -58,11 +60,6 @@ internal class SendFragment : ComposeFragment() { @Composable override fun ScreenContent(modifier: Modifier) { - val systemBarsColor = TangemTheme.colors.background.tertiary - SystemBarsEffect { - setSystemBarsColor(systemBarsColor) - } - val currentState = viewModel.stateRouter.currentState.collectAsStateWithLifecycle() val uiState by viewModel.uiState.collectAsStateWithLifecycle() diff --git a/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/analytics/utils/SendScreenAnalyticSender.kt b/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/analytics/utils/SendScreenAnalyticSender.kt index ac6485fc8a..7b8bbc3be3 100644 --- a/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/analytics/utils/SendScreenAnalyticSender.kt +++ b/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/analytics/utils/SendScreenAnalyticSender.kt @@ -1,6 +1,7 @@ package com.tangem.features.send.impl.presentation.analytics.utils import com.tangem.blockchain.common.transaction.TransactionFee +import com.tangem.common.ui.amountScreen.models.AmountState import com.tangem.core.analytics.api.AnalyticsEventHandler import com.tangem.core.analytics.models.AnalyticsParam import com.tangem.core.analytics.models.Basic @@ -36,7 +37,7 @@ internal class SendScreenAnalyticSender( } } SendUiStateType.Amount -> { - val amountState = state.getAmountState(stateRouterProvider().isEditState) ?: return + val amountState = state.getAmountState(stateRouterProvider().isEditState) as? AmountState.Data ?: return val isFiatSelected = amountState.amountTextField.isFiatValue val selectedCurrency = if (!isFiatSelected) { SelectedCurrencyType.Token diff --git a/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/errors/FeeErrorStateMapper.kt b/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/errors/FeeErrorStateMapper.kt new file mode 100644 index 0000000000..ab218f7fe0 --- /dev/null +++ b/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/errors/FeeErrorStateMapper.kt @@ -0,0 +1,19 @@ +package com.tangem.features.send.impl.presentation.errors + +import com.tangem.domain.transaction.error.GetFeeError +import com.tangem.features.send.impl.presentation.state.fee.FeeSelectorState + +internal class FeeErrorStateMapper { + + fun getFeeError(loadFeeError: GetFeeError?, tokenName: String): FeeSelectorState.Error { + return when (loadFeeError) { + GetFeeError.BlockchainErrors.TronActivationError -> FeeSelectorState.Error.TronAccountActivationError( + tokenName, + ) + is GetFeeError.DataError, + GetFeeError.UnknownError, + null, + -> FeeSelectorState.Error.NetworkError + } + } +} \ No newline at end of file diff --git a/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/state/SendNotification.kt b/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/state/SendNotification.kt index 65318c9c39..017c91f8d4 100644 --- a/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/state/SendNotification.kt +++ b/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/state/SendNotification.kt @@ -157,6 +157,14 @@ internal sealed class SendNotification(val config: NotificationConfig) { ), ) + data class TronAccountNotActivated(val tokenName: String) : Warning( + title = resourceReference(R.string.send_fee_unreachable_error_title), + subtitle = resourceReference( + R.string.send_tron_account_activation_error, + wrappedList(tokenName), + ), + ) + data class FeeCoverageNotification(val cryptoAmount: String, val fiatAmount: String) : Warning( title = resourceReference(R.string.send_network_fee_warning_title), subtitle = resourceReference( diff --git a/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/state/SendStateFactory.kt b/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/state/SendStateFactory.kt index 8e552379b5..e71731954d 100644 --- a/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/state/SendStateFactory.kt +++ b/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/state/SendStateFactory.kt @@ -1,18 +1,18 @@ package com.tangem.features.send.impl.presentation.state import com.tangem.blockchain.common.TransactionData -import com.tangem.core.ui.components.currency.tokenicon.converter.CryptoCurrencyToIconStateConverter +import com.tangem.common.ui.amountScreen.converters.AmountStateConverter +import com.tangem.common.ui.amountScreen.models.AmountState +import com.tangem.core.ui.components.currency.icon.converter.CryptoCurrencyToIconStateConverter import com.tangem.core.ui.event.consumedEvent import com.tangem.domain.appcurrency.model.AppCurrency import com.tangem.domain.tokens.model.CryptoCurrencyStatus import com.tangem.domain.wallets.models.UserWallet -import com.tangem.features.send.impl.presentation.state.amount.SendAmountStateConverter import com.tangem.features.send.impl.presentation.state.common.SendSyncEditConverter import com.tangem.features.send.impl.presentation.state.confirm.SendConfirmStateConverter import com.tangem.features.send.impl.presentation.state.fee.FeeSelectorState import com.tangem.features.send.impl.presentation.state.fee.SendFeeStateConverter import com.tangem.features.send.impl.presentation.state.fee.checkFeeCoverage -import com.tangem.features.send.impl.presentation.state.fields.SendAmountFieldConverter import com.tangem.features.send.impl.presentation.state.recipient.SendRecipientStateConverter import com.tangem.features.send.impl.presentation.viewmodel.SendClickIntents import com.tangem.utils.Provider @@ -33,20 +33,12 @@ internal class SendStateFactory( ) { private val iconStateConverter by lazy(::CryptoCurrencyToIconStateConverter) - private val amountFieldConverter by lazy(LazyThreadSafetyMode.NONE) { - SendAmountFieldConverter( - clickIntents = clickIntents, - stateRouterProvider = stateRouterProvider, - cryptoCurrencyStatusProvider = cryptoCurrencyStatusProvider, - appCurrencyProvider = appCurrencyProvider, - ) - } private val amountStateConverter by lazy(LazyThreadSafetyMode.NONE) { - SendAmountStateConverter( + AmountStateConverter( + clickIntents = clickIntents, appCurrencyProvider = appCurrencyProvider, iconStateConverter = iconStateConverter, userWalletProvider = userWalletProvider, - sendAmountFieldConverter = amountFieldConverter, cryptoCurrencyStatusProvider = cryptoCurrencyStatusProvider, ) } @@ -79,12 +71,19 @@ internal class SendStateFactory( isBalanceHidden = false, cryptoCurrencyName = "", isSubtracted = false, + amountState = AmountState.Empty(false), + editAmountState = AmountState.Empty(false), ) fun getReadyState(): SendUiState { val state = currentStateProvider() + val amountState = if (state.amountState is AmountState.Empty) { + amountStateConverter.convert("") + } else { + state.amountState + } return state.copy( - amountState = state.amountState ?: amountStateConverter.convert(""), + amountState = amountState, recipientState = state.recipientState ?: recipientStateConverter.convert(SendRecipientStateConverter.Data("", null)), feeState = state.feeState ?: feeStateConverter.convert(Unit), @@ -95,8 +94,13 @@ internal class SendStateFactory( fun getReadyState(amount: String, destinationAddress: String, memo: String?): SendUiState { val state = currentStateProvider() + val amountState = if (state.amountState is AmountState.Empty) { + amountStateConverter.convert(amount) + } else { + state.amountState + } return state.copy( - amountState = state.amountState ?: amountStateConverter.convert(amount), + amountState = amountState, recipientState = state.recipientState ?: recipientStateConverter.convert(SendRecipientStateConverter.Data(destinationAddress, memo)), feeState = state.feeState ?: feeStateConverter.convert(Unit), @@ -117,7 +121,7 @@ internal class SendStateFactory( fun getIsAmountSubtractedState(isAmountSubtractAvailable: Boolean): SendUiState { val state = currentStateProvider() val balance = cryptoCurrencyStatusProvider().value.amount ?: return state - val amountState = state.getAmountState(stateRouterProvider().isEditState) ?: return state + val amountState = state.getAmountState(stateRouterProvider().isEditState) as? AmountState.Data ?: return state val feeState = state.getFeeState(stateRouterProvider().isEditState) ?: return state val amountValue = amountState.amountTextField.cryptoAmount.value ?: return state val feeValue = feeState.fee?.amount?.value ?: BigDecimal.ZERO @@ -146,7 +150,7 @@ internal class SendStateFactory( ) } - fun getTransactionSendState(txData: TransactionData, txUrl: String): SendUiState { + fun getTransactionSendState(txData: TransactionData.Uncompiled, txUrl: String): SendUiState { val state = currentStateProvider() val sendState = state.sendState ?: return state return state.copy( diff --git a/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/state/SendUiState.kt b/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/state/SendUiState.kt index c718256d95..e9badc64d0 100644 --- a/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/state/SendUiState.kt +++ b/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/state/SendUiState.kt @@ -3,17 +3,14 @@ package com.tangem.features.send.impl.presentation.state import androidx.compose.runtime.Immutable import androidx.compose.runtime.Stable import com.tangem.blockchain.common.transaction.Fee -import com.tangem.core.ui.components.currency.tokenicon.TokenIconState +import com.tangem.common.ui.amountScreen.models.AmountState import com.tangem.core.ui.event.StateEvent -import com.tangem.core.ui.extensions.TextReference import com.tangem.domain.appcurrency.model.AppCurrency import com.tangem.features.send.impl.presentation.domain.SendRecipientListContent -import com.tangem.features.send.impl.presentation.state.amount.SendAmountSegmentedButtonsConfig import com.tangem.features.send.impl.presentation.state.fee.FeeSelectorState import com.tangem.features.send.impl.presentation.state.fields.SendTextField import com.tangem.features.send.impl.presentation.viewmodel.SendClickIntents import kotlinx.collections.immutable.ImmutableList -import kotlinx.collections.immutable.PersistentList import java.math.BigDecimal /** @@ -24,11 +21,11 @@ internal data class SendUiState( val clickIntents: SendClickIntents, val isEditingDisabled: Boolean, val cryptoCurrencyName: String, - val amountState: SendStates.AmountState? = null, + val amountState: AmountState, val recipientState: SendStates.RecipientState? = null, val feeState: SendStates.FeeState? = null, val sendState: SendStates.SendState? = null, - val editAmountState: SendStates.AmountState? = null, + val editAmountState: AmountState, val editRecipientState: SendStates.RecipientState? = null, val editFeeState: SendStates.FeeState? = null, val isBalanceHidden: Boolean, @@ -36,7 +33,7 @@ internal data class SendUiState( val event: StateEvent, ) { - fun getAmountState(isEditState: Boolean): SendStates.AmountState? { + fun getAmountState(isEditState: Boolean): AmountState { return if (isEditState) { editAmountState } else { @@ -62,7 +59,7 @@ internal data class SendUiState( fun copyWrapped( isEditState: Boolean, - amountState: SendStates.AmountState? = this.amountState, + amountState: AmountState = this.amountState, feeState: SendStates.FeeState? = this.feeState, recipientState: SendStates.RecipientState? = this.recipientState, sendState: SendStates.SendState? = this.sendState, @@ -90,21 +87,6 @@ internal sealed class SendStates { abstract val isPrimaryButtonEnabled: Boolean - /** Amount state */ - @Stable - data class AmountState( - override val type: SendUiStateType = SendUiStateType.Amount, - override val isPrimaryButtonEnabled: Boolean, - val walletName: String, - val walletBalance: TextReference, - val tokenIconState: TokenIconState, - val segmentedButtonConfig: PersistentList, - val selectedButton: Int, - val isSegmentedButtonsEnabled: Boolean, - val amountTextField: SendTextField.AmountField, - val appCurrencyCode: String, - ) : SendStates() - /** Recipient state */ @Stable data class RecipientState( diff --git a/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/state/StateRouter.kt b/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/state/StateRouter.kt index e09467fa9c..6335c3b154 100644 --- a/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/state/StateRouter.kt +++ b/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/state/StateRouter.kt @@ -1,15 +1,14 @@ package com.tangem.features.send.impl.presentation.state -import androidx.fragment.app.FragmentManager +import com.tangem.common.routing.AppRouter import com.tangem.core.analytics.api.AnalyticsEventHandler import com.tangem.features.send.impl.presentation.analytics.SendAnalyticEvents import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.StateFlow import kotlinx.coroutines.flow.update -import java.lang.ref.WeakReference internal class StateRouter( - private val fragmentManager: WeakReference, + private val appRouter: AppRouter, private val analyticsEventsHandler: AnalyticsEventHandler, private val isEditingDisabled: Boolean, ) { @@ -26,7 +25,7 @@ internal class StateRouter( } fun popBackStack() { - fragmentManager.get()?.popBackStack() + appRouter.pop() } fun onBackClick(isSuccess: Boolean = false) { diff --git a/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/state/amount/AmountStateFactory.kt b/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/state/amount/AmountStateFactory.kt index d933d3276f..204918b99b 100644 --- a/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/state/amount/AmountStateFactory.kt +++ b/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/state/amount/AmountStateFactory.kt @@ -1,5 +1,6 @@ package com.tangem.features.send.impl.presentation.state.amount +import com.tangem.common.ui.amountScreen.converters.AmountReduceByTransformer import com.tangem.domain.tokens.model.CryptoCurrencyStatus import com.tangem.features.send.impl.presentation.state.SendUiState import com.tangem.features.send.impl.presentation.state.StateRouter @@ -64,7 +65,7 @@ internal class AmountStateFactory( fun getOnAmountReduceByState(reduceAmountBy: BigDecimal, reduceAmountByDiff: BigDecimal) = amountReduceByConverter.convert( - SendAmountReduceByConverter.ReduceByData( + AmountReduceByTransformer.ReduceByData( reduceAmountBy = reduceAmountBy, reduceAmountByDiff = reduceAmountByDiff, ), diff --git a/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/state/amount/SendAmountCurrencyConverter.kt b/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/state/amount/SendAmountCurrencyConverter.kt index fa31b63ea0..c59bf9780c 100644 --- a/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/state/amount/SendAmountCurrencyConverter.kt +++ b/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/state/amount/SendAmountCurrencyConverter.kt @@ -1,46 +1,27 @@ package com.tangem.features.send.impl.presentation.state.amount -import androidx.compose.foundation.text.KeyboardOptions -import androidx.compose.ui.text.input.ImeAction -import androidx.compose.ui.text.input.KeyboardType +import com.tangem.common.ui.amountScreen.converters.AmountCurrencyTransformer +import com.tangem.common.ui.amountScreen.models.AmountState import com.tangem.domain.tokens.model.CryptoCurrencyStatus import com.tangem.features.send.impl.presentation.state.SendUiState import com.tangem.features.send.impl.presentation.state.StateRouter import com.tangem.utils.Provider import com.tangem.utils.converter.Converter -import com.tangem.utils.isNullOrZero internal class SendAmountCurrencyConverter( private val stateRouterProvider: Provider, private val currentStateProvider: Provider, private val cryptoCurrencyStatusProvider: Provider, ) : Converter { + override fun convert(value: Boolean): SendUiState { val state = currentStateProvider() val isEditState = stateRouterProvider().isEditState - val amountState = state.getAmountState(isEditState) ?: return state - val amountTextField = amountState.amountTextField - val cryptoCurrencyStatus = cryptoCurrencyStatusProvider() + val amountState = state.getAmountState(isEditState) as? AmountState.Data ?: return state - val isValidFiatRate = cryptoCurrencyStatus.value.fiatRate.isNullOrZero() - val isDoneActionEnabled = amountState.isPrimaryButtonEnabled - return if (amountTextField.isFiatValue == value && !isValidFiatRate) { - state - } else { - return state.copyWrapped( - isEditState = isEditState, - amountState = amountState.copy( - amountTextField = amountTextField.copy( - isFiatValue = value, - isValuePasted = true, - keyboardOptions = KeyboardOptions( - imeAction = if (isDoneActionEnabled) ImeAction.Done else ImeAction.None, - keyboardType = KeyboardType.Number, - ), - ), - selectedButton = amountState.segmentedButtonConfig.indexOfFirst { it.isFiat == value }, - ), - ) - } + return state.copyWrapped( + isEditState = isEditState, + amountState = AmountCurrencyTransformer(cryptoCurrencyStatusProvider(), value).transform(amountState), + ) } } \ No newline at end of file diff --git a/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/state/amount/SendAmountPastedTriggerDismissConverter.kt b/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/state/amount/SendAmountPastedTriggerDismissConverter.kt index 093b1b6a8e..3766d7c9c9 100644 --- a/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/state/amount/SendAmountPastedTriggerDismissConverter.kt +++ b/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/state/amount/SendAmountPastedTriggerDismissConverter.kt @@ -1,5 +1,7 @@ package com.tangem.features.send.impl.presentation.state.amount +import com.tangem.common.ui.amountScreen.converters.AmountPastedTriggerDismissTransformer +import com.tangem.common.ui.amountScreen.models.AmountState import com.tangem.features.send.impl.presentation.state.SendUiState import com.tangem.features.send.impl.presentation.state.StateRouter import com.tangem.utils.Provider @@ -9,17 +11,15 @@ internal class SendAmountPastedTriggerDismissConverter( private val stateRouterProvider: Provider, private val currentStateProvider: Provider, ) : Converter { + override fun convert(value: Boolean): SendUiState { val state = currentStateProvider() val isEditState = stateRouterProvider().isEditState - val amountState = state.getAmountState(isEditState) ?: return state + val amountState = state.getAmountState(isEditState) as? AmountState.Data ?: return state + return state.copyWrapped( isEditState = isEditState, - amountState = amountState.copy( - amountTextField = amountState.amountTextField.copy( - isValuePasted = false, - ), - ), + amountState = AmountPastedTriggerDismissTransformer().transform(amountState), ) } } \ No newline at end of file diff --git a/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/state/amount/SendAmountReduceByConverter.kt b/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/state/amount/SendAmountReduceByConverter.kt index e937600d51..0468cd8c82 100644 --- a/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/state/amount/SendAmountReduceByConverter.kt +++ b/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/state/amount/SendAmountReduceByConverter.kt @@ -1,67 +1,29 @@ package com.tangem.features.send.impl.presentation.state.amount -import androidx.compose.foundation.text.KeyboardOptions -import androidx.compose.ui.text.input.KeyboardType -import com.tangem.common.extensions.isZero -import com.tangem.core.ui.utils.parseBigDecimal +import com.tangem.common.ui.amountScreen.converters.AmountReduceByTransformer import com.tangem.domain.tokens.model.CryptoCurrencyStatus import com.tangem.features.send.impl.presentation.state.SendUiState import com.tangem.features.send.impl.presentation.state.StateRouter import com.tangem.utils.Provider import com.tangem.utils.converter.Converter -import com.tangem.utils.isNullOrZero -import java.math.BigDecimal internal class SendAmountReduceByConverter( private val stateRouterProvider: Provider, private val currentStateProvider: Provider, private val cryptoCurrencyStatusProvider: Provider, -) : Converter { - override fun convert(value: ReduceByData): SendUiState { +) : Converter { + + override fun convert(value: AmountReduceByTransformer.ReduceByData): SendUiState { val state = currentStateProvider() - val cryptoCurrencyStatus = cryptoCurrencyStatusProvider() val isEditState = stateRouterProvider().isEditState val amountState = state.getAmountState(isEditState) ?: return state - val amountTextField = amountState.amountTextField - val cryptoDecimals = amountTextField.cryptoAmount.decimals - val fiatDecimals = amountTextField.fiatAmount.decimals - val amountValue = amountState.amountTextField.cryptoAmount.value ?: return state - val decimalCryptoValue = amountValue.minus(value.reduceAmountByDiff) - val cryptoValue = decimalCryptoValue.parseBigDecimal(cryptoDecimals) - val (fiatValue, decimalFiatValue) = cryptoValue.getFiatValue( - fiatRate = cryptoCurrencyStatus.value.fiatRate, - isFiatValue = false, - decimals = fiatDecimals, - ) - - val checkValue = if (amountTextField.isFiatValue) fiatValue else cryptoValue - val isExceedBalance = checkValue.checkExceedBalance(cryptoCurrencyStatus, amountTextField) - val isZero = if (amountTextField.isFiatValue) decimalFiatValue.isNullOrZero() else decimalCryptoValue.isZero() return state.copyWrapped( isEditState = isEditState, sendState = state.sendState?.copy( reduceAmountBy = value.reduceAmountBy, ), - amountState = amountState.copy( - isPrimaryButtonEnabled = !isExceedBalance && !isZero, - amountTextField = amountTextField.copy( - value = cryptoValue, - fiatValue = fiatValue, - isError = isExceedBalance, - cryptoAmount = amountTextField.cryptoAmount.copy(value = decimalCryptoValue), - fiatAmount = amountTextField.fiatAmount.copy(value = decimalFiatValue), - keyboardOptions = KeyboardOptions( - imeAction = getKeyboardAction(isExceedBalance, decimalCryptoValue), - keyboardType = KeyboardType.Number, - ), - ), - ), + amountState = AmountReduceByTransformer(cryptoCurrencyStatusProvider(), value).transform(amountState), ) } - - internal data class ReduceByData( - val reduceAmountBy: BigDecimal, - val reduceAmountByDiff: BigDecimal, - ) } \ No newline at end of file diff --git a/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/state/amount/SendAmountReduceToConverter.kt b/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/state/amount/SendAmountReduceToConverter.kt index 76fd7e2654..1bb5518063 100644 --- a/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/state/amount/SendAmountReduceToConverter.kt +++ b/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/state/amount/SendAmountReduceToConverter.kt @@ -1,15 +1,11 @@ package com.tangem.features.send.impl.presentation.state.amount -import androidx.compose.foundation.text.KeyboardOptions -import androidx.compose.ui.text.input.KeyboardType -import com.tangem.common.extensions.isZero -import com.tangem.core.ui.utils.parseBigDecimal +import com.tangem.common.ui.amountScreen.converters.AmountReduceToTransformer import com.tangem.domain.tokens.model.CryptoCurrencyStatus import com.tangem.features.send.impl.presentation.state.SendUiState import com.tangem.features.send.impl.presentation.state.StateRouter import com.tangem.utils.Provider import com.tangem.utils.converter.Converter -import com.tangem.utils.isNullOrZero import java.math.BigDecimal internal class SendAmountReduceToConverter( @@ -17,41 +13,15 @@ internal class SendAmountReduceToConverter( private val currentStateProvider: Provider, private val cryptoCurrencyStatusProvider: Provider, ) : Converter { + override fun convert(value: BigDecimal): SendUiState { val state = currentStateProvider() - val cryptoCurrencyStatus = cryptoCurrencyStatusProvider() val isEditState = stateRouterProvider().isEditState val amountState = state.getAmountState(isEditState) ?: return state - val amountTextField = amountState.amountTextField - val cryptoDecimals = amountTextField.cryptoAmount.decimals - val fiatDecimals = amountTextField.fiatAmount.decimals - val cryptoValue = value.parseBigDecimal(cryptoDecimals) - val (fiatValue, decimalFiatValue) = cryptoValue.getFiatValue( - fiatRate = cryptoCurrencyStatus.value.fiatRate, - isFiatValue = false, - decimals = fiatDecimals, - ) - - val checkValue = if (amountTextField.isFiatValue) fiatValue else cryptoValue - val isExceedBalance = checkValue.checkExceedBalance(cryptoCurrencyStatus, amountTextField) - val isZero = if (amountTextField.isFiatValue) decimalFiatValue.isNullOrZero() else value.isZero() return state.copyWrapped( isEditState = isEditState, - amountState = amountState.copy( - isPrimaryButtonEnabled = !isExceedBalance && !isZero, - amountTextField = amountTextField.copy( - value = cryptoValue, - fiatValue = fiatValue, - isError = isExceedBalance, - cryptoAmount = amountTextField.cryptoAmount.copy(value = value), - fiatAmount = amountTextField.fiatAmount.copy(value = decimalFiatValue), - keyboardOptions = KeyboardOptions( - imeAction = getKeyboardAction(isExceedBalance, value), - keyboardType = KeyboardType.Number, - ), - ), - ), + amountState = AmountReduceToTransformer(cryptoCurrencyStatusProvider(), value).transform(amountState), ) } } \ No newline at end of file diff --git a/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/state/confirm/SendNotificationFactory.kt b/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/state/confirm/SendNotificationFactory.kt index 16c1315e2d..a4e3bcbf9c 100644 --- a/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/state/confirm/SendNotificationFactory.kt +++ b/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/state/confirm/SendNotificationFactory.kt @@ -6,6 +6,9 @@ import com.tangem.blockchain.common.transaction.Fee import com.tangem.blockchain.common.transaction.TransactionFee import com.tangem.blockchainsdk.utils.fromNetworkId import com.tangem.blockchainsdk.utils.minimalAmount +import com.tangem.common.ui.amountScreen.models.AmountFieldModel +import com.tangem.common.ui.amountScreen.models.AmountState +import com.tangem.common.ui.amountScreen.utils.getFiatString import com.tangem.core.analytics.api.AnalyticsEventHandler import com.tangem.core.ui.extensions.networkIconResId import com.tangem.core.ui.utils.BigDecimalFormatter @@ -24,8 +27,6 @@ import com.tangem.features.send.impl.R import com.tangem.features.send.impl.presentation.analytics.SendAnalyticEvents import com.tangem.features.send.impl.presentation.state.* import com.tangem.features.send.impl.presentation.state.fee.* -import com.tangem.features.send.impl.presentation.state.fields.SendTextField -import com.tangem.features.send.impl.presentation.utils.getFiatString import com.tangem.features.send.impl.presentation.viewmodel.SendClickIntents import com.tangem.lib.crypto.BlockchainUtils import com.tangem.lib.crypto.BlockchainUtils.isTezos @@ -41,7 +42,7 @@ import java.math.BigDecimal @Suppress("LongParameterList", "LargeClass") internal class SendNotificationFactory( private val cryptoCurrencyStatusProvider: Provider, - private val coinCryptoCurrencyStatusProvider: Provider, + private val feeCryptoCurrencyStatusProvider: Provider, private val currentStateProvider: Provider, private val userWalletProvider: Provider, private val currencyChecksRepository: CurrencyChecksRepository, @@ -62,7 +63,7 @@ internal class SendNotificationFactory( val balance = cryptoCurrencyStatusProvider().value.amount ?: BigDecimal.ZERO val sendState = state.sendState ?: return@map persistentListOf() val feeState = state.getFeeState(isEditState) ?: return@map persistentListOf() - val amountState = state.getAmountState(isEditState) ?: return@map persistentListOf() + val amountState = state.getAmountState(isEditState) as? AmountState.Data ?: return@map persistentListOf() val amountValue = amountState.amountTextField.cryptoAmount.value ?: BigDecimal.ZERO val feeValue = feeState.fee?.amount?.value ?: BigDecimal.ZERO @@ -125,8 +126,18 @@ internal class SendNotificationFactory( } private fun MutableList.addFeeUnreachableNotification(feeSelectorState: FeeSelectorState) { - if (feeSelectorState is FeeSelectorState.Error) { - add(SendNotification.Warning.NetworkFeeUnreachable(clickIntents::feeReload)) + when (feeSelectorState) { + is FeeSelectorState.Error.TronAccountActivationError -> add( + SendNotification.Warning.TronAccountNotActivated( + feeSelectorState.tokenName, + ), + ) + is FeeSelectorState.Error.NetworkError -> add( + SendNotification.Warning.NetworkFeeUnreachable(clickIntents::feeReload), + ) + else -> { + /* do nothing */ + } } } @@ -239,7 +250,7 @@ internal class SendNotificationFactory( private fun MutableList.addFeeCoverageNotification( isFeeCoverage: Boolean, - amountField: SendTextField.AmountField, + amountField: AmountFieldModel, sendingValue: BigDecimal, ) { if (isFeeCoverage) { @@ -307,6 +318,7 @@ internal class SendNotificationFactory( private fun checkDustLimits(feeAmount: BigDecimal, receivedAmount: BigDecimal, dustValue: BigDecimal): Boolean { val cryptoCurrencyStatus = cryptoCurrencyStatusProvider() + val feeCurrencyStatus = feeCryptoCurrencyStatusProvider() ?: return false val change = when (cryptoCurrencyStatus.currency) { is CryptoCurrency.Coin -> { @@ -314,7 +326,7 @@ internal class SendNotificationFactory( balance - (feeAmount + receivedAmount) } is CryptoCurrency.Token -> { - val balance = coinCryptoCurrencyStatusProvider().value.amount ?: BigDecimal.ZERO + val balance = feeCurrencyStatus.value.amount ?: BigDecimal.ZERO balance - feeAmount } } @@ -351,16 +363,14 @@ internal class SendNotificationFactory( val feeValue = fee?.amount?.value ?: BigDecimal.ZERO val userWalletId = userWalletProvider().walletId val cryptoCurrencyStatus = cryptoCurrencyStatusProvider() + val feeCurrencyStatus = feeCryptoCurrencyStatusProvider() ?: return val warning = getBalanceNotEnoughForFeeWarningUseCase( fee = feeValue, userWalletId = userWalletId, tokenStatus = cryptoCurrencyStatus, - coinStatus = coinCryptoCurrencyStatusProvider(), - ).fold( - ifLeft = { null }, - ifRight = { it }, - ) ?: return + coinStatus = feeCurrencyStatus, + ).getOrNull() ?: return val mergeFeeNetworkName = cryptoCurrencyStatus.shouldMergeFeeNetworkName() when (warning) { diff --git a/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/state/fee/FeeConverter.kt b/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/state/fee/FeeConverter.kt index 5109aa17b9..670da73277 100644 --- a/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/state/fee/FeeConverter.kt +++ b/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/state/fee/FeeConverter.kt @@ -8,6 +8,7 @@ import com.tangem.domain.tokens.model.CryptoCurrencyStatus import com.tangem.features.send.impl.presentation.state.StateRouter import com.tangem.features.send.impl.presentation.state.fee.custom.BitcoinCustomFeeConverter import com.tangem.features.send.impl.presentation.state.fee.custom.EthereumCustomFeeConverter +import com.tangem.features.send.impl.presentation.state.fee.custom.KaspaCustomFeeConverter import com.tangem.features.send.impl.presentation.viewmodel.SendClickIntents import com.tangem.utils.Provider import com.tangem.utils.converter.Converter @@ -37,6 +38,15 @@ internal class FeeConverter( ) } + private val kaspaCustomFeeConverter by lazy(LazyThreadSafetyMode.NONE) { + KaspaCustomFeeConverter( + clickIntents = clickIntents, + stateRouterProvider = stateRouterProvider, + appCurrencyProvider = appCurrencyProvider, + feeCryptoCurrencyStatusProvider = feeCryptoCurrencyStatusProvider, + ) + } + override fun convert(value: FeeSelectorState.Content): Fee { return when (val fees = value.fees) { is TransactionFee.Choosable -> { @@ -47,7 +57,12 @@ internal class FeeConverter( FeeType.Custom -> convertCustom(value, fees) } } - is TransactionFee.Single -> fees.normal + is TransactionFee.Single -> + when (value.selectedFee) { + FeeType.Market -> fees.normal + FeeType.Custom -> convertCustom(value, fees) + else -> fees.normal + } } } @@ -60,6 +75,7 @@ internal class FeeConverter( when (normalFee) { is Fee.Ethereum -> ethereumCustomFeeConverter.convertBack(normalFee = normalFee, value = customValues) is Fee.Bitcoin -> bitcoinCustomFeeConverter.convertBack(normalFee = normalFee, value = customValues) + is Fee.Kaspa -> kaspaCustomFeeConverter.convertBack(normalFee = normalFee, value = customValues) else -> { val customFee = customValues.firstOrNull() Fee.Common( diff --git a/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/state/fee/FeeNotificationFactory.kt b/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/state/fee/FeeNotificationFactory.kt index 229568a930..aba37ba2ea 100644 --- a/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/state/fee/FeeNotificationFactory.kt +++ b/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/state/fee/FeeNotificationFactory.kt @@ -1,6 +1,9 @@ package com.tangem.features.send.impl.presentation.state.fee -import com.tangem.features.send.impl.presentation.state.* +import com.tangem.features.send.impl.presentation.state.SendNotification +import com.tangem.features.send.impl.presentation.state.SendUiState +import com.tangem.features.send.impl.presentation.state.SendUiStateType +import com.tangem.features.send.impl.presentation.state.StateRouter import com.tangem.features.send.impl.presentation.viewmodel.SendClickIntents import com.tangem.utils.Provider import kotlinx.collections.immutable.persistentListOf @@ -21,13 +24,25 @@ internal class FeeNotificationFactory( val state = currentStateProvider() val feeState = state.getFeeState(stateRouterProvider().isEditState) ?: return@map persistentListOf() buildList { - addFeeUnreachableNotification(feeState.feeSelectorState) + addFeeUnreachableNotification( + feeState.feeSelectorState, + ) }.toImmutableList() } private fun MutableList.addFeeUnreachableNotification(feeSelectorState: FeeSelectorState) { - if (feeSelectorState is FeeSelectorState.Error) { - add(SendNotification.Warning.NetworkFeeUnreachable(clickIntents::feeReload)) + when (feeSelectorState) { + is FeeSelectorState.Error.TronAccountActivationError -> add( + SendNotification.Warning.TronAccountNotActivated( + feeSelectorState.tokenName, + ), + ) + is FeeSelectorState.Error.NetworkError -> add( + SendNotification.Warning.NetworkFeeUnreachable(clickIntents::feeReload), + ) + else -> { + /* do nothing */ + } } } } \ No newline at end of file diff --git a/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/state/fee/FeeSelectorState.kt b/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/state/fee/FeeSelectorState.kt index cd1fe29939..6ee78a7939 100644 --- a/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/state/fee/FeeSelectorState.kt +++ b/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/state/fee/FeeSelectorState.kt @@ -17,7 +17,10 @@ internal sealed class FeeSelectorState { data object Loading : FeeSelectorState() - data object Error : FeeSelectorState() + sealed class Error : FeeSelectorState() { + data object NetworkError : Error() + data class TronAccountActivationError(val tokenName: String) : Error() + } } enum class FeeType { diff --git a/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/state/fee/FeeStateFactory.kt b/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/state/fee/FeeStateFactory.kt index e933b89477..3a30e424b9 100644 --- a/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/state/fee/FeeStateFactory.kt +++ b/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/state/fee/FeeStateFactory.kt @@ -99,13 +99,13 @@ internal class FeeStateFactory( ) } - fun onFeeOnErrorState(): SendUiState { + fun onFeeOnErrorState(feeError: FeeSelectorState.Error): SendUiState { val state = currentStateProvider() val isEditState = stateRouterProvider().isEditState return state.copyWrapped( isEditState = isEditState, feeState = state.getFeeState(isEditState)?.copy( - feeSelectorState = FeeSelectorState.Error, + feeSelectorState = feeError, ), sendState = state.sendState?.copy( isPrimaryButtonEnabled = false, diff --git a/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/state/fee/SendFeeCustomFieldConverter.kt b/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/state/fee/SendFeeCustomFieldConverter.kt index 5fd2a4060d..d80cf917b0 100644 --- a/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/state/fee/SendFeeCustomFieldConverter.kt +++ b/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/state/fee/SendFeeCustomFieldConverter.kt @@ -6,6 +6,7 @@ import com.tangem.domain.tokens.model.CryptoCurrencyStatus import com.tangem.features.send.impl.presentation.state.StateRouter import com.tangem.features.send.impl.presentation.state.fee.custom.BitcoinCustomFeeConverter import com.tangem.features.send.impl.presentation.state.fee.custom.EthereumCustomFeeConverter +import com.tangem.features.send.impl.presentation.state.fee.custom.KaspaCustomFeeConverter import com.tangem.features.send.impl.presentation.state.fields.SendTextField import com.tangem.features.send.impl.presentation.viewmodel.SendClickIntents import com.tangem.utils.Provider @@ -38,10 +39,20 @@ internal class SendFeeCustomFieldConverter( ) } + private val kaspaCustomFeeConverter by lazy(LazyThreadSafetyMode.NONE) { + KaspaCustomFeeConverter( + clickIntents = clickIntents, + stateRouterProvider = stateRouterProvider, + appCurrencyProvider = appCurrencyProvider, + feeCryptoCurrencyStatusProvider = feeCryptoCurrencyStatusProvider, + ) + } + override fun convert(value: Fee): ImmutableList { return when (value) { is Fee.Ethereum -> ethereumCustomFeeConverter.convert(value) is Fee.Bitcoin -> bitcoinCustomFeeConverter.convert(value) + is Fee.Kaspa -> kaspaCustomFeeConverter.convert(value) else -> persistentListOf() } } @@ -59,6 +70,12 @@ internal class SendFeeCustomFieldConverter( value = value, txSize = fee.txSize, ) + is Fee.Kaspa -> kaspaCustomFeeConverter.onValueChange( + customValues = feeSelectorState.customValues, + index = index, + value = value, + utxoCount = fee.utxoCount, + ) else -> feeSelectorState.customValues }, ) diff --git a/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/state/fee/custom/BitcoinCustomFeeConverter.kt b/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/state/fee/custom/BitcoinCustomFeeConverter.kt index 62bf1460ad..2d5e5999e3 100644 --- a/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/state/fee/custom/BitcoinCustomFeeConverter.kt +++ b/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/state/fee/custom/BitcoinCustomFeeConverter.kt @@ -5,6 +5,7 @@ import androidx.compose.foundation.text.KeyboardOptions import androidx.compose.ui.text.input.ImeAction import androidx.compose.ui.text.input.KeyboardType import com.tangem.blockchain.common.transaction.Fee +import com.tangem.common.ui.amountScreen.utils.getFiatReference import com.tangem.core.ui.extensions.resourceReference import com.tangem.core.ui.utils.parseBigDecimal import com.tangem.core.ui.utils.parseToBigDecimal @@ -14,7 +15,6 @@ import com.tangem.features.send.impl.R import com.tangem.features.send.impl.presentation.state.StateRouter import com.tangem.features.send.impl.presentation.state.fee.checkExceedBalance import com.tangem.features.send.impl.presentation.state.fields.SendTextField -import com.tangem.features.send.impl.presentation.utils.getFiatReference import com.tangem.features.send.impl.presentation.viewmodel.SendClickIntents import com.tangem.lib.crypto.BlockchainUtils.isBitcoin import com.tangem.utils.Provider diff --git a/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/state/fee/custom/EthereumCustomFeeConverter.kt b/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/state/fee/custom/EthereumCustomFeeConverter.kt index d64f1c3d47..fdee783db4 100644 --- a/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/state/fee/custom/EthereumCustomFeeConverter.kt +++ b/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/state/fee/custom/EthereumCustomFeeConverter.kt @@ -5,6 +5,7 @@ import androidx.compose.foundation.text.KeyboardOptions import androidx.compose.ui.text.input.ImeAction import androidx.compose.ui.text.input.KeyboardType import com.tangem.blockchain.common.transaction.Fee +import com.tangem.common.ui.amountScreen.utils.getFiatReference import com.tangem.core.ui.extensions.resourceReference import com.tangem.core.ui.utils.parseBigDecimal import com.tangem.core.ui.utils.parseToBigDecimal @@ -14,7 +15,6 @@ import com.tangem.features.send.impl.R import com.tangem.features.send.impl.presentation.state.StateRouter import com.tangem.features.send.impl.presentation.state.fee.checkExceedBalance import com.tangem.features.send.impl.presentation.state.fields.SendTextField -import com.tangem.features.send.impl.presentation.utils.getFiatReference import com.tangem.features.send.impl.presentation.viewmodel.SendClickIntents import com.tangem.utils.Provider import kotlinx.collections.immutable.ImmutableList @@ -43,7 +43,7 @@ internal class EthereumCustomFeeConverter( keyboardType = KeyboardType.Number, ), title = resourceReference(R.string.send_max_fee), - footer = resourceReference(R.string.send_evm_custom_fee_footer), + footer = resourceReference(R.string.send_custom_amount_fee_footer), label = getFiatReference( rate = feeCurrency?.fiatRate, value = feeValue, diff --git a/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/state/fee/custom/KaspaCustomFeeConverter.kt b/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/state/fee/custom/KaspaCustomFeeConverter.kt new file mode 100644 index 0000000000..05b117547d --- /dev/null +++ b/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/state/fee/custom/KaspaCustomFeeConverter.kt @@ -0,0 +1,153 @@ +package com.tangem.features.send.impl.presentation.state.fee.custom + +import androidx.compose.foundation.text.KeyboardActions +import androidx.compose.foundation.text.KeyboardOptions +import androidx.compose.ui.text.input.ImeAction +import androidx.compose.ui.text.input.KeyboardType +import com.tangem.blockchain.common.transaction.Fee +import com.tangem.common.ui.amountScreen.utils.getFiatReference +import com.tangem.core.ui.extensions.resourceReference +import com.tangem.core.ui.utils.parseBigDecimal +import com.tangem.core.ui.utils.parseToBigDecimal +import com.tangem.domain.appcurrency.model.AppCurrency +import com.tangem.domain.tokens.model.CryptoCurrencyStatus +import com.tangem.features.send.impl.R +import com.tangem.features.send.impl.presentation.state.StateRouter +import com.tangem.features.send.impl.presentation.state.fee.checkExceedBalance +import com.tangem.features.send.impl.presentation.state.fields.SendTextField +import com.tangem.features.send.impl.presentation.viewmodel.SendClickIntents +import com.tangem.utils.Provider +import kotlinx.collections.immutable.ImmutableList +import kotlinx.collections.immutable.persistentListOf +import kotlinx.collections.immutable.toImmutableList +import java.math.RoundingMode + +internal class KaspaCustomFeeConverter( + private val clickIntents: SendClickIntents, + private val stateRouterProvider: Provider, + private val appCurrencyProvider: Provider, + private val feeCryptoCurrencyStatusProvider: Provider, +) : CustomFeeConverter { + + override fun convert(value: Fee.Kaspa): ImmutableList { + val feeValue = value.amount.value + val feeCurrency = feeCryptoCurrencyStatusProvider()?.value + val network = feeCryptoCurrencyStatusProvider()?.currency?.network?.id?.value + return if (network != null) { + persistentListOf( + SendTextField.CustomFee( + value = feeValue?.parseBigDecimal(value.amount.decimals).orEmpty(), + decimals = value.amount.decimals, + symbol = value.amount.currencySymbol, + onValueChange = { clickIntents.onCustomFeeValueChange(FEE_AMOUNT_INDEX, it) }, + keyboardOptions = KeyboardOptions( + imeAction = ImeAction.Next, + keyboardType = KeyboardType.Number, + ), + title = resourceReference(R.string.send_max_fee), + footer = resourceReference(R.string.send_custom_amount_fee_footer), + label = getFiatReference( + rate = feeCurrency?.fiatRate, + value = feeValue, + appCurrency = appCurrencyProvider(), + ), + keyboardActions = KeyboardActions(), + ), + SendTextField.CustomFee( + value = value.valuePerUtxo.parseBigDecimal(value.amount.decimals), + decimals = value.amount.decimals, + symbol = "", + title = resourceReference(R.string.send_custom_kaspa_per_utxo_title), + footer = resourceReference(R.string.send_custom_kaspa_per_utxo_footer), + onValueChange = { clickIntents.onCustomFeeValueChange(FEE_VALUE_PER_UTXO_INDEX, it) }, + keyboardOptions = KeyboardOptions( + imeAction = if (checkExceedBalance( + feeBalance = feeCurrency?.amount, + feeAmount = feeValue, + ) + ) { + ImeAction.None + } else { + ImeAction.Done + }, + keyboardType = KeyboardType.Number, + ), + keyboardActions = KeyboardActions( + onDone = { clickIntents.onNextClick(stateRouterProvider().isEditState) }, + ), + ), + ) + } else { + persistentListOf() + } + } + + override fun convertBack(normalFee: Fee.Kaspa, value: ImmutableList): Fee.Kaspa { + val feeAmount = value[FEE_AMOUNT_INDEX].value.parseToBigDecimal(value[FEE_AMOUNT_INDEX].decimals) + val valuePerUtxo = + value[FEE_VALUE_PER_UTXO_INDEX].value.parseToBigDecimal(value[FEE_VALUE_PER_UTXO_INDEX].decimals) + return normalFee.copy( + amount = normalFee.amount.copy(value = feeAmount), + valuePerUtxo = valuePerUtxo, + ) + } + + fun onValueChange( + customValues: ImmutableList, + index: Int, + value: String, + utxoCount: Int, + ): ImmutableList { + val mutableCustomValues = customValues.toMutableList() + return mutableCustomValues.apply { + when (index) { + FEE_AMOUNT_INDEX -> { + val valueDecimal = value.parseToBigDecimal(this[FEE_AMOUNT_INDEX].decimals) + val newValuePerUtxo = valueDecimal.divide( + /* divisor = */ utxoCount.toBigDecimal(), + /* scale = */ this[FEE_VALUE_PER_UTXO_INDEX].decimals, + /* roundingMode = */ RoundingMode.HALF_UP, + ) + set( + FEE_VALUE_PER_UTXO_INDEX, + this[FEE_VALUE_PER_UTXO_INDEX].copy( + value = newValuePerUtxo.parseBigDecimal(this[FEE_VALUE_PER_UTXO_INDEX].decimals), + ), + ) + set( + index, + this[index].copy( + value = value, + label = getFiatReference( + rate = feeCryptoCurrencyStatusProvider()?.value?.fiatRate, + value = valueDecimal, + appCurrency = appCurrencyProvider(), + ), + ), + ) + } + FEE_VALUE_PER_UTXO_INDEX -> { + val valuePerUtxo = value.parseToBigDecimal(this[FEE_VALUE_PER_UTXO_INDEX].decimals) + val newFeeAmount = valuePerUtxo.multiply(utxoCount.toBigDecimal()) + set( + FEE_AMOUNT_INDEX, + this[FEE_AMOUNT_INDEX].copy( + value = newFeeAmount.parseBigDecimal(this[FEE_AMOUNT_INDEX].decimals), + label = getFiatReference( + rate = feeCryptoCurrencyStatusProvider()?.value?.fiatRate, + value = newFeeAmount, + appCurrency = appCurrencyProvider(), + ), + ), + ) + set(index, this[index].copy(value = value)) + } + } + }.toImmutableList() + } + + private companion object { + private const val FEE_AMOUNT_INDEX = 0 + private const val FEE_VALUE_PER_UTXO_INDEX = 1 + } +} \ No newline at end of file diff --git a/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/state/fields/SendAmountFieldChangeConverter.kt b/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/state/fields/SendAmountFieldChangeConverter.kt index 112b0f1cb7..4b5dda431d 100644 --- a/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/state/fields/SendAmountFieldChangeConverter.kt +++ b/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/state/fields/SendAmountFieldChangeConverter.kt @@ -1,89 +1,27 @@ package com.tangem.features.send.impl.presentation.state.fields -import androidx.compose.foundation.text.KeyboardOptions -import androidx.compose.ui.text.input.KeyboardType -import com.tangem.common.extensions.isZero -import com.tangem.core.ui.utils.parseToBigDecimal +import com.tangem.common.ui.amountScreen.converters.field.AmountFieldChangeTransformer import com.tangem.domain.tokens.model.CryptoCurrencyStatus import com.tangem.features.send.impl.presentation.state.SendUiState import com.tangem.features.send.impl.presentation.state.StateRouter -import com.tangem.features.send.impl.presentation.state.amount.checkExceedBalance -import com.tangem.features.send.impl.presentation.state.amount.getCryptoValue -import com.tangem.features.send.impl.presentation.state.amount.getFiatValue -import com.tangem.features.send.impl.presentation.state.amount.getKeyboardAction import com.tangem.utils.Provider import com.tangem.utils.converter.Converter -import com.tangem.utils.isNullOrZero -import java.math.BigDecimal internal class SendAmountFieldChangeConverter( private val stateRouterProvider: Provider, private val currentStateProvider: Provider, private val cryptoCurrencyStatusProvider: Provider, ) : Converter { + override fun convert(value: String): SendUiState { val state = currentStateProvider() - val cryptoCurrencyStatus = cryptoCurrencyStatusProvider() val isEditState = stateRouterProvider().isEditState val amountState = state.getAmountState(isEditState) ?: return state - val amountTextField = amountState.amountTextField - if (value.isEmpty()) return state.emptyState() - val cryptoDecimals = amountTextField.cryptoAmount.decimals - val fiatDecimals = amountTextField.fiatAmount.decimals - - val trimmedValue = value.trim() - val cryptoValue = trimmedValue.getCryptoValue( - fiatRate = cryptoCurrencyStatus.value.fiatRate, - isFiatValue = amountTextField.isFiatValue, - decimals = cryptoDecimals, - ) - val decimalCryptoValue = cryptoValue.parseToBigDecimal(cryptoDecimals) - val (fiatValue, decimalFiatValue) = trimmedValue.getFiatValue( - fiatRate = cryptoCurrencyStatus.value.fiatRate, - isFiatValue = amountTextField.isFiatValue, - decimals = fiatDecimals, - ) - - val checkValue = if (amountTextField.isFiatValue) fiatValue else cryptoValue - val isExceedBalance = checkValue.checkExceedBalance(cryptoCurrencyStatus, amountTextField) - val isZero = if (amountTextField.isFiatValue) decimalFiatValue.isNullOrZero() else decimalCryptoValue.isZero() return state.copyWrapped( isEditState = isEditState, sendState = state.sendState?.copy(reduceAmountBy = null), - amountState = amountState.copy( - isPrimaryButtonEnabled = !isExceedBalance && !isZero, - amountTextField = amountTextField.copy( - value = cryptoValue, - fiatValue = fiatValue, - isError = isExceedBalance, - cryptoAmount = amountTextField.cryptoAmount.copy(value = decimalCryptoValue), - fiatAmount = amountTextField.fiatAmount.copy(value = decimalFiatValue), - keyboardOptions = KeyboardOptions( - imeAction = getKeyboardAction(isExceedBalance, decimalCryptoValue), - keyboardType = KeyboardType.Number, - ), - ), - ), - ) - } - - private fun SendUiState.emptyState(): SendUiState { - val isEditState = stateRouterProvider().isEditState - val amountState = getAmountState(isEditState) ?: return this - val amountTextField = amountState.amountTextField - return copyWrapped( - isEditState = isEditState, - amountState = amountState.copy( - isPrimaryButtonEnabled = false, - amountTextField = amountTextField.copy( - value = "", - fiatValue = "", - cryptoAmount = amountTextField.cryptoAmount.copy(value = BigDecimal.ZERO), - fiatAmount = amountTextField.fiatAmount.copy(value = BigDecimal.ZERO), - isError = false, - ), - ), + amountState = AmountFieldChangeTransformer(cryptoCurrencyStatusProvider(), value).transform(amountState), ) } } \ No newline at end of file diff --git a/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/state/fields/SendAmountFieldMaxAmountConverter.kt b/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/state/fields/SendAmountFieldMaxAmountConverter.kt index 11cfa98faa..5577388040 100644 --- a/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/state/fields/SendAmountFieldMaxAmountConverter.kt +++ b/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/state/fields/SendAmountFieldMaxAmountConverter.kt @@ -1,16 +1,12 @@ package com.tangem.features.send.impl.presentation.state.fields -import androidx.compose.foundation.text.KeyboardOptions -import androidx.compose.ui.text.input.ImeAction -import androidx.compose.ui.text.input.KeyboardType -import com.tangem.core.ui.utils.parseBigDecimal +import com.tangem.common.ui.amountScreen.converters.field.AmountFieldMaxAmountTransformer import com.tangem.domain.tokens.model.CryptoCurrencyStatus import com.tangem.features.send.impl.presentation.state.SendUiState import com.tangem.features.send.impl.presentation.state.StateRouter import com.tangem.utils.Provider import com.tangem.utils.converter.Converter import com.tangem.utils.isNullOrZero -import java.math.RoundingMode internal class SendAmountFieldMaxAmountConverter( private val stateRouterProvider: Provider, @@ -23,36 +19,14 @@ internal class SendAmountFieldMaxAmountConverter( val cryptoCurrencyStatus = cryptoCurrencyStatusProvider() val isEditState = stateRouterProvider().isEditState val amountState = state.getAmountState(isEditState) ?: return state - val amountTextField = amountState.amountTextField - val cryptoDecimals = amountTextField.cryptoAmount.decimals - val fiatDecimals = amountTextField.fiatAmount.decimals val decimalCryptoValue = cryptoCurrencyStatus.value.amount - val decimalFiatValue = cryptoCurrencyStatus.value.fiatAmount - if (decimalCryptoValue.isNullOrZero()) return state - val isDoneActionEnabled = !decimalCryptoValue.isNullOrZero() - val cryptoValue = decimalCryptoValue?.parseBigDecimal(cryptoDecimals).orEmpty() - val fiatValue = decimalFiatValue?.parseBigDecimal(fiatDecimals, roundingMode = RoundingMode.HALF_UP).orEmpty() return state.copyWrapped( isEditState = isEditState, sendState = state.sendState?.copy(reduceAmountBy = null), - amountState = amountState.copy( - isPrimaryButtonEnabled = true, - amountTextField = amountTextField.copy( - isValuePasted = true, - value = cryptoValue, - fiatValue = fiatValue, - isError = false, - cryptoAmount = amountTextField.cryptoAmount.copy(value = decimalCryptoValue), - fiatAmount = amountTextField.fiatAmount.copy(value = decimalFiatValue), - keyboardOptions = KeyboardOptions( - imeAction = if (isDoneActionEnabled) ImeAction.Done else ImeAction.None, - keyboardType = KeyboardType.Number, - ), - ), - ), + amountState = AmountFieldMaxAmountTransformer(cryptoCurrencyStatusProvider()).transform(amountState), ) } } \ No newline at end of file diff --git a/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/state/fields/SendTextField.kt b/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/state/fields/SendTextField.kt index 4f5ce27038..e289c7968a 100644 --- a/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/state/fields/SendTextField.kt +++ b/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/state/fields/SendTextField.kt @@ -4,7 +4,6 @@ import androidx.compose.foundation.text.KeyboardActions import androidx.compose.foundation.text.KeyboardOptions import androidx.compose.runtime.Immutable import com.tangem.core.ui.extensions.TextReference -import com.tangem.domain.tokens.model.Amount @Immutable internal sealed class SendTextField { @@ -18,22 +17,6 @@ internal sealed class SendTextField { /** Keyboard options */ abstract val keyboardOptions: KeyboardOptions - data class AmountField( - override val value: String, - override val onValueChange: (String) -> Unit, - override val keyboardOptions: KeyboardOptions, - val keyboardActions: KeyboardActions, - val cryptoAmount: Amount, - val fiatAmount: Amount, - val isFiatValue: Boolean, - val fiatValue: String, - val isFiatUnavailable: Boolean, - val isValuePasted: Boolean, - val onValuePastedTriggerDismiss: () -> Unit, - val isError: Boolean, - val error: TextReference, - ) : SendTextField() - data class RecipientAddress( override val value: String, override val onValueChange: (String) -> Unit, diff --git a/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/state/previewdata/FeeStatePreviewData.kt b/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/state/previewdata/FeeStatePreviewData.kt index c024b39ee0..7d00f7102d 100644 --- a/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/state/previewdata/FeeStatePreviewData.kt +++ b/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/state/previewdata/FeeStatePreviewData.kt @@ -102,6 +102,6 @@ internal object FeeStatePreviewData { ) val errorFeeState = feeState.copy( - feeSelectorState = FeeSelectorState.Error, + feeSelectorState = FeeSelectorState.Error.NetworkError, ) } \ No newline at end of file diff --git a/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/state/previewdata/SendClickIntentsStub.kt b/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/state/previewdata/SendClickIntentsStub.kt index 2eeda94fd5..8eab2cbac3 100644 --- a/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/state/previewdata/SendClickIntentsStub.kt +++ b/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/state/previewdata/SendClickIntentsStub.kt @@ -29,6 +29,7 @@ internal object SendClickIntentsStub : SendClickIntents { override fun onAmountValueChange(value: String) {} override fun onCurrencyChangeClick(isFiat: Boolean) {} + override fun onAmountNext() {} override fun onMaxValueClick() {} diff --git a/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/state/previewdata/SendStatesPreviewData.kt b/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/state/previewdata/SendStatesPreviewData.kt index 2366b09686..dd64a24aed 100644 --- a/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/state/previewdata/SendStatesPreviewData.kt +++ b/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/state/previewdata/SendStatesPreviewData.kt @@ -1,5 +1,6 @@ package com.tangem.features.send.impl.presentation.state.previewdata +import com.tangem.common.ui.amountScreen.preview.AmountStatePreviewData import com.tangem.core.ui.event.consumedEvent import com.tangem.features.send.impl.presentation.state.SendUiState diff --git a/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/ui/SendNavigationButtons.kt b/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/ui/SendNavigationButtons.kt index f5247e516a..3e676181c9 100644 --- a/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/ui/SendNavigationButtons.kt +++ b/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/ui/SendNavigationButtons.kt @@ -16,14 +16,16 @@ import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.draw.clip import androidx.compose.ui.hapticfeedback.HapticFeedbackType -import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.platform.LocalHapticFeedback import androidx.compose.ui.res.painterResource import androidx.compose.ui.res.stringResource import androidx.compose.ui.text.style.TextAlign +import com.tangem.common.ui.amountScreen.models.AmountState +import com.tangem.common.ui.amountScreen.ui.SendDoneButtons +import com.tangem.common.ui.amountScreen.utils.getCryptoReference +import com.tangem.common.ui.amountScreen.utils.getFiatString import com.tangem.core.ui.R import com.tangem.core.ui.components.Keyboard -import com.tangem.core.ui.components.SecondaryButtonIconStart import com.tangem.core.ui.components.SpacerW12 import com.tangem.core.ui.components.buttons.common.TangemButton import com.tangem.core.ui.components.buttons.common.TangemButtonIconPosition @@ -32,12 +34,9 @@ import com.tangem.core.ui.components.keyboardAsState import com.tangem.core.ui.extensions.* import com.tangem.core.ui.res.TangemTheme import com.tangem.core.ui.utils.BigDecimalFormatter -import com.tangem.domain.tokens.model.Amount import com.tangem.features.send.impl.presentation.state.SendUiCurrentScreen import com.tangem.features.send.impl.presentation.state.SendUiState import com.tangem.features.send.impl.presentation.state.SendUiStateType -import com.tangem.features.send.impl.presentation.utils.getFiatString -import com.tangem.features.send.impl.presentation.utils.getCryptoReference @Composable internal fun SendNavigationButtons( @@ -166,7 +165,7 @@ private fun SendingText( exit = fadeOut(tween(durationMillis = 300)), label = "Animate show sending state text", ) { - val amountState = uiState.getAmountState(isEditState) + val amountState = uiState.getAmountState(isEditState) as? AmountState.Data val feeState = uiState.getFeeState(isEditState) val fiatRate = feeState?.rate val fiatAmount = amountState?.amountTextField?.fiatAmount @@ -220,46 +219,6 @@ private fun SendingText( } } -@Composable -private fun SendDoneButtons( - txUrl: String, - onExploreClick: () -> Unit, - onShareClick: () -> Unit, - isVisible: Boolean, - modifier: Modifier = Modifier, -) { - val hapticFeedback = LocalHapticFeedback.current - val context = LocalContext.current - - AnimatedVisibility( - visible = isVisible && txUrl.isNotBlank(), - modifier = modifier, - enter = slideInVertically().plus(fadeIn()), - exit = slideOutVertically().plus(fadeOut()), - label = "Animate show sent state buttons", - ) { - Row(modifier = Modifier.padding(bottom = TangemTheme.dimens.spacing12)) { - SecondaryButtonIconStart( - text = stringResource(id = R.string.common_explore), - iconResId = R.drawable.ic_web_24, - onClick = onExploreClick, - modifier = Modifier.weight(1f), - ) - SpacerW12() - SecondaryButtonIconStart( - text = stringResource(id = R.string.common_share), - iconResId = R.drawable.ic_share_24, - onClick = { - hapticFeedback.performHapticFeedback(HapticFeedbackType.LongPress) - context.shareText(txUrl) - onShareClick() - }, - modifier = Modifier.weight(1f), - ) - } - } -} - private fun getButtonData( uiState: SendUiState, currentState: SendUiCurrentScreen, diff --git a/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/ui/SendScreen.kt b/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/ui/SendScreen.kt index cdef0b59c6..992da60b9f 100644 --- a/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/ui/SendScreen.kt +++ b/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/ui/SendScreen.kt @@ -16,6 +16,8 @@ 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.PreviewParameterProvider +import com.tangem.common.ui.amountScreen.AmountScreenContent +import com.tangem.common.ui.amountScreen.models.AmountState import com.tangem.core.ui.components.appbar.AppBarWithBackButtonAndIcon import com.tangem.core.ui.extensions.resolveReference import com.tangem.core.ui.extensions.resourceReference @@ -28,7 +30,6 @@ import com.tangem.features.send.impl.presentation.state.SendUiState import com.tangem.features.send.impl.presentation.state.SendUiStateType import com.tangem.features.send.impl.presentation.state.previewdata.ConfirmStatePreviewData import com.tangem.features.send.impl.presentation.state.previewdata.SendStatesPreviewData -import com.tangem.features.send.impl.presentation.ui.amount.SendAmountContent import com.tangem.features.send.impl.presentation.ui.fee.SendSpeedAndFeeContent import com.tangem.features.send.impl.presentation.ui.recipient.SendRecipientContent import com.tangem.features.send.impl.presentation.ui.send.SendContent @@ -46,10 +47,10 @@ internal fun SendScreen(uiState: SendUiState, currentState: SendUiCurrentScreen) BackHandler(onBack = onBackClick) Column( modifier = Modifier + .background(color = TangemTheme.colors.background.tertiary) .fillMaxSize() .imePadding() - .systemBarsPadding() - .background(color = TangemTheme.colors.background.tertiary), + .systemBarsPadding(), horizontalAlignment = Alignment.CenterHorizontally, ) { SendAppBar( @@ -87,7 +88,7 @@ private fun SendAppBar(uiState: SendUiState, currentState: SendUiCurrentScreen) -> resourceReference(R.string.common_fee_selector_title) to null SendUiStateType.Send -> if (uiState.sendState?.isSuccess == false) { resourceReference(R.string.send_summary_title, wrappedList(uiState.cryptoCurrencyName)) to - uiState.amountState?.walletName + (uiState.amountState as? AmountState.Data)?.walletName } else { null to null } @@ -160,13 +161,13 @@ private fun SendScreenContent(uiState: SendUiState, currentState: SendUiCurrentS isTransitionAnimationRunning = transition.targetState != transition.currentState when (state.type) { - SendUiStateType.Amount -> SendAmountContent( + SendUiStateType.Amount -> AmountScreenContent( amountState = uiState.amountState, isBalanceHiding = uiState.isBalanceHidden, clickIntents = uiState.clickIntents, ) - SendUiStateType.EditAmount -> SendAmountContent( - amountState = uiState.editAmountState, + SendUiStateType.EditAmount -> AmountScreenContent( + amountState = uiState.editAmountState!!, isBalanceHiding = uiState.isBalanceHidden, clickIntents = uiState.clickIntents, ) diff --git a/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/ui/fee/SendCustomFee.kt b/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/ui/fee/SendCustomFee.kt index 1c7e332844..1af5a5154a 100644 --- a/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/ui/fee/SendCustomFee.kt +++ b/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/ui/fee/SendCustomFee.kt @@ -13,7 +13,7 @@ import com.tangem.core.ui.extensions.resolveReference import com.tangem.core.ui.res.TangemTheme import com.tangem.features.send.impl.presentation.state.fee.FeeType import com.tangem.features.send.impl.presentation.state.fields.SendTextField -import com.tangem.features.send.impl.presentation.ui.common.FooterContainer +import com.tangem.core.ui.components.containers.FooterContainer import kotlinx.collections.immutable.ImmutableList @Composable diff --git a/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/ui/fee/SendSpeedSelector.kt b/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/ui/fee/SendSpeedSelector.kt index f403cf423b..096fbe1d8b 100644 --- a/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/ui/fee/SendSpeedSelector.kt +++ b/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/ui/fee/SendSpeedSelector.kt @@ -63,7 +63,7 @@ internal fun SendSpeedSelector( onSelect = { clickIntents.onFeeSelectorClick(FeeType.Fast) }, ) SendSpeedSelectorItem( - titleRes = R.string.common_fee_selector_option_custom, + titleRes = R.string.common_custom, iconRes = R.drawable.ic_edit_24, feeType = FeeType.Custom, state = state, diff --git a/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/ui/fee/SendSpeedSelectorItem.kt b/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/ui/fee/SendSpeedSelectorItem.kt index ed1ad443a4..f7aacce75a 100644 --- a/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/ui/fee/SendSpeedSelectorItem.kt +++ b/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/ui/fee/SendSpeedSelectorItem.kt @@ -11,6 +11,8 @@ import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import com.tangem.blockchain.common.Amount import com.tangem.blockchain.common.transaction.TransactionFee +import com.tangem.common.ui.amountScreen.utils.getCryptoReference +import com.tangem.common.ui.amountScreen.utils.getFiatReference import com.tangem.core.ui.components.RectangleShimmer import com.tangem.core.ui.components.SpacerWMax import com.tangem.core.ui.components.rows.SelectorRowItem @@ -20,8 +22,6 @@ import com.tangem.core.ui.utils.parseToBigDecimal import com.tangem.features.send.impl.presentation.state.SendStates import com.tangem.features.send.impl.presentation.state.fee.FeeSelectorState import com.tangem.features.send.impl.presentation.state.fee.FeeType -import com.tangem.features.send.impl.presentation.utils.getCryptoReference -import com.tangem.features.send.impl.presentation.utils.getFiatReference @Composable internal fun SendSpeedSelectorItem( @@ -36,9 +36,8 @@ internal fun SendSpeedSelectorItem( val content = feeSelectorState as? FeeSelectorState.Content val amount = content?.getAmount(feeType) val (showDivider, isVisible) = content.getDividerAndVisibility(feeType) - val hasCustomValues = !content?.customValues.isNullOrEmpty() AnimatedVisibility( - visible = isVisible || hasCustomValues, + visible = isVisible, label = "Fee Selector Visibility Animation", enter = expandVertically().plus(fadeIn()), exit = shrinkVertically().plus(fadeOut()), @@ -99,7 +98,7 @@ private fun FeeError(feeSelectorState: FeeSelectorState) { Row { SpacerWMax() AnimatedVisibility( - visible = feeSelectorState == FeeSelectorState.Error, + visible = feeSelectorState is FeeSelectorState.Error, label = "Fee Error State Change", modifier = Modifier.align(Alignment.CenterVertically), ) { @@ -135,7 +134,7 @@ private fun FeeSelectorState.Content?.getDividerAndVisibility(feeType: FeeType): val isNotSingle = this?.fees !is TransactionFee.Single return when (feeType) { FeeType.Slow -> true to isNotSingle - FeeType.Market -> isNotSingle to true + FeeType.Market -> (isNotSingle || hasCustomValues) to true FeeType.Fast -> hasCustomValues to isNotSingle FeeType.Custom -> false to hasCustomValues } diff --git a/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/ui/recipient/SendRecipientContent.kt b/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/ui/recipient/SendRecipientContent.kt index b3402a2bbe..cf63542cee 100644 --- a/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/ui/recipient/SendRecipientContent.kt +++ b/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/ui/recipient/SendRecipientContent.kt @@ -21,7 +21,6 @@ import androidx.compose.ui.res.stringResource import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.tooling.preview.PreviewParameter import androidx.compose.ui.tooling.preview.PreviewParameterProvider -import com.tangem.common.Strings.STARS import com.tangem.core.ui.components.inputrow.InputRowRecipient import com.tangem.core.ui.extensions.resolveReference import com.tangem.core.ui.res.TangemTheme @@ -33,8 +32,9 @@ import com.tangem.features.send.impl.presentation.state.SendStates import com.tangem.features.send.impl.presentation.state.fields.SendTextField import com.tangem.features.send.impl.presentation.state.previewdata.RecipientStatePreviewData import com.tangem.features.send.impl.presentation.state.previewdata.SendClickIntentsStub -import com.tangem.features.send.impl.presentation.ui.common.FooterContainer +import com.tangem.core.ui.components.containers.FooterContainer import com.tangem.features.send.impl.presentation.viewmodel.SendClickIntents +import com.tangem.utils.StringsSigns.STARS import kotlinx.collections.immutable.ImmutableList private const val ADDRESS_FIELD_KEY = "ADDRESS_FIELD_KEY" diff --git a/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/ui/recipient/TextFieldWithPaste.kt b/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/ui/recipient/TextFieldWithPaste.kt index e11b62e872..762dc7f7eb 100644 --- a/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/ui/recipient/TextFieldWithPaste.kt +++ b/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/ui/recipient/TextFieldWithPaste.kt @@ -17,7 +17,7 @@ import com.tangem.core.ui.components.inputrow.inner.PasteButton import com.tangem.core.ui.extensions.TextReference import com.tangem.core.ui.extensions.resolveReference import com.tangem.core.ui.res.TangemTheme -import com.tangem.features.send.impl.presentation.ui.common.FooterContainer +import com.tangem.core.ui.components.containers.FooterContainer @Composable internal fun TextFieldWithPaste( diff --git a/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/ui/send/FeeBlock.kt b/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/ui/send/FeeBlock.kt index f2dcd33987..0339ddc783 100644 --- a/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/ui/send/FeeBlock.kt +++ b/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/ui/send/FeeBlock.kt @@ -14,6 +14,8 @@ import androidx.compose.ui.res.stringResource import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.tooling.preview.PreviewParameter import androidx.compose.ui.tooling.preview.PreviewParameterProvider +import com.tangem.common.ui.amountScreen.utils.getCryptoReference +import com.tangem.common.ui.amountScreen.utils.getFiatReference import com.tangem.core.ui.components.RectangleShimmer import com.tangem.core.ui.components.rows.SelectorRowItem import com.tangem.core.ui.res.TangemThemePreview @@ -24,8 +26,6 @@ import com.tangem.features.send.impl.presentation.state.SendStates import com.tangem.features.send.impl.presentation.state.fee.FeeSelectorState import com.tangem.features.send.impl.presentation.state.fee.FeeType import com.tangem.features.send.impl.presentation.state.previewdata.FeeStatePreviewData -import com.tangem.features.send.impl.presentation.utils.getCryptoReference -import com.tangem.features.send.impl.presentation.utils.getFiatReference @Composable internal fun FeeBlock(feeState: SendStates.FeeState, isClickDisabled: Boolean, onClick: () -> Unit) { @@ -53,7 +53,7 @@ internal fun FeeBlock(feeState: SendStates.FeeState, isClickDisabled: Boolean, o FeeType.Slow -> R.string.common_fee_selector_option_slow to R.drawable.ic_tortoise_24 FeeType.Market -> R.string.common_fee_selector_option_market to R.drawable.ic_bird_24 FeeType.Fast -> R.string.common_fee_selector_option_fast to R.drawable.ic_hare_24 - FeeType.Custom -> R.string.common_fee_selector_option_custom to R.drawable.ic_edit_24 + FeeType.Custom -> R.string.common_custom to R.drawable.ic_edit_24 } } else { R.string.common_fee_selector_option_market to R.drawable.ic_bird_24 @@ -105,7 +105,7 @@ private fun BoxScope.FeeError(feeSelectorState: FeeSelectorState) { label = "Fee Error State Change", modifier = Modifier.align(Alignment.CenterEnd), ) { - if (it == FeeSelectorState.Error) { + if (it is FeeSelectorState.Error) { Text( text = BigDecimalFormatter.EMPTY_BALANCE_SIGN, color = TangemTheme.colors.text.primary1, diff --git a/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/ui/send/SendContent.kt b/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/ui/send/SendContent.kt index 0f6304ae81..2576d7b37f 100644 --- a/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/ui/send/SendContent.kt +++ b/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/ui/send/SendContent.kt @@ -24,6 +24,7 @@ import androidx.compose.ui.res.stringResource import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.tooling.preview.PreviewParameter import androidx.compose.ui.tooling.preview.PreviewParameterProvider +import com.tangem.common.ui.amountScreen.ui.AmountBlock import com.tangem.core.ui.components.transactions.TransactionDoneTitle import com.tangem.core.ui.res.TangemTheme import com.tangem.core.ui.res.TangemThemePreview @@ -53,7 +54,7 @@ internal fun SendContent(uiState: SendUiState) { } private fun LazyListScope.blocks(uiState: SendUiState) { - val amountState = uiState.amountState ?: return + val amountState = uiState.amountState val recipientState = uiState.recipientState ?: return val feeState = uiState.feeState ?: return val sendState = uiState.sendState ?: return diff --git a/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/viewmodel/SendClickIntents.kt b/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/viewmodel/SendClickIntents.kt index 457de01af1..b7bc64d493 100644 --- a/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/viewmodel/SendClickIntents.kt +++ b/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/viewmodel/SendClickIntents.kt @@ -1,5 +1,6 @@ package com.tangem.features.send.impl.presentation.viewmodel +import com.tangem.common.ui.amountScreen.AmountScreenClickIntents import com.tangem.domain.tokens.model.CryptoCurrency import com.tangem.domain.wallets.models.UserWalletId import com.tangem.features.send.impl.presentation.analytics.EnterAddressSource @@ -8,7 +9,7 @@ import com.tangem.features.send.impl.presentation.state.fee.FeeType import java.math.BigDecimal @Suppress("TooManyFunctions") -internal interface SendClickIntents { +internal interface SendClickIntents : AmountScreenClickIntents { fun popBackStack() @@ -26,16 +27,6 @@ internal interface SendClickIntents { fun onTokenDetailsClick(userWalletId: UserWalletId, currency: CryptoCurrency) - // region Amount - fun onAmountValueChange(value: String) - - fun onCurrencyChangeClick(isFiat: Boolean) - - fun onMaxValueClick() - - fun onAmountPasteTriggerDismiss() - // endregion - // region Recipient fun onRecipientAddressValueChange(value: String, type: EnterAddressSource? = null) diff --git a/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/viewmodel/SendViewModel.kt b/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/viewmodel/SendViewModel.kt index 622ca294c5..a57a241ebf 100644 --- a/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/viewmodel/SendViewModel.kt +++ b/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/viewmodel/SendViewModel.kt @@ -1,5 +1,6 @@ package com.tangem.features.send.impl.presentation.viewmodel +import android.os.Bundle import android.os.SystemClock import androidx.lifecycle.* import arrow.core.Either @@ -7,6 +8,9 @@ import arrow.core.getOrElse import arrow.core.left import com.tangem.blockchain.common.TransactionData import com.tangem.blockchain.common.transaction.TransactionFee +import com.tangem.common.routing.AppRoute +import com.tangem.common.routing.bundle.unbundle +import com.tangem.common.ui.amountScreen.models.AmountState import com.tangem.core.analytics.api.AnalyticsEventHandler import com.tangem.core.ui.utils.parseBigDecimal import com.tangem.domain.appcurrency.GetSelectedAppCurrencyUseCase @@ -35,13 +39,13 @@ import com.tangem.domain.wallets.models.UserWallet import com.tangem.domain.wallets.models.UserWalletId import com.tangem.domain.wallets.usecase.GetUserWalletUseCase import com.tangem.domain.wallets.usecase.GetWalletsUseCase -import com.tangem.features.send.api.navigation.SendRouter import com.tangem.features.send.impl.navigation.InnerSendRouter import com.tangem.features.send.impl.presentation.analytics.EnterAddressSource import com.tangem.features.send.impl.presentation.analytics.SendAnalyticEvents import com.tangem.features.send.impl.presentation.analytics.SendScreenSource import com.tangem.features.send.impl.presentation.analytics.utils.SendScreenAnalyticSender import com.tangem.features.send.impl.presentation.domain.AvailableWallet +import com.tangem.features.send.impl.presentation.errors.FeeErrorStateMapper import com.tangem.features.send.impl.presentation.state.* import com.tangem.features.send.impl.presentation.state.amount.AmountStateFactory import com.tangem.features.send.impl.presentation.state.confirm.SendNotificationFactory @@ -66,7 +70,6 @@ internal class SendViewModel @Inject constructor( private val dispatchers: CoroutineDispatcherProvider, private val getUserWalletUseCase: GetUserWalletUseCase, private val getCryptoCurrencyStatusSyncUseCase: GetCryptoCurrencyStatusSyncUseCase, - private val getNetworkCoinStatusUseCase: GetNetworkCoinStatusUseCase, private val getSelectedAppCurrencyUseCase: GetSelectedAppCurrencyUseCase, private val getWalletsUseCase: GetWalletsUseCase, private val getFeePaidCryptoCurrencyStatusSyncUseCase: GetFeePaidCryptoCurrencyStatusSyncUseCase, @@ -99,17 +102,18 @@ internal class SendViewModel @Inject constructor( savedStateHandle: SavedStateHandle, ) : ViewModel(), DefaultLifecycleObserver, SendClickIntents { - private val userWalletId: UserWalletId = savedStateHandle.get(SendRouter.USER_WALLET_ID_KEY) - ?.let { stringValue -> UserWalletId(stringValue) } + private val userWalletId: UserWalletId = savedStateHandle.get(AppRoute.Send.USER_WALLET_ID_KEY) + ?.unbundle(UserWalletId.serializer()) ?: error("This screen can't open without `UserWalletId`") - private val cryptoCurrency: CryptoCurrency = savedStateHandle[SendRouter.CRYPTO_CURRENCY_KEY] + private val cryptoCurrency: CryptoCurrency = savedStateHandle.get(AppRoute.Send.CRYPTO_CURRENCY_KEY) + ?.unbundle(CryptoCurrency.serializer()) ?: error("This screen can't open without `CryptoCurrency`") - private val transactionId: String? = savedStateHandle[SendRouter.TRANSACTION_ID_KEY] - private val amount: String? = savedStateHandle[SendRouter.AMOUNT_KEY] - private val destinationAddress: String? = savedStateHandle[SendRouter.DESTINATION_ADDRESS_KEY] - private val memo: String? = savedStateHandle[SendRouter.TAG_KEY] + private val transactionId: String? = savedStateHandle[AppRoute.Send.TRANSACTION_ID_KEY] + private val amount: String? = savedStateHandle[AppRoute.Send.AMOUNT_KEY] + private val destinationAddress: String? = savedStateHandle[AppRoute.Send.DESTINATION_ADDRESS_KEY] + private val memo: String? = savedStateHandle[AppRoute.Send.TAG_KEY] private val selectedAppCurrencyFlow: StateFlow = createSelectedAppCurrencyFlow() @@ -117,6 +121,8 @@ internal class SendViewModel @Inject constructor( var stateRouter: StateRouter by Delegates.notNull() private set + private val feeErrorHandler = FeeErrorStateMapper() + private val stateFactory = SendStateFactory( clickIntents = this, stateRouterProvider = Provider { stateRouter }, @@ -167,7 +173,7 @@ internal class SendViewModel @Inject constructor( private val sendNotificationFactory = SendNotificationFactory( cryptoCurrencyStatusProvider = Provider { cryptoCurrencyStatus }, - coinCryptoCurrencyStatusProvider = Provider { coinCryptoCurrencyStatus }, + feeCryptoCurrencyStatusProvider = Provider { feeCryptoCurrencyStatus }, currentStateProvider = Provider { uiState.value }, userWalletProvider = Provider { userWallet }, stateRouterProvider = Provider { stateRouter }, @@ -199,7 +205,6 @@ internal class SendViewModel @Inject constructor( private var isAmountSubtractAvailable: Boolean = false private var isUtxoConsolidationAvailable: Boolean = false private var isTapHelpPreviewEnabled: Boolean = false - private var coinCryptoCurrencyStatus: CryptoCurrencyStatus by Delegates.notNull() private var cryptoCurrencyStatus: CryptoCurrencyStatus by Delegates.notNull() private var feeCryptoCurrencyStatus: CryptoCurrencyStatus? = null @@ -277,33 +282,18 @@ internal class SendViewModel @Inject constructor( } private suspend fun getCurrenciesStatusUpdates(isSingleWalletWithToken: Boolean, isMultiCurrency: Boolean) { - val maybeCurrencyStatus = getCurrencyStatus( + getCurrencyStatus( isSingleWalletWithToken = isSingleWalletWithToken, isMultiCurrency = isMultiCurrency, + ).fold( + ifRight = { cryptoCurrencyStatus -> + onDataLoaded( + currencyStatus = cryptoCurrencyStatus, + feeCurrencyStatus = getFeeCurrencyStatusSync(cryptoCurrencyStatus, isMultiCurrency), + ) + }, + ifLeft = { showErrorAlert() }, ) - val maybeCoinStatus = if (cryptoCurrency is CryptoCurrency.Coin) { - maybeCurrencyStatus - } else { - getCoinCurrencyStatusUpdates(isSingleWalletWithToken) - } - - if (maybeCoinStatus.isRight() && maybeCurrencyStatus.isRight()) { - val currencyStatus = maybeCurrencyStatus.getOrElse { - showErrorAlert() - return Timber.e("Currency status is unreachable") - } - val coinStatus = maybeCoinStatus.getOrElse { - showErrorAlert() - return Timber.e("Coin status is unreachable") - } - onDataLoaded( - currencyStatus = currencyStatus, - coinCurrencyStatus = coinStatus, - feeCurrencyStatus = getFeeCurrencyStatusSync(currencyStatus, isMultiCurrency), - ) - } else { - showErrorAlert() - } } private fun getTapHelpPreviewAvailability() { @@ -312,14 +302,6 @@ internal class SendViewModel @Inject constructor( } } - private suspend fun getCoinCurrencyStatusUpdates(isSingleWalletWithToken: Boolean) = getNetworkCoinStatusUseCase - .invokeSync( - userWalletId = userWalletId, - networkId = cryptoCurrency.network.id, - derivationPath = cryptoCurrency.network.derivationPath, - isSingleWalletWithTokens = isSingleWalletWithToken, - ) - private suspend fun getCurrencyStatus( isSingleWalletWithToken: Boolean, isMultiCurrency: Boolean, @@ -361,13 +343,8 @@ internal class SendViewModel @Inject constructor( ) } - private fun onDataLoaded( - currencyStatus: CryptoCurrencyStatus, - coinCurrencyStatus: CryptoCurrencyStatus, - feeCurrencyStatus: CryptoCurrencyStatus?, - ) { + private fun onDataLoaded(currencyStatus: CryptoCurrencyStatus, feeCurrencyStatus: CryptoCurrencyStatus?) { cryptoCurrencyStatus = currencyStatus - coinCryptoCurrencyStatus = coinCurrencyStatus feeCryptoCurrencyStatus = feeCurrencyStatus subscribeOnQRScannerResult() when { @@ -518,6 +495,8 @@ internal class SendViewModel @Inject constructor( stateRouter.onNextClick() } + override fun onAmountNext() = onNextClick(stateRouter.isEditState) + override fun onPrevClick() { cancelFeeRequest() stateRouter.onPrevClick() @@ -531,7 +510,7 @@ internal class SendViewModel @Inject constructor( override fun onFailedTxEmailClick(errorMessage: String) { val recipient = uiState.value.recipientState?.addressTextField?.value val feeValue = uiState.value.feeState?.fee?.amount?.value - val amountValue = uiState.value.amountState?.amountTextField?.cryptoAmount?.value + val amountValue = (uiState.value.amountState as? AmountState.Data)?.amountTextField?.cryptoAmount?.value val receivingAmount = if (amountValue != null && feeValue != null) { checkAndCalculateSubtractedAmount( @@ -552,6 +531,7 @@ internal class SendViewModel @Inject constructor( fee = feeValue, destinationAddress = recipient, errorMessage = errorMessage, + scanResponse = userWallet.scanResponse, ), ) } @@ -734,20 +714,24 @@ internal class SendViewModel @Inject constructor( uiState.value = feeStateFactory.onFeeOnLoadedState(it) sendIdleTimer = SystemClock.elapsedRealtime() }, - ifLeft = { - onFeeLoadFailed(isShowStatus) + ifLeft = { loadFeeError -> + onFeeLoadFailed(isShowStatus, loadFeeError) }, ) if (result == null) { - onFeeLoadFailed(isShowStatus) + onFeeLoadFailed(isShowStatus, null) } updateNotifications() updateFeeNotifications() }.saveIn(feeJobHolder) } - private fun onFeeLoadFailed(isShowStatus: Boolean) { - if (isShowStatus) uiState.value = feeStateFactory.onFeeOnErrorState() + private fun onFeeLoadFailed(isShowStatus: Boolean, loadFeeError: GetFeeError?) { + if (isShowStatus) { + uiState.value = feeStateFactory.onFeeOnErrorState( + feeErrorHandler.getFeeError(loadFeeError, cryptoCurrency.name), + ) + } } private suspend fun checkIfSubtractAvailable() { @@ -766,7 +750,7 @@ internal class SendViewModel @Inject constructor( private suspend fun callFeeUseCase(): Either? { val isFromConfirmation = stateRouter.currentState.value.isFromConfirmation - val amountState = uiState.value.getAmountState(isFromConfirmation) ?: return null + val amountState = uiState.value.getAmountState(isFromConfirmation) as? AmountState.Data ?: return null val recipientState = uiState.value.getRecipientState(isFromConfirmation) ?: return null val amount = amountState.amountTextField.cryptoAmount.value ?: return null @@ -857,7 +841,9 @@ internal class SendViewModel @Inject constructor( val feeState = uiState.value.feeState ?: return val fee = feeState.fee ?: return val memo = uiState.value.recipientState?.memoTextField?.value - val amountValue = uiState.value.amountState?.amountTextField?.cryptoAmount?.value ?: return + val amountValue = (uiState.value.amountState as? AmountState.Data) + ?.amountTextField?.cryptoAmount?.value + ?: return val feeValue = fee.amount.value ?: return val receivingAmount = checkAndCalculateSubtractedAmount( @@ -892,7 +878,7 @@ internal class SendViewModel @Inject constructor( } } - private suspend fun sendTransaction(txData: TransactionData) { + private suspend fun sendTransaction(txData: TransactionData.Uncompiled) { val result = sendTransactionUseCase( txData = txData, userWallet = userWallet, @@ -935,7 +921,7 @@ internal class SendViewModel @Inject constructor( } } - private suspend fun updateTransactionStatus(txData: TransactionData) { + private suspend fun updateTransactionStatus(txData: TransactionData.Uncompiled) { val txUrl = getExplorerTransactionUrlUseCase( userWalletId = userWalletId, network = cryptoCurrency.network, diff --git a/features/staking/impl/build.gradle.kts b/features/staking/impl/build.gradle.kts index ac2ce74301..15213f79d6 100644 --- a/features/staking/impl/build.gradle.kts +++ b/features/staking/impl/build.gradle.kts @@ -47,8 +47,25 @@ dependencies { implementation(projects.core.analytics) implementation(projects.core.analytics.models) + + /** Domain */ + implementation(projects.domain.tokens) + implementation(projects.domain.tokens.models) + implementation(projects.domain.wallets) + implementation(projects.domain.wallets.models) + implementation(projects.domain.staking) + implementation(projects.domain.balanceHiding) + implementation(projects.domain.balanceHiding.models) + implementation(projects.domain.appCurrency) + implementation(projects.domain.appCurrency.models) + implementation(projects.domain.legacy) + implementation(projects.domain.models) + implementation(projects.domain.transaction) + implementation(projects.domain.txhistory) + /** Common */ - implementation(projects.common) + implementation(projects.common.ui) + implementation(projects.common.routing) /** Libs */ implementation(projects.libs.crypto) diff --git a/features/staking/impl/src/main/java/com/tangem/features/staking/impl/di/StakingRouterModule.kt b/features/staking/impl/src/main/java/com/tangem/features/staking/impl/di/StakingRouterModule.kt index c351d87a6e..c64b0dd4f2 100644 --- a/features/staking/impl/src/main/java/com/tangem/features/staking/impl/di/StakingRouterModule.kt +++ b/features/staking/impl/src/main/java/com/tangem/features/staking/impl/di/StakingRouterModule.kt @@ -1,5 +1,6 @@ package com.tangem.features.staking.impl.di +import com.tangem.core.navigation.url.UrlOpener import com.tangem.features.staking.impl.navigation.DefaultStakingRouter import com.tangem.features.staking.api.navigation.StakingRouter import dagger.Module @@ -17,7 +18,9 @@ internal object StakingRouterModule { @Provides @ActivityScoped - fun provideStakingRouter(): StakingRouter { - return DefaultStakingRouter() + fun provideStakingRouter(urlOpener: UrlOpener): StakingRouter { + return DefaultStakingRouter( + urlOpener = urlOpener, + ) } } \ No newline at end of file diff --git a/features/staking/impl/src/main/java/com/tangem/features/staking/impl/navigation/DefaultStakingRouter.kt b/features/staking/impl/src/main/java/com/tangem/features/staking/impl/navigation/DefaultStakingRouter.kt index 83cd830e4d..464d28694e 100644 --- a/features/staking/impl/src/main/java/com/tangem/features/staking/impl/navigation/DefaultStakingRouter.kt +++ b/features/staking/impl/src/main/java/com/tangem/features/staking/impl/navigation/DefaultStakingRouter.kt @@ -1,8 +1,15 @@ package com.tangem.features.staking.impl.navigation import androidx.fragment.app.Fragment +import com.tangem.core.navigation.url.UrlOpener +import com.tangem.features.staking.impl.presentation.StakingFragment -internal class DefaultStakingRouter : InnerStakingRouter { +internal class DefaultStakingRouter( + private val urlOpener: UrlOpener, +) : InnerStakingRouter { + override fun getEntryFragment(): Fragment = StakingFragment.create() - override fun getEntryFragment(): Fragment = TODO() + override fun openUrl(url: String) { + urlOpener.openUrl(url) + } } \ No newline at end of file diff --git a/features/staking/impl/src/main/java/com/tangem/features/staking/impl/navigation/InnerStakingRouter.kt b/features/staking/impl/src/main/java/com/tangem/features/staking/impl/navigation/InnerStakingRouter.kt index 7d7aa226d4..d4197489fb 100644 --- a/features/staking/impl/src/main/java/com/tangem/features/staking/impl/navigation/InnerStakingRouter.kt +++ b/features/staking/impl/src/main/java/com/tangem/features/staking/impl/navigation/InnerStakingRouter.kt @@ -2,4 +2,7 @@ package com.tangem.features.staking.impl.navigation import com.tangem.features.staking.api.navigation.StakingRouter -interface InnerStakingRouter : StakingRouter \ No newline at end of file +interface InnerStakingRouter : StakingRouter { + + fun openUrl(url: String) +} \ No newline at end of file diff --git a/features/staking/impl/src/main/java/com/tangem/features/staking/impl/presentation/StakingFragment.kt b/features/staking/impl/src/main/java/com/tangem/features/staking/impl/presentation/StakingFragment.kt new file mode 100644 index 0000000000..cb590bcb4c --- /dev/null +++ b/features/staking/impl/src/main/java/com/tangem/features/staking/impl/presentation/StakingFragment.kt @@ -0,0 +1,76 @@ +package com.tangem.features.staking.impl.presentation + +import android.os.Bundle +import androidx.compose.runtime.Composable +import androidx.compose.ui.Modifier +import androidx.fragment.app.viewModels +import androidx.lifecycle.compose.collectAsStateWithLifecycle +import com.tangem.common.routing.AppRouter +import com.tangem.core.analytics.api.AnalyticsEventHandler +import com.tangem.core.ui.UiDependencies +import com.tangem.core.ui.screen.ComposeFragment +import com.tangem.features.staking.api.navigation.StakingRouter +import com.tangem.features.staking.impl.navigation.InnerStakingRouter +import com.tangem.features.staking.impl.presentation.state.StakingStateController +import com.tangem.features.staking.impl.presentation.state.StakingStateRouter +import com.tangem.features.staking.impl.presentation.ui.StakingScreen +import com.tangem.features.staking.impl.presentation.viewmodel.StakingViewModel +import dagger.hilt.android.AndroidEntryPoint +import javax.inject.Inject + +/** + * Staking fragment + */ +@AndroidEntryPoint +internal class StakingFragment : ComposeFragment() { + + @Inject + override lateinit var uiDependencies: UiDependencies + + @Inject + lateinit var stakingRouter: StakingRouter + + @Inject + lateinit var appRouter: AppRouter + + @Inject + lateinit var stateController: StakingStateController + + @Inject + lateinit var analyticsEventsHandler: AnalyticsEventHandler + + private val viewModel by viewModels() + private val innerStakingRouter: InnerStakingRouter + get() = requireNotNull(stakingRouter as? InnerStakingRouter) { + "innerStakingRouter should be instance of InnerStakingRouter" + } + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + lifecycle.addObserver(viewModel) + + viewModel.setRouter( + innerStakingRouter, + StakingStateRouter( + appRouter = appRouter, + stateController = stateController, + ), + ) + } + + @Composable + override fun ScreenContent(modifier: Modifier) { + val currentState = viewModel.uiState.collectAsStateWithLifecycle() + StakingScreen(currentState.value) + } + + override fun onDestroy() { + lifecycle.removeObserver(viewModel) + super.onDestroy() + } + + companion object { + /** Create staking fragment instance */ + fun create(): StakingFragment = StakingFragment() + } +} \ No newline at end of file diff --git a/features/staking/impl/src/main/java/com/tangem/features/staking/impl/presentation/state/FeeState.kt b/features/staking/impl/src/main/java/com/tangem/features/staking/impl/presentation/state/FeeState.kt new file mode 100644 index 0000000000..c58332a870 --- /dev/null +++ b/features/staking/impl/src/main/java/com/tangem/features/staking/impl/presentation/state/FeeState.kt @@ -0,0 +1,20 @@ +package com.tangem.features.staking.impl.presentation.state + +import com.tangem.blockchain.common.transaction.Fee +import com.tangem.domain.appcurrency.model.AppCurrency +import java.math.BigDecimal + +sealed class FeeState { + + data class Content( + val fee: Fee?, + val rate: BigDecimal?, + val isFeeConvertibleToFiat: Boolean, + val appCurrency: AppCurrency, + val isFeeApproximate: Boolean, + ) : FeeState() + + data object Loading : FeeState() + + data object Error : FeeState() +} \ No newline at end of file diff --git a/features/staking/impl/src/main/java/com/tangem/features/staking/impl/presentation/state/InnerConfirmationStakingState.kt b/features/staking/impl/src/main/java/com/tangem/features/staking/impl/presentation/state/InnerConfirmationStakingState.kt new file mode 100644 index 0000000000..babc93a2dd --- /dev/null +++ b/features/staking/impl/src/main/java/com/tangem/features/staking/impl/presentation/state/InnerConfirmationStakingState.kt @@ -0,0 +1,7 @@ +package com.tangem.features.staking.impl.presentation.state + +enum class InnerConfirmationStakingState { + ASSENT, + IN_PROGRESS, + COMPLETED, +} \ No newline at end of file diff --git a/features/staking/impl/src/main/java/com/tangem/features/staking/impl/presentation/state/InnerFeeState.kt b/features/staking/impl/src/main/java/com/tangem/features/staking/impl/presentation/state/InnerFeeState.kt new file mode 100644 index 0000000000..7a0acf09f9 --- /dev/null +++ b/features/staking/impl/src/main/java/com/tangem/features/staking/impl/presentation/state/InnerFeeState.kt @@ -0,0 +1,14 @@ +package com.tangem.features.staking.impl.presentation.state + +import com.tangem.blockchain.common.transaction.TransactionFee + +internal sealed class InnerFeeState { + + data class Content( + val fees: TransactionFee, + ) : InnerFeeState() + + data object Loading : InnerFeeState() + + data object Error : InnerFeeState() +} \ No newline at end of file diff --git a/features/staking/impl/src/main/java/com/tangem/features/staking/impl/presentation/state/InnerYieldBalanceState.kt b/features/staking/impl/src/main/java/com/tangem/features/staking/impl/presentation/state/InnerYieldBalanceState.kt new file mode 100644 index 0000000000..dcea12e0ed --- /dev/null +++ b/features/staking/impl/src/main/java/com/tangem/features/staking/impl/presentation/state/InnerYieldBalanceState.kt @@ -0,0 +1,42 @@ +package com.tangem.features.staking.impl.presentation.state + +import com.tangem.core.ui.extensions.TextReference +import com.tangem.domain.staking.model.stakekit.PendingAction +import com.tangem.domain.staking.model.stakekit.Yield +import kotlinx.collections.immutable.ImmutableList +import java.math.BigDecimal + +sealed class InnerYieldBalanceState { + data class Data( + val rewardsCrypto: String, + val rewardsFiat: String, + val isRewardsToClaim: Boolean, + val balance: List, + ) : InnerYieldBalanceState() + + data object Empty : InnerYieldBalanceState() +} + +data class BalanceGroupedState( + val items: ImmutableList, + val footer: TextReference?, + val title: TextReference, + val type: BalanceGroupType, +) + +data class BalanceState( + val validator: Yield.Validator, + val cryptoValue: String, + val cryptoDecimal: BigDecimal, + val cryptoAmount: TextReference, + val fiatAmount: TextReference, + val rawCurrencyId: String?, + val unbondingPeriod: TextReference, + val pendingActions: ImmutableList, +) + +enum class BalanceGroupType { + ACTIVE, + UNSTAKED, + UNKNOWN, +} \ No newline at end of file diff --git a/features/staking/impl/src/main/java/com/tangem/features/staking/impl/presentation/state/StakingAlertState.kt b/features/staking/impl/src/main/java/com/tangem/features/staking/impl/presentation/state/StakingAlertState.kt new file mode 100644 index 0000000000..c133fe00ca --- /dev/null +++ b/features/staking/impl/src/main/java/com/tangem/features/staking/impl/presentation/state/StakingAlertState.kt @@ -0,0 +1,24 @@ +package com.tangem.features.staking.impl.presentation.state + +import androidx.compose.runtime.Immutable +import com.tangem.core.ui.extensions.TextReference +import com.tangem.core.ui.extensions.resourceReference +import com.tangem.features.staking.impl.R + +@Immutable +internal sealed class StakingAlertState { + + abstract val title: TextReference? + abstract val message: TextReference + open val confirmButtonText: TextReference = resourceReference(id = R.string.common_ok) + open val onConfirmClick: (() -> Unit)? = null + + data class GenericError( + override val title: TextReference? = TODO(), + override val onConfirmClick: () -> Unit, + ) : StakingAlertState() { + override val message: TextReference = resourceReference(R.string.common_unknown_error) + override val confirmButtonText: TextReference = + resourceReference(id = R.string.common_support) + } +} \ No newline at end of file diff --git a/features/staking/impl/src/main/java/com/tangem/features/staking/impl/presentation/state/StakingEvent.kt b/features/staking/impl/src/main/java/com/tangem/features/staking/impl/presentation/state/StakingEvent.kt new file mode 100644 index 0000000000..dbc800ea01 --- /dev/null +++ b/features/staking/impl/src/main/java/com/tangem/features/staking/impl/presentation/state/StakingEvent.kt @@ -0,0 +1,12 @@ +package com.tangem.features.staking.impl.presentation.state + +import androidx.compose.runtime.Immutable +import com.tangem.core.ui.extensions.TextReference + +@Immutable +internal sealed class StakingEvent { + + data class ShowSnackBar(val text: TextReference) : StakingEvent() + + data class ShowAlert(val alert: StakingAlertState) : StakingEvent() +} \ No newline at end of file diff --git a/features/staking/impl/src/main/java/com/tangem/features/staking/impl/presentation/state/StakingNotification.kt b/features/staking/impl/src/main/java/com/tangem/features/staking/impl/presentation/state/StakingNotification.kt new file mode 100644 index 0000000000..967f681edb --- /dev/null +++ b/features/staking/impl/src/main/java/com/tangem/features/staking/impl/presentation/state/StakingNotification.kt @@ -0,0 +1,54 @@ +package com.tangem.features.staking.impl.presentation.state + +import com.tangem.core.ui.components.notifications.NotificationConfig +import com.tangem.core.ui.extensions.TextReference +import com.tangem.core.ui.extensions.resourceReference +import com.tangem.core.ui.extensions.wrappedList +import com.tangem.features.staking.impl.R + +internal sealed class StakingNotification(val config: NotificationConfig) { + + sealed class Error( + title: TextReference, + subtitle: TextReference, + iconResId: Int = R.drawable.ic_alert_24, + buttonState: NotificationConfig.ButtonsState? = null, + onCloseClick: (() -> Unit)? = null, + ) : StakingNotification( + config = NotificationConfig( + title = title, + subtitle = subtitle, + iconResId = iconResId, + buttonsState = buttonState, + onCloseClick = onCloseClick, + ), + ) { + // TODO staking + } + + sealed class Warning( + title: TextReference, + subtitle: TextReference, + buttonsState: NotificationConfig.ButtonsState? = null, + onCloseClick: (() -> Unit)? = null, + ) : StakingNotification( + config = NotificationConfig( + title = title, + subtitle = subtitle, + iconResId = R.drawable.ic_alert_circle_24, + buttonsState = buttonsState, + onCloseClick = onCloseClick, + ), + ) { + data class EarnRewards( + val currencyName: String, + val days: Int, + ) : Warning( + title = resourceReference(R.string.staking_notification_earn_rewards_title), + subtitle = resourceReference( + R.string.staking_notification_earn_rewards_text, + wrappedList(currencyName, days), + ), + ) + } +} \ No newline at end of file diff --git a/features/staking/impl/src/main/java/com/tangem/features/staking/impl/presentation/state/StakingStateController.kt b/features/staking/impl/src/main/java/com/tangem/features/staking/impl/presentation/state/StakingStateController.kt new file mode 100644 index 0000000000..d3570e6c23 --- /dev/null +++ b/features/staking/impl/src/main/java/com/tangem/features/staking/impl/presentation/state/StakingStateController.kt @@ -0,0 +1,50 @@ +package com.tangem.features.staking.impl.presentation.state + +import com.tangem.common.ui.amountScreen.models.AmountState +import com.tangem.core.ui.event.consumedEvent +import com.tangem.features.staking.impl.presentation.state.stub.StakingClickIntentsStub +import com.tangem.utils.transformer.Transformer +import kotlinx.coroutines.flow.MutableStateFlow +import kotlinx.coroutines.flow.StateFlow +import kotlinx.coroutines.flow.asStateFlow +import kotlinx.coroutines.flow.update +import javax.inject.Inject +import javax.inject.Singleton + +@Singleton +internal class StakingStateController @Inject constructor() { + + val value: StakingUiState get() = uiState.value + + private val mutableUiState: MutableStateFlow = MutableStateFlow(value = getInitialState()) + + val uiState: StateFlow get() = mutableUiState.asStateFlow() + + fun update(function: (StakingUiState) -> StakingUiState) { + mutableUiState.update(function = function) + } + + fun update(transformer: Transformer) { + mutableUiState.update(function = transformer::transform) + } + + fun clear() { + mutableUiState.update { getInitialState() } + } + + private fun getInitialState(): StakingUiState { + return StakingUiState( + clickIntents = StakingClickIntentsStub, + cryptoCurrencyName = "", + currentStep = StakingStep.InitialInfo, + initialInfoState = StakingStates.InitialInfoState.Empty(), + amountState = AmountState.Empty(), + rewardsValidatorsState = StakingStates.RewardsValidatorsState.Empty(), + confirmationState = StakingStates.ConfirmationState.Empty(), + isBalanceHidden = false, + event = consumedEvent(), + bottomSheetConfig = null, + routeType = RouteType.STAKE, + ) + } +} \ No newline at end of file diff --git a/features/staking/impl/src/main/java/com/tangem/features/staking/impl/presentation/state/StakingStateRouter.kt b/features/staking/impl/src/main/java/com/tangem/features/staking/impl/presentation/state/StakingStateRouter.kt new file mode 100644 index 0000000000..2629f6405b --- /dev/null +++ b/features/staking/impl/src/main/java/com/tangem/features/staking/impl/presentation/state/StakingStateRouter.kt @@ -0,0 +1,63 @@ +package com.tangem.features.staking.impl.presentation.state + +import com.tangem.common.routing.AppRouter + +internal class StakingStateRouter( + private val appRouter: AppRouter, + private val stateController: StakingStateController, +) { + + fun onBackClick() { + appRouter.pop() + stateController.clear() + } + + fun onNextClick() { + when (stateController.value.currentStep) { + StakingStep.InitialInfo -> when (stateController.value.routeType) { + RouteType.STAKE -> showAmount() + RouteType.OTHER, + RouteType.UNSTAKE, + -> showConfirmation() + RouteType.CLAIM -> showRewardsValidators() + } + StakingStep.RewardsValidators, + StakingStep.Validators, + StakingStep.Amount, + -> showConfirmation() + StakingStep.Confirmation -> { + // TODO staking handle + } + } + } + + fun onPrevClick() { + when (stateController.uiState.value.currentStep) { + StakingStep.InitialInfo -> onBackClick() + StakingStep.Amount -> showInitial() + StakingStep.Confirmation -> showAmount() + StakingStep.Validators -> showConfirmation() + StakingStep.RewardsValidators -> showInitial() + } + } + + private fun showInitial() { + stateController.update { it.copy(currentStep = StakingStep.InitialInfo) } + } + + fun showRewardsValidators() { + stateController.update { it.copy(currentStep = StakingStep.RewardsValidators) } + } + + fun showAmount() { + stateController.update { it.copy(currentStep = StakingStep.Amount) } + } + + fun showValidators() { + stateController.update { it.copy(currentStep = StakingStep.Validators) } + } + + fun showConfirmation() { + stateController.update { it.copy(currentStep = StakingStep.Confirmation) } + } +} \ No newline at end of file diff --git a/features/staking/impl/src/main/java/com/tangem/features/staking/impl/presentation/state/StakingUiState.kt b/features/staking/impl/src/main/java/com/tangem/features/staking/impl/presentation/state/StakingUiState.kt new file mode 100644 index 0000000000..2ad72821a5 --- /dev/null +++ b/features/staking/impl/src/main/java/com/tangem/features/staking/impl/presentation/state/StakingUiState.kt @@ -0,0 +1,118 @@ +package com.tangem.features.staking.impl.presentation.state + +import androidx.compose.runtime.Immutable +import com.tangem.common.ui.amountScreen.models.AmountState +import com.tangem.core.ui.components.bottomsheets.TangemBottomSheetConfig +import com.tangem.core.ui.components.list.RoundedListWithDividersItemData +import com.tangem.core.ui.event.StateEvent +import com.tangem.core.ui.extensions.TextReference +import com.tangem.domain.staking.model.stakekit.PendingAction +import com.tangem.features.staking.impl.presentation.state.transformers.InfoType +import com.tangem.features.staking.impl.presentation.viewmodel.StakingClickIntents +import kotlinx.collections.immutable.ImmutableList + +/** + * Ui states of the staking screen + */ +@Immutable +internal data class StakingUiState( + val clickIntents: StakingClickIntents, + val cryptoCurrencyName: String, + val currentStep: StakingStep, + val initialInfoState: StakingStates.InitialInfoState, + val amountState: AmountState, + val rewardsValidatorsState: StakingStates.RewardsValidatorsState, + val confirmationState: StakingStates.ConfirmationState, + val isBalanceHidden: Boolean, + val bottomSheetConfig: TangemBottomSheetConfig?, + val routeType: RouteType, + val event: StateEvent, +) { + + fun copyWrapped( + initialInfoState: StakingStates.InitialInfoState = this.initialInfoState, + amountState: AmountState = this.amountState, + confirmationState: StakingStates.ConfirmationState = this.confirmationState, + ): StakingUiState = copy( + initialInfoState = initialInfoState, + amountState = amountState, + confirmationState = confirmationState, + ) +} + +internal sealed class StakingStates { + + abstract val isPrimaryButtonEnabled: Boolean + + /** Initial info state */ + sealed class InitialInfoState : StakingStates() { + data class Data( + override val isPrimaryButtonEnabled: Boolean, + val infoItems: ImmutableList, + val aprRange: TextReference, + val onInfoClick: (InfoType) -> Unit, + val yieldBalance: InnerYieldBalanceState, + val isStakeMoreAvailable: Boolean, + ) : InitialInfoState() + + data class InitialInfoItems( + val available: String, + val onStake: String, + val aprRange: TextReference, + val unbondingPeriod: String, + val minimumRequirement: String, + val rewardClaiming: String, + val warmupPeriod: String, + val rewardSchedule: String, + ) + + data class Empty( + override val isPrimaryButtonEnabled: Boolean = false, + ) : InitialInfoState() + } + + /** Select validator to claim rewards state */ + sealed class RewardsValidatorsState : StakingStates() { + data class Data( + override val isPrimaryButtonEnabled: Boolean, + val rewards: ImmutableList, + ) : RewardsValidatorsState() + + data class Empty( + override val isPrimaryButtonEnabled: Boolean = false, + ) : RewardsValidatorsState() + } + + /** Confirmation state */ + sealed class ConfirmationState : StakingStates() { + data class Data( + override val isPrimaryButtonEnabled: Boolean, + val innerState: InnerConfirmationStakingState, + val feeState: FeeState, + val validatorState: ValidatorState, + val pendingActions: ImmutableList, + val notifications: ImmutableList, + val footerText: String, + val transactionDoneState: TransactionDoneState, + ) : ConfirmationState() + + data class Empty( + override val isPrimaryButtonEnabled: Boolean = false, + ) : ConfirmationState() + } +} + +enum class StakingStep { + InitialInfo, + RewardsValidators, + Amount, + Confirmation, + Validators, +} + +enum class RouteType { + STAKE, + UNSTAKE, + CLAIM, + OTHER, +} \ No newline at end of file diff --git a/features/staking/impl/src/main/java/com/tangem/features/staking/impl/presentation/state/TransactionDoneState.kt b/features/staking/impl/src/main/java/com/tangem/features/staking/impl/presentation/state/TransactionDoneState.kt new file mode 100644 index 0000000000..3af58c716f --- /dev/null +++ b/features/staking/impl/src/main/java/com/tangem/features/staking/impl/presentation/state/TransactionDoneState.kt @@ -0,0 +1,14 @@ +package com.tangem.features.staking.impl.presentation.state + +import androidx.compose.runtime.Immutable + +@Immutable +internal sealed class TransactionDoneState { + + data class Content( + val timestamp: Long, + val txUrl: String, + ) : TransactionDoneState() + + data object Empty : TransactionDoneState() +} \ No newline at end of file diff --git a/features/staking/impl/src/main/java/com/tangem/features/staking/impl/presentation/state/ValidatorState.kt b/features/staking/impl/src/main/java/com/tangem/features/staking/impl/presentation/state/ValidatorState.kt new file mode 100644 index 0000000000..7871149443 --- /dev/null +++ b/features/staking/impl/src/main/java/com/tangem/features/staking/impl/presentation/state/ValidatorState.kt @@ -0,0 +1,34 @@ +package com.tangem.features.staking.impl.presentation.state + +import androidx.compose.runtime.Immutable +import com.tangem.domain.staking.model.stakekit.Yield + +@Immutable +internal sealed class ValidatorState { + + abstract val isClickable: Boolean + + data class Content( + override val isClickable: Boolean, + val chosenValidator: Yield.Validator, + val availableValidators: List, + ) : ValidatorState() + + data object Loading : ValidatorState() { + override val isClickable: Boolean + get() = false + } + + data object Error : ValidatorState() { + override val isClickable: Boolean + get() = false + } + + fun copySealed(isClickable: Boolean): ValidatorState { + return if (this is Content) { + copy(isClickable = isClickable) + } else { + this + } + } +} \ No newline at end of file diff --git a/features/staking/impl/src/main/java/com/tangem/features/staking/impl/presentation/state/bottomsheet/StakingInfoBottomSheetConfig.kt b/features/staking/impl/src/main/java/com/tangem/features/staking/impl/presentation/state/bottomsheet/StakingInfoBottomSheetConfig.kt new file mode 100644 index 0000000000..f8cc06e495 --- /dev/null +++ b/features/staking/impl/src/main/java/com/tangem/features/staking/impl/presentation/state/bottomsheet/StakingInfoBottomSheetConfig.kt @@ -0,0 +1,9 @@ +package com.tangem.features.staking.impl.presentation.state.bottomsheet + +import com.tangem.core.ui.components.bottomsheets.TangemBottomSheetConfigContent +import com.tangem.core.ui.extensions.TextReference + +data class StakingInfoBottomSheetConfig( + val title: TextReference, + val text: TextReference, +) : TangemBottomSheetConfigContent \ No newline at end of file diff --git a/features/staking/impl/src/main/java/com/tangem/features/staking/impl/presentation/state/converters/RewardsValidatorStateConverter.kt b/features/staking/impl/src/main/java/com/tangem/features/staking/impl/presentation/state/converters/RewardsValidatorStateConverter.kt new file mode 100644 index 0000000000..107207c36c --- /dev/null +++ b/features/staking/impl/src/main/java/com/tangem/features/staking/impl/presentation/state/converters/RewardsValidatorStateConverter.kt @@ -0,0 +1,101 @@ +package com.tangem.features.staking.impl.presentation.state.converters + +import com.tangem.core.ui.extensions.* +import com.tangem.core.ui.utils.BigDecimalFormatter +import com.tangem.core.ui.utils.parseBigDecimal +import com.tangem.domain.appcurrency.model.AppCurrency +import com.tangem.domain.staking.model.stakekit.* +import com.tangem.domain.tokens.model.CryptoCurrencyStatus +import com.tangem.features.staking.impl.R +import com.tangem.features.staking.impl.presentation.state.BalanceState +import com.tangem.features.staking.impl.presentation.state.StakingStates +import com.tangem.utils.Provider +import com.tangem.utils.StringsSigns.PLUS +import com.tangem.utils.converter.Converter +import kotlinx.collections.immutable.ImmutableList +import kotlinx.collections.immutable.toPersistentList +import java.math.BigDecimal + +internal class RewardsValidatorStateConverter( + private val cryptoCurrencyStatusProvider: Provider, + private val appCurrencyProvider: Provider, + private val yield: Yield, +) : Converter { + override fun convert(value: Unit): StakingStates.RewardsValidatorsState { + val cryptoCurrencyStatus = cryptoCurrencyStatusProvider() + + val yieldBalance = cryptoCurrencyStatus.value.yieldBalance + return if (yieldBalance is YieldBalance.Data) { + val balances = yieldBalance.balance.items + StakingStates.RewardsValidatorsState.Data( + isPrimaryButtonEnabled = true, + rewards = balances + .filter { it.type == BalanceType.REWARDS } + .mapRewardBalances(cryptoCurrencyStatus) + .toPersistentList(), + ) + } else { + StakingStates.RewardsValidatorsState.Empty() + } + } + + private fun List.mapRewardBalances(cryptoCurrencyStatus: CryptoCurrencyStatus) = + this.mapNotNull { balance -> + val validator = yield.validators.firstOrNull { + it.address.contains(balance.validatorAddress.orEmpty(), ignoreCase = true) + } + val cryptoValue = balance.amount.times(balance.pricePerShare) + val fiatValue = cryptoCurrencyStatus.value.fiatRate?.times(cryptoValue) + val unbondingPeriod = yield.metadata.cooldownPeriod.days + validator?.toBalanceState( + cryptoCurrencyStatus = cryptoCurrencyStatus, + cryptoValue = cryptoValue, + fiatValue = fiatValue, + unbondingPeriod = pluralReference( + id = R.plurals.common_days, + count = unbondingPeriod, + formatArgs = wrappedList(unbondingPeriod), + ), + pendingActions = balance.pendingActions.toPersistentList(), + ) + } + + private fun Yield.Validator.toBalanceState( + cryptoCurrencyStatus: CryptoCurrencyStatus, + cryptoValue: BigDecimal, + fiatValue: BigDecimal?, + unbondingPeriod: TextReference, + pendingActions: ImmutableList, + ): BalanceState { + val appCurrency = appCurrencyProvider() + val cryptoCurrency = cryptoCurrencyStatus.currency + + val cryptoAmount = stringReference( + BigDecimalFormatter.formatCryptoAmount( + cryptoAmount = cryptoValue, + cryptoCurrency = cryptoCurrency, + ), + ) + val fiatAmount = combinedReference( + stringReference(PLUS), + stringReference( + BigDecimalFormatter.formatFiatAmount( + fiatAmount = fiatValue, + fiatCurrencyCode = appCurrency.code, + fiatCurrencySymbol = appCurrency.symbol, + ), + ), + ) + + return BalanceState( + validator = this, + cryptoValue = cryptoValue.parseBigDecimal(cryptoCurrency.decimals), + cryptoDecimal = cryptoValue, + cryptoAmount = cryptoAmount, + fiatAmount = fiatAmount, + rawCurrencyId = cryptoCurrency.id.rawCurrencyId, + unbondingPeriod = unbondingPeriod, + pendingActions = pendingActions, + ) + } +} \ No newline at end of file diff --git a/features/staking/impl/src/main/java/com/tangem/features/staking/impl/presentation/state/converters/YieldBalancesConverter.kt b/features/staking/impl/src/main/java/com/tangem/features/staking/impl/presentation/state/converters/YieldBalancesConverter.kt new file mode 100644 index 0000000000..23141275d2 --- /dev/null +++ b/features/staking/impl/src/main/java/com/tangem/features/staking/impl/presentation/state/converters/YieldBalancesConverter.kt @@ -0,0 +1,141 @@ +package com.tangem.features.staking.impl.presentation.state.converters + +import com.tangem.core.ui.extensions.pluralReference +import com.tangem.core.ui.extensions.resourceReference +import com.tangem.core.ui.extensions.stringReference +import com.tangem.core.ui.extensions.wrappedList +import com.tangem.core.ui.utils.BigDecimalFormatter +import com.tangem.core.ui.utils.parseBigDecimal +import com.tangem.domain.appcurrency.model.AppCurrency +import com.tangem.domain.staking.model.stakekit.* +import com.tangem.domain.tokens.model.CryptoCurrencyStatus +import com.tangem.features.staking.impl.R +import com.tangem.features.staking.impl.presentation.state.BalanceGroupType +import com.tangem.features.staking.impl.presentation.state.BalanceGroupedState +import com.tangem.features.staking.impl.presentation.state.BalanceState +import com.tangem.features.staking.impl.presentation.state.InnerYieldBalanceState +import com.tangem.utils.Provider +import com.tangem.utils.converter.Converter +import com.tangem.utils.isNullOrZero +import kotlinx.collections.immutable.toPersistentList + +internal class YieldBalancesConverter( + private val cryptoCurrencyStatusProvider: Provider, + private val appCurrencyProvider: Provider, + private val yield: Yield, +) : Converter { + override fun convert(value: Unit): InnerYieldBalanceState { + val cryptoCurrencyStatus = cryptoCurrencyStatusProvider() + val appCurrency = appCurrencyProvider() + + val cryptoCurrency = cryptoCurrencyStatus.currency + val yieldBalance = cryptoCurrencyStatus.value.yieldBalance + + return if (yieldBalance is YieldBalance.Data) { + val cryptoRewardsValue = yieldBalance.getRewardStakingBalance() + val fiatRewardsValue = cryptoCurrencyStatus.value.fiatRate?.times(cryptoRewardsValue) + val groupedBalances = getGroupedBalance(yieldBalance.balance) + + InnerYieldBalanceState.Data( + rewardsCrypto = BigDecimalFormatter.formatCryptoAmount( + cryptoAmount = cryptoRewardsValue, + cryptoCurrency = cryptoCurrency, + ), + rewardsFiat = BigDecimalFormatter.formatFiatAmount( + fiatAmount = fiatRewardsValue, + fiatCurrencyCode = appCurrency.code, + fiatCurrencySymbol = appCurrency.symbol, + ), + isRewardsToClaim = !cryptoRewardsValue.isNullOrZero(), + balance = groupedBalances, + ) + } else { + InnerYieldBalanceState.Empty + } + } + + private fun getGroupedBalance(balance: YieldBalanceItem) = balance.items + .sortedBy { it.type } + .groupBy { it.type.toGroup() } + .mapNotNull { item -> + val (title, footer) = getGroupTitle(item.key) + title?.let { + BalanceGroupedState( + items = item.value.mapBalances().toPersistentList(), + footer = footer, + title = it, + type = item.key, + ) + } + } + + private fun List.mapBalances(): List { + val cryptoCurrencyStatus = cryptoCurrencyStatusProvider() + val appCurrency = appCurrencyProvider() + val cryptoCurrency = cryptoCurrencyStatus.currency + return this.mapNotNull { balance -> + val validator = yield.validators.firstOrNull { + balance.validatorAddress?.contains(it.address, ignoreCase = true) == true + } + val cryptoAmount = balance.amount * balance.pricePerShare + val fiatAmount = cryptoCurrencyStatus.value.fiatRate?.times(cryptoAmount) + val unbondingPeriod = yield.metadata.cooldownPeriod.days + validator?.let { + BalanceState( + validator = validator, + cryptoValue = cryptoAmount.parseBigDecimal(cryptoCurrency.decimals), + cryptoDecimal = cryptoAmount, + cryptoAmount = stringReference( + BigDecimalFormatter.formatCryptoAmount( + cryptoAmount = cryptoAmount, + cryptoCurrency = cryptoCurrency, + ), + ), + fiatAmount = stringReference( + BigDecimalFormatter.formatFiatAmount( + fiatAmount = fiatAmount, + fiatCurrencyCode = appCurrency.code, + fiatCurrencySymbol = appCurrency.symbol, + ), + ), + rawCurrencyId = balance.rawCurrencyId, + unbondingPeriod = pluralReference( + id = R.plurals.common_days, + count = unbondingPeriod, + formatArgs = wrappedList(unbondingPeriod), + ), + pendingActions = balance.pendingActions.toPersistentList(), + ) + } + } + } + + private fun BalanceType.toGroup() = when (this) { + BalanceType.PREPARING, + BalanceType.STAKED, + BalanceType.REWARDS, + BalanceType.AVAILABLE, + BalanceType.LOCKED, + -> BalanceGroupType.ACTIVE + BalanceType.UNSTAKING, + BalanceType.UNLOCKING, + BalanceType.UNSTAKED, + -> BalanceGroupType.UNSTAKED + BalanceType.UNKNOWN, + -> BalanceGroupType.UNKNOWN + } + + private fun getGroupTitle(type: BalanceGroupType) = when (type) { + BalanceGroupType.ACTIVE -> resourceReference( + R.string.staking_active, + ) to resourceReference( + R.string.staking_active_footer, + ) + BalanceGroupType.UNSTAKED -> resourceReference( + R.string.staking_unstaked, + ) to resourceReference( + R.string.staking_unstaked_footer, + ) + BalanceGroupType.UNKNOWN -> null to null + } +} \ No newline at end of file diff --git a/features/staking/impl/src/main/java/com/tangem/features/staking/impl/presentation/state/previewdata/ConfirmationStatePreviewData.kt b/features/staking/impl/src/main/java/com/tangem/features/staking/impl/presentation/state/previewdata/ConfirmationStatePreviewData.kt new file mode 100644 index 0000000000..0994dd7cdb --- /dev/null +++ b/features/staking/impl/src/main/java/com/tangem/features/staking/impl/presentation/state/previewdata/ConfirmationStatePreviewData.kt @@ -0,0 +1,90 @@ +package com.tangem.features.staking.impl.presentation.state.previewdata + +import com.tangem.blockchain.common.Amount +import com.tangem.blockchain.common.AmountType.Coin +import com.tangem.blockchain.common.transaction.Fee +import com.tangem.domain.appcurrency.model.AppCurrency +import com.tangem.domain.staking.model.stakekit.Yield +import com.tangem.features.staking.impl.presentation.state.* +import com.tangem.features.staking.impl.presentation.state.StakingNotification +import com.tangem.features.staking.impl.presentation.state.StakingStates +import com.tangem.features.staking.impl.presentation.state.ValidatorState +import kotlinx.collections.immutable.persistentListOf +import java.math.BigDecimal + +internal object ConfirmationStatePreviewData { + + private val validatorList = listOf( + Yield.Validator( + address = "0xa6e768fef2d1af36c0cfdb276422e7881a83e951", + status = "active", + name = "Luganodes", + image = "https://assets.stakek.it/validators/luganodes.png", + apr = BigDecimal("0.054823398040640445"), + commission = 0.1, + stakedBalance = "355544384.45009977", + website = "https://luganodes.com/", + votingPower = 0.09778360195377911, + preferred = true, + ), + Yield.Validator( + address = "0x35b1ca0f398905cf752e6fe122b51c88022fca32", + status = "active", + name = "InfStones", + image = "https://assets.stakek.it/validators/infstones.png", + apr = BigDecimal("0.057786472172836965"), + commission = 0.05, + stakedBalance = "12495684.05643019", + website = "https://infstones.com/", + votingPower = 0.0034366257754399774, + preferred = true, + ), + Yield.Validator( + address = "0xd14a87025109013b0a2354a775cb335f926af65a", + status = "active", + name = "Kiln", + image = "https://assets.stakek.it/validators/kiln.png", + apr = BigDecimal("0.057786472172836965"), + commission = 0.05, + stakedBalance = "85400369.96393165", + website = "https://infstones.com/", + votingPower = 0.023487238579718264, + preferred = true, + ), + ) + + private val fee = Fee.Common( + amount = Amount( + currencySymbol = "MATIC", + value = BigDecimal(0.159806), + decimals = 18, + type = Coin, + ), + ) + + val assentStakingState = StakingStates.ConfirmationState.Data( + isPrimaryButtonEnabled = true, + innerState = InnerConfirmationStakingState.ASSENT, + feeState = FeeState.Content( + fee = fee, + rate = BigDecimal.ONE, + appCurrency = AppCurrency.Default, + isFeeApproximate = false, + isFeeConvertibleToFiat = true, + ), + validatorState = ValidatorState.Content( + isClickable = true, + chosenValidator = validatorList[0], + availableValidators = validatorList, + ), + footerText = "You stake \$715.11 and will be receiving ~\$35 monthly", + notifications = persistentListOf( + StakingNotification.Warning.EarnRewards( + currencyName = "Solana", + days = 2, + ), + ), + transactionDoneState = TransactionDoneState.Empty, + pendingActions = persistentListOf(), + ) +} \ No newline at end of file diff --git a/features/staking/impl/src/main/java/com/tangem/features/staking/impl/presentation/state/previewdata/InitialStakingStatePreview.kt b/features/staking/impl/src/main/java/com/tangem/features/staking/impl/presentation/state/previewdata/InitialStakingStatePreview.kt new file mode 100644 index 0000000000..cca20b1416 --- /dev/null +++ b/features/staking/impl/src/main/java/com/tangem/features/staking/impl/presentation/state/previewdata/InitialStakingStatePreview.kt @@ -0,0 +1,94 @@ +package com.tangem.features.staking.impl.presentation.state.previewdata + +import com.tangem.core.ui.components.list.RoundedListWithDividersItemData +import com.tangem.core.ui.extensions.TextReference +import com.tangem.core.ui.extensions.stringReference +import com.tangem.domain.staking.model.stakekit.Yield +import com.tangem.features.staking.impl.R +import com.tangem.features.staking.impl.presentation.state.* +import kotlinx.collections.immutable.persistentListOf + +internal object InitialStakingStatePreview { + val defaultState = StakingStates.InitialInfoState.Data( + isPrimaryButtonEnabled = true, + aprRange = stringReference("2.54-5.12%"), + infoItems = persistentListOf( + RoundedListWithDividersItemData( + id = R.string.staking_details_available, + startText = TextReference.Res(R.string.staking_details_available), + endText = TextReference.Str("15 SOL"), + ), + RoundedListWithDividersItemData( + id = R.string.staking_details_annual_percentage_rate, + startText = TextReference.Res(R.string.staking_details_annual_percentage_rate), + endText = TextReference.Str("2.54-5.12%"), + ), + RoundedListWithDividersItemData( + id = R.string.staking_details_unbonding_period, + startText = TextReference.Res(R.string.staking_details_unbonding_period), + endText = TextReference.Str("3d"), + ), + RoundedListWithDividersItemData( + id = R.string.staking_details_minimum_requirement, + startText = TextReference.Res(R.string.staking_details_minimum_requirement), + endText = TextReference.Str("12 SOL"), + ), + RoundedListWithDividersItemData( + id = R.string.staking_details_reward_claiming, + startText = TextReference.Res(R.string.staking_details_reward_claiming), + endText = TextReference.Str("Auto"), + ), + RoundedListWithDividersItemData( + id = R.string.staking_details_warmup_period, + startText = TextReference.Res(R.string.staking_details_warmup_period), + endText = TextReference.Str("Days"), + ), + RoundedListWithDividersItemData( + id = R.string.staking_details_reward_schedule, + startText = TextReference.Res(R.string.staking_details_reward_schedule), + endText = TextReference.Str("Block"), + ), + ), + onInfoClick = {}, + yieldBalance = InnerYieldBalanceState.Empty, + isStakeMoreAvailable = true, + ) + + val stateWithYield = defaultState.copy( + yieldBalance = InnerYieldBalanceState.Data( + rewardsFiat = "100 $", + rewardsCrypto = "100 SOL", + isRewardsToClaim = false, + balance = listOf( + BalanceGroupedState( + title = stringReference("Staked"), + footer = null, + type = BalanceGroupType.ACTIVE, + items = persistentListOf( + BalanceState( + cryptoValue = "100", + cryptoAmount = stringReference("100 SOL"), + cryptoDecimal = "100".toBigDecimal(), + fiatAmount = stringReference("100 $"), + rawCurrencyId = null, + validator = Yield.Validator( + address = "address", + status = "status", + name = "Binance", + image = null, + website = null, + apr = "5".toBigDecimal(), + commission = null, + stakedBalance = null, + votingPower = null, + preferred = false, + ), + unbondingPeriod = stringReference("3 days"), + pendingActions = persistentListOf(), + ), + ), + ), + ), + ), + ) +} \ No newline at end of file diff --git a/features/staking/impl/src/main/java/com/tangem/features/staking/impl/presentation/state/stub/StakingClickIntentsStub.kt b/features/staking/impl/src/main/java/com/tangem/features/staking/impl/presentation/state/stub/StakingClickIntentsStub.kt new file mode 100644 index 0000000000..b9a90741b4 --- /dev/null +++ b/features/staking/impl/src/main/java/com/tangem/features/staking/impl/presentation/state/stub/StakingClickIntentsStub.kt @@ -0,0 +1,43 @@ +package com.tangem.features.staking.impl.presentation.state.stub + +import com.tangem.domain.staking.model.stakekit.PendingAction +import com.tangem.domain.staking.model.stakekit.Yield +import com.tangem.features.staking.impl.presentation.state.BalanceState +import com.tangem.features.staking.impl.presentation.state.transformers.InfoType +import com.tangem.features.staking.impl.presentation.viewmodel.StakingClickIntents +import kotlinx.collections.immutable.ImmutableList + +object StakingClickIntentsStub : StakingClickIntents { + + override fun onBackClick() {} + + override fun onNextClick(pendingActions: ImmutableList) {} + + override fun onPrevClick() {} + + override fun onInfoClick(infoType: InfoType) {} + + override fun onAmountValueChange(value: String) {} + + override fun onAmountPasteTriggerDismiss() {} + + override fun onMaxValueClick() {} + + override fun onCurrencyChangeClick(isFiat: Boolean) {} + + override fun onAmountNext() {} + + override fun openValidators() {} + + override fun onValidatorSelect(validator: Yield.Validator) {} + + override fun openRewardsValidators() {} + + override fun selectRewardValidator(rewardValue: String) {} + + override fun onExploreClick() {} + + override fun onShareClick() {} + + override fun onActiveStake(activeStake: BalanceState) {} +} \ No newline at end of file diff --git a/features/staking/impl/src/main/java/com/tangem/features/staking/impl/presentation/state/transformers/DismissBottomSheetStateTransformer.kt b/features/staking/impl/src/main/java/com/tangem/features/staking/impl/presentation/state/transformers/DismissBottomSheetStateTransformer.kt new file mode 100644 index 0000000000..251b237e9d --- /dev/null +++ b/features/staking/impl/src/main/java/com/tangem/features/staking/impl/presentation/state/transformers/DismissBottomSheetStateTransformer.kt @@ -0,0 +1,10 @@ +package com.tangem.features.staking.impl.presentation.state.transformers + +import com.tangem.features.staking.impl.presentation.state.StakingUiState +import com.tangem.utils.transformer.Transformer + +internal class DismissBottomSheetStateTransformer : Transformer { + override fun transform(prevState: StakingUiState): StakingUiState { + return prevState.copy(bottomSheetConfig = null) + } +} \ No newline at end of file diff --git a/features/staking/impl/src/main/java/com/tangem/features/staking/impl/presentation/state/transformers/HideBalanceStateTransformer.kt b/features/staking/impl/src/main/java/com/tangem/features/staking/impl/presentation/state/transformers/HideBalanceStateTransformer.kt new file mode 100644 index 0000000000..84128a62a1 --- /dev/null +++ b/features/staking/impl/src/main/java/com/tangem/features/staking/impl/presentation/state/transformers/HideBalanceStateTransformer.kt @@ -0,0 +1,13 @@ +package com.tangem.features.staking.impl.presentation.state.transformers + +import com.tangem.features.staking.impl.presentation.state.StakingUiState +import com.tangem.utils.transformer.Transformer + +internal class HideBalanceStateTransformer( + private val isBalanceHidden: Boolean, +) : Transformer { + + override fun transform(prevState: StakingUiState): StakingUiState { + return prevState.copy(isBalanceHidden = isBalanceHidden) + } +} \ No newline at end of file diff --git a/features/staking/impl/src/main/java/com/tangem/features/staking/impl/presentation/state/transformers/SetConfirmationStateAssentTransformer.kt b/features/staking/impl/src/main/java/com/tangem/features/staking/impl/presentation/state/transformers/SetConfirmationStateAssentTransformer.kt new file mode 100644 index 0000000000..f2dc22698e --- /dev/null +++ b/features/staking/impl/src/main/java/com/tangem/features/staking/impl/presentation/state/transformers/SetConfirmationStateAssentTransformer.kt @@ -0,0 +1,57 @@ +package com.tangem.features.staking.impl.presentation.state.transformers + +import com.tangem.blockchain.common.Amount +import com.tangem.blockchain.common.transaction.Fee +import com.tangem.domain.appcurrency.model.AppCurrency +import com.tangem.domain.staking.model.stakekit.PendingAction +import com.tangem.domain.staking.model.stakekit.transaction.StakingGasEstimate +import com.tangem.domain.tokens.model.CryptoCurrencyStatus +import com.tangem.features.staking.impl.presentation.state.FeeState +import com.tangem.features.staking.impl.presentation.state.InnerConfirmationStakingState +import com.tangem.features.staking.impl.presentation.state.StakingStates +import com.tangem.features.staking.impl.presentation.state.StakingUiState +import com.tangem.utils.Provider +import com.tangem.utils.transformer.Transformer +import kotlinx.collections.immutable.ImmutableList + +internal class SetConfirmationStateAssentTransformer( + private val appCurrencyProvider: Provider, + private val cryptoCurrencyStatusProvider: Provider, + private val stakingGasEstimate: StakingGasEstimate, + private val pendingActionList: ImmutableList, +) : Transformer { + + override fun transform(prevState: StakingUiState): StakingUiState { + return prevState.copy( + confirmationState = prevState.confirmationState.copyWrapped(stakingGasEstimate), + ) + } + + private fun StakingStates.ConfirmationState.copyWrapped( + gasEstimate: StakingGasEstimate, + ): StakingStates.ConfirmationState { + if (this is StakingStates.ConfirmationState.Data) { + return copy( + innerState = InnerConfirmationStakingState.ASSENT, + feeState = FeeState.Content( + fee = Fee.Common( + Amount( + currencySymbol = gasEstimate.token.symbol, + value = gasEstimate.amount, + decimals = gasEstimate.token.decimals, + ), + ), + rate = cryptoCurrencyStatusProvider().value.fiatRate, + isFeeConvertibleToFiat = cryptoCurrencyStatusProvider().currency.network.hasFiatFeeRate, + appCurrency = appCurrencyProvider(), + isFeeApproximate = false, + ), + validatorState = validatorState.copySealed(isClickable = true), + pendingActions = pendingActionList, + isPrimaryButtonEnabled = true, + ) + } else { + return this + } + } +} \ No newline at end of file diff --git a/features/staking/impl/src/main/java/com/tangem/features/staking/impl/presentation/state/transformers/SetConfirmationStateCompletedTransformer.kt b/features/staking/impl/src/main/java/com/tangem/features/staking/impl/presentation/state/transformers/SetConfirmationStateCompletedTransformer.kt new file mode 100644 index 0000000000..fa8af0041e --- /dev/null +++ b/features/staking/impl/src/main/java/com/tangem/features/staking/impl/presentation/state/transformers/SetConfirmationStateCompletedTransformer.kt @@ -0,0 +1,60 @@ +package com.tangem.features.staking.impl.presentation.state.transformers + +import com.tangem.blockchain.common.Amount +import com.tangem.blockchain.common.transaction.Fee +import com.tangem.domain.appcurrency.model.AppCurrency +import com.tangem.domain.staking.model.stakekit.transaction.StakingGasEstimate +import com.tangem.domain.tokens.model.CryptoCurrencyStatus +import com.tangem.features.staking.impl.presentation.state.* +import com.tangem.features.staking.impl.presentation.state.StakingStates +import com.tangem.features.staking.impl.presentation.state.StakingUiState +import com.tangem.features.staking.impl.presentation.state.TransactionDoneState +import com.tangem.utils.Provider +import com.tangem.utils.transformer.Transformer + +internal class SetConfirmationStateCompletedTransformer( + private val appCurrencyProvider: Provider, + private val cryptoCurrencyStatusProvider: Provider, + private val stakingGasEstimate: StakingGasEstimate, + private val txUrl: String, +) : Transformer { + + override fun transform(prevState: StakingUiState): StakingUiState { + return prevState.copy( + confirmationState = prevState.confirmationState.copyWrapped(stakingGasEstimate), + ) + } + + private fun StakingStates.ConfirmationState.copyWrapped( + gasEstimate: StakingGasEstimate, + ): StakingStates.ConfirmationState { + if (this is StakingStates.ConfirmationState.Data) { + return copy( + isPrimaryButtonEnabled = true, + innerState = InnerConfirmationStakingState.COMPLETED, + feeState = FeeState.Content( + fee = Fee.Common( + Amount( + currencySymbol = gasEstimate.token.symbol, + value = gasEstimate.amount, + decimals = gasEstimate.token.decimals, + ), + ), + rate = cryptoCurrencyStatusProvider().value.fiatRate, + isFeeConvertibleToFiat = cryptoCurrencyStatusProvider().currency.network.hasFiatFeeRate, + appCurrency = appCurrencyProvider(), + isFeeApproximate = false, + ), + validatorState = validatorState.copySealed( + isClickable = false, + ), + transactionDoneState = TransactionDoneState.Content( + timestamp = System.currentTimeMillis(), + txUrl = txUrl, + ), + ) + } else { + return this + } + } +} \ No newline at end of file diff --git a/features/staking/impl/src/main/java/com/tangem/features/staking/impl/presentation/state/transformers/SetConfirmationStateInProgressTransformer.kt b/features/staking/impl/src/main/java/com/tangem/features/staking/impl/presentation/state/transformers/SetConfirmationStateInProgressTransformer.kt new file mode 100644 index 0000000000..e17aad84b4 --- /dev/null +++ b/features/staking/impl/src/main/java/com/tangem/features/staking/impl/presentation/state/transformers/SetConfirmationStateInProgressTransformer.kt @@ -0,0 +1,27 @@ +package com.tangem.features.staking.impl.presentation.state.transformers + +import com.tangem.features.staking.impl.presentation.state.InnerConfirmationStakingState +import com.tangem.features.staking.impl.presentation.state.StakingStates +import com.tangem.features.staking.impl.presentation.state.StakingUiState +import com.tangem.utils.transformer.Transformer + +internal class SetConfirmationStateInProgressTransformer : Transformer { + + override fun transform(prevState: StakingUiState): StakingUiState { + return prevState.copy( + confirmationState = prevState.confirmationState.copyWrapped(), + ) + } + + private fun StakingStates.ConfirmationState.copyWrapped(): StakingStates.ConfirmationState { + return if (this is StakingStates.ConfirmationState.Data) { + copy( + isPrimaryButtonEnabled = false, + innerState = InnerConfirmationStakingState.IN_PROGRESS, + validatorState = validatorState.copySealed(isClickable = false), + ) + } else { + this + } + } +} \ No newline at end of file diff --git a/features/staking/impl/src/main/java/com/tangem/features/staking/impl/presentation/state/transformers/SetConfirmationStateLoadingTransformer.kt b/features/staking/impl/src/main/java/com/tangem/features/staking/impl/presentation/state/transformers/SetConfirmationStateLoadingTransformer.kt new file mode 100644 index 0000000000..b9bd36aff7 --- /dev/null +++ b/features/staking/impl/src/main/java/com/tangem/features/staking/impl/presentation/state/transformers/SetConfirmationStateLoadingTransformer.kt @@ -0,0 +1,39 @@ +package com.tangem.features.staking.impl.presentation.state.transformers + +import com.tangem.domain.staking.model.stakekit.Yield +import com.tangem.features.staking.impl.presentation.state.* +import com.tangem.utils.transformer.Transformer +import kotlinx.collections.immutable.persistentListOf + +internal class SetConfirmationStateLoadingTransformer( + private val yield: Yield, +) : Transformer { + + override fun transform(prevState: StakingUiState): StakingUiState { + val possibleConfirmationState = prevState.confirmationState as? StakingStates.ConfirmationState.Data + val possibleValidatorState = possibleConfirmationState?.validatorState as? ValidatorState.Content + val chosenValidator = possibleValidatorState?.chosenValidator ?: yield.validators[0] + + return prevState.copy( + confirmationState = StakingStates.ConfirmationState.Data( + isPrimaryButtonEnabled = false, + innerState = InnerConfirmationStakingState.ASSENT, + feeState = FeeState.Loading, + validatorState = ValidatorState.Content( + isClickable = false, + chosenValidator = chosenValidator, + availableValidators = yield.validators, + ), + notifications = persistentListOf( + StakingNotification.Warning.EarnRewards( + currencyName = yield.token.name, + days = yield.metadata.cooldownPeriod.days, + ), + ), + footerText = "", + transactionDoneState = TransactionDoneState.Empty, + pendingActions = persistentListOf(), + ), + ) + } +} \ No newline at end of file diff --git a/features/staking/impl/src/main/java/com/tangem/features/staking/impl/presentation/state/transformers/SetInitialDataStateTransformer.kt b/features/staking/impl/src/main/java/com/tangem/features/staking/impl/presentation/state/transformers/SetInitialDataStateTransformer.kt new file mode 100644 index 0000000000..5dba67759a --- /dev/null +++ b/features/staking/impl/src/main/java/com/tangem/features/staking/impl/presentation/state/transformers/SetInitialDataStateTransformer.kt @@ -0,0 +1,196 @@ +package com.tangem.features.staking.impl.presentation.state.transformers + +import com.tangem.common.extensions.remove +import com.tangem.common.ui.amountScreen.converters.AmountStateConverter +import com.tangem.common.ui.amountScreen.models.AmountState +import com.tangem.core.ui.components.currency.icon.converter.CryptoCurrencyToIconStateConverter +import com.tangem.core.ui.components.list.RoundedListWithDividersItemData +import com.tangem.core.ui.extensions.TextReference +import com.tangem.core.ui.extensions.resourceReference +import com.tangem.core.ui.extensions.stringReference +import com.tangem.core.ui.extensions.wrappedList +import com.tangem.core.ui.utils.BigDecimalFormatter +import com.tangem.domain.appcurrency.model.AppCurrency +import com.tangem.domain.staking.model.stakekit.Yield +import com.tangem.domain.staking.model.stakekit.YieldBalance +import com.tangem.domain.tokens.model.CryptoCurrencyStatus +import com.tangem.domain.wallets.models.UserWallet +import com.tangem.features.staking.impl.R +import com.tangem.features.staking.impl.presentation.state.StakingStates +import com.tangem.features.staking.impl.presentation.state.StakingStep +import com.tangem.features.staking.impl.presentation.state.StakingUiState +import com.tangem.features.staking.impl.presentation.state.ValidatorState +import com.tangem.features.staking.impl.presentation.state.converters.RewardsValidatorStateConverter +import com.tangem.features.staking.impl.presentation.state.converters.YieldBalancesConverter +import com.tangem.features.staking.impl.presentation.state.previewdata.ConfirmationStatePreviewData +import com.tangem.features.staking.impl.presentation.viewmodel.StakingClickIntents +import com.tangem.utils.Provider +import com.tangem.utils.extensions.orZero +import com.tangem.utils.transformer.Transformer +import kotlinx.collections.immutable.PersistentList +import kotlinx.collections.immutable.persistentListOf +import java.math.BigDecimal + +internal class SetInitialDataStateTransformer( + private val clickIntents: StakingClickIntents, + private val yield: Yield, + private val isStakeMoreAvailable: Boolean, + private val cryptoCurrencyStatusProvider: Provider, + private val userWalletProvider: Provider, + private val appCurrencyProvider: Provider, +) : Transformer { + + private val iconStateConverter by lazy(::CryptoCurrencyToIconStateConverter) + + private val amountStateConverter by lazy(LazyThreadSafetyMode.NONE) { + AmountStateConverter( + clickIntents = clickIntents, + cryptoCurrencyStatusProvider = cryptoCurrencyStatusProvider, + appCurrencyProvider = appCurrencyProvider, + userWalletProvider = userWalletProvider, + iconStateConverter = iconStateConverter, + ) + } + + private val rewardsValidatorStateConverter by lazy(LazyThreadSafetyMode.NONE) { + RewardsValidatorStateConverter(cryptoCurrencyStatusProvider, appCurrencyProvider, yield) + } + + private val yieldBalancesConverter by lazy(LazyThreadSafetyMode.NONE) { + YieldBalancesConverter(cryptoCurrencyStatusProvider, appCurrencyProvider, yield) + } + + override fun transform(prevState: StakingUiState): StakingUiState { + return prevState.copy( + clickIntents = clickIntents, + currentStep = StakingStep.InitialInfo, + initialInfoState = createInitialInfoState(), + amountState = createInitialAmountState(), + confirmationState = createInitialConfirmationState(), + rewardsValidatorsState = rewardsValidatorStateConverter.convert(Unit), + bottomSheetConfig = null, + ) + } + + private fun createInitialInfoState(): StakingStates.InitialInfoState.Data { + return StakingStates.InitialInfoState.Data( + isPrimaryButtonEnabled = true, + aprRange = getAprRange(), + infoItems = getInfoItems(), + onInfoClick = clickIntents::onInfoClick, + yieldBalance = yieldBalancesConverter.convert(Unit), + isStakeMoreAvailable = isStakeMoreAvailable, + ) + } + + private fun getInfoItems(): PersistentList { + val cryptoCurrencyStatus = cryptoCurrencyStatusProvider() + val yieldBalance = cryptoCurrencyStatus.value.yieldBalance + + return persistentListOf( + RoundedListWithDividersItemData( + id = R.string.staking_details_available, + startText = TextReference.Res(R.string.staking_details_available), + endText = TextReference.Str( + value = BigDecimalFormatter.formatCryptoAmount( + cryptoAmount = cryptoCurrencyStatus.value.amount, + cryptoCurrency = cryptoCurrencyStatus.currency.symbol, + decimals = cryptoCurrencyStatus.currency.decimals, + ), + ), + ), + RoundedListWithDividersItemData( + id = R.string.staking_details_annual_percentage_rate, + startText = TextReference.Res(R.string.staking_details_annual_percentage_rate), + endText = getAprRange(), + iconClick = { clickIntents.onInfoClick(InfoType.APY) }, + ), + RoundedListWithDividersItemData( + id = 0, // todo remove in merge + startText = TextReference.Res(0), // todo remove in merge + endText = TextReference.Str( + value = BigDecimalFormatter.formatCryptoAmount( + cryptoAmount = (yieldBalance as? YieldBalance.Data)?.getTotalStakingBalance().orZero(), + cryptoCurrency = cryptoCurrencyStatus.currency.symbol, + decimals = cryptoCurrencyStatus.currency.decimals, + ), + ), + ), + RoundedListWithDividersItemData( + id = R.string.staking_details_unbonding_period, + startText = TextReference.Res(R.string.staking_details_unbonding_period), + endText = TextReference.Str(yield.metadata.cooldownPeriod.days.toString()), + iconClick = { clickIntents.onInfoClick(InfoType.UNBOUNDING_PERIOD) }, + ), + RoundedListWithDividersItemData( + id = R.string.staking_details_minimum_requirement, + startText = TextReference.Res(R.string.staking_details_minimum_requirement), + endText = TextReference.Str( + value = BigDecimalFormatter.formatCryptoAmount( + cryptoAmount = yield.args.enter.args[KEY_AMOUNT]?.minimum?.toBigDecimal(), + cryptoCurrency = cryptoCurrencyStatus.currency.symbol, + decimals = cryptoCurrencyStatus.currency.decimals, + ), + ), + ), + RoundedListWithDividersItemData( + id = R.string.staking_details_reward_claiming, + startText = TextReference.Res(R.string.staking_details_reward_claiming), + endText = TextReference.Str(yield.metadata.rewardClaiming), + iconClick = { clickIntents.onInfoClick(InfoType.REWARD_CLAIMING) }, + ), + RoundedListWithDividersItemData( + id = R.string.staking_details_warmup_period, + startText = TextReference.Res(R.string.staking_details_warmup_period), + endText = TextReference.Str(yield.metadata.warmupPeriod.days.toString()), + iconClick = { clickIntents.onInfoClick(InfoType.WARMUP_PERIOD) }, + ), + RoundedListWithDividersItemData( + id = R.string.staking_details_reward_schedule, + startText = TextReference.Res(R.string.staking_details_reward_schedule), + endText = TextReference.Str(yield.metadata.rewardSchedule), + iconClick = { clickIntents.onInfoClick(InfoType.REWARD_SCHEDULE) }, + ), + ) + } + + private fun createInitialAmountState(): AmountState { + return amountStateConverter.convert("") + } + + private fun createInitialConfirmationState(): StakingStates.ConfirmationState { + return ConfirmationStatePreviewData.assentStakingState.copy( + validatorState = ValidatorState.Content( + isClickable = true, + chosenValidator = yield.validators.first(), + availableValidators = yield.validators, + ), + ) + } + + private fun getAprRange(): TextReference { + val aprValues = yield.validators.mapNotNull { it.apr } + + val minApr = aprValues.min() + val maxApr = aprValues.max() + + val formattedMinApr = BigDecimalFormatter.formatPercent( + percent = minApr, + useAbsoluteValue = true, + ).remove("%") + val formattedMaxApr = BigDecimalFormatter.formatPercent( + percent = maxApr, + useAbsoluteValue = true, + ) + + if (maxApr - minApr < EQUALITY_THRESHOLD) { + return stringReference("$formattedMinApr%") + } + return resourceReference(R.string.common_range, wrappedList(formattedMinApr, formattedMaxApr)) + } + + companion object { + private val EQUALITY_THRESHOLD = BigDecimal(1E-10) + private const val KEY_AMOUNT = "amount" + } +} \ No newline at end of file diff --git a/features/staking/impl/src/main/java/com/tangem/features/staking/impl/presentation/state/transformers/ShowInfoBottomSheetStateTransformer.kt b/features/staking/impl/src/main/java/com/tangem/features/staking/impl/presentation/state/transformers/ShowInfoBottomSheetStateTransformer.kt new file mode 100644 index 0000000000..05db6fb7ba --- /dev/null +++ b/features/staking/impl/src/main/java/com/tangem/features/staking/impl/presentation/state/transformers/ShowInfoBottomSheetStateTransformer.kt @@ -0,0 +1,53 @@ +package com.tangem.features.staking.impl.presentation.state.transformers + +import com.tangem.core.ui.components.bottomsheets.TangemBottomSheetConfig +import com.tangem.core.ui.extensions.resourceReference +import com.tangem.features.staking.impl.R +import com.tangem.features.staking.impl.presentation.state.StakingUiState +import com.tangem.features.staking.impl.presentation.state.bottomsheet.StakingInfoBottomSheetConfig +import com.tangem.utils.transformer.Transformer + +internal class ShowInfoBottomSheetStateTransformer( + private val infoType: InfoType, + private val onDismiss: () -> Unit, +) : Transformer { + + override fun transform(prevState: StakingUiState): StakingUiState { + return prevState.copy( + bottomSheetConfig = TangemBottomSheetConfig( + onDismissRequest = onDismiss, + isShow = true, + content = when (infoType) { + InfoType.APY -> StakingInfoBottomSheetConfig( + title = resourceReference(R.string.staking_details_annual_percentage_rate), + text = resourceReference(R.string.staking_details_annual_percentage_rate_info), + ) + InfoType.UNBOUNDING_PERIOD -> StakingInfoBottomSheetConfig( + title = resourceReference(R.string.staking_details_unbonding_period), + text = resourceReference(R.string.staking_details_unbonding_period_info), + ) + InfoType.REWARD_CLAIMING -> StakingInfoBottomSheetConfig( + title = resourceReference(R.string.staking_details_reward_claiming), + text = resourceReference(R.string.staking_details_reward_claiming_info), + ) + InfoType.WARMUP_PERIOD -> StakingInfoBottomSheetConfig( + title = resourceReference(R.string.staking_details_warmup_period), + text = resourceReference(R.string.staking_details_warmup_period_info), + ) + InfoType.REWARD_SCHEDULE -> StakingInfoBottomSheetConfig( + title = resourceReference(R.string.staking_details_reward_schedule), + text = resourceReference(R.string.staking_details_reward_schedule_info), + ) + }, + ), + ) + } +} + +enum class InfoType { + APY, + UNBOUNDING_PERIOD, + REWARD_CLAIMING, + WARMUP_PERIOD, + REWARD_SCHEDULE, +} \ No newline at end of file diff --git a/features/staking/impl/src/main/java/com/tangem/features/staking/impl/presentation/state/transformers/amount/AmountChangeStateTransformer.kt b/features/staking/impl/src/main/java/com/tangem/features/staking/impl/presentation/state/transformers/amount/AmountChangeStateTransformer.kt new file mode 100644 index 0000000000..110de484fc --- /dev/null +++ b/features/staking/impl/src/main/java/com/tangem/features/staking/impl/presentation/state/transformers/amount/AmountChangeStateTransformer.kt @@ -0,0 +1,18 @@ +package com.tangem.features.staking.impl.presentation.state.transformers.amount + +import com.tangem.common.ui.amountScreen.converters.field.AmountFieldChangeTransformer +import com.tangem.domain.tokens.model.CryptoCurrencyStatus +import com.tangem.features.staking.impl.presentation.state.StakingUiState +import com.tangem.utils.transformer.Transformer + +internal class AmountChangeStateTransformer( + private val cryptoCurrencyStatus: CryptoCurrencyStatus, + private val value: String, +) : Transformer { + + override fun transform(prevState: StakingUiState): StakingUiState { + return prevState.copy( + amountState = AmountFieldChangeTransformer(cryptoCurrencyStatus, value).transform(prevState.amountState), + ) + } +} \ No newline at end of file diff --git a/features/staking/impl/src/main/java/com/tangem/features/staking/impl/presentation/state/transformers/amount/AmountCurrencyChangeStateTransformer.kt b/features/staking/impl/src/main/java/com/tangem/features/staking/impl/presentation/state/transformers/amount/AmountCurrencyChangeStateTransformer.kt new file mode 100644 index 0000000000..0410bf8745 --- /dev/null +++ b/features/staking/impl/src/main/java/com/tangem/features/staking/impl/presentation/state/transformers/amount/AmountCurrencyChangeStateTransformer.kt @@ -0,0 +1,17 @@ +package com.tangem.features.staking.impl.presentation.state.transformers.amount + +import com.tangem.common.ui.amountScreen.converters.AmountCurrencyTransformer +import com.tangem.domain.tokens.model.CryptoCurrencyStatus +import com.tangem.features.staking.impl.presentation.state.StakingUiState +import com.tangem.utils.transformer.Transformer + +internal class AmountCurrencyChangeStateTransformer( + private val cryptoCurrencyStatus: CryptoCurrencyStatus, + private val value: Boolean, +) : Transformer { + override fun transform(prevState: StakingUiState): StakingUiState { + return prevState.copy( + amountState = AmountCurrencyTransformer(cryptoCurrencyStatus, value).transform(prevState.amountState), + ) + } +} \ No newline at end of file diff --git a/features/staking/impl/src/main/java/com/tangem/features/staking/impl/presentation/state/transformers/amount/AmountMaxValueStateTransformer.kt b/features/staking/impl/src/main/java/com/tangem/features/staking/impl/presentation/state/transformers/amount/AmountMaxValueStateTransformer.kt new file mode 100644 index 0000000000..3d7dc9125d --- /dev/null +++ b/features/staking/impl/src/main/java/com/tangem/features/staking/impl/presentation/state/transformers/amount/AmountMaxValueStateTransformer.kt @@ -0,0 +1,16 @@ +package com.tangem.features.staking.impl.presentation.state.transformers.amount + +import com.tangem.common.ui.amountScreen.converters.field.AmountFieldMaxAmountTransformer +import com.tangem.domain.tokens.model.CryptoCurrencyStatus +import com.tangem.features.staking.impl.presentation.state.StakingUiState +import com.tangem.utils.transformer.Transformer + +internal class AmountMaxValueStateTransformer( + private val cryptoCurrencyStatus: CryptoCurrencyStatus, +) : Transformer { + override fun transform(prevState: StakingUiState): StakingUiState { + return prevState.copy( + amountState = AmountFieldMaxAmountTransformer(cryptoCurrencyStatus).transform(prevState.amountState), + ) + } +} \ No newline at end of file diff --git a/features/staking/impl/src/main/java/com/tangem/features/staking/impl/presentation/state/transformers/amount/AmountPasteDismissStateTransformer.kt b/features/staking/impl/src/main/java/com/tangem/features/staking/impl/presentation/state/transformers/amount/AmountPasteDismissStateTransformer.kt new file mode 100644 index 0000000000..b2d7752952 --- /dev/null +++ b/features/staking/impl/src/main/java/com/tangem/features/staking/impl/presentation/state/transformers/amount/AmountPasteDismissStateTransformer.kt @@ -0,0 +1,14 @@ +package com.tangem.features.staking.impl.presentation.state.transformers.amount + +import com.tangem.common.ui.amountScreen.converters.AmountPastedTriggerDismissTransformer +import com.tangem.features.staking.impl.presentation.state.StakingUiState +import com.tangem.utils.transformer.Transformer + +internal class AmountPasteDismissStateTransformer : Transformer { + + override fun transform(prevState: StakingUiState): StakingUiState { + return prevState.copy( + amountState = AmountPastedTriggerDismissTransformer().transform(prevState.amountState), + ) + } +} \ No newline at end of file diff --git a/features/staking/impl/src/main/java/com/tangem/features/staking/impl/presentation/state/transformers/validator/ValidatorSelectChangeTransformer.kt b/features/staking/impl/src/main/java/com/tangem/features/staking/impl/presentation/state/transformers/validator/ValidatorSelectChangeTransformer.kt new file mode 100644 index 0000000000..273108e5b5 --- /dev/null +++ b/features/staking/impl/src/main/java/com/tangem/features/staking/impl/presentation/state/transformers/validator/ValidatorSelectChangeTransformer.kt @@ -0,0 +1,24 @@ +package com.tangem.features.staking.impl.presentation.state.transformers.validator + +import com.tangem.domain.staking.model.stakekit.Yield +import com.tangem.features.staking.impl.presentation.state.StakingStates +import com.tangem.features.staking.impl.presentation.state.StakingUiState +import com.tangem.features.staking.impl.presentation.state.ValidatorState +import com.tangem.utils.transformer.Transformer + +internal class ValidatorSelectChangeTransformer( + private val selectedValidator: Yield.Validator, +) : Transformer { + override fun transform(prevState: StakingUiState): StakingUiState { + val confirmationState = prevState.confirmationState as? StakingStates.ConfirmationState.Data ?: return prevState + val validatorState = confirmationState.validatorState as? ValidatorState.Content ?: return prevState + + return prevState.copy( + confirmationState = confirmationState.copy( + validatorState = validatorState.copy( + chosenValidator = selectedValidator, + ), + ), + ) + } +} \ No newline at end of file diff --git a/features/staking/impl/src/main/java/com/tangem/features/staking/impl/presentation/ui/StakingClaimRewardsValidatorContent.kt b/features/staking/impl/src/main/java/com/tangem/features/staking/impl/presentation/ui/StakingClaimRewardsValidatorContent.kt new file mode 100644 index 0000000000..64a2f51b56 --- /dev/null +++ b/features/staking/impl/src/main/java/com/tangem/features/staking/impl/presentation/ui/StakingClaimRewardsValidatorContent.kt @@ -0,0 +1,73 @@ +package com.tangem.features.staking.impl.presentation.ui + +import androidx.compose.foundation.background +import androidx.compose.foundation.clickable +import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.padding +import androidx.compose.foundation.rememberScrollState +import androidx.compose.foundation.verticalScroll +import androidx.compose.runtime.Composable +import androidx.compose.runtime.key +import androidx.compose.ui.Modifier +import androidx.compose.ui.text.SpanStyle +import androidx.compose.ui.text.buildAnnotatedString +import androidx.compose.ui.text.withStyle +import com.tangem.core.ui.components.inputrow.InputRowImageInfo +import com.tangem.core.ui.decorations.roundedShapeItemDecoration +import com.tangem.core.ui.extensions.* +import com.tangem.core.ui.res.TangemTheme +import com.tangem.core.ui.utils.BigDecimalFormatter +import com.tangem.features.staking.impl.R +import com.tangem.features.staking.impl.presentation.state.StakingStates +import com.tangem.features.staking.impl.presentation.viewmodel.StakingClickIntents +import com.tangem.utils.extensions.orZero + +@Composable +internal fun StakingClaimRewardsValidatorContent( + state: StakingStates.RewardsValidatorsState, + clickIntents: StakingClickIntents, + modifier: Modifier = Modifier, +) { + if (state !is StakingStates.RewardsValidatorsState.Data) return + Column( + modifier = Modifier // Do not put fillMaxSize() in here + .background(TangemTheme.colors.background.tertiary) + .padding(horizontal = TangemTheme.dimens.spacing12) + .verticalScroll(rememberScrollState()), + ) { + state.rewards.forEachIndexed { index, item -> + key(item.validator.address) { + InputRowImageInfo( + subtitle = stringReference(item.validator.name), + caption = combinedReference( + resourceReference(R.string.staking_details_apr), + annotatedReference( + buildAnnotatedString { + appendSpace() + withStyle(SpanStyle(color = TangemTheme.colors.text.accent)) { + append( + BigDecimalFormatter.formatPercent( + percent = item.validator.apr.orZero(), + useAbsoluteValue = true, + ), + ) + } + }, + ), + ), + infoTitle = item.fiatAmount, + infoSubtitle = item.cryptoAmount, + imageUrl = item.validator.image.orEmpty(), + modifier = modifier + .roundedShapeItemDecoration(index, state.rewards.lastIndex, false) + .background(TangemTheme.colors.background.action) + .clickable( + onClick = { + clickIntents.selectRewardValidator(item.cryptoValue) + }, + ), + ) + } + } + } +} \ No newline at end of file diff --git a/features/staking/impl/src/main/java/com/tangem/features/staking/impl/presentation/ui/StakingConfirmationContent.kt b/features/staking/impl/src/main/java/com/tangem/features/staking/impl/presentation/ui/StakingConfirmationContent.kt new file mode 100644 index 0000000000..261d4437cf --- /dev/null +++ b/features/staking/impl/src/main/java/com/tangem/features/staking/impl/presentation/ui/StakingConfirmationContent.kt @@ -0,0 +1,100 @@ +package com.tangem.features.staking.impl.presentation.ui + +import android.content.res.Configuration +import androidx.compose.animation.AnimatedVisibility +import androidx.compose.foundation.background +import androidx.compose.foundation.layout.* +import androidx.compose.foundation.rememberScrollState +import androidx.compose.foundation.verticalScroll +import androidx.compose.material3.Text +import androidx.compose.runtime.Composable +import androidx.compose.ui.Modifier +import androidx.compose.ui.text.style.TextAlign +import androidx.compose.ui.tooling.preview.Preview +import com.tangem.common.ui.amountScreen.models.AmountState +import com.tangem.common.ui.amountScreen.preview.AmountStatePreviewData +import com.tangem.common.ui.amountScreen.ui.AmountBlock +import com.tangem.core.ui.components.SpacerHMax +import com.tangem.core.ui.components.transactions.TransactionDoneTitle +import com.tangem.core.ui.res.TangemTheme +import com.tangem.core.ui.res.TangemThemePreview +import com.tangem.features.staking.impl.R +import com.tangem.features.staking.impl.presentation.state.RouteType +import com.tangem.features.staking.impl.presentation.state.StakingStates +import com.tangem.features.staking.impl.presentation.state.TransactionDoneState +import com.tangem.features.staking.impl.presentation.state.previewdata.ConfirmationStatePreviewData +import com.tangem.features.staking.impl.presentation.state.stub.StakingClickIntentsStub +import com.tangem.features.staking.impl.presentation.ui.block.NotificationsBlock +import com.tangem.features.staking.impl.presentation.ui.block.StakingFeeBlock +import com.tangem.features.staking.impl.presentation.ui.block.ValidatorBlock +import com.tangem.features.staking.impl.presentation.viewmodel.StakingClickIntents + +@Composable +internal fun StakingConfirmationContent( + amountState: AmountState, + state: StakingStates.ConfirmationState, + clickIntents: StakingClickIntents, + type: RouteType, +) { + if (state !is StakingStates.ConfirmationState.Data) return + + Column( + modifier = Modifier + .fillMaxSize() + .background(TangemTheme.colors.background.tertiary) + .padding(TangemTheme.dimens.spacing16) + .verticalScroll(rememberScrollState()), + verticalArrangement = Arrangement.spacedBy(TangemTheme.dimens.spacing16), + ) { + AnimatedVisibility( + visible = state.transactionDoneState is TransactionDoneState.Content, + modifier = Modifier.padding(vertical = TangemTheme.dimens.spacing12), + ) { + val transactionDoneStateContent = state.transactionDoneState as TransactionDoneState.Content + TransactionDoneTitle( + titleRes = R.string.sent_transaction_sent_title, + date = transactionDoneStateContent.timestamp, + ) + } + AmountBlock( + amountState = amountState, + isClickDisabled = true, + isEditingDisabled = true, + onClick = {}, + ) + if (type == RouteType.STAKE) { + ValidatorBlock(validatorState = state.validatorState, onClick = clickIntents::openValidators) + } + StakingFeeBlock(feeState = state.feeState) + NotificationsBlock(notifications = state.notifications) + SpacerHMax() + FooterText(text = state.footerText) + } +} + +@Composable +private fun FooterText(text: String) { + Text( + modifier = Modifier.fillMaxWidth(), + text = text, + color = TangemTheme.colors.text.tertiary, + style = TangemTheme.typography.caption2, + textAlign = TextAlign.Center, + ) +} + +@Preview(widthDp = 360, showBackground = true) +@Preview(widthDp = 360, showBackground = true, uiMode = Configuration.UI_MODE_NIGHT_YES) +@Composable +private fun Preview_StakingConfirmationContent() { + TangemThemePreview { + Column(Modifier.background(TangemTheme.colors.background.primary)) { + StakingConfirmationContent( + amountState = AmountStatePreviewData.amountState, + state = ConfirmationStatePreviewData.assentStakingState, + clickIntents = StakingClickIntentsStub, + type = RouteType.STAKE, + ) + } + } +} \ No newline at end of file diff --git a/features/staking/impl/src/main/java/com/tangem/features/staking/impl/presentation/ui/StakingInitialInfoContent.kt b/features/staking/impl/src/main/java/com/tangem/features/staking/impl/presentation/ui/StakingInitialInfoContent.kt new file mode 100644 index 0000000000..859bc837c1 --- /dev/null +++ b/features/staking/impl/src/main/java/com/tangem/features/staking/impl/presentation/ui/StakingInitialInfoContent.kt @@ -0,0 +1,265 @@ +package com.tangem.features.staking.impl.presentation.ui + +import android.content.res.Configuration +import androidx.compose.animation.AnimatedContent +import androidx.compose.animation.AnimatedVisibility +import androidx.compose.foundation.background +import androidx.compose.foundation.clickable +import androidx.compose.foundation.interaction.MutableInteractionSource +import androidx.compose.foundation.layout.* +import androidx.compose.foundation.shape.RoundedCornerShape +import androidx.compose.material.ripple.rememberRipple +import androidx.compose.material3.Icon +import androidx.compose.material3.Text +import androidx.compose.runtime.Composable +import androidx.compose.runtime.key +import androidx.compose.runtime.remember +import androidx.compose.ui.Alignment +import androidx.compose.ui.Modifier +import androidx.compose.ui.draw.clip +import androidx.compose.ui.res.painterResource +import androidx.compose.ui.res.stringResource +import androidx.compose.ui.tooling.preview.Preview +import androidx.compose.ui.tooling.preview.PreviewParameter +import androidx.compose.ui.tooling.preview.PreviewParameterProvider +import com.tangem.core.ui.components.containers.FooterContainer +import com.tangem.core.ui.components.inputrow.InputRowDefault +import com.tangem.core.ui.components.inputrow.InputRowImageInfo +import com.tangem.core.ui.components.list.RoundedListWithDividers +import com.tangem.core.ui.extensions.* +import com.tangem.core.ui.res.TangemTheme +import com.tangem.core.ui.res.TangemThemePreview +import com.tangem.core.ui.utils.BigDecimalFormatter +import com.tangem.features.staking.impl.R +import com.tangem.features.staking.impl.presentation.state.* +import com.tangem.features.staking.impl.presentation.state.previewdata.InitialStakingStatePreview +import com.tangem.features.staking.impl.presentation.state.stub.StakingClickIntentsStub +import com.tangem.features.staking.impl.presentation.viewmodel.StakingClickIntents +import com.tangem.utils.StringsSigns.DOT +import com.tangem.utils.StringsSigns.PLUS +import com.tangem.utils.extensions.orZero + +@Composable +internal fun StakingInitialInfoContent(state: StakingStates.InitialInfoState, clickIntents: StakingClickIntents) { + if (state !is StakingStates.InitialInfoState.Data) return + + Column( + verticalArrangement = Arrangement.spacedBy(TangemTheme.dimens.spacing12), + modifier = Modifier // Do not put fillMaxSize() in here + .background(TangemTheme.colors.background.tertiary) + .padding( + start = TangemTheme.dimens.spacing16, + end = TangemTheme.dimens.spacing16, + bottom = TangemTheme.dimens.spacing16, + ), + ) { + AnimatedVisibility(state.yieldBalance == InnerYieldBalanceState.Empty) { + MetricsBlock(state) + } + RoundedListWithDividers(state.infoItems) + AnimatedContent(targetState = state.yieldBalance, label = "Rewards block visibility animation") { + if (it is InnerYieldBalanceState.Data) { + StakingRewardBlock( + rewardCrypto = it.rewardsCrypto, + rewardFiat = it.rewardsFiat, + isRewardsToClaim = it.isRewardsToClaim, + onRewardsClick = clickIntents::openRewardsValidators, + ) + } + } + AnimatedContent(targetState = state.yieldBalance, label = "Rewards block visibility animation") { + if (it is InnerYieldBalanceState.Data) { + ActiveStakingBlock(it.balance, clickIntents::onActiveStake) + } + } + } +} + +@Composable +private fun MetricsBlock(state: StakingStates.InitialInfoState.Data) { + Column( + modifier = Modifier + .background( + color = TangemTheme.colors.background.primary, + shape = RoundedCornerShape(TangemTheme.dimens.radius12), + ) + .padding(TangemTheme.dimens.spacing12) + .fillMaxWidth(), + ) { + Text( + text = stringResource(id = R.string.staking_details_metrics_block_header), + style = TangemTheme.typography.subtitle2, + color = TangemTheme.colors.text.tertiary, + ) + Spacer(modifier = Modifier.height(TangemTheme.dimens.size8)) + Row( + modifier = Modifier.fillMaxWidth(), + horizontalArrangement = Arrangement.SpaceBetween, + ) { + Column(modifier = Modifier.weight(1F)) { + Text( + text = stringResource(id = R.string.staking_details_apr), + style = TangemTheme.typography.caption2, + color = TangemTheme.colors.text.tertiary, + ) + Text( + modifier = Modifier.padding(top = TangemTheme.dimens.spacing8), + text = state.aprRange.resolveReference(), + style = TangemTheme.typography.body1, + color = TangemTheme.colors.text.accent, + ) + } + Column(modifier = Modifier.weight(1F)) { + Row { + Text( + modifier = Modifier.padding(end = TangemTheme.dimens.spacing4), + text = stringResource(id = R.string.staking_details_market_rating), + style = TangemTheme.typography.caption2, + color = TangemTheme.colors.text.tertiary, + ) + Icon( + modifier = Modifier + .size(TangemTheme.dimens.size16) + .align(Alignment.CenterVertically), + painter = painterResource(id = R.drawable.ic_alert_24), + contentDescription = null, + tint = TangemTheme.colors.text.tertiary, + ) + } + Text( + modifier = Modifier.padding(top = TangemTheme.dimens.spacing8), + text = "1", // TODO staking + style = TangemTheme.typography.body1, + color = TangemTheme.colors.text.accent, + ) + } + } + } +} + +@Composable +private fun StakingRewardBlock( + rewardCrypto: String, + rewardFiat: String, + isRewardsToClaim: Boolean, + onRewardsClick: () -> Unit, +) { + val (text, textColor) = if (isRewardsToClaim) { + annotatedReference { + append(PLUS) + appendSpace() + append(rewardFiat) + appendSpace() + append(DOT) + appendSpace() + append(rewardCrypto) + } to TangemTheme.colors.text.primary1 + } else { + resourceReference(R.string.staking_details_no_rewards_to_claim) to TangemTheme.colors.text.tertiary + } + InputRowDefault( + title = resourceReference(R.string.staking_rewards), + text = text, + iconRes = R.drawable.ic_chevron_right_24, + textColor = textColor, + modifier = Modifier + .clip(TangemTheme.shapes.roundedCornersXMedium) + .background(TangemTheme.colors.background.action) + .clickable( + interactionSource = remember { MutableInteractionSource() }, + indication = rememberRipple(), + onClick = onRewardsClick, + ), + ) +} + +@Composable +private fun ActiveStakingBlock(groups: List, onClick: (BalanceState) -> Unit) { + Column( + verticalArrangement = Arrangement.spacedBy(TangemTheme.dimens.spacing12), + ) { + groups.forEach { group -> + key(group.title) { + FooterContainer( + footer = group.footer?.resolveReference(), + modifier = Modifier, + ) { + Column( + modifier = Modifier + .fillMaxWidth() + .clip(TangemTheme.shapes.roundedCornersXMedium) + .background(TangemTheme.colors.background.action), + ) { + group.items.forEachIndexed { index, balance -> + key(balance.validator.address) { + val caption = combinedReference( + if (group.type == BalanceGroupType.UNSTAKED) { + resourceReference(R.string.staking_details_unbonding_period) + annotatedReference { + appendSpace() + appendColored( + text = balance.unbondingPeriod.resolveReference(), + color = TangemTheme.colors.text.accent, + ) + } + } else { + resourceReference(R.string.app_name) + annotatedReference { + appendSpace() + appendColored( + text = BigDecimalFormatter.formatPercent( + percent = balance.validator.apr.orZero(), + useAbsoluteValue = true, + ), + color = TangemTheme.colors.text.accent, + ) + } + }, + ) + InputRowImageInfo( + title = group.title.takeIf { index == 0 }, + subtitle = stringReference(balance.validator.name), + caption = caption, + isGrayscaleImage = group.type == BalanceGroupType.UNSTAKED, + infoTitle = balance.fiatAmount, + infoSubtitle = balance.cryptoAmount, + imageUrl = balance.validator.image.orEmpty(), + modifier = Modifier.clickable( + interactionSource = remember { MutableInteractionSource() }, + indication = rememberRipple(), + onClick = { onClick(balance) }, + ), + ) + } + } + } + } + } + } + } +} + +// region preview + +@Preview(showBackground = true, widthDp = 360) +@Preview(showBackground = true, widthDp = 360, uiMode = Configuration.UI_MODE_NIGHT_YES) +@Composable +private fun StakingInitialInfoContent_Preview( + @PreviewParameter(StakingInitialInfoContentPreviewProvider::class) feeState: StakingStates.InitialInfoState.Data, +) { + TangemThemePreview { + StakingInitialInfoContent( + state = feeState, + clickIntents = StakingClickIntentsStub, + ) + } +} + +private class StakingInitialInfoContentPreviewProvider : PreviewParameterProvider { + override val values: Sequence + get() = sequenceOf( + InitialStakingStatePreview.defaultState, + InitialStakingStatePreview.stateWithYield, + ) +} +// endregion \ No newline at end of file diff --git a/features/staking/impl/src/main/java/com/tangem/features/staking/impl/presentation/ui/StakingNavigationButtons.kt b/features/staking/impl/src/main/java/com/tangem/features/staking/impl/presentation/ui/StakingNavigationButtons.kt new file mode 100644 index 0000000000..1ce479e4a5 --- /dev/null +++ b/features/staking/impl/src/main/java/com/tangem/features/staking/impl/presentation/ui/StakingNavigationButtons.kt @@ -0,0 +1,201 @@ +package com.tangem.features.staking.impl.presentation.ui + +import androidx.compose.animation.* +import androidx.compose.foundation.background +import androidx.compose.foundation.clickable +import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.Row +import androidx.compose.foundation.layout.fillMaxWidth +import androidx.compose.foundation.layout.padding +import androidx.compose.foundation.shape.RoundedCornerShape +import androidx.compose.material3.Icon +import androidx.compose.runtime.Composable +import androidx.compose.ui.Alignment +import androidx.compose.ui.Modifier +import androidx.compose.ui.draw.clip +import androidx.compose.ui.hapticfeedback.HapticFeedbackType +import androidx.compose.ui.platform.LocalHapticFeedback +import androidx.compose.ui.res.painterResource +import androidx.compose.ui.res.stringResource +import com.tangem.common.ui.amountScreen.ui.SendDoneButtons +import com.tangem.core.ui.R +import com.tangem.core.ui.components.SpacerW12 +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.TangemButtonsDefaults +import com.tangem.core.ui.res.TangemTheme +import com.tangem.features.staking.impl.presentation.state.* + +@Composable +internal fun StakingNavigationButtons(uiState: StakingUiState, modifier: Modifier = Modifier) { + val confirmInnerState = (uiState.confirmationState as? StakingStates.ConfirmationState.Data)?.innerState + val isSuccessState = confirmInnerState == InnerConfirmationStakingState.COMPLETED + + Column( + modifier = modifier + .padding( + start = TangemTheme.dimens.spacing16, + end = TangemTheme.dimens.spacing16, + bottom = TangemTheme.dimens.spacing16, + ), + ) { + val confirmationDataState = uiState.confirmationState as? StakingStates.ConfirmationState.Data + val transactionDoneState = confirmationDataState?.transactionDoneState as? TransactionDoneState.Content + + SendDoneButtons( + txUrl = transactionDoneState?.txUrl.orEmpty(), + onExploreClick = uiState.clickIntents::onExploreClick, + onShareClick = uiState.clickIntents::onShareClick, + isVisible = isSuccessState, + ) + StakingNavigationButton( + uiState = uiState, + modifier = Modifier, + ) + } +} + +@Composable +private fun StakingNavigationButton(uiState: StakingUiState, modifier: Modifier = Modifier) { + val hapticFeedback = LocalHapticFeedback.current + + val isButtonsVisible = isPrevButtonVisible(uiState.currentStep) + + val innerConfirmState = (uiState.confirmationState as? StakingStates.ConfirmationState.Data)?.innerState + val isInProgressInnerState = innerConfirmState == InnerConfirmationStakingState.IN_PROGRESS + val isInAssentInnerState = innerConfirmState == InnerConfirmationStakingState.ASSENT + + val showTangemIcon = uiState.currentStep == StakingStep.Confirmation && + (isInProgressInnerState || isInAssentInnerState) + + val buttonTextId = getButtonData(currentState = uiState) + val (isButtonEnabled, isButtonDisplayed) = isButtonEnabled(uiState) + val buttonIcon = if (showTangemIcon) { + TangemButtonIconPosition.End(R.drawable.ic_tangem_24) + } else { + TangemButtonIconPosition.None + } + + Row(modifier = modifier) { + AnimatedVisibility( + visible = isButtonsVisible, + enter = expandHorizontally(expandFrom = Alignment.End), + exit = shrinkHorizontally(shrinkTowards = Alignment.End), + ) { + Row { + Icon( + painter = painterResource(R.drawable.ic_back_24), + tint = TangemTheme.colors.icon.primary1, + contentDescription = null, + modifier = Modifier + .clip(RoundedCornerShape(TangemTheme.dimens.radius16)) + .background(TangemTheme.colors.button.secondary) + .clickable { uiState.clickIntents.onPrevClick() } + .padding(TangemTheme.dimens.spacing12), + ) + SpacerW12() + } + } + AnimatedVisibility( + visible = isButtonDisplayed, + enter = fadeIn(), + exit = fadeOut(), + ) { + TangemButton( + text = stringResource(buttonTextId), + icon = buttonIcon, + enabled = isButtonEnabled && isButtonDisplayed, + onClick = { + if (showTangemIcon) hapticFeedback.performHapticFeedback(HapticFeedbackType.LongPress) + onPrimaryClick(uiState) + }, + showProgress = isInProgressInnerState, + modifier = Modifier.fillMaxWidth(), + colors = TangemButtonsDefaults.primaryButtonColors, + ) + } + } +} + +private fun getButtonData(currentState: StakingUiState): Int { + return when (currentState.currentStep) { + StakingStep.InitialInfo -> { + val initialState = currentState.initialInfoState as? StakingStates.InitialInfoState.Data + if (initialState?.yieldBalance is InnerYieldBalanceState.Data) { + R.string.staking_stake_more + } else { + R.string.common_next + } + } + StakingStep.Confirmation -> { + val confirmationState = currentState.confirmationState + if (confirmationState is StakingStates.ConfirmationState.Data) { + if (confirmationState.innerState == InnerConfirmationStakingState.COMPLETED) { + R.string.common_close + } else { + R.string.common_stake + } + } else { + R.string.common_close + } + } + StakingStep.Validators -> R.string.common_continue + StakingStep.Amount, + StakingStep.RewardsValidators, + -> R.string.common_next + } +} + +private fun onPrimaryClick(currentState: StakingUiState) { + when (currentState.currentStep) { + StakingStep.InitialInfo -> { + val initialState = currentState.initialInfoState as? StakingStates.InitialInfoState.Data + if (initialState?.yieldBalance is InnerYieldBalanceState.Data) { + if (initialState.isStakeMoreAvailable) { + currentState.clickIntents.onNextClick() + } + } else { + currentState.clickIntents.onNextClick() + } + } + StakingStep.Amount -> currentState.clickIntents.onNextClick() + StakingStep.Confirmation -> { + val confirmationState = currentState.confirmationState + if (confirmationState is StakingStates.ConfirmationState.Data) { + if (confirmationState.innerState == InnerConfirmationStakingState.COMPLETED) { + currentState.clickIntents.onBackClick() + } else { + currentState.clickIntents.onNextClick() + } + } else { + currentState.clickIntents.onBackClick() + } + } + StakingStep.Validators -> currentState.clickIntents.onNextClick() + StakingStep.RewardsValidators -> Unit + } +} + +private fun isPrevButtonVisible(step: StakingStep): Boolean = when (step) { + StakingStep.InitialInfo, + StakingStep.RewardsValidators, + StakingStep.Confirmation, + -> false + StakingStep.Amount, + StakingStep.Validators, + -> true +} + +private fun isButtonEnabled(uiState: StakingUiState): Pair { + return when (uiState.currentStep) { + StakingStep.InitialInfo -> { + val initialState = uiState.initialInfoState as? StakingStates.InitialInfoState.Data + val isDisplayed = initialState?.isStakeMoreAvailable == true + uiState.initialInfoState.isPrimaryButtonEnabled to isDisplayed + } + StakingStep.Amount -> uiState.amountState.isPrimaryButtonEnabled to true + StakingStep.Confirmation -> uiState.confirmationState.isPrimaryButtonEnabled to true + StakingStep.RewardsValidators -> uiState.rewardsValidatorsState.isPrimaryButtonEnabled to false + StakingStep.Validators -> true to true + } +} \ No newline at end of file diff --git a/features/staking/impl/src/main/java/com/tangem/features/staking/impl/presentation/ui/StakingScreen.kt b/features/staking/impl/src/main/java/com/tangem/features/staking/impl/presentation/ui/StakingScreen.kt new file mode 100644 index 0000000000..c26935b80c --- /dev/null +++ b/features/staking/impl/src/main/java/com/tangem/features/staking/impl/presentation/ui/StakingScreen.kt @@ -0,0 +1,171 @@ +package com.tangem.features.staking.impl.presentation.ui + +import androidx.activity.compose.BackHandler +import androidx.compose.animation.AnimatedContent +import androidx.compose.animation.AnimatedContentTransitionScope +import androidx.compose.animation.ExperimentalAnimationApi +import androidx.compose.animation.core.tween +import androidx.compose.animation.togetherWith +import androidx.compose.foundation.background +import androidx.compose.foundation.layout.* +import androidx.compose.runtime.* +import androidx.compose.ui.Alignment +import androidx.compose.ui.Modifier +import androidx.compose.ui.res.stringResource +import com.tangem.common.ui.amountScreen.AmountScreenContent +import com.tangem.core.ui.components.appbar.AppBarWithBackButtonAndIcon +import com.tangem.core.ui.components.bottomsheets.TangemBottomSheetConfig +import com.tangem.core.ui.res.TangemTheme +import com.tangem.features.staking.impl.R +import com.tangem.features.staking.impl.presentation.state.StakingStates +import com.tangem.features.staking.impl.presentation.state.StakingStep +import com.tangem.features.staking.impl.presentation.state.StakingUiState +import com.tangem.features.staking.impl.presentation.state.bottomsheet.StakingInfoBottomSheetConfig +import com.tangem.features.staking.impl.presentation.ui.bottomsheet.StakingInfoBottomSheet +import kotlinx.coroutines.delay +import kotlinx.coroutines.flow.first +import kotlinx.coroutines.flow.map +import kotlinx.coroutines.flow.withIndex + +@Composable +internal fun StakingScreen(uiState: StakingUiState) { + BackHandler(onBack = uiState.clickIntents::onBackClick) + Column( + modifier = Modifier + .background(color = TangemTheme.colors.background.tertiary) + .fillMaxSize() + .imePadding() + .systemBarsPadding(), + horizontalAlignment = Alignment.CenterHorizontally, + ) { + SendAppBar( + uiState = uiState, + ) + StakingScreenContent( + uiState = uiState, + modifier = Modifier.weight(1f), + ) + StakingNavigationButtons( + uiState = uiState, + ) + StakingBottomSheet(bottomSheetConfig = uiState.bottomSheetConfig) + } +} + +@Composable +fun StakingBottomSheet(bottomSheetConfig: TangemBottomSheetConfig?) { + if (bottomSheetConfig == null) return + when (bottomSheetConfig.content) { + is StakingInfoBottomSheetConfig -> StakingInfoBottomSheet(bottomSheetConfig) + } +} + +@Composable +private fun SendAppBar(uiState: StakingUiState) { + val titleRes = when (uiState.currentStep) { + StakingStep.Amount -> stringResource(id = R.string.send_amount_label) + StakingStep.InitialInfo, + StakingStep.RewardsValidators, + StakingStep.Validators, + StakingStep.Confirmation, + -> stringResource(id = R.string.common_stake) + } + val backIcon = when (uiState.currentStep) { + StakingStep.Amount, + StakingStep.Validators, + StakingStep.Confirmation, + -> { + R.drawable.ic_close_24 + } + StakingStep.RewardsValidators, + StakingStep.InitialInfo, + -> { + R.drawable.ic_back_24 + } + } + AppBarWithBackButtonAndIcon( + text = titleRes, + backIconRes = backIcon, + onBackClick = uiState.clickIntents::onBackClick, + backgroundColor = TangemTheme.colors.background.tertiary, + modifier = Modifier.height(TangemTheme.dimens.size56), + ) +} + +@OptIn(ExperimentalAnimationApi::class) +@Composable +private fun StakingScreenContent(uiState: StakingUiState, modifier: Modifier = Modifier) { + val currentScreen = uiState.currentStep + var currentStateProxy by remember { mutableStateOf(currentScreen) } + var isTransitionAnimationRunning by remember { mutableStateOf(false) } + + // Prevent quick screen changes to avoid some of the transition animation distortions + LaunchedEffect(currentScreen) { + snapshotFlow { isTransitionAnimationRunning } + .withIndex() + .map { (index, running) -> + if (running && index != 0) { + delay(timeMillis = 200) + } + running + } + .first { !it } + + currentStateProxy = currentScreen + } + // Restrict pressing the back button while screen transition is running to avoid most of the animation distortions + BackHandler(enabled = isTransitionAnimationRunning) {} + + // Box is needed to fix animation with resizing of AnimatedContent + Box(modifier = modifier.fillMaxSize()) { + AnimatedContent( + targetState = currentStateProxy, + contentAlignment = Alignment.TopCenter, + label = "Staking Screen Navigation", + transitionSpec = { + val direction = if (initialState.ordinal < targetState.ordinal) { + AnimatedContentTransitionScope.SlideDirection.Start + } else { + AnimatedContentTransitionScope.SlideDirection.End + } + + slideIntoContainer(towards = direction, animationSpec = tween()) + .togetherWith(slideOutOfContainer(towards = direction, animationSpec = tween())) + }, + ) { state -> + isTransitionAnimationRunning = transition.targetState != transition.currentState + + when (state) { + StakingStep.InitialInfo -> StakingInitialInfoContent( + state = uiState.initialInfoState, + clickIntents = uiState.clickIntents, + ) + StakingStep.RewardsValidators -> { + StakingClaimRewardsValidatorContent( + state = uiState.rewardsValidatorsState, + clickIntents = uiState.clickIntents, + ) + } + StakingStep.Amount -> AmountScreenContent( + amountState = uiState.amountState, + isBalanceHiding = uiState.isBalanceHidden, + clickIntents = uiState.clickIntents, + ) + StakingStep.Confirmation -> StakingConfirmationContent( + amountState = uiState.amountState, + state = uiState.confirmationState, + clickIntents = uiState.clickIntents, + type = uiState.routeType, + ) + StakingStep.Validators -> { + val confirmState = uiState.confirmationState + if (confirmState !is StakingStates.ConfirmationState.Data) return@AnimatedContent + StakingValidatorListContent( + state = confirmState.validatorState, + clickIntents = uiState.clickIntents, + ) + } + } + } + } +} \ No newline at end of file diff --git a/features/staking/impl/src/main/java/com/tangem/features/staking/impl/presentation/ui/StakingValidatorListContent.kt b/features/staking/impl/src/main/java/com/tangem/features/staking/impl/presentation/ui/StakingValidatorListContent.kt new file mode 100644 index 0000000000..743979fa67 --- /dev/null +++ b/features/staking/impl/src/main/java/com/tangem/features/staking/impl/presentation/ui/StakingValidatorListContent.kt @@ -0,0 +1,129 @@ +package com.tangem.features.staking.impl.presentation.ui + +import android.content.res.Configuration +import androidx.compose.foundation.background +import androidx.compose.foundation.layout.* +import androidx.compose.foundation.lazy.LazyColumn +import androidx.compose.material3.Text +import androidx.compose.runtime.Composable +import androidx.compose.ui.Modifier +import androidx.compose.ui.draw.clip +import androidx.compose.ui.platform.LocalDensity +import androidx.compose.ui.res.stringResource +import androidx.compose.ui.text.SpanStyle +import androidx.compose.ui.text.buildAnnotatedString +import androidx.compose.ui.text.withStyle +import androidx.compose.ui.tooling.preview.Preview +import androidx.compose.ui.tooling.preview.PreviewParameter +import androidx.compose.ui.tooling.preview.PreviewParameterProvider +import com.tangem.core.ui.components.inputrow.InputRowImageSelector +import com.tangem.core.ui.components.rows.CornersToRound +import com.tangem.core.ui.extensions.annotatedReference +import com.tangem.core.ui.extensions.combinedReference +import com.tangem.core.ui.extensions.resourceReference +import com.tangem.core.ui.extensions.stringReference +import com.tangem.core.ui.res.TangemTheme +import com.tangem.core.ui.res.TangemThemePreview +import com.tangem.core.ui.utils.BigDecimalFormatter +import com.tangem.features.staking.impl.R +import com.tangem.features.staking.impl.presentation.state.ValidatorState +import com.tangem.features.staking.impl.presentation.state.previewdata.ConfirmationStatePreviewData +import com.tangem.features.staking.impl.presentation.state.stub.StakingClickIntentsStub +import com.tangem.features.staking.impl.presentation.viewmodel.StakingClickIntents +import java.math.BigDecimal + +/** + * Staking screen with validators + */ +@Composable +internal fun StakingValidatorListContent( + state: ValidatorState, + clickIntents: StakingClickIntents, + modifier: Modifier = Modifier, +) { + val bottomBarHeight = with(LocalDensity.current) { WindowInsets.systemBars.getBottom(this).toDp() } + + LazyColumn( + contentPadding = PaddingValues(bottom = bottomBarHeight), + modifier = modifier.padding(horizontal = TangemTheme.dimens.spacing16), + ) { + item(key = "HEADER") { + Text( + text = stringResource(R.string.staking_validator), + style = TangemTheme.typography.subtitle2, + color = TangemTheme.colors.text.tertiary, + modifier = Modifier + .fillMaxWidth() + .clip(CornersToRound.TOP_2.getShape()) + .background(TangemTheme.colors.background.action) + .padding( + start = TangemTheme.dimens.spacing12, + end = TangemTheme.dimens.spacing12, + top = TangemTheme.dimens.spacing12, + bottom = TangemTheme.dimens.spacing8, + ), + ) + } + if (state is ValidatorState.Content) { + val validators = state.availableValidators + items( + count = validators.size, + key = { validators[it].address }, + contentType = { validators[it]::class.java }, + ) { index -> + val item = validators[index] + + InputRowImageSelector( + subtitle = stringReference(item.name), + caption = combinedReference( + resourceReference(R.string.staking_details_apr), + annotatedReference( + buildAnnotatedString { + append(" ") + withStyle(style = SpanStyle(color = TangemTheme.colors.text.accent)) { + append( + BigDecimalFormatter.formatPercent(item.apr ?: BigDecimal.ZERO, true), + ) + } + }, + ), + ), + imageUrl = item.image.orEmpty(), + isSelected = item == state.chosenValidator, + onSelect = { clickIntents.onValidatorSelect(item) }, + modifier = Modifier + .clip( + if (index == validators.lastIndex) { + CornersToRound.BOTTOM_2 + } else { + CornersToRound.ZERO + }.getShape(), + ) + .background(TangemTheme.colors.background.action), + ) + } + } + } +} + +// region Preview +@Preview(showBackground = true, widthDp = 360) +@Preview(showBackground = true, widthDp = 360, uiMode = Configuration.UI_MODE_NIGHT_YES) +@Composable +private fun StakingValidatorListContent_Preview( + @PreviewParameter(StakingValidatorListContentPreviewProvider::class) + data: ValidatorState, +) { + TangemThemePreview { + StakingValidatorListContent( + state = data, + clickIntents = StakingClickIntentsStub, + ) + } +} + +private class StakingValidatorListContentPreviewProvider : PreviewParameterProvider { + override val values: Sequence + get() = sequenceOf(ConfirmationStatePreviewData.assentStakingState.validatorState) +} +// endregion \ No newline at end of file diff --git a/features/staking/impl/src/main/java/com/tangem/features/staking/impl/presentation/ui/block/NotificationsBlock.kt b/features/staking/impl/src/main/java/com/tangem/features/staking/impl/presentation/ui/block/NotificationsBlock.kt new file mode 100644 index 0000000000..68d638aaaa --- /dev/null +++ b/features/staking/impl/src/main/java/com/tangem/features/staking/impl/presentation/ui/block/NotificationsBlock.kt @@ -0,0 +1,13 @@ +package com.tangem.features.staking.impl.presentation.ui.block + +import androidx.compose.runtime.Composable +import com.tangem.core.ui.components.notifications.Notification +import com.tangem.core.ui.res.TangemTheme +import com.tangem.features.staking.impl.presentation.state.StakingNotification + +@Composable +internal fun NotificationsBlock(notifications: List) { + notifications.forEach { + Notification(config = it.config, iconTint = TangemTheme.colors.icon.accent) + } +} \ No newline at end of file diff --git a/features/staking/impl/src/main/java/com/tangem/features/staking/impl/presentation/ui/block/StakingFeeBlock.kt b/features/staking/impl/src/main/java/com/tangem/features/staking/impl/presentation/ui/block/StakingFeeBlock.kt new file mode 100644 index 0000000000..4dff5385fb --- /dev/null +++ b/features/staking/impl/src/main/java/com/tangem/features/staking/impl/presentation/ui/block/StakingFeeBlock.kt @@ -0,0 +1,153 @@ +package com.tangem.features.staking.impl.presentation.ui.block + +import android.content.res.Configuration +import androidx.compose.animation.AnimatedContent +import androidx.compose.foundation.background +import androidx.compose.foundation.layout.* +import androidx.compose.material3.Text +import androidx.compose.runtime.Composable +import androidx.compose.ui.Alignment +import androidx.compose.ui.Modifier +import androidx.compose.ui.draw.clip +import androidx.compose.ui.res.stringResource +import androidx.compose.ui.tooling.preview.Preview +import androidx.compose.ui.tooling.preview.PreviewParameter +import androidx.compose.ui.tooling.preview.PreviewParameterProvider +import com.tangem.blockchain.common.Amount +import com.tangem.blockchain.common.AmountType +import com.tangem.blockchain.common.transaction.Fee +import com.tangem.core.ui.components.RectangleShimmer +import com.tangem.core.ui.components.rows.SelectorRowItem +import com.tangem.core.ui.res.TangemThemePreview +import com.tangem.core.ui.res.TangemTheme +import com.tangem.core.ui.utils.BigDecimalFormatter +import com.tangem.common.ui.R +import com.tangem.common.ui.amountScreen.utils.getCryptoReference +import com.tangem.common.ui.amountScreen.utils.getFiatReference +import com.tangem.domain.appcurrency.model.AppCurrency +import com.tangem.features.staking.impl.presentation.state.FeeState +import java.math.BigDecimal + +@Composable +internal fun StakingFeeBlock(feeState: FeeState) { + Column( + modifier = Modifier + .fillMaxWidth() + .clip(TangemTheme.shapes.roundedCornersXMedium) + .background(TangemTheme.colors.background.action) + .padding(TangemTheme.dimens.spacing12), + ) { + Text( + text = stringResource(R.string.common_network_fee_title), + style = TangemTheme.typography.caption2, + color = TangemTheme.colors.text.secondary, + ) + + Box( + modifier = Modifier.padding(top = TangemTheme.dimens.spacing8), + ) { + when (feeState) { + is FeeState.Content -> { + val feeAmount = feeState.fee?.amount + val (title, icon) = R.string.common_fee_selector_option_market to R.drawable.ic_bird_24 + SelectorRowItem( + titleRes = title, + iconRes = icon, + preDot = getCryptoReference(feeAmount, feeState.isFeeApproximate), + postDot = if (feeState.isFeeConvertibleToFiat) { + getFiatReference(feeAmount?.value, feeState.rate, feeState.appCurrency) + } else { + null + }, + ellipsizeOffset = feeAmount?.currencySymbol?.length, + isSelected = true, + showDivider = false, + showSelectedAppearance = false, + paddingValues = PaddingValues(), + ) + } + is FeeState.Loading -> { + FeeLoading(feeState) + } + is FeeState.Error -> { + FeeError(feeState) + } + } + } + } +} + +@Composable +private fun BoxScope.FeeLoading(feeState: FeeState) { + AnimatedContent( + targetState = feeState, + label = "Fee Loading State Change", + modifier = Modifier.align(Alignment.CenterEnd), + ) { + if (it == FeeState.Loading) { + RectangleShimmer( + radius = TangemTheme.dimens.radius3, + modifier = Modifier.size( + height = TangemTheme.dimens.size12, + width = TangemTheme.dimens.size90, + ), + ) + } + } +} + +@Composable +private fun BoxScope.FeeError(feeState: FeeState) { + AnimatedContent( + targetState = feeState, + label = "Fee Error State Change", + modifier = Modifier.align(Alignment.CenterEnd), + ) { + if (it == FeeState.Error) { + Text( + text = BigDecimalFormatter.EMPTY_BALANCE_SIGN, + color = TangemTheme.colors.text.primary1, + style = TangemTheme.typography.body2, + ) + } + } +} + +// region Preview +@Preview +@Preview(uiMode = Configuration.UI_MODE_NIGHT_YES) +@Composable +private fun FeeBlockPreview(@PreviewParameter(FeeBlockPreviewProvider::class) value: FeeState.Content) { + TangemThemePreview { + StakingFeeBlock( + feeState = value, + ) + } +} + +private class FeeBlockPreviewProvider : PreviewParameterProvider { + + override val values: Sequence + get() = sequenceOf( + feeState, + ) + + private val fee = Fee.Common( + amount = Amount( + currencySymbol = "MATIC", + value = BigDecimal(0.159806), + decimals = 18, + type = AmountType.Coin, + ), + ) + + private val feeState = FeeState.Content( + fee = fee, + rate = BigDecimal.ONE, + appCurrency = AppCurrency.Default, + isFeeApproximate = false, + isFeeConvertibleToFiat = true, + ) +} + +// endregion \ No newline at end of file diff --git a/features/staking/impl/src/main/java/com/tangem/features/staking/impl/presentation/ui/block/ValidatorBlock.kt b/features/staking/impl/src/main/java/com/tangem/features/staking/impl/presentation/ui/block/ValidatorBlock.kt new file mode 100644 index 0000000000..ffd1d0c966 --- /dev/null +++ b/features/staking/impl/src/main/java/com/tangem/features/staking/impl/presentation/ui/block/ValidatorBlock.kt @@ -0,0 +1,71 @@ +package com.tangem.features.staking.impl.presentation.ui.block + +import androidx.compose.foundation.background +import androidx.compose.foundation.clickable +import androidx.compose.foundation.interaction.MutableInteractionSource +import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.fillMaxWidth +import androidx.compose.foundation.layout.padding +import androidx.compose.material.ripple.rememberRipple +import androidx.compose.material3.Text +import androidx.compose.runtime.Composable +import androidx.compose.runtime.remember +import androidx.compose.ui.Modifier +import androidx.compose.ui.draw.clip +import androidx.compose.ui.res.stringResource +import androidx.compose.ui.text.SpanStyle +import androidx.compose.ui.text.buildAnnotatedString +import androidx.compose.ui.text.withStyle +import com.tangem.core.ui.components.inputrow.InputRowImageChevron +import com.tangem.core.ui.extensions.annotatedReference +import com.tangem.core.ui.extensions.combinedReference +import com.tangem.core.ui.extensions.resourceReference +import com.tangem.core.ui.extensions.stringReference +import com.tangem.core.ui.res.TangemTheme +import com.tangem.core.ui.utils.BigDecimalFormatter +import com.tangem.features.staking.impl.R +import com.tangem.features.staking.impl.presentation.state.ValidatorState +import java.math.BigDecimal + +@Composable +internal fun ValidatorBlock(validatorState: ValidatorState, onClick: () -> Unit) { + Column( + modifier = Modifier + .fillMaxWidth() + .clip(TangemTheme.shapes.roundedCornersXMedium) + .background(TangemTheme.colors.background.action) + .clickable( + enabled = validatorState.isClickable, + interactionSource = remember { MutableInteractionSource() }, + indication = rememberRipple(), + onClick = onClick, + ) + .padding(TangemTheme.dimens.spacing12), + ) { + Text( + text = stringResource(R.string.staking_validator), + style = TangemTheme.typography.subtitle2, + color = TangemTheme.colors.text.tertiary, + modifier = Modifier.padding(bottom = TangemTheme.dimens.spacing6), + ) + if (validatorState is ValidatorState.Content) { + InputRowImageChevron( + subtitle = stringReference(validatorState.chosenValidator.name), + caption = combinedReference( + resourceReference(R.string.staking_details_apr), + annotatedReference( + buildAnnotatedString { + append(" ") + withStyle(SpanStyle(color = TangemTheme.colors.text.accent)) { + val apr = validatorState.chosenValidator.apr ?: BigDecimal.ZERO + append(BigDecimalFormatter.formatPercent(apr, true)) + } + }, + ), + ), + imageUrl = validatorState.chosenValidator.image.orEmpty(), + showChevron = validatorState.isClickable, + ) + } + } +} \ No newline at end of file diff --git a/features/staking/impl/src/main/java/com/tangem/features/staking/impl/presentation/ui/bottomsheet/StakingInfoBottomSheet.kt b/features/staking/impl/src/main/java/com/tangem/features/staking/impl/presentation/ui/bottomsheet/StakingInfoBottomSheet.kt new file mode 100644 index 0000000000..6e0b80bd18 --- /dev/null +++ b/features/staking/impl/src/main/java/com/tangem/features/staking/impl/presentation/ui/bottomsheet/StakingInfoBottomSheet.kt @@ -0,0 +1,74 @@ +package com.tangem.features.staking.impl.presentation.ui.bottomsheet + +import android.content.res.Configuration +import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.padding +import androidx.compose.foundation.rememberScrollState +import androidx.compose.foundation.verticalScroll +import androidx.compose.material3.Text +import androidx.compose.runtime.Composable +import androidx.compose.ui.Modifier +import androidx.compose.ui.tooling.preview.Preview +import com.tangem.core.ui.components.bottomsheets.TangemBottomSheet +import com.tangem.core.ui.components.bottomsheets.TangemBottomSheetConfig +import com.tangem.core.ui.components.bottomsheets.TangemBottomSheetTitle +import com.tangem.core.ui.extensions.resolveReference +import com.tangem.core.ui.extensions.stringReference +import com.tangem.core.ui.res.TangemTheme +import com.tangem.core.ui.res.TangemThemePreview +import com.tangem.features.staking.impl.presentation.state.bottomsheet.StakingInfoBottomSheetConfig + +@Composable +fun StakingInfoBottomSheet(config: TangemBottomSheetConfig) { + val scrollState = rememberScrollState() + + TangemBottomSheet( + config = config, + title = { content -> + TangemBottomSheetTitle(title = content.title) + }, + ) { content -> + Column( + modifier = Modifier.verticalScroll(scrollState), + ) { + Text( + text = content.text.resolveReference(), + color = TangemTheme.colors.text.secondary, + style = TangemTheme.typography.body2, + modifier = Modifier.padding( + horizontal = TangemTheme.dimens.spacing28, + vertical = TangemTheme.dimens.spacing16, + ), + ) + } + } +} + +// region Preview +@Composable +@Preview(showBackground = true) +@Preview(showBackground = true, uiMode = Configuration.UI_MODE_NIGHT_YES) +private fun Preview_StakingInfoBottomSheet() { + TangemThemePreview { + StakingInfoBottomSheet( + config = TangemBottomSheetConfig( + isShow = true, + onDismissRequest = {}, + content = StakingInfoBottomSheetConfig( + title = stringReference("Title"), + text = stringReference( + """ + Lorem ipsum dolor sit amet, consectetur adipiscing elit. Fusce varius neque vel ligula + tincidunt, nec faucibus nulla ultricies. Maecenas euismod arcu in nunc volutpat, + at bibendum eros lacinia. Proin hendrerit massa non velit congue, + in volutpat nisi consequat. Sed vitae justo nec orci tincidunt malesuada. + Nullam feugiat purus vel lectus efficitur, vel fringilla urna volutpat. + Donec sagittis enim in metus lacinia, vel tempor nunc bibendum. + """.trimIndent(), + ), + ), + ), + ) + } +} +// endregion Preview \ No newline at end of file diff --git a/features/staking/impl/src/main/java/com/tangem/features/staking/impl/presentation/viewmodel/StakingClickIntents.kt b/features/staking/impl/src/main/java/com/tangem/features/staking/impl/presentation/viewmodel/StakingClickIntents.kt new file mode 100644 index 0000000000..8302d36d14 --- /dev/null +++ b/features/staking/impl/src/main/java/com/tangem/features/staking/impl/presentation/viewmodel/StakingClickIntents.kt @@ -0,0 +1,36 @@ +package com.tangem.features.staking.impl.presentation.viewmodel + +import com.tangem.common.ui.amountScreen.AmountScreenClickIntents +import com.tangem.domain.staking.model.stakekit.PendingAction +import com.tangem.domain.staking.model.stakekit.Yield +import com.tangem.features.staking.impl.presentation.state.BalanceState +import com.tangem.features.staking.impl.presentation.state.transformers.InfoType +import kotlinx.collections.immutable.ImmutableList +import kotlinx.collections.immutable.persistentListOf + +internal interface StakingClickIntents : AmountScreenClickIntents { + + fun onBackClick() + + fun onNextClick(pendingActions: ImmutableList = persistentListOf()) + + fun onPrevClick() + + fun onInfoClick(infoType: InfoType) + + override fun onAmountNext() = onNextClick() + + fun openValidators() + + fun onValidatorSelect(validator: Yield.Validator) + + fun openRewardsValidators() + + fun selectRewardValidator(rewardValue: String) + + fun onActiveStake(activeStake: BalanceState) + + fun onExploreClick() + + fun onShareClick() +} \ No newline at end of file diff --git a/features/staking/impl/src/main/java/com/tangem/features/staking/impl/presentation/viewmodel/StakingViewModel.kt b/features/staking/impl/src/main/java/com/tangem/features/staking/impl/presentation/viewmodel/StakingViewModel.kt new file mode 100644 index 0000000000..1aa55e58c3 --- /dev/null +++ b/features/staking/impl/src/main/java/com/tangem/features/staking/impl/presentation/viewmodel/StakingViewModel.kt @@ -0,0 +1,387 @@ +package com.tangem.features.staking.impl.presentation.viewmodel + +import android.os.Bundle +import androidx.lifecycle.DefaultLifecycleObserver +import androidx.lifecycle.SavedStateHandle +import androidx.lifecycle.ViewModel +import androidx.lifecycle.viewModelScope +import arrow.core.getOrElse +import com.tangem.blockchain.common.TransactionData +import com.tangem.common.extensions.hexToBytes +import com.tangem.common.routing.AppRoute +import com.tangem.common.routing.bundle.unbundle +import com.tangem.common.ui.amountScreen.models.AmountState +import com.tangem.domain.appcurrency.GetSelectedAppCurrencyUseCase +import com.tangem.domain.appcurrency.model.AppCurrency +import com.tangem.domain.balancehiding.GetBalanceHidingSettingsUseCase +import com.tangem.domain.staking.* +import com.tangem.domain.staking.model.stakekit.PendingAction +import com.tangem.domain.staking.model.stakekit.Yield +import com.tangem.domain.staking.model.stakekit.action.StakingActionCommonType +import com.tangem.domain.staking.model.stakekit.transaction.ActionParams +import com.tangem.domain.staking.model.stakekit.transaction.StakingGasEstimate +import com.tangem.domain.tokens.GetCryptoCurrencyStatusSyncUseCase +import com.tangem.domain.tokens.model.CryptoCurrency +import com.tangem.domain.tokens.model.CryptoCurrencyStatus +import com.tangem.domain.transaction.usecase.SendTransactionUseCase +import com.tangem.domain.txhistory.usecase.GetExplorerTransactionUrlUseCase +import com.tangem.domain.wallets.models.UserWallet +import com.tangem.domain.wallets.models.UserWalletId +import com.tangem.domain.wallets.usecase.GetUserWalletUseCase +import com.tangem.features.staking.impl.navigation.InnerStakingRouter +import com.tangem.features.staking.impl.presentation.state.* +import com.tangem.features.staking.impl.presentation.state.transformers.* +import com.tangem.features.staking.impl.presentation.state.transformers.amount.AmountChangeStateTransformer +import com.tangem.features.staking.impl.presentation.state.transformers.amount.AmountCurrencyChangeStateTransformer +import com.tangem.features.staking.impl.presentation.state.transformers.amount.AmountMaxValueStateTransformer +import com.tangem.features.staking.impl.presentation.state.transformers.amount.AmountPasteDismissStateTransformer +import com.tangem.features.staking.impl.presentation.state.transformers.validator.ValidatorSelectChangeTransformer +import com.tangem.utils.Provider +import com.tangem.utils.coroutines.CoroutineDispatcherProvider +import dagger.hilt.android.lifecycle.HiltViewModel +import kotlinx.collections.immutable.ImmutableList +import kotlinx.coroutines.flow.* +import kotlinx.coroutines.launch +import timber.log.Timber +import javax.inject.Inject +import kotlin.properties.Delegates + +@Suppress("LargeClass", "LongParameterList") +@HiltViewModel +internal class StakingViewModel @Inject constructor( + private val stateController: StakingStateController, + private val dispatchers: CoroutineDispatcherProvider, + private val getBalanceHidingSettingsUseCase: GetBalanceHidingSettingsUseCase, + private val getCryptoCurrencyStatusSyncUseCase: GetCryptoCurrencyStatusSyncUseCase, + private val getSelectedAppCurrencyUseCase: GetSelectedAppCurrencyUseCase, + private val getUserWalletUseCase: GetUserWalletUseCase, + private val getStakingTransactionUseCase: GetStakingTransactionUseCase, + private val estimateGasUseCase: EstimateGasUseCase, + private val sendTransactionUseCase: SendTransactionUseCase, + private val getExplorerTransactionUrlUseCase: GetExplorerTransactionUrlUseCase, + private val saveUnsubmittedHashUseCase: SaveUnsubmittedHashUseCase, + private val submitHashUseCase: SubmitHashUseCase, + private val isStakeMoreAvailableUseCase: IsStakeMoreAvailableUseCase, + savedStateHandle: SavedStateHandle, +) : ViewModel(), DefaultLifecycleObserver, StakingClickIntents { + + val uiState: StateFlow = stateController.uiState + val value: StakingUiState get() = uiState.value + + var stakingStateRouter: StakingStateRouter by Delegates.notNull() + private set + + private val cryptoCurrencyId: CryptoCurrency.ID = + savedStateHandle.get(AppRoute.Staking.CRYPTO_CURRENCY_ID_KEY) + ?.unbundle(CryptoCurrency.ID.serializer()) + ?: error("This screen can't be opened without `CryptoCurrency.ID`") + + private val userWalletId: UserWalletId = savedStateHandle.get(AppRoute.Staking.USER_WALLET_ID_KEY) + ?.unbundle(UserWalletId.serializer()) + ?: error("This screen can't be opened without `UserWalletId`") + + private val yield: Yield = savedStateHandle.get(AppRoute.Staking.YIELD_KEY) + ?.unbundle(Yield.serializer()) + ?: error("This screen can't be opened without `Yield`") + + private var cryptoCurrencyStatus: CryptoCurrencyStatus by Delegates.notNull() + + private var innerRouter: InnerStakingRouter by Delegates.notNull() + private var userWallet: UserWallet by Delegates.notNull() + private var appCurrency: AppCurrency by Delegates.notNull() + + init { + subscribeOnSelectedAppCurrency() + subscribeOnBalanceHiding() + subscribeOnCurrencyStatusUpdates() + } + + override fun onBackClick() { + stakingStateRouter.onBackClick() + } + + override fun onNextClick(pendingActions: ImmutableList) { + handleOnNextConfirmationClick() + stakingStateRouter.onNextClick() + if (isAssentState()) { + estimateGas(pendingActions) + } + } + + private fun handleOnNextConfirmationClick() { + if (isAssentState()) { + viewModelScope.launch { + stateController.update(SetConfirmationStateInProgressTransformer()) + + val confirmationState = + value.confirmationState as? StakingStates.ConfirmationState.Data ?: error("No confirmation state") + val validatorState = confirmationState.validatorState as? ValidatorState.Content + ?: error("No validator provided") + val pendingActions = confirmationState.pendingActions + + val stakingTransaction = getStakingTransactionUseCase( + params = ActionParams( + actionCommonType = getStakingCommonType(), + integrationId = yield.id, + amount = (value.amountState as? AmountState.Data)?.amountTextField?.cryptoAmount?.value + ?: error("No amount provided"), + address = cryptoCurrencyStatus.value.networkAddress?.defaultAddress?.value + ?: error("No available address"), + validatorAddress = validatorState.chosenValidator.address, + token = yield.token, + passthrough = pendingActions.firstOrNull()?.passthrough, + type = pendingActions.firstOrNull()?.type, + ), + ).getOrElse { + error(it) + } + + stakingTransaction.unsignedTransaction?.let { + sendStakingTransaction( + transactionId = stakingTransaction.id, + gasEstimate = stakingTransaction.gasEstimate ?: error("No gas estimate available"), + txData = TransactionData.Compiled(value = it.hexToBytes()), + pendingActions = pendingActions, + ) + } ?: error("No unsigned transaction available") + } + } + } + + private fun estimateGas(pendingActions: ImmutableList) { + viewModelScope.launch { + stateController.update( + SetConfirmationStateLoadingTransformer( + yield = yield, + ), + ) + val cryptoCurrencyValue = cryptoCurrencyStatus.value + + val stakingGasEstimate = estimateGasUseCase( + params = ActionParams( + actionCommonType = getStakingCommonType(), + integrationId = yield.id, + amount = (value.amountState as? AmountState.Data)?.amountTextField?.cryptoAmount?.value + ?: error("No amount provided"), + address = cryptoCurrencyValue.networkAddress?.defaultAddress?.value + ?: error("No available address"), + validatorAddress = yield.validators.getOrNull(0)?.address ?: error("No available validator"), + token = yield.token, + passthrough = pendingActions.firstOrNull()?.passthrough, + type = pendingActions.firstOrNull()?.type, + ), + ).getOrElse { error("Can't get fee info") } + + stateController.update( + SetConfirmationStateAssentTransformer( + appCurrencyProvider = Provider { appCurrency }, + cryptoCurrencyStatusProvider = Provider { cryptoCurrencyStatus }, + stakingGasEstimate = stakingGasEstimate, + pendingActionList = pendingActions, + ), + ) + } + } + + override fun onPrevClick() { + stakingStateRouter.onPrevClick() + } + + override fun onInfoClick(infoType: InfoType) { + stateController.update( + ShowInfoBottomSheetStateTransformer(infoType) { + stateController.update(DismissBottomSheetStateTransformer()) + }, + ) + } + + override fun onAmountValueChange(value: String) { + stateController.update(AmountChangeStateTransformer(cryptoCurrencyStatus, value)) + } + + override fun onAmountPasteTriggerDismiss() { + stateController.update(AmountPasteDismissStateTransformer()) + } + + override fun onMaxValueClick() { + stateController.update(AmountMaxValueStateTransformer(cryptoCurrencyStatus)) + } + + override fun onCurrencyChangeClick(isFiat: Boolean) { + stateController.update(AmountCurrencyChangeStateTransformer(cryptoCurrencyStatus, isFiat)) + } + + override fun openValidators() = stakingStateRouter.showValidators() + + override fun onValidatorSelect(validator: Yield.Validator) { + stateController.update(ValidatorSelectChangeTransformer(validator)) + } + + override fun openRewardsValidators() { + stateController.update { it.copy(routeType = RouteType.CLAIM) } + onNextClick() + } + + override fun selectRewardValidator(rewardValue: String) { + stateController.update(AmountChangeStateTransformer(cryptoCurrencyStatus, rewardValue)) + onNextClick() + } + + override fun onActiveStake(activeStake: BalanceState) { + val routeType = if (activeStake.pendingActions.isEmpty()) { + RouteType.UNSTAKE + } else { + RouteType.OTHER + } + stateController.update { it.copy(routeType = routeType) } + stateController.update(AmountChangeStateTransformer(cryptoCurrencyStatus, activeStake.cryptoValue)) + onNextClick(activeStake.pendingActions) + } + + override fun onExploreClick() { + val confirmationDataState = uiState.value.confirmationState as? StakingStates.ConfirmationState.Data + val transactionDoneState = confirmationDataState?.transactionDoneState as? TransactionDoneState.Content + val txUrl = transactionDoneState?.txUrl + + if (txUrl != null) { + innerRouter.openUrl(txUrl) + } + } + + override fun onShareClick() { + // TODO staking analytics event + } + + fun setRouter(router: InnerStakingRouter, stateRouter: StakingStateRouter) { + innerRouter = router + this.stakingStateRouter = stateRouter + } + + private fun subscribeOnCurrencyStatusUpdates() { + viewModelScope.launch { + getUserWalletUseCase(userWalletId).fold( + ifRight = { wallet -> + userWallet = wallet + }, + ifLeft = { + // TODO staking error + }, + ) + getCryptoCurrencyStatusSyncUseCase(userWalletId, cryptoCurrencyId).fold( + ifRight = { + cryptoCurrencyStatus = it + + val networkId = cryptoCurrencyStatus.currency.network.id + val isStakeMoreAvailable = isStakeMoreAvailableUseCase(networkId) + stateController.update( + transformer = SetInitialDataStateTransformer( + clickIntents = this@StakingViewModel, + yield = yield, + isStakeMoreAvailable = isStakeMoreAvailable.getOrElse { false }, + cryptoCurrencyStatusProvider = Provider { cryptoCurrencyStatus }, + userWalletProvider = Provider { userWallet }, + appCurrencyProvider = Provider { appCurrency }, + ), + ) + }, + ifLeft = { + // TODO staking error + }, + ) + } + } + + private fun subscribeOnBalanceHiding() { + getBalanceHidingSettingsUseCase() + .conflate() + .distinctUntilChanged() + .onEach { + stateController.update(transformer = HideBalanceStateTransformer(it.isBalanceHidden)) + } + .flowOn(dispatchers.main) + .launchIn(viewModelScope) + } + + private fun subscribeOnSelectedAppCurrency() { + getSelectedAppCurrencyUseCase() + .conflate() + .distinctUntilChanged() + .onEach { maybeAppCurrency -> + appCurrency = maybeAppCurrency.getOrElse { AppCurrency.Default } + } + .flowOn(dispatchers.main) + .launchIn(viewModelScope) + } + + private suspend fun sendStakingTransaction( + transactionId: String, + gasEstimate: StakingGasEstimate, + txData: TransactionData, + pendingActions: ImmutableList, + ) { + sendTransactionUseCase( + txData = txData, + userWallet = userWallet, + network = cryptoCurrencyStatus.currency.network, + ).fold( + ifLeft = { error -> + Timber.e(error.toString()) + stateController.update( + SetConfirmationStateAssentTransformer( + appCurrencyProvider = Provider { appCurrency }, + cryptoCurrencyStatusProvider = Provider { cryptoCurrencyStatus }, + stakingGasEstimate = gasEstimate, + pendingActionList = pendingActions, + ), + ) + // todo add error dialog + }, + ifRight = { txHash -> + submitHash(transactionId, txHash) + + val txUrl = getExplorerTransactionUrlUseCase( + txHash = txHash, + networkId = cryptoCurrencyStatus.currency.network.id, + ).getOrElse { "" } + + stateController.update( + SetConfirmationStateCompletedTransformer( + appCurrencyProvider = Provider { appCurrency }, + cryptoCurrencyStatusProvider = Provider { cryptoCurrencyStatus }, + stakingGasEstimate = gasEstimate, + txUrl = txUrl, + ), + ) + }, + ) + } + + private suspend fun submitHash(transactionId: String, transactionHash: String) { + submitHashUseCase.submitHash( + transactionId = transactionId, + transactionHash = transactionHash, + ) + .onLeft { + saveUnsubmittedHashUseCase.invoke( + transactionId = transactionId, + transactionHash = transactionHash, + ) + }.onRight { + Timber.d("Successful hash submission") + } + } + + private fun isAssentState(): Boolean { + return value.currentStep == StakingStep.Confirmation && + (value.confirmationState as? StakingStates.ConfirmationState.Data)?.innerState == + InnerConfirmationStakingState.ASSENT + } + + private fun getStakingCommonType() = when (value.routeType) { + RouteType.STAKE -> StakingActionCommonType.ENTER + RouteType.UNSTAKE -> StakingActionCommonType.EXIT + RouteType.CLAIM, + RouteType.OTHER, + -> StakingActionCommonType.PENDING + } +} \ No newline at end of file diff --git a/features/swap/domain/build.gradle.kts b/features/swap/domain/build.gradle.kts index 73348d6d0b..55f5e6eea3 100644 --- a/features/swap/domain/build.gradle.kts +++ b/features/swap/domain/build.gradle.kts @@ -32,8 +32,10 @@ dependencies { implementation(projects.domain.card) implementation(projects.domain.appCurrency.models) implementation(projects.domain.txhistory.models) + implementation(projects.domain.transaction.models) implementation(projects.features.swap.domain.api) implementation(projects.features.swap.domain.models) + implementation(projects.domain.staking) /** Core modules */ implementation(projects.core.utils) diff --git a/features/swap/domain/src/main/java/com/tangem/feature/swap/domain/SwapInteractorImpl.kt b/features/swap/domain/src/main/java/com/tangem/feature/swap/domain/SwapInteractorImpl.kt index 9e7fd0aa87..3f3656b18c 100644 --- a/features/swap/domain/src/main/java/com/tangem/feature/swap/domain/SwapInteractorImpl.kt +++ b/features/swap/domain/src/main/java/com/tangem/feature/swap/domain/SwapInteractorImpl.kt @@ -2,7 +2,6 @@ package com.tangem.feature.swap.domain import arrow.core.Either import arrow.core.getOrElse -import com.tangem.blockchain.blockchains.ethereum.EthereumTransactionExtras import com.tangem.blockchain.common.* import com.tangem.blockchain.common.Amount import com.tangem.blockchain.common.AmountType @@ -10,12 +9,12 @@ import com.tangem.blockchain.common.transaction.Fee import com.tangem.blockchain.common.transaction.TransactionFee import com.tangem.blockchainsdk.utils.fromNetworkId import com.tangem.blockchainsdk.utils.minimalAmount -import com.tangem.common.extensions.hexToBytes import com.tangem.core.ui.utils.BigDecimalFormatter import com.tangem.core.ui.utils.parseBigDecimal import com.tangem.domain.appcurrency.GetSelectedAppCurrencyUseCase import com.tangem.domain.appcurrency.extenstions.unwrap import com.tangem.domain.appcurrency.repository.AppCurrencyRepository +import com.tangem.domain.demo.DemoConfig import com.tangem.domain.demo.IsDemoCardUseCase import com.tangem.domain.tokens.GetCryptoCurrencyStatusesSyncUseCase import com.tangem.domain.tokens.model.* @@ -24,13 +23,10 @@ import com.tangem.domain.tokens.repository.CurrenciesRepository import com.tangem.domain.tokens.repository.CurrencyChecksRepository import com.tangem.domain.tokens.repository.QuotesRepository import com.tangem.domain.tokens.utils.convertToAmount -import com.tangem.domain.transaction.TransactionRepository import com.tangem.domain.transaction.error.GetFeeError import com.tangem.domain.transaction.error.SendTransactionError -import com.tangem.domain.transaction.usecase.CreateTransactionUseCase -import com.tangem.domain.transaction.usecase.EstimateFeeUseCase -import com.tangem.domain.transaction.usecase.SendTransactionUseCase -import com.tangem.domain.walletmanager.WalletManagersFacade +import com.tangem.domain.transaction.models.TransactionType +import com.tangem.domain.transaction.usecase.* import com.tangem.domain.wallets.models.UserWallet import com.tangem.domain.wallets.models.UserWalletId import com.tangem.domain.wallets.usecase.GetSelectedWalletSyncUseCase @@ -44,9 +40,9 @@ import com.tangem.feature.swap.domain.models.ui.* import com.tangem.lib.crypto.BlockchainUtils import com.tangem.lib.crypto.TransactionManager import com.tangem.lib.crypto.UserWalletManager -import com.tangem.lib.crypto.models.* -import com.tangem.lib.crypto.models.transactions.SendTxResult -import com.tangem.utils.coroutines.CoroutineDispatcherProvider +import com.tangem.lib.crypto.models.ProxyAmount +import com.tangem.lib.crypto.models.ProxyFee +import com.tangem.lib.crypto.models.ProxyFees import kotlinx.coroutines.coroutineScope import kotlinx.coroutines.flow.firstOrNull import timber.log.Timber @@ -63,24 +59,21 @@ internal class SwapInteractorImpl @Inject constructor( private val allowPermissionsHandler: AllowPermissionsHandler, private val getSelectedWalletSyncUseCase: GetSelectedWalletSyncUseCase, private val getMultiCryptoCurrencyStatusUseCase: GetCryptoCurrencyStatusesSyncUseCase, - private val walletManagersFacade: WalletManagersFacade, private val sendTransactionUseCase: SendTransactionUseCase, private val createTransactionUseCase: CreateTransactionUseCase, + private val createTransactionExtrasUseCase: CreateTransactionDataExtrasUseCase, private val isDemoCardUseCase: IsDemoCardUseCase, private val quotesRepository: QuotesRepository, - private val dispatcher: CoroutineDispatcherProvider, private val swapTransactionRepository: SwapTransactionRepository, private val currencyChecksRepository: CurrencyChecksRepository, private val appCurrencyRepository: AppCurrencyRepository, private val currenciesRepository: CurrenciesRepository, private val initialToCurrencyResolver: InitialToCurrencyResolver, - private val transactionRepository: TransactionRepository, + private val demoConfig: DemoConfig, + private val validateTransactionUseCase: ValidateTransactionUseCase, + private val estimateFeeUseCase: EstimateFeeUseCase, ) : SwapInteractor { - private val estimateFeeUseCase by lazy(LazyThreadSafetyMode.NONE) { - EstimateFeeUseCase(walletManagersFacade, dispatcher) - } - private val getSelectedAppCurrencyUseCase by lazy(LazyThreadSafetyMode.NONE) { GetSelectedAppCurrencyUseCase(appCurrencyRepository) } @@ -222,35 +215,50 @@ internal class SwapInteractorImpl @Inject constructor( } else { permissionOptions.approveData.approveData } - val result = transactionManager.sendApproveTransaction( - txData = ApproveTxData( - networkId = networkId, - feeAmount = permissionOptions.txFee.feeValue, - gasLimit = permissionOptions.txFee.gasLimit, - destinationAddress = getTokenAddress(permissionOptions.fromToken), - dataToSign = dataToSign, + val approveTransaction = createTransactionUseCase( + amount = BigDecimal.ZERO.convertToAmount(permissionOptions.fromToken), + fee = getFeeForTransaction( + fee = permissionOptions.txFee, + blockchain = Blockchain.fromId(permissionOptions.fromToken.network.id.value), ), - derivationPath = derivationPath, - analyticsData = AnalyticsData( - feeType = permissionOptions.txFee.feeType.getNameForAnalytics(), - tokenSymbol = permissionOptions.fromToken.symbol, - permissionType = permissionOptions.approveType.getNameForAnalytics(), + memo = null, + destination = getTokenAddress(permissionOptions.fromToken), + network = permissionOptions.fromToken.network, + userWalletId = requireNotNull(getSelectedWallet()).walletId, + txExtras = createDexTxExtras( + dataToSign, + permissionOptions.fromToken.network, + permissionOptions.txFee.gasLimit, ), + ).getOrElse { + Timber.e(it, "Failed to create approveTransaction") + return SwapTransactionState.UnknownError + } + + val result = sendTransactionUseCase( + txData = approveTransaction, + userWallet = requireNotNull(getSelectedWallet()), + network = permissionOptions.fromToken.network, ) - return when (result) { - is SendTxResult.Success -> { + return result.fold( + ifRight = { hash -> allowPermissionsHandler.addAddressToInProgress(permissionOptions.forTokenContractAddress) SwapTransactionState.TxSent( - txHash = userWalletManager.getLastTransactionHash(networkId, derivationPath).orEmpty(), + txHash = hash, timestamp = System.currentTimeMillis(), ) - } - SendTxResult.UserCancelledError -> SwapTransactionState.UserCancelled - is SendTxResult.BlockchainSdkError -> SwapTransactionState.BlockchainError - is SendTxResult.TangemSdkError -> SwapTransactionState.TangemSdkError - is SendTxResult.NetworkError -> SwapTransactionState.NetworkError - is SendTxResult.UnknownError -> SwapTransactionState.UnknownError - } + }, + ifLeft = { + when (it) { + SendTransactionError.UserCancelledError -> SwapTransactionState.UserCancelled + is SendTransactionError.BlockchainSdkError -> SwapTransactionState.BlockchainError + is SendTransactionError.TangemSdkError -> SwapTransactionState.TangemSdkError + is SendTransactionError.NetworkError -> SwapTransactionState.NetworkError + is SendTransactionError.DemoCardError -> SwapTransactionState.DemoMode + else -> SwapTransactionState.UnknownError + } + }, + ) } override suspend fun findBestQuote( @@ -498,35 +506,33 @@ internal class SwapInteractorImpl @Inject constructor( ), ) - transactionRepository.validateTransaction( + validateTransactionUseCase( amount = amount.value.convertToAmount(fromToken), fee = fee, memo = null, - txExtras = null, destination = getTokenAddress(fromToken), userWalletId = userWalletId, network = fromToken.network, - ) - .fold( - onFailure = { - addCardanoTransactionValidationError( - warnings = warnings, - error = it as? BlockchainSdkError.Cardano ?: return@fold, - fromToken = fromToken, - userWalletId = userWalletId, + ).fold( + ifLeft = { + addCardanoTransactionValidationError( + warnings = warnings, + error = it as? BlockchainSdkError.Cardano ?: return@fold, + fromToken = fromToken, + userWalletId = userWalletId, + ) + }, + ifRight = { + minAdaValue?.let { + warnings.add( + Warning.Cardano.MinAdaValueCharged( + tokenName = fromToken.name, + minAdaValue = minAdaValue.parseBigDecimal(fromToken.decimals), + ), ) - }, - onSuccess = { - minAdaValue?.let { - warnings.add( - Warning.Cardano.MinAdaValueCharged( - tokenName = fromToken.name, - minAdaValue = minAdaValue.parseBigDecimal(fromToken.decimals), - ), - ) - } - }, - ) + } + }, + ) } private suspend fun addCardanoTransactionValidationError( @@ -667,10 +673,10 @@ internal class SwapInteractorImpl @Inject constructor( destination = swapData.transaction.txTo, userWalletId = userWalletId, network = currencyToSendStatus.currency.network, - txExtras = createDexTxExtras(fee.gasLimit, dataToSign), + txExtras = createDexTxExtras(dataToSign, currencyToSendStatus.currency.network, fee.gasLimit), hash = dataToSign, ).getOrElse { - Timber.e(it) + Timber.e(it, "Failed to create swap dex tx data") return SwapTransactionState.UnknownError } @@ -720,13 +726,13 @@ internal class SwapInteractorImpl @Inject constructor( ) } - private fun createDexTxExtras(gasLimit: Int, data: String): TransactionExtras { - // for now we support only Ethereum like DEX - // need to be extended if we support other blockchains in DEX - return EthereumTransactionExtras( - gasLimit = gasLimit.toBigInteger(), - data = data.removePrefix(HEX_PREFIX).hexToBytes(), - ) + private fun createDexTxExtras(data: String, network: Network, gasLimit: Int?): TransactionExtras { + return createTransactionExtrasUseCase( + data = data, + network = network, + transactionType = TransactionType.APPROVE, + gasLimit = gasLimit?.toBigInteger(), + ).getOrNull() ?: error("failed to create extras") } @Suppress("LongMethod") @@ -757,27 +763,27 @@ internal class SwapInteractorImpl @Inject constructor( val exchangeDataCex = exchangeData.transaction as? ExpressTransactionModel.CEX ?: return SwapTransactionState.UnknownError - val txExtras = transactionManager.getMemoExtras( - currencyToSend.currency.network.backendId, - exchangeDataCex.txExtraId, - ) - if (txExtras == null && exchangeDataCex.txExtraId != null) { - return SwapTransactionState.UnknownError - } + val cardId = getSelectedWallet()?.scanResponse?.card?.cardId ?: return SwapTransactionState.UnknownError + if (demoConfig.isDemoCardId(cardId)) return SwapTransactionState.UnknownError + val txData = createTransactionUseCase( amount = amount.value.convertToAmount(currencyToSend.currency), fee = getFeeForTransaction( fee = txFee, blockchain = Blockchain.fromId(currencyToSend.currency.network.id.value), ), - memo = null, + memo = exchangeDataCex.txExtraId, destination = exchangeDataCex.txTo, userWalletId = userWalletId, network = currencyToSend.currency.network, ).getOrElse { - Timber.e(it) + Timber.e(it, "Failed to create swap CEX tx data") return SwapTransactionState.UnknownError - }.copy(extras = txExtras) + } + + if (txData.extras == null && exchangeDataCex.txExtraId != null) { + return SwapTransactionState.UnknownError + } val result = sendTransactionUseCase( txData = txData, @@ -995,10 +1001,10 @@ internal class SwapInteractorImpl @Inject constructor( val fromToken = fromTokenStatus.currency val toToken = toTokenStatus.currency return coroutineScope { - val txFeeResult = getSelectedWalletSyncUseCase().getOrNull()?.walletId?.let { userWalletId -> + val txFeeResult = getSelectedWalletSyncUseCase().getOrNull()?.let { userWallet -> getUnhandledFee( amount = amount.value, - userWalletId = userWalletId, + userWallet = userWallet, cryptoCurrency = fromToken, ) } @@ -1263,7 +1269,15 @@ internal class SwapInteractorImpl @Inject constructor( val otherNativeFee = transaction.otherNativeFeeWei ?.movePointLeft(nativeCoinDecimals) ?: BigDecimal.ZERO - val txFeeState = when (val feeData = getFeeDataForDexSwap(networkId, transaction, fromToken.currency)) { + val userWallet = getSelectedWallet() + val txFeeState = when ( + val feeData = getFeeDataForDexSwap( + networkId = networkId, + transaction = transaction, + fromToken = fromToken.currency, + cardId = userWallet?.scanResponse?.card?.cardId, + ) + ) { is ProxyFees.MultipleFees -> feeData.proxyFeesToFeeState(fromToken.currency, otherNativeFee) is ProxyFees.SingleFee -> feeData.proxyFeesToFeeState(fromToken.currency, otherNativeFee) } @@ -1325,7 +1339,11 @@ internal class SwapInteractorImpl @Inject constructor( networkId: String, transaction: ExpressTransactionModel.DEX, fromToken: CryptoCurrency, + cardId: String?, ): ProxyFees { + if (cardId != null && isDemoCardUseCase(cardId)) { + return getDemoFees(fromToken) + } return try { val nativeBalance = userWalletManager.getNativeTokenBalance( networkId = networkId, @@ -1406,12 +1424,12 @@ internal class SwapInteractorImpl @Inject constructor( private suspend fun getUnhandledFee( amount: BigDecimal, - userWalletId: UserWalletId, + userWallet: UserWallet, cryptoCurrency: CryptoCurrency, ): Either? { return estimateFeeUseCase( amount = amount, - userWalletId = userWalletId, + userWallet = userWallet, cryptoCurrency = cryptoCurrency, ).firstOrNull() } @@ -1987,7 +2005,6 @@ internal class SwapInteractorImpl @Inject constructor( } companion object { - @Suppress("UnusedPrivateMember") private const val INCREASE_GAS_LIMIT_BY = 112 // 12% private const val INCREASE_GAS_LIMIT_FOR_SEND = 105 // 5% private const val INFINITY_SYMBOL = "∞" diff --git a/features/swap/domain/src/main/java/com/tangem/feature/swap/domain/di/SwapDomainModule.kt b/features/swap/domain/src/main/java/com/tangem/feature/swap/domain/di/SwapDomainModule.kt index a99ef1d6d7..3f20bc09bc 100644 --- a/features/swap/domain/src/main/java/com/tangem/feature/swap/domain/di/SwapDomainModule.kt +++ b/features/swap/domain/src/main/java/com/tangem/feature/swap/domain/di/SwapDomainModule.kt @@ -4,6 +4,7 @@ import com.tangem.domain.appcurrency.repository.AppCurrencyRepository import com.tangem.domain.card.repository.CardSdkConfigRepository import com.tangem.domain.demo.DemoConfig import com.tangem.domain.demo.IsDemoCardUseCase +import com.tangem.domain.staking.repositories.StakingRepository import com.tangem.domain.tokens.GetCardTokensListUseCase import com.tangem.domain.tokens.GetCryptoCurrencyStatusesSyncUseCase import com.tangem.domain.tokens.repository.CurrenciesRepository @@ -11,8 +12,7 @@ import com.tangem.domain.tokens.repository.CurrencyChecksRepository import com.tangem.domain.tokens.repository.NetworksRepository import com.tangem.domain.tokens.repository.QuotesRepository import com.tangem.domain.transaction.TransactionRepository -import com.tangem.domain.transaction.usecase.CreateTransactionUseCase -import com.tangem.domain.transaction.usecase.SendTransactionUseCase +import com.tangem.domain.transaction.usecase.* import com.tangem.domain.walletmanager.WalletManagersFacade import com.tangem.domain.wallets.legacy.UserWalletsListManager import com.tangem.domain.wallets.usecase.GetSelectedWalletSyncUseCase @@ -42,16 +42,16 @@ class SwapDomainModule { getCryptoCurrencyStatusUseCase: GetCryptoCurrencyStatusesSyncUseCase, @SwapScope sendTransactionUseCase: SendTransactionUseCase, @SwapScope createTransactionUseCase: CreateTransactionUseCase, + createTransactionDataExtrasUseCase: CreateTransactionDataExtrasUseCase, isDemoCardUseCase: IsDemoCardUseCase, quotesRepository: QuotesRepository, swapTransactionRepository: SwapTransactionRepository, appCurrencyRepository: AppCurrencyRepository, currencyChecksRepository: CurrencyChecksRepository, - walletManagersFacade: WalletManagersFacade, - coroutineDispatcherProvider: CoroutineDispatcherProvider, initialToCurrencyResolver: InitialToCurrencyResolver, currenciesRepository: CurrenciesRepository, - transactionRepository: TransactionRepository, + validateTransactionUseCase: ValidateTransactionUseCase, + estimateFeeUseCase: EstimateFeeUseCase, ): SwapInteractor { return SwapInteractorImpl( transactionManager = transactionManager, @@ -62,16 +62,17 @@ class SwapDomainModule { getMultiCryptoCurrencyStatusUseCase = getCryptoCurrencyStatusUseCase, sendTransactionUseCase = sendTransactionUseCase, createTransactionUseCase = createTransactionUseCase, + createTransactionExtrasUseCase = createTransactionDataExtrasUseCase, isDemoCardUseCase = isDemoCardUseCase, quotesRepository = quotesRepository, - walletManagersFacade = walletManagersFacade, - dispatcher = coroutineDispatcherProvider, swapTransactionRepository = swapTransactionRepository, appCurrencyRepository = appCurrencyRepository, currencyChecksRepository = currencyChecksRepository, currenciesRepository = currenciesRepository, initialToCurrencyResolver = initialToCurrencyResolver, - transactionRepository = transactionRepository, + demoConfig = DemoConfig(), + validateTransactionUseCase = validateTransactionUseCase, + estimateFeeUseCase = estimateFeeUseCase, ) } @@ -96,12 +97,14 @@ class SwapDomainModule { currenciesRepository: CurrenciesRepository, quotesRepository: QuotesRepository, networksRepository: NetworksRepository, + stakingRepository: StakingRepository, dispatchers: CoroutineDispatcherProvider, ): GetCryptoCurrencyStatusesSyncUseCase { return GetCryptoCurrencyStatusesSyncUseCase( currenciesRepository = currenciesRepository, quotesRepository = quotesRepository, networksRepository = networksRepository, + stakingRepository = stakingRepository, dispatchers = dispatchers, ) } @@ -113,11 +116,13 @@ class SwapDomainModule { currenciesRepository: CurrenciesRepository, quotesRepository: QuotesRepository, networksRepository: NetworksRepository, + stakingRepository: StakingRepository, ): GetCardTokensListUseCase { return GetCardTokensListUseCase( currenciesRepository = currenciesRepository, quotesRepository = quotesRepository, networksRepository = networksRepository, + stakingRepository = stakingRepository, ) } diff --git a/features/swap/presentation/build.gradle.kts b/features/swap/presentation/build.gradle.kts index 643cf8f201..c41603a025 100644 --- a/features/swap/presentation/build.gradle.kts +++ b/features/swap/presentation/build.gradle.kts @@ -19,7 +19,8 @@ dependencies { implementation(projects.core.navigation) implementation(projects.core.utils) implementation(projects.core.ui) - implementation(projects.common) + implementation(projects.common.routing) + implementation(projects.common.ui) /** Domain modules **/ implementation(projects.domain.appCurrency) @@ -35,6 +36,7 @@ dependencies { implementation(projects.features.swap.domain) implementation(projects.features.swap.domain.api) implementation(projects.features.swap.domain.models) + implementation(projects.domain.staking) /** AndroidX */ implementation(deps.androidx.activity.compose) diff --git a/features/swap/presentation/src/main/java/com/tangem/feature/swap/analytics/SwapEvents.kt b/features/swap/presentation/src/main/java/com/tangem/feature/swap/analytics/SwapEvents.kt index 59fd338f5a..55450cbdec 100644 --- a/features/swap/presentation/src/main/java/com/tangem/feature/swap/analytics/SwapEvents.kt +++ b/features/swap/presentation/src/main/java/com/tangem/feature/swap/analytics/SwapEvents.kt @@ -1,9 +1,9 @@ package com.tangem.feature.swap.analytics +import com.tangem.common.ui.bottomsheet.permission.state.ApproveType import com.tangem.core.analytics.models.AnalyticsEvent import com.tangem.feature.swap.domain.models.domain.SwapProvider import com.tangem.feature.swap.domain.models.ui.FeeType -import com.tangem.feature.swap.models.ApproveType private const val SWAP_CATEGORY = "Swap" private const val PROMO_CATEGORY = "Promo" @@ -60,6 +60,8 @@ sealed class SwapEvents( data class SwapInProgressScreen( val provider: SwapProvider, val commission: FeeType, // Market / Fast + val sendBlockchain: String, + val receiveBlockchain: String, val sendToken: String, val receiveToken: String, ) : SwapEvents( @@ -69,6 +71,8 @@ sealed class SwapEvents( "Commission" to if (commission == FeeType.NORMAL) "Market" else "Fast", "Send Token" to sendToken, "Receive Token" to receiveToken, + "Send Blockchain" to sendBlockchain, + "Receive Blockchain" to receiveBlockchain, ), ) diff --git a/features/swap/presentation/src/main/java/com/tangem/feature/swap/converters/TokensDataConverter.kt b/features/swap/presentation/src/main/java/com/tangem/feature/swap/converters/TokensDataConverter.kt index 40dd04e697..390b8e7c7e 100644 --- a/features/swap/presentation/src/main/java/com/tangem/feature/swap/converters/TokensDataConverter.kt +++ b/features/swap/presentation/src/main/java/com/tangem/feature/swap/converters/TokensDataConverter.kt @@ -1,6 +1,6 @@ package com.tangem.feature.swap.converters -import com.tangem.core.ui.components.currency.tokenicon.TokenIconState +import com.tangem.core.ui.components.currency.icon.CurrencyIconState import com.tangem.core.ui.extensions.* import com.tangem.core.ui.utils.BigDecimalFormatter import com.tangem.domain.appcurrency.model.AppCurrency @@ -11,8 +11,8 @@ import com.tangem.feature.swap.models.CurrenciesGroupWithFromCurrency import com.tangem.feature.swap.models.SwapSelectTokenStateHolder import com.tangem.feature.swap.models.TokenBalanceData import com.tangem.feature.swap.models.TokenToSelectState -import com.tangem.utils.Provider import com.tangem.feature.swap.presentation.R +import com.tangem.utils.Provider import com.tangem.utils.converter.Converter import kotlinx.collections.immutable.toImmutableList @@ -76,10 +76,10 @@ class TokensDataConverter( ) } - private fun convertIcon(currency: CryptoCurrency, isAvailable: Boolean): TokenIconState { + private fun convertIcon(currency: CryptoCurrency, isAvailable: Boolean): CurrencyIconState { return when (currency) { is CryptoCurrency.Coin -> { - TokenIconState.CoinIcon( + CurrencyIconState.CoinIcon( url = currency.iconUrl, fallbackResId = currency.networkIconResId, isGrayscale = !isAvailable, @@ -90,11 +90,11 @@ class TokensDataConverter( val isGrayscale = currency.network.isTestnet val background = currency.tryGetBackgroundForTokenIcon(isGrayscale) val tint = getTintForTokenIcon(background) - TokenIconState.TokenIcon( + CurrencyIconState.TokenIcon( url = currency.iconUrl, isGrayscale = !isAvailable, showCustomBadge = currency.isCustom, - networkBadgeIconResId = currency.networkIconResId, + topBadgeIconResId = currency.networkIconResId, fallbackTint = tint, fallbackBackground = background, ) diff --git a/features/swap/presentation/src/main/java/com/tangem/feature/swap/di/SwapPresentationModule.kt b/features/swap/presentation/src/main/java/com/tangem/feature/swap/di/SwapPresentationModule.kt index 441abf4a2e..db8287c844 100644 --- a/features/swap/presentation/src/main/java/com/tangem/feature/swap/di/SwapPresentationModule.kt +++ b/features/swap/presentation/src/main/java/com/tangem/feature/swap/di/SwapPresentationModule.kt @@ -1,10 +1,10 @@ package com.tangem.feature.swap.di +import com.tangem.domain.staking.repositories.StakingRepository import com.tangem.domain.tokens.GetCryptoCurrencyStatusSyncUseCase import com.tangem.domain.tokens.repository.CurrenciesRepository import com.tangem.domain.tokens.repository.NetworksRepository import com.tangem.domain.tokens.repository.QuotesRepository -import com.tangem.feature.swap.domain.* import com.tangem.utils.coroutines.CoroutineDispatcherProvider import dagger.Module import dagger.Provides @@ -23,11 +23,13 @@ class SwapPresentationModule { dispatcherProvider: CoroutineDispatcherProvider, quotesRepository: QuotesRepository, networksRepository: NetworksRepository, + stakingRepository: StakingRepository, ): GetCryptoCurrencyStatusSyncUseCase { return GetCryptoCurrencyStatusSyncUseCase( currenciesRepository = currenciesRepository, quotesRepository = quotesRepository, networksRepository = networksRepository, + stakingRepository = stakingRepository, dispatchers = dispatcherProvider, ) } diff --git a/features/swap/presentation/src/main/java/com/tangem/feature/swap/models/SwapSelectTokenStateHolder.kt b/features/swap/presentation/src/main/java/com/tangem/feature/swap/models/SwapSelectTokenStateHolder.kt index 585afb1921..d99e967096 100644 --- a/features/swap/presentation/src/main/java/com/tangem/feature/swap/models/SwapSelectTokenStateHolder.kt +++ b/features/swap/presentation/src/main/java/com/tangem/feature/swap/models/SwapSelectTokenStateHolder.kt @@ -1,6 +1,6 @@ package com.tangem.feature.swap.models -import com.tangem.core.ui.components.currency.tokenicon.TokenIconState +import com.tangem.core.ui.components.currency.icon.CurrencyIconState import com.tangem.core.ui.extensions.TextReference import kotlinx.collections.immutable.ImmutableList @@ -20,7 +20,7 @@ sealed class TokenToSelectState { val id: String, val name: String, val symbol: String, - val tokenIcon: TokenIconState, + val tokenIcon: CurrencyIconState, val available: Boolean = true, val addedTokenBalanceData: TokenBalanceData? = null, ) : TokenToSelectState() diff --git a/features/swap/presentation/src/main/java/com/tangem/feature/swap/models/SwapStateHolder.kt b/features/swap/presentation/src/main/java/com/tangem/feature/swap/models/SwapStateHolder.kt index 6e429c9c13..003f258f6f 100644 --- a/features/swap/presentation/src/main/java/com/tangem/feature/swap/models/SwapStateHolder.kt +++ b/features/swap/presentation/src/main/java/com/tangem/feature/swap/models/SwapStateHolder.kt @@ -2,6 +2,7 @@ package com.tangem.feature.swap.models import androidx.annotation.DrawableRes import androidx.compose.ui.text.input.TextFieldValue +import com.tangem.common.ui.bottomsheet.permission.state.GiveTxPermissionState import com.tangem.core.ui.R import com.tangem.core.ui.components.bottomsheets.TangemBottomSheetConfig import com.tangem.core.ui.components.notifications.NotificationConfig @@ -21,7 +22,7 @@ data class SwapStateHolder( val providerState: ProviderState, val fee: FeeItemState = FeeItemState.Empty, - val permissionState: SwapPermissionState = SwapPermissionState.Empty, + val permissionState: GiveTxPermissionState = GiveTxPermissionState.Empty, val priceImpact: PriceImpact, val successState: SwapSuccessStateHolder? = null, diff --git a/features/swap/presentation/src/main/java/com/tangem/feature/swap/models/SwapSuccessStateHolder.kt b/features/swap/presentation/src/main/java/com/tangem/feature/swap/models/SwapSuccessStateHolder.kt index cbe749c6a8..5d05e969b8 100644 --- a/features/swap/presentation/src/main/java/com/tangem/feature/swap/models/SwapSuccessStateHolder.kt +++ b/features/swap/presentation/src/main/java/com/tangem/feature/swap/models/SwapSuccessStateHolder.kt @@ -1,6 +1,6 @@ package com.tangem.feature.swap.models -import com.tangem.core.ui.components.currency.tokenicon.TokenIconState +import com.tangem.core.ui.components.currency.icon.CurrencyIconState import com.tangem.core.ui.extensions.TextReference data class SwapSuccessStateHolder( @@ -16,8 +16,8 @@ data class SwapSuccessStateHolder( val toTokenAmount: TextReference, val fromTokenFiatAmount: TextReference, val toTokenFiatAmount: TextReference, - val fromTokenIconState: TokenIconState?, - val toTokenIconState: TokenIconState?, + val fromTokenIconState: CurrencyIconState?, + val toTokenIconState: CurrencyIconState?, val onExploreButtonClick: () -> Unit, val onStatusButtonClick: () -> Unit, ) \ No newline at end of file diff --git a/features/swap/presentation/src/main/java/com/tangem/feature/swap/models/UiActions.kt b/features/swap/presentation/src/main/java/com/tangem/feature/swap/models/UiActions.kt index 6bbee12717..c25fc38225 100644 --- a/features/swap/presentation/src/main/java/com/tangem/feature/swap/models/UiActions.kt +++ b/features/swap/presentation/src/main/java/com/tangem/feature/swap/models/UiActions.kt @@ -1,5 +1,6 @@ package com.tangem.feature.swap.models +import com.tangem.common.ui.bottomsheet.permission.state.ApproveType import com.tangem.domain.tokens.model.CryptoCurrency import com.tangem.feature.swap.domain.models.SwapAmount import com.tangem.feature.swap.domain.models.ui.TxFee diff --git a/features/swap/presentation/src/main/java/com/tangem/feature/swap/models/states/GivePermissionBottomSheetConfig.kt b/features/swap/presentation/src/main/java/com/tangem/feature/swap/models/states/GivePermissionBottomSheetConfig.kt deleted file mode 100644 index 9a8bd7a519..0000000000 --- a/features/swap/presentation/src/main/java/com/tangem/feature/swap/models/states/GivePermissionBottomSheetConfig.kt +++ /dev/null @@ -1,9 +0,0 @@ -package com.tangem.feature.swap.models.states - -import com.tangem.core.ui.components.bottomsheets.TangemBottomSheetConfigContent -import com.tangem.feature.swap.models.SwapPermissionState - -data class GivePermissionBottomSheetConfig( - val data: SwapPermissionState.ReadyForRequest, - val onCancel: () -> Unit, -) : TangemBottomSheetConfigContent \ No newline at end of file diff --git a/features/swap/presentation/src/main/java/com/tangem/feature/swap/presentation/SwapFragment.kt b/features/swap/presentation/src/main/java/com/tangem/feature/swap/presentation/SwapFragment.kt index 6409755135..60df4a856b 100644 --- a/features/swap/presentation/src/main/java/com/tangem/feature/swap/presentation/SwapFragment.kt +++ b/features/swap/presentation/src/main/java/com/tangem/feature/swap/presentation/SwapFragment.kt @@ -2,12 +2,13 @@ package com.tangem.feature.swap.presentation import android.os.Bundle import androidx.compose.animation.Crossfade +import androidx.compose.foundation.background import androidx.compose.runtime.Composable import androidx.compose.ui.Modifier import androidx.fragment.app.viewModels -import com.tangem.core.navigation.ReduxNavController +import com.tangem.common.routing.AppRouter + import com.tangem.core.ui.UiDependencies -import com.tangem.core.ui.components.SystemBarsEffect import com.tangem.core.ui.res.TangemTheme import com.tangem.core.ui.screen.ComposeFragment import com.tangem.feature.swap.router.CustomTabsManager @@ -28,7 +29,7 @@ class SwapFragment : ComposeFragment() { override lateinit var uiDependencies: UiDependencies @Inject - lateinit var reduxNavController: ReduxNavController + lateinit var appRouter: AppRouter private val viewModel by viewModels() @@ -37,9 +38,8 @@ class SwapFragment : ComposeFragment() { lifecycle.addObserver(viewModel) viewModel.setRouter( SwapRouter( - fragmentManager = WeakReference(parentFragmentManager), customTabsManager = CustomTabsManager(WeakReference(context)), - reduxNavController = reduxNavController, + router = appRouter, ), ) } @@ -47,17 +47,17 @@ class SwapFragment : ComposeFragment() { @Composable override fun ScreenContent(modifier: Modifier) { viewModel.onScreenOpened() - - val backgroundColor = TangemTheme.colors.background.secondary - SystemBarsEffect { setSystemBarsColor(backgroundColor) } - ScreenContent(viewModel = viewModel) } @Suppress("TopLevelComposableFunctions") @Composable private fun ScreenContent(viewModel: SwapViewModel) { - Crossfade(targetState = viewModel.currentScreen, label = "") { screen -> + Crossfade( + modifier = Modifier.background(TangemTheme.colors.background.secondary), + targetState = viewModel.currentScreen, + label = "", + ) { screen -> when (screen) { SwapNavScreen.Main -> SwapScreen(stateHolder = viewModel.uiState) SwapNavScreen.Success -> { @@ -84,8 +84,4 @@ class SwapFragment : ComposeFragment() { lifecycle.removeObserver(viewModel) super.onDestroy() } - - companion object { - const val CURRENCY_BUNDLE_KEY = "swap_currency" - } } \ No newline at end of file diff --git a/features/swap/presentation/src/main/java/com/tangem/feature/swap/router/SwapRouter.kt b/features/swap/presentation/src/main/java/com/tangem/feature/swap/router/SwapRouter.kt index 081730868d..bc5009da3c 100644 --- a/features/swap/presentation/src/main/java/com/tangem/feature/swap/router/SwapRouter.kt +++ b/features/swap/presentation/src/main/java/com/tangem/feature/swap/router/SwapRouter.kt @@ -3,20 +3,14 @@ package com.tangem.feature.swap.router import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.setValue -import androidx.core.os.bundleOf -import androidx.fragment.app.FragmentManager -import com.tangem.core.navigation.AppScreen -import com.tangem.core.navigation.NavigationAction -import com.tangem.core.navigation.ReduxNavController +import com.tangem.common.routing.AppRoute +import com.tangem.common.routing.AppRouter import com.tangem.domain.tokens.model.CryptoCurrency import com.tangem.domain.wallets.models.UserWalletId -import com.tangem.features.tokendetails.navigation.TokenDetailsRouter -import java.lang.ref.WeakReference internal class SwapRouter( - private val fragmentManager: WeakReference, private val customTabsManager: CustomTabsManager, - private val reduxNavController: ReduxNavController, + private val router: AppRouter, ) { var currentScreen by mutableStateOf(SwapNavScreen.Main) @@ -30,7 +24,7 @@ internal class SwapRouter( if (currentScreen == SwapNavScreen.SelectToken) { currentScreen = SwapNavScreen.Main } else { - fragmentManager.get()?.popBackStack() + router.pop() } } @@ -39,13 +33,10 @@ internal class SwapRouter( } fun openTokenDetails(userWalletId: UserWalletId, currency: CryptoCurrency) { - reduxNavController.navigate( - action = NavigationAction.NavigateTo( - screen = AppScreen.WalletDetails, - bundle = bundleOf( - TokenDetailsRouter.USER_WALLET_ID_KEY to userWalletId.stringValue, - TokenDetailsRouter.CRYPTO_CURRENCY_KEY to currency, - ), + router.push( + AppRoute.CurrencyDetails( + userWalletId = userWalletId, + currency = currency, ), ) } diff --git a/features/swap/presentation/src/main/java/com/tangem/feature/swap/ui/ChooseFeeBottomSheet.kt b/features/swap/presentation/src/main/java/com/tangem/feature/swap/ui/ChooseFeeBottomSheet.kt index 8b1ac6f243..f183c74cbd 100644 --- a/features/swap/presentation/src/main/java/com/tangem/feature/swap/ui/ChooseFeeBottomSheet.kt +++ b/features/swap/presentation/src/main/java/com/tangem/feature/swap/ui/ChooseFeeBottomSheet.kt @@ -1,12 +1,11 @@ package com.tangem.feature.swap.ui +import android.content.res.Configuration import androidx.compose.foundation.background import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.padding import androidx.compose.foundation.text.ClickableText -import androidx.compose.material3.Text import androidx.compose.runtime.Composable -import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.draw.clip import androidx.compose.ui.res.stringResource @@ -15,12 +14,12 @@ import androidx.compose.ui.text.buildAnnotatedString import androidx.compose.ui.text.style.TextAlign import androidx.compose.ui.text.withStyle import androidx.compose.ui.tooling.preview.Preview -import com.tangem.core.ui.components.SpacerH24 import com.tangem.core.ui.components.bottomsheets.TangemBottomSheet import com.tangem.core.ui.components.bottomsheets.TangemBottomSheetConfig import com.tangem.core.ui.components.rows.SelectorRowItem import com.tangem.core.ui.extensions.TextReference import com.tangem.core.ui.extensions.resolveReference +import com.tangem.core.ui.extensions.resourceReference import com.tangem.core.ui.extensions.stringReference import com.tangem.core.ui.res.TangemTheme import com.tangem.core.ui.res.TangemThemePreview @@ -35,6 +34,7 @@ fun ChooseFeeBottomSheet(config: TangemBottomSheetConfig) { TangemBottomSheet( config = config, containerColor = TangemTheme.colors.background.tertiary, + titleText = resourceReference(R.string.common_fee_selector_title), ) { content: ChooseFeeBottomSheetConfig -> ChooseFeeBottomSheetContent(content = content) } @@ -47,14 +47,6 @@ private fun ChooseFeeBottomSheetContent(content: ChooseFeeBottomSheetConfig) { .background(TangemTheme.colors.background.tertiary) .padding(bottom = TangemTheme.dimens.spacing8), ) { - Text( - text = stringResource(R.string.common_fee_selector_title), - style = TangemTheme.typography.subtitle1, - color = TangemTheme.colors.text.primary1, - modifier = Modifier - .padding(top = TangemTheme.dimens.spacing10) - .align(Alignment.CenterHorizontally), - ) Column( modifier = Modifier .padding(TangemTheme.dimens.spacing16) @@ -145,9 +137,11 @@ private fun FeeItemsBlock(content: ChooseFeeBottomSheetConfig) { } } -@Preview +// region Preview @Composable -private fun ChooseFeeBottomSheetContent_Preview() { +@Preview(showBackground = true) +@Preview(showBackground = true, uiMode = Configuration.UI_MODE_NIGHT_YES) +private fun Preview_ChooseFeeBottomSheet() { val feeItems = listOf( FeeItemState.Content( feeType = FeeType.NORMAL, @@ -168,33 +162,23 @@ private fun ChooseFeeBottomSheetContent_Preview() { onClick = {}, ), ).toImmutableList() - Column { - TangemThemePreview(isDark = true) { - ChooseFeeBottomSheetContent( - ChooseFeeBottomSheetConfig( - selectedFee = FeeType.NORMAL, - onSelectFeeType = {}, - feeItems = feeItems, - readMore = stringReference("Read more"), - readMoreUrl = "", - onReadMoreClick = {}, - ), - ) - } + val content = ChooseFeeBottomSheetConfig( + selectedFee = FeeType.NORMAL, + onSelectFeeType = {}, + feeItems = feeItems, + readMore = stringReference("Read more"), + readMoreUrl = "", + onReadMoreClick = {}, + ) - SpacerH24() - - TangemThemePreview(isDark = false) { - ChooseFeeBottomSheetContent( - ChooseFeeBottomSheetConfig( - selectedFee = FeeType.NORMAL, - onSelectFeeType = {}, - feeItems = feeItems, - readMore = stringReference("Read more"), - readMoreUrl = "", - onReadMoreClick = {}, - ), - ) - } + TangemThemePreview { + ChooseFeeBottomSheet( + config = TangemBottomSheetConfig( + isShow = true, + onDismissRequest = {}, + content = content, + ), + ) } -} \ No newline at end of file +} +// endregion Preview \ No newline at end of file diff --git a/features/swap/presentation/src/main/java/com/tangem/feature/swap/ui/ChooseProviderBottomSheet.kt b/features/swap/presentation/src/main/java/com/tangem/feature/swap/ui/ChooseProviderBottomSheet.kt index 960b9d3373..3663417055 100644 --- a/features/swap/presentation/src/main/java/com/tangem/feature/swap/ui/ChooseProviderBottomSheet.kt +++ b/features/swap/presentation/src/main/java/com/tangem/feature/swap/ui/ChooseProviderBottomSheet.kt @@ -1,5 +1,6 @@ package com.tangem.feature.swap.ui +import android.content.res.Configuration import androidx.compose.foundation.background import androidx.compose.foundation.clickable import androidx.compose.foundation.layout.Column @@ -16,6 +17,7 @@ import androidx.compose.ui.text.style.TextAlign import androidx.compose.ui.tooling.preview.Preview import com.tangem.core.ui.components.bottomsheets.TangemBottomSheet import com.tangem.core.ui.components.bottomsheets.TangemBottomSheetConfig +import com.tangem.core.ui.extensions.resourceReference import com.tangem.core.ui.extensions.stringReference import com.tangem.core.ui.res.TangemTheme import com.tangem.core.ui.res.TangemThemePreview @@ -23,13 +25,14 @@ import com.tangem.feature.swap.models.states.ChooseProviderBottomSheetConfig import com.tangem.feature.swap.models.states.PercentDifference import com.tangem.feature.swap.models.states.ProviderState import com.tangem.feature.swap.presentation.R -import kotlinx.collections.immutable.toImmutableList +import kotlinx.collections.immutable.persistentListOf @Composable fun ChooseProviderBottomSheet(config: TangemBottomSheetConfig) { TangemBottomSheet( config = config, containerColor = TangemTheme.colors.background.tertiary, + titleText = resourceReference(R.string.express_choose_providers_title), ) { content: ChooseProviderBottomSheetConfig -> ChooseProviderBottomSheetContent(content = content) } @@ -39,13 +42,6 @@ fun ChooseProviderBottomSheet(config: TangemBottomSheetConfig) { @Composable private fun ChooseProviderBottomSheetContent(content: ChooseProviderBottomSheetConfig) { Column(horizontalAlignment = Alignment.CenterHorizontally) { - Text( - text = stringResource(R.string.express_choose_providers_title), - style = TangemTheme.typography.subtitle1, - color = TangemTheme.colors.text.primary1, - modifier = Modifier - .padding(top = TangemTheme.dimens.spacing10), - ) Text( text = stringResource(R.string.express_choose_providers_subtitle), style = TangemTheme.typography.caption2, @@ -104,10 +100,12 @@ private fun ChooseProviderBottomSheetContent(content: ChooseProviderBottomSheetC } } -@Preview +// region Preview @Composable -private fun ChooseProviderBottomSheet_Preview() { - val providers = listOf( +@Preview(showBackground = true) +@Preview(showBackground = true, uiMode = Configuration.UI_MODE_NIGHT_YES) +private fun Preview_ChooseProviderBottomSheet() { + val providers = persistentListOf( ProviderState.Content( id = "1", name = "1inch", @@ -129,12 +127,18 @@ private fun ChooseProviderBottomSheet_Preview() { alertText = stringReference("Unavailable"), ), ) - TangemThemePreview(isDark = false) { - ChooseProviderBottomSheetContent( - ChooseProviderBottomSheetConfig( - selectedProviderId = "1", - providers = providers.toImmutableList(), + val content = ChooseProviderBottomSheetConfig( + selectedProviderId = "1", + providers = providers, + ) + TangemThemePreview { + ChooseProviderBottomSheet( + TangemBottomSheetConfig( + isShow = true, + onDismissRequest = {}, + content = content, ), ) } -} \ No newline at end of file +} +// endregion Preview \ No newline at end of file diff --git a/features/swap/presentation/src/main/java/com/tangem/feature/swap/ui/StateBuilder.kt b/features/swap/presentation/src/main/java/com/tangem/feature/swap/ui/StateBuilder.kt index e7d4edd818..517c795db6 100644 --- a/features/swap/presentation/src/main/java/com/tangem/feature/swap/ui/StateBuilder.kt +++ b/features/swap/presentation/src/main/java/com/tangem/feature/swap/ui/StateBuilder.kt @@ -2,8 +2,9 @@ package com.tangem.feature.swap.ui import androidx.compose.ui.text.TextRange import androidx.compose.ui.text.input.TextFieldValue +import com.tangem.common.ui.bottomsheet.permission.state.* import com.tangem.core.ui.components.bottomsheets.TangemBottomSheetConfig -import com.tangem.core.ui.components.currency.tokenicon.converter.CryptoCurrencyToIconStateConverter +import com.tangem.core.ui.components.currency.icon.converter.CryptoCurrencyToIconStateConverter import com.tangem.core.ui.components.notifications.NotificationConfig import com.tangem.core.ui.extensions.* import com.tangem.core.ui.utils.BigDecimalFormatter @@ -21,6 +22,8 @@ import com.tangem.feature.swap.models.states.* import com.tangem.feature.swap.presentation.R import com.tangem.feature.swap.viewmodels.SwapProcessDataState import com.tangem.utils.Provider +import com.tangem.utils.StringsSigns.DASH_SIGN +import com.tangem.utils.StringsSigns.TILDE_SIGN import kotlinx.collections.immutable.ImmutableList import kotlinx.collections.immutable.toImmutableList import java.math.BigDecimal @@ -225,6 +228,7 @@ internal class StateBuilder( quoteModel = quoteModel, fromToken = fromToken, selectedFeeType = selectedFeeType, + providerName = swapProvider.name, ) val feeState = createFeeState(quoteModel.txFee, selectedFeeType) val fromCurrencyStatus = quoteModel.fromTokenInfo.cryptoCurrencyStatus @@ -259,7 +263,11 @@ internal class StateBuilder( showWarning = true, actions.onReceiveCardWarningClick, ), - amountTextFieldValue = TextFieldValue(quoteModel.toTokenInfo.tokenAmount.formatToUIRepresentation()), + amountTextFieldValue = TextFieldValue( + quoteModel.toTokenInfo.tokenAmount + .formatToUIRepresentation() + .appendApproximateSign(), + ), amountEquivalent = getFormattedFiatAmount(quoteModel.toTokenInfo.amountFiat), token = toCurrencyStatus, tokenIconUrl = uiStateHolder.receiveCardData.tokenIconUrl, @@ -275,7 +283,7 @@ internal class StateBuilder( permissionState = convertPermissionState( lastPermissionState = uiStateHolder.permissionState, permissionDataState = quoteModel.permissionState, - providerName = quoteModel.swapProvider.name, + providerName = swapProvider.name, onGivePermissionClick = actions.onGivePermissionClick, onChangeApproveType = actions.onChangeApproveType, ), @@ -335,11 +343,12 @@ internal class StateBuilder( quoteModel: SwapState.QuotesLoadedState, fromToken: CryptoCurrency, selectedFeeType: FeeType, + providerName: String, ): List { val warnings = mutableListOf() maybeAddDomainWarnings(quoteModel, warnings) maybeAddNeedReserveToCreateAccountWarning(quoteModel, warnings) - maybeAddPermissionNeededWarning(quoteModel, warnings, fromToken, quoteModel.swapProvider.name) + maybeAddPermissionNeededWarning(quoteModel, warnings, fromToken, providerName) maybeAddNetworkFeeCoverageWarning(quoteModel, warnings, selectedFeeType) maybeAddUnableCoverFeeWarning(quoteModel, fromToken, warnings) maybeAddInsufficientFundsWarning(quoteModel, warnings) @@ -672,7 +681,7 @@ internal class StateBuilder( ), receiveCardData = receiveCardData, warnings = warnings, - permissionState = SwapPermissionState.Empty, + permissionState = GiveTxPermissionState.Empty, fee = FeeItemState.Empty, swapButton = SwapButton( enabled = false, @@ -811,7 +820,7 @@ internal class StateBuilder( tokenCurrency = uiStateHolder.receiveCardData.tokenCurrency, canSelectAnotherToken = uiStateHolder.receiveCardData.canSelectAnotherToken, networkIconRes = uiStateHolder.receiveCardData.networkIconRes, - balance = toTokenStatus?.getFormattedAmount(isNeedSymbol = false) ?: UNKNOWN_AMOUNT_SIGN, + balance = toTokenStatus?.getFormattedAmount(isNeedSymbol = false) ?: DASH_SIGN, isBalanceHidden = isBalanceHiddenProvider(), ), warnings = emptyList(), @@ -931,7 +940,7 @@ internal class StateBuilder( } fun updateApproveType(uiState: SwapStateHolder, approveType: ApproveType): SwapStateHolder { - val config = uiState.bottomSheetConfig?.content as? GivePermissionBottomSheetConfig + val config = uiState.bottomSheetConfig?.content as? GiveTxPermissionBottomSheetConfig return if (config != null) { uiState.copy( bottomSheetConfig = uiState.bottomSheetConfig.copy( @@ -1005,7 +1014,7 @@ internal class StateBuilder( ), ) return uiState.copy( - permissionState = SwapPermissionState.InProgress, + permissionState = GiveTxPermissionState.InProgress, warnings = warnings, ) } @@ -1166,29 +1175,28 @@ internal class StateBuilder( } private fun convertPermissionState( - lastPermissionState: SwapPermissionState, + lastPermissionState: GiveTxPermissionState, permissionDataState: PermissionDataState, providerName: String, onGivePermissionClick: () -> Unit, onChangeApproveType: (ApproveType) -> Unit, - ): SwapPermissionState { - val approveType = if (lastPermissionState is SwapPermissionState.ReadyForRequest) { + ): GiveTxPermissionState { + val approveType = if (lastPermissionState is GiveTxPermissionState.ReadyForRequest) { lastPermissionState.approveType } else { ApproveType.UNLIMITED } return when (permissionDataState) { - PermissionDataState.Empty -> SwapPermissionState.Empty - PermissionDataState.PermissionFailed -> SwapPermissionState.Empty - PermissionDataState.PermissionLoading -> SwapPermissionState.InProgress + PermissionDataState.Empty -> GiveTxPermissionState.Empty + PermissionDataState.PermissionFailed -> GiveTxPermissionState.Empty + PermissionDataState.PermissionLoading -> GiveTxPermissionState.InProgress is PermissionDataState.PermissionReadyForRequest -> { val permissionFee = when (val fee = permissionDataState.requestApproveData.fee) { TxFeeState.Empty -> error("Fee shouldn't be empty") is TxFeeState.MultipleFeeState -> fee.priorityFee is TxFeeState.SingleFeeState -> fee.fee } - SwapPermissionState.ReadyForRequest( - providerName = providerName, + GiveTxPermissionState.ReadyForRequest( currency = permissionDataState.currency, amount = permissionDataState.amount, approveType = approveType, @@ -1203,6 +1211,11 @@ internal class StateBuilder( enabled = true, ), onChangeApproveType = onChangeApproveType, + subtitle = resourceReference( + id = R.string.give_permission_swap_subtitle, + formatArgs = wrappedList(providerName, permissionDataState.currency), + ), + dialogText = resourceReference(R.string.swapping_approve_information_text), ) } } @@ -1221,8 +1234,8 @@ internal class StateBuilder( fun showPermissionBottomSheet(uiState: SwapStateHolder, onDismiss: () -> Unit): SwapStateHolder { val permissionState = uiState.permissionState - if (permissionState is SwapPermissionState.ReadyForRequest) { - val config = GivePermissionBottomSheetConfig( + if (permissionState is GiveTxPermissionState.ReadyForRequest) { + val config = GiveTxPermissionBottomSheetConfig( data = permissionState, onCancel = onDismiss, ) @@ -1430,7 +1443,7 @@ internal class StateBuilder( return NotificationConfig( title = resourceReference(R.string.express_provider_permission_needed), subtitle = resourceReference( - id = R.string.swapping_permission_subheader, + id = R.string.give_permission_swap_subtitle, formatArgs = wrappedList(providerName, fromTokenSymbol), ), iconResId = R.drawable.ic_locked_24, @@ -1661,14 +1674,14 @@ internal class StateBuilder( } private fun CryptoCurrencyStatus.getFormattedAmount(isNeedSymbol: Boolean): String { - val amount = value.amount ?: return UNKNOWN_AMOUNT_SIGN + val amount = value.amount ?: return DASH_SIGN val symbol = if (isNeedSymbol) currency.symbol else "" return BigDecimalFormatter.formatCryptoAmount(amount, symbol, currency.decimals) } @Suppress("UnusedPrivateMember") private fun CryptoCurrencyStatus.getFormattedFiatAmount(): String { - val fiatAmount = value.fiatAmount ?: return UNKNOWN_AMOUNT_SIGN + val fiatAmount = value.fiatAmount ?: return DASH_SIGN val appCurrency = appCurrencyProvider() return BigDecimalFormatter.formatFiatAmount(fiatAmount, appCurrency.code, appCurrency.symbol) @@ -1700,6 +1713,10 @@ internal class StateBuilder( } } + private fun String.appendApproximateSign(): String { + return "$TILDE_SIGN $this" + } + private companion object { private const val RU_LOCALE = "ru" private const val EN_LOCALE = "en" @@ -1707,7 +1724,6 @@ internal class StateBuilder( const val ADDRESS_FIRST_PART_LENGTH = 7 const val ADDRESS_SECOND_PART_LENGTH = 4 private const val PRICE_IMPACT_THRESHOLD = 0.1 - private const val UNKNOWN_AMOUNT_SIGN = "—" private const val MAX_DECIMALS_TO_SHOW = 8 private const val FEE_READ_MORE_URL_FIRST_PART = "https://tangem.com/" private const val FEE_READ_MORE_URL_SECOND_PART = "/blog/post/what-is-a-transaction-fee-and-why-do-we-need-it/" diff --git a/features/swap/presentation/src/main/java/com/tangem/feature/swap/ui/SwapPermissionBottomSheet.kt b/features/swap/presentation/src/main/java/com/tangem/feature/swap/ui/SwapPermissionBottomSheet.kt deleted file mode 100644 index 6c06e7e630..0000000000 --- a/features/swap/presentation/src/main/java/com/tangem/feature/swap/ui/SwapPermissionBottomSheet.kt +++ /dev/null @@ -1,319 +0,0 @@ -package com.tangem.feature.swap.ui - -import android.content.res.Configuration -import androidx.compose.foundation.background -import androidx.compose.foundation.clickable -import androidx.compose.foundation.layout.* -import androidx.compose.material.* -import androidx.compose.runtime.* -import androidx.compose.ui.Alignment -import androidx.compose.ui.Modifier -import androidx.compose.ui.res.painterResource -import androidx.compose.ui.res.stringResource -import androidx.compose.ui.text.style.TextAlign -import androidx.compose.ui.tooling.preview.Preview -import com.tangem.core.ui.components.* -import com.tangem.core.ui.components.bottomsheets.TangemBottomSheet -import com.tangem.core.ui.components.bottomsheets.TangemBottomSheetConfig -import com.tangem.core.ui.extensions.TextReference -import com.tangem.core.ui.extensions.resolveReference -import com.tangem.core.ui.res.TangemTheme -import com.tangem.core.ui.res.TangemThemePreview -import com.tangem.feature.swap.models.ApprovePermissionButton -import com.tangem.feature.swap.models.ApproveType -import com.tangem.feature.swap.models.CancelPermissionButton -import com.tangem.feature.swap.models.SwapPermissionState -import com.tangem.feature.swap.models.states.GivePermissionBottomSheetConfig -import com.tangem.feature.swap.presentation.R -import kotlinx.collections.immutable.ImmutableList - -@Composable -fun SwapPermissionBottomSheet(config: TangemBottomSheetConfig) { - TangemBottomSheet(config) { content: GivePermissionBottomSheetConfig -> - SwapPermissionBottomSheetContent(content = content) - } -} - -@Composable -private fun SwapPermissionBottomSheetContent(content: GivePermissionBottomSheetConfig) { - var isPermissionAlertShow by remember { mutableStateOf(false) } - val data = content.data - Column( - modifier = Modifier - .background(color = TangemTheme.colors.background.primary) - .fillMaxWidth() - .padding(horizontal = TangemTheme.dimens.spacing16), - horizontalAlignment = Alignment.CenterHorizontally, - ) { - Box(modifier = Modifier.fillMaxWidth()) { - Text( - modifier = Modifier.align(Alignment.Center), - text = stringResource(id = R.string.swapping_permission_header), - color = TangemTheme.colors.text.primary1, - style = TangemTheme.typography.subtitle1, - ) - IconButton( - modifier = Modifier.align(Alignment.CenterEnd), - onClick = { isPermissionAlertShow = true }, - ) { - Icon( - painter = painterResource(id = R.drawable.ic_question_24), - contentDescription = null, - ) - } - } - - SpacerH10() - - Text( - text = stringResource( - id = R.string.swapping_permission_subheader, - data.providerName, - data.currency, - ), - color = TangemTheme.colors.text.secondary, - style = TangemTheme.typography.body2, - textAlign = TextAlign.Center, - modifier = Modifier.padding(horizontal = TangemTheme.dimens.spacing8), - ) - - SpacerH16() - - ApprovalBottomSheetInfo(data) - - SpacerH28() - - PrimaryButtonIconEnd( - text = stringResource(id = R.string.swapping_permission_buttons_approve), - iconResId = R.drawable.ic_tangem_24, - modifier = Modifier.fillMaxWidth(), - onClick = data.approveButton.onClick, - ) - - SpacerH12() - - SecondaryButton( - text = stringResource(id = R.string.common_cancel), - modifier = Modifier.fillMaxWidth(), - onClick = { - content.onCancel() - }, - ) - - SpacerH16() - - // region dialog - if (isPermissionAlertShow) { - BasicDialog( - message = stringResource(id = R.string.swapping_approve_information_text), - title = stringResource(id = R.string.swapping_approve_information_title), - confirmButton = DialogButton { isPermissionAlertShow = false }, - onDismissDialog = {}, - ) - } - } -} - -@Composable -private fun ApprovalBottomSheetInfo(data: SwapPermissionState.ReadyForRequest) { - Column( - modifier = Modifier - .background(color = TangemTheme.colors.background.primary) - .fillMaxWidth(), - horizontalAlignment = Alignment.CenterHorizontally, - ) { - AmountItem( - currency = data.currency, - approveType = data.approveType, - onChangeApproveType = data.onChangeApproveType, - approveItems = data.approveItems, - ) - SubtitleItem( - subtitle = stringResource(id = R.string.swapping_permission_policy_type_footer), - modifier = Modifier.fillMaxWidth(), - ) - SpacerH24() - DividerBottomSheet() - FeeItem(fee = data.fee.resolveReference()) - SubtitleItem( - subtitle = stringResource(id = R.string.swapping_permission_fee_footer), - modifier = Modifier.fillMaxWidth(), - ) - } -} - -@Composable -private fun DividerBottomSheet() { - Divider( - color = TangemTheme.colors.stroke.primary, - thickness = TangemTheme.dimens.size0_5, - ) -} - -@Composable -private fun InformationItem(subtitle: String, value: String) { - Row( - modifier = Modifier - .fillMaxWidth() - .padding(vertical = TangemTheme.dimens.spacing16), - horizontalArrangement = Arrangement.SpaceBetween, - verticalAlignment = Alignment.CenterVertically, - ) { - Text( - text = subtitle, - color = TangemTheme.colors.text.primary1, - style = TangemTheme.typography.subtitle1, - maxLines = 1, - ) - - MiddleEllipsisText( - text = value, - color = TangemTheme.colors.text.tertiary, - style = TangemTheme.typography.body2, - modifier = Modifier.padding(start = TangemTheme.dimens.spacing16), - ) - } -} - -@Composable -private fun AmountItem( - currency: String, - approveType: ApproveType, - approveItems: ImmutableList, - onChangeApproveType: (ApproveType) -> Unit, -) { - var isExpandSelector by remember { - mutableStateOf(false) - } - Row( - modifier = Modifier - .fillMaxWidth() - .padding(vertical = TangemTheme.dimens.spacing16), - horizontalArrangement = Arrangement.SpaceBetween, - verticalAlignment = Alignment.CenterVertically, - ) { - Text( - text = stringResource(id = R.string.swapping_permission_rows_amount, currency), - color = TangemTheme.colors.text.primary1, - style = TangemTheme.typography.subtitle1, - maxLines = 1, - ) - Box { - SelectorItem( - getTitleForApproveType(approveType = approveType), - ) { - isExpandSelector = true - } - DropdownSelector( - isExpanded = isExpandSelector, - onDismiss = { isExpandSelector = false }, - onItemClick = { approveType -> - isExpandSelector = false - onChangeApproveType.invoke(approveType) - }, - items = approveItems, - ) - } - } -} - -@Composable -private fun SelectorItem(title: String, onClick: () -> Unit) { - Row( - modifier = Modifier.clickable { onClick() }, - ) { - Text( - text = title, - color = TangemTheme.colors.text.primary1, - style = TangemTheme.typography.body1, - maxLines = 1, - ) - Icon( - painter = painterResource(id = R.drawable.ic_chevron_24), - tint = TangemTheme.colors.icon.primary1, - contentDescription = null, - ) - } -} - -@Composable -private fun DropdownSelector( - isExpanded: Boolean, - onDismiss: () -> Unit, - onItemClick: (ApproveType) -> Unit, - items: ImmutableList, -) { - DropdownMenu( - expanded = isExpanded, - onDismissRequest = onDismiss, - modifier = Modifier - .wrapContentSize() - .background(TangemTheme.colors.background.secondary), - ) { - items.forEach { item -> - DropdownMenuItem( - onClick = { - onItemClick.invoke(item) - }, - ) { - Text( - text = getTitleForApproveType(approveType = item), - color = TangemTheme.colors.text.primary1, - style = TangemTheme.typography.body1, - maxLines = 1, - ) - } - } - } -} - -@Composable -private fun FeeItem(fee: String) { - InformationItem( - subtitle = stringResource(id = R.string.common_network_fee_title), - value = fee, - ) -} - -@Composable -private fun SubtitleItem(subtitle: String, modifier: Modifier = Modifier) { - Text( - modifier = modifier, - text = subtitle, - color = TangemTheme.colors.text.secondary, - style = TangemTheme.typography.body2, - ) -} - -@Composable -private fun getTitleForApproveType(approveType: ApproveType): String = when (approveType) { - ApproveType.LIMITED -> stringResource(id = R.string.swapping_permission_current_transaction) - ApproveType.UNLIMITED -> stringResource(id = R.string.swapping_permission_unlimited) -} - -// region preview - -@Preview -@Preview(uiMode = Configuration.UI_MODE_NIGHT_YES) -@Composable -private fun Preview_AgreementBottomSheet() { - TangemThemePreview { - SwapPermissionBottomSheetContent(content = previewData) - } -} - -private val previewData = GivePermissionBottomSheetConfig( - data = SwapPermissionState.ReadyForRequest( - providerName = "1inch", - currency = "DAI", - amount = "∞", - walletAddress = "", - spenderAddress = "", - fee = TextReference.Str("2,14$"), - approveType = ApproveType.UNLIMITED, - approveButton = ApprovePermissionButton(true) {}, - cancelButton = CancelPermissionButton(true), - onChangeApproveType = { ApproveType.UNLIMITED }, - ), - onCancel = {}, -) \ No newline at end of file diff --git a/features/swap/presentation/src/main/java/com/tangem/feature/swap/ui/SwapScreen.kt b/features/swap/presentation/src/main/java/com/tangem/feature/swap/ui/SwapScreen.kt index 04a53a581c..7379f7ad2a 100644 --- a/features/swap/presentation/src/main/java/com/tangem/feature/swap/ui/SwapScreen.kt +++ b/features/swap/presentation/src/main/java/com/tangem/feature/swap/ui/SwapScreen.kt @@ -1,17 +1,20 @@ package com.tangem.feature.swap.ui import androidx.activity.compose.BackHandler -import androidx.compose.foundation.layout.* +import androidx.compose.foundation.layout.padding +import androidx.compose.foundation.layout.systemBarsPadding import androidx.compose.material3.Scaffold import androidx.compose.runtime.Composable import androidx.compose.ui.Modifier import androidx.compose.ui.res.stringResource +import com.tangem.common.ui.bottomsheet.permission.GiveTxPermissionBottomSheet +import com.tangem.common.ui.bottomsheet.permission.state.GiveTxPermissionBottomSheetConfig import com.tangem.core.ui.components.appbar.AppBarWithBackButton import com.tangem.core.ui.res.TangemTheme +import com.tangem.core.ui.utils.WindowInsetsZero import com.tangem.feature.swap.models.SwapStateHolder import com.tangem.feature.swap.models.states.ChooseFeeBottomSheetConfig import com.tangem.feature.swap.models.states.ChooseProviderBottomSheetConfig -import com.tangem.feature.swap.models.states.GivePermissionBottomSheetConfig import com.tangem.feature.swap.models.states.WebViewBottomSheetConfig import com.tangem.feature.swap.presentation.R @@ -28,7 +31,7 @@ internal fun SwapScreen(stateHolder: SwapStateHolder) { iconRes = R.drawable.ic_close_24, ) }, - contentWindowInsets = WindowInsets(left = 0, top = 0, right = 0, bottom = 0), + contentWindowInsets = WindowInsetsZero, containerColor = TangemTheme.colors.background.secondary, ) { scaffoldPaddings -> @@ -39,8 +42,8 @@ internal fun SwapScreen(stateHolder: SwapStateHolder) { stateHolder.bottomSheetConfig?.let { config -> when (config.content) { - is GivePermissionBottomSheetConfig -> { - SwapPermissionBottomSheet(config = config) + is GiveTxPermissionBottomSheetConfig -> { + GiveTxPermissionBottomSheet(config = config) } is ChooseProviderBottomSheetConfig -> { ChooseProviderBottomSheet(config = config) diff --git a/features/swap/presentation/src/main/java/com/tangem/feature/swap/ui/SwapScreenContent.kt b/features/swap/presentation/src/main/java/com/tangem/feature/swap/ui/SwapScreenContent.kt index fc0b98feb3..f3004d1c73 100644 --- a/features/swap/presentation/src/main/java/com/tangem/feature/swap/ui/SwapScreenContent.kt +++ b/features/swap/presentation/src/main/java/com/tangem/feature/swap/ui/SwapScreenContent.kt @@ -23,7 +23,7 @@ import androidx.compose.ui.text.style.TextAlign import androidx.compose.ui.text.withStyle import androidx.compose.ui.tooling.preview.Preview import androidx.constraintlayout.compose.ConstraintLayout -import com.tangem.common.Strings.STARS +import com.tangem.common.ui.bottomsheet.permission.state.GiveTxPermissionState import com.tangem.core.ui.components.* import com.tangem.core.ui.components.notifications.Notification import com.tangem.core.ui.components.notifications.NotificationConfig @@ -38,6 +38,7 @@ import com.tangem.feature.swap.models.* import com.tangem.feature.swap.models.states.FeeItemState import com.tangem.feature.swap.models.states.ProviderState import com.tangem.feature.swap.presentation.R +import com.tangem.utils.StringsSigns.STARS @Suppress("LongMethod") @Composable @@ -414,7 +415,7 @@ private fun MainButton(state: SwapStateHolder, onPermissionWarningClick: () -> U state.warnings.any { it is SwapWarning.PermissionNeeded } -> { PrimaryButton( modifier = Modifier.fillMaxWidth(), - text = stringResource(id = R.string.swapping_give_permission), + text = stringResource(id = R.string.give_permission_title), enabled = true, onClick = onPermissionWarningClick, ) @@ -495,7 +496,7 @@ private val state = SwapStateHolder( onRefresh = {}, onBackClicked = {}, onChangeCardsClicked = {}, - permissionState = SwapPermissionState.InProgress, + permissionState = GiveTxPermissionState.InProgress, blockchainId = "POLYGON", providerState = ProviderState.Loading(), priceImpact = PriceImpact.Empty(), diff --git a/features/swap/presentation/src/main/java/com/tangem/feature/swap/ui/SwapSelectTokenScreen.kt b/features/swap/presentation/src/main/java/com/tangem/feature/swap/ui/SwapSelectTokenScreen.kt index 081b492357..5066dc9be6 100644 --- a/features/swap/presentation/src/main/java/com/tangem/feature/swap/ui/SwapSelectTokenScreen.kt +++ b/features/swap/presentation/src/main/java/com/tangem/feature/swap/ui/SwapSelectTokenScreen.kt @@ -10,7 +10,7 @@ import androidx.compose.foundation.lazy.LazyListScope import androidx.compose.foundation.lazy.itemsIndexed import androidx.compose.material.Scaffold import androidx.compose.material.Text -import androidx.compose.runtime.* +import androidx.compose.runtime.Composable import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.ColorFilter @@ -18,18 +18,21 @@ import androidx.compose.ui.res.painterResource import androidx.compose.ui.res.stringResource import androidx.compose.ui.text.style.TextAlign import androidx.compose.ui.tooling.preview.Preview -import com.tangem.common.Strings -import com.tangem.core.ui.components.* +import com.tangem.core.ui.components.SpacerH12 +import com.tangem.core.ui.components.SpacerW2 import com.tangem.core.ui.components.appbar.ExpandableSearchView -import com.tangem.core.ui.components.currency.tokenicon.TokenIcon -import com.tangem.core.ui.components.currency.tokenicon.TokenIconState +import com.tangem.core.ui.components.currency.icon.CurrencyIcon +import com.tangem.core.ui.components.currency.icon.CurrencyIconState import com.tangem.core.ui.decorations.roundedShapeItemDecoration import com.tangem.core.ui.extensions.resolveReference import com.tangem.core.ui.extensions.stringReference import com.tangem.core.ui.res.TangemTheme import com.tangem.core.ui.res.TangemThemePreview -import com.tangem.feature.swap.models.* +import com.tangem.feature.swap.models.SwapSelectTokenStateHolder +import com.tangem.feature.swap.models.TokenBalanceData +import com.tangem.feature.swap.models.TokenToSelectState import com.tangem.feature.swap.presentation.R +import com.tangem.utils.StringsSigns import kotlinx.collections.immutable.ImmutableList import kotlinx.collections.immutable.toImmutableList @@ -212,7 +215,7 @@ private fun TokenItem( ), verticalAlignment = Alignment.CenterVertically, ) { - TokenIcon( + CurrencyIcon( state = token.tokenIcon, shouldDisplayNetwork = true, ) @@ -251,7 +254,7 @@ private fun TokenItem( text = if (token.addedTokenBalanceData.isBalanceHidden && !token.addedTokenBalanceData.amountEquivalent.isNullOrEmpty() ) { - Strings.STARS + StringsSigns.STARS } else { token.addedTokenBalanceData.amountEquivalent.orEmpty() }, @@ -267,7 +270,7 @@ private fun TokenItem( text = if (token.addedTokenBalanceData.isBalanceHidden && !token.addedTokenBalanceData.amount.isNullOrEmpty() ) { - Strings.STARS + StringsSigns.STARS } else { token.addedTokenBalanceData.amount.orEmpty() }, @@ -280,7 +283,7 @@ private fun TokenItem( } private val token = TokenToSelectState.TokenToSelect( - tokenIcon = TokenIconState.CoinIcon( + tokenIcon = CurrencyIconState.CoinIcon( url = "", fallbackResId = 0, isGrayscale = false, diff --git a/features/swap/presentation/src/main/java/com/tangem/feature/swap/ui/SwapSuccessScreen.kt b/features/swap/presentation/src/main/java/com/tangem/feature/swap/ui/SwapSuccessScreen.kt index 6f1b0517ff..335a399520 100644 --- a/features/swap/presentation/src/main/java/com/tangem/feature/swap/ui/SwapSuccessScreen.kt +++ b/features/swap/presentation/src/main/java/com/tangem/feature/swap/ui/SwapSuccessScreen.kt @@ -12,7 +12,7 @@ import androidx.compose.ui.res.stringResource import androidx.compose.ui.tooling.preview.Preview import com.tangem.core.ui.components.* import com.tangem.core.ui.components.appbar.AppBarWithBackButton -import com.tangem.core.ui.components.currency.tokenicon.TokenIconState +import com.tangem.core.ui.components.currency.icon.CurrencyIconState import com.tangem.core.ui.components.inputrow.InputRowBestRate import com.tangem.core.ui.components.inputrow.InputRowDefault import com.tangem.core.ui.components.inputrow.InputRowImage @@ -65,7 +65,7 @@ private fun SwapSuccessScreenContent(state: SwapSuccessStateHolder, padding: Pad title = TextReference.Res(R.string.swapping_from_title), subtitle = state.fromTokenAmount, caption = state.fromTokenFiatAmount, - tokenIconState = state.fromTokenIconState ?: TokenIconState.Loading, + tokenIconState = state.fromTokenIconState ?: CurrencyIconState.Loading, modifier = Modifier .clip(TangemTheme.shapes.roundedCornersXMedium) .background(TangemTheme.colors.background.action), @@ -76,7 +76,7 @@ private fun SwapSuccessScreenContent(state: SwapSuccessStateHolder, padding: Pad title = TextReference.Res(R.string.swapping_to_title), subtitle = state.toTokenAmount, caption = state.toTokenFiatAmount, - tokenIconState = state.toTokenIconState ?: TokenIconState.Loading, + tokenIconState = state.toTokenIconState ?: CurrencyIconState.Loading, modifier = Modifier .clip(TangemTheme.shapes.roundedCornersXMedium) .background(TangemTheme.colors.background.action), @@ -161,8 +161,8 @@ private val state = SwapSuccessStateHolder( toTokenAmount = TextReference.Str("1 000 MATIC"), fromTokenFiatAmount = TextReference.Str("1 000 $"), toTokenFiatAmount = TextReference.Str("1 000 $"), - fromTokenIconState = TokenIconState.Loading, - toTokenIconState = TokenIconState.Loading, + fromTokenIconState = CurrencyIconState.Loading, + toTokenIconState = CurrencyIconState.Loading, rate = TextReference.Str("1 000 DAI ~ 1 000 MATIC"), onExploreButtonClick = {}, onStatusButtonClick = {}, diff --git a/features/swap/presentation/src/main/java/com/tangem/feature/swap/viewmodels/SwapProcessDataState.kt b/features/swap/presentation/src/main/java/com/tangem/feature/swap/viewmodels/SwapProcessDataState.kt index aada4b7d2b..8a505fb148 100644 --- a/features/swap/presentation/src/main/java/com/tangem/feature/swap/viewmodels/SwapProcessDataState.kt +++ b/features/swap/presentation/src/main/java/com/tangem/feature/swap/viewmodels/SwapProcessDataState.kt @@ -1,5 +1,6 @@ package com.tangem.feature.swap.viewmodels +import com.tangem.common.ui.bottomsheet.permission.state.ApproveType import com.tangem.domain.tokens.model.CryptoCurrencyStatus import com.tangem.feature.swap.domain.models.domain.SwapDataModel import com.tangem.feature.swap.domain.models.domain.SwapProvider @@ -7,7 +8,6 @@ import com.tangem.feature.swap.domain.models.ui.RequestApproveStateData import com.tangem.feature.swap.domain.models.ui.SwapState import com.tangem.feature.swap.domain.models.ui.TokensDataStateExpress import com.tangem.feature.swap.domain.models.ui.TxFee -import com.tangem.feature.swap.models.ApproveType data class SwapProcessDataState( // Initial network id diff --git a/features/swap/presentation/src/main/java/com/tangem/feature/swap/viewmodels/SwapViewModel.kt b/features/swap/presentation/src/main/java/com/tangem/feature/swap/viewmodels/SwapViewModel.kt index 58731f8a00..f02139cb42 100644 --- a/features/swap/presentation/src/main/java/com/tangem/feature/swap/viewmodels/SwapViewModel.kt +++ b/features/swap/presentation/src/main/java/com/tangem/feature/swap/viewmodels/SwapViewModel.kt @@ -1,15 +1,20 @@ package com.tangem.feature.swap.viewmodels +import android.os.Bundle import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.setValue import androidx.lifecycle.* import arrow.core.Either import arrow.core.getOrElse +import com.tangem.common.routing.AppRoute +import com.tangem.common.routing.bundle.unbundle +import com.tangem.common.ui.bottomsheet.permission.state.ApproveType import com.tangem.core.analytics.api.AnalyticsEventHandler import com.tangem.core.analytics.models.AnalyticsParam import com.tangem.core.analytics.models.Basic import com.tangem.core.ui.extensions.TextReference +import com.tangem.core.ui.extensions.resourceReference import com.tangem.core.ui.utils.InputNumberFormatter import com.tangem.domain.appcurrency.GetSelectedAppCurrencyUseCase import com.tangem.domain.appcurrency.model.AppCurrency @@ -31,8 +36,10 @@ import com.tangem.feature.swap.domain.models.SwapAmount import com.tangem.feature.swap.domain.models.domain.* import com.tangem.feature.swap.domain.models.formatToUIRepresentation import com.tangem.feature.swap.domain.models.ui.* -import com.tangem.feature.swap.models.* -import com.tangem.feature.swap.presentation.SwapFragment +import com.tangem.feature.swap.models.SwapStateHolder +import com.tangem.feature.swap.models.SwapWarning +import com.tangem.feature.swap.models.UiActions +import com.tangem.feature.swap.presentation.R import com.tangem.feature.swap.router.SwapNavScreen import com.tangem.feature.swap.router.SwapRouter import com.tangem.feature.swap.ui.StateBuilder @@ -70,8 +77,10 @@ internal class SwapViewModel @Inject constructor( savedStateHandle: SavedStateHandle, ) : ViewModel(), DefaultLifecycleObserver { - private val initialCryptoCurrency: CryptoCurrency = - savedStateHandle[SwapFragment.CURRENCY_BUNDLE_KEY] ?: error("no expected parameter CryptoCurrency found`") + private val initialCryptoCurrency: CryptoCurrency = savedStateHandle.get(AppRoute.Swap.CURRENCY_BUNDLE_KEY) + ?.unbundle(CryptoCurrency.serializer()) + ?: error("no expected parameter CryptoCurrency found`") + private lateinit var initialCryptoCurrencyStatus: CryptoCurrencyStatus private var isBalanceHidden = true @@ -488,9 +497,9 @@ internal class SwapViewModel @Inject constructor( } val fromCurrency = requireNotNull(dataState.fromCryptoCurrency) val fee = dataState.selectedFee - // TODO: unexpected crash for some users, this workaround to prevent app crash and follow to support + if (fee == null) { - makeDefaultAlert(TextReference.Str("Fee estimation error. Please send feedback to support.")) + makeDefaultAlert(resourceReference(R.string.swapping_fee_estimation_error_text)) return } viewModelScope.launch(dispatchers.main) { @@ -567,72 +576,80 @@ internal class SwapViewModel @Inject constructor( private fun sendSuccessEvent() { val provider = dataState.selectedProvider ?: return val fee = dataState.selectedFee?.feeType ?: return - val sendToken = dataState.fromCryptoCurrency?.currency?.symbol ?: return - val toToken = dataState.toCryptoCurrency?.currency?.symbol ?: return + val fromCurrency = dataState.fromCryptoCurrency?.currency ?: return + val toCurrency = dataState.toCryptoCurrency?.currency ?: return analyticsEventHandler.send( SwapEvents.SwapInProgressScreen( provider = provider, commission = fee, - sendToken = sendToken, - receiveToken = toToken, + sendBlockchain = fromCurrency.network.name, + receiveBlockchain = toCurrency.network.name, + sendToken = fromCurrency.symbol, + receiveToken = toCurrency.symbol, ), ) } private fun givePermissionsToSwap() { viewModelScope.launch(dispatchers.main) { - val fromToken = requireNotNull(dataState.fromCryptoCurrency?.currency) { - "dataState.fromCurrency might not be null" - } - val feeForPermission = when (val fee = dataState.approveDataModel?.fee) { - TxFeeState.Empty -> error("Fee should not be Empty") - is TxFeeState.MultipleFeeState -> fee.priorityFee - is TxFeeState.SingleFeeState -> fee.fee - null -> error("Fee should not be null") - } - val approveType = requireNotNull(dataState.approveType) { - "uiState.permissionState should not be null" - }.toDomainApproveType() - runCatching(dispatchers.io) { - swapInteractor.givePermissionToSwap( - networkId = fromToken.network.backendId, - permissionOptions = PermissionOptions( - approveData = requireNotNull(dataState.approveDataModel) { - "dataState.approveDataModel might not be null" - }, - forTokenContractAddress = (dataState.fromCryptoCurrency?.currency as? CryptoCurrency.Token) - ?.contractAddress ?: "", - fromToken = fromToken, - approveType = approveType, - txFee = feeForPermission, - spenderAddress = requireNotNull(dataState.approveDataModel?.spenderAddress) { - "dataState.approveDataModel.spenderAddress shouldn't be null" - }, - ), - ) - }.onSuccess { - when (it) { - is SwapTransactionState.TxSent -> { - sendApproveSuccessEvent(fromToken, feeForPermission.feeType, approveType) - updateWalletBalance() - uiState = stateBuilder.loadingPermissionState(uiState) - uiState = stateBuilder.dismissBottomSheet(uiState) - startLoadingQuotesFromLastState(isSilent = true) + runCatching { + val fromToken = requireNotNull(dataState.fromCryptoCurrency?.currency) { + "dataState.fromCurrency might not be null" + } + val approveDataModel = requireNotNull(dataState.approveDataModel) { + "dataState.approveDataModel.spenderAddress shouldn't be null" + } + val approveType = requireNotNull(dataState.approveType?.toDomainApproveType()) { + "uiState.permissionState should not be null" + } + val feeForPermission = when (val fee = approveDataModel.fee) { + TxFeeState.Empty -> { + makeDefaultAlert(resourceReference(R.string.swapping_fee_estimation_error_text)) + Timber.e("Fee should not be Empty") + return@runCatching } - is SwapTransactionState.UserCancelled -> Unit - else -> { - uiState = stateBuilder.createErrorTransaction(uiState, it) { - uiState = stateBuilder.clearAlert(uiState) + is TxFeeState.MultipleFeeState -> fee.priorityFee + is TxFeeState.SingleFeeState -> fee.fee + } + runCatching(dispatchers.io) { + swapInteractor.givePermissionToSwap( + networkId = fromToken.network.backendId, + permissionOptions = PermissionOptions( + approveData = approveDataModel, + forTokenContractAddress = (fromToken as? CryptoCurrency.Token)?.contractAddress.orEmpty(), + fromToken = fromToken, + approveType = approveType, + txFee = feeForPermission, + spenderAddress = approveDataModel.spenderAddress, + ), + ) + }.onSuccess { + when (it) { + is SwapTransactionState.TxSent -> { + sendApproveSuccessEvent(fromToken, feeForPermission.feeType, approveType) + updateWalletBalance() + uiState = stateBuilder.loadingPermissionState(uiState) + uiState = stateBuilder.dismissBottomSheet(uiState) + startLoadingQuotesFromLastState(isSilent = true) + } + is SwapTransactionState.UserCancelled -> Unit + else -> { + uiState = stateBuilder.createErrorTransaction(uiState, it) { + uiState = stateBuilder.clearAlert(uiState) + } } } - } - }.onFailure { - makeDefaultAlert() - } + }.onFailure { makeDefaultAlert() } + }.onFailure { showGenericError(it.message.orEmpty()) } } } + private fun showGenericError(message: String) { + makeDefaultAlert(resourceReference(R.string.common_unknown_error)) + Timber.e(message) + } + private fun onSearchEntered(searchQuery: String) { viewModelScope.launch(dispatchers.io) { val tokenDataState = dataState.tokensDataState ?: return@launch @@ -830,7 +847,6 @@ internal class SwapViewModel @Inject constructor( onAmountChanged(newAmount.formatToUIRepresentation()) } - @Suppress("UnusedPrivateMember") private fun onAmountSelected(selected: Boolean) { if (selected) { analyticsEventHandler.send(SwapEvents.SendTokenBalanceClicked) @@ -1172,6 +1188,13 @@ internal class SwapViewModel @Inject constructor( ) } + private fun ApproveType.toDomainApproveType(): SwapApproveType { + return when (this) { + ApproveType.LIMITED -> SwapApproveType.LIMITED + ApproveType.UNLIMITED -> SwapApproveType.UNLIMITED + } + } + private fun triggerPromoProviderEvent(recommendedProvider: SwapProvider?, bestQuotesProvider: SwapProvider?) { // for now send event only for changelly if (recommendedProvider == null || diff --git a/features/tester/api/src/main/java/com/tangem/features/tester/api/AppRestarter.kt b/features/tester/api/src/main/java/com/tangem/features/tester/api/AppRestarter.kt deleted file mode 100644 index a64be25542..0000000000 --- a/features/tester/api/src/main/java/com/tangem/features/tester/api/AppRestarter.kt +++ /dev/null @@ -1,9 +0,0 @@ -package com.tangem.features.tester.api - -/** - * Interface for app restarter - */ -interface AppRestarter { - - fun restart() -} \ No newline at end of file diff --git a/features/tester/api/src/main/java/com/tangem/features/tester/api/TesterRouter.kt b/features/tester/api/src/main/java/com/tangem/features/tester/api/TesterRouter.kt index 913c04a076..7e647c8323 100644 --- a/features/tester/api/src/main/java/com/tangem/features/tester/api/TesterRouter.kt +++ b/features/tester/api/src/main/java/com/tangem/features/tester/api/TesterRouter.kt @@ -1,5 +1,7 @@ package com.tangem.features.tester.api +import android.content.Intent + /** * Outer tester feature router * @@ -8,5 +10,5 @@ package com.tangem.features.tester.api interface TesterRouter { /** Open tester menu */ - fun startTesterScreen() + fun getEntryIntent(): Intent } \ No newline at end of file diff --git a/features/tester/impl/build.gradle.kts b/features/tester/impl/build.gradle.kts index 86db03dca7..01480f6da6 100644 --- a/features/tester/impl/build.gradle.kts +++ b/features/tester/impl/build.gradle.kts @@ -39,6 +39,7 @@ dependencies { implementation(projects.core.featuretoggles) implementation(projects.core.ui) implementation(projects.core.utils) + implementation(projects.core.navigation) /** Feature Apis */ implementation(projects.features.tester.api) diff --git a/features/tester/impl/src/main/java/com/tangem/feature/tester/ActivityClassWrapper.kt b/features/tester/impl/src/main/java/com/tangem/feature/tester/ActivityClassWrapper.kt deleted file mode 100644 index 22d2d4d3a9..0000000000 --- a/features/tester/impl/src/main/java/com/tangem/feature/tester/ActivityClassWrapper.kt +++ /dev/null @@ -1,12 +0,0 @@ -package com.tangem.feature.tester - -import android.app.Activity - -/** - * Wraps the main activity class to avoid type erasure issues during injection. - * - * @property clazz activity class - */ -class ActivityClassWrapper( - val clazz: Class, -) \ No newline at end of file diff --git a/features/tester/impl/src/main/java/com/tangem/feature/tester/apprestarter/DefaultAppRestarter.kt b/features/tester/impl/src/main/java/com/tangem/feature/tester/apprestarter/DefaultAppRestarter.kt deleted file mode 100644 index 34cd927e71..0000000000 --- a/features/tester/impl/src/main/java/com/tangem/feature/tester/apprestarter/DefaultAppRestarter.kt +++ /dev/null @@ -1,27 +0,0 @@ -package com.tangem.feature.tester.apprestarter - -import android.app.Activity -import android.content.Context -import android.content.Intent -import com.tangem.feature.tester.ActivityClassWrapper -import com.tangem.features.tester.api.AppRestarter - -/** - * Entity that kills the process and restarts the main activity - * @property context Activity context - */ -internal class DefaultAppRestarter( - private val context: Context, - private val activityClassWrapper: ActivityClassWrapper, -) : AppRestarter { - - override fun restart() { - if (context !is Activity) return - - context.finish() - context.startActivity( - Intent(context, activityClassWrapper.clazz).apply { flags = Intent.FLAG_ACTIVITY_CLEAR_TOP }, - ) - Runtime.getRuntime().exit(0) - } -} \ No newline at end of file diff --git a/features/tester/impl/src/main/java/com/tangem/feature/tester/di/RestarterModule.kt b/features/tester/impl/src/main/java/com/tangem/feature/tester/di/RestarterModule.kt deleted file mode 100644 index 4891a60f12..0000000000 --- a/features/tester/impl/src/main/java/com/tangem/feature/tester/di/RestarterModule.kt +++ /dev/null @@ -1,26 +0,0 @@ -package com.tangem.feature.tester.di - -import android.content.Context -import com.tangem.feature.tester.ActivityClassWrapper -import com.tangem.feature.tester.apprestarter.DefaultAppRestarter -import com.tangem.features.tester.api.AppRestarter -import dagger.Module -import dagger.Provides -import dagger.hilt.InstallIn -import dagger.hilt.android.components.ActivityComponent -import dagger.hilt.android.qualifiers.ActivityContext -import dagger.hilt.android.scopes.ActivityScoped - -@Module -@InstallIn(ActivityComponent::class) -internal object RestarterModule { - - @Provides - @ActivityScoped - fun provideAppRestarter( - @ActivityContext context: Context, - activityClassWrapper: ActivityClassWrapper, - ): AppRestarter { - return DefaultAppRestarter(context, activityClassWrapper) - } -} \ No newline at end of file diff --git a/features/tester/impl/src/main/java/com/tangem/feature/tester/presentation/TesterActivity.kt b/features/tester/impl/src/main/java/com/tangem/feature/tester/presentation/TesterActivity.kt index ef7ab21998..62206ea5e5 100644 --- a/features/tester/impl/src/main/java/com/tangem/feature/tester/presentation/TesterActivity.kt +++ b/features/tester/impl/src/main/java/com/tangem/feature/tester/presentation/TesterActivity.kt @@ -6,8 +6,9 @@ import androidx.hilt.navigation.compose.hiltViewModel import androidx.navigation.compose.NavHost import androidx.navigation.compose.composable import androidx.navigation.compose.rememberNavController +import com.google.accompanist.systemuicontroller.rememberSystemUiController +import com.tangem.core.navigation.finisher.AppFinisher import com.tangem.core.ui.UiDependencies -import com.tangem.core.ui.components.SystemBarsEffect import com.tangem.core.ui.res.TangemTheme import com.tangem.core.ui.screen.ComposeActivity import com.tangem.feature.tester.presentation.actions.TesterActionsScreen @@ -18,7 +19,6 @@ import com.tangem.feature.tester.presentation.menu.state.TesterMenuContentState import com.tangem.feature.tester.presentation.menu.ui.TesterMenuScreen import com.tangem.feature.tester.presentation.navigation.InnerTesterRouter import com.tangem.feature.tester.presentation.navigation.TesterScreen -import com.tangem.features.tester.api.AppRestarter import com.tangem.features.tester.api.TesterRouter import dagger.hilt.android.AndroidEntryPoint import javax.inject.Inject @@ -35,7 +35,7 @@ internal class TesterActivity : ComposeActivity() { lateinit var testerRouter: TesterRouter @Inject - lateinit var appRestarter: AppRestarter + lateinit var appFinisher: AppFinisher private val innerTesterRouter: InnerTesterRouter get() = requireNotNull(testerRouter as? InnerTesterRouter) { @@ -45,9 +45,8 @@ internal class TesterActivity : ComposeActivity() { @Composable override fun ScreenContent(modifier: Modifier) { val systemBarsColor = TangemTheme.colors.background.secondary - SystemBarsEffect { - setSystemBarsColor(systemBarsColor) - } + val systemUiController = rememberSystemUiController() + systemUiController.setSystemBarsColor(systemBarsColor) TesterNavHost() } @@ -70,7 +69,7 @@ internal class TesterActivity : ComposeActivity() { composable(route = TesterScreen.FEATURE_TOGGLES.name) { val viewModel = hiltViewModel().apply { - setupInteractions(innerTesterRouter, appRestarter) + setupInteractions(innerTesterRouter, appFinisher) } FeatureTogglesScreen(state = viewModel.uiState) diff --git a/features/tester/impl/src/main/java/com/tangem/feature/tester/presentation/featuretoggles/viewmodels/FeatureTogglesViewModel.kt b/features/tester/impl/src/main/java/com/tangem/feature/tester/presentation/featuretoggles/viewmodels/FeatureTogglesViewModel.kt index d3459ac31f..2d810e1ebf 100644 --- a/features/tester/impl/src/main/java/com/tangem/feature/tester/presentation/featuretoggles/viewmodels/FeatureTogglesViewModel.kt +++ b/features/tester/impl/src/main/java/com/tangem/feature/tester/presentation/featuretoggles/viewmodels/FeatureTogglesViewModel.kt @@ -7,10 +7,10 @@ import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope import com.tangem.core.featuretoggle.manager.FeatureTogglesManager import com.tangem.core.featuretoggle.manager.MutableFeatureTogglesManager +import com.tangem.core.navigation.finisher.AppFinisher import com.tangem.feature.tester.presentation.featuretoggles.models.TesterFeatureToggle import com.tangem.feature.tester.presentation.featuretoggles.state.FeatureTogglesContentState import com.tangem.feature.tester.presentation.navigation.InnerTesterRouter -import com.tangem.features.tester.api.AppRestarter import com.tangem.utils.coroutines.CoroutineDispatcherProvider import dagger.hilt.android.lifecycle.HiltViewModel import kotlinx.coroutines.launch @@ -40,10 +40,10 @@ internal class FeatureTogglesViewModel @Inject constructor( } /** Setup navigation state property by router [router] and provides app restart method by [appRestarter] */ - fun setupInteractions(router: InnerTesterRouter, appRestarter: AppRestarter) { + fun setupInteractions(router: InnerTesterRouter, appFinisher: AppFinisher) { uiState = uiState.copy( onBackClick = router::back, - onApplyChangesClick = appRestarter::restart, + onApplyChangesClick = appFinisher::restart, ) } diff --git a/features/tester/impl/src/main/java/com/tangem/feature/tester/presentation/navigation/DefaultTesterRouter.kt b/features/tester/impl/src/main/java/com/tangem/feature/tester/presentation/navigation/DefaultTesterRouter.kt index 97126f3540..0d3c250e91 100644 --- a/features/tester/impl/src/main/java/com/tangem/feature/tester/presentation/navigation/DefaultTesterRouter.kt +++ b/features/tester/impl/src/main/java/com/tangem/feature/tester/presentation/navigation/DefaultTesterRouter.kt @@ -22,10 +22,8 @@ internal class DefaultTesterRouter @Inject constructor( private var navController: NavController? = null - override fun startTesterScreen() { - context.startActivity( - Intent(context, TesterActivity::class.java).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK), - ) + override fun getEntryIntent(): Intent { + return Intent(context, TesterActivity::class.java).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) } override fun setNavController(navController: NavController) { diff --git a/features/tokendetails/api/src/main/kotlin/com/tangem/features/tokendetails/navigation/TokenDetailsRouter.kt b/features/tokendetails/api/src/main/kotlin/com/tangem/features/tokendetails/navigation/TokenDetailsRouter.kt index a0f630c125..a361d75438 100644 --- a/features/tokendetails/api/src/main/kotlin/com/tangem/features/tokendetails/navigation/TokenDetailsRouter.kt +++ b/features/tokendetails/api/src/main/kotlin/com/tangem/features/tokendetails/navigation/TokenDetailsRouter.kt @@ -5,9 +5,4 @@ import androidx.fragment.app.Fragment interface TokenDetailsRouter { fun getEntryFragment(): Fragment - - companion object { - const val USER_WALLET_ID_KEY = "token_details_user_wallet_id" - const val CRYPTO_CURRENCY_KEY = "token_details_crypto_currency" - } } \ No newline at end of file diff --git a/features/tokendetails/impl/build.gradle.kts b/features/tokendetails/impl/build.gradle.kts index bff55fb9ad..73f39eae8c 100644 --- a/features/tokendetails/impl/build.gradle.kts +++ b/features/tokendetails/impl/build.gradle.kts @@ -38,13 +38,14 @@ dependencies { implementation(deps.tangem.card.core) implementation(deps.timber) implementation(deps.lifecycle.compose) + implementation(deps.kotlin.serialization) /** DI */ implementation(deps.hilt.android) kapt(deps.hilt.kapt) /** Core modules */ - implementation(projects.common) + implementation(projects.common.routing) implementation(projects.core.navigation) implementation(projects.core.ui) implementation(projects.core.utils) @@ -85,4 +86,6 @@ dependencies { /** Feature Apis */ implementation(projects.features.tokendetails.api) implementation(projects.features.send.api) + implementation(projects.features.staking.api) + } \ No newline at end of file diff --git a/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/di/TokenDetailsRouterModule.kt b/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/di/TokenDetailsRouterModule.kt index b87eb5b538..94147e5592 100644 --- a/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/di/TokenDetailsRouterModule.kt +++ b/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/di/TokenDetailsRouterModule.kt @@ -1,6 +1,8 @@ package com.tangem.feature.tokendetails.di -import com.tangem.core.navigation.ReduxNavController +import com.tangem.common.routing.AppRouter +import com.tangem.core.navigation.share.ShareManager +import com.tangem.core.navigation.url.UrlOpener import com.tangem.feature.tokendetails.presentation.router.DefaultTokenDetailsRouter import com.tangem.features.tokendetails.navigation.TokenDetailsRouter import dagger.Module @@ -15,7 +17,11 @@ internal object TokenDetailsRouterModule { @Provides @ActivityScoped - fun provideTokenDetailsRouter(reduxNavController: ReduxNavController): TokenDetailsRouter { - return DefaultTokenDetailsRouter(reduxNavController) + fun provideTokenDetailsRouter( + appRouter: AppRouter, + urlOpener: UrlOpener, + shareManager: ShareManager, + ): TokenDetailsRouter { + return DefaultTokenDetailsRouter(appRouter, urlOpener, shareManager) } } \ No newline at end of file diff --git a/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/presentation/TokenDetailsFragment.kt b/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/presentation/TokenDetailsFragment.kt index bd8ea330aa..25e7d71ad8 100644 --- a/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/presentation/TokenDetailsFragment.kt +++ b/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/presentation/TokenDetailsFragment.kt @@ -6,8 +6,7 @@ import androidx.compose.ui.platform.LocalLifecycleOwner import androidx.hilt.navigation.compose.hiltViewModel import androidx.lifecycle.compose.collectAsStateWithLifecycle import com.tangem.core.ui.UiDependencies -import com.tangem.core.ui.components.SystemBarsEffect -import com.tangem.core.ui.res.TangemTheme +import com.tangem.core.ui.components.NavigationBar3ButtonsScrim import com.tangem.core.ui.screen.ComposeFragment import com.tangem.feature.tokendetails.presentation.router.InnerTokenDetailsRouter import com.tangem.feature.tokendetails.presentation.tokendetails.ui.TokenDetailsScreen @@ -34,14 +33,8 @@ internal class TokenDetailsFragment : ComposeFragment() { override fun ScreenContent(modifier: Modifier) { val viewModel = hiltViewModel() viewModel.router = this@TokenDetailsFragment.internalTokenDetailsRouter - LocalLifecycleOwner.current.lifecycle.addObserver(viewModel) - - val systemBarsColor = TangemTheme.colors.background.secondary - SystemBarsEffect { - setSystemBarsColor(systemBarsColor) - } - + NavigationBar3ButtonsScrim() TokenDetailsScreen(state = viewModel.uiState.collectAsStateWithLifecycle().value) } } \ No newline at end of file diff --git a/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/presentation/router/DefaultTokenDetailsRouter.kt b/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/presentation/router/DefaultTokenDetailsRouter.kt index cadf3b9549..30a598c8df 100644 --- a/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/presentation/router/DefaultTokenDetailsRouter.kt +++ b/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/presentation/router/DefaultTokenDetailsRouter.kt @@ -1,41 +1,50 @@ package com.tangem.feature.tokendetails.presentation.router -import androidx.core.os.bundleOf import androidx.fragment.app.Fragment -import com.tangem.core.navigation.AppScreen -import com.tangem.core.navigation.NavigationAction -import com.tangem.core.navigation.ReduxNavController +import com.tangem.common.routing.AppRoute +import com.tangem.common.routing.AppRouter +import com.tangem.core.navigation.share.ShareManager +import com.tangem.core.navigation.url.UrlOpener +import com.tangem.domain.staking.model.stakekit.Yield import com.tangem.domain.tokens.model.CryptoCurrency import com.tangem.domain.wallets.models.UserWalletId import com.tangem.feature.tokendetails.presentation.TokenDetailsFragment -import com.tangem.features.tokendetails.navigation.TokenDetailsRouter internal class DefaultTokenDetailsRouter( - private val reduxNavController: ReduxNavController, + private val router: AppRouter, + private val urlOpener: UrlOpener, + private val shareManager: ShareManager, ) : InnerTokenDetailsRouter { override fun getEntryFragment(): Fragment = TokenDetailsFragment() override fun popBackStack() { - reduxNavController.navigate(NavigationAction.PopBackTo()) + router.pop() } override fun openUrl(url: String) { - reduxNavController.navigate(NavigationAction.OpenUrl(url = url)) + urlOpener.openUrl(url) } override fun share(text: String) { - reduxNavController.navigate(NavigationAction.Share(text)) + shareManager.shareText(text) } override fun openTokenDetails(userWalletId: UserWalletId, currency: CryptoCurrency) { - reduxNavController.navigate( - action = NavigationAction.NavigateTo( - screen = AppScreen.WalletDetails, - bundle = bundleOf( - TokenDetailsRouter.USER_WALLET_ID_KEY to userWalletId.stringValue, - TokenDetailsRouter.CRYPTO_CURRENCY_KEY to currency, - ), + router.push( + AppRoute.CurrencyDetails( + userWalletId = userWalletId, + currency = currency, + ), + ) + } + + override fun openStaking(userWalletId: UserWalletId, cryptoCurrency: CryptoCurrency, yield: Yield) { + router.push( + AppRoute.Staking( + userWalletId = userWalletId, + cryptoCurrencyId = cryptoCurrency.id, + yield = yield, ), ) } diff --git a/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/presentation/router/InnerTokenDetailsRouter.kt b/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/presentation/router/InnerTokenDetailsRouter.kt index 56eead22a5..b7c55e065b 100644 --- a/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/presentation/router/InnerTokenDetailsRouter.kt +++ b/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/presentation/router/InnerTokenDetailsRouter.kt @@ -1,5 +1,6 @@ package com.tangem.feature.tokendetails.presentation.router +import com.tangem.domain.staking.model.stakekit.Yield import com.tangem.domain.tokens.model.CryptoCurrency import com.tangem.domain.wallets.models.UserWalletId import com.tangem.features.tokendetails.navigation.TokenDetailsRouter @@ -16,4 +17,6 @@ internal interface InnerTokenDetailsRouter : TokenDetailsRouter { fun share(text: String) fun openTokenDetails(userWalletId: UserWalletId, currency: CryptoCurrency) + + fun openStaking(userWalletId: UserWalletId, cryptoCurrency: CryptoCurrency, yield: Yield) } \ No newline at end of file diff --git a/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/presentation/tokendetails/TokenDetailsPreviewData.kt b/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/presentation/tokendetails/TokenDetailsPreviewData.kt index 470cc0ac26..182ed49b47 100644 --- a/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/presentation/tokendetails/TokenDetailsPreviewData.kt +++ b/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/presentation/tokendetails/TokenDetailsPreviewData.kt @@ -9,7 +9,9 @@ import com.tangem.core.ui.components.transactions.state.TransactionState import com.tangem.core.ui.components.transactions.state.TxHistoryState import com.tangem.core.ui.event.consumedEvent import com.tangem.core.ui.extensions.TextReference +import com.tangem.core.ui.extensions.resourceReference import com.tangem.core.ui.extensions.stringReference +import com.tangem.core.ui.extensions.wrappedList import com.tangem.core.ui.res.TangemTheme import com.tangem.feature.tokendetails.presentation.tokendetails.state.* import com.tangem.feature.tokendetails.presentation.tokendetails.state.components.TokenDetailsActionButton @@ -17,7 +19,9 @@ import com.tangem.feature.tokendetails.presentation.tokendetails.state.component import com.tangem.features.tokendetails.impl.R import kotlinx.collections.immutable.persistentListOf import kotlinx.coroutines.flow.MutableStateFlow +import java.math.BigDecimal +@Suppress("LargeClass") internal object TokenDetailsPreviewData { val tokenDetailsTopAppBarConfig = TokenDetailsTopAppBarConfig( @@ -100,17 +104,60 @@ internal object TokenDetailsPreviewData { TokenDetailsActionButton.Swap(dimContent = false, onClick = {}), ) - val balanceLoading = TokenDetailsBalanceBlockState.Loading(actionButtons = actionButtons) + private val balanceSegmentedButtonConfig = persistentListOf( + TokenBalanceSegmentedButtonConfig( + title = resourceReference(R.string.common_all), + type = BalanceType.ALL, + ), + TokenBalanceSegmentedButtonConfig( + title = resourceReference(R.string.staking_details_available), + type = BalanceType.AVAILABLE, + ), + ) + + val balanceLoading = TokenDetailsBalanceBlockState.Loading( + actionButtons = actionButtons, + balanceSegmentedButtonConfig = balanceSegmentedButtonConfig, + selectedBalanceType = BalanceType.ALL, + ) val balanceContent = TokenDetailsBalanceBlockState.Content( actionButtons = actionButtons, - fiatBalance = "91,50$", - cryptoBalance = "966,96 XLM", + fiatBalance = BigDecimal.ZERO, + cryptoBalance = BigDecimal.ZERO, + balanceSegmentedButtonConfig = balanceSegmentedButtonConfig, + selectedBalanceType = BalanceType.ALL, + onBalanceSelect = {}, + displayCryptoBalance = "966,96 XLM", + displayFiatBalance = "91,50$", + isBalanceSelectorEnabled = false, + ) + val balanceError = TokenDetailsBalanceBlockState.Error( + actionButtons = actionButtons, + balanceSegmentedButtonConfig = balanceSegmentedButtonConfig, + selectedBalanceType = BalanceType.ALL, ) - val balanceError = TokenDetailsBalanceBlockState.Error(actionButtons = actionButtons) private val marketPriceLoading = MarketPriceBlockState.Loading(currencySymbol = "USDT") - private val stakingLoading = StakingBlockState.Loading(iconState = iconState) + val stakingLoadingBlock = StakingBlockUM.Loading(iconState) + val stakingErrorBlock = StakingBlockUM.Error(iconState) + + val stakingAvailableBlock = StakingBlockUM.StakeAvailable( + interestRate = "7.38", + periodInDays = 4, + tokenSymbol = "XLM", + iconState = iconState, + onStakeClicked = {}, + ) + + val stakedBlock = StakingBlockUM.Staked( + cryptoValue = stringReference("5 SOL"), + fiatValue = stringReference("456.34 $"), + rewardValue = resourceReference(R.string.staking_details_no_rewards_to_claim, wrappedList("0.43 $")), + cryptoAmount = BigDecimal.ZERO, + fiatAmount = BigDecimal.ZERO, + onStakeClicked = {}, + ) private val pullToRefreshConfig = TokenDetailsPullToRefreshConfig( isRefreshing = false, @@ -246,7 +293,7 @@ internal object TokenDetailsPreviewData { tokenInfoBlockState = tokenInfoBlockState, tokenBalanceBlockState = balanceLoading, marketPriceBlockState = marketPriceLoading, - stakingBlockState = stakingLoading, + stakingBlocksState = stakingLoadingBlock, notifications = persistentListOf(), txHistoryState = TxHistoryState.Content( contentItems = MutableStateFlow( @@ -260,7 +307,7 @@ internal object TokenDetailsPreviewData { bottomSheetConfig = null, isBalanceHidden = false, isMarketPriceAvailable = false, - isStakingAvailable = false, + isStakingBlockShown = false, event = consumedEvent(), ) @@ -278,12 +325,7 @@ internal object TokenDetailsPreviewData { type = PriceChangeType.UP, ), ), - stakingBlockState = StakingBlockState.Content( - interestRate = "7.38", - periodInDays = 4, - tokenSymbol = "XLM", - iconState = iconState, - ), + stakingBlocksState = stakingAvailableBlock, notifications = persistentListOf(), txHistoryState = TxHistoryState.NotSupported( onExploreClick = {}, @@ -296,7 +338,7 @@ internal object TokenDetailsPreviewData { bottomSheetConfig = null, isBalanceHidden = false, isMarketPriceAvailable = true, - isStakingAvailable = true, + isStakingBlockShown = true, event = consumedEvent(), ) @@ -306,5 +348,6 @@ internal object TokenDetailsPreviewData { value = PagingData.from(txHistoryItems), ), ), + stakingBlocksState = stakedBlock, ) } \ No newline at end of file diff --git a/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/presentation/tokendetails/state/StakingBlockState.kt b/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/presentation/tokendetails/state/StakingBlockState.kt deleted file mode 100644 index f1668235b6..0000000000 --- a/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/presentation/tokendetails/state/StakingBlockState.kt +++ /dev/null @@ -1,20 +0,0 @@ -package com.tangem.feature.tokendetails.presentation.tokendetails.state - -import androidx.compose.runtime.Immutable - -@Immutable -internal sealed interface StakingBlockState { - - val iconState: IconState - - data class Error(override val iconState: IconState) : StakingBlockState - - data class Loading(override val iconState: IconState) : StakingBlockState - - data class Content( - override val iconState: IconState, - val interestRate: String, - val periodInDays: Int, - val tokenSymbol: String, - ) : StakingBlockState -} \ No newline at end of file diff --git a/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/presentation/tokendetails/state/StakingBlockUM.kt b/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/presentation/tokendetails/state/StakingBlockUM.kt new file mode 100644 index 0000000000..91d76db70d --- /dev/null +++ b/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/presentation/tokendetails/state/StakingBlockUM.kt @@ -0,0 +1,29 @@ +package com.tangem.feature.tokendetails.presentation.tokendetails.state + +import androidx.compose.runtime.Stable +import com.tangem.core.ui.extensions.TextReference +import java.math.BigDecimal + +@Stable +internal sealed interface StakingBlockUM { + data class Error(val iconState: IconState) : StakingBlockUM + + data class Loading(val iconState: IconState) : StakingBlockUM + + data class Staked( + val cryptoValue: TextReference, + val fiatValue: TextReference, + val rewardValue: TextReference, + val cryptoAmount: BigDecimal?, + val fiatAmount: BigDecimal?, + val onStakeClicked: () -> Unit, + ) : StakingBlockUM + + data class StakeAvailable( + val iconState: IconState, + val interestRate: String, + val periodInDays: Int, + val tokenSymbol: String, + val onStakeClicked: () -> Unit, + ) : StakingBlockUM +} \ No newline at end of file diff --git a/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/presentation/tokendetails/state/SwapTransactionsState.kt b/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/presentation/tokendetails/state/SwapTransactionsState.kt index 923a5e73a1..26daa6490f 100644 --- a/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/presentation/tokendetails/state/SwapTransactionsState.kt +++ b/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/presentation/tokendetails/state/SwapTransactionsState.kt @@ -1,7 +1,7 @@ package com.tangem.feature.tokendetails.presentation.tokendetails.state import androidx.compose.runtime.Immutable -import com.tangem.core.ui.components.currency.tokenicon.TokenIconState +import com.tangem.core.ui.components.currency.icon.CurrencyIconState import com.tangem.core.ui.extensions.TextReference import com.tangem.domain.tokens.model.CryptoCurrency import com.tangem.feature.swap.domain.models.domain.ExchangeStatus @@ -23,11 +23,11 @@ internal data class SwapTransactionsState( val toCryptoCurrency: CryptoCurrency, val toCryptoAmount: String, val toFiatAmount: String, - val toCurrencyIcon: TokenIconState, + val toCurrencyIcon: CurrencyIconState, val fromCryptoCurrency: CryptoCurrency, val fromCryptoAmount: String, val fromFiatAmount: String, - val fromCurrencyIcon: TokenIconState, + val fromCurrencyIcon: CurrencyIconState, val showProviderLink: Boolean, val isRefundTerminalStatus: Boolean = true, val onClick: () -> Unit, diff --git a/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/presentation/tokendetails/state/TokenBalanceSegmentedButtonConfig.kt b/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/presentation/tokendetails/state/TokenBalanceSegmentedButtonConfig.kt new file mode 100644 index 0000000000..d741d3e609 --- /dev/null +++ b/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/presentation/tokendetails/state/TokenBalanceSegmentedButtonConfig.kt @@ -0,0 +1,13 @@ +package com.tangem.feature.tokendetails.presentation.tokendetails.state + +import com.tangem.core.ui.extensions.TextReference + +data class TokenBalanceSegmentedButtonConfig( + val title: TextReference, + val type: BalanceType, +) + +enum class BalanceType { + ALL, + AVAILABLE, +} \ No newline at end of file diff --git a/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/presentation/tokendetails/state/TokenDetailsBalanceBlockState.kt b/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/presentation/tokendetails/state/TokenDetailsBalanceBlockState.kt index 2f066dae01..3828253254 100644 --- a/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/presentation/tokendetails/state/TokenDetailsBalanceBlockState.kt +++ b/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/presentation/tokendetails/state/TokenDetailsBalanceBlockState.kt @@ -2,23 +2,36 @@ package com.tangem.feature.tokendetails.presentation.tokendetails.state import com.tangem.feature.tokendetails.presentation.tokendetails.state.components.TokenDetailsActionButton import kotlinx.collections.immutable.ImmutableList +import java.math.BigDecimal internal sealed class TokenDetailsBalanceBlockState { abstract val actionButtons: ImmutableList + abstract val balanceSegmentedButtonConfig: ImmutableList + abstract val selectedBalanceType: BalanceType data class Loading( override val actionButtons: ImmutableList, + override val balanceSegmentedButtonConfig: ImmutableList, + override val selectedBalanceType: BalanceType, ) : TokenDetailsBalanceBlockState() data class Content( override val actionButtons: ImmutableList, - val fiatBalance: String, - val cryptoBalance: String, + override val balanceSegmentedButtonConfig: ImmutableList, + override val selectedBalanceType: BalanceType, + val fiatBalance: BigDecimal?, + val cryptoBalance: BigDecimal?, + val onBalanceSelect: (TokenBalanceSegmentedButtonConfig) -> Unit, + val displayCryptoBalance: String, + val displayFiatBalance: String, + val isBalanceSelectorEnabled: Boolean, ) : TokenDetailsBalanceBlockState() data class Error( override val actionButtons: ImmutableList, + override val balanceSegmentedButtonConfig: ImmutableList, + override val selectedBalanceType: BalanceType, ) : TokenDetailsBalanceBlockState() fun copyActionButtons(buttons: ImmutableList): TokenDetailsBalanceBlockState { diff --git a/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/presentation/tokendetails/state/TokenDetailsState.kt b/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/presentation/tokendetails/state/TokenDetailsState.kt index 26f36f81ad..f6b3d59719 100644 --- a/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/presentation/tokendetails/state/TokenDetailsState.kt +++ b/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/presentation/tokendetails/state/TokenDetailsState.kt @@ -17,7 +17,7 @@ internal data class TokenDetailsState( val tokenInfoBlockState: TokenInfoBlockState, val tokenBalanceBlockState: TokenDetailsBalanceBlockState, val marketPriceBlockState: MarketPriceBlockState, - val stakingBlockState: StakingBlockState, + val stakingBlocksState: StakingBlockUM, val notifications: ImmutableList, val pendingTxs: PersistentList, val swapTxs: PersistentList, @@ -27,6 +27,6 @@ internal data class TokenDetailsState( val bottomSheetConfig: TangemBottomSheetConfig?, val isBalanceHidden: Boolean, val isMarketPriceAvailable: Boolean, - val isStakingAvailable: Boolean, + val isStakingBlockShown: Boolean, val event: StateEvent, ) \ No newline at end of file diff --git a/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/presentation/tokendetails/state/components/ExchangeStatusNotifications.kt b/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/presentation/tokendetails/state/components/ExchangeStatusNotifications.kt index fd9625e5c3..47508d351e 100644 --- a/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/presentation/tokendetails/state/components/ExchangeStatusNotifications.kt +++ b/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/presentation/tokendetails/state/components/ExchangeStatusNotifications.kt @@ -5,7 +5,7 @@ import androidx.compose.ui.res.stringResource import androidx.compose.ui.text.SpanStyle import androidx.compose.ui.text.buildAnnotatedString import androidx.compose.ui.text.withStyle -import com.tangem.core.ui.components.currency.tokenicon.converter.CryptoCurrencyToIconStateConverter +import com.tangem.core.ui.components.currency.icon.converter.CryptoCurrencyToIconStateConverter import com.tangem.core.ui.components.notifications.CurrencyNotificationConfig import com.tangem.core.ui.components.notifications.NotificationConfig import com.tangem.core.ui.extensions.resourceReference diff --git a/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/presentation/tokendetails/state/components/TokenDetailsActionButton.kt b/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/presentation/tokendetails/state/components/TokenDetailsActionButton.kt index c5b6078527..f3104d8636 100644 --- a/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/presentation/tokendetails/state/components/TokenDetailsActionButton.kt +++ b/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/presentation/tokendetails/state/components/TokenDetailsActionButton.kt @@ -91,4 +91,19 @@ internal sealed class TokenDetailsActionButton(val config: ActionButtonConfig) { dimContent = dimContent, ), ) + + /** + * Staking + * + * @property dimContent determines whether the button content will be dimmed + * @property onClick lambda be invoked when Swap button is clicked + */ + data class Stake(val dimContent: Boolean, override val onClick: () -> Unit) : TokenDetailsActionButton( + config = ActionButtonConfig( + text = TextReference.Res(id = R.string.common_stake), + iconResId = R.drawable.ic_staking_24, + onClick = onClick, + dimContent = dimContent, + ), + ) } \ No newline at end of file diff --git a/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/presentation/tokendetails/state/factory/TokenDetailsActionButtonsConverter.kt b/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/presentation/tokendetails/state/factory/TokenDetailsActionButtonsConverter.kt index dbf8a99f3c..afe2413ce6 100644 --- a/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/presentation/tokendetails/state/factory/TokenDetailsActionButtonsConverter.kt +++ b/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/presentation/tokendetails/state/factory/TokenDetailsActionButtonsConverter.kt @@ -38,6 +38,12 @@ internal class TokenDetailsActionButtonsConverter( onLongClick = clickIntents::onCopyAddress, ) } + is TokenActionsState.ActionState.Stake -> { + TokenDetailsActionButton.Stake( + dimContent = action.unavailabilityReason != ScenarioUnavailabilityReason.None, + onClick = { clickIntents.onStakeClick(action.unavailabilityReason) }, + ) + } is TokenActionsState.ActionState.Sell -> { TokenDetailsActionButton.Sell( dimContent = action.unavailabilityReason != ScenarioUnavailabilityReason.None, diff --git a/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/presentation/tokendetails/state/factory/TokenDetailsBalanceSelectStateConverter.kt b/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/presentation/tokendetails/state/factory/TokenDetailsBalanceSelectStateConverter.kt new file mode 100644 index 0000000000..7695aa744c --- /dev/null +++ b/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/presentation/tokendetails/state/factory/TokenDetailsBalanceSelectStateConverter.kt @@ -0,0 +1,75 @@ +package com.tangem.feature.tokendetails.presentation.tokendetails.state.factory + +import com.tangem.core.ui.utils.BigDecimalFormatter +import com.tangem.domain.appcurrency.model.AppCurrency +import com.tangem.domain.tokens.model.CryptoCurrencyStatus +import com.tangem.feature.tokendetails.presentation.tokendetails.state.* +import com.tangem.feature.tokendetails.presentation.tokendetails.state.utils.getBalance +import com.tangem.utils.Provider +import com.tangem.utils.converter.Converter +import java.math.BigDecimal + +internal class TokenDetailsBalanceSelectStateConverter( + private val currentStateProvider: Provider, + private val appCurrencyProvider: Provider, + private val cryptoCurrencyStatusProvider: Provider, +) : Converter { + + override fun convert(value: TokenBalanceSegmentedButtonConfig): TokenDetailsState { + return with(currentStateProvider()) { + if (stakingBlocksState !is StakingBlockUM.Staked) return this + val cryptoCurrencyStatus = cryptoCurrencyStatusProvider() ?: return this + + val stakingCryptoAmount = stakingBlocksState.cryptoAmount + val stakingFiatAmount = stakingBlocksState.fiatAmount + + copy( + tokenBalanceBlockState = if (tokenBalanceBlockState is TokenDetailsBalanceBlockState.Content) { + tokenBalanceBlockState.copy( + selectedBalanceType = value.type, + displayFiatBalance = formatFiatAmount( + status = cryptoCurrencyStatus.value, + stakingFiatAmount = stakingFiatAmount, + selectedBalanceType = value.type, + appCurrency = appCurrencyProvider(), + ), + displayCryptoBalance = formatCryptoAmount( + status = cryptoCurrencyStatus, + stakingCryptoAmount = stakingCryptoAmount, + selectedBalanceType = value.type, + ), + ) + } else { + tokenBalanceBlockState + }, + ) + } + } + + private fun formatFiatAmount( + status: CryptoCurrencyStatus.Value, + stakingFiatAmount: BigDecimal?, + selectedBalanceType: BalanceType, + appCurrency: AppCurrency, + ): String { + val fiatAmount = status.fiatAmount ?: return BigDecimalFormatter.EMPTY_BALANCE_SIGN + val totalAmount = fiatAmount.getBalance(selectedBalanceType, stakingFiatAmount) + + return BigDecimalFormatter.formatFiatAmount( + fiatAmount = totalAmount, + fiatCurrencyCode = appCurrency.code, + fiatCurrencySymbol = appCurrency.symbol, + ) + } + + private fun formatCryptoAmount( + status: CryptoCurrencyStatus, + stakingCryptoAmount: BigDecimal?, + selectedBalanceType: BalanceType, + ): String { + val amount = status.value.amount ?: return BigDecimalFormatter.EMPTY_BALANCE_SIGN + val totalAmount = amount.getBalance(selectedBalanceType, stakingCryptoAmount) + + return BigDecimalFormatter.formatCryptoAmount(totalAmount, status.currency.symbol, status.currency.decimals) + } +} \ No newline at end of file diff --git a/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/presentation/tokendetails/state/factory/TokenDetailsLoadedBalanceConverter.kt b/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/presentation/tokendetails/state/factory/TokenDetailsLoadedBalanceConverter.kt index 63d735d3ad..b5b0f8a5c6 100644 --- a/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/presentation/tokendetails/state/factory/TokenDetailsLoadedBalanceConverter.kt +++ b/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/presentation/tokendetails/state/factory/TokenDetailsLoadedBalanceConverter.kt @@ -6,19 +6,30 @@ import com.tangem.core.ui.components.marketprice.PriceChangeState import com.tangem.core.ui.components.marketprice.PriceChangeType import com.tangem.core.ui.components.marketprice.utils.PriceChangeConverter import com.tangem.core.ui.components.transactions.state.TxHistoryState +import com.tangem.core.ui.extensions.resourceReference +import com.tangem.core.ui.extensions.stringReference +import com.tangem.core.ui.extensions.wrappedList import com.tangem.core.ui.utils.BigDecimalFormatter import com.tangem.domain.appcurrency.model.AppCurrency +import com.tangem.domain.staking.model.stakekit.YieldBalance import com.tangem.domain.tokens.error.CurrencyStatusError import com.tangem.domain.tokens.model.CryptoCurrencyStatus +import com.tangem.feature.tokendetails.presentation.tokendetails.state.BalanceType +import com.tangem.feature.tokendetails.presentation.tokendetails.state.StakingBlockUM import com.tangem.feature.tokendetails.presentation.tokendetails.state.TokenDetailsBalanceBlockState import com.tangem.feature.tokendetails.presentation.tokendetails.state.TokenDetailsState import com.tangem.feature.tokendetails.presentation.tokendetails.state.components.TokenDetailsNotification import com.tangem.feature.tokendetails.presentation.tokendetails.state.factory.txhistory.TokenDetailsTxHistoryTransactionStateConverter +import com.tangem.feature.tokendetails.presentation.tokendetails.state.utils.getBalance import com.tangem.feature.tokendetails.presentation.tokendetails.viewmodels.TokenDetailsClickIntents +import com.tangem.features.staking.api.featuretoggles.StakingFeatureToggles +import com.tangem.features.tokendetails.impl.R import com.tangem.utils.Provider import com.tangem.utils.converter.Converter +import com.tangem.utils.isNullOrZero import kotlinx.collections.immutable.persistentListOf import kotlinx.collections.immutable.toPersistentList +import java.math.BigDecimal internal class TokenDetailsLoadedBalanceConverter( private val currentStateProvider: Provider, @@ -26,6 +37,7 @@ internal class TokenDetailsLoadedBalanceConverter( private val symbol: String, private val decimals: Int, private val clickIntents: TokenDetailsClickIntents, + private val stakingFeatureToggles: StakingFeatureToggles, ) : Converter, TokenDetailsState> { private val txHistoryItemConverter by lazy { @@ -33,13 +45,21 @@ internal class TokenDetailsLoadedBalanceConverter( } override fun convert(value: Either): TokenDetailsState { - return value.fold(ifLeft = { convertError() }, ifRight = ::convert) + return value.fold( + ifLeft = { convertError() }, + ifRight = { convert(it) }, + ) } private fun convertError(): TokenDetailsState { val state = currentStateProvider() return state.copy( - tokenBalanceBlockState = TokenDetailsBalanceBlockState.Error(state.tokenBalanceBlockState.actionButtons), + isStakingBlockShown = false, + tokenBalanceBlockState = TokenDetailsBalanceBlockState.Error( + actionButtons = state.tokenBalanceBlockState.actionButtons, + balanceSegmentedButtonConfig = state.tokenBalanceBlockState.balanceSegmentedButtonConfig, + selectedBalanceType = state.tokenBalanceBlockState.selectedBalanceType, + ), marketPriceBlockState = MarketPriceBlockState.Error(state.marketPriceBlockState.currencySymbol), notifications = persistentListOf(TokenDetailsNotification.NetworksUnreachable), ) @@ -49,8 +69,13 @@ internal class TokenDetailsLoadedBalanceConverter( val state = currentStateProvider() val currencyName = state.marketPriceBlockState.currencySymbol val pendingTxs = status.value.pendingTransactions.map(txHistoryItemConverter::convert).toPersistentList() + return state.copy( - tokenBalanceBlockState = getBalanceState(state.tokenBalanceBlockState, status), + tokenBalanceBlockState = getBalanceState( + currentState = state.tokenBalanceBlockState, + status = status, + ), + stakingBlocksState = getYieldBalance(status, state), marketPriceBlockState = getMarketPriceState(status = status.value, currencySymbol = currencyName), pendingTxs = pendingTxs, txHistoryState = if (state.txHistoryState is TxHistoryState.NotSupported) { @@ -65,6 +90,9 @@ internal class TokenDetailsLoadedBalanceConverter( currentState: TokenDetailsBalanceBlockState, status: CryptoCurrencyStatus, ): TokenDetailsBalanceBlockState { + val stakingCryptoAmount = (status.value.yieldBalance as? YieldBalance.Data)?.getTotalStakingBalance() + val stakingFiatAmount = stakingCryptoAmount?.let { status.value.fiatRate?.multiply(it) } + val isBalanceSelectorEnabled = stakingFeatureToggles.isStakingEnabled && !stakingCryptoAmount.isNullOrZero() return when (status.value) { is CryptoCurrencyStatus.NoQuote, is CryptoCurrencyStatus.Loaded, @@ -72,14 +100,75 @@ internal class TokenDetailsLoadedBalanceConverter( is CryptoCurrencyStatus.Custom, -> TokenDetailsBalanceBlockState.Content( actionButtons = currentState.actionButtons, - fiatBalance = formatFiatAmount(status.value, appCurrencyProvider()), - cryptoBalance = formatCryptoAmount(status), + cryptoBalance = status.value.amount, + fiatBalance = status.value.fiatAmount, + displayFiatBalance = formatFiatAmount( + status.value, + stakingFiatAmount, + currentState.selectedBalanceType, + appCurrencyProvider(), + ), + displayCryptoBalance = formatCryptoAmount( + status, + stakingCryptoAmount, + currentState.selectedBalanceType, + ), + balanceSegmentedButtonConfig = currentState.balanceSegmentedButtonConfig, + onBalanceSelect = clickIntents::onBalanceSelect, + selectedBalanceType = currentState.selectedBalanceType, + isBalanceSelectorEnabled = isBalanceSelectorEnabled, + ) + is CryptoCurrencyStatus.Loading -> TokenDetailsBalanceBlockState.Loading( + actionButtons = currentState.actionButtons, + balanceSegmentedButtonConfig = currentState.balanceSegmentedButtonConfig, + selectedBalanceType = currentState.selectedBalanceType, ) - is CryptoCurrencyStatus.Loading -> TokenDetailsBalanceBlockState.Loading(currentState.actionButtons) is CryptoCurrencyStatus.MissedDerivation, is CryptoCurrencyStatus.Unreachable, is CryptoCurrencyStatus.NoAmount, - -> TokenDetailsBalanceBlockState.Error(currentState.actionButtons) + -> TokenDetailsBalanceBlockState.Error( + actionButtons = currentState.actionButtons, + balanceSegmentedButtonConfig = currentState.balanceSegmentedButtonConfig, + selectedBalanceType = currentState.selectedBalanceType, + ) + } + } + + private fun getYieldBalance(status: CryptoCurrencyStatus, state: TokenDetailsState): StakingBlockUM { + val yieldBalance = status.value.yieldBalance as? YieldBalance.Data + + val stakingCryptoAmount = yieldBalance?.getTotalStakingBalance() + val stakingRewardAmount = yieldBalance?.getRewardStakingBalance() + val stakingFiatAmount = stakingCryptoAmount?.let { status.value.fiatRate?.multiply(it) } + + return if (stakingCryptoAmount.isNullOrZero()) { + StakingBlockUM.Loading(state.tokenInfoBlockState.iconState) + } else { + StakingBlockUM.Staked( + cryptoAmount = stakingCryptoAmount, + fiatAmount = stakingFiatAmount, + cryptoValue = stringReference( + BigDecimalFormatter.formatCryptoAmount(stakingCryptoAmount, symbol, decimals), + ), + fiatValue = stringReference( + BigDecimalFormatter.formatFiatAmount( + stakingFiatAmount, + appCurrencyProvider().code, + appCurrencyProvider().symbol, + ), + ), + rewardValue = resourceReference( + R.string.staking_details_rewards_to_claim, + wrappedList( + BigDecimalFormatter.formatFiatAmount( + stakingRewardAmount, + appCurrencyProvider().code, + appCurrencyProvider().symbol, + ), + ), + ), + onStakeClicked = clickIntents::onStakeBannerClick, + ) } } @@ -140,19 +229,30 @@ internal class TokenDetailsLoadedBalanceConverter( ) } - private fun formatFiatAmount(status: CryptoCurrencyStatus.Value, appCurrency: AppCurrency): String { + private fun formatFiatAmount( + status: CryptoCurrencyStatus.Value, + stakingFiatAmount: BigDecimal?, + selectedBalanceType: BalanceType, + appCurrency: AppCurrency, + ): String { val fiatAmount = status.fiatAmount ?: return BigDecimalFormatter.EMPTY_BALANCE_SIGN + val totalAmount = fiatAmount.getBalance(selectedBalanceType, stakingFiatAmount) return BigDecimalFormatter.formatFiatAmount( - fiatAmount = fiatAmount, + fiatAmount = totalAmount, fiatCurrencyCode = appCurrency.code, fiatCurrencySymbol = appCurrency.symbol, ) } - private fun formatCryptoAmount(status: CryptoCurrencyStatus): String { + private fun formatCryptoAmount( + status: CryptoCurrencyStatus, + stakingCryptoAmount: BigDecimal?, + selectedBalanceType: BalanceType, + ): String { val amount = status.value.amount ?: return BigDecimalFormatter.EMPTY_BALANCE_SIGN + val totalAmount = amount.getBalance(selectedBalanceType, stakingCryptoAmount) - return BigDecimalFormatter.formatCryptoAmount(amount, status.currency.symbol, status.currency.decimals) + return BigDecimalFormatter.formatCryptoAmount(totalAmount, status.currency.symbol, status.currency.decimals) } } \ No newline at end of file diff --git a/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/presentation/tokendetails/state/factory/TokenDetailsSkeletonStateConverter.kt b/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/presentation/tokendetails/state/factory/TokenDetailsSkeletonStateConverter.kt index 2c29e74ce3..8339f1f69b 100644 --- a/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/presentation/tokendetails/state/factory/TokenDetailsSkeletonStateConverter.kt +++ b/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/presentation/tokendetails/state/factory/TokenDetailsSkeletonStateConverter.kt @@ -1,5 +1,6 @@ package com.tangem.feature.tokendetails.presentation.tokendetails.state.factory +import arrow.core.getOrElse import com.tangem.core.ui.components.marketprice.MarketPriceBlockState import com.tangem.core.ui.components.transactions.state.TxHistoryState import com.tangem.core.ui.event.consumedEvent @@ -7,9 +8,11 @@ import com.tangem.core.ui.extensions.TextReference import com.tangem.core.ui.extensions.networkIconResId import com.tangem.core.ui.extensions.resourceReference import com.tangem.core.ui.res.TangemTheme -import com.tangem.domain.staking.model.StakingAvailability +import com.tangem.domain.card.NetworkHasDerivationUseCase import com.tangem.domain.tokens.model.CryptoCurrency import com.tangem.domain.tokens.model.Network +import com.tangem.domain.wallets.models.UserWalletId +import com.tangem.domain.wallets.usecase.GetUserWalletUseCase import com.tangem.feature.tokendetails.presentation.tokendetails.state.* import com.tangem.feature.tokendetails.presentation.tokendetails.state.components.TokenDetailsActionButton import com.tangem.feature.tokendetails.presentation.tokendetails.state.components.TokenDetailsPullToRefreshConfig @@ -17,7 +20,6 @@ import com.tangem.feature.tokendetails.presentation.tokendetails.viewmodels.Toke import com.tangem.features.tokendetails.featuretoggles.TokenDetailsFeatureToggles import com.tangem.features.tokendetails.impl.R import com.tangem.lib.crypto.BlockchainUtils.isBitcoin -import com.tangem.utils.Provider import com.tangem.utils.converter.Converter import kotlinx.collections.immutable.ImmutableList import kotlinx.collections.immutable.persistentListOf @@ -27,7 +29,9 @@ import kotlinx.coroutines.flow.MutableStateFlow internal class TokenDetailsSkeletonStateConverter( private val clickIntents: TokenDetailsClickIntents, private val featureToggles: TokenDetailsFeatureToggles, - private val stakingAvailabilityProvider: Provider, + private val networkHasDerivationUseCase: NetworkHasDerivationUseCase, + private val getUserWalletUseCase: GetUserWalletUseCase, + private val userWalletId: UserWalletId, ) : Converter { private val iconStateConverter by lazy { TokenDetailsIconStateConverter() } @@ -51,9 +55,13 @@ internal class TokenDetailsSkeletonStateConverter( ) }, ), - tokenBalanceBlockState = TokenDetailsBalanceBlockState.Loading(actionButtons = createButtons()), + tokenBalanceBlockState = TokenDetailsBalanceBlockState.Loading( + actionButtons = createButtons(), + balanceSegmentedButtonConfig = createBalanceSegmentedButtonConfig(), + selectedBalanceType = BalanceType.ALL, + ), marketPriceBlockState = MarketPriceBlockState.Loading(value.symbol), - stakingBlockState = StakingBlockState.Loading(iconState = iconState), + stakingBlocksState = StakingBlockUM.Loading(iconState), notifications = persistentListOf(), pendingTxs = persistentListOf(), swapTxs = persistentListOf(), @@ -67,7 +75,7 @@ internal class TokenDetailsSkeletonStateConverter( bottomSheetConfig = null, isBalanceHidden = true, isMarketPriceAvailable = value.id.rawCurrencyId != null, - isStakingAvailable = stakingAvailabilityProvider.invoke() is StakingAvailability.Available, + isStakingBlockShown = false, event = consumedEvent(), ) } @@ -77,13 +85,7 @@ internal class TokenDetailsSkeletonStateConverter( private fun createMenu(cryptoCurrency: CryptoCurrency): TokenDetailsAppBarMenuConfig = TokenDetailsAppBarMenuConfig( items = buildList { - if (featureToggles.isGenerateXPubEnabled() && isBitcoin(cryptoCurrency.network.id.value)) { - TokenDetailsAppBarMenuConfig.MenuItem( - title = resourceReference(R.string.token_details_generate_xpub), - textColorProvider = { TangemTheme.colors.text.primary1 }, - onClick = clickIntents::onGenerateExtendedKey, - ).let(::add) - } + addGenerateXPubMenuItem(cryptoCurrency) TokenDetailsAppBarMenuConfig.MenuItem( title = TextReference.Res(id = R.string.token_details_hide_token), textColorProvider = { TangemTheme.colors.text.warning }, @@ -92,6 +94,26 @@ internal class TokenDetailsSkeletonStateConverter( }.toImmutableList(), ) + private fun MutableList.addGenerateXPubMenuItem( + cryptoCurrency: CryptoCurrency, + ) { + val userWallet = getUserWalletUseCase(userWalletId).getOrNull() ?: return + val isGenerateXPubEnabled = featureToggles.isGenerateXPubEnabled() + val isBitcoin = isBitcoin(cryptoCurrency.network.id.value) + val hasDerivations = + networkHasDerivationUseCase(userWallet.scanResponse, cryptoCurrency.network).getOrElse { false } + + if (isGenerateXPubEnabled && isBitcoin && hasDerivations) { + add( + TokenDetailsAppBarMenuConfig.MenuItem( + title = resourceReference(R.string.token_details_generate_xpub), + textColorProvider = { TangemTheme.colors.text.primary1 }, + onClick = clickIntents::onGenerateExtendedKey, + ), + ) + } + } + private fun createButtons(): ImmutableList { return persistentListOf( TokenDetailsActionButton.Buy(dimContent = false, onClick = {}), @@ -102,6 +124,19 @@ internal class TokenDetailsSkeletonStateConverter( ) } + private fun createBalanceSegmentedButtonConfig(): ImmutableList { + return persistentListOf( + TokenBalanceSegmentedButtonConfig( + title = resourceReference(R.string.common_all), + type = BalanceType.ALL, + ), + TokenBalanceSegmentedButtonConfig( + title = resourceReference(R.string.staking_details_available), + type = BalanceType.AVAILABLE, + ), + ) + } + private fun createPullToRefresh(): TokenDetailsPullToRefreshConfig = TokenDetailsPullToRefreshConfig( isRefreshing = false, onRefresh = clickIntents::onRefreshSwipe, diff --git a/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/presentation/tokendetails/state/factory/TokenDetailsStateFactory.kt b/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/presentation/tokendetails/state/factory/TokenDetailsStateFactory.kt index c47c971328..3d6080faba 100644 --- a/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/presentation/tokendetails/state/factory/TokenDetailsStateFactory.kt +++ b/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/presentation/tokendetails/state/factory/TokenDetailsStateFactory.kt @@ -15,24 +15,30 @@ import com.tangem.core.ui.extensions.resourceReference import com.tangem.core.ui.extensions.wrappedList import com.tangem.core.ui.res.TangemTheme import com.tangem.domain.appcurrency.model.AppCurrency +import com.tangem.domain.card.NetworkHasDerivationUseCase import com.tangem.domain.common.CardTypesResolver import com.tangem.domain.staking.model.StakingAvailability import com.tangem.domain.staking.model.StakingEntryInfo +import com.tangem.domain.staking.model.stakekit.StakingError import com.tangem.domain.tokens.error.CurrencyStatusError import com.tangem.domain.tokens.model.* import com.tangem.domain.tokens.model.warnings.CryptoCurrencyWarning import com.tangem.domain.txhistory.models.TxHistoryItem import com.tangem.domain.txhistory.models.TxHistoryListError import com.tangem.domain.txhistory.models.TxHistoryStateError +import com.tangem.domain.wallets.models.UserWalletId +import com.tangem.domain.wallets.usecase.GetUserWalletUseCase import com.tangem.feature.tokendetails.presentation.tokendetails.state.SwapTransactionsState import com.tangem.feature.tokendetails.presentation.tokendetails.state.TokenDetailsAppBarMenuConfig import com.tangem.feature.tokendetails.presentation.tokendetails.state.TokenDetailsState +import com.tangem.feature.tokendetails.presentation.tokendetails.state.* import com.tangem.feature.tokendetails.presentation.tokendetails.state.components.TokenDetailsDialogConfig import com.tangem.feature.tokendetails.presentation.tokendetails.state.factory.txhistory.TokenDetailsLoadedTxHistoryConverter import com.tangem.feature.tokendetails.presentation.tokendetails.state.factory.txhistory.TokenDetailsLoadingTxHistoryConverter import com.tangem.feature.tokendetails.presentation.tokendetails.state.factory.txhistory.TokenDetailsLoadingTxHistoryConverter.TokenDetailsLoadingTxHistoryModel import com.tangem.feature.tokendetails.presentation.tokendetails.ui.components.exchange.ExchangeStatusBottomSheetConfig import com.tangem.feature.tokendetails.presentation.tokendetails.viewmodels.TokenDetailsClickIntents +import com.tangem.features.staking.api.featuretoggles.StakingFeatureToggles import com.tangem.features.tokendetails.featuretoggles.TokenDetailsFeatureToggles import com.tangem.features.tokendetails.impl.R import com.tangem.utils.Provider @@ -44,9 +50,13 @@ import kotlinx.coroutines.flow.MutableStateFlow internal class TokenDetailsStateFactory( private val currentStateProvider: Provider, private val appCurrencyProvider: Provider, - private val stakingAvailabilityProvider: Provider, + private val cryptoCurrencyStatusProvider: Provider, private val clickIntents: TokenDetailsClickIntents, private val featureToggles: TokenDetailsFeatureToggles, + private val networkHasDerivationUseCase: NetworkHasDerivationUseCase, + private val getUserWalletUseCase: GetUserWalletUseCase, + private val userWalletId: UserWalletId, + stakingFeatureToggles: StakingFeatureToggles, symbol: String, decimals: Int, ) { @@ -55,7 +65,9 @@ internal class TokenDetailsStateFactory( TokenDetailsSkeletonStateConverter( clickIntents = clickIntents, featureToggles = featureToggles, - stakingAvailabilityProvider = stakingAvailabilityProvider, + networkHasDerivationUseCase = networkHasDerivationUseCase, + getUserWalletUseCase = getUserWalletUseCase, + userWalletId = userWalletId, ) } @@ -70,6 +82,7 @@ internal class TokenDetailsStateFactory( symbol = symbol, decimals = decimals, clickIntents = clickIntents, + stakingFeatureToggles = stakingFeatureToggles, ) } @@ -105,6 +118,15 @@ internal class TokenDetailsStateFactory( private val stakingStateConverter by lazy { TokenStakingStateConverter( currentStateProvider = currentStateProvider, + clickIntents = clickIntents, + ) + } + + private val balanceSelectStateConverter by lazy { + TokenDetailsBalanceSelectStateConverter( + currentStateProvider = currentStateProvider, + appCurrencyProvider = appCurrencyProvider, + cryptoCurrencyStatusProvider = cryptoCurrencyStatusProvider, ) } @@ -212,9 +234,15 @@ internal class TokenDetailsStateFactory( ) } - fun getStateWithStaking(stakingEither: Either): TokenDetailsState { + fun getStateWithUpdatedStakingAvailability(stakingAvailability: StakingAvailability): TokenDetailsState { return currentStateProvider().copy( - stakingBlockState = stakingStateConverter.convert(stakingEither), + isStakingBlockShown = stakingAvailability != StakingAvailability.Unavailable, + ) + } + + fun getStateWithStaking(stakingEither: Either): TokenDetailsState { + return currentStateProvider().copy( + stakingBlocksState = stakingStateConverter.convert(stakingEither), ) } @@ -333,26 +361,37 @@ internal class TokenDetailsStateFactory( ) } - fun getStateWithUpdatedMenu(cardTypesResolver: CardTypesResolver, isBitcoin: Boolean): TokenDetailsState { + fun getStateWithUpdatedMenu( + cardTypesResolver: CardTypesResolver, + hasDerivations: Boolean, + isBitcoin: Boolean, + ): TokenDetailsState { return with(currentStateProvider()) { copy( topAppBarConfig = topAppBarConfig.copy( tokenDetailsAppBarMenuConfig = topAppBarConfig.tokenDetailsAppBarMenuConfig - ?.updateMenu(cardTypesResolver, isBitcoin), + ?.updateMenu(cardTypesResolver, hasDerivations, isBitcoin), ), ) } } + fun getStateWithUpdatedBalanceSegmentedButtonConfig( + buttonConfig: TokenBalanceSegmentedButtonConfig, + ): TokenDetailsState { + return balanceSelectStateConverter.convert(buttonConfig) + } + private fun TokenDetailsAppBarMenuConfig.updateMenu( cardTypesResolver: CardTypesResolver, + hasDerivations: Boolean, isBitcoin: Boolean, ): TokenDetailsAppBarMenuConfig? { if (cardTypesResolver.isSingleWalletWithToken()) return null val showGenerateExtendedKey = featureToggles.isGenerateXPubEnabled() && isBitcoin return copy( items = buildList { - if (showGenerateExtendedKey) { + if (showGenerateExtendedKey && hasDerivations) { TokenDetailsAppBarMenuConfig.MenuItem( title = resourceReference(R.string.token_details_generate_xpub), textColorProvider = { TangemTheme.colors.text.primary1 }, @@ -370,6 +409,12 @@ internal class TokenDetailsStateFactory( private fun getUnavailabilityReasonText(unavailabilityReason: ScenarioUnavailabilityReason): TextReference { return when (unavailabilityReason) { + is ScenarioUnavailabilityReason.StakingUnavailable -> { + resourceReference( + id = R.string.token_button_unavailability_reason_staking_unavailable, + formatArgs = wrappedList(unavailabilityReason.cryptoCurrencyName), + ) + } is ScenarioUnavailabilityReason.PendingTransaction -> { when (unavailabilityReason.withdrawalScenario) { ScenarioUnavailabilityReason.WithdrawalScenario.SEND -> resourceReference( diff --git a/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/presentation/tokendetails/state/factory/TokenDetailsSwapTransactionsStateConverter.kt b/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/presentation/tokendetails/state/factory/TokenDetailsSwapTransactionsStateConverter.kt index 12a65e1e6b..15523c353c 100644 --- a/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/presentation/tokendetails/state/factory/TokenDetailsSwapTransactionsStateConverter.kt +++ b/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/presentation/tokendetails/state/factory/TokenDetailsSwapTransactionsStateConverter.kt @@ -1,7 +1,7 @@ package com.tangem.feature.tokendetails.presentation.tokendetails.state.factory import com.tangem.core.analytics.api.AnalyticsEventHandler -import com.tangem.core.ui.components.currency.tokenicon.converter.CryptoCurrencyToIconStateConverter +import com.tangem.core.ui.components.currency.icon.converter.CryptoCurrencyToIconStateConverter import com.tangem.core.ui.extensions.TextReference import com.tangem.core.ui.utils.BigDecimalFormatter import com.tangem.core.ui.utils.toDateFormatWithTodayYesterday diff --git a/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/presentation/tokendetails/state/factory/TokenStakingStateConverter.kt b/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/presentation/tokendetails/state/factory/TokenStakingStateConverter.kt index 371e2e766d..3bc3e36023 100644 --- a/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/presentation/tokendetails/state/factory/TokenStakingStateConverter.kt +++ b/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/presentation/tokendetails/state/factory/TokenStakingStateConverter.kt @@ -3,31 +3,37 @@ package com.tangem.feature.tokendetails.presentation.tokendetails.state.factory import arrow.core.Either import com.tangem.core.ui.utils.BigDecimalFormatter import com.tangem.domain.staking.model.StakingEntryInfo -import com.tangem.feature.tokendetails.presentation.tokendetails.state.StakingBlockState +import com.tangem.domain.staking.model.stakekit.StakingError +import com.tangem.feature.tokendetails.presentation.tokendetails.state.StakingBlockUM import com.tangem.feature.tokendetails.presentation.tokendetails.state.TokenDetailsState +import com.tangem.feature.tokendetails.presentation.tokendetails.viewmodels.TokenDetailsClickIntents import com.tangem.utils.Provider import com.tangem.utils.converter.Converter internal class TokenStakingStateConverter( + private val clickIntents: TokenDetailsClickIntents, private val currentStateProvider: Provider, -) : Converter, StakingBlockState> { +) : Converter, StakingBlockUM> { - override fun convert(value: Either): StakingBlockState { - value.fold( + override fun convert(value: Either): StakingBlockUM { + val state = currentStateProvider() + if (state.stakingBlocksState is StakingBlockUM.Staked) return state.stakingBlocksState + + val iconState = state.tokenInfoBlockState.iconState + return value.fold( ifLeft = { - return StakingBlockState.Error( - iconState = currentStateProvider().tokenInfoBlockState.iconState, - ) + StakingBlockUM.Error(iconState = iconState) }, ifRight = { - return StakingBlockState.Content( + StakingBlockUM.StakeAvailable( interestRate = BigDecimalFormatter.formatPercent( percent = it.interestRate, useAbsoluteValue = true, ), periodInDays = it.periodInDays, tokenSymbol = it.tokenSymbol, - iconState = currentStateProvider().tokenInfoBlockState.iconState, + iconState = iconState, + onStakeClicked = clickIntents::onStakeBannerClick, ) }, ) diff --git a/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/presentation/tokendetails/state/factory/txhistory/TokenDetailsTxHistoryTransactionStateConverter.kt b/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/presentation/tokendetails/state/factory/txhistory/TokenDetailsTxHistoryTransactionStateConverter.kt index 1e2ab2341d..3aacd1221a 100644 --- a/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/presentation/tokendetails/state/factory/txhistory/TokenDetailsTxHistoryTransactionStateConverter.kt +++ b/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/presentation/tokendetails/state/factory/txhistory/TokenDetailsTxHistoryTransactionStateConverter.kt @@ -10,6 +10,8 @@ import com.tangem.core.ui.utils.toTimeFormat import com.tangem.domain.txhistory.models.TxHistoryItem import com.tangem.feature.tokendetails.presentation.tokendetails.viewmodels.TokenDetailsClickIntents import com.tangem.features.tokendetails.impl.R +import com.tangem.utils.StringsSigns.MINUS +import com.tangem.utils.StringsSigns.PLUS import com.tangem.utils.converter.Converter import com.tangem.utils.toBriefAddressFormat import com.tangem.utils.toFormattedCurrencyString @@ -96,7 +98,7 @@ internal class TokenDetailsTxHistoryTransactionStateConverter( private fun TxHistoryItem.getAmount(): String { val prefix = when (status) { TxHistoryItem.TransactionStatus.Failed -> "" - else -> if (isOutgoing) "-" else "+" + else -> if (isOutgoing) MINUS else PLUS } return prefix + amount.toFormattedCurrencyString(currency = symbol, decimals = decimals) } diff --git a/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/presentation/tokendetails/state/utils/BalanceUtils.kt b/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/presentation/tokendetails/state/utils/BalanceUtils.kt new file mode 100644 index 0000000000..faa0144943 --- /dev/null +++ b/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/presentation/tokendetails/state/utils/BalanceUtils.kt @@ -0,0 +1,12 @@ +package com.tangem.feature.tokendetails.presentation.tokendetails.state.utils + +import com.tangem.feature.tokendetails.presentation.tokendetails.state.BalanceType +import java.math.BigDecimal + +fun BigDecimal.getBalance(selectedBalanceType: BalanceType, stakingAmount: BigDecimal?): BigDecimal { + return if (selectedBalanceType == BalanceType.ALL && stakingAmount != null) { + this.plus(stakingAmount) + } else { + this + } +} \ No newline at end of file diff --git a/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/presentation/tokendetails/ui/TokenDetailsScreen.kt b/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/presentation/tokendetails/ui/TokenDetailsScreen.kt index c24ca651d8..378b55e62d 100644 --- a/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/presentation/tokendetails/ui/TokenDetailsScreen.kt +++ b/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/presentation/tokendetails/ui/TokenDetailsScreen.kt @@ -3,10 +3,7 @@ package com.tangem.feature.tokendetails.presentation.tokendetails.ui import android.content.res.Configuration import androidx.activity.compose.BackHandler import androidx.compose.foundation.ExperimentalFoundationApi -import androidx.compose.foundation.layout.Box -import androidx.compose.foundation.layout.PaddingValues -import androidx.compose.foundation.layout.fillMaxSize -import androidx.compose.foundation.layout.padding +import androidx.compose.foundation.layout.* import androidx.compose.foundation.lazy.LazyColumn import androidx.compose.foundation.lazy.items import androidx.compose.material.ExperimentalMaterialApi @@ -14,13 +11,14 @@ import androidx.compose.material.pullrefresh.PullRefreshIndicator import androidx.compose.material.pullrefresh.pullRefresh import androidx.compose.material.pullrefresh.rememberPullRefreshState import androidx.compose.material3.Scaffold -import androidx.compose.material3.SnackbarHost +import androidx.compose.material3.ScaffoldDefaults import androidx.compose.material3.SnackbarHostState import androidx.compose.runtime.Composable import androidx.compose.runtime.remember import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.platform.LocalContext +import androidx.compose.ui.platform.LocalDensity import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.tooling.preview.PreviewParameter import androidx.compose.ui.tooling.preview.datasource.CollectionPreviewParameterProvider @@ -33,6 +31,7 @@ import com.tangem.core.ui.components.marketprice.MarketPriceBlock import com.tangem.core.ui.components.marketprice.MarketPriceBlockState import com.tangem.core.ui.components.notifications.Notification import com.tangem.core.ui.components.notifications.OkxPromoNotification +import com.tangem.core.ui.components.snackbar.TangemSnackbarHost import com.tangem.core.ui.components.transactions.state.TxHistoryState import com.tangem.core.ui.components.transactions.txHistoryItems import com.tangem.core.ui.event.EventEffect @@ -42,10 +41,9 @@ import com.tangem.core.ui.extensions.resolveReference import com.tangem.core.ui.res.TangemTheme import com.tangem.core.ui.res.TangemThemePreview import com.tangem.feature.tokendetails.presentation.tokendetails.TokenDetailsPreviewData -import com.tangem.feature.tokendetails.presentation.tokendetails.state.StakingBlockState +import com.tangem.feature.tokendetails.presentation.tokendetails.state.StakingBlockUM import com.tangem.feature.tokendetails.presentation.tokendetails.state.TokenDetailsState import com.tangem.feature.tokendetails.presentation.tokendetails.state.components.TokenDetailsNotification -import com.tangem.feature.tokendetails.presentation.tokendetails.ui.components.* import com.tangem.feature.tokendetails.presentation.tokendetails.ui.components.TokenDetailsBalanceBlock import com.tangem.feature.tokendetails.presentation.tokendetails.ui.components.TokenDetailsDialogs import com.tangem.feature.tokendetails.presentation.tokendetails.ui.components.TokenDetailsTopAppBar @@ -53,6 +51,7 @@ import com.tangem.feature.tokendetails.presentation.tokendetails.ui.components.T import com.tangem.feature.tokendetails.presentation.tokendetails.ui.components.exchange.ExchangeStatusBottomSheet import com.tangem.feature.tokendetails.presentation.tokendetails.ui.components.exchange.ExchangeStatusBottomSheetConfig import com.tangem.feature.tokendetails.presentation.tokendetails.ui.components.exchange.swapTransactionsItems +import com.tangem.feature.tokendetails.presentation.tokendetails.ui.components.staking.TokenStakingBlock // TODO: Split to blocks [REDACTED_JIRA] @Suppress("LongMethod") @@ -60,11 +59,22 @@ import com.tangem.feature.tokendetails.presentation.tokendetails.ui.components.e @Composable internal fun TokenDetailsScreen(state: TokenDetailsState) { BackHandler(onBack = state.topAppBarConfig.onBackClick) + val bottomBarHeight = with(LocalDensity.current) { WindowInsets.systemBars.getBottom(this).toDp() } val snackbarHostState = remember { SnackbarHostState() } Scaffold( topBar = { TokenDetailsTopAppBar(config = state.topAppBarConfig) }, - snackbarHost = { SnackbarHost(hostState = snackbarHostState) }, + snackbarHost = { + TangemSnackbarHost( + modifier = Modifier.padding( + start = TangemTheme.dimens.spacing16, + end = TangemTheme.dimens.spacing16, + bottom = bottomBarHeight + TangemTheme.dimens.spacing16, + ), + hostState = snackbarHostState, + ) + }, + contentWindowInsets = ScaffoldDefaults.contentWindowInsets.exclude(WindowInsets.navigationBars), containerColor = TangemTheme.colors.background.secondary, ) { scaffoldPaddings -> val pullRefreshState = rememberPullRefreshState( @@ -90,7 +100,9 @@ internal fun TokenDetailsScreen(state: TokenDetailsState) { ) { LazyColumn( modifier = Modifier.fillMaxSize(), - contentPadding = PaddingValues(bottom = TangemTheme.dimens.spacing16), + contentPadding = PaddingValues( + bottom = TangemTheme.dimens.spacing16 + bottomBarHeight, + ), ) { item { TokenInfoBlock( @@ -135,11 +147,16 @@ internal fun TokenDetailsScreen(state: TokenDetailsState) { ) } - if (state.isStakingAvailable) { + if (state.isStakingBlockShown) { item( - key = StakingBlockState::class.java, - contentType = StakingBlockState::class.java, - content = { TokenStakingBlock(modifier = itemModifier, state = state.stakingBlockState) }, + key = StakingBlockUM::class.java, + contentType = StakingBlockUM::class.java, + content = { + TokenStakingBlock( + modifier = itemModifier, + state = state.stakingBlocksState, + ) + }, ) } diff --git a/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/presentation/tokendetails/ui/components/TokenDetailsBalanceBlock.kt b/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/presentation/tokendetails/ui/components/TokenDetailsBalanceBlock.kt index 3f448ae33a..d3e4bdff81 100644 --- a/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/presentation/tokendetails/ui/components/TokenDetailsBalanceBlock.kt +++ b/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/presentation/tokendetails/ui/components/TokenDetailsBalanceBlock.kt @@ -11,9 +11,10 @@ import androidx.compose.ui.res.stringResource 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.common.Strings.STARS import com.tangem.core.ui.components.RectangleShimmer import com.tangem.core.ui.components.buttons.HorizontalActionChips +import com.tangem.core.ui.components.buttons.segmentedbutton.SegmentedButtons +import com.tangem.core.ui.extensions.resolveReference import com.tangem.core.ui.res.TangemTheme import com.tangem.core.ui.res.TangemThemePreview import com.tangem.core.ui.utils.BigDecimalFormatter @@ -21,6 +22,7 @@ import com.tangem.feature.tokendetails.presentation.tokendetails.TokenDetailsPre import com.tangem.feature.tokendetails.presentation.tokendetails.state.TokenDetailsBalanceBlockState import com.tangem.feature.tokendetails.presentation.tokendetails.state.components.TokenDetailsActionButton import com.tangem.features.tokendetails.impl.R +import com.tangem.utils.StringsSigns.STARS import kotlinx.collections.immutable.toImmutableList @Composable @@ -35,20 +37,23 @@ internal fun TokenDetailsBalanceBlock( color = TangemTheme.colors.background.primary, ) { Column { - Box( + Row( + verticalAlignment = Alignment.CenterVertically, modifier = Modifier - .padding(top = TangemTheme.dimens.spacing12) .padding(horizontal = TangemTheme.dimens.spacing12) .fillMaxWidth() .heightIn(min = TangemTheme.dimens.spacing24), - contentAlignment = Alignment.CenterStart, ) { Text( text = stringResource(id = R.string.common_balance_title), color = TangemTheme.colors.text.tertiary, style = TangemTheme.typography.subtitle2, maxLines = 1, + modifier = Modifier + .weight(1f) + .padding(top = TangemTheme.dimens.spacing12), ) + BalanceButtons(state) } FiatBalance( state = state, @@ -89,7 +94,7 @@ private fun FiatBalance( ) is TokenDetailsBalanceBlockState.Content -> Text( modifier = modifier, - text = if (isBalanceHidden) STARS else state.fiatBalance, + text = if (isBalanceHidden) STARS else state.displayFiatBalance, style = TangemTheme.typography.h2, color = TangemTheme.colors.text.primary1, ) @@ -117,7 +122,7 @@ private fun CryptoBalance( ) is TokenDetailsBalanceBlockState.Content -> Text( modifier = modifier, - text = if (isBalanceHidden) STARS else state.cryptoBalance, + text = if (isBalanceHidden) STARS else state.displayCryptoBalance, style = TangemTheme.typography.caption2, color = TangemTheme.colors.text.tertiary, ) @@ -130,6 +135,35 @@ private fun CryptoBalance( } } +@Composable +private fun BalanceButtons(state: TokenDetailsBalanceBlockState) { + if (state !is TokenDetailsBalanceBlockState.Content || !state.isBalanceSelectorEnabled) return + + SegmentedButtons( + config = state.balanceSegmentedButtonConfig, + onClick = state.onBalanceSelect, + showIndication = false, + modifier = Modifier + .padding(top = TangemTheme.dimens.spacing11) + .width(IntrinsicSize.Min), + ) { config -> + Text( + text = config.title.resolveReference(), + color = TangemTheme.colors.text.primary1, + style = TangemTheme.typography.caption1, + maxLines = 1, + modifier = Modifier + .padding( + start = TangemTheme.dimens.spacing5, + end = TangemTheme.dimens.spacing5, + top = TangemTheme.dimens.spacing3, + bottom = TangemTheme.dimens.spacing3, + ) + .align(Alignment.Center), + ) + } +} + @Preview(widthDp = 328, heightDp = 152) @Preview(widthDp = 328, heightDp = 152, uiMode = Configuration.UI_MODE_NIGHT_YES) @Composable diff --git a/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/presentation/tokendetails/ui/components/TokenInfoBlock.kt b/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/presentation/tokendetails/ui/components/TokenInfoBlock.kt index 773dc2868f..a6d81965bb 100644 --- a/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/presentation/tokendetails/ui/components/TokenInfoBlock.kt +++ b/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/presentation/tokendetails/ui/components/TokenInfoBlock.kt @@ -18,9 +18,7 @@ import androidx.compose.ui.tooling.preview.PreviewParameter import androidx.compose.ui.tooling.preview.datasource.CollectionPreviewParameterProvider import com.tangem.core.ui.res.TangemTheme import com.tangem.core.ui.res.TangemThemePreview -import com.tangem.core.ui.utils.GRAY_SCALE_ALPHA -import com.tangem.core.ui.utils.GrayscaleColorFilter -import com.tangem.core.ui.utils.NORMAL_ALPHA +import com.tangem.core.ui.utils.getGreyScaleColorFilter import com.tangem.feature.tokendetails.presentation.tokendetails.TokenDetailsPreviewData import com.tangem.feature.tokendetails.presentation.tokendetails.state.TokenInfoBlockState import com.tangem.features.tokendetails.impl.R @@ -46,11 +44,7 @@ internal fun TokenInfoBlock(state: TokenInfoBlockState, modifier: Modifier = Mod } val (alpha, colorFilter) = remember(state.iconState.isGrayscale) { - if (state.iconState.isGrayscale) { - GRAY_SCALE_ALPHA to GrayscaleColorFilter - } else { - NORMAL_ALPHA to null - } + getGreyScaleColorFilter(state.iconState.isGrayscale) } CurrencyIcon( modifier = Modifier diff --git a/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/presentation/tokendetails/ui/components/exchange/ExchangeEstimate.kt b/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/presentation/tokendetails/ui/components/exchange/ExchangeEstimate.kt index 6aee05217a..319e6f44fe 100644 --- a/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/presentation/tokendetails/ui/components/exchange/ExchangeEstimate.kt +++ b/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/presentation/tokendetails/ui/components/exchange/ExchangeEstimate.kt @@ -8,7 +8,7 @@ import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.draw.clip import androidx.compose.ui.res.stringResource -import com.tangem.core.ui.components.currency.tokenicon.TokenIconState +import com.tangem.core.ui.components.currency.icon.CurrencyIconState import com.tangem.core.ui.components.inputrow.InputRowApprox import com.tangem.core.ui.extensions.TextReference import com.tangem.core.ui.extensions.resolveReference @@ -19,8 +19,8 @@ import com.tangem.features.tokendetails.impl.R @Composable internal fun ExchangeEstimate( timestamp: TextReference, - fromTokenIconState: TokenIconState, - toTokenIconState: TokenIconState, + fromTokenIconState: CurrencyIconState, + toTokenIconState: CurrencyIconState, fromCryptoAmount: TextReference, fromCryptoSymbol: String, toCryptoAmount: TextReference, diff --git a/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/presentation/tokendetails/ui/components/exchange/ExchangeStatusItems.kt b/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/presentation/tokendetails/ui/components/exchange/ExchangeStatusItems.kt index 1945621d19..4b2a5a1ab4 100644 --- a/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/presentation/tokendetails/ui/components/exchange/ExchangeStatusItems.kt +++ b/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/presentation/tokendetails/ui/components/exchange/ExchangeStatusItems.kt @@ -23,8 +23,8 @@ import androidx.compose.ui.tooling.preview.PreviewParameterProvider import androidx.constraintlayout.compose.* import com.tangem.core.ui.components.atoms.text.EllipsisText import com.tangem.core.ui.components.atoms.text.TextEllipsis -import com.tangem.core.ui.components.currency.tokenicon.TokenIcon -import com.tangem.core.ui.components.currency.tokenicon.TokenIconState +import com.tangem.core.ui.components.currency.icon.CurrencyIcon +import com.tangem.core.ui.components.currency.icon.CurrencyIconState import com.tangem.core.ui.res.TangemTheme import com.tangem.core.ui.res.TangemThemePreview import com.tangem.feature.swap.domain.models.domain.ExchangeStatus @@ -72,8 +72,8 @@ internal fun LazyListScope.swapTransactionsItems( @Composable private fun ExchangeStatusItem( providerName: String, - fromTokenIconState: TokenIconState, - toTokenIconState: TokenIconState, + fromTokenIconState: CurrencyIconState, + toTokenIconState: CurrencyIconState, fromAmount: String, fromSymbol: String, toSymbol: String, @@ -102,7 +102,7 @@ private fun ExchangeStatusItem( top.linkTo(parent.top) }, ) - TokenIcon( + CurrencyIcon( state = fromTokenIconState, shouldDisplayNetwork = false, modifier = Modifier @@ -139,7 +139,7 @@ private fun ExchangeStatusItem( bottom.linkTo(parent.bottom) }, ) - TokenIcon( + CurrencyIcon( state = toTokenIconState, shouldDisplayNetwork = false, modifier = Modifier @@ -205,8 +205,8 @@ private fun ExchangeStatusItemPreview( TangemThemePreview { ExchangeStatusItem( providerName = "ChangeNow", - fromTokenIconState = TokenIconState.Loading, - toTokenIconState = TokenIconState.Loading, + fromTokenIconState = CurrencyIconState.Loading, + toTokenIconState = CurrencyIconState.Loading, fromAmount = amount, fromSymbol = "USDT", toSymbol = "USDT", diff --git a/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/presentation/tokendetails/ui/components/staking/StakingBalanceBlock.kt b/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/presentation/tokendetails/ui/components/staking/StakingBalanceBlock.kt new file mode 100644 index 0000000000..0d5d72efd5 --- /dev/null +++ b/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/presentation/tokendetails/ui/components/staking/StakingBalanceBlock.kt @@ -0,0 +1,104 @@ +package com.tangem.feature.tokendetails.presentation.tokendetails.ui.components.staking + +import android.content.res.Configuration +import androidx.compose.foundation.background +import androidx.compose.foundation.clickable +import androidx.compose.foundation.interaction.MutableInteractionSource +import androidx.compose.foundation.layout.* +import androidx.compose.material.ripple.rememberRipple +import androidx.compose.material3.Icon +import androidx.compose.material3.Text +import androidx.compose.runtime.Composable +import androidx.compose.runtime.remember +import androidx.compose.ui.Alignment +import androidx.compose.ui.Modifier +import androidx.compose.ui.draw.clip +import androidx.compose.ui.res.painterResource +import androidx.compose.ui.res.stringResource +import androidx.compose.ui.tooling.preview.Preview +import androidx.compose.ui.tooling.preview.PreviewParameter +import androidx.compose.ui.tooling.preview.PreviewParameterProvider +import com.tangem.core.ui.extensions.resolveReference +import com.tangem.core.ui.res.TangemTheme +import com.tangem.core.ui.res.TangemThemePreview +import com.tangem.feature.tokendetails.presentation.tokendetails.TokenDetailsPreviewData.stakedBlock +import com.tangem.feature.tokendetails.presentation.tokendetails.state.StakingBlockUM +import com.tangem.features.tokendetails.impl.R +import com.tangem.utils.StringsSigns + +@Composable +internal fun StakingBalanceBlock(state: StakingBlockUM.Staked, modifier: Modifier = Modifier) { + Row( + verticalAlignment = Alignment.CenterVertically, + modifier = modifier + .fillMaxWidth() + .clip(TangemTheme.shapes.roundedCornersXMedium) + .background(TangemTheme.colors.background.action) + .clickable( + interactionSource = remember { MutableInteractionSource() }, + indication = rememberRipple(), + onClick = state.onStakeClicked, + ) + .padding(TangemTheme.dimens.spacing12), + ) { + Column( + verticalArrangement = Arrangement.spacedBy(TangemTheme.dimens.spacing4), + modifier = Modifier.weight(1f), + ) { + Text( + text = stringResource(R.string.staking_native), + style = TangemTheme.typography.subtitle2, + color = TangemTheme.colors.text.tertiary, + modifier = Modifier.padding(vertical = TangemTheme.dimens.spacing2), + ) + Row(horizontalArrangement = Arrangement.spacedBy(TangemTheme.dimens.spacing8)) { + Text( + text = state.fiatValue.resolveReference(), + style = TangemTheme.typography.body2, + color = TangemTheme.colors.text.primary1, + ) + Text( + text = StringsSigns.DOT, + style = TangemTheme.typography.body2, + color = TangemTheme.colors.text.primary1, + ) + Text( + text = state.cryptoValue.resolveReference(), + style = TangemTheme.typography.body2, + color = TangemTheme.colors.text.tertiary, + ) + } + Text( + text = state.rewardValue.resolveReference(), + style = TangemTheme.typography.caption2, + color = TangemTheme.colors.text.tertiary, + ) + } + Icon( + painter = painterResource(id = R.drawable.ic_chevron_right_24), + contentDescription = null, + tint = TangemTheme.colors.icon.informative, + ) + } +} + +// region Preview +@Preview(showBackground = true, widthDp = 360) +@Preview(showBackground = true, widthDp = 360, uiMode = Configuration.UI_MODE_NIGHT_YES) +@Composable +private fun StakingBalanceBlock_Preview( + @PreviewParameter(StakingBalanceBlockPreviewProvider::class) data: StakingBlockUM.Staked, +) { + TangemThemePreview { + StakingBalanceBlock( + state = data, + modifier = Modifier.padding(TangemTheme.dimens.spacing16), + ) + } +} + +private class StakingBalanceBlockPreviewProvider : PreviewParameterProvider { + override val values: Sequence + get() = sequenceOf(stakedBlock) +} +// endregion \ No newline at end of file diff --git a/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/presentation/tokendetails/ui/components/TokenStakingBlock.kt b/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/presentation/tokendetails/ui/components/staking/TokenStakingBlock.kt similarity index 61% rename from features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/presentation/tokendetails/ui/components/TokenStakingBlock.kt rename to features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/presentation/tokendetails/ui/components/staking/TokenStakingBlock.kt index 6ce576304f..c2d7940cbc 100644 --- a/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/presentation/tokendetails/ui/components/TokenStakingBlock.kt +++ b/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/presentation/tokendetails/ui/components/staking/TokenStakingBlock.kt @@ -1,27 +1,31 @@ -package com.tangem.feature.tokendetails.presentation.tokendetails.ui.components +package com.tangem.feature.tokendetails.presentation.tokendetails.ui.components.staking import android.content.res.Configuration import androidx.compose.animation.AnimatedContent import androidx.compose.foundation.background import androidx.compose.foundation.layout.* -import androidx.compose.material.Text -import androidx.compose.runtime.* +import androidx.compose.material3.Text +import androidx.compose.runtime.Composable +import androidx.compose.runtime.remember import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.draw.clip -import androidx.compose.ui.graphics.Color import androidx.compose.ui.res.stringResource 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.components.* -import com.tangem.core.ui.res.TangemThemePreview +import com.tangem.core.ui.components.RectangleShimmer +import com.tangem.core.ui.components.SecondaryButton +import com.tangem.core.ui.components.SpacerW8 import com.tangem.core.ui.res.TangemTheme -import com.tangem.core.ui.utils.GRAY_SCALE_ALPHA -import com.tangem.core.ui.utils.GrayscaleColorFilter -import com.tangem.core.ui.utils.NORMAL_ALPHA +import com.tangem.core.ui.res.TangemThemePreview +import com.tangem.core.ui.utils.getGreyScaleColorFilter +import com.tangem.feature.tokendetails.presentation.tokendetails.TokenDetailsPreviewData.stakingAvailableBlock +import com.tangem.feature.tokendetails.presentation.tokendetails.TokenDetailsPreviewData.stakingErrorBlock +import com.tangem.feature.tokendetails.presentation.tokendetails.TokenDetailsPreviewData.stakingLoadingBlock import com.tangem.feature.tokendetails.presentation.tokendetails.state.IconState -import com.tangem.feature.tokendetails.presentation.tokendetails.state.StakingBlockState +import com.tangem.feature.tokendetails.presentation.tokendetails.state.StakingBlockUM +import com.tangem.feature.tokendetails.presentation.tokendetails.ui.components.CurrencyIcon import com.tangem.features.tokendetails.impl.R /** @@ -31,7 +35,32 @@ import com.tangem.features.tokendetails.impl.R * @param modifier modifier */ @Composable -internal fun TokenStakingBlock(state: StakingBlockState, modifier: Modifier = Modifier) { +internal fun TokenStakingBlock(state: StakingBlockUM, modifier: Modifier = Modifier) { + AnimatedContent( + targetState = state, + contentAlignment = Alignment.CenterStart, + label = "Staking block animation", + ) { + when (it) { + is StakingBlockUM.Error -> Row {} // TODO staking error + is StakingBlockUM.Loading -> StakingLoading( + iconState = it.iconState, + modifier = modifier, + ) + is StakingBlockUM.Staked -> StakingBalanceBlock( + state = it, + modifier = modifier, + ) + is StakingBlockUM.StakeAvailable -> StakingAvailableContent( + state = it, + modifier = modifier, + ) + } + } +} + +@Composable +private fun StakingAvailableContent(state: StakingBlockUM.StakeAvailable, modifier: Modifier = Modifier) { Column( modifier = modifier .background( @@ -39,57 +68,18 @@ internal fun TokenStakingBlock(state: StakingBlockState, modifier: Modifier = Mo shape = TangemTheme.shapes.roundedCornersXMedium, ) .fillMaxWidth() - .heightIn(min = TangemTheme.dimens.size72) .padding(all = TangemTheme.dimens.spacing12), - verticalArrangement = Arrangement.spacedBy(TangemTheme.dimens.spacing4), - horizontalAlignment = Alignment.Start, ) { - Content(state = state) - } -} - -@Composable -private fun Content(state: StakingBlockState, modifier: Modifier = Modifier) { - AnimatedContent( - modifier = modifier.heightIn(min = TangemTheme.dimens.size60), - targetState = state, - contentAlignment = Alignment.CenterStart, - label = "Update the content", - ) { stakingBlockState -> - when (stakingBlockState) { - is StakingBlockState.Content -> { - StakingContent( - stakingBlockState = stakingBlockState, - iconState = stakingBlockState.iconState, - ) - } - is StakingBlockState.Loading -> { - StakingLoading( - iconState = stakingBlockState.iconState, - ) - } - is StakingBlockState.Error -> Row {} // TODO staking - } - } -} - -@Composable -private fun StakingContent(stakingBlockState: StakingBlockState.Content, iconState: IconState) { - Column { Row { - val (alpha, colorFilter) = remember(iconState.isGrayscale) { - if (iconState.isGrayscale) { - GRAY_SCALE_ALPHA to GrayscaleColorFilter - } else { - NORMAL_ALPHA to null - } + val (alpha, colorFilter) = remember(state.iconState.isGrayscale) { + getGreyScaleColorFilter(state.iconState.isGrayscale) } CurrencyIcon( modifier = Modifier .size(TangemTheme.dimens.size20) .clip(TangemTheme.shapes.roundedCorners8) .align(Alignment.CenterVertically), - icon = iconState, + icon = state.iconState, alpha = alpha, colorFilter = colorFilter, ) @@ -98,7 +88,7 @@ private fun StakingContent(stakingBlockState: StakingBlockState.Content, iconSta Text( text = stringResource( R.string.token_details_staking_block_title, - stakingBlockState.interestRate, + state.interestRate, ), color = TangemTheme.colors.text.primary1, style = TangemTheme.typography.subtitle2, @@ -109,8 +99,8 @@ private fun StakingContent(stakingBlockState: StakingBlockState.Content, iconSta Text( text = stringResource( R.string.token_details_staking_block_subtitle, - stakingBlockState.tokenSymbol, - stakingBlockState.periodInDays, + state.tokenSymbol, + state.periodInDays, ), color = TangemTheme.colors.text.tertiary, style = TangemTheme.typography.body2, @@ -121,22 +111,28 @@ private fun StakingContent(stakingBlockState: StakingBlockState.Content, iconSta } SecondaryButton( modifier = Modifier.fillMaxWidth(), - text = "Stake", - onClick = { /* [REDACTED_TODO_COMMENT] */ }, + text = stringResource(id = R.string.common_stake), + onClick = state.onStakeClicked, ) } } @Composable -private fun StakingLoading(iconState: IconState) { - Column { +private fun StakingLoading(iconState: IconState, modifier: Modifier = Modifier) { + Column( + modifier = modifier + .background( + color = TangemTheme.colors.background.primary, + shape = TangemTheme.shapes.roundedCornersXMedium, + ) + .fillMaxWidth() + .heightIn(min = TangemTheme.dimens.size72) + .padding(all = TangemTheme.dimens.spacing12), + + ) { Row { val (alpha, colorFilter) = remember(iconState.isGrayscale) { - if (iconState.isGrayscale) { - GRAY_SCALE_ALPHA to GrayscaleColorFilter - } else { - NORMAL_ALPHA to null - } + getGreyScaleColorFilter(iconState.isGrayscale) } CurrencyIcon( modifier = Modifier @@ -177,30 +173,18 @@ private fun StakingLoading(iconState: IconState) { @Composable private fun Preview_TokenStakingBlock( @PreviewParameter(StakingBlockStateProvider::class) - state: StakingBlockState, + state: StakingBlockUM, ) { TangemThemePreview { TokenStakingBlock(state = state) } } -private class StakingBlockStateProvider : CollectionPreviewParameterProvider( +private class StakingBlockStateProvider : CollectionPreviewParameterProvider( collection = listOf( - StakingBlockState.Content( - iconState = iconState, - interestRate = "10", - periodInDays = 4, - tokenSymbol = "SOL", - ), - StakingBlockState.Loading(iconState = iconState), - StakingBlockState.Error(iconState = iconState), + stakingLoadingBlock, + stakingAvailableBlock, + stakingErrorBlock, ), ) - -private val iconState = IconState.TokenIcon( - url = "https://s3.eu-central-1.amazonaws.com/tangem.api/coins/large/stellar.png", - fallbackTint = Color.Cyan, - fallbackBackground = Color.Blue, - isGrayscale = false, -) // endregion Preview \ No newline at end of file diff --git a/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/presentation/tokendetails/viewmodels/TokenDetailsClickIntents.kt b/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/presentation/tokendetails/viewmodels/TokenDetailsClickIntents.kt index 9781e7cca9..833a3a3f0b 100644 --- a/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/presentation/tokendetails/viewmodels/TokenDetailsClickIntents.kt +++ b/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/presentation/tokendetails/viewmodels/TokenDetailsClickIntents.kt @@ -4,6 +4,7 @@ import com.tangem.core.ui.components.bottomsheets.tokenreceive.AddressModel import com.tangem.core.ui.extensions.TextReference import com.tangem.domain.tokens.model.CryptoCurrency import com.tangem.domain.tokens.model.ScenarioUnavailabilityReason +import com.tangem.feature.tokendetails.presentation.tokendetails.state.TokenBalanceSegmentedButtonConfig @Suppress("TooManyFunctions") interface TokenDetailsClickIntents { @@ -12,6 +13,8 @@ interface TokenDetailsClickIntents { fun onReceiveClick(unavailabilityReason: ScenarioUnavailabilityReason) + fun onStakeClick(unavailabilityReason: ScenarioUnavailabilityReason) + fun onSendClick(unavailabilityReason: ScenarioUnavailabilityReason) fun onSwapClick(unavailabilityReason: ScenarioUnavailabilityReason) @@ -56,6 +59,10 @@ interface TokenDetailsClickIntents { fun onAssociateClick() + fun onStakeBannerClick() + + fun onBalanceSelect(config: TokenBalanceSegmentedButtonConfig) + fun onGoToRefundedTokenClick(cryptoCurrency: CryptoCurrency) fun onOpenUrlClick(url: String) diff --git a/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/presentation/tokendetails/viewmodels/TokenDetailsViewModel.kt b/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/presentation/tokendetails/viewmodels/TokenDetailsViewModel.kt index 557903c7ca..bffe54c894 100644 --- a/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/presentation/tokendetails/viewmodels/TokenDetailsViewModel.kt +++ b/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/presentation/tokendetails/viewmodels/TokenDetailsViewModel.kt @@ -1,9 +1,12 @@ package com.tangem.feature.tokendetails.presentation.tokendetails.viewmodels +import android.os.Bundle import androidx.lifecycle.* import androidx.paging.cachedIn import arrow.core.getOrElse import com.tangem.blockchain.common.address.AddressType +import com.tangem.common.routing.AppRoute +import com.tangem.common.routing.bundle.unbundle import com.tangem.core.analytics.api.AnalyticsEventHandler import com.tangem.core.analytics.models.AnalyticsParam import com.tangem.core.deeplink.DeepLinksRegistry @@ -22,12 +25,14 @@ import com.tangem.domain.appcurrency.GetSelectedAppCurrencyUseCase import com.tangem.domain.appcurrency.model.AppCurrency import com.tangem.domain.balancehiding.GetBalanceHidingSettingsUseCase import com.tangem.domain.card.GetExtendedPublicKeyForCurrencyUseCase +import com.tangem.domain.card.NetworkHasDerivationUseCase import com.tangem.domain.common.util.cardTypesResolver import com.tangem.domain.demo.IsDemoCardUseCase import com.tangem.domain.redux.ReduxStateHolder import com.tangem.domain.settings.ShouldShowSwapPromoTokenUseCase import com.tangem.domain.staking.GetStakingAvailabilityUseCase import com.tangem.domain.staking.GetStakingEntryInfoUseCase +import com.tangem.domain.staking.GetYieldUseCase import com.tangem.domain.staking.model.StakingAvailability import com.tangem.domain.tokens.* import com.tangem.domain.tokens.legacy.TradeCryptoAction @@ -58,12 +63,13 @@ import com.tangem.feature.tokendetails.presentation.router.InnerTokenDetailsRout import com.tangem.feature.tokendetails.presentation.tokendetails.analytics.TokenDetailsCurrencyStatusAnalyticsSender import com.tangem.feature.tokendetails.presentation.tokendetails.analytics.TokenDetailsNotificationsAnalyticsSender import com.tangem.feature.tokendetails.presentation.tokendetails.state.SwapTransactionsState +import com.tangem.feature.tokendetails.presentation.tokendetails.state.TokenBalanceSegmentedButtonConfig import com.tangem.feature.tokendetails.presentation.tokendetails.state.TokenDetailsState import com.tangem.feature.tokendetails.presentation.tokendetails.state.factory.TokenDetailsStateFactory import com.tangem.feature.tokendetails.presentation.tokendetails.ui.components.exchange.ExchangeStatusBottomSheetConfig +import com.tangem.features.staking.api.featuretoggles.StakingFeatureToggles import com.tangem.features.tokendetails.featuretoggles.TokenDetailsFeatureToggles import com.tangem.features.tokendetails.impl.R -import com.tangem.features.tokendetails.navigation.TokenDetailsRouter import com.tangem.lib.crypto.BlockchainUtils.isBitcoin import com.tangem.utils.Provider import com.tangem.utils.coroutines.* @@ -101,7 +107,10 @@ internal class TokenDetailsViewModel @Inject constructor( private val updateDelayedCurrencyStatusUseCase: UpdateDelayedNetworkStatusUseCase, private val getExtendedPublicKeyForCurrencyUseCase: GetExtendedPublicKeyForCurrencyUseCase, private val getStakingEntryInfoUseCase: GetStakingEntryInfoUseCase, + private val stakingFeatureToggles: StakingFeatureToggles, private val getStakingAvailabilityUseCase: GetStakingAvailabilityUseCase, + private val getYieldUseCase: GetYieldUseCase, + private val networkHasDerivationUseCase: NetworkHasDerivationUseCase, private val swapRepository: SwapRepository, private val swapTransactionRepository: SwapTransactionRepository, private val quotesRepository: QuotesRepository, @@ -112,18 +121,20 @@ internal class TokenDetailsViewModel @Inject constructor( private val analyticsEventsHandler: AnalyticsEventHandler, private val hapticManager: HapticManager, private val clipboardManager: ClipboardManager, + private val getUserWalletUseCase: GetUserWalletUseCase, tokenDetailsFeatureToggles: TokenDetailsFeatureToggles, - getUserWalletUseCase: GetUserWalletUseCase, deepLinksRegistry: DeepLinksRegistry, savedStateHandle: SavedStateHandle, ) : ViewModel(), DefaultLifecycleObserver, TokenDetailsClickIntents { - private val userWalletId: UserWalletId = savedStateHandle.get(TokenDetailsRouter.USER_WALLET_ID_KEY) - ?.let { stringValue -> UserWalletId(stringValue) } + private val userWalletId: UserWalletId = savedStateHandle.get(AppRoute.CurrencyDetails.USER_WALLET_ID_KEY) + ?.unbundle(UserWalletId.serializer()) ?: error("This screen can't open without `UserWalletId`") - private val cryptoCurrency: CryptoCurrency = savedStateHandle[TokenDetailsRouter.CRYPTO_CURRENCY_KEY] - ?: error("This screen can't open without `CryptoCurrency`") + private val cryptoCurrency: CryptoCurrency = + savedStateHandle.get(AppRoute.CurrencyDetails.CRYPTO_CURRENCY_KEY) + ?.unbundle(CryptoCurrency.serializer()) + ?: error("This screen can't open without `CryptoCurrency`") private val userWallet: UserWallet @@ -142,13 +153,15 @@ internal class TokenDetailsViewModel @Inject constructor( private val stateFactory = TokenDetailsStateFactory( currentStateProvider = Provider { uiState.value }, appCurrencyProvider = Provider(selectedAppCurrencyFlow::value), - stakingAvailabilityProvider = Provider { - getStakingAvailabilityUseCase.invoke(cryptoCurrency.network.id.value) - }, + cryptoCurrencyStatusProvider = Provider { cryptoCurrencyStatus }, clickIntents = this, symbol = cryptoCurrency.symbol, decimals = cryptoCurrency.decimals, featureToggles = tokenDetailsFeatureToggles, + stakingFeatureToggles = stakingFeatureToggles, + userWalletId = userWalletId, + networkHasDerivationUseCase = networkHasDerivationUseCase, + getUserWalletUseCase = getUserWalletUseCase, ) private val exchangeStatusFactory by lazy(mode = LazyThreadSafetyMode.NONE) { @@ -216,7 +229,10 @@ internal class TokenDetailsViewModel @Inject constructor( subscribeOnCurrencyStatusUpdates() subscribeOnExchangeTransactionsUpdates() updateTxHistory(refresh = false, showItemsLoading = true) - updateStakingInfo() + + if (stakingFeatureToggles.isStakingEnabled) { + updateStakingInfo() + } } private fun handleBalanceHiding(owner: LifecycleOwner) { @@ -371,10 +387,18 @@ internal class TokenDetailsViewModel @Inject constructor( } private fun updateStakingInfo() { - viewModelScope.launch(dispatchers.main) { - val stakingAvailability = getStakingAvailabilityUseCase(cryptoCurrency.network.id.value) + viewModelScope.launch { + val stakingAvailability = getStakingAvailabilityUseCase( + cryptoCurrencyId = cryptoCurrency.id, + symbol = cryptoCurrency.symbol, + ).getOrElse { StakingAvailability.Unavailable } + + internalUiState.value = stateFactory.getStateWithUpdatedStakingAvailability(stakingAvailability) if (stakingAvailability is StakingAvailability.Available) { - val stakingInfo = getStakingEntryInfoUseCase(stakingAvailability.integrationId) + val stakingInfo = getStakingEntryInfoUseCase( + cryptoCurrencyId = cryptoCurrency.id, + symbol = cryptoCurrency.symbol, + ) internalUiState.value = stateFactory.getStateWithStaking(stakingInfo) } } @@ -382,8 +406,11 @@ internal class TokenDetailsViewModel @Inject constructor( private fun updateTopBarMenu() { viewModelScope.launch(dispatchers.main) { + val hasDerivations = + networkHasDerivationUseCase(userWallet.scanResponse, cryptoCurrency.network).getOrElse { false } internalUiState.value = stateFactory.getStateWithUpdatedMenu( cardTypesResolver = userWallet.scanResponse.cardTypesResolver, + hasDerivations = hasDerivations, isBitcoin = isBitcoin(cryptoCurrency.network.id.value), ) } @@ -430,6 +457,10 @@ internal class TokenDetailsViewModel @Inject constructor( router.openTokenDetails(userWalletId = userWalletId, currency = cryptoCurrency) } + override fun onStakeBannerClick() { + openStaking() + } + override fun onReloadClick() { analyticsEventsHandler.send(TokenScreenAnalyticsEvent.ButtonReload(cryptoCurrency.symbol)) internalUiState.value = stateFactory.getLoadingTxHistoryState() @@ -527,6 +558,12 @@ internal class TokenDetailsViewModel @Inject constructor( } } + override fun onStakeClick(unavailabilityReason: ScenarioUnavailabilityReason) { + if (handleUnavailabilityReason(unavailabilityReason)) return + + openStaking() + } + override fun onGenerateExtendedKey() { viewModelScope.launch(dispatchers.main) { val extendedKey = getExtendedPublicKeyForCurrencyUseCase( @@ -803,6 +840,10 @@ internal class TokenDetailsViewModel @Inject constructor( } } + override fun onBalanceSelect(config: TokenBalanceSegmentedButtonConfig) { + internalUiState.value = stateFactory.getStateWithUpdatedBalanceSegmentedButtonConfig(config) + } + private fun handleUnavailabilityReason(unavailabilityReason: ScenarioUnavailabilityReason): Boolean { if (unavailabilityReason == ScenarioUnavailabilityReason.None) return false @@ -811,6 +852,19 @@ internal class TokenDetailsViewModel @Inject constructor( return true } + private fun openStaking() { + viewModelScope.launch { + val yield = getYieldUseCase.invoke( + cryptoCurrencyId = cryptoCurrency.id, + symbol = cryptoCurrency.symbol, + ).getOrElse { + error("Staking is unavailable for ${cryptoCurrency.name}") + } + + router.openStaking(userWalletId, cryptoCurrency, yield) + } + } + private companion object { const val EXCHANGE_STATUS_UPDATE_DELAY = 10_000L } diff --git a/features/wallet-settings/api/.gitignore b/features/wallet-settings/api/.gitignore new file mode 100644 index 0000000000..796b96d1c4 --- /dev/null +++ b/features/wallet-settings/api/.gitignore @@ -0,0 +1 @@ +/build diff --git a/features/wallet-settings/api/build.gradle.kts b/features/wallet-settings/api/build.gradle.kts new file mode 100644 index 0000000000..7c48ae5a59 --- /dev/null +++ b/features/wallet-settings/api/build.gradle.kts @@ -0,0 +1,19 @@ +plugins { + alias(deps.plugins.android.library) + alias(deps.plugins.kotlin.android) + id("configuration") +} + +android { + namespace = "com.tangem.feature.walletsettings.api" +} + +dependencies { + + /* Project - Domain */ + implementation(projects.domain.wallets.models) + + /* Project - Core */ + implementation(projects.core.decompose) + implementation(projects.core.ui) +} \ No newline at end of file diff --git a/features/wallet-settings/api/src/main/kotlin/com/tangem/feature/walletsettings/component/RenameWalletComponent.kt b/features/wallet-settings/api/src/main/kotlin/com/tangem/feature/walletsettings/component/RenameWalletComponent.kt new file mode 100644 index 0000000000..4d3b21b9f1 --- /dev/null +++ b/features/wallet-settings/api/src/main/kotlin/com/tangem/feature/walletsettings/component/RenameWalletComponent.kt @@ -0,0 +1,16 @@ +package com.tangem.feature.walletsettings.component + +import com.tangem.core.decompose.factory.ComponentFactory +import com.tangem.core.ui.decompose.ComposableDialogComponent +import com.tangem.domain.wallets.models.UserWalletId + +interface RenameWalletComponent : ComposableDialogComponent { + + data class Params( + val userWalletId: UserWalletId, + val currentName: String, + val onDismiss: () -> Unit, + ) + + interface Factory : ComponentFactory +} \ No newline at end of file diff --git a/features/wallet-settings/api/src/main/kotlin/com/tangem/feature/walletsettings/component/WalletSettingsComponent.kt b/features/wallet-settings/api/src/main/kotlin/com/tangem/feature/walletsettings/component/WalletSettingsComponent.kt new file mode 100644 index 0000000000..2c8cdd889a --- /dev/null +++ b/features/wallet-settings/api/src/main/kotlin/com/tangem/feature/walletsettings/component/WalletSettingsComponent.kt @@ -0,0 +1,14 @@ +package com.tangem.feature.walletsettings.component + +import com.tangem.core.decompose.factory.ComponentFactory +import com.tangem.core.ui.decompose.ComposableContentComponent +import com.tangem.domain.wallets.models.UserWalletId + +interface WalletSettingsComponent : ComposableContentComponent { + + data class Params( + val userWalletId: UserWalletId, + ) + + interface Factory : ComponentFactory +} \ No newline at end of file diff --git a/features/wallet-settings/impl/.gitignore b/features/wallet-settings/impl/.gitignore new file mode 100644 index 0000000000..796b96d1c4 --- /dev/null +++ b/features/wallet-settings/impl/.gitignore @@ -0,0 +1 @@ +/build diff --git a/features/wallet-settings/impl/build.gradle.kts b/features/wallet-settings/impl/build.gradle.kts new file mode 100644 index 0000000000..14885a740b --- /dev/null +++ b/features/wallet-settings/impl/build.gradle.kts @@ -0,0 +1,56 @@ +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") +} + +android { + namespace = "com.tangem.feature.walletsettings.impl" +} + +dependencies { + + /* Project - API */ + implementation(projects.features.walletSettings.api) + + /* Project - Core */ + implementation(projects.core.decompose) + implementation(projects.core.ui) + implementation(projects.core.featuretoggles) + implementation(projects.core.navigation) + implementation(projects.core.analytics) + implementation(projects.core.analytics.models) + implementation(projects.common.routing) + + /* Project - Domain */ + implementation(projects.domain.legacy) + implementation(projects.domain.models) + implementation(projects.domain.wallets) + implementation(projects.domain.wallets.models) + + /* AndroidX */ + implementation(deps.androidx.fragment.ktx) + implementation(deps.androidx.activity.compose) + implementation(deps.lifecycle.compose) + + /* Compose */ + implementation(deps.compose.ui) + implementation(deps.compose.ui.tooling) + implementation(deps.compose.accompanist.systemUiController) + implementation(deps.compose.foundation) + implementation(deps.compose.material3) + implementation(deps.compose.shimmer) + implementation(deps.decompose.ext.compose) + + /* DI */ + implementation(deps.hilt.android) + kapt(deps.hilt.kapt) + + /* Other */ + implementation(deps.kotlin.immutable.collections) + implementation(deps.timber) + implementation(deps.reKotlin) +} \ No newline at end of file diff --git a/features/wallet-settings/impl/src/main/kotlin/com/tangem/feature/walletsettings/analytics/Settings.kt b/features/wallet-settings/impl/src/main/kotlin/com/tangem/feature/walletsettings/analytics/Settings.kt new file mode 100644 index 0000000000..9a655d973a --- /dev/null +++ b/features/wallet-settings/impl/src/main/kotlin/com/tangem/feature/walletsettings/analytics/Settings.kt @@ -0,0 +1,13 @@ +package com.tangem.feature.walletsettings.analytics + +import com.tangem.core.analytics.models.AnalyticsEvent + +internal sealed class Settings( + category: String = "Settings", + event: String, + params: Map = mapOf(), + error: Throwable? = null, +) : AnalyticsEvent(category, event, params, error) { + + class ButtonCreateBackup : Settings(event = "Button - Create Backup") +} \ No newline at end of file diff --git a/features/wallet-settings/impl/src/main/kotlin/com/tangem/feature/walletsettings/component/impl/DefaultRenameWalletComponent.kt b/features/wallet-settings/impl/src/main/kotlin/com/tangem/feature/walletsettings/component/impl/DefaultRenameWalletComponent.kt new file mode 100644 index 0000000000..902d26f1ef --- /dev/null +++ b/features/wallet-settings/impl/src/main/kotlin/com/tangem/feature/walletsettings/component/impl/DefaultRenameWalletComponent.kt @@ -0,0 +1,96 @@ +package com.tangem.feature.walletsettings.component.impl + +import androidx.compose.runtime.Composable +import androidx.compose.runtime.getValue +import androidx.compose.ui.text.input.TextFieldValue +import androidx.lifecycle.compose.collectAsStateWithLifecycle +import com.tangem.core.decompose.context.AppComponentContext +import com.tangem.core.ui.extensions.resourceReference +import com.tangem.core.ui.extensions.wrappedList +import com.tangem.core.ui.message.SnackbarMessage +import com.tangem.domain.wallets.models.UpdateWalletError +import com.tangem.domain.wallets.models.UserWalletId +import com.tangem.domain.wallets.usecase.RenameWalletUseCase +import com.tangem.feature.walletsettings.component.RenameWalletComponent +import com.tangem.feature.walletsettings.entity.RenameWalletUM +import com.tangem.feature.walletsettings.impl.R +import com.tangem.feature.walletsettings.ui.RenameWalletDialog +import dagger.assisted.Assisted +import dagger.assisted.AssistedFactory +import dagger.assisted.AssistedInject +import kotlinx.coroutines.flow.MutableStateFlow +import kotlinx.coroutines.flow.update +import kotlinx.coroutines.launch +import timber.log.Timber + +internal class DefaultRenameWalletComponent @AssistedInject constructor( + @Assisted context: AppComponentContext, + @Assisted private val params: RenameWalletComponent.Params, + private val renameWalletUseCase: RenameWalletUseCase, +) : RenameWalletComponent, AppComponentContext by context { + + private val currentWalletName = params.currentName + + private val stateFlow: MutableStateFlow = MutableStateFlow( + value = RenameWalletUM( + walletNameValue = TextFieldValue(text = params.currentName), + updateValue = ::updateValue, + isConfirmEnabled = false, + onConfirm = { renameWallet(params.userWalletId) }, + ), + ) + + override fun dismiss() { + params.onDismiss() + } + + @Composable + override fun Dialog() { + val model by stateFlow.collectAsStateWithLifecycle() + + RenameWalletDialog( + model = model, + onDismiss = ::dismiss, + ) + } + + private fun updateValue(value: TextFieldValue) { + stateFlow.update { + it.copy( + walletNameValue = value, + isConfirmEnabled = value.text.isNotBlank() && value.text != currentWalletName, + ) + } + } + + private fun renameWallet(userWalletId: UserWalletId) = componentScope.launch { + stateFlow.update { it.copy(isConfirmEnabled = false) } + + val newName = stateFlow.value.walletNameValue + val maybeError = renameWalletUseCase(userWalletId, newName.text).leftOrNull() + + if (maybeError != null) { + Timber.e("Unable to rename wallet: $maybeError") + + val message = when (maybeError) { + is UpdateWalletError.DataError -> resourceReference(id = R.string.common_unknown_error) + is UpdateWalletError.NameAlreadyExists -> resourceReference( + id = R.string.user_wallet_list_rename_popup_error_already_exists, + formatArgs = wrappedList(newName), + ) + } + + messageSender.send(message = SnackbarMessage(message)) + } + + dismiss() + } + + @AssistedFactory + interface Factory : RenameWalletComponent.Factory { + override fun create( + context: AppComponentContext, + params: RenameWalletComponent.Params, + ): DefaultRenameWalletComponent + } +} \ No newline at end of file diff --git a/features/wallet-settings/impl/src/main/kotlin/com/tangem/feature/walletsettings/component/impl/DefaultWalletSettingsComponent.kt b/features/wallet-settings/impl/src/main/kotlin/com/tangem/feature/walletsettings/component/impl/DefaultWalletSettingsComponent.kt new file mode 100644 index 0000000000..39ed1d65a5 --- /dev/null +++ b/features/wallet-settings/impl/src/main/kotlin/com/tangem/feature/walletsettings/component/impl/DefaultWalletSettingsComponent.kt @@ -0,0 +1,74 @@ +package com.tangem.feature.walletsettings.component.impl + +import androidx.compose.runtime.Composable +import androidx.compose.runtime.getValue +import androidx.compose.ui.Modifier +import androidx.lifecycle.compose.collectAsStateWithLifecycle +import com.arkivanov.decompose.ComponentContext +import com.arkivanov.decompose.extensions.compose.jetpack.subscribeAsState +import com.arkivanov.decompose.router.slot.childSlot +import com.arkivanov.decompose.router.slot.dismiss +import com.tangem.core.decompose.context.AppComponentContext +import com.tangem.core.decompose.context.childByContext +import com.tangem.core.decompose.model.getOrCreateModel +import com.tangem.core.ui.decompose.ComposableDialogComponent +import com.tangem.feature.walletsettings.component.RenameWalletComponent +import com.tangem.feature.walletsettings.component.WalletSettingsComponent +import com.tangem.feature.walletsettings.entity.DialogConfig +import com.tangem.feature.walletsettings.model.WalletSettingsModel +import com.tangem.feature.walletsettings.ui.WalletSettingsScreen +import dagger.assisted.Assisted +import dagger.assisted.AssistedFactory +import dagger.assisted.AssistedInject + +internal class DefaultWalletSettingsComponent @AssistedInject constructor( + @Assisted context: AppComponentContext, + @Assisted params: WalletSettingsComponent.Params, + private val renameWalletComponentFactory: RenameWalletComponent.Factory, +) : WalletSettingsComponent, AppComponentContext by context { + + private val model: WalletSettingsModel = getOrCreateModel(params) + + private val dialog = childSlot( + source = model.dialogNavigation, + serializer = DialogConfig.serializer(), + handleBackButton = true, + childFactory = ::dialogChild, + ) + + @Composable + override fun Content(modifier: Modifier) { + val state by model.state.collectAsStateWithLifecycle() + val dialog by dialog.subscribeAsState() + + WalletSettingsScreen( + modifier = modifier, + state = state, + dialog = { dialog.child?.instance?.Dialog() }, + ) + } + + private fun dialogChild( + dialogConfig: DialogConfig, + componentContext: ComponentContext, + ): ComposableDialogComponent = when (dialogConfig) { + is DialogConfig.RenameWallet -> { + renameWalletComponentFactory.create( + context = childByContext(componentContext), + params = RenameWalletComponent.Params( + userWalletId = dialogConfig.userWalletId, + currentName = dialogConfig.currentName, + onDismiss = model.dialogNavigation::dismiss, + ), + ) + } + } + + @AssistedFactory + interface Factory : WalletSettingsComponent.Factory { + override fun create( + context: AppComponentContext, + params: WalletSettingsComponent.Params, + ): DefaultWalletSettingsComponent + } +} \ No newline at end of file diff --git a/features/wallet-settings/impl/src/main/kotlin/com/tangem/feature/walletsettings/component/preview/PreviewRenameWalletComponent.kt b/features/wallet-settings/impl/src/main/kotlin/com/tangem/feature/walletsettings/component/preview/PreviewRenameWalletComponent.kt new file mode 100644 index 0000000000..fbcb3d6389 --- /dev/null +++ b/features/wallet-settings/impl/src/main/kotlin/com/tangem/feature/walletsettings/component/preview/PreviewRenameWalletComponent.kt @@ -0,0 +1,24 @@ +package com.tangem.feature.walletsettings.component.preview + +import androidx.compose.runtime.Composable +import androidx.compose.ui.text.input.TextFieldValue +import com.tangem.feature.walletsettings.component.RenameWalletComponent +import com.tangem.feature.walletsettings.entity.RenameWalletUM +import com.tangem.feature.walletsettings.ui.RenameWalletDialog + +internal class PreviewRenameWalletComponent : RenameWalletComponent { + + private val previewState = RenameWalletUM( + walletNameValue = TextFieldValue(text = "My Wallet"), + isConfirmEnabled = false, + updateValue = {}, + onConfirm = {}, + ) + + override fun dismiss() {} + + @Composable + override fun Dialog() { + RenameWalletDialog(model = previewState, onDismiss = {}) + } +} \ No newline at end of file diff --git a/features/wallet-settings/impl/src/main/kotlin/com/tangem/feature/walletsettings/component/preview/PreviewWalletSettingsComponent.kt b/features/wallet-settings/impl/src/main/kotlin/com/tangem/feature/walletsettings/component/preview/PreviewWalletSettingsComponent.kt new file mode 100644 index 0000000000..4dba365556 --- /dev/null +++ b/features/wallet-settings/impl/src/main/kotlin/com/tangem/feature/walletsettings/component/preview/PreviewWalletSettingsComponent.kt @@ -0,0 +1,37 @@ +package com.tangem.feature.walletsettings.component.preview + +import androidx.compose.runtime.Composable +import androidx.compose.ui.Modifier +import com.tangem.core.decompose.navigation.DummyRouter +import com.tangem.domain.wallets.models.UserWalletId +import com.tangem.feature.walletsettings.component.WalletSettingsComponent +import com.tangem.feature.walletsettings.entity.WalletSettingsUM +import com.tangem.feature.walletsettings.ui.WalletSettingsScreen +import com.tangem.feature.walletsettings.utils.ItemsBuilder + +internal class PreviewWalletSettingsComponent : WalletSettingsComponent { + + private val previewState = WalletSettingsUM( + popBack = {}, + items = ItemsBuilder( + router = DummyRouter(), + ).buildItems( + userWalletId = UserWalletId("011"), + userWalletName = "My Wallet", + isReferralAvailable = true, + isLinkMoreCardsAvailable = true, + renameWallet = {}, + forgetWallet = {}, + onLinkMoreCardsClick = {}, + ), + ) + + @Composable + override fun Content(modifier: Modifier) { + WalletSettingsScreen( + modifier = modifier, + state = previewState, + dialog = {}, + ) + } +} \ No newline at end of file diff --git a/features/wallet-settings/impl/src/main/kotlin/com/tangem/feature/walletsettings/di/ComponentModule.kt b/features/wallet-settings/impl/src/main/kotlin/com/tangem/feature/walletsettings/di/ComponentModule.kt new file mode 100644 index 0000000000..90ff4e1255 --- /dev/null +++ b/features/wallet-settings/impl/src/main/kotlin/com/tangem/feature/walletsettings/di/ComponentModule.kt @@ -0,0 +1,26 @@ +package com.tangem.feature.walletsettings.di + +import com.tangem.feature.walletsettings.component.RenameWalletComponent +import com.tangem.feature.walletsettings.component.WalletSettingsComponent +import com.tangem.feature.walletsettings.component.impl.DefaultRenameWalletComponent +import com.tangem.feature.walletsettings.component.impl.DefaultWalletSettingsComponent +import dagger.Binds +import dagger.Module +import dagger.hilt.InstallIn +import dagger.hilt.components.SingletonComponent +import javax.inject.Singleton + +@Module +@InstallIn(SingletonComponent::class) +internal interface ComponentModule { + + @Binds + @Singleton + fun bindWalletSettingsComponentFactory( + factory: DefaultWalletSettingsComponent.Factory, + ): WalletSettingsComponent.Factory + + @Binds + @Singleton + fun bindRenameWalletComponentFactory(factory: DefaultRenameWalletComponent.Factory): RenameWalletComponent.Factory +} \ No newline at end of file diff --git a/features/wallet-settings/impl/src/main/kotlin/com/tangem/feature/walletsettings/di/ModelModule.kt b/features/wallet-settings/impl/src/main/kotlin/com/tangem/feature/walletsettings/di/ModelModule.kt new file mode 100644 index 0000000000..f7c93024a5 --- /dev/null +++ b/features/wallet-settings/impl/src/main/kotlin/com/tangem/feature/walletsettings/di/ModelModule.kt @@ -0,0 +1,20 @@ +package com.tangem.feature.walletsettings.di + +import com.tangem.core.decompose.di.DecomposeComponent +import com.tangem.core.decompose.model.Model +import com.tangem.feature.walletsettings.model.WalletSettingsModel +import dagger.Binds +import dagger.Module +import dagger.hilt.InstallIn +import dagger.multibindings.ClassKey +import dagger.multibindings.IntoMap + +@Module +@InstallIn(DecomposeComponent::class) +internal interface ModelModule { + + @Binds + @IntoMap + @ClassKey(WalletSettingsModel::class) + fun provideWalletSettingsModel(model: WalletSettingsModel): Model +} \ No newline at end of file diff --git a/features/wallet-settings/impl/src/main/kotlin/com/tangem/feature/walletsettings/entity/DialogConfig.kt b/features/wallet-settings/impl/src/main/kotlin/com/tangem/feature/walletsettings/entity/DialogConfig.kt new file mode 100644 index 0000000000..b338e5d3eb --- /dev/null +++ b/features/wallet-settings/impl/src/main/kotlin/com/tangem/feature/walletsettings/entity/DialogConfig.kt @@ -0,0 +1,14 @@ +package com.tangem.feature.walletsettings.entity + +import com.tangem.domain.wallets.models.UserWalletId +import kotlinx.serialization.Serializable + +@Serializable +internal sealed interface DialogConfig { + + @Serializable + data class RenameWallet( + val userWalletId: UserWalletId, + val currentName: String, + ) : DialogConfig +} \ No newline at end of file diff --git a/features/wallet-settings/impl/src/main/kotlin/com/tangem/feature/walletsettings/entity/RenameWalletUM.kt b/features/wallet-settings/impl/src/main/kotlin/com/tangem/feature/walletsettings/entity/RenameWalletUM.kt new file mode 100644 index 0000000000..730cc1ee60 --- /dev/null +++ b/features/wallet-settings/impl/src/main/kotlin/com/tangem/feature/walletsettings/entity/RenameWalletUM.kt @@ -0,0 +1,12 @@ +package com.tangem.feature.walletsettings.entity + +import androidx.compose.runtime.Immutable +import androidx.compose.ui.text.input.TextFieldValue + +@Immutable +internal data class RenameWalletUM( + val walletNameValue: TextFieldValue, + val updateValue: (value: TextFieldValue) -> Unit, + val isConfirmEnabled: Boolean, + val onConfirm: () -> Unit, +) \ No newline at end of file diff --git a/features/wallet-settings/impl/src/main/kotlin/com/tangem/feature/walletsettings/entity/WalletSettingsItemUM.kt b/features/wallet-settings/impl/src/main/kotlin/com/tangem/feature/walletsettings/entity/WalletSettingsItemUM.kt new file mode 100644 index 0000000000..9596f1fa02 --- /dev/null +++ b/features/wallet-settings/impl/src/main/kotlin/com/tangem/feature/walletsettings/entity/WalletSettingsItemUM.kt @@ -0,0 +1,25 @@ +package com.tangem.feature.walletsettings.entity + +import androidx.compose.runtime.Immutable +import com.tangem.core.ui.components.block.model.BlockUM +import com.tangem.core.ui.extensions.TextReference +import kotlinx.collections.immutable.ImmutableList + +@Immutable +internal sealed class WalletSettingsItemUM { + + abstract val id: String + + data class WithItems( + override val id: String, + val description: TextReference, + val blocks: ImmutableList, + ) : WalletSettingsItemUM() + + data class WithText( + override val id: String, + val title: TextReference, + val text: TextReference, + val onClick: () -> Unit, + ) : WalletSettingsItemUM() +} \ No newline at end of file diff --git a/features/wallet-settings/impl/src/main/kotlin/com/tangem/feature/walletsettings/entity/WalletSettingsUM.kt b/features/wallet-settings/impl/src/main/kotlin/com/tangem/feature/walletsettings/entity/WalletSettingsUM.kt new file mode 100644 index 0000000000..749a2ce005 --- /dev/null +++ b/features/wallet-settings/impl/src/main/kotlin/com/tangem/feature/walletsettings/entity/WalletSettingsUM.kt @@ -0,0 +1,10 @@ +package com.tangem.feature.walletsettings.entity + +import androidx.compose.runtime.Immutable +import kotlinx.collections.immutable.PersistentList + +@Immutable +internal data class WalletSettingsUM( + val popBack: () -> Unit, + val items: PersistentList, +) \ No newline at end of file diff --git a/features/wallet-settings/impl/src/main/kotlin/com/tangem/feature/walletsettings/model/WalletSettingsModel.kt b/features/wallet-settings/impl/src/main/kotlin/com/tangem/feature/walletsettings/model/WalletSettingsModel.kt new file mode 100644 index 0000000000..a9e5b42932 --- /dev/null +++ b/features/wallet-settings/impl/src/main/kotlin/com/tangem/feature/walletsettings/model/WalletSettingsModel.kt @@ -0,0 +1,158 @@ +package com.tangem.feature.walletsettings.model + +import androidx.compose.ui.res.stringResource +import arrow.core.getOrElse +import com.arkivanov.decompose.router.slot.SlotNavigation +import com.arkivanov.decompose.router.slot.activate +import com.tangem.common.routing.AppRoute +import com.tangem.core.analytics.api.AnalyticsEventHandler +import com.tangem.core.analytics.utils.AnalyticsContextProxy +import com.tangem.core.decompose.di.ComponentScoped +import com.tangem.core.decompose.model.Model +import com.tangem.core.decompose.model.ParamsContainer +import com.tangem.core.decompose.navigation.Router +import com.tangem.core.decompose.ui.UiMessageSender +import com.tangem.core.ui.components.BasicDialog +import com.tangem.core.ui.components.DialogButton +import com.tangem.core.ui.extensions.resourceReference +import com.tangem.core.ui.message.ContentMessage +import com.tangem.core.ui.message.SnackbarMessage +import com.tangem.domain.common.util.cardTypesResolver +import com.tangem.domain.models.scan.CardDTO +import com.tangem.domain.models.scan.ScanResponse +import com.tangem.domain.redux.LegacyAction +import com.tangem.domain.redux.ReduxStateHolder +import com.tangem.domain.wallets.models.UserWallet +import com.tangem.domain.wallets.usecase.DeleteWalletUseCase +import com.tangem.domain.wallets.usecase.GetUserWalletUseCase +import com.tangem.feature.walletsettings.analytics.Settings +import com.tangem.feature.walletsettings.component.WalletSettingsComponent +import com.tangem.feature.walletsettings.entity.DialogConfig +import com.tangem.feature.walletsettings.entity.WalletSettingsItemUM +import com.tangem.feature.walletsettings.entity.WalletSettingsUM +import com.tangem.feature.walletsettings.impl.R +import com.tangem.feature.walletsettings.utils.ItemsBuilder +import com.tangem.utils.coroutines.CoroutineDispatcherProvider +import kotlinx.collections.immutable.PersistentList +import kotlinx.collections.immutable.persistentListOf +import kotlinx.coroutines.flow.* +import kotlinx.coroutines.launch +import timber.log.Timber +import javax.inject.Inject + +@Suppress("LongParameterList") +@ComponentScoped +internal class WalletSettingsModel @Inject constructor( + getWalletUseCase: GetUserWalletUseCase, + paramsContainer: ParamsContainer, + private val router: Router, + private val messageSender: UiMessageSender, + private val deleteWalletUseCase: DeleteWalletUseCase, + private val itemsBuilder: ItemsBuilder, + override val dispatchers: CoroutineDispatcherProvider, + private val analyticsEventHandler: AnalyticsEventHandler, + private val analyticsContextProxy: AnalyticsContextProxy, + private val reduxStateHolder: ReduxStateHolder, +) : Model() { + + val params: WalletSettingsComponent.Params = paramsContainer.require() + val dialogNavigation = SlotNavigation() + + val state: MutableStateFlow = MutableStateFlow( + value = WalletSettingsUM( + popBack = router::pop, + items = persistentListOf(), + ), + ) + + init { + getWalletUseCase.invokeFlow(params.userWalletId) + .distinctUntilChanged() + .onEach { maybeWallet -> + val wallet = maybeWallet.getOrNull() ?: return@onEach + + state.update { value -> + value.copy(items = buildItems(wallet, dialogNavigation)) + } + } + .launchIn(modelScope) + } + + private fun buildItems( + userWallet: UserWallet, + dialogNavigation: SlotNavigation, + ): PersistentList = itemsBuilder.buildItems( + userWalletId = userWallet.walletId, + userWalletName = userWallet.name, + isReferralAvailable = userWallet.cardTypesResolver.isTangemWallet(), + isLinkMoreCardsAvailable = userWallet.scanResponse.card.backupStatus == CardDTO.BackupStatus.NoBackup, + renameWallet = { openRenameWalletDialog(userWallet, dialogNavigation) }, + forgetWallet = { + messageSender.send( + ContentMessage { onDismiss -> + BasicDialog( + message = stringResource(R.string.user_wallet_list_delete_prompt), + onDismissDialog = onDismiss, + confirmButton = DialogButton( + title = stringResource(R.string.common_delete), + warning = true, + onClick = { + forgetWallet() + onDismiss() + }, + ), + dismissButton = DialogButton( + title = stringResource(R.string.common_cancel), + onClick = onDismiss, + ), + ) + }, + ) + }, + onLinkMoreCardsClick = { + onLinkMoreCardsClick(scanResponse = userWallet.scanResponse) + }, + ) + + private fun openRenameWalletDialog(userWallet: UserWallet, dialogNavigation: SlotNavigation) { + val config = DialogConfig.RenameWallet( + userWalletId = userWallet.walletId, + currentName = userWallet.name, + ) + + dialogNavigation.activate(config) + } + + private fun forgetWallet() = modelScope.launch { + val hasUserWallets = deleteWalletUseCase(params.userWalletId).getOrElse { + Timber.e("Unable to delete wallet: $it") + + messageSender.send( + message = SnackbarMessage(resourceReference(R.string.common_unknown_error)), + ) + + return@launch + } + + if (hasUserWallets) { + router.pop() + } else { + router.replaceAll(AppRoute.Home) + } + } + + private fun onLinkMoreCardsClick(scanResponse: ScanResponse) { + analyticsEventHandler.send(Settings.ButtonCreateBackup()) + + analyticsContextProxy.addContext(scanResponse) + + reduxStateHolder.dispatch( + LegacyAction.StartOnboardingProcess( + scanResponse = scanResponse, + canSkipBackup = false, + ), + ) + + router.push(AppRoute.OnboardingWallet()) + } +} \ No newline at end of file diff --git a/features/wallet-settings/impl/src/main/kotlin/com/tangem/feature/walletsettings/ui/RenameWalletDialog.kt b/features/wallet-settings/impl/src/main/kotlin/com/tangem/feature/walletsettings/ui/RenameWalletDialog.kt new file mode 100644 index 0000000000..5ff04fe2e7 --- /dev/null +++ b/features/wallet-settings/impl/src/main/kotlin/com/tangem/feature/walletsettings/ui/RenameWalletDialog.kt @@ -0,0 +1,50 @@ +package com.tangem.feature.walletsettings.ui + +import android.content.res.Configuration +import androidx.compose.runtime.Composable +import androidx.compose.runtime.getValue +import androidx.compose.runtime.rememberUpdatedState +import androidx.compose.ui.res.stringResource +import androidx.compose.ui.tooling.preview.Preview +import com.tangem.core.ui.components.AdditionalTextInputDialogParams +import com.tangem.core.ui.components.DialogButton +import com.tangem.core.ui.components.TextInputDialog +import com.tangem.core.ui.res.TangemThemePreview +import com.tangem.feature.walletsettings.component.preview.PreviewRenameWalletComponent +import com.tangem.feature.walletsettings.entity.RenameWalletUM +import com.tangem.feature.walletsettings.impl.R + +@Composable +internal fun RenameWalletDialog(model: RenameWalletUM, onDismiss: () -> Unit) { + val value by rememberUpdatedState(newValue = model.walletNameValue) + + TextInputDialog( + title = stringResource(id = R.string.user_wallet_list_rename_popup_title), + fieldValue = value, + confirmButton = DialogButton( + title = stringResource(id = R.string.common_ok), + enabled = model.isConfirmEnabled, + onClick = model.onConfirm, + ), + dismissButton = DialogButton( + title = stringResource(id = R.string.common_cancel), + onClick = onDismiss, + ), + onDismissDialog = onDismiss, + onValueChange = model.updateValue, + textFieldParams = AdditionalTextInputDialogParams( + label = stringResource(id = R.string.user_wallet_list_rename_popup_placeholder), + ), + ) +} + +// region Preview +@Composable +@Preview(showBackground = true, widthDp = 360) +@Preview(showBackground = true, widthDp = 360, uiMode = Configuration.UI_MODE_NIGHT_YES) +private fun Preview_RenameWalletDialog() { + TangemThemePreview { + PreviewRenameWalletComponent().Dialog() + } +} +// endregion Preview \ No newline at end of file diff --git a/features/wallet-settings/impl/src/main/kotlin/com/tangem/feature/walletsettings/ui/WalletSettingsScreen.kt b/features/wallet-settings/impl/src/main/kotlin/com/tangem/feature/walletsettings/ui/WalletSettingsScreen.kt new file mode 100644 index 0000000000..29223948a2 --- /dev/null +++ b/features/wallet-settings/impl/src/main/kotlin/com/tangem/feature/walletsettings/ui/WalletSettingsScreen.kt @@ -0,0 +1,179 @@ +package com.tangem.feature.walletsettings.ui + +import android.content.res.Configuration +import androidx.activity.compose.BackHandler +import androidx.compose.foundation.background +import androidx.compose.foundation.layout.* +import androidx.compose.foundation.lazy.LazyColumn +import androidx.compose.foundation.lazy.items +import androidx.compose.material3.Scaffold +import androidx.compose.material3.Text +import androidx.compose.runtime.Composable +import androidx.compose.ui.Alignment +import androidx.compose.ui.Modifier +import androidx.compose.ui.res.stringResource +import androidx.compose.ui.text.style.TextOverflow +import androidx.compose.ui.tooling.preview.Preview +import com.tangem.core.ui.components.appbar.TangemTopAppBar +import com.tangem.core.ui.components.appbar.models.TopAppBarButtonUM +import com.tangem.core.ui.components.block.BlockCard +import com.tangem.core.ui.components.block.BlockItem +import com.tangem.core.ui.components.snackbar.TangemSnackbarHost +import com.tangem.core.ui.extensions.resolveReference +import com.tangem.core.ui.res.LocalSnackbarHostState +import com.tangem.core.ui.res.TangemTheme +import com.tangem.core.ui.res.TangemThemePreview +import com.tangem.feature.walletsettings.component.preview.PreviewWalletSettingsComponent +import com.tangem.feature.walletsettings.entity.WalletSettingsItemUM +import com.tangem.feature.walletsettings.entity.WalletSettingsUM +import com.tangem.feature.walletsettings.impl.R + +@Composable +internal fun WalletSettingsScreen( + state: WalletSettingsUM, + dialog: @Composable () -> Unit, + modifier: Modifier = Modifier, +) { + val backgroundColor = TangemTheme.colors.background.secondary + + BackHandler(onBack = state.popBack) + + Scaffold( + modifier = modifier, + containerColor = backgroundColor, + snackbarHost = { + TangemSnackbarHost( + modifier = Modifier.padding(all = TangemTheme.dimens.spacing16), + hostState = LocalSnackbarHostState.current, + ) + }, + topBar = { + TangemTopAppBar( + modifier = Modifier.statusBarsPadding(), + startButton = TopAppBarButtonUM.Back(state.popBack), + ) + }, + content = { paddingValues -> + Content( + modifier = Modifier.padding(paddingValues), + state = state, + ) + + dialog() + }, + ) +} + +@Composable +private fun Content(state: WalletSettingsUM, modifier: Modifier = Modifier) { + LazyColumn( + modifier = modifier, + verticalArrangement = Arrangement.spacedBy(TangemTheme.dimens.spacing16), + contentPadding = PaddingValues( + top = TangemTheme.dimens.spacing16, + bottom = TangemTheme.dimens.spacing16, + ), + ) { + item { + Text( + modifier = Modifier.padding(horizontal = TangemTheme.dimens.spacing16), + text = stringResource(id = R.string.wallet_settings_title), + style = TangemTheme.typography.h1, + color = TangemTheme.colors.text.primary1, + ) + } + items( + items = state.items, + key = WalletSettingsItemUM::id, + ) { item -> + val itemModifier = Modifier + .padding(horizontal = TangemTheme.dimens.spacing16) + .fillMaxWidth() + + when (item) { + is WalletSettingsItemUM.WithItems -> ItemsBlock( + modifier = itemModifier, + model = item, + ) + is WalletSettingsItemUM.WithText -> TextBlock( + modifier = itemModifier, + model = item, + ) + } + } + } +} + +@Composable +private fun ItemsBlock(model: WalletSettingsItemUM.WithItems, modifier: Modifier = Modifier) { + Column( + modifier = modifier, + horizontalAlignment = Alignment.Start, + verticalArrangement = Arrangement.spacedBy(TangemTheme.dimens.spacing8), + ) { + Column( + modifier = Modifier + .fillMaxWidth() + .background( + shape = TangemTheme.shapes.roundedCornersXMedium, + color = TangemTheme.colors.background.primary, + ), + horizontalAlignment = Alignment.Start, + verticalArrangement = Arrangement.Top, + ) { + model.blocks.forEach { block -> + BlockItem( + modifier = Modifier.fillMaxWidth(), + model = block, + ) + } + } + + Text( + modifier = Modifier.padding(horizontal = TangemTheme.dimens.spacing12), + text = model.description.resolveReference(), + color = TangemTheme.colors.text.tertiary, + style = TangemTheme.typography.caption2, + ) + } +} + +@Composable +private fun TextBlock(model: WalletSettingsItemUM.WithText, modifier: Modifier = Modifier) { + BlockCard( + modifier = modifier.fillMaxWidth(), + onClick = model.onClick, + ) { + Column( + modifier = Modifier.padding(all = TangemTheme.dimens.spacing12), + horizontalAlignment = Alignment.Start, + verticalArrangement = Arrangement.spacedBy(TangemTheme.dimens.spacing8), + ) { + Text( + text = model.title.resolveReference(), + color = TangemTheme.colors.text.tertiary, + style = TangemTheme.typography.subtitle2, + maxLines = 1, + overflow = TextOverflow.Ellipsis, + ) + + Text( + text = model.text.resolveReference(), + color = TangemTheme.colors.text.primary1, + style = TangemTheme.typography.body1, + overflow = TextOverflow.Ellipsis, + ) + } + } +} + +// region Preview +@Composable +@Preview(showBackground = true, widthDp = 360) +@Preview(showBackground = true, widthDp = 360, uiMode = Configuration.UI_MODE_NIGHT_YES) +private fun Preview_WalletSettingsScreen() { + TangemThemePreview { + PreviewWalletSettingsComponent().Content(modifier = Modifier.fillMaxSize()) + } +} +// endregion Preview \ No newline at end of file diff --git a/features/wallet-settings/impl/src/main/kotlin/com/tangem/feature/walletsettings/utils/ItemsBuilder.kt b/features/wallet-settings/impl/src/main/kotlin/com/tangem/feature/walletsettings/utils/ItemsBuilder.kt new file mode 100644 index 0000000000..941f1c53f2 --- /dev/null +++ b/features/wallet-settings/impl/src/main/kotlin/com/tangem/feature/walletsettings/utils/ItemsBuilder.kt @@ -0,0 +1,89 @@ +package com.tangem.feature.walletsettings.utils + +import com.tangem.common.routing.AppRoute +import com.tangem.core.decompose.di.ComponentScoped +import com.tangem.core.decompose.navigation.Router +import com.tangem.core.ui.components.block.model.BlockUM +import com.tangem.core.ui.extensions.resourceReference +import com.tangem.core.ui.extensions.stringReference +import com.tangem.domain.wallets.models.UserWalletId +import com.tangem.feature.walletsettings.entity.WalletSettingsItemUM +import com.tangem.feature.walletsettings.impl.R +import kotlinx.collections.immutable.PersistentList +import kotlinx.collections.immutable.persistentListOf +import kotlinx.collections.immutable.toImmutableList +import javax.inject.Inject + +@ComponentScoped +internal class ItemsBuilder @Inject constructor( + private val router: Router, +) { + + @Suppress("LongParameterList") + fun buildItems( + userWalletId: UserWalletId, + userWalletName: String, + isLinkMoreCardsAvailable: Boolean, + isReferralAvailable: Boolean, + forgetWallet: () -> Unit, + renameWallet: () -> Unit, + onLinkMoreCardsClick: () -> Unit, + ): PersistentList = persistentListOf( + buildNameItem(userWalletName, renameWallet), + buildCardItem(userWalletId, isLinkMoreCardsAvailable, isReferralAvailable, onLinkMoreCardsClick), + buildForgetItem(forgetWallet), + ) + + private fun buildNameItem(walletName: String, renameWallet: () -> Unit) = WalletSettingsItemUM.WithText( + id = "wallet_name", + title = resourceReference(id = R.string.settings_wallet_name_title), + text = stringReference(walletName), + onClick = renameWallet, + ) + + private fun buildCardItem( + userWalletId: UserWalletId, + isLinkMoreCardsAvailable: Boolean, + isReferralAvailable: Boolean, + onLinkMoreCardsClick: () -> Unit, + ) = WalletSettingsItemUM.WithItems( + id = "card", + description = resourceReference(R.string.settings_card_settings_footer), + blocks = buildList { + if (isLinkMoreCardsAvailable) { + BlockUM( + text = resourceReference(R.string.details_row_title_create_backup), + iconRes = R.drawable.ic_more_cards_24, + onClick = onLinkMoreCardsClick, + ).let(::add) + } + + BlockUM( + text = resourceReference(R.string.card_settings_title), + iconRes = R.drawable.ic_card_settings_24, + onClick = { router.push(AppRoute.CardSettings(userWalletId)) }, + ).let(::add) + + if (isReferralAvailable) { + BlockUM( + text = resourceReference(R.string.details_referral_title), + iconRes = R.drawable.ic_add_friends_24, + onClick = { router.push(AppRoute.ReferralProgram(userWalletId)) }, + ).let(::add) + } + }.toImmutableList(), + ) + + private fun buildForgetItem(forgetWallet: () -> Unit) = WalletSettingsItemUM.WithItems( + id = "forget", + description = resourceReference(R.string.settings_forget_wallet_footer), + blocks = persistentListOf( + BlockUM( + text = resourceReference(R.string.settings_forget_wallet), + iconRes = R.drawable.ic_card_foget_24, + onClick = forgetWallet, + accentType = BlockUM.AccentType.WARNING, + ), + ), + ) +} \ No newline at end of file diff --git a/features/wallet/impl/build.gradle.kts b/features/wallet/impl/build.gradle.kts index ecad0b9c68..9d6ff75448 100644 --- a/features/wallet/impl/build.gradle.kts +++ b/features/wallet/impl/build.gradle.kts @@ -52,9 +52,10 @@ dependencies { implementation(projects.core.utils) implementation(projects.core.analytics) implementation(projects.core.analytics.models) - implementation(projects.common) + implementation(projects.common.routing) implementation(projects.core.deepLinks) implementation(projects.core.deepLinks.global) + implementation(projects.core.decompose) implementation(projects.libs.crypto) @@ -77,6 +78,7 @@ dependencies { implementation(projects.domain.balanceHiding.models) implementation(projects.domain.analytics) implementation(projects.domain.visa) + implementation(projects.domain.staking) //TODO: Create api/impl modules for onboarding [REDACTED_JIRA] implementation(projects.features.onboarding) @@ -88,4 +90,6 @@ dependencies { implementation(projects.features.tester.api) implementation(projects.features.manageTokens.api) implementation(projects.features.details.api) + implementation(projects.features.pushNotifications.api) + implementation(projects.features.markets.api) } \ No newline at end of file diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/di/FeatureTogglesModule.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/di/FeatureTogglesModule.kt deleted file mode 100644 index a358685961..0000000000 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/di/FeatureTogglesModule.kt +++ /dev/null @@ -1,20 +0,0 @@ -package com.tangem.feature.wallet.di - -import com.tangem.core.featuretoggle.manager.FeatureTogglesManager -import com.tangem.feature.wallet.featuretoggle.WalletFeatureToggles -import dagger.Module -import dagger.Provides -import dagger.hilt.InstallIn -import dagger.hilt.components.SingletonComponent -import javax.inject.Singleton - -@Module -@InstallIn(SingletonComponent::class) -internal object FeatureTogglesModule { - - @Provides - @Singleton - fun provideWalletFeatureToggles(featureTogglesManager: FeatureTogglesManager): WalletFeatureToggles { - return WalletFeatureToggles(featureTogglesManager) - } -} \ No newline at end of file diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/di/WalletRouterModule.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/di/WalletRouterModule.kt index 1e64fc4122..4e031b0729 100644 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/di/WalletRouterModule.kt +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/di/WalletRouterModule.kt @@ -1,6 +1,8 @@ package com.tangem.feature.wallet.di -import com.tangem.core.navigation.ReduxNavController +import com.tangem.common.routing.AppRouter +import com.tangem.core.navigation.url.UrlOpener +import com.tangem.domain.redux.ReduxStateHolder import com.tangem.feature.wallet.presentation.router.DefaultWalletRouter import com.tangem.features.wallet.navigation.WalletRouter import dagger.Module @@ -15,7 +17,11 @@ internal object WalletRouterModule { @Provides @ActivityScoped - fun provideWalletRouter(reduxNavController: ReduxNavController): WalletRouter { - return DefaultWalletRouter(reduxNavController = reduxNavController) + fun provideWalletRouter( + appRouter: AppRouter, + urlOpener: UrlOpener, + reduxStateHolder: ReduxStateHolder, + ): WalletRouter { + return DefaultWalletRouter(appRouter, urlOpener, reduxStateHolder) } } \ No newline at end of file diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/featuretoggle/WalletFeatureToggles.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/featuretoggle/WalletFeatureToggles.kt deleted file mode 100644 index e0881eead6..0000000000 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/featuretoggle/WalletFeatureToggles.kt +++ /dev/null @@ -1,11 +0,0 @@ -package com.tangem.feature.wallet.featuretoggle - -import com.tangem.core.featuretoggle.manager.FeatureTogglesManager - -internal class WalletFeatureToggles( - private val featureTogglesManager: FeatureTogglesManager, -) { - - val isTokenListLceFlowEnabled: Boolean - get() = featureTogglesManager.isFeatureEnabled("TOKEN_LIST_LCE_ENABLED") -} \ No newline at end of file diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/WalletFragment.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/WalletFragment.kt index 5a2c923015..fa0bdbd72d 100644 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/WalletFragment.kt +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/WalletFragment.kt @@ -1,14 +1,18 @@ package com.tangem.feature.wallet.presentation +import android.os.Bundle import androidx.compose.runtime.Composable import androidx.compose.ui.Modifier +import com.arkivanov.decompose.defaultComponentContext +import com.tangem.core.decompose.context.DefaultAppComponentContext +import com.tangem.core.decompose.di.DecomposeComponent import com.tangem.core.ui.UiDependencies -import com.tangem.core.ui.components.SystemBarsEffect -import com.tangem.core.ui.res.TangemTheme import com.tangem.core.ui.screen.ComposeFragment import com.tangem.feature.wallet.presentation.router.InnerWalletRouter -import com.tangem.features.managetokens.navigation.ManageTokensUi +import com.tangem.features.markets.MarketsFeatureToggles +import com.tangem.features.markets.component.MarketsListComponent import com.tangem.features.wallet.navigation.WalletRouter +import com.tangem.utils.coroutines.CoroutineDispatcherProvider import dagger.hilt.android.AndroidEntryPoint import javax.inject.Inject @@ -23,28 +27,49 @@ internal class WalletFragment : ComposeFragment() { @Inject override lateinit var uiDependencies: UiDependencies - @Inject - internal lateinit var manageTokensUi: ManageTokensUi - /** Feature router */ @Inject internal lateinit var walletRouter: WalletRouter + @Inject + internal lateinit var marketsListComponentFactory: MarketsListComponent.Factory + + @Inject + internal lateinit var coroutineDispatcherProvider: CoroutineDispatcherProvider + + @Inject + internal lateinit var componentBuilder: DecomposeComponent.Builder + + @Inject + internal lateinit var marketsFeatureToggles: MarketsFeatureToggles + + private var marketsListComponent: MarketsListComponent? = null + private val _walletRouter: InnerWalletRouter get() = requireNotNull(walletRouter as? InnerWalletRouter) { "_walletRouter should be instance of InnerWalletRouter" } + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + + if (marketsFeatureToggles.isFeatureEnabled) { + val appContext = DefaultAppComponentContext( + componentContext = defaultComponentContext(requireActivity().onBackPressedDispatcher), + messageHandler = uiDependencies.eventMessageHandler, + dispatchers = coroutineDispatcherProvider, + hiltComponentBuilder = componentBuilder, + ) + + marketsListComponent = marketsListComponentFactory.create(appContext) + } + } + @Composable override fun ScreenContent(modifier: Modifier) { - val systemBarsColor = TangemTheme.colors.background.secondary - SystemBarsEffect { - setSystemBarsColor(systemBarsColor) - } - _walletRouter.Initialize( onFinish = requireActivity()::finish, - manageTokensUi = manageTokensUi, + marketsListComponent = marketsListComponent, ) } diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/common/WalletPreviewData.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/common/WalletPreviewData.kt index 92abf8f92f..e1f6a29f77 100644 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/common/WalletPreviewData.kt +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/common/WalletPreviewData.kt @@ -1,7 +1,7 @@ package com.tangem.feature.wallet.presentation.common import com.tangem.core.ui.components.bottomsheets.TangemBottomSheetConfig -import com.tangem.core.ui.components.currency.tokenicon.TokenIconState +import com.tangem.core.ui.components.currency.icon.CurrencyIconState import com.tangem.core.ui.components.marketprice.PriceChangeType import com.tangem.core.ui.event.consumedEvent import com.tangem.core.ui.extensions.TextReference @@ -67,7 +67,7 @@ internal object WalletPreviewData { } val coinIconState - get() = TokenIconState.CoinIcon( + get() = CurrencyIconState.CoinIcon( url = null, fallbackResId = R.drawable.img_polygon_22, isGrayscale = false, @@ -75,9 +75,9 @@ internal object WalletPreviewData { ) private val tokenIconState - get() = TokenIconState.TokenIcon( + get() = CurrencyIconState.TokenIcon( url = null, - networkBadgeIconResId = R.drawable.img_polygon_22, + topBadgeIconResId = R.drawable.img_polygon_22, fallbackTint = TangemColorPalette.Black, fallbackBackground = TangemColorPalette.Meadow, isGrayscale = false, @@ -85,10 +85,10 @@ internal object WalletPreviewData { ) private val customTokenIconState - get() = TokenIconState.CustomTokenIcon( + get() = CurrencyIconState.CustomTokenIcon( tint = TangemColorPalette.Black, background = TangemColorPalette.Meadow, - networkBadgeIconResId = R.drawable.img_polygon_22, + topBadgeIconResId = R.drawable.img_polygon_22, isGrayscale = false, ) diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/common/component/TokenItem.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/common/component/TokenItem.kt index eb3f107e08..01c4e11d48 100644 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/common/component/TokenItem.kt +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/common/component/TokenItem.kt @@ -16,7 +16,7 @@ import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.tooling.preview.PreviewParameter import androidx.compose.ui.tooling.preview.datasource.CollectionPreviewParameterProvider import androidx.compose.ui.unit.Constraints -import com.tangem.core.ui.components.currency.tokenicon.TokenIcon +import com.tangem.core.ui.components.currency.icon.CurrencyIcon import com.tangem.core.ui.components.marketprice.PriceChangeType import com.tangem.core.ui.extensions.rememberHapticFeedback import com.tangem.core.ui.res.TangemTheme @@ -49,7 +49,7 @@ internal fun TokenItem( .tokenClickable(state = state) .background(color = TangemTheme.colors.background.primary), ) { - TokenIcon( + CurrencyIcon( state = state.iconState, modifier = Modifier .layoutId(layoutId = LayoutId.ICON) diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/common/component/token/TokenCryptoAmount.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/common/component/token/TokenCryptoAmount.kt index 1d8ddf1d9d..b68b55f129 100644 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/common/component/token/TokenCryptoAmount.kt +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/common/component/token/TokenCryptoAmount.kt @@ -8,10 +8,10 @@ import androidx.compose.ui.Modifier import androidx.compose.ui.composed import androidx.compose.ui.res.stringResource import androidx.compose.ui.text.style.TextOverflow -import com.tangem.common.Strings import com.tangem.core.ui.components.RectangleShimmer import com.tangem.core.ui.res.TangemTheme import com.tangem.feature.wallet.impl.R +import com.tangem.utils.StringsSigns import com.tangem.feature.wallet.presentation.common.state.TokenItemState.CryptoAmountState as TokenCryptoAmountState @Composable @@ -23,7 +23,7 @@ internal fun TokenCryptoAmount( when (state) { is TokenCryptoAmountState.Content -> { CryptoAmountText( - amount = if (isBalanceHidden) Strings.STARS else state.text, + amount = if (isBalanceHidden) StringsSigns.STARS else state.text, modifier = modifier, ) } diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/common/component/token/TokenFiatAmount.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/common/component/token/TokenFiatAmount.kt index 8e0535314e..437bd97b09 100644 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/common/component/token/TokenFiatAmount.kt +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/common/component/token/TokenFiatAmount.kt @@ -7,9 +7,9 @@ import androidx.compose.runtime.Composable import androidx.compose.ui.Modifier import androidx.compose.ui.composed import androidx.compose.ui.text.style.TextOverflow -import com.tangem.common.Strings import com.tangem.core.ui.components.RectangleShimmer import com.tangem.core.ui.res.TangemTheme +import com.tangem.utils.StringsSigns import com.tangem.feature.wallet.presentation.common.state.TokenItemState.FiatAmountState as TokenFiatAmountState @Composable @@ -17,7 +17,7 @@ internal fun TokenFiatAmount(state: TokenFiatAmountState?, isBalanceHidden: Bool when (state) { is TokenFiatAmountState.Content -> { FiatAmountText( - text = if (isBalanceHidden) Strings.STARS else state.text, + text = if (isBalanceHidden) StringsSigns.STARS else state.text, modifier, ) } diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/common/component/token/TokenPrice.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/common/component/token/TokenPrice.kt index 4822e0d489..4df035cf66 100644 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/common/component/token/TokenPrice.kt +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/common/component/token/TokenPrice.kt @@ -18,7 +18,7 @@ import com.tangem.core.ui.components.SpacerW6 import com.tangem.core.ui.components.marketprice.PriceChangeType import com.tangem.core.ui.res.TangemTheme import com.tangem.feature.wallet.impl.R -import com.tangem.feature.wallet.presentation.common.state.TokenItemState +import com.tangem.utils.StringsSigns.DASH_SIGN import com.tangem.feature.wallet.presentation.common.state.TokenItemState.CryptoPriceState as TokenPriceChangeState @Composable @@ -33,7 +33,7 @@ internal fun TokenPrice(state: TokenPriceChangeState?, modifier: Modifier = Modi ) } is TokenPriceChangeState.Unknown -> { - PriceText(text = TokenItemState.UNKNOWN_AMOUNT_SIGN, modifier = modifier) + PriceText(text = DASH_SIGN, modifier = modifier) } is TokenPriceChangeState.Loading -> { RectangleShimmer(modifier = modifier.placeholderSize(), radius = TangemTheme.dimens.radius4) @@ -104,7 +104,7 @@ private fun PriceChangeIcon(type: PriceChangeType) { private fun PriceChangeText(type: PriceChangeType?, text: String?, modifier: Modifier = Modifier) { AnimatedContent(targetState = text, modifier = modifier, label = "Update the price change's text") { animatedText -> Text( - text = animatedText ?: TokenItemState.UNKNOWN_AMOUNT_SIGN, + text = animatedText ?: DASH_SIGN, color = when (type) { PriceChangeType.UP -> TangemTheme.colors.text.accent PriceChangeType.DOWN -> TangemTheme.colors.text.warning diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/common/preview/WalletScreenPreviewData.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/common/preview/WalletScreenPreviewData.kt index 509a1b3085..635afd0fc9 100644 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/common/preview/WalletScreenPreviewData.kt +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/common/preview/WalletScreenPreviewData.kt @@ -1,7 +1,6 @@ package com.tangem.feature.wallet.presentation.common.preview -import androidx.compose.runtime.mutableStateOf -import com.tangem.core.ui.components.currency.tokenicon.TokenIconState +import com.tangem.core.ui.components.currency.icon.CurrencyIconState import com.tangem.core.ui.components.marketprice.PriceChangeType import com.tangem.core.ui.event.consumedEvent import com.tangem.core.ui.extensions.TextReference @@ -12,13 +11,12 @@ import com.tangem.feature.wallet.impl.R import com.tangem.feature.wallet.presentation.common.WalletPreviewData.topBarConfig import com.tangem.feature.wallet.presentation.common.state.TokenItemState import com.tangem.feature.wallet.presentation.wallet.state.model.* -import com.tangem.features.managetokens.navigation.ExpandableState import kotlinx.collections.immutable.persistentListOf internal object WalletScreenPreviewData { private val tokenItemState = TokenItemState.Content( id = "1", - iconState = TokenIconState.Locked, + iconState = CurrencyIconState.Locked, titleState = TokenItemState.TitleState.Content(text = "Bitcoin"), fiatAmountState = TokenItemState.FiatAmountState.Content(text = "12 368,14 \$"), cryptoAmountState = TokenItemState.CryptoAmountState.Content(text = "0,35853044 BTC"), @@ -58,7 +56,7 @@ internal object WalletScreenPreviewData { WalletTokensListState.TokensListItemState.Token( state = TokenItemState.Unreachable( id = "3", - iconState = TokenIconState.Locked, + iconState = CurrencyIconState.Locked, titleState = TokenItemState.TitleState.Content(text = "Polygon"), onItemClick = {}, onItemLongClick = {}, @@ -151,7 +149,6 @@ internal object WalletScreenPreviewData { internal val walletScreenState = WalletScreenState( onBackClick = {}, - manageTokensExpandableState = mutableStateOf(ExpandableState.COLLAPSED), topBarConfig = topBarConfig, selectedWalletIndex = 0, wallets = persistentListOf( @@ -161,6 +158,5 @@ internal object WalletScreenPreviewData { onWalletChange = {}, event = consumedEvent(), isHidingMode = false, - manageTokenRedesignToggle = false, ) } \ No newline at end of file diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/common/state/TokenItemState.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/common/state/TokenItemState.kt index 80fdc10cdc..6338c9f8b0 100644 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/common/state/TokenItemState.kt +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/common/state/TokenItemState.kt @@ -1,7 +1,7 @@ package com.tangem.feature.wallet.presentation.common.state import androidx.compose.runtime.Immutable -import com.tangem.core.ui.components.currency.tokenicon.TokenIconState +import com.tangem.core.ui.components.currency.icon.CurrencyIconState import com.tangem.core.ui.components.marketprice.PriceChangeType /** Token item state */ @@ -10,7 +10,7 @@ internal sealed class TokenItemState { abstract val id: String - abstract val iconState: TokenIconState + abstract val iconState: CurrencyIconState abstract val titleState: TitleState @@ -23,7 +23,7 @@ internal sealed class TokenItemState { /** Loading token state */ data class Loading( override val id: String, - override val iconState: TokenIconState, + override val iconState: CurrencyIconState, override val titleState: TitleState.Content, ) : TokenItemState() { override val fiatAmountState: FiatAmountState = FiatAmountState.Loading @@ -33,7 +33,7 @@ internal sealed class TokenItemState { /** Locked token state */ data class Locked(override val id: String) : TokenItemState() { - override val iconState: TokenIconState = TokenIconState.Locked + override val iconState: CurrencyIconState = CurrencyIconState.Locked override val titleState: TitleState = TitleState.Locked override val fiatAmountState: FiatAmountState = FiatAmountState.Locked override val cryptoAmountState: CryptoAmountState = CryptoAmountState.Locked @@ -51,7 +51,7 @@ internal sealed class TokenItemState { */ data class Content( override val id: String, - override val iconState: TokenIconState, + override val iconState: CurrencyIconState, override val titleState: TitleState, override val fiatAmountState: FiatAmountState, override val cryptoAmountState: CryptoAmountState.Content, @@ -69,7 +69,7 @@ internal sealed class TokenItemState { */ data class Draggable( override val id: String, - override val iconState: TokenIconState, + override val iconState: CurrencyIconState, override val titleState: TitleState, override val cryptoAmountState: CryptoAmountState, ) : TokenItemState() { @@ -88,7 +88,7 @@ internal sealed class TokenItemState { */ data class Unreachable( override val id: String, - override val iconState: TokenIconState, + override val iconState: CurrencyIconState, override val titleState: TitleState, val onItemClick: () -> Unit, val onItemLongClick: () -> Unit, @@ -108,7 +108,7 @@ internal sealed class TokenItemState { */ data class NoAddress( override val id: String, - override val iconState: TokenIconState, + override val iconState: CurrencyIconState, override val titleState: TitleState, val onItemLongClick: () -> Unit, ) : TokenItemState() { @@ -161,8 +161,4 @@ internal sealed class TokenItemState { object Locked : CryptoPriceState() } - - companion object { - const val UNKNOWN_AMOUNT_SIGN = "—" - } } \ No newline at end of file diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/organizetokens/OrganizeTokensScreen.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/organizetokens/OrganizeTokensScreen.kt index 4efcf827cb..6c3aea984f 100644 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/organizetokens/OrganizeTokensScreen.kt +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/organizetokens/OrganizeTokensScreen.kt @@ -16,11 +16,10 @@ import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.composed import androidx.compose.ui.draw.shadow -import androidx.compose.ui.graphics.Brush -import androidx.compose.ui.graphics.Color import androidx.compose.ui.graphics.RectangleShape import androidx.compose.ui.graphics.Shape import androidx.compose.ui.hapticfeedback.HapticFeedbackType +import androidx.compose.ui.platform.LocalDensity import androidx.compose.ui.platform.LocalHapticFeedback import androidx.compose.ui.res.stringResource import androidx.compose.ui.tooling.preview.Preview @@ -28,6 +27,7 @@ import androidx.compose.ui.tooling.preview.PreviewParameter import androidx.compose.ui.tooling.preview.datasource.CollectionPreviewParameterProvider import androidx.compose.ui.unit.Dp import androidx.compose.ui.unit.dp +import com.tangem.core.ui.components.BottomFade import com.tangem.core.ui.components.PrimaryButton import com.tangem.core.ui.components.SecondaryButton import com.tangem.core.ui.components.buttons.actions.ActionButtonConfig @@ -36,6 +36,7 @@ import com.tangem.core.ui.event.EventEffect import com.tangem.core.ui.extensions.TextReference import com.tangem.core.ui.res.TangemTheme import com.tangem.core.ui.res.TangemThemePreview +import com.tangem.core.ui.utils.WindowInsetsZero import com.tangem.feature.wallet.impl.R import com.tangem.feature.wallet.presentation.common.WalletPreviewData import com.tangem.feature.wallet.presentation.common.component.DraggableNetworkGroupItem @@ -57,8 +58,12 @@ internal fun OrganizeTokensScreen(state: OrganizeTokensState, modifier: Modifier Scaffold( modifier = modifier, topBar = { - TopBar(state.header, tokensListState) + TopBar( + config = state.header, + tokensListState = tokensListState, + ) }, + contentWindowInsets = WindowInsetsZero, content = { paddingValues -> TokenList( modifier = Modifier @@ -72,7 +77,9 @@ internal fun OrganizeTokensScreen(state: OrganizeTokensState, modifier: Modifier }, floatingActionButtonPosition = FabPosition.Center, floatingActionButton = { - Actions(state.actions) + Box(modifier = Modifier.navigationBarsPadding()) { + Actions(state.actions) + } }, containerColor = TangemTheme.colors.background.secondary, ) @@ -104,9 +111,11 @@ private fun TokenList( onDragEnd = onDragEnd, ) + val bottomBarHeight = with(LocalDensity.current) { WindowInsets.systemBars.getBottom(this).toDp() } + val listContentPadding = PaddingValues( top = TangemTheme.dimens.spacing4, - bottom = TangemTheme.dimens.spacing92, + bottom = TangemTheme.dimens.spacing92 + bottomBarHeight, start = TangemTheme.dimens.spacing16, end = TangemTheme.dimens.spacing16, ) @@ -140,7 +149,7 @@ private fun TokenList( } } - BottomGradient(modifier = Modifier.align(Alignment.BottomCenter)) + BottomFade(modifier = Modifier.align(Alignment.BottomCenter)) } } @@ -191,23 +200,6 @@ private fun LazyItemScope.DraggableItem( } } -@Composable -private fun BottomGradient(modifier: Modifier = Modifier) { - Box( - modifier = modifier - .fillMaxWidth() - .height(TangemTheme.dimens.size116) - .background( - brush = Brush.verticalGradient( - colors = listOf( - Color.Transparent, - TangemTheme.colors.background.secondary, - ), - ), - ), - ) -} - @Composable private fun TopBar( config: OrganizeTokensState.HeaderConfig, @@ -228,6 +220,7 @@ private fun TopBar( modifier = modifier .shadow(elevation) .background(TangemTheme.colors.background.secondary) + .statusBarsPadding() .padding(horizontal = TangemTheme.dimens.spacing16) .fillMaxWidth(), ) { diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/organizetokens/OrganizeTokensViewModel.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/organizetokens/OrganizeTokensViewModel.kt index 2540a508f8..93c0aab777 100644 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/organizetokens/OrganizeTokensViewModel.kt +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/organizetokens/OrganizeTokensViewModel.kt @@ -13,9 +13,7 @@ import com.tangem.domain.tokens.GetTokenListUseCase import com.tangem.domain.tokens.ToggleTokenListGroupingUseCase import com.tangem.domain.tokens.ToggleTokenListSortingUseCase import com.tangem.domain.tokens.model.TokenList -import com.tangem.domain.tokens.model.TotalFiatBalance import com.tangem.domain.wallets.models.UserWalletId -import com.tangem.feature.wallet.featuretoggle.WalletFeatureToggles import com.tangem.feature.wallet.presentation.organizetokens.analytics.PortfolioOrganizeTokensAnalyticsEvent import com.tangem.feature.wallet.presentation.organizetokens.model.OrganizeTokensListState import com.tangem.feature.wallet.presentation.organizetokens.model.OrganizeTokensState @@ -42,7 +40,6 @@ internal class OrganizeTokensViewModel @Inject constructor( private val getSelectedAppCurrencyUseCase: GetSelectedAppCurrencyUseCase, private val getBalanceHidingSettingsUseCase: GetBalanceHidingSettingsUseCase, private val analyticsEventsHandler: AnalyticsEventHandler, - private val walletFeatureToggles: WalletFeatureToggles, private val dispatchers: CoroutineDispatcherProvider, savedStateHandle: SavedStateHandle, ) : ViewModel(), DefaultLifecycleObserver, OrganizeTokensIntents { @@ -173,34 +170,21 @@ internal class OrganizeTokensViewModel @Inject constructor( } private suspend fun getTokenList(): TokenList? { - return if (walletFeatureToggles.isTokenListLceFlowEnabled) { - val tokenList = getTokenListUseCase.launchLce(userWalletId) - .transform { maybeTokenList -> - val tokenList = maybeTokenList.getOrElse( - ifLoading = { return@transform }, - ifError = { error -> - stateHolder.updateStateWithError(error) + val tokenList = getTokenListUseCase.launch(userWalletId) + .transform { maybeTokenList -> + val tokenList = maybeTokenList.getOrElse( + ifLoading = { return@transform }, + ifError = { error -> + stateHolder.updateStateWithError(error) - return@transform - }, - ) + return@transform + }, + ) - emit(tokenList) - } - - tokenList.firstOrNull() - } else { - val maybeTokenList = getTokenListUseCase.launch(userWalletId) - .first { maybeTokenList -> - maybeTokenList.getOrNull()?.totalFiatBalance !is TotalFiatBalance.Loading - } - - maybeTokenList.getOrElse { error -> - stateHolder.updateStateWithError(error) - - null + emit(tokenList) } - } + + return tokenList.firstOrNull() } private fun bootstrapDragAndDropUpdates() { diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/organizetokens/utils/converter/items/CryptoCurrencyToDraggableItemConverter.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/organizetokens/utils/converter/items/CryptoCurrencyToDraggableItemConverter.kt index 2288a0c763..93f8267b5e 100644 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/organizetokens/utils/converter/items/CryptoCurrencyToDraggableItemConverter.kt +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/organizetokens/utils/converter/items/CryptoCurrencyToDraggableItemConverter.kt @@ -1,6 +1,6 @@ package com.tangem.feature.wallet.presentation.organizetokens.utils.converter.items -import com.tangem.core.ui.components.currency.tokenicon.converter.CryptoCurrencyToIconStateConverter +import com.tangem.core.ui.components.currency.icon.converter.CryptoCurrencyToIconStateConverter import com.tangem.core.ui.utils.BigDecimalFormatter import com.tangem.domain.appcurrency.model.AppCurrency import com.tangem.domain.tokens.model.CryptoCurrencyStatus diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/router/DefaultWalletRouter.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/router/DefaultWalletRouter.kt index 6276cdb2e9..c90cea3084 100644 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/router/DefaultWalletRouter.kt +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/router/DefaultWalletRouter.kt @@ -1,12 +1,9 @@ package com.tangem.feature.wallet.presentation.router import android.annotation.SuppressLint -import androidx.compose.foundation.layout.statusBarsPadding -import androidx.compose.runtime.* -import androidx.compose.ui.Modifier +import androidx.compose.runtime.Composable +import androidx.compose.runtime.getValue import androidx.compose.ui.platform.LocalLifecycleOwner -import androidx.compose.ui.unit.dp -import androidx.core.os.bundleOf import androidx.fragment.app.Fragment import androidx.hilt.navigation.compose.hiltViewModel import androidx.lifecycle.compose.collectAsStateWithLifecycle @@ -16,27 +13,26 @@ import androidx.navigation.compose.NavHost import androidx.navigation.compose.composable import androidx.navigation.compose.rememberNavController import androidx.navigation.navArgument -import com.tangem.core.navigation.AppScreen -import com.tangem.core.navigation.NavigationAction -import com.tangem.core.navigation.ReduxNavController -import com.tangem.core.navigation.StateDialog +import com.tangem.common.routing.AppRoute +import com.tangem.common.routing.AppRouter +import com.tangem.core.navigation.url.UrlOpener +import com.tangem.domain.redux.ReduxStateHolder +import com.tangem.domain.redux.StateDialog import com.tangem.domain.tokens.model.CryptoCurrencyStatus import com.tangem.domain.wallets.models.UserWalletId -import com.tangem.feature.onboarding.navigation.OnboardingRouter import com.tangem.feature.wallet.presentation.WalletFragment import com.tangem.feature.wallet.presentation.organizetokens.OrganizeTokensScreen import com.tangem.feature.wallet.presentation.organizetokens.OrganizeTokensViewModel import com.tangem.feature.wallet.presentation.wallet.ui.WalletScreen import com.tangem.feature.wallet.presentation.wallet.viewmodels.WalletViewModel -import com.tangem.features.details.DetailsEntryPoint -import com.tangem.features.managetokens.navigation.ExpandableState -import com.tangem.features.managetokens.navigation.ManageTokensUi -import com.tangem.features.tokendetails.navigation.TokenDetailsRouter +import com.tangem.features.markets.component.MarketsListComponent import kotlin.properties.Delegates /** Default implementation of wallet feature router */ internal class DefaultWalletRouter( - private val reduxNavController: ReduxNavController, + private val router: AppRouter, + private val urlOpener: UrlOpener, + private val reduxStateHolder: ReduxStateHolder, ) : InnerWalletRouter { private var navController: NavHostController by Delegates.notNull() @@ -45,7 +41,7 @@ internal class DefaultWalletRouter( override fun getEntryFragment(): Fragment = WalletFragment.create() @Composable - override fun Initialize(onFinish: () -> Unit, manageTokensUi: ManageTokensUi) { + override fun Initialize(onFinish: () -> Unit, marketsListComponent: MarketsListComponent?) { this.onFinish = onFinish NavHost( @@ -58,20 +54,9 @@ internal class DefaultWalletRouter( subscribeToLifecycle(LocalLifecycleOwner.current) } - var bottomSheetHeaderHeight by remember { mutableStateOf(0.dp) } - WalletScreen( state = viewModel.uiState.collectAsStateWithLifecycle().value, - bottomSheetHeaderHeightProvider = { bottomSheetHeaderHeight }, - bottomSheetContent = { - val state = remember { mutableStateOf(ExpandableState.COLLAPSED) } - // Manage Tokens - manageTokensUi.Content( - onHeaderSizeChange = { bottomSheetHeaderHeight = it }, - state = state, - ) - viewModel.setExpandableState(state) - }, + marketsListComponent = marketsListComponent, ) } @@ -87,7 +72,6 @@ internal class DefaultWalletRouter( val uiState by viewModel.uiState.collectAsStateWithLifecycle() OrganizeTokensScreen( - modifier = Modifier.statusBarsPadding(), state = uiState, ) } @@ -95,7 +79,7 @@ internal class DefaultWalletRouter( } @SuppressLint("RestrictedApi") - override fun popBackStack(screen: AppScreen?) { + override fun popBackStack() { /* * It's hack that avoid issue with closing the wallet screen. * We are using NavGraph only inside feature so first backstack's element is entry of NavGraph and @@ -103,11 +87,7 @@ internal class DefaultWalletRouter( * If backstack contains only NavGraph entry and wallet screen entry then we close the wallet fragment. */ if (navController.currentBackStack.value.size == BACKSTACK_ENTRY_COUNT_TO_CLOSE_WALLET_SCREEN) { - if (screen != null) { - reduxNavController.navigate(action = NavigationAction.PopBackTo(screen)) - } else { - onFinish.invoke() - } + onFinish.invoke() } else { navController.popBackStack() } @@ -118,64 +98,53 @@ internal class DefaultWalletRouter( } override fun openDetailsScreen(selectedWalletId: UserWalletId) { - reduxNavController.navigate( - action = NavigationAction.NavigateTo( - screen = AppScreen.Details, - bundle = bundleOf( - DetailsEntryPoint.USER_WALLET_ID_KEY to selectedWalletId.stringValue, - ), + router.push( + AppRoute.Details( + userWalletId = selectedWalletId, ), ) } override fun openOnboardingScreen() { - reduxNavController.navigate( - action = NavigationAction.NavigateTo( - screen = AppScreen.OnboardingWallet, - bundle = bundleOf(OnboardingRouter.CAN_SKIP_BACKUP to false), - ), + router.push( + AppRoute.OnboardingWallet(canSkipBackup = false), ) } override fun openUrl(url: String) { - reduxNavController.navigate(action = NavigationAction.OpenUrl(url)) + urlOpener.openUrl(url) } override fun openTokenDetails(userWalletId: UserWalletId, currencyStatus: CryptoCurrencyStatus) { val networkAddress = currencyStatus.value.networkAddress if (networkAddress != null && networkAddress.defaultAddress.value.isNotEmpty()) { - reduxNavController.navigate( - action = NavigationAction.NavigateTo( - screen = AppScreen.WalletDetails, - bundle = bundleOf( - TokenDetailsRouter.USER_WALLET_ID_KEY to userWalletId.stringValue, - TokenDetailsRouter.CRYPTO_CURRENCY_KEY to currencyStatus.currency, - ), + router.push( + AppRoute.CurrencyDetails( + userWalletId = userWalletId, + currency = currencyStatus.currency, ), ) } } override fun openStoriesScreen() { - reduxNavController.navigate(action = NavigationAction.NavigateTo(screen = AppScreen.Home)) + router.push(AppRoute.Home) } override fun openSaveUserWalletScreen() { - reduxNavController.navigate(action = NavigationAction.NavigateTo(AppScreen.SaveWallet)) + router.push(AppRoute.SaveWallet) } - override fun isWalletLastScreen(): Boolean = reduxNavController.getBackStack().lastOrNull() == AppScreen.Wallet + override fun isWalletLastScreen(): Boolean { + return router.stack.lastOrNull() is AppRoute.Wallet + } override fun openManageTokensScreen() { - reduxNavController.navigate(action = NavigationAction.NavigateTo(AppScreen.ManageTokens)) + router.push(AppRoute.ManageTokens) } - override fun openScanFailedDialog() { - reduxNavController.navigate( - action = NavigationAction.OpenDialog( - StateDialog.ScanFailsDialog(StateDialog.ScanFailsSource.MAIN), - ), - ) + override fun openScanFailedDialog(onTryAgain: () -> Unit) { + reduxStateHolder.dispatchDialogShow(StateDialog.ScanFailsDialog(StateDialog.ScanFailsSource.MAIN, onTryAgain)) } private companion object { diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/router/InnerWalletRouter.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/router/InnerWalletRouter.kt index bf8aba542f..0666e1191a 100644 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/router/InnerWalletRouter.kt +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/router/InnerWalletRouter.kt @@ -2,10 +2,9 @@ package com.tangem.feature.wallet.presentation.router import androidx.compose.runtime.Composable import androidx.compose.runtime.Stable -import com.tangem.core.navigation.AppScreen import com.tangem.domain.tokens.model.CryptoCurrencyStatus import com.tangem.domain.wallets.models.UserWalletId -import com.tangem.features.managetokens.navigation.ManageTokensUi +import com.tangem.features.markets.component.MarketsListComponent import com.tangem.features.wallet.navigation.WalletRouter /** @@ -24,12 +23,11 @@ internal interface InnerWalletRouter : WalletRouter { * * @param onFinish finish activity callback */ - @Suppress("TopLevelComposableFunctions") @Composable - fun Initialize(onFinish: () -> Unit, manageTokensUi: ManageTokensUi) + fun Initialize(onFinish: () -> Unit, marketsListComponent: MarketsListComponent?) /** Pop back stack */ - fun popBackStack(screen: AppScreen? = null) + fun popBackStack() /** Open organize tokens screen */ fun openOrganizeTokensScreen(userWalletId: UserWalletId) @@ -59,5 +57,5 @@ internal interface InnerWalletRouter : WalletRouter { fun openManageTokensScreen() /** Open scan failed dialog */ - fun openScanFailedDialog() + fun openScanFailedDialog(onTryAgain: () -> Unit) } \ No newline at end of file diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/analytics/utils/WalletWarningsAnalyticsSender.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/analytics/utils/WalletWarningsAnalyticsSender.kt index 398372e208..1a15d9ee54 100644 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/analytics/utils/WalletWarningsAnalyticsSender.kt +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/analytics/utils/WalletWarningsAnalyticsSender.kt @@ -46,10 +46,6 @@ internal class WalletWarningsAnalyticsSender @Inject constructor( is WalletNotification.Informational.MissingAddresses -> MainScreen.MissingAddresses is WalletNotification.RateApp -> MainScreen.HowDoYouLikeTangem is WalletNotification.Critical.BackupError -> MainScreen.BackupError - is WalletNotification.TravalaPromo -> TokenSwapPromoAnalyticsEvent.NoticePromotionBanner( - source = AnalyticsParam.ScreensSources.Main, - programName = TokenSwapPromoAnalyticsEvent.ProgramName.Travala, - ) is WalletNotification.SwapPromo -> TokenSwapPromoAnalyticsEvent.NoticePromotionBanner( source = AnalyticsParam.ScreensSources.Main, programName = TokenSwapPromoAnalyticsEvent.ProgramName.OKX, diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/domain/GetMultiWalletWarningsFactory.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/domain/GetMultiWalletWarningsFactory.kt index ef7f55da6d..031c843c16 100644 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/domain/GetMultiWalletWarningsFactory.kt +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/domain/GetMultiWalletWarningsFactory.kt @@ -1,8 +1,8 @@ package com.tangem.feature.wallet.presentation.wallet.domain -import arrow.core.Either import com.tangem.domain.common.CardTypesResolver import com.tangem.domain.common.util.cardTypesResolver +import com.tangem.domain.core.lce.Lce import com.tangem.domain.demo.IsDemoCardUseCase import com.tangem.domain.promo.PromoBanner import com.tangem.domain.settings.IsReadyToShowRateAppUseCase @@ -23,7 +23,6 @@ import kotlinx.collections.immutable.ImmutableList import kotlinx.collections.immutable.toImmutableList import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.combine -import kotlinx.coroutines.flow.conflate import kotlinx.coroutines.flow.flow import javax.inject.Inject import kotlin.collections.count @@ -40,21 +39,17 @@ internal class GetMultiWalletWarningsFactory @Inject constructor( private val backupValidator: BackupValidator, ) { - private var readyForRateAppNotification = false - fun create(userWallet: UserWallet, clickIntents: WalletClickIntents): Flow> { val cardTypesResolver = userWallet.scanResponse.cardTypesResolver val promoFlow = flow { emit(promoRepository.getOkxPromoBanner()) } return combine( - flow = getTokenListUseCase.launch(userWallet.walletId).conflate(), - flow2 = isReadyToShowRateAppUseCase().conflate(), - flow3 = isNeedToBackupUseCase(userWallet.walletId).conflate(), - flow4 = shouldShowSwapPromoWalletUseCase().conflate(), - flow5 = promoFlow.conflate(), + flow = getTokenListUseCase.launch(userWallet.walletId), + flow2 = isReadyToShowRateAppUseCase(), + flow3 = isNeedToBackupUseCase(userWallet.walletId), + flow4 = shouldShowSwapPromoWalletUseCase(), + flow5 = promoFlow, ) { maybeTokenList, isReadyToShowRating, isNeedToBackup, shouldShowPromo, promoBanner -> - - readyForRateAppNotification = true buildList { addSwapPromoNotification(shouldShowPromo, promoBanner, clickIntents) @@ -64,7 +59,13 @@ internal class GetMultiWalletWarningsFactory @Inject constructor( addWarningNotifications(cardTypesResolver, maybeTokenList, isNeedToBackup, clickIntents) - addRateTheAppNotification(isReadyToShowRating, clickIntents) + val hasCriticalOrWarning = any { notification -> + notification is WalletNotification.Critical || notification is WalletNotification.Warning + } + + if (!hasCriticalOrWarning) { + addRateTheAppNotification(isReadyToShowRating, clickIntents) + } }.toImmutableList() } } @@ -116,7 +117,7 @@ internal class GetMultiWalletWarningsFactory @Inject constructor( private fun MutableList.addInformationalNotifications( cardTypesResolver: CardTypesResolver, - maybeTokenList: Either, + maybeTokenList: Lce, clickIntents: WalletClickIntents, ) { addIf( @@ -128,7 +129,7 @@ internal class GetMultiWalletWarningsFactory @Inject constructor( } private fun MutableList.addMissingAddressesNotification( - maybeTokenList: Either, + maybeTokenList: Lce, clickIntents: WalletClickIntents, ) { val currencies = maybeTokenList.getMissingAddressCurrencies() @@ -144,26 +145,23 @@ internal class GetMultiWalletWarningsFactory @Inject constructor( ) } - private fun Either.getMissingAddressCurrencies(): List { - return fold( - ifLeft = { emptyList() }, - ifRight = { tokenList -> - val currencies = when (tokenList) { - is TokenList.GroupedByNetwork -> tokenList.groups.flatMap(NetworkGroup::currencies) - is TokenList.Ungrouped -> tokenList.currencies - is TokenList.Empty -> emptyList() - } + private fun Lce.getMissingAddressCurrencies(): List { + val tokenList = getOrNull(isPartialContentAccepted = false) ?: return emptyList() - currencies - .filter { it.value is CryptoCurrencyStatus.MissedDerivation } - .map(CryptoCurrencyStatus::currency) - }, - ) + val currencies = when (tokenList) { + is TokenList.GroupedByNetwork -> tokenList.groups.flatMap(NetworkGroup::currencies) + is TokenList.Ungrouped -> tokenList.currencies + is TokenList.Empty -> emptyList() + } + + return currencies + .filter { it.value is CryptoCurrencyStatus.MissedDerivation } + .map(CryptoCurrencyStatus::currency) } private fun MutableList.addWarningNotifications( cardTypesResolver: CardTypesResolver, - tokenList: Either, + tokenList: Lce, isNeedToBackup: Boolean, clickIntents: WalletClickIntents, ) { @@ -185,19 +183,16 @@ internal class GetMultiWalletWarningsFactory @Inject constructor( ) } - private fun Either.hasUnreachableNetworks(): Boolean { - return fold( - ifLeft = { false }, - ifRight = { tokenList -> - val currencies = when (tokenList) { - is TokenList.GroupedByNetwork -> tokenList.groups.flatMap(NetworkGroup::currencies) - is TokenList.Ungrouped -> tokenList.currencies - is TokenList.Empty -> emptyList() - } + private fun Lce.hasUnreachableNetworks(): Boolean { + val tokenList = getOrNull(isPartialContentAccepted = false) ?: return false - currencies.any { it.value is CryptoCurrencyStatus.Unreachable } - }, - ) + val currencies = when (tokenList) { + is TokenList.GroupedByNetwork -> tokenList.groups.flatMap(NetworkGroup::currencies) + is TokenList.Ungrouped -> tokenList.currencies + is TokenList.Empty -> emptyList() + } + + return currencies.any { it.value is CryptoCurrencyStatus.Unreachable } } private fun MutableList.addRateTheAppNotification( @@ -210,17 +205,12 @@ internal class GetMultiWalletWarningsFactory @Inject constructor( onDislikeClick = clickIntents::onDislikeAppClick, onCloseClick = clickIntents::onCloseRateAppWarningClick, ), - condition = isReadyToShowRating && readyForRateAppNotification, + condition = isReadyToShowRating, ) } private fun MutableList.addIf(element: WalletNotification, condition: Boolean) { - if (condition) { - add(element = element) - if (element is WalletNotification.Critical || element is WalletNotification.Warning) { - readyForRateAppNotification = false - } - } + if (condition) add(element = element) } private companion object { diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/loaders/implementors/MultiWalletContentLoader.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/loaders/implementors/MultiWalletContentLoader.kt index 0a3310ce92..7dc59658c4 100644 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/loaders/implementors/MultiWalletContentLoader.kt +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/loaders/implementors/MultiWalletContentLoader.kt @@ -5,7 +5,6 @@ import com.tangem.domain.tokens.ApplyTokenListSortingUseCase import com.tangem.domain.tokens.GetTokenListUseCase import com.tangem.domain.tokens.RunPolkadotAccountHealthCheckUseCase import com.tangem.domain.wallets.models.UserWallet -import com.tangem.feature.wallet.featuretoggle.WalletFeatureToggles import com.tangem.feature.wallet.presentation.wallet.analytics.utils.TokenListAnalyticsSender import com.tangem.feature.wallet.presentation.wallet.analytics.utils.WalletWarningsAnalyticsSender import com.tangem.feature.wallet.presentation.wallet.domain.GetMultiWalletWarningsFactory @@ -28,7 +27,6 @@ internal class MultiWalletContentLoader( private val getSelectedAppCurrencyUseCase: GetSelectedAppCurrencyUseCase, private val applyTokenListSortingUseCase: ApplyTokenListSortingUseCase, private val getMultiWalletWarningsFactory: GetMultiWalletWarningsFactory, - private val walletFeatureToggles: WalletFeatureToggles, private val runPolkadotAccountHealthCheckUseCase: RunPolkadotAccountHealthCheckUseCase, ) : WalletContentLoader(id = userWallet.walletId) { @@ -42,7 +40,6 @@ internal class MultiWalletContentLoader( walletWithFundsChecker = walletWithFundsChecker, getTokenListUseCase = getTokenListUseCase, getSelectedAppCurrencyUseCase = getSelectedAppCurrencyUseCase, - walletFeatureToggles = walletFeatureToggles, applyTokenListSortingUseCase = applyTokenListSortingUseCase, runPolkadotAccountHealthCheckUseCase = runPolkadotAccountHealthCheckUseCase, ), diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/loaders/implementors/MultiWalletContentLoaderFactory.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/loaders/implementors/MultiWalletContentLoaderFactory.kt index 13dbadebb3..1b405c8af6 100644 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/loaders/implementors/MultiWalletContentLoaderFactory.kt +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/loaders/implementors/MultiWalletContentLoaderFactory.kt @@ -5,7 +5,6 @@ import com.tangem.domain.tokens.ApplyTokenListSortingUseCase import com.tangem.domain.tokens.GetTokenListUseCase import com.tangem.domain.tokens.RunPolkadotAccountHealthCheckUseCase import com.tangem.domain.wallets.models.UserWallet -import com.tangem.feature.wallet.featuretoggle.WalletFeatureToggles import com.tangem.feature.wallet.presentation.wallet.analytics.utils.TokenListAnalyticsSender import com.tangem.feature.wallet.presentation.wallet.analytics.utils.WalletWarningsAnalyticsSender import com.tangem.feature.wallet.presentation.wallet.domain.GetMultiWalletWarningsFactory @@ -26,7 +25,6 @@ internal class MultiWalletContentLoaderFactory @Inject constructor( private val getSelectedAppCurrencyUseCase: GetSelectedAppCurrencyUseCase, private val applyTokenListSortingUseCase: ApplyTokenListSortingUseCase, private val walletWarningsAnalyticsSender: WalletWarningsAnalyticsSender, - private val walletFeatureToggles: WalletFeatureToggles, private val runPolkadotAccountHealthCheckUseCase: RunPolkadotAccountHealthCheckUseCase, ) { @@ -42,7 +40,6 @@ internal class MultiWalletContentLoaderFactory @Inject constructor( getMultiWalletWarningsFactory = getMultiWalletWarningsFactory, walletWarningsAnalyticsSender = walletWarningsAnalyticsSender, applyTokenListSortingUseCase = applyTokenListSortingUseCase, - walletFeatureToggles = walletFeatureToggles, runPolkadotAccountHealthCheckUseCase = runPolkadotAccountHealthCheckUseCase, ) } diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/WalletStateController.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/WalletStateController.kt index 895c894ab0..4f4e7c869f 100644 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/WalletStateController.kt +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/WalletStateController.kt @@ -1,6 +1,5 @@ package com.tangem.feature.wallet.presentation.wallet.state -import androidx.compose.runtime.mutableStateOf import com.tangem.core.ui.components.bottomsheets.TangemBottomSheetConfigContent import com.tangem.core.ui.event.consumedEvent import com.tangem.domain.wallets.models.UserWalletId @@ -11,8 +10,6 @@ import com.tangem.feature.wallet.presentation.wallet.state.model.WalletTopBarCon import com.tangem.feature.wallet.presentation.wallet.state.transformers.CloseBottomSheetTransformer import com.tangem.feature.wallet.presentation.wallet.state.transformers.OpenBottomSheetTransformer import com.tangem.feature.wallet.presentation.wallet.state.transformers.WalletScreenStateTransformer -import com.tangem.features.managetokens.featuretoggles.ManageTokensFeatureToggles -import com.tangem.features.managetokens.navigation.ExpandableState import kotlinx.collections.immutable.persistentListOf import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.StateFlow @@ -27,9 +24,7 @@ import javax.inject.Singleton [REDACTED_AUTHOR] */ @Singleton -internal class WalletStateController @Inject constructor( - private val manageTokensFeatureToggles: ManageTokensFeatureToggles, -) { +internal class WalletStateController @Inject constructor() { val uiState: StateFlow get() = mutableUiState @@ -70,12 +65,19 @@ internal class WalletStateController @Inject constructor( return with(value) { wallets[selectedWalletIndex].walletCardState.id } } - fun showBottomSheet(content: TangemBottomSheetConfigContent, userWalletId: UserWalletId = getSelectedWalletId()) { + fun showBottomSheet( + content: TangemBottomSheetConfigContent, + userWalletId: UserWalletId = getSelectedWalletId(), + onDismiss: (() -> Unit)? = null, + ) { update( OpenBottomSheetTransformer( userWalletId = userWalletId, content = content, - onDismissBottomSheet = { update(CloseBottomSheetTransformer(userWalletId)) }, + onDismissBottomSheet = { + onDismiss?.invoke() + update(CloseBottomSheetTransformer(userWalletId)) + }, ), ) } @@ -89,8 +91,6 @@ internal class WalletStateController @Inject constructor( onWalletChange = {}, event = consumedEvent(), isHidingMode = false, - manageTokenRedesignToggle = manageTokensFeatureToggles.isRedesignedScreenEnabled, - manageTokensExpandableState = mutableStateOf(ExpandableState.EXPANDED), ) } } \ No newline at end of file diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/model/PushNotificationsBottomSheetConfig.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/model/PushNotificationsBottomSheetConfig.kt new file mode 100644 index 0000000000..6fd16546b2 --- /dev/null +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/model/PushNotificationsBottomSheetConfig.kt @@ -0,0 +1,10 @@ +package com.tangem.feature.wallet.presentation.wallet.state.model + +import com.tangem.core.ui.components.bottomsheets.TangemBottomSheetConfigContent + +data class PushNotificationsBottomSheetConfig( + val onRequest: () -> Unit, + val onNeverRequest: () -> Unit, + val onAllow: () -> Unit, + val onDeny: () -> Unit, +) : TangemBottomSheetConfigContent \ No newline at end of file diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/model/WalletCardState.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/model/WalletCardState.kt index d4feb6a295..d2ffe9d0d1 100644 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/model/WalletCardState.kt +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/model/WalletCardState.kt @@ -2,9 +2,10 @@ package com.tangem.feature.wallet.presentation.wallet.state.model import androidx.annotation.DrawableRes import androidx.compose.runtime.Immutable -import com.tangem.common.Strings import com.tangem.core.ui.extensions.TextReference import com.tangem.domain.wallets.models.UserWalletId +import com.tangem.utils.StringsSigns +import com.tangem.utils.StringsSigns.DASH_SIGN /** Wallet card state */ @Immutable @@ -123,7 +124,7 @@ internal sealed interface WalletCardState { } companion object { - val HIDDEN_BALANCE_TEXT by lazy { TextReference.Str(value = Strings.STARS) } - val EMPTY_BALANCE_TEXT by lazy { TextReference.Str(value = "—") } + val HIDDEN_BALANCE_TEXT by lazy { TextReference.Str(value = StringsSigns.STARS) } + val EMPTY_BALANCE_TEXT by lazy { TextReference.Str(value = DASH_SIGN) } } } \ No newline at end of file diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/model/WalletManageButton.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/model/WalletManageButton.kt index afbd667405..4c811a13ef 100644 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/model/WalletManageButton.kt +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/model/WalletManageButton.kt @@ -89,6 +89,19 @@ internal sealed class WalletManageButton(val config: ActionButtonConfig) { ), ) + data class Stake( + override val enabled: Boolean, + override val dimContent: Boolean, + override val onClick: () -> Unit, + ) : WalletManageButton( + config = ActionButtonConfig( + text = TextReference.Res(id = R.string.common_stake), + iconResId = R.drawable.ic_staking_24, + onClick = onClick, + dimContent = dimContent, + ), + ) + /** * Sell * diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/model/WalletNotification.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/model/WalletNotification.kt index 258a9f73f9..c878757dbc 100644 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/model/WalletNotification.kt +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/model/WalletNotification.kt @@ -6,7 +6,6 @@ import com.tangem.core.ui.extensions.TextReference import com.tangem.core.ui.extensions.pluralReference import com.tangem.core.ui.extensions.resourceReference import com.tangem.core.ui.extensions.wrappedList -import com.tangem.core.ui.utils.DateTimeFormatters import com.tangem.feature.wallet.impl.R import org.joda.time.DateTime @@ -183,34 +182,6 @@ sealed class WalletNotification(val config: NotificationConfig) { ), ) - data class TravalaPromo( - val startDateTime: DateTime, - val endDateTime: DateTime, - val bannerLink: String?, - val onBookNowButtonClick: (String?) -> Unit, - val onCloseClick: () -> Unit, - ) : WalletNotification( - config = NotificationConfig( - title = resourceReference(id = R.string.main_travala_promotion_title), - subtitle = resourceReference( - id = R.string.main_travala_promotion_description, - wrappedList( - DateTimeFormatters.formatDate(startDateTime, DateTimeFormatters.dateMMMMd), - DateTimeFormatters.formatDate(endDateTime, DateTimeFormatters.dateMMMMd), - ), - ), - // Stub. Travala has its own Composable implementation with correct img - iconResId = R.drawable.ic_star_24, - // Stub. Travala has its own Composable implementation with correct img - backgroundResId = R.drawable.ic_star_24, - buttonsState = NotificationConfig.ButtonsState.SecondaryButtonConfig( - onClick = { onBookNowButtonClick(bannerLink) }, - text = resourceReference(R.string.main_travala_promotion_button), - ), - onCloseClick = onCloseClick, - ), - ) - data class SwapPromo( val startDateTime: DateTime, val endDateTime: DateTime, diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/model/WalletScreenState.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/model/WalletScreenState.kt index 5c9424f9ee..9285575d9e 100644 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/model/WalletScreenState.kt +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/model/WalletScreenState.kt @@ -1,18 +1,14 @@ package com.tangem.feature.wallet.presentation.wallet.state.model -import androidx.compose.runtime.MutableState import com.tangem.core.ui.event.StateEvent -import com.tangem.features.managetokens.navigation.ExpandableState import kotlinx.collections.immutable.ImmutableList internal data class WalletScreenState( val onBackClick: () -> Unit, - val manageTokensExpandableState: MutableState, val topBarConfig: WalletTopBarConfig, val selectedWalletIndex: Int, val wallets: ImmutableList, val onWalletChange: (Int) -> Unit, val event: StateEvent, val isHidingMode: Boolean, - val manageTokenRedesignToggle: Boolean, ) \ No newline at end of file diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/transformers/SetBalancesAndLimitsTransformer.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/transformers/SetBalancesAndLimitsTransformer.kt index ea53efb4c6..d42d27f165 100644 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/transformers/SetBalancesAndLimitsTransformer.kt +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/transformers/SetBalancesAndLimitsTransformer.kt @@ -19,24 +19,25 @@ internal class SetBalancesAndLimitsTransformer( private val userWallet: UserWallet, private val maybeVisaCurrency: Either, private val clickIntents: WalletClickIntents, -) : WalletStateTransformer(userWallet.walletId) { +) : TypedWalletStateTransformer( + userWalletId = userWallet.walletId, + targetStateClass = WalletState.Visa.Content::class, +) { - override fun transform(prevState: WalletState): WalletState { - return prevState.transformWhenInState { state -> - val visaCurrency = maybeVisaCurrency.getOrElse { - return state.copy( - walletCardState = getErrorWalletCardState(state.walletCardState), - depositButtonState = state.depositButtonState.copy(isEnabled = false), - balancesAndLimitBlockState = BalancesAndLimitsBlockState.Error, - ) - } - - state.copy( - walletCardState = getContentWalletCardState(state.walletCardState, visaCurrency), - depositButtonState = state.depositButtonState.copy(isEnabled = true), - balancesAndLimitBlockState = getContentBlockState(visaCurrency), + override fun transformTyped(prevState: WalletState.Visa.Content): WalletState { + val visaCurrency = maybeVisaCurrency.getOrElse { + return prevState.copy( + walletCardState = getErrorWalletCardState(prevState.walletCardState), + depositButtonState = prevState.depositButtonState.copy(isEnabled = false), + balancesAndLimitBlockState = BalancesAndLimitsBlockState.Error, ) } + + return prevState.copy( + walletCardState = getContentWalletCardState(prevState.walletCardState, visaCurrency), + depositButtonState = prevState.depositButtonState.copy(isEnabled = true), + balancesAndLimitBlockState = getContentBlockState(visaCurrency), + ) } private fun getContentBlockState(visaCurrency: VisaCurrency) = BalancesAndLimitsBlockState.Content( diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/transformers/SetRefreshStateTransformer.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/transformers/SetRefreshStateTransformer.kt index 0f6d520acf..58ceb2ac53 100644 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/transformers/SetRefreshStateTransformer.kt +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/transformers/SetRefreshStateTransformer.kt @@ -64,6 +64,7 @@ internal class SetRefreshStateTransformer( is WalletManageButton.Send -> button.copy(enabled = isButtonsEnabled) is WalletManageButton.Sell -> button.copy(enabled = isButtonsEnabled) is WalletManageButton.Receive -> button + is WalletManageButton.Stake -> null is WalletManageButton.Swap -> null } } diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/transformers/TypedWalletStateTransformer.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/transformers/TypedWalletStateTransformer.kt new file mode 100644 index 0000000000..2c72901066 --- /dev/null +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/transformers/TypedWalletStateTransformer.kt @@ -0,0 +1,22 @@ +package com.tangem.feature.wallet.presentation.wallet.state.transformers + +import com.tangem.domain.wallets.models.UserWalletId +import com.tangem.feature.wallet.presentation.wallet.state.model.WalletState +import kotlin.reflect.KClass + +internal abstract class TypedWalletStateTransformer( + userWalletId: UserWalletId, + protected val targetStateClass: KClass, +) : WalletStateTransformer(userWalletId) { + + abstract fun transformTyped(prevState: S): WalletState + + @Suppress("UNCHECKED_CAST") + final override fun transform(prevState: WalletState): WalletState { + return if (prevState::class == targetStateClass) { + transformTyped(prevState as S) + } else { + prevState + } + } +} \ No newline at end of file diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/transformers/WalletStateTransformer.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/transformers/WalletStateTransformer.kt index f02bd16531..bcbd84cf28 100644 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/transformers/WalletStateTransformer.kt +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/transformers/WalletStateTransformer.kt @@ -4,7 +4,6 @@ import com.tangem.domain.wallets.models.UserWalletId import com.tangem.feature.wallet.presentation.wallet.state.model.WalletScreenState import com.tangem.feature.wallet.presentation.wallet.state.model.WalletState import kotlinx.collections.immutable.toImmutableList -import timber.log.Timber internal abstract class WalletStateTransformer( protected val userWalletId: UserWalletId, @@ -12,7 +11,7 @@ internal abstract class WalletStateTransformer( abstract fun transform(prevState: WalletState): WalletState - override fun transform(prevState: WalletScreenState): WalletScreenState { + final override fun transform(prevState: WalletScreenState): WalletScreenState { return prevState.copy( wallets = prevState.wallets .map { state -> @@ -21,13 +20,4 @@ internal abstract class WalletStateTransformer( .toImmutableList(), ) } - - protected inline fun WalletState.transformWhenInState( - transform: (state: S) -> WalletState, - ): WalletState = if (this is S) { - transform(this) - } else { - Timber.w("Impossible to transform ${this::class.simpleName} because current is ${S::class.simpleName}") - this - } } \ No newline at end of file diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/transformers/converter/MultiWalletCurrencyActionsConverter.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/transformers/converter/MultiWalletCurrencyActionsConverter.kt index fa7478a428..d924dabe10 100644 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/transformers/converter/MultiWalletCurrencyActionsConverter.kt +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/transformers/converter/MultiWalletCurrencyActionsConverter.kt @@ -59,6 +59,11 @@ internal class MultiWalletCurrencyActionsConverter( icon = R.drawable.ic_arrow_down_24 action = { clickIntents.onReceiveClick(cryptoCurrencyStatus) } } + is TokenActionsState.ActionState.Stake -> { + title = resourceReference(R.string.common_stake) + icon = R.drawable.ic_staking_24 + action = { clickIntents.onStakeClick(cryptoCurrencyStatus) } + } is TokenActionsState.ActionState.Sell -> { title = resourceReference(R.string.common_sell) icon = R.drawable.ic_currency_24 diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/transformers/converter/TokenItemStateConverter.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/transformers/converter/TokenItemStateConverter.kt index f41d4d4ee7..d7639404cc 100644 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/transformers/converter/TokenItemStateConverter.kt +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/transformers/converter/TokenItemStateConverter.kt @@ -1,15 +1,18 @@ package com.tangem.feature.wallet.presentation.wallet.state.transformers.converter -import com.tangem.core.ui.components.currency.tokenicon.converter.CryptoCurrencyToIconStateConverter +import com.tangem.core.ui.components.currency.icon.converter.CryptoCurrencyToIconStateConverter import com.tangem.core.ui.components.marketprice.PriceChangeType import com.tangem.core.ui.components.marketprice.utils.PriceChangeConverter import com.tangem.core.ui.utils.BigDecimalFormatter import com.tangem.domain.appcurrency.model.AppCurrency +import com.tangem.domain.staking.model.stakekit.YieldBalance import com.tangem.domain.tokens.model.CryptoCurrencyStatus import com.tangem.feature.wallet.presentation.common.state.TokenItemState import com.tangem.feature.wallet.presentation.wallet.viewmodels.intents.WalletClickIntents import com.tangem.utils.Provider +import com.tangem.utils.StringsSigns.DASH_SIGN import com.tangem.utils.converter.Converter +import com.tangem.utils.extensions.orZero import java.math.BigDecimal internal class TokenItemStateConverter( @@ -61,13 +64,16 @@ internal class TokenItemStateConverter( } private fun CryptoCurrencyStatus.getFormattedAmount(): String { - val amount = value.amount ?: return TokenItemState.UNKNOWN_AMOUNT_SIGN + val yieldBalance = (value.yieldBalance as? YieldBalance.Data)?.getTotalStakingBalance().orZero() + val amount = value.amount?.plus(yieldBalance) ?: return DASH_SIGN return BigDecimalFormatter.formatCryptoAmount(amount, currency.symbol, currency.decimals) } private fun CryptoCurrencyStatus.getFormattedFiatAmount(): String { - val fiatAmount = value.fiatAmount ?: return TokenItemState.UNKNOWN_AMOUNT_SIGN + val yieldBalance = (value.yieldBalance as? YieldBalance.Data)?.getTotalStakingBalance().orZero() + val fiatYieldBalance = value.fiatRate?.times(yieldBalance).orZero() + val fiatAmount = value.fiatAmount?.plus(fiatYieldBalance) ?: return DASH_SIGN val appCurrency = appCurrencyProvider() return BigDecimalFormatter.formatFiatAmount(fiatAmount, appCurrency.code, appCurrency.symbol) diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/transformers/converter/TxHistoryItemStateConverter.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/transformers/converter/TxHistoryItemStateConverter.kt index d31a165d9a..45a7931776 100644 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/transformers/converter/TxHistoryItemStateConverter.kt +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/transformers/converter/TxHistoryItemStateConverter.kt @@ -9,6 +9,8 @@ import com.tangem.core.ui.utils.toTimeFormat import com.tangem.domain.txhistory.models.TxHistoryItem import com.tangem.feature.wallet.impl.R import com.tangem.feature.wallet.presentation.wallet.viewmodels.intents.WalletClickIntents +import com.tangem.utils.StringsSigns.MINUS +import com.tangem.utils.StringsSigns.PLUS import com.tangem.utils.converter.Converter import com.tangem.utils.toBriefAddressFormat import com.tangem.utils.toFormattedCurrencyString @@ -96,7 +98,7 @@ internal class TxHistoryItemStateConverter( private fun TxHistoryItem.getAmount(): String { val prefix = when (status) { TxHistoryItem.TransactionStatus.Failed -> "" - else -> if (isOutgoing) "-" else "+" + else -> if (isOutgoing) MINUS else PLUS } return prefix + amount.toFormattedCurrencyString(currency = symbol, decimals = decimals) } diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/transformers/converter/VisaTxHistoryItemStateConverter.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/transformers/converter/VisaTxHistoryItemStateConverter.kt index 5c1b0a20c5..60ac94068a 100644 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/transformers/converter/VisaTxHistoryItemStateConverter.kt +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/transformers/converter/VisaTxHistoryItemStateConverter.kt @@ -9,6 +9,7 @@ import com.tangem.domain.visa.model.VisaCurrency import com.tangem.domain.visa.model.VisaTxHistoryItem import com.tangem.feature.wallet.impl.R import com.tangem.feature.wallet.presentation.wallet.viewmodels.intents.VisaWalletIntents +import com.tangem.utils.StringsSigns import com.tangem.utils.converter.Converter import org.joda.time.DateTimeZone @@ -20,7 +21,7 @@ internal class VisaTxHistoryItemStateConverter( override fun convert(value: VisaTxHistoryItem): TransactionState { val localDate = value.date.withZone(DateTimeZone.getDefault()) val time = DateTimeFormatters.formatDate(localDate, DateTimeFormatters.timeFormatter) - val subtitle = "$time • ${value.status.capitalize()}" + val subtitle = "$time ${StringsSigns.DOT} ${value.status.capitalize()}" return TransactionState.Content( txHash = value.id, diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/subscribers/MultiWalletTokenListSubscriber.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/subscribers/MultiWalletTokenListSubscriber.kt index 6b19dfd81d..12d5115bcf 100644 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/subscribers/MultiWalletTokenListSubscriber.kt +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/subscribers/MultiWalletTokenListSubscriber.kt @@ -3,7 +3,6 @@ package com.tangem.feature.wallet.presentation.wallet.subscribers import com.tangem.domain.appcurrency.GetSelectedAppCurrencyUseCase import com.tangem.domain.core.lce.Lce import com.tangem.domain.core.lce.LceFlow -import com.tangem.domain.core.utils.toLce import com.tangem.domain.tokens.ApplyTokenListSortingUseCase import com.tangem.domain.tokens.GetTokenListUseCase import com.tangem.domain.tokens.RunPolkadotAccountHealthCheckUseCase @@ -12,19 +11,16 @@ import com.tangem.domain.tokens.model.CryptoCurrency import com.tangem.domain.tokens.model.TokenList import com.tangem.domain.tokens.model.TotalFiatBalance import com.tangem.domain.wallets.models.UserWallet -import com.tangem.feature.wallet.featuretoggle.WalletFeatureToggles import com.tangem.feature.wallet.presentation.wallet.analytics.utils.TokenListAnalyticsSender import com.tangem.feature.wallet.presentation.wallet.domain.WalletWithFundsChecker import com.tangem.feature.wallet.presentation.wallet.state.WalletStateController import com.tangem.feature.wallet.presentation.wallet.viewmodels.intents.WalletClickIntents -import kotlinx.coroutines.flow.map @Suppress("LongParameterList") internal class MultiWalletTokenListSubscriber( private val userWallet: UserWallet, private val getTokenListUseCase: GetTokenListUseCase, private val applyTokenListSortingUseCase: ApplyTokenListSortingUseCase, - private val walletFeatureToggles: WalletFeatureToggles, stateHolder: WalletStateController, clickIntents: WalletClickIntents, tokenListAnalyticsSender: TokenListAnalyticsSender, @@ -42,11 +38,7 @@ internal class MultiWalletTokenListSubscriber( ) { override fun tokenListFlow(): LceFlow { - return if (walletFeatureToggles.isTokenListLceFlowEnabled) { - getTokenListUseCase.launchLce(userWallet.walletId) - } else { - getTokenListUseCase.launch(userWallet.walletId).map { it.toLce() } - } + return getTokenListUseCase.launch(userWallet.walletId) } override suspend fun onTokenListReceived(maybeTokenList: Lce) { diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/ui/WalletScreen.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/ui/WalletScreen.kt index c930c63241..806518dbe8 100644 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/ui/WalletScreen.kt +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/ui/WalletScreen.kt @@ -20,6 +20,7 @@ import androidx.compose.runtime.* import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.Color +import androidx.compose.ui.graphics.luminance import androidx.compose.ui.input.pointer.pointerInput import androidx.compose.ui.platform.LocalDensity import androidx.compose.ui.platform.LocalSoftwareKeyboardController @@ -33,11 +34,12 @@ import androidx.compose.ui.unit.Dp import androidx.compose.ui.unit.dp import androidx.paging.compose.collectAsLazyPagingItems import com.google.accompanist.systemuicontroller.rememberSystemUiController +import com.tangem.core.ui.components.BottomFade import com.tangem.core.ui.components.Keyboard import com.tangem.core.ui.components.PrimaryButton -import com.tangem.core.ui.components.SystemBarsEffect import com.tangem.core.ui.components.atoms.Hand import com.tangem.core.ui.components.atoms.handComposableComponentHeight +import com.tangem.core.ui.components.bottomsheets.TangemBottomSheetConfig import com.tangem.core.ui.components.bottomsheets.chooseaddress.ChooseAddressBottomSheet import com.tangem.core.ui.components.bottomsheets.chooseaddress.ChooseAddressBottomSheetConfig import com.tangem.core.ui.components.bottomsheets.tokenreceive.TokenReceiveBottomSheet @@ -50,10 +52,12 @@ import com.tangem.core.ui.event.StateEvent import com.tangem.core.ui.res.TangemTheme import com.tangem.core.ui.res.TangemThemePreview import com.tangem.core.ui.test.TestTags +import com.tangem.core.ui.utils.WindowInsetsZero import com.tangem.feature.wallet.impl.R import com.tangem.feature.wallet.presentation.common.preview.WalletScreenPreviewData.walletScreenState import com.tangem.feature.wallet.presentation.wallet.state.model.* import com.tangem.feature.wallet.presentation.wallet.state.model.holder.TxHistoryStateHolder +import com.tangem.feature.wallet.presentation.wallet.ui.components.PushNotificationsBottomSheet import com.tangem.feature.wallet.presentation.wallet.ui.components.TokenActionsBottomSheet import com.tangem.feature.wallet.presentation.wallet.ui.components.WalletsList import com.tangem.feature.wallet.presentation.wallet.ui.components.common.* @@ -65,16 +69,13 @@ import com.tangem.feature.wallet.presentation.wallet.ui.components.visa.VisaTxDe import com.tangem.feature.wallet.presentation.wallet.ui.components.visa.balancesAndLimitsBlock import com.tangem.feature.wallet.presentation.wallet.ui.components.visa.depositButton import com.tangem.feature.wallet.presentation.wallet.ui.utils.changeWalletAnimator -import com.tangem.features.managetokens.navigation.ExpandableState +import com.tangem.features.markets.component.BottomSheetState +import com.tangem.features.markets.component.MarketsListComponent import kotlinx.collections.immutable.toImmutableList import kotlinx.coroutines.launch @Composable -internal fun WalletScreen( - state: WalletScreenState, - bottomSheetHeaderHeightProvider: () -> Dp, - bottomSheetContent: @Composable () -> Unit, -) { +internal fun WalletScreen(state: WalletScreenState, marketsListComponent: MarketsListComponent?) { BackHandler(onBack = state.onBackClick) // It means that screen is still initializing @@ -97,8 +98,7 @@ internal fun WalletScreen( snackbarHostState = snackbarHostState, isAutoScroll = isAutoScroll, onAutoScrollReset = { isAutoScroll.value = false }, - bottomSheetHeaderHeightProvider = bottomSheetHeaderHeightProvider, - bottomSheetContent = bottomSheetContent, + marketsListComponent = marketsListComponent, alertConfig = alertConfig, ) @@ -112,17 +112,16 @@ internal fun WalletScreen( ) } -@Suppress("LongMethod", "LongParameterList") +@Suppress("LongMethod", "LongParameterList", "CyclomaticComplexMethod") @Composable private fun WalletContent( state: WalletScreenState, walletsListState: LazyListState, snackbarHostState: SnackbarHostState, isAutoScroll: State, - bottomSheetHeaderHeightProvider: () -> Dp, - onAutoScrollReset: () -> Unit, - bottomSheetContent: @Composable () -> Unit, + marketsListComponent: MarketsListComponent?, alertConfig: WalletAlertState?, + onAutoScrollReset: () -> Unit, ) { var selectedWalletIndex by remember(state.selectedWalletIndex) { mutableIntStateOf(state.selectedWalletIndex) } val selectedWallet = state.wallets.getOrElse(selectedWalletIndex) { state.wallets[state.selectedWalletIndex] } @@ -144,17 +143,20 @@ private fun WalletContent( .padding(top = betweenItemsPadding) .padding(horizontal = horizontalPadding) + val bottomBarHeight = with(LocalDensity.current) { WindowInsets.systemBars.getBottom(this).toDp() } + LazyColumn( modifier = Modifier .fillMaxSize() .testTag(TestTags.WALLET_SCREEN), contentPadding = PaddingValues( - bottom = TangemTheme.dimens.spacing92, + bottom = TangemTheme.dimens.spacing92 + bottomBarHeight, ), horizontalAlignment = Alignment.CenterHorizontally, ) { item( - key = state.wallets.map { it.walletCardState.id }, + // !!! Type of the key should be saveable via Bundle on Android !!! + key = state.wallets.map { it.walletCardState.id.stringValue }, contentType = state.wallets.map { it.walletCardState.id }, ) { WalletsList( @@ -202,17 +204,7 @@ private fun WalletContent( organizeTokens(state = selectedWallet, itemModifier = itemModifier) } - val bottomSheetConfig = selectedWallet.bottomSheetConfig - if (bottomSheetConfig != null) { - when (bottomSheetConfig.content) { - is WalletBottomSheetConfig -> WalletBottomSheet(config = bottomSheetConfig) - is TokenReceiveBottomSheetConfig -> TokenReceiveBottomSheet(config = bottomSheetConfig) - is ActionsBottomSheetConfig -> TokenActionsBottomSheet(config = bottomSheetConfig) - is ChooseAddressBottomSheetConfig -> ChooseAddressBottomSheet(config = bottomSheetConfig) - is BalancesAndLimitsBottomSheetConfig -> BalancesAndLimitsBottomSheet(config = bottomSheetConfig) - is VisaTxDetailsBottomSheetConfig -> VisaTxDetailsBottomSheet(config = bottomSheetConfig) - } - } + ShowBottomSheet(bottomSheetConfig = selectedWallet.bottomSheetConfig) WalletsListEffects( lazyListState = walletsListState, @@ -224,14 +216,28 @@ private fun WalletContent( ) } - if (state.manageTokenRedesignToggle) { - BaseScaffoldManageTokenRedesign( + if (marketsListComponent != null) { + val bottomSheetState = remember { + mutableStateOf(BottomSheetState.COLLAPSED) + } + var headerSize by remember { + mutableStateOf(0.dp) + } + + BaseScaffoldWithMarkets( state = state, selectedWallet = selectedWallet, snackbarHostState = snackbarHostState, - bottomSheetHeaderHeightProvider = bottomSheetHeaderHeightProvider, - bottomSheetContent = bottomSheetContent, + bottomSheetHeaderHeightProvider = { headerSize }, alertConfig = alertConfig, + onBottomSheetStateChange = { bottomSheetState.value = it }, + bottomSheetContent = { + marketsListComponent.BottomSheetContent( + bottomSheetState = bottomSheetState, + onHeaderSizeChange = { headerSize = it }, + modifier = Modifier, + ) + }, ) { scaffoldContent() } @@ -246,16 +252,78 @@ private fun WalletContent( } } +@OptIn(ExperimentalMaterialApi::class) +@Composable +private fun BaseScaffold( + state: WalletScreenState, + selectedWallet: WalletState, + snackbarHostState: SnackbarHostState, + content: @Composable () -> Unit, +) { + Scaffold( + topBar = { WalletTopBar(config = state.topBarConfig) }, + contentWindowInsets = WindowInsetsZero, + snackbarHost = { + WalletSnackbarHost( + snackbarHostState = snackbarHostState, + event = state.event, + modifier = Modifier.padding(bottom = TangemTheme.dimens.spacing16), + ) + }, + floatingActionButton = { + val manageTokensButtonConfig by remember(state.selectedWalletIndex) { + mutableStateOf( + (state.wallets[state.selectedWalletIndex] as? WalletState.MultiCurrency)?.manageTokensButtonConfig, + ) + } + + manageTokensButtonConfig?.let { + ManageTokensButton( + modifier = Modifier.navigationBarsPadding(), + onClick = it.onClick, + ) + } + }, + floatingActionButtonPosition = FabPosition.Center, + containerColor = TangemTheme.colors.background.secondary, + content = { + val pullRefreshState = rememberPullRefreshState( + refreshing = selectedWallet.pullToRefreshConfig.isRefreshing, + onRefresh = { + selectedWallet.pullToRefreshConfig.onRefresh(WalletPullToRefreshConfig.ShowRefreshState(true)) + }, + ) + + Box( + modifier = Modifier + .pullRefresh(pullRefreshState) + .padding(it), + ) { + content() + + WalletPullToRefreshIndicator( + isRefreshing = selectedWallet.pullToRefreshConfig.isRefreshing, + state = pullRefreshState, + modifier = Modifier.align(Alignment.TopCenter), + ) + + BottomFade(Modifier.align(Alignment.BottomCenter)) + } + }, + ) +} + @Suppress("LongParameterList", "LongMethod") @OptIn(ExperimentalMaterialApi::class, ExperimentalMaterial3Api::class) @Composable -private fun BaseScaffoldManageTokenRedesign( +private fun BaseScaffoldWithMarkets( state: WalletScreenState, selectedWallet: WalletState, snackbarHostState: SnackbarHostState, bottomSheetHeaderHeightProvider: () -> Dp, bottomSheetContent: @Composable () -> Unit, alertConfig: WalletAlertState?, + onBottomSheetStateChange: (BottomSheetState) -> Unit, content: @Composable () -> Unit, ) { // show the bottom sheet if there is at least one multicurrency wallet @@ -278,10 +346,10 @@ private fun BaseScaffoldManageTokenRedesign( BottomSheetStateEffects( bottomSheetState = bottomSheetState, - state = state, showManageTokensBottomSheet = showManageTokensBottomSheet, alertConfig = alertConfig, keyboardShown = keyboardShown, + onBottomSheetStateChange = onBottomSheetStateChange, ) val scaffoldState = rememberBottomSheetScaffoldState( @@ -300,7 +368,9 @@ private fun BaseScaffoldManageTokenRedesign( WalletSnackbarHost( snackbarHostState = it, event = state.event, - modifier = Modifier.padding(bottom = TangemTheme.dimens.spacing16), + modifier = Modifier + .padding(bottom = TangemTheme.dimens.spacing4) + .navigationBarsPadding(), ) }, containerColor = TangemTheme.colors.background.secondary, @@ -310,6 +380,8 @@ private fun BaseScaffoldManageTokenRedesign( sheetDragHandle = { Hand(modifier = Modifier.background(color = TangemTheme.colors.background.primary)) }, + sheetTonalElevation = 8.dp, + sheetShadowElevation = 8.dp, sheetContent = { BoxWithConstraints { Box( @@ -329,7 +401,7 @@ private fun BaseScaffoldManageTokenRedesign( coroutineScope.launch { bottomSheetState.partialExpand() } } }, - content = { paddingValues -> + content = { _ -> val pullRefreshState = rememberPullRefreshState( refreshing = selectedWallet.pullToRefreshConfig.isRefreshing, onRefresh = { @@ -337,9 +409,7 @@ private fun BaseScaffoldManageTokenRedesign( }, ) - Column( - modifier = Modifier.padding(paddingValues), - ) { + Column { WalletTopBar(config = state.topBarConfig) Box( modifier = Modifier.pullRefresh(pullRefreshState), @@ -391,14 +461,14 @@ private fun BottomSheetScrim(color: Color, visible: Boolean, onDismissRequest: ( } @OptIn(ExperimentalMaterial3Api::class) -@Suppress("CyclomaticComplexMethod") +@Suppress("CyclomaticComplexMethod", "MagicNumber", "LongMethod") @Composable private fun BottomSheetStateEffects( bottomSheetState: SheetState, - state: WalletScreenState, showManageTokensBottomSheet: Boolean, alertConfig: WalletAlertState?, keyboardShown: State, + onBottomSheetStateChange: (BottomSheetState) -> Unit, ) { // Bottom sheet during initialization internally expand partially after its content was remeasured, // therefore initialValue = SheetValue.Hidden in rememberStandardBottomSheetState doesn't work as expected @@ -424,19 +494,29 @@ private fun BottomSheetStateEffects( val systemUiController = rememberSystemUiController() val navigationBarColor = TangemTheme.colors.background.primary - val navigationBarColorWithout = TangemTheme.colors.background.secondary - SystemBarsEffect { - if (showManageTokensBottomSheet) { - setNavigationBarColor(navigationBarColor) + LaunchedEffect(key1 = bottomSheetState.targetValue, navigationBarColor) { + when (bottomSheetState.targetValue) { + SheetValue.Hidden, + SheetValue.Expanded, + -> systemUiController.setNavigationBarColor( + color = Color.Transparent, + darkIcons = navigationBarColor.luminance() > 0.5f, + navigationBarContrastEnforced = true, + ) + SheetValue.PartiallyExpanded, + -> systemUiController.setNavigationBarColor(navigationBarColor) } } - DisposableEffect( - showManageTokensBottomSheet, - ) { + + DisposableEffect(showManageTokensBottomSheet) { onDispose { if (showManageTokensBottomSheet) { - systemUiController.setNavigationBarColor(navigationBarColorWithout) + systemUiController.setNavigationBarColor( + color = Color.Transparent, + darkIcons = navigationBarColor.luminance() > 0.5f, + navigationBarContrastEnforced = false, + ) } } } @@ -463,11 +543,13 @@ private fun BottomSheetStateEffects( val isSheetHidden = bottomSheetState.targetValue == SheetValue.PartiallyExpanded LaunchedEffect(isSheetHidden) { - if (isSheetHidden) { - state.manageTokensExpandableState.value = ExpandableState.COLLAPSED - } else { - state.manageTokensExpandableState.value = ExpandableState.EXPANDED - } + onBottomSheetStateChange( + if (isSheetHidden) { + BottomSheetState.COLLAPSED + } else { + BottomSheetState.EXPANDED + }, + ) } } @@ -495,59 +577,6 @@ private fun rememberSheetStateEnhanced( } } -@OptIn(ExperimentalMaterialApi::class) -@Composable -private fun BaseScaffold( - state: WalletScreenState, - selectedWallet: WalletState, - snackbarHostState: SnackbarHostState, - content: @Composable () -> Unit, -) { - Scaffold( - topBar = { WalletTopBar(config = state.topBarConfig) }, - snackbarHost = { - WalletSnackbarHost( - snackbarHostState = snackbarHostState, - event = state.event, - modifier = Modifier.padding(bottom = TangemTheme.dimens.spacing16), - ) - }, - floatingActionButton = { - val manageTokensButtonConfig by remember(state.selectedWalletIndex) { - mutableStateOf( - (state.wallets[state.selectedWalletIndex] as? WalletState.MultiCurrency)?.manageTokensButtonConfig, - ) - } - - manageTokensButtonConfig?.let { ManageTokensButton(onClick = it.onClick) } - }, - floatingActionButtonPosition = FabPosition.Center, - containerColor = TangemTheme.colors.background.secondary, - content = { - val pullRefreshState = rememberPullRefreshState( - refreshing = selectedWallet.pullToRefreshConfig.isRefreshing, - onRefresh = { - selectedWallet.pullToRefreshConfig.onRefresh(WalletPullToRefreshConfig.ShowRefreshState(true)) - }, - ) - - Box( - modifier = Modifier - .pullRefresh(pullRefreshState) - .padding(it), - ) { - content() - - WalletPullToRefreshIndicator( - isRefreshing = selectedWallet.pullToRefreshConfig.isRefreshing, - state = pullRefreshState, - modifier = Modifier.align(Alignment.TopCenter), - ) - } - }, - ) -} - @Composable private fun WalletSnackbarHost( snackbarHostState: SnackbarHostState, @@ -564,11 +593,11 @@ private fun WalletSnackbarHost( } @Composable -private fun ManageTokensButton(onClick: () -> Unit) { +private fun ManageTokensButton(onClick: () -> Unit, modifier: Modifier = Modifier) { PrimaryButton( text = stringResource(id = R.string.main_manage_tokens), onClick = onClick, - modifier = Modifier + modifier = modifier .fillMaxWidth() .padding(horizontal = TangemTheme.dimens.spacing16), ) @@ -588,6 +617,21 @@ internal fun LazyListScope.organizeTokens(state: WalletState, itemModifier: Modi } } +@Composable +private fun ShowBottomSheet(bottomSheetConfig: TangemBottomSheetConfig?) { + if (bottomSheetConfig != null) { + when (bottomSheetConfig.content) { + is WalletBottomSheetConfig -> WalletBottomSheet(config = bottomSheetConfig) + is TokenReceiveBottomSheetConfig -> TokenReceiveBottomSheet(config = bottomSheetConfig) + is ActionsBottomSheetConfig -> TokenActionsBottomSheet(config = bottomSheetConfig) + is ChooseAddressBottomSheetConfig -> ChooseAddressBottomSheet(config = bottomSheetConfig) + is BalancesAndLimitsBottomSheetConfig -> BalancesAndLimitsBottomSheet(config = bottomSheetConfig) + is VisaTxDetailsBottomSheetConfig -> VisaTxDetailsBottomSheet(config = bottomSheetConfig) + is PushNotificationsBottomSheetConfig -> PushNotificationsBottomSheet(config = bottomSheetConfig) + } + } +} + // region Preview @Preview(showBackground = true, widthDp = 360) @Preview(showBackground = true, widthDp = 360, uiMode = Configuration.UI_MODE_NIGHT_YES) @@ -596,8 +640,7 @@ private fun WalletScreen_Preview(@PreviewParameter(WalletScreenPreviewProvider:: TangemThemePreview { WalletScreen( state = data, - bottomSheetHeaderHeightProvider = { 0.dp }, - bottomSheetContent = {}, + marketsListComponent = null, ) } } diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/ui/components/PushNotificationsBottomSheet.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/ui/components/PushNotificationsBottomSheet.kt new file mode 100644 index 0000000000..aeaad6ef3f --- /dev/null +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/ui/components/PushNotificationsBottomSheet.kt @@ -0,0 +1,116 @@ +package com.tangem.feature.wallet.presentation.wallet.ui.components + +import android.content.res.Configuration +import androidx.compose.foundation.background +import androidx.compose.foundation.layout.Arrangement +import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.Row +import androidx.compose.foundation.layout.padding +import androidx.compose.runtime.Composable +import androidx.compose.runtime.mutableStateOf +import androidx.compose.runtime.remember +import androidx.compose.ui.Modifier +import androidx.compose.ui.res.stringResource +import androidx.compose.ui.tooling.preview.Preview +import com.tangem.core.ui.components.PrimaryButton +import com.tangem.core.ui.components.SecondaryButton +import com.tangem.core.ui.components.bottomsheets.TangemBottomSheet +import com.tangem.core.ui.components.bottomsheets.TangemBottomSheetConfig +import com.tangem.core.ui.components.showcase.ShowcaseContent +import com.tangem.core.ui.components.showcase.model.ShowcaseItemModel +import com.tangem.core.ui.extensions.resourceReference +import com.tangem.core.ui.res.TangemTheme +import com.tangem.core.ui.res.TangemThemePreview +import com.tangem.core.ui.utils.requestPushPermission +import com.tangem.feature.wallet.impl.R +import com.tangem.feature.wallet.presentation.wallet.state.model.PushNotificationsBottomSheetConfig +import com.tangem.features.pushnotifications.api.utils.getPushPermissionOrNull +import kotlinx.collections.immutable.persistentListOf + +@Composable +internal fun PushNotificationsBottomSheet(config: TangemBottomSheetConfig) { + TangemBottomSheet(config = config) { + PushNotificationsSheetContent(content = it, onDismiss = config.onDismissRequest) + } +} + +@Composable +private fun PushNotificationsSheetContent(content: PushNotificationsBottomSheetConfig, onDismiss: () -> Unit) { + val isClicked = remember { mutableStateOf(false) } + val requestPushPermission = requestPushPermission( + pushPermission = getPushPermissionOrNull(), + isClicked = isClicked, + onAllow = { + content.onAllow() + onDismiss() + }, + onDeny = { + content.onDeny() + onDismiss() + }, + ) + + Column(modifier = Modifier.background(TangemTheme.colors.background.primary)) { + ShowcaseContent( + headerIconRes = R.drawable.ic_notifications_unread_24, + headerText = resourceReference(R.string.user_push_notification_agreement_header), + showcaseItems = persistentListOf( + ShowcaseItemModel( + iconRes = R.drawable.ic_rocket_launch_24, + text = resourceReference(R.string.user_push_notification_agreement_argument_one), + ), + ShowcaseItemModel( + iconRes = R.drawable.ic_storefront_24, + text = resourceReference(R.string.user_push_notification_agreement_argument_two), + ), + ), + modifier = Modifier.padding(top = TangemTheme.dimens.spacing40), + ) + Row( + horizontalArrangement = Arrangement.spacedBy(TangemTheme.dimens.spacing12), + modifier = Modifier.padding( + start = TangemTheme.dimens.spacing16, + end = TangemTheme.dimens.spacing16, + top = TangemTheme.dimens.spacing40, + bottom = TangemTheme.dimens.spacing16, + ), + ) { + SecondaryButton( + text = stringResource(R.string.common_cancel), + onClick = { + content.onNeverRequest() + onDismiss() + }, + modifier = Modifier.weight(1f), + ) + PrimaryButton( + text = stringResource(R.string.common_allow), + onClick = { + isClicked.value = true + content.onRequest() + requestPushPermission() + }, + modifier = Modifier.weight(1f), + ) + } + } +} + +// region Preview +@Preview(showBackground = true, widthDp = 360) +@Preview(showBackground = true, widthDp = 360, uiMode = Configuration.UI_MODE_NIGHT_YES) +@Composable +private fun PushNotificationsSheetContent_Preview() { + TangemThemePreview { + PushNotificationsSheetContent( + PushNotificationsBottomSheetConfig( + onRequest = {}, + onNeverRequest = {}, + onAllow = {}, + onDeny = {}, + ), + onDismiss = {}, + ) + } +} +// endregion \ No newline at end of file diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/ui/components/common/WalletCard.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/ui/components/common/WalletCard.kt index 3962d07d47..07aaba8fe5 100644 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/ui/components/common/WalletCard.kt +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/ui/components/common/WalletCard.kt @@ -42,7 +42,6 @@ import androidx.compose.ui.unit.sp import androidx.constraintlayout.compose.ConstraintLayout import androidx.constraintlayout.compose.ConstraintLayoutScope import androidx.constraintlayout.compose.Dimension -import com.tangem.common.Strings import com.tangem.core.ui.components.FontSizeRange import com.tangem.core.ui.components.RectangleShimmer import com.tangem.core.ui.components.ResizableText @@ -54,6 +53,7 @@ import com.tangem.core.ui.res.TangemThemePreview import com.tangem.feature.wallet.impl.R import com.tangem.feature.wallet.presentation.common.WalletPreviewData import com.tangem.feature.wallet.presentation.wallet.state.model.WalletCardState +import com.tangem.utils.StringsSigns private const val HALF_OF_ITEM_WIDTH = 0.5 @@ -291,7 +291,7 @@ private fun Balance(state: WalletCardState, isBalanceHidden: Boolean, modifier: when (walletCardState) { is WalletCardState.Content -> { ResizableText( - text = if (isBalanceHidden) Strings.STARS else walletCardState.balance, + text = if (isBalanceHidden) StringsSigns.STARS else walletCardState.balance, fontSizeRange = FontSizeRange(min = 16.sp, max = TangemTheme.typography.h2.fontSize), modifier = Modifier.defaultMinSize(minHeight = TangemTheme.dimens.size32), color = TangemTheme.colors.text.primary1, diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/ui/components/common/WalletNotifications.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/ui/components/common/WalletNotifications.kt index 08a341ebb7..b27ba3f5e5 100644 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/ui/components/common/WalletNotifications.kt +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/ui/components/common/WalletNotifications.kt @@ -6,7 +6,6 @@ import androidx.compose.foundation.lazy.items import androidx.compose.ui.Modifier import com.tangem.core.ui.components.notifications.Notification import com.tangem.core.ui.components.notifications.OkxPromoNotification -import com.tangem.core.ui.components.notifications.TravalaNotificationWithBackground import com.tangem.core.ui.res.TangemTheme import com.tangem.feature.wallet.presentation.wallet.state.model.WalletNotification import kotlinx.collections.immutable.ImmutableList @@ -34,12 +33,6 @@ internal fun LazyListScope.notifications(configs: ImmutableList { - TravalaNotificationWithBackground( - config = it.config, - modifier = modifier.animateItemPlacement(), - ) - } else -> { Notification( config = it.config, diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/viewmodels/WalletViewModel.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/viewmodels/WalletViewModel.kt index 713453127a..06bb5b53a9 100644 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/viewmodels/WalletViewModel.kt +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/viewmodels/WalletViewModel.kt @@ -1,15 +1,12 @@ package com.tangem.feature.wallet.presentation.wallet.viewmodels -import androidx.compose.runtime.MutableState import androidx.lifecycle.LifecycleOwner import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope import arrow.core.getOrElse import com.tangem.core.analytics.api.AnalyticsEventHandler import com.tangem.domain.balancehiding.GetBalanceHidingSettingsUseCase -import com.tangem.domain.settings.CanUseBiometryUseCase -import com.tangem.domain.settings.IsWalletsScrollPreviewEnabled -import com.tangem.domain.settings.ShouldShowSaveWalletScreenUseCase +import com.tangem.domain.settings.* import com.tangem.domain.tokens.RefreshMultiCurrencyWalletQuotesUseCase import com.tangem.domain.wallets.models.UserWalletId import com.tangem.domain.wallets.usecase.GetSelectedWalletUseCase @@ -21,6 +18,7 @@ import com.tangem.feature.wallet.presentation.wallet.analytics.utils.SelectedWal import com.tangem.feature.wallet.presentation.wallet.domain.WalletNameMigrationUseCase import com.tangem.feature.wallet.presentation.wallet.loaders.WalletScreenContentLoader import com.tangem.feature.wallet.presentation.wallet.state.WalletStateController +import com.tangem.feature.wallet.presentation.wallet.state.model.PushNotificationsBottomSheetConfig import com.tangem.feature.wallet.presentation.wallet.state.model.WalletEvent import com.tangem.feature.wallet.presentation.wallet.state.model.WalletEvent.DemonstrateWalletsScrollPreview.Direction import com.tangem.feature.wallet.presentation.wallet.state.model.WalletScreenState @@ -28,7 +26,9 @@ import com.tangem.feature.wallet.presentation.wallet.state.transformers.* import com.tangem.feature.wallet.presentation.wallet.state.utils.WalletEventSender import com.tangem.feature.wallet.presentation.wallet.utils.ScreenLifecycleProvider import com.tangem.feature.wallet.presentation.wallet.viewmodels.intents.WalletClickIntents -import com.tangem.features.managetokens.navigation.ExpandableState +import com.tangem.features.pushnotifications.api.featuretoggles.PushNotificationsFeatureToggles +import com.tangem.features.pushnotifications.api.utils.PUSH_PERMISSION +import com.tangem.features.pushnotifications.api.utils.getPushPermissionOrNull import com.tangem.utils.Provider import com.tangem.utils.coroutines.CoroutineDispatcherProvider import com.tangem.utils.coroutines.JobHolder @@ -42,7 +42,7 @@ import kotlinx.coroutines.withContext import timber.log.Timber import javax.inject.Inject -@Suppress("LongParameterList") +@Suppress("LongParameterList", "LargeClass") @HiltViewModel internal class WalletViewModel @Inject constructor( private val stateHolder: WalletStateController, @@ -56,13 +56,15 @@ internal class WalletViewModel @Inject constructor( private val canUseBiometryUseCase: CanUseBiometryUseCase, private val isWalletsScrollPreviewEnabled: IsWalletsScrollPreviewEnabled, private val getBalanceHidingSettingsUseCase: GetBalanceHidingSettingsUseCase, - analyticsEventsHandler: AnalyticsEventHandler, private val dispatchers: CoroutineDispatcherProvider, private val screenLifecycleProvider: ScreenLifecycleProvider, private val selectedWalletAnalyticsSender: SelectedWalletAnalyticsSender, private val walletDeepLinksHandler: WalletDeepLinksHandler, private val walletNameMigrationUseCase: WalletNameMigrationUseCase, private val refreshMultiCurrencyWalletQuotesUseCase: RefreshMultiCurrencyWalletQuotesUseCase, + private val shouldAskPermissionUseCase: ShouldAskPermissionUseCase, + private val pushNotificationsFeatureToggles: PushNotificationsFeatureToggles, + analyticsEventsHandler: AnalyticsEventHandler, ) : ViewModel() { val uiState: StateFlow = stateHolder.uiState @@ -82,6 +84,7 @@ internal class WalletViewModel @Inject constructor( subscribeOnBalanceHiding() subscribeOnSelectedWalletFlow() subscribeToScreenBackgroundState() + subscribeOnPushNotificationsPermission() } private fun maybeMigrateNames() { @@ -95,12 +98,6 @@ internal class WalletViewModel @Inject constructor( clickIntents.initialize(router, viewModelScope) } - fun setExpandableState(state: MutableState) { - stateHolder.update { - it.copy(manageTokensExpandableState = state) - } - } - fun subscribeToLifecycle(lifecycleOwner: LifecycleOwner) { lifecycleOwner.lifecycle.addObserver(screenLifecycleProvider) } @@ -147,6 +144,29 @@ internal class WalletViewModel @Inject constructor( .launchIn(viewModelScope) } + private fun subscribeOnPushNotificationsPermission() { + viewModelScope.launch { + val isPushToggled = pushNotificationsFeatureToggles.isPushNotificationsEnabled + val shouldRequestPush = shouldAskPermissionUseCase(PUSH_PERMISSION) + val isPushPermissionAvailable = getPushPermissionOrNull() != null + if (!isPushToggled || !shouldRequestPush || !isPushPermissionAvailable) return@launch + + delay(timeMillis = 1_800) + + stateHolder.showBottomSheet( + content = PushNotificationsBottomSheetConfig( + onRequest = clickIntents::onRequestPushPermission, + onNeverRequest = { clickIntents.onNeverAskPushPermission(false) }, + onAllow = clickIntents::onAllowPushPermission, + onDeny = clickIntents::onDenyPushPermission, + ), + onDismiss = { clickIntents.onNeverAskPushPermission(true) }, + ) + } + } + + // It's okay here because we need to be able to observe the selected wallet changes + @Suppress("DEPRECATION") private fun subscribeOnSelectedWalletFlow() { getSelectedWalletUseCase().onRight { it @@ -307,6 +327,8 @@ internal class WalletViewModel @Inject constructor( } private suspend fun deleteWallet(action: WalletsUpdateActionResolver.Action.DeleteWallet) { + walletScreenContentLoader.cancel(action.deletedWalletId) + walletScreenContentLoader.load( userWallet = action.selectedWallet, clickIntents = clickIntents, diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/viewmodels/intents/WalletCardClickIntents.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/viewmodels/intents/WalletCardClickIntents.kt index 5b4bf78f5d..7c128ca00d 100644 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/viewmodels/intents/WalletCardClickIntents.kt +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/viewmodels/intents/WalletCardClickIntents.kt @@ -1,21 +1,16 @@ package com.tangem.feature.wallet.presentation.wallet.viewmodels.intents import arrow.core.getOrElse +import com.tangem.common.routing.AppRoute +import com.tangem.common.routing.AppRouter import com.tangem.core.analytics.api.AnalyticsEventHandler import com.tangem.core.ui.extensions.resourceReference import com.tangem.core.ui.extensions.wrappedList -import com.tangem.domain.wallets.usecase.GetWalletNamesUseCase -import com.tangem.domain.wallets.usecase.RenameWalletUseCase -import com.tangem.feature.wallet.impl.R import com.tangem.domain.card.DeleteSavedAccessCodesUseCase -import com.tangem.core.navigation.AppScreen -import com.tangem.core.navigation.NavigationAction -import com.tangem.core.navigation.ReduxNavController import com.tangem.domain.redux.ReduxStateHolder import com.tangem.domain.wallets.models.UserWalletId -import com.tangem.domain.wallets.usecase.DeleteWalletUseCase -import com.tangem.domain.wallets.usecase.GetSelectedWalletSyncUseCase -import com.tangem.domain.wallets.usecase.GetUserWalletUseCase +import com.tangem.domain.wallets.usecase.* +import com.tangem.feature.wallet.impl.R import com.tangem.feature.wallet.presentation.wallet.analytics.WalletScreenAnalyticsEvent.MainScreen import com.tangem.feature.wallet.presentation.wallet.loaders.WalletScreenContentLoader import com.tangem.feature.wallet.presentation.wallet.state.WalletStateController @@ -52,7 +47,7 @@ internal class WalletCardClickIntentsImplementor @Inject constructor( private val deleteSavedAccessCodesUseCase: DeleteSavedAccessCodesUseCase, private val analyticsEventHandler: AnalyticsEventHandler, private val reduxStateHolder: ReduxStateHolder, - private val reduxNavController: ReduxNavController, + private val appRouter: AppRouter, private val dispatchers: CoroutineDispatcherProvider, ) : BaseWalletClickIntents(), WalletCardClickIntents { @@ -123,7 +118,7 @@ internal class WalletCardClickIntentsImplementor @Inject constructor( reduxStateHolder.onUserWalletSelected(selectedWallet) } else { stateHolder.clear() - reduxNavController.navigate(NavigationAction.PopBackTo(AppScreen.Home)) + appRouter.replaceAll(AppRoute.Home) } } } diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/viewmodels/intents/WalletClickIntents.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/viewmodels/intents/WalletClickIntents.kt index eba25e8d34..ec3f2d992d 100644 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/viewmodels/intents/WalletClickIntents.kt +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/viewmodels/intents/WalletClickIntents.kt @@ -32,6 +32,7 @@ internal class WalletClickIntents @Inject constructor( private val currencyActionsClickIntentsImplementor: WalletCurrencyActionsClickIntentsImplementor, private val contentClickIntentsImplementor: WalletContentClickIntentsImplementor, private val visaWalletIntentsImplementor: VisaWalletIntentsImplementor, + private val pushPermissionClickIntentsImplementor: WalletPushPermissionClickIntentsImplementor, private val stateHolder: WalletStateController, private val walletScreenContentLoader: WalletScreenContentLoader, private val getSelectedWalletSyncUseCase: GetSelectedWalletSyncUseCase, @@ -48,7 +49,8 @@ internal class WalletClickIntents @Inject constructor( WalletWarningsClickIntents by warningsClickIntentsImplementer, WalletCurrencyActionsClickIntents by currencyActionsClickIntentsImplementor, WalletContentClickIntents by contentClickIntentsImplementor, - VisaWalletIntents by visaWalletIntentsImplementor { + VisaWalletIntents by visaWalletIntentsImplementor, + WalletPushPermissionClickIntents by pushPermissionClickIntentsImplementor { override fun initialize(router: InnerWalletRouter, coroutineScope: CoroutineScope) { super.initialize(router, coroutineScope) @@ -58,6 +60,7 @@ internal class WalletClickIntents @Inject constructor( currencyActionsClickIntentsImplementor.initialize(router, coroutineScope) contentClickIntentsImplementor.initialize(router, coroutineScope) visaWalletIntentsImplementor.initialize(router, coroutineScope) + pushPermissionClickIntentsImplementor.initialize(router, coroutineScope) } fun onWalletChange(index: Int) { diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/viewmodels/intents/WalletCurrencyActionsClickIntents.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/viewmodels/intents/WalletCurrencyActionsClickIntents.kt index bc843df1e7..c6b5eb1cff 100644 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/viewmodels/intents/WalletCurrencyActionsClickIntents.kt +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/viewmodels/intents/WalletCurrencyActionsClickIntents.kt @@ -1,5 +1,6 @@ package com.tangem.feature.wallet.presentation.wallet.viewmodels.intents +import arrow.core.getOrElse import com.tangem.blockchain.common.address.AddressType import com.tangem.core.analytics.api.AnalyticsEventHandler import com.tangem.core.ui.clipboard.ClipboardManager @@ -18,6 +19,7 @@ import com.tangem.domain.appcurrency.extenstions.unwrap import com.tangem.domain.common.util.cardTypesResolver import com.tangem.domain.demo.IsDemoCardUseCase import com.tangem.domain.redux.ReduxStateHolder +import com.tangem.domain.staking.GetYieldUseCase import com.tangem.domain.tokens.* import com.tangem.domain.tokens.legacy.TradeCryptoAction import com.tangem.domain.tokens.model.CryptoCurrency @@ -58,6 +60,8 @@ interface WalletCurrencyActionsClickIntents { fun onReceiveClick(cryptoCurrencyStatus: CryptoCurrencyStatus) + fun onStakeClick(cryptoCurrencyStatus: CryptoCurrencyStatus) + fun onCopyAddressLongClick(cryptoCurrencyStatus: CryptoCurrencyStatus): TextReference? fun onCopyAddressClick(cryptoCurrencyStatus: CryptoCurrencyStatus) @@ -89,6 +93,7 @@ internal class WalletCurrencyActionsClickIntentsImplementor @Inject constructor( private val reduxStateHolder: ReduxStateHolder, private val hapticManager: HapticManager, private val clipboardManager: ClipboardManager, + private val getYieldUseCase: GetYieldUseCase, ) : BaseWalletClickIntents(), WalletCurrencyActionsClickIntents { override fun onSendClick( @@ -364,6 +369,27 @@ internal class WalletCurrencyActionsClickIntentsImplementor @Inject constructor( showErrorIfDemoModeOrElse(action = ::openExplorer) } + override fun onStakeClick(cryptoCurrencyStatus: CryptoCurrencyStatus) { + viewModelScope.launch { + val userWalletId = stateHolder.getSelectedWalletId() + val cryptoCurrency = cryptoCurrencyStatus.currency + val yield = getYieldUseCase.invoke( + cryptoCurrencyId = cryptoCurrency.id, + symbol = cryptoCurrency.symbol, + ).getOrElse { + error("Staking is unavailable for ${cryptoCurrency.name}") + } + + reduxStateHolder.dispatch( + TradeCryptoAction.Stake( + userWalletId = userWalletId, + cryptoCurrencyId = cryptoCurrency.id, + yield = yield, + ), + ) + } + } + private fun openExplorer() { val userWalletId = stateHolder.getSelectedWalletId() @@ -466,6 +492,12 @@ internal class WalletCurrencyActionsClickIntentsImplementor @Inject constructor( private fun getUnavailabilityReasonText(unavailabilityReason: ScenarioUnavailabilityReason): TextReference { return when (unavailabilityReason) { + is ScenarioUnavailabilityReason.StakingUnavailable -> { + resourceReference( + id = R.string.token_button_unavailability_reason_staking_unavailable, + formatArgs = wrappedList(unavailabilityReason.cryptoCurrencyName), + ) + } is ScenarioUnavailabilityReason.PendingTransaction -> { when (unavailabilityReason.withdrawalScenario) { ScenarioUnavailabilityReason.WithdrawalScenario.SEND -> resourceReference( diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/viewmodels/intents/WalletPushPermissionClickIntents.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/viewmodels/intents/WalletPushPermissionClickIntents.kt new file mode 100644 index 0000000000..13a301f372 --- /dev/null +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/viewmodels/intents/WalletPushPermissionClickIntents.kt @@ -0,0 +1,59 @@ +package com.tangem.feature.wallet.presentation.wallet.viewmodels.intents + +import com.tangem.core.analytics.api.AnalyticsEventHandler +import com.tangem.core.analytics.models.AnalyticsParam +import com.tangem.domain.settings.NeverRequestPermissionUseCase +import com.tangem.features.pushnotifications.api.analytics.PushNotificationAnalyticEvents +import com.tangem.features.pushnotifications.api.utils.PUSH_PERMISSION +import dagger.hilt.android.scopes.ViewModelScoped +import kotlinx.coroutines.launch +import javax.inject.Inject + +internal interface WalletPushPermissionClickIntents { + + fun onRequestPushPermission() + + fun onNeverAskPushPermission(isUserDismissed: Boolean) + + fun onDenyPushPermission() + + fun onAllowPushPermission() +} + +@ViewModelScoped +internal class WalletPushPermissionClickIntentsImplementor @Inject constructor( + private val neverRequestPermissionUseCase: NeverRequestPermissionUseCase, + private val analyticsEventHandler: AnalyticsEventHandler, +) : BaseWalletClickIntents(), WalletPushPermissionClickIntents { + + private var isUserDismissedDialog: Boolean = true + override fun onRequestPushPermission() { + isUserDismissedDialog = false + analyticsEventHandler.send( + PushNotificationAnalyticEvents.ButtonAllow(AnalyticsParam.ScreensSources.Main), + ) + } + + override fun onNeverAskPushPermission(isUserDismissed: Boolean) { + if (!isUserDismissedDialog) return + isUserDismissedDialog = isUserDismissed + viewModelScope.launch { + PushNotificationAnalyticEvents.ButtonCancel(AnalyticsParam.ScreensSources.Main) + neverRequestPermissionUseCase(PUSH_PERMISSION) + } + } + + override fun onDenyPushPermission() { + analyticsEventHandler.send(PushNotificationAnalyticEvents.PermissionStatus(isAllowed = false)) + viewModelScope.launch { + neverRequestPermissionUseCase(PUSH_PERMISSION) + } + } + + override fun onAllowPushPermission() { + analyticsEventHandler.send(PushNotificationAnalyticEvents.PermissionStatus(isAllowed = true)) + viewModelScope.launch { + neverRequestPermissionUseCase(PUSH_PERMISSION) + } + } +} \ No newline at end of file diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/viewmodels/intents/WalletWarningsClickIntents.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/viewmodels/intents/WalletWarningsClickIntents.kt index d7e79ce743..b8ee6c5ef5 100644 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/viewmodels/intents/WalletWarningsClickIntents.kt +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/viewmodels/intents/WalletWarningsClickIntents.kt @@ -167,7 +167,10 @@ internal class WalletWarningsClickIntentsImplementor @Inject constructor( override fun onScanToUnlockWalletClick() { analyticsEventHandler.send(MainScreen.UnlockWithCardScan) + openScanCardDialog() + } + private fun openScanCardDialog() { viewModelScope.launch(dispatchers.main) { scanCardToUnlockWalletClickHandler(walletId = stateHolder.getSelectedWalletId()) .onLeft { error -> @@ -177,7 +180,7 @@ internal class WalletWarningsClickIntentsImplementor @Inject constructor( event = WalletEvent.ShowAlert(WalletAlertState.WrongCardIsScanned), ) } - ScanCardToUnlockWalletError.ManyScanFails -> router.openScanFailedDialog() + ScanCardToUnlockWalletError.ManyScanFails -> router.openScanFailedDialog(::openScanCardDialog) } } } @@ -203,7 +206,12 @@ internal class WalletWarningsClickIntentsImplementor @Inject constructor( viewModelScope.launch(dispatchers.main) { neverToSuggestRateAppUseCase() - reduxStateHolder.dispatch(LegacyAction.SendEmailRateCanBeBetter) + reduxStateHolder.dispatch( + LegacyAction.SendEmailRateCanBeBetter( + scanResponse = getSelectedUserWallet()?.scanResponse + ?: error("ScanResponse must be not null"), + ), + ) } } @@ -257,7 +265,12 @@ internal class WalletWarningsClickIntentsImplementor @Inject constructor( } override fun onSupportClick() { - reduxStateHolder.dispatch(LegacyAction.SendEmailSupport) + reduxStateHolder.dispatch( + LegacyAction.SendEmailSupport( + scanResponse = getSelectedUserWallet()?.scanResponse + ?: error("ScanResponse must be not null"), + ), + ) } private fun getSelectedUserWallet(): UserWallet? { diff --git a/gradle/dependencies.toml b/gradle/dependencies.toml index 5b292b2371..934dbe9b97 100644 --- a/gradle/dependencies.toml +++ b/gradle/dependencies.toml @@ -4,8 +4,8 @@ [versions] # region Classpath androidGradlePlugin = "8.2.2" -firebaseCrashlytics = "2.9.4" -googleServices = "4.3.10" +firebaseCrashlytics = "3.0.1" +googleServices = "4.4.1" kotlin = "1.9.22" # endregion Classpath @@ -21,6 +21,7 @@ androidxLifecycle = "2.5.1" androidx-paging = "3.1.1" androidx-palette = "1.0.0" androidx-datastore = "1.0.0" +androidxWindowManager = "1.3.0" # endregion AndroidX # region Compose @@ -44,7 +45,7 @@ coil = "2.1.0" compose-shimmer = "1.0.3" coroutine = "1.7.2" desugarJdkLibs = "1.1.5" -firebase = "26.0.0" +firebase = "33.1.0" googleMaterialComponent = "1.6.1" googlePlayReview = "2.0.1" googlePlayReviewKtx = "2.0.1" @@ -87,10 +88,12 @@ markdown = "0.7.2" # endregion Other libraries # region Tangem -tangemBlockchainSdk = "release-app_5.12-715" +tangemBlockchainSdk = "release-app_5.13-718" #tangemBlockchainSdk = "0.0.1" # Keep it! - used for local builds -tangemCardSdk = "release-app_5.12-373" +tangemCardSdk = "release-app_5.13-376" #tangemCardSdk = "0.0.1" # Keep it! - used for local builds ^ +tangemVico = "2.0.0-alpha.21-tangem14" +#tangemVico = "0.0.1" # Keep it! - used for local builds ^ # endregion Tangem # region Tools @@ -130,7 +133,6 @@ room = { id = "androidx.room", version.ref = "room" } gradle-android = { module = "com.android.tools.build:gradle", version.ref = "androidGradlePlugin" } gradle-kotlin = { module = "org.jetbrains.kotlin:kotlin-gradle-plugin", version.ref = "kotlin" } gradle-detekt = { module = "io.gitlab.arturbosch.detekt:detekt-gradle-plugin", version.ref = "detekt" } -gradle-firebase-crashlytics = { module = "com.google.firebase:firebase-crashlytics-gradle", version.ref = "firebaseCrashlytics" } # end region Classpath # region AndroidX @@ -144,6 +146,7 @@ androidx-fragment-ktx = { module = "androidx.fragment:fragment-ktx", version.ref androidx-paging-runtime = { module = "androidx.paging:paging-runtime", version.ref = "androidx-paging" } androidx-swipeRefreshLayout = { module = "androidx.swiperefreshlayout:swiperefreshlayout", version.ref = "swipeRefreshLayout" } androidx-palette = { module = "androidx.palette:palette", version.ref = "androidx-palette" } +androidx-windowManager = { group = "androidx.window", name = "window", version.ref = "androidxWindowManager" } lifecycle-common-java8 = { module = "androidx.lifecycle:lifecycle-common-java8", version.ref = "androidxLifecycle" } lifecycle-runtime-ktx = { module = "androidx.lifecycle:lifecycle-runtime-ktx", version.ref = "androidxLifecycle" } lifecycle-viewModel-ktx = { module = "androidx.lifecycle:lifecycle-viewmodel-ktx", version.ref = "androidxLifecycle" } @@ -167,6 +170,7 @@ compose-navigation-hilt = { module = "androidx.hilt:hilt-navigation-compose", ve compose-accompanist-appCompatTheme = { module = "com.google.accompanist:accompanist-appcompat-theme", version.ref = "compose-accompanist" } compose-accompanist-systemUiController = { module = "com.google.accompanist:accompanist-systemuicontroller", version.ref = "compose-accompanist" } compose-accompanist-webView = { module = "com.google.accompanist:accompanist-webview", version.ref = "compose-accompanist" } +compose-accompanist-permission = { module = "com.google.accompanist:accompanist-permissions", version.ref = "compose-accompanist" } compose-paging = { module = "androidx.paging:paging-compose", version.ref = "compose-paging" } compose-reorderable = { module = "org.burnoutcrew.composereorderable:reorderable", version.ref = "compose-reorderable" } # endregion Compose @@ -175,12 +179,17 @@ compose-reorderable = { module = "org.burnoutcrew.composereorderable:reorderable firebase-bom = { module = "com.google.firebase:firebase-bom", version.ref = "firebase" } firebase-analytics = { module = "com.google.firebase:firebase-analytics-ktx" } firebase-crashlytics = { module = "com.google.firebase:firebase-crashlytics-ktx" } +firebase-messaging = { module = "com.google.firebase:firebase-messaging-ktx" } # endregion Firebase # region Tangem tangem-blockchain = { module = "com.tangem:blockchain", version.ref = "tangemBlockchainSdk" } tangem-card-android = { module = "com.tangem.tangem-sdk-kotlin:android", version.ref = "tangemCardSdk" } tangem-card-core = { module = "com.tangem.tangem-sdk-kotlin:core", version.ref = "tangemCardSdk" } + +tangem-vico-compose = { group = "com.tangem.vico", name = "compose", version.ref = "tangemVico" } +tangem-vico-compose-m3 = { group = "com.tangem.vico", name = "compose-m3", version.ref = "tangemVico" } +tangem-vico-core = { group = "com.tangem.vico", name = "core", version.ref = "tangemVico" } # endregion Tangem # region Detekt @@ -210,6 +219,7 @@ armadillo = { module = "at.favre.lib:armadillo", version.ref = "armadillo" } coil = { module = "io.coil-kt:coil", version.ref = "coil" } kotlin-coroutines = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-core", version.ref = "coroutine" } kotlin-coroutines-rx2 = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-rx2", version.ref = "coroutine" } +kotlin-coroutines-android = { group = "org.jetbrains.kotlinx", name = "kotlinx-coroutines-android", version.ref = "coroutine" } kotlin-immutable-collections = { module = "org.jetbrains.kotlinx:kotlinx-collections-immutable", version.ref = "kotlin-immutable-collections" } desugar = { module = "com.android.tools:desugar_jdk_libs", version.ref = "desugarJdkLibs" } googlePlay-review = { module = "com.google.android.play:review", version.ref = "googlePlayReview" } @@ -244,7 +254,6 @@ reactive-network = { module = "com.github.pwittchen:reactivenetwork-rx2", versio walletConnectCore = { module = "com.walletconnect:android-core", version.ref = "walletConnectCore" } walletConnectWeb3 = { module = "com.walletconnect:web3wallet", version.ref = "walletConnectWeb3" } prettyLogger = { module = "com.orhanobut:logger", version.ref = "prettyLogger" } -sprClient = { module = "com.spr:messengerclient", version.ref = "spr-client" } chucker = { module = "com.github.chuckerteam.chucker:library", version.ref = "chucker" } chuckerStub = { module = "com.github.chuckerteam.chucker:library-no-op", version.ref = "chucker" } mlKit-barcodeScanning = { module = "com.google.mlkit:barcode-scanning", version.ref = "mlKit-barcodeScanning" } diff --git a/libs/blockchain-sdk/src/main/java/com/tangem/blockchainsdk/converters/BlockchainSDKConfigConverter.kt b/libs/blockchain-sdk/src/main/java/com/tangem/blockchainsdk/converters/BlockchainSDKConfigConverter.kt index 5d713313ea..f8e769ebd1 100644 --- a/libs/blockchain-sdk/src/main/java/com/tangem/blockchainsdk/converters/BlockchainSDKConfigConverter.kt +++ b/libs/blockchain-sdk/src/main/java/com/tangem/blockchainsdk/converters/BlockchainSDKConfigConverter.kt @@ -41,6 +41,7 @@ internal object BlockchainSDKConfigConverter : Converter ProviderType.Tron.TronGrid "dwellirBittensor" -> ProviderType.Bittensor.Dwellir "onfinalityBittensor" -> ProviderType.Bittensor.Onfinality + "koinospro" -> ProviderType.Koinos.KoinosPro else -> { Timber.e("Private provider with name $name is not supported") null diff --git a/libs/crypto/src/main/java/com/tangem/lib/crypto/TransactionManager.kt b/libs/crypto/src/main/java/com/tangem/lib/crypto/TransactionManager.kt index a3a9846b43..8bdae098a7 100644 --- a/libs/crypto/src/main/java/com/tangem/lib/crypto/TransactionManager.kt +++ b/libs/crypto/src/main/java/com/tangem/lib/crypto/TransactionManager.kt @@ -1,37 +1,11 @@ package com.tangem.lib.crypto import com.tangem.blockchain.common.Amount -import com.tangem.blockchain.common.TransactionExtras import com.tangem.lib.crypto.models.* -import com.tangem.lib.crypto.models.transactions.SendTxResult -import java.math.BigDecimal import java.math.BigInteger interface TransactionManager { - @Throws(IllegalStateException::class) - suspend fun sendApproveTransaction( - txData: ApproveTxData, - derivationPath: String?, - analyticsData: AnalyticsData, - ): SendTxResult - - /** - * Send transaction - * - * @param txData data to build a tx - * @param derivationPath for select right walletManager - * @param analyticsData data for send analytics event - * @return result of transaction - */ - @Throws(IllegalStateException::class) - suspend fun sendTransaction( - txData: SwapTxData, - isSwap: Boolean, - derivationPath: String?, - analyticsData: AnalyticsData, - ): SendTxResult - /** * Get fee * @@ -62,8 +36,6 @@ interface TransactionManager { @Throws(IllegalStateException::class) suspend fun updateWalletManager(networkId: String, derivationPath: String?) - fun calculateFee(networkId: String, gasPrice: String, estimatedGas: Int): BigDecimal - /** * In app blockchain id, actual in blockchain sdk, not the same as networkId * @@ -74,7 +46,4 @@ interface TransactionManager { @Throws(IllegalStateException::class) fun getExplorerTransactionLink(networkId: String, txAddress: String): String - - // TODO: move to another place to use as in Send feature - fun getMemoExtras(networkId: String, memo: String?): TransactionExtras? } \ No newline at end of file diff --git a/libs/crypto/src/main/java/com/tangem/lib/crypto/models/errors/UserCancelledException.kt b/libs/crypto/src/main/java/com/tangem/lib/crypto/models/errors/UserCancelledException.kt deleted file mode 100644 index bdaf360494..0000000000 --- a/libs/crypto/src/main/java/com/tangem/lib/crypto/models/errors/UserCancelledException.kt +++ /dev/null @@ -1,3 +0,0 @@ -package com.tangem.lib.crypto.models.errors - -class UserCancelledException : Exception() \ No newline at end of file diff --git a/libs/visa/src/main/kotlin/com/tangem/lib/visa/VisaContractInfoProvider.kt b/libs/visa/src/main/kotlin/com/tangem/lib/visa/VisaContractInfoProvider.kt index 7ae3b7e0dc..4696b698fb 100644 --- a/libs/visa/src/main/kotlin/com/tangem/lib/visa/VisaContractInfoProvider.kt +++ b/libs/visa/src/main/kotlin/com/tangem/lib/visa/VisaContractInfoProvider.kt @@ -3,8 +3,8 @@ package com.tangem.lib.visa import com.ihsanbal.logging.Level import com.ihsanbal.logging.LoggingInterceptor import com.tangem.lib.visa.model.VisaContractInfo -import com.tangem.lib.visa.utils.VisaConfig -import com.tangem.lib.visa.utils.VisaConfig.NETWORK_LOGS_TAG +import com.tangem.lib.visa.utils.Constants +import com.tangem.lib.visa.utils.Constants.NETWORK_LOGS_TAG import com.tangem.lib.visa.utils.toHexString import com.tangem.utils.coroutines.CoroutineDispatcherProvider import okhttp3.OkHttpClient @@ -24,16 +24,16 @@ interface VisaContractInfoProvider { suspend fun getContractInfo(walletAddress: String): VisaContractInfo class Builder( + private val useTestnetRpc: Boolean, + private val bridgeProcessorAddress: String, + private val paymentAccountRegistryAddress: String, private val isNetworkLoggingEnabled: Boolean, private val dispatchers: CoroutineDispatcherProvider, - private val baseUrl: String = VisaConfig.BASE_RPC_URL, - private val bridgeProcessorAddress: String = VisaConfig.BRIDGE_PROCESSOR_CONTRACT_ADDRESS, - private val paymentAccountRegistryAddress: String = VisaConfig.PAYMENT_ACCOUNT_REGISTRY_ADDRESS, - private val chainId: Long = VisaConfig.CHAIN_ID, - private val networkTimeoutSeconds: Long = VisaConfig.NETWORK_TIMEOUT_SECONDS, - private val decimals: Int = VisaConfig.DECIMALS, - private val gasLimit: Long = VisaConfig.GAS_LIMIT, - private val privateKey: String = ByteArray(VisaConfig.PRIVATE_KEY_LENGTH).toHexString(), + private val chainId: Long = Constants.CHAIN_ID, + private val decimals: Int = Constants.DECIMALS, + private val gasLimit: Long = Constants.GAS_LIMIT, + private val networkTimeoutSeconds: Long = Constants.NETWORK_TIMEOUT_SECONDS, + private val privateKey: String = ByteArray(Constants.PRIVATE_KEY_LENGTH).toHexString(), ) { fun build(): VisaContractInfoProvider { @@ -52,6 +52,8 @@ interface VisaContractInfoProvider { } private fun createWeb3J(): Web3j { + val baseUrl: String = if (useTestnetRpc) Constants.TESTNET_RPC_URL else Constants.MAINNET_RPC_URL + val httpClient = OkHttpClient.Builder().apply { connectTimeout(networkTimeoutSeconds, TimeUnit.SECONDS) readTimeout(networkTimeoutSeconds, TimeUnit.SECONDS) diff --git a/libs/visa/src/main/kotlin/com/tangem/lib/visa/api/VisaApiBuilder.kt b/libs/visa/src/main/kotlin/com/tangem/lib/visa/api/VisaApiBuilder.kt index 50f200249b..ef1a99dd5f 100644 --- a/libs/visa/src/main/kotlin/com/tangem/lib/visa/api/VisaApiBuilder.kt +++ b/libs/visa/src/main/kotlin/com/tangem/lib/visa/api/VisaApiBuilder.kt @@ -5,8 +5,8 @@ import com.ihsanbal.logging.Level import com.ihsanbal.logging.LoggingInterceptor import com.squareup.moshi.Moshi import com.tangem.datasource.api.common.response.ApiResponseCallAdapterFactory -import com.tangem.lib.visa.utils.VisaConfig -import com.tangem.lib.visa.utils.VisaConfig.NETWORK_LOGS_TAG +import com.tangem.lib.visa.utils.Constants +import com.tangem.lib.visa.utils.Constants.NETWORK_LOGS_TAG import okhttp3.Interceptor import okhttp3.OkHttpClient import retrofit2.Retrofit @@ -17,7 +17,8 @@ class VisaApiBuilder( private val useDevApi: Boolean, private val isNetworkLoggingEnabled: Boolean, private val moshi: Moshi, - private val networkTimeoutSeconds: Long = VisaConfig.NETWORK_TIMEOUT_SECONDS, + private val headers: Map, + private val networkTimeoutSeconds: Long = Constants.NETWORK_TIMEOUT_SECONDS, ) { fun build(): VisaApi { @@ -35,13 +36,23 @@ class VisaApiBuilder( if (isNetworkLoggingEnabled) { addInterceptor(createNetworkLoggingInterceptor()) } + + if (headers.isNotEmpty()) { + addInterceptor { chain -> + val request = chain.request().newBuilder().apply { + headers.forEach { (key, value) -> addHeader(key, value) } + }.build() + + chain.proceed(request) + } + } } return builder.build() } private fun createRetrofit(okHttpClient: OkHttpClient): Retrofit { - val baseUrl = if (useDevApi) VisaConfig.VISA_API_DEV_URL else VisaConfig.VISA_API_PROD_URL + val baseUrl = if (useDevApi) Constants.VISA_API_DEV_URL else Constants.VISA_API_PROD_URL return Retrofit.Builder() .addConverterFactory(MoshiConverterFactory.create(moshi)) diff --git a/libs/visa/src/main/kotlin/com/tangem/lib/visa/utils/VisaConfig.kt b/libs/visa/src/main/kotlin/com/tangem/lib/visa/utils/Constants.kt similarity index 55% rename from libs/visa/src/main/kotlin/com/tangem/lib/visa/utils/VisaConfig.kt rename to libs/visa/src/main/kotlin/com/tangem/lib/visa/utils/Constants.kt index e3d0a9dab5..06e365e4ec 100644 --- a/libs/visa/src/main/kotlin/com/tangem/lib/visa/utils/VisaConfig.kt +++ b/libs/visa/src/main/kotlin/com/tangem/lib/visa/utils/Constants.kt @@ -1,10 +1,10 @@ package com.tangem.lib.visa.utils -internal object VisaConfig { +internal object Constants { + + const val MAINNET_RPC_URL = "https://polygon-rpc.com/" + const val TESTNET_RPC_URL = "https://rpc-amoy.polygon.technology/" - const val BASE_RPC_URL = "https://polygon-mumbai.g.alchemy.com/v2/_1qqjXgBC_IikaXChnna8KTcV2eMMIQG/" - const val BRIDGE_PROCESSOR_CONTRACT_ADDRESS = "0xe32ecbbc1ec17fa9c160569cd613ad568ca50279" - const val PAYMENT_ACCOUNT_REGISTRY_ADDRESS = "0x3f4ae01073d1a9d5a92315fe118e57d1cdec7c44" const val CHAIN_ID = 80_001L const val DECIMALS = 9 const val GAS_LIMIT = 500_000_000L diff --git a/plugins/configuration/src/main/kotlin/com/tangem/plugin/configuration/configurations/extension/AppExtensionConfigurations.kt b/plugins/configuration/src/main/kotlin/com/tangem/plugin/configuration/configurations/extension/AppExtensionConfigurations.kt index 885f32c1d7..1d659a2d09 100644 --- a/plugins/configuration/src/main/kotlin/com/tangem/plugin/configuration/configurations/extension/AppExtensionConfigurations.kt +++ b/plugins/configuration/src/main/kotlin/com/tangem/plugin/configuration/configurations/extension/AppExtensionConfigurations.kt @@ -74,13 +74,18 @@ private fun AndroidBuildType.configureBuildVariant(extension: AppExtension, buil isDebuggable = true isMinifyEnabled = false } + BuildType.External -> { + initWith(extension.buildTypes.getByName(BuildType.Release.id)) + matchingFallbacks.add(BuildType.Release.id) + signingConfig = extension.signingConfigs.getByName(BuildType.Debug.id) + } BuildType.Internal, - BuildType.External, - BuildType.Mocked + BuildType.Mocked, -> { initWith(extension.buildTypes.getByName(BuildType.Release.id)) matchingFallbacks.add(BuildType.Release.id) signingConfig = extension.signingConfigs.getByName(BuildType.Debug.id) + isDebuggable = true } } diff --git a/plugins/configuration/src/main/kotlin/com/tangem/plugin/configuration/configurations/extension/BaseExtensionConfigurations.kt b/plugins/configuration/src/main/kotlin/com/tangem/plugin/configuration/configurations/extension/BaseExtensionConfigurations.kt index c47360c0fc..49a6869c47 100644 --- a/plugins/configuration/src/main/kotlin/com/tangem/plugin/configuration/configurations/extension/BaseExtensionConfigurations.kt +++ b/plugins/configuration/src/main/kotlin/com/tangem/plugin/configuration/configurations/extension/BaseExtensionConfigurations.kt @@ -20,10 +20,11 @@ internal fun BaseExtension.configureCompilerOptions() { internal fun BaseExtension.configureCompose(project: Project) { val useCompose = with(project.path) { contains(":ui") || + contains(":common:ui-charts") || contains(":features:onboarding") || // TODO: divide on api/impl after migrating all onboarding to module contains(Regex(pattern = ":presentation\$")) || contains(Regex(pattern = ":app\$")) || // TODO: [REDACTED_JIRA] - contains(Regex(pattern = ":features:manage-tokens:api\$")) || // provides Composable function + contains(Regex(pattern = ":features:markets:api\$")) || // provides Composable function contains(Regex(pattern = ":impl\$")) } diff --git a/plugins/configuration/src/main/kotlin/com/tangem/plugin/configuration/configurations/extension/LibraryExtensionConfigurations.kt b/plugins/configuration/src/main/kotlin/com/tangem/plugin/configuration/configurations/extension/LibraryExtensionConfigurations.kt index 053151f9f1..f82cfcf71e 100644 --- a/plugins/configuration/src/main/kotlin/com/tangem/plugin/configuration/configurations/extension/LibraryExtensionConfigurations.kt +++ b/plugins/configuration/src/main/kotlin/com/tangem/plugin/configuration/configurations/extension/LibraryExtensionConfigurations.kt @@ -39,7 +39,7 @@ private fun LibraryExtension.configureBuildTypes() { } private fun LibraryExtension.configurePackagingOptions() { - packagingOptions { + packaging { resources { excludes += "lib/x86_64/darwin/libscrypt.dylib" excludes += "lib/x86_64/freebsd/libscrypt.so" diff --git a/settings.gradle.kts b/settings.gradle.kts index 9f9643c29f..0d6be44673 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -35,6 +35,7 @@ dependencyResolutionManagement { mavenLocal { content { includeGroupAndSubgroups("com.tangem.tangem-sdk-kotlin") + includeGroupAndSubgroups("com.tangem.vico") includeModule("com.tangem", "blstlib") includeModule("com.tangem", "blockchain") includeModule("com.tangem", "wallet-core-proto") @@ -80,6 +81,17 @@ dependencyResolutionManagement { includeModule("com.tangem", "wallet-core") } } + maven { + // setting any repository from tangem project allows maven search all packages in the project + url = uri("https://maven.pkg.github.com/tangem/vico") + credentials { + username = properties.getProperty("gpr.user") ?: System.getenv("GITHUB_ACTOR") + password = properties.getProperty("gpr.key") ?: System.getenv("GITHUB_TOKEN") + } + content { + includeGroupAndSubgroups("com.tangem.vico") + } + } jcenter { // unable to replace with mavenCentral() due to rekotlin content { includeModule("org.rekotlin", "rekotlin") @@ -100,6 +112,8 @@ enableFeaturePreview("TYPESAFE_PROJECT_ACCESSORS") include(":app") include(":common") +include(":common:ui-charts") +include(":common:routing") // region Core modules include(":core:analytics") @@ -113,8 +127,13 @@ include(":core:utils") include(":core:deep-links") include(":core:deep-links:global") include(":core:decompose") +include(":core:pagination") // endregion Core modules +// region Common modules +include(":common:ui") +// endregion + // region Libs modules include(":libs:auth") include(":libs:blockchain-sdk") @@ -159,6 +178,18 @@ include(":features:staking:impl") include(":features:details:api") include(":features:details:impl") + +include(":features:disclaimer:api") +include(":features:disclaimer:impl") + +include(":features:push-notifications:api") +include(":features:push-notifications:impl") + +include(":features:wallet-settings:api") +include(":features:wallet-settings:impl") + +include(":features:markets:api") +include(":features:markets:impl") // endregion Feature modules // region Domain modules @@ -191,7 +222,10 @@ include(":domain:feedback") include(":domain:qr-scanning") include(":domain:qr-scanning:models") include(":domain:staking") +include(":domain:staking:models") include(":domain:wallet-connect") +include(":domain:markets") +include(":domain:markets:models") // endregion Domain modules // region Data modules @@ -213,4 +247,5 @@ include(":data:feedback") include(":data:qr-scanning") include(":data:staking") include(":data:wallet-connect") +include(":data:markets") // endregion Data modules \ No newline at end of file diff --git a/tangem-android-tools b/tangem-android-tools index d8e6da9ab3..0ed07b85e6 160000 --- a/tangem-android-tools +++ b/tangem-android-tools @@ -1 +1 @@ -Subproject commit d8e6da9ab3a0442657822352cb6274237d88e77d +Subproject commit 0ed07b85e64805707b2ef6a92f42bc2c4e8b7753 diff --git a/version.properties b/version.properties new file mode 100644 index 0000000000..f8c3184558 --- /dev/null +++ b/version.properties @@ -0,0 +1 @@ +versionName=5.13.0 \ No newline at end of file