pair price display fixes
This commit is contained in:
@@ -6,7 +6,7 @@
|
||||
<template v-slot:item.input="{ item }">
|
||||
<suspense v-if="item.order.amountIsInput">
|
||||
<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"/>
|
||||
</span>
|
||||
@@ -18,7 +18,7 @@
|
||||
<template v-slot:item.output="{ item }">
|
||||
<suspense v-if="!item.order.amountIsInput">
|
||||
<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"/>
|
||||
</span>
|
||||
|
||||
25
src/misc.js
25
src/misc.js
@@ -120,7 +120,10 @@ export function pairPriceAddr(chainId, baseTokenAddr, quoteTokenAddr, price) {
|
||||
|
||||
|
||||
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()
|
||||
prefs.inverted[k] = !prefs.inverted[k]
|
||||
}
|
||||
@@ -128,36 +131,42 @@ export function flipInversionPreference(chainId, base, quote) {
|
||||
|
||||
export function inversionPreference(chainId, base, quote) {
|
||||
// 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()
|
||||
if (!(invertedKey in prefs.inverted)) {
|
||||
if (!(key in prefs.inverted)) {
|
||||
// todo prefer stablecoins as the quote asset
|
||||
let inverted = false;
|
||||
let preferInverted = false;
|
||||
for (const q of QUOTE_SYMBOLS) {
|
||||
if (quote.s === q)
|
||||
break // definitely not inverted
|
||||
if (base.s === q) {
|
||||
inverted = true
|
||||
preferInverted = true
|
||||
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) {
|
||||
// console.warn('pairPrice', chainId, baseToken, quoteToken, price, decimals)
|
||||
if (price === null || price === undefined)
|
||||
return null
|
||||
const decimals = quoteToken.d - baseToken.d
|
||||
// console.log('pairPrice', chainId, baseToken, quoteToken, price, decimals)
|
||||
if (decimals >= 0)
|
||||
price /= 10 ** decimals
|
||||
else
|
||||
price *= 10 ** -decimals
|
||||
// console.log('adjusted pairPrice', price)
|
||||
if (inversionPreference(chainId, baseToken, quoteToken))
|
||||
price = 1 / price
|
||||
// console.log('inverted?', price)
|
||||
return price
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user