mirror of
https://github.com/oceanprotocol/react.git
synced 2025-02-09 02:47:22 +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 { TransactionReceipt } from 'web3-core'
|
||||||
import { Decimal } from 'decimal.js'
|
import { Decimal } from 'decimal.js'
|
||||||
import {
|
import {
|
||||||
getBestDataTokenPrice,
|
|
||||||
getFirstPoolPrice,
|
getFirstPoolPrice,
|
||||||
getCreatePricingPoolFeedback,
|
getCreatePricingPoolFeedback,
|
||||||
getCreatePricingExchangeFeedback,
|
getCreatePricingExchangeFeedback,
|
||||||
getBuyDTFeedback,
|
getBuyDTFeedback,
|
||||||
getSellDTFeedback,
|
getSellDTFeedback,
|
||||||
sleep
|
sleep,
|
||||||
|
getDataTokenPrice,
|
||||||
|
getBestDataTokenPrice
|
||||||
} from 'utils'
|
} from 'utils'
|
||||||
|
|
||||||
interface UsePricing {
|
interface UsePricing {
|
||||||
@ -113,8 +114,14 @@ function usePricing(ddo: DDO): UsePricing {
|
|||||||
setPricingIsLoading(true)
|
setPricingIsLoading(true)
|
||||||
setPricingError(undefined)
|
setPricingError(undefined)
|
||||||
setStep(1, 'buy')
|
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) {
|
switch (bestPrice?.type) {
|
||||||
case 'pool': {
|
case 'pool': {
|
||||||
const price = new Decimal(bestPrice.value).times(1.05).toString()
|
const price = new Decimal(bestPrice.value).times(1.05).toString()
|
||||||
|
@ -87,7 +87,7 @@ export async function getCheapestExchangePrice(
|
|||||||
? await ocean.fixedRateExchange.getSupply(cheapestExchangeAddress)
|
? await ocean.fixedRateExchange.getSupply(cheapestExchangeAddress)
|
||||||
: '0'
|
: '0'
|
||||||
return {
|
return {
|
||||||
type: 'pool',
|
type: 'exchange',
|
||||||
pools: [],
|
pools: [],
|
||||||
address: cheapestExchangeAddress || '',
|
address: cheapestExchangeAddress || '',
|
||||||
value: Number(cheapestExchangePrice),
|
value: Number(cheapestExchangePrice),
|
||||||
@ -131,7 +131,7 @@ export async function getFirstExchangePrice(
|
|||||||
const [tokenExchange] = tokenExchanges
|
const [tokenExchange] = tokenExchanges
|
||||||
|
|
||||||
return {
|
return {
|
||||||
type: 'pool',
|
type: 'exchange',
|
||||||
pools: [],
|
pools: [],
|
||||||
address: tokenExchange.exchangeID || '',
|
address: tokenExchange.exchangeID || '',
|
||||||
value: Number(tokenExchange.fixedRate),
|
value: Number(tokenExchange.fixedRate),
|
||||||
|
Loading…
Reference in New Issue
Block a user