ghost-portal/packages/app-contracts/src/Contracts/index.tsx
kwingram25 81c925f3d7 UI support for v2 ABI (#1602)
* ui support for v2 ABI

* drop v1 support

* update ABI display

* changes

* buttons

* update ABI display

* ABI v1 error message

* fix key warning

* Bump deps

* Bump deps

* Updates for merge

* default gas and endowment
2019-10-10 21:37:07 +02:00

122 lines
3.1 KiB
TypeScript

// Copyright 2017-2019 @polkadot/app-staking authors & contributors
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
import { I18nProps } from '@polkadot/react-components/types';
import { ComponentProps } from '../types';
import React from 'react';
import { RouteComponentProps } from 'react-router';
import { withRouter } from 'react-router-dom';
import { Button, CardGrid } from '@polkadot/react-components';
import { stringCamelCase } from '@polkadot/util';
import translate from '../translate';
import Add from './Add';
import Contract from './Contract';
import Call from './Call';
interface Props extends ComponentProps, I18nProps, RouteComponentProps {}
interface State {
isAddOpen: boolean;
isCallOpen: boolean;
callAddress: string | null;
callMethod: string | null;
}
class Contracts extends React.PureComponent<Props, State> {
public state: State = {
callAddress: null,
callMethod: null,
isAddOpen: false,
isCallOpen: false
};
public render (): React.ReactNode {
const { accounts, basePath, contracts, hasCode, showDeploy, t } = this.props;
const { callAddress, callMethod, isAddOpen, isCallOpen } = this.state;
return (
<>
<CardGrid
emptyText={t('No contracts available')}
buttons={
<Button.Group>
{hasCode && (
<>
<Button
icon='cloud upload'
isPrimary
label={t('Deploy a code hash')}
onClick={showDeploy()}
/>
<Button.Or />
</>
)}
<Button
icon='add'
isPrimary
label={t('Add an existing contract')}
onClick={this.showAdd}
/>
</Button.Group>
}
>
{accounts && contracts && Object.keys(contracts).map((address): React.ReactNode => {
return (
<Contract
basePath={basePath}
address={address}
key={address}
onCall={this.showCall}
/>
);
})}
</CardGrid>
<Add
basePath={basePath}
isOpen={isAddOpen}
onClose={this.hideAdd}
/>
<Call
address={callAddress}
isOpen={isCallOpen}
method={callMethod}
onClose={this.hideCall}
/>
</>
);
}
private showAdd = (): void => {
this.setState({
isAddOpen: true
});
}
private hideAdd = (): void => {
this.setState({
isAddOpen: false
});
}
private showCall = (callAddress?: string, callMethod?: string): void => {
this.setState({
isCallOpen: true,
callAddress: callAddress || null,
callMethod: callMethod ? stringCamelCase(callMethod) : null
});
}
private hideCall = (): void => {
this.setState({
isCallOpen: false,
callAddress: null,
callMethod: null
});
}
}
export default translate(withRouter(Contracts));