ghost-portal/packages/page-contracts/src/shared/MessageSignature.tsx
Albert 2215541cd9
Apply Nunito fonts globally (#3882)
* Add nunito fonts

* Apply Nunito fonts globally

* Remove Nunito fonts (600,800)

* Add fontFamily to themes

* Unify font-weight and font-family across app

* Fix linting

* Use Monospace font from theme where required

* Add font-family from theme to buttons

* Revert font-family change in Claim

* Provide enough vertical space for rendering of an account name with verified identity

* Use theme font in transfer and search inputs

Co-authored-by: Jaco Greeff <jacogr@gmail.com>
Co-authored-by: Krzysztof Jelski <krzysztof@ethworks.io>
2020-11-04 14:35:49 +01:00

104 lines
2.8 KiB
TypeScript

// Copyright 2017-2020 @polkadot/react-components authors & contributors
// SPDX-License-Identifier: Apache-2.0
import { AbiMessage } from '@polkadot/api-contract/types';
import React from 'react';
import { ThemeProps } from '@polkadot/react-components/types';
import styled from 'styled-components';
import { Icon, Tooltip } from '@polkadot/react-components';
import { encodeTypeDef } from '@polkadot/types';
import { stringCamelCase } from '@polkadot/util';
import { useTranslation } from '../translate';
const MAX_PARAM_LENGTH = 20;
export interface Props {
asConstructor?: boolean;
className?: string;
message: AbiMessage;
params?: any[];
withTooltip?: boolean;
}
function truncate (param: string): string {
return param.length > MAX_PARAM_LENGTH
? `${param.substring(0, MAX_PARAM_LENGTH / 2)}…${param.substring(param.length - MAX_PARAM_LENGTH / 2)}`
: param;
}
function MessageSignature ({ className, message: { args, identifier, isConstructor, isMutating, returnType }, params = [], withTooltip = false }: Props): React.ReactElement<Props> {
const { t } = useTranslation();
return (
<div className={className}>
<span className='ui--MessageSignature-name'>{stringCamelCase(identifier)}</span>
{' '}({args.map(({ name, type }, index): React.ReactNode => {
return (
<React.Fragment key={`${name}-args-${index}`}>
{name}:
{' '}
<span className='ui--MessageSignature-type'>
{params && params[index]
? <b>{truncate((params as string[])[index].toString())}</b>
: encodeTypeDef(type)
}
</span>
{index < (args.length) - 1 && ', '}
</React.Fragment>
);
})})
{(!isConstructor && returnType) && (
<>
:
{' '}
<span className='ui--MessageSignature-returnType'>
{encodeTypeDef(returnType)}
</span>
</>
)}
{isMutating && (
<>
<Icon
className='ui--MessageSignature-mutates'
icon='database'
tooltip={`mutates-${identifier}`}
/>
{withTooltip && (
<Tooltip
text={t<string>('Mutates contract state')}
trigger={`mutates-${identifier}`}
/>
)}
</>
)}
</div>
);
}
export default React.memo(styled(MessageSignature)`
font-family: ${({ theme }: ThemeProps) => theme.fontMono};
font-weight: 400;
flex-grow: 1;
.ui--MessageSignature-mutates {
color: #ff8600;
margin-left: 0.5rem;
opacity: 0.6;
}
.ui--MessageSignature-name {
color: #2f8ddb;
font-weight: 400;
}
.ui--MessageSignature-type {
color: #21a2b2;
}
.ui--MessageSignature-returnType {
color: #ff8600;
}
`);