Updated on 2026-08-14
This commit is contained in:
parent
a88a63d6ef
commit
6018cf0b71
6 changed files with 43 additions and 13 deletions
|
|
@ -7,5 +7,16 @@ import com.squareup.moshi.JsonClass
|
|||
data class WalletIdBody(
|
||||
@Json(name = "id") val walletId: String,
|
||||
@Json(name = "name") val name: String,
|
||||
@Json(name = "type") val walletType: WalletType? = null,
|
||||
@Json(name = "cards") val cards: List<CardInfoBody>? = null,
|
||||
)
|
||||
) {
|
||||
|
||||
@JsonClass(generateAdapter = false)
|
||||
enum class WalletType {
|
||||
@Json(name = "card")
|
||||
COLD,
|
||||
|
||||
@Json(name = "mobile")
|
||||
HOT,
|
||||
}
|
||||
}
|
||||
|
|
@ -12,11 +12,13 @@ import com.tangem.datasource.api.common.response.isNetworkError
|
|||
import com.tangem.datasource.api.tangemTech.TangemTechApi
|
||||
import com.tangem.datasource.api.tangemTech.models.UserTokensResponse
|
||||
import com.tangem.datasource.api.tangemTech.models.WalletIdBody
|
||||
import com.tangem.datasource.api.tangemTech.models.WalletIdBody.WalletType
|
||||
import com.tangem.datasource.api.tangemTech.models.account.GetWalletAccountsResponse
|
||||
import com.tangem.datasource.api.tangemTech.models.account.WalletAccountDTO
|
||||
import com.tangem.datasource.api.tangemTech.models.account.toUserTokensResponse
|
||||
import com.tangem.datasource.local.token.UserTokensResponseStore
|
||||
import com.tangem.datasource.local.userwallet.UserWalletsStore
|
||||
import com.tangem.domain.models.wallet.UserWallet
|
||||
import com.tangem.domain.models.wallet.UserWalletId
|
||||
import com.tangem.utils.coroutines.CoroutineDispatcherProvider
|
||||
import kotlinx.coroutines.withContext
|
||||
|
|
@ -127,6 +129,10 @@ internal class FetchWalletAccountsErrorHandler @Inject constructor(
|
|||
body = WalletIdBody(
|
||||
walletId = userWalletId.stringValue,
|
||||
name = userWallet.name,
|
||||
walletType = when (userWallet) {
|
||||
is UserWallet.Cold -> WalletType.COLD
|
||||
is UserWallet.Hot -> WalletType.HOT
|
||||
},
|
||||
),
|
||||
)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -113,14 +113,20 @@ class FetchWalletAccountsErrorHandlerTest {
|
|||
)
|
||||
|
||||
val walletName = "Wallet"
|
||||
val userWallet = mockk<UserWallet> {
|
||||
val userWallet = mockk<UserWallet.Cold> {
|
||||
every { this@mockk.walletId } returns userWalletId
|
||||
every { this@mockk.name } returns walletName
|
||||
}
|
||||
coEvery { userWalletsStore.getSyncOrNull(userWalletId) } returns userWallet
|
||||
|
||||
coEvery {
|
||||
tangemTechApi.createWallet(WalletIdBody(walletId = userWalletId.stringValue, name = walletName))
|
||||
tangemTechApi.createWallet(
|
||||
WalletIdBody(
|
||||
walletId = userWalletId.stringValue,
|
||||
name = walletName,
|
||||
walletType = WalletIdBody.WalletType.COLD,
|
||||
),
|
||||
)
|
||||
} returns apiResponse
|
||||
coEvery { pushWalletAccounts(userWalletId, listOf(accountDTO)) } returns savedAccountsResponse
|
||||
|
||||
|
|
@ -136,7 +142,13 @@ class FetchWalletAccountsErrorHandlerTest {
|
|||
// Assert
|
||||
coVerify {
|
||||
userTokensSaver.pushWithRetryer(userWalletId, response = savedAccountsResponse.toUserTokensResponse())
|
||||
tangemTechApi.createWallet(WalletIdBody(walletId = userWalletId.stringValue, name = "Wallet"))
|
||||
tangemTechApi.createWallet(
|
||||
WalletIdBody(
|
||||
walletId = userWalletId.stringValue,
|
||||
name = walletName,
|
||||
walletType = WalletIdBody.WalletType.COLD,
|
||||
),
|
||||
)
|
||||
eTagsStore.store(userWalletId, ETagsStore.Key.WalletAccounts, eTagValue)
|
||||
pushWalletAccounts(userWalletId, listOf(accountDTO))
|
||||
storeWalletAccounts(userWalletId, savedAccountsResponse)
|
||||
|
|
|
|||
|
|
@ -176,11 +176,10 @@ class NetworkFactory @Inject constructor(
|
|||
Network.DerivationPath.Card(defaultDerivationPath)
|
||||
}
|
||||
} else {
|
||||
val isMainIndexOrNull = accountIndex == null || accountIndex == DerivationIndex.Main
|
||||
if (extraDerivationPath != defaultDerivationPath && isMainIndexOrNull) {
|
||||
Network.DerivationPath.Custom(extraDerivationPath)
|
||||
if (extraDerivationPath == defaultDerivationPath) {
|
||||
Network.DerivationPath.Card(defaultDerivationPath)
|
||||
} else {
|
||||
Network.DerivationPath.Card(extraDerivationPath)
|
||||
Network.DerivationPath.Custom(extraDerivationPath)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@ import com.tangem.datasource.api.common.response.getOrThrow
|
|||
import com.tangem.datasource.api.tangemTech.TangemTechApi
|
||||
import com.tangem.datasource.api.tangemTech.models.*
|
||||
import com.tangem.datasource.api.tangemTech.models.SeedPhraseNotificationDTO.Status
|
||||
import com.tangem.datasource.api.tangemTech.models.WalletIdBody.WalletType
|
||||
import com.tangem.datasource.local.datastore.RuntimeStateStore
|
||||
import com.tangem.datasource.local.preferences.AppPreferencesStore
|
||||
import com.tangem.datasource.local.preferences.PreferencesKeys
|
||||
|
|
@ -260,6 +261,10 @@ internal class DefaultWalletsRepository(
|
|||
body = WalletIdBody(
|
||||
walletId = userWalletId.stringValue,
|
||||
name = userWallet.name,
|
||||
walletType = when (userWallet) {
|
||||
is UserWallet.Cold -> WalletType.COLD
|
||||
is UserWallet.Hot -> WalletType.HOT
|
||||
},
|
||||
),
|
||||
)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,19 +24,16 @@ internal class ExpandedAccountsHolder @Inject constructor(
|
|||
flow = walletAccounts(userWallet),
|
||||
flow2 = isAccountsModeEnabledUseCase.invoke(),
|
||||
transform = { accountList, isAccountsMode ->
|
||||
if (!isAccountsMode) {
|
||||
expandedAccounts.update { emptyMap() }
|
||||
return@combine
|
||||
}
|
||||
val isSingleAccount = accountList.accounts.size == 1
|
||||
val defaultExpanded = when {
|
||||
!isAccountsMode -> setOf()
|
||||
isSingleAccount -> setOf(accountList.mainAccount.accountId)
|
||||
else -> setOf()
|
||||
}
|
||||
expandedAccounts.update { map ->
|
||||
var expandedSet = map[userWallet.walletId] ?: defaultExpanded
|
||||
// force expand for single account
|
||||
if (isSingleAccount) expandedSet = defaultExpanded
|
||||
if (isSingleAccount || !isAccountsMode) expandedSet = defaultExpanded
|
||||
map.plus(userWallet.walletId to expandedSet)
|
||||
}
|
||||
},
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue