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

update price output tooltip and total price logic

This commit is contained in:
Bogdan Fazakas 2022-06-15 16:43:37 +03:00
parent 88fbab5602
commit 9eb47f6602
6 changed files with 60 additions and 19 deletions

View File

@ -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
}

View File

@ -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

View File

@ -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}
/>
<ButtonBuy

View File

@ -36,8 +36,10 @@
border-bottom: 1px solid var(--border-color);
padding-top: calc(var(--spacer) / 7);
padding-bottom: calc(var(--spacer) / 7);
display: flex;
justify-content: space-between;
display: grid;
grid-template-columns: 5% 1fr auto;
column-gap: calc(var(--spacer) / 10);
/* justify-content: space-between; */
}
.priceRow:last-child {
@ -47,8 +49,14 @@
.sign {
display: inline-block;
width: 5%;
text-align: left;
color: var(--color-secondary);
font-size: var(--font-size-base);
}
.type {
display: inline-block;
text-align: left;
color: var(--color-secondary);
font-size: var(--font-size-mini);
}

View File

@ -19,6 +19,8 @@ interface PriceOutputProps {
selectedComputeAssetTimeout: string
datasetOrderPrice?: number
algoOrderPrice?: number
providerFeeAmount?: string
validUntil?: string
}
function Row({
@ -27,7 +29,8 @@ function Row({
hasDatatoken,
symbol,
timeout,
sign
sign,
type
}: {
price: string
hasPreviousOrder?: boolean
@ -35,10 +38,12 @@ function Row({
symbol?: string
timeout?: string
sign?: string
type?: string
}) {
return (
<div className={styles.priceRow}>
<div className={styles.sign}>{sign}</div>
<div className={styles.type}>{type}</div>
<div>
<PriceUnit
price={hasPreviousOrder || hasDatatoken ? '0' : `${price}`}
@ -68,7 +73,9 @@ export default function PriceOutput({
algorithmConsumeDetails,
selectedComputeAssetTimeout,
datasetOrderPrice,
algoOrderPrice
algoOrderPrice,
providerFeeAmount,
validUntil
}: PriceOutputProps): ReactElement {
const { asset } = useAsset()
@ -89,6 +96,7 @@ export default function PriceOutput({
.toString()}
timeout={assetTimeout}
symbol={symbol}
type="DATASET"
/>
<Row
hasPreviousOrder={hasPreviousOrderSelectedComputeAsset}
@ -101,6 +109,14 @@ export default function PriceOutput({
timeout={selectedComputeAssetTimeout}
symbol={symbol}
sign="+"
type="ALGORITHM"
/>
<Row
price={providerFeeAmount} // initializeCompute.provider fee amount
timeout={`${validUntil} seconds`} // valid until value
symbol={symbol}
sign="+"
type="C2D RESOURCES"
/>
<Row price={totalPrice} symbol={symbol} sign="=" />
</div>

View File

@ -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<ComputeEnvironment>()
const [initializedProviderResponse, setInitializedProviderResponse] =
useState<ProviderComputeInitializeResults>()
// const [computeValidUntil, setComputeValidUntil] = useState<number>()
const [providerFeeAmount, setProviderFeeAmount] = useState<string>('0')
const [computeValidUntil, setComputeValidUntil] = useState<string>('0')
const [datasetOrderPriceAndFees, setDatasetOrderPriceAndFees] =
useState<OrderPriceAndFees>()
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}
/>
</Formik>
)}