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 b18a7f0cd..a67ee20a7 100644 --- a/src/hooks/usePricing.ts +++ b/src/hooks/usePricing.ts @@ -2,12 +2,10 @@ import { DDO, Logger, BestPrice } from '@oceanprotocol/lib' import { 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' @@ -30,10 +28,6 @@ interface UsePricing { priceOptions: PriceOptions, ddo: DDO ) => Promise - sellDT: ( - dtAmount: number | string, - ddo: DDO - ) => Promise mint: (tokensToMint: string, ddo: DDO) => Promise buyDT: ( dtAmount: number | string, @@ -56,6 +50,7 @@ function usePricing(): UsePricing { async function getDTSymbol(ddo: DDO): Promise { if (!ocean || !accountId) return + const { dataToken, dataTokenInfo } = ddo return dataTokenInfo ? dataTokenInfo.symbol @@ -73,7 +68,7 @@ function usePricing(): UsePricing { // Helper for setting steps & feedback for all flows async function setStep( index: number, - type: 'pool' | 'exchange' | 'buy' | 'sell', + type: 'pool' | 'exchange' | 'buy', ddo: DDO ) { const dtSymbol = await getDTSymbol(ddo) @@ -92,9 +87,6 @@ function usePricing(): UsePricing { case 'buy': messages = getBuyDTFeedback(dtSymbol) break - case 'sell': - messages = getSellDTFeedback(dtSymbol) - break } setPricingStepText(messages[index]) @@ -201,47 +193,6 @@ function usePricing(): UsePricing { return tx } - async function sellDT( - dtAmount: number | string, - ddo: DDO - ): Promise { - if (!ocean || !accountId) return - - Decimal.set({ precision: 18 }) - if (!config.oceanTokenAddress) { - Logger.error(`'oceanTokenAddress' not set in config`) - return - } - - try { - const { dataToken } = ddo - setPricingIsLoading(true) - setPricingError(undefined) - setStep(1, 'sell', ddo) - 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', ddo) - Logger.log('Selling token to pool', pool, accountId, price) - const tx = await ocean.pool.sellDT( - accountId, - pool.address, - `${dtAmount}`, - price - ) - setStep(3, 'sell', ddo) - Logger.log('DT sell response', tx) - return tx - } catch (error) { - setPricingError(error.message) - Logger.error(error) - } finally { - setStep(0, 'sell', ddo) - setPricingStepText(undefined) - setPricingIsLoading(false) - } - } - async function createPricing( priceOptions: PriceOptions, ddo: DDO @@ -309,7 +260,6 @@ function usePricing(): UsePricing { getDTName, createPricing, buyDT, - sellDT, mint, pricingStep, pricingStepText, diff --git a/src/providers/Asset.tsx b/src/providers/Asset.tsx index 66984652c..0f336cc6a 100644 --- a/src/providers/Asset.tsx +++ b/src/providers/Asset.tsx @@ -197,7 +197,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/providers/Web3.tsx b/src/providers/Web3.tsx index a4364e60b..695212fab 100644 --- a/src/providers/Web3.tsx +++ b/src/providers/Web3.tsx @@ -112,11 +112,13 @@ function Web3Provider({ children }: { children: ReactNode }): ReactElement { const [block, setBlock] = useState() const [isTestnet, setIsTestnet] = useState() const [accountId, setAccountId] = useState() - const [web3Loading, setWeb3Loading] = useState() + const [web3Loading, setWeb3Loading] = useState(true) const connect = useCallback(async () => { - if (!web3Modal) return - + if (!web3Modal) { + setWeb3Loading(false) + return + } try { setWeb3Loading(true) Logger.log('[web3] Connecting Web3...') 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 -}