From 9fc0cdbe64b6dea14d06bf584aa16e7c77608991 Mon Sep 17 00:00:00 2001 From: joemarct Date: Wed, 10 Aug 2022 10:53:42 +0800 Subject: [PATCH] Catch smartbch transaction reversion and mark tx as success false --- src/wallet/sbch/index.js | 42 ++++++++++++++++++++++++++++++++-------- 1 file changed, 34 insertions(+), 8 deletions(-) diff --git a/src/wallet/sbch/index.js b/src/wallet/sbch/index.js index bd93a8326..8ebc3d162 100644 --- a/src/wallet/sbch/index.js +++ b/src/wallet/sbch/index.js @@ -336,8 +336,20 @@ export class SmartBchWallet { async sendTransaction (txParams, wait = true) { try { const tx = await this._wallet.sendTransaction(txParams) - if (wait) await tx.wait() - + if (wait) { + const minedTx = await tx.wait() + if (minedTx.status === 1) { + return { + success: true, + transaction: minedTx + } + } else if (minedTx.status === 0) { + return { + success: false, + transaction: 'transaction reverted' + } + } + } return { success: true, transaction: tx @@ -376,9 +388,16 @@ export class SmartBchWallet { try { const tx = await contractWithSigner.transfer(recipientAddress, parsedAmount) const minedTx = await tx.wait() - return { - success: true, - transaction: minedTx + if (minedTx.status === 1) { + return { + success: true, + transaction: minedTx + } + } else if (minedTx.status === 0) { + return { + success: false, + transaction: 'transaction reverted' + } } } catch (e) { return { @@ -423,9 +442,16 @@ export class SmartBchWallet { try { const tx = await contractWithSigner.safeTransferFrom(this._wallet.address, recipientAddress, parsedTokenId) const minedTx = await tx.wait() - return { - success: true, - transaction: minedTx + if (minedTx.status === 1) { + return { + success: true, + transaction: minedTx + } + } else if (minedTx.status === 0) { + return { + success: false, + transaction: 'transaction reverted' + } } } catch (e) { return {