Commit 52a43f3d authored by Jack Short's avatar Jack Short Committed by GitHub

chore: removeing fetch usd price for bag footer (#5903)

* chore: removing fetchUsdprice

* removing console
parent 0a2a46d5
import { BigNumber } from '@ethersproject/bignumber'
import { formatEther } from '@ethersproject/units'
import { sendAnalyticsEvent } from '@uniswap/analytics'
import { NFTEventName } from '@uniswap/analytics-events'
import { useWeb3React } from '@web3-react/core'
......@@ -24,14 +23,13 @@ import { fetchRoute } from 'nft/queries'
import { BagItemStatus, BagStatus, ProfilePageStateType, RouteResponse, TxStateType } from 'nft/types'
import {
buildSellObject,
fetchPrice,
formatAssetEventProperties,
recalculateBagUsingPooledAssets,
sortUpdatedAssets,
} from 'nft/utils'
import { combineBuyItemsWithTxRoute } from 'nft/utils/txRoute/combineItemsWithTxRoute'
import { useCallback, useEffect, useMemo, useRef, useState } from 'react'
import { useQuery, useQueryClient } from 'react-query'
import { useQueryClient } from 'react-query'
import styled from 'styled-components/macro'
import { Z_INDEX } from 'theme/zIndex'
import shallow from 'zustand/shallow'
......@@ -127,7 +125,6 @@ const Bag = () => {
bagExpanded,
toggleBag,
setTotalEthPrice,
setTotalUsdPrice,
setBagExpanded,
} = useBag((state) => ({ ...state, bagIsLocked: state.isLocked, uncheckedItemsInBag: state.itemsInBag }), shallow)
const { uncheckedItemsInBag } = useBag(({ itemsInBag }) => ({ uncheckedItemsInBag: itemsInBag }))
......@@ -158,9 +155,7 @@ const Bag = () => {
}
}
const { data: fetchedPriceData } = useQuery(['fetchPrice', {}], () => fetchPrice(), {})
const { totalEthPrice, totalUsdPrice } = useMemo(() => {
const { totalEthPrice } = useMemo(() => {
const totalEthPrice = itemsInBag.reduce(
(total, item) =>
item.status !== BagItemStatus.UNAVAILABLE
......@@ -172,10 +167,9 @@ const Bag = () => {
: total,
BigNumber.from(0)
)
const totalUsdPrice = fetchedPriceData ? parseFloat(formatEther(totalEthPrice)) * fetchedPriceData : undefined
return { totalEthPrice, totalUsdPrice }
}, [itemsInBag, fetchedPriceData])
return { totalEthPrice }
}, [itemsInBag])
const purchaseAssets = async (routingData: RouteResponse) => {
if (!provider || !routingData) return
......@@ -283,8 +277,7 @@ const Bag = () => {
useEffect(() => {
setTotalEthPrice(totalEthPrice)
setTotalUsdPrice(totalUsdPrice)
}, [totalEthPrice, totalUsdPrice, setTotalEthPrice, setTotalUsdPrice])
}, [totalEthPrice, setTotalEthPrice])
const hasAssetsToShow = itemsInBag.length > 0
......@@ -305,10 +298,9 @@ const Bag = () => {
const eventProperties = useMemo(
() => ({
usd_value: totalUsdPrice,
...formatAssetEventProperties(itemsInBag.map((item) => item.asset)),
}),
[itemsInBag, totalUsdPrice]
[itemsInBag]
)
if (!bagExpanded || !isNFTPage) {
......@@ -334,7 +326,6 @@ const Bag = () => {
{hasAssetsToShow && !isProfilePage && (
<BagFooter
totalEthPrice={totalEthPrice}
totalUsdPrice={totalUsdPrice}
bagStatus={bagStatus}
fetchAssets={fetchAssets}
eventProperties={eventProperties}
......
......@@ -123,7 +123,6 @@ const Warning = ({ children }: PropsWithChildren<unknown>) => {
interface BagFooterProps {
totalEthPrice: BigNumber
totalUsdPrice: number | undefined
bagStatus: BagStatus
fetchAssets: () => void
eventProperties: Record<string, unknown>
......@@ -136,13 +135,7 @@ const PENDING_BAG_STATUSES = [
BagStatus.PROCESSING_TRANSACTION,
]
export const BagFooter = ({
totalEthPrice,
totalUsdPrice,
bagStatus,
fetchAssets,
eventProperties,
}: BagFooterProps) => {
export const BagFooter = ({ totalEthPrice, bagStatus, fetchAssets, eventProperties }: BagFooterProps) => {
const toggleWalletModal = useToggleWalletModal()
const theme = useTheme()
const { account, chainId, connector } = useWeb3React()
......@@ -205,9 +198,8 @@ export const BagFooter = ({
const activeCurrency = inputCurrency ?? defaultCurrency
const parsedAmount = useMemo(() => {
if (!inputCurrency) return undefined
return tryParseCurrencyAmount(formatEther(totalEthPrice.toString()), defaultCurrency ?? undefined)
}, [defaultCurrency, totalEthPrice, inputCurrency])
}, [defaultCurrency, totalEthPrice])
const { state: swapState, trade: swapTrade } = useBestTrade(
TradeType.EXACT_OUTPUT,
......@@ -215,7 +207,7 @@ export const BagFooter = ({
inputCurrency ?? undefined
)
const usdcValue = useStablecoinValue(swapTrade?.inputAmount)
const usdcValue = useStablecoinValue(inputCurrency ? swapTrade?.inputAmount : parsedAmount)
return (
<FooterContainer>
......@@ -247,7 +239,7 @@ export const BagFooter = ({
&nbsp;{activeCurrency?.symbol ?? 'ETH'}
</ThemedText.HeadlineSmall>
<ThemedText.BodySmall color="textSecondary" lineHeight="20px">
{`${ethNumberStandardFormatter(inputCurrency ? usdcValue?.toExact() : totalUsdPrice, true)}`}
{`${ethNumberStandardFormatter(usdcValue?.toExact(), true)}`}
</ThemedText.BodySmall>
</TotalColumn>
</CurrencyRow>
......@@ -266,7 +258,7 @@ export const BagFooter = ({
</Row>
<Row justify="flex-end">
<ThemedText.BodySmall color="textSecondary" lineHeight="20px">{`${ethNumberStandardFormatter(
totalUsdPrice,
usdcValue?.toExact(),
true
)}`}</ThemedText.BodySmall>
</Row>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment