mirror of
https://github.com/oceanprotocol/market.git
synced 2024-12-02 05:57:29 +01:00
Fix/Fallback to subgraph price (#1959)
* wip use subgraph * add more fallbacks * fix checks * fix tests * fix teaser * fix build * add return type
This commit is contained in:
parent
1514e785f2
commit
ba17184cf8
@ -5,6 +5,7 @@ import {
|
|||||||
TokenPriceQuery_token as TokenPrice
|
TokenPriceQuery_token as TokenPrice
|
||||||
} from '../@types/subgraph/TokenPriceQuery'
|
} from '../@types/subgraph/TokenPriceQuery'
|
||||||
import {
|
import {
|
||||||
|
AssetPrice,
|
||||||
getErrorMessage,
|
getErrorMessage,
|
||||||
LoggerInstance,
|
LoggerInstance,
|
||||||
ProviderFees,
|
ProviderFees,
|
||||||
@ -179,7 +180,6 @@ export async function getOrderPriceAndFees(
|
|||||||
},
|
},
|
||||||
opcFee: '0'
|
opcFee: '0'
|
||||||
} as OrderPriceAndFees
|
} as OrderPriceAndFees
|
||||||
|
|
||||||
// fetch provider fee
|
// fetch provider fee
|
||||||
let initializeData
|
let initializeData
|
||||||
try {
|
try {
|
||||||
@ -255,3 +255,14 @@ export async function getAccessDetails(
|
|||||||
LoggerInstance.error('Error getting access details: ', error.message)
|
LoggerInstance.error('Error getting access details: ', error.message)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function getAvailablePrice(asset: AssetExtended): AssetPrice {
|
||||||
|
const price: AssetPrice = asset?.stats?.price?.value
|
||||||
|
? asset?.stats?.price
|
||||||
|
: {
|
||||||
|
value: Number(asset?.accessDetails?.price),
|
||||||
|
tokenSymbol: asset?.accessDetails?.baseToken?.symbol,
|
||||||
|
tokenAddress: asset?.accessDetails?.baseToken?.address
|
||||||
|
}
|
||||||
|
return price
|
||||||
|
}
|
||||||
|
@ -8,7 +8,7 @@ describe('@shared/AssetTeaser', () => {
|
|||||||
testRender(<AssetTeaser asset={asset} />)
|
testRender(<AssetTeaser asset={asset} />)
|
||||||
|
|
||||||
it('renders no pricing schema available', () => {
|
it('renders no pricing schema available', () => {
|
||||||
asset.stats.price = null
|
asset.accessDetails.type = 'NOT_SUPPORTED'
|
||||||
render(<AssetTeaser asset={asset} />)
|
render(<AssetTeaser asset={asset} />)
|
||||||
expect(screen.getByText('No pricing schema available')).toBeInTheDocument()
|
expect(screen.getByText('No pricing schema available')).toBeInTheDocument()
|
||||||
expect(screen.getByText('This is a test.')).toBeInTheDocument()
|
expect(screen.getByText('This is a test.')).toBeInTheDocument()
|
||||||
|
@ -10,6 +10,7 @@ import styles from './index.module.css'
|
|||||||
import { getServiceByName } from '@utils/ddo'
|
import { getServiceByName } from '@utils/ddo'
|
||||||
import { useUserPreferences } from '@context/UserPreferences'
|
import { useUserPreferences } from '@context/UserPreferences'
|
||||||
import { formatNumber } from '@utils/numbers'
|
import { formatNumber } from '@utils/numbers'
|
||||||
|
import { AssetPrice } from '@oceanprotocol/lib'
|
||||||
|
|
||||||
export declare type AssetTeaserProps = {
|
export declare type AssetTeaserProps = {
|
||||||
asset: AssetExtended
|
asset: AssetExtended
|
||||||
@ -31,7 +32,7 @@ export default function AssetTeaser({
|
|||||||
const { orders, allocated, price } = asset.stats
|
const { orders, allocated, price } = asset.stats
|
||||||
const isUnsupportedPricing =
|
const isUnsupportedPricing =
|
||||||
!asset.services.length ||
|
!asset.services.length ||
|
||||||
asset?.stats?.price?.value === undefined ||
|
price.value === undefined ||
|
||||||
asset?.accessDetails?.type === 'NOT_SUPPORTED'
|
asset?.accessDetails?.type === 'NOT_SUPPORTED'
|
||||||
const { locale } = useUserPreferences()
|
const { locale } = useUserPreferences()
|
||||||
|
|
||||||
|
@ -17,7 +17,6 @@ export default function Price({
|
|||||||
size?: 'small' | 'mini' | 'large'
|
size?: 'small' | 'mini' | 'large'
|
||||||
}): ReactElement {
|
}): ReactElement {
|
||||||
if (!price && !orderPriceAndFees) return
|
if (!price && !orderPriceAndFees) return
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<PriceUnit
|
<PriceUnit
|
||||||
price={Number(orderPriceAndFees?.price) || price?.value}
|
price={Number(orderPriceAndFees?.price) || price?.value}
|
||||||
|
@ -14,6 +14,7 @@ import {
|
|||||||
ProviderComputeInitializeResults,
|
ProviderComputeInitializeResults,
|
||||||
unitsToAmount,
|
unitsToAmount,
|
||||||
ProviderFees,
|
ProviderFees,
|
||||||
|
AssetPrice,
|
||||||
UserCustomParameters,
|
UserCustomParameters,
|
||||||
getErrorMessage
|
getErrorMessage
|
||||||
} from '@oceanprotocol/lib'
|
} from '@oceanprotocol/lib'
|
||||||
@ -41,7 +42,10 @@ import ComputeJobs from '../../../Profile/History/ComputeJobs'
|
|||||||
import { useCancelToken } from '@hooks/useCancelToken'
|
import { useCancelToken } from '@hooks/useCancelToken'
|
||||||
import { Decimal } from 'decimal.js'
|
import { Decimal } from 'decimal.js'
|
||||||
import { useAbortController } from '@hooks/useAbortController'
|
import { useAbortController } from '@hooks/useAbortController'
|
||||||
import { getOrderPriceAndFees } from '@utils/accessDetailsAndPricing'
|
import {
|
||||||
|
getAvailablePrice,
|
||||||
|
getOrderPriceAndFees
|
||||||
|
} from '@utils/accessDetailsAndPricing'
|
||||||
import { handleComputeOrder } from '@utils/order'
|
import { handleComputeOrder } from '@utils/order'
|
||||||
import { getComputeFeedback } from '@utils/feedback'
|
import { getComputeFeedback } from '@utils/feedback'
|
||||||
import { initializeProviderForCompute } from '@utils/provider'
|
import { initializeProviderForCompute } from '@utils/provider'
|
||||||
@ -111,6 +115,8 @@ export default function Compute({
|
|||||||
const { isSupportedOceanNetwork } = useNetworkMetadata()
|
const { isSupportedOceanNetwork } = useNetworkMetadata()
|
||||||
const { isAssetNetwork } = useAsset()
|
const { isAssetNetwork } = useAsset()
|
||||||
|
|
||||||
|
const price: AssetPrice = getAvailablePrice(asset)
|
||||||
|
|
||||||
const hasDatatoken = Number(dtBalance) >= 1
|
const hasDatatoken = Number(dtBalance) >= 1
|
||||||
const isComputeButtonDisabled =
|
const isComputeButtonDisabled =
|
||||||
isOrdering === true ||
|
isOrdering === true ||
|
||||||
@ -489,7 +495,7 @@ export default function Compute({
|
|||||||
/>
|
/>
|
||||||
) : (
|
) : (
|
||||||
<Price
|
<Price
|
||||||
price={asset.stats?.price}
|
price={price}
|
||||||
orderPriceAndFees={datasetOrderPriceAndFees}
|
orderPriceAndFees={datasetOrderPriceAndFees}
|
||||||
conversion
|
conversion
|
||||||
size="large"
|
size="large"
|
||||||
|
@ -4,9 +4,10 @@ import Price from '@shared/Price'
|
|||||||
import { useAsset } from '@context/Asset'
|
import { useAsset } from '@context/Asset'
|
||||||
import ButtonBuy from '../ButtonBuy'
|
import ButtonBuy from '../ButtonBuy'
|
||||||
import { secondsToString } from '@utils/ddo'
|
import { secondsToString } from '@utils/ddo'
|
||||||
import AlgorithmDatasetsListForCompute from '../Compute/AlgorithmDatasetsListForCompute'
|
|
||||||
import styles from './index.module.css'
|
import styles from './index.module.css'
|
||||||
|
import AlgorithmDatasetsListForCompute from '../Compute/AlgorithmDatasetsListForCompute'
|
||||||
import {
|
import {
|
||||||
|
AssetPrice,
|
||||||
FileInfo,
|
FileInfo,
|
||||||
LoggerInstance,
|
LoggerInstance,
|
||||||
UserCustomParameters,
|
UserCustomParameters,
|
||||||
@ -15,7 +16,10 @@ import {
|
|||||||
import { order } from '@utils/order'
|
import { order } from '@utils/order'
|
||||||
import { downloadFile } from '@utils/provider'
|
import { downloadFile } from '@utils/provider'
|
||||||
import { getOrderFeedback } from '@utils/feedback'
|
import { getOrderFeedback } from '@utils/feedback'
|
||||||
import { getOrderPriceAndFees } from '@utils/accessDetailsAndPricing'
|
import {
|
||||||
|
getAvailablePrice,
|
||||||
|
getOrderPriceAndFees
|
||||||
|
} from '@utils/accessDetailsAndPricing'
|
||||||
import { toast } from 'react-toastify'
|
import { toast } from 'react-toastify'
|
||||||
import { useIsMounted } from '@hooks/useIsMounted'
|
import { useIsMounted } from '@hooks/useIsMounted'
|
||||||
import { useMarketMetadata } from '@context/MarketMetadata'
|
import { useMarketMetadata } from '@context/MarketMetadata'
|
||||||
@ -64,10 +68,10 @@ export default function Download({
|
|||||||
useState<OrderPriceAndFees>()
|
useState<OrderPriceAndFees>()
|
||||||
const [retry, setRetry] = useState<boolean>(false)
|
const [retry, setRetry] = useState<boolean>(false)
|
||||||
|
|
||||||
|
const price: AssetPrice = getAvailablePrice(asset)
|
||||||
const isUnsupportedPricing =
|
const isUnsupportedPricing =
|
||||||
!asset?.accessDetails ||
|
!asset?.accessDetails ||
|
||||||
!asset.services.length ||
|
!asset.services.length ||
|
||||||
asset?.stats?.price?.value === undefined ||
|
|
||||||
asset?.accessDetails?.type === 'NOT_SUPPORTED' ||
|
asset?.accessDetails?.type === 'NOT_SUPPORTED' ||
|
||||||
(asset?.accessDetails?.type === 'fixed' &&
|
(asset?.accessDetails?.type === 'fixed' &&
|
||||||
!asset?.accessDetails?.baseToken?.symbol)
|
!asset?.accessDetails?.baseToken?.symbol)
|
||||||
@ -287,7 +291,7 @@ export default function Download({
|
|||||||
) : (
|
) : (
|
||||||
<Price
|
<Price
|
||||||
className={styles.price}
|
className={styles.price}
|
||||||
price={asset.stats?.price}
|
price={price}
|
||||||
orderPriceAndFees={orderPriceAndFees}
|
orderPriceAndFees={orderPriceAndFees}
|
||||||
conversion
|
conversion
|
||||||
size="large"
|
size="large"
|
||||||
|
Loading…
Reference in New Issue
Block a user