From db4d7441d907db7f543a5bd4ac1dad5c3960abbc Mon Sep 17 00:00:00 2001 From: Jaco Greeff Date: Thu, 13 Jun 2019 06:03:33 +0200 Subject: [PATCH] Various small UI fixes (incl. AddressMini names) (#1291) * Various small UI fixes * Types for getAddress defaults --- packages/ui-app/src/AddressMini.tsx | 14 ++-- packages/ui-app/src/AddressRow.tsx | 4 +- packages/ui-app/src/Messages.tsx | 75 +++++++++++----------- packages/ui-app/src/Row.tsx | 6 +- packages/ui-app/src/util/getAddressName.ts | 6 +- packages/ui-app/src/util/getAddressTags.ts | 2 +- 6 files changed, 56 insertions(+), 51 deletions(-) diff --git a/packages/ui-app/src/AddressMini.tsx b/packages/ui-app/src/AddressMini.tsx index 7425c2b19b..ddeee85817 100644 --- a/packages/ui-app/src/AddressMini.tsx +++ b/packages/ui-app/src/AddressMini.tsx @@ -68,13 +68,13 @@ class AddressMini extends React.PureComponent { } private renderAddressOrName (address: string) { - const { isShort = true, withAddress = true, type = 'address' } = this.props; + const { isShort = true, withAddress = true, type } = this.props; if (!withAddress) { return null; } - const name = getAddressName(address, type, true); + const name = getAddressName(address, type); return (
{ @@ -135,14 +135,18 @@ export default styled(AddressMini)` } .ui--AddressMini-address { - &.withAddr { + &.withAddr, + &.withName { font-family: monospace; + max-width: 9rem; + min-width: 4em; + overflow: hidden; + text-align: right; + text-overflow: ellipsis; } &.withName { - text-align: right; text-transform: uppercase; - min-width: 4em; } } diff --git a/packages/ui-app/src/AddressRow.tsx b/packages/ui-app/src/AddressRow.tsx index 97622c9ba4..4b96c85ab4 100644 --- a/packages/ui-app/src/AddressRow.tsx +++ b/packages/ui-app/src/AddressRow.tsx @@ -53,7 +53,7 @@ class AddressRow extends Row { const address = accountId ? accountId.toString() : DEFAULT_ADDR; - const name = getAddressName(address, type, false, defaultName) || ''; + const name = getAddressName(address, type, false, defaultName || '') || ''; const tags = getAddressTags(address, type); const state = { tags } as State; let hasChanged = false; @@ -106,7 +106,7 @@ class AddressRow extends Row { const address = accountId ? accountId.toString() : DEFAULT_ADDR; - const name = getAddressName(address, type, false, defaultName) || ''; + const name = getAddressName(address, type, false, defaultName || '') || ''; const tags = getAddressTags(address, type); return { diff --git a/packages/ui-app/src/Messages.tsx b/packages/ui-app/src/Messages.tsx index d809fa81ec..b641b03ec4 100644 --- a/packages/ui-app/src/Messages.tsx +++ b/packages/ui-app/src/Messages.tsx @@ -8,9 +8,9 @@ import { Button } from '@polkadot/ui-app'; import React from 'react'; import styled from 'styled-components'; -import classNames from 'classnames'; import translate from './translate'; +import { classes } from './util'; export type Props = I18nProps & { address?: string, @@ -20,44 +20,12 @@ export type Props = I18nProps & { onSelect?: (callAddress?: string, callMethod?: string) => void }; -const Wrapper = styled.div` - font-size: 0.9rem; - min-height: 3.5rem; - padding: 0; - margin: 0; - display: inline-flex; - justify-content: flex-start; - align-items: center; - flex-wrap: wrap; - - & > .message { - font-family: monospace; - font-weight: normal; - margin-bottom: 0; - margin-right: 0; - padding: 0.5rem; - margin: 0; - border-radius: 0.7rem; - - &.disabled { - opacity: 1 !important; - background: #eee !important; - color: #555 !important; - } - - &:not(:last-of-type) { - margin-right: 1rem; - } - } -`; - class Messages extends React.PureComponent { - render () { - const { contractAbi: { abi: { messages } }, isRemovable, onRemove = () => null, onSelect, t } = this.props; + const { className, contractAbi: { abi: { messages } }, isRemovable, onRemove = () => null, onSelect, t } = this.props; return ( - +
{messages.map((_, index) => { return this.renderMessage(index); })} @@ -71,7 +39,7 @@ class Messages extends React.PureComponent { tooltip={t('Remove ABI')} /> )} - +
); } @@ -87,14 +55,14 @@ class Messages extends React.PureComponent { return ( @@ -114,4 +82,33 @@ class Messages extends React.PureComponent { } } -export default translate(Messages); +export default translate(styled(Messages)` + font-size: 0.9rem; + min-height: 3.5rem; + padding: 0; + margin: 0; + display: inline-flex; + justify-content: flex-start; + align-items: center; + flex-wrap: wrap; + + & > .message { + font-family: monospace; + font-weight: normal; + margin-bottom: 0; + margin-right: 0; + padding: 0.5rem; + margin: 0; + /* border-radius: 0.7rem; */ + + &.disabled { + opacity: 1 !important; + background: #eee !important; + color: #555 !important; + } + + &:not(:last-of-type) { + margin-right: 0.5rem; + } + } +`); diff --git a/packages/ui-app/src/Row.tsx b/packages/ui-app/src/Row.tsx index ae8c145310..58dc100198 100644 --- a/packages/ui-app/src/Row.tsx +++ b/packages/ui-app/src/Row.tsx @@ -68,8 +68,12 @@ export const styles = ` .ui--Row-buttons { flex: 0; - margin: -0.75rem -0.75rem 0 0; + margin: -0.75rem -1rem 0 0; white-space: nowrap; + + button.ui.button:last-child { + margin-right: 0; + } } .ui--Row-children { diff --git a/packages/ui-app/src/util/getAddressName.ts b/packages/ui-app/src/util/getAddressName.ts index 699be40b01..24ffb36d58 100644 --- a/packages/ui-app/src/util/getAddressName.ts +++ b/packages/ui-app/src/util/getAddressName.ts @@ -6,7 +6,7 @@ import keyring from '@polkadot/ui-keyring'; import { KeyringItemType } from '@polkadot/ui-keyring/types'; import toShortAddress from './toShortAddress'; -export default function getAddressName (address: string, type: KeyringItemType | null = null, withShort?: boolean, defaultName?: string | null): string | undefined { +export default function getAddressName (address: string, type: KeyringItemType | null = null, withShort?: boolean, defaultName?: string): string | undefined { let pair; try { @@ -17,9 +17,9 @@ export default function getAddressName (address: string, type: KeyringItemType | const name = pair && pair.isValid() ? pair.getMeta().name - : (defaultName || null); + : defaultName; return !name && withShort ? toShortAddress(address) - : (name || ''); + : name; } diff --git a/packages/ui-app/src/util/getAddressTags.ts b/packages/ui-app/src/util/getAddressTags.ts index 875ec2497e..023e5ed8be 100644 --- a/packages/ui-app/src/util/getAddressTags.ts +++ b/packages/ui-app/src/util/getAddressTags.ts @@ -5,7 +5,7 @@ import keyring from '@polkadot/ui-keyring'; import { KeyringItemType } from '@polkadot/ui-keyring/types'; -export default function getAddressTags (address: string, type: KeyringItemType = 'account'): Array { +export default function getAddressTags (address: string, type: KeyringItemType | null = null): Array { let pair; try {