This repository has been archived by the owner on Nov 10, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 362
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix: conditions to display "Execute transaction" (#3257)
* Build: create a hook for getting the recommended nonce * Build: extract "can execute transaction" to a hook * Build: remove unused return type * Build: use "can execute" hook to retrieve condition to show the checkbox * Refactor: use ComponentProps to get component types * Fix: remove from tests logic extracted to hook * refactor: refactor the useCanExecuteType to test the logic * refactor: exclude the spending limit logic from useCanTxExecute * refactor: use useCanTxExecute in other review modals * fix: improve useCanTxExecute types and logic * refactor: do not return isExecution from useEstimateTransactionGas * fix: approve modal logic * build: include PENDING_FAILED transactions in awaiting for execution * build: flag execution to calculate tx gas * build: include PENDING_FAILED tx status in showing execution tooltip and icon * fix: adjust tests to reflect latest logic * fix: add missing hook dependency * fix: avoid race conditions when fetching from the backend * fix: implement minor PR comments * build: display the Execute checkbox if safe nonce is edited to be next * fix: update tests to take manualSafeNonce * fix: remove wrong check * refactor: rename execution related variables * fix: rename variable * Obtain isOffChainSignature by calling a function instead of prop drilling * Calculate tx gas even for off chain transactions * fix TransactionFees rendering
- Loading branch information
1 parent
88f93ab
commit 42c2ee6
Showing
27 changed files
with
555 additions
and
241 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,191 @@ | ||
import { calculateCanTxExecute } from '../useCanTxExecute' | ||
|
||
describe('useCanTxExecute tests', () => { | ||
describe('calculateCanTxExecute tests', () => { | ||
beforeEach(() => { | ||
threshold = 1 | ||
isExecution = false | ||
currentSafeNonce = 8 | ||
recommendedNonce = 8 | ||
txConfirmations = 0 | ||
preApprovingOwner = '' | ||
manualSafeNonce = recommendedNonce | ||
}) | ||
// to be overriden as necessary | ||
let threshold | ||
let preApprovingOwner | ||
let txConfirmations | ||
let currentSafeNonce | ||
let recommendedNonce | ||
let isExecution | ||
let manualSafeNonce | ||
it(`should return true if isExecution`, () => { | ||
// given | ||
isExecution = true | ||
|
||
// when | ||
const result = calculateCanTxExecute( | ||
currentSafeNonce, | ||
preApprovingOwner, | ||
threshold, | ||
txConfirmations, | ||
recommendedNonce, | ||
isExecution, | ||
) | ||
|
||
// then | ||
expect(result).toBe(true) | ||
}) | ||
it(`should return true if single owner and edited nonce is same as safeNonce`, () => { | ||
// given | ||
threshold = 1 | ||
currentSafeNonce = 8 | ||
recommendedNonce = 12 | ||
manualSafeNonce = 8 | ||
|
||
// when | ||
const result = calculateCanTxExecute( | ||
currentSafeNonce, | ||
preApprovingOwner, | ||
threshold, | ||
txConfirmations, | ||
recommendedNonce, | ||
undefined, | ||
manualSafeNonce, | ||
) | ||
|
||
// then | ||
expect(result).toBe(true) | ||
}) | ||
it(`should return false if single owner and edited nonce is different than safeNonce`, () => { | ||
// given | ||
threshold = 1 | ||
currentSafeNonce = 8 | ||
recommendedNonce = 8 | ||
manualSafeNonce = 20 | ||
|
||
// when | ||
const result = calculateCanTxExecute( | ||
currentSafeNonce, | ||
preApprovingOwner, | ||
threshold, | ||
txConfirmations, | ||
recommendedNonce, | ||
undefined, | ||
manualSafeNonce, | ||
) | ||
|
||
// then | ||
expect(result).toBe(false) | ||
}) | ||
it(`should return true if single owner and recommendedNonce is same as safeNonce`, () => { | ||
// given | ||
threshold = 1 | ||
currentSafeNonce = 8 | ||
recommendedNonce = 8 | ||
|
||
// when | ||
const result = calculateCanTxExecute( | ||
currentSafeNonce, | ||
preApprovingOwner, | ||
threshold, | ||
txConfirmations, | ||
recommendedNonce, | ||
) | ||
|
||
// then | ||
expect(result).toBe(true) | ||
}) | ||
it(`should return false if single owner and recommendedNonce is greater than safeNonce and no edited nonce`, () => { | ||
// given | ||
threshold = 1 | ||
currentSafeNonce = 8 | ||
recommendedNonce = 11 | ||
manualSafeNonce = undefined | ||
|
||
// when | ||
const result = calculateCanTxExecute( | ||
currentSafeNonce, | ||
preApprovingOwner, | ||
threshold, | ||
txConfirmations, | ||
recommendedNonce, | ||
undefined, | ||
manualSafeNonce, | ||
) | ||
|
||
// then | ||
expect(result).toBe(false) | ||
}) | ||
it(`should return false if single owner and recommendedNonce is different than safeNonce`, () => { | ||
// given | ||
threshold = 1 | ||
currentSafeNonce = 8 | ||
recommendedNonce = 12 | ||
|
||
// when | ||
const result = calculateCanTxExecute( | ||
currentSafeNonce, | ||
preApprovingOwner, | ||
threshold, | ||
txConfirmations, | ||
recommendedNonce, | ||
) | ||
|
||
// then | ||
expect(result).toBe(false) | ||
}) | ||
it(`should return true if the safe threshold is reached for the transaction`, () => { | ||
// given | ||
threshold = 3 | ||
txConfirmations = 3 | ||
|
||
// when | ||
const result = calculateCanTxExecute( | ||
currentSafeNonce, | ||
preApprovingOwner, | ||
threshold, | ||
txConfirmations, | ||
recommendedNonce, | ||
) | ||
|
||
// then | ||
expect(result).toBe(true) | ||
}) | ||
it(`should return false if the number of confirmations does not meet the threshold and there is no preApprovingOwner`, () => { | ||
// given | ||
threshold = 5 | ||
txConfirmations = 4 | ||
|
||
// when | ||
const result = calculateCanTxExecute( | ||
currentSafeNonce, | ||
preApprovingOwner, | ||
threshold, | ||
txConfirmations, | ||
recommendedNonce, | ||
) | ||
|
||
// then | ||
expect(result).toBe(false) | ||
}) | ||
it(`should return true if the number of confirmations is one bellow the threshold but there is a preApprovingOwner`, () => { | ||
// given | ||
threshold = 5 | ||
preApprovingOwner = '0x29B1b813b6e84654Ca698ef5d7808E154364900B' | ||
txConfirmations = 4 | ||
|
||
// when | ||
const result = calculateCanTxExecute( | ||
currentSafeNonce, | ||
preApprovingOwner, | ||
threshold, | ||
txConfirmations, | ||
recommendedNonce, | ||
) | ||
|
||
// then | ||
expect(result).toBe(true) | ||
}) | ||
}) | ||
}) |
74 changes: 1 addition & 73 deletions
74
src/logic/hooks/__tests__/useEstimateTransactionGas.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.