From 4014d79f62e9ca70a59905d2509ab8d552eac792 Mon Sep 17 00:00:00 2001 From: Wyatt Barnes Date: Mon, 24 Jul 2023 15:26:30 -1000 Subject: [PATCH] Fix yarn nx build --- .../src/app/plugins/solidity-script.tsx | 4 +-- apps/remix-ide/src/blockchain/blockchain.tsx | 9 ++--- .../src/blockchain/providers/node.ts | 6 ++-- apps/remix-ide/src/blockchain/providers/vm.ts | 27 ++++++-------- libs/remix-simulator/src/VmProxy.ts | 4 +-- .../src/lib/vm-debugger/global-variables.tsx | 4 +-- libs/remix-ui/editor/src/lib/web-types.ts | 36 ++++++++----------- .../run-tab/src/lib/components/mainnet.tsx | 7 ++-- 8 files changed, 43 insertions(+), 54 deletions(-) diff --git a/apps/remix-ide/src/app/plugins/solidity-script.tsx b/apps/remix-ide/src/app/plugins/solidity-script.tsx index 88c3b1e962..38aa958ecd 100644 --- a/apps/remix-ide/src/app/plugins/solidity-script.tsx +++ b/apps/remix-ide/src/app/plugins/solidity-script.tsx @@ -2,7 +2,7 @@ import React from 'react' // eslint-disable-line import { format } from 'util' import { Plugin } from '@remixproject/engine' import { compile } from '@remix-project/remix-solidity' -import { TransactionConfig } from 'web3-core' +import { Transaction } from 'web3-types' const _paq = window._paq = window._paq || [] //eslint-disable-line const profile = { @@ -68,7 +68,7 @@ export class SolidityScript extends Plugin { } // deploy the contract - let tx: TransactionConfig = { + let tx: Transaction = { from: accounts[0], data: bytecode } diff --git a/apps/remix-ide/src/blockchain/blockchain.tsx b/apps/remix-ide/src/blockchain/blockchain.tsx index 61aeeb74df..9f0f010aad 100644 --- a/apps/remix-ide/src/blockchain/blockchain.tsx +++ b/apps/remix-ide/src/blockchain/blockchain.tsx @@ -1,6 +1,7 @@ import React from 'react' // eslint-disable-line import Web3 from 'web3' +import { fromWei, toBN, toWei } from 'web3-utils-legacy' import { Plugin } from '@remixproject/engine' import { toBuffer, addHexPrefix } from '@ethereumjs/util' import { EventEmitter } from 'events' @@ -422,17 +423,17 @@ export class Blockchain extends Plugin { fromWei (value, doTypeConversion, unit) { if (doTypeConversion) { - return Web3.utils.fromWei(typeConversion.toInt(value), unit || 'ether') + return fromWei(typeConversion.toInt(value), unit || 'ether') } - return Web3.utils.fromWei(value.toString(10), unit || 'ether') + return fromWei(value.toString(10), unit || 'ether') } toWei (value, unit) { - return Web3.utils.toWei(value, unit || 'gwei') + return toWei(value, unit || 'gwei') } calculateFee (gas, gasPrice, unit?) { - return Web3.utils.toBN(gas).mul(Web3.utils.toBN(Web3.utils.toWei(gasPrice.toString(10) as string, unit || 'gwei'))) + return toBN(gas).mul(toBN(toWei(gasPrice.toString(10) as string, unit || 'gwei'))) } determineGasFees (tx) { diff --git a/apps/remix-ide/src/blockchain/providers/node.ts b/apps/remix-ide/src/blockchain/providers/node.ts index 65116b4923..13d32148ec 100644 --- a/apps/remix-ide/src/blockchain/providers/node.ts +++ b/apps/remix-ide/src/blockchain/providers/node.ts @@ -46,9 +46,9 @@ export class NodeProvider { const messageHash = hashPersonalMessage(Buffer.from(message)) try { const personal = new Personal(this.executionContext.web3().currentProvider) - personal.sign(message, account, passphrase, (error, signedData) => { - cb(error, '0x' + messageHash.toString('hex'), signedData) - }) + personal.sign(message, account, passphrase) + .then(signedData => cb(undefined, '0x' + messageHash.toString('hex'), signedData)) + .catch(error => cb(error, '0x' + messageHash.toString('hex'), undefined)) } catch (e) { cb(e.message) } diff --git a/apps/remix-ide/src/blockchain/providers/vm.ts b/apps/remix-ide/src/blockchain/providers/vm.ts index 4234e42616..d412e3d6a7 100644 --- a/apps/remix-ide/src/blockchain/providers/vm.ts +++ b/apps/remix-ide/src/blockchain/providers/vm.ts @@ -1,4 +1,5 @@ -import Web3 from 'web3' +import Web3, { FMT_BYTES, FMT_NUMBER, LegacySendAsyncProvider } from 'web3' +import { fromWei } from 'web3-utils-legacy' import { privateToAddress, hashPersonalMessage } from '@ethereumjs/util' import BN from 'bn.js' import { extend, JSONRPCRequestPayload, JSONRPCResponseCallback } from '@remix-project/remix-simulator' @@ -21,12 +22,9 @@ export class VMProvider { } getAccounts (cb) { - this.web3.eth.getAccounts((err, accounts) => { - if (err) { - return cb('No accounts?') - } - return cb(null, accounts) - }) + this.web3.eth.getAccounts() + .then(accounts => cb(null, accounts)) + .catch(err => cb('No accounts?')) } async resetEnvironment () { @@ -51,7 +49,7 @@ export class VMProvider { this.worker.postMessage({ cmd: 'sendAsync', query, stamp }) } } - this.web3 = new Web3(this.provider) + this.web3 = new Web3(this.provider as LegacySendAsyncProvider) extend(this.web3) this.executionContext.setWeb3(this.executionContext.getProvider(), this.web3) resolve({}) @@ -85,8 +83,8 @@ export class VMProvider { } async getBalanceInEther (address) { - const balance = await this.web3.eth.getBalance(address) - return Web3.utils.fromWei(new BN(balance).toString(10), 'ether') + const balance = await this.web3.eth.getBalance(address, undefined, { number: FMT_NUMBER.HEX, bytes: FMT_BYTES.HEX }) + return fromWei(new BN(balance).toString(10), 'ether') } getGasPrice (cb) { @@ -95,12 +93,9 @@ export class VMProvider { signMessage (message, account, _passphrase, cb) { const messageHash = hashPersonalMessage(Buffer.from(message)) - this.web3.eth.sign(message, account, (error, signedData) => { - if (error) { - return cb(error) - } - cb(null, '0x' + messageHash.toString('hex'), signedData) - }) + this.web3.eth.sign(message, account) + .then(signedData => cb(null, '0x' + messageHash.toString('hex'), signedData)) + .catch(error => cb(error)) } getProvider () { diff --git a/libs/remix-simulator/src/VmProxy.ts b/libs/remix-simulator/src/VmProxy.ts index 65e7d24831..1ad22e075f 100644 --- a/libs/remix-simulator/src/VmProxy.ts +++ b/libs/remix-simulator/src/VmProxy.ts @@ -6,6 +6,7 @@ import { ConsoleLogs, hash } from '@remix-project/remix-lib' import BN from 'bn.js' import { toChecksumAddress, bufferToHex, Address, toBuffer } from '@ethereumjs/util' import utils from 'web3-utils' +import { toBN } from 'web3-utils-legacy' import { ethers } from 'ethers' import { VMContext } from './vm-context' import type { StateManager } from '@ethereumjs/statemanager' @@ -83,8 +84,7 @@ export class VmProxy { this.fromDecimal = (...args) => utils.fromDecimal.apply(this, args) this.fromWei = (...args) => utils.fromWei.apply(this, args) this.toWei = (...args) => utils.toWei.apply(this, args) - // TODO Is this still needed? - // this.toBigNumber = (...args) => utils.toBN.apply(this, args) + this.toBigNumber = (...args) => toBN.apply(this, args) this.isAddress = (...args) => utils.isAddress.apply(this, args) this.utils = utils this.txsMapBlock = {} diff --git a/libs/remix-ui/debugger-ui/src/lib/vm-debugger/global-variables.tsx b/libs/remix-ui/debugger-ui/src/lib/vm-debugger/global-variables.tsx index ed5f4aec0a..3d4a281838 100644 --- a/libs/remix-ui/debugger-ui/src/lib/vm-debugger/global-variables.tsx +++ b/libs/remix-ui/debugger-ui/src/lib/vm-debugger/global-variables.tsx @@ -1,7 +1,7 @@ import React from 'react' // eslint-disable-line import DropdownPanel from './dropdown-panel' // eslint-disable-line import { BN } from 'bn.js' -import Web3 from 'web3' +import { toBN } from 'web3-utils-legacy' export const GlobalVariables = ({ block, receipt, tx, className }) => { // see https://docs.soliditylang.org/en/latest/units-and-global-variables.html#block-and-transaction-properties @@ -18,7 +18,7 @@ export const GlobalVariables = ({ block, receipt, tx, className }) => { 'tx.origin': tx && tx.from } if (block && block.baseFeePerGas) { - globals['block.basefee'] = Web3.utils.toBN(block.baseFeePerGas).toString(10) + ` Wei (${block.baseFeePerGas})` + globals['block.basefee'] = toBN(block.baseFeePerGas).toString(10) + ` Wei (${block.baseFeePerGas})` } return ( diff --git a/libs/remix-ui/editor/src/lib/web-types.ts b/libs/remix-ui/editor/src/lib/web-types.ts index dd70a43bc0..9d95f1440e 100644 --- a/libs/remix-ui/editor/src/lib/web-types.ts +++ b/libs/remix-ui/editor/src/lib/web-types.ts @@ -184,40 +184,32 @@ export const loadTypes = async (monaco) => { // Web3 // @ts-ignore - const indexWeb3 = await import('raw-loader!web3/types/index.d.ts') - monaco.languages.typescript.typescriptDefaults.addExtraLib(indexWeb3.default, `file:///node_modules/@types/web3/index.d.ts`) + const indexWeb3 = await import('raw-loader!web3') + monaco.languages.typescript.typescriptDefaults.addExtraLib(indexWeb3.default, `file:///node_modules/web3/lib/types/index.d.ts`) // @ts-ignore - const indexWeb3Bzz = await import('raw-loader!web3-bzz/types/index.d.ts') - monaco.languages.typescript.typescriptDefaults.addExtraLib(indexWeb3Bzz.default, `file:///node_modules/@types/web3-bzz/index.d.ts`) + const indexWeb3Core = await import('raw-loader!web3-core') + monaco.languages.typescript.typescriptDefaults.addExtraLib(indexWeb3Core.default, `file:///node_modules/web3-core/lib/types/index.d.ts`) // @ts-ignore - const indexWeb3Core = await import('raw-loader!web3-core/types/index.d.ts') - monaco.languages.typescript.typescriptDefaults.addExtraLib(indexWeb3Core.default, `file:///node_modules/@types/web3-core/index.d.ts`) + const indexWeb3Eth = await import('raw-loader!web3-eth') + monaco.languages.typescript.typescriptDefaults.addExtraLib(indexWeb3Eth.default, `file:///node_modules/web3-eth/lib/types/index.d.ts`) // @ts-ignore - const indexWeb3Eth = await import('raw-loader!web3-eth/types/index.d.ts') - monaco.languages.typescript.typescriptDefaults.addExtraLib(indexWeb3Eth.default, `file:///node_modules/@types/web3-eth/index.d.ts`) + const indexWeb3Personal = await import('raw-loader!web3-eth-personal') + monaco.languages.typescript.typescriptDefaults.addExtraLib(indexWeb3Personal.default, `file:///node_modules/web3-eth-personal/lib/types/index.d.ts`) // @ts-ignore - const indexWeb3Personal = await import('raw-loader!web3-eth-personal/types/index.d.ts') - monaco.languages.typescript.typescriptDefaults.addExtraLib(indexWeb3Personal.default, `file:///node_modules/@types/web3-eth-personal/index.d.ts`) + const indexWeb3Contract = await import('raw-loader!web3-eth-contract') + monaco.languages.typescript.typescriptDefaults.addExtraLib(indexWeb3Contract.default, `file:///node_modules/web3-eth-contract/lib/types/index.d.ts`) // @ts-ignore - const indexWeb3Contract = await import('raw-loader!web3-eth-contract/types/index.d.ts') - monaco.languages.typescript.typescriptDefaults.addExtraLib(indexWeb3Contract.default, `file:///node_modules/@types/web3-eth-contract/index.d.ts`) + const indexWeb3Net = await import('raw-loader!web3-net') + monaco.languages.typescript.typescriptDefaults.addExtraLib(indexWeb3Net.default, `file:///node_modules/web3-net/lib/types/index.d.ts`) // @ts-ignore - const indexWeb3Net = await import('raw-loader!web3-net/types/index.d.ts') - monaco.languages.typescript.typescriptDefaults.addExtraLib(indexWeb3Net.default, `file:///node_modules/@types/web3-net/index.d.ts`) - - // @ts-ignore - const indexWeb3Shh = await import('raw-loader!web3-shh/types/index.d.ts') - monaco.languages.typescript.typescriptDefaults.addExtraLib(indexWeb3Shh.default, `file:///node_modules/@types/web3-shh/index.d.ts`) - - // @ts-ignore - const indexWeb3Util = await import('raw-loader!web3-utils/types/index.d.ts') - monaco.languages.typescript.typescriptDefaults.addExtraLib(indexWeb3Util.default, `file:///node_modules/@types/web3-utils/index.d.ts`) + const indexWeb3Util = await import('raw-loader!web3-utils') + monaco.languages.typescript.typescriptDefaults.addExtraLib(indexWeb3Util.default, `file:///node_modules/web3-utils/lib/types/index.d.ts`) // remix const indexRemixApi = remixTypes + `\n declare global { diff --git a/libs/remix-ui/run-tab/src/lib/components/mainnet.tsx b/libs/remix-ui/run-tab/src/lib/components/mainnet.tsx index a27e40b640..b8d1a661a4 100644 --- a/libs/remix-ui/run-tab/src/lib/components/mainnet.tsx +++ b/libs/remix-ui/run-tab/src/lib/components/mainnet.tsx @@ -2,6 +2,7 @@ import React, { useEffect, useState } from 'react' import { CopyToClipboard } from '@remix-ui/clipboard' import Web3 from 'web3' +import { fromWei, toBN, toWei } from 'web3-utils-legacy' import { MainnetProps } from '../types' export function MainnetPrompt (props: MainnetProps) { @@ -13,7 +14,7 @@ export function MainnetPrompt (props: MainnetProps) { if (txFeeText) setTransactionFee(txFeeText) if (gasPriceValue) onGasPriceChange(gasPriceValue) if (props.network && props.network.lastBlock && props.network.lastBlock.baseFeePerGas) { - const baseFee = Web3.utils.fromWei(Web3.utils.toBN(props.network.lastBlock.baseFeePerGas), 'Gwei') + const baseFee = fromWei(toBN(props.network.lastBlock.baseFeePerGas), 'Gwei') setBaseFee(baseFee) onMaxFeeChange(baseFee) @@ -25,7 +26,7 @@ export function MainnetPrompt (props: MainnetProps) { const onMaxFeeChange = (value: string) => { const maxFee = value // @ts-ignore - if (Web3.utils.toBN(props.network.lastBlock.baseFeePerGas).gt(Web3.utils.toBN(Web3.utils.toWei(maxFee, 'Gwei')))) { + if (toBN(props.network.lastBlock.baseFeePerGas).gt(toBN(toWei(maxFee, 'Gwei')))) { setTransactionFee('Transaction is invalid. Max fee should not be less than Base fee') props.updateGasPriceStatus(false) props.updateConfirmSettings(true) @@ -106,7 +107,7 @@ export function MainnetPrompt (props: MainnetProps) {
- Max fee (Not less than base fee {Web3.utils.fromWei(Web3.utils.toBN(props.network.lastBlock.baseFeePerGas), 'Gwei')} Gwei): + Max fee (Not less than base fee {fromWei(toBN(props.network.lastBlock.baseFeePerGas), 'Gwei')} Gwei): onMaxFeeChange(e.target.value)} defaultValue={baseFee} /> Gwei