From a731340136e1f9a003d46a73c96bcf5248e094e3 Mon Sep 17 00:00:00 2001 From: yann300 Date: Wed, 10 Apr 2024 15:18:02 +0200 Subject: [PATCH] fix gasLimit default and allow still using gas estimate --- libs/remix-lib/src/execution/txRunnerWeb3.ts | 11 +++-- .../run-tab/src/lib/components/gasLimit.tsx | 44 +++++++++++++++++++ .../run-tab/src/lib/components/gasPrice.tsx | 22 ---------- .../run-tab/src/lib/components/settingsUI.tsx | 4 +- .../run-tab/src/lib/reducers/runTab.ts | 2 +- 5 files changed, 55 insertions(+), 28 deletions(-) create mode 100644 libs/remix-ui/run-tab/src/lib/components/gasLimit.tsx delete mode 100644 libs/remix-ui/run-tab/src/lib/components/gasPrice.tsx diff --git a/libs/remix-lib/src/execution/txRunnerWeb3.ts b/libs/remix-lib/src/execution/txRunnerWeb3.ts index 9b3ff8171d..c55a2a2181 100644 --- a/libs/remix-lib/src/execution/txRunnerWeb3.ts +++ b/libs/remix-lib/src/execution/txRunnerWeb3.ts @@ -141,10 +141,15 @@ export class TxRunnerWeb3 { * gasLimit is a value that can be set in the UI to hardcap value that can be put in a tx. * e.g if the gasestimate */ - if (gasEstimation > gasLimit) { + if (gasLimit !== '0x0' && gasEstimation > gasLimit) { return callback(`estimated gas for this transaction (${gasEstimation}) is higher than gasLimit set in the configuration (${gasLimit}). Please raise the gas limit.`) - } - tx['gas'] = gasLimit + } + + if (gasLimit === '0x0') { + tx['gas'] = gasEstimation + } else { + tx['gas'] = gasLimit + } if (this._api.config.getUnpersistedProperty('doNotShowTransactionConfirmationAgain')) { return this._executeTx(tx, network, null, this._api, promptCb, callback) diff --git a/libs/remix-ui/run-tab/src/lib/components/gasLimit.tsx b/libs/remix-ui/run-tab/src/lib/components/gasLimit.tsx new file mode 100644 index 0000000000..35674a2768 --- /dev/null +++ b/libs/remix-ui/run-tab/src/lib/components/gasLimit.tsx @@ -0,0 +1,44 @@ +// eslint-disable-next-line no-use-before-define +import {CustomTooltip} from '@remix-ui/helper' +import React, { useEffect, useRef } from 'react' +import {FormattedMessage} from 'react-intl' +import {GasPriceProps} from '../types' + +const defaultGasLimit = 500000 +export function GasLimitUI(props: GasPriceProps) { + const auto = useRef(true) + const inputComponent = useRef(null) + const currentGasLimit = useRef(defaultGasLimit) + + useEffect(() => { + handleGasLimitAuto(true) + }, []) + + const handleGasLimit = (e) => { + props.setGasFee(e.target.value) + } + + const handleGasLimitAuto = (checked) => { + auto.current = checked + if (checked) { + currentGasLimit.current = parseInt(inputComponent.current.value) + props.setGasFee(0) + } else { + props.setGasFee(currentGasLimit.current) + } + } + + return ( +
+ +
+ { handleGasLimitAuto(e.target.checked) } } /> + }> + + +
+
+ ) +} diff --git a/libs/remix-ui/run-tab/src/lib/components/gasPrice.tsx b/libs/remix-ui/run-tab/src/lib/components/gasPrice.tsx deleted file mode 100644 index 1f641af0a8..0000000000 --- a/libs/remix-ui/run-tab/src/lib/components/gasPrice.tsx +++ /dev/null @@ -1,22 +0,0 @@ -// eslint-disable-next-line no-use-before-define -import {CustomTooltip} from '@remix-ui/helper' -import React from 'react' -import {FormattedMessage} from 'react-intl' -import {GasPriceProps} from '../types' - -export function GasPriceUI(props: GasPriceProps) { - const handleGasLimit = (e) => { - props.setGasFee(e.target.value) - } - - return ( -
- - }> - - -
- ) -} diff --git a/libs/remix-ui/run-tab/src/lib/components/settingsUI.tsx b/libs/remix-ui/run-tab/src/lib/components/settingsUI.tsx index e5856011a7..265262f289 100644 --- a/libs/remix-ui/run-tab/src/lib/components/settingsUI.tsx +++ b/libs/remix-ui/run-tab/src/lib/components/settingsUI.tsx @@ -4,7 +4,7 @@ import {SettingsProps} from '../types' import {EnvironmentUI} from './environment' import {NetworkUI} from './network' import {AccountUI} from './account' -import {GasPriceUI} from './gasPrice' +import {GasLimitUI} from './gasLimit' import {ValueUI} from './value' export function SettingsUI(props: SettingsProps) { @@ -27,7 +27,7 @@ export function SettingsUI(props: SettingsProps) { signMessageWithAddress={props.signMessageWithAddress} passphrase={props.passphrase} /> - + ) diff --git a/libs/remix-ui/run-tab/src/lib/reducers/runTab.ts b/libs/remix-ui/run-tab/src/lib/reducers/runTab.ts index a1686bdb1d..ce3f04dc9b 100644 --- a/libs/remix-ui/run-tab/src/lib/reducers/runTab.ts +++ b/libs/remix-ui/run-tab/src/lib/reducers/runTab.ts @@ -18,7 +18,7 @@ export const runTabInitialState: RunTabState = { }, sendValue: '0', sendUnit: 'wei', - gasLimit: 500000, + gasLimit: 0, selectExEnv: 'vm-paris', personalMode: false, networkName: 'VM',