Skip to content

Commit

Permalink
ETH-951 - display full amount in send button (#2193)
Browse files Browse the repository at this point in the history
* ETH-951 - display full amount in send button

* ETH-951 - import class
  • Loading branch information
eduardmaximovich authored Feb 14, 2024
1 parent b2d545d commit 5dd3763
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ class NewSendButtonState(
private val feeRelayerState: FeeRelayerState,
private val calculationMode: CalculationMode,
private val minRentExemption: BigInteger,
private val resources: Resources
private val resources: Resources,
private val totalFee: SendFeeTotal,
) {

private val minSolValidator = SendButtonStateMinSolValidator(
Expand Down Expand Up @@ -114,7 +115,7 @@ class NewSendButtonState(
else -> {
State.Enabled(
textResId = R.string.send_format,
value = "${calculationMode.getCurrentAmount().toPlainString()} ${tokenToSend.tokenSymbol}",
value = totalFee.totalSumWithSymbol,
totalAmountTextColor = R.color.text_night
)
}
Expand Down
34 changes: 32 additions & 2 deletions app/src/main/java/org/p2p/wallet/send/model/SendFeeTotal.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package org.p2p.wallet.send.model
import androidx.annotation.ColorInt
import android.os.Parcelable
import java.math.BigDecimal
import java.math.BigInteger
import kotlinx.parcelize.IgnoredOnParcel
import kotlinx.parcelize.Parcelize
import org.p2p.core.model.TextHighlighting
Expand All @@ -12,6 +13,8 @@ import org.p2p.core.utils.formatTokenWithSymbol
import org.p2p.core.utils.orZero
import org.p2p.uikit.utils.SpanUtils
import org.p2p.wallet.R
import org.p2p.wallet.feerelayer.model.Limits
import org.p2p.wallet.feerelayer.model.ProcessedFee
import org.p2p.wallet.feerelayer.model.TransactionFeeLimits

/**
Expand All @@ -36,6 +39,33 @@ class SendFeeTotal constructor(
val interestBearingPercent: BigDecimal? = null
) : Parcelable {

companion object {
fun createEmpty(): SendFeeTotal = SendFeeTotal(
currentAmount = BigDecimal.ZERO,
currentAmountUsd = null,
receiveFormatted = "",
receiveUsd = null,
sendFee = null,
feeLimit = TransactionFeeLimits(
limits = Limits(
maxFeeCountAllowed = 0,
maxFeeAmountAllowed = BigInteger.ZERO,
maxAccountCreationCountAllowed = 0,
maxAccountCreationAmountAllowed = BigInteger.ZERO
),
processedFee = ProcessedFee(
totalFeeAmountUsed = BigInteger.ZERO,
totalRentAmountUsed = BigInteger.ZERO,
totalFeeCountUsed = 0,
totalRentCountUsed = 0,
totalAmountUsed = BigInteger.ZERO
)
),
sourceSymbol = "",
recipientAddress = ""
)
}

@IgnoredOnParcel
val isSendingToken2022: Boolean
get() = transferFeePercent != null || interestBearingPercent != null
Expand Down Expand Up @@ -115,10 +145,10 @@ class SendFeeTotal constructor(
private val totalWithSymbolFormatted: String
get() = currentAmount.formatTokenWithSymbol(sourceSymbol, SOL_DECIMALS)

private val totalSumWithSymbol: String
val totalSumWithSymbol: String
get() {
val transferFee = transferFeePercent
?.let { it / 100.toBigDecimal() }
?.multiply("0.01".toBigDecimal())
?.multiply(currentAmount)

val totalSum = currentAmount
Expand Down
7 changes: 6 additions & 1 deletion app/src/main/java/org/p2p/wallet/send/ui/NewSendPresenter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -616,7 +616,12 @@ class NewSendPresenter(
calculationMode = calculationMode,
feeRelayerState = feeRelayerState,
minRentExemption = sendFeeRelayerManager.getMinRentExemption(),
resources = resources
resources = resources,
totalFee = sendFeeRelayerManager.buildTotalFee(
sourceToken = sourceToken,
calculationMode = calculationMode,
tokenExtensions = (feeRelayerState as? FeeRelayerState.UpdateFee)?.tokenExtensions.orEmpty()
)
)

when (val state = sendButton.getCurrentState()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import org.p2p.wallet.send.interactor.SendInteractor
import org.p2p.wallet.send.model.CalculationMode
import org.p2p.wallet.send.model.FeeRelayerState
import org.p2p.wallet.send.model.NewSendButtonState
import org.p2p.wallet.send.model.SendFeeTotal
import org.p2p.wallet.send.model.TemporaryAccount
import org.p2p.wallet.send.model.toSearchResult
import org.p2p.wallet.svl.analytics.SendViaLinkAnalytics
Expand Down Expand Up @@ -278,7 +279,8 @@ class SendViaLinkPresenter(
calculationMode = calculationMode,
feeRelayerState = FeeRelayerState.Idle,
minRentExemption = minRentExemption,
resources = resources
resources = resources,
totalFee = SendFeeTotal.createEmpty()
)

when (val state = sendButton.getCurrentState()) {
Expand Down

0 comments on commit 5dd3763

Please sign in to comment.