-
Notifications
You must be signed in to change notification settings - Fork 2
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
Fix/overloaded funcs #14
base: develop
Are you sure you want to change the base?
Conversation
@lndgalante I requested your review. |
let contractMethod = contractABI.find((method) => methodName === method.name); | ||
|
||
//If we are over loaded, check how many inputs this method has. | ||
if (contractMethods.length > 1) { | ||
//Get all the inputs for the Method. | ||
const contractInputs = Array.from( | ||
document.querySelectorAll(createAttributeSelector(`data-dh-property-method-id`, methodId)), | ||
).filter((element) => !(element.getAttribute('id') || '').includes('dh')).filter((element) => element.nodeName === 'INPUT') | ||
|
||
//Get the method that has the number of imputs which matches | ||
contractMethod = contractMethods.filter((method) => method.inputs.length === contractInputs.length)[0] | ||
|
||
//If the number of inputs does not match either function, then it's an error. | ||
} |
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.
Would prefer const
and use of destructuring
for avoiding variable mutations and code simplicity
Code example:
let contractMethod = contractABI.find((method) => methodName === method.name); | |
//If we are over loaded, check how many inputs this method has. | |
if (contractMethods.length > 1) { | |
//Get all the inputs for the Method. | |
const contractInputs = Array.from( | |
document.querySelectorAll(createAttributeSelector(`data-dh-property-method-id`, methodId)), | |
).filter((element) => !(element.getAttribute('id') || '').includes('dh')).filter((element) => element.nodeName === 'INPUT') | |
//Get the method that has the number of imputs which matches | |
contractMethod = contractMethods.filter((method) => method.inputs.length === contractInputs.length)[0] | |
//If the number of inputs does not match either function, then it's an error. | |
} | |
//Get all the inputs for the Method. | |
const contractInputs = Array.from( | |
document.querySelectorAll(createAttributeSelector(`data-dh-property-method-id`, methodId)), | |
) | |
.filter((element) => !(element.getAttribute('id') || '').includes('dh')) | |
.filter((element) => element.nodeName === 'INPUT'); | |
// If we are over loaded, check how many inputs this method has. | |
const contractMethod = | |
contractMethods.length > 1 | |
? contractMethods.filter((method) => method.inputs.length === contractInputs.length)[0] | |
: contractABI.find(({ name }) => methodName === name); |
const getIsArray = (value) => { | ||
if (value.charAt(0) === '[' && value.charAt(value.length - 1) === ']' && !isNaN(value.substring(1, value.length - 1))) { | ||
return parseInt(value.substring(1, value.length - 1), 10) | ||
} else { | ||
return false | ||
} | ||
} |
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.
Would prefer a RegExp for this scenario since it would be easier to understand and maintain
const getIsArray = (value) => { | |
if (value.charAt(0) === '[' && value.charAt(value.length - 1) === ']' && !isNaN(value.substring(1, value.length - 1))) { | |
return parseInt(value.substring(1, value.length - 1), 10) | |
} else { | |
return false | |
} | |
} | |
const getIsArray = (value) => { | |
const [position] = value.match(/\d+/g) || []; | |
const isPosition = !isNaN(position); | |
return isPosition ? Number(position) : false; | |
}; |
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.
Left a few comments!
🌟 Add support for overloaded functions