diff --git a/src/logic/contracts/__tests__/safeContractErrors.test.ts b/src/logic/contracts/__tests__/safeContractErrors.test.ts index 393c921607..188b82c410 100644 --- a/src/logic/contracts/__tests__/safeContractErrors.test.ts +++ b/src/logic/contracts/__tests__/safeContractErrors.test.ts @@ -14,6 +14,6 @@ describe('decodeMessage', () => { }) it('returns provided errors if not safe errors', () => { - expect(decodeMessage('Not a Safe error')).toBe('Not a Safe error') + expect(decodeMessage('Not a Safe error')).toBe(null) }) }) diff --git a/src/logic/contracts/safeContractErrors.ts b/src/logic/contracts/safeContractErrors.ts index 8ef0bb1471..a5ce3ae26f 100644 --- a/src/logic/contracts/safeContractErrors.ts +++ b/src/logic/contracts/safeContractErrors.ts @@ -5,12 +5,14 @@ import { getWeb3 } from 'src/logic/wallets/getWeb3' import { GnosisSafe } from 'src/types/contracts/gnosis_safe.d' import { logError, Errors } from '../exceptions/CodedException' -export const decodeMessage = (message: string): string => { +const GENERIC_FAILED_TX_MSG = 'unable to decode contract error message' + +export const decodeMessage = (message: string): string | null => { const code = CONTRACT_ERROR_CODES.find((code) => { return message.toUpperCase().includes(code.toUpperCase()) }) - return code ? `${code}: ${CONTRACT_ERRORS[code]}` : message + return code ? `${code}: ${CONTRACT_ERRORS[code]}` : null } export const getContractErrorMessage = async ({ @@ -35,8 +37,9 @@ export const getContractErrorMessage = async ({ const returnBuffer = Buffer.from(returnData.slice(2), 'hex') const contractOutput = abi.rawDecode(['string'], returnBuffer.slice(4))[0] - return decodeMessage(contractOutput) + return decodeMessage(contractOutput) || contractOutput } catch (err) { logError(Errors._817, err.message) + return GENERIC_FAILED_TX_MSG } }