LeastAuthority / metamask-plugin-beta

MIT License
1 stars 4 forks source link

Check will return true if the `opts[requiredField]` property is declared but undefined #2

Open tacticalchihuahua opened 4 years ago

tacticalchihuahua commented 4 years ago

This check will return true if the opts[requiredField] property is declared but undefined. Example:

em@xps7390 ~ $ node
> const opts = { symbol: undefined, balance: null, identifier: function() {}, decimals: -19, customViewUrl: '' };
undefined
> const assetRequiredFields = ['symbol', 'balance', 'identifier', 'decimals', 'customViewUrl']
undefined
> assetRequiredFields.forEach((requiredField) => {
... if (!(requiredField in opts)) {
..... throw new Error('missing required field');
..... }
... })
undefined
> 

Instead of (!(requiredField in opts)) use (typeof opts[requiredField] === 'undefined'), as well as adding more sophisticated validation for the specific fields.

Originally posted by @emeryrose in https://github.com/LeastAuthority/metamask-plugin-beta/pull/1