Skip to content

Commit

Permalink
Catch smartbch transaction reversion and mark tx as success false
Browse files Browse the repository at this point in the history
  • Loading branch information
joemarct committed Aug 10, 2022
1 parent 21408d6 commit 9fc0cdb
Showing 1 changed file with 34 additions and 8 deletions.
42 changes: 34 additions & 8 deletions src/wallet/sbch/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 9fc0cdb

Please sign in to comment.