1
0
mirror of https://github.com/oceanprotocol/market.git synced 2024-11-13 16:54:53 +01:00

price optimizations and bug fixes (#274)

* price optimizations and bug fixes

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

* travis fix

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

* remove console.log

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

* rephrasing

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

* bump react hooks, show price while checking if consumable

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

* remove console.log

* fix travis
This commit is contained in:
mihaisc 2020-11-26 17:02:42 +02:00 committed by GitHub
parent a7a29a6c63
commit 35d9b6faec
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 69 additions and 26 deletions

45
package-lock.json generated
View File

@ -3550,9 +3550,9 @@
"integrity": "sha512-p0oOHXr60hXZuLNsQ/PsOQtCfia79thm7MjPxTrnnBvD+csJoHzARYMB0IFj/KTw6U5vLXODgjJAn8x6QksLwg=="
},
"@oceanprotocol/lib": {
"version": "0.9.17",
"resolved": "https://registry.npmjs.org/@oceanprotocol/lib/-/lib-0.9.17.tgz",
"integrity": "sha512-im/e3zD1d8C8rDi0yidRhb1DU77Ka+XrweWYKMNQ8W86X1ODGf8CzdxMbwM3nIcYeTbNT+PcbBraRLQxwZOe3A==",
"version": "0.9.18",
"resolved": "https://registry.npmjs.org/@oceanprotocol/lib/-/lib-0.9.18.tgz",
"integrity": "sha512-RsP4CjAnauI2kDH0923LOO3NhdKNB1y8WwpAviVwIwz9sYqsIIcac6MKXIm5oDeLNhmCIhJXbwvQehf17wRL5Q==",
"requires": {
"@ethereum-navigator/navigator": "^0.5.0",
"@oceanprotocol/contracts": "^0.5.7",
@ -3572,15 +3572,34 @@
"integrity": "sha512-MMyy81FvnRGwl2cQ4+cucq/YWjUTGzStHyAUVM6P2pFA8zMc3jouuWN2WSAjmvhxeKZU7jvJRwZCoi+miEYKjw=="
},
"@oceanprotocol/react": {
"version": "0.3.20",
"resolved": "https://registry.npmjs.org/@oceanprotocol/react/-/react-0.3.20.tgz",
"integrity": "sha512-98mRBP0Ij20v6wYsbb/B7GM1H3HclUyrlWJKybRB/K+Hbk3AJW0+RQxJ+C4WkrkR4C5KquNjGccvgr5sZyQFoQ==",
"version": "0.3.21",
"resolved": "https://registry.npmjs.org/@oceanprotocol/react/-/react-0.3.21.tgz",
"integrity": "sha512-3fY3oYbJ1I2bTZzWqaHbQvVCI9Xdn3Oa0BOeWPA0757wT6gOQzdMcE/zKAFqzI6L/4006kTQF3Ls0UnKVkocUA==",
"requires": {
"@oceanprotocol/lib": "^0.9.14",
"@oceanprotocol/lib": "^0.9.18",
"axios": "^0.21.0",
"decimal.js": "^10.2.1",
"web3": "^1.3.0",
"web3modal": "^1.9.1"
},
"dependencies": {
"@oceanprotocol/lib": {
"version": "0.9.18",
"resolved": "https://registry.npmjs.org/@oceanprotocol/lib/-/lib-0.9.18.tgz",
"integrity": "sha512-RsP4CjAnauI2kDH0923LOO3NhdKNB1y8WwpAviVwIwz9sYqsIIcac6MKXIm5oDeLNhmCIhJXbwvQehf17wRL5Q==",
"requires": {
"@ethereum-navigator/navigator": "^0.5.0",
"@oceanprotocol/contracts": "^0.5.7",
"decimal.js": "^10.2.0",
"fs": "0.0.1-security",
"lzma": "^2.3.2",
"node-fetch": "^2.6.1",
"save-file": "^2.3.1",
"uuid": "^8.3.0",
"web3": "^1.3.0",
"web3-eth-contract": "^1.3.0"
}
}
}
},
"@oceanprotocol/typographies": {
@ -8077,9 +8096,9 @@
"dev": true
},
"babel-plugin-styled-components": {
"version": "1.11.1",
"resolved": "https://registry.npmjs.org/babel-plugin-styled-components/-/babel-plugin-styled-components-1.11.1.tgz",
"integrity": "sha512-YwrInHyKUk1PU3avIRdiLyCpM++18Rs1NgyMXEAQC33rIXs/vro0A+stf4sT0Gf22Got+xRWB8Cm0tw+qkRzBA==",
"version": "1.12.0",
"resolved": "https://registry.npmjs.org/babel-plugin-styled-components/-/babel-plugin-styled-components-1.12.0.tgz",
"integrity": "sha512-FEiD7l5ZABdJPpLssKXjBUJMYqzbcNzBowfXDCdJhOpbhWiewapUaY+LZGT8R4Jg2TwOjGjG4RKeyrO5p9sBkA==",
"requires": {
"@babel/helper-annotate-as-pure": "^7.0.0",
"@babel/helper-module-imports": "^7.0.0",
@ -34344,9 +34363,9 @@
}
},
"web3modal": {
"version": "1.9.1",
"resolved": "https://registry.npmjs.org/web3modal/-/web3modal-1.9.1.tgz",
"integrity": "sha512-fBybI1+jFAWO492ieyMexyr0MMdquCapeVaHLhclx8GegzIUeWhWa/S19LYMLMW/DDUi2aVTE4JbECX/IHYdQQ==",
"version": "1.9.2",
"resolved": "https://registry.npmjs.org/web3modal/-/web3modal-1.9.2.tgz",
"integrity": "sha512-wxUpMPwFwjjTnhSSXbWY49Nrn9VAz9RRZpVmfFI2tMny26rsjqdBfYKiRNuMF2Y0Ui9gG4KiUtVkS7DJ2qfo2Q==",
"requires": {
"detect-browser": "^5.1.0",
"prop-types": "^15.7.2",

View File

@ -24,9 +24,9 @@
"@coingecko/cryptoformat": "^0.4.2",
"@loadable/component": "^5.14.1",
"@oceanprotocol/art": "^3.0.0",
"@oceanprotocol/lib": "^0.9.17",
"@oceanprotocol/lib": "^0.9.18",
"@oceanprotocol/list-datapartners": "^1.0.3",
"@oceanprotocol/react": "^0.3.20",
"@oceanprotocol/react": "^0.3.22",
"@oceanprotocol/typographies": "^0.1.0",
"@sindresorhus/slugify": "^1.0.0",
"@tippyjs/react": "^4.2.0",

View File

@ -27,7 +27,7 @@ export default function Consume({
const { marketFeeAddress } = useSiteMetadata()
const [hasPreviousOrder, setHasPreviousOrder] = useState(false)
const [previousOrderId, setPreviousOrderId] = useState<string>()
const { isInPurgatory } = useAsset()
const { isInPurgatory, price } = useAsset()
const {
dtSymbol,
buyDT,
@ -37,23 +37,37 @@ export default function Consume({
} = usePricing(ddo)
const { consumeStepText, consume, consumeError } = useConsume()
const [isDisabled, setIsDisabled] = useState(true)
const [hasDatatoken, setHasDatatoken] = useState(false)
const [isConsumable, setIsConsumable] = useState(true)
const hasDatatoken = Number(dtBalance) >= 1
useEffect(() => {
setIsConsumable(
price.isConsumable !== undefined ? price.isConsumable === 'true' : true
)
}, [price])
useEffect(() => {
setHasDatatoken(Number(dtBalance) >= 1)
}, [dtBalance])
useEffect(() => {
setIsDisabled(
(!ocean ||
!isBalanceSufficient ||
typeof consumeStepText !== 'undefined' ||
pricingIsLoading) &&
!hasPreviousOrder
pricingIsLoading ||
!isConsumable) &&
!hasPreviousOrder &&
!hasDatatoken
)
}, [
ocean,
hasPreviousOrder,
isBalanceSufficient,
consumeStepText,
pricingIsLoading
pricingIsLoading,
isConsumable,
hasDatatoken
])
useEffect(() => {
@ -118,7 +132,13 @@ export default function Consume({
<File file={file} />
</div>
<div className={styles.pricewrapper}>
<Price ddo={ddo} conversion />
{isConsumable ? (
<Price ddo={ddo} conversion />
) : (
<div className={styles.help}>
There is not enough liquidity in the pool to buy this data set.
</div>
)}
{!isInPurgatory && <PurchaseButton />}
</div>
</div>

View File

@ -1,5 +1,5 @@
import { MetadataMarket } from '../../../@types/MetaData'
import React, { ReactElement } from 'react'
import React, { ReactElement, useEffect, useState } from 'react'
import { Link } from 'gatsby'
import Markdown from '../../atoms/Markdown'
import MetaFull from './MetaFull'
@ -13,6 +13,7 @@ import { useMetadata, useOcean, usePricing } from '@oceanprotocol/react'
import EtherscanLink from '../../atoms/EtherscanLink'
import Bookmark from './Bookmark'
import Byline from './Byline'
import { useAsset } from '../../../providers/Asset'
export interface AssetContentProps {
metadata: MetadataMarket
@ -28,9 +29,12 @@ export default function AssetContent({
const { accountId, networkId } = useOcean()
const { owner } = useMetadata(ddo)
const { dtSymbol, dtName } = usePricing(ddo)
const isOwner = accountId === owner
const hasNoPrice = ddo.price.datatoken === 0 && ddo.price.value === 0
const showPricing = isOwner && hasNoPrice
const [showPricing, setShowPricing] = useState(false)
const { price } = useAsset()
useEffect(() => {
setShowPricing(accountId === owner && price.isConsumable === '')
}, [accountId, owner, price])
return (
<article className={styles.grid}>

View File

@ -152,7 +152,7 @@ function AssetProvider({
setOwner(ddo.publicKey[0].owner)
await setPurgatory(ddo.id)
refreshPrice()
await refreshPrice()
},
[refreshPrice, setPurgatory]
)