1
0
mirror of https://github.com/oceanprotocol/market.git synced 2024-12-02 05:57:29 +01:00

merge v4 into v4-c2d

This commit is contained in:
Bogdan Fazakas 2022-05-20 08:20:49 +03:00
commit ea6a350796
6 changed files with 34 additions and 20 deletions

View File

@ -38,7 +38,7 @@ function MarketMetadataProvider({
chainId: appConfig.chainIdsSupported[i], chainId: appConfig.chainIdsSupported[i],
approvedTokens: response.data?.opc.approvedTokens, approvedTokens: response.data?.opc.approvedTokens,
swapApprovedFee: response.data?.opc.swapOceanFee, swapApprovedFee: response.data?.opc.swapOceanFee,
swapNotApprovedFee: response.data.opc.swapNonOceanFee swapNotApprovedFee: response.data?.opc.swapNonOceanFee
} as OpcFee) } as OpcFee)
} }
setOpcFees(opcData) setOpcFees(opcData)

View File

@ -67,10 +67,10 @@ function PoolProvider({ children }: { children: ReactNode }): ReactElement {
poolInfoShares poolInfoShares
) )
// Pool share in %. // Pool share in %. We double it to compensate for ss bot
const poolSharePercentage = new Decimal(poolInfoShares) const poolSharePercentage = new Decimal(poolInfoShares)
.dividedBy(new Decimal(response.poolData.totalShares)) .dividedBy(new Decimal(response.poolData.totalShares))
.mul(100) .mul(200)
.toFixed(2) .toFixed(2)
setUserHasAddedLiquidity(Number(poolSharePercentage) > 0) setUserHasAddedLiquidity(Number(poolSharePercentage) > 0)
@ -143,10 +143,10 @@ function PoolProvider({ children }: { children: ReactNode }): ReactElement {
) )
return return
// Pool share tokens. // Pool share tokens. We double it to compensate for ss bot
const poolSharePercentage = new Decimal(poolData.shares[0]?.shares) const poolSharePercentage = new Decimal(poolData.shares[0]?.shares)
.dividedBy(poolInfo.totalPoolTokens) .dividedBy(poolInfo.totalPoolTokens)
.mul(100) .mul(200)
.toFixed(2) .toFixed(2)
const ownerLiquidity = calcSingleOutGivenPoolIn( const ownerLiquidity = calcSingleOutGivenPoolIn(

View File

@ -157,14 +157,11 @@ function getAccessDetailsFromTokenPrice(
timeout?: number timeout?: number
): AccessDetails { ): AccessDetails {
const accessDetails = {} as AccessDetails const accessDetails = {} as AccessDetails
if ( if (tokenPrice && tokenPrice.orders && tokenPrice.orders.length > 0) {
tokenPrice &&
timeout &&
tokenPrice.orders &&
tokenPrice.orders.length > 0
) {
const order = tokenPrice.orders[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 accessDetails.validOrderTx = order.tx
} }

View File

@ -53,8 +53,9 @@ export default function Download({
useEffect(() => { useEffect(() => {
if (!asset?.accessDetails) return if (!asset?.accessDetails) return
setIsOwned(asset?.accessDetails?.isOwned) asset?.accessDetails?.isOwned && setIsOwned(asset?.accessDetails?.isOwned)
setValidOrderTx(asset?.accessDetails?.validOrderTx) asset?.accessDetails?.validOrderTx &&
setValidOrderTx(asset?.accessDetails?.validOrderTx)
// get full price and fees // get full price and fees
async function init() { async function init() {
@ -166,7 +167,6 @@ export default function Download({
if (!orderTx) { if (!orderTx) {
throw new Error() throw new Error()
} }
setIsOwned(true) setIsOwned(true)
setValidOrderTx(orderTx.transactionHash) setValidOrderTx(orderTx.transactionHash)
} }

View File

@ -87,6 +87,10 @@ export default function Remove({
const getValues = useRef( const getValues = useRef(
debounce(async (poolInstance, id, poolInfo, newAmountPoolShares) => { debounce(async (poolInstance, id, poolInfo, newAmountPoolShares) => {
if (newAmountPoolShares === '0') {
setAmountOcean('0')
return
}
const newAmountOcean = await poolInstance.calcSingleOutGivenPoolIn( const newAmountOcean = await poolInstance.calcSingleOutGivenPoolIn(
id, id,
poolInfo.baseTokenAddress, poolInfo.baseTokenAddress,

View File

@ -3,7 +3,7 @@ import { usePool } from '@context/Pool'
import Tooltip from '@shared/atoms/Tooltip' import Tooltip from '@shared/atoms/Tooltip'
import ExplorerLink from '@shared/ExplorerLink' import ExplorerLink from '@shared/ExplorerLink'
import PriceUnit from '@shared/Price/PriceUnit' import PriceUnit from '@shared/Price/PriceUnit'
import React from 'react' import React, { useEffect, useState } from 'react'
import Graph from '../Graph' import Graph from '../Graph'
import PoolSection from '../Section' import PoolSection from '../Section'
import Token from '../../../../@shared/Token' import Token from '../../../../@shared/Token'
@ -11,11 +11,27 @@ import content from '../../../../../../content/price.json'
import styles from './index.module.css' import styles from './index.module.css'
import Update from './Update' import Update from './Update'
import { useMarketMetadata } from '@context/MarketMetadata' 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() { export default function PoolSections() {
const { asset } = useAsset() const { asset } = useAsset()
const { poolData, poolInfo, poolInfoUser, poolInfoOwner } = usePool() const { poolData, poolInfo, poolInfoUser, poolInfoOwner } = usePool()
const { getOpcFeeForToken } = useMarketMetadata() const { getOpcFeeForToken } = useMarketMetadata()
const { chainId } = useWeb3()
const [oceanCommunitySwapFee, setOceanCommunitySwapFee] = useState<string>('')
useEffect(() => {
getOpcFees(chainId || 1).then((response: OpcFeesData) => {
setOceanCommunitySwapFee(
response?.swapOceanFee
? new Decimal(response.swapOceanFee).mul(100).toString()
: '0'
)
})
}, [chainId])
return ( return (
<> <>
<PoolSection className={styles.dataToken}> <PoolSection className={styles.dataToken}>
@ -119,10 +135,7 @@ export default function PoolSections() {
/> />
<Token <Token
symbol="% OPC fee" symbol="% OPC fee"
balance={getOpcFeeForToken( balance={oceanCommunitySwapFee}
poolInfo?.baseTokenAddress,
asset?.chainId
)}
noIcon noIcon
size="mini" size="mini"
/> />