Skip to content

Commit

Permalink
fix token decimals
Browse files Browse the repository at this point in the history
  • Loading branch information
sehyunc committed Mar 22, 2024
1 parent a1aacc3 commit 99811bd
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
1 change: 0 additions & 1 deletion trade.renegade.fi/app/providers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,6 @@ export function Providers({
}: PropsWithChildren & {
icons?: Record<string, string>
}) {
console.log("🚀 ~ icons:", icons)
useEffect(() => {
async function loadUtils() {
await renegade.init()
Expand Down
23 changes: 13 additions & 10 deletions trade.renegade.fi/components/live-price.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,16 @@ export const LivePrices = ({

const baseDefaultDecimals = TICKER_TO_DEFAULT_DECIMALS[baseTicker] || 0
const trailingDecimals = useMemo(() => {
if (quoteTicker !== "USDC") {
if (["USDC", "WETH", "WBTC"].includes(baseTicker)) {
return 2
} else if (quoteTicker !== "USDC") {
return 2
} else if (baseDefaultDecimals >= 3) {
return 2
} else {
return Math.abs(baseDefaultDecimals) + 2
}
}, [baseDefaultDecimals, quoteTicker])
}, [baseDefaultDecimals, baseTicker, quoteTicker])

const callbackIdRef = useRef(false)
useEffect(() => {
Expand Down Expand Up @@ -98,11 +100,11 @@ export const LivePrices = ({

let price = currentPriceReport.midpointPrice
? currentPriceReport.midpointPrice
: priceProp
? priceProp
: baseTicker === "USDC"
? 1
: 0
? 1
: priceProp
? priceProp
: 0

// If the caller supplied a scaleBy prop, scale the price appropriately
if (scaleBy !== undefined) {
Expand All @@ -113,7 +115,8 @@ export const LivePrices = ({
let priceStr = price.toFixed(trailingDecimals)
if (
(!Object.keys(currentPriceReport).length || scaleBy === 0) &&
baseDefaultDecimals > 0
baseDefaultDecimals > 0 &&
baseTicker !== "USDC"
) {
const leadingDecimals = priceStr.split(".")[0].length
priceStr =
Expand Down Expand Up @@ -176,9 +179,9 @@ export const LivePrices = ({
sx={
isMobile
? {
writingMode: "vertical-rl",
textOrientation: "sideways",
}
writingMode: "vertical-rl",
textOrientation: "sideways",
}
: undefined
}
alignItems="center"
Expand Down

0 comments on commit 99811bd

Please sign in to comment.