Skip to content

Commit

Permalink
Clean up redundant code
Browse files Browse the repository at this point in the history
  • Loading branch information
abdrasulov committed Dec 23, 2024
1 parent 31b51dd commit 2ee4d54
Show file tree
Hide file tree
Showing 2 changed files with 91 additions and 107 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,7 @@ fun TonConnectSendRequestScreen(navController: NavController) {
TonConnectSendRequestViewModel(
sendRequestEntity,
App.accountManager,
App.tonConnectManager,
App.marketKit,
App.currencyManager
App.tonConnectManager
)
})

Expand Down Expand Up @@ -132,85 +130,12 @@ fun TonConnectSendRequestScreen(navController: NavController) {
if (index != 0) {
VSpacer(12.dp)
}
when (val actionType = action.type) {
is TonTransactionRecord.Action.Type.Burn -> {
XxxBurnSection(
transactionValue = actionType.value,
transactionInfoHelper = transactionInfoHelper,
navController = navController
)
}

is TonTransactionRecord.Action.Type.ContractCall -> {
XxxContractCallSection(
navController = navController,
operation = actionType.operation,
address = actionType.address,
transactionValue = actionType.value,
transactionInfoHelper = transactionInfoHelper
)
}

is TonTransactionRecord.Action.Type.ContractDeploy -> {
XxxContractDeploySection(
interfaces = actionType.interfaces
)
}

is TonTransactionRecord.Action.Type.Mint -> {
XxxMintSection(
transactionValue = actionType.value,
transactionInfoHelper = transactionInfoHelper,
navController = navController
)
}

is TonTransactionRecord.Action.Type.Receive -> {
XxxReceiveCoinSection(
transactionValue = actionType.value,
address = actionType.from,
comment = actionType.comment,
statPage = StatPage.TonConnect,
navController = navController,
transactionInfoHelper = transactionInfoHelper,
blockchainType = BlockchainType.Ton
)
}

is TonTransactionRecord.Action.Type.Send -> {
XxxSendCoinSection(
transactionValue = actionType.value,
address = actionType.to,
comment = actionType.comment,
sentToSelf = actionType.sentToSelf,
statPage = StatPage.TonConnect,
navController = navController,
transactionInfoHelper = transactionInfoHelper,
blockchainType = BlockchainType.Ton
)
}

is TonTransactionRecord.Action.Type.Swap -> {
XxxSwapSection(
transactionInfoHelper = transactionInfoHelper,
navController = navController,
transactionValueIn = actionType.valueIn,
transactionValueOut = actionType.valueOut
)
}

is TonTransactionRecord.Action.Type.Unsupported -> {
SectionUniversalLawrence {
XxxSectionHeaderCell(
title = stringResource(R.string.Send_Confirmation_Action),
value = actionType.type,
painter = null
)
}
}
}
TonConnectRequestActionSection(
action = action,
transactionInfoHelper = transactionInfoHelper,
navController = navController
)
}

VSpacer(12.dp)

XxxFeeSection(
Expand All @@ -221,10 +146,90 @@ fun TonConnectSendRequestScreen(navController: NavController) {
}
}
}
}
}

@Composable
fun TonConnectRequestActionSection(
action: TonTransactionRecord.Action,
transactionInfoHelper: TransactionInfoHelper,
navController: NavController,
) {
when (val actionType = action.type) {
is TonTransactionRecord.Action.Type.Burn -> {
XxxBurnSection(
transactionValue = actionType.value,
transactionInfoHelper = transactionInfoHelper,
navController = navController
)
}

is TonTransactionRecord.Action.Type.ContractCall -> {
XxxContractCallSection(
navController = navController,
operation = actionType.operation,
address = actionType.address,
transactionValue = actionType.value,
transactionInfoHelper = transactionInfoHelper
)
}

is TonTransactionRecord.Action.Type.ContractDeploy -> {
XxxContractDeploySection(
interfaces = actionType.interfaces
)
}

// uiState.itemSections.forEach { items ->
// TransactionInfoSection(items, navController, { null })
// VSpacer(12.dp)
// }
is TonTransactionRecord.Action.Type.Mint -> {
XxxMintSection(
transactionValue = actionType.value,
transactionInfoHelper = transactionInfoHelper,
navController = navController
)
}

is TonTransactionRecord.Action.Type.Receive -> {
XxxReceiveCoinSection(
transactionValue = actionType.value,
address = actionType.from,
comment = actionType.comment,
statPage = StatPage.TonConnect,
navController = navController,
transactionInfoHelper = transactionInfoHelper,
blockchainType = BlockchainType.Ton
)
}

is TonTransactionRecord.Action.Type.Send -> {
XxxSendCoinSection(
transactionValue = actionType.value,
address = actionType.to,
comment = actionType.comment,
sentToSelf = actionType.sentToSelf,
statPage = StatPage.TonConnect,
navController = navController,
transactionInfoHelper = transactionInfoHelper,
blockchainType = BlockchainType.Ton
)
}

is TonTransactionRecord.Action.Type.Swap -> {
XxxSwapSection(
transactionInfoHelper = transactionInfoHelper,
navController = navController,
transactionValueIn = actionType.valueIn,
transactionValueOut = actionType.valueOut
)
}

is TonTransactionRecord.Action.Type.Unsupported -> {
SectionUniversalLawrence {
XxxSectionHeaderCell(
title = stringResource(R.string.Send_Confirmation_Action),
value = actionType.type,
painter = null
)
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,10 @@ import io.horizontalsystems.bankwallet.core.App
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.CurrencyManager
import io.horizontalsystems.bankwallet.core.managers.MarketKitWrapper
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 @@ -28,29 +23,22 @@ class TonConnectSendRequestViewModel(
private val sendRequestEntity: SendRequestEntity?,
private val accountManager: IAccountManager,
private val tonConnectManager: TonConnectManager,
private val marketKit: MarketKitWrapper,
private val currencyManager: CurrencyManager,
) : ViewModelUiState<TonConnectSendRequestUiState>() {

private var error: TonConnectSendRequestError? = null
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
private var tonKitWrapper: TonKitWrapper? = null
private var tonEvent: Event? = null

override fun createState() = TonConnectSendRequestUiState(
tonTransactionRecord = tonTransactionRecord,
currency = currency,
error = error,
confirmEnabled = sendRequestEntity != null && tonWallet != null,
rejectEnabled = sendRequestEntity != null,
itemSections = itemSections
rejectEnabled = sendRequestEntity != null
)

init {
Expand Down Expand Up @@ -99,13 +87,6 @@ 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 @@ -137,9 +118,7 @@ sealed class TonConnectSendRequestError : Error() {

data class TonConnectSendRequestUiState(
val tonTransactionRecord: TonTransactionRecord?,
val currency: Currency,
val error: TonConnectSendRequestError?,
val confirmEnabled: Boolean,
val rejectEnabled: Boolean,
val itemSections: List<List<TransactionInfoViewItem>>,
)

0 comments on commit 2ee4d54

Please sign in to comment.