From 8f4ffdeca456235d805f8cc151b88673493c4715 Mon Sep 17 00:00:00 2001 From: Samuel Holmes Date: Wed, 25 Oct 2023 17:05:23 -0700 Subject: [PATCH] Detect and warn user for amount changes within transaction acceleration --- CHANGELOG.md | 2 ++ src/components/modals/AccelerateTxModal.tsx | 18 ++++++++++++++++++ src/locales/en_US.ts | 2 ++ src/locales/strings/enUS.json | 2 ++ 4 files changed, 24 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index e91a84b8eba..d9d326baf9a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ ## Unreleased +- added: New 'Lower Send Amount' warning for transaction acceleration + ## 3.21.0 - added: Paybis buy/sell in Brazil, Columbia, and Mexico diff --git a/src/components/modals/AccelerateTxModal.tsx b/src/components/modals/AccelerateTxModal.tsx index 2d647202b07..cb1ed32a110 100644 --- a/src/components/modals/AccelerateTxModal.tsx +++ b/src/components/modals/AccelerateTxModal.tsx @@ -1,3 +1,4 @@ +import { abs, lt, sub } from 'biggystring' import { EdgeCurrencyWallet, EdgeDenomination, EdgeTransaction } from 'edge-core-js' import React, { PureComponent } from 'react' import { Text, View } from 'react-native' @@ -8,6 +9,7 @@ import { getDisplayDenominationFromState, getExchangeDenominationFromState } fro import { connect } from '../../types/reactRedux' import { GuiExchangeRates } from '../../types/types' import { convertTransactionFeeToDisplayFee } from '../../util/utils' +import { WarningCard } from '../cards/WarningCard' import { cacheStyles, Theme, ThemeProps, withTheme } from '../services/ThemeContext' import { ModalMessage, ModalTitle } from '../themed/ModalParts' import { Slider } from '../themed/Slider' @@ -105,6 +107,7 @@ export class AccelerateTxModalComponent extends PureComponent { const oldFee = this.getTxFeeDisplay(replacedTx) const newFee = this.getTxFeeDisplay(acceleratedTx) + const isLowerAmount = lt(getTxSendAmount(acceleratedTx), getTxSendAmount(replacedTx)) const isSending = status === 'sending' return ( @@ -115,6 +118,13 @@ export class AccelerateTxModalComponent extends PureComponent { {newFee == null ? null : } + {isLowerAmount ? ( + + ) : null} {error == null ? null : ( @@ -169,3 +179,11 @@ export const AccelerateTxModal = connect( } }) )(withTheme(AccelerateTxModalComponent)) + +function getTxSendAmount(edgeTransaction: EdgeTransaction): string { + // Transaction amounts are negative for send transactions + const nativeAmount = abs(edgeTransaction.nativeAmount) + // Parent network fee is used for token sends + const feeAmount = edgeTransaction.parentNetworkFee ?? edgeTransaction.networkFee + return sub(nativeAmount, feeAmount) +} diff --git a/src/locales/en_US.ts b/src/locales/en_US.ts index 482c74774f6..e014f414ef6 100644 --- a/src/locales/en_US.ts +++ b/src/locales/en_US.ts @@ -664,6 +664,8 @@ const strings = { transaction_details_accelerate_transaction_slider_disabled: 'Unable to Accelerate Transaction', transaction_details_accelerate_transaction_fee_too_low: 'Accelerated transaction fee is too low. Fee has been updated. Please try again.', transaction_details_accelerate_transaction_sent: 'Your transaction has been accelerated.', + transaction_details_accelerate_transaction_lower_amount_tx_title: 'Lower Send Amount', + transaction_details_accelerate_transaction_lower_amount_tx_message: `In order to accelerate this transaction, the recipient's amount will be lower due to insufficient balance to cover the new fee.`, transaction_details_exchange_details: 'Exchange Details', transaction_details_exchange_service: 'Exchange Service', transaction_details_exchange_order_id: 'Order ID', diff --git a/src/locales/strings/enUS.json b/src/locales/strings/enUS.json index 479517ba1ab..8e5cba5ca7c 100644 --- a/src/locales/strings/enUS.json +++ b/src/locales/strings/enUS.json @@ -595,6 +595,8 @@ "transaction_details_accelerate_transaction_slider_disabled": "Unable to Accelerate Transaction", "transaction_details_accelerate_transaction_fee_too_low": "Accelerated transaction fee is too low. Fee has been updated. Please try again.", "transaction_details_accelerate_transaction_sent": "Your transaction has been accelerated.", + "transaction_details_accelerate_transaction_lower_amount_tx_title": "Lower Send Amount", + "transaction_details_accelerate_transaction_lower_amount_tx_message": "In order to accelerate this transaction, the recipient's amount will be lower due to insufficient balance to cover the new fee.", "transaction_details_exchange_details": "Exchange Details", "transaction_details_exchange_service": "Exchange Service", "transaction_details_exchange_order_id": "Order ID",