Skip to content

Commit

Permalink
fix: prices must be in Fraction before division
Browse files Browse the repository at this point in the history
  • Loading branch information
alfetopito committed Jan 16, 2025
1 parent d672231 commit 4903127
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,9 @@ export function SpotPricesUpdater(): null {
return
}

const fraction = inputPrice.price.divide(outputPrice.price)
const inputFraction = FractionUtils.fractionLikeToFraction(inputPrice.price)
const outputFraction = FractionUtils.fractionLikeToFraction(outputPrice.price)
const fraction = inputFraction.divide(outputFraction)

if (!fraction) {
return
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useEffect, useState } from 'react'

import { getWrappedToken } from '@cowprotocol/common-utils'
import { FractionUtils, getWrappedToken } from '@cowprotocol/common-utils'
import { Fraction } from '@uniswap/sdk-core'

import { useAsyncMemo } from 'use-async-memo'
Expand Down Expand Up @@ -32,7 +32,9 @@ export function useGetInitialPrice(): { price: Fraction | null; isLoading: boole
if (!inputUsdPrice?.price || !outputUsdPrice?.price) {
return null
}
return inputUsdPrice.price.divide(outputUsdPrice.price)
const inputFraction = FractionUtils.fractionLikeToFraction(inputUsdPrice.price)
const outputFraction = FractionUtils.fractionLikeToFraction(outputUsdPrice.price)
return inputFraction.divide(outputFraction)
},
[inputUsdPrice?.price, outputUsdPrice?.price],
null,
Expand Down

0 comments on commit 4903127

Please sign in to comment.