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 363
Fix: conditions to display "Execute transaction" #3257
Merged
Merged
Changes from 27 commits
Commits
Show all changes
28 commits
Select commit
Hold shift + click to select a range
a216e28
Build: create a hook for getting the recommended nonce
0266a1e
Build: extract "can execute transaction" to a hook
b084b55
Build: remove unused return type
f0fb4cf
Build: use "can execute" hook to retrieve condition to show the checkbox
ab24bd3
Refactor: use ComponentProps to get component types
240478a
Fix: remove from tests logic extracted to hook
ffc1bfc
refactor: refactor the useCanExecuteType to test the logic
d56093b
refactor: exclude the spending limit logic from useCanTxExecute
57612cf
refactor: use useCanTxExecute in other review modals
a989041
fix: improve useCanTxExecute types and logic
1fa2d51
refactor: do not return isExecution from useEstimateTransactionGas
e1c7de6
fix: approve modal logic
93ef7c2
build: include PENDING_FAILED transactions in awaiting for execution
674c8a8
build: flag execution to calculate tx gas
5cca7a9
build: include PENDING_FAILED tx status in showing execution tooltip …
31f0efb
fix: adjust tests to reflect latest logic
01ac45e
fix: add missing hook dependency
144a35c
fix: avoid race conditions when fetching from the backend
2befeb9
fix: implement minor PR comments
738e7a2
build: display the Execute checkbox if safe nonce is edited to be next
9b622dd
fix: update tests to take manualSafeNonce
be54a48
fix: remove wrong check
f501dde
refactor: rename execution related variables
669f8e4
fix: rename variable
3f26613
Obtain isOffChainSignature by calling a function instead of prop dril…
fa26e8d
Calculate tx gas even for off chain transactions
572c8f8
Merge branch 'dev' into hide-execute-checkbox-conditions
DiogoSoaress 7e8d179
fix TransactionFees rendering
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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', () => { | ||
iamacook marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should not default the Safe version otherwise it won't calculate the possibility of off chain signing correctly. You should get it from the Safe instance.