1
0
mirror of https://github.com/oceanprotocol/react.git synced 2025-02-03 23:57:29 +01:00

fix exchange price

Signed-off-by: mihaisc <mihai.scarlat@smartcontrol.ro>
This commit is contained in:
mihaisc 2020-12-01 19:35:06 +02:00
parent 257e572cc7
commit 04f3704f38
No known key found for this signature in database
GPG Key ID: 4FB0C2329B4C6E29
2 changed files with 12 additions and 5 deletions

View File

@ -5,13 +5,14 @@ import { PriceOptions } from './PriceOptions'
import { TransactionReceipt } from 'web3-core'
import { Decimal } from 'decimal.js'
import {
getBestDataTokenPrice,
getFirstPoolPrice,
getCreatePricingPoolFeedback,
getCreatePricingExchangeFeedback,
getBuyDTFeedback,
getSellDTFeedback,
sleep
sleep,
getDataTokenPrice,
getBestDataTokenPrice
} from 'utils'
interface UsePricing {
@ -113,8 +114,14 @@ function usePricing(ddo: DDO): UsePricing {
setPricingIsLoading(true)
setPricingError(undefined)
setStep(1, 'buy')
const bestPrice = await getBestDataTokenPrice(ocean, dataToken)
const bestPrice = await await getDataTokenPrice(
ocean,
ddo.dataToken,
ddo?.price?.type,
ddo.price.address
)
Logger.log('Price found for buying', bestPrice)
switch (bestPrice?.type) {
case 'pool': {
const price = new Decimal(bestPrice.value).times(1.05).toString()

View File

@ -87,7 +87,7 @@ export async function getCheapestExchangePrice(
? await ocean.fixedRateExchange.getSupply(cheapestExchangeAddress)
: '0'
return {
type: 'pool',
type: 'exchange',
pools: [],
address: cheapestExchangeAddress || '',
value: Number(cheapestExchangePrice),
@ -131,7 +131,7 @@ export async function getFirstExchangePrice(
const [tokenExchange] = tokenExchanges
return {
type: 'pool',
type: 'exchange',
pools: [],
address: tokenExchange.exchangeID || '',
value: Number(tokenExchange.fixedRate),