Skip to content

Commit

Permalink
Show tx details in Ton Connect tx confirming
Browse files Browse the repository at this point in the history
  • Loading branch information
abdrasulov committed Dec 18, 2024
1 parent 6262418 commit 697285f
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 115 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,8 @@ object TonHelper {
action: TonTransactionRecord.Action,
rates: Map<String, CurrencyValue>,
blockchainType: BlockchainType,
hideAmount: Boolean
hideAmount: Boolean,
showHistoricalRate: Boolean
): List<TransactionInfoViewItem> {

val itemsForAction = mutableListOf<TransactionInfoViewItem>()
Expand All @@ -172,6 +173,7 @@ object TonHelper {
hideAmount = hideAmount,
sentToSelf = actionType.sentToSelf,
blockchainType = blockchainType,
showHistoricalRate = showHistoricalRate
)
)
actionType.comment?.let {
Expand All @@ -192,6 +194,7 @@ object TonHelper {
coinPrice = rates[actionType.value.coinUid],
hideAmount = hideAmount,
blockchainType = blockchainType,
showHistoricalRate = showHistoricalRate
)
)
actionType.comment?.let {
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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<List<TransactionInfoViewItem>> = listOf()

private var currency = App.currencyManager.baseCurrency

private var tonWallet: TonWallet.FullAccess? = null
Expand All @@ -41,7 +45,8 @@ class TonConnectSendRequestViewModel(
currency = currency,
error = error,
confirmEnabled = sendRequestEntity != null && tonWallet != null,
rejectEnabled = sendRequestEntity != null
rejectEnabled = sendRequestEntity != null,
itemSections = itemSections
)

init {
Expand Down Expand Up @@ -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(
Expand All @@ -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() {
Expand Down Expand Up @@ -125,4 +137,5 @@ data class TonConnectSendRequestUiState(
val error: TonConnectSendRequestError?,
val confirmEnabled: Boolean,
val rejectEnabled: Boolean,
val itemSections: List<List<TransactionInfoViewItem>>,
)
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,7 @@ object TransactionViewItemFactoryHelper {
hideAmount: Boolean,
nftMetadata: Map<NftUid, NftAssetBriefMetadata> = mapOf(),
blockchainType: BlockchainType,
showHistoricalRate: Boolean = true
): List<TransactionInfoViewItem> {
val mint = fromAddress == zeroAddress
val title: String =
Expand All @@ -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)
}
}
Expand All @@ -283,7 +285,9 @@ object TransactionViewItemFactoryHelper {
}
}

rate?.let { items.add(it) }
if (showHistoricalRate) {
rate?.let { items.add(it) }
}

return items
}
Expand All @@ -297,6 +301,7 @@ object TransactionViewItemFactoryHelper {
sentToSelf: Boolean = false,
nftMetadata: Map<NftUid, NftAssetBriefMetadata> = mapOf(),
blockchainType: BlockchainType,
showHistoricalRate: Boolean = true
): List<TransactionInfoViewItem> {
val burn = toAddress == zeroAddress

Expand Down Expand Up @@ -349,7 +354,9 @@ object TransactionViewItemFactoryHelper {
}
}

rate?.let { items.add(it) }
if (showHistoricalRate) {
rate?.let { items.add(it) }
}

return items
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -738,6 +738,7 @@
<string name="TransactionInfo_YouGot">You Got</string>
<string name="TransactionInfo_YouSent">You Sent</string>
<string name="TransactionInfo_Received">Received</string>
<string name="TransactionInfo_Minted">Minted</string>
<string name="TransactionInfo_Sent">Sent</string>
<string name="TransactionInfo_Approved">Approved</string>
<string name="TransactionInfo_SpeedUp">Speed Up</string>
Expand Down

0 comments on commit 697285f

Please sign in to comment.