Updated on 2026-08-14

This commit is contained in:
Tangem 2022-12-12 15:16:01 +03:00
parent ce76ab4791
commit 8df1379bdc
7 changed files with 57 additions and 32 deletions

View file

@ -15,7 +15,6 @@ import com.tangem.operations.backup.BackupService
import com.tangem.tangem_sdk_new.extensions.init
import com.tangem.tap.common.ActivityResultCallbackHolder
import com.tangem.tap.common.DialogManager
import com.tangem.tap.common.IntentHandler
import com.tangem.tap.common.OnActivityResultCallback
import com.tangem.tap.common.SnackbarHandler
import com.tangem.tap.common.extensions.dispatchOnMain
@ -29,6 +28,7 @@ import com.tangem.tap.domain.TangemSdkManager
import com.tangem.tap.domain.userWalletList.UserWalletsListManager
import com.tangem.tap.domain.userWalletList.di.provideBiometricImplementation
import com.tangem.tap.features.shop.redux.ShopAction
import com.tangem.tap.features.welcome.redux.WelcomeAction
import com.tangem.tap.proxy.AppStateHolder
import com.tangem.wallet.R
import com.tangem.wallet.databinding.ActivityMainBinding
@ -66,7 +66,6 @@ class MainActivity : AppCompatActivity(), SnackbarHandler, ActivityResultCallbac
private var snackbar: Snackbar? = null
private val dialogManager = DialogManager()
private val intentHandler = IntentHandler()
private val binding: ActivityMainBinding by viewBinding(ActivityMainBinding::bind)
private val onActivityResultCallbacks = mutableListOf<OnActivityResultCallback>()
@ -119,16 +118,23 @@ class MainActivity : AppCompatActivity(), SnackbarHandler, ActivityResultCallbac
val isOnboardingServiceActive = store.state.globalState.onboardingState.onboardingStarted
val shopOpened = store.state.shopState.total != null
if (backStackIsEmpty || (!isOnboardingServiceActive && !isScannedBefore && !shopOpened)) {
val navigateTo = if (userWalletsListManager.hasSavedUserWallets) AppScreen.Welcome else AppScreen.Home
store.dispatchOnMain(NavigationAction.NavigateTo(navigateTo))
if (userWalletsListManager.hasSavedUserWallets) {
store.dispatchOnMain(WelcomeAction.HandleDeepLink(intent))
store.dispatchOnMain(NavigationAction.NavigateTo(AppScreen.Welcome))
} else {
store.dispatchOnMain(NavigationAction.NavigateTo(AppScreen.Home))
intentHandler.handleWalletConnectLink(intent)
}
}
intentHandler.handleIntent(intent)
intentHandler.handleBackgroundScan(intent)
intentHandler.handleSellCurrencyCallback(intent)
}
override fun onNewIntent(intent: Intent?) {
super.onNewIntent(intent)
intentHandler.handleIntent(intent)
intentHandler.handleBackgroundScan(intent)
intentHandler.handleSellCurrencyCallback(intent)
intentHandler.handleWalletConnectLink(intent)
}
override fun onStart() {

View file

@ -16,6 +16,7 @@ import com.tangem.domain.DomainLayer
import com.tangem.domain.common.LogConfig
import com.tangem.tap.common.AndroidAssetReader
import com.tangem.tap.common.AssetReader
import com.tangem.tap.common.IntentHandler
import com.tangem.tap.common.analytics.Analytics
import com.tangem.tap.common.analytics.AnalyticsFactory
import com.tangem.tap.common.analytics.api.AnalyticsHandlerBuilder
@ -109,6 +110,7 @@ val walletCurrenciesManager by lazy {
val totalFiatBalanceCalculator by lazy {
TotalFiatBalanceCalculator.provideDefaultImplementation()
}
val intentHandler by lazy { IntentHandler() }
@HiltAndroidApp
class TapApplication : Application(), ImageLoaderFactory {

View file

@ -19,13 +19,13 @@ class IntentHandler {
private val CURRENCY_AMOUNT_PARAM = "baseCurrencyAmount"
private val DEPOSIT_WALLET_ADDRESS_PARAM = "depositWalletAddress"
fun handleIntent(intent: Intent?) {
handleBackgroundScan(intent)
handleWalletConnectLink(intent)
handleSellCurrencyCallback(intent)
fun handleWalletConnectLink(intent: Intent?) {
if (intent?.scheme == WalletConnectManager.WC_SCHEME) {
store.dispatch(WalletConnectAction.HandleDeepLink(intent.data?.toString()))
}
}
private fun handleBackgroundScan(intent: Intent?) {
fun handleBackgroundScan(intent: Intent?) {
if (intent != null && (NfcAdapter.ACTION_TECH_DISCOVERED == intent.action ||
NfcAdapter.ACTION_NDEF_DISCOVERED == intent.action
)
@ -40,13 +40,7 @@ class IntentHandler {
}
}
private fun handleWalletConnectLink(intent: Intent?) {
if (intent?.scheme == WalletConnectManager.WC_SCHEME) {
store.dispatch(WalletConnectAction.HandleDeepLink(intent.data?.toString()))
}
}
private fun handleSellCurrencyCallback(intent: Intent?) {
fun handleSellCurrencyCallback(intent: Intent?) {
try {
val transactionID =
intent?.data?.getQueryParameter(TRANSACTION_ID_PARAM) ?: return

View file

@ -1,5 +1,6 @@
package com.tangem.tap.features.welcome.redux
import android.content.Intent
import com.tangem.common.core.TangemError
import org.rekotlin.Action
@ -14,5 +15,7 @@ internal sealed interface WelcomeAction : Action {
data class Error(val error: TangemError) : WelcomeAction
}
data class HandleDeepLink(val intent: Intent?) : WelcomeAction
object CloseError : WelcomeAction
}

View file

@ -1,5 +1,6 @@
package com.tangem.tap.features.welcome.redux
import android.content.Intent
import com.tangem.common.doOnFailure
import com.tangem.common.doOnSuccess
import com.tangem.domain.common.ScanResponse
@ -10,6 +11,7 @@ import com.tangem.tap.common.redux.navigation.AppScreen
import com.tangem.tap.common.redux.navigation.NavigationAction
import com.tangem.tap.domain.model.builders.UserWalletBuilder
import com.tangem.tap.domain.scanCard.ScanCardProcessor
import com.tangem.tap.intentHandler
import com.tangem.tap.preferencesStorage
import com.tangem.tap.scope
import com.tangem.tap.store
@ -19,30 +21,37 @@ import kotlinx.coroutines.launch
import org.rekotlin.Middleware
internal class WelcomeMiddleware {
val middleware: Middleware<AppState> = { _, _ ->
val middleware: Middleware<AppState> = { _, appStateProvider ->
{ next ->
{ action ->
if (action is WelcomeAction) {
handleAction(action)
val appState = appStateProvider()
if (action is WelcomeAction && appState != null) {
handleAction(action, appState.welcomeState)
}
next(action)
}
}
}
private fun handleAction(action: WelcomeAction) {
private fun handleAction(action: WelcomeAction, state: WelcomeState) {
when (action) {
is WelcomeAction.ProceedWithBiometrics -> proceedWithBiometry()
is WelcomeAction.ProceedWithCard -> proceedWithCard()
is WelcomeAction.ProceedWithBiometrics.Error -> Unit
is WelcomeAction.ProceedWithCard.Error -> Unit
is WelcomeAction.ProceedWithBiometrics.Success -> Unit
is WelcomeAction.ProceedWithCard.Success -> Unit
is WelcomeAction.CloseError -> Unit
is WelcomeAction.ProceedWithBiometrics -> {
proceedWithBiometry(state)
}
is WelcomeAction.ProceedWithCard -> {
proceedWithCard(state)
}
is WelcomeAction.ProceedWithBiometrics.Error,
is WelcomeAction.ProceedWithCard.Error,
is WelcomeAction.ProceedWithBiometrics.Success,
is WelcomeAction.ProceedWithCard.Success,
is WelcomeAction.CloseError,
is WelcomeAction.HandleDeepLink,
-> Unit
}
}
private fun proceedWithBiometry() {
private fun proceedWithBiometry(state: WelcomeState) {
scope.launch {
userWalletsListManager.unlockWithBiometry()
.doOnFailure { error ->
@ -58,12 +67,14 @@ internal class WelcomeMiddleware {
store.dispatchOnMain(NavigationAction.NavigateTo(AppScreen.Wallet))
store.dispatchOnMain(WelcomeAction.ProceedWithBiometrics.Success)
store.onUserWalletSelected(selectedUserWallet)
handleDeepLinkIfNeeded(state.deepLinkIntent)
}
}
}
}
private fun proceedWithCard() = scope.launch {
private fun proceedWithCard(state: WelcomeState) = scope.launch {
scanCardInternal { scanResponse ->
val userWallet = UserWalletBuilder(scanResponse).build()
@ -78,10 +89,16 @@ internal class WelcomeMiddleware {
store.dispatchOnMain(NavigationAction.NavigateTo(AppScreen.Wallet))
store.dispatchOnMain(WelcomeAction.ProceedWithCard.Success)
store.onUserWalletSelected(userWallet)
handleDeepLinkIfNeeded(state.deepLinkIntent)
}
}
}
private fun handleDeepLinkIfNeeded(intent: Intent?) {
intentHandler.handleWalletConnectLink(intent)
}
private suspend inline fun scanCardInternal(
crossinline onCardScanned: suspend (ScanResponse) -> Unit,
) {

View file

@ -12,6 +12,7 @@ internal object WelcomeReducer {
private fun internalReduce(action: WelcomeAction, state: WelcomeState): WelcomeState {
return when (action) {
is WelcomeAction.HandleDeepLink -> state.copy(deepLinkIntent = action.intent)
is WelcomeAction.ProceedWithBiometrics -> state.copy(isUnlockWithBiometricsInProgress = true)
is WelcomeAction.ProceedWithCard -> state.copy(isUnlockWithCardInProgress = true)
is WelcomeAction.ProceedWithBiometrics.Error -> state.copy(

View file

@ -1,10 +1,12 @@
package com.tangem.tap.features.welcome.redux
import android.content.Intent
import com.tangem.common.core.TangemError
import org.rekotlin.StateType
data class WelcomeState(
val isUnlockWithBiometricsInProgress: Boolean = false,
val isUnlockWithCardInProgress: Boolean = false,
val deepLinkIntent: Intent? = null,
val error: TangemError? = null,
) : StateType