From 04f3704f38aa4747609432c7da2c03df3ce92398 Mon Sep 17 00:00:00 2001 From: mihaisc Date: Tue, 1 Dec 2020 19:35:06 +0200 Subject: [PATCH] fix exchange price Signed-off-by: mihaisc --- src/hooks/usePricing/usePricing.ts | 13 ++++++++++--- src/utils/dtUtils.ts | 4 ++-- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/hooks/usePricing/usePricing.ts b/src/hooks/usePricing/usePricing.ts index 7cd5ec1..8d58c56 100644 --- a/src/hooks/usePricing/usePricing.ts +++ b/src/hooks/usePricing/usePricing.ts @@ -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() diff --git a/src/utils/dtUtils.ts b/src/utils/dtUtils.ts index 1fbf43a..0e373de 100644 --- a/src/utils/dtUtils.ts +++ b/src/utils/dtUtils.ts @@ -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),