mirror of
https://github.com/oceanprotocol/market.git
synced 2024-12-02 05:57:29 +01:00
remove loading feedback during price fetching (#1361)
This commit is contained in:
parent
6a6f1acd84
commit
ce07740ef8
@ -22,7 +22,7 @@ interface ButtonBuyProps {
|
|||||||
selectedComputeAssetLowPoolLiquidity?: boolean
|
selectedComputeAssetLowPoolLiquidity?: boolean
|
||||||
selectedComputeAssetType?: string
|
selectedComputeAssetType?: string
|
||||||
isBalanceSufficient: boolean
|
isBalanceSufficient: boolean
|
||||||
isLoading: boolean
|
isLoading?: boolean
|
||||||
onClick?: (e: FormEvent<HTMLButtonElement>) => void
|
onClick?: (e: FormEvent<HTMLButtonElement>) => void
|
||||||
stepText?: string
|
stepText?: string
|
||||||
type?: 'submit'
|
type?: 'submit'
|
||||||
|
@ -38,6 +38,7 @@ export default function Download({
|
|||||||
const { accountId, web3 } = useWeb3()
|
const { accountId, web3 } = useWeb3()
|
||||||
const { getOpcFeeForToken } = useMarketMetadata()
|
const { getOpcFeeForToken } = useMarketMetadata()
|
||||||
const { isInPurgatory, isAssetNetwork } = useAsset()
|
const { isInPurgatory, isAssetNetwork } = useAsset()
|
||||||
|
const { poolData } = usePool()
|
||||||
const isMounted = useIsMounted()
|
const isMounted = useIsMounted()
|
||||||
|
|
||||||
const [isDisabled, setIsDisabled] = useState(true)
|
const [isDisabled, setIsDisabled] = useState(true)
|
||||||
@ -46,25 +47,25 @@ export default function Download({
|
|||||||
const [isLoading, setIsLoading] = useState(false)
|
const [isLoading, setIsLoading] = useState(false)
|
||||||
const [isOwned, setIsOwned] = useState(false)
|
const [isOwned, setIsOwned] = useState(false)
|
||||||
const [validOrderTx, setValidOrderTx] = useState('')
|
const [validOrderTx, setValidOrderTx] = useState('')
|
||||||
|
|
||||||
const { poolData } = usePool()
|
|
||||||
const [orderPriceAndFees, setOrderPriceAndFees] =
|
const [orderPriceAndFees, setOrderPriceAndFees] =
|
||||||
useState<OrderPriceAndFees>()
|
useState<OrderPriceAndFees>()
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!asset?.accessDetails) return
|
if (!asset?.accessDetails) return
|
||||||
|
|
||||||
setIsOwned(asset?.accessDetails?.isOwned)
|
setIsOwned(asset?.accessDetails?.isOwned)
|
||||||
setValidOrderTx(asset?.accessDetails?.validOrderTx)
|
setValidOrderTx(asset?.accessDetails?.validOrderTx)
|
||||||
|
|
||||||
// get full price and fees
|
// get full price and fees
|
||||||
async function init() {
|
async function init() {
|
||||||
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
|
||||||
setIsLoading(true)
|
|
||||||
setStatusText('Calculating price including fees.')
|
|
||||||
|
|
||||||
const params: CalcInGivenOutParams = {
|
const params: CalcInGivenOutParams = {
|
||||||
tokenInLiquidity: poolData?.baseTokenLiquidity,
|
tokenInLiquidity: poolData?.baseTokenLiquidity,
|
||||||
@ -82,12 +83,11 @@ export default function Download({
|
|||||||
)
|
)
|
||||||
|
|
||||||
setOrderPriceAndFees(orderPriceAndFees)
|
setOrderPriceAndFees(orderPriceAndFees)
|
||||||
|
setIsDisabled(false)
|
||||||
setIsLoading(false)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
init()
|
init()
|
||||||
}, [asset, accountId, poolData, getOpcFeeForToken])
|
}, [asset, accountId, poolData, getOpcFeeForToken, isLoading])
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setHasDatatoken(Number(dtBalance) >= 1)
|
setHasDatatoken(Number(dtBalance) >= 1)
|
||||||
@ -112,6 +112,7 @@ export default function Download({
|
|||||||
|
|
||||||
async function handleOrderOrDownload() {
|
async function handleOrderOrDownload() {
|
||||||
setIsLoading(true)
|
setIsLoading(true)
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (isOwned) {
|
if (isOwned) {
|
||||||
setStatusText(
|
setStatusText(
|
||||||
@ -171,7 +172,6 @@ export default function Download({
|
|||||||
assetTimeout={secondsToString(asset.services[0].timeout)}
|
assetTimeout={secondsToString(asset.services[0].timeout)}
|
||||||
assetType={asset?.metadata?.type}
|
assetType={asset?.metadata?.type}
|
||||||
stepText={statusText}
|
stepText={statusText}
|
||||||
// isLoading={pricingIsLoading || isLoading}
|
|
||||||
isLoading={isLoading}
|
isLoading={isLoading}
|
||||||
priceType={asset.accessDetails?.type}
|
priceType={asset.accessDetails?.type}
|
||||||
isConsumable={asset.accessDetails?.isPurchasable}
|
isConsumable={asset.accessDetails?.isPurchasable}
|
||||||
|
@ -26,6 +26,8 @@ export default function AssetActions({
|
|||||||
}): ReactElement {
|
}): ReactElement {
|
||||||
const { accountId, balance, web3 } = useWeb3()
|
const { accountId, balance, web3 } = useWeb3()
|
||||||
const { isAssetNetwork } = useAsset()
|
const { isAssetNetwork } = useAsset()
|
||||||
|
const newCancelToken = useCancelToken()
|
||||||
|
const isMounted = useIsMounted()
|
||||||
|
|
||||||
// TODO: using this for the publish preview works fine, but produces a console warning
|
// TODO: using this for the publish preview works fine, but produces a console warning
|
||||||
// on asset details page as there is no formik context there:
|
// on asset details page as there is no formik context there:
|
||||||
@ -41,27 +43,7 @@ export default function AssetActions({
|
|||||||
asset?.services.filter((service) => service.type === 'compute')[0]
|
asset?.services.filter((service) => service.type === 'compute')[0]
|
||||||
)
|
)
|
||||||
|
|
||||||
const [isConsumable, setIsConsumable] = useState<boolean>(true)
|
// Get and set file info
|
||||||
const [consumableFeedback, setConsumableFeedback] = useState<string>('')
|
|
||||||
const newCancelToken = useCancelToken()
|
|
||||||
const isMounted = useIsMounted()
|
|
||||||
|
|
||||||
// useEffect(() => {
|
|
||||||
// if (!ddo || !accountId || !ocean || !isAssetNetwork) return
|
|
||||||
|
|
||||||
// async function checkIsConsumable() {
|
|
||||||
// const consumable = await ocean.assets.isConsumable(
|
|
||||||
// ddo,
|
|
||||||
// accountId.toLowerCase()
|
|
||||||
// )
|
|
||||||
// if (consumable) {
|
|
||||||
// setIsConsumable(consumable.result)
|
|
||||||
// setConsumableFeedback(consumable.message)
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// checkIsConsumable()
|
|
||||||
// }, [accountId, isAssetNetwork, ddo, ocean])
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const oceanConfig = getOceanConfig(asset?.chainId)
|
const oceanConfig = getOceanConfig(asset?.chainId)
|
||||||
if (!oceanConfig) return
|
if (!oceanConfig) return
|
||||||
@ -136,8 +118,6 @@ export default function AssetActions({
|
|||||||
dtBalance={dtBalance}
|
dtBalance={dtBalance}
|
||||||
file={fileMetadata}
|
file={fileMetadata}
|
||||||
fileIsLoading={fileIsLoading}
|
fileIsLoading={fileIsLoading}
|
||||||
isConsumable={isConsumable}
|
|
||||||
consumableFeedback={consumableFeedback}
|
|
||||||
/>
|
/>
|
||||||
) : (
|
) : (
|
||||||
<Consume
|
<Consume
|
||||||
@ -146,7 +126,6 @@ export default function AssetActions({
|
|||||||
isBalanceSufficient={isBalanceSufficient}
|
isBalanceSufficient={isBalanceSufficient}
|
||||||
file={fileMetadata}
|
file={fileMetadata}
|
||||||
fileIsLoading={fileIsLoading}
|
fileIsLoading={fileIsLoading}
|
||||||
consumableFeedback={consumableFeedback}
|
|
||||||
/>
|
/>
|
||||||
)
|
)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user