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 =
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.'

View File

@ -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(
const priceDataset = new Decimal(
datasetOrderPriceAndFees?.price || asset.accessDetails.price
).toDecimalPlaces(MAX_DECIMALS)
const priceAlgo =
hasPreviousOrderSelectedComputeAsset || hasDatatokenSelectedComputeAsset
? new Decimal(0)

View File

@ -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,