From f83ad4c2767b6526fe0abea4c8ed7d44b3093fb6 Mon Sep 17 00:00:00 2001 From: Rob Stupay Date: Thu, 26 Apr 2018 15:10:02 +0200 Subject: [PATCH 01/10] updating some of issues 1250 --- src/multiParamManager.js | 56 +++++++++++++++++++++++++++++++++------- 1 file changed, 47 insertions(+), 9 deletions(-) diff --git a/src/multiParamManager.js b/src/multiParamManager.js index 08cb124cb9..5e9e7cab4f 100644 --- a/src/multiParamManager.js +++ b/src/multiParamManager.js @@ -20,16 +20,51 @@ class MultiParamManager { this.clickCallBack = clickCallBack this.inputs = inputs this.title = title + this.basicInputField + this.multiFields } switchMethodViewOn () { this.contractActionsContainerSingle.style.display = 'none' this.contractActionsContainerMulti.style.display = 'flex' + // fill in the inputs + this.makeMultiVal() } switchMethodViewOff () { this.contractActionsContainerSingle.style.display = 'flex' this.contractActionsContainerMulti.style.display = 'none' + this.basicInputField.value = this.getMultiValsString() + } + getMultiValsString () { + var valArray = this.multiFields.querySelectorAll('input') + var ret = '' + for (var k = 0; k < valArray.length; k++) { + var el = valArray[k] + if (ret !== '') ret += ',' + ret += el.value + } + return ret + } + + emptyInputs () { + var valArray = this.multiFields.querySelectorAll('input') + for (var k = 0; k < valArray.length; k++) { + valArray[k].value = '' + } + this.basicInputField.value = '' + } + + makeMultiVal () { + var inputString = this.basicInputField.value + console.log(inputString) + var inputStringArray = inputString.split(',') + // !! the split here will mess up a value with a comma in it !! + // do we not make a split if its a , inside a []? + var multiInputs = this.multiFields.querySelectorAll('input') + for (var k = 0; k < multiInputs.length; k++) { + multiInputs[k].value = inputStringArray[k] + } } createMultiFields () { @@ -52,28 +87,31 @@ class MultiParamManager { title = '(fallback)' } - var basicInputField = yo`` - basicInputField.setAttribute('placeholder', this.inputs) - basicInputField.setAttribute('title', this.inputs) + this.basicInputField = yo`` + this.basicInputField.setAttribute('placeholder', this.inputs) + this.basicInputField.setAttribute('title', this.inputs) var onClick = (domEl) => { - this.clickCallBack(this.funABI.inputs, basicInputField.value) + this.clickCallBack(this.funABI.inputs, this.basicInputField.value) + this.emptyInputs() } this.contractActionsContainerSingle = yo`
- ${basicInputField} { this.switchMethodViewOn() }} title=${title} > + ${this.basicInputField} { this.switchMethodViewOn() }} title=${title} >
` - var multiFields = this.createMultiFields() + this.multiFields = this.createMultiFields() var multiOnClick = () => { - var valArray = multiFields.querySelectorAll('input') + var valArray = this.multiFields.querySelectorAll('input') var ret = '' for (var k = 0; k < valArray.length; k++) { var el = valArray[k] if (ret !== '') ret += ',' + el.value = el.value.replace(/(^|,\s+|,)([a-zA-Z]+)(\s+,|,|$)/g, '$1"$2"$3') // replace non quoted string - that starts with a letter ret += el.value } this.clickCallBack(this.funABI.inputs, ret) + this.emptyInputs() } var button = yo`` @@ -84,7 +122,7 @@ class MultiParamManager {
${title}
- ${multiFields} + ${this.multiFields}
${button}
@@ -106,7 +144,7 @@ class MultiParamManager { contractProperty.classList.add(css.hasArgs) } else { this.contractActionsContainerSingle.querySelector('i').style.visibility = 'hidden' - basicInputField.style.display = 'none' + this.basicInputField.style.display = 'none' } if (this.funABI.payable === true) { From d5201d7bc8754d42047e4c3c2d66aae22676ddce Mon Sep 17 00:00:00 2001 From: Rob Stupay Date: Mon, 30 Apr 2018 12:57:36 +0200 Subject: [PATCH 02/10] update to content --- src/multiParamManager.js | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/multiParamManager.js b/src/multiParamManager.js index 5e9e7cab4f..3620c9f3b7 100644 --- a/src/multiParamManager.js +++ b/src/multiParamManager.js @@ -2,6 +2,7 @@ var yo = require('yo-yo') var css = require('./universal-dapp-styles') +// var helper = require('../remix/remix-lib/src/execution/txHelper') class MultiParamManager { @@ -57,13 +58,13 @@ class MultiParamManager { makeMultiVal () { var inputString = this.basicInputField.value - console.log(inputString) - var inputStringArray = inputString.split(',') - // !! the split here will mess up a value with a comma in it !! - // do we not make a split if its a , inside a []? + var inputJSON = JSON.parse('[' + inputString + ']') + console.log('inputJSON is ' + inputJSON) var multiInputs = this.multiFields.querySelectorAll('input') + console.log('ml length ' + multiInputs.length) for (var k = 0; k < multiInputs.length; k++) { - multiInputs[k].value = inputStringArray[k] + multiInputs[k].value = inputJSON[k] + console.log('inputJSON number ' + k + ' is ' + inputJSON[k]) } } From f65661744f610967b85f9a828a85eee3be045ad3 Mon Sep 17 00:00:00 2001 From: Rob Stupay Date: Mon, 30 Apr 2018 16:42:20 +0200 Subject: [PATCH 03/10] not working yet --- src/multiParamManager.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/multiParamManager.js b/src/multiParamManager.js index 3620c9f3b7..171ed49fbf 100644 --- a/src/multiParamManager.js +++ b/src/multiParamManager.js @@ -108,9 +108,12 @@ class MultiParamManager { for (var k = 0; k < valArray.length; k++) { var el = valArray[k] if (ret !== '') ret += ',' - el.value = el.value.replace(/(^|,\s+|,)([a-zA-Z]+)(\s+,|,|$)/g, '$1"$2"$3') // replace non quoted string - that starts with a letter + // start with the beginning of a line or with a comma or with a space and a comma + // then match on a a-zA-Z or a [] or a {} but not a "" + // el.value = el.value.replace(/(^|,\s+|,)(^[a-zA-Z^a-zA-Z]+)(\s+,|,|$)/g, '$1"$2"$3') // replace non quoted string - that starts with a letter ret += el.value } + console.log('ret is ' + ret) this.clickCallBack(this.funABI.inputs, ret) this.emptyInputs() } From 1db74cb39a9e67f782f015e161606c95f2e287c3 Mon Sep 17 00:00:00 2001 From: Rob Stupay Date: Mon, 14 May 2018 11:35:42 +0200 Subject: [PATCH 04/10] multiParmaMan update --- src/multiParamManager.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/multiParamManager.js b/src/multiParamManager.js index 171ed49fbf..4f6d544274 100644 --- a/src/multiParamManager.js +++ b/src/multiParamManager.js @@ -63,8 +63,10 @@ class MultiParamManager { var multiInputs = this.multiFields.querySelectorAll('input') console.log('ml length ' + multiInputs.length) for (var k = 0; k < multiInputs.length; k++) { - multiInputs[k].value = inputJSON[k] - console.log('inputJSON number ' + k + ' is ' + inputJSON[k]) + if (inputJSON[k]) { + multiInputs[k].value = inputJSON[k] + console.log('inputJSON number ' + k + ' is ' + inputJSON[k]) + } } } From d9246688dba65bbc846e574705ba270f51838b8c Mon Sep 17 00:00:00 2001 From: Rob Stupay Date: Mon, 14 May 2018 17:23:26 +0200 Subject: [PATCH 05/10] quotes and arrays for expand and submit --- src/multiParamManager.js | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/src/multiParamManager.js b/src/multiParamManager.js index 4f6d544274..6461517b59 100644 --- a/src/multiParamManager.js +++ b/src/multiParamManager.js @@ -59,13 +59,10 @@ class MultiParamManager { makeMultiVal () { var inputString = this.basicInputField.value var inputJSON = JSON.parse('[' + inputString + ']') - console.log('inputJSON is ' + inputJSON) var multiInputs = this.multiFields.querySelectorAll('input') - console.log('ml length ' + multiInputs.length) for (var k = 0; k < multiInputs.length; k++) { if (inputJSON[k]) { - multiInputs[k].value = inputJSON[k] - console.log('inputJSON number ' + k + ' is ' + inputJSON[k]) + multiInputs[k].value = JSON.stringify(inputJSON[k]) } } } @@ -108,14 +105,11 @@ class MultiParamManager { var valArray = this.multiFields.querySelectorAll('input') var ret = '' for (var k = 0; k < valArray.length; k++) { - var el = valArray[k] + let el = valArray[k].value if (ret !== '') ret += ',' - // start with the beginning of a line or with a comma or with a space and a comma - // then match on a a-zA-Z or a [] or a {} but not a "" - // el.value = el.value.replace(/(^|,\s+|,)(^[a-zA-Z^a-zA-Z]+)(\s+,|,|$)/g, '$1"$2"$3') // replace non quoted string - that starts with a letter - ret += el.value + el = el.replace(/(^|,\s+|,)(\w+|)(\s+,|,|$)/g, '$1"$2"$3') // replace non quoted string or number by quoted string + ret += el } - console.log('ret is ' + ret) this.clickCallBack(this.funABI.inputs, ret) this.emptyInputs() } From 6e11efe3483e5a67bfcf5f2ab7ab67140ce5c456 Mon Sep 17 00:00:00 2001 From: Rob Stupay Date: Wed, 16 May 2018 14:06:39 +0200 Subject: [PATCH 06/10] fix of regex --- src/multiParamManager.js | 46 ++++++++++++++++++++++++---------------- 1 file changed, 28 insertions(+), 18 deletions(-) diff --git a/src/multiParamManager.js b/src/multiParamManager.js index 6461517b59..43f0251b0d 100644 --- a/src/multiParamManager.js +++ b/src/multiParamManager.js @@ -28,22 +28,31 @@ class MultiParamManager { switchMethodViewOn () { this.contractActionsContainerSingle.style.display = 'none' this.contractActionsContainerMulti.style.display = 'flex' - // fill in the inputs this.makeMultiVal() } switchMethodViewOff () { this.contractActionsContainerSingle.style.display = 'flex' this.contractActionsContainerMulti.style.display = 'none' - this.basicInputField.value = this.getMultiValsString() + if (this.getMultiValsString()) this.basicInputField.value = this.getMultiValsString() } + getMultiValsString () { var valArray = this.multiFields.querySelectorAll('input') + var notEmpty = 0 var ret = '' + for (var k = 0; k < valArray.length; k++) { - var el = valArray[k] - if (ret !== '') ret += ',' - ret += el.value + var elA = valArray[k].value + if (elA) notEmpty++ + } + if (notEmpty) { + for (var j = 0; j < valArray.length; j++) { + if (ret !== '') ret += ',' + var elVal = valArray[j].value + elVal = elVal.replace(/(^|,\s+|,)(\w+|)(\s+,|,|$)/g, '$1"$2"$3') // replace non quoted string or number by quoted string + ret += elVal + } } return ret } @@ -58,11 +67,14 @@ class MultiParamManager { makeMultiVal () { var inputString = this.basicInputField.value - var inputJSON = JSON.parse('[' + inputString + ']') - var multiInputs = this.multiFields.querySelectorAll('input') - for (var k = 0; k < multiInputs.length; k++) { - if (inputJSON[k]) { - multiInputs[k].value = JSON.stringify(inputJSON[k]) + if (inputString) { + inputString = inputString.replace(/(^|,\s+|,)(\w+|)(\s+,|,|$)/g, '$1"$2"$3') + var inputJSON = JSON.parse('[' + inputString + ']') + var multiInputs = this.multiFields.querySelectorAll('input') + for (var k = 0; k < multiInputs.length; k++) { + if (inputJSON[k]) { + multiInputs[k].value = JSON.stringify(inputJSON[k]) + } } } } @@ -101,16 +113,14 @@ class MultiParamManager { ` this.multiFields = this.createMultiFields() + var multiOnClick = () => { - var valArray = this.multiFields.querySelectorAll('input') - var ret = '' - for (var k = 0; k < valArray.length; k++) { - let el = valArray[k].value - if (ret !== '') ret += ',' - el = el.replace(/(^|,\s+|,)(\w+|)(\s+,|,|$)/g, '$1"$2"$3') // replace non quoted string or number by quoted string - ret += el + var valsString = this.getMultiValsString() + if (valsString) { + this.clickCallBack(this.funABI.inputs, valsString) + } else { + this.clickCallBack(this.funABI.inputs, '') } - this.clickCallBack(this.funABI.inputs, ret) this.emptyInputs() } From 89137ba1b1e004a5f7f578855f449551ad16d365 Mon Sep 17 00:00:00 2001 From: Rob Stupay Date: Wed, 16 May 2018 15:52:26 +0200 Subject: [PATCH 07/10] update regex and style --- src/multiParamManager.js | 6 ++++-- src/universal-dapp-styles.js | 4 ++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/multiParamManager.js b/src/multiParamManager.js index 43f0251b0d..3b29c00cfa 100644 --- a/src/multiParamManager.js +++ b/src/multiParamManager.js @@ -50,7 +50,8 @@ class MultiParamManager { for (var j = 0; j < valArray.length; j++) { if (ret !== '') ret += ',' var elVal = valArray[j].value - elVal = elVal.replace(/(^|,\s+|,)(\w+|)(\s+,|,|$)/g, '$1"$2"$3') // replace non quoted string or number by quoted string + elVal = elVal.replace(/(^|,\s+|,)(\d+)(\s+,|,|$)/g, '$1"$2"$3') // replace non quoted number by quoted number + elVal = elVal.replace(/(^|,\s+|,)(0[xX][0-9a-fA-F]+)(\s+,|,|$)/g, '$1"$2"$3') // replace non quoted hex string by quoted hex string ret += elVal } } @@ -68,7 +69,8 @@ class MultiParamManager { makeMultiVal () { var inputString = this.basicInputField.value if (inputString) { - inputString = inputString.replace(/(^|,\s+|,)(\w+|)(\s+,|,|$)/g, '$1"$2"$3') + inputString = inputString.replace(/(^|,\s+|,)(\d+)(\s+,|,|$)/g, '$1"$2"$3') // replace non quoted number by quoted number + inputString = inputString.replace(/(^|,\s+|,)(0[xX][0-9a-fA-F]+)(\s+,|,|$)/g, '$1"$2"$3') // replace non quoted hex string by quoted hex string var inputJSON = JSON.parse('[' + inputString + ']') var multiInputs = this.multiFields.querySelectorAll('input') for (var k = 0; k < multiInputs.length; k++) { diff --git a/src/universal-dapp-styles.js b/src/universal-dapp-styles.js index 4d15387aa2..924f579d1c 100644 --- a/src/universal-dapp-styles.js +++ b/src/universal-dapp-styles.js @@ -154,7 +154,7 @@ var css = csjs` } .contractActionsContainerMultiInner { margin-bottom: 10px; - border-bottom: 1px solid ${styles.appProperties.solidBorderBox_BorderColor}; + border: 1px solid ${styles.appProperties.solidBorderBox_BorderColor}; padding: 0px 5px 5px 0px; background-color: ${styles.appProperties.primary_BackgroundColor}; width: 100%; @@ -171,7 +171,7 @@ var css = csjs` .contractProperty .multiTitle { display: inline-block; width: 90%; - font-size: 10px; + font-size: 12px; height: 25px; padding-left: 20px; font-weight: bold; From 2d549dcb15f08c97917e527dafd3557940b5a08a Mon Sep 17 00:00:00 2001 From: Rob Stupay Date: Wed, 16 May 2018 17:28:52 +0200 Subject: [PATCH 08/10] cleanup code --- src/multiParamManager.js | 36 +++++++++++++++++++++--------------- 1 file changed, 21 insertions(+), 15 deletions(-) diff --git a/src/multiParamManager.js b/src/multiParamManager.js index 3b29c00cfa..95ca630de1 100644 --- a/src/multiParamManager.js +++ b/src/multiParamManager.js @@ -34,28 +34,34 @@ class MultiParamManager { switchMethodViewOff () { this.contractActionsContainerSingle.style.display = 'flex' this.contractActionsContainerMulti.style.display = 'none' - if (this.getMultiValsString()) this.basicInputField.value = this.getMultiValsString() + var multiValString = this.getMultiValsString() + if (multiValString) this.basicInputField.value = multiValString + } + + getValue (item, index) { + var valStr = item.value.join('') + return valStr } getMultiValsString () { var valArray = this.multiFields.querySelectorAll('input') - var notEmpty = 0 var ret = '' - - for (var k = 0; k < valArray.length; k++) { - var elA = valArray[k].value - if (elA) notEmpty++ + var valArrayTest = [] + + for (var j = 0; j < valArray.length; j++) { + if (ret !== '') ret += ',' + var elVal = valArray[j].value + valArrayTest.push(elVal) + elVal = elVal.replace(/(^|,\s+|,)(\d+)(\s+,|,|$)/g, '$1"$2"$3') // replace non quoted number by quoted number + elVal = elVal.replace(/(^|,\s+|,)(0[xX][0-9a-fA-F]+)(\s+,|,|$)/g, '$1"$2"$3') // replace non quoted hex string by quoted hex string + ret += elVal } - if (notEmpty) { - for (var j = 0; j < valArray.length; j++) { - if (ret !== '') ret += ',' - var elVal = valArray[j].value - elVal = elVal.replace(/(^|,\s+|,)(\d+)(\s+,|,|$)/g, '$1"$2"$3') // replace non quoted number by quoted number - elVal = elVal.replace(/(^|,\s+|,)(0[xX][0-9a-fA-F]+)(\s+,|,|$)/g, '$1"$2"$3') // replace non quoted hex string by quoted hex string - ret += elVal - } + var valStringTest = valArrayTest.join('') + if (valStringTest) { + return ret + } else { + return '' } - return ret } emptyInputs () { From 9911f122d2649bbd26466a51be94faa78a5e647c Mon Sep 17 00:00:00 2001 From: Rob Stupay Date: Thu, 17 May 2018 14:44:31 +0200 Subject: [PATCH 09/10] try catch for JSON validation --- src/multiParamManager.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/multiParamManager.js b/src/multiParamManager.js index 95ca630de1..a803d506ec 100644 --- a/src/multiParamManager.js +++ b/src/multiParamManager.js @@ -54,6 +54,11 @@ class MultiParamManager { valArrayTest.push(elVal) elVal = elVal.replace(/(^|,\s+|,)(\d+)(\s+,|,|$)/g, '$1"$2"$3') // replace non quoted number by quoted number elVal = elVal.replace(/(^|,\s+|,)(0[xX][0-9a-fA-F]+)(\s+,|,|$)/g, '$1"$2"$3') // replace non quoted hex string by quoted hex string + try { + JSON.parse(elVal) + } catch (e) { + elVal = '"' + elVal + '"' + } ret += elVal } var valStringTest = valArrayTest.join('') From d6cdd48f6057dca24bf6c59ec0d8d91e0e7bfc29 Mon Sep 17 00:00:00 2001 From: yann300 Date: Thu, 17 May 2018 15:26:46 +0200 Subject: [PATCH 10/10] Update multiParamManager.js --- src/multiParamManager.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/multiParamManager.js b/src/multiParamManager.js index a803d506ec..75ffc1f9fa 100644 --- a/src/multiParamManager.js +++ b/src/multiParamManager.js @@ -2,7 +2,6 @@ var yo = require('yo-yo') var css = require('./universal-dapp-styles') -// var helper = require('../remix/remix-lib/src/execution/txHelper') class MultiParamManager {