1
0
mirror of https://github.com/oceanprotocol/react.git synced 2024-06-26 03:06:48 +02:00

Merge pull request #82 from oceanprotocol/feature/getCheapestPool

add getBestPool
This commit is contained in:
mihaisc 2020-08-18 13:17:04 +03:00 committed by GitHub
commit 356ba797c1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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
@ -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 {
@ -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)
@ -68,7 +76,8 @@ function useMetadata(did?: DID | string): UseMetadata {
getDDO,
getMetadata,
getTitle,
getBestPrice
getBestPrice,
getBestPool
}
}