From 797c12be3cafb0fda042394f5fa854d20e139c62 Mon Sep 17 00:00:00 2001 From: Thibaut Sardan <33178835+Tbaut@users.noreply.github.com> Date: Wed, 22 May 2019 15:38:44 +0200 Subject: [PATCH] Account overview (#1163) * starting point * show all accounts * edit and save a name but remains ugly * actually don't use deriveStateFromProps * fix AdressRow * indentation * upperCase * bring back the index * trim input * change edition l&f * lint * cater for small screens * address comments * lint and alphabetical order * allow viewing and editing tags * better UX when tag editing and styling for no tags * nonce refactoring and show balances * crypto type * styling balances * use css grid * fix address row and creator * with buttons * button styling * locked tooltip * edit button always visible * nits cleanup * lint * address comments * try to prevent jump on editing * no jump when no tags * tweak for tag jump * forgot the useless spacer * align AddressSummary childre top right * fix key warning and nits * CSS stuff to align things * Fix merge gone wrong --- packages/app-accounts/src/Account.tsx | 352 +++++++++++++++ packages/app-accounts/src/Editor.tsx | 408 ------------------ packages/app-accounts/src/Overview.tsx | 65 +++ packages/app-accounts/src/index.css | 2 +- packages/app-accounts/src/index.tsx | 37 +- packages/app-accounts/src/modals/Backup.tsx | 21 +- .../app-accounts/src/modals/ChangePass.tsx | 67 +-- .../app-accounts/src/modals/Forgetting.tsx | 1 + packages/app-accounts/src/types.ts | 11 + packages/app-staking/src/Overview/Address.tsx | 1 - packages/app-staking/src/index.css | 2 - packages/app-transfer/src/Transfer.tsx | 1 - packages/ui-app/src/AddressMini.tsx | 6 +- packages/ui-app/src/AddressRow.tsx | 13 +- packages/ui-app/src/AddressSummary.tsx | 351 +++++++++++---- packages/ui-app/src/Available.tsx | 3 +- packages/ui-app/src/CopyButton.tsx | 2 +- packages/ui-app/src/CryptoType.tsx | 35 ++ packages/ui-app/src/Dropdown.tsx | 20 +- packages/ui-app/src/Input.tsx | 11 +- packages/ui-app/src/InputTags.tsx | 14 +- packages/ui-app/src/Nonce.tsx | 35 ++ packages/ui-app/src/index.tsx | 6 + packages/ui-app/src/styles/app.css | 7 + packages/ui-app/src/styles/components.css | 150 +++++-- packages/ui-reactive/src/Available.tsx | 31 +- packages/ui-reactive/src/Balance.tsx | 23 +- packages/ui-reactive/src/Bonded.tsx | 25 +- packages/ui-reactive/src/Nonce.tsx | 28 +- packages/ui-reactive/src/Unlocking.tsx | 106 +++-- 30 files changed, 1138 insertions(+), 696 deletions(-) create mode 100644 packages/app-accounts/src/Account.tsx delete mode 100644 packages/app-accounts/src/Editor.tsx create mode 100644 packages/app-accounts/src/Overview.tsx create mode 100644 packages/ui-app/src/CryptoType.tsx create mode 100644 packages/ui-app/src/Nonce.tsx diff --git a/packages/app-accounts/src/Account.tsx b/packages/app-accounts/src/Account.tsx new file mode 100644 index 0000000000..64c4147a80 --- /dev/null +++ b/packages/app-accounts/src/Account.tsx @@ -0,0 +1,352 @@ +// Copyright 2017-2019 @polkadot/app-staking authors & contributors +// This software may be modified and distributed under the terms +// of the Apache-2.0 license. See the LICENSE file for details. + +import { ActionStatus } from '@polkadot/ui-app/Status/types'; +import { I18nProps } from './types'; + +import { Button as SUIB, Popup } from 'semantic-ui-react'; +import React from 'react'; +import styled from 'styled-components'; +import { AddressSummary, Available, Balance, Bonded, CryptoType, Nonce, Unlocking } from '@polkadot/ui-app'; +import keyring from '@polkadot/ui-keyring'; + +import Backup from './modals/Backup'; +import ChangePass from './modals/ChangePass'; +import Forgetting from './modals/Forgetting'; +import translate from './translate'; + +type Props = I18nProps & { + address: string +}; + +type State = { + isBackupOpen: boolean, + isForgetOpen: boolean, + isPasswordOpen: boolean +}; + +const Wrapper = styled.article` + position: relative; + flex: 1 1; + min-width: 24%; + max-width: 24%; + justify-content: space-around; + + .accounts--Account-buttons { + text-align: right; + margin-bottom: 2em; + } + + .ui--AddressSummary { + justify-content: space-around; + } + + .ui--AddressSummary-base { + flex: 1; + padding: 0; + } + .ui--AddressSummary-children { + flex: 1; + display: flex; + align-items: flex-start; + justify-content: flex-end; + } + + .account--Account-balances { + display: grid; + grid-column-gap: .5em; + color: #4e4e4e; + opacity: 1; + } + + .label-available, + .label-balance, + .label-bonded, + .label-cryptotype, + .label-locked, + .label-nonce, + .label-redeemable { + grid-column: 1; + text-align: right; + } + + .result-available, + .result-balance, + .result-bonded, + .result-cryptotype, + .result-locked, + .result-nonce, + .result-redeemable { + grid-column: 2; + } + + .accounts--Account-buttons > button { + margin: .2em; + } + + @media (max-width: 2060px) { + min-width: 32%; + max-width: 32%; + } + + @media (max-width: 1580px) { + min-width: 49%; + max-width: 49%; + } + + @media (max-width: 1100px) { + min-width: 100%; + max-width: 100%; + } +`; + +class Account extends React.PureComponent { + state: State; + + constructor (props: Props) { + super(props); + + this.state = { + isBackupOpen: false, + isForgetOpen: false, + isPasswordOpen: false + }; + } + + render () { + const { address } = this.props; + + return ( + + {this.renderModals()} + +
+ {this.renderButtons()} +
+ {this.renderTotal()} + {this.renderAvailable()} + {this.renderBonded()} + {this.renderUnlocking()} +
+ {this.renderNonce()} + {this.renderCryptoType()} +
+
+
+
+ ); + } + + private renderAvailable () { + const { address, t } = this.props; + + return ( + + ); + } + + private renderBonded () { + const { address, t } = this.props; + + return ( + + ); + } + + private renderCryptoType () { + const { address, t } = this.props; + + return ( + + ); + } + + private renderModals () { + const { address } = this.props; + const { isBackupOpen, isForgetOpen, isPasswordOpen } = this.state; + + if (!address) { + return null; + } + + const modals = []; + + if (isBackupOpen) { + modals.push( + + ); + } + + if (isForgetOpen) { + modals.push( + + ); + } + + if (isPasswordOpen) { + modals.push( + + ); + } + + return modals; + } + + private toggleBackup = (): void => { + const { isBackupOpen } = this.state; + + this.setState({ + isBackupOpen: !isBackupOpen + }); + } + + private toggleForget = (): void => { + const { isForgetOpen } = this.state; + + this.setState({ + isForgetOpen: !isForgetOpen + }); + } + + private togglePass = (): void => { + const { isPasswordOpen } = this.state; + + this.setState({ + isPasswordOpen: !isPasswordOpen + }); + } + + private onForget = (): void => { + const { address, t } = this.props; + + if (!address) { + return; + } + + const status = { + account: address, + action: 'forget' + } as ActionStatus; + + try { + keyring.forgetAccount(address); + status.status = 'success'; + status.message = t('account forgotten'); + } catch (error) { + status.status = 'error'; + status.message = error.message; + } + } + + private renderNonce () { + const { address, t } = this.props; + + return ( + + ); + } + + private renderTotal () { + const { address, t } = this.props; + + return ( + + ); + } + + private renderUnlocking () { + const { address } = this.props; + + return ( + + ); + } + + private renderButtons () { + + // FIXME: The event trigger on='hover' does not work together with the ui-app' + //