mirror of
https://github.com/oceanprotocol/market.git
synced 2024-12-02 05:57:29 +01:00
124fd1d137
* fix compute asset selction lists * Update src/@utils/assetConvertor.ts Co-authored-by: Matthias Kretschmann <m@kretschmann.io> * use propper const Co-authored-by: mihaisc <mihai.scarlat@smartcontrol.ro> Co-authored-by: Matthias Kretschmann <m@kretschmann.io>
44 lines
1.4 KiB
TypeScript
44 lines
1.4 KiB
TypeScript
import { getAccessDetailsForAssets } from './accessDetailsAndPricing'
|
|
import { PublisherTrustedAlgorithm, Asset } from '@oceanprotocol/lib'
|
|
import { AssetSelectionAsset } from '@shared/FormInput/InputElement/AssetSelection'
|
|
import { getServiceByName } from './ddo'
|
|
|
|
export async function transformAssetToAssetSelection(
|
|
datasetProviderEndpoint: string,
|
|
assets: Asset[],
|
|
selectedAlgorithms?: PublisherTrustedAlgorithm[]
|
|
): Promise<AssetSelectionAsset[]> {
|
|
const extendedAssets: AssetExtended[] = await getAccessDetailsForAssets(
|
|
assets
|
|
)
|
|
const algorithmList: AssetSelectionAsset[] = []
|
|
|
|
for (const asset of extendedAssets) {
|
|
const algoService =
|
|
getServiceByName(asset, 'compute') || getServiceByName(asset, 'access')
|
|
|
|
if (
|
|
asset?.accessDetails?.price &&
|
|
algoService?.serviceEndpoint === datasetProviderEndpoint
|
|
) {
|
|
let selected = false
|
|
selectedAlgorithms?.forEach((algorithm: PublisherTrustedAlgorithm) => {
|
|
if (algorithm.did === asset.id) {
|
|
selected = true
|
|
}
|
|
})
|
|
const algorithmAsset: AssetSelectionAsset = {
|
|
did: asset.id,
|
|
name: asset.metadata.name,
|
|
price: asset.accessDetails.price,
|
|
checked: selected,
|
|
symbol: asset.datatokens[0].symbol
|
|
}
|
|
selected
|
|
? algorithmList.unshift(algorithmAsset)
|
|
: algorithmList.push(algorithmAsset)
|
|
}
|
|
}
|
|
return algorithmList
|
|
}
|