From 88c610208c7d45a7fdd4a3b4782eccd297a5f546 Mon Sep 17 00:00:00 2001 From: Jonathan Rainville Date: Wed, 17 Oct 2018 17:13:36 -0400 Subject: [PATCH] start to fix for arrays --- lib/modules/scaffolding-react/index.js | 2 +- lib/modules/scaffolding-react/templates/dapp.js.hbs | 4 ++-- .../scaffolding-solidity/templates/contract.sol.hbs | 7 ++++++- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/lib/modules/scaffolding-react/index.js b/lib/modules/scaffolding-react/index.js index 1c0efe12..663ed3fa 100644 --- a/lib/modules/scaffolding-react/index.js +++ b/lib/modules/scaffolding-react/index.js @@ -68,7 +68,7 @@ class ScaffoldingReact { throw new Error("file '" + filePath + "' already exists"); } - const templatePath = fs.embarkPath('lib/modules/scaffolding-react/templates/' + templateFilename); + const templatePath = utils.joinPath(__dirname, 'templates/' + templateFilename); const source = fs.readFileSync(templatePath).toString(); const template = Handlebars.compile(source); diff --git a/lib/modules/scaffolding-react/templates/dapp.js.hbs b/lib/modules/scaffolding-react/templates/dapp.js.hbs index 4cc141e2..7a857ba1 100644 --- a/lib/modules/scaffolding-react/templates/dapp.js.hbs +++ b/lib/modules/scaffolding-react/templates/dapp.js.hbs @@ -63,7 +63,7 @@ class {{capitalize name}}Form{{@index}} extends Component { {{else}} {{#each inputs}} {{#ifarr type}} - input.{{trim name}} = input.{{trim name}}.split(',').map(x => trim(x.toString())); + input.{{trim name}} = input.{{trim name}}.split(',').map(x => x.toString().trim()); {{/ifarr}} {{/each}} @@ -154,7 +154,7 @@ class {{capitalize name}}Form{{@index}} extends Component { { receipt && - {receipt.status == "0x1" ? 'Success' : 'Failure / Revert'} - Transaction Hash: {receipt.transactionHash} + {receipt.status === "0x1" ? 'Success' : 'Failure / Revert'} - Transaction Hash: {receipt.transactionHash} } diff --git a/lib/modules/scaffolding-solidity/templates/contract.sol.hbs b/lib/modules/scaffolding-solidity/templates/contract.sol.hbs index 365a6eac..7e6f50b3 100644 --- a/lib/modules/scaffolding-solidity/templates/contract.sol.hbs +++ b/lib/modules/scaffolding-solidity/templates/contract.sol.hbs @@ -8,7 +8,7 @@ contract {{contractName}} { {{/each}} } - {{structName}}[] public items; + {{structName}}[] items; event ItemCreated(uint id, address createdBy); event ItemDeleted(uint id, address deletedBy); @@ -42,4 +42,9 @@ contract {{contractName}} { emit ItemDeleted(_id, msg.sender); } + function get(uint _id) public view returns ({{#each fields}}{{type}}{{#unless @last}},{{/unless}}{{/each}}) { + require(_id < items.length, "Invalid ArrayContractStruct id"); + return ({{#each fields}}items[_id].{{name}}{{#unless @last}},{{/unless}}{{/each}}); + } + }