From 9eb47f6602f2b8aa04434c6d2b5b5682714d066d Mon Sep 17 00:00:00 2001 From: Bogdan Fazakas Date: Wed, 15 Jun 2022 16:43:37 +0300 Subject: [PATCH] update price output tooltip and total price logic --- src/@utils/accessDetailsAndPricing.ts | 9 -------- src/@utils/assetConvertor.ts | 2 +- .../Compute/FormComputeDataset.tsx | 12 +++++++++- .../Compute/PriceOutput.module.css | 14 +++++++++--- .../AssetActions/Compute/PriceOutput.tsx | 20 +++++++++++++++-- .../Asset/AssetActions/Compute/index.tsx | 22 ++++++++++++++++--- 6 files changed, 60 insertions(+), 19 deletions(-) diff --git a/src/@utils/accessDetailsAndPricing.ts b/src/@utils/accessDetailsAndPricing.ts index 322fd99f6..7cbf86a97 100644 --- a/src/@utils/accessDetailsAndPricing.ts +++ b/src/@utils/accessDetailsAndPricing.ts @@ -319,15 +319,6 @@ 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( - (await unitsToAmount( - web3, - orderPriceAndFee?.providerFee?.providerFeeToken, - orderPriceAndFee?.providerFee?.providerFeeAmount.toString() - )) || 0 - ) - ) .toString() return orderPriceAndFee } diff --git a/src/@utils/assetConvertor.ts b/src/@utils/assetConvertor.ts index 2536060d2..de12c9fa3 100644 --- a/src/@utils/assetConvertor.ts +++ b/src/@utils/assetConvertor.ts @@ -18,7 +18,7 @@ export async function transformAssetToAssetSelection( const algoComputeService = getServiceByName(asset, 'compute') if ( - asset?.accessDetails.price && + asset?.accessDetails?.price && algoComputeService?.serviceEndpoint === datasetProviderEndpoint ) { let selected = false diff --git a/src/components/Asset/AssetActions/Compute/FormComputeDataset.tsx b/src/components/Asset/AssetActions/Compute/FormComputeDataset.tsx index 4bd1414d1..1708e3ed9 100644 --- a/src/components/Asset/AssetActions/Compute/FormComputeDataset.tsx +++ b/src/components/Asset/AssetActions/Compute/FormComputeDataset.tsx @@ -43,7 +43,9 @@ export default function FormStartCompute({ isConsumable, consumableFeedback, datasetOrderPriceAndFees, - algoOrderPriceAndFees + algoOrderPriceAndFees, + providerFeeAmount, + validUntil }: { algorithms: AssetSelectionAsset[] ddoListAlgorithms: Asset[] @@ -70,6 +72,8 @@ export default function FormStartCompute({ consumableFeedback: string datasetOrderPriceAndFees?: OrderPriceAndFees algoOrderPriceAndFees?: OrderPriceAndFees + providerFeeAmount?: string + validUntil?: string }): ReactElement { const { siteContent } = useMarketMetadata() const { isValid, values }: FormikContextType<{ algorithm: string }> = @@ -138,8 +142,12 @@ export default function FormStartCompute({ algoOrderPriceAndFees?.price || selectedAlgorithmAsset.accessDetails.price ).toDecimalPlaces(MAX_DECIMALS) + const providerFees = providerFeeAmount + ? new Decimal(providerFeeAmount).toDecimalPlaces(MAX_DECIMALS) + : new Decimal(0) const totalPrice = priceDataset .plus(priceAlgo) + .plus(providerFees) .toDecimalPlaces(MAX_DECIMALS) .toString() setTotalPrice(totalPrice) @@ -192,6 +200,8 @@ export default function FormStartCompute({ totalPrice={totalPrice} datasetOrderPrice={datasetOrderPrice} algoOrderPrice={algoOrderPrice} + providerFeeAmount={providerFeeAmount} + validUntil={validUntil} />
{sign}
+
{type}
+
diff --git a/src/components/Asset/AssetActions/Compute/index.tsx b/src/components/Asset/AssetActions/Compute/index.tsx index 842287dc2..16cc34119 100644 --- a/src/components/Asset/AssetActions/Compute/index.tsx +++ b/src/components/Asset/AssetActions/Compute/index.tsx @@ -11,7 +11,8 @@ import { LoggerInstance, ComputeAlgorithm, ComputeOutput, - ProviderComputeInitializeResults + ProviderComputeInitializeResults, + unitsToAmount } from '@oceanprotocol/lib' import { toast } from 'react-toastify' import Price from '@shared/Price' @@ -93,7 +94,8 @@ export default function Compute({ const [computeEnv, setComputeEnv] = useState() const [initializedProviderResponse, setInitializedProviderResponse] = useState() - // const [computeValidUntil, setComputeValidUntil] = useState() + const [providerFeeAmount, setProviderFeeAmount] = useState('0') + const [computeValidUntil, setComputeValidUntil] = useState('0') const [datasetOrderPriceAndFees, setDatasetOrderPriceAndFees] = useState() const [isRequestingDataseOrderPrice, setIsRequestingDataseOrderPrice] = @@ -146,7 +148,19 @@ export default function Compute({ return } setInitializedProviderResponse(initializedProvider) - + setProviderFeeAmount( + await unitsToAmount( + web3, + initializedProvider?.datasets?.[0]?.providerFee?.providerFeeToken, + initializedProviderResponse?.datasets?.[0]?.providerFee + ?.providerFeeAmount + ) + ) + const computeDuration = ( + parseInt(initializedProvider?.datasets?.[0]?.providerFee?.validUntil) - + Math.floor(Date.now() / 1000) + ).toString() + setComputeValidUntil(computeDuration) if ( asset?.accessDetails?.addressOrId !== ZERO_ADDRESS && asset?.accessDetails?.type !== 'free' && @@ -476,6 +490,8 @@ export default function Compute({ consumableFeedback={consumableFeedback} datasetOrderPriceAndFees={datasetOrderPriceAndFees} algoOrderPriceAndFees={algoOrderPriceAndFees} + providerFeeAmount={providerFeeAmount} + validUntil={computeValidUntil} /> )}