From fc6e00669c8e4995ea9d378aa9d34248eab4bd8f Mon Sep 17 00:00:00 2001 From: EnzoVezzaro Date: Fri, 11 Mar 2022 07:25:51 -0400 Subject: [PATCH] Feature/issue 1175 catch user rejection buy (#1177) * fix approval rejection on buyDtFromPool * fix approval rejection on order --- src/@utils/order.ts | 3 +++ src/@utils/pool.ts | 3 +++ src/components/Asset/AssetActions/Download.tsx | 8 +++++--- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/@utils/order.ts b/src/@utils/order.ts index 09150be13..472f97da5 100644 --- a/src/@utils/order.ts +++ b/src/@utils/order.ts @@ -60,6 +60,9 @@ export async function order( orderPriceAndFees.price, false ) + if (!txApprove) { + return + } const freParams = { exchangeContract: config.fixedRateExchangeAddress, diff --git a/src/@utils/pool.ts b/src/@utils/pool.ts index 6d1cf597c..f4c25531c 100644 --- a/src/@utils/pool.ts +++ b/src/@utils/pool.ts @@ -56,6 +56,9 @@ export async function buyDtFromPool( dtPrice.tokenAmount, false ) + if (!approveTx) { + return + } const result = await pool.swapExactAmountOut( accountId, accessDetails.addressOrId, diff --git a/src/components/Asset/AssetActions/Download.tsx b/src/components/Asset/AssetActions/Download.tsx index a7ec4230c..7a4f3757e 100644 --- a/src/components/Asset/AssetActions/Download.tsx +++ b/src/components/Asset/AssetActions/Download.tsx @@ -146,9 +146,7 @@ export default function Download({ asset.accessDetails.datatoken?.symbol )[0] ) - const tx = await buyDtFromPool(asset.accessDetails, accountId, web3) - if (!tx) { toast.error('Failed to buy datatoken from pool!') setIsLoading(false) @@ -162,7 +160,11 @@ export default function Download({ )[asset.accessDetails?.type === 'fixed' ? 2 : 1] ) const orderTx = await order(web3, asset, orderPriceAndFees, accountId) - + if (!orderTx) { + toast.error('Failed to buy datatoken from pool!') + setIsLoading(false) + return + } setIsOwned(true) setValidOrderTx(orderTx.transactionHash) } catch (ex) {