fix gasLimit default and allow still using gas estimate

pull/4737/head^2
yann300 8 months ago committed by Aniket
parent 2c9f1a03d6
commit a731340136
  1. 11
      libs/remix-lib/src/execution/txRunnerWeb3.ts
  2. 44
      libs/remix-ui/run-tab/src/lib/components/gasLimit.tsx
  3. 22
      libs/remix-ui/run-tab/src/lib/components/gasPrice.tsx
  4. 4
      libs/remix-ui/run-tab/src/lib/components/settingsUI.tsx
  5. 2
      libs/remix-ui/run-tab/src/lib/reducers/runTab.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)

@ -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<HTMLInputElement>(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 (
<div className="udapp_crow">
<label className="udapp_settingsLabel">
<FormattedMessage id="udapp.gasLimit" />
</label>
<div className='custom-control custom-checkbox udapp_col2 udapp_gasNval'>
<input type="checkbox" className="" id="gasLimitAuto" checked={auto.current} onChange={(e) => { handleGasLimitAuto(e.target.checked) } } />
<CustomTooltip placement={'right'} tooltipClasses="text-nowrap" tooltipId="remixGasPriceTooltip" tooltipText={<FormattedMessage id="udapp.tooltipText4" />}>
<input type="number" ref={inputComponent} disabled={auto.current} className="form-control" id="gasLimit" value={props.gasLimit === 0 ? currentGasLimit.current : props.gasLimit} onChange={handleGasLimit} />
</CustomTooltip>
</div>
</div>
)
}

@ -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 (
<div className="udapp_crow">
<label className="udapp_settingsLabel">
<FormattedMessage id="udapp.gasLimit" />
</label>
<CustomTooltip placement={'right'} tooltipClasses="text-nowrap" tooltipId="remixGasPriceTooltip" tooltipText={<FormattedMessage id="udapp.tooltipText4" />}>
<input type="number" className="form-control udapp_gasNval udapp_col2" id="gasLimit" value={props.gasLimit} onChange={handleGasLimit} />
</CustomTooltip>
</div>
)
}

@ -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}
/>
<GasPriceUI gasLimit={props.gasLimit} setGasFee={props.setGasFee} />
<GasLimitUI gasLimit={props.gasLimit} setGasFee={props.setGasFee} />
<ValueUI setUnit={props.setUnit} sendValue={props.sendValue} sendUnit={props.sendUnit} setSendValue={props.setSendValue} />
</div>
)

@ -18,7 +18,7 @@ export const runTabInitialState: RunTabState = {
},
sendValue: '0',
sendUnit: 'wei',
gasLimit: 500000,
gasLimit: 0,
selectExEnv: 'vm-paris',
personalMode: false,
networkName: 'VM',

Loading…
Cancel
Save