diff --git a/app/src/main/java/com/tangem/tap/domain/walletStores/repository/implementation/DefaultWalletAmountsRepository.kt b/app/src/main/java/com/tangem/tap/domain/walletStores/repository/implementation/DefaultWalletAmountsRepository.kt index 444d6fc480..93c70be9ef 100644 --- a/app/src/main/java/com/tangem/tap/domain/walletStores/repository/implementation/DefaultWalletAmountsRepository.kt +++ b/app/src/main/java/com/tangem/tap/domain/walletStores/repository/implementation/DefaultWalletAmountsRepository.kt @@ -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) + } }, ) } diff --git a/app/src/main/java/com/tangem/tap/domain/walletStores/repository/implementation/utils/WalletDataOperations.kt b/app/src/main/java/com/tangem/tap/domain/walletStores/repository/implementation/utils/WalletDataOperations.kt index 64e2241737..dc1765ac47 100644 --- a/app/src/main/java/com/tangem/tap/domain/walletStores/repository/implementation/utils/WalletDataOperations.kt +++ b/app/src/main/java/com/tangem/tap/domain/walletStores/repository/implementation/utils/WalletDataOperations.kt @@ -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.updateWithAmounts(wallet: Wallet): List { return this.map { walletData -> walletData.updateWithAmount(wallet) } } +internal fun List.updateWithDemoAmounts(wallet: Wallet): List { + return this.map { walletData -> + walletData.updateWithDemoAmount(wallet) + } +} + internal fun WalletDataModel.updateWithError( wallet: Wallet, error: TangemError, diff --git a/app/src/main/java/com/tangem/tap/domain/walletStores/repository/implementation/utils/WalletStoreOperations.kt b/app/src/main/java/com/tangem/tap/domain/walletStores/repository/implementation/utils/WalletStoreOperations.kt index 0e9e9d8715..6679dc7a1d 100644 --- a/app/src/main/java/com/tangem/tap/domain/walletStores/repository/implementation/utils/WalletStoreOperations.kt +++ b/app/src/main/java/com/tangem/tap/domain/walletStores/repository/implementation/utils/WalletStoreOperations.kt @@ -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, ): WalletStoreModel {