Check if swapTokenValue is negative and set prefix accordingly (#9743)

* Check if swapTokenValue is negative and set prefix accordingly

Co-authored-by: Mark Stacey <markjstacey@gmail.com>

Co-authored-by: Mark Stacey <markjstacey@gmail.com>
feature/default_network_editable
Thomas Huang 4 years ago committed by GitHub
parent 557f9550d7
commit 0494f72128
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 7
      ui/app/hooks/useSwappedTokenValue.js
  2. 11
      ui/app/hooks/useTransactionDisplayData.js

@ -44,6 +44,11 @@ export function useSwappedTokenValue (transactionGroup, currentAsset) {
decimals,
)
: transactionCategory === SWAP && primaryTransaction.swapTokenValue
const isNegative = typeof swapTokenValue === 'string'
? Math.sign(swapTokenValue) === -1
: false
const _swapTokenFiatAmount = useTokenFiatAmount(
address,
swapTokenValue || '',
@ -52,5 +57,5 @@ export function useSwappedTokenValue (transactionGroup, currentAsset) {
const swapTokenFiatAmount = (
swapTokenValue && isViewingReceivedTokenFromSwap && _swapTokenFiatAmount
)
return { swapTokenValue, swapTokenFiatAmount, isViewingReceivedTokenFromSwap }
return { swapTokenValue, swapTokenFiatAmount, isViewingReceivedTokenFromSwap, isNegative }
}

@ -115,7 +115,7 @@ export function useTransactionDisplayData (transactionGroup) {
// The primary title of the Tx that will be displayed in the activity list
let title
const { swapTokenValue, swapTokenFiatAmount, isViewingReceivedTokenFromSwap } = useSwappedTokenValue(transactionGroup, currentAsset)
const { swapTokenValue, isNegative, swapTokenFiatAmount, isViewingReceivedTokenFromSwap } = useSwappedTokenValue(transactionGroup, currentAsset)
// There are seven types of transaction entries that are currently differentiated in the design
// 1. Signature request
@ -145,8 +145,13 @@ export function useTransactionDisplayData (transactionGroup) {
: initialTransaction.sourceTokenSymbol
primaryDisplayValue = swapTokenValue
secondaryDisplayValue = swapTokenFiatAmount
prefix = isViewingReceivedTokenFromSwap ? '+' : '-'
if (isNegative) {
prefix = ''
} else if (isViewingReceivedTokenFromSwap) {
prefix = '+'
} else {
prefix = '-'
}
} else if (transactionCategory === SWAP_APPROVAL) {
category = TRANSACTION_CATEGORY_APPROVAL
title = t('swapApproval', [primaryTransaction.sourceTokenSymbol])

Loading…
Cancel
Save