Updated on 2026-08-14

This commit is contained in:
Tangem 2025-12-03 14:25:18 +03:00
parent ccb8c774ed
commit 57d3a102ab
4 changed files with 28 additions and 10 deletions

View file

@ -344,18 +344,27 @@ internal class DefaultWalletsRepository(
upgradeWalletNotificationDisabled.update { it.plus(userWalletId) }
}
override suspend fun setWalletName(walletId: String, walletName: String) = withContext(dispatchers.io) {
val userWallet = userWalletsStore.getSyncOrNull(key = UserWalletId(walletId))
override suspend fun setWalletName(walletId: UserWalletId, walletName: String) = withContext(dispatchers.io) {
val userWallet = userWalletsStore.getSyncOrNull(key = walletId)
tangemTechApi.updateWallet(
walletId = walletId,
walletId = walletId.stringValue,
body = WalletBody(name = walletName, type = WalletType.from(userWallet)),
).getOrThrow()
}
override suspend fun getWalletInfo(walletId: String): UserWalletRemoteInfo = withContext(dispatchers.io) {
override suspend fun upgradeWallet(walletId: UserWalletId) = withContext(dispatchers.io) {
val userWallet = userWalletsStore.getSyncStrict(key = walletId)
tangemTechApi.updateWallet(
walletId = walletId.stringValue,
body = WalletBody(name = userWallet.name, type = WalletType.from(userWallet)),
).getOrThrow()
}
override suspend fun getWalletInfo(walletId: UserWalletId): UserWalletRemoteInfo = withContext(dispatchers.io) {
UserWalletRemoteInfoConverter.convert(
value = tangemTechApi.getWalletById(walletId).getOrThrow(),
value = tangemTechApi.getWalletById(walletId.stringValue).getOrThrow(),
)
}

View file

@ -64,10 +64,13 @@ interface WalletsRepository {
suspend fun dismissUpgradeWalletNotification(userWalletId: UserWalletId)
@Throws
suspend fun setWalletName(walletId: String, walletName: String)
suspend fun setWalletName(walletId: UserWalletId, walletName: String)
@Throws
suspend fun getWalletInfo(walletId: String): UserWalletRemoteInfo
suspend fun upgradeWallet(walletId: UserWalletId)
@Throws
suspend fun getWalletInfo(walletId: UserWalletId): UserWalletRemoteInfo
@Throws
suspend fun getWalletsInfo(applicationId: String, updateCache: Boolean = true): List<UserWalletRemoteInfo>

View file

@ -16,7 +16,7 @@ class RenameWalletUseCase(
suspend operator fun invoke(userWalletId: UserWalletId, name: String): Either<UpdateWalletError, UserWallet> =
either {
runCatching {
walletsRepository.setWalletName(userWalletId.stringValue, name)
walletsRepository.setWalletName(userWalletId, name)
}
userWalletsSyncDelegate.syncWallet(userWalletId, name).bind()

View file

@ -41,6 +41,7 @@ import com.tangem.sdk.api.BackupServiceHolder
import com.tangem.sdk.api.TangemSdkManager
import com.tangem.utils.StringsSigns
import com.tangem.utils.coroutines.CoroutineDispatcherProvider
import com.tangem.utils.coroutines.runSuspendCatching
import kotlinx.coroutines.NonCancellable
import kotlinx.coroutines.flow.MutableSharedFlow
import kotlinx.coroutines.flow.MutableStateFlow
@ -91,7 +92,8 @@ internal class MultiWalletFinalizeModel @Inject constructor(
// sets proper artwork state for initial step
// (if we start from backup cards, we need to show proper artwork) ([REDACTED_TASK_KEY])
when (getInitialStep()) {
MultiWalletFinalizeUM.Step.Primary -> { /* state is already set */ }
MultiWalletFinalizeUM.Step.Primary -> { /* state is already set */
}
MultiWalletFinalizeUM.Step.BackupDevice1 -> {
onEvent.emit(MultiWalletFinalizeComponent.Event.OneBackupCardAdded)
}
@ -299,7 +301,11 @@ internal class MultiWalletFinalizeModel @Inject constructor(
.updateWithHotWallet(wallet),
)
},
).getOrElse {
).onRight {
launch(NonCancellable) {
runSuspendCatching { walletsRepository.upgradeWallet(userWalletCreated.walletId) }
}
}.getOrElse {
error("Failed to upgrade to cold wallet. Error: $it")
}
}