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

Fix showing the exact value of the total fee #1254

Merged
merged 6 commits into from
Oct 29, 2024
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 @@ -25,6 +25,7 @@ import com.vultisig.wallet.data.common.DeepLinkHelper
import com.vultisig.wallet.data.common.Endpoints
import com.vultisig.wallet.data.crypto.ThorChainHelper
import com.vultisig.wallet.data.mappers.KeysignMessageFromProtoMapper
import com.vultisig.wallet.data.models.EstimatedGasFee
import com.vultisig.wallet.data.models.GasFeeParams
import com.vultisig.wallet.data.models.TokenStandard
import com.vultisig.wallet.data.models.TokenValue
Expand Down Expand Up @@ -89,7 +90,9 @@ sealed class JoinKeysignError(val message: UiText) {
JoinKeysignError(UiText.DynamicString(exceptionMessage))

data object WrongVault : JoinKeysignError(R.string.join_keysign_wrong_vault.asUiText())
data object WrongVaultShare : JoinKeysignError(R.string.join_keysign_error_wrong_vault_share.asUiText())
data object WrongVaultShare :
JoinKeysignError(R.string.join_keysign_error_wrong_vault_share.asUiText())

data object WrongReShare : JoinKeysignError(R.string.join_keysign_wrong_reshare.asUiText())
data object InvalidQr : JoinKeysignError(R.string.join_keysign_invalid_qr.asUiText())
data object FailedToStart : JoinKeysignError(R.string.join_keysign_failed_to_start.asUiText())
Expand Down Expand Up @@ -292,6 +295,21 @@ internal class JoinKeysignViewModel @Inject constructor(

val nativeToken = tokenRepository.getNativeToken(dstToken.chain.id)

val chain = srcToken.chain
val gasFee = gasFeeRepository.getGasFee(chain, nativeToken.address)
val estimatedGasFee: EstimatedGasFee = gasFeeToEstimatedFee(
GasFeeParams(
gasLimit = if (chain.standard == TokenStandard.EVM) {
(payload.blockChainSpecific as BlockChainSpecific.Ethereum).gasLimit
} else {
BigInteger.valueOf(1)
},
gasFee = gasFee,
selectedToken = srcToken,
)
)
val gasFeeFiatValue = estimatedGasFee.fiatValue

when (swapPayload) {
is SwapPayload.OneInch -> {
val estimatedTokenFees = TokenValue(
Expand All @@ -301,15 +319,17 @@ internal class JoinKeysignViewModel @Inject constructor(
token = nativeToken
)

val estimatedFee = convertTokenValueToFiat(
nativeToken,
estimatedTokenFees,
currency
)

val swapTransaction = SwapTransactionUiModel(
srcTokenValue = mapTokenValueToStringWithUnit(srcTokenValue),
dstTokenValue = mapTokenValueToStringWithUnit(dstTokenValue),
estimatedFees = fiatValueToStringMapper.map(
convertTokenValueToFiat(
nativeToken,
estimatedTokenFees,
currency
)
totalFee = fiatValueToStringMapper.map(
estimatedFee + gasFeeFiatValue
),
)

Expand Down Expand Up @@ -339,11 +359,12 @@ internal class JoinKeysignViewModel @Inject constructor(
isAffiliate = isAffiliate,
)

val estimatedFee = convertTokenValueToFiat(dstToken, quote.fees, currency)
val swapTransactionUiModel = SwapTransactionUiModel(
srcTokenValue = mapTokenValueToStringWithUnit(srcTokenValue),
dstTokenValue = mapTokenValueToStringWithUnit(dstTokenValue),
estimatedFees = fiatValueToStringMapper.map(
convertTokenValueToFiat(dstToken, quote.fees, currency)
totalFee = fiatValueToStringMapper.map(
estimatedFee + gasFeeFiatValue
),
)
transactionTypeUiModel = TransactionTypeUiModel.Swap(swapTransactionUiModel)
Expand Down Expand Up @@ -372,11 +393,13 @@ internal class JoinKeysignViewModel @Inject constructor(
isAffiliate = isAffiliate
)

val estimatedFee =
convertTokenValueToFiat(nativeToken, quote.fees, currency)
val swapTransactionUiModel = SwapTransactionUiModel(
srcTokenValue = mapTokenValueToStringWithUnit(srcTokenValue),
dstTokenValue = mapTokenValueToStringWithUnit(dstTokenValue),
estimatedFees = fiatValueToStringMapper.map(
convertTokenValueToFiat(nativeToken, quote.fees, currency)
totalFee = fiatValueToStringMapper.map(
estimatedFee + gasFeeFiatValue
),
)
transactionTypeUiModel = TransactionTypeUiModel.Swap(swapTransactionUiModel)
Expand All @@ -389,6 +412,7 @@ internal class JoinKeysignViewModel @Inject constructor(
}
}
}

else -> {
val isDeposit = when (val specific = payload.blockChainSpecific) {
is BlockChainSpecific.MayaChain -> specific.isDeposit
Expand Down Expand Up @@ -422,7 +446,8 @@ internal class JoinKeysignViewModel @Inject constructor(
),
memo = payload.memo ?: "",
)
transactionTypeUiModel = TransactionTypeUiModel.Deposit(depositTransactionUiModel)
transactionTypeUiModel =
TransactionTypeUiModel.Deposit(depositTransactionUiModel)
verifyUiModel.value = VerifyUiModel.Deposit(
VerifyDepositUiModel(
depositTransactionUiModel
Expand Down Expand Up @@ -574,6 +599,7 @@ internal class JoinKeysignViewModel @Inject constructor(
}
return false
}

fun enableNavigationToHome() {
isNavigateToHome = true
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ internal class SwapTransactionToUiModelMapperImpl @Inject constructor(
srcTokenValue = mapTokenValueToStringWithUnit(from.srcTokenValue),
dstTokenValue = mapTokenValueToStringWithUnit(from.expectedDstTokenValue),
hasConsentAllowance = from.isApprovalRequired,
estimatedFees = fiatValueToStringMapper.map(fiatFees),
totalFee = fiatValueToStringMapper.map(fiatFees + from.gasFeeFiatValue)
)
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.vultisig.wallet.ui.models.swap

import androidx.compose.foundation.text.input.TextFieldState
import androidx.compose.foundation.text.input.setTextAndPlaceCursorAtEnd
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.vultisig.wallet.R
Expand Down Expand Up @@ -39,7 +38,6 @@ import com.vultisig.wallet.data.utils.TextFieldUtils
import com.vultisig.wallet.ui.models.mappers.AccountToTokenBalanceUiModelMapper
import com.vultisig.wallet.ui.models.mappers.FiatValueToStringMapper
import com.vultisig.wallet.ui.models.mappers.TokenValueToDecimalUiStringMapper
import com.vultisig.wallet.ui.models.mappers.TokenValueToStringWithUnitMapper
import com.vultisig.wallet.ui.models.mappers.ZeroValueCurrencyToStringMapper
import com.vultisig.wallet.ui.models.send.InvalidTransactionDataException
import com.vultisig.wallet.ui.models.send.SendSrc
Expand Down Expand Up @@ -94,7 +92,6 @@ internal class SwapFormViewModel @Inject constructor(
private val navigator: Navigator<Destination>,
private val sendNavigator: Navigator<SendDst>,
private val accountToTokenBalanceUiModelMapper: AccountToTokenBalanceUiModelMapper,
private val mapTokenValueToString: TokenValueToStringWithUnitMapper,
private val mapTokenValueToDecimalUiString: TokenValueToDecimalUiStringMapper,
private val fiatValueToString: FiatValueToStringMapper,
private val zeroValueCurrencyToString: ZeroValueCurrencyToStringMapper,
Expand Down Expand Up @@ -155,6 +152,7 @@ internal class SwapFormViewModel @Inject constructor(
val selectedDst = selectedDst.value ?: return

val gasFee = gasFee.value ?: return
val gasFeeFiatValue = gasFeeFiat.value ?: return

val srcToken = selectedSrc.account.token
val dstToken = selectedDst.account.token
Expand Down Expand Up @@ -260,6 +258,7 @@ internal class SwapFormViewModel @Inject constructor(
estimatedFees = quote.fees,
isApprovalRequired = isApprovalRequired,
memo = null,
gasFeeFiatValue = gasFeeFiatValue,
payload = SwapPayload.ThorChain(
THORChainSwapPayload(
fromAddress = srcAddress,
Expand Down Expand Up @@ -312,6 +311,7 @@ internal class SwapFormViewModel @Inject constructor(
estimatedFees = quote.fees,
memo = quote.data.memo,
isApprovalRequired = isApprovalRequired,
gasFeeFiatValue = gasFeeFiatValue,
payload = SwapPayload.MayaChain(
THORChainSwapPayload(
fromAddress = srcAddress,
Expand Down Expand Up @@ -358,6 +358,7 @@ internal class SwapFormViewModel @Inject constructor(
estimatedFees = quote.fees,
memo = null,
isApprovalRequired = isApprovalRequired,
gasFeeFiatValue = gasFeeFiatValue,
payload = SwapPayload.OneInch(
OneInchSwapPayloadJson(
fromCoin = srcToken,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import javax.inject.Inject
internal data class SwapTransactionUiModel(
val srcTokenValue: String = "",
val dstTokenValue: String = "",
val estimatedFees: String = "",
val totalFee: String = "",
val hasConsentAllowance: Boolean = false,
)

Expand Down Expand Up @@ -123,7 +123,7 @@ internal class VerifySwapViewModel @Inject constructor(

if (hasAllConsents) {
viewModelScope.launch {
sendNavigator.navigate (
sendNavigator.navigate(
getSendDstByKeysignInitType(keysignInitType, transactionId, password.value)
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ internal fun TransactionDoneScreen(
navController: NavController,
transactionHash: String,
transactionLink: String,
progressLink:String?,
progressLink: String?,
transactionTypeUiModel: TransactionTypeUiModel,
) {
UiBarContainer(
Expand Down Expand Up @@ -132,9 +132,9 @@ internal fun TransactionDoneView(
)


when (transactionTypeUiModel) {
is TransactionTypeUiModel.Deposit ->
DepositTransactionDetail(transactionTypeUiModel.depositTransactionUiModel)
when (transactionTypeUiModel) {
is TransactionTypeUiModel.Deposit ->
DepositTransactionDetail(transactionTypeUiModel.depositTransactionUiModel)


is TransactionTypeUiModel.Send ->
Expand All @@ -143,8 +143,8 @@ internal fun TransactionDoneView(
is TransactionTypeUiModel.Swap -> SwapTransactionDetail(
swapTransaction = transactionTypeUiModel.swapTransactionUiModel,
progressLink = progressLink,
) { progressLink ->
uriHandler.openUri(progressLink)
) { progressLink ->
uriHandler.openUri(progressLink)
}

else -> Unit
Expand Down Expand Up @@ -226,8 +226,8 @@ private fun ColumnScope.SwapTransactionDetail(
}

OtherField(
title = stringResource(R.string.verify_swap_screen_estimated_fees),
value = swapTransaction.estimatedFees,
title = stringResource(R.string.verify_swap_screen_total_fees),
value = swapTransaction.totalFee,
)

if (progressLink != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,8 +196,8 @@ private fun VerifySwapScreen(
}

OtherField(
title = stringResource(R.string.verify_swap_screen_estimated_fees),
value = swapTransactionUiModel.estimatedFees,
title = stringResource(R.string.verify_swap_screen_total_fees),
value = swapTransactionUiModel.totalFee,
divider = false,
)
}
Expand Down Expand Up @@ -243,7 +243,7 @@ private fun VerifySwapScreenPreview() {
swapTransactionUiModel = SwapTransactionUiModel(
srcTokenValue = "1 RUNE",
dstTokenValue = "1 ETH",
estimatedFees = "1.00$",
totalFee = "1.00$",
hasConsentAllowance = true,
),
consentAllowance = true,
Expand Down
1 change: 0 additions & 1 deletion app/src/main/res/values-de/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,6 @@
<string name="vault_settings_success_backup_file">Datei gespeichert in Downloads/%1$s</string>
<string name="failed_to_start_error">Start fehlgeschlagen, Fehler: %1$s</string>
<string name="swap_form_estimated_fees_title">Swap Gebühr</string>
<string name="verify_swap_screen_estimated_fees">Geschätzte Gebühren</string>
<string name="keysign_screen_error_please_try_again">Fehler! Bitte versuchen Sie es erneut. %1$s</string>
<string name="join_keysign_discovering_session_id">Sitzungs-ID ermitteln</string>
<string name="join_key_gen_screen_discovering_session_id">Sitzungs-ID ermitteln</string>
Expand Down
1 change: 0 additions & 1 deletion app/src/main/res/values-es/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,6 @@
<string name="swap_form_gas_title">Tarifa de red</string>
<string name="swap_form_total_fees_title">Tarifas totales</string>
<string name="share_qr_utils_choose_an_app">Elige una aplicación</string>
<string name="verify_swap_screen_estimated_fees">Tarifas estimadas</string>
<string name="verify_swap_agree_receive_amount">Estoy de acuerdo con la cantidad que recibiré después del intercambio.</string>
<string name="verify_swap_consent_amount">El monto del intercambio es correcto</string>
<string name="settings_screen_vault_settings">Configuración Bóvedas</string>
Expand Down
1 change: 0 additions & 1 deletion app/src/main/res/values-hr/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,6 @@
<string name="vault_settings_success_backup_file">datoteka spremljena u Downloads/%1$s</string>
<string name="failed_to_start_error">Pokretanje nije uspjelo, pogreška: %1$s</string>
<string name="swap_form_estimated_fees_title">Naknada za zamjenu</string>
<string name="verify_swap_screen_estimated_fees">Procijenjene naknade</string>
<string name="keysign_screen_error_please_try_again">Greška! Molim te pokušaj ponovno. %1$s</string>
<string name="join_keysign_discovering_session_id">Otkrivanje ID-a sesije</string>
<string name="join_key_gen_screen_discovering_session_id">Otkrivanje ID-a sesije</string>
Expand Down
1 change: 0 additions & 1 deletion app/src/main/res/values-it/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,6 @@
<string name="vault_settings_success_backup_file">file salvato in Download/%1$s</string>
<string name="failed_to_start_error">Impossibile avviare, errore: %1$s</string>
<string name="swap_form_estimated_fees_title">Commissione di cambio</string>
<string name="verify_swap_screen_estimated_fees">Tariffe stimate</string>
<string name="keysign_screen_error_please_try_again">Errore! Riprova. %1$s</string>
<string name="join_keysign_discovering_session_id">Individuazione dell\’ID sessione</string>
<string name="join_key_gen_screen_discovering_session_id">Individuazione dell\’ID sessione</string>
Expand Down
1 change: 0 additions & 1 deletion app/src/main/res/values-nl/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,6 @@
<string name="swap_form_gas_title">Netwerkkosten</string>
<string name="swap_form_total_fees_title">Totale kosten</string>
<string name="share_qr_utils_choose_an_app">Kies een app</string>
<string name="verify_swap_screen_estimated_fees">Geschatte kosten</string>
<string name="verify_swap_agree_receive_amount">Ik ga akkoord met het bedrag dat ik na de wissel zal ontvangen</string>
<string name="verify_swap_consent_amount">Het wisselbedrag is correct</string>
<string name="chain_token_screen_address_copied">%1$s gekopieerd naar klembord</string>
Expand Down
1 change: 0 additions & 1 deletion app/src/main/res/values-pt/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,6 @@
<string name="vault_settings_success_backup_file">arquivo salvo em Downloads/%1$s</string>
<string name="failed_to_start_error">Falha ao iniciar, erro: %1$s</string>
<string name="swap_form_estimated_fees_title">Taxa de swap</string>
<string name="verify_swap_screen_estimated_fees">Taxas estimadas</string>
<string name="keysign_screen_error_please_try_again">Erro! Por favor, tente novamente. %1$s</string>
<string name="join_keysign_discovering_session_id">Descobrindo o ID da sessão</string>
<string name="join_key_gen_screen_discovering_session_id">Descobrindo o ID da sessão</string>
Expand Down
1 change: 0 additions & 1 deletion app/src/main/res/values-ru/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,6 @@
<string name="swap_form_gas_title">Сетевой сбор</string>
<string name="swap_form_total_fees_title">Общая сумма сборов</string>
<string name="share_qr_utils_choose_an_app">Выберите приложение</string>
<string name="verify_swap_screen_estimated_fees">Ориентировочные сборы</string>
<string name="verify_swap_agree_receive_amount">Я согласен с суммой, которую получу после обмена</string>
<string name="verify_swap_consent_amount">Сумма обмена корректна</string>
<string name="chain_token_screen_address_copied">%1$s скопировано в буфер обмена</string>
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,6 @@
<string name="swap_form_gas_title">Network fee</string>
<string name="swap_form_total_fees_title">Total fees</string>
<string name="share_qr_utils_choose_an_app">Choose an app</string>
<string name="verify_swap_screen_estimated_fees">Estimated Fees</string>
<string name="verify_swap_agree_receive_amount">I agree with the amount I will receive after the swap</string>
<string name="verify_swap_consent_amount">The swap amount is correct</string>
<string name="chain_token_screen_address_copied">%1$s copied to clipboard</string>
Expand Down Expand Up @@ -463,4 +462,5 @@
<string name="keygen_vultiserver_peer_discovery_please_wait" translatable="false">Please wait</string>
<string name="keygen_fast_vault_email_hint" translatable="false">This email is only used to send the backup</string>
<string name="register_vault_screen_save_qr_code" translatable="false">Save QR Code</string>
<string name="verify_swap_screen_total_fees" translatable="false">Total Fees</string>
</resources>
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ sealed interface SwapTransaction {
val memo: String?
val payload: SwapPayload
val isApprovalRequired: Boolean
val gasFeeFiatValue: FiatValue

data class RegularSwapTransaction(
override val id: TransactionId,
Expand All @@ -31,6 +32,7 @@ sealed interface SwapTransaction {
override val memo: String?,
override val payload: SwapPayload,
override val isApprovalRequired: Boolean,
override val gasFeeFiatValue: FiatValue,
) : SwapTransaction

companion object {
Expand Down