order pending bugfix
This commit is contained in:
@@ -85,15 +85,31 @@ export async function connectWallet() {
|
|||||||
// eth_getaccounts
|
// eth_getaccounts
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const pendingOrders = []
|
||||||
|
|
||||||
export function pendOrder(order) {
|
export async function pendOrder(order) {
|
||||||
console.log('order', JSON.stringify(order))
|
console.log('order', JSON.stringify(order))
|
||||||
const s = useStore()
|
const s = useStore()
|
||||||
const vault = s.vault;
|
const signer = await s.provider.getSigner()
|
||||||
if(vault === null ) {
|
if (!s.vaults.length) {
|
||||||
console.error('vault was null during pendOrder')
|
pendingOrders.push(order)
|
||||||
return
|
const owner = await signer.getAddress();
|
||||||
|
socket.emit('ensureVault', s.chainId, owner, 0)
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
const vault = s.vaults[0];
|
||||||
|
pendOrderAsTransaction(vault, order)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
export function flushOrders(vault) {
|
||||||
|
for( const order of pendingOrders )
|
||||||
|
pendOrderAsTransaction(vault, order)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function pendOrderAsTransaction(vault, order) {
|
||||||
pendTransaction(async (signer)=> {
|
pendTransaction(async (signer)=> {
|
||||||
const contract = contractOrNull(vault, vaultAbi, signer)
|
const contract = contractOrNull(vault, vaultAbi, signer)
|
||||||
if( contract === null ) {
|
if( contract === null ) {
|
||||||
@@ -139,10 +155,6 @@ export async function asyncFlushTransactions() {
|
|||||||
console.log('signer denied')
|
console.log('signer denied')
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if (!s.vaults.length) {
|
|
||||||
socket.emit('ensureVault', s.chainId, await signer.getAddress(), 0)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
for (const sender of senders)
|
for (const sender of senders)
|
||||||
doSendTransaction(sender, signer)
|
doSendTransaction(sender, signer)
|
||||||
}
|
}
|
||||||
@@ -168,10 +180,3 @@ function doSendTransaction(sender, signer) {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
socket.on('vaults', (vaults)=>{
|
|
||||||
const s = useStore()
|
|
||||||
console.log('vaults', vaults)
|
|
||||||
s.vaults = vaults
|
|
||||||
flushTransactions()
|
|
||||||
})
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import {io} from "socket.io-client";
|
import {io} from "socket.io-client";
|
||||||
import {useStore} from "@/store/store.js";
|
import {useStore} from "@/store/store.js";
|
||||||
import {onChainChanged} from "@/blockchain/wallet.js";
|
import {flushOrders, onChainChanged} from "@/blockchain/wallet.js";
|
||||||
import {ethers} from "ethers";
|
import {ethers} from "ethers";
|
||||||
|
|
||||||
export const socket = io(import.meta.env.VITE_WS_URL || undefined, {transports: ["websocket"]})
|
export const socket = io(import.meta.env.VITE_WS_URL || undefined, {transports: ["websocket"]})
|
||||||
@@ -39,3 +39,13 @@ socket.on('vb', async (vault, balances) => {
|
|||||||
s.$patch({vaultBalances:vb})
|
s.$patch({vaultBalances:vb})
|
||||||
console.log('vault balances', vault, vb)
|
console.log('vault balances', vault, vb)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
socket.on('vaults', (vaults)=>{
|
||||||
|
const s = useStore()
|
||||||
|
console.log('vaults', vaults)
|
||||||
|
s.vaults = vaults
|
||||||
|
if( vaults.length ) {
|
||||||
|
const vault = vaults[0]
|
||||||
|
flushOrders(vault)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user