mirror of
https://github.com/oceanprotocol/market.git
synced 2024-12-02 05:57:29 +01:00
Merge branch 'feature/v4-c2d' into fix/issue-1069-c2d-unsupported-networks
This commit is contained in:
commit
db1e1f8fae
@ -27,6 +27,7 @@ export interface AssetProviderValue {
|
|||||||
error?: string
|
error?: string
|
||||||
isAssetNetwork: boolean
|
isAssetNetwork: boolean
|
||||||
isV3Asset: boolean
|
isV3Asset: boolean
|
||||||
|
isOwner: boolean
|
||||||
oceanConfig: Config
|
oceanConfig: Config
|
||||||
loading: boolean
|
loading: boolean
|
||||||
fetchAsset: (token?: CancelToken) => Promise<void>
|
fetchAsset: (token?: CancelToken) => Promise<void>
|
||||||
@ -49,6 +50,7 @@ function AssetProvider({
|
|||||||
const [asset, setAsset] = useState<AssetExtended>()
|
const [asset, setAsset] = useState<AssetExtended>()
|
||||||
const [title, setTitle] = useState<string>()
|
const [title, setTitle] = useState<string>()
|
||||||
const [owner, setOwner] = useState<string>()
|
const [owner, setOwner] = useState<string>()
|
||||||
|
const [isOwner, setIsOwner] = useState<boolean>()
|
||||||
const [error, setError] = useState<string>()
|
const [error, setError] = useState<string>()
|
||||||
const [loading, setLoading] = useState(false)
|
const [loading, setLoading] = useState(false)
|
||||||
const [isAssetNetwork, setIsAssetNetwork] = useState<boolean>()
|
const [isAssetNetwork, setIsAssetNetwork] = useState<boolean>()
|
||||||
@ -140,6 +142,16 @@ function AssetProvider({
|
|||||||
setIsAssetNetwork(isAssetNetwork)
|
setIsAssetNetwork(isAssetNetwork)
|
||||||
}, [chainId, asset?.chainId])
|
}, [chainId, asset?.chainId])
|
||||||
|
|
||||||
|
// -----------------------------------
|
||||||
|
// Asset owner check against wallet user
|
||||||
|
// -----------------------------------
|
||||||
|
useEffect(() => {
|
||||||
|
if (!accountId || !owner) return
|
||||||
|
|
||||||
|
const isOwner = accountId?.toLowerCase() === owner.toLowerCase()
|
||||||
|
setIsOwner(isOwner)
|
||||||
|
}, [accountId, owner])
|
||||||
|
|
||||||
// -----------------------------------
|
// -----------------------------------
|
||||||
// Load ocean config based on asset network
|
// Load ocean config based on asset network
|
||||||
// -----------------------------------
|
// -----------------------------------
|
||||||
@ -172,6 +184,7 @@ function AssetProvider({
|
|||||||
fetchAsset,
|
fetchAsset,
|
||||||
isAssetNetwork,
|
isAssetNetwork,
|
||||||
isV3Asset,
|
isV3Asset,
|
||||||
|
isOwner,
|
||||||
oceanConfig
|
oceanConfig
|
||||||
} as AssetProviderValue
|
} as AssetProviderValue
|
||||||
}
|
}
|
||||||
|
@ -151,19 +151,20 @@ export async function getComputeEnviroment(
|
|||||||
|
|
||||||
export function getQueryString(
|
export function getQueryString(
|
||||||
trustedAlgorithmList: PublisherTrustedAlgorithm[],
|
trustedAlgorithmList: PublisherTrustedAlgorithm[],
|
||||||
|
trustedPublishersList: string[],
|
||||||
chainId?: number
|
chainId?: number
|
||||||
): SearchQuery {
|
): SearchQuery {
|
||||||
const algorithmDidList = trustedAlgorithmList.map((x) => x.did)
|
const algorithmDidList = trustedAlgorithmList?.map((x) => x.did)
|
||||||
|
|
||||||
const baseParams = {
|
const baseParams = {
|
||||||
chainIds: [chainId],
|
chainIds: [chainId],
|
||||||
sort: { sortBy: SortTermOptions.Created },
|
sort: { sortBy: SortTermOptions.Created },
|
||||||
filters: [
|
filters: [getFilterTerm('metadata.type', 'algorithm')]
|
||||||
getFilterTerm('metadata.type', 'algorithm'),
|
|
||||||
algorithmDidList.length > 0 && getFilterTerm('_id', algorithmDidList)
|
|
||||||
]
|
|
||||||
} as BaseQueryParams
|
} as BaseQueryParams
|
||||||
|
algorithmDidList?.length > 0 &&
|
||||||
|
baseParams.filters.push(getFilterTerm('_id', algorithmDidList))
|
||||||
|
trustedPublishersList?.length > 0 &&
|
||||||
|
baseParams.filters.push(getFilterTerm('nft.owner', trustedPublishersList))
|
||||||
const query = generateBaseQuery(baseParams)
|
const query = generateBaseQuery(baseParams)
|
||||||
|
|
||||||
return query
|
return query
|
||||||
@ -174,19 +175,25 @@ export async function getAlgorithmsForAsset(
|
|||||||
token: CancelToken
|
token: CancelToken
|
||||||
): Promise<Asset[]> {
|
): Promise<Asset[]> {
|
||||||
const computeService: Service = getServiceByName(asset, 'compute')
|
const computeService: Service = getServiceByName(asset, 'compute')
|
||||||
const publisherTrustedAlgorithms =
|
|
||||||
computeService.compute.publisherTrustedAlgorithms || []
|
|
||||||
|
|
||||||
let algorithms: Asset[]
|
if (
|
||||||
if (!computeService.compute) {
|
!computeService.compute ||
|
||||||
algorithms = []
|
(computeService.compute.publisherTrustedAlgorithms?.length === 0 &&
|
||||||
} else {
|
computeService.compute.publisherTrustedAlgorithmPublishers?.length === 0)
|
||||||
|
) {
|
||||||
|
return []
|
||||||
|
}
|
||||||
|
|
||||||
const gueryResults = await queryMetadata(
|
const gueryResults = await queryMetadata(
|
||||||
getQueryString(publisherTrustedAlgorithms, asset.chainId),
|
getQueryString(
|
||||||
|
computeService.compute.publisherTrustedAlgorithms,
|
||||||
|
computeService.compute.publisherTrustedAlgorithmPublishers,
|
||||||
|
asset.chainId
|
||||||
|
),
|
||||||
token
|
token
|
||||||
)
|
)
|
||||||
algorithms = gueryResults?.results
|
|
||||||
}
|
const algorithms: Asset[] = gueryResults?.results
|
||||||
return algorithms
|
return algorithms
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -356,7 +363,7 @@ export async function transformComputeFormToServiceComputeOptions(
|
|||||||
cancelToken: CancelToken
|
cancelToken: CancelToken
|
||||||
): Promise<ServiceComputeOptions> {
|
): Promise<ServiceComputeOptions> {
|
||||||
const publisherTrustedAlgorithms = values.allowAllPublishedAlgorithms
|
const publisherTrustedAlgorithms = values.allowAllPublishedAlgorithms
|
||||||
? null
|
? []
|
||||||
: await createTrustedAlgorithmList(
|
: await createTrustedAlgorithmList(
|
||||||
values.publisherTrustedAlgorithms,
|
values.publisherTrustedAlgorithms,
|
||||||
assetChainId,
|
assetChainId,
|
||||||
|
@ -155,6 +155,55 @@ export async function reuseOrder(
|
|||||||
return tx
|
return tx
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function approveProviderFee(
|
||||||
|
asset: AssetExtended,
|
||||||
|
accountId: string,
|
||||||
|
web3: Web3,
|
||||||
|
providerFeeAmount: string
|
||||||
|
): Promise<string> {
|
||||||
|
const baseToken =
|
||||||
|
asset?.accessDetails?.type === 'free'
|
||||||
|
? getOceanConfig(asset.chainId).oceanTokenAddress
|
||||||
|
: asset?.accessDetails?.baseToken?.address
|
||||||
|
const txApproveWei = await approveWei(
|
||||||
|
web3,
|
||||||
|
accountId,
|
||||||
|
baseToken,
|
||||||
|
asset?.accessDetails?.datatoken?.address,
|
||||||
|
providerFeeAmount
|
||||||
|
)
|
||||||
|
return txApproveWei as string // thanks ocean.js
|
||||||
|
}
|
||||||
|
|
||||||
|
async function startOrder(
|
||||||
|
web3: Web3,
|
||||||
|
asset: AssetExtended,
|
||||||
|
orderPriceAndFees: OrderPriceAndFees,
|
||||||
|
accountId: string,
|
||||||
|
hasDatatoken: boolean,
|
||||||
|
initializeData: ProviderComputeInitialize,
|
||||||
|
computeConsumerAddress?: string
|
||||||
|
): Promise<TransactionReceipt> {
|
||||||
|
if (!hasDatatoken && asset?.accessDetails.type === 'dynamic') {
|
||||||
|
const poolTx = await buyDtFromPool(asset?.accessDetails, accountId, web3)
|
||||||
|
LoggerInstance.log('[compute] Bought datatoken from pool: ', poolTx)
|
||||||
|
if (!poolTx) {
|
||||||
|
toast.error('Failed to buy datatoken from pool!')
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
const tx = await order(
|
||||||
|
web3,
|
||||||
|
asset,
|
||||||
|
orderPriceAndFees,
|
||||||
|
accountId,
|
||||||
|
initializeData.providerFee,
|
||||||
|
computeConsumerAddress
|
||||||
|
)
|
||||||
|
LoggerInstance.log('[compute] Asset ordered:', tx)
|
||||||
|
return tx
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handles order for compute assets for the following scenarios:
|
* Handles order for compute assets for the following scenarios:
|
||||||
* - have validOrder and no providerFees -> then order is valid, providerFees are valid, it returns the valid order value
|
* - have validOrder and no providerFees -> then order is valid, providerFees are valid, it returns the valid order value
|
||||||
@ -182,60 +231,62 @@ export async function handleComputeOrder(
|
|||||||
'[compute] Handle compute order for asset type: ',
|
'[compute] Handle compute order for asset type: ',
|
||||||
asset.metadata.type
|
asset.metadata.type
|
||||||
)
|
)
|
||||||
|
LoggerInstance.log('[compute] Using initializeData: ', initializeData)
|
||||||
|
|
||||||
if (
|
try {
|
||||||
initializeData.providerFee &&
|
// Return early when valid order is found, and no provider fees
|
||||||
initializeData.providerFee.providerFeeAmount !== '0'
|
// are to be paid
|
||||||
) {
|
if (initializeData?.validOrder && !initializeData.providerFee) {
|
||||||
const baseToken =
|
LoggerInstance.log(
|
||||||
asset?.accessDetails?.type === 'free'
|
'[compute] Has valid order: ',
|
||||||
? getOceanConfig(asset.chainId).oceanTokenAddress
|
initializeData.validOrder
|
||||||
: asset?.accessDetails?.baseToken?.address
|
|
||||||
const txApproveWei = await approveWei(
|
|
||||||
web3,
|
|
||||||
accountId,
|
|
||||||
baseToken,
|
|
||||||
asset?.accessDetails?.datatoken?.address,
|
|
||||||
initializeData?.providerFee?.providerFeeAmount
|
|
||||||
)
|
)
|
||||||
if (!txApproveWei) {
|
return asset?.accessDetails?.validOrderTx
|
||||||
toast.error('Failed to approve provider fees!')
|
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Approve potential Provider fee amount first
|
||||||
|
if (initializeData?.providerFee?.providerFeeAmount !== '0') {
|
||||||
|
const txApproveProvider = await approveProviderFee(
|
||||||
|
asset,
|
||||||
|
accountId,
|
||||||
|
web3,
|
||||||
|
initializeData.providerFee.providerFeeAmount
|
||||||
|
)
|
||||||
|
|
||||||
|
if (!txApproveProvider)
|
||||||
|
throw new Error('Failed to approve provider fees!')
|
||||||
|
|
||||||
|
LoggerInstance.log('[compute] Approved provider fees:', txApproveProvider)
|
||||||
}
|
}
|
||||||
if (initializeData.validOrder && !initializeData.providerFee) {
|
|
||||||
LoggerInstance.log('[compute] Has valid order: ', initializeData.validOrder)
|
if (initializeData?.validOrder) {
|
||||||
return initializeData.validOrder
|
|
||||||
} else if (initializeData.validOrder) {
|
|
||||||
LoggerInstance.log('[compute] Calling reuseOrder ...', initializeData)
|
LoggerInstance.log('[compute] Calling reuseOrder ...', initializeData)
|
||||||
const tx = await reuseOrder(
|
const txReuseOrder = await reuseOrder(
|
||||||
web3,
|
web3,
|
||||||
asset,
|
asset,
|
||||||
accountId,
|
accountId,
|
||||||
initializeData.validOrder,
|
initializeData.validOrder,
|
||||||
initializeData.providerFee
|
initializeData.providerFee
|
||||||
)
|
)
|
||||||
LoggerInstance.log('[compute] Reused order:', tx.transactionHash)
|
if (!txReuseOrder) throw new Error('Failed to reuse order!')
|
||||||
return tx.transactionHash
|
LoggerInstance.log('[compute] Reused order:', txReuseOrder)
|
||||||
} else {
|
return txReuseOrder?.transactionHash
|
||||||
|
}
|
||||||
|
|
||||||
LoggerInstance.log('[compute] Calling order ...', initializeData)
|
LoggerInstance.log('[compute] Calling order ...', initializeData)
|
||||||
if (!hasDatatoken && asset?.accessDetails.type === 'dynamic') {
|
const txStartOrder = await startOrder(
|
||||||
const poolTx = await buyDtFromPool(asset?.accessDetails, accountId, web3)
|
|
||||||
LoggerInstance.log('[compute] Buoght dt from pool: ', poolTx)
|
|
||||||
if (!poolTx) {
|
|
||||||
toast.error('Failed to buy datatoken from pool!')
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
const tx = await order(
|
|
||||||
web3,
|
web3,
|
||||||
asset,
|
asset,
|
||||||
orderPriceAndFees,
|
orderPriceAndFees,
|
||||||
accountId,
|
accountId,
|
||||||
initializeData.providerFee,
|
hasDatatoken,
|
||||||
|
initializeData,
|
||||||
computeConsumerAddress
|
computeConsumerAddress
|
||||||
)
|
)
|
||||||
LoggerInstance.log('[compute] Asset ordered:', tx.transactionHash)
|
LoggerInstance.log('[compute] Order succeeded', txStartOrder)
|
||||||
return tx.transactionHash
|
return txStartOrder?.transactionHash
|
||||||
|
} catch (error) {
|
||||||
|
toast.error(error.message)
|
||||||
|
LoggerInstance.error(`[compute] ${error.message}`)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,7 +5,6 @@ import { AssetSelectionAsset } from '@shared/FormFields/AssetSelection'
|
|||||||
import AssetComputeList from '@shared/AssetList/AssetComputeList'
|
import AssetComputeList from '@shared/AssetList/AssetComputeList'
|
||||||
import { useCancelToken } from '@hooks/useCancelToken'
|
import { useCancelToken } from '@hooks/useCancelToken'
|
||||||
import { getServiceByName } from '@utils/ddo'
|
import { getServiceByName } from '@utils/ddo'
|
||||||
import { Asset } from '@oceanprotocol/lib'
|
|
||||||
import { AssetExtended } from 'src/@types/AssetExtended'
|
import { AssetExtended } from 'src/@types/AssetExtended'
|
||||||
|
|
||||||
export default function AlgorithmDatasetsListForCompute({
|
export default function AlgorithmDatasetsListForCompute({
|
||||||
@ -15,9 +14,9 @@ export default function AlgorithmDatasetsListForCompute({
|
|||||||
asset: AssetExtended
|
asset: AssetExtended
|
||||||
algorithmDid: string
|
algorithmDid: string
|
||||||
}): ReactElement {
|
}): ReactElement {
|
||||||
|
const newCancelToken = useCancelToken()
|
||||||
const [datasetsForCompute, setDatasetsForCompute] =
|
const [datasetsForCompute, setDatasetsForCompute] =
|
||||||
useState<AssetSelectionAsset[]>()
|
useState<AssetSelectionAsset[]>()
|
||||||
const newCancelToken = useCancelToken()
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!asset) return
|
if (!asset) return
|
||||||
@ -37,7 +36,7 @@ export default function AlgorithmDatasetsListForCompute({
|
|||||||
setDatasetsForCompute(datasets)
|
setDatasetsForCompute(datasets)
|
||||||
}
|
}
|
||||||
asset.metadata.type === 'algorithm' && getDatasetsAllowedForCompute()
|
asset.metadata.type === 'algorithm' && getDatasetsAllowedForCompute()
|
||||||
}, [asset?.metadata?.type])
|
}, [asset, algorithmDid, newCancelToken])
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={styles.datasetsContainer}>
|
<div className={styles.datasetsContainer}>
|
||||||
|
@ -83,6 +83,8 @@ export default function Compute({
|
|||||||
const [validAlgorithmOrderTx, setValidAlgorithmOrderTx] = useState('')
|
const [validAlgorithmOrderTx, setValidAlgorithmOrderTx] = useState('')
|
||||||
|
|
||||||
const [isConsumablePrice, setIsConsumablePrice] = useState(true)
|
const [isConsumablePrice, setIsConsumablePrice] = useState(true)
|
||||||
|
const [isConsumableaAlgorithmPrice, setIsConsumableAlgorithmPrice] =
|
||||||
|
useState(true)
|
||||||
const [computeStatusText, setComputeStatusText] = useState('')
|
const [computeStatusText, setComputeStatusText] = useState('')
|
||||||
const [computeEnv, setComputeEnv] = useState<ComputeEnvironment>()
|
const [computeEnv, setComputeEnv] = useState<ComputeEnvironment>()
|
||||||
const [initializedProviderResponse, setInitializedProviderResponse] =
|
const [initializedProviderResponse, setInitializedProviderResponse] =
|
||||||
@ -102,7 +104,9 @@ export default function Compute({
|
|||||||
isOrdering === true ||
|
isOrdering === true ||
|
||||||
file === null ||
|
file === null ||
|
||||||
(!validOrderTx && !hasDatatoken && !isConsumablePrice) ||
|
(!validOrderTx && !hasDatatoken && !isConsumablePrice) ||
|
||||||
(!validAlgorithmOrderTx && !hasAlgoAssetDatatoken)
|
(!validAlgorithmOrderTx &&
|
||||||
|
!hasAlgoAssetDatatoken &&
|
||||||
|
!isConsumableaAlgorithmPrice)
|
||||||
|
|
||||||
async function checkAssetDTBalance(asset: DDO): Promise<boolean> {
|
async function checkAssetDTBalance(asset: DDO): Promise<boolean> {
|
||||||
if (!asset?.services[0].datatokenAddress) return
|
if (!asset?.services[0].datatokenAddress) return
|
||||||
@ -119,26 +123,25 @@ export default function Compute({
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function initPriceAndFees() {
|
async function initPriceAndFees() {
|
||||||
|
try {
|
||||||
const computeEnv = await getComputeEnviroment(asset)
|
const computeEnv = await getComputeEnviroment(asset)
|
||||||
if (!computeEnv || !computeEnv.id) {
|
if (!computeEnv || !computeEnv.id)
|
||||||
setError(`Error getting compute environments!`)
|
throw new Error(`Error getting compute environments!`)
|
||||||
return
|
|
||||||
}
|
|
||||||
setComputeEnv(computeEnv)
|
setComputeEnv(computeEnv)
|
||||||
const initializedProvider = await initializeProviderForCompute(
|
const initializedProvider = await initializeProviderForCompute(
|
||||||
asset,
|
asset,
|
||||||
selectedAlgorithmAsset,
|
selectedAlgorithmAsset,
|
||||||
accountId || ZERO_ADDRESS, // if the user is not connected, we use ZERO_ADDRESS as accountId
|
accountId,
|
||||||
computeEnv
|
computeEnv
|
||||||
)
|
)
|
||||||
if (
|
if (
|
||||||
!initializedProvider ||
|
!initializedProvider ||
|
||||||
!initializedProvider?.datasets ||
|
!initializedProvider?.datasets ||
|
||||||
!initializedProvider?.algorithm
|
!initializedProvider?.algorithm
|
||||||
) {
|
)
|
||||||
setError(`Error initializing provider for the compute job!`)
|
throw new Error(`Error initializing provider for the compute job!`)
|
||||||
return
|
|
||||||
}
|
|
||||||
setInitializedProviderResponse(initializedProvider)
|
setInitializedProviderResponse(initializedProvider)
|
||||||
setProviderFeeAmount(
|
setProviderFeeAmount(
|
||||||
await unitsToAmount(
|
await unitsToAmount(
|
||||||
@ -152,6 +155,7 @@ export default function Compute({
|
|||||||
Math.floor(Date.now() / 1000)
|
Math.floor(Date.now() / 1000)
|
||||||
).toString()
|
).toString()
|
||||||
setComputeValidUntil(computeDuration)
|
setComputeValidUntil(computeDuration)
|
||||||
|
|
||||||
if (
|
if (
|
||||||
asset?.accessDetails?.addressOrId !== ZERO_ADDRESS &&
|
asset?.accessDetails?.addressOrId !== ZERO_ADDRESS &&
|
||||||
asset?.accessDetails?.type !== 'free' &&
|
asset?.accessDetails?.type !== 'free' &&
|
||||||
@ -181,17 +185,14 @@ export default function Compute({
|
|||||||
}
|
}
|
||||||
: null
|
: null
|
||||||
const datasetPriceAndFees = await getOrderPriceAndFees(
|
const datasetPriceAndFees = await getOrderPriceAndFees(
|
||||||
web3 || (await getDummyWeb3(asset?.chainId)), // if the user is not connected, we need to use a dummy web3
|
|
||||||
asset,
|
asset,
|
||||||
accountId || ZERO_ADDRESS, // if the user is not connected, we need to use ZERO_ADDRESS as accountId
|
ZERO_ADDRESS,
|
||||||
poolParams,
|
poolParams,
|
||||||
initializedProvider?.datasets?.[0]?.providerFee
|
initializedProvider?.datasets?.[0]?.providerFee
|
||||||
)
|
)
|
||||||
|
if (!datasetPriceAndFees)
|
||||||
|
throw new Error('Error setting dataset price and fees!')
|
||||||
|
|
||||||
if (!datasetPriceAndFees) {
|
|
||||||
setError('Error setting dataset price and fees!')
|
|
||||||
return
|
|
||||||
}
|
|
||||||
setDatasetOrderPriceAndFees(datasetPriceAndFees)
|
setDatasetOrderPriceAndFees(datasetPriceAndFees)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -230,35 +231,36 @@ export default function Compute({
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
const algorithmOrderPriceAndFees = await getOrderPriceAndFees(
|
const algorithmOrderPriceAndFees = await getOrderPriceAndFees(
|
||||||
web3 || (await getDummyWeb3(asset?.chainId)),
|
|
||||||
selectedAlgorithmAsset,
|
selectedAlgorithmAsset,
|
||||||
accountId || ZERO_ADDRESS,
|
ZERO_ADDRESS,
|
||||||
algoPoolParams,
|
algoPoolParams,
|
||||||
initializedProvider.algorithm.providerFee
|
initializedProvider.algorithm.providerFee
|
||||||
)
|
)
|
||||||
|
if (!algorithmOrderPriceAndFees)
|
||||||
|
throw new Error('Error setting algorithm price and fees!')
|
||||||
|
|
||||||
if (!algorithmOrderPriceAndFees) {
|
|
||||||
setError('Error setting algorithm price and fees!')
|
|
||||||
return
|
|
||||||
}
|
|
||||||
setAlgoOrderPriceAndFees(algorithmOrderPriceAndFees)
|
setAlgoOrderPriceAndFees(algorithmOrderPriceAndFees)
|
||||||
}
|
}
|
||||||
|
} catch (error) {
|
||||||
|
setError(error.message)
|
||||||
|
LoggerInstance.error(`[compute] ${error.message} `)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!asset?.accessDetails || !accountId) return
|
if (!asset?.accessDetails || !accountId) return
|
||||||
|
|
||||||
setIsConsumablePrice(asset?.accessDetails?.isPurchasable)
|
setIsConsumablePrice(asset?.accessDetails?.isPurchasable)
|
||||||
// setIsOwned(asset?.accessDetails?.isOwned)
|
|
||||||
setValidOrderTx(asset?.accessDetails?.validOrderTx)
|
setValidOrderTx(asset?.accessDetails?.validOrderTx)
|
||||||
}, [asset?.accessDetails])
|
}, [asset?.accessDetails, accountId])
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!selectedAlgorithmAsset?.accessDetails) return
|
if (!selectedAlgorithmAsset?.accessDetails) return
|
||||||
|
|
||||||
setIsRequestingAlgoOrderPrice(true)
|
setIsRequestingAlgoOrderPrice(true)
|
||||||
setIsConsumablePrice(selectedAlgorithmAsset?.accessDetails?.isPurchasable)
|
setIsConsumableAlgorithmPrice(
|
||||||
// setIsAlgorithmOwned(selectedAlgorithmAsset?.accessDetails?.isOwned)
|
selectedAlgorithmAsset?.accessDetails?.isPurchasable
|
||||||
|
)
|
||||||
setValidAlgorithmOrderTx(
|
setValidAlgorithmOrderTx(
|
||||||
selectedAlgorithmAsset?.accessDetails?.validOrderTx
|
selectedAlgorithmAsset?.accessDetails?.validOrderTx
|
||||||
)
|
)
|
||||||
@ -271,11 +273,10 @@ export default function Compute({
|
|||||||
}
|
}
|
||||||
|
|
||||||
initSelectedAlgo()
|
initSelectedAlgo()
|
||||||
}, [selectedAlgorithmAsset])
|
}, [selectedAlgorithmAsset, accountId])
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!asset) return
|
if (!asset) return
|
||||||
|
|
||||||
getAlgorithmsForAsset(asset, newCancelToken()).then((algorithmsAssets) => {
|
getAlgorithmsForAsset(asset, newCancelToken()).then((algorithmsAssets) => {
|
||||||
setDdoAlgorithmList(algorithmsAssets)
|
setDdoAlgorithmList(algorithmsAssets)
|
||||||
getAlgorithmAssetSelectionList(asset, algorithmsAssets).then(
|
getAlgorithmAssetSelectionList(asset, algorithmsAssets).then(
|
||||||
@ -293,10 +294,10 @@ export default function Compute({
|
|||||||
toast.error(newError)
|
toast.error(newError)
|
||||||
}, [error])
|
}, [error])
|
||||||
|
|
||||||
async function startJob(): Promise<string> {
|
async function startJob(): Promise<void> {
|
||||||
try {
|
try {
|
||||||
setIsOrdering(true)
|
setIsOrdering(true)
|
||||||
setIsOrdered(false) // would be nice to rename this
|
setIsOrdered(false)
|
||||||
setError(undefined)
|
setError(undefined)
|
||||||
const computeService = getServiceByName(asset, 'compute')
|
const computeService = getServiceByName(asset, 'compute')
|
||||||
const computeAlgorithm: ComputeAlgorithm = {
|
const computeAlgorithm: ComputeAlgorithm = {
|
||||||
@ -310,15 +311,10 @@ export default function Compute({
|
|||||||
selectedAlgorithmAsset
|
selectedAlgorithmAsset
|
||||||
)
|
)
|
||||||
LoggerInstance.log('[compute] Is data set orderable?', allowed)
|
LoggerInstance.log('[compute] Is data set orderable?', allowed)
|
||||||
if (!allowed) {
|
if (!allowed)
|
||||||
setError(
|
throw new Error(
|
||||||
'Data set is not orderable in combination with selected algorithm.'
|
'Data set is not orderable in combination with selected algorithm.'
|
||||||
)
|
)
|
||||||
LoggerInstance.error(
|
|
||||||
'[compute] Error starting compute job. Dataset is not orderable in combination with selected algorithm.'
|
|
||||||
)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
setComputeStatusText(
|
setComputeStatusText(
|
||||||
getComputeFeedback(
|
getComputeFeedback(
|
||||||
@ -342,11 +338,8 @@ export default function Compute({
|
|||||||
initializedProviderResponse.datasets[0],
|
initializedProviderResponse.datasets[0],
|
||||||
computeEnv.consumerAddress
|
computeEnv.consumerAddress
|
||||||
)
|
)
|
||||||
if (!datasetOrderTx) {
|
if (!datasetOrderTx) throw new Error('Failed to order dataset.')
|
||||||
setError('Failed to order dataset.')
|
|
||||||
LoggerInstance.error('[compute] Failed to order dataset.')
|
|
||||||
return
|
|
||||||
}
|
|
||||||
setComputeStatusText(
|
setComputeStatusText(
|
||||||
getComputeFeedback(
|
getComputeFeedback(
|
||||||
selectedAlgorithmAsset.accessDetails.baseToken?.symbol,
|
selectedAlgorithmAsset.accessDetails.baseToken?.symbol,
|
||||||
@ -370,11 +363,7 @@ export default function Compute({
|
|||||||
initializedProviderResponse.algorithm,
|
initializedProviderResponse.algorithm,
|
||||||
computeEnv.consumerAddress
|
computeEnv.consumerAddress
|
||||||
)
|
)
|
||||||
if (!algorithmOrderTx) {
|
if (!algorithmOrderTx) throw new Error('Failed to order algorithm.')
|
||||||
setError('Failed to order algorithm.')
|
|
||||||
LoggerInstance.error('[compute] Failed to order algorithm.')
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
LoggerInstance.log('[compute] Starting compute job.')
|
LoggerInstance.log('[compute] Starting compute job.')
|
||||||
const computeAsset: ComputeAsset = {
|
const computeAsset: ComputeAsset = {
|
||||||
@ -399,17 +388,15 @@ export default function Compute({
|
|||||||
null,
|
null,
|
||||||
output
|
output
|
||||||
)
|
)
|
||||||
if (!response) {
|
if (!response) throw new Error('Error starting compute job.')
|
||||||
setError('Error starting compute job.')
|
|
||||||
return
|
|
||||||
}
|
|
||||||
LoggerInstance.log('[compute] Starting compute job response: ', response)
|
LoggerInstance.log('[compute] Starting compute job response: ', response)
|
||||||
setIsOrdered(true)
|
setIsOrdered(true)
|
||||||
setRefetchJobs(!refetchJobs)
|
setRefetchJobs(!refetchJobs)
|
||||||
initPriceAndFees()
|
initPriceAndFees()
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
setError('Failed to start job!')
|
setError(error.message)
|
||||||
LoggerInstance.error('[compute] Failed to start job: ', error.message)
|
LoggerInstance.error(`[compute] ${error.message} `)
|
||||||
} finally {
|
} finally {
|
||||||
setIsOrdering(false)
|
setIsOrdering(false)
|
||||||
}
|
}
|
||||||
|
@ -35,20 +35,7 @@
|
|||||||
text-align: center;
|
text-align: center;
|
||||||
margin-top: var(--spacer);
|
margin-top: var(--spacer);
|
||||||
margin-bottom: calc(var(--spacer) * 1.5);
|
margin-bottom: calc(var(--spacer) * 1.5);
|
||||||
margin-left: -2rem;
|
padding: calc(var(--spacer) / 3) var(--spacer);
|
||||||
margin-right: -2rem;
|
|
||||||
padding: calc(var(--spacer) / 4) var(--spacer);
|
|
||||||
border-top: 1px solid var(--border-color);
|
border-top: 1px solid var(--border-color);
|
||||||
border-bottom: 1px solid var(--border-color);
|
border-bottom: 1px solid var(--border-color);
|
||||||
}
|
}
|
||||||
|
|
||||||
.ownerActions a,
|
|
||||||
.ownerActions button {
|
|
||||||
color: var(--color-secondary);
|
|
||||||
margin-left: calc(var(--spacer) / 4);
|
|
||||||
margin-right: calc(var(--spacer) / 4);
|
|
||||||
}
|
|
||||||
|
|
||||||
.separator {
|
|
||||||
color: var(--color-secondary);
|
|
||||||
}
|
|
||||||
|
@ -15,17 +15,15 @@ import styles from './index.module.css'
|
|||||||
import NetworkName from '@shared/NetworkName'
|
import NetworkName from '@shared/NetworkName'
|
||||||
import content from '../../../../content/purgatory.json'
|
import content from '../../../../content/purgatory.json'
|
||||||
import { AssetExtended } from 'src/@types/AssetExtended'
|
import { AssetExtended } from 'src/@types/AssetExtended'
|
||||||
import { useWeb3 } from '@context/Web3'
|
|
||||||
import Web3 from 'web3'
|
import Web3 from 'web3'
|
||||||
|
import Button from '@shared/atoms/Button'
|
||||||
|
|
||||||
export default function AssetContent({
|
export default function AssetContent({
|
||||||
asset
|
asset
|
||||||
}: {
|
}: {
|
||||||
asset: AssetExtended
|
asset: AssetExtended
|
||||||
}): ReactElement {
|
}): ReactElement {
|
||||||
const [isOwner, setIsOwner] = useState(false)
|
const { isInPurgatory, purgatoryData, isOwner, isAssetNetwork } = useAsset()
|
||||||
const { accountId } = useWeb3()
|
|
||||||
const { isInPurgatory, purgatoryData, owner, isAssetNetwork } = useAsset()
|
|
||||||
const { debug } = useUserPreferences()
|
const { debug } = useUserPreferences()
|
||||||
const [receipts, setReceipts] = useState([])
|
const [receipts, setReceipts] = useState([])
|
||||||
const [nftPublisher, setNftPublisher] = useState<string>()
|
const [nftPublisher, setNftPublisher] = useState<string>()
|
||||||
@ -38,20 +36,6 @@ export default function AssetContent({
|
|||||||
)
|
)
|
||||||
}, [receipts])
|
}, [receipts])
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
if (!accountId || !owner) return
|
|
||||||
|
|
||||||
const isOwner = accountId.toLowerCase() === owner.toLowerCase()
|
|
||||||
setIsOwner(isOwner)
|
|
||||||
}, [accountId, owner, asset])
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
if (!accountId || !owner) return
|
|
||||||
|
|
||||||
const isOwner = accountId.toLowerCase() === owner.toLowerCase()
|
|
||||||
setIsOwner(isOwner)
|
|
||||||
}, [accountId, asset?.accessDetails, owner, asset])
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<div className={styles.networkWrap}>
|
<div className={styles.networkWrap}>
|
||||||
@ -91,9 +75,9 @@ export default function AssetContent({
|
|||||||
<AssetActions asset={asset} />
|
<AssetActions asset={asset} />
|
||||||
{isOwner && isAssetNetwork && (
|
{isOwner && isAssetNetwork && (
|
||||||
<div className={styles.ownerActions}>
|
<div className={styles.ownerActions}>
|
||||||
<Link href={`/asset/${asset?.id}/edit`}>
|
<Button style="text" size="small" to={`/asset/${asset?.id}/edit`}>
|
||||||
<a>Edit</a>
|
Edit Asset
|
||||||
</Link>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
@ -42,9 +42,11 @@ function Asset({
|
|||||||
|
|
||||||
function DetailsAssets({ job }: { job: ComputeJobMetaData }) {
|
function DetailsAssets({ job }: { job: ComputeJobMetaData }) {
|
||||||
const { appConfig } = useMarketMetadata()
|
const { appConfig } = useMarketMetadata()
|
||||||
|
const newCancelToken = useCancelToken()
|
||||||
|
|
||||||
const [algoName, setAlgoName] = useState<string>()
|
const [algoName, setAlgoName] = useState<string>()
|
||||||
const [algoDtSymbol, setAlgoDtSymbol] = useState<string>()
|
const [algoDtSymbol, setAlgoDtSymbol] = useState<string>()
|
||||||
const newCancelToken = useCancelToken()
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
async function getAlgoMetadata() {
|
async function getAlgoMetadata() {
|
||||||
const ddo = await retrieveAsset(job.algoDID, newCancelToken())
|
const ddo = await retrieveAsset(job.algoDID, newCancelToken())
|
||||||
@ -52,7 +54,7 @@ function DetailsAssets({ job }: { job: ComputeJobMetaData }) {
|
|||||||
setAlgoName(ddo?.metadata.name)
|
setAlgoName(ddo?.metadata.name)
|
||||||
}
|
}
|
||||||
getAlgoMetadata()
|
getAlgoMetadata()
|
||||||
}, [appConfig.metadataCacheUri, job.algoDID])
|
}, [appConfig.metadataCacheUri, job.algoDID, newCancelToken])
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
|
@ -3,8 +3,10 @@
|
|||||||
border-bottom-left-radius: var(--border-radius) !important;
|
border-bottom-left-radius: var(--border-radius) !important;
|
||||||
}
|
}
|
||||||
|
|
||||||
.results li {
|
.title {
|
||||||
list-style-type: none;
|
font-size: var(--font-size-base);
|
||||||
|
color: var(--font-color-text);
|
||||||
|
margin-bottom: calc(var(--spacer) / 3);
|
||||||
}
|
}
|
||||||
|
|
||||||
.help {
|
.help {
|
||||||
|
@ -26,31 +26,32 @@ export default function Results({
|
|||||||
|
|
||||||
const [datasetProvider, setDatasetProvider] = useState<string>()
|
const [datasetProvider, setDatasetProvider] = useState<string>()
|
||||||
const newCancelToken = useCancelToken()
|
const newCancelToken = useCancelToken()
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
async function getAssetMetadata() {
|
async function getAssetMetadata() {
|
||||||
const ddo = await retrieveAsset(job.inputDID[0], newCancelToken())
|
const ddo = await retrieveAsset(job.inputDID[0], newCancelToken())
|
||||||
setDatasetProvider(ddo.services[0].serviceEndpoint)
|
setDatasetProvider(ddo.services[0].serviceEndpoint)
|
||||||
}
|
}
|
||||||
getAssetMetadata()
|
getAssetMetadata()
|
||||||
}, [job.inputDID[0]])
|
}, [job.inputDID, newCancelToken])
|
||||||
|
|
||||||
function getDownloadButtonValue(type: ComputeResultType): string {
|
function getDownloadButtonValue(type: ComputeResultType): string {
|
||||||
let buttonName
|
let buttonName
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case 'output':
|
case 'output':
|
||||||
buttonName = 'Download results'
|
buttonName = 'results'
|
||||||
break
|
break
|
||||||
case 'algorithmLog':
|
case 'algorithmLog':
|
||||||
buttonName = 'Download algorithm logs'
|
buttonName = 'algorithm logs'
|
||||||
break
|
break
|
||||||
case 'configrationLog':
|
case 'configrationLog':
|
||||||
buttonName = 'Download configuration logs'
|
buttonName = 'configuration logs'
|
||||||
break
|
break
|
||||||
case 'publishLog':
|
case 'publishLog':
|
||||||
buttonName = 'Download publish logs'
|
buttonName = 'publish logs'
|
||||||
break
|
break
|
||||||
default:
|
default:
|
||||||
buttonName = 'Download results'
|
buttonName = 'results'
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
return buttonName
|
return buttonName
|
||||||
@ -78,6 +79,7 @@ export default function Results({
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={styles.results}>
|
<div className={styles.results}>
|
||||||
|
<h4 className={styles.title}>Results</h4>
|
||||||
{isFinished ? (
|
{isFinished ? (
|
||||||
<ul>
|
<ul>
|
||||||
{job.results &&
|
{job.results &&
|
||||||
@ -86,10 +88,10 @@ export default function Results({
|
|||||||
jobResult.filename ? (
|
jobResult.filename ? (
|
||||||
<ListItem key={i}>
|
<ListItem key={i}>
|
||||||
<Button
|
<Button
|
||||||
style="primary"
|
style="text"
|
||||||
size="small"
|
size="small"
|
||||||
onClick={() => downloadResults(i)}
|
onClick={() => downloadResults(i)}
|
||||||
disabled={isLoading || !isFinished}
|
download
|
||||||
>
|
>
|
||||||
{getDownloadButtonValue(jobResult.type)}
|
{getDownloadButtonValue(jobResult.type)}
|
||||||
</Button>
|
</Button>
|
||||||
|
@ -1,8 +1,6 @@
|
|||||||
import React, { ReactElement, useEffect, useState, useCallback } from 'react'
|
import React, { ReactElement, useEffect, useState, useCallback } from 'react'
|
||||||
import Time from '@shared/atoms/Time'
|
import Time from '@shared/atoms/Time'
|
||||||
import Link from 'next/link'
|
|
||||||
import { LoggerInstance } from '@oceanprotocol/lib'
|
import { LoggerInstance } from '@oceanprotocol/lib'
|
||||||
import Dotdotdot from 'react-dotdotdot'
|
|
||||||
import Table from '@shared/atoms/Table'
|
import Table from '@shared/atoms/Table'
|
||||||
import Button from '@shared/atoms/Button'
|
import Button from '@shared/atoms/Button'
|
||||||
import { useWeb3 } from '@context/Web3'
|
import { useWeb3 } from '@context/Web3'
|
||||||
@ -15,6 +13,7 @@ import styles from './index.module.css'
|
|||||||
import { useAsset } from '@context/Asset'
|
import { useAsset } from '@context/Asset'
|
||||||
import { useIsMounted } from '@hooks/useIsMounted'
|
import { useIsMounted } from '@hooks/useIsMounted'
|
||||||
import { useCancelToken } from '@hooks/useCancelToken'
|
import { useCancelToken } from '@hooks/useCancelToken'
|
||||||
|
import AssetListTitle from '@shared/AssetList/AssetListTitle'
|
||||||
|
|
||||||
export function Status({ children }: { children: string }): ReactElement {
|
export function Status({ children }: { children: string }): ReactElement {
|
||||||
return <div className={styles.status}>{children}</div>
|
return <div className={styles.status}>{children}</div>
|
||||||
@ -24,13 +23,7 @@ const columns = [
|
|||||||
{
|
{
|
||||||
name: 'Data Set',
|
name: 'Data Set',
|
||||||
selector: function getAssetRow(row: ComputeJobMetaData) {
|
selector: function getAssetRow(row: ComputeJobMetaData) {
|
||||||
return (
|
return <AssetListTitle did={row.inputDID[0]} title={row.assetName} />
|
||||||
<Dotdotdot clamp={2}>
|
|
||||||
<Link href={`/asset/${row.inputDID[0]}`}>
|
|
||||||
<a>{row.assetName}</a>
|
|
||||||
</Link>
|
|
||||||
</Dotdotdot>
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -41,8 +41,8 @@ export const wizardSteps: StepContent[] = [
|
|||||||
const computeOptions: ServiceComputeOptions = {
|
const computeOptions: ServiceComputeOptions = {
|
||||||
allowRawAlgorithm: false,
|
allowRawAlgorithm: false,
|
||||||
allowNetworkAccess: true,
|
allowNetworkAccess: true,
|
||||||
publisherTrustedAlgorithmPublishers: null,
|
publisherTrustedAlgorithmPublishers: [],
|
||||||
publisherTrustedAlgorithms: null
|
publisherTrustedAlgorithms: []
|
||||||
}
|
}
|
||||||
|
|
||||||
export const initialValues: FormPublishData = {
|
export const initialValues: FormPublishData = {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user