mirror of
https://github.com/oceanprotocol/market.git
synced 2024-12-02 05:57:29 +01:00
fix unsupported network crash and allow price calculations to those networks
This commit is contained in:
parent
167ac4aaa3
commit
f242cebefa
@ -29,10 +29,10 @@ interface ButtonBuyProps {
|
|||||||
priceType?: string
|
priceType?: string
|
||||||
algorithmPriceType?: string
|
algorithmPriceType?: string
|
||||||
isAlgorithmConsumable?: boolean
|
isAlgorithmConsumable?: boolean
|
||||||
|
isSupportedOceanNetwork?: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: we need to take a look at these messages
|
// TODO: we need to take a look at these messages
|
||||||
|
|
||||||
function getConsumeHelpText(
|
function getConsumeHelpText(
|
||||||
dtBalance: string,
|
dtBalance: string,
|
||||||
dtSymbol: string,
|
dtSymbol: string,
|
||||||
@ -42,7 +42,8 @@ function getConsumeHelpText(
|
|||||||
assetType: string,
|
assetType: string,
|
||||||
isConsumable: boolean,
|
isConsumable: boolean,
|
||||||
isBalanceSufficient: boolean,
|
isBalanceSufficient: boolean,
|
||||||
consumableFeedback: string
|
consumableFeedback: string,
|
||||||
|
isSupportedOceanNetwork: boolean
|
||||||
) {
|
) {
|
||||||
const text =
|
const text =
|
||||||
isConsumable === false
|
isConsumable === false
|
||||||
@ -53,12 +54,41 @@ function getConsumeHelpText(
|
|||||||
? `You own ${dtBalance} ${dtSymbol} allowing you to use this data set by spending 1 ${dtSymbol}, but without paying OCEAN again.`
|
? `You own ${dtBalance} ${dtSymbol} allowing you to use this data set by spending 1 ${dtSymbol}, but without paying OCEAN again.`
|
||||||
: lowPoolLiquidity
|
: lowPoolLiquidity
|
||||||
? `There are not enought ${dtSymbol} available in the pool for the transaction to take place`
|
? `There are not enought ${dtSymbol} available in the pool for the transaction to take place`
|
||||||
: isBalanceSufficient === false
|
: isBalanceSufficient === false && isSupportedOceanNetwork
|
||||||
? 'You do not have enough OCEAN in your wallet to purchase this asset.'
|
? 'You do not have enough OCEAN in your wallet to purchase this asset.'
|
||||||
: `For using this ${assetType}, you will buy 1 ${dtSymbol} and immediately spend it back to the publisher and pool.`
|
: `For using this ${assetType}, you will buy 1 ${dtSymbol} and immediately spend it back to the publisher and pool.`
|
||||||
return text
|
return text
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getAlgoHelpText(
|
||||||
|
dtSymbolSelectedComputeAsset: string,
|
||||||
|
dtBalanceSelectedComputeAsset: string,
|
||||||
|
isConsumable: boolean,
|
||||||
|
isAlgorithmConsumable: boolean,
|
||||||
|
hasPreviousOrderSelectedComputeAsset: boolean,
|
||||||
|
selectedComputeAssetType: string,
|
||||||
|
hasDatatokenSelectedComputeAsset: boolean,
|
||||||
|
selectedComputeAssettLowPoolLiquidity: boolean,
|
||||||
|
isBalanceSufficient: boolean,
|
||||||
|
isSupportedOceanNetwork: boolean
|
||||||
|
) {
|
||||||
|
const text =
|
||||||
|
(!dtSymbolSelectedComputeAsset && !dtBalanceSelectedComputeAsset) ||
|
||||||
|
isConsumable === false ||
|
||||||
|
isAlgorithmConsumable === false
|
||||||
|
? ''
|
||||||
|
: hasPreviousOrderSelectedComputeAsset
|
||||||
|
? `You already bought the selected ${selectedComputeAssetType}, allowing you to use it without paying again.`
|
||||||
|
: hasDatatokenSelectedComputeAsset
|
||||||
|
? `You own ${dtBalanceSelectedComputeAsset} ${dtSymbolSelectedComputeAsset} allowing you to use the selected ${selectedComputeAssetType} by spending 1 ${dtSymbolSelectedComputeAsset}, but without paying OCEAN again.`
|
||||||
|
: selectedComputeAssettLowPoolLiquidity
|
||||||
|
? `There are not enought ${dtSymbolSelectedComputeAsset} available in the pool for the transaction to take place`
|
||||||
|
: isBalanceSufficient === false && isSupportedOceanNetwork
|
||||||
|
? ''
|
||||||
|
: `Additionally, you will buy 1 ${dtSymbolSelectedComputeAsset} for the ${selectedComputeAssetType} and spend it back to its publisher and pool.`
|
||||||
|
return text
|
||||||
|
}
|
||||||
|
|
||||||
function getComputeAssetHelpText(
|
function getComputeAssetHelpText(
|
||||||
hasPreviousOrder: boolean,
|
hasPreviousOrder: boolean,
|
||||||
hasDatatoken: boolean,
|
hasDatatoken: boolean,
|
||||||
@ -75,7 +105,8 @@ function getComputeAssetHelpText(
|
|||||||
dtBalanceSelectedComputeAsset?: string,
|
dtBalanceSelectedComputeAsset?: string,
|
||||||
selectedComputeAssettLowPoolLiquidity?: boolean,
|
selectedComputeAssettLowPoolLiquidity?: boolean,
|
||||||
selectedComputeAssetType?: string,
|
selectedComputeAssetType?: string,
|
||||||
isAlgorithmConsumable?: boolean
|
isAlgorithmConsumable?: boolean,
|
||||||
|
isSupportedOceanNetwork?: boolean
|
||||||
) {
|
) {
|
||||||
const computeAssetHelpText = getConsumeHelpText(
|
const computeAssetHelpText = getConsumeHelpText(
|
||||||
dtBalance,
|
dtBalance,
|
||||||
@ -86,22 +117,23 @@ function getComputeAssetHelpText(
|
|||||||
assetType,
|
assetType,
|
||||||
isConsumable,
|
isConsumable,
|
||||||
isBalanceSufficient,
|
isBalanceSufficient,
|
||||||
consumableFeedback
|
consumableFeedback,
|
||||||
|
isSupportedOceanNetwork
|
||||||
)
|
)
|
||||||
const computeAlgoHelpText =
|
|
||||||
(!dtSymbolSelectedComputeAsset && !dtBalanceSelectedComputeAsset) ||
|
const computeAlgoHelpText = getAlgoHelpText(
|
||||||
isConsumable === false ||
|
dtSymbolSelectedComputeAsset,
|
||||||
isAlgorithmConsumable === false
|
dtBalanceSelectedComputeAsset,
|
||||||
? ''
|
isConsumable,
|
||||||
: hasPreviousOrderSelectedComputeAsset
|
isAlgorithmConsumable,
|
||||||
? `You already bought the selected ${selectedComputeAssetType}, allowing you to use it without paying again.`
|
hasPreviousOrderSelectedComputeAsset,
|
||||||
: hasDatatokenSelectedComputeAsset
|
selectedComputeAssetType,
|
||||||
? `You own ${dtBalanceSelectedComputeAsset} ${dtSymbolSelectedComputeAsset} allowing you to use the selected ${selectedComputeAssetType} by spending 1 ${dtSymbolSelectedComputeAsset}, but without paying OCEAN again.`
|
hasDatatokenSelectedComputeAsset,
|
||||||
: selectedComputeAssettLowPoolLiquidity
|
selectedComputeAssettLowPoolLiquidity,
|
||||||
? `There are not enought ${dtSymbolSelectedComputeAsset} available in the pool for the transaction to take place`
|
isBalanceSufficient,
|
||||||
: isBalanceSufficient === false
|
isSupportedOceanNetwork
|
||||||
? ''
|
)
|
||||||
: `Additionally, you will buy 1 ${dtSymbolSelectedComputeAsset} for the ${selectedComputeAssetType} and spend it back to its publisher and pool.`
|
|
||||||
const computeHelpText = selectedComputeAssettLowPoolLiquidity
|
const computeHelpText = selectedComputeAssettLowPoolLiquidity
|
||||||
? computeAlgoHelpText
|
? computeAlgoHelpText
|
||||||
: lowPoolLiquidity
|
: lowPoolLiquidity
|
||||||
@ -135,7 +167,8 @@ export default function ButtonBuy({
|
|||||||
type,
|
type,
|
||||||
priceType,
|
priceType,
|
||||||
algorithmPriceType,
|
algorithmPriceType,
|
||||||
isAlgorithmConsumable
|
isAlgorithmConsumable,
|
||||||
|
isSupportedOceanNetwork
|
||||||
}: ButtonBuyProps): ReactElement {
|
}: ButtonBuyProps): ReactElement {
|
||||||
const buttonText =
|
const buttonText =
|
||||||
action === 'download'
|
action === 'download'
|
||||||
@ -176,7 +209,8 @@ export default function ButtonBuy({
|
|||||||
assetType,
|
assetType,
|
||||||
isConsumable,
|
isConsumable,
|
||||||
isBalanceSufficient,
|
isBalanceSufficient,
|
||||||
consumableFeedback
|
consumableFeedback,
|
||||||
|
isSupportedOceanNetwork
|
||||||
)
|
)
|
||||||
: getComputeAssetHelpText(
|
: getComputeAssetHelpText(
|
||||||
hasPreviousOrder,
|
hasPreviousOrder,
|
||||||
@ -194,7 +228,8 @@ export default function ButtonBuy({
|
|||||||
dtBalanceSelectedComputeAsset,
|
dtBalanceSelectedComputeAsset,
|
||||||
selectedComputeAssetLowPoolLiquidity,
|
selectedComputeAssetLowPoolLiquidity,
|
||||||
selectedComputeAssetType,
|
selectedComputeAssetType,
|
||||||
isAlgorithmConsumable
|
isAlgorithmConsumable,
|
||||||
|
isSupportedOceanNetwork
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
</>
|
</>
|
||||||
|
@ -155,11 +155,11 @@ export default function FormStartCompute({
|
|||||||
])
|
])
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!totalPrice) return
|
if (!totalPrice || !balance.ocean || !dtBalance) return
|
||||||
setIsBalanceSufficient(
|
setIsBalanceSufficient(
|
||||||
compareAsBN(balance.ocean, `${totalPrice}`) || Number(dtBalance) >= 1
|
compareAsBN(balance.ocean, `${totalPrice}`) || Number(dtBalance) >= 1
|
||||||
)
|
)
|
||||||
}, [totalPrice])
|
}, [totalPrice, balance.ocean, dtBalance])
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Form className={styles.form}>
|
<Form className={styles.form}>
|
||||||
@ -169,7 +169,7 @@ export default function FormStartCompute({
|
|||||||
{...field}
|
{...field}
|
||||||
options={algorithms}
|
options={algorithms}
|
||||||
component={Input}
|
component={Input}
|
||||||
disabled={isLoading || !isSupportedOceanNetwork}
|
disabled={isLoading}
|
||||||
/>
|
/>
|
||||||
))}
|
))}
|
||||||
|
|
||||||
@ -226,6 +226,7 @@ export default function FormStartCompute({
|
|||||||
isAlgorithmConsumable={
|
isAlgorithmConsumable={
|
||||||
selectedAlgorithmAsset?.accessDetails?.isPurchasable
|
selectedAlgorithmAsset?.accessDetails?.isPurchasable
|
||||||
}
|
}
|
||||||
|
isSupportedOceanNetwork={isSupportedOceanNetwork}
|
||||||
/>
|
/>
|
||||||
</Form>
|
</Form>
|
||||||
)
|
)
|
||||||
|
@ -35,7 +35,7 @@ export default function Download({
|
|||||||
fileIsLoading?: boolean
|
fileIsLoading?: boolean
|
||||||
consumableFeedback?: string
|
consumableFeedback?: string
|
||||||
}): ReactElement {
|
}): ReactElement {
|
||||||
const { accountId, web3 } = useWeb3()
|
const { accountId, web3, isSupportedOceanNetwork } = useWeb3()
|
||||||
const { getOpcFeeForToken } = useMarketMetadata()
|
const { getOpcFeeForToken } = useMarketMetadata()
|
||||||
const { isInPurgatory, isAssetNetwork } = useAsset()
|
const { isInPurgatory, isAssetNetwork } = useAsset()
|
||||||
const { poolData } = usePool()
|
const { poolData } = usePool()
|
||||||
@ -199,6 +199,7 @@ export default function Download({
|
|||||||
isConsumable={asset.accessDetails?.isPurchasable}
|
isConsumable={asset.accessDetails?.isPurchasable}
|
||||||
isBalanceSufficient={isBalanceSufficient}
|
isBalanceSufficient={isBalanceSufficient}
|
||||||
consumableFeedback={consumableFeedback}
|
consumableFeedback={consumableFeedback}
|
||||||
|
isSupportedOceanNetwork={isSupportedOceanNetwork}
|
||||||
/>
|
/>
|
||||||
)
|
)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user