From 35d9b6faecafe9672e1b10ca5311791f51245e14 Mon Sep 17 00:00:00 2001 From: mihaisc Date: Thu, 26 Nov 2020 17:02:42 +0200 Subject: [PATCH] price optimizations and bug fixes (#274) * price optimizations and bug fixes Signed-off-by: mihaisc * travis fix Signed-off-by: mihaisc * remove console.log Signed-off-by: mihaisc * rephrasing Signed-off-by: mihaisc * bump react hooks, show price while checking if consumable Signed-off-by: mihaisc * remove console.log * fix travis --- package-lock.json | 45 +++++++++++++------ package.json | 4 +- .../organisms/AssetActions/Consume.tsx | 32 ++++++++++--- .../organisms/AssetContent/index.tsx | 12 +++-- src/providers/Asset.tsx | 2 +- 5 files changed, 69 insertions(+), 26 deletions(-) diff --git a/package-lock.json b/package-lock.json index 44fbc0eb9..86068f144 100644 --- a/package-lock.json +++ b/package-lock.json @@ -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", diff --git a/package.json b/package.json index f0edb326b..6f3ce36f3 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/components/organisms/AssetActions/Consume.tsx b/src/components/organisms/AssetActions/Consume.tsx index b521bb7f6..929bd0e16 100644 --- a/src/components/organisms/AssetActions/Consume.tsx +++ b/src/components/organisms/AssetActions/Consume.tsx @@ -27,7 +27,7 @@ export default function Consume({ const { marketFeeAddress } = useSiteMetadata() const [hasPreviousOrder, setHasPreviousOrder] = useState(false) const [previousOrderId, setPreviousOrderId] = useState() - 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({
- + {isConsumable ? ( + + ) : ( +
+ There is not enough liquidity in the pool to buy this data set. +
+ )} {!isInPurgatory && }
diff --git a/src/components/organisms/AssetContent/index.tsx b/src/components/organisms/AssetContent/index.tsx index 96ae071c8..a9780c8cb 100644 --- a/src/components/organisms/AssetContent/index.tsx +++ b/src/components/organisms/AssetContent/index.tsx @@ -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 (
diff --git a/src/providers/Asset.tsx b/src/providers/Asset.tsx index 4201af105..cfa14a765 100644 --- a/src/providers/Asset.tsx +++ b/src/providers/Asset.tsx @@ -152,7 +152,7 @@ function AssetProvider({ setOwner(ddo.publicKey[0].owner) await setPurgatory(ddo.id) - refreshPrice() + await refreshPrice() }, [refreshPrice, setPurgatory] )