Updated on 2026-08-14

This commit is contained in:
Tangem 2024-05-23 14:29:37 +08:00
parent 0b8efe6d02
commit 125b301a32
3 changed files with 74 additions and 17 deletions

View file

@ -9,6 +9,7 @@ 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.wallets.models.UserWalletId
import com.tangem.domain.wallets.usecase.GetSelectedWalletUseCase
import com.tangem.domain.wallets.usecase.GetWalletsUseCase
import com.tangem.feature.wallet.presentation.deeplink.WalletDeepLinksHandler
@ -31,6 +32,7 @@ import com.tangem.utils.Provider
import com.tangem.utils.coroutines.CoroutineDispatcherProvider
import com.tangem.utils.coroutines.JobHolder
import com.tangem.utils.coroutines.saveIn
import com.tangem.utils.extensions.indexOfFirstOrNull
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.delay
import kotlinx.coroutines.flow.*
@ -153,16 +155,29 @@ internal class WalletViewModel @Inject constructor(
selectedWalletAnalyticsSender.send(selectedWallet)
}
walletDeepLinksHandler.registerForWallet(
viewModel = this,
userWallet = selectedWallet,
)
changeSelectedWalletState(selectedWalletId = selectedWallet.walletId)
walletDeepLinksHandler.registerForWallet(viewModel = this, userWallet = selectedWallet)
}
.flowOn(dispatchers.main)
.launchIn(viewModelScope)
}
}
/** Change selected wallet state if selected wallet [selectedWalletId] was changed in the background */
private suspend fun changeSelectedWalletState(selectedWalletId: UserWalletId) {
if (screenLifecycleProvider.isBackgroundState.value && selectedWalletId != stateHolder.getSelectedWalletId()) {
stateHolder.value.wallets
.indexOfFirstOrNull { prevState -> prevState.walletCardState.id == selectedWalletId }
?.let { selectedIndex ->
Timber.e("Selected wallet changed from background state: $selectedWalletId")
delay(timeMillis = 1000)
scrollToWallet(selectedIndex)
}
}
}
// We need to update the current wallet if the application was in the background for more than 10 seconds
// and then returned to the foreground
private fun subscribeToScreenBackgroundState() {