metadata has chainId as first key
This commit is contained in:
@@ -143,10 +143,16 @@ function addSymbol(p, base, quote, inverted) {
|
|||||||
|
|
||||||
async function getAllSymbols() {
|
async function getAllSymbols() {
|
||||||
if (_symbols===null) {
|
if (_symbols===null) {
|
||||||
|
const chainId = useStore().chainId.value;
|
||||||
|
const md = metadata[chainId]
|
||||||
|
if(!md) {
|
||||||
|
console.log('could not get metadata for chain', chainId)
|
||||||
|
return []
|
||||||
|
}
|
||||||
_symbols = {}
|
_symbols = {}
|
||||||
for (const t of metadata.t)
|
for (const t of md.t)
|
||||||
tokenMap[t.a] = t
|
tokenMap[t.a] = t
|
||||||
metadata.p.forEach((p)=>{
|
md.p.forEach((p)=>{
|
||||||
poolMap[p.a] = p
|
poolMap[p.a] = p
|
||||||
const base = tokenMap[p.b];
|
const base = tokenMap[p.b];
|
||||||
const quote = tokenMap[p.q];
|
const quote = tokenMap[p.q];
|
||||||
@@ -173,24 +179,24 @@ export function lookupSymbol(key) { // lookup by fullname
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function lookupBaseQuote(baseAddr, quoteAddr) {
|
export function lookupBaseQuote(baseAddr, quoteAddr) {
|
||||||
|
return _symbols[`${baseAddr}${quoteAddr}`]
|
||||||
return _symbols[key]
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function poolIsInverted(pool) {
|
function poolIsInverted(pool) {
|
||||||
|
const chainId = useStore().chainId.value
|
||||||
let p
|
let p
|
||||||
for (p of metadata.p) {
|
for (p of metadata[chainId].p) {
|
||||||
if (p.a==pool.substr(0,42)) {
|
if (p.a===pool.substr(0,42)) {
|
||||||
let fullname = `${p.q}${p.b}`
|
let fullname = `${p.q}${p.b}`
|
||||||
let symbol = lookupSymbol(fullname)
|
let symbol = lookupSymbol(fullname)
|
||||||
if (symbol in [undefined, null]) {
|
if (symbol in [undefined, null]) {
|
||||||
throw error(`poolIsInverted: pool fullname not found: ${fullname}`)
|
throw Error(`poolIsInverted: pool fullname not found: ${fullname}`)
|
||||||
}
|
}
|
||||||
return symbol.inverted
|
return symbol.inverted
|
||||||
// return p.x.data.inverted ^ symbol.inverted
|
// return p.x.data.inverted ^ symbol.inverted
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
throw error(`poolIsInverted: pool not found in metadata.json: ${pool}`)
|
throw Error(`poolIsInverted: pool not found in metadata.json: ${pool}`)
|
||||||
}
|
}
|
||||||
|
|
||||||
export function maybeInvertBar (pool, bar) {
|
export function maybeInvertBar (pool, bar) {
|
||||||
|
|||||||
@@ -19,8 +19,12 @@ export const metadata = await metadataPromise
|
|||||||
console.log('metadata', metadata)
|
console.log('metadata', metadata)
|
||||||
|
|
||||||
export const metadataMap = {}
|
export const metadataMap = {}
|
||||||
for (const poolMeta of metadata.p)
|
for (const [chain, info] of Object.entries(metadata)) {
|
||||||
metadataMap[poolMeta.a] = poolMeta
|
const map = {}
|
||||||
for (const tokenMeta of metadata.t)
|
for (const poolMeta of info.p)
|
||||||
metadataMap[tokenMeta.a] = tokenMeta
|
map[poolMeta.a] = poolMeta
|
||||||
|
for (const tokenMeta of info.t)
|
||||||
|
map[tokenMeta.a] = tokenMeta
|
||||||
|
metadataMap[chain] = map
|
||||||
|
}
|
||||||
console.log('metadataMap', metadataMap)
|
console.log('metadataMap', metadataMap)
|
||||||
Reference in New Issue
Block a user