Skip to content

Commit

Permalink
Detect and warn user for amount changes within transaction acceleration
Browse files Browse the repository at this point in the history
  • Loading branch information
samholmes committed Oct 30, 2023
1 parent 2dedb39 commit 8f4ffde
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 18 additions & 0 deletions src/components/modals/AccelerateTxModal.tsx
Original file line number Diff line number Diff line change
@@ -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'
Expand All @@ -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'
Expand Down Expand Up @@ -105,6 +107,7 @@ export class AccelerateTxModalComponent extends PureComponent<Props, State> {
const oldFee = this.getTxFeeDisplay(replacedTx)
const newFee = this.getTxFeeDisplay(acceleratedTx)

const isLowerAmount = lt(getTxSendAmount(acceleratedTx), getTxSendAmount(replacedTx))
const isSending = status === 'sending'

return (
Expand All @@ -115,6 +118,13 @@ export class AccelerateTxModalComponent extends PureComponent<Props, State> {
<Tile type="static" title={lstrings.transaction_details_accelerate_transaction_old_fee_title} body={oldFee} />
{newFee == null ? null : <Tile type="static" title={lstrings.transaction_details_accelerate_transaction_new_fee_title} body={newFee} />}
</View>
{isLowerAmount ? (
<WarningCard
title={lstrings.transaction_details_accelerate_transaction_lower_amount_tx_title}
points={[lstrings.transaction_details_accelerate_transaction_lower_amount_tx_message]}
marginRem={[1.5, 1]}
/>
) : null}
{error == null ? null : (
<View style={styles.error}>
<Text style={styles.errorText} numberOfLines={3}>
Expand Down Expand Up @@ -169,3 +179,11 @@ export const AccelerateTxModal = connect<StateProps, DispatchProps, OwnProps>(
}
})
)(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)
}
2 changes: 2 additions & 0 deletions src/locales/en_US.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
2 changes: 2 additions & 0 deletions src/locales/strings/enUS.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 8f4ffde

Please sign in to comment.