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:
parent
257e572cc7
commit
04f3704f38
@ -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()
|
||||
|
@ -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),
|
||||
|
Loading…
Reference in New Issue
Block a user