-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Add Hex Check For User Input #5668
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Added hex check for user input, the lack of which was causing the app to crash due to the `toWei` method not supporting hex strings
CLA Signature Action: All authors have signed the CLA. You may need to manually re-run the blocking PR check if it doesn't pass in a few minutes. |
I have read the CLA Document and I hereby sign the CLA |
@MetaMask/mobile-devs PTAL |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hey @rduttshukla, thanks for the catch and fix! LGTM
I think we can add a test for invalid inputs with or following this PR
@@ -85,6 +85,7 @@ import { | |||
CURRENCY_SWITCH, | |||
} from '../../../../../wdio/screen-objects/testIDs/Screens/AmountScreen.testIds.js'; | |||
import generateTestId from '../../../../../wdio/utils/generateTestId'; | |||
import { isHexString } from 'ethjs-util'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This functionality is already imported at least through ethers
.
See app/components/UI/PaymentRequest/index.js
for example.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@digiwand looks like this may be an inconsistent update-merge - could you take a look and rebase if necessary?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice catch @legobeat. agreed using the ethers
module would be preferred here too
I used the GitHub UI to resolve the merge conflict. I checked out the PR and the code looks good to me still
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@digiwand looks like we're still importing from ethjs-util
after the merge
could you retry or add a commit importing/using ethers
? should fix the CI lint error too
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧹 as an aside could also follow-up separately to update below to ethers
🧹
metamask-mobile/app/util/address/index.js
Lines 4 to 8 in fbbd7d5
isHexString, | |
addHexPrefix, | |
isValidChecksumAddress, | |
isHexPrefixed, | |
} from 'ethereumjs-util'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
^ Dropping ethereumjs-util
(deprecated) in favor of either ethers
or @ethereumjs/util
would be great I think
Development & PR Process
release-xx
label to identify the PR slated for a upcoming release (will be used in release discussion)needs-dev-review
label when work is completedneeds-qa
label when dev review is completedQA Passed
label when QA has signed offDescription
Added hex check for user input under Send Flow, the lack of which was causing the app to crash due to the
toWei
method not supporting hex strings. The reason for writing this PR are as belowScreenshots/Recordings
Here is the screen recording demonstrating the issue.
WhatsApp.Video.2023-02-02.at.23.25.06.mp4
Issue
The issue is that the
isDecimal
check returnstrue
a string like '0x1' but the resulting hex string is incompatible with thetoWei
method. While we can change theisDecimal
to returnfalse
for hex strings, the solution I preferred is checking the string in theonInputChange
method instead.While we should depend on the
keyboardType
prop set asnumeric
, but as seen in the screen recording, it did not work as expected. Moreover, the prop didn't prevent pasting of non-numeric data at my end.