Skip to content

Commit

Permalink
Fix bug related to setting custom gas price for dapp invoked txs
Browse files Browse the repository at this point in the history
  • Loading branch information
rileystephens28 committed Jan 9, 2025
1 parent 37c2f06 commit 6464cca
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 27 deletions.
19 changes: 7 additions & 12 deletions ui/components/NetworkFees/FeeSettingsText.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,7 @@ const estimateGweiAmount = (options: {
transactionData?: QuaiTransactionRequestWithAnnotation
}): string => {
const { networkSettings, baseFeePerGas } = options
const estimatedSpendPerGas =
baseFeePerGas + networkSettings.values.minerTip
const estimatedSpendPerGas = baseFeePerGas + networkSettings.values.minerTip

const desiredDecimals = 0

Expand All @@ -95,16 +94,15 @@ export default function FeeSettingsText({
const estimatedFeesPerGas = useBackgroundSelector(selectEstimatedFeesPerGas)
let networkSettings = useBackgroundSelector(selectDefaultNetworkFeeSettings)
networkSettings = customNetworkSetting ?? networkSettings
const baseFeePerGas =
useBackgroundSelector((state) => {
return state.networks.blockInfo[selectedNetwork.chainID]?.baseFeePerGas
}) ??
networkSettings.values?.baseFeePerGas ??
0n

const mainCurrencyPricePoint = useBackgroundSelector(
selectTransactionMainCurrencyPricePoint
)

const baseFeePerGas =
(networkSettings.values.gasPrice ?? 1n) +
(networkSettings.values.minerTip ?? 0n)

const estimatedGweiAmount = estimateGweiAmount({
baseFeePerGas,
networkSettings,
Expand All @@ -113,9 +111,6 @@ export default function FeeSettingsText({
})

const gasLimit = networkSettings.gasLimit ?? networkSettings.suggestedGasLimit
const estimatedSpendPerGas =
(networkSettings.values.gasPrice ?? 1n) +
(networkSettings.values.minerTip ?? 0n)

if (typeof estimatedFeesPerGas === "undefined")
return <div>{t("networkFees.unknownFee")}</div>
Expand All @@ -129,7 +124,7 @@ export default function FeeSettingsText({
const dollarValue = getFeeDollarValue(
mainCurrencyPricePoint,
gasLimit,
estimatedSpendPerGas,
baseFeePerGas,
estimatedRollupFee
)

Expand Down
12 changes: 5 additions & 7 deletions ui/components/NetworkFees/NetworkSettingsSelect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ export default function NetworkSettingsSelect({

const updateGasOptions = useCallback(() => {
if (typeof estimatedFeesPerGas !== "undefined") {
const { regular, express, instant, custom } = estimatedFeesPerGas ?? {}
const { regular, instant, custom } = estimatedFeesPerGas ?? {}
const gasLimit =
networkSettings.gasLimit ?? networkSettings.suggestedGasLimit

Expand All @@ -167,7 +167,8 @@ export default function NetworkSettingsSelect({
confidence: 1,
} as BlockEstimate

const baseFees = [autoFee, regular, express, instant, custom]
// const baseFees = [autoFee, regular, express, instant, custom]
const baseFees = [autoFee, regular, custom]

const updatedGasOptions: GasOption[] = []

Expand Down Expand Up @@ -229,10 +230,7 @@ export default function NetworkSettingsSelect({
onNetworkSettingsChange({ ...networkSettings, gasLimit })
}

function updateCustomGas(
customMinerTip: bigint,
customGasPrice: bigint
) {
function updateCustomGas(customMinerTip: bigint, customGasPrice: bigint) {
dispatch(
setCustomGas({
gasPrice: customGasPrice,
Expand Down Expand Up @@ -382,4 +380,4 @@ export default function NetworkSettingsSelect({
</style>
</div>
)
}
}
13 changes: 5 additions & 8 deletions ui/components/NetworkFees/NetworkSettingsSelectOptionButtons.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ export function NetworkSettingsSelectOptionButton({
<div className="price">
{`${
option.type !== NetworkFeeTypeChosen.Auto
? Number(option.minerTipGwei).toFixed(2)
? Number(option.gasPriceGwei).toFixed(2)
: "Auto"
}`}
</div>
Expand All @@ -153,10 +153,7 @@ export function NetworkSettingsSelectOptionButtonCustom({
option: GasOption
handleSelectGasOption: () => void
isActive: boolean
updateCustomGas: (
customMinerTip: bigint,
customGasPrice: bigint
) => void
updateCustomGas: (customMinerTip: bigint, customGasPrice: bigint) => void
}): ReactElement {
const { t } = useTranslation("translation", { keyPrefix: "networkFees" })
const [warningMessage, setWarningMessage] = useState("")
Expand Down Expand Up @@ -186,7 +183,7 @@ export function NetworkSettingsSelectOptionButtonCustom({
<span className="subtext_large r_label">{t("miner")}</span>
<div className="input_wrap">
<SharedInput
value={`${option.minerTip}`}
value={`${option.minerTipGwei}`}
isSmall
type="number"
onChange={(value: string) => {
Expand All @@ -203,14 +200,14 @@ export function NetworkSettingsSelectOptionButtonCustom({
<span className="subtext_large r_label">{t("maxBase")}</span>
<div className="input_wrap">
<SharedInput
value={`${option.gasPrice}`}
value={`${option.gasPriceGwei}`}
isSmall
type="number"
onChange={(value: string) => {
updateCustomGas(
BigInt(option.minerTip ?? 0n),
gweiToWei(parseFloat(value))
)
)
if (baseGasFee && gweiToWei(parseFloat(value)) < baseGasFee) {
setWarningMessage(t("errors.lowGas"))
} else {
Expand Down

0 comments on commit 6464cca

Please sign in to comment.