From 70400395c1e17e864084882546bfe375a8c8d6fb Mon Sep 17 00:00:00 2001 From: yann300 Date: Mon, 7 Oct 2024 11:40:09 +0200 Subject: [PATCH] remove request --- apps/remix-ide/src/blockchain/providers/vm.ts | 22 ++++++------- .../src/blockchain/providers/worker-vm.ts | 31 +++++++++++++++++++ 2 files changed, 41 insertions(+), 12 deletions(-) diff --git a/apps/remix-ide/src/blockchain/providers/vm.ts b/apps/remix-ide/src/blockchain/providers/vm.ts index a6614682c73..620cee6e40d 100644 --- a/apps/remix-ide/src/blockchain/providers/vm.ts +++ b/apps/remix-ide/src/blockchain/providers/vm.ts @@ -38,18 +38,16 @@ 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 - - if (stamps[msg.data.stamp].callback) { - stamps[msg.data.stamp].callback(msg.data.error, result) - return - } + 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(result) + 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, msg.data.result) + return } } else if (msg.data.cmd === 'initiateResult') { if (!msg.data.error) { @@ -58,7 +56,7 @@ 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 } this.worker.postMessage({ cmd: 'sendAsync', query, stamp }) }) }, @@ -66,8 +64,8 @@ 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 } + this.worker.postMessage({ cmd: 'request', query, stamp }) }) } } diff --git a/apps/remix-ide/src/blockchain/providers/worker-vm.ts b/apps/remix-ide/src/blockchain/providers/worker-vm.ts index d1ad0b7f0da..ccc97129b1b 100644 --- a/apps/remix-ide/src/blockchain/providers/worker-vm.ts +++ b/apps/remix-ide/src/blockchain/providers/worker-vm.ts @@ -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) {