(Fix) - #1783 Trezor gas estimation fail (#1788)

* Improves the way we parse the error message on getDataFromNodeErrorMessage for supporting trezor response

* Fix trezor execution not working properly

* Add parameter to processTransaction in ApproveTxModal

Co-authored-by: Daniel Sanchez <daniel.sanchez@gnosis.pm>
This commit is contained in:
Agustin Pane 2021-01-18 14:04:04 -03:00 committed by GitHub
parent 0fb1824f49
commit ce43a97bee
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 26 additions and 2 deletions

View File

@ -32,6 +32,7 @@ interface ProcessTransactionArgs {
safeAddress: string safeAddress: string
tx: Transaction tx: Transaction
userAddress: string userAddress: string
thresholdReached: boolean
} }
type ProcessTransactionAction = ThunkAction<Promise<void | string>, AppReduxState, DispatchReturn, AnyAction> type ProcessTransactionAction = ThunkAction<Promise<void | string>, AppReduxState, DispatchReturn, AnyAction>
@ -42,6 +43,7 @@ export const processTransaction = ({
safeAddress, safeAddress,
tx, tx,
userAddress, userAddress,
thresholdReached,
}: ProcessTransactionArgs): ProcessTransactionAction => async ( }: ProcessTransactionArgs): ProcessTransactionAction => async (
dispatch: Dispatch, dispatch: Dispatch,
getState: () => AppReduxState, getState: () => AppReduxState,
@ -56,7 +58,7 @@ export const processTransaction = ({
const isExecution = approveAndExecute || (await shouldExecuteTransaction(safeInstance, nonce, lastTx)) const isExecution = approveAndExecute || (await shouldExecuteTransaction(safeInstance, nonce, lastTx))
const safeVersion = await getCurrentSafeVersion(safeInstance) const safeVersion = await getCurrentSafeVersion(safeInstance)
const preApprovingOwner = approveAndExecute ? userAddress : undefined const preApprovingOwner = approveAndExecute && !thresholdReached ? userAddress : undefined
let sigs = generateSignaturesFromTxConfirmations(tx.confirmations, preApprovingOwner) let sigs = generateSignaturesFromTxConfirmations(tx.confirmations, preApprovingOwner)
if (!sigs) { if (!sigs) {

View File

@ -25,6 +25,21 @@ const parseRequiredTxGasResponse = (data: string): number => {
return data.match(/.{2}/g)?.reduce(reducer, 0) return data.match(/.{2}/g)?.reduce(reducer, 0)
} }
interface ErrorDataJson extends JSON {
originalError?: {
data?: string
}
data?: string
}
const getJSONOrNullFromString = (stringInput: string): ErrorDataJson | null => {
try {
return JSON.parse(stringInput)
} catch (error) {
return null
}
}
// Parses the result from the error message (GETH, OpenEthereum/Parity and Nethermind) and returns the data value // Parses the result from the error message (GETH, OpenEthereum/Parity and Nethermind) and returns the data value
export const getDataFromNodeErrorMessage = (errorMessage: string): string | undefined => { export const getDataFromNodeErrorMessage = (errorMessage: string): string | undefined => {
// Replace illegal characters that often comes within the error string (like <20> for example) // Replace illegal characters that often comes within the error string (like <20> for example)
@ -35,7 +50,13 @@ export const getDataFromNodeErrorMessage = (errorMessage: string): string | unde
const [, ...error] = normalizedErrorString.split('\n') const [, ...error] = normalizedErrorString.split('\n')
try { try {
const errorAsJSON = JSON.parse(error.join('')) const errorAsString = error.join('')
const errorAsJSON = getJSONOrNullFromString(errorAsString)
// Trezor wallet returns the error not as an JSON object but directly as string
if (!errorAsJSON) {
return errorAsString.length ? errorAsString : undefined
}
// For new GETH nodes they will return the data as error in the format: // For new GETH nodes they will return the data as error in the format:
// { // {

View File

@ -105,6 +105,7 @@ export const ApproveTxModal = ({
userAddress, userAddress,
notifiedTransaction: TX_NOTIFICATION_TYPES.CONFIRMATION_TX, notifiedTransaction: TX_NOTIFICATION_TYPES.CONFIRMATION_TX,
approveAndExecute: canExecute && approveAndExecute && isTheTxReadyToBeExecuted, approveAndExecute: canExecute && approveAndExecute && isTheTxReadyToBeExecuted,
thresholdReached,
}), }),
) )
onClose() onClose()