1
0
mirror of https://github.com/oceanprotocol/market.git synced 2024-06-30 22:01:44 +02:00

introduce weightOnOcean

This commit is contained in:
Matthias Kretschmann 2020-10-26 16:40:18 +01:00
parent 04e8352dd0
commit ef335ff850
Signed by: m
GPG Key ID: 606EEEF3C479A91F
4 changed files with 14 additions and 7 deletions

View File

@ -19,6 +19,7 @@ export interface MetadataMarket extends Metadata {
}
export interface PriceOptionsMarket extends PriceOptions {
weightOnOcean: string
// easier to keep this as number for Yup input validation
swapFee: number
}

View File

@ -27,7 +27,11 @@ export default function Dynamic({
// Connect with form
const { values } = useFormikContext()
const { price, weightOnDataToken } = values as PriceOptionsMarket
const {
price,
weightOnDataToken,
weightOnOcean
} = values as PriceOptionsMarket
const [error, setError] = useState<string>()
@ -84,7 +88,7 @@ export default function Dynamic({
<Coin
name="oceanAmount"
datatokenOptions={{ symbol: 'OCEAN', name: 'Ocean Token' }}
weight={`${100 - Number(Number(weightOnDataToken) * 10)}%`}
weight={`${Number(weightOnOcean) * 10}%`}
/>
<Coin
name="dtAmount"

View File

@ -26,6 +26,7 @@ export default function FormPricing({
const {
price,
oceanAmount,
weightOnOcean,
weightOnDataToken,
type
} = values as PriceOptionsMarket
@ -38,13 +39,12 @@ export default function FormPricing({
// Always update everything when price value changes
useEffect(() => {
// with `weightOnDataToken` we assume it's measured against 1 OCEAN
const weightOnOcean = 1
const dtAmount =
(Number(oceanAmount) / weightOnOcean / price) * Number(weightOnDataToken)
(Number(oceanAmount) / Number(weightOnOcean) / price) *
Number(weightOnDataToken)
setFieldValue('dtAmount', dtAmount)
}, [price, oceanAmount, weightOnDataToken])
}, [price, oceanAmount, weightOnOcean, weightOnDataToken])
const tabs = [
{

View File

@ -11,6 +11,7 @@ export const validationSchema = Yup.object().shape<PriceOptionsMarket>({
.matches(/fixed|dynamic/g)
.required('Required'),
weightOnDataToken: Yup.string().required('Required'),
weightOnOcean: Yup.string().required('Required'),
swapFee: Yup.number()
.min(0.1, 'Must be more or equal to 0.1')
.max(10, 'Maximum is 10%')
@ -23,6 +24,7 @@ export const initialValues: PriceOptionsMarket = {
type: 'dynamic',
dtAmount: 9,
oceanAmount: 1,
weightOnDataToken: '9', // 90% on data token
weightOnOcean: '1', // 10% on OCEAN
weightOnDataToken: '9', // 90% on datatoken
swapFee: 0.1 // in %
}