diff --git a/src/components/Asset/AssetActions/Download.tsx b/src/components/Asset/AssetActions/Download.tsx index 2a25eaebd..67c48b511 100644 --- a/src/components/Asset/AssetActions/Download.tsx +++ b/src/components/Asset/AssetActions/Download.tsx @@ -87,16 +87,17 @@ export default function Download({ async function handleOrderOrDownload() { setIsLoading(true) - if (isOwned) { - setStatusText( - getOrderFeedback( - asset.accessDetails?.baseToken?.symbol, - asset.accessDetails?.datatoken?.symbol - )[3] - ) - await downloadFile(web3, asset, accountId, validOrderTx) - } else { - try { + try { + if (isOwned) { + setStatusText( + getOrderFeedback( + asset.accessDetails?.baseToken?.symbol, + asset.accessDetails?.datatoken?.symbol + )[3] + ) + + await downloadFile(web3, asset, accountId, validOrderTx) + } else { if (!hasDatatoken && asset.accessDetails.type === 'dynamic') { setStatusText( getOrderFeedback( @@ -106,9 +107,7 @@ export default function Download({ ) const tx = await buyDtFromPool(asset.accessDetails, accountId, web3) if (!tx) { - toast.error('Failed to buy datatoken from pool!') - setIsLoading(false) - return + throw new Error() } } setStatusText( @@ -119,18 +118,18 @@ export default function Download({ ) const orderTx = await order(web3, asset, orderPriceAndFees, accountId) if (!orderTx) { - toast.error('Failed to buy datatoken from pool!') - setIsLoading(false) - return + throw new Error() } setIsOwned(true) setValidOrderTx(orderTx.transactionHash) - } catch (ex) { - LoggerInstance.log(ex.message) - setIsLoading(false) } + } catch (error) { + LoggerInstance.error(error) + const message = isOwned + ? 'Failed to download file!' + : 'Failed to buy datatoken from pool!' + toast.error(message) } - setIsLoading(false) }