Skip to content

Commit

Permalink
fix: Handle safe creation errors (#1591)
Browse files Browse the repository at this point in the history
  • Loading branch information
usame-algan authored Jan 24, 2023
1 parent f0ba1ea commit 7a65685
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
10 changes: 4 additions & 6 deletions src/components/new-safe/create/logic/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,10 @@ describe('checkSafeCreationTx', () => {
expect(result).toBe(SafeCreationStatus.REVERTED)
})

it('returns TIMEOUT if transaction couldnt be found within the timeout limit', async () => {
it('returns TIMEOUT if transaction could not be found within the timeout limit', async () => {
const mockEthersError = {
...new Error(),
receipt: {
status: 1,
},
code: ErrorCode.TIMEOUT,
}

waitForTxSpy.mockImplementationOnce(() => Promise.reject(mockEthersError))
Expand Down Expand Up @@ -173,7 +171,7 @@ describe('handleSafeCreationError', () => {
expect(result).toEqual(SafeCreationStatus.SUCCESS)
})

it('returns TIMEOUT if the tx was not rejected, cancelled or replaced', () => {
it('returns ERROR if the tx was not rejected, cancelled or replaced', () => {
const mockEthersError = {
...new Error(),
code: ErrorCode.UNKNOWN_ERROR,
Expand All @@ -183,7 +181,7 @@ describe('handleSafeCreationError', () => {

const result = handleSafeCreationError(mockEthersError)

expect(result).toEqual(SafeCreationStatus.TIMEOUT)
expect(result).toEqual(SafeCreationStatus.ERROR)
})

it('returns REVERTED if the tx failed', () => {
Expand Down
9 changes: 6 additions & 3 deletions src/components/new-safe/create/logic/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { Web3Provider, JsonRpcProvider } from '@ethersproject/providers'
import type { ChainInfo } from '@safe-global/safe-gateway-typescript-sdk'
import { getSafeInfo, type SafeInfo, type ChainInfo } from '@safe-global/safe-gateway-typescript-sdk'
import {
getFallbackHandlerContractInstance,
getGnosisSafeContractInstance,
Expand All @@ -26,7 +26,6 @@ import type Safe from '@safe-global/safe-core-sdk'
import type { DeploySafeProps } from '@safe-global/safe-core-sdk'
import { createEthersAdapter } from '@/hooks/coreSDK/safeCoreSDK'
import type { PredictSafeProps } from '@safe-global/safe-core-sdk/dist/src/safeFactory'
import { getSafeInfo, type SafeInfo } from '@safe-global/safe-gateway-typescript-sdk'
import { backOff } from 'exponential-backoff'
import { LATEST_SAFE_VERSION } from '@/config/constants'
import { EMPTY_DATA, ZERO_ADDRESS } from '@safe-global/safe-core-sdk/dist/src/utils/constants'
Expand Down Expand Up @@ -184,7 +183,11 @@ export const handleSafeCreationError = (error: EthersError) => {
return SafeCreationStatus.REVERTED
}

return SafeCreationStatus.TIMEOUT
if (error.code === ErrorCode.TIMEOUT) {
return SafeCreationStatus.TIMEOUT
}

return SafeCreationStatus.ERROR
}

export const SAFE_CREATION_ERROR_KEY = 'create-safe-error'
Expand Down

0 comments on commit 7a65685

Please sign in to comment.