1
0
mirror of https://github.com/oceanprotocol/market.git synced 2024-12-02 05:57:29 +01:00
mihaisc 8d1782a800
Restore order (#1068)
* minor refactors

* minor refactors

* fixes

* buy dt

* consumePrice + estimation

* various fixes

* cleanup

* fix build

* fix ssh issue

* feedback

* build fix

* ssh fix

* remove console.log

* suggested fixes

* other fixes

* switch to decimal

* more fixes

* more fixes

* fix

* some fee refactors

* more fee refactoring

* lib update, fre rename

Signed-off-by: mihaisc <mihai.scarlat@smartcontrol.ro>

* minor refactors

Signed-off-by: mihaisc <mihai.scarlat@smartcontrol.ro>

* build fixes

Signed-off-by: mihaisc <mihai.scarlat@smartcontrol.ro>

* update + more refactoring

* calc price

* fix build

* restore accountId in effect

* fix order

* fix build and update lib

* fix order index

* fix comments

* pool fix

* remove console.log

* fix order fixed rate exchange

* fixed free order and messaging

* add comment

* minor type fix

* more type fixes
2022-02-14 08:27:36 -08:00

97 lines
2.5 KiB
TypeScript

import React, { ReactElement } from 'react'
import { useAsset } from '@context/Asset'
import PriceUnit from '@shared/Price/PriceUnit'
import Tooltip from '@shared/atoms/Tooltip'
import styles from './PriceOutput.module.css'
import { AccessDetails } from 'src/@types/Price'
interface PriceOutputProps {
totalPrice: number
hasPreviousOrder: boolean
hasDatatoken: boolean
symbol: string
assetTimeout: string
hasPreviousOrderSelectedComputeAsset: boolean
hasDatatokenSelectedComputeAsset: boolean
algorithmConsumeDetails: AccessDetails
selectedComputeAssetTimeout: string
}
function Row({
price,
hasPreviousOrder,
hasDatatoken,
symbol,
timeout,
sign
}: {
price: number
hasPreviousOrder?: boolean
hasDatatoken?: boolean
symbol?: string
timeout?: string
sign?: string
}) {
return (
<div className={styles.priceRow}>
<div className={styles.sign}>{sign}</div>
<div>
<PriceUnit
price={hasPreviousOrder || hasDatatoken ? '0' : `${price}`}
symbol={symbol}
small
className={styles.price}
/>
<span className={styles.timeout}>
{timeout &&
timeout !== 'Forever' &&
!hasPreviousOrder &&
`for ${timeout}`}
</span>
</div>
</div>
)
}
export default function PriceOutput({
totalPrice,
hasPreviousOrder,
hasDatatoken,
assetTimeout,
symbol,
hasPreviousOrderSelectedComputeAsset,
hasDatatokenSelectedComputeAsset,
algorithmConsumeDetails,
selectedComputeAssetTimeout
}: PriceOutputProps): ReactElement {
const { asset } = useAsset()
return (
<div className={styles.priceComponent}>
You will pay <PriceUnit price={`${totalPrice}`} symbol={symbol} small />
<Tooltip
content={
<div className={styles.calculation}>
<Row
hasPreviousOrder={hasPreviousOrder}
hasDatatoken={hasDatatoken}
price={Number.parseFloat(asset?.accessDetails?.price)}
timeout={assetTimeout}
symbol={symbol}
/>
<Row
hasPreviousOrder={hasPreviousOrderSelectedComputeAsset}
hasDatatoken={hasDatatokenSelectedComputeAsset}
price={Number.parseFloat(algorithmConsumeDetails?.price)}
timeout={selectedComputeAssetTimeout}
symbol={symbol}
sign="+"
/>
<Row price={totalPrice} symbol={symbol} sign="=" />
</div>
}
/>
</div>
)
}