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