From 5e7664ce74977a87209c6cd8fbfaea1ae22d4fce Mon Sep 17 00:00:00 2001 From: abdrasulov Date: Wed, 18 Dec 2024 16:15:12 +0600 Subject: [PATCH 1/2] Show ContractCall and ContractDeploy actions in Tx Info --- .../bankwallet/core/managers/TonKitManager.kt | 48 ++++++++++++++----- .../TransactionInfoFragment.kt | 7 ++- 2 files changed, 42 insertions(+), 13 deletions(-) diff --git a/app/src/main/java/io/horizontalsystems/bankwallet/core/managers/TonKitManager.kt b/app/src/main/java/io/horizontalsystems/bankwallet/core/managers/TonKitManager.kt index 3fac447cfc..09ce8941db 100644 --- a/app/src/main/java/io/horizontalsystems/bankwallet/core/managers/TonKitManager.kt +++ b/app/src/main/java/io/horizontalsystems/bankwallet/core/managers/TonKitManager.kt @@ -6,6 +6,7 @@ import io.horizontalsystems.bankwallet.core.App import io.horizontalsystems.bankwallet.core.UnsupportedAccountException import io.horizontalsystems.bankwallet.core.adapters.TonTransactionRecord import io.horizontalsystems.bankwallet.core.providers.Translator +import io.horizontalsystems.bankwallet.core.stats.StatSection import io.horizontalsystems.bankwallet.entities.Account import io.horizontalsystems.bankwallet.entities.AccountType import io.horizontalsystems.bankwallet.entities.CurrencyValue @@ -14,6 +15,7 @@ import io.horizontalsystems.bankwallet.modules.transactionInfo.TransactionInfoVi import io.horizontalsystems.bankwallet.modules.transactionInfo.TransactionInfoViewItem.Value import io.horizontalsystems.bankwallet.modules.transactionInfo.TransactionViewItemFactoryHelper import io.horizontalsystems.bankwallet.modules.transactions.TransactionStatus +import io.horizontalsystems.bankwallet.modules.transactions.TransactionViewItem import io.horizontalsystems.core.BackgroundManager import io.horizontalsystems.core.BackgroundManagerState import io.horizontalsystems.hdwalletkit.Curve @@ -240,20 +242,44 @@ object TonHelper { } is TonTransactionRecord.Action.Type.ContractDeploy -> { -// case let .contractDeploy(interfaces): -// viewItems = [ -// .actionTitle(iconName: nil, iconDimmed: false, title: "transactions.contract_deploy".localized, subTitle: interfaces.joined(separator: ", ")), -// ] + itemsForAction.add( + TransactionInfoViewItem.Transaction( + leftValue = Translator.getString(R.string.Transactions_ContractDeploy), + rightValue = actionType.interfaces.joinToString(), + icon = null, + ) + ) + } is TonTransactionRecord.Action.Type.ContractCall -> { -// case let .contractCall(address, value, operation): -// viewItems = [ -// .actionTitle(iconName: record.source.blockchainType.iconPlain32, iconDimmed: false, title: "transactions.contract_call".localized, subTitle: operation), -// .to(value: address, valueTitle: nil, contactAddress: nil) -// ] -// -// viewItems.append(contentsOf: sendSection(source: record.source, transactionValue: value, to: nil, rates: item.rates, balanceHidden: balanceHidden)) + itemsForAction.add( + TransactionInfoViewItem.Transaction( + leftValue = Translator.getString(R.string.Transactions_ContractCall), + rightValue = actionType.operation, + icon = TransactionViewItem.Icon.Platform(blockchainType).iconRes, + ) + ) + + itemsForAction.add( + TransactionInfoViewItem.Address( + Translator.getString(R.string.TransactionInfo_To), + actionType.address, + false, + blockchainType, + StatSection.AddressTo + ) + ) + + itemsForAction.addAll( + TransactionViewItemFactoryHelper.getSendSectionItems( + value = actionType.value, + toAddress = null, + coinPrice = rates[actionType.value.coinUid], + hideAmount = hideAmount, + blockchainType = blockchainType, + ) + ) } is TonTransactionRecord.Action.Type.Unsupported -> { diff --git a/app/src/main/java/io/horizontalsystems/bankwallet/modules/transactionInfo/TransactionInfoFragment.kt b/app/src/main/java/io/horizontalsystems/bankwallet/modules/transactionInfo/TransactionInfoFragment.kt index 7e2b85b0c3..e0f37cbfe0 100644 --- a/app/src/main/java/io/horizontalsystems/bankwallet/modules/transactionInfo/TransactionInfoFragment.kt +++ b/app/src/main/java/io/horizontalsystems/bankwallet/modules/transactionInfo/TransactionInfoFragment.kt @@ -287,8 +287,11 @@ fun TransactionInfoSection( } } - else -> { - //do nothing + is TransactionInfoViewItem.Description -> { + + } + is TransactionInfoViewItem.WarningMessage -> { + } } } From f98271f9042b942e0d6e1c361a9b43604ab6b849 Mon Sep 17 00:00:00 2001 From: abdrasulov Date: Wed, 18 Dec 2024 17:12:07 +0600 Subject: [PATCH 2/2] Show tx details in Ton Connect tx confirming --- .../bankwallet/core/managers/TonKitManager.kt | 5 +- .../tonconnect/TonConnectSendRequestScreen.kt | 111 +----------------- .../TonConnectSendRequestViewModel.kt | 17 ++- .../TransactionInfoViewItem.kt | 2 +- .../TransactionInfoViewItemFactory.kt | 8 +- .../TransactionViewItemFactoryHelper.kt | 13 +- .../components/TransactionInfoCells.kt | 1 + app/src/main/res/values/strings.xml | 1 + 8 files changed, 43 insertions(+), 115 deletions(-) diff --git a/app/src/main/java/io/horizontalsystems/bankwallet/core/managers/TonKitManager.kt b/app/src/main/java/io/horizontalsystems/bankwallet/core/managers/TonKitManager.kt index 09ce8941db..d4194818e6 100644 --- a/app/src/main/java/io/horizontalsystems/bankwallet/core/managers/TonKitManager.kt +++ b/app/src/main/java/io/horizontalsystems/bankwallet/core/managers/TonKitManager.kt @@ -157,7 +157,8 @@ object TonHelper { action: TonTransactionRecord.Action, rates: Map, blockchainType: BlockchainType, - hideAmount: Boolean + hideAmount: Boolean, + showHistoricalRate: Boolean ): List { val itemsForAction = mutableListOf() @@ -172,6 +173,7 @@ object TonHelper { hideAmount = hideAmount, sentToSelf = actionType.sentToSelf, blockchainType = blockchainType, + showHistoricalRate = showHistoricalRate ) ) actionType.comment?.let { @@ -192,6 +194,7 @@ object TonHelper { coinPrice = rates[actionType.value.coinUid], hideAmount = hideAmount, blockchainType = blockchainType, + showHistoricalRate = showHistoricalRate ) ) actionType.comment?.let { diff --git a/app/src/main/java/io/horizontalsystems/bankwallet/modules/tonconnect/TonConnectSendRequestScreen.kt b/app/src/main/java/io/horizontalsystems/bankwallet/modules/tonconnect/TonConnectSendRequestScreen.kt index 452e9fbd65..2391db3e09 100644 --- a/app/src/main/java/io/horizontalsystems/bankwallet/modules/tonconnect/TonConnectSendRequestScreen.kt +++ b/app/src/main/java/io/horizontalsystems/bankwallet/modules/tonconnect/TonConnectSendRequestScreen.kt @@ -1,11 +1,7 @@ package io.horizontalsystems.bankwallet.modules.tonconnect import androidx.activity.ComponentActivity -import androidx.compose.animation.Crossfade -import androidx.compose.foundation.layout.Column -import androidx.compose.foundation.layout.Spacer import androidx.compose.foundation.layout.fillMaxWidth -import androidx.compose.foundation.layout.height import androidx.compose.runtime.Composable import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableStateOf @@ -22,23 +18,13 @@ import androidx.navigation.NavController import io.horizontalsystems.bankwallet.R import io.horizontalsystems.bankwallet.core.App import io.horizontalsystems.bankwallet.core.AppLogger -import io.horizontalsystems.bankwallet.core.adapters.TonTransactionRecord -import io.horizontalsystems.bankwallet.modules.amount.AmountInputType import io.horizontalsystems.bankwallet.modules.confirm.ConfirmTransactionScreen -import io.horizontalsystems.bankwallet.modules.fee.HSFeeRaw import io.horizontalsystems.bankwallet.modules.main.MainActivityViewModel -import io.horizontalsystems.bankwallet.modules.multiswap.TokenRowPure -import io.horizontalsystems.bankwallet.ui.compose.ComposeAppTheme +import io.horizontalsystems.bankwallet.modules.transactionInfo.TransactionInfoSection import io.horizontalsystems.bankwallet.ui.compose.components.ButtonPrimaryDefault import io.horizontalsystems.bankwallet.ui.compose.components.ButtonPrimaryYellow -import io.horizontalsystems.bankwallet.ui.compose.components.CellUniversalLawrenceSection -import io.horizontalsystems.bankwallet.ui.compose.components.HFillSpacer import io.horizontalsystems.bankwallet.ui.compose.components.TextImportantError import io.horizontalsystems.bankwallet.ui.compose.components.VSpacer -import io.horizontalsystems.bankwallet.ui.compose.components.cell.CellUniversal -import io.horizontalsystems.bankwallet.ui.compose.components.cell.SectionUniversalLawrence -import io.horizontalsystems.bankwallet.ui.compose.components.subhead1_leah -import io.horizontalsystems.bankwallet.ui.compose.components.subhead2_grey import io.horizontalsystems.core.SnackbarDuration import io.horizontalsystems.core.helpers.HudHelper import kotlinx.coroutines.delay @@ -113,98 +99,9 @@ fun TonConnectSendRequestScreen(navController: NavController) { TextImportantError(text = error.message ?: error.javaClass.simpleName) } - Crossfade(uiState.tonTransactionRecord) { transactionRecord -> - Column { - if (transactionRecord != null) { - SectionUniversalLawrence { - transactionRecord.actions.forEach { action -> - when (val actionType = action.type) { - is TonTransactionRecord.Action.Type.Swap -> { - val valueIn = actionType.valueIn - val valueInDecimalValue = valueIn.decimalValue - val valueInDecimals = valueIn.decimals - val amountFormatted = if (valueInDecimalValue != null && valueInDecimals != null) { - App.numberFormatter.formatCoinFull( - valueInDecimalValue.abs(), - valueIn.coinCode, - valueInDecimals - ) - } else { - null - } - TokenRowPure( - fiatAmount = null, - borderTop = false, - currency = uiState.currency, - title = stringResource(R.string.Send_Confirmation_YouSend), - amountColor = ComposeAppTheme.colors.leah, - imageUrl = valueIn.coinIconUrl, - alternativeImageUrl = valueIn.alternativeCoinIconUrl, - imagePlaceholder = valueIn.coinIconPlaceholder, - badge = valueIn.badge, - amountFormatted = amountFormatted - ) - - val valueOut = actionType.valueOut - val valueOutDecimalValue = valueOut.decimalValue - val valueOutDecimals = valueOut.decimals - val valueOutAmountFormatted = if (valueOutDecimalValue != null && valueOutDecimals != null) { - App.numberFormatter.formatCoinFull( - valueOutDecimalValue, - valueOut.coinCode, - valueOutDecimals - ) - } else { - null - } - - TokenRowPure( - fiatAmount = null, - currency = uiState.currency, - title = stringResource(R.string.Swap_ToAmountTitle), - amountColor = ComposeAppTheme.colors.remus, - imageUrl = valueOut.coinIconUrl, - alternativeImageUrl = valueOut.alternativeCoinIconUrl, - imagePlaceholder = valueOut.coinIconPlaceholder, - badge = valueOut.badge, - amountFormatted = valueOutAmountFormatted, - ) - } -// is TonTransactionRecord.Action.Type.Burn -> {} -// is TonTransactionRecord.Action.Type.ContractCall -> {} -// is TonTransactionRecord.Action.Type.ContractDeploy -> {} -// is TonTransactionRecord.Action.Type.Mint -> {} -// is TonTransactionRecord.Action.Type.Receive -> {} -// is TonTransactionRecord.Action.Type.Send -> {} -// is TonTransactionRecord.Action.Type.Unsupported -> {} - else -> { - CellUniversal(borderTop = false) { - subhead2_grey(text = stringResource(R.string.Send_Confirmation_Action)) - HFillSpacer(minWidth = 16.dp) - subhead1_leah(text = actionType.javaClass.simpleName) - } - } - } - } - } - - Spacer(modifier = Modifier.height(28.dp)) - - val fee = transactionRecord.fee - CellUniversalLawrenceSection( - listOf { - HSFeeRaw( - coinCode = fee.coinCode, - coinDecimal = fee.decimals, - fee = fee.value, - amountInputType = AmountInputType.COIN, - rate = null, - navController = navController - ) - } - ) - } - } + uiState.itemSections.forEach { items -> + TransactionInfoSection(items, navController, { null }) + VSpacer(12.dp) } } } diff --git a/app/src/main/java/io/horizontalsystems/bankwallet/modules/tonconnect/TonConnectSendRequestViewModel.kt b/app/src/main/java/io/horizontalsystems/bankwallet/modules/tonconnect/TonConnectSendRequestViewModel.kt index 34dfcbb9f4..eaec8d75ed 100644 --- a/app/src/main/java/io/horizontalsystems/bankwallet/modules/tonconnect/TonConnectSendRequestViewModel.kt +++ b/app/src/main/java/io/horizontalsystems/bankwallet/modules/tonconnect/TonConnectSendRequestViewModel.kt @@ -7,10 +7,12 @@ import io.horizontalsystems.bankwallet.core.IAccountManager import io.horizontalsystems.bankwallet.core.ViewModelUiState import io.horizontalsystems.bankwallet.core.adapters.TonTransactionRecord import io.horizontalsystems.bankwallet.core.managers.TonConnectManager +import io.horizontalsystems.bankwallet.core.managers.TonHelper import io.horizontalsystems.bankwallet.core.managers.TonKitWrapper import io.horizontalsystems.bankwallet.core.managers.toTonWalletFullAccess import io.horizontalsystems.bankwallet.core.meta import io.horizontalsystems.bankwallet.entities.Currency +import io.horizontalsystems.bankwallet.modules.transactionInfo.TransactionInfoViewItem import io.horizontalsystems.bankwallet.modules.transactions.TransactionSource import io.horizontalsystems.marketkit.models.BlockchainType import io.horizontalsystems.marketkit.models.TokenQuery @@ -30,6 +32,8 @@ class TonConnectSendRequestViewModel( private val transactionSigner = tonConnectManager.transactionSigner private val tonConnectKit = App.tonConnectManager.kit private var tonTransactionRecord: TonTransactionRecord? = null + private var itemSections: List> = listOf() + private var currency = App.currencyManager.baseCurrency private var tonWallet: TonWallet.FullAccess? = null @@ -41,7 +45,8 @@ class TonConnectSendRequestViewModel( currency = currency, error = error, confirmEnabled = sendRequestEntity != null && tonWallet != null, - rejectEnabled = sendRequestEntity != null + rejectEnabled = sendRequestEntity != null, + itemSections = itemSections ) init { @@ -81,7 +86,7 @@ class TonConnectSendRequestViewModel( error = TonConnectSendRequestError.Other("Token Ton not found") return } - + val transactionSource = TransactionSource(token.blockchain, account, token.type.meta) val tonTransactionConverter = tonConnectManager.adapterFactory.tonTransactionConverter( @@ -90,6 +95,13 @@ class TonConnectSendRequestViewModel( ) tonTransactionRecord = tonTransactionConverter?.createTransactionRecord(tonEvent) + + tonTransactionRecord?.let { + itemSections = it.actions.map { action -> + TonHelper.getViewItemsForAction(action, mapOf(), BlockchainType.Ton, false, showHistoricalRate = false) + } + } + } fun confirm() { @@ -125,4 +137,5 @@ data class TonConnectSendRequestUiState( val error: TonConnectSendRequestError?, val confirmEnabled: Boolean, val rejectEnabled: Boolean, + val itemSections: List>, ) diff --git a/app/src/main/java/io/horizontalsystems/bankwallet/modules/transactionInfo/TransactionInfoViewItem.kt b/app/src/main/java/io/horizontalsystems/bankwallet/modules/transactionInfo/TransactionInfoViewItem.kt index 20f9e7797f..de8e7c3e83 100644 --- a/app/src/main/java/io/horizontalsystems/bankwallet/modules/transactionInfo/TransactionInfoViewItem.kt +++ b/app/src/main/java/io/horizontalsystems/bankwallet/modules/transactionInfo/TransactionInfoViewItem.kt @@ -61,7 +61,7 @@ sealed class TransactionInfoViewItem { } enum class AmountType { - YouSent, YouGot, Received, Sent, Approved; + YouSent, YouGot, Received, Sent, Approved, Minted; } data class ColoredValue(val value: String, val color: ColorName) diff --git a/app/src/main/java/io/horizontalsystems/bankwallet/modules/transactionInfo/TransactionInfoViewItemFactory.kt b/app/src/main/java/io/horizontalsystems/bankwallet/modules/transactionInfo/TransactionInfoViewItemFactory.kt index e16d043d0e..1436401797 100644 --- a/app/src/main/java/io/horizontalsystems/bankwallet/modules/transactionInfo/TransactionInfoViewItemFactory.kt +++ b/app/src/main/java/io/horizontalsystems/bankwallet/modules/transactionInfo/TransactionInfoViewItemFactory.kt @@ -61,7 +61,13 @@ class TransactionInfoViewItemFactory( is TonTransactionRecord -> { transaction.actions.forEach { action -> itemSections.add( - TonHelper.getViewItemsForAction(action, rates, blockchainType, transactionItem.hideAmount) + TonHelper.getViewItemsForAction( + action, + rates, + blockchainType, + transactionItem.hideAmount, + true + ) ) } diff --git a/app/src/main/java/io/horizontalsystems/bankwallet/modules/transactionInfo/TransactionViewItemFactoryHelper.kt b/app/src/main/java/io/horizontalsystems/bankwallet/modules/transactionInfo/TransactionViewItemFactoryHelper.kt index e2271b5ba4..e83cb18ae2 100644 --- a/app/src/main/java/io/horizontalsystems/bankwallet/modules/transactionInfo/TransactionViewItemFactoryHelper.kt +++ b/app/src/main/java/io/horizontalsystems/bankwallet/modules/transactionInfo/TransactionViewItemFactoryHelper.kt @@ -241,6 +241,7 @@ object TransactionViewItemFactoryHelper { hideAmount: Boolean, nftMetadata: Map = mapOf(), blockchainType: BlockchainType, + showHistoricalRate: Boolean = true ): List { val mint = fromAddress == zeroAddress val title: String = @@ -256,7 +257,8 @@ object TransactionViewItemFactoryHelper { } else -> { - amount = getAmount(coinPrice, value, true, hideAmount, AmountType.Received) + val amountType = if (mint) AmountType.Minted else AmountType.Received + amount = getAmount(coinPrice, value, true, hideAmount, amountType) rate = getHistoricalRate(coinPrice, value) } } @@ -283,7 +285,9 @@ object TransactionViewItemFactoryHelper { } } - rate?.let { items.add(it) } + if (showHistoricalRate) { + rate?.let { items.add(it) } + } return items } @@ -297,6 +301,7 @@ object TransactionViewItemFactoryHelper { sentToSelf: Boolean = false, nftMetadata: Map = mapOf(), blockchainType: BlockchainType, + showHistoricalRate: Boolean = true ): List { val burn = toAddress == zeroAddress @@ -349,7 +354,9 @@ object TransactionViewItemFactoryHelper { } } - rate?.let { items.add(it) } + if (showHistoricalRate) { + rate?.let { items.add(it) } + } return items } diff --git a/app/src/main/java/io/horizontalsystems/bankwallet/ui/compose/components/TransactionInfoCells.kt b/app/src/main/java/io/horizontalsystems/bankwallet/ui/compose/components/TransactionInfoCells.kt index 06f477b1b5..6b00855a9d 100644 --- a/app/src/main/java/io/horizontalsystems/bankwallet/ui/compose/components/TransactionInfoCells.kt +++ b/app/src/main/java/io/horizontalsystems/bankwallet/ui/compose/components/TransactionInfoCells.kt @@ -170,6 +170,7 @@ fun TransactionAmountCell( AmountType.Received -> stringResource(R.string.TransactionInfo_Received) AmountType.Sent -> stringResource(R.string.TransactionInfo_Sent) AmountType.Approved -> stringResource(R.string.TransactionInfo_Approved) + AmountType.Minted -> stringResource(R.string.TransactionInfo_Minted) } RowUniversal( modifier = Modifier.padding(horizontal = 16.dp), diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 03a3891647..bac837663a 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -738,6 +738,7 @@ You Got You Sent Received + Minted Sent Approved Speed Up