From 970624e6521abdde8d47c778dcd6b7aa9187dd9b Mon Sep 17 00:00:00 2001 From: Matthias Kretschmann Date: Thu, 9 Jul 2020 12:27:59 +0200 Subject: [PATCH] refined wallet interactions --- src/components/atoms/Button.tsx | 4 +- src/components/atoms/Status.module.css | 2 - src/components/atoms/Status.tsx | 25 ++++++--- .../molecules/Wallet/Account.module.css | 50 +++++++++++++++--- src/components/molecules/Wallet/Account.tsx | 51 ++++++++++++++----- .../molecules/Wallet/Details.module.css | 30 +++++++++++ src/components/molecules/Wallet/Details.tsx | 5 +- src/components/molecules/Wallet/index.tsx | 2 + src/images/caret.svg | 1 + 9 files changed, 135 insertions(+), 35 deletions(-) create mode 100644 src/images/caret.svg diff --git a/src/components/atoms/Button.tsx b/src/components/atoms/Button.tsx index fa6aa566c..7e3769742 100644 --- a/src/components/atoms/Button.tsx +++ b/src/components/atoms/Button.tsx @@ -1,4 +1,4 @@ -import React, { ReactNode, FormEvent } from 'react' +import React, { ReactNode, FormEvent, ReactElement } from 'react' import { Link } from 'gatsby' import classNames from 'classnames/bind' import styles from './Button.module.css' @@ -27,7 +27,7 @@ export default function Button({ size, style, ...props -}: ButtonProps) { +}: ButtonProps): ReactElement { const styleClasses = cx({ button: true, primary: style === 'primary', diff --git a/src/components/atoms/Status.module.css b/src/components/atoms/Status.module.css index 6d22da38f..ea1cf3f03 100644 --- a/src/components/atoms/Status.module.css +++ b/src/components/atoms/Status.module.css @@ -9,7 +9,6 @@ /* yellow triangle */ .warning { - composes: status; border-radius: 0; background: none; width: 0; @@ -21,7 +20,6 @@ /* red square */ .error { - composes: status; border-radius: 0; background: var(--brand-alert-red); text-transform: capitalize; diff --git a/src/components/atoms/Status.tsx b/src/components/atoms/Status.tsx index 123f35d18..7c6c7b310 100644 --- a/src/components/atoms/Status.tsx +++ b/src/components/atoms/Status.tsx @@ -1,13 +1,22 @@ import React, { ReactElement } from 'react' +import classNames from 'classnames/bind' import styles from './Status.module.css' -export default function Status({ state }: { state?: string }): ReactElement { - const classes = - state === 'error' - ? styles.error - : state === 'warning' - ? styles.warning - : styles.status +const cx = classNames.bind(styles) - return +export default function Status({ + state, + className +}: { + state?: string + className?: string +}): ReactElement { + const styleClasses = cx({ + status: true, + warning: state === 'warning', + error: state === 'error', + [className]: className + }) + + return } diff --git a/src/components/molecules/Wallet/Account.module.css b/src/components/molecules/Wallet/Account.module.css index a99269df3..69ab4740e 100644 --- a/src/components/molecules/Wallet/Account.module.css +++ b/src/components/molecules/Wallet/Account.module.css @@ -1,14 +1,24 @@ -.wallet { +.button { + font-family: var(--font-family-base); + font-weight: var(--font-weight-bold); + font-size: var(--font-size-small); + text-transform: uppercase; border: 1px solid var(--brand-grey-lighter); border-radius: var(--border-radius); - padding: calc(var(--spacer) / 8) calc(var(--spacer) / 4); + padding: calc(var(--spacer) / 6) calc(var(--spacer) / 4); + white-space: nowrap; + background: none; + color: var(--brand-grey); + margin: 0; + transition: border 0.2s ease-out; + cursor: pointer; } -.address { - font-size: var(--font-size-small); - font-family: var(--font-family-monospace); - white-space: nowrap; - margin-bottom: calc(var(--spacer) / 8); +.button:hover, +.button:focus { + transform: none; + outline: 0; + border-color: var(--brand-grey-light); } .blockies { @@ -20,3 +30,29 @@ vertical-align: middle; margin-right: calc(var(--spacer) / 6); } + +.address { + text-transform: none; + border-right: 1px solid var(--brand-grey-lighter); + padding-right: calc(var(--spacer) / 4); +} + +.button svg { + width: 1em; + height: 1em; + fill: var(--brand-grey-lighter); + display: inline-block; + vertical-align: middle; + margin-left: calc(var(--spacer) / 4); + transition: transform 0.2s ease-out; +} + +.wallet[aria-expanded='true'] .button svg { + transform: rotate(180deg); +} + +.status { + margin-left: calc(var(--spacer) / 4); + position: relative; + top: 1px; +} diff --git a/src/components/molecules/Wallet/Account.tsx b/src/components/molecules/Wallet/Account.tsx index 34ecdeda2..e8196c392 100644 --- a/src/components/molecules/Wallet/Account.tsx +++ b/src/components/molecules/Wallet/Account.tsx @@ -1,28 +1,51 @@ import React from 'react' import Button from '../../atoms/Button' import styles from './Account.module.css' -import { useWeb3 } from '@oceanprotocol/react' +import { useWeb3, useOcean } from '@oceanprotocol/react' import { toDataUrl } from 'ethereum-blockies' +import { ReactComponent as Caret } from '../../../images/caret.svg' +import Status from '../../atoms/Status' + +function accountTruncate(account: string) { + const middle = account.substring(6, 38) + const truncated = account.replace(middle, '…') + return truncated +} // Forward ref for Tippy.js // eslint-disable-next-line const Account = React.forwardRef((props, ref: any) => { - const { account, web3Connect } = useWeb3() + const { account, web3Connect, ethProviderStatus } = useWeb3() + const { status } = useOcean() const blockies = account && toDataUrl(account) + const hasSuccess = ethProviderStatus === 1 && status === 1 - return ( -
- {account ? ( -
- Blockies - {`${account.substring(0, 12)}...`} -
- ) : ( - + return account ? ( +
+ {accountTruncate(account)} + {!hasSuccess && ( + + )} +