Skip to content

Commit

Permalink
Show fiat amounts inline on token transfers
Browse files Browse the repository at this point in the history
Fiat amounts are now shown inline on token transfers in the transaction
list, where possible (i.e. where the conversion rates are known).

The logic for this hook is pretty tangled because it's used for so many
fundamentally different types of items (eth transactions, token
transactions, signature requests). In the future we should split these
into different components.

The documentation for the `useTokenFiatAmount` hook was updated to make
`tokenAmount` optional, but in practice it already worked as expected
without the amount being passed in.
  • Loading branch information
Gudahtt committed Jun 11, 2020
1 parent 058c63c commit 18577d7
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
2 changes: 1 addition & 1 deletion ui/app/hooks/useTokenFiatAmount.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { getFormattedTokenFiatAmount } from '../helpers/utils/token-util'
/**
* Get the token balance converted to fiat and formatted for display
*
* @param {string} tokenAddress - The token address
* @param {string} [tokenAddress] - The token address
* @param {string} [tokenAmount] - The token balance
* @param {string} [tokenSymbol] - The token symbol
* @return {string} - The formatted token amount in the user's chosen fiat currency
Expand Down
11 changes: 7 additions & 4 deletions ui/app/hooks/useTransactionDisplayData.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { getKnownMethodData } from '../selectors/selectors'
import { getTransactionActionKey, getStatusKey } from '../helpers/utils/transactions.util'
import { camelCaseToCapitalize } from '../helpers/utils/common.util'
import { useI18nContext } from './useI18nContext'
import { useTokenFiatAmount } from './useTokenFiatAmount'
import { PRIMARY, SECONDARY } from '../helpers/constants/common'
import { getTokenToAddress } from '../helpers/utils/token-util'
import { useUserPreferencedCurrency } from './useUserPreferencedCurrency'
Expand Down Expand Up @@ -84,6 +85,7 @@ export function useTransactionDisplayData (transactionGroup) {
const token = isTokenCategory && knownTokens.find((token) => token.address === recipientAddress)
const tokenData = useTokenData(initialTransaction?.txParams?.data, isTokenCategory)
const tokenDisplayValue = useTokenDisplayValue(initialTransaction?.txParams?.data, token, isTokenCategory)
const tokenFiatAmount = useTokenFiatAmount(token?.address, tokenDisplayValue, token?.symbol)

let category
let title
Expand Down Expand Up @@ -127,14 +129,15 @@ export function useTransactionDisplayData (transactionGroup) {

const [primaryCurrency] = useCurrencyDisplay(primaryValue, {
prefix,
displayValue: isTokenCategory && tokenDisplayValue,
suffix: isTokenCategory && token?.symbol,
displayValue: isTokenCategory ? tokenDisplayValue : undefined,
suffix: isTokenCategory ? token?.symbol : undefined,
...primaryCurrencyPreferences,
})

const [secondaryCurrency] = useCurrencyDisplay(primaryValue, {
prefix,
displayValue: isTokenCategory && tokenDisplayValue,
displayValue: isTokenCategory ? tokenFiatAmount : undefined,
hideLabel: isTokenCategory ? true : undefined,
...secondaryCurrencyPreferences,
})

Expand All @@ -146,7 +149,7 @@ export function useTransactionDisplayData (transactionGroup) {
primaryCurrency,
senderAddress,
recipientAddress,
secondaryCurrency: isTokenCategory ? undefined : secondaryCurrency,
secondaryCurrency: isTokenCategory && !tokenFiatAmount ? undefined : secondaryCurrency,
status,
isPending: status in PENDING_STATUS_HASH,
}
Expand Down

0 comments on commit 18577d7

Please sign in to comment.