Skip to content
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

Open
wants to merge 8 commits into
base: develop
Choose a base branch
from
Open

Fix/overloaded funcs #14

wants to merge 8 commits into from

Conversation

crazyrabbitLTC
Copy link
Contributor

🌟 Add support for overloaded functions

@crazyrabbitLTC crazyrabbitLTC requested a review from lndgalante June 3, 2020 22:54
@crazyrabbitLTC
Copy link
Contributor Author

@lndgalante I requested your review.

Comment on lines +58 to +71
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.
}
Copy link
Contributor

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:

Suggested change
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);

Comment on lines +105 to +111
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
}
}
Copy link
Contributor

@lndgalante lndgalante Jun 4, 2020

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

Suggested change
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;
};

Copy link
Contributor

@lndgalante lndgalante left a 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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants