Updated on 2026-08-14
This commit is contained in:
parent
bd33dadcfe
commit
5a62376bfa
18 changed files with 194 additions and 163 deletions
|
|
@ -1,6 +1,5 @@
|
|||
package com.tangem.features.account.archived
|
||||
|
||||
import com.tangem.common.ui.account.toUM
|
||||
import com.tangem.core.analytics.api.AnalyticsExceptionHandler
|
||||
import com.tangem.core.analytics.models.ExceptionAnalyticsEvent
|
||||
import com.tangem.core.decompose.model.Model
|
||||
|
|
@ -15,11 +14,8 @@ import com.tangem.core.ui.message.EventMessageAction
|
|||
import com.tangem.core.ui.message.ToastMessage
|
||||
import com.tangem.core.ui.utils.showErrorDialog
|
||||
import com.tangem.domain.account.models.AccountList
|
||||
import com.tangem.domain.account.models.ArchivedAccount
|
||||
import com.tangem.domain.account.usecase.ArchivedAccountList
|
||||
import com.tangem.domain.account.usecase.GetArchivedAccountsUseCase
|
||||
import com.tangem.domain.account.usecase.RecoverCryptoPortfolioUseCase
|
||||
import com.tangem.domain.core.lce.Lce
|
||||
import com.tangem.domain.models.account.AccountId
|
||||
import com.tangem.features.account.ArchivedAccountListComponent
|
||||
import com.tangem.features.account.archived.entity.AccountArchivedUM
|
||||
|
|
@ -30,6 +26,7 @@ import com.tangem.utils.coroutines.JobHolder
|
|||
import com.tangem.utils.coroutines.saveIn
|
||||
import kotlinx.coroutines.flow.*
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.withContext
|
||||
import timber.log.Timber
|
||||
import javax.inject.Inject
|
||||
|
||||
|
|
@ -61,25 +58,32 @@ internal class ArchivedAccountListModel @Inject constructor(
|
|||
.conflate()
|
||||
.distinctUntilChanged()
|
||||
.onEach { lce ->
|
||||
val newState = when (lce) {
|
||||
is Lce.Content<ArchivedAccountList> -> umBuilder.mapContent(
|
||||
accounts = lce.content,
|
||||
onCloseClick = onCloseClick,
|
||||
confirmRecoverDialog = { confirmRecoverDialog(it) },
|
||||
)
|
||||
is Lce.Error<Throwable> -> umBuilder.mapError(
|
||||
throwable = lce.error,
|
||||
onCloseClick = onCloseClick,
|
||||
getArchivedAccounts = { getArchivedAccounts() },
|
||||
)
|
||||
is Lce.Loading<ArchivedAccountList> -> lce.partialContent?.let { content ->
|
||||
val newState = lce.fold(
|
||||
ifLoading = { content ->
|
||||
content ?: return@fold null
|
||||
|
||||
umBuilder.mapContent(
|
||||
accounts = content,
|
||||
onCloseClick = onCloseClick,
|
||||
confirmRecoverDialog = { confirmRecoverDialog(it) },
|
||||
onRecoverClick = { recoverCryptoPortfolio(accountId = it.accountId) },
|
||||
)
|
||||
}
|
||||
}
|
||||
},
|
||||
ifContent = { content ->
|
||||
umBuilder.mapContent(
|
||||
accounts = content,
|
||||
onCloseClick = onCloseClick,
|
||||
onRecoverClick = { recoverCryptoPortfolio(accountId = it.accountId) },
|
||||
)
|
||||
},
|
||||
ifError = { error ->
|
||||
umBuilder.mapError(
|
||||
throwable = error,
|
||||
onCloseClick = onCloseClick,
|
||||
getArchivedAccounts = { getArchivedAccounts() },
|
||||
)
|
||||
},
|
||||
)
|
||||
|
||||
newState?.let { _uiState.value = newState }
|
||||
}
|
||||
.flowOn(dispatchers.default)
|
||||
|
|
@ -87,30 +91,10 @@ internal class ArchivedAccountListModel @Inject constructor(
|
|||
.saveIn(getArchivedAccountsJob)
|
||||
}
|
||||
|
||||
private fun confirmRecoverDialog(account: ArchivedAccount) {
|
||||
val secondAction = EventMessageAction(
|
||||
title = resourceReference(R.string.common_cancel),
|
||||
onClick = {},
|
||||
)
|
||||
val firstAction = EventMessageAction(
|
||||
title = resourceReference(R.string.account_archived_recover),
|
||||
onClick = { recoverCryptoPortfolio(account.accountId) },
|
||||
)
|
||||
messageSender.send(
|
||||
DialogMessage(
|
||||
title = resourceReference(R.string.account_archived_recover_dialog_title),
|
||||
message = resourceReference(
|
||||
id = R.string.account_archived_recover_dialog_description,
|
||||
formatArgs = wrappedList(account.name.toUM().value),
|
||||
),
|
||||
firstActionBuilder = { firstAction },
|
||||
secondActionBuilder = { secondAction },
|
||||
),
|
||||
)
|
||||
}
|
||||
|
||||
private fun recoverCryptoPortfolio(accountId: AccountId) = modelScope.launch(dispatchers.default) {
|
||||
recoverCryptoPortfolioUseCase(accountId)
|
||||
private fun recoverCryptoPortfolio(accountId: AccountId) = modelScope.launch {
|
||||
withContext(dispatchers.default) {
|
||||
recoverCryptoPortfolioUseCase(accountId)
|
||||
}
|
||||
.onLeft(::handleRecoverError)
|
||||
.onRight {
|
||||
showSuccessRecoverMessage()
|
||||
|
|
@ -122,8 +106,22 @@ internal class ArchivedAccountListModel @Inject constructor(
|
|||
if (error is RecoverCryptoPortfolioUseCase.Error.AccountListRequirementsNotMet &&
|
||||
error.cause is AccountList.Error.ExceedsMaxAccountsCount
|
||||
) {
|
||||
// TODO("account") show alert that max accounts count reached
|
||||
// https://www.figma.com/design/09KKG4ZVuFDZhj8WLv5rGJ/%F0%9F%9A%A7-App-experience?node-id=24765-180563&t=vk6TCy4MkYol1cPb-4
|
||||
val firstAction = EventMessageAction(
|
||||
title = resourceReference(R.string.common_got_it),
|
||||
onClick = { },
|
||||
)
|
||||
|
||||
messageSender.send(
|
||||
DialogMessage(
|
||||
title = resourceReference(R.string.account_recover_limit_dialog_title),
|
||||
message = resourceReference(
|
||||
id = R.string.account_recover_limit_dialog_description,
|
||||
formatArgs = wrappedList(AccountList.MAX_ACCOUNTS_COUNT.toString()),
|
||||
),
|
||||
firstActionBuilder = { firstAction },
|
||||
),
|
||||
)
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -15,15 +15,15 @@ internal class AccountArchivedUMBuilder @Inject constructor() {
|
|||
fun mapContent(
|
||||
accounts: ArchivedAccountList,
|
||||
onCloseClick: () -> Unit,
|
||||
confirmRecoverDialog: (account: ArchivedAccount) -> Unit,
|
||||
onRecoverClick: (account: ArchivedAccount) -> Unit,
|
||||
) = AccountArchivedUM.Content(
|
||||
onCloseClick = onCloseClick,
|
||||
accounts = accounts
|
||||
.map { account -> account.mapArchivedAccountUM(confirmRecoverDialog) }
|
||||
.map { account -> account.mapArchivedAccountUM(onRecoverClick) }
|
||||
.toImmutableList(),
|
||||
)
|
||||
|
||||
fun ArchivedAccount.mapArchivedAccountUM(confirmRecoverDialog: (account: ArchivedAccount) -> Unit) =
|
||||
private fun ArchivedAccount.mapArchivedAccountUM(onRecoverClick: (account: ArchivedAccount) -> Unit) =
|
||||
ArchivedAccountUM(
|
||||
accountId = accountId.value,
|
||||
accountName = name.toUM().value,
|
||||
|
|
@ -38,7 +38,7 @@ internal class AccountArchivedUMBuilder @Inject constructor() {
|
|||
count = networksCount,
|
||||
formatArgs = wrappedList(networksCount),
|
||||
),
|
||||
onClick = { confirmRecoverDialog(this) },
|
||||
onClick = { onRecoverClick(this) },
|
||||
)
|
||||
|
||||
fun mapError(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue