From bf31cdfed59921391f0884eeb87788e5fced90ed Mon Sep 17 00:00:00 2001 From: mihaisc Date: Wed, 18 May 2022 09:25:44 -0700 Subject: [PATCH 1/2] Various fixes (#1441) * fixes * more fixes --- src/@context/MarketMetadata/index.tsx | 2 +- src/@context/Pool/index.tsx | 8 +++---- .../Asset/AssetActions/Pool/Remove/index.tsx | 4 ++++ .../AssetActions/Pool/Sections/index.tsx | 23 +++++++++++++++---- 4 files changed, 27 insertions(+), 10 deletions(-) diff --git a/src/@context/MarketMetadata/index.tsx b/src/@context/MarketMetadata/index.tsx index 85dde0450..209fac7c0 100644 --- a/src/@context/MarketMetadata/index.tsx +++ b/src/@context/MarketMetadata/index.tsx @@ -38,7 +38,7 @@ function MarketMetadataProvider({ chainId: appConfig.chainIdsSupported[i], approvedTokens: response.data?.opc.approvedTokens, swapApprovedFee: response.data?.opc.swapOceanFee, - swapNotApprovedFee: response.data.opc.swapNonOceanFee + swapNotApprovedFee: response.data?.opc.swapNonOceanFee } as OpcFee) } setOpcFees(opcData) diff --git a/src/@context/Pool/index.tsx b/src/@context/Pool/index.tsx index cc78e11f1..f17933321 100644 --- a/src/@context/Pool/index.tsx +++ b/src/@context/Pool/index.tsx @@ -67,10 +67,10 @@ function PoolProvider({ children }: { children: ReactNode }): ReactElement { poolInfoShares ) - // Pool share in %. + // Pool share in %. We double it to compensate for ss bot const poolSharePercentage = new Decimal(poolInfoShares) .dividedBy(new Decimal(response.poolData.totalShares)) - .mul(100) + .mul(200) .toFixed(2) setUserHasAddedLiquidity(Number(poolSharePercentage) > 0) @@ -143,10 +143,10 @@ function PoolProvider({ children }: { children: ReactNode }): ReactElement { ) return - // Pool share tokens. + // Pool share tokens. We double it to compensate for ss bot const poolSharePercentage = new Decimal(poolData.shares[0]?.shares) .dividedBy(poolInfo.totalPoolTokens) - .mul(100) + .mul(200) .toFixed(2) const ownerLiquidity = calcSingleOutGivenPoolIn( diff --git a/src/components/Asset/AssetActions/Pool/Remove/index.tsx b/src/components/Asset/AssetActions/Pool/Remove/index.tsx index 6fc190da2..66da99969 100644 --- a/src/components/Asset/AssetActions/Pool/Remove/index.tsx +++ b/src/components/Asset/AssetActions/Pool/Remove/index.tsx @@ -87,6 +87,10 @@ export default function Remove({ const getValues = useRef( debounce(async (poolInstance, id, poolInfo, newAmountPoolShares) => { + if (newAmountPoolShares === '0') { + setAmountOcean('0') + return + } const newAmountOcean = await poolInstance.calcSingleOutGivenPoolIn( id, poolInfo.baseTokenAddress, diff --git a/src/components/Asset/AssetActions/Pool/Sections/index.tsx b/src/components/Asset/AssetActions/Pool/Sections/index.tsx index 014efea4c..50954298e 100644 --- a/src/components/Asset/AssetActions/Pool/Sections/index.tsx +++ b/src/components/Asset/AssetActions/Pool/Sections/index.tsx @@ -3,7 +3,7 @@ import { usePool } from '@context/Pool' import Tooltip from '@shared/atoms/Tooltip' import ExplorerLink from '@shared/ExplorerLink' import PriceUnit from '@shared/Price/PriceUnit' -import React from 'react' +import React, { useEffect, useState } from 'react' import Graph from '../Graph' import PoolSection from '../Section' import Token from '../../../../@shared/Token' @@ -11,11 +11,27 @@ import content from '../../../../../../content/price.json' import styles from './index.module.css' import Update from './Update' import { useMarketMetadata } from '@context/MarketMetadata' +import { OpcFeesQuery_opc as OpcFeesData } from '../../../../../@types/subgraph/OpcFeesQuery' +import { getOpcFees } from '@utils/subgraph' +import { useWeb3 } from '@context/Web3' +import Decimal from 'decimal.js' export default function PoolSections() { const { asset } = useAsset() const { poolData, poolInfo, poolInfoUser, poolInfoOwner } = usePool() const { getOpcFeeForToken } = useMarketMetadata() + const { chainId } = useWeb3() + const [oceanCommunitySwapFee, setOceanCommunitySwapFee] = useState('') + useEffect(() => { + getOpcFees(chainId || 1).then((response: OpcFeesData) => { + setOceanCommunitySwapFee( + response?.swapOceanFee + ? new Decimal(response.swapOceanFee).mul(100).toString() + : '0' + ) + }) + }, [chainId]) + return ( <> @@ -119,10 +135,7 @@ export default function PoolSections() { /> From f0b22ee8e42e917a017170a6605c41ccedcc3e2a Mon Sep 17 00:00:00 2001 From: Bogdan Fazakas Date: Thu, 19 May 2022 19:48:13 +0300 Subject: [PATCH 2/2] fix forever timeout for assets (#1445) --- src/@utils/accessDetailsAndPricing.ts | 11 ++++------- src/components/Asset/AssetActions/Download.tsx | 6 +++--- 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/src/@utils/accessDetailsAndPricing.ts b/src/@utils/accessDetailsAndPricing.ts index dbdb5c38b..1d718d6be 100644 --- a/src/@utils/accessDetailsAndPricing.ts +++ b/src/@utils/accessDetailsAndPricing.ts @@ -152,14 +152,11 @@ function getAccessDetailsFromTokenPrice( timeout?: number ): AccessDetails { const accessDetails = {} as AccessDetails - if ( - tokenPrice && - timeout && - tokenPrice.orders && - tokenPrice.orders.length > 0 - ) { + if (tokenPrice && tokenPrice.orders && tokenPrice.orders.length > 0) { const order = tokenPrice.orders[0] - accessDetails.isOwned = Date.now() / 1000 - order.createdTimestamp < timeout + // asset is owned if there is an order and asset has timeout 0 (forever) or if the condition is valid + accessDetails.isOwned = + timeout === 0 || Date.now() / 1000 - order.createdTimestamp < timeout accessDetails.validOrderTx = order.tx } diff --git a/src/components/Asset/AssetActions/Download.tsx b/src/components/Asset/AssetActions/Download.tsx index 1ab7e10fa..a63fb5996 100644 --- a/src/components/Asset/AssetActions/Download.tsx +++ b/src/components/Asset/AssetActions/Download.tsx @@ -53,8 +53,9 @@ export default function Download({ useEffect(() => { if (!asset?.accessDetails) return - setIsOwned(asset?.accessDetails?.isOwned) - setValidOrderTx(asset?.accessDetails?.validOrderTx) + asset?.accessDetails?.isOwned && setIsOwned(asset?.accessDetails?.isOwned) + asset?.accessDetails?.validOrderTx && + setValidOrderTx(asset?.accessDetails?.validOrderTx) // get full price and fees async function init() { @@ -166,7 +167,6 @@ export default function Download({ if (!orderTx) { throw new Error() } - setIsOwned(true) setValidOrderTx(orderTx.transactionHash) }