From a5ca9c0017388753066372ac2d2c8d39f3357fac Mon Sep 17 00:00:00 2001 From: Oleksii Kosynskyi Date: Tue, 15 Aug 2023 21:25:35 -0400 Subject: [PATCH] fix ui --- apps/remix-ide/src/app/udapp/run-tab.js | 21 +++++++------------ .../src/blockchain/execution-context.js | 10 ++++----- .../src/blockchain/providers/injected.ts | 14 ++++++------- .../src/blockchain/providers/node.ts | 8 +++---- apps/remix-ide/src/blockchain/providers/vm.ts | 19 ++++++----------- 5 files changed, 30 insertions(+), 42 deletions(-) diff --git a/apps/remix-ide/src/app/udapp/run-tab.js b/apps/remix-ide/src/app/udapp/run-tab.js index ec389b1db8..6d8707e4ae 100644 --- a/apps/remix-ide/src/app/udapp/run-tab.js +++ b/apps/remix-ide/src/app/udapp/run-tab.js @@ -113,19 +113,14 @@ export class RunTab extends ViewPlugin { title, init: async function () { const options = await udapp.call(name, 'init') - if (options) { + if (options) { this.options = options if (options['fork']) this.fork = options['fork'] } }, provider: { - async sendAsync (payload, callback) { - try { - const result = await udapp.call(name, 'sendAsync', payload) - callback(null, result) - } catch (e) { - callback(e) - } + async sendAsync (payload) { + return udapp.call(name, 'sendAsync', payload) } } }) @@ -145,10 +140,10 @@ export class RunTab extends ViewPlugin { } if (window && window.trustwallet) { - const displayNameInjected = `Injected Provider - TrustWallet` + const displayNameInjected = `Injected Provider - TrustWallet` await addProvider('injected-trustwallet', displayNameInjected, true, false) } - + // VM const titleVM = 'Execution environment is local to Remix. Data is only saved to browser memory and will vanish upon reload.' await addProvider('vm-shanghai', 'Remix VM (Shanghai)', false, true, 'shanghai', 'settingsVMShanghaiMode', titleVM) @@ -167,9 +162,9 @@ export class RunTab extends ViewPlugin { await addProvider('basic-http-provider', 'Custom - External Http Provider', false, false) await addProvider('hardhat-provider', 'Dev - Hardhat Provider', false, false) await addProvider('ganache-provider', 'Dev - Ganache Provider', false, false) - await addProvider('foundry-provider', 'Dev - Foundry Provider', false, false) - - // injected provider + await addProvider('foundry-provider', 'Dev - Foundry Provider', false, false) + + // injected provider await addProvider('injected-optimism-provider', 'L2 - Optimism Provider', true, false) await addProvider('injected-arbitrum-one-provider', 'L2 - Arbitrum One Provider', true, false) } diff --git a/apps/remix-ide/src/blockchain/execution-context.js b/apps/remix-ide/src/blockchain/execution-context.js index d730a130e3..af9c9eefab 100644 --- a/apps/remix-ide/src/blockchain/execution-context.js +++ b/apps/remix-ide/src/blockchain/execution-context.js @@ -36,7 +36,7 @@ export class ExecutionContext { init (config) { this.executionContext = 'vm-shanghai' this.event.trigger('contextChanged', [this.executionContext]) - } + } getProvider () { return this.executionContext @@ -117,7 +117,7 @@ export class ExecutionContext { internalWeb3 () { return web3 } - + setContext (context, endPointUrl, confirmCb, infoCb) { this.executionContext = context this.executionContextChange(context, endPointUrl, confirmCb, infoCb, null) @@ -128,9 +128,9 @@ export class ExecutionContext { const context = value.context if (!cb) cb = () => { /* Do nothing. */ } if (!confirmCb) confirmCb = () => { /* Do nothing. */ } - if (!infoCb) infoCb = () => { /* Do nothing. */ } + if (!infoCb) infoCb = () => { /* Do nothing. */ } if (this.customNetWorks[context]) { - var network = this.customNetWorks[context] + var network = this.customNetWorks[context] await network.init() this.currentFork = network.fork this.executionContext = context @@ -156,7 +156,7 @@ export class ExecutionContext { try { const block = await web3.eth.getBlock('latest') // we can't use the blockGasLimit cause the next blocks could have a lower limit : https://github.com/ethereum/remix/issues/506 - this.blockGasLimit = (block && block.gasLimit) ? Math.floor(block.gasLimit - (5 * block.gasLimit) / 1024) : this.blockGasLimitDefault + this.blockGasLimit = (block && block.gasLimit) ? Math.floor(web3.utils.toNumber(block.gasLimit) - (5 * web3.utils.toNumber(block.gasLimit) / 1024)) : web3.utils.toNumber(this.blockGasLimitDefault) this.lastBlock = block try { this.currentFork = execution.forkAt(await web3.eth.net.getId(), block.number) diff --git a/apps/remix-ide/src/blockchain/providers/injected.ts b/apps/remix-ide/src/blockchain/providers/injected.ts index bc6ab49e7f..c116457da6 100644 --- a/apps/remix-ide/src/blockchain/providers/injected.ts +++ b/apps/remix-ide/src/blockchain/providers/injected.ts @@ -10,17 +10,17 @@ export class InjectedProvider { } getAccounts (cb) { - return this.executionContext.web3().eth.getAccounts(cb) + return this.executionContext.web3().eth.getAccounts().then(res => cb(null, res)).catch(err => cb(err)) } newAccount (passwordPromptCb, cb) { passwordPromptCb((passphrase) => { - this.executionContext.web3().eth.personal.newAccount(passphrase, cb) + this.executionContext.web3().eth.personal.newAccount(passphrase).then(res => cb(null, res)).catch(err => cb(err)) }) } async resetEnvironment () { - /* Do nothing. */ + /* Do nothing. */ } async getBalanceInEther (address) { @@ -29,15 +29,15 @@ export class InjectedProvider { } getGasPrice (cb) { - this.executionContext.web3().eth.getGasPrice(cb) + this.executionContext.web3().eth.getGasPrice().then(res => cb(null, res)).catch(err => cb(err)) } signMessage (message, account, _passphrase, cb) { const messageHash = hashPersonalMessage(Buffer.from(message)) try { - this.executionContext.web3().eth.personal.sign(message, account, (error, signedData) => { - cb(error, '0x' + messageHash.toString('hex'), signedData) - }) + this.executionContext.web3().eth.personal.sign(message, account) + .then(signedData=>cb(null, '0x' + messageHash.toString('hex'), signedData)) + .catch(error=>cb(error, '0x' + messageHash.toString('hex'))) } catch (e) { cb(e.message) } diff --git a/apps/remix-ide/src/blockchain/providers/node.ts b/apps/remix-ide/src/blockchain/providers/node.ts index 13d32148ec..b65ee639b3 100644 --- a/apps/remix-ide/src/blockchain/providers/node.ts +++ b/apps/remix-ide/src/blockchain/providers/node.ts @@ -15,9 +15,9 @@ export class NodeProvider { getAccounts (cb) { if (this.config.get('settings/personal-mode')) { - return this.executionContext.web3().eth.personal.getAccounts(cb) + return this.executionContext.web3().eth.personal.getAccounts().then(res => cb(null, res)).catch(err => cb(err)) } - return this.executionContext.web3().eth.getAccounts(cb) + return this.executionContext.web3().eth.getAccounts().then(res => cb(null, res)).catch(err => cb(err)) } newAccount (passwordPromptCb, cb) { @@ -25,7 +25,7 @@ export class NodeProvider { return cb('Not running in personal mode') } passwordPromptCb((passphrase) => { - this.executionContext.web3().eth.personal.newAccount(passphrase, cb) + this.executionContext.web3().eth.personal.newAccount(passphrase).then(res => cb(null, res)).catch(err => cb(err)) }) } @@ -39,7 +39,7 @@ export class NodeProvider { } getGasPrice (cb) { - this.executionContext.web3().eth.getGasPrice(cb) + this.executionContext.web3().eth.getGasPrice().then(res => cb(null, res)).catch(err => cb(err)) } signMessage (message, account, passphrase, cb) { diff --git a/apps/remix-ide/src/blockchain/providers/vm.ts b/apps/remix-ide/src/blockchain/providers/vm.ts index 720055df9d..8fc07563eb 100644 --- a/apps/remix-ide/src/blockchain/providers/vm.ts +++ b/apps/remix-ide/src/blockchain/providers/vm.ts @@ -1,5 +1,5 @@ -import Web3, { FMT_BYTES, FMT_NUMBER, LegacySendAsyncProvider } from 'web3' -import { fromWei, toBigInt } from 'web3-utils' +import Web3, { LegacySendAsyncProvider } from 'web3' +import { fromWei } from 'web3-utils' import { privateToAddress, hashPersonalMessage } from '@ethereumjs/util' import { extend, JSONRPCRequestPayload, JSONRPCResponseCallback } from '@remix-project/remix-simulator' import { ExecutionContext } from '../execution-context' @@ -22,12 +22,7 @@ export class VMProvider { } getAccounts (cb) { - this.web3.eth.getAccounts() - .then(accounts => cb(null, accounts)) - .catch(err => { - console.log('err',err) - cb('No accounts?') - }) + this.web3.eth.getAccounts().then(accounts => cb(null, accounts)).catch(err => cb('No accounts?')) } async resetEnvironment () { @@ -46,8 +41,6 @@ export class VMProvider { if (!msg.data.error) { this.provider = { sendAsync: (query, callback) => { - console.log('query',query) - console.log('callback',callback) const stamp = Date.now() + incr incr++ stamps[stamp] = callback @@ -88,12 +81,12 @@ export class VMProvider { } async getBalanceInEther (address) { - const balance = await this.web3.eth.getBalance(address, undefined, { number: FMT_NUMBER.HEX, bytes: FMT_BYTES.HEX }) - return fromWei(toBigInt(balance).toString(10), 'ether') + const balance = await this.web3.eth.getBalance(address) + return fromWei(balance.toString(10), 'ether') } getGasPrice (cb) { - this.web3.eth.getGasPrice(cb) + this.web3.eth.getGasPrice().then(res => cb(null, res)).catch(err => cb(err)) } signMessage (message, account, _passphrase, cb) {