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

Commit

Permalink
fix: display notification for decode contract error (#3879)
Browse files Browse the repository at this point in the history
* fix: display notification for decode contract error

* fix: move error log to createTransaction try...catch

* fix: do not instantiate CodeException again to log error

* fix: show decoded contract error in the notification

* fix: rm unnecessary try..catch block

* fix: return a decoded message instead of propagating the Error

* fix: ammend test asserrtion when no error_code found

Co-authored-by: katspaugh <[email protected]>
  • Loading branch information
DiogoSoaress and katspaugh authored May 23, 2022
1 parent 092bf07 commit 55f6c61
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/logic/contracts/__tests__/safeContractErrors.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
})
9 changes: 6 additions & 3 deletions src/logic/contracts/safeContractErrors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 ({
Expand All @@ -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
}
}

0 comments on commit 55f6c61

Please sign in to comment.