From 6f80bdb6367fc60a5047cc9e2a5bbcff677e6c42 Mon Sep 17 00:00:00 2001 From: Tangem Date: Mon, 26 Aug 2024 18:17:33 +0300 Subject: [PATCH] Updated on 2026-08-14 --- .../sdk/mocks/content/WalletMockContent.kt | 11 +++++++ .../presentation/state/fee/FeeStateFactory.kt | 29 ++++++++++++++++--- 2 files changed, 36 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/com/tangem/tap/domain/sdk/mocks/content/WalletMockContent.kt b/app/src/main/java/com/tangem/tap/domain/sdk/mocks/content/WalletMockContent.kt index 8e059f5450..6168bdda1f 100644 --- a/app/src/main/java/com/tangem/tap/domain/sdk/mocks/content/WalletMockContent.kt +++ b/app/src/main/java/com/tangem/tap/domain/sdk/mocks/content/WalletMockContent.kt @@ -111,6 +111,10 @@ object WalletMockContent : MockContent { publicKey = byteArrayOf(2, -40, 115, -15, 80, 104, 100, -29, 80, 29, 112, -35, -54, 64, -98, 45, 115, 108, 93, 113, -71, 89, 17, 72, 98, 21, 126, 82, -50, 50, -12, -87, -62), chainCode = byteArrayOf(-27, 56, 57, 54, 27, -40, 65, 109, 119, -54, -94, 88, -29, -115, -45, -112, -31, 57, 53, 56, 118, 87, 34, -16, -64, -45, 105, 77, 91, -106, -92, 41), ), + DerivationPath("m/44'/195'/0'/0/0") to ExtendedPublicKey( + publicKey = byteArrayOf(2, -40, 115, -15, 80, 104, 100, -29, 80, 29, 112, -35, -54, 64, -98, 45, 115, 108, 93, 113, -71, 89, 17, 72, 98, 21, 126, 82, -50, 50, -12, -87, -62), + chainCode = byteArrayOf(-27, 56, 57, 54, 27, -40, 65, 109, 119, -54, -94, 88, -29, -115, -45, -112, -31, 57, 53, 56, 118, 87, 34, -16, -64, -45, 105, 77, 91, -106, -92, 41), + ), ), extendedPublicKey = ExtendedPublicKey( publicKey = byteArrayOf(2, -109, 28, -27, -124, -58, -97, -61, 43, -84, 90, -9, -5, 4, 90, 17, 112, -125, -108, 44, 19, -79, -60, -23, 34, -20, -20, 61, 84, 113, 120, -90, -5), @@ -189,6 +193,13 @@ object WalletMockContent : MockContent { parentFingerprint = byteArrayOf(0, 0, 0, 0), childNumber = 0, ), + DerivationPath("m/44'/195'/0'/0/0") to ExtendedPublicKey( + publicKey = byteArrayOf(2, -40, 115, -15, 80, 104, 100, -29, 80, 29, 112, -35, -54, 64, -98, 45, 115, 108, 93, 113, -71, 89, 17, 72, 98, 21, 126, 82, -50, 50, -12, -87, -62), + chainCode = byteArrayOf(-27, 56, 57, 54, 27, -40, 65, 109, 119, -54, -94, 88, -29, -115, -45, -112, -31, 57, 53, 56, 118, 87, 34, -16, -64, -45, 105, 77, 91, -106, -92, 41), + depth = 0, + parentFingerprint = byteArrayOf(0, 0, 0, 0), + childNumber = 0, + ), ), ), ), diff --git a/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/state/fee/FeeStateFactory.kt b/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/state/fee/FeeStateFactory.kt index 3a30e424b9..3ff511170b 100644 --- a/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/state/fee/FeeStateFactory.kt +++ b/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/state/fee/FeeStateFactory.kt @@ -1,10 +1,12 @@ package com.tangem.features.send.impl.presentation.state.fee -import com.tangem.blockchain.common.transaction.Fee +import com.tangem.blockchain.common.Token import com.tangem.blockchain.common.transaction.TransactionFee import com.tangem.common.extensions.isZero +import com.tangem.common.ui.amountScreen.models.AmountState import com.tangem.core.ui.utils.parseToBigDecimal import com.tangem.domain.appcurrency.model.AppCurrency +import com.tangem.domain.tokens.model.AmountType import com.tangem.domain.tokens.model.CryptoCurrencyStatus import com.tangem.domain.transaction.usecase.IsFeeApproximateUseCase import com.tangem.features.send.impl.presentation.state.SendNotification @@ -15,6 +17,7 @@ import com.tangem.features.send.impl.presentation.viewmodel.SendClickIntents import com.tangem.utils.Provider import kotlinx.collections.immutable.ImmutableList import kotlinx.collections.immutable.persistentListOf +import com.tangem.blockchain.common.AmountType as SdkAmountType /** * Factory to produce fee state for [SendUiState] @@ -94,7 +97,7 @@ internal class FeeStateFactory( feeState = feeState.copy( feeSelectorState = updatedFeeSelectorState, fee = fee, - isFeeApproximate = isFeeApproximate(fee), + isFeeApproximate = isFeeApproximate(state.amountState), ), ) } @@ -180,11 +183,29 @@ internal class FeeStateFactory( return noErrors && (isNotEmptyCustom || isNotCustom) } - private fun isFeeApproximate(fee: Fee): Boolean { + private fun isFeeApproximate(state: AmountState): Boolean { val cryptoCurrencyStatus = feeCryptoCurrencyStatusProvider() ?: return false + val amount = (state as? AmountState.Data)?.amountTextField?.cryptoAmount ?: return false return isFeeApproximateUseCase( networkId = cryptoCurrencyStatus.currency.network.id, - amountType = fee.amount.type, + amountType = amount.type.toSdkAmountType(), ) } + + private fun AmountType.toSdkAmountType(): SdkAmountType { + return when (this) { + AmountType.CoinType -> SdkAmountType.Coin + is AmountType.FiatType -> error("unsupported type FiatType") + AmountType.ReserveType -> SdkAmountType.Reserve + is AmountType.TokenType -> SdkAmountType.Token( + Token( + name = this.token.name, + symbol = this.token.symbol, + contractAddress = this.token.contractAddress, + decimals = this.token.decimals, + id = this.token.id.rawCurrencyId, + ), + ) + } + } } \ No newline at end of file