Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ETH-951 - display full amount in send button #2193

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mb just val EMPTY?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No reason to do this; this code is unused in fact, and allocating static storage for it is pointless

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
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
Loading