Skip to content
This repository has been archived by the owner on Nov 10, 2023. It is now read-only.

Commit

Permalink
fix: prevent endless estimation on erronous gas limit estimation (#3959)
Browse files Browse the repository at this point in the history
  • Loading branch information
Manuel Gellfart authored Jun 10, 2022
1 parent 8e5e60a commit c49db48
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 6 deletions.
6 changes: 3 additions & 3 deletions src/logic/hooks/__tests__/useExecutionStatus.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ describe('useExecutionStatus', () => {
})
})

it('returns LOADING if gasLimit is 0', async () => {
it('returns SUCCESS if gasLimit is 0', async () => {
const mockFn = jest.fn(() => Promise.resolve(true))

const { result } = renderHook(() =>
Expand All @@ -58,8 +58,8 @@ describe('useExecutionStatus', () => {
)

await waitFor(() => {
expect(result.current).toBe(EstimationStatus.LOADING)
expect(mockFn).toHaveBeenCalledTimes(0)
expect(result.current).toBe(EstimationStatus.SUCCESS)
expect(mockFn).toHaveBeenCalledTimes(1)
})
})

Expand Down
4 changes: 1 addition & 3 deletions src/logic/hooks/useExecutionStatus.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { DEFAULT_GAS, EstimationStatus } from 'src/logic/hooks/useEstimateTransactionGas'
import { useEffect, useState } from 'react'
import useAsync from 'src/logic/hooks/useAsync'
import { DEFAULT_GAS_LIMIT } from 'src/logic/hooks/useEstimateGasLimit'

type Props = {
checkTxExecution: () => Promise<boolean>
Expand All @@ -24,8 +23,7 @@ export const useExecutionStatus = ({

const [status, error, loading] = useAsync(async () => {
if (!isExecution || !txData) return EstimationStatus.SUCCESS
const isEstimationPending =
!gasLimit || gasLimit === DEFAULT_GAS_LIMIT || gasPrice === DEFAULT_GAS || gasMaxPrioFee === DEFAULT_GAS
const isEstimationPending = !gasLimit || gasPrice === DEFAULT_GAS || gasMaxPrioFee === DEFAULT_GAS
if (isEstimationPending) return EstimationStatus.LOADING

const success = await checkTxExecution()
Expand Down

0 comments on commit c49db48

Please sign in to comment.