Show labels of account parent (#306)

* Show derived accounts indentation

* Add parent labels

* Update branch

* styling

* CR requests

* Slightly reword derive documentation

* Remove derivation path from account metadata
This commit is contained in:
Ivan Rukhavets
2020-04-03 10:45:30 +02:00
committed by GitHub
parent 5e13f5e57f
commit 53d3ebce37
14 changed files with 173 additions and 43 deletions
@@ -2,7 +2,7 @@
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
import { AccountJson } from '@polkadot/extension-base/background/types';
import { AccountJson, AccountWithChildren } from '@polkadot/extension-base/background/types';
import { Chain } from '@polkadot/extension-chains/types';
import React, { useCallback, useContext, useEffect, useRef, useState } from 'react';
@@ -29,6 +29,7 @@ interface Props {
children?: React.ReactNode;
genesisHash?: string | null;
actions?: React.ReactNode;
parentName?: string;
}
interface Recoded {
@@ -47,7 +48,7 @@ function findAccount (accounts: AccountJson[], publicKey: Uint8Array): AccountJs
}
// recodes an supplied address using the prefix/genesisHash, include the actual saved account & chain
function recodeAddress (address: string, accounts: AccountJson[], chain: Chain | null): Recoded {
function recodeAddress (address: string, accounts: AccountWithChildren[], chain: Chain | null): Recoded {
// decode and create a shortcut for the encoded address
const publicKey = decodeAddress(address);
@@ -65,8 +66,8 @@ function recodeAddress (address: string, accounts: AccountJson[], chain: Chain |
const ACCOUNTS_SCREEN_HEIGHT = 500;
function Address ({ actions, address, children, className, genesisHash, name }: Props): React.ReactElement<Props> {
const accounts = useContext(AccountContext);
function Address ({ actions, address, children, className, genesisHash, name, parentName }: Props): React.ReactElement<Props> {
const { accounts } = useContext(AccountContext);
const chain = useMetadata(genesisHash);
const [{ account, formatted, prefix }, setRecoded] = useState<Recoded>({ account: null, formatted: null, prefix: 42 });
const [showActionsMenu, setShowActionsMenu] = useState(false);
@@ -111,9 +112,8 @@ function Address ({ actions, address, children, className, genesisHash, name }:
<Name>{name || (account && account.name) || '<unknown>'}</Name>
<CopyAddress>
<FullAddress>{formatted || '<unknown>'}</FullAddress>
{chain?.genesisHash && (
<Banner>{chain.name}</Banner>
)}
{chain?.genesisHash && <ChainBanner>{chain.name}</ChainBanner>}
{parentName && <ParentBanner>↳ {parentName}</ParentBanner>}
<CopyToClipboard text={(formatted && formatted) || ''} >
<Svg
onClick={_onCopy}
@@ -241,7 +241,6 @@ const ActiveActionsIcon = styled(Svg).attrs(() => ({
`;
const Banner = styled.div`
background: ${({ theme }): string => theme.primaryColor};
border-radius: 0 0 8px 8px;
color: white;
font-size: 12px;
@@ -252,6 +251,14 @@ const Banner = styled.div`
top: 0;
`;
const ChainBanner = styled(Banner)`
background: ${({ theme }): string => theme.primaryColor};
`;
const ParentBanner = styled(Banner)`
background: ${({ theme }): string => theme.parentLabelColor};
`;
const MovableMenu = styled(Menu) <{ isMoved: boolean }>`
${({ isMoved }): string => isMoved ? 'bottom: 50px' : ''};
`;
@@ -2,7 +2,7 @@
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
import { AccountJson, AuthorizeRequest, MetadataRequest, SigningRequest } from '@polkadot/extension-base/background/types';
import { AccountsContext, AuthorizeRequest, MetadataRequest, SigningRequest } from '@polkadot/extension-base/background/types';
import React from 'react';
import { AvailableThemes } from '.';
@@ -10,7 +10,10 @@ import { AvailableThemes } from '.';
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const noop = (): void => undefined;
const AccountContext = React.createContext<AccountJson[]>([]);
const AccountContext = React.createContext<AccountsContext>({
accounts: [],
hierarchy: []
});
const ActionContext = React.createContext<(to?: string) => void>(noop);
const AuthorizeReqContext = React.createContext<AuthorizeRequest[]>([]);
const MediaContext = React.createContext<boolean>(false);
@@ -34,6 +34,7 @@ const darkTheme = {
labelFontSize: '13px',
labelLineHeight: '18px',
lineHeight: '26px',
parentLabelColor: '#4A7463',
popupBackground: '#38393F',
primaryColor: '#FF7D01',
readonlyInputBackground: '#1A1B20',
@@ -59,6 +60,7 @@ const lightTheme: Theme = {
inputBackground: '#FFFFFF',
inputBorderColor: '#DDE1EB',
labelColor: '#333333',
parentLabelColor: '#215B4F',
popupBackground: '#FFFFFF',
readonlyInputBackground: '#FFF',
subTextColor: '#454545',