fix sendAsync call

pull/3951/head
yann300 1 year ago
parent ff08aa184f
commit bc7f13b438
  1. 14
      apps/remix-ide/src/blockchain/providers/vm.ts

@ -40,15 +40,25 @@ export class VMProvider {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
this.worker.addEventListener('message', (msg) => { this.worker.addEventListener('message', (msg) => {
if (msg.data.cmd === 'sendAsyncResult' && stamps[msg.data.stamp]) { if (msg.data.cmd === 'sendAsyncResult' && stamps[msg.data.stamp]) {
stamps[msg.data.stamp](msg.data.error, msg.data.result) if (stamps[msg.data.stamp].callback) {
stamps[msg.data.stamp].callback(msg.data.error, msg.data.result)
return
}
if (msg.data.error) {
stamps[msg.data.stamp].reject(msg.data.error)
} else {
stamps[msg.data.stamp].resolve(msg.data.result)
}
} else if (msg.data.cmd === 'initiateResult') { } else if (msg.data.cmd === 'initiateResult') {
if (!msg.data.error) { if (!msg.data.error) {
this.provider = { this.provider = {
sendAsync: (query, callback) => { sendAsync: (query, callback) => {
return new Promise((resolve, reject) => {
const stamp = Date.now() + incr const stamp = Date.now() + incr
incr++ incr++
stamps[stamp] = callback stamps[stamp] = { callback, resolve, reject }
this.worker.postMessage({ cmd: 'sendAsync', query, stamp }) this.worker.postMessage({ cmd: 'sendAsync', query, stamp })
})
} }
} }
this.web3 = new Web3(this.provider as LegacySendAsyncProvider) this.web3 = new Web3(this.provider as LegacySendAsyncProvider)

Loading…
Cancel
Save