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

fix connection and networks calculations

This commit is contained in:
EnzoVezzaro 2022-10-26 08:25:52 -04:00
parent 8c88d512bf
commit 589963e368
3 changed files with 40 additions and 20 deletions

View File

@ -119,27 +119,28 @@ export default function FormStartCompute({
useEffect(() => {
if (!asset?.accessDetails || !selectedAlgorithmAsset?.accessDetails) return
setDatasetOrderPrice(
datasetOrderPriceAndFees?.price || asset.accessDetails.price
)
setAlgoOrderPrice(
algoOrderPriceAndFees?.price ||
selectedAlgorithmAsset?.accessDetails.price
)
const priceDataset = new Decimal(
hasPreviousOrder || hasDatatoken
? 0
isAssetNetwork
? hasPreviousOrder || hasDatatoken
? 0
: datasetOrderPriceAndFees?.price || asset.accessDetails.price
: datasetOrderPriceAndFees?.price || asset.accessDetails.price
).toDecimalPlaces(MAX_DECIMALS)
const priceAlgo =
hasPreviousOrderSelectedComputeAsset || hasDatatokenSelectedComputeAsset
? new Decimal(0)
: new Decimal(
algoOrderPriceAndFees?.price ||
selectedAlgorithmAsset.accessDetails.price
).toDecimalPlaces(MAX_DECIMALS)
setDatasetOrderPrice(priceDataset.toString())
const priceAlgo = new Decimal(
isAssetNetwork
? hasPreviousOrderSelectedComputeAsset ||
hasDatatokenSelectedComputeAsset
? 0
: algoOrderPriceAndFees?.price ||
selectedAlgorithmAsset.accessDetails.price
: algoOrderPriceAndFees?.price ||
selectedAlgorithmAsset.accessDetails.price
).toDecimalPlaces(MAX_DECIMALS)
setAlgoOrderPrice(priceAlgo.toString())
const providerFees = providerFeeAmount
? new Decimal(providerFeeAmount).toDecimalPlaces(MAX_DECIMALS)
@ -160,7 +161,8 @@ export default function FormStartCompute({
hasDatatokenSelectedComputeAsset,
datasetOrderPriceAndFees,
algoOrderPriceAndFees,
providerFeeAmount
providerFeeAmount,
isAssetNetwork
])
useEffect(() => {
@ -175,6 +177,8 @@ export default function FormStartCompute({
)
}, [totalPrice, balance, dtBalance, asset?.accessDetails?.baseToken?.symbol])
console.log(totalPrice, datasetOrderPrice, algoOrderPrice)
return (
<Form className={styles.form}>
<Alert

View File

@ -5,6 +5,7 @@ import Tooltip from '@shared/atoms/Tooltip'
import styles from './PriceOutput.module.css'
import { MAX_DECIMALS } from '@utils/constants'
import Decimal from 'decimal.js'
import { useWeb3 } from '@context/Web3'
interface PriceOutputProps {
totalPrice: string
@ -39,13 +40,21 @@ function Row({
sign?: string
type?: string
}) {
const { isSupportedOceanNetwork } = useWeb3()
return (
<div className={styles.priceRow}>
<div className={styles.sign}>{sign}</div>
<div className={styles.type}>{type}</div>
<div>
<PriceUnit
price={hasPreviousOrder || hasDatatoken ? 0 : Number(price)}
price={
!isSupportedOceanNetwork
? hasPreviousOrder || hasDatatoken
? 0
: Number(price)
: Number(price)
}
symbol={symbol}
size="small"
className={styles.price}

View File

@ -45,6 +45,7 @@ import { getComputeFeedback } from '@utils/feedback'
import { getDummyWeb3 } from '@utils/web3'
import { initializeProviderForCompute } from '@utils/provider'
import { useUserPreferences } from '@context/UserPreferences'
import { useAsset } from '@context/Asset'
const refreshInterval = 10000 // 10 sec.
export default function Compute({
@ -62,6 +63,8 @@ export default function Compute({
}): ReactElement {
const { accountId, web3, isSupportedOceanNetwork } = useWeb3()
const { chainIds } = useUserPreferences()
const { isAssetNetwork } = useAsset()
const newAbortController = useAbortController()
const newCancelToken = useCancelToken()
@ -146,8 +149,12 @@ export default function Compute({
setInitializedProviderResponse(initializedProvider)
console.log('here')
const feeAmount = await unitsToAmount(
!isSupportedOceanNetwork ? await getDummyWeb3(asset?.chainId) : web3,
!isSupportedOceanNetwork || !isAssetNetwork
? await getDummyWeb3(asset?.chainId)
: web3,
initializedProvider?.datasets?.[0]?.providerFee?.providerFeeToken,
initializedProvider?.datasets?.[0]?.providerFee?.providerFeeAmount
)