Updated on 2026-08-14

This commit is contained in:
Tangem 2026-07-02 18:21:04 +04:00
parent 5da166073b
commit 4ed2144ca3
2 changed files with 17 additions and 4 deletions

View file

@ -29,6 +29,10 @@ internal class AddWalletTransformer(
override fun transform(prevState: WalletScreenState): WalletScreenState {
return prevState.copy(
// Select the newly added wallet synchronously (it is appended to the end), mirroring
// Initialize/Delete transformers. Otherwise selectedWalletIndex stays stale until the
// deferred scroll settles, and getSelectedWalletId() returns the previously selected wallet.
selectedWalletIndex = prevState.wallets2.size,
wallets = (prevState.wallets + walletLoadingStateFactory.create(userWallet)).toImmutableList(),
wallets2 = (prevState.wallets2 + walletLoadingStateFactory.create2(userWallet)).toImmutableList(),
)

View file

@ -80,6 +80,8 @@ import com.tangem.features.virtualaccount.main.component.VirtualAccountMainBlock
import com.tangem.features.virtualaccount.main.entity.VirtualAccountMainUM
import dev.chrisbanes.haze.HazeProgressive
import dev.chrisbanes.haze.HazeTint
import kotlinx.coroutines.flow.collectLatest
import kotlinx.coroutines.flow.drop
import kotlinx.coroutines.launch
import kotlin.math.abs
@ -208,9 +210,16 @@ private fun WalletContent2(
bottom = paddingValues.calculateBottomPadding() + marketHintApproxHeight,
)
LaunchedEffect(walletsPagerState.currentPage) {
if (walletsPagerState.currentPage != state.selectedWalletIndex) {
state.onWalletChange(walletsPagerState.currentPage, false)
val selectedWalletIndex by rememberUpdatedState(state.selectedWalletIndex)
LaunchedEffect(walletsPagerState) {
// Only react to genuine settles and skip the page the pager was (re)created with, so a
// programmatic scroll or pager recreation can't revert the selection to a stale page.
snapshotFlow { walletsPagerState.settledPage }
.drop(count = 1)
.collectLatest { settledPage ->
if (settledPage != selectedWalletIndex) {
state.onWalletChange(settledPage, false)
}
}
}