From 0b1505d5f31a3d39058a9281310fb44bf170a0fc Mon Sep 17 00:00:00 2001 From: Matthias Kretschmann Date: Thu, 6 Aug 2020 11:41:18 +0200 Subject: [PATCH] output Liquidity Provider Fee --- .../FormFields/Price/Advanced.module.css | 14 +++++++++-- .../molecules/FormFields/Price/Advanced.tsx | 25 +++++++++++++++---- .../molecules/FormFields/Price/Coin.tsx | 6 ++--- .../molecules/FormFields/Price/index.tsx | 6 ++--- 4 files changed, 38 insertions(+), 13 deletions(-) diff --git a/src/components/molecules/FormFields/Price/Advanced.module.css b/src/components/molecules/FormFields/Price/Advanced.module.css index 8ff159aa2..e8da2cd42 100644 --- a/src/components/molecules/FormFields/Price/Advanced.module.css +++ b/src/components/molecules/FormFields/Price/Advanced.module.css @@ -35,9 +35,10 @@ .tokens { display: grid; - margin-bottom: -2rem; + margin-left: -3rem; margin-right: -3rem; + border-bottom: 1px solid var(--brand-grey-lighter); } @media screen and (min-width: 40rem) { @@ -46,11 +47,20 @@ } } +.summary { + text-align: center; + margin-top: var(--spacer); + margin-bottom: -2rem; +} + +.summary input { + max-width: 5rem; +} + .alertArea { margin-left: -3rem; margin-right: -3rem; padding: var(--spacer) calc(var(--spacer) / 2); padding-bottom: 0; margin-top: var(--spacer); - border-top: 1px solid var(--brand-grey-lighter); } diff --git a/src/components/molecules/FormFields/Price/Advanced.tsx b/src/components/molecules/FormFields/Price/Advanced.tsx index 004a34098..d617df6a5 100644 --- a/src/components/molecules/FormFields/Price/Advanced.tsx +++ b/src/components/molecules/FormFields/Price/Advanced.tsx @@ -8,17 +8,21 @@ import Alert from '../../../atoms/Alert' import Coin from './Coin' import { isCorrectNetwork } from '../../../../utils/wallet' import { useSiteMetadata } from '../../../../hooks/useSiteMetadata' +import InputElement from '../../../atoms/Input/InputElement' +import Label from '../../../atoms/Input/Label' export default function Advanced({ ocean, tokensToMint, weightOnDataToken, - onChange + liquidityProviderFee, + onOceanChange }: { ocean: string tokensToMint: number weightOnDataToken: string - onChange: (event: ChangeEvent) => void + liquidityProviderFee: string + onOceanChange: (event: ChangeEvent) => void }): ReactElement { const { appConfig } = useSiteMetadata() const { account, balance, chainId, refreshBalance } = useOcean() @@ -40,18 +44,19 @@ export default function Advanced({ } else { setError(undefined) } - }, [ocean]) + }, [ocean, chainId, account, balance]) // refetch balance periodically useEffect(() => { if (!account) return + refreshBalance() const balanceInterval = setInterval(() => refreshBalance(), 10000) // 10 sec. return () => { clearInterval(balanceInterval) } - }, []) + }, [ocean, chainId, account]) return (
@@ -78,7 +83,7 @@ export default function Advanced({ symbol="OCEAN" value={ocean} weight={`${100 - Number(Number(weightOnDataToken) * 10)}%`} - onChange={onChange} + onOceanChange={onOceanChange} />
+
+ + +
+ {error && (
diff --git a/src/components/molecules/FormFields/Price/Coin.tsx b/src/components/molecules/FormFields/Price/Coin.tsx index 93fd344ef..53c3590be 100644 --- a/src/components/molecules/FormFields/Price/Coin.tsx +++ b/src/components/molecules/FormFields/Price/Coin.tsx @@ -10,14 +10,14 @@ export default function Coin({ name, value, weight, - onChange, + onOceanChange, readOnly }: { symbol: string name: string value: string weight: string - onChange?: (event: ChangeEvent) => void + onOceanChange?: (event: ChangeEvent) => void readOnly?: boolean }): ReactElement { return ( @@ -31,7 +31,7 @@ export default function Coin({ value={value} name={name} type="number" - onChange={onChange} + onChange={onOceanChange} readOnly={readOnly} prefix={symbol} /> diff --git a/src/components/molecules/FormFields/Price/index.tsx b/src/components/molecules/FormFields/Price/index.tsx index 19b4db98b..e83f5c6ad 100644 --- a/src/components/molecules/FormFields/Price/index.tsx +++ b/src/components/molecules/FormFields/Price/index.tsx @@ -8,7 +8,7 @@ import { useField } from 'formik' export default function Price(props: InputProps): ReactElement { const [field, meta, helpers] = useField(props) - const { weightOnDataToken } = field.value + const { weightOnDataToken, liquidityProviderFee } = field.value const [ocean, setOcean] = useState('1') const [tokensToMint, setTokensToMint] = useState() @@ -26,7 +26,6 @@ export default function Price(props: InputProps): ReactElement { useEffect(() => { const tokensToMint = Number(ocean) * Number(weightOnDataToken) setTokensToMint(tokensToMint) - console.log(field.value) helpers.setValue({ ...field.value, tokensToMint }) }, [ocean]) @@ -42,7 +41,8 @@ export default function Price(props: InputProps): ReactElement { ocean={ocean} tokensToMint={tokensToMint} weightOnDataToken={weightOnDataToken} - onChange={handleOceanChange} + onOceanChange={handleOceanChange} + liquidityProviderFee={liquidityProviderFee} /> ) }