From 3a723c14575ec773ac3b77914be76fad2e7c9b87 Mon Sep 17 00:00:00 2001 From: Dennison Bertram Date: Thu, 28 May 2020 23:01:06 -0400 Subject: [PATCH 1/8] =?UTF-8?q?=F0=9F=90=9B=20FIX:=20Allow=20Array=20indix?= =?UTF-8?q?es=20to=20work=20for=20inputs?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/features/customContract/parser.ts | 44 ++++++++++++++++++++++++--- 1 file changed, 40 insertions(+), 4 deletions(-) diff --git a/src/features/customContract/parser.ts b/src/features/customContract/parser.ts index ae5b4ea..03c93f1 100644 --- a/src/features/customContract/parser.ts +++ b/src/features/customContract/parser.ts @@ -75,26 +75,62 @@ 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))) { + console.log("Is an integer!", value) + return parseInt(value.substring(1, value.length - 1), 10) + } else { + console.log("Not an integer!", value) + return false + } + } + + 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) `, ); } + console.log({ + element: input, + id: property.id, + shouldAutoClear, + argumentName: value, + }) return { element: input, id: property.id, From 1d8b9f835071776254abbd5223bdac6fbc9a63e5 Mon Sep 17 00:00:00 2001 From: Dennison Bertram Date: Thu, 28 May 2020 23:04:28 -0400 Subject: [PATCH 2/8] =?UTF-8?q?=F0=9F=91=8C=20IMPROVE:=20=20remove=20conso?= =?UTF-8?q?le=20logs?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/features/customContract/parser.ts | 8 -------- 1 file changed, 8 deletions(-) diff --git a/src/features/customContract/parser.ts b/src/features/customContract/parser.ts index 03c93f1..f9e6669 100644 --- a/src/features/customContract/parser.ts +++ b/src/features/customContract/parser.ts @@ -79,10 +79,8 @@ export const customContractParser = ( // 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))) { - console.log("Is an integer!", value) return parseInt(value.substring(1, value.length - 1), 10) } else { - console.log("Not an integer!", value) return false } } @@ -125,12 +123,6 @@ export const customContractParser = ( ); } - console.log({ - element: input, - id: property.id, - shouldAutoClear, - argumentName: value, - }) return { element: input, id: property.id, From 3d2957e7f2e826a52d1235f0105e2c6193e0bf1c Mon Sep 17 00:00:00 2001 From: Dennison Bertram Date: Fri, 29 May 2020 14:39:45 -0400 Subject: [PATCH 3/8] =?UTF-8?q?=F0=9F=90=9B=20FIX:=20=20Seems=20to=20be=20?= =?UTF-8?q?working.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/features/customContract/parser.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/features/customContract/parser.ts b/src/features/customContract/parser.ts index f9e6669..2df660d 100644 --- a/src/features/customContract/parser.ts +++ b/src/features/customContract/parser.ts @@ -123,6 +123,7 @@ export const customContractParser = ( ); } + return { element: input, id: property.id, From 97dfa64a061c5d9d06bfd18c1ec57cd48580871d Mon Sep 17 00:00:00 2001 From: Dennison Bertram Date: Fri, 29 May 2020 14:52:41 -0400 Subject: [PATCH 4/8] =?UTF-8?q?=F0=9F=91=8C=20IMPROVE:=20=20add=20all=2018?= =?UTF-8?q?=20units=20for=20conversions?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/features/customContract/index.ts | 6 +++--- src/lib/constants.ts | 20 ++++++++++++++++++++ 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/src/features/customContract/index.ts b/src/features/customContract/index.ts index 9f54ecb..667f5ce 100644 --- a/src/features/customContract/index.ts +++ b/src/features/customContract/index.ts @@ -1,5 +1,5 @@ // Constants -import { DATA_FEATURE, DATA_PROPERTY, DATA_MODIFIER } from '../../lib/constants'; +import { DATA_FEATURE, DATA_PROPERTY, DATA_MODIFIER, ETHER_UNITS } from '../../lib/constants'; export const customContract = { id: 'customContract', @@ -85,13 +85,13 @@ export const customContract = { id: 'displayUnits', defaultValue: 'ether', attribute: `${DATA_MODIFIER}-display-units`, - validator: (value) => ['wei', 'ether'].includes(value), + validator: (value) => ETHER_UNITS.includes(value), }, { id: 'contractUnits', defaultValue: 'wei', attribute: `${DATA_MODIFIER}-contract-units`, - validator: (value) => ['wei', 'ether'].includes(value), + validator: (value) => ETHER_UNITS.includes(value), }, { id: 'displayDecimals', diff --git a/src/lib/constants.ts b/src/lib/constants.ts index 86cea87..bdecccb 100644 --- a/src/lib/constants.ts +++ b/src/lib/constants.ts @@ -15,6 +15,26 @@ export const ELEMENT_TYPES = { video: 'video', }; +export const ETHER_UNITS = ['wei', 'ether', +'1', +'10', +'100', +'1000', +'10000', +'100000', +'1000000', +'10000000', +'100000000', +'1000000000', +'10000000000', +'100000000000', +'1000000000000', +'10000000000000', +'100000000000000', +'1000000000000000', +'100000000000000000', +'1000000000000000000'] + export const TAG_TYPES = { H1: ELEMENT_TYPES.text, H2: ELEMENT_TYPES.text, From dcef4a58a7f5c4a3c699579cf6d37630f16b5ae7 Mon Sep 17 00:00:00 2001 From: Dennison Bertram Date: Mon, 1 Jun 2020 17:08:24 -0400 Subject: [PATCH 5/8] =?UTF-8?q?=F0=9F=90=9B=20FIX:=20Add=20support=20for?= =?UTF-8?q?=20overloaded=20methods=20by=20argument=20count?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/features/customContract/parser.ts | 31 ++++++++++++++++++++++----- 1 file changed, 26 insertions(+), 5 deletions(-) diff --git a/src/features/customContract/parser.ts b/src/features/customContract/parser.ts index 2df660d..73cb658 100644 --- a/src/features/customContract/parser.ts +++ b/src/features/customContract/parser.ts @@ -47,12 +47,33 @@ 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 (!contractMethod) { + // 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 + + //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'; const hasOutputs = contractMethod.outputs.length > 0; @@ -91,10 +112,10 @@ export const customContractParser = ( // Check each input name in ABI equals to the value defined in the DOM const isInputFound = contractMethod.inputs.some((input) => { - if(input.name === value) return true + 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) { + if (inputArrayValue !== false && inputArrayValue <= contractMethod.inputs.length - 1) { return true } // There is no match for input name, or for array possition, so return false. @@ -104,7 +125,7 @@ export const customContractParser = ( // 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; From 65cb80885d4d61515ee1b85e7128591073e1f735 Mon Sep 17 00:00:00 2001 From: Dennison Bertram Date: Mon, 1 Jun 2020 18:25:01 -0400 Subject: [PATCH 6/8] =?UTF-8?q?=F0=9F=90=9B=20FIX:=20=20Bug=20hunting?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/features/customContract/parser.ts | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/src/features/customContract/parser.ts b/src/features/customContract/parser.ts index 73cb658..91d5cbe 100644 --- a/src/features/customContract/parser.ts +++ b/src/features/customContract/parser.ts @@ -55,11 +55,10 @@ export const customContractParser = ( } // placeholder for the contract method we will be working with. - let contractMethod + 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)), @@ -69,12 +68,18 @@ export const customContractParser = ( 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`); - } } + + 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) + // console.log("isTransaction", isTransaction) + + // const isTransaction = contractMethod.stateMutability !== 'view'; const hasOutputs = contractMethod.outputs.length > 0; // Get customContract children properties @@ -130,8 +135,9 @@ export const customContractParser = ( const isEmptyString = value === emptyString; if (!['EthValue', emptyString].includes(value) && !isInputFound) { + return console.error( - `(DH-DOM) 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`, ); } @@ -173,6 +179,7 @@ export const customContractParser = ( )}`, ); } + const parsedChilrenElements = childrenElements.map((childrenElement) => { if (property.attribute.endsWith('output-name')) { const value = childrenElement.getAttribute(property.attribute); @@ -195,6 +202,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; From 44300d1d89756d825c35c41ac5d481291e7ef367 Mon Sep 17 00:00:00 2001 From: Dennison Bertram Date: Wed, 3 Jun 2020 15:46:56 -0400 Subject: [PATCH 7/8] =?UTF-8?q?=F0=9F=91=8C=20IMPROVE:=20Remove=20console?= =?UTF-8?q?=20logs?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/features/customContract/parser.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/features/customContract/parser.ts b/src/features/customContract/parser.ts index 91d5cbe..2487b4a 100644 --- a/src/features/customContract/parser.ts +++ b/src/features/customContract/parser.ts @@ -77,7 +77,6 @@ export const customContractParser = ( // Transactions are transactions if they are not view, pure or constant const isTransaction = !Boolean(['view', 'pure', 'constant'].filter(el => contractMethod.stateMutability === el).length) - // console.log("isTransaction", isTransaction) // const isTransaction = contractMethod.stateMutability !== 'view'; const hasOutputs = contractMethod.outputs.length > 0; From 808be035979bf7291eb6e0fd7c9c8ec6e6604997 Mon Sep 17 00:00:00 2001 From: Dennison Bertram Date: Sun, 7 Jun 2020 13:52:56 -0400 Subject: [PATCH 8/8] =?UTF-8?q?=F0=9F=90=9B=20FIX:=20=20bump=20DH-Dom?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 6516e5a..9f811aa 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@dapphero/dapphero-dom", - "version": "0.4.1", + "version": "0.4.2", "license": "MIT", "source": "src/index.ts", "main": "dist/dapphero-dom.js",