import {io} from "socket.io-client"; import {useStore} from "@/store/store.js"; import {onChainChanged} from "@/blockchain/wallet.js"; import {ethers} from "ethers"; export const socket = io(import.meta.env.VITE_WS_URL || undefined, { transports: ["websocket"] }) socket.on('connect', ()=>{ console.log('ws connected') }) socket.on('disconnect', ()=>{ console.log('ws disconnected') }) socket.on('welcome', async (data)=>{ console.log('welcome',data) const s = useStore() s.chainInfo = data.chainInfo s.vaultInitCodeHash = data.vaultInitCodeHash const p = new ethers.BrowserProvider(window.ethereum) const network = await p.getNetwork() if( network !== null ) onChainChanged(network.chainId) })