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:
parent
88fbab5602
commit
9eb47f6602
@ -319,15 +319,6 @@ export async function getOrderPriceAndFees(
|
|||||||
orderPriceAndFee.price = new Decimal(+orderPriceAndFee.price || 0)
|
orderPriceAndFee.price = new Decimal(+orderPriceAndFee.price || 0)
|
||||||
.add(new Decimal(+orderPriceAndFee?.consumeMarketOrderFee || 0))
|
.add(new Decimal(+orderPriceAndFee?.consumeMarketOrderFee || 0))
|
||||||
.add(new Decimal(+orderPriceAndFee?.publisherMarketOrderFee || 0))
|
.add(new Decimal(+orderPriceAndFee?.publisherMarketOrderFee || 0))
|
||||||
.add(
|
|
||||||
new Decimal(
|
|
||||||
(await unitsToAmount(
|
|
||||||
web3,
|
|
||||||
orderPriceAndFee?.providerFee?.providerFeeToken,
|
|
||||||
orderPriceAndFee?.providerFee?.providerFeeAmount.toString()
|
|
||||||
)) || 0
|
|
||||||
)
|
|
||||||
)
|
|
||||||
.toString()
|
.toString()
|
||||||
return orderPriceAndFee
|
return orderPriceAndFee
|
||||||
}
|
}
|
||||||
|
@ -18,7 +18,7 @@ export async function transformAssetToAssetSelection(
|
|||||||
const algoComputeService = getServiceByName(asset, 'compute')
|
const algoComputeService = getServiceByName(asset, 'compute')
|
||||||
|
|
||||||
if (
|
if (
|
||||||
asset?.accessDetails.price &&
|
asset?.accessDetails?.price &&
|
||||||
algoComputeService?.serviceEndpoint === datasetProviderEndpoint
|
algoComputeService?.serviceEndpoint === datasetProviderEndpoint
|
||||||
) {
|
) {
|
||||||
let selected = false
|
let selected = false
|
||||||
|
@ -43,7 +43,9 @@ export default function FormStartCompute({
|
|||||||
isConsumable,
|
isConsumable,
|
||||||
consumableFeedback,
|
consumableFeedback,
|
||||||
datasetOrderPriceAndFees,
|
datasetOrderPriceAndFees,
|
||||||
algoOrderPriceAndFees
|
algoOrderPriceAndFees,
|
||||||
|
providerFeeAmount,
|
||||||
|
validUntil
|
||||||
}: {
|
}: {
|
||||||
algorithms: AssetSelectionAsset[]
|
algorithms: AssetSelectionAsset[]
|
||||||
ddoListAlgorithms: Asset[]
|
ddoListAlgorithms: Asset[]
|
||||||
@ -70,6 +72,8 @@ export default function FormStartCompute({
|
|||||||
consumableFeedback: string
|
consumableFeedback: string
|
||||||
datasetOrderPriceAndFees?: OrderPriceAndFees
|
datasetOrderPriceAndFees?: OrderPriceAndFees
|
||||||
algoOrderPriceAndFees?: OrderPriceAndFees
|
algoOrderPriceAndFees?: OrderPriceAndFees
|
||||||
|
providerFeeAmount?: string
|
||||||
|
validUntil?: string
|
||||||
}): ReactElement {
|
}): ReactElement {
|
||||||
const { siteContent } = useMarketMetadata()
|
const { siteContent } = useMarketMetadata()
|
||||||
const { isValid, values }: FormikContextType<{ algorithm: string }> =
|
const { isValid, values }: FormikContextType<{ algorithm: string }> =
|
||||||
@ -138,8 +142,12 @@ export default function FormStartCompute({
|
|||||||
algoOrderPriceAndFees?.price ||
|
algoOrderPriceAndFees?.price ||
|
||||||
selectedAlgorithmAsset.accessDetails.price
|
selectedAlgorithmAsset.accessDetails.price
|
||||||
).toDecimalPlaces(MAX_DECIMALS)
|
).toDecimalPlaces(MAX_DECIMALS)
|
||||||
|
const providerFees = providerFeeAmount
|
||||||
|
? new Decimal(providerFeeAmount).toDecimalPlaces(MAX_DECIMALS)
|
||||||
|
: new Decimal(0)
|
||||||
const totalPrice = priceDataset
|
const totalPrice = priceDataset
|
||||||
.plus(priceAlgo)
|
.plus(priceAlgo)
|
||||||
|
.plus(providerFees)
|
||||||
.toDecimalPlaces(MAX_DECIMALS)
|
.toDecimalPlaces(MAX_DECIMALS)
|
||||||
.toString()
|
.toString()
|
||||||
setTotalPrice(totalPrice)
|
setTotalPrice(totalPrice)
|
||||||
@ -192,6 +200,8 @@ export default function FormStartCompute({
|
|||||||
totalPrice={totalPrice}
|
totalPrice={totalPrice}
|
||||||
datasetOrderPrice={datasetOrderPrice}
|
datasetOrderPrice={datasetOrderPrice}
|
||||||
algoOrderPrice={algoOrderPrice}
|
algoOrderPrice={algoOrderPrice}
|
||||||
|
providerFeeAmount={providerFeeAmount}
|
||||||
|
validUntil={validUntil}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<ButtonBuy
|
<ButtonBuy
|
||||||
|
@ -36,8 +36,10 @@
|
|||||||
border-bottom: 1px solid var(--border-color);
|
border-bottom: 1px solid var(--border-color);
|
||||||
padding-top: calc(var(--spacer) / 7);
|
padding-top: calc(var(--spacer) / 7);
|
||||||
padding-bottom: calc(var(--spacer) / 7);
|
padding-bottom: calc(var(--spacer) / 7);
|
||||||
display: flex;
|
display: grid;
|
||||||
justify-content: space-between;
|
grid-template-columns: 5% 1fr auto;
|
||||||
|
column-gap: calc(var(--spacer) / 10);
|
||||||
|
/* justify-content: space-between; */
|
||||||
}
|
}
|
||||||
|
|
||||||
.priceRow:last-child {
|
.priceRow:last-child {
|
||||||
@ -47,8 +49,14 @@
|
|||||||
|
|
||||||
.sign {
|
.sign {
|
||||||
display: inline-block;
|
display: inline-block;
|
||||||
width: 5%;
|
|
||||||
text-align: left;
|
text-align: left;
|
||||||
color: var(--color-secondary);
|
color: var(--color-secondary);
|
||||||
font-size: var(--font-size-base);
|
font-size: var(--font-size-base);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.type {
|
||||||
|
display: inline-block;
|
||||||
|
text-align: left;
|
||||||
|
color: var(--color-secondary);
|
||||||
|
font-size: var(--font-size-mini);
|
||||||
|
}
|
||||||
|
@ -19,6 +19,8 @@ interface PriceOutputProps {
|
|||||||
selectedComputeAssetTimeout: string
|
selectedComputeAssetTimeout: string
|
||||||
datasetOrderPrice?: number
|
datasetOrderPrice?: number
|
||||||
algoOrderPrice?: number
|
algoOrderPrice?: number
|
||||||
|
providerFeeAmount?: string
|
||||||
|
validUntil?: string
|
||||||
}
|
}
|
||||||
|
|
||||||
function Row({
|
function Row({
|
||||||
@ -27,7 +29,8 @@ function Row({
|
|||||||
hasDatatoken,
|
hasDatatoken,
|
||||||
symbol,
|
symbol,
|
||||||
timeout,
|
timeout,
|
||||||
sign
|
sign,
|
||||||
|
type
|
||||||
}: {
|
}: {
|
||||||
price: string
|
price: string
|
||||||
hasPreviousOrder?: boolean
|
hasPreviousOrder?: boolean
|
||||||
@ -35,10 +38,12 @@ function Row({
|
|||||||
symbol?: string
|
symbol?: string
|
||||||
timeout?: string
|
timeout?: string
|
||||||
sign?: string
|
sign?: string
|
||||||
|
type?: string
|
||||||
}) {
|
}) {
|
||||||
return (
|
return (
|
||||||
<div className={styles.priceRow}>
|
<div className={styles.priceRow}>
|
||||||
<div className={styles.sign}>{sign}</div>
|
<div className={styles.sign}>{sign}</div>
|
||||||
|
<div className={styles.type}>{type}</div>
|
||||||
<div>
|
<div>
|
||||||
<PriceUnit
|
<PriceUnit
|
||||||
price={hasPreviousOrder || hasDatatoken ? '0' : `${price}`}
|
price={hasPreviousOrder || hasDatatoken ? '0' : `${price}`}
|
||||||
@ -68,7 +73,9 @@ export default function PriceOutput({
|
|||||||
algorithmConsumeDetails,
|
algorithmConsumeDetails,
|
||||||
selectedComputeAssetTimeout,
|
selectedComputeAssetTimeout,
|
||||||
datasetOrderPrice,
|
datasetOrderPrice,
|
||||||
algoOrderPrice
|
algoOrderPrice,
|
||||||
|
providerFeeAmount,
|
||||||
|
validUntil
|
||||||
}: PriceOutputProps): ReactElement {
|
}: PriceOutputProps): ReactElement {
|
||||||
const { asset } = useAsset()
|
const { asset } = useAsset()
|
||||||
|
|
||||||
@ -89,6 +96,7 @@ export default function PriceOutput({
|
|||||||
.toString()}
|
.toString()}
|
||||||
timeout={assetTimeout}
|
timeout={assetTimeout}
|
||||||
symbol={symbol}
|
symbol={symbol}
|
||||||
|
type="DATASET"
|
||||||
/>
|
/>
|
||||||
<Row
|
<Row
|
||||||
hasPreviousOrder={hasPreviousOrderSelectedComputeAsset}
|
hasPreviousOrder={hasPreviousOrderSelectedComputeAsset}
|
||||||
@ -101,6 +109,14 @@ export default function PriceOutput({
|
|||||||
timeout={selectedComputeAssetTimeout}
|
timeout={selectedComputeAssetTimeout}
|
||||||
symbol={symbol}
|
symbol={symbol}
|
||||||
sign="+"
|
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="=" />
|
<Row price={totalPrice} symbol={symbol} sign="=" />
|
||||||
</div>
|
</div>
|
||||||
|
@ -11,7 +11,8 @@ import {
|
|||||||
LoggerInstance,
|
LoggerInstance,
|
||||||
ComputeAlgorithm,
|
ComputeAlgorithm,
|
||||||
ComputeOutput,
|
ComputeOutput,
|
||||||
ProviderComputeInitializeResults
|
ProviderComputeInitializeResults,
|
||||||
|
unitsToAmount
|
||||||
} from '@oceanprotocol/lib'
|
} from '@oceanprotocol/lib'
|
||||||
import { toast } from 'react-toastify'
|
import { toast } from 'react-toastify'
|
||||||
import Price from '@shared/Price'
|
import Price from '@shared/Price'
|
||||||
@ -93,7 +94,8 @@ export default function Compute({
|
|||||||
const [computeEnv, setComputeEnv] = useState<ComputeEnvironment>()
|
const [computeEnv, setComputeEnv] = useState<ComputeEnvironment>()
|
||||||
const [initializedProviderResponse, setInitializedProviderResponse] =
|
const [initializedProviderResponse, setInitializedProviderResponse] =
|
||||||
useState<ProviderComputeInitializeResults>()
|
useState<ProviderComputeInitializeResults>()
|
||||||
// const [computeValidUntil, setComputeValidUntil] = useState<number>()
|
const [providerFeeAmount, setProviderFeeAmount] = useState<string>('0')
|
||||||
|
const [computeValidUntil, setComputeValidUntil] = useState<string>('0')
|
||||||
const [datasetOrderPriceAndFees, setDatasetOrderPriceAndFees] =
|
const [datasetOrderPriceAndFees, setDatasetOrderPriceAndFees] =
|
||||||
useState<OrderPriceAndFees>()
|
useState<OrderPriceAndFees>()
|
||||||
const [isRequestingDataseOrderPrice, setIsRequestingDataseOrderPrice] =
|
const [isRequestingDataseOrderPrice, setIsRequestingDataseOrderPrice] =
|
||||||
@ -146,7 +148,19 @@ export default function Compute({
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
setInitializedProviderResponse(initializedProvider)
|
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 (
|
if (
|
||||||
asset?.accessDetails?.addressOrId !== ZERO_ADDRESS &&
|
asset?.accessDetails?.addressOrId !== ZERO_ADDRESS &&
|
||||||
asset?.accessDetails?.type !== 'free' &&
|
asset?.accessDetails?.type !== 'free' &&
|
||||||
@ -476,6 +490,8 @@ export default function Compute({
|
|||||||
consumableFeedback={consumableFeedback}
|
consumableFeedback={consumableFeedback}
|
||||||
datasetOrderPriceAndFees={datasetOrderPriceAndFees}
|
datasetOrderPriceAndFees={datasetOrderPriceAndFees}
|
||||||
algoOrderPriceAndFees={algoOrderPriceAndFees}
|
algoOrderPriceAndFees={algoOrderPriceAndFees}
|
||||||
|
providerFeeAmount={providerFeeAmount}
|
||||||
|
validUntil={computeValidUntil}
|
||||||
/>
|
/>
|
||||||
</Formik>
|
</Formik>
|
||||||
)}
|
)}
|
||||||
|
Loading…
Reference in New Issue
Block a user