Skip to content
This repository has been archived by the owner on Aug 3, 2021. It is now read-only.

Commit

Permalink
Merge pull request #82 from oceanprotocol/feature/getCheapestPool
Browse files Browse the repository at this point in the history
add getBestPool
  • Loading branch information
mihaisc authored Aug 18, 2020
2 parents ca05853 + 881057e commit 356ba79
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/hooks/useMetadata/useMetadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { useState, useEffect } from 'react'
import { DID, DDO, Metadata, MetadataStore, Logger } from '@oceanprotocol/lib'
import { useOcean } from '../../providers'
import ProviderStatus from '../../providers/OceanProvider/ProviderStatus'
import { getBestDataTokenPrice } from '../../utils/dtUtils'
import { getBestDataTokenPrice, getCheapestPool } from '../../utils/dtUtils'

interface UseMetadata {
ddo: DDO
Expand All @@ -12,6 +12,9 @@ interface UseMetadata {
getMetadata: (did: DID | string) => Promise<Metadata>
getTitle: (did: DID | string) => Promise<string>
getBestPrice: (dataTokenAddress: string) => Promise<string>
getBestPool: (
dataTokenAddress: string
) => Promise<{ poolAddress: string; poolPrice: string }>
}

function useMetadata(did?: DID | string): UseMetadata {
Expand All @@ -35,6 +38,11 @@ function useMetadata(did?: DID | string): UseMetadata {
async function getBestPrice(dataTokenAddress: string): Promise<string> {
return await getBestDataTokenPrice(ocean, accountId, dataTokenAddress)
}
async function getBestPool(
dataTokenAddress: string
): Promise<{ poolAddress: string; poolPrice: string }> {
return await getCheapestPool(ocean, accountId, dataTokenAddress)
}

async function getMetadata(did: DID | string): Promise<Metadata> {
const ddo = await getDDO(did)
Expand Down Expand Up @@ -68,7 +76,8 @@ function useMetadata(did?: DID | string): UseMetadata {
getDDO,
getMetadata,
getTitle,
getBestPrice
getBestPrice,
getBestPool
}
}

Expand Down

0 comments on commit 356ba79

Please sign in to comment.