Skip to content

Commit

Permalink
🥅 Detect failed Tx (#798)
Browse files Browse the repository at this point in the history
  • Loading branch information
WeiJun0827 authored Nov 23, 2022
1 parent fd5ebfa commit 4f99e8c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
6 changes: 4 additions & 2 deletions src/mixins/nft.js
Original file line number Diff line number Diff line change
Expand Up @@ -514,14 +514,15 @@ export default {
this.classId,
1
);
const txHash = await broadcastTx(signData, this.getSigner);
const { txHash, code } = await broadcastTx(signData, this.getSigner);
logTrackerEvent(
this,
'NFT',
'NFTCollectBroadcastTxComplete',
this.classId,
1
);
if (code !== 0) throw new Error(`TX_FAILED_WITH_CODE_${code}`);
if (txHash && this.uiIsOpenCollectModal) {
logTrackerEvent(this, 'NFT', 'NFTCollectPurchase', this.classId, 1);
const result = await this.$api.post(
Expand Down Expand Up @@ -621,14 +622,15 @@ export default {
1
);
this.uiSetTxStatus(TX_STATUS.PROCESSING);
const txHash = await broadcastTx(signData, this.getSigner);
const { txHash, code } = await broadcastTx(signData, this.getSigner);
logTrackerEvent(
this,
'NFT',
'NFTTransferBroadcastTxComplete',
this.classId,
1
);
if (code !== 0) throw new Error(`TX_FAILED_WITH_CODE_${code}`);

logTrackerEvent(
this,
Expand Down
4 changes: 2 additions & 2 deletions src/util/nft.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,8 @@ export async function broadcastTx(signData, signer) {
const client = await createNFTSigningClient(signer);
const senderClient = client.getSigningStargateClient();
const txBytes = TxRaw.encode(signData).finish();
const { transactionHash } = await senderClient.broadcastTx(txBytes);
return transactionHash;
const { transactionHash, code } = await senderClient.broadcastTx(txBytes);
return { txHash: transactionHash, code };
}

export async function signTransferNFT({
Expand Down

0 comments on commit 4f99e8c

Please sign in to comment.