orders view fixes
This commit is contained in:
57
src/misc.js
57
src/misc.js
@@ -3,6 +3,19 @@ import {usePrefStore, useStore} from "@/store/store.js";
|
||||
import {token} from "@/blockchain/token.js";
|
||||
import Color from "color";
|
||||
|
||||
const QUOTE_SYMBOLS = [
|
||||
// in order of preference
|
||||
// todo put this in metadata.json using addrs
|
||||
'USDT',
|
||||
'USDC',
|
||||
'USDC.e',
|
||||
'BTC',
|
||||
'WBTC',
|
||||
'ETH',
|
||||
'WETH',
|
||||
'ARB',
|
||||
]
|
||||
|
||||
export class SingletonCoroutine {
|
||||
constructor(f, delay = 10) {
|
||||
this.f = f
|
||||
@@ -106,24 +119,44 @@ export function pairPriceAddr(chainId, baseTokenAddr, quoteTokenAddr, price) {
|
||||
}
|
||||
|
||||
|
||||
export function pairPrice(chainId, baseToken, quoteToken, price, decimals = null) {
|
||||
export function flipInversionPreference(chainId, base, quote) {
|
||||
const k = pairKey(chainId, base, quote)
|
||||
const prefs = usePrefStore()
|
||||
prefs.inverted[k] = !prefs.inverted[k]
|
||||
}
|
||||
|
||||
|
||||
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 prefs = usePrefStore()
|
||||
if (!(invertedKey in prefs.inverted)) {
|
||||
// todo prefer stablecoins as the quote asset
|
||||
let inverted = false;
|
||||
for (const q of QUOTE_SYMBOLS) {
|
||||
if (quote.s === q)
|
||||
break // definitely not inverted
|
||||
if (base.s === q) {
|
||||
inverted = true
|
||||
break // definitely inverted
|
||||
}
|
||||
}
|
||||
prefs.inverted[invertedKey] = inverted
|
||||
}
|
||||
return prefs.inverted[invertedKey]
|
||||
}
|
||||
|
||||
|
||||
export function pairPrice(chainId, baseToken, quoteToken, price) {
|
||||
// console.warn('pairPrice', chainId, baseToken, quoteToken, price, decimals)
|
||||
if (!price) return null
|
||||
if (price === null || price === undefined)
|
||||
return price
|
||||
if (decimals === null)
|
||||
decimals = baseToken.d - quoteToken.d
|
||||
return null
|
||||
const decimals = quoteToken.d - baseToken.d
|
||||
if (decimals >= 0)
|
||||
price /= 10 ** decimals
|
||||
else
|
||||
price *= 10 ** -decimals
|
||||
const invertedKey = pairKey(chainId, baseToken, quoteToken);
|
||||
const prefs = usePrefStore()
|
||||
if (!(invertedKey in prefs.inverted)) {
|
||||
// todo prefer stablecoins as the quote asset
|
||||
prefs.inverted[invertedKey] = false
|
||||
}
|
||||
if (prefs.inverted[invertedKey])
|
||||
if (inversionPreference(chainId, baseToken, quoteToken))
|
||||
price = 1 / price
|
||||
return price
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user