order status updates working

This commit is contained in:
Tim Olson
2023-11-08 23:18:36 -04:00
parent 077e664a30
commit f1bc632074
14 changed files with 259 additions and 21 deletions

11
src/blockchain/common.js Normal file
View File

@@ -0,0 +1,11 @@
export function applyFills( orderStatus, filled ) {
console.log('apply fills', orderStatus, filled)
orderStatus[4] = filled[0][0]
orderStatus[5] = filled[0][1]
for( const i in filled[1] ) {
const {filledIn, filledOut} = filled[1][i]
orderStatus[6][i] = filledIn
orderStatus[7][i] = filledOut
}
console.log('applied fills', orderStatus)
}

View File

@@ -3,6 +3,19 @@ import {useStore} from "@/store/store.js";
import {erc20Abi} from "@/blockchain/abi.js";
import {ethers} from "ethers";
// synchronous version may return null but will trigger a lookup
export function token(addr) {
const s = useStore()
if( !(addr in s.tokens) ) {
getToken(addr)
return null
}
return s.tokens[addr]
}
// async version doesnt return until it has a token value
export async function getToken(addr) {
const s = useStore()
if (!(addr in s.tokens))

View File

@@ -88,14 +88,27 @@ export async function connectWallet() {
const pendingOrders = []
export function ensureVault() {
const s = useStore()
if( !s.chain ) {
console.log('cannot create vault: no chain selected')
return
}
if( !s.account ) {
console.log('cannot create vault: no account logged in')
return
}
socket.emit('ensureVault', s.chainId, s.account, 0)
}
export async function pendOrder(order) {
console.log('order', JSON.stringify(order))
const s = useStore()
const signer = await s.provider.getSigner()
if (!s.vaults.length) {
pendingOrders.push(order)
const owner = await signer.getAddress();
socket.emit('ensureVault', s.chainId, owner, 0)
ensureVault()
}
else {
const vault = s.vaults[0];