From fd57de45af6fe1152944a1b13504c1fea72a8a30 Mon Sep 17 00:00:00 2001 From: yann300 Date: Mon, 18 Sep 2023 14:26:51 +0200 Subject: [PATCH] fix sendAsync call --- apps/remix-ide/src/blockchain/providers/vm.ts | 20 ++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/apps/remix-ide/src/blockchain/providers/vm.ts b/apps/remix-ide/src/blockchain/providers/vm.ts index 39a57b0197..0ebe1370a2 100644 --- a/apps/remix-ide/src/blockchain/providers/vm.ts +++ b/apps/remix-ide/src/blockchain/providers/vm.ts @@ -40,15 +40,25 @@ export class VMProvider { return new Promise((resolve, reject) => { this.worker.addEventListener('message', (msg) => { 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') { if (!msg.data.error) { this.provider = { sendAsync: (query, callback) => { - const stamp = Date.now() + incr - incr++ - stamps[stamp] = callback - this.worker.postMessage({ cmd: 'sendAsync', query, stamp }) + return new Promise((resolve, reject) => { + const stamp = Date.now() + incr + incr++ + stamps[stamp] = { callback, resolve, reject } + this.worker.postMessage({ cmd: 'sendAsync', query, stamp }) + }) } } this.web3 = new Web3(this.provider as LegacySendAsyncProvider)