Skip to content

Commit 832f16a

Browse files
michaelsbradleyjriurimatias
authored andcommitted
fix(embark-ui): detect fallback functions in the contracts explorer
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.
1 parent 9d34355 commit 832f16a

File tree

1 file changed

+21
-10
lines changed

1 file changed

+21
-10
lines changed

packages/embark-ui/src/components/ContractOverview.js

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ class ContractFunction extends Component {
3939
return !this.isPureCall(method) && (method.type === 'event');
4040
}
4141

42+
static isFallback(method) {
43+
return method.type === 'fallback';
44+
}
45+
4246
buttonTitle() {
4347
const {method} = this.props;
4448
if (method.name === 'constructor') {
@@ -140,24 +144,31 @@ class ContractFunction extends Component {
140144
'border-bottom-0': !this.state.functionCollapse,
141145
'rounded': !this.state.functionCollapse
142146
})}
143-
onClick={() => this.toggleFunction()}>
147+
onClick={ContractFunction.isFallback(this.props.method)
148+
? () => {}
149+
: () => this.toggleFunction()}>
144150
<CardTitle>
145151
<span className="contract-function-signature">
146-
{`${this.props.method.name}` +
152+
{ContractFunction.isFallback(this.props.method)
153+
? 'function()'
154+
: `${this.props.method.name}` +
147155
`(${this.props.method.inputs.map(i => i.name).join(', ')})`}
148156
</span>
149157
<div>
150-
{(ContractFunction.isPureCall(this.props.method) &&
151-
this.makeBadge('success', 'white', 'call')) ||
152-
this.makeBadge('warning', 'black', 'send')}
158+
{ContractFunction.isFallback(this.props.method)
159+
? this.makeBadge('light', 'black', 'fallback')
160+
: (ContractFunction.isPureCall(this.props.method) &&
161+
this.makeBadge('success', 'white', 'call')) ||
162+
this.makeBadge('warning', 'black', 'send')}
153163
</div>
154164
</CardTitle>
155165
</CardHeader>
156-
<Collapse isOpen={this.state.functionCollapse} className="relative">
166+
{!ContractFunction.isFallback(this.props.method) &&
167+
<Collapse isOpen={this.state.functionCollapse} className="relative">
157168
<CardBody>
158169
<Form inline>
159-
{this.props.method.inputs.map(input => (
160-
<FormGroup key={input.name}>
170+
{this.props.method.inputs.map((input, idx) => (
171+
<FormGroup key={idx}>
161172
<Label for={input.name} className="mr-2 font-weight-bold contract-function-input">
162173
{input.name}
163174
</Label>
@@ -240,7 +251,7 @@ class ContractFunction extends Component {
240251
))}
241252
</ListGroup>
242253
</CardFooter>}
243-
</Collapse>
254+
</Collapse>}
244255
</Card>
245256
);
246257
}
@@ -275,7 +286,7 @@ const ContractOverview = (props) => {
275286
.filter((method) => {
276287
return props.onlyConstructor ? method.type === 'constructor' : method.type !== 'constructor';
277288
})
278-
.map(method => <ContractFunction key={method.name}
289+
.map((method, idx) => <ContractFunction key={idx}
279290
contractName={contract.className}
280291
method={method}
281292
contractFunctions={filterContractFunctions(props.contractFunctions, contract.className, method.name)}

0 commit comments

Comments
 (0)