Updated on 2026-08-14

This commit is contained in:
Tangem 2024-03-01 17:31:59 +08:00
parent 5c37996587
commit a7c74b16f3
3 changed files with 93 additions and 89 deletions

View file

@ -178,7 +178,7 @@ internal class WalletViewModel @Inject constructor(
}
}
private fun updateWallets(action: WalletsUpdateActionResolver.Action) {
private suspend fun updateWallets(action: WalletsUpdateActionResolver.Action) {
when (action) {
is WalletsUpdateActionResolver.Action.InitializeWallets -> initializeWallets(action)
is WalletsUpdateActionResolver.Action.ReinitializeWallets -> {
@ -203,7 +203,7 @@ internal class WalletViewModel @Inject constructor(
}
}
private fun initializeWallets(action: WalletsUpdateActionResolver.Action.InitializeWallets) {
private suspend fun initializeWallets(action: WalletsUpdateActionResolver.Action.InitializeWallets) {
walletScreenContentLoader.load(
userWallet = action.selectedWallet,
clickIntents = clickIntents,
@ -219,100 +219,96 @@ internal class WalletViewModel @Inject constructor(
),
)
viewModelScope.launch(dispatchers.main) {
if (action.wallets.size > 1 && isWalletsScrollPreviewEnabled()) {
withContext(dispatchers.io) {
delay(timeMillis = 1_800)
}
if (action.wallets.size > 1 && isWalletsScrollPreviewEnabled()) {
withContext(dispatchers.io) { delay(timeMillis = 1_800) }
walletEventSender.send(
event = WalletEvent.DemonstrateWalletsScrollPreview(
direction = if (action.selectedWalletIndex == action.wallets.lastIndex) {
Direction.RIGHT
} else {
Direction.LEFT
},
),
)
}
walletEventSender.send(
event = WalletEvent.DemonstrateWalletsScrollPreview(
direction = if (action.selectedWalletIndex == action.wallets.lastIndex) {
Direction.RIGHT
} else {
Direction.LEFT
},
),
)
}
}
private fun reinitializeWallet(action: WalletsUpdateActionResolver.Action.ReinitializeWallet) {
viewModelScope.launch(dispatchers.main) {
walletScreenContentLoader.cancel(action.prevWalletId)
walletScreenContentLoader.cancel(action.prevWalletId)
walletScreenContentLoader.load(
userWallet = action.selectedWallet,
clickIntents = clickIntents,
coroutineScope = viewModelScope,
)
walletScreenContentLoader.load(
userWallet = action.selectedWallet,
clickIntents = clickIntents,
coroutineScope = viewModelScope,
)
stateHolder.update(
ReinitializeWalletTransformer(userWallet = action.selectedWallet, clickIntents = clickIntents),
)
}
stateHolder.update(
ReinitializeWalletTransformer(userWallet = action.selectedWallet, clickIntents = clickIntents),
)
}
private fun addWallet(action: WalletsUpdateActionResolver.Action.AddWallet) {
viewModelScope.launch(dispatchers.main) {
stateHolder.update(
AddWalletTransformer(
userWallet = action.selectedWallet,
clickIntents = clickIntents,
),
)
walletScreenContentLoader.load(
private suspend fun addWallet(action: WalletsUpdateActionResolver.Action.AddWallet) {
stateHolder.update(
AddWalletTransformer(
userWallet = action.selectedWallet,
clickIntents = clickIntents,
coroutineScope = viewModelScope,
)
),
)
walletScreenContentLoader.load(
userWallet = action.selectedWallet,
clickIntents = clickIntents,
coroutineScope = viewModelScope,
)
withContext(dispatchers.io) { delay(timeMillis = 700) }
scrollToWallet(index = action.selectedWalletIndex)
}
private suspend fun deleteWallet(action: WalletsUpdateActionResolver.Action.DeleteWallet) {
walletScreenContentLoader.load(
userWallet = action.selectedWallet,
clickIntents = clickIntents,
coroutineScope = viewModelScope,
)
if (action.selectedWalletIndex != 0) {
/*
* If card is reset to factory settings, then Compose need some time to draw the WalletScreen.
* Otherwise, scroll isn't happened
*/
withContext(dispatchers.io) { delay(timeMillis = 700) }
scrollToWallet(index = action.selectedWalletIndex)
withContext(dispatchers.io) { delay(timeMillis = 1000) }
}
stateHolder.update(
DeleteWalletTransformer(
selectedWalletIndex = action.selectedWalletIndex,
deletedWalletId = action.deletedWalletId,
),
)
}
private fun deleteWallet(action: WalletsUpdateActionResolver.Action.DeleteWallet) {
viewModelScope.launch(dispatchers.main) {
walletScreenContentLoader.load(
userWallet = action.selectedWallet,
private suspend fun unlockWallet(action: WalletsUpdateActionResolver.Action.UnlockWallet) {
withContext(dispatchers.io) { delay(timeMillis = 700) }
stateHolder.update(
transformer = UnlockWalletTransformer(
unlockedWallets = action.unlockedWallets,
clickIntents = clickIntents,
coroutineScope = viewModelScope,
)
),
)
scrollToWallet(index = action.selectedWalletIndex)
withContext(dispatchers.io) { delay(timeMillis = 700) }
stateHolder.update(
DeleteWalletTransformer(
selectedWalletIndex = action.selectedWalletIndex,
deletedWalletId = action.deletedWalletId,
),
)
}
}
private fun unlockWallet(action: WalletsUpdateActionResolver.Action.UnlockWallet) {
viewModelScope.launch(dispatchers.main) {
withContext(dispatchers.io) { delay(timeMillis = 700) }
stateHolder.update(
transformer = UnlockWalletTransformer(
unlockedWallets = action.unlockedWallets,
clickIntents = clickIntents,
),
)
walletScreenContentLoader.load(
userWallet = action.selectedWallet,
clickIntents = clickIntents,
coroutineScope = viewModelScope,
)
}
walletScreenContentLoader.load(
userWallet = action.selectedWallet,
clickIntents = clickIntents,
coroutineScope = viewModelScope,
)
}
private fun scrollToWallet(index: Int) {