Updated on 2026-08-14
This commit is contained in:
parent
5dc6145d63
commit
5ddd060079
6 changed files with 30 additions and 24 deletions
|
|
@ -106,11 +106,7 @@ internal class DefaultWalletManagersRepository(
|
|||
|
||||
override suspend fun delete(userWalletIds: List<UserWalletId>): CompletionResult<Unit> = catching {
|
||||
walletManagersStorage.update { prevManagers ->
|
||||
prevManagers.apply {
|
||||
userWalletIds.forEach { userWalletId ->
|
||||
remove(userWalletId)
|
||||
}
|
||||
}
|
||||
prevManagers.filterKeys { it !in userWalletIds } as HashMap<UserWalletId, List<WalletManager>>
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -306,7 +306,7 @@ class WalletMiddleware {
|
|||
val reduxWalletStores = wallStores.mapToReduxModels(state.isMultiwalletAllowed)
|
||||
store.dispatchOnMain(
|
||||
WalletAction.WalletStoresChanged.UpdateWalletStores(
|
||||
reduxWalletStores = reduxWalletStores.toList(),
|
||||
reduxWalletStores = reduxWalletStores,
|
||||
),
|
||||
)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -36,7 +36,7 @@ class MultiWalletReducer {
|
|||
fun reduce(action: WalletAction.MultiWallet, state: WalletState): WalletState {
|
||||
return when (action) {
|
||||
is WalletAction.MultiWallet.AddBlockchains -> {
|
||||
val walletStores: List<WalletStore> = action.blockchains.mapNotNull { blockchain ->
|
||||
val walletStores: List<WalletStore> = action.blockchains.map { blockchain ->
|
||||
val walletManager = action.walletManagers.firstOrNull {
|
||||
it.wallet.blockchain == blockchain.blockchain &&
|
||||
(it.wallet.publicKey.derivationPath?.rawPath == blockchain.derivationPath)
|
||||
|
|
@ -70,10 +70,10 @@ class MultiWalletReducer {
|
|||
)
|
||||
}
|
||||
|
||||
val selectedCurrency = if (!state.isMultiwalletAllowed) {
|
||||
walletStores.firstOrNull()?.walletsData?.firstOrNull()?.currency
|
||||
val selectedCurrency = if (state.isMultiwalletAllowed) {
|
||||
state.selectedCurrency
|
||||
} else {
|
||||
state.selectedWalletData?.currency
|
||||
walletStores.firstOrNull()?.walletsData?.firstOrNull()?.currency
|
||||
}
|
||||
state.copy(
|
||||
walletsStores = walletStores,
|
||||
|
|
|
|||
|
|
@ -362,13 +362,13 @@ private fun internalReduce(action: Action, state: AppState, appStateHolder: AppS
|
|||
)
|
||||
}
|
||||
is WalletAction.LoadData.Success -> {
|
||||
val selectedCurrency = if (!newState.isMultiwalletAllowed) {
|
||||
val selectedCurrency = if (newState.isMultiwalletAllowed) {
|
||||
newState.selectedCurrency
|
||||
} else {
|
||||
newState.walletsStores.firstOrNull()
|
||||
?.walletsData
|
||||
?.firstOrNull()
|
||||
?.currency
|
||||
} else {
|
||||
newState.selectedWalletData?.currency
|
||||
}
|
||||
|
||||
newState = newState.copy(
|
||||
|
|
|
|||
|
|
@ -8,8 +8,10 @@ import com.tangem.tap.store
|
|||
import com.tangem.tap.userWalletsListManager
|
||||
import com.tangem.tap.walletStoresManager
|
||||
import kotlinx.coroutines.delay
|
||||
import kotlinx.coroutines.flow.distinctUntilChanged
|
||||
import kotlinx.coroutines.flow.flatMapLatest
|
||||
import kotlinx.coroutines.flow.launchIn
|
||||
import kotlinx.coroutines.flow.map
|
||||
import kotlinx.coroutines.flow.onEach
|
||||
import kotlinx.coroutines.launch
|
||||
|
||||
|
|
@ -21,8 +23,10 @@ internal class WalletViewModel : ViewModel() {
|
|||
|
||||
private fun bootstrapSelectedWalletStoresChanges() {
|
||||
userWalletsListManager.selectedUserWallet
|
||||
.flatMapLatest { selectedWallet ->
|
||||
walletStoresManager.get(selectedWallet.walletId)
|
||||
.map { it.walletId }
|
||||
.distinctUntilChanged()
|
||||
.flatMapLatest { selectedUserWalletId ->
|
||||
walletStoresManager.get(selectedUserWalletId)
|
||||
}
|
||||
.onEach { walletStores ->
|
||||
store.dispatch(WalletAction.WalletStoresChanged(walletStores))
|
||||
|
|
|
|||
|
|
@ -277,26 +277,32 @@ internal class WalletSelectorMiddleware {
|
|||
.flatMap { walletStoresManager.delete(userWalletsIds) }
|
||||
.flatMap { deleteAccessCodes(userWalletsIds) }
|
||||
.doOnSuccess {
|
||||
val selectedWallet = userWalletsListManager.selectedUserWalletSync
|
||||
val selectedUserWallet = userWalletsListManager.selectedUserWalletSync
|
||||
|
||||
when {
|
||||
selectedWallet == null -> {
|
||||
selectedUserWallet == null -> {
|
||||
store.dispatchOnMain(NavigationAction.PopBackTo(AppScreen.Welcome))
|
||||
}
|
||||
currentSelectedWalletId != selectedWallet.walletId -> {
|
||||
store.onUserWalletSelected(selectedWallet)
|
||||
|
||||
currentSelectedWalletId != selectedUserWallet.walletId -> {
|
||||
store.onUserWalletSelected(selectedUserWallet)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private suspend fun deleteAccessCodes(userWalletsIds: List<UserWalletId>): CompletionResult<Unit> {
|
||||
val cardsIds = userWalletsListManager.userWallets.firstOrNull().orEmpty()
|
||||
.asSequence()
|
||||
.filter { it.walletId in userWalletsIds }
|
||||
.flatMap { it.cardsInWallet }
|
||||
val cardsIds = userWalletsListManager.userWallets.firstOrNull()
|
||||
?.asSequence()
|
||||
?.filter { it.walletId in userWalletsIds }
|
||||
?.flatMap { it.cardsInWallet }
|
||||
?.toSet()
|
||||
|
||||
return tangemSdkManager.deleteSavedUserCodes(cardsIds.toSet())
|
||||
return if (cardsIds.isNullOrEmpty()) {
|
||||
CompletionResult.Success(Unit)
|
||||
} else {
|
||||
tangemSdkManager.deleteSavedUserCodes(cardsIds.toSet())
|
||||
}
|
||||
}
|
||||
|
||||
private suspend fun UserWalletModel.updateWalletStoresAndCalculateFiatBalance(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue