From ce1a8ed0eb1d86c881ea0a0dbbbcc42ab306c3e3 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 | 24 ++++++++------ .../src/blockchain/providers/worker-vm.ts | 31 +++++++++++++++++++ 2 files changed, 46 insertions(+), 9 deletions(-) diff --git a/apps/remix-ide/src/blockchain/providers/vm.ts b/apps/remix-ide/src/blockchain/providers/vm.ts index a6614682c7..ccd8b391e2 100644 --- a/apps/remix-ide/src/blockchain/providers/vm.ts +++ b/apps/remix-ide/src/blockchain/providers/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 }) }) } } diff --git a/apps/remix-ide/src/blockchain/providers/worker-vm.ts b/apps/remix-ide/src/blockchain/providers/worker-vm.ts index d1ad0b7f0d..ccc97129b1 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) {