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

Commit

Permalink
fix: reject Safe creation if reverted (#3692)
Browse files Browse the repository at this point in the history
* fix: clear pending status upon failure

* fix: rename function

* fix: don't throw

* fix: resolve spy

* fix: reject Safe creation if reverted

* fix: don't check receipt + set `txId`

* fix: don't check for reversion on `promiEvent`

* fix: throw `Error` object + adjust comment

* fix: throw `Error` object + adjust comment

* fix: add return
  • Loading branch information
iamacook authored Mar 22, 2022
1 parent e897403 commit 1b1ecde
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ describe('PendingTxMonitor', () => {
}
})

it('checks each pending tx', async () => {
it.only('checks each pending tx', async () => {
jest.spyOn(store.store, 'getState').mockImplementation(() => ({
pendingTransactions: {
'4': {
Expand Down
9 changes: 9 additions & 0 deletions src/routes/CreateSafePage/components/SafeCreationProcess.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import { getExplorerInfo, getShortName } from 'src/config'
import { createSendParams } from 'src/logic/safe/transactions/gas'
import { currentChainId } from 'src/logic/config/store/selectors'
import PrefixedEthHashInfo from 'src/components/PrefixedEthHashInfo'
import { didTxRevert } from 'src/logic/safe/store/actions/transactions/utils/transactionHelpers'

export const InlinePrefixedEthHashInfo = styled(PrefixedEthHashInfo)`
display: inline-flex;
Expand Down Expand Up @@ -136,6 +137,13 @@ const createNewSafe = (userAddress: string, onHash: (hash: string) => void): Pro
// Monitor the latest block to find a potential speed-up tx
txMonitor({ sender: userAddress, hash: txHash, data: deploymentTx.encodeABI() })
.then((txReceipt) => {
// txMonitor returns the txReceipt from `getTransactionReceipt` which doesn't throw
// if it was reverted. We must check the status of the receipt manually.
if (didTxRevert(txReceipt)) {
reject(new Error('Sped-up tx reverted'))
return
}

console.log('Sped-up tx mined:', txReceipt)
resolve(txReceipt)
})
Expand All @@ -148,6 +156,7 @@ const createNewSafe = (userAddress: string, onHash: (hash: string) => void): Pro
resolve(txReceipt)
})
.catch((error) => {
// `deploymentTx` will throw if the transaction was reverted
reject(parseError(error))
})
})
Expand Down

0 comments on commit 1b1ecde

Please sign in to comment.