diff --git a/src/components/@shared/ButtonBuy/index.tsx b/src/components/@shared/ButtonBuy/index.tsx index 74e120f47..d0c8b6673 100644 --- a/src/components/@shared/ButtonBuy/index.tsx +++ b/src/components/@shared/ButtonBuy/index.tsx @@ -51,13 +51,15 @@ function getConsumeHelpText( const text = isConsumable === false ? consumableFeedback - : hasPreviousOrder && web3 + : hasPreviousOrder && web3 && isSupportedOceanNetwork ? `You bought this ${assetType} already allowing you to use it without paying again.` : hasDatatoken ? `You own ${dtBalance} ${dtSymbol} allowing you to use this data set by spending 1 ${dtSymbol}, but without paying OCEAN again.` : lowPoolLiquidity ? `There are not enought ${dtSymbol} available in the pool for the transaction to take place` - : isBalanceSufficient === false && isSupportedOceanNetwork + : web3 && !isSupportedOceanNetwork + ? `You are connected to an unsupported network.` + : isBalanceSufficient === false ? 'You do not have enough OCEAN in your wallet to purchase this asset.' : `For using this ${assetType}, you will buy 1 ${dtSymbol} and immediately spend it back to the publisher and pool.` return text @@ -73,20 +75,23 @@ function getAlgoHelpText( hasDatatokenSelectedComputeAsset: boolean, selectedComputeAssettLowPoolLiquidity: boolean, isBalanceSufficient: boolean, - isSupportedOceanNetwork: boolean + isSupportedOceanNetwork: boolean, + web3: any ) { const text = (!dtSymbolSelectedComputeAsset && !dtBalanceSelectedComputeAsset) || isConsumable === false || isAlgorithmConsumable === false ? '' - : hasPreviousOrderSelectedComputeAsset + : hasPreviousOrderSelectedComputeAsset && web3 && isSupportedOceanNetwork ? `You already bought the selected ${selectedComputeAssetType}, allowing you to use it without paying again.` : hasDatatokenSelectedComputeAsset ? `You own ${dtBalanceSelectedComputeAsset} ${dtSymbolSelectedComputeAsset} allowing you to use the selected ${selectedComputeAssetType} by spending 1 ${dtSymbolSelectedComputeAsset}, but without paying OCEAN again.` : selectedComputeAssettLowPoolLiquidity ? `There are not enought ${dtSymbolSelectedComputeAsset} available in the pool for the transaction to take place` - : isBalanceSufficient === false && isSupportedOceanNetwork + : web3 && !isSupportedOceanNetwork + ? `Connect to the correct network to interact with this asset.` + : isBalanceSufficient === false ? '' : `Additionally, you will buy 1 ${dtSymbolSelectedComputeAsset} for the ${selectedComputeAssetType} and spend it back to its publisher and pool.` return text @@ -137,10 +142,13 @@ function getComputeAssetHelpText( hasDatatokenSelectedComputeAsset, selectedComputeAssettLowPoolLiquidity, isBalanceSufficient, - isSupportedOceanNetwork + isSupportedOceanNetwork, + web3 ) - const providerFeeHelpText = hasProviderFee + const providerFeeHelpText = !isSupportedOceanNetwork + ? '' + : hasProviderFee ? 'In order to start the job you also need to pay the fees for renting the c2d resources.' : 'C2D resources required to start the job are available, no payment required for those fees.' diff --git a/src/components/Asset/AssetActions/Compute/FormComputeDataset.tsx b/src/components/Asset/AssetActions/Compute/FormComputeDataset.tsx index 94c0ee88d..f0340774a 100644 --- a/src/components/Asset/AssetActions/Compute/FormComputeDataset.tsx +++ b/src/components/Asset/AssetActions/Compute/FormComputeDataset.tsx @@ -80,7 +80,7 @@ export default function FormStartCompute({ validUntil?: string }): ReactElement { const { siteContent } = useMarketMetadata() - const { accountId, balance } = useWeb3() + const { accountId, balance, isSupportedOceanNetwork } = useWeb3() const { isValid, values }: FormikContextType<{ algorithm: string }> = useFormikContext() const { asset, isAssetNetwork } = useAsset() @@ -103,7 +103,7 @@ export default function FormStartCompute({ } useEffect(() => { - if (!values.algorithm || !accountId || !isConsumable) return + if (!values.algorithm || !isConsumable) return async function fetchAlgorithmAssetExtended() { const algorithmAsset = getAlgorithmAsset(values.algorithm) @@ -136,12 +136,10 @@ export default function FormStartCompute({ algoOrderPriceAndFees?.price || selectedAlgorithmAsset?.accessDetails.price ) - const priceDataset = - hasPreviousOrder || hasDatatoken - ? new Decimal(0) - : new Decimal( - datasetOrderPriceAndFees?.price || asset.accessDetails.price - ).toDecimalPlaces(MAX_DECIMALS) + const priceDataset = new Decimal( + datasetOrderPriceAndFees?.price || asset.accessDetails.price + ).toDecimalPlaces(MAX_DECIMALS) + const priceAlgo = hasPreviousOrderSelectedComputeAsset || hasDatatokenSelectedComputeAsset ? new Decimal(0) diff --git a/src/components/Asset/AssetActions/Compute/index.tsx b/src/components/Asset/AssetActions/Compute/index.tsx index f1663ce20..025eda86f 100644 --- a/src/components/Asset/AssetActions/Compute/index.tsx +++ b/src/components/Asset/AssetActions/Compute/index.tsx @@ -132,9 +132,10 @@ export default function Compute({ const initializedProvider = await initializeProviderForCompute( asset, selectedAlgorithmAsset, - accountId, + accountId || ZERO_ADDRESS, // if the user is not connected, we use ZERO_ADDRESS as accountId computeEnv ) + if ( !initializedProvider || !initializedProvider?.datasets || @@ -143,9 +144,10 @@ export default function Compute({ throw new Error(`Error initializing provider for the compute job!`) setInitializedProviderResponse(initializedProvider) + setProviderFeeAmount( await unitsToAmount( - web3, + web3 || (await getDummyWeb3(asset?.chainId)), initializedProvider?.datasets?.[0]?.providerFee?.providerFeeToken, initializedProvider?.datasets?.[0]?.providerFee?.providerFeeAmount ) @@ -304,6 +306,7 @@ export default function Compute({ documentId: selectedAlgorithmAsset.id, serviceId: selectedAlgorithmAsset.services[0].id } + const allowed = await isOrderable( asset, computeService.id, @@ -329,6 +332,7 @@ export default function Compute({ : 3 ] ) + const datasetOrderTx = await handleComputeOrder( web3, asset,