order status updates working
This commit is contained in:
11
src/blockchain/common.js
Normal file
11
src/blockchain/common.js
Normal 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)
|
||||
}
|
||||
@@ -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))
|
||||
|
||||
@@ -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];
|
||||
|
||||
Reference in New Issue
Block a user