From 6ce25cbff5bfb1ffd50c30ee9e30d9cf4a9a35eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=A1s?= Date: Wed, 22 May 2024 05:25:41 -0400 Subject: [PATCH] fix: handling transfer cancellation on substrate (#195) ## Description Handles user cancelation on substrate transfer ## Related Issue Or Context Closes: #193 ## How Has This Been Tested? Testing details. ## Types of changes - [x] Bug fix (non-breaking change which fixes an issue) - [ ] New feature (non-breaking change which adds functionality) - [ ] Breaking change (fix or feature that would cause existing functionality to change) - [ ] Documentation ## Checklist: - [ ] I have commented my code, particularly in hard-to-understand areas. - [ ] I have ensured that all acceptance criteria (or expected behavior) from issue are met - [ ] I have updated the documentation locally and in sygma-docs. - [ ] I have added tests to cover my changes. - [ ] I have ensured that all the checks are passing and green, I've signed the CLA bot --- .../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; + } }