// Copyright 2017-2023 @polkadot/react-components authors & contributors // SPDX-License-Identifier: Apache-2.0 import type { AbiConstructor, AbiMessage, ContractCallOutcome } from '@polkadot/api-contract/types'; import React, { useCallback } from 'react'; import styled from 'styled-components'; import { Button, Output } from '@polkadot/react-components'; import valueToText from '@polkadot/react-params/valueToText'; import { useTranslation } from '../translate'; import MessageSignature from './MessageSignature'; export interface Props { className?: string; index: number; lastResult?: ContractCallOutcome; message: AbiConstructor | AbiMessage; onSelect?: (index: number) => void; } function filterDocs (docs: string[]): string[] { let skip = false; return docs .map((line) => line.trim()) .filter((line) => line) .filter((line, index): boolean => { if (skip) { return false; } else if (index || line.startsWith('#')) { skip = true; return false; } return true; }); } function Message ({ className = '', index, lastResult, message, onSelect }: Props): React.ReactElement { const { t } = useTranslation(); const _onSelect = useCallback( () => onSelect && onSelect(index), [index, onSelect] ); return (
{onSelect && ( message.isConstructor ? (
); } export default React.memo(styled(Message)` align-items: center; border-radius: 0.25rem; display: flex; padding: 0.25rem 0.75rem 0.25rem 0; &.disabled { opacity: 1 !important; background: #eee !important; color: #555 !important; } .info { flex: 1 1; margin-left: 1.5rem; .docs { font-size: var(--font-size-small); font-weight: var(--font-weight-normal); } } .result { min-width: 15rem; } &+& { margin-top: 0.5rem; } `);