mirror of
https://github.com/oceanprotocol/market.git
synced 2024-12-02 05:57:29 +01:00
C2D fixes (#1715)
This commit is contained in:
parent
d1e3fa9afa
commit
c780411b74
5
src/@types/Compute.d.ts
vendored
5
src/@types/Compute.d.ts
vendored
@ -27,4 +27,9 @@ declare global {
|
|||||||
computeJobs: ComputeJobMetaData[]
|
computeJobs: ComputeJobMetaData[]
|
||||||
isLoaded: boolean
|
isLoaded: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interface totalPriceMap {
|
||||||
|
value: string
|
||||||
|
symbol: string
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,18 +1,13 @@
|
|||||||
import { LoggerInstance, Dispenser, Datatoken } from '@oceanprotocol/lib'
|
import { LoggerInstance, Datatoken } from '@oceanprotocol/lib'
|
||||||
import Web3 from 'web3'
|
import Web3 from 'web3'
|
||||||
import { TransactionReceipt } from 'web3-core'
|
import { TransactionReceipt } from 'web3-core'
|
||||||
|
|
||||||
export async function setMinterToPublisher(
|
export async function setMinterToPublisher(
|
||||||
web3: Web3,
|
web3: Web3,
|
||||||
dispenserAddress: string,
|
|
||||||
datatokenAddress: string,
|
datatokenAddress: string,
|
||||||
accountId: string,
|
accountId: string,
|
||||||
setError: (msg: string) => void
|
setError: (msg: string) => void
|
||||||
): Promise<TransactionReceipt> {
|
): Promise<TransactionReceipt> {
|
||||||
const dispenserInstance = new Dispenser(dispenserAddress, web3)
|
|
||||||
const status = await dispenserInstance.status(datatokenAddress)
|
|
||||||
if (!status?.active) return
|
|
||||||
|
|
||||||
const datatokenInstance = new Datatoken(web3)
|
const datatokenInstance = new Datatoken(web3)
|
||||||
|
|
||||||
const response = await datatokenInstance.removeMinter(
|
const response = await datatokenInstance.removeMinter(
|
||||||
@ -20,6 +15,7 @@ export async function setMinterToPublisher(
|
|||||||
accountId,
|
accountId,
|
||||||
accountId
|
accountId
|
||||||
)
|
)
|
||||||
|
|
||||||
if (!response) {
|
if (!response) {
|
||||||
setError('Updating DDO failed.')
|
setError('Updating DDO failed.')
|
||||||
LoggerInstance.error('Failed at cancelMinter')
|
LoggerInstance.error('Failed at cancelMinter')
|
||||||
|
@ -11,11 +11,11 @@ import { useWeb3 } from '@context/Web3'
|
|||||||
import content from '../../../../../content/pages/startComputeDataset.json'
|
import content from '../../../../../content/pages/startComputeDataset.json'
|
||||||
import { Asset } from '@oceanprotocol/lib'
|
import { Asset } from '@oceanprotocol/lib'
|
||||||
import { getAccessDetails } from '@utils/accessDetailsAndPricing'
|
import { getAccessDetails } from '@utils/accessDetailsAndPricing'
|
||||||
import Decimal from 'decimal.js'
|
|
||||||
import { MAX_DECIMALS } from '@utils/constants'
|
|
||||||
import { useMarketMetadata } from '@context/MarketMetadata'
|
import { useMarketMetadata } from '@context/MarketMetadata'
|
||||||
import Alert from '@shared/atoms/Alert'
|
import Alert from '@shared/atoms/Alert'
|
||||||
import { getTokenBalanceFromSymbol } from '@utils/web3'
|
import { getTokenBalanceFromSymbol } from '@utils/web3'
|
||||||
|
import { MAX_DECIMALS } from '@utils/constants'
|
||||||
|
import Decimal from 'decimal.js'
|
||||||
|
|
||||||
export default function FormStartCompute({
|
export default function FormStartCompute({
|
||||||
algorithms,
|
algorithms,
|
||||||
@ -31,7 +31,8 @@ export default function FormStartCompute({
|
|||||||
assetTimeout,
|
assetTimeout,
|
||||||
hasPreviousOrderSelectedComputeAsset,
|
hasPreviousOrderSelectedComputeAsset,
|
||||||
hasDatatokenSelectedComputeAsset,
|
hasDatatokenSelectedComputeAsset,
|
||||||
oceanSymbol,
|
datasetSymbol,
|
||||||
|
algorithmSymbol,
|
||||||
dtSymbolSelectedComputeAsset,
|
dtSymbolSelectedComputeAsset,
|
||||||
dtBalanceSelectedComputeAsset,
|
dtBalanceSelectedComputeAsset,
|
||||||
selectedComputeAssetType,
|
selectedComputeAssetType,
|
||||||
@ -57,7 +58,8 @@ export default function FormStartCompute({
|
|||||||
assetTimeout: string
|
assetTimeout: string
|
||||||
hasPreviousOrderSelectedComputeAsset?: boolean
|
hasPreviousOrderSelectedComputeAsset?: boolean
|
||||||
hasDatatokenSelectedComputeAsset?: boolean
|
hasDatatokenSelectedComputeAsset?: boolean
|
||||||
oceanSymbol?: string
|
datasetSymbol?: string
|
||||||
|
algorithmSymbol?: string
|
||||||
dtSymbolSelectedComputeAsset?: string
|
dtSymbolSelectedComputeAsset?: string
|
||||||
dtBalanceSelectedComputeAsset?: string
|
dtBalanceSelectedComputeAsset?: string
|
||||||
selectedComputeAssetType?: string
|
selectedComputeAssetType?: string
|
||||||
@ -76,14 +78,14 @@ export default function FormStartCompute({
|
|||||||
useFormikContext()
|
useFormikContext()
|
||||||
const { asset, isAssetNetwork } = useAsset()
|
const { asset, isAssetNetwork } = useAsset()
|
||||||
|
|
||||||
const [totalPrice, setTotalPrice] = useState('0')
|
|
||||||
const [datasetOrderPrice, setDatasetOrderPrice] = useState(
|
const [datasetOrderPrice, setDatasetOrderPrice] = useState(
|
||||||
asset?.accessDetails?.price
|
asset?.accessDetails?.price
|
||||||
)
|
)
|
||||||
const [algoOrderPrice, setAlgoOrderPrice] = useState(
|
const [algoOrderPrice, setAlgoOrderPrice] = useState(
|
||||||
selectedAlgorithmAsset?.accessDetails?.price
|
selectedAlgorithmAsset?.accessDetails?.price
|
||||||
)
|
)
|
||||||
const [isBalanceSufficient, setIsBalanceSufficient] = useState<boolean>(false)
|
const [totalPrices, setTotalPrices] = useState([])
|
||||||
|
const [isBalanceSufficient, setIsBalanceSufficient] = useState<boolean>(true)
|
||||||
|
|
||||||
function getAlgorithmAsset(algorithmId: string): Asset {
|
function getAlgorithmAsset(algorithmId: string): Asset {
|
||||||
let assetDdo = null
|
let assetDdo = null
|
||||||
@ -126,28 +128,73 @@ export default function FormStartCompute({
|
|||||||
algoOrderPriceAndFees?.price ||
|
algoOrderPriceAndFees?.price ||
|
||||||
selectedAlgorithmAsset?.accessDetails.price
|
selectedAlgorithmAsset?.accessDetails.price
|
||||||
)
|
)
|
||||||
|
const totalPrices: totalPriceMap[] = []
|
||||||
const priceDataset =
|
const priceDataset =
|
||||||
hasPreviousOrder || hasDatatoken
|
!datasetOrderPrice || hasPreviousOrder || hasDatatoken
|
||||||
? new Decimal(0)
|
? new Decimal(0)
|
||||||
: new Decimal(
|
: new Decimal(datasetOrderPrice).toDecimalPlaces(MAX_DECIMALS)
|
||||||
datasetOrderPriceAndFees?.price || asset.accessDetails.price
|
|
||||||
).toDecimalPlaces(MAX_DECIMALS)
|
|
||||||
const priceAlgo =
|
const priceAlgo =
|
||||||
hasPreviousOrderSelectedComputeAsset || hasDatatokenSelectedComputeAsset
|
!algoOrderPrice ||
|
||||||
|
hasPreviousOrderSelectedComputeAsset ||
|
||||||
|
hasDatatokenSelectedComputeAsset
|
||||||
? new Decimal(0)
|
? new Decimal(0)
|
||||||
: new Decimal(
|
: new Decimal(algoOrderPrice).toDecimalPlaces(MAX_DECIMALS)
|
||||||
algoOrderPriceAndFees?.price ||
|
|
||||||
selectedAlgorithmAsset.accessDetails.price
|
|
||||||
).toDecimalPlaces(MAX_DECIMALS)
|
|
||||||
const providerFees = providerFeeAmount
|
const providerFees = providerFeeAmount
|
||||||
? new Decimal(providerFeeAmount).toDecimalPlaces(MAX_DECIMALS)
|
? new Decimal(providerFeeAmount).toDecimalPlaces(MAX_DECIMALS)
|
||||||
: new Decimal(0)
|
: new Decimal(0)
|
||||||
const totalPrice = priceDataset
|
|
||||||
.plus(priceAlgo)
|
if (algorithmSymbol === 'OCEAN') {
|
||||||
.plus(providerFees)
|
let sum = providerFees.add(priceAlgo)
|
||||||
.toDecimalPlaces(MAX_DECIMALS)
|
totalPrices.push({
|
||||||
.toString()
|
value: sum.toDecimalPlaces(MAX_DECIMALS).toString(),
|
||||||
setTotalPrice(totalPrice)
|
symbol: algorithmSymbol
|
||||||
|
})
|
||||||
|
if (algorithmSymbol === datasetSymbol) {
|
||||||
|
sum = sum.add(priceDataset)
|
||||||
|
totalPrices[0].value = sum.toDecimalPlaces(MAX_DECIMALS).toString()
|
||||||
|
} else {
|
||||||
|
totalPrices.push({
|
||||||
|
value: priceDataset.toDecimalPlaces(MAX_DECIMALS).toString(),
|
||||||
|
symbol: datasetSymbol
|
||||||
|
})
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (datasetSymbol === 'OCEAN') {
|
||||||
|
const sum = providerFees.add(priceDataset)
|
||||||
|
totalPrices.push({
|
||||||
|
value: sum.toDecimalPlaces(MAX_DECIMALS).toString(),
|
||||||
|
symbol: datasetSymbol
|
||||||
|
})
|
||||||
|
totalPrices.push({
|
||||||
|
value: priceAlgo.toDecimalPlaces(MAX_DECIMALS).toString(),
|
||||||
|
symbol: algorithmSymbol
|
||||||
|
})
|
||||||
|
} else if (datasetSymbol === algorithmSymbol) {
|
||||||
|
const sum = priceAlgo.add(priceDataset)
|
||||||
|
totalPrices.push({
|
||||||
|
value: sum.toDecimalPlaces(MAX_DECIMALS).toString(),
|
||||||
|
symbol: algorithmSymbol
|
||||||
|
})
|
||||||
|
totalPrices.push({
|
||||||
|
value: providerFees.toDecimalPlaces(MAX_DECIMALS).toString(),
|
||||||
|
symbol: 'OCEAN'
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
totalPrices.push({
|
||||||
|
value: priceDataset.toDecimalPlaces(MAX_DECIMALS).toString(),
|
||||||
|
symbol: datasetSymbol
|
||||||
|
})
|
||||||
|
totalPrices.push({
|
||||||
|
value: providerFees.toDecimalPlaces(MAX_DECIMALS).toString(),
|
||||||
|
symbol: 'OCEAN'
|
||||||
|
})
|
||||||
|
totalPrices.push({
|
||||||
|
value: priceAlgo.toDecimalPlaces(MAX_DECIMALS).toString(),
|
||||||
|
symbol: algorithmSymbol
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
setTotalPrices(totalPrices)
|
||||||
}, [
|
}, [
|
||||||
asset?.accessDetails,
|
asset?.accessDetails,
|
||||||
selectedAlgorithmAsset?.accessDetails,
|
selectedAlgorithmAsset?.accessDetails,
|
||||||
@ -161,16 +208,18 @@ export default function FormStartCompute({
|
|||||||
])
|
])
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const baseTokenBalance = getTokenBalanceFromSymbol(
|
totalPrices.forEach((price) => {
|
||||||
balance,
|
const baseTokenBalance = getTokenBalanceFromSymbol(balance, price.symbol)
|
||||||
asset?.accessDetails?.baseToken?.symbol
|
if (!baseTokenBalance) {
|
||||||
)
|
setIsBalanceSufficient(false)
|
||||||
|
return
|
||||||
if (!totalPrice || !baseTokenBalance || !dtBalance) return
|
}
|
||||||
setIsBalanceSufficient(
|
// if one comparison of baseTokenBalance and token price comparison is false then the state will be false
|
||||||
compareAsBN(baseTokenBalance, `${totalPrice}`) || Number(dtBalance) >= 1
|
setIsBalanceSufficient(
|
||||||
)
|
isBalanceSufficient && compareAsBN(baseTokenBalance, `${price.value}`)
|
||||||
}, [totalPrice, balance, dtBalance, asset?.accessDetails?.baseToken?.symbol])
|
)
|
||||||
|
})
|
||||||
|
}, [balance, dtBalance, datasetSymbol, algorithmSymbol])
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Form className={styles.form}>
|
<Form className={styles.form}>
|
||||||
@ -201,12 +250,13 @@ export default function FormStartCompute({
|
|||||||
selectedComputeAssetTimeout={selectedComputeAssetTimeout}
|
selectedComputeAssetTimeout={selectedComputeAssetTimeout}
|
||||||
hasDatatokenSelectedComputeAsset={hasDatatokenSelectedComputeAsset}
|
hasDatatokenSelectedComputeAsset={hasDatatokenSelectedComputeAsset}
|
||||||
algorithmConsumeDetails={selectedAlgorithmAsset?.accessDetails}
|
algorithmConsumeDetails={selectedAlgorithmAsset?.accessDetails}
|
||||||
symbol={oceanSymbol}
|
symbol={datasetSymbol}
|
||||||
totalPrice={totalPrice}
|
algorithmSymbol={algorithmSymbol}
|
||||||
datasetOrderPrice={datasetOrderPrice}
|
datasetOrderPrice={datasetOrderPrice}
|
||||||
algoOrderPrice={algoOrderPrice}
|
algoOrderPrice={algoOrderPrice}
|
||||||
providerFeeAmount={providerFeeAmount}
|
providerFeeAmount={providerFeeAmount}
|
||||||
validUntil={validUntil}
|
validUntil={validUntil}
|
||||||
|
totalPrices={totalPrices}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<ButtonBuy
|
<ButtonBuy
|
||||||
|
@ -7,7 +7,6 @@ import { MAX_DECIMALS } from '@utils/constants'
|
|||||||
import Decimal from 'decimal.js'
|
import Decimal from 'decimal.js'
|
||||||
|
|
||||||
interface PriceOutputProps {
|
interface PriceOutputProps {
|
||||||
totalPrice: string
|
|
||||||
hasPreviousOrder: boolean
|
hasPreviousOrder: boolean
|
||||||
hasDatatoken: boolean
|
hasDatatoken: boolean
|
||||||
symbol: string
|
symbol: string
|
||||||
@ -15,11 +14,13 @@ interface PriceOutputProps {
|
|||||||
hasPreviousOrderSelectedComputeAsset: boolean
|
hasPreviousOrderSelectedComputeAsset: boolean
|
||||||
hasDatatokenSelectedComputeAsset: boolean
|
hasDatatokenSelectedComputeAsset: boolean
|
||||||
algorithmConsumeDetails: AccessDetails
|
algorithmConsumeDetails: AccessDetails
|
||||||
|
algorithmSymbol: string
|
||||||
selectedComputeAssetTimeout: string
|
selectedComputeAssetTimeout: string
|
||||||
datasetOrderPrice?: string
|
datasetOrderPrice?: string
|
||||||
algoOrderPrice?: string
|
algoOrderPrice?: string
|
||||||
providerFeeAmount?: string
|
providerFeeAmount?: string
|
||||||
validUntil?: string
|
validUntil?: string
|
||||||
|
totalPrices?: totalPriceMap[]
|
||||||
}
|
}
|
||||||
|
|
||||||
function Row({
|
function Row({
|
||||||
@ -62,7 +63,6 @@ function Row({
|
|||||||
}
|
}
|
||||||
|
|
||||||
export default function PriceOutput({
|
export default function PriceOutput({
|
||||||
totalPrice,
|
|
||||||
hasPreviousOrder,
|
hasPreviousOrder,
|
||||||
hasDatatoken,
|
hasDatatoken,
|
||||||
assetTimeout,
|
assetTimeout,
|
||||||
@ -70,18 +70,30 @@ export default function PriceOutput({
|
|||||||
hasPreviousOrderSelectedComputeAsset,
|
hasPreviousOrderSelectedComputeAsset,
|
||||||
hasDatatokenSelectedComputeAsset,
|
hasDatatokenSelectedComputeAsset,
|
||||||
algorithmConsumeDetails,
|
algorithmConsumeDetails,
|
||||||
|
algorithmSymbol,
|
||||||
selectedComputeAssetTimeout,
|
selectedComputeAssetTimeout,
|
||||||
datasetOrderPrice,
|
datasetOrderPrice,
|
||||||
algoOrderPrice,
|
algoOrderPrice,
|
||||||
providerFeeAmount,
|
providerFeeAmount,
|
||||||
validUntil
|
validUntil,
|
||||||
|
totalPrices
|
||||||
}: PriceOutputProps): ReactElement {
|
}: PriceOutputProps): ReactElement {
|
||||||
const { asset } = useAsset()
|
const { asset } = useAsset()
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={styles.priceComponent}>
|
<div className={styles.priceComponent}>
|
||||||
You will pay{' '}
|
You will pay{' '}
|
||||||
<PriceUnit price={Number(totalPrice)} symbol={symbol} size="small" />
|
{totalPrices.map((item, index) => (
|
||||||
|
<div key={item.symbol}>
|
||||||
|
<PriceUnit
|
||||||
|
price={Number(item.value)}
|
||||||
|
symbol={
|
||||||
|
index < totalPrices.length - 1 ? `${item.symbol} & ` : item.symbol
|
||||||
|
}
|
||||||
|
size="small"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
))}
|
||||||
<Tooltip
|
<Tooltip
|
||||||
content={
|
content={
|
||||||
<div className={styles.calculation}>
|
<div className={styles.calculation}>
|
||||||
@ -106,18 +118,25 @@ export default function PriceOutput({
|
|||||||
.toDecimalPlaces(MAX_DECIMALS)
|
.toDecimalPlaces(MAX_DECIMALS)
|
||||||
.toString()}
|
.toString()}
|
||||||
timeout={selectedComputeAssetTimeout}
|
timeout={selectedComputeAssetTimeout}
|
||||||
symbol={symbol}
|
symbol={algorithmSymbol}
|
||||||
sign="+"
|
sign="+"
|
||||||
type="ALGORITHM"
|
type="ALGORITHM"
|
||||||
/>
|
/>
|
||||||
<Row
|
<Row
|
||||||
price={providerFeeAmount} // initializeCompute.provider fee amount
|
price={providerFeeAmount} // initializeCompute.provider fee amount
|
||||||
timeout={`${validUntil} seconds`} // valid until value
|
timeout={`${validUntil} seconds`} // valid until value
|
||||||
symbol={symbol}
|
symbol={'OCEAN'} // we assume that provider fees will always be in OCEAN token
|
||||||
sign="+"
|
sign="+"
|
||||||
type="C2D RESOURCES"
|
type="C2D RESOURCES"
|
||||||
/>
|
/>
|
||||||
<Row price={totalPrice} symbol={symbol} sign="=" />
|
{totalPrices.map((item, index) => (
|
||||||
|
<Row
|
||||||
|
price={item.value}
|
||||||
|
symbol={item.symbol}
|
||||||
|
sign={index === 0 ? '=' : '&'}
|
||||||
|
key={item.symbol}
|
||||||
|
/>
|
||||||
|
))}
|
||||||
</div>
|
</div>
|
||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
|
@ -456,8 +456,8 @@ export default function Compute({
|
|||||||
validAlgorithmOrderTx !== undefined
|
validAlgorithmOrderTx !== undefined
|
||||||
}
|
}
|
||||||
hasDatatokenSelectedComputeAsset={hasAlgoAssetDatatoken}
|
hasDatatokenSelectedComputeAsset={hasAlgoAssetDatatoken}
|
||||||
oceanSymbol={
|
datasetSymbol={asset?.accessDetails?.baseToken?.symbol || 'OCEAN'}
|
||||||
asset?.accessDetails?.baseToken?.symbol ||
|
algorithmSymbol={
|
||||||
selectedAlgorithmAsset?.accessDetails?.baseToken?.symbol ||
|
selectedAlgorithmAsset?.accessDetails?.baseToken?.symbol ||
|
||||||
'OCEAN'
|
'OCEAN'
|
||||||
}
|
}
|
||||||
|
@ -41,10 +41,12 @@ export default function EditComputeDataset({
|
|||||||
|
|
||||||
async function handleSubmit(values: ComputeEditForm, resetForm: () => void) {
|
async function handleSubmit(values: ComputeEditForm, resetForm: () => void) {
|
||||||
try {
|
try {
|
||||||
if (asset?.accessDetails?.type === 'free') {
|
if (
|
||||||
|
asset?.accessDetails?.type === 'free' &&
|
||||||
|
asset?.accessDetails?.isPurchasable
|
||||||
|
) {
|
||||||
const tx = await setMinterToPublisher(
|
const tx = await setMinterToPublisher(
|
||||||
web3,
|
web3,
|
||||||
asset?.accessDetails?.addressOrId,
|
|
||||||
asset?.accessDetails?.datatoken?.address,
|
asset?.accessDetails?.datatoken?.address,
|
||||||
accountId,
|
accountId,
|
||||||
setError
|
setError
|
||||||
|
Loading…
Reference in New Issue
Block a user