Skip to content

Commit

Permalink
fix(embark-ui): detect fallback functions in the contracts explorer
Browse files Browse the repository at this point in the history
When a fallback function is encountered give its signature as `function()`,
disable row expansion, and omit the interaction form. Also label with a
`fallback` badge.
  • Loading branch information
michaelsbradleyjr authored and iurimatias committed Mar 18, 2019
1 parent 9d34355 commit 832f16a
Showing 1 changed file with 21 additions and 10 deletions.
31 changes: 21 additions & 10 deletions packages/embark-ui/src/components/ContractOverview.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ class ContractFunction extends Component {
return !this.isPureCall(method) && (method.type === 'event');
}

static isFallback(method) {
return method.type === 'fallback';
}

buttonTitle() {
const {method} = this.props;
if (method.name === 'constructor') {
Expand Down Expand Up @@ -140,24 +144,31 @@ class ContractFunction extends Component {
'border-bottom-0': !this.state.functionCollapse,
'rounded': !this.state.functionCollapse
})}
onClick={() => this.toggleFunction()}>
onClick={ContractFunction.isFallback(this.props.method)
? () => {}
: () => this.toggleFunction()}>
<CardTitle>
<span className="contract-function-signature">
{`${this.props.method.name}` +
{ContractFunction.isFallback(this.props.method)
? 'function()'
: `${this.props.method.name}` +
`(${this.props.method.inputs.map(i => i.name).join(', ')})`}
</span>
<div>
{(ContractFunction.isPureCall(this.props.method) &&
this.makeBadge('success', 'white', 'call')) ||
this.makeBadge('warning', 'black', 'send')}
{ContractFunction.isFallback(this.props.method)
? this.makeBadge('light', 'black', 'fallback')
: (ContractFunction.isPureCall(this.props.method) &&
this.makeBadge('success', 'white', 'call')) ||
this.makeBadge('warning', 'black', 'send')}
</div>
</CardTitle>
</CardHeader>
<Collapse isOpen={this.state.functionCollapse} className="relative">
{!ContractFunction.isFallback(this.props.method) &&
<Collapse isOpen={this.state.functionCollapse} className="relative">
<CardBody>
<Form inline>
{this.props.method.inputs.map(input => (
<FormGroup key={input.name}>
{this.props.method.inputs.map((input, idx) => (
<FormGroup key={idx}>
<Label for={input.name} className="mr-2 font-weight-bold contract-function-input">
{input.name}
</Label>
Expand Down Expand Up @@ -240,7 +251,7 @@ class ContractFunction extends Component {
))}
</ListGroup>
</CardFooter>}
</Collapse>
</Collapse>}
</Card>
);
}
Expand Down Expand Up @@ -275,7 +286,7 @@ const ContractOverview = (props) => {
.filter((method) => {
return props.onlyConstructor ? method.type === 'constructor' : method.type !== 'constructor';
})
.map(method => <ContractFunction key={method.name}
.map((method, idx) => <ContractFunction key={idx}
contractName={contract.className}
method={method}
contractFunctions={filterContractFunctions(props.contractFunctions, contract.className, method.name)}
Expand Down

0 comments on commit 832f16a

Please sign in to comment.