1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-12-23 09:52:26 +01:00

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>
This commit is contained in:
Thomas Huang 2020-10-28 00:08:02 -07:00 committed by GitHub
parent 557f9550d7
commit 0494f72128
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 4 deletions

View File

@ -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 }
}

View File

@ -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])