pair price display fixes

This commit is contained in:
Tim
2024-03-29 16:48:12 -04:00
parent 12aa7bec5d
commit bb1bc3d966
2 changed files with 19 additions and 10 deletions

View File

@@ -6,7 +6,7 @@
<template v-slot:item.input="{ item }"> <template v-slot:item.input="{ item }">
<suspense v-if="item.order.amountIsInput"> <suspense v-if="item.order.amountIsInput">
<span> <span>
<token-amount :addr="item.order.tokenIn" :amount="item.filled" :raw="true"/> <token-amount :addr="item.order.tokenIn" :amount="item.filledIn" :raw="true"/>
/ /
<token-amount :addr="item.order.tokenIn" :amount="item.order.amount"/> <token-amount :addr="item.order.tokenIn" :amount="item.order.amount"/>
</span> </span>
@@ -18,7 +18,7 @@
<template v-slot:item.output="{ item }"> <template v-slot:item.output="{ item }">
<suspense v-if="!item.order.amountIsInput"> <suspense v-if="!item.order.amountIsInput">
<span> <span>
<token-amount :addr="item.order.tokenOut" :amount="item.filled" :raw="true"/> <token-amount :addr="item.order.tokenOut" :amount="item.filledOut" :raw="true"/>
/ /
<token-amount :addr="item.order.tokenOut" :amount="item.order.amount"/> <token-amount :addr="item.order.tokenOut" :amount="item.order.amount"/>
</span> </span>

View File

@@ -120,7 +120,10 @@ export function pairPriceAddr(chainId, baseTokenAddr, quoteTokenAddr, price) {
export function flipInversionPreference(chainId, base, quote) { export function flipInversionPreference(chainId, base, quote) {
const k = pairKey(chainId, base, quote) const inverted = base.a > quote.a
const token0 = !inverted ? base.a : quote.a
const token1 = inverted ? base.a : quote.a
const k = [chainId, token0, token1];
const prefs = usePrefStore() const prefs = usePrefStore()
prefs.inverted[k] = !prefs.inverted[k] prefs.inverted[k] = !prefs.inverted[k]
} }
@@ -128,36 +131,42 @@ export function flipInversionPreference(chainId, base, quote) {
export function inversionPreference(chainId, base, quote) { export function inversionPreference(chainId, base, quote) {
// returns the user preference for whether to invert this pair or not // returns the user preference for whether to invert this pair or not
const invertedKey = pairKey(chainId, base, quote); const inputInverted = base.a > quote.a
const token0 = !inputInverted ? base.a : quote.a
const token1 = inputInverted ? base.a : quote.a
const key = [chainId, token0, token1];
const prefs = usePrefStore() const prefs = usePrefStore()
if (!(invertedKey in prefs.inverted)) { if (!(key in prefs.inverted)) {
// todo prefer stablecoins as the quote asset // todo prefer stablecoins as the quote asset
let inverted = false; let preferInverted = false;
for (const q of QUOTE_SYMBOLS) { for (const q of QUOTE_SYMBOLS) {
if (quote.s === q) if (quote.s === q)
break // definitely not inverted break // definitely not inverted
if (base.s === q) { if (base.s === q) {
inverted = true preferInverted = true
break // definitely inverted break // definitely inverted
} }
} }
prefs.inverted[invertedKey] = inverted prefs.inverted[key] = preferInverted
} }
return prefs.inverted[invertedKey] console.log('inversion preference', base, quote, prefs.inverted[key], inputInverted)
return prefs.inverted[key] !== inputInverted
} }
export function pairPrice(chainId, baseToken, quoteToken, price) { export function pairPrice(chainId, baseToken, quoteToken, price) {
// console.warn('pairPrice', chainId, baseToken, quoteToken, price, decimals)
if (price === null || price === undefined) if (price === null || price === undefined)
return null return null
const decimals = quoteToken.d - baseToken.d const decimals = quoteToken.d - baseToken.d
// console.log('pairPrice', chainId, baseToken, quoteToken, price, decimals)
if (decimals >= 0) if (decimals >= 0)
price /= 10 ** decimals price /= 10 ** decimals
else else
price *= 10 ** -decimals price *= 10 ** -decimals
// console.log('adjusted pairPrice', price)
if (inversionPreference(chainId, baseToken, quoteToken)) if (inversionPreference(chainId, baseToken, quoteToken))
price = 1 / price price = 1 / price
// console.log('inverted?', price)
return price return price
} }