Skip to content

Commit 8f4ffde

Browse files
committed
Detect and warn user for amount changes within transaction acceleration
1 parent 2dedb39 commit 8f4ffde

File tree

4 files changed

+24
-0
lines changed

4 files changed

+24
-0
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
## Unreleased
44

5+
- added: New 'Lower Send Amount' warning for transaction acceleration
6+
57
## 3.21.0
68

79
- added: Paybis buy/sell in Brazil, Columbia, and Mexico

src/components/modals/AccelerateTxModal.tsx

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { abs, lt, sub } from 'biggystring'
12
import { EdgeCurrencyWallet, EdgeDenomination, EdgeTransaction } from 'edge-core-js'
23
import React, { PureComponent } from 'react'
34
import { Text, View } from 'react-native'
@@ -8,6 +9,7 @@ import { getDisplayDenominationFromState, getExchangeDenominationFromState } fro
89
import { connect } from '../../types/reactRedux'
910
import { GuiExchangeRates } from '../../types/types'
1011
import { convertTransactionFeeToDisplayFee } from '../../util/utils'
12+
import { WarningCard } from '../cards/WarningCard'
1113
import { cacheStyles, Theme, ThemeProps, withTheme } from '../services/ThemeContext'
1214
import { ModalMessage, ModalTitle } from '../themed/ModalParts'
1315
import { Slider } from '../themed/Slider'
@@ -105,6 +107,7 @@ export class AccelerateTxModalComponent extends PureComponent<Props, State> {
105107
const oldFee = this.getTxFeeDisplay(replacedTx)
106108
const newFee = this.getTxFeeDisplay(acceleratedTx)
107109

110+
const isLowerAmount = lt(getTxSendAmount(acceleratedTx), getTxSendAmount(replacedTx))
108111
const isSending = status === 'sending'
109112

110113
return (
@@ -115,6 +118,13 @@ export class AccelerateTxModalComponent extends PureComponent<Props, State> {
115118
<Tile type="static" title={lstrings.transaction_details_accelerate_transaction_old_fee_title} body={oldFee} />
116119
{newFee == null ? null : <Tile type="static" title={lstrings.transaction_details_accelerate_transaction_new_fee_title} body={newFee} />}
117120
</View>
121+
{isLowerAmount ? (
122+
<WarningCard
123+
title={lstrings.transaction_details_accelerate_transaction_lower_amount_tx_title}
124+
points={[lstrings.transaction_details_accelerate_transaction_lower_amount_tx_message]}
125+
marginRem={[1.5, 1]}
126+
/>
127+
) : null}
118128
{error == null ? null : (
119129
<View style={styles.error}>
120130
<Text style={styles.errorText} numberOfLines={3}>
@@ -169,3 +179,11 @@ export const AccelerateTxModal = connect<StateProps, DispatchProps, OwnProps>(
169179
}
170180
})
171181
)(withTheme(AccelerateTxModalComponent))
182+
183+
function getTxSendAmount(edgeTransaction: EdgeTransaction): string {
184+
// Transaction amounts are negative for send transactions
185+
const nativeAmount = abs(edgeTransaction.nativeAmount)
186+
// Parent network fee is used for token sends
187+
const feeAmount = edgeTransaction.parentNetworkFee ?? edgeTransaction.networkFee
188+
return sub(nativeAmount, feeAmount)
189+
}

src/locales/en_US.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -664,6 +664,8 @@ const strings = {
664664
transaction_details_accelerate_transaction_slider_disabled: 'Unable to Accelerate Transaction',
665665
transaction_details_accelerate_transaction_fee_too_low: 'Accelerated transaction fee is too low. Fee has been updated. Please try again.',
666666
transaction_details_accelerate_transaction_sent: 'Your transaction has been accelerated.',
667+
transaction_details_accelerate_transaction_lower_amount_tx_title: 'Lower Send Amount',
668+
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.`,
667669
transaction_details_exchange_details: 'Exchange Details',
668670
transaction_details_exchange_service: 'Exchange Service',
669671
transaction_details_exchange_order_id: 'Order ID',

src/locales/strings/enUS.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -595,6 +595,8 @@
595595
"transaction_details_accelerate_transaction_slider_disabled": "Unable to Accelerate Transaction",
596596
"transaction_details_accelerate_transaction_fee_too_low": "Accelerated transaction fee is too low. Fee has been updated. Please try again.",
597597
"transaction_details_accelerate_transaction_sent": "Your transaction has been accelerated.",
598+
"transaction_details_accelerate_transaction_lower_amount_tx_title": "Lower Send Amount",
599+
"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.",
598600
"transaction_details_exchange_details": "Exchange Details",
599601
"transaction_details_exchange_service": "Exchange Service",
600602
"transaction_details_exchange_order_id": "Order ID",

0 commit comments

Comments
 (0)