major refactor of web store into vue setup style declaration; reactivity debugging; order view has known refresh issues
This commit is contained in:
@@ -16,25 +16,28 @@ export function subPrices( routes ) {
|
||||
let chainId = null
|
||||
for( const route of routes ) {
|
||||
// console.log('sub route', route, subscriptionCounts)
|
||||
if( !(route in subscriptionCounts) || subscriptionCounts[route] === 0 ) {
|
||||
subscriptionCounts[route] = 1
|
||||
// console.log('subscribing to pool', route.pool)
|
||||
const routeKey = [route.chainId, route.pool]
|
||||
if( !(routeKey in subscriptionCounts) || subscriptionCounts[routeKey] === 0 ) {
|
||||
subscriptionCounts[routeKey] = 1
|
||||
subRoutes.push(route)
|
||||
}
|
||||
else {
|
||||
subscriptionCounts[route]++
|
||||
subscriptionCounts[routeKey]++
|
||||
}
|
||||
if( chainId !== null && route.chainId !== chainId )
|
||||
throw Error('cannot mix chainIds in a subscription list')
|
||||
chainId = route.chainId
|
||||
}
|
||||
if( subRoutes.length ) {
|
||||
socket.emit('subPools', chainId, routes.map((r)=>r.pool) )
|
||||
const pools = routes.map((r)=>r.pool);
|
||||
// console.log('subscribing to pools', pools)
|
||||
socket.emit('subPools', chainId, pools )
|
||||
// perform a local query if necessary
|
||||
const s = useStore()
|
||||
for( const route of subRoutes ) {
|
||||
const s = useStore()
|
||||
if( !(route.pool in s.poolPrices) ) {
|
||||
getPriceForRoute(route).then((price)=>s.poolPrices[route.pool]=price)
|
||||
const routeKey = [route.chainId, route.pool]
|
||||
if( !(routeKey in s.poolPrices) ) {
|
||||
getPriceForRoute(route).then((price)=>s.poolPrices[routeKey]=price)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -45,26 +48,27 @@ export function unsubPrices( routes ) {
|
||||
const unsubAddrs = []
|
||||
for( const route of routes ) {
|
||||
// console.log('unsub route', route, subscriptionCounts)
|
||||
if( !(route in subscriptionCounts) ) {
|
||||
const routeKey = [route.chainId, route.pool]
|
||||
if( !(routeKey in subscriptionCounts) ) {
|
||||
console.error('unsubscribed to a nonexistent route', route)
|
||||
}
|
||||
else {
|
||||
subscriptionCounts[route]--
|
||||
if( subscriptionCounts[route] === 0 ) {
|
||||
subscriptionCounts[routeKey]--
|
||||
if( subscriptionCounts[routeKey] === 0 ) {
|
||||
unsubAddrs.push(route.pool)
|
||||
if( chainId !== null && route.chainId !== chainId )
|
||||
throw Error('cannot mix chainIds in a subscription list')
|
||||
// console.log('unsubscribing from pool', route.pool)
|
||||
chainId = route.chainId
|
||||
}
|
||||
else if( subscriptionCounts[route] < 0 ) {
|
||||
else if( subscriptionCounts[routeKey] < 0 ) {
|
||||
console.error('unsubscribed to an already unsubbed route', route)
|
||||
subscriptionCounts[route] = 0 // fix
|
||||
subscriptionCounts[routeKey] = 0 // fix
|
||||
}
|
||||
}
|
||||
}
|
||||
if( unsubAddrs.length )
|
||||
socket.emit('unsubPool', chainId, unsubAddrs )
|
||||
socket.emit('unsubPools', chainId, unsubAddrs )
|
||||
}
|
||||
|
||||
|
||||
@@ -86,7 +90,7 @@ async function getPriceForRoute(route) {
|
||||
price = price.div(FixedNumber.fromValue(2n**(96n*2n),0,WIDE_PRICE_FORMAT))
|
||||
price = price.round(18).toString()
|
||||
// console.log(`price for ${route.token0.symbol}/${route.token1.symbol}`,price)
|
||||
store.poolPrices[addr] = price
|
||||
store.poolPrices[[route.chainId,addr]] = price
|
||||
return price
|
||||
}
|
||||
else
|
||||
|
||||
Reference in New Issue
Block a user