From b36edb24141565d25096d9cca44f5249ba811365 Mon Sep 17 00:00:00 2001 From: Matthias Kretschmann Date: Wed, 29 Jul 2020 21:08:22 +0200 Subject: [PATCH] output balance & error feedback --- .../FormFields/Price/Advanced.module.css | 25 ++++++++++++++++--- .../molecules/FormFields/Price/Advanced.tsx | 19 ++++++++++++-- .../FormFields/Price/index.module.css | 4 ++- 3 files changed, 42 insertions(+), 6 deletions(-) diff --git a/src/components/molecules/FormFields/Price/Advanced.module.css b/src/components/molecules/FormFields/Price/Advanced.module.css index aeddcd7ff..8d4983810 100644 --- a/src/components/molecules/FormFields/Price/Advanced.module.css +++ b/src/components/molecules/FormFields/Price/Advanced.module.css @@ -1,10 +1,29 @@ .advanced { } -.wallet > button { - margin: var(--spacer) auto calc(var(--spacer) / 2) auto; - display: block; +.wallet { + display: flex; + align-items: center; + justify-content: center; + margin-bottom: calc(var(--spacer) / 2); +} + +.balance { + text-align: center; + font-size: var(--font-size-small); + border: 1px solid var(--brand-grey-lighter); + border-right: 0; + margin-right: -3px; + padding: calc(var(--spacer) / 4.5) calc(var(--spacer) / 2); + border-top-left-radius: var(--border-radius); + border-bottom-left-radius: var(--border-radius); + color: var(--color-secondary); +} + +.balance strong { + color: var(--brand-grey); } .tokens { + margin-bottom: var(--spacer); } diff --git a/src/components/molecules/FormFields/Price/Advanced.tsx b/src/components/molecules/FormFields/Price/Advanced.tsx index 31aa21ba4..b9f0ffa2f 100644 --- a/src/components/molecules/FormFields/Price/Advanced.tsx +++ b/src/components/molecules/FormFields/Price/Advanced.tsx @@ -1,4 +1,4 @@ -import React, { ReactElement, useState, ChangeEvent } from 'react' +import React, { ReactElement, useState, ChangeEvent, useEffect } from 'react' import { InputProps } from '../../../atoms/Input' import InputElement from '../../../atoms/Input/InputElement' import stylesIndex from './index.module.css' @@ -10,6 +10,7 @@ import Conversion from '../../../atoms/Price/Conversion' import FormHelp from '../../../atoms/Input/Help' import Wallet from '../../Wallet' import { useOcean } from '@oceanprotocol/react' +import Alert from '../../../atoms/Alert' export default function Advanced(props: InputProps): ReactElement { const { price } = props.form.values as MetadataPublishForm @@ -21,6 +22,14 @@ export default function Advanced(props: InputProps): ReactElement { const [ocean, setOcean] = useState('10') const tokensToMint = Number(ocean) * (Number(weightOnDataToken) / 10) + const [error, setError] = useState() + + useEffect(() => { + if (balance.ocean < ocean) { + setError(`Insufficiant balance. You need at least ${ocean} OCEAN`) + } + }, [ocean]) + function handleOceanChange(event: ChangeEvent) { setOcean(event.target.value) } @@ -34,6 +43,11 @@ export default function Advanced(props: InputProps): ReactElement { @@ -70,7 +84,6 @@ export default function Advanced(props: InputProps): ReactElement { {...props.field} value={tokensToMint.toString()} name="price.tokensToMint" - type="number" readOnly /> @@ -78,6 +91,8 @@ export default function Advanced(props: InputProps): ReactElement { + + {error && } {/* Hidden to fields to actually collect form values for Formik state */} diff --git a/src/components/molecules/FormFields/Price/index.module.css b/src/components/molecules/FormFields/Price/index.module.css index da4b6f1ac..33cfdef48 100644 --- a/src/components/molecules/FormFields/Price/index.module.css +++ b/src/components/molecules/FormFields/Price/index.module.css @@ -29,5 +29,7 @@ .help { text-align: center; - margin-bottom: calc(var(--spacer) / 2); + margin-bottom: var(--spacer); + border-bottom: 1px solid var(--brand-grey-lighter); + padding-bottom: var(--spacer); }