1
0
mirror of https://github.com/oceanprotocol/market.git synced 2024-12-02 05:57:29 +01:00

allow calculations on unsupported network & user not connected

This commit is contained in:
Enzo Vezzaro 2022-06-24 09:06:13 -04:00
parent db1e1f8fae
commit 7023247894
3 changed files with 27 additions and 17 deletions

View File

@ -51,13 +51,15 @@ function getConsumeHelpText(
const text = const text =
isConsumable === false isConsumable === false
? consumableFeedback ? consumableFeedback
: hasPreviousOrder && web3 : hasPreviousOrder && web3 && isSupportedOceanNetwork
? `You bought this ${assetType} already allowing you to use it without paying again.` ? `You bought this ${assetType} already allowing you to use it without paying again.`
: hasDatatoken : hasDatatoken
? `You own ${dtBalance} ${dtSymbol} allowing you to use this data set by spending 1 ${dtSymbol}, but without paying OCEAN again.` ? `You own ${dtBalance} ${dtSymbol} allowing you to use this data set by spending 1 ${dtSymbol}, but without paying OCEAN again.`
: lowPoolLiquidity : lowPoolLiquidity
? `There are not enought ${dtSymbol} available in the pool for the transaction to take place` ? `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.' ? '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.` : `For using this ${assetType}, you will buy 1 ${dtSymbol} and immediately spend it back to the publisher and pool.`
return text return text
@ -73,20 +75,23 @@ function getAlgoHelpText(
hasDatatokenSelectedComputeAsset: boolean, hasDatatokenSelectedComputeAsset: boolean,
selectedComputeAssettLowPoolLiquidity: boolean, selectedComputeAssettLowPoolLiquidity: boolean,
isBalanceSufficient: boolean, isBalanceSufficient: boolean,
isSupportedOceanNetwork: boolean isSupportedOceanNetwork: boolean,
web3: any
) { ) {
const text = const text =
(!dtSymbolSelectedComputeAsset && !dtBalanceSelectedComputeAsset) || (!dtSymbolSelectedComputeAsset && !dtBalanceSelectedComputeAsset) ||
isConsumable === false || isConsumable === false ||
isAlgorithmConsumable === false isAlgorithmConsumable === false
? '' ? ''
: hasPreviousOrderSelectedComputeAsset : hasPreviousOrderSelectedComputeAsset && web3 && isSupportedOceanNetwork
? `You already bought the selected ${selectedComputeAssetType}, allowing you to use it without paying again.` ? `You already bought the selected ${selectedComputeAssetType}, allowing you to use it without paying again.`
: hasDatatokenSelectedComputeAsset : hasDatatokenSelectedComputeAsset
? `You own ${dtBalanceSelectedComputeAsset} ${dtSymbolSelectedComputeAsset} allowing you to use the selected ${selectedComputeAssetType} by spending 1 ${dtSymbolSelectedComputeAsset}, but without paying OCEAN again.` ? `You own ${dtBalanceSelectedComputeAsset} ${dtSymbolSelectedComputeAsset} allowing you to use the selected ${selectedComputeAssetType} by spending 1 ${dtSymbolSelectedComputeAsset}, but without paying OCEAN again.`
: selectedComputeAssettLowPoolLiquidity : selectedComputeAssettLowPoolLiquidity
? `There are not enought ${dtSymbolSelectedComputeAsset} available in the pool for the transaction to take place` ? `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.` : `Additionally, you will buy 1 ${dtSymbolSelectedComputeAsset} for the ${selectedComputeAssetType} and spend it back to its publisher and pool.`
return text return text
@ -137,10 +142,13 @@ function getComputeAssetHelpText(
hasDatatokenSelectedComputeAsset, hasDatatokenSelectedComputeAsset,
selectedComputeAssettLowPoolLiquidity, selectedComputeAssettLowPoolLiquidity,
isBalanceSufficient, 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.' ? '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.' : 'C2D resources required to start the job are available, no payment required for those fees.'

View File

@ -80,7 +80,7 @@ export default function FormStartCompute({
validUntil?: string validUntil?: string
}): ReactElement { }): ReactElement {
const { siteContent } = useMarketMetadata() const { siteContent } = useMarketMetadata()
const { accountId, balance } = useWeb3() const { accountId, balance, isSupportedOceanNetwork } = useWeb3()
const { isValid, values }: FormikContextType<{ algorithm: string }> = const { isValid, values }: FormikContextType<{ algorithm: string }> =
useFormikContext() useFormikContext()
const { asset, isAssetNetwork } = useAsset() const { asset, isAssetNetwork } = useAsset()
@ -103,7 +103,7 @@ export default function FormStartCompute({
} }
useEffect(() => { useEffect(() => {
if (!values.algorithm || !accountId || !isConsumable) return if (!values.algorithm || !isConsumable) return
async function fetchAlgorithmAssetExtended() { async function fetchAlgorithmAssetExtended() {
const algorithmAsset = getAlgorithmAsset(values.algorithm) const algorithmAsset = getAlgorithmAsset(values.algorithm)
@ -136,12 +136,10 @@ export default function FormStartCompute({
algoOrderPriceAndFees?.price || algoOrderPriceAndFees?.price ||
selectedAlgorithmAsset?.accessDetails.price selectedAlgorithmAsset?.accessDetails.price
) )
const priceDataset = const priceDataset = new Decimal(
hasPreviousOrder || hasDatatoken
? new Decimal(0)
: new Decimal(
datasetOrderPriceAndFees?.price || asset.accessDetails.price datasetOrderPriceAndFees?.price || asset.accessDetails.price
).toDecimalPlaces(MAX_DECIMALS) ).toDecimalPlaces(MAX_DECIMALS)
const priceAlgo = const priceAlgo =
hasPreviousOrderSelectedComputeAsset || hasDatatokenSelectedComputeAsset hasPreviousOrderSelectedComputeAsset || hasDatatokenSelectedComputeAsset
? new Decimal(0) ? new Decimal(0)

View File

@ -132,9 +132,10 @@ export default function Compute({
const initializedProvider = await initializeProviderForCompute( const initializedProvider = await initializeProviderForCompute(
asset, asset,
selectedAlgorithmAsset, selectedAlgorithmAsset,
accountId, accountId || ZERO_ADDRESS, // if the user is not connected, we use ZERO_ADDRESS as accountId
computeEnv computeEnv
) )
if ( if (
!initializedProvider || !initializedProvider ||
!initializedProvider?.datasets || !initializedProvider?.datasets ||
@ -143,9 +144,10 @@ export default function Compute({
throw new Error(`Error initializing provider for the compute job!`) throw new Error(`Error initializing provider for the compute job!`)
setInitializedProviderResponse(initializedProvider) setInitializedProviderResponse(initializedProvider)
setProviderFeeAmount( setProviderFeeAmount(
await unitsToAmount( await unitsToAmount(
web3, web3 || (await getDummyWeb3(asset?.chainId)),
initializedProvider?.datasets?.[0]?.providerFee?.providerFeeToken, initializedProvider?.datasets?.[0]?.providerFee?.providerFeeToken,
initializedProvider?.datasets?.[0]?.providerFee?.providerFeeAmount initializedProvider?.datasets?.[0]?.providerFee?.providerFeeAmount
) )
@ -304,6 +306,7 @@ export default function Compute({
documentId: selectedAlgorithmAsset.id, documentId: selectedAlgorithmAsset.id,
serviceId: selectedAlgorithmAsset.services[0].id serviceId: selectedAlgorithmAsset.services[0].id
} }
const allowed = await isOrderable( const allowed = await isOrderable(
asset, asset,
computeService.id, computeService.id,
@ -329,6 +332,7 @@ export default function Compute({
: 3 : 3
] ]
) )
const datasetOrderTx = await handleComputeOrder( const datasetOrderTx = await handleComputeOrder(
web3, web3,
asset, asset,