1
0
mirror of https://github.com/oceanprotocol/market.git synced 2024-11-16 02:04:54 +01:00

output Liquidity Provider Fee

This commit is contained in:
Matthias Kretschmann 2020-08-06 11:41:18 +02:00
parent 988c7bc89a
commit 0b1505d5f3
Signed by: m
GPG Key ID: 606EEEF3C479A91F
4 changed files with 38 additions and 13 deletions

View File

@ -35,9 +35,10 @@
.tokens { .tokens {
display: grid; display: grid;
margin-bottom: -2rem;
margin-left: -3rem; margin-left: -3rem;
margin-right: -3rem; margin-right: -3rem;
border-bottom: 1px solid var(--brand-grey-lighter);
} }
@media screen and (min-width: 40rem) { @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 { .alertArea {
margin-left: -3rem; margin-left: -3rem;
margin-right: -3rem; margin-right: -3rem;
padding: var(--spacer) calc(var(--spacer) / 2); padding: var(--spacer) calc(var(--spacer) / 2);
padding-bottom: 0; padding-bottom: 0;
margin-top: var(--spacer); margin-top: var(--spacer);
border-top: 1px solid var(--brand-grey-lighter);
} }

View File

@ -8,17 +8,21 @@ import Alert from '../../../atoms/Alert'
import Coin from './Coin' import Coin from './Coin'
import { isCorrectNetwork } from '../../../../utils/wallet' import { isCorrectNetwork } from '../../../../utils/wallet'
import { useSiteMetadata } from '../../../../hooks/useSiteMetadata' import { useSiteMetadata } from '../../../../hooks/useSiteMetadata'
import InputElement from '../../../atoms/Input/InputElement'
import Label from '../../../atoms/Input/Label'
export default function Advanced({ export default function Advanced({
ocean, ocean,
tokensToMint, tokensToMint,
weightOnDataToken, weightOnDataToken,
onChange liquidityProviderFee,
onOceanChange
}: { }: {
ocean: string ocean: string
tokensToMint: number tokensToMint: number
weightOnDataToken: string weightOnDataToken: string
onChange: (event: ChangeEvent<HTMLInputElement>) => void liquidityProviderFee: string
onOceanChange: (event: ChangeEvent<HTMLInputElement>) => void
}): ReactElement { }): ReactElement {
const { appConfig } = useSiteMetadata() const { appConfig } = useSiteMetadata()
const { account, balance, chainId, refreshBalance } = useOcean() const { account, balance, chainId, refreshBalance } = useOcean()
@ -40,18 +44,19 @@ export default function Advanced({
} else { } else {
setError(undefined) setError(undefined)
} }
}, [ocean]) }, [ocean, chainId, account, balance])
// refetch balance periodically // refetch balance periodically
useEffect(() => { useEffect(() => {
if (!account) return if (!account) return
refreshBalance()
const balanceInterval = setInterval(() => refreshBalance(), 10000) // 10 sec. const balanceInterval = setInterval(() => refreshBalance(), 10000) // 10 sec.
return () => { return () => {
clearInterval(balanceInterval) clearInterval(balanceInterval)
} }
}, []) }, [ocean, chainId, account])
return ( return (
<div className={stylesIndex.content}> <div className={stylesIndex.content}>
@ -78,7 +83,7 @@ export default function Advanced({
symbol="OCEAN" symbol="OCEAN"
value={ocean} value={ocean}
weight={`${100 - Number(Number(weightOnDataToken) * 10)}%`} weight={`${100 - Number(Number(weightOnDataToken) * 10)}%`}
onChange={onChange} onOceanChange={onOceanChange}
/> />
<Coin <Coin
name="tokensToMint" name="tokensToMint"
@ -89,6 +94,16 @@ export default function Advanced({
/> />
</div> </div>
<footer className={styles.summary}>
<Label htmlFor="liquidityProviderFee">Liquidity Provider Fee</Label>
<InputElement
value={liquidityProviderFee}
name="liquidityProviderFee"
readOnly
postfix="%"
/>
</footer>
{error && ( {error && (
<div className={styles.alertArea}> <div className={styles.alertArea}>
<Alert text={error} state="error" /> <Alert text={error} state="error" />

View File

@ -10,14 +10,14 @@ export default function Coin({
name, name,
value, value,
weight, weight,
onChange, onOceanChange,
readOnly readOnly
}: { }: {
symbol: string symbol: string
name: string name: string
value: string value: string
weight: string weight: string
onChange?: (event: ChangeEvent<HTMLInputElement>) => void onOceanChange?: (event: ChangeEvent<HTMLInputElement>) => void
readOnly?: boolean readOnly?: boolean
}): ReactElement { }): ReactElement {
return ( return (
@ -31,7 +31,7 @@ export default function Coin({
value={value} value={value}
name={name} name={name}
type="number" type="number"
onChange={onChange} onChange={onOceanChange}
readOnly={readOnly} readOnly={readOnly}
prefix={symbol} prefix={symbol}
/> />

View File

@ -8,7 +8,7 @@ import { useField } from 'formik'
export default function Price(props: InputProps): ReactElement { export default function Price(props: InputProps): ReactElement {
const [field, meta, helpers] = useField(props) const [field, meta, helpers] = useField(props)
const { weightOnDataToken } = field.value const { weightOnDataToken, liquidityProviderFee } = field.value
const [ocean, setOcean] = useState('1') const [ocean, setOcean] = useState('1')
const [tokensToMint, setTokensToMint] = useState<number>() const [tokensToMint, setTokensToMint] = useState<number>()
@ -26,7 +26,6 @@ export default function Price(props: InputProps): ReactElement {
useEffect(() => { useEffect(() => {
const tokensToMint = Number(ocean) * Number(weightOnDataToken) const tokensToMint = Number(ocean) * Number(weightOnDataToken)
setTokensToMint(tokensToMint) setTokensToMint(tokensToMint)
console.log(field.value)
helpers.setValue({ ...field.value, tokensToMint }) helpers.setValue({ ...field.value, tokensToMint })
}, [ocean]) }, [ocean])
@ -42,7 +41,8 @@ export default function Price(props: InputProps): ReactElement {
ocean={ocean} ocean={ocean}
tokensToMint={tokensToMint} tokensToMint={tokensToMint}
weightOnDataToken={weightOnDataToken} weightOnDataToken={weightOnDataToken}
onChange={handleOceanChange} onOceanChange={handleOceanChange}
liquidityProviderFee={liquidityProviderFee}
/> />
) )
} }