From 946e9bf6cf8ad2f09c71611dcd5f85c7aa3eea62 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=A1s=20Riquelme=20Guzm=C3=A1n?= Date: Sun, 12 May 2024 12:26:26 -0400 Subject: [PATCH] fix: handling transfer cancellation on substrate --- .../transfers/substrate/execute.ts | 55 ++++++++++--------- 1 file changed, 30 insertions(+), 25 deletions(-) diff --git a/packages/widget/src/controllers/transfers/substrate/execute.ts b/packages/widget/src/controllers/transfers/substrate/execute.ts index a5d631a6..ca901394 100644 --- a/packages/widget/src/controllers/transfers/substrate/execute.ts +++ b/packages/widget/src/controllers/transfers/substrate/execute.ts @@ -20,33 +20,38 @@ export async function executeNextSubstrateTransaction( const provider = this.sourceSubstrateProvider; this.waitingTxExecution = true; - await (this.pendingTransferTransaction as SubstrateTransaction).signAndSend( - sender, - { signer: signer }, - ({ blockNumber, txIndex, status, dispatchError }) => { - if (status.isInBlock) { - this.waitingTxExecution = false; - this.pendingTransferTransaction = undefined; - this.transferTransactionId = `${blockNumber?.toString()}-${txIndex?.toString()}`; - this.host.requestUpdate(); - } - - if (status.isBroadcast) { - this.waitingUserConfirmation = false; - this.host.requestUpdate(); - } - - if (dispatchError) { - if (dispatchError.isModule) { - const decoded = provider?.registry.findMetaError( - dispatchError.asModule - ); - const [docs] = decoded?.docs || ['Transfer failed']; - this.errorMessage = docs; + try { + await (this.pendingTransferTransaction as SubstrateTransaction).signAndSend( + sender, + { signer: signer }, + ({ blockNumber, txIndex, status, dispatchError }) => { + if (status.isInBlock) { this.waitingTxExecution = false; + this.pendingTransferTransaction = undefined; + this.transferTransactionId = `${blockNumber?.toString()}-${txIndex?.toString()}`; this.host.requestUpdate(); } + + if (status.isBroadcast) { + this.waitingUserConfirmation = false; + this.host.requestUpdate(); + } + + if (dispatchError) { + if (dispatchError.isModule) { + const decoded = provider?.registry.findMetaError( + dispatchError.asModule + ); + const [docs] = decoded?.docs || ['Transfer failed']; + this.errorMessage = docs; + this.waitingTxExecution = false; + this.host.requestUpdate(); + } + } } - } - ); + ); + } catch (error) { + this.waitingUserConfirmation = false; + this.waitingTxExecution = false; + } }