Merge pull request #2783 from MetaMask/tx-param-vaalidation

transactions - throw error if txParams.value contains a decimal
This commit is contained in:
kumavis 2018-01-02 14:30:39 -08:00 committed by GitHub
commit 313b3c087a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 2 deletions

View File

@ -2,6 +2,7 @@
## Current Master
- Throw an error if a application tries to submit a tx whose value is a decimal, and inform that it should be in wei.
- Fix bug that prevented updating custom token details.
- No longer mark long-pending transactions as failed, since we now have button to retry with higher gas.
- Fix rounding error when specifying an ether amount that has too much precision.

View File

@ -81,8 +81,15 @@ module.exports = class txProvideUtil {
}
async validateTxParams (txParams) {
if (('value' in txParams) && txParams.value.indexOf('-') === 0) {
if ('value' in txParams) {
const value = txParams.value.toString()
if (value.includes('-')) {
throw new Error(`Invalid transaction value of ${txParams.value} not a positive number.`)
}
if (value.includes('.')) {
throw new Error(`Invalid transaction value of ${txParams.value} number must be in wei`)
}
}
}
}