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

Bug: 422 status code when proposing transaction from an app #2706

Merged
merged 2 commits into from
Sep 6, 2021

Conversation

mmv08
Copy link
Member

@mmv08 mmv08 commented Sep 6, 2021

What it solves

Resolves #2705

How this PR fixes it

In safe-apps-sdk v0.x.x it was allowed to use an integer for specifying transaction value. This is not the case anymore.

Some apps are still using an old sdk version and therefore this line of code would evaluate to 0:
https://github.com/gnosis/safe-react/blob/93ce1803605198af282a18d8fb2c3b7227dbe60f/src/routes/safe/components/Apps/components/ConfirmTxModal/ReviewConfirm.tsx#L101

The backend expects a string, so the transaction will be rejected by the backend

How to test it

Try using aave v1 app

iamacook and others added 2 commits September 6, 2021 12:21
* Handle chunk loading error + add Suspense types

* Remove hook/expiry functions from error boundary

* Add account to CLA

* Fix ESLint

* Fix React import

* Extract handleChunkError + test it

* Fix tests

* Return handleChunkError boolean + alter no. format

* Move const to beginning of fn + don't export key

* Update test to check for boolean return

* Adjust sessionStorage key const
@mmv08 mmv08 requested a review from katspaugh September 6, 2021 10:25
@github-actions
Copy link

github-actions bot commented Sep 6, 2021

CLA Assistant Lite All Contributors have signed the CLA.

@github-actions
Copy link

github-actions bot commented Sep 6, 2021

ESLint Summary View Full Report

Annotations are provided inline on the Files Changed tab. You can also see all annotations that were generated on the annotations page.

Type Occurrences Fixable
Errors 0 0
Warnings 0 0
Ignored 0 N/A
  • Result: ✅ success
  • Annotations: 0 total

Report generated by eslint-plus-action

@@ -98,7 +98,8 @@ export const ReviewConfirm = ({
[txs, isMultiSend],
)
const txValue: string | undefined = useMemo(
() => (isMultiSend ? '0' : txs[0]?.value && parseTxValue(txs[0]?.value)),
// Value is converted to string because numbers were allowed in the safe-apps-sdk v1, so 0 and anything would evaluate as false
() => (isMultiSend ? '0' : txs[0]?.value.toString() && parseTxValue(txs[0]?.value)),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens if value is undefined?

Copy link
Member

@iamacook iamacook Sep 6, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you're expecting undefined, I would suggest optionally chain everything: txs[0]?.value?.toString().

Copy link
Member Author

@mmv08 mmv08 Sep 6, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://github.com/gnosis/safe-apps-sdk/blob/4ce9a16b2d8f4133f6a7e7fbc25f422210cba786/src/types.ts#L35 the type signature doesn't support undefined, actually, it doesn't even support numbers 😅

Currently, it'd error. I think app developers should test their apps, if we'll account for each possible type things will get crazy.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mikheevm but how it is currently this will crash the whole web app, right?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mean I am fine that we error, but then we should properly check what is send to the interface. I would also expect to see tests for something like this.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if we'll account for each possible type things will get crazy

I tend to agree but we don't have to check for wrong types, we need to check for the expected types.

In this case if (typeof value !== 'string') { throw new CodedException('Wrong type used for value') }.

Maybe we could include some runtime type-checker for the apps API, similar to PropTypes in React? And do it in a declarative fashion?

Copy link
Member Author

@mmv08 mmv08 Sep 6, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then undefined should never get that far 👍

@github-actions
Copy link

github-actions bot commented Sep 6, 2021

@github-actions
Copy link

github-actions bot commented Sep 6, 2021

@github-actions
Copy link

github-actions bot commented Sep 6, 2021

@francovenica
Copy link
Contributor

So I was able to create a "Redeem" tx in Aave v1. Didn't execute it since is really expensive to do so, but given that in the original issue the error happens by just trying to create the tx it seems that what I did is enough.
@mikheevm what do you think?

Safe: https://pr2706--safereact.review.gnosisdev.com/mainnet/app/#/safes/0x8675B754342754A30A2AeF474D114d8460bca19b/transactions
Tx 202 in queue tab

image

@mmv08
Copy link
Member Author

mmv08 commented Sep 6, 2021

@francovenica awesome, this should be enough :)

@mmv08
Copy link
Member Author

mmv08 commented Sep 6, 2021

How do we proceed with the release? @katspaugh

@katspaugh
Copy link
Member

Let's merge this and make a release as usual, @mikheevm.

@mmv08 mmv08 merged commit 3d42698 into dev Sep 6, 2021
@mmv08 mmv08 deleted the bug/apps-convert-int-to-string branch September 6, 2021 14:00
@github-actions github-actions bot locked and limited conversation to collaborators Sep 6, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Where is the source code of the AAVE v1 app located?
5 participants