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

Fix order and price (#1375)

* fix loading

Signed-off-by: mihaisc <mihai.scarlat@smartcontrol.ro>

* add order fee

Signed-off-by: mihaisc <mihai.scarlat@smartcontrol.ro>

* fix opc

Signed-off-by: mihaisc <mihai.scarlat@smartcontrol.ro>

* remove cache from urql

Signed-off-by: mihaisc <mihai.scarlat@smartcontrol.ro>

* update urlq dep

Signed-off-by: mihaisc <mihai.scarlat@smartcontrol.ro>

* update urlq dep

Signed-off-by: mihaisc <mihai.scarlat@smartcontrol.ro>

* fix lock

Signed-off-by: mihaisc <mihai.scarlat@smartcontrol.ro>

* fix states

Signed-off-by: mihaisc <mihai.scarlat@smartcontrol.ro>
This commit is contained in:
mihaisc 2022-04-29 22:14:14 +03:00 committed by GitHub
parent 97744820ac
commit 2107eab979
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 3878 additions and 5265 deletions

9068
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -11,7 +11,6 @@ export const poolDataQuery = gql`
id id
totalShares totalShares
liquidityProviderSwapFee liquidityProviderSwapFee
opcFee
publishMarketSwapFee publishMarketSwapFee
spotPrice spotPrice
baseToken { baseToken {

View File

@ -6,7 +6,6 @@ import {
export interface PoolInfo { export interface PoolInfo {
liquidityProviderSwapFee: string liquidityProviderSwapFee: string
publishMarketSwapFee: string publishMarketSwapFee: string
opcFee: string
weightBaseToken: string weightBaseToken: string
weightDt: string weightDt: string
datatokenSymbol: string datatokenSymbol: string

View File

@ -2,7 +2,6 @@ import {
createClient, createClient,
Provider, Provider,
Client, Client,
cacheExchange,
dedupExchange, dedupExchange,
fetchExchange fetchExchange
} from 'urql' } from 'urql'
@ -16,7 +15,7 @@ let urqlClient: Client
function createUrqlClient(subgraphUri: string) { function createUrqlClient(subgraphUri: string) {
const client = createClient({ const client = createClient({
url: `${subgraphUri}/subgraphs/name/oceanprotocol/ocean-subgraph`, url: `${subgraphUri}/subgraphs/name/oceanprotocol/ocean-subgraph`,
exchanges: [dedupExchange, refocusExchange(), cacheExchange, fetchExchange] exchanges: [dedupExchange, refocusExchange(), fetchExchange]
}) })
return client return client
} }

View File

@ -22,6 +22,9 @@ const TokensPriceQuery = gql`
id id
symbol symbol
name name
publishMarketFeeAddress
publishMarketFeeToken
publishMarketFeeAmount
orders( orders(
where: { consumer: $account } where: { consumer: $account }
orderBy: createdTimestamp orderBy: createdTimestamp
@ -46,6 +49,7 @@ const TokensPriceQuery = gql`
id id
exchangeId exchangeId
price price
publishMarketSwapFee
baseToken { baseToken {
symbol symbol
name name
@ -83,6 +87,9 @@ const TokenPriceQuery = gql`
id id
symbol symbol
name name
publishMarketFeeAddress
publishMarketFeeToken
publishMarketFeeAmount
orders( orders(
where: { consumer: $account } where: { consumer: $account }
orderBy: createdTimestamp orderBy: createdTimestamp
@ -107,6 +114,7 @@ const TokenPriceQuery = gql`
id id
exchangeId exchangeId
price price
publishMarketSwapFee
baseToken { baseToken {
symbol symbol
name name
@ -139,7 +147,6 @@ const TokenPriceQuery = gql`
} }
` `
// TODO: fill in fees after subgraph update
function getAccessDetailsFromTokenPrice( function getAccessDetailsFromTokenPrice(
tokenPrice: TokenPrice | TokensPrice, tokenPrice: TokenPrice | TokensPrice,
timeout?: number timeout?: number
@ -157,7 +164,7 @@ function getAccessDetailsFromTokenPrice(
} }
// TODO: fetch order fee from sub query // TODO: fetch order fee from sub query
accessDetails.publisherMarketOrderFee = '0' accessDetails.publisherMarketOrderFee = tokenPrice.publishMarketFeeAmount
// free is always the best price // free is always the best price
if (tokenPrice.dispensers && tokenPrice.dispensers.length > 0) { if (tokenPrice.dispensers && tokenPrice.dispensers.length > 0) {
@ -256,7 +263,6 @@ export async function getOrderPriceAndFees(
asset?.services[0].serviceEndpoint asset?.services[0].serviceEndpoint
) )
orderPriceAndFee.providerFee = initializeData.providerFee orderPriceAndFee.providerFee = initializeData.providerFee
if (!orderPriceAndFee.providerFee) return
// fetch price and swap fees // fetch price and swap fees
switch (asset?.accessDetails?.type) { switch (asset?.accessDetails?.type) {

View File

@ -61,37 +61,43 @@ export default function Download({
if ( if (
asset?.accessDetails?.addressOrId === ZERO_ADDRESS || asset?.accessDetails?.addressOrId === ZERO_ADDRESS ||
asset?.accessDetails?.type === 'free' || asset?.accessDetails?.type === 'free' ||
(!poolData && asset?.accessDetails?.type === 'dynamic') (!poolData && asset?.accessDetails?.type === 'dynamic') ||
isLoading
) )
return return
const params: CalcInGivenOutParams = { !orderPriceAndFees && setIsLoading(true)
setStatusText('Refreshing price')
// this is needed just for pool
const paramsForPool: CalcInGivenOutParams = {
tokenInLiquidity: poolData?.baseTokenLiquidity, tokenInLiquidity: poolData?.baseTokenLiquidity,
tokenOutLiquidity: poolData?.datatokenLiquidity, tokenOutLiquidity: poolData?.datatokenLiquidity,
tokenOutAmount: '1', tokenOutAmount: '1',
opcFee: getOpcFeeForToken( opcFee: getOpcFeeForToken(
poolData?.baseToken?.address || asset?.accessDetails?.addressOrId, asset?.accessDetails?.baseToken.address,
asset?.chainId asset?.chainId
), ),
lpSwapFee: poolData?.liquidityProviderSwapFee, lpSwapFee: poolData?.liquidityProviderSwapFee,
publishMarketSwapFee: poolData?.publishMarketSwapFee, publishMarketSwapFee: asset?.accessDetails?.publisherMarketOrderFee,
consumeMarketSwapFee: '0' consumeMarketSwapFee: '0'
} }
const _orderPriceAndFees = await getOrderPriceAndFees(
const orderPriceAndFees = await getOrderPriceAndFees(
asset, asset,
ZERO_ADDRESS, ZERO_ADDRESS,
params paramsForPool
) )
setOrderPriceAndFees(orderPriceAndFees) setOrderPriceAndFees(_orderPriceAndFees)
!orderPriceAndFees && setIsLoading(false)
} }
init() init()
/** /**
* we listen to the assets' changes to get the most updated price * we listen to the assets' changes to get the most updated price
* based on the asset and the poolData's information * based on the asset and the poolData's information.
* Not adding isLoading and getOpcFeeForToken because we set these here. It is a compromise
*/ */
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [asset, accountId, poolData, getOpcFeeForToken]) }, [asset, accountId, poolData, getOpcFeeForToken])
useEffect(() => { useEffect(() => {

View File

@ -10,11 +10,12 @@ import Token from '../../../../@shared/Token'
import content from '../../../../../../content/price.json' 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'
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()
return ( return (
<> <>
<PoolSection className={styles.dataToken}> <PoolSection className={styles.dataToken}>
@ -118,7 +119,10 @@ export default function PoolSections() {
/> />
<Token <Token
symbol="% OPC fee" symbol="% OPC fee"
balance={poolInfo?.opcFee} balance={getOpcFeeForToken(
poolInfo?.baseTokenAddress,
asset?.chainId
)}
noIcon noIcon
size="mini" size="mini"
/> />