remove request

pull/5298/head
yann300 2 months ago committed by Aniket
parent f7bd13b9f8
commit ce1a8ed0eb
  1. 24
      apps/remix-ide/src/blockchain/providers/vm.ts
  2. 31
      apps/remix-ide/src/blockchain/providers/worker-vm.ts

@ -38,18 +38,22 @@ export class VMProvider {
return new Promise((resolve, reject) => {
this.worker.addEventListener('message', (msg) => {
if (msg.data.cmd === 'sendAsyncResult' && stamps[msg.data.stamp]) {
const result = msg.data.result
// if (stamps[msg.data.stamp].request && msg.data.result) result = msg.data.result.result
console.log('message', msg)
if (msg.data.cmd === 'requestResult' && stamps[msg.data.stamp]) {
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 === 'sendAsyncResult' && stamps[msg.data.stamp]) {
if (stamps[msg.data.stamp].callback) {
stamps[msg.data.stamp].callback(msg.data.error, result)
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(result)
stamps[msg.data.stamp].resolve(msg.data.result)
}
} else if (msg.data.cmd === 'initiateResult') {
if (!msg.data.error) {
@ -58,7 +62,8 @@ export class VMProvider {
return new Promise((resolve, reject) => {
const stamp = Date.now() + incr
incr++
stamps[stamp] = { callback, resolve, reject, sendAsync: true }
stamps[stamp] = { callback, resolve, reject }
console.log('sendAsync', query, stamp)
this.worker.postMessage({ cmd: 'sendAsync', query, stamp })
})
},
@ -66,8 +71,9 @@ export class VMProvider {
return new Promise((resolve, reject) => {
const stamp = Date.now() + incr
incr++
stamps[stamp] = { resolve, reject, request: true }
this.worker.postMessage({ cmd: 'sendAsync', query, stamp })
stamps[stamp] = { resolve, reject }
console.log('request', query, stamp)
this.worker.postMessage({ cmd: 'request', query, stamp })
})
}
}

@ -43,6 +43,37 @@ self.onmessage = (e: MessageEvent) => {
break
}
case 'request':
{
(function (data) {
const stamp = data.stamp
if (provider) {
provider.request(data.query).then((result) => {
self.postMessage({
cmd: 'requestResult',
error: null,
result: result,
stamp: stamp
})
}).catch((error) => {
self.postMessage({
cmd: 'requestResult',
error: error,
result: null,
stamp: stamp
})
})
} else {
self.postMessage({
cmd: 'requestResult',
error: 'Provider not instantiated',
result: null,
stamp: stamp
})
}
})(data)
break
}
case 'addAccount':
{
if (provider) {

Loading…
Cancel
Save