Skip to content

Commit

Permalink
fix merge conflicts and duplications
Browse files Browse the repository at this point in the history
  • Loading branch information
bogdanfazakas committed Oct 16, 2023
2 parents b60f343 + 1514e78 commit 0d585b6
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 40 deletions.
12 changes: 12 additions & 0 deletions src/@utils/accessDetailsAndPricing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
TokenPriceQuery_token as TokenPrice
} from '../@types/subgraph/TokenPriceQuery'
import {
AssetPrice,
getErrorMessage,
LoggerInstance,
ProviderFees,
Expand Down Expand Up @@ -254,3 +255,14 @@ export async function getAccessDetails(
LoggerInstance.error('Error getting access details: ', error.message)
}
}

export function getAvailablePrice(asset: AssetExtended) {
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
}
5 changes: 4 additions & 1 deletion src/@utils/assetConvertor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ export async function transformAssetToAssetSelection(
const algoService =
getServiceByName(asset, 'compute') || getServiceByName(asset, 'access')

if (algoService?.serviceEndpoint === datasetProviderEndpoint) {
if (
asset?.stats?.price?.value >= 0 &&
algoService?.serviceEndpoint === datasetProviderEndpoint
) {
let selected = false
selectedAlgorithms?.forEach((algorithm: PublisherTrustedAlgorithm) => {
if (algorithm.did === asset.id) {
Expand Down
33 changes: 12 additions & 21 deletions src/components/Asset/AssetActions/Compute/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,10 @@ import ComputeJobs from '../../../Profile/History/ComputeJobs'
import { useCancelToken } from '@hooks/useCancelToken'
import { Decimal } from 'decimal.js'
import { useAbortController } from '@hooks/useAbortController'
import { getOrderPriceAndFees } from '@utils/accessDetailsAndPricing'
import {
getAvailablePrice,
getOrderPriceAndFees
} from '@utils/accessDetailsAndPricing'
import { handleComputeOrder } from '@utils/order'
import { getComputeFeedback } from '@utils/feedback'
import { initializeProviderForCompute } from '@utils/provider'
Expand Down Expand Up @@ -112,13 +115,7 @@ export default function Compute({
const { isSupportedOceanNetwork } = useNetworkMetadata()
const { isAssetNetwork } = useAsset()

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
}
const price: AssetPrice = getAvailablePrice(asset)

const hasDatatoken = Number(dtBalance) >= 1
const isComputeButtonDisabled =
Expand Down Expand Up @@ -507,20 +504,14 @@ export default function Compute({
</div>

{isUnsupportedPricing ? null : asset.metadata.type === 'algorithm' ? (
<>
{asset.services[0].type === 'compute' && (
<Alert
text={
"This algorithm has been set to private by the publisher and can't be downloaded. You can run it against any allowed datasets though!"
}
state="info"
/>
)}
<AlgorithmDatasetsListForCompute
algorithmDid={asset.id}
asset={asset}
asset.services[0].type === 'compute' && (
<Alert
text={
"This algorithm has been set to private by the publisher and can't be downloaded. You can run it against any allowed datasets though!"
}
state="info"
/>
</>
)
) : (
<Formik
initialValues={getInitialValues(asset, selectedAlgorithmAsset)}
Expand Down
16 changes: 6 additions & 10 deletions src/components/Asset/AssetActions/Download/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ import {
import { order } from '@utils/order'
import { downloadFile } from '@utils/provider'
import { getOrderFeedback } from '@utils/feedback'
import { getOrderPriceAndFees } from '@utils/accessDetailsAndPricing'
import {
getAvailablePrice,
getOrderPriceAndFees
} from '@utils/accessDetailsAndPricing'
import { toast } from 'react-toastify'
import { useIsMounted } from '@hooks/useIsMounted'
import { useMarketMetadata } from '@context/MarketMetadata'
Expand Down Expand Up @@ -65,14 +68,7 @@ export default function Download({
useState<OrderPriceAndFees>()
const [retry, setRetry] = useState<boolean>(false)

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
}

const price: AssetPrice = getAvailablePrice(asset)
const isUnsupportedPricing =
!asset?.accessDetails ||
!asset.services.length ||
Expand Down Expand Up @@ -295,7 +291,7 @@ export default function Download({
) : (
<Price
className={styles.price}
price={asset.stats?.price}
price={price}
orderPriceAndFees={orderPriceAndFees}
conversion
size="large"
Expand Down
33 changes: 25 additions & 8 deletions src/components/Footer/MarketStats/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import Markdown from '@shared/Markdown'
import content from '../../../../content/footer.json'
import { getTotalAllocatedAndLocked } from '@utils/veAllocation'
import PriceUnit from '@shared/Price/PriceUnit'
import Loader from '@components/@shared/atoms/Loader'

const initialTotal: StatsTotal = {
nfts: 0,
Expand All @@ -25,6 +26,14 @@ const initialTotal: StatsTotal = {
veLocked: 0
}

function LoaderArea() {
return (
<div className={styles.loaderWrap}>
<Loader />
</div>
)
}

export default function MarketStats(): ReactElement {
const { appConfig } = useMarketMetadata()
const { networksList } = useNetworkMetadata()
Expand All @@ -33,6 +42,7 @@ export default function MarketStats(): ReactElement {
[chainId: number]: FooterStatsValuesGlobalStatistics
}>()
const [total, setTotal] = useState(initialTotal)
const [loading, setLoading] = useState<boolean>(false)

//
// Set the main chain ids we want to display stats for
Expand Down Expand Up @@ -72,15 +82,16 @@ export default function MarketStats(): ReactElement {
LoggerInstance.error('Error fetching global stats: ', error.message)
}
}
setData(newData)
}, [mainChainIds])

async function addVeTotals(partialTotals: StatsTotal) {
const total: StatsTotal = { ...partialTotals }
const veTotals = await getTotalAllocatedAndLocked()
total.veAllocated = veTotals.totalAllocated
total.veLocked = veTotals.totalLocked
setTotal(total)

setData(newData)
}, [mainChainIds])

return total
}
//
// 1. Fetch Data
//
Expand All @@ -93,6 +104,7 @@ export default function MarketStats(): ReactElement {
//
useEffect(() => {
if (!data || !mainChainIds?.length) return
setLoading(true)
const newTotal: StatsTotal = total

for (const chainId of mainChainIds) {
Expand All @@ -108,11 +120,16 @@ export default function MarketStats(): ReactElement {
LoggerInstance.error('Error data manipulation: ', error.message)
}
}

setTotal(newTotal)
async function setTotalAllocatedAndLocked() {
setTotal(await addVeTotals(newTotal))
setLoading(false)
}
setTotalAllocatedAndLocked()
}, [data, mainChainIds])

return (
return loading ? (
<LoaderArea />
) : (
<div className={styles.stats}>
<div>
<MarketStatsTotal total={total} />{' '}
Expand Down

0 comments on commit 0d585b6

Please sign in to comment.