From b674013c21672377b3e03e6449b601690140efb6 Mon Sep 17 00:00:00 2001 From: Aaron Cox Date: Fri, 17 Apr 2020 14:53:54 -0400 Subject: [PATCH] Default fields to solve empty array issues --- src/containers/index.js | 34 +++++++++++++++++++++------------- 1 file changed, 21 insertions(+), 13 deletions(-) diff --git a/src/containers/index.js b/src/containers/index.js index e14dd1a..831371a 100644 --- a/src/containers/index.js +++ b/src/containers/index.js @@ -161,20 +161,28 @@ class IndexContainer extends Component { this.state.action && this.state.action !== nextState.action ) { - const { abi, action } = nextState; - const { structs } = abi; - const struct = find(structs, { name: action }); - if (struct) { - const { fields } = struct; - const defaultFields = {}; - fields.forEach((field) => { + this.updateFields(nextState) + } + } + + updateFields = (state) => { + const { abi, action } = state; + const { structs } = abi; + const struct = find(structs, { name: action }); + if (struct) { + const { fields } = struct; + const defaultFields = {}; + fields.forEach((field) => { + if (field.type && field.type.substr(field.type.length - 2) === "[]") { + defaultFields[field.name] = []; + } else { defaultFields[field.name] = ''; - }); - this.setState({ - uri: undefined, - fields: defaultFields - }); - } + } + }); + this.setState({ + uri: undefined, + fields: defaultFields + }); } }