Skip to content

Commit

Permalink
feat: use the usdPrice from the providerTokens array
Browse files Browse the repository at this point in the history
  • Loading branch information
juanmahidalgo committed Nov 27, 2023
1 parent 2ef90fd commit 59b1241
Showing 1 changed file with 10 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -215,20 +215,17 @@ export const BuyWithCryptoModal = (props: Props) => {
}, [route])

const routeTotalUSDCost = useMemo(() => {
if (
route &&
routeFeeCost &&
routeFeeCost.token.usdPrice &&
fromAmount &&
selectedToken?.usdPrice
) {
if (route && routeFeeCost && fromAmount && selectedToken?.usdPrice) {
const { feeCost, gasCost } = routeFeeCost
const tokenPrice = providerTokens.find(
t => t.symbol === routeFeeCost.token.symbol
)?.usdPrice
return (
routeFeeCost.token.usdPrice * (Number(gasCost) + Number(feeCost)) +
tokenPrice! * (Number(gasCost) + Number(feeCost)) +
selectedToken.usdPrice * Number(fromAmount)
)
}
}, [fromAmount, route, routeFeeCost, selectedToken])
}, [fromAmount, providerTokens, route, routeFeeCost, selectedToken.usdPrice])

// useEffects

Expand Down Expand Up @@ -1063,13 +1060,15 @@ export const BuyWithCryptoModal = (props: Props) => {
)}
/>
)}
{!!routeFeeCost && routeFeeCost.token.usdPrice ? (
{!!routeFeeCost ? (
<span className={styles.fromAmountUSD}>
≈ $
{(
(Number(routeFeeCost.feeCost) +
Number(routeFeeCost.gasCost)) *
routeFeeCost.token.usdPrice
providerTokens.find(
t => t.symbol === routeFeeCost.token.symbol
)?.usdPrice!
).toFixed(4)}
</span>
) : null}
Expand Down

0 comments on commit 59b1241

Please sign in to comment.