From cd8e38880690fe2ef6be93c99db23beca94b1de7 Mon Sep 17 00:00:00 2001 From: Norbi <37236152+KatunaNorbert@users.noreply.github.com> Date: Thu, 27 May 2021 17:39:02 +0300 Subject: [PATCH 1/4] fixed app crash (#629) Co-authored-by: Norbi --- src/components/organisms/AssetActions/Pool/Add/FormAdd.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/organisms/AssetActions/Pool/Add/FormAdd.tsx b/src/components/organisms/AssetActions/Pool/Add/FormAdd.tsx index 20c96755c..d36281249 100644 --- a/src/components/organisms/AssetActions/Pool/Add/FormAdd.tsx +++ b/src/components/organisms/AssetActions/Pool/Add/FormAdd.tsx @@ -90,7 +90,7 @@ export default function FormAdd({ amountMax, coin, poolAddress, - ocean.pool, + ocean?.pool, setNewPoolTokens, setNewPoolShare ]) From 29b644f4028297ff4ecc899d259ed4e51b4ab89f Mon Sep 17 00:00:00 2001 From: Dimo Dzhurenov Date: Mon, 31 May 2021 13:52:14 +0300 Subject: [PATCH 2/4] updated parameter (#635) --- src/components/organisms/AssetActions/Trade/FormTrade.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/organisms/AssetActions/Trade/FormTrade.tsx b/src/components/organisms/AssetActions/Trade/FormTrade.tsx index b41ab263c..f04bd5704 100644 --- a/src/components/organisms/AssetActions/Trade/FormTrade.tsx +++ b/src/components/organisms/AssetActions/Trade/FormTrade.tsx @@ -64,7 +64,7 @@ export default function FormTrade({ .required('Required') .nullable(), datatoken: Yup.number() - .max(maxDt, `Must be less or equal than ${maximumDt}`) + .max(maximumDt, (param) => `Must be less or equal than ${param.max}`) .min(0.00001, (param) => `Must be more or equal to ${param.min}`) .required('Required') .nullable(), From 94139f42b4c8417798ca3661bbfa998ef6b9ba89 Mon Sep 17 00:00:00 2001 From: Matthias Kretschmann Date: Mon, 31 May 2021 12:53:37 +0200 Subject: [PATCH 3/4] fix marketFeeAddress (#633) * fix marketFeeAddress * UseSiteMetadata typing fixes --- .../organisms/AssetActions/Compute/index.tsx | 6 ++-- .../organisms/AssetActions/Consume.tsx | 4 +-- src/hooks/useSiteMetadata.ts | 34 +++++++++++++++++-- 3 files changed, 37 insertions(+), 7 deletions(-) diff --git a/src/components/organisms/AssetActions/Compute/index.tsx b/src/components/organisms/AssetActions/Compute/index.tsx index aa7fa2bd2..80c392e85 100644 --- a/src/components/organisms/AssetActions/Compute/index.tsx +++ b/src/components/organisms/AssetActions/Compute/index.tsx @@ -54,7 +54,7 @@ export default function Compute({ dtBalance: string file: FileMetadata }): ReactElement { - const { marketFeeAddress } = useSiteMetadata() + const { appConfig } = useSiteMetadata() const { accountId } = useWeb3() const { ocean, account, config } = useOcean() const { price, type, ddo } = useAsset() @@ -296,7 +296,7 @@ export default function Compute({ ddo.id, computeService.index, computeAlgorithm, - marketFeeAddress, + appConfig.marketFeeAddress, undefined, false ) @@ -316,7 +316,7 @@ export default function Compute({ serviceAlgo.type, accountId, serviceAlgo.index, - marketFeeAddress, + appConfig.marketFeeAddress, undefined, false ) diff --git a/src/components/organisms/AssetActions/Consume.tsx b/src/components/organisms/AssetActions/Consume.tsx index 30ba32d08..034a89899 100644 --- a/src/components/organisms/AssetActions/Consume.tsx +++ b/src/components/organisms/AssetActions/Consume.tsx @@ -44,7 +44,7 @@ export default function Consume({ }): ReactElement { const { accountId } = useWeb3() const { ocean } = useOcean() - const { marketFeeAddress } = useSiteMetadata() + const { appConfig } = useSiteMetadata() const [hasPreviousOrder, setHasPreviousOrder] = useState(false) const [previousOrderId, setPreviousOrderId] = useState() const { isInPurgatory, price, type } = useAsset() @@ -131,7 +131,7 @@ export default function Consume({ ddo.id, ddo.dataToken, 'access', - marketFeeAddress, + appConfig.marketFeeAddress, previousOrderId ) setHasPreviousOrder(true) diff --git a/src/hooks/useSiteMetadata.ts b/src/hooks/useSiteMetadata.ts index 3abf2bbd4..0db181ea0 100644 --- a/src/hooks/useSiteMetadata.ts +++ b/src/hooks/useSiteMetadata.ts @@ -1,5 +1,35 @@ import { useStaticQuery, graphql } from 'gatsby' +interface UseSiteMetadata { + siteTitle: string + siteTagline: string + siteUrl: string + siteIcon: string + siteImage: { childImageSharp: { original: { src: string } } } + copyright: string + menu: { + name: string + link: string + }[] + warning: { + main: string + polygonPublish: string + } + announcement: { + main: string + polygon: string + } + appConfig: { + infuraProjectId: string + network: string + marketFeeAddress: string + currencies: string[] + portisId: string + allowFixedPricing: string + allowDynamicPricing: string + } +} + const query = graphql` query { site { @@ -53,10 +83,10 @@ const query = graphql` } ` -export function useSiteMetadata() { +export function useSiteMetadata(): UseSiteMetadata { const data = useStaticQuery(query) - const siteMeta = { + const siteMeta: UseSiteMetadata = { ...data.siteImage.edges[0].node.childContentJson.site, ...data.site.siteMetadata } From 88663d812ac4a5d49e1df5054865c2955b8997bb Mon Sep 17 00:00:00 2001 From: claudiaHash <49017601+claudiaHash@users.noreply.github.com> Date: Wed, 2 Jun 2021 12:14:54 +0300 Subject: [PATCH 4/4] Highest liquidity list based on subgraph (#512) * fetch pools from graph, fetch ddos for pools * WIP on displaying highest liquidity assets * loader added * check ddo state for each asset * data ordered by valueLocked, logger added * filter ddos for purgatory * verify ddo isConsumable price attribute * moved query into subgraph.ts * send did list, fix assets display * fixes on assets display * assets sorted by dids * get assets on correct order * get assets in correct order * loading assets fixes * correct order and loading, network overloaded * fixes on loading * fixed on network change, added loading * fixed on network change when no wallet connected, improved loading Co-authored-by: claudia.holhos Co-authored-by: Matthias Kretschmann Co-authored-by: Norbi --- src/components/pages/Home.tsx | 105 +++++++++++++++++++++++----------- src/providers/Ocean.tsx | 12 +++- src/utils/subgraph.ts | 35 +++++++++++- 3 files changed, 114 insertions(+), 38 deletions(-) diff --git a/src/components/pages/Home.tsx b/src/components/pages/Home.tsx index 93d70a964..dc801e637 100644 --- a/src/components/pages/Home.tsx +++ b/src/components/pages/Home.tsx @@ -12,19 +12,10 @@ import Button from '../atoms/Button' import Bookmarks from '../molecules/Bookmarks' import axios from 'axios' import { queryMetadata } from '../../utils/aquarius' +import { getHighestLiquidityDIDs } from '../../utils/subgraph' +import { DDO, Logger } from '@oceanprotocol/lib' import { useWeb3 } from '../../providers/Web3' -const queryHighest = { - page: 1, - offset: 9, - query: { - query_string: { - query: `(price.type:pool) -isInPurgatory:true` - } - }, - sort: { 'price.ocean': -1 } -} - const queryLatest = { page: 1, offset: 9, @@ -36,48 +27,99 @@ const queryLatest = { sort: { created: -1 } } +function sortElements(items: DDO[], sorted: string[]) { + items.sort(function (a, b) { + return sorted.indexOf(a.dataToken) - sorted.indexOf(b.dataToken) + }) + return items +} + function SectionQueryResult({ title, query, - action + action, + queryData }: { title: ReactElement | string query: SearchQuery action?: ReactElement + queryData?: string }) { const { config } = useOcean() const [result, setResult] = useState() - const { web3Loading } = useWeb3() + const [loading, setLoading] = useState() useEffect(() => { - if (!config?.metadataCacheUri || web3Loading) return + if (!config?.metadataCacheUri) return const source = axios.CancelToken.source() async function init() { - const result = await queryMetadata( - query, - config.metadataCacheUri, - source.token - ) - setResult(result) + try { + setLoading(true) + const result = await queryMetadata( + query, + config.metadataCacheUri, + source.token + ) + if (result.totalResults <= 15) { + const searchDIDs = queryData.split(' ') + const sortedAssets = sortElements(result.results, searchDIDs) + // We take more assets than we need from the subgraph (to make sure + // all the 9 assets with highest liquidity we need are in OceanDB) + // so we need to get rid of the surplus + const overflow = sortedAssets.length - 9 + sortedAssets.splice(sortedAssets.length - overflow, overflow) + result.results = sortedAssets + } + if (result.results.length === 0) return + setResult(result) + setLoading(false) + } catch (error) { + Logger.log(error.message) + } } init() return () => { source.cancel() } - }, [config?.metadataCacheUri, query, web3Loading]) + }, [query, config?.metadataCacheUri]) return (

{title}

- + {action && action}
) } export default function HomePage(): ReactElement { + const { config, loading } = useOcean() + const [queryAndDids, setQueryAndDids] = useState<[SearchQuery, string]>() + const { web3Loading, web3Provider } = useWeb3() + + useEffect(() => { + if (loading || (web3Loading && web3Provider)) return + getHighestLiquidityDIDs().then((results) => { + const queryHighest = { + page: 1, + offset: 15, + query: { + query_string: { + query: `(${results}) AND -isInPurgatory:true AND price.isConsumable:true`, + fields: ['dataToken'] + } + } + } + setQueryAndDids([queryHighest, results]) + }) + }, [config.subgraphUri, loading, web3Loading]) + return ( <> @@ -89,18 +131,13 @@ export default function HomePage(): ReactElement { - - Data sets and algorithms with pool → - - } - /> + {queryAndDids && ( + + )} Promise refreshBalance: () => Promise } @@ -53,27 +54,29 @@ function OceanProvider({ const [config, setConfig] = useState( initialConfig ) + const [loading, setLoading] = useState() // ----------------------------------- // Create Ocean instance // ----------------------------------- const connect = useCallback( async (newConfig?: ConfigHelperConfig | Config) => { + setLoading(true) try { const usedConfig = newConfig || config Logger.log('[ocean] Connecting Ocean...', usedConfig) - usedConfig.web3Provider = web3 || initialConfig.web3Provider if (newConfig) { - setConfig(usedConfig) + await setConfig(usedConfig) } if (usedConfig.web3Provider) { const newOcean = await Ocean.getInstance(usedConfig) - setOcean(newOcean) + await setOcean(newOcean) Logger.log('[ocean] Ocean instance created.', newOcean) } + setLoading(false) } catch (error) { Logger.error('[ocean] Error: ', error.message) } @@ -136,7 +139,9 @@ function OceanProvider({ } try { + setLoading(true) await connect(newConfig) + setLoading(false) } catch (error) { Logger.error('[ocean] Error: ', error.message) } @@ -152,6 +157,7 @@ function OceanProvider({ account, balance, config, + loading, connect, refreshBalance } as OceanProviderValue diff --git a/src/utils/subgraph.ts b/src/utils/subgraph.ts index c38df78a7..d48f3336e 100644 --- a/src/utils/subgraph.ts +++ b/src/utils/subgraph.ts @@ -10,7 +10,7 @@ import { AssetsFrePrice_fixedRateExchanges as AssetsFrePriceFixedRateExchanges } from '../@types/apollo/AssetsFrePrice' import { AssetPreviousOrder } from '../@types/apollo/AssetPreviousOrder' -import BigNumber from 'bignumber.js' +import web3 from 'web3' export interface PriceList { [key: string]: string @@ -86,6 +86,20 @@ const PreviousOrderQuery = gql` } } ` +const HighestLiquidityAssets = gql` + query HighestLiquidiyAssets { + pools(orderBy: valueLocked, orderDirection: desc, first: 15) { + id + consumePrice + spotPrice + tx + symbol + name + datatokenAddress + valueLocked + } + } +` async function fetchData( query: DocumentNode, @@ -298,3 +312,22 @@ export async function getAssetsBestPrices( return assetsWithPrice } + +export async function getHighestLiquidityDIDs(): Promise { + const didList: string[] = [] + const fetchedPools = await fetchData(HighestLiquidityAssets, null) + if (fetchedPools.data?.pools?.length === 0) return null + for (let i = 0; i < fetchedPools.data.pools.length; i++) { + if (!fetchedPools.data.pools[i].datatokenAddress) continue + const did = web3.utils + .toChecksumAddress(fetchedPools.data.pools[i].datatokenAddress) + .replace('0x', 'did:op:') + didList.push(did) + } + const searchDids = JSON.stringify(didList) + .replace(/,/g, ' ') + .replace(/"/g, '') + .replace(/(\[|\])/g, '') + .replace(/(did:op:)/g, '0x') + return searchDids +}