From 4b7987ae1c11e7121379033f21759e8b67a02082 Mon Sep 17 00:00:00 2001 From: kwingram25 Date: Wed, 12 Jun 2019 13:52:53 +0200 Subject: [PATCH] New contracts app (#1283) * new contracts app * new contracts app * test ci fix * fixes * fixes * remove abi inline * css code card * icon buttons * fixes * fixes cont. * travis ci fixed * api version --- package.json | 4 +- packages/app-accounts/src/Account.tsx | 8 +- packages/app-accounts/src/index.tsx | 1 + .../app-accounts/src/modals/Forgetting.tsx | 74 ---- packages/app-accounts/src/modals/Transfer.tsx | 2 +- packages/app-address-book/src/Address.tsx | 13 +- packages/app-address-book/src/index.tsx | 1 + .../src/modals/Forgetting.tsx | 83 ---- packages/app-contracts/src/ABI.tsx | 156 ++++++-- packages/app-contracts/src/Code.tsx | 285 -------------- packages/app-contracts/src/Codes/Add.tsx | 117 ++++++ packages/app-contracts/src/Codes/Code.tsx | 172 ++++++++ packages/app-contracts/src/Codes/Upload.tsx | 118 ++++++ .../src/{ => Codes}/ValidateCode.tsx | 2 +- packages/app-contracts/src/Codes/index.tsx | 98 +++++ packages/app-contracts/src/Contracts/Add.tsx | 133 +++++++ .../src/{ => Contracts}/Call.tsx | 220 ++++++++--- .../app-contracts/src/Contracts/Contract.tsx | 160 ++++++++ .../src/{ => Contracts}/ValidateAddr.tsx | 15 +- .../app-contracts/src/Contracts/index.tsx | 124 ++++++ packages/app-contracts/src/Deploy.tsx | 290 ++++++++++++++ packages/app-contracts/src/Instantiate.tsx | 371 ------------------ packages/app-contracts/src/Modal.tsx | 240 +++++++++++ packages/app-contracts/src/Params.tsx | 4 +- packages/app-contracts/src/RemoveABI.tsx | 94 +++++ packages/app-contracts/src/index.tsx | 133 ++++--- packages/app-contracts/src/store.ts | 66 +--- packages/app-contracts/src/types.ts | 25 +- .../app-council/src/Overview/Candidate.tsx | 1 + packages/app-council/src/Overview/Member.tsx | 1 + packages/app-democracy/src/index.tsx | 1 + packages/app-explorer/src/index.tsx | 1 + packages/app-extrinsics/src/index.tsx | 1 + packages/app-settings/src/index.tsx | 1 + packages/app-staking/src/Account/index.tsx | 1 + packages/app-staking/src/Accounts.tsx | 4 +- packages/app-staking/src/Overview/Address.tsx | 1 + packages/app-staking/src/index.tsx | 1 + packages/app-storage/src/Selection/index.tsx | 1 + packages/app-sudo/src/index.tsx | 1 + packages/app-toolbox/src/index.tsx | 1 + packages/ui-api/package.json | 2 +- packages/ui-api/src/Api.tsx | 1 + packages/ui-app/src/AddressCard.tsx | 9 +- packages/ui-app/src/AddressMini.tsx | 8 +- packages/ui-app/src/AddressRow.tsx | 351 ++--------------- packages/ui-app/src/Button/Button.tsx | 17 +- packages/ui-app/src/Button/types.ts | 2 + packages/ui-app/src/Card.tsx | 6 + packages/ui-app/src/CardGrid.tsx | 77 +++- packages/ui-app/src/CodeRow.tsx | 200 ++++++++++ packages/ui-app/src/Forget.tsx | 141 +++++++ packages/ui-app/src/InputAddress.tsx | 4 +- packages/ui-app/src/InputFile.tsx | 66 ++-- packages/ui-app/src/Messages.tsx | 117 ++++++ packages/ui-app/src/Params/Extrinsic.tsx | 2 +- packages/ui-app/src/Row.tsx | 312 +++++++++++++++ packages/ui-app/src/Tabs.tsx | 52 ++- packages/ui-app/src/index.tsx | 3 + packages/ui-app/src/styles/app.css | 2 +- packages/ui-app/src/styles/semantic.css | 1 + .../{getAddrName.ts => getAddressName.ts} | 11 +- .../{getAddrTags.ts => getAddressTags.ts} | 7 +- packages/ui-app/src/util/getContractAbi.ts | 25 ++ packages/ui-app/src/util/index.ts | 5 +- packages/ui-params/src/Param/Account.tsx | 1 + packages/ui-params/src/Param/Base.tsx | 2 +- packages/ui-params/src/Param/File.tsx | 2 +- packages/ui-params/src/Param/index.tsx | 13 +- packages/ui-params/src/types.ts | 2 +- packages/ui-signer/src/Modal.tsx | 3 +- tsconfig.json | 2 + yarn.lock | 130 +++--- 73 files changed, 3110 insertions(+), 1491 deletions(-) delete mode 100644 packages/app-accounts/src/modals/Forgetting.tsx delete mode 100644 packages/app-address-book/src/modals/Forgetting.tsx delete mode 100644 packages/app-contracts/src/Code.tsx create mode 100644 packages/app-contracts/src/Codes/Add.tsx create mode 100644 packages/app-contracts/src/Codes/Code.tsx create mode 100644 packages/app-contracts/src/Codes/Upload.tsx rename packages/app-contracts/src/{ => Codes}/ValidateCode.tsx (98%) create mode 100644 packages/app-contracts/src/Codes/index.tsx create mode 100644 packages/app-contracts/src/Contracts/Add.tsx rename packages/app-contracts/src/{ => Contracts}/Call.tsx (51%) create mode 100644 packages/app-contracts/src/Contracts/Contract.tsx rename packages/app-contracts/src/{ => Contracts}/ValidateAddr.tsx (78%) create mode 100644 packages/app-contracts/src/Contracts/index.tsx create mode 100644 packages/app-contracts/src/Deploy.tsx delete mode 100644 packages/app-contracts/src/Instantiate.tsx create mode 100644 packages/app-contracts/src/Modal.tsx create mode 100644 packages/app-contracts/src/RemoveABI.tsx create mode 100644 packages/ui-app/src/CodeRow.tsx create mode 100644 packages/ui-app/src/Forget.tsx create mode 100644 packages/ui-app/src/Messages.tsx create mode 100644 packages/ui-app/src/Row.tsx rename packages/ui-app/src/util/{getAddrName.ts => getAddressName.ts} (59%) rename packages/ui-app/src/util/{getAddrTags.ts => getAddressTags.ts} (64%) create mode 100644 packages/ui-app/src/util/getContractAbi.ts diff --git a/package.json b/package.json index 60dedb694f..764ea2d4c5 100644 --- a/package.json +++ b/package.json @@ -10,9 +10,9 @@ "packages/*" ], "resolutions": { - "@polkadot/api": "^0.81.0-beta.3", + "@polkadot/api": "^0.81.0-beta.7", "@polkadot/keyring": "^0.93.0-beta.0", - "@polkadot/types": "^0.81.0-beta.3", + "@polkadot/types": "^0.81.0-beta.7", "@polkadot/util": "^0.93.0-beta.0", "@polkadot/util-crypto": "^0.93.0-beta.0", "babel-core": "^7.0.0-bridge.0", diff --git a/packages/app-accounts/src/Account.tsx b/packages/app-accounts/src/Account.tsx index d0acda03fb..8aa13c8a5d 100644 --- a/packages/app-accounts/src/Account.tsx +++ b/packages/app-accounts/src/Account.tsx @@ -6,12 +6,11 @@ import { ActionStatus } from '@polkadot/ui-app/Status/types'; import { I18nProps } from '@polkadot/ui-app/types'; import React from 'react'; -import { AddressCard, AddressInfo, Button, Icon } from '@polkadot/ui-app'; +import { AddressCard, AddressInfo, Button, Forget, Icon } 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 Transfer from './modals/Transfer'; import translate from './translate'; @@ -53,6 +52,7 @@ class Account extends React.PureComponent { { if (isForgetOpen) { modals.push( - diff --git a/packages/app-accounts/src/index.tsx b/packages/app-accounts/src/index.tsx index 7df34b21e8..cde9d3465d 100644 --- a/packages/app-accounts/src/index.tsx +++ b/packages/app-accounts/src/index.tsx @@ -42,6 +42,7 @@ class AccountsApp extends React.PureComponent { ...baseState, tabs: [ { + isRoot: true, name: 'overview', text: t('My accounts') }, diff --git a/packages/app-accounts/src/modals/Forgetting.tsx b/packages/app-accounts/src/modals/Forgetting.tsx deleted file mode 100644 index 32964d7c1f..0000000000 --- a/packages/app-accounts/src/modals/Forgetting.tsx +++ /dev/null @@ -1,74 +0,0 @@ -// Copyright 2017-2019 @polkadot/app-accounts 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 { I18nProps } from '@polkadot/ui-app/types'; - -import React from 'react'; -import { AddressRow, Button, Modal } from '@polkadot/ui-app'; - -import translate from '../translate'; - -type Props = I18nProps & { - address: string, - onClose: () => void, - doForget: () => void -}; - -class Forgetting extends React.PureComponent { - render () { - const { t } = this.props; - - return ( - - {t('Confirm account removal')} - {this.renderContent()} - {this.renderButtons()} - - ); - } - - private renderButtons () { - const { onClose, doForget, t } = this.props; - - return ( - - - + ); + } + + onSelect = (index: number) => () => { + const { address: callAddress, contractAbi: { abi: { messages } }, onSelect } = this.props; + + if (!callAddress || !messages || !messages[index]) { + return; + } + + const { name: callMethod } = messages[index]; + + onSelect && onSelect(callAddress, callMethod); + } +} + +export default translate(Messages); diff --git a/packages/ui-app/src/Params/Extrinsic.tsx b/packages/ui-app/src/Params/Extrinsic.tsx index 5f37815d0a..71d1c28fb5 100644 --- a/packages/ui-app/src/Params/Extrinsic.tsx +++ b/packages/ui-app/src/Params/Extrinsic.tsx @@ -17,7 +17,7 @@ type Props = I18nProps & { isDisabled?: boolean, isError?: boolean, isPrivate: boolean, - label: string, + label: React.ReactNode, onChange?: RawParam$OnChange, onEnter?: RawParam$OnEnter, withLabel?: boolean diff --git a/packages/ui-app/src/Row.tsx b/packages/ui-app/src/Row.tsx new file mode 100644 index 0000000000..ae8c145310 --- /dev/null +++ b/packages/ui-app/src/Row.tsx @@ -0,0 +1,312 @@ +// Copyright 2017-2019 @polkadot/ui-app 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 { Label } from 'semantic-ui-react'; +import React from 'react'; +import { Button, Input, InputTags } from '@polkadot/ui-app'; + +import { classes } from './util'; + +export const styles = ` + text-align: left; + + &.inline { + display: flex; + + .ui--Row-children { + padding: 0 0 0 3rem; + } + } + + &.invalid { + filter: grayscale(100); + opacity: 0.5; + } + + button.ui.icon.editButton { + padding: 0em .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; + } + + .ui--Row-accountId, + .ui--Row-accountIndex { + font-family: monospace; + font-size: 1.25em; + padding: 0; + margin-bottom: 0.25rem; + } + + .ui--Row-accountIndex { + font-style: italic; + } + + .ui--Row-balances { + .column { + display: block; + + label, + .result { + display: inline-block; + } + } + + > span { + text-align: left; + } + } + + .ui--Row-base { + display: flex; + } + + .ui--Row-buttons { + flex: 0; + margin: -0.75rem -0.75rem 0 0; + white-space: nowrap; + } + + .ui--Row-children { + display: block; + padding-top: 1rem; + } + + .ui--Row-details { + flex: 1; + margin-right: 1rem; + padding: 0.25rem 0 0; + + * { + vertical-align: middle; + } + } + + .ui--Row-icon { + flex: 0; + margin-right: 1em; + position: relative; + + .ui--Row-icon-info { + left: -0.5rem; + position: absolute; + top: -0.5rem; + } + } + + .ui--Row-name { + box-sizing: border-box; + margin: 0; + padding: 0; + overflow: hidden; + text-overflow: ellipsis; + text-transform: uppercase; + white-space: normal; + } + + .ui--Row-name-input { + input { + height: 1em; + text-transform: uppercase; + margin-top: -0.3em; + margin-bottom: -0.35em; + } + } + + .ui--Row-tags { + &.editable { + display: flex; + flex-wrap: wrap; + justify-content: left; + + > span { + border: 1px #00000052 solid; + border-radius: .5em; + border-style: dashed; + color: grey; + font-size: x-small; + padding: .1em 0.3em 0.1em 0.3em; + margin-top: .2em; + } + + > div.label { + margin-top:.3em + } + } + } + + .ui--Row-tags-input { + margin-bottom: -1.4em; + } +`; + +export type RowProps = { + buttons?: React.ReactNode, + children?: React.ReactNode, + className?: string, + defaultName?: string, + extraInfo?: React.ReactNode, + iconInfo?: React.ReactNode, + isEditable?: boolean, + isInline?: boolean, + withIcon?: boolean, + withTags?: boolean +}; + +export type RowState = { + isEditingName: boolean, + isEditingTags: boolean, + name: string, + tags: string[] +}; + +// const DEFAULT_ADDR = '5'.padEnd(16, 'x'); +// const ICON_SIZE = 48; + +class Row

extends React.PureComponent { + state: S = { + isEditingName: false, + isEditingTags: false + } as S; + + static defaultProps = { + defaultName: '' + }; + + protected onChangeName = (name: string) => { + this.setState({ name }); + } + + protected onChangeTags = (tags: string[]) => { + this.setState({ tags }); + } + + protected renderButtons () { + const { buttons } = this.props; + + return buttons + ?

{buttons}
+ : null; + } + + protected renderChildren () { + const { children } = this.props; + + const hasChildren = !children + ? false + : Array.isArray(children) + ? children.filter((child) => child).length !== 0 + : true; + + if (!hasChildren) { + return null; + } + + return ( +
+ {children} +
+ ); + } + + protected renderEditIcon () { + return ( +