mirror of
https://github.com/oceanprotocol/market.git
synced 2024-12-02 05:57:29 +01:00
restore order for assets with fixed pricing (#1360)
* restore button if there's not pool data * restore order for fixed pricing and download button after purchase * minor fixes - avoid errors when providerFee is null - fix disabled download/buy button when user is on different network as asset's * added improvements
This commit is contained in:
parent
b6ad55dda4
commit
6ef2082724
@ -256,6 +256,7 @@ export async function getOrderPriceAndFees(
|
|||||||
asset?.services[0].serviceEndpoint
|
asset?.services[0].serviceEndpoint
|
||||||
)
|
)
|
||||||
orderPriceAndFee.providerFee = initializeData.providerFee
|
orderPriceAndFee.providerFee = initializeData.providerFee
|
||||||
|
if (!orderPriceAndFee.providerFee) return
|
||||||
|
|
||||||
// fetch price and swap fees
|
// fetch price and swap fees
|
||||||
switch (asset?.accessDetails?.type) {
|
switch (asset?.accessDetails?.type) {
|
||||||
|
@ -420,7 +420,7 @@ export default function Compute({
|
|||||||
assetTimeout={datasetTimeout}
|
assetTimeout={datasetTimeout}
|
||||||
hasPreviousOrderSelectedComputeAsset={hasPreviousAlgorithmOrder}
|
hasPreviousOrderSelectedComputeAsset={hasPreviousAlgorithmOrder}
|
||||||
hasDatatokenSelectedComputeAsset={hasAlgoAssetDatatoken}
|
hasDatatokenSelectedComputeAsset={hasAlgoAssetDatatoken}
|
||||||
oceanSymbol={accessDetails ? accessDetails.baseToken.symbol : ''}
|
oceanSymbol={accessDetails?.baseToken?.symbol || ''}
|
||||||
dtSymbolSelectedComputeAsset={
|
dtSymbolSelectedComputeAsset={
|
||||||
selectedAlgorithmAsset?.datatokens[0]?.symbol
|
selectedAlgorithmAsset?.datatokens[0]?.symbol
|
||||||
}
|
}
|
||||||
|
@ -61,9 +61,7 @@ export default function Download({
|
|||||||
if (
|
if (
|
||||||
asset?.accessDetails?.addressOrId === ZERO_ADDRESS ||
|
asset?.accessDetails?.addressOrId === ZERO_ADDRESS ||
|
||||||
asset?.accessDetails?.type === 'free' ||
|
asset?.accessDetails?.type === 'free' ||
|
||||||
(!poolData && asset?.accessDetails?.type === 'dynamic') ||
|
(!poolData && asset?.accessDetails?.type === 'dynamic')
|
||||||
// Stop refetching price and fees when asset is being accessed
|
|
||||||
isLoading
|
|
||||||
)
|
)
|
||||||
return
|
return
|
||||||
|
|
||||||
@ -71,11 +69,15 @@ export default function Download({
|
|||||||
tokenInLiquidity: poolData?.baseTokenLiquidity,
|
tokenInLiquidity: poolData?.baseTokenLiquidity,
|
||||||
tokenOutLiquidity: poolData?.datatokenLiquidity,
|
tokenOutLiquidity: poolData?.datatokenLiquidity,
|
||||||
tokenOutAmount: '1',
|
tokenOutAmount: '1',
|
||||||
opcFee: getOpcFeeForToken(poolData.baseToken.address, asset?.chainId),
|
opcFee: getOpcFeeForToken(
|
||||||
|
poolData?.baseToken?.address || asset?.accessDetails?.addressOrId,
|
||||||
|
asset?.chainId
|
||||||
|
),
|
||||||
lpSwapFee: poolData?.liquidityProviderSwapFee,
|
lpSwapFee: poolData?.liquidityProviderSwapFee,
|
||||||
publishMarketSwapFee: poolData?.publishMarketSwapFee,
|
publishMarketSwapFee: poolData?.publishMarketSwapFee,
|
||||||
consumeMarketSwapFee: '0'
|
consumeMarketSwapFee: '0'
|
||||||
}
|
}
|
||||||
|
|
||||||
const orderPriceAndFees = await getOrderPriceAndFees(
|
const orderPriceAndFees = await getOrderPriceAndFees(
|
||||||
asset,
|
asset,
|
||||||
ZERO_ADDRESS,
|
ZERO_ADDRESS,
|
||||||
@ -83,11 +85,14 @@ export default function Download({
|
|||||||
)
|
)
|
||||||
|
|
||||||
setOrderPriceAndFees(orderPriceAndFees)
|
setOrderPriceAndFees(orderPriceAndFees)
|
||||||
setIsDisabled(false)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
init()
|
init()
|
||||||
}, [asset, accountId, poolData, getOpcFeeForToken, isLoading])
|
/**
|
||||||
|
* we listen to the assets' changes to get the most updated price
|
||||||
|
* based on the asset and the poolData's information
|
||||||
|
*/
|
||||||
|
}, [asset, accountId, poolData, getOpcFeeForToken])
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setHasDatatoken(Number(dtBalance) >= 1)
|
setHasDatatoken(Number(dtBalance) >= 1)
|
||||||
@ -96,9 +101,18 @@ export default function Download({
|
|||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!isMounted || !accountId || !asset?.accessDetails) return
|
if (!isMounted || !accountId || !asset?.accessDetails) return
|
||||||
|
|
||||||
|
/**
|
||||||
|
* disabled in these cases:
|
||||||
|
* - if the asset is not purchasable
|
||||||
|
* - if the user is on the wrong network
|
||||||
|
* - if user balance is not sufficient
|
||||||
|
* - if user has no datatokens
|
||||||
|
*/
|
||||||
const isDisabled =
|
const isDisabled =
|
||||||
!asset?.accessDetails.isPurchasable ||
|
!asset?.accessDetails.isPurchasable ||
|
||||||
|
!isAssetNetwork ||
|
||||||
((!isBalanceSufficient || !isAssetNetwork) && !isOwned && !hasDatatoken)
|
((!isBalanceSufficient || !isAssetNetwork) && !isOwned && !hasDatatoken)
|
||||||
|
|
||||||
setIsDisabled(isDisabled)
|
setIsDisabled(isDisabled)
|
||||||
}, [
|
}, [
|
||||||
isMounted,
|
isMounted,
|
||||||
@ -146,6 +160,7 @@ export default function Download({
|
|||||||
if (!orderTx) {
|
if (!orderTx) {
|
||||||
throw new Error()
|
throw new Error()
|
||||||
}
|
}
|
||||||
|
|
||||||
setIsOwned(true)
|
setIsOwned(true)
|
||||||
setValidOrderTx(orderTx.transactionHash)
|
setValidOrderTx(orderTx.transactionHash)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user