initial websocket setup

This commit is contained in:
Tim Olson
2023-08-28 20:29:56 -04:00
parent 054fe2cfa9
commit 274e1dfd7e
8 changed files with 123 additions and 15 deletions

View File

@@ -79,26 +79,31 @@ import {ethers} from "ethers";
import wallet from "@/blockchain/wallet.js";
import {erc20Abi} from "@/blockchain/abi.js";
import {useStore} from "@/store/store.js";
import {socket} from "@/socket.js";
const s = useStore()
async function addExtraToken(addr) {
const token = new ethers.Contract(addr, erc20Abi, await wallet.provider())
const symbol = await token.symbol()
const decimals = Number(await token.decimals())
const info = {name:`${symbol} (${addr})`, symbol, decimals, address:addr}
s.$patch((state)=>{
let extras = state.extraTokens[state.chain.id]
if( extras === undefined ) {
extras = {}
state.extraTokens[state.chain.id] = extras
}
extras[info.address] = info
const prom = new Promise((resolve)=>{
socket.emit('lookupToken', s.chain.id, addr, (info) => {
if( info === null )
return resolve(null)
s.$patch((state)=>{
let extras = state.extraTokens[state.chain.id]
if( extras === undefined ) {
extras = {}
state.extraTokens[state.chain.id] = extras
}
extras[info.address] = info
})
resolve(info)
})
})
return info
return await prom
}
</script>
<style scoped lang="scss">
@use "src/styles/vars" as *;