diff --git a/src/@utils/accessDetailsAndPricing.ts b/src/@utils/accessDetailsAndPricing.ts index ebd423b31..322fd99f6 100644 --- a/src/@utils/accessDetailsAndPricing.ts +++ b/src/@utils/accessDetailsAndPricing.ts @@ -12,7 +12,8 @@ import { Asset, LoggerInstance, ProviderFees, - ProviderInstance + ProviderInstance, + unitsToAmount } from '@oceanprotocol/lib' import { AssetExtended } from 'src/@types/AssetExtended' import { calcInGivenOut } from './pool' @@ -20,6 +21,7 @@ import { getFixedBuyPrice } from './fixedRateExchange' import { AccessDetails, OrderPriceAndFees } from 'src/@types/Price' import Decimal from 'decimal.js' import { consumeMarketOrderFee } from '../../app.config' +import Web3 from 'web3' const tokensPriceQuery = gql` query TokensPriceQuery($datatokenIds: [ID!], $account: String) { @@ -255,6 +257,7 @@ function getAccessDetailsFromTokenPrice( * @return {Promise} */ export async function getOrderPriceAndFees( + web3: Web3, asset: AssetExtended, accountId?: string, paramsForPool?: CalcInGivenOutParams, @@ -316,7 +319,15 @@ export async function getOrderPriceAndFees( orderPriceAndFee.price = new Decimal(+orderPriceAndFee.price || 0) .add(new Decimal(+orderPriceAndFee?.consumeMarketOrderFee || 0)) .add(new Decimal(+orderPriceAndFee?.publisherMarketOrderFee || 0)) - .add(new Decimal(+orderPriceAndFee?.providerFee?.providerFeeAmount || 0)) + .add( + new Decimal( + (await unitsToAmount( + web3, + orderPriceAndFee?.providerFee?.providerFeeToken, + orderPriceAndFee?.providerFee?.providerFeeAmount.toString() + )) || 0 + ) + ) .toString() return orderPriceAndFee } diff --git a/src/@utils/order.ts b/src/@utils/order.ts index 3c28521b3..5b523a864 100644 --- a/src/@utils/order.ts +++ b/src/@utils/order.ts @@ -6,7 +6,8 @@ import { OrderParams, ProviderComputeInitialize, ProviderFees, - ProviderInstance + ProviderInstance, + unitsToAmount } from '@oceanprotocol/lib' import { AssetExtended } from 'src/@types/AssetExtended' import Web3 from 'web3' @@ -52,10 +53,17 @@ export async function order( asset.services[0].serviceEndpoint )) + const providerFeesSanitized = providerFees || initializeData.providerFee + providerFeesSanitized.providerFeeAmount = await unitsToAmount( + web3, + providerFeesSanitized.providerFeeToken, + providerFeesSanitized.providerFeeAmount.toString() + ) + const orderParams = { consumer: computeConsumerAddress || accountId, serviceIndex: 0, - _providerFee: providerFees || initializeData.providerFee, + _providerFee: providerFeesSanitized, _consumeMarketFee: { consumeMarketFeeAddress: marketFeeAddress, consumeMarketFeeAmount: consumeMarketOrderFee, @@ -86,6 +94,8 @@ export async function order( swapMarketFee: consumeMarketFixedSwapFee, marketFeeAddress } as FreOrderParams + console.log('freParams', freParams) + console.log('orderParams', orderParams) const tx = await datatoken.buyFromFreAndOrder( asset.accessDetails.datatoken.address, accountId, @@ -153,10 +163,15 @@ export async function reuseOrder( web3, accountId, providerFees.providerFeeToken || - initializeData.providerFee.providerFeeAmount, - asset.accessDetails.datatoken.address, - providerFees.providerFeeAmount || initializeData.providerFee.providerFeeToken, + asset.accessDetails.datatoken.address, + await unitsToAmount( + web3, + providerFees.providerFeeToken || + initializeData.providerFee.providerFeeToken, + providerFees.providerFeeAmount || + initializeData.providerFee.providerFeeAmount + ), false ) if (!txApprove) { diff --git a/src/components/Asset/AssetActions/Compute/index.tsx b/src/components/Asset/AssetActions/Compute/index.tsx index d3ff04b3f..842287dc2 100644 --- a/src/components/Asset/AssetActions/Compute/index.tsx +++ b/src/components/Asset/AssetActions/Compute/index.tsx @@ -176,6 +176,7 @@ export default function Compute({ } : null const datasetPriceAndFees = await getOrderPriceAndFees( + web3, asset, ZERO_ADDRESS, poolParams, @@ -223,6 +224,7 @@ export default function Compute({ } } const algorithmOrderPriceAndFees = await getOrderPriceAndFees( + web3, selectedAlgorithmAsset, ZERO_ADDRESS, algoPoolParams, diff --git a/src/components/Asset/AssetActions/Download.tsx b/src/components/Asset/AssetActions/Download.tsx index a63fb5996..8e9a5820a 100644 --- a/src/components/Asset/AssetActions/Download.tsx +++ b/src/components/Asset/AssetActions/Download.tsx @@ -83,6 +83,7 @@ export default function Download({ consumeMarketSwapFee: '0' } const _orderPriceAndFees = await getOrderPriceAndFees( + web3, asset, ZERO_ADDRESS, paramsForPool