Updated on 2026-08-14

This commit is contained in:
Tangem 2023-01-27 18:21:59 +03:00
commit 159cac64ea
3 changed files with 32 additions and 1 deletions

View file

@ -27,6 +27,7 @@ import com.tangem.tap.domain.walletStores.repository.WalletAmountsRepository
import com.tangem.tap.domain.walletStores.repository.implementation.utils.replaceWalletStore
import com.tangem.tap.domain.walletStores.repository.implementation.utils.replaceWalletStores
import com.tangem.tap.domain.walletStores.repository.implementation.utils.updateWithAmounts
import com.tangem.tap.domain.walletStores.repository.implementation.utils.updateWithDemoAmounts
import com.tangem.tap.domain.walletStores.repository.implementation.utils.updateWithError
import com.tangem.tap.domain.walletStores.repository.implementation.utils.updateWithFiatRates
import com.tangem.tap.domain.walletStores.repository.implementation.utils.updateWithMissedDerivation
@ -34,6 +35,7 @@ import com.tangem.tap.domain.walletStores.repository.implementation.utils.update
import com.tangem.tap.domain.walletStores.repository.implementation.utils.updateWithUnreachable
import com.tangem.tap.domain.walletStores.storage.WalletManagerStorage
import com.tangem.tap.domain.walletStores.storage.WalletStoresStorage
import com.tangem.tap.features.demo.DemoHelper
import com.tangem.tap.features.wallet.models.PendingTransactionType
import com.tangem.tap.features.wallet.models.filterByCoin
import com.tangem.tap.features.wallet.models.getPendingTransactions
@ -207,6 +209,8 @@ internal class DefaultWalletAmountsRepository(
updateWalletStoreWithAmounts(
walletStore = walletStore,
updatedWallet = walletManager.wallet,
// fixme move DemoHelper to Demo core module maybe
isDemo = DemoHelper.isDemoCardId(scanResponse.card.cardId),
)
}
.flatMap { fetchWalletStoreRentIfNeeded(walletStore, walletManager) }
@ -296,6 +300,7 @@ internal class DefaultWalletAmountsRepository(
private suspend fun updateWalletStoreWithAmounts(
walletStore: WalletStoreModel,
updatedWallet: Wallet,
isDemo: Boolean,
) = withContext(Dispatchers.Default) {
Timber.d(
"""
@ -309,7 +314,11 @@ internal class DefaultWalletAmountsRepository(
prevState.replaceWalletStore(
walletStoreToUpdate = walletStore,
update = {
it.updateWithAmounts(wallet = updatedWallet)
if (isDemo) {
it.updateWithDemoAmounts(wallet = updatedWallet)
} else {
it.updateWithAmounts(wallet = updatedWallet)
}
},
)
}

View file

@ -7,6 +7,7 @@ import com.tangem.common.core.TangemError
import com.tangem.tap.domain.extensions.amountToCreateAccount
import com.tangem.tap.domain.getFirstToken
import com.tangem.tap.domain.model.WalletDataModel
import com.tangem.tap.features.demo.DemoHelper
import com.tangem.tap.features.wallet.models.Currency
import com.tangem.tap.features.wallet.models.getPendingTransactions
import java.math.BigDecimal
@ -74,12 +75,25 @@ internal fun WalletDataModel.updateWithAmount(wallet: Wallet): WalletDataModel {
)
}
internal fun WalletDataModel.updateWithDemoAmount(wallet: Wallet): WalletDataModel {
val amount = DemoHelper.config.getBalance(wallet.blockchain)
return this.copy(
status = WalletDataModel.VerifiedOnline(amount = amount.value ?: BigDecimal.ZERO),
)
}
internal fun List<WalletDataModel>.updateWithAmounts(wallet: Wallet): List<WalletDataModel> {
return this.map { walletData ->
walletData.updateWithAmount(wallet)
}
}
internal fun List<WalletDataModel>.updateWithDemoAmounts(wallet: Wallet): List<WalletDataModel> {
return this.map { walletData ->
walletData.updateWithDemoAmount(wallet)
}
}
internal fun WalletDataModel.updateWithError(
wallet: Wallet,
error: TangemError,

View file

@ -49,6 +49,14 @@ internal fun WalletStoreModel.updateWithAmounts(
)
}
internal fun WalletStoreModel.updateWithDemoAmounts(
wallet: Wallet,
): WalletStoreModel {
return this.copy(
walletsData = walletsData.updateWithDemoAmounts(wallet = wallet),
)
}
internal fun WalletStoreModel.updateWithFiatRates(
rates: Map<String, Double>,
): WalletStoreModel {