Updated on 2026-08-14
This commit is contained in:
parent
351671604a
commit
51ed623916
11 changed files with 48 additions and 56 deletions
|
|
@ -19,8 +19,14 @@ interface UserWalletsListManager {
|
|||
|
||||
suspend fun selectWallet(walletId: UserWalletId): CompletionResult<UserWallet>
|
||||
|
||||
suspend fun save(userWallet: UserWallet): CompletionResult<Unit>
|
||||
suspend fun update(userWallet: UserWallet): CompletionResult<Unit>
|
||||
/**
|
||||
* Save user's wallet
|
||||
* @param userWallet User's wallet to save
|
||||
* @param canOverride If false, then terminate with [UserWalletListError.WalletAlreadySaved] when user tries to save an
|
||||
* already saved card
|
||||
* @return [CompletionResult] operation result
|
||||
* */
|
||||
suspend fun save(userWallet: UserWallet, canOverride: Boolean = false): CompletionResult<Unit>
|
||||
|
||||
suspend fun delete(walletIds: List<UserWalletId>): CompletionResult<Unit>
|
||||
suspend fun clear(): CompletionResult<Unit>
|
||||
|
|
|
|||
|
|
@ -110,12 +110,36 @@ internal class BiometricUserWalletsListManager(
|
|||
findSelectedWallet()!!
|
||||
}
|
||||
|
||||
override suspend fun save(userWallet: UserWallet): CompletionResult<Unit> {
|
||||
return saveInternal(userWallet, override = false)
|
||||
}
|
||||
override suspend fun save(
|
||||
userWallet: UserWallet,
|
||||
canOverride: Boolean,
|
||||
): CompletionResult<Unit> = withUnlock {
|
||||
val isWalletSaved = state.value.wallets
|
||||
.filter { it.isSaved }
|
||||
.flatMap(UserWallet::cardsInWallet)
|
||||
.contains(userWallet.cardId)
|
||||
|
||||
override suspend fun update(userWallet: UserWallet): CompletionResult<Unit> {
|
||||
return saveInternal(userWallet, override = true)
|
||||
if (isWalletSaved && !canOverride) {
|
||||
CompletionResult.Failure(UserWalletListError.WalletAlreadySaved)
|
||||
} else {
|
||||
keysRepository.save(
|
||||
walletId = userWallet.walletId,
|
||||
encryptionKey = userWallet.scanResponse.card.encryptionKey,
|
||||
)
|
||||
.doOnSuccess { keys ->
|
||||
state.update { prevState ->
|
||||
prevState.copy(
|
||||
encryptionKeys = (keys + prevState.encryptionKeys).distinctBy { it.walletId },
|
||||
)
|
||||
}
|
||||
}
|
||||
.flatMap { publicInformationRepository.save(userWallet) }
|
||||
.flatMap { sensitiveInformationRepository.save(userWallet) }
|
||||
.flatMap { loadModels() }
|
||||
.doOnSuccess {
|
||||
userWallet.isSaved = true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override suspend fun delete(walletIds: List<UserWalletId>): CompletionResult<Unit> {
|
||||
|
|
@ -162,38 +186,6 @@ internal class BiometricUserWalletsListManager(
|
|||
}
|
||||
}
|
||||
|
||||
private suspend fun saveInternal(
|
||||
userWallet: UserWallet,
|
||||
override: Boolean,
|
||||
): CompletionResult<Unit> = withUnlock {
|
||||
val isWalletSaved = state.value.wallets
|
||||
.filter { it.isSaved }
|
||||
.flatMap(UserWallet::cardsInWallet)
|
||||
.contains(userWallet.cardId)
|
||||
|
||||
if (isWalletSaved && !override) {
|
||||
CompletionResult.Failure(UserWalletListError.WalletAlreadySaved)
|
||||
} else {
|
||||
keysRepository.save(
|
||||
walletId = userWallet.walletId,
|
||||
encryptionKey = userWallet.scanResponse.card.encryptionKey,
|
||||
)
|
||||
.doOnSuccess { keys ->
|
||||
state.update { prevState ->
|
||||
prevState.copy(
|
||||
encryptionKeys = (keys + prevState.encryptionKeys).distinctBy { it.walletId },
|
||||
)
|
||||
}
|
||||
}
|
||||
.flatMap { publicInformationRepository.save(userWallet) }
|
||||
.flatMap { sensitiveInformationRepository.save(userWallet) }
|
||||
.flatMap { loadModels() }
|
||||
.doOnSuccess {
|
||||
userWallet.isSaved = true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private suspend inline fun <reified T> withUnlock(
|
||||
block: () -> CompletionResult<T>,
|
||||
): CompletionResult<T> {
|
||||
|
|
|
|||
|
|
@ -40,11 +40,7 @@ class DummyUserWalletsListManager : UserWalletsListManager {
|
|||
}
|
||||
}
|
||||
|
||||
override suspend fun save(userWallet: UserWallet): CompletionResult<Unit> {
|
||||
return CompletionResult.Success(Unit)
|
||||
}
|
||||
|
||||
override suspend fun update(userWallet: UserWallet): CompletionResult<Unit> {
|
||||
override suspend fun save(userWallet: UserWallet, canOverride: Boolean): CompletionResult<Unit> {
|
||||
return CompletionResult.Success(Unit)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -246,7 +246,7 @@ class DetailsMiddleware {
|
|||
Timber.e(error, "Wallet saving failed")
|
||||
}
|
||||
.doOnSuccess {
|
||||
preferencesStorage.shouldShowSaveWallet = false
|
||||
preferencesStorage.shouldShowSaveUserWalletScreen = false
|
||||
preferencesStorage.shouldSaveUserWallets = true
|
||||
store.dispatchOnMain(
|
||||
DetailsAction.AppSettings.SwitchPrivacySetting.Success(
|
||||
|
|
|
|||
|
|
@ -11,7 +11,6 @@ import com.tangem.tap.preferencesStorage
|
|||
import com.tangem.tap.scope
|
||||
import com.tangem.tap.store
|
||||
import com.tangem.tap.tangemSdkManager
|
||||
import com.tangem.tap.userWalletsListManager
|
||||
import kotlinx.coroutines.delay
|
||||
import kotlinx.coroutines.launch
|
||||
|
||||
|
|
@ -56,8 +55,7 @@ class OnboardingHelper {
|
|||
backupCardsIds: List<String>? = null,
|
||||
) {
|
||||
when {
|
||||
userWalletsListManager.hasSavedUserWallets -> scope.launch {
|
||||
delay(timeMillis = 1_200)
|
||||
preferencesStorage.shouldSaveUserWallets -> scope.launch {
|
||||
store.dispatchOnMain(
|
||||
SaveWalletAction.ProvideBackupInfo(
|
||||
scanResponse = scanResponse,
|
||||
|
|
@ -68,7 +66,7 @@ class OnboardingHelper {
|
|||
store.dispatchOnMain(SaveWalletAction.Save)
|
||||
}
|
||||
tangemSdkManager.canUseBiometry &&
|
||||
preferencesStorage.shouldShowSaveWallet -> scope.launch {
|
||||
preferencesStorage.shouldShowSaveUserWalletScreen -> scope.launch {
|
||||
delay(timeMillis = 1_200)
|
||||
store.dispatchOnMain(
|
||||
SaveWalletAction.ProvideBackupInfo(
|
||||
|
|
|
|||
|
|
@ -82,7 +82,7 @@ internal class SaveWalletMiddleware {
|
|||
val isFirstSavedWallet = !userWalletsListManager.hasSavedUserWallets
|
||||
|
||||
saveAccessCodeIfNeeded(state.backupInfo?.accessCode, userWallet.cardsInWallet)
|
||||
.flatMap { userWalletsListManager.save(userWallet) }
|
||||
.flatMap { userWalletsListManager.save(userWallet, canOverride = true) }
|
||||
.doOnFailure { error ->
|
||||
store.dispatchOnMain(SaveWalletAction.Save.Error(error))
|
||||
}
|
||||
|
|
@ -109,7 +109,7 @@ internal class SaveWalletMiddleware {
|
|||
}
|
||||
|
||||
private fun saveWalletWasShown() {
|
||||
preferencesStorage.shouldShowSaveWallet = false
|
||||
preferencesStorage.shouldShowSaveUserWalletScreen = false
|
||||
}
|
||||
|
||||
private suspend fun saveAccessCodeIfNeeded(
|
||||
|
|
|
|||
|
|
@ -286,7 +286,7 @@ class TokensMiddleware {
|
|||
)
|
||||
|
||||
scope.launch {
|
||||
userWalletsListManager.update(updatedUserWallet)
|
||||
userWalletsListManager.save(updatedUserWallet, canOverride = true)
|
||||
.flatMap {
|
||||
walletCurrenciesManager.addCurrencies(
|
||||
userWallet = updatedUserWallet,
|
||||
|
|
|
|||
|
|
@ -189,7 +189,7 @@ class MultiWalletMiddleware {
|
|||
scanResponse = scanResponse,
|
||||
)
|
||||
|
||||
userWalletsListManager.update(userWallet)
|
||||
userWalletsListManager.save(userWallet, canOverride = true)
|
||||
.doOnSuccess {
|
||||
store.state.globalState.tapWalletManager.loadData(userWallet, refresh = true)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -338,7 +338,7 @@ class WalletMiddleware {
|
|||
}
|
||||
|
||||
private fun showSaveWalletIfNeeded() {
|
||||
if (preferencesStorage.shouldShowSaveWallet
|
||||
if (preferencesStorage.shouldShowSaveUserWalletScreen
|
||||
&& tangemSdkManager.canUseBiometry
|
||||
&& store.state.navigationState.backStack.lastOrNull() == AppScreen.Wallet
|
||||
) {
|
||||
|
|
|
|||
|
|
@ -168,7 +168,7 @@ internal class WalletSelectorMiddleware {
|
|||
scope.launch {
|
||||
userWalletsListManager.get(walletId = UserWalletId(walletId))
|
||||
.map { it.copy(name = newName) }
|
||||
.flatMap { userWalletsListManager.update(it) }
|
||||
.flatMap { userWalletsListManager.save(it, canOverride = true) }
|
||||
.doOnFailure { error ->
|
||||
store.dispatchOnMain(WalletSelectorAction.HandleError(error))
|
||||
}
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@ class PreferencesStorage(applicationContext: Application) {
|
|||
get() = preferences.getLong(CHAT_FIRST_LAUNCH_KEY, 0).takeIf { it != 0L }
|
||||
set(value) = preferences.edit { putLong(CHAT_FIRST_LAUNCH_KEY, value ?: 0) }
|
||||
|
||||
var shouldShowSaveWallet: Boolean
|
||||
var shouldShowSaveUserWalletScreen: Boolean
|
||||
get() = preferences.getBoolean(SAVE_WALLET_DIALOG_SHOWN_KEY, true)
|
||||
set(value) = preferences.edit {
|
||||
putBoolean(SAVE_WALLET_DIALOG_SHOWN_KEY, value)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue