1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-10-22 11:22:43 +02:00

Fix for #11503: when you send a transaction with value as 0x, you get a Bignumber error (#11996)

* Fix for #11503: when you send a transaction with value  as 0x, you get a
Bignumber error. Fix this by setting value to 0x0 is it's 0x.

Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com>

* 1. Fix this in app/scripts/controllers/transactions/lib/utils.js
2. Make sure other non-hex non-valid strings for value return 0x0

Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com>

* Linting Fixes.

Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com>

* Instead of returning 0x0 for invalid hex values, throw a descriptive
error

Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com>

* Unit tests.
Lint fixes.

Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com>

* assert.throws takes a function

Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com>

* Lint Fixes.

Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com>

* Use standardized error message.

Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com>

* remove fixHexValue
move code validating hex value to validateTxParams

Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com>

* Change message displayed if hex string is invalid.

Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com>

* Fixed missing second quote mark on message.

Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com>
This commit is contained in:
Akintayo A. Olusegun 2021-10-15 13:04:14 +01:00 committed by GitHub
parent be0508d41e
commit 319ab42bc1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -197,6 +197,12 @@ export function validateTxParams(txParams, eip1559Compatibility = true) {
`Invalid transaction value of "${value}": number must be in wei.`,
);
}
if (!value.match(/^0x[a-fA-F0-9]+$/u)) {
throw ethErrors.rpc.invalidParams(
`Invalid transaction value of "${value}": not a valid hex string.`,
);
}
break;
case 'chainId':
if (typeof value !== 'number' && typeof value !== 'string') {