Skip to content

Commit

Permalink
Restructure composable components
Browse files Browse the repository at this point in the history
  • Loading branch information
abdrasulov committed Dec 23, 2024
1 parent 2ee4d54 commit 2f5551c
Show file tree
Hide file tree
Showing 17 changed files with 154 additions and 105 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,16 @@ import io.horizontalsystems.bankwallet.core.adapters.TonTransactionRecord
import io.horizontalsystems.bankwallet.core.stats.StatPage
import io.horizontalsystems.bankwallet.modules.confirm.ConfirmTransactionScreen
import io.horizontalsystems.bankwallet.modules.main.MainActivityViewModel
import io.horizontalsystems.bankwallet.modules.xtransaction.TransactionInfoHelper
import io.horizontalsystems.bankwallet.modules.xtransaction.XxxBurnSection
import io.horizontalsystems.bankwallet.modules.xtransaction.XxxContractCallSection
import io.horizontalsystems.bankwallet.modules.xtransaction.XxxContractDeploySection
import io.horizontalsystems.bankwallet.modules.xtransaction.XxxFeeSection
import io.horizontalsystems.bankwallet.modules.xtransaction.XxxMintSection
import io.horizontalsystems.bankwallet.modules.xtransaction.XxxReceiveCoinSection
import io.horizontalsystems.bankwallet.modules.xtransaction.XxxSectionHeaderCell
import io.horizontalsystems.bankwallet.modules.xtransaction.XxxSendCoinSection
import io.horizontalsystems.bankwallet.modules.xtransaction.XxxSwapSection
import io.horizontalsystems.bankwallet.modules.xtransaction.cells.HeaderCell
import io.horizontalsystems.bankwallet.modules.xtransaction.helpers.TransactionInfoHelper
import io.horizontalsystems.bankwallet.modules.xtransaction.sections.BurnSection
import io.horizontalsystems.bankwallet.modules.xtransaction.sections.FeeSection
import io.horizontalsystems.bankwallet.modules.xtransaction.sections.MintSection
import io.horizontalsystems.bankwallet.modules.xtransaction.sections.ReceiveCoinSection
import io.horizontalsystems.bankwallet.modules.xtransaction.sections.SendCoinSection
import io.horizontalsystems.bankwallet.modules.xtransaction.sections.SwapSection
import io.horizontalsystems.bankwallet.modules.xtransaction.sections.ton.ContractCallSection
import io.horizontalsystems.bankwallet.modules.xtransaction.sections.ton.ContractDeploySection
import io.horizontalsystems.bankwallet.ui.compose.components.ButtonPrimaryDefault
import io.horizontalsystems.bankwallet.ui.compose.components.ButtonPrimaryYellow
import io.horizontalsystems.bankwallet.ui.compose.components.TextImportantError
Expand Down Expand Up @@ -138,7 +138,7 @@ fun TonConnectSendRequestScreen(navController: NavController) {
}
VSpacer(12.dp)

XxxFeeSection(
FeeSection(
transactionInfoHelper = transactionInfoHelper,
fee = record.fee,
navController = navController
Expand All @@ -157,39 +157,40 @@ fun TonConnectRequestActionSection(
) {
when (val actionType = action.type) {
is TonTransactionRecord.Action.Type.Burn -> {
XxxBurnSection(
BurnSection(
transactionValue = actionType.value,
transactionInfoHelper = transactionInfoHelper,
navController = navController
)
}

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

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

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

is TonTransactionRecord.Action.Type.Receive -> {
XxxReceiveCoinSection(
ReceiveCoinSection(
transactionValue = actionType.value,
address = actionType.from,
comment = actionType.comment,
Expand All @@ -201,7 +202,7 @@ fun TonConnectRequestActionSection(
}

is TonTransactionRecord.Action.Type.Send -> {
XxxSendCoinSection(
SendCoinSection(
transactionValue = actionType.value,
address = actionType.to,
comment = actionType.comment,
Expand All @@ -214,7 +215,7 @@ fun TonConnectRequestActionSection(
}

is TonTransactionRecord.Action.Type.Swap -> {
XxxSwapSection(
SwapSection(
transactionInfoHelper = transactionInfoHelper,
navController = navController,
transactionValueIn = actionType.valueIn,
Expand All @@ -224,7 +225,7 @@ fun TonConnectRequestActionSection(

is TonTransactionRecord.Action.Type.Unsupported -> {
SectionUniversalLawrence {
XxxSectionHeaderCell(
HeaderCell(
title = stringResource(R.string.Send_Confirmation_Action),
value = actionType.type,
painter = null
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.horizontalsystems.bankwallet.modules.xtransaction
package io.horizontalsystems.bankwallet.modules.xtransaction.cells

import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
Expand Down Expand Up @@ -33,7 +33,7 @@ import io.horizontalsystems.core.helpers.HudHelper
import io.horizontalsystems.marketkit.models.BlockchainType

@Composable
fun XxxAddressCell(
fun AddressCell(
title: String,
value: String,
showAddContactButton: Boolean,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.horizontalsystems.bankwallet.modules.xtransaction
package io.horizontalsystems.bankwallet.modules.xtransaction.cells

import androidx.compose.foundation.Image
import androidx.compose.foundation.layout.Column
Expand All @@ -20,6 +20,10 @@ import io.horizontalsystems.bankwallet.core.stats.StatPage
import io.horizontalsystems.bankwallet.core.stats.stat
import io.horizontalsystems.bankwallet.entities.TransactionValue
import io.horizontalsystems.bankwallet.modules.coin.CoinFragment
import io.horizontalsystems.bankwallet.modules.xtransaction.helpers.TransactionInfoHelper
import io.horizontalsystems.bankwallet.modules.xtransaction.helpers.coinAmountString
import io.horizontalsystems.bankwallet.modules.xtransaction.helpers.coinIconPainter
import io.horizontalsystems.bankwallet.modules.xtransaction.helpers.fiatAmountString
import io.horizontalsystems.bankwallet.ui.compose.ComposeAppTheme
import io.horizontalsystems.bankwallet.ui.compose.components.HFillSpacer
import io.horizontalsystems.bankwallet.ui.compose.components.HSpacer
Expand All @@ -30,7 +34,7 @@ import io.horizontalsystems.bankwallet.ui.compose.components.subhead2_grey
import io.horizontalsystems.bankwallet.ui.compose.components.subhead2_leah

@Composable
fun XxxAmountCell(
fun AmountCell(
title: String,
coinIcon: Painter,
coinProtocolType: String,
Expand Down Expand Up @@ -75,7 +79,7 @@ fun XxxAmountCell(
}

@Composable
fun XxxAmountCellTV(
fun AmountCellTV(
title: String,
transactionValue: TransactionValue,
coinAmountColor: AmountColor,
Expand All @@ -85,7 +89,7 @@ fun XxxAmountCellTV(
statPage: StatPage,
borderTop: Boolean = true
) {
XxxAmountCell(
AmountCell(
title = title,
coinIcon = coinIconPainter(
url = transactionValue.coinIconUrl,
Expand All @@ -94,13 +98,13 @@ fun XxxAmountCellTV(
),
coinProtocolType = transactionValue.badge
?: stringResource(id = R.string.CoinPlatforms_Native),
coinAmount = xxxCoinAmount(
coinAmount = coinAmountString(
value = transactionValue.decimalValue?.abs(),
coinCode = transactionValue.coinCode,
sign = coinAmountSign.sign()
),
coinAmountColor = coinAmountColor.color(),
fiatAmount = xxxFiatAmount(
fiatAmount = fiatAmountString(
value = transactionInfoHelper.getXRate(transactionValue.coinUid)
?.let {
transactionValue.decimalValue?.abs()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.horizontalsystems.bankwallet.modules.xtransaction
package io.horizontalsystems.bankwallet.modules.xtransaction.cells

import androidx.compose.foundation.layout.padding
import androidx.compose.material.Icon
Expand All @@ -8,18 +8,13 @@ import androidx.compose.ui.graphics.painter.Painter
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.unit.dp
import io.horizontalsystems.bankwallet.core.App
import io.horizontalsystems.bankwallet.ui.compose.ComposeAppTheme
import io.horizontalsystems.bankwallet.ui.compose.components.HSpacer
import io.horizontalsystems.bankwallet.ui.compose.components.body_leah
import io.horizontalsystems.bankwallet.ui.compose.components.cell.CellUniversal
import io.horizontalsystems.bankwallet.ui.compose.components.subhead1_grey
import io.horizontalsystems.bankwallet.ui.compose.components.subhead1_leah
import io.horizontalsystems.bankwallet.ui.compose.components.subhead2_grey
import java.math.BigDecimal

@Composable
fun XxxSectionHeaderCell(
fun HeaderCell(
title: String,
value: String,
borderTop: Boolean = true,
Expand Down Expand Up @@ -47,37 +42,4 @@ fun XxxSectionHeaderCell(
overflow = TextOverflow.Ellipsis
)
}
}

@Composable
fun XxxTitleAndValueCell(
title: String,
value: String,
borderTop: Boolean = true
) {
CellUniversal(borderTop = borderTop) {
subhead2_grey(text = title, modifier = Modifier.padding(end = 16.dp))
HSpacer(16.dp)
subhead1_leah(
modifier = Modifier.weight(1f),
text = value,
textAlign = TextAlign.Right
)
}
}

@Composable
fun xxxCoinAmount(value: BigDecimal?, coinCode: String, sign: String): String {
// if (hideAmount) return "*****"
if (value == null) return "---"

return sign + App.numberFormatter.formatCoinFull(value, coinCode, 8)
}

@Composable
fun xxxFiatAmount(value: BigDecimal?, fiatSymbol: String): String {
// if (hideAmount) return "*****"
if (value == null) return "---"

return App.numberFormatter.formatFiatFull(value, fiatSymbol)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package io.horizontalsystems.bankwallet.modules.xtransaction.cells

import androidx.compose.foundation.layout.padding
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.dp
import io.horizontalsystems.bankwallet.ui.compose.components.HSpacer
import io.horizontalsystems.bankwallet.ui.compose.components.cell.CellUniversal
import io.horizontalsystems.bankwallet.ui.compose.components.subhead1_leah
import io.horizontalsystems.bankwallet.ui.compose.components.subhead2_grey

@Composable
fun TitleAndValueCell(
title: String,
value: String,
borderTop: Boolean = true
) {
CellUniversal(borderTop = borderTop) {
subhead2_grey(text = title, modifier = Modifier.padding(end = 16.dp))
HSpacer(16.dp)
subhead1_leah(
modifier = Modifier.weight(1f),
text = value,
textAlign = TextAlign.Right
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package io.horizontalsystems.bankwallet.modules.xtransaction.helpers

import androidx.compose.runtime.Composable
import io.horizontalsystems.bankwallet.core.App
import java.math.BigDecimal

@Composable
fun coinAmountString(value: BigDecimal?, coinCode: String, sign: String): String {
// if (hideAmount) return "*****"
if (value == null) return "---"

return sign + App.numberFormatter.formatCoinFull(value, coinCode, 8)
}

@Composable
fun fiatAmountString(value: BigDecimal?, fiatSymbol: String): String {
// if (hideAmount) return "*****"
if (value == null) return "---"

return App.numberFormatter.formatFiatFull(value, fiatSymbol)
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.horizontalsystems.bankwallet.modules.xtransaction
package io.horizontalsystems.bankwallet.modules.xtransaction.helpers

import androidx.compose.runtime.Composable
import androidx.compose.ui.res.painterResource
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.horizontalsystems.bankwallet.modules.xtransaction
package io.horizontalsystems.bankwallet.modules.xtransaction.helpers

import io.horizontalsystems.bankwallet.core.App
import io.horizontalsystems.bankwallet.entities.Currency
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,25 @@
package io.horizontalsystems.bankwallet.modules.xtransaction
package io.horizontalsystems.bankwallet.modules.xtransaction.sections

import androidx.compose.runtime.Composable
import androidx.compose.ui.res.stringResource
import androidx.navigation.NavController
import io.horizontalsystems.bankwallet.R
import io.horizontalsystems.bankwallet.core.stats.StatPage
import io.horizontalsystems.bankwallet.entities.TransactionValue
import io.horizontalsystems.bankwallet.modules.xtransaction.cells.AmountCellTV
import io.horizontalsystems.bankwallet.modules.xtransaction.cells.AmountColor
import io.horizontalsystems.bankwallet.modules.xtransaction.cells.AmountSign
import io.horizontalsystems.bankwallet.modules.xtransaction.helpers.TransactionInfoHelper
import io.horizontalsystems.bankwallet.ui.compose.components.cell.SectionUniversalLawrence

@Composable
fun XxxBurnSection(
fun BurnSection(
transactionValue: TransactionValue,
transactionInfoHelper: TransactionInfoHelper,
navController: NavController,
) {
SectionUniversalLawrence {
XxxAmountCellTV(
AmountCellTV(
title = stringResource(R.string.Send_Confirmation_Burn),
transactionValue = transactionValue,
coinAmountColor = AmountColor.Negative,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
package io.horizontalsystems.bankwallet.modules.xtransaction
package io.horizontalsystems.bankwallet.modules.xtransaction.sections

import androidx.compose.runtime.Composable
import androidx.navigation.NavController
import io.horizontalsystems.bankwallet.entities.CurrencyValue
import io.horizontalsystems.bankwallet.entities.TransactionValue
import io.horizontalsystems.bankwallet.modules.amount.AmountInputType
import io.horizontalsystems.bankwallet.modules.fee.HSFeeRaw
import io.horizontalsystems.bankwallet.modules.xtransaction.helpers.TransactionInfoHelper
import io.horizontalsystems.bankwallet.ui.compose.components.cell.SectionUniversalLawrence

@Composable
fun XxxFeeSection(
fun FeeSection(
transactionInfoHelper: TransactionInfoHelper,
fee: TransactionValue.CoinValue,
navController: NavController,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,25 @@
package io.horizontalsystems.bankwallet.modules.xtransaction
package io.horizontalsystems.bankwallet.modules.xtransaction.sections

import androidx.compose.runtime.Composable
import androidx.compose.ui.res.stringResource
import androidx.navigation.NavController
import io.horizontalsystems.bankwallet.R
import io.horizontalsystems.bankwallet.core.stats.StatPage
import io.horizontalsystems.bankwallet.entities.TransactionValue
import io.horizontalsystems.bankwallet.modules.xtransaction.cells.AmountCellTV
import io.horizontalsystems.bankwallet.modules.xtransaction.cells.AmountColor
import io.horizontalsystems.bankwallet.modules.xtransaction.cells.AmountSign
import io.horizontalsystems.bankwallet.modules.xtransaction.helpers.TransactionInfoHelper
import io.horizontalsystems.bankwallet.ui.compose.components.cell.SectionUniversalLawrence

@Composable
fun XxxMintSection(
fun MintSection(
transactionValue: TransactionValue,
transactionInfoHelper: TransactionInfoHelper,
navController: NavController,
) {
SectionUniversalLawrence {
XxxAmountCellTV(
AmountCellTV(
title = stringResource(R.string.Send_Confirmation_Mint),
transactionValue = transactionValue,
coinAmountColor = AmountColor.Positive,
Expand Down
Loading

0 comments on commit 2f5551c

Please sign in to comment.