ghost-portal/packages/react-components/src/AddressRow.tsx
Krzysztof Jelski 7b387762bd
Updated flow for creating accounts (#3880)
* Add 3 step account creation

* Add textarea with dropdown

* Add OWASP and styles to PasswordStrength

* Align the checkbox with other ui elements

* Notification on mnemonic copy

* Make confirmation label clickable

* Do not shorten address in creation modal

* Make address name not editable in header

* Always show password strength meter

* Always show password strength meter

* Update tests to new account flow

* Remove repeated dependency

* Remove console.log from test

* Update yarn.lock

* Restore imports order.

* Format div component according to style

* Remove cursor styling for old browsers

* Empty line

* Organize imports. Configure StrengthTester once. Use color from theme.

* wip on text area

* TextArea styling

* Checbox styling

* Update repeated password validity on first password change

* Simplify CopyButton notification code.

* Change TextArea styling to more consistent

* Make password strength indicator wider

* Move external warning down and show on both steps

* Inline TextArea subcomponents

* Move mnemonic saved confirmation label closer to buttons

* Add steps counter to header

* Remove space

Co-authored-by: Michał Ziętalak <michal.z@ethworks.io>
Co-authored-by: Jaco Greeff <jacogr@gmail.com>
2020-10-22 15:59:01 +02:00

112 lines
2.8 KiB
TypeScript

// Copyright 2017-2020 @polkadot/react-components authors & contributors
// SPDX-License-Identifier: Apache-2.0
import { AccountId, AccountIndex, Address } from '@polkadot/types/interfaces';
import React from 'react';
import styled from 'styled-components';
import { useAccountInfo } from '@polkadot/react-hooks';
import BaseIdentityIcon from '@polkadot/react-identicon';
import { toShortAddress } from './util';
import IdentityIcon from './IdentityIcon';
import Row, { RowProps } from './Row';
export interface Props extends RowProps {
isContract?: boolean;
isValid?: boolean;
fullLength?: boolean;
label?: string;
noDefaultNameOpacity?: boolean;
overlay?: React.ReactNode;
value: AccountId | AccountIndex | Address | string;
withSidebar?: boolean;
withTags?: boolean;
}
const DEFAULT_ADDR = '5'.padEnd(48, 'x');
const ICON_SIZE = 32;
function AddressRow ({ buttons, children, className, defaultName, fullLength = false, isContract = false, isDisabled, isEditableName, isInline, isValid: propsIsValid, overlay, value, withTags = false }: Props): React.ReactElement<Props> | null {
const { accountIndex, isNull, name, onSaveName, onSaveTags, setName, setTags, tags } = useAccountInfo(value ? value.toString() : null, isContract);
const isValid = !isNull && (propsIsValid || value || accountIndex);
const Icon = value ? IdentityIcon : BaseIdentityIcon;
const address = value && isValid ? value : DEFAULT_ADDR;
return (
<Row
address={fullLength ? address : toShortAddress(address)}
buttons={buttons}
className={className}
defaultName={defaultName}
icon={
<Icon
size={ICON_SIZE}
value={value ? value.toString() : null}
/>
}
isDisabled={isDisabled}
isEditableName={isEditableName}
isEditableTags
isInline={isInline}
name={name}
onChangeName={setName}
onChangeTags={setTags}
onSaveName={onSaveName}
onSaveTags={onSaveTags}
tags={withTags && tags}
>
{children}
{overlay}
</Row>
);
}
export {
DEFAULT_ADDR,
AddressRow
};
export default React.memo(styled(AddressRow)`
button.u.ui--Icon.editButton {
padding: 0 .3em .3em .3em;
color: #2e86ab;
background: none;
/*trick to let the button in the flow but keep the content centered regardless*/
margin-left: -2em;
position: relative;
right: -2.3em;
z-index: 1;
}
.editSpan {
white-space: nowrap;
&:before {
content: '';
}
}
.ui--AddressRow-balances {
display: flex;
.column {
display: block;
label,
.result {
display: inline-block;
vertical-align: middle;
}
}
> span {
text-align: left;
}
}
.ui--AddressRow-placeholder {
opacity: 0.5;
}
`);