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

Commit

Permalink
fix: Set safeTxGas to 0 when rejecting a tx (#3605)
Browse files Browse the repository at this point in the history
* fix: Set safeTxGas to 0 when rejecting a tx

* fix: Add missing isRejectTx dependency
  • Loading branch information
usame-algan committed Mar 3, 2022
1 parent 7805d06 commit 13ca2a7
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
22 changes: 22 additions & 0 deletions src/logic/hooks/__tests__/useEstimateSafeTxGas.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,35 @@ jest.mock('react-redux', () => {

describe('useEstimateSafeTxGas', () => {
it(`should return 0 if it is not a tx creation`, () => {
const spy = jest.spyOn(gas, 'estimateSafeTxGas')

const { result } = renderHook(() =>
useEstimateSafeTxGas({
txAmount: '',
txData: '',
txRecipient: '',
isCreation: false,
isRejectTx: false,
}),
)
expect(result.current).toBe('0')
expect(spy).toHaveBeenCalledTimes(0)
})

it(`should return 0 if it is a reject tx`, () => {
const spy = jest.spyOn(gas, 'estimateSafeTxGas')

const { result } = renderHook(() =>
useEstimateSafeTxGas({
txAmount: '',
txData: '',
txRecipient: '',
isCreation: false,
isRejectTx: true,
}),
)
expect(result.current).toBe('0')
expect(spy).toHaveBeenCalledTimes(0)
})

it(`calls estimateSafeTxGas if it is a tx creation`, () => {
Expand All @@ -32,6 +52,7 @@ describe('useEstimateSafeTxGas', () => {
txData: '',
txRecipient: '',
isCreation: true,
isRejectTx: false,
}),
)
expect(spy).toHaveBeenCalledTimes(1)
Expand All @@ -48,6 +69,7 @@ describe('useEstimateSafeTxGas', () => {
txData: '',
txRecipient: '',
isCreation: true,
isRejectTx: false,
}),
)
expect(spy).toHaveBeenCalledTimes(1)
Expand Down
6 changes: 4 additions & 2 deletions src/logic/hooks/useEstimateSafeTxGas.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { currentSafe } from 'src/logic/safe/store/selectors'

type UseEstimateSafeTxGasProps = {
isCreation: boolean
isRejectTx: boolean
txData: string
txRecipient: string
txAmount: string
Expand All @@ -15,6 +16,7 @@ type UseEstimateSafeTxGasProps = {

export const useEstimateSafeTxGas = ({
isCreation,
isRejectTx,
txData,
txRecipient,
txAmount,
Expand All @@ -24,7 +26,7 @@ export const useEstimateSafeTxGas = ({
const { address: safeAddress, currentVersion: safeVersion } = useSelector(currentSafe) ?? {}

useEffect(() => {
if (!isCreation) return
if (!isCreation || isRejectTx) return
const estimateSafeTxGasCall = async () => {
try {
const safeTxGasEstimation = await estimateSafeTxGas(
Expand All @@ -43,7 +45,7 @@ export const useEstimateSafeTxGas = ({
}
}
estimateSafeTxGasCall()
}, [isCreation, operation, safeAddress, safeVersion, txAmount, txData, txRecipient])
}, [isCreation, isRejectTx, operation, safeAddress, safeVersion, txAmount, txData, txRecipient])

return safeTxGasEstimation
}
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ export const TxModalWrapper = ({

const safeTxGasEstimation = useEstimateSafeTxGas({
isCreation,
isRejectTx,
txData,
txRecipient: txTo || safeAddress,
txAmount: txValue,
Expand Down

0 comments on commit 13ca2a7

Please sign in to comment.