major refactor of web store into vue setup style declaration; reactivity debugging; order view has known refresh issues

This commit is contained in:
Tim Olson
2023-11-27 00:52:17 -04:00
parent 41457b85f5
commit d2db5dc4f7
24 changed files with 545 additions and 364 deletions

View File

@@ -3,7 +3,6 @@ import {useStore} from "@/store/store.js";
import {flushOrders, onChainChanged} from "@/blockchain/wallet.js";
import {ethers} from "ethers";
import {applyFills} from "@/blockchain/common.js";
import {ref} from "vue";
export const socket = io(import.meta.env.VITE_WS_URL || undefined, {transports: ["websocket"]})
@@ -28,20 +27,16 @@ socket.on('welcome', async (data) => {
})
socket.on('p', async (chainId, pool, price) => {
console.log('pool price from message', chainId, pool, price)
const s = useStore()
if( s.chainId !== chainId )
if( s.chainId.value !== chainId )
return
const prices = {}
prices[pool] = price
console.log('pool price from message', pool, typeof price, price)
const poolPrices = s.poolPrices
poolPrices[pool] = price
s.poolPrices = poolPrices
s.poolPrices[[chainId,pool]] = price
})
socket.on('vb', async (chainId, vault, balances) => {
const s = useStore()
if( s.chainId !== chainId )
if( s.chainId.value !== chainId )
return
console.log('vb', vault, balances)
const vb = {}
@@ -52,9 +47,9 @@ socket.on('vb', async (chainId, vault, balances) => {
socket.on('vaults', (chainId, owner, vaults)=>{
const s = useStore()
if( s.chainId !== chainId || s.account !== owner )
return
console.log('vaults', vaults)
if( s.chainId.value !== chainId || s.account !== owner )
return
s.vaults = vaults
if( vaults.length ) {
const vault = vaults[0]
@@ -65,14 +60,12 @@ socket.on('vaults', (chainId, owner, vaults)=>{
function handleOrderStatus(chainId, vault, orderIndex, status) {
const s = useStore()
if( s.chainId !== chainId )
if( s.chainId.value !== chainId )
return
console.log('o', chainId, vault, orderIndex, status)
const orders = s.orders
if( !(vault in orders) )
orders[vault] = {}
orders[vault][orderIndex] = status
s.orders = orders
if( !(vault in s.orders) )
s.orders[vault] = {}
s.orders[vault][orderIndex] = status
}
socket.on('os', (chainId, vault, orders) => {
@@ -85,19 +78,18 @@ socket.on( 'o', handleOrderStatus)
socket.on( 'of', (chainId, vault, orderIndex, fills)=>{
const s = useStore()
if( s.chainId !== chainId )
if( s.chainId.value !== chainId )
return
console.log('of', chainId, vault, orderIndex, fills)
const orders = s.orders
if( !(vault in orders) ) {
if( !(vault in s.orders) ) {
console.log('warning: got fill on an order in an unknown vault')
return
}
if( !(orderIndex in orders[vault]) ) {
if( !(orderIndex in s.orders[vault]) ) {
console.log(`warning: orderIndex ${orderIndex} missing from vault ${vault}`)
return
}
const order = orders[vault][orderIndex]
const order = s.orders[vault][orderIndex]
applyFills(order, fills)
orders[vault][orderIndex] = order
s.orders[vault][orderIndex] = order
})