Move contracts-only components to contracts (and fix from page imports) (#2392)

This commit is contained in:
Jaco Greeff 2020-03-16 09:41:42 +01:00 committed by GitHub
parent 21c26f1767
commit 22d387e824
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 54 additions and 61 deletions

View File

@ -8,9 +8,10 @@ import React from 'react';
import styled from 'styled-components';
import { Abi } from '@polkadot/api-contract';
import { registry } from '@polkadot/react-api';
import { InputFile, Labelled, Messages } from '@polkadot/react-components';
import { InputFile, Labelled } from '@polkadot/react-components';
import { u8aToString } from '@polkadot/util';
import Messages from './Messages';
import translate from './translate';
interface Props extends I18nProps {

View File

@ -12,13 +12,11 @@ import { createType } from '@polkadot/types';
import { registry } from '@polkadot/react-api';
import { withMulti } from '@polkadot/react-api/hoc';
import { classes, toShortAddress } from '@polkadot/react-components/util';
import contracts from '@polkadot/app-contracts/store';
import Row, { RowProps, RowState, styles } from '@polkadot/react-components/Row';
import { CopyButton, Icon } from '@polkadot/react-components';
import CopyButton from './CopyButton';
import Icon from './Icon';
import contracts from './store';
import Messages from './Messages';
import Row, { RowProps, RowState, styles } from './Row';
import translate from './translate';
interface Props extends I18nProps, RowProps {

View File

@ -9,11 +9,11 @@ import React from 'react';
import styled from 'styled-components';
import { RouteComponentProps } from 'react-router';
import { withRouter } from 'react-router-dom';
import { Button, Card, CodeRow, Forget } from '@polkadot/react-components';
import { Button, Card, Forget } from '@polkadot/react-components';
import ABI from '../ABI';
import CodeRow from '../CodeRow';
import RemoveABI from '../RemoveABI';
import contracts from '../store';
import translate from '../translate';
@ -106,7 +106,7 @@ class Code extends React.PureComponent<Props, State> {
}
private renderModals (): React.ReactNode {
const { code } = this.props;
const { code, t } = this.props;
const { isForgetOpen, isRemoveABIOpen } = this.state;
if (!code) {
@ -118,12 +118,19 @@ class Code extends React.PureComponent<Props, State> {
if (isForgetOpen) {
modals.push(
<Forget
code={code}
key='modal-forget-account'
mode='code'
onClose={this.toggleForget}
onForget={this.onForget}
/>
>
<CodeRow
isInline
code={code || ''}
>
<p>{t('You are about to remove this code from your list of available code hashes. Once completed, should you need to access it again, you will have to manually add the code hash again.')}</p>
<p>{t('This operation does not remove the uploaded code WASM and ABI from the chain, nor any deployed contracts. The forget operation only limits your access to the code on this browser.')}</p>
</CodeRow>
</Forget>
);
}

View File

@ -10,8 +10,9 @@ import { RouteComponentProps } from 'react-router';
import { withRouter } from 'react-router-dom';
import keyring from '@polkadot/ui-keyring';
import { PromiseContract as ApiContract } from '@polkadot/api-contract';
import { AddressRow, Button, Card, Forget, Messages } from '@polkadot/react-components';
import { AddressRow, Button, Card, Forget } from '@polkadot/react-components';
import Messages from '../Messages';
import { useTranslation } from '../translate';
interface Props extends RouteComponentProps {
@ -61,17 +62,15 @@ function Contract (props: Props): React.ReactElement<Props> | null {
return (
<ContractCard>
{
isForgetOpen && (
<Forget
address={address.toString()}
mode='contract'
onForget={_onForget}
key='modal-forget-contract'
onClose={_toggleForget}
/>
)
}
{isForgetOpen && (
<Forget
address={address.toString()}
mode='contract'
onForget={_onForget}
key='modal-forget-contract'
onClose={_toggleForget}
/>
)}
<AddressRow
buttons={
<div className='contracts--Contract-buttons'>

View File

@ -6,7 +6,9 @@ import { ContractCallOutcome } from '@polkadot/api-contract/types';
import React from 'react';
import styled from 'styled-components';
import { AddressMini, Button, MessageSignature, Output } from '@polkadot/react-components';
import { AddressMini, Button, Output } from '@polkadot/react-components';
import MessageSignature from '../MessageSignature';
interface Props {
className?: string;

View File

@ -8,9 +8,10 @@ import { StringOrNull } from '@polkadot/react-components/types';
import React from 'react';
import { ApiPromise } from '@polkadot/api';
import { PromiseContract as Contract } from '@polkadot/api-contract';
import { MessageSignature } from '@polkadot/react-components';
import { getContractAbi } from '@polkadot/react-components/util';
import MessageSignature from '../MessageSignature';
export function findCallMethod (callContract: Contract | null, callMethodIndex = 0): ContractABIMessage | null {
const message = callContract && callContract.abi.abi.contract.messages[callMethodIndex];

View File

@ -14,9 +14,10 @@ import { SubmittableResult } from '@polkadot/api';
import { Abi } from '@polkadot/api-contract';
import { withApi, withMulti } from '@polkadot/react-api/hoc';
import keyring from '@polkadot/ui-keyring';
import { Dropdown, InputBalance, MessageSignature, TxButton } from '@polkadot/react-components';
import { Dropdown, InputBalance, TxButton } from '@polkadot/react-components';
import createValues from '@polkadot/react-params/values';
import MessageSignature from './MessageSignature';
import ContractModal, { ContractModalProps, ContractModalState } from './Modal';
import Params from './Params';
import store from './store';

View File

@ -6,10 +6,9 @@ import { ContractABIMessage } from '@polkadot/api-contract/types';
import React from 'react';
import styled from 'styled-components';
import { Icon, Tooltip } from '@polkadot/react-components';
import { displayType } from '@polkadot/types';
import Icon from './Icon';
import Tooltip from './Tooltip';
import { useTranslation } from './translate';
const MAX_PARAM_LENGTH = 20;

View File

@ -3,16 +3,15 @@
// of the Apache-2.0 license. See the LICENSE file for details.
import { ContractABIMessage } from '@polkadot/api-contract/types';
import { Button } from '@polkadot/react-components';
import React from 'react';
import styled from 'styled-components';
import { Abi } from '@polkadot/api-contract';
import { classes } from '@polkadot/react-components/util';
import { Button, IconLink } from '@polkadot/react-components';
import IconLink from './IconLink';
import MessageSignature from './MessageSignature';
import { useTranslation } from './translate';
import { classes } from './util';
export interface Props {
address?: string;

View File

@ -5,8 +5,9 @@
import { CodeStored } from '@polkadot/app-contracts/types';
import React from 'react';
import { Button, CodeRow, Modal } from '@polkadot/react-components';
import { Button, Modal } from '@polkadot/react-components';
import CodeRow from './CodeRow';
import { useTranslation } from './translate';
interface Props {

View File

@ -2,10 +2,8 @@
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
import { CodeStored } from '@polkadot/app-contracts/types';
import React from 'react';
import { AddressRow, Button, CodeRow, Modal } from '@polkadot/react-components';
import { AddressRow, Button, Modal } from '@polkadot/react-components';
import { useTranslation } from './translate';
@ -13,14 +11,14 @@ type Mode = 'account' | 'address' | 'contract' | 'code';
interface Props {
address?: string;
code?: CodeStored;
children?: React.ReactNode;
name?: string;
mode?: Mode;
onClose: () => void;
onForget: () => void;
}
function getContent (mode: Mode, t: (key: string) => string): React.ReactNode {
function getContent (mode: Mode, t: (key: string) => string): React.ReactNode | null {
switch (mode) {
case 'account':
return (
@ -43,13 +41,8 @@ function getContent (mode: Mode, t: (key: string) => string): React.ReactNode {
<p>{t('This operation does not remove the history of the contract from the chain, nor any associated funds from its account. The forget operation only limits your access to the contract on this browser.')}</p>
</>
);
case 'code':
return (
<>
<p>{t('You are about to remove this code from your list of available code hashes. Once completed, should you need to access it again, you will have to manually add the code hash again.')}</p>
<p>{t('This operation does not remove the uploaded code WASM and ABI from the chain, nor any deployed contracts. The forget operation only limits your access to the code on this browser.')}</p>
</>
);
default:
return null;
}
}
@ -66,8 +59,8 @@ function getHeaderText (mode: Mode, t: (key: string) => string): string {
}
}
function renderContent (props: Props, t: (key: string) => string): React.ReactNode {
const { address, code, mode = 'account' } = props;
function renderContent (props: Props, t: (key: string) => string): React.ReactNode | null {
const { address, mode = 'account' } = props;
switch (mode) {
case 'account':
@ -81,21 +74,14 @@ function renderContent (props: Props, t: (key: string) => string): React.ReactNo
{getContent(mode, t)}
</AddressRow>
);
case 'code':
return (
<CodeRow
isInline
code={code || ''}
>
{getContent(mode, t)}
</CodeRow>
);
default:
return null;
}
}
export default function Forget (props: Props): React.ReactElement<Props> {
function Forget (props: Props): React.ReactElement<Props> {
const { t } = useTranslation();
const { mode = 'account', onForget, onClose } = props;
const { children, mode = 'account', onForget, onClose } = props;
return (
<Modal
@ -103,7 +89,7 @@ export default function Forget (props: Props): React.ReactElement<Props> {
header={getHeaderText(mode, t)}
onClose={onClose}
>
<Modal.Content>{renderContent(props, t)}</Modal.Content>
<Modal.Content>{children || renderContent(props, t)}</Modal.Content>
<Modal.Actions onCancel={onClose}>
<Button
isPrimary
@ -115,3 +101,5 @@ export default function Forget (props: Props): React.ReactElement<Props> {
</Modal>
);
}
export default React.memo(Forget);

View File

@ -26,7 +26,6 @@ export { default as ChainLock } from './ChainLock';
export { default as Chart } from './Chart';
export { default as Columar } from './Columar';
export { default as Column } from './Column';
export { default as CodeRow } from './CodeRow';
export { default as CopyButton } from './CopyButton';
export { default as CryptoType } from './CryptoType';
export { default as Dropdown } from './Dropdown';
@ -64,8 +63,6 @@ export { default as Labelled } from './Labelled';
export { default as LinkExternal } from './LinkExternal';
export { default as LockedVote } from './LockedVote';
export { default as Menu } from './Menu';
export { default as Messages } from './Messages';
export { default as MessageSignature } from './MessageSignature';
export { default as Modal } from './Modal';
export { default as Nonce } from './Nonce';
export { default as Output } from './Output';