-
Notifications
You must be signed in to change notification settings - Fork 2
Fix/overloaded funcs #14
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
Open
crazyrabbitLTC
wants to merge
8
commits into
develop
Choose a base branch
from
fix/overloaded-funcs
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
3a723c1
🐛 FIX: Allow Array indixes to work for inputs
crazyrabbitLTC 1d8b9f8
👌 IMPROVE: remove console logs
crazyrabbitLTC 3d2957e
🐛 FIX: Seems to be working.
crazyrabbitLTC 97dfa64
👌 IMPROVE: add all 18 units for conversions
crazyrabbitLTC dcef4a5
🐛 FIX: Add support for overloaded methods by argument count
crazyrabbitLTC 65cb808
🐛 FIX: Bug hunting
crazyrabbitLTC 44300d1
👌 IMPROVE: Remove console logs
crazyrabbitLTC 808be03
🐛 FIX: bump DH-Dom
crazyrabbitLTC File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -47,13 +47,38 @@ export const customContractParser = ( | |||||||||||||||||||||||||||
| // Check if method name exists in ABI | ||||||||||||||||||||||||||||
| const methodId = methodIdKey.value; | ||||||||||||||||||||||||||||
| const methodName = methodNameKey.value; | ||||||||||||||||||||||||||||
| const contractMethod = contractABI.find((method) => methodName === method.name); | ||||||||||||||||||||||||||||
| const contractMethods = contractABI.filter((method) => methodName === method.name); | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| // If no contract methods are found, return error | ||||||||||||||||||||||||||||
| if (contractMethods.length === 0) { | ||||||||||||||||||||||||||||
| return console.error(`(DH-DOM) | Method name "${methodName}" does not exists on the contract ABI`); | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| // placeholder for the contract method we will be working with. | ||||||||||||||||||||||||||||
| 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. | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| if (!contractMethod) { | ||||||||||||||||||||||||||||
| return console.error(`(DH-DOM) | Method name "${methodName}" does not exists on the contract ABI`); | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| const isTransaction = contractMethod.stateMutability !== 'view'; | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| // Transactions are transactions if they are not view, pure or constant | ||||||||||||||||||||||||||||
| const isTransaction = !Boolean(['view', 'pure', 'constant'].filter(el => contractMethod.stateMutability === el).length) | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| // const isTransaction = contractMethod.stateMutability !== 'view'; | ||||||||||||||||||||||||||||
| const hasOutputs = contractMethod.outputs.length > 0; | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| // Get customContract children properties | ||||||||||||||||||||||||||||
|
|
@@ -75,26 +100,56 @@ export const customContractParser = ( | |||||||||||||||||||||||||||
| const parsedInputs = inputs | ||||||||||||||||||||||||||||
| .map((input) => { | ||||||||||||||||||||||||||||
| const value = input.getAttribute(property.attribute); | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| // we need to check if the start of value is [ and the end is ] and the middle item is a number. | ||||||||||||||||||||||||||||
| 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 | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
|
Comment on lines
+105
to
+111
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 inputArrayValue = getIsArray(value) | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| const shouldAutoClear = input.getAttribute(`${DATA_PROPERTY}-auto-clear`) === 'true' | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| // Check each input name in ABI equals to the value defined in the DOM | ||||||||||||||||||||||||||||
| const isInputFound = contractMethod.inputs.some((input) => input.name === value); | ||||||||||||||||||||||||||||
| const isInputFound = contractMethod.inputs.some((input) => { | ||||||||||||||||||||||||||||
| if (input.name === value) return true | ||||||||||||||||||||||||||||
| //check if the actually array value is less than or equal to the input array length | ||||||||||||||||||||||||||||
| //note that a zero position value would evaluate falsey, hense we deep equal to false. | ||||||||||||||||||||||||||||
| if (inputArrayValue !== false && inputArrayValue <= contractMethod.inputs.length - 1) { | ||||||||||||||||||||||||||||
| return true | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
| // There is no match for input name, or for array possition, so return false. | ||||||||||||||||||||||||||||
| return false | ||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| // Now that we know it's an array, check if the array value is valid. | ||||||||||||||||||||||||||||
| // Note we will have to also check if ALL the array inputs are found. | ||||||||||||||||||||||||||||
| // Note you could also mix&match the array idnex with a named input (Or too complicated?) | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| const emptyString = '$true'; | ||||||||||||||||||||||||||||
| const isEmptyString = value === emptyString; | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| if (!['EthValue', emptyString].includes(value) && !isInputFound) { | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| return console.error( | ||||||||||||||||||||||||||||
| `Input name "${value}" for method ${methodName} does not exists on the contract ABI`, | ||||||||||||||||||||||||||||
| `(DH-DOM) * Input name "${value}" for method ${methodName} does not exists on the contract ABI`, | ||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| // TODO: [DEV-312] This is part of the error for anonymous inputs | ||||||||||||||||||||||||||||
| if (isEmptyString && contractMethod.inputs.length > 1) { | ||||||||||||||||||||||||||||
| return console.error( | ||||||||||||||||||||||||||||
| `Input with empty string (anonymous input) cannot be set since exists more than one input on the contract ABI`, | ||||||||||||||||||||||||||||
| `(DH-DOM) Input with empty string (anonymous input) | ||||||||||||||||||||||||||||
| cannot be set since exists more than one input on the contract ABI, | ||||||||||||||||||||||||||||
| use Array input array Index. (See documentation: docs.dapphero.io) `, | ||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| return { | ||||||||||||||||||||||||||||
| element: input, | ||||||||||||||||||||||||||||
| id: property.id, | ||||||||||||||||||||||||||||
|
|
@@ -123,6 +178,7 @@ export const customContractParser = ( | |||||||||||||||||||||||||||
| )}`, | ||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| const parsedChilrenElements = childrenElements.map((childrenElement) => { | ||||||||||||||||||||||||||||
| if (property.attribute.endsWith('output-name')) { | ||||||||||||||||||||||||||||
| const value = childrenElement.getAttribute(property.attribute); | ||||||||||||||||||||||||||||
|
|
@@ -145,6 +201,7 @@ export const customContractParser = ( | |||||||||||||||||||||||||||
| contractElement.hasAttribute(property.attribute), | ||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| // TODO: [DEV-121] Figure out why validation fails when output-name is not included | ||||||||||||||||||||||||||||
| if (!childrenElement) { | ||||||||||||||||||||||||||||
| return; | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
constand use ofdestructuringfor avoiding variable mutations and code simplicityCode example: