diff --git a/src/components/atoms/Price/index.tsx b/src/components/atoms/Price/index.tsx index 96f2c2238..18082436f 100644 --- a/src/components/atoms/Price/index.tsx +++ b/src/components/atoms/Price/index.tsx @@ -24,17 +24,18 @@ export default function Price({ conversion={conversion} type={price.type} /> - ) : !price || !price.address || price.address === '' ? ( + ) : !price || price?.type === '' ? (
No price set{' '}
- ) : price.isConsumable !== 'true' ? ( -
- Low liquidity{' '} - -
) : ( + // TODO: Hacky hack, put back some check for low liquidity + // ) : price.isConsumable !== 'true' ? ( + //
+ // Low liquidity{' '} + // + //
) } diff --git a/src/hooks/usePricing.ts b/src/hooks/usePricing.ts index 59746a316..6dc06a99a 100644 --- a/src/hooks/usePricing.ts +++ b/src/hooks/usePricing.ts @@ -2,12 +2,10 @@ import { DDO, Logger, BestPrice } from '@oceanprotocol/lib' import { useEffect, useState } from 'react' import { TransactionReceipt } from 'web3-core' import { Decimal } from 'decimal.js' -import { getFirstPoolPrice } from '../utils/dtUtils' import { getCreatePricingPoolFeedback, getCreatePricingExchangeFeedback, - getBuyDTFeedback, - getSellDTFeedback + getBuyDTFeedback } from '../utils/feedback' import { sleep } from '../utils' @@ -29,7 +27,6 @@ interface UsePricing { createPricing: ( priceOptions: PriceOptions ) => Promise - sellDT: (dtAmount: number | string) => Promise mint: (tokensToMint: string) => Promise buyDT: ( dtAmount: number | string, @@ -72,7 +69,7 @@ function usePricing(ddo: DDO): UsePricing { }, [ocean, dataToken, dataTokenInfo]) // Helper for setting steps & feedback for all flows - function setStep(index: number, type: 'pool' | 'exchange' | 'buy' | 'sell') { + function setStep(index: number, type: 'pool' | 'exchange' | 'buy') { setPricingStep(index) if (!dtSymbol) return @@ -88,9 +85,6 @@ function usePricing(ddo: DDO): UsePricing { case 'buy': messages = getBuyDTFeedback(dtSymbol) break - case 'sell': - messages = getSellDTFeedback(dtSymbol) - break } setPricingStepText(messages[index]) @@ -193,45 +187,6 @@ function usePricing(ddo: DDO): UsePricing { return tx } - async function sellDT( - dtAmount: number | string - ): Promise { - if (!ocean || !accountId) return - - Decimal.set({ precision: 18 }) - if (!config.oceanTokenAddress) { - Logger.error(`'oceanTokenAddress' not set in config`) - return - } - - try { - setPricingIsLoading(true) - setPricingError(undefined) - setStep(1, 'sell') - const pool = await getFirstPoolPrice(ocean, dataToken) - if (!pool || pool.value === 0) return - const price = new Decimal(pool.value).times(0.95).toString() - setStep(2, 'sell') - Logger.log('Selling token to pool', pool, accountId, price) - const tx = await ocean.pool.sellDT( - accountId, - pool.address, - `${dtAmount}`, - price - ) - setStep(3, 'sell') - Logger.log('DT sell response', tx) - return tx - } catch (error) { - setPricingError(error.message) - Logger.error(error) - } finally { - setStep(0, 'sell') - setPricingStepText(undefined) - setPricingIsLoading(false) - } - } - async function createPricing( priceOptions: PriceOptions ): Promise { @@ -295,7 +250,6 @@ function usePricing(ddo: DDO): UsePricing { dtName, createPricing, buyDT, - sellDT, mint, pricingStep, pricingStepText, diff --git a/src/providers/Asset.tsx b/src/providers/Asset.tsx index 60612fc8b..927bbd077 100644 --- a/src/providers/Asset.tsx +++ b/src/providers/Asset.tsx @@ -193,7 +193,8 @@ function AssetProvider({ if (!ddo) return // Set price & metadata from DDO first - setPrice(ddo.price) + // TODO Hacky hack, temporary™: set isConsumable to true by default since Aquarius can't be trusted. + setPrice({ ...ddo.price, isConsumable: 'true' }) setVariables({ datatoken: ddo?.dataToken.toLowerCase() }) // Get metadata from DDO diff --git a/src/utils/dtUtils.ts b/src/utils/dtUtils.ts deleted file mode 100644 index ea9b49a5b..000000000 --- a/src/utils/dtUtils.ts +++ /dev/null @@ -1,93 +0,0 @@ -import { Ocean, BestPrice, Logger } from '@oceanprotocol/lib' - -const priceError: BestPrice = { - type: '', - address: '', - pools: [], - datatoken: 0, - value: 0, - isConsumable: '' -} - -export async function getFirstExchangePrice( - ocean: Ocean, - dataTokenAddress: string -): Promise { - try { - const tokenExchanges = await ocean.fixedRateExchange.searchforDT( - dataTokenAddress, - '1' - ) - if (tokenExchanges === undefined || tokenExchanges.length === 0) { - return priceError - } - - const [tokenExchange] = tokenExchanges - - return { - type: 'exchange', - pools: [], - address: tokenExchange.exchangeID || '', - value: Number(tokenExchange.fixedRate), - ocean: 0, - datatoken: Number(tokenExchange.supply), - isConsumable: Number(tokenExchange.supply) > 0 ? 'true' : 'false' - } - } catch (err) { - Logger.log(err) - return priceError - } -} - -export async function getFirstPoolPrice( - ocean: Ocean, - dataTokenAddress: string, - poolAddress?: string -): Promise { - let firstPoolAddress = poolAddress - if (!poolAddress) { - const tokenPools = await ocean.pool.searchPoolforDT(dataTokenAddress) - - if (tokenPools === undefined || tokenPools.length === 0) { - return priceError - } - ;[firstPoolAddress] = tokenPools - } - - if (!firstPoolAddress) return priceError - - const firstPoolPrice = await ocean.pool.calcInGivenOut( - firstPoolAddress, - ocean.pool.oceanAddress, - dataTokenAddress, - '1' - ) - const usePrice = await ocean.pool.getOceanNeeded(firstPoolAddress, '1') - const oceanReserve = await ocean.pool.getOceanReserve(firstPoolAddress) - - const dtReserve = await ocean.pool.getDTReserve(firstPoolAddress) - - return { - type: 'pool', - pools: [firstPoolAddress], - address: firstPoolAddress, - value: Number(firstPoolPrice), - ocean: Number(oceanReserve), - datatoken: Number(dtReserve), - isConsumable: Number(usePrice) > 0 ? 'true' : 'false' - } -} - -export async function getDataTokenPrice( - ocean: Ocean, - dataTokenAddress: string, - type: string, - poolAddress?: string -): Promise { - const price = - type === 'pool' - ? await getFirstPoolPrice(ocean, dataTokenAddress, poolAddress) - : await getFirstExchangePrice(ocean, dataTokenAddress) - - return price -}