mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 09:52:26 +01:00
Data consistency swaps token balance (#9588)
* Explicitly set balance and string on the swaps from token in token-overview * Set swapsFromToken balance to a decimal instead of a hex on eth balance change in build-quote
This commit is contained in:
parent
4149fed6e0
commit
2563180a88
@ -38,8 +38,9 @@ const TokenOverview = ({ className, token }) => {
|
|||||||
const keyring = useSelector(getCurrentKeyring)
|
const keyring = useSelector(getCurrentKeyring)
|
||||||
const usingHardwareWallet = keyring.type.search('Hardware') !== -1
|
const usingHardwareWallet = keyring.type.search('Hardware') !== -1
|
||||||
const { tokensWithBalances } = useTokenTracker([token])
|
const { tokensWithBalances } = useTokenTracker([token])
|
||||||
const balance = tokensWithBalances[0]?.string
|
const balanceToRender = tokensWithBalances[0]?.string
|
||||||
const formattedFiatBalance = useTokenFiatAmount(token.address, balance, token.symbol)
|
const balance = tokensWithBalances[0]?.balance
|
||||||
|
const formattedFiatBalance = useTokenFiatAmount(token.address, balanceToRender, token.symbol)
|
||||||
const networkId = useSelector(getCurrentNetworkId)
|
const networkId = useSelector(getCurrentNetworkId)
|
||||||
const enteredSwapsEvent = useNewMetricEvent({ event: 'Swaps Opened', properties: { source: 'Token View', active_currency: token.symbol }, category: 'swaps' })
|
const enteredSwapsEvent = useNewMetricEvent({ event: 'Swaps Opened', properties: { source: 'Token View', active_currency: token.symbol }, category: 'swaps' })
|
||||||
const swapsEnabled = useSelector(getSwapsFeatureLiveness)
|
const swapsEnabled = useSelector(getSwapsFeatureLiveness)
|
||||||
@ -50,7 +51,7 @@ const TokenOverview = ({ className, token }) => {
|
|||||||
<div className="token-overview__balance">
|
<div className="token-overview__balance">
|
||||||
<CurrencyDisplay
|
<CurrencyDisplay
|
||||||
className="token-overview__primary-balance"
|
className="token-overview__primary-balance"
|
||||||
displayValue={balance}
|
displayValue={balanceToRender}
|
||||||
suffix={token.symbol}
|
suffix={token.symbol}
|
||||||
/>
|
/>
|
||||||
{
|
{
|
||||||
@ -87,7 +88,12 @@ const TokenOverview = ({ className, token }) => {
|
|||||||
onClick={() => {
|
onClick={() => {
|
||||||
if (networkId === MAINNET_NETWORK_ID) {
|
if (networkId === MAINNET_NETWORK_ID) {
|
||||||
enteredSwapsEvent()
|
enteredSwapsEvent()
|
||||||
dispatch(setSwapsFromToken({ ...token, iconUrl: assetImages[token.address] }))
|
dispatch(setSwapsFromToken({
|
||||||
|
...token,
|
||||||
|
iconUrl: assetImages[token.address],
|
||||||
|
balance,
|
||||||
|
string: balanceToRender,
|
||||||
|
}))
|
||||||
if (usingHardwareWallet) {
|
if (usingHardwareWallet) {
|
||||||
global.platform.openExtensionInBrowser(BUILD_QUOTE_ROUTE)
|
global.platform.openExtensionInBrowser(BUILD_QUOTE_ROUTE)
|
||||||
} else {
|
} else {
|
||||||
|
@ -24,7 +24,7 @@ import {
|
|||||||
getTopAssets,
|
getTopAssets,
|
||||||
getFetchParams,
|
getFetchParams,
|
||||||
} from '../../../ducks/swaps/swaps'
|
} from '../../../ducks/swaps/swaps'
|
||||||
import { getValueFromWeiHex } from '../../../helpers/utils/conversions.util'
|
import { getValueFromWeiHex, hexToDecimal } from '../../../helpers/utils/conversions.util'
|
||||||
import { calcTokenAmount } from '../../../helpers/utils/token-util'
|
import { calcTokenAmount } from '../../../helpers/utils/token-util'
|
||||||
import { usePrevious } from '../../../hooks/usePrevious'
|
import { usePrevious } from '../../../hooks/usePrevious'
|
||||||
import { useTokenTracker } from '../../../hooks/useTokenTracker'
|
import { useTokenTracker } from '../../../hooks/useTokenTracker'
|
||||||
@ -167,7 +167,11 @@ export default function BuildQuote ({
|
|||||||
// If the eth balance changes while on build quote, we update the selected from token
|
// If the eth balance changes while on build quote, we update the selected from token
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (fromToken?.address === ETH_SWAPS_TOKEN_OBJECT.address && (fromToken?.balance !== ethBalance)) {
|
if (fromToken?.address === ETH_SWAPS_TOKEN_OBJECT.address && (fromToken?.balance !== ethBalance)) {
|
||||||
dispatch(setSwapsFromToken({ ...fromToken, balance: ethBalance, string: getValueFromWeiHex({ value: ethBalance, numberOfDecimals: 4, toDenomination: 'ETH' }) }))
|
dispatch(setSwapsFromToken({
|
||||||
|
...fromToken,
|
||||||
|
balance: hexToDecimal(ethBalance),
|
||||||
|
string: getValueFromWeiHex({ value: ethBalance, numberOfDecimals: 4, toDenomination: 'ETH' }),
|
||||||
|
}))
|
||||||
}
|
}
|
||||||
}, [dispatch, fromToken, ethBalance])
|
}, [dispatch, fromToken, ethBalance])
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user