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

Merge branch 'main' into feature/multinetwork

This commit is contained in:
Norbert 2021-07-07 10:09:28 +03:00
commit fa4c3a10ee
9 changed files with 139 additions and 41 deletions

14
package-lock.json generated
View File

@ -14,7 +14,7 @@
"@coingecko/cryptoformat": "^0.4.2", "@coingecko/cryptoformat": "^0.4.2",
"@loadable/component": "^5.15.0", "@loadable/component": "^5.15.0",
"@oceanprotocol/art": "^3.0.0", "@oceanprotocol/art": "^3.0.0",
"@oceanprotocol/lib": "^0.16.1", "@oceanprotocol/lib": "^0.16.2",
"@oceanprotocol/typographies": "^0.1.0", "@oceanprotocol/typographies": "^0.1.0",
"@portis/web3": "^4.0.4", "@portis/web3": "^4.0.4",
"@sindresorhus/slugify": "^2.1.0", "@sindresorhus/slugify": "^2.1.0",
@ -4871,9 +4871,9 @@
} }
}, },
"node_modules/@oceanprotocol/lib": { "node_modules/@oceanprotocol/lib": {
"version": "0.16.1", "version": "0.16.2",
"resolved": "https://registry.npmjs.org/@oceanprotocol/lib/-/lib-0.16.1.tgz", "resolved": "https://registry.npmjs.org/@oceanprotocol/lib/-/lib-0.16.2.tgz",
"integrity": "sha512-zSVs1VaC8T+BBo9MeL88odU6wFNRHAptaLPHT6qGf2Nvc8MyhHdP15TdnHpeLJF4Ez0k6WKemnOQ1DNuaW8FlA==", "integrity": "sha512-hESsrSjTf/6O4oLrJgBzzTn7EkANtpa+Sl+fp/VXBZ3YvJRbp4instlKJMCqWHi+CA4dYr/uLRmaXeY/PGyx5w==",
"dependencies": { "dependencies": {
"@ethereum-navigator/navigator": "^0.5.3", "@ethereum-navigator/navigator": "^0.5.3",
"@oceanprotocol/contracts": "^0.6.4", "@oceanprotocol/contracts": "^0.6.4",
@ -58189,9 +58189,9 @@
} }
}, },
"@oceanprotocol/lib": { "@oceanprotocol/lib": {
"version": "0.16.1", "version": "0.16.2",
"resolved": "https://registry.npmjs.org/@oceanprotocol/lib/-/lib-0.16.1.tgz", "resolved": "https://registry.npmjs.org/@oceanprotocol/lib/-/lib-0.16.2.tgz",
"integrity": "sha512-zSVs1VaC8T+BBo9MeL88odU6wFNRHAptaLPHT6qGf2Nvc8MyhHdP15TdnHpeLJF4Ez0k6WKemnOQ1DNuaW8FlA==", "integrity": "sha512-hESsrSjTf/6O4oLrJgBzzTn7EkANtpa+Sl+fp/VXBZ3YvJRbp4instlKJMCqWHi+CA4dYr/uLRmaXeY/PGyx5w==",
"requires": { "requires": {
"@ethereum-navigator/navigator": "^0.5.3", "@ethereum-navigator/navigator": "^0.5.3",
"@oceanprotocol/contracts": "^0.6.4", "@oceanprotocol/contracts": "^0.6.4",

View File

@ -27,7 +27,7 @@
"@coingecko/cryptoformat": "^0.4.2", "@coingecko/cryptoformat": "^0.4.2",
"@loadable/component": "^5.15.0", "@loadable/component": "^5.15.0",
"@oceanprotocol/art": "^3.0.0", "@oceanprotocol/art": "^3.0.0",
"@oceanprotocol/lib": "^0.16.1", "@oceanprotocol/lib": "^0.16.2",
"@oceanprotocol/typographies": "^0.1.0", "@oceanprotocol/typographies": "^0.1.0",
"@portis/web3": "^4.0.4", "@portis/web3": "^4.0.4",
"@sindresorhus/slugify": "^2.1.0", "@sindresorhus/slugify": "^2.1.0",

View File

@ -12,6 +12,8 @@ interface ButtonBuyProps {
dtBalance: string dtBalance: string
assetType: string assetType: string
assetTimeout: string assetTimeout: string
isConsumable: boolean
consumableFeedback: string
hasPreviousOrderSelectedComputeAsset?: boolean hasPreviousOrderSelectedComputeAsset?: boolean
hasDatatokenSelectedComputeAsset?: boolean hasDatatokenSelectedComputeAsset?: boolean
dtSymbolSelectedComputeAsset?: string dtSymbolSelectedComputeAsset?: string
@ -23,6 +25,7 @@ interface ButtonBuyProps {
type?: 'submit' type?: 'submit'
priceType?: string priceType?: string
algorithmPriceType?: string algorithmPriceType?: string
algorithmConsumableStatus?: number
} }
function getConsumeHelpText( function getConsumeHelpText(
@ -30,13 +33,18 @@ function getConsumeHelpText(
dtSymbol: string, dtSymbol: string,
hasDatatoken: boolean, hasDatatoken: boolean,
hasPreviousOrder: boolean, hasPreviousOrder: boolean,
assetType: string assetType: string,
isConsumable: boolean,
consumableFeedback: string
) { ) {
const text = hasPreviousOrder const text =
? `You bought this ${assetType} already allowing you to use it without paying again.` isConsumable === false
: hasDatatoken ? consumableFeedback
? `You own ${dtBalance} ${dtSymbol} allowing you to use this data set by spending 1 ${dtSymbol}, but without paying OCEAN again.` : hasPreviousOrder
: `For using this ${assetType}, you will buy 1 ${dtSymbol} and immediately spend it back to the publisher and pool.` ? `You bought this ${assetType} already allowing you to use it without paying again.`
: hasDatatoken
? `You own ${dtBalance} ${dtSymbol} allowing you to use this data set by spending 1 ${dtSymbol}, but without paying OCEAN again.`
: `For using this ${assetType}, you will buy 1 ${dtSymbol} and immediately spend it back to the publisher and pool.`
return text return text
} }
@ -47,22 +55,34 @@ function getComputeAssetHelpText(
dtSymbol: string, dtSymbol: string,
dtBalance: string, dtBalance: string,
assetType: string, assetType: string,
isConsumable: boolean,
consumableFeedback: string,
hasPreviousOrderSelectedComputeAsset?: boolean, hasPreviousOrderSelectedComputeAsset?: boolean,
hasDatatokenSelectedComputeAsset?: boolean, hasDatatokenSelectedComputeAsset?: boolean,
dtSymbolSelectedComputeAsset?: string, dtSymbolSelectedComputeAsset?: string,
dtBalanceSelectedComputeAsset?: string, dtBalanceSelectedComputeAsset?: string,
selectedComputeAssetType?: string selectedComputeAssetType?: string,
algorithmConsumableStatus?: number
) { ) {
const computeAssetHelpText = getConsumeHelpText( const computeAssetHelpText = getConsumeHelpText(
dtBalance, dtBalance,
dtSymbol, dtSymbol,
hasDatatoken, hasDatatoken,
hasPreviousOrder, hasPreviousOrder,
assetType assetType,
isConsumable,
consumableFeedback
) )
const text = const text =
!dtSymbolSelectedComputeAsset && !dtBalanceSelectedComputeAsset (!dtSymbolSelectedComputeAsset && !dtBalanceSelectedComputeAsset) ||
isConsumable === false
? '' ? ''
: algorithmConsumableStatus === 1
? 'The selected algorithm has been temporarily disabled by the publisher, please try again later.'
: algorithmConsumableStatus === 2
? 'Access denied, your wallet address is not found on the selected algorithm allow list.'
: algorithmConsumableStatus === 3
? 'Access denied, your wallet address is found on the selected algorithm deny list.'
: hasPreviousOrderSelectedComputeAsset : hasPreviousOrderSelectedComputeAsset
? `You already bought the selected ${selectedComputeAssetType}, allowing you to use it without paying again.` ? `You already bought the selected ${selectedComputeAssetType}, allowing you to use it without paying again.`
: hasDatatokenSelectedComputeAsset : hasDatatokenSelectedComputeAsset
@ -81,6 +101,8 @@ export default function ButtonBuy({
dtBalance, dtBalance,
assetType, assetType,
assetTimeout, assetTimeout,
isConsumable,
consumableFeedback,
hasPreviousOrderSelectedComputeAsset, hasPreviousOrderSelectedComputeAsset,
hasDatatokenSelectedComputeAsset, hasDatatokenSelectedComputeAsset,
dtSymbolSelectedComputeAsset, dtSymbolSelectedComputeAsset,
@ -91,7 +113,8 @@ export default function ButtonBuy({
isLoading, isLoading,
type, type,
priceType, priceType,
algorithmPriceType algorithmPriceType,
algorithmConsumableStatus
}: ButtonBuyProps): ReactElement { }: ButtonBuyProps): ReactElement {
const buttonText = const buttonText =
action === 'download' action === 'download'
@ -127,7 +150,9 @@ export default function ButtonBuy({
dtSymbol, dtSymbol,
hasDatatoken, hasDatatoken,
hasPreviousOrder, hasPreviousOrder,
assetType assetType,
isConsumable,
consumableFeedback
) )
: getComputeAssetHelpText( : getComputeAssetHelpText(
hasPreviousOrder, hasPreviousOrder,
@ -135,11 +160,14 @@ export default function ButtonBuy({
dtSymbol, dtSymbol,
dtBalance, dtBalance,
assetType, assetType,
isConsumable,
consumableFeedback,
hasPreviousOrderSelectedComputeAsset, hasPreviousOrderSelectedComputeAsset,
hasDatatokenSelectedComputeAsset, hasDatatokenSelectedComputeAsset,
dtSymbolSelectedComputeAsset, dtSymbolSelectedComputeAsset,
dtBalanceSelectedComputeAsset, dtBalanceSelectedComputeAsset,
selectedComputeAssetType selectedComputeAssetType,
algorithmConsumableStatus
)} )}
</div> </div>
</> </>

View File

@ -30,11 +30,11 @@ export default function Credentials(props: InputProps) {
toast.error('Wallet address is invalid') toast.error('Wallet address is invalid')
return return
} }
if (arrayInput.includes(value)) { if (arrayInput.includes(value.toLowerCase())) {
toast.error('Wallet address already added into list') toast.error('Wallet address already added into list')
return return
} }
setArrayInput((arrayInput) => [...arrayInput, value]) setArrayInput((arrayInput) => [...arrayInput, value.toLowerCase()])
setValue('') setValue('')
} }

View File

@ -9,6 +9,8 @@ import { AssetSelectionAsset } from '../../../molecules/FormFields/AssetSelectio
import ButtonBuy from '../../../atoms/ButtonBuy' import ButtonBuy from '../../../atoms/ButtonBuy'
import PriceOutput from './PriceOutput' import PriceOutput from './PriceOutput'
import { useAsset } from '../../../../providers/Asset' import { useAsset } from '../../../../providers/Asset'
import { useOcean } from '../../../../providers/Ocean'
import { useWeb3 } from '../../../../providers/Web3'
const contentQuery = graphql` const contentQuery = graphql`
query StartComputeDatasetQuery { query StartComputeDatasetQuery {
@ -58,7 +60,9 @@ export default function FormStartCompute({
selectedComputeAssetType, selectedComputeAssetType,
selectedComputeAssetTimeout, selectedComputeAssetTimeout,
stepText, stepText,
algorithmPrice algorithmPrice,
isConsumable,
consumableFeedback
}: { }: {
algorithms: AssetSelectionAsset[] algorithms: AssetSelectionAsset[]
ddoListAlgorithms: DDO[] ddoListAlgorithms: DDO[]
@ -78,6 +82,8 @@ export default function FormStartCompute({
selectedComputeAssetTimeout?: string selectedComputeAssetTimeout?: string
stepText: string stepText: string
algorithmPrice: BestPrice algorithmPrice: BestPrice
isConsumable: boolean
consumableFeedback: string
}): ReactElement { }): ReactElement {
const data = useStaticQuery(contentQuery) const data = useStaticQuery(contentQuery)
const content = data.content.edges[0].node.childPagesJson const content = data.content.edges[0].node.childPagesJson
@ -86,6 +92,10 @@ export default function FormStartCompute({
useFormikContext() useFormikContext()
const { price, ddo, isAssetNetwork } = useAsset() const { price, ddo, isAssetNetwork } = useAsset()
const [totalPrice, setTotalPrice] = useState(price?.value) const [totalPrice, setTotalPrice] = useState(price?.value)
const { accountId } = useWeb3()
const { ocean } = useOcean()
const [algorithmConsumableStatus, setAlgorithmConsumableStatus] =
useState<number>()
function getAlgorithmAsset(algorithmId: string): DDO { function getAlgorithmAsset(algorithmId: string): DDO {
let assetDdo = null let assetDdo = null
@ -97,8 +107,19 @@ export default function FormStartCompute({
useEffect(() => { useEffect(() => {
if (!values.algorithm) return if (!values.algorithm) return
setSelectedAlgorithm(getAlgorithmAsset(values.algorithm)) const algorithmDDO = getAlgorithmAsset(values.algorithm)
}, [values.algorithm]) setSelectedAlgorithm(algorithmDDO)
if (!accountId || !isConsumable) return
async function checkIsConsumable() {
const consumable = await ocean.assets.isConsumable(
algorithmDDO,
accountId.toLowerCase()
)
if (consumable) setAlgorithmConsumableStatus(consumable.status)
}
checkIsConsumable()
}, [values.algorithm, accountId, isConsumable])
// //
// Set price for calculation output // Set price for calculation output
@ -149,7 +170,12 @@ export default function FormStartCompute({
<ButtonBuy <ButtonBuy
action="compute" action="compute"
disabled={isComputeButtonDisabled || !isValid || !isAssetNetwork} disabled={
isComputeButtonDisabled ||
!isValid ||
!isAssetNetwork ||
algorithmConsumableStatus > 0
}
hasPreviousOrder={hasPreviousOrder} hasPreviousOrder={hasPreviousOrder}
hasDatatoken={hasDatatoken} hasDatatoken={hasDatatoken}
dtSymbol={ddo.dataTokenInfo.symbol} dtSymbol={ddo.dataTokenInfo.symbol}
@ -168,6 +194,9 @@ export default function FormStartCompute({
type="submit" type="submit"
priceType={price?.type} priceType={price?.type}
algorithmPriceType={algorithmPrice?.type} algorithmPriceType={algorithmPrice?.type}
isConsumable={isConsumable}
consumableFeedback={consumableFeedback}
algorithmConsumableStatus={algorithmConsumableStatus}
/> />
</Form> </Form>
) )

View File

@ -50,12 +50,16 @@ export default function Compute({
isBalanceSufficient, isBalanceSufficient,
dtBalance, dtBalance,
file, file,
fileIsLoading fileIsLoading,
isConsumable,
consumableFeedback
}: { }: {
isBalanceSufficient: boolean isBalanceSufficient: boolean
dtBalance: string dtBalance: string
file: FileMetadata file: FileMetadata
fileIsLoading?: boolean fileIsLoading?: boolean
isConsumable?: boolean
consumableFeedback?: string
}): ReactElement { }): ReactElement {
const { appConfig } = useSiteMetadata() const { appConfig } = useSiteMetadata()
const { accountId } = useWeb3() const { accountId } = useWeb3()
@ -82,7 +86,11 @@ export default function Compute({
const [algorithmTimeout, setAlgorithmTimeout] = useState<string>() const [algorithmTimeout, setAlgorithmTimeout] = useState<string>()
const isComputeButtonDisabled = const isComputeButtonDisabled =
isJobStarting === true || file === null || !ocean || !isBalanceSufficient isJobStarting === true ||
file === null ||
!ocean ||
!isBalanceSufficient ||
!isConsumable
const hasDatatoken = Number(dtBalance) >= 1 const hasDatatoken = Number(dtBalance) >= 1
async function checkPreviousOrders(ddo: DDO) { async function checkPreviousOrders(ddo: DDO) {
@ -418,6 +426,8 @@ export default function Compute({
selectedComputeAssetTimeout={algorithmTimeout} selectedComputeAssetTimeout={algorithmTimeout}
stepText={pricingStepText || 'Starting Compute Job...'} stepText={pricingStepText || 'Starting Compute Job...'}
algorithmPrice={algorithmPrice} algorithmPrice={algorithmPrice}
isConsumable={isConsumable}
consumableFeedback={consumableFeedback}
/> />
</Formik> </Formik>
)} )}

View File

@ -36,13 +36,17 @@ export default function Consume({
file, file,
isBalanceSufficient, isBalanceSufficient,
dtBalance, dtBalance,
fileIsLoading fileIsLoading,
isConsumable,
consumableFeedback
}: { }: {
ddo: DDO ddo: DDO
file: FileMetadata file: FileMetadata
isBalanceSufficient: boolean isBalanceSufficient: boolean
dtBalance: string dtBalance: string
fileIsLoading?: boolean fileIsLoading?: boolean
isConsumable?: boolean
consumableFeedback?: string
}): ReactElement { }): ReactElement {
const { accountId } = useWeb3() const { accountId } = useWeb3()
const { ocean } = useOcean() const { ocean } = useOcean()
@ -55,7 +59,7 @@ export default function Consume({
const { consumeStepText, consume, consumeError, isLoading } = useConsume() const { consumeStepText, consume, consumeError, isLoading } = useConsume()
const [isDisabled, setIsDisabled] = useState(true) const [isDisabled, setIsDisabled] = useState(true)
const [hasDatatoken, setHasDatatoken] = useState(false) const [hasDatatoken, setHasDatatoken] = useState(false)
const [isConsumable, setIsConsumable] = useState(true) const [isConsumablePrice, setIsConsumablePrice] = useState(true)
const [assetTimeout, setAssetTimeout] = useState('') const [assetTimeout, setAssetTimeout] = useState('')
const { data } = useQuery<OrdersData>(previousOrderQuery, { const { data } = useQuery<OrdersData>(previousOrderQuery, {
variables: { variables: {
@ -93,7 +97,7 @@ export default function Consume({
useEffect(() => { useEffect(() => {
if (!price) return if (!price) return
setIsConsumable( setIsConsumablePrice(
price.isConsumable !== undefined ? price.isConsumable === 'true' : true price.isConsumable !== undefined ? price.isConsumable === 'true' : true
) )
}, [price]) }, [price])
@ -104,14 +108,15 @@ export default function Consume({
useEffect(() => { useEffect(() => {
setIsDisabled( setIsDisabled(
(!ocean || !isConsumable ||
!isBalanceSufficient || ((!ocean ||
!isAssetNetwork || !isBalanceSufficient ||
typeof consumeStepText !== 'undefined' || !isAssetNetwork ||
pricingIsLoading || typeof consumeStepText !== 'undefined' ||
!isConsumable) && pricingIsLoading ||
!hasPreviousOrder && !isConsumablePrice) &&
!hasDatatoken !hasPreviousOrder &&
!hasDatatoken)
) )
}, [ }, [
ocean, ocean,
@ -120,8 +125,9 @@ export default function Consume({
isAssetNetwork, isAssetNetwork,
consumeStepText, consumeStepText,
pricingIsLoading, pricingIsLoading,
isConsumable, isConsumablePrice,
hasDatatoken hasDatatoken,
isConsumable
]) ])
async function handleConsume() { async function handleConsume() {
@ -162,6 +168,8 @@ export default function Consume({
stepText={consumeStepText || pricingStepText} stepText={consumeStepText || pricingStepText}
isLoading={pricingIsLoading || isLoading} isLoading={pricingIsLoading || isLoading}
priceType={price?.type} priceType={price?.type}
isConsumable={isConsumable}
consumableFeedback={consumableFeedback}
/> />
) )

View File

@ -26,6 +26,24 @@ export default function AssetActions(): ReactElement {
const [fileIsLoading, setFileIsLoading] = useState<boolean>(false) const [fileIsLoading, setFileIsLoading] = useState<boolean>(false)
const isCompute = Boolean(ddo?.findServiceByType('compute')) const isCompute = Boolean(ddo?.findServiceByType('compute'))
const [isConsumable, setIsConsumable] = useState<boolean>(true)
const [consumableFeedback, setConsumableFeedback] = useState<string>('')
useEffect(() => {
if (!ddo || !accountId) return
async function checkIsConsumable() {
const consumable: any = await ocean.assets.isConsumable(
ddo,
accountId.toLowerCase()
)
if (consumable) {
setIsConsumable(consumable.result)
setConsumableFeedback(consumable.message)
}
}
checkIsConsumable()
}, [accountId, ddo])
useEffect(() => { useEffect(() => {
const { attributes } = ddo.findServiceByType('metadata') const { attributes } = ddo.findServiceByType('metadata')
setFileMetadata(attributes.main.files[0]) setFileMetadata(attributes.main.files[0])
@ -88,6 +106,8 @@ export default function AssetActions(): ReactElement {
isBalanceSufficient={isBalanceSufficient} isBalanceSufficient={isBalanceSufficient}
file={fileMetadata} file={fileMetadata}
fileIsLoading={fileIsLoading} fileIsLoading={fileIsLoading}
isConsumable={isConsumable}
consumableFeedback={consumableFeedback}
/> />
) : ( ) : (
<Consume <Consume
@ -96,6 +116,8 @@ export default function AssetActions(): ReactElement {
isBalanceSufficient={isBalanceSufficient} isBalanceSufficient={isBalanceSufficient}
file={fileMetadata} file={fileMetadata}
fileIsLoading={fileIsLoading} fileIsLoading={fileIsLoading}
isConsumable={isConsumable}
consumableFeedback={consumableFeedback}
/> />
) )

View File

@ -116,6 +116,7 @@ export function transformPublishFormToMetadata(
name, name,
author, author,
dateCreated: ddo ? ddo.created : currentTime, dateCreated: ddo ? ddo.created : currentTime,
datePublished: '',
files: typeof files !== 'string' && files, files: typeof files !== 'string' && files,
license: 'https://market.oceanprotocol.com/terms' license: 'https://market.oceanprotocol.com/terms'
}, },