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

include loading when calculating data + algo price, tooltip show order price

This commit is contained in:
Soon Huat 2022-03-31 23:55:22 +08:00
parent 795ba0c01b
commit 31167856fc
3 changed files with 45 additions and 4 deletions

View File

@ -74,6 +74,12 @@ export default function FormStartCompute({
useFormikContext() useFormikContext()
const { asset, isAssetNetwork } = useAsset() const { asset, isAssetNetwork } = useAsset()
const [totalPrice, setTotalPrice] = useState(asset?.accessDetails?.price) const [totalPrice, setTotalPrice] = useState(asset?.accessDetails?.price)
const [datasetOrderPrice, setDatasetOrderPrice] = useState(
asset?.accessDetails?.price
)
const [algoOrderPrice, setAlgoOrderPrice] = useState(
selectedAlgorithmAsset?.accessDetails?.price
)
const [isBalanceSufficient, setIsBalanceSufficient] = useState<boolean>(false) const [isBalanceSufficient, setIsBalanceSufficient] = useState<boolean>(false)
const { accountId, balance } = useWeb3() const { accountId, balance } = useWeb3()
@ -110,6 +116,13 @@ export default function FormStartCompute({
useEffect(() => { useEffect(() => {
if (!asset?.accessDetails || !selectedAlgorithmAsset?.accessDetails) return if (!asset?.accessDetails || !selectedAlgorithmAsset?.accessDetails) return
setDatasetOrderPrice(
datasetOrderPriceAndFees?.price || asset.accessDetails.price
)
setAlgoOrderPrice(
algoOrderPriceAndFees?.price ||
selectedAlgorithmAsset?.accessDetails.price
)
const priceDataset = const priceDataset =
hasPreviousOrder || hasDatatoken hasPreviousOrder || hasDatatoken
? 0 ? 0
@ -164,6 +177,8 @@ export default function FormStartCompute({
algorithmConsumeDetails={selectedAlgorithmAsset?.accessDetails} algorithmConsumeDetails={selectedAlgorithmAsset?.accessDetails}
symbol={oceanSymbol} symbol={oceanSymbol}
totalPrice={Number.parseFloat(totalPrice)} totalPrice={Number.parseFloat(totalPrice)}
datasetOrderPrice={datasetOrderPrice}
algoOrderPrice={algoOrderPrice}
/> />
<ButtonBuy <ButtonBuy

View File

@ -15,6 +15,8 @@ interface PriceOutputProps {
hasDatatokenSelectedComputeAsset: boolean hasDatatokenSelectedComputeAsset: boolean
algorithmConsumeDetails: AccessDetails algorithmConsumeDetails: AccessDetails
selectedComputeAssetTimeout: string selectedComputeAssetTimeout: string
datasetOrderPrice?: number
algoOrderPrice?: number
} }
function Row({ function Row({
@ -62,7 +64,9 @@ export default function PriceOutput({
hasPreviousOrderSelectedComputeAsset, hasPreviousOrderSelectedComputeAsset,
hasDatatokenSelectedComputeAsset, hasDatatokenSelectedComputeAsset,
algorithmConsumeDetails, algorithmConsumeDetails,
selectedComputeAssetTimeout selectedComputeAssetTimeout,
datasetOrderPrice,
algoOrderPrice
}: PriceOutputProps): ReactElement { }: PriceOutputProps): ReactElement {
const { asset } = useAsset() const { asset } = useAsset()
@ -76,14 +80,20 @@ export default function PriceOutput({
<Row <Row
hasPreviousOrder={hasPreviousOrder} hasPreviousOrder={hasPreviousOrder}
hasDatatoken={hasDatatoken} hasDatatoken={hasDatatoken}
price={Number.parseFloat(asset?.accessDetails?.price)} price={
datasetOrderPrice ||
Number.parseFloat(asset?.accessDetails?.price)
}
timeout={assetTimeout} timeout={assetTimeout}
symbol={symbol} symbol={symbol}
/> />
<Row <Row
hasPreviousOrder={hasPreviousOrderSelectedComputeAsset} hasPreviousOrder={hasPreviousOrderSelectedComputeAsset}
hasDatatoken={hasDatatokenSelectedComputeAsset} hasDatatoken={hasDatatokenSelectedComputeAsset}
price={Number.parseFloat(algorithmConsumeDetails?.price)} price={
algoOrderPrice ||
Number.parseFloat(algorithmConsumeDetails?.price)
}
timeout={selectedComputeAssetTimeout} timeout={selectedComputeAssetTimeout}
symbol={symbol} symbol={symbol}
sign="+" sign="+"

View File

@ -85,8 +85,12 @@ export default function Compute({
const [computeStatusText, setComputeStatusText] = useState('') const [computeStatusText, setComputeStatusText] = useState('')
const [datasetOrderPriceAndFees, setDatasetOrderPriceAndFees] = const [datasetOrderPriceAndFees, setDatasetOrderPriceAndFees] =
useState<OrderPriceAndFees>() useState<OrderPriceAndFees>()
const [isRequestingDataseOrderPrice, setIsRequestingDataseOrderPrice] =
useState(false)
const [algoOrderPriceAndFees, setAlgoOrderPriceAndFees] = const [algoOrderPriceAndFees, setAlgoOrderPriceAndFees] =
useState<OrderPriceAndFees>() useState<OrderPriceAndFees>()
const [isRequestingAlgoOrderPrice, setIsRequestingAlgoOrderPrice] =
useState(false)
const isComputeButtonDisabled = const isComputeButtonDisabled =
isJobStarting === true || isJobStarting === true ||
file === null || file === null ||
@ -119,8 +123,12 @@ export default function Compute({
asset?.accessDetails?.type === 'free' asset?.accessDetails?.type === 'free'
) )
return return
setIsRequestingDataseOrderPrice(true)
setComputeStatusText('Calculating price including fees.')
const orderPriceAndFees = await getOrderPriceAndFees(asset, accountId) const orderPriceAndFees = await getOrderPriceAndFees(asset, accountId)
setDatasetOrderPriceAndFees(orderPriceAndFees) setDatasetOrderPriceAndFees(orderPriceAndFees)
setIsRequestingDataseOrderPrice(false)
} }
initDatasetPriceAndFees() initDatasetPriceAndFees()
@ -141,11 +149,15 @@ export default function Compute({
selectedAlgorithmAsset?.accessDetails?.type === 'free' selectedAlgorithmAsset?.accessDetails?.type === 'free'
) )
return return
setIsRequestingAlgoOrderPrice(true)
setComputeStatusText('Calculating price including fees.')
const orderPriceAndFees = await getOrderPriceAndFees( const orderPriceAndFees = await getOrderPriceAndFees(
selectedAlgorithmAsset, selectedAlgorithmAsset,
accountId accountId
) )
setAlgoOrderPriceAndFees(orderPriceAndFees) setAlgoOrderPriceAndFees(orderPriceAndFees)
setIsRequestingAlgoOrderPrice(false)
} }
async function initSelectedAlgo() { async function initSelectedAlgo() {
@ -444,7 +456,11 @@ export default function Compute({
ddoListAlgorithms={ddoAlgorithmList} ddoListAlgorithms={ddoAlgorithmList}
selectedAlgorithmAsset={selectedAlgorithmAsset} selectedAlgorithmAsset={selectedAlgorithmAsset}
setSelectedAlgorithm={setSelectedAlgorithmAsset} setSelectedAlgorithm={setSelectedAlgorithmAsset}
isLoading={isJobStarting} isLoading={
isJobStarting ||
isRequestingDataseOrderPrice ||
isRequestingAlgoOrderPrice
}
isComputeButtonDisabled={isComputeButtonDisabled} isComputeButtonDisabled={isComputeButtonDisabled}
hasPreviousOrder={validOrderTx !== undefined} hasPreviousOrder={validOrderTx !== undefined}
hasDatatoken={hasDatatoken} hasDatatoken={hasDatatoken}