mirror of
https://github.com/oceanprotocol/market.git
synced 2024-12-02 05:57:29 +01:00
adding dummyweb3 and zero_address to calculate price on unsupported network / not connected user
This commit is contained in:
parent
6a048d4c5c
commit
da934f789f
@ -16,9 +16,8 @@ export async function transformAssetToAssetSelection(
|
||||
|
||||
for (const asset of extendedAssets) {
|
||||
const algoComputeService = getServiceByName(asset, 'compute')
|
||||
|
||||
if (
|
||||
asset?.accessDetails.price &&
|
||||
asset?.accessDetails?.price &&
|
||||
algoComputeService?.serviceEndpoint === datasetProviderEndpoint
|
||||
) {
|
||||
let selected = false
|
||||
|
@ -2,6 +2,7 @@ import React, { FormEvent, ReactElement } from 'react'
|
||||
import Button from '../atoms/Button'
|
||||
import styles from './index.module.css'
|
||||
import Loader from '../atoms/Loader'
|
||||
import { useWeb3 } from '@context/Web3'
|
||||
|
||||
interface ButtonBuyProps {
|
||||
action: 'download' | 'compute'
|
||||
@ -43,12 +44,13 @@ function getConsumeHelpText(
|
||||
isConsumable: boolean,
|
||||
isBalanceSufficient: boolean,
|
||||
consumableFeedback: string,
|
||||
isSupportedOceanNetwork: boolean
|
||||
isSupportedOceanNetwork: boolean,
|
||||
web3: any
|
||||
) {
|
||||
const text =
|
||||
isConsumable === false
|
||||
? consumableFeedback
|
||||
: hasPreviousOrder
|
||||
: hasPreviousOrder && web3
|
||||
? `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.`
|
||||
@ -106,7 +108,8 @@ function getComputeAssetHelpText(
|
||||
selectedComputeAssettLowPoolLiquidity?: boolean,
|
||||
selectedComputeAssetType?: string,
|
||||
isAlgorithmConsumable?: boolean,
|
||||
isSupportedOceanNetwork?: boolean
|
||||
isSupportedOceanNetwork?: boolean,
|
||||
web3?: any
|
||||
) {
|
||||
const computeAssetHelpText = getConsumeHelpText(
|
||||
dtBalance,
|
||||
@ -118,7 +121,8 @@ function getComputeAssetHelpText(
|
||||
isConsumable,
|
||||
isBalanceSufficient,
|
||||
consumableFeedback,
|
||||
isSupportedOceanNetwork
|
||||
isSupportedOceanNetwork,
|
||||
web3
|
||||
)
|
||||
|
||||
const computeAlgoHelpText = getAlgoHelpText(
|
||||
@ -170,6 +174,7 @@ export default function ButtonBuy({
|
||||
isAlgorithmConsumable,
|
||||
isSupportedOceanNetwork
|
||||
}: ButtonBuyProps): ReactElement {
|
||||
const { web3 } = useWeb3()
|
||||
const buttonText =
|
||||
action === 'download'
|
||||
? hasPreviousOrder
|
||||
@ -210,7 +215,8 @@ export default function ButtonBuy({
|
||||
isConsumable,
|
||||
isBalanceSufficient,
|
||||
consumableFeedback,
|
||||
isSupportedOceanNetwork
|
||||
isSupportedOceanNetwork,
|
||||
web3
|
||||
)
|
||||
: getComputeAssetHelpText(
|
||||
hasPreviousOrder,
|
||||
@ -229,7 +235,8 @@ export default function ButtonBuy({
|
||||
selectedComputeAssetLowPoolLiquidity,
|
||||
selectedComputeAssetType,
|
||||
isAlgorithmConsumable,
|
||||
isSupportedOceanNetwork
|
||||
isSupportedOceanNetwork,
|
||||
web3
|
||||
)}
|
||||
</div>
|
||||
</>
|
||||
|
@ -9,7 +9,7 @@ import PriceOutput from './PriceOutput'
|
||||
import { useAsset } from '@context/Asset'
|
||||
import { useWeb3 } from '@context/Web3'
|
||||
import content from '../../../../../content/pages/startComputeDataset.json'
|
||||
import { Asset } from '@oceanprotocol/lib'
|
||||
import { Asset, ZERO_ADDRESS } from '@oceanprotocol/lib'
|
||||
import { AccessDetails, OrderPriceAndFees } from 'src/@types/Price'
|
||||
import {
|
||||
getAccessDetailsForAssets,
|
||||
@ -18,6 +18,7 @@ import {
|
||||
import { AssetExtended } from 'src/@types/AssetExtended'
|
||||
import Decimal from 'decimal.js'
|
||||
import { MAX_DECIMALS } from '@utils/constants'
|
||||
import { getDummyWeb3 } from '@utils/web3'
|
||||
|
||||
export default function FormStartCompute({
|
||||
algorithms,
|
||||
@ -94,14 +95,14 @@ export default function FormStartCompute({
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
if (!values.algorithm || !accountId || !isConsumable) return
|
||||
if (!values.algorithm || !isConsumable) return
|
||||
async function fetchAlgorithmAssetExtended() {
|
||||
const algorithmAsset = getAlgorithmAsset(values.algorithm)
|
||||
const accessDetails = await getAccessDetails(
|
||||
algorithmAsset.chainId,
|
||||
algorithmAsset.services[0].datatokenAddress,
|
||||
algorithmAsset.services[0].timeout,
|
||||
accountId
|
||||
accountId || ZERO_ADDRESS // if user is not connected, use ZERO_ADDRESS as accountId
|
||||
)
|
||||
const extendedAlgoAsset: AssetExtended = {
|
||||
...algorithmAsset,
|
||||
@ -121,6 +122,7 @@ export default function FormStartCompute({
|
||||
setDatasetOrderPrice(
|
||||
datasetOrderPriceAndFees?.price || asset.accessDetails.price
|
||||
)
|
||||
|
||||
setAlgoOrderPrice(
|
||||
algoOrderPriceAndFees?.price ||
|
||||
selectedAlgorithmAsset?.accessDetails.price
|
||||
@ -142,16 +144,17 @@ export default function FormStartCompute({
|
||||
.plus(priceAlgo)
|
||||
.toDecimalPlaces(MAX_DECIMALS)
|
||||
.toString()
|
||||
|
||||
setTotalPrice(totalPrice)
|
||||
}, [
|
||||
asset?.accessDetails,
|
||||
selectedAlgorithmAsset?.accessDetails,
|
||||
asset,
|
||||
hasPreviousOrder,
|
||||
hasDatatoken,
|
||||
hasPreviousOrderSelectedComputeAsset,
|
||||
hasDatatokenSelectedComputeAsset,
|
||||
datasetOrderPriceAndFees,
|
||||
algoOrderPriceAndFees
|
||||
algoOrderPriceAndFees,
|
||||
selectedAlgorithmAsset
|
||||
])
|
||||
|
||||
useEffect(() => {
|
||||
|
@ -65,6 +65,7 @@ export default function Compute({
|
||||
consumableFeedback?: string
|
||||
}): ReactElement {
|
||||
const { accountId, web3 } = useWeb3()
|
||||
|
||||
const [isJobStarting, setIsJobStarting] = useState(false)
|
||||
const [error, setError] = useState<string>()
|
||||
const newAbortController = useAbortController()
|
||||
@ -116,7 +117,7 @@ export default function Compute({
|
||||
const datatokenInstance = new Datatoken(web3)
|
||||
const dtBalance = await datatokenInstance.balance(
|
||||
asset?.services[0].datatokenAddress,
|
||||
accountId
|
||||
accountId || ZERO_ADDRESS // if the user is not connected, we use ZERO_ADDRESS as accountId
|
||||
)
|
||||
setAlgorithmDTBalance(new Decimal(dtBalance).toString())
|
||||
const hasAlgoDt = Number(dtBalance) >= 1
|
||||
@ -134,7 +135,7 @@ 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 (
|
||||
@ -176,12 +177,13 @@ export default function Compute({
|
||||
}
|
||||
: null
|
||||
const datasetPriceAndFees = await getOrderPriceAndFees(
|
||||
web3,
|
||||
web3 || (await getDummyWeb3(asset?.chainId)), // if the user is not connected, we need to use a dummy web3
|
||||
asset,
|
||||
ZERO_ADDRESS,
|
||||
accountId || ZERO_ADDRESS, // if the user is not connected, we need to use ZERO_ADDRESS as accountId
|
||||
poolParams,
|
||||
initializedProvider?.datasets?.[0]?.providerFee
|
||||
)
|
||||
|
||||
if (!datasetPriceAndFees) {
|
||||
setError('Error setting dataset price and fees!')
|
||||
return
|
||||
@ -224,12 +226,13 @@ export default function Compute({
|
||||
}
|
||||
}
|
||||
const algorithmOrderPriceAndFees = await getOrderPriceAndFees(
|
||||
web3,
|
||||
web3 || (await getDummyWeb3(asset?.chainId)),
|
||||
selectedAlgorithmAsset,
|
||||
ZERO_ADDRESS,
|
||||
accountId || ZERO_ADDRESS,
|
||||
algoPoolParams,
|
||||
initializedProvider.algorithm.providerFee
|
||||
)
|
||||
|
||||
if (!algorithmOrderPriceAndFees) {
|
||||
setError('Error setting algorithm price and fees!')
|
||||
return
|
||||
@ -247,7 +250,7 @@ export default function Compute({
|
||||
}, [asset?.accessDetails])
|
||||
|
||||
useEffect(() => {
|
||||
if (!selectedAlgorithmAsset?.accessDetails || !accountId) return
|
||||
if (!selectedAlgorithmAsset?.accessDetails) return
|
||||
|
||||
setIsRequestingAlgoOrderPrice(true)
|
||||
setIsConsumablePrice(selectedAlgorithmAsset?.accessDetails?.isPurchasable)
|
||||
|
Loading…
Reference in New Issue
Block a user