initial websocket setup
This commit is contained in:
@@ -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 *;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user